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