blob: 0ae56cb6b0b30b76c199dc8cd3e80e22f6b01487 [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
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100129struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100130 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100132
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200133 struct mwl8k_device_info *device_info;
134
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100135 void __iomem *sram;
136 void __iomem *regs;
137
138 /* firmware */
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100139 struct firmware *fw_helper;
140 struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100141
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100142 /* hardware/firmware parameters */
143 bool ap_fw;
144 struct rxd_ops *rxd_ops;
145
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200146 /* firmware access */
147 struct mutex fw_mutex;
148 struct task_struct *fw_mutex_owner;
149 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200150 struct completion *hostcmd_wait;
151
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100152 /* lock held over TX and TX reap */
153 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100154
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200155 /* TX quiesce completion, protected by fw_mutex and tx_lock */
156 struct completion *tx_wait;
157
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100158 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100159
160 struct ieee80211_channel *current_channel;
161
162 /* power management status cookie from firmware */
163 u32 *cookie;
164 dma_addr_t cookie_dma;
165
166 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100167 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200168 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100169
170 /*
171 * Running count of TX packets in flight, to avoid
172 * iterating over the transmit rings each time.
173 */
174 int pending_tx_pkts;
175
176 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
177 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
178
179 /* PHY parameters */
180 struct ieee80211_supported_band band;
181 struct ieee80211_channel channels[14];
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100182 struct ieee80211_rate rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100183
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200184 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200185 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200186 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200187 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100188
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100189 /* XXX need to convert this to handle multiple interfaces */
190 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200191 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100192 struct sk_buff *beacon_skb;
193
194 /*
195 * This FJ worker has to be global as it is scheduled from the
196 * RX handler. At this point we don't know which interface it
197 * belongs to until the list of bssids waiting to complete join
198 * is checked.
199 */
200 struct work_struct finalize_join_worker;
201
202 /* Tasklet to reclaim TX descriptors and buffers after tx */
203 struct tasklet_struct tx_reclaim_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100204};
205
206/* Per interface specific private data */
207struct mwl8k_vif {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100208 /* backpointer to parent config block */
209 struct mwl8k_priv *priv;
210
211 /* BSS config of AP or IBSS from mac80211*/
212 struct ieee80211_bss_conf bss_info;
213
214 /* BSSID of AP or IBSS */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200215 u8 bssid[ETH_ALEN];
216 u8 mac_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100217
Lennert Buytenhek55489b62009-11-30 18:31:33 +0100218 /* Index into station database. Returned by UPDATE_STADB. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100219 u8 peer_id;
220
221 /* Non AMPDU sequence number assigned by driver */
222 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100223};
224
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200225#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100226
227static const struct ieee80211_channel mwl8k_channels[] = {
228 { .center_freq = 2412, .hw_value = 1, },
229 { .center_freq = 2417, .hw_value = 2, },
230 { .center_freq = 2422, .hw_value = 3, },
231 { .center_freq = 2427, .hw_value = 4, },
232 { .center_freq = 2432, .hw_value = 5, },
233 { .center_freq = 2437, .hw_value = 6, },
234 { .center_freq = 2442, .hw_value = 7, },
235 { .center_freq = 2447, .hw_value = 8, },
236 { .center_freq = 2452, .hw_value = 9, },
237 { .center_freq = 2457, .hw_value = 10, },
238 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100239 { .center_freq = 2467, .hw_value = 12, },
240 { .center_freq = 2472, .hw_value = 13, },
241 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100242};
243
244static const struct ieee80211_rate mwl8k_rates[] = {
245 { .bitrate = 10, .hw_value = 2, },
246 { .bitrate = 20, .hw_value = 4, },
247 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200248 { .bitrate = 110, .hw_value = 22, },
249 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100250 { .bitrate = 60, .hw_value = 12, },
251 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100252 { .bitrate = 120, .hw_value = 24, },
253 { .bitrate = 180, .hw_value = 36, },
254 { .bitrate = 240, .hw_value = 48, },
255 { .bitrate = 360, .hw_value = 72, },
256 { .bitrate = 480, .hw_value = 96, },
257 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100258 { .bitrate = 720, .hw_value = 144, },
259};
260
261static const u8 mwl8k_rateids[12] = {
262 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108,
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100263};
264
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100265/* Set or get info from Firmware */
266#define MWL8K_CMD_SET 0x0001
267#define MWL8K_CMD_GET 0x0000
268
269/* Firmware command codes */
270#define MWL8K_CMD_CODE_DNLD 0x0001
271#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200272#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100273#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
274#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200275#define MWL8K_CMD_RADIO_CONTROL 0x001c
276#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200277#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100278#define MWL8K_CMD_SET_PRE_SCAN 0x0107
279#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200280#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100281#define MWL8K_CMD_SET_AID 0x010d
282#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200283#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100284#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200285#define MWL8K_CMD_SET_SLOT 0x0114
286#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
287#define MWL8K_CMD_SET_WMM_MODE 0x0123
288#define MWL8K_CMD_MIMO_CONFIG 0x0125
289#define MWL8K_CMD_USE_FIXED_RATE 0x0126
290#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200291#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200292#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
293#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100294
295static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
296{
297#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
298 snprintf(buf, bufsize, "%s", #x);\
299 return buf;\
300 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200301 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100302 MWL8K_CMDNAME(CODE_DNLD);
303 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200304 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100305 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
306 MWL8K_CMDNAME(GET_STAT);
307 MWL8K_CMDNAME(RADIO_CONTROL);
308 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200309 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100310 MWL8K_CMDNAME(SET_PRE_SCAN);
311 MWL8K_CMDNAME(SET_POST_SCAN);
312 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100313 MWL8K_CMDNAME(SET_AID);
314 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200315 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100316 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200317 MWL8K_CMDNAME(SET_SLOT);
318 MWL8K_CMDNAME(SET_EDCA_PARAMS);
319 MWL8K_CMDNAME(SET_WMM_MODE);
320 MWL8K_CMDNAME(MIMO_CONFIG);
321 MWL8K_CMDNAME(USE_FIXED_RATE);
322 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200323 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200324 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
325 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100326 default:
327 snprintf(buf, bufsize, "0x%x", cmd);
328 }
329#undef MWL8K_CMDNAME
330
331 return buf;
332}
333
334/* Hardware and firmware reset */
335static void mwl8k_hw_reset(struct mwl8k_priv *priv)
336{
337 iowrite32(MWL8K_H2A_INT_RESET,
338 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
339 iowrite32(MWL8K_H2A_INT_RESET,
340 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
341 msleep(20);
342}
343
344/* Release fw image */
345static void mwl8k_release_fw(struct firmware **fw)
346{
347 if (*fw == NULL)
348 return;
349 release_firmware(*fw);
350 *fw = NULL;
351}
352
353static void mwl8k_release_firmware(struct mwl8k_priv *priv)
354{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100355 mwl8k_release_fw(&priv->fw_ucode);
356 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100357}
358
359/* Request fw image */
360static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200361 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100362{
363 /* release current image */
364 if (*fw != NULL)
365 mwl8k_release_fw(fw);
366
367 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200368 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100369}
370
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200371static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100372{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200373 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100374 int rc;
375
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200376 if (di->helper_image != NULL) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100377 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200378 if (rc) {
379 printk(KERN_ERR "%s: Error requesting helper "
380 "firmware file %s\n", pci_name(priv->pdev),
381 di->helper_image);
382 return rc;
383 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100384 }
385
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100386 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100387 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200388 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200389 pci_name(priv->pdev), di->fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100390 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100391 return rc;
392 }
393
394 return 0;
395}
396
Ben Hutchings7e75b942009-11-07 22:00:57 +0000397MODULE_FIRMWARE("mwl8k/helper_8687.fw");
398MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
399
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100400struct mwl8k_cmd_pkt {
401 __le16 code;
402 __le16 length;
403 __le16 seq_num;
404 __le16 result;
405 char payload[0];
406} __attribute__((packed));
407
408/*
409 * Firmware loading.
410 */
411static int
412mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
413{
414 void __iomem *regs = priv->regs;
415 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100416 int loops;
417
418 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
419 if (pci_dma_mapping_error(priv->pdev, dma_addr))
420 return -ENOMEM;
421
422 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
423 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
424 iowrite32(MWL8K_H2A_INT_DOORBELL,
425 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
426 iowrite32(MWL8K_H2A_INT_DUMMY,
427 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
428
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100429 loops = 1000;
430 do {
431 u32 int_code;
432
433 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
434 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
435 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100436 break;
437 }
438
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200439 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100440 udelay(1);
441 } while (--loops);
442
443 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
444
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200445 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100446}
447
448static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
449 const u8 *data, size_t length)
450{
451 struct mwl8k_cmd_pkt *cmd;
452 int done;
453 int rc = 0;
454
455 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
456 if (cmd == NULL)
457 return -ENOMEM;
458
459 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
460 cmd->seq_num = 0;
461 cmd->result = 0;
462
463 done = 0;
464 while (length) {
465 int block_size = length > 256 ? 256 : length;
466
467 memcpy(cmd->payload, data + done, block_size);
468 cmd->length = cpu_to_le16(block_size);
469
470 rc = mwl8k_send_fw_load_cmd(priv, cmd,
471 sizeof(*cmd) + block_size);
472 if (rc)
473 break;
474
475 done += block_size;
476 length -= block_size;
477 }
478
479 if (!rc) {
480 cmd->length = 0;
481 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
482 }
483
484 kfree(cmd);
485
486 return rc;
487}
488
489static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
490 const u8 *data, size_t length)
491{
492 unsigned char *buffer;
493 int may_continue, rc = 0;
494 u32 done, prev_block_size;
495
496 buffer = kmalloc(1024, GFP_KERNEL);
497 if (buffer == NULL)
498 return -ENOMEM;
499
500 done = 0;
501 prev_block_size = 0;
502 may_continue = 1000;
503 while (may_continue > 0) {
504 u32 block_size;
505
506 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
507 if (block_size & 1) {
508 block_size &= ~1;
509 may_continue--;
510 } else {
511 done += prev_block_size;
512 length -= prev_block_size;
513 }
514
515 if (block_size > 1024 || block_size > length) {
516 rc = -EOVERFLOW;
517 break;
518 }
519
520 if (length == 0) {
521 rc = 0;
522 break;
523 }
524
525 if (block_size == 0) {
526 rc = -EPROTO;
527 may_continue--;
528 udelay(1);
529 continue;
530 }
531
532 prev_block_size = block_size;
533 memcpy(buffer, data + done, block_size);
534
535 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
536 if (rc)
537 break;
538 }
539
540 if (!rc && length != 0)
541 rc = -EREMOTEIO;
542
543 kfree(buffer);
544
545 return rc;
546}
547
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200548static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100549{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200550 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100551 struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200552 int rc;
553 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100554
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200555 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100556 struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100557
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200558 if (helper == NULL) {
559 printk(KERN_ERR "%s: helper image needed but none "
560 "given\n", pci_name(priv->pdev));
561 return -EINVAL;
562 }
563
564 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100565 if (rc) {
566 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200567 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100568 return rc;
569 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100570 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100571
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200572 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100573 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200574 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100575 }
576
577 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200578 printk(KERN_ERR "%s: unable to load firmware image\n",
579 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100580 return rc;
581 }
582
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100583 if (priv->device_info->modes & BIT(NL80211_IFTYPE_AP))
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200584 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
585 else
586 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100587
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100588 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100589 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200590 u32 ready_code;
591
592 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
593 if (ready_code == MWL8K_FWAP_READY) {
594 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100595 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200596 } else if (ready_code == MWL8K_FWSTA_READY) {
597 priv->ap_fw = 0;
598 break;
599 }
600
601 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100602 udelay(1);
603 } while (--loops);
604
605 return loops ? 0 : -ETIMEDOUT;
606}
607
608
609/*
610 * Defines shared between transmission and reception.
611 */
612/* HT control fields for firmware */
613struct ewc_ht_info {
614 __le16 control1;
615 __le16 control2;
616 __le16 control3;
617} __attribute__((packed));
618
619/* Firmware Station database operations */
620#define MWL8K_STA_DB_ADD_ENTRY 0
621#define MWL8K_STA_DB_MODIFY_ENTRY 1
622#define MWL8K_STA_DB_DEL_ENTRY 2
623#define MWL8K_STA_DB_FLUSH 3
624
625/* Peer Entry flags - used to define the type of the peer node */
626#define MWL8K_PEER_TYPE_ACCESSPOINT 2
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100627
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100628struct peer_capability_info {
629 /* Peer type - AP vs. STA. */
630 __u8 peer_type;
631
632 /* Basic 802.11 capabilities from assoc resp. */
633 __le16 basic_caps;
634
635 /* Set if peer supports 802.11n high throughput (HT). */
636 __u8 ht_support;
637
638 /* Valid if HT is supported. */
639 __le16 ht_caps;
640 __u8 extended_ht_caps;
641 struct ewc_ht_info ewc_info;
642
643 /* Legacy rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100644 __u8 legacy_rates[12];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100645
646 /* HT rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek0b5351a2009-11-30 18:11:18 +0100647 __u8 ht_rates[16];
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +0200648 __u8 pad[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100649
650 /* If set, interoperability mode, no proprietary extensions. */
651 __u8 interop;
652 __u8 pad2;
653 __u8 station_id;
654 __le16 amsdu_enabled;
655} __attribute__((packed));
656
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100657/* DMA header used by firmware and hardware. */
658struct mwl8k_dma_data {
659 __le16 fwlen;
660 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100661 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100662} __attribute__((packed));
663
664/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100665static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100666{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100667 struct mwl8k_dma_data *tr;
668 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100669
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100670 tr = (struct mwl8k_dma_data *)skb->data;
671 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
672
673 if (hdrlen != sizeof(tr->wh)) {
674 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
675 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
676 *((__le16 *)(tr->data - 2)) = qos;
677 } else {
678 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
679 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100680 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100681
682 if (hdrlen != sizeof(*tr))
683 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100684}
685
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200686static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100687{
688 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100689 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100690 struct mwl8k_dma_data *tr;
691
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100692 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100693 * Add a firmware DMA header; the firmware requires that we
694 * present a 2-byte payload length followed by a 4-address
695 * header (without QoS field), followed (optionally) by any
696 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100697 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100698 wh = (struct ieee80211_hdr *)skb->data;
699
700 hdrlen = ieee80211_hdrlen(wh->frame_control);
701 if (hdrlen != sizeof(*tr))
702 skb_push(skb, sizeof(*tr) - hdrlen);
703
704 if (ieee80211_is_data_qos(wh->frame_control))
705 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100706
707 tr = (struct mwl8k_dma_data *)skb->data;
708 if (wh != &tr->wh)
709 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100710 if (hdrlen != sizeof(tr->wh))
711 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100712
713 /*
714 * Firmware length is the length of the fully formed "802.11
715 * payload". That is, everything except for the 802.11 header.
716 * This includes all crypto material including the MIC.
717 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100718 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100719}
720
721
722/*
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200723 * Packet reception for 88w8366.
724 */
725struct mwl8k_rxd_8366 {
726 __le16 pkt_len;
727 __u8 sq2;
728 __u8 rate;
729 __le32 pkt_phys_addr;
730 __le32 next_rxd_phys_addr;
731 __le16 qos_control;
732 __le16 htsig2;
733 __le32 hw_rssi_info;
734 __le32 hw_noise_floor_info;
735 __u8 noise_floor;
736 __u8 pad0[3];
737 __u8 rssi;
738 __u8 rx_status;
739 __u8 channel;
740 __u8 rx_ctrl;
741} __attribute__((packed));
742
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100743#define MWL8K_8366_RATE_INFO_MCS_FORMAT 0x80
744#define MWL8K_8366_RATE_INFO_40MHZ 0x40
745#define MWL8K_8366_RATE_INFO_RATEID(x) ((x) & 0x3f)
746
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200747#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
748
749static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
750{
751 struct mwl8k_rxd_8366 *rxd = _rxd;
752
753 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
754 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
755}
756
757static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
758{
759 struct mwl8k_rxd_8366 *rxd = _rxd;
760
761 rxd->pkt_len = cpu_to_le16(len);
762 rxd->pkt_phys_addr = cpu_to_le32(addr);
763 wmb();
764 rxd->rx_ctrl = 0;
765}
766
767static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100768mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status,
769 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200770{
771 struct mwl8k_rxd_8366 *rxd = _rxd;
772
773 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
774 return -1;
775 rmb();
776
777 memset(status, 0, sizeof(*status));
778
779 status->signal = -rxd->rssi;
780 status->noise = -rxd->noise_floor;
781
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100782 if (rxd->rate & MWL8K_8366_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200783 status->flag |= RX_FLAG_HT;
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100784 if (rxd->rate & MWL8K_8366_RATE_INFO_40MHZ)
785 status->flag |= RX_FLAG_40MHZ;
786 status->rate_idx = MWL8K_8366_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200787 } else {
788 int i;
789
790 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
791 if (mwl8k_rates[i].hw_value == rxd->rate) {
792 status->rate_idx = i;
793 break;
794 }
795 }
796 }
797
798 status->band = IEEE80211_BAND_2GHZ;
799 status->freq = ieee80211_channel_to_frequency(rxd->channel);
800
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100801 *qos = rxd->qos_control;
802
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200803 return le16_to_cpu(rxd->pkt_len);
804}
805
806static struct rxd_ops rxd_8366_ops = {
807 .rxd_size = sizeof(struct mwl8k_rxd_8366),
808 .rxd_init = mwl8k_rxd_8366_init,
809 .rxd_refill = mwl8k_rxd_8366_refill,
810 .rxd_process = mwl8k_rxd_8366_process,
811};
812
813/*
814 * Packet reception for 88w8687.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100815 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200816struct mwl8k_rxd_8687 {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100817 __le16 pkt_len;
818 __u8 link_quality;
819 __u8 noise_level;
820 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200821 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100822 __le16 qos_control;
823 __le16 rate_info;
824 __le32 pad0[4];
825 __u8 rssi;
826 __u8 channel;
827 __le16 pad1;
828 __u8 rx_ctrl;
829 __u8 rx_status;
830 __u8 pad2[2];
831} __attribute__((packed));
832
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200833#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
834#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
835#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
836#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
837#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
838#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
839
840#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
841
842static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
843{
844 struct mwl8k_rxd_8687 *rxd = _rxd;
845
846 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
847 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
848}
849
850static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
851{
852 struct mwl8k_rxd_8687 *rxd = _rxd;
853
854 rxd->pkt_len = cpu_to_le16(len);
855 rxd->pkt_phys_addr = cpu_to_le32(addr);
856 wmb();
857 rxd->rx_ctrl = 0;
858}
859
860static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100861mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status,
862 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200863{
864 struct mwl8k_rxd_8687 *rxd = _rxd;
865 u16 rate_info;
866
867 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
868 return -1;
869 rmb();
870
871 rate_info = le16_to_cpu(rxd->rate_info);
872
873 memset(status, 0, sizeof(*status));
874
875 status->signal = -rxd->rssi;
876 status->noise = -rxd->noise_level;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200877 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
878 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
879
880 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
881 status->flag |= RX_FLAG_SHORTPRE;
882 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
883 status->flag |= RX_FLAG_40MHZ;
884 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
885 status->flag |= RX_FLAG_SHORT_GI;
886 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
887 status->flag |= RX_FLAG_HT;
888
889 status->band = IEEE80211_BAND_2GHZ;
890 status->freq = ieee80211_channel_to_frequency(rxd->channel);
891
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100892 *qos = rxd->qos_control;
893
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200894 return le16_to_cpu(rxd->pkt_len);
895}
896
897static struct rxd_ops rxd_8687_ops = {
898 .rxd_size = sizeof(struct mwl8k_rxd_8687),
899 .rxd_init = mwl8k_rxd_8687_init,
900 .rxd_refill = mwl8k_rxd_8687_refill,
901 .rxd_process = mwl8k_rxd_8687_process,
902};
903
904
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100905#define MWL8K_RX_DESCS 256
906#define MWL8K_RX_MAXSZ 3800
907
908static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
909{
910 struct mwl8k_priv *priv = hw->priv;
911 struct mwl8k_rx_queue *rxq = priv->rxq + index;
912 int size;
913 int i;
914
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200915 rxq->rxd_count = 0;
916 rxq->head = 0;
917 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100918
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200919 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100920
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200921 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
922 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100923 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200924 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100925 return -ENOMEM;
926 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200927 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100928
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200929 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
930 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100931 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200932 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200933 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100934 return -ENOMEM;
935 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200936 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100937
938 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200939 int desc_size;
940 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100941 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200942 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100943
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200944 desc_size = priv->rxd_ops->rxd_size;
945 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100946
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200947 nexti = i + 1;
948 if (nexti == MWL8K_RX_DESCS)
949 nexti = 0;
950 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
951
952 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100953 }
954
955 return 0;
956}
957
958static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
959{
960 struct mwl8k_priv *priv = hw->priv;
961 struct mwl8k_rx_queue *rxq = priv->rxq + index;
962 int refilled;
963
964 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200965 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100966 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200967 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100968 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200969 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100970
971 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
972 if (skb == NULL)
973 break;
974
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200975 addr = pci_map_single(priv->pdev, skb->data,
976 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100977
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200978 rxq->rxd_count++;
979 rx = rxq->tail++;
980 if (rxq->tail == MWL8K_RX_DESCS)
981 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200982 rxq->buf[rx].skb = skb;
983 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200984
985 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
986 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100987
988 refilled++;
989 }
990
991 return refilled;
992}
993
994/* Must be called only when the card's reception is completely halted */
995static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
996{
997 struct mwl8k_priv *priv = hw->priv;
998 struct mwl8k_rx_queue *rxq = priv->rxq + index;
999 int i;
1000
1001 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001002 if (rxq->buf[i].skb != NULL) {
1003 pci_unmap_single(priv->pdev,
1004 pci_unmap_addr(&rxq->buf[i], dma),
1005 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1006 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001007
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001008 kfree_skb(rxq->buf[i].skb);
1009 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001010 }
1011 }
1012
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001013 kfree(rxq->buf);
1014 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001015
1016 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001017 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001018 rxq->rxd, rxq->rxd_dma);
1019 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001020}
1021
1022
1023/*
1024 * Scan a list of BSSIDs to process for finalize join.
1025 * Allows for extension to process multiple BSSIDs.
1026 */
1027static inline int
1028mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1029{
1030 return priv->capture_beacon &&
1031 ieee80211_is_beacon(wh->frame_control) &&
1032 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1033}
1034
Lennert Buytenhek37797522009-10-22 20:19:45 +02001035static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1036 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001037{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001038 struct mwl8k_priv *priv = hw->priv;
1039
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001040 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001041 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001042
1043 /*
1044 * Use GFP_ATOMIC as rxq_process is called from
1045 * the primary interrupt handler, memory allocation call
1046 * must not sleep.
1047 */
1048 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1049 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001050 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001051}
1052
1053static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1054{
1055 struct mwl8k_priv *priv = hw->priv;
1056 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1057 int processed;
1058
1059 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001060 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001061 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001062 void *rxd;
1063 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001064 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001065 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001066
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001067 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001068 if (skb == NULL)
1069 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001070
1071 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1072
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001073 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001074 if (pkt_len < 0)
1075 break;
1076
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001077 rxq->buf[rxq->head].skb = NULL;
1078
1079 pci_unmap_single(priv->pdev,
1080 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1081 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1082 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001083
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001084 rxq->head++;
1085 if (rxq->head == MWL8K_RX_DESCS)
1086 rxq->head = 0;
1087
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001088 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001089
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001090 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001091 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001092
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001093 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001094 * Check for a pending join operation. Save a
1095 * copy of the beacon and schedule a tasklet to
1096 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001097 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001098 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001099 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001100
Johannes Bergf1d58c22009-06-17 13:13:00 +02001101 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1102 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001103
1104 processed++;
1105 }
1106
1107 return processed;
1108}
1109
1110
1111/*
1112 * Packet transmission.
1113 */
1114
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001115#define MWL8K_TXD_STATUS_OK 0x00000001
1116#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1117#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1118#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001119#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001120
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001121#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1122#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1123#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1124#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1125#define MWL8K_QOS_EOSP 0x0010
1126
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001127struct mwl8k_tx_desc {
1128 __le32 status;
1129 __u8 data_rate;
1130 __u8 tx_priority;
1131 __le16 qos_control;
1132 __le32 pkt_phys_addr;
1133 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001134 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001135 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001136 __le32 reserved;
1137 __le16 rate_info;
1138 __u8 peer_id;
1139 __u8 tx_frag_cnt;
1140} __attribute__((packed));
1141
1142#define MWL8K_TX_DESCS 128
1143
1144static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1145{
1146 struct mwl8k_priv *priv = hw->priv;
1147 struct mwl8k_tx_queue *txq = priv->txq + index;
1148 int size;
1149 int i;
1150
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001151 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1152 txq->stats.limit = MWL8K_TX_DESCS;
1153 txq->head = 0;
1154 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001155
1156 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1157
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001158 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1159 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001160 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001161 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001162 return -ENOMEM;
1163 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001164 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001165
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001166 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1167 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001168 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001169 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001170 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001171 return -ENOMEM;
1172 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001173 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001174
1175 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1176 struct mwl8k_tx_desc *tx_desc;
1177 int nexti;
1178
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001179 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001180 nexti = (i + 1) % MWL8K_TX_DESCS;
1181
1182 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001183 tx_desc->next_txd_phys_addr =
1184 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001185 }
1186
1187 return 0;
1188}
1189
1190static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1191{
1192 iowrite32(MWL8K_H2A_INT_PPA_READY,
1193 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1194 iowrite32(MWL8K_H2A_INT_DUMMY,
1195 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1196 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1197}
1198
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001199static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001200{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001201 struct mwl8k_priv *priv = hw->priv;
1202 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001204 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1205 struct mwl8k_tx_queue *txq = priv->txq + i;
1206 int fw_owned = 0;
1207 int drv_owned = 0;
1208 int unused = 0;
1209 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001210
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001211 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001212 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1213 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001214
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001215 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001216 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001217 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001218 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001219 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001220
1221 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001222 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001223 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001224
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001225 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1226 "fw_owned=%d drv_owned=%d unused=%d\n",
1227 wiphy_name(hw->wiphy), i,
1228 txq->stats.len, txq->head, txq->tail,
1229 fw_owned, drv_owned, unused);
1230 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001231}
1232
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001233/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001234 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001235 */
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001236#define MWL8K_TX_WAIT_TIMEOUT_MS 1000
1237
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001238static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001239{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001240 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001241 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001242 int retry;
1243 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001244
1245 might_sleep();
1246
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001247 /*
1248 * The TX queues are stopped at this point, so this test
1249 * doesn't need to take ->tx_lock.
1250 */
1251 if (!priv->pending_tx_pkts)
1252 return 0;
1253
1254 retry = 0;
1255 rc = 0;
1256
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001257 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001258 priv->tx_wait = &tx_wait;
1259 while (!rc) {
1260 int oldcount;
1261 unsigned long timeout;
1262
1263 oldcount = priv->pending_tx_pkts;
1264
1265 spin_unlock_bh(&priv->tx_lock);
1266 timeout = wait_for_completion_timeout(&tx_wait,
1267 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1268 spin_lock_bh(&priv->tx_lock);
1269
1270 if (timeout) {
1271 WARN_ON(priv->pending_tx_pkts);
1272 if (retry) {
1273 printk(KERN_NOTICE "%s: tx rings drained\n",
1274 wiphy_name(hw->wiphy));
1275 }
1276 break;
1277 }
1278
1279 if (priv->pending_tx_pkts < oldcount) {
1280 printk(KERN_NOTICE "%s: timeout waiting for tx "
1281 "rings to drain (%d -> %d pkts), retrying\n",
1282 wiphy_name(hw->wiphy), oldcount,
1283 priv->pending_tx_pkts);
1284 retry = 1;
1285 continue;
1286 }
1287
1288 priv->tx_wait = NULL;
1289
1290 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1291 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1292 mwl8k_dump_tx_rings(hw);
1293
1294 rc = -ETIMEDOUT;
1295 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001296 spin_unlock_bh(&priv->tx_lock);
1297
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001298 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001299}
1300
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001301#define MWL8K_TXD_SUCCESS(status) \
1302 ((status) & (MWL8K_TXD_STATUS_OK | \
1303 MWL8K_TXD_STATUS_OK_RETRY | \
1304 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001305
1306static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1307{
1308 struct mwl8k_priv *priv = hw->priv;
1309 struct mwl8k_tx_queue *txq = priv->txq + index;
1310 int wake = 0;
1311
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001312 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001313 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001314 struct mwl8k_tx_desc *tx_desc;
1315 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001316 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001317 struct sk_buff *skb;
1318 struct ieee80211_tx_info *info;
1319 u32 status;
1320
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001321 tx = txq->head;
1322 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001323
1324 status = le32_to_cpu(tx_desc->status);
1325
1326 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1327 if (!force)
1328 break;
1329 tx_desc->status &=
1330 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1331 }
1332
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001333 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1334 BUG_ON(txq->stats.len == 0);
1335 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001336 priv->pending_tx_pkts--;
1337
1338 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001339 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001340 skb = txq->skb[tx];
1341 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001342
1343 BUG_ON(skb == NULL);
1344 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1345
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001346 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001347
1348 /* Mark descriptor as unused */
1349 tx_desc->pkt_phys_addr = 0;
1350 tx_desc->pkt_len = 0;
1351
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001352 info = IEEE80211_SKB_CB(skb);
1353 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001354 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001355 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001356
1357 ieee80211_tx_status_irqsafe(hw, skb);
1358
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001359 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001360 }
1361
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001362 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001363 ieee80211_wake_queue(hw, index);
1364}
1365
1366/* must be called only when the card's transmit is completely halted */
1367static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1368{
1369 struct mwl8k_priv *priv = hw->priv;
1370 struct mwl8k_tx_queue *txq = priv->txq + index;
1371
1372 mwl8k_txq_reclaim(hw, index, 1);
1373
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001374 kfree(txq->skb);
1375 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001376
1377 pci_free_consistent(priv->pdev,
1378 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001379 txq->txd, txq->txd_dma);
1380 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001381}
1382
1383static int
1384mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1385{
1386 struct mwl8k_priv *priv = hw->priv;
1387 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001388 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001389 struct ieee80211_hdr *wh;
1390 struct mwl8k_tx_queue *txq;
1391 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001392 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001393 u32 txstatus;
1394 u8 txdatarate;
1395 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001396
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001397 wh = (struct ieee80211_hdr *)skb->data;
1398 if (ieee80211_is_data_qos(wh->frame_control))
1399 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1400 else
1401 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001402
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001403 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001404 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001405
1406 tx_info = IEEE80211_SKB_CB(skb);
1407 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001408
1409 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1410 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001411
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001412 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1413 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1414 mwl8k_vif->seqno = seqno++ % 4096;
1415 }
1416
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001417 /* Setup firmware control bit fields for each frame type. */
1418 txstatus = 0;
1419 txdatarate = 0;
1420 if (ieee80211_is_mgmt(wh->frame_control) ||
1421 ieee80211_is_ctl(wh->frame_control)) {
1422 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001423 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001424 } else if (ieee80211_is_data(wh->frame_control)) {
1425 txdatarate = 1;
1426 if (is_multicast_ether_addr(wh->addr1))
1427 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1428
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001429 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001430 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001431 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001432 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001433 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001434 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001435
1436 dma = pci_map_single(priv->pdev, skb->data,
1437 skb->len, PCI_DMA_TODEVICE);
1438
1439 if (pci_dma_mapping_error(priv->pdev, dma)) {
1440 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001441 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001442 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001443 return NETDEV_TX_OK;
1444 }
1445
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001446 spin_lock_bh(&priv->tx_lock);
1447
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001448 txq = priv->txq + index;
1449
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001450 BUG_ON(txq->skb[txq->tail] != NULL);
1451 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001452
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001453 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001454 tx->data_rate = txdatarate;
1455 tx->tx_priority = index;
1456 tx->qos_control = cpu_to_le16(qos);
1457 tx->pkt_phys_addr = cpu_to_le32(dma);
1458 tx->pkt_len = cpu_to_le16(skb->len);
1459 tx->rate_info = 0;
1460 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001461 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001462 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1463
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001464 txq->stats.count++;
1465 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001466 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001467
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001468 txq->tail++;
1469 if (txq->tail == MWL8K_TX_DESCS)
1470 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001471
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001472 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001473 ieee80211_stop_queue(hw, index);
1474
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001475 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001476
1477 spin_unlock_bh(&priv->tx_lock);
1478
1479 return NETDEV_TX_OK;
1480}
1481
1482
1483/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001484 * Firmware access.
1485 *
1486 * We have the following requirements for issuing firmware commands:
1487 * - Some commands require that the packet transmit path is idle when
1488 * the command is issued. (For simplicity, we'll just quiesce the
1489 * transmit path for every command.)
1490 * - There are certain sequences of commands that need to be issued to
1491 * the hardware sequentially, with no other intervening commands.
1492 *
1493 * This leads to an implementation of a "firmware lock" as a mutex that
1494 * can be taken recursively, and which is taken by both the low-level
1495 * command submission function (mwl8k_post_cmd) as well as any users of
1496 * that function that require issuing of an atomic sequence of commands,
1497 * and quiesces the transmit path whenever it's taken.
1498 */
1499static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1500{
1501 struct mwl8k_priv *priv = hw->priv;
1502
1503 if (priv->fw_mutex_owner != current) {
1504 int rc;
1505
1506 mutex_lock(&priv->fw_mutex);
1507 ieee80211_stop_queues(hw);
1508
1509 rc = mwl8k_tx_wait_empty(hw);
1510 if (rc) {
1511 ieee80211_wake_queues(hw);
1512 mutex_unlock(&priv->fw_mutex);
1513
1514 return rc;
1515 }
1516
1517 priv->fw_mutex_owner = current;
1518 }
1519
1520 priv->fw_mutex_depth++;
1521
1522 return 0;
1523}
1524
1525static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1526{
1527 struct mwl8k_priv *priv = hw->priv;
1528
1529 if (!--priv->fw_mutex_depth) {
1530 ieee80211_wake_queues(hw);
1531 priv->fw_mutex_owner = NULL;
1532 mutex_unlock(&priv->fw_mutex);
1533 }
1534}
1535
1536
1537/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001538 * Command processing.
1539 */
1540
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001541/* Timeout firmware commands after 10s */
1542#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001543
1544static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1545{
1546 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1547 struct mwl8k_priv *priv = hw->priv;
1548 void __iomem *regs = priv->regs;
1549 dma_addr_t dma_addr;
1550 unsigned int dma_size;
1551 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001552 unsigned long timeout = 0;
1553 u8 buf[32];
1554
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001555 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001556 dma_size = le16_to_cpu(cmd->length);
1557 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1558 PCI_DMA_BIDIRECTIONAL);
1559 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1560 return -ENOMEM;
1561
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001562 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001563 if (rc) {
1564 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1565 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001566 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001567 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001568
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001569 priv->hostcmd_wait = &cmd_wait;
1570 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1571 iowrite32(MWL8K_H2A_INT_DOORBELL,
1572 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1573 iowrite32(MWL8K_H2A_INT_DUMMY,
1574 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001575
1576 timeout = wait_for_completion_timeout(&cmd_wait,
1577 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1578
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001579 priv->hostcmd_wait = NULL;
1580
1581 mwl8k_fw_unlock(hw);
1582
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001583 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1584 PCI_DMA_BIDIRECTIONAL);
1585
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001586 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001587 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001588 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001589 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1590 MWL8K_CMD_TIMEOUT_MS);
1591 rc = -ETIMEDOUT;
1592 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001593 int ms;
1594
1595 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1596
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001597 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001598 if (rc)
1599 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001600 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001601 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001602 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001603 else if (ms > 2000)
1604 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1605 wiphy_name(hw->wiphy),
1606 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1607 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001608 }
1609
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001610 return rc;
1611}
1612
1613/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001614 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001615 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001616struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001617 struct mwl8k_cmd_pkt header;
1618 __u8 hw_rev;
1619 __u8 host_interface;
1620 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001621 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001622 __le16 region_code;
1623 __le32 fw_rev;
1624 __le32 ps_cookie;
1625 __le32 caps;
1626 __u8 mcs_bitmap[16];
1627 __le32 rx_queue_ptr;
1628 __le32 num_tx_queues;
1629 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1630 __le32 caps2;
1631 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001632 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001633} __attribute__((packed));
1634
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001635static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001636{
1637 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001638 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001639 int rc;
1640 int i;
1641
1642 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1643 if (cmd == NULL)
1644 return -ENOMEM;
1645
1646 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1647 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1648
1649 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1650 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001651 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001652 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001653 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001654 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001655 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001656 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001657
1658 rc = mwl8k_post_cmd(hw, &cmd->header);
1659
1660 if (!rc) {
1661 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1662 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001663 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001664 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001665 }
1666
1667 kfree(cmd);
1668 return rc;
1669}
1670
1671/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001672 * CMD_GET_HW_SPEC (AP version).
1673 */
1674struct mwl8k_cmd_get_hw_spec_ap {
1675 struct mwl8k_cmd_pkt header;
1676 __u8 hw_rev;
1677 __u8 host_interface;
1678 __le16 num_wcb;
1679 __le16 num_mcaddrs;
1680 __u8 perm_addr[ETH_ALEN];
1681 __le16 region_code;
1682 __le16 num_antenna;
1683 __le32 fw_rev;
1684 __le32 wcbbase0;
1685 __le32 rxwrptr;
1686 __le32 rxrdptr;
1687 __le32 ps_cookie;
1688 __le32 wcbbase1;
1689 __le32 wcbbase2;
1690 __le32 wcbbase3;
1691} __attribute__((packed));
1692
1693static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1694{
1695 struct mwl8k_priv *priv = hw->priv;
1696 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1697 int rc;
1698
1699 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1700 if (cmd == NULL)
1701 return -ENOMEM;
1702
1703 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1704 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1705
1706 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1707 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1708
1709 rc = mwl8k_post_cmd(hw, &cmd->header);
1710
1711 if (!rc) {
1712 int off;
1713
1714 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1715 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1716 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1717 priv->hw_rev = cmd->hw_rev;
1718
1719 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1720 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1721
1722 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1723 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1724
1725 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1726 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1727
1728 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1729 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1730
1731 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1732 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1733
1734 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1735 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1736 }
1737
1738 kfree(cmd);
1739 return rc;
1740}
1741
1742/*
1743 * CMD_SET_HW_SPEC.
1744 */
1745struct mwl8k_cmd_set_hw_spec {
1746 struct mwl8k_cmd_pkt header;
1747 __u8 hw_rev;
1748 __u8 host_interface;
1749 __le16 num_mcaddrs;
1750 __u8 perm_addr[ETH_ALEN];
1751 __le16 region_code;
1752 __le32 fw_rev;
1753 __le32 ps_cookie;
1754 __le32 caps;
1755 __le32 rx_queue_ptr;
1756 __le32 num_tx_queues;
1757 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1758 __le32 flags;
1759 __le32 num_tx_desc_per_queue;
1760 __le32 total_rxd;
1761} __attribute__((packed));
1762
1763#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1764
1765static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1766{
1767 struct mwl8k_priv *priv = hw->priv;
1768 struct mwl8k_cmd_set_hw_spec *cmd;
1769 int rc;
1770 int i;
1771
1772 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1773 if (cmd == NULL)
1774 return -ENOMEM;
1775
1776 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1777 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1778
1779 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1780 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1781 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1782 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1783 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1784 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1785 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1786 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1787
1788 rc = mwl8k_post_cmd(hw, &cmd->header);
1789 kfree(cmd);
1790
1791 return rc;
1792}
1793
1794/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001795 * CMD_MAC_MULTICAST_ADR.
1796 */
1797struct mwl8k_cmd_mac_multicast_adr {
1798 struct mwl8k_cmd_pkt header;
1799 __le16 action;
1800 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001801 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001802};
1803
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001804#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1805#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1806#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1807#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001808
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001809static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001810__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001811 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001812{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001813 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001814 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001815 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001816
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001817 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001818 allmulti = 1;
1819 mc_count = 0;
1820 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001821
1822 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1823
1824 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001825 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001826 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001827
1828 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1829 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001830 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1831 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001832
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001833 if (allmulti) {
1834 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1835 } else if (mc_count) {
1836 int i;
1837
1838 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1839 cmd->numaddr = cpu_to_le16(mc_count);
1840 for (i = 0; i < mc_count && mclist; i++) {
1841 if (mclist->da_addrlen != ETH_ALEN) {
1842 kfree(cmd);
1843 return NULL;
1844 }
1845 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1846 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001847 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001848 }
1849
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001850 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001851}
1852
1853/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001854 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001855 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001856struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001857 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001858 __le32 stats[64];
1859} __attribute__((packed));
1860
1861#define MWL8K_STAT_ACK_FAILURE 9
1862#define MWL8K_STAT_RTS_FAILURE 12
1863#define MWL8K_STAT_FCS_ERROR 24
1864#define MWL8K_STAT_RTS_SUCCESS 11
1865
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001866static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1867 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001868{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001869 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001870 int rc;
1871
1872 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1873 if (cmd == NULL)
1874 return -ENOMEM;
1875
1876 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1877 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001878
1879 rc = mwl8k_post_cmd(hw, &cmd->header);
1880 if (!rc) {
1881 stats->dot11ACKFailureCount =
1882 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1883 stats->dot11RTSFailureCount =
1884 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1885 stats->dot11FCSErrorCount =
1886 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1887 stats->dot11RTSSuccessCount =
1888 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1889 }
1890 kfree(cmd);
1891
1892 return rc;
1893}
1894
1895/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001896 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001897 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001898struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001899 struct mwl8k_cmd_pkt header;
1900 __le16 action;
1901 __le16 control;
1902 __le16 radio_on;
1903} __attribute__((packed));
1904
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001905static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001906mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001907{
1908 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001909 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001910 int rc;
1911
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001912 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001913 return 0;
1914
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001915 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1916 if (cmd == NULL)
1917 return -ENOMEM;
1918
1919 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1920 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1921 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001922 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001923 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1924
1925 rc = mwl8k_post_cmd(hw, &cmd->header);
1926 kfree(cmd);
1927
1928 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001929 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001930
1931 return rc;
1932}
1933
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001934static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001935{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001936 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001937}
1938
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001939static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001940{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001941 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001942}
1943
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001944static int
1945mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1946{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01001947 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001948
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001949 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001950
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001951 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001952}
1953
1954/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001955 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001956 */
1957#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1958
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001959struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001960 struct mwl8k_cmd_pkt header;
1961 __le16 action;
1962 __le16 support_level;
1963 __le16 current_level;
1964 __le16 reserved;
1965 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1966} __attribute__((packed));
1967
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001968static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001969{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001970 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001971 int rc;
1972
1973 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1974 if (cmd == NULL)
1975 return -ENOMEM;
1976
1977 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1978 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1979 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1980 cmd->support_level = cpu_to_le16(dBm);
1981
1982 rc = mwl8k_post_cmd(hw, &cmd->header);
1983 kfree(cmd);
1984
1985 return rc;
1986}
1987
1988/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02001989 * CMD_RF_ANTENNA.
1990 */
1991struct mwl8k_cmd_rf_antenna {
1992 struct mwl8k_cmd_pkt header;
1993 __le16 antenna;
1994 __le16 mode;
1995} __attribute__((packed));
1996
1997#define MWL8K_RF_ANTENNA_RX 1
1998#define MWL8K_RF_ANTENNA_TX 2
1999
2000static int
2001mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2002{
2003 struct mwl8k_cmd_rf_antenna *cmd;
2004 int rc;
2005
2006 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2007 if (cmd == NULL)
2008 return -ENOMEM;
2009
2010 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2011 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2012 cmd->antenna = cpu_to_le16(antenna);
2013 cmd->mode = cpu_to_le16(mask);
2014
2015 rc = mwl8k_post_cmd(hw, &cmd->header);
2016 kfree(cmd);
2017
2018 return rc;
2019}
2020
2021/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002022 * CMD_SET_PRE_SCAN.
2023 */
2024struct mwl8k_cmd_set_pre_scan {
2025 struct mwl8k_cmd_pkt header;
2026} __attribute__((packed));
2027
2028static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2029{
2030 struct mwl8k_cmd_set_pre_scan *cmd;
2031 int rc;
2032
2033 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2034 if (cmd == NULL)
2035 return -ENOMEM;
2036
2037 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2038 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2039
2040 rc = mwl8k_post_cmd(hw, &cmd->header);
2041 kfree(cmd);
2042
2043 return rc;
2044}
2045
2046/*
2047 * CMD_SET_POST_SCAN.
2048 */
2049struct mwl8k_cmd_set_post_scan {
2050 struct mwl8k_cmd_pkt header;
2051 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002052 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002053} __attribute__((packed));
2054
2055static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002056mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002057{
2058 struct mwl8k_cmd_set_post_scan *cmd;
2059 int rc;
2060
2061 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2062 if (cmd == NULL)
2063 return -ENOMEM;
2064
2065 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2066 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2067 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002068 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002069
2070 rc = mwl8k_post_cmd(hw, &cmd->header);
2071 kfree(cmd);
2072
2073 return rc;
2074}
2075
2076/*
2077 * CMD_SET_RF_CHANNEL.
2078 */
2079struct mwl8k_cmd_set_rf_channel {
2080 struct mwl8k_cmd_pkt header;
2081 __le16 action;
2082 __u8 current_channel;
2083 __le32 channel_flags;
2084} __attribute__((packed));
2085
2086static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2087 struct ieee80211_channel *channel)
2088{
2089 struct mwl8k_cmd_set_rf_channel *cmd;
2090 int rc;
2091
2092 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2093 if (cmd == NULL)
2094 return -ENOMEM;
2095
2096 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2097 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2098 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2099 cmd->current_channel = channel->hw_value;
2100 if (channel->band == IEEE80211_BAND_2GHZ)
2101 cmd->channel_flags = cpu_to_le32(0x00000081);
2102 else
2103 cmd->channel_flags = cpu_to_le32(0x00000000);
2104
2105 rc = mwl8k_post_cmd(hw, &cmd->header);
2106 kfree(cmd);
2107
2108 return rc;
2109}
2110
2111/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002112 * CMD_SET_AID.
2113 */
2114#define MWL8K_FRAME_PROT_DISABLED 0x00
2115#define MWL8K_FRAME_PROT_11G 0x07
2116#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2117#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2118
2119struct mwl8k_cmd_update_set_aid {
2120 struct mwl8k_cmd_pkt header;
2121 __le16 aid;
2122
2123 /* AP's MAC address (BSSID) */
2124 __u8 bssid[ETH_ALEN];
2125 __le16 protection_mode;
2126 __u8 supp_rates[14];
2127} __attribute__((packed));
2128
2129static int
2130mwl8k_cmd_set_aid(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2131{
2132 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2133 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2134 struct mwl8k_cmd_update_set_aid *cmd;
2135 u16 prot_mode;
2136 int rc;
2137
2138 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2139 if (cmd == NULL)
2140 return -ENOMEM;
2141
2142 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2143 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2144 cmd->aid = cpu_to_le16(info->aid);
2145
2146 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
2147
2148 if (info->use_cts_prot) {
2149 prot_mode = MWL8K_FRAME_PROT_11G;
2150 } else {
2151 switch (info->ht_operation_mode &
2152 IEEE80211_HT_OP_MODE_PROTECTION) {
2153 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2154 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2155 break;
2156 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2157 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2158 break;
2159 default:
2160 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2161 break;
2162 }
2163 }
2164 cmd->protection_mode = cpu_to_le16(prot_mode);
2165
2166 memcpy(cmd->supp_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
2167
2168 rc = mwl8k_post_cmd(hw, &cmd->header);
2169 kfree(cmd);
2170
2171 return rc;
2172}
2173
2174/*
2175 * CMD_SET_RATE.
2176 */
2177struct mwl8k_cmd_set_rate {
2178 struct mwl8k_cmd_pkt header;
2179 __u8 legacy_rates[14];
2180
2181 /* Bitmap for supported MCS codes. */
2182 __u8 mcs_set[16];
2183 __u8 reserved[16];
2184} __attribute__((packed));
2185
2186static int
2187mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2188{
2189 struct mwl8k_cmd_set_rate *cmd;
2190 int rc;
2191
2192 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2193 if (cmd == NULL)
2194 return -ENOMEM;
2195
2196 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2197 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2198 memcpy(cmd->legacy_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
2199
2200 rc = mwl8k_post_cmd(hw, &cmd->header);
2201 kfree(cmd);
2202
2203 return rc;
2204}
2205
2206/*
2207 * CMD_FINALIZE_JOIN.
2208 */
2209#define MWL8K_FJ_BEACON_MAXLEN 128
2210
2211struct mwl8k_cmd_finalize_join {
2212 struct mwl8k_cmd_pkt header;
2213 __le32 sleep_interval; /* Number of beacon periods to sleep */
2214 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2215} __attribute__((packed));
2216
2217static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2218 int framelen, int dtim)
2219{
2220 struct mwl8k_cmd_finalize_join *cmd;
2221 struct ieee80211_mgmt *payload = frame;
2222 int payload_len;
2223 int rc;
2224
2225 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2226 if (cmd == NULL)
2227 return -ENOMEM;
2228
2229 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2230 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2231 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2232
2233 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2234 if (payload_len < 0)
2235 payload_len = 0;
2236 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2237 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2238
2239 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2240
2241 rc = mwl8k_post_cmd(hw, &cmd->header);
2242 kfree(cmd);
2243
2244 return rc;
2245}
2246
2247/*
2248 * CMD_SET_RTS_THRESHOLD.
2249 */
2250struct mwl8k_cmd_set_rts_threshold {
2251 struct mwl8k_cmd_pkt header;
2252 __le16 action;
2253 __le16 threshold;
2254} __attribute__((packed));
2255
2256static int mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw,
2257 u16 action, u16 threshold)
2258{
2259 struct mwl8k_cmd_set_rts_threshold *cmd;
2260 int rc;
2261
2262 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2263 if (cmd == NULL)
2264 return -ENOMEM;
2265
2266 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2267 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2268 cmd->action = cpu_to_le16(action);
2269 cmd->threshold = cpu_to_le16(threshold);
2270
2271 rc = mwl8k_post_cmd(hw, &cmd->header);
2272 kfree(cmd);
2273
2274 return rc;
2275}
2276
2277/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002278 * CMD_SET_SLOT.
2279 */
2280struct mwl8k_cmd_set_slot {
2281 struct mwl8k_cmd_pkt header;
2282 __le16 action;
2283 __u8 short_slot;
2284} __attribute__((packed));
2285
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002286static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002287{
2288 struct mwl8k_cmd_set_slot *cmd;
2289 int rc;
2290
2291 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2292 if (cmd == NULL)
2293 return -ENOMEM;
2294
2295 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2296 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2297 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002298 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002299
2300 rc = mwl8k_post_cmd(hw, &cmd->header);
2301 kfree(cmd);
2302
2303 return rc;
2304}
2305
2306/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002307 * CMD_SET_EDCA_PARAMS.
2308 */
2309struct mwl8k_cmd_set_edca_params {
2310 struct mwl8k_cmd_pkt header;
2311
2312 /* See MWL8K_SET_EDCA_XXX below */
2313 __le16 action;
2314
2315 /* TX opportunity in units of 32 us */
2316 __le16 txop;
2317
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002318 union {
2319 struct {
2320 /* Log exponent of max contention period: 0...15 */
2321 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002322
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002323 /* Log exponent of min contention period: 0...15 */
2324 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002325
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002326 /* Adaptive interframe spacing in units of 32us */
2327 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002328
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002329 /* TX queue to configure */
2330 __u8 txq;
2331 } ap;
2332 struct {
2333 /* Log exponent of max contention period: 0...15 */
2334 __u8 log_cw_max;
2335
2336 /* Log exponent of min contention period: 0...15 */
2337 __u8 log_cw_min;
2338
2339 /* Adaptive interframe spacing in units of 32us */
2340 __u8 aifs;
2341
2342 /* TX queue to configure */
2343 __u8 txq;
2344 } sta;
2345 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002346} __attribute__((packed));
2347
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002348#define MWL8K_SET_EDCA_CW 0x01
2349#define MWL8K_SET_EDCA_TXOP 0x02
2350#define MWL8K_SET_EDCA_AIFS 0x04
2351
2352#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2353 MWL8K_SET_EDCA_TXOP | \
2354 MWL8K_SET_EDCA_AIFS)
2355
2356static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002357mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2358 __u16 cw_min, __u16 cw_max,
2359 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002360{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002361 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002362 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002363 int rc;
2364
2365 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2366 if (cmd == NULL)
2367 return -ENOMEM;
2368
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002369 /*
2370 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2371 * this call.
2372 */
2373 qnum ^= !(qnum >> 1);
2374
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002375 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2376 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002377 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2378 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002379 if (priv->ap_fw) {
2380 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2381 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2382 cmd->ap.aifs = aifs;
2383 cmd->ap.txq = qnum;
2384 } else {
2385 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2386 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2387 cmd->sta.aifs = aifs;
2388 cmd->sta.txq = qnum;
2389 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002390
2391 rc = mwl8k_post_cmd(hw, &cmd->header);
2392 kfree(cmd);
2393
2394 return rc;
2395}
2396
2397/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002398 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002399 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002400struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002401 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002402 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002403} __attribute__((packed));
2404
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002405static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002406{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002407 struct mwl8k_priv *priv = hw->priv;
2408 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002409 int rc;
2410
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002411 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2412 if (cmd == NULL)
2413 return -ENOMEM;
2414
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002415 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002416 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002417 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002418
2419 rc = mwl8k_post_cmd(hw, &cmd->header);
2420 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002421
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002422 if (!rc)
2423 priv->wmm_enabled = enable;
2424
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002425 return rc;
2426}
2427
2428/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002429 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002430 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002431struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002432 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002433 __le32 action;
2434 __u8 rx_antenna_map;
2435 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002436} __attribute__((packed));
2437
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002438static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002439{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002440 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002441 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002442
2443 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2444 if (cmd == NULL)
2445 return -ENOMEM;
2446
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002447 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002448 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002449 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2450 cmd->rx_antenna_map = rx;
2451 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002452
2453 rc = mwl8k_post_cmd(hw, &cmd->header);
2454 kfree(cmd);
2455
2456 return rc;
2457}
2458
2459/*
2460 * CMD_USE_FIXED_RATE.
2461 */
2462#define MWL8K_RATE_TABLE_SIZE 8
2463#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002464#define MWL8K_USE_AUTO_RATE 0x0002
2465
2466struct mwl8k_rate_entry {
2467 /* Set to 1 if HT rate, 0 if legacy. */
2468 __le32 is_ht_rate;
2469
2470 /* Set to 1 to use retry_count field. */
2471 __le32 enable_retry;
2472
2473 /* Specified legacy rate or MCS. */
2474 __le32 rate;
2475
2476 /* Number of allowed retries. */
2477 __le32 retry_count;
2478} __attribute__((packed));
2479
2480struct mwl8k_rate_table {
2481 /* 1 to allow specified rate and below */
2482 __le32 allow_rate_drop;
2483 __le32 num_rates;
2484 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2485} __attribute__((packed));
2486
2487struct mwl8k_cmd_use_fixed_rate {
2488 struct mwl8k_cmd_pkt header;
2489 __le32 action;
2490 struct mwl8k_rate_table rate_table;
2491
2492 /* Unicast, Broadcast or Multicast */
2493 __le32 rate_type;
2494 __le32 reserved1;
2495 __le32 reserved2;
2496} __attribute__((packed));
2497
2498static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2499 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2500{
2501 struct mwl8k_cmd_use_fixed_rate *cmd;
2502 int count;
2503 int rc;
2504
2505 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2506 if (cmd == NULL)
2507 return -ENOMEM;
2508
2509 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2510 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2511
2512 cmd->action = cpu_to_le32(action);
2513 cmd->rate_type = cpu_to_le32(rate_type);
2514
2515 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002516 /*
2517 * Copy over each field manually so that endian
2518 * conversion can be done.
2519 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002520 cmd->rate_table.allow_rate_drop =
2521 cpu_to_le32(rate_table->allow_rate_drop);
2522 cmd->rate_table.num_rates =
2523 cpu_to_le32(rate_table->num_rates);
2524
2525 for (count = 0; count < rate_table->num_rates; count++) {
2526 struct mwl8k_rate_entry *dst =
2527 &cmd->rate_table.rate_entry[count];
2528 struct mwl8k_rate_entry *src =
2529 &rate_table->rate_entry[count];
2530
2531 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2532 dst->enable_retry = cpu_to_le32(src->enable_retry);
2533 dst->rate = cpu_to_le32(src->rate);
2534 dst->retry_count = cpu_to_le32(src->retry_count);
2535 }
2536 }
2537
2538 rc = mwl8k_post_cmd(hw, &cmd->header);
2539 kfree(cmd);
2540
2541 return rc;
2542}
2543
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002544/*
2545 * CMD_ENABLE_SNIFFER.
2546 */
2547struct mwl8k_cmd_enable_sniffer {
2548 struct mwl8k_cmd_pkt header;
2549 __le32 action;
2550} __attribute__((packed));
2551
2552static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2553{
2554 struct mwl8k_cmd_enable_sniffer *cmd;
2555 int rc;
2556
2557 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2558 if (cmd == NULL)
2559 return -ENOMEM;
2560
2561 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2562 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2563 cmd->action = cpu_to_le32(!!enable);
2564
2565 rc = mwl8k_post_cmd(hw, &cmd->header);
2566 kfree(cmd);
2567
2568 return rc;
2569}
2570
2571/*
2572 * CMD_SET_MAC_ADDR.
2573 */
2574struct mwl8k_cmd_set_mac_addr {
2575 struct mwl8k_cmd_pkt header;
2576 union {
2577 struct {
2578 __le16 mac_type;
2579 __u8 mac_addr[ETH_ALEN];
2580 } mbss;
2581 __u8 mac_addr[ETH_ALEN];
2582 };
2583} __attribute__((packed));
2584
2585static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2586{
2587 struct mwl8k_priv *priv = hw->priv;
2588 struct mwl8k_cmd_set_mac_addr *cmd;
2589 int rc;
2590
2591 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2592 if (cmd == NULL)
2593 return -ENOMEM;
2594
2595 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2596 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2597 if (priv->ap_fw) {
2598 cmd->mbss.mac_type = 0;
2599 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2600 } else {
2601 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2602 }
2603
2604 rc = mwl8k_post_cmd(hw, &cmd->header);
2605 kfree(cmd);
2606
2607 return rc;
2608}
2609
2610/*
2611 * CMD_SET_RATEADAPT_MODE.
2612 */
2613struct mwl8k_cmd_set_rate_adapt_mode {
2614 struct mwl8k_cmd_pkt header;
2615 __le16 action;
2616 __le16 mode;
2617} __attribute__((packed));
2618
2619static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2620{
2621 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2622 int rc;
2623
2624 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2625 if (cmd == NULL)
2626 return -ENOMEM;
2627
2628 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2629 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2630 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2631 cmd->mode = cpu_to_le16(mode);
2632
2633 rc = mwl8k_post_cmd(hw, &cmd->header);
2634 kfree(cmd);
2635
2636 return rc;
2637}
2638
2639/*
2640 * CMD_UPDATE_STADB.
2641 */
2642struct mwl8k_cmd_update_stadb {
2643 struct mwl8k_cmd_pkt header;
2644
2645 /* See STADB_ACTION_TYPE */
2646 __le32 action;
2647
2648 /* Peer MAC address */
2649 __u8 peer_addr[ETH_ALEN];
2650
2651 __le32 reserved;
2652
2653 /* Peer info - valid during add/update. */
2654 struct peer_capability_info peer_info;
2655} __attribute__((packed));
2656
2657static int mwl8k_cmd_update_stadb(struct ieee80211_hw *hw,
2658 struct ieee80211_vif *vif, __u32 action)
2659{
2660 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2661 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2662 struct mwl8k_cmd_update_stadb *cmd;
2663 struct peer_capability_info *peer_info;
2664 int rc;
2665
2666 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2667 if (cmd == NULL)
2668 return -ENOMEM;
2669
2670 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2671 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2672
2673 cmd->action = cpu_to_le32(action);
2674 peer_info = &cmd->peer_info;
2675 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2676
2677 switch (action) {
2678 case MWL8K_STA_DB_ADD_ENTRY:
2679 case MWL8K_STA_DB_MODIFY_ENTRY:
2680 /* Build peer_info block */
2681 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2682 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2683 memcpy(peer_info->legacy_rates, mwl8k_rateids,
2684 sizeof(mwl8k_rateids));
2685 peer_info->interop = 1;
2686 peer_info->amsdu_enabled = 0;
2687
2688 rc = mwl8k_post_cmd(hw, &cmd->header);
2689 if (rc == 0)
2690 mv_vif->peer_id = peer_info->station_id;
2691
2692 break;
2693
2694 case MWL8K_STA_DB_DEL_ENTRY:
2695 case MWL8K_STA_DB_FLUSH:
2696 default:
2697 rc = mwl8k_post_cmd(hw, &cmd->header);
2698 if (rc == 0)
2699 mv_vif->peer_id = 0;
2700 break;
2701 }
2702 kfree(cmd);
2703
2704 return rc;
2705}
2706
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002707
2708/*
2709 * Interrupt handling.
2710 */
2711static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2712{
2713 struct ieee80211_hw *hw = dev_id;
2714 struct mwl8k_priv *priv = hw->priv;
2715 u32 status;
2716
2717 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2718 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2719
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002720 if (!status)
2721 return IRQ_NONE;
2722
2723 if (status & MWL8K_A2H_INT_TX_DONE)
2724 tasklet_schedule(&priv->tx_reclaim_task);
2725
2726 if (status & MWL8K_A2H_INT_RX_READY) {
2727 while (rxq_process(hw, 0, 1))
2728 rxq_refill(hw, 0, 1);
2729 }
2730
2731 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002732 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002733 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002734 }
2735
2736 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002737 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002738 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002739 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002740 }
2741
2742 return IRQ_HANDLED;
2743}
2744
2745
2746/*
2747 * Core driver operations.
2748 */
2749static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2750{
2751 struct mwl8k_priv *priv = hw->priv;
2752 int index = skb_get_queue_mapping(skb);
2753 int rc;
2754
2755 if (priv->current_channel == NULL) {
2756 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002757 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002758 dev_kfree_skb(skb);
2759 return NETDEV_TX_OK;
2760 }
2761
2762 rc = mwl8k_txq_xmit(hw, index, skb);
2763
2764 return rc;
2765}
2766
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002767static int mwl8k_start(struct ieee80211_hw *hw)
2768{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002769 struct mwl8k_priv *priv = hw->priv;
2770 int rc;
2771
Joe Perchesa0607fd2009-11-18 23:29:17 -08002772 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002773 IRQF_SHARED, MWL8K_NAME, hw);
2774 if (rc) {
2775 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002776 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002777 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002778 }
2779
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002780 /* Enable tx reclaim tasklet */
2781 tasklet_enable(&priv->tx_reclaim_task);
2782
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002783 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002784 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002785
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002786 rc = mwl8k_fw_lock(hw);
2787 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002788 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002789
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002790 if (!priv->ap_fw) {
2791 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002792 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002793
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002794 if (!rc)
2795 rc = mwl8k_cmd_set_pre_scan(hw);
2796
2797 if (!rc)
2798 rc = mwl8k_cmd_set_post_scan(hw,
2799 "\x00\x00\x00\x00\x00\x00");
2800 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002801
2802 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002803 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002804
2805 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002806 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002807
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002808 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002809 }
2810
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002811 if (rc) {
2812 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2813 free_irq(priv->pdev->irq, hw);
2814 tasklet_disable(&priv->tx_reclaim_task);
2815 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002816
2817 return rc;
2818}
2819
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002820static void mwl8k_stop(struct ieee80211_hw *hw)
2821{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002822 struct mwl8k_priv *priv = hw->priv;
2823 int i;
2824
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002825 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002826
2827 ieee80211_stop_queues(hw);
2828
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002829 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002830 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002831 free_irq(priv->pdev->irq, hw);
2832
2833 /* Stop finalize join worker */
2834 cancel_work_sync(&priv->finalize_join_worker);
2835 if (priv->beacon_skb != NULL)
2836 dev_kfree_skb(priv->beacon_skb);
2837
2838 /* Stop tx reclaim tasklet */
2839 tasklet_disable(&priv->tx_reclaim_task);
2840
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002841 /* Return all skbs to mac80211 */
2842 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2843 mwl8k_txq_reclaim(hw, i, 1);
2844}
2845
2846static int mwl8k_add_interface(struct ieee80211_hw *hw,
2847 struct ieee80211_if_init_conf *conf)
2848{
2849 struct mwl8k_priv *priv = hw->priv;
2850 struct mwl8k_vif *mwl8k_vif;
2851
2852 /*
2853 * We only support one active interface at a time.
2854 */
2855 if (priv->vif != NULL)
2856 return -EBUSY;
2857
2858 /*
2859 * We only support managed interfaces for now.
2860 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002861 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002862 return -EINVAL;
2863
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002864 /*
2865 * Reject interface creation if sniffer mode is active, as
2866 * STA operation is mutually exclusive with hardware sniffer
2867 * mode.
2868 */
2869 if (priv->sniffer_enabled) {
2870 printk(KERN_INFO "%s: unable to create STA "
2871 "interface due to sniffer mode being enabled\n",
2872 wiphy_name(hw->wiphy));
2873 return -EINVAL;
2874 }
2875
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002876 /* Clean out driver private area */
2877 mwl8k_vif = MWL8K_VIF(conf->vif);
2878 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2879
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002880 /* Set and save the mac address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002881 mwl8k_cmd_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002882 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002883
2884 /* Back pointer to parent config block */
2885 mwl8k_vif->priv = priv;
2886
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002887 /* Set Initial sequence number to zero */
2888 mwl8k_vif->seqno = 0;
2889
2890 priv->vif = conf->vif;
2891 priv->current_channel = NULL;
2892
2893 return 0;
2894}
2895
2896static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2897 struct ieee80211_if_init_conf *conf)
2898{
2899 struct mwl8k_priv *priv = hw->priv;
2900
2901 if (priv->vif == NULL)
2902 return;
2903
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002904 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002905
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002906 priv->vif = NULL;
2907}
2908
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002909static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002910{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002911 struct ieee80211_conf *conf = &hw->conf;
2912 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002913 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002914
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002915 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002916 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002917 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002918 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002919 }
2920
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002921 rc = mwl8k_fw_lock(hw);
2922 if (rc)
2923 return rc;
2924
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002925 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002926 if (rc)
2927 goto out;
2928
2929 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2930 if (rc)
2931 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002932
2933 priv->current_channel = conf->channel;
2934
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002935 if (conf->power_level > 18)
2936 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002937 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002938 if (rc)
2939 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002940
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002941 if (priv->ap_fw) {
2942 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2943 if (!rc)
2944 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2945 } else {
2946 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2947 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002948
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002949out:
2950 mwl8k_fw_unlock(hw);
2951
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002952 return rc;
2953}
2954
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002955static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
2956 struct ieee80211_vif *vif,
2957 struct ieee80211_bss_conf *info,
2958 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002959{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002960 struct mwl8k_priv *priv = hw->priv;
2961 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002962 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002963
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002964 if ((changed & BSS_CHANGED_ASSOC) == 0)
2965 return;
2966
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002967 priv->capture_beacon = false;
2968
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002969 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02002970 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002971 return;
2972
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002973 if (info->assoc) {
2974 memcpy(&mwl8k_vif->bss_info, info,
2975 sizeof(struct ieee80211_bss_conf));
2976
Lennert Buytenhekd1844d72009-11-30 18:13:56 +01002977 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
2978
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002979 /* Install rates */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002980 rc = mwl8k_cmd_set_rate(hw, vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002981 if (rc)
2982 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002983
2984 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002985 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
2986 MWL8K_UCAST_RATE, NULL);
2987 if (rc)
2988 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002989
2990 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002991 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
2992 if (rc)
2993 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002994
2995 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002996 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
2997 if (rc)
2998 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002999
3000 /* Update peer rate info */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003001 rc = mwl8k_cmd_update_stadb(hw, vif,
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003002 MWL8K_STA_DB_MODIFY_ENTRY);
3003 if (rc)
3004 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003005
3006 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003007 rc = mwl8k_cmd_set_aid(hw, vif);
3008 if (rc)
3009 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003010
3011 /*
3012 * Finalize the join. Tell rx handler to process
3013 * next beacon from our BSSID.
3014 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003015 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003016 priv->capture_beacon = true;
3017 } else {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003018 rc = mwl8k_cmd_update_stadb(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003019 memset(&mwl8k_vif->bss_info, 0,
3020 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003021 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003022 }
3023
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003024out:
3025 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003026}
3027
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003028static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3029 int mc_count, struct dev_addr_list *mclist)
3030{
3031 struct mwl8k_cmd_pkt *cmd;
3032
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003033 /*
3034 * Synthesize and return a command packet that programs the
3035 * hardware multicast address filter. At this point we don't
3036 * know whether FIF_ALLMULTI is being requested, but if it is,
3037 * we'll end up throwing this packet away and creating a new
3038 * one in mwl8k_configure_filter().
3039 */
3040 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003041
3042 return (unsigned long)cmd;
3043}
3044
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003045static int
3046mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3047 unsigned int changed_flags,
3048 unsigned int *total_flags)
3049{
3050 struct mwl8k_priv *priv = hw->priv;
3051
3052 /*
3053 * Hardware sniffer mode is mutually exclusive with STA
3054 * operation, so refuse to enable sniffer mode if a STA
3055 * interface is active.
3056 */
3057 if (priv->vif != NULL) {
3058 if (net_ratelimit())
3059 printk(KERN_INFO "%s: not enabling sniffer "
3060 "mode because STA interface is active\n",
3061 wiphy_name(hw->wiphy));
3062 return 0;
3063 }
3064
3065 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003066 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003067 return 0;
3068 priv->sniffer_enabled = true;
3069 }
3070
3071 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3072 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3073 FIF_OTHER_BSS;
3074
3075 return 1;
3076}
3077
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003078static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3079 unsigned int changed_flags,
3080 unsigned int *total_flags,
3081 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003082{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003083 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003084 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3085
3086 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003087 * AP firmware doesn't allow fine-grained control over
3088 * the receive filter.
3089 */
3090 if (priv->ap_fw) {
3091 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3092 kfree(cmd);
3093 return;
3094 }
3095
3096 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003097 * Enable hardware sniffer mode if FIF_CONTROL or
3098 * FIF_OTHER_BSS is requested.
3099 */
3100 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3101 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3102 kfree(cmd);
3103 return;
3104 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003105
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003106 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003107 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003108
3109 if (mwl8k_fw_lock(hw))
3110 return;
3111
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003112 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003113 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003114 priv->sniffer_enabled = false;
3115 }
3116
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003117 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003118 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3119 /*
3120 * Disable the BSS filter.
3121 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003122 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003123 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003124 u8 *bssid;
3125
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003126 /*
3127 * Enable the BSS filter.
3128 *
3129 * If there is an active STA interface, use that
3130 * interface's BSSID, otherwise use a dummy one
3131 * (where the OUI part needs to be nonzero for
3132 * the BSSID to be accepted by POST_SCAN).
3133 */
3134 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003135 if (priv->vif != NULL)
3136 bssid = MWL8K_VIF(priv->vif)->bssid;
3137
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003138 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003139 }
3140 }
3141
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003142 /*
3143 * If FIF_ALLMULTI is being requested, throw away the command
3144 * packet that ->prepare_multicast() built and replace it with
3145 * a command packet that enables reception of all multicast
3146 * packets.
3147 */
3148 if (*total_flags & FIF_ALLMULTI) {
3149 kfree(cmd);
3150 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3151 }
3152
3153 if (cmd != NULL) {
3154 mwl8k_post_cmd(hw, cmd);
3155 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003156 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003157
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003158 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003159}
3160
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003161static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3162{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003163 return mwl8k_cmd_set_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003164}
3165
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003166static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3167 const struct ieee80211_tx_queue_params *params)
3168{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003169 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003170 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003171
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003172 rc = mwl8k_fw_lock(hw);
3173 if (!rc) {
3174 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003175 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003176
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003177 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003178 rc = mwl8k_cmd_set_edca_params(hw, queue,
3179 params->cw_min,
3180 params->cw_max,
3181 params->aifs,
3182 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003183
3184 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003185 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003186
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003187 return rc;
3188}
3189
3190static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3191 struct ieee80211_tx_queue_stats *stats)
3192{
3193 struct mwl8k_priv *priv = hw->priv;
3194 struct mwl8k_tx_queue *txq;
3195 int index;
3196
3197 spin_lock_bh(&priv->tx_lock);
3198 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3199 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003200 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003201 sizeof(struct ieee80211_tx_queue_stats));
3202 }
3203 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003204
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003205 return 0;
3206}
3207
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003208static int mwl8k_get_stats(struct ieee80211_hw *hw,
3209 struct ieee80211_low_level_stats *stats)
3210{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003211 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003212}
3213
3214static const struct ieee80211_ops mwl8k_ops = {
3215 .tx = mwl8k_tx,
3216 .start = mwl8k_start,
3217 .stop = mwl8k_stop,
3218 .add_interface = mwl8k_add_interface,
3219 .remove_interface = mwl8k_remove_interface,
3220 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003221 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003222 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003223 .configure_filter = mwl8k_configure_filter,
3224 .set_rts_threshold = mwl8k_set_rts_threshold,
3225 .conf_tx = mwl8k_conf_tx,
3226 .get_tx_stats = mwl8k_get_tx_stats,
3227 .get_stats = mwl8k_get_stats,
3228};
3229
3230static void mwl8k_tx_reclaim_handler(unsigned long data)
3231{
3232 int i;
3233 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3234 struct mwl8k_priv *priv = hw->priv;
3235
3236 spin_lock_bh(&priv->tx_lock);
3237 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3238 mwl8k_txq_reclaim(hw, i, 0);
3239
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003240 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003241 complete(priv->tx_wait);
3242 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003243 }
3244 spin_unlock_bh(&priv->tx_lock);
3245}
3246
3247static void mwl8k_finalize_join_worker(struct work_struct *work)
3248{
3249 struct mwl8k_priv *priv =
3250 container_of(work, struct mwl8k_priv, finalize_join_worker);
3251 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003252 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003253
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003254 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003255 dev_kfree_skb(skb);
3256
3257 priv->beacon_skb = NULL;
3258}
3259
John W. Linvillebcb628d2009-11-06 16:40:16 -05003260enum {
3261 MWL8687 = 0,
3262 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003263};
3264
John W. Linvillebcb628d2009-11-06 16:40:16 -05003265static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003266 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003267 .part_name = "88w8687",
3268 .helper_image = "mwl8k/helper_8687.fw",
3269 .fw_image = "mwl8k/fmimage_8687.fw",
3270 .rxd_ops = &rxd_8687_ops,
3271 .modes = BIT(NL80211_IFTYPE_STATION),
3272 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003273 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003274 .part_name = "88w8366",
3275 .helper_image = "mwl8k/helper_8366.fw",
3276 .fw_image = "mwl8k/fmimage_8366.fw",
3277 .rxd_ops = &rxd_8366_ops,
3278 .modes = 0,
3279 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003280};
3281
3282static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003283 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3284 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3285 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3286 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003287};
3288MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3289
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003290static int __devinit mwl8k_probe(struct pci_dev *pdev,
3291 const struct pci_device_id *id)
3292{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003293 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003294 struct ieee80211_hw *hw;
3295 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003296 int rc;
3297 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003298
3299 if (!printed_version) {
3300 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3301 printed_version = 1;
3302 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003303
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003304
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003305 rc = pci_enable_device(pdev);
3306 if (rc) {
3307 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3308 MWL8K_NAME);
3309 return rc;
3310 }
3311
3312 rc = pci_request_regions(pdev, MWL8K_NAME);
3313 if (rc) {
3314 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3315 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003316 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003317 }
3318
3319 pci_set_master(pdev);
3320
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003321
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003322 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3323 if (hw == NULL) {
3324 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3325 rc = -ENOMEM;
3326 goto err_free_reg;
3327 }
3328
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003329 SET_IEEE80211_DEV(hw, &pdev->dev);
3330 pci_set_drvdata(pdev, hw);
3331
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003332 priv = hw->priv;
3333 priv->hw = hw;
3334 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003335 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003336
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003337
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003338 priv->sram = pci_iomap(pdev, 0, 0x10000);
3339 if (priv->sram == NULL) {
3340 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003341 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003342 goto err_iounmap;
3343 }
3344
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003345 /*
3346 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3347 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3348 */
3349 priv->regs = pci_iomap(pdev, 1, 0x10000);
3350 if (priv->regs == NULL) {
3351 priv->regs = pci_iomap(pdev, 2, 0x10000);
3352 if (priv->regs == NULL) {
3353 printk(KERN_ERR "%s: Cannot map device registers\n",
3354 wiphy_name(hw->wiphy));
3355 goto err_iounmap;
3356 }
3357 }
3358
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003359
3360 /* Reset firmware and hardware */
3361 mwl8k_hw_reset(priv);
3362
3363 /* Ask userland hotplug daemon for the device firmware */
3364 rc = mwl8k_request_firmware(priv);
3365 if (rc) {
3366 printk(KERN_ERR "%s: Firmware files not found\n",
3367 wiphy_name(hw->wiphy));
3368 goto err_stop_firmware;
3369 }
3370
3371 /* Load firmware into hardware */
3372 rc = mwl8k_load_firmware(hw);
3373 if (rc) {
3374 printk(KERN_ERR "%s: Cannot start firmware\n",
3375 wiphy_name(hw->wiphy));
3376 goto err_stop_firmware;
3377 }
3378
3379 /* Reclaim memory once firmware is successfully loaded */
3380 mwl8k_release_firmware(priv);
3381
3382
3383 priv->rxd_ops = priv->device_info->rxd_ops;
3384
3385 priv->sniffer_enabled = false;
3386 priv->wmm_enabled = false;
3387 priv->pending_tx_pkts = 0;
3388
3389
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003390 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3391 priv->band.band = IEEE80211_BAND_2GHZ;
3392 priv->band.channels = priv->channels;
3393 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3394 priv->band.bitrates = priv->rates;
3395 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3396 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3397
3398 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3399 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3400
3401 /*
3402 * Extra headroom is the size of the required DMA header
3403 * minus the size of the smallest 802.11 frame (CTS frame).
3404 */
3405 hw->extra_tx_headroom =
3406 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3407
3408 hw->channel_change_time = 10;
3409
3410 hw->queues = MWL8K_TX_QUEUES;
3411
Lennert Buytenhek547810e2009-10-22 20:21:02 +02003412 hw->wiphy->interface_modes = priv->device_info->modes;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003413
3414 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003415 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003416 hw->vif_data_size = sizeof(struct mwl8k_vif);
3417 priv->vif = NULL;
3418
3419 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003420 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003421 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003422
3423 /* Finalize join worker */
3424 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3425
3426 /* TX reclaim tasklet */
3427 tasklet_init(&priv->tx_reclaim_task,
3428 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3429 tasklet_disable(&priv->tx_reclaim_task);
3430
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003431 /* Power management cookie */
3432 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3433 if (priv->cookie == NULL)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003434 goto err_stop_firmware;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003435
3436 rc = mwl8k_rxq_init(hw, 0);
3437 if (rc)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003438 goto err_free_cookie;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003439 rxq_refill(hw, 0, INT_MAX);
3440
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003441 mutex_init(&priv->fw_mutex);
3442 priv->fw_mutex_owner = NULL;
3443 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003444 priv->hostcmd_wait = NULL;
3445
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003446 spin_lock_init(&priv->tx_lock);
3447
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003448 priv->tx_wait = NULL;
3449
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003450 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3451 rc = mwl8k_txq_init(hw, i);
3452 if (rc)
3453 goto err_free_queues;
3454 }
3455
3456 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003457 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003458 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3459 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3460
Joe Perchesa0607fd2009-11-18 23:29:17 -08003461 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003462 IRQF_SHARED, MWL8K_NAME, hw);
3463 if (rc) {
3464 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003465 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003466 goto err_free_queues;
3467 }
3468
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003469 /*
3470 * Temporarily enable interrupts. Initial firmware host
3471 * commands use interrupts and avoids polling. Disable
3472 * interrupts when done.
3473 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003474 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003475
3476 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02003477 if (priv->ap_fw) {
3478 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3479 if (!rc)
3480 rc = mwl8k_cmd_set_hw_spec(hw);
3481 } else {
3482 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3483 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003484 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003485 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3486 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003487 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003488 }
3489
3490 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003491 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003492 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003493 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003494 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003495 }
3496
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003497 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003498 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003499 if (rc) {
3500 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3501 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003502 goto err_free_irq;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003503 }
3504
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003505 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003506 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003507 free_irq(priv->pdev->irq, hw);
3508
3509 rc = ieee80211_register_hw(hw);
3510 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003511 printk(KERN_ERR "%s: Cannot register device\n",
3512 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003513 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003514 }
3515
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003516 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003517 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003518 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003519 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003520 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3521 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003522
3523 return 0;
3524
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003525err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003526 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003527 free_irq(priv->pdev->irq, hw);
3528
3529err_free_queues:
3530 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3531 mwl8k_txq_deinit(hw, i);
3532 mwl8k_rxq_deinit(hw, 0);
3533
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003534err_free_cookie:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003535 if (priv->cookie != NULL)
3536 pci_free_consistent(priv->pdev, 4,
3537 priv->cookie, priv->cookie_dma);
3538
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003539err_stop_firmware:
3540 mwl8k_hw_reset(priv);
3541 mwl8k_release_firmware(priv);
3542
3543err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003544 if (priv->regs != NULL)
3545 pci_iounmap(pdev, priv->regs);
3546
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003547 if (priv->sram != NULL)
3548 pci_iounmap(pdev, priv->sram);
3549
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003550 pci_set_drvdata(pdev, NULL);
3551 ieee80211_free_hw(hw);
3552
3553err_free_reg:
3554 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003555
3556err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003557 pci_disable_device(pdev);
3558
3559 return rc;
3560}
3561
Joerg Albert230f7af2009-04-18 02:10:45 +02003562static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003563{
3564 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3565}
3566
Joerg Albert230f7af2009-04-18 02:10:45 +02003567static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003568{
3569 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3570 struct mwl8k_priv *priv;
3571 int i;
3572
3573 if (hw == NULL)
3574 return;
3575 priv = hw->priv;
3576
3577 ieee80211_stop_queues(hw);
3578
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003579 ieee80211_unregister_hw(hw);
3580
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003581 /* Remove tx reclaim tasklet */
3582 tasklet_kill(&priv->tx_reclaim_task);
3583
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003584 /* Stop hardware */
3585 mwl8k_hw_reset(priv);
3586
3587 /* Return all skbs to mac80211 */
3588 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3589 mwl8k_txq_reclaim(hw, i, 1);
3590
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003591 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3592 mwl8k_txq_deinit(hw, i);
3593
3594 mwl8k_rxq_deinit(hw, 0);
3595
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003596 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003597
3598 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003599 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003600 pci_set_drvdata(pdev, NULL);
3601 ieee80211_free_hw(hw);
3602 pci_release_regions(pdev);
3603 pci_disable_device(pdev);
3604}
3605
3606static struct pci_driver mwl8k_driver = {
3607 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003608 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003609 .probe = mwl8k_probe,
3610 .remove = __devexit_p(mwl8k_remove),
3611 .shutdown = __devexit_p(mwl8k_shutdown),
3612};
3613
3614static int __init mwl8k_init(void)
3615{
3616 return pci_register_driver(&mwl8k_driver);
3617}
3618
3619static void __exit mwl8k_exit(void)
3620{
3621 pci_unregister_driver(&mwl8k_driver);
3622}
3623
3624module_init(mwl8k_init);
3625module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003626
3627MODULE_DESCRIPTION(MWL8K_DESC);
3628MODULE_VERSION(MWL8K_VERSION);
3629MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3630MODULE_LICENSE("GPL");