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