blob: ee7d8a6329f8668d6f5248a9b5a2363494f63fc4 [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 Buytenhekf5bb87c2010-01-12 13:49:51 +0100163 /* List of interfaces. */
164 struct list_head vif_list;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100165
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100166 /* power management status cookie from firmware */
167 u32 *cookie;
168 dma_addr_t cookie_dma;
169
170 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100171 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200172 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100173
174 /*
175 * Running count of TX packets in flight, to avoid
176 * iterating over the transmit rings each time.
177 */
178 int pending_tx_pkts;
179
180 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
181 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
182
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200183 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200184 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200185 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200186 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100187
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +0100188 struct work_struct sta_notify_worker;
189 spinlock_t sta_notify_list_lock;
190 struct list_head sta_notify_list;
191
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100192 /* XXX need to convert this to handle multiple interfaces */
193 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200194 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100195 struct sk_buff *beacon_skb;
196
197 /*
198 * This FJ worker has to be global as it is scheduled from the
199 * RX handler. At this point we don't know which interface it
200 * belongs to until the list of bssids waiting to complete join
201 * is checked.
202 */
203 struct work_struct finalize_join_worker;
204
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100205 /* Tasklet to perform TX reclaim. */
206 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100207
208 /* Tasklet to perform RX. */
209 struct tasklet_struct poll_rx_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100210};
211
212/* Per interface specific private data */
213struct mwl8k_vif {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100214 struct list_head list;
215 struct ieee80211_vif *vif;
216
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100217 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100218 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100219};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200220#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100221
Lennert Buytenheka6804002010-01-04 21:55:42 +0100222struct mwl8k_sta {
223 /* Index into station database. Returned by UPDATE_STADB. */
224 u8 peer_id;
225};
226#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
227
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100228static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100229 { .center_freq = 2412, .hw_value = 1, },
230 { .center_freq = 2417, .hw_value = 2, },
231 { .center_freq = 2422, .hw_value = 3, },
232 { .center_freq = 2427, .hw_value = 4, },
233 { .center_freq = 2432, .hw_value = 5, },
234 { .center_freq = 2437, .hw_value = 6, },
235 { .center_freq = 2442, .hw_value = 7, },
236 { .center_freq = 2447, .hw_value = 8, },
237 { .center_freq = 2452, .hw_value = 9, },
238 { .center_freq = 2457, .hw_value = 10, },
239 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100240 { .center_freq = 2467, .hw_value = 12, },
241 { .center_freq = 2472, .hw_value = 13, },
242 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100243};
244
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100245static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100246 { .bitrate = 10, .hw_value = 2, },
247 { .bitrate = 20, .hw_value = 4, },
248 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200249 { .bitrate = 110, .hw_value = 22, },
250 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100251 { .bitrate = 60, .hw_value = 12, },
252 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100253 { .bitrate = 120, .hw_value = 24, },
254 { .bitrate = 180, .hw_value = 36, },
255 { .bitrate = 240, .hw_value = 48, },
256 { .bitrate = 360, .hw_value = 72, },
257 { .bitrate = 480, .hw_value = 96, },
258 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100259 { .bitrate = 720, .hw_value = 144, },
260};
261
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100262static const struct ieee80211_channel mwl8k_channels_50[] = {
263 { .center_freq = 5180, .hw_value = 36, },
264 { .center_freq = 5200, .hw_value = 40, },
265 { .center_freq = 5220, .hw_value = 44, },
266 { .center_freq = 5240, .hw_value = 48, },
267};
268
269static const struct ieee80211_rate mwl8k_rates_50[] = {
270 { .bitrate = 60, .hw_value = 12, },
271 { .bitrate = 90, .hw_value = 18, },
272 { .bitrate = 120, .hw_value = 24, },
273 { .bitrate = 180, .hw_value = 36, },
274 { .bitrate = 240, .hw_value = 48, },
275 { .bitrate = 360, .hw_value = 72, },
276 { .bitrate = 480, .hw_value = 96, },
277 { .bitrate = 540, .hw_value = 108, },
278 { .bitrate = 720, .hw_value = 144, },
279};
280
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100281/* Set or get info from Firmware */
282#define MWL8K_CMD_SET 0x0001
283#define MWL8K_CMD_GET 0x0000
284
285/* Firmware command codes */
286#define MWL8K_CMD_CODE_DNLD 0x0001
287#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200288#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100289#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
290#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200291#define MWL8K_CMD_RADIO_CONTROL 0x001c
292#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200293#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100294#define MWL8K_CMD_SET_BEACON 0x0100
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100295#define MWL8K_CMD_SET_PRE_SCAN 0x0107
296#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200297#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100298#define MWL8K_CMD_SET_AID 0x010d
299#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200300#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100301#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200302#define MWL8K_CMD_SET_SLOT 0x0114
303#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
304#define MWL8K_CMD_SET_WMM_MODE 0x0123
305#define MWL8K_CMD_MIMO_CONFIG 0x0125
306#define MWL8K_CMD_USE_FIXED_RATE 0x0126
307#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200308#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200309#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100310#define MWL8K_CMD_BSS_START 0x1100
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100311#define MWL8K_CMD_SET_NEW_STN 0x1111
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200312#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100313
314static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
315{
316#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
317 snprintf(buf, bufsize, "%s", #x);\
318 return buf;\
319 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200320 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100321 MWL8K_CMDNAME(CODE_DNLD);
322 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200323 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100324 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
325 MWL8K_CMDNAME(GET_STAT);
326 MWL8K_CMDNAME(RADIO_CONTROL);
327 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200328 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100329 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100330 MWL8K_CMDNAME(SET_PRE_SCAN);
331 MWL8K_CMDNAME(SET_POST_SCAN);
332 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100333 MWL8K_CMDNAME(SET_AID);
334 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200335 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100336 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200337 MWL8K_CMDNAME(SET_SLOT);
338 MWL8K_CMDNAME(SET_EDCA_PARAMS);
339 MWL8K_CMDNAME(SET_WMM_MODE);
340 MWL8K_CMDNAME(MIMO_CONFIG);
341 MWL8K_CMDNAME(USE_FIXED_RATE);
342 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200343 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200344 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100345 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100346 MWL8K_CMDNAME(SET_NEW_STN);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200347 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100348 default:
349 snprintf(buf, bufsize, "0x%x", cmd);
350 }
351#undef MWL8K_CMDNAME
352
353 return buf;
354}
355
356/* Hardware and firmware reset */
357static void mwl8k_hw_reset(struct mwl8k_priv *priv)
358{
359 iowrite32(MWL8K_H2A_INT_RESET,
360 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
361 iowrite32(MWL8K_H2A_INT_RESET,
362 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
363 msleep(20);
364}
365
366/* Release fw image */
367static void mwl8k_release_fw(struct firmware **fw)
368{
369 if (*fw == NULL)
370 return;
371 release_firmware(*fw);
372 *fw = NULL;
373}
374
375static void mwl8k_release_firmware(struct mwl8k_priv *priv)
376{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100377 mwl8k_release_fw(&priv->fw_ucode);
378 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100379}
380
381/* Request fw image */
382static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200383 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100384{
385 /* release current image */
386 if (*fw != NULL)
387 mwl8k_release_fw(fw);
388
389 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200390 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100391}
392
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200393static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100394{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200395 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100396 int rc;
397
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200398 if (di->helper_image != NULL) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100399 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200400 if (rc) {
401 printk(KERN_ERR "%s: Error requesting helper "
402 "firmware file %s\n", pci_name(priv->pdev),
403 di->helper_image);
404 return rc;
405 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100406 }
407
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100408 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100409 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200410 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200411 pci_name(priv->pdev), di->fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100412 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100413 return rc;
414 }
415
416 return 0;
417}
418
419struct mwl8k_cmd_pkt {
420 __le16 code;
421 __le16 length;
422 __le16 seq_num;
423 __le16 result;
424 char payload[0];
425} __attribute__((packed));
426
427/*
428 * Firmware loading.
429 */
430static int
431mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
432{
433 void __iomem *regs = priv->regs;
434 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100435 int loops;
436
437 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
438 if (pci_dma_mapping_error(priv->pdev, dma_addr))
439 return -ENOMEM;
440
441 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
442 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
443 iowrite32(MWL8K_H2A_INT_DOORBELL,
444 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
445 iowrite32(MWL8K_H2A_INT_DUMMY,
446 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
447
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100448 loops = 1000;
449 do {
450 u32 int_code;
451
452 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
453 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
454 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100455 break;
456 }
457
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200458 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100459 udelay(1);
460 } while (--loops);
461
462 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
463
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200464 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100465}
466
467static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
468 const u8 *data, size_t length)
469{
470 struct mwl8k_cmd_pkt *cmd;
471 int done;
472 int rc = 0;
473
474 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
475 if (cmd == NULL)
476 return -ENOMEM;
477
478 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
479 cmd->seq_num = 0;
480 cmd->result = 0;
481
482 done = 0;
483 while (length) {
484 int block_size = length > 256 ? 256 : length;
485
486 memcpy(cmd->payload, data + done, block_size);
487 cmd->length = cpu_to_le16(block_size);
488
489 rc = mwl8k_send_fw_load_cmd(priv, cmd,
490 sizeof(*cmd) + block_size);
491 if (rc)
492 break;
493
494 done += block_size;
495 length -= block_size;
496 }
497
498 if (!rc) {
499 cmd->length = 0;
500 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
501 }
502
503 kfree(cmd);
504
505 return rc;
506}
507
508static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
509 const u8 *data, size_t length)
510{
511 unsigned char *buffer;
512 int may_continue, rc = 0;
513 u32 done, prev_block_size;
514
515 buffer = kmalloc(1024, GFP_KERNEL);
516 if (buffer == NULL)
517 return -ENOMEM;
518
519 done = 0;
520 prev_block_size = 0;
521 may_continue = 1000;
522 while (may_continue > 0) {
523 u32 block_size;
524
525 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
526 if (block_size & 1) {
527 block_size &= ~1;
528 may_continue--;
529 } else {
530 done += prev_block_size;
531 length -= prev_block_size;
532 }
533
534 if (block_size > 1024 || block_size > length) {
535 rc = -EOVERFLOW;
536 break;
537 }
538
539 if (length == 0) {
540 rc = 0;
541 break;
542 }
543
544 if (block_size == 0) {
545 rc = -EPROTO;
546 may_continue--;
547 udelay(1);
548 continue;
549 }
550
551 prev_block_size = block_size;
552 memcpy(buffer, data + done, block_size);
553
554 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
555 if (rc)
556 break;
557 }
558
559 if (!rc && length != 0)
560 rc = -EREMOTEIO;
561
562 kfree(buffer);
563
564 return rc;
565}
566
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200567static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100568{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200569 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100570 struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200571 int rc;
572 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100573
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200574 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100575 struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100576
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200577 if (helper == NULL) {
578 printk(KERN_ERR "%s: helper image needed but none "
579 "given\n", pci_name(priv->pdev));
580 return -EINVAL;
581 }
582
583 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100584 if (rc) {
585 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200586 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100587 return rc;
588 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100589 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100590
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200591 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100592 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200593 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100594 }
595
596 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200597 printk(KERN_ERR "%s: unable to load firmware image\n",
598 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100599 return rc;
600 }
601
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100602 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100603
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100604 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100605 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200606 u32 ready_code;
607
608 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
609 if (ready_code == MWL8K_FWAP_READY) {
610 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100611 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200612 } else if (ready_code == MWL8K_FWSTA_READY) {
613 priv->ap_fw = 0;
614 break;
615 }
616
617 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100618 udelay(1);
619 } while (--loops);
620
621 return loops ? 0 : -ETIMEDOUT;
622}
623
624
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100625/* DMA header used by firmware and hardware. */
626struct mwl8k_dma_data {
627 __le16 fwlen;
628 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100629 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100630} __attribute__((packed));
631
632/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100633static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100634{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100635 struct mwl8k_dma_data *tr;
636 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100637
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100638 tr = (struct mwl8k_dma_data *)skb->data;
639 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
640
641 if (hdrlen != sizeof(tr->wh)) {
642 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
643 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
644 *((__le16 *)(tr->data - 2)) = qos;
645 } else {
646 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
647 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100648 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100649
650 if (hdrlen != sizeof(*tr))
651 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100652}
653
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200654static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100655{
656 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100657 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100658 struct mwl8k_dma_data *tr;
659
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100660 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100661 * Add a firmware DMA header; the firmware requires that we
662 * present a 2-byte payload length followed by a 4-address
663 * header (without QoS field), followed (optionally) by any
664 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100665 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100666 wh = (struct ieee80211_hdr *)skb->data;
667
668 hdrlen = ieee80211_hdrlen(wh->frame_control);
669 if (hdrlen != sizeof(*tr))
670 skb_push(skb, sizeof(*tr) - hdrlen);
671
672 if (ieee80211_is_data_qos(wh->frame_control))
673 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100674
675 tr = (struct mwl8k_dma_data *)skb->data;
676 if (wh != &tr->wh)
677 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100678 if (hdrlen != sizeof(tr->wh))
679 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100680
681 /*
682 * Firmware length is the length of the fully formed "802.11
683 * payload". That is, everything except for the 802.11 header.
684 * This includes all crypto material including the MIC.
685 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100686 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100687}
688
689
690/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100691 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200692 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100693struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200694 __le16 pkt_len;
695 __u8 sq2;
696 __u8 rate;
697 __le32 pkt_phys_addr;
698 __le32 next_rxd_phys_addr;
699 __le16 qos_control;
700 __le16 htsig2;
701 __le32 hw_rssi_info;
702 __le32 hw_noise_floor_info;
703 __u8 noise_floor;
704 __u8 pad0[3];
705 __u8 rssi;
706 __u8 rx_status;
707 __u8 channel;
708 __u8 rx_ctrl;
709} __attribute__((packed));
710
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100711#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
712#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
713#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100714
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100715#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200716
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100717static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200718{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100719 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200720
721 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100722 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200723}
724
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100725static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200726{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100727 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200728
729 rxd->pkt_len = cpu_to_le16(len);
730 rxd->pkt_phys_addr = cpu_to_le32(addr);
731 wmb();
732 rxd->rx_ctrl = 0;
733}
734
735static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100736mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
737 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200738{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100739 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200740
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100741 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200742 return -1;
743 rmb();
744
745 memset(status, 0, sizeof(*status));
746
747 status->signal = -rxd->rssi;
748 status->noise = -rxd->noise_floor;
749
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100750 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200751 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100752 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100753 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100754 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200755 } else {
756 int i;
757
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100758 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
759 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200760 status->rate_idx = i;
761 break;
762 }
763 }
764 }
765
Lennert Buytenhek85478342010-01-12 13:48:56 +0100766 if (rxd->channel > 14) {
767 status->band = IEEE80211_BAND_5GHZ;
768 if (!(status->flag & RX_FLAG_HT))
769 status->rate_idx -= 5;
770 } else {
771 status->band = IEEE80211_BAND_2GHZ;
772 }
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200773 status->freq = ieee80211_channel_to_frequency(rxd->channel);
774
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100775 *qos = rxd->qos_control;
776
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200777 return le16_to_cpu(rxd->pkt_len);
778}
779
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100780static struct rxd_ops rxd_8366_ap_ops = {
781 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
782 .rxd_init = mwl8k_rxd_8366_ap_init,
783 .rxd_refill = mwl8k_rxd_8366_ap_refill,
784 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200785};
786
787/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100788 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100789 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100790struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100791 __le16 pkt_len;
792 __u8 link_quality;
793 __u8 noise_level;
794 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200795 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100796 __le16 qos_control;
797 __le16 rate_info;
798 __le32 pad0[4];
799 __u8 rssi;
800 __u8 channel;
801 __le16 pad1;
802 __u8 rx_ctrl;
803 __u8 rx_status;
804 __u8 pad2[2];
805} __attribute__((packed));
806
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100807#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
808#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
809#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
810#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
811#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
812#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200813
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100814#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200815
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100816static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200817{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100818 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200819
820 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100821 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200822}
823
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100824static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200825{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100826 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200827
828 rxd->pkt_len = cpu_to_le16(len);
829 rxd->pkt_phys_addr = cpu_to_le32(addr);
830 wmb();
831 rxd->rx_ctrl = 0;
832}
833
834static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100835mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100836 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200837{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100838 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200839 u16 rate_info;
840
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100841 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200842 return -1;
843 rmb();
844
845 rate_info = le16_to_cpu(rxd->rate_info);
846
847 memset(status, 0, sizeof(*status));
848
849 status->signal = -rxd->rssi;
850 status->noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100851 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
852 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200853
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100854 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200855 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100856 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200857 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100858 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200859 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100860 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200861 status->flag |= RX_FLAG_HT;
862
Lennert Buytenhek85478342010-01-12 13:48:56 +0100863 if (rxd->channel > 14) {
864 status->band = IEEE80211_BAND_5GHZ;
865 if (!(status->flag & RX_FLAG_HT))
866 status->rate_idx -= 5;
867 } else {
868 status->band = IEEE80211_BAND_2GHZ;
869 }
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200870 status->freq = ieee80211_channel_to_frequency(rxd->channel);
871
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100872 *qos = rxd->qos_control;
873
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200874 return le16_to_cpu(rxd->pkt_len);
875}
876
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100877static struct rxd_ops rxd_sta_ops = {
878 .rxd_size = sizeof(struct mwl8k_rxd_sta),
879 .rxd_init = mwl8k_rxd_sta_init,
880 .rxd_refill = mwl8k_rxd_sta_refill,
881 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200882};
883
884
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100885#define MWL8K_RX_DESCS 256
886#define MWL8K_RX_MAXSZ 3800
887
888static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
889{
890 struct mwl8k_priv *priv = hw->priv;
891 struct mwl8k_rx_queue *rxq = priv->rxq + index;
892 int size;
893 int i;
894
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200895 rxq->rxd_count = 0;
896 rxq->head = 0;
897 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100898
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200899 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100900
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200901 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
902 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100903 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200904 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100905 return -ENOMEM;
906 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200907 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100908
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200909 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
910 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100911 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200912 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200913 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100914 return -ENOMEM;
915 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200916 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100917
918 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200919 int desc_size;
920 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100921 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200922 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100923
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200924 desc_size = priv->rxd_ops->rxd_size;
925 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100926
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200927 nexti = i + 1;
928 if (nexti == MWL8K_RX_DESCS)
929 nexti = 0;
930 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
931
932 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100933 }
934
935 return 0;
936}
937
938static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
939{
940 struct mwl8k_priv *priv = hw->priv;
941 struct mwl8k_rx_queue *rxq = priv->rxq + index;
942 int refilled;
943
944 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200945 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100946 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200947 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100948 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200949 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100950
951 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
952 if (skb == NULL)
953 break;
954
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200955 addr = pci_map_single(priv->pdev, skb->data,
956 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100957
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200958 rxq->rxd_count++;
959 rx = rxq->tail++;
960 if (rxq->tail == MWL8K_RX_DESCS)
961 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200962 rxq->buf[rx].skb = skb;
963 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200964
965 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
966 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100967
968 refilled++;
969 }
970
971 return refilled;
972}
973
974/* Must be called only when the card's reception is completely halted */
975static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
976{
977 struct mwl8k_priv *priv = hw->priv;
978 struct mwl8k_rx_queue *rxq = priv->rxq + index;
979 int i;
980
981 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200982 if (rxq->buf[i].skb != NULL) {
983 pci_unmap_single(priv->pdev,
984 pci_unmap_addr(&rxq->buf[i], dma),
985 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
986 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100987
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200988 kfree_skb(rxq->buf[i].skb);
989 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100990 }
991 }
992
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200993 kfree(rxq->buf);
994 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100995
996 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200997 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200998 rxq->rxd, rxq->rxd_dma);
999 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001000}
1001
1002
1003/*
1004 * Scan a list of BSSIDs to process for finalize join.
1005 * Allows for extension to process multiple BSSIDs.
1006 */
1007static inline int
1008mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1009{
1010 return priv->capture_beacon &&
1011 ieee80211_is_beacon(wh->frame_control) &&
1012 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1013}
1014
Lennert Buytenhek37797522009-10-22 20:19:45 +02001015static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1016 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001017{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001018 struct mwl8k_priv *priv = hw->priv;
1019
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001020 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001021 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001022
1023 /*
1024 * Use GFP_ATOMIC as rxq_process is called from
1025 * the primary interrupt handler, memory allocation call
1026 * must not sleep.
1027 */
1028 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1029 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001030 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001031}
1032
1033static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1034{
1035 struct mwl8k_priv *priv = hw->priv;
1036 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1037 int processed;
1038
1039 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001040 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001041 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001042 void *rxd;
1043 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001044 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001045 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001046
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001047 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001048 if (skb == NULL)
1049 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001050
1051 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1052
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001053 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001054 if (pkt_len < 0)
1055 break;
1056
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001057 rxq->buf[rxq->head].skb = NULL;
1058
1059 pci_unmap_single(priv->pdev,
1060 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1061 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1062 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001063
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001064 rxq->head++;
1065 if (rxq->head == MWL8K_RX_DESCS)
1066 rxq->head = 0;
1067
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001068 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001069
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001070 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001071 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001072
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001073 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001074 * Check for a pending join operation. Save a
1075 * copy of the beacon and schedule a tasklet to
1076 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001077 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001078 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001079 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001080
Johannes Bergf1d58c22009-06-17 13:13:00 +02001081 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1082 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001083
1084 processed++;
1085 }
1086
1087 return processed;
1088}
1089
1090
1091/*
1092 * Packet transmission.
1093 */
1094
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001095#define MWL8K_TXD_STATUS_OK 0x00000001
1096#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1097#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1098#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001099#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001100
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001101#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1102#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1103#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1104#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1105#define MWL8K_QOS_EOSP 0x0010
1106
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001107struct mwl8k_tx_desc {
1108 __le32 status;
1109 __u8 data_rate;
1110 __u8 tx_priority;
1111 __le16 qos_control;
1112 __le32 pkt_phys_addr;
1113 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001114 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001115 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001116 __le32 reserved;
1117 __le16 rate_info;
1118 __u8 peer_id;
1119 __u8 tx_frag_cnt;
1120} __attribute__((packed));
1121
1122#define MWL8K_TX_DESCS 128
1123
1124static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1125{
1126 struct mwl8k_priv *priv = hw->priv;
1127 struct mwl8k_tx_queue *txq = priv->txq + index;
1128 int size;
1129 int i;
1130
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001131 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1132 txq->stats.limit = MWL8K_TX_DESCS;
1133 txq->head = 0;
1134 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001135
1136 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1137
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001138 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1139 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001140 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001141 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001142 return -ENOMEM;
1143 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001144 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001145
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001146 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1147 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001148 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001149 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001150 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001151 return -ENOMEM;
1152 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001153 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001154
1155 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1156 struct mwl8k_tx_desc *tx_desc;
1157 int nexti;
1158
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001159 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001160 nexti = (i + 1) % MWL8K_TX_DESCS;
1161
1162 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001163 tx_desc->next_txd_phys_addr =
1164 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001165 }
1166
1167 return 0;
1168}
1169
1170static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1171{
1172 iowrite32(MWL8K_H2A_INT_PPA_READY,
1173 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1174 iowrite32(MWL8K_H2A_INT_DUMMY,
1175 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1176 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1177}
1178
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001179static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001180{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001181 struct mwl8k_priv *priv = hw->priv;
1182 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001183
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001184 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1185 struct mwl8k_tx_queue *txq = priv->txq + i;
1186 int fw_owned = 0;
1187 int drv_owned = 0;
1188 int unused = 0;
1189 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001190
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001191 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001192 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1193 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001194
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001195 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001196 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001197 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001198 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001199 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001200
1201 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001202 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001204
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001205 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1206 "fw_owned=%d drv_owned=%d unused=%d\n",
1207 wiphy_name(hw->wiphy), i,
1208 txq->stats.len, txq->head, txq->tail,
1209 fw_owned, drv_owned, unused);
1210 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001211}
1212
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001213/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001214 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001215 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001216#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001217
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001218static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001219{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001220 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001221 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001222 int retry;
1223 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001224
1225 might_sleep();
1226
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001227 /*
1228 * The TX queues are stopped at this point, so this test
1229 * doesn't need to take ->tx_lock.
1230 */
1231 if (!priv->pending_tx_pkts)
1232 return 0;
1233
1234 retry = 0;
1235 rc = 0;
1236
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001237 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001238 priv->tx_wait = &tx_wait;
1239 while (!rc) {
1240 int oldcount;
1241 unsigned long timeout;
1242
1243 oldcount = priv->pending_tx_pkts;
1244
1245 spin_unlock_bh(&priv->tx_lock);
1246 timeout = wait_for_completion_timeout(&tx_wait,
1247 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1248 spin_lock_bh(&priv->tx_lock);
1249
1250 if (timeout) {
1251 WARN_ON(priv->pending_tx_pkts);
1252 if (retry) {
1253 printk(KERN_NOTICE "%s: tx rings drained\n",
1254 wiphy_name(hw->wiphy));
1255 }
1256 break;
1257 }
1258
1259 if (priv->pending_tx_pkts < oldcount) {
Lennert Buytenhek9a2303b2010-01-04 21:54:25 +01001260 printk(KERN_NOTICE "%s: waiting for tx rings "
1261 "to drain (%d -> %d pkts)\n",
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001262 wiphy_name(hw->wiphy), oldcount,
1263 priv->pending_tx_pkts);
1264 retry = 1;
1265 continue;
1266 }
1267
1268 priv->tx_wait = NULL;
1269
1270 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1271 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1272 mwl8k_dump_tx_rings(hw);
1273
1274 rc = -ETIMEDOUT;
1275 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001276 spin_unlock_bh(&priv->tx_lock);
1277
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001278 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001279}
1280
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001281#define MWL8K_TXD_SUCCESS(status) \
1282 ((status) & (MWL8K_TXD_STATUS_OK | \
1283 MWL8K_TXD_STATUS_OK_RETRY | \
1284 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001285
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001286static int
1287mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001288{
1289 struct mwl8k_priv *priv = hw->priv;
1290 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001291 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001292
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001293 processed = 0;
1294 while (txq->stats.len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001295 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001296 struct mwl8k_tx_desc *tx_desc;
1297 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001298 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001299 struct sk_buff *skb;
1300 struct ieee80211_tx_info *info;
1301 u32 status;
1302
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001303 tx = txq->head;
1304 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001305
1306 status = le32_to_cpu(tx_desc->status);
1307
1308 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1309 if (!force)
1310 break;
1311 tx_desc->status &=
1312 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1313 }
1314
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001315 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1316 BUG_ON(txq->stats.len == 0);
1317 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001318 priv->pending_tx_pkts--;
1319
1320 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001321 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001322 skb = txq->skb[tx];
1323 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001324
1325 BUG_ON(skb == NULL);
1326 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1327
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001328 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001329
1330 /* Mark descriptor as unused */
1331 tx_desc->pkt_phys_addr = 0;
1332 tx_desc->pkt_len = 0;
1333
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001334 info = IEEE80211_SKB_CB(skb);
1335 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001336 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001337 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001338
1339 ieee80211_tx_status_irqsafe(hw, skb);
1340
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001341 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001342 }
1343
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001344 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001345 ieee80211_wake_queue(hw, index);
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001346
1347 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001348}
1349
1350/* must be called only when the card's transmit is completely halted */
1351static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1352{
1353 struct mwl8k_priv *priv = hw->priv;
1354 struct mwl8k_tx_queue *txq = priv->txq + index;
1355
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001356 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001357
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001358 kfree(txq->skb);
1359 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001360
1361 pci_free_consistent(priv->pdev,
1362 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001363 txq->txd, txq->txd_dma);
1364 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001365}
1366
1367static int
1368mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1369{
1370 struct mwl8k_priv *priv = hw->priv;
1371 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001372 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001373 struct ieee80211_hdr *wh;
1374 struct mwl8k_tx_queue *txq;
1375 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001376 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001377 u32 txstatus;
1378 u8 txdatarate;
1379 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001380
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001381 wh = (struct ieee80211_hdr *)skb->data;
1382 if (ieee80211_is_data_qos(wh->frame_control))
1383 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1384 else
1385 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001386
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001387 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001388 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001389
1390 tx_info = IEEE80211_SKB_CB(skb);
1391 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001392
1393 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001394 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001395 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1396 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001397 }
1398
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001399 /* Setup firmware control bit fields for each frame type. */
1400 txstatus = 0;
1401 txdatarate = 0;
1402 if (ieee80211_is_mgmt(wh->frame_control) ||
1403 ieee80211_is_ctl(wh->frame_control)) {
1404 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001405 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001406 } else if (ieee80211_is_data(wh->frame_control)) {
1407 txdatarate = 1;
1408 if (is_multicast_ether_addr(wh->addr1))
1409 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1410
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001411 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001412 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001413 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001414 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001415 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001416 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001417
1418 dma = pci_map_single(priv->pdev, skb->data,
1419 skb->len, PCI_DMA_TODEVICE);
1420
1421 if (pci_dma_mapping_error(priv->pdev, dma)) {
1422 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001423 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001424 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001425 return NETDEV_TX_OK;
1426 }
1427
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001428 spin_lock_bh(&priv->tx_lock);
1429
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001430 txq = priv->txq + index;
1431
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001432 BUG_ON(txq->skb[txq->tail] != NULL);
1433 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001434
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001435 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001436 tx->data_rate = txdatarate;
1437 tx->tx_priority = index;
1438 tx->qos_control = cpu_to_le16(qos);
1439 tx->pkt_phys_addr = cpu_to_le32(dma);
1440 tx->pkt_len = cpu_to_le16(skb->len);
1441 tx->rate_info = 0;
Lennert Buytenheka6804002010-01-04 21:55:42 +01001442 if (!priv->ap_fw && tx_info->control.sta != NULL)
1443 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1444 else
1445 tx->peer_id = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001446 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001447 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1448
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001449 txq->stats.count++;
1450 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001451 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001452
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001453 txq->tail++;
1454 if (txq->tail == MWL8K_TX_DESCS)
1455 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001456
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001457 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001458 ieee80211_stop_queue(hw, index);
1459
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001460 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001461
1462 spin_unlock_bh(&priv->tx_lock);
1463
1464 return NETDEV_TX_OK;
1465}
1466
1467
1468/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001469 * Firmware access.
1470 *
1471 * We have the following requirements for issuing firmware commands:
1472 * - Some commands require that the packet transmit path is idle when
1473 * the command is issued. (For simplicity, we'll just quiesce the
1474 * transmit path for every command.)
1475 * - There are certain sequences of commands that need to be issued to
1476 * the hardware sequentially, with no other intervening commands.
1477 *
1478 * This leads to an implementation of a "firmware lock" as a mutex that
1479 * can be taken recursively, and which is taken by both the low-level
1480 * command submission function (mwl8k_post_cmd) as well as any users of
1481 * that function that require issuing of an atomic sequence of commands,
1482 * and quiesces the transmit path whenever it's taken.
1483 */
1484static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1485{
1486 struct mwl8k_priv *priv = hw->priv;
1487
1488 if (priv->fw_mutex_owner != current) {
1489 int rc;
1490
1491 mutex_lock(&priv->fw_mutex);
1492 ieee80211_stop_queues(hw);
1493
1494 rc = mwl8k_tx_wait_empty(hw);
1495 if (rc) {
1496 ieee80211_wake_queues(hw);
1497 mutex_unlock(&priv->fw_mutex);
1498
1499 return rc;
1500 }
1501
1502 priv->fw_mutex_owner = current;
1503 }
1504
1505 priv->fw_mutex_depth++;
1506
1507 return 0;
1508}
1509
1510static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1511{
1512 struct mwl8k_priv *priv = hw->priv;
1513
1514 if (!--priv->fw_mutex_depth) {
1515 ieee80211_wake_queues(hw);
1516 priv->fw_mutex_owner = NULL;
1517 mutex_unlock(&priv->fw_mutex);
1518 }
1519}
1520
1521
1522/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001523 * Command processing.
1524 */
1525
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001526/* Timeout firmware commands after 10s */
1527#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001528
1529static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1530{
1531 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1532 struct mwl8k_priv *priv = hw->priv;
1533 void __iomem *regs = priv->regs;
1534 dma_addr_t dma_addr;
1535 unsigned int dma_size;
1536 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001537 unsigned long timeout = 0;
1538 u8 buf[32];
1539
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001540 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001541 dma_size = le16_to_cpu(cmd->length);
1542 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1543 PCI_DMA_BIDIRECTIONAL);
1544 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1545 return -ENOMEM;
1546
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001547 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001548 if (rc) {
1549 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1550 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001551 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001552 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001553
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001554 priv->hostcmd_wait = &cmd_wait;
1555 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1556 iowrite32(MWL8K_H2A_INT_DOORBELL,
1557 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1558 iowrite32(MWL8K_H2A_INT_DUMMY,
1559 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001560
1561 timeout = wait_for_completion_timeout(&cmd_wait,
1562 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1563
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001564 priv->hostcmd_wait = NULL;
1565
1566 mwl8k_fw_unlock(hw);
1567
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001568 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1569 PCI_DMA_BIDIRECTIONAL);
1570
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001571 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001572 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001573 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001574 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1575 MWL8K_CMD_TIMEOUT_MS);
1576 rc = -ETIMEDOUT;
1577 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001578 int ms;
1579
1580 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1581
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001582 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001583 if (rc)
1584 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001585 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001586 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001587 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001588 else if (ms > 2000)
1589 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1590 wiphy_name(hw->wiphy),
1591 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1592 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001593 }
1594
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001595 return rc;
1596}
1597
1598/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001599 * Setup code shared between STA and AP firmware images.
1600 */
1601static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1602{
1603 struct mwl8k_priv *priv = hw->priv;
1604
1605 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1606 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1607
1608 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1609 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1610
1611 priv->band_24.band = IEEE80211_BAND_2GHZ;
1612 priv->band_24.channels = priv->channels_24;
1613 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1614 priv->band_24.bitrates = priv->rates_24;
1615 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1616
1617 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1618}
1619
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01001620static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
1621{
1622 struct mwl8k_priv *priv = hw->priv;
1623
1624 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
1625 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
1626
1627 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
1628 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
1629
1630 priv->band_50.band = IEEE80211_BAND_5GHZ;
1631 priv->band_50.channels = priv->channels_50;
1632 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
1633 priv->band_50.bitrates = priv->rates_50;
1634 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
1635
1636 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
1637}
1638
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001639/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001640 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001641 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001642struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001643 struct mwl8k_cmd_pkt header;
1644 __u8 hw_rev;
1645 __u8 host_interface;
1646 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001647 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001648 __le16 region_code;
1649 __le32 fw_rev;
1650 __le32 ps_cookie;
1651 __le32 caps;
1652 __u8 mcs_bitmap[16];
1653 __le32 rx_queue_ptr;
1654 __le32 num_tx_queues;
1655 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1656 __le32 caps2;
1657 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001658 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001659} __attribute__((packed));
1660
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001661#define MWL8K_CAP_MAX_AMSDU 0x20000000
1662#define MWL8K_CAP_GREENFIELD 0x08000000
1663#define MWL8K_CAP_AMPDU 0x04000000
1664#define MWL8K_CAP_RX_STBC 0x01000000
1665#define MWL8K_CAP_TX_STBC 0x00800000
1666#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1667#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1668#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1669#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1670#define MWL8K_CAP_DELAY_BA 0x00003000
1671#define MWL8K_CAP_MIMO 0x00000200
1672#define MWL8K_CAP_40MHZ 0x00000100
Lennert Buytenhek06953232010-01-12 13:49:41 +01001673#define MWL8K_CAP_BAND_MASK 0x00000007
1674#define MWL8K_CAP_5GHZ 0x00000004
1675#define MWL8K_CAP_2GHZ4 0x00000001
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001676
Lennert Buytenhek06953232010-01-12 13:49:41 +01001677static void
1678mwl8k_set_ht_caps(struct ieee80211_hw *hw,
1679 struct ieee80211_supported_band *band, u32 cap)
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001680{
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001681 int rx_streams;
1682 int tx_streams;
1683
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001684 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001685
1686 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001687 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001688 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001689 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001690 if (cap & MWL8K_CAP_AMPDU) {
1691 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001692 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1693 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001694 }
1695 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001696 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001697 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001698 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001699 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001700 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001701 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001702 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001703 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001704 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001705 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001706 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001707
1708 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1709 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1710
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001711 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001712 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001713 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001714 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001715 band->ht_cap.mcs.rx_mask[2] = 0xff;
1716 band->ht_cap.mcs.rx_mask[4] = 0x01;
1717 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001718
1719 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001720 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1721 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001722 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1723 }
1724}
1725
Lennert Buytenhek06953232010-01-12 13:49:41 +01001726static void
1727mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
1728{
1729 struct mwl8k_priv *priv = hw->priv;
1730
1731 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
1732 mwl8k_setup_2ghz_band(hw);
1733 if (caps & MWL8K_CAP_MIMO)
1734 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
1735 }
1736
1737 if (caps & MWL8K_CAP_5GHZ) {
1738 mwl8k_setup_5ghz_band(hw);
1739 if (caps & MWL8K_CAP_MIMO)
1740 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
1741 }
1742}
1743
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001744static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001745{
1746 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001747 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001748 int rc;
1749 int i;
1750
1751 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1752 if (cmd == NULL)
1753 return -ENOMEM;
1754
1755 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1756 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1757
1758 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1759 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001760 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001761 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001762 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001763 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001764 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001765 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001766
1767 rc = mwl8k_post_cmd(hw, &cmd->header);
1768
1769 if (!rc) {
1770 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1771 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001772 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001773 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek06953232010-01-12 13:49:41 +01001774 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001775 }
1776
1777 kfree(cmd);
1778 return rc;
1779}
1780
1781/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001782 * CMD_GET_HW_SPEC (AP version).
1783 */
1784struct mwl8k_cmd_get_hw_spec_ap {
1785 struct mwl8k_cmd_pkt header;
1786 __u8 hw_rev;
1787 __u8 host_interface;
1788 __le16 num_wcb;
1789 __le16 num_mcaddrs;
1790 __u8 perm_addr[ETH_ALEN];
1791 __le16 region_code;
1792 __le16 num_antenna;
1793 __le32 fw_rev;
1794 __le32 wcbbase0;
1795 __le32 rxwrptr;
1796 __le32 rxrdptr;
1797 __le32 ps_cookie;
1798 __le32 wcbbase1;
1799 __le32 wcbbase2;
1800 __le32 wcbbase3;
1801} __attribute__((packed));
1802
1803static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1804{
1805 struct mwl8k_priv *priv = hw->priv;
1806 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1807 int rc;
1808
1809 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1810 if (cmd == NULL)
1811 return -ENOMEM;
1812
1813 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1814 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1815
1816 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1817 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1818
1819 rc = mwl8k_post_cmd(hw, &cmd->header);
1820
1821 if (!rc) {
1822 int off;
1823
1824 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1825 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1826 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1827 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001828 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001829
1830 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1831 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1832
1833 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1834 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1835
1836 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1837 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1838
1839 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1840 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1841
1842 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1843 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1844
1845 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1846 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1847 }
1848
1849 kfree(cmd);
1850 return rc;
1851}
1852
1853/*
1854 * CMD_SET_HW_SPEC.
1855 */
1856struct mwl8k_cmd_set_hw_spec {
1857 struct mwl8k_cmd_pkt header;
1858 __u8 hw_rev;
1859 __u8 host_interface;
1860 __le16 num_mcaddrs;
1861 __u8 perm_addr[ETH_ALEN];
1862 __le16 region_code;
1863 __le32 fw_rev;
1864 __le32 ps_cookie;
1865 __le32 caps;
1866 __le32 rx_queue_ptr;
1867 __le32 num_tx_queues;
1868 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1869 __le32 flags;
1870 __le32 num_tx_desc_per_queue;
1871 __le32 total_rxd;
1872} __attribute__((packed));
1873
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001874#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1875#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1876#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001877
1878static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1879{
1880 struct mwl8k_priv *priv = hw->priv;
1881 struct mwl8k_cmd_set_hw_spec *cmd;
1882 int rc;
1883 int i;
1884
1885 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1886 if (cmd == NULL)
1887 return -ENOMEM;
1888
1889 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1890 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1891
1892 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1893 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1894 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1895 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1896 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001897 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1898 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1899 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001900 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1901 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1902
1903 rc = mwl8k_post_cmd(hw, &cmd->header);
1904 kfree(cmd);
1905
1906 return rc;
1907}
1908
1909/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001910 * CMD_MAC_MULTICAST_ADR.
1911 */
1912struct mwl8k_cmd_mac_multicast_adr {
1913 struct mwl8k_cmd_pkt header;
1914 __le16 action;
1915 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001916 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001917};
1918
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001919#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1920#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1921#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1922#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001923
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001924static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001925__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001926 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001927{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001928 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001929 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001930 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001931
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001932 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001933 allmulti = 1;
1934 mc_count = 0;
1935 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001936
1937 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1938
1939 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001940 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001941 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001942
1943 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1944 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001945 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1946 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001947
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001948 if (allmulti) {
1949 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1950 } else if (mc_count) {
1951 int i;
1952
1953 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1954 cmd->numaddr = cpu_to_le16(mc_count);
1955 for (i = 0; i < mc_count && mclist; i++) {
1956 if (mclist->da_addrlen != ETH_ALEN) {
1957 kfree(cmd);
1958 return NULL;
1959 }
1960 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1961 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001962 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001963 }
1964
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001965 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001966}
1967
1968/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001969 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001970 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001971struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001972 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001973 __le32 stats[64];
1974} __attribute__((packed));
1975
1976#define MWL8K_STAT_ACK_FAILURE 9
1977#define MWL8K_STAT_RTS_FAILURE 12
1978#define MWL8K_STAT_FCS_ERROR 24
1979#define MWL8K_STAT_RTS_SUCCESS 11
1980
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001981static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1982 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001983{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001984 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001985 int rc;
1986
1987 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1988 if (cmd == NULL)
1989 return -ENOMEM;
1990
1991 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1992 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001993
1994 rc = mwl8k_post_cmd(hw, &cmd->header);
1995 if (!rc) {
1996 stats->dot11ACKFailureCount =
1997 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1998 stats->dot11RTSFailureCount =
1999 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2000 stats->dot11FCSErrorCount =
2001 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2002 stats->dot11RTSSuccessCount =
2003 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2004 }
2005 kfree(cmd);
2006
2007 return rc;
2008}
2009
2010/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002011 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002012 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002013struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002014 struct mwl8k_cmd_pkt header;
2015 __le16 action;
2016 __le16 control;
2017 __le16 radio_on;
2018} __attribute__((packed));
2019
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002020static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002021mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002022{
2023 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002024 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002025 int rc;
2026
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002027 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002028 return 0;
2029
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002030 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2031 if (cmd == NULL)
2032 return -ENOMEM;
2033
2034 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2035 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2036 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002037 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002038 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2039
2040 rc = mwl8k_post_cmd(hw, &cmd->header);
2041 kfree(cmd);
2042
2043 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002044 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002045
2046 return rc;
2047}
2048
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002049static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002050{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002051 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002052}
2053
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002054static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002055{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002056 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002057}
2058
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002059static int
2060mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2061{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002062 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002063
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002064 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002065
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002066 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002067}
2068
2069/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002070 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002071 */
2072#define MWL8K_TX_POWER_LEVEL_TOTAL 8
2073
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002074struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002075 struct mwl8k_cmd_pkt header;
2076 __le16 action;
2077 __le16 support_level;
2078 __le16 current_level;
2079 __le16 reserved;
2080 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2081} __attribute__((packed));
2082
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002083static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002084{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002085 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002086 int rc;
2087
2088 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2089 if (cmd == NULL)
2090 return -ENOMEM;
2091
2092 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2093 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2094 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2095 cmd->support_level = cpu_to_le16(dBm);
2096
2097 rc = mwl8k_post_cmd(hw, &cmd->header);
2098 kfree(cmd);
2099
2100 return rc;
2101}
2102
2103/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002104 * CMD_RF_ANTENNA.
2105 */
2106struct mwl8k_cmd_rf_antenna {
2107 struct mwl8k_cmd_pkt header;
2108 __le16 antenna;
2109 __le16 mode;
2110} __attribute__((packed));
2111
2112#define MWL8K_RF_ANTENNA_RX 1
2113#define MWL8K_RF_ANTENNA_TX 2
2114
2115static int
2116mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2117{
2118 struct mwl8k_cmd_rf_antenna *cmd;
2119 int rc;
2120
2121 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2122 if (cmd == NULL)
2123 return -ENOMEM;
2124
2125 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2126 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2127 cmd->antenna = cpu_to_le16(antenna);
2128 cmd->mode = cpu_to_le16(mask);
2129
2130 rc = mwl8k_post_cmd(hw, &cmd->header);
2131 kfree(cmd);
2132
2133 return rc;
2134}
2135
2136/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002137 * CMD_SET_BEACON.
2138 */
2139struct mwl8k_cmd_set_beacon {
2140 struct mwl8k_cmd_pkt header;
2141 __le16 beacon_len;
2142 __u8 beacon[0];
2143};
2144
2145static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, u8 *beacon, int len)
2146{
2147 struct mwl8k_cmd_set_beacon *cmd;
2148 int rc;
2149
2150 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2151 if (cmd == NULL)
2152 return -ENOMEM;
2153
2154 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2155 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2156 cmd->beacon_len = cpu_to_le16(len);
2157 memcpy(cmd->beacon, beacon, len);
2158
2159 rc = mwl8k_post_cmd(hw, &cmd->header);
2160 kfree(cmd);
2161
2162 return rc;
2163}
2164
2165/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002166 * CMD_SET_PRE_SCAN.
2167 */
2168struct mwl8k_cmd_set_pre_scan {
2169 struct mwl8k_cmd_pkt header;
2170} __attribute__((packed));
2171
2172static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2173{
2174 struct mwl8k_cmd_set_pre_scan *cmd;
2175 int rc;
2176
2177 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2178 if (cmd == NULL)
2179 return -ENOMEM;
2180
2181 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2182 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2183
2184 rc = mwl8k_post_cmd(hw, &cmd->header);
2185 kfree(cmd);
2186
2187 return rc;
2188}
2189
2190/*
2191 * CMD_SET_POST_SCAN.
2192 */
2193struct mwl8k_cmd_set_post_scan {
2194 struct mwl8k_cmd_pkt header;
2195 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002196 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002197} __attribute__((packed));
2198
2199static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002200mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002201{
2202 struct mwl8k_cmd_set_post_scan *cmd;
2203 int rc;
2204
2205 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2206 if (cmd == NULL)
2207 return -ENOMEM;
2208
2209 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2210 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2211 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002212 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002213
2214 rc = mwl8k_post_cmd(hw, &cmd->header);
2215 kfree(cmd);
2216
2217 return rc;
2218}
2219
2220/*
2221 * CMD_SET_RF_CHANNEL.
2222 */
2223struct mwl8k_cmd_set_rf_channel {
2224 struct mwl8k_cmd_pkt header;
2225 __le16 action;
2226 __u8 current_channel;
2227 __le32 channel_flags;
2228} __attribute__((packed));
2229
2230static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002231 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002232{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002233 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002234 struct mwl8k_cmd_set_rf_channel *cmd;
2235 int rc;
2236
2237 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2238 if (cmd == NULL)
2239 return -ENOMEM;
2240
2241 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2242 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2243 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2244 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002245
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002246 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002247 cmd->channel_flags |= cpu_to_le32(0x00000001);
Lennert Buytenhek42574ea2010-01-12 13:49:18 +01002248 else if (channel->band == IEEE80211_BAND_5GHZ)
2249 cmd->channel_flags |= cpu_to_le32(0x00000004);
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002250
2251 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2252 conf->channel_type == NL80211_CHAN_HT20)
2253 cmd->channel_flags |= cpu_to_le32(0x00000080);
2254 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2255 cmd->channel_flags |= cpu_to_le32(0x000001900);
2256 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2257 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002258
2259 rc = mwl8k_post_cmd(hw, &cmd->header);
2260 kfree(cmd);
2261
2262 return rc;
2263}
2264
2265/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002266 * CMD_SET_AID.
2267 */
2268#define MWL8K_FRAME_PROT_DISABLED 0x00
2269#define MWL8K_FRAME_PROT_11G 0x07
2270#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2271#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2272
2273struct mwl8k_cmd_update_set_aid {
2274 struct mwl8k_cmd_pkt header;
2275 __le16 aid;
2276
2277 /* AP's MAC address (BSSID) */
2278 __u8 bssid[ETH_ALEN];
2279 __le16 protection_mode;
2280 __u8 supp_rates[14];
2281} __attribute__((packed));
2282
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002283static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2284{
2285 int i;
2286 int j;
2287
2288 /*
2289 * Clear nonstandard rates 4 and 13.
2290 */
2291 mask &= 0x1fef;
2292
2293 for (i = 0, j = 0; i < 14; i++) {
2294 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002295 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002296 }
2297}
2298
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002299static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002300mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2301 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002302{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002303 struct mwl8k_cmd_update_set_aid *cmd;
2304 u16 prot_mode;
2305 int rc;
2306
2307 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2308 if (cmd == NULL)
2309 return -ENOMEM;
2310
2311 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2312 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002313 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002314 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002315
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002316 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002317 prot_mode = MWL8K_FRAME_PROT_11G;
2318 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002319 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002320 IEEE80211_HT_OP_MODE_PROTECTION) {
2321 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2322 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2323 break;
2324 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2325 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2326 break;
2327 default:
2328 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2329 break;
2330 }
2331 }
2332 cmd->protection_mode = cpu_to_le16(prot_mode);
2333
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002334 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002335
2336 rc = mwl8k_post_cmd(hw, &cmd->header);
2337 kfree(cmd);
2338
2339 return rc;
2340}
2341
2342/*
2343 * CMD_SET_RATE.
2344 */
2345struct mwl8k_cmd_set_rate {
2346 struct mwl8k_cmd_pkt header;
2347 __u8 legacy_rates[14];
2348
2349 /* Bitmap for supported MCS codes. */
2350 __u8 mcs_set[16];
2351 __u8 reserved[16];
2352} __attribute__((packed));
2353
2354static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002355mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002356 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002357{
2358 struct mwl8k_cmd_set_rate *cmd;
2359 int rc;
2360
2361 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2362 if (cmd == NULL)
2363 return -ENOMEM;
2364
2365 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2366 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002367 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002368 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002369
2370 rc = mwl8k_post_cmd(hw, &cmd->header);
2371 kfree(cmd);
2372
2373 return rc;
2374}
2375
2376/*
2377 * CMD_FINALIZE_JOIN.
2378 */
2379#define MWL8K_FJ_BEACON_MAXLEN 128
2380
2381struct mwl8k_cmd_finalize_join {
2382 struct mwl8k_cmd_pkt header;
2383 __le32 sleep_interval; /* Number of beacon periods to sleep */
2384 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2385} __attribute__((packed));
2386
2387static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2388 int framelen, int dtim)
2389{
2390 struct mwl8k_cmd_finalize_join *cmd;
2391 struct ieee80211_mgmt *payload = frame;
2392 int payload_len;
2393 int rc;
2394
2395 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2396 if (cmd == NULL)
2397 return -ENOMEM;
2398
2399 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2400 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2401 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2402
2403 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2404 if (payload_len < 0)
2405 payload_len = 0;
2406 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2407 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2408
2409 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2410
2411 rc = mwl8k_post_cmd(hw, &cmd->header);
2412 kfree(cmd);
2413
2414 return rc;
2415}
2416
2417/*
2418 * CMD_SET_RTS_THRESHOLD.
2419 */
2420struct mwl8k_cmd_set_rts_threshold {
2421 struct mwl8k_cmd_pkt header;
2422 __le16 action;
2423 __le16 threshold;
2424} __attribute__((packed));
2425
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002426static int
2427mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002428{
2429 struct mwl8k_cmd_set_rts_threshold *cmd;
2430 int rc;
2431
2432 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2433 if (cmd == NULL)
2434 return -ENOMEM;
2435
2436 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2437 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002438 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2439 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002440
2441 rc = mwl8k_post_cmd(hw, &cmd->header);
2442 kfree(cmd);
2443
2444 return rc;
2445}
2446
2447/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002448 * CMD_SET_SLOT.
2449 */
2450struct mwl8k_cmd_set_slot {
2451 struct mwl8k_cmd_pkt header;
2452 __le16 action;
2453 __u8 short_slot;
2454} __attribute__((packed));
2455
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002456static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002457{
2458 struct mwl8k_cmd_set_slot *cmd;
2459 int rc;
2460
2461 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2462 if (cmd == NULL)
2463 return -ENOMEM;
2464
2465 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2466 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2467 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002468 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002469
2470 rc = mwl8k_post_cmd(hw, &cmd->header);
2471 kfree(cmd);
2472
2473 return rc;
2474}
2475
2476/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002477 * CMD_SET_EDCA_PARAMS.
2478 */
2479struct mwl8k_cmd_set_edca_params {
2480 struct mwl8k_cmd_pkt header;
2481
2482 /* See MWL8K_SET_EDCA_XXX below */
2483 __le16 action;
2484
2485 /* TX opportunity in units of 32 us */
2486 __le16 txop;
2487
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002488 union {
2489 struct {
2490 /* Log exponent of max contention period: 0...15 */
2491 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002492
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002493 /* Log exponent of min contention period: 0...15 */
2494 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002495
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002496 /* Adaptive interframe spacing in units of 32us */
2497 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002498
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002499 /* TX queue to configure */
2500 __u8 txq;
2501 } ap;
2502 struct {
2503 /* Log exponent of max contention period: 0...15 */
2504 __u8 log_cw_max;
2505
2506 /* Log exponent of min contention period: 0...15 */
2507 __u8 log_cw_min;
2508
2509 /* Adaptive interframe spacing in units of 32us */
2510 __u8 aifs;
2511
2512 /* TX queue to configure */
2513 __u8 txq;
2514 } sta;
2515 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002516} __attribute__((packed));
2517
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002518#define MWL8K_SET_EDCA_CW 0x01
2519#define MWL8K_SET_EDCA_TXOP 0x02
2520#define MWL8K_SET_EDCA_AIFS 0x04
2521
2522#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2523 MWL8K_SET_EDCA_TXOP | \
2524 MWL8K_SET_EDCA_AIFS)
2525
2526static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002527mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2528 __u16 cw_min, __u16 cw_max,
2529 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002530{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002531 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002532 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002533 int rc;
2534
2535 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2536 if (cmd == NULL)
2537 return -ENOMEM;
2538
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002539 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2540 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002541 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2542 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002543 if (priv->ap_fw) {
2544 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2545 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2546 cmd->ap.aifs = aifs;
2547 cmd->ap.txq = qnum;
2548 } else {
2549 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2550 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2551 cmd->sta.aifs = aifs;
2552 cmd->sta.txq = qnum;
2553 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002554
2555 rc = mwl8k_post_cmd(hw, &cmd->header);
2556 kfree(cmd);
2557
2558 return rc;
2559}
2560
2561/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002562 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002563 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002564struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002565 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002566 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002567} __attribute__((packed));
2568
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002569static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002570{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002571 struct mwl8k_priv *priv = hw->priv;
2572 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002573 int rc;
2574
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002575 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2576 if (cmd == NULL)
2577 return -ENOMEM;
2578
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002579 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002580 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002581 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002582
2583 rc = mwl8k_post_cmd(hw, &cmd->header);
2584 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002585
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002586 if (!rc)
2587 priv->wmm_enabled = enable;
2588
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002589 return rc;
2590}
2591
2592/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002593 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002594 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002595struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002596 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002597 __le32 action;
2598 __u8 rx_antenna_map;
2599 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002600} __attribute__((packed));
2601
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002602static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002603{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002604 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002605 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002606
2607 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2608 if (cmd == NULL)
2609 return -ENOMEM;
2610
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002611 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002612 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002613 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2614 cmd->rx_antenna_map = rx;
2615 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002616
2617 rc = mwl8k_post_cmd(hw, &cmd->header);
2618 kfree(cmd);
2619
2620 return rc;
2621}
2622
2623/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002624 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002625 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002626struct mwl8k_cmd_use_fixed_rate_sta {
2627 struct mwl8k_cmd_pkt header;
2628 __le32 action;
2629 __le32 allow_rate_drop;
2630 __le32 num_rates;
2631 struct {
2632 __le32 is_ht_rate;
2633 __le32 enable_retry;
2634 __le32 rate;
2635 __le32 retry_count;
2636 } rate_entry[8];
2637 __le32 rate_type;
2638 __le32 reserved1;
2639 __le32 reserved2;
2640} __attribute__((packed));
2641
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002642#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002643#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002644
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002645static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002646{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002647 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002648 int rc;
2649
2650 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2651 if (cmd == NULL)
2652 return -ENOMEM;
2653
2654 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2655 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002656 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2657 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002658
2659 rc = mwl8k_post_cmd(hw, &cmd->header);
2660 kfree(cmd);
2661
2662 return rc;
2663}
2664
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002665/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002666 * CMD_USE_FIXED_RATE (AP version).
2667 */
2668struct mwl8k_cmd_use_fixed_rate_ap {
2669 struct mwl8k_cmd_pkt header;
2670 __le32 action;
2671 __le32 allow_rate_drop;
2672 __le32 num_rates;
2673 struct mwl8k_rate_entry_ap {
2674 __le32 is_ht_rate;
2675 __le32 enable_retry;
2676 __le32 rate;
2677 __le32 retry_count;
2678 } rate_entry[4];
2679 u8 multicast_rate;
2680 u8 multicast_rate_type;
2681 u8 management_rate;
2682} __attribute__((packed));
2683
2684static int
2685mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2686{
2687 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2688 int rc;
2689
2690 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2691 if (cmd == NULL)
2692 return -ENOMEM;
2693
2694 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2695 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2696 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2697 cmd->multicast_rate = mcast;
2698 cmd->management_rate = mgmt;
2699
2700 rc = mwl8k_post_cmd(hw, &cmd->header);
2701 kfree(cmd);
2702
2703 return rc;
2704}
2705
2706/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002707 * CMD_ENABLE_SNIFFER.
2708 */
2709struct mwl8k_cmd_enable_sniffer {
2710 struct mwl8k_cmd_pkt header;
2711 __le32 action;
2712} __attribute__((packed));
2713
2714static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2715{
2716 struct mwl8k_cmd_enable_sniffer *cmd;
2717 int rc;
2718
2719 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2720 if (cmd == NULL)
2721 return -ENOMEM;
2722
2723 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2724 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2725 cmd->action = cpu_to_le32(!!enable);
2726
2727 rc = mwl8k_post_cmd(hw, &cmd->header);
2728 kfree(cmd);
2729
2730 return rc;
2731}
2732
2733/*
2734 * CMD_SET_MAC_ADDR.
2735 */
2736struct mwl8k_cmd_set_mac_addr {
2737 struct mwl8k_cmd_pkt header;
2738 union {
2739 struct {
2740 __le16 mac_type;
2741 __u8 mac_addr[ETH_ALEN];
2742 } mbss;
2743 __u8 mac_addr[ETH_ALEN];
2744 };
2745} __attribute__((packed));
2746
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002747#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2748#define MWL8K_MAC_TYPE_PRIMARY_AP 2
2749
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002750static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2751{
2752 struct mwl8k_priv *priv = hw->priv;
2753 struct mwl8k_cmd_set_mac_addr *cmd;
2754 int rc;
2755
2756 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2757 if (cmd == NULL)
2758 return -ENOMEM;
2759
2760 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2761 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2762 if (priv->ap_fw) {
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002763 cmd->mbss.mac_type = cpu_to_le16(MWL8K_MAC_TYPE_PRIMARY_AP);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002764 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2765 } else {
2766 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2767 }
2768
2769 rc = mwl8k_post_cmd(hw, &cmd->header);
2770 kfree(cmd);
2771
2772 return rc;
2773}
2774
2775/*
2776 * CMD_SET_RATEADAPT_MODE.
2777 */
2778struct mwl8k_cmd_set_rate_adapt_mode {
2779 struct mwl8k_cmd_pkt header;
2780 __le16 action;
2781 __le16 mode;
2782} __attribute__((packed));
2783
2784static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2785{
2786 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2787 int rc;
2788
2789 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2790 if (cmd == NULL)
2791 return -ENOMEM;
2792
2793 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2794 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2795 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2796 cmd->mode = cpu_to_le16(mode);
2797
2798 rc = mwl8k_post_cmd(hw, &cmd->header);
2799 kfree(cmd);
2800
2801 return rc;
2802}
2803
2804/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002805 * CMD_BSS_START.
2806 */
2807struct mwl8k_cmd_bss_start {
2808 struct mwl8k_cmd_pkt header;
2809 __le32 enable;
2810} __attribute__((packed));
2811
2812static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, int enable)
2813{
2814 struct mwl8k_cmd_bss_start *cmd;
2815 int rc;
2816
2817 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2818 if (cmd == NULL)
2819 return -ENOMEM;
2820
2821 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2822 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2823 cmd->enable = cpu_to_le32(enable);
2824
2825 rc = mwl8k_post_cmd(hw, &cmd->header);
2826 kfree(cmd);
2827
2828 return rc;
2829}
2830
2831/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002832 * CMD_SET_NEW_STN.
2833 */
2834struct mwl8k_cmd_set_new_stn {
2835 struct mwl8k_cmd_pkt header;
2836 __le16 aid;
2837 __u8 mac_addr[6];
2838 __le16 stn_id;
2839 __le16 action;
2840 __le16 rsvd;
2841 __le32 legacy_rates;
2842 __u8 ht_rates[4];
2843 __le16 cap_info;
2844 __le16 ht_capabilities_info;
2845 __u8 mac_ht_param_info;
2846 __u8 rev;
2847 __u8 control_channel;
2848 __u8 add_channel;
2849 __le16 op_mode;
2850 __le16 stbc;
2851 __u8 add_qos_info;
2852 __u8 is_qos_sta;
2853 __le32 fw_sta_ptr;
2854} __attribute__((packed));
2855
2856#define MWL8K_STA_ACTION_ADD 0
2857#define MWL8K_STA_ACTION_REMOVE 2
2858
2859static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2860 struct ieee80211_vif *vif,
2861 struct ieee80211_sta *sta)
2862{
2863 struct mwl8k_cmd_set_new_stn *cmd;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01002864 u32 rates;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002865 int rc;
2866
2867 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2868 if (cmd == NULL)
2869 return -ENOMEM;
2870
2871 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2872 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2873 cmd->aid = cpu_to_le16(sta->aid);
2874 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2875 cmd->stn_id = cpu_to_le16(sta->aid);
2876 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01002877 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
2878 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
2879 else
2880 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
2881 cmd->legacy_rates = cpu_to_le32(rates);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002882 if (sta->ht_cap.ht_supported) {
2883 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2884 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2885 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2886 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2887 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2888 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2889 ((sta->ht_cap.ampdu_density & 7) << 2);
2890 cmd->is_qos_sta = 1;
2891 }
2892
2893 rc = mwl8k_post_cmd(hw, &cmd->header);
2894 kfree(cmd);
2895
2896 return rc;
2897}
2898
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002899static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2900 struct ieee80211_vif *vif)
2901{
2902 struct mwl8k_cmd_set_new_stn *cmd;
2903 int rc;
2904
2905 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2906 if (cmd == NULL)
2907 return -ENOMEM;
2908
2909 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2910 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2911 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2912
2913 rc = mwl8k_post_cmd(hw, &cmd->header);
2914 kfree(cmd);
2915
2916 return rc;
2917}
2918
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002919static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2920 struct ieee80211_vif *vif, u8 *addr)
2921{
2922 struct mwl8k_cmd_set_new_stn *cmd;
2923 int rc;
2924
2925 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2926 if (cmd == NULL)
2927 return -ENOMEM;
2928
2929 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2930 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2931 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2932 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2933
2934 rc = mwl8k_post_cmd(hw, &cmd->header);
2935 kfree(cmd);
2936
2937 return rc;
2938}
2939
2940/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002941 * CMD_UPDATE_STADB.
2942 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01002943struct ewc_ht_info {
2944 __le16 control1;
2945 __le16 control2;
2946 __le16 control3;
2947} __attribute__((packed));
2948
2949struct peer_capability_info {
2950 /* Peer type - AP vs. STA. */
2951 __u8 peer_type;
2952
2953 /* Basic 802.11 capabilities from assoc resp. */
2954 __le16 basic_caps;
2955
2956 /* Set if peer supports 802.11n high throughput (HT). */
2957 __u8 ht_support;
2958
2959 /* Valid if HT is supported. */
2960 __le16 ht_caps;
2961 __u8 extended_ht_caps;
2962 struct ewc_ht_info ewc_info;
2963
2964 /* Legacy rate table. Intersection of our rates and peer rates. */
2965 __u8 legacy_rates[12];
2966
2967 /* HT rate table. Intersection of our rates and peer rates. */
2968 __u8 ht_rates[16];
2969 __u8 pad[16];
2970
2971 /* If set, interoperability mode, no proprietary extensions. */
2972 __u8 interop;
2973 __u8 pad2;
2974 __u8 station_id;
2975 __le16 amsdu_enabled;
2976} __attribute__((packed));
2977
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002978struct mwl8k_cmd_update_stadb {
2979 struct mwl8k_cmd_pkt header;
2980
2981 /* See STADB_ACTION_TYPE */
2982 __le32 action;
2983
2984 /* Peer MAC address */
2985 __u8 peer_addr[ETH_ALEN];
2986
2987 __le32 reserved;
2988
2989 /* Peer info - valid during add/update. */
2990 struct peer_capability_info peer_info;
2991} __attribute__((packed));
2992
Lennert Buytenheka6804002010-01-04 21:55:42 +01002993#define MWL8K_STA_DB_MODIFY_ENTRY 1
2994#define MWL8K_STA_DB_DEL_ENTRY 2
2995
2996/* Peer Entry flags - used to define the type of the peer node */
2997#define MWL8K_PEER_TYPE_ACCESSPOINT 2
2998
2999static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003000 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003001 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003002{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003003 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01003004 struct peer_capability_info *p;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003005 u32 rates;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003006 int rc;
3007
3008 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3009 if (cmd == NULL)
3010 return -ENOMEM;
3011
3012 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3013 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01003014 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003015 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003016
Lennert Buytenheka6804002010-01-04 21:55:42 +01003017 p = &cmd->peer_info;
3018 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
3019 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003020 p->ht_support = sta->ht_cap.ht_supported;
3021 p->ht_caps = sta->ht_cap.cap;
3022 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
3023 ((sta->ht_cap.ampdu_density & 7) << 2);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003024 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3025 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3026 else
3027 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3028 legacy_rate_mask_to_array(p->legacy_rates, rates);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003029 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003030 p->interop = 1;
3031 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003032
Lennert Buytenheka6804002010-01-04 21:55:42 +01003033 rc = mwl8k_post_cmd(hw, &cmd->header);
3034 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003035
Lennert Buytenheka6804002010-01-04 21:55:42 +01003036 return rc ? rc : p->station_id;
3037}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003038
Lennert Buytenheka6804002010-01-04 21:55:42 +01003039static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
3040 struct ieee80211_vif *vif, u8 *addr)
3041{
3042 struct mwl8k_cmd_update_stadb *cmd;
3043 int rc;
3044
3045 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3046 if (cmd == NULL)
3047 return -ENOMEM;
3048
3049 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3050 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3051 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
3052 memcpy(cmd->peer_addr, addr, ETH_ALEN);
3053
3054 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003055 kfree(cmd);
3056
3057 return rc;
3058}
3059
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003060
3061/*
3062 * Interrupt handling.
3063 */
3064static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
3065{
3066 struct ieee80211_hw *hw = dev_id;
3067 struct mwl8k_priv *priv = hw->priv;
3068 u32 status;
3069
3070 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003071 if (!status)
3072 return IRQ_NONE;
3073
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003074 if (status & MWL8K_A2H_INT_TX_DONE) {
3075 status &= ~MWL8K_A2H_INT_TX_DONE;
3076 tasklet_schedule(&priv->poll_tx_task);
3077 }
3078
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003079 if (status & MWL8K_A2H_INT_RX_READY) {
3080 status &= ~MWL8K_A2H_INT_RX_READY;
3081 tasklet_schedule(&priv->poll_rx_task);
3082 }
3083
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003084 if (status)
3085 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003086
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003087 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003088 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003089 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003090 }
3091
3092 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003093 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003094 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003095 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003096 }
3097
3098 return IRQ_HANDLED;
3099}
3100
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003101static void mwl8k_tx_poll(unsigned long data)
3102{
3103 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3104 struct mwl8k_priv *priv = hw->priv;
3105 int limit;
3106 int i;
3107
3108 limit = 32;
3109
3110 spin_lock_bh(&priv->tx_lock);
3111
3112 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3113 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3114
3115 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3116 complete(priv->tx_wait);
3117 priv->tx_wait = NULL;
3118 }
3119
3120 spin_unlock_bh(&priv->tx_lock);
3121
3122 if (limit) {
3123 writel(~MWL8K_A2H_INT_TX_DONE,
3124 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3125 } else {
3126 tasklet_schedule(&priv->poll_tx_task);
3127 }
3128}
3129
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003130static void mwl8k_rx_poll(unsigned long data)
3131{
3132 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3133 struct mwl8k_priv *priv = hw->priv;
3134 int limit;
3135
3136 limit = 32;
3137 limit -= rxq_process(hw, 0, limit);
3138 limit -= rxq_refill(hw, 0, limit);
3139
3140 if (limit) {
3141 writel(~MWL8K_A2H_INT_RX_READY,
3142 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3143 } else {
3144 tasklet_schedule(&priv->poll_rx_task);
3145 }
3146}
3147
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003148
3149/*
3150 * Core driver operations.
3151 */
3152static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3153{
3154 struct mwl8k_priv *priv = hw->priv;
3155 int index = skb_get_queue_mapping(skb);
3156 int rc;
3157
Lennert Buytenhek9189c102010-01-12 13:47:32 +01003158 if (!priv->radio_on) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003159 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003160 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003161 dev_kfree_skb(skb);
3162 return NETDEV_TX_OK;
3163 }
3164
3165 rc = mwl8k_txq_xmit(hw, index, skb);
3166
3167 return rc;
3168}
3169
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003170static int mwl8k_start(struct ieee80211_hw *hw)
3171{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003172 struct mwl8k_priv *priv = hw->priv;
3173 int rc;
3174
Joe Perchesa0607fd2009-11-18 23:29:17 -08003175 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003176 IRQF_SHARED, MWL8K_NAME, hw);
3177 if (rc) {
3178 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003179 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003180 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003181 }
3182
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003183 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003184 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003185 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003186
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003187 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003188 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003189
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003190 rc = mwl8k_fw_lock(hw);
3191 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003192 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003193
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003194 if (!priv->ap_fw) {
3195 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003196 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003197
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003198 if (!rc)
3199 rc = mwl8k_cmd_set_pre_scan(hw);
3200
3201 if (!rc)
3202 rc = mwl8k_cmd_set_post_scan(hw,
3203 "\x00\x00\x00\x00\x00\x00");
3204 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003205
3206 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003207 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003208
3209 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003210 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003211
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003212 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003213 }
3214
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003215 if (rc) {
3216 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3217 free_irq(priv->pdev->irq, hw);
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003218 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003219 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003220 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003221
3222 return rc;
3223}
3224
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003225static void mwl8k_stop(struct ieee80211_hw *hw)
3226{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003227 struct mwl8k_priv *priv = hw->priv;
3228 int i;
3229
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003230 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003231
3232 ieee80211_stop_queues(hw);
3233
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003234 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003235 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003236 free_irq(priv->pdev->irq, hw);
3237
3238 /* Stop finalize join worker */
3239 cancel_work_sync(&priv->finalize_join_worker);
3240 if (priv->beacon_skb != NULL)
3241 dev_kfree_skb(priv->beacon_skb);
3242
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003243 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003244 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003245 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003246
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003247 /* Return all skbs to mac80211 */
3248 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01003249 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003250}
3251
3252static int mwl8k_add_interface(struct ieee80211_hw *hw,
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003253 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003254{
3255 struct mwl8k_priv *priv = hw->priv;
3256 struct mwl8k_vif *mwl8k_vif;
3257
3258 /*
3259 * We only support one active interface at a time.
3260 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003261 if (!list_empty(&priv->vif_list))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003262 return -EBUSY;
3263
3264 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003265 * Reject interface creation if sniffer mode is active, as
3266 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003267 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003268 */
3269 if (priv->sniffer_enabled) {
3270 printk(KERN_INFO "%s: unable to create STA "
3271 "interface due to sniffer mode being enabled\n",
3272 wiphy_name(hw->wiphy));
3273 return -EINVAL;
3274 }
3275
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003276 /* Set the mac address. */
3277 mwl8k_cmd_set_mac_addr(hw, vif->addr);
3278
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003279 if (priv->ap_fw)
3280 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3281
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003282 /* Setup driver private area. */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003283 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003284 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003285 mwl8k_vif->vif = vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003286 mwl8k_vif->seqno = 0;
3287
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003288 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003289
3290 return 0;
3291}
3292
3293static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003294 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003295{
3296 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003297 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003298
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003299 if (priv->ap_fw)
3300 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3301
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003302 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003303
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003304 list_del(&mwl8k_vif->list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003305}
3306
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003307static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003308{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003309 struct ieee80211_conf *conf = &hw->conf;
3310 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003311 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003312
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003313 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003314 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003315 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003316 }
3317
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003318 rc = mwl8k_fw_lock(hw);
3319 if (rc)
3320 return rc;
3321
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003322 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003323 if (rc)
3324 goto out;
3325
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003326 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003327 if (rc)
3328 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003329
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003330 if (conf->power_level > 18)
3331 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003332 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003333 if (rc)
3334 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003335
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003336 if (priv->ap_fw) {
3337 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3338 if (!rc)
3339 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3340 } else {
3341 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3342 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003343
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003344out:
3345 mwl8k_fw_unlock(hw);
3346
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003347 return rc;
3348}
3349
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003350static void
3351mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3352 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003353{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003354 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003355 u32 ap_legacy_rates;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003356 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003357 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003358
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003359 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003360 return;
3361
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003362 /*
3363 * No need to capture a beacon if we're no longer associated.
3364 */
3365 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3366 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003367
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003368 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003369 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003370 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003371 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003372 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003373
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003374 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003375
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003376 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003377 if (ap == NULL) {
3378 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003379 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003380 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003381
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003382 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
3383 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3384 } else {
3385 ap_legacy_rates =
3386 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3387 }
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003388 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003389
3390 rcu_read_unlock();
3391 }
3392
3393 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003394 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003395 if (rc)
3396 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003397
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003398 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003399 if (rc)
3400 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003401 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003402
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003403 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003404 rc = mwl8k_set_radio_preamble(hw,
3405 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003406 if (rc)
3407 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003408 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003409
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003410 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003411 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003412 if (rc)
3413 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003414 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003415
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003416 if (vif->bss_conf.assoc &&
3417 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3418 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003419 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003420 if (rc)
3421 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003422 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003423
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003424 if (vif->bss_conf.assoc &&
3425 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003426 /*
3427 * Finalize the join. Tell rx handler to process
3428 * next beacon from our BSSID.
3429 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003430 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003431 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003432 }
3433
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003434out:
3435 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003436}
3437
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003438static void
3439mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3440 struct ieee80211_bss_conf *info, u32 changed)
3441{
3442 int rc;
3443
3444 if (mwl8k_fw_lock(hw))
3445 return;
3446
3447 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3448 rc = mwl8k_set_radio_preamble(hw,
3449 vif->bss_conf.use_short_preamble);
3450 if (rc)
3451 goto out;
3452 }
3453
3454 if (changed & BSS_CHANGED_BASIC_RATES) {
3455 int idx;
3456 int rate;
3457
3458 /*
3459 * Use lowest supported basic rate for multicasts
3460 * and management frames (such as probe responses --
3461 * beacons will always go out at 1 Mb/s).
3462 */
3463 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003464 if (idx)
3465 idx--;
3466
3467 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3468 rate = mwl8k_rates_24[idx].hw_value;
3469 else
3470 rate = mwl8k_rates_50[idx].hw_value;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003471
3472 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3473 }
3474
3475 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3476 struct sk_buff *skb;
3477
3478 skb = ieee80211_beacon_get(hw, vif);
3479 if (skb != NULL) {
3480 mwl8k_cmd_set_beacon(hw, skb->data, skb->len);
3481 kfree_skb(skb);
3482 }
3483 }
3484
3485 if (changed & BSS_CHANGED_BEACON_ENABLED)
3486 mwl8k_cmd_bss_start(hw, info->enable_beacon);
3487
3488out:
3489 mwl8k_fw_unlock(hw);
3490}
3491
3492static void
3493mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3494 struct ieee80211_bss_conf *info, u32 changed)
3495{
3496 struct mwl8k_priv *priv = hw->priv;
3497
3498 if (!priv->ap_fw)
3499 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3500 else
3501 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3502}
3503
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003504static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3505 int mc_count, struct dev_addr_list *mclist)
3506{
3507 struct mwl8k_cmd_pkt *cmd;
3508
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003509 /*
3510 * Synthesize and return a command packet that programs the
3511 * hardware multicast address filter. At this point we don't
3512 * know whether FIF_ALLMULTI is being requested, but if it is,
3513 * we'll end up throwing this packet away and creating a new
3514 * one in mwl8k_configure_filter().
3515 */
3516 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003517
3518 return (unsigned long)cmd;
3519}
3520
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003521static int
3522mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3523 unsigned int changed_flags,
3524 unsigned int *total_flags)
3525{
3526 struct mwl8k_priv *priv = hw->priv;
3527
3528 /*
3529 * Hardware sniffer mode is mutually exclusive with STA
3530 * operation, so refuse to enable sniffer mode if a STA
3531 * interface is active.
3532 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003533 if (!list_empty(&priv->vif_list)) {
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003534 if (net_ratelimit())
3535 printk(KERN_INFO "%s: not enabling sniffer "
3536 "mode because STA interface is active\n",
3537 wiphy_name(hw->wiphy));
3538 return 0;
3539 }
3540
3541 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003542 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003543 return 0;
3544 priv->sniffer_enabled = true;
3545 }
3546
3547 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3548 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3549 FIF_OTHER_BSS;
3550
3551 return 1;
3552}
3553
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003554static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
3555{
3556 if (!list_empty(&priv->vif_list))
3557 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
3558
3559 return NULL;
3560}
3561
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003562static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3563 unsigned int changed_flags,
3564 unsigned int *total_flags,
3565 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003566{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003567 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003568 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3569
3570 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003571 * AP firmware doesn't allow fine-grained control over
3572 * the receive filter.
3573 */
3574 if (priv->ap_fw) {
3575 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3576 kfree(cmd);
3577 return;
3578 }
3579
3580 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003581 * Enable hardware sniffer mode if FIF_CONTROL or
3582 * FIF_OTHER_BSS is requested.
3583 */
3584 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3585 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3586 kfree(cmd);
3587 return;
3588 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003589
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003590 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003591 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003592
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003593 if (mwl8k_fw_lock(hw)) {
3594 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003595 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003596 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003597
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003598 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003599 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003600 priv->sniffer_enabled = false;
3601 }
3602
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003603 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003604 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3605 /*
3606 * Disable the BSS filter.
3607 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003608 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003609 } else {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003610 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003611 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003612
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003613 /*
3614 * Enable the BSS filter.
3615 *
3616 * If there is an active STA interface, use that
3617 * interface's BSSID, otherwise use a dummy one
3618 * (where the OUI part needs to be nonzero for
3619 * the BSSID to be accepted by POST_SCAN).
3620 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003621 mwl8k_vif = mwl8k_first_vif(priv);
3622 if (mwl8k_vif != NULL)
3623 bssid = mwl8k_vif->vif->bss_conf.bssid;
3624 else
3625 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003626
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003627 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003628 }
3629 }
3630
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003631 /*
3632 * If FIF_ALLMULTI is being requested, throw away the command
3633 * packet that ->prepare_multicast() built and replace it with
3634 * a command packet that enables reception of all multicast
3635 * packets.
3636 */
3637 if (*total_flags & FIF_ALLMULTI) {
3638 kfree(cmd);
3639 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3640 }
3641
3642 if (cmd != NULL) {
3643 mwl8k_post_cmd(hw, cmd);
3644 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003645 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003646
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003647 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003648}
3649
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003650static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3651{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003652 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003653}
3654
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003655struct mwl8k_sta_notify_item
3656{
3657 struct list_head list;
3658 struct ieee80211_vif *vif;
3659 enum sta_notify_cmd cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003660 struct ieee80211_sta sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003661};
3662
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003663static void
3664mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3665{
3666 struct mwl8k_priv *priv = hw->priv;
3667
3668 /*
3669 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3670 */
3671 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3672 int rc;
3673
3674 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3675 if (rc >= 0) {
3676 struct ieee80211_sta *sta;
3677
3678 rcu_read_lock();
3679 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3680 if (sta != NULL)
3681 MWL8K_STA(sta)->peer_id = rc;
3682 rcu_read_unlock();
3683 }
3684 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3685 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3686 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3687 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3688 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3689 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3690 }
3691}
3692
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003693static void mwl8k_sta_notify_worker(struct work_struct *work)
3694{
3695 struct mwl8k_priv *priv =
3696 container_of(work, struct mwl8k_priv, sta_notify_worker);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003697 struct ieee80211_hw *hw = priv->hw;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003698
3699 spin_lock_bh(&priv->sta_notify_list_lock);
3700 while (!list_empty(&priv->sta_notify_list)) {
3701 struct mwl8k_sta_notify_item *s;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003702
3703 s = list_entry(priv->sta_notify_list.next,
3704 struct mwl8k_sta_notify_item, list);
3705 list_del(&s->list);
3706
3707 spin_unlock_bh(&priv->sta_notify_list_lock);
3708
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003709 mwl8k_do_sta_notify(hw, s);
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003710 kfree(s);
3711
3712 spin_lock_bh(&priv->sta_notify_list_lock);
3713 }
3714 spin_unlock_bh(&priv->sta_notify_list_lock);
3715}
3716
3717static void
3718mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3719 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3720{
3721 struct mwl8k_priv *priv = hw->priv;
3722 struct mwl8k_sta_notify_item *s;
3723
3724 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3725 return;
3726
3727 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3728 if (s != NULL) {
3729 s->vif = vif;
3730 s->cmd = cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003731 s->sta = *sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003732
3733 spin_lock(&priv->sta_notify_list_lock);
3734 list_add_tail(&s->list, &priv->sta_notify_list);
3735 spin_unlock(&priv->sta_notify_list_lock);
3736
3737 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3738 }
3739}
3740
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003741static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3742 const struct ieee80211_tx_queue_params *params)
3743{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003744 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003745 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003746
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003747 rc = mwl8k_fw_lock(hw);
3748 if (!rc) {
3749 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003750 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003751
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003752 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003753 rc = mwl8k_cmd_set_edca_params(hw, queue,
3754 params->cw_min,
3755 params->cw_max,
3756 params->aifs,
3757 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003758
3759 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003760 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003761
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003762 return rc;
3763}
3764
3765static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3766 struct ieee80211_tx_queue_stats *stats)
3767{
3768 struct mwl8k_priv *priv = hw->priv;
3769 struct mwl8k_tx_queue *txq;
3770 int index;
3771
3772 spin_lock_bh(&priv->tx_lock);
3773 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3774 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003775 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003776 sizeof(struct ieee80211_tx_queue_stats));
3777 }
3778 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003779
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003780 return 0;
3781}
3782
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003783static int mwl8k_get_stats(struct ieee80211_hw *hw,
3784 struct ieee80211_low_level_stats *stats)
3785{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003786 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003787}
3788
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003789static int
3790mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3791 enum ieee80211_ampdu_mlme_action action,
3792 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3793{
3794 switch (action) {
3795 case IEEE80211_AMPDU_RX_START:
3796 case IEEE80211_AMPDU_RX_STOP:
3797 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3798 return -ENOTSUPP;
3799 return 0;
3800 default:
3801 return -ENOTSUPP;
3802 }
3803}
3804
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003805static const struct ieee80211_ops mwl8k_ops = {
3806 .tx = mwl8k_tx,
3807 .start = mwl8k_start,
3808 .stop = mwl8k_stop,
3809 .add_interface = mwl8k_add_interface,
3810 .remove_interface = mwl8k_remove_interface,
3811 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003812 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003813 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003814 .configure_filter = mwl8k_configure_filter,
3815 .set_rts_threshold = mwl8k_set_rts_threshold,
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003816 .sta_notify = mwl8k_sta_notify,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003817 .conf_tx = mwl8k_conf_tx,
3818 .get_tx_stats = mwl8k_get_tx_stats,
3819 .get_stats = mwl8k_get_stats,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003820 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003821};
3822
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003823static void mwl8k_finalize_join_worker(struct work_struct *work)
3824{
3825 struct mwl8k_priv *priv =
3826 container_of(work, struct mwl8k_priv, finalize_join_worker);
3827 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003828 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003829
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003830 mwl8k_vif = mwl8k_first_vif(priv);
3831 if (mwl8k_vif != NULL)
3832 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len,
3833 mwl8k_vif->vif->bss_conf.dtim_period);
3834
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003835 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003836 priv->beacon_skb = NULL;
3837}
3838
John W. Linvillebcb628d2009-11-06 16:40:16 -05003839enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003840 MWL8363 = 0,
3841 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003842 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003843};
3844
John W. Linvillebcb628d2009-11-06 16:40:16 -05003845static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003846 [MWL8363] = {
3847 .part_name = "88w8363",
3848 .helper_image = "mwl8k/helper_8363.fw",
3849 .fw_image = "mwl8k/fmimage_8363.fw",
3850 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003851 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003852 .part_name = "88w8687",
3853 .helper_image = "mwl8k/helper_8687.fw",
3854 .fw_image = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05003855 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003856 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003857 .part_name = "88w8366",
3858 .helper_image = "mwl8k/helper_8366.fw",
3859 .fw_image = "mwl8k/fmimage_8366.fw",
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003860 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003861 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003862};
3863
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01003864MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3865MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3866MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3867MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3868MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3869MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3870
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003871static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003872 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3873 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003874 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3875 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3876 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01003877 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003878 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003879};
3880MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3881
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003882static int __devinit mwl8k_probe(struct pci_dev *pdev,
3883 const struct pci_device_id *id)
3884{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003885 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003886 struct ieee80211_hw *hw;
3887 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003888 int rc;
3889 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003890
3891 if (!printed_version) {
3892 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3893 printed_version = 1;
3894 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003895
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003896
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003897 rc = pci_enable_device(pdev);
3898 if (rc) {
3899 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3900 MWL8K_NAME);
3901 return rc;
3902 }
3903
3904 rc = pci_request_regions(pdev, MWL8K_NAME);
3905 if (rc) {
3906 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3907 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003908 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003909 }
3910
3911 pci_set_master(pdev);
3912
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003913
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003914 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3915 if (hw == NULL) {
3916 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3917 rc = -ENOMEM;
3918 goto err_free_reg;
3919 }
3920
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003921 SET_IEEE80211_DEV(hw, &pdev->dev);
3922 pci_set_drvdata(pdev, hw);
3923
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003924 priv = hw->priv;
3925 priv->hw = hw;
3926 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003927 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003928
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003929
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003930 priv->sram = pci_iomap(pdev, 0, 0x10000);
3931 if (priv->sram == NULL) {
3932 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003933 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003934 goto err_iounmap;
3935 }
3936
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003937 /*
3938 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3939 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3940 */
3941 priv->regs = pci_iomap(pdev, 1, 0x10000);
3942 if (priv->regs == NULL) {
3943 priv->regs = pci_iomap(pdev, 2, 0x10000);
3944 if (priv->regs == NULL) {
3945 printk(KERN_ERR "%s: Cannot map device registers\n",
3946 wiphy_name(hw->wiphy));
3947 goto err_iounmap;
3948 }
3949 }
3950
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003951
3952 /* Reset firmware and hardware */
3953 mwl8k_hw_reset(priv);
3954
3955 /* Ask userland hotplug daemon for the device firmware */
3956 rc = mwl8k_request_firmware(priv);
3957 if (rc) {
3958 printk(KERN_ERR "%s: Firmware files not found\n",
3959 wiphy_name(hw->wiphy));
3960 goto err_stop_firmware;
3961 }
3962
3963 /* Load firmware into hardware */
3964 rc = mwl8k_load_firmware(hw);
3965 if (rc) {
3966 printk(KERN_ERR "%s: Cannot start firmware\n",
3967 wiphy_name(hw->wiphy));
3968 goto err_stop_firmware;
3969 }
3970
3971 /* Reclaim memory once firmware is successfully loaded */
3972 mwl8k_release_firmware(priv);
3973
3974
Lennert Buytenhek91942232010-01-04 21:53:54 +01003975 if (priv->ap_fw) {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003976 priv->rxd_ops = priv->device_info->ap_rxd_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003977 if (priv->rxd_ops == NULL) {
3978 printk(KERN_ERR "%s: Driver does not have AP "
3979 "firmware image support for this hardware\n",
3980 wiphy_name(hw->wiphy));
3981 goto err_stop_firmware;
3982 }
3983 } else {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003984 priv->rxd_ops = &rxd_sta_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003985 }
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003986
3987 priv->sniffer_enabled = false;
3988 priv->wmm_enabled = false;
3989 priv->pending_tx_pkts = 0;
3990
3991
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003992 /*
3993 * Extra headroom is the size of the required DMA header
3994 * minus the size of the smallest 802.11 frame (CTS frame).
3995 */
3996 hw->extra_tx_headroom =
3997 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3998
3999 hw->channel_change_time = 10;
4000
4001 hw->queues = MWL8K_TX_QUEUES;
4002
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004003 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02004004 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004005 hw->vif_data_size = sizeof(struct mwl8k_vif);
Lennert Buytenheka6804002010-01-04 21:55:42 +01004006 hw->sta_data_size = sizeof(struct mwl8k_sta);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01004007
4008 INIT_LIST_HEAD(&priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004009
4010 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02004011 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02004012 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004013
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01004014 /* Station database handling */
4015 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
4016 spin_lock_init(&priv->sta_notify_list_lock);
4017 INIT_LIST_HEAD(&priv->sta_notify_list);
4018
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004019 /* Finalize join worker */
4020 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
4021
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004022 /* TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004023 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
4024 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004025 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
4026 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004027
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004028 /* Power management cookie */
4029 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
4030 if (priv->cookie == NULL)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004031 goto err_stop_firmware;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004032
4033 rc = mwl8k_rxq_init(hw, 0);
4034 if (rc)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004035 goto err_free_cookie;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004036 rxq_refill(hw, 0, INT_MAX);
4037
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004038 mutex_init(&priv->fw_mutex);
4039 priv->fw_mutex_owner = NULL;
4040 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004041 priv->hostcmd_wait = NULL;
4042
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004043 spin_lock_init(&priv->tx_lock);
4044
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02004045 priv->tx_wait = NULL;
4046
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004047 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
4048 rc = mwl8k_txq_init(hw, i);
4049 if (rc)
4050 goto err_free_queues;
4051 }
4052
4053 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004054 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004055 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004056 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004057 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4058
Joe Perchesa0607fd2009-11-18 23:29:17 -08004059 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004060 IRQF_SHARED, MWL8K_NAME, hw);
4061 if (rc) {
4062 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004063 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004064 goto err_free_queues;
4065 }
4066
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004067 /*
4068 * Temporarily enable interrupts. Initial firmware host
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01004069 * commands use interrupts and avoid polling. Disable
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004070 * interrupts when done.
4071 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004072 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004073
4074 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004075 if (priv->ap_fw) {
4076 rc = mwl8k_cmd_get_hw_spec_ap(hw);
4077 if (!rc)
4078 rc = mwl8k_cmd_set_hw_spec(hw);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004079
4080 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_AP);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004081 } else {
4082 rc = mwl8k_cmd_get_hw_spec_sta(hw);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01004083
4084 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004085 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004086 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004087 printk(KERN_ERR "%s: Cannot initialise firmware\n",
4088 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004089 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004090 }
4091
4092 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004093 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004094 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004095 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004096 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004097 }
4098
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004099 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004100 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004101 if (rc) {
4102 printk(KERN_ERR "%s: Cannot clear MAC address\n",
4103 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004104 goto err_free_irq;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004105 }
4106
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004107 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004108 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004109 free_irq(priv->pdev->irq, hw);
4110
4111 rc = ieee80211_register_hw(hw);
4112 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004113 printk(KERN_ERR "%s: Cannot register device\n",
4114 wiphy_name(hw->wiphy));
Lennert Buytenhek153458f2010-01-04 21:54:08 +01004115 goto err_free_queues;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004116 }
4117
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02004118 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02004119 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004120 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02004121 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02004122 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4123 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004124
4125 return 0;
4126
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004127err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004128 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004129 free_irq(priv->pdev->irq, hw);
4130
4131err_free_queues:
4132 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4133 mwl8k_txq_deinit(hw, i);
4134 mwl8k_rxq_deinit(hw, 0);
4135
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004136err_free_cookie:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004137 if (priv->cookie != NULL)
4138 pci_free_consistent(priv->pdev, 4,
4139 priv->cookie, priv->cookie_dma);
4140
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004141err_stop_firmware:
4142 mwl8k_hw_reset(priv);
4143 mwl8k_release_firmware(priv);
4144
4145err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004146 if (priv->regs != NULL)
4147 pci_iounmap(pdev, priv->regs);
4148
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004149 if (priv->sram != NULL)
4150 pci_iounmap(pdev, priv->sram);
4151
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004152 pci_set_drvdata(pdev, NULL);
4153 ieee80211_free_hw(hw);
4154
4155err_free_reg:
4156 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004157
4158err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004159 pci_disable_device(pdev);
4160
4161 return rc;
4162}
4163
Joerg Albert230f7af2009-04-18 02:10:45 +02004164static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004165{
4166 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4167}
4168
Joerg Albert230f7af2009-04-18 02:10:45 +02004169static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004170{
4171 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4172 struct mwl8k_priv *priv;
4173 int i;
4174
4175 if (hw == NULL)
4176 return;
4177 priv = hw->priv;
4178
4179 ieee80211_stop_queues(hw);
4180
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02004181 ieee80211_unregister_hw(hw);
4182
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004183 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004184 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004185 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004186
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004187 /* Stop hardware */
4188 mwl8k_hw_reset(priv);
4189
4190 /* Return all skbs to mac80211 */
4191 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004192 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004193
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004194 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4195 mwl8k_txq_deinit(hw, i);
4196
4197 mwl8k_rxq_deinit(hw, 0);
4198
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004199 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004200
4201 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004202 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004203 pci_set_drvdata(pdev, NULL);
4204 ieee80211_free_hw(hw);
4205 pci_release_regions(pdev);
4206 pci_disable_device(pdev);
4207}
4208
4209static struct pci_driver mwl8k_driver = {
4210 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004211 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004212 .probe = mwl8k_probe,
4213 .remove = __devexit_p(mwl8k_remove),
4214 .shutdown = __devexit_p(mwl8k_shutdown),
4215};
4216
4217static int __init mwl8k_init(void)
4218{
4219 return pci_register_driver(&mwl8k_driver);
4220}
4221
4222static void __exit mwl8k_exit(void)
4223{
4224 pci_unregister_driver(&mwl8k_driver);
4225}
4226
4227module_init(mwl8k_init);
4228module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004229
4230MODULE_DESCRIPTION(MWL8K_DESC);
4231MODULE_VERSION(MWL8K_VERSION);
4232MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4233MODULE_LICENSE("GPL");