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