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 | |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 12 | #include <linux/interrupt.h> |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
Lennert Buytenhek | 3d76e82 | 2009-10-22 20:20:16 +0200 | [diff] [blame] | 15 | #include <linux/sched.h> |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 16 | #include <linux/spinlock.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/pci.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/completion.h> |
| 21 | #include <linux/etherdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 23 | #include <net/mac80211.h> |
| 24 | #include <linux/moduleparam.h> |
| 25 | #include <linux/firmware.h> |
| 26 | #include <linux/workqueue.h> |
| 27 | |
| 28 | #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver" |
| 29 | #define MWL8K_NAME KBUILD_MODNAME |
Yogesh Ashok Powar | 00e8e69 | 2011-12-20 11:39:29 +0530 | [diff] [blame] | 30 | #define MWL8K_VERSION "0.13" |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 31 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 32 | /* Module parameters */ |
Rusty Russell | eb93992 | 2011-12-19 14:08:01 +0000 | [diff] [blame] | 33 | static bool ap_mode_default; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 34 | module_param(ap_mode_default, bool, 0); |
| 35 | MODULE_PARM_DESC(ap_mode_default, |
| 36 | "Set to 1 to make ap mode the default instead of sta mode"); |
| 37 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 38 | /* Register definitions */ |
| 39 | #define MWL8K_HIU_GEN_PTR 0x00000c10 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 40 | #define MWL8K_MODE_STA 0x0000005a |
| 41 | #define MWL8K_MODE_AP 0x000000a5 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 42 | #define MWL8K_HIU_INT_CODE 0x00000c14 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 43 | #define MWL8K_FWSTA_READY 0xf0f1f2f4 |
| 44 | #define MWL8K_FWAP_READY 0xf1f2f4a5 |
| 45 | #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 46 | #define MWL8K_HIU_SCRATCH 0x00000c40 |
| 47 | |
| 48 | /* Host->device communications */ |
| 49 | #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18 |
| 50 | #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c |
| 51 | #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20 |
| 52 | #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24 |
| 53 | #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 54 | #define MWL8K_H2A_INT_DUMMY (1 << 20) |
| 55 | #define MWL8K_H2A_INT_RESET (1 << 15) |
| 56 | #define MWL8K_H2A_INT_DOORBELL (1 << 1) |
| 57 | #define MWL8K_H2A_INT_PPA_READY (1 << 0) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 58 | |
| 59 | /* Device->host communications */ |
| 60 | #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c |
| 61 | #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30 |
| 62 | #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34 |
| 63 | #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38 |
| 64 | #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 65 | #define MWL8K_A2H_INT_DUMMY (1 << 20) |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 66 | #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14) |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 67 | #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11) |
| 68 | #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10) |
| 69 | #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7) |
| 70 | #define MWL8K_A2H_INT_RADIO_ON (1 << 6) |
| 71 | #define MWL8K_A2H_INT_RADIO_OFF (1 << 5) |
| 72 | #define MWL8K_A2H_INT_MAC_EVENT (1 << 3) |
| 73 | #define MWL8K_A2H_INT_OPC_DONE (1 << 2) |
| 74 | #define MWL8K_A2H_INT_RX_READY (1 << 1) |
| 75 | #define MWL8K_A2H_INT_TX_DONE (1 << 0) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 76 | |
Pradeep Nemavat | 566875d | 2011-04-21 16:34:57 +0530 | [diff] [blame] | 77 | /* HW micro second timer register |
| 78 | * located at offset 0xA600. This |
| 79 | * will be used to timestamp tx |
| 80 | * packets. |
| 81 | */ |
| 82 | |
| 83 | #define MWL8K_HW_TIMER_REGISTER 0x0000a600 |
| 84 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 85 | #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \ |
| 86 | MWL8K_A2H_INT_CHNL_SWITCHED | \ |
| 87 | MWL8K_A2H_INT_QUEUE_EMPTY | \ |
| 88 | MWL8K_A2H_INT_RADAR_DETECT | \ |
| 89 | MWL8K_A2H_INT_RADIO_ON | \ |
| 90 | MWL8K_A2H_INT_RADIO_OFF | \ |
| 91 | MWL8K_A2H_INT_MAC_EVENT | \ |
| 92 | MWL8K_A2H_INT_OPC_DONE | \ |
| 93 | MWL8K_A2H_INT_RX_READY | \ |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 94 | MWL8K_A2H_INT_TX_DONE | \ |
| 95 | MWL8K_A2H_INT_BA_WATCHDOG) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 96 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 97 | #define MWL8K_RX_QUEUES 1 |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 98 | #define MWL8K_TX_WMM_QUEUES 4 |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 99 | #define MWL8K_MAX_AMPDU_QUEUES 8 |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 100 | #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES) |
| 101 | #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] | 102 | |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame] | 103 | /* txpriorities are mapped with hw queues. |
| 104 | * Each hw queue has a txpriority. |
| 105 | */ |
| 106 | #define TOTAL_HW_TX_QUEUES 8 |
| 107 | |
| 108 | /* Each HW queue can have one AMPDU stream. |
| 109 | * But, because one of the hw queue is reserved, |
| 110 | * maximum AMPDU queues that can be created are |
| 111 | * one short of total tx queues. |
| 112 | */ |
| 113 | #define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1) |
| 114 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 115 | struct rxd_ops { |
| 116 | int rxd_size; |
| 117 | void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr); |
| 118 | void (*rxd_refill)(void *rxd, dma_addr_t addr, int len); |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 119 | int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 120 | __le16 *qos, s8 *noise); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 123 | struct mwl8k_device_info { |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 124 | char *part_name; |
| 125 | char *helper_image; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 126 | char *fw_image_sta; |
| 127 | char *fw_image_ap; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 128 | struct rxd_ops *ap_rxd_ops; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 129 | u32 fw_api_ap; |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 130 | }; |
| 131 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 132 | struct mwl8k_rx_queue { |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 133 | int rxd_count; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 134 | |
| 135 | /* hw receives here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 136 | int head; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 137 | |
| 138 | /* refill descs here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 139 | int tail; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 140 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 141 | void *rxd; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 142 | dma_addr_t rxd_dma; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 143 | struct { |
| 144 | struct sk_buff *skb; |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 145 | DEFINE_DMA_UNMAP_ADDR(dma); |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 146 | } *buf; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 147 | }; |
| 148 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 149 | struct mwl8k_tx_queue { |
| 150 | /* hw transmits here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 151 | int head; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 152 | |
| 153 | /* sw appends here */ |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 154 | int tail; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 155 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 156 | unsigned int len; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 157 | struct mwl8k_tx_desc *txd; |
| 158 | dma_addr_t txd_dma; |
| 159 | struct sk_buff **skb; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 160 | }; |
| 161 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 162 | enum { |
| 163 | AMPDU_NO_STREAM, |
| 164 | AMPDU_STREAM_NEW, |
| 165 | AMPDU_STREAM_IN_PROGRESS, |
| 166 | AMPDU_STREAM_ACTIVE, |
| 167 | }; |
| 168 | |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 169 | struct mwl8k_ampdu_stream { |
| 170 | struct ieee80211_sta *sta; |
| 171 | u8 tid; |
| 172 | u8 state; |
| 173 | u8 idx; |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 176 | struct mwl8k_priv { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 177 | struct ieee80211_hw *hw; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 178 | struct pci_dev *pdev; |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 179 | int irq; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 180 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 181 | struct mwl8k_device_info *device_info; |
| 182 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 183 | void __iomem *sram; |
| 184 | void __iomem *regs; |
| 185 | |
| 186 | /* firmware */ |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 187 | const struct firmware *fw_helper; |
| 188 | const struct firmware *fw_ucode; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 189 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 190 | /* hardware/firmware parameters */ |
| 191 | bool ap_fw; |
| 192 | struct rxd_ops *rxd_ops; |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 193 | struct ieee80211_supported_band band_24; |
| 194 | struct ieee80211_channel channels_24[14]; |
Jonas Gorski | 3f52455 | 2013-04-14 14:11:58 +0200 | [diff] [blame] | 195 | struct ieee80211_rate rates_24[13]; |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 196 | struct ieee80211_supported_band band_50; |
| 197 | struct ieee80211_channel channels_50[4]; |
Jonas Gorski | 3f52455 | 2013-04-14 14:11:58 +0200 | [diff] [blame] | 198 | struct ieee80211_rate rates_50[8]; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 199 | u32 ap_macids_supported; |
| 200 | u32 sta_macids_supported; |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 201 | |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 202 | /* Ampdu stream information */ |
| 203 | u8 num_ampdu_queues; |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 204 | spinlock_t stream_lock; |
| 205 | struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES]; |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 206 | struct work_struct watchdog_ba_handle; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 207 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 208 | /* firmware access */ |
| 209 | struct mutex fw_mutex; |
| 210 | struct task_struct *fw_mutex_owner; |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 211 | struct task_struct *hw_restart_owner; |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 212 | int fw_mutex_depth; |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 213 | struct completion *hostcmd_wait; |
| 214 | |
Yogesh Ashok Powar | c27a54d | 2013-01-03 13:24:19 +0530 | [diff] [blame] | 215 | atomic_t watchdog_event_pending; |
| 216 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 217 | /* lock held over TX and TX reap */ |
| 218 | spinlock_t tx_lock; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 219 | |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 220 | /* TX quiesce completion, protected by fw_mutex and tx_lock */ |
| 221 | struct completion *tx_wait; |
| 222 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 223 | /* List of interfaces. */ |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 224 | u32 macids_used; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 225 | struct list_head vif_list; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 226 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 227 | /* power management status cookie from firmware */ |
| 228 | u32 *cookie; |
| 229 | dma_addr_t cookie_dma; |
| 230 | |
| 231 | u16 num_mcaddrs; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 232 | u8 hw_rev; |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 233 | u32 fw_rev; |
Jonas Gorski | c3f251a | 2013-03-11 17:44:21 +0100 | [diff] [blame] | 234 | u32 caps; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * Running count of TX packets in flight, to avoid |
| 238 | * iterating over the transmit rings each time. |
| 239 | */ |
| 240 | int pending_tx_pkts; |
| 241 | |
| 242 | struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES]; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 243 | struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES]; |
| 244 | u32 txq_offset[MWL8K_MAX_TX_QUEUES]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 245 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 246 | bool radio_on; |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 247 | bool radio_short_preamble; |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 248 | bool sniffer_enabled; |
Lennert Buytenhek | 0439b1f | 2009-07-16 12:34:02 +0200 | [diff] [blame] | 249 | bool wmm_enabled; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 250 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 251 | /* XXX need to convert this to handle multiple interfaces */ |
| 252 | bool capture_beacon; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 253 | u8 capture_bssid[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 254 | struct sk_buff *beacon_skb; |
| 255 | |
| 256 | /* |
| 257 | * This FJ worker has to be global as it is scheduled from the |
| 258 | * RX handler. At this point we don't know which interface it |
| 259 | * belongs to until the list of bssids waiting to complete join |
| 260 | * is checked. |
| 261 | */ |
| 262 | struct work_struct finalize_join_worker; |
| 263 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 264 | /* Tasklet to perform TX reclaim. */ |
| 265 | struct tasklet_struct poll_tx_task; |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 266 | |
| 267 | /* Tasklet to perform RX. */ |
| 268 | struct tasklet_struct poll_rx_task; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 269 | |
| 270 | /* Most recently reported noise in dBm */ |
| 271 | s8 noise; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 272 | |
| 273 | /* |
| 274 | * preserve the queue configurations so they can be restored if/when |
| 275 | * the firmware image is swapped. |
| 276 | */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 277 | struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES]; |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 278 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 279 | /* To perform the task of reloading the firmware */ |
| 280 | struct work_struct fw_reload; |
| 281 | bool hw_restart_in_progress; |
| 282 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 283 | /* async firmware loading state */ |
| 284 | unsigned fw_state; |
| 285 | char *fw_pref; |
| 286 | char *fw_alt; |
Nishant Sarmukadam | 9892982 | 2013-03-01 17:13:01 +0530 | [diff] [blame] | 287 | bool is_8764; |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 288 | struct completion firmware_loading_complete; |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 289 | |
| 290 | /* bitmap of running BSSes */ |
| 291 | u32 running_bsses; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 292 | }; |
| 293 | |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 294 | #define MAX_WEP_KEY_LEN 13 |
| 295 | #define NUM_WEP_KEYS 4 |
| 296 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 297 | /* Per interface specific private data */ |
| 298 | struct mwl8k_vif { |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 299 | struct list_head list; |
| 300 | struct ieee80211_vif *vif; |
| 301 | |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 302 | /* Firmware macid for this vif. */ |
| 303 | int macid; |
| 304 | |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 305 | /* Non AMPDU sequence number assigned by driver. */ |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 306 | u16 seqno; |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 307 | |
| 308 | /* Saved WEP keys */ |
| 309 | struct { |
| 310 | u8 enabled; |
| 311 | u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN]; |
| 312 | } wep_key_conf[NUM_WEP_KEYS]; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 313 | |
| 314 | /* BSSID */ |
| 315 | u8 bssid[ETH_ALEN]; |
| 316 | |
| 317 | /* A flag to indicate is HW crypto is enabled for this bssid */ |
| 318 | bool is_hw_crypto_enabled; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 319 | }; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 320 | #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv)) |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 321 | #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 322 | |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 323 | struct tx_traffic_info { |
| 324 | u32 start_time; |
| 325 | u32 pkts; |
| 326 | }; |
| 327 | |
| 328 | #define MWL8K_MAX_TID 8 |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 329 | struct mwl8k_sta { |
| 330 | /* Index into station database. Returned by UPDATE_STADB. */ |
| 331 | u8 peer_id; |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 332 | u8 is_ampdu_allowed; |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 333 | struct tx_traffic_info tx_stats[MWL8K_MAX_TID]; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 334 | }; |
| 335 | #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv)) |
| 336 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 337 | static const struct ieee80211_channel mwl8k_channels_24[] = { |
Jonas Gorski | d786f67 | 2013-02-08 16:07:25 +0100 | [diff] [blame] | 338 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2412, .hw_value = 1, }, |
| 339 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2417, .hw_value = 2, }, |
| 340 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2422, .hw_value = 3, }, |
| 341 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2427, .hw_value = 4, }, |
| 342 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2432, .hw_value = 5, }, |
| 343 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2437, .hw_value = 6, }, |
| 344 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2442, .hw_value = 7, }, |
| 345 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2447, .hw_value = 8, }, |
| 346 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2452, .hw_value = 9, }, |
| 347 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2457, .hw_value = 10, }, |
| 348 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2462, .hw_value = 11, }, |
| 349 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2467, .hw_value = 12, }, |
| 350 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2472, .hw_value = 13, }, |
| 351 | { .band = IEEE80211_BAND_2GHZ, .center_freq = 2484, .hw_value = 14, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 352 | }; |
| 353 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 354 | static const struct ieee80211_rate mwl8k_rates_24[] = { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 355 | { .bitrate = 10, .hw_value = 2, }, |
| 356 | { .bitrate = 20, .hw_value = 4, }, |
| 357 | { .bitrate = 55, .hw_value = 11, }, |
Lennert Buytenhek | 5dfd3e2 | 2009-10-22 20:20:29 +0200 | [diff] [blame] | 358 | { .bitrate = 110, .hw_value = 22, }, |
| 359 | { .bitrate = 220, .hw_value = 44, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 360 | { .bitrate = 60, .hw_value = 12, }, |
| 361 | { .bitrate = 90, .hw_value = 18, }, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 362 | { .bitrate = 120, .hw_value = 24, }, |
| 363 | { .bitrate = 180, .hw_value = 36, }, |
| 364 | { .bitrate = 240, .hw_value = 48, }, |
| 365 | { .bitrate = 360, .hw_value = 72, }, |
| 366 | { .bitrate = 480, .hw_value = 96, }, |
| 367 | { .bitrate = 540, .hw_value = 108, }, |
Lennert Buytenhek | 140eb5e | 2009-11-30 18:11:44 +0100 | [diff] [blame] | 368 | }; |
| 369 | |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 370 | static const struct ieee80211_channel mwl8k_channels_50[] = { |
Jonas Gorski | d786f67 | 2013-02-08 16:07:25 +0100 | [diff] [blame] | 371 | { .band = IEEE80211_BAND_5GHZ, .center_freq = 5180, .hw_value = 36, }, |
| 372 | { .band = IEEE80211_BAND_5GHZ, .center_freq = 5200, .hw_value = 40, }, |
| 373 | { .band = IEEE80211_BAND_5GHZ, .center_freq = 5220, .hw_value = 44, }, |
| 374 | { .band = IEEE80211_BAND_5GHZ, .center_freq = 5240, .hw_value = 48, }, |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | static const struct ieee80211_rate mwl8k_rates_50[] = { |
| 378 | { .bitrate = 60, .hw_value = 12, }, |
| 379 | { .bitrate = 90, .hw_value = 18, }, |
| 380 | { .bitrate = 120, .hw_value = 24, }, |
| 381 | { .bitrate = 180, .hw_value = 36, }, |
| 382 | { .bitrate = 240, .hw_value = 48, }, |
| 383 | { .bitrate = 360, .hw_value = 72, }, |
| 384 | { .bitrate = 480, .hw_value = 96, }, |
| 385 | { .bitrate = 540, .hw_value = 108, }, |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 386 | }; |
| 387 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 388 | /* Set or get info from Firmware */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 389 | #define MWL8K_CMD_GET 0x0000 |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 390 | #define MWL8K_CMD_SET 0x0001 |
| 391 | #define MWL8K_CMD_SET_LIST 0x0002 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 392 | |
| 393 | /* Firmware command codes */ |
| 394 | #define MWL8K_CMD_CODE_DNLD 0x0001 |
| 395 | #define MWL8K_CMD_GET_HW_SPEC 0x0003 |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 396 | #define MWL8K_CMD_SET_HW_SPEC 0x0004 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 397 | #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010 |
| 398 | #define MWL8K_CMD_GET_STAT 0x0014 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 399 | #define MWL8K_CMD_RADIO_CONTROL 0x001c |
| 400 | #define MWL8K_CMD_RF_TX_POWER 0x001e |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 401 | #define MWL8K_CMD_TX_POWER 0x001f |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 402 | #define MWL8K_CMD_RF_ANTENNA 0x0020 |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 403 | #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 404 | #define MWL8K_CMD_SET_PRE_SCAN 0x0107 |
| 405 | #define MWL8K_CMD_SET_POST_SCAN 0x0108 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 406 | #define MWL8K_CMD_SET_RF_CHANNEL 0x010a |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 407 | #define MWL8K_CMD_SET_AID 0x010d |
| 408 | #define MWL8K_CMD_SET_RATE 0x0110 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 409 | #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 410 | #define MWL8K_CMD_RTS_THRESHOLD 0x0113 |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 411 | #define MWL8K_CMD_SET_SLOT 0x0114 |
| 412 | #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115 |
| 413 | #define MWL8K_CMD_SET_WMM_MODE 0x0123 |
| 414 | #define MWL8K_CMD_MIMO_CONFIG 0x0125 |
| 415 | #define MWL8K_CMD_USE_FIXED_RATE 0x0126 |
| 416 | #define MWL8K_CMD_ENABLE_SNIFFER 0x0150 |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 417 | #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */ |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 418 | #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203 |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 419 | #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205 |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 420 | #define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */ |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 421 | #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */ |
| 422 | #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */ |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 423 | #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */ |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 424 | #define MWL8K_CMD_UPDATE_STADB 0x1123 |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 425 | #define MWL8K_CMD_BASTREAM 0x1125 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 426 | |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 427 | static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 428 | { |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 429 | u16 command = le16_to_cpu(cmd); |
| 430 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 431 | #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\ |
| 432 | snprintf(buf, bufsize, "%s", #x);\ |
| 433 | return buf;\ |
| 434 | } while (0) |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 435 | switch (command & ~0x8000) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 436 | MWL8K_CMDNAME(CODE_DNLD); |
| 437 | MWL8K_CMDNAME(GET_HW_SPEC); |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 438 | MWL8K_CMDNAME(SET_HW_SPEC); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 439 | MWL8K_CMDNAME(MAC_MULTICAST_ADR); |
| 440 | MWL8K_CMDNAME(GET_STAT); |
| 441 | MWL8K_CMDNAME(RADIO_CONTROL); |
| 442 | MWL8K_CMDNAME(RF_TX_POWER); |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 443 | MWL8K_CMDNAME(TX_POWER); |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 444 | MWL8K_CMDNAME(RF_ANTENNA); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 445 | MWL8K_CMDNAME(SET_BEACON); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 446 | MWL8K_CMDNAME(SET_PRE_SCAN); |
| 447 | MWL8K_CMDNAME(SET_POST_SCAN); |
| 448 | MWL8K_CMDNAME(SET_RF_CHANNEL); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 449 | MWL8K_CMDNAME(SET_AID); |
| 450 | MWL8K_CMDNAME(SET_RATE); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 451 | MWL8K_CMDNAME(SET_FINALIZE_JOIN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 452 | MWL8K_CMDNAME(RTS_THRESHOLD); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 453 | MWL8K_CMDNAME(SET_SLOT); |
| 454 | MWL8K_CMDNAME(SET_EDCA_PARAMS); |
| 455 | MWL8K_CMDNAME(SET_WMM_MODE); |
| 456 | MWL8K_CMDNAME(MIMO_CONFIG); |
| 457 | MWL8K_CMDNAME(USE_FIXED_RATE); |
| 458 | MWL8K_CMDNAME(ENABLE_SNIFFER); |
Lennert Buytenhek | 32060e1 | 2009-10-22 20:20:04 +0200 | [diff] [blame] | 459 | MWL8K_CMDNAME(SET_MAC_ADDR); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 460 | MWL8K_CMDNAME(SET_RATEADAPT_MODE); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 461 | MWL8K_CMDNAME(BSS_START); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 462 | MWL8K_CMDNAME(SET_NEW_STN); |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 463 | MWL8K_CMDNAME(UPDATE_ENCRYPTION); |
Lennert Buytenhek | ff45fc6 | 2009-07-16 11:50:36 +0200 | [diff] [blame] | 464 | MWL8K_CMDNAME(UPDATE_STADB); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 465 | MWL8K_CMDNAME(BASTREAM); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 466 | MWL8K_CMDNAME(GET_WATCHDOG_BITMAP); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 467 | default: |
| 468 | snprintf(buf, bufsize, "0x%x", cmd); |
| 469 | } |
| 470 | #undef MWL8K_CMDNAME |
| 471 | |
| 472 | return buf; |
| 473 | } |
| 474 | |
| 475 | /* Hardware and firmware reset */ |
| 476 | static void mwl8k_hw_reset(struct mwl8k_priv *priv) |
| 477 | { |
| 478 | iowrite32(MWL8K_H2A_INT_RESET, |
| 479 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 480 | iowrite32(MWL8K_H2A_INT_RESET, |
| 481 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 482 | msleep(20); |
| 483 | } |
| 484 | |
| 485 | /* Release fw image */ |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 486 | static void mwl8k_release_fw(const struct firmware **fw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 487 | { |
| 488 | if (*fw == NULL) |
| 489 | return; |
| 490 | release_firmware(*fw); |
| 491 | *fw = NULL; |
| 492 | } |
| 493 | |
| 494 | static void mwl8k_release_firmware(struct mwl8k_priv *priv) |
| 495 | { |
Lennert Buytenhek | 22be40d | 2009-11-30 18:32:38 +0100 | [diff] [blame] | 496 | mwl8k_release_fw(&priv->fw_ucode); |
| 497 | mwl8k_release_fw(&priv->fw_helper); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 498 | } |
| 499 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 500 | /* states for asynchronous f/w loading */ |
| 501 | static void mwl8k_fw_state_machine(const struct firmware *fw, void *context); |
| 502 | enum { |
| 503 | FW_STATE_INIT = 0, |
| 504 | FW_STATE_LOADING_PREF, |
| 505 | FW_STATE_LOADING_ALT, |
| 506 | FW_STATE_ERROR, |
| 507 | }; |
| 508 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 509 | /* Request fw image */ |
| 510 | static int mwl8k_request_fw(struct mwl8k_priv *priv, |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 511 | const char *fname, const struct firmware **fw, |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 512 | bool nowait) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 513 | { |
| 514 | /* release current image */ |
| 515 | if (*fw != NULL) |
| 516 | mwl8k_release_fw(fw); |
| 517 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 518 | if (nowait) |
| 519 | return request_firmware_nowait(THIS_MODULE, 1, fname, |
| 520 | &priv->pdev->dev, GFP_KERNEL, |
| 521 | priv, mwl8k_fw_state_machine); |
| 522 | else |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 523 | return request_firmware(fw, fname, &priv->pdev->dev); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 524 | } |
| 525 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 526 | static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image, |
| 527 | bool nowait) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 528 | { |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 529 | struct mwl8k_device_info *di = priv->device_info; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 530 | int rc; |
| 531 | |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 532 | if (di->helper_image != NULL) { |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 533 | if (nowait) |
| 534 | rc = mwl8k_request_fw(priv, di->helper_image, |
| 535 | &priv->fw_helper, true); |
| 536 | else |
| 537 | rc = mwl8k_request_fw(priv, di->helper_image, |
| 538 | &priv->fw_helper, false); |
| 539 | if (rc) |
| 540 | printk(KERN_ERR "%s: Error requesting helper fw %s\n", |
| 541 | pci_name(priv->pdev), di->helper_image); |
| 542 | |
| 543 | if (rc || nowait) |
Lennert Buytenhek | a74b295 | 2009-10-22 20:20:50 +0200 | [diff] [blame] | 544 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 547 | if (nowait) { |
| 548 | /* |
| 549 | * if we get here, no helper image is needed. Skip the |
| 550 | * FW_STATE_INIT state. |
| 551 | */ |
| 552 | priv->fw_state = FW_STATE_LOADING_PREF; |
| 553 | rc = mwl8k_request_fw(priv, fw_image, |
| 554 | &priv->fw_ucode, |
| 555 | true); |
| 556 | } else |
| 557 | rc = mwl8k_request_fw(priv, fw_image, |
| 558 | &priv->fw_ucode, false); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 559 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 560 | printk(KERN_ERR "%s: Error requesting firmware file %s\n", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 561 | pci_name(priv->pdev), fw_image); |
Lennert Buytenhek | 22be40d | 2009-11-30 18:32:38 +0100 | [diff] [blame] | 562 | mwl8k_release_fw(&priv->fw_helper); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 563 | return rc; |
| 564 | } |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | struct mwl8k_cmd_pkt { |
| 570 | __le16 code; |
| 571 | __le16 length; |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 572 | __u8 seq_num; |
| 573 | __u8 macid; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 574 | __le16 result; |
| 575 | char payload[0]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 576 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 577 | |
| 578 | /* |
| 579 | * Firmware loading. |
| 580 | */ |
| 581 | static int |
| 582 | mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length) |
| 583 | { |
| 584 | void __iomem *regs = priv->regs; |
| 585 | dma_addr_t dma_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 586 | int loops; |
| 587 | |
| 588 | dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE); |
| 589 | if (pci_dma_mapping_error(priv->pdev, dma_addr)) |
| 590 | return -ENOMEM; |
| 591 | |
| 592 | iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR); |
| 593 | iowrite32(0, regs + MWL8K_HIU_INT_CODE); |
| 594 | iowrite32(MWL8K_H2A_INT_DOORBELL, |
| 595 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 596 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 597 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 598 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 599 | loops = 1000; |
| 600 | do { |
| 601 | u32 int_code; |
Nishant Sarmukadam | 9892982 | 2013-03-01 17:13:01 +0530 | [diff] [blame] | 602 | if (priv->is_8764) { |
| 603 | int_code = ioread32(regs + |
| 604 | MWL8K_HIU_H2A_INTERRUPT_STATUS); |
| 605 | if (int_code == 0) |
| 606 | break; |
| 607 | } else { |
| 608 | int_code = ioread32(regs + MWL8K_HIU_INT_CODE); |
| 609 | if (int_code == MWL8K_INT_CODE_CMD_FINISHED) { |
| 610 | iowrite32(0, regs + MWL8K_HIU_INT_CODE); |
| 611 | break; |
| 612 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 613 | } |
Lennert Buytenhek | 3d76e82 | 2009-10-22 20:20:16 +0200 | [diff] [blame] | 614 | cond_resched(); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 615 | udelay(1); |
| 616 | } while (--loops); |
| 617 | |
| 618 | pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE); |
| 619 | |
Lennert Buytenhek | d4b7057 | 2009-07-16 12:44:45 +0200 | [diff] [blame] | 620 | return loops ? 0 : -ETIMEDOUT; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static int mwl8k_load_fw_image(struct mwl8k_priv *priv, |
| 624 | const u8 *data, size_t length) |
| 625 | { |
| 626 | struct mwl8k_cmd_pkt *cmd; |
| 627 | int done; |
| 628 | int rc = 0; |
| 629 | |
| 630 | cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL); |
| 631 | if (cmd == NULL) |
| 632 | return -ENOMEM; |
| 633 | |
| 634 | cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD); |
| 635 | cmd->seq_num = 0; |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 636 | cmd->macid = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 637 | cmd->result = 0; |
| 638 | |
| 639 | done = 0; |
| 640 | while (length) { |
| 641 | int block_size = length > 256 ? 256 : length; |
| 642 | |
| 643 | memcpy(cmd->payload, data + done, block_size); |
| 644 | cmd->length = cpu_to_le16(block_size); |
| 645 | |
| 646 | rc = mwl8k_send_fw_load_cmd(priv, cmd, |
| 647 | sizeof(*cmd) + block_size); |
| 648 | if (rc) |
| 649 | break; |
| 650 | |
| 651 | done += block_size; |
| 652 | length -= block_size; |
| 653 | } |
| 654 | |
| 655 | if (!rc) { |
| 656 | cmd->length = 0; |
| 657 | rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd)); |
| 658 | } |
| 659 | |
| 660 | kfree(cmd); |
| 661 | |
| 662 | return rc; |
| 663 | } |
| 664 | |
| 665 | static int mwl8k_feed_fw_image(struct mwl8k_priv *priv, |
| 666 | const u8 *data, size_t length) |
| 667 | { |
| 668 | unsigned char *buffer; |
| 669 | int may_continue, rc = 0; |
| 670 | u32 done, prev_block_size; |
| 671 | |
| 672 | buffer = kmalloc(1024, GFP_KERNEL); |
| 673 | if (buffer == NULL) |
| 674 | return -ENOMEM; |
| 675 | |
| 676 | done = 0; |
| 677 | prev_block_size = 0; |
| 678 | may_continue = 1000; |
| 679 | while (may_continue > 0) { |
| 680 | u32 block_size; |
| 681 | |
| 682 | block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH); |
| 683 | if (block_size & 1) { |
| 684 | block_size &= ~1; |
| 685 | may_continue--; |
| 686 | } else { |
| 687 | done += prev_block_size; |
| 688 | length -= prev_block_size; |
| 689 | } |
| 690 | |
| 691 | if (block_size > 1024 || block_size > length) { |
| 692 | rc = -EOVERFLOW; |
| 693 | break; |
| 694 | } |
| 695 | |
| 696 | if (length == 0) { |
| 697 | rc = 0; |
| 698 | break; |
| 699 | } |
| 700 | |
| 701 | if (block_size == 0) { |
| 702 | rc = -EPROTO; |
| 703 | may_continue--; |
| 704 | udelay(1); |
| 705 | continue; |
| 706 | } |
| 707 | |
| 708 | prev_block_size = block_size; |
| 709 | memcpy(buffer, data + done, block_size); |
| 710 | |
| 711 | rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size); |
| 712 | if (rc) |
| 713 | break; |
| 714 | } |
| 715 | |
| 716 | if (!rc && length != 0) |
| 717 | rc = -EREMOTEIO; |
| 718 | |
| 719 | kfree(buffer); |
| 720 | |
| 721 | return rc; |
| 722 | } |
| 723 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 724 | static int mwl8k_load_firmware(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 725 | { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 726 | struct mwl8k_priv *priv = hw->priv; |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 727 | const struct firmware *fw = priv->fw_ucode; |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 728 | int rc; |
| 729 | int loops; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 730 | |
Nishant Sarmukadam | 9892982 | 2013-03-01 17:13:01 +0530 | [diff] [blame] | 731 | if (!memcmp(fw->data, "\x01\x00\x00\x00", 4) && !priv->is_8764) { |
Brian Cavagnolo | d1f9e41 | 2010-11-12 17:23:53 -0800 | [diff] [blame] | 732 | const struct firmware *helper = priv->fw_helper; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 733 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 734 | if (helper == NULL) { |
| 735 | printk(KERN_ERR "%s: helper image needed but none " |
| 736 | "given\n", pci_name(priv->pdev)); |
| 737 | return -EINVAL; |
| 738 | } |
| 739 | |
| 740 | rc = mwl8k_load_fw_image(priv, helper->data, helper->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 741 | if (rc) { |
| 742 | printk(KERN_ERR "%s: unable to load firmware " |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 743 | "helper image\n", pci_name(priv->pdev)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 744 | return rc; |
| 745 | } |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 746 | msleep(20); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 747 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 748 | rc = mwl8k_feed_fw_image(priv, fw->data, fw->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 749 | } else { |
Nishant Sarmukadam | 9892982 | 2013-03-01 17:13:01 +0530 | [diff] [blame] | 750 | if (priv->is_8764) |
| 751 | rc = mwl8k_feed_fw_image(priv, fw->data, fw->size); |
| 752 | else |
| 753 | rc = mwl8k_load_fw_image(priv, fw->data, fw->size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | if (rc) { |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 757 | printk(KERN_ERR "%s: unable to load firmware image\n", |
| 758 | pci_name(priv->pdev)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 759 | return rc; |
| 760 | } |
| 761 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 762 | iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 763 | |
Lennert Buytenhek | 89b872e | 2009-11-30 18:13:20 +0100 | [diff] [blame] | 764 | loops = 500000; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 765 | do { |
Lennert Buytenhek | eae74e6 | 2009-10-22 20:20:53 +0200 | [diff] [blame] | 766 | u32 ready_code; |
| 767 | |
| 768 | ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE); |
| 769 | if (ready_code == MWL8K_FWAP_READY) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 770 | priv->ap_fw = true; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 771 | break; |
Lennert Buytenhek | eae74e6 | 2009-10-22 20:20:53 +0200 | [diff] [blame] | 772 | } else if (ready_code == MWL8K_FWSTA_READY) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 773 | priv->ap_fw = false; |
Lennert Buytenhek | eae74e6 | 2009-10-22 20:20:53 +0200 | [diff] [blame] | 774 | break; |
| 775 | } |
| 776 | |
| 777 | cond_resched(); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 778 | udelay(1); |
| 779 | } while (--loops); |
| 780 | |
| 781 | return loops ? 0 : -ETIMEDOUT; |
| 782 | } |
| 783 | |
| 784 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 785 | /* DMA header used by firmware and hardware. */ |
| 786 | struct mwl8k_dma_data { |
| 787 | __le16 fwlen; |
| 788 | struct ieee80211_hdr wh; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 789 | char data[0]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 790 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 791 | |
| 792 | /* Routines to add/remove DMA header from skb. */ |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 793 | 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] | 794 | { |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 795 | struct mwl8k_dma_data *tr; |
| 796 | int hdrlen; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 797 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 798 | tr = (struct mwl8k_dma_data *)skb->data; |
| 799 | hdrlen = ieee80211_hdrlen(tr->wh.frame_control); |
| 800 | |
| 801 | if (hdrlen != sizeof(tr->wh)) { |
| 802 | if (ieee80211_is_data_qos(tr->wh.frame_control)) { |
| 803 | memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2); |
| 804 | *((__le16 *)(tr->data - 2)) = qos; |
| 805 | } else { |
| 806 | memmove(tr->data - hdrlen, &tr->wh, hdrlen); |
| 807 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 808 | } |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 809 | |
| 810 | if (hdrlen != sizeof(*tr)) |
| 811 | skb_pull(skb, sizeof(*tr) - hdrlen); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 812 | } |
| 813 | |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 814 | #define REDUCED_TX_HEADROOM 8 |
| 815 | |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 816 | static void |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 817 | mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb, |
| 818 | int head_pad, int tail_pad) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 819 | { |
| 820 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 821 | int hdrlen; |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 822 | int reqd_hdrlen; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 823 | struct mwl8k_dma_data *tr; |
| 824 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 825 | /* |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 826 | * Add a firmware DMA header; the firmware requires that we |
| 827 | * present a 2-byte payload length followed by a 4-address |
| 828 | * header (without QoS field), followed (optionally) by any |
| 829 | * WEP/ExtIV header (but only filled in for CCMP). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 830 | */ |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 831 | wh = (struct ieee80211_hdr *)skb->data; |
| 832 | |
| 833 | hdrlen = ieee80211_hdrlen(wh->frame_control); |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 834 | |
| 835 | /* |
| 836 | * Check if skb_resize is required because of |
| 837 | * tx_headroom adjustment. |
| 838 | */ |
| 839 | if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts) |
| 840 | + REDUCED_TX_HEADROOM))) { |
| 841 | if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) { |
| 842 | |
| 843 | wiphy_err(priv->hw->wiphy, |
| 844 | "Failed to reallocate TX buffer\n"); |
| 845 | return; |
| 846 | } |
| 847 | skb->truesize += REDUCED_TX_HEADROOM; |
| 848 | } |
| 849 | |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 850 | reqd_hdrlen = sizeof(*tr) + head_pad; |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 851 | |
| 852 | if (hdrlen != reqd_hdrlen) |
| 853 | skb_push(skb, reqd_hdrlen - hdrlen); |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 854 | |
| 855 | if (ieee80211_is_data_qos(wh->frame_control)) |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 856 | hdrlen -= IEEE80211_QOS_CTL_LEN; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 857 | |
| 858 | tr = (struct mwl8k_dma_data *)skb->data; |
| 859 | if (wh != &tr->wh) |
| 860 | memmove(&tr->wh, wh, hdrlen); |
Lennert Buytenhek | ca00930 | 2009-11-30 18:12:20 +0100 | [diff] [blame] | 861 | if (hdrlen != sizeof(tr->wh)) |
| 862 | memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 863 | |
| 864 | /* |
| 865 | * Firmware length is the length of the fully formed "802.11 |
| 866 | * payload". That is, everything except for the 802.11 header. |
| 867 | * This includes all crypto material including the MIC. |
| 868 | */ |
Nishant Sarmukadam | 252486a | 2010-12-30 11:23:31 -0800 | [diff] [blame] | 869 | tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 872 | static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv, |
| 873 | struct sk_buff *skb) |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 874 | { |
| 875 | struct ieee80211_hdr *wh; |
| 876 | struct ieee80211_tx_info *tx_info; |
| 877 | struct ieee80211_key_conf *key_conf; |
| 878 | int data_pad; |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 879 | int head_pad = 0; |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 880 | |
| 881 | wh = (struct ieee80211_hdr *)skb->data; |
| 882 | |
| 883 | tx_info = IEEE80211_SKB_CB(skb); |
| 884 | |
| 885 | key_conf = NULL; |
| 886 | if (ieee80211_is_data(wh->frame_control)) |
| 887 | key_conf = tx_info->control.hw_key; |
| 888 | |
| 889 | /* |
| 890 | * 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] | 891 | * without QoS), and add head & tail padding when HW crypto is enabled. |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 892 | * |
| 893 | * We have the following trailer padding requirements: |
| 894 | * - WEP: 4 trailer bytes (ICV) |
| 895 | * - TKIP: 12 trailer bytes (8 MIC + 4 ICV) |
| 896 | * - CCMP: 8 trailer bytes (MIC) |
| 897 | */ |
| 898 | data_pad = 0; |
| 899 | if (key_conf != NULL) { |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 900 | head_pad = key_conf->iv_len; |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 901 | switch (key_conf->cipher) { |
| 902 | case WLAN_CIPHER_SUITE_WEP40: |
| 903 | case WLAN_CIPHER_SUITE_WEP104: |
| 904 | data_pad = 4; |
| 905 | break; |
| 906 | case WLAN_CIPHER_SUITE_TKIP: |
| 907 | data_pad = 12; |
| 908 | break; |
| 909 | case WLAN_CIPHER_SUITE_CCMP: |
| 910 | data_pad = 8; |
| 911 | break; |
| 912 | } |
| 913 | } |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 914 | mwl8k_add_dma_header(priv, skb, head_pad, data_pad); |
Nishant Sarmukadam | e53d9b9 | 2010-12-30 11:23:32 -0800 | [diff] [blame] | 915 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 916 | |
| 917 | /* |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 918 | * Packet reception for 88w8366/88w8764 AP firmware. |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 919 | */ |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 920 | struct mwl8k_rxd_ap { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 921 | __le16 pkt_len; |
| 922 | __u8 sq2; |
| 923 | __u8 rate; |
| 924 | __le32 pkt_phys_addr; |
| 925 | __le32 next_rxd_phys_addr; |
| 926 | __le16 qos_control; |
| 927 | __le16 htsig2; |
| 928 | __le32 hw_rssi_info; |
| 929 | __le32 hw_noise_floor_info; |
| 930 | __u8 noise_floor; |
| 931 | __u8 pad0[3]; |
| 932 | __u8 rssi; |
| 933 | __u8 rx_status; |
| 934 | __u8 channel; |
| 935 | __u8 rx_ctrl; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 936 | } __packed; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 937 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 938 | #define MWL8K_AP_RATE_INFO_MCS_FORMAT 0x80 |
| 939 | #define MWL8K_AP_RATE_INFO_40MHZ 0x40 |
| 940 | #define MWL8K_AP_RATE_INFO_RATEID(x) ((x) & 0x3f) |
Lennert Buytenhek | 8e9f33f | 2009-11-30 18:12:35 +0100 | [diff] [blame] | 941 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 942 | #define MWL8K_AP_RX_CTRL_OWNED_BY_HOST 0x80 |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 943 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 944 | /* 8366/8764 AP rx_status bits */ |
| 945 | #define MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK 0x80 |
| 946 | #define MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF |
| 947 | #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02 |
| 948 | #define MWL8K_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04 |
| 949 | #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08 |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 950 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 951 | static void mwl8k_rxd_ap_init(void *_rxd, dma_addr_t next_dma_addr) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 952 | { |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 953 | struct mwl8k_rxd_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 954 | |
| 955 | rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr); |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 956 | rxd->rx_ctrl = MWL8K_AP_RX_CTRL_OWNED_BY_HOST; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 957 | } |
| 958 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 959 | static void mwl8k_rxd_ap_refill(void *_rxd, dma_addr_t addr, int len) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 960 | { |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 961 | struct mwl8k_rxd_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 962 | |
| 963 | rxd->pkt_len = cpu_to_le16(len); |
| 964 | rxd->pkt_phys_addr = cpu_to_le32(addr); |
| 965 | wmb(); |
| 966 | rxd->rx_ctrl = 0; |
| 967 | } |
| 968 | |
| 969 | static int |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 970 | mwl8k_rxd_ap_process(void *_rxd, struct ieee80211_rx_status *status, |
| 971 | __le16 *qos, s8 *noise) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 972 | { |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 973 | struct mwl8k_rxd_ap *rxd = _rxd; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 974 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 975 | if (!(rxd->rx_ctrl & MWL8K_AP_RX_CTRL_OWNED_BY_HOST)) |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 976 | return -1; |
| 977 | rmb(); |
| 978 | |
| 979 | memset(status, 0, sizeof(*status)); |
| 980 | |
| 981 | status->signal = -rxd->rssi; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 982 | *noise = -rxd->noise_floor; |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 983 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 984 | if (rxd->rate & MWL8K_AP_RATE_INFO_MCS_FORMAT) { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 985 | status->flag |= RX_FLAG_HT; |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 986 | if (rxd->rate & MWL8K_AP_RATE_INFO_40MHZ) |
Lennert Buytenhek | 8e9f33f | 2009-11-30 18:12:35 +0100 | [diff] [blame] | 987 | status->flag |= RX_FLAG_40MHZ; |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 988 | status->rate_idx = MWL8K_AP_RATE_INFO_RATEID(rxd->rate); |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 989 | } else { |
| 990 | int i; |
| 991 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 992 | for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) { |
| 993 | if (mwl8k_rates_24[i].hw_value == rxd->rate) { |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 994 | status->rate_idx = i; |
| 995 | break; |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
Lennert Buytenhek | 8547834 | 2010-01-12 13:48:56 +0100 | [diff] [blame] | 1000 | if (rxd->channel > 14) { |
| 1001 | status->band = IEEE80211_BAND_5GHZ; |
| 1002 | if (!(status->flag & RX_FLAG_HT)) |
| 1003 | status->rate_idx -= 5; |
| 1004 | } else { |
| 1005 | status->band = IEEE80211_BAND_2GHZ; |
| 1006 | } |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 1007 | status->freq = ieee80211_channel_to_frequency(rxd->channel, |
| 1008 | status->band); |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 1009 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1010 | *qos = rxd->qos_control; |
| 1011 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 1012 | if ((rxd->rx_status != MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR) && |
| 1013 | (rxd->rx_status & MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK) && |
| 1014 | (rxd->rx_status & MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR)) |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1015 | status->flag |= RX_FLAG_MMIC_ERROR; |
| 1016 | |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 1017 | return le16_to_cpu(rxd->pkt_len); |
| 1018 | } |
| 1019 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 1020 | static struct rxd_ops rxd_ap_ops = { |
| 1021 | .rxd_size = sizeof(struct mwl8k_rxd_ap), |
| 1022 | .rxd_init = mwl8k_rxd_ap_init, |
| 1023 | .rxd_refill = mwl8k_rxd_ap_refill, |
| 1024 | .rxd_process = mwl8k_rxd_ap_process, |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 1025 | }; |
| 1026 | |
| 1027 | /* |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1028 | * Packet reception for STA firmware. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1029 | */ |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1030 | struct mwl8k_rxd_sta { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1031 | __le16 pkt_len; |
| 1032 | __u8 link_quality; |
| 1033 | __u8 noise_level; |
| 1034 | __le32 pkt_phys_addr; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1035 | __le32 next_rxd_phys_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1036 | __le16 qos_control; |
| 1037 | __le16 rate_info; |
| 1038 | __le32 pad0[4]; |
| 1039 | __u8 rssi; |
| 1040 | __u8 channel; |
| 1041 | __le16 pad1; |
| 1042 | __u8 rx_ctrl; |
| 1043 | __u8 rx_status; |
| 1044 | __u8 pad2[2]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 1045 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1046 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1047 | #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000 |
| 1048 | #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3) |
| 1049 | #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f) |
| 1050 | #define MWL8K_STA_RATE_INFO_40MHZ 0x0004 |
| 1051 | #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002 |
| 1052 | #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001 |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1053 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1054 | #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02 |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1055 | #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04 |
| 1056 | /* ICV=0 or MIC=1 */ |
| 1057 | #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08 |
| 1058 | /* Key is uploaded only in failure case */ |
| 1059 | #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30 |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1060 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1061 | 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] | 1062 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1063 | struct mwl8k_rxd_sta *rxd = _rxd; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1064 | |
| 1065 | rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr); |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1066 | rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1067 | } |
| 1068 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1069 | 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] | 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 | |
| 1073 | rxd->pkt_len = cpu_to_le16(len); |
| 1074 | rxd->pkt_phys_addr = cpu_to_le32(addr); |
| 1075 | wmb(); |
| 1076 | rxd->rx_ctrl = 0; |
| 1077 | } |
| 1078 | |
| 1079 | static int |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1080 | mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1081 | __le16 *qos, s8 *noise) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1082 | { |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1083 | struct mwl8k_rxd_sta *rxd = _rxd; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1084 | u16 rate_info; |
| 1085 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1086 | if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST)) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1087 | return -1; |
| 1088 | rmb(); |
| 1089 | |
| 1090 | rate_info = le16_to_cpu(rxd->rate_info); |
| 1091 | |
| 1092 | memset(status, 0, sizeof(*status)); |
| 1093 | |
| 1094 | status->signal = -rxd->rssi; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1095 | *noise = -rxd->noise_level; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1096 | status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info); |
| 1097 | status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1098 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1099 | if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1100 | status->flag |= RX_FLAG_SHORTPRE; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1101 | if (rate_info & MWL8K_STA_RATE_INFO_40MHZ) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1102 | status->flag |= RX_FLAG_40MHZ; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1103 | if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1104 | status->flag |= RX_FLAG_SHORT_GI; |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1105 | if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT) |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1106 | status->flag |= RX_FLAG_HT; |
| 1107 | |
Lennert Buytenhek | 8547834 | 2010-01-12 13:48:56 +0100 | [diff] [blame] | 1108 | if (rxd->channel > 14) { |
| 1109 | status->band = IEEE80211_BAND_5GHZ; |
| 1110 | if (!(status->flag & RX_FLAG_HT)) |
| 1111 | status->rate_idx -= 5; |
| 1112 | } else { |
| 1113 | status->band = IEEE80211_BAND_2GHZ; |
| 1114 | } |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 1115 | status->freq = ieee80211_channel_to_frequency(rxd->channel, |
| 1116 | status->band); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1117 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1118 | *qos = rxd->qos_control; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1119 | if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) && |
| 1120 | (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE)) |
| 1121 | status->flag |= RX_FLAG_MMIC_ERROR; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1122 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1123 | return le16_to_cpu(rxd->pkt_len); |
| 1124 | } |
| 1125 | |
Lennert Buytenhek | 89a91f4 | 2009-11-30 18:32:54 +0100 | [diff] [blame] | 1126 | static struct rxd_ops rxd_sta_ops = { |
| 1127 | .rxd_size = sizeof(struct mwl8k_rxd_sta), |
| 1128 | .rxd_init = mwl8k_rxd_sta_init, |
| 1129 | .rxd_refill = mwl8k_rxd_sta_refill, |
| 1130 | .rxd_process = mwl8k_rxd_sta_process, |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1134 | #define MWL8K_RX_DESCS 256 |
| 1135 | #define MWL8K_RX_MAXSZ 3800 |
| 1136 | |
| 1137 | static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index) |
| 1138 | { |
| 1139 | struct mwl8k_priv *priv = hw->priv; |
| 1140 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1141 | int size; |
| 1142 | int i; |
| 1143 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1144 | rxq->rxd_count = 0; |
| 1145 | rxq->head = 0; |
| 1146 | rxq->tail = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1147 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1148 | size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1149 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1150 | rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma); |
| 1151 | if (rxq->rxd == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1152 | wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1153 | return -ENOMEM; |
| 1154 | } |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1155 | memset(rxq->rxd, 0, size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1156 | |
Shan Wei | b9ede5f | 2011-03-08 11:02:03 +0800 | [diff] [blame] | 1157 | rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL); |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1158 | if (rxq->buf == NULL) { |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1159 | pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1160 | return -ENOMEM; |
| 1161 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1162 | |
| 1163 | for (i = 0; i < MWL8K_RX_DESCS; i++) { |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1164 | int desc_size; |
| 1165 | void *rxd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1166 | int nexti; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1167 | dma_addr_t next_dma_addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1168 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1169 | desc_size = priv->rxd_ops->rxd_size; |
| 1170 | rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1171 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1172 | nexti = i + 1; |
| 1173 | if (nexti == MWL8K_RX_DESCS) |
| 1174 | nexti = 0; |
| 1175 | next_dma_addr = rxq->rxd_dma + (nexti * desc_size); |
| 1176 | |
| 1177 | priv->rxd_ops->rxd_init(rxd, next_dma_addr); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | static int rxq_refill(struct ieee80211_hw *hw, int index, int limit) |
| 1184 | { |
| 1185 | struct mwl8k_priv *priv = hw->priv; |
| 1186 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1187 | int refilled; |
| 1188 | |
| 1189 | refilled = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1190 | while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1191 | struct sk_buff *skb; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1192 | dma_addr_t addr; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1193 | int rx; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1194 | void *rxd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1195 | |
| 1196 | skb = dev_alloc_skb(MWL8K_RX_MAXSZ); |
| 1197 | if (skb == NULL) |
| 1198 | break; |
| 1199 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1200 | addr = pci_map_single(priv->pdev, skb->data, |
| 1201 | MWL8K_RX_MAXSZ, DMA_FROM_DEVICE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1202 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1203 | rxq->rxd_count++; |
| 1204 | rx = rxq->tail++; |
| 1205 | if (rxq->tail == MWL8K_RX_DESCS) |
| 1206 | rxq->tail = 0; |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1207 | rxq->buf[rx].skb = skb; |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1208 | dma_unmap_addr_set(&rxq->buf[rx], dma, addr); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1209 | |
| 1210 | rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size); |
| 1211 | priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1212 | |
| 1213 | refilled++; |
| 1214 | } |
| 1215 | |
| 1216 | return refilled; |
| 1217 | } |
| 1218 | |
| 1219 | /* Must be called only when the card's reception is completely halted */ |
| 1220 | static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index) |
| 1221 | { |
| 1222 | struct mwl8k_priv *priv = hw->priv; |
| 1223 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1224 | int i; |
| 1225 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 1226 | if (rxq->rxd == NULL) |
| 1227 | return; |
| 1228 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1229 | for (i = 0; i < MWL8K_RX_DESCS; i++) { |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1230 | if (rxq->buf[i].skb != NULL) { |
| 1231 | pci_unmap_single(priv->pdev, |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1232 | dma_unmap_addr(&rxq->buf[i], dma), |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1233 | MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1234 | dma_unmap_addr_set(&rxq->buf[i], dma, 0); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1235 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1236 | kfree_skb(rxq->buf[i].skb); |
| 1237 | rxq->buf[i].skb = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1241 | kfree(rxq->buf); |
| 1242 | rxq->buf = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1243 | |
| 1244 | pci_free_consistent(priv->pdev, |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1245 | MWL8K_RX_DESCS * priv->rxd_ops->rxd_size, |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1246 | rxq->rxd, rxq->rxd_dma); |
| 1247 | rxq->rxd = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | /* |
| 1252 | * Scan a list of BSSIDs to process for finalize join. |
| 1253 | * Allows for extension to process multiple BSSIDs. |
| 1254 | */ |
| 1255 | static inline int |
| 1256 | mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh) |
| 1257 | { |
| 1258 | return priv->capture_beacon && |
| 1259 | ieee80211_is_beacon(wh->frame_control) && |
Julia Lawall | 3f9a79b | 2013-12-30 19:15:01 +0100 | [diff] [blame] | 1260 | ether_addr_equal_64bits(wh->addr3, priv->capture_bssid); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1261 | } |
| 1262 | |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1263 | static inline void mwl8k_save_beacon(struct ieee80211_hw *hw, |
| 1264 | struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1265 | { |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1266 | struct mwl8k_priv *priv = hw->priv; |
| 1267 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1268 | priv->capture_beacon = false; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1269 | memset(priv->capture_bssid, 0, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1270 | |
| 1271 | /* |
| 1272 | * Use GFP_ATOMIC as rxq_process is called from |
| 1273 | * the primary interrupt handler, memory allocation call |
| 1274 | * must not sleep. |
| 1275 | */ |
| 1276 | priv->beacon_skb = skb_copy(skb, GFP_ATOMIC); |
| 1277 | if (priv->beacon_skb != NULL) |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1278 | ieee80211_queue_work(hw, &priv->finalize_join_worker); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1281 | static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list, |
| 1282 | u8 *bssid) |
| 1283 | { |
| 1284 | struct mwl8k_vif *mwl8k_vif; |
| 1285 | |
| 1286 | list_for_each_entry(mwl8k_vif, |
| 1287 | vif_list, list) { |
| 1288 | if (memcmp(bssid, mwl8k_vif->bssid, |
| 1289 | ETH_ALEN) == 0) |
| 1290 | return mwl8k_vif; |
| 1291 | } |
| 1292 | |
| 1293 | return NULL; |
| 1294 | } |
| 1295 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1296 | static int rxq_process(struct ieee80211_hw *hw, int index, int limit) |
| 1297 | { |
| 1298 | struct mwl8k_priv *priv = hw->priv; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1299 | struct mwl8k_vif *mwl8k_vif = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1300 | struct mwl8k_rx_queue *rxq = priv->rxq + index; |
| 1301 | int processed; |
| 1302 | |
| 1303 | processed = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1304 | while (rxq->rxd_count && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1305 | struct sk_buff *skb; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1306 | void *rxd; |
| 1307 | int pkt_len; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1308 | struct ieee80211_rx_status status; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1309 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1310 | __le16 qos; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1311 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1312 | skb = rxq->buf[rxq->head].skb; |
Lennert Buytenhek | d25f9f1 | 2009-08-03 21:58:26 +0200 | [diff] [blame] | 1313 | if (skb == NULL) |
| 1314 | break; |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1315 | |
| 1316 | rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size); |
| 1317 | |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 1318 | pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos, |
| 1319 | &priv->noise); |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1320 | if (pkt_len < 0) |
| 1321 | break; |
| 1322 | |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1323 | rxq->buf[rxq->head].skb = NULL; |
| 1324 | |
| 1325 | pci_unmap_single(priv->pdev, |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1326 | dma_unmap_addr(&rxq->buf[rxq->head], dma), |
Lennert Buytenhek | 788838e | 2009-10-22 20:20:56 +0200 | [diff] [blame] | 1327 | MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 53b1b3e | 2010-04-02 13:10:38 +0900 | [diff] [blame] | 1328 | dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1329 | |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1330 | rxq->head++; |
| 1331 | if (rxq->head == MWL8K_RX_DESCS) |
| 1332 | rxq->head = 0; |
| 1333 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1334 | rxq->rxd_count--; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1335 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1336 | wh = &((struct mwl8k_dma_data *)skb->data)->wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1337 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1338 | /* |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 1339 | * Check for a pending join operation. Save a |
| 1340 | * copy of the beacon and schedule a tasklet to |
| 1341 | * send a FINALIZE_JOIN command to the firmware. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1342 | */ |
Lennert Buytenhek | 54bc3a0 | 2009-10-22 20:20:59 +0200 | [diff] [blame] | 1343 | if (mwl8k_capture_bssid(priv, (void *)skb->data)) |
Lennert Buytenhek | 3779752 | 2009-10-22 20:19:45 +0200 | [diff] [blame] | 1344 | mwl8k_save_beacon(hw, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1345 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1346 | if (ieee80211_has_protected(wh->frame_control)) { |
| 1347 | |
| 1348 | /* Check if hw crypto has been enabled for |
| 1349 | * this bss. If yes, set the status flags |
| 1350 | * accordingly |
| 1351 | */ |
| 1352 | mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list, |
| 1353 | wh->addr1); |
| 1354 | |
| 1355 | if (mwl8k_vif != NULL && |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 1356 | mwl8k_vif->is_hw_crypto_enabled) { |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1357 | /* |
| 1358 | * When MMIC ERROR is encountered |
| 1359 | * by the firmware, payload is |
| 1360 | * dropped and only 32 bytes of |
| 1361 | * mwl8k Firmware header is sent |
| 1362 | * to the host. |
| 1363 | * |
| 1364 | * We need to add four bytes of |
| 1365 | * key information. In it |
| 1366 | * MAC80211 expects keyidx set to |
| 1367 | * 0 for triggering Counter |
| 1368 | * Measure of MMIC failure. |
| 1369 | */ |
| 1370 | if (status.flag & RX_FLAG_MMIC_ERROR) { |
| 1371 | struct mwl8k_dma_data *tr; |
| 1372 | tr = (struct mwl8k_dma_data *)skb->data; |
| 1373 | memset((void *)&(tr->data), 0, 4); |
| 1374 | pkt_len += 4; |
| 1375 | } |
| 1376 | |
| 1377 | if (!ieee80211_is_auth(wh->frame_control)) |
| 1378 | status.flag |= RX_FLAG_IV_STRIPPED | |
| 1379 | RX_FLAG_DECRYPTED | |
| 1380 | RX_FLAG_MMIC_STRIPPED; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | skb_put(skb, pkt_len); |
| 1385 | mwl8k_remove_dma_header(skb, qos); |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 1386 | memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status)); |
| 1387 | ieee80211_rx_irqsafe(hw, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1388 | |
| 1389 | processed++; |
| 1390 | } |
| 1391 | |
| 1392 | return processed; |
| 1393 | } |
| 1394 | |
| 1395 | |
| 1396 | /* |
| 1397 | * Packet transmission. |
| 1398 | */ |
| 1399 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1400 | #define MWL8K_TXD_STATUS_OK 0x00000001 |
| 1401 | #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002 |
| 1402 | #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004 |
| 1403 | #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1404 | #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1405 | |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1406 | #define MWL8K_QOS_QLEN_UNSPEC 0xff00 |
| 1407 | #define MWL8K_QOS_ACK_POLICY_MASK 0x0060 |
| 1408 | #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000 |
| 1409 | #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060 |
| 1410 | #define MWL8K_QOS_EOSP 0x0010 |
| 1411 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1412 | struct mwl8k_tx_desc { |
| 1413 | __le32 status; |
| 1414 | __u8 data_rate; |
| 1415 | __u8 tx_priority; |
| 1416 | __le16 qos_control; |
| 1417 | __le32 pkt_phys_addr; |
| 1418 | __le16 pkt_len; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 1419 | __u8 dest_MAC_addr[ETH_ALEN]; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1420 | __le32 next_txd_phys_addr; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 1421 | __le32 timestamp; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1422 | __le16 rate_info; |
| 1423 | __u8 peer_id; |
Brian Cavagnolo | a1fe24b | 2010-11-12 17:23:47 -0800 | [diff] [blame] | 1424 | __u8 tx_frag_cnt; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 1425 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1426 | |
| 1427 | #define MWL8K_TX_DESCS 128 |
| 1428 | |
| 1429 | static int mwl8k_txq_init(struct ieee80211_hw *hw, int index) |
| 1430 | { |
| 1431 | struct mwl8k_priv *priv = hw->priv; |
| 1432 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1433 | int size; |
| 1434 | int i; |
| 1435 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1436 | txq->len = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1437 | txq->head = 0; |
| 1438 | txq->tail = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1439 | |
| 1440 | size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc); |
| 1441 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1442 | txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma); |
| 1443 | if (txq->txd == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 1444 | wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1445 | return -ENOMEM; |
| 1446 | } |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1447 | memset(txq->txd, 0, size); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1448 | |
Shan Wei | b9ede5f | 2011-03-08 11:02:03 +0800 | [diff] [blame] | 1449 | txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1450 | if (txq->skb == NULL) { |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1451 | pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1452 | return -ENOMEM; |
| 1453 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1454 | |
| 1455 | for (i = 0; i < MWL8K_TX_DESCS; i++) { |
| 1456 | struct mwl8k_tx_desc *tx_desc; |
| 1457 | int nexti; |
| 1458 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1459 | tx_desc = txq->txd + i; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1460 | nexti = (i + 1) % MWL8K_TX_DESCS; |
| 1461 | |
| 1462 | tx_desc->status = 0; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1463 | tx_desc->next_txd_phys_addr = |
| 1464 | cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | static inline void mwl8k_tx_start(struct mwl8k_priv *priv) |
| 1471 | { |
| 1472 | iowrite32(MWL8K_H2A_INT_PPA_READY, |
| 1473 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1474 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 1475 | priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 1476 | ioread32(priv->regs + MWL8K_HIU_INT_CODE); |
| 1477 | } |
| 1478 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1479 | static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1480 | { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1481 | struct mwl8k_priv *priv = hw->priv; |
| 1482 | int i; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1483 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 1484 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1485 | struct mwl8k_tx_queue *txq = priv->txq + i; |
| 1486 | int fw_owned = 0; |
| 1487 | int drv_owned = 0; |
| 1488 | int unused = 0; |
| 1489 | int desc; |
Lennert Buytenhek | c3f967d | 2009-08-18 04:15:22 +0200 | [diff] [blame] | 1490 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1491 | for (desc = 0; desc < MWL8K_TX_DESCS; desc++) { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1492 | struct mwl8k_tx_desc *tx_desc = txq->txd + desc; |
| 1493 | u32 status; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1494 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1495 | status = le32_to_cpu(tx_desc->status); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1496 | if (status & MWL8K_TXD_STATUS_FW_OWNED) |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1497 | fw_owned++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1498 | else |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1499 | drv_owned++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1500 | |
| 1501 | if (tx_desc->pkt_len == 0) |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1502 | unused++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1503 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1504 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1505 | wiphy_err(hw->wiphy, |
| 1506 | "txq[%d] len=%d head=%d tail=%d " |
| 1507 | "fw_owned=%d drv_owned=%d unused=%d\n", |
| 1508 | i, |
| 1509 | txq->len, txq->head, txq->tail, |
| 1510 | fw_owned, drv_owned, unused); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1511 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1512 | } |
| 1513 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1514 | /* |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 1515 | * Must be called with priv->fw_mutex held and tx queues stopped. |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 1516 | */ |
Lennert Buytenhek | 62abd3c | 2010-01-08 18:28:34 +0100 | [diff] [blame] | 1517 | #define MWL8K_TX_WAIT_TIMEOUT_MS 5000 |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1518 | |
Lennert Buytenhek | 950d5b0 | 2009-07-17 01:48:41 +0200 | [diff] [blame] | 1519 | static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1520 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1521 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 1522 | DECLARE_COMPLETION_ONSTACK(tx_wait); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1523 | int retry; |
| 1524 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1525 | |
| 1526 | might_sleep(); |
| 1527 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 1528 | /* Since fw restart is in progress, allow only the firmware |
| 1529 | * commands from the restart code and block the other |
| 1530 | * commands since they are going to fail in any case since |
| 1531 | * the firmware has crashed |
| 1532 | */ |
| 1533 | if (priv->hw_restart_in_progress) { |
| 1534 | if (priv->hw_restart_owner == current) |
| 1535 | return 0; |
| 1536 | else |
| 1537 | return -EBUSY; |
| 1538 | } |
| 1539 | |
Yogesh Ashok Powar | c27a54d | 2013-01-03 13:24:19 +0530 | [diff] [blame] | 1540 | if (atomic_read(&priv->watchdog_event_pending)) |
| 1541 | return 0; |
| 1542 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1543 | /* |
| 1544 | * The TX queues are stopped at this point, so this test |
| 1545 | * doesn't need to take ->tx_lock. |
| 1546 | */ |
| 1547 | if (!priv->pending_tx_pkts) |
| 1548 | return 0; |
| 1549 | |
Nishant Sarmukadam | bbf71a8 | 2013-05-24 14:42:25 +0530 | [diff] [blame] | 1550 | retry = 1; |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1551 | rc = 0; |
| 1552 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1553 | spin_lock_bh(&priv->tx_lock); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1554 | priv->tx_wait = &tx_wait; |
| 1555 | while (!rc) { |
| 1556 | int oldcount; |
| 1557 | unsigned long timeout; |
| 1558 | |
| 1559 | oldcount = priv->pending_tx_pkts; |
| 1560 | |
| 1561 | spin_unlock_bh(&priv->tx_lock); |
| 1562 | timeout = wait_for_completion_timeout(&tx_wait, |
| 1563 | msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS)); |
Yogesh Ashok Powar | c27a54d | 2013-01-03 13:24:19 +0530 | [diff] [blame] | 1564 | |
| 1565 | if (atomic_read(&priv->watchdog_event_pending)) { |
| 1566 | spin_lock_bh(&priv->tx_lock); |
| 1567 | priv->tx_wait = NULL; |
| 1568 | spin_unlock_bh(&priv->tx_lock); |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1572 | spin_lock_bh(&priv->tx_lock); |
| 1573 | |
Nishant Sarmukadam | bbf71a8 | 2013-05-24 14:42:25 +0530 | [diff] [blame] | 1574 | if (timeout || !priv->pending_tx_pkts) { |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1575 | WARN_ON(priv->pending_tx_pkts); |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 1576 | if (retry) |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1577 | wiphy_notice(hw->wiphy, "tx rings drained\n"); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1578 | break; |
| 1579 | } |
| 1580 | |
Nishant Sarmukadam | bbf71a8 | 2013-05-24 14:42:25 +0530 | [diff] [blame] | 1581 | if (retry) { |
| 1582 | mwl8k_tx_start(priv); |
| 1583 | retry = 0; |
| 1584 | continue; |
| 1585 | } |
| 1586 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1587 | if (priv->pending_tx_pkts < oldcount) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1588 | wiphy_notice(hw->wiphy, |
| 1589 | "waiting for tx rings to drain (%d -> %d pkts)\n", |
| 1590 | oldcount, priv->pending_tx_pkts); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1591 | retry = 1; |
| 1592 | continue; |
| 1593 | } |
| 1594 | |
| 1595 | priv->tx_wait = NULL; |
| 1596 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 1597 | wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n", |
| 1598 | MWL8K_TX_WAIT_TIMEOUT_MS); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1599 | mwl8k_dump_tx_rings(hw); |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 1600 | priv->hw_restart_in_progress = true; |
| 1601 | ieee80211_queue_work(hw, &priv->fw_reload); |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1602 | |
| 1603 | rc = -ETIMEDOUT; |
| 1604 | } |
Nishant Sarmukadam | 9b0b11f | 2013-01-08 10:16:05 +0530 | [diff] [blame] | 1605 | priv->tx_wait = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1606 | spin_unlock_bh(&priv->tx_lock); |
| 1607 | |
Lennert Buytenhek | 7e1112d | 2009-11-30 18:13:04 +0100 | [diff] [blame] | 1608 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1609 | } |
| 1610 | |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 1611 | #define MWL8K_TXD_SUCCESS(status) \ |
| 1612 | ((status) & (MWL8K_TXD_STATUS_OK | \ |
| 1613 | MWL8K_TXD_STATUS_OK_RETRY | \ |
| 1614 | MWL8K_TXD_STATUS_OK_MORE_RETRY)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1615 | |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1616 | static int mwl8k_tid_queue_mapping(u8 tid) |
| 1617 | { |
| 1618 | BUG_ON(tid > 7); |
| 1619 | |
| 1620 | switch (tid) { |
| 1621 | case 0: |
| 1622 | case 3: |
| 1623 | return IEEE80211_AC_BE; |
| 1624 | break; |
| 1625 | case 1: |
| 1626 | case 2: |
| 1627 | return IEEE80211_AC_BK; |
| 1628 | break; |
| 1629 | case 4: |
| 1630 | case 5: |
| 1631 | return IEEE80211_AC_VI; |
| 1632 | break; |
| 1633 | case 6: |
| 1634 | case 7: |
| 1635 | return IEEE80211_AC_VO; |
| 1636 | break; |
| 1637 | default: |
| 1638 | return -1; |
| 1639 | break; |
| 1640 | } |
| 1641 | } |
| 1642 | |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1643 | /* The firmware will fill in the rate information |
| 1644 | * for each packet that gets queued in the hardware |
John W. Linville | 49adc5c | 2011-04-27 15:04:28 -0400 | [diff] [blame] | 1645 | * and these macros will interpret that info. |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1646 | */ |
| 1647 | |
John W. Linville | 49adc5c | 2011-04-27 15:04:28 -0400 | [diff] [blame] | 1648 | #define RI_FORMAT(a) (a & 0x0001) |
| 1649 | #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3) |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1650 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1651 | static int |
| 1652 | 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] | 1653 | { |
| 1654 | struct mwl8k_priv *priv = hw->priv; |
| 1655 | struct mwl8k_tx_queue *txq = priv->txq + index; |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1656 | int processed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1657 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1658 | processed = 0; |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1659 | while (txq->len > 0 && limit--) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1660 | int tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1661 | struct mwl8k_tx_desc *tx_desc; |
| 1662 | unsigned long addr; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1663 | int size; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1664 | struct sk_buff *skb; |
| 1665 | struct ieee80211_tx_info *info; |
| 1666 | u32 status; |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1667 | struct ieee80211_sta *sta; |
| 1668 | struct mwl8k_sta *sta_info = NULL; |
| 1669 | u16 rate_info; |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1670 | struct ieee80211_hdr *wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1671 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1672 | tx = txq->head; |
| 1673 | tx_desc = txq->txd + tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1674 | |
| 1675 | status = le32_to_cpu(tx_desc->status); |
| 1676 | |
| 1677 | if (status & MWL8K_TXD_STATUS_FW_OWNED) { |
| 1678 | if (!force) |
| 1679 | break; |
| 1680 | tx_desc->status &= |
| 1681 | ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED); |
| 1682 | } |
| 1683 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1684 | txq->head = (tx + 1) % MWL8K_TX_DESCS; |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 1685 | BUG_ON(txq->len == 0); |
| 1686 | txq->len--; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1687 | priv->pending_tx_pkts--; |
| 1688 | |
| 1689 | addr = le32_to_cpu(tx_desc->pkt_phys_addr); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1690 | size = le16_to_cpu(tx_desc->pkt_len); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1691 | skb = txq->skb[tx]; |
| 1692 | txq->skb[tx] = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1693 | |
| 1694 | BUG_ON(skb == NULL); |
| 1695 | pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE); |
| 1696 | |
Lennert Buytenhek | 20f09c3 | 2009-11-30 18:12:08 +0100 | [diff] [blame] | 1697 | mwl8k_remove_dma_header(skb, tx_desc->qos_control); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1698 | |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1699 | wh = (struct ieee80211_hdr *) skb->data; |
| 1700 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1701 | /* Mark descriptor as unused */ |
| 1702 | tx_desc->pkt_phys_addr = 0; |
| 1703 | tx_desc->pkt_len = 0; |
| 1704 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1705 | info = IEEE80211_SKB_CB(skb); |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1706 | if (ieee80211_is_data(wh->frame_control)) { |
Thomas Huehn | 89e1180 | 2012-07-11 13:21:41 +0200 | [diff] [blame] | 1707 | rcu_read_lock(); |
| 1708 | sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1, |
| 1709 | wh->addr2); |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1710 | if (sta) { |
| 1711 | sta_info = MWL8K_STA(sta); |
| 1712 | BUG_ON(sta_info == NULL); |
| 1713 | rate_info = le16_to_cpu(tx_desc->rate_info); |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1714 | /* If rate is < 6.5 Mpbs for an ht station |
| 1715 | * do not form an ampdu. If the station is a |
| 1716 | * legacy station (format = 0), do not form an |
| 1717 | * ampdu |
| 1718 | */ |
John W. Linville | 49adc5c | 2011-04-27 15:04:28 -0400 | [diff] [blame] | 1719 | if (RI_RATE_ID_MCS(rate_info) < 1 || |
| 1720 | RI_FORMAT(rate_info) == 0) { |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1721 | sta_info->is_ampdu_allowed = false; |
| 1722 | } else { |
| 1723 | sta_info->is_ampdu_allowed = true; |
| 1724 | } |
| 1725 | } |
Thomas Huehn | 89e1180 | 2012-07-11 13:21:41 +0200 | [diff] [blame] | 1726 | rcu_read_unlock(); |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1729 | ieee80211_tx_info_clear_status(info); |
Nishant Sarmukadam | 0bf22c3 | 2011-02-17 14:45:17 -0800 | [diff] [blame] | 1730 | |
| 1731 | /* Rate control is happening in the firmware. |
| 1732 | * Ensure no tx rate is being reported. |
| 1733 | */ |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 1734 | info->status.rates[0].idx = -1; |
| 1735 | info->status.rates[0].count = 1; |
Nishant Sarmukadam | 0bf22c3 | 2011-02-17 14:45:17 -0800 | [diff] [blame] | 1736 | |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 1737 | if (MWL8K_TXD_SUCCESS(status)) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1738 | info->flags |= IEEE80211_TX_STAT_ACK; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1739 | |
| 1740 | ieee80211_tx_status_irqsafe(hw, skb); |
| 1741 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1742 | processed++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1743 | } |
| 1744 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1745 | return processed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | /* must be called only when the card's transmit is completely halted */ |
| 1749 | static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index) |
| 1750 | { |
| 1751 | struct mwl8k_priv *priv = hw->priv; |
| 1752 | struct mwl8k_tx_queue *txq = priv->txq + index; |
| 1753 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 1754 | if (txq->txd == NULL) |
| 1755 | return; |
| 1756 | |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 1757 | mwl8k_txq_reclaim(hw, index, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1758 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1759 | kfree(txq->skb); |
| 1760 | txq->skb = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1761 | |
| 1762 | pci_free_consistent(priv->pdev, |
| 1763 | MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc), |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 1764 | txq->txd, txq->txd_dma); |
| 1765 | txq->txd = NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1766 | } |
| 1767 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1768 | /* caller must hold priv->stream_lock when calling the stream functions */ |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 1769 | static struct mwl8k_ampdu_stream * |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1770 | mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid) |
| 1771 | { |
| 1772 | struct mwl8k_ampdu_stream *stream; |
| 1773 | struct mwl8k_priv *priv = hw->priv; |
| 1774 | int i; |
| 1775 | |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame] | 1776 | for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) { |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1777 | stream = &priv->ampdu[i]; |
| 1778 | if (stream->state == AMPDU_NO_STREAM) { |
| 1779 | stream->sta = sta; |
| 1780 | stream->state = AMPDU_STREAM_NEW; |
| 1781 | stream->tid = tid; |
| 1782 | stream->idx = i; |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1783 | wiphy_debug(hw->wiphy, "Added a new stream for %pM %d", |
| 1784 | sta->addr, tid); |
| 1785 | return stream; |
| 1786 | } |
| 1787 | } |
| 1788 | return NULL; |
| 1789 | } |
| 1790 | |
| 1791 | static int |
| 1792 | mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream) |
| 1793 | { |
| 1794 | int ret; |
| 1795 | |
| 1796 | /* if the stream has already been started, don't start it again */ |
| 1797 | if (stream->state != AMPDU_STREAM_NEW) |
| 1798 | return 0; |
| 1799 | ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0); |
| 1800 | if (ret) |
| 1801 | wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: " |
| 1802 | "%d\n", stream->sta->addr, stream->tid, ret); |
| 1803 | else |
| 1804 | wiphy_debug(hw->wiphy, "Started stream for %pM %d\n", |
| 1805 | stream->sta->addr, stream->tid); |
| 1806 | return ret; |
| 1807 | } |
| 1808 | |
| 1809 | static void |
| 1810 | mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream) |
| 1811 | { |
| 1812 | wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr, |
| 1813 | stream->tid); |
| 1814 | memset(stream, 0, sizeof(*stream)); |
| 1815 | } |
| 1816 | |
| 1817 | static struct mwl8k_ampdu_stream * |
| 1818 | mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid) |
| 1819 | { |
| 1820 | struct mwl8k_priv *priv = hw->priv; |
| 1821 | int i; |
| 1822 | |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame] | 1823 | for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) { |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 1824 | struct mwl8k_ampdu_stream *stream; |
| 1825 | stream = &priv->ampdu[i]; |
| 1826 | if (stream->state == AMPDU_NO_STREAM) |
| 1827 | continue; |
| 1828 | if (!memcmp(stream->sta->addr, addr, ETH_ALEN) && |
| 1829 | stream->tid == tid) |
| 1830 | return stream; |
| 1831 | } |
| 1832 | return NULL; |
| 1833 | } |
| 1834 | |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 1835 | #define MWL8K_AMPDU_PACKET_THRESHOLD 64 |
| 1836 | static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid) |
| 1837 | { |
| 1838 | struct mwl8k_sta *sta_info = MWL8K_STA(sta); |
| 1839 | struct tx_traffic_info *tx_stats; |
| 1840 | |
| 1841 | BUG_ON(tid >= MWL8K_MAX_TID); |
| 1842 | tx_stats = &sta_info->tx_stats[tid]; |
| 1843 | |
| 1844 | return sta_info->is_ampdu_allowed && |
| 1845 | tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD; |
| 1846 | } |
| 1847 | |
| 1848 | static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid) |
| 1849 | { |
| 1850 | struct mwl8k_sta *sta_info = MWL8K_STA(sta); |
| 1851 | struct tx_traffic_info *tx_stats; |
| 1852 | |
| 1853 | BUG_ON(tid >= MWL8K_MAX_TID); |
| 1854 | tx_stats = &sta_info->tx_stats[tid]; |
| 1855 | |
| 1856 | if (tx_stats->start_time == 0) |
| 1857 | tx_stats->start_time = jiffies; |
| 1858 | |
| 1859 | /* reset the packet count after each second elapses. If the number of |
| 1860 | * packets ever exceeds the ampdu_min_traffic threshold, we will allow |
| 1861 | * an ampdu stream to be started. |
| 1862 | */ |
| 1863 | if (jiffies - tx_stats->start_time > HZ) { |
| 1864 | tx_stats->pkts = 0; |
| 1865 | tx_stats->start_time = 0; |
| 1866 | } else |
| 1867 | tx_stats->pkts++; |
| 1868 | } |
| 1869 | |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame] | 1870 | /* The hardware ampdu queues start from 5. |
| 1871 | * txpriorities for ampdu queues are |
| 1872 | * 5 6 7 0 1 2 3 4 ie., queue 5 is highest |
| 1873 | * and queue 3 is lowest (queue 4 is reserved) |
| 1874 | */ |
| 1875 | #define BA_QUEUE 5 |
| 1876 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1877 | static void |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1878 | mwl8k_txq_xmit(struct ieee80211_hw *hw, |
| 1879 | int index, |
| 1880 | struct ieee80211_sta *sta, |
| 1881 | struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1882 | { |
| 1883 | struct mwl8k_priv *priv = hw->priv; |
| 1884 | struct ieee80211_tx_info *tx_info; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1885 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1886 | struct ieee80211_hdr *wh; |
| 1887 | struct mwl8k_tx_queue *txq; |
| 1888 | struct mwl8k_tx_desc *tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1889 | dma_addr_t dma; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1890 | u32 txstatus; |
| 1891 | u8 txdatarate; |
| 1892 | u16 qos; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1893 | int txpriority; |
| 1894 | u8 tid = 0; |
| 1895 | struct mwl8k_ampdu_stream *stream = NULL; |
| 1896 | bool start_ba_session = false; |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 1897 | bool mgmtframe = false; |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1898 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; |
Nishant Sarmukadam | e1f4d69 | 2012-11-06 19:23:01 +0530 | [diff] [blame] | 1899 | bool eapol_frame = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1900 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1901 | wh = (struct ieee80211_hdr *)skb->data; |
| 1902 | if (ieee80211_is_data_qos(wh->frame_control)) |
| 1903 | qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh))); |
| 1904 | else |
| 1905 | qos = 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1906 | |
Nishant Sarmukadam | e1f4d69 | 2012-11-06 19:23:01 +0530 | [diff] [blame] | 1907 | if (skb->protocol == cpu_to_be16(ETH_P_PAE)) |
| 1908 | eapol_frame = true; |
| 1909 | |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 1910 | if (ieee80211_is_mgmt(wh->frame_control)) |
| 1911 | mgmtframe = true; |
| 1912 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1913 | if (priv->ap_fw) |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 1914 | mwl8k_encapsulate_tx_frame(priv, skb); |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1915 | else |
Yogesh Ashok Powar | e4eefec | 2011-05-05 16:30:48 +0530 | [diff] [blame] | 1916 | mwl8k_add_dma_header(priv, skb, 0, 0); |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 1917 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1918 | wh = &((struct mwl8k_dma_data *)skb->data)->wh; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1919 | |
| 1920 | tx_info = IEEE80211_SKB_CB(skb); |
| 1921 | mwl8k_vif = MWL8K_VIF(tx_info->control.vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1922 | |
| 1923 | if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1924 | wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
Lennert Buytenhek | 657232b | 2010-01-12 13:47:47 +0100 | [diff] [blame] | 1925 | wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno); |
| 1926 | mwl8k_vif->seqno += 0x10; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1927 | } |
| 1928 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1929 | /* Setup firmware control bit fields for each frame type. */ |
| 1930 | txstatus = 0; |
| 1931 | txdatarate = 0; |
| 1932 | if (ieee80211_is_mgmt(wh->frame_control) || |
| 1933 | ieee80211_is_ctl(wh->frame_control)) { |
| 1934 | txdatarate = 0; |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1935 | qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1936 | } else if (ieee80211_is_data(wh->frame_control)) { |
| 1937 | txdatarate = 1; |
| 1938 | if (is_multicast_ether_addr(wh->addr1)) |
| 1939 | txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX; |
| 1940 | |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1941 | qos &= ~MWL8K_QOS_ACK_POLICY_MASK; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1942 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1943 | qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1944 | else |
Lennert Buytenhek | e0493a8 | 2009-11-30 18:32:00 +0100 | [diff] [blame] | 1945 | qos |= MWL8K_QOS_ACK_POLICY_NORMAL; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 1946 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 1947 | |
Nishant Sarmukadam | a0e7c6c | 2011-03-17 11:58:49 -0700 | [diff] [blame] | 1948 | /* Queue ADDBA request in the respective data queue. While setting up |
| 1949 | * the ampdu stream, mac80211 queues further packets for that |
| 1950 | * particular ra/tid pair. However, packets piled up in the hardware |
| 1951 | * for that ra/tid pair will still go out. ADDBA request and the |
| 1952 | * related data packets going out from different queues asynchronously |
| 1953 | * will cause a shift in the receiver window which might result in |
| 1954 | * ampdu packets getting dropped at the receiver after the stream has |
| 1955 | * been setup. |
| 1956 | */ |
| 1957 | if (unlikely(ieee80211_is_action(wh->frame_control) && |
| 1958 | mgmt->u.action.category == WLAN_CATEGORY_BACK && |
| 1959 | mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ && |
| 1960 | priv->ap_fw)) { |
| 1961 | u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 1962 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 1963 | index = mwl8k_tid_queue_mapping(tid); |
| 1964 | } |
| 1965 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1966 | txpriority = index; |
| 1967 | |
Nishant Sarmukadam | e1f4d69 | 2012-11-06 19:23:01 +0530 | [diff] [blame] | 1968 | if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame && |
| 1969 | ieee80211_is_data_qos(wh->frame_control)) { |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1970 | tid = qos & 0xf; |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 1971 | mwl8k_tx_count_packet(sta, tid); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1972 | spin_lock(&priv->stream_lock); |
| 1973 | stream = mwl8k_lookup_stream(hw, sta->addr, tid); |
| 1974 | if (stream != NULL) { |
| 1975 | if (stream->state == AMPDU_STREAM_ACTIVE) { |
Yogesh Ashok Powar | 5f2a149 | 2013-01-03 13:21:25 +0530 | [diff] [blame] | 1976 | WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK)); |
Yogesh Ashok Powar | 7fb978b | 2013-01-03 13:22:56 +0530 | [diff] [blame] | 1977 | txpriority = (BA_QUEUE + stream->idx) % |
| 1978 | TOTAL_HW_TX_QUEUES; |
| 1979 | if (stream->idx <= 1) |
| 1980 | index = stream->idx + |
| 1981 | MWL8K_TX_WMM_QUEUES; |
| 1982 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 1983 | } else if (stream->state == AMPDU_STREAM_NEW) { |
| 1984 | /* We get here if the driver sends us packets |
| 1985 | * after we've initiated a stream, but before |
| 1986 | * our ampdu_action routine has been called |
| 1987 | * with IEEE80211_AMPDU_TX_START to get the SSN |
| 1988 | * for the ADDBA request. So this packet can |
| 1989 | * go out with no risk of sequence number |
| 1990 | * mismatch. No special handling is required. |
| 1991 | */ |
| 1992 | } else { |
| 1993 | /* Drop packets that would go out after the |
| 1994 | * ADDBA request was sent but before the ADDBA |
| 1995 | * response is received. If we don't do this, |
| 1996 | * the recipient would probably receive it |
| 1997 | * after the ADDBA request with SSN 0. This |
| 1998 | * will cause the recipient's BA receive window |
| 1999 | * to shift, which would cause the subsequent |
| 2000 | * packets in the BA stream to be discarded. |
| 2001 | * mac80211 queues our packets for us in this |
| 2002 | * case, so this is really just a safety check. |
| 2003 | */ |
| 2004 | wiphy_warn(hw->wiphy, |
| 2005 | "Cannot send packet while ADDBA " |
| 2006 | "dialog is underway.\n"); |
| 2007 | spin_unlock(&priv->stream_lock); |
| 2008 | dev_kfree_skb(skb); |
| 2009 | return; |
| 2010 | } |
| 2011 | } else { |
| 2012 | /* Defer calling mwl8k_start_stream so that the current |
| 2013 | * skb can go out before the ADDBA request. This |
| 2014 | * prevents sequence number mismatch at the recepient |
| 2015 | * as described above. |
| 2016 | */ |
Brian Cavagnolo | d0805c1 | 2011-04-12 11:06:28 -0700 | [diff] [blame] | 2017 | if (mwl8k_ampdu_allowed(sta, tid)) { |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 2018 | stream = mwl8k_add_stream(hw, sta, tid); |
| 2019 | if (stream != NULL) |
| 2020 | start_ba_session = true; |
| 2021 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2022 | } |
| 2023 | spin_unlock(&priv->stream_lock); |
Yogesh Ashok Powar | 5f2a149 | 2013-01-03 13:21:25 +0530 | [diff] [blame] | 2024 | } else { |
| 2025 | qos &= ~MWL8K_QOS_ACK_POLICY_MASK; |
| 2026 | qos |= MWL8K_QOS_ACK_POLICY_NORMAL; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2029 | dma = pci_map_single(priv->pdev, skb->data, |
| 2030 | skb->len, PCI_DMA_TODEVICE); |
| 2031 | |
| 2032 | if (pci_dma_mapping_error(priv->pdev, dma)) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2033 | wiphy_debug(hw->wiphy, |
| 2034 | "failed to dma map skb, dropping TX frame.\n"); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2035 | if (start_ba_session) { |
| 2036 | spin_lock(&priv->stream_lock); |
| 2037 | mwl8k_remove_stream(hw, stream); |
| 2038 | spin_unlock(&priv->stream_lock); |
| 2039 | } |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2040 | dev_kfree_skb(skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 2041 | return; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2042 | } |
| 2043 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2044 | spin_lock_bh(&priv->tx_lock); |
| 2045 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2046 | txq = priv->txq + index; |
| 2047 | |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 2048 | /* Mgmt frames that go out frequently are probe |
| 2049 | * responses. Other mgmt frames got out relatively |
| 2050 | * infrequently. Hence reserve 2 buffers so that |
| 2051 | * other mgmt frames do not get dropped due to an |
| 2052 | * already queued probe response in one of the |
| 2053 | * reserved buffers. |
| 2054 | */ |
| 2055 | |
| 2056 | if (txq->len >= MWL8K_TX_DESCS - 2) { |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 2057 | if (!mgmtframe || txq->len == MWL8K_TX_DESCS) { |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 2058 | if (start_ba_session) { |
| 2059 | spin_lock(&priv->stream_lock); |
| 2060 | mwl8k_remove_stream(hw, stream); |
| 2061 | spin_unlock(&priv->stream_lock); |
| 2062 | } |
Nishant Sarmukadam | bbf71a8 | 2013-05-24 14:42:25 +0530 | [diff] [blame] | 2063 | mwl8k_tx_start(priv); |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 2064 | spin_unlock_bh(&priv->tx_lock); |
Nishant Sarmukadam | ff7aa96 | 2012-11-06 19:22:48 +0530 | [diff] [blame] | 2065 | pci_unmap_single(priv->pdev, dma, skb->len, |
| 2066 | PCI_DMA_TODEVICE); |
Nishant Sarmukadam | 3a76988 | 2011-04-21 16:34:58 +0530 | [diff] [blame] | 2067 | dev_kfree_skb(skb); |
| 2068 | return; |
Pradeep Nemavat | 3a7dbc3 | 2011-04-21 16:34:56 +0530 | [diff] [blame] | 2069 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2072 | BUG_ON(txq->skb[txq->tail] != NULL); |
| 2073 | txq->skb[txq->tail] = skb; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2074 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2075 | tx = txq->txd + txq->tail; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2076 | tx->data_rate = txdatarate; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2077 | tx->tx_priority = txpriority; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2078 | tx->qos_control = cpu_to_le16(qos); |
| 2079 | tx->pkt_phys_addr = cpu_to_le32(dma); |
| 2080 | tx->pkt_len = cpu_to_le16(skb->len); |
| 2081 | tx->rate_info = 0; |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 2082 | if (!priv->ap_fw && sta != NULL) |
| 2083 | tx->peer_id = MWL8K_STA(sta)->peer_id; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 2084 | else |
| 2085 | tx->peer_id = 0; |
Pradeep Nemavat | 566875d | 2011-04-21 16:34:57 +0530 | [diff] [blame] | 2086 | |
Nishant Sarmukadam | e1f4d69 | 2012-11-06 19:23:01 +0530 | [diff] [blame] | 2087 | if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame) |
Pradeep Nemavat | 566875d | 2011-04-21 16:34:57 +0530 | [diff] [blame] | 2088 | tx->timestamp = cpu_to_le32(ioread32(priv->regs + |
| 2089 | MWL8K_HW_TIMER_REGISTER)); |
Nishant Sarmukadam | b8d9e57 | 2012-11-06 19:23:15 +0530 | [diff] [blame] | 2090 | else |
| 2091 | tx->timestamp = 0; |
Pradeep Nemavat | 566875d | 2011-04-21 16:34:57 +0530 | [diff] [blame] | 2092 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2093 | wmb(); |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2094 | tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus); |
| 2095 | |
Kalle Valo | 8ccbc3b | 2010-02-07 10:20:52 +0200 | [diff] [blame] | 2096 | txq->len++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2097 | priv->pending_tx_pkts++; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2098 | |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2099 | txq->tail++; |
| 2100 | if (txq->tail == MWL8K_TX_DESCS) |
| 2101 | txq->tail = 0; |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2102 | |
Lennert Buytenhek | 23b3390 | 2009-07-17 05:21:04 +0200 | [diff] [blame] | 2103 | mwl8k_tx_start(priv); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2104 | |
| 2105 | spin_unlock_bh(&priv->tx_lock); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 2106 | |
| 2107 | /* Initiate the ampdu session here */ |
| 2108 | if (start_ba_session) { |
| 2109 | spin_lock(&priv->stream_lock); |
| 2110 | if (mwl8k_start_stream(hw, stream)) |
| 2111 | mwl8k_remove_stream(hw, stream); |
| 2112 | spin_unlock(&priv->stream_lock); |
| 2113 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | |
| 2117 | /* |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2118 | * Firmware access. |
| 2119 | * |
| 2120 | * We have the following requirements for issuing firmware commands: |
| 2121 | * - Some commands require that the packet transmit path is idle when |
| 2122 | * the command is issued. (For simplicity, we'll just quiesce the |
| 2123 | * transmit path for every command.) |
| 2124 | * - There are certain sequences of commands that need to be issued to |
| 2125 | * the hardware sequentially, with no other intervening commands. |
| 2126 | * |
| 2127 | * This leads to an implementation of a "firmware lock" as a mutex that |
| 2128 | * can be taken recursively, and which is taken by both the low-level |
| 2129 | * command submission function (mwl8k_post_cmd) as well as any users of |
| 2130 | * that function that require issuing of an atomic sequence of commands, |
| 2131 | * and quiesces the transmit path whenever it's taken. |
| 2132 | */ |
| 2133 | static int mwl8k_fw_lock(struct ieee80211_hw *hw) |
| 2134 | { |
| 2135 | struct mwl8k_priv *priv = hw->priv; |
| 2136 | |
| 2137 | if (priv->fw_mutex_owner != current) { |
| 2138 | int rc; |
| 2139 | |
| 2140 | mutex_lock(&priv->fw_mutex); |
| 2141 | ieee80211_stop_queues(hw); |
| 2142 | |
| 2143 | rc = mwl8k_tx_wait_empty(hw); |
| 2144 | if (rc) { |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 2145 | if (!priv->hw_restart_in_progress) |
| 2146 | ieee80211_wake_queues(hw); |
| 2147 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2148 | mutex_unlock(&priv->fw_mutex); |
| 2149 | |
| 2150 | return rc; |
| 2151 | } |
| 2152 | |
| 2153 | priv->fw_mutex_owner = current; |
| 2154 | } |
| 2155 | |
| 2156 | priv->fw_mutex_depth++; |
| 2157 | |
| 2158 | return 0; |
| 2159 | } |
| 2160 | |
| 2161 | static void mwl8k_fw_unlock(struct ieee80211_hw *hw) |
| 2162 | { |
| 2163 | struct mwl8k_priv *priv = hw->priv; |
| 2164 | |
| 2165 | if (!--priv->fw_mutex_depth) { |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 2166 | if (!priv->hw_restart_in_progress) |
| 2167 | ieee80211_wake_queues(hw); |
| 2168 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2169 | priv->fw_mutex_owner = NULL; |
| 2170 | mutex_unlock(&priv->fw_mutex); |
| 2171 | } |
| 2172 | } |
| 2173 | |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 2174 | static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable, |
| 2175 | u32 bitmap); |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2176 | |
| 2177 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2178 | * Command processing. |
| 2179 | */ |
| 2180 | |
Lennert Buytenhek | 0c9cc640 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2181 | /* Timeout firmware commands after 10s */ |
| 2182 | #define MWL8K_CMD_TIMEOUT_MS 10000 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2183 | |
| 2184 | static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd) |
| 2185 | { |
| 2186 | DECLARE_COMPLETION_ONSTACK(cmd_wait); |
| 2187 | struct mwl8k_priv *priv = hw->priv; |
| 2188 | void __iomem *regs = priv->regs; |
| 2189 | dma_addr_t dma_addr; |
| 2190 | unsigned int dma_size; |
| 2191 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2192 | unsigned long timeout = 0; |
| 2193 | u8 buf[32]; |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 2194 | u32 bitmap = 0; |
| 2195 | |
| 2196 | wiphy_dbg(hw->wiphy, "Posting %s [%d]\n", |
| 2197 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), cmd->macid); |
| 2198 | |
| 2199 | /* Before posting firmware commands that could change the hardware |
| 2200 | * characteristics, make sure that all BSSes are stopped temporary. |
| 2201 | * Enable these stopped BSSes after completion of the commands |
| 2202 | */ |
| 2203 | |
| 2204 | rc = mwl8k_fw_lock(hw); |
| 2205 | if (rc) |
| 2206 | return rc; |
| 2207 | |
| 2208 | if (priv->ap_fw && priv->running_bsses) { |
| 2209 | switch (le16_to_cpu(cmd->code)) { |
| 2210 | case MWL8K_CMD_SET_RF_CHANNEL: |
| 2211 | case MWL8K_CMD_RADIO_CONTROL: |
| 2212 | case MWL8K_CMD_RF_TX_POWER: |
| 2213 | case MWL8K_CMD_TX_POWER: |
| 2214 | case MWL8K_CMD_RF_ANTENNA: |
| 2215 | case MWL8K_CMD_RTS_THRESHOLD: |
| 2216 | case MWL8K_CMD_MIMO_CONFIG: |
| 2217 | bitmap = priv->running_bsses; |
| 2218 | mwl8k_enable_bsses(hw, false, bitmap); |
| 2219 | break; |
| 2220 | } |
| 2221 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2222 | |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2223 | cmd->result = (__force __le16) 0xffff; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2224 | dma_size = le16_to_cpu(cmd->length); |
| 2225 | dma_addr = pci_map_single(priv->pdev, cmd, dma_size, |
| 2226 | PCI_DMA_BIDIRECTIONAL); |
| 2227 | if (pci_dma_mapping_error(priv->pdev, dma_addr)) |
| 2228 | return -ENOMEM; |
| 2229 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2230 | priv->hostcmd_wait = &cmd_wait; |
| 2231 | iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR); |
| 2232 | iowrite32(MWL8K_H2A_INT_DOORBELL, |
| 2233 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
| 2234 | iowrite32(MWL8K_H2A_INT_DUMMY, |
| 2235 | regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2236 | |
| 2237 | timeout = wait_for_completion_timeout(&cmd_wait, |
| 2238 | msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS)); |
| 2239 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2240 | priv->hostcmd_wait = NULL; |
| 2241 | |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 2242 | |
Lennert Buytenhek | 37055bd | 2009-08-03 21:58:47 +0200 | [diff] [blame] | 2243 | pci_unmap_single(priv->pdev, dma_addr, dma_size, |
| 2244 | PCI_DMA_BIDIRECTIONAL); |
| 2245 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2246 | if (!timeout) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2247 | wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2248 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), |
| 2249 | MWL8K_CMD_TIMEOUT_MS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2250 | rc = -ETIMEDOUT; |
| 2251 | } else { |
Lennert Buytenhek | 0c9cc640 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2252 | int ms; |
| 2253 | |
| 2254 | ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout); |
| 2255 | |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2256 | rc = cmd->result ? -EINVAL : 0; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2257 | if (rc) |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2258 | wiphy_err(hw->wiphy, "Command %s error 0x%x\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2259 | mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), |
| 2260 | le16_to_cpu(cmd->result)); |
Lennert Buytenhek | 0c9cc640 | 2009-11-30 18:12:49 +0100 | [diff] [blame] | 2261 | else if (ms > 2000) |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 2262 | wiphy_notice(hw->wiphy, "Command %s took %d ms\n", |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 2263 | mwl8k_cmd_name(cmd->code, |
| 2264 | buf, sizeof(buf)), |
| 2265 | ms); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2266 | } |
| 2267 | |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 2268 | if (bitmap) |
| 2269 | mwl8k_enable_bsses(hw, true, bitmap); |
| 2270 | |
| 2271 | mwl8k_fw_unlock(hw); |
| 2272 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2273 | return rc; |
| 2274 | } |
| 2275 | |
Lennert Buytenhek | f57ca9c | 2010-01-12 13:50:14 +0100 | [diff] [blame] | 2276 | static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw, |
| 2277 | struct ieee80211_vif *vif, |
| 2278 | struct mwl8k_cmd_pkt *cmd) |
| 2279 | { |
| 2280 | if (vif != NULL) |
| 2281 | cmd->macid = MWL8K_VIF(vif)->macid; |
| 2282 | return mwl8k_post_cmd(hw, cmd); |
| 2283 | } |
| 2284 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2285 | /* |
Lennert Buytenhek | 1349ad2 | 2010-01-12 13:48:17 +0100 | [diff] [blame] | 2286 | * Setup code shared between STA and AP firmware images. |
| 2287 | */ |
| 2288 | static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw) |
| 2289 | { |
| 2290 | struct mwl8k_priv *priv = hw->priv; |
| 2291 | |
| 2292 | BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24)); |
| 2293 | memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24)); |
| 2294 | |
| 2295 | BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24)); |
| 2296 | memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24)); |
| 2297 | |
| 2298 | priv->band_24.band = IEEE80211_BAND_2GHZ; |
| 2299 | priv->band_24.channels = priv->channels_24; |
| 2300 | priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24); |
| 2301 | priv->band_24.bitrates = priv->rates_24; |
| 2302 | priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24); |
| 2303 | |
| 2304 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24; |
| 2305 | } |
| 2306 | |
Lennert Buytenhek | 4eae9ed | 2010-01-12 13:48:32 +0100 | [diff] [blame] | 2307 | static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw) |
| 2308 | { |
| 2309 | struct mwl8k_priv *priv = hw->priv; |
| 2310 | |
| 2311 | BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50)); |
| 2312 | memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50)); |
| 2313 | |
| 2314 | BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50)); |
| 2315 | memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50)); |
| 2316 | |
| 2317 | priv->band_50.band = IEEE80211_BAND_5GHZ; |
| 2318 | priv->band_50.channels = priv->channels_50; |
| 2319 | priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50); |
| 2320 | priv->band_50.bitrates = priv->rates_50; |
| 2321 | priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50); |
| 2322 | |
| 2323 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50; |
| 2324 | } |
| 2325 | |
Lennert Buytenhek | 1349ad2 | 2010-01-12 13:48:17 +0100 | [diff] [blame] | 2326 | /* |
Lennert Buytenhek | 04b147b1 | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2327 | * CMD_GET_HW_SPEC (STA version). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2328 | */ |
Lennert Buytenhek | 04b147b1 | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2329 | struct mwl8k_cmd_get_hw_spec_sta { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2330 | struct mwl8k_cmd_pkt header; |
| 2331 | __u8 hw_rev; |
| 2332 | __u8 host_interface; |
| 2333 | __le16 num_mcaddrs; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2334 | __u8 perm_addr[ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2335 | __le16 region_code; |
| 2336 | __le32 fw_rev; |
| 2337 | __le32 ps_cookie; |
| 2338 | __le32 caps; |
| 2339 | __u8 mcs_bitmap[16]; |
| 2340 | __le32 rx_queue_ptr; |
| 2341 | __le32 num_tx_queues; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2342 | __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2343 | __le32 caps2; |
| 2344 | __le32 num_tx_desc_per_queue; |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2345 | __le32 total_rxd; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2346 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2347 | |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2348 | #define MWL8K_CAP_MAX_AMSDU 0x20000000 |
| 2349 | #define MWL8K_CAP_GREENFIELD 0x08000000 |
| 2350 | #define MWL8K_CAP_AMPDU 0x04000000 |
| 2351 | #define MWL8K_CAP_RX_STBC 0x01000000 |
| 2352 | #define MWL8K_CAP_TX_STBC 0x00800000 |
| 2353 | #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000 |
| 2354 | #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000 |
| 2355 | #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000 |
| 2356 | #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000 |
| 2357 | #define MWL8K_CAP_DELAY_BA 0x00003000 |
| 2358 | #define MWL8K_CAP_MIMO 0x00000200 |
| 2359 | #define MWL8K_CAP_40MHZ 0x00000100 |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2360 | #define MWL8K_CAP_BAND_MASK 0x00000007 |
| 2361 | #define MWL8K_CAP_5GHZ 0x00000004 |
| 2362 | #define MWL8K_CAP_2GHZ4 0x00000001 |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2363 | |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2364 | static void |
| 2365 | mwl8k_set_ht_caps(struct ieee80211_hw *hw, |
| 2366 | struct ieee80211_supported_band *band, u32 cap) |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2367 | { |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2368 | int rx_streams; |
| 2369 | int tx_streams; |
| 2370 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2371 | band->ht_cap.ht_supported = 1; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2372 | |
| 2373 | if (cap & MWL8K_CAP_MAX_AMSDU) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2374 | band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2375 | if (cap & MWL8K_CAP_GREENFIELD) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2376 | band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2377 | if (cap & MWL8K_CAP_AMPDU) { |
| 2378 | hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION; |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2379 | band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 2380 | band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2381 | } |
| 2382 | if (cap & MWL8K_CAP_RX_STBC) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2383 | band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2384 | if (cap & MWL8K_CAP_TX_STBC) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2385 | band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2386 | if (cap & MWL8K_CAP_SHORTGI_40MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2387 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2388 | if (cap & MWL8K_CAP_SHORTGI_20MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2389 | band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2390 | if (cap & MWL8K_CAP_DELAY_BA) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2391 | band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2392 | if (cap & MWL8K_CAP_40MHZ) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2393 | band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2394 | |
| 2395 | rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK); |
| 2396 | tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK); |
| 2397 | |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2398 | band->ht_cap.mcs.rx_mask[0] = 0xff; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2399 | if (rx_streams >= 2) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2400 | band->ht_cap.mcs.rx_mask[1] = 0xff; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2401 | if (rx_streams >= 3) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2402 | band->ht_cap.mcs.rx_mask[2] = 0xff; |
| 2403 | band->ht_cap.mcs.rx_mask[4] = 0x01; |
| 2404 | band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2405 | |
| 2406 | if (rx_streams != tx_streams) { |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 2407 | band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF; |
| 2408 | band->ht_cap.mcs.tx_params |= (tx_streams - 1) << |
Lennert Buytenhek | 341c979 | 2010-01-04 21:58:40 +0100 | [diff] [blame] | 2409 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; |
| 2410 | } |
| 2411 | } |
| 2412 | |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2413 | static void |
| 2414 | mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps) |
| 2415 | { |
| 2416 | struct mwl8k_priv *priv = hw->priv; |
| 2417 | |
Jonas Gorski | c3f251a | 2013-03-11 17:44:21 +0100 | [diff] [blame] | 2418 | if (priv->caps) |
| 2419 | return; |
| 2420 | |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2421 | if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) { |
| 2422 | mwl8k_setup_2ghz_band(hw); |
| 2423 | if (caps & MWL8K_CAP_MIMO) |
| 2424 | mwl8k_set_ht_caps(hw, &priv->band_24, caps); |
| 2425 | } |
| 2426 | |
| 2427 | if (caps & MWL8K_CAP_5GHZ) { |
| 2428 | mwl8k_setup_5ghz_band(hw); |
| 2429 | if (caps & MWL8K_CAP_MIMO) |
| 2430 | mwl8k_set_ht_caps(hw, &priv->band_50, caps); |
| 2431 | } |
Jonas Gorski | c3f251a | 2013-03-11 17:44:21 +0100 | [diff] [blame] | 2432 | |
| 2433 | priv->caps = caps; |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2434 | } |
| 2435 | |
Lennert Buytenhek | 04b147b1 | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2436 | static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2437 | { |
| 2438 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 04b147b1 | 2009-10-22 20:21:05 +0200 | [diff] [blame] | 2439 | struct mwl8k_cmd_get_hw_spec_sta *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2440 | int rc; |
| 2441 | int i; |
| 2442 | |
| 2443 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2444 | if (cmd == NULL) |
| 2445 | return -ENOMEM; |
| 2446 | |
| 2447 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC); |
| 2448 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2449 | |
| 2450 | memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr)); |
| 2451 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2452 | cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma); |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2453 | cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv)); |
| 2454 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2455 | 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] | 2456 | cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); |
Lennert Buytenhek | 45eb400 | 2009-10-22 20:20:40 +0200 | [diff] [blame] | 2457 | cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2458 | |
| 2459 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2460 | |
| 2461 | if (!rc) { |
| 2462 | SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr); |
| 2463 | priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); |
Lennert Buytenhek | 4ff6432 | 2009-08-03 21:58:39 +0200 | [diff] [blame] | 2464 | priv->fw_rev = le32_to_cpu(cmd->fw_rev); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2465 | priv->hw_rev = cmd->hw_rev; |
Lennert Buytenhek | 0695323 | 2010-01-12 13:49:41 +0100 | [diff] [blame] | 2466 | mwl8k_set_caps(hw, le32_to_cpu(cmd->caps)); |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 2467 | priv->ap_macids_supported = 0x00000000; |
| 2468 | priv->sta_macids_supported = 0x00000001; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | kfree(cmd); |
| 2472 | return rc; |
| 2473 | } |
| 2474 | |
| 2475 | /* |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2476 | * CMD_GET_HW_SPEC (AP version). |
| 2477 | */ |
| 2478 | struct mwl8k_cmd_get_hw_spec_ap { |
| 2479 | struct mwl8k_cmd_pkt header; |
| 2480 | __u8 hw_rev; |
| 2481 | __u8 host_interface; |
| 2482 | __le16 num_wcb; |
| 2483 | __le16 num_mcaddrs; |
| 2484 | __u8 perm_addr[ETH_ALEN]; |
| 2485 | __le16 region_code; |
| 2486 | __le16 num_antenna; |
| 2487 | __le32 fw_rev; |
| 2488 | __le32 wcbbase0; |
| 2489 | __le32 rxwrptr; |
| 2490 | __le32 rxrdptr; |
| 2491 | __le32 ps_cookie; |
| 2492 | __le32 wcbbase1; |
| 2493 | __le32 wcbbase2; |
| 2494 | __le32 wcbbase3; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2495 | __le32 fw_api_version; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2496 | __le32 caps; |
| 2497 | __le32 num_of_ampdu_queues; |
| 2498 | __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2499 | } __packed; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2500 | |
| 2501 | static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw) |
| 2502 | { |
| 2503 | struct mwl8k_priv *priv = hw->priv; |
| 2504 | struct mwl8k_cmd_get_hw_spec_ap *cmd; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2505 | int rc, i; |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2506 | u32 api_version; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2507 | |
| 2508 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2509 | if (cmd == NULL) |
| 2510 | return -ENOMEM; |
| 2511 | |
| 2512 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC); |
| 2513 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2514 | |
| 2515 | memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr)); |
| 2516 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
| 2517 | |
| 2518 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2519 | |
| 2520 | if (!rc) { |
| 2521 | int off; |
| 2522 | |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2523 | api_version = le32_to_cpu(cmd->fw_api_version); |
| 2524 | if (priv->device_info->fw_api_ap != api_version) { |
| 2525 | printk(KERN_ERR "%s: Unsupported fw API version for %s." |
| 2526 | " Expected %d got %d.\n", MWL8K_NAME, |
| 2527 | priv->device_info->part_name, |
| 2528 | priv->device_info->fw_api_ap, |
| 2529 | api_version); |
| 2530 | rc = -EINVAL; |
| 2531 | goto done; |
| 2532 | } |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2533 | SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr); |
| 2534 | priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs); |
| 2535 | priv->fw_rev = le32_to_cpu(cmd->fw_rev); |
| 2536 | priv->hw_rev = cmd->hw_rev; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2537 | mwl8k_set_caps(hw, le32_to_cpu(cmd->caps)); |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 2538 | priv->ap_macids_supported = 0x000000ff; |
Yogesh Ashok Powar | d59c1cf | 2013-01-25 16:20:03 +0530 | [diff] [blame] | 2539 | priv->sta_macids_supported = 0x00000100; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2540 | priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues); |
| 2541 | if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) { |
| 2542 | wiphy_warn(hw->wiphy, "fw reported %d ampdu queues" |
| 2543 | " but we only support %d.\n", |
| 2544 | priv->num_ampdu_queues, |
| 2545 | MWL8K_MAX_AMPDU_QUEUES); |
| 2546 | priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES; |
| 2547 | } |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2548 | off = le32_to_cpu(cmd->rxwrptr) & 0xffff; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2549 | iowrite32(priv->rxq[0].rxd_dma, priv->sram + off); |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2550 | |
| 2551 | off = le32_to_cpu(cmd->rxrdptr) & 0xffff; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 2552 | iowrite32(priv->rxq[0].rxd_dma, priv->sram + off); |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2553 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 2554 | priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff; |
| 2555 | priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff; |
| 2556 | priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff; |
| 2557 | priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff; |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2558 | |
| 2559 | for (i = 0; i < priv->num_ampdu_queues; i++) |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2560 | priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] = |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2561 | le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2562 | } |
| 2563 | |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 2564 | done: |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2565 | kfree(cmd); |
| 2566 | return rc; |
| 2567 | } |
| 2568 | |
| 2569 | /* |
| 2570 | * CMD_SET_HW_SPEC. |
| 2571 | */ |
| 2572 | struct mwl8k_cmd_set_hw_spec { |
| 2573 | struct mwl8k_cmd_pkt header; |
| 2574 | __u8 hw_rev; |
| 2575 | __u8 host_interface; |
| 2576 | __le16 num_mcaddrs; |
| 2577 | __u8 perm_addr[ETH_ALEN]; |
| 2578 | __le16 region_code; |
| 2579 | __le32 fw_rev; |
| 2580 | __le32 ps_cookie; |
| 2581 | __le32 caps; |
| 2582 | __le32 rx_queue_ptr; |
| 2583 | __le32 num_tx_queues; |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2584 | __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES]; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2585 | __le32 flags; |
| 2586 | __le32 num_tx_desc_per_queue; |
| 2587 | __le32 total_rxd; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2588 | } __packed; |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2589 | |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 2590 | /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause |
| 2591 | * packets to expire 500 ms after the timestamp in the tx descriptor. That is, |
| 2592 | * the packets that are queued for more than 500ms, will be dropped in the |
| 2593 | * hardware. This helps minimizing the issues caused due to head-of-line |
| 2594 | * blocking where a slow client can hog the bandwidth and affect traffic to a |
| 2595 | * faster client. |
| 2596 | */ |
| 2597 | #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400 |
Nishant Sarmukadam | 3373b28 | 2011-06-13 16:26:15 +0530 | [diff] [blame] | 2598 | #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200 |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2599 | #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080 |
| 2600 | #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020 |
| 2601 | #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010 |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2602 | |
| 2603 | static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw) |
| 2604 | { |
| 2605 | struct mwl8k_priv *priv = hw->priv; |
| 2606 | struct mwl8k_cmd_set_hw_spec *cmd; |
| 2607 | int rc; |
| 2608 | int i; |
| 2609 | |
| 2610 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2611 | if (cmd == NULL) |
| 2612 | return -ENOMEM; |
| 2613 | |
| 2614 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC); |
| 2615 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2616 | |
| 2617 | cmd->ps_cookie = cpu_to_le32(priv->cookie_dma); |
| 2618 | cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma); |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2619 | cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv)); |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 2620 | |
| 2621 | /* |
| 2622 | * Mac80211 stack has Q0 as highest priority and Q3 as lowest in |
| 2623 | * that order. Firmware has Q3 as highest priority and Q0 as lowest |
| 2624 | * in that order. Map Q3 of mac80211 to Q0 of firmware so that the |
| 2625 | * priority is interpreted the right way in firmware. |
| 2626 | */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 2627 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
| 2628 | int j = mwl8k_tx_queues(priv) - 1 - i; |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 2629 | cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma); |
| 2630 | } |
| 2631 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2632 | cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT | |
| 2633 | MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP | |
Nishant Sarmukadam | 31d291a | 2011-04-21 16:34:59 +0530 | [diff] [blame] | 2634 | MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON | |
Nishant Sarmukadam | 3373b28 | 2011-06-13 16:26:15 +0530 | [diff] [blame] | 2635 | MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY | |
| 2636 | MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR); |
Lennert Buytenhek | 42fba21d | 2009-10-22 20:21:30 +0200 | [diff] [blame] | 2637 | cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS); |
| 2638 | cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS); |
| 2639 | |
| 2640 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2641 | kfree(cmd); |
| 2642 | |
| 2643 | return rc; |
| 2644 | } |
| 2645 | |
| 2646 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2647 | * CMD_MAC_MULTICAST_ADR. |
| 2648 | */ |
| 2649 | struct mwl8k_cmd_mac_multicast_adr { |
| 2650 | struct mwl8k_cmd_pkt header; |
| 2651 | __le16 action; |
| 2652 | __le16 numaddr; |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2653 | __u8 addr[0][ETH_ALEN]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2654 | }; |
| 2655 | |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2656 | #define MWL8K_ENABLE_RX_DIRECTED 0x0001 |
| 2657 | #define MWL8K_ENABLE_RX_MULTICAST 0x0002 |
| 2658 | #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004 |
| 2659 | #define MWL8K_ENABLE_RX_BROADCAST 0x0008 |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2660 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2661 | static struct mwl8k_cmd_pkt * |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 2662 | __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti, |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2663 | struct netdev_hw_addr_list *mc_list) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2664 | { |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2665 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2666 | struct mwl8k_cmd_mac_multicast_adr *cmd; |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2667 | int size; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2668 | int mc_count = 0; |
| 2669 | |
| 2670 | if (mc_list) |
| 2671 | mc_count = netdev_hw_addr_list_count(mc_list); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2672 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 2673 | if (allmulti || mc_count > priv->num_mcaddrs) { |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2674 | allmulti = 1; |
| 2675 | mc_count = 0; |
| 2676 | } |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2677 | |
| 2678 | size = sizeof(*cmd) + mc_count * ETH_ALEN; |
| 2679 | |
| 2680 | cmd = kzalloc(size, GFP_ATOMIC); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2681 | if (cmd == NULL) |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2682 | return NULL; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2683 | |
| 2684 | cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR); |
| 2685 | cmd->header.length = cpu_to_le16(size); |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2686 | cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED | |
| 2687 | MWL8K_ENABLE_RX_BROADCAST); |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 2688 | |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2689 | if (allmulti) { |
| 2690 | cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST); |
| 2691 | } else if (mc_count) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2692 | struct netdev_hw_addr *ha; |
| 2693 | int i = 0; |
Lennert Buytenhek | d5e3084 | 2009-10-22 20:19:41 +0200 | [diff] [blame] | 2694 | |
| 2695 | cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST); |
| 2696 | cmd->numaddr = cpu_to_le16(mc_count); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2697 | netdev_hw_addr_list_for_each(ha, mc_list) { |
| 2698 | memcpy(cmd->addr[i], ha->addr, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2699 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2700 | } |
| 2701 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 2702 | return &cmd->header; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2706 | * CMD_GET_STAT. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2707 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2708 | struct mwl8k_cmd_get_stat { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2709 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2710 | __le32 stats[64]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2711 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2712 | |
| 2713 | #define MWL8K_STAT_ACK_FAILURE 9 |
| 2714 | #define MWL8K_STAT_RTS_FAILURE 12 |
| 2715 | #define MWL8K_STAT_FCS_ERROR 24 |
| 2716 | #define MWL8K_STAT_RTS_SUCCESS 11 |
| 2717 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2718 | static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw, |
| 2719 | struct ieee80211_low_level_stats *stats) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2720 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2721 | struct mwl8k_cmd_get_stat *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2722 | int rc; |
| 2723 | |
| 2724 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2725 | if (cmd == NULL) |
| 2726 | return -ENOMEM; |
| 2727 | |
| 2728 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT); |
| 2729 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2730 | |
| 2731 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2732 | if (!rc) { |
| 2733 | stats->dot11ACKFailureCount = |
| 2734 | le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]); |
| 2735 | stats->dot11RTSFailureCount = |
| 2736 | le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]); |
| 2737 | stats->dot11FCSErrorCount = |
| 2738 | le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]); |
| 2739 | stats->dot11RTSSuccessCount = |
| 2740 | le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]); |
| 2741 | } |
| 2742 | kfree(cmd); |
| 2743 | |
| 2744 | return rc; |
| 2745 | } |
| 2746 | |
| 2747 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2748 | * CMD_RADIO_CONTROL. |
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_radio_control { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2751 | struct mwl8k_cmd_pkt header; |
| 2752 | __le16 action; |
| 2753 | __le16 control; |
| 2754 | __le16 radio_on; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2755 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2756 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2757 | static int |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2758 | mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2759 | { |
| 2760 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2761 | struct mwl8k_cmd_radio_control *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2762 | int rc; |
| 2763 | |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2764 | if (enable == priv->radio_on && !force) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2765 | return 0; |
| 2766 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2767 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2768 | if (cmd == NULL) |
| 2769 | return -ENOMEM; |
| 2770 | |
| 2771 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL); |
| 2772 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2773 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 2774 | cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2775 | cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000); |
| 2776 | |
| 2777 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2778 | kfree(cmd); |
| 2779 | |
| 2780 | if (!rc) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2781 | priv->radio_on = enable; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2782 | |
| 2783 | return rc; |
| 2784 | } |
| 2785 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2786 | static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2787 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2788 | return mwl8k_cmd_radio_control(hw, 0, 0); |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2789 | } |
| 2790 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2791 | static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw) |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2792 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2793 | return mwl8k_cmd_radio_control(hw, 1, 0); |
Lennert Buytenhek | c46563b | 2009-07-16 12:14:58 +0200 | [diff] [blame] | 2794 | } |
| 2795 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2796 | static int |
| 2797 | mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble) |
| 2798 | { |
Lennert Buytenhek | 99200a99 | 2009-11-30 18:31:40 +0100 | [diff] [blame] | 2799 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2800 | |
Lennert Buytenhek | 68ce388 | 2009-07-16 12:26:57 +0200 | [diff] [blame] | 2801 | priv->radio_short_preamble = short_preamble; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2802 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2803 | return mwl8k_cmd_radio_control(hw, 1, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2807 | * CMD_RF_TX_POWER. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2808 | */ |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2809 | #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2810 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2811 | struct mwl8k_cmd_rf_tx_power { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2812 | struct mwl8k_cmd_pkt header; |
| 2813 | __le16 action; |
| 2814 | __le16 support_level; |
| 2815 | __le16 current_level; |
| 2816 | __le16 reserved; |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2817 | __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2818 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2819 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2820 | 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] | 2821 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 2822 | struct mwl8k_cmd_rf_tx_power *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2823 | int rc; |
| 2824 | |
| 2825 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2826 | if (cmd == NULL) |
| 2827 | return -ENOMEM; |
| 2828 | |
| 2829 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER); |
| 2830 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2831 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 2832 | cmd->support_level = cpu_to_le16(dBm); |
| 2833 | |
| 2834 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2835 | kfree(cmd); |
| 2836 | |
| 2837 | return rc; |
| 2838 | } |
| 2839 | |
| 2840 | /* |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2841 | * CMD_TX_POWER. |
| 2842 | */ |
| 2843 | #define MWL8K_TX_POWER_LEVEL_TOTAL 12 |
| 2844 | |
| 2845 | struct mwl8k_cmd_tx_power { |
| 2846 | struct mwl8k_cmd_pkt header; |
| 2847 | __le16 action; |
| 2848 | __le16 band; |
| 2849 | __le16 channel; |
| 2850 | __le16 bw; |
| 2851 | __le16 sub_ch; |
| 2852 | __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL]; |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 2853 | } __packed; |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2854 | |
| 2855 | static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw, |
| 2856 | struct ieee80211_conf *conf, |
| 2857 | unsigned short pwr) |
| 2858 | { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 2859 | struct ieee80211_channel *channel = conf->chandef.chan; |
| 2860 | enum nl80211_channel_type channel_type = |
| 2861 | cfg80211_get_chandef_type(&conf->chandef); |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2862 | struct mwl8k_cmd_tx_power *cmd; |
| 2863 | int rc; |
| 2864 | int i; |
| 2865 | |
| 2866 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2867 | if (cmd == NULL) |
| 2868 | return -ENOMEM; |
| 2869 | |
| 2870 | cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER); |
| 2871 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2872 | cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST); |
| 2873 | |
| 2874 | if (channel->band == IEEE80211_BAND_2GHZ) |
| 2875 | cmd->band = cpu_to_le16(0x1); |
| 2876 | else if (channel->band == IEEE80211_BAND_5GHZ) |
| 2877 | cmd->band = cpu_to_le16(0x4); |
| 2878 | |
Yogesh Ashok Powar | 604c4ef | 2012-01-17 15:45:15 +0530 | [diff] [blame] | 2879 | cmd->channel = cpu_to_le16(channel->hw_value); |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2880 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 2881 | if (channel_type == NL80211_CHAN_NO_HT || |
| 2882 | channel_type == NL80211_CHAN_HT20) { |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2883 | cmd->bw = cpu_to_le16(0x2); |
| 2884 | } else { |
| 2885 | cmd->bw = cpu_to_le16(0x4); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 2886 | if (channel_type == NL80211_CHAN_HT40MINUS) |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2887 | cmd->sub_ch = cpu_to_le16(0x3); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 2888 | else if (channel_type == NL80211_CHAN_HT40PLUS) |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 2889 | cmd->sub_ch = cpu_to_le16(0x1); |
| 2890 | } |
| 2891 | |
| 2892 | for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++) |
| 2893 | cmd->power_level_list[i] = cpu_to_le16(pwr); |
| 2894 | |
| 2895 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2896 | kfree(cmd); |
| 2897 | |
| 2898 | return rc; |
| 2899 | } |
| 2900 | |
| 2901 | /* |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 2902 | * CMD_RF_ANTENNA. |
| 2903 | */ |
| 2904 | struct mwl8k_cmd_rf_antenna { |
| 2905 | struct mwl8k_cmd_pkt header; |
| 2906 | __le16 antenna; |
| 2907 | __le16 mode; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2908 | } __packed; |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 2909 | |
| 2910 | #define MWL8K_RF_ANTENNA_RX 1 |
| 2911 | #define MWL8K_RF_ANTENNA_TX 2 |
| 2912 | |
| 2913 | static int |
| 2914 | mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask) |
| 2915 | { |
| 2916 | struct mwl8k_cmd_rf_antenna *cmd; |
| 2917 | int rc; |
| 2918 | |
| 2919 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2920 | if (cmd == NULL) |
| 2921 | return -ENOMEM; |
| 2922 | |
| 2923 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA); |
| 2924 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2925 | cmd->antenna = cpu_to_le16(antenna); |
| 2926 | cmd->mode = cpu_to_le16(mask); |
| 2927 | |
| 2928 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2929 | kfree(cmd); |
| 2930 | |
| 2931 | return rc; |
| 2932 | } |
| 2933 | |
| 2934 | /* |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2935 | * CMD_SET_BEACON. |
| 2936 | */ |
| 2937 | struct mwl8k_cmd_set_beacon { |
| 2938 | struct mwl8k_cmd_pkt header; |
| 2939 | __le16 beacon_len; |
| 2940 | __u8 beacon[0]; |
| 2941 | }; |
| 2942 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 2943 | static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw, |
| 2944 | struct ieee80211_vif *vif, u8 *beacon, int len) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2945 | { |
| 2946 | struct mwl8k_cmd_set_beacon *cmd; |
| 2947 | int rc; |
| 2948 | |
| 2949 | cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL); |
| 2950 | if (cmd == NULL) |
| 2951 | return -ENOMEM; |
| 2952 | |
| 2953 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON); |
| 2954 | cmd->header.length = cpu_to_le16(sizeof(*cmd) + len); |
| 2955 | cmd->beacon_len = cpu_to_le16(len); |
| 2956 | memcpy(cmd->beacon, beacon, len); |
| 2957 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 2958 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 2959 | kfree(cmd); |
| 2960 | |
| 2961 | return rc; |
| 2962 | } |
| 2963 | |
| 2964 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2965 | * CMD_SET_PRE_SCAN. |
| 2966 | */ |
| 2967 | struct mwl8k_cmd_set_pre_scan { |
| 2968 | struct mwl8k_cmd_pkt header; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2969 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2970 | |
| 2971 | static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw) |
| 2972 | { |
| 2973 | struct mwl8k_cmd_set_pre_scan *cmd; |
| 2974 | int rc; |
| 2975 | |
| 2976 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2977 | if (cmd == NULL) |
| 2978 | return -ENOMEM; |
| 2979 | |
| 2980 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN); |
| 2981 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 2982 | |
| 2983 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 2984 | kfree(cmd); |
| 2985 | |
| 2986 | return rc; |
| 2987 | } |
| 2988 | |
| 2989 | /* |
| 2990 | * CMD_SET_POST_SCAN. |
| 2991 | */ |
| 2992 | struct mwl8k_cmd_set_post_scan { |
| 2993 | struct mwl8k_cmd_pkt header; |
| 2994 | __le32 isibss; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 2995 | __u8 bssid[ETH_ALEN]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 2996 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 2997 | |
| 2998 | static int |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 2999 | mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3000 | { |
| 3001 | struct mwl8k_cmd_set_post_scan *cmd; |
| 3002 | int rc; |
| 3003 | |
| 3004 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3005 | if (cmd == NULL) |
| 3006 | return -ENOMEM; |
| 3007 | |
| 3008 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN); |
| 3009 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3010 | cmd->isibss = 0; |
Lennert Buytenhek | d89173f | 2009-07-16 09:54:27 +0200 | [diff] [blame] | 3011 | memcpy(cmd->bssid, mac, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3012 | |
| 3013 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3014 | kfree(cmd); |
| 3015 | |
| 3016 | return rc; |
| 3017 | } |
| 3018 | |
| 3019 | /* |
| 3020 | * CMD_SET_RF_CHANNEL. |
| 3021 | */ |
| 3022 | struct mwl8k_cmd_set_rf_channel { |
| 3023 | struct mwl8k_cmd_pkt header; |
| 3024 | __le16 action; |
| 3025 | __u8 current_channel; |
| 3026 | __le32 channel_flags; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3027 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3028 | |
| 3029 | static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw, |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 3030 | struct ieee80211_conf *conf) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3031 | { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3032 | struct ieee80211_channel *channel = conf->chandef.chan; |
| 3033 | enum nl80211_channel_type channel_type = |
| 3034 | cfg80211_get_chandef_type(&conf->chandef); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3035 | struct mwl8k_cmd_set_rf_channel *cmd; |
| 3036 | int rc; |
| 3037 | |
| 3038 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3039 | if (cmd == NULL) |
| 3040 | return -ENOMEM; |
| 3041 | |
| 3042 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL); |
| 3043 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3044 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 3045 | cmd->current_channel = channel->hw_value; |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 3046 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3047 | if (channel->band == IEEE80211_BAND_2GHZ) |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 3048 | cmd->channel_flags |= cpu_to_le32(0x00000001); |
Lennert Buytenhek | 42574ea | 2010-01-12 13:49:18 +0100 | [diff] [blame] | 3049 | else if (channel->band == IEEE80211_BAND_5GHZ) |
| 3050 | cmd->channel_flags |= cpu_to_le32(0x00000004); |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 3051 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3052 | if (channel_type == NL80211_CHAN_NO_HT || |
| 3053 | channel_type == NL80211_CHAN_HT20) |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 3054 | cmd->channel_flags |= cpu_to_le32(0x00000080); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3055 | else if (channel_type == NL80211_CHAN_HT40MINUS) |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 3056 | cmd->channel_flags |= cpu_to_le32(0x000001900); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3057 | else if (channel_type == NL80211_CHAN_HT40PLUS) |
Lennert Buytenhek | 610677d | 2010-01-04 21:56:46 +0100 | [diff] [blame] | 3058 | cmd->channel_flags |= cpu_to_le32(0x000000900); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3059 | |
| 3060 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3061 | kfree(cmd); |
| 3062 | |
| 3063 | return rc; |
| 3064 | } |
| 3065 | |
| 3066 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3067 | * CMD_SET_AID. |
| 3068 | */ |
| 3069 | #define MWL8K_FRAME_PROT_DISABLED 0x00 |
| 3070 | #define MWL8K_FRAME_PROT_11G 0x07 |
| 3071 | #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02 |
| 3072 | #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06 |
| 3073 | |
| 3074 | struct mwl8k_cmd_update_set_aid { |
| 3075 | struct mwl8k_cmd_pkt header; |
| 3076 | __le16 aid; |
| 3077 | |
| 3078 | /* AP's MAC address (BSSID) */ |
| 3079 | __u8 bssid[ETH_ALEN]; |
| 3080 | __le16 protection_mode; |
| 3081 | __u8 supp_rates[14]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3082 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3083 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3084 | static void legacy_rate_mask_to_array(u8 *rates, u32 mask) |
| 3085 | { |
| 3086 | int i; |
| 3087 | int j; |
| 3088 | |
| 3089 | /* |
Jonas Gorski | 3f52455 | 2013-04-14 14:11:58 +0200 | [diff] [blame] | 3090 | * Clear nonstandard rate 4. |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3091 | */ |
| 3092 | mask &= 0x1fef; |
| 3093 | |
Jonas Gorski | 3f52455 | 2013-04-14 14:11:58 +0200 | [diff] [blame] | 3094 | for (i = 0, j = 0; i < 13; i++) { |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3095 | if (mask & (1 << i)) |
Lennert Buytenhek | 777ad37 | 2010-01-12 13:48:04 +0100 | [diff] [blame] | 3096 | rates[j++] = mwl8k_rates_24[i].hw_value; |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3100 | static int |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3101 | mwl8k_cmd_set_aid(struct ieee80211_hw *hw, |
| 3102 | struct ieee80211_vif *vif, u32 legacy_rate_mask) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3103 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3104 | struct mwl8k_cmd_update_set_aid *cmd; |
| 3105 | u16 prot_mode; |
| 3106 | int rc; |
| 3107 | |
| 3108 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3109 | if (cmd == NULL) |
| 3110 | return -ENOMEM; |
| 3111 | |
| 3112 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID); |
| 3113 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 3114 | cmd->aid = cpu_to_le16(vif->bss_conf.aid); |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 3115 | memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3116 | |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 3117 | if (vif->bss_conf.use_cts_prot) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3118 | prot_mode = MWL8K_FRAME_PROT_11G; |
| 3119 | } else { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 3120 | switch (vif->bss_conf.ht_operation_mode & |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3121 | IEEE80211_HT_OP_MODE_PROTECTION) { |
| 3122 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 3123 | prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY; |
| 3124 | break; |
| 3125 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 3126 | prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL; |
| 3127 | break; |
| 3128 | default: |
| 3129 | prot_mode = MWL8K_FRAME_PROT_DISABLED; |
| 3130 | break; |
| 3131 | } |
| 3132 | } |
| 3133 | cmd->protection_mode = cpu_to_le16(prot_mode); |
| 3134 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3135 | legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3136 | |
| 3137 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3138 | kfree(cmd); |
| 3139 | |
| 3140 | return rc; |
| 3141 | } |
| 3142 | |
| 3143 | /* |
| 3144 | * CMD_SET_RATE. |
| 3145 | */ |
| 3146 | struct mwl8k_cmd_set_rate { |
| 3147 | struct mwl8k_cmd_pkt header; |
| 3148 | __u8 legacy_rates[14]; |
| 3149 | |
| 3150 | /* Bitmap for supported MCS codes. */ |
| 3151 | __u8 mcs_set[16]; |
| 3152 | __u8 reserved[16]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3153 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3154 | |
| 3155 | static int |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3156 | mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 3157 | u32 legacy_rate_mask, u8 *mcs_rates) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3158 | { |
| 3159 | struct mwl8k_cmd_set_rate *cmd; |
| 3160 | int rc; |
| 3161 | |
| 3162 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3163 | if (cmd == NULL) |
| 3164 | return -ENOMEM; |
| 3165 | |
| 3166 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE); |
| 3167 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 3168 | legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 3169 | memcpy(cmd->mcs_set, mcs_rates, 16); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3170 | |
| 3171 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3172 | kfree(cmd); |
| 3173 | |
| 3174 | return rc; |
| 3175 | } |
| 3176 | |
| 3177 | /* |
| 3178 | * CMD_FINALIZE_JOIN. |
| 3179 | */ |
| 3180 | #define MWL8K_FJ_BEACON_MAXLEN 128 |
| 3181 | |
| 3182 | struct mwl8k_cmd_finalize_join { |
| 3183 | struct mwl8k_cmd_pkt header; |
| 3184 | __le32 sleep_interval; /* Number of beacon periods to sleep */ |
| 3185 | __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3186 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3187 | |
| 3188 | static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame, |
| 3189 | int framelen, int dtim) |
| 3190 | { |
| 3191 | struct mwl8k_cmd_finalize_join *cmd; |
| 3192 | struct ieee80211_mgmt *payload = frame; |
| 3193 | int payload_len; |
| 3194 | int rc; |
| 3195 | |
| 3196 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3197 | if (cmd == NULL) |
| 3198 | return -ENOMEM; |
| 3199 | |
| 3200 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN); |
| 3201 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3202 | cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1); |
| 3203 | |
| 3204 | payload_len = framelen - ieee80211_hdrlen(payload->frame_control); |
| 3205 | if (payload_len < 0) |
| 3206 | payload_len = 0; |
| 3207 | else if (payload_len > MWL8K_FJ_BEACON_MAXLEN) |
| 3208 | payload_len = MWL8K_FJ_BEACON_MAXLEN; |
| 3209 | |
| 3210 | memcpy(cmd->beacon_data, &payload->u.beacon, payload_len); |
| 3211 | |
| 3212 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3213 | kfree(cmd); |
| 3214 | |
| 3215 | return rc; |
| 3216 | } |
| 3217 | |
| 3218 | /* |
| 3219 | * CMD_SET_RTS_THRESHOLD. |
| 3220 | */ |
| 3221 | struct mwl8k_cmd_set_rts_threshold { |
| 3222 | struct mwl8k_cmd_pkt header; |
| 3223 | __le16 action; |
| 3224 | __le16 threshold; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3225 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3226 | |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 3227 | static int |
| 3228 | mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3229 | { |
| 3230 | struct mwl8k_cmd_set_rts_threshold *cmd; |
| 3231 | int rc; |
| 3232 | |
| 3233 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3234 | if (cmd == NULL) |
| 3235 | return -ENOMEM; |
| 3236 | |
| 3237 | cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD); |
| 3238 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 3239 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 3240 | cmd->threshold = cpu_to_le16(rts_thresh); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3241 | |
| 3242 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3243 | kfree(cmd); |
| 3244 | |
| 3245 | return rc; |
| 3246 | } |
| 3247 | |
| 3248 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3249 | * CMD_SET_SLOT. |
| 3250 | */ |
| 3251 | struct mwl8k_cmd_set_slot { |
| 3252 | struct mwl8k_cmd_pkt header; |
| 3253 | __le16 action; |
| 3254 | __u8 short_slot; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3255 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3256 | |
Lennert Buytenhek | 5539bb5 | 2009-07-16 16:06:53 +0200 | [diff] [blame] | 3257 | 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] | 3258 | { |
| 3259 | struct mwl8k_cmd_set_slot *cmd; |
| 3260 | int rc; |
| 3261 | |
| 3262 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3263 | if (cmd == NULL) |
| 3264 | return -ENOMEM; |
| 3265 | |
| 3266 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT); |
| 3267 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3268 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
Lennert Buytenhek | 5539bb5 | 2009-07-16 16:06:53 +0200 | [diff] [blame] | 3269 | cmd->short_slot = short_slot_time; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3270 | |
| 3271 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3272 | kfree(cmd); |
| 3273 | |
| 3274 | return rc; |
| 3275 | } |
| 3276 | |
| 3277 | /* |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3278 | * CMD_SET_EDCA_PARAMS. |
| 3279 | */ |
| 3280 | struct mwl8k_cmd_set_edca_params { |
| 3281 | struct mwl8k_cmd_pkt header; |
| 3282 | |
| 3283 | /* See MWL8K_SET_EDCA_XXX below */ |
| 3284 | __le16 action; |
| 3285 | |
| 3286 | /* TX opportunity in units of 32 us */ |
| 3287 | __le16 txop; |
| 3288 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3289 | union { |
| 3290 | struct { |
| 3291 | /* Log exponent of max contention period: 0...15 */ |
| 3292 | __le32 log_cw_max; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3293 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3294 | /* Log exponent of min contention period: 0...15 */ |
| 3295 | __le32 log_cw_min; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3296 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3297 | /* Adaptive interframe spacing in units of 32us */ |
| 3298 | __u8 aifs; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3299 | |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3300 | /* TX queue to configure */ |
| 3301 | __u8 txq; |
| 3302 | } ap; |
| 3303 | struct { |
| 3304 | /* Log exponent of max contention period: 0...15 */ |
| 3305 | __u8 log_cw_max; |
| 3306 | |
| 3307 | /* Log exponent of min contention period: 0...15 */ |
| 3308 | __u8 log_cw_min; |
| 3309 | |
| 3310 | /* Adaptive interframe spacing in units of 32us */ |
| 3311 | __u8 aifs; |
| 3312 | |
| 3313 | /* TX queue to configure */ |
| 3314 | __u8 txq; |
| 3315 | } sta; |
| 3316 | }; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3317 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3318 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3319 | #define MWL8K_SET_EDCA_CW 0x01 |
| 3320 | #define MWL8K_SET_EDCA_TXOP 0x02 |
| 3321 | #define MWL8K_SET_EDCA_AIFS 0x04 |
| 3322 | |
| 3323 | #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \ |
| 3324 | MWL8K_SET_EDCA_TXOP | \ |
| 3325 | MWL8K_SET_EDCA_AIFS) |
| 3326 | |
| 3327 | static int |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3328 | mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum, |
| 3329 | __u16 cw_min, __u16 cw_max, |
| 3330 | __u8 aifs, __u16 txop) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3331 | { |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3332 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3333 | struct mwl8k_cmd_set_edca_params *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3334 | int rc; |
| 3335 | |
| 3336 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3337 | if (cmd == NULL) |
| 3338 | return -ENOMEM; |
| 3339 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3340 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS); |
| 3341 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3342 | cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL); |
| 3343 | cmd->txop = cpu_to_le16(txop); |
Lennert Buytenhek | 2e484c8 | 2009-10-22 20:21:43 +0200 | [diff] [blame] | 3344 | if (priv->ap_fw) { |
| 3345 | cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1)); |
| 3346 | cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1)); |
| 3347 | cmd->ap.aifs = aifs; |
| 3348 | cmd->ap.txq = qnum; |
| 3349 | } else { |
| 3350 | cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1); |
| 3351 | cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1); |
| 3352 | cmd->sta.aifs = aifs; |
| 3353 | cmd->sta.txq = qnum; |
| 3354 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3355 | |
| 3356 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3357 | kfree(cmd); |
| 3358 | |
| 3359 | return rc; |
| 3360 | } |
| 3361 | |
| 3362 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3363 | * CMD_SET_WMM_MODE. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3364 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3365 | struct mwl8k_cmd_set_wmm_mode { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3366 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3367 | __le16 action; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3368 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3369 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3370 | 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] | 3371 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3372 | struct mwl8k_priv *priv = hw->priv; |
| 3373 | struct mwl8k_cmd_set_wmm_mode *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3374 | int rc; |
| 3375 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3376 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3377 | if (cmd == NULL) |
| 3378 | return -ENOMEM; |
| 3379 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3380 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3381 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3382 | cmd->action = cpu_to_le16(!!enable); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3383 | |
| 3384 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3385 | kfree(cmd); |
Lennert Buytenhek | 16cec43 | 2009-11-30 18:14:23 +0100 | [diff] [blame] | 3386 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3387 | if (!rc) |
| 3388 | priv->wmm_enabled = enable; |
| 3389 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3390 | return rc; |
| 3391 | } |
| 3392 | |
| 3393 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3394 | * CMD_MIMO_CONFIG. |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3395 | */ |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3396 | struct mwl8k_cmd_mimo_config { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3397 | struct mwl8k_cmd_pkt header; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3398 | __le32 action; |
| 3399 | __u8 rx_antenna_map; |
| 3400 | __u8 tx_antenna_map; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3401 | } __packed; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3402 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3403 | 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] | 3404 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3405 | struct mwl8k_cmd_mimo_config *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3406 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3407 | |
| 3408 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3409 | if (cmd == NULL) |
| 3410 | return -ENOMEM; |
| 3411 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3412 | cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3413 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3414 | cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET); |
| 3415 | cmd->rx_antenna_map = rx; |
| 3416 | cmd->tx_antenna_map = tx; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3417 | |
| 3418 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3419 | kfree(cmd); |
| 3420 | |
| 3421 | return rc; |
| 3422 | } |
| 3423 | |
| 3424 | /* |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3425 | * CMD_USE_FIXED_RATE (STA version). |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3426 | */ |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3427 | struct mwl8k_cmd_use_fixed_rate_sta { |
| 3428 | struct mwl8k_cmd_pkt header; |
| 3429 | __le32 action; |
| 3430 | __le32 allow_rate_drop; |
| 3431 | __le32 num_rates; |
| 3432 | struct { |
| 3433 | __le32 is_ht_rate; |
| 3434 | __le32 enable_retry; |
| 3435 | __le32 rate; |
| 3436 | __le32 retry_count; |
| 3437 | } rate_entry[8]; |
| 3438 | __le32 rate_type; |
| 3439 | __le32 reserved1; |
| 3440 | __le32 reserved2; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3441 | } __packed; |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3442 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3443 | #define MWL8K_USE_AUTO_RATE 0x0002 |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3444 | #define MWL8K_UCAST_RATE 0 |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3445 | |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3446 | static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3447 | { |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3448 | struct mwl8k_cmd_use_fixed_rate_sta *cmd; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3449 | int rc; |
| 3450 | |
| 3451 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3452 | if (cmd == NULL) |
| 3453 | return -ENOMEM; |
| 3454 | |
| 3455 | cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE); |
| 3456 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 3457 | cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE); |
| 3458 | cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 3459 | |
| 3460 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3461 | kfree(cmd); |
| 3462 | |
| 3463 | return rc; |
| 3464 | } |
| 3465 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3466 | /* |
Lennert Buytenhek | 088aab8 | 2010-01-08 18:30:36 +0100 | [diff] [blame] | 3467 | * CMD_USE_FIXED_RATE (AP version). |
| 3468 | */ |
| 3469 | struct mwl8k_cmd_use_fixed_rate_ap { |
| 3470 | struct mwl8k_cmd_pkt header; |
| 3471 | __le32 action; |
| 3472 | __le32 allow_rate_drop; |
| 3473 | __le32 num_rates; |
| 3474 | struct mwl8k_rate_entry_ap { |
| 3475 | __le32 is_ht_rate; |
| 3476 | __le32 enable_retry; |
| 3477 | __le32 rate; |
| 3478 | __le32 retry_count; |
| 3479 | } rate_entry[4]; |
| 3480 | u8 multicast_rate; |
| 3481 | u8 multicast_rate_type; |
| 3482 | u8 management_rate; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3483 | } __packed; |
Lennert Buytenhek | 088aab8 | 2010-01-08 18:30:36 +0100 | [diff] [blame] | 3484 | |
| 3485 | static int |
| 3486 | mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt) |
| 3487 | { |
| 3488 | struct mwl8k_cmd_use_fixed_rate_ap *cmd; |
| 3489 | int rc; |
| 3490 | |
| 3491 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3492 | if (cmd == NULL) |
| 3493 | return -ENOMEM; |
| 3494 | |
| 3495 | cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE); |
| 3496 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3497 | cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE); |
| 3498 | cmd->multicast_rate = mcast; |
| 3499 | cmd->management_rate = mgmt; |
| 3500 | |
| 3501 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3502 | kfree(cmd); |
| 3503 | |
| 3504 | return rc; |
| 3505 | } |
| 3506 | |
| 3507 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3508 | * CMD_ENABLE_SNIFFER. |
| 3509 | */ |
| 3510 | struct mwl8k_cmd_enable_sniffer { |
| 3511 | struct mwl8k_cmd_pkt header; |
| 3512 | __le32 action; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3513 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3514 | |
| 3515 | static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable) |
| 3516 | { |
| 3517 | struct mwl8k_cmd_enable_sniffer *cmd; |
| 3518 | int rc; |
| 3519 | |
| 3520 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3521 | if (cmd == NULL) |
| 3522 | return -ENOMEM; |
| 3523 | |
| 3524 | cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER); |
| 3525 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3526 | cmd->action = cpu_to_le32(!!enable); |
| 3527 | |
| 3528 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3529 | kfree(cmd); |
| 3530 | |
| 3531 | return rc; |
| 3532 | } |
| 3533 | |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3534 | struct mwl8k_cmd_update_mac_addr { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3535 | struct mwl8k_cmd_pkt header; |
| 3536 | union { |
| 3537 | struct { |
| 3538 | __le16 mac_type; |
| 3539 | __u8 mac_addr[ETH_ALEN]; |
| 3540 | } mbss; |
| 3541 | __u8 mac_addr[ETH_ALEN]; |
| 3542 | }; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3543 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3544 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3545 | #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0 |
| 3546 | #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1 |
| 3547 | #define MWL8K_MAC_TYPE_PRIMARY_AP 2 |
| 3548 | #define MWL8K_MAC_TYPE_SECONDARY_AP 3 |
Lennert Buytenhek | a9e00b1 | 2010-01-08 18:31:30 +0100 | [diff] [blame] | 3549 | |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3550 | static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw, |
| 3551 | struct ieee80211_vif *vif, u8 *mac, bool set) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3552 | { |
| 3553 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3554 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3555 | struct mwl8k_cmd_update_mac_addr *cmd; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3556 | int mac_type; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3557 | int rc; |
| 3558 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3559 | mac_type = MWL8K_MAC_TYPE_PRIMARY_AP; |
| 3560 | if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) { |
| 3561 | if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported)) |
Yogesh Ashok Powar | af45883 | 2013-01-25 16:20:12 +0530 | [diff] [blame] | 3562 | if (priv->ap_fw) |
| 3563 | mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT; |
| 3564 | else |
| 3565 | mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3566 | else |
| 3567 | mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT; |
| 3568 | } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) { |
| 3569 | if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported)) |
| 3570 | mac_type = MWL8K_MAC_TYPE_PRIMARY_AP; |
| 3571 | else |
| 3572 | mac_type = MWL8K_MAC_TYPE_SECONDARY_AP; |
| 3573 | } |
| 3574 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3575 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3576 | if (cmd == NULL) |
| 3577 | return -ENOMEM; |
| 3578 | |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3579 | if (set) |
| 3580 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR); |
| 3581 | else |
| 3582 | cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR); |
| 3583 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3584 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3585 | if (priv->ap_fw) { |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 3586 | cmd->mbss.mac_type = cpu_to_le16(mac_type); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3587 | memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN); |
| 3588 | } else { |
| 3589 | memcpy(cmd->mac_addr, mac, ETH_ALEN); |
| 3590 | } |
| 3591 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3592 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3593 | kfree(cmd); |
| 3594 | |
| 3595 | return rc; |
| 3596 | } |
| 3597 | |
| 3598 | /* |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 3599 | * MWL8K_CMD_SET_MAC_ADDR. |
| 3600 | */ |
| 3601 | static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw, |
| 3602 | struct ieee80211_vif *vif, u8 *mac) |
| 3603 | { |
| 3604 | return mwl8k_cmd_update_mac_addr(hw, vif, mac, true); |
| 3605 | } |
| 3606 | |
| 3607 | /* |
| 3608 | * MWL8K_CMD_DEL_MAC_ADDR. |
| 3609 | */ |
| 3610 | static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw, |
| 3611 | struct ieee80211_vif *vif, u8 *mac) |
| 3612 | { |
| 3613 | return mwl8k_cmd_update_mac_addr(hw, vif, mac, false); |
| 3614 | } |
| 3615 | |
| 3616 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3617 | * CMD_SET_RATEADAPT_MODE. |
| 3618 | */ |
| 3619 | struct mwl8k_cmd_set_rate_adapt_mode { |
| 3620 | struct mwl8k_cmd_pkt header; |
| 3621 | __le16 action; |
| 3622 | __le16 mode; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3623 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 3624 | |
| 3625 | static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode) |
| 3626 | { |
| 3627 | struct mwl8k_cmd_set_rate_adapt_mode *cmd; |
| 3628 | int rc; |
| 3629 | |
| 3630 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3631 | if (cmd == NULL) |
| 3632 | return -ENOMEM; |
| 3633 | |
| 3634 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE); |
| 3635 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3636 | cmd->action = cpu_to_le16(MWL8K_CMD_SET); |
| 3637 | cmd->mode = cpu_to_le16(mode); |
| 3638 | |
| 3639 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3640 | kfree(cmd); |
| 3641 | |
| 3642 | return rc; |
| 3643 | } |
| 3644 | |
| 3645 | /* |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3646 | * CMD_GET_WATCHDOG_BITMAP. |
| 3647 | */ |
| 3648 | struct mwl8k_cmd_get_watchdog_bitmap { |
| 3649 | struct mwl8k_cmd_pkt header; |
| 3650 | u8 bitmap; |
| 3651 | } __packed; |
| 3652 | |
| 3653 | static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap) |
| 3654 | { |
| 3655 | struct mwl8k_cmd_get_watchdog_bitmap *cmd; |
| 3656 | int rc; |
| 3657 | |
| 3658 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3659 | if (cmd == NULL) |
| 3660 | return -ENOMEM; |
| 3661 | |
| 3662 | cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP); |
| 3663 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3664 | |
| 3665 | rc = mwl8k_post_cmd(hw, &cmd->header); |
| 3666 | if (!rc) |
| 3667 | *bitmap = cmd->bitmap; |
| 3668 | |
| 3669 | kfree(cmd); |
| 3670 | |
| 3671 | return rc; |
| 3672 | } |
| 3673 | |
Yogesh Ashok Powar | cfacba1 | 2013-01-03 13:24:03 +0530 | [diff] [blame] | 3674 | #define MWL8K_WMM_QUEUE_NUMBER 3 |
| 3675 | |
| 3676 | static void mwl8k_destroy_ba(struct ieee80211_hw *hw, |
| 3677 | u8 idx); |
| 3678 | |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3679 | static void mwl8k_watchdog_ba_events(struct work_struct *work) |
| 3680 | { |
| 3681 | int rc; |
| 3682 | u8 bitmap = 0, stream_index; |
| 3683 | struct mwl8k_ampdu_stream *streams; |
| 3684 | struct mwl8k_priv *priv = |
| 3685 | container_of(work, struct mwl8k_priv, watchdog_ba_handle); |
Yogesh Ashok Powar | cfacba1 | 2013-01-03 13:24:03 +0530 | [diff] [blame] | 3686 | struct ieee80211_hw *hw = priv->hw; |
| 3687 | int i; |
| 3688 | u32 status = 0; |
| 3689 | |
| 3690 | mwl8k_fw_lock(hw); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3691 | |
| 3692 | rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap); |
| 3693 | if (rc) |
Yogesh Ashok Powar | cfacba1 | 2013-01-03 13:24:03 +0530 | [diff] [blame] | 3694 | goto done; |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3695 | |
Yogesh Ashok Powar | cfacba1 | 2013-01-03 13:24:03 +0530 | [diff] [blame] | 3696 | spin_lock(&priv->stream_lock); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3697 | |
| 3698 | /* the bitmap is the hw queue number. Map it to the ampdu queue. */ |
Yogesh Ashok Powar | cfacba1 | 2013-01-03 13:24:03 +0530 | [diff] [blame] | 3699 | for (i = 0; i < TOTAL_HW_TX_QUEUES; i++) { |
| 3700 | if (bitmap & (1 << i)) { |
| 3701 | stream_index = (i + MWL8K_WMM_QUEUE_NUMBER) % |
| 3702 | TOTAL_HW_TX_QUEUES; |
| 3703 | streams = &priv->ampdu[stream_index]; |
| 3704 | if (streams->state == AMPDU_STREAM_ACTIVE) { |
| 3705 | ieee80211_stop_tx_ba_session(streams->sta, |
| 3706 | streams->tid); |
| 3707 | spin_unlock(&priv->stream_lock); |
| 3708 | mwl8k_destroy_ba(hw, stream_index); |
| 3709 | spin_lock(&priv->stream_lock); |
| 3710 | } |
| 3711 | } |
| 3712 | } |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3713 | |
Yogesh Ashok Powar | cfacba1 | 2013-01-03 13:24:03 +0530 | [diff] [blame] | 3714 | spin_unlock(&priv->stream_lock); |
| 3715 | done: |
Yogesh Ashok Powar | c27a54d | 2013-01-03 13:24:19 +0530 | [diff] [blame] | 3716 | atomic_dec(&priv->watchdog_event_pending); |
Yogesh Ashok Powar | cfacba1 | 2013-01-03 13:24:03 +0530 | [diff] [blame] | 3717 | status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
| 3718 | iowrite32((status | MWL8K_A2H_INT_BA_WATCHDOG), |
| 3719 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
| 3720 | mwl8k_fw_unlock(hw); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 3721 | return; |
| 3722 | } |
| 3723 | |
| 3724 | |
| 3725 | /* |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3726 | * CMD_BSS_START. |
| 3727 | */ |
| 3728 | struct mwl8k_cmd_bss_start { |
| 3729 | struct mwl8k_cmd_pkt header; |
| 3730 | __le32 enable; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3731 | } __packed; |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3732 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3733 | static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw, |
| 3734 | struct ieee80211_vif *vif, int enable) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3735 | { |
| 3736 | struct mwl8k_cmd_bss_start *cmd; |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 3737 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 3738 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3739 | int rc; |
| 3740 | |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 3741 | if (enable && (priv->running_bsses & (1 << mwl8k_vif->macid))) |
| 3742 | return 0; |
| 3743 | |
| 3744 | if (!enable && !(priv->running_bsses & (1 << mwl8k_vif->macid))) |
| 3745 | return 0; |
| 3746 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3747 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3748 | if (cmd == NULL) |
| 3749 | return -ENOMEM; |
| 3750 | |
| 3751 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START); |
| 3752 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3753 | cmd->enable = cpu_to_le32(enable); |
| 3754 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3755 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3756 | kfree(cmd); |
| 3757 | |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 3758 | if (!rc) { |
| 3759 | if (enable) |
| 3760 | priv->running_bsses |= (1 << mwl8k_vif->macid); |
| 3761 | else |
| 3762 | priv->running_bsses &= ~(1 << mwl8k_vif->macid); |
| 3763 | } |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3764 | return rc; |
| 3765 | } |
| 3766 | |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 3767 | static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable, u32 bitmap) |
| 3768 | { |
| 3769 | struct mwl8k_priv *priv = hw->priv; |
| 3770 | struct mwl8k_vif *mwl8k_vif, *tmp_vif; |
| 3771 | struct ieee80211_vif *vif; |
| 3772 | |
| 3773 | list_for_each_entry_safe(mwl8k_vif, tmp_vif, &priv->vif_list, list) { |
| 3774 | vif = mwl8k_vif->vif; |
| 3775 | |
| 3776 | if (!(bitmap & (1 << mwl8k_vif->macid))) |
| 3777 | continue; |
| 3778 | |
| 3779 | if (vif->type == NL80211_IFTYPE_AP) |
| 3780 | mwl8k_cmd_bss_start(hw, vif, enable); |
| 3781 | } |
| 3782 | } |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3783 | /* |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3784 | * CMD_BASTREAM. |
| 3785 | */ |
| 3786 | |
| 3787 | /* |
| 3788 | * UPSTREAM is tx direction |
| 3789 | */ |
| 3790 | #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00 |
| 3791 | #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01 |
| 3792 | |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 3793 | enum ba_stream_action_type { |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3794 | MWL8K_BA_CREATE, |
| 3795 | MWL8K_BA_UPDATE, |
| 3796 | MWL8K_BA_DESTROY, |
| 3797 | MWL8K_BA_FLUSH, |
| 3798 | MWL8K_BA_CHECK, |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 3799 | }; |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3800 | |
| 3801 | |
| 3802 | struct mwl8k_create_ba_stream { |
| 3803 | __le32 flags; |
| 3804 | __le32 idle_thrs; |
| 3805 | __le32 bar_thrs; |
| 3806 | __le32 window_size; |
| 3807 | u8 peer_mac_addr[6]; |
| 3808 | u8 dialog_token; |
| 3809 | u8 tid; |
| 3810 | u8 queue_id; |
| 3811 | u8 param_info; |
| 3812 | __le32 ba_context; |
| 3813 | u8 reset_seq_no_flag; |
| 3814 | __le16 curr_seq_no; |
| 3815 | u8 sta_src_mac_addr[6]; |
| 3816 | } __packed; |
| 3817 | |
| 3818 | struct mwl8k_destroy_ba_stream { |
| 3819 | __le32 flags; |
| 3820 | __le32 ba_context; |
| 3821 | } __packed; |
| 3822 | |
| 3823 | struct mwl8k_cmd_bastream { |
| 3824 | struct mwl8k_cmd_pkt header; |
| 3825 | __le32 action; |
| 3826 | union { |
| 3827 | struct mwl8k_create_ba_stream create_params; |
| 3828 | struct mwl8k_destroy_ba_stream destroy_params; |
| 3829 | }; |
| 3830 | } __packed; |
| 3831 | |
| 3832 | static int |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 3833 | mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream, |
| 3834 | struct ieee80211_vif *vif) |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3835 | { |
| 3836 | struct mwl8k_cmd_bastream *cmd; |
| 3837 | int rc; |
| 3838 | |
| 3839 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3840 | if (cmd == NULL) |
| 3841 | return -ENOMEM; |
| 3842 | |
| 3843 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3844 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3845 | |
| 3846 | cmd->action = cpu_to_le32(MWL8K_BA_CHECK); |
| 3847 | |
| 3848 | cmd->create_params.queue_id = stream->idx; |
| 3849 | memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr, |
| 3850 | ETH_ALEN); |
| 3851 | cmd->create_params.tid = stream->tid; |
| 3852 | |
| 3853 | cmd->create_params.flags = |
| 3854 | cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) | |
| 3855 | cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM); |
| 3856 | |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 3857 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3858 | |
| 3859 | kfree(cmd); |
| 3860 | |
| 3861 | return rc; |
| 3862 | } |
| 3863 | |
| 3864 | static int |
| 3865 | 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] | 3866 | u8 buf_size, struct ieee80211_vif *vif) |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3867 | { |
| 3868 | struct mwl8k_cmd_bastream *cmd; |
| 3869 | int rc; |
| 3870 | |
| 3871 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3872 | if (cmd == NULL) |
| 3873 | return -ENOMEM; |
| 3874 | |
| 3875 | |
| 3876 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3877 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3878 | |
| 3879 | cmd->action = cpu_to_le32(MWL8K_BA_CREATE); |
| 3880 | |
| 3881 | cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size); |
| 3882 | cmd->create_params.window_size = cpu_to_le32((u32)buf_size); |
| 3883 | cmd->create_params.queue_id = stream->idx; |
| 3884 | |
| 3885 | memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN); |
| 3886 | cmd->create_params.tid = stream->tid; |
| 3887 | cmd->create_params.curr_seq_no = cpu_to_le16(0); |
| 3888 | cmd->create_params.reset_seq_no_flag = 1; |
| 3889 | |
| 3890 | cmd->create_params.param_info = |
| 3891 | (stream->sta->ht_cap.ampdu_factor & |
| 3892 | IEEE80211_HT_AMPDU_PARM_FACTOR) | |
| 3893 | ((stream->sta->ht_cap.ampdu_density << 2) & |
| 3894 | IEEE80211_HT_AMPDU_PARM_DENSITY); |
| 3895 | |
| 3896 | cmd->create_params.flags = |
| 3897 | cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE | |
| 3898 | BASTREAM_FLAG_DIRECTION_UPSTREAM); |
| 3899 | |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 3900 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3901 | |
| 3902 | wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n", |
| 3903 | stream->sta->addr, stream->tid); |
| 3904 | kfree(cmd); |
| 3905 | |
| 3906 | return rc; |
| 3907 | } |
| 3908 | |
| 3909 | static void mwl8k_destroy_ba(struct ieee80211_hw *hw, |
Yogesh Ashok Powar | 07f6dda | 2013-01-03 13:23:33 +0530 | [diff] [blame] | 3910 | u8 idx) |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3911 | { |
| 3912 | struct mwl8k_cmd_bastream *cmd; |
| 3913 | |
| 3914 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3915 | if (cmd == NULL) |
| 3916 | return; |
| 3917 | |
| 3918 | cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM); |
| 3919 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3920 | cmd->action = cpu_to_le32(MWL8K_BA_DESTROY); |
| 3921 | |
Yogesh Ashok Powar | 07f6dda | 2013-01-03 13:23:33 +0530 | [diff] [blame] | 3922 | cmd->destroy_params.ba_context = cpu_to_le32(idx); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3923 | mwl8k_post_cmd(hw, &cmd->header); |
| 3924 | |
Yogesh Ashok Powar | 07f6dda | 2013-01-03 13:23:33 +0530 | [diff] [blame] | 3925 | wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", idx); |
Nishant Sarmukadam | 5faa1af | 2011-03-17 11:58:43 -0700 | [diff] [blame] | 3926 | |
| 3927 | kfree(cmd); |
| 3928 | } |
| 3929 | |
| 3930 | /* |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3931 | * CMD_SET_NEW_STN. |
| 3932 | */ |
| 3933 | struct mwl8k_cmd_set_new_stn { |
| 3934 | struct mwl8k_cmd_pkt header; |
| 3935 | __le16 aid; |
| 3936 | __u8 mac_addr[6]; |
| 3937 | __le16 stn_id; |
| 3938 | __le16 action; |
| 3939 | __le16 rsvd; |
| 3940 | __le32 legacy_rates; |
| 3941 | __u8 ht_rates[4]; |
| 3942 | __le16 cap_info; |
| 3943 | __le16 ht_capabilities_info; |
| 3944 | __u8 mac_ht_param_info; |
| 3945 | __u8 rev; |
| 3946 | __u8 control_channel; |
| 3947 | __u8 add_channel; |
| 3948 | __le16 op_mode; |
| 3949 | __le16 stbc; |
| 3950 | __u8 add_qos_info; |
| 3951 | __u8 is_qos_sta; |
| 3952 | __le32 fw_sta_ptr; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 3953 | } __packed; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3954 | |
| 3955 | #define MWL8K_STA_ACTION_ADD 0 |
| 3956 | #define MWL8K_STA_ACTION_REMOVE 2 |
| 3957 | |
| 3958 | static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw, |
| 3959 | struct ieee80211_vif *vif, |
| 3960 | struct ieee80211_sta *sta) |
| 3961 | { |
| 3962 | struct mwl8k_cmd_set_new_stn *cmd; |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 3963 | u32 rates; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3964 | int rc; |
| 3965 | |
| 3966 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 3967 | if (cmd == NULL) |
| 3968 | return -ENOMEM; |
| 3969 | |
| 3970 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 3971 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 3972 | cmd->aid = cpu_to_le16(sta->aid); |
| 3973 | memcpy(cmd->mac_addr, sta->addr, ETH_ALEN); |
| 3974 | cmd->stn_id = cpu_to_le16(sta->aid); |
| 3975 | cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3976 | if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 3977 | rates = sta->supp_rates[IEEE80211_BAND_2GHZ]; |
| 3978 | else |
| 3979 | rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 3980 | cmd->legacy_rates = cpu_to_le32(rates); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3981 | if (sta->ht_cap.ht_supported) { |
| 3982 | cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0]; |
| 3983 | cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1]; |
| 3984 | cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2]; |
| 3985 | cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3]; |
| 3986 | cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap); |
| 3987 | cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) | |
| 3988 | ((sta->ht_cap.ampdu_density & 7) << 2); |
| 3989 | cmd->is_qos_sta = 1; |
| 3990 | } |
| 3991 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 3992 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 3993 | kfree(cmd); |
| 3994 | |
| 3995 | return rc; |
| 3996 | } |
| 3997 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 3998 | static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw, |
| 3999 | struct ieee80211_vif *vif) |
| 4000 | { |
| 4001 | struct mwl8k_cmd_set_new_stn *cmd; |
| 4002 | int rc; |
| 4003 | |
| 4004 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4005 | if (cmd == NULL) |
| 4006 | return -ENOMEM; |
| 4007 | |
| 4008 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 4009 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 4010 | memcpy(cmd->mac_addr, vif->addr, ETH_ALEN); |
| 4011 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4012 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4013 | kfree(cmd); |
| 4014 | |
| 4015 | return rc; |
| 4016 | } |
| 4017 | |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4018 | static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw, |
| 4019 | struct ieee80211_vif *vif, u8 *addr) |
| 4020 | { |
| 4021 | struct mwl8k_cmd_set_new_stn *cmd; |
Yogesh Ashok Powar | 0dd13a4 | 2013-01-08 10:16:37 +0530 | [diff] [blame] | 4022 | struct mwl8k_priv *priv = hw->priv; |
| 4023 | int rc, i; |
| 4024 | u8 idx; |
| 4025 | |
| 4026 | spin_lock(&priv->stream_lock); |
| 4027 | /* Destroy any active ampdu streams for this sta */ |
| 4028 | for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) { |
| 4029 | struct mwl8k_ampdu_stream *s; |
| 4030 | s = &priv->ampdu[i]; |
| 4031 | if (s->state != AMPDU_NO_STREAM) { |
| 4032 | if (memcmp(s->sta->addr, addr, ETH_ALEN) == 0) { |
| 4033 | if (s->state == AMPDU_STREAM_ACTIVE) { |
| 4034 | idx = s->idx; |
| 4035 | spin_unlock(&priv->stream_lock); |
| 4036 | mwl8k_destroy_ba(hw, idx); |
| 4037 | spin_lock(&priv->stream_lock); |
| 4038 | } else if (s->state == AMPDU_STREAM_NEW) { |
| 4039 | mwl8k_remove_stream(hw, s); |
| 4040 | } |
| 4041 | } |
| 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | spin_unlock(&priv->stream_lock); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4046 | |
| 4047 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4048 | if (cmd == NULL) |
| 4049 | return -ENOMEM; |
| 4050 | |
| 4051 | cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN); |
| 4052 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 4053 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 4054 | cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE); |
| 4055 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4056 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 4057 | kfree(cmd); |
| 4058 | |
| 4059 | return rc; |
| 4060 | } |
| 4061 | |
| 4062 | /* |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4063 | * CMD_UPDATE_ENCRYPTION. |
| 4064 | */ |
| 4065 | |
| 4066 | #define MAX_ENCR_KEY_LENGTH 16 |
| 4067 | #define MIC_KEY_LENGTH 8 |
| 4068 | |
| 4069 | struct mwl8k_cmd_update_encryption { |
| 4070 | struct mwl8k_cmd_pkt header; |
| 4071 | |
| 4072 | __le32 action; |
| 4073 | __le32 reserved; |
| 4074 | __u8 mac_addr[6]; |
| 4075 | __u8 encr_type; |
| 4076 | |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 4077 | } __packed; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4078 | |
| 4079 | struct mwl8k_cmd_set_key { |
| 4080 | struct mwl8k_cmd_pkt header; |
| 4081 | |
| 4082 | __le32 action; |
| 4083 | __le32 reserved; |
| 4084 | __le16 length; |
| 4085 | __le16 key_type_id; |
| 4086 | __le32 key_info; |
| 4087 | __le32 key_id; |
| 4088 | __le16 key_len; |
| 4089 | __u8 key_material[MAX_ENCR_KEY_LENGTH]; |
| 4090 | __u8 tkip_tx_mic_key[MIC_KEY_LENGTH]; |
| 4091 | __u8 tkip_rx_mic_key[MIC_KEY_LENGTH]; |
| 4092 | __le16 tkip_rsc_low; |
| 4093 | __le32 tkip_rsc_high; |
| 4094 | __le16 tkip_tsc_low; |
| 4095 | __le32 tkip_tsc_high; |
| 4096 | __u8 mac_addr[6]; |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 4097 | } __packed; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4098 | |
| 4099 | enum { |
| 4100 | MWL8K_ENCR_ENABLE, |
| 4101 | MWL8K_ENCR_SET_KEY, |
| 4102 | MWL8K_ENCR_REMOVE_KEY, |
| 4103 | MWL8K_ENCR_SET_GROUP_KEY, |
| 4104 | }; |
| 4105 | |
| 4106 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0 |
| 4107 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1 |
| 4108 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4 |
| 4109 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7 |
| 4110 | #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8 |
| 4111 | |
| 4112 | enum { |
| 4113 | MWL8K_ALG_WEP, |
| 4114 | MWL8K_ALG_TKIP, |
| 4115 | MWL8K_ALG_CCMP, |
| 4116 | }; |
| 4117 | |
| 4118 | #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004 |
| 4119 | #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008 |
| 4120 | #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040 |
| 4121 | #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000 |
| 4122 | #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000 |
| 4123 | |
| 4124 | static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw, |
| 4125 | struct ieee80211_vif *vif, |
| 4126 | u8 *addr, |
| 4127 | u8 encr_type) |
| 4128 | { |
| 4129 | struct mwl8k_cmd_update_encryption *cmd; |
| 4130 | int rc; |
| 4131 | |
| 4132 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4133 | if (cmd == NULL) |
| 4134 | return -ENOMEM; |
| 4135 | |
| 4136 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION); |
| 4137 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 4138 | cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE); |
| 4139 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 4140 | cmd->encr_type = encr_type; |
| 4141 | |
| 4142 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 4143 | kfree(cmd); |
| 4144 | |
| 4145 | return rc; |
| 4146 | } |
| 4147 | |
| 4148 | static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd, |
| 4149 | u8 *addr, |
| 4150 | struct ieee80211_key_conf *key) |
| 4151 | { |
| 4152 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION); |
| 4153 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 4154 | cmd->length = cpu_to_le16(sizeof(*cmd) - |
| 4155 | offsetof(struct mwl8k_cmd_set_key, length)); |
| 4156 | cmd->key_id = cpu_to_le32(key->keyidx); |
| 4157 | cmd->key_len = cpu_to_le16(key->keylen); |
| 4158 | memcpy(cmd->mac_addr, addr, ETH_ALEN); |
| 4159 | |
| 4160 | switch (key->cipher) { |
| 4161 | case WLAN_CIPHER_SUITE_WEP40: |
| 4162 | case WLAN_CIPHER_SUITE_WEP104: |
| 4163 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP); |
| 4164 | if (key->keyidx == 0) |
| 4165 | cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY); |
| 4166 | |
| 4167 | break; |
| 4168 | case WLAN_CIPHER_SUITE_TKIP: |
| 4169 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP); |
| 4170 | cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4171 | ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE) |
| 4172 | : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY); |
| 4173 | cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID |
| 4174 | | MWL8K_KEY_FLAG_TSC_VALID); |
| 4175 | break; |
| 4176 | case WLAN_CIPHER_SUITE_CCMP: |
| 4177 | cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP); |
| 4178 | cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4179 | ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE) |
| 4180 | : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY); |
| 4181 | break; |
| 4182 | default: |
| 4183 | return -ENOTSUPP; |
| 4184 | } |
| 4185 | |
| 4186 | return 0; |
| 4187 | } |
| 4188 | |
| 4189 | static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw, |
| 4190 | struct ieee80211_vif *vif, |
| 4191 | u8 *addr, |
| 4192 | struct ieee80211_key_conf *key) |
| 4193 | { |
| 4194 | struct mwl8k_cmd_set_key *cmd; |
| 4195 | int rc; |
| 4196 | int keymlen; |
| 4197 | u32 action; |
| 4198 | u8 idx; |
| 4199 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 4200 | |
| 4201 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4202 | if (cmd == NULL) |
| 4203 | return -ENOMEM; |
| 4204 | |
| 4205 | rc = mwl8k_encryption_set_cmd_info(cmd, addr, key); |
| 4206 | if (rc < 0) |
| 4207 | goto done; |
| 4208 | |
| 4209 | idx = key->keyidx; |
| 4210 | |
| 4211 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4212 | action = MWL8K_ENCR_SET_KEY; |
| 4213 | else |
| 4214 | action = MWL8K_ENCR_SET_GROUP_KEY; |
| 4215 | |
| 4216 | switch (key->cipher) { |
| 4217 | case WLAN_CIPHER_SUITE_WEP40: |
| 4218 | case WLAN_CIPHER_SUITE_WEP104: |
| 4219 | if (!mwl8k_vif->wep_key_conf[idx].enabled) { |
| 4220 | memcpy(mwl8k_vif->wep_key_conf[idx].key, key, |
| 4221 | sizeof(*key) + key->keylen); |
| 4222 | mwl8k_vif->wep_key_conf[idx].enabled = 1; |
| 4223 | } |
| 4224 | |
Yogesh Ashok Powar | 9b571e2 | 2011-05-04 17:22:16 +0530 | [diff] [blame] | 4225 | keymlen = key->keylen; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4226 | action = MWL8K_ENCR_SET_KEY; |
| 4227 | break; |
| 4228 | case WLAN_CIPHER_SUITE_TKIP: |
| 4229 | keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH; |
| 4230 | break; |
| 4231 | case WLAN_CIPHER_SUITE_CCMP: |
| 4232 | keymlen = key->keylen; |
| 4233 | break; |
| 4234 | default: |
| 4235 | rc = -ENOTSUPP; |
| 4236 | goto done; |
| 4237 | } |
| 4238 | |
| 4239 | memcpy(cmd->key_material, key->key, keymlen); |
| 4240 | cmd->action = cpu_to_le32(action); |
| 4241 | |
| 4242 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 4243 | done: |
| 4244 | kfree(cmd); |
| 4245 | |
| 4246 | return rc; |
| 4247 | } |
| 4248 | |
| 4249 | static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw, |
| 4250 | struct ieee80211_vif *vif, |
| 4251 | u8 *addr, |
| 4252 | struct ieee80211_key_conf *key) |
| 4253 | { |
| 4254 | struct mwl8k_cmd_set_key *cmd; |
| 4255 | int rc; |
| 4256 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 4257 | |
| 4258 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4259 | if (cmd == NULL) |
| 4260 | return -ENOMEM; |
| 4261 | |
| 4262 | rc = mwl8k_encryption_set_cmd_info(cmd, addr, key); |
| 4263 | if (rc < 0) |
| 4264 | goto done; |
| 4265 | |
| 4266 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
Dan Carpenter | d981e05 | 2012-01-17 10:33:31 +0300 | [diff] [blame] | 4267 | key->cipher == WLAN_CIPHER_SUITE_WEP104) |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4268 | mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0; |
| 4269 | |
| 4270 | cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY); |
| 4271 | |
| 4272 | rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header); |
| 4273 | done: |
| 4274 | kfree(cmd); |
| 4275 | |
| 4276 | return rc; |
| 4277 | } |
| 4278 | |
| 4279 | static int mwl8k_set_key(struct ieee80211_hw *hw, |
| 4280 | enum set_key_cmd cmd_param, |
| 4281 | struct ieee80211_vif *vif, |
| 4282 | struct ieee80211_sta *sta, |
| 4283 | struct ieee80211_key_conf *key) |
| 4284 | { |
| 4285 | int rc = 0; |
| 4286 | u8 encr_type; |
| 4287 | u8 *addr; |
| 4288 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
Yogesh Ashok Powar | 751930c | 2013-01-25 16:20:28 +0530 | [diff] [blame] | 4289 | struct mwl8k_priv *priv = hw->priv; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4290 | |
Yogesh Ashok Powar | 751930c | 2013-01-25 16:20:28 +0530 | [diff] [blame] | 4291 | if (vif->type == NL80211_IFTYPE_STATION && !priv->ap_fw) |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4292 | return -EOPNOTSUPP; |
| 4293 | |
| 4294 | if (sta == NULL) |
Yogesh Ashok Powar | ff7e9f9 | 2012-01-27 16:08:27 +0530 | [diff] [blame] | 4295 | addr = vif->addr; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4296 | else |
| 4297 | addr = sta->addr; |
| 4298 | |
| 4299 | if (cmd_param == SET_KEY) { |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4300 | rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key); |
| 4301 | if (rc) |
| 4302 | goto out; |
| 4303 | |
| 4304 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40) |
| 4305 | || (key->cipher == WLAN_CIPHER_SUITE_WEP104)) |
| 4306 | encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP; |
| 4307 | else |
| 4308 | encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED; |
| 4309 | |
| 4310 | rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr, |
| 4311 | encr_type); |
| 4312 | if (rc) |
| 4313 | goto out; |
| 4314 | |
| 4315 | mwl8k_vif->is_hw_crypto_enabled = true; |
| 4316 | |
| 4317 | } else { |
| 4318 | rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key); |
| 4319 | |
| 4320 | if (rc) |
| 4321 | goto out; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 4322 | } |
| 4323 | out: |
| 4324 | return rc; |
| 4325 | } |
| 4326 | |
| 4327 | /* |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4328 | * CMD_UPDATE_STADB. |
| 4329 | */ |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4330 | struct ewc_ht_info { |
| 4331 | __le16 control1; |
| 4332 | __le16 control2; |
| 4333 | __le16 control3; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4334 | } __packed; |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4335 | |
| 4336 | struct peer_capability_info { |
| 4337 | /* Peer type - AP vs. STA. */ |
| 4338 | __u8 peer_type; |
| 4339 | |
| 4340 | /* Basic 802.11 capabilities from assoc resp. */ |
| 4341 | __le16 basic_caps; |
| 4342 | |
| 4343 | /* Set if peer supports 802.11n high throughput (HT). */ |
| 4344 | __u8 ht_support; |
| 4345 | |
| 4346 | /* Valid if HT is supported. */ |
| 4347 | __le16 ht_caps; |
| 4348 | __u8 extended_ht_caps; |
| 4349 | struct ewc_ht_info ewc_info; |
| 4350 | |
| 4351 | /* Legacy rate table. Intersection of our rates and peer rates. */ |
| 4352 | __u8 legacy_rates[12]; |
| 4353 | |
| 4354 | /* HT rate table. Intersection of our rates and peer rates. */ |
| 4355 | __u8 ht_rates[16]; |
| 4356 | __u8 pad[16]; |
| 4357 | |
| 4358 | /* If set, interoperability mode, no proprietary extensions. */ |
| 4359 | __u8 interop; |
| 4360 | __u8 pad2; |
| 4361 | __u8 station_id; |
| 4362 | __le16 amsdu_enabled; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4363 | } __packed; |
Lennert Buytenhek | 25d81b1 | 2010-01-04 21:54:41 +0100 | [diff] [blame] | 4364 | |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4365 | struct mwl8k_cmd_update_stadb { |
| 4366 | struct mwl8k_cmd_pkt header; |
| 4367 | |
| 4368 | /* See STADB_ACTION_TYPE */ |
| 4369 | __le32 action; |
| 4370 | |
| 4371 | /* Peer MAC address */ |
| 4372 | __u8 peer_addr[ETH_ALEN]; |
| 4373 | |
| 4374 | __le32 reserved; |
| 4375 | |
| 4376 | /* Peer info - valid during add/update. */ |
| 4377 | struct peer_capability_info peer_info; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 4378 | } __packed; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4379 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4380 | #define MWL8K_STA_DB_MODIFY_ENTRY 1 |
| 4381 | #define MWL8K_STA_DB_DEL_ENTRY 2 |
| 4382 | |
| 4383 | /* Peer Entry flags - used to define the type of the peer node */ |
| 4384 | #define MWL8K_PEER_TYPE_ACCESSPOINT 2 |
| 4385 | |
| 4386 | static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw, |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4387 | struct ieee80211_vif *vif, |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4388 | struct ieee80211_sta *sta) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4389 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4390 | struct mwl8k_cmd_update_stadb *cmd; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4391 | struct peer_capability_info *p; |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4392 | u32 rates; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4393 | int rc; |
| 4394 | |
| 4395 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4396 | if (cmd == NULL) |
| 4397 | return -ENOMEM; |
| 4398 | |
| 4399 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB); |
| 4400 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4401 | cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4402 | memcpy(cmd->peer_addr, sta->addr, ETH_ALEN); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4403 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4404 | p = &cmd->peer_info; |
| 4405 | p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT; |
| 4406 | p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4407 | p->ht_support = sta->ht_cap.ht_supported; |
John W. Linville | b603742 | 2010-07-20 13:55:00 -0400 | [diff] [blame] | 4408 | p->ht_caps = cpu_to_le16(sta->ht_cap.cap); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4409 | p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) | |
| 4410 | ((sta->ht_cap.ampdu_density & 7) << 2); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4411 | if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4412 | rates = sta->supp_rates[IEEE80211_BAND_2GHZ]; |
| 4413 | else |
| 4414 | rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 4415 | legacy_rate_mask_to_array(p->legacy_rates, rates); |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4416 | memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16); |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4417 | p->interop = 1; |
| 4418 | p->amsdu_enabled = 0; |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4419 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4420 | rc = mwl8k_post_cmd(hw, &cmd->header); |
Nickolai Zeldovich | c4f74d3 | 2013-01-06 20:27:22 -0500 | [diff] [blame] | 4421 | if (!rc) |
| 4422 | rc = p->station_id; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4423 | kfree(cmd); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4424 | |
Nickolai Zeldovich | c4f74d3 | 2013-01-06 20:27:22 -0500 | [diff] [blame] | 4425 | return rc; |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4426 | } |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4427 | |
Lennert Buytenhek | a680400 | 2010-01-04 21:55:42 +0100 | [diff] [blame] | 4428 | static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw, |
| 4429 | struct ieee80211_vif *vif, u8 *addr) |
| 4430 | { |
| 4431 | struct mwl8k_cmd_update_stadb *cmd; |
| 4432 | int rc; |
| 4433 | |
| 4434 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 4435 | if (cmd == NULL) |
| 4436 | return -ENOMEM; |
| 4437 | |
| 4438 | cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB); |
| 4439 | cmd->header.length = cpu_to_le16(sizeof(*cmd)); |
| 4440 | cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY); |
| 4441 | memcpy(cmd->peer_addr, addr, ETH_ALEN); |
| 4442 | |
| 4443 | rc = mwl8k_post_cmd(hw, &cmd->header); |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4444 | kfree(cmd); |
| 4445 | |
| 4446 | return rc; |
| 4447 | } |
| 4448 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4449 | |
| 4450 | /* |
| 4451 | * Interrupt handling. |
| 4452 | */ |
| 4453 | static irqreturn_t mwl8k_interrupt(int irq, void *dev_id) |
| 4454 | { |
| 4455 | struct ieee80211_hw *hw = dev_id; |
| 4456 | struct mwl8k_priv *priv = hw->priv; |
| 4457 | u32 status; |
| 4458 | |
| 4459 | status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4460 | if (!status) |
| 4461 | return IRQ_NONE; |
| 4462 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4463 | if (status & MWL8K_A2H_INT_TX_DONE) { |
| 4464 | status &= ~MWL8K_A2H_INT_TX_DONE; |
| 4465 | tasklet_schedule(&priv->poll_tx_task); |
| 4466 | } |
| 4467 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4468 | if (status & MWL8K_A2H_INT_RX_READY) { |
| 4469 | status &= ~MWL8K_A2H_INT_RX_READY; |
| 4470 | tasklet_schedule(&priv->poll_rx_task); |
| 4471 | } |
| 4472 | |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 4473 | if (status & MWL8K_A2H_INT_BA_WATCHDOG) { |
Yogesh Ashok Powar | c27a54d | 2013-01-03 13:24:19 +0530 | [diff] [blame] | 4474 | iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG, |
| 4475 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
| 4476 | |
| 4477 | atomic_inc(&priv->watchdog_event_pending); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 4478 | status &= ~MWL8K_A2H_INT_BA_WATCHDOG; |
| 4479 | ieee80211_queue_work(hw, &priv->watchdog_ba_handle); |
| 4480 | } |
| 4481 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4482 | if (status) |
| 4483 | iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4484 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4485 | if (status & MWL8K_A2H_INT_OPC_DONE) { |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4486 | if (priv->hostcmd_wait != NULL) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4487 | complete(priv->hostcmd_wait); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | if (status & MWL8K_A2H_INT_QUEUE_EMPTY) { |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4491 | if (!mutex_is_locked(&priv->fw_mutex) && |
Lennert Buytenhek | 88de754a | 2009-10-22 20:19:37 +0200 | [diff] [blame] | 4492 | priv->radio_on && priv->pending_tx_pkts) |
Lennert Buytenhek | 618952a | 2009-08-18 03:18:01 +0200 | [diff] [blame] | 4493 | mwl8k_tx_start(priv); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | return IRQ_HANDLED; |
| 4497 | } |
| 4498 | |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4499 | static void mwl8k_tx_poll(unsigned long data) |
| 4500 | { |
| 4501 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 4502 | struct mwl8k_priv *priv = hw->priv; |
| 4503 | int limit; |
| 4504 | int i; |
| 4505 | |
| 4506 | limit = 32; |
| 4507 | |
| 4508 | spin_lock_bh(&priv->tx_lock); |
| 4509 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 4510 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4511 | limit -= mwl8k_txq_reclaim(hw, i, limit, 0); |
| 4512 | |
| 4513 | if (!priv->pending_tx_pkts && priv->tx_wait != NULL) { |
| 4514 | complete(priv->tx_wait); |
| 4515 | priv->tx_wait = NULL; |
| 4516 | } |
| 4517 | |
| 4518 | spin_unlock_bh(&priv->tx_lock); |
| 4519 | |
| 4520 | if (limit) { |
| 4521 | writel(~MWL8K_A2H_INT_TX_DONE, |
| 4522 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 4523 | } else { |
| 4524 | tasklet_schedule(&priv->poll_tx_task); |
| 4525 | } |
| 4526 | } |
| 4527 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4528 | static void mwl8k_rx_poll(unsigned long data) |
| 4529 | { |
| 4530 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 4531 | struct mwl8k_priv *priv = hw->priv; |
| 4532 | int limit; |
| 4533 | |
| 4534 | limit = 32; |
| 4535 | limit -= rxq_process(hw, 0, limit); |
| 4536 | limit -= rxq_refill(hw, 0, limit); |
| 4537 | |
| 4538 | if (limit) { |
| 4539 | writel(~MWL8K_A2H_INT_RX_READY, |
| 4540 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 4541 | } else { |
| 4542 | tasklet_schedule(&priv->poll_rx_task); |
| 4543 | } |
| 4544 | } |
| 4545 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4546 | |
| 4547 | /* |
| 4548 | * Core driver operations. |
| 4549 | */ |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 4550 | static void mwl8k_tx(struct ieee80211_hw *hw, |
| 4551 | struct ieee80211_tx_control *control, |
| 4552 | struct sk_buff *skb) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4553 | { |
| 4554 | struct mwl8k_priv *priv = hw->priv; |
| 4555 | int index = skb_get_queue_mapping(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4556 | |
Lennert Buytenhek | 9189c10 | 2010-01-12 13:47:32 +0100 | [diff] [blame] | 4557 | if (!priv->radio_on) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4558 | wiphy_debug(hw->wiphy, |
| 4559 | "dropped TX frame since radio disabled\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4560 | dev_kfree_skb(skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 4561 | return; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4562 | } |
| 4563 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 4564 | mwl8k_txq_xmit(hw, index, control->sta, skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4565 | } |
| 4566 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4567 | static int mwl8k_start(struct ieee80211_hw *hw) |
| 4568 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4569 | struct mwl8k_priv *priv = hw->priv; |
| 4570 | int rc; |
| 4571 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 4572 | rc = request_irq(priv->pdev->irq, mwl8k_interrupt, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4573 | IRQF_SHARED, MWL8K_NAME, hw); |
| 4574 | if (rc) { |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4575 | priv->irq = -1; |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 4576 | wiphy_err(hw->wiphy, "failed to register IRQ handler\n"); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4577 | return -EIO; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4578 | } |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4579 | priv->irq = priv->pdev->irq; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4580 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4581 | /* Enable TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4582 | tasklet_enable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4583 | tasklet_enable(&priv->poll_rx_task); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4584 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4585 | /* Enable interrupts */ |
Lennert Buytenhek | c23b5a6 | 2009-07-16 13:49:55 +0200 | [diff] [blame] | 4586 | iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Nishant Sarmukadam | 12488e0 | 2011-04-08 14:38:27 +0530 | [diff] [blame] | 4587 | iowrite32(MWL8K_A2H_EVENTS, |
| 4588 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4589 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4590 | rc = mwl8k_fw_lock(hw); |
| 4591 | if (!rc) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4592 | rc = mwl8k_cmd_radio_enable(hw); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4593 | |
Lennert Buytenhek | 5e4cf16 | 2009-10-22 20:21:38 +0200 | [diff] [blame] | 4594 | if (!priv->ap_fw) { |
| 4595 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4596 | rc = mwl8k_cmd_enable_sniffer(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4597 | |
Lennert Buytenhek | 5e4cf16 | 2009-10-22 20:21:38 +0200 | [diff] [blame] | 4598 | if (!rc) |
| 4599 | rc = mwl8k_cmd_set_pre_scan(hw); |
| 4600 | |
| 4601 | if (!rc) |
| 4602 | rc = mwl8k_cmd_set_post_scan(hw, |
| 4603 | "\x00\x00\x00\x00\x00\x00"); |
| 4604 | } |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4605 | |
| 4606 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4607 | rc = mwl8k_cmd_set_rateadapt_mode(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4608 | |
| 4609 | if (!rc) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 4610 | rc = mwl8k_cmd_set_wmm_mode(hw, 0); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4611 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4612 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4613 | } |
| 4614 | |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4615 | if (rc) { |
| 4616 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 4617 | free_irq(priv->pdev->irq, hw); |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4618 | priv->irq = -1; |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4619 | tasklet_disable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4620 | tasklet_disable(&priv->poll_rx_task); |
Nishant Sarmukadam | 4850b6d | 2013-01-08 12:10:53 +0530 | [diff] [blame] | 4621 | } else { |
| 4622 | ieee80211_wake_queues(hw); |
Lennert Buytenhek | 2ec610c | 2009-07-17 07:11:37 +0200 | [diff] [blame] | 4623 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4624 | |
| 4625 | return rc; |
| 4626 | } |
| 4627 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4628 | static void mwl8k_stop(struct ieee80211_hw *hw) |
| 4629 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4630 | struct mwl8k_priv *priv = hw->priv; |
| 4631 | int i; |
| 4632 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 4633 | if (!priv->hw_restart_in_progress) |
| 4634 | mwl8k_cmd_radio_disable(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4635 | |
| 4636 | ieee80211_stop_queues(hw); |
| 4637 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4638 | /* Disable interrupts */ |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4639 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Brian Cavagnolo | bf3ca7f | 2011-04-06 14:18:46 +0530 | [diff] [blame] | 4640 | if (priv->irq != -1) { |
| 4641 | free_irq(priv->pdev->irq, hw); |
| 4642 | priv->irq = -1; |
| 4643 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4644 | |
| 4645 | /* Stop finalize join worker */ |
| 4646 | cancel_work_sync(&priv->finalize_join_worker); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 4647 | cancel_work_sync(&priv->watchdog_ba_handle); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4648 | if (priv->beacon_skb != NULL) |
| 4649 | dev_kfree_skb(priv->beacon_skb); |
| 4650 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4651 | /* Stop TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 4652 | tasklet_disable(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 4653 | tasklet_disable(&priv->poll_rx_task); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4654 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4655 | /* Return all skbs to mac80211 */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 4656 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 4657 | mwl8k_txq_reclaim(hw, i, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4658 | } |
| 4659 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4660 | static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image); |
| 4661 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4662 | static int mwl8k_add_interface(struct ieee80211_hw *hw, |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4663 | struct ieee80211_vif *vif) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4664 | { |
| 4665 | struct mwl8k_priv *priv = hw->priv; |
| 4666 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4667 | u32 macids_supported; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4668 | int macid, rc; |
| 4669 | struct mwl8k_device_info *di; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4670 | |
| 4671 | /* |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4672 | * Reject interface creation if sniffer mode is active, as |
| 4673 | * STA operation is mutually exclusive with hardware sniffer |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4674 | * mode. (Sniffer mode is only used on STA firmware.) |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4675 | */ |
| 4676 | if (priv->sniffer_enabled) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4677 | wiphy_info(hw->wiphy, |
| 4678 | "unable to create STA interface because sniffer mode is enabled\n"); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 4679 | return -EINVAL; |
| 4680 | } |
| 4681 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4682 | di = priv->device_info; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4683 | switch (vif->type) { |
| 4684 | case NL80211_IFTYPE_AP: |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4685 | if (!priv->ap_fw && di->fw_image_ap) { |
| 4686 | /* we must load the ap fw to meet this request */ |
| 4687 | if (!list_empty(&priv->vif_list)) |
| 4688 | return -EBUSY; |
| 4689 | rc = mwl8k_reload_firmware(hw, di->fw_image_ap); |
| 4690 | if (rc) |
| 4691 | return rc; |
| 4692 | } |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4693 | macids_supported = priv->ap_macids_supported; |
| 4694 | break; |
| 4695 | case NL80211_IFTYPE_STATION: |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4696 | if (priv->ap_fw && di->fw_image_sta) { |
Yogesh Ashok Powar | d59c1cf | 2013-01-25 16:20:03 +0530 | [diff] [blame] | 4697 | if (!list_empty(&priv->vif_list)) { |
| 4698 | wiphy_warn(hw->wiphy, "AP interface is running.\n" |
| 4699 | "Adding STA interface for WDS"); |
| 4700 | } else { |
| 4701 | /* we must load the sta fw to |
| 4702 | * meet this request. |
| 4703 | */ |
| 4704 | rc = mwl8k_reload_firmware(hw, |
| 4705 | di->fw_image_sta); |
| 4706 | if (rc) |
| 4707 | return rc; |
| 4708 | } |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 4709 | } |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4710 | macids_supported = priv->sta_macids_supported; |
| 4711 | break; |
| 4712 | default: |
| 4713 | return -EINVAL; |
| 4714 | } |
| 4715 | |
| 4716 | macid = ffs(macids_supported & ~priv->macids_used); |
| 4717 | if (!macid--) |
| 4718 | return -EBUSY; |
| 4719 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4720 | /* Setup driver private area. */ |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 4721 | mwl8k_vif = MWL8K_VIF(vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4722 | memset(mwl8k_vif, 0, sizeof(*mwl8k_vif)); |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4723 | mwl8k_vif->vif = vif; |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4724 | mwl8k_vif->macid = macid; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4725 | mwl8k_vif->seqno = 0; |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 4726 | memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN); |
| 4727 | mwl8k_vif->is_hw_crypto_enabled = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4728 | |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4729 | /* Set the mac address. */ |
| 4730 | mwl8k_cmd_set_mac_addr(hw, vif, vif->addr); |
| 4731 | |
Yogesh Ashok Powar | d994a1c | 2013-01-25 16:20:35 +0530 | [diff] [blame] | 4732 | if (vif->type == NL80211_IFTYPE_AP) |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 4733 | mwl8k_cmd_set_new_stn_add_self(hw, vif); |
| 4734 | |
Lennert Buytenhek | ee0ddf1 | 2010-01-12 13:51:30 +0100 | [diff] [blame] | 4735 | priv->macids_used |= 1 << mwl8k_vif->macid; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4736 | list_add_tail(&mwl8k_vif->list, &priv->vif_list); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4737 | |
| 4738 | return 0; |
| 4739 | } |
| 4740 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 4741 | static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif) |
| 4742 | { |
| 4743 | /* Has ieee80211_restart_hw re-added the removed interfaces? */ |
| 4744 | if (!priv->macids_used) |
| 4745 | return; |
| 4746 | |
| 4747 | priv->macids_used &= ~(1 << vif->macid); |
| 4748 | list_del(&vif->list); |
| 4749 | } |
| 4750 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4751 | static void mwl8k_remove_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 4752 | struct ieee80211_vif *vif) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4753 | { |
| 4754 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 4755 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4756 | |
Yogesh Ashok Powar | d994a1c | 2013-01-25 16:20:35 +0530 | [diff] [blame] | 4757 | if (vif->type == NL80211_IFTYPE_AP) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4758 | mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr); |
| 4759 | |
Yogesh Ashok Powar | 197a4e4 | 2012-02-01 16:19:54 +0530 | [diff] [blame] | 4760 | mwl8k_cmd_del_mac_addr(hw, vif, vif->addr); |
Lennert Buytenhek | 32060e1 | 2009-10-22 20:20:04 +0200 | [diff] [blame] | 4761 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 4762 | mwl8k_remove_vif(priv, mwl8k_vif); |
| 4763 | } |
| 4764 | |
| 4765 | static void mwl8k_hw_restart_work(struct work_struct *work) |
| 4766 | { |
| 4767 | struct mwl8k_priv *priv = |
| 4768 | container_of(work, struct mwl8k_priv, fw_reload); |
| 4769 | struct ieee80211_hw *hw = priv->hw; |
| 4770 | struct mwl8k_device_info *di; |
| 4771 | int rc; |
| 4772 | |
| 4773 | /* If some command is waiting for a response, clear it */ |
| 4774 | if (priv->hostcmd_wait != NULL) { |
| 4775 | complete(priv->hostcmd_wait); |
| 4776 | priv->hostcmd_wait = NULL; |
| 4777 | } |
| 4778 | |
| 4779 | priv->hw_restart_owner = current; |
| 4780 | di = priv->device_info; |
| 4781 | mwl8k_fw_lock(hw); |
| 4782 | |
| 4783 | if (priv->ap_fw) |
| 4784 | rc = mwl8k_reload_firmware(hw, di->fw_image_ap); |
| 4785 | else |
| 4786 | rc = mwl8k_reload_firmware(hw, di->fw_image_sta); |
| 4787 | |
| 4788 | if (rc) |
| 4789 | goto fail; |
| 4790 | |
| 4791 | priv->hw_restart_owner = NULL; |
| 4792 | priv->hw_restart_in_progress = false; |
| 4793 | |
| 4794 | /* |
| 4795 | * This unlock will wake up the queues and |
| 4796 | * also opens the command path for other |
| 4797 | * commands |
| 4798 | */ |
| 4799 | mwl8k_fw_unlock(hw); |
| 4800 | |
| 4801 | ieee80211_restart_hw(hw); |
| 4802 | |
| 4803 | wiphy_err(hw->wiphy, "Firmware restarted successfully\n"); |
| 4804 | |
| 4805 | return; |
| 4806 | fail: |
| 4807 | mwl8k_fw_unlock(hw); |
| 4808 | |
| 4809 | wiphy_err(hw->wiphy, "Firmware restart failed\n"); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4810 | } |
| 4811 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4812 | static int mwl8k_config(struct ieee80211_hw *hw, u32 changed) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4813 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4814 | struct ieee80211_conf *conf = &hw->conf; |
| 4815 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4816 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4817 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4818 | rc = mwl8k_fw_lock(hw); |
| 4819 | if (rc) |
| 4820 | return rc; |
| 4821 | |
Jonas Gorski | fe21bb0 | 2013-03-25 16:39:54 +0100 | [diff] [blame] | 4822 | if (conf->flags & IEEE80211_CONF_IDLE) |
| 4823 | rc = mwl8k_cmd_radio_disable(hw); |
| 4824 | else |
| 4825 | rc = mwl8k_cmd_radio_enable(hw); |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4826 | if (rc) |
| 4827 | goto out; |
| 4828 | |
Yogesh Ashok Powar | 0f4316b | 2013-01-25 16:17:45 +0530 | [diff] [blame] | 4829 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 4830 | rc = mwl8k_cmd_set_rf_channel(hw, conf); |
| 4831 | if (rc) |
| 4832 | goto out; |
| 4833 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4834 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4835 | if (conf->power_level > 18) |
| 4836 | conf->power_level = 18; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4837 | |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4838 | if (priv->ap_fw) { |
Nishant Sarmukadam | 0321708 | 2011-04-05 14:18:09 +0530 | [diff] [blame] | 4839 | |
| 4840 | if (conf->flags & IEEE80211_CONF_CHANGE_POWER) { |
| 4841 | rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level); |
| 4842 | if (rc) |
| 4843 | goto out; |
| 4844 | } |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 4845 | |
Nishant Sarmukadam | da62b76 | 2011-02-17 14:45:16 -0800 | [diff] [blame] | 4846 | |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4847 | } else { |
Nishant Sarmukadam | 41fdf09 | 2010-11-12 17:23:48 -0800 | [diff] [blame] | 4848 | rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level); |
| 4849 | if (rc) |
| 4850 | goto out; |
Lennert Buytenhek | 08b0634 | 2009-10-22 20:21:33 +0200 | [diff] [blame] | 4851 | rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7); |
| 4852 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4853 | |
Lennert Buytenhek | ee03a93 | 2009-07-17 07:19:37 +0200 | [diff] [blame] | 4854 | out: |
| 4855 | mwl8k_fw_unlock(hw); |
| 4856 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4857 | return rc; |
| 4858 | } |
| 4859 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4860 | static void |
| 4861 | mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4862 | struct ieee80211_bss_conf *info, u32 changed) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4863 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4864 | struct mwl8k_priv *priv = hw->priv; |
Yogesh Ashok Powar | ba30c4a | 2011-04-09 00:25:37 +0530 | [diff] [blame] | 4865 | u32 ap_legacy_rates = 0; |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4866 | u8 ap_mcs_rates[16]; |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4867 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4868 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4869 | if (mwl8k_fw_lock(hw)) |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4870 | return; |
| 4871 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4872 | /* |
| 4873 | * No need to capture a beacon if we're no longer associated. |
| 4874 | */ |
| 4875 | if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc) |
| 4876 | priv->capture_beacon = false; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4877 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4878 | /* |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4879 | * Get the AP's legacy and MCS rates. |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4880 | */ |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4881 | if (vif->bss_conf.assoc) { |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4882 | struct ieee80211_sta *ap; |
Lennert Buytenhek | c97470d | 2010-01-12 13:47:37 +0100 | [diff] [blame] | 4883 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4884 | rcu_read_lock(); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4885 | |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4886 | ap = ieee80211_find_sta(vif, vif->bss_conf.bssid); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4887 | if (ap == NULL) { |
| 4888 | rcu_read_unlock(); |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4889 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4890 | } |
Lennert Buytenhek | c6e9601 | 2010-01-04 21:55:52 +0100 | [diff] [blame] | 4891 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4892 | if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) { |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4893 | ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ]; |
| 4894 | } else { |
| 4895 | ap_legacy_rates = |
| 4896 | ap->supp_rates[IEEE80211_BAND_5GHZ] << 5; |
| 4897 | } |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4898 | memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16); |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4899 | |
| 4900 | rcu_read_unlock(); |
| 4901 | } |
| 4902 | |
Yogesh Ashok Powar | dcee743 | 2013-01-25 16:20:50 +0530 | [diff] [blame] | 4903 | if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc && |
| 4904 | !priv->ap_fw) { |
Lennert Buytenhek | 13935e2 | 2010-01-04 21:57:59 +0100 | [diff] [blame] | 4905 | 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] | 4906 | if (rc) |
| 4907 | goto out; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4908 | |
Lennert Buytenhek | b71ed2c | 2010-01-08 18:30:16 +0100 | [diff] [blame] | 4909 | rc = mwl8k_cmd_use_fixed_rate_sta(hw); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4910 | if (rc) |
| 4911 | goto out; |
Yogesh Ashok Powar | dcee743 | 2013-01-25 16:20:50 +0530 | [diff] [blame] | 4912 | } else { |
| 4913 | if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc && |
| 4914 | priv->ap_fw) { |
| 4915 | int idx; |
| 4916 | int rate; |
| 4917 | |
| 4918 | /* Use AP firmware specific rate command. |
| 4919 | */ |
| 4920 | idx = ffs(vif->bss_conf.basic_rates); |
| 4921 | if (idx) |
| 4922 | idx--; |
| 4923 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4924 | if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) |
Yogesh Ashok Powar | dcee743 | 2013-01-25 16:20:50 +0530 | [diff] [blame] | 4925 | rate = mwl8k_rates_24[idx].hw_value; |
| 4926 | else |
| 4927 | rate = mwl8k_rates_50[idx].hw_value; |
| 4928 | |
| 4929 | mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate); |
| 4930 | } |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4931 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4932 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4933 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4934 | rc = mwl8k_set_radio_preamble(hw, |
| 4935 | vif->bss_conf.use_short_preamble); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4936 | if (rc) |
| 4937 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4938 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4939 | |
Yogesh Ashok Powar | dcee743 | 2013-01-25 16:20:50 +0530 | [diff] [blame] | 4940 | if ((changed & BSS_CHANGED_ERP_SLOT) && !priv->ap_fw) { |
Lennert Buytenhek | 7dc6a7a | 2009-11-30 18:33:09 +0100 | [diff] [blame] | 4941 | rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4942 | if (rc) |
| 4943 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4944 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4945 | |
Yogesh Ashok Powar | dcee743 | 2013-01-25 16:20:50 +0530 | [diff] [blame] | 4946 | if (vif->bss_conf.assoc && !priv->ap_fw && |
Lennert Buytenhek | c97470d | 2010-01-12 13:47:37 +0100 | [diff] [blame] | 4947 | (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT | |
| 4948 | BSS_CHANGED_HT))) { |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4949 | rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates); |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4950 | if (rc) |
| 4951 | goto out; |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4952 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4953 | |
Lennert Buytenhek | c3cbbe8 | 2010-01-04 21:56:07 +0100 | [diff] [blame] | 4954 | if (vif->bss_conf.assoc && |
| 4955 | (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4956 | /* |
| 4957 | * Finalize the join. Tell rx handler to process |
| 4958 | * next beacon from our BSSID. |
| 4959 | */ |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 4960 | memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4961 | priv->capture_beacon = true; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4962 | } |
| 4963 | |
Lennert Buytenhek | 3a980d0 | 2009-07-17 07:21:46 +0200 | [diff] [blame] | 4964 | out: |
| 4965 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 4966 | } |
| 4967 | |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 4968 | static void |
| 4969 | mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4970 | struct ieee80211_bss_conf *info, u32 changed) |
| 4971 | { |
| 4972 | int rc; |
| 4973 | |
| 4974 | if (mwl8k_fw_lock(hw)) |
| 4975 | return; |
| 4976 | |
| 4977 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 4978 | rc = mwl8k_set_radio_preamble(hw, |
| 4979 | vif->bss_conf.use_short_preamble); |
| 4980 | if (rc) |
| 4981 | goto out; |
| 4982 | } |
| 4983 | |
| 4984 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 4985 | int idx; |
| 4986 | int rate; |
| 4987 | |
| 4988 | /* |
| 4989 | * Use lowest supported basic rate for multicasts |
| 4990 | * and management frames (such as probe responses -- |
| 4991 | * beacons will always go out at 1 Mb/s). |
| 4992 | */ |
| 4993 | idx = ffs(vif->bss_conf.basic_rates); |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4994 | if (idx) |
| 4995 | idx--; |
| 4996 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4997 | if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) |
Lennert Buytenhek | 8707d02 | 2010-01-12 13:49:15 +0100 | [diff] [blame] | 4998 | rate = mwl8k_rates_24[idx].hw_value; |
| 4999 | else |
| 5000 | rate = mwl8k_rates_50[idx].hw_value; |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 5001 | |
| 5002 | mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate); |
| 5003 | } |
| 5004 | |
| 5005 | if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) { |
| 5006 | struct sk_buff *skb; |
| 5007 | |
| 5008 | skb = ieee80211_beacon_get(hw, vif); |
| 5009 | if (skb != NULL) { |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 5010 | mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 5011 | kfree_skb(skb); |
| 5012 | } |
| 5013 | } |
| 5014 | |
| 5015 | if (changed & BSS_CHANGED_BEACON_ENABLED) |
Lennert Buytenhek | aa21d0f6 | 2010-01-12 13:50:36 +0100 | [diff] [blame] | 5016 | mwl8k_cmd_bss_start(hw, vif, info->enable_beacon); |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 5017 | |
| 5018 | out: |
| 5019 | mwl8k_fw_unlock(hw); |
| 5020 | } |
| 5021 | |
| 5022 | static void |
| 5023 | mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5024 | struct ieee80211_bss_conf *info, u32 changed) |
| 5025 | { |
Yogesh Ashok Powar | 41bf911 | 2013-01-25 16:20:42 +0530 | [diff] [blame] | 5026 | if (vif->type == NL80211_IFTYPE_STATION) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 5027 | mwl8k_bss_info_changed_sta(hw, vif, info, changed); |
Yogesh Ashok Powar | 41bf911 | 2013-01-25 16:20:42 +0530 | [diff] [blame] | 5028 | if (vif->type == NL80211_IFTYPE_AP) |
Lennert Buytenhek | b64fe61 | 2010-01-08 18:31:39 +0100 | [diff] [blame] | 5029 | mwl8k_bss_info_changed_ap(hw, vif, info, changed); |
| 5030 | } |
| 5031 | |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 5032 | static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw, |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5033 | struct netdev_hw_addr_list *mc_list) |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 5034 | { |
| 5035 | struct mwl8k_cmd_pkt *cmd; |
| 5036 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 5037 | /* |
| 5038 | * Synthesize and return a command packet that programs the |
| 5039 | * hardware multicast address filter. At this point we don't |
| 5040 | * know whether FIF_ALLMULTI is being requested, but if it is, |
| 5041 | * we'll end up throwing this packet away and creating a new |
| 5042 | * one in mwl8k_configure_filter(). |
| 5043 | */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5044 | cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list); |
Lennert Buytenhek | e81cd2d | 2009-08-18 03:55:42 +0200 | [diff] [blame] | 5045 | |
| 5046 | return (unsigned long)cmd; |
| 5047 | } |
| 5048 | |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 5049 | static int |
| 5050 | mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw, |
| 5051 | unsigned int changed_flags, |
| 5052 | unsigned int *total_flags) |
| 5053 | { |
| 5054 | struct mwl8k_priv *priv = hw->priv; |
| 5055 | |
| 5056 | /* |
| 5057 | * Hardware sniffer mode is mutually exclusive with STA |
| 5058 | * operation, so refuse to enable sniffer mode if a STA |
| 5059 | * interface is active. |
| 5060 | */ |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 5061 | if (!list_empty(&priv->vif_list)) { |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 5062 | if (net_ratelimit()) |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 5063 | wiphy_info(hw->wiphy, |
| 5064 | "not enabling sniffer mode because STA interface is active\n"); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 5065 | return 0; |
| 5066 | } |
| 5067 | |
| 5068 | if (!priv->sniffer_enabled) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 5069 | if (mwl8k_cmd_enable_sniffer(hw, 1)) |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 5070 | return 0; |
| 5071 | priv->sniffer_enabled = true; |
| 5072 | } |
| 5073 | |
| 5074 | *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI | |
| 5075 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL | |
| 5076 | FIF_OTHER_BSS; |
| 5077 | |
| 5078 | return 1; |
| 5079 | } |
| 5080 | |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 5081 | static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv) |
| 5082 | { |
| 5083 | if (!list_empty(&priv->vif_list)) |
| 5084 | return list_entry(priv->vif_list.next, struct mwl8k_vif, list); |
| 5085 | |
| 5086 | return NULL; |
| 5087 | } |
| 5088 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5089 | static void mwl8k_configure_filter(struct ieee80211_hw *hw, |
| 5090 | unsigned int changed_flags, |
| 5091 | unsigned int *total_flags, |
| 5092 | u64 multicast) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5093 | { |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5094 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 5095 | struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast; |
| 5096 | |
| 5097 | /* |
Lennert Buytenhek | c0adae2 | 2009-10-22 20:21:36 +0200 | [diff] [blame] | 5098 | * AP firmware doesn't allow fine-grained control over |
| 5099 | * the receive filter. |
| 5100 | */ |
| 5101 | if (priv->ap_fw) { |
| 5102 | *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC; |
| 5103 | kfree(cmd); |
| 5104 | return; |
| 5105 | } |
| 5106 | |
| 5107 | /* |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 5108 | * Enable hardware sniffer mode if FIF_CONTROL or |
| 5109 | * FIF_OTHER_BSS is requested. |
| 5110 | */ |
| 5111 | if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) && |
| 5112 | mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) { |
| 5113 | kfree(cmd); |
| 5114 | return; |
| 5115 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5116 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5117 | /* Clear unsupported feature flags */ |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 5118 | *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC; |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5119 | |
Lennert Buytenhek | 90852f7 | 2010-01-02 10:31:42 +0100 | [diff] [blame] | 5120 | if (mwl8k_fw_lock(hw)) { |
| 5121 | kfree(cmd); |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5122 | return; |
Lennert Buytenhek | 90852f7 | 2010-01-02 10:31:42 +0100 | [diff] [blame] | 5123 | } |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5124 | |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 5125 | if (priv->sniffer_enabled) { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 5126 | mwl8k_cmd_enable_sniffer(hw, 0); |
Lennert Buytenhek | a43c49a | 2009-10-22 20:20:32 +0200 | [diff] [blame] | 5127 | priv->sniffer_enabled = false; |
| 5128 | } |
| 5129 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5130 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 5131 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 5132 | /* |
| 5133 | * Disable the BSS filter. |
| 5134 | */ |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5135 | mwl8k_cmd_set_pre_scan(hw); |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 5136 | } else { |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 5137 | struct mwl8k_vif *mwl8k_vif; |
Lennert Buytenhek | 0a11dfc | 2010-01-04 21:55:21 +0100 | [diff] [blame] | 5138 | const u8 *bssid; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 5139 | |
Lennert Buytenhek | 77165d8 | 2009-10-22 20:19:53 +0200 | [diff] [blame] | 5140 | /* |
| 5141 | * Enable the BSS filter. |
| 5142 | * |
| 5143 | * If there is an active STA interface, use that |
| 5144 | * interface's BSSID, otherwise use a dummy one |
| 5145 | * (where the OUI part needs to be nonzero for |
| 5146 | * the BSSID to be accepted by POST_SCAN). |
| 5147 | */ |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 5148 | mwl8k_vif = mwl8k_first_vif(priv); |
| 5149 | if (mwl8k_vif != NULL) |
| 5150 | bssid = mwl8k_vif->vif->bss_conf.bssid; |
| 5151 | else |
| 5152 | bssid = "\x01\x00\x00\x00\x00\x00"; |
Lennert Buytenhek | a94cc97 | 2009-08-03 21:58:57 +0200 | [diff] [blame] | 5153 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5154 | mwl8k_cmd_set_post_scan(hw, bssid); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5155 | } |
| 5156 | } |
| 5157 | |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 5158 | /* |
| 5159 | * If FIF_ALLMULTI is being requested, throw away the command |
| 5160 | * packet that ->prepare_multicast() built and replace it with |
| 5161 | * a command packet that enables reception of all multicast |
| 5162 | * packets. |
| 5163 | */ |
| 5164 | if (*total_flags & FIF_ALLMULTI) { |
| 5165 | kfree(cmd); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5166 | cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL); |
Lennert Buytenhek | 447ced0 | 2009-10-22 20:19:50 +0200 | [diff] [blame] | 5167 | } |
| 5168 | |
| 5169 | if (cmd != NULL) { |
| 5170 | mwl8k_post_cmd(hw, cmd); |
| 5171 | kfree(cmd); |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5172 | } |
Lennert Buytenhek | ce9e2e1 | 2009-07-16 14:00:45 +0200 | [diff] [blame] | 5173 | |
Lennert Buytenhek | e6935ea | 2009-08-18 04:06:20 +0200 | [diff] [blame] | 5174 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5175 | } |
| 5176 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5177 | static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 5178 | { |
Lennert Buytenhek | c2c2b12 | 2010-01-08 18:27:59 +0100 | [diff] [blame] | 5179 | return mwl8k_cmd_set_rts_threshold(hw, value); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5180 | } |
| 5181 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5182 | static int mwl8k_sta_remove(struct ieee80211_hw *hw, |
| 5183 | struct ieee80211_vif *vif, |
| 5184 | struct ieee80211_sta *sta) |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5185 | { |
| 5186 | struct mwl8k_priv *priv = hw->priv; |
| 5187 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5188 | if (priv->ap_fw) |
| 5189 | return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr); |
| 5190 | else |
| 5191 | return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr); |
| 5192 | } |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5193 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5194 | static int mwl8k_sta_add(struct ieee80211_hw *hw, |
| 5195 | struct ieee80211_vif *vif, |
| 5196 | struct ieee80211_sta *sta) |
| 5197 | { |
| 5198 | struct mwl8k_priv *priv = hw->priv; |
| 5199 | int ret; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5200 | int i; |
| 5201 | struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif); |
| 5202 | struct ieee80211_key_conf *key; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5203 | |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5204 | if (!priv->ap_fw) { |
| 5205 | ret = mwl8k_cmd_update_stadb_add(hw, vif, sta); |
| 5206 | if (ret >= 0) { |
| 5207 | MWL8K_STA(sta)->peer_id = ret; |
Nishant Sarmukadam | 17033543 | 2011-03-17 11:58:48 -0700 | [diff] [blame] | 5208 | if (sta->ht_cap.ht_supported) |
| 5209 | MWL8K_STA(sta)->is_ampdu_allowed = true; |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5210 | ret = 0; |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5211 | } |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5212 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 5213 | } else { |
| 5214 | ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta); |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5215 | } |
Lennert Buytenhek | 3f5610f | 2010-01-08 18:30:58 +0100 | [diff] [blame] | 5216 | |
Nishant Sarmukadam | d9a07d4 | 2010-12-30 11:23:33 -0800 | [diff] [blame] | 5217 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 5218 | key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key); |
| 5219 | if (mwl8k_vif->wep_key_conf[i].enabled) |
| 5220 | mwl8k_set_key(hw, SET_KEY, vif, sta, key); |
| 5221 | } |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5222 | return ret; |
Lennert Buytenhek | bbfd912 | 2010-01-04 21:55:12 +0100 | [diff] [blame] | 5223 | } |
| 5224 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 5225 | static int mwl8k_conf_tx(struct ieee80211_hw *hw, |
| 5226 | struct ieee80211_vif *vif, u16 queue, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5227 | const struct ieee80211_tx_queue_params *params) |
| 5228 | { |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5229 | struct mwl8k_priv *priv = hw->priv; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5230 | int rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5231 | |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5232 | rc = mwl8k_fw_lock(hw); |
| 5233 | if (!rc) { |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5234 | BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1); |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5235 | memcpy(&priv->wmm_params[queue], params, sizeof(*params)); |
| 5236 | |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5237 | if (!priv->wmm_enabled) |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 5238 | rc = mwl8k_cmd_set_wmm_mode(hw, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5239 | |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 5240 | if (!rc) { |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5241 | int q = MWL8K_TX_WMM_QUEUES - 1 - queue; |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 5242 | rc = mwl8k_cmd_set_edca_params(hw, q, |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 5243 | params->cw_min, |
| 5244 | params->cw_max, |
| 5245 | params->aifs, |
| 5246 | params->txop); |
Nishant Sarmukadam | 85c9205 | 2011-02-17 14:45:18 -0800 | [diff] [blame] | 5247 | } |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5248 | |
| 5249 | mwl8k_fw_unlock(hw); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5250 | } |
Lennert Buytenhek | 3e4f542 | 2009-07-17 07:25:59 +0200 | [diff] [blame] | 5251 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5252 | return rc; |
| 5253 | } |
| 5254 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5255 | static int mwl8k_get_stats(struct ieee80211_hw *hw, |
| 5256 | struct ieee80211_low_level_stats *stats) |
| 5257 | { |
Lennert Buytenhek | 55489b6 | 2009-11-30 18:31:33 +0100 | [diff] [blame] | 5258 | return mwl8k_cmd_get_stat(hw, stats); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5259 | } |
| 5260 | |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 5261 | static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx, |
| 5262 | struct survey_info *survey) |
| 5263 | { |
| 5264 | struct mwl8k_priv *priv = hw->priv; |
| 5265 | struct ieee80211_conf *conf = &hw->conf; |
| 5266 | |
| 5267 | if (idx != 0) |
| 5268 | return -ENOENT; |
| 5269 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 5270 | survey->channel = conf->chandef.chan; |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 5271 | survey->filled = SURVEY_INFO_NOISE_DBM; |
| 5272 | survey->noise = priv->noise; |
| 5273 | |
| 5274 | return 0; |
| 5275 | } |
| 5276 | |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5277 | #define MAX_AMPDU_ATTEMPTS 5 |
| 5278 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5279 | static int |
| 5280 | mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5281 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 5282 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 5283 | u8 buf_size) |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5284 | { |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5285 | |
| 5286 | int i, rc = 0; |
| 5287 | struct mwl8k_priv *priv = hw->priv; |
| 5288 | struct mwl8k_ampdu_stream *stream; |
Yogesh Ashok Powar | 07f6dda | 2013-01-03 13:23:33 +0530 | [diff] [blame] | 5289 | u8 *addr = sta->addr, idx; |
Yogesh Ashok Powar | fd712f5 | 2012-11-06 19:22:35 +0530 | [diff] [blame] | 5290 | struct mwl8k_sta *sta_info = MWL8K_STA(sta); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5291 | |
| 5292 | if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION)) |
| 5293 | return -ENOTSUPP; |
| 5294 | |
| 5295 | spin_lock(&priv->stream_lock); |
| 5296 | stream = mwl8k_lookup_stream(hw, addr, tid); |
| 5297 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5298 | switch (action) { |
| 5299 | case IEEE80211_AMPDU_RX_START: |
| 5300 | case IEEE80211_AMPDU_RX_STOP: |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5301 | break; |
| 5302 | case IEEE80211_AMPDU_TX_START: |
| 5303 | /* By the time we get here the hw queues may contain outgoing |
| 5304 | * packets for this RA/TID that are not part of this BA |
| 5305 | * session. The hw will assign sequence numbers to these |
| 5306 | * packets as they go out. So if we query the hw for its next |
| 5307 | * sequence number and use that for the SSN here, it may end up |
| 5308 | * being wrong, which will lead to sequence number mismatch at |
| 5309 | * the recipient. To avoid this, we reset the sequence number |
| 5310 | * to O for the first MPDU in this BA stream. |
| 5311 | */ |
| 5312 | *ssn = 0; |
| 5313 | if (stream == NULL) { |
| 5314 | /* This means that somebody outside this driver called |
| 5315 | * ieee80211_start_tx_ba_session. This is unexpected |
| 5316 | * because we do our own rate control. Just warn and |
| 5317 | * move on. |
| 5318 | */ |
| 5319 | wiphy_warn(hw->wiphy, "Unexpected call to %s. " |
| 5320 | "Proceeding anyway.\n", __func__); |
| 5321 | stream = mwl8k_add_stream(hw, sta, tid); |
| 5322 | } |
| 5323 | if (stream == NULL) { |
| 5324 | wiphy_debug(hw->wiphy, "no free AMPDU streams\n"); |
| 5325 | rc = -EBUSY; |
| 5326 | break; |
| 5327 | } |
| 5328 | stream->state = AMPDU_STREAM_IN_PROGRESS; |
| 5329 | |
| 5330 | /* Release the lock before we do the time consuming stuff */ |
| 5331 | spin_unlock(&priv->stream_lock); |
| 5332 | for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) { |
Yogesh Ashok Powar | fd712f5 | 2012-11-06 19:22:35 +0530 | [diff] [blame] | 5333 | |
| 5334 | /* Check if link is still valid */ |
| 5335 | if (!sta_info->is_ampdu_allowed) { |
| 5336 | spin_lock(&priv->stream_lock); |
| 5337 | mwl8k_remove_stream(hw, stream); |
| 5338 | spin_unlock(&priv->stream_lock); |
| 5339 | return -EBUSY; |
| 5340 | } |
| 5341 | |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 5342 | rc = mwl8k_check_ba(hw, stream, vif); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5343 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5344 | /* If HW restart is in progress mwl8k_post_cmd will |
| 5345 | * return -EBUSY. Avoid retrying mwl8k_check_ba in |
| 5346 | * such cases |
| 5347 | */ |
| 5348 | if (!rc || rc == -EBUSY) |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5349 | break; |
| 5350 | /* |
| 5351 | * HW queues take time to be flushed, give them |
| 5352 | * sufficient time |
| 5353 | */ |
| 5354 | |
| 5355 | msleep(1000); |
| 5356 | } |
| 5357 | spin_lock(&priv->stream_lock); |
| 5358 | if (rc) { |
| 5359 | wiphy_err(hw->wiphy, "Stream for tid %d busy after %d" |
| 5360 | " attempts\n", tid, MAX_AMPDU_ATTEMPTS); |
| 5361 | mwl8k_remove_stream(hw, stream); |
| 5362 | rc = -EBUSY; |
| 5363 | break; |
| 5364 | } |
| 5365 | ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid); |
| 5366 | break; |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 5367 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 5368 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 5369 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Yogesh Ashok Powar | eca107f | 2011-12-20 11:37:08 +0530 | [diff] [blame] | 5370 | if (stream) { |
| 5371 | if (stream->state == AMPDU_STREAM_ACTIVE) { |
Yogesh Ashok Powar | 07f6dda | 2013-01-03 13:23:33 +0530 | [diff] [blame] | 5372 | idx = stream->idx; |
Yogesh Ashok Powar | eca107f | 2011-12-20 11:37:08 +0530 | [diff] [blame] | 5373 | spin_unlock(&priv->stream_lock); |
Yogesh Ashok Powar | 07f6dda | 2013-01-03 13:23:33 +0530 | [diff] [blame] | 5374 | mwl8k_destroy_ba(hw, idx); |
Yogesh Ashok Powar | eca107f | 2011-12-20 11:37:08 +0530 | [diff] [blame] | 5375 | spin_lock(&priv->stream_lock); |
| 5376 | } |
| 5377 | mwl8k_remove_stream(hw, stream); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5378 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5379 | ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid); |
| 5380 | break; |
| 5381 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 5382 | BUG_ON(stream == NULL); |
| 5383 | BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS); |
| 5384 | spin_unlock(&priv->stream_lock); |
Yogesh Ashok Powar | f95275c | 2012-11-08 19:10:44 +0530 | [diff] [blame] | 5385 | rc = mwl8k_create_ba(hw, stream, buf_size, vif); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5386 | spin_lock(&priv->stream_lock); |
| 5387 | if (!rc) |
| 5388 | stream->state = AMPDU_STREAM_ACTIVE; |
| 5389 | else { |
Yogesh Ashok Powar | 07f6dda | 2013-01-03 13:23:33 +0530 | [diff] [blame] | 5390 | idx = stream->idx; |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5391 | spin_unlock(&priv->stream_lock); |
Yogesh Ashok Powar | 07f6dda | 2013-01-03 13:23:33 +0530 | [diff] [blame] | 5392 | mwl8k_destroy_ba(hw, idx); |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5393 | spin_lock(&priv->stream_lock); |
| 5394 | wiphy_debug(hw->wiphy, |
| 5395 | "Failed adding stream for sta %pM tid %d\n", |
| 5396 | addr, tid); |
| 5397 | mwl8k_remove_stream(hw, stream); |
| 5398 | } |
| 5399 | break; |
| 5400 | |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5401 | default: |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5402 | rc = -ENOTSUPP; |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5403 | } |
Nishant Sarmukadam | 65f3ddc | 2011-03-17 11:58:46 -0700 | [diff] [blame] | 5404 | |
| 5405 | spin_unlock(&priv->stream_lock); |
| 5406 | return rc; |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5407 | } |
| 5408 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5409 | static const struct ieee80211_ops mwl8k_ops = { |
| 5410 | .tx = mwl8k_tx, |
| 5411 | .start = mwl8k_start, |
| 5412 | .stop = mwl8k_stop, |
| 5413 | .add_interface = mwl8k_add_interface, |
| 5414 | .remove_interface = mwl8k_remove_interface, |
| 5415 | .config = mwl8k_config, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5416 | .bss_info_changed = mwl8k_bss_info_changed, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 5417 | .prepare_multicast = mwl8k_prepare_multicast, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5418 | .configure_filter = mwl8k_configure_filter, |
Nishant Sarmukadam | fcdc403 | 2010-12-30 11:23:34 -0800 | [diff] [blame] | 5419 | .set_key = mwl8k_set_key, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5420 | .set_rts_threshold = mwl8k_set_rts_threshold, |
Johannes Berg | 4a6967b | 2010-02-19 19:18:37 +0100 | [diff] [blame] | 5421 | .sta_add = mwl8k_sta_add, |
| 5422 | .sta_remove = mwl8k_sta_remove, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5423 | .conf_tx = mwl8k_conf_tx, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5424 | .get_stats = mwl8k_get_stats, |
John W. Linville | 0d462bb | 2010-07-28 14:04:24 -0400 | [diff] [blame] | 5425 | .get_survey = mwl8k_get_survey, |
Lennert Buytenhek | a2292d8 | 2010-01-04 21:58:12 +0100 | [diff] [blame] | 5426 | .ampdu_action = mwl8k_ampdu_action, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5427 | }; |
| 5428 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5429 | static void mwl8k_finalize_join_worker(struct work_struct *work) |
| 5430 | { |
| 5431 | struct mwl8k_priv *priv = |
| 5432 | container_of(work, struct mwl8k_priv, finalize_join_worker); |
| 5433 | struct sk_buff *skb = priv->beacon_skb; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 5434 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 5435 | int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable); |
| 5436 | const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM, |
| 5437 | mgmt->u.beacon.variable, len); |
| 5438 | int dtim_period = 1; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5439 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 5440 | if (tim && tim[1] >= 2) |
| 5441 | dtim_period = tim[3]; |
| 5442 | |
| 5443 | mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period); |
Lennert Buytenhek | f5bb87c | 2010-01-12 13:49:51 +0100 | [diff] [blame] | 5444 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5445 | dev_kfree_skb(skb); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5446 | priv->beacon_skb = NULL; |
| 5447 | } |
| 5448 | |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5449 | enum { |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5450 | MWL8363 = 0, |
| 5451 | MWL8687, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5452 | MWL8366, |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 5453 | MWL8764, |
Lennert Buytenhek | 6f6d1e9 | 2009-10-22 20:21:48 +0200 | [diff] [blame] | 5454 | }; |
| 5455 | |
Yogesh Ashok Powar | c2f2e20 | 2013-01-03 13:24:44 +0530 | [diff] [blame] | 5456 | #define MWL8K_8366_AP_FW_API 3 |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5457 | #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw" |
| 5458 | #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api) |
| 5459 | |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 5460 | #define MWL8K_8764_AP_FW_API 1 |
| 5461 | #define _MWL8K_8764_AP_FW(api) "mwl8k/fmimage_8764_ap-" #api ".fw" |
| 5462 | #define MWL8K_8764_AP_FW(api) _MWL8K_8764_AP_FW(api) |
| 5463 | |
Bill Pemberton | 8dee5ee | 2012-12-03 09:56:36 -0500 | [diff] [blame] | 5464 | static struct mwl8k_device_info mwl8k_info_tbl[] = { |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5465 | [MWL8363] = { |
| 5466 | .part_name = "88w8363", |
| 5467 | .helper_image = "mwl8k/helper_8363.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5468 | .fw_image_sta = "mwl8k/fmimage_8363.fw", |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5469 | }, |
Lennert Buytenhek | 49eb691 | 2009-11-30 18:32:13 +0100 | [diff] [blame] | 5470 | [MWL8687] = { |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5471 | .part_name = "88w8687", |
| 5472 | .helper_image = "mwl8k/helper_8687.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5473 | .fw_image_sta = "mwl8k/fmimage_8687.fw", |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5474 | }, |
Lennert Buytenhek | 49eb691 | 2009-11-30 18:32:13 +0100 | [diff] [blame] | 5475 | [MWL8366] = { |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5476 | .part_name = "88w8366", |
| 5477 | .helper_image = "mwl8k/helper_8366.fw", |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5478 | .fw_image_sta = "mwl8k/fmimage_8366.fw", |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5479 | .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API), |
| 5480 | .fw_api_ap = MWL8K_8366_AP_FW_API, |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 5481 | .ap_rxd_ops = &rxd_ap_ops, |
| 5482 | }, |
| 5483 | [MWL8764] = { |
| 5484 | .part_name = "88w8764", |
| 5485 | .fw_image_ap = MWL8K_8764_AP_FW(MWL8K_8764_AP_FW_API), |
| 5486 | .fw_api_ap = MWL8K_8764_AP_FW_API, |
| 5487 | .ap_rxd_ops = &rxd_ap_ops, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5488 | }, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5489 | }; |
| 5490 | |
Lennert Buytenhek | c92d4ed | 2010-01-12 13:47:22 +0100 | [diff] [blame] | 5491 | MODULE_FIRMWARE("mwl8k/helper_8363.fw"); |
| 5492 | MODULE_FIRMWARE("mwl8k/fmimage_8363.fw"); |
| 5493 | MODULE_FIRMWARE("mwl8k/helper_8687.fw"); |
| 5494 | MODULE_FIRMWARE("mwl8k/fmimage_8687.fw"); |
| 5495 | MODULE_FIRMWARE("mwl8k/helper_8366.fw"); |
| 5496 | MODULE_FIRMWARE("mwl8k/fmimage_8366.fw"); |
Brian Cavagnolo | 952a0e9 | 2010-11-12 17:23:51 -0800 | [diff] [blame] | 5497 | MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API)); |
Lennert Buytenhek | c92d4ed | 2010-01-12 13:47:22 +0100 | [diff] [blame] | 5498 | |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5499 | static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = { |
Benjamin Larsson | e5868ba | 2010-03-19 01:46:10 +0100 | [diff] [blame] | 5500 | { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, }, |
Lennert Buytenhek | 9e1b17e | 2010-01-04 21:56:19 +0100 | [diff] [blame] | 5501 | { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, }, |
| 5502 | { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, }, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5503 | { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, }, |
| 5504 | { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, }, |
| 5505 | { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, }, |
Jonas Gorski | fc5bc16 | 2013-02-05 16:59:17 +0100 | [diff] [blame] | 5506 | { PCI_VDEVICE(MARVELL, 0x2a41), .driver_data = MWL8366, }, |
| 5507 | { PCI_VDEVICE(MARVELL, 0x2a42), .driver_data = MWL8366, }, |
Lennert Buytenhek | ca66527 | 2010-01-12 13:47:53 +0100 | [diff] [blame] | 5508 | { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, }, |
Nishant Sarmukadam | d926dc7 | 2013-03-01 17:12:45 +0530 | [diff] [blame] | 5509 | { PCI_VDEVICE(MARVELL, 0x2b36), .driver_data = MWL8764, }, |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 5510 | { }, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 5511 | }; |
| 5512 | MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table); |
| 5513 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5514 | static int mwl8k_request_alt_fw(struct mwl8k_priv *priv) |
| 5515 | { |
| 5516 | int rc; |
| 5517 | printk(KERN_ERR "%s: Error requesting preferred fw %s.\n" |
| 5518 | "Trying alternative firmware %s\n", pci_name(priv->pdev), |
| 5519 | priv->fw_pref, priv->fw_alt); |
| 5520 | rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true); |
| 5521 | if (rc) { |
| 5522 | printk(KERN_ERR "%s: Error requesting alt fw %s\n", |
| 5523 | pci_name(priv->pdev), priv->fw_alt); |
| 5524 | return rc; |
| 5525 | } |
| 5526 | return 0; |
| 5527 | } |
| 5528 | |
| 5529 | static int mwl8k_firmware_load_success(struct mwl8k_priv *priv); |
| 5530 | static void mwl8k_fw_state_machine(const struct firmware *fw, void *context) |
| 5531 | { |
| 5532 | struct mwl8k_priv *priv = context; |
| 5533 | struct mwl8k_device_info *di = priv->device_info; |
| 5534 | int rc; |
| 5535 | |
| 5536 | switch (priv->fw_state) { |
| 5537 | case FW_STATE_INIT: |
| 5538 | if (!fw) { |
| 5539 | printk(KERN_ERR "%s: Error requesting helper fw %s\n", |
| 5540 | pci_name(priv->pdev), di->helper_image); |
| 5541 | goto fail; |
| 5542 | } |
| 5543 | priv->fw_helper = fw; |
| 5544 | rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode, |
| 5545 | true); |
| 5546 | if (rc && priv->fw_alt) { |
| 5547 | rc = mwl8k_request_alt_fw(priv); |
| 5548 | if (rc) |
| 5549 | goto fail; |
| 5550 | priv->fw_state = FW_STATE_LOADING_ALT; |
| 5551 | } else if (rc) |
| 5552 | goto fail; |
| 5553 | else |
| 5554 | priv->fw_state = FW_STATE_LOADING_PREF; |
| 5555 | break; |
| 5556 | |
| 5557 | case FW_STATE_LOADING_PREF: |
| 5558 | if (!fw) { |
| 5559 | if (priv->fw_alt) { |
| 5560 | rc = mwl8k_request_alt_fw(priv); |
| 5561 | if (rc) |
| 5562 | goto fail; |
| 5563 | priv->fw_state = FW_STATE_LOADING_ALT; |
| 5564 | } else |
| 5565 | goto fail; |
| 5566 | } else { |
| 5567 | priv->fw_ucode = fw; |
| 5568 | rc = mwl8k_firmware_load_success(priv); |
| 5569 | if (rc) |
| 5570 | goto fail; |
| 5571 | else |
| 5572 | complete(&priv->firmware_loading_complete); |
| 5573 | } |
| 5574 | break; |
| 5575 | |
| 5576 | case FW_STATE_LOADING_ALT: |
| 5577 | if (!fw) { |
| 5578 | printk(KERN_ERR "%s: Error requesting alt fw %s\n", |
| 5579 | pci_name(priv->pdev), di->helper_image); |
| 5580 | goto fail; |
| 5581 | } |
| 5582 | priv->fw_ucode = fw; |
| 5583 | rc = mwl8k_firmware_load_success(priv); |
| 5584 | if (rc) |
| 5585 | goto fail; |
| 5586 | else |
| 5587 | complete(&priv->firmware_loading_complete); |
| 5588 | break; |
| 5589 | |
| 5590 | default: |
| 5591 | printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n", |
| 5592 | MWL8K_NAME, priv->fw_state); |
| 5593 | BUG_ON(1); |
| 5594 | } |
| 5595 | |
| 5596 | return; |
| 5597 | |
| 5598 | fail: |
| 5599 | priv->fw_state = FW_STATE_ERROR; |
| 5600 | complete(&priv->firmware_loading_complete); |
| 5601 | device_release_driver(&priv->pdev->dev); |
| 5602 | mwl8k_release_firmware(priv); |
| 5603 | } |
| 5604 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5605 | #define MAX_RESTART_ATTEMPTS 1 |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5606 | static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image, |
| 5607 | bool nowait) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5608 | { |
| 5609 | struct mwl8k_priv *priv = hw->priv; |
| 5610 | int rc; |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5611 | int count = MAX_RESTART_ATTEMPTS; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5612 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5613 | retry: |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5614 | /* Reset firmware and hardware */ |
| 5615 | mwl8k_hw_reset(priv); |
| 5616 | |
| 5617 | /* Ask userland hotplug daemon for the device firmware */ |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5618 | rc = mwl8k_request_firmware(priv, fw_image, nowait); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5619 | if (rc) { |
| 5620 | wiphy_err(hw->wiphy, "Firmware files not found\n"); |
| 5621 | return rc; |
| 5622 | } |
| 5623 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5624 | if (nowait) |
| 5625 | return rc; |
| 5626 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5627 | /* Load firmware into hardware */ |
| 5628 | rc = mwl8k_load_firmware(hw); |
| 5629 | if (rc) |
| 5630 | wiphy_err(hw->wiphy, "Cannot start firmware\n"); |
| 5631 | |
| 5632 | /* Reclaim memory once firmware is successfully loaded */ |
| 5633 | mwl8k_release_firmware(priv); |
| 5634 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5635 | if (rc && count) { |
| 5636 | /* FW did not start successfully; |
| 5637 | * lets try one more time |
| 5638 | */ |
| 5639 | count--; |
| 5640 | wiphy_err(hw->wiphy, "Trying to reload the firmware again\n"); |
| 5641 | msleep(20); |
| 5642 | goto retry; |
| 5643 | } |
| 5644 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5645 | return rc; |
| 5646 | } |
| 5647 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5648 | static int mwl8k_init_txqs(struct ieee80211_hw *hw) |
| 5649 | { |
| 5650 | struct mwl8k_priv *priv = hw->priv; |
| 5651 | int rc = 0; |
| 5652 | int i; |
| 5653 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5654 | for (i = 0; i < mwl8k_tx_queues(priv); i++) { |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5655 | rc = mwl8k_txq_init(hw, i); |
| 5656 | if (rc) |
| 5657 | break; |
| 5658 | if (priv->ap_fw) |
| 5659 | iowrite32(priv->txq[i].txd_dma, |
| 5660 | priv->sram + priv->txq_offset[i]); |
| 5661 | } |
| 5662 | return rc; |
| 5663 | } |
| 5664 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5665 | /* initialize hw after successfully loading a firmware image */ |
| 5666 | static int mwl8k_probe_hw(struct ieee80211_hw *hw) |
| 5667 | { |
| 5668 | struct mwl8k_priv *priv = hw->priv; |
| 5669 | int rc = 0; |
| 5670 | int i; |
| 5671 | |
| 5672 | if (priv->ap_fw) { |
| 5673 | priv->rxd_ops = priv->device_info->ap_rxd_ops; |
| 5674 | if (priv->rxd_ops == NULL) { |
| 5675 | wiphy_err(hw->wiphy, |
| 5676 | "Driver does not have AP firmware image support for this hardware\n"); |
Alexey Khoroshilov | a2ca8ec | 2013-01-19 01:24:01 +0400 | [diff] [blame] | 5677 | rc = -ENOENT; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5678 | goto err_stop_firmware; |
| 5679 | } |
| 5680 | } else { |
| 5681 | priv->rxd_ops = &rxd_sta_ops; |
| 5682 | } |
| 5683 | |
| 5684 | priv->sniffer_enabled = false; |
| 5685 | priv->wmm_enabled = false; |
| 5686 | priv->pending_tx_pkts = 0; |
Yogesh Ashok Powar | c27a54d | 2013-01-03 13:24:19 +0530 | [diff] [blame] | 5687 | atomic_set(&priv->watchdog_event_pending, 0); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5688 | |
| 5689 | rc = mwl8k_rxq_init(hw, 0); |
| 5690 | if (rc) |
| 5691 | goto err_stop_firmware; |
| 5692 | rxq_refill(hw, 0, INT_MAX); |
| 5693 | |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5694 | /* For the sta firmware, we need to know the dma addresses of tx queues |
| 5695 | * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them |
| 5696 | * prior to issuing this command. But for the AP case, we learn the |
| 5697 | * total number of queues from the result CMD_GET_HW_SPEC, so for this |
| 5698 | * case we must initialize the tx queues after. |
| 5699 | */ |
Brian Cavagnolo | 8a7a578 | 2011-03-17 11:58:42 -0700 | [diff] [blame] | 5700 | priv->num_ampdu_queues = 0; |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5701 | if (!priv->ap_fw) { |
| 5702 | rc = mwl8k_init_txqs(hw); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5703 | if (rc) |
| 5704 | goto err_free_queues; |
| 5705 | } |
| 5706 | |
| 5707 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS); |
| 5708 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 5709 | iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY| |
| 5710 | MWL8K_A2H_INT_BA_WATCHDOG, |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5711 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL); |
Nishant Sarmukadam | 12488e0 | 2011-04-08 14:38:27 +0530 | [diff] [blame] | 5712 | iowrite32(MWL8K_A2H_INT_OPC_DONE, |
| 5713 | priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5714 | |
| 5715 | rc = request_irq(priv->pdev->irq, mwl8k_interrupt, |
| 5716 | IRQF_SHARED, MWL8K_NAME, hw); |
| 5717 | if (rc) { |
| 5718 | wiphy_err(hw->wiphy, "failed to register IRQ handler\n"); |
| 5719 | goto err_free_queues; |
| 5720 | } |
| 5721 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5722 | /* |
| 5723 | * When hw restart is requested, |
| 5724 | * mac80211 will take care of clearing |
| 5725 | * the ampdu streams, so do not clear |
| 5726 | * the ampdu state here |
| 5727 | */ |
| 5728 | if (!priv->hw_restart_in_progress) |
| 5729 | memset(priv->ampdu, 0, sizeof(priv->ampdu)); |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 5730 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5731 | /* |
| 5732 | * Temporarily enable interrupts. Initial firmware host |
| 5733 | * commands use interrupts and avoid polling. Disable |
| 5734 | * interrupts when done. |
| 5735 | */ |
| 5736 | iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5737 | |
| 5738 | /* Get config data, mac addrs etc */ |
| 5739 | if (priv->ap_fw) { |
| 5740 | rc = mwl8k_cmd_get_hw_spec_ap(hw); |
| 5741 | if (!rc) |
Brian Cavagnolo | 73b4632 | 2011-03-17 11:58:41 -0700 | [diff] [blame] | 5742 | rc = mwl8k_init_txqs(hw); |
| 5743 | if (!rc) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5744 | rc = mwl8k_cmd_set_hw_spec(hw); |
| 5745 | } else { |
| 5746 | rc = mwl8k_cmd_get_hw_spec_sta(hw); |
| 5747 | } |
| 5748 | if (rc) { |
| 5749 | wiphy_err(hw->wiphy, "Cannot initialise firmware\n"); |
| 5750 | goto err_free_irq; |
| 5751 | } |
| 5752 | |
| 5753 | /* Turn radio off */ |
| 5754 | rc = mwl8k_cmd_radio_disable(hw); |
| 5755 | if (rc) { |
| 5756 | wiphy_err(hw->wiphy, "Cannot disable\n"); |
| 5757 | goto err_free_irq; |
| 5758 | } |
| 5759 | |
| 5760 | /* Clear MAC address */ |
| 5761 | rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00"); |
| 5762 | if (rc) { |
| 5763 | wiphy_err(hw->wiphy, "Cannot clear MAC address\n"); |
| 5764 | goto err_free_irq; |
| 5765 | } |
| 5766 | |
Yogesh Ashok Powar | a246ac3 | 2013-01-25 16:17:56 +0530 | [diff] [blame] | 5767 | /* Configure Antennas */ |
| 5768 | rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3); |
| 5769 | if (rc) |
| 5770 | wiphy_warn(hw->wiphy, "failed to set # of RX antennas"); |
| 5771 | rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7); |
| 5772 | if (rc) |
| 5773 | wiphy_warn(hw->wiphy, "failed to set # of TX antennas"); |
| 5774 | |
| 5775 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5776 | /* Disable interrupts */ |
| 5777 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5778 | free_irq(priv->pdev->irq, hw); |
| 5779 | |
| 5780 | wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n", |
| 5781 | priv->device_info->part_name, |
| 5782 | priv->hw_rev, hw->wiphy->perm_addr, |
| 5783 | priv->ap_fw ? "AP" : "STA", |
| 5784 | (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff, |
| 5785 | (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff); |
| 5786 | |
| 5787 | return 0; |
| 5788 | |
| 5789 | err_free_irq: |
| 5790 | iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK); |
| 5791 | free_irq(priv->pdev->irq, hw); |
| 5792 | |
| 5793 | err_free_queues: |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5794 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5795 | mwl8k_txq_deinit(hw, i); |
| 5796 | mwl8k_rxq_deinit(hw, 0); |
| 5797 | |
| 5798 | err_stop_firmware: |
| 5799 | mwl8k_hw_reset(priv); |
| 5800 | |
| 5801 | return rc; |
| 5802 | } |
| 5803 | |
| 5804 | /* |
| 5805 | * invoke mwl8k_reload_firmware to change the firmware image after the device |
| 5806 | * has already been registered |
| 5807 | */ |
| 5808 | static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image) |
| 5809 | { |
| 5810 | int i, rc = 0; |
| 5811 | struct mwl8k_priv *priv = hw->priv; |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5812 | struct mwl8k_vif *vif, *tmp_vif; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5813 | |
| 5814 | mwl8k_stop(hw); |
| 5815 | mwl8k_rxq_deinit(hw, 0); |
| 5816 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5817 | /* |
| 5818 | * All the existing interfaces are re-added by the ieee80211_reconfig; |
| 5819 | * which means driver should remove existing interfaces before calling |
| 5820 | * ieee80211_restart_hw |
| 5821 | */ |
| 5822 | if (priv->hw_restart_in_progress) |
| 5823 | list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list) |
| 5824 | mwl8k_remove_vif(priv, vif); |
| 5825 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5826 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5827 | mwl8k_txq_deinit(hw, i); |
| 5828 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5829 | rc = mwl8k_init_firmware(hw, fw_image, false); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5830 | if (rc) |
| 5831 | goto fail; |
| 5832 | |
| 5833 | rc = mwl8k_probe_hw(hw); |
| 5834 | if (rc) |
| 5835 | goto fail; |
| 5836 | |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5837 | if (priv->hw_restart_in_progress) |
| 5838 | return rc; |
| 5839 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5840 | rc = mwl8k_start(hw); |
| 5841 | if (rc) |
| 5842 | goto fail; |
| 5843 | |
| 5844 | rc = mwl8k_config(hw, ~0); |
| 5845 | if (rc) |
| 5846 | goto fail; |
| 5847 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5848 | for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) { |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 5849 | rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5850 | if (rc) |
| 5851 | goto fail; |
| 5852 | } |
| 5853 | |
| 5854 | return rc; |
| 5855 | |
| 5856 | fail: |
| 5857 | printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n"); |
| 5858 | return rc; |
| 5859 | } |
| 5860 | |
Yogesh Ashok Powar | 5d377fc | 2012-11-06 19:22:16 +0530 | [diff] [blame] | 5861 | static const struct ieee80211_iface_limit ap_if_limits[] = { |
| 5862 | { .max = 8, .types = BIT(NL80211_IFTYPE_AP) }, |
Yogesh Ashok Powar | 2acdaa7 | 2013-01-25 16:19:55 +0530 | [diff] [blame] | 5863 | { .max = 1, .types = BIT(NL80211_IFTYPE_STATION) }, |
Yogesh Ashok Powar | 5d377fc | 2012-11-06 19:22:16 +0530 | [diff] [blame] | 5864 | }; |
| 5865 | |
| 5866 | static const struct ieee80211_iface_combination ap_if_comb = { |
| 5867 | .limits = ap_if_limits, |
| 5868 | .n_limits = ARRAY_SIZE(ap_if_limits), |
| 5869 | .max_interfaces = 8, |
| 5870 | .num_different_channels = 1, |
| 5871 | }; |
| 5872 | |
| 5873 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5874 | static int mwl8k_firmware_load_success(struct mwl8k_priv *priv) |
| 5875 | { |
| 5876 | struct ieee80211_hw *hw = priv->hw; |
| 5877 | int i, rc; |
| 5878 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 5879 | rc = mwl8k_load_firmware(hw); |
| 5880 | mwl8k_release_firmware(priv); |
| 5881 | if (rc) { |
| 5882 | wiphy_err(hw->wiphy, "Cannot start firmware\n"); |
| 5883 | return rc; |
| 5884 | } |
| 5885 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5886 | /* |
| 5887 | * Extra headroom is the size of the required DMA header |
| 5888 | * minus the size of the smallest 802.11 frame (CTS frame). |
| 5889 | */ |
| 5890 | hw->extra_tx_headroom = |
| 5891 | sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts); |
| 5892 | |
Yogesh Ashok Powar | ff776ce | 2011-04-28 17:34:48 +0530 | [diff] [blame] | 5893 | hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0; |
| 5894 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5895 | hw->queues = MWL8K_TX_WMM_QUEUES; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5896 | |
| 5897 | /* Set rssi values to dBm */ |
Nishant Sarmukadam | 0bf22c3 | 2011-02-17 14:45:17 -0800 | [diff] [blame] | 5898 | hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL; |
Yogesh Ashok Powar | 2a36a0e | 2011-08-29 17:12:44 +0530 | [diff] [blame] | 5899 | |
| 5900 | /* |
| 5901 | * Ask mac80211 to not to trigger PS mode |
| 5902 | * based on PM bit of incoming frames. |
| 5903 | */ |
| 5904 | if (priv->ap_fw) |
| 5905 | hw->flags |= IEEE80211_HW_AP_LINK_PS; |
| 5906 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5907 | hw->vif_data_size = sizeof(struct mwl8k_vif); |
| 5908 | hw->sta_data_size = sizeof(struct mwl8k_sta); |
| 5909 | |
| 5910 | priv->macids_used = 0; |
| 5911 | INIT_LIST_HEAD(&priv->vif_list); |
| 5912 | |
| 5913 | /* Set default radio state and preamble */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5914 | priv->radio_on = false; |
| 5915 | priv->radio_short_preamble = false; |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5916 | |
| 5917 | /* Finalize join worker */ |
| 5918 | INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker); |
Nishant Sarmukadam | 3aefc37 | 2011-03-17 11:58:47 -0700 | [diff] [blame] | 5919 | /* Handle watchdog ba events */ |
| 5920 | INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events); |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 5921 | /* To reload the firmware if it crashes */ |
| 5922 | INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work); |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5923 | |
| 5924 | /* TX reclaim and RX tasklets. */ |
| 5925 | tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw); |
| 5926 | tasklet_disable(&priv->poll_tx_task); |
| 5927 | tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw); |
| 5928 | tasklet_disable(&priv->poll_rx_task); |
| 5929 | |
| 5930 | /* Power management cookie */ |
| 5931 | priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma); |
| 5932 | if (priv->cookie == NULL) |
| 5933 | return -ENOMEM; |
| 5934 | |
| 5935 | mutex_init(&priv->fw_mutex); |
| 5936 | priv->fw_mutex_owner = NULL; |
| 5937 | priv->fw_mutex_depth = 0; |
| 5938 | priv->hostcmd_wait = NULL; |
| 5939 | |
| 5940 | spin_lock_init(&priv->tx_lock); |
| 5941 | |
Brian Cavagnolo | ac109fd | 2011-03-17 11:58:45 -0700 | [diff] [blame] | 5942 | spin_lock_init(&priv->stream_lock); |
| 5943 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5944 | priv->tx_wait = NULL; |
| 5945 | |
| 5946 | rc = mwl8k_probe_hw(hw); |
| 5947 | if (rc) |
| 5948 | goto err_free_cookie; |
| 5949 | |
| 5950 | hw->wiphy->interface_modes = 0; |
Yogesh Ashok Powar | 5d377fc | 2012-11-06 19:22:16 +0530 | [diff] [blame] | 5951 | |
| 5952 | if (priv->ap_macids_supported || priv->device_info->fw_image_ap) { |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5953 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP); |
Yogesh Ashok Powar | 2acdaa7 | 2013-01-25 16:19:55 +0530 | [diff] [blame] | 5954 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION); |
Yogesh Ashok Powar | 5d377fc | 2012-11-06 19:22:16 +0530 | [diff] [blame] | 5955 | hw->wiphy->iface_combinations = &ap_if_comb; |
| 5956 | hw->wiphy->n_iface_combinations = 1; |
| 5957 | } |
| 5958 | |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5959 | if (priv->sta_macids_supported || priv->device_info->fw_image_sta) |
| 5960 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION); |
| 5961 | |
| 5962 | rc = ieee80211_register_hw(hw); |
| 5963 | if (rc) { |
| 5964 | wiphy_err(hw->wiphy, "Cannot register device\n"); |
| 5965 | goto err_unprobe_hw; |
| 5966 | } |
| 5967 | |
| 5968 | return 0; |
| 5969 | |
| 5970 | err_unprobe_hw: |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 5971 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5972 | mwl8k_txq_deinit(hw, i); |
| 5973 | mwl8k_rxq_deinit(hw, 0); |
| 5974 | |
| 5975 | err_free_cookie: |
| 5976 | if (priv->cookie != NULL) |
| 5977 | pci_free_consistent(priv->pdev, 4, |
| 5978 | priv->cookie, priv->cookie_dma); |
| 5979 | |
| 5980 | return rc; |
| 5981 | } |
Bill Pemberton | 8dee5ee | 2012-12-03 09:56:36 -0500 | [diff] [blame] | 5982 | static int mwl8k_probe(struct pci_dev *pdev, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5983 | const struct pci_device_id *id) |
| 5984 | { |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 5985 | static int printed_version; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5986 | struct ieee80211_hw *hw; |
| 5987 | struct mwl8k_priv *priv; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 5988 | struct mwl8k_device_info *di; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5989 | int rc; |
Lennert Buytenhek | 2aa7b01 | 2009-08-24 15:48:07 +0200 | [diff] [blame] | 5990 | |
| 5991 | if (!printed_version) { |
| 5992 | printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION); |
| 5993 | printed_version = 1; |
| 5994 | } |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5995 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 5996 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 5997 | rc = pci_enable_device(pdev); |
| 5998 | if (rc) { |
| 5999 | printk(KERN_ERR "%s: Cannot enable new PCI device\n", |
| 6000 | MWL8K_NAME); |
| 6001 | return rc; |
| 6002 | } |
| 6003 | |
| 6004 | rc = pci_request_regions(pdev, MWL8K_NAME); |
| 6005 | if (rc) { |
| 6006 | printk(KERN_ERR "%s: Cannot obtain PCI resources\n", |
| 6007 | MWL8K_NAME); |
Lennert Buytenhek | 3db95e5 | 2009-11-30 18:13:34 +0100 | [diff] [blame] | 6008 | goto err_disable_device; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | pci_set_master(pdev); |
| 6012 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 6013 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6014 | hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops); |
| 6015 | if (hw == NULL) { |
| 6016 | printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME); |
| 6017 | rc = -ENOMEM; |
| 6018 | goto err_free_reg; |
| 6019 | } |
| 6020 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 6021 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 6022 | pci_set_drvdata(pdev, hw); |
| 6023 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6024 | priv = hw->priv; |
| 6025 | priv->hw = hw; |
| 6026 | priv->pdev = pdev; |
John W. Linville | bcb628d | 2009-11-06 16:40:16 -0500 | [diff] [blame] | 6027 | priv->device_info = &mwl8k_info_tbl[id->driver_data]; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6028 | |
Nishant Sarmukadam | 9892982 | 2013-03-01 17:13:01 +0530 | [diff] [blame] | 6029 | if (id->driver_data == MWL8764) |
| 6030 | priv->is_8764 = true; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6031 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 6032 | priv->sram = pci_iomap(pdev, 0, 0x10000); |
| 6033 | if (priv->sram == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 6034 | wiphy_err(hw->wiphy, "Cannot map device SRAM\n"); |
Alexey Khoroshilov | a2ca8ec | 2013-01-19 01:24:01 +0400 | [diff] [blame] | 6035 | rc = -EIO; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6036 | goto err_iounmap; |
| 6037 | } |
| 6038 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 6039 | /* |
| 6040 | * If BAR0 is a 32 bit BAR, the register BAR will be BAR1. |
| 6041 | * If BAR0 is a 64 bit BAR, the register BAR will be BAR2. |
| 6042 | */ |
| 6043 | priv->regs = pci_iomap(pdev, 1, 0x10000); |
| 6044 | if (priv->regs == NULL) { |
| 6045 | priv->regs = pci_iomap(pdev, 2, 0x10000); |
| 6046 | if (priv->regs == NULL) { |
Joe Perches | 5db5584 | 2010-08-11 19:11:19 -0700 | [diff] [blame] | 6047 | wiphy_err(hw->wiphy, "Cannot map device registers\n"); |
Alexey Khoroshilov | a2ca8ec | 2013-01-19 01:24:01 +0400 | [diff] [blame] | 6048 | rc = -EIO; |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 6049 | goto err_iounmap; |
| 6050 | } |
| 6051 | } |
| 6052 | |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 6053 | /* |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 6054 | * Choose the initial fw image depending on user input. If a second |
| 6055 | * image is available, make it the alternative image that will be |
| 6056 | * loaded if the first one fails. |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 6057 | */ |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 6058 | init_completion(&priv->firmware_loading_complete); |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 6059 | di = priv->device_info; |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 6060 | if (ap_mode_default && di->fw_image_ap) { |
| 6061 | priv->fw_pref = di->fw_image_ap; |
| 6062 | priv->fw_alt = di->fw_image_sta; |
| 6063 | } else if (!ap_mode_default && di->fw_image_sta) { |
| 6064 | priv->fw_pref = di->fw_image_sta; |
| 6065 | priv->fw_alt = di->fw_image_ap; |
| 6066 | } 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] | 6067 | printk(KERN_WARNING "AP fw is unavailable. Using STA fw."); |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 6068 | priv->fw_pref = di->fw_image_sta; |
Brian Cavagnolo | 0863ade | 2010-11-12 17:23:50 -0800 | [diff] [blame] | 6069 | } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) { |
| 6070 | printk(KERN_WARNING "STA fw is unavailable. Using AP fw."); |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 6071 | priv->fw_pref = di->fw_image_ap; |
| 6072 | } |
| 6073 | rc = mwl8k_init_firmware(hw, priv->fw_pref, true); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6074 | if (rc) |
Brian Cavagnolo | 3cc7772 | 2010-11-12 17:23:49 -0800 | [diff] [blame] | 6075 | goto err_stop_firmware; |
Yogesh Ashok Powar | 6b6accc | 2011-12-30 16:35:27 +0530 | [diff] [blame] | 6076 | |
| 6077 | priv->hw_restart_in_progress = false; |
| 6078 | |
Yogesh Ashok Powar | e882efc | 2013-01-25 16:17:32 +0530 | [diff] [blame] | 6079 | priv->running_bsses = 0; |
| 6080 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 6081 | return rc; |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6082 | |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 6083 | err_stop_firmware: |
| 6084 | mwl8k_hw_reset(priv); |
Lennert Buytenhek | be695fc | 2009-11-30 18:32:46 +0100 | [diff] [blame] | 6085 | |
| 6086 | err_iounmap: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6087 | if (priv->regs != NULL) |
| 6088 | pci_iounmap(pdev, priv->regs); |
| 6089 | |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 6090 | if (priv->sram != NULL) |
| 6091 | pci_iounmap(pdev, priv->sram); |
| 6092 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6093 | ieee80211_free_hw(hw); |
| 6094 | |
| 6095 | err_free_reg: |
| 6096 | pci_release_regions(pdev); |
Lennert Buytenhek | 3db95e5 | 2009-11-30 18:13:34 +0100 | [diff] [blame] | 6097 | |
| 6098 | err_disable_device: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6099 | pci_disable_device(pdev); |
| 6100 | |
| 6101 | return rc; |
| 6102 | } |
| 6103 | |
Bill Pemberton | 8dee5ee | 2012-12-03 09:56:36 -0500 | [diff] [blame] | 6104 | static void mwl8k_remove(struct pci_dev *pdev) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6105 | { |
| 6106 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 6107 | struct mwl8k_priv *priv; |
| 6108 | int i; |
| 6109 | |
| 6110 | if (hw == NULL) |
| 6111 | return; |
| 6112 | priv = hw->priv; |
| 6113 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 6114 | wait_for_completion(&priv->firmware_loading_complete); |
| 6115 | |
| 6116 | if (priv->fw_state == FW_STATE_ERROR) { |
| 6117 | mwl8k_hw_reset(priv); |
| 6118 | goto unmap; |
| 6119 | } |
| 6120 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6121 | ieee80211_stop_queues(hw); |
| 6122 | |
Lennert Buytenhek | 60aa569 | 2009-08-03 21:59:09 +0200 | [diff] [blame] | 6123 | ieee80211_unregister_hw(hw); |
| 6124 | |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 6125 | /* Remove TX reclaim and RX tasklets. */ |
Lennert Buytenhek | 1e9f9de3 | 2010-01-08 18:32:01 +0100 | [diff] [blame] | 6126 | tasklet_kill(&priv->poll_tx_task); |
Lennert Buytenhek | 67e2eb2 | 2010-01-08 18:32:18 +0100 | [diff] [blame] | 6127 | tasklet_kill(&priv->poll_rx_task); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6128 | |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6129 | /* Stop hardware */ |
| 6130 | mwl8k_hw_reset(priv); |
| 6131 | |
| 6132 | /* Return all skbs to mac80211 */ |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 6133 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | efb7c49 | 2010-01-08 18:31:47 +0100 | [diff] [blame] | 6134 | mwl8k_txq_reclaim(hw, i, INT_MAX, 1); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6135 | |
Brian Cavagnolo | e600707 | 2011-03-17 11:58:44 -0700 | [diff] [blame] | 6136 | for (i = 0; i < mwl8k_tx_queues(priv); i++) |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6137 | mwl8k_txq_deinit(hw, i); |
| 6138 | |
| 6139 | mwl8k_rxq_deinit(hw, 0); |
| 6140 | |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 6141 | pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6142 | |
Brian Cavagnolo | 9902047 | 2010-11-12 17:23:52 -0800 | [diff] [blame] | 6143 | unmap: |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6144 | pci_iounmap(pdev, priv->regs); |
Lennert Buytenhek | 5b9482d | 2009-10-22 20:20:43 +0200 | [diff] [blame] | 6145 | pci_iounmap(pdev, priv->sram); |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6146 | ieee80211_free_hw(hw); |
| 6147 | pci_release_regions(pdev); |
| 6148 | pci_disable_device(pdev); |
| 6149 | } |
| 6150 | |
| 6151 | static struct pci_driver mwl8k_driver = { |
| 6152 | .name = MWL8K_NAME, |
Lennert Buytenhek | 45a390d | 2009-10-22 20:20:47 +0200 | [diff] [blame] | 6153 | .id_table = mwl8k_pci_id_table, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6154 | .probe = mwl8k_probe, |
Bill Pemberton | 8dee5ee | 2012-12-03 09:56:36 -0500 | [diff] [blame] | 6155 | .remove = mwl8k_remove, |
Lennert Buytenhek | a66098d | 2009-03-10 10:13:33 +0100 | [diff] [blame] | 6156 | }; |
| 6157 | |
Axel Lin | 5b0a3b7 | 2012-04-14 10:38:36 +0800 | [diff] [blame] | 6158 | module_pci_driver(mwl8k_driver); |
Lennert Buytenhek | c2c357c | 2009-10-22 20:19:33 +0200 | [diff] [blame] | 6159 | |
| 6160 | MODULE_DESCRIPTION(MWL8K_DESC); |
| 6161 | MODULE_VERSION(MWL8K_VERSION); |
| 6162 | MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>"); |
| 6163 | MODULE_LICENSE("GPL"); |