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