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