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