blob: 13dded49323e84bd8ce1ad45a391afdeb3b02560 [file] [log] [blame]
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004 *
Lennert Buytenheka145d572009-08-18 04:34:26 +02005 * Copyright (C) 2008-2009 Marvell Semiconductor Inc.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/kernel.h>
Lennert Buytenhek3d76e822009-10-22 20:20:16 +020015#include <linux/sched.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010016#include <linux/spinlock.h>
17#include <linux/list.h>
18#include <linux/pci.h>
19#include <linux/delay.h>
20#include <linux/completion.h>
21#include <linux/etherdevice.h>
22#include <net/mac80211.h>
23#include <linux/moduleparam.h>
24#include <linux/firmware.h>
25#include <linux/workqueue.h>
26
27#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
28#define MWL8K_NAME KBUILD_MODNAME
Lennert Buytenhek6976b662010-01-02 10:31:50 +010029#define MWL8K_VERSION "0.11"
Lennert Buytenheka66098d2009-03-10 10:13:33 +010030
Lennert Buytenheka66098d2009-03-10 10:13:33 +010031/* Register definitions */
32#define MWL8K_HIU_GEN_PTR 0x00000c10
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020033#define MWL8K_MODE_STA 0x0000005a
34#define MWL8K_MODE_AP 0x000000a5
Lennert Buytenheka66098d2009-03-10 10:13:33 +010035#define MWL8K_HIU_INT_CODE 0x00000c14
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020036#define MWL8K_FWSTA_READY 0xf0f1f2f4
37#define MWL8K_FWAP_READY 0xf1f2f4a5
38#define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
Lennert Buytenheka66098d2009-03-10 10:13:33 +010039#define MWL8K_HIU_SCRATCH 0x00000c40
40
41/* Host->device communications */
42#define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
43#define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
44#define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
45#define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
46#define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020047#define MWL8K_H2A_INT_DUMMY (1 << 20)
48#define MWL8K_H2A_INT_RESET (1 << 15)
49#define MWL8K_H2A_INT_DOORBELL (1 << 1)
50#define MWL8K_H2A_INT_PPA_READY (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010051
52/* Device->host communications */
53#define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
54#define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
55#define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
56#define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
57#define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020058#define MWL8K_A2H_INT_DUMMY (1 << 20)
59#define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
60#define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
61#define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
62#define MWL8K_A2H_INT_RADIO_ON (1 << 6)
63#define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
64#define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
65#define MWL8K_A2H_INT_OPC_DONE (1 << 2)
66#define MWL8K_A2H_INT_RX_READY (1 << 1)
67#define MWL8K_A2H_INT_TX_DONE (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010068
69#define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
70 MWL8K_A2H_INT_CHNL_SWITCHED | \
71 MWL8K_A2H_INT_QUEUE_EMPTY | \
72 MWL8K_A2H_INT_RADAR_DETECT | \
73 MWL8K_A2H_INT_RADIO_ON | \
74 MWL8K_A2H_INT_RADIO_OFF | \
75 MWL8K_A2H_INT_MAC_EVENT | \
76 MWL8K_A2H_INT_OPC_DONE | \
77 MWL8K_A2H_INT_RX_READY | \
78 MWL8K_A2H_INT_TX_DONE)
79
Lennert Buytenheka66098d2009-03-10 10:13:33 +010080#define MWL8K_RX_QUEUES 1
81#define MWL8K_TX_QUEUES 4
82
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020083struct rxd_ops {
84 int rxd_size;
85 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
86 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +010087 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
88 __le16 *qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020089};
90
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020091struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +020092 char *part_name;
93 char *helper_image;
94 char *fw_image;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +010095 struct rxd_ops *ap_rxd_ops;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020096};
97
Lennert Buytenheka66098d2009-03-10 10:13:33 +010098struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020099 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100100
101 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200102 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100103
104 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200105 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100106
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200107 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200108 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200109 struct {
110 struct sk_buff *skb;
111 DECLARE_PCI_UNMAP_ADDR(dma)
112 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100113};
114
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100115struct mwl8k_tx_queue {
116 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200117 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100118
119 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200120 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100121
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200122 struct ieee80211_tx_queue_stats stats;
123 struct mwl8k_tx_desc *txd;
124 dma_addr_t txd_dma;
125 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100126};
127
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100128struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100129 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100130 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200132 struct mwl8k_device_info *device_info;
133
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100134 void __iomem *sram;
135 void __iomem *regs;
136
137 /* firmware */
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100138 struct firmware *fw_helper;
139 struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100140
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100141 /* hardware/firmware parameters */
142 bool ap_fw;
143 struct rxd_ops *rxd_ops;
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100144 struct ieee80211_supported_band band_24;
145 struct ieee80211_channel channels_24[14];
146 struct ieee80211_rate rates_24[14];
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100147 struct ieee80211_supported_band band_50;
148 struct ieee80211_channel channels_50[4];
149 struct ieee80211_rate rates_50[9];
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100150
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200151 /* firmware access */
152 struct mutex fw_mutex;
153 struct task_struct *fw_mutex_owner;
154 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200155 struct completion *hostcmd_wait;
156
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100157 /* lock held over TX and TX reap */
158 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100159
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200160 /* TX quiesce completion, protected by fw_mutex and tx_lock */
161 struct completion *tx_wait;
162
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100163 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100164
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100165 /* power management status cookie from firmware */
166 u32 *cookie;
167 dma_addr_t cookie_dma;
168
169 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100170 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200171 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100172
173 /*
174 * Running count of TX packets in flight, to avoid
175 * iterating over the transmit rings each time.
176 */
177 int pending_tx_pkts;
178
179 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
180 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
181
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200182 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200183 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200184 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200185 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100186
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +0100187 struct work_struct sta_notify_worker;
188 spinlock_t sta_notify_list_lock;
189 struct list_head sta_notify_list;
190
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100191 /* XXX need to convert this to handle multiple interfaces */
192 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200193 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100194 struct sk_buff *beacon_skb;
195
196 /*
197 * This FJ worker has to be global as it is scheduled from the
198 * RX handler. At this point we don't know which interface it
199 * belongs to until the list of bssids waiting to complete join
200 * is checked.
201 */
202 struct work_struct finalize_join_worker;
203
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100204 /* Tasklet to perform TX reclaim. */
205 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100206
207 /* Tasklet to perform RX. */
208 struct tasklet_struct poll_rx_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100209};
210
211/* Per interface specific private data */
212struct mwl8k_vif {
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100213 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100214 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100215};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200216#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100217
Lennert Buytenheka6804002010-01-04 21:55:42 +0100218struct mwl8k_sta {
219 /* Index into station database. Returned by UPDATE_STADB. */
220 u8 peer_id;
221};
222#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
223
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100224static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100225 { .center_freq = 2412, .hw_value = 1, },
226 { .center_freq = 2417, .hw_value = 2, },
227 { .center_freq = 2422, .hw_value = 3, },
228 { .center_freq = 2427, .hw_value = 4, },
229 { .center_freq = 2432, .hw_value = 5, },
230 { .center_freq = 2437, .hw_value = 6, },
231 { .center_freq = 2442, .hw_value = 7, },
232 { .center_freq = 2447, .hw_value = 8, },
233 { .center_freq = 2452, .hw_value = 9, },
234 { .center_freq = 2457, .hw_value = 10, },
235 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100236 { .center_freq = 2467, .hw_value = 12, },
237 { .center_freq = 2472, .hw_value = 13, },
238 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100239};
240
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100241static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100242 { .bitrate = 10, .hw_value = 2, },
243 { .bitrate = 20, .hw_value = 4, },
244 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200245 { .bitrate = 110, .hw_value = 22, },
246 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100247 { .bitrate = 60, .hw_value = 12, },
248 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100249 { .bitrate = 120, .hw_value = 24, },
250 { .bitrate = 180, .hw_value = 36, },
251 { .bitrate = 240, .hw_value = 48, },
252 { .bitrate = 360, .hw_value = 72, },
253 { .bitrate = 480, .hw_value = 96, },
254 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100255 { .bitrate = 720, .hw_value = 144, },
256};
257
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100258static const struct ieee80211_channel mwl8k_channels_50[] = {
259 { .center_freq = 5180, .hw_value = 36, },
260 { .center_freq = 5200, .hw_value = 40, },
261 { .center_freq = 5220, .hw_value = 44, },
262 { .center_freq = 5240, .hw_value = 48, },
263};
264
265static const struct ieee80211_rate mwl8k_rates_50[] = {
266 { .bitrate = 60, .hw_value = 12, },
267 { .bitrate = 90, .hw_value = 18, },
268 { .bitrate = 120, .hw_value = 24, },
269 { .bitrate = 180, .hw_value = 36, },
270 { .bitrate = 240, .hw_value = 48, },
271 { .bitrate = 360, .hw_value = 72, },
272 { .bitrate = 480, .hw_value = 96, },
273 { .bitrate = 540, .hw_value = 108, },
274 { .bitrate = 720, .hw_value = 144, },
275};
276
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100277/* Set or get info from Firmware */
278#define MWL8K_CMD_SET 0x0001
279#define MWL8K_CMD_GET 0x0000
280
281/* Firmware command codes */
282#define MWL8K_CMD_CODE_DNLD 0x0001
283#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200284#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100285#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
286#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200287#define MWL8K_CMD_RADIO_CONTROL 0x001c
288#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200289#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100290#define MWL8K_CMD_SET_BEACON 0x0100
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100291#define MWL8K_CMD_SET_PRE_SCAN 0x0107
292#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200293#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100294#define MWL8K_CMD_SET_AID 0x010d
295#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200296#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100297#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200298#define MWL8K_CMD_SET_SLOT 0x0114
299#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
300#define MWL8K_CMD_SET_WMM_MODE 0x0123
301#define MWL8K_CMD_MIMO_CONFIG 0x0125
302#define MWL8K_CMD_USE_FIXED_RATE 0x0126
303#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200304#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200305#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100306#define MWL8K_CMD_BSS_START 0x1100
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100307#define MWL8K_CMD_SET_NEW_STN 0x1111
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200308#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100309
310static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
311{
312#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
313 snprintf(buf, bufsize, "%s", #x);\
314 return buf;\
315 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200316 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100317 MWL8K_CMDNAME(CODE_DNLD);
318 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200319 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100320 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
321 MWL8K_CMDNAME(GET_STAT);
322 MWL8K_CMDNAME(RADIO_CONTROL);
323 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200324 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100325 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100326 MWL8K_CMDNAME(SET_PRE_SCAN);
327 MWL8K_CMDNAME(SET_POST_SCAN);
328 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100329 MWL8K_CMDNAME(SET_AID);
330 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200331 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100332 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200333 MWL8K_CMDNAME(SET_SLOT);
334 MWL8K_CMDNAME(SET_EDCA_PARAMS);
335 MWL8K_CMDNAME(SET_WMM_MODE);
336 MWL8K_CMDNAME(MIMO_CONFIG);
337 MWL8K_CMDNAME(USE_FIXED_RATE);
338 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200339 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200340 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100341 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100342 MWL8K_CMDNAME(SET_NEW_STN);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200343 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100344 default:
345 snprintf(buf, bufsize, "0x%x", cmd);
346 }
347#undef MWL8K_CMDNAME
348
349 return buf;
350}
351
352/* Hardware and firmware reset */
353static void mwl8k_hw_reset(struct mwl8k_priv *priv)
354{
355 iowrite32(MWL8K_H2A_INT_RESET,
356 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
357 iowrite32(MWL8K_H2A_INT_RESET,
358 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
359 msleep(20);
360}
361
362/* Release fw image */
363static void mwl8k_release_fw(struct firmware **fw)
364{
365 if (*fw == NULL)
366 return;
367 release_firmware(*fw);
368 *fw = NULL;
369}
370
371static void mwl8k_release_firmware(struct mwl8k_priv *priv)
372{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100373 mwl8k_release_fw(&priv->fw_ucode);
374 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100375}
376
377/* Request fw image */
378static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200379 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100380{
381 /* release current image */
382 if (*fw != NULL)
383 mwl8k_release_fw(fw);
384
385 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200386 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100387}
388
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200389static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100390{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200391 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100392 int rc;
393
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200394 if (di->helper_image != NULL) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100395 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200396 if (rc) {
397 printk(KERN_ERR "%s: Error requesting helper "
398 "firmware file %s\n", pci_name(priv->pdev),
399 di->helper_image);
400 return rc;
401 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100402 }
403
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100404 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100405 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200406 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200407 pci_name(priv->pdev), di->fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100408 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100409 return rc;
410 }
411
412 return 0;
413}
414
415struct mwl8k_cmd_pkt {
416 __le16 code;
417 __le16 length;
418 __le16 seq_num;
419 __le16 result;
420 char payload[0];
421} __attribute__((packed));
422
423/*
424 * Firmware loading.
425 */
426static int
427mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
428{
429 void __iomem *regs = priv->regs;
430 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100431 int loops;
432
433 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
434 if (pci_dma_mapping_error(priv->pdev, dma_addr))
435 return -ENOMEM;
436
437 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
438 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
439 iowrite32(MWL8K_H2A_INT_DOORBELL,
440 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
441 iowrite32(MWL8K_H2A_INT_DUMMY,
442 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
443
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100444 loops = 1000;
445 do {
446 u32 int_code;
447
448 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
449 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
450 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100451 break;
452 }
453
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200454 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100455 udelay(1);
456 } while (--loops);
457
458 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
459
Lennert Buytenhekd4b70572009-07-16 12:44:45 +0200460 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100461}
462
463static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
464 const u8 *data, size_t length)
465{
466 struct mwl8k_cmd_pkt *cmd;
467 int done;
468 int rc = 0;
469
470 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
471 if (cmd == NULL)
472 return -ENOMEM;
473
474 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
475 cmd->seq_num = 0;
476 cmd->result = 0;
477
478 done = 0;
479 while (length) {
480 int block_size = length > 256 ? 256 : length;
481
482 memcpy(cmd->payload, data + done, block_size);
483 cmd->length = cpu_to_le16(block_size);
484
485 rc = mwl8k_send_fw_load_cmd(priv, cmd,
486 sizeof(*cmd) + block_size);
487 if (rc)
488 break;
489
490 done += block_size;
491 length -= block_size;
492 }
493
494 if (!rc) {
495 cmd->length = 0;
496 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
497 }
498
499 kfree(cmd);
500
501 return rc;
502}
503
504static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
505 const u8 *data, size_t length)
506{
507 unsigned char *buffer;
508 int may_continue, rc = 0;
509 u32 done, prev_block_size;
510
511 buffer = kmalloc(1024, GFP_KERNEL);
512 if (buffer == NULL)
513 return -ENOMEM;
514
515 done = 0;
516 prev_block_size = 0;
517 may_continue = 1000;
518 while (may_continue > 0) {
519 u32 block_size;
520
521 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
522 if (block_size & 1) {
523 block_size &= ~1;
524 may_continue--;
525 } else {
526 done += prev_block_size;
527 length -= prev_block_size;
528 }
529
530 if (block_size > 1024 || block_size > length) {
531 rc = -EOVERFLOW;
532 break;
533 }
534
535 if (length == 0) {
536 rc = 0;
537 break;
538 }
539
540 if (block_size == 0) {
541 rc = -EPROTO;
542 may_continue--;
543 udelay(1);
544 continue;
545 }
546
547 prev_block_size = block_size;
548 memcpy(buffer, data + done, block_size);
549
550 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
551 if (rc)
552 break;
553 }
554
555 if (!rc && length != 0)
556 rc = -EREMOTEIO;
557
558 kfree(buffer);
559
560 return rc;
561}
562
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200563static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100564{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200565 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100566 struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200567 int rc;
568 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100569
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200570 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100571 struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100572
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200573 if (helper == NULL) {
574 printk(KERN_ERR "%s: helper image needed but none "
575 "given\n", pci_name(priv->pdev));
576 return -EINVAL;
577 }
578
579 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100580 if (rc) {
581 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200582 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100583 return rc;
584 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100585 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100586
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200587 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100588 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200589 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100590 }
591
592 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200593 printk(KERN_ERR "%s: unable to load firmware image\n",
594 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100595 return rc;
596 }
597
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100598 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100599
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100600 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100601 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200602 u32 ready_code;
603
604 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
605 if (ready_code == MWL8K_FWAP_READY) {
606 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100607 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200608 } else if (ready_code == MWL8K_FWSTA_READY) {
609 priv->ap_fw = 0;
610 break;
611 }
612
613 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100614 udelay(1);
615 } while (--loops);
616
617 return loops ? 0 : -ETIMEDOUT;
618}
619
620
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100621/* DMA header used by firmware and hardware. */
622struct mwl8k_dma_data {
623 __le16 fwlen;
624 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100625 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100626} __attribute__((packed));
627
628/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100629static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100630{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100631 struct mwl8k_dma_data *tr;
632 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100633
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100634 tr = (struct mwl8k_dma_data *)skb->data;
635 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
636
637 if (hdrlen != sizeof(tr->wh)) {
638 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
639 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
640 *((__le16 *)(tr->data - 2)) = qos;
641 } else {
642 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
643 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100644 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100645
646 if (hdrlen != sizeof(*tr))
647 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100648}
649
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200650static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100651{
652 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100653 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100654 struct mwl8k_dma_data *tr;
655
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100656 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100657 * Add a firmware DMA header; the firmware requires that we
658 * present a 2-byte payload length followed by a 4-address
659 * header (without QoS field), followed (optionally) by any
660 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100661 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100662 wh = (struct ieee80211_hdr *)skb->data;
663
664 hdrlen = ieee80211_hdrlen(wh->frame_control);
665 if (hdrlen != sizeof(*tr))
666 skb_push(skb, sizeof(*tr) - hdrlen);
667
668 if (ieee80211_is_data_qos(wh->frame_control))
669 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100670
671 tr = (struct mwl8k_dma_data *)skb->data;
672 if (wh != &tr->wh)
673 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100674 if (hdrlen != sizeof(tr->wh))
675 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100676
677 /*
678 * Firmware length is the length of the fully formed "802.11
679 * payload". That is, everything except for the 802.11 header.
680 * This includes all crypto material including the MIC.
681 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100682 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100683}
684
685
686/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100687 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200688 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100689struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200690 __le16 pkt_len;
691 __u8 sq2;
692 __u8 rate;
693 __le32 pkt_phys_addr;
694 __le32 next_rxd_phys_addr;
695 __le16 qos_control;
696 __le16 htsig2;
697 __le32 hw_rssi_info;
698 __le32 hw_noise_floor_info;
699 __u8 noise_floor;
700 __u8 pad0[3];
701 __u8 rssi;
702 __u8 rx_status;
703 __u8 channel;
704 __u8 rx_ctrl;
705} __attribute__((packed));
706
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100707#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
708#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
709#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100710
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100711#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200712
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100713static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200714{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100715 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200716
717 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100718 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200719}
720
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100721static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200722{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100723 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200724
725 rxd->pkt_len = cpu_to_le16(len);
726 rxd->pkt_phys_addr = cpu_to_le32(addr);
727 wmb();
728 rxd->rx_ctrl = 0;
729}
730
731static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100732mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
733 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200734{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100735 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200736
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100737 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200738 return -1;
739 rmb();
740
741 memset(status, 0, sizeof(*status));
742
743 status->signal = -rxd->rssi;
744 status->noise = -rxd->noise_floor;
745
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100746 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200747 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100748 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100749 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100750 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200751 } else {
752 int i;
753
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100754 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
755 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200756 status->rate_idx = i;
757 break;
758 }
759 }
760 }
761
762 status->band = IEEE80211_BAND_2GHZ;
763 status->freq = ieee80211_channel_to_frequency(rxd->channel);
764
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100765 *qos = rxd->qos_control;
766
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200767 return le16_to_cpu(rxd->pkt_len);
768}
769
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100770static struct rxd_ops rxd_8366_ap_ops = {
771 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
772 .rxd_init = mwl8k_rxd_8366_ap_init,
773 .rxd_refill = mwl8k_rxd_8366_ap_refill,
774 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200775};
776
777/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100778 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100779 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100780struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100781 __le16 pkt_len;
782 __u8 link_quality;
783 __u8 noise_level;
784 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200785 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100786 __le16 qos_control;
787 __le16 rate_info;
788 __le32 pad0[4];
789 __u8 rssi;
790 __u8 channel;
791 __le16 pad1;
792 __u8 rx_ctrl;
793 __u8 rx_status;
794 __u8 pad2[2];
795} __attribute__((packed));
796
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100797#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
798#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
799#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
800#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
801#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
802#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200803
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100804#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200805
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100806static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200807{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100808 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200809
810 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100811 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200812}
813
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100814static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200815{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100816 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200817
818 rxd->pkt_len = cpu_to_le16(len);
819 rxd->pkt_phys_addr = cpu_to_le32(addr);
820 wmb();
821 rxd->rx_ctrl = 0;
822}
823
824static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100825mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100826 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200827{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100828 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200829 u16 rate_info;
830
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100831 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200832 return -1;
833 rmb();
834
835 rate_info = le16_to_cpu(rxd->rate_info);
836
837 memset(status, 0, sizeof(*status));
838
839 status->signal = -rxd->rssi;
840 status->noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100841 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
842 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200843
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100844 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200845 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100846 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200847 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100848 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200849 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100850 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200851 status->flag |= RX_FLAG_HT;
852
853 status->band = IEEE80211_BAND_2GHZ;
854 status->freq = ieee80211_channel_to_frequency(rxd->channel);
855
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100856 *qos = rxd->qos_control;
857
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200858 return le16_to_cpu(rxd->pkt_len);
859}
860
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100861static struct rxd_ops rxd_sta_ops = {
862 .rxd_size = sizeof(struct mwl8k_rxd_sta),
863 .rxd_init = mwl8k_rxd_sta_init,
864 .rxd_refill = mwl8k_rxd_sta_refill,
865 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200866};
867
868
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100869#define MWL8K_RX_DESCS 256
870#define MWL8K_RX_MAXSZ 3800
871
872static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
873{
874 struct mwl8k_priv *priv = hw->priv;
875 struct mwl8k_rx_queue *rxq = priv->rxq + index;
876 int size;
877 int i;
878
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200879 rxq->rxd_count = 0;
880 rxq->head = 0;
881 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100882
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200883 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100884
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200885 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
886 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100887 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200888 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100889 return -ENOMEM;
890 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200891 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100892
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200893 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
894 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100895 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200896 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200897 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100898 return -ENOMEM;
899 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200900 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100901
902 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200903 int desc_size;
904 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100905 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200906 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100907
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200908 desc_size = priv->rxd_ops->rxd_size;
909 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100910
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200911 nexti = i + 1;
912 if (nexti == MWL8K_RX_DESCS)
913 nexti = 0;
914 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
915
916 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100917 }
918
919 return 0;
920}
921
922static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
923{
924 struct mwl8k_priv *priv = hw->priv;
925 struct mwl8k_rx_queue *rxq = priv->rxq + index;
926 int refilled;
927
928 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200929 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100930 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200931 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100932 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200933 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100934
935 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
936 if (skb == NULL)
937 break;
938
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200939 addr = pci_map_single(priv->pdev, skb->data,
940 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100941
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200942 rxq->rxd_count++;
943 rx = rxq->tail++;
944 if (rxq->tail == MWL8K_RX_DESCS)
945 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200946 rxq->buf[rx].skb = skb;
947 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200948
949 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
950 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100951
952 refilled++;
953 }
954
955 return refilled;
956}
957
958/* Must be called only when the card's reception is completely halted */
959static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
960{
961 struct mwl8k_priv *priv = hw->priv;
962 struct mwl8k_rx_queue *rxq = priv->rxq + index;
963 int i;
964
965 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200966 if (rxq->buf[i].skb != NULL) {
967 pci_unmap_single(priv->pdev,
968 pci_unmap_addr(&rxq->buf[i], dma),
969 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
970 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100971
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200972 kfree_skb(rxq->buf[i].skb);
973 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100974 }
975 }
976
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200977 kfree(rxq->buf);
978 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100979
980 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200981 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200982 rxq->rxd, rxq->rxd_dma);
983 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100984}
985
986
987/*
988 * Scan a list of BSSIDs to process for finalize join.
989 * Allows for extension to process multiple BSSIDs.
990 */
991static inline int
992mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
993{
994 return priv->capture_beacon &&
995 ieee80211_is_beacon(wh->frame_control) &&
996 !compare_ether_addr(wh->addr3, priv->capture_bssid);
997}
998
Lennert Buytenhek37797522009-10-22 20:19:45 +0200999static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1000 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001001{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001002 struct mwl8k_priv *priv = hw->priv;
1003
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001004 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001005 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001006
1007 /*
1008 * Use GFP_ATOMIC as rxq_process is called from
1009 * the primary interrupt handler, memory allocation call
1010 * must not sleep.
1011 */
1012 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1013 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001014 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001015}
1016
1017static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1018{
1019 struct mwl8k_priv *priv = hw->priv;
1020 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1021 int processed;
1022
1023 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001024 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001025 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001026 void *rxd;
1027 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001028 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001029 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001030
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001031 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001032 if (skb == NULL)
1033 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001034
1035 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1036
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001037 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001038 if (pkt_len < 0)
1039 break;
1040
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001041 rxq->buf[rxq->head].skb = NULL;
1042
1043 pci_unmap_single(priv->pdev,
1044 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1045 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1046 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001047
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001048 rxq->head++;
1049 if (rxq->head == MWL8K_RX_DESCS)
1050 rxq->head = 0;
1051
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001052 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001053
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001054 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001055 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001056
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001057 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001058 * Check for a pending join operation. Save a
1059 * copy of the beacon and schedule a tasklet to
1060 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001061 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001062 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001063 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001064
Johannes Bergf1d58c22009-06-17 13:13:00 +02001065 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1066 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001067
1068 processed++;
1069 }
1070
1071 return processed;
1072}
1073
1074
1075/*
1076 * Packet transmission.
1077 */
1078
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001079#define MWL8K_TXD_STATUS_OK 0x00000001
1080#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1081#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1082#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001083#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001084
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001085#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1086#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1087#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1088#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1089#define MWL8K_QOS_EOSP 0x0010
1090
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001091struct mwl8k_tx_desc {
1092 __le32 status;
1093 __u8 data_rate;
1094 __u8 tx_priority;
1095 __le16 qos_control;
1096 __le32 pkt_phys_addr;
1097 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001098 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001099 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001100 __le32 reserved;
1101 __le16 rate_info;
1102 __u8 peer_id;
1103 __u8 tx_frag_cnt;
1104} __attribute__((packed));
1105
1106#define MWL8K_TX_DESCS 128
1107
1108static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1109{
1110 struct mwl8k_priv *priv = hw->priv;
1111 struct mwl8k_tx_queue *txq = priv->txq + index;
1112 int size;
1113 int i;
1114
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001115 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1116 txq->stats.limit = MWL8K_TX_DESCS;
1117 txq->head = 0;
1118 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001119
1120 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1121
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001122 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1123 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001124 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001125 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001126 return -ENOMEM;
1127 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001128 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001129
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001130 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1131 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001132 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001133 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001134 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001135 return -ENOMEM;
1136 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001137 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001138
1139 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1140 struct mwl8k_tx_desc *tx_desc;
1141 int nexti;
1142
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001143 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001144 nexti = (i + 1) % MWL8K_TX_DESCS;
1145
1146 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001147 tx_desc->next_txd_phys_addr =
1148 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001149 }
1150
1151 return 0;
1152}
1153
1154static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1155{
1156 iowrite32(MWL8K_H2A_INT_PPA_READY,
1157 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1158 iowrite32(MWL8K_H2A_INT_DUMMY,
1159 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1160 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1161}
1162
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001163static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001164{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001165 struct mwl8k_priv *priv = hw->priv;
1166 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001167
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001168 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1169 struct mwl8k_tx_queue *txq = priv->txq + i;
1170 int fw_owned = 0;
1171 int drv_owned = 0;
1172 int unused = 0;
1173 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001174
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001175 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001176 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1177 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001178
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001179 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001180 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001181 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001182 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001183 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001184
1185 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001186 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001187 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001188
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001189 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1190 "fw_owned=%d drv_owned=%d unused=%d\n",
1191 wiphy_name(hw->wiphy), i,
1192 txq->stats.len, txq->head, txq->tail,
1193 fw_owned, drv_owned, unused);
1194 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001195}
1196
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001197/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001198 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001199 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001200#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001201
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001202static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001204 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001205 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001206 int retry;
1207 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001208
1209 might_sleep();
1210
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001211 /*
1212 * The TX queues are stopped at this point, so this test
1213 * doesn't need to take ->tx_lock.
1214 */
1215 if (!priv->pending_tx_pkts)
1216 return 0;
1217
1218 retry = 0;
1219 rc = 0;
1220
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001221 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001222 priv->tx_wait = &tx_wait;
1223 while (!rc) {
1224 int oldcount;
1225 unsigned long timeout;
1226
1227 oldcount = priv->pending_tx_pkts;
1228
1229 spin_unlock_bh(&priv->tx_lock);
1230 timeout = wait_for_completion_timeout(&tx_wait,
1231 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1232 spin_lock_bh(&priv->tx_lock);
1233
1234 if (timeout) {
1235 WARN_ON(priv->pending_tx_pkts);
1236 if (retry) {
1237 printk(KERN_NOTICE "%s: tx rings drained\n",
1238 wiphy_name(hw->wiphy));
1239 }
1240 break;
1241 }
1242
1243 if (priv->pending_tx_pkts < oldcount) {
Lennert Buytenhek9a2303b2010-01-04 21:54:25 +01001244 printk(KERN_NOTICE "%s: waiting for tx rings "
1245 "to drain (%d -> %d pkts)\n",
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001246 wiphy_name(hw->wiphy), oldcount,
1247 priv->pending_tx_pkts);
1248 retry = 1;
1249 continue;
1250 }
1251
1252 priv->tx_wait = NULL;
1253
1254 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1255 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1256 mwl8k_dump_tx_rings(hw);
1257
1258 rc = -ETIMEDOUT;
1259 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001260 spin_unlock_bh(&priv->tx_lock);
1261
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001262 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001263}
1264
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001265#define MWL8K_TXD_SUCCESS(status) \
1266 ((status) & (MWL8K_TXD_STATUS_OK | \
1267 MWL8K_TXD_STATUS_OK_RETRY | \
1268 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001269
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001270static int
1271mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001272{
1273 struct mwl8k_priv *priv = hw->priv;
1274 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001275 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001276
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001277 processed = 0;
1278 while (txq->stats.len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001279 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001280 struct mwl8k_tx_desc *tx_desc;
1281 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001282 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001283 struct sk_buff *skb;
1284 struct ieee80211_tx_info *info;
1285 u32 status;
1286
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001287 tx = txq->head;
1288 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001289
1290 status = le32_to_cpu(tx_desc->status);
1291
1292 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1293 if (!force)
1294 break;
1295 tx_desc->status &=
1296 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1297 }
1298
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001299 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1300 BUG_ON(txq->stats.len == 0);
1301 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001302 priv->pending_tx_pkts--;
1303
1304 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001305 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001306 skb = txq->skb[tx];
1307 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001308
1309 BUG_ON(skb == NULL);
1310 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1311
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001312 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001313
1314 /* Mark descriptor as unused */
1315 tx_desc->pkt_phys_addr = 0;
1316 tx_desc->pkt_len = 0;
1317
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001318 info = IEEE80211_SKB_CB(skb);
1319 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001320 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001321 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001322
1323 ieee80211_tx_status_irqsafe(hw, skb);
1324
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001325 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001326 }
1327
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001328 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001329 ieee80211_wake_queue(hw, index);
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001330
1331 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001332}
1333
1334/* must be called only when the card's transmit is completely halted */
1335static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1336{
1337 struct mwl8k_priv *priv = hw->priv;
1338 struct mwl8k_tx_queue *txq = priv->txq + index;
1339
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001340 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001341
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001342 kfree(txq->skb);
1343 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001344
1345 pci_free_consistent(priv->pdev,
1346 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001347 txq->txd, txq->txd_dma);
1348 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001349}
1350
1351static int
1352mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1353{
1354 struct mwl8k_priv *priv = hw->priv;
1355 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001356 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001357 struct ieee80211_hdr *wh;
1358 struct mwl8k_tx_queue *txq;
1359 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001360 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001361 u32 txstatus;
1362 u8 txdatarate;
1363 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001364
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001365 wh = (struct ieee80211_hdr *)skb->data;
1366 if (ieee80211_is_data_qos(wh->frame_control))
1367 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1368 else
1369 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001370
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001371 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001372 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001373
1374 tx_info = IEEE80211_SKB_CB(skb);
1375 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001376
1377 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001378 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001379 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1380 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001381 }
1382
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001383 /* Setup firmware control bit fields for each frame type. */
1384 txstatus = 0;
1385 txdatarate = 0;
1386 if (ieee80211_is_mgmt(wh->frame_control) ||
1387 ieee80211_is_ctl(wh->frame_control)) {
1388 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001389 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001390 } else if (ieee80211_is_data(wh->frame_control)) {
1391 txdatarate = 1;
1392 if (is_multicast_ether_addr(wh->addr1))
1393 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1394
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001395 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001396 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001397 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001398 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001399 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001400 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001401
1402 dma = pci_map_single(priv->pdev, skb->data,
1403 skb->len, PCI_DMA_TODEVICE);
1404
1405 if (pci_dma_mapping_error(priv->pdev, dma)) {
1406 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001407 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001408 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001409 return NETDEV_TX_OK;
1410 }
1411
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001412 spin_lock_bh(&priv->tx_lock);
1413
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001414 txq = priv->txq + index;
1415
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001416 BUG_ON(txq->skb[txq->tail] != NULL);
1417 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001418
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001419 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001420 tx->data_rate = txdatarate;
1421 tx->tx_priority = index;
1422 tx->qos_control = cpu_to_le16(qos);
1423 tx->pkt_phys_addr = cpu_to_le32(dma);
1424 tx->pkt_len = cpu_to_le16(skb->len);
1425 tx->rate_info = 0;
Lennert Buytenheka6804002010-01-04 21:55:42 +01001426 if (!priv->ap_fw && tx_info->control.sta != NULL)
1427 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1428 else
1429 tx->peer_id = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001430 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001431 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1432
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001433 txq->stats.count++;
1434 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001435 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001436
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001437 txq->tail++;
1438 if (txq->tail == MWL8K_TX_DESCS)
1439 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001440
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001441 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001442 ieee80211_stop_queue(hw, index);
1443
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001444 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001445
1446 spin_unlock_bh(&priv->tx_lock);
1447
1448 return NETDEV_TX_OK;
1449}
1450
1451
1452/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001453 * Firmware access.
1454 *
1455 * We have the following requirements for issuing firmware commands:
1456 * - Some commands require that the packet transmit path is idle when
1457 * the command is issued. (For simplicity, we'll just quiesce the
1458 * transmit path for every command.)
1459 * - There are certain sequences of commands that need to be issued to
1460 * the hardware sequentially, with no other intervening commands.
1461 *
1462 * This leads to an implementation of a "firmware lock" as a mutex that
1463 * can be taken recursively, and which is taken by both the low-level
1464 * command submission function (mwl8k_post_cmd) as well as any users of
1465 * that function that require issuing of an atomic sequence of commands,
1466 * and quiesces the transmit path whenever it's taken.
1467 */
1468static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1469{
1470 struct mwl8k_priv *priv = hw->priv;
1471
1472 if (priv->fw_mutex_owner != current) {
1473 int rc;
1474
1475 mutex_lock(&priv->fw_mutex);
1476 ieee80211_stop_queues(hw);
1477
1478 rc = mwl8k_tx_wait_empty(hw);
1479 if (rc) {
1480 ieee80211_wake_queues(hw);
1481 mutex_unlock(&priv->fw_mutex);
1482
1483 return rc;
1484 }
1485
1486 priv->fw_mutex_owner = current;
1487 }
1488
1489 priv->fw_mutex_depth++;
1490
1491 return 0;
1492}
1493
1494static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1495{
1496 struct mwl8k_priv *priv = hw->priv;
1497
1498 if (!--priv->fw_mutex_depth) {
1499 ieee80211_wake_queues(hw);
1500 priv->fw_mutex_owner = NULL;
1501 mutex_unlock(&priv->fw_mutex);
1502 }
1503}
1504
1505
1506/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001507 * Command processing.
1508 */
1509
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001510/* Timeout firmware commands after 10s */
1511#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001512
1513static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1514{
1515 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1516 struct mwl8k_priv *priv = hw->priv;
1517 void __iomem *regs = priv->regs;
1518 dma_addr_t dma_addr;
1519 unsigned int dma_size;
1520 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001521 unsigned long timeout = 0;
1522 u8 buf[32];
1523
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001524 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001525 dma_size = le16_to_cpu(cmd->length);
1526 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1527 PCI_DMA_BIDIRECTIONAL);
1528 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1529 return -ENOMEM;
1530
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001531 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001532 if (rc) {
1533 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1534 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001535 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001536 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001537
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001538 priv->hostcmd_wait = &cmd_wait;
1539 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1540 iowrite32(MWL8K_H2A_INT_DOORBELL,
1541 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1542 iowrite32(MWL8K_H2A_INT_DUMMY,
1543 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001544
1545 timeout = wait_for_completion_timeout(&cmd_wait,
1546 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1547
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001548 priv->hostcmd_wait = NULL;
1549
1550 mwl8k_fw_unlock(hw);
1551
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001552 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1553 PCI_DMA_BIDIRECTIONAL);
1554
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001555 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001556 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001557 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001558 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1559 MWL8K_CMD_TIMEOUT_MS);
1560 rc = -ETIMEDOUT;
1561 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001562 int ms;
1563
1564 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1565
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001566 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001567 if (rc)
1568 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001569 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001570 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001571 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001572 else if (ms > 2000)
1573 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1574 wiphy_name(hw->wiphy),
1575 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1576 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001577 }
1578
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001579 return rc;
1580}
1581
1582/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001583 * Setup code shared between STA and AP firmware images.
1584 */
1585static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1586{
1587 struct mwl8k_priv *priv = hw->priv;
1588
1589 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1590 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1591
1592 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1593 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1594
1595 priv->band_24.band = IEEE80211_BAND_2GHZ;
1596 priv->band_24.channels = priv->channels_24;
1597 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1598 priv->band_24.bitrates = priv->rates_24;
1599 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1600
1601 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1602}
1603
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01001604static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
1605{
1606 struct mwl8k_priv *priv = hw->priv;
1607
1608 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
1609 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
1610
1611 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
1612 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
1613
1614 priv->band_50.band = IEEE80211_BAND_5GHZ;
1615 priv->band_50.channels = priv->channels_50;
1616 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
1617 priv->band_50.bitrates = priv->rates_50;
1618 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
1619
1620 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
1621}
1622
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001623/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001624 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001625 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001626struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001627 struct mwl8k_cmd_pkt header;
1628 __u8 hw_rev;
1629 __u8 host_interface;
1630 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001631 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001632 __le16 region_code;
1633 __le32 fw_rev;
1634 __le32 ps_cookie;
1635 __le32 caps;
1636 __u8 mcs_bitmap[16];
1637 __le32 rx_queue_ptr;
1638 __le32 num_tx_queues;
1639 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1640 __le32 caps2;
1641 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001642 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001643} __attribute__((packed));
1644
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001645#define MWL8K_CAP_MAX_AMSDU 0x20000000
1646#define MWL8K_CAP_GREENFIELD 0x08000000
1647#define MWL8K_CAP_AMPDU 0x04000000
1648#define MWL8K_CAP_RX_STBC 0x01000000
1649#define MWL8K_CAP_TX_STBC 0x00800000
1650#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1651#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1652#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1653#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1654#define MWL8K_CAP_DELAY_BA 0x00003000
1655#define MWL8K_CAP_MIMO 0x00000200
1656#define MWL8K_CAP_40MHZ 0x00000100
1657
1658static void mwl8k_set_ht_caps(struct ieee80211_hw *hw, u32 cap)
1659{
1660 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001661 struct ieee80211_supported_band *band = &priv->band_24;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001662 int rx_streams;
1663 int tx_streams;
1664
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001665 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001666
1667 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001668 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001669 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001670 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001671 if (cap & MWL8K_CAP_AMPDU) {
1672 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001673 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1674 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001675 }
1676 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001677 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001678 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001679 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001680 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001681 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001682 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001683 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001684 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001685 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001686 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001687 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001688
1689 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1690 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1691
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001692 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001693 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001694 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001695 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001696 band->ht_cap.mcs.rx_mask[2] = 0xff;
1697 band->ht_cap.mcs.rx_mask[4] = 0x01;
1698 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001699
1700 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001701 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1702 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001703 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1704 }
1705}
1706
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001707static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001708{
1709 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001710 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001711 int rc;
1712 int i;
1713
1714 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1715 if (cmd == NULL)
1716 return -ENOMEM;
1717
1718 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1719 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1720
1721 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1722 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001723 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001724 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001725 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001726 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001727 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001728 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001729
1730 rc = mwl8k_post_cmd(hw, &cmd->header);
1731
1732 if (!rc) {
1733 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1734 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001735 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001736 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001737 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001738 if (cmd->caps & cpu_to_le32(MWL8K_CAP_MIMO))
1739 mwl8k_set_ht_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001740 }
1741
1742 kfree(cmd);
1743 return rc;
1744}
1745
1746/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001747 * CMD_GET_HW_SPEC (AP version).
1748 */
1749struct mwl8k_cmd_get_hw_spec_ap {
1750 struct mwl8k_cmd_pkt header;
1751 __u8 hw_rev;
1752 __u8 host_interface;
1753 __le16 num_wcb;
1754 __le16 num_mcaddrs;
1755 __u8 perm_addr[ETH_ALEN];
1756 __le16 region_code;
1757 __le16 num_antenna;
1758 __le32 fw_rev;
1759 __le32 wcbbase0;
1760 __le32 rxwrptr;
1761 __le32 rxrdptr;
1762 __le32 ps_cookie;
1763 __le32 wcbbase1;
1764 __le32 wcbbase2;
1765 __le32 wcbbase3;
1766} __attribute__((packed));
1767
1768static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1769{
1770 struct mwl8k_priv *priv = hw->priv;
1771 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1772 int rc;
1773
1774 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1775 if (cmd == NULL)
1776 return -ENOMEM;
1777
1778 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1779 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1780
1781 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1782 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1783
1784 rc = mwl8k_post_cmd(hw, &cmd->header);
1785
1786 if (!rc) {
1787 int off;
1788
1789 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1790 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1791 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1792 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001793 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001794
1795 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1796 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1797
1798 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1799 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1800
1801 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1802 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1803
1804 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1805 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1806
1807 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1808 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1809
1810 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1811 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1812 }
1813
1814 kfree(cmd);
1815 return rc;
1816}
1817
1818/*
1819 * CMD_SET_HW_SPEC.
1820 */
1821struct mwl8k_cmd_set_hw_spec {
1822 struct mwl8k_cmd_pkt header;
1823 __u8 hw_rev;
1824 __u8 host_interface;
1825 __le16 num_mcaddrs;
1826 __u8 perm_addr[ETH_ALEN];
1827 __le16 region_code;
1828 __le32 fw_rev;
1829 __le32 ps_cookie;
1830 __le32 caps;
1831 __le32 rx_queue_ptr;
1832 __le32 num_tx_queues;
1833 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1834 __le32 flags;
1835 __le32 num_tx_desc_per_queue;
1836 __le32 total_rxd;
1837} __attribute__((packed));
1838
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001839#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1840#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1841#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001842
1843static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1844{
1845 struct mwl8k_priv *priv = hw->priv;
1846 struct mwl8k_cmd_set_hw_spec *cmd;
1847 int rc;
1848 int i;
1849
1850 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1851 if (cmd == NULL)
1852 return -ENOMEM;
1853
1854 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1855 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1856
1857 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1858 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1859 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1860 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1861 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001862 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1863 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1864 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001865 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1866 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1867
1868 rc = mwl8k_post_cmd(hw, &cmd->header);
1869 kfree(cmd);
1870
1871 return rc;
1872}
1873
1874/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001875 * CMD_MAC_MULTICAST_ADR.
1876 */
1877struct mwl8k_cmd_mac_multicast_adr {
1878 struct mwl8k_cmd_pkt header;
1879 __le16 action;
1880 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001881 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001882};
1883
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001884#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1885#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1886#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1887#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001888
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001889static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001890__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001891 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001892{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001893 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001894 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001895 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001896
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001897 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001898 allmulti = 1;
1899 mc_count = 0;
1900 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001901
1902 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1903
1904 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001905 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001906 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001907
1908 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1909 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001910 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1911 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001912
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001913 if (allmulti) {
1914 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1915 } else if (mc_count) {
1916 int i;
1917
1918 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1919 cmd->numaddr = cpu_to_le16(mc_count);
1920 for (i = 0; i < mc_count && mclist; i++) {
1921 if (mclist->da_addrlen != ETH_ALEN) {
1922 kfree(cmd);
1923 return NULL;
1924 }
1925 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1926 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001927 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001928 }
1929
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001930 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001931}
1932
1933/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001934 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001935 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001936struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001937 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001938 __le32 stats[64];
1939} __attribute__((packed));
1940
1941#define MWL8K_STAT_ACK_FAILURE 9
1942#define MWL8K_STAT_RTS_FAILURE 12
1943#define MWL8K_STAT_FCS_ERROR 24
1944#define MWL8K_STAT_RTS_SUCCESS 11
1945
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001946static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1947 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001948{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001949 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001950 int rc;
1951
1952 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1953 if (cmd == NULL)
1954 return -ENOMEM;
1955
1956 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1957 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001958
1959 rc = mwl8k_post_cmd(hw, &cmd->header);
1960 if (!rc) {
1961 stats->dot11ACKFailureCount =
1962 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1963 stats->dot11RTSFailureCount =
1964 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1965 stats->dot11FCSErrorCount =
1966 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1967 stats->dot11RTSSuccessCount =
1968 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1969 }
1970 kfree(cmd);
1971
1972 return rc;
1973}
1974
1975/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001976 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001977 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001978struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001979 struct mwl8k_cmd_pkt header;
1980 __le16 action;
1981 __le16 control;
1982 __le16 radio_on;
1983} __attribute__((packed));
1984
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001985static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001986mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001987{
1988 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001989 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001990 int rc;
1991
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001992 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001993 return 0;
1994
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001995 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1996 if (cmd == NULL)
1997 return -ENOMEM;
1998
1999 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2000 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2001 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002002 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002003 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2004
2005 rc = mwl8k_post_cmd(hw, &cmd->header);
2006 kfree(cmd);
2007
2008 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002009 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002010
2011 return rc;
2012}
2013
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002014static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002015{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002016 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002017}
2018
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002019static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002020{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002021 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002022}
2023
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002024static int
2025mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2026{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002027 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002028
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002029 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002030
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002031 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002032}
2033
2034/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002035 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002036 */
2037#define MWL8K_TX_POWER_LEVEL_TOTAL 8
2038
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002039struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002040 struct mwl8k_cmd_pkt header;
2041 __le16 action;
2042 __le16 support_level;
2043 __le16 current_level;
2044 __le16 reserved;
2045 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2046} __attribute__((packed));
2047
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002048static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002049{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002050 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002051 int rc;
2052
2053 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2054 if (cmd == NULL)
2055 return -ENOMEM;
2056
2057 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2058 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2059 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2060 cmd->support_level = cpu_to_le16(dBm);
2061
2062 rc = mwl8k_post_cmd(hw, &cmd->header);
2063 kfree(cmd);
2064
2065 return rc;
2066}
2067
2068/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002069 * CMD_RF_ANTENNA.
2070 */
2071struct mwl8k_cmd_rf_antenna {
2072 struct mwl8k_cmd_pkt header;
2073 __le16 antenna;
2074 __le16 mode;
2075} __attribute__((packed));
2076
2077#define MWL8K_RF_ANTENNA_RX 1
2078#define MWL8K_RF_ANTENNA_TX 2
2079
2080static int
2081mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2082{
2083 struct mwl8k_cmd_rf_antenna *cmd;
2084 int rc;
2085
2086 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2087 if (cmd == NULL)
2088 return -ENOMEM;
2089
2090 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2091 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2092 cmd->antenna = cpu_to_le16(antenna);
2093 cmd->mode = cpu_to_le16(mask);
2094
2095 rc = mwl8k_post_cmd(hw, &cmd->header);
2096 kfree(cmd);
2097
2098 return rc;
2099}
2100
2101/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002102 * CMD_SET_BEACON.
2103 */
2104struct mwl8k_cmd_set_beacon {
2105 struct mwl8k_cmd_pkt header;
2106 __le16 beacon_len;
2107 __u8 beacon[0];
2108};
2109
2110static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, u8 *beacon, int len)
2111{
2112 struct mwl8k_cmd_set_beacon *cmd;
2113 int rc;
2114
2115 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2116 if (cmd == NULL)
2117 return -ENOMEM;
2118
2119 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2120 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2121 cmd->beacon_len = cpu_to_le16(len);
2122 memcpy(cmd->beacon, beacon, len);
2123
2124 rc = mwl8k_post_cmd(hw, &cmd->header);
2125 kfree(cmd);
2126
2127 return rc;
2128}
2129
2130/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002131 * CMD_SET_PRE_SCAN.
2132 */
2133struct mwl8k_cmd_set_pre_scan {
2134 struct mwl8k_cmd_pkt header;
2135} __attribute__((packed));
2136
2137static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2138{
2139 struct mwl8k_cmd_set_pre_scan *cmd;
2140 int rc;
2141
2142 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2143 if (cmd == NULL)
2144 return -ENOMEM;
2145
2146 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2147 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2148
2149 rc = mwl8k_post_cmd(hw, &cmd->header);
2150 kfree(cmd);
2151
2152 return rc;
2153}
2154
2155/*
2156 * CMD_SET_POST_SCAN.
2157 */
2158struct mwl8k_cmd_set_post_scan {
2159 struct mwl8k_cmd_pkt header;
2160 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002161 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002162} __attribute__((packed));
2163
2164static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002165mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002166{
2167 struct mwl8k_cmd_set_post_scan *cmd;
2168 int rc;
2169
2170 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2171 if (cmd == NULL)
2172 return -ENOMEM;
2173
2174 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2175 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2176 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002177 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002178
2179 rc = mwl8k_post_cmd(hw, &cmd->header);
2180 kfree(cmd);
2181
2182 return rc;
2183}
2184
2185/*
2186 * CMD_SET_RF_CHANNEL.
2187 */
2188struct mwl8k_cmd_set_rf_channel {
2189 struct mwl8k_cmd_pkt header;
2190 __le16 action;
2191 __u8 current_channel;
2192 __le32 channel_flags;
2193} __attribute__((packed));
2194
2195static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002196 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002197{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002198 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002199 struct mwl8k_cmd_set_rf_channel *cmd;
2200 int rc;
2201
2202 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2203 if (cmd == NULL)
2204 return -ENOMEM;
2205
2206 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2207 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2208 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2209 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002210
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002211 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002212 cmd->channel_flags |= cpu_to_le32(0x00000001);
2213
2214 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2215 conf->channel_type == NL80211_CHAN_HT20)
2216 cmd->channel_flags |= cpu_to_le32(0x00000080);
2217 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2218 cmd->channel_flags |= cpu_to_le32(0x000001900);
2219 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2220 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002221
2222 rc = mwl8k_post_cmd(hw, &cmd->header);
2223 kfree(cmd);
2224
2225 return rc;
2226}
2227
2228/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002229 * CMD_SET_AID.
2230 */
2231#define MWL8K_FRAME_PROT_DISABLED 0x00
2232#define MWL8K_FRAME_PROT_11G 0x07
2233#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2234#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2235
2236struct mwl8k_cmd_update_set_aid {
2237 struct mwl8k_cmd_pkt header;
2238 __le16 aid;
2239
2240 /* AP's MAC address (BSSID) */
2241 __u8 bssid[ETH_ALEN];
2242 __le16 protection_mode;
2243 __u8 supp_rates[14];
2244} __attribute__((packed));
2245
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002246static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2247{
2248 int i;
2249 int j;
2250
2251 /*
2252 * Clear nonstandard rates 4 and 13.
2253 */
2254 mask &= 0x1fef;
2255
2256 for (i = 0, j = 0; i < 14; i++) {
2257 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002258 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002259 }
2260}
2261
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002262static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002263mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2264 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002265{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002266 struct mwl8k_cmd_update_set_aid *cmd;
2267 u16 prot_mode;
2268 int rc;
2269
2270 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2271 if (cmd == NULL)
2272 return -ENOMEM;
2273
2274 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2275 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002276 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002277 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002278
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002279 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002280 prot_mode = MWL8K_FRAME_PROT_11G;
2281 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002282 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002283 IEEE80211_HT_OP_MODE_PROTECTION) {
2284 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2285 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2286 break;
2287 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2288 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2289 break;
2290 default:
2291 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2292 break;
2293 }
2294 }
2295 cmd->protection_mode = cpu_to_le16(prot_mode);
2296
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002297 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002298
2299 rc = mwl8k_post_cmd(hw, &cmd->header);
2300 kfree(cmd);
2301
2302 return rc;
2303}
2304
2305/*
2306 * CMD_SET_RATE.
2307 */
2308struct mwl8k_cmd_set_rate {
2309 struct mwl8k_cmd_pkt header;
2310 __u8 legacy_rates[14];
2311
2312 /* Bitmap for supported MCS codes. */
2313 __u8 mcs_set[16];
2314 __u8 reserved[16];
2315} __attribute__((packed));
2316
2317static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002318mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002319 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002320{
2321 struct mwl8k_cmd_set_rate *cmd;
2322 int rc;
2323
2324 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2325 if (cmd == NULL)
2326 return -ENOMEM;
2327
2328 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2329 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002330 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002331 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002332
2333 rc = mwl8k_post_cmd(hw, &cmd->header);
2334 kfree(cmd);
2335
2336 return rc;
2337}
2338
2339/*
2340 * CMD_FINALIZE_JOIN.
2341 */
2342#define MWL8K_FJ_BEACON_MAXLEN 128
2343
2344struct mwl8k_cmd_finalize_join {
2345 struct mwl8k_cmd_pkt header;
2346 __le32 sleep_interval; /* Number of beacon periods to sleep */
2347 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2348} __attribute__((packed));
2349
2350static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2351 int framelen, int dtim)
2352{
2353 struct mwl8k_cmd_finalize_join *cmd;
2354 struct ieee80211_mgmt *payload = frame;
2355 int payload_len;
2356 int rc;
2357
2358 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2359 if (cmd == NULL)
2360 return -ENOMEM;
2361
2362 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2363 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2364 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2365
2366 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2367 if (payload_len < 0)
2368 payload_len = 0;
2369 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2370 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2371
2372 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2373
2374 rc = mwl8k_post_cmd(hw, &cmd->header);
2375 kfree(cmd);
2376
2377 return rc;
2378}
2379
2380/*
2381 * CMD_SET_RTS_THRESHOLD.
2382 */
2383struct mwl8k_cmd_set_rts_threshold {
2384 struct mwl8k_cmd_pkt header;
2385 __le16 action;
2386 __le16 threshold;
2387} __attribute__((packed));
2388
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002389static int
2390mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002391{
2392 struct mwl8k_cmd_set_rts_threshold *cmd;
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_RTS_THRESHOLD);
2400 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002401 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2402 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002403
2404 rc = mwl8k_post_cmd(hw, &cmd->header);
2405 kfree(cmd);
2406
2407 return rc;
2408}
2409
2410/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002411 * CMD_SET_SLOT.
2412 */
2413struct mwl8k_cmd_set_slot {
2414 struct mwl8k_cmd_pkt header;
2415 __le16 action;
2416 __u8 short_slot;
2417} __attribute__((packed));
2418
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002419static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002420{
2421 struct mwl8k_cmd_set_slot *cmd;
2422 int rc;
2423
2424 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2425 if (cmd == NULL)
2426 return -ENOMEM;
2427
2428 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2429 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2430 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002431 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002432
2433 rc = mwl8k_post_cmd(hw, &cmd->header);
2434 kfree(cmd);
2435
2436 return rc;
2437}
2438
2439/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002440 * CMD_SET_EDCA_PARAMS.
2441 */
2442struct mwl8k_cmd_set_edca_params {
2443 struct mwl8k_cmd_pkt header;
2444
2445 /* See MWL8K_SET_EDCA_XXX below */
2446 __le16 action;
2447
2448 /* TX opportunity in units of 32 us */
2449 __le16 txop;
2450
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002451 union {
2452 struct {
2453 /* Log exponent of max contention period: 0...15 */
2454 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002455
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002456 /* Log exponent of min contention period: 0...15 */
2457 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002458
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002459 /* Adaptive interframe spacing in units of 32us */
2460 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002461
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002462 /* TX queue to configure */
2463 __u8 txq;
2464 } ap;
2465 struct {
2466 /* Log exponent of max contention period: 0...15 */
2467 __u8 log_cw_max;
2468
2469 /* Log exponent of min contention period: 0...15 */
2470 __u8 log_cw_min;
2471
2472 /* Adaptive interframe spacing in units of 32us */
2473 __u8 aifs;
2474
2475 /* TX queue to configure */
2476 __u8 txq;
2477 } sta;
2478 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002479} __attribute__((packed));
2480
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002481#define MWL8K_SET_EDCA_CW 0x01
2482#define MWL8K_SET_EDCA_TXOP 0x02
2483#define MWL8K_SET_EDCA_AIFS 0x04
2484
2485#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2486 MWL8K_SET_EDCA_TXOP | \
2487 MWL8K_SET_EDCA_AIFS)
2488
2489static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002490mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2491 __u16 cw_min, __u16 cw_max,
2492 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002493{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002494 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002495 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002496 int rc;
2497
2498 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2499 if (cmd == NULL)
2500 return -ENOMEM;
2501
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002502 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2503 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002504 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2505 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002506 if (priv->ap_fw) {
2507 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2508 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2509 cmd->ap.aifs = aifs;
2510 cmd->ap.txq = qnum;
2511 } else {
2512 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2513 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2514 cmd->sta.aifs = aifs;
2515 cmd->sta.txq = qnum;
2516 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002517
2518 rc = mwl8k_post_cmd(hw, &cmd->header);
2519 kfree(cmd);
2520
2521 return rc;
2522}
2523
2524/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002525 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002526 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002527struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002528 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002529 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002530} __attribute__((packed));
2531
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002532static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002533{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002534 struct mwl8k_priv *priv = hw->priv;
2535 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002536 int rc;
2537
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002538 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2539 if (cmd == NULL)
2540 return -ENOMEM;
2541
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002542 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002543 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002544 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002545
2546 rc = mwl8k_post_cmd(hw, &cmd->header);
2547 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002548
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002549 if (!rc)
2550 priv->wmm_enabled = enable;
2551
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002552 return rc;
2553}
2554
2555/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002556 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002557 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002558struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002559 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002560 __le32 action;
2561 __u8 rx_antenna_map;
2562 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002563} __attribute__((packed));
2564
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002565static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002566{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002567 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002568 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002569
2570 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2571 if (cmd == NULL)
2572 return -ENOMEM;
2573
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002574 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002575 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002576 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2577 cmd->rx_antenna_map = rx;
2578 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002579
2580 rc = mwl8k_post_cmd(hw, &cmd->header);
2581 kfree(cmd);
2582
2583 return rc;
2584}
2585
2586/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002587 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002588 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002589struct mwl8k_cmd_use_fixed_rate_sta {
2590 struct mwl8k_cmd_pkt header;
2591 __le32 action;
2592 __le32 allow_rate_drop;
2593 __le32 num_rates;
2594 struct {
2595 __le32 is_ht_rate;
2596 __le32 enable_retry;
2597 __le32 rate;
2598 __le32 retry_count;
2599 } rate_entry[8];
2600 __le32 rate_type;
2601 __le32 reserved1;
2602 __le32 reserved2;
2603} __attribute__((packed));
2604
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002605#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002606#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002607
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002608static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002609{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002610 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002611 int rc;
2612
2613 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2614 if (cmd == NULL)
2615 return -ENOMEM;
2616
2617 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2618 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002619 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2620 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002621
2622 rc = mwl8k_post_cmd(hw, &cmd->header);
2623 kfree(cmd);
2624
2625 return rc;
2626}
2627
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002628/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002629 * CMD_USE_FIXED_RATE (AP version).
2630 */
2631struct mwl8k_cmd_use_fixed_rate_ap {
2632 struct mwl8k_cmd_pkt header;
2633 __le32 action;
2634 __le32 allow_rate_drop;
2635 __le32 num_rates;
2636 struct mwl8k_rate_entry_ap {
2637 __le32 is_ht_rate;
2638 __le32 enable_retry;
2639 __le32 rate;
2640 __le32 retry_count;
2641 } rate_entry[4];
2642 u8 multicast_rate;
2643 u8 multicast_rate_type;
2644 u8 management_rate;
2645} __attribute__((packed));
2646
2647static int
2648mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2649{
2650 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2651 int rc;
2652
2653 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2654 if (cmd == NULL)
2655 return -ENOMEM;
2656
2657 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2658 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2659 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2660 cmd->multicast_rate = mcast;
2661 cmd->management_rate = mgmt;
2662
2663 rc = mwl8k_post_cmd(hw, &cmd->header);
2664 kfree(cmd);
2665
2666 return rc;
2667}
2668
2669/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002670 * CMD_ENABLE_SNIFFER.
2671 */
2672struct mwl8k_cmd_enable_sniffer {
2673 struct mwl8k_cmd_pkt header;
2674 __le32 action;
2675} __attribute__((packed));
2676
2677static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2678{
2679 struct mwl8k_cmd_enable_sniffer *cmd;
2680 int rc;
2681
2682 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2683 if (cmd == NULL)
2684 return -ENOMEM;
2685
2686 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2687 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2688 cmd->action = cpu_to_le32(!!enable);
2689
2690 rc = mwl8k_post_cmd(hw, &cmd->header);
2691 kfree(cmd);
2692
2693 return rc;
2694}
2695
2696/*
2697 * CMD_SET_MAC_ADDR.
2698 */
2699struct mwl8k_cmd_set_mac_addr {
2700 struct mwl8k_cmd_pkt header;
2701 union {
2702 struct {
2703 __le16 mac_type;
2704 __u8 mac_addr[ETH_ALEN];
2705 } mbss;
2706 __u8 mac_addr[ETH_ALEN];
2707 };
2708} __attribute__((packed));
2709
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002710#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2711#define MWL8K_MAC_TYPE_PRIMARY_AP 2
2712
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002713static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2714{
2715 struct mwl8k_priv *priv = hw->priv;
2716 struct mwl8k_cmd_set_mac_addr *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_SET_MAC_ADDR);
2724 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2725 if (priv->ap_fw) {
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002726 cmd->mbss.mac_type = cpu_to_le16(MWL8K_MAC_TYPE_PRIMARY_AP);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002727 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2728 } else {
2729 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2730 }
2731
2732 rc = mwl8k_post_cmd(hw, &cmd->header);
2733 kfree(cmd);
2734
2735 return rc;
2736}
2737
2738/*
2739 * CMD_SET_RATEADAPT_MODE.
2740 */
2741struct mwl8k_cmd_set_rate_adapt_mode {
2742 struct mwl8k_cmd_pkt header;
2743 __le16 action;
2744 __le16 mode;
2745} __attribute__((packed));
2746
2747static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2748{
2749 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2750 int rc;
2751
2752 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2753 if (cmd == NULL)
2754 return -ENOMEM;
2755
2756 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2757 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2758 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2759 cmd->mode = cpu_to_le16(mode);
2760
2761 rc = mwl8k_post_cmd(hw, &cmd->header);
2762 kfree(cmd);
2763
2764 return rc;
2765}
2766
2767/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002768 * CMD_BSS_START.
2769 */
2770struct mwl8k_cmd_bss_start {
2771 struct mwl8k_cmd_pkt header;
2772 __le32 enable;
2773} __attribute__((packed));
2774
2775static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, int enable)
2776{
2777 struct mwl8k_cmd_bss_start *cmd;
2778 int rc;
2779
2780 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2781 if (cmd == NULL)
2782 return -ENOMEM;
2783
2784 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2785 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2786 cmd->enable = cpu_to_le32(enable);
2787
2788 rc = mwl8k_post_cmd(hw, &cmd->header);
2789 kfree(cmd);
2790
2791 return rc;
2792}
2793
2794/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002795 * CMD_SET_NEW_STN.
2796 */
2797struct mwl8k_cmd_set_new_stn {
2798 struct mwl8k_cmd_pkt header;
2799 __le16 aid;
2800 __u8 mac_addr[6];
2801 __le16 stn_id;
2802 __le16 action;
2803 __le16 rsvd;
2804 __le32 legacy_rates;
2805 __u8 ht_rates[4];
2806 __le16 cap_info;
2807 __le16 ht_capabilities_info;
2808 __u8 mac_ht_param_info;
2809 __u8 rev;
2810 __u8 control_channel;
2811 __u8 add_channel;
2812 __le16 op_mode;
2813 __le16 stbc;
2814 __u8 add_qos_info;
2815 __u8 is_qos_sta;
2816 __le32 fw_sta_ptr;
2817} __attribute__((packed));
2818
2819#define MWL8K_STA_ACTION_ADD 0
2820#define MWL8K_STA_ACTION_REMOVE 2
2821
2822static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2823 struct ieee80211_vif *vif,
2824 struct ieee80211_sta *sta)
2825{
2826 struct mwl8k_cmd_set_new_stn *cmd;
2827 int rc;
2828
2829 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2830 if (cmd == NULL)
2831 return -ENOMEM;
2832
2833 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2834 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2835 cmd->aid = cpu_to_le16(sta->aid);
2836 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2837 cmd->stn_id = cpu_to_le16(sta->aid);
2838 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
2839 cmd->legacy_rates = cpu_to_le32(sta->supp_rates[IEEE80211_BAND_2GHZ]);
2840 if (sta->ht_cap.ht_supported) {
2841 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2842 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2843 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2844 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2845 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2846 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2847 ((sta->ht_cap.ampdu_density & 7) << 2);
2848 cmd->is_qos_sta = 1;
2849 }
2850
2851 rc = mwl8k_post_cmd(hw, &cmd->header);
2852 kfree(cmd);
2853
2854 return rc;
2855}
2856
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002857static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2858 struct ieee80211_vif *vif)
2859{
2860 struct mwl8k_cmd_set_new_stn *cmd;
2861 int rc;
2862
2863 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2864 if (cmd == NULL)
2865 return -ENOMEM;
2866
2867 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2868 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2869 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2870
2871 rc = mwl8k_post_cmd(hw, &cmd->header);
2872 kfree(cmd);
2873
2874 return rc;
2875}
2876
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002877static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2878 struct ieee80211_vif *vif, u8 *addr)
2879{
2880 struct mwl8k_cmd_set_new_stn *cmd;
2881 int rc;
2882
2883 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2884 if (cmd == NULL)
2885 return -ENOMEM;
2886
2887 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2888 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2889 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2890 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2891
2892 rc = mwl8k_post_cmd(hw, &cmd->header);
2893 kfree(cmd);
2894
2895 return rc;
2896}
2897
2898/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002899 * CMD_UPDATE_STADB.
2900 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01002901struct ewc_ht_info {
2902 __le16 control1;
2903 __le16 control2;
2904 __le16 control3;
2905} __attribute__((packed));
2906
2907struct peer_capability_info {
2908 /* Peer type - AP vs. STA. */
2909 __u8 peer_type;
2910
2911 /* Basic 802.11 capabilities from assoc resp. */
2912 __le16 basic_caps;
2913
2914 /* Set if peer supports 802.11n high throughput (HT). */
2915 __u8 ht_support;
2916
2917 /* Valid if HT is supported. */
2918 __le16 ht_caps;
2919 __u8 extended_ht_caps;
2920 struct ewc_ht_info ewc_info;
2921
2922 /* Legacy rate table. Intersection of our rates and peer rates. */
2923 __u8 legacy_rates[12];
2924
2925 /* HT rate table. Intersection of our rates and peer rates. */
2926 __u8 ht_rates[16];
2927 __u8 pad[16];
2928
2929 /* If set, interoperability mode, no proprietary extensions. */
2930 __u8 interop;
2931 __u8 pad2;
2932 __u8 station_id;
2933 __le16 amsdu_enabled;
2934} __attribute__((packed));
2935
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002936struct mwl8k_cmd_update_stadb {
2937 struct mwl8k_cmd_pkt header;
2938
2939 /* See STADB_ACTION_TYPE */
2940 __le32 action;
2941
2942 /* Peer MAC address */
2943 __u8 peer_addr[ETH_ALEN];
2944
2945 __le32 reserved;
2946
2947 /* Peer info - valid during add/update. */
2948 struct peer_capability_info peer_info;
2949} __attribute__((packed));
2950
Lennert Buytenheka6804002010-01-04 21:55:42 +01002951#define MWL8K_STA_DB_MODIFY_ENTRY 1
2952#define MWL8K_STA_DB_DEL_ENTRY 2
2953
2954/* Peer Entry flags - used to define the type of the peer node */
2955#define MWL8K_PEER_TYPE_ACCESSPOINT 2
2956
2957static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002958 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002959 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002960{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002961 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01002962 struct peer_capability_info *p;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002963 int rc;
2964
2965 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2966 if (cmd == NULL)
2967 return -ENOMEM;
2968
2969 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2970 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01002971 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002972 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002973
Lennert Buytenheka6804002010-01-04 21:55:42 +01002974 p = &cmd->peer_info;
2975 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2976 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002977 p->ht_support = sta->ht_cap.ht_supported;
2978 p->ht_caps = sta->ht_cap.cap;
2979 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
2980 ((sta->ht_cap.ampdu_density & 7) << 2);
2981 legacy_rate_mask_to_array(p->legacy_rates,
2982 sta->supp_rates[IEEE80211_BAND_2GHZ]);
2983 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01002984 p->interop = 1;
2985 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002986
Lennert Buytenheka6804002010-01-04 21:55:42 +01002987 rc = mwl8k_post_cmd(hw, &cmd->header);
2988 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002989
Lennert Buytenheka6804002010-01-04 21:55:42 +01002990 return rc ? rc : p->station_id;
2991}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002992
Lennert Buytenheka6804002010-01-04 21:55:42 +01002993static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
2994 struct ieee80211_vif *vif, u8 *addr)
2995{
2996 struct mwl8k_cmd_update_stadb *cmd;
2997 int rc;
2998
2999 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3000 if (cmd == NULL)
3001 return -ENOMEM;
3002
3003 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3004 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3005 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
3006 memcpy(cmd->peer_addr, addr, ETH_ALEN);
3007
3008 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003009 kfree(cmd);
3010
3011 return rc;
3012}
3013
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003014
3015/*
3016 * Interrupt handling.
3017 */
3018static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
3019{
3020 struct ieee80211_hw *hw = dev_id;
3021 struct mwl8k_priv *priv = hw->priv;
3022 u32 status;
3023
3024 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003025 if (!status)
3026 return IRQ_NONE;
3027
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003028 if (status & MWL8K_A2H_INT_TX_DONE) {
3029 status &= ~MWL8K_A2H_INT_TX_DONE;
3030 tasklet_schedule(&priv->poll_tx_task);
3031 }
3032
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003033 if (status & MWL8K_A2H_INT_RX_READY) {
3034 status &= ~MWL8K_A2H_INT_RX_READY;
3035 tasklet_schedule(&priv->poll_rx_task);
3036 }
3037
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003038 if (status)
3039 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003040
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003041 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003042 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003043 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003044 }
3045
3046 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003047 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003048 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003049 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003050 }
3051
3052 return IRQ_HANDLED;
3053}
3054
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003055static void mwl8k_tx_poll(unsigned long data)
3056{
3057 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3058 struct mwl8k_priv *priv = hw->priv;
3059 int limit;
3060 int i;
3061
3062 limit = 32;
3063
3064 spin_lock_bh(&priv->tx_lock);
3065
3066 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3067 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3068
3069 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3070 complete(priv->tx_wait);
3071 priv->tx_wait = NULL;
3072 }
3073
3074 spin_unlock_bh(&priv->tx_lock);
3075
3076 if (limit) {
3077 writel(~MWL8K_A2H_INT_TX_DONE,
3078 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3079 } else {
3080 tasklet_schedule(&priv->poll_tx_task);
3081 }
3082}
3083
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003084static void mwl8k_rx_poll(unsigned long data)
3085{
3086 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3087 struct mwl8k_priv *priv = hw->priv;
3088 int limit;
3089
3090 limit = 32;
3091 limit -= rxq_process(hw, 0, limit);
3092 limit -= rxq_refill(hw, 0, limit);
3093
3094 if (limit) {
3095 writel(~MWL8K_A2H_INT_RX_READY,
3096 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3097 } else {
3098 tasklet_schedule(&priv->poll_rx_task);
3099 }
3100}
3101
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003102
3103/*
3104 * Core driver operations.
3105 */
3106static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3107{
3108 struct mwl8k_priv *priv = hw->priv;
3109 int index = skb_get_queue_mapping(skb);
3110 int rc;
3111
Lennert Buytenhek9189c102010-01-12 13:47:32 +01003112 if (!priv->radio_on) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003113 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003114 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003115 dev_kfree_skb(skb);
3116 return NETDEV_TX_OK;
3117 }
3118
3119 rc = mwl8k_txq_xmit(hw, index, skb);
3120
3121 return rc;
3122}
3123
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003124static int mwl8k_start(struct ieee80211_hw *hw)
3125{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003126 struct mwl8k_priv *priv = hw->priv;
3127 int rc;
3128
Joe Perchesa0607fd2009-11-18 23:29:17 -08003129 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003130 IRQF_SHARED, MWL8K_NAME, hw);
3131 if (rc) {
3132 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003133 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003134 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003135 }
3136
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003137 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003138 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003139 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003140
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003141 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003142 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003143
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003144 rc = mwl8k_fw_lock(hw);
3145 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003146 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003147
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003148 if (!priv->ap_fw) {
3149 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003150 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003151
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003152 if (!rc)
3153 rc = mwl8k_cmd_set_pre_scan(hw);
3154
3155 if (!rc)
3156 rc = mwl8k_cmd_set_post_scan(hw,
3157 "\x00\x00\x00\x00\x00\x00");
3158 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003159
3160 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003161 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003162
3163 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003164 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003165
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003166 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003167 }
3168
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003169 if (rc) {
3170 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3171 free_irq(priv->pdev->irq, hw);
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003172 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003173 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003174 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003175
3176 return rc;
3177}
3178
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003179static void mwl8k_stop(struct ieee80211_hw *hw)
3180{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003181 struct mwl8k_priv *priv = hw->priv;
3182 int i;
3183
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003184 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003185
3186 ieee80211_stop_queues(hw);
3187
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003188 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003189 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003190 free_irq(priv->pdev->irq, hw);
3191
3192 /* Stop finalize join worker */
3193 cancel_work_sync(&priv->finalize_join_worker);
3194 if (priv->beacon_skb != NULL)
3195 dev_kfree_skb(priv->beacon_skb);
3196
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003197 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003198 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003199 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003200
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003201 /* Return all skbs to mac80211 */
3202 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01003203 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003204}
3205
3206static int mwl8k_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003207 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003208{
3209 struct mwl8k_priv *priv = hw->priv;
3210 struct mwl8k_vif *mwl8k_vif;
3211
3212 /*
3213 * We only support one active interface at a time.
3214 */
3215 if (priv->vif != NULL)
3216 return -EBUSY;
3217
3218 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003219 * Reject interface creation if sniffer mode is active, as
3220 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003221 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003222 */
3223 if (priv->sniffer_enabled) {
3224 printk(KERN_INFO "%s: unable to create STA "
3225 "interface due to sniffer mode being enabled\n",
3226 wiphy_name(hw->wiphy));
3227 return -EINVAL;
3228 }
3229
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003230 /* Set the mac address. */
3231 mwl8k_cmd_set_mac_addr(hw, vif->addr);
3232
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003233 if (priv->ap_fw)
3234 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3235
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003236 /* Clean out driver private area */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003237 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003238 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
3239
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003240 /* Set Initial sequence number to zero */
3241 mwl8k_vif->seqno = 0;
3242
Johannes Berg1ed32e42009-12-23 13:15:45 +01003243 priv->vif = vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003244
3245 return 0;
3246}
3247
3248static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003249 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003250{
3251 struct mwl8k_priv *priv = hw->priv;
3252
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003253 if (priv->ap_fw)
3254 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3255
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003256 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003257
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003258 priv->vif = NULL;
3259}
3260
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003261static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003262{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003263 struct ieee80211_conf *conf = &hw->conf;
3264 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003265 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003266
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003267 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003268 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003269 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003270 }
3271
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003272 rc = mwl8k_fw_lock(hw);
3273 if (rc)
3274 return rc;
3275
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003276 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003277 if (rc)
3278 goto out;
3279
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003280 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003281 if (rc)
3282 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003283
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003284 if (conf->power_level > 18)
3285 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003286 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003287 if (rc)
3288 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003289
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003290 if (priv->ap_fw) {
3291 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3292 if (!rc)
3293 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3294 } else {
3295 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3296 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003297
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003298out:
3299 mwl8k_fw_unlock(hw);
3300
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003301 return rc;
3302}
3303
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003304static void
3305mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3306 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003307{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003308 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003309 u32 ap_legacy_rates;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003310 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003311 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003312
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003313 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003314 return;
3315
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003316 /*
3317 * No need to capture a beacon if we're no longer associated.
3318 */
3319 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3320 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003321
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003322 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003323 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003324 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003325 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003326 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003327
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003328 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003329
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003330 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003331 if (ap == NULL) {
3332 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003333 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003334 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003335
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003336 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003337 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003338
3339 rcu_read_unlock();
3340 }
3341
3342 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003343 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003344 if (rc)
3345 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003346
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003347 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003348 if (rc)
3349 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003350 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003351
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003352 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003353 rc = mwl8k_set_radio_preamble(hw,
3354 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003355 if (rc)
3356 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003357 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003358
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003359 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003360 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003361 if (rc)
3362 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003363 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003364
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003365 if (vif->bss_conf.assoc &&
3366 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3367 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003368 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003369 if (rc)
3370 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003371 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003372
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003373 if (vif->bss_conf.assoc &&
3374 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003375 /*
3376 * Finalize the join. Tell rx handler to process
3377 * next beacon from our BSSID.
3378 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003379 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003380 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003381 }
3382
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003383out:
3384 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003385}
3386
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003387static void
3388mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3389 struct ieee80211_bss_conf *info, u32 changed)
3390{
3391 int rc;
3392
3393 if (mwl8k_fw_lock(hw))
3394 return;
3395
3396 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3397 rc = mwl8k_set_radio_preamble(hw,
3398 vif->bss_conf.use_short_preamble);
3399 if (rc)
3400 goto out;
3401 }
3402
3403 if (changed & BSS_CHANGED_BASIC_RATES) {
3404 int idx;
3405 int rate;
3406
3407 /*
3408 * Use lowest supported basic rate for multicasts
3409 * and management frames (such as probe responses --
3410 * beacons will always go out at 1 Mb/s).
3411 */
3412 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek777ad372010-01-12 13:48:04 +01003413 rate = idx ? mwl8k_rates_24[idx - 1].hw_value : 2;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003414
3415 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3416 }
3417
3418 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3419 struct sk_buff *skb;
3420
3421 skb = ieee80211_beacon_get(hw, vif);
3422 if (skb != NULL) {
3423 mwl8k_cmd_set_beacon(hw, skb->data, skb->len);
3424 kfree_skb(skb);
3425 }
3426 }
3427
3428 if (changed & BSS_CHANGED_BEACON_ENABLED)
3429 mwl8k_cmd_bss_start(hw, info->enable_beacon);
3430
3431out:
3432 mwl8k_fw_unlock(hw);
3433}
3434
3435static void
3436mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3437 struct ieee80211_bss_conf *info, u32 changed)
3438{
3439 struct mwl8k_priv *priv = hw->priv;
3440
3441 if (!priv->ap_fw)
3442 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3443 else
3444 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3445}
3446
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003447static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3448 int mc_count, struct dev_addr_list *mclist)
3449{
3450 struct mwl8k_cmd_pkt *cmd;
3451
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003452 /*
3453 * Synthesize and return a command packet that programs the
3454 * hardware multicast address filter. At this point we don't
3455 * know whether FIF_ALLMULTI is being requested, but if it is,
3456 * we'll end up throwing this packet away and creating a new
3457 * one in mwl8k_configure_filter().
3458 */
3459 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003460
3461 return (unsigned long)cmd;
3462}
3463
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003464static int
3465mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3466 unsigned int changed_flags,
3467 unsigned int *total_flags)
3468{
3469 struct mwl8k_priv *priv = hw->priv;
3470
3471 /*
3472 * Hardware sniffer mode is mutually exclusive with STA
3473 * operation, so refuse to enable sniffer mode if a STA
3474 * interface is active.
3475 */
3476 if (priv->vif != NULL) {
3477 if (net_ratelimit())
3478 printk(KERN_INFO "%s: not enabling sniffer "
3479 "mode because STA interface is active\n",
3480 wiphy_name(hw->wiphy));
3481 return 0;
3482 }
3483
3484 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003485 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003486 return 0;
3487 priv->sniffer_enabled = true;
3488 }
3489
3490 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3491 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3492 FIF_OTHER_BSS;
3493
3494 return 1;
3495}
3496
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003497static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3498 unsigned int changed_flags,
3499 unsigned int *total_flags,
3500 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003501{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003502 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003503 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3504
3505 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003506 * AP firmware doesn't allow fine-grained control over
3507 * the receive filter.
3508 */
3509 if (priv->ap_fw) {
3510 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3511 kfree(cmd);
3512 return;
3513 }
3514
3515 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003516 * Enable hardware sniffer mode if FIF_CONTROL or
3517 * FIF_OTHER_BSS is requested.
3518 */
3519 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3520 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3521 kfree(cmd);
3522 return;
3523 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003524
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003525 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003526 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003527
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003528 if (mwl8k_fw_lock(hw)) {
3529 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003530 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003531 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003532
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003533 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003534 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003535 priv->sniffer_enabled = false;
3536 }
3537
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003538 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003539 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3540 /*
3541 * Disable the BSS filter.
3542 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003543 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003544 } else {
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003545 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003546
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003547 /*
3548 * Enable the BSS filter.
3549 *
3550 * If there is an active STA interface, use that
3551 * interface's BSSID, otherwise use a dummy one
3552 * (where the OUI part needs to be nonzero for
3553 * the BSSID to be accepted by POST_SCAN).
3554 */
3555 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003556 if (priv->vif != NULL)
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003557 bssid = priv->vif->bss_conf.bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003558
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003559 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003560 }
3561 }
3562
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003563 /*
3564 * If FIF_ALLMULTI is being requested, throw away the command
3565 * packet that ->prepare_multicast() built and replace it with
3566 * a command packet that enables reception of all multicast
3567 * packets.
3568 */
3569 if (*total_flags & FIF_ALLMULTI) {
3570 kfree(cmd);
3571 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3572 }
3573
3574 if (cmd != NULL) {
3575 mwl8k_post_cmd(hw, cmd);
3576 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003577 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003578
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003579 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003580}
3581
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003582static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3583{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003584 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003585}
3586
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003587struct mwl8k_sta_notify_item
3588{
3589 struct list_head list;
3590 struct ieee80211_vif *vif;
3591 enum sta_notify_cmd cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003592 struct ieee80211_sta sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003593};
3594
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003595static void
3596mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3597{
3598 struct mwl8k_priv *priv = hw->priv;
3599
3600 /*
3601 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3602 */
3603 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3604 int rc;
3605
3606 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3607 if (rc >= 0) {
3608 struct ieee80211_sta *sta;
3609
3610 rcu_read_lock();
3611 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3612 if (sta != NULL)
3613 MWL8K_STA(sta)->peer_id = rc;
3614 rcu_read_unlock();
3615 }
3616 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3617 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3618 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3619 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3620 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3621 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3622 }
3623}
3624
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003625static void mwl8k_sta_notify_worker(struct work_struct *work)
3626{
3627 struct mwl8k_priv *priv =
3628 container_of(work, struct mwl8k_priv, sta_notify_worker);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003629 struct ieee80211_hw *hw = priv->hw;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003630
3631 spin_lock_bh(&priv->sta_notify_list_lock);
3632 while (!list_empty(&priv->sta_notify_list)) {
3633 struct mwl8k_sta_notify_item *s;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003634
3635 s = list_entry(priv->sta_notify_list.next,
3636 struct mwl8k_sta_notify_item, list);
3637 list_del(&s->list);
3638
3639 spin_unlock_bh(&priv->sta_notify_list_lock);
3640
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003641 mwl8k_do_sta_notify(hw, s);
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003642 kfree(s);
3643
3644 spin_lock_bh(&priv->sta_notify_list_lock);
3645 }
3646 spin_unlock_bh(&priv->sta_notify_list_lock);
3647}
3648
3649static void
3650mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3651 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3652{
3653 struct mwl8k_priv *priv = hw->priv;
3654 struct mwl8k_sta_notify_item *s;
3655
3656 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3657 return;
3658
3659 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3660 if (s != NULL) {
3661 s->vif = vif;
3662 s->cmd = cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003663 s->sta = *sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003664
3665 spin_lock(&priv->sta_notify_list_lock);
3666 list_add_tail(&s->list, &priv->sta_notify_list);
3667 spin_unlock(&priv->sta_notify_list_lock);
3668
3669 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3670 }
3671}
3672
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003673static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3674 const struct ieee80211_tx_queue_params *params)
3675{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003676 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003677 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003678
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003679 rc = mwl8k_fw_lock(hw);
3680 if (!rc) {
3681 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003682 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003683
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003684 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003685 rc = mwl8k_cmd_set_edca_params(hw, queue,
3686 params->cw_min,
3687 params->cw_max,
3688 params->aifs,
3689 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003690
3691 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003692 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003693
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003694 return rc;
3695}
3696
3697static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3698 struct ieee80211_tx_queue_stats *stats)
3699{
3700 struct mwl8k_priv *priv = hw->priv;
3701 struct mwl8k_tx_queue *txq;
3702 int index;
3703
3704 spin_lock_bh(&priv->tx_lock);
3705 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3706 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003707 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003708 sizeof(struct ieee80211_tx_queue_stats));
3709 }
3710 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003711
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003712 return 0;
3713}
3714
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003715static int mwl8k_get_stats(struct ieee80211_hw *hw,
3716 struct ieee80211_low_level_stats *stats)
3717{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003718 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003719}
3720
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003721static int
3722mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3723 enum ieee80211_ampdu_mlme_action action,
3724 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3725{
3726 switch (action) {
3727 case IEEE80211_AMPDU_RX_START:
3728 case IEEE80211_AMPDU_RX_STOP:
3729 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3730 return -ENOTSUPP;
3731 return 0;
3732 default:
3733 return -ENOTSUPP;
3734 }
3735}
3736
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003737static const struct ieee80211_ops mwl8k_ops = {
3738 .tx = mwl8k_tx,
3739 .start = mwl8k_start,
3740 .stop = mwl8k_stop,
3741 .add_interface = mwl8k_add_interface,
3742 .remove_interface = mwl8k_remove_interface,
3743 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003744 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003745 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003746 .configure_filter = mwl8k_configure_filter,
3747 .set_rts_threshold = mwl8k_set_rts_threshold,
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003748 .sta_notify = mwl8k_sta_notify,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003749 .conf_tx = mwl8k_conf_tx,
3750 .get_tx_stats = mwl8k_get_tx_stats,
3751 .get_stats = mwl8k_get_stats,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003752 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003753};
3754
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003755static void mwl8k_finalize_join_worker(struct work_struct *work)
3756{
3757 struct mwl8k_priv *priv =
3758 container_of(work, struct mwl8k_priv, finalize_join_worker);
3759 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003760
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003761 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len,
3762 priv->vif->bss_conf.dtim_period);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003763 dev_kfree_skb(skb);
3764
3765 priv->beacon_skb = NULL;
3766}
3767
John W. Linvillebcb628d2009-11-06 16:40:16 -05003768enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003769 MWL8363 = 0,
3770 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003771 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003772};
3773
John W. Linvillebcb628d2009-11-06 16:40:16 -05003774static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003775 [MWL8363] = {
3776 .part_name = "88w8363",
3777 .helper_image = "mwl8k/helper_8363.fw",
3778 .fw_image = "mwl8k/fmimage_8363.fw",
3779 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003780 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003781 .part_name = "88w8687",
3782 .helper_image = "mwl8k/helper_8687.fw",
3783 .fw_image = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05003784 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003785 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003786 .part_name = "88w8366",
3787 .helper_image = "mwl8k/helper_8366.fw",
3788 .fw_image = "mwl8k/fmimage_8366.fw",
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003789 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003790 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003791};
3792
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01003793MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3794MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3795MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3796MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3797MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3798MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3799
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003800static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003801 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3802 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003803 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3804 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3805 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01003806 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003807 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003808};
3809MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3810
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003811static int __devinit mwl8k_probe(struct pci_dev *pdev,
3812 const struct pci_device_id *id)
3813{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003814 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003815 struct ieee80211_hw *hw;
3816 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003817 int rc;
3818 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003819
3820 if (!printed_version) {
3821 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3822 printed_version = 1;
3823 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003824
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003825
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003826 rc = pci_enable_device(pdev);
3827 if (rc) {
3828 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3829 MWL8K_NAME);
3830 return rc;
3831 }
3832
3833 rc = pci_request_regions(pdev, MWL8K_NAME);
3834 if (rc) {
3835 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3836 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003837 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003838 }
3839
3840 pci_set_master(pdev);
3841
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003842
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003843 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3844 if (hw == NULL) {
3845 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3846 rc = -ENOMEM;
3847 goto err_free_reg;
3848 }
3849
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003850 SET_IEEE80211_DEV(hw, &pdev->dev);
3851 pci_set_drvdata(pdev, hw);
3852
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003853 priv = hw->priv;
3854 priv->hw = hw;
3855 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003856 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003857
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003858
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003859 priv->sram = pci_iomap(pdev, 0, 0x10000);
3860 if (priv->sram == NULL) {
3861 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003862 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003863 goto err_iounmap;
3864 }
3865
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003866 /*
3867 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3868 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3869 */
3870 priv->regs = pci_iomap(pdev, 1, 0x10000);
3871 if (priv->regs == NULL) {
3872 priv->regs = pci_iomap(pdev, 2, 0x10000);
3873 if (priv->regs == NULL) {
3874 printk(KERN_ERR "%s: Cannot map device registers\n",
3875 wiphy_name(hw->wiphy));
3876 goto err_iounmap;
3877 }
3878 }
3879
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003880
3881 /* Reset firmware and hardware */
3882 mwl8k_hw_reset(priv);
3883
3884 /* Ask userland hotplug daemon for the device firmware */
3885 rc = mwl8k_request_firmware(priv);
3886 if (rc) {
3887 printk(KERN_ERR "%s: Firmware files not found\n",
3888 wiphy_name(hw->wiphy));
3889 goto err_stop_firmware;
3890 }
3891
3892 /* Load firmware into hardware */
3893 rc = mwl8k_load_firmware(hw);
3894 if (rc) {
3895 printk(KERN_ERR "%s: Cannot start firmware\n",
3896 wiphy_name(hw->wiphy));
3897 goto err_stop_firmware;
3898 }
3899
3900 /* Reclaim memory once firmware is successfully loaded */
3901 mwl8k_release_firmware(priv);
3902
3903
Lennert Buytenhek91942232010-01-04 21:53:54 +01003904 if (priv->ap_fw) {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003905 priv->rxd_ops = priv->device_info->ap_rxd_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003906 if (priv->rxd_ops == NULL) {
3907 printk(KERN_ERR "%s: Driver does not have AP "
3908 "firmware image support for this hardware\n",
3909 wiphy_name(hw->wiphy));
3910 goto err_stop_firmware;
3911 }
3912 } else {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003913 priv->rxd_ops = &rxd_sta_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003914 }
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003915
3916 priv->sniffer_enabled = false;
3917 priv->wmm_enabled = false;
3918 priv->pending_tx_pkts = 0;
3919
3920
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003921 /*
3922 * Extra headroom is the size of the required DMA header
3923 * minus the size of the smallest 802.11 frame (CTS frame).
3924 */
3925 hw->extra_tx_headroom =
3926 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3927
3928 hw->channel_change_time = 10;
3929
3930 hw->queues = MWL8K_TX_QUEUES;
3931
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003932 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003933 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003934 hw->vif_data_size = sizeof(struct mwl8k_vif);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003935 hw->sta_data_size = sizeof(struct mwl8k_sta);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003936 priv->vif = NULL;
3937
3938 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003939 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003940 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003941
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003942 /* Station database handling */
3943 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
3944 spin_lock_init(&priv->sta_notify_list_lock);
3945 INIT_LIST_HEAD(&priv->sta_notify_list);
3946
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003947 /* Finalize join worker */
3948 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3949
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003950 /* TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003951 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
3952 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003953 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
3954 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003955
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003956 /* Power management cookie */
3957 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3958 if (priv->cookie == NULL)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003959 goto err_stop_firmware;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003960
3961 rc = mwl8k_rxq_init(hw, 0);
3962 if (rc)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003963 goto err_free_cookie;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003964 rxq_refill(hw, 0, INT_MAX);
3965
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003966 mutex_init(&priv->fw_mutex);
3967 priv->fw_mutex_owner = NULL;
3968 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003969 priv->hostcmd_wait = NULL;
3970
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003971 spin_lock_init(&priv->tx_lock);
3972
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003973 priv->tx_wait = NULL;
3974
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003975 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3976 rc = mwl8k_txq_init(hw, i);
3977 if (rc)
3978 goto err_free_queues;
3979 }
3980
3981 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003982 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003983 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003984 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003985 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3986
Joe Perchesa0607fd2009-11-18 23:29:17 -08003987 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003988 IRQF_SHARED, MWL8K_NAME, hw);
3989 if (rc) {
3990 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003991 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003992 goto err_free_queues;
3993 }
3994
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003995 /*
3996 * Temporarily enable interrupts. Initial firmware host
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003997 * commands use interrupts and avoid polling. Disable
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003998 * interrupts when done.
3999 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004000 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004001
4002 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004003 if (priv->ap_fw) {
4004 rc = mwl8k_cmd_get_hw_spec_ap(hw);
4005 if (!rc)
4006 rc = mwl8k_cmd_set_hw_spec(hw);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01004007
4008 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_AP);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004009 } else {
4010 rc = mwl8k_cmd_get_hw_spec_sta(hw);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01004011
4012 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004013 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004014 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004015 printk(KERN_ERR "%s: Cannot initialise firmware\n",
4016 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004017 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004018 }
4019
4020 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004021 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004022 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004023 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004024 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004025 }
4026
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004027 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004028 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004029 if (rc) {
4030 printk(KERN_ERR "%s: Cannot clear MAC address\n",
4031 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004032 goto err_free_irq;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004033 }
4034
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004035 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004036 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004037 free_irq(priv->pdev->irq, hw);
4038
4039 rc = ieee80211_register_hw(hw);
4040 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004041 printk(KERN_ERR "%s: Cannot register device\n",
4042 wiphy_name(hw->wiphy));
Lennert Buytenhek153458f2010-01-04 21:54:08 +01004043 goto err_free_queues;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004044 }
4045
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02004046 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02004047 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004048 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02004049 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02004050 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4051 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004052
4053 return 0;
4054
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004055err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004056 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004057 free_irq(priv->pdev->irq, hw);
4058
4059err_free_queues:
4060 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4061 mwl8k_txq_deinit(hw, i);
4062 mwl8k_rxq_deinit(hw, 0);
4063
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004064err_free_cookie:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004065 if (priv->cookie != NULL)
4066 pci_free_consistent(priv->pdev, 4,
4067 priv->cookie, priv->cookie_dma);
4068
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004069err_stop_firmware:
4070 mwl8k_hw_reset(priv);
4071 mwl8k_release_firmware(priv);
4072
4073err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004074 if (priv->regs != NULL)
4075 pci_iounmap(pdev, priv->regs);
4076
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004077 if (priv->sram != NULL)
4078 pci_iounmap(pdev, priv->sram);
4079
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004080 pci_set_drvdata(pdev, NULL);
4081 ieee80211_free_hw(hw);
4082
4083err_free_reg:
4084 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004085
4086err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004087 pci_disable_device(pdev);
4088
4089 return rc;
4090}
4091
Joerg Albert230f7af2009-04-18 02:10:45 +02004092static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004093{
4094 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4095}
4096
Joerg Albert230f7af2009-04-18 02:10:45 +02004097static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004098{
4099 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4100 struct mwl8k_priv *priv;
4101 int i;
4102
4103 if (hw == NULL)
4104 return;
4105 priv = hw->priv;
4106
4107 ieee80211_stop_queues(hw);
4108
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02004109 ieee80211_unregister_hw(hw);
4110
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004111 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004112 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004113 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004114
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004115 /* Stop hardware */
4116 mwl8k_hw_reset(priv);
4117
4118 /* Return all skbs to mac80211 */
4119 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004120 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004121
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004122 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4123 mwl8k_txq_deinit(hw, i);
4124
4125 mwl8k_rxq_deinit(hw, 0);
4126
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004127 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004128
4129 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004130 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004131 pci_set_drvdata(pdev, NULL);
4132 ieee80211_free_hw(hw);
4133 pci_release_regions(pdev);
4134 pci_disable_device(pdev);
4135}
4136
4137static struct pci_driver mwl8k_driver = {
4138 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004139 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004140 .probe = mwl8k_probe,
4141 .remove = __devexit_p(mwl8k_remove),
4142 .shutdown = __devexit_p(mwl8k_shutdown),
4143};
4144
4145static int __init mwl8k_init(void)
4146{
4147 return pci_register_driver(&mwl8k_driver);
4148}
4149
4150static void __exit mwl8k_exit(void)
4151{
4152 pci_unregister_driver(&mwl8k_driver);
4153}
4154
4155module_init(mwl8k_init);
4156module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004157
4158MODULE_DESCRIPTION(MWL8K_DESC);
4159MODULE_VERSION(MWL8K_VERSION);
4160MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4161MODULE_LICENSE("GPL");