aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/mwl8k.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/mwl8k.c')
-rw-r--r--drivers/net/wireless/mwl8k.c2111
1 files changed, 1365 insertions, 746 deletions
diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index 59f92105b0c2..68546ca0ba37 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -2,7 +2,7 @@
2 * drivers/net/wireless/mwl8k.c 2 * drivers/net/wireless/mwl8k.c
3 * Driver for Marvell TOPDOG 802.11 Wireless cards 3 * Driver for Marvell TOPDOG 802.11 Wireless cards
4 * 4 *
5 * Copyright (C) 2008-2009 Marvell Semiconductor Inc. 5 * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc.
6 * 6 *
7 * This file is licensed under the terms of the GNU General Public 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 8 * License version 2. This program is licensed "as is" without any
@@ -26,7 +26,7 @@
26 26
27#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver" 27#define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
28#define MWL8K_NAME KBUILD_MODNAME 28#define MWL8K_NAME KBUILD_MODNAME
29#define MWL8K_VERSION "0.10" 29#define MWL8K_VERSION "0.12"
30 30
31/* Register definitions */ 31/* Register definitions */
32#define MWL8K_HIU_GEN_PTR 0x00000c10 32#define MWL8K_HIU_GEN_PTR 0x00000c10
@@ -92,8 +92,7 @@ struct mwl8k_device_info {
92 char *part_name; 92 char *part_name;
93 char *helper_image; 93 char *helper_image;
94 char *fw_image; 94 char *fw_image;
95 struct rxd_ops *rxd_ops; 95 struct rxd_ops *ap_rxd_ops;
96 u16 modes;
97}; 96};
98 97
99struct mwl8k_rx_queue { 98struct mwl8k_rx_queue {
@@ -126,28 +125,30 @@ struct mwl8k_tx_queue {
126 struct sk_buff **skb; 125 struct sk_buff **skb;
127}; 126};
128 127
129/* Pointers to the firmware data and meta information about it. */ 128struct mwl8k_priv {
130struct mwl8k_firmware { 129 struct ieee80211_hw *hw;
131 /* Boot helper code */ 130 struct pci_dev *pdev;
132 struct firmware *helper;
133 131
134 /* Microcode */ 132 struct mwl8k_device_info *device_info;
135 struct firmware *ucode;
136};
137 133
138struct mwl8k_priv {
139 void __iomem *sram; 134 void __iomem *sram;
140 void __iomem *regs; 135 void __iomem *regs;
141 struct ieee80211_hw *hw;
142 136
143 struct pci_dev *pdev; 137 /* firmware */
138 struct firmware *fw_helper;
139 struct firmware *fw_ucode;
144 140
145 struct mwl8k_device_info *device_info; 141 /* hardware/firmware parameters */
146 bool ap_fw; 142 bool ap_fw;
147 struct rxd_ops *rxd_ops; 143 struct rxd_ops *rxd_ops;
148 144 struct ieee80211_supported_band band_24;
149 /* firmware files and meta data */ 145 struct ieee80211_channel channels_24[14];
150 struct mwl8k_firmware fw; 146 struct ieee80211_rate rates_24[14];
147 struct ieee80211_supported_band band_50;
148 struct ieee80211_channel channels_50[4];
149 struct ieee80211_rate rates_50[9];
150 u32 ap_macids_supported;
151 u32 sta_macids_supported;
151 152
152 /* firmware access */ 153 /* firmware access */
153 struct mutex fw_mutex; 154 struct mutex fw_mutex;
@@ -161,9 +162,9 @@ struct mwl8k_priv {
161 /* TX quiesce completion, protected by fw_mutex and tx_lock */ 162 /* TX quiesce completion, protected by fw_mutex and tx_lock */
162 struct completion *tx_wait; 163 struct completion *tx_wait;
163 164
164 struct ieee80211_vif *vif; 165 /* List of interfaces. */
165 166 u32 macids_used;
166 struct ieee80211_channel *current_channel; 167 struct list_head vif_list;
167 168
168 /* power management status cookie from firmware */ 169 /* power management status cookie from firmware */
169 u32 *cookie; 170 u32 *cookie;
@@ -182,16 +183,15 @@ struct mwl8k_priv {
182 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES]; 183 struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
183 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES]; 184 struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
184 185
185 /* PHY parameters */
186 struct ieee80211_supported_band band;
187 struct ieee80211_channel channels[14];
188 struct ieee80211_rate rates[14];
189
190 bool radio_on; 186 bool radio_on;
191 bool radio_short_preamble; 187 bool radio_short_preamble;
192 bool sniffer_enabled; 188 bool sniffer_enabled;
193 bool wmm_enabled; 189 bool wmm_enabled;
194 190
191 struct work_struct sta_notify_worker;
192 spinlock_t sta_notify_list_lock;
193 struct list_head sta_notify_list;
194
195 /* XXX need to convert this to handle multiple interfaces */ 195 /* XXX need to convert this to handle multiple interfaces */
196 bool capture_beacon; 196 bool capture_beacon;
197 u8 capture_bssid[ETH_ALEN]; 197 u8 capture_bssid[ETH_ALEN];
@@ -205,32 +205,33 @@ struct mwl8k_priv {
205 */ 205 */
206 struct work_struct finalize_join_worker; 206 struct work_struct finalize_join_worker;
207 207
208 /* Tasklet to reclaim TX descriptors and buffers after tx */ 208 /* Tasklet to perform TX reclaim. */
209 struct tasklet_struct tx_reclaim_task; 209 struct tasklet_struct poll_tx_task;
210
211 /* Tasklet to perform RX. */
212 struct tasklet_struct poll_rx_task;
210}; 213};
211 214
212/* Per interface specific private data */ 215/* Per interface specific private data */
213struct mwl8k_vif { 216struct mwl8k_vif {
214 /* backpointer to parent config block */ 217 struct list_head list;
215 struct mwl8k_priv *priv; 218 struct ieee80211_vif *vif;
216
217 /* BSS config of AP or IBSS from mac80211*/
218 struct ieee80211_bss_conf bss_info;
219
220 /* BSSID of AP or IBSS */
221 u8 bssid[ETH_ALEN];
222 u8 mac_addr[ETH_ALEN];
223 219
224 /* Index into station database.Returned by update_sta_db call */ 220 /* Firmware macid for this vif. */
225 u8 peer_id; 221 int macid;
226 222
227 /* Non AMPDU sequence number assigned by driver */ 223 /* Non AMPDU sequence number assigned by driver. */
228 u16 seqno; 224 u16 seqno;
229}; 225};
230
231#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv)) 226#define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
232 227
233static const struct ieee80211_channel mwl8k_channels[] = { 228struct mwl8k_sta {
229 /* Index into station database. Returned by UPDATE_STADB. */
230 u8 peer_id;
231};
232#define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
233
234static const struct ieee80211_channel mwl8k_channels_24[] = {
234 { .center_freq = 2412, .hw_value = 1, }, 235 { .center_freq = 2412, .hw_value = 1, },
235 { .center_freq = 2417, .hw_value = 2, }, 236 { .center_freq = 2417, .hw_value = 2, },
236 { .center_freq = 2422, .hw_value = 3, }, 237 { .center_freq = 2422, .hw_value = 3, },
@@ -242,9 +243,12 @@ static const struct ieee80211_channel mwl8k_channels[] = {
242 { .center_freq = 2452, .hw_value = 9, }, 243 { .center_freq = 2452, .hw_value = 9, },
243 { .center_freq = 2457, .hw_value = 10, }, 244 { .center_freq = 2457, .hw_value = 10, },
244 { .center_freq = 2462, .hw_value = 11, }, 245 { .center_freq = 2462, .hw_value = 11, },
246 { .center_freq = 2467, .hw_value = 12, },
247 { .center_freq = 2472, .hw_value = 13, },
248 { .center_freq = 2484, .hw_value = 14, },
245}; 249};
246 250
247static const struct ieee80211_rate mwl8k_rates[] = { 251static const struct ieee80211_rate mwl8k_rates_24[] = {
248 { .bitrate = 10, .hw_value = 2, }, 252 { .bitrate = 10, .hw_value = 2, },
249 { .bitrate = 20, .hw_value = 4, }, 253 { .bitrate = 20, .hw_value = 4, },
250 { .bitrate = 55, .hw_value = 11, }, 254 { .bitrate = 55, .hw_value = 11, },
@@ -261,8 +265,23 @@ static const struct ieee80211_rate mwl8k_rates[] = {
261 { .bitrate = 720, .hw_value = 144, }, 265 { .bitrate = 720, .hw_value = 144, },
262}; 266};
263 267
264static const u8 mwl8k_rateids[12] = { 268static const struct ieee80211_channel mwl8k_channels_50[] = {
265 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 269 { .center_freq = 5180, .hw_value = 36, },
270 { .center_freq = 5200, .hw_value = 40, },
271 { .center_freq = 5220, .hw_value = 44, },
272 { .center_freq = 5240, .hw_value = 48, },
273};
274
275static const struct ieee80211_rate mwl8k_rates_50[] = {
276 { .bitrate = 60, .hw_value = 12, },
277 { .bitrate = 90, .hw_value = 18, },
278 { .bitrate = 120, .hw_value = 24, },
279 { .bitrate = 180, .hw_value = 36, },
280 { .bitrate = 240, .hw_value = 48, },
281 { .bitrate = 360, .hw_value = 72, },
282 { .bitrate = 480, .hw_value = 96, },
283 { .bitrate = 540, .hw_value = 108, },
284 { .bitrate = 720, .hw_value = 144, },
266}; 285};
267 286
268/* Set or get info from Firmware */ 287/* Set or get info from Firmware */
@@ -278,6 +297,7 @@ static const u8 mwl8k_rateids[12] = {
278#define MWL8K_CMD_RADIO_CONTROL 0x001c 297#define MWL8K_CMD_RADIO_CONTROL 0x001c
279#define MWL8K_CMD_RF_TX_POWER 0x001e 298#define MWL8K_CMD_RF_TX_POWER 0x001e
280#define MWL8K_CMD_RF_ANTENNA 0x0020 299#define MWL8K_CMD_RF_ANTENNA 0x0020
300#define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
281#define MWL8K_CMD_SET_PRE_SCAN 0x0107 301#define MWL8K_CMD_SET_PRE_SCAN 0x0107
282#define MWL8K_CMD_SET_POST_SCAN 0x0108 302#define MWL8K_CMD_SET_POST_SCAN 0x0108
283#define MWL8K_CMD_SET_RF_CHANNEL 0x010a 303#define MWL8K_CMD_SET_RF_CHANNEL 0x010a
@@ -291,8 +311,10 @@ static const u8 mwl8k_rateids[12] = {
291#define MWL8K_CMD_MIMO_CONFIG 0x0125 311#define MWL8K_CMD_MIMO_CONFIG 0x0125
292#define MWL8K_CMD_USE_FIXED_RATE 0x0126 312#define MWL8K_CMD_USE_FIXED_RATE 0x0126
293#define MWL8K_CMD_ENABLE_SNIFFER 0x0150 313#define MWL8K_CMD_ENABLE_SNIFFER 0x0150
294#define MWL8K_CMD_SET_MAC_ADDR 0x0202 314#define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
295#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203 315#define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
316#define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
317#define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
296#define MWL8K_CMD_UPDATE_STADB 0x1123 318#define MWL8K_CMD_UPDATE_STADB 0x1123
297 319
298static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize) 320static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
@@ -310,6 +332,7 @@ static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
310 MWL8K_CMDNAME(RADIO_CONTROL); 332 MWL8K_CMDNAME(RADIO_CONTROL);
311 MWL8K_CMDNAME(RF_TX_POWER); 333 MWL8K_CMDNAME(RF_TX_POWER);
312 MWL8K_CMDNAME(RF_ANTENNA); 334 MWL8K_CMDNAME(RF_ANTENNA);
335 MWL8K_CMDNAME(SET_BEACON);
313 MWL8K_CMDNAME(SET_PRE_SCAN); 336 MWL8K_CMDNAME(SET_PRE_SCAN);
314 MWL8K_CMDNAME(SET_POST_SCAN); 337 MWL8K_CMDNAME(SET_POST_SCAN);
315 MWL8K_CMDNAME(SET_RF_CHANNEL); 338 MWL8K_CMDNAME(SET_RF_CHANNEL);
@@ -325,6 +348,8 @@ static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
325 MWL8K_CMDNAME(ENABLE_SNIFFER); 348 MWL8K_CMDNAME(ENABLE_SNIFFER);
326 MWL8K_CMDNAME(SET_MAC_ADDR); 349 MWL8K_CMDNAME(SET_MAC_ADDR);
327 MWL8K_CMDNAME(SET_RATEADAPT_MODE); 350 MWL8K_CMDNAME(SET_RATEADAPT_MODE);
351 MWL8K_CMDNAME(BSS_START);
352 MWL8K_CMDNAME(SET_NEW_STN);
328 MWL8K_CMDNAME(UPDATE_STADB); 353 MWL8K_CMDNAME(UPDATE_STADB);
329 default: 354 default:
330 snprintf(buf, bufsize, "0x%x", cmd); 355 snprintf(buf, bufsize, "0x%x", cmd);
@@ -355,8 +380,8 @@ static void mwl8k_release_fw(struct firmware **fw)
355 380
356static void mwl8k_release_firmware(struct mwl8k_priv *priv) 381static void mwl8k_release_firmware(struct mwl8k_priv *priv)
357{ 382{
358 mwl8k_release_fw(&priv->fw.ucode); 383 mwl8k_release_fw(&priv->fw_ucode);
359 mwl8k_release_fw(&priv->fw.helper); 384 mwl8k_release_fw(&priv->fw_helper);
360} 385}
361 386
362/* Request fw image */ 387/* Request fw image */
@@ -377,7 +402,7 @@ static int mwl8k_request_firmware(struct mwl8k_priv *priv)
377 int rc; 402 int rc;
378 403
379 if (di->helper_image != NULL) { 404 if (di->helper_image != NULL) {
380 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw.helper); 405 rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
381 if (rc) { 406 if (rc) {
382 printk(KERN_ERR "%s: Error requesting helper " 407 printk(KERN_ERR "%s: Error requesting helper "
383 "firmware file %s\n", pci_name(priv->pdev), 408 "firmware file %s\n", pci_name(priv->pdev),
@@ -386,24 +411,22 @@ static int mwl8k_request_firmware(struct mwl8k_priv *priv)
386 } 411 }
387 } 412 }
388 413
389 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw.ucode); 414 rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
390 if (rc) { 415 if (rc) {
391 printk(KERN_ERR "%s: Error requesting firmware file %s\n", 416 printk(KERN_ERR "%s: Error requesting firmware file %s\n",
392 pci_name(priv->pdev), di->fw_image); 417 pci_name(priv->pdev), di->fw_image);
393 mwl8k_release_fw(&priv->fw.helper); 418 mwl8k_release_fw(&priv->fw_helper);
394 return rc; 419 return rc;
395 } 420 }
396 421
397 return 0; 422 return 0;
398} 423}
399 424
400MODULE_FIRMWARE("mwl8k/helper_8687.fw");
401MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
402
403struct mwl8k_cmd_pkt { 425struct mwl8k_cmd_pkt {
404 __le16 code; 426 __le16 code;
405 __le16 length; 427 __le16 length;
406 __le16 seq_num; 428 __u8 seq_num;
429 __u8 macid;
407 __le16 result; 430 __le16 result;
408 char payload[0]; 431 char payload[0];
409} __attribute__((packed)); 432} __attribute__((packed));
@@ -461,6 +484,7 @@ static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
461 484
462 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD); 485 cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
463 cmd->seq_num = 0; 486 cmd->seq_num = 0;
487 cmd->macid = 0;
464 cmd->result = 0; 488 cmd->result = 0;
465 489
466 done = 0; 490 done = 0;
@@ -551,13 +575,12 @@ static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
551static int mwl8k_load_firmware(struct ieee80211_hw *hw) 575static int mwl8k_load_firmware(struct ieee80211_hw *hw)
552{ 576{
553 struct mwl8k_priv *priv = hw->priv; 577 struct mwl8k_priv *priv = hw->priv;
554 struct firmware *fw = priv->fw.ucode; 578 struct firmware *fw = priv->fw_ucode;
555 struct mwl8k_device_info *di = priv->device_info;
556 int rc; 579 int rc;
557 int loops; 580 int loops;
558 581
559 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) { 582 if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
560 struct firmware *helper = priv->fw.helper; 583 struct firmware *helper = priv->fw_helper;
561 584
562 if (helper == NULL) { 585 if (helper == NULL) {
563 printk(KERN_ERR "%s: helper image needed but none " 586 printk(KERN_ERR "%s: helper image needed but none "
@@ -584,10 +607,7 @@ static int mwl8k_load_firmware(struct ieee80211_hw *hw)
584 return rc; 607 return rc;
585 } 608 }
586 609
587 if (di->modes & BIT(NL80211_IFTYPE_AP)) 610 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
588 iowrite32(MWL8K_MODE_AP, priv->regs + MWL8K_HIU_GEN_PTR);
589 else
590 iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
591 611
592 loops = 500000; 612 loops = 500000;
593 do { 613 do {
@@ -610,91 +630,6 @@ static int mwl8k_load_firmware(struct ieee80211_hw *hw)
610} 630}
611 631
612 632
613/*
614 * Defines shared between transmission and reception.
615 */
616/* HT control fields for firmware */
617struct ewc_ht_info {
618 __le16 control1;
619 __le16 control2;
620 __le16 control3;
621} __attribute__((packed));
622
623/* Firmware Station database operations */
624#define MWL8K_STA_DB_ADD_ENTRY 0
625#define MWL8K_STA_DB_MODIFY_ENTRY 1
626#define MWL8K_STA_DB_DEL_ENTRY 2
627#define MWL8K_STA_DB_FLUSH 3
628
629/* Peer Entry flags - used to define the type of the peer node */
630#define MWL8K_PEER_TYPE_ACCESSPOINT 2
631
632struct peer_capability_info {
633 /* Peer type - AP vs. STA. */
634 __u8 peer_type;
635
636 /* Basic 802.11 capabilities from assoc resp. */
637 __le16 basic_caps;
638
639 /* Set if peer supports 802.11n high throughput (HT). */
640 __u8 ht_support;
641
642 /* Valid if HT is supported. */
643 __le16 ht_caps;
644 __u8 extended_ht_caps;
645 struct ewc_ht_info ewc_info;
646
647 /* Legacy rate table. Intersection of our rates and peer rates. */
648 __u8 legacy_rates[12];
649
650 /* HT rate table. Intersection of our rates and peer rates. */
651 __u8 ht_rates[16];
652 __u8 pad[16];
653
654 /* If set, interoperability mode, no proprietary extensions. */
655 __u8 interop;
656 __u8 pad2;
657 __u8 station_id;
658 __le16 amsdu_enabled;
659} __attribute__((packed));
660
661/* Inline functions to manipulate QoS field in data descriptor. */
662static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
663{
664 u16 val_mask = 1 << 4;
665
666 /* End of Service Period Bit 4 */
667 return qos | val_mask;
668}
669
670static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
671{
672 u16 val_mask = 0x3;
673 u8 shift = 5;
674 u16 qos_mask = ~(val_mask << shift);
675
676 /* Ack Policy Bit 5-6 */
677 return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
678}
679
680static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
681{
682 u16 val_mask = 1 << 7;
683
684 /* AMSDU present Bit 7 */
685 return qos | val_mask;
686}
687
688static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
689{
690 u16 val_mask = 0xff;
691 u8 shift = 8;
692 u16 qos_mask = ~(val_mask << shift);
693
694 /* Queue Length Bits 8-15 */
695 return (qos & qos_mask) | ((len & val_mask) << shift);
696}
697
698/* DMA header used by firmware and hardware. */ 633/* DMA header used by firmware and hardware. */
699struct mwl8k_dma_data { 634struct mwl8k_dma_data {
700 __le16 fwlen; 635 __le16 fwlen;
@@ -761,9 +696,9 @@ static inline void mwl8k_add_dma_header(struct sk_buff *skb)
761 696
762 697
763/* 698/*
764 * Packet reception for 88w8366. 699 * Packet reception for 88w8366 AP firmware.
765 */ 700 */
766struct mwl8k_rxd_8366 { 701struct mwl8k_rxd_8366_ap {
767 __le16 pkt_len; 702 __le16 pkt_len;
768 __u8 sq2; 703 __u8 sq2;
769 __u8 rate; 704 __u8 rate;
@@ -781,23 +716,23 @@ struct mwl8k_rxd_8366 {
781 __u8 rx_ctrl; 716 __u8 rx_ctrl;
782} __attribute__((packed)); 717} __attribute__((packed));
783 718
784#define MWL8K_8366_RATE_INFO_MCS_FORMAT 0x80 719#define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
785#define MWL8K_8366_RATE_INFO_40MHZ 0x40 720#define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
786#define MWL8K_8366_RATE_INFO_RATEID(x) ((x) & 0x3f) 721#define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
787 722
788#define MWL8K_8366_RX_CTRL_OWNED_BY_HOST 0x80 723#define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
789 724
790static void mwl8k_rxd_8366_init(void *_rxd, dma_addr_t next_dma_addr) 725static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
791{ 726{
792 struct mwl8k_rxd_8366 *rxd = _rxd; 727 struct mwl8k_rxd_8366_ap *rxd = _rxd;
793 728
794 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr); 729 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
795 rxd->rx_ctrl = MWL8K_8366_RX_CTRL_OWNED_BY_HOST; 730 rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
796} 731}
797 732
798static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len) 733static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
799{ 734{
800 struct mwl8k_rxd_8366 *rxd = _rxd; 735 struct mwl8k_rxd_8366_ap *rxd = _rxd;
801 736
802 rxd->pkt_len = cpu_to_le16(len); 737 rxd->pkt_len = cpu_to_le16(len);
803 rxd->pkt_phys_addr = cpu_to_le32(addr); 738 rxd->pkt_phys_addr = cpu_to_le32(addr);
@@ -806,12 +741,12 @@ static void mwl8k_rxd_8366_refill(void *_rxd, dma_addr_t addr, int len)
806} 741}
807 742
808static int 743static int
809mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status, 744mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
810 __le16 *qos) 745 __le16 *qos)
811{ 746{
812 struct mwl8k_rxd_8366 *rxd = _rxd; 747 struct mwl8k_rxd_8366_ap *rxd = _rxd;
813 748
814 if (!(rxd->rx_ctrl & MWL8K_8366_RX_CTRL_OWNED_BY_HOST)) 749 if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
815 return -1; 750 return -1;
816 rmb(); 751 rmb();
817 752
@@ -820,23 +755,29 @@ mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status,
820 status->signal = -rxd->rssi; 755 status->signal = -rxd->rssi;
821 status->noise = -rxd->noise_floor; 756 status->noise = -rxd->noise_floor;
822 757
823 if (rxd->rate & MWL8K_8366_RATE_INFO_MCS_FORMAT) { 758 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
824 status->flag |= RX_FLAG_HT; 759 status->flag |= RX_FLAG_HT;
825 if (rxd->rate & MWL8K_8366_RATE_INFO_40MHZ) 760 if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
826 status->flag |= RX_FLAG_40MHZ; 761 status->flag |= RX_FLAG_40MHZ;
827 status->rate_idx = MWL8K_8366_RATE_INFO_RATEID(rxd->rate); 762 status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
828 } else { 763 } else {
829 int i; 764 int i;
830 765
831 for (i = 0; i < ARRAY_SIZE(mwl8k_rates); i++) { 766 for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
832 if (mwl8k_rates[i].hw_value == rxd->rate) { 767 if (mwl8k_rates_24[i].hw_value == rxd->rate) {
833 status->rate_idx = i; 768 status->rate_idx = i;
834 break; 769 break;
835 } 770 }
836 } 771 }
837 } 772 }
838 773
839 status->band = IEEE80211_BAND_2GHZ; 774 if (rxd->channel > 14) {
775 status->band = IEEE80211_BAND_5GHZ;
776 if (!(status->flag & RX_FLAG_HT))
777 status->rate_idx -= 5;
778 } else {
779 status->band = IEEE80211_BAND_2GHZ;
780 }
840 status->freq = ieee80211_channel_to_frequency(rxd->channel); 781 status->freq = ieee80211_channel_to_frequency(rxd->channel);
841 782
842 *qos = rxd->qos_control; 783 *qos = rxd->qos_control;
@@ -844,17 +785,17 @@ mwl8k_rxd_8366_process(void *_rxd, struct ieee80211_rx_status *status,
844 return le16_to_cpu(rxd->pkt_len); 785 return le16_to_cpu(rxd->pkt_len);
845} 786}
846 787
847static struct rxd_ops rxd_8366_ops = { 788static struct rxd_ops rxd_8366_ap_ops = {
848 .rxd_size = sizeof(struct mwl8k_rxd_8366), 789 .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
849 .rxd_init = mwl8k_rxd_8366_init, 790 .rxd_init = mwl8k_rxd_8366_ap_init,
850 .rxd_refill = mwl8k_rxd_8366_refill, 791 .rxd_refill = mwl8k_rxd_8366_ap_refill,
851 .rxd_process = mwl8k_rxd_8366_process, 792 .rxd_process = mwl8k_rxd_8366_ap_process,
852}; 793};
853 794
854/* 795/*
855 * Packet reception for 88w8687. 796 * Packet reception for STA firmware.
856 */ 797 */
857struct mwl8k_rxd_8687 { 798struct mwl8k_rxd_sta {
858 __le16 pkt_len; 799 __le16 pkt_len;
859 __u8 link_quality; 800 __u8 link_quality;
860 __u8 noise_level; 801 __u8 noise_level;
@@ -871,26 +812,26 @@ struct mwl8k_rxd_8687 {
871 __u8 pad2[2]; 812 __u8 pad2[2];
872} __attribute__((packed)); 813} __attribute__((packed));
873 814
874#define MWL8K_8687_RATE_INFO_SHORTPRE 0x8000 815#define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
875#define MWL8K_8687_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3) 816#define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
876#define MWL8K_8687_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f) 817#define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
877#define MWL8K_8687_RATE_INFO_40MHZ 0x0004 818#define MWL8K_STA_RATE_INFO_40MHZ 0x0004
878#define MWL8K_8687_RATE_INFO_SHORTGI 0x0002 819#define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
879#define MWL8K_8687_RATE_INFO_MCS_FORMAT 0x0001 820#define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
880 821
881#define MWL8K_8687_RX_CTRL_OWNED_BY_HOST 0x02 822#define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
882 823
883static void mwl8k_rxd_8687_init(void *_rxd, dma_addr_t next_dma_addr) 824static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
884{ 825{
885 struct mwl8k_rxd_8687 *rxd = _rxd; 826 struct mwl8k_rxd_sta *rxd = _rxd;
886 827
887 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr); 828 rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
888 rxd->rx_ctrl = MWL8K_8687_RX_CTRL_OWNED_BY_HOST; 829 rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
889} 830}
890 831
891static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len) 832static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
892{ 833{
893 struct mwl8k_rxd_8687 *rxd = _rxd; 834 struct mwl8k_rxd_sta *rxd = _rxd;
894 835
895 rxd->pkt_len = cpu_to_le16(len); 836 rxd->pkt_len = cpu_to_le16(len);
896 rxd->pkt_phys_addr = cpu_to_le32(addr); 837 rxd->pkt_phys_addr = cpu_to_le32(addr);
@@ -899,13 +840,13 @@ static void mwl8k_rxd_8687_refill(void *_rxd, dma_addr_t addr, int len)
899} 840}
900 841
901static int 842static int
902mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status, 843mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
903 __le16 *qos) 844 __le16 *qos)
904{ 845{
905 struct mwl8k_rxd_8687 *rxd = _rxd; 846 struct mwl8k_rxd_sta *rxd = _rxd;
906 u16 rate_info; 847 u16 rate_info;
907 848
908 if (!(rxd->rx_ctrl & MWL8K_8687_RX_CTRL_OWNED_BY_HOST)) 849 if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
909 return -1; 850 return -1;
910 rmb(); 851 rmb();
911 852
@@ -915,19 +856,25 @@ mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status,
915 856
916 status->signal = -rxd->rssi; 857 status->signal = -rxd->rssi;
917 status->noise = -rxd->noise_level; 858 status->noise = -rxd->noise_level;
918 status->antenna = MWL8K_8687_RATE_INFO_ANTSELECT(rate_info); 859 status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
919 status->rate_idx = MWL8K_8687_RATE_INFO_RATEID(rate_info); 860 status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
920 861
921 if (rate_info & MWL8K_8687_RATE_INFO_SHORTPRE) 862 if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
922 status->flag |= RX_FLAG_SHORTPRE; 863 status->flag |= RX_FLAG_SHORTPRE;
923 if (rate_info & MWL8K_8687_RATE_INFO_40MHZ) 864 if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
924 status->flag |= RX_FLAG_40MHZ; 865 status->flag |= RX_FLAG_40MHZ;
925 if (rate_info & MWL8K_8687_RATE_INFO_SHORTGI) 866 if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
926 status->flag |= RX_FLAG_SHORT_GI; 867 status->flag |= RX_FLAG_SHORT_GI;
927 if (rate_info & MWL8K_8687_RATE_INFO_MCS_FORMAT) 868 if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
928 status->flag |= RX_FLAG_HT; 869 status->flag |= RX_FLAG_HT;
929 870
930 status->band = IEEE80211_BAND_2GHZ; 871 if (rxd->channel > 14) {
872 status->band = IEEE80211_BAND_5GHZ;
873 if (!(status->flag & RX_FLAG_HT))
874 status->rate_idx -= 5;
875 } else {
876 status->band = IEEE80211_BAND_2GHZ;
877 }
931 status->freq = ieee80211_channel_to_frequency(rxd->channel); 878 status->freq = ieee80211_channel_to_frequency(rxd->channel);
932 879
933 *qos = rxd->qos_control; 880 *qos = rxd->qos_control;
@@ -935,11 +882,11 @@ mwl8k_rxd_8687_process(void *_rxd, struct ieee80211_rx_status *status,
935 return le16_to_cpu(rxd->pkt_len); 882 return le16_to_cpu(rxd->pkt_len);
936} 883}
937 884
938static struct rxd_ops rxd_8687_ops = { 885static struct rxd_ops rxd_sta_ops = {
939 .rxd_size = sizeof(struct mwl8k_rxd_8687), 886 .rxd_size = sizeof(struct mwl8k_rxd_sta),
940 .rxd_init = mwl8k_rxd_8687_init, 887 .rxd_init = mwl8k_rxd_sta_init,
941 .rxd_refill = mwl8k_rxd_8687_refill, 888 .rxd_refill = mwl8k_rxd_sta_refill,
942 .rxd_process = mwl8k_rxd_8687_process, 889 .rxd_process = mwl8k_rxd_sta_process,
943}; 890};
944 891
945 892
@@ -1153,16 +1100,18 @@ static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1153 * Packet transmission. 1100 * Packet transmission.
1154 */ 1101 */
1155 1102
1156/* Transmit packet ACK policy */
1157#define MWL8K_TXD_ACK_POLICY_NORMAL 0
1158#define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
1159
1160#define MWL8K_TXD_STATUS_OK 0x00000001 1103#define MWL8K_TXD_STATUS_OK 0x00000001
1161#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002 1104#define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
1162#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004 1105#define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
1163#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008 1106#define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
1164#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000 1107#define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
1165 1108
1109#define MWL8K_QOS_QLEN_UNSPEC 0xff00
1110#define MWL8K_QOS_ACK_POLICY_MASK 0x0060
1111#define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
1112#define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
1113#define MWL8K_QOS_EOSP 0x0010
1114
1166struct mwl8k_tx_desc { 1115struct mwl8k_tx_desc {
1167 __le32 status; 1116 __le32 status;
1168 __u8 data_rate; 1117 __u8 data_rate;
@@ -1272,7 +1221,7 @@ static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
1272/* 1221/*
1273 * Must be called with priv->fw_mutex held and tx queues stopped. 1222 * Must be called with priv->fw_mutex held and tx queues stopped.
1274 */ 1223 */
1275#define MWL8K_TX_WAIT_TIMEOUT_MS 1000 1224#define MWL8K_TX_WAIT_TIMEOUT_MS 5000
1276 1225
1277static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw) 1226static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1278{ 1227{
@@ -1316,8 +1265,8 @@ static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1316 } 1265 }
1317 1266
1318 if (priv->pending_tx_pkts < oldcount) { 1267 if (priv->pending_tx_pkts < oldcount) {
1319 printk(KERN_NOTICE "%s: timeout waiting for tx " 1268 printk(KERN_NOTICE "%s: waiting for tx rings "
1320 "rings to drain (%d -> %d pkts), retrying\n", 1269 "to drain (%d -> %d pkts)\n",
1321 wiphy_name(hw->wiphy), oldcount, 1270 wiphy_name(hw->wiphy), oldcount,
1322 priv->pending_tx_pkts); 1271 priv->pending_tx_pkts);
1323 retry = 1; 1272 retry = 1;
@@ -1342,13 +1291,15 @@ static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
1342 MWL8K_TXD_STATUS_OK_RETRY | \ 1291 MWL8K_TXD_STATUS_OK_RETRY | \
1343 MWL8K_TXD_STATUS_OK_MORE_RETRY)) 1292 MWL8K_TXD_STATUS_OK_MORE_RETRY))
1344 1293
1345static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force) 1294static int
1295mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
1346{ 1296{
1347 struct mwl8k_priv *priv = hw->priv; 1297 struct mwl8k_priv *priv = hw->priv;
1348 struct mwl8k_tx_queue *txq = priv->txq + index; 1298 struct mwl8k_tx_queue *txq = priv->txq + index;
1349 int wake = 0; 1299 int processed;
1350 1300
1351 while (txq->stats.len > 0) { 1301 processed = 0;
1302 while (txq->stats.len > 0 && limit--) {
1352 int tx; 1303 int tx;
1353 struct mwl8k_tx_desc *tx_desc; 1304 struct mwl8k_tx_desc *tx_desc;
1354 unsigned long addr; 1305 unsigned long addr;
@@ -1395,11 +1346,13 @@ static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
1395 1346
1396 ieee80211_tx_status_irqsafe(hw, skb); 1347 ieee80211_tx_status_irqsafe(hw, skb);
1397 1348
1398 wake = 1; 1349 processed++;
1399 } 1350 }
1400 1351
1401 if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex)) 1352 if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
1402 ieee80211_wake_queue(hw, index); 1353 ieee80211_wake_queue(hw, index);
1354
1355 return processed;
1403} 1356}
1404 1357
1405/* must be called only when the card's transmit is completely halted */ 1358/* must be called only when the card's transmit is completely halted */
@@ -1408,7 +1361,7 @@ static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
1408 struct mwl8k_priv *priv = hw->priv; 1361 struct mwl8k_priv *priv = hw->priv;
1409 struct mwl8k_tx_queue *txq = priv->txq + index; 1362 struct mwl8k_tx_queue *txq = priv->txq + index;
1410 1363
1411 mwl8k_txq_reclaim(hw, index, 1); 1364 mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
1412 1365
1413 kfree(txq->skb); 1366 kfree(txq->skb);
1414 txq->skb = NULL; 1367 txq->skb = NULL;
@@ -1446,11 +1399,9 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1446 mwl8k_vif = MWL8K_VIF(tx_info->control.vif); 1399 mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
1447 1400
1448 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { 1401 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1449 u16 seqno = mwl8k_vif->seqno;
1450
1451 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); 1402 wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1452 wh->seq_ctrl |= cpu_to_le16(seqno << 4); 1403 wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
1453 mwl8k_vif->seqno = seqno++ % 4096; 1404 mwl8k_vif->seqno += 0x10;
1454 } 1405 }
1455 1406
1456 /* Setup firmware control bit fields for each frame type. */ 1407 /* Setup firmware control bit fields for each frame type. */
@@ -1459,24 +1410,17 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1459 if (ieee80211_is_mgmt(wh->frame_control) || 1410 if (ieee80211_is_mgmt(wh->frame_control) ||
1460 ieee80211_is_ctl(wh->frame_control)) { 1411 ieee80211_is_ctl(wh->frame_control)) {
1461 txdatarate = 0; 1412 txdatarate = 0;
1462 qos = mwl8k_qos_setbit_eosp(qos); 1413 qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
1463 /* Set Queue size to unspecified */
1464 qos = mwl8k_qos_setbit_qlen(qos, 0xff);
1465 } else if (ieee80211_is_data(wh->frame_control)) { 1414 } else if (ieee80211_is_data(wh->frame_control)) {
1466 txdatarate = 1; 1415 txdatarate = 1;
1467 if (is_multicast_ether_addr(wh->addr1)) 1416 if (is_multicast_ether_addr(wh->addr1))
1468 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX; 1417 txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
1469 1418
1470 /* Send pkt in an aggregate if AMPDU frame. */ 1419 qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
1471 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) 1420 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1472 qos = mwl8k_qos_setbit_ack(qos, 1421 qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
1473 MWL8K_TXD_ACK_POLICY_BLOCKACK);
1474 else 1422 else
1475 qos = mwl8k_qos_setbit_ack(qos, 1423 qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
1476 MWL8K_TXD_ACK_POLICY_NORMAL);
1477
1478 if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
1479 qos = mwl8k_qos_setbit_amsdu(qos);
1480 } 1424 }
1481 1425
1482 dma = pci_map_single(priv->pdev, skb->data, 1426 dma = pci_map_single(priv->pdev, skb->data,
@@ -1503,7 +1447,10 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
1503 tx->pkt_phys_addr = cpu_to_le32(dma); 1447 tx->pkt_phys_addr = cpu_to_le32(dma);
1504 tx->pkt_len = cpu_to_le16(skb->len); 1448 tx->pkt_len = cpu_to_le16(skb->len);
1505 tx->rate_info = 0; 1449 tx->rate_info = 0;
1506 tx->peer_id = mwl8k_vif->peer_id; 1450 if (!priv->ap_fw && tx_info->control.sta != NULL)
1451 tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
1452 else
1453 tx->peer_id = 0;
1507 wmb(); 1454 wmb();
1508 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus); 1455 tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
1509 1456
@@ -1656,6 +1603,56 @@ static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
1656 return rc; 1603 return rc;
1657} 1604}
1658 1605
1606static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
1607 struct ieee80211_vif *vif,
1608 struct mwl8k_cmd_pkt *cmd)
1609{
1610 if (vif != NULL)
1611 cmd->macid = MWL8K_VIF(vif)->macid;
1612 return mwl8k_post_cmd(hw, cmd);
1613}
1614
1615/*
1616 * Setup code shared between STA and AP firmware images.
1617 */
1618static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
1619{
1620 struct mwl8k_priv *priv = hw->priv;
1621
1622 BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
1623 memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
1624
1625 BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
1626 memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
1627
1628 priv->band_24.band = IEEE80211_BAND_2GHZ;
1629 priv->band_24.channels = priv->channels_24;
1630 priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
1631 priv->band_24.bitrates = priv->rates_24;
1632 priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
1633
1634 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
1635}
1636
1637static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
1638{
1639 struct mwl8k_priv *priv = hw->priv;
1640
1641 BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
1642 memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
1643
1644 BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
1645 memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
1646
1647 priv->band_50.band = IEEE80211_BAND_5GHZ;
1648 priv->band_50.channels = priv->channels_50;
1649 priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
1650 priv->band_50.bitrates = priv->rates_50;
1651 priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
1652
1653 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
1654}
1655
1659/* 1656/*
1660 * CMD_GET_HW_SPEC (STA version). 1657 * CMD_GET_HW_SPEC (STA version).
1661 */ 1658 */
@@ -1678,6 +1675,89 @@ struct mwl8k_cmd_get_hw_spec_sta {
1678 __le32 total_rxd; 1675 __le32 total_rxd;
1679} __attribute__((packed)); 1676} __attribute__((packed));
1680 1677
1678#define MWL8K_CAP_MAX_AMSDU 0x20000000
1679#define MWL8K_CAP_GREENFIELD 0x08000000
1680#define MWL8K_CAP_AMPDU 0x04000000
1681#define MWL8K_CAP_RX_STBC 0x01000000
1682#define MWL8K_CAP_TX_STBC 0x00800000
1683#define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
1684#define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
1685#define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
1686#define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
1687#define MWL8K_CAP_DELAY_BA 0x00003000
1688#define MWL8K_CAP_MIMO 0x00000200
1689#define MWL8K_CAP_40MHZ 0x00000100
1690#define MWL8K_CAP_BAND_MASK 0x00000007
1691#define MWL8K_CAP_5GHZ 0x00000004
1692#define MWL8K_CAP_2GHZ4 0x00000001
1693
1694static void
1695mwl8k_set_ht_caps(struct ieee80211_hw *hw,
1696 struct ieee80211_supported_band *band, u32 cap)
1697{
1698 int rx_streams;
1699 int tx_streams;
1700
1701 band->ht_cap.ht_supported = 1;
1702
1703 if (cap & MWL8K_CAP_MAX_AMSDU)
1704 band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
1705 if (cap & MWL8K_CAP_GREENFIELD)
1706 band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
1707 if (cap & MWL8K_CAP_AMPDU) {
1708 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
1709 band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
1710 band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
1711 }
1712 if (cap & MWL8K_CAP_RX_STBC)
1713 band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
1714 if (cap & MWL8K_CAP_TX_STBC)
1715 band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
1716 if (cap & MWL8K_CAP_SHORTGI_40MHZ)
1717 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
1718 if (cap & MWL8K_CAP_SHORTGI_20MHZ)
1719 band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
1720 if (cap & MWL8K_CAP_DELAY_BA)
1721 band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
1722 if (cap & MWL8K_CAP_40MHZ)
1723 band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1724
1725 rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
1726 tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
1727
1728 band->ht_cap.mcs.rx_mask[0] = 0xff;
1729 if (rx_streams >= 2)
1730 band->ht_cap.mcs.rx_mask[1] = 0xff;
1731 if (rx_streams >= 3)
1732 band->ht_cap.mcs.rx_mask[2] = 0xff;
1733 band->ht_cap.mcs.rx_mask[4] = 0x01;
1734 band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1735
1736 if (rx_streams != tx_streams) {
1737 band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1738 band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
1739 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1740 }
1741}
1742
1743static void
1744mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
1745{
1746 struct mwl8k_priv *priv = hw->priv;
1747
1748 if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
1749 mwl8k_setup_2ghz_band(hw);
1750 if (caps & MWL8K_CAP_MIMO)
1751 mwl8k_set_ht_caps(hw, &priv->band_24, caps);
1752 }
1753
1754 if (caps & MWL8K_CAP_5GHZ) {
1755 mwl8k_setup_5ghz_band(hw);
1756 if (caps & MWL8K_CAP_MIMO)
1757 mwl8k_set_ht_caps(hw, &priv->band_50, caps);
1758 }
1759}
1760
1681static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw) 1761static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
1682{ 1762{
1683 struct mwl8k_priv *priv = hw->priv; 1763 struct mwl8k_priv *priv = hw->priv;
@@ -1708,6 +1788,9 @@ static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
1708 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); 1788 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1709 priv->fw_rev = le32_to_cpu(cmd->fw_rev); 1789 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1710 priv->hw_rev = cmd->hw_rev; 1790 priv->hw_rev = cmd->hw_rev;
1791 mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
1792 priv->ap_macids_supported = 0x00000000;
1793 priv->sta_macids_supported = 0x00000001;
1711 } 1794 }
1712 1795
1713 kfree(cmd); 1796 kfree(cmd);
@@ -1761,6 +1844,9 @@ static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
1761 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); 1844 priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
1762 priv->fw_rev = le32_to_cpu(cmd->fw_rev); 1845 priv->fw_rev = le32_to_cpu(cmd->fw_rev);
1763 priv->hw_rev = cmd->hw_rev; 1846 priv->hw_rev = cmd->hw_rev;
1847 mwl8k_setup_2ghz_band(hw);
1848 priv->ap_macids_supported = 0x000000ff;
1849 priv->sta_macids_supported = 0x00000000;
1764 1850
1765 off = le32_to_cpu(cmd->wcbbase0) & 0xffff; 1851 off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
1766 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off); 1852 iowrite32(cpu_to_le32(priv->txq[0].txd_dma), priv->sram + off);
@@ -1806,7 +1892,9 @@ struct mwl8k_cmd_set_hw_spec {
1806 __le32 total_rxd; 1892 __le32 total_rxd;
1807} __attribute__((packed)); 1893} __attribute__((packed));
1808 1894
1809#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080 1895#define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
1896#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
1897#define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
1810 1898
1811static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw) 1899static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1812{ 1900{
@@ -1827,7 +1915,9 @@ static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
1827 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES); 1915 cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
1828 for (i = 0; i < MWL8K_TX_QUEUES; i++) 1916 for (i = 0; i < MWL8K_TX_QUEUES; i++)
1829 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma); 1917 cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
1830 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT); 1918 cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
1919 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
1920 MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
1831 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); 1921 cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
1832 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS); 1922 cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
1833 1923
@@ -1897,9 +1987,9 @@ __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
1897} 1987}
1898 1988
1899/* 1989/*
1900 * CMD_802_11_GET_STAT. 1990 * CMD_GET_STAT.
1901 */ 1991 */
1902struct mwl8k_cmd_802_11_get_stat { 1992struct mwl8k_cmd_get_stat {
1903 struct mwl8k_cmd_pkt header; 1993 struct mwl8k_cmd_pkt header;
1904 __le32 stats[64]; 1994 __le32 stats[64];
1905} __attribute__((packed)); 1995} __attribute__((packed));
@@ -1909,10 +1999,10 @@ struct mwl8k_cmd_802_11_get_stat {
1909#define MWL8K_STAT_FCS_ERROR 24 1999#define MWL8K_STAT_FCS_ERROR 24
1910#define MWL8K_STAT_RTS_SUCCESS 11 2000#define MWL8K_STAT_RTS_SUCCESS 11
1911 2001
1912static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw, 2002static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
1913 struct ieee80211_low_level_stats *stats) 2003 struct ieee80211_low_level_stats *stats)
1914{ 2004{
1915 struct mwl8k_cmd_802_11_get_stat *cmd; 2005 struct mwl8k_cmd_get_stat *cmd;
1916 int rc; 2006 int rc;
1917 2007
1918 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2008 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -1939,9 +2029,9 @@ static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
1939} 2029}
1940 2030
1941/* 2031/*
1942 * CMD_802_11_RADIO_CONTROL. 2032 * CMD_RADIO_CONTROL.
1943 */ 2033 */
1944struct mwl8k_cmd_802_11_radio_control { 2034struct mwl8k_cmd_radio_control {
1945 struct mwl8k_cmd_pkt header; 2035 struct mwl8k_cmd_pkt header;
1946 __le16 action; 2036 __le16 action;
1947 __le16 control; 2037 __le16 control;
@@ -1949,10 +2039,10 @@ struct mwl8k_cmd_802_11_radio_control {
1949} __attribute__((packed)); 2039} __attribute__((packed));
1950 2040
1951static int 2041static int
1952mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force) 2042mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
1953{ 2043{
1954 struct mwl8k_priv *priv = hw->priv; 2044 struct mwl8k_priv *priv = hw->priv;
1955 struct mwl8k_cmd_802_11_radio_control *cmd; 2045 struct mwl8k_cmd_radio_control *cmd;
1956 int rc; 2046 int rc;
1957 2047
1958 if (enable == priv->radio_on && !force) 2048 if (enable == priv->radio_on && !force)
@@ -1977,36 +2067,32 @@ mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
1977 return rc; 2067 return rc;
1978} 2068}
1979 2069
1980static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw) 2070static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
1981{ 2071{
1982 return mwl8k_cmd_802_11_radio_control(hw, 0, 0); 2072 return mwl8k_cmd_radio_control(hw, 0, 0);
1983} 2073}
1984 2074
1985static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw) 2075static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
1986{ 2076{
1987 return mwl8k_cmd_802_11_radio_control(hw, 1, 0); 2077 return mwl8k_cmd_radio_control(hw, 1, 0);
1988} 2078}
1989 2079
1990static int 2080static int
1991mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble) 2081mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
1992{ 2082{
1993 struct mwl8k_priv *priv; 2083 struct mwl8k_priv *priv = hw->priv;
1994
1995 if (hw == NULL || hw->priv == NULL)
1996 return -EINVAL;
1997 priv = hw->priv;
1998 2084
1999 priv->radio_short_preamble = short_preamble; 2085 priv->radio_short_preamble = short_preamble;
2000 2086
2001 return mwl8k_cmd_802_11_radio_control(hw, 1, 1); 2087 return mwl8k_cmd_radio_control(hw, 1, 1);
2002} 2088}
2003 2089
2004/* 2090/*
2005 * CMD_802_11_RF_TX_POWER. 2091 * CMD_RF_TX_POWER.
2006 */ 2092 */
2007#define MWL8K_TX_POWER_LEVEL_TOTAL 8 2093#define MWL8K_TX_POWER_LEVEL_TOTAL 8
2008 2094
2009struct mwl8k_cmd_802_11_rf_tx_power { 2095struct mwl8k_cmd_rf_tx_power {
2010 struct mwl8k_cmd_pkt header; 2096 struct mwl8k_cmd_pkt header;
2011 __le16 action; 2097 __le16 action;
2012 __le16 support_level; 2098 __le16 support_level;
@@ -2015,9 +2101,9 @@ struct mwl8k_cmd_802_11_rf_tx_power {
2015 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL]; 2101 __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
2016} __attribute__((packed)); 2102} __attribute__((packed));
2017 2103
2018static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm) 2104static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
2019{ 2105{
2020 struct mwl8k_cmd_802_11_rf_tx_power *cmd; 2106 struct mwl8k_cmd_rf_tx_power *cmd;
2021 int rc; 2107 int rc;
2022 2108
2023 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2109 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -2069,6 +2155,36 @@ mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
2069} 2155}
2070 2156
2071/* 2157/*
2158 * CMD_SET_BEACON.
2159 */
2160struct mwl8k_cmd_set_beacon {
2161 struct mwl8k_cmd_pkt header;
2162 __le16 beacon_len;
2163 __u8 beacon[0];
2164};
2165
2166static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
2167 struct ieee80211_vif *vif, u8 *beacon, int len)
2168{
2169 struct mwl8k_cmd_set_beacon *cmd;
2170 int rc;
2171
2172 cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
2173 if (cmd == NULL)
2174 return -ENOMEM;
2175
2176 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
2177 cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
2178 cmd->beacon_len = cpu_to_le16(len);
2179 memcpy(cmd->beacon, beacon, len);
2180
2181 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2182 kfree(cmd);
2183
2184 return rc;
2185}
2186
2187/*
2072 * CMD_SET_PRE_SCAN. 2188 * CMD_SET_PRE_SCAN.
2073 */ 2189 */
2074struct mwl8k_cmd_set_pre_scan { 2190struct mwl8k_cmd_set_pre_scan {
@@ -2103,7 +2219,7 @@ struct mwl8k_cmd_set_post_scan {
2103} __attribute__((packed)); 2219} __attribute__((packed));
2104 2220
2105static int 2221static int
2106mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac) 2222mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
2107{ 2223{
2108 struct mwl8k_cmd_set_post_scan *cmd; 2224 struct mwl8k_cmd_set_post_scan *cmd;
2109 int rc; 2225 int rc;
@@ -2134,8 +2250,9 @@ struct mwl8k_cmd_set_rf_channel {
2134} __attribute__((packed)); 2250} __attribute__((packed));
2135 2251
2136static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw, 2252static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2137 struct ieee80211_channel *channel) 2253 struct ieee80211_conf *conf)
2138{ 2254{
2255 struct ieee80211_channel *channel = conf->channel;
2139 struct mwl8k_cmd_set_rf_channel *cmd; 2256 struct mwl8k_cmd_set_rf_channel *cmd;
2140 int rc; 2257 int rc;
2141 2258
@@ -2147,10 +2264,19 @@ static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2147 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2264 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2148 cmd->action = cpu_to_le16(MWL8K_CMD_SET); 2265 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2149 cmd->current_channel = channel->hw_value; 2266 cmd->current_channel = channel->hw_value;
2267
2150 if (channel->band == IEEE80211_BAND_2GHZ) 2268 if (channel->band == IEEE80211_BAND_2GHZ)
2151 cmd->channel_flags = cpu_to_le32(0x00000081); 2269 cmd->channel_flags |= cpu_to_le32(0x00000001);
2152 else 2270 else if (channel->band == IEEE80211_BAND_5GHZ)
2153 cmd->channel_flags = cpu_to_le32(0x00000000); 2271 cmd->channel_flags |= cpu_to_le32(0x00000004);
2272
2273 if (conf->channel_type == NL80211_CHAN_NO_HT ||
2274 conf->channel_type == NL80211_CHAN_HT20)
2275 cmd->channel_flags |= cpu_to_le32(0x00000080);
2276 else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
2277 cmd->channel_flags |= cpu_to_le32(0x000001900);
2278 else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
2279 cmd->channel_flags |= cpu_to_le32(0x000000900);
2154 2280
2155 rc = mwl8k_post_cmd(hw, &cmd->header); 2281 rc = mwl8k_post_cmd(hw, &cmd->header);
2156 kfree(cmd); 2282 kfree(cmd);
@@ -2159,85 +2285,75 @@ static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
2159} 2285}
2160 2286
2161/* 2287/*
2162 * CMD_SET_SLOT. 2288 * CMD_SET_AID.
2163 */ 2289 */
2164struct mwl8k_cmd_set_slot { 2290#define MWL8K_FRAME_PROT_DISABLED 0x00
2165 struct mwl8k_cmd_pkt header; 2291#define MWL8K_FRAME_PROT_11G 0x07
2166 __le16 action; 2292#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
2167 __u8 short_slot; 2293#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2168} __attribute__((packed));
2169
2170static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
2171{
2172 struct mwl8k_cmd_set_slot *cmd;
2173 int rc;
2174
2175 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2176 if (cmd == NULL)
2177 return -ENOMEM;
2178
2179 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2180 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2181 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2182 cmd->short_slot = short_slot_time;
2183
2184 rc = mwl8k_post_cmd(hw, &cmd->header);
2185 kfree(cmd);
2186 2294
2187 return rc; 2295struct mwl8k_cmd_update_set_aid {
2188} 2296 struct mwl8k_cmd_pkt header;
2297 __le16 aid;
2189 2298
2190/* 2299 /* AP's MAC address (BSSID) */
2191 * CMD_MIMO_CONFIG. 2300 __u8 bssid[ETH_ALEN];
2192 */ 2301 __le16 protection_mode;
2193struct mwl8k_cmd_mimo_config { 2302 __u8 supp_rates[14];
2194 struct mwl8k_cmd_pkt header;
2195 __le32 action;
2196 __u8 rx_antenna_map;
2197 __u8 tx_antenna_map;
2198} __attribute__((packed)); 2303} __attribute__((packed));
2199 2304
2200static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx) 2305static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
2201{ 2306{
2202 struct mwl8k_cmd_mimo_config *cmd; 2307 int i;
2203 int rc; 2308 int j;
2204
2205 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2206 if (cmd == NULL)
2207 return -ENOMEM;
2208
2209 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2210 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2211 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2212 cmd->rx_antenna_map = rx;
2213 cmd->tx_antenna_map = tx;
2214 2309
2215 rc = mwl8k_post_cmd(hw, &cmd->header); 2310 /*
2216 kfree(cmd); 2311 * Clear nonstandard rates 4 and 13.
2312 */
2313 mask &= 0x1fef;
2217 2314
2218 return rc; 2315 for (i = 0, j = 0; i < 14; i++) {
2316 if (mask & (1 << i))
2317 rates[j++] = mwl8k_rates_24[i].hw_value;
2318 }
2219} 2319}
2220 2320
2221/* 2321static int
2222 * CMD_ENABLE_SNIFFER. 2322mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2223 */ 2323 struct ieee80211_vif *vif, u32 legacy_rate_mask)
2224struct mwl8k_cmd_enable_sniffer {
2225 struct mwl8k_cmd_pkt header;
2226 __le32 action;
2227} __attribute__((packed));
2228
2229static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2230{ 2324{
2231 struct mwl8k_cmd_enable_sniffer *cmd; 2325 struct mwl8k_cmd_update_set_aid *cmd;
2326 u16 prot_mode;
2232 int rc; 2327 int rc;
2233 2328
2234 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2329 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2235 if (cmd == NULL) 2330 if (cmd == NULL)
2236 return -ENOMEM; 2331 return -ENOMEM;
2237 2332
2238 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER); 2333 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
2239 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2334 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2240 cmd->action = cpu_to_le32(!!enable); 2335 cmd->aid = cpu_to_le16(vif->bss_conf.aid);
2336 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
2337
2338 if (vif->bss_conf.use_cts_prot) {
2339 prot_mode = MWL8K_FRAME_PROT_11G;
2340 } else {
2341 switch (vif->bss_conf.ht_operation_mode &
2342 IEEE80211_HT_OP_MODE_PROTECTION) {
2343 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2344 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2345 break;
2346 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2347 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2348 break;
2349 default:
2350 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2351 break;
2352 }
2353 }
2354 cmd->protection_mode = cpu_to_le16(prot_mode);
2355
2356 legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
2241 2357
2242 rc = mwl8k_post_cmd(hw, &cmd->header); 2358 rc = mwl8k_post_cmd(hw, &cmd->header);
2243 kfree(cmd); 2359 kfree(cmd);
@@ -2246,37 +2362,32 @@ static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2246} 2362}
2247 2363
2248/* 2364/*
2249 * CMD_SET_MAC_ADDR. 2365 * CMD_SET_RATE.
2250 */ 2366 */
2251struct mwl8k_cmd_set_mac_addr { 2367struct mwl8k_cmd_set_rate {
2252 struct mwl8k_cmd_pkt header; 2368 struct mwl8k_cmd_pkt header;
2253 union { 2369 __u8 legacy_rates[14];
2254 struct { 2370
2255 __le16 mac_type; 2371 /* Bitmap for supported MCS codes. */
2256 __u8 mac_addr[ETH_ALEN]; 2372 __u8 mcs_set[16];
2257 } mbss; 2373 __u8 reserved[16];
2258 __u8 mac_addr[ETH_ALEN];
2259 };
2260} __attribute__((packed)); 2374} __attribute__((packed));
2261 2375
2262static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac) 2376static int
2377mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2378 u32 legacy_rate_mask, u8 *mcs_rates)
2263{ 2379{
2264 struct mwl8k_priv *priv = hw->priv; 2380 struct mwl8k_cmd_set_rate *cmd;
2265 struct mwl8k_cmd_set_mac_addr *cmd;
2266 int rc; 2381 int rc;
2267 2382
2268 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2383 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2269 if (cmd == NULL) 2384 if (cmd == NULL)
2270 return -ENOMEM; 2385 return -ENOMEM;
2271 2386
2272 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR); 2387 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
2273 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2388 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2274 if (priv->ap_fw) { 2389 legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
2275 cmd->mbss.mac_type = 0; 2390 memcpy(cmd->mcs_set, mcs_rates, 16);
2276 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2277 } else {
2278 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2279 }
2280 2391
2281 rc = mwl8k_post_cmd(hw, &cmd->header); 2392 rc = mwl8k_post_cmd(hw, &cmd->header);
2282 kfree(cmd); 2393 kfree(cmd);
@@ -2284,29 +2395,40 @@ static int mwl8k_set_mac_addr(struct ieee80211_hw *hw, u8 *mac)
2284 return rc; 2395 return rc;
2285} 2396}
2286 2397
2287
2288/* 2398/*
2289 * CMD_SET_RATEADAPT_MODE. 2399 * CMD_FINALIZE_JOIN.
2290 */ 2400 */
2291struct mwl8k_cmd_set_rate_adapt_mode { 2401#define MWL8K_FJ_BEACON_MAXLEN 128
2402
2403struct mwl8k_cmd_finalize_join {
2292 struct mwl8k_cmd_pkt header; 2404 struct mwl8k_cmd_pkt header;
2293 __le16 action; 2405 __le32 sleep_interval; /* Number of beacon periods to sleep */
2294 __le16 mode; 2406 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2295} __attribute__((packed)); 2407} __attribute__((packed));
2296 2408
2297static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode) 2409static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
2410 int framelen, int dtim)
2298{ 2411{
2299 struct mwl8k_cmd_set_rate_adapt_mode *cmd; 2412 struct mwl8k_cmd_finalize_join *cmd;
2413 struct ieee80211_mgmt *payload = frame;
2414 int payload_len;
2300 int rc; 2415 int rc;
2301 2416
2302 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2417 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2303 if (cmd == NULL) 2418 if (cmd == NULL)
2304 return -ENOMEM; 2419 return -ENOMEM;
2305 2420
2306 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE); 2421 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
2307 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2422 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2308 cmd->action = cpu_to_le16(MWL8K_CMD_SET); 2423 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
2309 cmd->mode = cpu_to_le16(mode); 2424
2425 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2426 if (payload_len < 0)
2427 payload_len = 0;
2428 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2429 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2430
2431 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2310 2432
2311 rc = mwl8k_post_cmd(hw, &cmd->header); 2433 rc = mwl8k_post_cmd(hw, &cmd->header);
2312 kfree(cmd); 2434 kfree(cmd);
@@ -2315,59 +2437,57 @@ static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
2315} 2437}
2316 2438
2317/* 2439/*
2318 * CMD_SET_WMM_MODE. 2440 * CMD_SET_RTS_THRESHOLD.
2319 */ 2441 */
2320struct mwl8k_cmd_set_wmm { 2442struct mwl8k_cmd_set_rts_threshold {
2321 struct mwl8k_cmd_pkt header; 2443 struct mwl8k_cmd_pkt header;
2322 __le16 action; 2444 __le16 action;
2445 __le16 threshold;
2323} __attribute__((packed)); 2446} __attribute__((packed));
2324 2447
2325static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable) 2448static int
2449mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
2326{ 2450{
2327 struct mwl8k_priv *priv = hw->priv; 2451 struct mwl8k_cmd_set_rts_threshold *cmd;
2328 struct mwl8k_cmd_set_wmm *cmd;
2329 int rc; 2452 int rc;
2330 2453
2331 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2454 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2332 if (cmd == NULL) 2455 if (cmd == NULL)
2333 return -ENOMEM; 2456 return -ENOMEM;
2334 2457
2335 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE); 2458 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
2336 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2459 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2337 cmd->action = cpu_to_le16(!!enable); 2460 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2461 cmd->threshold = cpu_to_le16(rts_thresh);
2338 2462
2339 rc = mwl8k_post_cmd(hw, &cmd->header); 2463 rc = mwl8k_post_cmd(hw, &cmd->header);
2340 kfree(cmd); 2464 kfree(cmd);
2341 2465
2342 if (!rc)
2343 priv->wmm_enabled = enable;
2344
2345 return rc; 2466 return rc;
2346} 2467}
2347 2468
2348/* 2469/*
2349 * CMD_SET_RTS_THRESHOLD. 2470 * CMD_SET_SLOT.
2350 */ 2471 */
2351struct mwl8k_cmd_rts_threshold { 2472struct mwl8k_cmd_set_slot {
2352 struct mwl8k_cmd_pkt header; 2473 struct mwl8k_cmd_pkt header;
2353 __le16 action; 2474 __le16 action;
2354 __le16 threshold; 2475 __u8 short_slot;
2355} __attribute__((packed)); 2476} __attribute__((packed));
2356 2477
2357static int mwl8k_rts_threshold(struct ieee80211_hw *hw, 2478static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
2358 u16 action, u16 threshold)
2359{ 2479{
2360 struct mwl8k_cmd_rts_threshold *cmd; 2480 struct mwl8k_cmd_set_slot *cmd;
2361 int rc; 2481 int rc;
2362 2482
2363 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2483 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2364 if (cmd == NULL) 2484 if (cmd == NULL)
2365 return -ENOMEM; 2485 return -ENOMEM;
2366 2486
2367 cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD); 2487 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
2368 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2488 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2369 cmd->action = cpu_to_le16(action); 2489 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2370 cmd->threshold = cpu_to_le16(threshold); 2490 cmd->short_slot = short_slot_time;
2371 2491
2372 rc = mwl8k_post_cmd(hw, &cmd->header); 2492 rc = mwl8k_post_cmd(hw, &cmd->header);
2373 kfree(cmd); 2493 kfree(cmd);
@@ -2426,9 +2546,9 @@ struct mwl8k_cmd_set_edca_params {
2426 MWL8K_SET_EDCA_AIFS) 2546 MWL8K_SET_EDCA_AIFS)
2427 2547
2428static int 2548static int
2429mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum, 2549mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2430 __u16 cw_min, __u16 cw_max, 2550 __u16 cw_min, __u16 cw_max,
2431 __u8 aifs, __u16 txop) 2551 __u8 aifs, __u16 txop)
2432{ 2552{
2433 struct mwl8k_priv *priv = hw->priv; 2553 struct mwl8k_priv *priv = hw->priv;
2434 struct mwl8k_cmd_set_edca_params *cmd; 2554 struct mwl8k_cmd_set_edca_params *cmd;
@@ -2438,12 +2558,6 @@ mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2438 if (cmd == NULL) 2558 if (cmd == NULL)
2439 return -ENOMEM; 2559 return -ENOMEM;
2440 2560
2441 /*
2442 * Queues 0 (BE) and 1 (BK) are swapped in hardware for
2443 * this call.
2444 */
2445 qnum ^= !(qnum >> 1);
2446
2447 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS); 2561 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
2448 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2562 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2449 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL); 2563 cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
@@ -2467,170 +2581,259 @@ mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
2467} 2581}
2468 2582
2469/* 2583/*
2470 * CMD_FINALIZE_JOIN. 2584 * CMD_SET_WMM_MODE.
2471 */ 2585 */
2472#define MWL8K_FJ_BEACON_MAXLEN 128 2586struct mwl8k_cmd_set_wmm_mode {
2473
2474struct mwl8k_cmd_finalize_join {
2475 struct mwl8k_cmd_pkt header; 2587 struct mwl8k_cmd_pkt header;
2476 __le32 sleep_interval; /* Number of beacon periods to sleep */ 2588 __le16 action;
2477 __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
2478} __attribute__((packed)); 2589} __attribute__((packed));
2479 2590
2480static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame, 2591static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
2481 int framelen, int dtim)
2482{ 2592{
2483 struct mwl8k_cmd_finalize_join *cmd; 2593 struct mwl8k_priv *priv = hw->priv;
2484 struct ieee80211_mgmt *payload = frame; 2594 struct mwl8k_cmd_set_wmm_mode *cmd;
2485 int payload_len;
2486 int rc; 2595 int rc;
2487 2596
2488 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2597 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2489 if (cmd == NULL) 2598 if (cmd == NULL)
2490 return -ENOMEM; 2599 return -ENOMEM;
2491 2600
2492 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN); 2601 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
2493 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2602 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2494 cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1); 2603 cmd->action = cpu_to_le16(!!enable);
2495
2496 payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
2497 if (payload_len < 0)
2498 payload_len = 0;
2499 else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
2500 payload_len = MWL8K_FJ_BEACON_MAXLEN;
2501
2502 memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
2503 2604
2504 rc = mwl8k_post_cmd(hw, &cmd->header); 2605 rc = mwl8k_post_cmd(hw, &cmd->header);
2505 kfree(cmd); 2606 kfree(cmd);
2506 2607
2608 if (!rc)
2609 priv->wmm_enabled = enable;
2610
2507 return rc; 2611 return rc;
2508} 2612}
2509 2613
2510/* 2614/*
2511 * CMD_UPDATE_STADB. 2615 * CMD_MIMO_CONFIG.
2512 */ 2616 */
2513struct mwl8k_cmd_update_sta_db { 2617struct mwl8k_cmd_mimo_config {
2514 struct mwl8k_cmd_pkt header; 2618 struct mwl8k_cmd_pkt header;
2619 __le32 action;
2620 __u8 rx_antenna_map;
2621 __u8 tx_antenna_map;
2622} __attribute__((packed));
2515 2623
2516 /* See STADB_ACTION_TYPE */ 2624static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
2517 __le32 action; 2625{
2626 struct mwl8k_cmd_mimo_config *cmd;
2627 int rc;
2518 2628
2519 /* Peer MAC address */ 2629 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2520 __u8 peer_addr[ETH_ALEN]; 2630 if (cmd == NULL)
2631 return -ENOMEM;
2521 2632
2522 __le32 reserved; 2633 cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
2634 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2635 cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
2636 cmd->rx_antenna_map = rx;
2637 cmd->tx_antenna_map = tx;
2523 2638
2524 /* Peer info - valid during add/update. */ 2639 rc = mwl8k_post_cmd(hw, &cmd->header);
2525 struct peer_capability_info peer_info; 2640 kfree(cmd);
2641
2642 return rc;
2643}
2644
2645/*
2646 * CMD_USE_FIXED_RATE (STA version).
2647 */
2648struct mwl8k_cmd_use_fixed_rate_sta {
2649 struct mwl8k_cmd_pkt header;
2650 __le32 action;
2651 __le32 allow_rate_drop;
2652 __le32 num_rates;
2653 struct {
2654 __le32 is_ht_rate;
2655 __le32 enable_retry;
2656 __le32 rate;
2657 __le32 retry_count;
2658 } rate_entry[8];
2659 __le32 rate_type;
2660 __le32 reserved1;
2661 __le32 reserved2;
2526} __attribute__((packed)); 2662} __attribute__((packed));
2527 2663
2528static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw, 2664#define MWL8K_USE_AUTO_RATE 0x0002
2529 struct ieee80211_vif *vif, __u32 action) 2665#define MWL8K_UCAST_RATE 0
2666
2667static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
2530{ 2668{
2531 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif); 2669 struct mwl8k_cmd_use_fixed_rate_sta *cmd;
2532 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2533 struct mwl8k_cmd_update_sta_db *cmd;
2534 struct peer_capability_info *peer_info;
2535 int rc; 2670 int rc;
2536 2671
2537 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2672 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2538 if (cmd == NULL) 2673 if (cmd == NULL)
2539 return -ENOMEM; 2674 return -ENOMEM;
2540 2675
2541 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB); 2676 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2542 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2677 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2678 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2679 cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
2543 2680
2544 cmd->action = cpu_to_le32(action); 2681 rc = mwl8k_post_cmd(hw, &cmd->header);
2545 peer_info = &cmd->peer_info; 2682 kfree(cmd);
2546 memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN);
2547 2683
2548 switch (action) { 2684 return rc;
2549 case MWL8K_STA_DB_ADD_ENTRY: 2685}
2550 case MWL8K_STA_DB_MODIFY_ENTRY:
2551 /* Build peer_info block */
2552 peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
2553 peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
2554 memcpy(peer_info->legacy_rates, mwl8k_rateids,
2555 sizeof(mwl8k_rateids));
2556 peer_info->interop = 1;
2557 peer_info->amsdu_enabled = 0;
2558
2559 rc = mwl8k_post_cmd(hw, &cmd->header);
2560 if (rc == 0)
2561 mv_vif->peer_id = peer_info->station_id;
2562 2686
2563 break; 2687/*
2688 * CMD_USE_FIXED_RATE (AP version).
2689 */
2690struct mwl8k_cmd_use_fixed_rate_ap {
2691 struct mwl8k_cmd_pkt header;
2692 __le32 action;
2693 __le32 allow_rate_drop;
2694 __le32 num_rates;
2695 struct mwl8k_rate_entry_ap {
2696 __le32 is_ht_rate;
2697 __le32 enable_retry;
2698 __le32 rate;
2699 __le32 retry_count;
2700 } rate_entry[4];
2701 u8 multicast_rate;
2702 u8 multicast_rate_type;
2703 u8 management_rate;
2704} __attribute__((packed));
2564 2705
2565 case MWL8K_STA_DB_DEL_ENTRY: 2706static int
2566 case MWL8K_STA_DB_FLUSH: 2707mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
2567 default: 2708{
2568 rc = mwl8k_post_cmd(hw, &cmd->header); 2709 struct mwl8k_cmd_use_fixed_rate_ap *cmd;
2569 if (rc == 0) 2710 int rc;
2570 mv_vif->peer_id = 0; 2711
2571 break; 2712 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2572 } 2713 if (cmd == NULL)
2714 return -ENOMEM;
2715
2716 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
2717 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2718 cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
2719 cmd->multicast_rate = mcast;
2720 cmd->management_rate = mgmt;
2721
2722 rc = mwl8k_post_cmd(hw, &cmd->header);
2573 kfree(cmd); 2723 kfree(cmd);
2574 2724
2575 return rc; 2725 return rc;
2576} 2726}
2577 2727
2578/* 2728/*
2579 * CMD_SET_AID. 2729 * CMD_ENABLE_SNIFFER.
2580 */ 2730 */
2581#define MWL8K_FRAME_PROT_DISABLED 0x00 2731struct mwl8k_cmd_enable_sniffer {
2582#define MWL8K_FRAME_PROT_11G 0x07 2732 struct mwl8k_cmd_pkt header;
2583#define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02 2733 __le32 action;
2584#define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
2585
2586struct mwl8k_cmd_update_set_aid {
2587 struct mwl8k_cmd_pkt header;
2588 __le16 aid;
2589
2590 /* AP's MAC address (BSSID) */
2591 __u8 bssid[ETH_ALEN];
2592 __le16 protection_mode;
2593 __u8 supp_rates[14];
2594} __attribute__((packed)); 2734} __attribute__((packed));
2595 2735
2596static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw, 2736static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
2597 struct ieee80211_vif *vif)
2598{ 2737{
2599 struct mwl8k_vif *mv_vif = MWL8K_VIF(vif); 2738 struct mwl8k_cmd_enable_sniffer *cmd;
2600 struct ieee80211_bss_conf *info = &mv_vif->bss_info;
2601 struct mwl8k_cmd_update_set_aid *cmd;
2602 u16 prot_mode;
2603 int rc; 2739 int rc;
2604 2740
2605 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2741 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2606 if (cmd == NULL) 2742 if (cmd == NULL)
2607 return -ENOMEM; 2743 return -ENOMEM;
2608 2744
2609 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID); 2745 cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
2610 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2746 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2611 cmd->aid = cpu_to_le16(info->aid); 2747 cmd->action = cpu_to_le32(!!enable);
2612 2748
2613 memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN); 2749 rc = mwl8k_post_cmd(hw, &cmd->header);
2750 kfree(cmd);
2614 2751
2615 if (info->use_cts_prot) { 2752 return rc;
2616 prot_mode = MWL8K_FRAME_PROT_11G; 2753}
2754
2755/*
2756 * CMD_SET_MAC_ADDR.
2757 */
2758struct mwl8k_cmd_set_mac_addr {
2759 struct mwl8k_cmd_pkt header;
2760 union {
2761 struct {
2762 __le16 mac_type;
2763 __u8 mac_addr[ETH_ALEN];
2764 } mbss;
2765 __u8 mac_addr[ETH_ALEN];
2766 };
2767} __attribute__((packed));
2768
2769#define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
2770#define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
2771#define MWL8K_MAC_TYPE_PRIMARY_AP 2
2772#define MWL8K_MAC_TYPE_SECONDARY_AP 3
2773
2774static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
2775 struct ieee80211_vif *vif, u8 *mac)
2776{
2777 struct mwl8k_priv *priv = hw->priv;
2778 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
2779 struct mwl8k_cmd_set_mac_addr *cmd;
2780 int mac_type;
2781 int rc;
2782
2783 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
2784 if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
2785 if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
2786 mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
2787 else
2788 mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
2789 } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
2790 if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
2791 mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
2792 else
2793 mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
2794 }
2795
2796 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2797 if (cmd == NULL)
2798 return -ENOMEM;
2799
2800 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
2801 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2802 if (priv->ap_fw) {
2803 cmd->mbss.mac_type = cpu_to_le16(mac_type);
2804 memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
2617 } else { 2805 } else {
2618 switch (info->ht_operation_mode & 2806 memcpy(cmd->mac_addr, mac, ETH_ALEN);
2619 IEEE80211_HT_OP_MODE_PROTECTION) {
2620 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
2621 prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
2622 break;
2623 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
2624 prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
2625 break;
2626 default:
2627 prot_mode = MWL8K_FRAME_PROT_DISABLED;
2628 break;
2629 }
2630 } 2807 }
2631 cmd->protection_mode = cpu_to_le16(prot_mode);
2632 2808
2633 memcpy(cmd->supp_rates, mwl8k_rateids, sizeof(mwl8k_rateids)); 2809 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2810 kfree(cmd);
2811
2812 return rc;
2813}
2814
2815/*
2816 * CMD_SET_RATEADAPT_MODE.
2817 */
2818struct mwl8k_cmd_set_rate_adapt_mode {
2819 struct mwl8k_cmd_pkt header;
2820 __le16 action;
2821 __le16 mode;
2822} __attribute__((packed));
2823
2824static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
2825{
2826 struct mwl8k_cmd_set_rate_adapt_mode *cmd;
2827 int rc;
2828
2829 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2830 if (cmd == NULL)
2831 return -ENOMEM;
2832
2833 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
2834 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2835 cmd->action = cpu_to_le16(MWL8K_CMD_SET);
2836 cmd->mode = cpu_to_le16(mode);
2634 2837
2635 rc = mwl8k_post_cmd(hw, &cmd->header); 2838 rc = mwl8k_post_cmd(hw, &cmd->header);
2636 kfree(cmd); 2839 kfree(cmd);
@@ -2639,115 +2842,255 @@ static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
2639} 2842}
2640 2843
2641/* 2844/*
2642 * CMD_SET_RATE. 2845 * CMD_BSS_START.
2643 */ 2846 */
2644struct mwl8k_cmd_update_rateset { 2847struct mwl8k_cmd_bss_start {
2645 struct mwl8k_cmd_pkt header; 2848 struct mwl8k_cmd_pkt header;
2646 __u8 legacy_rates[14]; 2849 __le32 enable;
2647
2648 /* Bitmap for supported MCS codes. */
2649 __u8 mcs_set[16];
2650 __u8 reserved[16];
2651} __attribute__((packed)); 2850} __attribute__((packed));
2652 2851
2653static int mwl8k_update_rateset(struct ieee80211_hw *hw, 2852static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
2654 struct ieee80211_vif *vif) 2853 struct ieee80211_vif *vif, int enable)
2655{ 2854{
2656 struct mwl8k_cmd_update_rateset *cmd; 2855 struct mwl8k_cmd_bss_start *cmd;
2657 int rc; 2856 int rc;
2658 2857
2659 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 2858 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2660 if (cmd == NULL) 2859 if (cmd == NULL)
2661 return -ENOMEM; 2860 return -ENOMEM;
2662 2861
2663 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE); 2862 cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
2664 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 2863 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2665 memcpy(cmd->legacy_rates, mwl8k_rateids, sizeof(mwl8k_rateids)); 2864 cmd->enable = cpu_to_le32(enable);
2666 2865
2667 rc = mwl8k_post_cmd(hw, &cmd->header); 2866 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2668 kfree(cmd); 2867 kfree(cmd);
2669 2868
2670 return rc; 2869 return rc;
2671} 2870}
2672 2871
2673/* 2872/*
2674 * CMD_USE_FIXED_RATE. 2873 * CMD_SET_NEW_STN.
2675 */ 2874 */
2676#define MWL8K_RATE_TABLE_SIZE 8 2875struct mwl8k_cmd_set_new_stn {
2677#define MWL8K_UCAST_RATE 0 2876 struct mwl8k_cmd_pkt header;
2678#define MWL8K_USE_AUTO_RATE 0x0002 2877 __le16 aid;
2878 __u8 mac_addr[6];
2879 __le16 stn_id;
2880 __le16 action;
2881 __le16 rsvd;
2882 __le32 legacy_rates;
2883 __u8 ht_rates[4];
2884 __le16 cap_info;
2885 __le16 ht_capabilities_info;
2886 __u8 mac_ht_param_info;
2887 __u8 rev;
2888 __u8 control_channel;
2889 __u8 add_channel;
2890 __le16 op_mode;
2891 __le16 stbc;
2892 __u8 add_qos_info;
2893 __u8 is_qos_sta;
2894 __le32 fw_sta_ptr;
2895} __attribute__((packed));
2679 2896
2680struct mwl8k_rate_entry { 2897#define MWL8K_STA_ACTION_ADD 0
2681 /* Set to 1 if HT rate, 0 if legacy. */ 2898#define MWL8K_STA_ACTION_REMOVE 2
2682 __le32 is_ht_rate;
2683 2899
2684 /* Set to 1 to use retry_count field. */ 2900static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
2685 __le32 enable_retry; 2901 struct ieee80211_vif *vif,
2902 struct ieee80211_sta *sta)
2903{
2904 struct mwl8k_cmd_set_new_stn *cmd;
2905 u32 rates;
2906 int rc;
2686 2907
2687 /* Specified legacy rate or MCS. */ 2908 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2688 __le32 rate; 2909 if (cmd == NULL)
2910 return -ENOMEM;
2689 2911
2690 /* Number of allowed retries. */ 2912 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2691 __le32 retry_count; 2913 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2914 cmd->aid = cpu_to_le16(sta->aid);
2915 memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
2916 cmd->stn_id = cpu_to_le16(sta->aid);
2917 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
2918 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
2919 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
2920 else
2921 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
2922 cmd->legacy_rates = cpu_to_le32(rates);
2923 if (sta->ht_cap.ht_supported) {
2924 cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
2925 cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
2926 cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
2927 cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
2928 cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
2929 cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
2930 ((sta->ht_cap.ampdu_density & 7) << 2);
2931 cmd->is_qos_sta = 1;
2932 }
2933
2934 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2935 kfree(cmd);
2936
2937 return rc;
2938}
2939
2940static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
2941 struct ieee80211_vif *vif)
2942{
2943 struct mwl8k_cmd_set_new_stn *cmd;
2944 int rc;
2945
2946 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2947 if (cmd == NULL)
2948 return -ENOMEM;
2949
2950 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2951 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2952 memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
2953
2954 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2955 kfree(cmd);
2956
2957 return rc;
2958}
2959
2960static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
2961 struct ieee80211_vif *vif, u8 *addr)
2962{
2963 struct mwl8k_cmd_set_new_stn *cmd;
2964 int rc;
2965
2966 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2967 if (cmd == NULL)
2968 return -ENOMEM;
2969
2970 cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
2971 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2972 memcpy(cmd->mac_addr, addr, ETH_ALEN);
2973 cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
2974
2975 rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
2976 kfree(cmd);
2977
2978 return rc;
2979}
2980
2981/*
2982 * CMD_UPDATE_STADB.
2983 */
2984struct ewc_ht_info {
2985 __le16 control1;
2986 __le16 control2;
2987 __le16 control3;
2692} __attribute__((packed)); 2988} __attribute__((packed));
2693 2989
2694struct mwl8k_rate_table { 2990struct peer_capability_info {
2695 /* 1 to allow specified rate and below */ 2991 /* Peer type - AP vs. STA. */
2696 __le32 allow_rate_drop; 2992 __u8 peer_type;
2697 __le32 num_rates; 2993
2698 struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE]; 2994 /* Basic 802.11 capabilities from assoc resp. */
2995 __le16 basic_caps;
2996
2997 /* Set if peer supports 802.11n high throughput (HT). */
2998 __u8 ht_support;
2999
3000 /* Valid if HT is supported. */
3001 __le16 ht_caps;
3002 __u8 extended_ht_caps;
3003 struct ewc_ht_info ewc_info;
3004
3005 /* Legacy rate table. Intersection of our rates and peer rates. */
3006 __u8 legacy_rates[12];
3007
3008 /* HT rate table. Intersection of our rates and peer rates. */
3009 __u8 ht_rates[16];
3010 __u8 pad[16];
3011
3012 /* If set, interoperability mode, no proprietary extensions. */
3013 __u8 interop;
3014 __u8 pad2;
3015 __u8 station_id;
3016 __le16 amsdu_enabled;
2699} __attribute__((packed)); 3017} __attribute__((packed));
2700 3018
2701struct mwl8k_cmd_use_fixed_rate { 3019struct mwl8k_cmd_update_stadb {
2702 struct mwl8k_cmd_pkt header; 3020 struct mwl8k_cmd_pkt header;
3021
3022 /* See STADB_ACTION_TYPE */
2703 __le32 action; 3023 __le32 action;
2704 struct mwl8k_rate_table rate_table;
2705 3024
2706 /* Unicast, Broadcast or Multicast */ 3025 /* Peer MAC address */
2707 __le32 rate_type; 3026 __u8 peer_addr[ETH_ALEN];
2708 __le32 reserved1; 3027
2709 __le32 reserved2; 3028 __le32 reserved;
3029
3030 /* Peer info - valid during add/update. */
3031 struct peer_capability_info peer_info;
2710} __attribute__((packed)); 3032} __attribute__((packed));
2711 3033
2712static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw, 3034#define MWL8K_STA_DB_MODIFY_ENTRY 1
2713 u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table) 3035#define MWL8K_STA_DB_DEL_ENTRY 2
3036
3037/* Peer Entry flags - used to define the type of the peer node */
3038#define MWL8K_PEER_TYPE_ACCESSPOINT 2
3039
3040static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
3041 struct ieee80211_vif *vif,
3042 struct ieee80211_sta *sta)
2714{ 3043{
2715 struct mwl8k_cmd_use_fixed_rate *cmd; 3044 struct mwl8k_cmd_update_stadb *cmd;
2716 int count; 3045 struct peer_capability_info *p;
3046 u32 rates;
2717 int rc; 3047 int rc;
2718 3048
2719 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 3049 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2720 if (cmd == NULL) 3050 if (cmd == NULL)
2721 return -ENOMEM; 3051 return -ENOMEM;
2722 3052
2723 cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE); 3053 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2724 cmd->header.length = cpu_to_le16(sizeof(*cmd)); 3054 cmd->header.length = cpu_to_le16(sizeof(*cmd));
3055 cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
3056 memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
3057
3058 p = &cmd->peer_info;
3059 p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
3060 p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
3061 p->ht_support = sta->ht_cap.ht_supported;
3062 p->ht_caps = sta->ht_cap.cap;
3063 p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
3064 ((sta->ht_cap.ampdu_density & 7) << 2);
3065 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3066 rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
3067 else
3068 rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3069 legacy_rate_mask_to_array(p->legacy_rates, rates);
3070 memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
3071 p->interop = 1;
3072 p->amsdu_enabled = 0;
2725 3073
2726 cmd->action = cpu_to_le32(action); 3074 rc = mwl8k_post_cmd(hw, &cmd->header);
2727 cmd->rate_type = cpu_to_le32(rate_type); 3075 kfree(cmd);
2728 3076
2729 if (rate_table != NULL) { 3077 return rc ? rc : p->station_id;
2730 /* 3078}
2731 * Copy over each field manually so that endian 3079
2732 * conversion can be done. 3080static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
2733 */ 3081 struct ieee80211_vif *vif, u8 *addr)
2734 cmd->rate_table.allow_rate_drop = 3082{
2735 cpu_to_le32(rate_table->allow_rate_drop); 3083 struct mwl8k_cmd_update_stadb *cmd;
2736 cmd->rate_table.num_rates = 3084 int rc;
2737 cpu_to_le32(rate_table->num_rates); 3085
2738 3086 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2739 for (count = 0; count < rate_table->num_rates; count++) { 3087 if (cmd == NULL)
2740 struct mwl8k_rate_entry *dst = 3088 return -ENOMEM;
2741 &cmd->rate_table.rate_entry[count]; 3089
2742 struct mwl8k_rate_entry *src = 3090 cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
2743 &rate_table->rate_entry[count]; 3091 cmd->header.length = cpu_to_le16(sizeof(*cmd));
2744 3092 cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
2745 dst->is_ht_rate = cpu_to_le32(src->is_ht_rate); 3093 memcpy(cmd->peer_addr, addr, ETH_ALEN);
2746 dst->enable_retry = cpu_to_le32(src->enable_retry);
2747 dst->rate = cpu_to_le32(src->rate);
2748 dst->retry_count = cpu_to_le32(src->retry_count);
2749 }
2750 }
2751 3094
2752 rc = mwl8k_post_cmd(hw, &cmd->header); 3095 rc = mwl8k_post_cmd(hw, &cmd->header);
2753 kfree(cmd); 3096 kfree(cmd);
@@ -2766,19 +3109,22 @@ static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2766 u32 status; 3109 u32 status;
2767 3110
2768 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); 3111 status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2769 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
2770
2771 if (!status) 3112 if (!status)
2772 return IRQ_NONE; 3113 return IRQ_NONE;
2773 3114
2774 if (status & MWL8K_A2H_INT_TX_DONE) 3115 if (status & MWL8K_A2H_INT_TX_DONE) {
2775 tasklet_schedule(&priv->tx_reclaim_task); 3116 status &= ~MWL8K_A2H_INT_TX_DONE;
3117 tasklet_schedule(&priv->poll_tx_task);
3118 }
2776 3119
2777 if (status & MWL8K_A2H_INT_RX_READY) { 3120 if (status & MWL8K_A2H_INT_RX_READY) {
2778 while (rxq_process(hw, 0, 1)) 3121 status &= ~MWL8K_A2H_INT_RX_READY;
2779 rxq_refill(hw, 0, 1); 3122 tasklet_schedule(&priv->poll_rx_task);
2780 } 3123 }
2781 3124
3125 if (status)
3126 iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3127
2782 if (status & MWL8K_A2H_INT_OPC_DONE) { 3128 if (status & MWL8K_A2H_INT_OPC_DONE) {
2783 if (priv->hostcmd_wait != NULL) 3129 if (priv->hostcmd_wait != NULL)
2784 complete(priv->hostcmd_wait); 3130 complete(priv->hostcmd_wait);
@@ -2793,6 +3139,53 @@ static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
2793 return IRQ_HANDLED; 3139 return IRQ_HANDLED;
2794} 3140}
2795 3141
3142static void mwl8k_tx_poll(unsigned long data)
3143{
3144 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3145 struct mwl8k_priv *priv = hw->priv;
3146 int limit;
3147 int i;
3148
3149 limit = 32;
3150
3151 spin_lock_bh(&priv->tx_lock);
3152
3153 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3154 limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
3155
3156 if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
3157 complete(priv->tx_wait);
3158 priv->tx_wait = NULL;
3159 }
3160
3161 spin_unlock_bh(&priv->tx_lock);
3162
3163 if (limit) {
3164 writel(~MWL8K_A2H_INT_TX_DONE,
3165 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3166 } else {
3167 tasklet_schedule(&priv->poll_tx_task);
3168 }
3169}
3170
3171static void mwl8k_rx_poll(unsigned long data)
3172{
3173 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
3174 struct mwl8k_priv *priv = hw->priv;
3175 int limit;
3176
3177 limit = 32;
3178 limit -= rxq_process(hw, 0, limit);
3179 limit -= rxq_refill(hw, 0, limit);
3180
3181 if (limit) {
3182 writel(~MWL8K_A2H_INT_RX_READY,
3183 priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3184 } else {
3185 tasklet_schedule(&priv->poll_rx_task);
3186 }
3187}
3188
2796 3189
2797/* 3190/*
2798 * Core driver operations. 3191 * Core driver operations.
@@ -2803,7 +3196,7 @@ static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2803 int index = skb_get_queue_mapping(skb); 3196 int index = skb_get_queue_mapping(skb);
2804 int rc; 3197 int rc;
2805 3198
2806 if (priv->current_channel == NULL) { 3199 if (!priv->radio_on) {
2807 printk(KERN_DEBUG "%s: dropped TX frame since radio " 3200 printk(KERN_DEBUG "%s: dropped TX frame since radio "
2808 "disabled\n", wiphy_name(hw->wiphy)); 3201 "disabled\n", wiphy_name(hw->wiphy));
2809 dev_kfree_skb(skb); 3202 dev_kfree_skb(skb);
@@ -2828,19 +3221,20 @@ static int mwl8k_start(struct ieee80211_hw *hw)
2828 return -EIO; 3221 return -EIO;
2829 } 3222 }
2830 3223
2831 /* Enable tx reclaim tasklet */ 3224 /* Enable TX reclaim and RX tasklets. */
2832 tasklet_enable(&priv->tx_reclaim_task); 3225 tasklet_enable(&priv->poll_tx_task);
3226 tasklet_enable(&priv->poll_rx_task);
2833 3227
2834 /* Enable interrupts */ 3228 /* Enable interrupts */
2835 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); 3229 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2836 3230
2837 rc = mwl8k_fw_lock(hw); 3231 rc = mwl8k_fw_lock(hw);
2838 if (!rc) { 3232 if (!rc) {
2839 rc = mwl8k_cmd_802_11_radio_enable(hw); 3233 rc = mwl8k_cmd_radio_enable(hw);
2840 3234
2841 if (!priv->ap_fw) { 3235 if (!priv->ap_fw) {
2842 if (!rc) 3236 if (!rc)
2843 rc = mwl8k_enable_sniffer(hw, 0); 3237 rc = mwl8k_cmd_enable_sniffer(hw, 0);
2844 3238
2845 if (!rc) 3239 if (!rc)
2846 rc = mwl8k_cmd_set_pre_scan(hw); 3240 rc = mwl8k_cmd_set_pre_scan(hw);
@@ -2851,10 +3245,10 @@ static int mwl8k_start(struct ieee80211_hw *hw)
2851 } 3245 }
2852 3246
2853 if (!rc) 3247 if (!rc)
2854 rc = mwl8k_cmd_setrateadaptmode(hw, 0); 3248 rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
2855 3249
2856 if (!rc) 3250 if (!rc)
2857 rc = mwl8k_set_wmm(hw, 0); 3251 rc = mwl8k_cmd_set_wmm_mode(hw, 0);
2858 3252
2859 mwl8k_fw_unlock(hw); 3253 mwl8k_fw_unlock(hw);
2860 } 3254 }
@@ -2862,7 +3256,8 @@ static int mwl8k_start(struct ieee80211_hw *hw)
2862 if (rc) { 3256 if (rc) {
2863 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); 3257 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
2864 free_irq(priv->pdev->irq, hw); 3258 free_irq(priv->pdev->irq, hw);
2865 tasklet_disable(&priv->tx_reclaim_task); 3259 tasklet_disable(&priv->poll_tx_task);
3260 tasklet_disable(&priv->poll_rx_task);
2866 } 3261 }
2867 3262
2868 return rc; 3263 return rc;
@@ -2873,7 +3268,7 @@ static void mwl8k_stop(struct ieee80211_hw *hw)
2873 struct mwl8k_priv *priv = hw->priv; 3268 struct mwl8k_priv *priv = hw->priv;
2874 int i; 3269 int i;
2875 3270
2876 mwl8k_cmd_802_11_radio_disable(hw); 3271 mwl8k_cmd_radio_disable(hw);
2877 3272
2878 ieee80211_stop_queues(hw); 3273 ieee80211_stop_queues(hw);
2879 3274
@@ -2886,36 +3281,27 @@ static void mwl8k_stop(struct ieee80211_hw *hw)
2886 if (priv->beacon_skb != NULL) 3281 if (priv->beacon_skb != NULL)
2887 dev_kfree_skb(priv->beacon_skb); 3282 dev_kfree_skb(priv->beacon_skb);
2888 3283
2889 /* Stop tx reclaim tasklet */ 3284 /* Stop TX reclaim and RX tasklets. */
2890 tasklet_disable(&priv->tx_reclaim_task); 3285 tasklet_disable(&priv->poll_tx_task);
3286 tasklet_disable(&priv->poll_rx_task);
2891 3287
2892 /* Return all skbs to mac80211 */ 3288 /* Return all skbs to mac80211 */
2893 for (i = 0; i < MWL8K_TX_QUEUES; i++) 3289 for (i = 0; i < MWL8K_TX_QUEUES; i++)
2894 mwl8k_txq_reclaim(hw, i, 1); 3290 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
2895} 3291}
2896 3292
2897static int mwl8k_add_interface(struct ieee80211_hw *hw, 3293static int mwl8k_add_interface(struct ieee80211_hw *hw,
2898 struct ieee80211_if_init_conf *conf) 3294 struct ieee80211_vif *vif)
2899{ 3295{
2900 struct mwl8k_priv *priv = hw->priv; 3296 struct mwl8k_priv *priv = hw->priv;
2901 struct mwl8k_vif *mwl8k_vif; 3297 struct mwl8k_vif *mwl8k_vif;
2902 3298 u32 macids_supported;
2903 /* 3299 int macid;
2904 * We only support one active interface at a time.
2905 */
2906 if (priv->vif != NULL)
2907 return -EBUSY;
2908
2909 /*
2910 * We only support managed interfaces for now.
2911 */
2912 if (conf->type != NL80211_IFTYPE_STATION)
2913 return -EINVAL;
2914 3300
2915 /* 3301 /*
2916 * Reject interface creation if sniffer mode is active, as 3302 * Reject interface creation if sniffer mode is active, as
2917 * STA operation is mutually exclusive with hardware sniffer 3303 * STA operation is mutually exclusive with hardware sniffer
2918 * mode. 3304 * mode. (Sniffer mode is only used on STA firmware.)
2919 */ 3305 */
2920 if (priv->sniffer_enabled) { 3306 if (priv->sniffer_enabled) {
2921 printk(KERN_INFO "%s: unable to create STA " 3307 printk(KERN_INFO "%s: unable to create STA "
@@ -2924,37 +3310,54 @@ static int mwl8k_add_interface(struct ieee80211_hw *hw,
2924 return -EINVAL; 3310 return -EINVAL;
2925 } 3311 }
2926 3312
2927 /* Clean out driver private area */
2928 mwl8k_vif = MWL8K_VIF(conf->vif);
2929 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
2930 3313
2931 /* Set and save the mac address */ 3314 switch (vif->type) {
2932 mwl8k_set_mac_addr(hw, conf->mac_addr); 3315 case NL80211_IFTYPE_AP:
2933 memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN); 3316 macids_supported = priv->ap_macids_supported;
3317 break;
3318 case NL80211_IFTYPE_STATION:
3319 macids_supported = priv->sta_macids_supported;
3320 break;
3321 default:
3322 return -EINVAL;
3323 }
2934 3324
2935 /* Back pointer to parent config block */ 3325 macid = ffs(macids_supported & ~priv->macids_used);
2936 mwl8k_vif->priv = priv; 3326 if (!macid--)
3327 return -EBUSY;
2937 3328
2938 /* Set Initial sequence number to zero */ 3329 /* Setup driver private area. */
3330 mwl8k_vif = MWL8K_VIF(vif);
3331 memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
3332 mwl8k_vif->vif = vif;
3333 mwl8k_vif->macid = macid;
2939 mwl8k_vif->seqno = 0; 3334 mwl8k_vif->seqno = 0;
2940 3335
2941 priv->vif = conf->vif; 3336 /* Set the mac address. */
2942 priv->current_channel = NULL; 3337 mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
3338
3339 if (priv->ap_fw)
3340 mwl8k_cmd_set_new_stn_add_self(hw, vif);
3341
3342 priv->macids_used |= 1 << mwl8k_vif->macid;
3343 list_add_tail(&mwl8k_vif->list, &priv->vif_list);
2943 3344
2944 return 0; 3345 return 0;
2945} 3346}
2946 3347
2947static void mwl8k_remove_interface(struct ieee80211_hw *hw, 3348static void mwl8k_remove_interface(struct ieee80211_hw *hw,
2948 struct ieee80211_if_init_conf *conf) 3349 struct ieee80211_vif *vif)
2949{ 3350{
2950 struct mwl8k_priv *priv = hw->priv; 3351 struct mwl8k_priv *priv = hw->priv;
3352 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
2951 3353
2952 if (priv->vif == NULL) 3354 if (priv->ap_fw)
2953 return; 3355 mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
2954 3356
2955 mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00"); 3357 mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
2956 3358
2957 priv->vif = NULL; 3359 priv->macids_used &= ~(1 << mwl8k_vif->macid);
3360 list_del(&mwl8k_vif->list);
2958} 3361}
2959 3362
2960static int mwl8k_config(struct ieee80211_hw *hw, u32 changed) 3363static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
@@ -2964,8 +3367,7 @@ static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
2964 int rc; 3367 int rc;
2965 3368
2966 if (conf->flags & IEEE80211_CONF_IDLE) { 3369 if (conf->flags & IEEE80211_CONF_IDLE) {
2967 mwl8k_cmd_802_11_radio_disable(hw); 3370 mwl8k_cmd_radio_disable(hw);
2968 priv->current_channel = NULL;
2969 return 0; 3371 return 0;
2970 } 3372 }
2971 3373
@@ -2973,19 +3375,17 @@ static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
2973 if (rc) 3375 if (rc)
2974 return rc; 3376 return rc;
2975 3377
2976 rc = mwl8k_cmd_802_11_radio_enable(hw); 3378 rc = mwl8k_cmd_radio_enable(hw);
2977 if (rc) 3379 if (rc)
2978 goto out; 3380 goto out;
2979 3381
2980 rc = mwl8k_cmd_set_rf_channel(hw, conf->channel); 3382 rc = mwl8k_cmd_set_rf_channel(hw, conf);
2981 if (rc) 3383 if (rc)
2982 goto out; 3384 goto out;
2983 3385
2984 priv->current_channel = conf->channel;
2985
2986 if (conf->power_level > 18) 3386 if (conf->power_level > 18)
2987 conf->power_level = 18; 3387 conf->power_level = 18;
2988 rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level); 3388 rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
2989 if (rc) 3389 if (rc)
2990 goto out; 3390 goto out;
2991 3391
@@ -3003,79 +3403,160 @@ out:
3003 return rc; 3403 return rc;
3004} 3404}
3005 3405
3006static void mwl8k_bss_info_changed(struct ieee80211_hw *hw, 3406static void
3007 struct ieee80211_vif *vif, 3407mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3008 struct ieee80211_bss_conf *info, 3408 struct ieee80211_bss_conf *info, u32 changed)
3009 u32 changed)
3010{ 3409{
3011 struct mwl8k_priv *priv = hw->priv; 3410 struct mwl8k_priv *priv = hw->priv;
3012 struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); 3411 u32 ap_legacy_rates;
3412 u8 ap_mcs_rates[16];
3013 int rc; 3413 int rc;
3014 3414
3015 if ((changed & BSS_CHANGED_ASSOC) == 0) 3415 if (mwl8k_fw_lock(hw))
3016 return; 3416 return;
3017 3417
3018 priv->capture_beacon = false; 3418 /*
3019 3419 * No need to capture a beacon if we're no longer associated.
3020 rc = mwl8k_fw_lock(hw); 3420 */
3021 if (rc) 3421 if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
3022 return; 3422 priv->capture_beacon = false;
3023 3423
3024 if (info->assoc) { 3424 /*
3025 memcpy(&mwl8k_vif->bss_info, info, 3425 * Get the AP's legacy and MCS rates.
3026 sizeof(struct ieee80211_bss_conf)); 3426 */
3427 if (vif->bss_conf.assoc) {
3428 struct ieee80211_sta *ap;
3027 3429
3028 memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN); 3430 rcu_read_lock();
3029 3431
3030 /* Install rates */ 3432 ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
3031 rc = mwl8k_update_rateset(hw, vif); 3433 if (ap == NULL) {
3032 if (rc) 3434 rcu_read_unlock();
3033 goto out; 3435 goto out;
3436 }
3437
3438 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
3439 ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
3440 } else {
3441 ap_legacy_rates =
3442 ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
3443 }
3444 memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
3445
3446 rcu_read_unlock();
3447 }
3034 3448
3035 /* Turn on rate adaptation */ 3449 if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
3036 rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE, 3450 rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
3037 MWL8K_UCAST_RATE, NULL);
3038 if (rc) 3451 if (rc)
3039 goto out; 3452 goto out;
3040 3453
3041 /* Set radio preamble */ 3454 rc = mwl8k_cmd_use_fixed_rate_sta(hw);
3042 rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble);
3043 if (rc) 3455 if (rc)
3044 goto out; 3456 goto out;
3457 }
3045 3458
3046 /* Set slot time */ 3459 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3047 rc = mwl8k_cmd_set_slot(hw, info->use_short_slot); 3460 rc = mwl8k_set_radio_preamble(hw,
3461 vif->bss_conf.use_short_preamble);
3048 if (rc) 3462 if (rc)
3049 goto out; 3463 goto out;
3464 }
3050 3465
3051 /* Update peer rate info */ 3466 if (changed & BSS_CHANGED_ERP_SLOT) {
3052 rc = mwl8k_cmd_update_sta_db(hw, vif, 3467 rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
3053 MWL8K_STA_DB_MODIFY_ENTRY);
3054 if (rc) 3468 if (rc)
3055 goto out; 3469 goto out;
3470 }
3056 3471
3057 /* Set AID */ 3472 if (vif->bss_conf.assoc &&
3058 rc = mwl8k_cmd_set_aid(hw, vif); 3473 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
3474 BSS_CHANGED_HT))) {
3475 rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
3059 if (rc) 3476 if (rc)
3060 goto out; 3477 goto out;
3478 }
3061 3479
3480 if (vif->bss_conf.assoc &&
3481 (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
3062 /* 3482 /*
3063 * Finalize the join. Tell rx handler to process 3483 * Finalize the join. Tell rx handler to process
3064 * next beacon from our BSSID. 3484 * next beacon from our BSSID.
3065 */ 3485 */
3066 memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN); 3486 memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
3067 priv->capture_beacon = true; 3487 priv->capture_beacon = true;
3068 } else {
3069 rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
3070 memset(&mwl8k_vif->bss_info, 0,
3071 sizeof(struct ieee80211_bss_conf));
3072 memset(mwl8k_vif->bssid, 0, ETH_ALEN);
3073 } 3488 }
3074 3489
3075out: 3490out:
3076 mwl8k_fw_unlock(hw); 3491 mwl8k_fw_unlock(hw);
3077} 3492}
3078 3493
3494static void
3495mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3496 struct ieee80211_bss_conf *info, u32 changed)
3497{
3498 int rc;
3499
3500 if (mwl8k_fw_lock(hw))
3501 return;
3502
3503 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3504 rc = mwl8k_set_radio_preamble(hw,
3505 vif->bss_conf.use_short_preamble);
3506 if (rc)
3507 goto out;
3508 }
3509
3510 if (changed & BSS_CHANGED_BASIC_RATES) {
3511 int idx;
3512 int rate;
3513
3514 /*
3515 * Use lowest supported basic rate for multicasts
3516 * and management frames (such as probe responses --
3517 * beacons will always go out at 1 Mb/s).
3518 */
3519 idx = ffs(vif->bss_conf.basic_rates);
3520 if (idx)
3521 idx--;
3522
3523 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
3524 rate = mwl8k_rates_24[idx].hw_value;
3525 else
3526 rate = mwl8k_rates_50[idx].hw_value;
3527
3528 mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
3529 }
3530
3531 if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
3532 struct sk_buff *skb;
3533
3534 skb = ieee80211_beacon_get(hw, vif);
3535 if (skb != NULL) {
3536 mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
3537 kfree_skb(skb);
3538 }
3539 }
3540
3541 if (changed & BSS_CHANGED_BEACON_ENABLED)
3542 mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
3543
3544out:
3545 mwl8k_fw_unlock(hw);
3546}
3547
3548static void
3549mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3550 struct ieee80211_bss_conf *info, u32 changed)
3551{
3552 struct mwl8k_priv *priv = hw->priv;
3553
3554 if (!priv->ap_fw)
3555 mwl8k_bss_info_changed_sta(hw, vif, info, changed);
3556 else
3557 mwl8k_bss_info_changed_ap(hw, vif, info, changed);
3558}
3559
3079static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw, 3560static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
3080 int mc_count, struct dev_addr_list *mclist) 3561 int mc_count, struct dev_addr_list *mclist)
3081{ 3562{
@@ -3105,7 +3586,7 @@ mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3105 * operation, so refuse to enable sniffer mode if a STA 3586 * operation, so refuse to enable sniffer mode if a STA
3106 * interface is active. 3587 * interface is active.
3107 */ 3588 */
3108 if (priv->vif != NULL) { 3589 if (!list_empty(&priv->vif_list)) {
3109 if (net_ratelimit()) 3590 if (net_ratelimit())
3110 printk(KERN_INFO "%s: not enabling sniffer " 3591 printk(KERN_INFO "%s: not enabling sniffer "
3111 "mode because STA interface is active\n", 3592 "mode because STA interface is active\n",
@@ -3114,7 +3595,7 @@ mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3114 } 3595 }
3115 3596
3116 if (!priv->sniffer_enabled) { 3597 if (!priv->sniffer_enabled) {
3117 if (mwl8k_enable_sniffer(hw, 1)) 3598 if (mwl8k_cmd_enable_sniffer(hw, 1))
3118 return 0; 3599 return 0;
3119 priv->sniffer_enabled = true; 3600 priv->sniffer_enabled = true;
3120 } 3601 }
@@ -3126,6 +3607,14 @@ mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
3126 return 1; 3607 return 1;
3127} 3608}
3128 3609
3610static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
3611{
3612 if (!list_empty(&priv->vif_list))
3613 return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
3614
3615 return NULL;
3616}
3617
3129static void mwl8k_configure_filter(struct ieee80211_hw *hw, 3618static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3130 unsigned int changed_flags, 3619 unsigned int changed_flags,
3131 unsigned int *total_flags, 3620 unsigned int *total_flags,
@@ -3163,7 +3652,7 @@ static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3163 } 3652 }
3164 3653
3165 if (priv->sniffer_enabled) { 3654 if (priv->sniffer_enabled) {
3166 mwl8k_enable_sniffer(hw, 0); 3655 mwl8k_cmd_enable_sniffer(hw, 0);
3167 priv->sniffer_enabled = false; 3656 priv->sniffer_enabled = false;
3168 } 3657 }
3169 3658
@@ -3174,7 +3663,8 @@ static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3174 */ 3663 */
3175 mwl8k_cmd_set_pre_scan(hw); 3664 mwl8k_cmd_set_pre_scan(hw);
3176 } else { 3665 } else {
3177 u8 *bssid; 3666 struct mwl8k_vif *mwl8k_vif;
3667 const u8 *bssid;
3178 3668
3179 /* 3669 /*
3180 * Enable the BSS filter. 3670 * Enable the BSS filter.
@@ -3184,9 +3674,11 @@ static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3184 * (where the OUI part needs to be nonzero for 3674 * (where the OUI part needs to be nonzero for
3185 * the BSSID to be accepted by POST_SCAN). 3675 * the BSSID to be accepted by POST_SCAN).
3186 */ 3676 */
3187 bssid = "\x01\x00\x00\x00\x00\x00"; 3677 mwl8k_vif = mwl8k_first_vif(priv);
3188 if (priv->vif != NULL) 3678 if (mwl8k_vif != NULL)
3189 bssid = MWL8K_VIF(priv->vif)->bssid; 3679 bssid = mwl8k_vif->vif->bss_conf.bssid;
3680 else
3681 bssid = "\x01\x00\x00\x00\x00\x00";
3190 3682
3191 mwl8k_cmd_set_post_scan(hw, bssid); 3683 mwl8k_cmd_set_post_scan(hw, bssid);
3192 } 3684 }
@@ -3213,7 +3705,93 @@ static void mwl8k_configure_filter(struct ieee80211_hw *hw,
3213 3705
3214static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 3706static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3215{ 3707{
3216 return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value); 3708 return mwl8k_cmd_set_rts_threshold(hw, value);
3709}
3710
3711struct mwl8k_sta_notify_item
3712{
3713 struct list_head list;
3714 struct ieee80211_vif *vif;
3715 enum sta_notify_cmd cmd;
3716 struct ieee80211_sta sta;
3717};
3718
3719static void
3720mwl8k_do_sta_notify(struct ieee80211_hw *hw, struct mwl8k_sta_notify_item *s)
3721{
3722 struct mwl8k_priv *priv = hw->priv;
3723
3724 /*
3725 * STA firmware uses UPDATE_STADB, AP firmware uses SET_NEW_STN.
3726 */
3727 if (!priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3728 int rc;
3729
3730 rc = mwl8k_cmd_update_stadb_add(hw, s->vif, &s->sta);
3731 if (rc >= 0) {
3732 struct ieee80211_sta *sta;
3733
3734 rcu_read_lock();
3735 sta = ieee80211_find_sta(s->vif, s->sta.addr);
3736 if (sta != NULL)
3737 MWL8K_STA(sta)->peer_id = rc;
3738 rcu_read_unlock();
3739 }
3740 } else if (!priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3741 mwl8k_cmd_update_stadb_del(hw, s->vif, s->sta.addr);
3742 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_ADD) {
3743 mwl8k_cmd_set_new_stn_add(hw, s->vif, &s->sta);
3744 } else if (priv->ap_fw && s->cmd == STA_NOTIFY_REMOVE) {
3745 mwl8k_cmd_set_new_stn_del(hw, s->vif, s->sta.addr);
3746 }
3747}
3748
3749static void mwl8k_sta_notify_worker(struct work_struct *work)
3750{
3751 struct mwl8k_priv *priv =
3752 container_of(work, struct mwl8k_priv, sta_notify_worker);
3753 struct ieee80211_hw *hw = priv->hw;
3754
3755 spin_lock_bh(&priv->sta_notify_list_lock);
3756 while (!list_empty(&priv->sta_notify_list)) {
3757 struct mwl8k_sta_notify_item *s;
3758
3759 s = list_entry(priv->sta_notify_list.next,
3760 struct mwl8k_sta_notify_item, list);
3761 list_del(&s->list);
3762
3763 spin_unlock_bh(&priv->sta_notify_list_lock);
3764
3765 mwl8k_do_sta_notify(hw, s);
3766 kfree(s);
3767
3768 spin_lock_bh(&priv->sta_notify_list_lock);
3769 }
3770 spin_unlock_bh(&priv->sta_notify_list_lock);
3771}
3772
3773static void
3774mwl8k_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3775 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3776{
3777 struct mwl8k_priv *priv = hw->priv;
3778 struct mwl8k_sta_notify_item *s;
3779
3780 if (cmd != STA_NOTIFY_ADD && cmd != STA_NOTIFY_REMOVE)
3781 return;
3782
3783 s = kmalloc(sizeof(*s), GFP_ATOMIC);
3784 if (s != NULL) {
3785 s->vif = vif;
3786 s->cmd = cmd;
3787 s->sta = *sta;
3788
3789 spin_lock(&priv->sta_notify_list_lock);
3790 list_add_tail(&s->list, &priv->sta_notify_list);
3791 spin_unlock(&priv->sta_notify_list_lock);
3792
3793 ieee80211_queue_work(hw, &priv->sta_notify_worker);
3794 }
3217} 3795}
3218 3796
3219static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue, 3797static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
@@ -3225,14 +3803,14 @@ static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
3225 rc = mwl8k_fw_lock(hw); 3803 rc = mwl8k_fw_lock(hw);
3226 if (!rc) { 3804 if (!rc) {
3227 if (!priv->wmm_enabled) 3805 if (!priv->wmm_enabled)
3228 rc = mwl8k_set_wmm(hw, 1); 3806 rc = mwl8k_cmd_set_wmm_mode(hw, 1);
3229 3807
3230 if (!rc) 3808 if (!rc)
3231 rc = mwl8k_set_edca_params(hw, queue, 3809 rc = mwl8k_cmd_set_edca_params(hw, queue,
3232 params->cw_min, 3810 params->cw_min,
3233 params->cw_max, 3811 params->cw_max,
3234 params->aifs, 3812 params->aifs,
3235 params->txop); 3813 params->txop);
3236 3814
3237 mwl8k_fw_unlock(hw); 3815 mwl8k_fw_unlock(hw);
3238 } 3816 }
@@ -3261,7 +3839,23 @@ static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
3261static int mwl8k_get_stats(struct ieee80211_hw *hw, 3839static int mwl8k_get_stats(struct ieee80211_hw *hw,
3262 struct ieee80211_low_level_stats *stats) 3840 struct ieee80211_low_level_stats *stats)
3263{ 3841{
3264 return mwl8k_cmd_802_11_get_stat(hw, stats); 3842 return mwl8k_cmd_get_stat(hw, stats);
3843}
3844
3845static int
3846mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3847 enum ieee80211_ampdu_mlme_action action,
3848 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
3849{
3850 switch (action) {
3851 case IEEE80211_AMPDU_RX_START:
3852 case IEEE80211_AMPDU_RX_STOP:
3853 if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
3854 return -ENOTSUPP;
3855 return 0;
3856 default:
3857 return -ENOTSUPP;
3858 }
3265} 3859}
3266 3860
3267static const struct ieee80211_ops mwl8k_ops = { 3861static const struct ieee80211_ops mwl8k_ops = {
@@ -3275,67 +3869,68 @@ static const struct ieee80211_ops mwl8k_ops = {
3275 .prepare_multicast = mwl8k_prepare_multicast, 3869 .prepare_multicast = mwl8k_prepare_multicast,
3276 .configure_filter = mwl8k_configure_filter, 3870 .configure_filter = mwl8k_configure_filter,
3277 .set_rts_threshold = mwl8k_set_rts_threshold, 3871 .set_rts_threshold = mwl8k_set_rts_threshold,
3872 .sta_notify = mwl8k_sta_notify,
3278 .conf_tx = mwl8k_conf_tx, 3873 .conf_tx = mwl8k_conf_tx,
3279 .get_tx_stats = mwl8k_get_tx_stats, 3874 .get_tx_stats = mwl8k_get_tx_stats,
3280 .get_stats = mwl8k_get_stats, 3875 .get_stats = mwl8k_get_stats,
3876 .ampdu_action = mwl8k_ampdu_action,
3281}; 3877};
3282 3878
3283static void mwl8k_tx_reclaim_handler(unsigned long data)
3284{
3285 int i;
3286 struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
3287 struct mwl8k_priv *priv = hw->priv;
3288
3289 spin_lock_bh(&priv->tx_lock);
3290 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3291 mwl8k_txq_reclaim(hw, i, 0);
3292
3293 if (priv->tx_wait != NULL && !priv->pending_tx_pkts) {
3294 complete(priv->tx_wait);
3295 priv->tx_wait = NULL;
3296 }
3297 spin_unlock_bh(&priv->tx_lock);
3298}
3299
3300static void mwl8k_finalize_join_worker(struct work_struct *work) 3879static void mwl8k_finalize_join_worker(struct work_struct *work)
3301{ 3880{
3302 struct mwl8k_priv *priv = 3881 struct mwl8k_priv *priv =
3303 container_of(work, struct mwl8k_priv, finalize_join_worker); 3882 container_of(work, struct mwl8k_priv, finalize_join_worker);
3304 struct sk_buff *skb = priv->beacon_skb; 3883 struct sk_buff *skb = priv->beacon_skb;
3305 u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period; 3884 struct mwl8k_vif *mwl8k_vif;
3306 3885
3307 mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim); 3886 mwl8k_vif = mwl8k_first_vif(priv);
3308 dev_kfree_skb(skb); 3887 if (mwl8k_vif != NULL)
3888 mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len,
3889 mwl8k_vif->vif->bss_conf.dtim_period);
3309 3890
3891 dev_kfree_skb(skb);
3310 priv->beacon_skb = NULL; 3892 priv->beacon_skb = NULL;
3311} 3893}
3312 3894
3313enum { 3895enum {
3314 MWL8687 = 0, 3896 MWL8363 = 0,
3897 MWL8687,
3315 MWL8366, 3898 MWL8366,
3316}; 3899};
3317 3900
3318static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = { 3901static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
3319 { 3902 [MWL8363] = {
3903 .part_name = "88w8363",
3904 .helper_image = "mwl8k/helper_8363.fw",
3905 .fw_image = "mwl8k/fmimage_8363.fw",
3906 },
3907 [MWL8687] = {
3320 .part_name = "88w8687", 3908 .part_name = "88w8687",
3321 .helper_image = "mwl8k/helper_8687.fw", 3909 .helper_image = "mwl8k/helper_8687.fw",
3322 .fw_image = "mwl8k/fmimage_8687.fw", 3910 .fw_image = "mwl8k/fmimage_8687.fw",
3323 .rxd_ops = &rxd_8687_ops,
3324 .modes = BIT(NL80211_IFTYPE_STATION),
3325 }, 3911 },
3326 { 3912 [MWL8366] = {
3327 .part_name = "88w8366", 3913 .part_name = "88w8366",
3328 .helper_image = "mwl8k/helper_8366.fw", 3914 .helper_image = "mwl8k/helper_8366.fw",
3329 .fw_image = "mwl8k/fmimage_8366.fw", 3915 .fw_image = "mwl8k/fmimage_8366.fw",
3330 .rxd_ops = &rxd_8366_ops, 3916 .ap_rxd_ops = &rxd_8366_ap_ops,
3331 .modes = 0,
3332 }, 3917 },
3333}; 3918};
3334 3919
3920MODULE_FIRMWARE("mwl8k/helper_8363.fw");
3921MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
3922MODULE_FIRMWARE("mwl8k/helper_8687.fw");
3923MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
3924MODULE_FIRMWARE("mwl8k/helper_8366.fw");
3925MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
3926
3335static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = { 3927static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
3928 { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
3929 { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
3336 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, }, 3930 { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
3337 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, }, 3931 { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
3338 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, }, 3932 { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
3933 { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
3339 { }, 3934 { },
3340}; 3935};
3341MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table); 3936MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
@@ -3354,6 +3949,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3354 printed_version = 1; 3949 printed_version = 1;
3355 } 3950 }
3356 3951
3952
3357 rc = pci_enable_device(pdev); 3953 rc = pci_enable_device(pdev);
3358 if (rc) { 3954 if (rc) {
3359 printk(KERN_ERR "%s: Cannot enable new PCI device\n", 3955 printk(KERN_ERR "%s: Cannot enable new PCI device\n",
@@ -3370,6 +3966,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3370 3966
3371 pci_set_master(pdev); 3967 pci_set_master(pdev);
3372 3968
3969
3373 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops); 3970 hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
3374 if (hw == NULL) { 3971 if (hw == NULL) {
3375 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME); 3972 printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
@@ -3377,17 +3974,14 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3377 goto err_free_reg; 3974 goto err_free_reg;
3378 } 3975 }
3379 3976
3977 SET_IEEE80211_DEV(hw, &pdev->dev);
3978 pci_set_drvdata(pdev, hw);
3979
3380 priv = hw->priv; 3980 priv = hw->priv;
3381 priv->hw = hw; 3981 priv->hw = hw;
3382 priv->pdev = pdev; 3982 priv->pdev = pdev;
3383 priv->device_info = &mwl8k_info_tbl[id->driver_data]; 3983 priv->device_info = &mwl8k_info_tbl[id->driver_data];
3384 priv->rxd_ops = priv->device_info->rxd_ops;
3385 priv->sniffer_enabled = false;
3386 priv->wmm_enabled = false;
3387 priv->pending_tx_pkts = 0;
3388 3984
3389 SET_IEEE80211_DEV(hw, &pdev->dev);
3390 pci_set_drvdata(pdev, hw);
3391 3985
3392 priv->sram = pci_iomap(pdev, 0, 0x10000); 3986 priv->sram = pci_iomap(pdev, 0, 0x10000);
3393 if (priv->sram == NULL) { 3987 if (priv->sram == NULL) {
@@ -3410,16 +4004,46 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3410 } 4004 }
3411 } 4005 }
3412 4006
3413 memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
3414 priv->band.band = IEEE80211_BAND_2GHZ;
3415 priv->band.channels = priv->channels;
3416 priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
3417 priv->band.bitrates = priv->rates;
3418 priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
3419 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
3420 4007
3421 BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates)); 4008 /* Reset firmware and hardware */
3422 memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates)); 4009 mwl8k_hw_reset(priv);
4010
4011 /* Ask userland hotplug daemon for the device firmware */
4012 rc = mwl8k_request_firmware(priv);
4013 if (rc) {
4014 printk(KERN_ERR "%s: Firmware files not found\n",
4015 wiphy_name(hw->wiphy));
4016 goto err_stop_firmware;
4017 }
4018
4019 /* Load firmware into hardware */
4020 rc = mwl8k_load_firmware(hw);
4021 if (rc) {
4022 printk(KERN_ERR "%s: Cannot start firmware\n",
4023 wiphy_name(hw->wiphy));
4024 goto err_stop_firmware;
4025 }
4026
4027 /* Reclaim memory once firmware is successfully loaded */
4028 mwl8k_release_firmware(priv);
4029
4030
4031 if (priv->ap_fw) {
4032 priv->rxd_ops = priv->device_info->ap_rxd_ops;
4033 if (priv->rxd_ops == NULL) {
4034 printk(KERN_ERR "%s: Driver does not have AP "
4035 "firmware image support for this hardware\n",
4036 wiphy_name(hw->wiphy));
4037 goto err_stop_firmware;
4038 }
4039 } else {
4040 priv->rxd_ops = &rxd_sta_ops;
4041 }
4042
4043 priv->sniffer_enabled = false;
4044 priv->wmm_enabled = false;
4045 priv->pending_tx_pkts = 0;
4046
3423 4047
3424 /* 4048 /*
3425 * Extra headroom is the size of the required DMA header 4049 * Extra headroom is the size of the required DMA header
@@ -3432,33 +4056,40 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3432 4056
3433 hw->queues = MWL8K_TX_QUEUES; 4057 hw->queues = MWL8K_TX_QUEUES;
3434 4058
3435 hw->wiphy->interface_modes = priv->device_info->modes;
3436
3437 /* Set rssi and noise values to dBm */ 4059 /* Set rssi and noise values to dBm */
3438 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM; 4060 hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM;
3439 hw->vif_data_size = sizeof(struct mwl8k_vif); 4061 hw->vif_data_size = sizeof(struct mwl8k_vif);
3440 priv->vif = NULL; 4062 hw->sta_data_size = sizeof(struct mwl8k_sta);
4063
4064 priv->macids_used = 0;
4065 INIT_LIST_HEAD(&priv->vif_list);
3441 4066
3442 /* Set default radio state and preamble */ 4067 /* Set default radio state and preamble */
3443 priv->radio_on = 0; 4068 priv->radio_on = 0;
3444 priv->radio_short_preamble = 0; 4069 priv->radio_short_preamble = 0;
3445 4070
4071 /* Station database handling */
4072 INIT_WORK(&priv->sta_notify_worker, mwl8k_sta_notify_worker);
4073 spin_lock_init(&priv->sta_notify_list_lock);
4074 INIT_LIST_HEAD(&priv->sta_notify_list);
4075
3446 /* Finalize join worker */ 4076 /* Finalize join worker */
3447 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker); 4077 INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
3448 4078
3449 /* TX reclaim tasklet */ 4079 /* TX reclaim and RX tasklets. */
3450 tasklet_init(&priv->tx_reclaim_task, 4080 tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
3451 mwl8k_tx_reclaim_handler, (unsigned long)hw); 4081 tasklet_disable(&priv->poll_tx_task);
3452 tasklet_disable(&priv->tx_reclaim_task); 4082 tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
4083 tasklet_disable(&priv->poll_rx_task);
3453 4084
3454 /* Power management cookie */ 4085 /* Power management cookie */
3455 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma); 4086 priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
3456 if (priv->cookie == NULL) 4087 if (priv->cookie == NULL)
3457 goto err_iounmap; 4088 goto err_stop_firmware;
3458 4089
3459 rc = mwl8k_rxq_init(hw, 0); 4090 rc = mwl8k_rxq_init(hw, 0);
3460 if (rc) 4091 if (rc)
3461 goto err_iounmap; 4092 goto err_free_cookie;
3462 rxq_refill(hw, 0, INT_MAX); 4093 rxq_refill(hw, 0, INT_MAX);
3463 4094
3464 mutex_init(&priv->fw_mutex); 4095 mutex_init(&priv->fw_mutex);
@@ -3478,7 +4109,8 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3478 4109
3479 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); 4110 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
3480 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); 4111 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3481 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL); 4112 iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
4113 priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
3482 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); 4114 iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
3483 4115
3484 rc = request_irq(priv->pdev->irq, mwl8k_interrupt, 4116 rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
@@ -3489,31 +4121,9 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3489 goto err_free_queues; 4121 goto err_free_queues;
3490 } 4122 }
3491 4123
3492 /* Reset firmware and hardware */
3493 mwl8k_hw_reset(priv);
3494
3495 /* Ask userland hotplug daemon for the device firmware */
3496 rc = mwl8k_request_firmware(priv);
3497 if (rc) {
3498 printk(KERN_ERR "%s: Firmware files not found\n",
3499 wiphy_name(hw->wiphy));
3500 goto err_free_irq;
3501 }
3502
3503 /* Load firmware into hardware */
3504 rc = mwl8k_load_firmware(hw);
3505 if (rc) {
3506 printk(KERN_ERR "%s: Cannot start firmware\n",
3507 wiphy_name(hw->wiphy));
3508 goto err_stop_firmware;
3509 }
3510
3511 /* Reclaim memory once firmware is successfully loaded */
3512 mwl8k_release_firmware(priv);
3513
3514 /* 4124 /*
3515 * Temporarily enable interrupts. Initial firmware host 4125 * Temporarily enable interrupts. Initial firmware host
3516 * commands use interrupts and avoids polling. Disable 4126 * commands use interrupts and avoid polling. Disable
3517 * interrupts when done. 4127 * interrupts when done.
3518 */ 4128 */
3519 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); 4129 iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
@@ -3529,22 +4139,29 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3529 if (rc) { 4139 if (rc) {
3530 printk(KERN_ERR "%s: Cannot initialise firmware\n", 4140 printk(KERN_ERR "%s: Cannot initialise firmware\n",
3531 wiphy_name(hw->wiphy)); 4141 wiphy_name(hw->wiphy));
3532 goto err_stop_firmware; 4142 goto err_free_irq;
3533 } 4143 }
3534 4144
4145 hw->wiphy->interface_modes = 0;
4146 if (priv->ap_macids_supported)
4147 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
4148 if (priv->sta_macids_supported)
4149 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
4150
4151
3535 /* Turn radio off */ 4152 /* Turn radio off */
3536 rc = mwl8k_cmd_802_11_radio_disable(hw); 4153 rc = mwl8k_cmd_radio_disable(hw);
3537 if (rc) { 4154 if (rc) {
3538 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy)); 4155 printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy));
3539 goto err_stop_firmware; 4156 goto err_free_irq;
3540 } 4157 }
3541 4158
3542 /* Clear MAC address */ 4159 /* Clear MAC address */
3543 rc = mwl8k_set_mac_addr(hw, "\x00\x00\x00\x00\x00\x00"); 4160 rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
3544 if (rc) { 4161 if (rc) {
3545 printk(KERN_ERR "%s: Cannot clear MAC address\n", 4162 printk(KERN_ERR "%s: Cannot clear MAC address\n",
3546 wiphy_name(hw->wiphy)); 4163 wiphy_name(hw->wiphy));
3547 goto err_stop_firmware; 4164 goto err_free_irq;
3548 } 4165 }
3549 4166
3550 /* Disable interrupts */ 4167 /* Disable interrupts */
@@ -3555,7 +4172,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3555 if (rc) { 4172 if (rc) {
3556 printk(KERN_ERR "%s: Cannot register device\n", 4173 printk(KERN_ERR "%s: Cannot register device\n",
3557 wiphy_name(hw->wiphy)); 4174 wiphy_name(hw->wiphy));
3558 goto err_stop_firmware; 4175 goto err_free_queues;
3559 } 4176 }
3560 4177
3561 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n", 4178 printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
@@ -3567,10 +4184,6 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
3567 4184
3568 return 0; 4185 return 0;
3569 4186
3570err_stop_firmware:
3571 mwl8k_hw_reset(priv);
3572 mwl8k_release_firmware(priv);
3573
3574err_free_irq: 4187err_free_irq:
3575 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); 4188 iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
3576 free_irq(priv->pdev->irq, hw); 4189 free_irq(priv->pdev->irq, hw);
@@ -3580,11 +4193,16 @@ err_free_queues:
3580 mwl8k_txq_deinit(hw, i); 4193 mwl8k_txq_deinit(hw, i);
3581 mwl8k_rxq_deinit(hw, 0); 4194 mwl8k_rxq_deinit(hw, 0);
3582 4195
3583err_iounmap: 4196err_free_cookie:
3584 if (priv->cookie != NULL) 4197 if (priv->cookie != NULL)
3585 pci_free_consistent(priv->pdev, 4, 4198 pci_free_consistent(priv->pdev, 4,
3586 priv->cookie, priv->cookie_dma); 4199 priv->cookie, priv->cookie_dma);
3587 4200
4201err_stop_firmware:
4202 mwl8k_hw_reset(priv);
4203 mwl8k_release_firmware(priv);
4204
4205err_iounmap:
3588 if (priv->regs != NULL) 4206 if (priv->regs != NULL)
3589 pci_iounmap(pdev, priv->regs); 4207 pci_iounmap(pdev, priv->regs);
3590 4208
@@ -3622,15 +4240,16 @@ static void __devexit mwl8k_remove(struct pci_dev *pdev)
3622 4240
3623 ieee80211_unregister_hw(hw); 4241 ieee80211_unregister_hw(hw);
3624 4242
3625 /* Remove tx reclaim tasklet */ 4243 /* Remove TX reclaim and RX tasklets. */
3626 tasklet_kill(&priv->tx_reclaim_task); 4244 tasklet_kill(&priv->poll_tx_task);
4245 tasklet_kill(&priv->poll_rx_task);
3627 4246
3628 /* Stop hardware */ 4247 /* Stop hardware */
3629 mwl8k_hw_reset(priv); 4248 mwl8k_hw_reset(priv);
3630 4249
3631 /* Return all skbs to mac80211 */ 4250 /* Return all skbs to mac80211 */
3632 for (i = 0; i < MWL8K_TX_QUEUES; i++) 4251 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3633 mwl8k_txq_reclaim(hw, i, 1); 4252 mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
3634 4253
3635 for (i = 0; i < MWL8K_TX_QUEUES; i++) 4254 for (i = 0; i < MWL8K_TX_QUEUES; i++)
3636 mwl8k_txq_deinit(hw, i); 4255 mwl8k_txq_deinit(hw, i);