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