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