blob: a17111f402665862181149bf51404781e33db118 [file] [log] [blame]
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001/*
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02002 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004 *
Lennert Buytenheka145d572009-08-18 04:34:26 +02005 * Copyright (C) 2008-2009 Marvell Semiconductor Inc.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01006 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/kernel.h>
Lennert Buytenhek3d76e822009-10-22 20:20:16 +020015#include <linux/sched.h>
Lennert Buytenheka66098d2009-03-10 10:13:33 +010016#include <linux/spinlock.h>
17#include <linux/list.h>
18#include <linux/pci.h>
19#include <linux/delay.h>
20#include <linux/completion.h>
21#include <linux/etherdevice.h>
22#include <net/mac80211.h>
23#include <linux/moduleparam.h>
24#include <linux/firmware.h>
25#include <linux/workqueue.h>
26
27#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
28#define MWL8K_NAME KBUILD_MODNAME
Lennert Buytenhek6976b662010-01-02 10:31:50 +010029#define MWL8K_VERSION "0.11"
Lennert Buytenheka66098d2009-03-10 10:13:33 +010030
Lennert Buytenheka66098d2009-03-10 10:13:33 +010031/* Register definitions */
32#define MWL8K_HIU_GEN_PTR 0x00000c10
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020033#define MWL8K_MODE_STA 0x0000005a
34#define MWL8K_MODE_AP 0x000000a5
Lennert Buytenheka66098d2009-03-10 10:13:33 +010035#define MWL8K_HIU_INT_CODE 0x00000c14
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020036#define MWL8K_FWSTA_READY 0xf0f1f2f4
37#define MWL8K_FWAP_READY 0xf1f2f4a5
38#define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
Lennert Buytenheka66098d2009-03-10 10:13:33 +010039#define MWL8K_HIU_SCRATCH 0x00000c40
40
41/* Host->device communications */
42#define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
43#define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
44#define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
45#define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
46#define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020047#define MWL8K_H2A_INT_DUMMY (1 << 20)
48#define MWL8K_H2A_INT_RESET (1 << 15)
49#define MWL8K_H2A_INT_DOORBELL (1 << 1)
50#define MWL8K_H2A_INT_PPA_READY (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010051
52/* Device->host communications */
53#define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
54#define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
55#define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
56#define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
57#define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +020058#define MWL8K_A2H_INT_DUMMY (1 << 20)
59#define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
60#define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
61#define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
62#define MWL8K_A2H_INT_RADIO_ON (1 << 6)
63#define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
64#define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
65#define MWL8K_A2H_INT_OPC_DONE (1 << 2)
66#define MWL8K_A2H_INT_RX_READY (1 << 1)
67#define MWL8K_A2H_INT_TX_DONE (1 << 0)
Lennert Buytenheka66098d2009-03-10 10:13:33 +010068
69#define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
70 MWL8K_A2H_INT_CHNL_SWITCHED | \
71 MWL8K_A2H_INT_QUEUE_EMPTY | \
72 MWL8K_A2H_INT_RADAR_DETECT | \
73 MWL8K_A2H_INT_RADIO_ON | \
74 MWL8K_A2H_INT_RADIO_OFF | \
75 MWL8K_A2H_INT_MAC_EVENT | \
76 MWL8K_A2H_INT_OPC_DONE | \
77 MWL8K_A2H_INT_RX_READY | \
78 MWL8K_A2H_INT_TX_DONE)
79
Lennert Buytenheka66098d2009-03-10 10:13:33 +010080#define MWL8K_RX_QUEUES 1
81#define MWL8K_TX_QUEUES 4
82
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020083struct rxd_ops {
84 int rxd_size;
85 void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
86 void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
Lennert Buytenhek20f09c32009-11-30 18:12:08 +010087 int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
88 __le16 *qos);
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +020089};
90
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020091struct mwl8k_device_info {
Lennert Buytenheka74b2952009-10-22 20:20:50 +020092 char *part_name;
93 char *helper_image;
94 char *fw_image;
Lennert Buytenhek89a91f42009-11-30 18:32:54 +010095 struct rxd_ops *ap_rxd_ops;
Lennert Buytenhek45a390d2009-10-22 20:20:47 +020096};
97
Lennert Buytenheka66098d2009-03-10 10:13:33 +010098struct mwl8k_rx_queue {
Lennert Buytenhek45eb4002009-10-22 20:20:40 +020099 int rxd_count;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100100
101 /* hw receives here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200102 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100103
104 /* refill descs here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200105 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100106
Lennert Buytenhek54bc3a02009-10-22 20:20:59 +0200107 void *rxd;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200108 dma_addr_t rxd_dma;
Lennert Buytenhek788838e2009-10-22 20:20:56 +0200109 struct {
110 struct sk_buff *skb;
111 DECLARE_PCI_UNMAP_ADDR(dma)
112 } *buf;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100113};
114
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100115struct mwl8k_tx_queue {
116 /* hw transmits here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200117 int head;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100118
119 /* sw appends here */
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200120 int tail;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100121
Lennert Buytenhek45eb4002009-10-22 20:20:40 +0200122 struct ieee80211_tx_queue_stats stats;
123 struct mwl8k_tx_desc *txd;
124 dma_addr_t txd_dma;
125 struct sk_buff **skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100126};
127
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100128struct mwl8k_priv {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100129 struct ieee80211_hw *hw;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100130 struct pci_dev *pdev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100131
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200132 struct mwl8k_device_info *device_info;
133
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100134 void __iomem *sram;
135 void __iomem *regs;
136
137 /* firmware */
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100138 struct firmware *fw_helper;
139 struct firmware *fw_ucode;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100140
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100141 /* hardware/firmware parameters */
142 bool ap_fw;
143 struct rxd_ops *rxd_ops;
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100144 struct ieee80211_supported_band band_24;
145 struct ieee80211_channel channels_24[14];
146 struct ieee80211_rate rates_24[14];
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +0100147
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200148 /* firmware access */
149 struct mutex fw_mutex;
150 struct task_struct *fw_mutex_owner;
151 int fw_mutex_depth;
Lennert Buytenhek618952a2009-08-18 03:18:01 +0200152 struct completion *hostcmd_wait;
153
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100154 /* lock held over TX and TX reap */
155 spinlock_t tx_lock;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100156
Lennert Buytenhek88de754a2009-10-22 20:19:37 +0200157 /* TX quiesce completion, protected by fw_mutex and tx_lock */
158 struct completion *tx_wait;
159
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100160 struct ieee80211_vif *vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100161
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100162 /* power management status cookie from firmware */
163 u32 *cookie;
164 dma_addr_t cookie_dma;
165
166 u16 num_mcaddrs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100167 u8 hw_rev;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +0200168 u32 fw_rev;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100169
170 /*
171 * Running count of TX packets in flight, to avoid
172 * iterating over the transmit rings each time.
173 */
174 int pending_tx_pkts;
175
176 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
177 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
178
Lennert Buytenhekc46563b2009-07-16 12:14:58 +0200179 bool radio_on;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +0200180 bool radio_short_preamble;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +0200181 bool sniffer_enabled;
Lennert Buytenhek0439b1f2009-07-16 12:34:02 +0200182 bool wmm_enabled;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100183
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +0100184 struct work_struct sta_notify_worker;
185 spinlock_t sta_notify_list_lock;
186 struct list_head sta_notify_list;
187
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100188 /* XXX need to convert this to handle multiple interfaces */
189 bool capture_beacon;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +0200190 u8 capture_bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100191 struct sk_buff *beacon_skb;
192
193 /*
194 * This FJ worker has to be global as it is scheduled from the
195 * RX handler. At this point we don't know which interface it
196 * belongs to until the list of bssids waiting to complete join
197 * is checked.
198 */
199 struct work_struct finalize_join_worker;
200
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +0100201 /* Tasklet to perform TX reclaim. */
202 struct tasklet_struct poll_tx_task;
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +0100203
204 /* Tasklet to perform RX. */
205 struct tasklet_struct poll_rx_task;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100206};
207
208/* Per interface specific private data */
209struct mwl8k_vif {
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +0100210 /* Non AMPDU sequence number assigned by driver. */
Lennert Buytenheka6804002010-01-04 21:55:42 +0100211 u16 seqno;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100212};
Lennert Buytenheka94cc972009-08-03 21:58:57 +0200213#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100214
Lennert Buytenheka6804002010-01-04 21:55:42 +0100215struct mwl8k_sta {
216 /* Index into station database. Returned by UPDATE_STADB. */
217 u8 peer_id;
218};
219#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
220
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100221static const struct ieee80211_channel mwl8k_channels_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100222 { .center_freq = 2412, .hw_value = 1, },
223 { .center_freq = 2417, .hw_value = 2, },
224 { .center_freq = 2422, .hw_value = 3, },
225 { .center_freq = 2427, .hw_value = 4, },
226 { .center_freq = 2432, .hw_value = 5, },
227 { .center_freq = 2437, .hw_value = 6, },
228 { .center_freq = 2442, .hw_value = 7, },
229 { .center_freq = 2447, .hw_value = 8, },
230 { .center_freq = 2452, .hw_value = 9, },
231 { .center_freq = 2457, .hw_value = 10, },
232 { .center_freq = 2462, .hw_value = 11, },
Lennert Buytenhek647ca6b2009-11-30 18:32:20 +0100233 { .center_freq = 2467, .hw_value = 12, },
234 { .center_freq = 2472, .hw_value = 13, },
235 { .center_freq = 2484, .hw_value = 14, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100236};
237
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100238static const struct ieee80211_rate mwl8k_rates_24[] = {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100239 { .bitrate = 10, .hw_value = 2, },
240 { .bitrate = 20, .hw_value = 4, },
241 { .bitrate = 55, .hw_value = 11, },
Lennert Buytenhek5dfd3e22009-10-22 20:20:29 +0200242 { .bitrate = 110, .hw_value = 22, },
243 { .bitrate = 220, .hw_value = 44, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100244 { .bitrate = 60, .hw_value = 12, },
245 { .bitrate = 90, .hw_value = 18, },
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100246 { .bitrate = 120, .hw_value = 24, },
247 { .bitrate = 180, .hw_value = 36, },
248 { .bitrate = 240, .hw_value = 48, },
249 { .bitrate = 360, .hw_value = 72, },
250 { .bitrate = 480, .hw_value = 96, },
251 { .bitrate = 540, .hw_value = 108, },
Lennert Buytenhek140eb5e2009-11-30 18:11:44 +0100252 { .bitrate = 720, .hw_value = 144, },
253};
254
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100255/* Set or get info from Firmware */
256#define MWL8K_CMD_SET 0x0001
257#define MWL8K_CMD_GET 0x0000
258
259/* Firmware command codes */
260#define MWL8K_CMD_CODE_DNLD 0x0001
261#define MWL8K_CMD_GET_HW_SPEC 0x0003
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200262#define MWL8K_CMD_SET_HW_SPEC 0x0004
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100263#define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
264#define MWL8K_CMD_GET_STAT 0x0014
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200265#define MWL8K_CMD_RADIO_CONTROL 0x001c
266#define MWL8K_CMD_RF_TX_POWER 0x001e
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200267#define MWL8K_CMD_RF_ANTENNA 0x0020
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100268#define MWL8K_CMD_SET_BEACON 0x0100
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 Buytenhekb64fe612010-01-08 18:31:39 +0100284#define MWL8K_CMD_BSS_START 0x1100
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100285#define MWL8K_CMD_SET_NEW_STN 0x1111
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200286#define MWL8K_CMD_UPDATE_STADB 0x1123
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100287
288static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
289{
290#define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
291 snprintf(buf, bufsize, "%s", #x);\
292 return buf;\
293 } while (0)
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +0200294 switch (cmd & ~0x8000) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100295 MWL8K_CMDNAME(CODE_DNLD);
296 MWL8K_CMDNAME(GET_HW_SPEC);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +0200297 MWL8K_CMDNAME(SET_HW_SPEC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100298 MWL8K_CMDNAME(MAC_MULTICAST_ADR);
299 MWL8K_CMDNAME(GET_STAT);
300 MWL8K_CMDNAME(RADIO_CONTROL);
301 MWL8K_CMDNAME(RF_TX_POWER);
Lennert Buytenhek08b06342009-10-22 20:21:33 +0200302 MWL8K_CMDNAME(RF_ANTENNA);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100303 MWL8K_CMDNAME(SET_BEACON);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100304 MWL8K_CMDNAME(SET_PRE_SCAN);
305 MWL8K_CMDNAME(SET_POST_SCAN);
306 MWL8K_CMDNAME(SET_RF_CHANNEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100307 MWL8K_CMDNAME(SET_AID);
308 MWL8K_CMDNAME(SET_RATE);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200309 MWL8K_CMDNAME(SET_FINALIZE_JOIN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100310 MWL8K_CMDNAME(RTS_THRESHOLD);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200311 MWL8K_CMDNAME(SET_SLOT);
312 MWL8K_CMDNAME(SET_EDCA_PARAMS);
313 MWL8K_CMDNAME(SET_WMM_MODE);
314 MWL8K_CMDNAME(MIMO_CONFIG);
315 MWL8K_CMDNAME(USE_FIXED_RATE);
316 MWL8K_CMDNAME(ENABLE_SNIFFER);
Lennert Buytenhek32060e12009-10-22 20:20:04 +0200317 MWL8K_CMDNAME(SET_MAC_ADDR);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200318 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +0100319 MWL8K_CMDNAME(BSS_START);
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +0100320 MWL8K_CMDNAME(SET_NEW_STN);
Lennert Buytenhekff45fc62009-07-16 11:50:36 +0200321 MWL8K_CMDNAME(UPDATE_STADB);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100322 default:
323 snprintf(buf, bufsize, "0x%x", cmd);
324 }
325#undef MWL8K_CMDNAME
326
327 return buf;
328}
329
330/* Hardware and firmware reset */
331static void mwl8k_hw_reset(struct mwl8k_priv *priv)
332{
333 iowrite32(MWL8K_H2A_INT_RESET,
334 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
335 iowrite32(MWL8K_H2A_INT_RESET,
336 priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
337 msleep(20);
338}
339
340/* Release fw image */
341static void mwl8k_release_fw(struct firmware **fw)
342{
343 if (*fw == NULL)
344 return;
345 release_firmware(*fw);
346 *fw = NULL;
347}
348
349static void mwl8k_release_firmware(struct mwl8k_priv *priv)
350{
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100351 mwl8k_release_fw(&priv->fw_ucode);
352 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100353}
354
355/* Request fw image */
356static int mwl8k_request_fw(struct mwl8k_priv *priv,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200357 const char *fname, struct firmware **fw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100358{
359 /* release current image */
360 if (*fw != NULL)
361 mwl8k_release_fw(fw);
362
363 return request_firmware((const struct firmware **)fw,
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200364 fname, &priv->pdev->dev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100365}
366
Lennert Buytenhek45a390d2009-10-22 20:20:47 +0200367static int mwl8k_request_firmware(struct mwl8k_priv *priv)
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100368{
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200369 struct mwl8k_device_info *di = priv->device_info;
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100370 int rc;
371
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200372 if (di->helper_image != NULL) {
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100373 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200374 if (rc) {
375 printk(KERN_ERR "%s: Error requesting helper "
376 "firmware file %s\n", pci_name(priv->pdev),
377 di->helper_image);
378 return rc;
379 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100380 }
381
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100382 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100383 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +0200384 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +0200385 pci_name(priv->pdev), di->fw_image);
Lennert Buytenhek22be40d2009-11-30 18:32:38 +0100386 mwl8k_release_fw(&priv->fw_helper);
Lennert Buytenheka66098d2009-03-10 10:13:33 +0100387 return rc;
388 }
389
390 return 0;
391}
392
393struct 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 Buytenhekd4b70572009-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
Lennert Buytenhek777ad372010-01-12 13:48:04 +0100732 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
733 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +0200734 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
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001248static int
1249mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001250{
1251 struct mwl8k_priv *priv = hw->priv;
1252 struct mwl8k_tx_queue *txq = priv->txq + index;
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001253 int processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001254
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001255 processed = 0;
1256 while (txq->stats.len > 0 && limit--) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001257 int tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001258 struct mwl8k_tx_desc *tx_desc;
1259 unsigned long addr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001260 int size;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001261 struct sk_buff *skb;
1262 struct ieee80211_tx_info *info;
1263 u32 status;
1264
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001265 tx = txq->head;
1266 tx_desc = txq->txd + tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001267
1268 status = le32_to_cpu(tx_desc->status);
1269
1270 if (status & MWL8K_TXD_STATUS_FW_OWNED) {
1271 if (!force)
1272 break;
1273 tx_desc->status &=
1274 ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
1275 }
1276
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001277 txq->head = (tx + 1) % MWL8K_TX_DESCS;
1278 BUG_ON(txq->stats.len == 0);
1279 txq->stats.len--;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001280 priv->pending_tx_pkts--;
1281
1282 addr = le32_to_cpu(tx_desc->pkt_phys_addr);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001283 size = le16_to_cpu(tx_desc->pkt_len);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001284 skb = txq->skb[tx];
1285 txq->skb[tx] = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001286
1287 BUG_ON(skb == NULL);
1288 pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
1289
Lennert Buytenhek20f09c32009-11-30 18:12:08 +01001290 mwl8k_remove_dma_header(skb, tx_desc->qos_control);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001291
1292 /* Mark descriptor as unused */
1293 tx_desc->pkt_phys_addr = 0;
1294 tx_desc->pkt_len = 0;
1295
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001296 info = IEEE80211_SKB_CB(skb);
1297 ieee80211_tx_info_clear_status(info);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001298 if (MWL8K_TXD_SUCCESS(status))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001299 info->flags |= IEEE80211_TX_STAT_ACK;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001300
1301 ieee80211_tx_status_irqsafe(hw, skb);
1302
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001303 processed++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001304 }
1305
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001306 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001307 ieee80211_wake_queue(hw, index);
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001308
1309 return processed;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001310}
1311
1312/* must be called only when the card's transmit is completely halted */
1313static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1314{
1315 struct mwl8k_priv *priv = hw->priv;
1316 struct mwl8k_tx_queue *txq = priv->txq + index;
1317
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01001318 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001319
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001320 kfree(txq->skb);
1321 txq->skb = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001322
1323 pci_free_consistent(priv->pdev,
1324 MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001325 txq->txd, txq->txd_dma);
1326 txq->txd = NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001327}
1328
1329static int
1330mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1331{
1332 struct mwl8k_priv *priv = hw->priv;
1333 struct ieee80211_tx_info *tx_info;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001334 struct mwl8k_vif *mwl8k_vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001335 struct ieee80211_hdr *wh;
1336 struct mwl8k_tx_queue *txq;
1337 struct mwl8k_tx_desc *tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001338 dma_addr_t dma;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001339 u32 txstatus;
1340 u8 txdatarate;
1341 u16 qos;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001342
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001343 wh = (struct ieee80211_hdr *)skb->data;
1344 if (ieee80211_is_data_qos(wh->frame_control))
1345 qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
1346 else
1347 qos = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001348
Lennert Buytenhek76266b22009-07-16 11:07:09 +02001349 mwl8k_add_dma_header(skb);
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001350 wh = &((struct mwl8k_dma_data *)skb->data)->wh;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001351
1352 tx_info = IEEE80211_SKB_CB(skb);
1353 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001354
1355 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001356 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Lennert Buytenhek657232b2010-01-12 13:47:47 +01001357 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1358 mwl8k_vif->seqno += 0x10;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001359 }
1360
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001361 /* Setup firmware control bit fields for each frame type. */
1362 txstatus = 0;
1363 txdatarate = 0;
1364 if (ieee80211_is_mgmt(wh->frame_control) ||
1365 ieee80211_is_ctl(wh->frame_control)) {
1366 txdatarate = 0;
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001367 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001368 } else if (ieee80211_is_data(wh->frame_control)) {
1369 txdatarate = 1;
1370 if (is_multicast_ether_addr(wh->addr1))
1371 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1372
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001373 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001374 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001375 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001376 else
Lennert Buytenheke0493a82009-11-30 18:32:00 +01001377 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001378 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001379
1380 dma = pci_map_single(priv->pdev, skb->data,
1381 skb->len, PCI_DMA_TODEVICE);
1382
1383 if (pci_dma_mapping_error(priv->pdev, dma)) {
1384 printk(KERN_DEBUG "%s: failed to dma map skb, "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001385 "dropping TX frame.\n", wiphy_name(hw->wiphy));
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001386 dev_kfree_skb(skb);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001387 return NETDEV_TX_OK;
1388 }
1389
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001390 spin_lock_bh(&priv->tx_lock);
1391
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001392 txq = priv->txq + index;
1393
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001394 BUG_ON(txq->skb[txq->tail] != NULL);
1395 txq->skb[txq->tail] = skb;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001396
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001397 tx = txq->txd + txq->tail;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001398 tx->data_rate = txdatarate;
1399 tx->tx_priority = index;
1400 tx->qos_control = cpu_to_le16(qos);
1401 tx->pkt_phys_addr = cpu_to_le32(dma);
1402 tx->pkt_len = cpu_to_le16(skb->len);
1403 tx->rate_info = 0;
Lennert Buytenheka6804002010-01-04 21:55:42 +01001404 if (!priv->ap_fw && tx_info->control.sta != NULL)
1405 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1406 else
1407 tx->peer_id = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001408 wmb();
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001409 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1410
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001411 txq->stats.count++;
1412 txq->stats.len++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001413 priv->pending_tx_pkts++;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001414
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001415 txq->tail++;
1416 if (txq->tail == MWL8K_TX_DESCS)
1417 txq->tail = 0;
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001418
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001419 if (txq->head == txq->tail)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001420 ieee80211_stop_queue(hw, index);
1421
Lennert Buytenhek23b33902009-07-17 05:21:04 +02001422 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001423
1424 spin_unlock_bh(&priv->tx_lock);
1425
1426 return NETDEV_TX_OK;
1427}
1428
1429
1430/*
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001431 * Firmware access.
1432 *
1433 * We have the following requirements for issuing firmware commands:
1434 * - Some commands require that the packet transmit path is idle when
1435 * the command is issued. (For simplicity, we'll just quiesce the
1436 * transmit path for every command.)
1437 * - There are certain sequences of commands that need to be issued to
1438 * the hardware sequentially, with no other intervening commands.
1439 *
1440 * This leads to an implementation of a "firmware lock" as a mutex that
1441 * can be taken recursively, and which is taken by both the low-level
1442 * command submission function (mwl8k_post_cmd) as well as any users of
1443 * that function that require issuing of an atomic sequence of commands,
1444 * and quiesces the transmit path whenever it's taken.
1445 */
1446static int mwl8k_fw_lock(struct ieee80211_hw *hw)
1447{
1448 struct mwl8k_priv *priv = hw->priv;
1449
1450 if (priv->fw_mutex_owner != current) {
1451 int rc;
1452
1453 mutex_lock(&priv->fw_mutex);
1454 ieee80211_stop_queues(hw);
1455
1456 rc = mwl8k_tx_wait_empty(hw);
1457 if (rc) {
1458 ieee80211_wake_queues(hw);
1459 mutex_unlock(&priv->fw_mutex);
1460
1461 return rc;
1462 }
1463
1464 priv->fw_mutex_owner = current;
1465 }
1466
1467 priv->fw_mutex_depth++;
1468
1469 return 0;
1470}
1471
1472static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
1473{
1474 struct mwl8k_priv *priv = hw->priv;
1475
1476 if (!--priv->fw_mutex_depth) {
1477 ieee80211_wake_queues(hw);
1478 priv->fw_mutex_owner = NULL;
1479 mutex_unlock(&priv->fw_mutex);
1480 }
1481}
1482
1483
1484/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001485 * Command processing.
1486 */
1487
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01001488/* Timeout firmware commands after 10s */
1489#define MWL8K_CMD_TIMEOUT_MS 10000
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001490
1491static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1492{
1493 DECLARE_COMPLETION_ONSTACK(cmd_wait);
1494 struct mwl8k_priv *priv = hw->priv;
1495 void __iomem *regs = priv->regs;
1496 dma_addr_t dma_addr;
1497 unsigned int dma_size;
1498 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001499 unsigned long timeout = 0;
1500 u8 buf[32];
1501
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001502 cmd->result = 0xffff;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001503 dma_size = le16_to_cpu(cmd->length);
1504 dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
1505 PCI_DMA_BIDIRECTIONAL);
1506 if (pci_dma_mapping_error(priv->pdev, dma_addr))
1507 return -ENOMEM;
1508
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001509 rc = mwl8k_fw_lock(hw);
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001510 if (rc) {
1511 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1512 PCI_DMA_BIDIRECTIONAL);
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001513 return rc;
Lennert Buytenhek39a1e422009-08-24 15:42:46 +02001514 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001515
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001516 priv->hostcmd_wait = &cmd_wait;
1517 iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
1518 iowrite32(MWL8K_H2A_INT_DOORBELL,
1519 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
1520 iowrite32(MWL8K_H2A_INT_DUMMY,
1521 regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001522
1523 timeout = wait_for_completion_timeout(&cmd_wait,
1524 msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
1525
Lennert Buytenhek618952a2009-08-18 03:18:01 +02001526 priv->hostcmd_wait = NULL;
1527
1528 mwl8k_fw_unlock(hw);
1529
Lennert Buytenhek37055bd2009-08-03 21:58:47 +02001530 pci_unmap_single(priv->pdev, dma_addr, dma_size,
1531 PCI_DMA_BIDIRECTIONAL);
1532
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001533 if (!timeout) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001534 printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001535 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001536 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1537 MWL8K_CMD_TIMEOUT_MS);
1538 rc = -ETIMEDOUT;
1539 } else {
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01001540 int ms;
1541
1542 ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
1543
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001544 rc = cmd->result ? -EINVAL : 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001545 if (rc)
1546 printk(KERN_ERR "%s: Command %s error 0x%x\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02001547 wiphy_name(hw->wiphy),
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001548 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
Lennert Buytenhek76c962a2009-08-24 15:42:56 +02001549 le16_to_cpu(cmd->result));
Lennert Buytenhek0c9cc6402009-11-30 18:12:49 +01001550 else if (ms > 2000)
1551 printk(KERN_NOTICE "%s: Command %s took %d ms\n",
1552 wiphy_name(hw->wiphy),
1553 mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
1554 ms);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001555 }
1556
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001557 return rc;
1558}
1559
1560/*
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001561 * Setup code shared between STA and AP firmware images.
1562 */
1563static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1564{
1565 struct mwl8k_priv *priv = hw->priv;
1566
1567 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1568 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1569
1570 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1571 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1572
1573 priv->band_24.band = IEEE80211_BAND_2GHZ;
1574 priv->band_24.channels = priv->channels_24;
1575 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1576 priv->band_24.bitrates = priv->rates_24;
1577 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1578
1579 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1580}
1581
1582/*
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001583 * CMD_GET_HW_SPEC (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001584 */
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001585struct mwl8k_cmd_get_hw_spec_sta {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001586 struct mwl8k_cmd_pkt header;
1587 __u8 hw_rev;
1588 __u8 host_interface;
1589 __le16 num_mcaddrs;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02001590 __u8 perm_addr[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001591 __le16 region_code;
1592 __le32 fw_rev;
1593 __le32 ps_cookie;
1594 __le32 caps;
1595 __u8 mcs_bitmap[16];
1596 __le32 rx_queue_ptr;
1597 __le32 num_tx_queues;
1598 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1599 __le32 caps2;
1600 __le32 num_tx_desc_per_queue;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001601 __le32 total_rxd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001602} __attribute__((packed));
1603
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001604#define MWL8K_CAP_MAX_AMSDU 0x20000000
1605#define MWL8K_CAP_GREENFIELD 0x08000000
1606#define MWL8K_CAP_AMPDU 0x04000000
1607#define MWL8K_CAP_RX_STBC 0x01000000
1608#define MWL8K_CAP_TX_STBC 0x00800000
1609#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1610#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1611#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1612#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1613#define MWL8K_CAP_DELAY_BA 0x00003000
1614#define MWL8K_CAP_MIMO 0x00000200
1615#define MWL8K_CAP_40MHZ 0x00000100
1616
1617static void mwl8k_set_ht_caps(struct ieee80211_hw *hw, u32 cap)
1618{
1619 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001620 struct ieee80211_supported_band *band = &priv->band_24;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001621 int rx_streams;
1622 int tx_streams;
1623
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001624 band->ht_cap.ht_supported = 1;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001625
1626 if (cap & MWL8K_CAP_MAX_AMSDU)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001627 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001628 if (cap & MWL8K_CAP_GREENFIELD)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001629 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001630 if (cap & MWL8K_CAP_AMPDU) {
1631 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001632 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1633 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001634 }
1635 if (cap & MWL8K_CAP_RX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001636 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001637 if (cap & MWL8K_CAP_TX_STBC)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001638 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001639 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001640 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001641 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001642 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001643 if (cap & MWL8K_CAP_DELAY_BA)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001644 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001645 if (cap & MWL8K_CAP_40MHZ)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001646 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001647
1648 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1649 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1650
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001651 band->ht_cap.mcs.rx_mask[0] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001652 if (rx_streams >= 2)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001653 band->ht_cap.mcs.rx_mask[1] = 0xff;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001654 if (rx_streams >= 3)
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001655 band->ht_cap.mcs.rx_mask[2] = 0xff;
1656 band->ht_cap.mcs.rx_mask[4] = 0x01;
1657 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001658
1659 if (rx_streams != tx_streams) {
Lennert Buytenhek777ad372010-01-12 13:48:04 +01001660 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1661 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001662 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1663 }
1664}
1665
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001666static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001667{
1668 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek04b147b12009-10-22 20:21:05 +02001669 struct mwl8k_cmd_get_hw_spec_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001670 int rc;
1671 int i;
1672
1673 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1674 if (cmd == NULL)
1675 return -ENOMEM;
1676
1677 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1678 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1679
1680 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1681 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001682 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001683 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001684 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001685 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001686 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02001687 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001688
1689 rc = mwl8k_post_cmd(hw, &cmd->header);
1690
1691 if (!rc) {
1692 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1693 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
Lennert Buytenhek4ff64322009-08-03 21:58:39 +02001694 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001695 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001696 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhek341c9792010-01-04 21:58:40 +01001697 if (cmd->caps & cpu_to_le32(MWL8K_CAP_MIMO))
1698 mwl8k_set_ht_caps(hw, le32_to_cpu(cmd->caps));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001699 }
1700
1701 kfree(cmd);
1702 return rc;
1703}
1704
1705/*
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02001706 * CMD_GET_HW_SPEC (AP version).
1707 */
1708struct mwl8k_cmd_get_hw_spec_ap {
1709 struct mwl8k_cmd_pkt header;
1710 __u8 hw_rev;
1711 __u8 host_interface;
1712 __le16 num_wcb;
1713 __le16 num_mcaddrs;
1714 __u8 perm_addr[ETH_ALEN];
1715 __le16 region_code;
1716 __le16 num_antenna;
1717 __le32 fw_rev;
1718 __le32 wcbbase0;
1719 __le32 rxwrptr;
1720 __le32 rxrdptr;
1721 __le32 ps_cookie;
1722 __le32 wcbbase1;
1723 __le32 wcbbase2;
1724 __le32 wcbbase3;
1725} __attribute__((packed));
1726
1727static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1728{
1729 struct mwl8k_priv *priv = hw->priv;
1730 struct mwl8k_cmd_get_hw_spec_ap *cmd;
1731 int rc;
1732
1733 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1734 if (cmd == NULL)
1735 return -ENOMEM;
1736
1737 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
1738 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1739
1740 memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
1741 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1742
1743 rc = mwl8k_post_cmd(hw, &cmd->header);
1744
1745 if (!rc) {
1746 int off;
1747
1748 SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
1749 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1750 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1751 priv->hw_rev = cmd->hw_rev;
Lennert Buytenhek1349ad22010-01-12 13:48:17 +01001752 mwl8k_setup_2ghz_band(hw);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02001753
1754 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1755 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
1756
1757 off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
1758 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1759
1760 off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
1761 iowrite32(cpu_to_le32(priv->rxq[0].rxd_dma), priv->sram + off);
1762
1763 off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
1764 iowrite32(cpu_to_le32(priv->txq[1].txd_dma), priv->sram + off);
1765
1766 off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
1767 iowrite32(cpu_to_le32(priv->txq[2].txd_dma), priv->sram + off);
1768
1769 off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
1770 iowrite32(cpu_to_le32(priv->txq[3].txd_dma), priv->sram + off);
1771 }
1772
1773 kfree(cmd);
1774 return rc;
1775}
1776
1777/*
1778 * CMD_SET_HW_SPEC.
1779 */
1780struct mwl8k_cmd_set_hw_spec {
1781 struct mwl8k_cmd_pkt header;
1782 __u8 hw_rev;
1783 __u8 host_interface;
1784 __le16 num_mcaddrs;
1785 __u8 perm_addr[ETH_ALEN];
1786 __le16 region_code;
1787 __le32 fw_rev;
1788 __le32 ps_cookie;
1789 __le32 caps;
1790 __le32 rx_queue_ptr;
1791 __le32 num_tx_queues;
1792 __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
1793 __le32 flags;
1794 __le32 num_tx_desc_per_queue;
1795 __le32 total_rxd;
1796} __attribute__((packed));
1797
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001798#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1799#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1800#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02001801
1802static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1803{
1804 struct mwl8k_priv *priv = hw->priv;
1805 struct mwl8k_cmd_set_hw_spec *cmd;
1806 int rc;
1807 int i;
1808
1809 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1810 if (cmd == NULL)
1811 return -ENOMEM;
1812
1813 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
1814 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1815
1816 cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
1817 cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
1818 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1819 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1820 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01001821 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1822 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1823 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02001824 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1825 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1826
1827 rc = mwl8k_post_cmd(hw, &cmd->header);
1828 kfree(cmd);
1829
1830 return rc;
1831}
1832
1833/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001834 * CMD_MAC_MULTICAST_ADR.
1835 */
1836struct mwl8k_cmd_mac_multicast_adr {
1837 struct mwl8k_cmd_pkt header;
1838 __le16 action;
1839 __le16 numaddr;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001840 __u8 addr[0][ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001841};
1842
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001843#define MWL8K_ENABLE_RX_DIRECTED 0x0001
1844#define MWL8K_ENABLE_RX_MULTICAST 0x0002
1845#define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
1846#define MWL8K_ENABLE_RX_BROADCAST 0x0008
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001847
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001848static struct mwl8k_cmd_pkt *
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001849__mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001850 int mc_count, struct dev_addr_list *mclist)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001851{
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001852 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001853 struct mwl8k_cmd_mac_multicast_adr *cmd;
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001854 int size;
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001855
Lennert Buytenhek447ced02009-10-22 20:19:50 +02001856 if (allmulti || mc_count > priv->num_mcaddrs) {
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001857 allmulti = 1;
1858 mc_count = 0;
1859 }
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001860
1861 size = sizeof(*cmd) + mc_count * ETH_ALEN;
1862
1863 cmd = kzalloc(size, GFP_ATOMIC);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001864 if (cmd == NULL)
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001865 return NULL;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001866
1867 cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
1868 cmd->header.length = cpu_to_le16(size);
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001869 cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
1870 MWL8K_ENABLE_RX_BROADCAST);
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02001871
Lennert Buytenhekd5e30842009-10-22 20:19:41 +02001872 if (allmulti) {
1873 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
1874 } else if (mc_count) {
1875 int i;
1876
1877 cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
1878 cmd->numaddr = cpu_to_le16(mc_count);
1879 for (i = 0; i < mc_count && mclist; i++) {
1880 if (mclist->da_addrlen != ETH_ALEN) {
1881 kfree(cmd);
1882 return NULL;
1883 }
1884 memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN);
1885 mclist = mclist->next;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001886 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001887 }
1888
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02001889 return &cmd->header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001890}
1891
1892/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001893 * CMD_GET_STAT.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001894 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001895struct mwl8k_cmd_get_stat {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001896 struct mwl8k_cmd_pkt header;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001897 __le32 stats[64];
1898} __attribute__((packed));
1899
1900#define MWL8K_STAT_ACK_FAILURE 9
1901#define MWL8K_STAT_RTS_FAILURE 12
1902#define MWL8K_STAT_FCS_ERROR 24
1903#define MWL8K_STAT_RTS_SUCCESS 11
1904
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001905static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1906 struct ieee80211_low_level_stats *stats)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001907{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001908 struct mwl8k_cmd_get_stat *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001909 int rc;
1910
1911 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1912 if (cmd == NULL)
1913 return -ENOMEM;
1914
1915 cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
1916 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001917
1918 rc = mwl8k_post_cmd(hw, &cmd->header);
1919 if (!rc) {
1920 stats->dot11ACKFailureCount =
1921 le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
1922 stats->dot11RTSFailureCount =
1923 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
1924 stats->dot11FCSErrorCount =
1925 le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
1926 stats->dot11RTSSuccessCount =
1927 le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
1928 }
1929 kfree(cmd);
1930
1931 return rc;
1932}
1933
1934/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001935 * CMD_RADIO_CONTROL.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001936 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001937struct mwl8k_cmd_radio_control {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001938 struct mwl8k_cmd_pkt header;
1939 __le16 action;
1940 __le16 control;
1941 __le16 radio_on;
1942} __attribute__((packed));
1943
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001944static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001945mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001946{
1947 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001948 struct mwl8k_cmd_radio_control *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001949 int rc;
1950
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001951 if (enable == priv->radio_on && !force)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001952 return 0;
1953
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001954 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1955 if (cmd == NULL)
1956 return -ENOMEM;
1957
1958 cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
1959 cmd->header.length = cpu_to_le16(sizeof(*cmd));
1960 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001961 cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001962 cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
1963
1964 rc = mwl8k_post_cmd(hw, &cmd->header);
1965 kfree(cmd);
1966
1967 if (!rc)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001968 priv->radio_on = enable;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001969
1970 return rc;
1971}
1972
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001973static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001974{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001975 return mwl8k_cmd_radio_control(hw, 0, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001976}
1977
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001978static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001979{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001980 return mwl8k_cmd_radio_control(hw, 1, 0);
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02001981}
1982
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001983static int
1984mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1985{
Lennert Buytenhek99200a992009-11-30 18:31:40 +01001986 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001987
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02001988 priv->radio_short_preamble = short_preamble;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001989
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001990 return mwl8k_cmd_radio_control(hw, 1, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001991}
1992
1993/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001994 * CMD_RF_TX_POWER.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001995 */
1996#define MWL8K_TX_POWER_LEVEL_TOTAL 8
1997
Lennert Buytenhek55489b62009-11-30 18:31:33 +01001998struct mwl8k_cmd_rf_tx_power {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01001999 struct mwl8k_cmd_pkt header;
2000 __le16 action;
2001 __le16 support_level;
2002 __le16 current_level;
2003 __le16 reserved;
2004 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2005} __attribute__((packed));
2006
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002007static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002008{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002009 struct mwl8k_cmd_rf_tx_power *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002010 int rc;
2011
2012 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2013 if (cmd == NULL)
2014 return -ENOMEM;
2015
2016 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
2017 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2018 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2019 cmd->support_level = cpu_to_le16(dBm);
2020
2021 rc = mwl8k_post_cmd(hw, &cmd->header);
2022 kfree(cmd);
2023
2024 return rc;
2025}
2026
2027/*
Lennert Buytenhek08b06342009-10-22 20:21:33 +02002028 * CMD_RF_ANTENNA.
2029 */
2030struct mwl8k_cmd_rf_antenna {
2031 struct mwl8k_cmd_pkt header;
2032 __le16 antenna;
2033 __le16 mode;
2034} __attribute__((packed));
2035
2036#define MWL8K_RF_ANTENNA_RX 1
2037#define MWL8K_RF_ANTENNA_TX 2
2038
2039static int
2040mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2041{
2042 struct mwl8k_cmd_rf_antenna *cmd;
2043 int rc;
2044
2045 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2046 if (cmd == NULL)
2047 return -ENOMEM;
2048
2049 cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
2050 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2051 cmd->antenna = cpu_to_le16(antenna);
2052 cmd->mode = cpu_to_le16(mask);
2053
2054 rc = mwl8k_post_cmd(hw, &cmd->header);
2055 kfree(cmd);
2056
2057 return rc;
2058}
2059
2060/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002061 * CMD_SET_BEACON.
2062 */
2063struct mwl8k_cmd_set_beacon {
2064 struct mwl8k_cmd_pkt header;
2065 __le16 beacon_len;
2066 __u8 beacon[0];
2067};
2068
2069static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, u8 *beacon, int len)
2070{
2071 struct mwl8k_cmd_set_beacon *cmd;
2072 int rc;
2073
2074 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2075 if (cmd == NULL)
2076 return -ENOMEM;
2077
2078 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2079 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2080 cmd->beacon_len = cpu_to_le16(len);
2081 memcpy(cmd->beacon, beacon, len);
2082
2083 rc = mwl8k_post_cmd(hw, &cmd->header);
2084 kfree(cmd);
2085
2086 return rc;
2087}
2088
2089/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002090 * CMD_SET_PRE_SCAN.
2091 */
2092struct mwl8k_cmd_set_pre_scan {
2093 struct mwl8k_cmd_pkt header;
2094} __attribute__((packed));
2095
2096static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
2097{
2098 struct mwl8k_cmd_set_pre_scan *cmd;
2099 int rc;
2100
2101 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2102 if (cmd == NULL)
2103 return -ENOMEM;
2104
2105 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
2106 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2107
2108 rc = mwl8k_post_cmd(hw, &cmd->header);
2109 kfree(cmd);
2110
2111 return rc;
2112}
2113
2114/*
2115 * CMD_SET_POST_SCAN.
2116 */
2117struct mwl8k_cmd_set_post_scan {
2118 struct mwl8k_cmd_pkt header;
2119 __le32 isibss;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002120 __u8 bssid[ETH_ALEN];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002121} __attribute__((packed));
2122
2123static int
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002124mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002125{
2126 struct mwl8k_cmd_set_post_scan *cmd;
2127 int rc;
2128
2129 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2130 if (cmd == NULL)
2131 return -ENOMEM;
2132
2133 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
2134 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2135 cmd->isibss = 0;
Lennert Buytenhekd89173f2009-07-16 09:54:27 +02002136 memcpy(cmd->bssid, mac, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002137
2138 rc = mwl8k_post_cmd(hw, &cmd->header);
2139 kfree(cmd);
2140
2141 return rc;
2142}
2143
2144/*
2145 * CMD_SET_RF_CHANNEL.
2146 */
2147struct mwl8k_cmd_set_rf_channel {
2148 struct mwl8k_cmd_pkt header;
2149 __le16 action;
2150 __u8 current_channel;
2151 __le32 channel_flags;
2152} __attribute__((packed));
2153
2154static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002155 struct ieee80211_conf *conf)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002156{
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002157 struct ieee80211_channel *channel = conf->channel;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002158 struct mwl8k_cmd_set_rf_channel *cmd;
2159 int rc;
2160
2161 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2162 if (cmd == NULL)
2163 return -ENOMEM;
2164
2165 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
2166 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2167 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2168 cmd->current_channel = channel->hw_value;
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002169
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002170 if (channel->band == IEEE80211_BAND_2GHZ)
Lennert Buytenhek610677d2010-01-04 21:56:46 +01002171 cmd->channel_flags |= cpu_to_le32(0x00000001);
2172
2173 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2174 conf->channel_type == NL80211_CHAN_HT20)
2175 cmd->channel_flags |= cpu_to_le32(0x00000080);
2176 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2177 cmd->channel_flags |= cpu_to_le32(0x000001900);
2178 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2179 cmd->channel_flags |= cpu_to_le32(0x000000900);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002180
2181 rc = mwl8k_post_cmd(hw, &cmd->header);
2182 kfree(cmd);
2183
2184 return rc;
2185}
2186
2187/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002188 * CMD_SET_AID.
2189 */
2190#define MWL8K_FRAME_PROT_DISABLED 0x00
2191#define MWL8K_FRAME_PROT_11G 0x07
2192#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2193#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2194
2195struct mwl8k_cmd_update_set_aid {
2196 struct mwl8k_cmd_pkt header;
2197 __le16 aid;
2198
2199 /* AP's MAC address (BSSID) */
2200 __u8 bssid[ETH_ALEN];
2201 __le16 protection_mode;
2202 __u8 supp_rates[14];
2203} __attribute__((packed));
2204
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002205static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2206{
2207 int i;
2208 int j;
2209
2210 /*
2211 * Clear nonstandard rates 4 and 13.
2212 */
2213 mask &= 0x1fef;
2214
2215 for (i = 0, j = 0; i < 14; i++) {
2216 if (mask & (1 << i))
Lennert Buytenhek777ad372010-01-12 13:48:04 +01002217 rates[j++] = mwl8k_rates_24[i].hw_value;
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002218 }
2219}
2220
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002221static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002222mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2223 struct ieee80211_vif *vif, u32 legacy_rate_mask)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002224{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002225 struct mwl8k_cmd_update_set_aid *cmd;
2226 u16 prot_mode;
2227 int rc;
2228
2229 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2230 if (cmd == NULL)
2231 return -ENOMEM;
2232
2233 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2234 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002235 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01002236 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002237
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002238 if (vif->bss_conf.use_cts_prot) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002239 prot_mode = MWL8K_FRAME_PROT_11G;
2240 } else {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01002241 switch (vif->bss_conf.ht_operation_mode &
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002242 IEEE80211_HT_OP_MODE_PROTECTION) {
2243 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2244 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2245 break;
2246 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2247 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2248 break;
2249 default:
2250 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2251 break;
2252 }
2253 }
2254 cmd->protection_mode = cpu_to_le16(prot_mode);
2255
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002256 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002257
2258 rc = mwl8k_post_cmd(hw, &cmd->header);
2259 kfree(cmd);
2260
2261 return rc;
2262}
2263
2264/*
2265 * CMD_SET_RATE.
2266 */
2267struct mwl8k_cmd_set_rate {
2268 struct mwl8k_cmd_pkt header;
2269 __u8 legacy_rates[14];
2270
2271 /* Bitmap for supported MCS codes. */
2272 __u8 mcs_set[16];
2273 __u8 reserved[16];
2274} __attribute__((packed));
2275
2276static int
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002277mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002278 u32 legacy_rate_mask, u8 *mcs_rates)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002279{
2280 struct mwl8k_cmd_set_rate *cmd;
2281 int rc;
2282
2283 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2284 if (cmd == NULL)
2285 return -ENOMEM;
2286
2287 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2288 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002289 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002290 memcpy(cmd->mcs_set, mcs_rates, 16);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002291
2292 rc = mwl8k_post_cmd(hw, &cmd->header);
2293 kfree(cmd);
2294
2295 return rc;
2296}
2297
2298/*
2299 * CMD_FINALIZE_JOIN.
2300 */
2301#define MWL8K_FJ_BEACON_MAXLEN 128
2302
2303struct mwl8k_cmd_finalize_join {
2304 struct mwl8k_cmd_pkt header;
2305 __le32 sleep_interval; /* Number of beacon periods to sleep */
2306 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2307} __attribute__((packed));
2308
2309static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2310 int framelen, int dtim)
2311{
2312 struct mwl8k_cmd_finalize_join *cmd;
2313 struct ieee80211_mgmt *payload = frame;
2314 int payload_len;
2315 int rc;
2316
2317 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2318 if (cmd == NULL)
2319 return -ENOMEM;
2320
2321 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2322 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2323 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2324
2325 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2326 if (payload_len < 0)
2327 payload_len = 0;
2328 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2329 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2330
2331 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2332
2333 rc = mwl8k_post_cmd(hw, &cmd->header);
2334 kfree(cmd);
2335
2336 return rc;
2337}
2338
2339/*
2340 * CMD_SET_RTS_THRESHOLD.
2341 */
2342struct mwl8k_cmd_set_rts_threshold {
2343 struct mwl8k_cmd_pkt header;
2344 __le16 action;
2345 __le16 threshold;
2346} __attribute__((packed));
2347
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002348static int
2349mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002350{
2351 struct mwl8k_cmd_set_rts_threshold *cmd;
2352 int rc;
2353
2354 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2355 if (cmd == NULL)
2356 return -ENOMEM;
2357
2358 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2359 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01002360 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2361 cmd->threshold = cpu_to_le16(rts_thresh);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002362
2363 rc = mwl8k_post_cmd(hw, &cmd->header);
2364 kfree(cmd);
2365
2366 return rc;
2367}
2368
2369/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002370 * CMD_SET_SLOT.
2371 */
2372struct mwl8k_cmd_set_slot {
2373 struct mwl8k_cmd_pkt header;
2374 __le16 action;
2375 __u8 short_slot;
2376} __attribute__((packed));
2377
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002378static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002379{
2380 struct mwl8k_cmd_set_slot *cmd;
2381 int rc;
2382
2383 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2384 if (cmd == NULL)
2385 return -ENOMEM;
2386
2387 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2388 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2389 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
Lennert Buytenhek5539bb52009-07-16 16:06:53 +02002390 cmd->short_slot = short_slot_time;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002391
2392 rc = mwl8k_post_cmd(hw, &cmd->header);
2393 kfree(cmd);
2394
2395 return rc;
2396}
2397
2398/*
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002399 * CMD_SET_EDCA_PARAMS.
2400 */
2401struct mwl8k_cmd_set_edca_params {
2402 struct mwl8k_cmd_pkt header;
2403
2404 /* See MWL8K_SET_EDCA_XXX below */
2405 __le16 action;
2406
2407 /* TX opportunity in units of 32 us */
2408 __le16 txop;
2409
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002410 union {
2411 struct {
2412 /* Log exponent of max contention period: 0...15 */
2413 __le32 log_cw_max;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002414
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002415 /* Log exponent of min contention period: 0...15 */
2416 __le32 log_cw_min;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002417
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002418 /* Adaptive interframe spacing in units of 32us */
2419 __u8 aifs;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002420
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002421 /* TX queue to configure */
2422 __u8 txq;
2423 } ap;
2424 struct {
2425 /* Log exponent of max contention period: 0...15 */
2426 __u8 log_cw_max;
2427
2428 /* Log exponent of min contention period: 0...15 */
2429 __u8 log_cw_min;
2430
2431 /* Adaptive interframe spacing in units of 32us */
2432 __u8 aifs;
2433
2434 /* TX queue to configure */
2435 __u8 txq;
2436 } sta;
2437 };
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002438} __attribute__((packed));
2439
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002440#define MWL8K_SET_EDCA_CW 0x01
2441#define MWL8K_SET_EDCA_TXOP 0x02
2442#define MWL8K_SET_EDCA_AIFS 0x04
2443
2444#define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
2445 MWL8K_SET_EDCA_TXOP | \
2446 MWL8K_SET_EDCA_AIFS)
2447
2448static int
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002449mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2450 __u16 cw_min, __u16 cw_max,
2451 __u8 aifs, __u16 txop)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002452{
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002453 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002454 struct mwl8k_cmd_set_edca_params *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002455 int rc;
2456
2457 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2458 if (cmd == NULL)
2459 return -ENOMEM;
2460
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002461 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2462 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002463 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
2464 cmd->txop = cpu_to_le16(txop);
Lennert Buytenhek2e484c82009-10-22 20:21:43 +02002465 if (priv->ap_fw) {
2466 cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
2467 cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
2468 cmd->ap.aifs = aifs;
2469 cmd->ap.txq = qnum;
2470 } else {
2471 cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
2472 cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
2473 cmd->sta.aifs = aifs;
2474 cmd->sta.txq = qnum;
2475 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002476
2477 rc = mwl8k_post_cmd(hw, &cmd->header);
2478 kfree(cmd);
2479
2480 return rc;
2481}
2482
2483/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002484 * CMD_SET_WMM_MODE.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002485 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002486struct mwl8k_cmd_set_wmm_mode {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002487 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002488 __le16 action;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002489} __attribute__((packed));
2490
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002491static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002492{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002493 struct mwl8k_priv *priv = hw->priv;
2494 struct mwl8k_cmd_set_wmm_mode *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002495 int rc;
2496
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002497 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2498 if (cmd == NULL)
2499 return -ENOMEM;
2500
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002501 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002502 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002503 cmd->action = cpu_to_le16(!!enable);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002504
2505 rc = mwl8k_post_cmd(hw, &cmd->header);
2506 kfree(cmd);
Lennert Buytenhek16cec432009-11-30 18:14:23 +01002507
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002508 if (!rc)
2509 priv->wmm_enabled = enable;
2510
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002511 return rc;
2512}
2513
2514/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002515 * CMD_MIMO_CONFIG.
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002516 */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002517struct mwl8k_cmd_mimo_config {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002518 struct mwl8k_cmd_pkt header;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002519 __le32 action;
2520 __u8 rx_antenna_map;
2521 __u8 tx_antenna_map;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002522} __attribute__((packed));
2523
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002524static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002525{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002526 struct mwl8k_cmd_mimo_config *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002527 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002528
2529 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2530 if (cmd == NULL)
2531 return -ENOMEM;
2532
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002533 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002534 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002535 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2536 cmd->rx_antenna_map = rx;
2537 cmd->tx_antenna_map = tx;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002538
2539 rc = mwl8k_post_cmd(hw, &cmd->header);
2540 kfree(cmd);
2541
2542 return rc;
2543}
2544
2545/*
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002546 * CMD_USE_FIXED_RATE (STA version).
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002547 */
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002548struct mwl8k_cmd_use_fixed_rate_sta {
2549 struct mwl8k_cmd_pkt header;
2550 __le32 action;
2551 __le32 allow_rate_drop;
2552 __le32 num_rates;
2553 struct {
2554 __le32 is_ht_rate;
2555 __le32 enable_retry;
2556 __le32 rate;
2557 __le32 retry_count;
2558 } rate_entry[8];
2559 __le32 rate_type;
2560 __le32 reserved1;
2561 __le32 reserved2;
2562} __attribute__((packed));
2563
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002564#define MWL8K_USE_AUTO_RATE 0x0002
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002565#define MWL8K_UCAST_RATE 0
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002566
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002567static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002568{
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002569 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002570 int rc;
2571
2572 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2573 if (cmd == NULL)
2574 return -ENOMEM;
2575
2576 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2577 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01002578 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2579 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002580
2581 rc = mwl8k_post_cmd(hw, &cmd->header);
2582 kfree(cmd);
2583
2584 return rc;
2585}
2586
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002587/*
Lennert Buytenhek088aab82010-01-08 18:30:36 +01002588 * CMD_USE_FIXED_RATE (AP version).
2589 */
2590struct mwl8k_cmd_use_fixed_rate_ap {
2591 struct mwl8k_cmd_pkt header;
2592 __le32 action;
2593 __le32 allow_rate_drop;
2594 __le32 num_rates;
2595 struct mwl8k_rate_entry_ap {
2596 __le32 is_ht_rate;
2597 __le32 enable_retry;
2598 __le32 rate;
2599 __le32 retry_count;
2600 } rate_entry[4];
2601 u8 multicast_rate;
2602 u8 multicast_rate_type;
2603 u8 management_rate;
2604} __attribute__((packed));
2605
2606static int
2607mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2608{
2609 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2610 int rc;
2611
2612 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2613 if (cmd == NULL)
2614 return -ENOMEM;
2615
2616 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2617 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2618 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2619 cmd->multicast_rate = mcast;
2620 cmd->management_rate = mgmt;
2621
2622 rc = mwl8k_post_cmd(hw, &cmd->header);
2623 kfree(cmd);
2624
2625 return rc;
2626}
2627
2628/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002629 * CMD_ENABLE_SNIFFER.
2630 */
2631struct mwl8k_cmd_enable_sniffer {
2632 struct mwl8k_cmd_pkt header;
2633 __le32 action;
2634} __attribute__((packed));
2635
2636static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2637{
2638 struct mwl8k_cmd_enable_sniffer *cmd;
2639 int rc;
2640
2641 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2642 if (cmd == NULL)
2643 return -ENOMEM;
2644
2645 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2646 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2647 cmd->action = cpu_to_le32(!!enable);
2648
2649 rc = mwl8k_post_cmd(hw, &cmd->header);
2650 kfree(cmd);
2651
2652 return rc;
2653}
2654
2655/*
2656 * CMD_SET_MAC_ADDR.
2657 */
2658struct mwl8k_cmd_set_mac_addr {
2659 struct mwl8k_cmd_pkt header;
2660 union {
2661 struct {
2662 __le16 mac_type;
2663 __u8 mac_addr[ETH_ALEN];
2664 } mbss;
2665 __u8 mac_addr[ETH_ALEN];
2666 };
2667} __attribute__((packed));
2668
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002669#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2670#define MWL8K_MAC_TYPE_PRIMARY_AP 2
2671
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002672static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2673{
2674 struct mwl8k_priv *priv = hw->priv;
2675 struct mwl8k_cmd_set_mac_addr *cmd;
2676 int rc;
2677
2678 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2679 if (cmd == NULL)
2680 return -ENOMEM;
2681
2682 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2683 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2684 if (priv->ap_fw) {
Lennert Buytenheka9e00b12010-01-08 18:31:30 +01002685 cmd->mbss.mac_type = cpu_to_le16(MWL8K_MAC_TYPE_PRIMARY_AP);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002686 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2687 } else {
2688 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2689 }
2690
2691 rc = mwl8k_post_cmd(hw, &cmd->header);
2692 kfree(cmd);
2693
2694 return rc;
2695}
2696
2697/*
2698 * CMD_SET_RATEADAPT_MODE.
2699 */
2700struct mwl8k_cmd_set_rate_adapt_mode {
2701 struct mwl8k_cmd_pkt header;
2702 __le16 action;
2703 __le16 mode;
2704} __attribute__((packed));
2705
2706static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2707{
2708 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2709 int rc;
2710
2711 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2712 if (cmd == NULL)
2713 return -ENOMEM;
2714
2715 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2716 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2717 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2718 cmd->mode = cpu_to_le16(mode);
2719
2720 rc = mwl8k_post_cmd(hw, &cmd->header);
2721 kfree(cmd);
2722
2723 return rc;
2724}
2725
2726/*
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002727 * CMD_BSS_START.
2728 */
2729struct mwl8k_cmd_bss_start {
2730 struct mwl8k_cmd_pkt header;
2731 __le32 enable;
2732} __attribute__((packed));
2733
2734static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, int enable)
2735{
2736 struct mwl8k_cmd_bss_start *cmd;
2737 int rc;
2738
2739 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2740 if (cmd == NULL)
2741 return -ENOMEM;
2742
2743 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2744 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2745 cmd->enable = cpu_to_le32(enable);
2746
2747 rc = mwl8k_post_cmd(hw, &cmd->header);
2748 kfree(cmd);
2749
2750 return rc;
2751}
2752
2753/*
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002754 * CMD_SET_NEW_STN.
2755 */
2756struct mwl8k_cmd_set_new_stn {
2757 struct mwl8k_cmd_pkt header;
2758 __le16 aid;
2759 __u8 mac_addr[6];
2760 __le16 stn_id;
2761 __le16 action;
2762 __le16 rsvd;
2763 __le32 legacy_rates;
2764 __u8 ht_rates[4];
2765 __le16 cap_info;
2766 __le16 ht_capabilities_info;
2767 __u8 mac_ht_param_info;
2768 __u8 rev;
2769 __u8 control_channel;
2770 __u8 add_channel;
2771 __le16 op_mode;
2772 __le16 stbc;
2773 __u8 add_qos_info;
2774 __u8 is_qos_sta;
2775 __le32 fw_sta_ptr;
2776} __attribute__((packed));
2777
2778#define MWL8K_STA_ACTION_ADD 0
2779#define MWL8K_STA_ACTION_REMOVE 2
2780
2781static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2782 struct ieee80211_vif *vif,
2783 struct ieee80211_sta *sta)
2784{
2785 struct mwl8k_cmd_set_new_stn *cmd;
2786 int rc;
2787
2788 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2789 if (cmd == NULL)
2790 return -ENOMEM;
2791
2792 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2793 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2794 cmd->aid = cpu_to_le16(sta->aid);
2795 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2796 cmd->stn_id = cpu_to_le16(sta->aid);
2797 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
2798 cmd->legacy_rates = cpu_to_le32(sta->supp_rates[IEEE80211_BAND_2GHZ]);
2799 if (sta->ht_cap.ht_supported) {
2800 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2801 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2802 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2803 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2804 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2805 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2806 ((sta->ht_cap.ampdu_density & 7) << 2);
2807 cmd->is_qos_sta = 1;
2808 }
2809
2810 rc = mwl8k_post_cmd(hw, &cmd->header);
2811 kfree(cmd);
2812
2813 return rc;
2814}
2815
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01002816static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2817 struct ieee80211_vif *vif)
2818{
2819 struct mwl8k_cmd_set_new_stn *cmd;
2820 int rc;
2821
2822 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2823 if (cmd == NULL)
2824 return -ENOMEM;
2825
2826 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2827 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2828 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2829
2830 rc = mwl8k_post_cmd(hw, &cmd->header);
2831 kfree(cmd);
2832
2833 return rc;
2834}
2835
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01002836static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2837 struct ieee80211_vif *vif, u8 *addr)
2838{
2839 struct mwl8k_cmd_set_new_stn *cmd;
2840 int rc;
2841
2842 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2843 if (cmd == NULL)
2844 return -ENOMEM;
2845
2846 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2847 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2848 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2849 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2850
2851 rc = mwl8k_post_cmd(hw, &cmd->header);
2852 kfree(cmd);
2853
2854 return rc;
2855}
2856
2857/*
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002858 * CMD_UPDATE_STADB.
2859 */
Lennert Buytenhek25d81b12010-01-04 21:54:41 +01002860struct ewc_ht_info {
2861 __le16 control1;
2862 __le16 control2;
2863 __le16 control3;
2864} __attribute__((packed));
2865
2866struct peer_capability_info {
2867 /* Peer type - AP vs. STA. */
2868 __u8 peer_type;
2869
2870 /* Basic 802.11 capabilities from assoc resp. */
2871 __le16 basic_caps;
2872
2873 /* Set if peer supports 802.11n high throughput (HT). */
2874 __u8 ht_support;
2875
2876 /* Valid if HT is supported. */
2877 __le16 ht_caps;
2878 __u8 extended_ht_caps;
2879 struct ewc_ht_info ewc_info;
2880
2881 /* Legacy rate table. Intersection of our rates and peer rates. */
2882 __u8 legacy_rates[12];
2883
2884 /* HT rate table. Intersection of our rates and peer rates. */
2885 __u8 ht_rates[16];
2886 __u8 pad[16];
2887
2888 /* If set, interoperability mode, no proprietary extensions. */
2889 __u8 interop;
2890 __u8 pad2;
2891 __u8 station_id;
2892 __le16 amsdu_enabled;
2893} __attribute__((packed));
2894
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002895struct mwl8k_cmd_update_stadb {
2896 struct mwl8k_cmd_pkt header;
2897
2898 /* See STADB_ACTION_TYPE */
2899 __le32 action;
2900
2901 /* Peer MAC address */
2902 __u8 peer_addr[ETH_ALEN];
2903
2904 __le32 reserved;
2905
2906 /* Peer info - valid during add/update. */
2907 struct peer_capability_info peer_info;
2908} __attribute__((packed));
2909
Lennert Buytenheka6804002010-01-04 21:55:42 +01002910#define MWL8K_STA_DB_MODIFY_ENTRY 1
2911#define MWL8K_STA_DB_DEL_ENTRY 2
2912
2913/* Peer Entry flags - used to define the type of the peer node */
2914#define MWL8K_PEER_TYPE_ACCESSPOINT 2
2915
2916static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01002917 struct ieee80211_vif *vif,
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002918 struct ieee80211_sta *sta)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002919{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002920 struct mwl8k_cmd_update_stadb *cmd;
Lennert Buytenheka6804002010-01-04 21:55:42 +01002921 struct peer_capability_info *p;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002922 int rc;
2923
2924 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2925 if (cmd == NULL)
2926 return -ENOMEM;
2927
2928 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2929 cmd->header.length = cpu_to_le16(sizeof(*cmd));
Lennert Buytenheka6804002010-01-04 21:55:42 +01002930 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002931 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002932
Lennert Buytenheka6804002010-01-04 21:55:42 +01002933 p = &cmd->peer_info;
2934 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2935 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
Lennert Buytenhek13935e22010-01-04 21:57:59 +01002936 p->ht_support = sta->ht_cap.ht_supported;
2937 p->ht_caps = sta->ht_cap.cap;
2938 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
2939 ((sta->ht_cap.ampdu_density & 7) << 2);
2940 legacy_rate_mask_to_array(p->legacy_rates,
2941 sta->supp_rates[IEEE80211_BAND_2GHZ]);
2942 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
Lennert Buytenheka6804002010-01-04 21:55:42 +01002943 p->interop = 1;
2944 p->amsdu_enabled = 0;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002945
Lennert Buytenheka6804002010-01-04 21:55:42 +01002946 rc = mwl8k_post_cmd(hw, &cmd->header);
2947 kfree(cmd);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002948
Lennert Buytenheka6804002010-01-04 21:55:42 +01002949 return rc ? rc : p->station_id;
2950}
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002951
Lennert Buytenheka6804002010-01-04 21:55:42 +01002952static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
2953 struct ieee80211_vif *vif, u8 *addr)
2954{
2955 struct mwl8k_cmd_update_stadb *cmd;
2956 int rc;
2957
2958 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2959 if (cmd == NULL)
2960 return -ENOMEM;
2961
2962 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2963 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2964 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
2965 memcpy(cmd->peer_addr, addr, ETH_ALEN);
2966
2967 rc = mwl8k_post_cmd(hw, &cmd->header);
Lennert Buytenhek55489b62009-11-30 18:31:33 +01002968 kfree(cmd);
2969
2970 return rc;
2971}
2972
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002973
2974/*
2975 * Interrupt handling.
2976 */
2977static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2978{
2979 struct ieee80211_hw *hw = dev_id;
2980 struct mwl8k_priv *priv = hw->priv;
2981 u32 status;
2982
2983 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002984 if (!status)
2985 return IRQ_NONE;
2986
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01002987 if (status & MWL8K_A2H_INT_TX_DONE) {
2988 status &= ~MWL8K_A2H_INT_TX_DONE;
2989 tasklet_schedule(&priv->poll_tx_task);
2990 }
2991
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01002992 if (status & MWL8K_A2H_INT_RX_READY) {
2993 status &= ~MWL8K_A2H_INT_RX_READY;
2994 tasklet_schedule(&priv->poll_rx_task);
2995 }
2996
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01002997 if (status)
2998 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01002999
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003000 if (status & MWL8K_A2H_INT_OPC_DONE) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003001 if (priv->hostcmd_wait != NULL)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003002 complete(priv->hostcmd_wait);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003003 }
3004
3005 if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003006 if (!mutex_is_locked(&priv->fw_mutex) &&
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003007 priv->radio_on && priv->pending_tx_pkts)
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003008 mwl8k_tx_start(priv);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003009 }
3010
3011 return IRQ_HANDLED;
3012}
3013
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003014static void mwl8k_tx_poll(unsigned long data)
3015{
3016 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3017 struct mwl8k_priv *priv = hw->priv;
3018 int limit;
3019 int i;
3020
3021 limit = 32;
3022
3023 spin_lock_bh(&priv->tx_lock);
3024
3025 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3026 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3027
3028 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3029 complete(priv->tx_wait);
3030 priv->tx_wait = NULL;
3031 }
3032
3033 spin_unlock_bh(&priv->tx_lock);
3034
3035 if (limit) {
3036 writel(~MWL8K_A2H_INT_TX_DONE,
3037 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3038 } else {
3039 tasklet_schedule(&priv->poll_tx_task);
3040 }
3041}
3042
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003043static void mwl8k_rx_poll(unsigned long data)
3044{
3045 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3046 struct mwl8k_priv *priv = hw->priv;
3047 int limit;
3048
3049 limit = 32;
3050 limit -= rxq_process(hw, 0, limit);
3051 limit -= rxq_refill(hw, 0, limit);
3052
3053 if (limit) {
3054 writel(~MWL8K_A2H_INT_RX_READY,
3055 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3056 } else {
3057 tasklet_schedule(&priv->poll_rx_task);
3058 }
3059}
3060
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003061
3062/*
3063 * Core driver operations.
3064 */
3065static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3066{
3067 struct mwl8k_priv *priv = hw->priv;
3068 int index = skb_get_queue_mapping(skb);
3069 int rc;
3070
Lennert Buytenhek9189c102010-01-12 13:47:32 +01003071 if (!priv->radio_on) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003072 printk(KERN_DEBUG "%s: dropped TX frame since radio "
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003073 "disabled\n", wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003074 dev_kfree_skb(skb);
3075 return NETDEV_TX_OK;
3076 }
3077
3078 rc = mwl8k_txq_xmit(hw, index, skb);
3079
3080 return rc;
3081}
3082
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003083static int mwl8k_start(struct ieee80211_hw *hw)
3084{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003085 struct mwl8k_priv *priv = hw->priv;
3086 int rc;
3087
Joe Perchesa0607fd2009-11-18 23:29:17 -08003088 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003089 IRQF_SHARED, MWL8K_NAME, hw);
3090 if (rc) {
3091 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003092 wiphy_name(hw->wiphy));
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003093 return -EIO;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003094 }
3095
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003096 /* Enable TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003097 tasklet_enable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003098 tasklet_enable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003099
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003100 /* Enable interrupts */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003101 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003102
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003103 rc = mwl8k_fw_lock(hw);
3104 if (!rc) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003105 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003106
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003107 if (!priv->ap_fw) {
3108 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003109 rc = mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003110
Lennert Buytenhek5e4cf162009-10-22 20:21:38 +02003111 if (!rc)
3112 rc = mwl8k_cmd_set_pre_scan(hw);
3113
3114 if (!rc)
3115 rc = mwl8k_cmd_set_post_scan(hw,
3116 "\x00\x00\x00\x00\x00\x00");
3117 }
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003118
3119 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003120 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003121
3122 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003123 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003124
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003125 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003126 }
3127
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003128 if (rc) {
3129 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3130 free_irq(priv->pdev->irq, hw);
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003131 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003132 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenhek2ec610c2009-07-17 07:11:37 +02003133 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003134
3135 return rc;
3136}
3137
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003138static void mwl8k_stop(struct ieee80211_hw *hw)
3139{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003140 struct mwl8k_priv *priv = hw->priv;
3141 int i;
3142
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003143 mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003144
3145 ieee80211_stop_queues(hw);
3146
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003147 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003148 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003149 free_irq(priv->pdev->irq, hw);
3150
3151 /* Stop finalize join worker */
3152 cancel_work_sync(&priv->finalize_join_worker);
3153 if (priv->beacon_skb != NULL)
3154 dev_kfree_skb(priv->beacon_skb);
3155
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003156 /* Stop TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003157 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003158 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003159
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003160 /* Return all skbs to mac80211 */
3161 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01003162 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003163}
3164
3165static int mwl8k_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003166 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003167{
3168 struct mwl8k_priv *priv = hw->priv;
3169 struct mwl8k_vif *mwl8k_vif;
3170
3171 /*
3172 * We only support one active interface at a time.
3173 */
3174 if (priv->vif != NULL)
3175 return -EBUSY;
3176
3177 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003178 * Reject interface creation if sniffer mode is active, as
3179 * STA operation is mutually exclusive with hardware sniffer
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003180 * mode. (Sniffer mode is only used on STA firmware.)
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003181 */
3182 if (priv->sniffer_enabled) {
3183 printk(KERN_INFO "%s: unable to create STA "
3184 "interface due to sniffer mode being enabled\n",
3185 wiphy_name(hw->wiphy));
3186 return -EINVAL;
3187 }
3188
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003189 /* Set the mac address. */
3190 mwl8k_cmd_set_mac_addr(hw, vif->addr);
3191
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003192 if (priv->ap_fw)
3193 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3194
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003195 /* Clean out driver private area */
Johannes Berg1ed32e42009-12-23 13:15:45 +01003196 mwl8k_vif = MWL8K_VIF(vif);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003197 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
3198
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003199 /* Set Initial sequence number to zero */
3200 mwl8k_vif->seqno = 0;
3201
Johannes Berg1ed32e42009-12-23 13:15:45 +01003202 priv->vif = vif;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003203
3204 return 0;
3205}
3206
3207static void mwl8k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01003208 struct ieee80211_vif *vif)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003209{
3210 struct mwl8k_priv *priv = hw->priv;
3211
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003212 if (priv->ap_fw)
3213 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
3214
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003215 mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003216
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003217 priv->vif = NULL;
3218}
3219
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003220static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003221{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003222 struct ieee80211_conf *conf = &hw->conf;
3223 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003224 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003225
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003226 if (conf->flags & IEEE80211_CONF_IDLE) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003227 mwl8k_cmd_radio_disable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003228 return 0;
Lennert Buytenhek7595d672009-08-17 23:59:40 +02003229 }
3230
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003231 rc = mwl8k_fw_lock(hw);
3232 if (rc)
3233 return rc;
3234
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003235 rc = mwl8k_cmd_radio_enable(hw);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003236 if (rc)
3237 goto out;
3238
Lennert Buytenhek610677d2010-01-04 21:56:46 +01003239 rc = mwl8k_cmd_set_rf_channel(hw, conf);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003240 if (rc)
3241 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003242
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003243 if (conf->power_level > 18)
3244 conf->power_level = 18;
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003245 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003246 if (rc)
3247 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003248
Lennert Buytenhek08b06342009-10-22 20:21:33 +02003249 if (priv->ap_fw) {
3250 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
3251 if (!rc)
3252 rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
3253 } else {
3254 rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
3255 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003256
Lennert Buytenhekee03a932009-07-17 07:19:37 +02003257out:
3258 mwl8k_fw_unlock(hw);
3259
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003260 return rc;
3261}
3262
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003263static void
3264mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3265 struct ieee80211_bss_conf *info, u32 changed)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003266{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003267 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003268 u32 ap_legacy_rates;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003269 u8 ap_mcs_rates[16];
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003270 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003271
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003272 if (mwl8k_fw_lock(hw))
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003273 return;
3274
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003275 /*
3276 * No need to capture a beacon if we're no longer associated.
3277 */
3278 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3279 priv->capture_beacon = false;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003280
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003281 /*
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003282 * Get the AP's legacy and MCS rates.
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003283 */
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003284 if (vif->bss_conf.assoc) {
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003285 struct ieee80211_sta *ap;
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003286
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003287 rcu_read_lock();
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003288
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003289 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003290 if (ap == NULL) {
3291 rcu_read_unlock();
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003292 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003293 }
Lennert Buytenhekc6e96012010-01-04 21:55:52 +01003294
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003295 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003296 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003297
3298 rcu_read_unlock();
3299 }
3300
3301 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003302 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003303 if (rc)
3304 goto out;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003305
Lennert Buytenhekb71ed2c2010-01-08 18:30:16 +01003306 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003307 if (rc)
3308 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003309 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003310
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003311 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003312 rc = mwl8k_set_radio_preamble(hw,
3313 vif->bss_conf.use_short_preamble);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003314 if (rc)
3315 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003316 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003317
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003318 if (changed & BSS_CHANGED_ERP_SLOT) {
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003319 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003320 if (rc)
3321 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003322 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003323
Lennert Buytenhekc97470d2010-01-12 13:47:37 +01003324 if (vif->bss_conf.assoc &&
3325 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3326 BSS_CHANGED_HT))) {
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003327 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003328 if (rc)
3329 goto out;
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003330 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003331
Lennert Buytenhekc3cbbe82010-01-04 21:56:07 +01003332 if (vif->bss_conf.assoc &&
3333 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003334 /*
3335 * Finalize the join. Tell rx handler to process
3336 * next beacon from our BSSID.
3337 */
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003338 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003339 priv->capture_beacon = true;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003340 }
3341
Lennert Buytenhek3a980d02009-07-17 07:21:46 +02003342out:
3343 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003344}
3345
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003346static void
3347mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3348 struct ieee80211_bss_conf *info, u32 changed)
3349{
3350 int rc;
3351
3352 if (mwl8k_fw_lock(hw))
3353 return;
3354
3355 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3356 rc = mwl8k_set_radio_preamble(hw,
3357 vif->bss_conf.use_short_preamble);
3358 if (rc)
3359 goto out;
3360 }
3361
3362 if (changed & BSS_CHANGED_BASIC_RATES) {
3363 int idx;
3364 int rate;
3365
3366 /*
3367 * Use lowest supported basic rate for multicasts
3368 * and management frames (such as probe responses --
3369 * beacons will always go out at 1 Mb/s).
3370 */
3371 idx = ffs(vif->bss_conf.basic_rates);
Lennert Buytenhek777ad372010-01-12 13:48:04 +01003372 rate = idx ? mwl8k_rates_24[idx - 1].hw_value : 2;
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003373
3374 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3375 }
3376
3377 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3378 struct sk_buff *skb;
3379
3380 skb = ieee80211_beacon_get(hw, vif);
3381 if (skb != NULL) {
3382 mwl8k_cmd_set_beacon(hw, skb->data, skb->len);
3383 kfree_skb(skb);
3384 }
3385 }
3386
3387 if (changed & BSS_CHANGED_BEACON_ENABLED)
3388 mwl8k_cmd_bss_start(hw, info->enable_beacon);
3389
3390out:
3391 mwl8k_fw_unlock(hw);
3392}
3393
3394static void
3395mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3396 struct ieee80211_bss_conf *info, u32 changed)
3397{
3398 struct mwl8k_priv *priv = hw->priv;
3399
3400 if (!priv->ap_fw)
3401 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3402 else
3403 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3404}
3405
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003406static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3407 int mc_count, struct dev_addr_list *mclist)
3408{
3409 struct mwl8k_cmd_pkt *cmd;
3410
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003411 /*
3412 * Synthesize and return a command packet that programs the
3413 * hardware multicast address filter. At this point we don't
3414 * know whether FIF_ALLMULTI is being requested, but if it is,
3415 * we'll end up throwing this packet away and creating a new
3416 * one in mwl8k_configure_filter().
3417 */
3418 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_count, mclist);
Lennert Buytenheke81cd2d2009-08-18 03:55:42 +02003419
3420 return (unsigned long)cmd;
3421}
3422
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003423static int
3424mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3425 unsigned int changed_flags,
3426 unsigned int *total_flags)
3427{
3428 struct mwl8k_priv *priv = hw->priv;
3429
3430 /*
3431 * Hardware sniffer mode is mutually exclusive with STA
3432 * operation, so refuse to enable sniffer mode if a STA
3433 * interface is active.
3434 */
3435 if (priv->vif != NULL) {
3436 if (net_ratelimit())
3437 printk(KERN_INFO "%s: not enabling sniffer "
3438 "mode because STA interface is active\n",
3439 wiphy_name(hw->wiphy));
3440 return 0;
3441 }
3442
3443 if (!priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003444 if (mwl8k_cmd_enable_sniffer(hw, 1))
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003445 return 0;
3446 priv->sniffer_enabled = true;
3447 }
3448
3449 *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
3450 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
3451 FIF_OTHER_BSS;
3452
3453 return 1;
3454}
3455
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003456static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3457 unsigned int changed_flags,
3458 unsigned int *total_flags,
3459 u64 multicast)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003460{
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003461 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003462 struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
3463
3464 /*
Lennert Buytenhekc0adae22009-10-22 20:21:36 +02003465 * AP firmware doesn't allow fine-grained control over
3466 * the receive filter.
3467 */
3468 if (priv->ap_fw) {
3469 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
3470 kfree(cmd);
3471 return;
3472 }
3473
3474 /*
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003475 * Enable hardware sniffer mode if FIF_CONTROL or
3476 * FIF_OTHER_BSS is requested.
3477 */
3478 if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
3479 mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
3480 kfree(cmd);
3481 return;
3482 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003483
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003484 /* Clear unsupported feature flags */
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003485 *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003486
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003487 if (mwl8k_fw_lock(hw)) {
3488 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003489 return;
Lennert Buytenhek90852f72010-01-02 10:31:42 +01003490 }
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003491
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003492 if (priv->sniffer_enabled) {
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003493 mwl8k_cmd_enable_sniffer(hw, 0);
Lennert Buytenheka43c49a2009-10-22 20:20:32 +02003494 priv->sniffer_enabled = false;
3495 }
3496
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003497 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
Lennert Buytenhek77165d882009-10-22 20:19:53 +02003498 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
3499 /*
3500 * Disable the BSS filter.
3501 */
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003502 mwl8k_cmd_set_pre_scan(hw);
Lennert Buytenhek77165d882009-10-22 20:19:53 +02003503 } else {
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003504 const u8 *bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003505
Lennert Buytenhek77165d882009-10-22 20:19:53 +02003506 /*
3507 * Enable the BSS filter.
3508 *
3509 * If there is an active STA interface, use that
3510 * interface's BSSID, otherwise use a dummy one
3511 * (where the OUI part needs to be nonzero for
3512 * the BSSID to be accepted by POST_SCAN).
3513 */
3514 bssid = "\x01\x00\x00\x00\x00\x00";
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003515 if (priv->vif != NULL)
Lennert Buytenhek0a11dfc2010-01-04 21:55:21 +01003516 bssid = priv->vif->bss_conf.bssid;
Lennert Buytenheka94cc972009-08-03 21:58:57 +02003517
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003518 mwl8k_cmd_set_post_scan(hw, bssid);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003519 }
3520 }
3521
Lennert Buytenhek447ced02009-10-22 20:19:50 +02003522 /*
3523 * If FIF_ALLMULTI is being requested, throw away the command
3524 * packet that ->prepare_multicast() built and replace it with
3525 * a command packet that enables reception of all multicast
3526 * packets.
3527 */
3528 if (*total_flags & FIF_ALLMULTI) {
3529 kfree(cmd);
3530 cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, 0, NULL);
3531 }
3532
3533 if (cmd != NULL) {
3534 mwl8k_post_cmd(hw, cmd);
3535 kfree(cmd);
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003536 }
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003537
Lennert Buytenheke6935ea2009-08-18 04:06:20 +02003538 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003539}
3540
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003541static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3542{
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003543 return mwl8k_cmd_set_rts_threshold(hw, value);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003544}
3545
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003546struct mwl8k_sta_notify_item
3547{
3548 struct list_head list;
3549 struct ieee80211_vif *vif;
3550 enum sta_notify_cmd cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003551 struct ieee80211_sta sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003552};
3553
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003554static void
3555mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3556{
3557 struct mwl8k_priv *priv = hw->priv;
3558
3559 /*
3560 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3561 */
3562 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3563 int rc;
3564
3565 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3566 if (rc >= 0) {
3567 struct ieee80211_sta *sta;
3568
3569 rcu_read_lock();
3570 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3571 if (sta != NULL)
3572 MWL8K_STA(sta)->peer_id = rc;
3573 rcu_read_unlock();
3574 }
3575 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3576 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3577 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3578 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3579 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3580 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3581 }
3582}
3583
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003584static void mwl8k_sta_notify_worker(struct work_struct *work)
3585{
3586 struct mwl8k_priv *priv =
3587 container_of(work, struct mwl8k_priv, sta_notify_worker);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003588 struct ieee80211_hw *hw = priv->hw;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003589
3590 spin_lock_bh(&priv->sta_notify_list_lock);
3591 while (!list_empty(&priv->sta_notify_list)) {
3592 struct mwl8k_sta_notify_item *s;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003593
3594 s = list_entry(priv->sta_notify_list.next,
3595 struct mwl8k_sta_notify_item, list);
3596 list_del(&s->list);
3597
3598 spin_unlock_bh(&priv->sta_notify_list_lock);
3599
Lennert Buytenhek3f5610f2010-01-08 18:30:58 +01003600 mwl8k_do_sta_notify(hw, s);
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003601 kfree(s);
3602
3603 spin_lock_bh(&priv->sta_notify_list_lock);
3604 }
3605 spin_unlock_bh(&priv->sta_notify_list_lock);
3606}
3607
3608static void
3609mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3610 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3611{
3612 struct mwl8k_priv *priv = hw->priv;
3613 struct mwl8k_sta_notify_item *s;
3614
3615 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3616 return;
3617
3618 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3619 if (s != NULL) {
3620 s->vif = vif;
3621 s->cmd = cmd;
Lennert Buytenhek13935e22010-01-04 21:57:59 +01003622 s->sta = *sta;
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003623
3624 spin_lock(&priv->sta_notify_list_lock);
3625 list_add_tail(&s->list, &priv->sta_notify_list);
3626 spin_unlock(&priv->sta_notify_list_lock);
3627
3628 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3629 }
3630}
3631
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003632static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3633 const struct ieee80211_tx_queue_params *params)
3634{
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003635 struct mwl8k_priv *priv = hw->priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003636 int rc;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003637
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003638 rc = mwl8k_fw_lock(hw);
3639 if (!rc) {
3640 if (!priv->wmm_enabled)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003641 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003642
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003643 if (!rc)
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003644 rc = mwl8k_cmd_set_edca_params(hw, queue,
3645 params->cw_min,
3646 params->cw_max,
3647 params->aifs,
3648 params->txop);
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003649
3650 mwl8k_fw_unlock(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003651 }
Lennert Buytenhek3e4f5422009-07-17 07:25:59 +02003652
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003653 return rc;
3654}
3655
3656static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3657 struct ieee80211_tx_queue_stats *stats)
3658{
3659 struct mwl8k_priv *priv = hw->priv;
3660 struct mwl8k_tx_queue *txq;
3661 int index;
3662
3663 spin_lock_bh(&priv->tx_lock);
3664 for (index = 0; index < MWL8K_TX_QUEUES; index++) {
3665 txq = priv->txq + index;
Lennert Buytenhek45eb4002009-10-22 20:20:40 +02003666 memcpy(&stats[index], &txq->stats,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003667 sizeof(struct ieee80211_tx_queue_stats));
3668 }
3669 spin_unlock_bh(&priv->tx_lock);
Lennert Buytenhek954ef502009-07-17 07:26:27 +02003670
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003671 return 0;
3672}
3673
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003674static int mwl8k_get_stats(struct ieee80211_hw *hw,
3675 struct ieee80211_low_level_stats *stats)
3676{
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003677 return mwl8k_cmd_get_stat(hw, stats);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003678}
3679
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003680static int
3681mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3682 enum ieee80211_ampdu_mlme_action action,
3683 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3684{
3685 switch (action) {
3686 case IEEE80211_AMPDU_RX_START:
3687 case IEEE80211_AMPDU_RX_STOP:
3688 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3689 return -ENOTSUPP;
3690 return 0;
3691 default:
3692 return -ENOTSUPP;
3693 }
3694}
3695
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003696static const struct ieee80211_ops mwl8k_ops = {
3697 .tx = mwl8k_tx,
3698 .start = mwl8k_start,
3699 .stop = mwl8k_stop,
3700 .add_interface = mwl8k_add_interface,
3701 .remove_interface = mwl8k_remove_interface,
3702 .config = mwl8k_config,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003703 .bss_info_changed = mwl8k_bss_info_changed,
Johannes Berg3ac64be2009-08-17 16:16:53 +02003704 .prepare_multicast = mwl8k_prepare_multicast,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003705 .configure_filter = mwl8k_configure_filter,
3706 .set_rts_threshold = mwl8k_set_rts_threshold,
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003707 .sta_notify = mwl8k_sta_notify,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003708 .conf_tx = mwl8k_conf_tx,
3709 .get_tx_stats = mwl8k_get_tx_stats,
3710 .get_stats = mwl8k_get_stats,
Lennert Buytenheka2292d82010-01-04 21:58:12 +01003711 .ampdu_action = mwl8k_ampdu_action,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003712};
3713
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003714static void mwl8k_finalize_join_worker(struct work_struct *work)
3715{
3716 struct mwl8k_priv *priv =
3717 container_of(work, struct mwl8k_priv, finalize_join_worker);
3718 struct sk_buff *skb = priv->beacon_skb;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003719
Lennert Buytenhek7dc6a7a2009-11-30 18:33:09 +01003720 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len,
3721 priv->vif->bss_conf.dtim_period);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003722 dev_kfree_skb(skb);
3723
3724 priv->beacon_skb = NULL;
3725}
3726
John W. Linvillebcb628d2009-11-06 16:40:16 -05003727enum {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003728 MWL8363 = 0,
3729 MWL8687,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003730 MWL8366,
Lennert Buytenhek6f6d1e92009-10-22 20:21:48 +02003731};
3732
John W. Linvillebcb628d2009-11-06 16:40:16 -05003733static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003734 [MWL8363] = {
3735 .part_name = "88w8363",
3736 .helper_image = "mwl8k/helper_8363.fw",
3737 .fw_image = "mwl8k/fmimage_8363.fw",
3738 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003739 [MWL8687] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003740 .part_name = "88w8687",
3741 .helper_image = "mwl8k/helper_8687.fw",
3742 .fw_image = "mwl8k/fmimage_8687.fw",
John W. Linvillebcb628d2009-11-06 16:40:16 -05003743 },
Lennert Buytenhek49eb6912009-11-30 18:32:13 +01003744 [MWL8366] = {
John W. Linvillebcb628d2009-11-06 16:40:16 -05003745 .part_name = "88w8366",
3746 .helper_image = "mwl8k/helper_8366.fw",
3747 .fw_image = "mwl8k/fmimage_8366.fw",
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003748 .ap_rxd_ops = &rxd_8366_ap_ops,
John W. Linvillebcb628d2009-11-06 16:40:16 -05003749 },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003750};
3751
Lennert Buytenhekc92d4ed2010-01-12 13:47:22 +01003752MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3753MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3754MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3755MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3756MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3757MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3758
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003759static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
Lennert Buytenhek9e1b17e2010-01-04 21:56:19 +01003760 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3761 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003762 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3763 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3764 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
Lennert Buytenhekca665272010-01-12 13:47:53 +01003765 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
John W. Linvillebcb628d2009-11-06 16:40:16 -05003766 { },
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02003767};
3768MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
3769
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003770static int __devinit mwl8k_probe(struct pci_dev *pdev,
3771 const struct pci_device_id *id)
3772{
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003773 static int printed_version = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003774 struct ieee80211_hw *hw;
3775 struct mwl8k_priv *priv;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003776 int rc;
3777 int i;
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02003778
3779 if (!printed_version) {
3780 printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
3781 printed_version = 1;
3782 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003783
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003784
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003785 rc = pci_enable_device(pdev);
3786 if (rc) {
3787 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
3788 MWL8K_NAME);
3789 return rc;
3790 }
3791
3792 rc = pci_request_regions(pdev, MWL8K_NAME);
3793 if (rc) {
3794 printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
3795 MWL8K_NAME);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01003796 goto err_disable_device;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003797 }
3798
3799 pci_set_master(pdev);
3800
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003801
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003802 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3803 if (hw == NULL) {
3804 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
3805 rc = -ENOMEM;
3806 goto err_free_reg;
3807 }
3808
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003809 SET_IEEE80211_DEV(hw, &pdev->dev);
3810 pci_set_drvdata(pdev, hw);
3811
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003812 priv = hw->priv;
3813 priv->hw = hw;
3814 priv->pdev = pdev;
John W. Linvillebcb628d2009-11-06 16:40:16 -05003815 priv->device_info = &mwl8k_info_tbl[id->driver_data];
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003816
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003817
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003818 priv->sram = pci_iomap(pdev, 0, 0x10000);
3819 if (priv->sram == NULL) {
3820 printk(KERN_ERR "%s: Cannot map device SRAM\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003821 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003822 goto err_iounmap;
3823 }
3824
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02003825 /*
3826 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
3827 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
3828 */
3829 priv->regs = pci_iomap(pdev, 1, 0x10000);
3830 if (priv->regs == NULL) {
3831 priv->regs = pci_iomap(pdev, 2, 0x10000);
3832 if (priv->regs == NULL) {
3833 printk(KERN_ERR "%s: Cannot map device registers\n",
3834 wiphy_name(hw->wiphy));
3835 goto err_iounmap;
3836 }
3837 }
3838
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003839
3840 /* Reset firmware and hardware */
3841 mwl8k_hw_reset(priv);
3842
3843 /* Ask userland hotplug daemon for the device firmware */
3844 rc = mwl8k_request_firmware(priv);
3845 if (rc) {
3846 printk(KERN_ERR "%s: Firmware files not found\n",
3847 wiphy_name(hw->wiphy));
3848 goto err_stop_firmware;
3849 }
3850
3851 /* Load firmware into hardware */
3852 rc = mwl8k_load_firmware(hw);
3853 if (rc) {
3854 printk(KERN_ERR "%s: Cannot start firmware\n",
3855 wiphy_name(hw->wiphy));
3856 goto err_stop_firmware;
3857 }
3858
3859 /* Reclaim memory once firmware is successfully loaded */
3860 mwl8k_release_firmware(priv);
3861
3862
Lennert Buytenhek91942232010-01-04 21:53:54 +01003863 if (priv->ap_fw) {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003864 priv->rxd_ops = priv->device_info->ap_rxd_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003865 if (priv->rxd_ops == NULL) {
3866 printk(KERN_ERR "%s: Driver does not have AP "
3867 "firmware image support for this hardware\n",
3868 wiphy_name(hw->wiphy));
3869 goto err_stop_firmware;
3870 }
3871 } else {
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003872 priv->rxd_ops = &rxd_sta_ops;
Lennert Buytenhek91942232010-01-04 21:53:54 +01003873 }
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003874
3875 priv->sniffer_enabled = false;
3876 priv->wmm_enabled = false;
3877 priv->pending_tx_pkts = 0;
3878
3879
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003880 /*
3881 * Extra headroom is the size of the required DMA header
3882 * minus the size of the smallest 802.11 frame (CTS frame).
3883 */
3884 hw->extra_tx_headroom =
3885 sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
3886
3887 hw->channel_change_time = 10;
3888
3889 hw->queues = MWL8K_TX_QUEUES;
3890
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003891 /* Set rssi and noise values to dBm */
Lennert Buytenhekce9e2e12009-07-16 14:00:45 +02003892 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003893 hw->vif_data_size = sizeof(struct mwl8k_vif);
Lennert Buytenheka6804002010-01-04 21:55:42 +01003894 hw->sta_data_size = sizeof(struct mwl8k_sta);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003895 priv->vif = NULL;
3896
3897 /* Set default radio state and preamble */
Lennert Buytenhekc46563b2009-07-16 12:14:58 +02003898 priv->radio_on = 0;
Lennert Buytenhek68ce3882009-07-16 12:26:57 +02003899 priv->radio_short_preamble = 0;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003900
Lennert Buytenhekbbfd9122010-01-04 21:55:12 +01003901 /* Station database handling */
3902 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
3903 spin_lock_init(&priv->sta_notify_list_lock);
3904 INIT_LIST_HEAD(&priv->sta_notify_list);
3905
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003906 /* Finalize join worker */
3907 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3908
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003909 /* TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003910 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
3911 tasklet_disable(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003912 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
3913 tasklet_disable(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003914
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003915 /* Power management cookie */
3916 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3917 if (priv->cookie == NULL)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003918 goto err_stop_firmware;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003919
3920 rc = mwl8k_rxq_init(hw, 0);
3921 if (rc)
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003922 goto err_free_cookie;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003923 rxq_refill(hw, 0, INT_MAX);
3924
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003925 mutex_init(&priv->fw_mutex);
3926 priv->fw_mutex_owner = NULL;
3927 priv->fw_mutex_depth = 0;
Lennert Buytenhek618952a2009-08-18 03:18:01 +02003928 priv->hostcmd_wait = NULL;
3929
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003930 spin_lock_init(&priv->tx_lock);
3931
Lennert Buytenhek88de754a2009-10-22 20:19:37 +02003932 priv->tx_wait = NULL;
3933
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003934 for (i = 0; i < MWL8K_TX_QUEUES; i++) {
3935 rc = mwl8k_txq_init(hw, i);
3936 if (rc)
3937 goto err_free_queues;
3938 }
3939
3940 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003941 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01003942 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01003943 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003944 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3945
Joe Perchesa0607fd2009-11-18 23:29:17 -08003946 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003947 IRQF_SHARED, MWL8K_NAME, hw);
3948 if (rc) {
3949 printk(KERN_ERR "%s: failed to register IRQ handler\n",
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003950 wiphy_name(hw->wiphy));
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003951 goto err_free_queues;
3952 }
3953
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003954 /*
3955 * Temporarily enable interrupts. Initial firmware host
Lennert Buytenhekc2c2b122010-01-08 18:27:59 +01003956 * commands use interrupts and avoid polling. Disable
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003957 * interrupts when done.
3958 */
Lennert Buytenhekc23b5a62009-07-16 13:49:55 +02003959 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003960
3961 /* Get config data, mac addrs etc */
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02003962 if (priv->ap_fw) {
3963 rc = mwl8k_cmd_get_hw_spec_ap(hw);
3964 if (!rc)
3965 rc = mwl8k_cmd_set_hw_spec(hw);
Lennert Buytenhekb64fe612010-01-08 18:31:39 +01003966
3967 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_AP);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02003968 } else {
3969 rc = mwl8k_cmd_get_hw_spec_sta(hw);
Lennert Buytenhek89a91f42009-11-30 18:32:54 +01003970
3971 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
Lennert Buytenhek42fba21d2009-10-22 20:21:30 +02003972 }
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003973 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003974 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3975 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003976 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003977 }
3978
3979 /* Turn radio off */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003980 rc = mwl8k_cmd_radio_disable(hw);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003981 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02003982 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003983 goto err_free_irq;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003984 }
3985
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003986 /* Clear MAC address */
Lennert Buytenhek55489b62009-11-30 18:31:33 +01003987 rc = mwl8k_cmd_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00");
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003988 if (rc) {
3989 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3990 wiphy_name(hw->wiphy));
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01003991 goto err_free_irq;
Lennert Buytenhek32060e12009-10-22 20:20:04 +02003992 }
3993
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003994 /* Disable interrupts */
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003995 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01003996 free_irq(priv->pdev->irq, hw);
3997
3998 rc = ieee80211_register_hw(hw);
3999 if (rc) {
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004000 printk(KERN_ERR "%s: Cannot register device\n",
4001 wiphy_name(hw->wiphy));
Lennert Buytenhek153458f2010-01-04 21:54:08 +01004002 goto err_free_queues;
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004003 }
4004
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02004005 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
Lennert Buytenheka74b2952009-10-22 20:20:50 +02004006 wiphy_name(hw->wiphy), priv->device_info->part_name,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004007 priv->hw_rev, hw->wiphy->perm_addr,
Lennert Buytenhekeae74e62009-10-22 20:20:53 +02004008 priv->ap_fw ? "AP" : "STA",
Lennert Buytenhek2aa7b012009-08-24 15:48:07 +02004009 (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
4010 (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004011
4012 return 0;
4013
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004014err_free_irq:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004015 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004016 free_irq(priv->pdev->irq, hw);
4017
4018err_free_queues:
4019 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4020 mwl8k_txq_deinit(hw, i);
4021 mwl8k_rxq_deinit(hw, 0);
4022
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004023err_free_cookie:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004024 if (priv->cookie != NULL)
4025 pci_free_consistent(priv->pdev, 4,
4026 priv->cookie, priv->cookie_dma);
4027
Lennert Buytenhekbe695fc2009-11-30 18:32:46 +01004028err_stop_firmware:
4029 mwl8k_hw_reset(priv);
4030 mwl8k_release_firmware(priv);
4031
4032err_iounmap:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004033 if (priv->regs != NULL)
4034 pci_iounmap(pdev, priv->regs);
4035
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004036 if (priv->sram != NULL)
4037 pci_iounmap(pdev, priv->sram);
4038
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004039 pci_set_drvdata(pdev, NULL);
4040 ieee80211_free_hw(hw);
4041
4042err_free_reg:
4043 pci_release_regions(pdev);
Lennert Buytenhek3db95e52009-11-30 18:13:34 +01004044
4045err_disable_device:
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004046 pci_disable_device(pdev);
4047
4048 return rc;
4049}
4050
Joerg Albert230f7af2009-04-18 02:10:45 +02004051static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004052{
4053 printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
4054}
4055
Joerg Albert230f7af2009-04-18 02:10:45 +02004056static void __devexit mwl8k_remove(struct pci_dev *pdev)
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004057{
4058 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
4059 struct mwl8k_priv *priv;
4060 int i;
4061
4062 if (hw == NULL)
4063 return;
4064 priv = hw->priv;
4065
4066 ieee80211_stop_queues(hw);
4067
Lennert Buytenhek60aa5692009-08-03 21:59:09 +02004068 ieee80211_unregister_hw(hw);
4069
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004070 /* Remove TX reclaim and RX tasklets. */
Lennert Buytenhek1e9f9de32010-01-08 18:32:01 +01004071 tasklet_kill(&priv->poll_tx_task);
Lennert Buytenhek67e2eb22010-01-08 18:32:18 +01004072 tasklet_kill(&priv->poll_rx_task);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004073
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004074 /* Stop hardware */
4075 mwl8k_hw_reset(priv);
4076
4077 /* Return all skbs to mac80211 */
4078 for (i = 0; i < MWL8K_TX_QUEUES; i++)
Lennert Buytenhekefb7c492010-01-08 18:31:47 +01004079 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004080
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004081 for (i = 0; i < MWL8K_TX_QUEUES; i++)
4082 mwl8k_txq_deinit(hw, i);
4083
4084 mwl8k_rxq_deinit(hw, 0);
4085
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004086 pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004087
4088 pci_iounmap(pdev, priv->regs);
Lennert Buytenhek5b9482d2009-10-22 20:20:43 +02004089 pci_iounmap(pdev, priv->sram);
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004090 pci_set_drvdata(pdev, NULL);
4091 ieee80211_free_hw(hw);
4092 pci_release_regions(pdev);
4093 pci_disable_device(pdev);
4094}
4095
4096static struct pci_driver mwl8k_driver = {
4097 .name = MWL8K_NAME,
Lennert Buytenhek45a390d2009-10-22 20:20:47 +02004098 .id_table = mwl8k_pci_id_table,
Lennert Buytenheka66098d2009-03-10 10:13:33 +01004099 .probe = mwl8k_probe,
4100 .remove = __devexit_p(mwl8k_remove),
4101 .shutdown = __devexit_p(mwl8k_shutdown),
4102};
4103
4104static int __init mwl8k_init(void)
4105{
4106 return pci_register_driver(&mwl8k_driver);
4107}
4108
4109static void __exit mwl8k_exit(void)
4110{
4111 pci_unregister_driver(&mwl8k_driver);
4112}
4113
4114module_init(mwl8k_init);
4115module_exit(mwl8k_exit);
Lennert Buytenhekc2c357c2009-10-22 20:19:33 +02004116
4117MODULE_DESCRIPTION(MWL8K_DESC);
4118MODULE_VERSION(MWL8K_VERSION);
4119MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
4120MODULE_LICENSE("GPL");