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