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