blob: 28beeaf1f4c645cd243f685047b2549507370670 [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 Buytenheka5fb2972010-01-12 13:51:38 +01005 * Copyright (C) 2008, 2009, 2010 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010023#include <net/mac80211.h>
24#include <linux/moduleparam.h>
25#include <linux/firmware.h>
26#include <linux/workqueue.h>
27
28#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
29#define MWL8K_NAME KBUILD_MODNAME
Lennert Buytenheka5fb2972010-01-12 13:51:38 +010030#define MWL8K_VERSION "0.12"
Lennert Buytenheka66098d2009-03-10 10:13:33 +010031
Lennert Buytenheka66098d2009-03-10 10:13:33 +010032/* Register definitions */
33#define MWL8K_HIU_GEN_PTR 0x00000c10
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020034#define MWL8K_MODE_STA 0x0000005a
35#define MWL8K_MODE_AP 0x000000a5
Lennert Buytenheka66098d2009-03-10 10:13:33 +010036#define MWL8K_HIU_INT_CODE 0x00000c14
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020037#define MWL8K_FWSTA_READY 0xf0f1f2f4
38#define MWL8K_FWAP_READY 0xf1f2f4a5
39#define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
Lennert Buytenheka66098d2009-03-10 10:13:33 +010040#define MWL8K_HIU_SCRATCH 0x00000c40
41
42/* Host->device communications */
43#define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
44#define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
45#define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
46#define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
47#define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020048#define MWL8K_H2A_INT_DUMMY (1 << 20)
49#define MWL8K_H2A_INT_RESET (1 << 15)
50#define MWL8K_H2A_INT_DOORBELL (1 << 1)
51#define MWL8K_H2A_INT_PPA_READY (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010052
53/* Device->host communications */
54#define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
55#define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
56#define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
57#define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
58#define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020059#define MWL8K_A2H_INT_DUMMY (1 << 20)
60#define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
61#define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
62#define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
63#define MWL8K_A2H_INT_RADIO_ON (1 << 6)
64#define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
65#define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
66#define MWL8K_A2H_INT_OPC_DONE (1 << 2)
67#define MWL8K_A2H_INT_RX_READY (1 << 1)
68#define MWL8K_A2H_INT_TX_DONE (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010069
70#define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
71 MWL8K_A2H_INT_CHNL_SWITCHED | \
72 MWL8K_A2H_INT_QUEUE_EMPTY | \
73 MWL8K_A2H_INT_RADAR_DETECT | \
74 MWL8K_A2H_INT_RADIO_ON | \
75 MWL8K_A2H_INT_RADIO_OFF | \
76 MWL8K_A2H_INT_MAC_EVENT | \
77 MWL8K_A2H_INT_OPC_DONE | \
78 MWL8K_A2H_INT_RX_READY | \
79 MWL8K_A2H_INT_TX_DONE)
80
Lennert Buytenheka66098d2009-03-10 10:13:33 +010081#define MWL8K_RX_QUEUES 1
82#define MWL8K_TX_QUEUES 4
83
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020084struct rxd_ops {
85 int rxd_size;
86 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
87 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +010088 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
89 __le16 *qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020090};
91
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020092struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +020093 char *part_name;
94 char *helper_image;
95 char *fw_image;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +010096 struct rxd_ops *ap_rxd_ops;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020097};
98
Lennert Buytenheka66098d2009-03-10 10:13:33 +010099struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200100 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100101
102 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200103 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100104
105 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200106 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100107
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200108 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200109 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200110 struct {
111 struct sk_buff *skb;
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +0900112 DEFINE_DMA_UNMAP_ADDR(dma);
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200113 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100114};
115
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100116struct mwl8k_tx_queue {
117 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200118 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100119
120 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200121 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100122
Kalle Valo8ccbc3b2010-02-07 10:20:52 +0200123 unsigned int len;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200124 struct mwl8k_tx_desc *txd;
125 dma_addr_t txd_dma;
126 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100127};
128
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100129struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100130 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100132
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200133 struct mwl8k_device_info *device_info;
134
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100135 void __iomem *sram;
136 void __iomem *regs;
137
138 /* firmware */
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100139 struct firmware *fw_helper;
140 struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100141
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100142 /* hardware/firmware parameters */
143 bool ap_fw;
144 struct rxd_ops *rxd_ops;
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100145 struct ieee80211_supported_band band_24;
146 struct ieee80211_channel channels_24[14];
147 struct ieee80211_rate rates_24[14];
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100148 struct ieee80211_supported_band band_50;
149 struct ieee80211_channel channels_50[4];
150 struct ieee80211_rate rates_50[9];
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100151 u32 ap_macids_supported;
152 u32 sta_macids_supported;
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100153
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200154 /* firmware access */
155 struct mutex fw_mutex;
156 struct task_struct *fw_mutex_owner;
157 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200158 struct completion *hostcmd_wait;
159
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100160 /* lock held over TX and TX reap */
161 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100162
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200163 /* TX quiesce completion, protected by fw_mutex and tx_lock */
164 struct completion *tx_wait;
165
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100166 /* List of interfaces. */
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +0100167 u32 macids_used;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100168 struct list_head vif_list;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100169
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100170 /* power management status cookie from firmware */
171 u32 *cookie;
172 dma_addr_t cookie_dma;
173
174 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100175 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200176 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100177
178 /*
179 * Running count of TX packets in flight, to avoid
180 * iterating over the transmit rings each time.
181 */
182 int pending_tx_pkts;
183
184 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
185 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
186
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200187 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200188 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200189 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200190 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100191
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100192 /* XXX need to convert this to handle multiple interfaces */
193 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200194 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100195 struct sk_buff *beacon_skb;
196
197 /*
198 * This FJ worker has to be global as it is scheduled from the
199 * RX handler. At this point we don't know which interface it
200 * belongs to until the list of bssids waiting to complete join
201 * is checked.
202 */
203 struct work_struct finalize_join_worker;
204
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100205 /* Tasklet to perform TX reclaim. */
206 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100207
208 /* Tasklet to perform RX. */
209 struct tasklet_struct poll_rx_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100210};
211
212/* Per interface specific private data */
213struct mwl8k_vif {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +0100214 struct list_head list;
215 struct ieee80211_vif *vif;
216
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100217 /* Firmware macid for this vif. */
218 int macid;
219
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100220 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100221 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100222};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200223#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100224
Lennert Buytenheka6804002010-01-04 21:55:42 +0100225struct mwl8k_sta {
226 /* Index into station database. Returned by UPDATE_STADB. */
227 u8 peer_id;
228};
229#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
230
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100231static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100232 { .center_freq = 2412, .hw_value = 1, },
233 { .center_freq = 2417, .hw_value = 2, },
234 { .center_freq = 2422, .hw_value = 3, },
235 { .center_freq = 2427, .hw_value = 4, },
236 { .center_freq = 2432, .hw_value = 5, },
237 { .center_freq = 2437, .hw_value = 6, },
238 { .center_freq = 2442, .hw_value = 7, },
239 { .center_freq = 2447, .hw_value = 8, },
240 { .center_freq = 2452, .hw_value = 9, },
241 { .center_freq = 2457, .hw_value = 10, },
242 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100243 { .center_freq = 2467, .hw_value = 12, },
244 { .center_freq = 2472, .hw_value = 13, },
245 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100246};
247
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100248static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100249 { .bitrate = 10, .hw_value = 2, },
250 { .bitrate = 20, .hw_value = 4, },
251 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200252 { .bitrate = 110, .hw_value = 22, },
253 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100254 { .bitrate = 60, .hw_value = 12, },
255 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100256 { .bitrate = 120, .hw_value = 24, },
257 { .bitrate = 180, .hw_value = 36, },
258 { .bitrate = 240, .hw_value = 48, },
259 { .bitrate = 360, .hw_value = 72, },
260 { .bitrate = 480, .hw_value = 96, },
261 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100262 { .bitrate = 720, .hw_value = 144, },
263};
264
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +0100265static const struct ieee80211_channel mwl8k_channels_50[] = {
266 { .center_freq = 5180, .hw_value = 36, },
267 { .center_freq = 5200, .hw_value = 40, },
268 { .center_freq = 5220, .hw_value = 44, },
269 { .center_freq = 5240, .hw_value = 48, },
270};
271
272static const struct ieee80211_rate mwl8k_rates_50[] = {
273 { .bitrate = 60, .hw_value = 12, },
274 { .bitrate = 90, .hw_value = 18, },
275 { .bitrate = 120, .hw_value = 24, },
276 { .bitrate = 180, .hw_value = 36, },
277 { .bitrate = 240, .hw_value = 48, },
278 { .bitrate = 360, .hw_value = 72, },
279 { .bitrate = 480, .hw_value = 96, },
280 { .bitrate = 540, .hw_value = 108, },
281 { .bitrate = 720, .hw_value = 144, },
282};
283
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100284/* Set or get info from Firmware */
285#define MWL8K_CMD_SET 0x0001
286#define MWL8K_CMD_GET 0x0000
287
288/* Firmware command codes */
289#define MWL8K_CMD_CODE_DNLD 0x0001
290#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200291#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100292#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
293#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200294#define MWL8K_CMD_RADIO_CONTROL 0x001c
295#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200296#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100297#define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100298#define MWL8K_CMD_SET_PRE_SCAN 0x0107
299#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200300#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100301#define MWL8K_CMD_SET_AID 0x010d
302#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200303#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100304#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200305#define MWL8K_CMD_SET_SLOT 0x0114
306#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
307#define MWL8K_CMD_SET_WMM_MODE 0x0123
308#define MWL8K_CMD_MIMO_CONFIG 0x0125
309#define MWL8K_CMD_USE_FIXED_RATE 0x0126
310#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100311#define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200312#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +0100313#define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
314#define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200315#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100316
John W. Linvilleb6037422010-07-20 13:55:00 -0400317static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100318{
John W. Linvilleb6037422010-07-20 13:55:00 -0400319 u16 command = le16_to_cpu(cmd);
320
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100321#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
322 snprintf(buf, bufsize, "%s", #x);\
323 return buf;\
324 } while (0)
John W. Linvilleb6037422010-07-20 13:55:00 -0400325 switch (command & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100326 MWL8K_CMDNAME(CODE_DNLD);
327 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200328 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100329 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
330 MWL8K_CMDNAME(GET_STAT);
331 MWL8K_CMDNAME(RADIO_CONTROL);
332 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200333 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100334 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100335 MWL8K_CMDNAME(SET_PRE_SCAN);
336 MWL8K_CMDNAME(SET_POST_SCAN);
337 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100338 MWL8K_CMDNAME(SET_AID);
339 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200340 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100341 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200342 MWL8K_CMDNAME(SET_SLOT);
343 MWL8K_CMDNAME(SET_EDCA_PARAMS);
344 MWL8K_CMDNAME(SET_WMM_MODE);
345 MWL8K_CMDNAME(MIMO_CONFIG);
346 MWL8K_CMDNAME(USE_FIXED_RATE);
347 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200348 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200349 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100350 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100351 MWL8K_CMDNAME(SET_NEW_STN);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200352 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100353 default:
354 snprintf(buf, bufsize, "0x%x", cmd);
355 }
356#undef MWL8K_CMDNAME
357
358 return buf;
359}
360
361/* Hardware and firmware reset */
362static void mwl8k_hw_reset(struct mwl8k_priv *priv)
363{
364 iowrite32(MWL8K_H2A_INT_RESET,
365 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
366 iowrite32(MWL8K_H2A_INT_RESET,
367 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
368 msleep(20);
369}
370
371/* Release fw image */
372static void mwl8k_release_fw(struct firmware **fw)
373{
374 if (*fw == NULL)
375 return;
376 release_firmware(*fw);
377 *fw = NULL;
378}
379
380static void mwl8k_release_firmware(struct mwl8k_priv *priv)
381{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100382 mwl8k_release_fw(&priv->fw_ucode);
383 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100384}
385
386/* Request fw image */
387static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200388 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100389{
390 /* release current image */
391 if (*fw != NULL)
392 mwl8k_release_fw(fw);
393
394 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200395 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100396}
397
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200398static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100399{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200400 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100401 int rc;
402
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200403 if (di->helper_image != NULL) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100404 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200405 if (rc) {
406 printk(KERN_ERR "%s: Error requesting helper "
407 "firmware file %s\n", pci_name(priv->pdev),
408 di->helper_image);
409 return rc;
410 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100411 }
412
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100413 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100414 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200415 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200416 pci_name(priv->pdev), di->fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100417 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100418 return rc;
419 }
420
421 return 0;
422}
423
424struct mwl8k_cmd_pkt {
425 __le16 code;
426 __le16 length;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100427 __u8 seq_num;
428 __u8 macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100429 __le16 result;
430 char payload[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000431} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100432
433/*
434 * Firmware loading.
435 */
436static int
437mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
438{
439 void __iomem *regs = priv->regs;
440 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100441 int loops;
442
443 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
444 if (pci_dma_mapping_error(priv->pdev, dma_addr))
445 return -ENOMEM;
446
447 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
448 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
449 iowrite32(MWL8K_H2A_INT_DOORBELL,
450 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
451 iowrite32(MWL8K_H2A_INT_DUMMY,
452 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
453
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100454 loops = 1000;
455 do {
456 u32 int_code;
457
458 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
459 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
460 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100461 break;
462 }
463
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200464 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100465 udelay(1);
466 } while (--loops);
467
468 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
469
Lennert Buytenhekd4b705702009-07-16 12:44:45 +0200470 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100471}
472
473static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
474 const u8 *data, size_t length)
475{
476 struct mwl8k_cmd_pkt *cmd;
477 int done;
478 int rc = 0;
479
480 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
481 if (cmd == NULL)
482 return -ENOMEM;
483
484 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
485 cmd->seq_num = 0;
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +0100486 cmd->macid = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100487 cmd->result = 0;
488
489 done = 0;
490 while (length) {
491 int block_size = length > 256 ? 256 : length;
492
493 memcpy(cmd->payload, data + done, block_size);
494 cmd->length = cpu_to_le16(block_size);
495
496 rc = mwl8k_send_fw_load_cmd(priv, cmd,
497 sizeof(*cmd) + block_size);
498 if (rc)
499 break;
500
501 done += block_size;
502 length -= block_size;
503 }
504
505 if (!rc) {
506 cmd->length = 0;
507 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
508 }
509
510 kfree(cmd);
511
512 return rc;
513}
514
515static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
516 const u8 *data, size_t length)
517{
518 unsigned char *buffer;
519 int may_continue, rc = 0;
520 u32 done, prev_block_size;
521
522 buffer = kmalloc(1024, GFP_KERNEL);
523 if (buffer == NULL)
524 return -ENOMEM;
525
526 done = 0;
527 prev_block_size = 0;
528 may_continue = 1000;
529 while (may_continue > 0) {
530 u32 block_size;
531
532 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
533 if (block_size & 1) {
534 block_size &= ~1;
535 may_continue--;
536 } else {
537 done += prev_block_size;
538 length -= prev_block_size;
539 }
540
541 if (block_size > 1024 || block_size > length) {
542 rc = -EOVERFLOW;
543 break;
544 }
545
546 if (length == 0) {
547 rc = 0;
548 break;
549 }
550
551 if (block_size == 0) {
552 rc = -EPROTO;
553 may_continue--;
554 udelay(1);
555 continue;
556 }
557
558 prev_block_size = block_size;
559 memcpy(buffer, data + done, block_size);
560
561 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
562 if (rc)
563 break;
564 }
565
566 if (!rc && length != 0)
567 rc = -EREMOTEIO;
568
569 kfree(buffer);
570
571 return rc;
572}
573
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200574static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100575{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200576 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100577 struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200578 int rc;
579 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100580
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200581 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100582 struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100583
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200584 if (helper == NULL) {
585 printk(KERN_ERR "%s: helper image needed but none "
586 "given\n", pci_name(priv->pdev));
587 return -EINVAL;
588 }
589
590 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100591 if (rc) {
592 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200593 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100594 return rc;
595 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100596 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100597
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200598 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100599 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200600 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100601 }
602
603 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200604 printk(KERN_ERR "%s: unable to load firmware image\n",
605 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100606 return rc;
607 }
608
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100609 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100610
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100611 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100612 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200613 u32 ready_code;
614
615 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
616 if (ready_code == MWL8K_FWAP_READY) {
617 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100618 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200619 } else if (ready_code == MWL8K_FWSTA_READY) {
620 priv->ap_fw = 0;
621 break;
622 }
623
624 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100625 udelay(1);
626 } while (--loops);
627
628 return loops ? 0 : -ETIMEDOUT;
629}
630
631
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100632/* DMA header used by firmware and hardware. */
633struct mwl8k_dma_data {
634 __le16 fwlen;
635 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100636 char data[0];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000637} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100638
639/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100640static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100641{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100642 struct mwl8k_dma_data *tr;
643 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100644
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100645 tr = (struct mwl8k_dma_data *)skb->data;
646 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
647
648 if (hdrlen != sizeof(tr->wh)) {
649 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
650 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
651 *((__le16 *)(tr->data - 2)) = qos;
652 } else {
653 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
654 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100655 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100656
657 if (hdrlen != sizeof(*tr))
658 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100659}
660
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200661static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100662{
663 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100664 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100665 struct mwl8k_dma_data *tr;
666
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100667 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100668 * Add a firmware DMA header; the firmware requires that we
669 * present a 2-byte payload length followed by a 4-address
670 * header (without QoS field), followed (optionally) by any
671 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100672 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100673 wh = (struct ieee80211_hdr *)skb->data;
674
675 hdrlen = ieee80211_hdrlen(wh->frame_control);
676 if (hdrlen != sizeof(*tr))
677 skb_push(skb, sizeof(*tr) - hdrlen);
678
679 if (ieee80211_is_data_qos(wh->frame_control))
680 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100681
682 tr = (struct mwl8k_dma_data *)skb->data;
683 if (wh != &tr->wh)
684 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100685 if (hdrlen != sizeof(tr->wh))
686 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100687
688 /*
689 * Firmware length is the length of the fully formed "802.11
690 * payload". That is, everything except for the 802.11 header.
691 * This includes all crypto material including the MIC.
692 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100693 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100694}
695
696
697/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100698 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200699 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100700struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200701 __le16 pkt_len;
702 __u8 sq2;
703 __u8 rate;
704 __le32 pkt_phys_addr;
705 __le32 next_rxd_phys_addr;
706 __le16 qos_control;
707 __le16 htsig2;
708 __le32 hw_rssi_info;
709 __le32 hw_noise_floor_info;
710 __u8 noise_floor;
711 __u8 pad0[3];
712 __u8 rssi;
713 __u8 rx_status;
714 __u8 channel;
715 __u8 rx_ctrl;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000716} __packed;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200717
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100718#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
719#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
720#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100721
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100722#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200723
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100724static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200725{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100726 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200727
728 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100729 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200730}
731
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100732static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200733{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100734 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200735
736 rxd->pkt_len = cpu_to_le16(len);
737 rxd->pkt_phys_addr = cpu_to_le32(addr);
738 wmb();
739 rxd->rx_ctrl = 0;
740}
741
742static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100743mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
744 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200745{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100746 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200747
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100748 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200749 return -1;
750 rmb();
751
752 memset(status, 0, sizeof(*status));
753
754 status->signal = -rxd->rssi;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200755
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100756 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200757 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100758 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100759 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100760 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200761 } else {
762 int i;
763
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100764 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
765 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200766 status->rate_idx = i;
767 break;
768 }
769 }
770 }
771
Lennert Buytenhek85478342010-01-12 13:48:56 +0100772 if (rxd->channel > 14) {
773 status->band = IEEE80211_BAND_5GHZ;
774 if (!(status->flag & RX_FLAG_HT))
775 status->rate_idx -= 5;
776 } else {
777 status->band = IEEE80211_BAND_2GHZ;
778 }
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200779 status->freq = ieee80211_channel_to_frequency(rxd->channel);
780
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100781 *qos = rxd->qos_control;
782
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200783 return le16_to_cpu(rxd->pkt_len);
784}
785
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100786static struct rxd_ops rxd_8366_ap_ops = {
787 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
788 .rxd_init = mwl8k_rxd_8366_ap_init,
789 .rxd_refill = mwl8k_rxd_8366_ap_refill,
790 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200791};
792
793/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100794 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100795 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100796struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100797 __le16 pkt_len;
798 __u8 link_quality;
799 __u8 noise_level;
800 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200801 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100802 __le16 qos_control;
803 __le16 rate_info;
804 __le32 pad0[4];
805 __u8 rssi;
806 __u8 channel;
807 __le16 pad1;
808 __u8 rx_ctrl;
809 __u8 rx_status;
810 __u8 pad2[2];
Eric Dumazetba2d3582010-06-02 18:10:09 +0000811} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100812
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100813#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
814#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
815#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
816#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
817#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
818#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200819
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100820#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200821
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100822static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200823{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100824 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200825
826 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100827 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200828}
829
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100830static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200831{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100832 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200833
834 rxd->pkt_len = cpu_to_le16(len);
835 rxd->pkt_phys_addr = cpu_to_le32(addr);
836 wmb();
837 rxd->rx_ctrl = 0;
838}
839
840static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100841mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100842 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200843{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100844 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200845 u16 rate_info;
846
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100847 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200848 return -1;
849 rmb();
850
851 rate_info = le16_to_cpu(rxd->rate_info);
852
853 memset(status, 0, sizeof(*status));
854
855 status->signal = -rxd->rssi;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100856 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
857 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200858
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100859 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200860 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100861 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200862 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100863 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200864 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100865 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200866 status->flag |= RX_FLAG_HT;
867
Lennert Buytenhek85478342010-01-12 13:48:56 +0100868 if (rxd->channel > 14) {
869 status->band = IEEE80211_BAND_5GHZ;
870 if (!(status->flag & RX_FLAG_HT))
871 status->rate_idx -= 5;
872 } else {
873 status->band = IEEE80211_BAND_2GHZ;
874 }
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200875 status->freq = ieee80211_channel_to_frequency(rxd->channel);
876
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100877 *qos = rxd->qos_control;
878
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200879 return le16_to_cpu(rxd->pkt_len);
880}
881
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100882static struct rxd_ops rxd_sta_ops = {
883 .rxd_size = sizeof(struct mwl8k_rxd_sta),
884 .rxd_init = mwl8k_rxd_sta_init,
885 .rxd_refill = mwl8k_rxd_sta_refill,
886 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200887};
888
889
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100890#define MWL8K_RX_DESCS 256
891#define MWL8K_RX_MAXSZ 3800
892
893static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
894{
895 struct mwl8k_priv *priv = hw->priv;
896 struct mwl8k_rx_queue *rxq = priv->rxq + index;
897 int size;
898 int i;
899
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200900 rxq->rxd_count = 0;
901 rxq->head = 0;
902 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100903
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200904 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100905
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200906 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
907 if (rxq->rxd == NULL) {
Joe Perchesc96c31e2010-07-26 14:39:58 -0700908 wiphy_err(hw->wiphy, "failed to alloc rx descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100909 return -ENOMEM;
910 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200911 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100912
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200913 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
914 if (rxq->buf == NULL) {
Joe Perchesc96c31e2010-07-26 14:39:58 -0700915 wiphy_err(hw->wiphy, "failed to alloc rx skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200916 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100917 return -ENOMEM;
918 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200919 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100920
921 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200922 int desc_size;
923 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100924 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200925 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100926
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200927 desc_size = priv->rxd_ops->rxd_size;
928 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100929
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200930 nexti = i + 1;
931 if (nexti == MWL8K_RX_DESCS)
932 nexti = 0;
933 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
934
935 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100936 }
937
938 return 0;
939}
940
941static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
942{
943 struct mwl8k_priv *priv = hw->priv;
944 struct mwl8k_rx_queue *rxq = priv->rxq + index;
945 int refilled;
946
947 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200948 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100949 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200950 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100951 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200952 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100953
954 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
955 if (skb == NULL)
956 break;
957
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200958 addr = pci_map_single(priv->pdev, skb->data,
959 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100960
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200961 rxq->rxd_count++;
962 rx = rxq->tail++;
963 if (rxq->tail == MWL8K_RX_DESCS)
964 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200965 rxq->buf[rx].skb = skb;
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +0900966 dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200967
968 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
969 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100970
971 refilled++;
972 }
973
974 return refilled;
975}
976
977/* Must be called only when the card's reception is completely halted */
978static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
979{
980 struct mwl8k_priv *priv = hw->priv;
981 struct mwl8k_rx_queue *rxq = priv->rxq + index;
982 int i;
983
984 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200985 if (rxq->buf[i].skb != NULL) {
986 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +0900987 dma_unmap_addr(&rxq->buf[i], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200988 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +0900989 dma_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100990
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200991 kfree_skb(rxq->buf[i].skb);
992 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100993 }
994 }
995
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200996 kfree(rxq->buf);
997 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100998
999 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001000 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001001 rxq->rxd, rxq->rxd_dma);
1002 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001003}
1004
1005
1006/*
1007 * Scan a list of BSSIDs to process for finalize join.
1008 * Allows for extension to process multiple BSSIDs.
1009 */
1010static inline int
1011mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
1012{
1013 return priv->capture_beacon &&
1014 ieee80211_is_beacon(wh->frame_control) &&
1015 !compare_ether_addr(wh->addr3, priv->capture_bssid);
1016}
1017
Lennert Buytenhek37797522009-10-22 20:19:45 +02001018static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
1019 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001020{
Lennert Buytenhek37797522009-10-22 20:19:45 +02001021 struct mwl8k_priv *priv = hw->priv;
1022
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001023 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001024 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001025
1026 /*
1027 * Use GFP_ATOMIC as rxq_process is called from
1028 * the primary interrupt handler, memory allocation call
1029 * must not sleep.
1030 */
1031 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
1032 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +02001033 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001034}
1035
1036static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1037{
1038 struct mwl8k_priv *priv = hw->priv;
1039 struct mwl8k_rx_queue *rxq = priv->rxq + index;
1040 int processed;
1041
1042 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001043 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001044 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001045 void *rxd;
1046 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001047 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001048 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001049
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001050 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001051 if (skb == NULL)
1052 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001053
1054 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1055
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001056 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001057 if (pkt_len < 0)
1058 break;
1059
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001060 rxq->buf[rxq->head].skb = NULL;
1061
1062 pci_unmap_single(priv->pdev,
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001063 dma_unmap_addr(&rxq->buf[rxq->head], dma),
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001064 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
FUJITA Tomonori53b1b3e2010-04-02 13:10:38 +09001065 dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001066
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001067 rxq->head++;
1068 if (rxq->head == MWL8K_RX_DESCS)
1069 rxq->head = 0;
1070
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001071 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001072
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001073 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001074 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001075
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001076 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001077 * Check for a pending join operation. Save a
1078 * copy of the beacon and schedule a tasklet to
1079 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001080 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001081 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001082 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001083
Johannes Bergf1d58c22009-06-17 13:13:00 +02001084 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1085 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001086
1087 processed++;
1088 }
1089
1090 return processed;
1091}
1092
1093
1094/*
1095 * Packet transmission.
1096 */
1097
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001098#define MWL8K_TXD_STATUS_OK 0x00000001
1099#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1100#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1101#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001102#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001103
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001104#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1105#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1106#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1107#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1108#define MWL8K_QOS_EOSP 0x0010
1109
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001110struct mwl8k_tx_desc {
1111 __le32 status;
1112 __u8 data_rate;
1113 __u8 tx_priority;
1114 __le16 qos_control;
1115 __le32 pkt_phys_addr;
1116 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001117 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001118 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001119 __le32 reserved;
1120 __le16 rate_info;
1121 __u8 peer_id;
1122 __u8 tx_frag_cnt;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001123} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001124
1125#define MWL8K_TX_DESCS 128
1126
1127static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1128{
1129 struct mwl8k_priv *priv = hw->priv;
1130 struct mwl8k_tx_queue *txq = priv->txq + index;
1131 int size;
1132 int i;
1133
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001134 txq->len = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001135 txq->head = 0;
1136 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001137
1138 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1139
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001140 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1141 if (txq->txd == NULL) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001142 wiphy_err(hw->wiphy, "failed to alloc tx descriptors\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001143 return -ENOMEM;
1144 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001145 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001146
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001147 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1148 if (txq->skb == NULL) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001149 wiphy_err(hw->wiphy, "failed to alloc tx skbuff list\n");
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001150 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001151 return -ENOMEM;
1152 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001153 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001154
1155 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1156 struct mwl8k_tx_desc *tx_desc;
1157 int nexti;
1158
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001159 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001160 nexti = (i + 1) % MWL8K_TX_DESCS;
1161
1162 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001163 tx_desc->next_txd_phys_addr =
1164 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001165 }
1166
1167 return 0;
1168}
1169
1170static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1171{
1172 iowrite32(MWL8K_H2A_INT_PPA_READY,
1173 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1174 iowrite32(MWL8K_H2A_INT_DUMMY,
1175 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1176 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1177}
1178
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001179static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001180{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001181 struct mwl8k_priv *priv = hw->priv;
1182 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001183
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001184 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1185 struct mwl8k_tx_queue *txq = priv->txq + i;
1186 int fw_owned = 0;
1187 int drv_owned = 0;
1188 int unused = 0;
1189 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001190
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001191 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001192 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1193 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001194
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001195 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001196 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001197 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001198 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001199 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001200
1201 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001202 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001203 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001204
Joe Perchesc96c31e2010-07-26 14:39:58 -07001205 wiphy_err(hw->wiphy,
1206 "txq[%d] len=%d head=%d tail=%d "
1207 "fw_owned=%d drv_owned=%d unused=%d\n",
1208 i,
1209 txq->len, txq->head, txq->tail,
1210 fw_owned, drv_owned, unused);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001211 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001212}
1213
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001214/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001215 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001216 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001217#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001218
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001219static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001220{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001221 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001222 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001223 int retry;
1224 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001225
1226 might_sleep();
1227
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001228 /*
1229 * The TX queues are stopped at this point, so this test
1230 * doesn't need to take ->tx_lock.
1231 */
1232 if (!priv->pending_tx_pkts)
1233 return 0;
1234
1235 retry = 0;
1236 rc = 0;
1237
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001238 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001239 priv->tx_wait = &tx_wait;
1240 while (!rc) {
1241 int oldcount;
1242 unsigned long timeout;
1243
1244 oldcount = priv->pending_tx_pkts;
1245
1246 spin_unlock_bh(&priv->tx_lock);
1247 timeout = wait_for_completion_timeout(&tx_wait,
1248 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1249 spin_lock_bh(&priv->tx_lock);
1250
1251 if (timeout) {
1252 WARN_ON(priv->pending_tx_pkts);
1253 if (retry) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001254 wiphy_notice(hw->wiphy, "tx rings drained\n");
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001255 }
1256 break;
1257 }
1258
1259 if (priv->pending_tx_pkts < oldcount) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001260 wiphy_notice(hw->wiphy,
1261 "waiting for tx rings to drain (%d -> %d pkts)\n",
1262 oldcount, priv->pending_tx_pkts);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001263 retry = 1;
1264 continue;
1265 }
1266
1267 priv->tx_wait = NULL;
1268
Joe Perchesc96c31e2010-07-26 14:39:58 -07001269 wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
1270 MWL8K_TX_WAIT_TIMEOUT_MS);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001271 mwl8k_dump_tx_rings(hw);
1272
1273 rc = -ETIMEDOUT;
1274 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001275 spin_unlock_bh(&priv->tx_lock);
1276
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001277 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001278}
1279
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001280#define MWL8K_TXD_SUCCESS(status) \
1281 ((status) & (MWL8K_TXD_STATUS_OK | \
1282 MWL8K_TXD_STATUS_OK_RETRY | \
1283 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001284
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001285static int
1286mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001287{
1288 struct mwl8k_priv *priv = hw->priv;
1289 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001290 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001291
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001292 processed = 0;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001293 while (txq->len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001294 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001295 struct mwl8k_tx_desc *tx_desc;
1296 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001297 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001298 struct sk_buff *skb;
1299 struct ieee80211_tx_info *info;
1300 u32 status;
1301
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001302 tx = txq->head;
1303 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001304
1305 status = le32_to_cpu(tx_desc->status);
1306
1307 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1308 if (!force)
1309 break;
1310 tx_desc->status &=
1311 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1312 }
1313
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001314 txq->head = (tx + 1) % MWL8K_TX_DESCS;
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001315 BUG_ON(txq->len == 0);
1316 txq->len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001317 priv->pending_tx_pkts--;
1318
1319 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001320 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001321 skb = txq->skb[tx];
1322 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001323
1324 BUG_ON(skb == NULL);
1325 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1326
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001327 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001328
1329 /* Mark descriptor as unused */
1330 tx_desc->pkt_phys_addr = 0;
1331 tx_desc->pkt_len = 0;
1332
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001333 info = IEEE80211_SKB_CB(skb);
1334 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001335 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001336 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001337
1338 ieee80211_tx_status_irqsafe(hw, skb);
1339
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001340 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001341 }
1342
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001343 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001344 ieee80211_wake_queue(hw, index);
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001345
1346 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001347}
1348
1349/* must be called only when the card's transmit is completely halted */
1350static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1351{
1352 struct mwl8k_priv *priv = hw->priv;
1353 struct mwl8k_tx_queue *txq = priv->txq + index;
1354
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001355 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001356
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001357 kfree(txq->skb);
1358 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001359
1360 pci_free_consistent(priv->pdev,
1361 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001362 txq->txd, txq->txd_dma);
1363 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001364}
1365
1366static int
1367mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1368{
1369 struct mwl8k_priv *priv = hw->priv;
1370 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001371 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001372 struct ieee80211_hdr *wh;
1373 struct mwl8k_tx_queue *txq;
1374 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001375 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001376 u32 txstatus;
1377 u8 txdatarate;
1378 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001379
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001380 wh = (struct ieee80211_hdr *)skb->data;
1381 if (ieee80211_is_data_qos(wh->frame_control))
1382 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1383 else
1384 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001385
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001386 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001387 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001388
1389 tx_info = IEEE80211_SKB_CB(skb);
1390 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001391
1392 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001393 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001394 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1395 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001396 }
1397
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001398 /* Setup firmware control bit fields for each frame type. */
1399 txstatus = 0;
1400 txdatarate = 0;
1401 if (ieee80211_is_mgmt(wh->frame_control) ||
1402 ieee80211_is_ctl(wh->frame_control)) {
1403 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001404 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001405 } else if (ieee80211_is_data(wh->frame_control)) {
1406 txdatarate = 1;
1407 if (is_multicast_ether_addr(wh->addr1))
1408 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1409
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001410 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001411 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001412 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001413 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001414 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001415 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001416
1417 dma = pci_map_single(priv->pdev, skb->data,
1418 skb->len, PCI_DMA_TODEVICE);
1419
1420 if (pci_dma_mapping_error(priv->pdev, dma)) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001421 wiphy_debug(hw->wiphy,
1422 "failed to dma map skb, dropping TX frame.\n");
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001423 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001424 return NETDEV_TX_OK;
1425 }
1426
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001427 spin_lock_bh(&priv->tx_lock);
1428
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001429 txq = priv->txq + index;
1430
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001431 BUG_ON(txq->skb[txq->tail] != NULL);
1432 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001433
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001434 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001435 tx->data_rate = txdatarate;
1436 tx->tx_priority = index;
1437 tx->qos_control = cpu_to_le16(qos);
1438 tx->pkt_phys_addr = cpu_to_le32(dma);
1439 tx->pkt_len = cpu_to_le16(skb->len);
1440 tx->rate_info = 0;
Lennert Buytenheka6804002010-01-04 21:55:42 +01001441 if (!priv->ap_fw && tx_info->control.sta != NULL)
1442 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1443 else
1444 tx->peer_id = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001445 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001446 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1447
Kalle Valo8ccbc3b2010-02-07 10:20:52 +02001448 txq->len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001449 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001450
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001451 txq->tail++;
1452 if (txq->tail == MWL8K_TX_DESCS)
1453 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001454
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001455 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001456 ieee80211_stop_queue(hw, index);
1457
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001458 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001459
1460 spin_unlock_bh(&priv->tx_lock);
1461
1462 return NETDEV_TX_OK;
1463}
1464
1465
1466/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001467 * Firmware access.
1468 *
1469 * We have the following requirements for issuing firmware commands:
1470 * - Some commands require that the packet transmit path is idle when
1471 * the command is issued. (For simplicity, we'll just quiesce the
1472 * transmit path for every command.)
1473 * - There are certain sequences of commands that need to be issued to
1474 * the hardware sequentially, with no other intervening commands.
1475 *
1476 * This leads to an implementation of a "firmware lock" as a mutex that
1477 * can be taken recursively, and which is taken by both the low-level
1478 * command submission function (mwl8k_post_cmd) as well as any users of
1479 * that function that require issuing of an atomic sequence of commands,
1480 * and quiesces the transmit path whenever it's taken.
1481 */
1482static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1483{
1484 struct mwl8k_priv *priv = hw->priv;
1485
1486 if (priv->fw_mutex_owner != current) {
1487 int rc;
1488
1489 mutex_lock(&priv->fw_mutex);
1490 ieee80211_stop_queues(hw);
1491
1492 rc = mwl8k_tx_wait_empty(hw);
1493 if (rc) {
1494 ieee80211_wake_queues(hw);
1495 mutex_unlock(&priv->fw_mutex);
1496
1497 return rc;
1498 }
1499
1500 priv->fw_mutex_owner = current;
1501 }
1502
1503 priv->fw_mutex_depth++;
1504
1505 return 0;
1506}
1507
1508static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1509{
1510 struct mwl8k_priv *priv = hw->priv;
1511
1512 if (!--priv->fw_mutex_depth) {
1513 ieee80211_wake_queues(hw);
1514 priv->fw_mutex_owner = NULL;
1515 mutex_unlock(&priv->fw_mutex);
1516 }
1517}
1518
1519
1520/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001521 * Command processing.
1522 */
1523
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001524/* Timeout firmware commands after 10s */
1525#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001526
1527static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1528{
1529 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1530 struct mwl8k_priv *priv = hw->priv;
1531 void __iomem *regs = priv->regs;
1532 dma_addr_t dma_addr;
1533 unsigned int dma_size;
1534 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001535 unsigned long timeout = 0;
1536 u8 buf[32];
1537
John W. Linvilleb6037422010-07-20 13:55:00 -04001538 cmd->result = (__force __le16) 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001539 dma_size = le16_to_cpu(cmd->length);
1540 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1541 PCI_DMA_BIDIRECTIONAL);
1542 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1543 return -ENOMEM;
1544
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001545 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001546 if (rc) {
1547 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1548 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001549 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001550 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001551
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001552 priv->hostcmd_wait = &cmd_wait;
1553 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1554 iowrite32(MWL8K_H2A_INT_DOORBELL,
1555 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1556 iowrite32(MWL8K_H2A_INT_DUMMY,
1557 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001558
1559 timeout = wait_for_completion_timeout(&cmd_wait,
1560 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1561
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001562 priv->hostcmd_wait = NULL;
1563
1564 mwl8k_fw_unlock(hw);
1565
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001566 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1567 PCI_DMA_BIDIRECTIONAL);
1568
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001569 if (!timeout) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07001570 wiphy_err(hw->wiphy, "command %s timeout after %u ms\n",
1571 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1572 MWL8K_CMD_TIMEOUT_MS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001573 rc = -ETIMEDOUT;
1574 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001575 int ms;
1576
1577 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1578
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001579 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001580 if (rc)
Joe Perchesc96c31e2010-07-26 14:39:58 -07001581 wiphy_err(hw->wiphy, "command %s error 0x%x\n",
1582 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1583 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001584 else if (ms > 2000)
Joe Perchesc96c31e2010-07-26 14:39:58 -07001585 wiphy_notice(hw->wiphy, "command %s took %d ms\n",
1586 mwl8k_cmd_name(cmd->code,
1587 buf, sizeof(buf)),
1588 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001589 }
1590
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001591 return rc;
1592}
1593
Lennert Buytenhekf57ca9c2010-01-12 13:50:14 +01001594static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
1595 struct ieee80211_vif *vif,
1596 struct mwl8k_cmd_pkt *cmd)
1597{
1598 if (vif != NULL)
1599 cmd->macid = MWL8K_VIF(vif)->macid;
1600 return mwl8k_post_cmd(hw, cmd);
1601}
1602
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001603/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001604 * Setup code shared between STA and AP firmware images.
1605 */
1606static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1607{
1608 struct mwl8k_priv *priv = hw->priv;
1609
1610 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1611 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1612
1613 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1614 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1615
1616 priv->band_24.band = IEEE80211_BAND_2GHZ;
1617 priv->band_24.channels = priv->channels_24;
1618 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1619 priv->band_24.bitrates = priv->rates_24;
1620 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1621
1622 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1623}
1624
Lennert Buytenhek4eae9ed2010-01-12 13:48:32 +01001625static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
1626{
1627 struct mwl8k_priv *priv = hw->priv;
1628
1629 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
1630 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
1631
1632 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
1633 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
1634
1635 priv->band_50.band = IEEE80211_BAND_5GHZ;
1636 priv->band_50.channels = priv->channels_50;
1637 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
1638 priv->band_50.bitrates = priv->rates_50;
1639 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
1640
1641 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
1642}
1643
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001644/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001645 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001646 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001647struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001648 struct mwl8k_cmd_pkt header;
1649 __u8 hw_rev;
1650 __u8 host_interface;
1651 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001652 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001653 __le16 region_code;
1654 __le32 fw_rev;
1655 __le32 ps_cookie;
1656 __le32 caps;
1657 __u8 mcs_bitmap[16];
1658 __le32 rx_queue_ptr;
1659 __le32 num_tx_queues;
1660 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1661 __le32 caps2;
1662 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001663 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001664} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001665
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001666#define MWL8K_CAP_MAX_AMSDU 0x20000000
1667#define MWL8K_CAP_GREENFIELD 0x08000000
1668#define MWL8K_CAP_AMPDU 0x04000000
1669#define MWL8K_CAP_RX_STBC 0x01000000
1670#define MWL8K_CAP_TX_STBC 0x00800000
1671#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1672#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1673#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1674#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1675#define MWL8K_CAP_DELAY_BA 0x00003000
1676#define MWL8K_CAP_MIMO 0x00000200
1677#define MWL8K_CAP_40MHZ 0x00000100
Lennert Buytenhek06953232010-01-12 13:49:41 +01001678#define MWL8K_CAP_BAND_MASK 0x00000007
1679#define MWL8K_CAP_5GHZ 0x00000004
1680#define MWL8K_CAP_2GHZ4 0x00000001
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001681
Lennert Buytenhek06953232010-01-12 13:49:41 +01001682static void
1683mwl8k_set_ht_caps(struct ieee80211_hw *hw,
1684 struct ieee80211_supported_band *band, u32 cap)
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001685{
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001686 int rx_streams;
1687 int tx_streams;
1688
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001689 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001690
1691 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001692 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001693 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001694 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001695 if (cap & MWL8K_CAP_AMPDU) {
1696 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001697 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1698 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001699 }
1700 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001701 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001702 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001703 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001704 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001705 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001706 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001707 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001708 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001709 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001710 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001711 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001712
1713 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1714 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1715
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001716 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001717 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001718 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001719 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001720 band->ht_cap.mcs.rx_mask[2] = 0xff;
1721 band->ht_cap.mcs.rx_mask[4] = 0x01;
1722 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001723
1724 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001725 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1726 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001727 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1728 }
1729}
1730
Lennert Buytenhek06953232010-01-12 13:49:41 +01001731static void
1732mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
1733{
1734 struct mwl8k_priv *priv = hw->priv;
1735
1736 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
1737 mwl8k_setup_2ghz_band(hw);
1738 if (caps & MWL8K_CAP_MIMO)
1739 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
1740 }
1741
1742 if (caps & MWL8K_CAP_5GHZ) {
1743 mwl8k_setup_5ghz_band(hw);
1744 if (caps & MWL8K_CAP_MIMO)
1745 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
1746 }
1747}
1748
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001749static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001750{
1751 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001752 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001753 int rc;
1754 int i;
1755
1756 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1757 if (cmd == NULL)
1758 return -ENOMEM;
1759
1760 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1761 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1762
1763 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1764 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001765 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001766 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001767 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001768 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001769 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001770 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001771
1772 rc = mwl8k_post_cmd(hw, &cmd->header);
1773
1774 if (!rc) {
1775 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1776 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001777 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001778 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek06953232010-01-12 13:49:41 +01001779 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01001780 priv->ap_macids_supported = 0x00000000;
1781 priv->sta_macids_supported = 0x00000001;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001782 }
1783
1784 kfree(cmd);
1785 return rc;
1786}
1787
1788/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001789 * CMD_GET_HW_SPEC (AP version).
1790 */
1791struct mwl8k_cmd_get_hw_spec_ap {
1792 struct mwl8k_cmd_pkt header;
1793 __u8 hw_rev;
1794 __u8 host_interface;
1795 __le16 num_wcb;
1796 __le16 num_mcaddrs;
1797 __u8 perm_addr[ETH_ALEN];
1798 __le16 region_code;
1799 __le16 num_antenna;
1800 __le32 fw_rev;
1801 __le32 wcbbase0;
1802 __le32 rxwrptr;
1803 __le32 rxrdptr;
1804 __le32 ps_cookie;
1805 __le32 wcbbase1;
1806 __le32 wcbbase2;
1807 __le32 wcbbase3;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001808} __packed;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001809
1810static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1811{
1812 struct mwl8k_priv *priv = hw->priv;
1813 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1814 int rc;
1815
1816 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1817 if (cmd == NULL)
1818 return -ENOMEM;
1819
1820 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1821 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1822
1823 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1824 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1825
1826 rc = mwl8k_post_cmd(hw, &cmd->header);
1827
1828 if (!rc) {
1829 int off;
1830
1831 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1832 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1833 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1834 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001835 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01001836 priv->ap_macids_supported = 0x000000ff;
1837 priv->sta_macids_supported = 0x00000000;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001838
1839 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001840 iowrite32(priv->txq[0].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001841
1842 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001843 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001844
1845 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001846 iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001847
1848 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001849 iowrite32(priv->txq[1].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001850
1851 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001852 iowrite32(priv->txq[2].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001853
1854 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
John W. Linvilleb6037422010-07-20 13:55:00 -04001855 iowrite32(priv->txq[3].txd_dma, priv->sram + off);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001856 }
1857
1858 kfree(cmd);
1859 return rc;
1860}
1861
1862/*
1863 * CMD_SET_HW_SPEC.
1864 */
1865struct mwl8k_cmd_set_hw_spec {
1866 struct mwl8k_cmd_pkt header;
1867 __u8 hw_rev;
1868 __u8 host_interface;
1869 __le16 num_mcaddrs;
1870 __u8 perm_addr[ETH_ALEN];
1871 __le16 region_code;
1872 __le32 fw_rev;
1873 __le32 ps_cookie;
1874 __le32 caps;
1875 __le32 rx_queue_ptr;
1876 __le32 num_tx_queues;
1877 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1878 __le32 flags;
1879 __le32 num_tx_desc_per_queue;
1880 __le32 total_rxd;
Eric Dumazetba2d3582010-06-02 18:10:09 +00001881} __packed;
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001882
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001883#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1884#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1885#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001886
1887static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1888{
1889 struct mwl8k_priv *priv = hw->priv;
1890 struct mwl8k_cmd_set_hw_spec *cmd;
1891 int rc;
1892 int i;
1893
1894 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1895 if (cmd == NULL)
1896 return -ENOMEM;
1897
1898 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1899 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1900
1901 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1902 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1903 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1904 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1905 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001906 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1907 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1908 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001909 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1910 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1911
1912 rc = mwl8k_post_cmd(hw, &cmd->header);
1913 kfree(cmd);
1914
1915 return rc;
1916}
1917
1918/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001919 * CMD_MAC_MULTICAST_ADR.
1920 */
1921struct mwl8k_cmd_mac_multicast_adr {
1922 struct mwl8k_cmd_pkt header;
1923 __le16 action;
1924 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001925 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001926};
1927
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001928#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1929#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1930#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1931#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001932
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001933static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001934__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Jiri Pirko22bedad2010-04-01 21:22:57 +00001935 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001936{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001937 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001938 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001939 int size;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001940 int mc_count = 0;
1941
1942 if (mc_list)
1943 mc_count = netdev_hw_addr_list_count(mc_list);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001944
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001945 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001946 allmulti = 1;
1947 mc_count = 0;
1948 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001949
1950 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1951
1952 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001953 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001954 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001955
1956 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1957 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001958 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1959 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001960
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001961 if (allmulti) {
1962 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1963 } else if (mc_count) {
Jiri Pirko22bedad2010-04-01 21:22:57 +00001964 struct netdev_hw_addr *ha;
1965 int i = 0;
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001966
1967 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1968 cmd->numaddr = cpu_to_le16(mc_count);
Jiri Pirko22bedad2010-04-01 21:22:57 +00001969 netdev_hw_addr_list_for_each(ha, mc_list) {
1970 memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001971 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001972 }
1973
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001974 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001975}
1976
1977/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001978 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001979 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001980struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001981 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001982 __le32 stats[64];
Eric Dumazetba2d3582010-06-02 18:10:09 +00001983} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001984
1985#define MWL8K_STAT_ACK_FAILURE 9
1986#define MWL8K_STAT_RTS_FAILURE 12
1987#define MWL8K_STAT_FCS_ERROR 24
1988#define MWL8K_STAT_RTS_SUCCESS 11
1989
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001990static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1991 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001992{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001993 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001994 int rc;
1995
1996 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1997 if (cmd == NULL)
1998 return -ENOMEM;
1999
2000 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
2001 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002002
2003 rc = mwl8k_post_cmd(hw, &cmd->header);
2004 if (!rc) {
2005 stats->dot11ACKFailureCount =
2006 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
2007 stats->dot11RTSFailureCount =
2008 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
2009 stats->dot11FCSErrorCount =
2010 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
2011 stats->dot11RTSSuccessCount =
2012 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
2013 }
2014 kfree(cmd);
2015
2016 return rc;
2017}
2018
2019/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002020 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002021 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002022struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002023 struct mwl8k_cmd_pkt header;
2024 __le16 action;
2025 __le16 control;
2026 __le16 radio_on;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002027} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002028
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002029static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002030mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002031{
2032 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002033 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002034 int rc;
2035
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002036 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002037 return 0;
2038
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002039 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2040 if (cmd == NULL)
2041 return -ENOMEM;
2042
2043 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
2044 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2045 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002046 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002047 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
2048
2049 rc = mwl8k_post_cmd(hw, &cmd->header);
2050 kfree(cmd);
2051
2052 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002053 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002054
2055 return rc;
2056}
2057
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002058static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002059{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002060 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002061}
2062
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002063static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002064{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002065 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02002066}
2067
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002068static int
2069mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
2070{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01002071 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002072
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02002073 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002074
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002075 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002076}
2077
2078/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002079 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002080 */
2081#define MWL8K_TX_POWER_LEVEL_TOTAL 8
2082
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002083struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002084 struct mwl8k_cmd_pkt header;
2085 __le16 action;
2086 __le16 support_level;
2087 __le16 current_level;
2088 __le16 reserved;
2089 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002090} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002091
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002092static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002093{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002094 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002095 int rc;
2096
2097 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2098 if (cmd == NULL)
2099 return -ENOMEM;
2100
2101 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2102 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2103 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2104 cmd->support_level = cpu_to_le16(dBm);
2105
2106 rc = mwl8k_post_cmd(hw, &cmd->header);
2107 kfree(cmd);
2108
2109 return rc;
2110}
2111
2112/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002113 * CMD_RF_ANTENNA.
2114 */
2115struct mwl8k_cmd_rf_antenna {
2116 struct mwl8k_cmd_pkt header;
2117 __le16 antenna;
2118 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002119} __packed;
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002120
2121#define MWL8K_RF_ANTENNA_RX 1
2122#define MWL8K_RF_ANTENNA_TX 2
2123
2124static int
2125mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2126{
2127 struct mwl8k_cmd_rf_antenna *cmd;
2128 int rc;
2129
2130 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2131 if (cmd == NULL)
2132 return -ENOMEM;
2133
2134 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2135 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2136 cmd->antenna = cpu_to_le16(antenna);
2137 cmd->mode = cpu_to_le16(mask);
2138
2139 rc = mwl8k_post_cmd(hw, &cmd->header);
2140 kfree(cmd);
2141
2142 return rc;
2143}
2144
2145/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002146 * CMD_SET_BEACON.
2147 */
2148struct mwl8k_cmd_set_beacon {
2149 struct mwl8k_cmd_pkt header;
2150 __le16 beacon_len;
2151 __u8 beacon[0];
2152};
2153
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002154static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2155 struct ieee80211_vif *vif, u8 *beacon, int len)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002156{
2157 struct mwl8k_cmd_set_beacon *cmd;
2158 int rc;
2159
2160 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2161 if (cmd == NULL)
2162 return -ENOMEM;
2163
2164 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2165 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2166 cmd->beacon_len = cpu_to_le16(len);
2167 memcpy(cmd->beacon, beacon, len);
2168
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002169 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002170 kfree(cmd);
2171
2172 return rc;
2173}
2174
2175/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002176 * CMD_SET_PRE_SCAN.
2177 */
2178struct mwl8k_cmd_set_pre_scan {
2179 struct mwl8k_cmd_pkt header;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002180} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002181
2182static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2183{
2184 struct mwl8k_cmd_set_pre_scan *cmd;
2185 int rc;
2186
2187 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2188 if (cmd == NULL)
2189 return -ENOMEM;
2190
2191 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2192 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2193
2194 rc = mwl8k_post_cmd(hw, &cmd->header);
2195 kfree(cmd);
2196
2197 return rc;
2198}
2199
2200/*
2201 * CMD_SET_POST_SCAN.
2202 */
2203struct mwl8k_cmd_set_post_scan {
2204 struct mwl8k_cmd_pkt header;
2205 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002206 __u8 bssid[ETH_ALEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002207} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002208
2209static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002210mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002211{
2212 struct mwl8k_cmd_set_post_scan *cmd;
2213 int rc;
2214
2215 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2216 if (cmd == NULL)
2217 return -ENOMEM;
2218
2219 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2220 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2221 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002222 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002223
2224 rc = mwl8k_post_cmd(hw, &cmd->header);
2225 kfree(cmd);
2226
2227 return rc;
2228}
2229
2230/*
2231 * CMD_SET_RF_CHANNEL.
2232 */
2233struct mwl8k_cmd_set_rf_channel {
2234 struct mwl8k_cmd_pkt header;
2235 __le16 action;
2236 __u8 current_channel;
2237 __le32 channel_flags;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002238} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002239
2240static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002241 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002242{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002243 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002244 struct mwl8k_cmd_set_rf_channel *cmd;
2245 int rc;
2246
2247 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2248 if (cmd == NULL)
2249 return -ENOMEM;
2250
2251 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2252 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2253 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2254 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002255
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002256 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002257 cmd->channel_flags |= cpu_to_le32(0x00000001);
Lennert Buytenhek42574ea2010-01-12 13:49:18 +01002258 else if (channel->band == IEEE80211_BAND_5GHZ)
2259 cmd->channel_flags |= cpu_to_le32(0x00000004);
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002260
2261 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2262 conf->channel_type == NL80211_CHAN_HT20)
2263 cmd->channel_flags |= cpu_to_le32(0x00000080);
2264 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2265 cmd->channel_flags |= cpu_to_le32(0x000001900);
2266 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2267 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002268
2269 rc = mwl8k_post_cmd(hw, &cmd->header);
2270 kfree(cmd);
2271
2272 return rc;
2273}
2274
2275/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002276 * CMD_SET_AID.
2277 */
2278#define MWL8K_FRAME_PROT_DISABLED 0x00
2279#define MWL8K_FRAME_PROT_11G 0x07
2280#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2281#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2282
2283struct mwl8k_cmd_update_set_aid {
2284 struct mwl8k_cmd_pkt header;
2285 __le16 aid;
2286
2287 /* AP's MAC address (BSSID) */
2288 __u8 bssid[ETH_ALEN];
2289 __le16 protection_mode;
2290 __u8 supp_rates[14];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002291} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002292
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002293static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2294{
2295 int i;
2296 int j;
2297
2298 /*
2299 * Clear nonstandard rates 4 and 13.
2300 */
2301 mask &= 0x1fef;
2302
2303 for (i = 0, j = 0; i < 14; i++) {
2304 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002305 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002306 }
2307}
2308
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002309static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002310mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2311 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002312{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002313 struct mwl8k_cmd_update_set_aid *cmd;
2314 u16 prot_mode;
2315 int rc;
2316
2317 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2318 if (cmd == NULL)
2319 return -ENOMEM;
2320
2321 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2322 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002323 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002324 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002325
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002326 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002327 prot_mode = MWL8K_FRAME_PROT_11G;
2328 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002329 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002330 IEEE80211_HT_OP_MODE_PROTECTION) {
2331 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2332 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2333 break;
2334 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2335 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2336 break;
2337 default:
2338 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2339 break;
2340 }
2341 }
2342 cmd->protection_mode = cpu_to_le16(prot_mode);
2343
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002344 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002345
2346 rc = mwl8k_post_cmd(hw, &cmd->header);
2347 kfree(cmd);
2348
2349 return rc;
2350}
2351
2352/*
2353 * CMD_SET_RATE.
2354 */
2355struct mwl8k_cmd_set_rate {
2356 struct mwl8k_cmd_pkt header;
2357 __u8 legacy_rates[14];
2358
2359 /* Bitmap for supported MCS codes. */
2360 __u8 mcs_set[16];
2361 __u8 reserved[16];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002362} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002363
2364static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002365mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002366 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002367{
2368 struct mwl8k_cmd_set_rate *cmd;
2369 int rc;
2370
2371 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2372 if (cmd == NULL)
2373 return -ENOMEM;
2374
2375 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2376 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002377 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002378 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002379
2380 rc = mwl8k_post_cmd(hw, &cmd->header);
2381 kfree(cmd);
2382
2383 return rc;
2384}
2385
2386/*
2387 * CMD_FINALIZE_JOIN.
2388 */
2389#define MWL8K_FJ_BEACON_MAXLEN 128
2390
2391struct mwl8k_cmd_finalize_join {
2392 struct mwl8k_cmd_pkt header;
2393 __le32 sleep_interval; /* Number of beacon periods to sleep */
2394 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
Eric Dumazetba2d3582010-06-02 18:10:09 +00002395} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002396
2397static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2398 int framelen, int dtim)
2399{
2400 struct mwl8k_cmd_finalize_join *cmd;
2401 struct ieee80211_mgmt *payload = frame;
2402 int payload_len;
2403 int rc;
2404
2405 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2406 if (cmd == NULL)
2407 return -ENOMEM;
2408
2409 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2410 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2411 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2412
2413 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2414 if (payload_len < 0)
2415 payload_len = 0;
2416 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2417 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2418
2419 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2420
2421 rc = mwl8k_post_cmd(hw, &cmd->header);
2422 kfree(cmd);
2423
2424 return rc;
2425}
2426
2427/*
2428 * CMD_SET_RTS_THRESHOLD.
2429 */
2430struct mwl8k_cmd_set_rts_threshold {
2431 struct mwl8k_cmd_pkt header;
2432 __le16 action;
2433 __le16 threshold;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002434} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002435
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002436static int
2437mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002438{
2439 struct mwl8k_cmd_set_rts_threshold *cmd;
2440 int rc;
2441
2442 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2443 if (cmd == NULL)
2444 return -ENOMEM;
2445
2446 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2447 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002448 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2449 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002450
2451 rc = mwl8k_post_cmd(hw, &cmd->header);
2452 kfree(cmd);
2453
2454 return rc;
2455}
2456
2457/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002458 * CMD_SET_SLOT.
2459 */
2460struct mwl8k_cmd_set_slot {
2461 struct mwl8k_cmd_pkt header;
2462 __le16 action;
2463 __u8 short_slot;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002464} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002465
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002466static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002467{
2468 struct mwl8k_cmd_set_slot *cmd;
2469 int rc;
2470
2471 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2472 if (cmd == NULL)
2473 return -ENOMEM;
2474
2475 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2476 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2477 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002478 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002479
2480 rc = mwl8k_post_cmd(hw, &cmd->header);
2481 kfree(cmd);
2482
2483 return rc;
2484}
2485
2486/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002487 * CMD_SET_EDCA_PARAMS.
2488 */
2489struct mwl8k_cmd_set_edca_params {
2490 struct mwl8k_cmd_pkt header;
2491
2492 /* See MWL8K_SET_EDCA_XXX below */
2493 __le16 action;
2494
2495 /* TX opportunity in units of 32 us */
2496 __le16 txop;
2497
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002498 union {
2499 struct {
2500 /* Log exponent of max contention period: 0...15 */
2501 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002502
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002503 /* Log exponent of min contention period: 0...15 */
2504 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002505
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002506 /* Adaptive interframe spacing in units of 32us */
2507 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002508
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002509 /* TX queue to configure */
2510 __u8 txq;
2511 } ap;
2512 struct {
2513 /* Log exponent of max contention period: 0...15 */
2514 __u8 log_cw_max;
2515
2516 /* Log exponent of min contention period: 0...15 */
2517 __u8 log_cw_min;
2518
2519 /* Adaptive interframe spacing in units of 32us */
2520 __u8 aifs;
2521
2522 /* TX queue to configure */
2523 __u8 txq;
2524 } sta;
2525 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00002526} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002527
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002528#define MWL8K_SET_EDCA_CW 0x01
2529#define MWL8K_SET_EDCA_TXOP 0x02
2530#define MWL8K_SET_EDCA_AIFS 0x04
2531
2532#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2533 MWL8K_SET_EDCA_TXOP | \
2534 MWL8K_SET_EDCA_AIFS)
2535
2536static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002537mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2538 __u16 cw_min, __u16 cw_max,
2539 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002540{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002541 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002542 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002543 int rc;
2544
2545 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2546 if (cmd == NULL)
2547 return -ENOMEM;
2548
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002549 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2550 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002551 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2552 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002553 if (priv->ap_fw) {
2554 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2555 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2556 cmd->ap.aifs = aifs;
2557 cmd->ap.txq = qnum;
2558 } else {
2559 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2560 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2561 cmd->sta.aifs = aifs;
2562 cmd->sta.txq = qnum;
2563 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002564
2565 rc = mwl8k_post_cmd(hw, &cmd->header);
2566 kfree(cmd);
2567
2568 return rc;
2569}
2570
2571/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002572 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002573 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002574struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002575 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002576 __le16 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002577} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002578
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002579static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002580{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002581 struct mwl8k_priv *priv = hw->priv;
2582 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002583 int rc;
2584
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002585 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2586 if (cmd == NULL)
2587 return -ENOMEM;
2588
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002589 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002590 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002591 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002592
2593 rc = mwl8k_post_cmd(hw, &cmd->header);
2594 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002595
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002596 if (!rc)
2597 priv->wmm_enabled = enable;
2598
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002599 return rc;
2600}
2601
2602/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002603 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002604 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002605struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002606 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002607 __le32 action;
2608 __u8 rx_antenna_map;
2609 __u8 tx_antenna_map;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002610} __packed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002611
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002612static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002613{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002614 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002615 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002616
2617 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2618 if (cmd == NULL)
2619 return -ENOMEM;
2620
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002621 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002622 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002623 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2624 cmd->rx_antenna_map = rx;
2625 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002626
2627 rc = mwl8k_post_cmd(hw, &cmd->header);
2628 kfree(cmd);
2629
2630 return rc;
2631}
2632
2633/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002634 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002635 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002636struct mwl8k_cmd_use_fixed_rate_sta {
2637 struct mwl8k_cmd_pkt header;
2638 __le32 action;
2639 __le32 allow_rate_drop;
2640 __le32 num_rates;
2641 struct {
2642 __le32 is_ht_rate;
2643 __le32 enable_retry;
2644 __le32 rate;
2645 __le32 retry_count;
2646 } rate_entry[8];
2647 __le32 rate_type;
2648 __le32 reserved1;
2649 __le32 reserved2;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002650} __packed;
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002651
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002652#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002653#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002654
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002655static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002656{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002657 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002658 int rc;
2659
2660 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2661 if (cmd == NULL)
2662 return -ENOMEM;
2663
2664 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2665 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002666 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2667 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002668
2669 rc = mwl8k_post_cmd(hw, &cmd->header);
2670 kfree(cmd);
2671
2672 return rc;
2673}
2674
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002675/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002676 * CMD_USE_FIXED_RATE (AP version).
2677 */
2678struct mwl8k_cmd_use_fixed_rate_ap {
2679 struct mwl8k_cmd_pkt header;
2680 __le32 action;
2681 __le32 allow_rate_drop;
2682 __le32 num_rates;
2683 struct mwl8k_rate_entry_ap {
2684 __le32 is_ht_rate;
2685 __le32 enable_retry;
2686 __le32 rate;
2687 __le32 retry_count;
2688 } rate_entry[4];
2689 u8 multicast_rate;
2690 u8 multicast_rate_type;
2691 u8 management_rate;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002692} __packed;
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002693
2694static int
2695mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2696{
2697 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2698 int rc;
2699
2700 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2701 if (cmd == NULL)
2702 return -ENOMEM;
2703
2704 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2705 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2706 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2707 cmd->multicast_rate = mcast;
2708 cmd->management_rate = mgmt;
2709
2710 rc = mwl8k_post_cmd(hw, &cmd->header);
2711 kfree(cmd);
2712
2713 return rc;
2714}
2715
2716/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002717 * CMD_ENABLE_SNIFFER.
2718 */
2719struct mwl8k_cmd_enable_sniffer {
2720 struct mwl8k_cmd_pkt header;
2721 __le32 action;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002722} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002723
2724static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2725{
2726 struct mwl8k_cmd_enable_sniffer *cmd;
2727 int rc;
2728
2729 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2730 if (cmd == NULL)
2731 return -ENOMEM;
2732
2733 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2734 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2735 cmd->action = cpu_to_le32(!!enable);
2736
2737 rc = mwl8k_post_cmd(hw, &cmd->header);
2738 kfree(cmd);
2739
2740 return rc;
2741}
2742
2743/*
2744 * CMD_SET_MAC_ADDR.
2745 */
2746struct mwl8k_cmd_set_mac_addr {
2747 struct mwl8k_cmd_pkt header;
2748 union {
2749 struct {
2750 __le16 mac_type;
2751 __u8 mac_addr[ETH_ALEN];
2752 } mbss;
2753 __u8 mac_addr[ETH_ALEN];
2754 };
Eric Dumazetba2d3582010-06-02 18:10:09 +00002755} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002756
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002757#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2758#define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
2759#define MWL8K_MAC_TYPE_PRIMARY_AP 2
2760#define MWL8K_MAC_TYPE_SECONDARY_AP 3
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002761
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002762static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
2763 struct ieee80211_vif *vif, u8 *mac)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002764{
2765 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002766 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002767 struct mwl8k_cmd_set_mac_addr *cmd;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002768 int mac_type;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002769 int rc;
2770
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002771 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
2772 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
2773 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
2774 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
2775 else
2776 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
2777 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
2778 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
2779 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
2780 else
2781 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
2782 }
2783
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002784 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2785 if (cmd == NULL)
2786 return -ENOMEM;
2787
2788 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2789 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2790 if (priv->ap_fw) {
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01002791 cmd->mbss.mac_type = cpu_to_le16(mac_type);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002792 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2793 } else {
2794 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2795 }
2796
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002797 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002798 kfree(cmd);
2799
2800 return rc;
2801}
2802
2803/*
2804 * CMD_SET_RATEADAPT_MODE.
2805 */
2806struct mwl8k_cmd_set_rate_adapt_mode {
2807 struct mwl8k_cmd_pkt header;
2808 __le16 action;
2809 __le16 mode;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002810} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002811
2812static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2813{
2814 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2815 int rc;
2816
2817 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2818 if (cmd == NULL)
2819 return -ENOMEM;
2820
2821 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2822 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2823 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2824 cmd->mode = cpu_to_le16(mode);
2825
2826 rc = mwl8k_post_cmd(hw, &cmd->header);
2827 kfree(cmd);
2828
2829 return rc;
2830}
2831
2832/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002833 * CMD_BSS_START.
2834 */
2835struct mwl8k_cmd_bss_start {
2836 struct mwl8k_cmd_pkt header;
2837 __le32 enable;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002838} __packed;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002839
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002840static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
2841 struct ieee80211_vif *vif, int enable)
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002842{
2843 struct mwl8k_cmd_bss_start *cmd;
2844 int rc;
2845
2846 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2847 if (cmd == NULL)
2848 return -ENOMEM;
2849
2850 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2851 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2852 cmd->enable = cpu_to_le32(enable);
2853
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002854 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002855 kfree(cmd);
2856
2857 return rc;
2858}
2859
2860/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002861 * CMD_SET_NEW_STN.
2862 */
2863struct mwl8k_cmd_set_new_stn {
2864 struct mwl8k_cmd_pkt header;
2865 __le16 aid;
2866 __u8 mac_addr[6];
2867 __le16 stn_id;
2868 __le16 action;
2869 __le16 rsvd;
2870 __le32 legacy_rates;
2871 __u8 ht_rates[4];
2872 __le16 cap_info;
2873 __le16 ht_capabilities_info;
2874 __u8 mac_ht_param_info;
2875 __u8 rev;
2876 __u8 control_channel;
2877 __u8 add_channel;
2878 __le16 op_mode;
2879 __le16 stbc;
2880 __u8 add_qos_info;
2881 __u8 is_qos_sta;
2882 __le32 fw_sta_ptr;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002883} __packed;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002884
2885#define MWL8K_STA_ACTION_ADD 0
2886#define MWL8K_STA_ACTION_REMOVE 2
2887
2888static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2889 struct ieee80211_vif *vif,
2890 struct ieee80211_sta *sta)
2891{
2892 struct mwl8k_cmd_set_new_stn *cmd;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01002893 u32 rates;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002894 int rc;
2895
2896 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2897 if (cmd == NULL)
2898 return -ENOMEM;
2899
2900 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2901 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2902 cmd->aid = cpu_to_le16(sta->aid);
2903 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2904 cmd->stn_id = cpu_to_le16(sta->aid);
2905 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01002906 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
2907 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
2908 else
2909 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
2910 cmd->legacy_rates = cpu_to_le32(rates);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002911 if (sta->ht_cap.ht_supported) {
2912 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2913 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2914 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2915 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2916 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2917 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2918 ((sta->ht_cap.ampdu_density & 7) << 2);
2919 cmd->is_qos_sta = 1;
2920 }
2921
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002922 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002923 kfree(cmd);
2924
2925 return rc;
2926}
2927
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002928static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2929 struct ieee80211_vif *vif)
2930{
2931 struct mwl8k_cmd_set_new_stn *cmd;
2932 int rc;
2933
2934 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2935 if (cmd == NULL)
2936 return -ENOMEM;
2937
2938 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2939 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2940 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2941
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002942 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002943 kfree(cmd);
2944
2945 return rc;
2946}
2947
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002948static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2949 struct ieee80211_vif *vif, u8 *addr)
2950{
2951 struct mwl8k_cmd_set_new_stn *cmd;
2952 int rc;
2953
2954 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2955 if (cmd == NULL)
2956 return -ENOMEM;
2957
2958 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2959 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2960 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2961 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2962
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01002963 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002964 kfree(cmd);
2965
2966 return rc;
2967}
2968
2969/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002970 * CMD_UPDATE_STADB.
2971 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01002972struct ewc_ht_info {
2973 __le16 control1;
2974 __le16 control2;
2975 __le16 control3;
Eric Dumazetba2d3582010-06-02 18:10:09 +00002976} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01002977
2978struct peer_capability_info {
2979 /* Peer type - AP vs. STA. */
2980 __u8 peer_type;
2981
2982 /* Basic 802.11 capabilities from assoc resp. */
2983 __le16 basic_caps;
2984
2985 /* Set if peer supports 802.11n high throughput (HT). */
2986 __u8 ht_support;
2987
2988 /* Valid if HT is supported. */
2989 __le16 ht_caps;
2990 __u8 extended_ht_caps;
2991 struct ewc_ht_info ewc_info;
2992
2993 /* Legacy rate table. Intersection of our rates and peer rates. */
2994 __u8 legacy_rates[12];
2995
2996 /* HT rate table. Intersection of our rates and peer rates. */
2997 __u8 ht_rates[16];
2998 __u8 pad[16];
2999
3000 /* If set, interoperability mode, no proprietary extensions. */
3001 __u8 interop;
3002 __u8 pad2;
3003 __u8 station_id;
3004 __le16 amsdu_enabled;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003005} __packed;
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01003006
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003007struct mwl8k_cmd_update_stadb {
3008 struct mwl8k_cmd_pkt header;
3009
3010 /* See STADB_ACTION_TYPE */
3011 __le32 action;
3012
3013 /* Peer MAC address */
3014 __u8 peer_addr[ETH_ALEN];
3015
3016 __le32 reserved;
3017
3018 /* Peer info - valid during add/update. */
3019 struct peer_capability_info peer_info;
Eric Dumazetba2d3582010-06-02 18:10:09 +00003020} __packed;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003021
Lennert Buytenheka6804002010-01-04 21:55:42 +01003022#define MWL8K_STA_DB_MODIFY_ENTRY 1
3023#define MWL8K_STA_DB_DEL_ENTRY 2
3024
3025/* Peer Entry flags - used to define the type of the peer node */
3026#define MWL8K_PEER_TYPE_ACCESSPOINT 2
3027
3028static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003029 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003030 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003031{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003032 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01003033 struct peer_capability_info *p;
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003034 u32 rates;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003035 int rc;
3036
3037 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3038 if (cmd == NULL)
3039 return -ENOMEM;
3040
3041 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3042 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01003043 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003044 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003045
Lennert Buytenheka6804002010-01-04 21:55:42 +01003046 p = &cmd->peer_info;
3047 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
3048 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003049 p->ht_support = sta->ht_cap.ht_supported;
John W. Linvilleb6037422010-07-20 13:55:00 -04003050 p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003051 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
3052 ((sta->ht_cap.ampdu_density & 7) << 2);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003053 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3054 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3055 else
3056 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3057 legacy_rate_mask_to_array(p->legacy_rates, rates);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003058 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003059 p->interop = 1;
3060 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003061
Lennert Buytenheka6804002010-01-04 21:55:42 +01003062 rc = mwl8k_post_cmd(hw, &cmd->header);
3063 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003064
Lennert Buytenheka6804002010-01-04 21:55:42 +01003065 return rc ? rc : p->station_id;
3066}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003067
Lennert Buytenheka6804002010-01-04 21:55:42 +01003068static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
3069 struct ieee80211_vif *vif, u8 *addr)
3070{
3071 struct mwl8k_cmd_update_stadb *cmd;
3072 int rc;
3073
3074 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
3075 if (cmd == NULL)
3076 return -ENOMEM;
3077
3078 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
3079 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3080 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
3081 memcpy(cmd->peer_addr, addr, ETH_ALEN);
3082
3083 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003084 kfree(cmd);
3085
3086 return rc;
3087}
3088
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003089
3090/*
3091 * Interrupt handling.
3092 */
3093static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
3094{
3095 struct ieee80211_hw *hw = dev_id;
3096 struct mwl8k_priv *priv = hw->priv;
3097 u32 status;
3098
3099 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003100 if (!status)
3101 return IRQ_NONE;
3102
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003103 if (status & MWL8K_A2H_INT_TX_DONE) {
3104 status &= ~MWL8K_A2H_INT_TX_DONE;
3105 tasklet_schedule(&priv->poll_tx_task);
3106 }
3107
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003108 if (status & MWL8K_A2H_INT_RX_READY) {
3109 status &= ~MWL8K_A2H_INT_RX_READY;
3110 tasklet_schedule(&priv->poll_rx_task);
3111 }
3112
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003113 if (status)
3114 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003115
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003116 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003117 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003118 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003119 }
3120
3121 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003122 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003123 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003124 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003125 }
3126
3127 return IRQ_HANDLED;
3128}
3129
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003130static void mwl8k_tx_poll(unsigned long data)
3131{
3132 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3133 struct mwl8k_priv *priv = hw->priv;
3134 int limit;
3135 int i;
3136
3137 limit = 32;
3138
3139 spin_lock_bh(&priv->tx_lock);
3140
3141 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3142 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3143
3144 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3145 complete(priv->tx_wait);
3146 priv->tx_wait = NULL;
3147 }
3148
3149 spin_unlock_bh(&priv->tx_lock);
3150
3151 if (limit) {
3152 writel(~MWL8K_A2H_INT_TX_DONE,
3153 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3154 } else {
3155 tasklet_schedule(&priv->poll_tx_task);
3156 }
3157}
3158
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003159static void mwl8k_rx_poll(unsigned long data)
3160{
3161 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3162 struct mwl8k_priv *priv = hw->priv;
3163 int limit;
3164
3165 limit = 32;
3166 limit -= rxq_process(hw, 0, limit);
3167 limit -= rxq_refill(hw, 0, limit);
3168
3169 if (limit) {
3170 writel(~MWL8K_A2H_INT_RX_READY,
3171 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3172 } else {
3173 tasklet_schedule(&priv->poll_rx_task);
3174 }
3175}
3176
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003177
3178/*
3179 * Core driver operations.
3180 */
3181static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3182{
3183 struct mwl8k_priv *priv = hw->priv;
3184 int index = skb_get_queue_mapping(skb);
3185 int rc;
3186
Lennert Buytenhek9189c102010-01-12 13:47:32 +01003187 if (!priv->radio_on) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003188 wiphy_debug(hw->wiphy,
3189 "dropped TX frame since radio disabled\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003190 dev_kfree_skb(skb);
3191 return NETDEV_TX_OK;
3192 }
3193
3194 rc = mwl8k_txq_xmit(hw, index, skb);
3195
3196 return rc;
3197}
3198
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003199static int mwl8k_start(struct ieee80211_hw *hw)
3200{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003201 struct mwl8k_priv *priv = hw->priv;
3202 int rc;
3203
Joe Perchesa0607fd2009-11-18 23:29:17 -08003204 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003205 IRQF_SHARED, MWL8K_NAME, hw);
3206 if (rc) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003207 wiphy_err(hw->wiphy, "failed to register irq handler\n");
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003208 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003209 }
3210
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003211 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003212 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003213 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003214
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003215 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003216 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003217
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003218 rc = mwl8k_fw_lock(hw);
3219 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003220 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003221
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003222 if (!priv->ap_fw) {
3223 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003224 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003225
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003226 if (!rc)
3227 rc = mwl8k_cmd_set_pre_scan(hw);
3228
3229 if (!rc)
3230 rc = mwl8k_cmd_set_post_scan(hw,
3231 "\x00\x00\x00\x00\x00\x00");
3232 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003233
3234 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003235 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003236
3237 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003238 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003239
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003240 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003241 }
3242
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003243 if (rc) {
3244 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3245 free_irq(priv->pdev->irq, hw);
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003246 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003247 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003248 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003249
3250 return rc;
3251}
3252
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003253static void mwl8k_stop(struct ieee80211_hw *hw)
3254{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003255 struct mwl8k_priv *priv = hw->priv;
3256 int i;
3257
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003258 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003259
3260 ieee80211_stop_queues(hw);
3261
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003262 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003263 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003264 free_irq(priv->pdev->irq, hw);
3265
3266 /* Stop finalize join worker */
3267 cancel_work_sync(&priv->finalize_join_worker);
3268 if (priv->beacon_skb != NULL)
3269 dev_kfree_skb(priv->beacon_skb);
3270
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003271 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003272 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003273 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003274
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003275 /* Return all skbs to mac80211 */
3276 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01003277 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003278}
3279
3280static int mwl8k_add_interface(struct ieee80211_hw *hw,
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003281 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003282{
3283 struct mwl8k_priv *priv = hw->priv;
3284 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003285 u32 macids_supported;
3286 int macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003287
3288 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003289 * Reject interface creation if sniffer mode is active, as
3290 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003291 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003292 */
3293 if (priv->sniffer_enabled) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003294 wiphy_info(hw->wiphy,
3295 "unable to create STA interface because sniffer mode is enabled\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003296 return -EINVAL;
3297 }
3298
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003299
3300 switch (vif->type) {
3301 case NL80211_IFTYPE_AP:
3302 macids_supported = priv->ap_macids_supported;
3303 break;
3304 case NL80211_IFTYPE_STATION:
3305 macids_supported = priv->sta_macids_supported;
3306 break;
3307 default:
3308 return -EINVAL;
3309 }
3310
3311 macid = ffs(macids_supported & ~priv->macids_used);
3312 if (!macid--)
3313 return -EBUSY;
3314
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003315 /* Setup driver private area. */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003316 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003317 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003318 mwl8k_vif->vif = vif;
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003319 mwl8k_vif->macid = macid;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003320 mwl8k_vif->seqno = 0;
3321
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003322 /* Set the mac address. */
3323 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
3324
3325 if (priv->ap_fw)
3326 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3327
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003328 priv->macids_used |= 1 << mwl8k_vif->macid;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003329 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003330
3331 return 0;
3332}
3333
3334static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003335 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003336{
3337 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003338 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003339
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003340 if (priv->ap_fw)
3341 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3342
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003343 mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003344
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003345 priv->macids_used &= ~(1 << mwl8k_vif->macid);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003346 list_del(&mwl8k_vif->list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003347}
3348
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003349static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003350{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003351 struct ieee80211_conf *conf = &hw->conf;
3352 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003353 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003354
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003355 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003356 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003357 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003358 }
3359
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003360 rc = mwl8k_fw_lock(hw);
3361 if (rc)
3362 return rc;
3363
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003364 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003365 if (rc)
3366 goto out;
3367
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003368 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003369 if (rc)
3370 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003371
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003372 if (conf->power_level > 18)
3373 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003374 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003375 if (rc)
3376 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003377
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003378 if (priv->ap_fw) {
3379 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3380 if (!rc)
3381 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3382 } else {
3383 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3384 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003385
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003386out:
3387 mwl8k_fw_unlock(hw);
3388
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003389 return rc;
3390}
3391
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003392static void
3393mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3394 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003395{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003396 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003397 u32 ap_legacy_rates;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003398 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003399 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003400
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003401 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003402 return;
3403
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003404 /*
3405 * No need to capture a beacon if we're no longer associated.
3406 */
3407 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3408 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003409
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003410 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003411 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003412 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003413 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003414 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003415
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003416 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003417
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003418 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003419 if (ap == NULL) {
3420 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003421 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003422 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003423
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003424 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
3425 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3426 } else {
3427 ap_legacy_rates =
3428 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3429 }
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003430 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003431
3432 rcu_read_unlock();
3433 }
3434
3435 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003436 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003437 if (rc)
3438 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003439
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003440 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003441 if (rc)
3442 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003443 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003444
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003445 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003446 rc = mwl8k_set_radio_preamble(hw,
3447 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003448 if (rc)
3449 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003450 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003451
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003452 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003453 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003454 if (rc)
3455 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003456 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003457
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003458 if (vif->bss_conf.assoc &&
3459 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3460 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003461 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003462 if (rc)
3463 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003464 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003465
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003466 if (vif->bss_conf.assoc &&
3467 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003468 /*
3469 * Finalize the join. Tell rx handler to process
3470 * next beacon from our BSSID.
3471 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003472 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003473 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003474 }
3475
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003476out:
3477 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003478}
3479
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003480static void
3481mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3482 struct ieee80211_bss_conf *info, u32 changed)
3483{
3484 int rc;
3485
3486 if (mwl8k_fw_lock(hw))
3487 return;
3488
3489 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3490 rc = mwl8k_set_radio_preamble(hw,
3491 vif->bss_conf.use_short_preamble);
3492 if (rc)
3493 goto out;
3494 }
3495
3496 if (changed & BSS_CHANGED_BASIC_RATES) {
3497 int idx;
3498 int rate;
3499
3500 /*
3501 * Use lowest supported basic rate for multicasts
3502 * and management frames (such as probe responses --
3503 * beacons will always go out at 1 Mb/s).
3504 */
3505 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek8707d022010-01-12 13:49:15 +01003506 if (idx)
3507 idx--;
3508
3509 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3510 rate = mwl8k_rates_24[idx].hw_value;
3511 else
3512 rate = mwl8k_rates_50[idx].hw_value;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003513
3514 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3515 }
3516
3517 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3518 struct sk_buff *skb;
3519
3520 skb = ieee80211_beacon_get(hw, vif);
3521 if (skb != NULL) {
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003522 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003523 kfree_skb(skb);
3524 }
3525 }
3526
3527 if (changed & BSS_CHANGED_BEACON_ENABLED)
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01003528 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003529
3530out:
3531 mwl8k_fw_unlock(hw);
3532}
3533
3534static void
3535mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3536 struct ieee80211_bss_conf *info, u32 changed)
3537{
3538 struct mwl8k_priv *priv = hw->priv;
3539
3540 if (!priv->ap_fw)
3541 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3542 else
3543 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3544}
3545
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003546static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
Jiri Pirko22bedad2010-04-01 21:22:57 +00003547 struct netdev_hw_addr_list *mc_list)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003548{
3549 struct mwl8k_cmd_pkt *cmd;
3550
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003551 /*
3552 * Synthesize and return a command packet that programs the
3553 * hardware multicast address filter. At this point we don't
3554 * know whether FIF_ALLMULTI is being requested, but if it is,
3555 * we'll end up throwing this packet away and creating a new
3556 * one in mwl8k_configure_filter().
3557 */
Jiri Pirko22bedad2010-04-01 21:22:57 +00003558 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003559
3560 return (unsigned long)cmd;
3561}
3562
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003563static int
3564mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3565 unsigned int changed_flags,
3566 unsigned int *total_flags)
3567{
3568 struct mwl8k_priv *priv = hw->priv;
3569
3570 /*
3571 * Hardware sniffer mode is mutually exclusive with STA
3572 * operation, so refuse to enable sniffer mode if a STA
3573 * interface is active.
3574 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003575 if (!list_empty(&priv->vif_list)) {
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003576 if (net_ratelimit())
Joe Perchesc96c31e2010-07-26 14:39:58 -07003577 wiphy_info(hw->wiphy,
3578 "not enabling sniffer mode because STA interface is active\n");
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003579 return 0;
3580 }
3581
3582 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003583 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003584 return 0;
3585 priv->sniffer_enabled = true;
3586 }
3587
3588 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3589 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3590 FIF_OTHER_BSS;
3591
3592 return 1;
3593}
3594
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003595static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
3596{
3597 if (!list_empty(&priv->vif_list))
3598 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
3599
3600 return NULL;
3601}
3602
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003603static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3604 unsigned int changed_flags,
3605 unsigned int *total_flags,
3606 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003607{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003608 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003609 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3610
3611 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003612 * AP firmware doesn't allow fine-grained control over
3613 * the receive filter.
3614 */
3615 if (priv->ap_fw) {
3616 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3617 kfree(cmd);
3618 return;
3619 }
3620
3621 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003622 * Enable hardware sniffer mode if FIF_CONTROL or
3623 * FIF_OTHER_BSS is requested.
3624 */
3625 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3626 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3627 kfree(cmd);
3628 return;
3629 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003630
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003631 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003632 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003633
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003634 if (mwl8k_fw_lock(hw)) {
3635 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003636 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003637 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003638
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003639 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003640 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003641 priv->sniffer_enabled = false;
3642 }
3643
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003644 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003645 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3646 /*
3647 * Disable the BSS filter.
3648 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003649 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003650 } else {
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003651 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003652 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003653
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003654 /*
3655 * Enable the BSS filter.
3656 *
3657 * If there is an active STA interface, use that
3658 * interface's BSSID, otherwise use a dummy one
3659 * (where the OUI part needs to be nonzero for
3660 * the BSSID to be accepted by POST_SCAN).
3661 */
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003662 mwl8k_vif = mwl8k_first_vif(priv);
3663 if (mwl8k_vif != NULL)
3664 bssid = mwl8k_vif->vif->bss_conf.bssid;
3665 else
3666 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003667
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003668 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003669 }
3670 }
3671
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003672 /*
3673 * If FIF_ALLMULTI is being requested, throw away the command
3674 * packet that ->prepare_multicast() built and replace it with
3675 * a command packet that enables reception of all multicast
3676 * packets.
3677 */
3678 if (*total_flags & FIF_ALLMULTI) {
3679 kfree(cmd);
Jiri Pirko22bedad2010-04-01 21:22:57 +00003680 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003681 }
3682
3683 if (cmd != NULL) {
3684 mwl8k_post_cmd(hw, cmd);
3685 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003686 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003687
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003688 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003689}
3690
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003691static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3692{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003693 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003694}
3695
Johannes Berg4a6967b2010-02-19 19:18:37 +01003696static int mwl8k_sta_remove(struct ieee80211_hw *hw,
3697 struct ieee80211_vif *vif,
3698 struct ieee80211_sta *sta)
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003699{
3700 struct mwl8k_priv *priv = hw->priv;
3701
Johannes Berg4a6967b2010-02-19 19:18:37 +01003702 if (priv->ap_fw)
3703 return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
3704 else
3705 return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
3706}
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003707
Johannes Berg4a6967b2010-02-19 19:18:37 +01003708static int mwl8k_sta_add(struct ieee80211_hw *hw,
3709 struct ieee80211_vif *vif,
3710 struct ieee80211_sta *sta)
3711{
3712 struct mwl8k_priv *priv = hw->priv;
3713 int ret;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003714
Johannes Berg4a6967b2010-02-19 19:18:37 +01003715 if (!priv->ap_fw) {
3716 ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
3717 if (ret >= 0) {
3718 MWL8K_STA(sta)->peer_id = ret;
3719 return 0;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003720 }
Johannes Berg4a6967b2010-02-19 19:18:37 +01003721
3722 return ret;
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003723 }
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003724
Johannes Berg4a6967b2010-02-19 19:18:37 +01003725 return mwl8k_cmd_set_new_stn_add(hw, vif, sta);
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003726}
3727
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003728static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3729 const struct ieee80211_tx_queue_params *params)
3730{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003731 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003732 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003733
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003734 rc = mwl8k_fw_lock(hw);
3735 if (!rc) {
3736 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003737 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003738
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003739 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003740 rc = mwl8k_cmd_set_edca_params(hw, queue,
3741 params->cw_min,
3742 params->cw_max,
3743 params->aifs,
3744 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003745
3746 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003747 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003748
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003749 return rc;
3750}
3751
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003752static int mwl8k_get_stats(struct ieee80211_hw *hw,
3753 struct ieee80211_low_level_stats *stats)
3754{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003755 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003756}
3757
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003758static int
3759mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3760 enum ieee80211_ampdu_mlme_action action,
3761 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3762{
3763 switch (action) {
3764 case IEEE80211_AMPDU_RX_START:
3765 case IEEE80211_AMPDU_RX_STOP:
3766 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3767 return -ENOTSUPP;
3768 return 0;
3769 default:
3770 return -ENOTSUPP;
3771 }
3772}
3773
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003774static const struct ieee80211_ops mwl8k_ops = {
3775 .tx = mwl8k_tx,
3776 .start = mwl8k_start,
3777 .stop = mwl8k_stop,
3778 .add_interface = mwl8k_add_interface,
3779 .remove_interface = mwl8k_remove_interface,
3780 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003781 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003782 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003783 .configure_filter = mwl8k_configure_filter,
3784 .set_rts_threshold = mwl8k_set_rts_threshold,
Johannes Berg4a6967b2010-02-19 19:18:37 +01003785 .sta_add = mwl8k_sta_add,
3786 .sta_remove = mwl8k_sta_remove,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003787 .conf_tx = mwl8k_conf_tx,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003788 .get_stats = mwl8k_get_stats,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003789 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003790};
3791
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003792static void mwl8k_finalize_join_worker(struct work_struct *work)
3793{
3794 struct mwl8k_priv *priv =
3795 container_of(work, struct mwl8k_priv, finalize_join_worker);
3796 struct sk_buff *skb = priv->beacon_skb;
Johannes Berg56007a02010-01-26 14:19:52 +01003797 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3798 int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
3799 const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
3800 mgmt->u.beacon.variable, len);
3801 int dtim_period = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003802
Johannes Berg56007a02010-01-26 14:19:52 +01003803 if (tim && tim[1] >= 2)
3804 dtim_period = tim[3];
3805
3806 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003807
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003808 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003809 priv->beacon_skb = NULL;
3810}
3811
John W. Linvillebcb628d2009-11-06 16:40:16 -05003812enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003813 MWL8363 = 0,
3814 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003815 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003816};
3817
John W. Linvillebcb628d2009-11-06 16:40:16 -05003818static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003819 [MWL8363] = {
3820 .part_name = "88w8363",
3821 .helper_image = "mwl8k/helper_8363.fw",
3822 .fw_image = "mwl8k/fmimage_8363.fw",
3823 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003824 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003825 .part_name = "88w8687",
3826 .helper_image = "mwl8k/helper_8687.fw",
3827 .fw_image = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05003828 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003829 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003830 .part_name = "88w8366",
3831 .helper_image = "mwl8k/helper_8366.fw",
3832 .fw_image = "mwl8k/fmimage_8366.fw",
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003833 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003834 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003835};
3836
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01003837MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3838MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3839MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3840MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3841MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3842MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3843
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003844static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Benjamin Larssone5868ba2010-03-19 01:46:10 +01003845 { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003846 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3847 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003848 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3849 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3850 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01003851 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003852 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003853};
3854MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3855
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003856static int __devinit mwl8k_probe(struct pci_dev *pdev,
3857 const struct pci_device_id *id)
3858{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003859 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003860 struct ieee80211_hw *hw;
3861 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003862 int rc;
3863 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003864
3865 if (!printed_version) {
3866 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3867 printed_version = 1;
3868 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003869
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003870
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003871 rc = pci_enable_device(pdev);
3872 if (rc) {
3873 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3874 MWL8K_NAME);
3875 return rc;
3876 }
3877
3878 rc = pci_request_regions(pdev, MWL8K_NAME);
3879 if (rc) {
3880 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3881 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003882 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003883 }
3884
3885 pci_set_master(pdev);
3886
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003887
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003888 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3889 if (hw == NULL) {
3890 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3891 rc = -ENOMEM;
3892 goto err_free_reg;
3893 }
3894
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003895 SET_IEEE80211_DEV(hw, &pdev->dev);
3896 pci_set_drvdata(pdev, hw);
3897
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003898 priv = hw->priv;
3899 priv->hw = hw;
3900 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003901 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003902
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003903
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003904 priv->sram = pci_iomap(pdev, 0, 0x10000);
3905 if (priv->sram == NULL) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003906 wiphy_err(hw->wiphy, "cannot map device sram\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003907 goto err_iounmap;
3908 }
3909
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003910 /*
3911 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3912 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3913 */
3914 priv->regs = pci_iomap(pdev, 1, 0x10000);
3915 if (priv->regs == NULL) {
3916 priv->regs = pci_iomap(pdev, 2, 0x10000);
3917 if (priv->regs == NULL) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003918 wiphy_err(hw->wiphy, "cannot map device registers\n");
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003919 goto err_iounmap;
3920 }
3921 }
3922
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003923
3924 /* Reset firmware and hardware */
3925 mwl8k_hw_reset(priv);
3926
3927 /* Ask userland hotplug daemon for the device firmware */
3928 rc = mwl8k_request_firmware(priv);
3929 if (rc) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003930 wiphy_err(hw->wiphy, "firmware files not found\n");
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003931 goto err_stop_firmware;
3932 }
3933
3934 /* Load firmware into hardware */
3935 rc = mwl8k_load_firmware(hw);
3936 if (rc) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003937 wiphy_err(hw->wiphy, "cannot start firmware\n");
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003938 goto err_stop_firmware;
3939 }
3940
3941 /* Reclaim memory once firmware is successfully loaded */
3942 mwl8k_release_firmware(priv);
3943
3944
Lennert Buytenhek91942232010-01-04 21:53:54 +01003945 if (priv->ap_fw) {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003946 priv->rxd_ops = priv->device_info->ap_rxd_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003947 if (priv->rxd_ops == NULL) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003948 wiphy_err(hw->wiphy,
3949 "Driver does not have AP firmware image support for this hardware\n");
Lennert Buytenhek91942232010-01-04 21:53:54 +01003950 goto err_stop_firmware;
3951 }
3952 } else {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003953 priv->rxd_ops = &rxd_sta_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003954 }
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003955
3956 priv->sniffer_enabled = false;
3957 priv->wmm_enabled = false;
3958 priv->pending_tx_pkts = 0;
3959
3960
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003961 /*
3962 * Extra headroom is the size of the required DMA header
3963 * minus the size of the smallest 802.11 frame (CTS frame).
3964 */
3965 hw->extra_tx_headroom =
3966 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3967
3968 hw->channel_change_time = 10;
3969
3970 hw->queues = MWL8K_TX_QUEUES;
3971
John W. Linvillef5c044e2010-04-30 15:37:00 -04003972 /* Set rssi values to dBm */
3973 hw->flags |= IEEE80211_HW_SIGNAL_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003974 hw->vif_data_size = sizeof(struct mwl8k_vif);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003975 hw->sta_data_size = sizeof(struct mwl8k_sta);
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003976
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01003977 priv->macids_used = 0;
Lennert Buytenhekf5bb87c2010-01-12 13:49:51 +01003978 INIT_LIST_HEAD(&priv->vif_list);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003979
3980 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003981 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003982 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003983
3984 /* Finalize join worker */
3985 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3986
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003987 /* TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003988 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
3989 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003990 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
3991 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003992
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003993 /* Power management cookie */
3994 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3995 if (priv->cookie == NULL)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003996 goto err_stop_firmware;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003997
3998 rc = mwl8k_rxq_init(hw, 0);
3999 if (rc)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004000 goto err_free_cookie;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004001 rxq_refill(hw, 0, INT_MAX);
4002
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004003 mutex_init(&priv->fw_mutex);
4004 priv->fw_mutex_owner = NULL;
4005 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02004006 priv->hostcmd_wait = NULL;
4007
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004008 spin_lock_init(&priv->tx_lock);
4009
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02004010 priv->tx_wait = NULL;
4011
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004012 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
4013 rc = mwl8k_txq_init(hw, i);
4014 if (rc)
4015 goto err_free_queues;
4016 }
4017
4018 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004019 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004020 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004021 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004022 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
4023
Joe Perchesa0607fd2009-11-18 23:29:17 -08004024 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004025 IRQF_SHARED, MWL8K_NAME, hw);
4026 if (rc) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004027 wiphy_err(hw->wiphy, "failed to register irq handler\n");
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004028 goto err_free_queues;
4029 }
4030
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004031 /*
4032 * Temporarily enable interrupts. Initial firmware host
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01004033 * commands use interrupts and avoid polling. Disable
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004034 * interrupts when done.
4035 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02004036 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004037
4038 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02004039 if (priv->ap_fw) {
4040 rc = mwl8k_cmd_get_hw_spec_ap(hw);
4041 if (!rc)
4042 rc = mwl8k_cmd_set_hw_spec(hw);
4043 } else {
4044 rc = mwl8k_cmd_get_hw_spec_sta(hw);
4045 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004046 if (rc) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004047 wiphy_err(hw->wiphy, "cannot initialise firmware\n");
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004048 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004049 }
4050
Lennert Buytenhekee0ddf12010-01-12 13:51:30 +01004051 hw->wiphy->interface_modes = 0;
4052 if (priv->ap_macids_supported)
4053 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
4054 if (priv->sta_macids_supported)
4055 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
4056
4057
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004058 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01004059 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004060 if (rc) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004061 wiphy_err(hw->wiphy, "cannot disable\n");
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004062 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004063 }
4064
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004065 /* Clear MAC address */
Lennert Buytenhekaa21d0f2010-01-12 13:50:36 +01004066 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004067 if (rc) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004068 wiphy_err(hw->wiphy, "cannot clear mac address\n");
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004069 goto err_free_irq;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02004070 }
4071
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004072 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004073 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004074 free_irq(priv->pdev->irq, hw);
4075
4076 rc = ieee80211_register_hw(hw);
4077 if (rc) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004078 wiphy_err(hw->wiphy, "cannot register device\n");
Lennert Buytenhek153458f2010-01-04 21:54:08 +01004079 goto err_free_queues;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004080 }
4081
Joe Perchesc96c31e2010-07-26 14:39:58 -07004082 wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
4083 priv->device_info->part_name,
4084 priv->hw_rev, hw->wiphy->perm_addr,
4085 priv->ap_fw ? "AP" : "STA",
4086 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4087 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004088
4089 return 0;
4090
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004091err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004092 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004093 free_irq(priv->pdev->irq, hw);
4094
4095err_free_queues:
4096 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4097 mwl8k_txq_deinit(hw, i);
4098 mwl8k_rxq_deinit(hw, 0);
4099
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004100err_free_cookie:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004101 if (priv->cookie != NULL)
4102 pci_free_consistent(priv->pdev, 4,
4103 priv->cookie, priv->cookie_dma);
4104
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004105err_stop_firmware:
4106 mwl8k_hw_reset(priv);
4107 mwl8k_release_firmware(priv);
4108
4109err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004110 if (priv->regs != NULL)
4111 pci_iounmap(pdev, priv->regs);
4112
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004113 if (priv->sram != NULL)
4114 pci_iounmap(pdev, priv->sram);
4115
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004116 pci_set_drvdata(pdev, NULL);
4117 ieee80211_free_hw(hw);
4118
4119err_free_reg:
4120 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004121
4122err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004123 pci_disable_device(pdev);
4124
4125 return rc;
4126}
4127
Joerg Albert230f7af2009-04-18 02:10:45 +02004128static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004129{
4130 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4131}
4132
Joerg Albert230f7af2009-04-18 02:10:45 +02004133static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004134{
4135 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4136 struct mwl8k_priv *priv;
4137 int i;
4138
4139 if (hw == NULL)
4140 return;
4141 priv = hw->priv;
4142
4143 ieee80211_stop_queues(hw);
4144
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02004145 ieee80211_unregister_hw(hw);
4146
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004147 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004148 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004149 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004150
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004151 /* Stop hardware */
4152 mwl8k_hw_reset(priv);
4153
4154 /* Return all skbs to mac80211 */
4155 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004156 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004157
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004158 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4159 mwl8k_txq_deinit(hw, i);
4160
4161 mwl8k_rxq_deinit(hw, 0);
4162
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004163 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004164
4165 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004166 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004167 pci_set_drvdata(pdev, NULL);
4168 ieee80211_free_hw(hw);
4169 pci_release_regions(pdev);
4170 pci_disable_device(pdev);
4171}
4172
4173static struct pci_driver mwl8k_driver = {
4174 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004175 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004176 .probe = mwl8k_probe,
4177 .remove = __devexit_p(mwl8k_remove),
4178 .shutdown = __devexit_p(mwl8k_shutdown),
4179};
4180
4181static int __init mwl8k_init(void)
4182{
4183 return pci_register_driver(&mwl8k_driver);
4184}
4185
4186static void __exit mwl8k_exit(void)
4187{
4188 pci_unregister_driver(&mwl8k_driver);
4189}
4190
4191module_init(mwl8k_init);
4192module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004193
4194MODULE_DESCRIPTION(MWL8K_DESC);
4195MODULE_VERSION(MWL8K_VERSION);
4196MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4197MODULE_LICENSE("GPL");