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