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 | a145d57 | 2009-08-18 04:34:26 +0200 | [diff] [blame] | 5 | * Copyright (C) 2008-2009 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> |
| 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/list.h> |
| 17 | #include <linux/pci.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/completion.h> |
| 20 | #include <linux/etherdevice.h> |
| 21 | #include <net/mac80211.h> |
| 22 | #include <linux/moduleparam.h> |
| 23 | #include <linux/firmware.h> |
| 24 | #include <linux/workqueue.h> |
| 25 | |
| 26 | #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver" |
| 27 | #define MWL8K_NAME KBUILD_MODNAME |
Lennert Buytenhek | a145d57 | 2009-08-18 04:34:26 +0200 | [diff] [blame] | 28 | #define MWL8K_VERSION "0.10" |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 29 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 30 | static DEFINE_PCI_DEVICE_TABLE(mwl8k_table) = { |
| 31 | { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = 8687, }, |
| 32 | { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = 8687, }, |
| 33 | { } |
| 34 | }; |
| 35 | MODULE_DEVICE_TABLE(pci, mwl8k_table); |
| 36 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 37 | /* Register definitions */ |
| 38 | #define MWL8K_HIU_GEN_PTR 0x00000c10 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 39 | #define MWL8K_MODE_STA 0x0000005a |
| 40 | #define MWL8K_MODE_AP 0x000000a5 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 41 | #define MWL8K_HIU_INT_CODE 0x00000c14 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 42 | #define MWL8K_FWSTA_READY 0xf0f1f2f4 |
| 43 | #define MWL8K_FWAP_READY 0xf1f2f4a5 |
| 44 | #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 45 | #define MWL8K_HIU_SCRATCH 0x00000c40 |
| 46 | |
| 47 | /* Host->device communications */ |
| 48 | #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18 |
| 49 | #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c |
| 50 | #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20 |
| 51 | #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24 |
| 52 | #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 53 | #define MWL8K_H2A_INT_DUMMY (1 << 20) |
| 54 | #define MWL8K_H2A_INT_RESET (1 << 15) |
| 55 | #define MWL8K_H2A_INT_DOORBELL (1 << 1) |
| 56 | #define MWL8K_H2A_INT_PPA_READY (1 << 0) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 57 | |
| 58 | /* Device->host communications */ |
| 59 | #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c |
| 60 | #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30 |
| 61 | #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34 |
| 62 | #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38 |
| 63 | #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 64 | #define MWL8K_A2H_INT_DUMMY (1 << 20) |
| 65 | #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11) |
| 66 | #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10) |
| 67 | #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7) |
| 68 | #define MWL8K_A2H_INT_RADIO_ON (1 << 6) |
| 69 | #define MWL8K_A2H_INT_RADIO_OFF (1 << 5) |
| 70 | #define MWL8K_A2H_INT_MAC_EVENT (1 << 3) |
| 71 | #define MWL8K_A2H_INT_OPC_DONE (1 << 2) |
| 72 | #define MWL8K_A2H_INT_RX_READY (1 << 1) |
| 73 | #define MWL8K_A2H_INT_TX_DONE (1 << 0) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 74 | |
| 75 | #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \ |
| 76 | MWL8K_A2H_INT_CHNL_SWITCHED | \ |
| 77 | MWL8K_A2H_INT_QUEUE_EMPTY | \ |
| 78 | MWL8K_A2H_INT_RADAR_DETECT | \ |
| 79 | MWL8K_A2H_INT_RADIO_ON | \ |
| 80 | MWL8K_A2H_INT_RADIO_OFF | \ |
| 81 | MWL8K_A2H_INT_MAC_EVENT | \ |
| 82 | MWL8K_A2H_INT_OPC_DONE | \ |
| 83 | MWL8K_A2H_INT_RX_READY | \ |
| 84 | MWL8K_A2H_INT_TX_DONE) |
| 85 | |
| 86 | /* WME stream classes */ |
| 87 | #define WME_AC_BE 0 /* best effort */ |
| 88 | #define WME_AC_BK 1 /* background */ |
| 89 | #define WME_AC_VI 2 /* video */ |
| 90 | #define WME_AC_VO 3 /* voice */ |
| 91 | |
| 92 | #define MWL8K_RX_QUEUES 1 |
| 93 | #define MWL8K_TX_QUEUES 4 |
| 94 | |
| 95 | struct mwl8k_rx_queue { |
| 96 | int rx_desc_count; |
| 97 | |
| 98 | /* hw receives here */ |
| 99 | int rx_head; |
| 100 | |
| 101 | /* refill descs here */ |
| 102 | int rx_tail; |
| 103 | |
| 104 | struct mwl8k_rx_desc *rx_desc_area; |
| 105 | dma_addr_t rx_desc_dma; |
| 106 | struct sk_buff **rx_skb; |
| 107 | }; |
| 108 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 109 | struct mwl8k_tx_queue { |
| 110 | /* hw transmits here */ |
| 111 | int tx_head; |
| 112 | |
| 113 | /* sw appends here */ |
| 114 | int tx_tail; |
| 115 | |
| 116 | struct ieee80211_tx_queue_stats tx_stats; |
| 117 | struct mwl8k_tx_desc *tx_desc_area; |
| 118 | dma_addr_t tx_desc_dma; |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 119 | struct sk_buff **tx_skb; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /* Pointers to the firmware data and meta information about it. */ |
| 123 | struct mwl8k_firmware { |
| 124 | /* Microcode */ |
| 125 | struct firmware *ucode; |
| 126 | |
| 127 | /* Boot helper code */ |
| 128 | struct firmware *helper; |
| 129 | }; |
| 130 | |
| 131 | struct mwl8k_priv { |
| 132 | void __iomem *regs; |
| 133 | struct ieee80211_hw *hw; |
| 134 | |
| 135 | struct pci_dev *pdev; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 136 | |
| 137 | /* firmware files and meta data */ |
| 138 | struct mwl8k_firmware fw; |
| 139 | u32 part_num; |
| 140 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 141 | /* firmware access */ |
| 142 | struct mutex fw_mutex; |
| 143 | struct task_struct *fw_mutex_owner; |
| 144 | int fw_mutex_depth; |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 145 | struct completion *hostcmd_wait; |
| 146 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 147 | /* lock held over TX and TX reap */ |
| 148 | spinlock_t tx_lock; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 149 | |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 150 | /* TX quiesce completion, protected by fw_mutex and tx_lock */ |
| 151 | struct completion *tx_wait; |
| 152 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 153 | struct ieee80211_vif *vif; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 154 | |
| 155 | struct ieee80211_channel *current_channel; |
| 156 | |
| 157 | /* power management status cookie from firmware */ |
| 158 | u32 *cookie; |
| 159 | dma_addr_t cookie_dma; |
| 160 | |
| 161 | u16 num_mcaddrs; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 162 | u8 hw_rev; |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 163 | u32 fw_rev; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * Running count of TX packets in flight, to avoid |
| 167 | * iterating over the transmit rings each time. |
| 168 | */ |
| 169 | int pending_tx_pkts; |
| 170 | |
| 171 | struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES]; |
| 172 | struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES]; |
| 173 | |
| 174 | /* PHY parameters */ |
| 175 | struct ieee80211_supported_band band; |
| 176 | struct ieee80211_channel channels[14]; |
| 177 | struct ieee80211_rate rates[12]; |
| 178 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 179 | bool radio_on; |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 180 | bool radio_short_preamble; |
Lennert Buytenhek | 0439b1f | 2009-07-16 12:34:02 +0200 | [diff] [blame] | 181 | bool wmm_enabled; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 182 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 183 | /* XXX need to convert this to handle multiple interfaces */ |
| 184 | bool capture_beacon; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 185 | u8 capture_bssid[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 186 | struct sk_buff *beacon_skb; |
| 187 | |
| 188 | /* |
| 189 | * This FJ worker has to be global as it is scheduled from the |
| 190 | * RX handler. At this point we don't know which interface it |
| 191 | * belongs to until the list of bssids waiting to complete join |
| 192 | * is checked. |
| 193 | */ |
| 194 | struct work_struct finalize_join_worker; |
| 195 | |
| 196 | /* Tasklet to reclaim TX descriptors and buffers after tx */ |
| 197 | struct tasklet_struct tx_reclaim_task; |
| 198 | |
| 199 | /* Work thread to serialize configuration requests */ |
| 200 | struct workqueue_struct *config_wq; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | /* Per interface specific private data */ |
| 204 | struct mwl8k_vif { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 205 | /* backpointer to parent config block */ |
| 206 | struct mwl8k_priv *priv; |
| 207 | |
| 208 | /* BSS config of AP or IBSS from mac80211*/ |
| 209 | struct ieee80211_bss_conf bss_info; |
| 210 | |
| 211 | /* BSSID of AP or IBSS */ |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 212 | u8 bssid[ETH_ALEN]; |
| 213 | u8 mac_addr[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 214 | |
| 215 | /* |
| 216 | * Subset of supported legacy rates. |
| 217 | * Intersection of AP and STA supported rates. |
| 218 | */ |
| 219 | struct ieee80211_rate legacy_rates[12]; |
| 220 | |
| 221 | /* number of supported legacy rates */ |
| 222 | u8 legacy_nrates; |
| 223 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 224 | /* Index into station database.Returned by update_sta_db call */ |
| 225 | u8 peer_id; |
| 226 | |
| 227 | /* Non AMPDU sequence number assigned by driver */ |
| 228 | u16 seqno; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 229 | }; |
| 230 | |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 231 | #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 232 | |
| 233 | static const struct ieee80211_channel mwl8k_channels[] = { |
| 234 | { .center_freq = 2412, .hw_value = 1, }, |
| 235 | { .center_freq = 2417, .hw_value = 2, }, |
| 236 | { .center_freq = 2422, .hw_value = 3, }, |
| 237 | { .center_freq = 2427, .hw_value = 4, }, |
| 238 | { .center_freq = 2432, .hw_value = 5, }, |
| 239 | { .center_freq = 2437, .hw_value = 6, }, |
| 240 | { .center_freq = 2442, .hw_value = 7, }, |
| 241 | { .center_freq = 2447, .hw_value = 8, }, |
| 242 | { .center_freq = 2452, .hw_value = 9, }, |
| 243 | { .center_freq = 2457, .hw_value = 10, }, |
| 244 | { .center_freq = 2462, .hw_value = 11, }, |
| 245 | }; |
| 246 | |
| 247 | static const struct ieee80211_rate mwl8k_rates[] = { |
| 248 | { .bitrate = 10, .hw_value = 2, }, |
| 249 | { .bitrate = 20, .hw_value = 4, }, |
| 250 | { .bitrate = 55, .hw_value = 11, }, |
| 251 | { .bitrate = 60, .hw_value = 12, }, |
| 252 | { .bitrate = 90, .hw_value = 18, }, |
| 253 | { .bitrate = 110, .hw_value = 22, }, |
| 254 | { .bitrate = 120, .hw_value = 24, }, |
| 255 | { .bitrate = 180, .hw_value = 36, }, |
| 256 | { .bitrate = 240, .hw_value = 48, }, |
| 257 | { .bitrate = 360, .hw_value = 72, }, |
| 258 | { .bitrate = 480, .hw_value = 96, }, |
| 259 | { .bitrate = 540, .hw_value = 108, }, |
| 260 | }; |
| 261 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 262 | /* Set or get info from Firmware */ |
| 263 | #define MWL8K_CMD_SET 0x0001 |
| 264 | #define MWL8K_CMD_GET 0x0000 |
| 265 | |
| 266 | /* Firmware command codes */ |
| 267 | #define MWL8K_CMD_CODE_DNLD 0x0001 |
| 268 | #define MWL8K_CMD_GET_HW_SPEC 0x0003 |
| 269 | #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010 |
| 270 | #define MWL8K_CMD_GET_STAT 0x0014 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 271 | #define MWL8K_CMD_RADIO_CONTROL 0x001c |
| 272 | #define MWL8K_CMD_RF_TX_POWER 0x001e |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 273 | #define MWL8K_CMD_SET_PRE_SCAN 0x0107 |
| 274 | #define MWL8K_CMD_SET_POST_SCAN 0x0108 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 275 | #define MWL8K_CMD_SET_RF_CHANNEL 0x010a |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 276 | #define MWL8K_CMD_SET_AID 0x010d |
| 277 | #define MWL8K_CMD_SET_RATE 0x0110 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 278 | #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 279 | #define MWL8K_CMD_RTS_THRESHOLD 0x0113 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 280 | #define MWL8K_CMD_SET_SLOT 0x0114 |
| 281 | #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115 |
| 282 | #define MWL8K_CMD_SET_WMM_MODE 0x0123 |
| 283 | #define MWL8K_CMD_MIMO_CONFIG 0x0125 |
| 284 | #define MWL8K_CMD_USE_FIXED_RATE 0x0126 |
| 285 | #define MWL8K_CMD_ENABLE_SNIFFER 0x0150 |
| 286 | #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203 |
| 287 | #define MWL8K_CMD_UPDATE_STADB 0x1123 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 288 | |
| 289 | static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize) |
| 290 | { |
| 291 | #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\ |
| 292 | snprintf(buf, bufsize, "%s", #x);\ |
| 293 | return buf;\ |
| 294 | } while (0) |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 295 | switch (cmd & ~0x8000) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 296 | MWL8K_CMDNAME(CODE_DNLD); |
| 297 | MWL8K_CMDNAME(GET_HW_SPEC); |
| 298 | MWL8K_CMDNAME(MAC_MULTICAST_ADR); |
| 299 | MWL8K_CMDNAME(GET_STAT); |
| 300 | MWL8K_CMDNAME(RADIO_CONTROL); |
| 301 | MWL8K_CMDNAME(RF_TX_POWER); |
| 302 | MWL8K_CMDNAME(SET_PRE_SCAN); |
| 303 | MWL8K_CMDNAME(SET_POST_SCAN); |
| 304 | MWL8K_CMDNAME(SET_RF_CHANNEL); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 305 | MWL8K_CMDNAME(SET_AID); |
| 306 | MWL8K_CMDNAME(SET_RATE); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 307 | MWL8K_CMDNAME(SET_FINALIZE_JOIN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 308 | MWL8K_CMDNAME(RTS_THRESHOLD); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 309 | MWL8K_CMDNAME(SET_SLOT); |
| 310 | MWL8K_CMDNAME(SET_EDCA_PARAMS); |
| 311 | MWL8K_CMDNAME(SET_WMM_MODE); |
| 312 | MWL8K_CMDNAME(MIMO_CONFIG); |
| 313 | MWL8K_CMDNAME(USE_FIXED_RATE); |
| 314 | MWL8K_CMDNAME(ENABLE_SNIFFER); |
| 315 | MWL8K_CMDNAME(SET_RATEADAPT_MODE); |
| 316 | MWL8K_CMDNAME(UPDATE_STADB); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 317 | default: |
| 318 | snprintf(buf, bufsize, "0x%x", cmd); |
| 319 | } |
| 320 | #undef MWL8K_CMDNAME |
| 321 | |
| 322 | return buf; |
| 323 | } |
| 324 | |
| 325 | /* Hardware and firmware reset */ |
| 326 | static void mwl8k_hw_reset(struct mwl8k_priv *priv) |
| 327 | { |
| 328 | iowrite32(MWL8K_H2A_INT_RESET, |
| 329 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 330 | iowrite32(MWL8K_H2A_INT_RESET, |
| 331 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 332 | msleep(20); |
| 333 | } |
| 334 | |
| 335 | /* Release fw image */ |
| 336 | static void mwl8k_release_fw(struct firmware **fw) |
| 337 | { |
| 338 | if (*fw == NULL) |
| 339 | return; |
| 340 | release_firmware(*fw); |
| 341 | *fw = NULL; |
| 342 | } |
| 343 | |
| 344 | static void mwl8k_release_firmware(struct mwl8k_priv *priv) |
| 345 | { |
| 346 | mwl8k_release_fw(&priv->fw.ucode); |
| 347 | mwl8k_release_fw(&priv->fw.helper); |
| 348 | } |
| 349 | |
| 350 | /* Request fw image */ |
| 351 | static int mwl8k_request_fw(struct mwl8k_priv *priv, |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 352 | const char *fname, struct firmware **fw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 353 | { |
| 354 | /* release current image */ |
| 355 | if (*fw != NULL) |
| 356 | mwl8k_release_fw(fw); |
| 357 | |
| 358 | return request_firmware((const struct firmware **)fw, |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 359 | fname, &priv->pdev->dev); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static int mwl8k_request_firmware(struct mwl8k_priv *priv, u32 part_num) |
| 363 | { |
| 364 | u8 filename[64]; |
| 365 | int rc; |
| 366 | |
| 367 | priv->part_num = part_num; |
| 368 | |
| 369 | snprintf(filename, sizeof(filename), |
| 370 | "mwl8k/helper_%u.fw", priv->part_num); |
| 371 | |
| 372 | rc = mwl8k_request_fw(priv, filename, &priv->fw.helper); |
| 373 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 374 | printk(KERN_ERR "%s: Error requesting helper firmware " |
| 375 | "file %s\n", pci_name(priv->pdev), filename); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 376 | return rc; |
| 377 | } |
| 378 | |
| 379 | snprintf(filename, sizeof(filename), |
| 380 | "mwl8k/fmimage_%u.fw", priv->part_num); |
| 381 | |
| 382 | rc = mwl8k_request_fw(priv, filename, &priv->fw.ucode); |
| 383 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 384 | printk(KERN_ERR "%s: Error requesting firmware file %s\n", |
| 385 | pci_name(priv->pdev), filename); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 386 | mwl8k_release_fw(&priv->fw.helper); |
| 387 | return rc; |
| 388 | } |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | struct mwl8k_cmd_pkt { |
| 394 | __le16 code; |
| 395 | __le16 length; |
| 396 | __le16 seq_num; |
| 397 | __le16 result; |
| 398 | char payload[0]; |
| 399 | } __attribute__((packed)); |
| 400 | |
| 401 | /* |
| 402 | * Firmware loading. |
| 403 | */ |
| 404 | static int |
| 405 | mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length) |
| 406 | { |
| 407 | void __iomem *regs = priv->regs; |
| 408 | dma_addr_t dma_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 409 | int loops; |
| 410 | |
| 411 | dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE); |
| 412 | if (pci_dma_mapping_error(priv->pdev, dma_addr)) |
| 413 | return -ENOMEM; |
| 414 | |
| 415 | iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR); |
| 416 | iowrite32(0, regs + MWL8K_HIU_INT_CODE); |
| 417 | iowrite32(MWL8K_H2A_INT_DOORBELL, |
| 418 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 419 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 420 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 421 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 422 | loops = 1000; |
| 423 | do { |
| 424 | u32 int_code; |
| 425 | |
| 426 | int_code = ioread32(regs + MWL8K_HIU_INT_CODE); |
| 427 | if (int_code == MWL8K_INT_CODE_CMD_FINISHED) { |
| 428 | iowrite32(0, regs + MWL8K_HIU_INT_CODE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 429 | break; |
| 430 | } |
| 431 | |
| 432 | udelay(1); |
| 433 | } while (--loops); |
| 434 | |
| 435 | pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE); |
| 436 | |
Lennert Buytenhek | d4b70570 | 2009-07-16 12:44:45 +0200 | [diff] [blame] | 437 | return loops ? 0 : -ETIMEDOUT; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static int mwl8k_load_fw_image(struct mwl8k_priv *priv, |
| 441 | const u8 *data, size_t length) |
| 442 | { |
| 443 | struct mwl8k_cmd_pkt *cmd; |
| 444 | int done; |
| 445 | int rc = 0; |
| 446 | |
| 447 | cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL); |
| 448 | if (cmd == NULL) |
| 449 | return -ENOMEM; |
| 450 | |
| 451 | cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD); |
| 452 | cmd->seq_num = 0; |
| 453 | cmd->result = 0; |
| 454 | |
| 455 | done = 0; |
| 456 | while (length) { |
| 457 | int block_size = length > 256 ? 256 : length; |
| 458 | |
| 459 | memcpy(cmd->payload, data + done, block_size); |
| 460 | cmd->length = cpu_to_le16(block_size); |
| 461 | |
| 462 | rc = mwl8k_send_fw_load_cmd(priv, cmd, |
| 463 | sizeof(*cmd) + block_size); |
| 464 | if (rc) |
| 465 | break; |
| 466 | |
| 467 | done += block_size; |
| 468 | length -= block_size; |
| 469 | } |
| 470 | |
| 471 | if (!rc) { |
| 472 | cmd->length = 0; |
| 473 | rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd)); |
| 474 | } |
| 475 | |
| 476 | kfree(cmd); |
| 477 | |
| 478 | return rc; |
| 479 | } |
| 480 | |
| 481 | static int mwl8k_feed_fw_image(struct mwl8k_priv *priv, |
| 482 | const u8 *data, size_t length) |
| 483 | { |
| 484 | unsigned char *buffer; |
| 485 | int may_continue, rc = 0; |
| 486 | u32 done, prev_block_size; |
| 487 | |
| 488 | buffer = kmalloc(1024, GFP_KERNEL); |
| 489 | if (buffer == NULL) |
| 490 | return -ENOMEM; |
| 491 | |
| 492 | done = 0; |
| 493 | prev_block_size = 0; |
| 494 | may_continue = 1000; |
| 495 | while (may_continue > 0) { |
| 496 | u32 block_size; |
| 497 | |
| 498 | block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH); |
| 499 | if (block_size & 1) { |
| 500 | block_size &= ~1; |
| 501 | may_continue--; |
| 502 | } else { |
| 503 | done += prev_block_size; |
| 504 | length -= prev_block_size; |
| 505 | } |
| 506 | |
| 507 | if (block_size > 1024 || block_size > length) { |
| 508 | rc = -EOVERFLOW; |
| 509 | break; |
| 510 | } |
| 511 | |
| 512 | if (length == 0) { |
| 513 | rc = 0; |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | if (block_size == 0) { |
| 518 | rc = -EPROTO; |
| 519 | may_continue--; |
| 520 | udelay(1); |
| 521 | continue; |
| 522 | } |
| 523 | |
| 524 | prev_block_size = block_size; |
| 525 | memcpy(buffer, data + done, block_size); |
| 526 | |
| 527 | rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size); |
| 528 | if (rc) |
| 529 | break; |
| 530 | } |
| 531 | |
| 532 | if (!rc && length != 0) |
| 533 | rc = -EREMOTEIO; |
| 534 | |
| 535 | kfree(buffer); |
| 536 | |
| 537 | return rc; |
| 538 | } |
| 539 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 540 | static int mwl8k_load_firmware(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 541 | { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 542 | struct mwl8k_priv *priv = hw->priv; |
| 543 | struct firmware *fw = priv->fw.ucode; |
| 544 | int rc; |
| 545 | int loops; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 546 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 547 | if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) { |
| 548 | struct firmware *helper = priv->fw.helper; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 549 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 550 | if (helper == NULL) { |
| 551 | printk(KERN_ERR "%s: helper image needed but none " |
| 552 | "given\n", pci_name(priv->pdev)); |
| 553 | return -EINVAL; |
| 554 | } |
| 555 | |
| 556 | rc = mwl8k_load_fw_image(priv, helper->data, helper->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 557 | if (rc) { |
| 558 | printk(KERN_ERR "%s: unable to load firmware " |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 559 | "helper image\n", pci_name(priv->pdev)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 560 | return rc; |
| 561 | } |
| 562 | msleep(1); |
| 563 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 564 | rc = mwl8k_feed_fw_image(priv, fw->data, fw->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 565 | } else { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 566 | rc = mwl8k_load_fw_image(priv, fw->data, fw->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 570 | printk(KERN_ERR "%s: unable to load firmware image\n", |
| 571 | pci_name(priv->pdev)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 572 | return rc; |
| 573 | } |
| 574 | |
| 575 | iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR); |
| 576 | msleep(1); |
| 577 | |
| 578 | loops = 200000; |
| 579 | do { |
| 580 | if (ioread32(priv->regs + MWL8K_HIU_INT_CODE) |
| 581 | == MWL8K_FWSTA_READY) |
| 582 | break; |
| 583 | udelay(1); |
| 584 | } while (--loops); |
| 585 | |
| 586 | return loops ? 0 : -ETIMEDOUT; |
| 587 | } |
| 588 | |
| 589 | |
| 590 | /* |
| 591 | * Defines shared between transmission and reception. |
| 592 | */ |
| 593 | /* HT control fields for firmware */ |
| 594 | struct ewc_ht_info { |
| 595 | __le16 control1; |
| 596 | __le16 control2; |
| 597 | __le16 control3; |
| 598 | } __attribute__((packed)); |
| 599 | |
| 600 | /* Firmware Station database operations */ |
| 601 | #define MWL8K_STA_DB_ADD_ENTRY 0 |
| 602 | #define MWL8K_STA_DB_MODIFY_ENTRY 1 |
| 603 | #define MWL8K_STA_DB_DEL_ENTRY 2 |
| 604 | #define MWL8K_STA_DB_FLUSH 3 |
| 605 | |
| 606 | /* Peer Entry flags - used to define the type of the peer node */ |
| 607 | #define MWL8K_PEER_TYPE_ACCESSPOINT 2 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 608 | |
| 609 | #define MWL8K_IEEE_LEGACY_DATA_RATES 12 |
| 610 | #define MWL8K_MCS_BITMAP_SIZE 16 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 611 | |
| 612 | struct peer_capability_info { |
| 613 | /* Peer type - AP vs. STA. */ |
| 614 | __u8 peer_type; |
| 615 | |
| 616 | /* Basic 802.11 capabilities from assoc resp. */ |
| 617 | __le16 basic_caps; |
| 618 | |
| 619 | /* Set if peer supports 802.11n high throughput (HT). */ |
| 620 | __u8 ht_support; |
| 621 | |
| 622 | /* Valid if HT is supported. */ |
| 623 | __le16 ht_caps; |
| 624 | __u8 extended_ht_caps; |
| 625 | struct ewc_ht_info ewc_info; |
| 626 | |
| 627 | /* Legacy rate table. Intersection of our rates and peer rates. */ |
| 628 | __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES]; |
| 629 | |
| 630 | /* HT rate table. Intersection of our rates and peer rates. */ |
| 631 | __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE]; |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 632 | __u8 pad[16]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 633 | |
| 634 | /* If set, interoperability mode, no proprietary extensions. */ |
| 635 | __u8 interop; |
| 636 | __u8 pad2; |
| 637 | __u8 station_id; |
| 638 | __le16 amsdu_enabled; |
| 639 | } __attribute__((packed)); |
| 640 | |
| 641 | /* Inline functions to manipulate QoS field in data descriptor. */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 642 | static inline u16 mwl8k_qos_setbit_eosp(u16 qos) |
| 643 | { |
| 644 | u16 val_mask = 1 << 4; |
| 645 | |
| 646 | /* End of Service Period Bit 4 */ |
| 647 | return qos | val_mask; |
| 648 | } |
| 649 | |
| 650 | static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy) |
| 651 | { |
| 652 | u16 val_mask = 0x3; |
| 653 | u8 shift = 5; |
| 654 | u16 qos_mask = ~(val_mask << shift); |
| 655 | |
| 656 | /* Ack Policy Bit 5-6 */ |
| 657 | return (qos & qos_mask) | ((ack_policy & val_mask) << shift); |
| 658 | } |
| 659 | |
| 660 | static inline u16 mwl8k_qos_setbit_amsdu(u16 qos) |
| 661 | { |
| 662 | u16 val_mask = 1 << 7; |
| 663 | |
| 664 | /* AMSDU present Bit 7 */ |
| 665 | return qos | val_mask; |
| 666 | } |
| 667 | |
| 668 | static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len) |
| 669 | { |
| 670 | u16 val_mask = 0xff; |
| 671 | u8 shift = 8; |
| 672 | u16 qos_mask = ~(val_mask << shift); |
| 673 | |
| 674 | /* Queue Length Bits 8-15 */ |
| 675 | return (qos & qos_mask) | ((len & val_mask) << shift); |
| 676 | } |
| 677 | |
| 678 | /* DMA header used by firmware and hardware. */ |
| 679 | struct mwl8k_dma_data { |
| 680 | __le16 fwlen; |
| 681 | struct ieee80211_hdr wh; |
| 682 | } __attribute__((packed)); |
| 683 | |
| 684 | /* Routines to add/remove DMA header from skb. */ |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 685 | static inline void mwl8k_remove_dma_header(struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 686 | { |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 687 | struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)skb->data; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 688 | void *dst, *src = &tr->wh; |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 689 | int hdrlen = ieee80211_hdrlen(tr->wh.frame_control); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 690 | u16 space = sizeof(struct mwl8k_dma_data) - hdrlen; |
| 691 | |
| 692 | dst = (void *)tr + space; |
| 693 | if (dst != src) { |
| 694 | memmove(dst, src, hdrlen); |
| 695 | skb_pull(skb, space); |
| 696 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 697 | } |
| 698 | |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 699 | static inline void mwl8k_add_dma_header(struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 700 | { |
| 701 | struct ieee80211_hdr *wh; |
| 702 | u32 hdrlen, pktlen; |
| 703 | struct mwl8k_dma_data *tr; |
| 704 | |
| 705 | wh = (struct ieee80211_hdr *)skb->data; |
| 706 | hdrlen = ieee80211_hdrlen(wh->frame_control); |
| 707 | pktlen = skb->len; |
| 708 | |
| 709 | /* |
| 710 | * Copy up/down the 802.11 header; the firmware requires |
| 711 | * we present a 2-byte payload length followed by a |
| 712 | * 4-address header (w/o QoS), followed (optionally) by |
| 713 | * any WEP/ExtIV header (but only filled in for CCMP). |
| 714 | */ |
| 715 | if (hdrlen != sizeof(struct mwl8k_dma_data)) |
| 716 | skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen); |
| 717 | |
| 718 | tr = (struct mwl8k_dma_data *)skb->data; |
| 719 | if (wh != &tr->wh) |
| 720 | memmove(&tr->wh, wh, hdrlen); |
| 721 | |
| 722 | /* Clear addr4 */ |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 723 | memset(tr->wh.addr4, 0, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 724 | |
| 725 | /* |
| 726 | * Firmware length is the length of the fully formed "802.11 |
| 727 | * payload". That is, everything except for the 802.11 header. |
| 728 | * This includes all crypto material including the MIC. |
| 729 | */ |
| 730 | tr->fwlen = cpu_to_le16(pktlen - hdrlen); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | |
| 734 | /* |
| 735 | * Packet reception. |
| 736 | */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 737 | #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 738 | |
| 739 | struct mwl8k_rx_desc { |
| 740 | __le16 pkt_len; |
| 741 | __u8 link_quality; |
| 742 | __u8 noise_level; |
| 743 | __le32 pkt_phys_addr; |
| 744 | __le32 next_rx_desc_phys_addr; |
| 745 | __le16 qos_control; |
| 746 | __le16 rate_info; |
| 747 | __le32 pad0[4]; |
| 748 | __u8 rssi; |
| 749 | __u8 channel; |
| 750 | __le16 pad1; |
| 751 | __u8 rx_ctrl; |
| 752 | __u8 rx_status; |
| 753 | __u8 pad2[2]; |
| 754 | } __attribute__((packed)); |
| 755 | |
| 756 | #define MWL8K_RX_DESCS 256 |
| 757 | #define MWL8K_RX_MAXSZ 3800 |
| 758 | |
| 759 | static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index) |
| 760 | { |
| 761 | struct mwl8k_priv *priv = hw->priv; |
| 762 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 763 | int size; |
| 764 | int i; |
| 765 | |
| 766 | rxq->rx_desc_count = 0; |
| 767 | rxq->rx_head = 0; |
| 768 | rxq->rx_tail = 0; |
| 769 | |
| 770 | size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc); |
| 771 | |
| 772 | rxq->rx_desc_area = |
| 773 | pci_alloc_consistent(priv->pdev, size, &rxq->rx_desc_dma); |
| 774 | if (rxq->rx_desc_area == NULL) { |
| 775 | printk(KERN_ERR "%s: failed to alloc RX descriptors\n", |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 776 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 777 | return -ENOMEM; |
| 778 | } |
| 779 | memset(rxq->rx_desc_area, 0, size); |
| 780 | |
| 781 | rxq->rx_skb = kmalloc(MWL8K_RX_DESCS * |
| 782 | sizeof(*rxq->rx_skb), GFP_KERNEL); |
| 783 | if (rxq->rx_skb == NULL) { |
| 784 | printk(KERN_ERR "%s: failed to alloc RX skbuff list\n", |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 785 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 786 | pci_free_consistent(priv->pdev, size, |
| 787 | rxq->rx_desc_area, rxq->rx_desc_dma); |
| 788 | return -ENOMEM; |
| 789 | } |
| 790 | memset(rxq->rx_skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->rx_skb)); |
| 791 | |
| 792 | for (i = 0; i < MWL8K_RX_DESCS; i++) { |
| 793 | struct mwl8k_rx_desc *rx_desc; |
| 794 | int nexti; |
| 795 | |
| 796 | rx_desc = rxq->rx_desc_area + i; |
| 797 | nexti = (i + 1) % MWL8K_RX_DESCS; |
| 798 | |
| 799 | rx_desc->next_rx_desc_phys_addr = |
| 800 | cpu_to_le32(rxq->rx_desc_dma |
| 801 | + nexti * sizeof(*rx_desc)); |
Rami Rosen | c491bf1 | 2009-04-21 16:22:01 +0300 | [diff] [blame] | 802 | rx_desc->rx_ctrl = MWL8K_RX_CTRL_OWNED_BY_HOST; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | return 0; |
| 806 | } |
| 807 | |
| 808 | static int rxq_refill(struct ieee80211_hw *hw, int index, int limit) |
| 809 | { |
| 810 | struct mwl8k_priv *priv = hw->priv; |
| 811 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 812 | int refilled; |
| 813 | |
| 814 | refilled = 0; |
| 815 | while (rxq->rx_desc_count < MWL8K_RX_DESCS && limit--) { |
| 816 | struct sk_buff *skb; |
| 817 | int rx; |
| 818 | |
| 819 | skb = dev_alloc_skb(MWL8K_RX_MAXSZ); |
| 820 | if (skb == NULL) |
| 821 | break; |
| 822 | |
| 823 | rxq->rx_desc_count++; |
| 824 | |
| 825 | rx = rxq->rx_tail; |
| 826 | rxq->rx_tail = (rx + 1) % MWL8K_RX_DESCS; |
| 827 | |
| 828 | rxq->rx_desc_area[rx].pkt_phys_addr = |
| 829 | cpu_to_le32(pci_map_single(priv->pdev, skb->data, |
| 830 | MWL8K_RX_MAXSZ, DMA_FROM_DEVICE)); |
| 831 | |
| 832 | rxq->rx_desc_area[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ); |
| 833 | rxq->rx_skb[rx] = skb; |
| 834 | wmb(); |
| 835 | rxq->rx_desc_area[rx].rx_ctrl = 0; |
| 836 | |
| 837 | refilled++; |
| 838 | } |
| 839 | |
| 840 | return refilled; |
| 841 | } |
| 842 | |
| 843 | /* Must be called only when the card's reception is completely halted */ |
| 844 | static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index) |
| 845 | { |
| 846 | struct mwl8k_priv *priv = hw->priv; |
| 847 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 848 | int i; |
| 849 | |
| 850 | for (i = 0; i < MWL8K_RX_DESCS; i++) { |
| 851 | if (rxq->rx_skb[i] != NULL) { |
| 852 | unsigned long addr; |
| 853 | |
| 854 | addr = le32_to_cpu(rxq->rx_desc_area[i].pkt_phys_addr); |
| 855 | pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ, |
| 856 | PCI_DMA_FROMDEVICE); |
| 857 | kfree_skb(rxq->rx_skb[i]); |
| 858 | rxq->rx_skb[i] = NULL; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | kfree(rxq->rx_skb); |
| 863 | rxq->rx_skb = NULL; |
| 864 | |
| 865 | pci_free_consistent(priv->pdev, |
| 866 | MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc), |
| 867 | rxq->rx_desc_area, rxq->rx_desc_dma); |
| 868 | rxq->rx_desc_area = NULL; |
| 869 | } |
| 870 | |
| 871 | |
| 872 | /* |
| 873 | * Scan a list of BSSIDs to process for finalize join. |
| 874 | * Allows for extension to process multiple BSSIDs. |
| 875 | */ |
| 876 | static inline int |
| 877 | mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh) |
| 878 | { |
| 879 | return priv->capture_beacon && |
| 880 | ieee80211_is_beacon(wh->frame_control) && |
| 881 | !compare_ether_addr(wh->addr3, priv->capture_bssid); |
| 882 | } |
| 883 | |
| 884 | static inline void mwl8k_save_beacon(struct mwl8k_priv *priv, |
| 885 | struct sk_buff *skb) |
| 886 | { |
| 887 | priv->capture_beacon = false; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 888 | memset(priv->capture_bssid, 0, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 889 | |
| 890 | /* |
| 891 | * Use GFP_ATOMIC as rxq_process is called from |
| 892 | * the primary interrupt handler, memory allocation call |
| 893 | * must not sleep. |
| 894 | */ |
| 895 | priv->beacon_skb = skb_copy(skb, GFP_ATOMIC); |
| 896 | if (priv->beacon_skb != NULL) |
| 897 | queue_work(priv->config_wq, |
| 898 | &priv->finalize_join_worker); |
| 899 | } |
| 900 | |
| 901 | static int rxq_process(struct ieee80211_hw *hw, int index, int limit) |
| 902 | { |
| 903 | struct mwl8k_priv *priv = hw->priv; |
| 904 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 905 | int processed; |
| 906 | |
| 907 | processed = 0; |
| 908 | while (rxq->rx_desc_count && limit--) { |
| 909 | struct mwl8k_rx_desc *rx_desc; |
| 910 | struct sk_buff *skb; |
| 911 | struct ieee80211_rx_status status; |
| 912 | unsigned long addr; |
| 913 | struct ieee80211_hdr *wh; |
| 914 | |
| 915 | rx_desc = rxq->rx_desc_area + rxq->rx_head; |
| 916 | if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST)) |
| 917 | break; |
| 918 | rmb(); |
| 919 | |
| 920 | skb = rxq->rx_skb[rxq->rx_head]; |
Lennert Buytenhek | d25f9f1 | 2009-08-03 21:58:26 +0200 | [diff] [blame] | 921 | if (skb == NULL) |
| 922 | break; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 923 | rxq->rx_skb[rxq->rx_head] = NULL; |
| 924 | |
| 925 | rxq->rx_head = (rxq->rx_head + 1) % MWL8K_RX_DESCS; |
| 926 | rxq->rx_desc_count--; |
| 927 | |
| 928 | addr = le32_to_cpu(rx_desc->pkt_phys_addr); |
| 929 | pci_unmap_single(priv->pdev, addr, |
| 930 | MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE); |
| 931 | |
| 932 | skb_put(skb, le16_to_cpu(rx_desc->pkt_len)); |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 933 | mwl8k_remove_dma_header(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 934 | |
| 935 | wh = (struct ieee80211_hdr *)skb->data; |
| 936 | |
| 937 | /* |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 938 | * Check for a pending join operation. Save a |
| 939 | * copy of the beacon and schedule a tasklet to |
| 940 | * send a FINALIZE_JOIN command to the firmware. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 941 | */ |
| 942 | if (mwl8k_capture_bssid(priv, wh)) |
| 943 | mwl8k_save_beacon(priv, skb); |
| 944 | |
| 945 | memset(&status, 0, sizeof(status)); |
| 946 | status.mactime = 0; |
| 947 | status.signal = -rx_desc->rssi; |
| 948 | status.noise = -rx_desc->noise_level; |
| 949 | status.qual = rx_desc->link_quality; |
| 950 | status.antenna = 1; |
| 951 | status.rate_idx = 1; |
| 952 | status.flag = 0; |
| 953 | status.band = IEEE80211_BAND_2GHZ; |
| 954 | status.freq = ieee80211_channel_to_frequency(rx_desc->channel); |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 955 | memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); |
| 956 | ieee80211_rx_irqsafe(hw, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 957 | |
| 958 | processed++; |
| 959 | } |
| 960 | |
| 961 | return processed; |
| 962 | } |
| 963 | |
| 964 | |
| 965 | /* |
| 966 | * Packet transmission. |
| 967 | */ |
| 968 | |
| 969 | /* Transmit queue assignment. */ |
| 970 | enum { |
| 971 | MWL8K_WME_AC_BK = 0, /* background access */ |
| 972 | MWL8K_WME_AC_BE = 1, /* best effort access */ |
| 973 | MWL8K_WME_AC_VI = 2, /* video access */ |
| 974 | MWL8K_WME_AC_VO = 3, /* voice access */ |
| 975 | }; |
| 976 | |
| 977 | /* Transmit packet ACK policy */ |
| 978 | #define MWL8K_TXD_ACK_POLICY_NORMAL 0 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 979 | #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3 |
| 980 | |
| 981 | #define GET_TXQ(_ac) (\ |
| 982 | ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \ |
| 983 | ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \ |
| 984 | ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \ |
| 985 | MWL8K_WME_AC_BE) |
| 986 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 987 | #define MWL8K_TXD_STATUS_OK 0x00000001 |
| 988 | #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002 |
| 989 | #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004 |
| 990 | #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 991 | #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 992 | |
| 993 | struct mwl8k_tx_desc { |
| 994 | __le32 status; |
| 995 | __u8 data_rate; |
| 996 | __u8 tx_priority; |
| 997 | __le16 qos_control; |
| 998 | __le32 pkt_phys_addr; |
| 999 | __le16 pkt_len; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1000 | __u8 dest_MAC_addr[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1001 | __le32 next_tx_desc_phys_addr; |
| 1002 | __le32 reserved; |
| 1003 | __le16 rate_info; |
| 1004 | __u8 peer_id; |
| 1005 | __u8 tx_frag_cnt; |
| 1006 | } __attribute__((packed)); |
| 1007 | |
| 1008 | #define MWL8K_TX_DESCS 128 |
| 1009 | |
| 1010 | static int mwl8k_txq_init(struct ieee80211_hw *hw, int index) |
| 1011 | { |
| 1012 | struct mwl8k_priv *priv = hw->priv; |
| 1013 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1014 | int size; |
| 1015 | int i; |
| 1016 | |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1017 | memset(&txq->tx_stats, 0, sizeof(struct ieee80211_tx_queue_stats)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1018 | txq->tx_stats.limit = MWL8K_TX_DESCS; |
| 1019 | txq->tx_head = 0; |
| 1020 | txq->tx_tail = 0; |
| 1021 | |
| 1022 | size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc); |
| 1023 | |
| 1024 | txq->tx_desc_area = |
| 1025 | pci_alloc_consistent(priv->pdev, size, &txq->tx_desc_dma); |
| 1026 | if (txq->tx_desc_area == NULL) { |
| 1027 | printk(KERN_ERR "%s: failed to alloc TX descriptors\n", |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1028 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1029 | return -ENOMEM; |
| 1030 | } |
| 1031 | memset(txq->tx_desc_area, 0, size); |
| 1032 | |
| 1033 | txq->tx_skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->tx_skb), |
| 1034 | GFP_KERNEL); |
| 1035 | if (txq->tx_skb == NULL) { |
| 1036 | printk(KERN_ERR "%s: failed to alloc TX skbuff list\n", |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1037 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1038 | pci_free_consistent(priv->pdev, size, |
| 1039 | txq->tx_desc_area, txq->tx_desc_dma); |
| 1040 | return -ENOMEM; |
| 1041 | } |
| 1042 | memset(txq->tx_skb, 0, MWL8K_TX_DESCS * sizeof(*txq->tx_skb)); |
| 1043 | |
| 1044 | for (i = 0; i < MWL8K_TX_DESCS; i++) { |
| 1045 | struct mwl8k_tx_desc *tx_desc; |
| 1046 | int nexti; |
| 1047 | |
| 1048 | tx_desc = txq->tx_desc_area + i; |
| 1049 | nexti = (i + 1) % MWL8K_TX_DESCS; |
| 1050 | |
| 1051 | tx_desc->status = 0; |
| 1052 | tx_desc->next_tx_desc_phys_addr = |
| 1053 | cpu_to_le32(txq->tx_desc_dma + |
| 1054 | nexti * sizeof(*tx_desc)); |
| 1055 | } |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | static inline void mwl8k_tx_start(struct mwl8k_priv *priv) |
| 1061 | { |
| 1062 | iowrite32(MWL8K_H2A_INT_PPA_READY, |
| 1063 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1064 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 1065 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1066 | ioread32(priv->regs + MWL8K_HIU_INT_CODE); |
| 1067 | } |
| 1068 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1069 | struct mwl8k_txq_info { |
| 1070 | u32 fw_owned; |
| 1071 | u32 drv_owned; |
| 1072 | u32 unused; |
| 1073 | u32 len; |
| 1074 | u32 head; |
| 1075 | u32 tail; |
| 1076 | }; |
| 1077 | |
| 1078 | static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv, |
Lennert Buytenhek | c3f967d | 2009-08-18 04:15:22 +0200 | [diff] [blame] | 1079 | struct mwl8k_txq_info *txinfo) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1080 | { |
| 1081 | int count, desc, status; |
| 1082 | struct mwl8k_tx_queue *txq; |
| 1083 | struct mwl8k_tx_desc *tx_desc; |
| 1084 | int ndescs = 0; |
| 1085 | |
Lennert Buytenhek | c3f967d | 2009-08-18 04:15:22 +0200 | [diff] [blame] | 1086 | memset(txinfo, 0, MWL8K_TX_QUEUES * sizeof(struct mwl8k_txq_info)); |
| 1087 | |
Lennert Buytenhek | c3f967d | 2009-08-18 04:15:22 +0200 | [diff] [blame] | 1088 | for (count = 0; count < MWL8K_TX_QUEUES; count++) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1089 | txq = priv->txq + count; |
| 1090 | txinfo[count].len = txq->tx_stats.len; |
| 1091 | txinfo[count].head = txq->tx_head; |
| 1092 | txinfo[count].tail = txq->tx_tail; |
| 1093 | for (desc = 0; desc < MWL8K_TX_DESCS; desc++) { |
| 1094 | tx_desc = txq->tx_desc_area + desc; |
| 1095 | status = le32_to_cpu(tx_desc->status); |
| 1096 | |
| 1097 | if (status & MWL8K_TXD_STATUS_FW_OWNED) |
| 1098 | txinfo[count].fw_owned++; |
| 1099 | else |
| 1100 | txinfo[count].drv_owned++; |
| 1101 | |
| 1102 | if (tx_desc->pkt_len == 0) |
| 1103 | txinfo[count].unused++; |
| 1104 | } |
| 1105 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1106 | |
| 1107 | return ndescs; |
| 1108 | } |
| 1109 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1110 | /* |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 1111 | * Must be called with priv->fw_mutex held and tx queues stopped. |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1112 | */ |
Lennert Buytenhek | 950d5b0 | 2009-07-17 01:48:41 +0200 | [diff] [blame] | 1113 | static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1114 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1115 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 1116 | DECLARE_COMPLETION_ONSTACK(tx_wait); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1117 | u32 count; |
| 1118 | unsigned long timeout; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1119 | |
| 1120 | might_sleep(); |
| 1121 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1122 | spin_lock_bh(&priv->tx_lock); |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 1123 | count = priv->pending_tx_pkts; |
| 1124 | if (count) |
| 1125 | priv->tx_wait = &tx_wait; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1126 | spin_unlock_bh(&priv->tx_lock); |
| 1127 | |
| 1128 | if (count) { |
Lennert Buytenhek | c3f967d | 2009-08-18 04:15:22 +0200 | [diff] [blame] | 1129 | struct mwl8k_txq_info txinfo[MWL8K_TX_QUEUES]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1130 | int index; |
| 1131 | int newcount; |
| 1132 | |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 1133 | timeout = wait_for_completion_timeout(&tx_wait, |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1134 | msecs_to_jiffies(5000)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1135 | if (timeout) |
| 1136 | return 0; |
| 1137 | |
| 1138 | spin_lock_bh(&priv->tx_lock); |
| 1139 | priv->tx_wait = NULL; |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 1140 | newcount = priv->pending_tx_pkts; |
| 1141 | mwl8k_scan_tx_ring(priv, txinfo); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1142 | spin_unlock_bh(&priv->tx_lock); |
| 1143 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1144 | printk(KERN_ERR "%s(%u) TIMEDOUT:5000ms Pend:%u-->%u\n", |
Lennert Buytenhek | 950d5b0 | 2009-07-17 01:48:41 +0200 | [diff] [blame] | 1145 | __func__, __LINE__, count, newcount); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1146 | |
Lennert Buytenhek | c3f967d | 2009-08-18 04:15:22 +0200 | [diff] [blame] | 1147 | for (index = 0; index < MWL8K_TX_QUEUES; index++) |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1148 | printk(KERN_ERR "TXQ:%u L:%u H:%u T:%u FW:%u " |
| 1149 | "DRV:%u U:%u\n", |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1150 | index, |
| 1151 | txinfo[index].len, |
| 1152 | txinfo[index].head, |
| 1153 | txinfo[index].tail, |
| 1154 | txinfo[index].fw_owned, |
| 1155 | txinfo[index].drv_owned, |
| 1156 | txinfo[index].unused); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1157 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1158 | return -ETIMEDOUT; |
| 1159 | } |
| 1160 | |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 1164 | #define MWL8K_TXD_SUCCESS(status) \ |
| 1165 | ((status) & (MWL8K_TXD_STATUS_OK | \ |
| 1166 | MWL8K_TXD_STATUS_OK_RETRY | \ |
| 1167 | MWL8K_TXD_STATUS_OK_MORE_RETRY)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1168 | |
| 1169 | static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force) |
| 1170 | { |
| 1171 | struct mwl8k_priv *priv = hw->priv; |
| 1172 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1173 | int wake = 0; |
| 1174 | |
| 1175 | while (txq->tx_stats.len > 0) { |
| 1176 | int tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1177 | struct mwl8k_tx_desc *tx_desc; |
| 1178 | unsigned long addr; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1179 | int size; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1180 | struct sk_buff *skb; |
| 1181 | struct ieee80211_tx_info *info; |
| 1182 | u32 status; |
| 1183 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1184 | tx = txq->tx_head; |
| 1185 | tx_desc = txq->tx_desc_area + tx; |
| 1186 | |
| 1187 | status = le32_to_cpu(tx_desc->status); |
| 1188 | |
| 1189 | if (status & MWL8K_TXD_STATUS_FW_OWNED) { |
| 1190 | if (!force) |
| 1191 | break; |
| 1192 | tx_desc->status &= |
| 1193 | ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED); |
| 1194 | } |
| 1195 | |
| 1196 | txq->tx_head = (tx + 1) % MWL8K_TX_DESCS; |
| 1197 | BUG_ON(txq->tx_stats.len == 0); |
| 1198 | txq->tx_stats.len--; |
| 1199 | priv->pending_tx_pkts--; |
| 1200 | |
| 1201 | addr = le32_to_cpu(tx_desc->pkt_phys_addr); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1202 | size = le16_to_cpu(tx_desc->pkt_len); |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 1203 | skb = txq->tx_skb[tx]; |
| 1204 | txq->tx_skb[tx] = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1205 | |
| 1206 | BUG_ON(skb == NULL); |
| 1207 | pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE); |
| 1208 | |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 1209 | mwl8k_remove_dma_header(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1210 | |
| 1211 | /* Mark descriptor as unused */ |
| 1212 | tx_desc->pkt_phys_addr = 0; |
| 1213 | tx_desc->pkt_len = 0; |
| 1214 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1215 | info = IEEE80211_SKB_CB(skb); |
| 1216 | ieee80211_tx_info_clear_status(info); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1217 | if (MWL8K_TXD_SUCCESS(status)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1218 | info->flags |= IEEE80211_TX_STAT_ACK; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1219 | |
| 1220 | ieee80211_tx_status_irqsafe(hw, skb); |
| 1221 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1222 | wake = 1; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1223 | } |
| 1224 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1225 | if (wake && priv->radio_on && !mutex_is_locked(&priv->fw_mutex)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1226 | ieee80211_wake_queue(hw, index); |
| 1227 | } |
| 1228 | |
| 1229 | /* must be called only when the card's transmit is completely halted */ |
| 1230 | static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index) |
| 1231 | { |
| 1232 | struct mwl8k_priv *priv = hw->priv; |
| 1233 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1234 | |
| 1235 | mwl8k_txq_reclaim(hw, index, 1); |
| 1236 | |
| 1237 | kfree(txq->tx_skb); |
| 1238 | txq->tx_skb = NULL; |
| 1239 | |
| 1240 | pci_free_consistent(priv->pdev, |
| 1241 | MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc), |
| 1242 | txq->tx_desc_area, txq->tx_desc_dma); |
| 1243 | txq->tx_desc_area = NULL; |
| 1244 | } |
| 1245 | |
| 1246 | static int |
| 1247 | mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb) |
| 1248 | { |
| 1249 | struct mwl8k_priv *priv = hw->priv; |
| 1250 | struct ieee80211_tx_info *tx_info; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1251 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1252 | struct ieee80211_hdr *wh; |
| 1253 | struct mwl8k_tx_queue *txq; |
| 1254 | struct mwl8k_tx_desc *tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1255 | dma_addr_t dma; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1256 | u32 txstatus; |
| 1257 | u8 txdatarate; |
| 1258 | u16 qos; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1259 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1260 | wh = (struct ieee80211_hdr *)skb->data; |
| 1261 | if (ieee80211_is_data_qos(wh->frame_control)) |
| 1262 | qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh))); |
| 1263 | else |
| 1264 | qos = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1265 | |
Lennert Buytenhek | 76266b2 | 2009-07-16 11:07:09 +0200 | [diff] [blame] | 1266 | mwl8k_add_dma_header(skb); |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1267 | wh = &((struct mwl8k_dma_data *)skb->data)->wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1268 | |
| 1269 | tx_info = IEEE80211_SKB_CB(skb); |
| 1270 | mwl8k_vif = MWL8K_VIF(tx_info->control.vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1271 | |
| 1272 | if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 1273 | u16 seqno = mwl8k_vif->seqno; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1274 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1275 | wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
| 1276 | wh->seq_ctrl |= cpu_to_le16(seqno << 4); |
| 1277 | mwl8k_vif->seqno = seqno++ % 4096; |
| 1278 | } |
| 1279 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1280 | /* Setup firmware control bit fields for each frame type. */ |
| 1281 | txstatus = 0; |
| 1282 | txdatarate = 0; |
| 1283 | if (ieee80211_is_mgmt(wh->frame_control) || |
| 1284 | ieee80211_is_ctl(wh->frame_control)) { |
| 1285 | txdatarate = 0; |
| 1286 | qos = mwl8k_qos_setbit_eosp(qos); |
| 1287 | /* Set Queue size to unspecified */ |
| 1288 | qos = mwl8k_qos_setbit_qlen(qos, 0xff); |
| 1289 | } else if (ieee80211_is_data(wh->frame_control)) { |
| 1290 | txdatarate = 1; |
| 1291 | if (is_multicast_ether_addr(wh->addr1)) |
| 1292 | txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX; |
| 1293 | |
| 1294 | /* Send pkt in an aggregate if AMPDU frame. */ |
| 1295 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) |
| 1296 | qos = mwl8k_qos_setbit_ack(qos, |
| 1297 | MWL8K_TXD_ACK_POLICY_BLOCKACK); |
| 1298 | else |
| 1299 | qos = mwl8k_qos_setbit_ack(qos, |
| 1300 | MWL8K_TXD_ACK_POLICY_NORMAL); |
| 1301 | |
| 1302 | if (qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT) |
| 1303 | qos = mwl8k_qos_setbit_amsdu(qos); |
| 1304 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1305 | |
| 1306 | dma = pci_map_single(priv->pdev, skb->data, |
| 1307 | skb->len, PCI_DMA_TODEVICE); |
| 1308 | |
| 1309 | if (pci_dma_mapping_error(priv->pdev, dma)) { |
| 1310 | printk(KERN_DEBUG "%s: failed to dma map skb, " |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1311 | "dropping TX frame.\n", wiphy_name(hw->wiphy)); |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1312 | dev_kfree_skb(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1313 | return NETDEV_TX_OK; |
| 1314 | } |
| 1315 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1316 | spin_lock_bh(&priv->tx_lock); |
| 1317 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1318 | txq = priv->txq + index; |
| 1319 | |
| 1320 | BUG_ON(txq->tx_skb[txq->tx_tail] != NULL); |
| 1321 | txq->tx_skb[txq->tx_tail] = skb; |
| 1322 | |
| 1323 | tx = txq->tx_desc_area + txq->tx_tail; |
| 1324 | tx->data_rate = txdatarate; |
| 1325 | tx->tx_priority = index; |
| 1326 | tx->qos_control = cpu_to_le16(qos); |
| 1327 | tx->pkt_phys_addr = cpu_to_le32(dma); |
| 1328 | tx->pkt_len = cpu_to_le16(skb->len); |
| 1329 | tx->rate_info = 0; |
| 1330 | tx->peer_id = mwl8k_vif->peer_id; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1331 | wmb(); |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1332 | tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus); |
| 1333 | |
| 1334 | txq->tx_stats.count++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1335 | txq->tx_stats.len++; |
| 1336 | priv->pending_tx_pkts++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1337 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1338 | txq->tx_tail++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1339 | if (txq->tx_tail == MWL8K_TX_DESCS) |
| 1340 | txq->tx_tail = 0; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1341 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1342 | if (txq->tx_head == txq->tx_tail) |
| 1343 | ieee80211_stop_queue(hw, index); |
| 1344 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1345 | mwl8k_tx_start(priv); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1346 | |
| 1347 | spin_unlock_bh(&priv->tx_lock); |
| 1348 | |
| 1349 | return NETDEV_TX_OK; |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | /* |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1354 | * Firmware access. |
| 1355 | * |
| 1356 | * We have the following requirements for issuing firmware commands: |
| 1357 | * - Some commands require that the packet transmit path is idle when |
| 1358 | * the command is issued. (For simplicity, we'll just quiesce the |
| 1359 | * transmit path for every command.) |
| 1360 | * - There are certain sequences of commands that need to be issued to |
| 1361 | * the hardware sequentially, with no other intervening commands. |
| 1362 | * |
| 1363 | * This leads to an implementation of a "firmware lock" as a mutex that |
| 1364 | * can be taken recursively, and which is taken by both the low-level |
| 1365 | * command submission function (mwl8k_post_cmd) as well as any users of |
| 1366 | * that function that require issuing of an atomic sequence of commands, |
| 1367 | * and quiesces the transmit path whenever it's taken. |
| 1368 | */ |
| 1369 | static int mwl8k_fw_lock(struct ieee80211_hw *hw) |
| 1370 | { |
| 1371 | struct mwl8k_priv *priv = hw->priv; |
| 1372 | |
| 1373 | if (priv->fw_mutex_owner != current) { |
| 1374 | int rc; |
| 1375 | |
| 1376 | mutex_lock(&priv->fw_mutex); |
| 1377 | ieee80211_stop_queues(hw); |
| 1378 | |
| 1379 | rc = mwl8k_tx_wait_empty(hw); |
| 1380 | if (rc) { |
| 1381 | ieee80211_wake_queues(hw); |
| 1382 | mutex_unlock(&priv->fw_mutex); |
| 1383 | |
| 1384 | return rc; |
| 1385 | } |
| 1386 | |
| 1387 | priv->fw_mutex_owner = current; |
| 1388 | } |
| 1389 | |
| 1390 | priv->fw_mutex_depth++; |
| 1391 | |
| 1392 | return 0; |
| 1393 | } |
| 1394 | |
| 1395 | static void mwl8k_fw_unlock(struct ieee80211_hw *hw) |
| 1396 | { |
| 1397 | struct mwl8k_priv *priv = hw->priv; |
| 1398 | |
| 1399 | if (!--priv->fw_mutex_depth) { |
| 1400 | ieee80211_wake_queues(hw); |
| 1401 | priv->fw_mutex_owner = NULL; |
| 1402 | mutex_unlock(&priv->fw_mutex); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | |
| 1407 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1408 | * Command processing. |
| 1409 | */ |
| 1410 | |
| 1411 | /* Timeout firmware commands after 2000ms */ |
| 1412 | #define MWL8K_CMD_TIMEOUT_MS 2000 |
| 1413 | |
| 1414 | static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd) |
| 1415 | { |
| 1416 | DECLARE_COMPLETION_ONSTACK(cmd_wait); |
| 1417 | struct mwl8k_priv *priv = hw->priv; |
| 1418 | void __iomem *regs = priv->regs; |
| 1419 | dma_addr_t dma_addr; |
| 1420 | unsigned int dma_size; |
| 1421 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1422 | unsigned long timeout = 0; |
| 1423 | u8 buf[32]; |
| 1424 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1425 | cmd->result = 0xffff; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1426 | dma_size = le16_to_cpu(cmd->length); |
| 1427 | dma_addr = pci_map_single(priv->pdev, cmd, dma_size, |
| 1428 | PCI_DMA_BIDIRECTIONAL); |
| 1429 | if (pci_dma_mapping_error(priv->pdev, dma_addr)) |
| 1430 | return -ENOMEM; |
| 1431 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1432 | rc = mwl8k_fw_lock(hw); |
Lennert Buytenhek | 39a1e42 | 2009-08-24 15:42:46 +0200 | [diff] [blame] | 1433 | if (rc) { |
| 1434 | pci_unmap_single(priv->pdev, dma_addr, dma_size, |
| 1435 | PCI_DMA_BIDIRECTIONAL); |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1436 | return rc; |
Lennert Buytenhek | 39a1e42 | 2009-08-24 15:42:46 +0200 | [diff] [blame] | 1437 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1438 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1439 | priv->hostcmd_wait = &cmd_wait; |
| 1440 | iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR); |
| 1441 | iowrite32(MWL8K_H2A_INT_DOORBELL, |
| 1442 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1443 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 1444 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1445 | |
| 1446 | timeout = wait_for_completion_timeout(&cmd_wait, |
| 1447 | msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS)); |
| 1448 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1449 | priv->hostcmd_wait = NULL; |
| 1450 | |
| 1451 | mwl8k_fw_unlock(hw); |
| 1452 | |
Lennert Buytenhek | 37055bd | 2009-08-03 21:58:47 +0200 | [diff] [blame] | 1453 | pci_unmap_single(priv->pdev, dma_addr, dma_size, |
| 1454 | PCI_DMA_BIDIRECTIONAL); |
| 1455 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1456 | if (!timeout) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1457 | printk(KERN_ERR "%s: Command %s timeout after %u ms\n", |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1458 | wiphy_name(hw->wiphy), |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1459 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), |
| 1460 | MWL8K_CMD_TIMEOUT_MS); |
| 1461 | rc = -ETIMEDOUT; |
| 1462 | } else { |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1463 | rc = cmd->result ? -EINVAL : 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1464 | if (rc) |
| 1465 | printk(KERN_ERR "%s: Command %s error 0x%x\n", |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1466 | wiphy_name(hw->wiphy), |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1467 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), |
Lennert Buytenhek | 76c962a | 2009-08-24 15:42:56 +0200 | [diff] [blame] | 1468 | le16_to_cpu(cmd->result)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1469 | } |
| 1470 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1471 | return rc; |
| 1472 | } |
| 1473 | |
| 1474 | /* |
| 1475 | * GET_HW_SPEC. |
| 1476 | */ |
| 1477 | struct mwl8k_cmd_get_hw_spec { |
| 1478 | struct mwl8k_cmd_pkt header; |
| 1479 | __u8 hw_rev; |
| 1480 | __u8 host_interface; |
| 1481 | __le16 num_mcaddrs; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1482 | __u8 perm_addr[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1483 | __le16 region_code; |
| 1484 | __le32 fw_rev; |
| 1485 | __le32 ps_cookie; |
| 1486 | __le32 caps; |
| 1487 | __u8 mcs_bitmap[16]; |
| 1488 | __le32 rx_queue_ptr; |
| 1489 | __le32 num_tx_queues; |
| 1490 | __le32 tx_queue_ptrs[MWL8K_TX_QUEUES]; |
| 1491 | __le32 caps2; |
| 1492 | __le32 num_tx_desc_per_queue; |
| 1493 | __le32 total_rx_desc; |
| 1494 | } __attribute__((packed)); |
| 1495 | |
| 1496 | static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw) |
| 1497 | { |
| 1498 | struct mwl8k_priv *priv = hw->priv; |
| 1499 | struct mwl8k_cmd_get_hw_spec *cmd; |
| 1500 | int rc; |
| 1501 | int i; |
| 1502 | |
| 1503 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1504 | if (cmd == NULL) |
| 1505 | return -ENOMEM; |
| 1506 | |
| 1507 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC); |
| 1508 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1509 | |
| 1510 | memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr)); |
| 1511 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
| 1512 | cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rx_desc_dma); |
Lennert Buytenhek | 4ff6432 | 2009-08-03 21:58:39 +0200 | [diff] [blame] | 1513 | cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1514 | for (i = 0; i < MWL8K_TX_QUEUES; i++) |
| 1515 | cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].tx_desc_dma); |
Lennert Buytenhek | 4ff6432 | 2009-08-03 21:58:39 +0200 | [diff] [blame] | 1516 | cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); |
| 1517 | cmd->total_rx_desc = cpu_to_le32(MWL8K_RX_DESCS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1518 | |
| 1519 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1520 | |
| 1521 | if (!rc) { |
| 1522 | SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr); |
| 1523 | priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); |
Lennert Buytenhek | 4ff6432 | 2009-08-03 21:58:39 +0200 | [diff] [blame] | 1524 | priv->fw_rev = le32_to_cpu(cmd->fw_rev); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1525 | priv->hw_rev = cmd->hw_rev; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | kfree(cmd); |
| 1529 | return rc; |
| 1530 | } |
| 1531 | |
| 1532 | /* |
| 1533 | * CMD_MAC_MULTICAST_ADR. |
| 1534 | */ |
| 1535 | struct mwl8k_cmd_mac_multicast_adr { |
| 1536 | struct mwl8k_cmd_pkt header; |
| 1537 | __le16 action; |
| 1538 | __le16 numaddr; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1539 | __u8 addr[0][ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1540 | }; |
| 1541 | |
| 1542 | #define MWL8K_ENABLE_RX_MULTICAST 0x000F |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1543 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1544 | static struct mwl8k_cmd_pkt * |
| 1545 | __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, |
| 1546 | int mc_count, struct dev_addr_list *mclist) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1547 | { |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1548 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1549 | struct mwl8k_cmd_mac_multicast_adr *cmd; |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1550 | int size; |
| 1551 | int i; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1552 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1553 | if (mc_count > priv->num_mcaddrs) |
| 1554 | mc_count = priv->num_mcaddrs; |
| 1555 | |
| 1556 | size = sizeof(*cmd) + mc_count * ETH_ALEN; |
| 1557 | |
| 1558 | cmd = kzalloc(size, GFP_ATOMIC); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1559 | if (cmd == NULL) |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1560 | return NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1561 | |
| 1562 | cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR); |
| 1563 | cmd->header.length = cpu_to_le16(size); |
| 1564 | cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST); |
| 1565 | cmd->numaddr = cpu_to_le16(mc_count); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1566 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1567 | for (i = 0; i < mc_count && mclist; i++) { |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1568 | if (mclist->da_addrlen != ETH_ALEN) { |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1569 | kfree(cmd); |
| 1570 | return NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1571 | } |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1572 | memcpy(cmd->addr[i], mclist->da_addr, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1573 | mclist = mclist->next; |
| 1574 | } |
| 1575 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 1576 | return &cmd->header; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | /* |
| 1580 | * CMD_802_11_GET_STAT. |
| 1581 | */ |
| 1582 | struct mwl8k_cmd_802_11_get_stat { |
| 1583 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1584 | __le32 stats[64]; |
| 1585 | } __attribute__((packed)); |
| 1586 | |
| 1587 | #define MWL8K_STAT_ACK_FAILURE 9 |
| 1588 | #define MWL8K_STAT_RTS_FAILURE 12 |
| 1589 | #define MWL8K_STAT_FCS_ERROR 24 |
| 1590 | #define MWL8K_STAT_RTS_SUCCESS 11 |
| 1591 | |
| 1592 | static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw, |
| 1593 | struct ieee80211_low_level_stats *stats) |
| 1594 | { |
| 1595 | struct mwl8k_cmd_802_11_get_stat *cmd; |
| 1596 | int rc; |
| 1597 | |
| 1598 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1599 | if (cmd == NULL) |
| 1600 | return -ENOMEM; |
| 1601 | |
| 1602 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT); |
| 1603 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1604 | |
| 1605 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1606 | if (!rc) { |
| 1607 | stats->dot11ACKFailureCount = |
| 1608 | le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]); |
| 1609 | stats->dot11RTSFailureCount = |
| 1610 | le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]); |
| 1611 | stats->dot11FCSErrorCount = |
| 1612 | le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]); |
| 1613 | stats->dot11RTSSuccessCount = |
| 1614 | le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]); |
| 1615 | } |
| 1616 | kfree(cmd); |
| 1617 | |
| 1618 | return rc; |
| 1619 | } |
| 1620 | |
| 1621 | /* |
| 1622 | * CMD_802_11_RADIO_CONTROL. |
| 1623 | */ |
| 1624 | struct mwl8k_cmd_802_11_radio_control { |
| 1625 | struct mwl8k_cmd_pkt header; |
| 1626 | __le16 action; |
| 1627 | __le16 control; |
| 1628 | __le16 radio_on; |
| 1629 | } __attribute__((packed)); |
| 1630 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 1631 | static int |
| 1632 | mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, bool enable, bool force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1633 | { |
| 1634 | struct mwl8k_priv *priv = hw->priv; |
| 1635 | struct mwl8k_cmd_802_11_radio_control *cmd; |
| 1636 | int rc; |
| 1637 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 1638 | if (enable == priv->radio_on && !force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1639 | return 0; |
| 1640 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1641 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1642 | if (cmd == NULL) |
| 1643 | return -ENOMEM; |
| 1644 | |
| 1645 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL); |
| 1646 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1647 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 1648 | cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1649 | cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000); |
| 1650 | |
| 1651 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1652 | kfree(cmd); |
| 1653 | |
| 1654 | if (!rc) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 1655 | priv->radio_on = enable; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1656 | |
| 1657 | return rc; |
| 1658 | } |
| 1659 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 1660 | static int mwl8k_cmd_802_11_radio_disable(struct ieee80211_hw *hw) |
| 1661 | { |
| 1662 | return mwl8k_cmd_802_11_radio_control(hw, 0, 0); |
| 1663 | } |
| 1664 | |
| 1665 | static int mwl8k_cmd_802_11_radio_enable(struct ieee80211_hw *hw) |
| 1666 | { |
| 1667 | return mwl8k_cmd_802_11_radio_control(hw, 1, 0); |
| 1668 | } |
| 1669 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1670 | static int |
| 1671 | mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble) |
| 1672 | { |
| 1673 | struct mwl8k_priv *priv; |
| 1674 | |
| 1675 | if (hw == NULL || hw->priv == NULL) |
| 1676 | return -EINVAL; |
| 1677 | priv = hw->priv; |
| 1678 | |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 1679 | priv->radio_short_preamble = short_preamble; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1680 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 1681 | return mwl8k_cmd_802_11_radio_control(hw, 1, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | /* |
| 1685 | * CMD_802_11_RF_TX_POWER. |
| 1686 | */ |
| 1687 | #define MWL8K_TX_POWER_LEVEL_TOTAL 8 |
| 1688 | |
| 1689 | struct mwl8k_cmd_802_11_rf_tx_power { |
| 1690 | struct mwl8k_cmd_pkt header; |
| 1691 | __le16 action; |
| 1692 | __le16 support_level; |
| 1693 | __le16 current_level; |
| 1694 | __le16 reserved; |
| 1695 | __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL]; |
| 1696 | } __attribute__((packed)); |
| 1697 | |
| 1698 | static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm) |
| 1699 | { |
| 1700 | struct mwl8k_cmd_802_11_rf_tx_power *cmd; |
| 1701 | int rc; |
| 1702 | |
| 1703 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1704 | if (cmd == NULL) |
| 1705 | return -ENOMEM; |
| 1706 | |
| 1707 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER); |
| 1708 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1709 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 1710 | cmd->support_level = cpu_to_le16(dBm); |
| 1711 | |
| 1712 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1713 | kfree(cmd); |
| 1714 | |
| 1715 | return rc; |
| 1716 | } |
| 1717 | |
| 1718 | /* |
| 1719 | * CMD_SET_PRE_SCAN. |
| 1720 | */ |
| 1721 | struct mwl8k_cmd_set_pre_scan { |
| 1722 | struct mwl8k_cmd_pkt header; |
| 1723 | } __attribute__((packed)); |
| 1724 | |
| 1725 | static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw) |
| 1726 | { |
| 1727 | struct mwl8k_cmd_set_pre_scan *cmd; |
| 1728 | int rc; |
| 1729 | |
| 1730 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1731 | if (cmd == NULL) |
| 1732 | return -ENOMEM; |
| 1733 | |
| 1734 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN); |
| 1735 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1736 | |
| 1737 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1738 | kfree(cmd); |
| 1739 | |
| 1740 | return rc; |
| 1741 | } |
| 1742 | |
| 1743 | /* |
| 1744 | * CMD_SET_POST_SCAN. |
| 1745 | */ |
| 1746 | struct mwl8k_cmd_set_post_scan { |
| 1747 | struct mwl8k_cmd_pkt header; |
| 1748 | __le32 isibss; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1749 | __u8 bssid[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1750 | } __attribute__((packed)); |
| 1751 | |
| 1752 | static int |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1753 | mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 *mac) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1754 | { |
| 1755 | struct mwl8k_cmd_set_post_scan *cmd; |
| 1756 | int rc; |
| 1757 | |
| 1758 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1759 | if (cmd == NULL) |
| 1760 | return -ENOMEM; |
| 1761 | |
| 1762 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN); |
| 1763 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1764 | cmd->isibss = 0; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1765 | memcpy(cmd->bssid, mac, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1766 | |
| 1767 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1768 | kfree(cmd); |
| 1769 | |
| 1770 | return rc; |
| 1771 | } |
| 1772 | |
| 1773 | /* |
| 1774 | * CMD_SET_RF_CHANNEL. |
| 1775 | */ |
| 1776 | struct mwl8k_cmd_set_rf_channel { |
| 1777 | struct mwl8k_cmd_pkt header; |
| 1778 | __le16 action; |
| 1779 | __u8 current_channel; |
| 1780 | __le32 channel_flags; |
| 1781 | } __attribute__((packed)); |
| 1782 | |
| 1783 | static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw, |
| 1784 | struct ieee80211_channel *channel) |
| 1785 | { |
| 1786 | struct mwl8k_cmd_set_rf_channel *cmd; |
| 1787 | int rc; |
| 1788 | |
| 1789 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1790 | if (cmd == NULL) |
| 1791 | return -ENOMEM; |
| 1792 | |
| 1793 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL); |
| 1794 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1795 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 1796 | cmd->current_channel = channel->hw_value; |
| 1797 | if (channel->band == IEEE80211_BAND_2GHZ) |
| 1798 | cmd->channel_flags = cpu_to_le32(0x00000081); |
| 1799 | else |
| 1800 | cmd->channel_flags = cpu_to_le32(0x00000000); |
| 1801 | |
| 1802 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1803 | kfree(cmd); |
| 1804 | |
| 1805 | return rc; |
| 1806 | } |
| 1807 | |
| 1808 | /* |
| 1809 | * CMD_SET_SLOT. |
| 1810 | */ |
| 1811 | struct mwl8k_cmd_set_slot { |
| 1812 | struct mwl8k_cmd_pkt header; |
| 1813 | __le16 action; |
| 1814 | __u8 short_slot; |
| 1815 | } __attribute__((packed)); |
| 1816 | |
Lennert Buytenhek | 5539bb5 | 2009-07-16 16:06:53 +0200 | [diff] [blame] | 1817 | 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] | 1818 | { |
| 1819 | struct mwl8k_cmd_set_slot *cmd; |
| 1820 | int rc; |
| 1821 | |
| 1822 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1823 | if (cmd == NULL) |
| 1824 | return -ENOMEM; |
| 1825 | |
| 1826 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT); |
| 1827 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1828 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
Lennert Buytenhek | 5539bb5 | 2009-07-16 16:06:53 +0200 | [diff] [blame] | 1829 | cmd->short_slot = short_slot_time; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1830 | |
| 1831 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1832 | kfree(cmd); |
| 1833 | |
| 1834 | return rc; |
| 1835 | } |
| 1836 | |
| 1837 | /* |
| 1838 | * CMD_MIMO_CONFIG. |
| 1839 | */ |
| 1840 | struct mwl8k_cmd_mimo_config { |
| 1841 | struct mwl8k_cmd_pkt header; |
| 1842 | __le32 action; |
| 1843 | __u8 rx_antenna_map; |
| 1844 | __u8 tx_antenna_map; |
| 1845 | } __attribute__((packed)); |
| 1846 | |
| 1847 | static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx) |
| 1848 | { |
| 1849 | struct mwl8k_cmd_mimo_config *cmd; |
| 1850 | int rc; |
| 1851 | |
| 1852 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1853 | if (cmd == NULL) |
| 1854 | return -ENOMEM; |
| 1855 | |
| 1856 | cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG); |
| 1857 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1858 | cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET); |
| 1859 | cmd->rx_antenna_map = rx; |
| 1860 | cmd->tx_antenna_map = tx; |
| 1861 | |
| 1862 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1863 | kfree(cmd); |
| 1864 | |
| 1865 | return rc; |
| 1866 | } |
| 1867 | |
| 1868 | /* |
| 1869 | * CMD_ENABLE_SNIFFER. |
| 1870 | */ |
| 1871 | struct mwl8k_cmd_enable_sniffer { |
| 1872 | struct mwl8k_cmd_pkt header; |
| 1873 | __le32 action; |
| 1874 | } __attribute__((packed)); |
| 1875 | |
| 1876 | static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable) |
| 1877 | { |
| 1878 | struct mwl8k_cmd_enable_sniffer *cmd; |
| 1879 | int rc; |
| 1880 | |
| 1881 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1882 | if (cmd == NULL) |
| 1883 | return -ENOMEM; |
| 1884 | |
| 1885 | cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER); |
| 1886 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1887 | cmd->action = cpu_to_le32(!!enable); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1888 | |
| 1889 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1890 | kfree(cmd); |
| 1891 | |
| 1892 | return rc; |
| 1893 | } |
| 1894 | |
| 1895 | /* |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1896 | * CMD_SET_RATEADAPT_MODE. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1897 | */ |
| 1898 | struct mwl8k_cmd_set_rate_adapt_mode { |
| 1899 | struct mwl8k_cmd_pkt header; |
| 1900 | __le16 action; |
| 1901 | __le16 mode; |
| 1902 | } __attribute__((packed)); |
| 1903 | |
| 1904 | static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode) |
| 1905 | { |
| 1906 | struct mwl8k_cmd_set_rate_adapt_mode *cmd; |
| 1907 | int rc; |
| 1908 | |
| 1909 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1910 | if (cmd == NULL) |
| 1911 | return -ENOMEM; |
| 1912 | |
| 1913 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE); |
| 1914 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1915 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 1916 | cmd->mode = cpu_to_le16(mode); |
| 1917 | |
| 1918 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1919 | kfree(cmd); |
| 1920 | |
| 1921 | return rc; |
| 1922 | } |
| 1923 | |
| 1924 | /* |
| 1925 | * CMD_SET_WMM_MODE. |
| 1926 | */ |
| 1927 | struct mwl8k_cmd_set_wmm { |
| 1928 | struct mwl8k_cmd_pkt header; |
| 1929 | __le16 action; |
| 1930 | } __attribute__((packed)); |
| 1931 | |
| 1932 | static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable) |
| 1933 | { |
| 1934 | struct mwl8k_priv *priv = hw->priv; |
| 1935 | struct mwl8k_cmd_set_wmm *cmd; |
| 1936 | int rc; |
| 1937 | |
| 1938 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1939 | if (cmd == NULL) |
| 1940 | return -ENOMEM; |
| 1941 | |
| 1942 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE); |
| 1943 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 0439b1f | 2009-07-16 12:34:02 +0200 | [diff] [blame] | 1944 | cmd->action = cpu_to_le16(!!enable); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1945 | |
| 1946 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1947 | kfree(cmd); |
| 1948 | |
| 1949 | if (!rc) |
Lennert Buytenhek | 0439b1f | 2009-07-16 12:34:02 +0200 | [diff] [blame] | 1950 | priv->wmm_enabled = enable; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1951 | |
| 1952 | return rc; |
| 1953 | } |
| 1954 | |
| 1955 | /* |
| 1956 | * CMD_SET_RTS_THRESHOLD. |
| 1957 | */ |
| 1958 | struct mwl8k_cmd_rts_threshold { |
| 1959 | struct mwl8k_cmd_pkt header; |
| 1960 | __le16 action; |
| 1961 | __le16 threshold; |
| 1962 | } __attribute__((packed)); |
| 1963 | |
| 1964 | static int mwl8k_rts_threshold(struct ieee80211_hw *hw, |
Lennert Buytenhek | 733d306 | 2009-07-17 07:24:15 +0200 | [diff] [blame] | 1965 | u16 action, u16 threshold) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1966 | { |
| 1967 | struct mwl8k_cmd_rts_threshold *cmd; |
| 1968 | int rc; |
| 1969 | |
| 1970 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1971 | if (cmd == NULL) |
| 1972 | return -ENOMEM; |
| 1973 | |
| 1974 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD); |
| 1975 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 1976 | cmd->action = cpu_to_le16(action); |
Lennert Buytenhek | 733d306 | 2009-07-17 07:24:15 +0200 | [diff] [blame] | 1977 | cmd->threshold = cpu_to_le16(threshold); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1978 | |
| 1979 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 1980 | kfree(cmd); |
| 1981 | |
| 1982 | return rc; |
| 1983 | } |
| 1984 | |
| 1985 | /* |
| 1986 | * CMD_SET_EDCA_PARAMS. |
| 1987 | */ |
| 1988 | struct mwl8k_cmd_set_edca_params { |
| 1989 | struct mwl8k_cmd_pkt header; |
| 1990 | |
| 1991 | /* See MWL8K_SET_EDCA_XXX below */ |
| 1992 | __le16 action; |
| 1993 | |
| 1994 | /* TX opportunity in units of 32 us */ |
| 1995 | __le16 txop; |
| 1996 | |
| 1997 | /* Log exponent of max contention period: 0...15*/ |
| 1998 | __u8 log_cw_max; |
| 1999 | |
| 2000 | /* Log exponent of min contention period: 0...15 */ |
| 2001 | __u8 log_cw_min; |
| 2002 | |
| 2003 | /* Adaptive interframe spacing in units of 32us */ |
| 2004 | __u8 aifs; |
| 2005 | |
| 2006 | /* TX queue to configure */ |
| 2007 | __u8 txq; |
| 2008 | } __attribute__((packed)); |
| 2009 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2010 | #define MWL8K_SET_EDCA_CW 0x01 |
| 2011 | #define MWL8K_SET_EDCA_TXOP 0x02 |
| 2012 | #define MWL8K_SET_EDCA_AIFS 0x04 |
| 2013 | |
| 2014 | #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \ |
| 2015 | MWL8K_SET_EDCA_TXOP | \ |
| 2016 | MWL8K_SET_EDCA_AIFS) |
| 2017 | |
| 2018 | static int |
| 2019 | mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum, |
| 2020 | __u16 cw_min, __u16 cw_max, |
| 2021 | __u8 aifs, __u16 txop) |
| 2022 | { |
| 2023 | struct mwl8k_cmd_set_edca_params *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2024 | int rc; |
| 2025 | |
| 2026 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2027 | if (cmd == NULL) |
| 2028 | return -ENOMEM; |
| 2029 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2030 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS); |
| 2031 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2032 | cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL); |
| 2033 | cmd->txop = cpu_to_le16(txop); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2034 | cmd->log_cw_max = (u8)ilog2(cw_max + 1); |
| 2035 | cmd->log_cw_min = (u8)ilog2(cw_min + 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2036 | cmd->aifs = aifs; |
| 2037 | cmd->txq = qnum; |
| 2038 | |
| 2039 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2040 | kfree(cmd); |
| 2041 | |
| 2042 | return rc; |
| 2043 | } |
| 2044 | |
| 2045 | /* |
| 2046 | * CMD_FINALIZE_JOIN. |
| 2047 | */ |
| 2048 | |
| 2049 | /* FJ beacon buffer size is compiled into the firmware. */ |
| 2050 | #define MWL8K_FJ_BEACON_MAXLEN 128 |
| 2051 | |
| 2052 | struct mwl8k_cmd_finalize_join { |
| 2053 | struct mwl8k_cmd_pkt header; |
| 2054 | __le32 sleep_interval; /* Number of beacon periods to sleep */ |
| 2055 | __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN]; |
| 2056 | } __attribute__((packed)); |
| 2057 | |
| 2058 | static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame, |
| 2059 | __u16 framelen, __u16 dtim) |
| 2060 | { |
| 2061 | struct mwl8k_cmd_finalize_join *cmd; |
| 2062 | struct ieee80211_mgmt *payload = frame; |
| 2063 | u16 hdrlen; |
| 2064 | u32 payload_len; |
| 2065 | int rc; |
| 2066 | |
| 2067 | if (frame == NULL) |
| 2068 | return -EINVAL; |
| 2069 | |
| 2070 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2071 | if (cmd == NULL) |
| 2072 | return -ENOMEM; |
| 2073 | |
| 2074 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN); |
| 2075 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2076 | cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2077 | |
| 2078 | hdrlen = ieee80211_hdrlen(payload->frame_control); |
| 2079 | |
| 2080 | payload_len = framelen > hdrlen ? framelen - hdrlen : 0; |
| 2081 | |
| 2082 | /* XXX TBD Might just have to abort and return an error */ |
| 2083 | if (payload_len > MWL8K_FJ_BEACON_MAXLEN) |
| 2084 | printk(KERN_ERR "%s(): WARNING: Incomplete beacon " |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2085 | "sent to firmware. Sz=%u MAX=%u\n", __func__, |
| 2086 | payload_len, MWL8K_FJ_BEACON_MAXLEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2087 | |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2088 | if (payload_len > MWL8K_FJ_BEACON_MAXLEN) |
| 2089 | payload_len = MWL8K_FJ_BEACON_MAXLEN; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2090 | |
| 2091 | if (payload && payload_len) |
| 2092 | memcpy(cmd->beacon_data, &payload->u.beacon, payload_len); |
| 2093 | |
| 2094 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2095 | kfree(cmd); |
| 2096 | return rc; |
| 2097 | } |
| 2098 | |
| 2099 | /* |
| 2100 | * CMD_UPDATE_STADB. |
| 2101 | */ |
| 2102 | struct mwl8k_cmd_update_sta_db { |
| 2103 | struct mwl8k_cmd_pkt header; |
| 2104 | |
| 2105 | /* See STADB_ACTION_TYPE */ |
| 2106 | __le32 action; |
| 2107 | |
| 2108 | /* Peer MAC address */ |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2109 | __u8 peer_addr[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2110 | |
| 2111 | __le32 reserved; |
| 2112 | |
| 2113 | /* Peer info - valid during add/update. */ |
| 2114 | struct peer_capability_info peer_info; |
| 2115 | } __attribute__((packed)); |
| 2116 | |
| 2117 | static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw, |
| 2118 | struct ieee80211_vif *vif, __u32 action) |
| 2119 | { |
| 2120 | struct mwl8k_vif *mv_vif = MWL8K_VIF(vif); |
| 2121 | struct ieee80211_bss_conf *info = &mv_vif->bss_info; |
| 2122 | struct mwl8k_cmd_update_sta_db *cmd; |
| 2123 | struct peer_capability_info *peer_info; |
| 2124 | struct ieee80211_rate *bitrates = mv_vif->legacy_rates; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2125 | int rc; |
| 2126 | __u8 count, *rates; |
| 2127 | |
| 2128 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2129 | if (cmd == NULL) |
| 2130 | return -ENOMEM; |
| 2131 | |
| 2132 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB); |
| 2133 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2134 | |
| 2135 | cmd->action = cpu_to_le32(action); |
| 2136 | peer_info = &cmd->peer_info; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2137 | memcpy(cmd->peer_addr, mv_vif->bssid, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2138 | |
| 2139 | switch (action) { |
| 2140 | case MWL8K_STA_DB_ADD_ENTRY: |
| 2141 | case MWL8K_STA_DB_MODIFY_ENTRY: |
| 2142 | /* Build peer_info block */ |
| 2143 | peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT; |
| 2144 | peer_info->basic_caps = cpu_to_le16(info->assoc_capability); |
| 2145 | peer_info->interop = 1; |
| 2146 | peer_info->amsdu_enabled = 0; |
| 2147 | |
| 2148 | rates = peer_info->legacy_rates; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2149 | for (count = 0; count < mv_vif->legacy_nrates; count++) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2150 | rates[count] = bitrates[count].hw_value; |
| 2151 | |
| 2152 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2153 | if (rc == 0) |
| 2154 | mv_vif->peer_id = peer_info->station_id; |
| 2155 | |
| 2156 | break; |
| 2157 | |
| 2158 | case MWL8K_STA_DB_DEL_ENTRY: |
| 2159 | case MWL8K_STA_DB_FLUSH: |
| 2160 | default: |
| 2161 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2162 | if (rc == 0) |
| 2163 | mv_vif->peer_id = 0; |
| 2164 | break; |
| 2165 | } |
| 2166 | kfree(cmd); |
| 2167 | |
| 2168 | return rc; |
| 2169 | } |
| 2170 | |
| 2171 | /* |
| 2172 | * CMD_SET_AID. |
| 2173 | */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2174 | #define MWL8K_RATE_INDEX_MAX_ARRAY 14 |
| 2175 | |
| 2176 | #define MWL8K_FRAME_PROT_DISABLED 0x00 |
| 2177 | #define MWL8K_FRAME_PROT_11G 0x07 |
| 2178 | #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02 |
| 2179 | #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2180 | |
| 2181 | struct mwl8k_cmd_update_set_aid { |
| 2182 | struct mwl8k_cmd_pkt header; |
| 2183 | __le16 aid; |
| 2184 | |
| 2185 | /* AP's MAC address (BSSID) */ |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2186 | __u8 bssid[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2187 | __le16 protection_mode; |
| 2188 | __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY]; |
| 2189 | } __attribute__((packed)); |
| 2190 | |
| 2191 | static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw, |
| 2192 | struct ieee80211_vif *vif) |
| 2193 | { |
| 2194 | struct mwl8k_vif *mv_vif = MWL8K_VIF(vif); |
| 2195 | struct ieee80211_bss_conf *info = &mv_vif->bss_info; |
| 2196 | struct mwl8k_cmd_update_set_aid *cmd; |
| 2197 | struct ieee80211_rate *bitrates = mv_vif->legacy_rates; |
| 2198 | int count; |
| 2199 | u16 prot_mode; |
| 2200 | int rc; |
| 2201 | |
| 2202 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2203 | if (cmd == NULL) |
| 2204 | return -ENOMEM; |
| 2205 | |
| 2206 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID); |
| 2207 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2208 | cmd->aid = cpu_to_le16(info->aid); |
| 2209 | |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2210 | memcpy(cmd->bssid, mv_vif->bssid, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2211 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2212 | if (info->use_cts_prot) { |
| 2213 | prot_mode = MWL8K_FRAME_PROT_11G; |
| 2214 | } else { |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 2215 | switch (info->ht_operation_mode & |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2216 | IEEE80211_HT_OP_MODE_PROTECTION) { |
| 2217 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 2218 | prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY; |
| 2219 | break; |
| 2220 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 2221 | prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL; |
| 2222 | break; |
| 2223 | default: |
| 2224 | prot_mode = MWL8K_FRAME_PROT_DISABLED; |
| 2225 | break; |
| 2226 | } |
| 2227 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2228 | cmd->protection_mode = cpu_to_le16(prot_mode); |
| 2229 | |
| 2230 | for (count = 0; count < mv_vif->legacy_nrates; count++) |
| 2231 | cmd->supp_rates[count] = bitrates[count].hw_value; |
| 2232 | |
| 2233 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2234 | kfree(cmd); |
| 2235 | |
| 2236 | return rc; |
| 2237 | } |
| 2238 | |
| 2239 | /* |
| 2240 | * CMD_SET_RATE. |
| 2241 | */ |
| 2242 | struct mwl8k_cmd_update_rateset { |
| 2243 | struct mwl8k_cmd_pkt header; |
| 2244 | __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY]; |
| 2245 | |
| 2246 | /* Bitmap for supported MCS codes. */ |
| 2247 | __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES]; |
| 2248 | __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES]; |
| 2249 | } __attribute__((packed)); |
| 2250 | |
| 2251 | static int mwl8k_update_rateset(struct ieee80211_hw *hw, |
| 2252 | struct ieee80211_vif *vif) |
| 2253 | { |
| 2254 | struct mwl8k_vif *mv_vif = MWL8K_VIF(vif); |
| 2255 | struct mwl8k_cmd_update_rateset *cmd; |
| 2256 | struct ieee80211_rate *bitrates = mv_vif->legacy_rates; |
| 2257 | int count; |
| 2258 | int rc; |
| 2259 | |
| 2260 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2261 | if (cmd == NULL) |
| 2262 | return -ENOMEM; |
| 2263 | |
| 2264 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE); |
| 2265 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2266 | |
| 2267 | for (count = 0; count < mv_vif->legacy_nrates; count++) |
| 2268 | cmd->legacy_rates[count] = bitrates[count].hw_value; |
| 2269 | |
| 2270 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2271 | kfree(cmd); |
| 2272 | |
| 2273 | return rc; |
| 2274 | } |
| 2275 | |
| 2276 | /* |
| 2277 | * CMD_USE_FIXED_RATE. |
| 2278 | */ |
| 2279 | #define MWL8K_RATE_TABLE_SIZE 8 |
| 2280 | #define MWL8K_UCAST_RATE 0 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2281 | #define MWL8K_USE_AUTO_RATE 0x0002 |
| 2282 | |
| 2283 | struct mwl8k_rate_entry { |
| 2284 | /* Set to 1 if HT rate, 0 if legacy. */ |
| 2285 | __le32 is_ht_rate; |
| 2286 | |
| 2287 | /* Set to 1 to use retry_count field. */ |
| 2288 | __le32 enable_retry; |
| 2289 | |
| 2290 | /* Specified legacy rate or MCS. */ |
| 2291 | __le32 rate; |
| 2292 | |
| 2293 | /* Number of allowed retries. */ |
| 2294 | __le32 retry_count; |
| 2295 | } __attribute__((packed)); |
| 2296 | |
| 2297 | struct mwl8k_rate_table { |
| 2298 | /* 1 to allow specified rate and below */ |
| 2299 | __le32 allow_rate_drop; |
| 2300 | __le32 num_rates; |
| 2301 | struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE]; |
| 2302 | } __attribute__((packed)); |
| 2303 | |
| 2304 | struct mwl8k_cmd_use_fixed_rate { |
| 2305 | struct mwl8k_cmd_pkt header; |
| 2306 | __le32 action; |
| 2307 | struct mwl8k_rate_table rate_table; |
| 2308 | |
| 2309 | /* Unicast, Broadcast or Multicast */ |
| 2310 | __le32 rate_type; |
| 2311 | __le32 reserved1; |
| 2312 | __le32 reserved2; |
| 2313 | } __attribute__((packed)); |
| 2314 | |
| 2315 | static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw, |
| 2316 | u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table) |
| 2317 | { |
| 2318 | struct mwl8k_cmd_use_fixed_rate *cmd; |
| 2319 | int count; |
| 2320 | int rc; |
| 2321 | |
| 2322 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2323 | if (cmd == NULL) |
| 2324 | return -ENOMEM; |
| 2325 | |
| 2326 | cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE); |
| 2327 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2328 | |
| 2329 | cmd->action = cpu_to_le32(action); |
| 2330 | cmd->rate_type = cpu_to_le32(rate_type); |
| 2331 | |
| 2332 | if (rate_table != NULL) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2333 | /* |
| 2334 | * Copy over each field manually so that endian |
| 2335 | * conversion can be done. |
| 2336 | */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2337 | cmd->rate_table.allow_rate_drop = |
| 2338 | cpu_to_le32(rate_table->allow_rate_drop); |
| 2339 | cmd->rate_table.num_rates = |
| 2340 | cpu_to_le32(rate_table->num_rates); |
| 2341 | |
| 2342 | for (count = 0; count < rate_table->num_rates; count++) { |
| 2343 | struct mwl8k_rate_entry *dst = |
| 2344 | &cmd->rate_table.rate_entry[count]; |
| 2345 | struct mwl8k_rate_entry *src = |
| 2346 | &rate_table->rate_entry[count]; |
| 2347 | |
| 2348 | dst->is_ht_rate = cpu_to_le32(src->is_ht_rate); |
| 2349 | dst->enable_retry = cpu_to_le32(src->enable_retry); |
| 2350 | dst->rate = cpu_to_le32(src->rate); |
| 2351 | dst->retry_count = cpu_to_le32(src->retry_count); |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2356 | kfree(cmd); |
| 2357 | |
| 2358 | return rc; |
| 2359 | } |
| 2360 | |
| 2361 | |
| 2362 | /* |
| 2363 | * Interrupt handling. |
| 2364 | */ |
| 2365 | static irqreturn_t mwl8k_interrupt(int irq, void *dev_id) |
| 2366 | { |
| 2367 | struct ieee80211_hw *hw = dev_id; |
| 2368 | struct mwl8k_priv *priv = hw->priv; |
| 2369 | u32 status; |
| 2370 | |
| 2371 | status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 2372 | iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 2373 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2374 | if (!status) |
| 2375 | return IRQ_NONE; |
| 2376 | |
| 2377 | if (status & MWL8K_A2H_INT_TX_DONE) |
| 2378 | tasklet_schedule(&priv->tx_reclaim_task); |
| 2379 | |
| 2380 | if (status & MWL8K_A2H_INT_RX_READY) { |
| 2381 | while (rxq_process(hw, 0, 1)) |
| 2382 | rxq_refill(hw, 0, 1); |
| 2383 | } |
| 2384 | |
| 2385 | if (status & MWL8K_A2H_INT_OPC_DONE) { |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2386 | if (priv->hostcmd_wait != NULL) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2387 | complete(priv->hostcmd_wait); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | if (status & MWL8K_A2H_INT_QUEUE_EMPTY) { |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2391 | if (!mutex_is_locked(&priv->fw_mutex) && |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 2392 | priv->radio_on && priv->pending_tx_pkts) |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2393 | mwl8k_tx_start(priv); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | return IRQ_HANDLED; |
| 2397 | } |
| 2398 | |
| 2399 | |
| 2400 | /* |
| 2401 | * Core driver operations. |
| 2402 | */ |
| 2403 | static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 2404 | { |
| 2405 | struct mwl8k_priv *priv = hw->priv; |
| 2406 | int index = skb_get_queue_mapping(skb); |
| 2407 | int rc; |
| 2408 | |
| 2409 | if (priv->current_channel == NULL) { |
| 2410 | printk(KERN_DEBUG "%s: dropped TX frame since radio " |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2411 | "disabled\n", wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2412 | dev_kfree_skb(skb); |
| 2413 | return NETDEV_TX_OK; |
| 2414 | } |
| 2415 | |
| 2416 | rc = mwl8k_txq_xmit(hw, index, skb); |
| 2417 | |
| 2418 | return rc; |
| 2419 | } |
| 2420 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2421 | static int mwl8k_start(struct ieee80211_hw *hw) |
| 2422 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2423 | struct mwl8k_priv *priv = hw->priv; |
| 2424 | int rc; |
| 2425 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2426 | rc = request_irq(priv->pdev->irq, &mwl8k_interrupt, |
| 2427 | IRQF_SHARED, MWL8K_NAME, hw); |
| 2428 | if (rc) { |
| 2429 | printk(KERN_ERR "%s: failed to register IRQ handler\n", |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2430 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 2431 | return -EIO; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2432 | } |
| 2433 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 2434 | /* Enable tx reclaim tasklet */ |
| 2435 | tasklet_enable(&priv->tx_reclaim_task); |
| 2436 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2437 | /* Enable interrupts */ |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 2438 | iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2439 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 2440 | rc = mwl8k_fw_lock(hw); |
| 2441 | if (!rc) { |
| 2442 | rc = mwl8k_cmd_802_11_radio_enable(hw); |
| 2443 | |
| 2444 | if (!rc) |
| 2445 | rc = mwl8k_cmd_set_pre_scan(hw); |
| 2446 | |
| 2447 | if (!rc) |
| 2448 | rc = mwl8k_cmd_set_post_scan(hw, |
| 2449 | "\x00\x00\x00\x00\x00\x00"); |
| 2450 | |
| 2451 | if (!rc) |
| 2452 | rc = mwl8k_cmd_setrateadaptmode(hw, 0); |
| 2453 | |
| 2454 | if (!rc) |
| 2455 | rc = mwl8k_set_wmm(hw, 0); |
| 2456 | |
| 2457 | if (!rc) |
| 2458 | rc = mwl8k_enable_sniffer(hw, 0); |
| 2459 | |
| 2460 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2461 | } |
| 2462 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 2463 | if (rc) { |
| 2464 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 2465 | free_irq(priv->pdev->irq, hw); |
| 2466 | tasklet_disable(&priv->tx_reclaim_task); |
| 2467 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2468 | |
| 2469 | return rc; |
| 2470 | } |
| 2471 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2472 | static void mwl8k_stop(struct ieee80211_hw *hw) |
| 2473 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2474 | struct mwl8k_priv *priv = hw->priv; |
| 2475 | int i; |
| 2476 | |
Lennert Buytenhek | d3cea0b | 2009-07-17 07:15:49 +0200 | [diff] [blame] | 2477 | mwl8k_cmd_802_11_radio_disable(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2478 | |
| 2479 | ieee80211_stop_queues(hw); |
| 2480 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2481 | /* Disable interrupts */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2482 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2483 | free_irq(priv->pdev->irq, hw); |
| 2484 | |
| 2485 | /* Stop finalize join worker */ |
| 2486 | cancel_work_sync(&priv->finalize_join_worker); |
| 2487 | if (priv->beacon_skb != NULL) |
| 2488 | dev_kfree_skb(priv->beacon_skb); |
| 2489 | |
| 2490 | /* Stop tx reclaim tasklet */ |
| 2491 | tasklet_disable(&priv->tx_reclaim_task); |
| 2492 | |
| 2493 | /* Stop config thread */ |
| 2494 | flush_workqueue(priv->config_wq); |
| 2495 | |
| 2496 | /* Return all skbs to mac80211 */ |
| 2497 | for (i = 0; i < MWL8K_TX_QUEUES; i++) |
| 2498 | mwl8k_txq_reclaim(hw, i, 1); |
| 2499 | } |
| 2500 | |
| 2501 | static int mwl8k_add_interface(struct ieee80211_hw *hw, |
| 2502 | struct ieee80211_if_init_conf *conf) |
| 2503 | { |
| 2504 | struct mwl8k_priv *priv = hw->priv; |
| 2505 | struct mwl8k_vif *mwl8k_vif; |
| 2506 | |
| 2507 | /* |
| 2508 | * We only support one active interface at a time. |
| 2509 | */ |
| 2510 | if (priv->vif != NULL) |
| 2511 | return -EBUSY; |
| 2512 | |
| 2513 | /* |
| 2514 | * We only support managed interfaces for now. |
| 2515 | */ |
Lennert Buytenhek | 240e86e | 2009-07-16 14:15:44 +0200 | [diff] [blame] | 2516 | if (conf->type != NL80211_IFTYPE_STATION) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2517 | return -EINVAL; |
| 2518 | |
| 2519 | /* Clean out driver private area */ |
| 2520 | mwl8k_vif = MWL8K_VIF(conf->vif); |
| 2521 | memset(mwl8k_vif, 0, sizeof(*mwl8k_vif)); |
| 2522 | |
| 2523 | /* Save the mac address */ |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2524 | memcpy(mwl8k_vif->mac_addr, conf->mac_addr, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2525 | |
| 2526 | /* Back pointer to parent config block */ |
| 2527 | mwl8k_vif->priv = priv; |
| 2528 | |
| 2529 | /* Setup initial PHY parameters */ |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2530 | memcpy(mwl8k_vif->legacy_rates, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2531 | priv->rates, sizeof(mwl8k_vif->legacy_rates)); |
| 2532 | mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates); |
| 2533 | |
| 2534 | /* Set Initial sequence number to zero */ |
| 2535 | mwl8k_vif->seqno = 0; |
| 2536 | |
| 2537 | priv->vif = conf->vif; |
| 2538 | priv->current_channel = NULL; |
| 2539 | |
| 2540 | return 0; |
| 2541 | } |
| 2542 | |
| 2543 | static void mwl8k_remove_interface(struct ieee80211_hw *hw, |
| 2544 | struct ieee80211_if_init_conf *conf) |
| 2545 | { |
| 2546 | struct mwl8k_priv *priv = hw->priv; |
| 2547 | |
| 2548 | if (priv->vif == NULL) |
| 2549 | return; |
| 2550 | |
| 2551 | priv->vif = NULL; |
| 2552 | } |
| 2553 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 2554 | static int mwl8k_config(struct ieee80211_hw *hw, u32 changed) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2555 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2556 | struct ieee80211_conf *conf = &hw->conf; |
| 2557 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 2558 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2559 | |
Lennert Buytenhek | 7595d67 | 2009-08-17 23:59:40 +0200 | [diff] [blame] | 2560 | if (conf->flags & IEEE80211_CONF_IDLE) { |
| 2561 | mwl8k_cmd_802_11_radio_disable(hw); |
| 2562 | priv->current_channel = NULL; |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 2563 | return 0; |
Lennert Buytenhek | 7595d67 | 2009-08-17 23:59:40 +0200 | [diff] [blame] | 2564 | } |
| 2565 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 2566 | rc = mwl8k_fw_lock(hw); |
| 2567 | if (rc) |
| 2568 | return rc; |
| 2569 | |
| 2570 | rc = mwl8k_cmd_802_11_radio_enable(hw); |
| 2571 | if (rc) |
| 2572 | goto out; |
| 2573 | |
| 2574 | rc = mwl8k_cmd_set_rf_channel(hw, conf->channel); |
| 2575 | if (rc) |
| 2576 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2577 | |
| 2578 | priv->current_channel = conf->channel; |
| 2579 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2580 | if (conf->power_level > 18) |
| 2581 | conf->power_level = 18; |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 2582 | rc = mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level); |
| 2583 | if (rc) |
| 2584 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2585 | |
| 2586 | if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7)) |
| 2587 | rc = -EINVAL; |
| 2588 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 2589 | out: |
| 2590 | mwl8k_fw_unlock(hw); |
| 2591 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2592 | return rc; |
| 2593 | } |
| 2594 | |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2595 | static void mwl8k_bss_info_changed(struct ieee80211_hw *hw, |
| 2596 | struct ieee80211_vif *vif, |
| 2597 | struct ieee80211_bss_conf *info, |
| 2598 | u32 changed) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2599 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2600 | struct mwl8k_priv *priv = hw->priv; |
| 2601 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2602 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2603 | |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2604 | if (changed & BSS_CHANGED_BSSID) |
| 2605 | memcpy(mwl8k_vif->bssid, info->bssid, ETH_ALEN); |
| 2606 | |
| 2607 | if ((changed & BSS_CHANGED_ASSOC) == 0) |
| 2608 | return; |
| 2609 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2610 | priv->capture_beacon = false; |
| 2611 | |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2612 | rc = mwl8k_fw_lock(hw); |
Lennert Buytenhek | 942457d | 2009-08-24 15:42:36 +0200 | [diff] [blame] | 2613 | if (rc) |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2614 | return; |
| 2615 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2616 | if (info->assoc) { |
| 2617 | memcpy(&mwl8k_vif->bss_info, info, |
| 2618 | sizeof(struct ieee80211_bss_conf)); |
| 2619 | |
| 2620 | /* Install rates */ |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2621 | rc = mwl8k_update_rateset(hw, vif); |
| 2622 | if (rc) |
| 2623 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2624 | |
| 2625 | /* Turn on rate adaptation */ |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2626 | rc = mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE, |
| 2627 | MWL8K_UCAST_RATE, NULL); |
| 2628 | if (rc) |
| 2629 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2630 | |
| 2631 | /* Set radio preamble */ |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2632 | rc = mwl8k_set_radio_preamble(hw, info->use_short_preamble); |
| 2633 | if (rc) |
| 2634 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2635 | |
| 2636 | /* Set slot time */ |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2637 | rc = mwl8k_cmd_set_slot(hw, info->use_short_slot); |
| 2638 | if (rc) |
| 2639 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2640 | |
| 2641 | /* Update peer rate info */ |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2642 | rc = mwl8k_cmd_update_sta_db(hw, vif, |
| 2643 | MWL8K_STA_DB_MODIFY_ENTRY); |
| 2644 | if (rc) |
| 2645 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2646 | |
| 2647 | /* Set AID */ |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2648 | rc = mwl8k_cmd_set_aid(hw, vif); |
| 2649 | if (rc) |
| 2650 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2651 | |
| 2652 | /* |
| 2653 | * Finalize the join. Tell rx handler to process |
| 2654 | * next beacon from our BSSID. |
| 2655 | */ |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2656 | memcpy(priv->capture_bssid, mwl8k_vif->bssid, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2657 | priv->capture_beacon = true; |
| 2658 | } else { |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2659 | rc = mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2660 | memset(&mwl8k_vif->bss_info, 0, |
| 2661 | sizeof(struct ieee80211_bss_conf)); |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2662 | memset(mwl8k_vif->bssid, 0, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2663 | } |
| 2664 | |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 2665 | out: |
| 2666 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2667 | } |
| 2668 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2669 | static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw, |
| 2670 | int mc_count, struct dev_addr_list *mclist) |
| 2671 | { |
| 2672 | struct mwl8k_cmd_pkt *cmd; |
| 2673 | |
| 2674 | cmd = __mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist); |
| 2675 | |
| 2676 | return (unsigned long)cmd; |
| 2677 | } |
| 2678 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 2679 | static void mwl8k_configure_filter(struct ieee80211_hw *hw, |
| 2680 | unsigned int changed_flags, |
| 2681 | unsigned int *total_flags, |
| 2682 | u64 multicast) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2683 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2684 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 2685 | struct mwl8k_cmd_pkt *multicast_adr_cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2686 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 2687 | /* Clear unsupported feature flags */ |
| 2688 | *total_flags &= FIF_BCN_PRBRESP_PROMISC; |
| 2689 | |
| 2690 | if (mwl8k_fw_lock(hw)) |
| 2691 | return; |
| 2692 | |
| 2693 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 2694 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
| 2695 | mwl8k_cmd_set_pre_scan(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2696 | else { |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 2697 | u8 *bssid; |
| 2698 | |
| 2699 | bssid = "\x00\x00\x00\x00\x00\x00"; |
| 2700 | if (priv->vif != NULL) |
| 2701 | bssid = MWL8K_VIF(priv->vif)->bssid; |
| 2702 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 2703 | mwl8k_cmd_set_post_scan(hw, bssid); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 2707 | multicast_adr_cmd = (void *)(unsigned long)multicast; |
| 2708 | if (multicast_adr_cmd != NULL) { |
| 2709 | mwl8k_post_cmd(hw, multicast_adr_cmd); |
| 2710 | kfree(multicast_adr_cmd); |
| 2711 | } |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2712 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 2713 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2714 | } |
| 2715 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2716 | static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 2717 | { |
Lennert Buytenhek | 733d306 | 2009-07-17 07:24:15 +0200 | [diff] [blame] | 2718 | return mwl8k_rts_threshold(hw, MWL8K_CMD_SET, value); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2719 | } |
| 2720 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2721 | static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue, |
| 2722 | const struct ieee80211_tx_queue_params *params) |
| 2723 | { |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 2724 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2725 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2726 | |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 2727 | rc = mwl8k_fw_lock(hw); |
| 2728 | if (!rc) { |
| 2729 | if (!priv->wmm_enabled) |
| 2730 | rc = mwl8k_set_wmm(hw, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2731 | |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 2732 | if (!rc) |
| 2733 | rc = mwl8k_set_edca_params(hw, queue, |
| 2734 | params->cw_min, |
| 2735 | params->cw_max, |
| 2736 | params->aifs, |
| 2737 | params->txop); |
| 2738 | |
| 2739 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2740 | } |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 2741 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2742 | return rc; |
| 2743 | } |
| 2744 | |
| 2745 | static int mwl8k_get_tx_stats(struct ieee80211_hw *hw, |
| 2746 | struct ieee80211_tx_queue_stats *stats) |
| 2747 | { |
| 2748 | struct mwl8k_priv *priv = hw->priv; |
| 2749 | struct mwl8k_tx_queue *txq; |
| 2750 | int index; |
| 2751 | |
| 2752 | spin_lock_bh(&priv->tx_lock); |
| 2753 | for (index = 0; index < MWL8K_TX_QUEUES; index++) { |
| 2754 | txq = priv->txq + index; |
| 2755 | memcpy(&stats[index], &txq->tx_stats, |
| 2756 | sizeof(struct ieee80211_tx_queue_stats)); |
| 2757 | } |
| 2758 | spin_unlock_bh(&priv->tx_lock); |
Lennert Buytenhek | 954ef50 | 2009-07-17 07:26:27 +0200 | [diff] [blame] | 2759 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2760 | return 0; |
| 2761 | } |
| 2762 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2763 | static int mwl8k_get_stats(struct ieee80211_hw *hw, |
| 2764 | struct ieee80211_low_level_stats *stats) |
| 2765 | { |
Lennert Buytenhek | 954ef50 | 2009-07-17 07:26:27 +0200 | [diff] [blame] | 2766 | return mwl8k_cmd_802_11_get_stat(hw, stats); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | static const struct ieee80211_ops mwl8k_ops = { |
| 2770 | .tx = mwl8k_tx, |
| 2771 | .start = mwl8k_start, |
| 2772 | .stop = mwl8k_stop, |
| 2773 | .add_interface = mwl8k_add_interface, |
| 2774 | .remove_interface = mwl8k_remove_interface, |
| 2775 | .config = mwl8k_config, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2776 | .bss_info_changed = mwl8k_bss_info_changed, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 2777 | .prepare_multicast = mwl8k_prepare_multicast, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2778 | .configure_filter = mwl8k_configure_filter, |
| 2779 | .set_rts_threshold = mwl8k_set_rts_threshold, |
| 2780 | .conf_tx = mwl8k_conf_tx, |
| 2781 | .get_tx_stats = mwl8k_get_tx_stats, |
| 2782 | .get_stats = mwl8k_get_stats, |
| 2783 | }; |
| 2784 | |
| 2785 | static void mwl8k_tx_reclaim_handler(unsigned long data) |
| 2786 | { |
| 2787 | int i; |
| 2788 | struct ieee80211_hw *hw = (struct ieee80211_hw *) data; |
| 2789 | struct mwl8k_priv *priv = hw->priv; |
| 2790 | |
| 2791 | spin_lock_bh(&priv->tx_lock); |
| 2792 | for (i = 0; i < MWL8K_TX_QUEUES; i++) |
| 2793 | mwl8k_txq_reclaim(hw, i, 0); |
| 2794 | |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 2795 | if (priv->tx_wait != NULL && !priv->pending_tx_pkts) { |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2796 | complete(priv->tx_wait); |
| 2797 | priv->tx_wait = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2798 | } |
| 2799 | spin_unlock_bh(&priv->tx_lock); |
| 2800 | } |
| 2801 | |
| 2802 | static void mwl8k_finalize_join_worker(struct work_struct *work) |
| 2803 | { |
| 2804 | struct mwl8k_priv *priv = |
| 2805 | container_of(work, struct mwl8k_priv, finalize_join_worker); |
| 2806 | struct sk_buff *skb = priv->beacon_skb; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2807 | u8 dtim = MWL8K_VIF(priv->vif)->bss_info.dtim_period; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2808 | |
| 2809 | mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim); |
| 2810 | dev_kfree_skb(skb); |
| 2811 | |
| 2812 | priv->beacon_skb = NULL; |
| 2813 | } |
| 2814 | |
| 2815 | static int __devinit mwl8k_probe(struct pci_dev *pdev, |
| 2816 | const struct pci_device_id *id) |
| 2817 | { |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 2818 | static int printed_version = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2819 | struct ieee80211_hw *hw; |
| 2820 | struct mwl8k_priv *priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2821 | int rc; |
| 2822 | int i; |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 2823 | |
| 2824 | if (!printed_version) { |
| 2825 | printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION); |
| 2826 | printed_version = 1; |
| 2827 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2828 | |
| 2829 | rc = pci_enable_device(pdev); |
| 2830 | if (rc) { |
| 2831 | printk(KERN_ERR "%s: Cannot enable new PCI device\n", |
| 2832 | MWL8K_NAME); |
| 2833 | return rc; |
| 2834 | } |
| 2835 | |
| 2836 | rc = pci_request_regions(pdev, MWL8K_NAME); |
| 2837 | if (rc) { |
| 2838 | printk(KERN_ERR "%s: Cannot obtain PCI resources\n", |
| 2839 | MWL8K_NAME); |
| 2840 | return rc; |
| 2841 | } |
| 2842 | |
| 2843 | pci_set_master(pdev); |
| 2844 | |
| 2845 | hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops); |
| 2846 | if (hw == NULL) { |
| 2847 | printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME); |
| 2848 | rc = -ENOMEM; |
| 2849 | goto err_free_reg; |
| 2850 | } |
| 2851 | |
| 2852 | priv = hw->priv; |
| 2853 | priv->hw = hw; |
| 2854 | priv->pdev = pdev; |
Lennert Buytenhek | 0439b1f | 2009-07-16 12:34:02 +0200 | [diff] [blame] | 2855 | priv->wmm_enabled = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2856 | priv->pending_tx_pkts = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2857 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2858 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 2859 | pci_set_drvdata(pdev, hw); |
| 2860 | |
| 2861 | priv->regs = pci_iomap(pdev, 1, 0x10000); |
| 2862 | if (priv->regs == NULL) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2863 | printk(KERN_ERR "%s: Cannot map device memory\n", |
| 2864 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2865 | goto err_iounmap; |
| 2866 | } |
| 2867 | |
| 2868 | memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels)); |
| 2869 | priv->band.band = IEEE80211_BAND_2GHZ; |
| 2870 | priv->band.channels = priv->channels; |
| 2871 | priv->band.n_channels = ARRAY_SIZE(mwl8k_channels); |
| 2872 | priv->band.bitrates = priv->rates; |
| 2873 | priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates); |
| 2874 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band; |
| 2875 | |
| 2876 | BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates)); |
| 2877 | memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates)); |
| 2878 | |
| 2879 | /* |
| 2880 | * Extra headroom is the size of the required DMA header |
| 2881 | * minus the size of the smallest 802.11 frame (CTS frame). |
| 2882 | */ |
| 2883 | hw->extra_tx_headroom = |
| 2884 | sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts); |
| 2885 | |
| 2886 | hw->channel_change_time = 10; |
| 2887 | |
| 2888 | hw->queues = MWL8K_TX_QUEUES; |
| 2889 | |
Lennert Buytenhek | 240e86e | 2009-07-16 14:15:44 +0200 | [diff] [blame] | 2890 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2891 | |
| 2892 | /* Set rssi and noise values to dBm */ |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2893 | hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2894 | hw->vif_data_size = sizeof(struct mwl8k_vif); |
| 2895 | priv->vif = NULL; |
| 2896 | |
| 2897 | /* Set default radio state and preamble */ |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2898 | priv->radio_on = 0; |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 2899 | priv->radio_short_preamble = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2900 | |
| 2901 | /* Finalize join worker */ |
| 2902 | INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker); |
| 2903 | |
| 2904 | /* TX reclaim tasklet */ |
| 2905 | tasklet_init(&priv->tx_reclaim_task, |
| 2906 | mwl8k_tx_reclaim_handler, (unsigned long)hw); |
| 2907 | tasklet_disable(&priv->tx_reclaim_task); |
| 2908 | |
| 2909 | /* Config workthread */ |
| 2910 | priv->config_wq = create_singlethread_workqueue("mwl8k_config"); |
| 2911 | if (priv->config_wq == NULL) |
| 2912 | goto err_iounmap; |
| 2913 | |
| 2914 | /* Power management cookie */ |
| 2915 | priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma); |
| 2916 | if (priv->cookie == NULL) |
| 2917 | goto err_iounmap; |
| 2918 | |
| 2919 | rc = mwl8k_rxq_init(hw, 0); |
| 2920 | if (rc) |
| 2921 | goto err_iounmap; |
| 2922 | rxq_refill(hw, 0, INT_MAX); |
| 2923 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2924 | mutex_init(&priv->fw_mutex); |
| 2925 | priv->fw_mutex_owner = NULL; |
| 2926 | priv->fw_mutex_depth = 0; |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2927 | priv->hostcmd_wait = NULL; |
| 2928 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2929 | spin_lock_init(&priv->tx_lock); |
| 2930 | |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame^] | 2931 | priv->tx_wait = NULL; |
| 2932 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2933 | for (i = 0; i < MWL8K_TX_QUEUES; i++) { |
| 2934 | rc = mwl8k_txq_init(hw, i); |
| 2935 | if (rc) |
| 2936 | goto err_free_queues; |
| 2937 | } |
| 2938 | |
| 2939 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 2940 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2941 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL); |
| 2942 | iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
| 2943 | |
| 2944 | rc = request_irq(priv->pdev->irq, &mwl8k_interrupt, |
| 2945 | IRQF_SHARED, MWL8K_NAME, hw); |
| 2946 | if (rc) { |
| 2947 | printk(KERN_ERR "%s: failed to register IRQ handler\n", |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2948 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2949 | goto err_free_queues; |
| 2950 | } |
| 2951 | |
| 2952 | /* Reset firmware and hardware */ |
| 2953 | mwl8k_hw_reset(priv); |
| 2954 | |
| 2955 | /* Ask userland hotplug daemon for the device firmware */ |
| 2956 | rc = mwl8k_request_firmware(priv, (u32)id->driver_data); |
| 2957 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2958 | printk(KERN_ERR "%s: Firmware files not found\n", |
| 2959 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2960 | goto err_free_irq; |
| 2961 | } |
| 2962 | |
| 2963 | /* Load firmware into hardware */ |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2964 | rc = mwl8k_load_firmware(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2965 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2966 | printk(KERN_ERR "%s: Cannot start firmware\n", |
| 2967 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2968 | goto err_stop_firmware; |
| 2969 | } |
| 2970 | |
| 2971 | /* Reclaim memory once firmware is successfully loaded */ |
| 2972 | mwl8k_release_firmware(priv); |
| 2973 | |
| 2974 | /* |
| 2975 | * Temporarily enable interrupts. Initial firmware host |
| 2976 | * commands use interrupts and avoids polling. Disable |
| 2977 | * interrupts when done. |
| 2978 | */ |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 2979 | iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2980 | |
| 2981 | /* Get config data, mac addrs etc */ |
| 2982 | rc = mwl8k_cmd_get_hw_spec(hw); |
| 2983 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2984 | printk(KERN_ERR "%s: Cannot initialise firmware\n", |
| 2985 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2986 | goto err_stop_firmware; |
| 2987 | } |
| 2988 | |
| 2989 | /* Turn radio off */ |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2990 | rc = mwl8k_cmd_802_11_radio_disable(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2991 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 2992 | printk(KERN_ERR "%s: Cannot disable\n", wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2993 | goto err_stop_firmware; |
| 2994 | } |
| 2995 | |
| 2996 | /* Disable interrupts */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2997 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2998 | free_irq(priv->pdev->irq, hw); |
| 2999 | |
| 3000 | rc = ieee80211_register_hw(hw); |
| 3001 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 3002 | printk(KERN_ERR "%s: Cannot register device\n", |
| 3003 | wiphy_name(hw->wiphy)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3004 | goto err_stop_firmware; |
| 3005 | } |
| 3006 | |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 3007 | printk(KERN_INFO "%s: 88w%u v%d, %pM, firmware version %u.%u.%u.%u\n", |
| 3008 | wiphy_name(hw->wiphy), priv->part_num, priv->hw_rev, |
| 3009 | hw->wiphy->perm_addr, |
| 3010 | (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff, |
| 3011 | (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3012 | |
| 3013 | return 0; |
| 3014 | |
| 3015 | err_stop_firmware: |
| 3016 | mwl8k_hw_reset(priv); |
| 3017 | mwl8k_release_firmware(priv); |
| 3018 | |
| 3019 | err_free_irq: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3020 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3021 | free_irq(priv->pdev->irq, hw); |
| 3022 | |
| 3023 | err_free_queues: |
| 3024 | for (i = 0; i < MWL8K_TX_QUEUES; i++) |
| 3025 | mwl8k_txq_deinit(hw, i); |
| 3026 | mwl8k_rxq_deinit(hw, 0); |
| 3027 | |
| 3028 | err_iounmap: |
| 3029 | if (priv->cookie != NULL) |
| 3030 | pci_free_consistent(priv->pdev, 4, |
| 3031 | priv->cookie, priv->cookie_dma); |
| 3032 | |
| 3033 | if (priv->regs != NULL) |
| 3034 | pci_iounmap(pdev, priv->regs); |
| 3035 | |
| 3036 | if (priv->config_wq != NULL) |
| 3037 | destroy_workqueue(priv->config_wq); |
| 3038 | |
| 3039 | pci_set_drvdata(pdev, NULL); |
| 3040 | ieee80211_free_hw(hw); |
| 3041 | |
| 3042 | err_free_reg: |
| 3043 | pci_release_regions(pdev); |
| 3044 | pci_disable_device(pdev); |
| 3045 | |
| 3046 | return rc; |
| 3047 | } |
| 3048 | |
Joerg Albert | 230f7af | 2009-04-18 02:10:45 +0200 | [diff] [blame] | 3049 | static void __devexit mwl8k_shutdown(struct pci_dev *pdev) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3050 | { |
| 3051 | printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__); |
| 3052 | } |
| 3053 | |
Joerg Albert | 230f7af | 2009-04-18 02:10:45 +0200 | [diff] [blame] | 3054 | static void __devexit mwl8k_remove(struct pci_dev *pdev) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3055 | { |
| 3056 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 3057 | struct mwl8k_priv *priv; |
| 3058 | int i; |
| 3059 | |
| 3060 | if (hw == NULL) |
| 3061 | return; |
| 3062 | priv = hw->priv; |
| 3063 | |
| 3064 | ieee80211_stop_queues(hw); |
| 3065 | |
Lennert Buytenhek | 60aa569 | 2009-08-03 21:59:09 +0200 | [diff] [blame] | 3066 | ieee80211_unregister_hw(hw); |
| 3067 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3068 | /* Remove tx reclaim tasklet */ |
| 3069 | tasklet_kill(&priv->tx_reclaim_task); |
| 3070 | |
| 3071 | /* Stop config thread */ |
| 3072 | destroy_workqueue(priv->config_wq); |
| 3073 | |
| 3074 | /* Stop hardware */ |
| 3075 | mwl8k_hw_reset(priv); |
| 3076 | |
| 3077 | /* Return all skbs to mac80211 */ |
| 3078 | for (i = 0; i < MWL8K_TX_QUEUES; i++) |
| 3079 | mwl8k_txq_reclaim(hw, i, 1); |
| 3080 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3081 | for (i = 0; i < MWL8K_TX_QUEUES; i++) |
| 3082 | mwl8k_txq_deinit(hw, i); |
| 3083 | |
| 3084 | mwl8k_rxq_deinit(hw, 0); |
| 3085 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 3086 | pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3087 | |
| 3088 | pci_iounmap(pdev, priv->regs); |
| 3089 | pci_set_drvdata(pdev, NULL); |
| 3090 | ieee80211_free_hw(hw); |
| 3091 | pci_release_regions(pdev); |
| 3092 | pci_disable_device(pdev); |
| 3093 | } |
| 3094 | |
| 3095 | static struct pci_driver mwl8k_driver = { |
| 3096 | .name = MWL8K_NAME, |
| 3097 | .id_table = mwl8k_table, |
| 3098 | .probe = mwl8k_probe, |
| 3099 | .remove = __devexit_p(mwl8k_remove), |
| 3100 | .shutdown = __devexit_p(mwl8k_shutdown), |
| 3101 | }; |
| 3102 | |
| 3103 | static int __init mwl8k_init(void) |
| 3104 | { |
| 3105 | return pci_register_driver(&mwl8k_driver); |
| 3106 | } |
| 3107 | |
| 3108 | static void __exit mwl8k_exit(void) |
| 3109 | { |
| 3110 | pci_unregister_driver(&mwl8k_driver); |
| 3111 | } |
| 3112 | |
| 3113 | module_init(mwl8k_init); |
| 3114 | module_exit(mwl8k_exit); |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 3115 | |
| 3116 | MODULE_DESCRIPTION(MWL8K_DESC); |
| 3117 | MODULE_VERSION(MWL8K_VERSION); |
| 3118 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>"); |
| 3119 | MODULE_LICENSE("GPL"); |