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