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