blob: f0026f33232d58be459a4fc9e46e0a45f2f76333 [file] [log] [blame]
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004 *
Lennert Buytenheka145d572009-08-18 04:34:26 +02005 * Copyright (C) 2008-2009 Marvell Semiconductor Inc.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/kernel.h>
Lennert Buytenhek3d76e822009-10-22 20:20:16 +020015#include <linux/sched.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010016#include <linux/spinlock.h>
17#include <linux/list.h>
18#include <linux/pci.h>
19#include <linux/delay.h>
20#include <linux/completion.h>
21#include <linux/etherdevice.h>
22#include <net/mac80211.h>
23#include <linux/moduleparam.h>
24#include <linux/firmware.h>
25#include <linux/workqueue.h>
26
27#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
28#define MWL8K_NAME KBUILD_MODNAME
Lennert Buytenhek6976b662010-01-02 10:31:50 +010029#define MWL8K_VERSION "0.11"
Lennert Buytenheka66098d2009-03-10 10:13:33 +010030
Lennert Buytenheka66098d2009-03-10 10:13:33 +010031/* Register definitions */
32#define MWL8K_HIU_GEN_PTR 0x00000c10
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020033#define MWL8K_MODE_STA 0x0000005a
34#define MWL8K_MODE_AP 0x000000a5
Lennert Buytenheka66098d2009-03-10 10:13:33 +010035#define MWL8K_HIU_INT_CODE 0x00000c14
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020036#define MWL8K_FWSTA_READY 0xf0f1f2f4
37#define MWL8K_FWAP_READY 0xf1f2f4a5
38#define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
Lennert Buytenheka66098d2009-03-10 10:13:33 +010039#define MWL8K_HIU_SCRATCH 0x00000c40
40
41/* Host->device communications */
42#define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
43#define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
44#define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
45#define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
46#define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020047#define MWL8K_H2A_INT_DUMMY (1 << 20)
48#define MWL8K_H2A_INT_RESET (1 << 15)
49#define MWL8K_H2A_INT_DOORBELL (1 << 1)
50#define MWL8K_H2A_INT_PPA_READY (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010051
52/* Device->host communications */
53#define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
54#define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
55#define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
56#define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
57#define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020058#define MWL8K_A2H_INT_DUMMY (1 << 20)
59#define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
60#define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
61#define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
62#define MWL8K_A2H_INT_RADIO_ON (1 << 6)
63#define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
64#define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
65#define MWL8K_A2H_INT_OPC_DONE (1 << 2)
66#define MWL8K_A2H_INT_RX_READY (1 << 1)
67#define MWL8K_A2H_INT_TX_DONE (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010068
69#define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
70 MWL8K_A2H_INT_CHNL_SWITCHED | \
71 MWL8K_A2H_INT_QUEUE_EMPTY | \
72 MWL8K_A2H_INT_RADAR_DETECT | \
73 MWL8K_A2H_INT_RADIO_ON | \
74 MWL8K_A2H_INT_RADIO_OFF | \
75 MWL8K_A2H_INT_MAC_EVENT | \
76 MWL8K_A2H_INT_OPC_DONE | \
77 MWL8K_A2H_INT_RX_READY | \
78 MWL8K_A2H_INT_TX_DONE)
79
Lennert Buytenheka66098d2009-03-10 10:13:33 +010080#define MWL8K_RX_QUEUES 1
81#define MWL8K_TX_QUEUES 4
82
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020083struct rxd_ops {
84 int rxd_size;
85 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
86 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +010087 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
88 __le16 *qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020089};
90
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020091struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +020092 char *part_name;
93 char *helper_image;
94 char *fw_image;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +010095 struct rxd_ops *ap_rxd_ops;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020096};
97
Lennert Buytenheka66098d2009-03-10 10:13:33 +010098struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020099 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100100
101 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200102 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100103
104 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200105 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100106
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200107 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200108 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200109 struct {
110 struct sk_buff *skb;
111 DECLARE_PCI_UNMAP_ADDR(dma)
112 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100113};
114
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100115struct mwl8k_tx_queue {
116 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200117 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100118
119 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200120 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100121
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200122 struct ieee80211_tx_queue_stats stats;
123 struct mwl8k_tx_desc *txd;
124 dma_addr_t txd_dma;
125 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100126};
127
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100128struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100129 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100130 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200132 struct mwl8k_device_info *device_info;
133
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100134 void __iomem *sram;
135 void __iomem *regs;
136
137 /* firmware */
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100138 struct firmware *fw_helper;
139 struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100140
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100141 /* hardware/firmware parameters */
142 bool ap_fw;
143 struct rxd_ops *rxd_ops;
144
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200145 /* firmware access */
146 struct mutex fw_mutex;
147 struct task_struct *fw_mutex_owner;
148 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200149 struct completion *hostcmd_wait;
150
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100151 /* lock held over TX and TX reap */
152 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100153
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200154 /* TX quiesce completion, protected by fw_mutex and tx_lock */
155 struct completion *tx_wait;
156
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100157 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100158
159 struct ieee80211_channel *current_channel;
160
161 /* power management status cookie from firmware */
162 u32 *cookie;
163 dma_addr_t cookie_dma;
164
165 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100166 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200167 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100168
169 /*
170 * Running count of TX packets in flight, to avoid
171 * iterating over the transmit rings each time.
172 */
173 int pending_tx_pkts;
174
175 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
176 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
177
178 /* PHY parameters */
179 struct ieee80211_supported_band band;
180 struct ieee80211_channel channels[14];
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100181 struct ieee80211_rate rates[14];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100182
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200183 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200184 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200185 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200186 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100187
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +0100188 struct work_struct sta_notify_worker;
189 spinlock_t sta_notify_list_lock;
190 struct list_head sta_notify_list;
191
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100192 /* XXX need to convert this to handle multiple interfaces */
193 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200194 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100195 struct sk_buff *beacon_skb;
196
197 /*
198 * This FJ worker has to be global as it is scheduled from the
199 * RX handler. At this point we don't know which interface it
200 * belongs to until the list of bssids waiting to complete join
201 * is checked.
202 */
203 struct work_struct finalize_join_worker;
204
205 /* Tasklet to reclaim TX descriptors and buffers after tx */
206 struct tasklet_struct tx_reclaim_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100207};
208
209/* Per interface specific private data */
210struct mwl8k_vif {
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100211 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100212 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100213};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200214#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100215
Lennert Buytenheka6804002010-01-04 21:55:42 +0100216struct mwl8k_sta {
217 /* Index into station database. Returned by UPDATE_STADB. */
218 u8 peer_id;
219};
220#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
221
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100222static const struct ieee80211_channel mwl8k_channels[] = {
223 { .center_freq = 2412, .hw_value = 1, },
224 { .center_freq = 2417, .hw_value = 2, },
225 { .center_freq = 2422, .hw_value = 3, },
226 { .center_freq = 2427, .hw_value = 4, },
227 { .center_freq = 2432, .hw_value = 5, },
228 { .center_freq = 2437, .hw_value = 6, },
229 { .center_freq = 2442, .hw_value = 7, },
230 { .center_freq = 2447, .hw_value = 8, },
231 { .center_freq = 2452, .hw_value = 9, },
232 { .center_freq = 2457, .hw_value = 10, },
233 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100234 { .center_freq = 2467, .hw_value = 12, },
235 { .center_freq = 2472, .hw_value = 13, },
236 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100237};
238
239static const struct ieee80211_rate mwl8k_rates[] = {
240 { .bitrate = 10, .hw_value = 2, },
241 { .bitrate = 20, .hw_value = 4, },
242 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200243 { .bitrate = 110, .hw_value = 22, },
244 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100245 { .bitrate = 60, .hw_value = 12, },
246 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100247 { .bitrate = 120, .hw_value = 24, },
248 { .bitrate = 180, .hw_value = 36, },
249 { .bitrate = 240, .hw_value = 48, },
250 { .bitrate = 360, .hw_value = 72, },
251 { .bitrate = 480, .hw_value = 96, },
252 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100253 { .bitrate = 720, .hw_value = 144, },
254};
255
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100256/* Set or get info from Firmware */
257#define MWL8K_CMD_SET 0x0001
258#define MWL8K_CMD_GET 0x0000
259
260/* Firmware command codes */
261#define MWL8K_CMD_CODE_DNLD 0x0001
262#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200263#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100264#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
265#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200266#define MWL8K_CMD_RADIO_CONTROL 0x001c
267#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200268#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100269#define MWL8K_CMD_SET_PRE_SCAN 0x0107
270#define MWL8K_CMD_SET_POST_SCAN 0x0108
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200271#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100272#define MWL8K_CMD_SET_AID 0x010d
273#define MWL8K_CMD_SET_RATE 0x0110
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200274#define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100275#define MWL8K_CMD_RTS_THRESHOLD 0x0113
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200276#define MWL8K_CMD_SET_SLOT 0x0114
277#define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
278#define MWL8K_CMD_SET_WMM_MODE 0x0123
279#define MWL8K_CMD_MIMO_CONFIG 0x0125
280#define MWL8K_CMD_USE_FIXED_RATE 0x0126
281#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200282#define MWL8K_CMD_SET_MAC_ADDR 0x0202
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200283#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100284#define MWL8K_CMD_SET_NEW_STN 0x1111
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200285#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100286
287static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
288{
289#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
290 snprintf(buf, bufsize, "%s", #x);\
291 return buf;\
292 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200293 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100294 MWL8K_CMDNAME(CODE_DNLD);
295 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba212009-10-22 20:21:30 +0200296 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100297 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
298 MWL8K_CMDNAME(GET_STAT);
299 MWL8K_CMDNAME(RADIO_CONTROL);
300 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200301 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100302 MWL8K_CMDNAME(SET_PRE_SCAN);
303 MWL8K_CMDNAME(SET_POST_SCAN);
304 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100305 MWL8K_CMDNAME(SET_AID);
306 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200307 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100308 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200309 MWL8K_CMDNAME(SET_SLOT);
310 MWL8K_CMDNAME(SET_EDCA_PARAMS);
311 MWL8K_CMDNAME(SET_WMM_MODE);
312 MWL8K_CMDNAME(MIMO_CONFIG);
313 MWL8K_CMDNAME(USE_FIXED_RATE);
314 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200315 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200316 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100317 MWL8K_CMDNAME(SET_NEW_STN);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200318 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100319 default:
320 snprintf(buf, bufsize, "0x%x", cmd);
321 }
322#undef MWL8K_CMDNAME
323
324 return buf;
325}
326
327/* Hardware and firmware reset */
328static void mwl8k_hw_reset(struct mwl8k_priv *priv)
329{
330 iowrite32(MWL8K_H2A_INT_RESET,
331 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
332 iowrite32(MWL8K_H2A_INT_RESET,
333 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
334 msleep(20);
335}
336
337/* Release fw image */
338static void mwl8k_release_fw(struct firmware **fw)
339{
340 if (*fw == NULL)
341 return;
342 release_firmware(*fw);
343 *fw = NULL;
344}
345
346static void mwl8k_release_firmware(struct mwl8k_priv *priv)
347{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100348 mwl8k_release_fw(&priv->fw_ucode);
349 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100350}
351
352/* Request fw image */
353static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200354 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100355{
356 /* release current image */
357 if (*fw != NULL)
358 mwl8k_release_fw(fw);
359
360 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200361 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100362}
363
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200364static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100365{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200366 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100367 int rc;
368
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200369 if (di->helper_image != NULL) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100370 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200371 if (rc) {
372 printk(KERN_ERR "%s: Error requesting helper "
373 "firmware file %s\n", pci_name(priv->pdev),
374 di->helper_image);
375 return rc;
376 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100377 }
378
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100379 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100380 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200381 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200382 pci_name(priv->pdev), di->fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100383 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100384 return rc;
385 }
386
387 return 0;
388}
389
Ben Hutchings7e75b942009-11-07 22:00:57 +0000390MODULE_FIRMWARE("mwl8k/helper_8687.fw");
391MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
392
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100393struct mwl8k_cmd_pkt {
394 __le16 code;
395 __le16 length;
396 __le16 seq_num;
397 __le16 result;
398 char payload[0];
399} __attribute__((packed));
400
401/*
402 * Firmware loading.
403 */
404static int
405mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
406{
407 void __iomem *regs = priv->regs;
408 dma_addr_t dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100409 int loops;
410
411 dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
412 if (pci_dma_mapping_error(priv->pdev, dma_addr))
413 return -ENOMEM;
414
415 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
416 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
417 iowrite32(MWL8K_H2A_INT_DOORBELL,
418 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
419 iowrite32(MWL8K_H2A_INT_DUMMY,
420 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
421
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100422 loops = 1000;
423 do {
424 u32 int_code;
425
426 int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
427 if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
428 iowrite32(0, regs + MWL8K_HIU_INT_CODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100429 break;
430 }
431
Lennert Buytenhek3d76e822009-10-22 20:20:16 +0200432 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100433 udelay(1);
434 } while (--loops);
435
436 pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
437
Lennert Buytenhekd4b705702009-07-16 12:44:45 +0200438 return loops ? 0 : -ETIMEDOUT;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100439}
440
441static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
442 const u8 *data, size_t length)
443{
444 struct mwl8k_cmd_pkt *cmd;
445 int done;
446 int rc = 0;
447
448 cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
449 if (cmd == NULL)
450 return -ENOMEM;
451
452 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
453 cmd->seq_num = 0;
454 cmd->result = 0;
455
456 done = 0;
457 while (length) {
458 int block_size = length > 256 ? 256 : length;
459
460 memcpy(cmd->payload, data + done, block_size);
461 cmd->length = cpu_to_le16(block_size);
462
463 rc = mwl8k_send_fw_load_cmd(priv, cmd,
464 sizeof(*cmd) + block_size);
465 if (rc)
466 break;
467
468 done += block_size;
469 length -= block_size;
470 }
471
472 if (!rc) {
473 cmd->length = 0;
474 rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
475 }
476
477 kfree(cmd);
478
479 return rc;
480}
481
482static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
483 const u8 *data, size_t length)
484{
485 unsigned char *buffer;
486 int may_continue, rc = 0;
487 u32 done, prev_block_size;
488
489 buffer = kmalloc(1024, GFP_KERNEL);
490 if (buffer == NULL)
491 return -ENOMEM;
492
493 done = 0;
494 prev_block_size = 0;
495 may_continue = 1000;
496 while (may_continue > 0) {
497 u32 block_size;
498
499 block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
500 if (block_size & 1) {
501 block_size &= ~1;
502 may_continue--;
503 } else {
504 done += prev_block_size;
505 length -= prev_block_size;
506 }
507
508 if (block_size > 1024 || block_size > length) {
509 rc = -EOVERFLOW;
510 break;
511 }
512
513 if (length == 0) {
514 rc = 0;
515 break;
516 }
517
518 if (block_size == 0) {
519 rc = -EPROTO;
520 may_continue--;
521 udelay(1);
522 continue;
523 }
524
525 prev_block_size = block_size;
526 memcpy(buffer, data + done, block_size);
527
528 rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
529 if (rc)
530 break;
531 }
532
533 if (!rc && length != 0)
534 rc = -EREMOTEIO;
535
536 kfree(buffer);
537
538 return rc;
539}
540
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200541static int mwl8k_load_firmware(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100542{
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200543 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100544 struct firmware *fw = priv->fw_ucode;
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200545 int rc;
546 int loops;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100547
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200548 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100549 struct firmware *helper = priv->fw_helper;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100550
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200551 if (helper == NULL) {
552 printk(KERN_ERR "%s: helper image needed but none "
553 "given\n", pci_name(priv->pdev));
554 return -EINVAL;
555 }
556
557 rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100558 if (rc) {
559 printk(KERN_ERR "%s: unable to load firmware "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200560 "helper image\n", pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100561 return rc;
562 }
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100563 msleep(5);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100564
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200565 rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100566 } else {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200567 rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100568 }
569
570 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200571 printk(KERN_ERR "%s: unable to load firmware image\n",
572 pci_name(priv->pdev));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100573 return rc;
574 }
575
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100576 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100577
Lennert Buytenhek89b872e2009-11-30 18:13:20 +0100578 loops = 500000;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100579 do {
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200580 u32 ready_code;
581
582 ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
583 if (ready_code == MWL8K_FWAP_READY) {
584 priv->ap_fw = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100585 break;
Lennert Buytenhekeae74e62009-10-22 20:20:53 +0200586 } else if (ready_code == MWL8K_FWSTA_READY) {
587 priv->ap_fw = 0;
588 break;
589 }
590
591 cond_resched();
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100592 udelay(1);
593 } while (--loops);
594
595 return loops ? 0 : -ETIMEDOUT;
596}
597
598
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100599/* DMA header used by firmware and hardware. */
600struct mwl8k_dma_data {
601 __le16 fwlen;
602 struct ieee80211_hdr wh;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100603 char data[0];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100604} __attribute__((packed));
605
606/* Routines to add/remove DMA header from skb. */
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100607static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100608{
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100609 struct mwl8k_dma_data *tr;
610 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100611
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100612 tr = (struct mwl8k_dma_data *)skb->data;
613 hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
614
615 if (hdrlen != sizeof(tr->wh)) {
616 if (ieee80211_is_data_qos(tr->wh.frame_control)) {
617 memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
618 *((__le16 *)(tr->data - 2)) = qos;
619 } else {
620 memmove(tr->data - hdrlen, &tr->wh, hdrlen);
621 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100622 }
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100623
624 if (hdrlen != sizeof(*tr))
625 skb_pull(skb, sizeof(*tr) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100626}
627
Lennert Buytenhek76266b22009-07-16 11:07:09 +0200628static inline void mwl8k_add_dma_header(struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100629{
630 struct ieee80211_hdr *wh;
Lennert Buytenhekca009302009-11-30 18:12:20 +0100631 int hdrlen;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100632 struct mwl8k_dma_data *tr;
633
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100634 /*
Lennert Buytenhekca009302009-11-30 18:12:20 +0100635 * Add a firmware DMA header; the firmware requires that we
636 * present a 2-byte payload length followed by a 4-address
637 * header (without QoS field), followed (optionally) by any
638 * WEP/ExtIV header (but only filled in for CCMP).
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100639 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100640 wh = (struct ieee80211_hdr *)skb->data;
641
642 hdrlen = ieee80211_hdrlen(wh->frame_control);
643 if (hdrlen != sizeof(*tr))
644 skb_push(skb, sizeof(*tr) - hdrlen);
645
646 if (ieee80211_is_data_qos(wh->frame_control))
647 hdrlen -= 2;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100648
649 tr = (struct mwl8k_dma_data *)skb->data;
650 if (wh != &tr->wh)
651 memmove(&tr->wh, wh, hdrlen);
Lennert Buytenhekca009302009-11-30 18:12:20 +0100652 if (hdrlen != sizeof(tr->wh))
653 memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100654
655 /*
656 * Firmware length is the length of the fully formed "802.11
657 * payload". That is, everything except for the 802.11 header.
658 * This includes all crypto material including the MIC.
659 */
Lennert Buytenhekca009302009-11-30 18:12:20 +0100660 tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100661}
662
663
664/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100665 * Packet reception for 88w8366 AP firmware.
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200666 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100667struct mwl8k_rxd_8366_ap {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200668 __le16 pkt_len;
669 __u8 sq2;
670 __u8 rate;
671 __le32 pkt_phys_addr;
672 __le32 next_rxd_phys_addr;
673 __le16 qos_control;
674 __le16 htsig2;
675 __le32 hw_rssi_info;
676 __le32 hw_noise_floor_info;
677 __u8 noise_floor;
678 __u8 pad0[3];
679 __u8 rssi;
680 __u8 rx_status;
681 __u8 channel;
682 __u8 rx_ctrl;
683} __attribute__((packed));
684
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100685#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
686#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
687#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100688
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100689#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200690
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100691static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200692{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100693 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200694
695 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100696 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200697}
698
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100699static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200700{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100701 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200702
703 rxd->pkt_len = cpu_to_le16(len);
704 rxd->pkt_phys_addr = cpu_to_le32(addr);
705 wmb();
706 rxd->rx_ctrl = 0;
707}
708
709static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100710mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
711 __le16 *qos)
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200712{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100713 struct mwl8k_rxd_8366_ap *rxd = _rxd;
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200714
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100715 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200716 return -1;
717 rmb();
718
719 memset(status, 0, sizeof(*status));
720
721 status->signal = -rxd->rssi;
722 status->noise = -rxd->noise_floor;
723
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100724 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200725 status->flag |= RX_FLAG_HT;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100726 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
Lennert Buytenhek8e9f33f2009-11-30 18:12:35 +0100727 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100728 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200729 } else {
730 int i;
731
732 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) {
733 if (mwl8k_rates[i].hw_value == rxd->rate) {
734 status->rate_idx = i;
735 break;
736 }
737 }
738 }
739
740 status->band = IEEE80211_BAND_2GHZ;
741 status->freq = ieee80211_channel_to_frequency(rxd->channel);
742
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100743 *qos = rxd->qos_control;
744
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200745 return le16_to_cpu(rxd->pkt_len);
746}
747
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100748static struct rxd_ops rxd_8366_ap_ops = {
749 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
750 .rxd_init = mwl8k_rxd_8366_ap_init,
751 .rxd_refill = mwl8k_rxd_8366_ap_refill,
752 .rxd_process = mwl8k_rxd_8366_ap_process,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200753};
754
755/*
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100756 * Packet reception for STA firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100757 */
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100758struct mwl8k_rxd_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100759 __le16 pkt_len;
760 __u8 link_quality;
761 __u8 noise_level;
762 __le32 pkt_phys_addr;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200763 __le32 next_rxd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100764 __le16 qos_control;
765 __le16 rate_info;
766 __le32 pad0[4];
767 __u8 rssi;
768 __u8 channel;
769 __le16 pad1;
770 __u8 rx_ctrl;
771 __u8 rx_status;
772 __u8 pad2[2];
773} __attribute__((packed));
774
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100775#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
776#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
777#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
778#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
779#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
780#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200781
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100782#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200783
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100784static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200785{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100786 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200787
788 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100789 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200790}
791
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100792static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200793{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100794 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200795
796 rxd->pkt_len = cpu_to_le16(len);
797 rxd->pkt_phys_addr = cpu_to_le32(addr);
798 wmb();
799 rxd->rx_ctrl = 0;
800}
801
802static int
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100803mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100804 __le16 *qos)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200805{
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100806 struct mwl8k_rxd_sta *rxd = _rxd;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200807 u16 rate_info;
808
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100809 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200810 return -1;
811 rmb();
812
813 rate_info = le16_to_cpu(rxd->rate_info);
814
815 memset(status, 0, sizeof(*status));
816
817 status->signal = -rxd->rssi;
818 status->noise = -rxd->noise_level;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100819 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
820 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200821
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100822 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200823 status->flag |= RX_FLAG_SHORTPRE;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100824 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200825 status->flag |= RX_FLAG_40MHZ;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100826 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200827 status->flag |= RX_FLAG_SHORT_GI;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100828 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200829 status->flag |= RX_FLAG_HT;
830
831 status->band = IEEE80211_BAND_2GHZ;
832 status->freq = ieee80211_channel_to_frequency(rxd->channel);
833
Lennert Buytenhek20f09c32009-11-30 18:12:08 +0100834 *qos = rxd->qos_control;
835
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200836 return le16_to_cpu(rxd->pkt_len);
837}
838
Lennert Buytenhek89a91f42009-11-30 18:32:54 +0100839static struct rxd_ops rxd_sta_ops = {
840 .rxd_size = sizeof(struct mwl8k_rxd_sta),
841 .rxd_init = mwl8k_rxd_sta_init,
842 .rxd_refill = mwl8k_rxd_sta_refill,
843 .rxd_process = mwl8k_rxd_sta_process,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200844};
845
846
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100847#define MWL8K_RX_DESCS 256
848#define MWL8K_RX_MAXSZ 3800
849
850static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
851{
852 struct mwl8k_priv *priv = hw->priv;
853 struct mwl8k_rx_queue *rxq = priv->rxq + index;
854 int size;
855 int i;
856
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200857 rxq->rxd_count = 0;
858 rxq->head = 0;
859 rxq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100860
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200861 size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100862
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200863 rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
864 if (rxq->rxd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100865 printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200866 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100867 return -ENOMEM;
868 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200869 memset(rxq->rxd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100870
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200871 rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
872 if (rxq->buf == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100873 printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200874 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200875 pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100876 return -ENOMEM;
877 }
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200878 memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100879
880 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200881 int desc_size;
882 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100883 int nexti;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200884 dma_addr_t next_dma_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100885
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200886 desc_size = priv->rxd_ops->rxd_size;
887 rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100888
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200889 nexti = i + 1;
890 if (nexti == MWL8K_RX_DESCS)
891 nexti = 0;
892 next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
893
894 priv->rxd_ops->rxd_init(rxd, next_dma_addr);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100895 }
896
897 return 0;
898}
899
900static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
901{
902 struct mwl8k_priv *priv = hw->priv;
903 struct mwl8k_rx_queue *rxq = priv->rxq + index;
904 int refilled;
905
906 refilled = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200907 while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100908 struct sk_buff *skb;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200909 dma_addr_t addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100910 int rx;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200911 void *rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100912
913 skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
914 if (skb == NULL)
915 break;
916
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200917 addr = pci_map_single(priv->pdev, skb->data,
918 MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100919
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200920 rxq->rxd_count++;
921 rx = rxq->tail++;
922 if (rxq->tail == MWL8K_RX_DESCS)
923 rxq->tail = 0;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200924 rxq->buf[rx].skb = skb;
925 pci_unmap_addr_set(&rxq->buf[rx], dma, addr);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200926
927 rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
928 priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100929
930 refilled++;
931 }
932
933 return refilled;
934}
935
936/* Must be called only when the card's reception is completely halted */
937static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
938{
939 struct mwl8k_priv *priv = hw->priv;
940 struct mwl8k_rx_queue *rxq = priv->rxq + index;
941 int i;
942
943 for (i = 0; i < MWL8K_RX_DESCS; i++) {
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200944 if (rxq->buf[i].skb != NULL) {
945 pci_unmap_single(priv->pdev,
946 pci_unmap_addr(&rxq->buf[i], dma),
947 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
948 pci_unmap_addr_set(&rxq->buf[i], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100949
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200950 kfree_skb(rxq->buf[i].skb);
951 rxq->buf[i].skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100952 }
953 }
954
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200955 kfree(rxq->buf);
956 rxq->buf = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100957
958 pci_free_consistent(priv->pdev,
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200959 MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200960 rxq->rxd, rxq->rxd_dma);
961 rxq->rxd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100962}
963
964
965/*
966 * Scan a list of BSSIDs to process for finalize join.
967 * Allows for extension to process multiple BSSIDs.
968 */
969static inline int
970mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
971{
972 return priv->capture_beacon &&
973 ieee80211_is_beacon(wh->frame_control) &&
974 !compare_ether_addr(wh->addr3, priv->capture_bssid);
975}
976
Lennert Buytenhek37797522009-10-22 20:19:45 +0200977static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
978 struct sk_buff *skb)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100979{
Lennert Buytenhek37797522009-10-22 20:19:45 +0200980 struct mwl8k_priv *priv = hw->priv;
981
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100982 priv->capture_beacon = false;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200983 memset(priv->capture_bssid, 0, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100984
985 /*
986 * Use GFP_ATOMIC as rxq_process is called from
987 * the primary interrupt handler, memory allocation call
988 * must not sleep.
989 */
990 priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
991 if (priv->beacon_skb != NULL)
Lennert Buytenhek37797522009-10-22 20:19:45 +0200992 ieee80211_queue_work(hw, &priv->finalize_join_worker);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100993}
994
995static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
996{
997 struct mwl8k_priv *priv = hw->priv;
998 struct mwl8k_rx_queue *rxq = priv->rxq + index;
999 int processed;
1000
1001 processed = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001002 while (rxq->rxd_count && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001003 struct sk_buff *skb;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001004 void *rxd;
1005 int pkt_len;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001006 struct ieee80211_rx_status status;
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001007 __le16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001008
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001009 skb = rxq->buf[rxq->head].skb;
Lennert Buytenhekd25f9f12009-08-03 21:58:26 +02001010 if (skb == NULL)
1011 break;
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001012
1013 rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
1014
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001015 pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001016 if (pkt_len < 0)
1017 break;
1018
Lennert Buytenhek788838e2009-10-22 20:20:56 +02001019 rxq->buf[rxq->head].skb = NULL;
1020
1021 pci_unmap_single(priv->pdev,
1022 pci_unmap_addr(&rxq->buf[rxq->head], dma),
1023 MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
1024 pci_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001025
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001026 rxq->head++;
1027 if (rxq->head == MWL8K_RX_DESCS)
1028 rxq->head = 0;
1029
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001030 rxq->rxd_count--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001031
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001032 skb_put(skb, pkt_len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001033 mwl8k_remove_dma_header(skb, qos);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001034
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001035 /*
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001036 * Check for a pending join operation. Save a
1037 * copy of the beacon and schedule a tasklet to
1038 * send a FINALIZE_JOIN command to the firmware.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001039 */
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +02001040 if (mwl8k_capture_bssid(priv, (void *)skb->data))
Lennert Buytenhek37797522009-10-22 20:19:45 +02001041 mwl8k_save_beacon(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001042
Johannes Bergf1d58c22009-06-17 13:13:00 +02001043 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1044 ieee80211_rx_irqsafe(hw, skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001045
1046 processed++;
1047 }
1048
1049 return processed;
1050}
1051
1052
1053/*
1054 * Packet transmission.
1055 */
1056
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001057#define MWL8K_TXD_STATUS_OK 0x00000001
1058#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1059#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1060#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001061#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001062
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001063#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1064#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1065#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1066#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1067#define MWL8K_QOS_EOSP 0x0010
1068
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001069struct mwl8k_tx_desc {
1070 __le32 status;
1071 __u8 data_rate;
1072 __u8 tx_priority;
1073 __le16 qos_control;
1074 __le32 pkt_phys_addr;
1075 __le16 pkt_len;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001076 __u8 dest_MAC_addr[ETH_ALEN];
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001077 __le32 next_txd_phys_addr;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001078 __le32 reserved;
1079 __le16 rate_info;
1080 __u8 peer_id;
1081 __u8 tx_frag_cnt;
1082} __attribute__((packed));
1083
1084#define MWL8K_TX_DESCS 128
1085
1086static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
1087{
1088 struct mwl8k_priv *priv = hw->priv;
1089 struct mwl8k_tx_queue *txq = priv->txq + index;
1090 int size;
1091 int i;
1092
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001093 memset(&txq->stats, 0, sizeof(struct ieee80211_tx_queue_stats));
1094 txq->stats.limit = MWL8K_TX_DESCS;
1095 txq->head = 0;
1096 txq->tail = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001097
1098 size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
1099
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001100 txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
1101 if (txq->txd == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001102 printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001103 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001104 return -ENOMEM;
1105 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001106 memset(txq->txd, 0, size);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001107
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001108 txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
1109 if (txq->skb == NULL) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001110 printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001111 wiphy_name(hw->wiphy));
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001112 pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001113 return -ENOMEM;
1114 }
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001115 memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001116
1117 for (i = 0; i < MWL8K_TX_DESCS; i++) {
1118 struct mwl8k_tx_desc *tx_desc;
1119 int nexti;
1120
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001121 tx_desc = txq->txd + i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001122 nexti = (i + 1) % MWL8K_TX_DESCS;
1123
1124 tx_desc->status = 0;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001125 tx_desc->next_txd_phys_addr =
1126 cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001127 }
1128
1129 return 0;
1130}
1131
1132static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
1133{
1134 iowrite32(MWL8K_H2A_INT_PPA_READY,
1135 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1136 iowrite32(MWL8K_H2A_INT_DUMMY,
1137 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1138 ioread32(priv->regs + MWL8K_HIU_INT_CODE);
1139}
1140
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001141static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001142{
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001143 struct mwl8k_priv *priv = hw->priv;
1144 int i;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001145
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001146 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
1147 struct mwl8k_tx_queue *txq = priv->txq + i;
1148 int fw_owned = 0;
1149 int drv_owned = 0;
1150 int unused = 0;
1151 int desc;
Lennert Buytenhekc3f967d2009-08-18 04:15:22 +02001152
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001153 for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001154 struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
1155 u32 status;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001156
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001157 status = le32_to_cpu(tx_desc->status);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001158 if (status & MWL8K_TXD_STATUS_FW_OWNED)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001159 fw_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001160 else
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001161 drv_owned++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001162
1163 if (tx_desc->pkt_len == 0)
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001164 unused++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001165 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001166
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001167 printk(KERN_ERR "%s: txq[%d] len=%d head=%d tail=%d "
1168 "fw_owned=%d drv_owned=%d unused=%d\n",
1169 wiphy_name(hw->wiphy), i,
1170 txq->stats.len, txq->head, txq->tail,
1171 fw_owned, drv_owned, unused);
1172 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001173}
1174
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001175/*
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001176 * Must be called with priv->fw_mutex held and tx queues stopped.
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001177 */
Lennert Buytenhek62abd3c2010-01-08 18:28:34 +01001178#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001179
Lennert Buytenhek950d5b02009-07-17 01:48:41 +02001180static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001181{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001182 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02001183 DECLARE_COMPLETION_ONSTACK(tx_wait);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001184 int retry;
1185 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001186
1187 might_sleep();
1188
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001189 /*
1190 * The TX queues are stopped at this point, so this test
1191 * doesn't need to take ->tx_lock.
1192 */
1193 if (!priv->pending_tx_pkts)
1194 return 0;
1195
1196 retry = 0;
1197 rc = 0;
1198
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001199 spin_lock_bh(&priv->tx_lock);
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001200 priv->tx_wait = &tx_wait;
1201 while (!rc) {
1202 int oldcount;
1203 unsigned long timeout;
1204
1205 oldcount = priv->pending_tx_pkts;
1206
1207 spin_unlock_bh(&priv->tx_lock);
1208 timeout = wait_for_completion_timeout(&tx_wait,
1209 msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
1210 spin_lock_bh(&priv->tx_lock);
1211
1212 if (timeout) {
1213 WARN_ON(priv->pending_tx_pkts);
1214 if (retry) {
1215 printk(KERN_NOTICE "%s: tx rings drained\n",
1216 wiphy_name(hw->wiphy));
1217 }
1218 break;
1219 }
1220
1221 if (priv->pending_tx_pkts < oldcount) {
Lennert Buytenhek9a2303b2010-01-04 21:54:25 +01001222 printk(KERN_NOTICE "%s: waiting for tx rings "
1223 "to drain (%d -> %d pkts)\n",
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001224 wiphy_name(hw->wiphy), oldcount,
1225 priv->pending_tx_pkts);
1226 retry = 1;
1227 continue;
1228 }
1229
1230 priv->tx_wait = NULL;
1231
1232 printk(KERN_ERR "%s: tx rings stuck for %d ms\n",
1233 wiphy_name(hw->wiphy), MWL8K_TX_WAIT_TIMEOUT_MS);
1234 mwl8k_dump_tx_rings(hw);
1235
1236 rc = -ETIMEDOUT;
1237 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001238 spin_unlock_bh(&priv->tx_lock);
1239
Lennert Buytenhek7e1112d2009-11-30 18:13:04 +01001240 return rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001241}
1242
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02001243#define MWL8K_TXD_SUCCESS(status) \
1244 ((status) & (MWL8K_TXD_STATUS_OK | \
1245 MWL8K_TXD_STATUS_OK_RETRY | \
1246 MWL8K_TXD_STATUS_OK_MORE_RETRY))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001247
1248static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1249{
1250 struct mwl8k_priv *priv = hw->priv;
1251 struct mwl8k_tx_queue *txq = priv->txq + index;
1252 int wake = 0;
1253
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001254 while (txq->stats.len > 0) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001255 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001256 struct mwl8k_tx_desc *tx_desc;
1257 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001258 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001259 struct sk_buff *skb;
1260 struct ieee80211_tx_info *info;
1261 u32 status;
1262
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001263 tx = txq->head;
1264 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001265
1266 status = le32_to_cpu(tx_desc->status);
1267
1268 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1269 if (!force)
1270 break;
1271 tx_desc->status &=
1272 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1273 }
1274
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001275 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1276 BUG_ON(txq->stats.len == 0);
1277 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001278 priv->pending_tx_pkts--;
1279
1280 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001281 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001282 skb = txq->skb[tx];
1283 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001284
1285 BUG_ON(skb == NULL);
1286 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1287
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001288 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001289
1290 /* Mark descriptor as unused */
1291 tx_desc->pkt_phys_addr = 0;
1292 tx_desc->pkt_len = 0;
1293
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001294 info = IEEE80211_SKB_CB(skb);
1295 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001296 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001297 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001298
1299 ieee80211_tx_status_irqsafe(hw, skb);
1300
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001301 wake = 1;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001302 }
1303
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001304 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001305 ieee80211_wake_queue(hw, index);
1306}
1307
1308/* must be called only when the card's transmit is completely halted */
1309static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1310{
1311 struct mwl8k_priv *priv = hw->priv;
1312 struct mwl8k_tx_queue *txq = priv->txq + index;
1313
1314 mwl8k_txq_reclaim(hw, index, 1);
1315
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001316 kfree(txq->skb);
1317 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001318
1319 pci_free_consistent(priv->pdev,
1320 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001321 txq->txd, txq->txd_dma);
1322 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001323}
1324
1325static int
1326mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1327{
1328 struct mwl8k_priv *priv = hw->priv;
1329 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001330 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001331 struct ieee80211_hdr *wh;
1332 struct mwl8k_tx_queue *txq;
1333 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001334 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001335 u32 txstatus;
1336 u8 txdatarate;
1337 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001338
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001339 wh = (struct ieee80211_hdr *)skb->data;
1340 if (ieee80211_is_data_qos(wh->frame_control))
1341 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1342 else
1343 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001344
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001345 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001346 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001347
1348 tx_info = IEEE80211_SKB_CB(skb);
1349 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001350
1351 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1352 u16 seqno = mwl8k_vif->seqno;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001353
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001354 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1355 wh->seq_ctrl |= cpu_to_le16(seqno << 4);
1356 mwl8k_vif->seqno = seqno++ % 4096;
1357 }
1358
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001359 /* Setup firmware control bit fields for each frame type. */
1360 txstatus = 0;
1361 txdatarate = 0;
1362 if (ieee80211_is_mgmt(wh->frame_control) ||
1363 ieee80211_is_ctl(wh->frame_control)) {
1364 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001365 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001366 } else if (ieee80211_is_data(wh->frame_control)) {
1367 txdatarate = 1;
1368 if (is_multicast_ether_addr(wh->addr1))
1369 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1370
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001371 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001372 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001373 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001374 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001375 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001376 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001377
1378 dma = pci_map_single(priv->pdev, skb->data,
1379 skb->len, PCI_DMA_TODEVICE);
1380
1381 if (pci_dma_mapping_error(priv->pdev, dma)) {
1382 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001383 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001384 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001385 return NETDEV_TX_OK;
1386 }
1387
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001388 spin_lock_bh(&priv->tx_lock);
1389
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001390 txq = priv->txq + index;
1391
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001392 BUG_ON(txq->skb[txq->tail] != NULL);
1393 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001394
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001395 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001396 tx->data_rate = txdatarate;
1397 tx->tx_priority = index;
1398 tx->qos_control = cpu_to_le16(qos);
1399 tx->pkt_phys_addr = cpu_to_le32(dma);
1400 tx->pkt_len = cpu_to_le16(skb->len);
1401 tx->rate_info = 0;
Lennert Buytenheka6804002010-01-04 21:55:42 +01001402 if (!priv->ap_fw && tx_info->control.sta != NULL)
1403 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1404 else
1405 tx->peer_id = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001406 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001407 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1408
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001409 txq->stats.count++;
1410 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001411 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001412
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001413 txq->tail++;
1414 if (txq->tail == MWL8K_TX_DESCS)
1415 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001416
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001417 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001418 ieee80211_stop_queue(hw, index);
1419
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001420 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001421
1422 spin_unlock_bh(&priv->tx_lock);
1423
1424 return NETDEV_TX_OK;
1425}
1426
1427
1428/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001429 * Firmware access.
1430 *
1431 * We have the following requirements for issuing firmware commands:
1432 * - Some commands require that the packet transmit path is idle when
1433 * the command is issued. (For simplicity, we'll just quiesce the
1434 * transmit path for every command.)
1435 * - There are certain sequences of commands that need to be issued to
1436 * the hardware sequentially, with no other intervening commands.
1437 *
1438 * This leads to an implementation of a "firmware lock" as a mutex that
1439 * can be taken recursively, and which is taken by both the low-level
1440 * command submission function (mwl8k_post_cmd) as well as any users of
1441 * that function that require issuing of an atomic sequence of commands,
1442 * and quiesces the transmit path whenever it's taken.
1443 */
1444static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1445{
1446 struct mwl8k_priv *priv = hw->priv;
1447
1448 if (priv->fw_mutex_owner != current) {
1449 int rc;
1450
1451 mutex_lock(&priv->fw_mutex);
1452 ieee80211_stop_queues(hw);
1453
1454 rc = mwl8k_tx_wait_empty(hw);
1455 if (rc) {
1456 ieee80211_wake_queues(hw);
1457 mutex_unlock(&priv->fw_mutex);
1458
1459 return rc;
1460 }
1461
1462 priv->fw_mutex_owner = current;
1463 }
1464
1465 priv->fw_mutex_depth++;
1466
1467 return 0;
1468}
1469
1470static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1471{
1472 struct mwl8k_priv *priv = hw->priv;
1473
1474 if (!--priv->fw_mutex_depth) {
1475 ieee80211_wake_queues(hw);
1476 priv->fw_mutex_owner = NULL;
1477 mutex_unlock(&priv->fw_mutex);
1478 }
1479}
1480
1481
1482/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001483 * Command processing.
1484 */
1485
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001486/* Timeout firmware commands after 10s */
1487#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001488
1489static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1490{
1491 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1492 struct mwl8k_priv *priv = hw->priv;
1493 void __iomem *regs = priv->regs;
1494 dma_addr_t dma_addr;
1495 unsigned int dma_size;
1496 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001497 unsigned long timeout = 0;
1498 u8 buf[32];
1499
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001500 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001501 dma_size = le16_to_cpu(cmd->length);
1502 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1503 PCI_DMA_BIDIRECTIONAL);
1504 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1505 return -ENOMEM;
1506
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001507 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001508 if (rc) {
1509 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1510 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001511 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001512 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001513
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001514 priv->hostcmd_wait = &cmd_wait;
1515 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1516 iowrite32(MWL8K_H2A_INT_DOORBELL,
1517 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1518 iowrite32(MWL8K_H2A_INT_DUMMY,
1519 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001520
1521 timeout = wait_for_completion_timeout(&cmd_wait,
1522 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1523
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001524 priv->hostcmd_wait = NULL;
1525
1526 mwl8k_fw_unlock(hw);
1527
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001528 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1529 PCI_DMA_BIDIRECTIONAL);
1530
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001531 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001532 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001533 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001534 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1535 MWL8K_CMD_TIMEOUT_MS);
1536 rc = -ETIMEDOUT;
1537 } else {
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001538 int ms;
1539
1540 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1541
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001542 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001543 if (rc)
1544 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001545 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001546 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001547 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc642009-11-30 18:12:49 +01001548 else if (ms > 2000)
1549 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1550 wiphy_name(hw->wiphy),
1551 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1552 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001553 }
1554
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001555 return rc;
1556}
1557
1558/*
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001559 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001560 */
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001561struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001562 struct mwl8k_cmd_pkt header;
1563 __u8 hw_rev;
1564 __u8 host_interface;
1565 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001566 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001567 __le16 region_code;
1568 __le32 fw_rev;
1569 __le32 ps_cookie;
1570 __le32 caps;
1571 __u8 mcs_bitmap[16];
1572 __le32 rx_queue_ptr;
1573 __le32 num_tx_queues;
1574 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1575 __le32 caps2;
1576 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001577 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001578} __attribute__((packed));
1579
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001580#define MWL8K_CAP_MAX_AMSDU 0x20000000
1581#define MWL8K_CAP_GREENFIELD 0x08000000
1582#define MWL8K_CAP_AMPDU 0x04000000
1583#define MWL8K_CAP_RX_STBC 0x01000000
1584#define MWL8K_CAP_TX_STBC 0x00800000
1585#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1586#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1587#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1588#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1589#define MWL8K_CAP_DELAY_BA 0x00003000
1590#define MWL8K_CAP_MIMO 0x00000200
1591#define MWL8K_CAP_40MHZ 0x00000100
1592
1593static void mwl8k_set_ht_caps(struct ieee80211_hw *hw, u32 cap)
1594{
1595 struct mwl8k_priv *priv = hw->priv;
1596 int rx_streams;
1597 int tx_streams;
1598
1599 priv->band.ht_cap.ht_supported = 1;
1600
1601 if (cap & MWL8K_CAP_MAX_AMSDU)
1602 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
1603 if (cap & MWL8K_CAP_GREENFIELD)
1604 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
1605 if (cap & MWL8K_CAP_AMPDU) {
1606 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
1607 priv->band.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1608 priv->band.ht_cap.ampdu_density =
1609 IEEE80211_HT_MPDU_DENSITY_NONE;
1610 }
1611 if (cap & MWL8K_CAP_RX_STBC)
1612 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
1613 if (cap & MWL8K_CAP_TX_STBC)
1614 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
1615 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
1616 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
1617 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
1618 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
1619 if (cap & MWL8K_CAP_DELAY_BA)
1620 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
1621 if (cap & MWL8K_CAP_40MHZ)
1622 priv->band.ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1623
1624 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1625 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1626
1627 priv->band.ht_cap.mcs.rx_mask[0] = 0xff;
1628 if (rx_streams >= 2)
1629 priv->band.ht_cap.mcs.rx_mask[1] = 0xff;
1630 if (rx_streams >= 3)
1631 priv->band.ht_cap.mcs.rx_mask[2] = 0xff;
1632 priv->band.ht_cap.mcs.rx_mask[4] = 0x01;
1633 priv->band.ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1634
1635 if (rx_streams != tx_streams) {
1636 priv->band.ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1637 priv->band.ht_cap.mcs.tx_params |= (tx_streams - 1) <<
1638 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1639 }
1640}
1641
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001642static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001643{
1644 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b2009-10-22 20:21:05 +02001645 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001646 int rc;
1647 int i;
1648
1649 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1650 if (cmd == NULL)
1651 return -ENOMEM;
1652
1653 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1654 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1655
1656 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1657 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001658 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001659 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001660 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001661 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001662 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001663 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001664
1665 rc = mwl8k_post_cmd(hw, &cmd->header);
1666
1667 if (!rc) {
1668 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1669 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001670 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001671 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001672 if (cmd->caps & cpu_to_le32(MWL8K_CAP_MIMO))
1673 mwl8k_set_ht_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001674 }
1675
1676 kfree(cmd);
1677 return rc;
1678}
1679
1680/*
Lennert Buytenhek42fba212009-10-22 20:21:30 +02001681 * CMD_GET_HW_SPEC (AP version).
1682 */
1683struct mwl8k_cmd_get_hw_spec_ap {
1684 struct mwl8k_cmd_pkt header;
1685 __u8 hw_rev;
1686 __u8 host_interface;
1687 __le16 num_wcb;
1688 __le16 num_mcaddrs;
1689 __u8 perm_addr[ETH_ALEN];
1690 __le16 region_code;
1691 __le16 num_antenna;
1692 __le32 fw_rev;
1693 __le32 wcbbase0;
1694 __le32 rxwrptr;
1695 __le32 rxrdptr;
1696 __le32 ps_cookie;
1697 __le32 wcbbase1;
1698 __le32 wcbbase2;
1699 __le32 wcbbase3;
1700} __attribute__((packed));
1701
1702static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1703{
1704 struct mwl8k_priv *priv = hw->priv;
1705 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1706 int rc;
1707
1708 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1709 if (cmd == NULL)
1710 return -ENOMEM;
1711
1712 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1713 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1714
1715 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1716 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1717
1718 rc = mwl8k_post_cmd(hw, &cmd->header);
1719
1720 if (!rc) {
1721 int off;
1722
1723 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1724 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1725 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1726 priv->hw_rev = cmd->hw_rev;
1727
1728 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1729 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1730
1731 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1732 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1733
1734 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1735 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1736
1737 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1738 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1739
1740 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1741 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1742
1743 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1744 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1745 }
1746
1747 kfree(cmd);
1748 return rc;
1749}
1750
1751/*
1752 * CMD_SET_HW_SPEC.
1753 */
1754struct mwl8k_cmd_set_hw_spec {
1755 struct mwl8k_cmd_pkt header;
1756 __u8 hw_rev;
1757 __u8 host_interface;
1758 __le16 num_mcaddrs;
1759 __u8 perm_addr[ETH_ALEN];
1760 __le16 region_code;
1761 __le32 fw_rev;
1762 __le32 ps_cookie;
1763 __le32 caps;
1764 __le32 rx_queue_ptr;
1765 __le32 num_tx_queues;
1766 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1767 __le32 flags;
1768 __le32 num_tx_desc_per_queue;
1769 __le32 total_rxd;
1770} __attribute__((packed));
1771
1772#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1773
1774static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1775{
1776 struct mwl8k_priv *priv = hw->priv;
1777 struct mwl8k_cmd_set_hw_spec *cmd;
1778 int rc;
1779 int i;
1780
1781 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1782 if (cmd == NULL)
1783 return -ENOMEM;
1784
1785 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1786 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1787
1788 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1789 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1790 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1791 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1792 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1793 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT);
1794 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1795 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1796
1797 rc = mwl8k_post_cmd(hw, &cmd->header);
1798 kfree(cmd);
1799
1800 return rc;
1801}
1802
1803/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001804 * CMD_MAC_MULTICAST_ADR.
1805 */
1806struct mwl8k_cmd_mac_multicast_adr {
1807 struct mwl8k_cmd_pkt header;
1808 __le16 action;
1809 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001810 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001811};
1812
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001813#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1814#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1815#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1816#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001817
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001818static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001819__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001820 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001821{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001822 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001823 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001824 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001825
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001826 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001827 allmulti = 1;
1828 mc_count = 0;
1829 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001830
1831 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1832
1833 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001834 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001835 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001836
1837 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1838 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001839 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1840 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001841
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001842 if (allmulti) {
1843 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1844 } else if (mc_count) {
1845 int i;
1846
1847 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1848 cmd->numaddr = cpu_to_le16(mc_count);
1849 for (i = 0; i < mc_count && mclist; i++) {
1850 if (mclist->da_addrlen != ETH_ALEN) {
1851 kfree(cmd);
1852 return NULL;
1853 }
1854 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1855 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001856 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001857 }
1858
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001859 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001860}
1861
1862/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001863 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001864 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001865struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001866 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001867 __le32 stats[64];
1868} __attribute__((packed));
1869
1870#define MWL8K_STAT_ACK_FAILURE 9
1871#define MWL8K_STAT_RTS_FAILURE 12
1872#define MWL8K_STAT_FCS_ERROR 24
1873#define MWL8K_STAT_RTS_SUCCESS 11
1874
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001875static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1876 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001877{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001878 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001879 int rc;
1880
1881 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1882 if (cmd == NULL)
1883 return -ENOMEM;
1884
1885 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1886 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001887
1888 rc = mwl8k_post_cmd(hw, &cmd->header);
1889 if (!rc) {
1890 stats->dot11ACKFailureCount =
1891 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1892 stats->dot11RTSFailureCount =
1893 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1894 stats->dot11FCSErrorCount =
1895 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1896 stats->dot11RTSSuccessCount =
1897 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1898 }
1899 kfree(cmd);
1900
1901 return rc;
1902}
1903
1904/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001905 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001906 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001907struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001908 struct mwl8k_cmd_pkt header;
1909 __le16 action;
1910 __le16 control;
1911 __le16 radio_on;
1912} __attribute__((packed));
1913
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001914static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001915mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001916{
1917 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001918 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001919 int rc;
1920
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001921 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001922 return 0;
1923
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001924 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1925 if (cmd == NULL)
1926 return -ENOMEM;
1927
1928 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1929 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1930 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001931 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001932 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1933
1934 rc = mwl8k_post_cmd(hw, &cmd->header);
1935 kfree(cmd);
1936
1937 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001938 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001939
1940 return rc;
1941}
1942
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001943static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001944{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001945 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001946}
1947
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001948static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001949{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001950 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001951}
1952
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001953static int
1954mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1955{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01001956 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001957
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001958 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001959
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001960 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001961}
1962
1963/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001964 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001965 */
1966#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1967
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001968struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001969 struct mwl8k_cmd_pkt header;
1970 __le16 action;
1971 __le16 support_level;
1972 __le16 current_level;
1973 __le16 reserved;
1974 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
1975} __attribute__((packed));
1976
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001977static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001978{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001979 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001980 int rc;
1981
1982 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1983 if (cmd == NULL)
1984 return -ENOMEM;
1985
1986 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
1987 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1988 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
1989 cmd->support_level = cpu_to_le16(dBm);
1990
1991 rc = mwl8k_post_cmd(hw, &cmd->header);
1992 kfree(cmd);
1993
1994 return rc;
1995}
1996
1997/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02001998 * CMD_RF_ANTENNA.
1999 */
2000struct mwl8k_cmd_rf_antenna {
2001 struct mwl8k_cmd_pkt header;
2002 __le16 antenna;
2003 __le16 mode;
2004} __attribute__((packed));
2005
2006#define MWL8K_RF_ANTENNA_RX 1
2007#define MWL8K_RF_ANTENNA_TX 2
2008
2009static int
2010mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2011{
2012 struct mwl8k_cmd_rf_antenna *cmd;
2013 int rc;
2014
2015 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2016 if (cmd == NULL)
2017 return -ENOMEM;
2018
2019 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2020 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2021 cmd->antenna = cpu_to_le16(antenna);
2022 cmd->mode = cpu_to_le16(mask);
2023
2024 rc = mwl8k_post_cmd(hw, &cmd->header);
2025 kfree(cmd);
2026
2027 return rc;
2028}
2029
2030/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002031 * CMD_SET_PRE_SCAN.
2032 */
2033struct mwl8k_cmd_set_pre_scan {
2034 struct mwl8k_cmd_pkt header;
2035} __attribute__((packed));
2036
2037static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2038{
2039 struct mwl8k_cmd_set_pre_scan *cmd;
2040 int rc;
2041
2042 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2043 if (cmd == NULL)
2044 return -ENOMEM;
2045
2046 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2047 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2048
2049 rc = mwl8k_post_cmd(hw, &cmd->header);
2050 kfree(cmd);
2051
2052 return rc;
2053}
2054
2055/*
2056 * CMD_SET_POST_SCAN.
2057 */
2058struct mwl8k_cmd_set_post_scan {
2059 struct mwl8k_cmd_pkt header;
2060 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002061 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002062} __attribute__((packed));
2063
2064static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002065mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002066{
2067 struct mwl8k_cmd_set_post_scan *cmd;
2068 int rc;
2069
2070 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2071 if (cmd == NULL)
2072 return -ENOMEM;
2073
2074 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2075 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2076 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002077 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002078
2079 rc = mwl8k_post_cmd(hw, &cmd->header);
2080 kfree(cmd);
2081
2082 return rc;
2083}
2084
2085/*
2086 * CMD_SET_RF_CHANNEL.
2087 */
2088struct mwl8k_cmd_set_rf_channel {
2089 struct mwl8k_cmd_pkt header;
2090 __le16 action;
2091 __u8 current_channel;
2092 __le32 channel_flags;
2093} __attribute__((packed));
2094
2095static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002096 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002097{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002098 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002099 struct mwl8k_cmd_set_rf_channel *cmd;
2100 int rc;
2101
2102 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2103 if (cmd == NULL)
2104 return -ENOMEM;
2105
2106 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2107 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2108 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2109 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002110
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002111 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002112 cmd->channel_flags |= cpu_to_le32(0x00000001);
2113
2114 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2115 conf->channel_type == NL80211_CHAN_HT20)
2116 cmd->channel_flags |= cpu_to_le32(0x00000080);
2117 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2118 cmd->channel_flags |= cpu_to_le32(0x000001900);
2119 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2120 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002121
2122 rc = mwl8k_post_cmd(hw, &cmd->header);
2123 kfree(cmd);
2124
2125 return rc;
2126}
2127
2128/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002129 * CMD_SET_AID.
2130 */
2131#define MWL8K_FRAME_PROT_DISABLED 0x00
2132#define MWL8K_FRAME_PROT_11G 0x07
2133#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2134#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2135
2136struct mwl8k_cmd_update_set_aid {
2137 struct mwl8k_cmd_pkt header;
2138 __le16 aid;
2139
2140 /* AP's MAC address (BSSID) */
2141 __u8 bssid[ETH_ALEN];
2142 __le16 protection_mode;
2143 __u8 supp_rates[14];
2144} __attribute__((packed));
2145
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002146static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2147{
2148 int i;
2149 int j;
2150
2151 /*
2152 * Clear nonstandard rates 4 and 13.
2153 */
2154 mask &= 0x1fef;
2155
2156 for (i = 0, j = 0; i < 14; i++) {
2157 if (mask & (1 << i))
2158 rates[j++] = mwl8k_rates[i].hw_value;
2159 }
2160}
2161
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002162static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002163mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2164 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002165{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002166 struct mwl8k_cmd_update_set_aid *cmd;
2167 u16 prot_mode;
2168 int rc;
2169
2170 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2171 if (cmd == NULL)
2172 return -ENOMEM;
2173
2174 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2175 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002176 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002177 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002178
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002179 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002180 prot_mode = MWL8K_FRAME_PROT_11G;
2181 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002182 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002183 IEEE80211_HT_OP_MODE_PROTECTION) {
2184 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2185 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2186 break;
2187 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2188 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2189 break;
2190 default:
2191 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2192 break;
2193 }
2194 }
2195 cmd->protection_mode = cpu_to_le16(prot_mode);
2196
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002197 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002198
2199 rc = mwl8k_post_cmd(hw, &cmd->header);
2200 kfree(cmd);
2201
2202 return rc;
2203}
2204
2205/*
2206 * CMD_SET_RATE.
2207 */
2208struct mwl8k_cmd_set_rate {
2209 struct mwl8k_cmd_pkt header;
2210 __u8 legacy_rates[14];
2211
2212 /* Bitmap for supported MCS codes. */
2213 __u8 mcs_set[16];
2214 __u8 reserved[16];
2215} __attribute__((packed));
2216
2217static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002218mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002219 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002220{
2221 struct mwl8k_cmd_set_rate *cmd;
2222 int rc;
2223
2224 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2225 if (cmd == NULL)
2226 return -ENOMEM;
2227
2228 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2229 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002230 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002231 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002232
2233 rc = mwl8k_post_cmd(hw, &cmd->header);
2234 kfree(cmd);
2235
2236 return rc;
2237}
2238
2239/*
2240 * CMD_FINALIZE_JOIN.
2241 */
2242#define MWL8K_FJ_BEACON_MAXLEN 128
2243
2244struct mwl8k_cmd_finalize_join {
2245 struct mwl8k_cmd_pkt header;
2246 __le32 sleep_interval; /* Number of beacon periods to sleep */
2247 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2248} __attribute__((packed));
2249
2250static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2251 int framelen, int dtim)
2252{
2253 struct mwl8k_cmd_finalize_join *cmd;
2254 struct ieee80211_mgmt *payload = frame;
2255 int payload_len;
2256 int rc;
2257
2258 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2259 if (cmd == NULL)
2260 return -ENOMEM;
2261
2262 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2263 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2264 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2265
2266 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2267 if (payload_len < 0)
2268 payload_len = 0;
2269 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2270 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2271
2272 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2273
2274 rc = mwl8k_post_cmd(hw, &cmd->header);
2275 kfree(cmd);
2276
2277 return rc;
2278}
2279
2280/*
2281 * CMD_SET_RTS_THRESHOLD.
2282 */
2283struct mwl8k_cmd_set_rts_threshold {
2284 struct mwl8k_cmd_pkt header;
2285 __le16 action;
2286 __le16 threshold;
2287} __attribute__((packed));
2288
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002289static int
2290mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002291{
2292 struct mwl8k_cmd_set_rts_threshold *cmd;
2293 int rc;
2294
2295 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2296 if (cmd == NULL)
2297 return -ENOMEM;
2298
2299 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2300 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002301 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2302 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002303
2304 rc = mwl8k_post_cmd(hw, &cmd->header);
2305 kfree(cmd);
2306
2307 return rc;
2308}
2309
2310/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002311 * CMD_SET_SLOT.
2312 */
2313struct mwl8k_cmd_set_slot {
2314 struct mwl8k_cmd_pkt header;
2315 __le16 action;
2316 __u8 short_slot;
2317} __attribute__((packed));
2318
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002319static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002320{
2321 struct mwl8k_cmd_set_slot *cmd;
2322 int rc;
2323
2324 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2325 if (cmd == NULL)
2326 return -ENOMEM;
2327
2328 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2329 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2330 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002331 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002332
2333 rc = mwl8k_post_cmd(hw, &cmd->header);
2334 kfree(cmd);
2335
2336 return rc;
2337}
2338
2339/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002340 * CMD_SET_EDCA_PARAMS.
2341 */
2342struct mwl8k_cmd_set_edca_params {
2343 struct mwl8k_cmd_pkt header;
2344
2345 /* See MWL8K_SET_EDCA_XXX below */
2346 __le16 action;
2347
2348 /* TX opportunity in units of 32 us */
2349 __le16 txop;
2350
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002351 union {
2352 struct {
2353 /* Log exponent of max contention period: 0...15 */
2354 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002355
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002356 /* Log exponent of min contention period: 0...15 */
2357 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002358
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002359 /* Adaptive interframe spacing in units of 32us */
2360 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002361
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002362 /* TX queue to configure */
2363 __u8 txq;
2364 } ap;
2365 struct {
2366 /* Log exponent of max contention period: 0...15 */
2367 __u8 log_cw_max;
2368
2369 /* Log exponent of min contention period: 0...15 */
2370 __u8 log_cw_min;
2371
2372 /* Adaptive interframe spacing in units of 32us */
2373 __u8 aifs;
2374
2375 /* TX queue to configure */
2376 __u8 txq;
2377 } sta;
2378 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002379} __attribute__((packed));
2380
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002381#define MWL8K_SET_EDCA_CW 0x01
2382#define MWL8K_SET_EDCA_TXOP 0x02
2383#define MWL8K_SET_EDCA_AIFS 0x04
2384
2385#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2386 MWL8K_SET_EDCA_TXOP | \
2387 MWL8K_SET_EDCA_AIFS)
2388
2389static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002390mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2391 __u16 cw_min, __u16 cw_max,
2392 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002393{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002394 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002395 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002396 int rc;
2397
2398 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2399 if (cmd == NULL)
2400 return -ENOMEM;
2401
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002402 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2403 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002404 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2405 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002406 if (priv->ap_fw) {
2407 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2408 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2409 cmd->ap.aifs = aifs;
2410 cmd->ap.txq = qnum;
2411 } else {
2412 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2413 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2414 cmd->sta.aifs = aifs;
2415 cmd->sta.txq = qnum;
2416 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002417
2418 rc = mwl8k_post_cmd(hw, &cmd->header);
2419 kfree(cmd);
2420
2421 return rc;
2422}
2423
2424/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002425 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002426 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002427struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002428 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002429 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002430} __attribute__((packed));
2431
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002432static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002433{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002434 struct mwl8k_priv *priv = hw->priv;
2435 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002436 int rc;
2437
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002438 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2439 if (cmd == NULL)
2440 return -ENOMEM;
2441
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002442 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002443 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002444 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002445
2446 rc = mwl8k_post_cmd(hw, &cmd->header);
2447 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002448
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002449 if (!rc)
2450 priv->wmm_enabled = enable;
2451
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002452 return rc;
2453}
2454
2455/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002456 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002457 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002458struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002459 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002460 __le32 action;
2461 __u8 rx_antenna_map;
2462 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002463} __attribute__((packed));
2464
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002465static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002466{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002467 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002468 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002469
2470 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2471 if (cmd == NULL)
2472 return -ENOMEM;
2473
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002474 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002475 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002476 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2477 cmd->rx_antenna_map = rx;
2478 cmd->tx_antenna_map = tx;
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 Buytenhekb71ed2c2010-01-08 18:30:16 +01002487 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002488 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002489struct mwl8k_cmd_use_fixed_rate_sta {
2490 struct mwl8k_cmd_pkt header;
2491 __le32 action;
2492 __le32 allow_rate_drop;
2493 __le32 num_rates;
2494 struct {
2495 __le32 is_ht_rate;
2496 __le32 enable_retry;
2497 __le32 rate;
2498 __le32 retry_count;
2499 } rate_entry[8];
2500 __le32 rate_type;
2501 __le32 reserved1;
2502 __le32 reserved2;
2503} __attribute__((packed));
2504
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002505#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002506#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002507
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002508static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002509{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002510 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002511 int rc;
2512
2513 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2514 if (cmd == NULL)
2515 return -ENOMEM;
2516
2517 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2518 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002519 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2520 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002521
2522 rc = mwl8k_post_cmd(hw, &cmd->header);
2523 kfree(cmd);
2524
2525 return rc;
2526}
2527
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002528/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002529 * CMD_USE_FIXED_RATE (AP version).
2530 */
2531struct mwl8k_cmd_use_fixed_rate_ap {
2532 struct mwl8k_cmd_pkt header;
2533 __le32 action;
2534 __le32 allow_rate_drop;
2535 __le32 num_rates;
2536 struct mwl8k_rate_entry_ap {
2537 __le32 is_ht_rate;
2538 __le32 enable_retry;
2539 __le32 rate;
2540 __le32 retry_count;
2541 } rate_entry[4];
2542 u8 multicast_rate;
2543 u8 multicast_rate_type;
2544 u8 management_rate;
2545} __attribute__((packed));
2546
2547static int
2548mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2549{
2550 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2551 int rc;
2552
2553 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2554 if (cmd == NULL)
2555 return -ENOMEM;
2556
2557 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2558 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2559 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2560 cmd->multicast_rate = mcast;
2561 cmd->management_rate = mgmt;
2562
2563 rc = mwl8k_post_cmd(hw, &cmd->header);
2564 kfree(cmd);
2565
2566 return rc;
2567}
2568
2569/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002570 * CMD_ENABLE_SNIFFER.
2571 */
2572struct mwl8k_cmd_enable_sniffer {
2573 struct mwl8k_cmd_pkt header;
2574 __le32 action;
2575} __attribute__((packed));
2576
2577static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2578{
2579 struct mwl8k_cmd_enable_sniffer *cmd;
2580 int rc;
2581
2582 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2583 if (cmd == NULL)
2584 return -ENOMEM;
2585
2586 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2587 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2588 cmd->action = cpu_to_le32(!!enable);
2589
2590 rc = mwl8k_post_cmd(hw, &cmd->header);
2591 kfree(cmd);
2592
2593 return rc;
2594}
2595
2596/*
2597 * CMD_SET_MAC_ADDR.
2598 */
2599struct mwl8k_cmd_set_mac_addr {
2600 struct mwl8k_cmd_pkt header;
2601 union {
2602 struct {
2603 __le16 mac_type;
2604 __u8 mac_addr[ETH_ALEN];
2605 } mbss;
2606 __u8 mac_addr[ETH_ALEN];
2607 };
2608} __attribute__((packed));
2609
2610static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2611{
2612 struct mwl8k_priv *priv = hw->priv;
2613 struct mwl8k_cmd_set_mac_addr *cmd;
2614 int rc;
2615
2616 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2617 if (cmd == NULL)
2618 return -ENOMEM;
2619
2620 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2621 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2622 if (priv->ap_fw) {
2623 cmd->mbss.mac_type = 0;
2624 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2625 } else {
2626 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2627 }
2628
2629 rc = mwl8k_post_cmd(hw, &cmd->header);
2630 kfree(cmd);
2631
2632 return rc;
2633}
2634
2635/*
2636 * CMD_SET_RATEADAPT_MODE.
2637 */
2638struct mwl8k_cmd_set_rate_adapt_mode {
2639 struct mwl8k_cmd_pkt header;
2640 __le16 action;
2641 __le16 mode;
2642} __attribute__((packed));
2643
2644static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2645{
2646 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2647 int rc;
2648
2649 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2650 if (cmd == NULL)
2651 return -ENOMEM;
2652
2653 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2654 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2655 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2656 cmd->mode = cpu_to_le16(mode);
2657
2658 rc = mwl8k_post_cmd(hw, &cmd->header);
2659 kfree(cmd);
2660
2661 return rc;
2662}
2663
2664/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002665 * CMD_SET_NEW_STN.
2666 */
2667struct mwl8k_cmd_set_new_stn {
2668 struct mwl8k_cmd_pkt header;
2669 __le16 aid;
2670 __u8 mac_addr[6];
2671 __le16 stn_id;
2672 __le16 action;
2673 __le16 rsvd;
2674 __le32 legacy_rates;
2675 __u8 ht_rates[4];
2676 __le16 cap_info;
2677 __le16 ht_capabilities_info;
2678 __u8 mac_ht_param_info;
2679 __u8 rev;
2680 __u8 control_channel;
2681 __u8 add_channel;
2682 __le16 op_mode;
2683 __le16 stbc;
2684 __u8 add_qos_info;
2685 __u8 is_qos_sta;
2686 __le32 fw_sta_ptr;
2687} __attribute__((packed));
2688
2689#define MWL8K_STA_ACTION_ADD 0
2690#define MWL8K_STA_ACTION_REMOVE 2
2691
2692static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2693 struct ieee80211_vif *vif,
2694 struct ieee80211_sta *sta)
2695{
2696 struct mwl8k_cmd_set_new_stn *cmd;
2697 int rc;
2698
2699 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2700 if (cmd == NULL)
2701 return -ENOMEM;
2702
2703 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2704 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2705 cmd->aid = cpu_to_le16(sta->aid);
2706 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2707 cmd->stn_id = cpu_to_le16(sta->aid);
2708 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
2709 cmd->legacy_rates = cpu_to_le32(sta->supp_rates[IEEE80211_BAND_2GHZ]);
2710 if (sta->ht_cap.ht_supported) {
2711 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2712 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2713 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2714 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2715 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2716 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2717 ((sta->ht_cap.ampdu_density & 7) << 2);
2718 cmd->is_qos_sta = 1;
2719 }
2720
2721 rc = mwl8k_post_cmd(hw, &cmd->header);
2722 kfree(cmd);
2723
2724 return rc;
2725}
2726
2727static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2728 struct ieee80211_vif *vif, u8 *addr)
2729{
2730 struct mwl8k_cmd_set_new_stn *cmd;
2731 int rc;
2732
2733 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2734 if (cmd == NULL)
2735 return -ENOMEM;
2736
2737 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2738 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2739 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2740 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2741
2742 rc = mwl8k_post_cmd(hw, &cmd->header);
2743 kfree(cmd);
2744
2745 return rc;
2746}
2747
2748/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002749 * CMD_UPDATE_STADB.
2750 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01002751struct ewc_ht_info {
2752 __le16 control1;
2753 __le16 control2;
2754 __le16 control3;
2755} __attribute__((packed));
2756
2757struct peer_capability_info {
2758 /* Peer type - AP vs. STA. */
2759 __u8 peer_type;
2760
2761 /* Basic 802.11 capabilities from assoc resp. */
2762 __le16 basic_caps;
2763
2764 /* Set if peer supports 802.11n high throughput (HT). */
2765 __u8 ht_support;
2766
2767 /* Valid if HT is supported. */
2768 __le16 ht_caps;
2769 __u8 extended_ht_caps;
2770 struct ewc_ht_info ewc_info;
2771
2772 /* Legacy rate table. Intersection of our rates and peer rates. */
2773 __u8 legacy_rates[12];
2774
2775 /* HT rate table. Intersection of our rates and peer rates. */
2776 __u8 ht_rates[16];
2777 __u8 pad[16];
2778
2779 /* If set, interoperability mode, no proprietary extensions. */
2780 __u8 interop;
2781 __u8 pad2;
2782 __u8 station_id;
2783 __le16 amsdu_enabled;
2784} __attribute__((packed));
2785
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002786struct mwl8k_cmd_update_stadb {
2787 struct mwl8k_cmd_pkt header;
2788
2789 /* See STADB_ACTION_TYPE */
2790 __le32 action;
2791
2792 /* Peer MAC address */
2793 __u8 peer_addr[ETH_ALEN];
2794
2795 __le32 reserved;
2796
2797 /* Peer info - valid during add/update. */
2798 struct peer_capability_info peer_info;
2799} __attribute__((packed));
2800
Lennert Buytenheka6804002010-01-04 21:55:42 +01002801#define MWL8K_STA_DB_MODIFY_ENTRY 1
2802#define MWL8K_STA_DB_DEL_ENTRY 2
2803
2804/* Peer Entry flags - used to define the type of the peer node */
2805#define MWL8K_PEER_TYPE_ACCESSPOINT 2
2806
2807static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002808 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002809 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002810{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002811 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01002812 struct peer_capability_info *p;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002813 int rc;
2814
2815 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2816 if (cmd == NULL)
2817 return -ENOMEM;
2818
2819 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2820 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01002821 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002822 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002823
Lennert Buytenheka6804002010-01-04 21:55:42 +01002824 p = &cmd->peer_info;
2825 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2826 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002827 p->ht_support = sta->ht_cap.ht_supported;
2828 p->ht_caps = sta->ht_cap.cap;
2829 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
2830 ((sta->ht_cap.ampdu_density & 7) << 2);
2831 legacy_rate_mask_to_array(p->legacy_rates,
2832 sta->supp_rates[IEEE80211_BAND_2GHZ]);
2833 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01002834 p->interop = 1;
2835 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002836
Lennert Buytenheka6804002010-01-04 21:55:42 +01002837 rc = mwl8k_post_cmd(hw, &cmd->header);
2838 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002839
Lennert Buytenheka6804002010-01-04 21:55:42 +01002840 return rc ? rc : p->station_id;
2841}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002842
Lennert Buytenheka6804002010-01-04 21:55:42 +01002843static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
2844 struct ieee80211_vif *vif, u8 *addr)
2845{
2846 struct mwl8k_cmd_update_stadb *cmd;
2847 int rc;
2848
2849 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2850 if (cmd == NULL)
2851 return -ENOMEM;
2852
2853 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2854 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2855 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
2856 memcpy(cmd->peer_addr, addr, ETH_ALEN);
2857
2858 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002859 kfree(cmd);
2860
2861 return rc;
2862}
2863
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002864
2865/*
2866 * Interrupt handling.
2867 */
2868static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2869{
2870 struct ieee80211_hw *hw = dev_id;
2871 struct mwl8k_priv *priv = hw->priv;
2872 u32 status;
2873
2874 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2875 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2876
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002877 if (!status)
2878 return IRQ_NONE;
2879
2880 if (status & MWL8K_A2H_INT_TX_DONE)
2881 tasklet_schedule(&priv->tx_reclaim_task);
2882
2883 if (status & MWL8K_A2H_INT_RX_READY) {
2884 while (rxq_process(hw, 0, 1))
2885 rxq_refill(hw, 0, 1);
2886 }
2887
2888 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002889 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002890 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002891 }
2892
2893 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002894 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02002895 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02002896 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002897 }
2898
2899 return IRQ_HANDLED;
2900}
2901
2902
2903/*
2904 * Core driver operations.
2905 */
2906static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2907{
2908 struct mwl8k_priv *priv = hw->priv;
2909 int index = skb_get_queue_mapping(skb);
2910 int rc;
2911
2912 if (priv->current_channel == NULL) {
2913 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002914 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002915 dev_kfree_skb(skb);
2916 return NETDEV_TX_OK;
2917 }
2918
2919 rc = mwl8k_txq_xmit(hw, index, skb);
2920
2921 return rc;
2922}
2923
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002924static int mwl8k_start(struct ieee80211_hw *hw)
2925{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002926 struct mwl8k_priv *priv = hw->priv;
2927 int rc;
2928
Joe Perchesa0607fd2009-11-18 23:29:17 -08002929 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002930 IRQF_SHARED, MWL8K_NAME, hw);
2931 if (rc) {
2932 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02002933 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002934 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002935 }
2936
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002937 /* Enable tx reclaim tasklet */
2938 tasklet_enable(&priv->tx_reclaim_task);
2939
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002940 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02002941 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002942
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002943 rc = mwl8k_fw_lock(hw);
2944 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002945 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002946
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002947 if (!priv->ap_fw) {
2948 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002949 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002950
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02002951 if (!rc)
2952 rc = mwl8k_cmd_set_pre_scan(hw);
2953
2954 if (!rc)
2955 rc = mwl8k_cmd_set_post_scan(hw,
2956 "\x00\x00\x00\x00\x00\x00");
2957 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002958
2959 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002960 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002961
2962 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002963 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002964
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002965 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002966 }
2967
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02002968 if (rc) {
2969 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2970 free_irq(priv->pdev->irq, hw);
2971 tasklet_disable(&priv->tx_reclaim_task);
2972 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002973
2974 return rc;
2975}
2976
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002977static void mwl8k_stop(struct ieee80211_hw *hw)
2978{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002979 struct mwl8k_priv *priv = hw->priv;
2980 int i;
2981
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002982 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002983
2984 ieee80211_stop_queues(hw);
2985
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002986 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002987 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002988 free_irq(priv->pdev->irq, hw);
2989
2990 /* Stop finalize join worker */
2991 cancel_work_sync(&priv->finalize_join_worker);
2992 if (priv->beacon_skb != NULL)
2993 dev_kfree_skb(priv->beacon_skb);
2994
2995 /* Stop tx reclaim tasklet */
2996 tasklet_disable(&priv->tx_reclaim_task);
2997
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002998 /* Return all skbs to mac80211 */
2999 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3000 mwl8k_txq_reclaim(hw, i, 1);
3001}
3002
3003static int mwl8k_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003004 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003005{
3006 struct mwl8k_priv *priv = hw->priv;
3007 struct mwl8k_vif *mwl8k_vif;
3008
3009 /*
3010 * We only support one active interface at a time.
3011 */
3012 if (priv->vif != NULL)
3013 return -EBUSY;
3014
3015 /*
3016 * We only support managed interfaces for now.
3017 */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003018 if (vif->type != NL80211_IFTYPE_STATION)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003019 return -EINVAL;
3020
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003021 /*
3022 * Reject interface creation if sniffer mode is active, as
3023 * STA operation is mutually exclusive with hardware sniffer
3024 * mode.
3025 */
3026 if (priv->sniffer_enabled) {
3027 printk(KERN_INFO "%s: unable to create STA "
3028 "interface due to sniffer mode being enabled\n",
3029 wiphy_name(hw->wiphy));
3030 return -EINVAL;
3031 }
3032
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003033 /* Set the mac address. */
3034 mwl8k_cmd_set_mac_addr(hw, vif->addr);
3035
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003036 /* Clean out driver private area */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003037 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003038 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
3039
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003040 /* Set Initial sequence number to zero */
3041 mwl8k_vif->seqno = 0;
3042
Johannes Berg1ed32e42009-12-23 13:15:45 +01003043 priv->vif = vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003044 priv->current_channel = NULL;
3045
3046 return 0;
3047}
3048
3049static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003050 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003051{
3052 struct mwl8k_priv *priv = hw->priv;
3053
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003054 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003055
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003056 priv->vif = NULL;
3057}
3058
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003059static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003060{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003061 struct ieee80211_conf *conf = &hw->conf;
3062 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003063 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003064
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003065 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003066 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003067 priv->current_channel = NULL;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003068 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003069 }
3070
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003071 rc = mwl8k_fw_lock(hw);
3072 if (rc)
3073 return rc;
3074
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003075 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003076 if (rc)
3077 goto out;
3078
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003079 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003080 if (rc)
3081 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003082
3083 priv->current_channel = conf->channel;
3084
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003085 if (conf->power_level > 18)
3086 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003087 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003088 if (rc)
3089 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003090
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003091 if (priv->ap_fw) {
3092 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3093 if (!rc)
3094 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3095 } else {
3096 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3097 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003098
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003099out:
3100 mwl8k_fw_unlock(hw);
3101
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003102 return rc;
3103}
3104
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003105static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
3106 struct ieee80211_vif *vif,
3107 struct ieee80211_bss_conf *info,
3108 u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003109{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003110 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003111 u32 ap_legacy_rates;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003112 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003113 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003114
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003115 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003116 return;
3117
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003118 /*
3119 * No need to capture a beacon if we're no longer associated.
3120 */
3121 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3122 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003123
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003124 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003125 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003126 */
3127 ap_legacy_rates = 0;
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003128 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003129 struct ieee80211_sta *ap;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003130 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003131
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003132 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003133 if (ap == NULL) {
3134 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003135 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003136 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003137
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003138 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003139 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003140
3141 rcu_read_unlock();
3142 }
3143
3144 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003145 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003146 if (rc)
3147 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003148
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003149 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003150 if (rc)
3151 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003152 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003153
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003154 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003155 rc = mwl8k_set_radio_preamble(hw,
3156 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003157 if (rc)
3158 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003159 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003160
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003161 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003162 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003163 if (rc)
3164 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003165 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003166
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003167 if (((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) ||
3168 (changed & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT))) {
3169 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003170 if (rc)
3171 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003172 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003173
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003174 if (vif->bss_conf.assoc &&
3175 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003176 /*
3177 * Finalize the join. Tell rx handler to process
3178 * next beacon from our BSSID.
3179 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003180 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003181 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003182 }
3183
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003184out:
3185 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003186}
3187
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003188static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3189 int mc_count, struct dev_addr_list *mclist)
3190{
3191 struct mwl8k_cmd_pkt *cmd;
3192
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003193 /*
3194 * Synthesize and return a command packet that programs the
3195 * hardware multicast address filter. At this point we don't
3196 * know whether FIF_ALLMULTI is being requested, but if it is,
3197 * we'll end up throwing this packet away and creating a new
3198 * one in mwl8k_configure_filter().
3199 */
3200 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003201
3202 return (unsigned long)cmd;
3203}
3204
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003205static int
3206mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3207 unsigned int changed_flags,
3208 unsigned int *total_flags)
3209{
3210 struct mwl8k_priv *priv = hw->priv;
3211
3212 /*
3213 * Hardware sniffer mode is mutually exclusive with STA
3214 * operation, so refuse to enable sniffer mode if a STA
3215 * interface is active.
3216 */
3217 if (priv->vif != NULL) {
3218 if (net_ratelimit())
3219 printk(KERN_INFO "%s: not enabling sniffer "
3220 "mode because STA interface is active\n",
3221 wiphy_name(hw->wiphy));
3222 return 0;
3223 }
3224
3225 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003226 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003227 return 0;
3228 priv->sniffer_enabled = true;
3229 }
3230
3231 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3232 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3233 FIF_OTHER_BSS;
3234
3235 return 1;
3236}
3237
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003238static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3239 unsigned int changed_flags,
3240 unsigned int *total_flags,
3241 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003242{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003243 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003244 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3245
3246 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003247 * AP firmware doesn't allow fine-grained control over
3248 * the receive filter.
3249 */
3250 if (priv->ap_fw) {
3251 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3252 kfree(cmd);
3253 return;
3254 }
3255
3256 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003257 * Enable hardware sniffer mode if FIF_CONTROL or
3258 * FIF_OTHER_BSS is requested.
3259 */
3260 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3261 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3262 kfree(cmd);
3263 return;
3264 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003265
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003266 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003267 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003268
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003269 if (mwl8k_fw_lock(hw)) {
3270 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003271 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003272 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003273
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003274 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003275 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003276 priv->sniffer_enabled = false;
3277 }
3278
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003279 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003280 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3281 /*
3282 * Disable the BSS filter.
3283 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003284 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003285 } else {
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003286 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003287
Lennert Buytenhek77165d82009-10-22 20:19:53 +02003288 /*
3289 * Enable the BSS filter.
3290 *
3291 * If there is an active STA interface, use that
3292 * interface's BSSID, otherwise use a dummy one
3293 * (where the OUI part needs to be nonzero for
3294 * the BSSID to be accepted by POST_SCAN).
3295 */
3296 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003297 if (priv->vif != NULL)
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003298 bssid = priv->vif->bss_conf.bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003299
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003300 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003301 }
3302 }
3303
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003304 /*
3305 * If FIF_ALLMULTI is being requested, throw away the command
3306 * packet that ->prepare_multicast() built and replace it with
3307 * a command packet that enables reception of all multicast
3308 * packets.
3309 */
3310 if (*total_flags & FIF_ALLMULTI) {
3311 kfree(cmd);
3312 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3313 }
3314
3315 if (cmd != NULL) {
3316 mwl8k_post_cmd(hw, cmd);
3317 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003318 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003319
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003320 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003321}
3322
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003323static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3324{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003325 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003326}
3327
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003328struct mwl8k_sta_notify_item
3329{
3330 struct list_head list;
3331 struct ieee80211_vif *vif;
3332 enum sta_notify_cmd cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003333 struct ieee80211_sta sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003334};
3335
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003336static void
3337mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3338{
3339 struct mwl8k_priv *priv = hw->priv;
3340
3341 /*
3342 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3343 */
3344 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3345 int rc;
3346
3347 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3348 if (rc >= 0) {
3349 struct ieee80211_sta *sta;
3350
3351 rcu_read_lock();
3352 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3353 if (sta != NULL)
3354 MWL8K_STA(sta)->peer_id = rc;
3355 rcu_read_unlock();
3356 }
3357 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3358 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3359 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3360 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3361 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3362 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3363 }
3364}
3365
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003366static void mwl8k_sta_notify_worker(struct work_struct *work)
3367{
3368 struct mwl8k_priv *priv =
3369 container_of(work, struct mwl8k_priv, sta_notify_worker);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003370 struct ieee80211_hw *hw = priv->hw;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003371
3372 spin_lock_bh(&priv->sta_notify_list_lock);
3373 while (!list_empty(&priv->sta_notify_list)) {
3374 struct mwl8k_sta_notify_item *s;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003375
3376 s = list_entry(priv->sta_notify_list.next,
3377 struct mwl8k_sta_notify_item, list);
3378 list_del(&s->list);
3379
3380 spin_unlock_bh(&priv->sta_notify_list_lock);
3381
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003382 mwl8k_do_sta_notify(hw, s);
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003383 kfree(s);
3384
3385 spin_lock_bh(&priv->sta_notify_list_lock);
3386 }
3387 spin_unlock_bh(&priv->sta_notify_list_lock);
3388}
3389
3390static void
3391mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3392 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3393{
3394 struct mwl8k_priv *priv = hw->priv;
3395 struct mwl8k_sta_notify_item *s;
3396
3397 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3398 return;
3399
3400 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3401 if (s != NULL) {
3402 s->vif = vif;
3403 s->cmd = cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003404 s->sta = *sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003405
3406 spin_lock(&priv->sta_notify_list_lock);
3407 list_add_tail(&s->list, &priv->sta_notify_list);
3408 spin_unlock(&priv->sta_notify_list_lock);
3409
3410 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3411 }
3412}
3413
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003414static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3415 const struct ieee80211_tx_queue_params *params)
3416{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003417 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003418 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003419
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003420 rc = mwl8k_fw_lock(hw);
3421 if (!rc) {
3422 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003423 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003424
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003425 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003426 rc = mwl8k_cmd_set_edca_params(hw, queue,
3427 params->cw_min,
3428 params->cw_max,
3429 params->aifs,
3430 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003431
3432 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003433 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003434
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003435 return rc;
3436}
3437
3438static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3439 struct ieee80211_tx_queue_stats *stats)
3440{
3441 struct mwl8k_priv *priv = hw->priv;
3442 struct mwl8k_tx_queue *txq;
3443 int index;
3444
3445 spin_lock_bh(&priv->tx_lock);
3446 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3447 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003448 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003449 sizeof(struct ieee80211_tx_queue_stats));
3450 }
3451 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003452
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003453 return 0;
3454}
3455
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003456static int mwl8k_get_stats(struct ieee80211_hw *hw,
3457 struct ieee80211_low_level_stats *stats)
3458{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003459 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003460}
3461
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003462static int
3463mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3464 enum ieee80211_ampdu_mlme_action action,
3465 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3466{
3467 switch (action) {
3468 case IEEE80211_AMPDU_RX_START:
3469 case IEEE80211_AMPDU_RX_STOP:
3470 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3471 return -ENOTSUPP;
3472 return 0;
3473 default:
3474 return -ENOTSUPP;
3475 }
3476}
3477
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003478static const struct ieee80211_ops mwl8k_ops = {
3479 .tx = mwl8k_tx,
3480 .start = mwl8k_start,
3481 .stop = mwl8k_stop,
3482 .add_interface = mwl8k_add_interface,
3483 .remove_interface = mwl8k_remove_interface,
3484 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003485 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003486 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003487 .configure_filter = mwl8k_configure_filter,
3488 .set_rts_threshold = mwl8k_set_rts_threshold,
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003489 .sta_notify = mwl8k_sta_notify,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003490 .conf_tx = mwl8k_conf_tx,
3491 .get_tx_stats = mwl8k_get_tx_stats,
3492 .get_stats = mwl8k_get_stats,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003493 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003494};
3495
3496static void mwl8k_tx_reclaim_handler(unsigned long data)
3497{
3498 int i;
3499 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3500 struct mwl8k_priv *priv = hw->priv;
3501
3502 spin_lock_bh(&priv->tx_lock);
3503 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3504 mwl8k_txq_reclaim(hw, i, 0);
3505
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003506 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003507 complete(priv->tx_wait);
3508 priv->tx_wait = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003509 }
3510 spin_unlock_bh(&priv->tx_lock);
3511}
3512
3513static void mwl8k_finalize_join_worker(struct work_struct *work)
3514{
3515 struct mwl8k_priv *priv =
3516 container_of(work, struct mwl8k_priv, finalize_join_worker);
3517 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003518
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003519 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len,
3520 priv->vif->bss_conf.dtim_period);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003521 dev_kfree_skb(skb);
3522
3523 priv->beacon_skb = NULL;
3524}
3525
John W. Linvillebcb628d2009-11-06 16:40:16 -05003526enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003527 MWL8363 = 0,
3528 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003529 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003530};
3531
John W. Linvillebcb628d2009-11-06 16:40:16 -05003532static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003533 [MWL8363] = {
3534 .part_name = "88w8363",
3535 .helper_image = "mwl8k/helper_8363.fw",
3536 .fw_image = "mwl8k/fmimage_8363.fw",
3537 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003538 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003539 .part_name = "88w8687",
3540 .helper_image = "mwl8k/helper_8687.fw",
3541 .fw_image = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05003542 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003543 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003544 .part_name = "88w8366",
3545 .helper_image = "mwl8k/helper_8366.fw",
3546 .fw_image = "mwl8k/fmimage_8366.fw",
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003547 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003548 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003549};
3550
3551static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003552 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3553 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003554 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3555 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3556 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3557 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003558};
3559MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3560
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003561static int __devinit mwl8k_probe(struct pci_dev *pdev,
3562 const struct pci_device_id *id)
3563{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003564 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003565 struct ieee80211_hw *hw;
3566 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003567 int rc;
3568 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003569
3570 if (!printed_version) {
3571 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3572 printed_version = 1;
3573 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003574
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003575
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003576 rc = pci_enable_device(pdev);
3577 if (rc) {
3578 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3579 MWL8K_NAME);
3580 return rc;
3581 }
3582
3583 rc = pci_request_regions(pdev, MWL8K_NAME);
3584 if (rc) {
3585 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3586 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003587 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003588 }
3589
3590 pci_set_master(pdev);
3591
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003592
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003593 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3594 if (hw == NULL) {
3595 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3596 rc = -ENOMEM;
3597 goto err_free_reg;
3598 }
3599
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003600 SET_IEEE80211_DEV(hw, &pdev->dev);
3601 pci_set_drvdata(pdev, hw);
3602
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003603 priv = hw->priv;
3604 priv->hw = hw;
3605 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003606 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003607
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003608
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003609 priv->sram = pci_iomap(pdev, 0, 0x10000);
3610 if (priv->sram == NULL) {
3611 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003612 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003613 goto err_iounmap;
3614 }
3615
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003616 /*
3617 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3618 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3619 */
3620 priv->regs = pci_iomap(pdev, 1, 0x10000);
3621 if (priv->regs == NULL) {
3622 priv->regs = pci_iomap(pdev, 2, 0x10000);
3623 if (priv->regs == NULL) {
3624 printk(KERN_ERR "%s: Cannot map device registers\n",
3625 wiphy_name(hw->wiphy));
3626 goto err_iounmap;
3627 }
3628 }
3629
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003630
3631 /* Reset firmware and hardware */
3632 mwl8k_hw_reset(priv);
3633
3634 /* Ask userland hotplug daemon for the device firmware */
3635 rc = mwl8k_request_firmware(priv);
3636 if (rc) {
3637 printk(KERN_ERR "%s: Firmware files not found\n",
3638 wiphy_name(hw->wiphy));
3639 goto err_stop_firmware;
3640 }
3641
3642 /* Load firmware into hardware */
3643 rc = mwl8k_load_firmware(hw);
3644 if (rc) {
3645 printk(KERN_ERR "%s: Cannot start firmware\n",
3646 wiphy_name(hw->wiphy));
3647 goto err_stop_firmware;
3648 }
3649
3650 /* Reclaim memory once firmware is successfully loaded */
3651 mwl8k_release_firmware(priv);
3652
3653
Lennert Buytenhek91942232010-01-04 21:53:54 +01003654 if (priv->ap_fw) {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003655 priv->rxd_ops = priv->device_info->ap_rxd_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003656 if (priv->rxd_ops == NULL) {
3657 printk(KERN_ERR "%s: Driver does not have AP "
3658 "firmware image support for this hardware\n",
3659 wiphy_name(hw->wiphy));
3660 goto err_stop_firmware;
3661 }
3662 } else {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003663 priv->rxd_ops = &rxd_sta_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003664 }
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003665
3666 priv->sniffer_enabled = false;
3667 priv->wmm_enabled = false;
3668 priv->pending_tx_pkts = 0;
3669
3670
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003671 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3672 priv->band.band = IEEE80211_BAND_2GHZ;
3673 priv->band.channels = priv->channels;
3674 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3675 priv->band.bitrates = priv->rates;
3676 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3677 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3678
3679 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
3680 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
3681
3682 /*
3683 * Extra headroom is the size of the required DMA header
3684 * minus the size of the smallest 802.11 frame (CTS frame).
3685 */
3686 hw->extra_tx_headroom =
3687 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3688
3689 hw->channel_change_time = 10;
3690
3691 hw->queues = MWL8K_TX_QUEUES;
3692
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003693 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003694 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003695 hw->vif_data_size = sizeof(struct mwl8k_vif);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003696 hw->sta_data_size = sizeof(struct mwl8k_sta);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003697 priv->vif = NULL;
3698
3699 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003700 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003701 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003702
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003703 /* Station database handling */
3704 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
3705 spin_lock_init(&priv->sta_notify_list_lock);
3706 INIT_LIST_HEAD(&priv->sta_notify_list);
3707
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003708 /* Finalize join worker */
3709 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3710
3711 /* TX reclaim tasklet */
3712 tasklet_init(&priv->tx_reclaim_task,
3713 mwl8k_tx_reclaim_handler, (unsigned long)hw);
3714 tasklet_disable(&priv->tx_reclaim_task);
3715
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003716 /* Power management cookie */
3717 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3718 if (priv->cookie == NULL)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003719 goto err_stop_firmware;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003720
3721 rc = mwl8k_rxq_init(hw, 0);
3722 if (rc)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003723 goto err_free_cookie;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003724 rxq_refill(hw, 0, INT_MAX);
3725
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003726 mutex_init(&priv->fw_mutex);
3727 priv->fw_mutex_owner = NULL;
3728 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003729 priv->hostcmd_wait = NULL;
3730
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003731 spin_lock_init(&priv->tx_lock);
3732
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003733 priv->tx_wait = NULL;
3734
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003735 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3736 rc = mwl8k_txq_init(hw, i);
3737 if (rc)
3738 goto err_free_queues;
3739 }
3740
3741 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003742 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003743 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3744 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3745
Joe Perchesa0607fd2009-11-18 23:29:17 -08003746 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003747 IRQF_SHARED, MWL8K_NAME, hw);
3748 if (rc) {
3749 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003750 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003751 goto err_free_queues;
3752 }
3753
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003754 /*
3755 * Temporarily enable interrupts. Initial firmware host
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003756 * commands use interrupts and avoid polling. Disable
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003757 * interrupts when done.
3758 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003759 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003760
3761 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba212009-10-22 20:21:30 +02003762 if (priv->ap_fw) {
3763 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3764 if (!rc)
3765 rc = mwl8k_cmd_set_hw_spec(hw);
3766 } else {
3767 rc = mwl8k_cmd_get_hw_spec_sta(hw);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003768
3769 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
Lennert Buytenhek42fba212009-10-22 20:21:30 +02003770 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003771 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003772 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3773 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003774 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003775 }
3776
3777 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003778 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003779 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003780 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003781 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003782 }
3783
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003784 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003785 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003786 if (rc) {
3787 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3788 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003789 goto err_free_irq;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003790 }
3791
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003792 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003793 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003794 free_irq(priv->pdev->irq, hw);
3795
3796 rc = ieee80211_register_hw(hw);
3797 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003798 printk(KERN_ERR "%s: Cannot register device\n",
3799 wiphy_name(hw->wiphy));
Lennert Buytenhek153458f2010-01-04 21:54:08 +01003800 goto err_free_queues;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003801 }
3802
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003803 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02003804 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003805 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02003806 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003807 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
3808 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003809
3810 return 0;
3811
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003812err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003813 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003814 free_irq(priv->pdev->irq, hw);
3815
3816err_free_queues:
3817 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3818 mwl8k_txq_deinit(hw, i);
3819 mwl8k_rxq_deinit(hw, 0);
3820
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003821err_free_cookie:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003822 if (priv->cookie != NULL)
3823 pci_free_consistent(priv->pdev, 4,
3824 priv->cookie, priv->cookie_dma);
3825
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003826err_stop_firmware:
3827 mwl8k_hw_reset(priv);
3828 mwl8k_release_firmware(priv);
3829
3830err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003831 if (priv->regs != NULL)
3832 pci_iounmap(pdev, priv->regs);
3833
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003834 if (priv->sram != NULL)
3835 pci_iounmap(pdev, priv->sram);
3836
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003837 pci_set_drvdata(pdev, NULL);
3838 ieee80211_free_hw(hw);
3839
3840err_free_reg:
3841 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003842
3843err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003844 pci_disable_device(pdev);
3845
3846 return rc;
3847}
3848
Joerg Albert230f7af2009-04-18 02:10:45 +02003849static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003850{
3851 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
3852}
3853
Joerg Albert230f7af2009-04-18 02:10:45 +02003854static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003855{
3856 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
3857 struct mwl8k_priv *priv;
3858 int i;
3859
3860 if (hw == NULL)
3861 return;
3862 priv = hw->priv;
3863
3864 ieee80211_stop_queues(hw);
3865
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02003866 ieee80211_unregister_hw(hw);
3867
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003868 /* Remove tx reclaim tasklet */
3869 tasklet_kill(&priv->tx_reclaim_task);
3870
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003871 /* Stop hardware */
3872 mwl8k_hw_reset(priv);
3873
3874 /* Return all skbs to mac80211 */
3875 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3876 mwl8k_txq_reclaim(hw, i, 1);
3877
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003878 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3879 mwl8k_txq_deinit(hw, i);
3880
3881 mwl8k_rxq_deinit(hw, 0);
3882
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003883 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003884
3885 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003886 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003887 pci_set_drvdata(pdev, NULL);
3888 ieee80211_free_hw(hw);
3889 pci_release_regions(pdev);
3890 pci_disable_device(pdev);
3891}
3892
3893static struct pci_driver mwl8k_driver = {
3894 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003895 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003896 .probe = mwl8k_probe,
3897 .remove = __devexit_p(mwl8k_remove),
3898 .shutdown = __devexit_p(mwl8k_shutdown),
3899};
3900
3901static int __init mwl8k_init(void)
3902{
3903 return pci_register_driver(&mwl8k_driver);
3904}
3905
3906static void __exit mwl8k_exit(void)
3907{
3908 pci_unregister_driver(&mwl8k_driver);
3909}
3910
3911module_init(mwl8k_init);
3912module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003913
3914MODULE_DESCRIPTION(MWL8K_DESC);
3915MODULE_VERSION(MWL8K_VERSION);
3916MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
3917MODULE_LICENSE("GPL");