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