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