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