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 | a5fb297 | 2010-01-12 13:51:38 +0100 | [diff] [blame] | 5 | * Copyright (C) 2008, 2009, 2010 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> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
Lennert Buytenhek | 3d76e82 | 2009-10-22 20:20:16 +0200 | [diff] [blame] | 16 | #include <linux/sched.h> |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/list.h> |
| 19 | #include <linux/pci.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/completion.h> |
| 22 | #include <linux/etherdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 24 | #include <net/mac80211.h> |
| 25 | #include <linux/moduleparam.h> |
| 26 | #include <linux/firmware.h> |
| 27 | #include <linux/workqueue.h> |
| 28 | |
| 29 | #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver" |
| 30 | #define MWL8K_NAME KBUILD_MODNAME |
Yogesh Ashok Powar | 00e8e69 | 2011-12-20 11:39:29 +0530 | [diff] [blame] | 31 | #define MWL8K_VERSION "0.13" |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 32 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 33 | /* Module parameters */ |
Rusty Russell | eb93992 | 2011-12-19 14:08:01 +0000 | [diff] [blame] | 34 | static bool ap_mode_default; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 35 | module_param(ap_mode_default, bool, 0); |
| 36 | MODULE_PARM_DESC(ap_mode_default, |
| 37 | "Set to 1 to make ap mode the default instead of sta mode"); |
| 38 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 39 | /* Register definitions */ |
| 40 | #define MWL8K_HIU_GEN_PTR 0x00000c10 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 41 | #define MWL8K_MODE_STA 0x0000005a |
| 42 | #define MWL8K_MODE_AP 0x000000a5 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 43 | #define MWL8K_HIU_INT_CODE 0x00000c14 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 44 | #define MWL8K_FWSTA_READY 0xf0f1f2f4 |
| 45 | #define MWL8K_FWAP_READY 0xf1f2f4a5 |
| 46 | #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 47 | #define MWL8K_HIU_SCRATCH 0x00000c40 |
| 48 | |
| 49 | /* Host->device communications */ |
| 50 | #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18 |
| 51 | #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c |
| 52 | #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20 |
| 53 | #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24 |
| 54 | #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 55 | #define MWL8K_H2A_INT_DUMMY (1 << 20) |
| 56 | #define MWL8K_H2A_INT_RESET (1 << 15) |
| 57 | #define MWL8K_H2A_INT_DOORBELL (1 << 1) |
| 58 | #define MWL8K_H2A_INT_PPA_READY (1 << 0) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 59 | |
| 60 | /* Device->host communications */ |
| 61 | #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c |
| 62 | #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30 |
| 63 | #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34 |
| 64 | #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38 |
| 65 | #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 66 | #define MWL8K_A2H_INT_DUMMY (1 << 20) |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 67 | #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14) |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 68 | #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11) |
| 69 | #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10) |
| 70 | #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7) |
| 71 | #define MWL8K_A2H_INT_RADIO_ON (1 << 6) |
| 72 | #define MWL8K_A2H_INT_RADIO_OFF (1 << 5) |
| 73 | #define MWL8K_A2H_INT_MAC_EVENT (1 << 3) |
| 74 | #define MWL8K_A2H_INT_OPC_DONE (1 << 2) |
| 75 | #define MWL8K_A2H_INT_RX_READY (1 << 1) |
| 76 | #define MWL8K_A2H_INT_TX_DONE (1 << 0) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 77 | |
Pradeep Nemavat | 566875d | 2011-04-21 16:34:57 +0530 | [diff] [blame] | 78 | /* HW micro second timer register |
| 79 | * located at offset 0xA600. This |
| 80 | * will be used to timestamp tx |
| 81 | * packets. |
| 82 | */ |
| 83 | |
| 84 | #define MWL8K_HW_TIMER_REGISTER 0x0000a600 |
| 85 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 86 | #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \ |
| 87 | MWL8K_A2H_INT_CHNL_SWITCHED | \ |
| 88 | MWL8K_A2H_INT_QUEUE_EMPTY | \ |
| 89 | MWL8K_A2H_INT_RADAR_DETECT | \ |
| 90 | MWL8K_A2H_INT_RADIO_ON | \ |
| 91 | MWL8K_A2H_INT_RADIO_OFF | \ |
| 92 | MWL8K_A2H_INT_MAC_EVENT | \ |
| 93 | MWL8K_A2H_INT_OPC_DONE | \ |
| 94 | MWL8K_A2H_INT_RX_READY | \ |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 95 | MWL8K_A2H_INT_TX_DONE | \ |
| 96 | MWL8K_A2H_INT_BA_WATCHDOG) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 97 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 98 | #define MWL8K_RX_QUEUES 1 |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 99 | #define MWL8K_TX_WMM_QUEUES 4 |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 100 | #define MWL8K_MAX_AMPDU_QUEUES 8 |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 101 | #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES) |
| 102 | #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 103 | |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame^] | 104 | /* txpriorities are mapped with hw queues. |
| 105 | * Each hw queue has a txpriority. |
| 106 | */ |
| 107 | #define TOTAL_HW_TX_QUEUES 8 |
| 108 | |
| 109 | /* Each HW queue can have one AMPDU stream. |
| 110 | * But, because one of the hw queue is reserved, |
| 111 | * maximum AMPDU queues that can be created are |
| 112 | * one short of total tx queues. |
| 113 | */ |
| 114 | #define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1) |
| 115 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 116 | struct rxd_ops { |
| 117 | int rxd_size; |
| 118 | void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr); |
| 119 | void (*rxd_refill)(void *rxd, dma_addr_t addr, int len); |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 120 | int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 121 | __le16 *qos, s8 *noise); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 122 | }; |
| 123 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 124 | struct mwl8k_device_info { |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 125 | char *part_name; |
| 126 | char *helper_image; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 127 | char *fw_image_sta; |
| 128 | char *fw_image_ap; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 129 | struct rxd_ops *ap_rxd_ops; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 130 | u32 fw_api_ap; |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 131 | }; |
| 132 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 133 | struct mwl8k_rx_queue { |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 134 | int rxd_count; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 135 | |
| 136 | /* hw receives here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 137 | int head; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 138 | |
| 139 | /* refill descs here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 140 | int tail; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 141 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 142 | void *rxd; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 143 | dma_addr_t rxd_dma; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 144 | struct { |
| 145 | struct sk_buff *skb; |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 146 | DEFINE_DMA_UNMAP_ADDR(dma); |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 147 | } *buf; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 150 | struct mwl8k_tx_queue { |
| 151 | /* hw transmits here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 152 | int head; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 153 | |
| 154 | /* sw appends here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 155 | int tail; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 156 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 157 | unsigned int len; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 158 | struct mwl8k_tx_desc *txd; |
| 159 | dma_addr_t txd_dma; |
| 160 | struct sk_buff **skb; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 161 | }; |
| 162 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 163 | enum { |
| 164 | AMPDU_NO_STREAM, |
| 165 | AMPDU_STREAM_NEW, |
| 166 | AMPDU_STREAM_IN_PROGRESS, |
| 167 | AMPDU_STREAM_ACTIVE, |
| 168 | }; |
| 169 | |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 170 | struct mwl8k_ampdu_stream { |
| 171 | struct ieee80211_sta *sta; |
| 172 | u8 tid; |
| 173 | u8 state; |
| 174 | u8 idx; |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 177 | struct mwl8k_priv { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 178 | struct ieee80211_hw *hw; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 179 | struct pci_dev *pdev; |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 180 | int irq; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 181 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 182 | struct mwl8k_device_info *device_info; |
| 183 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 184 | void __iomem *sram; |
| 185 | void __iomem *regs; |
| 186 | |
| 187 | /* firmware */ |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 188 | const struct firmware *fw_helper; |
| 189 | const struct firmware *fw_ucode; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 190 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 191 | /* hardware/firmware parameters */ |
| 192 | bool ap_fw; |
| 193 | struct rxd_ops *rxd_ops; |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 194 | struct ieee80211_supported_band band_24; |
| 195 | struct ieee80211_channel channels_24[14]; |
| 196 | struct ieee80211_rate rates_24[14]; |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 197 | struct ieee80211_supported_band band_50; |
| 198 | struct ieee80211_channel channels_50[4]; |
| 199 | struct ieee80211_rate rates_50[9]; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 200 | u32 ap_macids_supported; |
| 201 | u32 sta_macids_supported; |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 202 | |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 203 | /* Ampdu stream information */ |
| 204 | u8 num_ampdu_queues; |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 205 | spinlock_t stream_lock; |
| 206 | struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES]; |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 207 | struct work_struct watchdog_ba_handle; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 208 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 209 | /* firmware access */ |
| 210 | struct mutex fw_mutex; |
| 211 | struct task_struct *fw_mutex_owner; |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 212 | struct task_struct *hw_restart_owner; |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 213 | int fw_mutex_depth; |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 214 | struct completion *hostcmd_wait; |
| 215 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 216 | /* lock held over TX and TX reap */ |
| 217 | spinlock_t tx_lock; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 218 | |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 219 | /* TX quiesce completion, protected by fw_mutex and tx_lock */ |
| 220 | struct completion *tx_wait; |
| 221 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 222 | /* List of interfaces. */ |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 223 | u32 macids_used; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 224 | struct list_head vif_list; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 225 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 226 | /* power management status cookie from firmware */ |
| 227 | u32 *cookie; |
| 228 | dma_addr_t cookie_dma; |
| 229 | |
| 230 | u16 num_mcaddrs; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 231 | u8 hw_rev; |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 232 | u32 fw_rev; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * Running count of TX packets in flight, to avoid |
| 236 | * iterating over the transmit rings each time. |
| 237 | */ |
| 238 | int pending_tx_pkts; |
| 239 | |
| 240 | struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES]; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 241 | struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES]; |
| 242 | u32 txq_offset[MWL8K_MAX_TX_QUEUES]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 243 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 244 | bool radio_on; |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 245 | bool radio_short_preamble; |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 246 | bool sniffer_enabled; |
Lennert Buytenhek | 0439b1f | 2009-07-16 12:34:02 +0200 | [diff] [blame] | 247 | bool wmm_enabled; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 248 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 249 | /* XXX need to convert this to handle multiple interfaces */ |
| 250 | bool capture_beacon; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 251 | u8 capture_bssid[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 252 | struct sk_buff *beacon_skb; |
| 253 | |
| 254 | /* |
| 255 | * This FJ worker has to be global as it is scheduled from the |
| 256 | * RX handler. At this point we don't know which interface it |
| 257 | * belongs to until the list of bssids waiting to complete join |
| 258 | * is checked. |
| 259 | */ |
| 260 | struct work_struct finalize_join_worker; |
| 261 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 262 | /* Tasklet to perform TX reclaim. */ |
| 263 | struct tasklet_struct poll_tx_task; |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 264 | |
| 265 | /* Tasklet to perform RX. */ |
| 266 | struct tasklet_struct poll_rx_task; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 267 | |
| 268 | /* Most recently reported noise in dBm */ |
| 269 | s8 noise; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 270 | |
| 271 | /* |
| 272 | * preserve the queue configurations so they can be restored if/when |
| 273 | * the firmware image is swapped. |
| 274 | */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 275 | struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES]; |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 276 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 277 | /* To perform the task of reloading the firmware */ |
| 278 | struct work_struct fw_reload; |
| 279 | bool hw_restart_in_progress; |
| 280 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 281 | /* async firmware loading state */ |
| 282 | unsigned fw_state; |
| 283 | char *fw_pref; |
| 284 | char *fw_alt; |
| 285 | struct completion firmware_loading_complete; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 286 | }; |
| 287 | |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 288 | #define MAX_WEP_KEY_LEN 13 |
| 289 | #define NUM_WEP_KEYS 4 |
| 290 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 291 | /* Per interface specific private data */ |
| 292 | struct mwl8k_vif { |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 293 | struct list_head list; |
| 294 | struct ieee80211_vif *vif; |
| 295 | |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 296 | /* Firmware macid for this vif. */ |
| 297 | int macid; |
| 298 | |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 299 | /* Non AMPDU sequence number assigned by driver. */ |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 300 | u16 seqno; |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 301 | |
| 302 | /* Saved WEP keys */ |
| 303 | struct { |
| 304 | u8 enabled; |
| 305 | u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN]; |
| 306 | } wep_key_conf[NUM_WEP_KEYS]; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 307 | |
| 308 | /* BSSID */ |
| 309 | u8 bssid[ETH_ALEN]; |
| 310 | |
| 311 | /* A flag to indicate is HW crypto is enabled for this bssid */ |
| 312 | bool is_hw_crypto_enabled; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 313 | }; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 314 | #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv)) |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 315 | #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 316 | |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 317 | struct tx_traffic_info { |
| 318 | u32 start_time; |
| 319 | u32 pkts; |
| 320 | }; |
| 321 | |
| 322 | #define MWL8K_MAX_TID 8 |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 323 | struct mwl8k_sta { |
| 324 | /* Index into station database. Returned by UPDATE_STADB. */ |
| 325 | u8 peer_id; |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 326 | u8 is_ampdu_allowed; |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 327 | struct tx_traffic_info tx_stats[MWL8K_MAX_TID]; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 328 | }; |
| 329 | #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv)) |
| 330 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 331 | static const struct ieee80211_channel mwl8k_channels_24[] = { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 332 | { .center_freq = 2412, .hw_value = 1, }, |
| 333 | { .center_freq = 2417, .hw_value = 2, }, |
| 334 | { .center_freq = 2422, .hw_value = 3, }, |
| 335 | { .center_freq = 2427, .hw_value = 4, }, |
| 336 | { .center_freq = 2432, .hw_value = 5, }, |
| 337 | { .center_freq = 2437, .hw_value = 6, }, |
| 338 | { .center_freq = 2442, .hw_value = 7, }, |
| 339 | { .center_freq = 2447, .hw_value = 8, }, |
| 340 | { .center_freq = 2452, .hw_value = 9, }, |
| 341 | { .center_freq = 2457, .hw_value = 10, }, |
| 342 | { .center_freq = 2462, .hw_value = 11, }, |
Lennert Buytenhek | 647ca6b | 2009-11-30 18:32:20 +0100 | [diff] [blame] | 343 | { .center_freq = 2467, .hw_value = 12, }, |
| 344 | { .center_freq = 2472, .hw_value = 13, }, |
| 345 | { .center_freq = 2484, .hw_value = 14, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 346 | }; |
| 347 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 348 | static const struct ieee80211_rate mwl8k_rates_24[] = { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 349 | { .bitrate = 10, .hw_value = 2, }, |
| 350 | { .bitrate = 20, .hw_value = 4, }, |
| 351 | { .bitrate = 55, .hw_value = 11, }, |
Lennert Buytenhek | 5dfd3e2 | 2009-10-22 20:20:29 +0200 | [diff] [blame] | 352 | { .bitrate = 110, .hw_value = 22, }, |
| 353 | { .bitrate = 220, .hw_value = 44, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 354 | { .bitrate = 60, .hw_value = 12, }, |
| 355 | { .bitrate = 90, .hw_value = 18, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 356 | { .bitrate = 120, .hw_value = 24, }, |
| 357 | { .bitrate = 180, .hw_value = 36, }, |
| 358 | { .bitrate = 240, .hw_value = 48, }, |
| 359 | { .bitrate = 360, .hw_value = 72, }, |
| 360 | { .bitrate = 480, .hw_value = 96, }, |
| 361 | { .bitrate = 540, .hw_value = 108, }, |
Lennert Buytenhek | 140eb5e | 2009-11-30 18:11:44 +0100 | [diff] [blame] | 362 | { .bitrate = 720, .hw_value = 144, }, |
| 363 | }; |
| 364 | |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 365 | static const struct ieee80211_channel mwl8k_channels_50[] = { |
| 366 | { .center_freq = 5180, .hw_value = 36, }, |
| 367 | { .center_freq = 5200, .hw_value = 40, }, |
| 368 | { .center_freq = 5220, .hw_value = 44, }, |
| 369 | { .center_freq = 5240, .hw_value = 48, }, |
| 370 | }; |
| 371 | |
| 372 | static const struct ieee80211_rate mwl8k_rates_50[] = { |
| 373 | { .bitrate = 60, .hw_value = 12, }, |
| 374 | { .bitrate = 90, .hw_value = 18, }, |
| 375 | { .bitrate = 120, .hw_value = 24, }, |
| 376 | { .bitrate = 180, .hw_value = 36, }, |
| 377 | { .bitrate = 240, .hw_value = 48, }, |
| 378 | { .bitrate = 360, .hw_value = 72, }, |
| 379 | { .bitrate = 480, .hw_value = 96, }, |
| 380 | { .bitrate = 540, .hw_value = 108, }, |
| 381 | { .bitrate = 720, .hw_value = 144, }, |
| 382 | }; |
| 383 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 384 | /* Set or get info from Firmware */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 385 | #define MWL8K_CMD_GET 0x0000 |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 386 | #define MWL8K_CMD_SET 0x0001 |
| 387 | #define MWL8K_CMD_SET_LIST 0x0002 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 388 | |
| 389 | /* Firmware command codes */ |
| 390 | #define MWL8K_CMD_CODE_DNLD 0x0001 |
| 391 | #define MWL8K_CMD_GET_HW_SPEC 0x0003 |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 392 | #define MWL8K_CMD_SET_HW_SPEC 0x0004 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 393 | #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010 |
| 394 | #define MWL8K_CMD_GET_STAT 0x0014 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 395 | #define MWL8K_CMD_RADIO_CONTROL 0x001c |
| 396 | #define MWL8K_CMD_RF_TX_POWER 0x001e |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 397 | #define MWL8K_CMD_TX_POWER 0x001f |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 398 | #define MWL8K_CMD_RF_ANTENNA 0x0020 |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 399 | #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 400 | #define MWL8K_CMD_SET_PRE_SCAN 0x0107 |
| 401 | #define MWL8K_CMD_SET_POST_SCAN 0x0108 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 402 | #define MWL8K_CMD_SET_RF_CHANNEL 0x010a |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 403 | #define MWL8K_CMD_SET_AID 0x010d |
| 404 | #define MWL8K_CMD_SET_RATE 0x0110 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 405 | #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 406 | #define MWL8K_CMD_RTS_THRESHOLD 0x0113 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 407 | #define MWL8K_CMD_SET_SLOT 0x0114 |
| 408 | #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115 |
| 409 | #define MWL8K_CMD_SET_WMM_MODE 0x0123 |
| 410 | #define MWL8K_CMD_MIMO_CONFIG 0x0125 |
| 411 | #define MWL8K_CMD_USE_FIXED_RATE 0x0126 |
| 412 | #define MWL8K_CMD_ENABLE_SNIFFER 0x0150 |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 413 | #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */ |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 414 | #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203 |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 415 | #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205 |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 416 | #define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */ |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 417 | #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */ |
| 418 | #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */ |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 419 | #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */ |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 420 | #define MWL8K_CMD_UPDATE_STADB 0x1123 |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 421 | #define MWL8K_CMD_BASTREAM 0x1125 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 422 | |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 423 | static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 424 | { |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 425 | u16 command = le16_to_cpu(cmd); |
| 426 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 427 | #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\ |
| 428 | snprintf(buf, bufsize, "%s", #x);\ |
| 429 | return buf;\ |
| 430 | } while (0) |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 431 | switch (command & ~0x8000) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 432 | MWL8K_CMDNAME(CODE_DNLD); |
| 433 | MWL8K_CMDNAME(GET_HW_SPEC); |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 434 | MWL8K_CMDNAME(SET_HW_SPEC); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 435 | MWL8K_CMDNAME(MAC_MULTICAST_ADR); |
| 436 | MWL8K_CMDNAME(GET_STAT); |
| 437 | MWL8K_CMDNAME(RADIO_CONTROL); |
| 438 | MWL8K_CMDNAME(RF_TX_POWER); |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 439 | MWL8K_CMDNAME(TX_POWER); |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 440 | MWL8K_CMDNAME(RF_ANTENNA); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 441 | MWL8K_CMDNAME(SET_BEACON); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 442 | MWL8K_CMDNAME(SET_PRE_SCAN); |
| 443 | MWL8K_CMDNAME(SET_POST_SCAN); |
| 444 | MWL8K_CMDNAME(SET_RF_CHANNEL); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 445 | MWL8K_CMDNAME(SET_AID); |
| 446 | MWL8K_CMDNAME(SET_RATE); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 447 | MWL8K_CMDNAME(SET_FINALIZE_JOIN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 448 | MWL8K_CMDNAME(RTS_THRESHOLD); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 449 | MWL8K_CMDNAME(SET_SLOT); |
| 450 | MWL8K_CMDNAME(SET_EDCA_PARAMS); |
| 451 | MWL8K_CMDNAME(SET_WMM_MODE); |
| 452 | MWL8K_CMDNAME(MIMO_CONFIG); |
| 453 | MWL8K_CMDNAME(USE_FIXED_RATE); |
| 454 | MWL8K_CMDNAME(ENABLE_SNIFFER); |
Lennert Buytenhek | 32060e1 | 2009-10-22 20:20:04 +0200 | [diff] [blame] | 455 | MWL8K_CMDNAME(SET_MAC_ADDR); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 456 | MWL8K_CMDNAME(SET_RATEADAPT_MODE); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 457 | MWL8K_CMDNAME(BSS_START); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 458 | MWL8K_CMDNAME(SET_NEW_STN); |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 459 | MWL8K_CMDNAME(UPDATE_ENCRYPTION); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 460 | MWL8K_CMDNAME(UPDATE_STADB); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 461 | MWL8K_CMDNAME(BASTREAM); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 462 | MWL8K_CMDNAME(GET_WATCHDOG_BITMAP); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 463 | default: |
| 464 | snprintf(buf, bufsize, "0x%x", cmd); |
| 465 | } |
| 466 | #undef MWL8K_CMDNAME |
| 467 | |
| 468 | return buf; |
| 469 | } |
| 470 | |
| 471 | /* Hardware and firmware reset */ |
| 472 | static void mwl8k_hw_reset(struct mwl8k_priv *priv) |
| 473 | { |
| 474 | iowrite32(MWL8K_H2A_INT_RESET, |
| 475 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 476 | iowrite32(MWL8K_H2A_INT_RESET, |
| 477 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 478 | msleep(20); |
| 479 | } |
| 480 | |
| 481 | /* Release fw image */ |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 482 | static void mwl8k_release_fw(const struct firmware **fw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 483 | { |
| 484 | if (*fw == NULL) |
| 485 | return; |
| 486 | release_firmware(*fw); |
| 487 | *fw = NULL; |
| 488 | } |
| 489 | |
| 490 | static void mwl8k_release_firmware(struct mwl8k_priv *priv) |
| 491 | { |
Lennert Buytenhek | 22be40d | 2009-11-30 18:32:38 +0100 | [diff] [blame] | 492 | mwl8k_release_fw(&priv->fw_ucode); |
| 493 | mwl8k_release_fw(&priv->fw_helper); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 494 | } |
| 495 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 496 | /* states for asynchronous f/w loading */ |
| 497 | static void mwl8k_fw_state_machine(const struct firmware *fw, void *context); |
| 498 | enum { |
| 499 | FW_STATE_INIT = 0, |
| 500 | FW_STATE_LOADING_PREF, |
| 501 | FW_STATE_LOADING_ALT, |
| 502 | FW_STATE_ERROR, |
| 503 | }; |
| 504 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 505 | /* Request fw image */ |
| 506 | static int mwl8k_request_fw(struct mwl8k_priv *priv, |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 507 | const char *fname, const struct firmware **fw, |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 508 | bool nowait) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 509 | { |
| 510 | /* release current image */ |
| 511 | if (*fw != NULL) |
| 512 | mwl8k_release_fw(fw); |
| 513 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 514 | if (nowait) |
| 515 | return request_firmware_nowait(THIS_MODULE, 1, fname, |
| 516 | &priv->pdev->dev, GFP_KERNEL, |
| 517 | priv, mwl8k_fw_state_machine); |
| 518 | else |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 519 | return request_firmware(fw, fname, &priv->pdev->dev); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 520 | } |
| 521 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 522 | static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image, |
| 523 | bool nowait) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 524 | { |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 525 | struct mwl8k_device_info *di = priv->device_info; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 526 | int rc; |
| 527 | |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 528 | if (di->helper_image != NULL) { |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 529 | if (nowait) |
| 530 | rc = mwl8k_request_fw(priv, di->helper_image, |
| 531 | &priv->fw_helper, true); |
| 532 | else |
| 533 | rc = mwl8k_request_fw(priv, di->helper_image, |
| 534 | &priv->fw_helper, false); |
| 535 | if (rc) |
| 536 | printk(KERN_ERR "%s: Error requesting helper fw %s\n", |
| 537 | pci_name(priv->pdev), di->helper_image); |
| 538 | |
| 539 | if (rc || nowait) |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 540 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 543 | if (nowait) { |
| 544 | /* |
| 545 | * if we get here, no helper image is needed. Skip the |
| 546 | * FW_STATE_INIT state. |
| 547 | */ |
| 548 | priv->fw_state = FW_STATE_LOADING_PREF; |
| 549 | rc = mwl8k_request_fw(priv, fw_image, |
| 550 | &priv->fw_ucode, |
| 551 | true); |
| 552 | } else |
| 553 | rc = mwl8k_request_fw(priv, fw_image, |
| 554 | &priv->fw_ucode, false); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 555 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 556 | printk(KERN_ERR "%s: Error requesting firmware file %s\n", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 557 | pci_name(priv->pdev), fw_image); |
Lennert Buytenhek | 22be40d | 2009-11-30 18:32:38 +0100 | [diff] [blame] | 558 | mwl8k_release_fw(&priv->fw_helper); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 559 | return rc; |
| 560 | } |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | struct mwl8k_cmd_pkt { |
| 566 | __le16 code; |
| 567 | __le16 length; |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 568 | __u8 seq_num; |
| 569 | __u8 macid; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 570 | __le16 result; |
| 571 | char payload[0]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 572 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 573 | |
| 574 | /* |
| 575 | * Firmware loading. |
| 576 | */ |
| 577 | static int |
| 578 | mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length) |
| 579 | { |
| 580 | void __iomem *regs = priv->regs; |
| 581 | dma_addr_t dma_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 582 | int loops; |
| 583 | |
| 584 | dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE); |
| 585 | if (pci_dma_mapping_error(priv->pdev, dma_addr)) |
| 586 | return -ENOMEM; |
| 587 | |
| 588 | iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR); |
| 589 | iowrite32(0, regs + MWL8K_HIU_INT_CODE); |
| 590 | iowrite32(MWL8K_H2A_INT_DOORBELL, |
| 591 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 592 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 593 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 594 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 595 | loops = 1000; |
| 596 | do { |
| 597 | u32 int_code; |
| 598 | |
| 599 | int_code = ioread32(regs + MWL8K_HIU_INT_CODE); |
| 600 | if (int_code == MWL8K_INT_CODE_CMD_FINISHED) { |
| 601 | iowrite32(0, regs + MWL8K_HIU_INT_CODE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 602 | break; |
| 603 | } |
| 604 | |
Lennert Buytenhek | 3d76e82 | 2009-10-22 20:20:16 +0200 | [diff] [blame] | 605 | cond_resched(); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 606 | udelay(1); |
| 607 | } while (--loops); |
| 608 | |
| 609 | pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE); |
| 610 | |
Lennert Buytenhek | d4b7057 | 2009-07-16 12:44:45 +0200 | [diff] [blame] | 611 | return loops ? 0 : -ETIMEDOUT; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static int mwl8k_load_fw_image(struct mwl8k_priv *priv, |
| 615 | const u8 *data, size_t length) |
| 616 | { |
| 617 | struct mwl8k_cmd_pkt *cmd; |
| 618 | int done; |
| 619 | int rc = 0; |
| 620 | |
| 621 | cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL); |
| 622 | if (cmd == NULL) |
| 623 | return -ENOMEM; |
| 624 | |
| 625 | cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD); |
| 626 | cmd->seq_num = 0; |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 627 | cmd->macid = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 628 | cmd->result = 0; |
| 629 | |
| 630 | done = 0; |
| 631 | while (length) { |
| 632 | int block_size = length > 256 ? 256 : length; |
| 633 | |
| 634 | memcpy(cmd->payload, data + done, block_size); |
| 635 | cmd->length = cpu_to_le16(block_size); |
| 636 | |
| 637 | rc = mwl8k_send_fw_load_cmd(priv, cmd, |
| 638 | sizeof(*cmd) + block_size); |
| 639 | if (rc) |
| 640 | break; |
| 641 | |
| 642 | done += block_size; |
| 643 | length -= block_size; |
| 644 | } |
| 645 | |
| 646 | if (!rc) { |
| 647 | cmd->length = 0; |
| 648 | rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd)); |
| 649 | } |
| 650 | |
| 651 | kfree(cmd); |
| 652 | |
| 653 | return rc; |
| 654 | } |
| 655 | |
| 656 | static int mwl8k_feed_fw_image(struct mwl8k_priv *priv, |
| 657 | const u8 *data, size_t length) |
| 658 | { |
| 659 | unsigned char *buffer; |
| 660 | int may_continue, rc = 0; |
| 661 | u32 done, prev_block_size; |
| 662 | |
| 663 | buffer = kmalloc(1024, GFP_KERNEL); |
| 664 | if (buffer == NULL) |
| 665 | return -ENOMEM; |
| 666 | |
| 667 | done = 0; |
| 668 | prev_block_size = 0; |
| 669 | may_continue = 1000; |
| 670 | while (may_continue > 0) { |
| 671 | u32 block_size; |
| 672 | |
| 673 | block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH); |
| 674 | if (block_size & 1) { |
| 675 | block_size &= ~1; |
| 676 | may_continue--; |
| 677 | } else { |
| 678 | done += prev_block_size; |
| 679 | length -= prev_block_size; |
| 680 | } |
| 681 | |
| 682 | if (block_size > 1024 || block_size > length) { |
| 683 | rc = -EOVERFLOW; |
| 684 | break; |
| 685 | } |
| 686 | |
| 687 | if (length == 0) { |
| 688 | rc = 0; |
| 689 | break; |
| 690 | } |
| 691 | |
| 692 | if (block_size == 0) { |
| 693 | rc = -EPROTO; |
| 694 | may_continue--; |
| 695 | udelay(1); |
| 696 | continue; |
| 697 | } |
| 698 | |
| 699 | prev_block_size = block_size; |
| 700 | memcpy(buffer, data + done, block_size); |
| 701 | |
| 702 | rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size); |
| 703 | if (rc) |
| 704 | break; |
| 705 | } |
| 706 | |
| 707 | if (!rc && length != 0) |
| 708 | rc = -EREMOTEIO; |
| 709 | |
| 710 | kfree(buffer); |
| 711 | |
| 712 | return rc; |
| 713 | } |
| 714 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 715 | static int mwl8k_load_firmware(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 716 | { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 717 | struct mwl8k_priv *priv = hw->priv; |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 718 | const struct firmware *fw = priv->fw_ucode; |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 719 | int rc; |
| 720 | int loops; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 721 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 722 | if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) { |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 723 | const struct firmware *helper = priv->fw_helper; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 724 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 725 | if (helper == NULL) { |
| 726 | printk(KERN_ERR "%s: helper image needed but none " |
| 727 | "given\n", pci_name(priv->pdev)); |
| 728 | return -EINVAL; |
| 729 | } |
| 730 | |
| 731 | rc = mwl8k_load_fw_image(priv, helper->data, helper->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 732 | if (rc) { |
| 733 | printk(KERN_ERR "%s: unable to load firmware " |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 734 | "helper image\n", pci_name(priv->pdev)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 735 | return rc; |
| 736 | } |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 737 | msleep(20); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 738 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 739 | rc = mwl8k_feed_fw_image(priv, fw->data, fw->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 740 | } else { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 741 | rc = mwl8k_load_fw_image(priv, fw->data, fw->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 745 | printk(KERN_ERR "%s: unable to load firmware image\n", |
| 746 | pci_name(priv->pdev)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 747 | return rc; |
| 748 | } |
| 749 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 750 | iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 751 | |
Lennert Buytenhek | 89b872e | 2009-11-30 18:13:20 +0100 | [diff] [blame] | 752 | loops = 500000; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 753 | do { |
Lennert Buytenhek | eae74e6 | 2009-10-22 20:20:53 +0200 | [diff] [blame] | 754 | u32 ready_code; |
| 755 | |
| 756 | ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE); |
| 757 | if (ready_code == MWL8K_FWAP_READY) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 758 | priv->ap_fw = true; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 759 | break; |
Lennert Buytenhek | eae74e6 | 2009-10-22 20:20:53 +0200 | [diff] [blame] | 760 | } else if (ready_code == MWL8K_FWSTA_READY) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 761 | priv->ap_fw = false; |
Lennert Buytenhek | eae74e6 | 2009-10-22 20:20:53 +0200 | [diff] [blame] | 762 | break; |
| 763 | } |
| 764 | |
| 765 | cond_resched(); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 766 | udelay(1); |
| 767 | } while (--loops); |
| 768 | |
| 769 | return loops ? 0 : -ETIMEDOUT; |
| 770 | } |
| 771 | |
| 772 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 773 | /* DMA header used by firmware and hardware. */ |
| 774 | struct mwl8k_dma_data { |
| 775 | __le16 fwlen; |
| 776 | struct ieee80211_hdr wh; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 777 | char data[0]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 778 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 779 | |
| 780 | /* Routines to add/remove DMA header from skb. */ |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 781 | 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] | 782 | { |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 783 | struct mwl8k_dma_data *tr; |
| 784 | int hdrlen; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 785 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 786 | tr = (struct mwl8k_dma_data *)skb->data; |
| 787 | hdrlen = ieee80211_hdrlen(tr->wh.frame_control); |
| 788 | |
| 789 | if (hdrlen != sizeof(tr->wh)) { |
| 790 | if (ieee80211_is_data_qos(tr->wh.frame_control)) { |
| 791 | memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2); |
| 792 | *((__le16 *)(tr->data - 2)) = qos; |
| 793 | } else { |
| 794 | memmove(tr->data - hdrlen, &tr->wh, hdrlen); |
| 795 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 796 | } |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 797 | |
| 798 | if (hdrlen != sizeof(*tr)) |
| 799 | skb_pull(skb, sizeof(*tr) - hdrlen); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 800 | } |
| 801 | |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 802 | #define REDUCED_TX_HEADROOM 8 |
| 803 | |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 804 | static void |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 805 | mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb, |
| 806 | int head_pad, int tail_pad) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 807 | { |
| 808 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 809 | int hdrlen; |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 810 | int reqd_hdrlen; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 811 | struct mwl8k_dma_data *tr; |
| 812 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 813 | /* |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 814 | * Add a firmware DMA header; the firmware requires that we |
| 815 | * present a 2-byte payload length followed by a 4-address |
| 816 | * header (without QoS field), followed (optionally) by any |
| 817 | * WEP/ExtIV header (but only filled in for CCMP). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 818 | */ |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 819 | wh = (struct ieee80211_hdr *)skb->data; |
| 820 | |
| 821 | hdrlen = ieee80211_hdrlen(wh->frame_control); |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 822 | |
| 823 | /* |
| 824 | * Check if skb_resize is required because of |
| 825 | * tx_headroom adjustment. |
| 826 | */ |
| 827 | if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts) |
| 828 | + REDUCED_TX_HEADROOM))) { |
| 829 | if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) { |
| 830 | |
| 831 | wiphy_err(priv->hw->wiphy, |
| 832 | "Failed to reallocate TX buffer\n"); |
| 833 | return; |
| 834 | } |
| 835 | skb->truesize += REDUCED_TX_HEADROOM; |
| 836 | } |
| 837 | |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 838 | reqd_hdrlen = sizeof(*tr) + head_pad; |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 839 | |
| 840 | if (hdrlen != reqd_hdrlen) |
| 841 | skb_push(skb, reqd_hdrlen - hdrlen); |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 842 | |
| 843 | if (ieee80211_is_data_qos(wh->frame_control)) |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 844 | hdrlen -= IEEE80211_QOS_CTL_LEN; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 845 | |
| 846 | tr = (struct mwl8k_dma_data *)skb->data; |
| 847 | if (wh != &tr->wh) |
| 848 | memmove(&tr->wh, wh, hdrlen); |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 849 | if (hdrlen != sizeof(tr->wh)) |
| 850 | memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 851 | |
| 852 | /* |
| 853 | * Firmware length is the length of the fully formed "802.11 |
| 854 | * payload". That is, everything except for the 802.11 header. |
| 855 | * This includes all crypto material including the MIC. |
| 856 | */ |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 857 | tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 858 | } |
| 859 | |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 860 | static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv, |
| 861 | struct sk_buff *skb) |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 862 | { |
| 863 | struct ieee80211_hdr *wh; |
| 864 | struct ieee80211_tx_info *tx_info; |
| 865 | struct ieee80211_key_conf *key_conf; |
| 866 | int data_pad; |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 867 | int head_pad = 0; |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 868 | |
| 869 | wh = (struct ieee80211_hdr *)skb->data; |
| 870 | |
| 871 | tx_info = IEEE80211_SKB_CB(skb); |
| 872 | |
| 873 | key_conf = NULL; |
| 874 | if (ieee80211_is_data(wh->frame_control)) |
| 875 | key_conf = tx_info->control.hw_key; |
| 876 | |
| 877 | /* |
| 878 | * Make sure the packet header is in the DMA header format (4-address |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 879 | * without QoS), and add head & tail padding when HW crypto is enabled. |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 880 | * |
| 881 | * We have the following trailer padding requirements: |
| 882 | * - WEP: 4 trailer bytes (ICV) |
| 883 | * - TKIP: 12 trailer bytes (8 MIC + 4 ICV) |
| 884 | * - CCMP: 8 trailer bytes (MIC) |
| 885 | */ |
| 886 | data_pad = 0; |
| 887 | if (key_conf != NULL) { |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 888 | head_pad = key_conf->iv_len; |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 889 | switch (key_conf->cipher) { |
| 890 | case WLAN_CIPHER_SUITE_WEP40: |
| 891 | case WLAN_CIPHER_SUITE_WEP104: |
| 892 | data_pad = 4; |
| 893 | break; |
| 894 | case WLAN_CIPHER_SUITE_TKIP: |
| 895 | data_pad = 12; |
| 896 | break; |
| 897 | case WLAN_CIPHER_SUITE_CCMP: |
| 898 | data_pad = 8; |
| 899 | break; |
| 900 | } |
| 901 | } |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 902 | mwl8k_add_dma_header(priv, skb, head_pad, data_pad); |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 903 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 904 | |
| 905 | /* |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 906 | * Packet reception for 88w8366 AP firmware. |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 907 | */ |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 908 | struct mwl8k_rxd_8366_ap { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 909 | __le16 pkt_len; |
| 910 | __u8 sq2; |
| 911 | __u8 rate; |
| 912 | __le32 pkt_phys_addr; |
| 913 | __le32 next_rxd_phys_addr; |
| 914 | __le16 qos_control; |
| 915 | __le16 htsig2; |
| 916 | __le32 hw_rssi_info; |
| 917 | __le32 hw_noise_floor_info; |
| 918 | __u8 noise_floor; |
| 919 | __u8 pad0[3]; |
| 920 | __u8 rssi; |
| 921 | __u8 rx_status; |
| 922 | __u8 channel; |
| 923 | __u8 rx_ctrl; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 924 | } __packed; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 925 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 926 | #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80 |
| 927 | #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40 |
| 928 | #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f) |
Lennert Buytenhek | 8e9f33f | 2009-11-30 18:12:35 +0100 | [diff] [blame] | 929 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 930 | #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80 |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 931 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 932 | /* 8366 AP rx_status bits */ |
| 933 | #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80 |
| 934 | #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF |
| 935 | #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02 |
| 936 | #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04 |
| 937 | #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08 |
| 938 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 939 | static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 940 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 941 | struct mwl8k_rxd_8366_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 942 | |
| 943 | rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr); |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 944 | rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 945 | } |
| 946 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 947 | static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 948 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 949 | struct mwl8k_rxd_8366_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 950 | |
| 951 | rxd->pkt_len = cpu_to_le16(len); |
| 952 | rxd->pkt_phys_addr = cpu_to_le32(addr); |
| 953 | wmb(); |
| 954 | rxd->rx_ctrl = 0; |
| 955 | } |
| 956 | |
| 957 | static int |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 958 | mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 959 | __le16 *qos, s8 *noise) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 960 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 961 | struct mwl8k_rxd_8366_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 962 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 963 | if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST)) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 964 | return -1; |
| 965 | rmb(); |
| 966 | |
| 967 | memset(status, 0, sizeof(*status)); |
| 968 | |
| 969 | status->signal = -rxd->rssi; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 970 | *noise = -rxd->noise_floor; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 971 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 972 | if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 973 | status->flag |= RX_FLAG_HT; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 974 | if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ) |
Lennert Buytenhek | 8e9f33f | 2009-11-30 18:12:35 +0100 | [diff] [blame] | 975 | status->flag |= RX_FLAG_40MHZ; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 976 | status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate); |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 977 | } else { |
| 978 | int i; |
| 979 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 980 | for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) { |
| 981 | if (mwl8k_rates_24[i].hw_value == rxd->rate) { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 982 | status->rate_idx = i; |
| 983 | break; |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | |
Lennert Buytenhek | 8547834 | 2010-01-12 13:48:56 +0100 | [diff] [blame] | 988 | if (rxd->channel > 14) { |
| 989 | status->band = IEEE80211_BAND_5GHZ; |
| 990 | if (!(status->flag & RX_FLAG_HT)) |
| 991 | status->rate_idx -= 5; |
| 992 | } else { |
| 993 | status->band = IEEE80211_BAND_2GHZ; |
| 994 | } |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 995 | status->freq = ieee80211_channel_to_frequency(rxd->channel, |
| 996 | status->band); |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 997 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 998 | *qos = rxd->qos_control; |
| 999 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1000 | if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) && |
| 1001 | (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) && |
| 1002 | (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR)) |
| 1003 | status->flag |= RX_FLAG_MMIC_ERROR; |
| 1004 | |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 1005 | return le16_to_cpu(rxd->pkt_len); |
| 1006 | } |
| 1007 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1008 | static struct rxd_ops rxd_8366_ap_ops = { |
| 1009 | .rxd_size = sizeof(struct mwl8k_rxd_8366_ap), |
| 1010 | .rxd_init = mwl8k_rxd_8366_ap_init, |
| 1011 | .rxd_refill = mwl8k_rxd_8366_ap_refill, |
| 1012 | .rxd_process = mwl8k_rxd_8366_ap_process, |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 1013 | }; |
| 1014 | |
| 1015 | /* |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1016 | * Packet reception for STA firmware. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1017 | */ |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1018 | struct mwl8k_rxd_sta { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1019 | __le16 pkt_len; |
| 1020 | __u8 link_quality; |
| 1021 | __u8 noise_level; |
| 1022 | __le32 pkt_phys_addr; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1023 | __le32 next_rxd_phys_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1024 | __le16 qos_control; |
| 1025 | __le16 rate_info; |
| 1026 | __le32 pad0[4]; |
| 1027 | __u8 rssi; |
| 1028 | __u8 channel; |
| 1029 | __le16 pad1; |
| 1030 | __u8 rx_ctrl; |
| 1031 | __u8 rx_status; |
| 1032 | __u8 pad2[2]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 1033 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1034 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1035 | #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000 |
| 1036 | #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3) |
| 1037 | #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f) |
| 1038 | #define MWL8K_STA_RATE_INFO_40MHZ 0x0004 |
| 1039 | #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002 |
| 1040 | #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001 |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1041 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1042 | #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02 |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1043 | #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04 |
| 1044 | /* ICV=0 or MIC=1 */ |
| 1045 | #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08 |
| 1046 | /* Key is uploaded only in failure case */ |
| 1047 | #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30 |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1048 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1049 | static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1050 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1051 | struct mwl8k_rxd_sta *rxd = _rxd; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1052 | |
| 1053 | rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr); |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1054 | rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1055 | } |
| 1056 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1057 | static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1058 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1059 | struct mwl8k_rxd_sta *rxd = _rxd; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1060 | |
| 1061 | rxd->pkt_len = cpu_to_le16(len); |
| 1062 | rxd->pkt_phys_addr = cpu_to_le32(addr); |
| 1063 | wmb(); |
| 1064 | rxd->rx_ctrl = 0; |
| 1065 | } |
| 1066 | |
| 1067 | static int |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1068 | mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1069 | __le16 *qos, s8 *noise) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1070 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1071 | struct mwl8k_rxd_sta *rxd = _rxd; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1072 | u16 rate_info; |
| 1073 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1074 | if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST)) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1075 | return -1; |
| 1076 | rmb(); |
| 1077 | |
| 1078 | rate_info = le16_to_cpu(rxd->rate_info); |
| 1079 | |
| 1080 | memset(status, 0, sizeof(*status)); |
| 1081 | |
| 1082 | status->signal = -rxd->rssi; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1083 | *noise = -rxd->noise_level; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1084 | status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info); |
| 1085 | status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1086 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1087 | if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1088 | status->flag |= RX_FLAG_SHORTPRE; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1089 | if (rate_info & MWL8K_STA_RATE_INFO_40MHZ) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1090 | status->flag |= RX_FLAG_40MHZ; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1091 | if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1092 | status->flag |= RX_FLAG_SHORT_GI; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1093 | if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1094 | status->flag |= RX_FLAG_HT; |
| 1095 | |
Lennert Buytenhek | 8547834 | 2010-01-12 13:48:56 +0100 | [diff] [blame] | 1096 | if (rxd->channel > 14) { |
| 1097 | status->band = IEEE80211_BAND_5GHZ; |
| 1098 | if (!(status->flag & RX_FLAG_HT)) |
| 1099 | status->rate_idx -= 5; |
| 1100 | } else { |
| 1101 | status->band = IEEE80211_BAND_2GHZ; |
| 1102 | } |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 1103 | status->freq = ieee80211_channel_to_frequency(rxd->channel, |
| 1104 | status->band); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1105 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1106 | *qos = rxd->qos_control; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1107 | if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) && |
| 1108 | (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE)) |
| 1109 | status->flag |= RX_FLAG_MMIC_ERROR; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1110 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1111 | return le16_to_cpu(rxd->pkt_len); |
| 1112 | } |
| 1113 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1114 | static struct rxd_ops rxd_sta_ops = { |
| 1115 | .rxd_size = sizeof(struct mwl8k_rxd_sta), |
| 1116 | .rxd_init = mwl8k_rxd_sta_init, |
| 1117 | .rxd_refill = mwl8k_rxd_sta_refill, |
| 1118 | .rxd_process = mwl8k_rxd_sta_process, |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1119 | }; |
| 1120 | |
| 1121 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1122 | #define MWL8K_RX_DESCS 256 |
| 1123 | #define MWL8K_RX_MAXSZ 3800 |
| 1124 | |
| 1125 | static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index) |
| 1126 | { |
| 1127 | struct mwl8k_priv *priv = hw->priv; |
| 1128 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1129 | int size; |
| 1130 | int i; |
| 1131 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1132 | rxq->rxd_count = 0; |
| 1133 | rxq->head = 0; |
| 1134 | rxq->tail = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1135 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1136 | size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1137 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1138 | rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma); |
| 1139 | if (rxq->rxd == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1140 | wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1141 | return -ENOMEM; |
| 1142 | } |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1143 | memset(rxq->rxd, 0, size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1144 | |
Shan Wei | b9ede5f | 2011-03-08 11:02:03 +0800 | [diff] [blame] | 1145 | rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL); |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1146 | if (rxq->buf == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1147 | wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n"); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1148 | pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1149 | return -ENOMEM; |
| 1150 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1151 | |
| 1152 | for (i = 0; i < MWL8K_RX_DESCS; i++) { |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1153 | int desc_size; |
| 1154 | void *rxd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1155 | int nexti; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1156 | dma_addr_t next_dma_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1157 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1158 | desc_size = priv->rxd_ops->rxd_size; |
| 1159 | rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1160 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1161 | nexti = i + 1; |
| 1162 | if (nexti == MWL8K_RX_DESCS) |
| 1163 | nexti = 0; |
| 1164 | next_dma_addr = rxq->rxd_dma + (nexti * desc_size); |
| 1165 | |
| 1166 | priv->rxd_ops->rxd_init(rxd, next_dma_addr); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | static int rxq_refill(struct ieee80211_hw *hw, int index, int limit) |
| 1173 | { |
| 1174 | struct mwl8k_priv *priv = hw->priv; |
| 1175 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1176 | int refilled; |
| 1177 | |
| 1178 | refilled = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1179 | while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1180 | struct sk_buff *skb; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1181 | dma_addr_t addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1182 | int rx; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1183 | void *rxd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1184 | |
| 1185 | skb = dev_alloc_skb(MWL8K_RX_MAXSZ); |
| 1186 | if (skb == NULL) |
| 1187 | break; |
| 1188 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1189 | addr = pci_map_single(priv->pdev, skb->data, |
| 1190 | MWL8K_RX_MAXSZ, DMA_FROM_DEVICE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1191 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1192 | rxq->rxd_count++; |
| 1193 | rx = rxq->tail++; |
| 1194 | if (rxq->tail == MWL8K_RX_DESCS) |
| 1195 | rxq->tail = 0; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1196 | rxq->buf[rx].skb = skb; |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1197 | dma_unmap_addr_set(&rxq->buf[rx], dma, addr); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1198 | |
| 1199 | rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size); |
| 1200 | priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1201 | |
| 1202 | refilled++; |
| 1203 | } |
| 1204 | |
| 1205 | return refilled; |
| 1206 | } |
| 1207 | |
| 1208 | /* Must be called only when the card's reception is completely halted */ |
| 1209 | static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index) |
| 1210 | { |
| 1211 | struct mwl8k_priv *priv = hw->priv; |
| 1212 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1213 | int i; |
| 1214 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 1215 | if (rxq->rxd == NULL) |
| 1216 | return; |
| 1217 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1218 | for (i = 0; i < MWL8K_RX_DESCS; i++) { |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1219 | if (rxq->buf[i].skb != NULL) { |
| 1220 | pci_unmap_single(priv->pdev, |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1221 | dma_unmap_addr(&rxq->buf[i], dma), |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1222 | MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1223 | dma_unmap_addr_set(&rxq->buf[i], dma, 0); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1224 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1225 | kfree_skb(rxq->buf[i].skb); |
| 1226 | rxq->buf[i].skb = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1230 | kfree(rxq->buf); |
| 1231 | rxq->buf = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1232 | |
| 1233 | pci_free_consistent(priv->pdev, |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1234 | MWL8K_RX_DESCS * priv->rxd_ops->rxd_size, |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1235 | rxq->rxd, rxq->rxd_dma); |
| 1236 | rxq->rxd = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | /* |
| 1241 | * Scan a list of BSSIDs to process for finalize join. |
| 1242 | * Allows for extension to process multiple BSSIDs. |
| 1243 | */ |
| 1244 | static inline int |
| 1245 | mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh) |
| 1246 | { |
| 1247 | return priv->capture_beacon && |
| 1248 | ieee80211_is_beacon(wh->frame_control) && |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 1249 | ether_addr_equal(wh->addr3, priv->capture_bssid); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1250 | } |
| 1251 | |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1252 | static inline void mwl8k_save_beacon(struct ieee80211_hw *hw, |
| 1253 | struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1254 | { |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1255 | struct mwl8k_priv *priv = hw->priv; |
| 1256 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1257 | priv->capture_beacon = false; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1258 | memset(priv->capture_bssid, 0, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1259 | |
| 1260 | /* |
| 1261 | * Use GFP_ATOMIC as rxq_process is called from |
| 1262 | * the primary interrupt handler, memory allocation call |
| 1263 | * must not sleep. |
| 1264 | */ |
| 1265 | priv->beacon_skb = skb_copy(skb, GFP_ATOMIC); |
| 1266 | if (priv->beacon_skb != NULL) |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1267 | ieee80211_queue_work(hw, &priv->finalize_join_worker); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1268 | } |
| 1269 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1270 | static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list, |
| 1271 | u8 *bssid) |
| 1272 | { |
| 1273 | struct mwl8k_vif *mwl8k_vif; |
| 1274 | |
| 1275 | list_for_each_entry(mwl8k_vif, |
| 1276 | vif_list, list) { |
| 1277 | if (memcmp(bssid, mwl8k_vif->bssid, |
| 1278 | ETH_ALEN) == 0) |
| 1279 | return mwl8k_vif; |
| 1280 | } |
| 1281 | |
| 1282 | return NULL; |
| 1283 | } |
| 1284 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1285 | static int rxq_process(struct ieee80211_hw *hw, int index, int limit) |
| 1286 | { |
| 1287 | struct mwl8k_priv *priv = hw->priv; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1288 | struct mwl8k_vif *mwl8k_vif = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1289 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1290 | int processed; |
| 1291 | |
| 1292 | processed = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1293 | while (rxq->rxd_count && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1294 | struct sk_buff *skb; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1295 | void *rxd; |
| 1296 | int pkt_len; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1297 | struct ieee80211_rx_status status; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1298 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1299 | __le16 qos; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1300 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1301 | skb = rxq->buf[rxq->head].skb; |
Lennert Buytenhek | d25f9f1 | 2009-08-03 21:58:26 +0200 | [diff] [blame] | 1302 | if (skb == NULL) |
| 1303 | break; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1304 | |
| 1305 | rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size); |
| 1306 | |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1307 | pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos, |
| 1308 | &priv->noise); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1309 | if (pkt_len < 0) |
| 1310 | break; |
| 1311 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1312 | rxq->buf[rxq->head].skb = NULL; |
| 1313 | |
| 1314 | pci_unmap_single(priv->pdev, |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1315 | dma_unmap_addr(&rxq->buf[rxq->head], dma), |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1316 | MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1317 | dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1318 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1319 | rxq->head++; |
| 1320 | if (rxq->head == MWL8K_RX_DESCS) |
| 1321 | rxq->head = 0; |
| 1322 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1323 | rxq->rxd_count--; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1324 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1325 | wh = &((struct mwl8k_dma_data *)skb->data)->wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1326 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1327 | /* |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1328 | * Check for a pending join operation. Save a |
| 1329 | * copy of the beacon and schedule a tasklet to |
| 1330 | * send a FINALIZE_JOIN command to the firmware. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1331 | */ |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1332 | if (mwl8k_capture_bssid(priv, (void *)skb->data)) |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1333 | mwl8k_save_beacon(hw, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1334 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1335 | if (ieee80211_has_protected(wh->frame_control)) { |
| 1336 | |
| 1337 | /* Check if hw crypto has been enabled for |
| 1338 | * this bss. If yes, set the status flags |
| 1339 | * accordingly |
| 1340 | */ |
| 1341 | mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list, |
| 1342 | wh->addr1); |
| 1343 | |
| 1344 | if (mwl8k_vif != NULL && |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 1345 | mwl8k_vif->is_hw_crypto_enabled) { |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1346 | /* |
| 1347 | * When MMIC ERROR is encountered |
| 1348 | * by the firmware, payload is |
| 1349 | * dropped and only 32 bytes of |
| 1350 | * mwl8k Firmware header is sent |
| 1351 | * to the host. |
| 1352 | * |
| 1353 | * We need to add four bytes of |
| 1354 | * key information. In it |
| 1355 | * MAC80211 expects keyidx set to |
| 1356 | * 0 for triggering Counter |
| 1357 | * Measure of MMIC failure. |
| 1358 | */ |
| 1359 | if (status.flag & RX_FLAG_MMIC_ERROR) { |
| 1360 | struct mwl8k_dma_data *tr; |
| 1361 | tr = (struct mwl8k_dma_data *)skb->data; |
| 1362 | memset((void *)&(tr->data), 0, 4); |
| 1363 | pkt_len += 4; |
| 1364 | } |
| 1365 | |
| 1366 | if (!ieee80211_is_auth(wh->frame_control)) |
| 1367 | status.flag |= RX_FLAG_IV_STRIPPED | |
| 1368 | RX_FLAG_DECRYPTED | |
| 1369 | RX_FLAG_MMIC_STRIPPED; |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | skb_put(skb, pkt_len); |
| 1374 | mwl8k_remove_dma_header(skb, qos); |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 1375 | memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); |
| 1376 | ieee80211_rx_irqsafe(hw, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1377 | |
| 1378 | processed++; |
| 1379 | } |
| 1380 | |
| 1381 | return processed; |
| 1382 | } |
| 1383 | |
| 1384 | |
| 1385 | /* |
| 1386 | * Packet transmission. |
| 1387 | */ |
| 1388 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1389 | #define MWL8K_TXD_STATUS_OK 0x00000001 |
| 1390 | #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002 |
| 1391 | #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004 |
| 1392 | #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1393 | #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1394 | |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1395 | #define MWL8K_QOS_QLEN_UNSPEC 0xff00 |
| 1396 | #define MWL8K_QOS_ACK_POLICY_MASK 0x0060 |
| 1397 | #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000 |
| 1398 | #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060 |
| 1399 | #define MWL8K_QOS_EOSP 0x0010 |
| 1400 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1401 | struct mwl8k_tx_desc { |
| 1402 | __le32 status; |
| 1403 | __u8 data_rate; |
| 1404 | __u8 tx_priority; |
| 1405 | __le16 qos_control; |
| 1406 | __le32 pkt_phys_addr; |
| 1407 | __le16 pkt_len; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1408 | __u8 dest_MAC_addr[ETH_ALEN]; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1409 | __le32 next_txd_phys_addr; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 1410 | __le32 timestamp; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1411 | __le16 rate_info; |
| 1412 | __u8 peer_id; |
Brian Cavagnolo | a1fe24b | 2010-11-12 17:23:47 -0800 | [diff] [blame] | 1413 | __u8 tx_frag_cnt; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 1414 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1415 | |
| 1416 | #define MWL8K_TX_DESCS 128 |
| 1417 | |
| 1418 | static int mwl8k_txq_init(struct ieee80211_hw *hw, int index) |
| 1419 | { |
| 1420 | struct mwl8k_priv *priv = hw->priv; |
| 1421 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1422 | int size; |
| 1423 | int i; |
| 1424 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1425 | txq->len = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1426 | txq->head = 0; |
| 1427 | txq->tail = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1428 | |
| 1429 | size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc); |
| 1430 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1431 | txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma); |
| 1432 | if (txq->txd == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1433 | wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1434 | return -ENOMEM; |
| 1435 | } |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1436 | memset(txq->txd, 0, size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1437 | |
Shan Wei | b9ede5f | 2011-03-08 11:02:03 +0800 | [diff] [blame] | 1438 | txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1439 | if (txq->skb == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1440 | wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n"); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1441 | pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1442 | return -ENOMEM; |
| 1443 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1444 | |
| 1445 | for (i = 0; i < MWL8K_TX_DESCS; i++) { |
| 1446 | struct mwl8k_tx_desc *tx_desc; |
| 1447 | int nexti; |
| 1448 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1449 | tx_desc = txq->txd + i; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1450 | nexti = (i + 1) % MWL8K_TX_DESCS; |
| 1451 | |
| 1452 | tx_desc->status = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1453 | tx_desc->next_txd_phys_addr = |
| 1454 | cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | static inline void mwl8k_tx_start(struct mwl8k_priv *priv) |
| 1461 | { |
| 1462 | iowrite32(MWL8K_H2A_INT_PPA_READY, |
| 1463 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1464 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 1465 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1466 | ioread32(priv->regs + MWL8K_HIU_INT_CODE); |
| 1467 | } |
| 1468 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1469 | static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1470 | { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1471 | struct mwl8k_priv *priv = hw->priv; |
| 1472 | int i; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1473 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 1474 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1475 | struct mwl8k_tx_queue *txq = priv->txq + i; |
| 1476 | int fw_owned = 0; |
| 1477 | int drv_owned = 0; |
| 1478 | int unused = 0; |
| 1479 | int desc; |
Lennert Buytenhek | c3f967d | 2009-08-18 04:15:22 +0200 | [diff] [blame] | 1480 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1481 | for (desc = 0; desc < MWL8K_TX_DESCS; desc++) { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1482 | struct mwl8k_tx_desc *tx_desc = txq->txd + desc; |
| 1483 | u32 status; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1484 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1485 | status = le32_to_cpu(tx_desc->status); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1486 | if (status & MWL8K_TXD_STATUS_FW_OWNED) |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1487 | fw_owned++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1488 | else |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1489 | drv_owned++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1490 | |
| 1491 | if (tx_desc->pkt_len == 0) |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1492 | unused++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1493 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1494 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1495 | wiphy_err(hw->wiphy, |
| 1496 | "txq[%d] len=%d head=%d tail=%d " |
| 1497 | "fw_owned=%d drv_owned=%d unused=%d\n", |
| 1498 | i, |
| 1499 | txq->len, txq->head, txq->tail, |
| 1500 | fw_owned, drv_owned, unused); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1501 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1502 | } |
| 1503 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1504 | /* |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 1505 | * Must be called with priv->fw_mutex held and tx queues stopped. |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1506 | */ |
Lennert Buytenhek | 62abd3c | 2010-01-08 18:28:34 +0100 | [diff] [blame] | 1507 | #define MWL8K_TX_WAIT_TIMEOUT_MS 5000 |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1508 | |
Lennert Buytenhek | 950d5b0 | 2009-07-17 01:48:41 +0200 | [diff] [blame] | 1509 | static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1510 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1511 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 1512 | DECLARE_COMPLETION_ONSTACK(tx_wait); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1513 | int retry; |
| 1514 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1515 | |
| 1516 | might_sleep(); |
| 1517 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 1518 | /* Since fw restart is in progress, allow only the firmware |
| 1519 | * commands from the restart code and block the other |
| 1520 | * commands since they are going to fail in any case since |
| 1521 | * the firmware has crashed |
| 1522 | */ |
| 1523 | if (priv->hw_restart_in_progress) { |
| 1524 | if (priv->hw_restart_owner == current) |
| 1525 | return 0; |
| 1526 | else |
| 1527 | return -EBUSY; |
| 1528 | } |
| 1529 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1530 | /* |
| 1531 | * The TX queues are stopped at this point, so this test |
| 1532 | * doesn't need to take ->tx_lock. |
| 1533 | */ |
| 1534 | if (!priv->pending_tx_pkts) |
| 1535 | return 0; |
| 1536 | |
| 1537 | retry = 0; |
| 1538 | rc = 0; |
| 1539 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1540 | spin_lock_bh(&priv->tx_lock); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1541 | priv->tx_wait = &tx_wait; |
| 1542 | while (!rc) { |
| 1543 | int oldcount; |
| 1544 | unsigned long timeout; |
| 1545 | |
| 1546 | oldcount = priv->pending_tx_pkts; |
| 1547 | |
| 1548 | spin_unlock_bh(&priv->tx_lock); |
| 1549 | timeout = wait_for_completion_timeout(&tx_wait, |
| 1550 | msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS)); |
| 1551 | spin_lock_bh(&priv->tx_lock); |
| 1552 | |
| 1553 | if (timeout) { |
| 1554 | WARN_ON(priv->pending_tx_pkts); |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 1555 | if (retry) |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1556 | wiphy_notice(hw->wiphy, "tx rings drained\n"); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1557 | break; |
| 1558 | } |
| 1559 | |
| 1560 | if (priv->pending_tx_pkts < oldcount) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1561 | wiphy_notice(hw->wiphy, |
| 1562 | "waiting for tx rings to drain (%d -> %d pkts)\n", |
| 1563 | oldcount, priv->pending_tx_pkts); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1564 | retry = 1; |
| 1565 | continue; |
| 1566 | } |
| 1567 | |
| 1568 | priv->tx_wait = NULL; |
| 1569 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1570 | wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n", |
| 1571 | MWL8K_TX_WAIT_TIMEOUT_MS); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1572 | mwl8k_dump_tx_rings(hw); |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 1573 | priv->hw_restart_in_progress = true; |
| 1574 | ieee80211_queue_work(hw, &priv->fw_reload); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1575 | |
| 1576 | rc = -ETIMEDOUT; |
| 1577 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1578 | spin_unlock_bh(&priv->tx_lock); |
| 1579 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1580 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 1583 | #define MWL8K_TXD_SUCCESS(status) \ |
| 1584 | ((status) & (MWL8K_TXD_STATUS_OK | \ |
| 1585 | MWL8K_TXD_STATUS_OK_RETRY | \ |
| 1586 | MWL8K_TXD_STATUS_OK_MORE_RETRY)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1587 | |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1588 | static int mwl8k_tid_queue_mapping(u8 tid) |
| 1589 | { |
| 1590 | BUG_ON(tid > 7); |
| 1591 | |
| 1592 | switch (tid) { |
| 1593 | case 0: |
| 1594 | case 3: |
| 1595 | return IEEE80211_AC_BE; |
| 1596 | break; |
| 1597 | case 1: |
| 1598 | case 2: |
| 1599 | return IEEE80211_AC_BK; |
| 1600 | break; |
| 1601 | case 4: |
| 1602 | case 5: |
| 1603 | return IEEE80211_AC_VI; |
| 1604 | break; |
| 1605 | case 6: |
| 1606 | case 7: |
| 1607 | return IEEE80211_AC_VO; |
| 1608 | break; |
| 1609 | default: |
| 1610 | return -1; |
| 1611 | break; |
| 1612 | } |
| 1613 | } |
| 1614 | |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1615 | /* The firmware will fill in the rate information |
| 1616 | * for each packet that gets queued in the hardware |
John W. Linville | 49adc5c | 2011-04-27 15:04:28 -0400 | [diff] [blame] | 1617 | * and these macros will interpret that info. |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1618 | */ |
| 1619 | |
John W. Linville | 49adc5c | 2011-04-27 15:04:28 -0400 | [diff] [blame] | 1620 | #define RI_FORMAT(a) (a & 0x0001) |
| 1621 | #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3) |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1622 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1623 | static int |
| 1624 | mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1625 | { |
| 1626 | struct mwl8k_priv *priv = hw->priv; |
| 1627 | struct mwl8k_tx_queue *txq = priv->txq + index; |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1628 | int processed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1629 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1630 | processed = 0; |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1631 | while (txq->len > 0 && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1632 | int tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1633 | struct mwl8k_tx_desc *tx_desc; |
| 1634 | unsigned long addr; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1635 | int size; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1636 | struct sk_buff *skb; |
| 1637 | struct ieee80211_tx_info *info; |
| 1638 | u32 status; |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1639 | struct ieee80211_sta *sta; |
| 1640 | struct mwl8k_sta *sta_info = NULL; |
| 1641 | u16 rate_info; |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1642 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1643 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1644 | tx = txq->head; |
| 1645 | tx_desc = txq->txd + tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1646 | |
| 1647 | status = le32_to_cpu(tx_desc->status); |
| 1648 | |
| 1649 | if (status & MWL8K_TXD_STATUS_FW_OWNED) { |
| 1650 | if (!force) |
| 1651 | break; |
| 1652 | tx_desc->status &= |
| 1653 | ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED); |
| 1654 | } |
| 1655 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1656 | txq->head = (tx + 1) % MWL8K_TX_DESCS; |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1657 | BUG_ON(txq->len == 0); |
| 1658 | txq->len--; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1659 | priv->pending_tx_pkts--; |
| 1660 | |
| 1661 | addr = le32_to_cpu(tx_desc->pkt_phys_addr); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1662 | size = le16_to_cpu(tx_desc->pkt_len); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1663 | skb = txq->skb[tx]; |
| 1664 | txq->skb[tx] = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1665 | |
| 1666 | BUG_ON(skb == NULL); |
| 1667 | pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE); |
| 1668 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1669 | mwl8k_remove_dma_header(skb, tx_desc->qos_control); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1670 | |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1671 | wh = (struct ieee80211_hdr *) skb->data; |
| 1672 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1673 | /* Mark descriptor as unused */ |
| 1674 | tx_desc->pkt_phys_addr = 0; |
| 1675 | tx_desc->pkt_len = 0; |
| 1676 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1677 | info = IEEE80211_SKB_CB(skb); |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1678 | if (ieee80211_is_data(wh->frame_control)) { |
Thomas Huehn | 89e1180 | 2012-07-11 13:21:41 +0200 | [diff] [blame] | 1679 | rcu_read_lock(); |
| 1680 | sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1, |
| 1681 | wh->addr2); |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1682 | if (sta) { |
| 1683 | sta_info = MWL8K_STA(sta); |
| 1684 | BUG_ON(sta_info == NULL); |
| 1685 | rate_info = le16_to_cpu(tx_desc->rate_info); |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1686 | /* If rate is < 6.5 Mpbs for an ht station |
| 1687 | * do not form an ampdu. If the station is a |
| 1688 | * legacy station (format = 0), do not form an |
| 1689 | * ampdu |
| 1690 | */ |
John W. Linville | 49adc5c | 2011-04-27 15:04:28 -0400 | [diff] [blame] | 1691 | if (RI_RATE_ID_MCS(rate_info) < 1 || |
| 1692 | RI_FORMAT(rate_info) == 0) { |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1693 | sta_info->is_ampdu_allowed = false; |
| 1694 | } else { |
| 1695 | sta_info->is_ampdu_allowed = true; |
| 1696 | } |
| 1697 | } |
Thomas Huehn | 89e1180 | 2012-07-11 13:21:41 +0200 | [diff] [blame] | 1698 | rcu_read_unlock(); |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1701 | ieee80211_tx_info_clear_status(info); |
Nishant Sarmukadam | 0bf22c3 | 2011-02-17 14:45:17 -0800 | [diff] [blame] | 1702 | |
| 1703 | /* Rate control is happening in the firmware. |
| 1704 | * Ensure no tx rate is being reported. |
| 1705 | */ |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 1706 | info->status.rates[0].idx = -1; |
| 1707 | info->status.rates[0].count = 1; |
Nishant Sarmukadam | 0bf22c3 | 2011-02-17 14:45:17 -0800 | [diff] [blame] | 1708 | |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1709 | if (MWL8K_TXD_SUCCESS(status)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1710 | info->flags |= IEEE80211_TX_STAT_ACK; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1711 | |
| 1712 | ieee80211_tx_status_irqsafe(hw, skb); |
| 1713 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1714 | processed++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1717 | return processed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | /* must be called only when the card's transmit is completely halted */ |
| 1721 | static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index) |
| 1722 | { |
| 1723 | struct mwl8k_priv *priv = hw->priv; |
| 1724 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1725 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 1726 | if (txq->txd == NULL) |
| 1727 | return; |
| 1728 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1729 | mwl8k_txq_reclaim(hw, index, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1730 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1731 | kfree(txq->skb); |
| 1732 | txq->skb = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1733 | |
| 1734 | pci_free_consistent(priv->pdev, |
| 1735 | MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc), |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1736 | txq->txd, txq->txd_dma); |
| 1737 | txq->txd = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1738 | } |
| 1739 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1740 | /* caller must hold priv->stream_lock when calling the stream functions */ |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 1741 | static struct mwl8k_ampdu_stream * |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1742 | mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid) |
| 1743 | { |
| 1744 | struct mwl8k_ampdu_stream *stream; |
| 1745 | struct mwl8k_priv *priv = hw->priv; |
| 1746 | int i; |
| 1747 | |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame^] | 1748 | for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) { |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1749 | stream = &priv->ampdu[i]; |
| 1750 | if (stream->state == AMPDU_NO_STREAM) { |
| 1751 | stream->sta = sta; |
| 1752 | stream->state = AMPDU_STREAM_NEW; |
| 1753 | stream->tid = tid; |
| 1754 | stream->idx = i; |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1755 | wiphy_debug(hw->wiphy, "Added a new stream for %pM %d", |
| 1756 | sta->addr, tid); |
| 1757 | return stream; |
| 1758 | } |
| 1759 | } |
| 1760 | return NULL; |
| 1761 | } |
| 1762 | |
| 1763 | static int |
| 1764 | mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream) |
| 1765 | { |
| 1766 | int ret; |
| 1767 | |
| 1768 | /* if the stream has already been started, don't start it again */ |
| 1769 | if (stream->state != AMPDU_STREAM_NEW) |
| 1770 | return 0; |
| 1771 | ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0); |
| 1772 | if (ret) |
| 1773 | wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: " |
| 1774 | "%d\n", stream->sta->addr, stream->tid, ret); |
| 1775 | else |
| 1776 | wiphy_debug(hw->wiphy, "Started stream for %pM %d\n", |
| 1777 | stream->sta->addr, stream->tid); |
| 1778 | return ret; |
| 1779 | } |
| 1780 | |
| 1781 | static void |
| 1782 | mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream) |
| 1783 | { |
| 1784 | wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr, |
| 1785 | stream->tid); |
| 1786 | memset(stream, 0, sizeof(*stream)); |
| 1787 | } |
| 1788 | |
| 1789 | static struct mwl8k_ampdu_stream * |
| 1790 | mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid) |
| 1791 | { |
| 1792 | struct mwl8k_priv *priv = hw->priv; |
| 1793 | int i; |
| 1794 | |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame^] | 1795 | for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) { |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1796 | struct mwl8k_ampdu_stream *stream; |
| 1797 | stream = &priv->ampdu[i]; |
| 1798 | if (stream->state == AMPDU_NO_STREAM) |
| 1799 | continue; |
| 1800 | if (!memcmp(stream->sta->addr, addr, ETH_ALEN) && |
| 1801 | stream->tid == tid) |
| 1802 | return stream; |
| 1803 | } |
| 1804 | return NULL; |
| 1805 | } |
| 1806 | |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 1807 | #define MWL8K_AMPDU_PACKET_THRESHOLD 64 |
| 1808 | static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid) |
| 1809 | { |
| 1810 | struct mwl8k_sta *sta_info = MWL8K_STA(sta); |
| 1811 | struct tx_traffic_info *tx_stats; |
| 1812 | |
| 1813 | BUG_ON(tid >= MWL8K_MAX_TID); |
| 1814 | tx_stats = &sta_info->tx_stats[tid]; |
| 1815 | |
| 1816 | return sta_info->is_ampdu_allowed && |
| 1817 | tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD; |
| 1818 | } |
| 1819 | |
| 1820 | static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid) |
| 1821 | { |
| 1822 | struct mwl8k_sta *sta_info = MWL8K_STA(sta); |
| 1823 | struct tx_traffic_info *tx_stats; |
| 1824 | |
| 1825 | BUG_ON(tid >= MWL8K_MAX_TID); |
| 1826 | tx_stats = &sta_info->tx_stats[tid]; |
| 1827 | |
| 1828 | if (tx_stats->start_time == 0) |
| 1829 | tx_stats->start_time = jiffies; |
| 1830 | |
| 1831 | /* reset the packet count after each second elapses. If the number of |
| 1832 | * packets ever exceeds the ampdu_min_traffic threshold, we will allow |
| 1833 | * an ampdu stream to be started. |
| 1834 | */ |
| 1835 | if (jiffies - tx_stats->start_time > HZ) { |
| 1836 | tx_stats->pkts = 0; |
| 1837 | tx_stats->start_time = 0; |
| 1838 | } else |
| 1839 | tx_stats->pkts++; |
| 1840 | } |
| 1841 | |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame^] | 1842 | /* The hardware ampdu queues start from 5. |
| 1843 | * txpriorities for ampdu queues are |
| 1844 | * 5 6 7 0 1 2 3 4 ie., queue 5 is highest |
| 1845 | * and queue 3 is lowest (queue 4 is reserved) |
| 1846 | */ |
| 1847 | #define BA_QUEUE 5 |
| 1848 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1849 | static void |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1850 | mwl8k_txq_xmit(struct ieee80211_hw *hw, |
| 1851 | int index, |
| 1852 | struct ieee80211_sta *sta, |
| 1853 | struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1854 | { |
| 1855 | struct mwl8k_priv *priv = hw->priv; |
| 1856 | struct ieee80211_tx_info *tx_info; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1857 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1858 | struct ieee80211_hdr *wh; |
| 1859 | struct mwl8k_tx_queue *txq; |
| 1860 | struct mwl8k_tx_desc *tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1861 | dma_addr_t dma; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1862 | u32 txstatus; |
| 1863 | u8 txdatarate; |
| 1864 | u16 qos; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1865 | int txpriority; |
| 1866 | u8 tid = 0; |
| 1867 | struct mwl8k_ampdu_stream *stream = NULL; |
| 1868 | bool start_ba_session = false; |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 1869 | bool mgmtframe = false; |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1870 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; |
Nishant Sarmukadam | e1f4d69 | 2012-11-06 19:23:01 +0530 | [diff] [blame] | 1871 | bool eapol_frame = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1872 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1873 | wh = (struct ieee80211_hdr *)skb->data; |
| 1874 | if (ieee80211_is_data_qos(wh->frame_control)) |
| 1875 | qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh))); |
| 1876 | else |
| 1877 | qos = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1878 | |
Nishant Sarmukadam | e1f4d69 | 2012-11-06 19:23:01 +0530 | [diff] [blame] | 1879 | if (skb->protocol == cpu_to_be16(ETH_P_PAE)) |
| 1880 | eapol_frame = true; |
| 1881 | |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 1882 | if (ieee80211_is_mgmt(wh->frame_control)) |
| 1883 | mgmtframe = true; |
| 1884 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1885 | if (priv->ap_fw) |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 1886 | mwl8k_encapsulate_tx_frame(priv, skb); |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1887 | else |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 1888 | mwl8k_add_dma_header(priv, skb, 0, 0); |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1889 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1890 | wh = &((struct mwl8k_dma_data *)skb->data)->wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1891 | |
| 1892 | tx_info = IEEE80211_SKB_CB(skb); |
| 1893 | mwl8k_vif = MWL8K_VIF(tx_info->control.vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1894 | |
| 1895 | if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1896 | wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
Lennert Buytenhek | 657232b | 2010-01-12 13:47:47 +0100 | [diff] [blame] | 1897 | wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno); |
| 1898 | mwl8k_vif->seqno += 0x10; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1899 | } |
| 1900 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1901 | /* Setup firmware control bit fields for each frame type. */ |
| 1902 | txstatus = 0; |
| 1903 | txdatarate = 0; |
| 1904 | if (ieee80211_is_mgmt(wh->frame_control) || |
| 1905 | ieee80211_is_ctl(wh->frame_control)) { |
| 1906 | txdatarate = 0; |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1907 | qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1908 | } else if (ieee80211_is_data(wh->frame_control)) { |
| 1909 | txdatarate = 1; |
| 1910 | if (is_multicast_ether_addr(wh->addr1)) |
| 1911 | txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX; |
| 1912 | |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1913 | qos &= ~MWL8K_QOS_ACK_POLICY_MASK; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1914 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1915 | qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1916 | else |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1917 | qos |= MWL8K_QOS_ACK_POLICY_NORMAL; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1918 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1919 | |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1920 | /* Queue ADDBA request in the respective data queue. While setting up |
| 1921 | * the ampdu stream, mac80211 queues further packets for that |
| 1922 | * particular ra/tid pair. However, packets piled up in the hardware |
| 1923 | * for that ra/tid pair will still go out. ADDBA request and the |
| 1924 | * related data packets going out from different queues asynchronously |
| 1925 | * will cause a shift in the receiver window which might result in |
| 1926 | * ampdu packets getting dropped at the receiver after the stream has |
| 1927 | * been setup. |
| 1928 | */ |
| 1929 | if (unlikely(ieee80211_is_action(wh->frame_control) && |
| 1930 | mgmt->u.action.category == WLAN_CATEGORY_BACK && |
| 1931 | mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ && |
| 1932 | priv->ap_fw)) { |
| 1933 | u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 1934 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 1935 | index = mwl8k_tid_queue_mapping(tid); |
| 1936 | } |
| 1937 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1938 | txpriority = index; |
| 1939 | |
Nishant Sarmukadam | e1f4d69 | 2012-11-06 19:23:01 +0530 | [diff] [blame] | 1940 | if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame && |
| 1941 | ieee80211_is_data_qos(wh->frame_control)) { |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1942 | tid = qos & 0xf; |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 1943 | mwl8k_tx_count_packet(sta, tid); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1944 | spin_lock(&priv->stream_lock); |
| 1945 | stream = mwl8k_lookup_stream(hw, sta->addr, tid); |
| 1946 | if (stream != NULL) { |
| 1947 | if (stream->state == AMPDU_STREAM_ACTIVE) { |
Yogesh Ashok Powar | 5f2a149 | 2013-01-03 13:21:25 +0530 | [diff] [blame] | 1948 | WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK)); |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame^] | 1949 | txpriority = (BA_QUEUE + stream->idx) % |
| 1950 | TOTAL_HW_TX_QUEUES; |
| 1951 | if (stream->idx <= 1) |
| 1952 | index = stream->idx + |
| 1953 | MWL8K_TX_WMM_QUEUES; |
| 1954 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1955 | } else if (stream->state == AMPDU_STREAM_NEW) { |
| 1956 | /* We get here if the driver sends us packets |
| 1957 | * after we've initiated a stream, but before |
| 1958 | * our ampdu_action routine has been called |
| 1959 | * with IEEE80211_AMPDU_TX_START to get the SSN |
| 1960 | * for the ADDBA request. So this packet can |
| 1961 | * go out with no risk of sequence number |
| 1962 | * mismatch. No special handling is required. |
| 1963 | */ |
| 1964 | } else { |
| 1965 | /* Drop packets that would go out after the |
| 1966 | * ADDBA request was sent but before the ADDBA |
| 1967 | * response is received. If we don't do this, |
| 1968 | * the recipient would probably receive it |
| 1969 | * after the ADDBA request with SSN 0. This |
| 1970 | * will cause the recipient's BA receive window |
| 1971 | * to shift, which would cause the subsequent |
| 1972 | * packets in the BA stream to be discarded. |
| 1973 | * mac80211 queues our packets for us in this |
| 1974 | * case, so this is really just a safety check. |
| 1975 | */ |
| 1976 | wiphy_warn(hw->wiphy, |
| 1977 | "Cannot send packet while ADDBA " |
| 1978 | "dialog is underway.\n"); |
| 1979 | spin_unlock(&priv->stream_lock); |
| 1980 | dev_kfree_skb(skb); |
| 1981 | return; |
| 1982 | } |
| 1983 | } else { |
| 1984 | /* Defer calling mwl8k_start_stream so that the current |
| 1985 | * skb can go out before the ADDBA request. This |
| 1986 | * prevents sequence number mismatch at the recepient |
| 1987 | * as described above. |
| 1988 | */ |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 1989 | if (mwl8k_ampdu_allowed(sta, tid)) { |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1990 | stream = mwl8k_add_stream(hw, sta, tid); |
| 1991 | if (stream != NULL) |
| 1992 | start_ba_session = true; |
| 1993 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1994 | } |
| 1995 | spin_unlock(&priv->stream_lock); |
Yogesh Ashok Powar | 5f2a149 | 2013-01-03 13:21:25 +0530 | [diff] [blame] | 1996 | } else { |
| 1997 | qos &= ~MWL8K_QOS_ACK_POLICY_MASK; |
| 1998 | qos |= MWL8K_QOS_ACK_POLICY_NORMAL; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2001 | dma = pci_map_single(priv->pdev, skb->data, |
| 2002 | skb->len, PCI_DMA_TODEVICE); |
| 2003 | |
| 2004 | if (pci_dma_mapping_error(priv->pdev, dma)) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2005 | wiphy_debug(hw->wiphy, |
| 2006 | "failed to dma map skb, dropping TX frame.\n"); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2007 | if (start_ba_session) { |
| 2008 | spin_lock(&priv->stream_lock); |
| 2009 | mwl8k_remove_stream(hw, stream); |
| 2010 | spin_unlock(&priv->stream_lock); |
| 2011 | } |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2012 | dev_kfree_skb(skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 2013 | return; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2016 | spin_lock_bh(&priv->tx_lock); |
| 2017 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2018 | txq = priv->txq + index; |
| 2019 | |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 2020 | /* Mgmt frames that go out frequently are probe |
| 2021 | * responses. Other mgmt frames got out relatively |
| 2022 | * infrequently. Hence reserve 2 buffers so that |
| 2023 | * other mgmt frames do not get dropped due to an |
| 2024 | * already queued probe response in one of the |
| 2025 | * reserved buffers. |
| 2026 | */ |
| 2027 | |
| 2028 | if (txq->len >= MWL8K_TX_DESCS - 2) { |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 2029 | if (!mgmtframe || txq->len == MWL8K_TX_DESCS) { |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 2030 | if (start_ba_session) { |
| 2031 | spin_lock(&priv->stream_lock); |
| 2032 | mwl8k_remove_stream(hw, stream); |
| 2033 | spin_unlock(&priv->stream_lock); |
| 2034 | } |
| 2035 | spin_unlock_bh(&priv->tx_lock); |
Nishant Sarmukadam | ff7aa96 | 2012-11-06 19:22:48 +0530 | [diff] [blame] | 2036 | pci_unmap_single(priv->pdev, dma, skb->len, |
| 2037 | PCI_DMA_TODEVICE); |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 2038 | dev_kfree_skb(skb); |
| 2039 | return; |
Pradeep Nemavat | 3a7dbc3 | 2011-04-21 16:34:56 +0530 | [diff] [blame] | 2040 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2043 | BUG_ON(txq->skb[txq->tail] != NULL); |
| 2044 | txq->skb[txq->tail] = skb; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2045 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2046 | tx = txq->txd + txq->tail; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2047 | tx->data_rate = txdatarate; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2048 | tx->tx_priority = txpriority; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2049 | tx->qos_control = cpu_to_le16(qos); |
| 2050 | tx->pkt_phys_addr = cpu_to_le32(dma); |
| 2051 | tx->pkt_len = cpu_to_le16(skb->len); |
| 2052 | tx->rate_info = 0; |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 2053 | if (!priv->ap_fw && sta != NULL) |
| 2054 | tx->peer_id = MWL8K_STA(sta)->peer_id; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 2055 | else |
| 2056 | tx->peer_id = 0; |
Pradeep Nemavat | 566875d | 2011-04-21 16:34:57 +0530 | [diff] [blame] | 2057 | |
Nishant Sarmukadam | e1f4d69 | 2012-11-06 19:23:01 +0530 | [diff] [blame] | 2058 | if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame) |
Pradeep Nemavat | 566875d | 2011-04-21 16:34:57 +0530 | [diff] [blame] | 2059 | tx->timestamp = cpu_to_le32(ioread32(priv->regs + |
| 2060 | MWL8K_HW_TIMER_REGISTER)); |
Nishant Sarmukadam | b8d9e57 | 2012-11-06 19:23:15 +0530 | [diff] [blame] | 2061 | else |
| 2062 | tx->timestamp = 0; |
Pradeep Nemavat | 566875d | 2011-04-21 16:34:57 +0530 | [diff] [blame] | 2063 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2064 | wmb(); |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2065 | tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus); |
| 2066 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 2067 | txq->len++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2068 | priv->pending_tx_pkts++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2069 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2070 | txq->tail++; |
| 2071 | if (txq->tail == MWL8K_TX_DESCS) |
| 2072 | txq->tail = 0; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2073 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2074 | mwl8k_tx_start(priv); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2075 | |
| 2076 | spin_unlock_bh(&priv->tx_lock); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2077 | |
| 2078 | /* Initiate the ampdu session here */ |
| 2079 | if (start_ba_session) { |
| 2080 | spin_lock(&priv->stream_lock); |
| 2081 | if (mwl8k_start_stream(hw, stream)) |
| 2082 | mwl8k_remove_stream(hw, stream); |
| 2083 | spin_unlock(&priv->stream_lock); |
| 2084 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | |
| 2088 | /* |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2089 | * Firmware access. |
| 2090 | * |
| 2091 | * We have the following requirements for issuing firmware commands: |
| 2092 | * - Some commands require that the packet transmit path is idle when |
| 2093 | * the command is issued. (For simplicity, we'll just quiesce the |
| 2094 | * transmit path for every command.) |
| 2095 | * - There are certain sequences of commands that need to be issued to |
| 2096 | * the hardware sequentially, with no other intervening commands. |
| 2097 | * |
| 2098 | * This leads to an implementation of a "firmware lock" as a mutex that |
| 2099 | * can be taken recursively, and which is taken by both the low-level |
| 2100 | * command submission function (mwl8k_post_cmd) as well as any users of |
| 2101 | * that function that require issuing of an atomic sequence of commands, |
| 2102 | * and quiesces the transmit path whenever it's taken. |
| 2103 | */ |
| 2104 | static int mwl8k_fw_lock(struct ieee80211_hw *hw) |
| 2105 | { |
| 2106 | struct mwl8k_priv *priv = hw->priv; |
| 2107 | |
| 2108 | if (priv->fw_mutex_owner != current) { |
| 2109 | int rc; |
| 2110 | |
| 2111 | mutex_lock(&priv->fw_mutex); |
| 2112 | ieee80211_stop_queues(hw); |
| 2113 | |
| 2114 | rc = mwl8k_tx_wait_empty(hw); |
| 2115 | if (rc) { |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 2116 | if (!priv->hw_restart_in_progress) |
| 2117 | ieee80211_wake_queues(hw); |
| 2118 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2119 | mutex_unlock(&priv->fw_mutex); |
| 2120 | |
| 2121 | return rc; |
| 2122 | } |
| 2123 | |
| 2124 | priv->fw_mutex_owner = current; |
| 2125 | } |
| 2126 | |
| 2127 | priv->fw_mutex_depth++; |
| 2128 | |
| 2129 | return 0; |
| 2130 | } |
| 2131 | |
| 2132 | static void mwl8k_fw_unlock(struct ieee80211_hw *hw) |
| 2133 | { |
| 2134 | struct mwl8k_priv *priv = hw->priv; |
| 2135 | |
| 2136 | if (!--priv->fw_mutex_depth) { |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 2137 | if (!priv->hw_restart_in_progress) |
| 2138 | ieee80211_wake_queues(hw); |
| 2139 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2140 | priv->fw_mutex_owner = NULL; |
| 2141 | mutex_unlock(&priv->fw_mutex); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | |
| 2146 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2147 | * Command processing. |
| 2148 | */ |
| 2149 | |
Lennert Buytenhek | 0c9cc640 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2150 | /* Timeout firmware commands after 10s */ |
| 2151 | #define MWL8K_CMD_TIMEOUT_MS 10000 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2152 | |
| 2153 | static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd) |
| 2154 | { |
| 2155 | DECLARE_COMPLETION_ONSTACK(cmd_wait); |
| 2156 | struct mwl8k_priv *priv = hw->priv; |
| 2157 | void __iomem *regs = priv->regs; |
| 2158 | dma_addr_t dma_addr; |
| 2159 | unsigned int dma_size; |
| 2160 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2161 | unsigned long timeout = 0; |
| 2162 | u8 buf[32]; |
| 2163 | |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2164 | cmd->result = (__force __le16) 0xffff; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2165 | dma_size = le16_to_cpu(cmd->length); |
| 2166 | dma_addr = pci_map_single(priv->pdev, cmd, dma_size, |
| 2167 | PCI_DMA_BIDIRECTIONAL); |
| 2168 | if (pci_dma_mapping_error(priv->pdev, dma_addr)) |
| 2169 | return -ENOMEM; |
| 2170 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2171 | rc = mwl8k_fw_lock(hw); |
Lennert Buytenhek | 39a1e42 | 2009-08-24 15:42:46 +0200 | [diff] [blame] | 2172 | if (rc) { |
| 2173 | pci_unmap_single(priv->pdev, dma_addr, dma_size, |
| 2174 | PCI_DMA_BIDIRECTIONAL); |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2175 | return rc; |
Lennert Buytenhek | 39a1e42 | 2009-08-24 15:42:46 +0200 | [diff] [blame] | 2176 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2177 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2178 | priv->hostcmd_wait = &cmd_wait; |
| 2179 | iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR); |
| 2180 | iowrite32(MWL8K_H2A_INT_DOORBELL, |
| 2181 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 2182 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 2183 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2184 | |
| 2185 | timeout = wait_for_completion_timeout(&cmd_wait, |
| 2186 | msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS)); |
| 2187 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2188 | priv->hostcmd_wait = NULL; |
| 2189 | |
| 2190 | mwl8k_fw_unlock(hw); |
| 2191 | |
Lennert Buytenhek | 37055bd | 2009-08-03 21:58:47 +0200 | [diff] [blame] | 2192 | pci_unmap_single(priv->pdev, dma_addr, dma_size, |
| 2193 | PCI_DMA_BIDIRECTIONAL); |
| 2194 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2195 | if (!timeout) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2196 | wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2197 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), |
| 2198 | MWL8K_CMD_TIMEOUT_MS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2199 | rc = -ETIMEDOUT; |
| 2200 | } else { |
Lennert Buytenhek | 0c9cc640 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2201 | int ms; |
| 2202 | |
| 2203 | ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout); |
| 2204 | |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2205 | rc = cmd->result ? -EINVAL : 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2206 | if (rc) |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2207 | wiphy_err(hw->wiphy, "Command %s error 0x%x\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2208 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), |
| 2209 | le16_to_cpu(cmd->result)); |
Lennert Buytenhek | 0c9cc640 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2210 | else if (ms > 2000) |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2211 | wiphy_notice(hw->wiphy, "Command %s took %d ms\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2212 | mwl8k_cmd_name(cmd->code, |
| 2213 | buf, sizeof(buf)), |
| 2214 | ms); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2215 | } |
| 2216 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2217 | return rc; |
| 2218 | } |
| 2219 | |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 2220 | static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw, |
| 2221 | struct ieee80211_vif *vif, |
| 2222 | struct mwl8k_cmd_pkt *cmd) |
| 2223 | { |
| 2224 | if (vif != NULL) |
| 2225 | cmd->macid = MWL8K_VIF(vif)->macid; |
| 2226 | return mwl8k_post_cmd(hw, cmd); |
| 2227 | } |
| 2228 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2229 | /* |
Lennert Buytenhek | 1349ad2 | 2010-01-12 13:48:17 +0100 | [diff] [blame] | 2230 | * Setup code shared between STA and AP firmware images. |
| 2231 | */ |
| 2232 | static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw) |
| 2233 | { |
| 2234 | struct mwl8k_priv *priv = hw->priv; |
| 2235 | |
| 2236 | BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24)); |
| 2237 | memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24)); |
| 2238 | |
| 2239 | BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24)); |
| 2240 | memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24)); |
| 2241 | |
| 2242 | priv->band_24.band = IEEE80211_BAND_2GHZ; |
| 2243 | priv->band_24.channels = priv->channels_24; |
| 2244 | priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24); |
| 2245 | priv->band_24.bitrates = priv->rates_24; |
| 2246 | priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24); |
| 2247 | |
| 2248 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24; |
| 2249 | } |
| 2250 | |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 2251 | static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw) |
| 2252 | { |
| 2253 | struct mwl8k_priv *priv = hw->priv; |
| 2254 | |
| 2255 | BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50)); |
| 2256 | memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50)); |
| 2257 | |
| 2258 | BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50)); |
| 2259 | memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50)); |
| 2260 | |
| 2261 | priv->band_50.band = IEEE80211_BAND_5GHZ; |
| 2262 | priv->band_50.channels = priv->channels_50; |
| 2263 | priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50); |
| 2264 | priv->band_50.bitrates = priv->rates_50; |
| 2265 | priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50); |
| 2266 | |
| 2267 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50; |
| 2268 | } |
| 2269 | |
Lennert Buytenhek | 1349ad2 | 2010-01-12 13:48:17 +0100 | [diff] [blame] | 2270 | /* |
Lennert Buytenhek | 04b147b1 | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2271 | * CMD_GET_HW_SPEC (STA version). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2272 | */ |
Lennert Buytenhek | 04b147b1 | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2273 | struct mwl8k_cmd_get_hw_spec_sta { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2274 | struct mwl8k_cmd_pkt header; |
| 2275 | __u8 hw_rev; |
| 2276 | __u8 host_interface; |
| 2277 | __le16 num_mcaddrs; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2278 | __u8 perm_addr[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2279 | __le16 region_code; |
| 2280 | __le32 fw_rev; |
| 2281 | __le32 ps_cookie; |
| 2282 | __le32 caps; |
| 2283 | __u8 mcs_bitmap[16]; |
| 2284 | __le32 rx_queue_ptr; |
| 2285 | __le32 num_tx_queues; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2286 | __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2287 | __le32 caps2; |
| 2288 | __le32 num_tx_desc_per_queue; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2289 | __le32 total_rxd; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2290 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2291 | |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2292 | #define MWL8K_CAP_MAX_AMSDU 0x20000000 |
| 2293 | #define MWL8K_CAP_GREENFIELD 0x08000000 |
| 2294 | #define MWL8K_CAP_AMPDU 0x04000000 |
| 2295 | #define MWL8K_CAP_RX_STBC 0x01000000 |
| 2296 | #define MWL8K_CAP_TX_STBC 0x00800000 |
| 2297 | #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000 |
| 2298 | #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000 |
| 2299 | #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000 |
| 2300 | #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000 |
| 2301 | #define MWL8K_CAP_DELAY_BA 0x00003000 |
| 2302 | #define MWL8K_CAP_MIMO 0x00000200 |
| 2303 | #define MWL8K_CAP_40MHZ 0x00000100 |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2304 | #define MWL8K_CAP_BAND_MASK 0x00000007 |
| 2305 | #define MWL8K_CAP_5GHZ 0x00000004 |
| 2306 | #define MWL8K_CAP_2GHZ4 0x00000001 |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2307 | |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2308 | static void |
| 2309 | mwl8k_set_ht_caps(struct ieee80211_hw *hw, |
| 2310 | struct ieee80211_supported_band *band, u32 cap) |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2311 | { |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2312 | int rx_streams; |
| 2313 | int tx_streams; |
| 2314 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2315 | band->ht_cap.ht_supported = 1; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2316 | |
| 2317 | if (cap & MWL8K_CAP_MAX_AMSDU) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2318 | band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2319 | if (cap & MWL8K_CAP_GREENFIELD) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2320 | band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2321 | if (cap & MWL8K_CAP_AMPDU) { |
| 2322 | hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION; |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2323 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 2324 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2325 | } |
| 2326 | if (cap & MWL8K_CAP_RX_STBC) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2327 | band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2328 | if (cap & MWL8K_CAP_TX_STBC) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2329 | band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2330 | if (cap & MWL8K_CAP_SHORTGI_40MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2331 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2332 | if (cap & MWL8K_CAP_SHORTGI_20MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2333 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2334 | if (cap & MWL8K_CAP_DELAY_BA) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2335 | band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2336 | if (cap & MWL8K_CAP_40MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2337 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2338 | |
| 2339 | rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK); |
| 2340 | tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK); |
| 2341 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2342 | band->ht_cap.mcs.rx_mask[0] = 0xff; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2343 | if (rx_streams >= 2) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2344 | band->ht_cap.mcs.rx_mask[1] = 0xff; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2345 | if (rx_streams >= 3) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2346 | band->ht_cap.mcs.rx_mask[2] = 0xff; |
| 2347 | band->ht_cap.mcs.rx_mask[4] = 0x01; |
| 2348 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2349 | |
| 2350 | if (rx_streams != tx_streams) { |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2351 | band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF; |
| 2352 | band->ht_cap.mcs.tx_params |= (tx_streams - 1) << |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2353 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; |
| 2354 | } |
| 2355 | } |
| 2356 | |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2357 | static void |
| 2358 | mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps) |
| 2359 | { |
| 2360 | struct mwl8k_priv *priv = hw->priv; |
| 2361 | |
| 2362 | if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) { |
| 2363 | mwl8k_setup_2ghz_band(hw); |
| 2364 | if (caps & MWL8K_CAP_MIMO) |
| 2365 | mwl8k_set_ht_caps(hw, &priv->band_24, caps); |
| 2366 | } |
| 2367 | |
| 2368 | if (caps & MWL8K_CAP_5GHZ) { |
| 2369 | mwl8k_setup_5ghz_band(hw); |
| 2370 | if (caps & MWL8K_CAP_MIMO) |
| 2371 | mwl8k_set_ht_caps(hw, &priv->band_50, caps); |
| 2372 | } |
| 2373 | } |
| 2374 | |
Lennert Buytenhek | 04b147b1 | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2375 | static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2376 | { |
| 2377 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 04b147b1 | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2378 | struct mwl8k_cmd_get_hw_spec_sta *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2379 | int rc; |
| 2380 | int i; |
| 2381 | |
| 2382 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2383 | if (cmd == NULL) |
| 2384 | return -ENOMEM; |
| 2385 | |
| 2386 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC); |
| 2387 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2388 | |
| 2389 | memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr)); |
| 2390 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2391 | cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma); |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2392 | cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv)); |
| 2393 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2394 | 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] | 2395 | cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2396 | cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2397 | |
| 2398 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2399 | |
| 2400 | if (!rc) { |
| 2401 | SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr); |
| 2402 | priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); |
Lennert Buytenhek | 4ff6432 | 2009-08-03 21:58:39 +0200 | [diff] [blame] | 2403 | priv->fw_rev = le32_to_cpu(cmd->fw_rev); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2404 | priv->hw_rev = cmd->hw_rev; |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2405 | mwl8k_set_caps(hw, le32_to_cpu(cmd->caps)); |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 2406 | priv->ap_macids_supported = 0x00000000; |
| 2407 | priv->sta_macids_supported = 0x00000001; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | kfree(cmd); |
| 2411 | return rc; |
| 2412 | } |
| 2413 | |
| 2414 | /* |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2415 | * CMD_GET_HW_SPEC (AP version). |
| 2416 | */ |
| 2417 | struct mwl8k_cmd_get_hw_spec_ap { |
| 2418 | struct mwl8k_cmd_pkt header; |
| 2419 | __u8 hw_rev; |
| 2420 | __u8 host_interface; |
| 2421 | __le16 num_wcb; |
| 2422 | __le16 num_mcaddrs; |
| 2423 | __u8 perm_addr[ETH_ALEN]; |
| 2424 | __le16 region_code; |
| 2425 | __le16 num_antenna; |
| 2426 | __le32 fw_rev; |
| 2427 | __le32 wcbbase0; |
| 2428 | __le32 rxwrptr; |
| 2429 | __le32 rxrdptr; |
| 2430 | __le32 ps_cookie; |
| 2431 | __le32 wcbbase1; |
| 2432 | __le32 wcbbase2; |
| 2433 | __le32 wcbbase3; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2434 | __le32 fw_api_version; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2435 | __le32 caps; |
| 2436 | __le32 num_of_ampdu_queues; |
| 2437 | __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2438 | } __packed; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2439 | |
| 2440 | static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw) |
| 2441 | { |
| 2442 | struct mwl8k_priv *priv = hw->priv; |
| 2443 | struct mwl8k_cmd_get_hw_spec_ap *cmd; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2444 | int rc, i; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2445 | u32 api_version; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2446 | |
| 2447 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2448 | if (cmd == NULL) |
| 2449 | return -ENOMEM; |
| 2450 | |
| 2451 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC); |
| 2452 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2453 | |
| 2454 | memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr)); |
| 2455 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
| 2456 | |
| 2457 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2458 | |
| 2459 | if (!rc) { |
| 2460 | int off; |
| 2461 | |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2462 | api_version = le32_to_cpu(cmd->fw_api_version); |
| 2463 | if (priv->device_info->fw_api_ap != api_version) { |
| 2464 | printk(KERN_ERR "%s: Unsupported fw API version for %s." |
| 2465 | " Expected %d got %d.\n", MWL8K_NAME, |
| 2466 | priv->device_info->part_name, |
| 2467 | priv->device_info->fw_api_ap, |
| 2468 | api_version); |
| 2469 | rc = -EINVAL; |
| 2470 | goto done; |
| 2471 | } |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2472 | SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr); |
| 2473 | priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); |
| 2474 | priv->fw_rev = le32_to_cpu(cmd->fw_rev); |
| 2475 | priv->hw_rev = cmd->hw_rev; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2476 | mwl8k_set_caps(hw, le32_to_cpu(cmd->caps)); |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 2477 | priv->ap_macids_supported = 0x000000ff; |
| 2478 | priv->sta_macids_supported = 0x00000000; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2479 | priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues); |
| 2480 | if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) { |
| 2481 | wiphy_warn(hw->wiphy, "fw reported %d ampdu queues" |
| 2482 | " but we only support %d.\n", |
| 2483 | priv->num_ampdu_queues, |
| 2484 | MWL8K_MAX_AMPDU_QUEUES); |
| 2485 | priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES; |
| 2486 | } |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2487 | off = le32_to_cpu(cmd->rxwrptr) & 0xffff; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2488 | iowrite32(priv->rxq[0].rxd_dma, priv->sram + off); |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2489 | |
| 2490 | off = le32_to_cpu(cmd->rxrdptr) & 0xffff; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2491 | iowrite32(priv->rxq[0].rxd_dma, priv->sram + off); |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2492 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 2493 | priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff; |
| 2494 | priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff; |
| 2495 | priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff; |
| 2496 | priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2497 | |
| 2498 | for (i = 0; i < priv->num_ampdu_queues; i++) |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2499 | priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] = |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2500 | le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2501 | } |
| 2502 | |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2503 | done: |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2504 | kfree(cmd); |
| 2505 | return rc; |
| 2506 | } |
| 2507 | |
| 2508 | /* |
| 2509 | * CMD_SET_HW_SPEC. |
| 2510 | */ |
| 2511 | struct mwl8k_cmd_set_hw_spec { |
| 2512 | struct mwl8k_cmd_pkt header; |
| 2513 | __u8 hw_rev; |
| 2514 | __u8 host_interface; |
| 2515 | __le16 num_mcaddrs; |
| 2516 | __u8 perm_addr[ETH_ALEN]; |
| 2517 | __le16 region_code; |
| 2518 | __le32 fw_rev; |
| 2519 | __le32 ps_cookie; |
| 2520 | __le32 caps; |
| 2521 | __le32 rx_queue_ptr; |
| 2522 | __le32 num_tx_queues; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2523 | __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES]; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2524 | __le32 flags; |
| 2525 | __le32 num_tx_desc_per_queue; |
| 2526 | __le32 total_rxd; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2527 | } __packed; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2528 | |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2529 | /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause |
| 2530 | * packets to expire 500 ms after the timestamp in the tx descriptor. That is, |
| 2531 | * the packets that are queued for more than 500ms, will be dropped in the |
| 2532 | * hardware. This helps minimizing the issues caused due to head-of-line |
| 2533 | * blocking where a slow client can hog the bandwidth and affect traffic to a |
| 2534 | * faster client. |
| 2535 | */ |
| 2536 | #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400 |
Nishant Sarmukadam | 3373b28 | 2011-06-13 16:26:15 +0530 | [diff] [blame] | 2537 | #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200 |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2538 | #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080 |
| 2539 | #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020 |
| 2540 | #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010 |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2541 | |
| 2542 | static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw) |
| 2543 | { |
| 2544 | struct mwl8k_priv *priv = hw->priv; |
| 2545 | struct mwl8k_cmd_set_hw_spec *cmd; |
| 2546 | int rc; |
| 2547 | int i; |
| 2548 | |
| 2549 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2550 | if (cmd == NULL) |
| 2551 | return -ENOMEM; |
| 2552 | |
| 2553 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC); |
| 2554 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2555 | |
| 2556 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
| 2557 | cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma); |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2558 | cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv)); |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 2559 | |
| 2560 | /* |
| 2561 | * Mac80211 stack has Q0 as highest priority and Q3 as lowest in |
| 2562 | * that order. Firmware has Q3 as highest priority and Q0 as lowest |
| 2563 | * in that order. Map Q3 of mac80211 to Q0 of firmware so that the |
| 2564 | * priority is interpreted the right way in firmware. |
| 2565 | */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2566 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
| 2567 | int j = mwl8k_tx_queues(priv) - 1 - i; |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 2568 | cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma); |
| 2569 | } |
| 2570 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2571 | cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT | |
| 2572 | MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP | |
Nishant Sarmukadam | 31d291a | 2011-04-21 16:34:59 +0530 | [diff] [blame] | 2573 | MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON | |
Nishant Sarmukadam | 3373b28 | 2011-06-13 16:26:15 +0530 | [diff] [blame] | 2574 | MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY | |
| 2575 | MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR); |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2576 | cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); |
| 2577 | cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS); |
| 2578 | |
| 2579 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2580 | kfree(cmd); |
| 2581 | |
| 2582 | return rc; |
| 2583 | } |
| 2584 | |
| 2585 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2586 | * CMD_MAC_MULTICAST_ADR. |
| 2587 | */ |
| 2588 | struct mwl8k_cmd_mac_multicast_adr { |
| 2589 | struct mwl8k_cmd_pkt header; |
| 2590 | __le16 action; |
| 2591 | __le16 numaddr; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2592 | __u8 addr[0][ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2593 | }; |
| 2594 | |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2595 | #define MWL8K_ENABLE_RX_DIRECTED 0x0001 |
| 2596 | #define MWL8K_ENABLE_RX_MULTICAST 0x0002 |
| 2597 | #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004 |
| 2598 | #define MWL8K_ENABLE_RX_BROADCAST 0x0008 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2599 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2600 | static struct mwl8k_cmd_pkt * |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 2601 | __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti, |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2602 | struct netdev_hw_addr_list *mc_list) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2603 | { |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2604 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2605 | struct mwl8k_cmd_mac_multicast_adr *cmd; |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2606 | int size; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2607 | int mc_count = 0; |
| 2608 | |
| 2609 | if (mc_list) |
| 2610 | mc_count = netdev_hw_addr_list_count(mc_list); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2611 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 2612 | if (allmulti || mc_count > priv->num_mcaddrs) { |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2613 | allmulti = 1; |
| 2614 | mc_count = 0; |
| 2615 | } |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2616 | |
| 2617 | size = sizeof(*cmd) + mc_count * ETH_ALEN; |
| 2618 | |
| 2619 | cmd = kzalloc(size, GFP_ATOMIC); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2620 | if (cmd == NULL) |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2621 | return NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2622 | |
| 2623 | cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR); |
| 2624 | cmd->header.length = cpu_to_le16(size); |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2625 | cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED | |
| 2626 | MWL8K_ENABLE_RX_BROADCAST); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2627 | |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2628 | if (allmulti) { |
| 2629 | cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST); |
| 2630 | } else if (mc_count) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2631 | struct netdev_hw_addr *ha; |
| 2632 | int i = 0; |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2633 | |
| 2634 | cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST); |
| 2635 | cmd->numaddr = cpu_to_le16(mc_count); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2636 | netdev_hw_addr_list_for_each(ha, mc_list) { |
| 2637 | memcpy(cmd->addr[i], ha->addr, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2638 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2639 | } |
| 2640 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2641 | return &cmd->header; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2645 | * CMD_GET_STAT. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2646 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2647 | struct mwl8k_cmd_get_stat { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2648 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2649 | __le32 stats[64]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2650 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2651 | |
| 2652 | #define MWL8K_STAT_ACK_FAILURE 9 |
| 2653 | #define MWL8K_STAT_RTS_FAILURE 12 |
| 2654 | #define MWL8K_STAT_FCS_ERROR 24 |
| 2655 | #define MWL8K_STAT_RTS_SUCCESS 11 |
| 2656 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2657 | static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw, |
| 2658 | struct ieee80211_low_level_stats *stats) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2659 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2660 | struct mwl8k_cmd_get_stat *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2661 | int rc; |
| 2662 | |
| 2663 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2664 | if (cmd == NULL) |
| 2665 | return -ENOMEM; |
| 2666 | |
| 2667 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT); |
| 2668 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2669 | |
| 2670 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2671 | if (!rc) { |
| 2672 | stats->dot11ACKFailureCount = |
| 2673 | le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]); |
| 2674 | stats->dot11RTSFailureCount = |
| 2675 | le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]); |
| 2676 | stats->dot11FCSErrorCount = |
| 2677 | le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]); |
| 2678 | stats->dot11RTSSuccessCount = |
| 2679 | le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]); |
| 2680 | } |
| 2681 | kfree(cmd); |
| 2682 | |
| 2683 | return rc; |
| 2684 | } |
| 2685 | |
| 2686 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2687 | * CMD_RADIO_CONTROL. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2688 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2689 | struct mwl8k_cmd_radio_control { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2690 | struct mwl8k_cmd_pkt header; |
| 2691 | __le16 action; |
| 2692 | __le16 control; |
| 2693 | __le16 radio_on; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2694 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2695 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2696 | static int |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2697 | mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2698 | { |
| 2699 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2700 | struct mwl8k_cmd_radio_control *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2701 | int rc; |
| 2702 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2703 | if (enable == priv->radio_on && !force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2704 | return 0; |
| 2705 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2706 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2707 | if (cmd == NULL) |
| 2708 | return -ENOMEM; |
| 2709 | |
| 2710 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL); |
| 2711 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2712 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 2713 | cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2714 | cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000); |
| 2715 | |
| 2716 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2717 | kfree(cmd); |
| 2718 | |
| 2719 | if (!rc) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2720 | priv->radio_on = enable; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2721 | |
| 2722 | return rc; |
| 2723 | } |
| 2724 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2725 | static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2726 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2727 | return mwl8k_cmd_radio_control(hw, 0, 0); |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2728 | } |
| 2729 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2730 | static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2731 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2732 | return mwl8k_cmd_radio_control(hw, 1, 0); |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2733 | } |
| 2734 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2735 | static int |
| 2736 | mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble) |
| 2737 | { |
Lennert Buytenhek | 99200a99 | 2009-11-30 18:31:40 +0100 | [diff] [blame] | 2738 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2739 | |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 2740 | priv->radio_short_preamble = short_preamble; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2741 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2742 | return mwl8k_cmd_radio_control(hw, 1, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2746 | * CMD_RF_TX_POWER. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2747 | */ |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2748 | #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2749 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2750 | struct mwl8k_cmd_rf_tx_power { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2751 | struct mwl8k_cmd_pkt header; |
| 2752 | __le16 action; |
| 2753 | __le16 support_level; |
| 2754 | __le16 current_level; |
| 2755 | __le16 reserved; |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2756 | __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2757 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2758 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2759 | 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] | 2760 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2761 | struct mwl8k_cmd_rf_tx_power *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2762 | int rc; |
| 2763 | |
| 2764 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2765 | if (cmd == NULL) |
| 2766 | return -ENOMEM; |
| 2767 | |
| 2768 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER); |
| 2769 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2770 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 2771 | cmd->support_level = cpu_to_le16(dBm); |
| 2772 | |
| 2773 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2774 | kfree(cmd); |
| 2775 | |
| 2776 | return rc; |
| 2777 | } |
| 2778 | |
| 2779 | /* |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2780 | * CMD_TX_POWER. |
| 2781 | */ |
| 2782 | #define MWL8K_TX_POWER_LEVEL_TOTAL 12 |
| 2783 | |
| 2784 | struct mwl8k_cmd_tx_power { |
| 2785 | struct mwl8k_cmd_pkt header; |
| 2786 | __le16 action; |
| 2787 | __le16 band; |
| 2788 | __le16 channel; |
| 2789 | __le16 bw; |
| 2790 | __le16 sub_ch; |
| 2791 | __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL]; |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 2792 | } __packed; |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2793 | |
| 2794 | static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw, |
| 2795 | struct ieee80211_conf *conf, |
| 2796 | unsigned short pwr) |
| 2797 | { |
| 2798 | struct ieee80211_channel *channel = conf->channel; |
| 2799 | struct mwl8k_cmd_tx_power *cmd; |
| 2800 | int rc; |
| 2801 | int i; |
| 2802 | |
| 2803 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2804 | if (cmd == NULL) |
| 2805 | return -ENOMEM; |
| 2806 | |
| 2807 | cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER); |
| 2808 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2809 | cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST); |
| 2810 | |
| 2811 | if (channel->band == IEEE80211_BAND_2GHZ) |
| 2812 | cmd->band = cpu_to_le16(0x1); |
| 2813 | else if (channel->band == IEEE80211_BAND_5GHZ) |
| 2814 | cmd->band = cpu_to_le16(0x4); |
| 2815 | |
Yogesh Ashok Powar | 604c4ef | 2012-01-17 15:45:15 +0530 | [diff] [blame] | 2816 | cmd->channel = cpu_to_le16(channel->hw_value); |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2817 | |
| 2818 | if (conf->channel_type == NL80211_CHAN_NO_HT || |
| 2819 | conf->channel_type == NL80211_CHAN_HT20) { |
| 2820 | cmd->bw = cpu_to_le16(0x2); |
| 2821 | } else { |
| 2822 | cmd->bw = cpu_to_le16(0x4); |
| 2823 | if (conf->channel_type == NL80211_CHAN_HT40MINUS) |
| 2824 | cmd->sub_ch = cpu_to_le16(0x3); |
| 2825 | else if (conf->channel_type == NL80211_CHAN_HT40PLUS) |
| 2826 | cmd->sub_ch = cpu_to_le16(0x1); |
| 2827 | } |
| 2828 | |
| 2829 | for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++) |
| 2830 | cmd->power_level_list[i] = cpu_to_le16(pwr); |
| 2831 | |
| 2832 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2833 | kfree(cmd); |
| 2834 | |
| 2835 | return rc; |
| 2836 | } |
| 2837 | |
| 2838 | /* |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 2839 | * CMD_RF_ANTENNA. |
| 2840 | */ |
| 2841 | struct mwl8k_cmd_rf_antenna { |
| 2842 | struct mwl8k_cmd_pkt header; |
| 2843 | __le16 antenna; |
| 2844 | __le16 mode; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2845 | } __packed; |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 2846 | |
| 2847 | #define MWL8K_RF_ANTENNA_RX 1 |
| 2848 | #define MWL8K_RF_ANTENNA_TX 2 |
| 2849 | |
| 2850 | static int |
| 2851 | mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask) |
| 2852 | { |
| 2853 | struct mwl8k_cmd_rf_antenna *cmd; |
| 2854 | int rc; |
| 2855 | |
| 2856 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2857 | if (cmd == NULL) |
| 2858 | return -ENOMEM; |
| 2859 | |
| 2860 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA); |
| 2861 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2862 | cmd->antenna = cpu_to_le16(antenna); |
| 2863 | cmd->mode = cpu_to_le16(mask); |
| 2864 | |
| 2865 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2866 | kfree(cmd); |
| 2867 | |
| 2868 | return rc; |
| 2869 | } |
| 2870 | |
| 2871 | /* |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2872 | * CMD_SET_BEACON. |
| 2873 | */ |
| 2874 | struct mwl8k_cmd_set_beacon { |
| 2875 | struct mwl8k_cmd_pkt header; |
| 2876 | __le16 beacon_len; |
| 2877 | __u8 beacon[0]; |
| 2878 | }; |
| 2879 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 2880 | static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, |
| 2881 | struct ieee80211_vif *vif, u8 *beacon, int len) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2882 | { |
| 2883 | struct mwl8k_cmd_set_beacon *cmd; |
| 2884 | int rc; |
| 2885 | |
| 2886 | cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL); |
| 2887 | if (cmd == NULL) |
| 2888 | return -ENOMEM; |
| 2889 | |
| 2890 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON); |
| 2891 | cmd->header.length = cpu_to_le16(sizeof(*cmd) + len); |
| 2892 | cmd->beacon_len = cpu_to_le16(len); |
| 2893 | memcpy(cmd->beacon, beacon, len); |
| 2894 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 2895 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2896 | kfree(cmd); |
| 2897 | |
| 2898 | return rc; |
| 2899 | } |
| 2900 | |
| 2901 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2902 | * CMD_SET_PRE_SCAN. |
| 2903 | */ |
| 2904 | struct mwl8k_cmd_set_pre_scan { |
| 2905 | struct mwl8k_cmd_pkt header; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2906 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2907 | |
| 2908 | static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw) |
| 2909 | { |
| 2910 | struct mwl8k_cmd_set_pre_scan *cmd; |
| 2911 | int rc; |
| 2912 | |
| 2913 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2914 | if (cmd == NULL) |
| 2915 | return -ENOMEM; |
| 2916 | |
| 2917 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN); |
| 2918 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2919 | |
| 2920 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2921 | kfree(cmd); |
| 2922 | |
| 2923 | return rc; |
| 2924 | } |
| 2925 | |
| 2926 | /* |
| 2927 | * CMD_SET_POST_SCAN. |
| 2928 | */ |
| 2929 | struct mwl8k_cmd_set_post_scan { |
| 2930 | struct mwl8k_cmd_pkt header; |
| 2931 | __le32 isibss; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2932 | __u8 bssid[ETH_ALEN]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2933 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2934 | |
| 2935 | static int |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 2936 | mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2937 | { |
| 2938 | struct mwl8k_cmd_set_post_scan *cmd; |
| 2939 | int rc; |
| 2940 | |
| 2941 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2942 | if (cmd == NULL) |
| 2943 | return -ENOMEM; |
| 2944 | |
| 2945 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN); |
| 2946 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2947 | cmd->isibss = 0; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2948 | memcpy(cmd->bssid, mac, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2949 | |
| 2950 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2951 | kfree(cmd); |
| 2952 | |
| 2953 | return rc; |
| 2954 | } |
| 2955 | |
| 2956 | /* |
| 2957 | * CMD_SET_RF_CHANNEL. |
| 2958 | */ |
| 2959 | struct mwl8k_cmd_set_rf_channel { |
| 2960 | struct mwl8k_cmd_pkt header; |
| 2961 | __le16 action; |
| 2962 | __u8 current_channel; |
| 2963 | __le32 channel_flags; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2964 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2965 | |
| 2966 | static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw, |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2967 | struct ieee80211_conf *conf) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2968 | { |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2969 | struct ieee80211_channel *channel = conf->channel; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2970 | struct mwl8k_cmd_set_rf_channel *cmd; |
| 2971 | int rc; |
| 2972 | |
| 2973 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2974 | if (cmd == NULL) |
| 2975 | return -ENOMEM; |
| 2976 | |
| 2977 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL); |
| 2978 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2979 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 2980 | cmd->current_channel = channel->hw_value; |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2981 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2982 | if (channel->band == IEEE80211_BAND_2GHZ) |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2983 | cmd->channel_flags |= cpu_to_le32(0x00000001); |
Lennert Buytenhek | 42574ea | 2010-01-12 13:49:18 +0100 | [diff] [blame] | 2984 | else if (channel->band == IEEE80211_BAND_5GHZ) |
| 2985 | cmd->channel_flags |= cpu_to_le32(0x00000004); |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 2986 | |
| 2987 | if (conf->channel_type == NL80211_CHAN_NO_HT || |
| 2988 | conf->channel_type == NL80211_CHAN_HT20) |
| 2989 | cmd->channel_flags |= cpu_to_le32(0x00000080); |
| 2990 | else if (conf->channel_type == NL80211_CHAN_HT40MINUS) |
| 2991 | cmd->channel_flags |= cpu_to_le32(0x000001900); |
| 2992 | else if (conf->channel_type == NL80211_CHAN_HT40PLUS) |
| 2993 | cmd->channel_flags |= cpu_to_le32(0x000000900); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2994 | |
| 2995 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2996 | kfree(cmd); |
| 2997 | |
| 2998 | return rc; |
| 2999 | } |
| 3000 | |
| 3001 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3002 | * CMD_SET_AID. |
| 3003 | */ |
| 3004 | #define MWL8K_FRAME_PROT_DISABLED 0x00 |
| 3005 | #define MWL8K_FRAME_PROT_11G 0x07 |
| 3006 | #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02 |
| 3007 | #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06 |
| 3008 | |
| 3009 | struct mwl8k_cmd_update_set_aid { |
| 3010 | struct mwl8k_cmd_pkt header; |
| 3011 | __le16 aid; |
| 3012 | |
| 3013 | /* AP's MAC address (BSSID) */ |
| 3014 | __u8 bssid[ETH_ALEN]; |
| 3015 | __le16 protection_mode; |
| 3016 | __u8 supp_rates[14]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3017 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3018 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3019 | static void legacy_rate_mask_to_array(u8 *rates, u32 mask) |
| 3020 | { |
| 3021 | int i; |
| 3022 | int j; |
| 3023 | |
| 3024 | /* |
| 3025 | * Clear nonstandard rates 4 and 13. |
| 3026 | */ |
| 3027 | mask &= 0x1fef; |
| 3028 | |
| 3029 | for (i = 0, j = 0; i < 14; i++) { |
| 3030 | if (mask & (1 << i)) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 3031 | rates[j++] = mwl8k_rates_24[i].hw_value; |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3035 | static int |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3036 | mwl8k_cmd_set_aid(struct ieee80211_hw *hw, |
| 3037 | struct ieee80211_vif *vif, u32 legacy_rate_mask) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3038 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3039 | struct mwl8k_cmd_update_set_aid *cmd; |
| 3040 | u16 prot_mode; |
| 3041 | int rc; |
| 3042 | |
| 3043 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3044 | if (cmd == NULL) |
| 3045 | return -ENOMEM; |
| 3046 | |
| 3047 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID); |
| 3048 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 3049 | cmd->aid = cpu_to_le16(vif->bss_conf.aid); |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 3050 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3051 | |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 3052 | if (vif->bss_conf.use_cts_prot) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3053 | prot_mode = MWL8K_FRAME_PROT_11G; |
| 3054 | } else { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 3055 | switch (vif->bss_conf.ht_operation_mode & |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3056 | IEEE80211_HT_OP_MODE_PROTECTION) { |
| 3057 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 3058 | prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY; |
| 3059 | break; |
| 3060 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 3061 | prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL; |
| 3062 | break; |
| 3063 | default: |
| 3064 | prot_mode = MWL8K_FRAME_PROT_DISABLED; |
| 3065 | break; |
| 3066 | } |
| 3067 | } |
| 3068 | cmd->protection_mode = cpu_to_le16(prot_mode); |
| 3069 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3070 | legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3071 | |
| 3072 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3073 | kfree(cmd); |
| 3074 | |
| 3075 | return rc; |
| 3076 | } |
| 3077 | |
| 3078 | /* |
| 3079 | * CMD_SET_RATE. |
| 3080 | */ |
| 3081 | struct mwl8k_cmd_set_rate { |
| 3082 | struct mwl8k_cmd_pkt header; |
| 3083 | __u8 legacy_rates[14]; |
| 3084 | |
| 3085 | /* Bitmap for supported MCS codes. */ |
| 3086 | __u8 mcs_set[16]; |
| 3087 | __u8 reserved[16]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3088 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3089 | |
| 3090 | static int |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3091 | mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 3092 | u32 legacy_rate_mask, u8 *mcs_rates) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3093 | { |
| 3094 | struct mwl8k_cmd_set_rate *cmd; |
| 3095 | int rc; |
| 3096 | |
| 3097 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3098 | if (cmd == NULL) |
| 3099 | return -ENOMEM; |
| 3100 | |
| 3101 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE); |
| 3102 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3103 | legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 3104 | memcpy(cmd->mcs_set, mcs_rates, 16); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3105 | |
| 3106 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3107 | kfree(cmd); |
| 3108 | |
| 3109 | return rc; |
| 3110 | } |
| 3111 | |
| 3112 | /* |
| 3113 | * CMD_FINALIZE_JOIN. |
| 3114 | */ |
| 3115 | #define MWL8K_FJ_BEACON_MAXLEN 128 |
| 3116 | |
| 3117 | struct mwl8k_cmd_finalize_join { |
| 3118 | struct mwl8k_cmd_pkt header; |
| 3119 | __le32 sleep_interval; /* Number of beacon periods to sleep */ |
| 3120 | __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3121 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3122 | |
| 3123 | static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame, |
| 3124 | int framelen, int dtim) |
| 3125 | { |
| 3126 | struct mwl8k_cmd_finalize_join *cmd; |
| 3127 | struct ieee80211_mgmt *payload = frame; |
| 3128 | int payload_len; |
| 3129 | int rc; |
| 3130 | |
| 3131 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3132 | if (cmd == NULL) |
| 3133 | return -ENOMEM; |
| 3134 | |
| 3135 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN); |
| 3136 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3137 | cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1); |
| 3138 | |
| 3139 | payload_len = framelen - ieee80211_hdrlen(payload->frame_control); |
| 3140 | if (payload_len < 0) |
| 3141 | payload_len = 0; |
| 3142 | else if (payload_len > MWL8K_FJ_BEACON_MAXLEN) |
| 3143 | payload_len = MWL8K_FJ_BEACON_MAXLEN; |
| 3144 | |
| 3145 | memcpy(cmd->beacon_data, &payload->u.beacon, payload_len); |
| 3146 | |
| 3147 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3148 | kfree(cmd); |
| 3149 | |
| 3150 | return rc; |
| 3151 | } |
| 3152 | |
| 3153 | /* |
| 3154 | * CMD_SET_RTS_THRESHOLD. |
| 3155 | */ |
| 3156 | struct mwl8k_cmd_set_rts_threshold { |
| 3157 | struct mwl8k_cmd_pkt header; |
| 3158 | __le16 action; |
| 3159 | __le16 threshold; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3160 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3161 | |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 3162 | static int |
| 3163 | mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3164 | { |
| 3165 | struct mwl8k_cmd_set_rts_threshold *cmd; |
| 3166 | int rc; |
| 3167 | |
| 3168 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3169 | if (cmd == NULL) |
| 3170 | return -ENOMEM; |
| 3171 | |
| 3172 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD); |
| 3173 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 3174 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 3175 | cmd->threshold = cpu_to_le16(rts_thresh); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3176 | |
| 3177 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3178 | kfree(cmd); |
| 3179 | |
| 3180 | return rc; |
| 3181 | } |
| 3182 | |
| 3183 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3184 | * CMD_SET_SLOT. |
| 3185 | */ |
| 3186 | struct mwl8k_cmd_set_slot { |
| 3187 | struct mwl8k_cmd_pkt header; |
| 3188 | __le16 action; |
| 3189 | __u8 short_slot; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3190 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3191 | |
Lennert Buytenhek | 5539bb5 | 2009-07-16 16:06:53 +0200 | [diff] [blame] | 3192 | 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] | 3193 | { |
| 3194 | struct mwl8k_cmd_set_slot *cmd; |
| 3195 | int rc; |
| 3196 | |
| 3197 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3198 | if (cmd == NULL) |
| 3199 | return -ENOMEM; |
| 3200 | |
| 3201 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT); |
| 3202 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3203 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
Lennert Buytenhek | 5539bb5 | 2009-07-16 16:06:53 +0200 | [diff] [blame] | 3204 | cmd->short_slot = short_slot_time; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3205 | |
| 3206 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3207 | kfree(cmd); |
| 3208 | |
| 3209 | return rc; |
| 3210 | } |
| 3211 | |
| 3212 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3213 | * CMD_SET_EDCA_PARAMS. |
| 3214 | */ |
| 3215 | struct mwl8k_cmd_set_edca_params { |
| 3216 | struct mwl8k_cmd_pkt header; |
| 3217 | |
| 3218 | /* See MWL8K_SET_EDCA_XXX below */ |
| 3219 | __le16 action; |
| 3220 | |
| 3221 | /* TX opportunity in units of 32 us */ |
| 3222 | __le16 txop; |
| 3223 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3224 | union { |
| 3225 | struct { |
| 3226 | /* Log exponent of max contention period: 0...15 */ |
| 3227 | __le32 log_cw_max; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3228 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3229 | /* Log exponent of min contention period: 0...15 */ |
| 3230 | __le32 log_cw_min; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3231 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3232 | /* Adaptive interframe spacing in units of 32us */ |
| 3233 | __u8 aifs; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3234 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3235 | /* TX queue to configure */ |
| 3236 | __u8 txq; |
| 3237 | } ap; |
| 3238 | struct { |
| 3239 | /* Log exponent of max contention period: 0...15 */ |
| 3240 | __u8 log_cw_max; |
| 3241 | |
| 3242 | /* Log exponent of min contention period: 0...15 */ |
| 3243 | __u8 log_cw_min; |
| 3244 | |
| 3245 | /* Adaptive interframe spacing in units of 32us */ |
| 3246 | __u8 aifs; |
| 3247 | |
| 3248 | /* TX queue to configure */ |
| 3249 | __u8 txq; |
| 3250 | } sta; |
| 3251 | }; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3252 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3253 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3254 | #define MWL8K_SET_EDCA_CW 0x01 |
| 3255 | #define MWL8K_SET_EDCA_TXOP 0x02 |
| 3256 | #define MWL8K_SET_EDCA_AIFS 0x04 |
| 3257 | |
| 3258 | #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \ |
| 3259 | MWL8K_SET_EDCA_TXOP | \ |
| 3260 | MWL8K_SET_EDCA_AIFS) |
| 3261 | |
| 3262 | static int |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3263 | mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum, |
| 3264 | __u16 cw_min, __u16 cw_max, |
| 3265 | __u8 aifs, __u16 txop) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3266 | { |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3267 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3268 | struct mwl8k_cmd_set_edca_params *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3269 | int rc; |
| 3270 | |
| 3271 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3272 | if (cmd == NULL) |
| 3273 | return -ENOMEM; |
| 3274 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3275 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS); |
| 3276 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3277 | cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL); |
| 3278 | cmd->txop = cpu_to_le16(txop); |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3279 | if (priv->ap_fw) { |
| 3280 | cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1)); |
| 3281 | cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1)); |
| 3282 | cmd->ap.aifs = aifs; |
| 3283 | cmd->ap.txq = qnum; |
| 3284 | } else { |
| 3285 | cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1); |
| 3286 | cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1); |
| 3287 | cmd->sta.aifs = aifs; |
| 3288 | cmd->sta.txq = qnum; |
| 3289 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3290 | |
| 3291 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3292 | kfree(cmd); |
| 3293 | |
| 3294 | return rc; |
| 3295 | } |
| 3296 | |
| 3297 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3298 | * CMD_SET_WMM_MODE. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3299 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3300 | struct mwl8k_cmd_set_wmm_mode { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3301 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3302 | __le16 action; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3303 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3304 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3305 | 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] | 3306 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3307 | struct mwl8k_priv *priv = hw->priv; |
| 3308 | struct mwl8k_cmd_set_wmm_mode *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3309 | int rc; |
| 3310 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3311 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3312 | if (cmd == NULL) |
| 3313 | return -ENOMEM; |
| 3314 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3315 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3316 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3317 | cmd->action = cpu_to_le16(!!enable); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3318 | |
| 3319 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3320 | kfree(cmd); |
Lennert Buytenhek | 16cec43 | 2009-11-30 18:14:23 +0100 | [diff] [blame] | 3321 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3322 | if (!rc) |
| 3323 | priv->wmm_enabled = enable; |
| 3324 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3325 | return rc; |
| 3326 | } |
| 3327 | |
| 3328 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3329 | * CMD_MIMO_CONFIG. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3330 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3331 | struct mwl8k_cmd_mimo_config { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3332 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3333 | __le32 action; |
| 3334 | __u8 rx_antenna_map; |
| 3335 | __u8 tx_antenna_map; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3336 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3337 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3338 | 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] | 3339 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3340 | struct mwl8k_cmd_mimo_config *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3341 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3342 | |
| 3343 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3344 | if (cmd == NULL) |
| 3345 | return -ENOMEM; |
| 3346 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3347 | cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3348 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3349 | cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET); |
| 3350 | cmd->rx_antenna_map = rx; |
| 3351 | cmd->tx_antenna_map = tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3352 | |
| 3353 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3354 | kfree(cmd); |
| 3355 | |
| 3356 | return rc; |
| 3357 | } |
| 3358 | |
| 3359 | /* |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3360 | * CMD_USE_FIXED_RATE (STA version). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3361 | */ |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3362 | struct mwl8k_cmd_use_fixed_rate_sta { |
| 3363 | struct mwl8k_cmd_pkt header; |
| 3364 | __le32 action; |
| 3365 | __le32 allow_rate_drop; |
| 3366 | __le32 num_rates; |
| 3367 | struct { |
| 3368 | __le32 is_ht_rate; |
| 3369 | __le32 enable_retry; |
| 3370 | __le32 rate; |
| 3371 | __le32 retry_count; |
| 3372 | } rate_entry[8]; |
| 3373 | __le32 rate_type; |
| 3374 | __le32 reserved1; |
| 3375 | __le32 reserved2; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3376 | } __packed; |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3377 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3378 | #define MWL8K_USE_AUTO_RATE 0x0002 |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3379 | #define MWL8K_UCAST_RATE 0 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3380 | |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3381 | static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3382 | { |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3383 | struct mwl8k_cmd_use_fixed_rate_sta *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3384 | int rc; |
| 3385 | |
| 3386 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3387 | if (cmd == NULL) |
| 3388 | return -ENOMEM; |
| 3389 | |
| 3390 | cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE); |
| 3391 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3392 | cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE); |
| 3393 | cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3394 | |
| 3395 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3396 | kfree(cmd); |
| 3397 | |
| 3398 | return rc; |
| 3399 | } |
| 3400 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3401 | /* |
Lennert Buytenhek | 088aab8 | 2010-01-08 18:30:36 +0100 | [diff] [blame] | 3402 | * CMD_USE_FIXED_RATE (AP version). |
| 3403 | */ |
| 3404 | struct mwl8k_cmd_use_fixed_rate_ap { |
| 3405 | struct mwl8k_cmd_pkt header; |
| 3406 | __le32 action; |
| 3407 | __le32 allow_rate_drop; |
| 3408 | __le32 num_rates; |
| 3409 | struct mwl8k_rate_entry_ap { |
| 3410 | __le32 is_ht_rate; |
| 3411 | __le32 enable_retry; |
| 3412 | __le32 rate; |
| 3413 | __le32 retry_count; |
| 3414 | } rate_entry[4]; |
| 3415 | u8 multicast_rate; |
| 3416 | u8 multicast_rate_type; |
| 3417 | u8 management_rate; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3418 | } __packed; |
Lennert Buytenhek | 088aab8 | 2010-01-08 18:30:36 +0100 | [diff] [blame] | 3419 | |
| 3420 | static int |
| 3421 | mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt) |
| 3422 | { |
| 3423 | struct mwl8k_cmd_use_fixed_rate_ap *cmd; |
| 3424 | int rc; |
| 3425 | |
| 3426 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3427 | if (cmd == NULL) |
| 3428 | return -ENOMEM; |
| 3429 | |
| 3430 | cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE); |
| 3431 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3432 | cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE); |
| 3433 | cmd->multicast_rate = mcast; |
| 3434 | cmd->management_rate = mgmt; |
| 3435 | |
| 3436 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3437 | kfree(cmd); |
| 3438 | |
| 3439 | return rc; |
| 3440 | } |
| 3441 | |
| 3442 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3443 | * CMD_ENABLE_SNIFFER. |
| 3444 | */ |
| 3445 | struct mwl8k_cmd_enable_sniffer { |
| 3446 | struct mwl8k_cmd_pkt header; |
| 3447 | __le32 action; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3448 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3449 | |
| 3450 | static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable) |
| 3451 | { |
| 3452 | struct mwl8k_cmd_enable_sniffer *cmd; |
| 3453 | int rc; |
| 3454 | |
| 3455 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3456 | if (cmd == NULL) |
| 3457 | return -ENOMEM; |
| 3458 | |
| 3459 | cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER); |
| 3460 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3461 | cmd->action = cpu_to_le32(!!enable); |
| 3462 | |
| 3463 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3464 | kfree(cmd); |
| 3465 | |
| 3466 | return rc; |
| 3467 | } |
| 3468 | |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3469 | struct mwl8k_cmd_update_mac_addr { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3470 | struct mwl8k_cmd_pkt header; |
| 3471 | union { |
| 3472 | struct { |
| 3473 | __le16 mac_type; |
| 3474 | __u8 mac_addr[ETH_ALEN]; |
| 3475 | } mbss; |
| 3476 | __u8 mac_addr[ETH_ALEN]; |
| 3477 | }; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3478 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3479 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3480 | #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0 |
| 3481 | #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1 |
| 3482 | #define MWL8K_MAC_TYPE_PRIMARY_AP 2 |
| 3483 | #define MWL8K_MAC_TYPE_SECONDARY_AP 3 |
Lennert Buytenhek | a9e00b1 | 2010-01-08 18:31:30 +0100 | [diff] [blame] | 3484 | |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3485 | static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw, |
| 3486 | struct ieee80211_vif *vif, u8 *mac, bool set) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3487 | { |
| 3488 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3489 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3490 | struct mwl8k_cmd_update_mac_addr *cmd; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3491 | int mac_type; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3492 | int rc; |
| 3493 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3494 | mac_type = MWL8K_MAC_TYPE_PRIMARY_AP; |
| 3495 | if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) { |
| 3496 | if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported)) |
| 3497 | mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT; |
| 3498 | else |
| 3499 | mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT; |
| 3500 | } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) { |
| 3501 | if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported)) |
| 3502 | mac_type = MWL8K_MAC_TYPE_PRIMARY_AP; |
| 3503 | else |
| 3504 | mac_type = MWL8K_MAC_TYPE_SECONDARY_AP; |
| 3505 | } |
| 3506 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3507 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3508 | if (cmd == NULL) |
| 3509 | return -ENOMEM; |
| 3510 | |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3511 | if (set) |
| 3512 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR); |
| 3513 | else |
| 3514 | cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR); |
| 3515 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3516 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3517 | if (priv->ap_fw) { |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3518 | cmd->mbss.mac_type = cpu_to_le16(mac_type); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3519 | memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN); |
| 3520 | } else { |
| 3521 | memcpy(cmd->mac_addr, mac, ETH_ALEN); |
| 3522 | } |
| 3523 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3524 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3525 | kfree(cmd); |
| 3526 | |
| 3527 | return rc; |
| 3528 | } |
| 3529 | |
| 3530 | /* |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3531 | * MWL8K_CMD_SET_MAC_ADDR. |
| 3532 | */ |
| 3533 | static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, |
| 3534 | struct ieee80211_vif *vif, u8 *mac) |
| 3535 | { |
| 3536 | return mwl8k_cmd_update_mac_addr(hw, vif, mac, true); |
| 3537 | } |
| 3538 | |
| 3539 | /* |
| 3540 | * MWL8K_CMD_DEL_MAC_ADDR. |
| 3541 | */ |
| 3542 | static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw, |
| 3543 | struct ieee80211_vif *vif, u8 *mac) |
| 3544 | { |
| 3545 | return mwl8k_cmd_update_mac_addr(hw, vif, mac, false); |
| 3546 | } |
| 3547 | |
| 3548 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3549 | * CMD_SET_RATEADAPT_MODE. |
| 3550 | */ |
| 3551 | struct mwl8k_cmd_set_rate_adapt_mode { |
| 3552 | struct mwl8k_cmd_pkt header; |
| 3553 | __le16 action; |
| 3554 | __le16 mode; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3555 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3556 | |
| 3557 | static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode) |
| 3558 | { |
| 3559 | struct mwl8k_cmd_set_rate_adapt_mode *cmd; |
| 3560 | int rc; |
| 3561 | |
| 3562 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3563 | if (cmd == NULL) |
| 3564 | return -ENOMEM; |
| 3565 | |
| 3566 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE); |
| 3567 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3568 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 3569 | cmd->mode = cpu_to_le16(mode); |
| 3570 | |
| 3571 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3572 | kfree(cmd); |
| 3573 | |
| 3574 | return rc; |
| 3575 | } |
| 3576 | |
| 3577 | /* |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3578 | * CMD_GET_WATCHDOG_BITMAP. |
| 3579 | */ |
| 3580 | struct mwl8k_cmd_get_watchdog_bitmap { |
| 3581 | struct mwl8k_cmd_pkt header; |
| 3582 | u8 bitmap; |
| 3583 | } __packed; |
| 3584 | |
| 3585 | static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap) |
| 3586 | { |
| 3587 | struct mwl8k_cmd_get_watchdog_bitmap *cmd; |
| 3588 | int rc; |
| 3589 | |
| 3590 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3591 | if (cmd == NULL) |
| 3592 | return -ENOMEM; |
| 3593 | |
| 3594 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP); |
| 3595 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3596 | |
| 3597 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3598 | if (!rc) |
| 3599 | *bitmap = cmd->bitmap; |
| 3600 | |
| 3601 | kfree(cmd); |
| 3602 | |
| 3603 | return rc; |
| 3604 | } |
| 3605 | |
| 3606 | #define INVALID_BA 0xAA |
| 3607 | static void mwl8k_watchdog_ba_events(struct work_struct *work) |
| 3608 | { |
| 3609 | int rc; |
| 3610 | u8 bitmap = 0, stream_index; |
| 3611 | struct mwl8k_ampdu_stream *streams; |
| 3612 | struct mwl8k_priv *priv = |
| 3613 | container_of(work, struct mwl8k_priv, watchdog_ba_handle); |
| 3614 | |
| 3615 | rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap); |
| 3616 | if (rc) |
| 3617 | return; |
| 3618 | |
| 3619 | if (bitmap == INVALID_BA) |
| 3620 | return; |
| 3621 | |
| 3622 | /* the bitmap is the hw queue number. Map it to the ampdu queue. */ |
| 3623 | stream_index = bitmap - MWL8K_TX_WMM_QUEUES; |
| 3624 | |
| 3625 | BUG_ON(stream_index >= priv->num_ampdu_queues); |
| 3626 | |
| 3627 | streams = &priv->ampdu[stream_index]; |
| 3628 | |
| 3629 | if (streams->state == AMPDU_STREAM_ACTIVE) |
| 3630 | ieee80211_stop_tx_ba_session(streams->sta, streams->tid); |
| 3631 | |
| 3632 | return; |
| 3633 | } |
| 3634 | |
| 3635 | |
| 3636 | /* |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3637 | * CMD_BSS_START. |
| 3638 | */ |
| 3639 | struct mwl8k_cmd_bss_start { |
| 3640 | struct mwl8k_cmd_pkt header; |
| 3641 | __le32 enable; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3642 | } __packed; |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3643 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3644 | static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, |
| 3645 | struct ieee80211_vif *vif, int enable) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3646 | { |
| 3647 | struct mwl8k_cmd_bss_start *cmd; |
| 3648 | int rc; |
| 3649 | |
| 3650 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3651 | if (cmd == NULL) |
| 3652 | return -ENOMEM; |
| 3653 | |
| 3654 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START); |
| 3655 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3656 | cmd->enable = cpu_to_le32(enable); |
| 3657 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3658 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3659 | kfree(cmd); |
| 3660 | |
| 3661 | return rc; |
| 3662 | } |
| 3663 | |
| 3664 | /* |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3665 | * CMD_BASTREAM. |
| 3666 | */ |
| 3667 | |
| 3668 | /* |
| 3669 | * UPSTREAM is tx direction |
| 3670 | */ |
| 3671 | #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00 |
| 3672 | #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01 |
| 3673 | |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 3674 | enum ba_stream_action_type { |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3675 | MWL8K_BA_CREATE, |
| 3676 | MWL8K_BA_UPDATE, |
| 3677 | MWL8K_BA_DESTROY, |
| 3678 | MWL8K_BA_FLUSH, |
| 3679 | MWL8K_BA_CHECK, |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 3680 | }; |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3681 | |
| 3682 | |
| 3683 | struct mwl8k_create_ba_stream { |
| 3684 | __le32 flags; |
| 3685 | __le32 idle_thrs; |
| 3686 | __le32 bar_thrs; |
| 3687 | __le32 window_size; |
| 3688 | u8 peer_mac_addr[6]; |
| 3689 | u8 dialog_token; |
| 3690 | u8 tid; |
| 3691 | u8 queue_id; |
| 3692 | u8 param_info; |
| 3693 | __le32 ba_context; |
| 3694 | u8 reset_seq_no_flag; |
| 3695 | __le16 curr_seq_no; |
| 3696 | u8 sta_src_mac_addr[6]; |
| 3697 | } __packed; |
| 3698 | |
| 3699 | struct mwl8k_destroy_ba_stream { |
| 3700 | __le32 flags; |
| 3701 | __le32 ba_context; |
| 3702 | } __packed; |
| 3703 | |
| 3704 | struct mwl8k_cmd_bastream { |
| 3705 | struct mwl8k_cmd_pkt header; |
| 3706 | __le32 action; |
| 3707 | union { |
| 3708 | struct mwl8k_create_ba_stream create_params; |
| 3709 | struct mwl8k_destroy_ba_stream destroy_params; |
| 3710 | }; |
| 3711 | } __packed; |
| 3712 | |
| 3713 | static int |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 3714 | mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream, |
| 3715 | struct ieee80211_vif *vif) |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3716 | { |
| 3717 | struct mwl8k_cmd_bastream *cmd; |
| 3718 | int rc; |
| 3719 | |
| 3720 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3721 | if (cmd == NULL) |
| 3722 | return -ENOMEM; |
| 3723 | |
| 3724 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3725 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3726 | |
| 3727 | cmd->action = cpu_to_le32(MWL8K_BA_CHECK); |
| 3728 | |
| 3729 | cmd->create_params.queue_id = stream->idx; |
| 3730 | memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr, |
| 3731 | ETH_ALEN); |
| 3732 | cmd->create_params.tid = stream->tid; |
| 3733 | |
| 3734 | cmd->create_params.flags = |
| 3735 | cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) | |
| 3736 | cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM); |
| 3737 | |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 3738 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3739 | |
| 3740 | kfree(cmd); |
| 3741 | |
| 3742 | return rc; |
| 3743 | } |
| 3744 | |
| 3745 | static int |
| 3746 | mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream, |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 3747 | u8 buf_size, struct ieee80211_vif *vif) |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3748 | { |
| 3749 | struct mwl8k_cmd_bastream *cmd; |
| 3750 | int rc; |
| 3751 | |
| 3752 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3753 | if (cmd == NULL) |
| 3754 | return -ENOMEM; |
| 3755 | |
| 3756 | |
| 3757 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3758 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3759 | |
| 3760 | cmd->action = cpu_to_le32(MWL8K_BA_CREATE); |
| 3761 | |
| 3762 | cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size); |
| 3763 | cmd->create_params.window_size = cpu_to_le32((u32)buf_size); |
| 3764 | cmd->create_params.queue_id = stream->idx; |
| 3765 | |
| 3766 | memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN); |
| 3767 | cmd->create_params.tid = stream->tid; |
| 3768 | cmd->create_params.curr_seq_no = cpu_to_le16(0); |
| 3769 | cmd->create_params.reset_seq_no_flag = 1; |
| 3770 | |
| 3771 | cmd->create_params.param_info = |
| 3772 | (stream->sta->ht_cap.ampdu_factor & |
| 3773 | IEEE80211_HT_AMPDU_PARM_FACTOR) | |
| 3774 | ((stream->sta->ht_cap.ampdu_density << 2) & |
| 3775 | IEEE80211_HT_AMPDU_PARM_DENSITY); |
| 3776 | |
| 3777 | cmd->create_params.flags = |
| 3778 | cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE | |
| 3779 | BASTREAM_FLAG_DIRECTION_UPSTREAM); |
| 3780 | |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 3781 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3782 | |
| 3783 | wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n", |
| 3784 | stream->sta->addr, stream->tid); |
| 3785 | kfree(cmd); |
| 3786 | |
| 3787 | return rc; |
| 3788 | } |
| 3789 | |
| 3790 | static void mwl8k_destroy_ba(struct ieee80211_hw *hw, |
| 3791 | struct mwl8k_ampdu_stream *stream) |
| 3792 | { |
| 3793 | struct mwl8k_cmd_bastream *cmd; |
| 3794 | |
| 3795 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3796 | if (cmd == NULL) |
| 3797 | return; |
| 3798 | |
| 3799 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3800 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3801 | cmd->action = cpu_to_le32(MWL8K_BA_DESTROY); |
| 3802 | |
| 3803 | cmd->destroy_params.ba_context = cpu_to_le32(stream->idx); |
| 3804 | mwl8k_post_cmd(hw, &cmd->header); |
| 3805 | |
| 3806 | wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", stream->idx); |
| 3807 | |
| 3808 | kfree(cmd); |
| 3809 | } |
| 3810 | |
| 3811 | /* |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3812 | * CMD_SET_NEW_STN. |
| 3813 | */ |
| 3814 | struct mwl8k_cmd_set_new_stn { |
| 3815 | struct mwl8k_cmd_pkt header; |
| 3816 | __le16 aid; |
| 3817 | __u8 mac_addr[6]; |
| 3818 | __le16 stn_id; |
| 3819 | __le16 action; |
| 3820 | __le16 rsvd; |
| 3821 | __le32 legacy_rates; |
| 3822 | __u8 ht_rates[4]; |
| 3823 | __le16 cap_info; |
| 3824 | __le16 ht_capabilities_info; |
| 3825 | __u8 mac_ht_param_info; |
| 3826 | __u8 rev; |
| 3827 | __u8 control_channel; |
| 3828 | __u8 add_channel; |
| 3829 | __le16 op_mode; |
| 3830 | __le16 stbc; |
| 3831 | __u8 add_qos_info; |
| 3832 | __u8 is_qos_sta; |
| 3833 | __le32 fw_sta_ptr; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3834 | } __packed; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3835 | |
| 3836 | #define MWL8K_STA_ACTION_ADD 0 |
| 3837 | #define MWL8K_STA_ACTION_REMOVE 2 |
| 3838 | |
| 3839 | static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw, |
| 3840 | struct ieee80211_vif *vif, |
| 3841 | struct ieee80211_sta *sta) |
| 3842 | { |
| 3843 | struct mwl8k_cmd_set_new_stn *cmd; |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 3844 | u32 rates; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3845 | int rc; |
| 3846 | |
| 3847 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3848 | if (cmd == NULL) |
| 3849 | return -ENOMEM; |
| 3850 | |
| 3851 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 3852 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3853 | cmd->aid = cpu_to_le16(sta->aid); |
| 3854 | memcpy(cmd->mac_addr, sta->addr, ETH_ALEN); |
| 3855 | cmd->stn_id = cpu_to_le16(sta->aid); |
| 3856 | cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD); |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 3857 | if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) |
| 3858 | rates = sta->supp_rates[IEEE80211_BAND_2GHZ]; |
| 3859 | else |
| 3860 | rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 3861 | cmd->legacy_rates = cpu_to_le32(rates); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3862 | if (sta->ht_cap.ht_supported) { |
| 3863 | cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0]; |
| 3864 | cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1]; |
| 3865 | cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2]; |
| 3866 | cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3]; |
| 3867 | cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap); |
| 3868 | cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) | |
| 3869 | ((sta->ht_cap.ampdu_density & 7) << 2); |
| 3870 | cmd->is_qos_sta = 1; |
| 3871 | } |
| 3872 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3873 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3874 | kfree(cmd); |
| 3875 | |
| 3876 | return rc; |
| 3877 | } |
| 3878 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3879 | static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw, |
| 3880 | struct ieee80211_vif *vif) |
| 3881 | { |
| 3882 | struct mwl8k_cmd_set_new_stn *cmd; |
| 3883 | int rc; |
| 3884 | |
| 3885 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3886 | if (cmd == NULL) |
| 3887 | return -ENOMEM; |
| 3888 | |
| 3889 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 3890 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3891 | memcpy(cmd->mac_addr, vif->addr, ETH_ALEN); |
| 3892 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3893 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3894 | kfree(cmd); |
| 3895 | |
| 3896 | return rc; |
| 3897 | } |
| 3898 | |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3899 | static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw, |
| 3900 | struct ieee80211_vif *vif, u8 *addr) |
| 3901 | { |
| 3902 | struct mwl8k_cmd_set_new_stn *cmd; |
| 3903 | int rc; |
| 3904 | |
| 3905 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3906 | if (cmd == NULL) |
| 3907 | return -ENOMEM; |
| 3908 | |
| 3909 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 3910 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3911 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 3912 | cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE); |
| 3913 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3914 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3915 | kfree(cmd); |
| 3916 | |
| 3917 | return rc; |
| 3918 | } |
| 3919 | |
| 3920 | /* |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 3921 | * CMD_UPDATE_ENCRYPTION. |
| 3922 | */ |
| 3923 | |
| 3924 | #define MAX_ENCR_KEY_LENGTH 16 |
| 3925 | #define MIC_KEY_LENGTH 8 |
| 3926 | |
| 3927 | struct mwl8k_cmd_update_encryption { |
| 3928 | struct mwl8k_cmd_pkt header; |
| 3929 | |
| 3930 | __le32 action; |
| 3931 | __le32 reserved; |
| 3932 | __u8 mac_addr[6]; |
| 3933 | __u8 encr_type; |
| 3934 | |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 3935 | } __packed; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 3936 | |
| 3937 | struct mwl8k_cmd_set_key { |
| 3938 | struct mwl8k_cmd_pkt header; |
| 3939 | |
| 3940 | __le32 action; |
| 3941 | __le32 reserved; |
| 3942 | __le16 length; |
| 3943 | __le16 key_type_id; |
| 3944 | __le32 key_info; |
| 3945 | __le32 key_id; |
| 3946 | __le16 key_len; |
| 3947 | __u8 key_material[MAX_ENCR_KEY_LENGTH]; |
| 3948 | __u8 tkip_tx_mic_key[MIC_KEY_LENGTH]; |
| 3949 | __u8 tkip_rx_mic_key[MIC_KEY_LENGTH]; |
| 3950 | __le16 tkip_rsc_low; |
| 3951 | __le32 tkip_rsc_high; |
| 3952 | __le16 tkip_tsc_low; |
| 3953 | __le32 tkip_tsc_high; |
| 3954 | __u8 mac_addr[6]; |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 3955 | } __packed; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 3956 | |
| 3957 | enum { |
| 3958 | MWL8K_ENCR_ENABLE, |
| 3959 | MWL8K_ENCR_SET_KEY, |
| 3960 | MWL8K_ENCR_REMOVE_KEY, |
| 3961 | MWL8K_ENCR_SET_GROUP_KEY, |
| 3962 | }; |
| 3963 | |
| 3964 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0 |
| 3965 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1 |
| 3966 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4 |
| 3967 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7 |
| 3968 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8 |
| 3969 | |
| 3970 | enum { |
| 3971 | MWL8K_ALG_WEP, |
| 3972 | MWL8K_ALG_TKIP, |
| 3973 | MWL8K_ALG_CCMP, |
| 3974 | }; |
| 3975 | |
| 3976 | #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004 |
| 3977 | #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008 |
| 3978 | #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040 |
| 3979 | #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000 |
| 3980 | #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000 |
| 3981 | |
| 3982 | static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw, |
| 3983 | struct ieee80211_vif *vif, |
| 3984 | u8 *addr, |
| 3985 | u8 encr_type) |
| 3986 | { |
| 3987 | struct mwl8k_cmd_update_encryption *cmd; |
| 3988 | int rc; |
| 3989 | |
| 3990 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3991 | if (cmd == NULL) |
| 3992 | return -ENOMEM; |
| 3993 | |
| 3994 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION); |
| 3995 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3996 | cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE); |
| 3997 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 3998 | cmd->encr_type = encr_type; |
| 3999 | |
| 4000 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 4001 | kfree(cmd); |
| 4002 | |
| 4003 | return rc; |
| 4004 | } |
| 4005 | |
| 4006 | static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd, |
| 4007 | u8 *addr, |
| 4008 | struct ieee80211_key_conf *key) |
| 4009 | { |
| 4010 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION); |
| 4011 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 4012 | cmd->length = cpu_to_le16(sizeof(*cmd) - |
| 4013 | offsetof(struct mwl8k_cmd_set_key, length)); |
| 4014 | cmd->key_id = cpu_to_le32(key->keyidx); |
| 4015 | cmd->key_len = cpu_to_le16(key->keylen); |
| 4016 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 4017 | |
| 4018 | switch (key->cipher) { |
| 4019 | case WLAN_CIPHER_SUITE_WEP40: |
| 4020 | case WLAN_CIPHER_SUITE_WEP104: |
| 4021 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP); |
| 4022 | if (key->keyidx == 0) |
| 4023 | cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY); |
| 4024 | |
| 4025 | break; |
| 4026 | case WLAN_CIPHER_SUITE_TKIP: |
| 4027 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP); |
| 4028 | cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4029 | ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE) |
| 4030 | : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY); |
| 4031 | cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID |
| 4032 | | MWL8K_KEY_FLAG_TSC_VALID); |
| 4033 | break; |
| 4034 | case WLAN_CIPHER_SUITE_CCMP: |
| 4035 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP); |
| 4036 | cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4037 | ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE) |
| 4038 | : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY); |
| 4039 | break; |
| 4040 | default: |
| 4041 | return -ENOTSUPP; |
| 4042 | } |
| 4043 | |
| 4044 | return 0; |
| 4045 | } |
| 4046 | |
| 4047 | static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw, |
| 4048 | struct ieee80211_vif *vif, |
| 4049 | u8 *addr, |
| 4050 | struct ieee80211_key_conf *key) |
| 4051 | { |
| 4052 | struct mwl8k_cmd_set_key *cmd; |
| 4053 | int rc; |
| 4054 | int keymlen; |
| 4055 | u32 action; |
| 4056 | u8 idx; |
| 4057 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 4058 | |
| 4059 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4060 | if (cmd == NULL) |
| 4061 | return -ENOMEM; |
| 4062 | |
| 4063 | rc = mwl8k_encryption_set_cmd_info(cmd, addr, key); |
| 4064 | if (rc < 0) |
| 4065 | goto done; |
| 4066 | |
| 4067 | idx = key->keyidx; |
| 4068 | |
| 4069 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4070 | action = MWL8K_ENCR_SET_KEY; |
| 4071 | else |
| 4072 | action = MWL8K_ENCR_SET_GROUP_KEY; |
| 4073 | |
| 4074 | switch (key->cipher) { |
| 4075 | case WLAN_CIPHER_SUITE_WEP40: |
| 4076 | case WLAN_CIPHER_SUITE_WEP104: |
| 4077 | if (!mwl8k_vif->wep_key_conf[idx].enabled) { |
| 4078 | memcpy(mwl8k_vif->wep_key_conf[idx].key, key, |
| 4079 | sizeof(*key) + key->keylen); |
| 4080 | mwl8k_vif->wep_key_conf[idx].enabled = 1; |
| 4081 | } |
| 4082 | |
Yogesh Ashok Powar | 9b571e2 | 2011-05-04 17:22:16 +0530 | [diff] [blame] | 4083 | keymlen = key->keylen; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4084 | action = MWL8K_ENCR_SET_KEY; |
| 4085 | break; |
| 4086 | case WLAN_CIPHER_SUITE_TKIP: |
| 4087 | keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH; |
| 4088 | break; |
| 4089 | case WLAN_CIPHER_SUITE_CCMP: |
| 4090 | keymlen = key->keylen; |
| 4091 | break; |
| 4092 | default: |
| 4093 | rc = -ENOTSUPP; |
| 4094 | goto done; |
| 4095 | } |
| 4096 | |
| 4097 | memcpy(cmd->key_material, key->key, keymlen); |
| 4098 | cmd->action = cpu_to_le32(action); |
| 4099 | |
| 4100 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 4101 | done: |
| 4102 | kfree(cmd); |
| 4103 | |
| 4104 | return rc; |
| 4105 | } |
| 4106 | |
| 4107 | static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw, |
| 4108 | struct ieee80211_vif *vif, |
| 4109 | u8 *addr, |
| 4110 | struct ieee80211_key_conf *key) |
| 4111 | { |
| 4112 | struct mwl8k_cmd_set_key *cmd; |
| 4113 | int rc; |
| 4114 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 4115 | |
| 4116 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4117 | if (cmd == NULL) |
| 4118 | return -ENOMEM; |
| 4119 | |
| 4120 | rc = mwl8k_encryption_set_cmd_info(cmd, addr, key); |
| 4121 | if (rc < 0) |
| 4122 | goto done; |
| 4123 | |
| 4124 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
Dan Carpenter | d981e05 | 2012-01-17 10:33:31 +0300 | [diff] [blame] | 4125 | key->cipher == WLAN_CIPHER_SUITE_WEP104) |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4126 | mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0; |
| 4127 | |
| 4128 | cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY); |
| 4129 | |
| 4130 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 4131 | done: |
| 4132 | kfree(cmd); |
| 4133 | |
| 4134 | return rc; |
| 4135 | } |
| 4136 | |
| 4137 | static int mwl8k_set_key(struct ieee80211_hw *hw, |
| 4138 | enum set_key_cmd cmd_param, |
| 4139 | struct ieee80211_vif *vif, |
| 4140 | struct ieee80211_sta *sta, |
| 4141 | struct ieee80211_key_conf *key) |
| 4142 | { |
| 4143 | int rc = 0; |
| 4144 | u8 encr_type; |
| 4145 | u8 *addr; |
| 4146 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 4147 | |
| 4148 | if (vif->type == NL80211_IFTYPE_STATION) |
| 4149 | return -EOPNOTSUPP; |
| 4150 | |
| 4151 | if (sta == NULL) |
Yogesh Ashok Powar | ff7e9f9 | 2012-01-27 16:08:27 +0530 | [diff] [blame] | 4152 | addr = vif->addr; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4153 | else |
| 4154 | addr = sta->addr; |
| 4155 | |
| 4156 | if (cmd_param == SET_KEY) { |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4157 | rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key); |
| 4158 | if (rc) |
| 4159 | goto out; |
| 4160 | |
| 4161 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40) |
| 4162 | || (key->cipher == WLAN_CIPHER_SUITE_WEP104)) |
| 4163 | encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP; |
| 4164 | else |
| 4165 | encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED; |
| 4166 | |
| 4167 | rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr, |
| 4168 | encr_type); |
| 4169 | if (rc) |
| 4170 | goto out; |
| 4171 | |
| 4172 | mwl8k_vif->is_hw_crypto_enabled = true; |
| 4173 | |
| 4174 | } else { |
| 4175 | rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key); |
| 4176 | |
| 4177 | if (rc) |
| 4178 | goto out; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4179 | } |
| 4180 | out: |
| 4181 | return rc; |
| 4182 | } |
| 4183 | |
| 4184 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4185 | * CMD_UPDATE_STADB. |
| 4186 | */ |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4187 | struct ewc_ht_info { |
| 4188 | __le16 control1; |
| 4189 | __le16 control2; |
| 4190 | __le16 control3; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4191 | } __packed; |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4192 | |
| 4193 | struct peer_capability_info { |
| 4194 | /* Peer type - AP vs. STA. */ |
| 4195 | __u8 peer_type; |
| 4196 | |
| 4197 | /* Basic 802.11 capabilities from assoc resp. */ |
| 4198 | __le16 basic_caps; |
| 4199 | |
| 4200 | /* Set if peer supports 802.11n high throughput (HT). */ |
| 4201 | __u8 ht_support; |
| 4202 | |
| 4203 | /* Valid if HT is supported. */ |
| 4204 | __le16 ht_caps; |
| 4205 | __u8 extended_ht_caps; |
| 4206 | struct ewc_ht_info ewc_info; |
| 4207 | |
| 4208 | /* Legacy rate table. Intersection of our rates and peer rates. */ |
| 4209 | __u8 legacy_rates[12]; |
| 4210 | |
| 4211 | /* HT rate table. Intersection of our rates and peer rates. */ |
| 4212 | __u8 ht_rates[16]; |
| 4213 | __u8 pad[16]; |
| 4214 | |
| 4215 | /* If set, interoperability mode, no proprietary extensions. */ |
| 4216 | __u8 interop; |
| 4217 | __u8 pad2; |
| 4218 | __u8 station_id; |
| 4219 | __le16 amsdu_enabled; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4220 | } __packed; |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4221 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4222 | struct mwl8k_cmd_update_stadb { |
| 4223 | struct mwl8k_cmd_pkt header; |
| 4224 | |
| 4225 | /* See STADB_ACTION_TYPE */ |
| 4226 | __le32 action; |
| 4227 | |
| 4228 | /* Peer MAC address */ |
| 4229 | __u8 peer_addr[ETH_ALEN]; |
| 4230 | |
| 4231 | __le32 reserved; |
| 4232 | |
| 4233 | /* Peer info - valid during add/update. */ |
| 4234 | struct peer_capability_info peer_info; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4235 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4236 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4237 | #define MWL8K_STA_DB_MODIFY_ENTRY 1 |
| 4238 | #define MWL8K_STA_DB_DEL_ENTRY 2 |
| 4239 | |
| 4240 | /* Peer Entry flags - used to define the type of the peer node */ |
| 4241 | #define MWL8K_PEER_TYPE_ACCESSPOINT 2 |
| 4242 | |
| 4243 | static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw, |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4244 | struct ieee80211_vif *vif, |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4245 | struct ieee80211_sta *sta) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4246 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4247 | struct mwl8k_cmd_update_stadb *cmd; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4248 | struct peer_capability_info *p; |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4249 | u32 rates; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4250 | int rc; |
| 4251 | |
| 4252 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4253 | if (cmd == NULL) |
| 4254 | return -ENOMEM; |
| 4255 | |
| 4256 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB); |
| 4257 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4258 | cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4259 | memcpy(cmd->peer_addr, sta->addr, ETH_ALEN); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4260 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4261 | p = &cmd->peer_info; |
| 4262 | p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT; |
| 4263 | p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4264 | p->ht_support = sta->ht_cap.ht_supported; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 4265 | p->ht_caps = cpu_to_le16(sta->ht_cap.cap); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4266 | p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) | |
| 4267 | ((sta->ht_cap.ampdu_density & 7) << 2); |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4268 | if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) |
| 4269 | rates = sta->supp_rates[IEEE80211_BAND_2GHZ]; |
| 4270 | else |
| 4271 | rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 4272 | legacy_rate_mask_to_array(p->legacy_rates, rates); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4273 | memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16); |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4274 | p->interop = 1; |
| 4275 | p->amsdu_enabled = 0; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4276 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4277 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 4278 | kfree(cmd); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4279 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4280 | return rc ? rc : p->station_id; |
| 4281 | } |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4282 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4283 | static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw, |
| 4284 | struct ieee80211_vif *vif, u8 *addr) |
| 4285 | { |
| 4286 | struct mwl8k_cmd_update_stadb *cmd; |
| 4287 | int rc; |
| 4288 | |
| 4289 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4290 | if (cmd == NULL) |
| 4291 | return -ENOMEM; |
| 4292 | |
| 4293 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB); |
| 4294 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 4295 | cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY); |
| 4296 | memcpy(cmd->peer_addr, addr, ETH_ALEN); |
| 4297 | |
| 4298 | rc = mwl8k_post_cmd(hw, &cmd->header); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4299 | kfree(cmd); |
| 4300 | |
| 4301 | return rc; |
| 4302 | } |
| 4303 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4304 | |
| 4305 | /* |
| 4306 | * Interrupt handling. |
| 4307 | */ |
| 4308 | static irqreturn_t mwl8k_interrupt(int irq, void *dev_id) |
| 4309 | { |
| 4310 | struct ieee80211_hw *hw = dev_id; |
| 4311 | struct mwl8k_priv *priv = hw->priv; |
| 4312 | u32 status; |
| 4313 | |
| 4314 | status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4315 | if (!status) |
| 4316 | return IRQ_NONE; |
| 4317 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4318 | if (status & MWL8K_A2H_INT_TX_DONE) { |
| 4319 | status &= ~MWL8K_A2H_INT_TX_DONE; |
| 4320 | tasklet_schedule(&priv->poll_tx_task); |
| 4321 | } |
| 4322 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4323 | if (status & MWL8K_A2H_INT_RX_READY) { |
| 4324 | status &= ~MWL8K_A2H_INT_RX_READY; |
| 4325 | tasklet_schedule(&priv->poll_rx_task); |
| 4326 | } |
| 4327 | |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 4328 | if (status & MWL8K_A2H_INT_BA_WATCHDOG) { |
| 4329 | status &= ~MWL8K_A2H_INT_BA_WATCHDOG; |
| 4330 | ieee80211_queue_work(hw, &priv->watchdog_ba_handle); |
| 4331 | } |
| 4332 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4333 | if (status) |
| 4334 | iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4335 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4336 | if (status & MWL8K_A2H_INT_OPC_DONE) { |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4337 | if (priv->hostcmd_wait != NULL) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4338 | complete(priv->hostcmd_wait); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | if (status & MWL8K_A2H_INT_QUEUE_EMPTY) { |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4342 | if (!mutex_is_locked(&priv->fw_mutex) && |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 4343 | priv->radio_on && priv->pending_tx_pkts) |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4344 | mwl8k_tx_start(priv); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | return IRQ_HANDLED; |
| 4348 | } |
| 4349 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4350 | static void mwl8k_tx_poll(unsigned long data) |
| 4351 | { |
| 4352 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 4353 | struct mwl8k_priv *priv = hw->priv; |
| 4354 | int limit; |
| 4355 | int i; |
| 4356 | |
| 4357 | limit = 32; |
| 4358 | |
| 4359 | spin_lock_bh(&priv->tx_lock); |
| 4360 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 4361 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4362 | limit -= mwl8k_txq_reclaim(hw, i, limit, 0); |
| 4363 | |
| 4364 | if (!priv->pending_tx_pkts && priv->tx_wait != NULL) { |
| 4365 | complete(priv->tx_wait); |
| 4366 | priv->tx_wait = NULL; |
| 4367 | } |
| 4368 | |
| 4369 | spin_unlock_bh(&priv->tx_lock); |
| 4370 | |
| 4371 | if (limit) { |
| 4372 | writel(~MWL8K_A2H_INT_TX_DONE, |
| 4373 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 4374 | } else { |
| 4375 | tasklet_schedule(&priv->poll_tx_task); |
| 4376 | } |
| 4377 | } |
| 4378 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4379 | static void mwl8k_rx_poll(unsigned long data) |
| 4380 | { |
| 4381 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 4382 | struct mwl8k_priv *priv = hw->priv; |
| 4383 | int limit; |
| 4384 | |
| 4385 | limit = 32; |
| 4386 | limit -= rxq_process(hw, 0, limit); |
| 4387 | limit -= rxq_refill(hw, 0, limit); |
| 4388 | |
| 4389 | if (limit) { |
| 4390 | writel(~MWL8K_A2H_INT_RX_READY, |
| 4391 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 4392 | } else { |
| 4393 | tasklet_schedule(&priv->poll_rx_task); |
| 4394 | } |
| 4395 | } |
| 4396 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4397 | |
| 4398 | /* |
| 4399 | * Core driver operations. |
| 4400 | */ |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 4401 | static void mwl8k_tx(struct ieee80211_hw *hw, |
| 4402 | struct ieee80211_tx_control *control, |
| 4403 | struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4404 | { |
| 4405 | struct mwl8k_priv *priv = hw->priv; |
| 4406 | int index = skb_get_queue_mapping(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4407 | |
Lennert Buytenhek | 9189c10 | 2010-01-12 13:47:32 +0100 | [diff] [blame] | 4408 | if (!priv->radio_on) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4409 | wiphy_debug(hw->wiphy, |
| 4410 | "dropped TX frame since radio disabled\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4411 | dev_kfree_skb(skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 4412 | return; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4413 | } |
| 4414 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 4415 | mwl8k_txq_xmit(hw, index, control->sta, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4416 | } |
| 4417 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4418 | static int mwl8k_start(struct ieee80211_hw *hw) |
| 4419 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4420 | struct mwl8k_priv *priv = hw->priv; |
| 4421 | int rc; |
| 4422 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 4423 | rc = request_irq(priv->pdev->irq, mwl8k_interrupt, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4424 | IRQF_SHARED, MWL8K_NAME, hw); |
| 4425 | if (rc) { |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4426 | priv->irq = -1; |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 4427 | wiphy_err(hw->wiphy, "failed to register IRQ handler\n"); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4428 | return -EIO; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4429 | } |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4430 | priv->irq = priv->pdev->irq; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4431 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4432 | /* Enable TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4433 | tasklet_enable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4434 | tasklet_enable(&priv->poll_rx_task); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4435 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4436 | /* Enable interrupts */ |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 4437 | iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Nishant Sarmukadam | 12488e0 | 2011-04-08 14:38:27 +0530 | [diff] [blame] | 4438 | iowrite32(MWL8K_A2H_EVENTS, |
| 4439 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4440 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4441 | rc = mwl8k_fw_lock(hw); |
| 4442 | if (!rc) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4443 | rc = mwl8k_cmd_radio_enable(hw); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4444 | |
Lennert Buytenhek | 5e4cf16 | 2009-10-22 20:21:38 +0200 | [diff] [blame] | 4445 | if (!priv->ap_fw) { |
| 4446 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4447 | rc = mwl8k_cmd_enable_sniffer(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4448 | |
Lennert Buytenhek | 5e4cf16 | 2009-10-22 20:21:38 +0200 | [diff] [blame] | 4449 | if (!rc) |
| 4450 | rc = mwl8k_cmd_set_pre_scan(hw); |
| 4451 | |
| 4452 | if (!rc) |
| 4453 | rc = mwl8k_cmd_set_post_scan(hw, |
| 4454 | "\x00\x00\x00\x00\x00\x00"); |
| 4455 | } |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4456 | |
| 4457 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4458 | rc = mwl8k_cmd_set_rateadapt_mode(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4459 | |
| 4460 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4461 | rc = mwl8k_cmd_set_wmm_mode(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4462 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4463 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4464 | } |
| 4465 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4466 | if (rc) { |
| 4467 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 4468 | free_irq(priv->pdev->irq, hw); |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4469 | priv->irq = -1; |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4470 | tasklet_disable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4471 | tasklet_disable(&priv->poll_rx_task); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4472 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4473 | |
| 4474 | return rc; |
| 4475 | } |
| 4476 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4477 | static void mwl8k_stop(struct ieee80211_hw *hw) |
| 4478 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4479 | struct mwl8k_priv *priv = hw->priv; |
| 4480 | int i; |
| 4481 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 4482 | if (!priv->hw_restart_in_progress) |
| 4483 | mwl8k_cmd_radio_disable(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4484 | |
| 4485 | ieee80211_stop_queues(hw); |
| 4486 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4487 | /* Disable interrupts */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4488 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4489 | if (priv->irq != -1) { |
| 4490 | free_irq(priv->pdev->irq, hw); |
| 4491 | priv->irq = -1; |
| 4492 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4493 | |
| 4494 | /* Stop finalize join worker */ |
| 4495 | cancel_work_sync(&priv->finalize_join_worker); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 4496 | cancel_work_sync(&priv->watchdog_ba_handle); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4497 | if (priv->beacon_skb != NULL) |
| 4498 | dev_kfree_skb(priv->beacon_skb); |
| 4499 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4500 | /* Stop TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4501 | tasklet_disable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4502 | tasklet_disable(&priv->poll_rx_task); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4503 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4504 | /* Return all skbs to mac80211 */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 4505 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 4506 | mwl8k_txq_reclaim(hw, i, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4507 | } |
| 4508 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4509 | static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image); |
| 4510 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4511 | static int mwl8k_add_interface(struct ieee80211_hw *hw, |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4512 | struct ieee80211_vif *vif) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4513 | { |
| 4514 | struct mwl8k_priv *priv = hw->priv; |
| 4515 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4516 | u32 macids_supported; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4517 | int macid, rc; |
| 4518 | struct mwl8k_device_info *di; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4519 | |
| 4520 | /* |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4521 | * Reject interface creation if sniffer mode is active, as |
| 4522 | * STA operation is mutually exclusive with hardware sniffer |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4523 | * mode. (Sniffer mode is only used on STA firmware.) |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4524 | */ |
| 4525 | if (priv->sniffer_enabled) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4526 | wiphy_info(hw->wiphy, |
| 4527 | "unable to create STA interface because sniffer mode is enabled\n"); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4528 | return -EINVAL; |
| 4529 | } |
| 4530 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4531 | di = priv->device_info; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4532 | switch (vif->type) { |
| 4533 | case NL80211_IFTYPE_AP: |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4534 | if (!priv->ap_fw && di->fw_image_ap) { |
| 4535 | /* we must load the ap fw to meet this request */ |
| 4536 | if (!list_empty(&priv->vif_list)) |
| 4537 | return -EBUSY; |
| 4538 | rc = mwl8k_reload_firmware(hw, di->fw_image_ap); |
| 4539 | if (rc) |
| 4540 | return rc; |
| 4541 | } |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4542 | macids_supported = priv->ap_macids_supported; |
| 4543 | break; |
| 4544 | case NL80211_IFTYPE_STATION: |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4545 | if (priv->ap_fw && di->fw_image_sta) { |
| 4546 | /* we must load the sta fw to meet this request */ |
| 4547 | if (!list_empty(&priv->vif_list)) |
| 4548 | return -EBUSY; |
| 4549 | rc = mwl8k_reload_firmware(hw, di->fw_image_sta); |
| 4550 | if (rc) |
| 4551 | return rc; |
| 4552 | } |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4553 | macids_supported = priv->sta_macids_supported; |
| 4554 | break; |
| 4555 | default: |
| 4556 | return -EINVAL; |
| 4557 | } |
| 4558 | |
| 4559 | macid = ffs(macids_supported & ~priv->macids_used); |
| 4560 | if (!macid--) |
| 4561 | return -EBUSY; |
| 4562 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4563 | /* Setup driver private area. */ |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 4564 | mwl8k_vif = MWL8K_VIF(vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4565 | memset(mwl8k_vif, 0, sizeof(*mwl8k_vif)); |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4566 | mwl8k_vif->vif = vif; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4567 | mwl8k_vif->macid = macid; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4568 | mwl8k_vif->seqno = 0; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 4569 | memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN); |
| 4570 | mwl8k_vif->is_hw_crypto_enabled = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4571 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4572 | /* Set the mac address. */ |
| 4573 | mwl8k_cmd_set_mac_addr(hw, vif, vif->addr); |
| 4574 | |
| 4575 | if (priv->ap_fw) |
| 4576 | mwl8k_cmd_set_new_stn_add_self(hw, vif); |
| 4577 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4578 | priv->macids_used |= 1 << mwl8k_vif->macid; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4579 | list_add_tail(&mwl8k_vif->list, &priv->vif_list); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4580 | |
| 4581 | return 0; |
| 4582 | } |
| 4583 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 4584 | static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif) |
| 4585 | { |
| 4586 | /* Has ieee80211_restart_hw re-added the removed interfaces? */ |
| 4587 | if (!priv->macids_used) |
| 4588 | return; |
| 4589 | |
| 4590 | priv->macids_used &= ~(1 << vif->macid); |
| 4591 | list_del(&vif->list); |
| 4592 | } |
| 4593 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4594 | static void mwl8k_remove_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 4595 | struct ieee80211_vif *vif) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4596 | { |
| 4597 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4598 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4599 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4600 | if (priv->ap_fw) |
| 4601 | mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr); |
| 4602 | |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 4603 | mwl8k_cmd_del_mac_addr(hw, vif, vif->addr); |
Lennert Buytenhek | 32060e1 | 2009-10-22 20:20:04 +0200 | [diff] [blame] | 4604 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 4605 | mwl8k_remove_vif(priv, mwl8k_vif); |
| 4606 | } |
| 4607 | |
| 4608 | static void mwl8k_hw_restart_work(struct work_struct *work) |
| 4609 | { |
| 4610 | struct mwl8k_priv *priv = |
| 4611 | container_of(work, struct mwl8k_priv, fw_reload); |
| 4612 | struct ieee80211_hw *hw = priv->hw; |
| 4613 | struct mwl8k_device_info *di; |
| 4614 | int rc; |
| 4615 | |
| 4616 | /* If some command is waiting for a response, clear it */ |
| 4617 | if (priv->hostcmd_wait != NULL) { |
| 4618 | complete(priv->hostcmd_wait); |
| 4619 | priv->hostcmd_wait = NULL; |
| 4620 | } |
| 4621 | |
| 4622 | priv->hw_restart_owner = current; |
| 4623 | di = priv->device_info; |
| 4624 | mwl8k_fw_lock(hw); |
| 4625 | |
| 4626 | if (priv->ap_fw) |
| 4627 | rc = mwl8k_reload_firmware(hw, di->fw_image_ap); |
| 4628 | else |
| 4629 | rc = mwl8k_reload_firmware(hw, di->fw_image_sta); |
| 4630 | |
| 4631 | if (rc) |
| 4632 | goto fail; |
| 4633 | |
| 4634 | priv->hw_restart_owner = NULL; |
| 4635 | priv->hw_restart_in_progress = false; |
| 4636 | |
| 4637 | /* |
| 4638 | * This unlock will wake up the queues and |
| 4639 | * also opens the command path for other |
| 4640 | * commands |
| 4641 | */ |
| 4642 | mwl8k_fw_unlock(hw); |
| 4643 | |
| 4644 | ieee80211_restart_hw(hw); |
| 4645 | |
| 4646 | wiphy_err(hw->wiphy, "Firmware restarted successfully\n"); |
| 4647 | |
| 4648 | return; |
| 4649 | fail: |
| 4650 | mwl8k_fw_unlock(hw); |
| 4651 | |
| 4652 | wiphy_err(hw->wiphy, "Firmware restart failed\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4653 | } |
| 4654 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4655 | static int mwl8k_config(struct ieee80211_hw *hw, u32 changed) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4656 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4657 | struct ieee80211_conf *conf = &hw->conf; |
| 4658 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4659 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4660 | |
Lennert Buytenhek | 7595d67 | 2009-08-17 23:59:40 +0200 | [diff] [blame] | 4661 | if (conf->flags & IEEE80211_CONF_IDLE) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4662 | mwl8k_cmd_radio_disable(hw); |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4663 | return 0; |
Lennert Buytenhek | 7595d67 | 2009-08-17 23:59:40 +0200 | [diff] [blame] | 4664 | } |
| 4665 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4666 | rc = mwl8k_fw_lock(hw); |
| 4667 | if (rc) |
| 4668 | return rc; |
| 4669 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4670 | rc = mwl8k_cmd_radio_enable(hw); |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4671 | if (rc) |
| 4672 | goto out; |
| 4673 | |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 4674 | rc = mwl8k_cmd_set_rf_channel(hw, conf); |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4675 | if (rc) |
| 4676 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4677 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4678 | if (conf->power_level > 18) |
| 4679 | conf->power_level = 18; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4680 | |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4681 | if (priv->ap_fw) { |
Nishant Sarmukadam | 0321708 | 2011-04-05 14:18:09 +0530 | [diff] [blame] | 4682 | |
| 4683 | if (conf->flags & IEEE80211_CONF_CHANGE_POWER) { |
| 4684 | rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level); |
| 4685 | if (rc) |
| 4686 | goto out; |
| 4687 | } |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 4688 | |
Nishant Sarmukadam | da62b76 | 2011-02-17 14:45:16 -0800 | [diff] [blame] | 4689 | rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3); |
| 4690 | if (rc) |
| 4691 | wiphy_warn(hw->wiphy, "failed to set # of RX antennas"); |
| 4692 | rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7); |
| 4693 | if (rc) |
| 4694 | wiphy_warn(hw->wiphy, "failed to set # of TX antennas"); |
| 4695 | |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4696 | } else { |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 4697 | rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level); |
| 4698 | if (rc) |
| 4699 | goto out; |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4700 | rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7); |
| 4701 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4702 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4703 | out: |
| 4704 | mwl8k_fw_unlock(hw); |
| 4705 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4706 | return rc; |
| 4707 | } |
| 4708 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4709 | static void |
| 4710 | mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4711 | struct ieee80211_bss_conf *info, u32 changed) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4712 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4713 | struct mwl8k_priv *priv = hw->priv; |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 4714 | u32 ap_legacy_rates = 0; |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4715 | u8 ap_mcs_rates[16]; |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4716 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4717 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4718 | if (mwl8k_fw_lock(hw)) |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4719 | return; |
| 4720 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4721 | /* |
| 4722 | * No need to capture a beacon if we're no longer associated. |
| 4723 | */ |
| 4724 | if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc) |
| 4725 | priv->capture_beacon = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4726 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4727 | /* |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4728 | * Get the AP's legacy and MCS rates. |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4729 | */ |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4730 | if (vif->bss_conf.assoc) { |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4731 | struct ieee80211_sta *ap; |
Lennert Buytenhek | c97470d | 2010-01-12 13:47:37 +0100 | [diff] [blame] | 4732 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4733 | rcu_read_lock(); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4734 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4735 | ap = ieee80211_find_sta(vif, vif->bss_conf.bssid); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4736 | if (ap == NULL) { |
| 4737 | rcu_read_unlock(); |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4738 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4739 | } |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4740 | |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4741 | if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) { |
| 4742 | ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ]; |
| 4743 | } else { |
| 4744 | ap_legacy_rates = |
| 4745 | ap->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 4746 | } |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4747 | memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4748 | |
| 4749 | rcu_read_unlock(); |
| 4750 | } |
| 4751 | |
| 4752 | if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) { |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4753 | rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4754 | if (rc) |
| 4755 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4756 | |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 4757 | rc = mwl8k_cmd_use_fixed_rate_sta(hw); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4758 | if (rc) |
| 4759 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4760 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4761 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4762 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4763 | rc = mwl8k_set_radio_preamble(hw, |
| 4764 | vif->bss_conf.use_short_preamble); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4765 | if (rc) |
| 4766 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4767 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4768 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4769 | if (changed & BSS_CHANGED_ERP_SLOT) { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4770 | rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4771 | if (rc) |
| 4772 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4773 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4774 | |
Lennert Buytenhek | c97470d | 2010-01-12 13:47:37 +0100 | [diff] [blame] | 4775 | if (vif->bss_conf.assoc && |
| 4776 | (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT | |
| 4777 | BSS_CHANGED_HT))) { |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4778 | rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4779 | if (rc) |
| 4780 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4781 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4782 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4783 | if (vif->bss_conf.assoc && |
| 4784 | (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4785 | /* |
| 4786 | * Finalize the join. Tell rx handler to process |
| 4787 | * next beacon from our BSSID. |
| 4788 | */ |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 4789 | memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4790 | priv->capture_beacon = true; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4791 | } |
| 4792 | |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4793 | out: |
| 4794 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4795 | } |
| 4796 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4797 | static void |
| 4798 | mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4799 | struct ieee80211_bss_conf *info, u32 changed) |
| 4800 | { |
| 4801 | int rc; |
| 4802 | |
| 4803 | if (mwl8k_fw_lock(hw)) |
| 4804 | return; |
| 4805 | |
| 4806 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 4807 | rc = mwl8k_set_radio_preamble(hw, |
| 4808 | vif->bss_conf.use_short_preamble); |
| 4809 | if (rc) |
| 4810 | goto out; |
| 4811 | } |
| 4812 | |
| 4813 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 4814 | int idx; |
| 4815 | int rate; |
| 4816 | |
| 4817 | /* |
| 4818 | * Use lowest supported basic rate for multicasts |
| 4819 | * and management frames (such as probe responses -- |
| 4820 | * beacons will always go out at 1 Mb/s). |
| 4821 | */ |
| 4822 | idx = ffs(vif->bss_conf.basic_rates); |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4823 | if (idx) |
| 4824 | idx--; |
| 4825 | |
| 4826 | if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) |
| 4827 | rate = mwl8k_rates_24[idx].hw_value; |
| 4828 | else |
| 4829 | rate = mwl8k_rates_50[idx].hw_value; |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4830 | |
| 4831 | mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate); |
| 4832 | } |
| 4833 | |
| 4834 | if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) { |
| 4835 | struct sk_buff *skb; |
| 4836 | |
| 4837 | skb = ieee80211_beacon_get(hw, vif); |
| 4838 | if (skb != NULL) { |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4839 | mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4840 | kfree_skb(skb); |
| 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | if (changed & BSS_CHANGED_BEACON_ENABLED) |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4845 | mwl8k_cmd_bss_start(hw, vif, info->enable_beacon); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4846 | |
| 4847 | out: |
| 4848 | mwl8k_fw_unlock(hw); |
| 4849 | } |
| 4850 | |
| 4851 | static void |
| 4852 | mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4853 | struct ieee80211_bss_conf *info, u32 changed) |
| 4854 | { |
| 4855 | struct mwl8k_priv *priv = hw->priv; |
| 4856 | |
| 4857 | if (!priv->ap_fw) |
| 4858 | mwl8k_bss_info_changed_sta(hw, vif, info, changed); |
| 4859 | else |
| 4860 | mwl8k_bss_info_changed_ap(hw, vif, info, changed); |
| 4861 | } |
| 4862 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 4863 | static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw, |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4864 | struct netdev_hw_addr_list *mc_list) |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 4865 | { |
| 4866 | struct mwl8k_cmd_pkt *cmd; |
| 4867 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 4868 | /* |
| 4869 | * Synthesize and return a command packet that programs the |
| 4870 | * hardware multicast address filter. At this point we don't |
| 4871 | * know whether FIF_ALLMULTI is being requested, but if it is, |
| 4872 | * we'll end up throwing this packet away and creating a new |
| 4873 | * one in mwl8k_configure_filter(). |
| 4874 | */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4875 | cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list); |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 4876 | |
| 4877 | return (unsigned long)cmd; |
| 4878 | } |
| 4879 | |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4880 | static int |
| 4881 | mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw, |
| 4882 | unsigned int changed_flags, |
| 4883 | unsigned int *total_flags) |
| 4884 | { |
| 4885 | struct mwl8k_priv *priv = hw->priv; |
| 4886 | |
| 4887 | /* |
| 4888 | * Hardware sniffer mode is mutually exclusive with STA |
| 4889 | * operation, so refuse to enable sniffer mode if a STA |
| 4890 | * interface is active. |
| 4891 | */ |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4892 | if (!list_empty(&priv->vif_list)) { |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4893 | if (net_ratelimit()) |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4894 | wiphy_info(hw->wiphy, |
| 4895 | "not enabling sniffer mode because STA interface is active\n"); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4896 | return 0; |
| 4897 | } |
| 4898 | |
| 4899 | if (!priv->sniffer_enabled) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4900 | if (mwl8k_cmd_enable_sniffer(hw, 1)) |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4901 | return 0; |
| 4902 | priv->sniffer_enabled = true; |
| 4903 | } |
| 4904 | |
| 4905 | *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI | |
| 4906 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL | |
| 4907 | FIF_OTHER_BSS; |
| 4908 | |
| 4909 | return 1; |
| 4910 | } |
| 4911 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4912 | static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv) |
| 4913 | { |
| 4914 | if (!list_empty(&priv->vif_list)) |
| 4915 | return list_entry(priv->vif_list.next, struct mwl8k_vif, list); |
| 4916 | |
| 4917 | return NULL; |
| 4918 | } |
| 4919 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4920 | static void mwl8k_configure_filter(struct ieee80211_hw *hw, |
| 4921 | unsigned int changed_flags, |
| 4922 | unsigned int *total_flags, |
| 4923 | u64 multicast) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4924 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4925 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4926 | struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast; |
| 4927 | |
| 4928 | /* |
Lennert Buytenhek | c0adae2 | 2009-10-22 20:21:36 +0200 | [diff] [blame] | 4929 | * AP firmware doesn't allow fine-grained control over |
| 4930 | * the receive filter. |
| 4931 | */ |
| 4932 | if (priv->ap_fw) { |
| 4933 | *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC; |
| 4934 | kfree(cmd); |
| 4935 | return; |
| 4936 | } |
| 4937 | |
| 4938 | /* |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4939 | * Enable hardware sniffer mode if FIF_CONTROL or |
| 4940 | * FIF_OTHER_BSS is requested. |
| 4941 | */ |
| 4942 | if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) && |
| 4943 | mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) { |
| 4944 | kfree(cmd); |
| 4945 | return; |
| 4946 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4947 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4948 | /* Clear unsupported feature flags */ |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 4949 | *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC; |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4950 | |
Lennert Buytenhek | 90852f7 | 2010-01-02 10:31:42 +0100 | [diff] [blame] | 4951 | if (mwl8k_fw_lock(hw)) { |
| 4952 | kfree(cmd); |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4953 | return; |
Lennert Buytenhek | 90852f7 | 2010-01-02 10:31:42 +0100 | [diff] [blame] | 4954 | } |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4955 | |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4956 | if (priv->sniffer_enabled) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4957 | mwl8k_cmd_enable_sniffer(hw, 0); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4958 | priv->sniffer_enabled = false; |
| 4959 | } |
| 4960 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4961 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 4962 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 4963 | /* |
| 4964 | * Disable the BSS filter. |
| 4965 | */ |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4966 | mwl8k_cmd_set_pre_scan(hw); |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 4967 | } else { |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4968 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 4969 | const u8 *bssid; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 4970 | |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 4971 | /* |
| 4972 | * Enable the BSS filter. |
| 4973 | * |
| 4974 | * If there is an active STA interface, use that |
| 4975 | * interface's BSSID, otherwise use a dummy one |
| 4976 | * (where the OUI part needs to be nonzero for |
| 4977 | * the BSSID to be accepted by POST_SCAN). |
| 4978 | */ |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4979 | mwl8k_vif = mwl8k_first_vif(priv); |
| 4980 | if (mwl8k_vif != NULL) |
| 4981 | bssid = mwl8k_vif->vif->bss_conf.bssid; |
| 4982 | else |
| 4983 | bssid = "\x01\x00\x00\x00\x00\x00"; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 4984 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 4985 | mwl8k_cmd_set_post_scan(hw, bssid); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4986 | } |
| 4987 | } |
| 4988 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 4989 | /* |
| 4990 | * If FIF_ALLMULTI is being requested, throw away the command |
| 4991 | * packet that ->prepare_multicast() built and replace it with |
| 4992 | * a command packet that enables reception of all multicast |
| 4993 | * packets. |
| 4994 | */ |
| 4995 | if (*total_flags & FIF_ALLMULTI) { |
| 4996 | kfree(cmd); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4997 | cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL); |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | if (cmd != NULL) { |
| 5001 | mwl8k_post_cmd(hw, cmd); |
| 5002 | kfree(cmd); |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5003 | } |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 5004 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5005 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5006 | } |
| 5007 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5008 | static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 5009 | { |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 5010 | return mwl8k_cmd_set_rts_threshold(hw, value); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5011 | } |
| 5012 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5013 | static int mwl8k_sta_remove(struct ieee80211_hw *hw, |
| 5014 | struct ieee80211_vif *vif, |
| 5015 | struct ieee80211_sta *sta) |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5016 | { |
| 5017 | struct mwl8k_priv *priv = hw->priv; |
| 5018 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5019 | if (priv->ap_fw) |
| 5020 | return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr); |
| 5021 | else |
| 5022 | return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr); |
| 5023 | } |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5024 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5025 | static int mwl8k_sta_add(struct ieee80211_hw *hw, |
| 5026 | struct ieee80211_vif *vif, |
| 5027 | struct ieee80211_sta *sta) |
| 5028 | { |
| 5029 | struct mwl8k_priv *priv = hw->priv; |
| 5030 | int ret; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5031 | int i; |
| 5032 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 5033 | struct ieee80211_key_conf *key; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5034 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5035 | if (!priv->ap_fw) { |
| 5036 | ret = mwl8k_cmd_update_stadb_add(hw, vif, sta); |
| 5037 | if (ret >= 0) { |
| 5038 | MWL8K_STA(sta)->peer_id = ret; |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 5039 | if (sta->ht_cap.ht_supported) |
| 5040 | MWL8K_STA(sta)->is_ampdu_allowed = true; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5041 | ret = 0; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5042 | } |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5043 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 5044 | } else { |
| 5045 | ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5046 | } |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5047 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 5048 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 5049 | key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key); |
| 5050 | if (mwl8k_vif->wep_key_conf[i].enabled) |
| 5051 | mwl8k_set_key(hw, SET_KEY, vif, sta, key); |
| 5052 | } |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5053 | return ret; |
Lennert Buytenhek | bbfd912 | 2010-01-04 21:55:12 +0100 | [diff] [blame] | 5054 | } |
| 5055 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 5056 | static int mwl8k_conf_tx(struct ieee80211_hw *hw, |
| 5057 | struct ieee80211_vif *vif, u16 queue, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5058 | const struct ieee80211_tx_queue_params *params) |
| 5059 | { |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5060 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5061 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5062 | |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5063 | rc = mwl8k_fw_lock(hw); |
| 5064 | if (!rc) { |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5065 | BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1); |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5066 | memcpy(&priv->wmm_params[queue], params, sizeof(*params)); |
| 5067 | |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5068 | if (!priv->wmm_enabled) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 5069 | rc = mwl8k_cmd_set_wmm_mode(hw, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5070 | |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 5071 | if (!rc) { |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5072 | int q = MWL8K_TX_WMM_QUEUES - 1 - queue; |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 5073 | rc = mwl8k_cmd_set_edca_params(hw, q, |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 5074 | params->cw_min, |
| 5075 | params->cw_max, |
| 5076 | params->aifs, |
| 5077 | params->txop); |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 5078 | } |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5079 | |
| 5080 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5081 | } |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5082 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5083 | return rc; |
| 5084 | } |
| 5085 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5086 | static int mwl8k_get_stats(struct ieee80211_hw *hw, |
| 5087 | struct ieee80211_low_level_stats *stats) |
| 5088 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 5089 | return mwl8k_cmd_get_stat(hw, stats); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5090 | } |
| 5091 | |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 5092 | static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx, |
| 5093 | struct survey_info *survey) |
| 5094 | { |
| 5095 | struct mwl8k_priv *priv = hw->priv; |
| 5096 | struct ieee80211_conf *conf = &hw->conf; |
| 5097 | |
| 5098 | if (idx != 0) |
| 5099 | return -ENOENT; |
| 5100 | |
| 5101 | survey->channel = conf->channel; |
| 5102 | survey->filled = SURVEY_INFO_NOISE_DBM; |
| 5103 | survey->noise = priv->noise; |
| 5104 | |
| 5105 | return 0; |
| 5106 | } |
| 5107 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5108 | #define MAX_AMPDU_ATTEMPTS 5 |
| 5109 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5110 | static int |
| 5111 | mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5112 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 5113 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 5114 | u8 buf_size) |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5115 | { |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5116 | |
| 5117 | int i, rc = 0; |
| 5118 | struct mwl8k_priv *priv = hw->priv; |
| 5119 | struct mwl8k_ampdu_stream *stream; |
| 5120 | u8 *addr = sta->addr; |
Yogesh Ashok Powar | fd712f5 | 2012-11-06 19:22:35 +0530 | [diff] [blame] | 5121 | struct mwl8k_sta *sta_info = MWL8K_STA(sta); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5122 | |
| 5123 | if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION)) |
| 5124 | return -ENOTSUPP; |
| 5125 | |
| 5126 | spin_lock(&priv->stream_lock); |
| 5127 | stream = mwl8k_lookup_stream(hw, addr, tid); |
| 5128 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5129 | switch (action) { |
| 5130 | case IEEE80211_AMPDU_RX_START: |
| 5131 | case IEEE80211_AMPDU_RX_STOP: |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5132 | break; |
| 5133 | case IEEE80211_AMPDU_TX_START: |
| 5134 | /* By the time we get here the hw queues may contain outgoing |
| 5135 | * packets for this RA/TID that are not part of this BA |
| 5136 | * session. The hw will assign sequence numbers to these |
| 5137 | * packets as they go out. So if we query the hw for its next |
| 5138 | * sequence number and use that for the SSN here, it may end up |
| 5139 | * being wrong, which will lead to sequence number mismatch at |
| 5140 | * the recipient. To avoid this, we reset the sequence number |
| 5141 | * to O for the first MPDU in this BA stream. |
| 5142 | */ |
| 5143 | *ssn = 0; |
| 5144 | if (stream == NULL) { |
| 5145 | /* This means that somebody outside this driver called |
| 5146 | * ieee80211_start_tx_ba_session. This is unexpected |
| 5147 | * because we do our own rate control. Just warn and |
| 5148 | * move on. |
| 5149 | */ |
| 5150 | wiphy_warn(hw->wiphy, "Unexpected call to %s. " |
| 5151 | "Proceeding anyway.\n", __func__); |
| 5152 | stream = mwl8k_add_stream(hw, sta, tid); |
| 5153 | } |
| 5154 | if (stream == NULL) { |
| 5155 | wiphy_debug(hw->wiphy, "no free AMPDU streams\n"); |
| 5156 | rc = -EBUSY; |
| 5157 | break; |
| 5158 | } |
| 5159 | stream->state = AMPDU_STREAM_IN_PROGRESS; |
| 5160 | |
| 5161 | /* Release the lock before we do the time consuming stuff */ |
| 5162 | spin_unlock(&priv->stream_lock); |
| 5163 | for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) { |
Yogesh Ashok Powar | fd712f5 | 2012-11-06 19:22:35 +0530 | [diff] [blame] | 5164 | |
| 5165 | /* Check if link is still valid */ |
| 5166 | if (!sta_info->is_ampdu_allowed) { |
| 5167 | spin_lock(&priv->stream_lock); |
| 5168 | mwl8k_remove_stream(hw, stream); |
| 5169 | spin_unlock(&priv->stream_lock); |
| 5170 | return -EBUSY; |
| 5171 | } |
| 5172 | |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 5173 | rc = mwl8k_check_ba(hw, stream, vif); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5174 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5175 | /* If HW restart is in progress mwl8k_post_cmd will |
| 5176 | * return -EBUSY. Avoid retrying mwl8k_check_ba in |
| 5177 | * such cases |
| 5178 | */ |
| 5179 | if (!rc || rc == -EBUSY) |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5180 | break; |
| 5181 | /* |
| 5182 | * HW queues take time to be flushed, give them |
| 5183 | * sufficient time |
| 5184 | */ |
| 5185 | |
| 5186 | msleep(1000); |
| 5187 | } |
| 5188 | spin_lock(&priv->stream_lock); |
| 5189 | if (rc) { |
| 5190 | wiphy_err(hw->wiphy, "Stream for tid %d busy after %d" |
| 5191 | " attempts\n", tid, MAX_AMPDU_ATTEMPTS); |
| 5192 | mwl8k_remove_stream(hw, stream); |
| 5193 | rc = -EBUSY; |
| 5194 | break; |
| 5195 | } |
| 5196 | ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid); |
| 5197 | break; |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 5198 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 5199 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 5200 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Yogesh Ashok Powar | eca107f | 2011-12-20 11:37:08 +0530 | [diff] [blame] | 5201 | if (stream) { |
| 5202 | if (stream->state == AMPDU_STREAM_ACTIVE) { |
| 5203 | spin_unlock(&priv->stream_lock); |
| 5204 | mwl8k_destroy_ba(hw, stream); |
| 5205 | spin_lock(&priv->stream_lock); |
| 5206 | } |
| 5207 | mwl8k_remove_stream(hw, stream); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5208 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5209 | ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid); |
| 5210 | break; |
| 5211 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 5212 | BUG_ON(stream == NULL); |
| 5213 | BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS); |
| 5214 | spin_unlock(&priv->stream_lock); |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 5215 | rc = mwl8k_create_ba(hw, stream, buf_size, vif); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5216 | spin_lock(&priv->stream_lock); |
| 5217 | if (!rc) |
| 5218 | stream->state = AMPDU_STREAM_ACTIVE; |
| 5219 | else { |
| 5220 | spin_unlock(&priv->stream_lock); |
| 5221 | mwl8k_destroy_ba(hw, stream); |
| 5222 | spin_lock(&priv->stream_lock); |
| 5223 | wiphy_debug(hw->wiphy, |
| 5224 | "Failed adding stream for sta %pM tid %d\n", |
| 5225 | addr, tid); |
| 5226 | mwl8k_remove_stream(hw, stream); |
| 5227 | } |
| 5228 | break; |
| 5229 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5230 | default: |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5231 | rc = -ENOTSUPP; |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5232 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5233 | |
| 5234 | spin_unlock(&priv->stream_lock); |
| 5235 | return rc; |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5236 | } |
| 5237 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5238 | static const struct ieee80211_ops mwl8k_ops = { |
| 5239 | .tx = mwl8k_tx, |
| 5240 | .start = mwl8k_start, |
| 5241 | .stop = mwl8k_stop, |
| 5242 | .add_interface = mwl8k_add_interface, |
| 5243 | .remove_interface = mwl8k_remove_interface, |
| 5244 | .config = mwl8k_config, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5245 | .bss_info_changed = mwl8k_bss_info_changed, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 5246 | .prepare_multicast = mwl8k_prepare_multicast, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5247 | .configure_filter = mwl8k_configure_filter, |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5248 | .set_key = mwl8k_set_key, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5249 | .set_rts_threshold = mwl8k_set_rts_threshold, |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5250 | .sta_add = mwl8k_sta_add, |
| 5251 | .sta_remove = mwl8k_sta_remove, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5252 | .conf_tx = mwl8k_conf_tx, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5253 | .get_stats = mwl8k_get_stats, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 5254 | .get_survey = mwl8k_get_survey, |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5255 | .ampdu_action = mwl8k_ampdu_action, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5256 | }; |
| 5257 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5258 | static void mwl8k_finalize_join_worker(struct work_struct *work) |
| 5259 | { |
| 5260 | struct mwl8k_priv *priv = |
| 5261 | container_of(work, struct mwl8k_priv, finalize_join_worker); |
| 5262 | struct sk_buff *skb = priv->beacon_skb; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 5263 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 5264 | int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable); |
| 5265 | const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM, |
| 5266 | mgmt->u.beacon.variable, len); |
| 5267 | int dtim_period = 1; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5268 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 5269 | if (tim && tim[1] >= 2) |
| 5270 | dtim_period = tim[3]; |
| 5271 | |
| 5272 | mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period); |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 5273 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5274 | dev_kfree_skb(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5275 | priv->beacon_skb = NULL; |
| 5276 | } |
| 5277 | |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5278 | enum { |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5279 | MWL8363 = 0, |
| 5280 | MWL8687, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5281 | MWL8366, |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 5282 | }; |
| 5283 | |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 5284 | #define MWL8K_8366_AP_FW_API 2 |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5285 | #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw" |
| 5286 | #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api) |
| 5287 | |
Bill Pemberton | 8dee5ee | 2012-12-03 09:56:36 -0500 | [diff] [blame] | 5288 | static struct mwl8k_device_info mwl8k_info_tbl[] = { |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5289 | [MWL8363] = { |
| 5290 | .part_name = "88w8363", |
| 5291 | .helper_image = "mwl8k/helper_8363.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5292 | .fw_image_sta = "mwl8k/fmimage_8363.fw", |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5293 | }, |
Lennert Buytenhek | 49eb691 | 2009-11-30 18:32:13 +0100 | [diff] [blame] | 5294 | [MWL8687] = { |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5295 | .part_name = "88w8687", |
| 5296 | .helper_image = "mwl8k/helper_8687.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5297 | .fw_image_sta = "mwl8k/fmimage_8687.fw", |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5298 | }, |
Lennert Buytenhek | 49eb691 | 2009-11-30 18:32:13 +0100 | [diff] [blame] | 5299 | [MWL8366] = { |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5300 | .part_name = "88w8366", |
| 5301 | .helper_image = "mwl8k/helper_8366.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5302 | .fw_image_sta = "mwl8k/fmimage_8366.fw", |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5303 | .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API), |
| 5304 | .fw_api_ap = MWL8K_8366_AP_FW_API, |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 5305 | .ap_rxd_ops = &rxd_8366_ap_ops, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5306 | }, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5307 | }; |
| 5308 | |
Lennert Buytenhek | c92d4ed | 2010-01-12 13:47:22 +0100 | [diff] [blame] | 5309 | MODULE_FIRMWARE("mwl8k/helper_8363.fw"); |
| 5310 | MODULE_FIRMWARE("mwl8k/fmimage_8363.fw"); |
| 5311 | MODULE_FIRMWARE("mwl8k/helper_8687.fw"); |
| 5312 | MODULE_FIRMWARE("mwl8k/fmimage_8687.fw"); |
| 5313 | MODULE_FIRMWARE("mwl8k/helper_8366.fw"); |
| 5314 | MODULE_FIRMWARE("mwl8k/fmimage_8366.fw"); |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5315 | MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API)); |
Lennert Buytenhek | c92d4ed | 2010-01-12 13:47:22 +0100 | [diff] [blame] | 5316 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5317 | static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = { |
Benjamin Larsson | e5868ba | 2010-03-19 01:46:10 +0100 | [diff] [blame] | 5318 | { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, }, |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5319 | { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, }, |
| 5320 | { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, }, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5321 | { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, }, |
| 5322 | { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, }, |
| 5323 | { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, }, |
Lennert Buytenhek | ca66527 | 2010-01-12 13:47:53 +0100 | [diff] [blame] | 5324 | { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, }, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5325 | { }, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5326 | }; |
| 5327 | MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table); |
| 5328 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5329 | static int mwl8k_request_alt_fw(struct mwl8k_priv *priv) |
| 5330 | { |
| 5331 | int rc; |
| 5332 | printk(KERN_ERR "%s: Error requesting preferred fw %s.\n" |
| 5333 | "Trying alternative firmware %s\n", pci_name(priv->pdev), |
| 5334 | priv->fw_pref, priv->fw_alt); |
| 5335 | rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true); |
| 5336 | if (rc) { |
| 5337 | printk(KERN_ERR "%s: Error requesting alt fw %s\n", |
| 5338 | pci_name(priv->pdev), priv->fw_alt); |
| 5339 | return rc; |
| 5340 | } |
| 5341 | return 0; |
| 5342 | } |
| 5343 | |
| 5344 | static int mwl8k_firmware_load_success(struct mwl8k_priv *priv); |
| 5345 | static void mwl8k_fw_state_machine(const struct firmware *fw, void *context) |
| 5346 | { |
| 5347 | struct mwl8k_priv *priv = context; |
| 5348 | struct mwl8k_device_info *di = priv->device_info; |
| 5349 | int rc; |
| 5350 | |
| 5351 | switch (priv->fw_state) { |
| 5352 | case FW_STATE_INIT: |
| 5353 | if (!fw) { |
| 5354 | printk(KERN_ERR "%s: Error requesting helper fw %s\n", |
| 5355 | pci_name(priv->pdev), di->helper_image); |
| 5356 | goto fail; |
| 5357 | } |
| 5358 | priv->fw_helper = fw; |
| 5359 | rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode, |
| 5360 | true); |
| 5361 | if (rc && priv->fw_alt) { |
| 5362 | rc = mwl8k_request_alt_fw(priv); |
| 5363 | if (rc) |
| 5364 | goto fail; |
| 5365 | priv->fw_state = FW_STATE_LOADING_ALT; |
| 5366 | } else if (rc) |
| 5367 | goto fail; |
| 5368 | else |
| 5369 | priv->fw_state = FW_STATE_LOADING_PREF; |
| 5370 | break; |
| 5371 | |
| 5372 | case FW_STATE_LOADING_PREF: |
| 5373 | if (!fw) { |
| 5374 | if (priv->fw_alt) { |
| 5375 | rc = mwl8k_request_alt_fw(priv); |
| 5376 | if (rc) |
| 5377 | goto fail; |
| 5378 | priv->fw_state = FW_STATE_LOADING_ALT; |
| 5379 | } else |
| 5380 | goto fail; |
| 5381 | } else { |
| 5382 | priv->fw_ucode = fw; |
| 5383 | rc = mwl8k_firmware_load_success(priv); |
| 5384 | if (rc) |
| 5385 | goto fail; |
| 5386 | else |
| 5387 | complete(&priv->firmware_loading_complete); |
| 5388 | } |
| 5389 | break; |
| 5390 | |
| 5391 | case FW_STATE_LOADING_ALT: |
| 5392 | if (!fw) { |
| 5393 | printk(KERN_ERR "%s: Error requesting alt fw %s\n", |
| 5394 | pci_name(priv->pdev), di->helper_image); |
| 5395 | goto fail; |
| 5396 | } |
| 5397 | priv->fw_ucode = fw; |
| 5398 | rc = mwl8k_firmware_load_success(priv); |
| 5399 | if (rc) |
| 5400 | goto fail; |
| 5401 | else |
| 5402 | complete(&priv->firmware_loading_complete); |
| 5403 | break; |
| 5404 | |
| 5405 | default: |
| 5406 | printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n", |
| 5407 | MWL8K_NAME, priv->fw_state); |
| 5408 | BUG_ON(1); |
| 5409 | } |
| 5410 | |
| 5411 | return; |
| 5412 | |
| 5413 | fail: |
| 5414 | priv->fw_state = FW_STATE_ERROR; |
| 5415 | complete(&priv->firmware_loading_complete); |
| 5416 | device_release_driver(&priv->pdev->dev); |
| 5417 | mwl8k_release_firmware(priv); |
| 5418 | } |
| 5419 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5420 | #define MAX_RESTART_ATTEMPTS 1 |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5421 | static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image, |
| 5422 | bool nowait) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5423 | { |
| 5424 | struct mwl8k_priv *priv = hw->priv; |
| 5425 | int rc; |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5426 | int count = MAX_RESTART_ATTEMPTS; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5427 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5428 | retry: |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5429 | /* Reset firmware and hardware */ |
| 5430 | mwl8k_hw_reset(priv); |
| 5431 | |
| 5432 | /* Ask userland hotplug daemon for the device firmware */ |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5433 | rc = mwl8k_request_firmware(priv, fw_image, nowait); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5434 | if (rc) { |
| 5435 | wiphy_err(hw->wiphy, "Firmware files not found\n"); |
| 5436 | return rc; |
| 5437 | } |
| 5438 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5439 | if (nowait) |
| 5440 | return rc; |
| 5441 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5442 | /* Load firmware into hardware */ |
| 5443 | rc = mwl8k_load_firmware(hw); |
| 5444 | if (rc) |
| 5445 | wiphy_err(hw->wiphy, "Cannot start firmware\n"); |
| 5446 | |
| 5447 | /* Reclaim memory once firmware is successfully loaded */ |
| 5448 | mwl8k_release_firmware(priv); |
| 5449 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5450 | if (rc && count) { |
| 5451 | /* FW did not start successfully; |
| 5452 | * lets try one more time |
| 5453 | */ |
| 5454 | count--; |
| 5455 | wiphy_err(hw->wiphy, "Trying to reload the firmware again\n"); |
| 5456 | msleep(20); |
| 5457 | goto retry; |
| 5458 | } |
| 5459 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5460 | return rc; |
| 5461 | } |
| 5462 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5463 | static int mwl8k_init_txqs(struct ieee80211_hw *hw) |
| 5464 | { |
| 5465 | struct mwl8k_priv *priv = hw->priv; |
| 5466 | int rc = 0; |
| 5467 | int i; |
| 5468 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5469 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5470 | rc = mwl8k_txq_init(hw, i); |
| 5471 | if (rc) |
| 5472 | break; |
| 5473 | if (priv->ap_fw) |
| 5474 | iowrite32(priv->txq[i].txd_dma, |
| 5475 | priv->sram + priv->txq_offset[i]); |
| 5476 | } |
| 5477 | return rc; |
| 5478 | } |
| 5479 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5480 | /* initialize hw after successfully loading a firmware image */ |
| 5481 | static int mwl8k_probe_hw(struct ieee80211_hw *hw) |
| 5482 | { |
| 5483 | struct mwl8k_priv *priv = hw->priv; |
| 5484 | int rc = 0; |
| 5485 | int i; |
| 5486 | |
| 5487 | if (priv->ap_fw) { |
| 5488 | priv->rxd_ops = priv->device_info->ap_rxd_ops; |
| 5489 | if (priv->rxd_ops == NULL) { |
| 5490 | wiphy_err(hw->wiphy, |
| 5491 | "Driver does not have AP firmware image support for this hardware\n"); |
| 5492 | goto err_stop_firmware; |
| 5493 | } |
| 5494 | } else { |
| 5495 | priv->rxd_ops = &rxd_sta_ops; |
| 5496 | } |
| 5497 | |
| 5498 | priv->sniffer_enabled = false; |
| 5499 | priv->wmm_enabled = false; |
| 5500 | priv->pending_tx_pkts = 0; |
| 5501 | |
| 5502 | rc = mwl8k_rxq_init(hw, 0); |
| 5503 | if (rc) |
| 5504 | goto err_stop_firmware; |
| 5505 | rxq_refill(hw, 0, INT_MAX); |
| 5506 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5507 | /* For the sta firmware, we need to know the dma addresses of tx queues |
| 5508 | * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them |
| 5509 | * prior to issuing this command. But for the AP case, we learn the |
| 5510 | * total number of queues from the result CMD_GET_HW_SPEC, so for this |
| 5511 | * case we must initialize the tx queues after. |
| 5512 | */ |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 5513 | priv->num_ampdu_queues = 0; |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5514 | if (!priv->ap_fw) { |
| 5515 | rc = mwl8k_init_txqs(hw); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5516 | if (rc) |
| 5517 | goto err_free_queues; |
| 5518 | } |
| 5519 | |
| 5520 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 5521 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 5522 | iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY| |
| 5523 | MWL8K_A2H_INT_BA_WATCHDOG, |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5524 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL); |
Nishant Sarmukadam | 12488e0 | 2011-04-08 14:38:27 +0530 | [diff] [blame] | 5525 | iowrite32(MWL8K_A2H_INT_OPC_DONE, |
| 5526 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5527 | |
| 5528 | rc = request_irq(priv->pdev->irq, mwl8k_interrupt, |
| 5529 | IRQF_SHARED, MWL8K_NAME, hw); |
| 5530 | if (rc) { |
| 5531 | wiphy_err(hw->wiphy, "failed to register IRQ handler\n"); |
| 5532 | goto err_free_queues; |
| 5533 | } |
| 5534 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5535 | /* |
| 5536 | * When hw restart is requested, |
| 5537 | * mac80211 will take care of clearing |
| 5538 | * the ampdu streams, so do not clear |
| 5539 | * the ampdu state here |
| 5540 | */ |
| 5541 | if (!priv->hw_restart_in_progress) |
| 5542 | memset(priv->ampdu, 0, sizeof(priv->ampdu)); |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 5543 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5544 | /* |
| 5545 | * Temporarily enable interrupts. Initial firmware host |
| 5546 | * commands use interrupts and avoid polling. Disable |
| 5547 | * interrupts when done. |
| 5548 | */ |
| 5549 | iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5550 | |
| 5551 | /* Get config data, mac addrs etc */ |
| 5552 | if (priv->ap_fw) { |
| 5553 | rc = mwl8k_cmd_get_hw_spec_ap(hw); |
| 5554 | if (!rc) |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5555 | rc = mwl8k_init_txqs(hw); |
| 5556 | if (!rc) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5557 | rc = mwl8k_cmd_set_hw_spec(hw); |
| 5558 | } else { |
| 5559 | rc = mwl8k_cmd_get_hw_spec_sta(hw); |
| 5560 | } |
| 5561 | if (rc) { |
| 5562 | wiphy_err(hw->wiphy, "Cannot initialise firmware\n"); |
| 5563 | goto err_free_irq; |
| 5564 | } |
| 5565 | |
| 5566 | /* Turn radio off */ |
| 5567 | rc = mwl8k_cmd_radio_disable(hw); |
| 5568 | if (rc) { |
| 5569 | wiphy_err(hw->wiphy, "Cannot disable\n"); |
| 5570 | goto err_free_irq; |
| 5571 | } |
| 5572 | |
| 5573 | /* Clear MAC address */ |
| 5574 | rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00"); |
| 5575 | if (rc) { |
| 5576 | wiphy_err(hw->wiphy, "Cannot clear MAC address\n"); |
| 5577 | goto err_free_irq; |
| 5578 | } |
| 5579 | |
| 5580 | /* Disable interrupts */ |
| 5581 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5582 | free_irq(priv->pdev->irq, hw); |
| 5583 | |
| 5584 | wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n", |
| 5585 | priv->device_info->part_name, |
| 5586 | priv->hw_rev, hw->wiphy->perm_addr, |
| 5587 | priv->ap_fw ? "AP" : "STA", |
| 5588 | (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff, |
| 5589 | (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff); |
| 5590 | |
| 5591 | return 0; |
| 5592 | |
| 5593 | err_free_irq: |
| 5594 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5595 | free_irq(priv->pdev->irq, hw); |
| 5596 | |
| 5597 | err_free_queues: |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5598 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5599 | mwl8k_txq_deinit(hw, i); |
| 5600 | mwl8k_rxq_deinit(hw, 0); |
| 5601 | |
| 5602 | err_stop_firmware: |
| 5603 | mwl8k_hw_reset(priv); |
| 5604 | |
| 5605 | return rc; |
| 5606 | } |
| 5607 | |
| 5608 | /* |
| 5609 | * invoke mwl8k_reload_firmware to change the firmware image after the device |
| 5610 | * has already been registered |
| 5611 | */ |
| 5612 | static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image) |
| 5613 | { |
| 5614 | int i, rc = 0; |
| 5615 | struct mwl8k_priv *priv = hw->priv; |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5616 | struct mwl8k_vif *vif, *tmp_vif; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5617 | |
| 5618 | mwl8k_stop(hw); |
| 5619 | mwl8k_rxq_deinit(hw, 0); |
| 5620 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5621 | /* |
| 5622 | * All the existing interfaces are re-added by the ieee80211_reconfig; |
| 5623 | * which means driver should remove existing interfaces before calling |
| 5624 | * ieee80211_restart_hw |
| 5625 | */ |
| 5626 | if (priv->hw_restart_in_progress) |
| 5627 | list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list) |
| 5628 | mwl8k_remove_vif(priv, vif); |
| 5629 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5630 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5631 | mwl8k_txq_deinit(hw, i); |
| 5632 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5633 | rc = mwl8k_init_firmware(hw, fw_image, false); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5634 | if (rc) |
| 5635 | goto fail; |
| 5636 | |
| 5637 | rc = mwl8k_probe_hw(hw); |
| 5638 | if (rc) |
| 5639 | goto fail; |
| 5640 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5641 | if (priv->hw_restart_in_progress) |
| 5642 | return rc; |
| 5643 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5644 | rc = mwl8k_start(hw); |
| 5645 | if (rc) |
| 5646 | goto fail; |
| 5647 | |
| 5648 | rc = mwl8k_config(hw, ~0); |
| 5649 | if (rc) |
| 5650 | goto fail; |
| 5651 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5652 | for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) { |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 5653 | rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5654 | if (rc) |
| 5655 | goto fail; |
| 5656 | } |
| 5657 | |
| 5658 | return rc; |
| 5659 | |
| 5660 | fail: |
| 5661 | printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n"); |
| 5662 | return rc; |
| 5663 | } |
| 5664 | |
Yogesh Ashok Powar | 5d377fc | 2012-11-06 19:22:16 +0530 | [diff] [blame] | 5665 | static const struct ieee80211_iface_limit ap_if_limits[] = { |
| 5666 | { .max = 8, .types = BIT(NL80211_IFTYPE_AP) }, |
| 5667 | }; |
| 5668 | |
| 5669 | static const struct ieee80211_iface_combination ap_if_comb = { |
| 5670 | .limits = ap_if_limits, |
| 5671 | .n_limits = ARRAY_SIZE(ap_if_limits), |
| 5672 | .max_interfaces = 8, |
| 5673 | .num_different_channels = 1, |
| 5674 | }; |
| 5675 | |
| 5676 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5677 | static int mwl8k_firmware_load_success(struct mwl8k_priv *priv) |
| 5678 | { |
| 5679 | struct ieee80211_hw *hw = priv->hw; |
| 5680 | int i, rc; |
| 5681 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5682 | rc = mwl8k_load_firmware(hw); |
| 5683 | mwl8k_release_firmware(priv); |
| 5684 | if (rc) { |
| 5685 | wiphy_err(hw->wiphy, "Cannot start firmware\n"); |
| 5686 | return rc; |
| 5687 | } |
| 5688 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5689 | /* |
| 5690 | * Extra headroom is the size of the required DMA header |
| 5691 | * minus the size of the smallest 802.11 frame (CTS frame). |
| 5692 | */ |
| 5693 | hw->extra_tx_headroom = |
| 5694 | sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts); |
| 5695 | |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 5696 | hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0; |
| 5697 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5698 | hw->channel_change_time = 10; |
| 5699 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5700 | hw->queues = MWL8K_TX_WMM_QUEUES; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5701 | |
| 5702 | /* Set rssi values to dBm */ |
Nishant Sarmukadam | 0bf22c3 | 2011-02-17 14:45:17 -0800 | [diff] [blame] | 5703 | hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL; |
Yogesh Ashok Powar | 2a36a0e | 2011-08-29 17:12:44 +0530 | [diff] [blame] | 5704 | |
| 5705 | /* |
| 5706 | * Ask mac80211 to not to trigger PS mode |
| 5707 | * based on PM bit of incoming frames. |
| 5708 | */ |
| 5709 | if (priv->ap_fw) |
| 5710 | hw->flags |= IEEE80211_HW_AP_LINK_PS; |
| 5711 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5712 | hw->vif_data_size = sizeof(struct mwl8k_vif); |
| 5713 | hw->sta_data_size = sizeof(struct mwl8k_sta); |
| 5714 | |
| 5715 | priv->macids_used = 0; |
| 5716 | INIT_LIST_HEAD(&priv->vif_list); |
| 5717 | |
| 5718 | /* Set default radio state and preamble */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5719 | priv->radio_on = false; |
| 5720 | priv->radio_short_preamble = false; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5721 | |
| 5722 | /* Finalize join worker */ |
| 5723 | INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 5724 | /* Handle watchdog ba events */ |
| 5725 | INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events); |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5726 | /* To reload the firmware if it crashes */ |
| 5727 | INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5728 | |
| 5729 | /* TX reclaim and RX tasklets. */ |
| 5730 | tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw); |
| 5731 | tasklet_disable(&priv->poll_tx_task); |
| 5732 | tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw); |
| 5733 | tasklet_disable(&priv->poll_rx_task); |
| 5734 | |
| 5735 | /* Power management cookie */ |
| 5736 | priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma); |
| 5737 | if (priv->cookie == NULL) |
| 5738 | return -ENOMEM; |
| 5739 | |
| 5740 | mutex_init(&priv->fw_mutex); |
| 5741 | priv->fw_mutex_owner = NULL; |
| 5742 | priv->fw_mutex_depth = 0; |
| 5743 | priv->hostcmd_wait = NULL; |
| 5744 | |
| 5745 | spin_lock_init(&priv->tx_lock); |
| 5746 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 5747 | spin_lock_init(&priv->stream_lock); |
| 5748 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5749 | priv->tx_wait = NULL; |
| 5750 | |
| 5751 | rc = mwl8k_probe_hw(hw); |
| 5752 | if (rc) |
| 5753 | goto err_free_cookie; |
| 5754 | |
| 5755 | hw->wiphy->interface_modes = 0; |
Yogesh Ashok Powar | 5d377fc | 2012-11-06 19:22:16 +0530 | [diff] [blame] | 5756 | |
| 5757 | if (priv->ap_macids_supported || priv->device_info->fw_image_ap) { |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5758 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP); |
Yogesh Ashok Powar | 5d377fc | 2012-11-06 19:22:16 +0530 | [diff] [blame] | 5759 | hw->wiphy->iface_combinations = &ap_if_comb; |
| 5760 | hw->wiphy->n_iface_combinations = 1; |
| 5761 | } |
| 5762 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5763 | if (priv->sta_macids_supported || priv->device_info->fw_image_sta) |
| 5764 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION); |
| 5765 | |
| 5766 | rc = ieee80211_register_hw(hw); |
| 5767 | if (rc) { |
| 5768 | wiphy_err(hw->wiphy, "Cannot register device\n"); |
| 5769 | goto err_unprobe_hw; |
| 5770 | } |
| 5771 | |
| 5772 | return 0; |
| 5773 | |
| 5774 | err_unprobe_hw: |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5775 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5776 | mwl8k_txq_deinit(hw, i); |
| 5777 | mwl8k_rxq_deinit(hw, 0); |
| 5778 | |
| 5779 | err_free_cookie: |
| 5780 | if (priv->cookie != NULL) |
| 5781 | pci_free_consistent(priv->pdev, 4, |
| 5782 | priv->cookie, priv->cookie_dma); |
| 5783 | |
| 5784 | return rc; |
| 5785 | } |
Bill Pemberton | 8dee5ee | 2012-12-03 09:56:36 -0500 | [diff] [blame] | 5786 | static int mwl8k_probe(struct pci_dev *pdev, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5787 | const struct pci_device_id *id) |
| 5788 | { |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5789 | static int printed_version; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5790 | struct ieee80211_hw *hw; |
| 5791 | struct mwl8k_priv *priv; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5792 | struct mwl8k_device_info *di; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5793 | int rc; |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 5794 | |
| 5795 | if (!printed_version) { |
| 5796 | printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION); |
| 5797 | printed_version = 1; |
| 5798 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5799 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5800 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5801 | rc = pci_enable_device(pdev); |
| 5802 | if (rc) { |
| 5803 | printk(KERN_ERR "%s: Cannot enable new PCI device\n", |
| 5804 | MWL8K_NAME); |
| 5805 | return rc; |
| 5806 | } |
| 5807 | |
| 5808 | rc = pci_request_regions(pdev, MWL8K_NAME); |
| 5809 | if (rc) { |
| 5810 | printk(KERN_ERR "%s: Cannot obtain PCI resources\n", |
| 5811 | MWL8K_NAME); |
Lennert Buytenhek | 3db95e5 | 2009-11-30 18:13:34 +0100 | [diff] [blame] | 5812 | goto err_disable_device; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5813 | } |
| 5814 | |
| 5815 | pci_set_master(pdev); |
| 5816 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5817 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5818 | hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops); |
| 5819 | if (hw == NULL) { |
| 5820 | printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME); |
| 5821 | rc = -ENOMEM; |
| 5822 | goto err_free_reg; |
| 5823 | } |
| 5824 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5825 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 5826 | pci_set_drvdata(pdev, hw); |
| 5827 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5828 | priv = hw->priv; |
| 5829 | priv->hw = hw; |
| 5830 | priv->pdev = pdev; |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5831 | priv->device_info = &mwl8k_info_tbl[id->driver_data]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5832 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5833 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5834 | priv->sram = pci_iomap(pdev, 0, 0x10000); |
| 5835 | if (priv->sram == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 5836 | wiphy_err(hw->wiphy, "Cannot map device SRAM\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5837 | goto err_iounmap; |
| 5838 | } |
| 5839 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5840 | /* |
| 5841 | * If BAR0 is a 32 bit BAR, the register BAR will be BAR1. |
| 5842 | * If BAR0 is a 64 bit BAR, the register BAR will be BAR2. |
| 5843 | */ |
| 5844 | priv->regs = pci_iomap(pdev, 1, 0x10000); |
| 5845 | if (priv->regs == NULL) { |
| 5846 | priv->regs = pci_iomap(pdev, 2, 0x10000); |
| 5847 | if (priv->regs == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 5848 | wiphy_err(hw->wiphy, "Cannot map device registers\n"); |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5849 | goto err_iounmap; |
| 5850 | } |
| 5851 | } |
| 5852 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5853 | /* |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5854 | * Choose the initial fw image depending on user input. If a second |
| 5855 | * image is available, make it the alternative image that will be |
| 5856 | * loaded if the first one fails. |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5857 | */ |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5858 | init_completion(&priv->firmware_loading_complete); |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5859 | di = priv->device_info; |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5860 | if (ap_mode_default && di->fw_image_ap) { |
| 5861 | priv->fw_pref = di->fw_image_ap; |
| 5862 | priv->fw_alt = di->fw_image_sta; |
| 5863 | } else if (!ap_mode_default && di->fw_image_sta) { |
| 5864 | priv->fw_pref = di->fw_image_sta; |
| 5865 | priv->fw_alt = di->fw_image_ap; |
| 5866 | } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) { |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5867 | printk(KERN_WARNING "AP fw is unavailable. Using STA fw."); |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5868 | priv->fw_pref = di->fw_image_sta; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5869 | } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) { |
| 5870 | printk(KERN_WARNING "STA fw is unavailable. Using AP fw."); |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5871 | priv->fw_pref = di->fw_image_ap; |
| 5872 | } |
| 5873 | rc = mwl8k_init_firmware(hw, priv->fw_pref, true); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5874 | if (rc) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5875 | goto err_stop_firmware; |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5876 | |
| 5877 | priv->hw_restart_in_progress = false; |
| 5878 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5879 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5880 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5881 | err_stop_firmware: |
| 5882 | mwl8k_hw_reset(priv); |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5883 | |
| 5884 | err_iounmap: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5885 | if (priv->regs != NULL) |
| 5886 | pci_iounmap(pdev, priv->regs); |
| 5887 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5888 | if (priv->sram != NULL) |
| 5889 | pci_iounmap(pdev, priv->sram); |
| 5890 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5891 | pci_set_drvdata(pdev, NULL); |
| 5892 | ieee80211_free_hw(hw); |
| 5893 | |
| 5894 | err_free_reg: |
| 5895 | pci_release_regions(pdev); |
Lennert Buytenhek | 3db95e5 | 2009-11-30 18:13:34 +0100 | [diff] [blame] | 5896 | |
| 5897 | err_disable_device: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5898 | pci_disable_device(pdev); |
| 5899 | |
| 5900 | return rc; |
| 5901 | } |
| 5902 | |
Bill Pemberton | 8dee5ee | 2012-12-03 09:56:36 -0500 | [diff] [blame] | 5903 | static void mwl8k_remove(struct pci_dev *pdev) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5904 | { |
| 5905 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 5906 | struct mwl8k_priv *priv; |
| 5907 | int i; |
| 5908 | |
| 5909 | if (hw == NULL) |
| 5910 | return; |
| 5911 | priv = hw->priv; |
| 5912 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5913 | wait_for_completion(&priv->firmware_loading_complete); |
| 5914 | |
| 5915 | if (priv->fw_state == FW_STATE_ERROR) { |
| 5916 | mwl8k_hw_reset(priv); |
| 5917 | goto unmap; |
| 5918 | } |
| 5919 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5920 | ieee80211_stop_queues(hw); |
| 5921 | |
Lennert Buytenhek | 60aa569 | 2009-08-03 21:59:09 +0200 | [diff] [blame] | 5922 | ieee80211_unregister_hw(hw); |
| 5923 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 5924 | /* Remove TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 5925 | tasklet_kill(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 5926 | tasklet_kill(&priv->poll_rx_task); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5927 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5928 | /* Stop hardware */ |
| 5929 | mwl8k_hw_reset(priv); |
| 5930 | |
| 5931 | /* Return all skbs to mac80211 */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5932 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 5933 | mwl8k_txq_reclaim(hw, i, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5934 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5935 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5936 | mwl8k_txq_deinit(hw, i); |
| 5937 | |
| 5938 | mwl8k_rxq_deinit(hw, 0); |
| 5939 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 5940 | pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5941 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5942 | unmap: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5943 | pci_iounmap(pdev, priv->regs); |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 5944 | pci_iounmap(pdev, priv->sram); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5945 | pci_set_drvdata(pdev, NULL); |
| 5946 | ieee80211_free_hw(hw); |
| 5947 | pci_release_regions(pdev); |
| 5948 | pci_disable_device(pdev); |
| 5949 | } |
| 5950 | |
| 5951 | static struct pci_driver mwl8k_driver = { |
| 5952 | .name = MWL8K_NAME, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5953 | .id_table = mwl8k_pci_id_table, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5954 | .probe = mwl8k_probe, |
Bill Pemberton | 8dee5ee | 2012-12-03 09:56:36 -0500 | [diff] [blame] | 5955 | .remove = mwl8k_remove, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5956 | }; |
| 5957 | |
Axel Lin | 5b0a3b7 | 2012-04-14 10:38:36 +0800 | [diff] [blame] | 5958 | module_pci_driver(mwl8k_driver); |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 5959 | |
| 5960 | MODULE_DESCRIPTION(MWL8K_DESC); |
| 5961 | MODULE_VERSION(MWL8K_VERSION); |
| 5962 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>"); |
| 5963 | MODULE_LICENSE("GPL"); |