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