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