blob: 382ef4305a3e37ba63077bd0a4499adf594d446f [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 Buytenhek6976b662010-01-02 10:31:50 +010029#define MWL8K_VERSION "0.11"
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 Buytenhek89a91f42009-11-30 18:32:54 +010095 struct rxd_ops *ap_rxd_ops;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020096};
97
Lennert Buytenheka66098d2009-03-10 10:13:33 +010098struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020099 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100100
101 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200102 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100103
104 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200105 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100106
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200107 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200108 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200109 struct {
110 struct sk_buff *skb;
111 DECLARE_PCI_UNMAP_ADDR(dma)
112 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100113};
114
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100115struct mwl8k_tx_queue {
116 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200117 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100118
119 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200120 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100121
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200122 struct ieee80211_tx_queue_stats stats;
123 struct mwl8k_tx_desc *txd;
124 dma_addr_t txd_dma;
125 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100126};
127
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100128struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100129 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100130 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200132 struct mwl8k_device_info *device_info;
133
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100134 void __iomem *sram;
135 void __iomem *regs;
136
137 /* firmware */
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100138 struct firmware *fw_helper;
139 struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100140
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100141 /* hardware/firmware parameters */
142 bool ap_fw;
143 struct rxd_ops *rxd_ops;
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100144 struct ieee80211_supported_band band_24;
145 struct ieee80211_channel channels_24[14];
146 struct ieee80211_rate rates_24[14];
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100147 struct ieee80211_supported_band band_50;
148 struct ieee80211_channel channels_50[4];
149 struct ieee80211_rate rates_50[9];
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100150
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200151 /* firmware access */
152 struct mutex fw_mutex;
153 struct task_struct *fw_mutex_owner;
154 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200155 struct completion *hostcmd_wait;
156
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100157 /* lock held over TX and TX reap */
158 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100159
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200160 /* TX quiesce completion, protected by fw_mutex and tx_lock */
161 struct completion *tx_wait;
162
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100163 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100164
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100165 /* power management status cookie from firmware */
166 u32 *cookie;
167 dma_addr_t cookie_dma;
168
169 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100170 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200171 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100172
173 /*
174 * Running count of TX packets in flight, to avoid
175 * iterating over the transmit rings each time.
176 */
177 int pending_tx_pkts;
178
179 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
180 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
181
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 Buytenhekbbfd9122010-01-04 21:55:12 +0100187 struct work_struct sta_notify_worker;
188 spinlock_t sta_notify_list_lock;
189 struct list_head sta_notify_list;
190
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100191 /* XXX need to convert this to handle multiple interfaces */
192 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200193 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100194 struct sk_buff *beacon_skb;
195
196 /*
197 * This FJ worker has to be global as it is scheduled from the
198 * RX handler. At this point we don't know which interface it
199 * belongs to until the list of bssids waiting to complete join
200 * is checked.
201 */
202 struct work_struct finalize_join_worker;
203
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100204 /* Tasklet to perform TX reclaim. */
205 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100206
207 /* Tasklet to perform RX. */
208 struct tasklet_struct poll_rx_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100209};
210
211/* Per interface specific private data */
212struct mwl8k_vif {
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100213 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100214 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100215};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200216#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100217
Lennert Buytenheka6804002010-01-04 21:55:42 +0100218struct mwl8k_sta {
219 /* Index into station database. Returned by UPDATE_STADB. */
220 u8 peer_id;
221};
222#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
223
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100224static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100225 { .center_freq = 2412, .hw_value = 1, },
226 { .center_freq = 2417, .hw_value = 2, },
227 { .center_freq = 2422, .hw_value = 3, },
228 { .center_freq = 2427, .hw_value = 4, },
229 { .center_freq = 2432, .hw_value = 5, },
230 { .center_freq = 2437, .hw_value = 6, },
231 { .center_freq = 2442, .hw_value = 7, },
232 { .center_freq = 2447, .hw_value = 8, },
233 { .center_freq = 2452, .hw_value = 9, },
234 { .center_freq = 2457, .hw_value = 10, },
235 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100236 { .center_freq = 2467, .hw_value = 12, },
237 { .center_freq = 2472, .hw_value = 13, },
238 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100239};
240
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100241static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100242 { .bitrate = 10, .hw_value = 2, },
243 { .bitrate = 20, .hw_value = 4, },
244 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200245 { .bitrate = 110, .hw_value = 22, },
246 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100247 { .bitrate = 60, .hw_value = 12, },
248 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100249 { .bitrate = 120, .hw_value = 24, },
250 { .bitrate = 180, .hw_value = 36, },
251 { .bitrate = 240, .hw_value = 48, },
252 { .bitrate = 360, .hw_value = 72, },
253 { .bitrate = 480, .hw_value = 96, },
254 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100255 { .bitrate = 720, .hw_value = 144, },
256};
257
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100258static const struct ieee80211_channel mwl8k_channels_50[] = {
259 { .center_freq = 5180, .hw_value = 36, },
260 { .center_freq = 5200, .hw_value = 40, },
261 { .center_freq = 5220, .hw_value = 44, },
262 { .center_freq = 5240, .hw_value = 48, },
263};
264
265static const struct ieee80211_rate mwl8k_rates_50[] = {
266 { .bitrate = 60, .hw_value = 12, },
267 { .bitrate = 90, .hw_value = 18, },
268 { .bitrate = 120, .hw_value = 24, },
269 { .bitrate = 180, .hw_value = 36, },
270 { .bitrate = 240, .hw_value = 48, },
271 { .bitrate = 360, .hw_value = 72, },
272 { .bitrate = 480, .hw_value = 96, },
273 { .bitrate = 540, .hw_value = 108, },
274 { .bitrate = 720, .hw_value = 144, },
275};
276
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100277/* Set or get info from Firmware */
278#define MWL8K_CMD_SET 0x0001
279#define MWL8K_CMD_GET 0x0000
280
281/* Firmware command codes */
282#define MWL8K_CMD_CODE_DNLD 0x0001
283#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200284#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100285#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
286#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200287#define MWL8K_CMD_RADIO_CONTROL 0x001c
288#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200289#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100290#define MWL8K_CMD_SET_BEACON 0x0100
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100291#define MWL8K_CMD_SET_PRE_SCAN 0x0107
292#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200293#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100294#define MWL8K_CMD_SET_AID 0x010d
295#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200296#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100297#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200298#define MWL8K_CMD_SET_SLOT 0x0114
299#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
300#define MWL8K_CMD_SET_WMM_MODE 0x0123
301#define MWL8K_CMD_MIMO_CONFIG 0x0125
302#define MWL8K_CMD_USE_FIXED_RATE 0x0126
303#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200304#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200305#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100306#define MWL8K_CMD_BSS_START 0x1100
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100307#define MWL8K_CMD_SET_NEW_STN 0x1111
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200308#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100309
310static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
311{
312#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
313 snprintf(buf, bufsize, "%s", #x);\
314 return buf;\
315 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200316 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100317 MWL8K_CMDNAME(CODE_DNLD);
318 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200319 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100320 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
321 MWL8K_CMDNAME(GET_STAT);
322 MWL8K_CMDNAME(RADIO_CONTROL);
323 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200324 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100325 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100326 MWL8K_CMDNAME(SET_PRE_SCAN);
327 MWL8K_CMDNAME(SET_POST_SCAN);
328 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100329 MWL8K_CMDNAME(SET_AID);
330 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200331 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100332 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200333 MWL8K_CMDNAME(SET_SLOT);
334 MWL8K_CMDNAME(SET_EDCA_PARAMS);
335 MWL8K_CMDNAME(SET_WMM_MODE);
336 MWL8K_CMDNAME(MIMO_CONFIG);
337 MWL8K_CMDNAME(USE_FIXED_RATE);
338 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200339 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200340 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100341 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100342 MWL8K_CMDNAME(SET_NEW_STN);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200343 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100344 default:
345 snprintf(buf, bufsize, "0x%x", cmd);
346 }
347#undef MWL8K_CMDNAME
348
349 return buf;
350}
351
352/* Hardware and firmware reset */
353static void mwl8k_hw_reset(struct mwl8k_priv *priv)
354{
355 iowrite32(MWL8K_H2A_INT_RESET,
356 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
357 iowrite32(MWL8K_H2A_INT_RESET,
358 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
359 msleep(20);
360}
361
362/* Release fw image */
363static void mwl8k_release_fw(struct firmware **fw)
364{
365 if (*fw == NULL)
366 return;
367 release_firmware(*fw);
368 *fw = NULL;
369}
370
371static void mwl8k_release_firmware(struct mwl8k_priv *priv)
372{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100373 mwl8k_release_fw(&priv->fw_ucode);
374 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100375}
376
377/* Request fw image */
378static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200379 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100380{
381 /* release current image */
382 if (*fw != NULL)
383 mwl8k_release_fw(fw);
384
385 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200386 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100387}
388
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200389static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100390{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200391 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100392 int rc;
393
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200394 if (di->helper_image != NULL) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100395 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200396 if (rc) {
397 printk(KERN_ERR "%s: Error requesting helper "
398 "firmware file %s\n", pci_name(priv->pdev),
399 di->helper_image);
400 return rc;
401 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100402 }
403
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100404 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100405 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200406 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200407 pci_name(priv->pdev), di->fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100408 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100409 return rc;
410 }
411
412 return 0;
413}
414
415struct mwl8k_cmd_pkt {
416 __le16 code;
417 __le16 length;
418 __le16 seq_num;
419 __le16 result;
420 char payload[0];
421} __attribute__((packed));
422
423/*
424 * Firmware loading.
425 */
426static int
427mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
428{
429 void __iomem *regs = priv->regs;
430 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100431 int loops;
432
433 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
434 if (pci_dma_mapping_error(priv->pdev, dma_addr))
435 return -ENOMEM;
436
437 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
438 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
439 iowrite32(MWL8K_H2A_INT_DOORBELL,
440 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
441 iowrite32(MWL8K_H2A_INT_DUMMY,
442 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
443
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100444 loops = 1000;
445 do {
446 u32 int_code;
447
448 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
449 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
450 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100451 break;
452 }
453
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200454 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100455 udelay(1);
456 } while (--loops);
457
458 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
459
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200460 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100461}
462
463static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
464 const u8 *data, size_t length)
465{
466 struct mwl8k_cmd_pkt *cmd;
467 int done;
468 int rc = 0;
469
470 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
471 if (cmd == NULL)
472 return -ENOMEM;
473
474 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
475 cmd->seq_num = 0;
476 cmd->result = 0;
477
478 done = 0;
479 while (length) {
480 int block_size = length > 256 ? 256 : length;
481
482 memcpy(cmd->payload, data + done, block_size);
483 cmd->length = cpu_to_le16(block_size);
484
485 rc = mwl8k_send_fw_load_cmd(priv, cmd,
486 sizeof(*cmd) + block_size);
487 if (rc)
488 break;
489
490 done += block_size;
491 length -= block_size;
492 }
493
494 if (!rc) {
495 cmd->length = 0;
496 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
497 }
498
499 kfree(cmd);
500
501 return rc;
502}
503
504static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
505 const u8 *data, size_t length)
506{
507 unsigned char *buffer;
508 int may_continue, rc = 0;
509 u32 done, prev_block_size;
510
511 buffer = kmalloc(1024, GFP_KERNEL);
512 if (buffer == NULL)
513 return -ENOMEM;
514
515 done = 0;
516 prev_block_size = 0;
517 may_continue = 1000;
518 while (may_continue > 0) {
519 u32 block_size;
520
521 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
522 if (block_size & 1) {
523 block_size &= ~1;
524 may_continue--;
525 } else {
526 done += prev_block_size;
527 length -= prev_block_size;
528 }
529
530 if (block_size > 1024 || block_size > length) {
531 rc = -EOVERFLOW;
532 break;
533 }
534
535 if (length == 0) {
536 rc = 0;
537 break;
538 }
539
540 if (block_size == 0) {
541 rc = -EPROTO;
542 may_continue--;
543 udelay(1);
544 continue;
545 }
546
547 prev_block_size = block_size;
548 memcpy(buffer, data + done, block_size);
549
550 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
551 if (rc)
552 break;
553 }
554
555 if (!rc && length != 0)
556 rc = -EREMOTEIO;
557
558 kfree(buffer);
559
560 return rc;
561}
562
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200563static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100564{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200565 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100566 struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200567 int rc;
568 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100569
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200570 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100571 struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100572
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200573 if (helper == NULL) {
574 printk(KERN_ERR "%s: helper image needed but none "
575 "given\n", pci_name(priv->pdev));
576 return -EINVAL;
577 }
578
579 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100580 if (rc) {
581 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200582 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100583 return rc;
584 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100585 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100586
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200587 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100588 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200589 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100590 }
591
592 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200593 printk(KERN_ERR "%s: unable to load firmware image\n",
594 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100595 return rc;
596 }
597
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100598 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100599
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100600 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100601 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200602 u32 ready_code;
603
604 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
605 if (ready_code == MWL8K_FWAP_READY) {
606 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100607 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200608 } else if (ready_code == MWL8K_FWSTA_READY) {
609 priv->ap_fw = 0;
610 break;
611 }
612
613 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100614 udelay(1);
615 } while (--loops);
616
617 return loops ? 0 : -ETIMEDOUT;
618}
619
620
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100621/* DMA header used by firmware and hardware. */
622struct mwl8k_dma_data {
623 __le16 fwlen;
624 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100625 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100626} __attribute__((packed));
627
628/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100629static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100630{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100631 struct mwl8k_dma_data *tr;
632 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100633
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100634 tr = (struct mwl8k_dma_data *)skb->data;
635 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
636
637 if (hdrlen != sizeof(tr->wh)) {
638 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
639 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
640 *((__le16 *)(tr->data - 2)) = qos;
641 } else {
642 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
643 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100644 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100645
646 if (hdrlen != sizeof(*tr))
647 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100648}
649
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200650static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100651{
652 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100653 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100654 struct mwl8k_dma_data *tr;
655
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100656 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100657 * Add a firmware DMA header; the firmware requires that we
658 * present a 2-byte payload length followed by a 4-address
659 * header (without QoS field), followed (optionally) by any
660 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100661 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100662 wh = (struct ieee80211_hdr *)skb->data;
663
664 hdrlen = ieee80211_hdrlen(wh->frame_control);
665 if (hdrlen != sizeof(*tr))
666 skb_push(skb, sizeof(*tr) - hdrlen);
667
668 if (ieee80211_is_data_qos(wh->frame_control))
669 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100670
671 tr = (struct mwl8k_dma_data *)skb->data;
672 if (wh != &tr->wh)
673 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100674 if (hdrlen != sizeof(tr->wh))
675 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100676
677 /*
678 * Firmware length is the length of the fully formed "802.11
679 * payload". That is, everything except for the 802.11 header.
680 * This includes all crypto material including the MIC.
681 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100682 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100683}
684
685
686/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100687 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200688 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100689struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200690 __le16 pkt_len;
691 __u8 sq2;
692 __u8 rate;
693 __le32 pkt_phys_addr;
694 __le32 next_rxd_phys_addr;
695 __le16 qos_control;
696 __le16 htsig2;
697 __le32 hw_rssi_info;
698 __le32 hw_noise_floor_info;
699 __u8 noise_floor;
700 __u8 pad0[3];
701 __u8 rssi;
702 __u8 rx_status;
703 __u8 channel;
704 __u8 rx_ctrl;
705} __attribute__((packed));
706
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100707#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
708#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
709#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100710
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100711#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200712
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100713static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200714{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100715 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200716
717 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100718 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200719}
720
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100721static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200722{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100723 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200724
725 rxd->pkt_len = cpu_to_le16(len);
726 rxd->pkt_phys_addr = cpu_to_le32(addr);
727 wmb();
728 rxd->rx_ctrl = 0;
729}
730
731static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100732mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
733 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200734{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100735 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200736
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100737 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200738 return -1;
739 rmb();
740
741 memset(status, 0, sizeof(*status));
742
743 status->signal = -rxd->rssi;
744 status->noise = -rxd->noise_floor;
745
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100746 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200747 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100748 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100749 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100750 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200751 } else {
752 int i;
753
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100754 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
755 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200756 status->rate_idx = i;
757 break;
758 }
759 }
760 }
761
Lennert Buytenhek85478342010-01-12 13:48:56 +0100762 if (rxd->channel > 14) {
763 status->band = IEEE80211_BAND_5GHZ;
764 if (!(status->flag & RX_FLAG_HT))
765 status->rate_idx -= 5;
766 } else {
767 status->band = IEEE80211_BAND_2GHZ;
768 }
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200769 status->freq = ieee80211_channel_to_frequency(rxd->channel);
770
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100771 *qos = rxd->qos_control;
772
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200773 return le16_to_cpu(rxd->pkt_len);
774}
775
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100776static struct rxd_ops rxd_8366_ap_ops = {
777 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
778 .rxd_init = mwl8k_rxd_8366_ap_init,
779 .rxd_refill = mwl8k_rxd_8366_ap_refill,
780 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200781};
782
783/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100784 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100785 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100786struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100787 __le16 pkt_len;
788 __u8 link_quality;
789 __u8 noise_level;
790 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200791 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100792 __le16 qos_control;
793 __le16 rate_info;
794 __le32 pad0[4];
795 __u8 rssi;
796 __u8 channel;
797 __le16 pad1;
798 __u8 rx_ctrl;
799 __u8 rx_status;
800 __u8 pad2[2];
801} __attribute__((packed));
802
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100803#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
804#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
805#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
806#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
807#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
808#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200809
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100810#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200811
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100812static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200813{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100814 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200815
816 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100817 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200818}
819
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100820static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200821{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100822 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200823
824 rxd->pkt_len = cpu_to_le16(len);
825 rxd->pkt_phys_addr = cpu_to_le32(addr);
826 wmb();
827 rxd->rx_ctrl = 0;
828}
829
830static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100831mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100832 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200833{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100834 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200835 u16 rate_info;
836
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100837 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200838 return -1;
839 rmb();
840
841 rate_info = le16_to_cpu(rxd->rate_info);
842
843 memset(status, 0, sizeof(*status));
844
845 status->signal = -rxd->rssi;
846 status->noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100847 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
848 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200849
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100850 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200851 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100852 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200853 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100854 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200855 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100856 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200857 status->flag |= RX_FLAG_HT;
858
Lennert Buytenhek85478342010-01-12 13:48:56 +0100859 if (rxd->channel > 14) {
860 status->band = IEEE80211_BAND_5GHZ;
861 if (!(status->flag & RX_FLAG_HT))
862 status->rate_idx -= 5;
863 } else {
864 status->band = IEEE80211_BAND_2GHZ;
865 }
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200866 status->freq = ieee80211_channel_to_frequency(rxd->channel);
867
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100868 *qos = rxd->qos_control;
869
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200870 return le16_to_cpu(rxd->pkt_len);
871}
872
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100873static struct rxd_ops rxd_sta_ops = {
874 .rxd_size = sizeof(struct mwl8k_rxd_sta),
875 .rxd_init = mwl8k_rxd_sta_init,
876 .rxd_refill = mwl8k_rxd_sta_refill,
877 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200878};
879
880
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100881#define MWL8K_RX_DESCS 256
882#define MWL8K_RX_MAXSZ 3800
883
884static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
885{
886 struct mwl8k_priv *priv = hw->priv;
887 struct mwl8k_rx_queue *rxq = priv->rxq + index;
888 int size;
889 int i;
890
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200891 rxq->rxd_count = 0;
892 rxq->head = 0;
893 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100894
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200895 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100896
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200897 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
898 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100899 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200900 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100901 return -ENOMEM;
902 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200903 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100904
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200905 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
906 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100907 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200908 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200909 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100910 return -ENOMEM;
911 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200912 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100913
914 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200915 int desc_size;
916 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100917 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200918 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100919
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200920 desc_size = priv->rxd_ops->rxd_size;
921 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100922
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200923 nexti = i + 1;
924 if (nexti == MWL8K_RX_DESCS)
925 nexti = 0;
926 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
927
928 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100929 }
930
931 return 0;
932}
933
934static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
935{
936 struct mwl8k_priv *priv = hw->priv;
937 struct mwl8k_rx_queue *rxq = priv->rxq + index;
938 int refilled;
939
940 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200941 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100942 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200943 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100944 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200945 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100946
947 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
948 if (skb == NULL)
949 break;
950
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200951 addr = pci_map_single(priv->pdev, skb->data,
952 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100953
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200954 rxq->rxd_count++;
955 rx = rxq->tail++;
956 if (rxq->tail == MWL8K_RX_DESCS)
957 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200958 rxq->buf[rx].skb = skb;
959 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200960
961 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
962 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100963
964 refilled++;
965 }
966
967 return refilled;
968}
969
970/* Must be called only when the card's reception is completely halted */
971static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
972{
973 struct mwl8k_priv *priv = hw->priv;
974 struct mwl8k_rx_queue *rxq = priv->rxq + index;
975 int i;
976
977 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200978 if (rxq->buf[i].skb != NULL) {
979 pci_unmap_single(priv->pdev,
980 pci_unmap_addr(&rxq->buf[i], dma),
981 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
982 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100983
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200984 kfree_skb(rxq->buf[i].skb);
985 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100986 }
987 }
988
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200989 kfree(rxq->buf);
990 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100991
992 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200993 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200994 rxq->rxd, rxq->rxd_dma);
995 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100996}
997
998
999/*
1000 * Scan a list of BSSIDs to process for finalize join.
1001 * Allows for extension to process multiple BSSIDs.
1002 */
1003static inline int
1004mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1005{
1006 return priv->capture_beacon &&
1007 ieee80211_is_beacon(wh->frame_control) &&
1008 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1009}
1010
Lennert Buytenhek37797522009-10-22 20:19:45 +02001011static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1012 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001013{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001014 struct mwl8k_priv *priv = hw->priv;
1015
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001016 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001017 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001018
1019 /*
1020 * Use GFP_ATOMIC as rxq_process is called from
1021 * the primary interrupt handler, memory allocation call
1022 * must not sleep.
1023 */
1024 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1025 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001026 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001027}
1028
1029static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1030{
1031 struct mwl8k_priv *priv = hw->priv;
1032 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1033 int processed;
1034
1035 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001036 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001037 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001038 void *rxd;
1039 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001040 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001041 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001042
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001043 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001044 if (skb == NULL)
1045 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001046
1047 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1048
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001049 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001050 if (pkt_len < 0)
1051 break;
1052
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001053 rxq->buf[rxq->head].skb = NULL;
1054
1055 pci_unmap_single(priv->pdev,
1056 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1057 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1058 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001059
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001060 rxq->head++;
1061 if (rxq->head == MWL8K_RX_DESCS)
1062 rxq->head = 0;
1063
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001064 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001065
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001066 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001067 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001068
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001069 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001070 * Check for a pending join operation. Save a
1071 * copy of the beacon and schedule a tasklet to
1072 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001073 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001074 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001075 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001076
Johannes Bergf1d58c22009-06-17 13:13:00 +02001077 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1078 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001079
1080 processed++;
1081 }
1082
1083 return processed;
1084}
1085
1086
1087/*
1088 * Packet transmission.
1089 */
1090
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001091#define MWL8K_TXD_STATUS_OK 0x00000001
1092#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1093#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1094#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001095#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001096
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001097#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1098#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1099#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1100#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1101#define MWL8K_QOS_EOSP 0x0010
1102
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001103struct mwl8k_tx_desc {
1104 __le32 status;
1105 __u8 data_rate;
1106 __u8 tx_priority;
1107 __le16 qos_control;
1108 __le32 pkt_phys_addr;
1109 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001110 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001111 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001112 __le32 reserved;
1113 __le16 rate_info;
1114 __u8 peer_id;
1115 __u8 tx_frag_cnt;
1116} __attribute__((packed));
1117
1118#define MWL8K_TX_DESCS 128
1119
1120static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1121{
1122 struct mwl8k_priv *priv = hw->priv;
1123 struct mwl8k_tx_queue *txq = priv->txq + index;
1124 int size;
1125 int i;
1126
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001127 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1128 txq->stats.limit = MWL8K_TX_DESCS;
1129 txq->head = 0;
1130 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001131
1132 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1133
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001134 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1135 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001136 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001137 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001138 return -ENOMEM;
1139 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001140 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001141
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001142 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1143 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001144 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001145 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001146 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001147 return -ENOMEM;
1148 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001149 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001150
1151 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1152 struct mwl8k_tx_desc *tx_desc;
1153 int nexti;
1154
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001155 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001156 nexti = (i + 1) % MWL8K_TX_DESCS;
1157
1158 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001159 tx_desc->next_txd_phys_addr =
1160 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001161 }
1162
1163 return 0;
1164}
1165
1166static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1167{
1168 iowrite32(MWL8K_H2A_INT_PPA_READY,
1169 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1170 iowrite32(MWL8K_H2A_INT_DUMMY,
1171 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1172 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1173}
1174
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001175static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001176{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001177 struct mwl8k_priv *priv = hw->priv;
1178 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001179
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001180 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1181 struct mwl8k_tx_queue *txq = priv->txq + i;
1182 int fw_owned = 0;
1183 int drv_owned = 0;
1184 int unused = 0;
1185 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001186
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001187 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001188 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1189 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001190
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001191 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001192 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001193 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001194 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001195 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001196
1197 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001198 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001199 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001200
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001201 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1202 "fw_owned=%d drv_owned=%d unused=%d\n",
1203 wiphy_name(hw->wiphy), i,
1204 txq->stats.len, txq->head, txq->tail,
1205 fw_owned, drv_owned, unused);
1206 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001207}
1208
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001209/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001210 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001211 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001212#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001213
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001214static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001215{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001216 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001217 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001218 int retry;
1219 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001220
1221 might_sleep();
1222
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001223 /*
1224 * The TX queues are stopped at this point, so this test
1225 * doesn't need to take ->tx_lock.
1226 */
1227 if (!priv->pending_tx_pkts)
1228 return 0;
1229
1230 retry = 0;
1231 rc = 0;
1232
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001233 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001234 priv->tx_wait = &tx_wait;
1235 while (!rc) {
1236 int oldcount;
1237 unsigned long timeout;
1238
1239 oldcount = priv->pending_tx_pkts;
1240
1241 spin_unlock_bh(&priv->tx_lock);
1242 timeout = wait_for_completion_timeout(&tx_wait,
1243 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1244 spin_lock_bh(&priv->tx_lock);
1245
1246 if (timeout) {
1247 WARN_ON(priv->pending_tx_pkts);
1248 if (retry) {
1249 printk(KERN_NOTICE "%s: tx rings drained\n",
1250 wiphy_name(hw->wiphy));
1251 }
1252 break;
1253 }
1254
1255 if (priv->pending_tx_pkts < oldcount) {
Lennert Buytenhek9a2303b2010-01-04 21:54:25 +01001256 printk(KERN_NOTICE "%s: waiting for tx rings "
1257 "to drain (%d -> %d pkts)\n",
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001258 wiphy_name(hw->wiphy), oldcount,
1259 priv->pending_tx_pkts);
1260 retry = 1;
1261 continue;
1262 }
1263
1264 priv->tx_wait = NULL;
1265
1266 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1267 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1268 mwl8k_dump_tx_rings(hw);
1269
1270 rc = -ETIMEDOUT;
1271 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001272 spin_unlock_bh(&priv->tx_lock);
1273
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001274 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001275}
1276
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001277#define MWL8K_TXD_SUCCESS(status) \
1278 ((status) & (MWL8K_TXD_STATUS_OK | \
1279 MWL8K_TXD_STATUS_OK_RETRY | \
1280 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001281
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001282static int
1283mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001284{
1285 struct mwl8k_priv *priv = hw->priv;
1286 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001287 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001288
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001289 processed = 0;
1290 while (txq->stats.len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001291 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001292 struct mwl8k_tx_desc *tx_desc;
1293 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001294 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001295 struct sk_buff *skb;
1296 struct ieee80211_tx_info *info;
1297 u32 status;
1298
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001299 tx = txq->head;
1300 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001301
1302 status = le32_to_cpu(tx_desc->status);
1303
1304 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1305 if (!force)
1306 break;
1307 tx_desc->status &=
1308 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1309 }
1310
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001311 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1312 BUG_ON(txq->stats.len == 0);
1313 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001314 priv->pending_tx_pkts--;
1315
1316 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001317 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001318 skb = txq->skb[tx];
1319 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001320
1321 BUG_ON(skb == NULL);
1322 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1323
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001324 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001325
1326 /* Mark descriptor as unused */
1327 tx_desc->pkt_phys_addr = 0;
1328 tx_desc->pkt_len = 0;
1329
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001330 info = IEEE80211_SKB_CB(skb);
1331 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001332 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001333 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001334
1335 ieee80211_tx_status_irqsafe(hw, skb);
1336
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001337 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001338 }
1339
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001340 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001341 ieee80211_wake_queue(hw, index);
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001342
1343 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001344}
1345
1346/* must be called only when the card's transmit is completely halted */
1347static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1348{
1349 struct mwl8k_priv *priv = hw->priv;
1350 struct mwl8k_tx_queue *txq = priv->txq + index;
1351
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001352 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001353
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001354 kfree(txq->skb);
1355 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001356
1357 pci_free_consistent(priv->pdev,
1358 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001359 txq->txd, txq->txd_dma);
1360 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001361}
1362
1363static int
1364mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1365{
1366 struct mwl8k_priv *priv = hw->priv;
1367 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001368 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001369 struct ieee80211_hdr *wh;
1370 struct mwl8k_tx_queue *txq;
1371 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001372 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001373 u32 txstatus;
1374 u8 txdatarate;
1375 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001376
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001377 wh = (struct ieee80211_hdr *)skb->data;
1378 if (ieee80211_is_data_qos(wh->frame_control))
1379 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1380 else
1381 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001382
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001383 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001384 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001385
1386 tx_info = IEEE80211_SKB_CB(skb);
1387 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001388
1389 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001390 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001391 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1392 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001393 }
1394
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001395 /* Setup firmware control bit fields for each frame type. */
1396 txstatus = 0;
1397 txdatarate = 0;
1398 if (ieee80211_is_mgmt(wh->frame_control) ||
1399 ieee80211_is_ctl(wh->frame_control)) {
1400 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001401 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001402 } else if (ieee80211_is_data(wh->frame_control)) {
1403 txdatarate = 1;
1404 if (is_multicast_ether_addr(wh->addr1))
1405 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1406
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001407 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001408 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001409 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001410 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001411 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001412 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001413
1414 dma = pci_map_single(priv->pdev, skb->data,
1415 skb->len, PCI_DMA_TODEVICE);
1416
1417 if (pci_dma_mapping_error(priv->pdev, dma)) {
1418 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001419 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001420 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001421 return NETDEV_TX_OK;
1422 }
1423
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001424 spin_lock_bh(&priv->tx_lock);
1425
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001426 txq = priv->txq + index;
1427
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001428 BUG_ON(txq->skb[txq->tail] != NULL);
1429 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001430
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001431 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001432 tx->data_rate = txdatarate;
1433 tx->tx_priority = index;
1434 tx->qos_control = cpu_to_le16(qos);
1435 tx->pkt_phys_addr = cpu_to_le32(dma);
1436 tx->pkt_len = cpu_to_le16(skb->len);
1437 tx->rate_info = 0;
Lennert Buytenheka6804002010-01-04 21:55:42 +01001438 if (!priv->ap_fw && tx_info->control.sta != NULL)
1439 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1440 else
1441 tx->peer_id = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001442 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001443 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1444
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001445 txq->stats.count++;
1446 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001447 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001448
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001449 txq->tail++;
1450 if (txq->tail == MWL8K_TX_DESCS)
1451 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001452
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001453 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001454 ieee80211_stop_queue(hw, index);
1455
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001456 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001457
1458 spin_unlock_bh(&priv->tx_lock);
1459
1460 return NETDEV_TX_OK;
1461}
1462
1463
1464/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001465 * Firmware access.
1466 *
1467 * We have the following requirements for issuing firmware commands:
1468 * - Some commands require that the packet transmit path is idle when
1469 * the command is issued. (For simplicity, we'll just quiesce the
1470 * transmit path for every command.)
1471 * - There are certain sequences of commands that need to be issued to
1472 * the hardware sequentially, with no other intervening commands.
1473 *
1474 * This leads to an implementation of a "firmware lock" as a mutex that
1475 * can be taken recursively, and which is taken by both the low-level
1476 * command submission function (mwl8k_post_cmd) as well as any users of
1477 * that function that require issuing of an atomic sequence of commands,
1478 * and quiesces the transmit path whenever it's taken.
1479 */
1480static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1481{
1482 struct mwl8k_priv *priv = hw->priv;
1483
1484 if (priv->fw_mutex_owner != current) {
1485 int rc;
1486
1487 mutex_lock(&priv->fw_mutex);
1488 ieee80211_stop_queues(hw);
1489
1490 rc = mwl8k_tx_wait_empty(hw);
1491 if (rc) {
1492 ieee80211_wake_queues(hw);
1493 mutex_unlock(&priv->fw_mutex);
1494
1495 return rc;
1496 }
1497
1498 priv->fw_mutex_owner = current;
1499 }
1500
1501 priv->fw_mutex_depth++;
1502
1503 return 0;
1504}
1505
1506static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1507{
1508 struct mwl8k_priv *priv = hw->priv;
1509
1510 if (!--priv->fw_mutex_depth) {
1511 ieee80211_wake_queues(hw);
1512 priv->fw_mutex_owner = NULL;
1513 mutex_unlock(&priv->fw_mutex);
1514 }
1515}
1516
1517
1518/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001519 * Command processing.
1520 */
1521
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001522/* Timeout firmware commands after 10s */
1523#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001524
1525static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1526{
1527 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1528 struct mwl8k_priv *priv = hw->priv;
1529 void __iomem *regs = priv->regs;
1530 dma_addr_t dma_addr;
1531 unsigned int dma_size;
1532 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001533 unsigned long timeout = 0;
1534 u8 buf[32];
1535
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001536 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001537 dma_size = le16_to_cpu(cmd->length);
1538 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1539 PCI_DMA_BIDIRECTIONAL);
1540 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1541 return -ENOMEM;
1542
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001543 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001544 if (rc) {
1545 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1546 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001547 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001548 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001549
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001550 priv->hostcmd_wait = &cmd_wait;
1551 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1552 iowrite32(MWL8K_H2A_INT_DOORBELL,
1553 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1554 iowrite32(MWL8K_H2A_INT_DUMMY,
1555 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001556
1557 timeout = wait_for_completion_timeout(&cmd_wait,
1558 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1559
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001560 priv->hostcmd_wait = NULL;
1561
1562 mwl8k_fw_unlock(hw);
1563
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001564 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1565 PCI_DMA_BIDIRECTIONAL);
1566
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001567 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001568 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001569 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001570 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1571 MWL8K_CMD_TIMEOUT_MS);
1572 rc = -ETIMEDOUT;
1573 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001574 int ms;
1575
1576 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1577
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001578 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001579 if (rc)
1580 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001581 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001582 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001583 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001584 else if (ms > 2000)
1585 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1586 wiphy_name(hw->wiphy),
1587 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1588 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001589 }
1590
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001591 return rc;
1592}
1593
1594/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001595 * Setup code shared between STA and AP firmware images.
1596 */
1597static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1598{
1599 struct mwl8k_priv *priv = hw->priv;
1600
1601 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1602 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1603
1604 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1605 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1606
1607 priv->band_24.band = IEEE80211_BAND_2GHZ;
1608 priv->band_24.channels = priv->channels_24;
1609 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1610 priv->band_24.bitrates = priv->rates_24;
1611 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1612
1613 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1614}
1615
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01001616static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
1617{
1618 struct mwl8k_priv *priv = hw->priv;
1619
1620 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
1621 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
1622
1623 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
1624 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
1625
1626 priv->band_50.band = IEEE80211_BAND_5GHZ;
1627 priv->band_50.channels = priv->channels_50;
1628 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
1629 priv->band_50.bitrates = priv->rates_50;
1630 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
1631
1632 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
1633}
1634
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001635/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001636 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001637 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001638struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001639 struct mwl8k_cmd_pkt header;
1640 __u8 hw_rev;
1641 __u8 host_interface;
1642 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001643 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001644 __le16 region_code;
1645 __le32 fw_rev;
1646 __le32 ps_cookie;
1647 __le32 caps;
1648 __u8 mcs_bitmap[16];
1649 __le32 rx_queue_ptr;
1650 __le32 num_tx_queues;
1651 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1652 __le32 caps2;
1653 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001654 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001655} __attribute__((packed));
1656
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001657#define MWL8K_CAP_MAX_AMSDU 0x20000000
1658#define MWL8K_CAP_GREENFIELD 0x08000000
1659#define MWL8K_CAP_AMPDU 0x04000000
1660#define MWL8K_CAP_RX_STBC 0x01000000
1661#define MWL8K_CAP_TX_STBC 0x00800000
1662#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1663#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1664#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1665#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1666#define MWL8K_CAP_DELAY_BA 0x00003000
1667#define MWL8K_CAP_MIMO 0x00000200
1668#define MWL8K_CAP_40MHZ 0x00000100
Lennert Buytenhek06953232010-01-12 13:49:41 +01001669#define MWL8K_CAP_BAND_MASK 0x00000007
1670#define MWL8K_CAP_5GHZ 0x00000004
1671#define MWL8K_CAP_2GHZ4 0x00000001
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001672
Lennert Buytenhek06953232010-01-12 13:49:41 +01001673static void
1674mwl8k_set_ht_caps(struct ieee80211_hw *hw,
1675 struct ieee80211_supported_band *band, u32 cap)
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001676{
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001677 int rx_streams;
1678 int tx_streams;
1679
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001680 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001681
1682 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001683 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001684 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001685 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001686 if (cap & MWL8K_CAP_AMPDU) {
1687 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001688 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1689 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001690 }
1691 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001692 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001693 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001694 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001695 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001696 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001697 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001698 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001699 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001700 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001701 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001702 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001703
1704 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1705 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1706
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001707 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001708 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001709 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001710 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001711 band->ht_cap.mcs.rx_mask[2] = 0xff;
1712 band->ht_cap.mcs.rx_mask[4] = 0x01;
1713 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001714
1715 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001716 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1717 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001718 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1719 }
1720}
1721
Lennert Buytenhek06953232010-01-12 13:49:41 +01001722static void
1723mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
1724{
1725 struct mwl8k_priv *priv = hw->priv;
1726
1727 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
1728 mwl8k_setup_2ghz_band(hw);
1729 if (caps & MWL8K_CAP_MIMO)
1730 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
1731 }
1732
1733 if (caps & MWL8K_CAP_5GHZ) {
1734 mwl8k_setup_5ghz_band(hw);
1735 if (caps & MWL8K_CAP_MIMO)
1736 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
1737 }
1738}
1739
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001740static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001741{
1742 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001743 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001744 int rc;
1745 int i;
1746
1747 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1748 if (cmd == NULL)
1749 return -ENOMEM;
1750
1751 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1752 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1753
1754 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1755 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001756 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001757 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001758 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001759 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001760 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001761 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001762
1763 rc = mwl8k_post_cmd(hw, &cmd->header);
1764
1765 if (!rc) {
1766 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1767 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001768 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001769 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek06953232010-01-12 13:49:41 +01001770 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001771 }
1772
1773 kfree(cmd);
1774 return rc;
1775}
1776
1777/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001778 * CMD_GET_HW_SPEC (AP version).
1779 */
1780struct mwl8k_cmd_get_hw_spec_ap {
1781 struct mwl8k_cmd_pkt header;
1782 __u8 hw_rev;
1783 __u8 host_interface;
1784 __le16 num_wcb;
1785 __le16 num_mcaddrs;
1786 __u8 perm_addr[ETH_ALEN];
1787 __le16 region_code;
1788 __le16 num_antenna;
1789 __le32 fw_rev;
1790 __le32 wcbbase0;
1791 __le32 rxwrptr;
1792 __le32 rxrdptr;
1793 __le32 ps_cookie;
1794 __le32 wcbbase1;
1795 __le32 wcbbase2;
1796 __le32 wcbbase3;
1797} __attribute__((packed));
1798
1799static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1800{
1801 struct mwl8k_priv *priv = hw->priv;
1802 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1803 int rc;
1804
1805 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1806 if (cmd == NULL)
1807 return -ENOMEM;
1808
1809 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1810 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1811
1812 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1813 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1814
1815 rc = mwl8k_post_cmd(hw, &cmd->header);
1816
1817 if (!rc) {
1818 int off;
1819
1820 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1821 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1822 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1823 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001824 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001825
1826 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1827 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1828
1829 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1830 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1831
1832 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1833 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1834
1835 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1836 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1837
1838 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1839 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1840
1841 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1842 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1843 }
1844
1845 kfree(cmd);
1846 return rc;
1847}
1848
1849/*
1850 * CMD_SET_HW_SPEC.
1851 */
1852struct mwl8k_cmd_set_hw_spec {
1853 struct mwl8k_cmd_pkt header;
1854 __u8 hw_rev;
1855 __u8 host_interface;
1856 __le16 num_mcaddrs;
1857 __u8 perm_addr[ETH_ALEN];
1858 __le16 region_code;
1859 __le32 fw_rev;
1860 __le32 ps_cookie;
1861 __le32 caps;
1862 __le32 rx_queue_ptr;
1863 __le32 num_tx_queues;
1864 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1865 __le32 flags;
1866 __le32 num_tx_desc_per_queue;
1867 __le32 total_rxd;
1868} __attribute__((packed));
1869
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001870#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1871#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1872#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001873
1874static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1875{
1876 struct mwl8k_priv *priv = hw->priv;
1877 struct mwl8k_cmd_set_hw_spec *cmd;
1878 int rc;
1879 int i;
1880
1881 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1882 if (cmd == NULL)
1883 return -ENOMEM;
1884
1885 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1886 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1887
1888 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1889 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1890 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1891 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1892 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001893 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1894 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1895 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001896 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1897 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1898
1899 rc = mwl8k_post_cmd(hw, &cmd->header);
1900 kfree(cmd);
1901
1902 return rc;
1903}
1904
1905/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001906 * CMD_MAC_MULTICAST_ADR.
1907 */
1908struct mwl8k_cmd_mac_multicast_adr {
1909 struct mwl8k_cmd_pkt header;
1910 __le16 action;
1911 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001912 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001913};
1914
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001915#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1916#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1917#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1918#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001919
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001920static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001921__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001922 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001923{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001924 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001925 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001926 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001927
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001928 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001929 allmulti = 1;
1930 mc_count = 0;
1931 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001932
1933 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1934
1935 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001936 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001937 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001938
1939 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1940 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001941 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1942 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001943
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001944 if (allmulti) {
1945 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1946 } else if (mc_count) {
1947 int i;
1948
1949 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1950 cmd->numaddr = cpu_to_le16(mc_count);
1951 for (i = 0; i < mc_count && mclist; i++) {
1952 if (mclist->da_addrlen != ETH_ALEN) {
1953 kfree(cmd);
1954 return NULL;
1955 }
1956 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1957 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001958 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001959 }
1960
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001961 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001962}
1963
1964/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001965 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001966 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001967struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001968 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001969 __le32 stats[64];
1970} __attribute__((packed));
1971
1972#define MWL8K_STAT_ACK_FAILURE 9
1973#define MWL8K_STAT_RTS_FAILURE 12
1974#define MWL8K_STAT_FCS_ERROR 24
1975#define MWL8K_STAT_RTS_SUCCESS 11
1976
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001977static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1978 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001979{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001980 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001981 int rc;
1982
1983 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1984 if (cmd == NULL)
1985 return -ENOMEM;
1986
1987 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1988 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001989
1990 rc = mwl8k_post_cmd(hw, &cmd->header);
1991 if (!rc) {
1992 stats->dot11ACKFailureCount =
1993 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1994 stats->dot11RTSFailureCount =
1995 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1996 stats->dot11FCSErrorCount =
1997 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1998 stats->dot11RTSSuccessCount =
1999 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2000 }
2001 kfree(cmd);
2002
2003 return rc;
2004}
2005
2006/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002007 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002008 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002009struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002010 struct mwl8k_cmd_pkt header;
2011 __le16 action;
2012 __le16 control;
2013 __le16 radio_on;
2014} __attribute__((packed));
2015
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002016static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002017mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002018{
2019 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002020 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002021 int rc;
2022
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002023 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002024 return 0;
2025
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002026 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2027 if (cmd == NULL)
2028 return -ENOMEM;
2029
2030 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2031 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2032 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002033 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002034 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2035
2036 rc = mwl8k_post_cmd(hw, &cmd->header);
2037 kfree(cmd);
2038
2039 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002040 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002041
2042 return rc;
2043}
2044
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002045static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002046{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002047 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002048}
2049
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002050static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002051{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002052 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002053}
2054
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002055static int
2056mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2057{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002058 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002059
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002060 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002061
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002062 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002063}
2064
2065/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002066 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002067 */
2068#define MWL8K_TX_POWER_LEVEL_TOTAL 8
2069
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002070struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002071 struct mwl8k_cmd_pkt header;
2072 __le16 action;
2073 __le16 support_level;
2074 __le16 current_level;
2075 __le16 reserved;
2076 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2077} __attribute__((packed));
2078
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002079static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002080{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002081 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002082 int rc;
2083
2084 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2085 if (cmd == NULL)
2086 return -ENOMEM;
2087
2088 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2089 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2090 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2091 cmd->support_level = cpu_to_le16(dBm);
2092
2093 rc = mwl8k_post_cmd(hw, &cmd->header);
2094 kfree(cmd);
2095
2096 return rc;
2097}
2098
2099/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002100 * CMD_RF_ANTENNA.
2101 */
2102struct mwl8k_cmd_rf_antenna {
2103 struct mwl8k_cmd_pkt header;
2104 __le16 antenna;
2105 __le16 mode;
2106} __attribute__((packed));
2107
2108#define MWL8K_RF_ANTENNA_RX 1
2109#define MWL8K_RF_ANTENNA_TX 2
2110
2111static int
2112mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2113{
2114 struct mwl8k_cmd_rf_antenna *cmd;
2115 int rc;
2116
2117 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2118 if (cmd == NULL)
2119 return -ENOMEM;
2120
2121 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2122 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2123 cmd->antenna = cpu_to_le16(antenna);
2124 cmd->mode = cpu_to_le16(mask);
2125
2126 rc = mwl8k_post_cmd(hw, &cmd->header);
2127 kfree(cmd);
2128
2129 return rc;
2130}
2131
2132/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002133 * CMD_SET_BEACON.
2134 */
2135struct mwl8k_cmd_set_beacon {
2136 struct mwl8k_cmd_pkt header;
2137 __le16 beacon_len;
2138 __u8 beacon[0];
2139};
2140
2141static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, u8 *beacon, int len)
2142{
2143 struct mwl8k_cmd_set_beacon *cmd;
2144 int rc;
2145
2146 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2147 if (cmd == NULL)
2148 return -ENOMEM;
2149
2150 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2151 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2152 cmd->beacon_len = cpu_to_le16(len);
2153 memcpy(cmd->beacon, beacon, len);
2154
2155 rc = mwl8k_post_cmd(hw, &cmd->header);
2156 kfree(cmd);
2157
2158 return rc;
2159}
2160
2161/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002162 * CMD_SET_PRE_SCAN.
2163 */
2164struct mwl8k_cmd_set_pre_scan {
2165 struct mwl8k_cmd_pkt header;
2166} __attribute__((packed));
2167
2168static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2169{
2170 struct mwl8k_cmd_set_pre_scan *cmd;
2171 int rc;
2172
2173 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2174 if (cmd == NULL)
2175 return -ENOMEM;
2176
2177 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2178 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2179
2180 rc = mwl8k_post_cmd(hw, &cmd->header);
2181 kfree(cmd);
2182
2183 return rc;
2184}
2185
2186/*
2187 * CMD_SET_POST_SCAN.
2188 */
2189struct mwl8k_cmd_set_post_scan {
2190 struct mwl8k_cmd_pkt header;
2191 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002192 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002193} __attribute__((packed));
2194
2195static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002196mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002197{
2198 struct mwl8k_cmd_set_post_scan *cmd;
2199 int rc;
2200
2201 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2202 if (cmd == NULL)
2203 return -ENOMEM;
2204
2205 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2206 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2207 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002208 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002209
2210 rc = mwl8k_post_cmd(hw, &cmd->header);
2211 kfree(cmd);
2212
2213 return rc;
2214}
2215
2216/*
2217 * CMD_SET_RF_CHANNEL.
2218 */
2219struct mwl8k_cmd_set_rf_channel {
2220 struct mwl8k_cmd_pkt header;
2221 __le16 action;
2222 __u8 current_channel;
2223 __le32 channel_flags;
2224} __attribute__((packed));
2225
2226static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002227 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002228{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002229 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002230 struct mwl8k_cmd_set_rf_channel *cmd;
2231 int rc;
2232
2233 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2234 if (cmd == NULL)
2235 return -ENOMEM;
2236
2237 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2238 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2239 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2240 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002241
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002242 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002243 cmd->channel_flags |= cpu_to_le32(0x00000001);
Lennert Buytenhek42574ea2010-01-12 13:49:18 +01002244 else if (channel->band == IEEE80211_BAND_5GHZ)
2245 cmd->channel_flags |= cpu_to_le32(0x00000004);
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002246
2247 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2248 conf->channel_type == NL80211_CHAN_HT20)
2249 cmd->channel_flags |= cpu_to_le32(0x00000080);
2250 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2251 cmd->channel_flags |= cpu_to_le32(0x000001900);
2252 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2253 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002254
2255 rc = mwl8k_post_cmd(hw, &cmd->header);
2256 kfree(cmd);
2257
2258 return rc;
2259}
2260
2261/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002262 * CMD_SET_AID.
2263 */
2264#define MWL8K_FRAME_PROT_DISABLED 0x00
2265#define MWL8K_FRAME_PROT_11G 0x07
2266#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2267#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2268
2269struct mwl8k_cmd_update_set_aid {
2270 struct mwl8k_cmd_pkt header;
2271 __le16 aid;
2272
2273 /* AP's MAC address (BSSID) */
2274 __u8 bssid[ETH_ALEN];
2275 __le16 protection_mode;
2276 __u8 supp_rates[14];
2277} __attribute__((packed));
2278
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002279static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2280{
2281 int i;
2282 int j;
2283
2284 /*
2285 * Clear nonstandard rates 4 and 13.
2286 */
2287 mask &= 0x1fef;
2288
2289 for (i = 0, j = 0; i < 14; i++) {
2290 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002291 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002292 }
2293}
2294
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002295static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002296mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2297 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002298{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002299 struct mwl8k_cmd_update_set_aid *cmd;
2300 u16 prot_mode;
2301 int rc;
2302
2303 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2304 if (cmd == NULL)
2305 return -ENOMEM;
2306
2307 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2308 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002309 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002310 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002311
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002312 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002313 prot_mode = MWL8K_FRAME_PROT_11G;
2314 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002315 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002316 IEEE80211_HT_OP_MODE_PROTECTION) {
2317 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2318 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2319 break;
2320 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2321 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2322 break;
2323 default:
2324 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2325 break;
2326 }
2327 }
2328 cmd->protection_mode = cpu_to_le16(prot_mode);
2329
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002330 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002331
2332 rc = mwl8k_post_cmd(hw, &cmd->header);
2333 kfree(cmd);
2334
2335 return rc;
2336}
2337
2338/*
2339 * CMD_SET_RATE.
2340 */
2341struct mwl8k_cmd_set_rate {
2342 struct mwl8k_cmd_pkt header;
2343 __u8 legacy_rates[14];
2344
2345 /* Bitmap for supported MCS codes. */
2346 __u8 mcs_set[16];
2347 __u8 reserved[16];
2348} __attribute__((packed));
2349
2350static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002351mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002352 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002353{
2354 struct mwl8k_cmd_set_rate *cmd;
2355 int rc;
2356
2357 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2358 if (cmd == NULL)
2359 return -ENOMEM;
2360
2361 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2362 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002363 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002364 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002365
2366 rc = mwl8k_post_cmd(hw, &cmd->header);
2367 kfree(cmd);
2368
2369 return rc;
2370}
2371
2372/*
2373 * CMD_FINALIZE_JOIN.
2374 */
2375#define MWL8K_FJ_BEACON_MAXLEN 128
2376
2377struct mwl8k_cmd_finalize_join {
2378 struct mwl8k_cmd_pkt header;
2379 __le32 sleep_interval; /* Number of beacon periods to sleep */
2380 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2381} __attribute__((packed));
2382
2383static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2384 int framelen, int dtim)
2385{
2386 struct mwl8k_cmd_finalize_join *cmd;
2387 struct ieee80211_mgmt *payload = frame;
2388 int payload_len;
2389 int rc;
2390
2391 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2392 if (cmd == NULL)
2393 return -ENOMEM;
2394
2395 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2396 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2397 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2398
2399 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2400 if (payload_len < 0)
2401 payload_len = 0;
2402 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2403 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2404
2405 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2406
2407 rc = mwl8k_post_cmd(hw, &cmd->header);
2408 kfree(cmd);
2409
2410 return rc;
2411}
2412
2413/*
2414 * CMD_SET_RTS_THRESHOLD.
2415 */
2416struct mwl8k_cmd_set_rts_threshold {
2417 struct mwl8k_cmd_pkt header;
2418 __le16 action;
2419 __le16 threshold;
2420} __attribute__((packed));
2421
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002422static int
2423mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002424{
2425 struct mwl8k_cmd_set_rts_threshold *cmd;
2426 int rc;
2427
2428 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2429 if (cmd == NULL)
2430 return -ENOMEM;
2431
2432 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2433 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002434 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2435 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002436
2437 rc = mwl8k_post_cmd(hw, &cmd->header);
2438 kfree(cmd);
2439
2440 return rc;
2441}
2442
2443/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002444 * CMD_SET_SLOT.
2445 */
2446struct mwl8k_cmd_set_slot {
2447 struct mwl8k_cmd_pkt header;
2448 __le16 action;
2449 __u8 short_slot;
2450} __attribute__((packed));
2451
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002452static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002453{
2454 struct mwl8k_cmd_set_slot *cmd;
2455 int rc;
2456
2457 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2458 if (cmd == NULL)
2459 return -ENOMEM;
2460
2461 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2462 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2463 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002464 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002465
2466 rc = mwl8k_post_cmd(hw, &cmd->header);
2467 kfree(cmd);
2468
2469 return rc;
2470}
2471
2472/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002473 * CMD_SET_EDCA_PARAMS.
2474 */
2475struct mwl8k_cmd_set_edca_params {
2476 struct mwl8k_cmd_pkt header;
2477
2478 /* See MWL8K_SET_EDCA_XXX below */
2479 __le16 action;
2480
2481 /* TX opportunity in units of 32 us */
2482 __le16 txop;
2483
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002484 union {
2485 struct {
2486 /* Log exponent of max contention period: 0...15 */
2487 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002488
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002489 /* Log exponent of min contention period: 0...15 */
2490 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002491
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002492 /* Adaptive interframe spacing in units of 32us */
2493 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002494
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002495 /* TX queue to configure */
2496 __u8 txq;
2497 } ap;
2498 struct {
2499 /* Log exponent of max contention period: 0...15 */
2500 __u8 log_cw_max;
2501
2502 /* Log exponent of min contention period: 0...15 */
2503 __u8 log_cw_min;
2504
2505 /* Adaptive interframe spacing in units of 32us */
2506 __u8 aifs;
2507
2508 /* TX queue to configure */
2509 __u8 txq;
2510 } sta;
2511 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002512} __attribute__((packed));
2513
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002514#define MWL8K_SET_EDCA_CW 0x01
2515#define MWL8K_SET_EDCA_TXOP 0x02
2516#define MWL8K_SET_EDCA_AIFS 0x04
2517
2518#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2519 MWL8K_SET_EDCA_TXOP | \
2520 MWL8K_SET_EDCA_AIFS)
2521
2522static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002523mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2524 __u16 cw_min, __u16 cw_max,
2525 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002526{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002527 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002528 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002529 int rc;
2530
2531 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2532 if (cmd == NULL)
2533 return -ENOMEM;
2534
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002535 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2536 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002537 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2538 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002539 if (priv->ap_fw) {
2540 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2541 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2542 cmd->ap.aifs = aifs;
2543 cmd->ap.txq = qnum;
2544 } else {
2545 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2546 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2547 cmd->sta.aifs = aifs;
2548 cmd->sta.txq = qnum;
2549 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002550
2551 rc = mwl8k_post_cmd(hw, &cmd->header);
2552 kfree(cmd);
2553
2554 return rc;
2555}
2556
2557/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002558 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002559 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002560struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002561 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002562 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002563} __attribute__((packed));
2564
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002565static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002566{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002567 struct mwl8k_priv *priv = hw->priv;
2568 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002569 int rc;
2570
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002571 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2572 if (cmd == NULL)
2573 return -ENOMEM;
2574
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002575 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002576 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002577 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002578
2579 rc = mwl8k_post_cmd(hw, &cmd->header);
2580 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002581
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002582 if (!rc)
2583 priv->wmm_enabled = enable;
2584
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002585 return rc;
2586}
2587
2588/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002589 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002590 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002591struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002592 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002593 __le32 action;
2594 __u8 rx_antenna_map;
2595 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002596} __attribute__((packed));
2597
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002598static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002599{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002600 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002601 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002602
2603 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2604 if (cmd == NULL)
2605 return -ENOMEM;
2606
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002607 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002608 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002609 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2610 cmd->rx_antenna_map = rx;
2611 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002612
2613 rc = mwl8k_post_cmd(hw, &cmd->header);
2614 kfree(cmd);
2615
2616 return rc;
2617}
2618
2619/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002620 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002621 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002622struct mwl8k_cmd_use_fixed_rate_sta {
2623 struct mwl8k_cmd_pkt header;
2624 __le32 action;
2625 __le32 allow_rate_drop;
2626 __le32 num_rates;
2627 struct {
2628 __le32 is_ht_rate;
2629 __le32 enable_retry;
2630 __le32 rate;
2631 __le32 retry_count;
2632 } rate_entry[8];
2633 __le32 rate_type;
2634 __le32 reserved1;
2635 __le32 reserved2;
2636} __attribute__((packed));
2637
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002638#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002639#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002640
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002641static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002642{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002643 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002644 int rc;
2645
2646 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2647 if (cmd == NULL)
2648 return -ENOMEM;
2649
2650 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2651 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002652 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2653 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002654
2655 rc = mwl8k_post_cmd(hw, &cmd->header);
2656 kfree(cmd);
2657
2658 return rc;
2659}
2660
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002661/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002662 * CMD_USE_FIXED_RATE (AP version).
2663 */
2664struct mwl8k_cmd_use_fixed_rate_ap {
2665 struct mwl8k_cmd_pkt header;
2666 __le32 action;
2667 __le32 allow_rate_drop;
2668 __le32 num_rates;
2669 struct mwl8k_rate_entry_ap {
2670 __le32 is_ht_rate;
2671 __le32 enable_retry;
2672 __le32 rate;
2673 __le32 retry_count;
2674 } rate_entry[4];
2675 u8 multicast_rate;
2676 u8 multicast_rate_type;
2677 u8 management_rate;
2678} __attribute__((packed));
2679
2680static int
2681mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2682{
2683 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2684 int rc;
2685
2686 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2687 if (cmd == NULL)
2688 return -ENOMEM;
2689
2690 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2691 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2692 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2693 cmd->multicast_rate = mcast;
2694 cmd->management_rate = mgmt;
2695
2696 rc = mwl8k_post_cmd(hw, &cmd->header);
2697 kfree(cmd);
2698
2699 return rc;
2700}
2701
2702/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002703 * CMD_ENABLE_SNIFFER.
2704 */
2705struct mwl8k_cmd_enable_sniffer {
2706 struct mwl8k_cmd_pkt header;
2707 __le32 action;
2708} __attribute__((packed));
2709
2710static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2711{
2712 struct mwl8k_cmd_enable_sniffer *cmd;
2713 int rc;
2714
2715 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2716 if (cmd == NULL)
2717 return -ENOMEM;
2718
2719 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2720 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2721 cmd->action = cpu_to_le32(!!enable);
2722
2723 rc = mwl8k_post_cmd(hw, &cmd->header);
2724 kfree(cmd);
2725
2726 return rc;
2727}
2728
2729/*
2730 * CMD_SET_MAC_ADDR.
2731 */
2732struct mwl8k_cmd_set_mac_addr {
2733 struct mwl8k_cmd_pkt header;
2734 union {
2735 struct {
2736 __le16 mac_type;
2737 __u8 mac_addr[ETH_ALEN];
2738 } mbss;
2739 __u8 mac_addr[ETH_ALEN];
2740 };
2741} __attribute__((packed));
2742
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002743#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2744#define MWL8K_MAC_TYPE_PRIMARY_AP 2
2745
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002746static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2747{
2748 struct mwl8k_priv *priv = hw->priv;
2749 struct mwl8k_cmd_set_mac_addr *cmd;
2750 int rc;
2751
2752 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2753 if (cmd == NULL)
2754 return -ENOMEM;
2755
2756 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2757 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2758 if (priv->ap_fw) {
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002759 cmd->mbss.mac_type = cpu_to_le16(MWL8K_MAC_TYPE_PRIMARY_AP);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002760 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2761 } else {
2762 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2763 }
2764
2765 rc = mwl8k_post_cmd(hw, &cmd->header);
2766 kfree(cmd);
2767
2768 return rc;
2769}
2770
2771/*
2772 * CMD_SET_RATEADAPT_MODE.
2773 */
2774struct mwl8k_cmd_set_rate_adapt_mode {
2775 struct mwl8k_cmd_pkt header;
2776 __le16 action;
2777 __le16 mode;
2778} __attribute__((packed));
2779
2780static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2781{
2782 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2783 int rc;
2784
2785 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2786 if (cmd == NULL)
2787 return -ENOMEM;
2788
2789 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2790 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2791 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2792 cmd->mode = cpu_to_le16(mode);
2793
2794 rc = mwl8k_post_cmd(hw, &cmd->header);
2795 kfree(cmd);
2796
2797 return rc;
2798}
2799
2800/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002801 * CMD_BSS_START.
2802 */
2803struct mwl8k_cmd_bss_start {
2804 struct mwl8k_cmd_pkt header;
2805 __le32 enable;
2806} __attribute__((packed));
2807
2808static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, int enable)
2809{
2810 struct mwl8k_cmd_bss_start *cmd;
2811 int rc;
2812
2813 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2814 if (cmd == NULL)
2815 return -ENOMEM;
2816
2817 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2818 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2819 cmd->enable = cpu_to_le32(enable);
2820
2821 rc = mwl8k_post_cmd(hw, &cmd->header);
2822 kfree(cmd);
2823
2824 return rc;
2825}
2826
2827/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002828 * CMD_SET_NEW_STN.
2829 */
2830struct mwl8k_cmd_set_new_stn {
2831 struct mwl8k_cmd_pkt header;
2832 __le16 aid;
2833 __u8 mac_addr[6];
2834 __le16 stn_id;
2835 __le16 action;
2836 __le16 rsvd;
2837 __le32 legacy_rates;
2838 __u8 ht_rates[4];
2839 __le16 cap_info;
2840 __le16 ht_capabilities_info;
2841 __u8 mac_ht_param_info;
2842 __u8 rev;
2843 __u8 control_channel;
2844 __u8 add_channel;
2845 __le16 op_mode;
2846 __le16 stbc;
2847 __u8 add_qos_info;
2848 __u8 is_qos_sta;
2849 __le32 fw_sta_ptr;
2850} __attribute__((packed));
2851
2852#define MWL8K_STA_ACTION_ADD 0
2853#define MWL8K_STA_ACTION_REMOVE 2
2854
2855static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2856 struct ieee80211_vif *vif,
2857 struct ieee80211_sta *sta)
2858{
2859 struct mwl8k_cmd_set_new_stn *cmd;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01002860 u32 rates;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002861 int rc;
2862
2863 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2864 if (cmd == NULL)
2865 return -ENOMEM;
2866
2867 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2868 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2869 cmd->aid = cpu_to_le16(sta->aid);
2870 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2871 cmd->stn_id = cpu_to_le16(sta->aid);
2872 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01002873 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
2874 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
2875 else
2876 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
2877 cmd->legacy_rates = cpu_to_le32(rates);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002878 if (sta->ht_cap.ht_supported) {
2879 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2880 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2881 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2882 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2883 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2884 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2885 ((sta->ht_cap.ampdu_density & 7) << 2);
2886 cmd->is_qos_sta = 1;
2887 }
2888
2889 rc = mwl8k_post_cmd(hw, &cmd->header);
2890 kfree(cmd);
2891
2892 return rc;
2893}
2894
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002895static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2896 struct ieee80211_vif *vif)
2897{
2898 struct mwl8k_cmd_set_new_stn *cmd;
2899 int rc;
2900
2901 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2902 if (cmd == NULL)
2903 return -ENOMEM;
2904
2905 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2906 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2907 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2908
2909 rc = mwl8k_post_cmd(hw, &cmd->header);
2910 kfree(cmd);
2911
2912 return rc;
2913}
2914
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002915static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2916 struct ieee80211_vif *vif, u8 *addr)
2917{
2918 struct mwl8k_cmd_set_new_stn *cmd;
2919 int rc;
2920
2921 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2922 if (cmd == NULL)
2923 return -ENOMEM;
2924
2925 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2926 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2927 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2928 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2929
2930 rc = mwl8k_post_cmd(hw, &cmd->header);
2931 kfree(cmd);
2932
2933 return rc;
2934}
2935
2936/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002937 * CMD_UPDATE_STADB.
2938 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01002939struct ewc_ht_info {
2940 __le16 control1;
2941 __le16 control2;
2942 __le16 control3;
2943} __attribute__((packed));
2944
2945struct peer_capability_info {
2946 /* Peer type - AP vs. STA. */
2947 __u8 peer_type;
2948
2949 /* Basic 802.11 capabilities from assoc resp. */
2950 __le16 basic_caps;
2951
2952 /* Set if peer supports 802.11n high throughput (HT). */
2953 __u8 ht_support;
2954
2955 /* Valid if HT is supported. */
2956 __le16 ht_caps;
2957 __u8 extended_ht_caps;
2958 struct ewc_ht_info ewc_info;
2959
2960 /* Legacy rate table. Intersection of our rates and peer rates. */
2961 __u8 legacy_rates[12];
2962
2963 /* HT rate table. Intersection of our rates and peer rates. */
2964 __u8 ht_rates[16];
2965 __u8 pad[16];
2966
2967 /* If set, interoperability mode, no proprietary extensions. */
2968 __u8 interop;
2969 __u8 pad2;
2970 __u8 station_id;
2971 __le16 amsdu_enabled;
2972} __attribute__((packed));
2973
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002974struct mwl8k_cmd_update_stadb {
2975 struct mwl8k_cmd_pkt header;
2976
2977 /* See STADB_ACTION_TYPE */
2978 __le32 action;
2979
2980 /* Peer MAC address */
2981 __u8 peer_addr[ETH_ALEN];
2982
2983 __le32 reserved;
2984
2985 /* Peer info - valid during add/update. */
2986 struct peer_capability_info peer_info;
2987} __attribute__((packed));
2988
Lennert Buytenheka6804002010-01-04 21:55:42 +01002989#define MWL8K_STA_DB_MODIFY_ENTRY 1
2990#define MWL8K_STA_DB_DEL_ENTRY 2
2991
2992/* Peer Entry flags - used to define the type of the peer node */
2993#define MWL8K_PEER_TYPE_ACCESSPOINT 2
2994
2995static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002996 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002997 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002998{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002999 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01003000 struct peer_capability_info *p;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003001 u32 rates;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003002 int rc;
3003
3004 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3005 if (cmd == NULL)
3006 return -ENOMEM;
3007
3008 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3009 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01003010 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003011 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003012
Lennert Buytenheka6804002010-01-04 21:55:42 +01003013 p = &cmd->peer_info;
3014 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
3015 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003016 p->ht_support = sta->ht_cap.ht_supported;
3017 p->ht_caps = sta->ht_cap.cap;
3018 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
3019 ((sta->ht_cap.ampdu_density & 7) << 2);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003020 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3021 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3022 else
3023 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3024 legacy_rate_mask_to_array(p->legacy_rates, rates);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003025 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003026 p->interop = 1;
3027 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003028
Lennert Buytenheka6804002010-01-04 21:55:42 +01003029 rc = mwl8k_post_cmd(hw, &cmd->header);
3030 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003031
Lennert Buytenheka6804002010-01-04 21:55:42 +01003032 return rc ? rc : p->station_id;
3033}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003034
Lennert Buytenheka6804002010-01-04 21:55:42 +01003035static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
3036 struct ieee80211_vif *vif, u8 *addr)
3037{
3038 struct mwl8k_cmd_update_stadb *cmd;
3039 int rc;
3040
3041 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3042 if (cmd == NULL)
3043 return -ENOMEM;
3044
3045 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3046 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3047 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
3048 memcpy(cmd->peer_addr, addr, ETH_ALEN);
3049
3050 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003051 kfree(cmd);
3052
3053 return rc;
3054}
3055
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003056
3057/*
3058 * Interrupt handling.
3059 */
3060static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
3061{
3062 struct ieee80211_hw *hw = dev_id;
3063 struct mwl8k_priv *priv = hw->priv;
3064 u32 status;
3065
3066 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003067 if (!status)
3068 return IRQ_NONE;
3069
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003070 if (status & MWL8K_A2H_INT_TX_DONE) {
3071 status &= ~MWL8K_A2H_INT_TX_DONE;
3072 tasklet_schedule(&priv->poll_tx_task);
3073 }
3074
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003075 if (status & MWL8K_A2H_INT_RX_READY) {
3076 status &= ~MWL8K_A2H_INT_RX_READY;
3077 tasklet_schedule(&priv->poll_rx_task);
3078 }
3079
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003080 if (status)
3081 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003082
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003083 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003084 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003085 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003086 }
3087
3088 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003089 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003090 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003091 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003092 }
3093
3094 return IRQ_HANDLED;
3095}
3096
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003097static void mwl8k_tx_poll(unsigned long data)
3098{
3099 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3100 struct mwl8k_priv *priv = hw->priv;
3101 int limit;
3102 int i;
3103
3104 limit = 32;
3105
3106 spin_lock_bh(&priv->tx_lock);
3107
3108 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3109 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3110
3111 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3112 complete(priv->tx_wait);
3113 priv->tx_wait = NULL;
3114 }
3115
3116 spin_unlock_bh(&priv->tx_lock);
3117
3118 if (limit) {
3119 writel(~MWL8K_A2H_INT_TX_DONE,
3120 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3121 } else {
3122 tasklet_schedule(&priv->poll_tx_task);
3123 }
3124}
3125
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003126static void mwl8k_rx_poll(unsigned long data)
3127{
3128 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3129 struct mwl8k_priv *priv = hw->priv;
3130 int limit;
3131
3132 limit = 32;
3133 limit -= rxq_process(hw, 0, limit);
3134 limit -= rxq_refill(hw, 0, limit);
3135
3136 if (limit) {
3137 writel(~MWL8K_A2H_INT_RX_READY,
3138 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3139 } else {
3140 tasklet_schedule(&priv->poll_rx_task);
3141 }
3142}
3143
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003144
3145/*
3146 * Core driver operations.
3147 */
3148static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3149{
3150 struct mwl8k_priv *priv = hw->priv;
3151 int index = skb_get_queue_mapping(skb);
3152 int rc;
3153
Lennert Buytenhek9189c102010-01-12 13:47:32 +01003154 if (!priv->radio_on) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003155 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003156 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003157 dev_kfree_skb(skb);
3158 return NETDEV_TX_OK;
3159 }
3160
3161 rc = mwl8k_txq_xmit(hw, index, skb);
3162
3163 return rc;
3164}
3165
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003166static int mwl8k_start(struct ieee80211_hw *hw)
3167{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003168 struct mwl8k_priv *priv = hw->priv;
3169 int rc;
3170
Joe Perchesa0607fd2009-11-18 23:29:17 -08003171 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003172 IRQF_SHARED, MWL8K_NAME, hw);
3173 if (rc) {
3174 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003175 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003176 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003177 }
3178
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003179 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003180 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003181 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003182
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003183 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003184 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003185
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003186 rc = mwl8k_fw_lock(hw);
3187 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003188 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003189
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003190 if (!priv->ap_fw) {
3191 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003192 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003193
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003194 if (!rc)
3195 rc = mwl8k_cmd_set_pre_scan(hw);
3196
3197 if (!rc)
3198 rc = mwl8k_cmd_set_post_scan(hw,
3199 "\x00\x00\x00\x00\x00\x00");
3200 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003201
3202 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003203 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003204
3205 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003206 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003207
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003208 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003209 }
3210
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003211 if (rc) {
3212 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3213 free_irq(priv->pdev->irq, hw);
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003214 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003215 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003216 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003217
3218 return rc;
3219}
3220
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003221static void mwl8k_stop(struct ieee80211_hw *hw)
3222{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003223 struct mwl8k_priv *priv = hw->priv;
3224 int i;
3225
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003226 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003227
3228 ieee80211_stop_queues(hw);
3229
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003230 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003231 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003232 free_irq(priv->pdev->irq, hw);
3233
3234 /* Stop finalize join worker */
3235 cancel_work_sync(&priv->finalize_join_worker);
3236 if (priv->beacon_skb != NULL)
3237 dev_kfree_skb(priv->beacon_skb);
3238
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003239 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003240 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003241 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003242
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003243 /* Return all skbs to mac80211 */
3244 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01003245 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003246}
3247
3248static int mwl8k_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003249 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003250{
3251 struct mwl8k_priv *priv = hw->priv;
3252 struct mwl8k_vif *mwl8k_vif;
3253
3254 /*
3255 * We only support one active interface at a time.
3256 */
3257 if (priv->vif != NULL)
3258 return -EBUSY;
3259
3260 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003261 * Reject interface creation if sniffer mode is active, as
3262 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003263 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003264 */
3265 if (priv->sniffer_enabled) {
3266 printk(KERN_INFO "%s: unable to create STA "
3267 "interface due to sniffer mode being enabled\n",
3268 wiphy_name(hw->wiphy));
3269 return -EINVAL;
3270 }
3271
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003272 /* Set the mac address. */
3273 mwl8k_cmd_set_mac_addr(hw, vif->addr);
3274
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003275 if (priv->ap_fw)
3276 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3277
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003278 /* Clean out driver private area */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003279 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003280 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
3281
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003282 /* Set Initial sequence number to zero */
3283 mwl8k_vif->seqno = 0;
3284
Johannes Berg1ed32e42009-12-23 13:15:45 +01003285 priv->vif = vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003286
3287 return 0;
3288}
3289
3290static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003291 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003292{
3293 struct mwl8k_priv *priv = hw->priv;
3294
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003295 if (priv->ap_fw)
3296 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3297
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003298 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003299
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003300 priv->vif = NULL;
3301}
3302
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003303static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003304{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003305 struct ieee80211_conf *conf = &hw->conf;
3306 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003307 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003308
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003309 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003310 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003311 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003312 }
3313
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003314 rc = mwl8k_fw_lock(hw);
3315 if (rc)
3316 return rc;
3317
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003318 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003319 if (rc)
3320 goto out;
3321
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003322 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003323 if (rc)
3324 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003325
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003326 if (conf->power_level > 18)
3327 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003328 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003329 if (rc)
3330 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003331
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003332 if (priv->ap_fw) {
3333 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3334 if (!rc)
3335 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3336 } else {
3337 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3338 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003339
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003340out:
3341 mwl8k_fw_unlock(hw);
3342
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003343 return rc;
3344}
3345
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003346static void
3347mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3348 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003349{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003350 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003351 u32 ap_legacy_rates;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003352 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003353 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003354
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003355 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003356 return;
3357
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003358 /*
3359 * No need to capture a beacon if we're no longer associated.
3360 */
3361 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3362 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003363
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003364 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003365 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003366 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003367 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003368 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003369
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003370 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003371
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003372 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003373 if (ap == NULL) {
3374 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003375 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003376 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003377
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003378 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
3379 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3380 } else {
3381 ap_legacy_rates =
3382 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3383 }
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003384 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003385
3386 rcu_read_unlock();
3387 }
3388
3389 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003390 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003391 if (rc)
3392 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003393
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003394 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003395 if (rc)
3396 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003397 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003398
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003399 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003400 rc = mwl8k_set_radio_preamble(hw,
3401 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003402 if (rc)
3403 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003404 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003405
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003406 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003407 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003408 if (rc)
3409 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003410 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003411
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003412 if (vif->bss_conf.assoc &&
3413 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3414 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003415 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003416 if (rc)
3417 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003418 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003419
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003420 if (vif->bss_conf.assoc &&
3421 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003422 /*
3423 * Finalize the join. Tell rx handler to process
3424 * next beacon from our BSSID.
3425 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003426 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003427 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003428 }
3429
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003430out:
3431 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003432}
3433
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003434static void
3435mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3436 struct ieee80211_bss_conf *info, u32 changed)
3437{
3438 int rc;
3439
3440 if (mwl8k_fw_lock(hw))
3441 return;
3442
3443 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3444 rc = mwl8k_set_radio_preamble(hw,
3445 vif->bss_conf.use_short_preamble);
3446 if (rc)
3447 goto out;
3448 }
3449
3450 if (changed & BSS_CHANGED_BASIC_RATES) {
3451 int idx;
3452 int rate;
3453
3454 /*
3455 * Use lowest supported basic rate for multicasts
3456 * and management frames (such as probe responses --
3457 * beacons will always go out at 1 Mb/s).
3458 */
3459 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003460 if (idx)
3461 idx--;
3462
3463 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3464 rate = mwl8k_rates_24[idx].hw_value;
3465 else
3466 rate = mwl8k_rates_50[idx].hw_value;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003467
3468 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3469 }
3470
3471 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3472 struct sk_buff *skb;
3473
3474 skb = ieee80211_beacon_get(hw, vif);
3475 if (skb != NULL) {
3476 mwl8k_cmd_set_beacon(hw, skb->data, skb->len);
3477 kfree_skb(skb);
3478 }
3479 }
3480
3481 if (changed & BSS_CHANGED_BEACON_ENABLED)
3482 mwl8k_cmd_bss_start(hw, info->enable_beacon);
3483
3484out:
3485 mwl8k_fw_unlock(hw);
3486}
3487
3488static void
3489mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3490 struct ieee80211_bss_conf *info, u32 changed)
3491{
3492 struct mwl8k_priv *priv = hw->priv;
3493
3494 if (!priv->ap_fw)
3495 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3496 else
3497 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3498}
3499
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003500static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3501 int mc_count, struct dev_addr_list *mclist)
3502{
3503 struct mwl8k_cmd_pkt *cmd;
3504
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003505 /*
3506 * Synthesize and return a command packet that programs the
3507 * hardware multicast address filter. At this point we don't
3508 * know whether FIF_ALLMULTI is being requested, but if it is,
3509 * we'll end up throwing this packet away and creating a new
3510 * one in mwl8k_configure_filter().
3511 */
3512 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003513
3514 return (unsigned long)cmd;
3515}
3516
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003517static int
3518mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3519 unsigned int changed_flags,
3520 unsigned int *total_flags)
3521{
3522 struct mwl8k_priv *priv = hw->priv;
3523
3524 /*
3525 * Hardware sniffer mode is mutually exclusive with STA
3526 * operation, so refuse to enable sniffer mode if a STA
3527 * interface is active.
3528 */
3529 if (priv->vif != NULL) {
3530 if (net_ratelimit())
3531 printk(KERN_INFO "%s: not enabling sniffer "
3532 "mode because STA interface is active\n",
3533 wiphy_name(hw->wiphy));
3534 return 0;
3535 }
3536
3537 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003538 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003539 return 0;
3540 priv->sniffer_enabled = true;
3541 }
3542
3543 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3544 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3545 FIF_OTHER_BSS;
3546
3547 return 1;
3548}
3549
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003550static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3551 unsigned int changed_flags,
3552 unsigned int *total_flags,
3553 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003554{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003555 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003556 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3557
3558 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003559 * AP firmware doesn't allow fine-grained control over
3560 * the receive filter.
3561 */
3562 if (priv->ap_fw) {
3563 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3564 kfree(cmd);
3565 return;
3566 }
3567
3568 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003569 * Enable hardware sniffer mode if FIF_CONTROL or
3570 * FIF_OTHER_BSS is requested.
3571 */
3572 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3573 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3574 kfree(cmd);
3575 return;
3576 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003577
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003578 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003579 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003580
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003581 if (mwl8k_fw_lock(hw)) {
3582 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003583 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003584 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003585
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003586 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003587 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003588 priv->sniffer_enabled = false;
3589 }
3590
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003591 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003592 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3593 /*
3594 * Disable the BSS filter.
3595 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003596 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003597 } else {
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003598 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003599
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003600 /*
3601 * Enable the BSS filter.
3602 *
3603 * If there is an active STA interface, use that
3604 * interface's BSSID, otherwise use a dummy one
3605 * (where the OUI part needs to be nonzero for
3606 * the BSSID to be accepted by POST_SCAN).
3607 */
3608 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003609 if (priv->vif != NULL)
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003610 bssid = priv->vif->bss_conf.bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003611
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003612 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003613 }
3614 }
3615
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003616 /*
3617 * If FIF_ALLMULTI is being requested, throw away the command
3618 * packet that ->prepare_multicast() built and replace it with
3619 * a command packet that enables reception of all multicast
3620 * packets.
3621 */
3622 if (*total_flags & FIF_ALLMULTI) {
3623 kfree(cmd);
3624 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3625 }
3626
3627 if (cmd != NULL) {
3628 mwl8k_post_cmd(hw, cmd);
3629 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003630 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003631
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003632 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003633}
3634
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003635static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3636{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003637 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003638}
3639
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003640struct mwl8k_sta_notify_item
3641{
3642 struct list_head list;
3643 struct ieee80211_vif *vif;
3644 enum sta_notify_cmd cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003645 struct ieee80211_sta sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003646};
3647
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003648static void
3649mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3650{
3651 struct mwl8k_priv *priv = hw->priv;
3652
3653 /*
3654 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3655 */
3656 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3657 int rc;
3658
3659 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3660 if (rc >= 0) {
3661 struct ieee80211_sta *sta;
3662
3663 rcu_read_lock();
3664 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3665 if (sta != NULL)
3666 MWL8K_STA(sta)->peer_id = rc;
3667 rcu_read_unlock();
3668 }
3669 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3670 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3671 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3672 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3673 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3674 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3675 }
3676}
3677
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003678static void mwl8k_sta_notify_worker(struct work_struct *work)
3679{
3680 struct mwl8k_priv *priv =
3681 container_of(work, struct mwl8k_priv, sta_notify_worker);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003682 struct ieee80211_hw *hw = priv->hw;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003683
3684 spin_lock_bh(&priv->sta_notify_list_lock);
3685 while (!list_empty(&priv->sta_notify_list)) {
3686 struct mwl8k_sta_notify_item *s;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003687
3688 s = list_entry(priv->sta_notify_list.next,
3689 struct mwl8k_sta_notify_item, list);
3690 list_del(&s->list);
3691
3692 spin_unlock_bh(&priv->sta_notify_list_lock);
3693
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003694 mwl8k_do_sta_notify(hw, s);
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003695 kfree(s);
3696
3697 spin_lock_bh(&priv->sta_notify_list_lock);
3698 }
3699 spin_unlock_bh(&priv->sta_notify_list_lock);
3700}
3701
3702static void
3703mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3704 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3705{
3706 struct mwl8k_priv *priv = hw->priv;
3707 struct mwl8k_sta_notify_item *s;
3708
3709 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3710 return;
3711
3712 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3713 if (s != NULL) {
3714 s->vif = vif;
3715 s->cmd = cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003716 s->sta = *sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003717
3718 spin_lock(&priv->sta_notify_list_lock);
3719 list_add_tail(&s->list, &priv->sta_notify_list);
3720 spin_unlock(&priv->sta_notify_list_lock);
3721
3722 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3723 }
3724}
3725
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003726static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3727 const struct ieee80211_tx_queue_params *params)
3728{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003729 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003730 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003731
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003732 rc = mwl8k_fw_lock(hw);
3733 if (!rc) {
3734 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003735 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003736
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003737 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003738 rc = mwl8k_cmd_set_edca_params(hw, queue,
3739 params->cw_min,
3740 params->cw_max,
3741 params->aifs,
3742 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003743
3744 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003745 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003746
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003747 return rc;
3748}
3749
3750static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3751 struct ieee80211_tx_queue_stats *stats)
3752{
3753 struct mwl8k_priv *priv = hw->priv;
3754 struct mwl8k_tx_queue *txq;
3755 int index;
3756
3757 spin_lock_bh(&priv->tx_lock);
3758 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3759 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003760 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003761 sizeof(struct ieee80211_tx_queue_stats));
3762 }
3763 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003764
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003765 return 0;
3766}
3767
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003768static int mwl8k_get_stats(struct ieee80211_hw *hw,
3769 struct ieee80211_low_level_stats *stats)
3770{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003771 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003772}
3773
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003774static int
3775mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3776 enum ieee80211_ampdu_mlme_action action,
3777 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3778{
3779 switch (action) {
3780 case IEEE80211_AMPDU_RX_START:
3781 case IEEE80211_AMPDU_RX_STOP:
3782 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3783 return -ENOTSUPP;
3784 return 0;
3785 default:
3786 return -ENOTSUPP;
3787 }
3788}
3789
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003790static const struct ieee80211_ops mwl8k_ops = {
3791 .tx = mwl8k_tx,
3792 .start = mwl8k_start,
3793 .stop = mwl8k_stop,
3794 .add_interface = mwl8k_add_interface,
3795 .remove_interface = mwl8k_remove_interface,
3796 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003797 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003798 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003799 .configure_filter = mwl8k_configure_filter,
3800 .set_rts_threshold = mwl8k_set_rts_threshold,
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003801 .sta_notify = mwl8k_sta_notify,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003802 .conf_tx = mwl8k_conf_tx,
3803 .get_tx_stats = mwl8k_get_tx_stats,
3804 .get_stats = mwl8k_get_stats,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003805 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003806};
3807
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003808static void mwl8k_finalize_join_worker(struct work_struct *work)
3809{
3810 struct mwl8k_priv *priv =
3811 container_of(work, struct mwl8k_priv, finalize_join_worker);
3812 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003813
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003814 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len,
3815 priv->vif->bss_conf.dtim_period);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003816 dev_kfree_skb(skb);
3817
3818 priv->beacon_skb = NULL;
3819}
3820
John W. Linvillebcb628d2009-11-06 16:40:16 -05003821enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003822 MWL8363 = 0,
3823 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003824 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003825};
3826
John W. Linvillebcb628d2009-11-06 16:40:16 -05003827static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003828 [MWL8363] = {
3829 .part_name = "88w8363",
3830 .helper_image = "mwl8k/helper_8363.fw",
3831 .fw_image = "mwl8k/fmimage_8363.fw",
3832 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003833 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003834 .part_name = "88w8687",
3835 .helper_image = "mwl8k/helper_8687.fw",
3836 .fw_image = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05003837 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003838 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003839 .part_name = "88w8366",
3840 .helper_image = "mwl8k/helper_8366.fw",
3841 .fw_image = "mwl8k/fmimage_8366.fw",
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003842 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003843 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003844};
3845
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01003846MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3847MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3848MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3849MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3850MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3851MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3852
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003853static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003854 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3855 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003856 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3857 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3858 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01003859 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003860 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003861};
3862MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3863
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003864static int __devinit mwl8k_probe(struct pci_dev *pdev,
3865 const struct pci_device_id *id)
3866{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003867 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003868 struct ieee80211_hw *hw;
3869 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003870 int rc;
3871 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003872
3873 if (!printed_version) {
3874 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3875 printed_version = 1;
3876 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003877
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003878
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003879 rc = pci_enable_device(pdev);
3880 if (rc) {
3881 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3882 MWL8K_NAME);
3883 return rc;
3884 }
3885
3886 rc = pci_request_regions(pdev, MWL8K_NAME);
3887 if (rc) {
3888 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3889 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003890 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003891 }
3892
3893 pci_set_master(pdev);
3894
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003895
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003896 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3897 if (hw == NULL) {
3898 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3899 rc = -ENOMEM;
3900 goto err_free_reg;
3901 }
3902
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003903 SET_IEEE80211_DEV(hw, &pdev->dev);
3904 pci_set_drvdata(pdev, hw);
3905
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003906 priv = hw->priv;
3907 priv->hw = hw;
3908 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003909 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003910
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003911
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003912 priv->sram = pci_iomap(pdev, 0, 0x10000);
3913 if (priv->sram == NULL) {
3914 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003915 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003916 goto err_iounmap;
3917 }
3918
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003919 /*
3920 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3921 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3922 */
3923 priv->regs = pci_iomap(pdev, 1, 0x10000);
3924 if (priv->regs == NULL) {
3925 priv->regs = pci_iomap(pdev, 2, 0x10000);
3926 if (priv->regs == NULL) {
3927 printk(KERN_ERR "%s: Cannot map device registers\n",
3928 wiphy_name(hw->wiphy));
3929 goto err_iounmap;
3930 }
3931 }
3932
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003933
3934 /* Reset firmware and hardware */
3935 mwl8k_hw_reset(priv);
3936
3937 /* Ask userland hotplug daemon for the device firmware */
3938 rc = mwl8k_request_firmware(priv);
3939 if (rc) {
3940 printk(KERN_ERR "%s: Firmware files not found\n",
3941 wiphy_name(hw->wiphy));
3942 goto err_stop_firmware;
3943 }
3944
3945 /* Load firmware into hardware */
3946 rc = mwl8k_load_firmware(hw);
3947 if (rc) {
3948 printk(KERN_ERR "%s: Cannot start firmware\n",
3949 wiphy_name(hw->wiphy));
3950 goto err_stop_firmware;
3951 }
3952
3953 /* Reclaim memory once firmware is successfully loaded */
3954 mwl8k_release_firmware(priv);
3955
3956
Lennert Buytenhek91942232010-01-04 21:53:54 +01003957 if (priv->ap_fw) {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003958 priv->rxd_ops = priv->device_info->ap_rxd_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003959 if (priv->rxd_ops == NULL) {
3960 printk(KERN_ERR "%s: Driver does not have AP "
3961 "firmware image support for this hardware\n",
3962 wiphy_name(hw->wiphy));
3963 goto err_stop_firmware;
3964 }
3965 } else {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003966 priv->rxd_ops = &rxd_sta_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003967 }
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003968
3969 priv->sniffer_enabled = false;
3970 priv->wmm_enabled = false;
3971 priv->pending_tx_pkts = 0;
3972
3973
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003974 /*
3975 * Extra headroom is the size of the required DMA header
3976 * minus the size of the smallest 802.11 frame (CTS frame).
3977 */
3978 hw->extra_tx_headroom =
3979 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3980
3981 hw->channel_change_time = 10;
3982
3983 hw->queues = MWL8K_TX_QUEUES;
3984
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003985 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003986 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003987 hw->vif_data_size = sizeof(struct mwl8k_vif);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003988 hw->sta_data_size = sizeof(struct mwl8k_sta);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003989 priv->vif = NULL;
3990
3991 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003992 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003993 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003994
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003995 /* Station database handling */
3996 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
3997 spin_lock_init(&priv->sta_notify_list_lock);
3998 INIT_LIST_HEAD(&priv->sta_notify_list);
3999
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004000 /* Finalize join worker */
4001 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
4002
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004003 /* TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004004 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
4005 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004006 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
4007 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004009 /* Power management cookie */
4010 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
4011 if (priv->cookie == NULL)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004012 goto err_stop_firmware;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004013
4014 rc = mwl8k_rxq_init(hw, 0);
4015 if (rc)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004016 goto err_free_cookie;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004017 rxq_refill(hw, 0, INT_MAX);
4018
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004019 mutex_init(&priv->fw_mutex);
4020 priv->fw_mutex_owner = NULL;
4021 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004022 priv->hostcmd_wait = NULL;
4023
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004024 spin_lock_init(&priv->tx_lock);
4025
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02004026 priv->tx_wait = NULL;
4027
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004028 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
4029 rc = mwl8k_txq_init(hw, i);
4030 if (rc)
4031 goto err_free_queues;
4032 }
4033
4034 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004035 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004036 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004037 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004038 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4039
Joe Perchesa0607fd2009-11-18 23:29:17 -08004040 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004041 IRQF_SHARED, MWL8K_NAME, hw);
4042 if (rc) {
4043 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004044 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004045 goto err_free_queues;
4046 }
4047
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004048 /*
4049 * Temporarily enable interrupts. Initial firmware host
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01004050 * commands use interrupts and avoid polling. Disable
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004051 * interrupts when done.
4052 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004053 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004054
4055 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004056 if (priv->ap_fw) {
4057 rc = mwl8k_cmd_get_hw_spec_ap(hw);
4058 if (!rc)
4059 rc = mwl8k_cmd_set_hw_spec(hw);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004060
4061 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_AP);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004062 } else {
4063 rc = mwl8k_cmd_get_hw_spec_sta(hw);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01004064
4065 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004066 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004067 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004068 printk(KERN_ERR "%s: Cannot initialise firmware\n",
4069 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004070 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004071 }
4072
4073 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004074 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004075 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004076 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004077 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004078 }
4079
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004080 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004081 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004082 if (rc) {
4083 printk(KERN_ERR "%s: Cannot clear MAC address\n",
4084 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004085 goto err_free_irq;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004086 }
4087
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004088 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004089 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004090 free_irq(priv->pdev->irq, hw);
4091
4092 rc = ieee80211_register_hw(hw);
4093 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004094 printk(KERN_ERR "%s: Cannot register device\n",
4095 wiphy_name(hw->wiphy));
Lennert Buytenhek153458f2010-01-04 21:54:08 +01004096 goto err_free_queues;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004097 }
4098
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02004099 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02004100 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004101 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02004102 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02004103 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4104 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004105
4106 return 0;
4107
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004108err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004109 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004110 free_irq(priv->pdev->irq, hw);
4111
4112err_free_queues:
4113 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4114 mwl8k_txq_deinit(hw, i);
4115 mwl8k_rxq_deinit(hw, 0);
4116
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004117err_free_cookie:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004118 if (priv->cookie != NULL)
4119 pci_free_consistent(priv->pdev, 4,
4120 priv->cookie, priv->cookie_dma);
4121
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004122err_stop_firmware:
4123 mwl8k_hw_reset(priv);
4124 mwl8k_release_firmware(priv);
4125
4126err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004127 if (priv->regs != NULL)
4128 pci_iounmap(pdev, priv->regs);
4129
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004130 if (priv->sram != NULL)
4131 pci_iounmap(pdev, priv->sram);
4132
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004133 pci_set_drvdata(pdev, NULL);
4134 ieee80211_free_hw(hw);
4135
4136err_free_reg:
4137 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004138
4139err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004140 pci_disable_device(pdev);
4141
4142 return rc;
4143}
4144
Joerg Albert230f7af2009-04-18 02:10:45 +02004145static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004146{
4147 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4148}
4149
Joerg Albert230f7af2009-04-18 02:10:45 +02004150static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004151{
4152 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4153 struct mwl8k_priv *priv;
4154 int i;
4155
4156 if (hw == NULL)
4157 return;
4158 priv = hw->priv;
4159
4160 ieee80211_stop_queues(hw);
4161
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02004162 ieee80211_unregister_hw(hw);
4163
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004164 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004165 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004166 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004167
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004168 /* Stop hardware */
4169 mwl8k_hw_reset(priv);
4170
4171 /* Return all skbs to mac80211 */
4172 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004173 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004174
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004175 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4176 mwl8k_txq_deinit(hw, i);
4177
4178 mwl8k_rxq_deinit(hw, 0);
4179
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004180 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004181
4182 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004183 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004184 pci_set_drvdata(pdev, NULL);
4185 ieee80211_free_hw(hw);
4186 pci_release_regions(pdev);
4187 pci_disable_device(pdev);
4188}
4189
4190static struct pci_driver mwl8k_driver = {
4191 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004192 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004193 .probe = mwl8k_probe,
4194 .remove = __devexit_p(mwl8k_remove),
4195 .shutdown = __devexit_p(mwl8k_shutdown),
4196};
4197
4198static int __init mwl8k_init(void)
4199{
4200 return pci_register_driver(&mwl8k_driver);
4201}
4202
4203static void __exit mwl8k_exit(void)
4204{
4205 pci_unregister_driver(&mwl8k_driver);
4206}
4207
4208module_init(mwl8k_init);
4209module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004210
4211MODULE_DESCRIPTION(MWL8K_DESC);
4212MODULE_VERSION(MWL8K_VERSION);
4213MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4214MODULE_LICENSE("GPL");