blob: 19fe7124d93a991eb070a1ba57934f650bd35a02 [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 Buytenhek5b9482d2009-10-22 20:20:43 +0200130 void __iomem *sram;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131 void __iomem *regs;
132 struct ieee80211_hw *hw;
133
134 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100135
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200136 struct mwl8k_device_info *device_info;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200137 bool ap_fw;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200138 struct rxd_ops *rxd_ops;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200139
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100140 /* firmware files and meta data */
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100141 struct firmware *fw_helper;
142 struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100143
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200144 /* firmware access */
145 struct mutex fw_mutex;
146 struct task_struct *fw_mutex_owner;
147 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200148 struct completion *hostcmd_wait;
149
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100150 /* lock held over TX and TX reap */
151 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100152
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200153 /* TX quiesce completion, protected by fw_mutex and tx_lock */
154 struct completion *tx_wait;
155
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100156 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100157
158 struct ieee80211_channel *current_channel;
159
160 /* power management status cookie from firmware */
161 u32 *cookie;
162 dma_addr_t cookie_dma;
163
164 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100165 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200166 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100167
168 /*
169 * Running count of TX packets in flight, to avoid
170 * iterating over the transmit rings each time.
171 */
172 int pending_tx_pkts;
173
174 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
175 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
176
177 /* PHY parameters */
178 struct ieee80211_supported_band band;
179 struct ieee80211_channel channels[14];
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100180 struct ieee80211_rate rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100181
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200182 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200183 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200184 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200185 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100186
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100187 /* XXX need to convert this to handle multiple interfaces */
188 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200189 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100190 struct sk_buff *beacon_skb;
191
192 /*
193 * This FJ worker has to be global as it is scheduled from the
194 * RX handler. At this point we don't know which interface it
195 * belongs to until the list of bssids waiting to complete join
196 * is checked.
197 */
198 struct work_struct finalize_join_worker;
199
200 /* Tasklet to reclaim TX descriptors and buffers after tx */
201 struct tasklet_struct tx_reclaim_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100202};
203
204/* Per interface specific private data */
205struct mwl8k_vif {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100206 /* backpointer to parent config block */
207 struct mwl8k_priv *priv;
208
209 /* BSS config of AP or IBSS from mac80211*/
210 struct ieee80211_bss_conf bss_info;
211
212 /* BSSID of AP or IBSS */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200213 u8 bssid[ETH_ALEN];
214 u8 mac_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100215
Lennert Buytenhek55489b62009-11-30 18:31:33 +0100216 /* Index into station database. Returned by UPDATE_STADB. */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100217 u8 peer_id;
218
219 /* Non AMPDU sequence number assigned by driver */
220 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100221};
222
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200223#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100224
225static const struct ieee80211_channel mwl8k_channels[] = {
226 { .center_freq = 2412, .hw_value = 1, },
227 { .center_freq = 2417, .hw_value = 2, },
228 { .center_freq = 2422, .hw_value = 3, },
229 { .center_freq = 2427, .hw_value = 4, },
230 { .center_freq = 2432, .hw_value = 5, },
231 { .center_freq = 2437, .hw_value = 6, },
232 { .center_freq = 2442, .hw_value = 7, },
233 { .center_freq = 2447, .hw_value = 8, },
234 { .center_freq = 2452, .hw_value = 9, },
235 { .center_freq = 2457, .hw_value = 10, },
236 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100237 { .center_freq = 2467, .hw_value = 12, },
238 { .center_freq = 2472, .hw_value = 13, },
239 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100240};
241
242static const struct ieee80211_rate mwl8k_rates[] = {
243 { .bitrate = 10, .hw_value = 2, },
244 { .bitrate = 20, .hw_value = 4, },
245 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200246 { .bitrate = 110, .hw_value = 22, },
247 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100248 { .bitrate = 60, .hw_value = 12, },
249 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100250 { .bitrate = 120, .hw_value = 24, },
251 { .bitrate = 180, .hw_value = 36, },
252 { .bitrate = 240, .hw_value = 48, },
253 { .bitrate = 360, .hw_value = 72, },
254 { .bitrate = 480, .hw_value = 96, },
255 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100256 { .bitrate = 720, .hw_value = 144, },
257};
258
259static const u8 mwl8k_rateids[12] = {
260 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108,
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100261};
262
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100263/* Set or get info from Firmware */
264#define MWL8K_CMD_SET 0x0001
265#define MWL8K_CMD_GET 0x0000
266
267/* Firmware command codes */
268#define MWL8K_CMD_CODE_DNLD 0x0001
269#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200270#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100271#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
272#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200273#define MWL8K_CMD_RADIO_CONTROL 0x001c
274#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200275#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100276#define MWL8K_CMD_SET_PRE_SCAN 0x0107
277#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200278#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100279#define MWL8K_CMD_SET_AID 0x010d
280#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200281#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100282#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200283#define MWL8K_CMD_SET_SLOT 0x0114
284#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
285#define MWL8K_CMD_SET_WMM_MODE 0x0123
286#define MWL8K_CMD_MIMO_CONFIG 0x0125
287#define MWL8K_CMD_USE_FIXED_RATE 0x0126
288#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200289#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200290#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
291#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100292
293static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
294{
295#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
296 snprintf(buf, bufsize, "%s", #x);\
297 return buf;\
298 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200299 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100300 MWL8K_CMDNAME(CODE_DNLD);
301 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200302 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100303 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
304 MWL8K_CMDNAME(GET_STAT);
305 MWL8K_CMDNAME(RADIO_CONTROL);
306 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200307 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100308 MWL8K_CMDNAME(SET_PRE_SCAN);
309 MWL8K_CMDNAME(SET_POST_SCAN);
310 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100311 MWL8K_CMDNAME(SET_AID);
312 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200313 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100314 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200315 MWL8K_CMDNAME(SET_SLOT);
316 MWL8K_CMDNAME(SET_EDCA_PARAMS);
317 MWL8K_CMDNAME(SET_WMM_MODE);
318 MWL8K_CMDNAME(MIMO_CONFIG);
319 MWL8K_CMDNAME(USE_FIXED_RATE);
320 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200321 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200322 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
323 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100324 default:
325 snprintf(buf, bufsize, "0x%x", cmd);
326 }
327#undef MWL8K_CMDNAME
328
329 return buf;
330}
331
332/* Hardware and firmware reset */
333static void mwl8k_hw_reset(struct mwl8k_priv *priv)
334{
335 iowrite32(MWL8K_H2A_INT_RESET,
336 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
337 iowrite32(MWL8K_H2A_INT_RESET,
338 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
339 msleep(20);
340}
341
342/* Release fw image */
343static void mwl8k_release_fw(struct firmware **fw)
344{
345 if (*fw == NULL)
346 return;
347 release_firmware(*fw);
348 *fw = NULL;
349}
350
351static void mwl8k_release_firmware(struct mwl8k_priv *priv)
352{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100353 mwl8k_release_fw(&priv->fw_ucode);
354 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100355}
356
357/* Request fw image */
358static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200359 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100360{
361 /* release current image */
362 if (*fw != NULL)
363 mwl8k_release_fw(fw);
364
365 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200366 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100367}
368
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200369static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100370{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200371 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100372 int rc;
373
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200374 if (di->helper_image != NULL) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100375 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200376 if (rc) {
377 printk(KERN_ERR "%s: Error requesting helper "
378 "firmware file %s\n", pci_name(priv->pdev),
379 di->helper_image);
380 return rc;
381 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100382 }
383
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100384 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100385 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200386 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200387 pci_name(priv->pdev), di->fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100388 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100389 return rc;
390 }
391
392 return 0;
393}
394
Ben Hutchings7e75b942009-11-07 22:00:57 +0000395MODULE_FIRMWARE("mwl8k/helper_8687.fw");
396MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
397
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100398struct mwl8k_cmd_pkt {
399 __le16 code;
400 __le16 length;
401 __le16 seq_num;
402 __le16 result;
403 char payload[0];
404} __attribute__((packed));
405
406/*
407 * Firmware loading.
408 */
409static int
410mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
411{
412 void __iomem *regs = priv->regs;
413 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100414 int loops;
415
416 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
417 if (pci_dma_mapping_error(priv->pdev, dma_addr))
418 return -ENOMEM;
419
420 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
421 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
422 iowrite32(MWL8K_H2A_INT_DOORBELL,
423 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
424 iowrite32(MWL8K_H2A_INT_DUMMY,
425 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
426
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100427 loops = 1000;
428 do {
429 u32 int_code;
430
431 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
432 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
433 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100434 break;
435 }
436
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200437 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100438 udelay(1);
439 } while (--loops);
440
441 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
442
Lennert Buytenhekd4b705702009-07-16 12:44:45 +0200443 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100444}
445
446static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
447 const u8 *data, size_t length)
448{
449 struct mwl8k_cmd_pkt *cmd;
450 int done;
451 int rc = 0;
452
453 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
454 if (cmd == NULL)
455 return -ENOMEM;
456
457 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
458 cmd->seq_num = 0;
459 cmd->result = 0;
460
461 done = 0;
462 while (length) {
463 int block_size = length > 256 ? 256 : length;
464
465 memcpy(cmd->payload, data + done, block_size);
466 cmd->length = cpu_to_le16(block_size);
467
468 rc = mwl8k_send_fw_load_cmd(priv, cmd,
469 sizeof(*cmd) + block_size);
470 if (rc)
471 break;
472
473 done += block_size;
474 length -= block_size;
475 }
476
477 if (!rc) {
478 cmd->length = 0;
479 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
480 }
481
482 kfree(cmd);
483
484 return rc;
485}
486
487static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
488 const u8 *data, size_t length)
489{
490 unsigned char *buffer;
491 int may_continue, rc = 0;
492 u32 done, prev_block_size;
493
494 buffer = kmalloc(1024, GFP_KERNEL);
495 if (buffer == NULL)
496 return -ENOMEM;
497
498 done = 0;
499 prev_block_size = 0;
500 may_continue = 1000;
501 while (may_continue > 0) {
502 u32 block_size;
503
504 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
505 if (block_size & 1) {
506 block_size &= ~1;
507 may_continue--;
508 } else {
509 done += prev_block_size;
510 length -= prev_block_size;
511 }
512
513 if (block_size > 1024 || block_size > length) {
514 rc = -EOVERFLOW;
515 break;
516 }
517
518 if (length == 0) {
519 rc = 0;
520 break;
521 }
522
523 if (block_size == 0) {
524 rc = -EPROTO;
525 may_continue--;
526 udelay(1);
527 continue;
528 }
529
530 prev_block_size = block_size;
531 memcpy(buffer, data + done, block_size);
532
533 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
534 if (rc)
535 break;
536 }
537
538 if (!rc && length != 0)
539 rc = -EREMOTEIO;
540
541 kfree(buffer);
542
543 return rc;
544}
545
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200546static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100547{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200548 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100549 struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200550 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200551 int rc;
552 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100553
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200554 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100555 struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100556
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200557 if (helper == NULL) {
558 printk(KERN_ERR "%s: helper image needed but none "
559 "given\n", pci_name(priv->pdev));
560 return -EINVAL;
561 }
562
563 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100564 if (rc) {
565 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200566 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100567 return rc;
568 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100569 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100570
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200571 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100572 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200573 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100574 }
575
576 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200577 printk(KERN_ERR "%s: unable to load firmware image\n",
578 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100579 return rc;
580 }
581
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200582 if (di->modes & BIT(NL80211_IFTYPE_AP))
583 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
584 else
585 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100586
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100587 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100588 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200589 u32 ready_code;
590
591 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
592 if (ready_code == MWL8K_FWAP_READY) {
593 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100594 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200595 } else if (ready_code == MWL8K_FWSTA_READY) {
596 priv->ap_fw = 0;
597 break;
598 }
599
600 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100601 udelay(1);
602 } while (--loops);
603
604 return loops ? 0 : -ETIMEDOUT;
605}
606
607
608/*
609 * Defines shared between transmission and reception.
610 */
611/* HT control fields for firmware */
612struct ewc_ht_info {
613 __le16 control1;
614 __le16 control2;
615 __le16 control3;
616} __attribute__((packed));
617
618/* Firmware Station database operations */
619#define MWL8K_STA_DB_ADD_ENTRY 0
620#define MWL8K_STA_DB_MODIFY_ENTRY 1
621#define MWL8K_STA_DB_DEL_ENTRY 2
622#define MWL8K_STA_DB_FLUSH 3
623
624/* Peer Entry flags - used to define the type of the peer node */
625#define MWL8K_PEER_TYPE_ACCESSPOINT 2
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100626
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100627struct peer_capability_info {
628 /* Peer type - AP vs. STA. */
629 __u8 peer_type;
630
631 /* Basic 802.11 capabilities from assoc resp. */
632 __le16 basic_caps;
633
634 /* Set if peer supports 802.11n high throughput (HT). */
635 __u8 ht_support;
636
637 /* Valid if HT is supported. */
638 __le16 ht_caps;
639 __u8 extended_ht_caps;
640 struct ewc_ht_info ewc_info;
641
642 /* Legacy rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100643 __u8 legacy_rates[12];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100644
645 /* HT rate table. Intersection of our rates and peer rates. */
Lennert Buytenhek0b5351a2009-11-30 18:11:18 +0100646 __u8 ht_rates[16];
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +0200647 __u8 pad[16];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100648
649 /* If set, interoperability mode, no proprietary extensions. */
650 __u8 interop;
651 __u8 pad2;
652 __u8 station_id;
653 __le16 amsdu_enabled;
654} __attribute__((packed));
655
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100656/* DMA header used by firmware and hardware. */
657struct mwl8k_dma_data {
658 __le16 fwlen;
659 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100660 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100661} __attribute__((packed));
662
663/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100664static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100665{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100666 struct mwl8k_dma_data *tr;
667 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100668
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100669 tr = (struct mwl8k_dma_data *)skb->data;
670 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
671
672 if (hdrlen != sizeof(tr->wh)) {
673 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
674 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
675 *((__le16 *)(tr->data - 2)) = qos;
676 } else {
677 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
678 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100679 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100680
681 if (hdrlen != sizeof(*tr))
682 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100683}
684
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200685static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100686{
687 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100688 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100689 struct mwl8k_dma_data *tr;
690
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100691 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100692 * Add a firmware DMA header; the firmware requires that we
693 * present a 2-byte payload length followed by a 4-address
694 * header (without QoS field), followed (optionally) by any
695 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100696 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100697 wh = (struct ieee80211_hdr *)skb->data;
698
699 hdrlen = ieee80211_hdrlen(wh->frame_control);
700 if (hdrlen != sizeof(*tr))
701 skb_push(skb, sizeof(*tr) - hdrlen);
702
703 if (ieee80211_is_data_qos(wh->frame_control))
704 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100705
706 tr = (struct mwl8k_dma_data *)skb->data;
707 if (wh != &tr->wh)
708 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100709 if (hdrlen != sizeof(tr->wh))
710 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100711
712 /*
713 * Firmware length is the length of the fully formed "802.11
714 * payload". That is, everything except for the 802.11 header.
715 * This includes all crypto material including the MIC.
716 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100717 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100718}
719
720
721/*
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200722 * Packet reception for 88w8366.
723 */
724struct mwl8k_rxd_8366 {
725 __le16 pkt_len;
726 __u8 sq2;
727 __u8 rate;
728 __le32 pkt_phys_addr;
729 __le32 next_rxd_phys_addr;
730 __le16 qos_control;
731 __le16 htsig2;
732 __le32 hw_rssi_info;
733 __le32 hw_noise_floor_info;
734 __u8 noise_floor;
735 __u8 pad0[3];
736 __u8 rssi;
737 __u8 rx_status;
738 __u8 channel;
739 __u8 rx_ctrl;
740} __attribute__((packed));
741
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100742#define MWL8K_8366_RATE_INFO_MCS_FORMAT 0x80
743#define MWL8K_8366_RATE_INFO_40MHZ 0x40
744#define MWL8K_8366_RATE_INFO_RATEID(x) ((x) & 0x3f)
745
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200746#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80
747
748static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr)
749{
750 struct mwl8k_rxd_8366 *rxd = _rxd;
751
752 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
753 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST;
754}
755
756static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
757{
758 struct mwl8k_rxd_8366 *rxd = _rxd;
759
760 rxd->pkt_len = cpu_to_le16(len);
761 rxd->pkt_phys_addr = cpu_to_le32(addr);
762 wmb();
763 rxd->rx_ctrl = 0;
764}
765
766static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100767mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status,
768 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200769{
770 struct mwl8k_rxd_8366 *rxd = _rxd;
771
772 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST))
773 return -1;
774 rmb();
775
776 memset(status, 0, sizeof(*status));
777
778 status->signal = -rxd->rssi;
779 status->noise = -rxd->noise_floor;
780
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100781 if (rxd->rate & MWL8K_8366_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200782 status->flag |= RX_FLAG_HT;
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100783 if (rxd->rate & MWL8K_8366_RATE_INFO_40MHZ)
784 status->flag |= RX_FLAG_40MHZ;
785 status->rate_idx = MWL8K_8366_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200786 } else {
787 int i;
788
789 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
790 if (mwl8k_rates[i].hw_value == rxd->rate) {
791 status->rate_idx = i;
792 break;
793 }
794 }
795 }
796
797 status->band = IEEE80211_BAND_2GHZ;
798 status->freq = ieee80211_channel_to_frequency(rxd->channel);
799
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100800 *qos = rxd->qos_control;
801
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200802 return le16_to_cpu(rxd->pkt_len);
803}
804
805static struct rxd_ops rxd_8366_ops = {
806 .rxd_size = sizeof(struct mwl8k_rxd_8366),
807 .rxd_init = mwl8k_rxd_8366_init,
808 .rxd_refill = mwl8k_rxd_8366_refill,
809 .rxd_process = mwl8k_rxd_8366_process,
810};
811
812/*
813 * Packet reception for 88w8687.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100814 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200815struct mwl8k_rxd_8687 {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100816 __le16 pkt_len;
817 __u8 link_quality;
818 __u8 noise_level;
819 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200820 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100821 __le16 qos_control;
822 __le16 rate_info;
823 __le32 pad0[4];
824 __u8 rssi;
825 __u8 channel;
826 __le16 pad1;
827 __u8 rx_ctrl;
828 __u8 rx_status;
829 __u8 pad2[2];
830} __attribute__((packed));
831
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200832#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000
833#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
834#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
835#define MWL8K_8687_RATE_INFO_40MHZ 0x0004
836#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002
837#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001
838
839#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02
840
841static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr)
842{
843 struct mwl8k_rxd_8687 *rxd = _rxd;
844
845 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
846 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST;
847}
848
849static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
850{
851 struct mwl8k_rxd_8687 *rxd = _rxd;
852
853 rxd->pkt_len = cpu_to_le16(len);
854 rxd->pkt_phys_addr = cpu_to_le32(addr);
855 wmb();
856 rxd->rx_ctrl = 0;
857}
858
859static int
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100860mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status,
861 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200862{
863 struct mwl8k_rxd_8687 *rxd = _rxd;
864 u16 rate_info;
865
866 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST))
867 return -1;
868 rmb();
869
870 rate_info = le16_to_cpu(rxd->rate_info);
871
872 memset(status, 0, sizeof(*status));
873
874 status->signal = -rxd->rssi;
875 status->noise = -rxd->noise_level;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200876 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info);
877 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info);
878
879 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE)
880 status->flag |= RX_FLAG_SHORTPRE;
881 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ)
882 status->flag |= RX_FLAG_40MHZ;
883 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI)
884 status->flag |= RX_FLAG_SHORT_GI;
885 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT)
886 status->flag |= RX_FLAG_HT;
887
888 status->band = IEEE80211_BAND_2GHZ;
889 status->freq = ieee80211_channel_to_frequency(rxd->channel);
890
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100891 *qos = rxd->qos_control;
892
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200893 return le16_to_cpu(rxd->pkt_len);
894}
895
896static struct rxd_ops rxd_8687_ops = {
897 .rxd_size = sizeof(struct mwl8k_rxd_8687),
898 .rxd_init = mwl8k_rxd_8687_init,
899 .rxd_refill = mwl8k_rxd_8687_refill,
900 .rxd_process = mwl8k_rxd_8687_process,
901};
902
903
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100904#define MWL8K_RX_DESCS 256
905#define MWL8K_RX_MAXSZ 3800
906
907static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
908{
909 struct mwl8k_priv *priv = hw->priv;
910 struct mwl8k_rx_queue *rxq = priv->rxq + index;
911 int size;
912 int i;
913
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200914 rxq->rxd_count = 0;
915 rxq->head = 0;
916 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100917
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200918 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100919
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200920 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
921 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100922 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200923 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100924 return -ENOMEM;
925 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200926 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100927
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200928 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
929 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100930 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200931 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200932 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100933 return -ENOMEM;
934 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200935 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100936
937 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200938 int desc_size;
939 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100940 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200941 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100942
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200943 desc_size = priv->rxd_ops->rxd_size;
944 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100945
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200946 nexti = i + 1;
947 if (nexti == MWL8K_RX_DESCS)
948 nexti = 0;
949 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
950
951 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100952 }
953
954 return 0;
955}
956
957static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
958{
959 struct mwl8k_priv *priv = hw->priv;
960 struct mwl8k_rx_queue *rxq = priv->rxq + index;
961 int refilled;
962
963 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200964 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100965 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200966 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100967 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200968 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100969
970 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
971 if (skb == NULL)
972 break;
973
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200974 addr = pci_map_single(priv->pdev, skb->data,
975 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100976
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200977 rxq->rxd_count++;
978 rx = rxq->tail++;
979 if (rxq->tail == MWL8K_RX_DESCS)
980 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200981 rxq->buf[rx].skb = skb;
982 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200983
984 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
985 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100986
987 refilled++;
988 }
989
990 return refilled;
991}
992
993/* Must be called only when the card's reception is completely halted */
994static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
995{
996 struct mwl8k_priv *priv = hw->priv;
997 struct mwl8k_rx_queue *rxq = priv->rxq + index;
998 int i;
999
1000 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001001 if (rxq->buf[i].skb != NULL) {
1002 pci_unmap_single(priv->pdev,
1003 pci_unmap_addr(&rxq->buf[i], dma),
1004 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1005 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001006
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001007 kfree_skb(rxq->buf[i].skb);
1008 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001009 }
1010 }
1011
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001012 kfree(rxq->buf);
1013 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001014
1015 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001016 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001017 rxq->rxd, rxq->rxd_dma);
1018 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001019}
1020
1021
1022/*
1023 * Scan a list of BSSIDs to process for finalize join.
1024 * Allows for extension to process multiple BSSIDs.
1025 */
1026static inline int
1027mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1028{
1029 return priv->capture_beacon &&
1030 ieee80211_is_beacon(wh->frame_control) &&
1031 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1032}
1033
Lennert Buytenhek37797522009-10-22 20:19:45 +02001034static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1035 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001036{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001037 struct mwl8k_priv *priv = hw->priv;
1038
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001039 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001040 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001041
1042 /*
1043 * Use GFP_ATOMIC as rxq_process is called from
1044 * the primary interrupt handler, memory allocation call
1045 * must not sleep.
1046 */
1047 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1048 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001049 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001050}
1051
1052static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1053{
1054 struct mwl8k_priv *priv = hw->priv;
1055 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1056 int processed;
1057
1058 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001059 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001060 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001061 void *rxd;
1062 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001063 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001064 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001065
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001066 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001067 if (skb == NULL)
1068 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001069
1070 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1071
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001072 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001073 if (pkt_len < 0)
1074 break;
1075
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001076 rxq->buf[rxq->head].skb = NULL;
1077
1078 pci_unmap_single(priv->pdev,
1079 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1080 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1081 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001082
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001083 rxq->head++;
1084 if (rxq->head == MWL8K_RX_DESCS)
1085 rxq->head = 0;
1086
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001087 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001088
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001089 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001090 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001091
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001092 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001093 * Check for a pending join operation. Save a
1094 * copy of the beacon and schedule a tasklet to
1095 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001096 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001097 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001098 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001099
Johannes Bergf1d58c22009-06-17 13:13:00 +02001100 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1101 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001102
1103 processed++;
1104 }
1105
1106 return processed;
1107}
1108
1109
1110/*
1111 * Packet transmission.
1112 */
1113
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001114#define MWL8K_TXD_STATUS_OK 0x00000001
1115#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1116#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1117#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001118#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001119
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001120#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1121#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1122#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1123#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1124#define MWL8K_QOS_EOSP 0x0010
1125
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001126struct mwl8k_tx_desc {
1127 __le32 status;
1128 __u8 data_rate;
1129 __u8 tx_priority;
1130 __le16 qos_control;
1131 __le32 pkt_phys_addr;
1132 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001133 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001134 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001135 __le32 reserved;
1136 __le16 rate_info;
1137 __u8 peer_id;
1138 __u8 tx_frag_cnt;
1139} __attribute__((packed));
1140
1141#define MWL8K_TX_DESCS 128
1142
1143static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1144{
1145 struct mwl8k_priv *priv = hw->priv;
1146 struct mwl8k_tx_queue *txq = priv->txq + index;
1147 int size;
1148 int i;
1149
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001150 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1151 txq->stats.limit = MWL8K_TX_DESCS;
1152 txq->head = 0;
1153 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001154
1155 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1156
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001157 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1158 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001159 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001160 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001161 return -ENOMEM;
1162 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001163 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001164
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001165 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1166 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001167 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001168 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001169 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001170 return -ENOMEM;
1171 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001172 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001173
1174 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1175 struct mwl8k_tx_desc *tx_desc;
1176 int nexti;
1177
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001178 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001179 nexti = (i + 1) % MWL8K_TX_DESCS;
1180
1181 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001182 tx_desc->next_txd_phys_addr =
1183 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001184 }
1185
1186 return 0;
1187}
1188
1189static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1190{
1191 iowrite32(MWL8K_H2A_INT_PPA_READY,
1192 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1193 iowrite32(MWL8K_H2A_INT_DUMMY,
1194 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1195 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1196}
1197
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001198static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001199{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001200 struct mwl8k_priv *priv = hw->priv;
1201 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001202
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001203 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1204 struct mwl8k_tx_queue *txq = priv->txq + i;
1205 int fw_owned = 0;
1206 int drv_owned = 0;
1207 int unused = 0;
1208 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001209
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001210 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001211 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1212 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001213
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001214 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001215 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001216 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001217 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001218 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001219
1220 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001221 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001222 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001223
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001224 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1225 "fw_owned=%d drv_owned=%d unused=%d\n",
1226 wiphy_name(hw->wiphy), i,
1227 txq->stats.len, txq->head, txq->tail,
1228 fw_owned, drv_owned, unused);
1229 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001230}
1231
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001232/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001233 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001234 */
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001235#define MWL8K_TX_WAIT_TIMEOUT_MS 1000
1236
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001237static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001238{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001239 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001240 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001241 int retry;
1242 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001243
1244 might_sleep();
1245
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001246 /*
1247 * The TX queues are stopped at this point, so this test
1248 * doesn't need to take ->tx_lock.
1249 */
1250 if (!priv->pending_tx_pkts)
1251 return 0;
1252
1253 retry = 0;
1254 rc = 0;
1255
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001256 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001257 priv->tx_wait = &tx_wait;
1258 while (!rc) {
1259 int oldcount;
1260 unsigned long timeout;
1261
1262 oldcount = priv->pending_tx_pkts;
1263
1264 spin_unlock_bh(&priv->tx_lock);
1265 timeout = wait_for_completion_timeout(&tx_wait,
1266 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1267 spin_lock_bh(&priv->tx_lock);
1268
1269 if (timeout) {
1270 WARN_ON(priv->pending_tx_pkts);
1271 if (retry) {
1272 printk(KERN_NOTICE "%s: tx rings drained\n",
1273 wiphy_name(hw->wiphy));
1274 }
1275 break;
1276 }
1277
1278 if (priv->pending_tx_pkts < oldcount) {
1279 printk(KERN_NOTICE "%s: timeout waiting for tx "
1280 "rings to drain (%d -> %d pkts), retrying\n",
1281 wiphy_name(hw->wiphy), oldcount,
1282 priv->pending_tx_pkts);
1283 retry = 1;
1284 continue;
1285 }
1286
1287 priv->tx_wait = NULL;
1288
1289 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1290 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1291 mwl8k_dump_tx_rings(hw);
1292
1293 rc = -ETIMEDOUT;
1294 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001295 spin_unlock_bh(&priv->tx_lock);
1296
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001297 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001298}
1299
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001300#define MWL8K_TXD_SUCCESS(status) \
1301 ((status) & (MWL8K_TXD_STATUS_OK | \
1302 MWL8K_TXD_STATUS_OK_RETRY | \
1303 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001304
1305static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1306{
1307 struct mwl8k_priv *priv = hw->priv;
1308 struct mwl8k_tx_queue *txq = priv->txq + index;
1309 int wake = 0;
1310
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001311 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001312 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001313 struct mwl8k_tx_desc *tx_desc;
1314 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001315 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001316 struct sk_buff *skb;
1317 struct ieee80211_tx_info *info;
1318 u32 status;
1319
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001320 tx = txq->head;
1321 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001322
1323 status = le32_to_cpu(tx_desc->status);
1324
1325 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1326 if (!force)
1327 break;
1328 tx_desc->status &=
1329 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1330 }
1331
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001332 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1333 BUG_ON(txq->stats.len == 0);
1334 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001335 priv->pending_tx_pkts--;
1336
1337 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001338 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001339 skb = txq->skb[tx];
1340 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001341
1342 BUG_ON(skb == NULL);
1343 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1344
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001345 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001346
1347 /* Mark descriptor as unused */
1348 tx_desc->pkt_phys_addr = 0;
1349 tx_desc->pkt_len = 0;
1350
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001351 info = IEEE80211_SKB_CB(skb);
1352 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001353 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001354 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001355
1356 ieee80211_tx_status_irqsafe(hw, skb);
1357
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001358 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001359 }
1360
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001361 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001362 ieee80211_wake_queue(hw, index);
1363}
1364
1365/* must be called only when the card's transmit is completely halted */
1366static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1367{
1368 struct mwl8k_priv *priv = hw->priv;
1369 struct mwl8k_tx_queue *txq = priv->txq + index;
1370
1371 mwl8k_txq_reclaim(hw, index, 1);
1372
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001373 kfree(txq->skb);
1374 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001375
1376 pci_free_consistent(priv->pdev,
1377 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001378 txq->txd, txq->txd_dma);
1379 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001380}
1381
1382static int
1383mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1384{
1385 struct mwl8k_priv *priv = hw->priv;
1386 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001387 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001388 struct ieee80211_hdr *wh;
1389 struct mwl8k_tx_queue *txq;
1390 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001391 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001392 u32 txstatus;
1393 u8 txdatarate;
1394 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001395
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001396 wh = (struct ieee80211_hdr *)skb->data;
1397 if (ieee80211_is_data_qos(wh->frame_control))
1398 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1399 else
1400 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001401
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001402 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001403 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001404
1405 tx_info = IEEE80211_SKB_CB(skb);
1406 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001407
1408 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1409 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001410
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001411 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1412 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1413 mwl8k_vif->seqno = seqno++ % 4096;
1414 }
1415
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001416 /* Setup firmware control bit fields for each frame type. */
1417 txstatus = 0;
1418 txdatarate = 0;
1419 if (ieee80211_is_mgmt(wh->frame_control) ||
1420 ieee80211_is_ctl(wh->frame_control)) {
1421 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001422 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001423 } else if (ieee80211_is_data(wh->frame_control)) {
1424 txdatarate = 1;
1425 if (is_multicast_ether_addr(wh->addr1))
1426 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1427
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001428 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001429 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001430 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001431 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001432 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001433 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001434
1435 dma = pci_map_single(priv->pdev, skb->data,
1436 skb->len, PCI_DMA_TODEVICE);
1437
1438 if (pci_dma_mapping_error(priv->pdev, dma)) {
1439 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001440 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001441 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001442 return NETDEV_TX_OK;
1443 }
1444
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001445 spin_lock_bh(&priv->tx_lock);
1446
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001447 txq = priv->txq + index;
1448
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001449 BUG_ON(txq->skb[txq->tail] != NULL);
1450 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001451
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001452 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001453 tx->data_rate = txdatarate;
1454 tx->tx_priority = index;
1455 tx->qos_control = cpu_to_le16(qos);
1456 tx->pkt_phys_addr = cpu_to_le32(dma);
1457 tx->pkt_len = cpu_to_le16(skb->len);
1458 tx->rate_info = 0;
1459 tx->peer_id = mwl8k_vif->peer_id;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001460 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001461 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1462
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001463 txq->stats.count++;
1464 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001465 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001466
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001467 txq->tail++;
1468 if (txq->tail == MWL8K_TX_DESCS)
1469 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001470
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001471 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001472 ieee80211_stop_queue(hw, index);
1473
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001474 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001475
1476 spin_unlock_bh(&priv->tx_lock);
1477
1478 return NETDEV_TX_OK;
1479}
1480
1481
1482/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001483 * Firmware access.
1484 *
1485 * We have the following requirements for issuing firmware commands:
1486 * - Some commands require that the packet transmit path is idle when
1487 * the command is issued. (For simplicity, we'll just quiesce the
1488 * transmit path for every command.)
1489 * - There are certain sequences of commands that need to be issued to
1490 * the hardware sequentially, with no other intervening commands.
1491 *
1492 * This leads to an implementation of a "firmware lock" as a mutex that
1493 * can be taken recursively, and which is taken by both the low-level
1494 * command submission function (mwl8k_post_cmd) as well as any users of
1495 * that function that require issuing of an atomic sequence of commands,
1496 * and quiesces the transmit path whenever it's taken.
1497 */
1498static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1499{
1500 struct mwl8k_priv *priv = hw->priv;
1501
1502 if (priv->fw_mutex_owner != current) {
1503 int rc;
1504
1505 mutex_lock(&priv->fw_mutex);
1506 ieee80211_stop_queues(hw);
1507
1508 rc = mwl8k_tx_wait_empty(hw);
1509 if (rc) {
1510 ieee80211_wake_queues(hw);
1511 mutex_unlock(&priv->fw_mutex);
1512
1513 return rc;
1514 }
1515
1516 priv->fw_mutex_owner = current;
1517 }
1518
1519 priv->fw_mutex_depth++;
1520
1521 return 0;
1522}
1523
1524static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1525{
1526 struct mwl8k_priv *priv = hw->priv;
1527
1528 if (!--priv->fw_mutex_depth) {
1529 ieee80211_wake_queues(hw);
1530 priv->fw_mutex_owner = NULL;
1531 mutex_unlock(&priv->fw_mutex);
1532 }
1533}
1534
1535
1536/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001537 * Command processing.
1538 */
1539
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001540/* Timeout firmware commands after 10s */
1541#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001542
1543static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1544{
1545 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1546 struct mwl8k_priv *priv = hw->priv;
1547 void __iomem *regs = priv->regs;
1548 dma_addr_t dma_addr;
1549 unsigned int dma_size;
1550 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001551 unsigned long timeout = 0;
1552 u8 buf[32];
1553
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001554 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001555 dma_size = le16_to_cpu(cmd->length);
1556 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1557 PCI_DMA_BIDIRECTIONAL);
1558 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1559 return -ENOMEM;
1560
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001561 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001562 if (rc) {
1563 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1564 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001565 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001566 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001567
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001568 priv->hostcmd_wait = &cmd_wait;
1569 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1570 iowrite32(MWL8K_H2A_INT_DOORBELL,
1571 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1572 iowrite32(MWL8K_H2A_INT_DUMMY,
1573 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001574
1575 timeout = wait_for_completion_timeout(&cmd_wait,
1576 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1577
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001578 priv->hostcmd_wait = NULL;
1579
1580 mwl8k_fw_unlock(hw);
1581
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001582 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1583 PCI_DMA_BIDIRECTIONAL);
1584
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001585 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001586 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001587 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001588 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1589 MWL8K_CMD_TIMEOUT_MS);
1590 rc = -ETIMEDOUT;
1591 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001592 int ms;
1593
1594 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1595
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001596 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001597 if (rc)
1598 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001599 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001600 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001601 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001602 else if (ms > 2000)
1603 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1604 wiphy_name(hw->wiphy),
1605 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1606 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001607 }
1608
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001609 return rc;
1610}
1611
1612/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001613 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001614 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001615struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001616 struct mwl8k_cmd_pkt header;
1617 __u8 hw_rev;
1618 __u8 host_interface;
1619 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001620 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001621 __le16 region_code;
1622 __le32 fw_rev;
1623 __le32 ps_cookie;
1624 __le32 caps;
1625 __u8 mcs_bitmap[16];
1626 __le32 rx_queue_ptr;
1627 __le32 num_tx_queues;
1628 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1629 __le32 caps2;
1630 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001631 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001632} __attribute__((packed));
1633
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001634static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001635{
1636 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001637 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001638 int rc;
1639 int i;
1640
1641 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1642 if (cmd == NULL)
1643 return -ENOMEM;
1644
1645 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1646 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1647
1648 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1649 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001650 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001651 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001652 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001653 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001654 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001655 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001656
1657 rc = mwl8k_post_cmd(hw, &cmd->header);
1658
1659 if (!rc) {
1660 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1661 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001662 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001663 priv->hw_rev = cmd->hw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001664 }
1665
1666 kfree(cmd);
1667 return rc;
1668}
1669
1670/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001671 * CMD_GET_HW_SPEC (AP version).
1672 */
1673struct mwl8k_cmd_get_hw_spec_ap {
1674 struct mwl8k_cmd_pkt header;
1675 __u8 hw_rev;
1676 __u8 host_interface;
1677 __le16 num_wcb;
1678 __le16 num_mcaddrs;
1679 __u8 perm_addr[ETH_ALEN];
1680 __le16 region_code;
1681 __le16 num_antenna;
1682 __le32 fw_rev;
1683 __le32 wcbbase0;
1684 __le32 rxwrptr;
1685 __le32 rxrdptr;
1686 __le32 ps_cookie;
1687 __le32 wcbbase1;
1688 __le32 wcbbase2;
1689 __le32 wcbbase3;
1690} __attribute__((packed));
1691
1692static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1693{
1694 struct mwl8k_priv *priv = hw->priv;
1695 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1696 int rc;
1697
1698 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1699 if (cmd == NULL)
1700 return -ENOMEM;
1701
1702 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1703 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1704
1705 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1706 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1707
1708 rc = mwl8k_post_cmd(hw, &cmd->header);
1709
1710 if (!rc) {
1711 int off;
1712
1713 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1714 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1715 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1716 priv->hw_rev = cmd->hw_rev;
1717
1718 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1719 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1720
1721 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1722 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1723
1724 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1725 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1726
1727 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1728 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1729
1730 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1731 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1732
1733 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1734 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1735 }
1736
1737 kfree(cmd);
1738 return rc;
1739}
1740
1741/*
1742 * CMD_SET_HW_SPEC.
1743 */
1744struct mwl8k_cmd_set_hw_spec {
1745 struct mwl8k_cmd_pkt header;
1746 __u8 hw_rev;
1747 __u8 host_interface;
1748 __le16 num_mcaddrs;
1749 __u8 perm_addr[ETH_ALEN];
1750 __le16 region_code;
1751 __le32 fw_rev;
1752 __le32 ps_cookie;
1753 __le32 caps;
1754 __le32 rx_queue_ptr;
1755 __le32 num_tx_queues;
1756 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1757 __le32 flags;
1758 __le32 num_tx_desc_per_queue;
1759 __le32 total_rxd;
1760} __attribute__((packed));
1761
1762#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1763
1764static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1765{
1766 struct mwl8k_priv *priv = hw->priv;
1767 struct mwl8k_cmd_set_hw_spec *cmd;
1768 int rc;
1769 int i;
1770
1771 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1772 if (cmd == NULL)
1773 return -ENOMEM;
1774
1775 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1776 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1777
1778 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1779 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1780 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1781 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1782 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1783 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1784 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1785 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1786
1787 rc = mwl8k_post_cmd(hw, &cmd->header);
1788 kfree(cmd);
1789
1790 return rc;
1791}
1792
1793/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001794 * CMD_MAC_MULTICAST_ADR.
1795 */
1796struct mwl8k_cmd_mac_multicast_adr {
1797 struct mwl8k_cmd_pkt header;
1798 __le16 action;
1799 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001800 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001801};
1802
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001803#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1804#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1805#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1806#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001807
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001808static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001809__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001810 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001811{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001812 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001813 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001814 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001815
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001816 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001817 allmulti = 1;
1818 mc_count = 0;
1819 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001820
1821 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1822
1823 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001824 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001825 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001826
1827 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1828 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001829 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1830 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001831
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001832 if (allmulti) {
1833 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1834 } else if (mc_count) {
1835 int i;
1836
1837 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1838 cmd->numaddr = cpu_to_le16(mc_count);
1839 for (i = 0; i < mc_count && mclist; i++) {
1840 if (mclist->da_addrlen != ETH_ALEN) {
1841 kfree(cmd);
1842 return NULL;
1843 }
1844 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1845 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001846 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001847 }
1848
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001849 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001850}
1851
1852/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001853 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001854 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001855struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001856 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001857 __le32 stats[64];
1858} __attribute__((packed));
1859
1860#define MWL8K_STAT_ACK_FAILURE 9
1861#define MWL8K_STAT_RTS_FAILURE 12
1862#define MWL8K_STAT_FCS_ERROR 24
1863#define MWL8K_STAT_RTS_SUCCESS 11
1864
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001865static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1866 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001867{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001868 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001869 int rc;
1870
1871 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1872 if (cmd == NULL)
1873 return -ENOMEM;
1874
1875 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1876 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001877
1878 rc = mwl8k_post_cmd(hw, &cmd->header);
1879 if (!rc) {
1880 stats->dot11ACKFailureCount =
1881 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1882 stats->dot11RTSFailureCount =
1883 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1884 stats->dot11FCSErrorCount =
1885 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1886 stats->dot11RTSSuccessCount =
1887 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1888 }
1889 kfree(cmd);
1890
1891 return rc;
1892}
1893
1894/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001895 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001896 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001897struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001898 struct mwl8k_cmd_pkt header;
1899 __le16 action;
1900 __le16 control;
1901 __le16 radio_on;
1902} __attribute__((packed));
1903
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001904static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001905mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001906{
1907 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001908 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001909 int rc;
1910
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001911 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001912 return 0;
1913
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001914 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1915 if (cmd == NULL)
1916 return -ENOMEM;
1917
1918 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1919 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1920 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001921 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001922 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1923
1924 rc = mwl8k_post_cmd(hw, &cmd->header);
1925 kfree(cmd);
1926
1927 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001928 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001929
1930 return rc;
1931}
1932
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001933static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001934{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001935 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001936}
1937
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001938static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001939{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001940 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001941}
1942
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001943static int
1944mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1945{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01001946 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001947
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001948 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001949
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001950 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001951}
1952
1953/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001954 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001955 */
1956#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1957
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001958struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001959 struct mwl8k_cmd_pkt header;
1960 __le16 action;
1961 __le16 support_level;
1962 __le16 current_level;
1963 __le16 reserved;
1964 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1965} __attribute__((packed));
1966
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001967static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001968{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001969 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001970 int rc;
1971
1972 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1973 if (cmd == NULL)
1974 return -ENOMEM;
1975
1976 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1977 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1978 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1979 cmd->support_level = cpu_to_le16(dBm);
1980
1981 rc = mwl8k_post_cmd(hw, &cmd->header);
1982 kfree(cmd);
1983
1984 return rc;
1985}
1986
1987/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02001988 * CMD_RF_ANTENNA.
1989 */
1990struct mwl8k_cmd_rf_antenna {
1991 struct mwl8k_cmd_pkt header;
1992 __le16 antenna;
1993 __le16 mode;
1994} __attribute__((packed));
1995
1996#define MWL8K_RF_ANTENNA_RX 1
1997#define MWL8K_RF_ANTENNA_TX 2
1998
1999static int
2000mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2001{
2002 struct mwl8k_cmd_rf_antenna *cmd;
2003 int rc;
2004
2005 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2006 if (cmd == NULL)
2007 return -ENOMEM;
2008
2009 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2010 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2011 cmd->antenna = cpu_to_le16(antenna);
2012 cmd->mode = cpu_to_le16(mask);
2013
2014 rc = mwl8k_post_cmd(hw, &cmd->header);
2015 kfree(cmd);
2016
2017 return rc;
2018}
2019
2020/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002021 * CMD_SET_PRE_SCAN.
2022 */
2023struct mwl8k_cmd_set_pre_scan {
2024 struct mwl8k_cmd_pkt header;
2025} __attribute__((packed));
2026
2027static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2028{
2029 struct mwl8k_cmd_set_pre_scan *cmd;
2030 int rc;
2031
2032 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2033 if (cmd == NULL)
2034 return -ENOMEM;
2035
2036 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2037 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2038
2039 rc = mwl8k_post_cmd(hw, &cmd->header);
2040 kfree(cmd);
2041
2042 return rc;
2043}
2044
2045/*
2046 * CMD_SET_POST_SCAN.
2047 */
2048struct mwl8k_cmd_set_post_scan {
2049 struct mwl8k_cmd_pkt header;
2050 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002051 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002052} __attribute__((packed));
2053
2054static int
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002055mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002056{
2057 struct mwl8k_cmd_set_post_scan *cmd;
2058 int rc;
2059
2060 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2061 if (cmd == NULL)
2062 return -ENOMEM;
2063
2064 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2065 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2066 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002067 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002068
2069 rc = mwl8k_post_cmd(hw, &cmd->header);
2070 kfree(cmd);
2071
2072 return rc;
2073}
2074
2075/*
2076 * CMD_SET_RF_CHANNEL.
2077 */
2078struct mwl8k_cmd_set_rf_channel {
2079 struct mwl8k_cmd_pkt header;
2080 __le16 action;
2081 __u8 current_channel;
2082 __le32 channel_flags;
2083} __attribute__((packed));
2084
2085static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2086 struct ieee80211_channel *channel)
2087{
2088 struct mwl8k_cmd_set_rf_channel *cmd;
2089 int rc;
2090
2091 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2092 if (cmd == NULL)
2093 return -ENOMEM;
2094
2095 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2096 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2097 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2098 cmd->current_channel = channel->hw_value;
2099 if (channel->band == IEEE80211_BAND_2GHZ)
2100 cmd->channel_flags = cpu_to_le32(0x00000081);
2101 else
2102 cmd->channel_flags = cpu_to_le32(0x00000000);
2103
2104 rc = mwl8k_post_cmd(hw, &cmd->header);
2105 kfree(cmd);
2106
2107 return rc;
2108}
2109
2110/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002111 * CMD_SET_AID.
2112 */
2113#define MWL8K_FRAME_PROT_DISABLED 0x00
2114#define MWL8K_FRAME_PROT_11G 0x07
2115#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2116#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2117
2118struct mwl8k_cmd_update_set_aid {
2119 struct mwl8k_cmd_pkt header;
2120 __le16 aid;
2121
2122 /* AP's MAC address (BSSID) */
2123 __u8 bssid[ETH_ALEN];
2124 __le16 protection_mode;
2125 __u8 supp_rates[14];
2126} __attribute__((packed));
2127
2128static int
2129mwl8k_cmd_set_aid(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2130{
2131 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2132 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2133 struct mwl8k_cmd_update_set_aid *cmd;
2134 u16 prot_mode;
2135 int rc;
2136
2137 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2138 if (cmd == NULL)
2139 return -ENOMEM;
2140
2141 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2142 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2143 cmd->aid = cpu_to_le16(info->aid);
2144
2145 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN);
2146
2147 if (info->use_cts_prot) {
2148 prot_mode = MWL8K_FRAME_PROT_11G;
2149 } else {
2150 switch (info->ht_operation_mode &
2151 IEEE80211_HT_OP_MODE_PROTECTION) {
2152 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2153 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2154 break;
2155 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2156 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2157 break;
2158 default:
2159 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2160 break;
2161 }
2162 }
2163 cmd->protection_mode = cpu_to_le16(prot_mode);
2164
2165 memcpy(cmd->supp_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
2166
2167 rc = mwl8k_post_cmd(hw, &cmd->header);
2168 kfree(cmd);
2169
2170 return rc;
2171}
2172
2173/*
2174 * CMD_SET_RATE.
2175 */
2176struct mwl8k_cmd_set_rate {
2177 struct mwl8k_cmd_pkt header;
2178 __u8 legacy_rates[14];
2179
2180 /* Bitmap for supported MCS codes. */
2181 __u8 mcs_set[16];
2182 __u8 reserved[16];
2183} __attribute__((packed));
2184
2185static int
2186mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2187{
2188 struct mwl8k_cmd_set_rate *cmd;
2189 int rc;
2190
2191 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2192 if (cmd == NULL)
2193 return -ENOMEM;
2194
2195 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2196 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2197 memcpy(cmd->legacy_rates, mwl8k_rateids, sizeof(mwl8k_rateids));
2198
2199 rc = mwl8k_post_cmd(hw, &cmd->header);
2200 kfree(cmd);
2201
2202 return rc;
2203}
2204
2205/*
2206 * CMD_FINALIZE_JOIN.
2207 */
2208#define MWL8K_FJ_BEACON_MAXLEN 128
2209
2210struct mwl8k_cmd_finalize_join {
2211 struct mwl8k_cmd_pkt header;
2212 __le32 sleep_interval; /* Number of beacon periods to sleep */
2213 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2214} __attribute__((packed));
2215
2216static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2217 int framelen, int dtim)
2218{
2219 struct mwl8k_cmd_finalize_join *cmd;
2220 struct ieee80211_mgmt *payload = frame;
2221 int payload_len;
2222 int rc;
2223
2224 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2225 if (cmd == NULL)
2226 return -ENOMEM;
2227
2228 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2229 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2230 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2231
2232 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2233 if (payload_len < 0)
2234 payload_len = 0;
2235 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2236 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2237
2238 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2239
2240 rc = mwl8k_post_cmd(hw, &cmd->header);
2241 kfree(cmd);
2242
2243 return rc;
2244}
2245
2246/*
2247 * CMD_SET_RTS_THRESHOLD.
2248 */
2249struct mwl8k_cmd_set_rts_threshold {
2250 struct mwl8k_cmd_pkt header;
2251 __le16 action;
2252 __le16 threshold;
2253} __attribute__((packed));
2254
2255static int mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw,
2256 u16 action, u16 threshold)
2257{
2258 struct mwl8k_cmd_set_rts_threshold *cmd;
2259 int rc;
2260
2261 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2262 if (cmd == NULL)
2263 return -ENOMEM;
2264
2265 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2266 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2267 cmd->action = cpu_to_le16(action);
2268 cmd->threshold = cpu_to_le16(threshold);
2269
2270 rc = mwl8k_post_cmd(hw, &cmd->header);
2271 kfree(cmd);
2272
2273 return rc;
2274}
2275
2276/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002277 * CMD_SET_SLOT.
2278 */
2279struct mwl8k_cmd_set_slot {
2280 struct mwl8k_cmd_pkt header;
2281 __le16 action;
2282 __u8 short_slot;
2283} __attribute__((packed));
2284
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002285static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002286{
2287 struct mwl8k_cmd_set_slot *cmd;
2288 int rc;
2289
2290 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2291 if (cmd == NULL)
2292 return -ENOMEM;
2293
2294 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2295 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2296 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002297 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002298
2299 rc = mwl8k_post_cmd(hw, &cmd->header);
2300 kfree(cmd);
2301
2302 return rc;
2303}
2304
2305/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002306 * CMD_SET_EDCA_PARAMS.
2307 */
2308struct mwl8k_cmd_set_edca_params {
2309 struct mwl8k_cmd_pkt header;
2310
2311 /* See MWL8K_SET_EDCA_XXX below */
2312 __le16 action;
2313
2314 /* TX opportunity in units of 32 us */
2315 __le16 txop;
2316
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002317 union {
2318 struct {
2319 /* Log exponent of max contention period: 0...15 */
2320 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002321
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002322 /* Log exponent of min contention period: 0...15 */
2323 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002324
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002325 /* Adaptive interframe spacing in units of 32us */
2326 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002327
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002328 /* TX queue to configure */
2329 __u8 txq;
2330 } ap;
2331 struct {
2332 /* Log exponent of max contention period: 0...15 */
2333 __u8 log_cw_max;
2334
2335 /* Log exponent of min contention period: 0...15 */
2336 __u8 log_cw_min;
2337
2338 /* Adaptive interframe spacing in units of 32us */
2339 __u8 aifs;
2340
2341 /* TX queue to configure */
2342 __u8 txq;
2343 } sta;
2344 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002345} __attribute__((packed));
2346
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002347#define MWL8K_SET_EDCA_CW 0x01
2348#define MWL8K_SET_EDCA_TXOP 0x02
2349#define MWL8K_SET_EDCA_AIFS 0x04
2350
2351#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2352 MWL8K_SET_EDCA_TXOP | \
2353 MWL8K_SET_EDCA_AIFS)
2354
2355static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002356mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2357 __u16 cw_min, __u16 cw_max,
2358 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002359{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002360 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002361 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002362 int rc;
2363
2364 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2365 if (cmd == NULL)
2366 return -ENOMEM;
2367
Lennert Buytenhek22995b22009-10-22 20:20:25 +02002368 /*
2369 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2370 * this call.
2371 */
2372 qnum ^= !(qnum >> 1);
2373
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002374 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2375 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002376 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2377 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002378 if (priv->ap_fw) {
2379 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2380 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2381 cmd->ap.aifs = aifs;
2382 cmd->ap.txq = qnum;
2383 } else {
2384 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2385 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2386 cmd->sta.aifs = aifs;
2387 cmd->sta.txq = qnum;
2388 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002389
2390 rc = mwl8k_post_cmd(hw, &cmd->header);
2391 kfree(cmd);
2392
2393 return rc;
2394}
2395
2396/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002397 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002398 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002399struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002400 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002401 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002402} __attribute__((packed));
2403
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002404static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002405{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002406 struct mwl8k_priv *priv = hw->priv;
2407 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002408 int rc;
2409
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002410 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2411 if (cmd == NULL)
2412 return -ENOMEM;
2413
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002414 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002415 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002416 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002417
2418 rc = mwl8k_post_cmd(hw, &cmd->header);
2419 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002420
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002421 if (!rc)
2422 priv->wmm_enabled = enable;
2423
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002424 return rc;
2425}
2426
2427/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002428 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002429 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002430struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002431 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002432 __le32 action;
2433 __u8 rx_antenna_map;
2434 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002435} __attribute__((packed));
2436
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002437static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002438{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002439 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002440 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002441
2442 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2443 if (cmd == NULL)
2444 return -ENOMEM;
2445
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002446 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002447 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002448 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2449 cmd->rx_antenna_map = rx;
2450 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002451
2452 rc = mwl8k_post_cmd(hw, &cmd->header);
2453 kfree(cmd);
2454
2455 return rc;
2456}
2457
2458/*
2459 * CMD_USE_FIXED_RATE.
2460 */
2461#define MWL8K_RATE_TABLE_SIZE 8
2462#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002463#define MWL8K_USE_AUTO_RATE 0x0002
2464
2465struct mwl8k_rate_entry {
2466 /* Set to 1 if HT rate, 0 if legacy. */
2467 __le32 is_ht_rate;
2468
2469 /* Set to 1 to use retry_count field. */
2470 __le32 enable_retry;
2471
2472 /* Specified legacy rate or MCS. */
2473 __le32 rate;
2474
2475 /* Number of allowed retries. */
2476 __le32 retry_count;
2477} __attribute__((packed));
2478
2479struct mwl8k_rate_table {
2480 /* 1 to allow specified rate and below */
2481 __le32 allow_rate_drop;
2482 __le32 num_rates;
2483 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
2484} __attribute__((packed));
2485
2486struct mwl8k_cmd_use_fixed_rate {
2487 struct mwl8k_cmd_pkt header;
2488 __le32 action;
2489 struct mwl8k_rate_table rate_table;
2490
2491 /* Unicast, Broadcast or Multicast */
2492 __le32 rate_type;
2493 __le32 reserved1;
2494 __le32 reserved2;
2495} __attribute__((packed));
2496
2497static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
2498 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
2499{
2500 struct mwl8k_cmd_use_fixed_rate *cmd;
2501 int count;
2502 int rc;
2503
2504 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2505 if (cmd == NULL)
2506 return -ENOMEM;
2507
2508 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2509 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2510
2511 cmd->action = cpu_to_le32(action);
2512 cmd->rate_type = cpu_to_le32(rate_type);
2513
2514 if (rate_table != NULL) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002515 /*
2516 * Copy over each field manually so that endian
2517 * conversion can be done.
2518 */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002519 cmd->rate_table.allow_rate_drop =
2520 cpu_to_le32(rate_table->allow_rate_drop);
2521 cmd->rate_table.num_rates =
2522 cpu_to_le32(rate_table->num_rates);
2523
2524 for (count = 0; count < rate_table->num_rates; count++) {
2525 struct mwl8k_rate_entry *dst =
2526 &cmd->rate_table.rate_entry[count];
2527 struct mwl8k_rate_entry *src =
2528 &rate_table->rate_entry[count];
2529
2530 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
2531 dst->enable_retry = cpu_to_le32(src->enable_retry);
2532 dst->rate = cpu_to_le32(src->rate);
2533 dst->retry_count = cpu_to_le32(src->retry_count);
2534 }
2535 }
2536
2537 rc = mwl8k_post_cmd(hw, &cmd->header);
2538 kfree(cmd);
2539
2540 return rc;
2541}
2542
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002543/*
2544 * CMD_ENABLE_SNIFFER.
2545 */
2546struct mwl8k_cmd_enable_sniffer {
2547 struct mwl8k_cmd_pkt header;
2548 __le32 action;
2549} __attribute__((packed));
2550
2551static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2552{
2553 struct mwl8k_cmd_enable_sniffer *cmd;
2554 int rc;
2555
2556 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2557 if (cmd == NULL)
2558 return -ENOMEM;
2559
2560 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2561 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2562 cmd->action = cpu_to_le32(!!enable);
2563
2564 rc = mwl8k_post_cmd(hw, &cmd->header);
2565 kfree(cmd);
2566
2567 return rc;
2568}
2569
2570/*
2571 * CMD_SET_MAC_ADDR.
2572 */
2573struct mwl8k_cmd_set_mac_addr {
2574 struct mwl8k_cmd_pkt header;
2575 union {
2576 struct {
2577 __le16 mac_type;
2578 __u8 mac_addr[ETH_ALEN];
2579 } mbss;
2580 __u8 mac_addr[ETH_ALEN];
2581 };
2582} __attribute__((packed));
2583
2584static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2585{
2586 struct mwl8k_priv *priv = hw->priv;
2587 struct mwl8k_cmd_set_mac_addr *cmd;
2588 int rc;
2589
2590 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2591 if (cmd == NULL)
2592 return -ENOMEM;
2593
2594 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2595 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2596 if (priv->ap_fw) {
2597 cmd->mbss.mac_type = 0;
2598 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2599 } else {
2600 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2601 }
2602
2603 rc = mwl8k_post_cmd(hw, &cmd->header);
2604 kfree(cmd);
2605
2606 return rc;
2607}
2608
2609/*
2610 * CMD_SET_RATEADAPT_MODE.
2611 */
2612struct mwl8k_cmd_set_rate_adapt_mode {
2613 struct mwl8k_cmd_pkt header;
2614 __le16 action;
2615 __le16 mode;
2616} __attribute__((packed));
2617
2618static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2619{
2620 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2621 int rc;
2622
2623 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2624 if (cmd == NULL)
2625 return -ENOMEM;
2626
2627 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2628 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2629 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2630 cmd->mode = cpu_to_le16(mode);
2631
2632 rc = mwl8k_post_cmd(hw, &cmd->header);
2633 kfree(cmd);
2634
2635 return rc;
2636}
2637
2638/*
2639 * CMD_UPDATE_STADB.
2640 */
2641struct mwl8k_cmd_update_stadb {
2642 struct mwl8k_cmd_pkt header;
2643
2644 /* See STADB_ACTION_TYPE */
2645 __le32 action;
2646
2647 /* Peer MAC address */
2648 __u8 peer_addr[ETH_ALEN];
2649
2650 __le32 reserved;
2651
2652 /* Peer info - valid during add/update. */
2653 struct peer_capability_info peer_info;
2654} __attribute__((packed));
2655
2656static int mwl8k_cmd_update_stadb(struct ieee80211_hw *hw,
2657 struct ieee80211_vif *vif, __u32 action)
2658{
2659 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
2660 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2661 struct mwl8k_cmd_update_stadb *cmd;
2662 struct peer_capability_info *peer_info;
2663 int rc;
2664
2665 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2666 if (cmd == NULL)
2667 return -ENOMEM;
2668
2669 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2670 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2671
2672 cmd->action = cpu_to_le32(action);
2673 peer_info = &cmd->peer_info;
2674 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2675
2676 switch (action) {
2677 case MWL8K_STA_DB_ADD_ENTRY:
2678 case MWL8K_STA_DB_MODIFY_ENTRY:
2679 /* Build peer_info block */
2680 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2681 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2682 memcpy(peer_info->legacy_rates, mwl8k_rateids,
2683 sizeof(mwl8k_rateids));
2684 peer_info->interop = 1;
2685 peer_info->amsdu_enabled = 0;
2686
2687 rc = mwl8k_post_cmd(hw, &cmd->header);
2688 if (rc == 0)
2689 mv_vif->peer_id = peer_info->station_id;
2690
2691 break;
2692
2693 case MWL8K_STA_DB_DEL_ENTRY:
2694 case MWL8K_STA_DB_FLUSH:
2695 default:
2696 rc = mwl8k_post_cmd(hw, &cmd->header);
2697 if (rc == 0)
2698 mv_vif->peer_id = 0;
2699 break;
2700 }
2701 kfree(cmd);
2702
2703 return rc;
2704}
2705
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002706
2707/*
2708 * Interrupt handling.
2709 */
2710static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2711{
2712 struct ieee80211_hw *hw = dev_id;
2713 struct mwl8k_priv *priv = hw->priv;
2714 u32 status;
2715
2716 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2717 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2718
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002719 if (!status)
2720 return IRQ_NONE;
2721
2722 if (status & MWL8K_A2H_INT_TX_DONE)
2723 tasklet_schedule(&priv->tx_reclaim_task);
2724
2725 if (status & MWL8K_A2H_INT_RX_READY) {
2726 while (rxq_process(hw, 0, 1))
2727 rxq_refill(hw, 0, 1);
2728 }
2729
2730 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002731 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002732 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002733 }
2734
2735 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002736 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002737 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002738 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002739 }
2740
2741 return IRQ_HANDLED;
2742}
2743
2744
2745/*
2746 * Core driver operations.
2747 */
2748static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2749{
2750 struct mwl8k_priv *priv = hw->priv;
2751 int index = skb_get_queue_mapping(skb);
2752 int rc;
2753
2754 if (priv->current_channel == NULL) {
2755 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002756 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002757 dev_kfree_skb(skb);
2758 return NETDEV_TX_OK;
2759 }
2760
2761 rc = mwl8k_txq_xmit(hw, index, skb);
2762
2763 return rc;
2764}
2765
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002766static int mwl8k_start(struct ieee80211_hw *hw)
2767{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002768 struct mwl8k_priv *priv = hw->priv;
2769 int rc;
2770
Joe Perchesa0607fd2009-11-18 23:29:17 -08002771 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002772 IRQF_SHARED, MWL8K_NAME, hw);
2773 if (rc) {
2774 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002775 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002776 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002777 }
2778
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002779 /* Enable tx reclaim tasklet */
2780 tasklet_enable(&priv->tx_reclaim_task);
2781
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002782 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002783 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002784
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002785 rc = mwl8k_fw_lock(hw);
2786 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002787 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002788
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002789 if (!priv->ap_fw) {
2790 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002791 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002792
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002793 if (!rc)
2794 rc = mwl8k_cmd_set_pre_scan(hw);
2795
2796 if (!rc)
2797 rc = mwl8k_cmd_set_post_scan(hw,
2798 "\x00\x00\x00\x00\x00\x00");
2799 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002800
2801 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002802 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002803
2804 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002805 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002806
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002807 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002808 }
2809
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002810 if (rc) {
2811 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2812 free_irq(priv->pdev->irq, hw);
2813 tasklet_disable(&priv->tx_reclaim_task);
2814 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002815
2816 return rc;
2817}
2818
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002819static void mwl8k_stop(struct ieee80211_hw *hw)
2820{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002821 struct mwl8k_priv *priv = hw->priv;
2822 int i;
2823
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002824 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002825
2826 ieee80211_stop_queues(hw);
2827
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002828 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002829 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002830 free_irq(priv->pdev->irq, hw);
2831
2832 /* Stop finalize join worker */
2833 cancel_work_sync(&priv->finalize_join_worker);
2834 if (priv->beacon_skb != NULL)
2835 dev_kfree_skb(priv->beacon_skb);
2836
2837 /* Stop tx reclaim tasklet */
2838 tasklet_disable(&priv->tx_reclaim_task);
2839
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002840 /* Return all skbs to mac80211 */
2841 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2842 mwl8k_txq_reclaim(hw, i, 1);
2843}
2844
2845static int mwl8k_add_interface(struct ieee80211_hw *hw,
2846 struct ieee80211_if_init_conf *conf)
2847{
2848 struct mwl8k_priv *priv = hw->priv;
2849 struct mwl8k_vif *mwl8k_vif;
2850
2851 /*
2852 * We only support one active interface at a time.
2853 */
2854 if (priv->vif != NULL)
2855 return -EBUSY;
2856
2857 /*
2858 * We only support managed interfaces for now.
2859 */
Lennert Buytenhek240e86e2009-07-16 14:15:44 +02002860 if (conf->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002861 return -EINVAL;
2862
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02002863 /*
2864 * Reject interface creation if sniffer mode is active, as
2865 * STA operation is mutually exclusive with hardware sniffer
2866 * mode.
2867 */
2868 if (priv->sniffer_enabled) {
2869 printk(KERN_INFO "%s: unable to create STA "
2870 "interface due to sniffer mode being enabled\n",
2871 wiphy_name(hw->wiphy));
2872 return -EINVAL;
2873 }
2874
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002875 /* Clean out driver private area */
2876 mwl8k_vif = MWL8K_VIF(conf->vif);
2877 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2878
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002879 /* Set and save the mac address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002880 mwl8k_cmd_set_mac_addr(hw, conf->mac_addr);
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002881 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002882
2883 /* Back pointer to parent config block */
2884 mwl8k_vif->priv = priv;
2885
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002886 /* Set Initial sequence number to zero */
2887 mwl8k_vif->seqno = 0;
2888
2889 priv->vif = conf->vif;
2890 priv->current_channel = NULL;
2891
2892 return 0;
2893}
2894
2895static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2896 struct ieee80211_if_init_conf *conf)
2897{
2898 struct mwl8k_priv *priv = hw->priv;
2899
2900 if (priv->vif == NULL)
2901 return;
2902
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002903 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02002904
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002905 priv->vif = NULL;
2906}
2907
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002908static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002909{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002910 struct ieee80211_conf *conf = &hw->conf;
2911 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002912 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002913
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002914 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002915 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002916 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002917 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02002918 }
2919
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002920 rc = mwl8k_fw_lock(hw);
2921 if (rc)
2922 return rc;
2923
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002924 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002925 if (rc)
2926 goto out;
2927
2928 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel);
2929 if (rc)
2930 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002931
2932 priv->current_channel = conf->channel;
2933
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002934 if (conf->power_level > 18)
2935 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002936 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002937 if (rc)
2938 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002939
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002940 if (priv->ap_fw) {
2941 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
2942 if (!rc)
2943 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
2944 } else {
2945 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
2946 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002947
Lennert Buytenhekee03a932009-07-17 07:19:37 +02002948out:
2949 mwl8k_fw_unlock(hw);
2950
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002951 return rc;
2952}
2953
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002954static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
2955 struct ieee80211_vif *vif,
2956 struct ieee80211_bss_conf *info,
2957 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002958{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002959 struct mwl8k_priv *priv = hw->priv;
2960 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002961 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002962
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002963 if ((changed & BSS_CHANGED_ASSOC) == 0)
2964 return;
2965
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002966 priv->capture_beacon = false;
2967
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002968 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek942457d2009-08-24 15:42:36 +02002969 if (rc)
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002970 return;
2971
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002972 if (info->assoc) {
2973 memcpy(&mwl8k_vif->bss_info, info,
2974 sizeof(struct ieee80211_bss_conf));
2975
Lennert Buytenhekd1844d72009-11-30 18:13:56 +01002976 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN);
2977
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002978 /* Install rates */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002979 rc = mwl8k_cmd_set_rate(hw, vif);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002980 if (rc)
2981 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002982
2983 /* Turn on rate adaptation */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002984 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
2985 MWL8K_UCAST_RATE, NULL);
2986 if (rc)
2987 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002988
2989 /* Set radio preamble */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002990 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
2991 if (rc)
2992 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002993
2994 /* Set slot time */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02002995 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot);
2996 if (rc)
2997 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002998
2999 /* Update peer rate info */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003000 rc = mwl8k_cmd_update_stadb(hw, vif,
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003001 MWL8K_STA_DB_MODIFY_ENTRY);
3002 if (rc)
3003 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003004
3005 /* Set AID */
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003006 rc = mwl8k_cmd_set_aid(hw, vif);
3007 if (rc)
3008 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003009
3010 /*
3011 * Finalize the join. Tell rx handler to process
3012 * next beacon from our BSSID.
3013 */
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003014 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003015 priv->capture_beacon = true;
3016 } else {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003017 rc = mwl8k_cmd_update_stadb(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003018 memset(&mwl8k_vif->bss_info, 0,
3019 sizeof(struct ieee80211_bss_conf));
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02003020 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003021 }
3022
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003023out:
3024 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003025}
3026
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003027static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3028 int mc_count, struct dev_addr_list *mclist)
3029{
3030 struct mwl8k_cmd_pkt *cmd;
3031
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003032 /*
3033 * Synthesize and return a command packet that programs the
3034 * hardware multicast address filter. At this point we don't
3035 * know whether FIF_ALLMULTI is being requested, but if it is,
3036 * we'll end up throwing this packet away and creating a new
3037 * one in mwl8k_configure_filter().
3038 */
3039 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003040
3041 return (unsigned long)cmd;
3042}
3043
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003044static int
3045mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3046 unsigned int changed_flags,
3047 unsigned int *total_flags)
3048{
3049 struct mwl8k_priv *priv = hw->priv;
3050
3051 /*
3052 * Hardware sniffer mode is mutually exclusive with STA
3053 * operation, so refuse to enable sniffer mode if a STA
3054 * interface is active.
3055 */
3056 if (priv->vif != NULL) {
3057 if (net_ratelimit())
3058 printk(KERN_INFO "%s: not enabling sniffer "
3059 "mode because STA interface is active\n",
3060 wiphy_name(hw->wiphy));
3061 return 0;
3062 }
3063
3064 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003065 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003066 return 0;
3067 priv->sniffer_enabled = true;
3068 }
3069
3070 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3071 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3072 FIF_OTHER_BSS;
3073
3074 return 1;
3075}
3076
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003077static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3078 unsigned int changed_flags,
3079 unsigned int *total_flags,
3080 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003081{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003082 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003083 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3084
3085 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003086 * AP firmware doesn't allow fine-grained control over
3087 * the receive filter.
3088 */
3089 if (priv->ap_fw) {
3090 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3091 kfree(cmd);
3092 return;
3093 }
3094
3095 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003096 * Enable hardware sniffer mode if FIF_CONTROL or
3097 * FIF_OTHER_BSS is requested.
3098 */
3099 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3100 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3101 kfree(cmd);
3102 return;
3103 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003104
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003105 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003106 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003107
3108 if (mwl8k_fw_lock(hw))
3109 return;
3110
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003111 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003112 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003113 priv->sniffer_enabled = false;
3114 }
3115
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003116 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003117 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3118 /*
3119 * Disable the BSS filter.
3120 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003121 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003122 } else {
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003123 u8 *bssid;
3124
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003125 /*
3126 * Enable the BSS filter.
3127 *
3128 * If there is an active STA interface, use that
3129 * interface's BSSID, otherwise use a dummy one
3130 * (where the OUI part needs to be nonzero for
3131 * the BSSID to be accepted by POST_SCAN).
3132 */
3133 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003134 if (priv->vif != NULL)
3135 bssid = MWL8K_VIF(priv->vif)->bssid;
3136
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003137 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003138 }
3139 }
3140
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003141 /*
3142 * If FIF_ALLMULTI is being requested, throw away the command
3143 * packet that ->prepare_multicast() built and replace it with
3144 * a command packet that enables reception of all multicast
3145 * packets.
3146 */
3147 if (*total_flags & FIF_ALLMULTI) {
3148 kfree(cmd);
3149 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3150 }
3151
3152 if (cmd != NULL) {
3153 mwl8k_post_cmd(hw, cmd);
3154 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003155 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003156
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003157 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003158}
3159
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003160static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3161{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003162 return mwl8k_cmd_set_rts_threshold(hw, MWL8K_CMD_SET, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003163}
3164
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003165static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3166 const struct ieee80211_tx_queue_params *params)
3167{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003168 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003169 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003170
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003171 rc = mwl8k_fw_lock(hw);
3172 if (!rc) {
3173 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003174 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003175
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003176 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003177 rc = mwl8k_cmd_set_edca_params(hw, queue,
3178 params->cw_min,
3179 params->cw_max,
3180 params->aifs,
3181 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003182
3183 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003184 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003185
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003186 return rc;
3187}
3188
3189static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3190 struct ieee80211_tx_queue_stats *stats)
3191{
3192 struct mwl8k_priv *priv = hw->priv;
3193 struct mwl8k_tx_queue *txq;
3194 int index;
3195
3196 spin_lock_bh(&priv->tx_lock);
3197 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3198 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003199 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003200 sizeof(struct ieee80211_tx_queue_stats));
3201 }
3202 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003203
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003204 return 0;
3205}
3206
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003207static int mwl8k_get_stats(struct ieee80211_hw *hw,
3208 struct ieee80211_low_level_stats *stats)
3209{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003210 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003211}
3212
3213static const struct ieee80211_ops mwl8k_ops = {
3214 .tx = mwl8k_tx,
3215 .start = mwl8k_start,
3216 .stop = mwl8k_stop,
3217 .add_interface = mwl8k_add_interface,
3218 .remove_interface = mwl8k_remove_interface,
3219 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003220 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003221 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003222 .configure_filter = mwl8k_configure_filter,
3223 .set_rts_threshold = mwl8k_set_rts_threshold,
3224 .conf_tx = mwl8k_conf_tx,
3225 .get_tx_stats = mwl8k_get_tx_stats,
3226 .get_stats = mwl8k_get_stats,
3227};
3228
3229static void mwl8k_tx_reclaim_handler(unsigned long data)
3230{
3231 int i;
3232 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3233 struct mwl8k_priv *priv = hw->priv;
3234
3235 spin_lock_bh(&priv->tx_lock);
3236 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3237 mwl8k_txq_reclaim(hw, i, 0);
3238
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003239 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003240 complete(priv->tx_wait);
3241 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003242 }
3243 spin_unlock_bh(&priv->tx_lock);
3244}
3245
3246static void mwl8k_finalize_join_worker(struct work_struct *work)
3247{
3248 struct mwl8k_priv *priv =
3249 container_of(work, struct mwl8k_priv, finalize_join_worker);
3250 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003251 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003252
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003253 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003254 dev_kfree_skb(skb);
3255
3256 priv->beacon_skb = NULL;
3257}
3258
John W. Linvillebcb628d2009-11-06 16:40:16 -05003259enum {
3260 MWL8687 = 0,
3261 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003262};
3263
John W. Linvillebcb628d2009-11-06 16:40:16 -05003264static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003265 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003266 .part_name = "88w8687",
3267 .helper_image = "mwl8k/helper_8687.fw",
3268 .fw_image = "mwl8k/fmimage_8687.fw",
3269 .rxd_ops = &rxd_8687_ops,
3270 .modes = BIT(NL80211_IFTYPE_STATION),
3271 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003272 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003273 .part_name = "88w8366",
3274 .helper_image = "mwl8k/helper_8366.fw",
3275 .fw_image = "mwl8k/fmimage_8366.fw",
3276 .rxd_ops = &rxd_8366_ops,
3277 .modes = 0,
3278 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003279};
3280
3281static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003282 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3283 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3284 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3285 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003286};
3287MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3288
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003289static int __devinit mwl8k_probe(struct pci_dev *pdev,
3290 const struct pci_device_id *id)
3291{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003292 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003293 struct ieee80211_hw *hw;
3294 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003295 int rc;
3296 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003297
3298 if (!printed_version) {
3299 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3300 printed_version = 1;
3301 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003302
3303 rc = pci_enable_device(pdev);
3304 if (rc) {
3305 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3306 MWL8K_NAME);
3307 return rc;
3308 }
3309
3310 rc = pci_request_regions(pdev, MWL8K_NAME);
3311 if (rc) {
3312 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3313 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003314 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003315 }
3316
3317 pci_set_master(pdev);
3318
3319 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3320 if (hw == NULL) {
3321 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3322 rc = -ENOMEM;
3323 goto err_free_reg;
3324 }
3325
3326 priv = hw->priv;
3327 priv->hw = hw;
3328 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003329 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02003330 priv->rxd_ops = priv->device_info->rxd_ops;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003331 priv->sniffer_enabled = false;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +02003332 priv->wmm_enabled = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003333 priv->pending_tx_pkts = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003334
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003335 SET_IEEE80211_DEV(hw, &pdev->dev);
3336 pci_set_drvdata(pdev, hw);
3337
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 Buytenheka66098d2009-03-10 10:13:33 +01003359 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3360 priv->band.band = IEEE80211_BAND_2GHZ;
3361 priv->band.channels = priv->channels;
3362 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3363 priv->band.bitrates = priv->rates;
3364 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3365 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3366
3367 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3368 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3369
3370 /*
3371 * Extra headroom is the size of the required DMA header
3372 * minus the size of the smallest 802.11 frame (CTS frame).
3373 */
3374 hw->extra_tx_headroom =
3375 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3376
3377 hw->channel_change_time = 10;
3378
3379 hw->queues = MWL8K_TX_QUEUES;
3380
Lennert Buytenhek547810e2009-10-22 20:21:02 +02003381 hw->wiphy->interface_modes = priv->device_info->modes;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003382
3383 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003384 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003385 hw->vif_data_size = sizeof(struct mwl8k_vif);
3386 priv->vif = NULL;
3387
3388 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003389 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003390 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003391
3392 /* Finalize join worker */
3393 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3394
3395 /* TX reclaim tasklet */
3396 tasklet_init(&priv->tx_reclaim_task,
3397 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3398 tasklet_disable(&priv->tx_reclaim_task);
3399
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003400 /* Power management cookie */
3401 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3402 if (priv->cookie == NULL)
3403 goto err_iounmap;
3404
3405 rc = mwl8k_rxq_init(hw, 0);
3406 if (rc)
3407 goto err_iounmap;
3408 rxq_refill(hw, 0, INT_MAX);
3409
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003410 mutex_init(&priv->fw_mutex);
3411 priv->fw_mutex_owner = NULL;
3412 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003413 priv->hostcmd_wait = NULL;
3414
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003415 spin_lock_init(&priv->tx_lock);
3416
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003417 priv->tx_wait = NULL;
3418
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003419 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3420 rc = mwl8k_txq_init(hw, i);
3421 if (rc)
3422 goto err_free_queues;
3423 }
3424
3425 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003426 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003427 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3428 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3429
Joe Perchesa0607fd2009-11-18 23:29:17 -08003430 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003431 IRQF_SHARED, MWL8K_NAME, hw);
3432 if (rc) {
3433 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003434 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003435 goto err_free_queues;
3436 }
3437
3438 /* Reset firmware and hardware */
3439 mwl8k_hw_reset(priv);
3440
3441 /* Ask userland hotplug daemon for the device firmware */
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003442 rc = mwl8k_request_firmware(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003443 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003444 printk(KERN_ERR "%s: Firmware files not found\n",
3445 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003446 goto err_free_irq;
3447 }
3448
3449 /* Load firmware into hardware */
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003450 rc = mwl8k_load_firmware(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003451 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003452 printk(KERN_ERR "%s: Cannot start firmware\n",
3453 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003454 goto err_stop_firmware;
3455 }
3456
3457 /* Reclaim memory once firmware is successfully loaded */
3458 mwl8k_release_firmware(priv);
3459
3460 /*
3461 * Temporarily enable interrupts. Initial firmware host
3462 * commands use interrupts and avoids polling. Disable
3463 * interrupts when done.
3464 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003465 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003466
3467 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02003468 if (priv->ap_fw) {
3469 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3470 if (!rc)
3471 rc = mwl8k_cmd_set_hw_spec(hw);
3472 } else {
3473 rc = mwl8k_cmd_get_hw_spec_sta(hw);
3474 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003475 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003476 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3477 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003478 goto err_stop_firmware;
3479 }
3480
3481 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003482 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003483 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003484 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003485 goto err_stop_firmware;
3486 }
3487
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003488 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003489 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003490 if (rc) {
3491 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3492 wiphy_name(hw->wiphy));
3493 goto err_stop_firmware;
3494 }
3495
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003496 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003497 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003498 free_irq(priv->pdev->irq, hw);
3499
3500 rc = ieee80211_register_hw(hw);
3501 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003502 printk(KERN_ERR "%s: Cannot register device\n",
3503 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003504 goto err_stop_firmware;
3505 }
3506
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003507 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003508 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003509 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003510 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003511 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3512 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003513
3514 return 0;
3515
3516err_stop_firmware:
3517 mwl8k_hw_reset(priv);
3518 mwl8k_release_firmware(priv);
3519
3520err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003521 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003522 free_irq(priv->pdev->irq, hw);
3523
3524err_free_queues:
3525 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3526 mwl8k_txq_deinit(hw, i);
3527 mwl8k_rxq_deinit(hw, 0);
3528
3529err_iounmap:
3530 if (priv->cookie != NULL)
3531 pci_free_consistent(priv->pdev, 4,
3532 priv->cookie, priv->cookie_dma);
3533
3534 if (priv->regs != NULL)
3535 pci_iounmap(pdev, priv->regs);
3536
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003537 if (priv->sram != NULL)
3538 pci_iounmap(pdev, priv->sram);
3539
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003540 pci_set_drvdata(pdev, NULL);
3541 ieee80211_free_hw(hw);
3542
3543err_free_reg:
3544 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003545
3546err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003547 pci_disable_device(pdev);
3548
3549 return rc;
3550}
3551
Joerg Albert230f7af2009-04-18 02:10:45 +02003552static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003553{
3554 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3555}
3556
Joerg Albert230f7af2009-04-18 02:10:45 +02003557static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003558{
3559 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3560 struct mwl8k_priv *priv;
3561 int i;
3562
3563 if (hw == NULL)
3564 return;
3565 priv = hw->priv;
3566
3567 ieee80211_stop_queues(hw);
3568
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003569 ieee80211_unregister_hw(hw);
3570
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003571 /* Remove tx reclaim tasklet */
3572 tasklet_kill(&priv->tx_reclaim_task);
3573
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003574 /* Stop hardware */
3575 mwl8k_hw_reset(priv);
3576
3577 /* Return all skbs to mac80211 */
3578 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3579 mwl8k_txq_reclaim(hw, i, 1);
3580
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003581 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3582 mwl8k_txq_deinit(hw, i);
3583
3584 mwl8k_rxq_deinit(hw, 0);
3585
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003586 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003587
3588 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003589 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003590 pci_set_drvdata(pdev, NULL);
3591 ieee80211_free_hw(hw);
3592 pci_release_regions(pdev);
3593 pci_disable_device(pdev);
3594}
3595
3596static struct pci_driver mwl8k_driver = {
3597 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003598 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003599 .probe = mwl8k_probe,
3600 .remove = __devexit_p(mwl8k_remove),
3601 .shutdown = __devexit_p(mwl8k_shutdown),
3602};
3603
3604static int __init mwl8k_init(void)
3605{
3606 return pci_register_driver(&mwl8k_driver);
3607}
3608
3609static void __exit mwl8k_exit(void)
3610{
3611 pci_unregister_driver(&mwl8k_driver);
3612}
3613
3614module_init(mwl8k_init);
3615module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003616
3617MODULE_DESCRIPTION(MWL8K_DESC);
3618MODULE_VERSION(MWL8K_VERSION);
3619MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3620MODULE_LICENSE("GPL");