Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1 | /* |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2 | * drivers/net/wireless/mwl8k.c |
| 3 | * Driver for Marvell TOPDOG 802.11 Wireless cards |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4 | * |
Lennert Buytenhek | a5fb297 | 2010-01-12 13:51:38 +0100 | [diff] [blame] | 5 | * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6 | * |
| 7 | * This file is licensed under the terms of the GNU General Public |
| 8 | * License version 2. This program is licensed "as is" without any |
| 9 | * warranty of any kind, whether express or implied. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
Lennert Buytenhek | 3d76e82 | 2009-10-22 20:20:16 +0200 | [diff] [blame] | 15 | #include <linux/sched.h> |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 16 | #include <linux/spinlock.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/pci.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/completion.h> |
| 21 | #include <linux/etherdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 23 | #include <net/mac80211.h> |
| 24 | #include <linux/moduleparam.h> |
| 25 | #include <linux/firmware.h> |
| 26 | #include <linux/workqueue.h> |
| 27 | |
| 28 | #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver" |
| 29 | #define MWL8K_NAME KBUILD_MODNAME |
Lennert Buytenhek | a5fb297 | 2010-01-12 13:51:38 +0100 | [diff] [blame] | 30 | #define MWL8K_VERSION "0.12" |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 31 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 32 | /* Module parameters */ |
| 33 | static unsigned ap_mode_default; |
| 34 | module_param(ap_mode_default, bool, 0); |
| 35 | MODULE_PARM_DESC(ap_mode_default, |
| 36 | "Set to 1 to make ap mode the default instead of sta mode"); |
| 37 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 38 | /* Register definitions */ |
| 39 | #define MWL8K_HIU_GEN_PTR 0x00000c10 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 40 | #define MWL8K_MODE_STA 0x0000005a |
| 41 | #define MWL8K_MODE_AP 0x000000a5 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 42 | #define MWL8K_HIU_INT_CODE 0x00000c14 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 43 | #define MWL8K_FWSTA_READY 0xf0f1f2f4 |
| 44 | #define MWL8K_FWAP_READY 0xf1f2f4a5 |
| 45 | #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 46 | #define MWL8K_HIU_SCRATCH 0x00000c40 |
| 47 | |
| 48 | /* Host->device communications */ |
| 49 | #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18 |
| 50 | #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c |
| 51 | #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20 |
| 52 | #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24 |
| 53 | #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 54 | #define MWL8K_H2A_INT_DUMMY (1 << 20) |
| 55 | #define MWL8K_H2A_INT_RESET (1 << 15) |
| 56 | #define MWL8K_H2A_INT_DOORBELL (1 << 1) |
| 57 | #define MWL8K_H2A_INT_PPA_READY (1 << 0) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 58 | |
| 59 | /* Device->host communications */ |
| 60 | #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c |
| 61 | #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30 |
| 62 | #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34 |
| 63 | #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38 |
| 64 | #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 65 | #define MWL8K_A2H_INT_DUMMY (1 << 20) |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 66 | #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14) |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 67 | #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11) |
| 68 | #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10) |
| 69 | #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7) |
| 70 | #define MWL8K_A2H_INT_RADIO_ON (1 << 6) |
| 71 | #define MWL8K_A2H_INT_RADIO_OFF (1 << 5) |
| 72 | #define MWL8K_A2H_INT_MAC_EVENT (1 << 3) |
| 73 | #define MWL8K_A2H_INT_OPC_DONE (1 << 2) |
| 74 | #define MWL8K_A2H_INT_RX_READY (1 << 1) |
| 75 | #define MWL8K_A2H_INT_TX_DONE (1 << 0) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 76 | |
| 77 | #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \ |
| 78 | MWL8K_A2H_INT_CHNL_SWITCHED | \ |
| 79 | MWL8K_A2H_INT_QUEUE_EMPTY | \ |
| 80 | MWL8K_A2H_INT_RADAR_DETECT | \ |
| 81 | MWL8K_A2H_INT_RADIO_ON | \ |
| 82 | MWL8K_A2H_INT_RADIO_OFF | \ |
| 83 | MWL8K_A2H_INT_MAC_EVENT | \ |
| 84 | MWL8K_A2H_INT_OPC_DONE | \ |
| 85 | MWL8K_A2H_INT_RX_READY | \ |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 86 | MWL8K_A2H_INT_TX_DONE | \ |
| 87 | MWL8K_A2H_INT_BA_WATCHDOG) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 88 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 89 | #define MWL8K_RX_QUEUES 1 |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 90 | #define MWL8K_TX_WMM_QUEUES 4 |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 91 | #define MWL8K_MAX_AMPDU_QUEUES 8 |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 92 | #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES) |
| 93 | #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 94 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 95 | struct rxd_ops { |
| 96 | int rxd_size; |
| 97 | void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr); |
| 98 | void (*rxd_refill)(void *rxd, dma_addr_t addr, int len); |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 99 | int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 100 | __le16 *qos, s8 *noise); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 101 | }; |
| 102 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 103 | struct mwl8k_device_info { |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 104 | char *part_name; |
| 105 | char *helper_image; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 106 | char *fw_image_sta; |
| 107 | char *fw_image_ap; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 108 | struct rxd_ops *ap_rxd_ops; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 109 | u32 fw_api_ap; |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 112 | struct mwl8k_rx_queue { |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 113 | int rxd_count; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 114 | |
| 115 | /* hw receives here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 116 | int head; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 117 | |
| 118 | /* refill descs here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 119 | int tail; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 120 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 121 | void *rxd; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 122 | dma_addr_t rxd_dma; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 123 | struct { |
| 124 | struct sk_buff *skb; |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 125 | DEFINE_DMA_UNMAP_ADDR(dma); |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 126 | } *buf; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 129 | struct mwl8k_tx_queue { |
| 130 | /* hw transmits here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 131 | int head; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 132 | |
| 133 | /* sw appends here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 134 | int tail; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 135 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 136 | unsigned int len; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 137 | struct mwl8k_tx_desc *txd; |
| 138 | dma_addr_t txd_dma; |
| 139 | struct sk_buff **skb; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 140 | }; |
| 141 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 142 | enum { |
| 143 | AMPDU_NO_STREAM, |
| 144 | AMPDU_STREAM_NEW, |
| 145 | AMPDU_STREAM_IN_PROGRESS, |
| 146 | AMPDU_STREAM_ACTIVE, |
| 147 | }; |
| 148 | |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 149 | struct mwl8k_ampdu_stream { |
| 150 | struct ieee80211_sta *sta; |
| 151 | u8 tid; |
| 152 | u8 state; |
| 153 | u8 idx; |
| 154 | u8 txq_idx; /* index of this stream in priv->txq */ |
| 155 | }; |
| 156 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 157 | struct mwl8k_priv { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 158 | struct ieee80211_hw *hw; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 159 | struct pci_dev *pdev; |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 160 | int irq; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 161 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 162 | struct mwl8k_device_info *device_info; |
| 163 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 164 | void __iomem *sram; |
| 165 | void __iomem *regs; |
| 166 | |
| 167 | /* firmware */ |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 168 | const struct firmware *fw_helper; |
| 169 | const struct firmware *fw_ucode; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 170 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 171 | /* hardware/firmware parameters */ |
| 172 | bool ap_fw; |
| 173 | struct rxd_ops *rxd_ops; |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 174 | struct ieee80211_supported_band band_24; |
| 175 | struct ieee80211_channel channels_24[14]; |
| 176 | struct ieee80211_rate rates_24[14]; |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 177 | struct ieee80211_supported_band band_50; |
| 178 | struct ieee80211_channel channels_50[4]; |
| 179 | struct ieee80211_rate rates_50[9]; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 180 | u32 ap_macids_supported; |
| 181 | u32 sta_macids_supported; |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 182 | |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 183 | /* Ampdu stream information */ |
| 184 | u8 num_ampdu_queues; |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 185 | spinlock_t stream_lock; |
| 186 | struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES]; |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 187 | struct work_struct watchdog_ba_handle; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 188 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 189 | /* firmware access */ |
| 190 | struct mutex fw_mutex; |
| 191 | struct task_struct *fw_mutex_owner; |
| 192 | int fw_mutex_depth; |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 193 | struct completion *hostcmd_wait; |
| 194 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 195 | /* lock held over TX and TX reap */ |
| 196 | spinlock_t tx_lock; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 197 | |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 198 | /* TX quiesce completion, protected by fw_mutex and tx_lock */ |
| 199 | struct completion *tx_wait; |
| 200 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 201 | /* List of interfaces. */ |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 202 | u32 macids_used; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 203 | struct list_head vif_list; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 204 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 205 | /* power management status cookie from firmware */ |
| 206 | u32 *cookie; |
| 207 | dma_addr_t cookie_dma; |
| 208 | |
| 209 | u16 num_mcaddrs; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 210 | u8 hw_rev; |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 211 | u32 fw_rev; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * Running count of TX packets in flight, to avoid |
| 215 | * iterating over the transmit rings each time. |
| 216 | */ |
| 217 | int pending_tx_pkts; |
| 218 | |
| 219 | struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES]; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 220 | struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES]; |
| 221 | u32 txq_offset[MWL8K_MAX_TX_QUEUES]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 222 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 223 | bool radio_on; |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 224 | bool radio_short_preamble; |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 225 | bool sniffer_enabled; |
Lennert Buytenhek | 0439b1f | 2009-07-16 12:34:02 +0200 | [diff] [blame] | 226 | bool wmm_enabled; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 227 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 228 | /* XXX need to convert this to handle multiple interfaces */ |
| 229 | bool capture_beacon; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 230 | u8 capture_bssid[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 231 | struct sk_buff *beacon_skb; |
| 232 | |
| 233 | /* |
| 234 | * This FJ worker has to be global as it is scheduled from the |
| 235 | * RX handler. At this point we don't know which interface it |
| 236 | * belongs to until the list of bssids waiting to complete join |
| 237 | * is checked. |
| 238 | */ |
| 239 | struct work_struct finalize_join_worker; |
| 240 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 241 | /* Tasklet to perform TX reclaim. */ |
| 242 | struct tasklet_struct poll_tx_task; |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 243 | |
| 244 | /* Tasklet to perform RX. */ |
| 245 | struct tasklet_struct poll_rx_task; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 246 | |
| 247 | /* Most recently reported noise in dBm */ |
| 248 | s8 noise; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 249 | |
| 250 | /* |
| 251 | * preserve the queue configurations so they can be restored if/when |
| 252 | * the firmware image is swapped. |
| 253 | */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 254 | struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES]; |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 255 | |
| 256 | /* async firmware loading state */ |
| 257 | unsigned fw_state; |
| 258 | char *fw_pref; |
| 259 | char *fw_alt; |
| 260 | struct completion firmware_loading_complete; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 261 | }; |
| 262 | |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 263 | #define MAX_WEP_KEY_LEN 13 |
| 264 | #define NUM_WEP_KEYS 4 |
| 265 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 266 | /* Per interface specific private data */ |
| 267 | struct mwl8k_vif { |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 268 | struct list_head list; |
| 269 | struct ieee80211_vif *vif; |
| 270 | |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 271 | /* Firmware macid for this vif. */ |
| 272 | int macid; |
| 273 | |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 274 | /* Non AMPDU sequence number assigned by driver. */ |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 275 | u16 seqno; |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 276 | |
| 277 | /* Saved WEP keys */ |
| 278 | struct { |
| 279 | u8 enabled; |
| 280 | u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN]; |
| 281 | } wep_key_conf[NUM_WEP_KEYS]; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 282 | |
| 283 | /* BSSID */ |
| 284 | u8 bssid[ETH_ALEN]; |
| 285 | |
| 286 | /* A flag to indicate is HW crypto is enabled for this bssid */ |
| 287 | bool is_hw_crypto_enabled; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 288 | }; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 289 | #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv)) |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 290 | #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 291 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 292 | struct mwl8k_sta { |
| 293 | /* Index into station database. Returned by UPDATE_STADB. */ |
| 294 | u8 peer_id; |
Nishant Sarmukadam | 1703354 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 295 | u8 is_ampdu_allowed; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 296 | }; |
| 297 | #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv)) |
| 298 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 299 | static const struct ieee80211_channel mwl8k_channels_24[] = { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 300 | { .center_freq = 2412, .hw_value = 1, }, |
| 301 | { .center_freq = 2417, .hw_value = 2, }, |
| 302 | { .center_freq = 2422, .hw_value = 3, }, |
| 303 | { .center_freq = 2427, .hw_value = 4, }, |
| 304 | { .center_freq = 2432, .hw_value = 5, }, |
| 305 | { .center_freq = 2437, .hw_value = 6, }, |
| 306 | { .center_freq = 2442, .hw_value = 7, }, |
| 307 | { .center_freq = 2447, .hw_value = 8, }, |
| 308 | { .center_freq = 2452, .hw_value = 9, }, |
| 309 | { .center_freq = 2457, .hw_value = 10, }, |
| 310 | { .center_freq = 2462, .hw_value = 11, }, |
Lennert Buytenhek | 647ca6b | 2009-11-30 18:32:20 +0100 | [diff] [blame] | 311 | { .center_freq = 2467, .hw_value = 12, }, |
| 312 | { .center_freq = 2472, .hw_value = 13, }, |
| 313 | { .center_freq = 2484, .hw_value = 14, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 314 | }; |
| 315 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 316 | static const struct ieee80211_rate mwl8k_rates_24[] = { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 317 | { .bitrate = 10, .hw_value = 2, }, |
| 318 | { .bitrate = 20, .hw_value = 4, }, |
| 319 | { .bitrate = 55, .hw_value = 11, }, |
Lennert Buytenhek | 5dfd3e2 | 2009-10-22 20:20:29 +0200 | [diff] [blame] | 320 | { .bitrate = 110, .hw_value = 22, }, |
| 321 | { .bitrate = 220, .hw_value = 44, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 322 | { .bitrate = 60, .hw_value = 12, }, |
| 323 | { .bitrate = 90, .hw_value = 18, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 324 | { .bitrate = 120, .hw_value = 24, }, |
| 325 | { .bitrate = 180, .hw_value = 36, }, |
| 326 | { .bitrate = 240, .hw_value = 48, }, |
| 327 | { .bitrate = 360, .hw_value = 72, }, |
| 328 | { .bitrate = 480, .hw_value = 96, }, |
| 329 | { .bitrate = 540, .hw_value = 108, }, |
Lennert Buytenhek | 140eb5e | 2009-11-30 18:11:44 +0100 | [diff] [blame] | 330 | { .bitrate = 720, .hw_value = 144, }, |
| 331 | }; |
| 332 | |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 333 | static const struct ieee80211_channel mwl8k_channels_50[] = { |
| 334 | { .center_freq = 5180, .hw_value = 36, }, |
| 335 | { .center_freq = 5200, .hw_value = 40, }, |
| 336 | { .center_freq = 5220, .hw_value = 44, }, |
| 337 | { .center_freq = 5240, .hw_value = 48, }, |
| 338 | }; |
| 339 | |
| 340 | static const struct ieee80211_rate mwl8k_rates_50[] = { |
| 341 | { .bitrate = 60, .hw_value = 12, }, |
| 342 | { .bitrate = 90, .hw_value = 18, }, |
| 343 | { .bitrate = 120, .hw_value = 24, }, |
| 344 | { .bitrate = 180, .hw_value = 36, }, |
| 345 | { .bitrate = 240, .hw_value = 48, }, |
| 346 | { .bitrate = 360, .hw_value = 72, }, |
| 347 | { .bitrate = 480, .hw_value = 96, }, |
| 348 | { .bitrate = 540, .hw_value = 108, }, |
| 349 | { .bitrate = 720, .hw_value = 144, }, |
| 350 | }; |
| 351 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 352 | /* Set or get info from Firmware */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 353 | #define MWL8K_CMD_GET 0x0000 |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 354 | #define MWL8K_CMD_SET 0x0001 |
| 355 | #define MWL8K_CMD_SET_LIST 0x0002 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 356 | |
| 357 | /* Firmware command codes */ |
| 358 | #define MWL8K_CMD_CODE_DNLD 0x0001 |
| 359 | #define MWL8K_CMD_GET_HW_SPEC 0x0003 |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 360 | #define MWL8K_CMD_SET_HW_SPEC 0x0004 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 361 | #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010 |
| 362 | #define MWL8K_CMD_GET_STAT 0x0014 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 363 | #define MWL8K_CMD_RADIO_CONTROL 0x001c |
| 364 | #define MWL8K_CMD_RF_TX_POWER 0x001e |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 365 | #define MWL8K_CMD_TX_POWER 0x001f |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 366 | #define MWL8K_CMD_RF_ANTENNA 0x0020 |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 367 | #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 368 | #define MWL8K_CMD_SET_PRE_SCAN 0x0107 |
| 369 | #define MWL8K_CMD_SET_POST_SCAN 0x0108 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 370 | #define MWL8K_CMD_SET_RF_CHANNEL 0x010a |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 371 | #define MWL8K_CMD_SET_AID 0x010d |
| 372 | #define MWL8K_CMD_SET_RATE 0x0110 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 373 | #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 374 | #define MWL8K_CMD_RTS_THRESHOLD 0x0113 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 375 | #define MWL8K_CMD_SET_SLOT 0x0114 |
| 376 | #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115 |
| 377 | #define MWL8K_CMD_SET_WMM_MODE 0x0123 |
| 378 | #define MWL8K_CMD_MIMO_CONFIG 0x0125 |
| 379 | #define MWL8K_CMD_USE_FIXED_RATE 0x0126 |
| 380 | #define MWL8K_CMD_ENABLE_SNIFFER 0x0150 |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 381 | #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */ |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 382 | #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203 |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 383 | #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205 |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 384 | #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */ |
| 385 | #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */ |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 386 | #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */ |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 387 | #define MWL8K_CMD_UPDATE_STADB 0x1123 |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 388 | #define MWL8K_CMD_BASTREAM 0x1125 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 389 | |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 390 | static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 391 | { |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 392 | u16 command = le16_to_cpu(cmd); |
| 393 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 394 | #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\ |
| 395 | snprintf(buf, bufsize, "%s", #x);\ |
| 396 | return buf;\ |
| 397 | } while (0) |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 398 | switch (command & ~0x8000) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 399 | MWL8K_CMDNAME(CODE_DNLD); |
| 400 | MWL8K_CMDNAME(GET_HW_SPEC); |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 401 | MWL8K_CMDNAME(SET_HW_SPEC); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 402 | MWL8K_CMDNAME(MAC_MULTICAST_ADR); |
| 403 | MWL8K_CMDNAME(GET_STAT); |
| 404 | MWL8K_CMDNAME(RADIO_CONTROL); |
| 405 | MWL8K_CMDNAME(RF_TX_POWER); |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 406 | MWL8K_CMDNAME(TX_POWER); |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 407 | MWL8K_CMDNAME(RF_ANTENNA); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 408 | MWL8K_CMDNAME(SET_BEACON); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 409 | MWL8K_CMDNAME(SET_PRE_SCAN); |
| 410 | MWL8K_CMDNAME(SET_POST_SCAN); |
| 411 | MWL8K_CMDNAME(SET_RF_CHANNEL); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 412 | MWL8K_CMDNAME(SET_AID); |
| 413 | MWL8K_CMDNAME(SET_RATE); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 414 | MWL8K_CMDNAME(SET_FINALIZE_JOIN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 415 | MWL8K_CMDNAME(RTS_THRESHOLD); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 416 | MWL8K_CMDNAME(SET_SLOT); |
| 417 | MWL8K_CMDNAME(SET_EDCA_PARAMS); |
| 418 | MWL8K_CMDNAME(SET_WMM_MODE); |
| 419 | MWL8K_CMDNAME(MIMO_CONFIG); |
| 420 | MWL8K_CMDNAME(USE_FIXED_RATE); |
| 421 | MWL8K_CMDNAME(ENABLE_SNIFFER); |
Lennert Buytenhek | 32060e1 | 2009-10-22 20:20:04 +0200 | [diff] [blame] | 422 | MWL8K_CMDNAME(SET_MAC_ADDR); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 423 | MWL8K_CMDNAME(SET_RATEADAPT_MODE); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 424 | MWL8K_CMDNAME(BSS_START); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 425 | MWL8K_CMDNAME(SET_NEW_STN); |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 426 | MWL8K_CMDNAME(UPDATE_ENCRYPTION); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 427 | MWL8K_CMDNAME(UPDATE_STADB); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 428 | MWL8K_CMDNAME(BASTREAM); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 429 | MWL8K_CMDNAME(GET_WATCHDOG_BITMAP); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 430 | default: |
| 431 | snprintf(buf, bufsize, "0x%x", cmd); |
| 432 | } |
| 433 | #undef MWL8K_CMDNAME |
| 434 | |
| 435 | return buf; |
| 436 | } |
| 437 | |
| 438 | /* Hardware and firmware reset */ |
| 439 | static void mwl8k_hw_reset(struct mwl8k_priv *priv) |
| 440 | { |
| 441 | iowrite32(MWL8K_H2A_INT_RESET, |
| 442 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 443 | iowrite32(MWL8K_H2A_INT_RESET, |
| 444 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 445 | msleep(20); |
| 446 | } |
| 447 | |
| 448 | /* Release fw image */ |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 449 | static void mwl8k_release_fw(const struct firmware **fw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 450 | { |
| 451 | if (*fw == NULL) |
| 452 | return; |
| 453 | release_firmware(*fw); |
| 454 | *fw = NULL; |
| 455 | } |
| 456 | |
| 457 | static void mwl8k_release_firmware(struct mwl8k_priv *priv) |
| 458 | { |
Lennert Buytenhek | 22be40d | 2009-11-30 18:32:38 +0100 | [diff] [blame] | 459 | mwl8k_release_fw(&priv->fw_ucode); |
| 460 | mwl8k_release_fw(&priv->fw_helper); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 463 | /* states for asynchronous f/w loading */ |
| 464 | static void mwl8k_fw_state_machine(const struct firmware *fw, void *context); |
| 465 | enum { |
| 466 | FW_STATE_INIT = 0, |
| 467 | FW_STATE_LOADING_PREF, |
| 468 | FW_STATE_LOADING_ALT, |
| 469 | FW_STATE_ERROR, |
| 470 | }; |
| 471 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 472 | /* Request fw image */ |
| 473 | static int mwl8k_request_fw(struct mwl8k_priv *priv, |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 474 | const char *fname, const struct firmware **fw, |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 475 | bool nowait) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 476 | { |
| 477 | /* release current image */ |
| 478 | if (*fw != NULL) |
| 479 | mwl8k_release_fw(fw); |
| 480 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 481 | if (nowait) |
| 482 | return request_firmware_nowait(THIS_MODULE, 1, fname, |
| 483 | &priv->pdev->dev, GFP_KERNEL, |
| 484 | priv, mwl8k_fw_state_machine); |
| 485 | else |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 486 | return request_firmware(fw, fname, &priv->pdev->dev); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 487 | } |
| 488 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 489 | static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image, |
| 490 | bool nowait) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 491 | { |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 492 | struct mwl8k_device_info *di = priv->device_info; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 493 | int rc; |
| 494 | |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 495 | if (di->helper_image != NULL) { |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 496 | if (nowait) |
| 497 | rc = mwl8k_request_fw(priv, di->helper_image, |
| 498 | &priv->fw_helper, true); |
| 499 | else |
| 500 | rc = mwl8k_request_fw(priv, di->helper_image, |
| 501 | &priv->fw_helper, false); |
| 502 | if (rc) |
| 503 | printk(KERN_ERR "%s: Error requesting helper fw %s\n", |
| 504 | pci_name(priv->pdev), di->helper_image); |
| 505 | |
| 506 | if (rc || nowait) |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 507 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 510 | if (nowait) { |
| 511 | /* |
| 512 | * if we get here, no helper image is needed. Skip the |
| 513 | * FW_STATE_INIT state. |
| 514 | */ |
| 515 | priv->fw_state = FW_STATE_LOADING_PREF; |
| 516 | rc = mwl8k_request_fw(priv, fw_image, |
| 517 | &priv->fw_ucode, |
| 518 | true); |
| 519 | } else |
| 520 | rc = mwl8k_request_fw(priv, fw_image, |
| 521 | &priv->fw_ucode, false); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 522 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 523 | printk(KERN_ERR "%s: Error requesting firmware file %s\n", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 524 | pci_name(priv->pdev), fw_image); |
Lennert Buytenhek | 22be40d | 2009-11-30 18:32:38 +0100 | [diff] [blame] | 525 | mwl8k_release_fw(&priv->fw_helper); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 526 | return rc; |
| 527 | } |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | struct mwl8k_cmd_pkt { |
| 533 | __le16 code; |
| 534 | __le16 length; |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 535 | __u8 seq_num; |
| 536 | __u8 macid; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 537 | __le16 result; |
| 538 | char payload[0]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 539 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 540 | |
| 541 | /* |
| 542 | * Firmware loading. |
| 543 | */ |
| 544 | static int |
| 545 | mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length) |
| 546 | { |
| 547 | void __iomem *regs = priv->regs; |
| 548 | dma_addr_t dma_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 549 | int loops; |
| 550 | |
| 551 | dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE); |
| 552 | if (pci_dma_mapping_error(priv->pdev, dma_addr)) |
| 553 | return -ENOMEM; |
| 554 | |
| 555 | iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR); |
| 556 | iowrite32(0, regs + MWL8K_HIU_INT_CODE); |
| 557 | iowrite32(MWL8K_H2A_INT_DOORBELL, |
| 558 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 559 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 560 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 561 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 562 | loops = 1000; |
| 563 | do { |
| 564 | u32 int_code; |
| 565 | |
| 566 | int_code = ioread32(regs + MWL8K_HIU_INT_CODE); |
| 567 | if (int_code == MWL8K_INT_CODE_CMD_FINISHED) { |
| 568 | iowrite32(0, regs + MWL8K_HIU_INT_CODE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 569 | break; |
| 570 | } |
| 571 | |
Lennert Buytenhek | 3d76e82 | 2009-10-22 20:20:16 +0200 | [diff] [blame] | 572 | cond_resched(); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 573 | udelay(1); |
| 574 | } while (--loops); |
| 575 | |
| 576 | pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE); |
| 577 | |
Lennert Buytenhek | d4b70570 | 2009-07-16 12:44:45 +0200 | [diff] [blame] | 578 | return loops ? 0 : -ETIMEDOUT; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static int mwl8k_load_fw_image(struct mwl8k_priv *priv, |
| 582 | const u8 *data, size_t length) |
| 583 | { |
| 584 | struct mwl8k_cmd_pkt *cmd; |
| 585 | int done; |
| 586 | int rc = 0; |
| 587 | |
| 588 | cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL); |
| 589 | if (cmd == NULL) |
| 590 | return -ENOMEM; |
| 591 | |
| 592 | cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD); |
| 593 | cmd->seq_num = 0; |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 594 | cmd->macid = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 595 | cmd->result = 0; |
| 596 | |
| 597 | done = 0; |
| 598 | while (length) { |
| 599 | int block_size = length > 256 ? 256 : length; |
| 600 | |
| 601 | memcpy(cmd->payload, data + done, block_size); |
| 602 | cmd->length = cpu_to_le16(block_size); |
| 603 | |
| 604 | rc = mwl8k_send_fw_load_cmd(priv, cmd, |
| 605 | sizeof(*cmd) + block_size); |
| 606 | if (rc) |
| 607 | break; |
| 608 | |
| 609 | done += block_size; |
| 610 | length -= block_size; |
| 611 | } |
| 612 | |
| 613 | if (!rc) { |
| 614 | cmd->length = 0; |
| 615 | rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd)); |
| 616 | } |
| 617 | |
| 618 | kfree(cmd); |
| 619 | |
| 620 | return rc; |
| 621 | } |
| 622 | |
| 623 | static int mwl8k_feed_fw_image(struct mwl8k_priv *priv, |
| 624 | const u8 *data, size_t length) |
| 625 | { |
| 626 | unsigned char *buffer; |
| 627 | int may_continue, rc = 0; |
| 628 | u32 done, prev_block_size; |
| 629 | |
| 630 | buffer = kmalloc(1024, GFP_KERNEL); |
| 631 | if (buffer == NULL) |
| 632 | return -ENOMEM; |
| 633 | |
| 634 | done = 0; |
| 635 | prev_block_size = 0; |
| 636 | may_continue = 1000; |
| 637 | while (may_continue > 0) { |
| 638 | u32 block_size; |
| 639 | |
| 640 | block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH); |
| 641 | if (block_size & 1) { |
| 642 | block_size &= ~1; |
| 643 | may_continue--; |
| 644 | } else { |
| 645 | done += prev_block_size; |
| 646 | length -= prev_block_size; |
| 647 | } |
| 648 | |
| 649 | if (block_size > 1024 || block_size > length) { |
| 650 | rc = -EOVERFLOW; |
| 651 | break; |
| 652 | } |
| 653 | |
| 654 | if (length == 0) { |
| 655 | rc = 0; |
| 656 | break; |
| 657 | } |
| 658 | |
| 659 | if (block_size == 0) { |
| 660 | rc = -EPROTO; |
| 661 | may_continue--; |
| 662 | udelay(1); |
| 663 | continue; |
| 664 | } |
| 665 | |
| 666 | prev_block_size = block_size; |
| 667 | memcpy(buffer, data + done, block_size); |
| 668 | |
| 669 | rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size); |
| 670 | if (rc) |
| 671 | break; |
| 672 | } |
| 673 | |
| 674 | if (!rc && length != 0) |
| 675 | rc = -EREMOTEIO; |
| 676 | |
| 677 | kfree(buffer); |
| 678 | |
| 679 | return rc; |
| 680 | } |
| 681 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 682 | static int mwl8k_load_firmware(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 683 | { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 684 | struct mwl8k_priv *priv = hw->priv; |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 685 | const struct firmware *fw = priv->fw_ucode; |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 686 | int rc; |
| 687 | int loops; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 688 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 689 | if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) { |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 690 | const struct firmware *helper = priv->fw_helper; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 691 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 692 | if (helper == NULL) { |
| 693 | printk(KERN_ERR "%s: helper image needed but none " |
| 694 | "given\n", pci_name(priv->pdev)); |
| 695 | return -EINVAL; |
| 696 | } |
| 697 | |
| 698 | rc = mwl8k_load_fw_image(priv, helper->data, helper->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 699 | if (rc) { |
| 700 | printk(KERN_ERR "%s: unable to load firmware " |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 701 | "helper image\n", pci_name(priv->pdev)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 702 | return rc; |
| 703 | } |
Lennert Buytenhek | 89b872e | 2009-11-30 18:13:20 +0100 | [diff] [blame] | 704 | msleep(5); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 705 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 706 | rc = mwl8k_feed_fw_image(priv, fw->data, fw->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 707 | } else { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 708 | rc = mwl8k_load_fw_image(priv, fw->data, fw->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 712 | printk(KERN_ERR "%s: unable to load firmware image\n", |
| 713 | pci_name(priv->pdev)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 714 | return rc; |
| 715 | } |
| 716 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 717 | iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 718 | |
Lennert Buytenhek | 89b872e | 2009-11-30 18:13:20 +0100 | [diff] [blame] | 719 | loops = 500000; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 720 | do { |
Lennert Buytenhek | eae74e6 | 2009-10-22 20:20:53 +0200 | [diff] [blame] | 721 | u32 ready_code; |
| 722 | |
| 723 | ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE); |
| 724 | if (ready_code == MWL8K_FWAP_READY) { |
| 725 | priv->ap_fw = 1; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 726 | break; |
Lennert Buytenhek | eae74e6 | 2009-10-22 20:20:53 +0200 | [diff] [blame] | 727 | } else if (ready_code == MWL8K_FWSTA_READY) { |
| 728 | priv->ap_fw = 0; |
| 729 | break; |
| 730 | } |
| 731 | |
| 732 | cond_resched(); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 733 | udelay(1); |
| 734 | } while (--loops); |
| 735 | |
| 736 | return loops ? 0 : -ETIMEDOUT; |
| 737 | } |
| 738 | |
| 739 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 740 | /* DMA header used by firmware and hardware. */ |
| 741 | struct mwl8k_dma_data { |
| 742 | __le16 fwlen; |
| 743 | struct ieee80211_hdr wh; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 744 | char data[0]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 745 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 746 | |
| 747 | /* Routines to add/remove DMA header from skb. */ |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 748 | static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 749 | { |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 750 | struct mwl8k_dma_data *tr; |
| 751 | int hdrlen; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 752 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 753 | tr = (struct mwl8k_dma_data *)skb->data; |
| 754 | hdrlen = ieee80211_hdrlen(tr->wh.frame_control); |
| 755 | |
| 756 | if (hdrlen != sizeof(tr->wh)) { |
| 757 | if (ieee80211_is_data_qos(tr->wh.frame_control)) { |
| 758 | memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2); |
| 759 | *((__le16 *)(tr->data - 2)) = qos; |
| 760 | } else { |
| 761 | memmove(tr->data - hdrlen, &tr->wh, hdrlen); |
| 762 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 763 | } |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 764 | |
| 765 | if (hdrlen != sizeof(*tr)) |
| 766 | skb_pull(skb, sizeof(*tr) - hdrlen); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 767 | } |
| 768 | |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 769 | static void |
| 770 | mwl8k_add_dma_header(struct sk_buff *skb, int tail_pad) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 771 | { |
| 772 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 773 | int hdrlen; |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 774 | int reqd_hdrlen; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 775 | struct mwl8k_dma_data *tr; |
| 776 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 777 | /* |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 778 | * Add a firmware DMA header; the firmware requires that we |
| 779 | * present a 2-byte payload length followed by a 4-address |
| 780 | * header (without QoS field), followed (optionally) by any |
| 781 | * WEP/ExtIV header (but only filled in for CCMP). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 782 | */ |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 783 | wh = (struct ieee80211_hdr *)skb->data; |
| 784 | |
| 785 | hdrlen = ieee80211_hdrlen(wh->frame_control); |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 786 | reqd_hdrlen = sizeof(*tr); |
| 787 | |
| 788 | if (hdrlen != reqd_hdrlen) |
| 789 | skb_push(skb, reqd_hdrlen - hdrlen); |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 790 | |
| 791 | if (ieee80211_is_data_qos(wh->frame_control)) |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 792 | hdrlen -= IEEE80211_QOS_CTL_LEN; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 793 | |
| 794 | tr = (struct mwl8k_dma_data *)skb->data; |
| 795 | if (wh != &tr->wh) |
| 796 | memmove(&tr->wh, wh, hdrlen); |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 797 | if (hdrlen != sizeof(tr->wh)) |
| 798 | memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 799 | |
| 800 | /* |
| 801 | * Firmware length is the length of the fully formed "802.11 |
| 802 | * payload". That is, everything except for the 802.11 header. |
| 803 | * This includes all crypto material including the MIC. |
| 804 | */ |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 805 | tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 806 | } |
| 807 | |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 808 | static void mwl8k_encapsulate_tx_frame(struct sk_buff *skb) |
| 809 | { |
| 810 | struct ieee80211_hdr *wh; |
| 811 | struct ieee80211_tx_info *tx_info; |
| 812 | struct ieee80211_key_conf *key_conf; |
| 813 | int data_pad; |
| 814 | |
| 815 | wh = (struct ieee80211_hdr *)skb->data; |
| 816 | |
| 817 | tx_info = IEEE80211_SKB_CB(skb); |
| 818 | |
| 819 | key_conf = NULL; |
| 820 | if (ieee80211_is_data(wh->frame_control)) |
| 821 | key_conf = tx_info->control.hw_key; |
| 822 | |
| 823 | /* |
| 824 | * Make sure the packet header is in the DMA header format (4-address |
| 825 | * without QoS), the necessary crypto padding between the header and the |
| 826 | * payload has already been provided by mac80211, but it doesn't add tail |
| 827 | * padding when HW crypto is enabled. |
| 828 | * |
| 829 | * We have the following trailer padding requirements: |
| 830 | * - WEP: 4 trailer bytes (ICV) |
| 831 | * - TKIP: 12 trailer bytes (8 MIC + 4 ICV) |
| 832 | * - CCMP: 8 trailer bytes (MIC) |
| 833 | */ |
| 834 | data_pad = 0; |
| 835 | if (key_conf != NULL) { |
| 836 | switch (key_conf->cipher) { |
| 837 | case WLAN_CIPHER_SUITE_WEP40: |
| 838 | case WLAN_CIPHER_SUITE_WEP104: |
| 839 | data_pad = 4; |
| 840 | break; |
| 841 | case WLAN_CIPHER_SUITE_TKIP: |
| 842 | data_pad = 12; |
| 843 | break; |
| 844 | case WLAN_CIPHER_SUITE_CCMP: |
| 845 | data_pad = 8; |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | mwl8k_add_dma_header(skb, data_pad); |
| 850 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 851 | |
| 852 | /* |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 853 | * Packet reception for 88w8366 AP firmware. |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 854 | */ |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 855 | struct mwl8k_rxd_8366_ap { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 856 | __le16 pkt_len; |
| 857 | __u8 sq2; |
| 858 | __u8 rate; |
| 859 | __le32 pkt_phys_addr; |
| 860 | __le32 next_rxd_phys_addr; |
| 861 | __le16 qos_control; |
| 862 | __le16 htsig2; |
| 863 | __le32 hw_rssi_info; |
| 864 | __le32 hw_noise_floor_info; |
| 865 | __u8 noise_floor; |
| 866 | __u8 pad0[3]; |
| 867 | __u8 rssi; |
| 868 | __u8 rx_status; |
| 869 | __u8 channel; |
| 870 | __u8 rx_ctrl; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 871 | } __packed; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 872 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 873 | #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80 |
| 874 | #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40 |
| 875 | #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f) |
Lennert Buytenhek | 8e9f33f | 2009-11-30 18:12:35 +0100 | [diff] [blame] | 876 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 877 | #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80 |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 878 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 879 | /* 8366 AP rx_status bits */ |
| 880 | #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80 |
| 881 | #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF |
| 882 | #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02 |
| 883 | #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04 |
| 884 | #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08 |
| 885 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 886 | static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 887 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 888 | struct mwl8k_rxd_8366_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 889 | |
| 890 | rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr); |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 891 | rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 894 | static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 895 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 896 | struct mwl8k_rxd_8366_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 897 | |
| 898 | rxd->pkt_len = cpu_to_le16(len); |
| 899 | rxd->pkt_phys_addr = cpu_to_le32(addr); |
| 900 | wmb(); |
| 901 | rxd->rx_ctrl = 0; |
| 902 | } |
| 903 | |
| 904 | static int |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 905 | mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 906 | __le16 *qos, s8 *noise) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 907 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 908 | struct mwl8k_rxd_8366_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 909 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 910 | if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST)) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 911 | return -1; |
| 912 | rmb(); |
| 913 | |
| 914 | memset(status, 0, sizeof(*status)); |
| 915 | |
| 916 | status->signal = -rxd->rssi; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 917 | *noise = -rxd->noise_floor; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 918 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 919 | if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 920 | status->flag |= RX_FLAG_HT; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 921 | if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ) |
Lennert Buytenhek | 8e9f33f | 2009-11-30 18:12:35 +0100 | [diff] [blame] | 922 | status->flag |= RX_FLAG_40MHZ; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 923 | status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate); |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 924 | } else { |
| 925 | int i; |
| 926 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 927 | for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) { |
| 928 | if (mwl8k_rates_24[i].hw_value == rxd->rate) { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 929 | status->rate_idx = i; |
| 930 | break; |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | |
Lennert Buytenhek | 8547834 | 2010-01-12 13:48:56 +0100 | [diff] [blame] | 935 | if (rxd->channel > 14) { |
| 936 | status->band = IEEE80211_BAND_5GHZ; |
| 937 | if (!(status->flag & RX_FLAG_HT)) |
| 938 | status->rate_idx -= 5; |
| 939 | } else { |
| 940 | status->band = IEEE80211_BAND_2GHZ; |
| 941 | } |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 942 | status->freq = ieee80211_channel_to_frequency(rxd->channel, |
| 943 | status->band); |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 944 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 945 | *qos = rxd->qos_control; |
| 946 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 947 | if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) && |
| 948 | (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) && |
| 949 | (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR)) |
| 950 | status->flag |= RX_FLAG_MMIC_ERROR; |
| 951 | |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 952 | return le16_to_cpu(rxd->pkt_len); |
| 953 | } |
| 954 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 955 | static struct rxd_ops rxd_8366_ap_ops = { |
| 956 | .rxd_size = sizeof(struct mwl8k_rxd_8366_ap), |
| 957 | .rxd_init = mwl8k_rxd_8366_ap_init, |
| 958 | .rxd_refill = mwl8k_rxd_8366_ap_refill, |
| 959 | .rxd_process = mwl8k_rxd_8366_ap_process, |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 960 | }; |
| 961 | |
| 962 | /* |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 963 | * Packet reception for STA firmware. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 964 | */ |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 965 | struct mwl8k_rxd_sta { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 966 | __le16 pkt_len; |
| 967 | __u8 link_quality; |
| 968 | __u8 noise_level; |
| 969 | __le32 pkt_phys_addr; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 970 | __le32 next_rxd_phys_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 971 | __le16 qos_control; |
| 972 | __le16 rate_info; |
| 973 | __le32 pad0[4]; |
| 974 | __u8 rssi; |
| 975 | __u8 channel; |
| 976 | __le16 pad1; |
| 977 | __u8 rx_ctrl; |
| 978 | __u8 rx_status; |
| 979 | __u8 pad2[2]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 980 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 981 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 982 | #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000 |
| 983 | #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3) |
| 984 | #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f) |
| 985 | #define MWL8K_STA_RATE_INFO_40MHZ 0x0004 |
| 986 | #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002 |
| 987 | #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001 |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 988 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 989 | #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02 |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 990 | #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04 |
| 991 | /* ICV=0 or MIC=1 */ |
| 992 | #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08 |
| 993 | /* Key is uploaded only in failure case */ |
| 994 | #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30 |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 995 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 996 | static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 997 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 998 | struct mwl8k_rxd_sta *rxd = _rxd; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 999 | |
| 1000 | rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr); |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1001 | rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1004 | static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1005 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1006 | struct mwl8k_rxd_sta *rxd = _rxd; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1007 | |
| 1008 | rxd->pkt_len = cpu_to_le16(len); |
| 1009 | rxd->pkt_phys_addr = cpu_to_le32(addr); |
| 1010 | wmb(); |
| 1011 | rxd->rx_ctrl = 0; |
| 1012 | } |
| 1013 | |
| 1014 | static int |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1015 | mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1016 | __le16 *qos, s8 *noise) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1017 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1018 | struct mwl8k_rxd_sta *rxd = _rxd; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1019 | u16 rate_info; |
| 1020 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1021 | if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST)) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1022 | return -1; |
| 1023 | rmb(); |
| 1024 | |
| 1025 | rate_info = le16_to_cpu(rxd->rate_info); |
| 1026 | |
| 1027 | memset(status, 0, sizeof(*status)); |
| 1028 | |
| 1029 | status->signal = -rxd->rssi; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1030 | *noise = -rxd->noise_level; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1031 | status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info); |
| 1032 | status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1033 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1034 | if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1035 | status->flag |= RX_FLAG_SHORTPRE; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1036 | if (rate_info & MWL8K_STA_RATE_INFO_40MHZ) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1037 | status->flag |= RX_FLAG_40MHZ; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1038 | if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1039 | status->flag |= RX_FLAG_SHORT_GI; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1040 | if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1041 | status->flag |= RX_FLAG_HT; |
| 1042 | |
Lennert Buytenhek | 8547834 | 2010-01-12 13:48:56 +0100 | [diff] [blame] | 1043 | if (rxd->channel > 14) { |
| 1044 | status->band = IEEE80211_BAND_5GHZ; |
| 1045 | if (!(status->flag & RX_FLAG_HT)) |
| 1046 | status->rate_idx -= 5; |
| 1047 | } else { |
| 1048 | status->band = IEEE80211_BAND_2GHZ; |
| 1049 | } |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 1050 | status->freq = ieee80211_channel_to_frequency(rxd->channel, |
| 1051 | status->band); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1052 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1053 | *qos = rxd->qos_control; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1054 | if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) && |
| 1055 | (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE)) |
| 1056 | status->flag |= RX_FLAG_MMIC_ERROR; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1057 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1058 | return le16_to_cpu(rxd->pkt_len); |
| 1059 | } |
| 1060 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1061 | static struct rxd_ops rxd_sta_ops = { |
| 1062 | .rxd_size = sizeof(struct mwl8k_rxd_sta), |
| 1063 | .rxd_init = mwl8k_rxd_sta_init, |
| 1064 | .rxd_refill = mwl8k_rxd_sta_refill, |
| 1065 | .rxd_process = mwl8k_rxd_sta_process, |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1066 | }; |
| 1067 | |
| 1068 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1069 | #define MWL8K_RX_DESCS 256 |
| 1070 | #define MWL8K_RX_MAXSZ 3800 |
| 1071 | |
| 1072 | static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index) |
| 1073 | { |
| 1074 | struct mwl8k_priv *priv = hw->priv; |
| 1075 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1076 | int size; |
| 1077 | int i; |
| 1078 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1079 | rxq->rxd_count = 0; |
| 1080 | rxq->head = 0; |
| 1081 | rxq->tail = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1082 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1083 | size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1084 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1085 | rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma); |
| 1086 | if (rxq->rxd == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1087 | wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1088 | return -ENOMEM; |
| 1089 | } |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1090 | memset(rxq->rxd, 0, size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1091 | |
Shan Wei | b9ede5f | 2011-03-08 11:02:03 +0800 | [diff] [blame] | 1092 | rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL); |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1093 | if (rxq->buf == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1094 | wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n"); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1095 | pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1096 | return -ENOMEM; |
| 1097 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1098 | |
| 1099 | for (i = 0; i < MWL8K_RX_DESCS; i++) { |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1100 | int desc_size; |
| 1101 | void *rxd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1102 | int nexti; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1103 | dma_addr_t next_dma_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1104 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1105 | desc_size = priv->rxd_ops->rxd_size; |
| 1106 | rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1107 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1108 | nexti = i + 1; |
| 1109 | if (nexti == MWL8K_RX_DESCS) |
| 1110 | nexti = 0; |
| 1111 | next_dma_addr = rxq->rxd_dma + (nexti * desc_size); |
| 1112 | |
| 1113 | priv->rxd_ops->rxd_init(rxd, next_dma_addr); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | static int rxq_refill(struct ieee80211_hw *hw, int index, int limit) |
| 1120 | { |
| 1121 | struct mwl8k_priv *priv = hw->priv; |
| 1122 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1123 | int refilled; |
| 1124 | |
| 1125 | refilled = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1126 | while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1127 | struct sk_buff *skb; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1128 | dma_addr_t addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1129 | int rx; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1130 | void *rxd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1131 | |
| 1132 | skb = dev_alloc_skb(MWL8K_RX_MAXSZ); |
| 1133 | if (skb == NULL) |
| 1134 | break; |
| 1135 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1136 | addr = pci_map_single(priv->pdev, skb->data, |
| 1137 | MWL8K_RX_MAXSZ, DMA_FROM_DEVICE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1138 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1139 | rxq->rxd_count++; |
| 1140 | rx = rxq->tail++; |
| 1141 | if (rxq->tail == MWL8K_RX_DESCS) |
| 1142 | rxq->tail = 0; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1143 | rxq->buf[rx].skb = skb; |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1144 | dma_unmap_addr_set(&rxq->buf[rx], dma, addr); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1145 | |
| 1146 | rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size); |
| 1147 | priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1148 | |
| 1149 | refilled++; |
| 1150 | } |
| 1151 | |
| 1152 | return refilled; |
| 1153 | } |
| 1154 | |
| 1155 | /* Must be called only when the card's reception is completely halted */ |
| 1156 | static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index) |
| 1157 | { |
| 1158 | struct mwl8k_priv *priv = hw->priv; |
| 1159 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1160 | int i; |
| 1161 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 1162 | if (rxq->rxd == NULL) |
| 1163 | return; |
| 1164 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1165 | for (i = 0; i < MWL8K_RX_DESCS; i++) { |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1166 | if (rxq->buf[i].skb != NULL) { |
| 1167 | pci_unmap_single(priv->pdev, |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1168 | dma_unmap_addr(&rxq->buf[i], dma), |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1169 | MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1170 | dma_unmap_addr_set(&rxq->buf[i], dma, 0); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1171 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1172 | kfree_skb(rxq->buf[i].skb); |
| 1173 | rxq->buf[i].skb = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1177 | kfree(rxq->buf); |
| 1178 | rxq->buf = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1179 | |
| 1180 | pci_free_consistent(priv->pdev, |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1181 | MWL8K_RX_DESCS * priv->rxd_ops->rxd_size, |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1182 | rxq->rxd, rxq->rxd_dma); |
| 1183 | rxq->rxd = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | /* |
| 1188 | * Scan a list of BSSIDs to process for finalize join. |
| 1189 | * Allows for extension to process multiple BSSIDs. |
| 1190 | */ |
| 1191 | static inline int |
| 1192 | mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh) |
| 1193 | { |
| 1194 | return priv->capture_beacon && |
| 1195 | ieee80211_is_beacon(wh->frame_control) && |
| 1196 | !compare_ether_addr(wh->addr3, priv->capture_bssid); |
| 1197 | } |
| 1198 | |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1199 | static inline void mwl8k_save_beacon(struct ieee80211_hw *hw, |
| 1200 | struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1201 | { |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1202 | struct mwl8k_priv *priv = hw->priv; |
| 1203 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1204 | priv->capture_beacon = false; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1205 | memset(priv->capture_bssid, 0, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1206 | |
| 1207 | /* |
| 1208 | * Use GFP_ATOMIC as rxq_process is called from |
| 1209 | * the primary interrupt handler, memory allocation call |
| 1210 | * must not sleep. |
| 1211 | */ |
| 1212 | priv->beacon_skb = skb_copy(skb, GFP_ATOMIC); |
| 1213 | if (priv->beacon_skb != NULL) |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1214 | ieee80211_queue_work(hw, &priv->finalize_join_worker); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1215 | } |
| 1216 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1217 | static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list, |
| 1218 | u8 *bssid) |
| 1219 | { |
| 1220 | struct mwl8k_vif *mwl8k_vif; |
| 1221 | |
| 1222 | list_for_each_entry(mwl8k_vif, |
| 1223 | vif_list, list) { |
| 1224 | if (memcmp(bssid, mwl8k_vif->bssid, |
| 1225 | ETH_ALEN) == 0) |
| 1226 | return mwl8k_vif; |
| 1227 | } |
| 1228 | |
| 1229 | return NULL; |
| 1230 | } |
| 1231 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1232 | static int rxq_process(struct ieee80211_hw *hw, int index, int limit) |
| 1233 | { |
| 1234 | struct mwl8k_priv *priv = hw->priv; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1235 | struct mwl8k_vif *mwl8k_vif = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1236 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1237 | int processed; |
| 1238 | |
| 1239 | processed = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1240 | while (rxq->rxd_count && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1241 | struct sk_buff *skb; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1242 | void *rxd; |
| 1243 | int pkt_len; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1244 | struct ieee80211_rx_status status; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1245 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1246 | __le16 qos; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1247 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1248 | skb = rxq->buf[rxq->head].skb; |
Lennert Buytenhek | d25f9f1 | 2009-08-03 21:58:26 +0200 | [diff] [blame] | 1249 | if (skb == NULL) |
| 1250 | break; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1251 | |
| 1252 | rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size); |
| 1253 | |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1254 | pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos, |
| 1255 | &priv->noise); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1256 | if (pkt_len < 0) |
| 1257 | break; |
| 1258 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1259 | rxq->buf[rxq->head].skb = NULL; |
| 1260 | |
| 1261 | pci_unmap_single(priv->pdev, |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1262 | dma_unmap_addr(&rxq->buf[rxq->head], dma), |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1263 | MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1264 | dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1265 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1266 | rxq->head++; |
| 1267 | if (rxq->head == MWL8K_RX_DESCS) |
| 1268 | rxq->head = 0; |
| 1269 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1270 | rxq->rxd_count--; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1271 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1272 | wh = &((struct mwl8k_dma_data *)skb->data)->wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1273 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1274 | /* |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1275 | * Check for a pending join operation. Save a |
| 1276 | * copy of the beacon and schedule a tasklet to |
| 1277 | * send a FINALIZE_JOIN command to the firmware. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1278 | */ |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1279 | if (mwl8k_capture_bssid(priv, (void *)skb->data)) |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1280 | mwl8k_save_beacon(hw, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1281 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1282 | if (ieee80211_has_protected(wh->frame_control)) { |
| 1283 | |
| 1284 | /* Check if hw crypto has been enabled for |
| 1285 | * this bss. If yes, set the status flags |
| 1286 | * accordingly |
| 1287 | */ |
| 1288 | mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list, |
| 1289 | wh->addr1); |
| 1290 | |
| 1291 | if (mwl8k_vif != NULL && |
| 1292 | mwl8k_vif->is_hw_crypto_enabled == true) { |
| 1293 | /* |
| 1294 | * When MMIC ERROR is encountered |
| 1295 | * by the firmware, payload is |
| 1296 | * dropped and only 32 bytes of |
| 1297 | * mwl8k Firmware header is sent |
| 1298 | * to the host. |
| 1299 | * |
| 1300 | * We need to add four bytes of |
| 1301 | * key information. In it |
| 1302 | * MAC80211 expects keyidx set to |
| 1303 | * 0 for triggering Counter |
| 1304 | * Measure of MMIC failure. |
| 1305 | */ |
| 1306 | if (status.flag & RX_FLAG_MMIC_ERROR) { |
| 1307 | struct mwl8k_dma_data *tr; |
| 1308 | tr = (struct mwl8k_dma_data *)skb->data; |
| 1309 | memset((void *)&(tr->data), 0, 4); |
| 1310 | pkt_len += 4; |
| 1311 | } |
| 1312 | |
| 1313 | if (!ieee80211_is_auth(wh->frame_control)) |
| 1314 | status.flag |= RX_FLAG_IV_STRIPPED | |
| 1315 | RX_FLAG_DECRYPTED | |
| 1316 | RX_FLAG_MMIC_STRIPPED; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | skb_put(skb, pkt_len); |
| 1321 | mwl8k_remove_dma_header(skb, qos); |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 1322 | memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); |
| 1323 | ieee80211_rx_irqsafe(hw, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1324 | |
| 1325 | processed++; |
| 1326 | } |
| 1327 | |
| 1328 | return processed; |
| 1329 | } |
| 1330 | |
| 1331 | |
| 1332 | /* |
| 1333 | * Packet transmission. |
| 1334 | */ |
| 1335 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1336 | #define MWL8K_TXD_STATUS_OK 0x00000001 |
| 1337 | #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002 |
| 1338 | #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004 |
| 1339 | #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1340 | #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1341 | |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1342 | #define MWL8K_QOS_QLEN_UNSPEC 0xff00 |
| 1343 | #define MWL8K_QOS_ACK_POLICY_MASK 0x0060 |
| 1344 | #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000 |
| 1345 | #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060 |
| 1346 | #define MWL8K_QOS_EOSP 0x0010 |
| 1347 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1348 | struct mwl8k_tx_desc { |
| 1349 | __le32 status; |
| 1350 | __u8 data_rate; |
| 1351 | __u8 tx_priority; |
| 1352 | __le16 qos_control; |
| 1353 | __le32 pkt_phys_addr; |
| 1354 | __le16 pkt_len; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1355 | __u8 dest_MAC_addr[ETH_ALEN]; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1356 | __le32 next_txd_phys_addr; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 1357 | __le32 timestamp; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1358 | __le16 rate_info; |
| 1359 | __u8 peer_id; |
Brian Cavagnolo | a1fe24b | 2010-11-12 17:23:47 -0800 | [diff] [blame] | 1360 | __u8 tx_frag_cnt; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 1361 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1362 | |
| 1363 | #define MWL8K_TX_DESCS 128 |
| 1364 | |
| 1365 | static int mwl8k_txq_init(struct ieee80211_hw *hw, int index) |
| 1366 | { |
| 1367 | struct mwl8k_priv *priv = hw->priv; |
| 1368 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1369 | int size; |
| 1370 | int i; |
| 1371 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1372 | txq->len = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1373 | txq->head = 0; |
| 1374 | txq->tail = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1375 | |
| 1376 | size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc); |
| 1377 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1378 | txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma); |
| 1379 | if (txq->txd == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1380 | wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1381 | return -ENOMEM; |
| 1382 | } |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1383 | memset(txq->txd, 0, size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1384 | |
Shan Wei | b9ede5f | 2011-03-08 11:02:03 +0800 | [diff] [blame] | 1385 | txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1386 | if (txq->skb == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1387 | wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n"); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1388 | pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1389 | return -ENOMEM; |
| 1390 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1391 | |
| 1392 | for (i = 0; i < MWL8K_TX_DESCS; i++) { |
| 1393 | struct mwl8k_tx_desc *tx_desc; |
| 1394 | int nexti; |
| 1395 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1396 | tx_desc = txq->txd + i; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1397 | nexti = (i + 1) % MWL8K_TX_DESCS; |
| 1398 | |
| 1399 | tx_desc->status = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1400 | tx_desc->next_txd_phys_addr = |
| 1401 | cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | static inline void mwl8k_tx_start(struct mwl8k_priv *priv) |
| 1408 | { |
| 1409 | iowrite32(MWL8K_H2A_INT_PPA_READY, |
| 1410 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1411 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 1412 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1413 | ioread32(priv->regs + MWL8K_HIU_INT_CODE); |
| 1414 | } |
| 1415 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1416 | static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1417 | { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1418 | struct mwl8k_priv *priv = hw->priv; |
| 1419 | int i; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1420 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 1421 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1422 | struct mwl8k_tx_queue *txq = priv->txq + i; |
| 1423 | int fw_owned = 0; |
| 1424 | int drv_owned = 0; |
| 1425 | int unused = 0; |
| 1426 | int desc; |
Lennert Buytenhek | c3f967d | 2009-08-18 04:15:22 +0200 | [diff] [blame] | 1427 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1428 | for (desc = 0; desc < MWL8K_TX_DESCS; desc++) { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1429 | struct mwl8k_tx_desc *tx_desc = txq->txd + desc; |
| 1430 | u32 status; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1431 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1432 | status = le32_to_cpu(tx_desc->status); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1433 | if (status & MWL8K_TXD_STATUS_FW_OWNED) |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1434 | fw_owned++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1435 | else |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1436 | drv_owned++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1437 | |
| 1438 | if (tx_desc->pkt_len == 0) |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1439 | unused++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1440 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1441 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1442 | wiphy_err(hw->wiphy, |
| 1443 | "txq[%d] len=%d head=%d tail=%d " |
| 1444 | "fw_owned=%d drv_owned=%d unused=%d\n", |
| 1445 | i, |
| 1446 | txq->len, txq->head, txq->tail, |
| 1447 | fw_owned, drv_owned, unused); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1448 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1449 | } |
| 1450 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1451 | /* |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 1452 | * Must be called with priv->fw_mutex held and tx queues stopped. |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1453 | */ |
Lennert Buytenhek | 62abd3c | 2010-01-08 18:28:34 +0100 | [diff] [blame] | 1454 | #define MWL8K_TX_WAIT_TIMEOUT_MS 5000 |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1455 | |
Lennert Buytenhek | 950d5b0 | 2009-07-17 01:48:41 +0200 | [diff] [blame] | 1456 | static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1457 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1458 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 1459 | DECLARE_COMPLETION_ONSTACK(tx_wait); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1460 | int retry; |
| 1461 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1462 | |
| 1463 | might_sleep(); |
| 1464 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1465 | /* |
| 1466 | * The TX queues are stopped at this point, so this test |
| 1467 | * doesn't need to take ->tx_lock. |
| 1468 | */ |
| 1469 | if (!priv->pending_tx_pkts) |
| 1470 | return 0; |
| 1471 | |
| 1472 | retry = 0; |
| 1473 | rc = 0; |
| 1474 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1475 | spin_lock_bh(&priv->tx_lock); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1476 | priv->tx_wait = &tx_wait; |
| 1477 | while (!rc) { |
| 1478 | int oldcount; |
| 1479 | unsigned long timeout; |
| 1480 | |
| 1481 | oldcount = priv->pending_tx_pkts; |
| 1482 | |
| 1483 | spin_unlock_bh(&priv->tx_lock); |
| 1484 | timeout = wait_for_completion_timeout(&tx_wait, |
| 1485 | msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS)); |
| 1486 | spin_lock_bh(&priv->tx_lock); |
| 1487 | |
| 1488 | if (timeout) { |
| 1489 | WARN_ON(priv->pending_tx_pkts); |
| 1490 | if (retry) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1491 | wiphy_notice(hw->wiphy, "tx rings drained\n"); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1492 | } |
| 1493 | break; |
| 1494 | } |
| 1495 | |
| 1496 | if (priv->pending_tx_pkts < oldcount) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1497 | wiphy_notice(hw->wiphy, |
| 1498 | "waiting for tx rings to drain (%d -> %d pkts)\n", |
| 1499 | oldcount, priv->pending_tx_pkts); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1500 | retry = 1; |
| 1501 | continue; |
| 1502 | } |
| 1503 | |
| 1504 | priv->tx_wait = NULL; |
| 1505 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1506 | wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n", |
| 1507 | MWL8K_TX_WAIT_TIMEOUT_MS); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1508 | mwl8k_dump_tx_rings(hw); |
| 1509 | |
| 1510 | rc = -ETIMEDOUT; |
| 1511 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1512 | spin_unlock_bh(&priv->tx_lock); |
| 1513 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1514 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1515 | } |
| 1516 | |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 1517 | #define MWL8K_TXD_SUCCESS(status) \ |
| 1518 | ((status) & (MWL8K_TXD_STATUS_OK | \ |
| 1519 | MWL8K_TXD_STATUS_OK_RETRY | \ |
| 1520 | MWL8K_TXD_STATUS_OK_MORE_RETRY)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1521 | |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1522 | static int mwl8k_tid_queue_mapping(u8 tid) |
| 1523 | { |
| 1524 | BUG_ON(tid > 7); |
| 1525 | |
| 1526 | switch (tid) { |
| 1527 | case 0: |
| 1528 | case 3: |
| 1529 | return IEEE80211_AC_BE; |
| 1530 | break; |
| 1531 | case 1: |
| 1532 | case 2: |
| 1533 | return IEEE80211_AC_BK; |
| 1534 | break; |
| 1535 | case 4: |
| 1536 | case 5: |
| 1537 | return IEEE80211_AC_VI; |
| 1538 | break; |
| 1539 | case 6: |
| 1540 | case 7: |
| 1541 | return IEEE80211_AC_VO; |
| 1542 | break; |
| 1543 | default: |
| 1544 | return -1; |
| 1545 | break; |
| 1546 | } |
| 1547 | } |
| 1548 | |
Nishant Sarmukadam | 1703354 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1549 | /* The firmware will fill in the rate information |
| 1550 | * for each packet that gets queued in the hardware |
| 1551 | * in this structure |
| 1552 | */ |
| 1553 | |
| 1554 | struct rateinfo { |
| 1555 | __le16 format:1; |
| 1556 | __le16 short_gi:1; |
| 1557 | __le16 band_width:1; |
| 1558 | __le16 rate_id_mcs:6; |
| 1559 | __le16 adv_coding:2; |
| 1560 | __le16 antenna:2; |
| 1561 | __le16 act_sub_chan:2; |
| 1562 | __le16 preamble_type:1; |
| 1563 | __le16 power_id:4; |
| 1564 | __le16 antenna2:1; |
| 1565 | __le16 reserved:1; |
| 1566 | __le16 tx_bf_frame:1; |
| 1567 | __le16 green_field:1; |
| 1568 | } __packed; |
| 1569 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1570 | static int |
| 1571 | mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1572 | { |
| 1573 | struct mwl8k_priv *priv = hw->priv; |
| 1574 | struct mwl8k_tx_queue *txq = priv->txq + index; |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1575 | int processed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1576 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1577 | processed = 0; |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1578 | while (txq->len > 0 && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1579 | int tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1580 | struct mwl8k_tx_desc *tx_desc; |
| 1581 | unsigned long addr; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1582 | int size; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1583 | struct sk_buff *skb; |
| 1584 | struct ieee80211_tx_info *info; |
| 1585 | u32 status; |
Nishant Sarmukadam | 1703354 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1586 | struct ieee80211_sta *sta; |
| 1587 | struct mwl8k_sta *sta_info = NULL; |
| 1588 | u16 rate_info; |
| 1589 | struct rateinfo *rate; |
| 1590 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1591 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1592 | tx = txq->head; |
| 1593 | tx_desc = txq->txd + tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1594 | |
| 1595 | status = le32_to_cpu(tx_desc->status); |
| 1596 | |
| 1597 | if (status & MWL8K_TXD_STATUS_FW_OWNED) { |
| 1598 | if (!force) |
| 1599 | break; |
| 1600 | tx_desc->status &= |
| 1601 | ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED); |
| 1602 | } |
| 1603 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1604 | txq->head = (tx + 1) % MWL8K_TX_DESCS; |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1605 | BUG_ON(txq->len == 0); |
| 1606 | txq->len--; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1607 | priv->pending_tx_pkts--; |
| 1608 | |
| 1609 | addr = le32_to_cpu(tx_desc->pkt_phys_addr); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1610 | size = le16_to_cpu(tx_desc->pkt_len); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1611 | skb = txq->skb[tx]; |
| 1612 | txq->skb[tx] = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1613 | |
| 1614 | BUG_ON(skb == NULL); |
| 1615 | pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE); |
| 1616 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1617 | mwl8k_remove_dma_header(skb, tx_desc->qos_control); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1618 | |
Nishant Sarmukadam | 1703354 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1619 | wh = (struct ieee80211_hdr *) skb->data; |
| 1620 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1621 | /* Mark descriptor as unused */ |
| 1622 | tx_desc->pkt_phys_addr = 0; |
| 1623 | tx_desc->pkt_len = 0; |
| 1624 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1625 | info = IEEE80211_SKB_CB(skb); |
Nishant Sarmukadam | 1703354 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1626 | if (ieee80211_is_data(wh->frame_control)) { |
| 1627 | sta = info->control.sta; |
| 1628 | if (sta) { |
| 1629 | sta_info = MWL8K_STA(sta); |
| 1630 | BUG_ON(sta_info == NULL); |
| 1631 | rate_info = le16_to_cpu(tx_desc->rate_info); |
| 1632 | rate = (struct rateinfo *)&rate_info; |
| 1633 | /* If rate is < 6.5 Mpbs for an ht station |
| 1634 | * do not form an ampdu. If the station is a |
| 1635 | * legacy station (format = 0), do not form an |
| 1636 | * ampdu |
| 1637 | */ |
| 1638 | if (rate->rate_id_mcs < 1 || |
| 1639 | rate->format == 0) { |
| 1640 | sta_info->is_ampdu_allowed = false; |
| 1641 | } else { |
| 1642 | sta_info->is_ampdu_allowed = true; |
| 1643 | } |
| 1644 | } |
| 1645 | } |
| 1646 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1647 | ieee80211_tx_info_clear_status(info); |
Nishant Sarmukadam | 0bf22c3 | 2011-02-17 14:45:17 -0800 | [diff] [blame] | 1648 | |
| 1649 | /* Rate control is happening in the firmware. |
| 1650 | * Ensure no tx rate is being reported. |
| 1651 | */ |
| 1652 | info->status.rates[0].idx = -1; |
| 1653 | info->status.rates[0].count = 1; |
| 1654 | |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1655 | if (MWL8K_TXD_SUCCESS(status)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1656 | info->flags |= IEEE80211_TX_STAT_ACK; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1657 | |
| 1658 | ieee80211_tx_status_irqsafe(hw, skb); |
| 1659 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1660 | processed++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1663 | if (index < MWL8K_TX_WMM_QUEUES && processed && priv->radio_on && |
| 1664 | !mutex_is_locked(&priv->fw_mutex)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1665 | ieee80211_wake_queue(hw, index); |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1666 | |
| 1667 | return processed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | /* must be called only when the card's transmit is completely halted */ |
| 1671 | static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index) |
| 1672 | { |
| 1673 | struct mwl8k_priv *priv = hw->priv; |
| 1674 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1675 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 1676 | if (txq->txd == NULL) |
| 1677 | return; |
| 1678 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1679 | mwl8k_txq_reclaim(hw, index, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1680 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1681 | kfree(txq->skb); |
| 1682 | txq->skb = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1683 | |
| 1684 | pci_free_consistent(priv->pdev, |
| 1685 | MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc), |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1686 | txq->txd, txq->txd_dma); |
| 1687 | txq->txd = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1688 | } |
| 1689 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1690 | /* caller must hold priv->stream_lock when calling the stream functions */ |
| 1691 | struct mwl8k_ampdu_stream * |
| 1692 | mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid) |
| 1693 | { |
| 1694 | struct mwl8k_ampdu_stream *stream; |
| 1695 | struct mwl8k_priv *priv = hw->priv; |
| 1696 | int i; |
| 1697 | |
| 1698 | for (i = 0; i < priv->num_ampdu_queues; i++) { |
| 1699 | stream = &priv->ampdu[i]; |
| 1700 | if (stream->state == AMPDU_NO_STREAM) { |
| 1701 | stream->sta = sta; |
| 1702 | stream->state = AMPDU_STREAM_NEW; |
| 1703 | stream->tid = tid; |
| 1704 | stream->idx = i; |
| 1705 | stream->txq_idx = MWL8K_TX_WMM_QUEUES + i; |
| 1706 | wiphy_debug(hw->wiphy, "Added a new stream for %pM %d", |
| 1707 | sta->addr, tid); |
| 1708 | return stream; |
| 1709 | } |
| 1710 | } |
| 1711 | return NULL; |
| 1712 | } |
| 1713 | |
| 1714 | static int |
| 1715 | mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream) |
| 1716 | { |
| 1717 | int ret; |
| 1718 | |
| 1719 | /* if the stream has already been started, don't start it again */ |
| 1720 | if (stream->state != AMPDU_STREAM_NEW) |
| 1721 | return 0; |
| 1722 | ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0); |
| 1723 | if (ret) |
| 1724 | wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: " |
| 1725 | "%d\n", stream->sta->addr, stream->tid, ret); |
| 1726 | else |
| 1727 | wiphy_debug(hw->wiphy, "Started stream for %pM %d\n", |
| 1728 | stream->sta->addr, stream->tid); |
| 1729 | return ret; |
| 1730 | } |
| 1731 | |
| 1732 | static void |
| 1733 | mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream) |
| 1734 | { |
| 1735 | wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr, |
| 1736 | stream->tid); |
| 1737 | memset(stream, 0, sizeof(*stream)); |
| 1738 | } |
| 1739 | |
| 1740 | static struct mwl8k_ampdu_stream * |
| 1741 | mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid) |
| 1742 | { |
| 1743 | struct mwl8k_priv *priv = hw->priv; |
| 1744 | int i; |
| 1745 | |
| 1746 | for (i = 0 ; i < priv->num_ampdu_queues; i++) { |
| 1747 | struct mwl8k_ampdu_stream *stream; |
| 1748 | stream = &priv->ampdu[i]; |
| 1749 | if (stream->state == AMPDU_NO_STREAM) |
| 1750 | continue; |
| 1751 | if (!memcmp(stream->sta->addr, addr, ETH_ALEN) && |
| 1752 | stream->tid == tid) |
| 1753 | return stream; |
| 1754 | } |
| 1755 | return NULL; |
| 1756 | } |
| 1757 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1758 | static void |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1759 | mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb) |
| 1760 | { |
| 1761 | struct mwl8k_priv *priv = hw->priv; |
| 1762 | struct ieee80211_tx_info *tx_info; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1763 | struct mwl8k_vif *mwl8k_vif; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1764 | struct ieee80211_sta *sta; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1765 | struct ieee80211_hdr *wh; |
| 1766 | struct mwl8k_tx_queue *txq; |
| 1767 | struct mwl8k_tx_desc *tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1768 | dma_addr_t dma; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1769 | u32 txstatus; |
| 1770 | u8 txdatarate; |
| 1771 | u16 qos; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1772 | int txpriority; |
| 1773 | u8 tid = 0; |
| 1774 | struct mwl8k_ampdu_stream *stream = NULL; |
| 1775 | bool start_ba_session = false; |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1776 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1777 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1778 | wh = (struct ieee80211_hdr *)skb->data; |
| 1779 | if (ieee80211_is_data_qos(wh->frame_control)) |
| 1780 | qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh))); |
| 1781 | else |
| 1782 | qos = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1783 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1784 | if (priv->ap_fw) |
| 1785 | mwl8k_encapsulate_tx_frame(skb); |
| 1786 | else |
| 1787 | mwl8k_add_dma_header(skb, 0); |
| 1788 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1789 | wh = &((struct mwl8k_dma_data *)skb->data)->wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1790 | |
| 1791 | tx_info = IEEE80211_SKB_CB(skb); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1792 | sta = tx_info->control.sta; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1793 | mwl8k_vif = MWL8K_VIF(tx_info->control.vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1794 | |
| 1795 | if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1796 | wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
Lennert Buytenhek | 657232b | 2010-01-12 13:47:47 +0100 | [diff] [blame] | 1797 | wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno); |
| 1798 | mwl8k_vif->seqno += 0x10; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1799 | } |
| 1800 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1801 | /* Setup firmware control bit fields for each frame type. */ |
| 1802 | txstatus = 0; |
| 1803 | txdatarate = 0; |
| 1804 | if (ieee80211_is_mgmt(wh->frame_control) || |
| 1805 | ieee80211_is_ctl(wh->frame_control)) { |
| 1806 | txdatarate = 0; |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1807 | qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1808 | } else if (ieee80211_is_data(wh->frame_control)) { |
| 1809 | txdatarate = 1; |
| 1810 | if (is_multicast_ether_addr(wh->addr1)) |
| 1811 | txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX; |
| 1812 | |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1813 | qos &= ~MWL8K_QOS_ACK_POLICY_MASK; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1814 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1815 | qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1816 | else |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1817 | qos |= MWL8K_QOS_ACK_POLICY_NORMAL; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1818 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1819 | |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1820 | /* Queue ADDBA request in the respective data queue. While setting up |
| 1821 | * the ampdu stream, mac80211 queues further packets for that |
| 1822 | * particular ra/tid pair. However, packets piled up in the hardware |
| 1823 | * for that ra/tid pair will still go out. ADDBA request and the |
| 1824 | * related data packets going out from different queues asynchronously |
| 1825 | * will cause a shift in the receiver window which might result in |
| 1826 | * ampdu packets getting dropped at the receiver after the stream has |
| 1827 | * been setup. |
| 1828 | */ |
| 1829 | if (unlikely(ieee80211_is_action(wh->frame_control) && |
| 1830 | mgmt->u.action.category == WLAN_CATEGORY_BACK && |
| 1831 | mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ && |
| 1832 | priv->ap_fw)) { |
| 1833 | u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 1834 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 1835 | index = mwl8k_tid_queue_mapping(tid); |
| 1836 | } |
| 1837 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1838 | txpriority = index; |
| 1839 | |
| 1840 | if (ieee80211_is_data_qos(wh->frame_control) && |
| 1841 | skb->protocol != cpu_to_be16(ETH_P_PAE) && |
| 1842 | sta->ht_cap.ht_supported && priv->ap_fw) { |
| 1843 | tid = qos & 0xf; |
| 1844 | spin_lock(&priv->stream_lock); |
| 1845 | stream = mwl8k_lookup_stream(hw, sta->addr, tid); |
| 1846 | if (stream != NULL) { |
| 1847 | if (stream->state == AMPDU_STREAM_ACTIVE) { |
| 1848 | txpriority = stream->txq_idx; |
| 1849 | index = stream->txq_idx; |
| 1850 | } else if (stream->state == AMPDU_STREAM_NEW) { |
| 1851 | /* We get here if the driver sends us packets |
| 1852 | * after we've initiated a stream, but before |
| 1853 | * our ampdu_action routine has been called |
| 1854 | * with IEEE80211_AMPDU_TX_START to get the SSN |
| 1855 | * for the ADDBA request. So this packet can |
| 1856 | * go out with no risk of sequence number |
| 1857 | * mismatch. No special handling is required. |
| 1858 | */ |
| 1859 | } else { |
| 1860 | /* Drop packets that would go out after the |
| 1861 | * ADDBA request was sent but before the ADDBA |
| 1862 | * response is received. If we don't do this, |
| 1863 | * the recipient would probably receive it |
| 1864 | * after the ADDBA request with SSN 0. This |
| 1865 | * will cause the recipient's BA receive window |
| 1866 | * to shift, which would cause the subsequent |
| 1867 | * packets in the BA stream to be discarded. |
| 1868 | * mac80211 queues our packets for us in this |
| 1869 | * case, so this is really just a safety check. |
| 1870 | */ |
| 1871 | wiphy_warn(hw->wiphy, |
| 1872 | "Cannot send packet while ADDBA " |
| 1873 | "dialog is underway.\n"); |
| 1874 | spin_unlock(&priv->stream_lock); |
| 1875 | dev_kfree_skb(skb); |
| 1876 | return; |
| 1877 | } |
| 1878 | } else { |
| 1879 | /* Defer calling mwl8k_start_stream so that the current |
| 1880 | * skb can go out before the ADDBA request. This |
| 1881 | * prevents sequence number mismatch at the recepient |
| 1882 | * as described above. |
| 1883 | */ |
Nishant Sarmukadam | 1703354 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1884 | if (MWL8K_STA(sta)->is_ampdu_allowed) { |
| 1885 | stream = mwl8k_add_stream(hw, sta, tid); |
| 1886 | if (stream != NULL) |
| 1887 | start_ba_session = true; |
| 1888 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1889 | } |
| 1890 | spin_unlock(&priv->stream_lock); |
| 1891 | } |
| 1892 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1893 | dma = pci_map_single(priv->pdev, skb->data, |
| 1894 | skb->len, PCI_DMA_TODEVICE); |
| 1895 | |
| 1896 | if (pci_dma_mapping_error(priv->pdev, dma)) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1897 | wiphy_debug(hw->wiphy, |
| 1898 | "failed to dma map skb, dropping TX frame.\n"); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1899 | if (start_ba_session) { |
| 1900 | spin_lock(&priv->stream_lock); |
| 1901 | mwl8k_remove_stream(hw, stream); |
| 1902 | spin_unlock(&priv->stream_lock); |
| 1903 | } |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1904 | dev_kfree_skb(skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1905 | return; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1906 | } |
| 1907 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1908 | spin_lock_bh(&priv->tx_lock); |
| 1909 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1910 | txq = priv->txq + index; |
| 1911 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1912 | if (index >= MWL8K_TX_WMM_QUEUES && txq->len >= MWL8K_TX_DESCS) { |
| 1913 | /* This is the case in which the tx packet is destined for an |
| 1914 | * AMPDU queue and that AMPDU queue is full. Because we don't |
| 1915 | * start and stop the AMPDU queues, we must drop these packets. |
| 1916 | */ |
| 1917 | dev_kfree_skb(skb); |
| 1918 | spin_unlock_bh(&priv->tx_lock); |
| 1919 | return; |
| 1920 | } |
| 1921 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1922 | BUG_ON(txq->skb[txq->tail] != NULL); |
| 1923 | txq->skb[txq->tail] = skb; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1924 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1925 | tx = txq->txd + txq->tail; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1926 | tx->data_rate = txdatarate; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1927 | tx->tx_priority = txpriority; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1928 | tx->qos_control = cpu_to_le16(qos); |
| 1929 | tx->pkt_phys_addr = cpu_to_le32(dma); |
| 1930 | tx->pkt_len = cpu_to_le16(skb->len); |
| 1931 | tx->rate_info = 0; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 1932 | if (!priv->ap_fw && tx_info->control.sta != NULL) |
| 1933 | tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id; |
| 1934 | else |
| 1935 | tx->peer_id = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1936 | wmb(); |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1937 | tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus); |
| 1938 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1939 | txq->len++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1940 | priv->pending_tx_pkts++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1941 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1942 | txq->tail++; |
| 1943 | if (txq->tail == MWL8K_TX_DESCS) |
| 1944 | txq->tail = 0; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1945 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1946 | if (txq->head == txq->tail && index < MWL8K_TX_WMM_QUEUES) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1947 | ieee80211_stop_queue(hw, index); |
| 1948 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1949 | mwl8k_tx_start(priv); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1950 | |
| 1951 | spin_unlock_bh(&priv->tx_lock); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1952 | |
| 1953 | /* Initiate the ampdu session here */ |
| 1954 | if (start_ba_session) { |
| 1955 | spin_lock(&priv->stream_lock); |
| 1956 | if (mwl8k_start_stream(hw, stream)) |
| 1957 | mwl8k_remove_stream(hw, stream); |
| 1958 | spin_unlock(&priv->stream_lock); |
| 1959 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | |
| 1963 | /* |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1964 | * Firmware access. |
| 1965 | * |
| 1966 | * We have the following requirements for issuing firmware commands: |
| 1967 | * - Some commands require that the packet transmit path is idle when |
| 1968 | * the command is issued. (For simplicity, we'll just quiesce the |
| 1969 | * transmit path for every command.) |
| 1970 | * - There are certain sequences of commands that need to be issued to |
| 1971 | * the hardware sequentially, with no other intervening commands. |
| 1972 | * |
| 1973 | * This leads to an implementation of a "firmware lock" as a mutex that |
| 1974 | * can be taken recursively, and which is taken by both the low-level |
| 1975 | * command submission function (mwl8k_post_cmd) as well as any users of |
| 1976 | * that function that require issuing of an atomic sequence of commands, |
| 1977 | * and quiesces the transmit path whenever it's taken. |
| 1978 | */ |
| 1979 | static int mwl8k_fw_lock(struct ieee80211_hw *hw) |
| 1980 | { |
| 1981 | struct mwl8k_priv *priv = hw->priv; |
| 1982 | |
| 1983 | if (priv->fw_mutex_owner != current) { |
| 1984 | int rc; |
| 1985 | |
| 1986 | mutex_lock(&priv->fw_mutex); |
| 1987 | ieee80211_stop_queues(hw); |
| 1988 | |
| 1989 | rc = mwl8k_tx_wait_empty(hw); |
| 1990 | if (rc) { |
| 1991 | ieee80211_wake_queues(hw); |
| 1992 | mutex_unlock(&priv->fw_mutex); |
| 1993 | |
| 1994 | return rc; |
| 1995 | } |
| 1996 | |
| 1997 | priv->fw_mutex_owner = current; |
| 1998 | } |
| 1999 | |
| 2000 | priv->fw_mutex_depth++; |
| 2001 | |
| 2002 | return 0; |
| 2003 | } |
| 2004 | |
| 2005 | static void mwl8k_fw_unlock(struct ieee80211_hw *hw) |
| 2006 | { |
| 2007 | struct mwl8k_priv *priv = hw->priv; |
| 2008 | |
| 2009 | if (!--priv->fw_mutex_depth) { |
| 2010 | ieee80211_wake_queues(hw); |
| 2011 | priv->fw_mutex_owner = NULL; |
| 2012 | mutex_unlock(&priv->fw_mutex); |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | |
| 2017 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2018 | * Command processing. |
| 2019 | */ |
| 2020 | |
Lennert Buytenhek | 0c9cc64 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2021 | /* Timeout firmware commands after 10s */ |
| 2022 | #define MWL8K_CMD_TIMEOUT_MS 10000 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2023 | |
| 2024 | static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd) |
| 2025 | { |
| 2026 | DECLARE_COMPLETION_ONSTACK(cmd_wait); |
| 2027 | struct mwl8k_priv *priv = hw->priv; |
| 2028 | void __iomem *regs = priv->regs; |
| 2029 | dma_addr_t dma_addr; |
| 2030 | unsigned int dma_size; |
| 2031 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2032 | unsigned long timeout = 0; |
| 2033 | u8 buf[32]; |
| 2034 | |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2035 | cmd->result = (__force __le16) 0xffff; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2036 | dma_size = le16_to_cpu(cmd->length); |
| 2037 | dma_addr = pci_map_single(priv->pdev, cmd, dma_size, |
| 2038 | PCI_DMA_BIDIRECTIONAL); |
| 2039 | if (pci_dma_mapping_error(priv->pdev, dma_addr)) |
| 2040 | return -ENOMEM; |
| 2041 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2042 | rc = mwl8k_fw_lock(hw); |
Lennert Buytenhek | 39a1e42 | 2009-08-24 15:42:46 +0200 | [diff] [blame] | 2043 | if (rc) { |
| 2044 | pci_unmap_single(priv->pdev, dma_addr, dma_size, |
| 2045 | PCI_DMA_BIDIRECTIONAL); |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2046 | return rc; |
Lennert Buytenhek | 39a1e42 | 2009-08-24 15:42:46 +0200 | [diff] [blame] | 2047 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2048 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2049 | priv->hostcmd_wait = &cmd_wait; |
| 2050 | iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR); |
| 2051 | iowrite32(MWL8K_H2A_INT_DOORBELL, |
| 2052 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 2053 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 2054 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2055 | |
| 2056 | timeout = wait_for_completion_timeout(&cmd_wait, |
| 2057 | msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS)); |
| 2058 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2059 | priv->hostcmd_wait = NULL; |
| 2060 | |
| 2061 | mwl8k_fw_unlock(hw); |
| 2062 | |
Lennert Buytenhek | 37055bd | 2009-08-03 21:58:47 +0200 | [diff] [blame] | 2063 | pci_unmap_single(priv->pdev, dma_addr, dma_size, |
| 2064 | PCI_DMA_BIDIRECTIONAL); |
| 2065 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2066 | if (!timeout) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2067 | wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2068 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), |
| 2069 | MWL8K_CMD_TIMEOUT_MS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2070 | rc = -ETIMEDOUT; |
| 2071 | } else { |
Lennert Buytenhek | 0c9cc64 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2072 | int ms; |
| 2073 | |
| 2074 | ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout); |
| 2075 | |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2076 | rc = cmd->result ? -EINVAL : 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2077 | if (rc) |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2078 | wiphy_err(hw->wiphy, "Command %s error 0x%x\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2079 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), |
| 2080 | le16_to_cpu(cmd->result)); |
Lennert Buytenhek | 0c9cc64 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2081 | else if (ms > 2000) |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2082 | wiphy_notice(hw->wiphy, "Command %s took %d ms\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2083 | mwl8k_cmd_name(cmd->code, |
| 2084 | buf, sizeof(buf)), |
| 2085 | ms); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2088 | return rc; |
| 2089 | } |
| 2090 | |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 2091 | static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw, |
| 2092 | struct ieee80211_vif *vif, |
| 2093 | struct mwl8k_cmd_pkt *cmd) |
| 2094 | { |
| 2095 | if (vif != NULL) |
| 2096 | cmd->macid = MWL8K_VIF(vif)->macid; |
| 2097 | return mwl8k_post_cmd(hw, cmd); |
| 2098 | } |
| 2099 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2100 | /* |
Lennert Buytenhek | 1349ad2 | 2010-01-12 13:48:17 +0100 | [diff] [blame] | 2101 | * Setup code shared between STA and AP firmware images. |
| 2102 | */ |
| 2103 | static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw) |
| 2104 | { |
| 2105 | struct mwl8k_priv *priv = hw->priv; |
| 2106 | |
| 2107 | BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24)); |
| 2108 | memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24)); |
| 2109 | |
| 2110 | BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24)); |
| 2111 | memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24)); |
| 2112 | |
| 2113 | priv->band_24.band = IEEE80211_BAND_2GHZ; |
| 2114 | priv->band_24.channels = priv->channels_24; |
| 2115 | priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24); |
| 2116 | priv->band_24.bitrates = priv->rates_24; |
| 2117 | priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24); |
| 2118 | |
| 2119 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24; |
| 2120 | } |
| 2121 | |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 2122 | static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw) |
| 2123 | { |
| 2124 | struct mwl8k_priv *priv = hw->priv; |
| 2125 | |
| 2126 | BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50)); |
| 2127 | memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50)); |
| 2128 | |
| 2129 | BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50)); |
| 2130 | memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50)); |
| 2131 | |
| 2132 | priv->band_50.band = IEEE80211_BAND_5GHZ; |
| 2133 | priv->band_50.channels = priv->channels_50; |
| 2134 | priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50); |
| 2135 | priv->band_50.bitrates = priv->rates_50; |
| 2136 | priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50); |
| 2137 | |
| 2138 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50; |
| 2139 | } |
| 2140 | |
Lennert Buytenhek | 1349ad2 | 2010-01-12 13:48:17 +0100 | [diff] [blame] | 2141 | /* |
Lennert Buytenhek | 04b147b | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2142 | * CMD_GET_HW_SPEC (STA version). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2143 | */ |
Lennert Buytenhek | 04b147b | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2144 | struct mwl8k_cmd_get_hw_spec_sta { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2145 | struct mwl8k_cmd_pkt header; |
| 2146 | __u8 hw_rev; |
| 2147 | __u8 host_interface; |
| 2148 | __le16 num_mcaddrs; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2149 | __u8 perm_addr[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2150 | __le16 region_code; |
| 2151 | __le32 fw_rev; |
| 2152 | __le32 ps_cookie; |
| 2153 | __le32 caps; |
| 2154 | __u8 mcs_bitmap[16]; |
| 2155 | __le32 rx_queue_ptr; |
| 2156 | __le32 num_tx_queues; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2157 | __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2158 | __le32 caps2; |
| 2159 | __le32 num_tx_desc_per_queue; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2160 | __le32 total_rxd; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2161 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2162 | |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2163 | #define MWL8K_CAP_MAX_AMSDU 0x20000000 |
| 2164 | #define MWL8K_CAP_GREENFIELD 0x08000000 |
| 2165 | #define MWL8K_CAP_AMPDU 0x04000000 |
| 2166 | #define MWL8K_CAP_RX_STBC 0x01000000 |
| 2167 | #define MWL8K_CAP_TX_STBC 0x00800000 |
| 2168 | #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000 |
| 2169 | #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000 |
| 2170 | #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000 |
| 2171 | #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000 |
| 2172 | #define MWL8K_CAP_DELAY_BA 0x00003000 |
| 2173 | #define MWL8K_CAP_MIMO 0x00000200 |
| 2174 | #define MWL8K_CAP_40MHZ 0x00000100 |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2175 | #define MWL8K_CAP_BAND_MASK 0x00000007 |
| 2176 | #define MWL8K_CAP_5GHZ 0x00000004 |
| 2177 | #define MWL8K_CAP_2GHZ4 0x00000001 |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2178 | |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2179 | static void |
| 2180 | mwl8k_set_ht_caps(struct ieee80211_hw *hw, |
| 2181 | struct ieee80211_supported_band *band, u32 cap) |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2182 | { |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2183 | int rx_streams; |
| 2184 | int tx_streams; |
| 2185 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2186 | band->ht_cap.ht_supported = 1; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2187 | |
| 2188 | if (cap & MWL8K_CAP_MAX_AMSDU) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2189 | band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2190 | if (cap & MWL8K_CAP_GREENFIELD) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2191 | band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2192 | if (cap & MWL8K_CAP_AMPDU) { |
| 2193 | hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION; |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2194 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 2195 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2196 | } |
| 2197 | if (cap & MWL8K_CAP_RX_STBC) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2198 | band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2199 | if (cap & MWL8K_CAP_TX_STBC) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2200 | band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2201 | if (cap & MWL8K_CAP_SHORTGI_40MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2202 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2203 | if (cap & MWL8K_CAP_SHORTGI_20MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2204 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2205 | if (cap & MWL8K_CAP_DELAY_BA) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2206 | band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2207 | if (cap & MWL8K_CAP_40MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2208 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2209 | |
| 2210 | rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK); |
| 2211 | tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK); |
| 2212 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2213 | band->ht_cap.mcs.rx_mask[0] = 0xff; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2214 | if (rx_streams >= 2) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2215 | band->ht_cap.mcs.rx_mask[1] = 0xff; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2216 | if (rx_streams >= 3) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2217 | band->ht_cap.mcs.rx_mask[2] = 0xff; |
| 2218 | band->ht_cap.mcs.rx_mask[4] = 0x01; |
| 2219 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2220 | |
| 2221 | if (rx_streams != tx_streams) { |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2222 | band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF; |
| 2223 | band->ht_cap.mcs.tx_params |= (tx_streams - 1) << |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2224 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; |
| 2225 | } |
| 2226 | } |
| 2227 | |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2228 | static void |
| 2229 | mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps) |
| 2230 | { |
| 2231 | struct mwl8k_priv *priv = hw->priv; |
| 2232 | |
| 2233 | if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) { |
| 2234 | mwl8k_setup_2ghz_band(hw); |
| 2235 | if (caps & MWL8K_CAP_MIMO) |
| 2236 | mwl8k_set_ht_caps(hw, &priv->band_24, caps); |
| 2237 | } |
| 2238 | |
| 2239 | if (caps & MWL8K_CAP_5GHZ) { |
| 2240 | mwl8k_setup_5ghz_band(hw); |
| 2241 | if (caps & MWL8K_CAP_MIMO) |
| 2242 | mwl8k_set_ht_caps(hw, &priv->band_50, caps); |
| 2243 | } |
| 2244 | } |
| 2245 | |
Lennert Buytenhek | 04b147b | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2246 | static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2247 | { |
| 2248 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 04b147b | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2249 | struct mwl8k_cmd_get_hw_spec_sta *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2250 | int rc; |
| 2251 | int i; |
| 2252 | |
| 2253 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2254 | if (cmd == NULL) |
| 2255 | return -ENOMEM; |
| 2256 | |
| 2257 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC); |
| 2258 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2259 | |
| 2260 | memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr)); |
| 2261 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2262 | cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma); |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2263 | cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv)); |
| 2264 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2265 | cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma); |
Lennert Buytenhek | 4ff6432 | 2009-08-03 21:58:39 +0200 | [diff] [blame] | 2266 | cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2267 | cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2268 | |
| 2269 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2270 | |
| 2271 | if (!rc) { |
| 2272 | SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr); |
| 2273 | priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); |
Lennert Buytenhek | 4ff6432 | 2009-08-03 21:58:39 +0200 | [diff] [blame] | 2274 | priv->fw_rev = le32_to_cpu(cmd->fw_rev); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2275 | priv->hw_rev = cmd->hw_rev; |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2276 | mwl8k_set_caps(hw, le32_to_cpu(cmd->caps)); |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 2277 | priv->ap_macids_supported = 0x00000000; |
| 2278 | priv->sta_macids_supported = 0x00000001; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | kfree(cmd); |
| 2282 | return rc; |
| 2283 | } |
| 2284 | |
| 2285 | /* |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2286 | * CMD_GET_HW_SPEC (AP version). |
| 2287 | */ |
| 2288 | struct mwl8k_cmd_get_hw_spec_ap { |
| 2289 | struct mwl8k_cmd_pkt header; |
| 2290 | __u8 hw_rev; |
| 2291 | __u8 host_interface; |
| 2292 | __le16 num_wcb; |
| 2293 | __le16 num_mcaddrs; |
| 2294 | __u8 perm_addr[ETH_ALEN]; |
| 2295 | __le16 region_code; |
| 2296 | __le16 num_antenna; |
| 2297 | __le32 fw_rev; |
| 2298 | __le32 wcbbase0; |
| 2299 | __le32 rxwrptr; |
| 2300 | __le32 rxrdptr; |
| 2301 | __le32 ps_cookie; |
| 2302 | __le32 wcbbase1; |
| 2303 | __le32 wcbbase2; |
| 2304 | __le32 wcbbase3; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2305 | __le32 fw_api_version; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2306 | __le32 caps; |
| 2307 | __le32 num_of_ampdu_queues; |
| 2308 | __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2309 | } __packed; |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2310 | |
| 2311 | static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw) |
| 2312 | { |
| 2313 | struct mwl8k_priv *priv = hw->priv; |
| 2314 | struct mwl8k_cmd_get_hw_spec_ap *cmd; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2315 | int rc, i; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2316 | u32 api_version; |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2317 | |
| 2318 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2319 | if (cmd == NULL) |
| 2320 | return -ENOMEM; |
| 2321 | |
| 2322 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC); |
| 2323 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2324 | |
| 2325 | memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr)); |
| 2326 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
| 2327 | |
| 2328 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2329 | |
| 2330 | if (!rc) { |
| 2331 | int off; |
| 2332 | |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2333 | api_version = le32_to_cpu(cmd->fw_api_version); |
| 2334 | if (priv->device_info->fw_api_ap != api_version) { |
| 2335 | printk(KERN_ERR "%s: Unsupported fw API version for %s." |
| 2336 | " Expected %d got %d.\n", MWL8K_NAME, |
| 2337 | priv->device_info->part_name, |
| 2338 | priv->device_info->fw_api_ap, |
| 2339 | api_version); |
| 2340 | rc = -EINVAL; |
| 2341 | goto done; |
| 2342 | } |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2343 | SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr); |
| 2344 | priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); |
| 2345 | priv->fw_rev = le32_to_cpu(cmd->fw_rev); |
| 2346 | priv->hw_rev = cmd->hw_rev; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2347 | mwl8k_set_caps(hw, le32_to_cpu(cmd->caps)); |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 2348 | priv->ap_macids_supported = 0x000000ff; |
| 2349 | priv->sta_macids_supported = 0x00000000; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2350 | priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues); |
| 2351 | if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) { |
| 2352 | wiphy_warn(hw->wiphy, "fw reported %d ampdu queues" |
| 2353 | " but we only support %d.\n", |
| 2354 | priv->num_ampdu_queues, |
| 2355 | MWL8K_MAX_AMPDU_QUEUES); |
| 2356 | priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES; |
| 2357 | } |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2358 | off = le32_to_cpu(cmd->rxwrptr) & 0xffff; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2359 | iowrite32(priv->rxq[0].rxd_dma, priv->sram + off); |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2360 | |
| 2361 | off = le32_to_cpu(cmd->rxrdptr) & 0xffff; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2362 | iowrite32(priv->rxq[0].rxd_dma, priv->sram + off); |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2363 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 2364 | priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff; |
| 2365 | priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff; |
| 2366 | priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff; |
| 2367 | priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2368 | |
| 2369 | for (i = 0; i < priv->num_ampdu_queues; i++) |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2370 | priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] = |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2371 | le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff; |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2372 | } |
| 2373 | |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2374 | done: |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2375 | kfree(cmd); |
| 2376 | return rc; |
| 2377 | } |
| 2378 | |
| 2379 | /* |
| 2380 | * CMD_SET_HW_SPEC. |
| 2381 | */ |
| 2382 | struct mwl8k_cmd_set_hw_spec { |
| 2383 | struct mwl8k_cmd_pkt header; |
| 2384 | __u8 hw_rev; |
| 2385 | __u8 host_interface; |
| 2386 | __le16 num_mcaddrs; |
| 2387 | __u8 perm_addr[ETH_ALEN]; |
| 2388 | __le16 region_code; |
| 2389 | __le32 fw_rev; |
| 2390 | __le32 ps_cookie; |
| 2391 | __le32 caps; |
| 2392 | __le32 rx_queue_ptr; |
| 2393 | __le32 num_tx_queues; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2394 | __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES]; |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2395 | __le32 flags; |
| 2396 | __le32 num_tx_desc_per_queue; |
| 2397 | __le32 total_rxd; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2398 | } __packed; |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2399 | |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2400 | /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause |
| 2401 | * packets to expire 500 ms after the timestamp in the tx descriptor. That is, |
| 2402 | * the packets that are queued for more than 500ms, will be dropped in the |
| 2403 | * hardware. This helps minimizing the issues caused due to head-of-line |
| 2404 | * blocking where a slow client can hog the bandwidth and affect traffic to a |
| 2405 | * faster client. |
| 2406 | */ |
| 2407 | #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400 |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2408 | #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080 |
| 2409 | #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020 |
| 2410 | #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010 |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2411 | |
| 2412 | static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw) |
| 2413 | { |
| 2414 | struct mwl8k_priv *priv = hw->priv; |
| 2415 | struct mwl8k_cmd_set_hw_spec *cmd; |
| 2416 | int rc; |
| 2417 | int i; |
| 2418 | |
| 2419 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2420 | if (cmd == NULL) |
| 2421 | return -ENOMEM; |
| 2422 | |
| 2423 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC); |
| 2424 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2425 | |
| 2426 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
| 2427 | cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma); |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2428 | cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv)); |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 2429 | |
| 2430 | /* |
| 2431 | * Mac80211 stack has Q0 as highest priority and Q3 as lowest in |
| 2432 | * that order. Firmware has Q3 as highest priority and Q0 as lowest |
| 2433 | * in that order. Map Q3 of mac80211 to Q0 of firmware so that the |
| 2434 | * priority is interpreted the right way in firmware. |
| 2435 | */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2436 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
| 2437 | int j = mwl8k_tx_queues(priv) - 1 - i; |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 2438 | cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma); |
| 2439 | } |
| 2440 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2441 | cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT | |
| 2442 | MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP | |
| 2443 | MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON); |
Lennert Buytenhek | 42fba21 | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2444 | cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); |
| 2445 | cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS); |
| 2446 | |
| 2447 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2448 | kfree(cmd); |
| 2449 | |
| 2450 | return rc; |
| 2451 | } |
| 2452 | |
| 2453 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2454 | * CMD_MAC_MULTICAST_ADR. |
| 2455 | */ |
| 2456 | struct mwl8k_cmd_mac_multicast_adr { |
| 2457 | struct mwl8k_cmd_pkt header; |
| 2458 | __le16 action; |
| 2459 | __le16 numaddr; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2460 | __u8 addr[0][ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2461 | }; |
| 2462 | |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2463 | #define MWL8K_ENABLE_RX_DIRECTED 0x0001 |
| 2464 | #define MWL8K_ENABLE_RX_MULTICAST 0x0002 |
| 2465 | #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004 |
| 2466 | #define MWL8K_ENABLE_RX_BROADCAST 0x0008 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2467 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2468 | static struct mwl8k_cmd_pkt * |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 2469 | __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti, |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2470 | struct netdev_hw_addr_list *mc_list) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2471 | { |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2472 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2473 | struct mwl8k_cmd_mac_multicast_adr *cmd; |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2474 | int size; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2475 | int mc_count = 0; |
| 2476 | |
| 2477 | if (mc_list) |
| 2478 | mc_count = netdev_hw_addr_list_count(mc_list); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2479 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 2480 | if (allmulti || mc_count > priv->num_mcaddrs) { |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2481 | allmulti = 1; |
| 2482 | mc_count = 0; |
| 2483 | } |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2484 | |
| 2485 | size = sizeof(*cmd) + mc_count * ETH_ALEN; |
| 2486 | |
| 2487 | cmd = kzalloc(size, GFP_ATOMIC); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2488 | if (cmd == NULL) |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2489 | return NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2490 | |
| 2491 | cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR); |
| 2492 | cmd->header.length = cpu_to_le16(size); |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2493 | cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED | |
| 2494 | MWL8K_ENABLE_RX_BROADCAST); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2495 | |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2496 | if (allmulti) { |
| 2497 | cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST); |
| 2498 | } else if (mc_count) { |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2499 | struct netdev_hw_addr *ha; |
| 2500 | int i = 0; |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2501 | |
| 2502 | cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST); |
| 2503 | cmd->numaddr = cpu_to_le16(mc_count); |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2504 | netdev_hw_addr_list_for_each(ha, mc_list) { |
| 2505 | memcpy(cmd->addr[i], ha->addr, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2506 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2507 | } |
| 2508 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2509 | return &cmd->header; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2513 | * CMD_GET_STAT. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2514 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2515 | struct mwl8k_cmd_get_stat { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2516 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2517 | __le32 stats[64]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2518 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2519 | |
| 2520 | #define MWL8K_STAT_ACK_FAILURE 9 |
| 2521 | #define MWL8K_STAT_RTS_FAILURE 12 |
| 2522 | #define MWL8K_STAT_FCS_ERROR 24 |
| 2523 | #define MWL8K_STAT_RTS_SUCCESS 11 |
| 2524 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2525 | static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw, |
| 2526 | struct ieee80211_low_level_stats *stats) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2527 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2528 | struct mwl8k_cmd_get_stat *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2529 | int rc; |
| 2530 | |
| 2531 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2532 | if (cmd == NULL) |
| 2533 | return -ENOMEM; |
| 2534 | |
| 2535 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT); |
| 2536 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2537 | |
| 2538 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2539 | if (!rc) { |
| 2540 | stats->dot11ACKFailureCount = |
| 2541 | le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]); |
| 2542 | stats->dot11RTSFailureCount = |
| 2543 | le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]); |
| 2544 | stats->dot11FCSErrorCount = |
| 2545 | le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]); |
| 2546 | stats->dot11RTSSuccessCount = |
| 2547 | le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]); |
| 2548 | } |
| 2549 | kfree(cmd); |
| 2550 | |
| 2551 | return rc; |
| 2552 | } |
| 2553 | |
| 2554 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2555 | * CMD_RADIO_CONTROL. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2556 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2557 | struct mwl8k_cmd_radio_control { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2558 | struct mwl8k_cmd_pkt header; |
| 2559 | __le16 action; |
| 2560 | __le16 control; |
| 2561 | __le16 radio_on; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2562 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2563 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2564 | static int |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2565 | mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2566 | { |
| 2567 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2568 | struct mwl8k_cmd_radio_control *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2569 | int rc; |
| 2570 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2571 | if (enable == priv->radio_on && !force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2572 | return 0; |
| 2573 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2574 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2575 | if (cmd == NULL) |
| 2576 | return -ENOMEM; |
| 2577 | |
| 2578 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL); |
| 2579 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2580 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 2581 | cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2582 | cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000); |
| 2583 | |
| 2584 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2585 | kfree(cmd); |
| 2586 | |
| 2587 | if (!rc) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2588 | priv->radio_on = enable; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2589 | |
| 2590 | return rc; |
| 2591 | } |
| 2592 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2593 | static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2594 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2595 | return mwl8k_cmd_radio_control(hw, 0, 0); |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2596 | } |
| 2597 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2598 | static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2599 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2600 | return mwl8k_cmd_radio_control(hw, 1, 0); |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2601 | } |
| 2602 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2603 | static int |
| 2604 | mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble) |
| 2605 | { |
Lennert Buytenhek | 99200a99 | 2009-11-30 18:31:40 +0100 | [diff] [blame] | 2606 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2607 | |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 2608 | priv->radio_short_preamble = short_preamble; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2609 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2610 | return mwl8k_cmd_radio_control(hw, 1, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2614 | * CMD_RF_TX_POWER. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2615 | */ |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2616 | #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2617 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2618 | struct mwl8k_cmd_rf_tx_power { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2619 | struct mwl8k_cmd_pkt header; |
| 2620 | __le16 action; |
| 2621 | __le16 support_level; |
| 2622 | __le16 current_level; |
| 2623 | __le16 reserved; |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2624 | __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2625 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2626 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2627 | static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2628 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2629 | struct mwl8k_cmd_rf_tx_power *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2630 | int rc; |
| 2631 | |
| 2632 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2633 | if (cmd == NULL) |
| 2634 | return -ENOMEM; |
| 2635 | |
| 2636 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER); |
| 2637 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2638 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 2639 | cmd->support_level = cpu_to_le16(dBm); |
| 2640 | |
| 2641 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2642 | kfree(cmd); |
| 2643 | |
| 2644 | return rc; |
| 2645 | } |
| 2646 | |
| 2647 | /* |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2648 | * CMD_TX_POWER. |
| 2649 | */ |
| 2650 | #define MWL8K_TX_POWER_LEVEL_TOTAL 12 |
| 2651 | |
| 2652 | struct mwl8k_cmd_tx_power { |
| 2653 | struct mwl8k_cmd_pkt header; |
| 2654 | __le16 action; |
| 2655 | __le16 band; |
| 2656 | __le16 channel; |
| 2657 | __le16 bw; |
| 2658 | __le16 sub_ch; |
| 2659 | __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL]; |
| 2660 | } __attribute__((packed)); |
| 2661 | |
| 2662 | static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw, |
| 2663 | struct ieee80211_conf *conf, |
| 2664 | unsigned short pwr) |
| 2665 | { |
| 2666 | struct ieee80211_channel *channel = conf->channel; |
| 2667 | struct mwl8k_cmd_tx_power *cmd; |
| 2668 | int rc; |
| 2669 | int i; |
| 2670 | |
| 2671 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2672 | if (cmd == NULL) |
| 2673 | return -ENOMEM; |
| 2674 | |
| 2675 | cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER); |
| 2676 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2677 | cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST); |
| 2678 | |
| 2679 | if (channel->band == IEEE80211_BAND_2GHZ) |
| 2680 | cmd->band = cpu_to_le16(0x1); |
| 2681 | else if (channel->band == IEEE80211_BAND_5GHZ) |
| 2682 | cmd->band = cpu_to_le16(0x4); |
| 2683 | |
| 2684 | cmd->channel = channel->hw_value; |
| 2685 | |
| 2686 | if (conf->channel_type == NL80211_CHAN_NO_HT || |
| 2687 | conf->channel_type == NL80211_CHAN_HT20) { |
| 2688 | cmd->bw = cpu_to_le16(0x2); |
| 2689 | } else { |
| 2690 | cmd->bw = cpu_to_le16(0x4); |
| 2691 | if (conf->channel_type == NL80211_CHAN_HT40MINUS) |
| 2692 | cmd->sub_ch = cpu_to_le16(0x3); |
| 2693 | else if (conf->channel_type == NL80211_CHAN_HT40PLUS) |
| 2694 | cmd->sub_ch = cpu_to_le16(0x1); |
| 2695 | } |
| 2696 | |
| 2697 | for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++) |
| 2698 | cmd->power_level_list[i] = cpu_to_le16(pwr); |
| 2699 | |
| 2700 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2701 | kfree(cmd); |
| 2702 | |
| 2703 | return rc; |
| 2704 | } |
| 2705 | |
| 2706 | /* |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 2707 | * CMD_RF_ANTENNA. |
| 2708 | */ |
| 2709 | struct mwl8k_cmd_rf_antenna { |
| 2710 | struct mwl8k_cmd_pkt header; |
| 2711 | __le16 antenna; |
| 2712 | __le16 mode; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2713 | } __packed; |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 2714 | |
| 2715 | #define MWL8K_RF_ANTENNA_RX 1 |
| 2716 | #define MWL8K_RF_ANTENNA_TX 2 |
| 2717 | |
| 2718 | static int |
| 2719 | mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask) |
| 2720 | { |
| 2721 | struct mwl8k_cmd_rf_antenna *cmd; |
| 2722 | int rc; |
| 2723 | |
| 2724 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2725 | if (cmd == NULL) |
| 2726 | return -ENOMEM; |
| 2727 | |
| 2728 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA); |
| 2729 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2730 | cmd->antenna = cpu_to_le16(antenna); |
| 2731 | cmd->mode = cpu_to_le16(mask); |
| 2732 | |
| 2733 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2734 | kfree(cmd); |
| 2735 | |
| 2736 | return rc; |
| 2737 | } |
| 2738 | |
| 2739 | /* |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2740 | * CMD_SET_BEACON. |
| 2741 | */ |
| 2742 | struct mwl8k_cmd_set_beacon { |
| 2743 | struct mwl8k_cmd_pkt header; |
| 2744 | __le16 beacon_len; |
| 2745 | __u8 beacon[0]; |
| 2746 | }; |
| 2747 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 2748 | static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, |
| 2749 | struct ieee80211_vif *vif, u8 *beacon, int len) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2750 | { |
| 2751 | struct mwl8k_cmd_set_beacon *cmd; |
| 2752 | int rc; |
| 2753 | |
| 2754 | cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL); |
| 2755 | if (cmd == NULL) |
| 2756 | return -ENOMEM; |
| 2757 | |
| 2758 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON); |
| 2759 | cmd->header.length = cpu_to_le16(sizeof(*cmd) + len); |
| 2760 | cmd->beacon_len = cpu_to_le16(len); |
| 2761 | memcpy(cmd->beacon, beacon, len); |
| 2762 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 2763 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2764 | kfree(cmd); |
| 2765 | |
| 2766 | return rc; |
| 2767 | } |
| 2768 | |
| 2769 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2770 | * CMD_SET_PRE_SCAN. |
| 2771 | */ |
| 2772 | struct mwl8k_cmd_set_pre_scan { |
| 2773 | struct mwl8k_cmd_pkt header; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2774 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2775 | |
| 2776 | static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw) |
| 2777 | { |
| 2778 | struct mwl8k_cmd_set_pre_scan *cmd; |
| 2779 | int rc; |
| 2780 | |
| 2781 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2782 | if (cmd == NULL) |
| 2783 | return -ENOMEM; |
| 2784 | |
| 2785 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN); |
| 2786 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2787 | |
| 2788 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2789 | kfree(cmd); |
| 2790 | |
| 2791 | return rc; |
| 2792 | } |
| 2793 | |
| 2794 | /* |
| 2795 | * CMD_SET_POST_SCAN. |
| 2796 | */ |
| 2797 | struct mwl8k_cmd_set_post_scan { |
| 2798 | struct mwl8k_cmd_pkt header; |
| 2799 | __le32 isibss; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2800 | __u8 bssid[ETH_ALEN]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2801 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2802 | |
| 2803 | static int |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 2804 | mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2805 | { |
| 2806 | struct mwl8k_cmd_set_post_scan *cmd; |
| 2807 | int rc; |
| 2808 | |
| 2809 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2810 | if (cmd == NULL) |
| 2811 | return -ENOMEM; |
| 2812 | |
| 2813 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN); |
| 2814 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2815 | cmd->isibss = 0; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2816 | memcpy(cmd->bssid, mac, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2817 | |
| 2818 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2819 | kfree(cmd); |
| 2820 | |
| 2821 | return rc; |
| 2822 | } |
| 2823 | |
| 2824 | /* |
| 2825 | * CMD_SET_RF_CHANNEL. |
| 2826 | */ |
| 2827 | struct mwl8k_cmd_set_rf_channel { |
| 2828 | struct mwl8k_cmd_pkt header; |
| 2829 | __le16 action; |
| 2830 | __u8 current_channel; |
| 2831 | __le32 channel_flags; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2832 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2833 | |
| 2834 | static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw, |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2835 | struct ieee80211_conf *conf) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2836 | { |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2837 | struct ieee80211_channel *channel = conf->channel; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2838 | struct mwl8k_cmd_set_rf_channel *cmd; |
| 2839 | int rc; |
| 2840 | |
| 2841 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2842 | if (cmd == NULL) |
| 2843 | return -ENOMEM; |
| 2844 | |
| 2845 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL); |
| 2846 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2847 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 2848 | cmd->current_channel = channel->hw_value; |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2849 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2850 | if (channel->band == IEEE80211_BAND_2GHZ) |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2851 | cmd->channel_flags |= cpu_to_le32(0x00000001); |
Lennert Buytenhek | 42574ea | 2010-01-12 13:49:18 +0100 | [diff] [blame] | 2852 | else if (channel->band == IEEE80211_BAND_5GHZ) |
| 2853 | cmd->channel_flags |= cpu_to_le32(0x00000004); |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2854 | |
| 2855 | if (conf->channel_type == NL80211_CHAN_NO_HT || |
| 2856 | conf->channel_type == NL80211_CHAN_HT20) |
| 2857 | cmd->channel_flags |= cpu_to_le32(0x00000080); |
| 2858 | else if (conf->channel_type == NL80211_CHAN_HT40MINUS) |
| 2859 | cmd->channel_flags |= cpu_to_le32(0x000001900); |
| 2860 | else if (conf->channel_type == NL80211_CHAN_HT40PLUS) |
| 2861 | cmd->channel_flags |= cpu_to_le32(0x000000900); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2862 | |
| 2863 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2864 | kfree(cmd); |
| 2865 | |
| 2866 | return rc; |
| 2867 | } |
| 2868 | |
| 2869 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2870 | * CMD_SET_AID. |
| 2871 | */ |
| 2872 | #define MWL8K_FRAME_PROT_DISABLED 0x00 |
| 2873 | #define MWL8K_FRAME_PROT_11G 0x07 |
| 2874 | #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02 |
| 2875 | #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06 |
| 2876 | |
| 2877 | struct mwl8k_cmd_update_set_aid { |
| 2878 | struct mwl8k_cmd_pkt header; |
| 2879 | __le16 aid; |
| 2880 | |
| 2881 | /* AP's MAC address (BSSID) */ |
| 2882 | __u8 bssid[ETH_ALEN]; |
| 2883 | __le16 protection_mode; |
| 2884 | __u8 supp_rates[14]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2885 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2886 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 2887 | static void legacy_rate_mask_to_array(u8 *rates, u32 mask) |
| 2888 | { |
| 2889 | int i; |
| 2890 | int j; |
| 2891 | |
| 2892 | /* |
| 2893 | * Clear nonstandard rates 4 and 13. |
| 2894 | */ |
| 2895 | mask &= 0x1fef; |
| 2896 | |
| 2897 | for (i = 0, j = 0; i < 14; i++) { |
| 2898 | if (mask & (1 << i)) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2899 | rates[j++] = mwl8k_rates_24[i].hw_value; |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 2900 | } |
| 2901 | } |
| 2902 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2903 | static int |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 2904 | mwl8k_cmd_set_aid(struct ieee80211_hw *hw, |
| 2905 | struct ieee80211_vif *vif, u32 legacy_rate_mask) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2906 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2907 | struct mwl8k_cmd_update_set_aid *cmd; |
| 2908 | u16 prot_mode; |
| 2909 | int rc; |
| 2910 | |
| 2911 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2912 | if (cmd == NULL) |
| 2913 | return -ENOMEM; |
| 2914 | |
| 2915 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID); |
| 2916 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 2917 | cmd->aid = cpu_to_le16(vif->bss_conf.aid); |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 2918 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2919 | |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 2920 | if (vif->bss_conf.use_cts_prot) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2921 | prot_mode = MWL8K_FRAME_PROT_11G; |
| 2922 | } else { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 2923 | switch (vif->bss_conf.ht_operation_mode & |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2924 | IEEE80211_HT_OP_MODE_PROTECTION) { |
| 2925 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 2926 | prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY; |
| 2927 | break; |
| 2928 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 2929 | prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL; |
| 2930 | break; |
| 2931 | default: |
| 2932 | prot_mode = MWL8K_FRAME_PROT_DISABLED; |
| 2933 | break; |
| 2934 | } |
| 2935 | } |
| 2936 | cmd->protection_mode = cpu_to_le16(prot_mode); |
| 2937 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 2938 | legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2939 | |
| 2940 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2941 | kfree(cmd); |
| 2942 | |
| 2943 | return rc; |
| 2944 | } |
| 2945 | |
| 2946 | /* |
| 2947 | * CMD_SET_RATE. |
| 2948 | */ |
| 2949 | struct mwl8k_cmd_set_rate { |
| 2950 | struct mwl8k_cmd_pkt header; |
| 2951 | __u8 legacy_rates[14]; |
| 2952 | |
| 2953 | /* Bitmap for supported MCS codes. */ |
| 2954 | __u8 mcs_set[16]; |
| 2955 | __u8 reserved[16]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2956 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2957 | |
| 2958 | static int |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 2959 | mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 2960 | u32 legacy_rate_mask, u8 *mcs_rates) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2961 | { |
| 2962 | struct mwl8k_cmd_set_rate *cmd; |
| 2963 | int rc; |
| 2964 | |
| 2965 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2966 | if (cmd == NULL) |
| 2967 | return -ENOMEM; |
| 2968 | |
| 2969 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE); |
| 2970 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 2971 | legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 2972 | memcpy(cmd->mcs_set, mcs_rates, 16); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2973 | |
| 2974 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2975 | kfree(cmd); |
| 2976 | |
| 2977 | return rc; |
| 2978 | } |
| 2979 | |
| 2980 | /* |
| 2981 | * CMD_FINALIZE_JOIN. |
| 2982 | */ |
| 2983 | #define MWL8K_FJ_BEACON_MAXLEN 128 |
| 2984 | |
| 2985 | struct mwl8k_cmd_finalize_join { |
| 2986 | struct mwl8k_cmd_pkt header; |
| 2987 | __le32 sleep_interval; /* Number of beacon periods to sleep */ |
| 2988 | __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2989 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2990 | |
| 2991 | static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame, |
| 2992 | int framelen, int dtim) |
| 2993 | { |
| 2994 | struct mwl8k_cmd_finalize_join *cmd; |
| 2995 | struct ieee80211_mgmt *payload = frame; |
| 2996 | int payload_len; |
| 2997 | int rc; |
| 2998 | |
| 2999 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3000 | if (cmd == NULL) |
| 3001 | return -ENOMEM; |
| 3002 | |
| 3003 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN); |
| 3004 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3005 | cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1); |
| 3006 | |
| 3007 | payload_len = framelen - ieee80211_hdrlen(payload->frame_control); |
| 3008 | if (payload_len < 0) |
| 3009 | payload_len = 0; |
| 3010 | else if (payload_len > MWL8K_FJ_BEACON_MAXLEN) |
| 3011 | payload_len = MWL8K_FJ_BEACON_MAXLEN; |
| 3012 | |
| 3013 | memcpy(cmd->beacon_data, &payload->u.beacon, payload_len); |
| 3014 | |
| 3015 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3016 | kfree(cmd); |
| 3017 | |
| 3018 | return rc; |
| 3019 | } |
| 3020 | |
| 3021 | /* |
| 3022 | * CMD_SET_RTS_THRESHOLD. |
| 3023 | */ |
| 3024 | struct mwl8k_cmd_set_rts_threshold { |
| 3025 | struct mwl8k_cmd_pkt header; |
| 3026 | __le16 action; |
| 3027 | __le16 threshold; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3028 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3029 | |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 3030 | static int |
| 3031 | mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3032 | { |
| 3033 | struct mwl8k_cmd_set_rts_threshold *cmd; |
| 3034 | int rc; |
| 3035 | |
| 3036 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3037 | if (cmd == NULL) |
| 3038 | return -ENOMEM; |
| 3039 | |
| 3040 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD); |
| 3041 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 3042 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 3043 | cmd->threshold = cpu_to_le16(rts_thresh); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3044 | |
| 3045 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3046 | kfree(cmd); |
| 3047 | |
| 3048 | return rc; |
| 3049 | } |
| 3050 | |
| 3051 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3052 | * CMD_SET_SLOT. |
| 3053 | */ |
| 3054 | struct mwl8k_cmd_set_slot { |
| 3055 | struct mwl8k_cmd_pkt header; |
| 3056 | __le16 action; |
| 3057 | __u8 short_slot; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3058 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3059 | |
Lennert Buytenhek | 5539bb5 | 2009-07-16 16:06:53 +0200 | [diff] [blame] | 3060 | static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3061 | { |
| 3062 | struct mwl8k_cmd_set_slot *cmd; |
| 3063 | int rc; |
| 3064 | |
| 3065 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3066 | if (cmd == NULL) |
| 3067 | return -ENOMEM; |
| 3068 | |
| 3069 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT); |
| 3070 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3071 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
Lennert Buytenhek | 5539bb5 | 2009-07-16 16:06:53 +0200 | [diff] [blame] | 3072 | cmd->short_slot = short_slot_time; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3073 | |
| 3074 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3075 | kfree(cmd); |
| 3076 | |
| 3077 | return rc; |
| 3078 | } |
| 3079 | |
| 3080 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3081 | * CMD_SET_EDCA_PARAMS. |
| 3082 | */ |
| 3083 | struct mwl8k_cmd_set_edca_params { |
| 3084 | struct mwl8k_cmd_pkt header; |
| 3085 | |
| 3086 | /* See MWL8K_SET_EDCA_XXX below */ |
| 3087 | __le16 action; |
| 3088 | |
| 3089 | /* TX opportunity in units of 32 us */ |
| 3090 | __le16 txop; |
| 3091 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3092 | union { |
| 3093 | struct { |
| 3094 | /* Log exponent of max contention period: 0...15 */ |
| 3095 | __le32 log_cw_max; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3096 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3097 | /* Log exponent of min contention period: 0...15 */ |
| 3098 | __le32 log_cw_min; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3099 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3100 | /* Adaptive interframe spacing in units of 32us */ |
| 3101 | __u8 aifs; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3102 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3103 | /* TX queue to configure */ |
| 3104 | __u8 txq; |
| 3105 | } ap; |
| 3106 | struct { |
| 3107 | /* Log exponent of max contention period: 0...15 */ |
| 3108 | __u8 log_cw_max; |
| 3109 | |
| 3110 | /* Log exponent of min contention period: 0...15 */ |
| 3111 | __u8 log_cw_min; |
| 3112 | |
| 3113 | /* Adaptive interframe spacing in units of 32us */ |
| 3114 | __u8 aifs; |
| 3115 | |
| 3116 | /* TX queue to configure */ |
| 3117 | __u8 txq; |
| 3118 | } sta; |
| 3119 | }; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3120 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3121 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3122 | #define MWL8K_SET_EDCA_CW 0x01 |
| 3123 | #define MWL8K_SET_EDCA_TXOP 0x02 |
| 3124 | #define MWL8K_SET_EDCA_AIFS 0x04 |
| 3125 | |
| 3126 | #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \ |
| 3127 | MWL8K_SET_EDCA_TXOP | \ |
| 3128 | MWL8K_SET_EDCA_AIFS) |
| 3129 | |
| 3130 | static int |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3131 | mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum, |
| 3132 | __u16 cw_min, __u16 cw_max, |
| 3133 | __u8 aifs, __u16 txop) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3134 | { |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3135 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3136 | struct mwl8k_cmd_set_edca_params *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3137 | int rc; |
| 3138 | |
| 3139 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3140 | if (cmd == NULL) |
| 3141 | return -ENOMEM; |
| 3142 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3143 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS); |
| 3144 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3145 | cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL); |
| 3146 | cmd->txop = cpu_to_le16(txop); |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3147 | if (priv->ap_fw) { |
| 3148 | cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1)); |
| 3149 | cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1)); |
| 3150 | cmd->ap.aifs = aifs; |
| 3151 | cmd->ap.txq = qnum; |
| 3152 | } else { |
| 3153 | cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1); |
| 3154 | cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1); |
| 3155 | cmd->sta.aifs = aifs; |
| 3156 | cmd->sta.txq = qnum; |
| 3157 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3158 | |
| 3159 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3160 | kfree(cmd); |
| 3161 | |
| 3162 | return rc; |
| 3163 | } |
| 3164 | |
| 3165 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3166 | * CMD_SET_WMM_MODE. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3167 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3168 | struct mwl8k_cmd_set_wmm_mode { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3169 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3170 | __le16 action; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3171 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3172 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3173 | static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3174 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3175 | struct mwl8k_priv *priv = hw->priv; |
| 3176 | struct mwl8k_cmd_set_wmm_mode *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3177 | int rc; |
| 3178 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3179 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3180 | if (cmd == NULL) |
| 3181 | return -ENOMEM; |
| 3182 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3183 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3184 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3185 | cmd->action = cpu_to_le16(!!enable); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3186 | |
| 3187 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3188 | kfree(cmd); |
Lennert Buytenhek | 16cec43 | 2009-11-30 18:14:23 +0100 | [diff] [blame] | 3189 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3190 | if (!rc) |
| 3191 | priv->wmm_enabled = enable; |
| 3192 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3193 | return rc; |
| 3194 | } |
| 3195 | |
| 3196 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3197 | * CMD_MIMO_CONFIG. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3198 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3199 | struct mwl8k_cmd_mimo_config { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3200 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3201 | __le32 action; |
| 3202 | __u8 rx_antenna_map; |
| 3203 | __u8 tx_antenna_map; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3204 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3205 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3206 | static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3207 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3208 | struct mwl8k_cmd_mimo_config *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3209 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3210 | |
| 3211 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3212 | if (cmd == NULL) |
| 3213 | return -ENOMEM; |
| 3214 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3215 | cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3216 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3217 | cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET); |
| 3218 | cmd->rx_antenna_map = rx; |
| 3219 | cmd->tx_antenna_map = tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3220 | |
| 3221 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3222 | kfree(cmd); |
| 3223 | |
| 3224 | return rc; |
| 3225 | } |
| 3226 | |
| 3227 | /* |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3228 | * CMD_USE_FIXED_RATE (STA version). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3229 | */ |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3230 | struct mwl8k_cmd_use_fixed_rate_sta { |
| 3231 | struct mwl8k_cmd_pkt header; |
| 3232 | __le32 action; |
| 3233 | __le32 allow_rate_drop; |
| 3234 | __le32 num_rates; |
| 3235 | struct { |
| 3236 | __le32 is_ht_rate; |
| 3237 | __le32 enable_retry; |
| 3238 | __le32 rate; |
| 3239 | __le32 retry_count; |
| 3240 | } rate_entry[8]; |
| 3241 | __le32 rate_type; |
| 3242 | __le32 reserved1; |
| 3243 | __le32 reserved2; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3244 | } __packed; |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3245 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3246 | #define MWL8K_USE_AUTO_RATE 0x0002 |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3247 | #define MWL8K_UCAST_RATE 0 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3248 | |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3249 | static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3250 | { |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3251 | struct mwl8k_cmd_use_fixed_rate_sta *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3252 | int rc; |
| 3253 | |
| 3254 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3255 | if (cmd == NULL) |
| 3256 | return -ENOMEM; |
| 3257 | |
| 3258 | cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE); |
| 3259 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3260 | cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE); |
| 3261 | cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3262 | |
| 3263 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3264 | kfree(cmd); |
| 3265 | |
| 3266 | return rc; |
| 3267 | } |
| 3268 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3269 | /* |
Lennert Buytenhek | 088aab8 | 2010-01-08 18:30:36 +0100 | [diff] [blame] | 3270 | * CMD_USE_FIXED_RATE (AP version). |
| 3271 | */ |
| 3272 | struct mwl8k_cmd_use_fixed_rate_ap { |
| 3273 | struct mwl8k_cmd_pkt header; |
| 3274 | __le32 action; |
| 3275 | __le32 allow_rate_drop; |
| 3276 | __le32 num_rates; |
| 3277 | struct mwl8k_rate_entry_ap { |
| 3278 | __le32 is_ht_rate; |
| 3279 | __le32 enable_retry; |
| 3280 | __le32 rate; |
| 3281 | __le32 retry_count; |
| 3282 | } rate_entry[4]; |
| 3283 | u8 multicast_rate; |
| 3284 | u8 multicast_rate_type; |
| 3285 | u8 management_rate; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3286 | } __packed; |
Lennert Buytenhek | 088aab8 | 2010-01-08 18:30:36 +0100 | [diff] [blame] | 3287 | |
| 3288 | static int |
| 3289 | mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt) |
| 3290 | { |
| 3291 | struct mwl8k_cmd_use_fixed_rate_ap *cmd; |
| 3292 | int rc; |
| 3293 | |
| 3294 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3295 | if (cmd == NULL) |
| 3296 | return -ENOMEM; |
| 3297 | |
| 3298 | cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE); |
| 3299 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3300 | cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE); |
| 3301 | cmd->multicast_rate = mcast; |
| 3302 | cmd->management_rate = mgmt; |
| 3303 | |
| 3304 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3305 | kfree(cmd); |
| 3306 | |
| 3307 | return rc; |
| 3308 | } |
| 3309 | |
| 3310 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3311 | * CMD_ENABLE_SNIFFER. |
| 3312 | */ |
| 3313 | struct mwl8k_cmd_enable_sniffer { |
| 3314 | struct mwl8k_cmd_pkt header; |
| 3315 | __le32 action; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3316 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3317 | |
| 3318 | static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable) |
| 3319 | { |
| 3320 | struct mwl8k_cmd_enable_sniffer *cmd; |
| 3321 | int rc; |
| 3322 | |
| 3323 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3324 | if (cmd == NULL) |
| 3325 | return -ENOMEM; |
| 3326 | |
| 3327 | cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER); |
| 3328 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3329 | cmd->action = cpu_to_le32(!!enable); |
| 3330 | |
| 3331 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3332 | kfree(cmd); |
| 3333 | |
| 3334 | return rc; |
| 3335 | } |
| 3336 | |
| 3337 | /* |
| 3338 | * CMD_SET_MAC_ADDR. |
| 3339 | */ |
| 3340 | struct mwl8k_cmd_set_mac_addr { |
| 3341 | struct mwl8k_cmd_pkt header; |
| 3342 | union { |
| 3343 | struct { |
| 3344 | __le16 mac_type; |
| 3345 | __u8 mac_addr[ETH_ALEN]; |
| 3346 | } mbss; |
| 3347 | __u8 mac_addr[ETH_ALEN]; |
| 3348 | }; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3349 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3350 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3351 | #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0 |
| 3352 | #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1 |
| 3353 | #define MWL8K_MAC_TYPE_PRIMARY_AP 2 |
| 3354 | #define MWL8K_MAC_TYPE_SECONDARY_AP 3 |
Lennert Buytenhek | a9e00b1 | 2010-01-08 18:31:30 +0100 | [diff] [blame] | 3355 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3356 | static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, |
| 3357 | struct ieee80211_vif *vif, u8 *mac) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3358 | { |
| 3359 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3360 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3361 | struct mwl8k_cmd_set_mac_addr *cmd; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3362 | int mac_type; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3363 | int rc; |
| 3364 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3365 | mac_type = MWL8K_MAC_TYPE_PRIMARY_AP; |
| 3366 | if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) { |
| 3367 | if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported)) |
| 3368 | mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT; |
| 3369 | else |
| 3370 | mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT; |
| 3371 | } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) { |
| 3372 | if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported)) |
| 3373 | mac_type = MWL8K_MAC_TYPE_PRIMARY_AP; |
| 3374 | else |
| 3375 | mac_type = MWL8K_MAC_TYPE_SECONDARY_AP; |
| 3376 | } |
| 3377 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3378 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3379 | if (cmd == NULL) |
| 3380 | return -ENOMEM; |
| 3381 | |
| 3382 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR); |
| 3383 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3384 | if (priv->ap_fw) { |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3385 | cmd->mbss.mac_type = cpu_to_le16(mac_type); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3386 | memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN); |
| 3387 | } else { |
| 3388 | memcpy(cmd->mac_addr, mac, ETH_ALEN); |
| 3389 | } |
| 3390 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3391 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3392 | kfree(cmd); |
| 3393 | |
| 3394 | return rc; |
| 3395 | } |
| 3396 | |
| 3397 | /* |
| 3398 | * CMD_SET_RATEADAPT_MODE. |
| 3399 | */ |
| 3400 | struct mwl8k_cmd_set_rate_adapt_mode { |
| 3401 | struct mwl8k_cmd_pkt header; |
| 3402 | __le16 action; |
| 3403 | __le16 mode; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3404 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3405 | |
| 3406 | static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode) |
| 3407 | { |
| 3408 | struct mwl8k_cmd_set_rate_adapt_mode *cmd; |
| 3409 | int rc; |
| 3410 | |
| 3411 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3412 | if (cmd == NULL) |
| 3413 | return -ENOMEM; |
| 3414 | |
| 3415 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE); |
| 3416 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3417 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 3418 | cmd->mode = cpu_to_le16(mode); |
| 3419 | |
| 3420 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3421 | kfree(cmd); |
| 3422 | |
| 3423 | return rc; |
| 3424 | } |
| 3425 | |
| 3426 | /* |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3427 | * CMD_GET_WATCHDOG_BITMAP. |
| 3428 | */ |
| 3429 | struct mwl8k_cmd_get_watchdog_bitmap { |
| 3430 | struct mwl8k_cmd_pkt header; |
| 3431 | u8 bitmap; |
| 3432 | } __packed; |
| 3433 | |
| 3434 | static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap) |
| 3435 | { |
| 3436 | struct mwl8k_cmd_get_watchdog_bitmap *cmd; |
| 3437 | int rc; |
| 3438 | |
| 3439 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3440 | if (cmd == NULL) |
| 3441 | return -ENOMEM; |
| 3442 | |
| 3443 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP); |
| 3444 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3445 | |
| 3446 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3447 | if (!rc) |
| 3448 | *bitmap = cmd->bitmap; |
| 3449 | |
| 3450 | kfree(cmd); |
| 3451 | |
| 3452 | return rc; |
| 3453 | } |
| 3454 | |
| 3455 | #define INVALID_BA 0xAA |
| 3456 | static void mwl8k_watchdog_ba_events(struct work_struct *work) |
| 3457 | { |
| 3458 | int rc; |
| 3459 | u8 bitmap = 0, stream_index; |
| 3460 | struct mwl8k_ampdu_stream *streams; |
| 3461 | struct mwl8k_priv *priv = |
| 3462 | container_of(work, struct mwl8k_priv, watchdog_ba_handle); |
| 3463 | |
| 3464 | rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap); |
| 3465 | if (rc) |
| 3466 | return; |
| 3467 | |
| 3468 | if (bitmap == INVALID_BA) |
| 3469 | return; |
| 3470 | |
| 3471 | /* the bitmap is the hw queue number. Map it to the ampdu queue. */ |
| 3472 | stream_index = bitmap - MWL8K_TX_WMM_QUEUES; |
| 3473 | |
| 3474 | BUG_ON(stream_index >= priv->num_ampdu_queues); |
| 3475 | |
| 3476 | streams = &priv->ampdu[stream_index]; |
| 3477 | |
| 3478 | if (streams->state == AMPDU_STREAM_ACTIVE) |
| 3479 | ieee80211_stop_tx_ba_session(streams->sta, streams->tid); |
| 3480 | |
| 3481 | return; |
| 3482 | } |
| 3483 | |
| 3484 | |
| 3485 | /* |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3486 | * CMD_BSS_START. |
| 3487 | */ |
| 3488 | struct mwl8k_cmd_bss_start { |
| 3489 | struct mwl8k_cmd_pkt header; |
| 3490 | __le32 enable; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3491 | } __packed; |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3492 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3493 | static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, |
| 3494 | struct ieee80211_vif *vif, int enable) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3495 | { |
| 3496 | struct mwl8k_cmd_bss_start *cmd; |
| 3497 | int rc; |
| 3498 | |
| 3499 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3500 | if (cmd == NULL) |
| 3501 | return -ENOMEM; |
| 3502 | |
| 3503 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START); |
| 3504 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3505 | cmd->enable = cpu_to_le32(enable); |
| 3506 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3507 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3508 | kfree(cmd); |
| 3509 | |
| 3510 | return rc; |
| 3511 | } |
| 3512 | |
| 3513 | /* |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3514 | * CMD_BASTREAM. |
| 3515 | */ |
| 3516 | |
| 3517 | /* |
| 3518 | * UPSTREAM is tx direction |
| 3519 | */ |
| 3520 | #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00 |
| 3521 | #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01 |
| 3522 | |
| 3523 | enum { |
| 3524 | MWL8K_BA_CREATE, |
| 3525 | MWL8K_BA_UPDATE, |
| 3526 | MWL8K_BA_DESTROY, |
| 3527 | MWL8K_BA_FLUSH, |
| 3528 | MWL8K_BA_CHECK, |
| 3529 | } ba_stream_action_type; |
| 3530 | |
| 3531 | |
| 3532 | struct mwl8k_create_ba_stream { |
| 3533 | __le32 flags; |
| 3534 | __le32 idle_thrs; |
| 3535 | __le32 bar_thrs; |
| 3536 | __le32 window_size; |
| 3537 | u8 peer_mac_addr[6]; |
| 3538 | u8 dialog_token; |
| 3539 | u8 tid; |
| 3540 | u8 queue_id; |
| 3541 | u8 param_info; |
| 3542 | __le32 ba_context; |
| 3543 | u8 reset_seq_no_flag; |
| 3544 | __le16 curr_seq_no; |
| 3545 | u8 sta_src_mac_addr[6]; |
| 3546 | } __packed; |
| 3547 | |
| 3548 | struct mwl8k_destroy_ba_stream { |
| 3549 | __le32 flags; |
| 3550 | __le32 ba_context; |
| 3551 | } __packed; |
| 3552 | |
| 3553 | struct mwl8k_cmd_bastream { |
| 3554 | struct mwl8k_cmd_pkt header; |
| 3555 | __le32 action; |
| 3556 | union { |
| 3557 | struct mwl8k_create_ba_stream create_params; |
| 3558 | struct mwl8k_destroy_ba_stream destroy_params; |
| 3559 | }; |
| 3560 | } __packed; |
| 3561 | |
| 3562 | static int |
| 3563 | mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream) |
| 3564 | { |
| 3565 | struct mwl8k_cmd_bastream *cmd; |
| 3566 | int rc; |
| 3567 | |
| 3568 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3569 | if (cmd == NULL) |
| 3570 | return -ENOMEM; |
| 3571 | |
| 3572 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3573 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3574 | |
| 3575 | cmd->action = cpu_to_le32(MWL8K_BA_CHECK); |
| 3576 | |
| 3577 | cmd->create_params.queue_id = stream->idx; |
| 3578 | memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr, |
| 3579 | ETH_ALEN); |
| 3580 | cmd->create_params.tid = stream->tid; |
| 3581 | |
| 3582 | cmd->create_params.flags = |
| 3583 | cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) | |
| 3584 | cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM); |
| 3585 | |
| 3586 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3587 | |
| 3588 | kfree(cmd); |
| 3589 | |
| 3590 | return rc; |
| 3591 | } |
| 3592 | |
| 3593 | static int |
| 3594 | mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream, |
| 3595 | u8 buf_size) |
| 3596 | { |
| 3597 | struct mwl8k_cmd_bastream *cmd; |
| 3598 | int rc; |
| 3599 | |
| 3600 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3601 | if (cmd == NULL) |
| 3602 | return -ENOMEM; |
| 3603 | |
| 3604 | |
| 3605 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3606 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3607 | |
| 3608 | cmd->action = cpu_to_le32(MWL8K_BA_CREATE); |
| 3609 | |
| 3610 | cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size); |
| 3611 | cmd->create_params.window_size = cpu_to_le32((u32)buf_size); |
| 3612 | cmd->create_params.queue_id = stream->idx; |
| 3613 | |
| 3614 | memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN); |
| 3615 | cmd->create_params.tid = stream->tid; |
| 3616 | cmd->create_params.curr_seq_no = cpu_to_le16(0); |
| 3617 | cmd->create_params.reset_seq_no_flag = 1; |
| 3618 | |
| 3619 | cmd->create_params.param_info = |
| 3620 | (stream->sta->ht_cap.ampdu_factor & |
| 3621 | IEEE80211_HT_AMPDU_PARM_FACTOR) | |
| 3622 | ((stream->sta->ht_cap.ampdu_density << 2) & |
| 3623 | IEEE80211_HT_AMPDU_PARM_DENSITY); |
| 3624 | |
| 3625 | cmd->create_params.flags = |
| 3626 | cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE | |
| 3627 | BASTREAM_FLAG_DIRECTION_UPSTREAM); |
| 3628 | |
| 3629 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3630 | |
| 3631 | wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n", |
| 3632 | stream->sta->addr, stream->tid); |
| 3633 | kfree(cmd); |
| 3634 | |
| 3635 | return rc; |
| 3636 | } |
| 3637 | |
| 3638 | static void mwl8k_destroy_ba(struct ieee80211_hw *hw, |
| 3639 | struct mwl8k_ampdu_stream *stream) |
| 3640 | { |
| 3641 | struct mwl8k_cmd_bastream *cmd; |
| 3642 | |
| 3643 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3644 | if (cmd == NULL) |
| 3645 | return; |
| 3646 | |
| 3647 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3648 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3649 | cmd->action = cpu_to_le32(MWL8K_BA_DESTROY); |
| 3650 | |
| 3651 | cmd->destroy_params.ba_context = cpu_to_le32(stream->idx); |
| 3652 | mwl8k_post_cmd(hw, &cmd->header); |
| 3653 | |
| 3654 | wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", stream->idx); |
| 3655 | |
| 3656 | kfree(cmd); |
| 3657 | } |
| 3658 | |
| 3659 | /* |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3660 | * CMD_SET_NEW_STN. |
| 3661 | */ |
| 3662 | struct mwl8k_cmd_set_new_stn { |
| 3663 | struct mwl8k_cmd_pkt header; |
| 3664 | __le16 aid; |
| 3665 | __u8 mac_addr[6]; |
| 3666 | __le16 stn_id; |
| 3667 | __le16 action; |
| 3668 | __le16 rsvd; |
| 3669 | __le32 legacy_rates; |
| 3670 | __u8 ht_rates[4]; |
| 3671 | __le16 cap_info; |
| 3672 | __le16 ht_capabilities_info; |
| 3673 | __u8 mac_ht_param_info; |
| 3674 | __u8 rev; |
| 3675 | __u8 control_channel; |
| 3676 | __u8 add_channel; |
| 3677 | __le16 op_mode; |
| 3678 | __le16 stbc; |
| 3679 | __u8 add_qos_info; |
| 3680 | __u8 is_qos_sta; |
| 3681 | __le32 fw_sta_ptr; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3682 | } __packed; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3683 | |
| 3684 | #define MWL8K_STA_ACTION_ADD 0 |
| 3685 | #define MWL8K_STA_ACTION_REMOVE 2 |
| 3686 | |
| 3687 | static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw, |
| 3688 | struct ieee80211_vif *vif, |
| 3689 | struct ieee80211_sta *sta) |
| 3690 | { |
| 3691 | struct mwl8k_cmd_set_new_stn *cmd; |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 3692 | u32 rates; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3693 | int rc; |
| 3694 | |
| 3695 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3696 | if (cmd == NULL) |
| 3697 | return -ENOMEM; |
| 3698 | |
| 3699 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 3700 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3701 | cmd->aid = cpu_to_le16(sta->aid); |
| 3702 | memcpy(cmd->mac_addr, sta->addr, ETH_ALEN); |
| 3703 | cmd->stn_id = cpu_to_le16(sta->aid); |
| 3704 | cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD); |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 3705 | if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) |
| 3706 | rates = sta->supp_rates[IEEE80211_BAND_2GHZ]; |
| 3707 | else |
| 3708 | rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 3709 | cmd->legacy_rates = cpu_to_le32(rates); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3710 | if (sta->ht_cap.ht_supported) { |
| 3711 | cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0]; |
| 3712 | cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1]; |
| 3713 | cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2]; |
| 3714 | cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3]; |
| 3715 | cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap); |
| 3716 | cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) | |
| 3717 | ((sta->ht_cap.ampdu_density & 7) << 2); |
| 3718 | cmd->is_qos_sta = 1; |
| 3719 | } |
| 3720 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3721 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3722 | kfree(cmd); |
| 3723 | |
| 3724 | return rc; |
| 3725 | } |
| 3726 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3727 | static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw, |
| 3728 | struct ieee80211_vif *vif) |
| 3729 | { |
| 3730 | struct mwl8k_cmd_set_new_stn *cmd; |
| 3731 | int rc; |
| 3732 | |
| 3733 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3734 | if (cmd == NULL) |
| 3735 | return -ENOMEM; |
| 3736 | |
| 3737 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 3738 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3739 | memcpy(cmd->mac_addr, vif->addr, ETH_ALEN); |
| 3740 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3741 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3742 | kfree(cmd); |
| 3743 | |
| 3744 | return rc; |
| 3745 | } |
| 3746 | |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3747 | static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw, |
| 3748 | struct ieee80211_vif *vif, u8 *addr) |
| 3749 | { |
| 3750 | struct mwl8k_cmd_set_new_stn *cmd; |
| 3751 | int rc; |
| 3752 | |
| 3753 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3754 | if (cmd == NULL) |
| 3755 | return -ENOMEM; |
| 3756 | |
| 3757 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 3758 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3759 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 3760 | cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE); |
| 3761 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3762 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3763 | kfree(cmd); |
| 3764 | |
| 3765 | return rc; |
| 3766 | } |
| 3767 | |
| 3768 | /* |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 3769 | * CMD_UPDATE_ENCRYPTION. |
| 3770 | */ |
| 3771 | |
| 3772 | #define MAX_ENCR_KEY_LENGTH 16 |
| 3773 | #define MIC_KEY_LENGTH 8 |
| 3774 | |
| 3775 | struct mwl8k_cmd_update_encryption { |
| 3776 | struct mwl8k_cmd_pkt header; |
| 3777 | |
| 3778 | __le32 action; |
| 3779 | __le32 reserved; |
| 3780 | __u8 mac_addr[6]; |
| 3781 | __u8 encr_type; |
| 3782 | |
| 3783 | } __attribute__((packed)); |
| 3784 | |
| 3785 | struct mwl8k_cmd_set_key { |
| 3786 | struct mwl8k_cmd_pkt header; |
| 3787 | |
| 3788 | __le32 action; |
| 3789 | __le32 reserved; |
| 3790 | __le16 length; |
| 3791 | __le16 key_type_id; |
| 3792 | __le32 key_info; |
| 3793 | __le32 key_id; |
| 3794 | __le16 key_len; |
| 3795 | __u8 key_material[MAX_ENCR_KEY_LENGTH]; |
| 3796 | __u8 tkip_tx_mic_key[MIC_KEY_LENGTH]; |
| 3797 | __u8 tkip_rx_mic_key[MIC_KEY_LENGTH]; |
| 3798 | __le16 tkip_rsc_low; |
| 3799 | __le32 tkip_rsc_high; |
| 3800 | __le16 tkip_tsc_low; |
| 3801 | __le32 tkip_tsc_high; |
| 3802 | __u8 mac_addr[6]; |
| 3803 | } __attribute__((packed)); |
| 3804 | |
| 3805 | enum { |
| 3806 | MWL8K_ENCR_ENABLE, |
| 3807 | MWL8K_ENCR_SET_KEY, |
| 3808 | MWL8K_ENCR_REMOVE_KEY, |
| 3809 | MWL8K_ENCR_SET_GROUP_KEY, |
| 3810 | }; |
| 3811 | |
| 3812 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0 |
| 3813 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1 |
| 3814 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4 |
| 3815 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7 |
| 3816 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8 |
| 3817 | |
| 3818 | enum { |
| 3819 | MWL8K_ALG_WEP, |
| 3820 | MWL8K_ALG_TKIP, |
| 3821 | MWL8K_ALG_CCMP, |
| 3822 | }; |
| 3823 | |
| 3824 | #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004 |
| 3825 | #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008 |
| 3826 | #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040 |
| 3827 | #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000 |
| 3828 | #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000 |
| 3829 | |
| 3830 | static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw, |
| 3831 | struct ieee80211_vif *vif, |
| 3832 | u8 *addr, |
| 3833 | u8 encr_type) |
| 3834 | { |
| 3835 | struct mwl8k_cmd_update_encryption *cmd; |
| 3836 | int rc; |
| 3837 | |
| 3838 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3839 | if (cmd == NULL) |
| 3840 | return -ENOMEM; |
| 3841 | |
| 3842 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION); |
| 3843 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3844 | cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE); |
| 3845 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 3846 | cmd->encr_type = encr_type; |
| 3847 | |
| 3848 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 3849 | kfree(cmd); |
| 3850 | |
| 3851 | return rc; |
| 3852 | } |
| 3853 | |
| 3854 | static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd, |
| 3855 | u8 *addr, |
| 3856 | struct ieee80211_key_conf *key) |
| 3857 | { |
| 3858 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION); |
| 3859 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3860 | cmd->length = cpu_to_le16(sizeof(*cmd) - |
| 3861 | offsetof(struct mwl8k_cmd_set_key, length)); |
| 3862 | cmd->key_id = cpu_to_le32(key->keyidx); |
| 3863 | cmd->key_len = cpu_to_le16(key->keylen); |
| 3864 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 3865 | |
| 3866 | switch (key->cipher) { |
| 3867 | case WLAN_CIPHER_SUITE_WEP40: |
| 3868 | case WLAN_CIPHER_SUITE_WEP104: |
| 3869 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP); |
| 3870 | if (key->keyidx == 0) |
| 3871 | cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY); |
| 3872 | |
| 3873 | break; |
| 3874 | case WLAN_CIPHER_SUITE_TKIP: |
| 3875 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP); |
| 3876 | cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 3877 | ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE) |
| 3878 | : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY); |
| 3879 | cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID |
| 3880 | | MWL8K_KEY_FLAG_TSC_VALID); |
| 3881 | break; |
| 3882 | case WLAN_CIPHER_SUITE_CCMP: |
| 3883 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP); |
| 3884 | cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 3885 | ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE) |
| 3886 | : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY); |
| 3887 | break; |
| 3888 | default: |
| 3889 | return -ENOTSUPP; |
| 3890 | } |
| 3891 | |
| 3892 | return 0; |
| 3893 | } |
| 3894 | |
| 3895 | static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw, |
| 3896 | struct ieee80211_vif *vif, |
| 3897 | u8 *addr, |
| 3898 | struct ieee80211_key_conf *key) |
| 3899 | { |
| 3900 | struct mwl8k_cmd_set_key *cmd; |
| 3901 | int rc; |
| 3902 | int keymlen; |
| 3903 | u32 action; |
| 3904 | u8 idx; |
| 3905 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 3906 | |
| 3907 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3908 | if (cmd == NULL) |
| 3909 | return -ENOMEM; |
| 3910 | |
| 3911 | rc = mwl8k_encryption_set_cmd_info(cmd, addr, key); |
| 3912 | if (rc < 0) |
| 3913 | goto done; |
| 3914 | |
| 3915 | idx = key->keyidx; |
| 3916 | |
| 3917 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 3918 | action = MWL8K_ENCR_SET_KEY; |
| 3919 | else |
| 3920 | action = MWL8K_ENCR_SET_GROUP_KEY; |
| 3921 | |
| 3922 | switch (key->cipher) { |
| 3923 | case WLAN_CIPHER_SUITE_WEP40: |
| 3924 | case WLAN_CIPHER_SUITE_WEP104: |
| 3925 | if (!mwl8k_vif->wep_key_conf[idx].enabled) { |
| 3926 | memcpy(mwl8k_vif->wep_key_conf[idx].key, key, |
| 3927 | sizeof(*key) + key->keylen); |
| 3928 | mwl8k_vif->wep_key_conf[idx].enabled = 1; |
| 3929 | } |
| 3930 | |
| 3931 | keymlen = 0; |
| 3932 | action = MWL8K_ENCR_SET_KEY; |
| 3933 | break; |
| 3934 | case WLAN_CIPHER_SUITE_TKIP: |
| 3935 | keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH; |
| 3936 | break; |
| 3937 | case WLAN_CIPHER_SUITE_CCMP: |
| 3938 | keymlen = key->keylen; |
| 3939 | break; |
| 3940 | default: |
| 3941 | rc = -ENOTSUPP; |
| 3942 | goto done; |
| 3943 | } |
| 3944 | |
| 3945 | memcpy(cmd->key_material, key->key, keymlen); |
| 3946 | cmd->action = cpu_to_le32(action); |
| 3947 | |
| 3948 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 3949 | done: |
| 3950 | kfree(cmd); |
| 3951 | |
| 3952 | return rc; |
| 3953 | } |
| 3954 | |
| 3955 | static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw, |
| 3956 | struct ieee80211_vif *vif, |
| 3957 | u8 *addr, |
| 3958 | struct ieee80211_key_conf *key) |
| 3959 | { |
| 3960 | struct mwl8k_cmd_set_key *cmd; |
| 3961 | int rc; |
| 3962 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 3963 | |
| 3964 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3965 | if (cmd == NULL) |
| 3966 | return -ENOMEM; |
| 3967 | |
| 3968 | rc = mwl8k_encryption_set_cmd_info(cmd, addr, key); |
| 3969 | if (rc < 0) |
| 3970 | goto done; |
| 3971 | |
| 3972 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3973 | WLAN_CIPHER_SUITE_WEP104) |
| 3974 | mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0; |
| 3975 | |
| 3976 | cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY); |
| 3977 | |
| 3978 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 3979 | done: |
| 3980 | kfree(cmd); |
| 3981 | |
| 3982 | return rc; |
| 3983 | } |
| 3984 | |
| 3985 | static int mwl8k_set_key(struct ieee80211_hw *hw, |
| 3986 | enum set_key_cmd cmd_param, |
| 3987 | struct ieee80211_vif *vif, |
| 3988 | struct ieee80211_sta *sta, |
| 3989 | struct ieee80211_key_conf *key) |
| 3990 | { |
| 3991 | int rc = 0; |
| 3992 | u8 encr_type; |
| 3993 | u8 *addr; |
| 3994 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 3995 | |
| 3996 | if (vif->type == NL80211_IFTYPE_STATION) |
| 3997 | return -EOPNOTSUPP; |
| 3998 | |
| 3999 | if (sta == NULL) |
| 4000 | addr = hw->wiphy->perm_addr; |
| 4001 | else |
| 4002 | addr = sta->addr; |
| 4003 | |
| 4004 | if (cmd_param == SET_KEY) { |
| 4005 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 4006 | rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key); |
| 4007 | if (rc) |
| 4008 | goto out; |
| 4009 | |
| 4010 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40) |
| 4011 | || (key->cipher == WLAN_CIPHER_SUITE_WEP104)) |
| 4012 | encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP; |
| 4013 | else |
| 4014 | encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED; |
| 4015 | |
| 4016 | rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr, |
| 4017 | encr_type); |
| 4018 | if (rc) |
| 4019 | goto out; |
| 4020 | |
| 4021 | mwl8k_vif->is_hw_crypto_enabled = true; |
| 4022 | |
| 4023 | } else { |
| 4024 | rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key); |
| 4025 | |
| 4026 | if (rc) |
| 4027 | goto out; |
| 4028 | |
| 4029 | mwl8k_vif->is_hw_crypto_enabled = false; |
| 4030 | |
| 4031 | } |
| 4032 | out: |
| 4033 | return rc; |
| 4034 | } |
| 4035 | |
| 4036 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4037 | * CMD_UPDATE_STADB. |
| 4038 | */ |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4039 | struct ewc_ht_info { |
| 4040 | __le16 control1; |
| 4041 | __le16 control2; |
| 4042 | __le16 control3; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4043 | } __packed; |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4044 | |
| 4045 | struct peer_capability_info { |
| 4046 | /* Peer type - AP vs. STA. */ |
| 4047 | __u8 peer_type; |
| 4048 | |
| 4049 | /* Basic 802.11 capabilities from assoc resp. */ |
| 4050 | __le16 basic_caps; |
| 4051 | |
| 4052 | /* Set if peer supports 802.11n high throughput (HT). */ |
| 4053 | __u8 ht_support; |
| 4054 | |
| 4055 | /* Valid if HT is supported. */ |
| 4056 | __le16 ht_caps; |
| 4057 | __u8 extended_ht_caps; |
| 4058 | struct ewc_ht_info ewc_info; |
| 4059 | |
| 4060 | /* Legacy rate table. Intersection of our rates and peer rates. */ |
| 4061 | __u8 legacy_rates[12]; |
| 4062 | |
| 4063 | /* HT rate table. Intersection of our rates and peer rates. */ |
| 4064 | __u8 ht_rates[16]; |
| 4065 | __u8 pad[16]; |
| 4066 | |
| 4067 | /* If set, interoperability mode, no proprietary extensions. */ |
| 4068 | __u8 interop; |
| 4069 | __u8 pad2; |
| 4070 | __u8 station_id; |
| 4071 | __le16 amsdu_enabled; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4072 | } __packed; |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4073 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4074 | struct mwl8k_cmd_update_stadb { |
| 4075 | struct mwl8k_cmd_pkt header; |
| 4076 | |
| 4077 | /* See STADB_ACTION_TYPE */ |
| 4078 | __le32 action; |
| 4079 | |
| 4080 | /* Peer MAC address */ |
| 4081 | __u8 peer_addr[ETH_ALEN]; |
| 4082 | |
| 4083 | __le32 reserved; |
| 4084 | |
| 4085 | /* Peer info - valid during add/update. */ |
| 4086 | struct peer_capability_info peer_info; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4087 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4088 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4089 | #define MWL8K_STA_DB_MODIFY_ENTRY 1 |
| 4090 | #define MWL8K_STA_DB_DEL_ENTRY 2 |
| 4091 | |
| 4092 | /* Peer Entry flags - used to define the type of the peer node */ |
| 4093 | #define MWL8K_PEER_TYPE_ACCESSPOINT 2 |
| 4094 | |
| 4095 | static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw, |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4096 | struct ieee80211_vif *vif, |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4097 | struct ieee80211_sta *sta) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4098 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4099 | struct mwl8k_cmd_update_stadb *cmd; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4100 | struct peer_capability_info *p; |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4101 | u32 rates; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4102 | int rc; |
| 4103 | |
| 4104 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4105 | if (cmd == NULL) |
| 4106 | return -ENOMEM; |
| 4107 | |
| 4108 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB); |
| 4109 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4110 | cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4111 | memcpy(cmd->peer_addr, sta->addr, ETH_ALEN); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4112 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4113 | p = &cmd->peer_info; |
| 4114 | p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT; |
| 4115 | p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4116 | p->ht_support = sta->ht_cap.ht_supported; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 4117 | p->ht_caps = cpu_to_le16(sta->ht_cap.cap); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4118 | p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) | |
| 4119 | ((sta->ht_cap.ampdu_density & 7) << 2); |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4120 | if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) |
| 4121 | rates = sta->supp_rates[IEEE80211_BAND_2GHZ]; |
| 4122 | else |
| 4123 | rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 4124 | legacy_rate_mask_to_array(p->legacy_rates, rates); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4125 | memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16); |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4126 | p->interop = 1; |
| 4127 | p->amsdu_enabled = 0; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4128 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4129 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 4130 | kfree(cmd); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4131 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4132 | return rc ? rc : p->station_id; |
| 4133 | } |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4134 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4135 | static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw, |
| 4136 | struct ieee80211_vif *vif, u8 *addr) |
| 4137 | { |
| 4138 | struct mwl8k_cmd_update_stadb *cmd; |
| 4139 | int rc; |
| 4140 | |
| 4141 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4142 | if (cmd == NULL) |
| 4143 | return -ENOMEM; |
| 4144 | |
| 4145 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB); |
| 4146 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 4147 | cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY); |
| 4148 | memcpy(cmd->peer_addr, addr, ETH_ALEN); |
| 4149 | |
| 4150 | rc = mwl8k_post_cmd(hw, &cmd->header); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4151 | kfree(cmd); |
| 4152 | |
| 4153 | return rc; |
| 4154 | } |
| 4155 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4156 | |
| 4157 | /* |
| 4158 | * Interrupt handling. |
| 4159 | */ |
| 4160 | static irqreturn_t mwl8k_interrupt(int irq, void *dev_id) |
| 4161 | { |
| 4162 | struct ieee80211_hw *hw = dev_id; |
| 4163 | struct mwl8k_priv *priv = hw->priv; |
| 4164 | u32 status; |
| 4165 | |
| 4166 | status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4167 | if (!status) |
| 4168 | return IRQ_NONE; |
| 4169 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4170 | if (status & MWL8K_A2H_INT_TX_DONE) { |
| 4171 | status &= ~MWL8K_A2H_INT_TX_DONE; |
| 4172 | tasklet_schedule(&priv->poll_tx_task); |
| 4173 | } |
| 4174 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4175 | if (status & MWL8K_A2H_INT_RX_READY) { |
| 4176 | status &= ~MWL8K_A2H_INT_RX_READY; |
| 4177 | tasklet_schedule(&priv->poll_rx_task); |
| 4178 | } |
| 4179 | |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 4180 | if (status & MWL8K_A2H_INT_BA_WATCHDOG) { |
| 4181 | status &= ~MWL8K_A2H_INT_BA_WATCHDOG; |
| 4182 | ieee80211_queue_work(hw, &priv->watchdog_ba_handle); |
| 4183 | } |
| 4184 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4185 | if (status) |
| 4186 | iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4187 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4188 | if (status & MWL8K_A2H_INT_OPC_DONE) { |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4189 | if (priv->hostcmd_wait != NULL) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4190 | complete(priv->hostcmd_wait); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | if (status & MWL8K_A2H_INT_QUEUE_EMPTY) { |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4194 | if (!mutex_is_locked(&priv->fw_mutex) && |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 4195 | priv->radio_on && priv->pending_tx_pkts) |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4196 | mwl8k_tx_start(priv); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | return IRQ_HANDLED; |
| 4200 | } |
| 4201 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4202 | static void mwl8k_tx_poll(unsigned long data) |
| 4203 | { |
| 4204 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 4205 | struct mwl8k_priv *priv = hw->priv; |
| 4206 | int limit; |
| 4207 | int i; |
| 4208 | |
| 4209 | limit = 32; |
| 4210 | |
| 4211 | spin_lock_bh(&priv->tx_lock); |
| 4212 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 4213 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4214 | limit -= mwl8k_txq_reclaim(hw, i, limit, 0); |
| 4215 | |
| 4216 | if (!priv->pending_tx_pkts && priv->tx_wait != NULL) { |
| 4217 | complete(priv->tx_wait); |
| 4218 | priv->tx_wait = NULL; |
| 4219 | } |
| 4220 | |
| 4221 | spin_unlock_bh(&priv->tx_lock); |
| 4222 | |
| 4223 | if (limit) { |
| 4224 | writel(~MWL8K_A2H_INT_TX_DONE, |
| 4225 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 4226 | } else { |
| 4227 | tasklet_schedule(&priv->poll_tx_task); |
| 4228 | } |
| 4229 | } |
| 4230 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4231 | static void mwl8k_rx_poll(unsigned long data) |
| 4232 | { |
| 4233 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 4234 | struct mwl8k_priv *priv = hw->priv; |
| 4235 | int limit; |
| 4236 | |
| 4237 | limit = 32; |
| 4238 | limit -= rxq_process(hw, 0, limit); |
| 4239 | limit -= rxq_refill(hw, 0, limit); |
| 4240 | |
| 4241 | if (limit) { |
| 4242 | writel(~MWL8K_A2H_INT_RX_READY, |
| 4243 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 4244 | } else { |
| 4245 | tasklet_schedule(&priv->poll_rx_task); |
| 4246 | } |
| 4247 | } |
| 4248 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4249 | |
| 4250 | /* |
| 4251 | * Core driver operations. |
| 4252 | */ |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 4253 | static void mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4254 | { |
| 4255 | struct mwl8k_priv *priv = hw->priv; |
| 4256 | int index = skb_get_queue_mapping(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4257 | |
Lennert Buytenhek | 9189c10 | 2010-01-12 13:47:32 +0100 | [diff] [blame] | 4258 | if (!priv->radio_on) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4259 | wiphy_debug(hw->wiphy, |
| 4260 | "dropped TX frame since radio disabled\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4261 | dev_kfree_skb(skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 4262 | return; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4263 | } |
| 4264 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 4265 | mwl8k_txq_xmit(hw, index, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4268 | static int mwl8k_start(struct ieee80211_hw *hw) |
| 4269 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4270 | struct mwl8k_priv *priv = hw->priv; |
| 4271 | int rc; |
| 4272 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 4273 | rc = request_irq(priv->pdev->irq, mwl8k_interrupt, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4274 | IRQF_SHARED, MWL8K_NAME, hw); |
| 4275 | if (rc) { |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4276 | priv->irq = -1; |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 4277 | wiphy_err(hw->wiphy, "failed to register IRQ handler\n"); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4278 | return -EIO; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4279 | } |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4280 | priv->irq = priv->pdev->irq; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4281 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4282 | /* Enable TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4283 | tasklet_enable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4284 | tasklet_enable(&priv->poll_rx_task); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4285 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4286 | /* Enable interrupts */ |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 4287 | iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4288 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4289 | rc = mwl8k_fw_lock(hw); |
| 4290 | if (!rc) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4291 | rc = mwl8k_cmd_radio_enable(hw); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4292 | |
Lennert Buytenhek | 5e4cf16 | 2009-10-22 20:21:38 +0200 | [diff] [blame] | 4293 | if (!priv->ap_fw) { |
| 4294 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4295 | rc = mwl8k_cmd_enable_sniffer(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4296 | |
Lennert Buytenhek | 5e4cf16 | 2009-10-22 20:21:38 +0200 | [diff] [blame] | 4297 | if (!rc) |
| 4298 | rc = mwl8k_cmd_set_pre_scan(hw); |
| 4299 | |
| 4300 | if (!rc) |
| 4301 | rc = mwl8k_cmd_set_post_scan(hw, |
| 4302 | "\x00\x00\x00\x00\x00\x00"); |
| 4303 | } |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4304 | |
| 4305 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4306 | rc = mwl8k_cmd_set_rateadapt_mode(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4307 | |
| 4308 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4309 | rc = mwl8k_cmd_set_wmm_mode(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4310 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4311 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4312 | } |
| 4313 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4314 | if (rc) { |
| 4315 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 4316 | free_irq(priv->pdev->irq, hw); |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4317 | priv->irq = -1; |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4318 | tasklet_disable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4319 | tasklet_disable(&priv->poll_rx_task); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4320 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4321 | |
| 4322 | return rc; |
| 4323 | } |
| 4324 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4325 | static void mwl8k_stop(struct ieee80211_hw *hw) |
| 4326 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4327 | struct mwl8k_priv *priv = hw->priv; |
| 4328 | int i; |
| 4329 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4330 | mwl8k_cmd_radio_disable(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4331 | |
| 4332 | ieee80211_stop_queues(hw); |
| 4333 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4334 | /* Disable interrupts */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4335 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4336 | if (priv->irq != -1) { |
| 4337 | free_irq(priv->pdev->irq, hw); |
| 4338 | priv->irq = -1; |
| 4339 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4340 | |
| 4341 | /* Stop finalize join worker */ |
| 4342 | cancel_work_sync(&priv->finalize_join_worker); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 4343 | cancel_work_sync(&priv->watchdog_ba_handle); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4344 | if (priv->beacon_skb != NULL) |
| 4345 | dev_kfree_skb(priv->beacon_skb); |
| 4346 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4347 | /* Stop TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4348 | tasklet_disable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4349 | tasklet_disable(&priv->poll_rx_task); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4350 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4351 | /* Return all skbs to mac80211 */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 4352 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 4353 | mwl8k_txq_reclaim(hw, i, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4354 | } |
| 4355 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4356 | static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image); |
| 4357 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4358 | static int mwl8k_add_interface(struct ieee80211_hw *hw, |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4359 | struct ieee80211_vif *vif) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4360 | { |
| 4361 | struct mwl8k_priv *priv = hw->priv; |
| 4362 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4363 | u32 macids_supported; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4364 | int macid, rc; |
| 4365 | struct mwl8k_device_info *di; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4366 | |
| 4367 | /* |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4368 | * Reject interface creation if sniffer mode is active, as |
| 4369 | * STA operation is mutually exclusive with hardware sniffer |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4370 | * mode. (Sniffer mode is only used on STA firmware.) |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4371 | */ |
| 4372 | if (priv->sniffer_enabled) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4373 | wiphy_info(hw->wiphy, |
| 4374 | "unable to create STA interface because sniffer mode is enabled\n"); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4375 | return -EINVAL; |
| 4376 | } |
| 4377 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4378 | di = priv->device_info; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4379 | switch (vif->type) { |
| 4380 | case NL80211_IFTYPE_AP: |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4381 | if (!priv->ap_fw && di->fw_image_ap) { |
| 4382 | /* we must load the ap fw to meet this request */ |
| 4383 | if (!list_empty(&priv->vif_list)) |
| 4384 | return -EBUSY; |
| 4385 | rc = mwl8k_reload_firmware(hw, di->fw_image_ap); |
| 4386 | if (rc) |
| 4387 | return rc; |
| 4388 | } |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4389 | macids_supported = priv->ap_macids_supported; |
| 4390 | break; |
| 4391 | case NL80211_IFTYPE_STATION: |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4392 | if (priv->ap_fw && di->fw_image_sta) { |
| 4393 | /* we must load the sta fw to meet this request */ |
| 4394 | if (!list_empty(&priv->vif_list)) |
| 4395 | return -EBUSY; |
| 4396 | rc = mwl8k_reload_firmware(hw, di->fw_image_sta); |
| 4397 | if (rc) |
| 4398 | return rc; |
| 4399 | } |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4400 | macids_supported = priv->sta_macids_supported; |
| 4401 | break; |
| 4402 | default: |
| 4403 | return -EINVAL; |
| 4404 | } |
| 4405 | |
| 4406 | macid = ffs(macids_supported & ~priv->macids_used); |
| 4407 | if (!macid--) |
| 4408 | return -EBUSY; |
| 4409 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4410 | /* Setup driver private area. */ |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 4411 | mwl8k_vif = MWL8K_VIF(vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4412 | memset(mwl8k_vif, 0, sizeof(*mwl8k_vif)); |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4413 | mwl8k_vif->vif = vif; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4414 | mwl8k_vif->macid = macid; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4415 | mwl8k_vif->seqno = 0; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 4416 | memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN); |
| 4417 | mwl8k_vif->is_hw_crypto_enabled = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4418 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4419 | /* Set the mac address. */ |
| 4420 | mwl8k_cmd_set_mac_addr(hw, vif, vif->addr); |
| 4421 | |
| 4422 | if (priv->ap_fw) |
| 4423 | mwl8k_cmd_set_new_stn_add_self(hw, vif); |
| 4424 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4425 | priv->macids_used |= 1 << mwl8k_vif->macid; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4426 | list_add_tail(&mwl8k_vif->list, &priv->vif_list); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4427 | |
| 4428 | return 0; |
| 4429 | } |
| 4430 | |
| 4431 | static void mwl8k_remove_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 4432 | struct ieee80211_vif *vif) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4433 | { |
| 4434 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4435 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4436 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4437 | if (priv->ap_fw) |
| 4438 | mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr); |
| 4439 | |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4440 | mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00"); |
Lennert Buytenhek | 32060e1 | 2009-10-22 20:20:04 +0200 | [diff] [blame] | 4441 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4442 | priv->macids_used &= ~(1 << mwl8k_vif->macid); |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4443 | list_del(&mwl8k_vif->list); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4444 | } |
| 4445 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4446 | static int mwl8k_config(struct ieee80211_hw *hw, u32 changed) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4447 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4448 | struct ieee80211_conf *conf = &hw->conf; |
| 4449 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4450 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4451 | |
Lennert Buytenhek | 7595d67 | 2009-08-17 23:59:40 +0200 | [diff] [blame] | 4452 | if (conf->flags & IEEE80211_CONF_IDLE) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4453 | mwl8k_cmd_radio_disable(hw); |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4454 | return 0; |
Lennert Buytenhek | 7595d67 | 2009-08-17 23:59:40 +0200 | [diff] [blame] | 4455 | } |
| 4456 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4457 | rc = mwl8k_fw_lock(hw); |
| 4458 | if (rc) |
| 4459 | return rc; |
| 4460 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4461 | rc = mwl8k_cmd_radio_enable(hw); |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4462 | if (rc) |
| 4463 | goto out; |
| 4464 | |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 4465 | rc = mwl8k_cmd_set_rf_channel(hw, conf); |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4466 | if (rc) |
| 4467 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4468 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4469 | if (conf->power_level > 18) |
| 4470 | conf->power_level = 18; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4471 | |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4472 | if (priv->ap_fw) { |
Nishant Sarmukadam | 0321708 | 2011-04-05 14:18:09 +0530 | [diff] [blame] | 4473 | |
| 4474 | if (conf->flags & IEEE80211_CONF_CHANGE_POWER) { |
| 4475 | rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level); |
| 4476 | if (rc) |
| 4477 | goto out; |
| 4478 | } |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 4479 | |
Nishant Sarmukadam | da62b76 | 2011-02-17 14:45:16 -0800 | [diff] [blame] | 4480 | rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3); |
| 4481 | if (rc) |
| 4482 | wiphy_warn(hw->wiphy, "failed to set # of RX antennas"); |
| 4483 | rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7); |
| 4484 | if (rc) |
| 4485 | wiphy_warn(hw->wiphy, "failed to set # of TX antennas"); |
| 4486 | |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4487 | } else { |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 4488 | rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level); |
| 4489 | if (rc) |
| 4490 | goto out; |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4491 | rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7); |
| 4492 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4493 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4494 | out: |
| 4495 | mwl8k_fw_unlock(hw); |
| 4496 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4497 | return rc; |
| 4498 | } |
| 4499 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4500 | static void |
| 4501 | mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4502 | struct ieee80211_bss_conf *info, u32 changed) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4503 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4504 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4505 | u32 ap_legacy_rates; |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4506 | u8 ap_mcs_rates[16]; |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4507 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4508 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4509 | if (mwl8k_fw_lock(hw)) |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4510 | return; |
| 4511 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4512 | /* |
| 4513 | * No need to capture a beacon if we're no longer associated. |
| 4514 | */ |
| 4515 | if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc) |
| 4516 | priv->capture_beacon = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4517 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4518 | /* |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4519 | * Get the AP's legacy and MCS rates. |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4520 | */ |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4521 | if (vif->bss_conf.assoc) { |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4522 | struct ieee80211_sta *ap; |
Lennert Buytenhek | c97470d | 2010-01-12 13:47:37 +0100 | [diff] [blame] | 4523 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4524 | rcu_read_lock(); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4525 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4526 | ap = ieee80211_find_sta(vif, vif->bss_conf.bssid); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4527 | if (ap == NULL) { |
| 4528 | rcu_read_unlock(); |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4529 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4530 | } |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4531 | |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4532 | if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) { |
| 4533 | ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ]; |
| 4534 | } else { |
| 4535 | ap_legacy_rates = |
| 4536 | ap->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 4537 | } |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4538 | memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4539 | |
| 4540 | rcu_read_unlock(); |
| 4541 | } |
| 4542 | |
| 4543 | if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) { |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4544 | rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4545 | if (rc) |
| 4546 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4547 | |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 4548 | rc = mwl8k_cmd_use_fixed_rate_sta(hw); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4549 | if (rc) |
| 4550 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4551 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4552 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4553 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4554 | rc = mwl8k_set_radio_preamble(hw, |
| 4555 | vif->bss_conf.use_short_preamble); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4556 | if (rc) |
| 4557 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4558 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4559 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4560 | if (changed & BSS_CHANGED_ERP_SLOT) { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4561 | rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4562 | if (rc) |
| 4563 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4564 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4565 | |
Lennert Buytenhek | c97470d | 2010-01-12 13:47:37 +0100 | [diff] [blame] | 4566 | if (vif->bss_conf.assoc && |
| 4567 | (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT | |
| 4568 | BSS_CHANGED_HT))) { |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4569 | rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4570 | if (rc) |
| 4571 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4572 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4573 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4574 | if (vif->bss_conf.assoc && |
| 4575 | (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4576 | /* |
| 4577 | * Finalize the join. Tell rx handler to process |
| 4578 | * next beacon from our BSSID. |
| 4579 | */ |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 4580 | memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4581 | priv->capture_beacon = true; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4582 | } |
| 4583 | |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4584 | out: |
| 4585 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4586 | } |
| 4587 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4588 | static void |
| 4589 | mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4590 | struct ieee80211_bss_conf *info, u32 changed) |
| 4591 | { |
| 4592 | int rc; |
| 4593 | |
| 4594 | if (mwl8k_fw_lock(hw)) |
| 4595 | return; |
| 4596 | |
| 4597 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 4598 | rc = mwl8k_set_radio_preamble(hw, |
| 4599 | vif->bss_conf.use_short_preamble); |
| 4600 | if (rc) |
| 4601 | goto out; |
| 4602 | } |
| 4603 | |
| 4604 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 4605 | int idx; |
| 4606 | int rate; |
| 4607 | |
| 4608 | /* |
| 4609 | * Use lowest supported basic rate for multicasts |
| 4610 | * and management frames (such as probe responses -- |
| 4611 | * beacons will always go out at 1 Mb/s). |
| 4612 | */ |
| 4613 | idx = ffs(vif->bss_conf.basic_rates); |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4614 | if (idx) |
| 4615 | idx--; |
| 4616 | |
| 4617 | if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) |
| 4618 | rate = mwl8k_rates_24[idx].hw_value; |
| 4619 | else |
| 4620 | rate = mwl8k_rates_50[idx].hw_value; |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4621 | |
| 4622 | mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate); |
| 4623 | } |
| 4624 | |
| 4625 | if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) { |
| 4626 | struct sk_buff *skb; |
| 4627 | |
| 4628 | skb = ieee80211_beacon_get(hw, vif); |
| 4629 | if (skb != NULL) { |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4630 | mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4631 | kfree_skb(skb); |
| 4632 | } |
| 4633 | } |
| 4634 | |
| 4635 | if (changed & BSS_CHANGED_BEACON_ENABLED) |
Lennert Buytenhek | aa21d0f | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4636 | mwl8k_cmd_bss_start(hw, vif, info->enable_beacon); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4637 | |
| 4638 | out: |
| 4639 | mwl8k_fw_unlock(hw); |
| 4640 | } |
| 4641 | |
| 4642 | static void |
| 4643 | mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4644 | struct ieee80211_bss_conf *info, u32 changed) |
| 4645 | { |
| 4646 | struct mwl8k_priv *priv = hw->priv; |
| 4647 | |
| 4648 | if (!priv->ap_fw) |
| 4649 | mwl8k_bss_info_changed_sta(hw, vif, info, changed); |
| 4650 | else |
| 4651 | mwl8k_bss_info_changed_ap(hw, vif, info, changed); |
| 4652 | } |
| 4653 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 4654 | static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw, |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4655 | struct netdev_hw_addr_list *mc_list) |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 4656 | { |
| 4657 | struct mwl8k_cmd_pkt *cmd; |
| 4658 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 4659 | /* |
| 4660 | * Synthesize and return a command packet that programs the |
| 4661 | * hardware multicast address filter. At this point we don't |
| 4662 | * know whether FIF_ALLMULTI is being requested, but if it is, |
| 4663 | * we'll end up throwing this packet away and creating a new |
| 4664 | * one in mwl8k_configure_filter(). |
| 4665 | */ |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4666 | cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list); |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 4667 | |
| 4668 | return (unsigned long)cmd; |
| 4669 | } |
| 4670 | |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4671 | static int |
| 4672 | mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw, |
| 4673 | unsigned int changed_flags, |
| 4674 | unsigned int *total_flags) |
| 4675 | { |
| 4676 | struct mwl8k_priv *priv = hw->priv; |
| 4677 | |
| 4678 | /* |
| 4679 | * Hardware sniffer mode is mutually exclusive with STA |
| 4680 | * operation, so refuse to enable sniffer mode if a STA |
| 4681 | * interface is active. |
| 4682 | */ |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4683 | if (!list_empty(&priv->vif_list)) { |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4684 | if (net_ratelimit()) |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4685 | wiphy_info(hw->wiphy, |
| 4686 | "not enabling sniffer mode because STA interface is active\n"); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4687 | return 0; |
| 4688 | } |
| 4689 | |
| 4690 | if (!priv->sniffer_enabled) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4691 | if (mwl8k_cmd_enable_sniffer(hw, 1)) |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4692 | return 0; |
| 4693 | priv->sniffer_enabled = true; |
| 4694 | } |
| 4695 | |
| 4696 | *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI | |
| 4697 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL | |
| 4698 | FIF_OTHER_BSS; |
| 4699 | |
| 4700 | return 1; |
| 4701 | } |
| 4702 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4703 | static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv) |
| 4704 | { |
| 4705 | if (!list_empty(&priv->vif_list)) |
| 4706 | return list_entry(priv->vif_list.next, struct mwl8k_vif, list); |
| 4707 | |
| 4708 | return NULL; |
| 4709 | } |
| 4710 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4711 | static void mwl8k_configure_filter(struct ieee80211_hw *hw, |
| 4712 | unsigned int changed_flags, |
| 4713 | unsigned int *total_flags, |
| 4714 | u64 multicast) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4715 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4716 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4717 | struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast; |
| 4718 | |
| 4719 | /* |
Lennert Buytenhek | c0adae2 | 2009-10-22 20:21:36 +0200 | [diff] [blame] | 4720 | * AP firmware doesn't allow fine-grained control over |
| 4721 | * the receive filter. |
| 4722 | */ |
| 4723 | if (priv->ap_fw) { |
| 4724 | *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC; |
| 4725 | kfree(cmd); |
| 4726 | return; |
| 4727 | } |
| 4728 | |
| 4729 | /* |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4730 | * Enable hardware sniffer mode if FIF_CONTROL or |
| 4731 | * FIF_OTHER_BSS is requested. |
| 4732 | */ |
| 4733 | if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) && |
| 4734 | mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) { |
| 4735 | kfree(cmd); |
| 4736 | return; |
| 4737 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4738 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4739 | /* Clear unsupported feature flags */ |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 4740 | *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC; |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4741 | |
Lennert Buytenhek | 90852f7 | 2010-01-02 10:31:42 +0100 | [diff] [blame] | 4742 | if (mwl8k_fw_lock(hw)) { |
| 4743 | kfree(cmd); |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4744 | return; |
Lennert Buytenhek | 90852f7 | 2010-01-02 10:31:42 +0100 | [diff] [blame] | 4745 | } |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4746 | |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4747 | if (priv->sniffer_enabled) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4748 | mwl8k_cmd_enable_sniffer(hw, 0); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4749 | priv->sniffer_enabled = false; |
| 4750 | } |
| 4751 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4752 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 4753 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 4754 | /* |
| 4755 | * Disable the BSS filter. |
| 4756 | */ |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4757 | mwl8k_cmd_set_pre_scan(hw); |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 4758 | } else { |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4759 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 4760 | const u8 *bssid; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 4761 | |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 4762 | /* |
| 4763 | * Enable the BSS filter. |
| 4764 | * |
| 4765 | * If there is an active STA interface, use that |
| 4766 | * interface's BSSID, otherwise use a dummy one |
| 4767 | * (where the OUI part needs to be nonzero for |
| 4768 | * the BSSID to be accepted by POST_SCAN). |
| 4769 | */ |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4770 | mwl8k_vif = mwl8k_first_vif(priv); |
| 4771 | if (mwl8k_vif != NULL) |
| 4772 | bssid = mwl8k_vif->vif->bss_conf.bssid; |
| 4773 | else |
| 4774 | bssid = "\x01\x00\x00\x00\x00\x00"; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 4775 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4776 | mwl8k_cmd_set_post_scan(hw, bssid); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4777 | } |
| 4778 | } |
| 4779 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 4780 | /* |
| 4781 | * If FIF_ALLMULTI is being requested, throw away the command |
| 4782 | * packet that ->prepare_multicast() built and replace it with |
| 4783 | * a command packet that enables reception of all multicast |
| 4784 | * packets. |
| 4785 | */ |
| 4786 | if (*total_flags & FIF_ALLMULTI) { |
| 4787 | kfree(cmd); |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4788 | cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL); |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 4789 | } |
| 4790 | |
| 4791 | if (cmd != NULL) { |
| 4792 | mwl8k_post_cmd(hw, cmd); |
| 4793 | kfree(cmd); |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4794 | } |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 4795 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4796 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4797 | } |
| 4798 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4799 | static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 4800 | { |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 4801 | return mwl8k_cmd_set_rts_threshold(hw, value); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4802 | } |
| 4803 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 4804 | static int mwl8k_sta_remove(struct ieee80211_hw *hw, |
| 4805 | struct ieee80211_vif *vif, |
| 4806 | struct ieee80211_sta *sta) |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4807 | { |
| 4808 | struct mwl8k_priv *priv = hw->priv; |
| 4809 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 4810 | if (priv->ap_fw) |
| 4811 | return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr); |
| 4812 | else |
| 4813 | return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr); |
| 4814 | } |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4815 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 4816 | static int mwl8k_sta_add(struct ieee80211_hw *hw, |
| 4817 | struct ieee80211_vif *vif, |
| 4818 | struct ieee80211_sta *sta) |
| 4819 | { |
| 4820 | struct mwl8k_priv *priv = hw->priv; |
| 4821 | int ret; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4822 | int i; |
| 4823 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 4824 | struct ieee80211_key_conf *key; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4825 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 4826 | if (!priv->ap_fw) { |
| 4827 | ret = mwl8k_cmd_update_stadb_add(hw, vif, sta); |
| 4828 | if (ret >= 0) { |
| 4829 | MWL8K_STA(sta)->peer_id = ret; |
Nishant Sarmukadam | 1703354 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 4830 | if (sta->ht_cap.ht_supported) |
| 4831 | MWL8K_STA(sta)->is_ampdu_allowed = true; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4832 | ret = 0; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4833 | } |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 4834 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 4835 | } else { |
| 4836 | ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4837 | } |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4838 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 4839 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 4840 | key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key); |
| 4841 | if (mwl8k_vif->wep_key_conf[i].enabled) |
| 4842 | mwl8k_set_key(hw, SET_KEY, vif, sta, key); |
| 4843 | } |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4844 | return ret; |
Lennert Buytenhek | bbfd912 | 2010-01-04 21:55:12 +0100 | [diff] [blame] | 4845 | } |
| 4846 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4847 | static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue, |
| 4848 | const struct ieee80211_tx_queue_params *params) |
| 4849 | { |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 4850 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4851 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4852 | |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 4853 | rc = mwl8k_fw_lock(hw); |
| 4854 | if (!rc) { |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 4855 | BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1); |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4856 | memcpy(&priv->wmm_params[queue], params, sizeof(*params)); |
| 4857 | |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 4858 | if (!priv->wmm_enabled) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4859 | rc = mwl8k_cmd_set_wmm_mode(hw, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4860 | |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 4861 | if (!rc) { |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 4862 | int q = MWL8K_TX_WMM_QUEUES - 1 - queue; |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 4863 | rc = mwl8k_cmd_set_edca_params(hw, q, |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4864 | params->cw_min, |
| 4865 | params->cw_max, |
| 4866 | params->aifs, |
| 4867 | params->txop); |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 4868 | } |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 4869 | |
| 4870 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4871 | } |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 4872 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4873 | return rc; |
| 4874 | } |
| 4875 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4876 | static int mwl8k_get_stats(struct ieee80211_hw *hw, |
| 4877 | struct ieee80211_low_level_stats *stats) |
| 4878 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4879 | return mwl8k_cmd_get_stat(hw, stats); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4880 | } |
| 4881 | |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 4882 | static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx, |
| 4883 | struct survey_info *survey) |
| 4884 | { |
| 4885 | struct mwl8k_priv *priv = hw->priv; |
| 4886 | struct ieee80211_conf *conf = &hw->conf; |
| 4887 | |
| 4888 | if (idx != 0) |
| 4889 | return -ENOENT; |
| 4890 | |
| 4891 | survey->channel = conf->channel; |
| 4892 | survey->filled = SURVEY_INFO_NOISE_DBM; |
| 4893 | survey->noise = priv->noise; |
| 4894 | |
| 4895 | return 0; |
| 4896 | } |
| 4897 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 4898 | #define MAX_AMPDU_ATTEMPTS 5 |
| 4899 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 4900 | static int |
| 4901 | mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4902 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 4903 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 4904 | u8 buf_size) |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 4905 | { |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 4906 | |
| 4907 | int i, rc = 0; |
| 4908 | struct mwl8k_priv *priv = hw->priv; |
| 4909 | struct mwl8k_ampdu_stream *stream; |
| 4910 | u8 *addr = sta->addr; |
| 4911 | |
| 4912 | if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION)) |
| 4913 | return -ENOTSUPP; |
| 4914 | |
| 4915 | spin_lock(&priv->stream_lock); |
| 4916 | stream = mwl8k_lookup_stream(hw, addr, tid); |
| 4917 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 4918 | switch (action) { |
| 4919 | case IEEE80211_AMPDU_RX_START: |
| 4920 | case IEEE80211_AMPDU_RX_STOP: |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 4921 | break; |
| 4922 | case IEEE80211_AMPDU_TX_START: |
| 4923 | /* By the time we get here the hw queues may contain outgoing |
| 4924 | * packets for this RA/TID that are not part of this BA |
| 4925 | * session. The hw will assign sequence numbers to these |
| 4926 | * packets as they go out. So if we query the hw for its next |
| 4927 | * sequence number and use that for the SSN here, it may end up |
| 4928 | * being wrong, which will lead to sequence number mismatch at |
| 4929 | * the recipient. To avoid this, we reset the sequence number |
| 4930 | * to O for the first MPDU in this BA stream. |
| 4931 | */ |
| 4932 | *ssn = 0; |
| 4933 | if (stream == NULL) { |
| 4934 | /* This means that somebody outside this driver called |
| 4935 | * ieee80211_start_tx_ba_session. This is unexpected |
| 4936 | * because we do our own rate control. Just warn and |
| 4937 | * move on. |
| 4938 | */ |
| 4939 | wiphy_warn(hw->wiphy, "Unexpected call to %s. " |
| 4940 | "Proceeding anyway.\n", __func__); |
| 4941 | stream = mwl8k_add_stream(hw, sta, tid); |
| 4942 | } |
| 4943 | if (stream == NULL) { |
| 4944 | wiphy_debug(hw->wiphy, "no free AMPDU streams\n"); |
| 4945 | rc = -EBUSY; |
| 4946 | break; |
| 4947 | } |
| 4948 | stream->state = AMPDU_STREAM_IN_PROGRESS; |
| 4949 | |
| 4950 | /* Release the lock before we do the time consuming stuff */ |
| 4951 | spin_unlock(&priv->stream_lock); |
| 4952 | for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) { |
| 4953 | rc = mwl8k_check_ba(hw, stream); |
| 4954 | |
| 4955 | if (!rc) |
| 4956 | break; |
| 4957 | /* |
| 4958 | * HW queues take time to be flushed, give them |
| 4959 | * sufficient time |
| 4960 | */ |
| 4961 | |
| 4962 | msleep(1000); |
| 4963 | } |
| 4964 | spin_lock(&priv->stream_lock); |
| 4965 | if (rc) { |
| 4966 | wiphy_err(hw->wiphy, "Stream for tid %d busy after %d" |
| 4967 | " attempts\n", tid, MAX_AMPDU_ATTEMPTS); |
| 4968 | mwl8k_remove_stream(hw, stream); |
| 4969 | rc = -EBUSY; |
| 4970 | break; |
| 4971 | } |
| 4972 | ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid); |
| 4973 | break; |
| 4974 | case IEEE80211_AMPDU_TX_STOP: |
| 4975 | if (stream == NULL) |
| 4976 | break; |
| 4977 | if (stream->state == AMPDU_STREAM_ACTIVE) { |
| 4978 | spin_unlock(&priv->stream_lock); |
| 4979 | mwl8k_destroy_ba(hw, stream); |
| 4980 | spin_lock(&priv->stream_lock); |
| 4981 | } |
| 4982 | mwl8k_remove_stream(hw, stream); |
| 4983 | ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid); |
| 4984 | break; |
| 4985 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 4986 | BUG_ON(stream == NULL); |
| 4987 | BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS); |
| 4988 | spin_unlock(&priv->stream_lock); |
| 4989 | rc = mwl8k_create_ba(hw, stream, buf_size); |
| 4990 | spin_lock(&priv->stream_lock); |
| 4991 | if (!rc) |
| 4992 | stream->state = AMPDU_STREAM_ACTIVE; |
| 4993 | else { |
| 4994 | spin_unlock(&priv->stream_lock); |
| 4995 | mwl8k_destroy_ba(hw, stream); |
| 4996 | spin_lock(&priv->stream_lock); |
| 4997 | wiphy_debug(hw->wiphy, |
| 4998 | "Failed adding stream for sta %pM tid %d\n", |
| 4999 | addr, tid); |
| 5000 | mwl8k_remove_stream(hw, stream); |
| 5001 | } |
| 5002 | break; |
| 5003 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5004 | default: |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5005 | rc = -ENOTSUPP; |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5006 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5007 | |
| 5008 | spin_unlock(&priv->stream_lock); |
| 5009 | return rc; |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5010 | } |
| 5011 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5012 | static const struct ieee80211_ops mwl8k_ops = { |
| 5013 | .tx = mwl8k_tx, |
| 5014 | .start = mwl8k_start, |
| 5015 | .stop = mwl8k_stop, |
| 5016 | .add_interface = mwl8k_add_interface, |
| 5017 | .remove_interface = mwl8k_remove_interface, |
| 5018 | .config = mwl8k_config, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5019 | .bss_info_changed = mwl8k_bss_info_changed, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 5020 | .prepare_multicast = mwl8k_prepare_multicast, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5021 | .configure_filter = mwl8k_configure_filter, |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5022 | .set_key = mwl8k_set_key, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5023 | .set_rts_threshold = mwl8k_set_rts_threshold, |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5024 | .sta_add = mwl8k_sta_add, |
| 5025 | .sta_remove = mwl8k_sta_remove, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5026 | .conf_tx = mwl8k_conf_tx, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5027 | .get_stats = mwl8k_get_stats, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 5028 | .get_survey = mwl8k_get_survey, |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5029 | .ampdu_action = mwl8k_ampdu_action, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5030 | }; |
| 5031 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5032 | static void mwl8k_finalize_join_worker(struct work_struct *work) |
| 5033 | { |
| 5034 | struct mwl8k_priv *priv = |
| 5035 | container_of(work, struct mwl8k_priv, finalize_join_worker); |
| 5036 | struct sk_buff *skb = priv->beacon_skb; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 5037 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 5038 | int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable); |
| 5039 | const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM, |
| 5040 | mgmt->u.beacon.variable, len); |
| 5041 | int dtim_period = 1; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5042 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 5043 | if (tim && tim[1] >= 2) |
| 5044 | dtim_period = tim[3]; |
| 5045 | |
| 5046 | mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period); |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 5047 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5048 | dev_kfree_skb(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5049 | priv->beacon_skb = NULL; |
| 5050 | } |
| 5051 | |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5052 | enum { |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5053 | MWL8363 = 0, |
| 5054 | MWL8687, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5055 | MWL8366, |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 5056 | }; |
| 5057 | |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 5058 | #define MWL8K_8366_AP_FW_API 2 |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5059 | #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw" |
| 5060 | #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api) |
| 5061 | |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5062 | static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = { |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5063 | [MWL8363] = { |
| 5064 | .part_name = "88w8363", |
| 5065 | .helper_image = "mwl8k/helper_8363.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5066 | .fw_image_sta = "mwl8k/fmimage_8363.fw", |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5067 | }, |
Lennert Buytenhek | 49eb691 | 2009-11-30 18:32:13 +0100 | [diff] [blame] | 5068 | [MWL8687] = { |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5069 | .part_name = "88w8687", |
| 5070 | .helper_image = "mwl8k/helper_8687.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5071 | .fw_image_sta = "mwl8k/fmimage_8687.fw", |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5072 | }, |
Lennert Buytenhek | 49eb691 | 2009-11-30 18:32:13 +0100 | [diff] [blame] | 5073 | [MWL8366] = { |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5074 | .part_name = "88w8366", |
| 5075 | .helper_image = "mwl8k/helper_8366.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5076 | .fw_image_sta = "mwl8k/fmimage_8366.fw", |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5077 | .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API), |
| 5078 | .fw_api_ap = MWL8K_8366_AP_FW_API, |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 5079 | .ap_rxd_ops = &rxd_8366_ap_ops, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5080 | }, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5081 | }; |
| 5082 | |
Lennert Buytenhek | c92d4ed | 2010-01-12 13:47:22 +0100 | [diff] [blame] | 5083 | MODULE_FIRMWARE("mwl8k/helper_8363.fw"); |
| 5084 | MODULE_FIRMWARE("mwl8k/fmimage_8363.fw"); |
| 5085 | MODULE_FIRMWARE("mwl8k/helper_8687.fw"); |
| 5086 | MODULE_FIRMWARE("mwl8k/fmimage_8687.fw"); |
| 5087 | MODULE_FIRMWARE("mwl8k/helper_8366.fw"); |
| 5088 | MODULE_FIRMWARE("mwl8k/fmimage_8366.fw"); |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5089 | MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API)); |
Lennert Buytenhek | c92d4ed | 2010-01-12 13:47:22 +0100 | [diff] [blame] | 5090 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5091 | static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = { |
Benjamin Larsson | e5868ba | 2010-03-19 01:46:10 +0100 | [diff] [blame] | 5092 | { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, }, |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5093 | { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, }, |
| 5094 | { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, }, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5095 | { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, }, |
| 5096 | { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, }, |
| 5097 | { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, }, |
Lennert Buytenhek | ca66527 | 2010-01-12 13:47:53 +0100 | [diff] [blame] | 5098 | { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, }, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5099 | { }, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5100 | }; |
| 5101 | MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table); |
| 5102 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5103 | static int mwl8k_request_alt_fw(struct mwl8k_priv *priv) |
| 5104 | { |
| 5105 | int rc; |
| 5106 | printk(KERN_ERR "%s: Error requesting preferred fw %s.\n" |
| 5107 | "Trying alternative firmware %s\n", pci_name(priv->pdev), |
| 5108 | priv->fw_pref, priv->fw_alt); |
| 5109 | rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true); |
| 5110 | if (rc) { |
| 5111 | printk(KERN_ERR "%s: Error requesting alt fw %s\n", |
| 5112 | pci_name(priv->pdev), priv->fw_alt); |
| 5113 | return rc; |
| 5114 | } |
| 5115 | return 0; |
| 5116 | } |
| 5117 | |
| 5118 | static int mwl8k_firmware_load_success(struct mwl8k_priv *priv); |
| 5119 | static void mwl8k_fw_state_machine(const struct firmware *fw, void *context) |
| 5120 | { |
| 5121 | struct mwl8k_priv *priv = context; |
| 5122 | struct mwl8k_device_info *di = priv->device_info; |
| 5123 | int rc; |
| 5124 | |
| 5125 | switch (priv->fw_state) { |
| 5126 | case FW_STATE_INIT: |
| 5127 | if (!fw) { |
| 5128 | printk(KERN_ERR "%s: Error requesting helper fw %s\n", |
| 5129 | pci_name(priv->pdev), di->helper_image); |
| 5130 | goto fail; |
| 5131 | } |
| 5132 | priv->fw_helper = fw; |
| 5133 | rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode, |
| 5134 | true); |
| 5135 | if (rc && priv->fw_alt) { |
| 5136 | rc = mwl8k_request_alt_fw(priv); |
| 5137 | if (rc) |
| 5138 | goto fail; |
| 5139 | priv->fw_state = FW_STATE_LOADING_ALT; |
| 5140 | } else if (rc) |
| 5141 | goto fail; |
| 5142 | else |
| 5143 | priv->fw_state = FW_STATE_LOADING_PREF; |
| 5144 | break; |
| 5145 | |
| 5146 | case FW_STATE_LOADING_PREF: |
| 5147 | if (!fw) { |
| 5148 | if (priv->fw_alt) { |
| 5149 | rc = mwl8k_request_alt_fw(priv); |
| 5150 | if (rc) |
| 5151 | goto fail; |
| 5152 | priv->fw_state = FW_STATE_LOADING_ALT; |
| 5153 | } else |
| 5154 | goto fail; |
| 5155 | } else { |
| 5156 | priv->fw_ucode = fw; |
| 5157 | rc = mwl8k_firmware_load_success(priv); |
| 5158 | if (rc) |
| 5159 | goto fail; |
| 5160 | else |
| 5161 | complete(&priv->firmware_loading_complete); |
| 5162 | } |
| 5163 | break; |
| 5164 | |
| 5165 | case FW_STATE_LOADING_ALT: |
| 5166 | if (!fw) { |
| 5167 | printk(KERN_ERR "%s: Error requesting alt fw %s\n", |
| 5168 | pci_name(priv->pdev), di->helper_image); |
| 5169 | goto fail; |
| 5170 | } |
| 5171 | priv->fw_ucode = fw; |
| 5172 | rc = mwl8k_firmware_load_success(priv); |
| 5173 | if (rc) |
| 5174 | goto fail; |
| 5175 | else |
| 5176 | complete(&priv->firmware_loading_complete); |
| 5177 | break; |
| 5178 | |
| 5179 | default: |
| 5180 | printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n", |
| 5181 | MWL8K_NAME, priv->fw_state); |
| 5182 | BUG_ON(1); |
| 5183 | } |
| 5184 | |
| 5185 | return; |
| 5186 | |
| 5187 | fail: |
| 5188 | priv->fw_state = FW_STATE_ERROR; |
| 5189 | complete(&priv->firmware_loading_complete); |
| 5190 | device_release_driver(&priv->pdev->dev); |
| 5191 | mwl8k_release_firmware(priv); |
| 5192 | } |
| 5193 | |
| 5194 | static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image, |
| 5195 | bool nowait) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5196 | { |
| 5197 | struct mwl8k_priv *priv = hw->priv; |
| 5198 | int rc; |
| 5199 | |
| 5200 | /* Reset firmware and hardware */ |
| 5201 | mwl8k_hw_reset(priv); |
| 5202 | |
| 5203 | /* Ask userland hotplug daemon for the device firmware */ |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5204 | rc = mwl8k_request_firmware(priv, fw_image, nowait); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5205 | if (rc) { |
| 5206 | wiphy_err(hw->wiphy, "Firmware files not found\n"); |
| 5207 | return rc; |
| 5208 | } |
| 5209 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5210 | if (nowait) |
| 5211 | return rc; |
| 5212 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5213 | /* Load firmware into hardware */ |
| 5214 | rc = mwl8k_load_firmware(hw); |
| 5215 | if (rc) |
| 5216 | wiphy_err(hw->wiphy, "Cannot start firmware\n"); |
| 5217 | |
| 5218 | /* Reclaim memory once firmware is successfully loaded */ |
| 5219 | mwl8k_release_firmware(priv); |
| 5220 | |
| 5221 | return rc; |
| 5222 | } |
| 5223 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5224 | static int mwl8k_init_txqs(struct ieee80211_hw *hw) |
| 5225 | { |
| 5226 | struct mwl8k_priv *priv = hw->priv; |
| 5227 | int rc = 0; |
| 5228 | int i; |
| 5229 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5230 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5231 | rc = mwl8k_txq_init(hw, i); |
| 5232 | if (rc) |
| 5233 | break; |
| 5234 | if (priv->ap_fw) |
| 5235 | iowrite32(priv->txq[i].txd_dma, |
| 5236 | priv->sram + priv->txq_offset[i]); |
| 5237 | } |
| 5238 | return rc; |
| 5239 | } |
| 5240 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5241 | /* initialize hw after successfully loading a firmware image */ |
| 5242 | static int mwl8k_probe_hw(struct ieee80211_hw *hw) |
| 5243 | { |
| 5244 | struct mwl8k_priv *priv = hw->priv; |
| 5245 | int rc = 0; |
| 5246 | int i; |
| 5247 | |
| 5248 | if (priv->ap_fw) { |
| 5249 | priv->rxd_ops = priv->device_info->ap_rxd_ops; |
| 5250 | if (priv->rxd_ops == NULL) { |
| 5251 | wiphy_err(hw->wiphy, |
| 5252 | "Driver does not have AP firmware image support for this hardware\n"); |
| 5253 | goto err_stop_firmware; |
| 5254 | } |
| 5255 | } else { |
| 5256 | priv->rxd_ops = &rxd_sta_ops; |
| 5257 | } |
| 5258 | |
| 5259 | priv->sniffer_enabled = false; |
| 5260 | priv->wmm_enabled = false; |
| 5261 | priv->pending_tx_pkts = 0; |
| 5262 | |
| 5263 | rc = mwl8k_rxq_init(hw, 0); |
| 5264 | if (rc) |
| 5265 | goto err_stop_firmware; |
| 5266 | rxq_refill(hw, 0, INT_MAX); |
| 5267 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5268 | /* For the sta firmware, we need to know the dma addresses of tx queues |
| 5269 | * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them |
| 5270 | * prior to issuing this command. But for the AP case, we learn the |
| 5271 | * total number of queues from the result CMD_GET_HW_SPEC, so for this |
| 5272 | * case we must initialize the tx queues after. |
| 5273 | */ |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 5274 | priv->num_ampdu_queues = 0; |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5275 | if (!priv->ap_fw) { |
| 5276 | rc = mwl8k_init_txqs(hw); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5277 | if (rc) |
| 5278 | goto err_free_queues; |
| 5279 | } |
| 5280 | |
| 5281 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 5282 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 5283 | iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY| |
| 5284 | MWL8K_A2H_INT_BA_WATCHDOG, |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5285 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL); |
| 5286 | iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
| 5287 | |
| 5288 | rc = request_irq(priv->pdev->irq, mwl8k_interrupt, |
| 5289 | IRQF_SHARED, MWL8K_NAME, hw); |
| 5290 | if (rc) { |
| 5291 | wiphy_err(hw->wiphy, "failed to register IRQ handler\n"); |
| 5292 | goto err_free_queues; |
| 5293 | } |
| 5294 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 5295 | memset(priv->ampdu, 0, sizeof(priv->ampdu)); |
| 5296 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5297 | /* |
| 5298 | * Temporarily enable interrupts. Initial firmware host |
| 5299 | * commands use interrupts and avoid polling. Disable |
| 5300 | * interrupts when done. |
| 5301 | */ |
| 5302 | iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5303 | |
| 5304 | /* Get config data, mac addrs etc */ |
| 5305 | if (priv->ap_fw) { |
| 5306 | rc = mwl8k_cmd_get_hw_spec_ap(hw); |
| 5307 | if (!rc) |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5308 | rc = mwl8k_init_txqs(hw); |
| 5309 | if (!rc) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5310 | rc = mwl8k_cmd_set_hw_spec(hw); |
| 5311 | } else { |
| 5312 | rc = mwl8k_cmd_get_hw_spec_sta(hw); |
| 5313 | } |
| 5314 | if (rc) { |
| 5315 | wiphy_err(hw->wiphy, "Cannot initialise firmware\n"); |
| 5316 | goto err_free_irq; |
| 5317 | } |
| 5318 | |
| 5319 | /* Turn radio off */ |
| 5320 | rc = mwl8k_cmd_radio_disable(hw); |
| 5321 | if (rc) { |
| 5322 | wiphy_err(hw->wiphy, "Cannot disable\n"); |
| 5323 | goto err_free_irq; |
| 5324 | } |
| 5325 | |
| 5326 | /* Clear MAC address */ |
| 5327 | rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00"); |
| 5328 | if (rc) { |
| 5329 | wiphy_err(hw->wiphy, "Cannot clear MAC address\n"); |
| 5330 | goto err_free_irq; |
| 5331 | } |
| 5332 | |
| 5333 | /* Disable interrupts */ |
| 5334 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5335 | free_irq(priv->pdev->irq, hw); |
| 5336 | |
| 5337 | wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n", |
| 5338 | priv->device_info->part_name, |
| 5339 | priv->hw_rev, hw->wiphy->perm_addr, |
| 5340 | priv->ap_fw ? "AP" : "STA", |
| 5341 | (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff, |
| 5342 | (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff); |
| 5343 | |
| 5344 | return 0; |
| 5345 | |
| 5346 | err_free_irq: |
| 5347 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5348 | free_irq(priv->pdev->irq, hw); |
| 5349 | |
| 5350 | err_free_queues: |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5351 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5352 | mwl8k_txq_deinit(hw, i); |
| 5353 | mwl8k_rxq_deinit(hw, 0); |
| 5354 | |
| 5355 | err_stop_firmware: |
| 5356 | mwl8k_hw_reset(priv); |
| 5357 | |
| 5358 | return rc; |
| 5359 | } |
| 5360 | |
| 5361 | /* |
| 5362 | * invoke mwl8k_reload_firmware to change the firmware image after the device |
| 5363 | * has already been registered |
| 5364 | */ |
| 5365 | static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image) |
| 5366 | { |
| 5367 | int i, rc = 0; |
| 5368 | struct mwl8k_priv *priv = hw->priv; |
| 5369 | |
| 5370 | mwl8k_stop(hw); |
| 5371 | mwl8k_rxq_deinit(hw, 0); |
| 5372 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5373 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5374 | mwl8k_txq_deinit(hw, i); |
| 5375 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5376 | rc = mwl8k_init_firmware(hw, fw_image, false); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5377 | if (rc) |
| 5378 | goto fail; |
| 5379 | |
| 5380 | rc = mwl8k_probe_hw(hw); |
| 5381 | if (rc) |
| 5382 | goto fail; |
| 5383 | |
| 5384 | rc = mwl8k_start(hw); |
| 5385 | if (rc) |
| 5386 | goto fail; |
| 5387 | |
| 5388 | rc = mwl8k_config(hw, ~0); |
| 5389 | if (rc) |
| 5390 | goto fail; |
| 5391 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5392 | for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) { |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5393 | rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]); |
| 5394 | if (rc) |
| 5395 | goto fail; |
| 5396 | } |
| 5397 | |
| 5398 | return rc; |
| 5399 | |
| 5400 | fail: |
| 5401 | printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n"); |
| 5402 | return rc; |
| 5403 | } |
| 5404 | |
| 5405 | static int mwl8k_firmware_load_success(struct mwl8k_priv *priv) |
| 5406 | { |
| 5407 | struct ieee80211_hw *hw = priv->hw; |
| 5408 | int i, rc; |
| 5409 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5410 | rc = mwl8k_load_firmware(hw); |
| 5411 | mwl8k_release_firmware(priv); |
| 5412 | if (rc) { |
| 5413 | wiphy_err(hw->wiphy, "Cannot start firmware\n"); |
| 5414 | return rc; |
| 5415 | } |
| 5416 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5417 | /* |
| 5418 | * Extra headroom is the size of the required DMA header |
| 5419 | * minus the size of the smallest 802.11 frame (CTS frame). |
| 5420 | */ |
| 5421 | hw->extra_tx_headroom = |
| 5422 | sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts); |
| 5423 | |
| 5424 | hw->channel_change_time = 10; |
| 5425 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5426 | hw->queues = MWL8K_TX_WMM_QUEUES; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5427 | |
| 5428 | /* Set rssi values to dBm */ |
Nishant Sarmukadam | 0bf22c3 | 2011-02-17 14:45:17 -0800 | [diff] [blame] | 5429 | hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5430 | hw->vif_data_size = sizeof(struct mwl8k_vif); |
| 5431 | hw->sta_data_size = sizeof(struct mwl8k_sta); |
| 5432 | |
| 5433 | priv->macids_used = 0; |
| 5434 | INIT_LIST_HEAD(&priv->vif_list); |
| 5435 | |
| 5436 | /* Set default radio state and preamble */ |
| 5437 | priv->radio_on = 0; |
| 5438 | priv->radio_short_preamble = 0; |
| 5439 | |
| 5440 | /* Finalize join worker */ |
| 5441 | INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 5442 | /* Handle watchdog ba events */ |
| 5443 | INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5444 | |
| 5445 | /* TX reclaim and RX tasklets. */ |
| 5446 | tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw); |
| 5447 | tasklet_disable(&priv->poll_tx_task); |
| 5448 | tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw); |
| 5449 | tasklet_disable(&priv->poll_rx_task); |
| 5450 | |
| 5451 | /* Power management cookie */ |
| 5452 | priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma); |
| 5453 | if (priv->cookie == NULL) |
| 5454 | return -ENOMEM; |
| 5455 | |
| 5456 | mutex_init(&priv->fw_mutex); |
| 5457 | priv->fw_mutex_owner = NULL; |
| 5458 | priv->fw_mutex_depth = 0; |
| 5459 | priv->hostcmd_wait = NULL; |
| 5460 | |
| 5461 | spin_lock_init(&priv->tx_lock); |
| 5462 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 5463 | spin_lock_init(&priv->stream_lock); |
| 5464 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5465 | priv->tx_wait = NULL; |
| 5466 | |
| 5467 | rc = mwl8k_probe_hw(hw); |
| 5468 | if (rc) |
| 5469 | goto err_free_cookie; |
| 5470 | |
| 5471 | hw->wiphy->interface_modes = 0; |
| 5472 | if (priv->ap_macids_supported || priv->device_info->fw_image_ap) |
| 5473 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP); |
| 5474 | if (priv->sta_macids_supported || priv->device_info->fw_image_sta) |
| 5475 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION); |
| 5476 | |
| 5477 | rc = ieee80211_register_hw(hw); |
| 5478 | if (rc) { |
| 5479 | wiphy_err(hw->wiphy, "Cannot register device\n"); |
| 5480 | goto err_unprobe_hw; |
| 5481 | } |
| 5482 | |
| 5483 | return 0; |
| 5484 | |
| 5485 | err_unprobe_hw: |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5486 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5487 | mwl8k_txq_deinit(hw, i); |
| 5488 | mwl8k_rxq_deinit(hw, 0); |
| 5489 | |
| 5490 | err_free_cookie: |
| 5491 | if (priv->cookie != NULL) |
| 5492 | pci_free_consistent(priv->pdev, 4, |
| 5493 | priv->cookie, priv->cookie_dma); |
| 5494 | |
| 5495 | return rc; |
| 5496 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5497 | static int __devinit mwl8k_probe(struct pci_dev *pdev, |
| 5498 | const struct pci_device_id *id) |
| 5499 | { |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5500 | static int printed_version; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5501 | struct ieee80211_hw *hw; |
| 5502 | struct mwl8k_priv *priv; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5503 | struct mwl8k_device_info *di; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5504 | int rc; |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 5505 | |
| 5506 | if (!printed_version) { |
| 5507 | printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION); |
| 5508 | printed_version = 1; |
| 5509 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5510 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5511 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5512 | rc = pci_enable_device(pdev); |
| 5513 | if (rc) { |
| 5514 | printk(KERN_ERR "%s: Cannot enable new PCI device\n", |
| 5515 | MWL8K_NAME); |
| 5516 | return rc; |
| 5517 | } |
| 5518 | |
| 5519 | rc = pci_request_regions(pdev, MWL8K_NAME); |
| 5520 | if (rc) { |
| 5521 | printk(KERN_ERR "%s: Cannot obtain PCI resources\n", |
| 5522 | MWL8K_NAME); |
Lennert Buytenhek | 3db95e5 | 2009-11-30 18:13:34 +0100 | [diff] [blame] | 5523 | goto err_disable_device; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5524 | } |
| 5525 | |
| 5526 | pci_set_master(pdev); |
| 5527 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5528 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5529 | hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops); |
| 5530 | if (hw == NULL) { |
| 5531 | printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME); |
| 5532 | rc = -ENOMEM; |
| 5533 | goto err_free_reg; |
| 5534 | } |
| 5535 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5536 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 5537 | pci_set_drvdata(pdev, hw); |
| 5538 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5539 | priv = hw->priv; |
| 5540 | priv->hw = hw; |
| 5541 | priv->pdev = pdev; |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5542 | priv->device_info = &mwl8k_info_tbl[id->driver_data]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5543 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5544 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5545 | priv->sram = pci_iomap(pdev, 0, 0x10000); |
| 5546 | if (priv->sram == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 5547 | wiphy_err(hw->wiphy, "Cannot map device SRAM\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5548 | goto err_iounmap; |
| 5549 | } |
| 5550 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5551 | /* |
| 5552 | * If BAR0 is a 32 bit BAR, the register BAR will be BAR1. |
| 5553 | * If BAR0 is a 64 bit BAR, the register BAR will be BAR2. |
| 5554 | */ |
| 5555 | priv->regs = pci_iomap(pdev, 1, 0x10000); |
| 5556 | if (priv->regs == NULL) { |
| 5557 | priv->regs = pci_iomap(pdev, 2, 0x10000); |
| 5558 | if (priv->regs == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 5559 | wiphy_err(hw->wiphy, "Cannot map device registers\n"); |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5560 | goto err_iounmap; |
| 5561 | } |
| 5562 | } |
| 5563 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5564 | /* |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5565 | * Choose the initial fw image depending on user input. If a second |
| 5566 | * image is available, make it the alternative image that will be |
| 5567 | * loaded if the first one fails. |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5568 | */ |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5569 | init_completion(&priv->firmware_loading_complete); |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5570 | di = priv->device_info; |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5571 | if (ap_mode_default && di->fw_image_ap) { |
| 5572 | priv->fw_pref = di->fw_image_ap; |
| 5573 | priv->fw_alt = di->fw_image_sta; |
| 5574 | } else if (!ap_mode_default && di->fw_image_sta) { |
| 5575 | priv->fw_pref = di->fw_image_sta; |
| 5576 | priv->fw_alt = di->fw_image_ap; |
| 5577 | } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) { |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5578 | printk(KERN_WARNING "AP fw is unavailable. Using STA fw."); |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5579 | priv->fw_pref = di->fw_image_sta; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5580 | } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) { |
| 5581 | printk(KERN_WARNING "STA fw is unavailable. Using AP fw."); |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5582 | priv->fw_pref = di->fw_image_ap; |
| 5583 | } |
| 5584 | rc = mwl8k_init_firmware(hw, priv->fw_pref, true); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5585 | if (rc) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5586 | goto err_stop_firmware; |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5587 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5588 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5589 | err_stop_firmware: |
| 5590 | mwl8k_hw_reset(priv); |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5591 | |
| 5592 | err_iounmap: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5593 | if (priv->regs != NULL) |
| 5594 | pci_iounmap(pdev, priv->regs); |
| 5595 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5596 | if (priv->sram != NULL) |
| 5597 | pci_iounmap(pdev, priv->sram); |
| 5598 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5599 | pci_set_drvdata(pdev, NULL); |
| 5600 | ieee80211_free_hw(hw); |
| 5601 | |
| 5602 | err_free_reg: |
| 5603 | pci_release_regions(pdev); |
Lennert Buytenhek | 3db95e5 | 2009-11-30 18:13:34 +0100 | [diff] [blame] | 5604 | |
| 5605 | err_disable_device: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5606 | pci_disable_device(pdev); |
| 5607 | |
| 5608 | return rc; |
| 5609 | } |
| 5610 | |
Joerg Albert | 230f7af | 2009-04-18 02:10:45 +0200 | [diff] [blame] | 5611 | static void __devexit mwl8k_shutdown(struct pci_dev *pdev) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5612 | { |
| 5613 | printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__); |
| 5614 | } |
| 5615 | |
Joerg Albert | 230f7af | 2009-04-18 02:10:45 +0200 | [diff] [blame] | 5616 | static void __devexit mwl8k_remove(struct pci_dev *pdev) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5617 | { |
| 5618 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 5619 | struct mwl8k_priv *priv; |
| 5620 | int i; |
| 5621 | |
| 5622 | if (hw == NULL) |
| 5623 | return; |
| 5624 | priv = hw->priv; |
| 5625 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5626 | wait_for_completion(&priv->firmware_loading_complete); |
| 5627 | |
| 5628 | if (priv->fw_state == FW_STATE_ERROR) { |
| 5629 | mwl8k_hw_reset(priv); |
| 5630 | goto unmap; |
| 5631 | } |
| 5632 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5633 | ieee80211_stop_queues(hw); |
| 5634 | |
Lennert Buytenhek | 60aa569 | 2009-08-03 21:59:09 +0200 | [diff] [blame] | 5635 | ieee80211_unregister_hw(hw); |
| 5636 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 5637 | /* Remove TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 5638 | tasklet_kill(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 5639 | tasklet_kill(&priv->poll_rx_task); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5640 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5641 | /* Stop hardware */ |
| 5642 | mwl8k_hw_reset(priv); |
| 5643 | |
| 5644 | /* Return all skbs to mac80211 */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5645 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 5646 | mwl8k_txq_reclaim(hw, i, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5647 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5648 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5649 | mwl8k_txq_deinit(hw, i); |
| 5650 | |
| 5651 | mwl8k_rxq_deinit(hw, 0); |
| 5652 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 5653 | pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5654 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5655 | unmap: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5656 | pci_iounmap(pdev, priv->regs); |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5657 | pci_iounmap(pdev, priv->sram); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5658 | pci_set_drvdata(pdev, NULL); |
| 5659 | ieee80211_free_hw(hw); |
| 5660 | pci_release_regions(pdev); |
| 5661 | pci_disable_device(pdev); |
| 5662 | } |
| 5663 | |
| 5664 | static struct pci_driver mwl8k_driver = { |
| 5665 | .name = MWL8K_NAME, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5666 | .id_table = mwl8k_pci_id_table, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5667 | .probe = mwl8k_probe, |
| 5668 | .remove = __devexit_p(mwl8k_remove), |
| 5669 | .shutdown = __devexit_p(mwl8k_shutdown), |
| 5670 | }; |
| 5671 | |
| 5672 | static int __init mwl8k_init(void) |
| 5673 | { |
| 5674 | return pci_register_driver(&mwl8k_driver); |
| 5675 | } |
| 5676 | |
| 5677 | static void __exit mwl8k_exit(void) |
| 5678 | { |
| 5679 | pci_unregister_driver(&mwl8k_driver); |
| 5680 | } |
| 5681 | |
| 5682 | module_init(mwl8k_init); |
| 5683 | module_exit(mwl8k_exit); |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 5684 | |
| 5685 | MODULE_DESCRIPTION(MWL8K_DESC); |
| 5686 | MODULE_VERSION(MWL8K_VERSION); |
| 5687 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>"); |
| 5688 | MODULE_LICENSE("GPL"); |