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