Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: SDIO specific handling |
| 3 | * |
Xinming Hu | 65da33f | 2014-06-19 21:38:57 -0700 | [diff] [blame] | 4 | * Copyright (C) 2011-2014, Marvell International Ltd. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/firmware.h> |
| 21 | |
| 22 | #include "decl.h" |
| 23 | #include "ioctl.h" |
| 24 | #include "util.h" |
| 25 | #include "fw.h" |
| 26 | #include "main.h" |
| 27 | #include "wmm.h" |
| 28 | #include "11n.h" |
| 29 | #include "sdio.h" |
| 30 | |
| 31 | |
| 32 | #define SDIO_VERSION "1.0" |
| 33 | |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 34 | /* The mwifiex_sdio_remove() callback function is called when |
| 35 | * user removes this module from kernel space or ejects |
| 36 | * the card from the slot. The driver handles these 2 cases |
| 37 | * differently. |
| 38 | * If the user is removing the module, the few commands (FUNC_SHUTDOWN, |
| 39 | * HS_CANCEL etc.) are sent to the firmware. |
| 40 | * If the card is removed, there is no need to send these command. |
| 41 | * |
| 42 | * The variable 'user_rmmod' is used to distinguish these two |
| 43 | * scenarios. This flag is initialized as FALSE in case the card |
| 44 | * is removed, and will be set to TRUE for module removal when |
| 45 | * module_exit function is called. |
| 46 | */ |
| 47 | static u8 user_rmmod; |
| 48 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 49 | static struct mwifiex_if_ops sdio_ops; |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 50 | static unsigned long iface_work_flags; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 51 | |
| 52 | static struct semaphore add_remove_card_sem; |
| 53 | |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 54 | static struct memory_type_mapping generic_mem_type_map[] = { |
| 55 | {"DUMP", NULL, 0, 0xDD}, |
| 56 | }; |
| 57 | |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 58 | static struct memory_type_mapping mem_type_mapping_tbl[] = { |
| 59 | {"ITCM", NULL, 0, 0xF0}, |
| 60 | {"DTCM", NULL, 0, 0xF1}, |
| 61 | {"SQRAM", NULL, 0, 0xF2}, |
| 62 | {"APU", NULL, 0, 0xF3}, |
| 63 | {"CIU", NULL, 0, 0xF4}, |
| 64 | {"ICU", NULL, 0, 0xF5}, |
| 65 | {"MAC", NULL, 0, 0xF6}, |
| 66 | {"EXT7", NULL, 0, 0xF7}, |
| 67 | {"EXT8", NULL, 0, 0xF8}, |
| 68 | {"EXT9", NULL, 0, 0xF9}, |
| 69 | {"EXT10", NULL, 0, 0xFA}, |
| 70 | {"EXT11", NULL, 0, 0xFB}, |
| 71 | {"EXT12", NULL, 0, 0xFC}, |
| 72 | {"EXT13", NULL, 0, 0xFD}, |
| 73 | {"EXTLAST", NULL, 0, 0xFE}, |
| 74 | }; |
| 75 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 76 | /* |
| 77 | * SDIO probe. |
| 78 | * |
| 79 | * This function probes an mwifiex device and registers it. It allocates |
| 80 | * the card structure, enables SDIO function number and initiates the |
| 81 | * device registration and initialization procedure by adding a logical |
| 82 | * interface. |
| 83 | */ |
| 84 | static int |
| 85 | mwifiex_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id) |
| 86 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 87 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 88 | struct sdio_mmc_card *card = NULL; |
| 89 | |
| 90 | pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n", |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 91 | func->vendor, func->device, func->class, func->num); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 92 | |
| 93 | card = kzalloc(sizeof(struct sdio_mmc_card), GFP_KERNEL); |
Joe Perches | e404dec | 2012-01-29 12:56:23 +0000 | [diff] [blame] | 94 | if (!card) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 95 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 96 | |
| 97 | card->func = func; |
Andreas Fenkart | b4336a2 | 2015-07-16 18:50:01 +0200 | [diff] [blame] | 98 | card->device_id = id; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 99 | |
| 100 | func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; |
| 101 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 102 | if (id->driver_data) { |
| 103 | struct mwifiex_sdio_device *data = (void *)id->driver_data; |
| 104 | |
| 105 | card->firmware = data->firmware; |
| 106 | card->reg = data->reg; |
| 107 | card->max_ports = data->max_ports; |
| 108 | card->mp_agg_pkt_limit = data->mp_agg_pkt_limit; |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 109 | card->supports_sdio_new_mode = data->supports_sdio_new_mode; |
| 110 | card->has_control_mask = data->has_control_mask; |
Amitkumar Karwar | 828cf22 | 2014-02-27 19:35:13 -0800 | [diff] [blame] | 111 | card->tx_buf_size = data->tx_buf_size; |
Amitkumar Karwar | e1aa93a4 | 2014-04-14 15:32:50 -0700 | [diff] [blame] | 112 | card->mp_tx_agg_buf_size = data->mp_tx_agg_buf_size; |
| 113 | card->mp_rx_agg_buf_size = data->mp_rx_agg_buf_size; |
Avinash Patil | b4e8aeb | 2015-02-11 23:12:26 +0530 | [diff] [blame] | 114 | card->can_dump_fw = data->can_dump_fw; |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 115 | card->fw_dump_enh = data->fw_dump_enh; |
Avinash Patil | b4e8aeb | 2015-02-11 23:12:26 +0530 | [diff] [blame] | 116 | card->can_auto_tdls = data->can_auto_tdls; |
Avinash Patil | 1fe192d | 2015-01-23 17:09:19 +0530 | [diff] [blame] | 117 | card->can_ext_scan = data->can_ext_scan; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 120 | sdio_claim_host(func); |
| 121 | ret = sdio_enable_func(func); |
| 122 | sdio_release_host(func); |
| 123 | |
| 124 | if (ret) { |
| 125 | pr_err("%s: failed to enable function\n", __func__); |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 126 | kfree(card); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 127 | return -EIO; |
| 128 | } |
| 129 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 130 | if (mwifiex_add_card(card, &add_remove_card_sem, &sdio_ops, |
| 131 | MWIFIEX_SDIO)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 132 | pr_err("%s: add card failed\n", __func__); |
| 133 | kfree(card); |
| 134 | sdio_claim_host(func); |
| 135 | ret = sdio_disable_func(func); |
| 136 | sdio_release_host(func); |
| 137 | ret = -1; |
| 138 | } |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | /* |
Amitkumar Karwar | 2cdf359 | 2013-07-22 19:17:56 -0700 | [diff] [blame] | 144 | * SDIO resume. |
| 145 | * |
| 146 | * Kernel needs to suspend all functions separately. Therefore all |
| 147 | * registered functions must have drivers with suspend and resume |
| 148 | * methods. Failing that the kernel simply removes the whole card. |
| 149 | * |
| 150 | * If already not resumed, this function turns on the traffic and |
| 151 | * sends a host sleep cancel request to the firmware. |
| 152 | */ |
| 153 | static int mwifiex_sdio_resume(struct device *dev) |
| 154 | { |
| 155 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 156 | struct sdio_mmc_card *card; |
| 157 | struct mwifiex_adapter *adapter; |
| 158 | mmc_pm_flag_t pm_flag = 0; |
| 159 | |
| 160 | if (func) { |
| 161 | pm_flag = sdio_get_host_pm_caps(func); |
| 162 | card = sdio_get_drvdata(func); |
| 163 | if (!card || !card->adapter) { |
| 164 | pr_err("resume: invalid card or adapter\n"); |
| 165 | return 0; |
| 166 | } |
| 167 | } else { |
| 168 | pr_err("resume: sdio_func is not specified\n"); |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | adapter = card->adapter; |
| 173 | |
| 174 | if (!adapter->is_suspended) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 175 | mwifiex_dbg(adapter, WARN, |
| 176 | "device already resumed\n"); |
Amitkumar Karwar | 2cdf359 | 2013-07-22 19:17:56 -0700 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | adapter->is_suspended = false; |
| 181 | |
| 182 | /* Disable Host Sleep */ |
| 183 | mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA), |
| 184 | MWIFIEX_ASYNC_CMD); |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 190 | * SDIO remove. |
| 191 | * |
| 192 | * This function removes the interface and frees up the card structure. |
| 193 | */ |
| 194 | static void |
| 195 | mwifiex_sdio_remove(struct sdio_func *func) |
| 196 | { |
| 197 | struct sdio_mmc_card *card; |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 198 | struct mwifiex_adapter *adapter; |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 199 | struct mwifiex_private *priv; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 200 | |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 201 | card = sdio_get_drvdata(func); |
| 202 | if (!card) |
| 203 | return; |
| 204 | |
| 205 | adapter = card->adapter; |
| 206 | if (!adapter || !adapter->priv_num) |
| 207 | return; |
| 208 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 209 | mwifiex_dbg(adapter, INFO, "info: SDIO func num=%d\n", func->num); |
| 210 | |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 211 | if (user_rmmod) { |
| 212 | if (adapter->is_suspended) |
| 213 | mwifiex_sdio_resume(adapter->dev); |
| 214 | |
Amitkumar Karwar | 848819f | 2014-02-27 19:35:17 -0800 | [diff] [blame] | 215 | mwifiex_deauthenticate_all(adapter); |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 216 | |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 217 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 218 | mwifiex_disable_auto_ds(priv); |
| 219 | mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 220 | } |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 221 | |
| 222 | mwifiex_remove_card(card->adapter, &add_remove_card_sem); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* |
| 226 | * SDIO suspend. |
| 227 | * |
| 228 | * Kernel needs to suspend all functions separately. Therefore all |
| 229 | * registered functions must have drivers with suspend and resume |
| 230 | * methods. Failing that the kernel simply removes the whole card. |
| 231 | * |
| 232 | * If already not suspended, this function allocates and sends a host |
| 233 | * sleep activate request to the firmware and turns off the traffic. |
| 234 | */ |
| 235 | static int mwifiex_sdio_suspend(struct device *dev) |
| 236 | { |
| 237 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 238 | struct sdio_mmc_card *card; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 239 | struct mwifiex_adapter *adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 240 | mmc_pm_flag_t pm_flag = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 241 | int ret = 0; |
| 242 | |
| 243 | if (func) { |
| 244 | pm_flag = sdio_get_host_pm_caps(func); |
| 245 | pr_debug("cmd: %s: suspend: PM flag = 0x%x\n", |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 246 | sdio_func_id(func), pm_flag); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 247 | if (!(pm_flag & MMC_PM_KEEP_POWER)) { |
| 248 | pr_err("%s: cannot remain alive while host is" |
| 249 | " suspended\n", sdio_func_id(func)); |
| 250 | return -ENOSYS; |
| 251 | } |
| 252 | |
| 253 | card = sdio_get_drvdata(func); |
| 254 | if (!card || !card->adapter) { |
| 255 | pr_err("suspend: invalid card or adapter\n"); |
| 256 | return 0; |
| 257 | } |
| 258 | } else { |
| 259 | pr_err("suspend: sdio_func is not specified\n"); |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | adapter = card->adapter; |
| 264 | |
| 265 | /* Enable the Host Sleep */ |
Bing Zhao | dd321ac | 2012-11-15 15:58:48 -0800 | [diff] [blame] | 266 | if (!mwifiex_enable_hs(adapter)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 267 | mwifiex_dbg(adapter, ERROR, |
| 268 | "cmd: failed to suspend\n"); |
Amitkumar Karwar | c0dbba6 | 2014-03-25 19:01:20 -0700 | [diff] [blame] | 269 | adapter->hs_enabling = false; |
Bing Zhao | dd321ac | 2012-11-15 15:58:48 -0800 | [diff] [blame] | 270 | return -EFAULT; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 273 | mwifiex_dbg(adapter, INFO, |
| 274 | "cmd: suspend with MMC_PM_KEEP_POWER\n"); |
Bing Zhao | dd321ac | 2012-11-15 15:58:48 -0800 | [diff] [blame] | 275 | ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); |
| 276 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 277 | /* Indicate device suspended */ |
| 278 | adapter->is_suspended = true; |
Amitkumar Karwar | c0dbba6 | 2014-03-25 19:01:20 -0700 | [diff] [blame] | 279 | adapter->hs_enabling = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 280 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 281 | return ret; |
| 282 | } |
| 283 | |
WarheadsSE | 98e6b9d | 2012-04-24 15:57:21 -0400 | [diff] [blame] | 284 | /* Device ID for SD8786 */ |
| 285 | #define SDIO_DEVICE_ID_MARVELL_8786 (0x9116) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 286 | /* Device ID for SD8787 */ |
| 287 | #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119) |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 288 | /* Device ID for SD8797 */ |
| 289 | #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129) |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 290 | /* Device ID for SD8897 */ |
| 291 | #define SDIO_DEVICE_ID_MARVELL_8897 (0x912d) |
Avinash Patil | 030bb75 | 2014-10-01 10:55:26 -0700 | [diff] [blame] | 292 | /* Device ID for SD8887 */ |
| 293 | #define SDIO_DEVICE_ID_MARVELL_8887 (0x9135) |
Yogesh Ashok Powar | 52bd3d2 | 2015-01-23 17:09:17 +0530 | [diff] [blame] | 294 | /* Device ID for SD8801 */ |
| 295 | #define SDIO_DEVICE_ID_MARVELL_8801 (0x9139) |
Zhaoyang Liu | 6d85ef0 | 2015-08-05 06:09:40 -0700 | [diff] [blame] | 296 | /* Device ID for SD8997 */ |
| 297 | #define SDIO_DEVICE_ID_MARVELL_8997 (0x9141) |
Yogesh Ashok Powar | 52bd3d2 | 2015-01-23 17:09:17 +0530 | [diff] [blame] | 298 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 299 | |
| 300 | /* WLAN IDs */ |
| 301 | static const struct sdio_device_id mwifiex_ids[] = { |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 302 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8786), |
| 303 | .driver_data = (unsigned long) &mwifiex_sdio_sd8786}, |
| 304 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787), |
| 305 | .driver_data = (unsigned long) &mwifiex_sdio_sd8787}, |
| 306 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797), |
| 307 | .driver_data = (unsigned long) &mwifiex_sdio_sd8797}, |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 308 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8897), |
| 309 | .driver_data = (unsigned long) &mwifiex_sdio_sd8897}, |
Avinash Patil | 030bb75 | 2014-10-01 10:55:26 -0700 | [diff] [blame] | 310 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8887), |
| 311 | .driver_data = (unsigned long)&mwifiex_sdio_sd8887}, |
Yogesh Ashok Powar | 52bd3d2 | 2015-01-23 17:09:17 +0530 | [diff] [blame] | 312 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8801), |
| 313 | .driver_data = (unsigned long)&mwifiex_sdio_sd8801}, |
Zhaoyang Liu | 6d85ef0 | 2015-08-05 06:09:40 -0700 | [diff] [blame] | 314 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8997), |
| 315 | .driver_data = (unsigned long)&mwifiex_sdio_sd8997}, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 316 | {}, |
| 317 | }; |
| 318 | |
| 319 | MODULE_DEVICE_TABLE(sdio, mwifiex_ids); |
| 320 | |
| 321 | static const struct dev_pm_ops mwifiex_sdio_pm_ops = { |
| 322 | .suspend = mwifiex_sdio_suspend, |
| 323 | .resume = mwifiex_sdio_resume, |
| 324 | }; |
| 325 | |
| 326 | static struct sdio_driver mwifiex_sdio = { |
| 327 | .name = "mwifiex_sdio", |
| 328 | .id_table = mwifiex_ids, |
| 329 | .probe = mwifiex_sdio_probe, |
| 330 | .remove = mwifiex_sdio_remove, |
| 331 | .drv = { |
| 332 | .owner = THIS_MODULE, |
| 333 | .pm = &mwifiex_sdio_pm_ops, |
| 334 | } |
| 335 | }; |
| 336 | |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 337 | /* Write data into SDIO card register. Caller claims SDIO device. */ |
| 338 | static int |
| 339 | mwifiex_write_reg_locked(struct sdio_func *func, u32 reg, u8 data) |
| 340 | { |
| 341 | int ret = -1; |
| 342 | sdio_writeb(func, data, reg, &ret); |
| 343 | return ret; |
| 344 | } |
| 345 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 346 | /* |
| 347 | * This function writes data into SDIO card register. |
| 348 | */ |
| 349 | static int |
Amitkumar Karwar | ab93d4f | 2013-05-17 17:53:42 -0700 | [diff] [blame] | 350 | mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u8 data) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 351 | { |
| 352 | struct sdio_mmc_card *card = adapter->card; |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 353 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 354 | |
| 355 | sdio_claim_host(card->func); |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 356 | ret = mwifiex_write_reg_locked(card->func, reg, data); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 357 | sdio_release_host(card->func); |
| 358 | |
| 359 | return ret; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * This function reads data from SDIO card register. |
| 364 | */ |
| 365 | static int |
Amitkumar Karwar | ab93d4f | 2013-05-17 17:53:42 -0700 | [diff] [blame] | 366 | mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u8 *data) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 367 | { |
| 368 | struct sdio_mmc_card *card = adapter->card; |
| 369 | int ret = -1; |
| 370 | u8 val; |
| 371 | |
| 372 | sdio_claim_host(card->func); |
| 373 | val = sdio_readb(card->func, reg, &ret); |
| 374 | sdio_release_host(card->func); |
| 375 | |
| 376 | *data = val; |
| 377 | |
| 378 | return ret; |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * This function writes multiple data into SDIO card memory. |
| 383 | * |
| 384 | * This does not work in suspended mode. |
| 385 | */ |
| 386 | static int |
| 387 | mwifiex_write_data_sync(struct mwifiex_adapter *adapter, |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 388 | u8 *buffer, u32 pkt_len, u32 port) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 389 | { |
| 390 | struct sdio_mmc_card *card = adapter->card; |
Bing Zhao | 5b2e2ec | 2013-01-25 18:23:00 -0800 | [diff] [blame] | 391 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 392 | u8 blk_mode = |
| 393 | (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE; |
| 394 | u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1; |
| 395 | u32 blk_cnt = |
| 396 | (blk_mode == |
| 397 | BLOCK_MODE) ? (pkt_len / |
| 398 | MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len; |
| 399 | u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK); |
| 400 | |
| 401 | if (adapter->is_suspended) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 402 | mwifiex_dbg(adapter, ERROR, |
| 403 | "%s: not allowed while suspended\n", __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 404 | return -1; |
| 405 | } |
| 406 | |
| 407 | sdio_claim_host(card->func); |
| 408 | |
Bing Zhao | 5b2e2ec | 2013-01-25 18:23:00 -0800 | [diff] [blame] | 409 | ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 410 | |
| 411 | sdio_release_host(card->func); |
| 412 | |
| 413 | return ret; |
| 414 | } |
| 415 | |
| 416 | /* |
| 417 | * This function reads multiple data from SDIO card memory. |
| 418 | */ |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 419 | static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer, |
| 420 | u32 len, u32 port, u8 claim) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 421 | { |
| 422 | struct sdio_mmc_card *card = adapter->card; |
Bing Zhao | 5b2e2ec | 2013-01-25 18:23:00 -0800 | [diff] [blame] | 423 | int ret; |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 424 | u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE |
| 425 | : BLOCK_MODE; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 426 | u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1; |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 427 | u32 blk_cnt = (blk_mode == BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE) |
| 428 | : len; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 429 | u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK); |
| 430 | |
| 431 | if (claim) |
| 432 | sdio_claim_host(card->func); |
| 433 | |
Bing Zhao | 5b2e2ec | 2013-01-25 18:23:00 -0800 | [diff] [blame] | 434 | ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 435 | |
| 436 | if (claim) |
| 437 | sdio_release_host(card->func); |
| 438 | |
| 439 | return ret; |
| 440 | } |
| 441 | |
| 442 | /* |
| 443 | * This function wakes up the card. |
| 444 | * |
| 445 | * A host power up command is written to the card configuration |
| 446 | * register to wake up the card. |
| 447 | */ |
| 448 | static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter) |
| 449 | { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 450 | mwifiex_dbg(adapter, EVENT, |
| 451 | "event: wakeup device...\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 452 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 453 | return mwifiex_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* |
| 457 | * This function is called after the card has woken up. |
| 458 | * |
| 459 | * The card configuration register is reset. |
| 460 | */ |
| 461 | static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter) |
| 462 | { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 463 | mwifiex_dbg(adapter, EVENT, |
| 464 | "cmd: wakeup device completed\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 465 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 466 | return mwifiex_write_reg(adapter, CONFIGURATION_REG, 0); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /* |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 470 | * This function is used to initialize IO ports for the |
| 471 | * chipsets supporting SDIO new mode eg SD8897. |
| 472 | */ |
| 473 | static int mwifiex_init_sdio_new_mode(struct mwifiex_adapter *adapter) |
| 474 | { |
| 475 | u8 reg; |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 476 | struct sdio_mmc_card *card = adapter->card; |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 477 | |
| 478 | adapter->ioport = MEM_PORT; |
| 479 | |
| 480 | /* enable sdio new mode */ |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 481 | if (mwifiex_read_reg(adapter, card->reg->card_cfg_2_1_reg, ®)) |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 482 | return -1; |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 483 | if (mwifiex_write_reg(adapter, card->reg->card_cfg_2_1_reg, |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 484 | reg | CMD53_NEW_MODE)) |
| 485 | return -1; |
| 486 | |
| 487 | /* Configure cmd port and enable reading rx length from the register */ |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 488 | if (mwifiex_read_reg(adapter, card->reg->cmd_cfg_0, ®)) |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 489 | return -1; |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 490 | if (mwifiex_write_reg(adapter, card->reg->cmd_cfg_0, |
| 491 | reg | CMD_PORT_RD_LEN_EN)) |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 492 | return -1; |
| 493 | |
| 494 | /* Enable Dnld/Upld ready auto reset for cmd port after cmd53 is |
| 495 | * completed |
| 496 | */ |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 497 | if (mwifiex_read_reg(adapter, card->reg->cmd_cfg_1, ®)) |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 498 | return -1; |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 499 | if (mwifiex_write_reg(adapter, card->reg->cmd_cfg_1, |
| 500 | reg | CMD_PORT_AUTO_EN)) |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 501 | return -1; |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | /* This function initializes the IO ports. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 507 | * |
| 508 | * The following operations are performed - |
| 509 | * - Read the IO ports (0, 1 and 2) |
| 510 | * - Set host interrupt Reset-To-Read to clear |
| 511 | * - Set auto re-enable interrupt |
| 512 | */ |
| 513 | static int mwifiex_init_sdio_ioport(struct mwifiex_adapter *adapter) |
| 514 | { |
Amitkumar Karwar | ab93d4f | 2013-05-17 17:53:42 -0700 | [diff] [blame] | 515 | u8 reg; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 516 | struct sdio_mmc_card *card = adapter->card; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 517 | |
| 518 | adapter->ioport = 0; |
| 519 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 520 | if (card->supports_sdio_new_mode) { |
| 521 | if (mwifiex_init_sdio_new_mode(adapter)) |
| 522 | return -1; |
| 523 | goto cont; |
| 524 | } |
| 525 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 526 | /* Read the IO port */ |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 527 | if (!mwifiex_read_reg(adapter, card->reg->io_port_0_reg, ®)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 528 | adapter->ioport |= (reg & 0xff); |
| 529 | else |
| 530 | return -1; |
| 531 | |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 532 | if (!mwifiex_read_reg(adapter, card->reg->io_port_1_reg, ®)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 533 | adapter->ioport |= ((reg & 0xff) << 8); |
| 534 | else |
| 535 | return -1; |
| 536 | |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 537 | if (!mwifiex_read_reg(adapter, card->reg->io_port_2_reg, ®)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 538 | adapter->ioport |= ((reg & 0xff) << 16); |
| 539 | else |
| 540 | return -1; |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 541 | cont: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 542 | mwifiex_dbg(adapter, INFO, |
| 543 | "info: SDIO FUNC1 IO port: %#x\n", adapter->ioport); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 544 | |
| 545 | /* Set Host interrupt reset to read to clear */ |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 546 | if (!mwifiex_read_reg(adapter, card->reg->host_int_rsr_reg, ®)) |
| 547 | mwifiex_write_reg(adapter, card->reg->host_int_rsr_reg, |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 548 | reg | card->reg->sdio_int_mask); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 549 | else |
| 550 | return -1; |
| 551 | |
| 552 | /* Dnld/Upld ready set to auto reset */ |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 553 | if (!mwifiex_read_reg(adapter, card->reg->card_misc_cfg_reg, ®)) |
| 554 | mwifiex_write_reg(adapter, card->reg->card_misc_cfg_reg, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 555 | reg | AUTO_RE_ENABLE_INT); |
| 556 | else |
| 557 | return -1; |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * This function sends data to the card. |
| 564 | */ |
| 565 | static int mwifiex_write_data_to_card(struct mwifiex_adapter *adapter, |
| 566 | u8 *payload, u32 pkt_len, u32 port) |
| 567 | { |
| 568 | u32 i = 0; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 569 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 570 | |
| 571 | do { |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 572 | ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 573 | if (ret) { |
| 574 | i++; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 575 | mwifiex_dbg(adapter, ERROR, |
| 576 | "host_to_card, write iomem\t" |
| 577 | "(%d) failed: %d\n", i, ret); |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 578 | if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04)) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 579 | mwifiex_dbg(adapter, ERROR, |
| 580 | "write CFG reg failed\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 581 | |
| 582 | ret = -1; |
| 583 | if (i > MAX_WRITE_IOMEM_RETRY) |
| 584 | return ret; |
| 585 | } |
| 586 | } while (ret == -1); |
| 587 | |
| 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * This function gets the read port. |
| 593 | * |
| 594 | * If control port bit is set in MP read bitmap, the control port |
| 595 | * is returned, otherwise the current read port is returned and |
| 596 | * the value is increased (provided it does not reach the maximum |
| 597 | * limit, in which case it is reset to 1) |
| 598 | */ |
| 599 | static int mwifiex_get_rd_port(struct mwifiex_adapter *adapter, u8 *port) |
| 600 | { |
| 601 | struct sdio_mmc_card *card = adapter->card; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 602 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
Amitkumar Karwar | 5ac253d | 2013-05-17 17:50:26 -0700 | [diff] [blame] | 603 | u32 rd_bitmap = card->mp_rd_bitmap; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 604 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 605 | mwifiex_dbg(adapter, DATA, |
| 606 | "data: mp_rd_bitmap=0x%08x\n", rd_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 607 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 608 | if (card->supports_sdio_new_mode) { |
| 609 | if (!(rd_bitmap & reg->data_port_mask)) |
| 610 | return -1; |
| 611 | } else { |
| 612 | if (!(rd_bitmap & (CTRL_PORT_MASK | reg->data_port_mask))) |
| 613 | return -1; |
| 614 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 615 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 616 | if ((card->has_control_mask) && |
| 617 | (card->mp_rd_bitmap & CTRL_PORT_MASK)) { |
Amitkumar Karwar | 5ac253d | 2013-05-17 17:50:26 -0700 | [diff] [blame] | 618 | card->mp_rd_bitmap &= (u32) (~CTRL_PORT_MASK); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 619 | *port = CTRL_PORT; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 620 | mwifiex_dbg(adapter, DATA, |
| 621 | "data: port=%d mp_rd_bitmap=0x%08x\n", |
| 622 | *port, card->mp_rd_bitmap); |
Amitkumar Karwar | e6a52030 | 2013-05-17 17:53:56 -0700 | [diff] [blame] | 623 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 624 | } |
Amitkumar Karwar | e6a52030 | 2013-05-17 17:53:56 -0700 | [diff] [blame] | 625 | |
| 626 | if (!(card->mp_rd_bitmap & (1 << card->curr_rd_port))) |
| 627 | return -1; |
| 628 | |
| 629 | /* We are now handling the SDIO data ports */ |
| 630 | card->mp_rd_bitmap &= (u32)(~(1 << card->curr_rd_port)); |
| 631 | *port = card->curr_rd_port; |
| 632 | |
| 633 | if (++card->curr_rd_port == card->max_ports) |
| 634 | card->curr_rd_port = reg->start_rd_port; |
| 635 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 636 | mwifiex_dbg(adapter, DATA, |
| 637 | "data: port=%d mp_rd_bitmap=0x%08x -> 0x%08x\n", |
| 638 | *port, rd_bitmap, card->mp_rd_bitmap); |
Amitkumar Karwar | e6a52030 | 2013-05-17 17:53:56 -0700 | [diff] [blame] | 639 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * This function gets the write port for data. |
| 645 | * |
| 646 | * The current write port is returned if available and the value is |
| 647 | * increased (provided it does not reach the maximum limit, in which |
| 648 | * case it is reset to 1) |
| 649 | */ |
Amitkumar Karwar | 0fc0d43 | 2013-05-17 17:54:23 -0700 | [diff] [blame] | 650 | static int mwifiex_get_wr_port_data(struct mwifiex_adapter *adapter, u32 *port) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 651 | { |
| 652 | struct sdio_mmc_card *card = adapter->card; |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 653 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
Amitkumar Karwar | 5ac253d | 2013-05-17 17:50:26 -0700 | [diff] [blame] | 654 | u32 wr_bitmap = card->mp_wr_bitmap; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 655 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 656 | mwifiex_dbg(adapter, DATA, |
| 657 | "data: mp_wr_bitmap=0x%08x\n", wr_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 658 | |
Amitkumar Karwar | c48ba04 | 2014-09-12 20:08:52 +0530 | [diff] [blame] | 659 | if (!(wr_bitmap & card->mp_data_port_mask)) { |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 660 | adapter->data_sent = true; |
| 661 | return -EBUSY; |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 662 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 663 | |
| 664 | if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) { |
Amitkumar Karwar | 5ac253d | 2013-05-17 17:50:26 -0700 | [diff] [blame] | 665 | card->mp_wr_bitmap &= (u32) (~(1 << card->curr_wr_port)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 666 | *port = card->curr_wr_port; |
Amitkumar Karwar | c48ba04 | 2014-09-12 20:08:52 +0530 | [diff] [blame] | 667 | if (++card->curr_wr_port == card->mp_end_port) |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 668 | card->curr_wr_port = reg->start_wr_port; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 669 | } else { |
| 670 | adapter->data_sent = true; |
| 671 | return -EBUSY; |
| 672 | } |
| 673 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 674 | if ((card->has_control_mask) && (*port == CTRL_PORT)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 675 | mwifiex_dbg(adapter, ERROR, |
| 676 | "invalid data port=%d cur port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n", |
| 677 | *port, card->curr_wr_port, wr_bitmap, |
| 678 | card->mp_wr_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 679 | return -1; |
| 680 | } |
| 681 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 682 | mwifiex_dbg(adapter, DATA, |
| 683 | "data: port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n", |
| 684 | *port, wr_bitmap, card->mp_wr_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * This function polls the card status. |
| 691 | */ |
| 692 | static int |
| 693 | mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits) |
| 694 | { |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 695 | struct sdio_mmc_card *card = adapter->card; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 696 | u32 tries; |
Amitkumar Karwar | ab93d4f | 2013-05-17 17:53:42 -0700 | [diff] [blame] | 697 | u8 cs; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 698 | |
| 699 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 700 | if (mwifiex_read_reg(adapter, card->reg->poll_reg, &cs)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 701 | break; |
| 702 | else if ((cs & bits) == bits) |
| 703 | return 0; |
| 704 | |
Yogesh Ashok Powar | e7891ba | 2012-03-12 19:35:11 -0700 | [diff] [blame] | 705 | usleep_range(10, 20); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 708 | mwifiex_dbg(adapter, ERROR, |
| 709 | "poll card status failed, tries = %d\n", tries); |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 710 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 711 | return -1; |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | * This function reads the firmware status. |
| 716 | */ |
| 717 | static int |
| 718 | mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat) |
| 719 | { |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 720 | struct sdio_mmc_card *card = adapter->card; |
| 721 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
Amitkumar Karwar | ab93d4f | 2013-05-17 17:53:42 -0700 | [diff] [blame] | 722 | u8 fws0, fws1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 723 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 724 | if (mwifiex_read_reg(adapter, reg->status_reg_0, &fws0)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 725 | return -1; |
| 726 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 727 | if (mwifiex_read_reg(adapter, reg->status_reg_1, &fws1)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 728 | return -1; |
| 729 | |
| 730 | *dat = (u16) ((fws1 << 8) | fws0); |
| 731 | |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | /* |
| 736 | * This function disables the host interrupt. |
| 737 | * |
| 738 | * The host interrupt mask is read, the disable bit is reset and |
| 739 | * written back to the card host interrupt mask register. |
| 740 | */ |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 741 | static void mwifiex_sdio_disable_host_int(struct mwifiex_adapter *adapter) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 742 | { |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 743 | struct sdio_mmc_card *card = adapter->card; |
| 744 | struct sdio_func *func = card->func; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 745 | |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 746 | sdio_claim_host(func); |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 747 | mwifiex_write_reg_locked(func, card->reg->host_int_mask_reg, 0); |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 748 | sdio_release_irq(func); |
| 749 | sdio_release_host(func); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | /* |
Amitkumar Karwar | 2cdf359 | 2013-07-22 19:17:56 -0700 | [diff] [blame] | 753 | * This function reads the interrupt status from card. |
| 754 | */ |
| 755 | static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter) |
| 756 | { |
| 757 | struct sdio_mmc_card *card = adapter->card; |
| 758 | u8 sdio_ireg; |
| 759 | unsigned long flags; |
| 760 | |
| 761 | if (mwifiex_read_data_sync(adapter, card->mp_regs, |
| 762 | card->reg->max_mp_regs, |
| 763 | REG_PORT | MWIFIEX_SDIO_BYTE_MODE_MASK, 0)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 764 | mwifiex_dbg(adapter, ERROR, "read mp_regs failed\n"); |
Amitkumar Karwar | 2cdf359 | 2013-07-22 19:17:56 -0700 | [diff] [blame] | 765 | return; |
| 766 | } |
| 767 | |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 768 | sdio_ireg = card->mp_regs[card->reg->host_int_status_reg]; |
Amitkumar Karwar | 2cdf359 | 2013-07-22 19:17:56 -0700 | [diff] [blame] | 769 | if (sdio_ireg) { |
| 770 | /* |
| 771 | * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS |
| 772 | * For SDIO new mode CMD port interrupts |
| 773 | * DN_LD_CMD_PORT_HOST_INT_STATUS and/or |
| 774 | * UP_LD_CMD_PORT_HOST_INT_STATUS |
| 775 | * Clear the interrupt status register |
| 776 | */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 777 | mwifiex_dbg(adapter, INTR, |
| 778 | "int: sdio_ireg = %#x\n", sdio_ireg); |
Amitkumar Karwar | 2cdf359 | 2013-07-22 19:17:56 -0700 | [diff] [blame] | 779 | spin_lock_irqsave(&adapter->int_lock, flags); |
| 780 | adapter->int_status |= sdio_ireg; |
| 781 | spin_unlock_irqrestore(&adapter->int_lock, flags); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | /* |
| 786 | * SDIO interrupt handler. |
| 787 | * |
| 788 | * This function reads the interrupt status from firmware and handles |
| 789 | * the interrupt in current thread (ksdioirqd) right away. |
| 790 | */ |
| 791 | static void |
| 792 | mwifiex_sdio_interrupt(struct sdio_func *func) |
| 793 | { |
| 794 | struct mwifiex_adapter *adapter; |
| 795 | struct sdio_mmc_card *card; |
| 796 | |
| 797 | card = sdio_get_drvdata(func); |
| 798 | if (!card || !card->adapter) { |
| 799 | pr_debug("int: func=%p card=%p adapter=%p\n", |
| 800 | func, card, card ? card->adapter : NULL); |
| 801 | return; |
| 802 | } |
| 803 | adapter = card->adapter; |
| 804 | |
| 805 | if (!adapter->pps_uapsd_mode && adapter->ps_state == PS_STATE_SLEEP) |
| 806 | adapter->ps_state = PS_STATE_AWAKE; |
| 807 | |
| 808 | mwifiex_interrupt_status(adapter); |
| 809 | mwifiex_main_process(adapter); |
| 810 | } |
| 811 | |
| 812 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 813 | * This function enables the host interrupt. |
| 814 | * |
| 815 | * The host interrupt enable mask is written to the card |
| 816 | * host interrupt mask register. |
| 817 | */ |
| 818 | static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter *adapter) |
| 819 | { |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 820 | struct sdio_mmc_card *card = adapter->card; |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 821 | struct sdio_func *func = card->func; |
| 822 | int ret; |
| 823 | |
| 824 | sdio_claim_host(func); |
| 825 | |
| 826 | /* Request the SDIO IRQ */ |
| 827 | ret = sdio_claim_irq(func, mwifiex_sdio_interrupt); |
| 828 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 829 | mwifiex_dbg(adapter, ERROR, |
| 830 | "claim irq failed: ret=%d\n", ret); |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 831 | goto out; |
| 832 | } |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 833 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 834 | /* Simply write the mask to the register */ |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 835 | ret = mwifiex_write_reg_locked(func, card->reg->host_int_mask_reg, |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 836 | card->reg->host_int_enable); |
| 837 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 838 | mwifiex_dbg(adapter, ERROR, |
| 839 | "enable host interrupt failed\n"); |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 840 | sdio_release_irq(func); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 841 | } |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 842 | |
| 843 | out: |
| 844 | sdio_release_host(func); |
| 845 | return ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /* |
| 849 | * This function sends a data buffer to the card. |
| 850 | */ |
| 851 | static int mwifiex_sdio_card_to_host(struct mwifiex_adapter *adapter, |
| 852 | u32 *type, u8 *buffer, |
| 853 | u32 npayload, u32 ioport) |
| 854 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 855 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 856 | u32 nb; |
| 857 | |
| 858 | if (!buffer) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 859 | mwifiex_dbg(adapter, ERROR, |
| 860 | "%s: buffer is NULL\n", __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 861 | return -1; |
| 862 | } |
| 863 | |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 864 | ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 865 | |
| 866 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 867 | mwifiex_dbg(adapter, ERROR, |
| 868 | "%s: read iomem failed: %d\n", __func__, |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 869 | ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 870 | return -1; |
| 871 | } |
| 872 | |
| 873 | nb = le16_to_cpu(*(__le16 *) (buffer)); |
| 874 | if (nb > npayload) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 875 | mwifiex_dbg(adapter, ERROR, |
| 876 | "%s: invalid packet, nb=%d npayload=%d\n", |
| 877 | __func__, nb, npayload); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 878 | return -1; |
| 879 | } |
| 880 | |
| 881 | *type = le16_to_cpu(*(__le16 *) (buffer + 2)); |
| 882 | |
| 883 | return ret; |
| 884 | } |
| 885 | |
| 886 | /* |
| 887 | * This function downloads the firmware to the card. |
| 888 | * |
| 889 | * Firmware is downloaded to the card in blocks. Every block download |
| 890 | * is tested for CRC errors, and retried a number of times before |
| 891 | * returning failure. |
| 892 | */ |
| 893 | static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter, |
| 894 | struct mwifiex_fw_image *fw) |
| 895 | { |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 896 | struct sdio_mmc_card *card = adapter->card; |
| 897 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 898 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 899 | u8 *firmware = fw->fw_buf; |
| 900 | u32 firmware_len = fw->fw_len; |
| 901 | u32 offset = 0; |
Amitkumar Karwar | ab93d4f | 2013-05-17 17:53:42 -0700 | [diff] [blame] | 902 | u8 base0, base1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 903 | u8 *fwbuf; |
| 904 | u16 len = 0; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 905 | u32 txlen, tx_blocks = 0, tries; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 906 | u32 i = 0; |
| 907 | |
| 908 | if (!firmware_len) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 909 | mwifiex_dbg(adapter, ERROR, |
| 910 | "firmware image not found! Terminating download\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 911 | return -1; |
| 912 | } |
| 913 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 914 | mwifiex_dbg(adapter, INFO, |
| 915 | "info: downloading FW image (%d bytes)\n", |
| 916 | firmware_len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 917 | |
| 918 | /* Assume that the allocated buffer is 8-byte aligned */ |
| 919 | fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL); |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 920 | if (!fwbuf) |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 921 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 922 | |
Aniket Nagarnaik | cb9d61e | 2015-08-06 00:39:16 -0700 | [diff] [blame] | 923 | sdio_claim_host(card->func); |
| 924 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 925 | /* Perform firmware data transfer */ |
| 926 | do { |
| 927 | /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY |
| 928 | bits */ |
| 929 | ret = mwifiex_sdio_poll_card_status(adapter, CARD_IO_READY | |
| 930 | DN_LD_CARD_RDY); |
| 931 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 932 | mwifiex_dbg(adapter, ERROR, |
| 933 | "FW download with helper:\t" |
| 934 | "poll status timeout @ %d\n", offset); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 935 | goto done; |
| 936 | } |
| 937 | |
| 938 | /* More data? */ |
| 939 | if (offset >= firmware_len) |
| 940 | break; |
| 941 | |
| 942 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 943 | ret = mwifiex_read_reg(adapter, reg->base_0_reg, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 944 | &base0); |
| 945 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 946 | mwifiex_dbg(adapter, ERROR, |
| 947 | "dev BASE0 register read failed:\t" |
| 948 | "base0=%#04X(%d). Terminating dnld\n", |
| 949 | base0, base0); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 950 | goto done; |
| 951 | } |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 952 | ret = mwifiex_read_reg(adapter, reg->base_1_reg, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 953 | &base1); |
| 954 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 955 | mwifiex_dbg(adapter, ERROR, |
| 956 | "dev BASE1 register read failed:\t" |
| 957 | "base1=%#04X(%d). Terminating dnld\n", |
| 958 | base1, base1); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 959 | goto done; |
| 960 | } |
| 961 | len = (u16) (((base1 & 0xff) << 8) | (base0 & 0xff)); |
| 962 | |
| 963 | if (len) |
| 964 | break; |
| 965 | |
Yogesh Ashok Powar | e7891ba | 2012-03-12 19:35:11 -0700 | [diff] [blame] | 966 | usleep_range(10, 20); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | if (!len) { |
| 970 | break; |
| 971 | } else if (len > MWIFIEX_UPLD_SIZE) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 972 | mwifiex_dbg(adapter, ERROR, |
| 973 | "FW dnld failed @ %d, invalid length %d\n", |
| 974 | offset, len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 975 | ret = -1; |
| 976 | goto done; |
| 977 | } |
| 978 | |
| 979 | txlen = len; |
| 980 | |
| 981 | if (len & BIT(0)) { |
| 982 | i++; |
| 983 | if (i > MAX_WRITE_IOMEM_RETRY) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 984 | mwifiex_dbg(adapter, ERROR, |
| 985 | "FW dnld failed @ %d, over max retry\n", |
| 986 | offset); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 987 | ret = -1; |
| 988 | goto done; |
| 989 | } |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 990 | mwifiex_dbg(adapter, ERROR, |
| 991 | "CRC indicated by the helper:\t" |
| 992 | "len = 0x%04X, txlen = %d\n", len, txlen); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 993 | len &= ~BIT(0); |
| 994 | /* Setting this to 0 to resend from same offset */ |
| 995 | txlen = 0; |
| 996 | } else { |
| 997 | i = 0; |
| 998 | |
| 999 | /* Set blocksize to transfer - checking for last |
| 1000 | block */ |
| 1001 | if (firmware_len - offset < txlen) |
| 1002 | txlen = firmware_len - offset; |
| 1003 | |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 1004 | tx_blocks = (txlen + MWIFIEX_SDIO_BLOCK_SIZE - 1) |
| 1005 | / MWIFIEX_SDIO_BLOCK_SIZE; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1006 | |
| 1007 | /* Copy payload to buffer */ |
| 1008 | memmove(fwbuf, &firmware[offset], txlen); |
| 1009 | } |
| 1010 | |
| 1011 | ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks * |
| 1012 | MWIFIEX_SDIO_BLOCK_SIZE, |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 1013 | adapter->ioport); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1014 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1015 | mwifiex_dbg(adapter, ERROR, |
| 1016 | "FW download, write iomem (%d) failed @ %d\n", |
| 1017 | i, offset); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1018 | if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04)) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1019 | mwifiex_dbg(adapter, ERROR, |
| 1020 | "write CFG reg failed\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1021 | |
| 1022 | ret = -1; |
| 1023 | goto done; |
| 1024 | } |
| 1025 | |
| 1026 | offset += txlen; |
| 1027 | } while (true); |
| 1028 | |
Aniket Nagarnaik | cb9d61e | 2015-08-06 00:39:16 -0700 | [diff] [blame] | 1029 | sdio_release_host(card->func); |
| 1030 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1031 | mwifiex_dbg(adapter, MSG, |
| 1032 | "info: FW download over, size %d bytes\n", offset); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1033 | |
| 1034 | ret = 0; |
| 1035 | done: |
| 1036 | kfree(fwbuf); |
| 1037 | return ret; |
| 1038 | } |
| 1039 | |
| 1040 | /* |
| 1041 | * This function checks the firmware status in card. |
| 1042 | * |
| 1043 | * The winner interface is also determined by this function. |
| 1044 | */ |
| 1045 | static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1046 | u32 poll_num) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1047 | { |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 1048 | struct sdio_mmc_card *card = adapter->card; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1049 | int ret = 0; |
| 1050 | u16 firmware_stat; |
| 1051 | u32 tries; |
Amitkumar Karwar | ab93d4f | 2013-05-17 17:53:42 -0700 | [diff] [blame] | 1052 | u8 winner_status; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1053 | |
| 1054 | /* Wait for firmware initialization event */ |
| 1055 | for (tries = 0; tries < poll_num; tries++) { |
| 1056 | ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat); |
| 1057 | if (ret) |
| 1058 | continue; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1059 | if (firmware_stat == FIRMWARE_READY_SDIO) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1060 | ret = 0; |
| 1061 | break; |
| 1062 | } else { |
Amitkumar Karwar | a76b20e | 2013-07-22 19:17:53 -0700 | [diff] [blame] | 1063 | msleep(100); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1064 | ret = -1; |
| 1065 | } |
| 1066 | } |
| 1067 | |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1068 | if (ret) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1069 | if (mwifiex_read_reg |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 1070 | (adapter, card->reg->status_reg_0, &winner_status)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1071 | winner_status = 0; |
| 1072 | |
| 1073 | if (winner_status) |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1074 | adapter->winner = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1075 | else |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1076 | adapter->winner = 1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1077 | } |
| 1078 | return ret; |
| 1079 | } |
| 1080 | |
| 1081 | /* |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1082 | * This function decode sdio aggreation pkt. |
| 1083 | * |
| 1084 | * Based on the the data block size and pkt_len, |
| 1085 | * skb data will be decoded to few packets. |
| 1086 | */ |
| 1087 | static void mwifiex_deaggr_sdio_pkt(struct mwifiex_adapter *adapter, |
| 1088 | struct sk_buff *skb) |
| 1089 | { |
| 1090 | u32 total_pkt_len, pkt_len; |
| 1091 | struct sk_buff *skb_deaggr; |
| 1092 | u32 pkt_type; |
| 1093 | u16 blk_size; |
| 1094 | u8 blk_num; |
| 1095 | u8 *data; |
| 1096 | |
| 1097 | data = skb->data; |
| 1098 | total_pkt_len = skb->len; |
| 1099 | |
| 1100 | while (total_pkt_len >= (SDIO_HEADER_OFFSET + INTF_HEADER_LEN)) { |
| 1101 | if (total_pkt_len < adapter->sdio_rx_block_size) |
| 1102 | break; |
| 1103 | blk_num = *(data + BLOCK_NUMBER_OFFSET); |
| 1104 | blk_size = adapter->sdio_rx_block_size * blk_num; |
| 1105 | if (blk_size > total_pkt_len) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1106 | mwifiex_dbg(adapter, ERROR, |
| 1107 | "%s: error in blk_size,\t" |
| 1108 | "blk_num=%d, blk_size=%d, total_pkt_len=%d\n", |
| 1109 | __func__, blk_num, blk_size, total_pkt_len); |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1110 | break; |
| 1111 | } |
| 1112 | pkt_len = le16_to_cpu(*(__le16 *)(data + SDIO_HEADER_OFFSET)); |
| 1113 | pkt_type = le16_to_cpu(*(__le16 *)(data + SDIO_HEADER_OFFSET + |
| 1114 | 2)); |
| 1115 | if ((pkt_len + SDIO_HEADER_OFFSET) > blk_size) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1116 | mwifiex_dbg(adapter, ERROR, |
| 1117 | "%s: error in pkt_len,\t" |
| 1118 | "pkt_len=%d, blk_size=%d\n", |
| 1119 | __func__, pkt_len, blk_size); |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1120 | break; |
| 1121 | } |
| 1122 | skb_deaggr = mwifiex_alloc_dma_align_buf(pkt_len, |
| 1123 | GFP_KERNEL | GFP_DMA); |
| 1124 | if (!skb_deaggr) |
| 1125 | break; |
| 1126 | skb_put(skb_deaggr, pkt_len); |
| 1127 | memcpy(skb_deaggr->data, data + SDIO_HEADER_OFFSET, pkt_len); |
| 1128 | skb_pull(skb_deaggr, INTF_HEADER_LEN); |
| 1129 | |
| 1130 | mwifiex_handle_rx_packet(adapter, skb_deaggr); |
| 1131 | data += blk_size; |
| 1132 | total_pkt_len -= blk_size; |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1137 | * This function decodes a received packet. |
| 1138 | * |
| 1139 | * Based on the type, the packet is treated as either a data, or |
| 1140 | * a command response, or an event, and the correct handler |
| 1141 | * function is invoked. |
| 1142 | */ |
| 1143 | static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter, |
| 1144 | struct sk_buff *skb, u32 upld_typ) |
| 1145 | { |
| 1146 | u8 *cmd_buf; |
Avinash Patil | d03b4aa | 2013-11-05 15:01:44 -0800 | [diff] [blame] | 1147 | __le16 *curr_ptr = (__le16 *)skb->data; |
| 1148 | u16 pkt_len = le16_to_cpu(*curr_ptr); |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1149 | struct mwifiex_rxinfo *rx_info; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1150 | |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1151 | if (upld_typ != MWIFIEX_TYPE_AGGR_DATA) { |
| 1152 | skb_trim(skb, pkt_len); |
| 1153 | skb_pull(skb, INTF_HEADER_LEN); |
| 1154 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1155 | |
| 1156 | switch (upld_typ) { |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1157 | case MWIFIEX_TYPE_AGGR_DATA: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1158 | mwifiex_dbg(adapter, INFO, |
| 1159 | "info: --- Rx: Aggr Data packet ---\n"); |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1160 | rx_info = MWIFIEX_SKB_RXCB(skb); |
| 1161 | rx_info->buf_type = MWIFIEX_TYPE_AGGR_DATA; |
| 1162 | if (adapter->rx_work_enabled) { |
| 1163 | skb_queue_tail(&adapter->rx_data_q, skb); |
| 1164 | atomic_inc(&adapter->rx_pending); |
| 1165 | adapter->data_received = true; |
| 1166 | } else { |
| 1167 | mwifiex_deaggr_sdio_pkt(adapter, skb); |
| 1168 | dev_kfree_skb_any(skb); |
| 1169 | } |
| 1170 | break; |
| 1171 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1172 | case MWIFIEX_TYPE_DATA: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1173 | mwifiex_dbg(adapter, DATA, |
| 1174 | "info: --- Rx: Data packet ---\n"); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1175 | if (adapter->rx_work_enabled) { |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1176 | skb_queue_tail(&adapter->rx_data_q, skb); |
Avinash Patil | 6e25117 | 2014-09-12 20:08:59 +0530 | [diff] [blame] | 1177 | adapter->data_received = true; |
| 1178 | atomic_inc(&adapter->rx_pending); |
| 1179 | } else { |
| 1180 | mwifiex_handle_rx_packet(adapter, skb); |
| 1181 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1182 | break; |
| 1183 | |
| 1184 | case MWIFIEX_TYPE_CMD: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1185 | mwifiex_dbg(adapter, CMD, |
| 1186 | "info: --- Rx: Cmd Response ---\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1187 | /* take care of curr_cmd = NULL case */ |
| 1188 | if (!adapter->curr_cmd) { |
| 1189 | cmd_buf = adapter->upld_buf; |
| 1190 | |
| 1191 | if (adapter->ps_state == PS_STATE_SLEEP_CFM) |
| 1192 | mwifiex_process_sleep_confirm_resp(adapter, |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 1193 | skb->data, |
| 1194 | skb->len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1195 | |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 1196 | memcpy(cmd_buf, skb->data, |
| 1197 | min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, |
| 1198 | skb->len)); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1199 | |
| 1200 | dev_kfree_skb_any(skb); |
| 1201 | } else { |
| 1202 | adapter->cmd_resp_received = true; |
| 1203 | adapter->curr_cmd->resp_skb = skb; |
| 1204 | } |
| 1205 | break; |
| 1206 | |
| 1207 | case MWIFIEX_TYPE_EVENT: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1208 | mwifiex_dbg(adapter, EVENT, |
| 1209 | "info: --- Rx: Event ---\n"); |
Tobias Waldekranz | cfcd926 | 2013-08-26 09:18:06 +0200 | [diff] [blame] | 1210 | adapter->event_cause = le32_to_cpu(*(__le32 *) skb->data); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1211 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1212 | if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE)) |
Amitkumar Karwar | e80c81d | 2012-06-20 20:21:12 -0700 | [diff] [blame] | 1213 | memcpy(adapter->event_body, |
| 1214 | skb->data + MWIFIEX_EVENT_HEADER_LEN, |
| 1215 | skb->len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1216 | |
| 1217 | /* event cause has been saved to adapter->event_cause */ |
| 1218 | adapter->event_received = true; |
| 1219 | adapter->event_skb = skb; |
| 1220 | |
| 1221 | break; |
| 1222 | |
| 1223 | default: |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1224 | mwifiex_dbg(adapter, ERROR, |
| 1225 | "unknown upload type %#x\n", upld_typ); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1226 | dev_kfree_skb_any(skb); |
| 1227 | break; |
| 1228 | } |
| 1229 | |
| 1230 | return 0; |
| 1231 | } |
| 1232 | |
| 1233 | /* |
| 1234 | * This function transfers received packets from card to driver, performing |
| 1235 | * aggregation if required. |
| 1236 | * |
| 1237 | * For data received on control port, or if aggregation is disabled, the |
| 1238 | * received buffers are uploaded as separate packets. However, if aggregation |
| 1239 | * is enabled and required, the buffers are copied onto an aggregation buffer, |
| 1240 | * provided there is space left, processed and finally uploaded. |
| 1241 | */ |
| 1242 | static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter *adapter, |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1243 | u16 rx_len, u8 port) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1244 | { |
| 1245 | struct sdio_mmc_card *card = adapter->card; |
| 1246 | s32 f_do_rx_aggr = 0; |
| 1247 | s32 f_do_rx_cur = 0; |
| 1248 | s32 f_aggr_cur = 0; |
Cathy Luo | 2c11ab9 | 2015-03-12 01:29:31 -0700 | [diff] [blame] | 1249 | s32 f_post_aggr_cur = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1250 | struct sk_buff *skb_deaggr; |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1251 | struct sk_buff *skb = NULL; |
| 1252 | u32 pkt_len, pkt_type, mport, pind; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1253 | u8 *curr_ptr; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1254 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1255 | if ((card->has_control_mask) && (port == CTRL_PORT)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1256 | /* Read the command Resp without aggr */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1257 | mwifiex_dbg(adapter, CMD, |
| 1258 | "info: %s: no aggregation for cmd\t" |
| 1259 | "response\n", __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1260 | |
| 1261 | f_do_rx_cur = 1; |
| 1262 | goto rx_curr_single; |
| 1263 | } |
| 1264 | |
| 1265 | if (!card->mpa_rx.enabled) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1266 | mwifiex_dbg(adapter, WARN, |
| 1267 | "info: %s: rx aggregation disabled\n", |
| 1268 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1269 | |
| 1270 | f_do_rx_cur = 1; |
| 1271 | goto rx_curr_single; |
| 1272 | } |
| 1273 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1274 | if ((!card->has_control_mask && (card->mp_rd_bitmap & |
| 1275 | card->reg->data_port_mask)) || |
| 1276 | (card->has_control_mask && (card->mp_rd_bitmap & |
| 1277 | (~((u32) CTRL_PORT_MASK))))) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1278 | /* Some more data RX pending */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1279 | mwifiex_dbg(adapter, INFO, |
| 1280 | "info: %s: not last packet\n", __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1281 | |
| 1282 | if (MP_RX_AGGR_IN_PROGRESS(card)) { |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1283 | if (MP_RX_AGGR_BUF_HAS_ROOM(card, rx_len)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1284 | f_aggr_cur = 1; |
| 1285 | } else { |
| 1286 | /* No room in Aggr buf, do rx aggr now */ |
| 1287 | f_do_rx_aggr = 1; |
Cathy Luo | 2c11ab9 | 2015-03-12 01:29:31 -0700 | [diff] [blame] | 1288 | f_post_aggr_cur = 1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1289 | } |
| 1290 | } else { |
| 1291 | /* Rx aggr not in progress */ |
| 1292 | f_aggr_cur = 1; |
| 1293 | } |
| 1294 | |
| 1295 | } else { |
| 1296 | /* No more data RX pending */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1297 | mwifiex_dbg(adapter, INFO, |
| 1298 | "info: %s: last packet\n", __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1299 | |
| 1300 | if (MP_RX_AGGR_IN_PROGRESS(card)) { |
| 1301 | f_do_rx_aggr = 1; |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1302 | if (MP_RX_AGGR_BUF_HAS_ROOM(card, rx_len)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1303 | f_aggr_cur = 1; |
| 1304 | else |
| 1305 | /* No room in Aggr buf, do rx aggr now */ |
| 1306 | f_do_rx_cur = 1; |
| 1307 | } else { |
| 1308 | f_do_rx_cur = 1; |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | if (f_aggr_cur) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1313 | mwifiex_dbg(adapter, INFO, |
| 1314 | "info: current packet aggregation\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1315 | /* Curr pkt can be aggregated */ |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1316 | mp_rx_aggr_setup(card, rx_len, port); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1317 | |
| 1318 | if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) || |
Amitkumar Karwar | c23b7c8 | 2013-05-17 17:54:51 -0700 | [diff] [blame] | 1319 | mp_rx_aggr_port_limit_reached(card)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1320 | mwifiex_dbg(adapter, INFO, |
| 1321 | "info: %s: aggregated packet\t" |
| 1322 | "limit reached\n", __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1323 | /* No more pkts allowed in Aggr buf, rx it */ |
| 1324 | f_do_rx_aggr = 1; |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | if (f_do_rx_aggr) { |
| 1329 | /* do aggr RX now */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1330 | mwifiex_dbg(adapter, DATA, |
| 1331 | "info: do_rx_aggr: num of packets: %d\n", |
| 1332 | card->mpa_rx.pkt_cnt); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1333 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1334 | if (card->supports_sdio_new_mode) { |
| 1335 | int i; |
| 1336 | u32 port_count; |
| 1337 | |
| 1338 | for (i = 0, port_count = 0; i < card->max_ports; i++) |
| 1339 | if (card->mpa_rx.ports & BIT(i)) |
| 1340 | port_count++; |
| 1341 | |
| 1342 | /* Reading data from "start_port + 0" to "start_port + |
| 1343 | * port_count -1", so decrease the count by 1 |
| 1344 | */ |
| 1345 | port_count--; |
| 1346 | mport = (adapter->ioport | SDIO_MPA_ADDR_BASE | |
| 1347 | (port_count << 8)) + card->mpa_rx.start_port; |
| 1348 | } else { |
| 1349 | mport = (adapter->ioport | SDIO_MPA_ADDR_BASE | |
| 1350 | (card->mpa_rx.ports << 4)) + |
| 1351 | card->mpa_rx.start_port; |
| 1352 | } |
Amitkumar Karwar | 0fc0d43 | 2013-05-17 17:54:23 -0700 | [diff] [blame] | 1353 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1354 | if (mwifiex_read_data_sync(adapter, card->mpa_rx.buf, |
Amitkumar Karwar | 0fc0d43 | 2013-05-17 17:54:23 -0700 | [diff] [blame] | 1355 | card->mpa_rx.buf_len, mport, 1)) |
Avinash Patil | 17a60b4 | 2011-12-08 20:41:04 -0800 | [diff] [blame] | 1356 | goto error; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1357 | |
| 1358 | curr_ptr = card->mpa_rx.buf; |
| 1359 | |
| 1360 | for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) { |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1361 | u32 *len_arr = card->mpa_rx.len_arr; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1362 | |
| 1363 | /* get curr PKT len & type */ |
Tobias Waldekranz | cfcd926 | 2013-08-26 09:18:06 +0200 | [diff] [blame] | 1364 | pkt_len = le16_to_cpu(*(__le16 *) &curr_ptr[0]); |
| 1365 | pkt_type = le16_to_cpu(*(__le16 *) &curr_ptr[2]); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1366 | |
| 1367 | /* copy pkt to deaggr buf */ |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1368 | skb_deaggr = mwifiex_alloc_dma_align_buf(len_arr[pind], |
| 1369 | GFP_KERNEL | |
| 1370 | GFP_DMA); |
Zhaoyang Liu | 4acaf04 | 2015-03-23 19:50:56 +0530 | [diff] [blame] | 1371 | if (!skb_deaggr) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1372 | mwifiex_dbg(adapter, ERROR, "skb allocation failure\t" |
| 1373 | "drop pkt len=%d type=%d\n", |
| 1374 | pkt_len, pkt_type); |
Zhaoyang Liu | 4acaf04 | 2015-03-23 19:50:56 +0530 | [diff] [blame] | 1375 | curr_ptr += len_arr[pind]; |
| 1376 | continue; |
| 1377 | } |
| 1378 | |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1379 | skb_put(skb_deaggr, len_arr[pind]); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1380 | |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1381 | if ((pkt_type == MWIFIEX_TYPE_DATA || |
| 1382 | (pkt_type == MWIFIEX_TYPE_AGGR_DATA && |
| 1383 | adapter->sdio_rx_aggr_enable)) && |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1384 | (pkt_len <= len_arr[pind])) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1385 | |
| 1386 | memcpy(skb_deaggr->data, curr_ptr, pkt_len); |
| 1387 | |
| 1388 | skb_trim(skb_deaggr, pkt_len); |
| 1389 | |
| 1390 | /* Process de-aggr packet */ |
| 1391 | mwifiex_decode_rx_packet(adapter, skb_deaggr, |
| 1392 | pkt_type); |
| 1393 | } else { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1394 | mwifiex_dbg(adapter, ERROR, |
| 1395 | "drop wrong aggr pkt:\t" |
| 1396 | "sdio_single_port_rx_aggr=%d\t" |
| 1397 | "type=%d len=%d max_len=%d\n", |
| 1398 | adapter->sdio_rx_aggr_enable, |
| 1399 | pkt_type, pkt_len, len_arr[pind]); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1400 | dev_kfree_skb_any(skb_deaggr); |
| 1401 | } |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1402 | curr_ptr += len_arr[pind]; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1403 | } |
| 1404 | MP_RX_AGGR_BUF_RESET(card); |
| 1405 | } |
| 1406 | |
| 1407 | rx_curr_single: |
| 1408 | if (f_do_rx_cur) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1409 | mwifiex_dbg(adapter, INFO, "info: RX: port: %d, rx_len: %d\n", |
| 1410 | port, rx_len); |
Zhaoyang Liu | 4acaf04 | 2015-03-23 19:50:56 +0530 | [diff] [blame] | 1411 | |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1412 | skb = mwifiex_alloc_dma_align_buf(rx_len, GFP_KERNEL | GFP_DMA); |
Zhaoyang Liu | 4acaf04 | 2015-03-23 19:50:56 +0530 | [diff] [blame] | 1413 | if (!skb) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1414 | mwifiex_dbg(adapter, ERROR, |
| 1415 | "single skb allocated fail,\t" |
| 1416 | "drop pkt port=%d len=%d\n", port, rx_len); |
Zhaoyang Liu | 4acaf04 | 2015-03-23 19:50:56 +0530 | [diff] [blame] | 1417 | if (mwifiex_sdio_card_to_host(adapter, &pkt_type, |
| 1418 | card->mpa_rx.buf, rx_len, |
| 1419 | adapter->ioport + port)) |
| 1420 | goto error; |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1424 | skb_put(skb, rx_len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1425 | |
| 1426 | if (mwifiex_sdio_card_to_host(adapter, &pkt_type, |
| 1427 | skb->data, skb->len, |
| 1428 | adapter->ioport + port)) |
Avinash Patil | 17a60b4 | 2011-12-08 20:41:04 -0800 | [diff] [blame] | 1429 | goto error; |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1430 | if (!adapter->sdio_rx_aggr_enable && |
| 1431 | pkt_type == MWIFIEX_TYPE_AGGR_DATA) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1432 | mwifiex_dbg(adapter, ERROR, "drop wrong pkt type %d\t" |
| 1433 | "current SDIO RX Aggr not enabled\n", |
| 1434 | pkt_type); |
Zhaoyang Liu | 4acaf04 | 2015-03-23 19:50:56 +0530 | [diff] [blame] | 1435 | dev_kfree_skb_any(skb); |
| 1436 | return 0; |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1437 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1438 | |
| 1439 | mwifiex_decode_rx_packet(adapter, skb, pkt_type); |
| 1440 | } |
Cathy Luo | 2c11ab9 | 2015-03-12 01:29:31 -0700 | [diff] [blame] | 1441 | if (f_post_aggr_cur) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1442 | mwifiex_dbg(adapter, INFO, |
| 1443 | "info: current packet aggregation\n"); |
Cathy Luo | 2c11ab9 | 2015-03-12 01:29:31 -0700 | [diff] [blame] | 1444 | /* Curr pkt can be aggregated */ |
Avinash Patil | 080465f | 2015-03-18 20:12:52 +0530 | [diff] [blame] | 1445 | mp_rx_aggr_setup(card, rx_len, port); |
Cathy Luo | 2c11ab9 | 2015-03-12 01:29:31 -0700 | [diff] [blame] | 1446 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1447 | |
| 1448 | return 0; |
Avinash Patil | 17a60b4 | 2011-12-08 20:41:04 -0800 | [diff] [blame] | 1449 | error: |
Zhaoyang Liu | 4acaf04 | 2015-03-23 19:50:56 +0530 | [diff] [blame] | 1450 | if (MP_RX_AGGR_IN_PROGRESS(card)) |
Avinash Patil | 17a60b4 | 2011-12-08 20:41:04 -0800 | [diff] [blame] | 1451 | MP_RX_AGGR_BUF_RESET(card); |
Avinash Patil | 17a60b4 | 2011-12-08 20:41:04 -0800 | [diff] [blame] | 1452 | |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1453 | if (f_do_rx_cur && skb) |
Avinash Patil | 17a60b4 | 2011-12-08 20:41:04 -0800 | [diff] [blame] | 1454 | /* Single transfer pending. Free curr buff also */ |
| 1455 | dev_kfree_skb_any(skb); |
| 1456 | |
| 1457 | return -1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | /* |
| 1461 | * This function checks the current interrupt status. |
| 1462 | * |
| 1463 | * The following interrupts are checked and handled by this function - |
| 1464 | * - Data sent |
| 1465 | * - Command sent |
| 1466 | * - Packets received |
| 1467 | * |
| 1468 | * Since the firmware does not generate download ready interrupt if the |
| 1469 | * port updated is command port only, command sent interrupt checking |
| 1470 | * should be done manually, and for every SDIO interrupt. |
| 1471 | * |
| 1472 | * In case of Rx packets received, the packets are uploaded from card to |
| 1473 | * host and processed accordingly. |
| 1474 | */ |
| 1475 | static int mwifiex_process_int_status(struct mwifiex_adapter *adapter) |
| 1476 | { |
| 1477 | struct sdio_mmc_card *card = adapter->card; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 1478 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1479 | int ret = 0; |
| 1480 | u8 sdio_ireg; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1481 | struct sk_buff *skb; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1482 | u8 port = CTRL_PORT; |
| 1483 | u32 len_reg_l, len_reg_u; |
| 1484 | u32 rx_blocks; |
| 1485 | u16 rx_len; |
| 1486 | unsigned long flags; |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1487 | u32 bitmap; |
| 1488 | u8 cr; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1489 | |
| 1490 | spin_lock_irqsave(&adapter->int_lock, flags); |
| 1491 | sdio_ireg = adapter->int_status; |
| 1492 | adapter->int_status = 0; |
| 1493 | spin_unlock_irqrestore(&adapter->int_lock, flags); |
| 1494 | |
| 1495 | if (!sdio_ireg) |
| 1496 | return ret; |
| 1497 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1498 | /* Following interrupt is only for SDIO new mode */ |
| 1499 | if (sdio_ireg & DN_LD_CMD_PORT_HOST_INT_STATUS && adapter->cmd_sent) |
| 1500 | adapter->cmd_sent = false; |
| 1501 | |
| 1502 | /* Following interrupt is only for SDIO new mode */ |
| 1503 | if (sdio_ireg & UP_LD_CMD_PORT_HOST_INT_STATUS) { |
| 1504 | u32 pkt_type; |
| 1505 | |
| 1506 | /* read the len of control packet */ |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 1507 | rx_len = card->mp_regs[reg->cmd_rd_len_1] << 8; |
| 1508 | rx_len |= (u16)card->mp_regs[reg->cmd_rd_len_0]; |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1509 | rx_blocks = DIV_ROUND_UP(rx_len, MWIFIEX_SDIO_BLOCK_SIZE); |
| 1510 | if (rx_len <= INTF_HEADER_LEN || |
| 1511 | (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) > |
| 1512 | MWIFIEX_RX_DATA_BUF_SIZE) |
| 1513 | return -1; |
| 1514 | rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1515 | mwifiex_dbg(adapter, INFO, "info: rx_len = %d\n", rx_len); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1516 | |
Avinash Patil | 6215994 | 2015-03-13 17:37:52 +0530 | [diff] [blame] | 1517 | skb = mwifiex_alloc_dma_align_buf(rx_len, GFP_KERNEL | GFP_DMA); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1518 | if (!skb) |
| 1519 | return -1; |
| 1520 | |
| 1521 | skb_put(skb, rx_len); |
| 1522 | |
| 1523 | if (mwifiex_sdio_card_to_host(adapter, &pkt_type, skb->data, |
| 1524 | skb->len, adapter->ioport | |
| 1525 | CMD_PORT_SLCT)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1526 | mwifiex_dbg(adapter, ERROR, |
| 1527 | "%s: failed to card_to_host", __func__); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1528 | dev_kfree_skb_any(skb); |
| 1529 | goto term_cmd; |
| 1530 | } |
| 1531 | |
| 1532 | if ((pkt_type != MWIFIEX_TYPE_CMD) && |
| 1533 | (pkt_type != MWIFIEX_TYPE_EVENT)) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1534 | mwifiex_dbg(adapter, ERROR, |
| 1535 | "%s:Received wrong packet on cmd port", |
| 1536 | __func__); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1537 | |
| 1538 | mwifiex_decode_rx_packet(adapter, skb, pkt_type); |
| 1539 | } |
| 1540 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1541 | if (sdio_ireg & DN_LD_HOST_INT_STATUS) { |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1542 | bitmap = (u32) card->mp_regs[reg->wr_bitmap_l]; |
| 1543 | bitmap |= ((u32) card->mp_regs[reg->wr_bitmap_u]) << 8; |
| 1544 | if (card->supports_sdio_new_mode) { |
| 1545 | bitmap |= |
| 1546 | ((u32) card->mp_regs[reg->wr_bitmap_1l]) << 16; |
| 1547 | bitmap |= |
| 1548 | ((u32) card->mp_regs[reg->wr_bitmap_1u]) << 24; |
| 1549 | } |
| 1550 | card->mp_wr_bitmap = bitmap; |
| 1551 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1552 | mwifiex_dbg(adapter, INTR, |
| 1553 | "int: DNLD: wr_bitmap=0x%x\n", |
| 1554 | card->mp_wr_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1555 | if (adapter->data_sent && |
| 1556 | (card->mp_wr_bitmap & card->mp_data_port_mask)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1557 | mwifiex_dbg(adapter, INTR, |
| 1558 | "info: <--- Tx DONE Interrupt --->\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1559 | adapter->data_sent = false; |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | /* As firmware will not generate download ready interrupt if the port |
| 1564 | updated is command port only, cmd_sent should be done for any SDIO |
| 1565 | interrupt. */ |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1566 | if (card->has_control_mask && adapter->cmd_sent) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1567 | /* Check if firmware has attach buffer at command port and |
| 1568 | update just that in wr_bit_map. */ |
| 1569 | card->mp_wr_bitmap |= |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 1570 | (u32) card->mp_regs[reg->wr_bitmap_l] & CTRL_PORT_MASK; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1571 | if (card->mp_wr_bitmap & CTRL_PORT_MASK) |
| 1572 | adapter->cmd_sent = false; |
| 1573 | } |
| 1574 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1575 | mwifiex_dbg(adapter, INTR, "info: cmd_sent=%d data_sent=%d\n", |
| 1576 | adapter->cmd_sent, adapter->data_sent); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1577 | if (sdio_ireg & UP_LD_HOST_INT_STATUS) { |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1578 | bitmap = (u32) card->mp_regs[reg->rd_bitmap_l]; |
| 1579 | bitmap |= ((u32) card->mp_regs[reg->rd_bitmap_u]) << 8; |
| 1580 | if (card->supports_sdio_new_mode) { |
| 1581 | bitmap |= |
| 1582 | ((u32) card->mp_regs[reg->rd_bitmap_1l]) << 16; |
| 1583 | bitmap |= |
| 1584 | ((u32) card->mp_regs[reg->rd_bitmap_1u]) << 24; |
| 1585 | } |
| 1586 | card->mp_rd_bitmap = bitmap; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1587 | mwifiex_dbg(adapter, INTR, |
| 1588 | "int: UPLD: rd_bitmap=0x%x\n", |
| 1589 | card->mp_rd_bitmap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1590 | |
| 1591 | while (true) { |
| 1592 | ret = mwifiex_get_rd_port(adapter, &port); |
| 1593 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1594 | mwifiex_dbg(adapter, INFO, |
| 1595 | "info: no more rd_port available\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1596 | break; |
| 1597 | } |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 1598 | len_reg_l = reg->rd_len_p0_l + (port << 1); |
| 1599 | len_reg_u = reg->rd_len_p0_u + (port << 1); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1600 | rx_len = ((u16) card->mp_regs[len_reg_u]) << 8; |
| 1601 | rx_len |= (u16) card->mp_regs[len_reg_l]; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1602 | mwifiex_dbg(adapter, INFO, |
| 1603 | "info: RX: port=%d rx_len=%u\n", |
| 1604 | port, rx_len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1605 | rx_blocks = |
| 1606 | (rx_len + MWIFIEX_SDIO_BLOCK_SIZE - |
| 1607 | 1) / MWIFIEX_SDIO_BLOCK_SIZE; |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 1608 | if (rx_len <= INTF_HEADER_LEN || |
Xinming Hu | e3ad3d5 | 2015-09-18 06:32:05 -0700 | [diff] [blame] | 1609 | (card->mpa_rx.enabled && |
| 1610 | ((rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) > |
| 1611 | card->mpa_rx.buf_size))) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1612 | mwifiex_dbg(adapter, ERROR, |
| 1613 | "invalid rx_len=%d\n", |
| 1614 | rx_len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1615 | return -1; |
| 1616 | } |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1617 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1618 | rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE); |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1619 | mwifiex_dbg(adapter, INFO, "info: rx_len = %d\n", |
| 1620 | rx_len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1621 | |
Zhaoyang Liu | 960d6d0 | 2015-03-13 17:37:59 +0530 | [diff] [blame] | 1622 | if (mwifiex_sdio_card_to_host_mp_aggr(adapter, rx_len, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1623 | port)) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1624 | mwifiex_dbg(adapter, ERROR, |
| 1625 | "card_to_host_mpa failed: int status=%#x\n", |
| 1626 | sdio_ireg); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1627 | goto term_cmd; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | return 0; |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1633 | |
| 1634 | term_cmd: |
| 1635 | /* terminate cmd */ |
| 1636 | if (mwifiex_read_reg(adapter, CONFIGURATION_REG, &cr)) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1637 | mwifiex_dbg(adapter, ERROR, "read CFG reg failed\n"); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1638 | else |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1639 | mwifiex_dbg(adapter, INFO, |
| 1640 | "info: CFG reg val = %d\n", cr); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1641 | |
| 1642 | if (mwifiex_write_reg(adapter, CONFIGURATION_REG, (cr | 0x04))) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1643 | mwifiex_dbg(adapter, ERROR, |
| 1644 | "write CFG reg failed\n"); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1645 | else |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1646 | mwifiex_dbg(adapter, INFO, "info: write success\n"); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1647 | |
| 1648 | if (mwifiex_read_reg(adapter, CONFIGURATION_REG, &cr)) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1649 | mwifiex_dbg(adapter, ERROR, |
| 1650 | "read CFG reg failed\n"); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1651 | else |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1652 | mwifiex_dbg(adapter, INFO, |
| 1653 | "info: CFG reg val =%x\n", cr); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1654 | |
| 1655 | return -1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | /* |
| 1659 | * This function aggregates transmission buffers in driver and downloads |
| 1660 | * the aggregated packet to card. |
| 1661 | * |
| 1662 | * The individual packets are aggregated by copying into an aggregation |
| 1663 | * buffer and then downloaded to the card. Previous unsent packets in the |
| 1664 | * aggregation buffer are pre-copied first before new packets are added. |
| 1665 | * Aggregation is done till there is space left in the aggregation buffer, |
| 1666 | * or till new packets are available. |
| 1667 | * |
| 1668 | * The function will only download the packet to the card when aggregation |
| 1669 | * stops, otherwise it will just aggregate the packet in aggregation buffer |
| 1670 | * and return. |
| 1671 | */ |
| 1672 | static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter *adapter, |
Amitkumar Karwar | 0fc0d43 | 2013-05-17 17:54:23 -0700 | [diff] [blame] | 1673 | u8 *payload, u32 pkt_len, u32 port, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1674 | u32 next_pkt_len) |
| 1675 | { |
| 1676 | struct sdio_mmc_card *card = adapter->card; |
| 1677 | int ret = 0; |
| 1678 | s32 f_send_aggr_buf = 0; |
| 1679 | s32 f_send_cur_buf = 0; |
| 1680 | s32 f_precopy_cur_buf = 0; |
| 1681 | s32 f_postcopy_cur_buf = 0; |
Amitkumar Karwar | 0fc0d43 | 2013-05-17 17:54:23 -0700 | [diff] [blame] | 1682 | u32 mport; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1683 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1684 | if (!card->mpa_tx.enabled || |
| 1685 | (card->has_control_mask && (port == CTRL_PORT)) || |
| 1686 | (card->supports_sdio_new_mode && (port == CMD_PORT_SLCT))) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1687 | mwifiex_dbg(adapter, WARN, |
| 1688 | "info: %s: tx aggregation disabled\n", |
| 1689 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1690 | |
| 1691 | f_send_cur_buf = 1; |
| 1692 | goto tx_curr_single; |
| 1693 | } |
| 1694 | |
| 1695 | if (next_pkt_len) { |
| 1696 | /* More pkt in TX queue */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1697 | mwifiex_dbg(adapter, INFO, |
| 1698 | "info: %s: more packets in queue.\n", |
| 1699 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1700 | |
| 1701 | if (MP_TX_AGGR_IN_PROGRESS(card)) { |
Amitkumar Karwar | c7346c3 | 2014-09-12 20:08:51 +0530 | [diff] [blame] | 1702 | if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1703 | f_precopy_cur_buf = 1; |
| 1704 | |
| 1705 | if (!(card->mp_wr_bitmap & |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 1706 | (1 << card->curr_wr_port)) || |
| 1707 | !MP_TX_AGGR_BUF_HAS_ROOM( |
| 1708 | card, pkt_len + next_pkt_len)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1709 | f_send_aggr_buf = 1; |
| 1710 | } else { |
| 1711 | /* No room in Aggr buf, send it */ |
| 1712 | f_send_aggr_buf = 1; |
| 1713 | |
Amitkumar Karwar | c7346c3 | 2014-09-12 20:08:51 +0530 | [diff] [blame] | 1714 | if (!(card->mp_wr_bitmap & |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1715 | (1 << card->curr_wr_port))) |
| 1716 | f_send_cur_buf = 1; |
| 1717 | else |
| 1718 | f_postcopy_cur_buf = 1; |
| 1719 | } |
| 1720 | } else { |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 1721 | if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len) && |
| 1722 | (card->mp_wr_bitmap & (1 << card->curr_wr_port))) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1723 | f_precopy_cur_buf = 1; |
| 1724 | else |
| 1725 | f_send_cur_buf = 1; |
| 1726 | } |
| 1727 | } else { |
| 1728 | /* Last pkt in TX queue */ |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1729 | mwifiex_dbg(adapter, INFO, |
| 1730 | "info: %s: Last packet in Tx Queue.\n", |
| 1731 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1732 | |
| 1733 | if (MP_TX_AGGR_IN_PROGRESS(card)) { |
| 1734 | /* some packs in Aggr buf already */ |
| 1735 | f_send_aggr_buf = 1; |
| 1736 | |
| 1737 | if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) |
| 1738 | f_precopy_cur_buf = 1; |
| 1739 | else |
| 1740 | /* No room in Aggr buf, send it */ |
| 1741 | f_send_cur_buf = 1; |
| 1742 | } else { |
| 1743 | f_send_cur_buf = 1; |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | if (f_precopy_cur_buf) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1748 | mwifiex_dbg(adapter, DATA, |
| 1749 | "data: %s: precopy current buffer\n", |
| 1750 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1751 | MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port); |
| 1752 | |
| 1753 | if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) || |
Amitkumar Karwar | c23b7c8 | 2013-05-17 17:54:51 -0700 | [diff] [blame] | 1754 | mp_tx_aggr_port_limit_reached(card)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1755 | /* No more pkts allowed in Aggr buf, send it */ |
| 1756 | f_send_aggr_buf = 1; |
| 1757 | } |
| 1758 | |
| 1759 | if (f_send_aggr_buf) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1760 | mwifiex_dbg(adapter, DATA, |
| 1761 | "data: %s: send aggr buffer: %d %d\n", |
| 1762 | __func__, card->mpa_tx.start_port, |
| 1763 | card->mpa_tx.ports); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1764 | if (card->supports_sdio_new_mode) { |
| 1765 | u32 port_count; |
| 1766 | int i; |
| 1767 | |
| 1768 | for (i = 0, port_count = 0; i < card->max_ports; i++) |
| 1769 | if (card->mpa_tx.ports & BIT(i)) |
| 1770 | port_count++; |
| 1771 | |
| 1772 | /* Writing data from "start_port + 0" to "start_port + |
| 1773 | * port_count -1", so decrease the count by 1 |
| 1774 | */ |
| 1775 | port_count--; |
| 1776 | mport = (adapter->ioport | SDIO_MPA_ADDR_BASE | |
| 1777 | (port_count << 8)) + card->mpa_tx.start_port; |
| 1778 | } else { |
| 1779 | mport = (adapter->ioport | SDIO_MPA_ADDR_BASE | |
| 1780 | (card->mpa_tx.ports << 4)) + |
| 1781 | card->mpa_tx.start_port; |
| 1782 | } |
| 1783 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1784 | ret = mwifiex_write_data_to_card(adapter, card->mpa_tx.buf, |
Amitkumar Karwar | 0fc0d43 | 2013-05-17 17:54:23 -0700 | [diff] [blame] | 1785 | card->mpa_tx.buf_len, mport); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1786 | |
| 1787 | MP_TX_AGGR_BUF_RESET(card); |
| 1788 | } |
| 1789 | |
| 1790 | tx_curr_single: |
| 1791 | if (f_send_cur_buf) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1792 | mwifiex_dbg(adapter, DATA, |
| 1793 | "data: %s: send current buffer %d\n", |
| 1794 | __func__, port); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1795 | ret = mwifiex_write_data_to_card(adapter, payload, pkt_len, |
| 1796 | adapter->ioport + port); |
| 1797 | } |
| 1798 | |
| 1799 | if (f_postcopy_cur_buf) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1800 | mwifiex_dbg(adapter, DATA, |
| 1801 | "data: %s: postcopy current buffer\n", |
| 1802 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1803 | MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port); |
| 1804 | } |
| 1805 | |
| 1806 | return ret; |
| 1807 | } |
| 1808 | |
| 1809 | /* |
| 1810 | * This function downloads data from driver to card. |
| 1811 | * |
| 1812 | * Both commands and data packets are transferred to the card by this |
| 1813 | * function. |
| 1814 | * |
| 1815 | * This function adds the SDIO specific header to the front of the buffer |
| 1816 | * before transferring. The header contains the length of the packet and |
| 1817 | * the type. The firmware handles the packets based upon this set type. |
| 1818 | */ |
| 1819 | static int mwifiex_sdio_host_to_card(struct mwifiex_adapter *adapter, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1820 | u8 type, struct sk_buff *skb, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1821 | struct mwifiex_tx_param *tx_param) |
| 1822 | { |
| 1823 | struct sdio_mmc_card *card = adapter->card; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1824 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1825 | u32 buf_block_len; |
| 1826 | u32 blk_size; |
Amitkumar Karwar | 0fc0d43 | 2013-05-17 17:54:23 -0700 | [diff] [blame] | 1827 | u32 port = CTRL_PORT; |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 1828 | u8 *payload = (u8 *)skb->data; |
| 1829 | u32 pkt_len = skb->len; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1830 | |
| 1831 | /* Allocate buffer and copy payload */ |
| 1832 | blk_size = MWIFIEX_SDIO_BLOCK_SIZE; |
| 1833 | buf_block_len = (pkt_len + blk_size - 1) / blk_size; |
Tomasz Moń | 83e612f | 2013-07-23 07:42:49 +0200 | [diff] [blame] | 1834 | *(__le16 *)&payload[0] = cpu_to_le16((u16)pkt_len); |
| 1835 | *(__le16 *)&payload[2] = cpu_to_le16(type); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1836 | |
| 1837 | /* |
| 1838 | * This is SDIO specific header |
| 1839 | * u16 length, |
| 1840 | * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1, |
| 1841 | * MWIFIEX_TYPE_EVENT = 3) |
| 1842 | */ |
| 1843 | if (type == MWIFIEX_TYPE_DATA) { |
| 1844 | ret = mwifiex_get_wr_port_data(adapter, &port); |
| 1845 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1846 | mwifiex_dbg(adapter, ERROR, |
| 1847 | "%s: no wr_port available\n", |
| 1848 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1849 | return ret; |
| 1850 | } |
| 1851 | } else { |
| 1852 | adapter->cmd_sent = true; |
| 1853 | /* Type must be MWIFIEX_TYPE_CMD */ |
| 1854 | |
| 1855 | if (pkt_len <= INTF_HEADER_LEN || |
| 1856 | pkt_len > MWIFIEX_UPLD_SIZE) |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1857 | mwifiex_dbg(adapter, ERROR, |
| 1858 | "%s: payload=%p, nb=%d\n", |
| 1859 | __func__, payload, pkt_len); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 1860 | |
| 1861 | if (card->supports_sdio_new_mode) |
| 1862 | port = CMD_PORT_SLCT; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | /* Transfer data to card */ |
| 1866 | pkt_len = buf_block_len * blk_size; |
| 1867 | |
| 1868 | if (tx_param) |
| 1869 | ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len, |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 1870 | port, tx_param->next_pkt_len |
| 1871 | ); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1872 | else |
| 1873 | ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len, |
Yogesh Ashok Powar | 5dbd326 | 2012-03-13 19:22:39 -0700 | [diff] [blame] | 1874 | port, 0); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1875 | |
| 1876 | if (ret) { |
| 1877 | if (type == MWIFIEX_TYPE_CMD) |
| 1878 | adapter->cmd_sent = false; |
Avinash Patil | bb71d01 | 2014-05-13 19:49:42 -0700 | [diff] [blame] | 1879 | if (type == MWIFIEX_TYPE_DATA) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1880 | adapter->data_sent = false; |
Avinash Patil | bb71d01 | 2014-05-13 19:49:42 -0700 | [diff] [blame] | 1881 | /* restore curr_wr_port in error cases */ |
| 1882 | card->curr_wr_port = port; |
| 1883 | card->mp_wr_bitmap |= (u32)(1 << card->curr_wr_port); |
| 1884 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1885 | } else { |
| 1886 | if (type == MWIFIEX_TYPE_DATA) { |
| 1887 | if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port))) |
| 1888 | adapter->data_sent = true; |
| 1889 | else |
| 1890 | adapter->data_sent = false; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | return ret; |
| 1895 | } |
| 1896 | |
| 1897 | /* |
| 1898 | * This function allocates the MPA Tx and Rx buffers. |
| 1899 | */ |
| 1900 | static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter, |
| 1901 | u32 mpa_tx_buf_size, u32 mpa_rx_buf_size) |
| 1902 | { |
| 1903 | struct sdio_mmc_card *card = adapter->card; |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1904 | u32 rx_buf_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1905 | int ret = 0; |
| 1906 | |
| 1907 | card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL); |
| 1908 | if (!card->mpa_tx.buf) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1909 | ret = -1; |
| 1910 | goto error; |
| 1911 | } |
| 1912 | |
| 1913 | card->mpa_tx.buf_size = mpa_tx_buf_size; |
| 1914 | |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1915 | rx_buf_size = max_t(u32, mpa_rx_buf_size, |
| 1916 | (u32)SDIO_MAX_AGGR_BUF_SIZE); |
| 1917 | card->mpa_rx.buf = kzalloc(rx_buf_size, GFP_KERNEL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1918 | if (!card->mpa_rx.buf) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1919 | ret = -1; |
| 1920 | goto error; |
| 1921 | } |
| 1922 | |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 1923 | card->mpa_rx.buf_size = rx_buf_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1924 | |
| 1925 | error: |
| 1926 | if (ret) { |
| 1927 | kfree(card->mpa_tx.buf); |
| 1928 | kfree(card->mpa_rx.buf); |
Xinming Hu | e3ad3d5 | 2015-09-18 06:32:05 -0700 | [diff] [blame] | 1929 | card->mpa_tx.buf_size = 0; |
| 1930 | card->mpa_rx.buf_size = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | return ret; |
| 1934 | } |
| 1935 | |
| 1936 | /* |
| 1937 | * This function unregisters the SDIO device. |
| 1938 | * |
| 1939 | * The SDIO IRQ is released, the function is disabled and driver |
| 1940 | * data is set to null. |
| 1941 | */ |
| 1942 | static void |
| 1943 | mwifiex_unregister_dev(struct mwifiex_adapter *adapter) |
| 1944 | { |
| 1945 | struct sdio_mmc_card *card = adapter->card; |
| 1946 | |
| 1947 | if (adapter->card) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1948 | sdio_claim_host(card->func); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1949 | sdio_disable_func(card->func); |
| 1950 | sdio_release_host(card->func); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | /* |
| 1955 | * This function registers the SDIO device. |
| 1956 | * |
| 1957 | * SDIO IRQ is claimed, block size is set and driver data is initialized. |
| 1958 | */ |
| 1959 | static int mwifiex_register_dev(struct mwifiex_adapter *adapter) |
| 1960 | { |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 1961 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1962 | struct sdio_mmc_card *card = adapter->card; |
| 1963 | struct sdio_func *func = card->func; |
| 1964 | |
| 1965 | /* save adapter pointer in card */ |
| 1966 | card->adapter = adapter; |
Amitkumar Karwar | 828cf22 | 2014-02-27 19:35:13 -0800 | [diff] [blame] | 1967 | adapter->tx_buf_size = card->tx_buf_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1968 | |
| 1969 | sdio_claim_host(func); |
| 1970 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1971 | /* Set block size */ |
| 1972 | ret = sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE); |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 1973 | sdio_release_host(func); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1974 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 1975 | mwifiex_dbg(adapter, ERROR, |
| 1976 | "cannot set SDIO block size\n"); |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 1977 | return ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1980 | |
| 1981 | adapter->dev = &func->dev; |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 1982 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 1983 | strcpy(adapter->fw_name, card->firmware); |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 1984 | if (card->fw_dump_enh) { |
| 1985 | adapter->mem_type_mapping_tbl = generic_mem_type_map; |
| 1986 | adapter->num_mem_types = 1; |
| 1987 | } else { |
| 1988 | adapter->mem_type_mapping_tbl = mem_type_mapping_tbl; |
| 1989 | adapter->num_mem_types = ARRAY_SIZE(mem_type_mapping_tbl); |
| 1990 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1991 | |
| 1992 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | /* |
| 1996 | * This function initializes the SDIO driver. |
| 1997 | * |
| 1998 | * The following initializations steps are followed - |
| 1999 | * - Read the Host interrupt status register to acknowledge |
| 2000 | * the first interrupt got from bootloader |
| 2001 | * - Disable host interrupt mask register |
| 2002 | * - Get SDIO port |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2003 | * - Initialize SDIO variables in card |
| 2004 | * - Allocate MP registers |
| 2005 | * - Allocate MPA Tx and Rx buffers |
| 2006 | */ |
| 2007 | static int mwifiex_init_sdio(struct mwifiex_adapter *adapter) |
| 2008 | { |
| 2009 | struct sdio_mmc_card *card = adapter->card; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2010 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2011 | int ret; |
Amitkumar Karwar | ab93d4f | 2013-05-17 17:53:42 -0700 | [diff] [blame] | 2012 | u8 sdio_ireg; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2013 | |
Amitkumar Karwar | 3c59e32 | 2013-11-14 19:10:41 -0800 | [diff] [blame] | 2014 | sdio_set_drvdata(card->func, card); |
| 2015 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2016 | /* |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 2017 | * Read the host_int_status_reg for ACK the first interrupt got |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2018 | * from the bootloader. If we don't do this we get a interrupt |
| 2019 | * as soon as we register the irq. |
| 2020 | */ |
Avinash Patil | 554a011 | 2014-10-01 10:55:25 -0700 | [diff] [blame] | 2021 | mwifiex_read_reg(adapter, card->reg->host_int_status_reg, &sdio_ireg); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2022 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2023 | /* Get SDIO ioport */ |
| 2024 | mwifiex_init_sdio_ioport(adapter); |
| 2025 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2026 | /* Initialize SDIO variables in card */ |
| 2027 | card->mp_rd_bitmap = 0; |
| 2028 | card->mp_wr_bitmap = 0; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2029 | card->curr_rd_port = reg->start_rd_port; |
| 2030 | card->curr_wr_port = reg->start_wr_port; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2031 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2032 | card->mp_data_port_mask = reg->data_port_mask; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2033 | |
| 2034 | card->mpa_tx.buf_len = 0; |
| 2035 | card->mpa_tx.pkt_cnt = 0; |
| 2036 | card->mpa_tx.start_port = 0; |
| 2037 | |
Amitkumar Karwar | 7d7ab02 | 2011-11-07 19:31:46 -0800 | [diff] [blame] | 2038 | card->mpa_tx.enabled = 1; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2039 | card->mpa_tx.pkt_aggr_limit = card->mp_agg_pkt_limit; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2040 | |
| 2041 | card->mpa_rx.buf_len = 0; |
| 2042 | card->mpa_rx.pkt_cnt = 0; |
| 2043 | card->mpa_rx.start_port = 0; |
| 2044 | |
Amitkumar Karwar | 7d7ab02 | 2011-11-07 19:31:46 -0800 | [diff] [blame] | 2045 | card->mpa_rx.enabled = 1; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2046 | card->mpa_rx.pkt_aggr_limit = card->mp_agg_pkt_limit; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2047 | |
| 2048 | /* Allocate buffers for SDIO MP-A */ |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2049 | card->mp_regs = kzalloc(reg->max_mp_regs, GFP_KERNEL); |
Joe Perches | 0d2e7a5 | 2013-02-03 17:28:14 +0000 | [diff] [blame] | 2050 | if (!card->mp_regs) |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 2051 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2052 | |
Amitkumar Karwar | c23b7c8 | 2013-05-17 17:54:51 -0700 | [diff] [blame] | 2053 | /* Allocate skb pointer buffers */ |
| 2054 | card->mpa_rx.skb_arr = kzalloc((sizeof(void *)) * |
| 2055 | card->mp_agg_pkt_limit, GFP_KERNEL); |
| 2056 | card->mpa_rx.len_arr = kzalloc(sizeof(*card->mpa_rx.len_arr) * |
| 2057 | card->mp_agg_pkt_limit, GFP_KERNEL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2058 | ret = mwifiex_alloc_sdio_mpa_buffers(adapter, |
Amitkumar Karwar | e1aa93a4 | 2014-04-14 15:32:50 -0700 | [diff] [blame] | 2059 | card->mp_tx_agg_buf_size, |
| 2060 | card->mp_rx_agg_buf_size); |
Xinming Hu | 9a9053c | 2015-09-18 06:32:06 -0700 | [diff] [blame] | 2061 | |
| 2062 | /* Allocate 32k MPA Tx/Rx buffers if 64k memory allocation fails */ |
| 2063 | if (ret && (card->mp_tx_agg_buf_size == MWIFIEX_MP_AGGR_BUF_SIZE_MAX || |
| 2064 | card->mp_rx_agg_buf_size == MWIFIEX_MP_AGGR_BUF_SIZE_MAX)) { |
| 2065 | /* Disable rx single port aggregation */ |
| 2066 | adapter->host_disable_sdio_rx_aggr = true; |
| 2067 | |
| 2068 | ret = mwifiex_alloc_sdio_mpa_buffers |
| 2069 | (adapter, MWIFIEX_MP_AGGR_BUF_SIZE_32K, |
| 2070 | MWIFIEX_MP_AGGR_BUF_SIZE_32K); |
| 2071 | if (ret) { |
| 2072 | /* Disable multi port aggregation */ |
| 2073 | card->mpa_tx.enabled = 0; |
| 2074 | card->mpa_rx.enabled = 0; |
| 2075 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
Avinash Patil | b4e8aeb | 2015-02-11 23:12:26 +0530 | [diff] [blame] | 2078 | adapter->auto_tdls = card->can_auto_tdls; |
Avinash Patil | 1fe192d | 2015-01-23 17:09:19 +0530 | [diff] [blame] | 2079 | adapter->ext_scan = card->can_ext_scan; |
Xinming Hu | 9a9053c | 2015-09-18 06:32:06 -0700 | [diff] [blame] | 2080 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | /* |
| 2084 | * This function resets the MPA Tx and Rx buffers. |
| 2085 | */ |
| 2086 | static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter *adapter) |
| 2087 | { |
| 2088 | struct sdio_mmc_card *card = adapter->card; |
| 2089 | |
| 2090 | MP_TX_AGGR_BUF_RESET(card); |
| 2091 | MP_RX_AGGR_BUF_RESET(card); |
| 2092 | } |
| 2093 | |
| 2094 | /* |
| 2095 | * This function cleans up the allocated card buffers. |
| 2096 | * |
| 2097 | * The following are freed by this function - |
| 2098 | * - MP registers |
| 2099 | * - MPA Tx buffer |
| 2100 | * - MPA Rx buffer |
| 2101 | */ |
| 2102 | static void mwifiex_cleanup_sdio(struct mwifiex_adapter *adapter) |
| 2103 | { |
| 2104 | struct sdio_mmc_card *card = adapter->card; |
| 2105 | |
| 2106 | kfree(card->mp_regs); |
Amitkumar Karwar | c23b7c8 | 2013-05-17 17:54:51 -0700 | [diff] [blame] | 2107 | kfree(card->mpa_rx.skb_arr); |
| 2108 | kfree(card->mpa_rx.len_arr); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2109 | kfree(card->mpa_tx.buf); |
| 2110 | kfree(card->mpa_rx.buf); |
Amitkumar Karwar | 3c59e32 | 2013-11-14 19:10:41 -0800 | [diff] [blame] | 2111 | sdio_set_drvdata(card->func, NULL); |
| 2112 | kfree(card); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | /* |
| 2116 | * This function updates the MP end port in card. |
| 2117 | */ |
| 2118 | static void |
| 2119 | mwifiex_update_mp_end_port(struct mwifiex_adapter *adapter, u16 port) |
| 2120 | { |
| 2121 | struct sdio_mmc_card *card = adapter->card; |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2122 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2123 | int i; |
| 2124 | |
| 2125 | card->mp_end_port = port; |
| 2126 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2127 | card->mp_data_port_mask = reg->data_port_mask; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2128 | |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 2129 | if (reg->start_wr_port) { |
| 2130 | for (i = 1; i <= card->max_ports - card->mp_end_port; i++) |
| 2131 | card->mp_data_port_mask &= |
| 2132 | ~(1 << (card->max_ports - i)); |
| 2133 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2134 | |
Amitkumar Karwar | 05889f8 | 2013-05-17 17:50:27 -0700 | [diff] [blame] | 2135 | card->curr_wr_port = reg->start_wr_port; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2136 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2137 | mwifiex_dbg(adapter, CMD, |
| 2138 | "cmd: mp_end_port %d, data port mask 0x%x\n", |
| 2139 | port, card->mp_data_port_mask); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
Andreas Fenkart | b4336a2 | 2015-07-16 18:50:01 +0200 | [diff] [blame] | 2142 | static void mwifiex_recreate_adapter(struct sdio_mmc_card *card) |
| 2143 | { |
| 2144 | struct sdio_func *func = card->func; |
| 2145 | const struct sdio_device_id *device_id = card->device_id; |
| 2146 | |
| 2147 | /* TODO mmc_hw_reset does not require destroying and re-probing the |
| 2148 | * whole adapter. Hence there was no need to for this rube-goldberg |
| 2149 | * design to reload the fw from an external workqueue. If we don't |
| 2150 | * destroy the adapter we could reload the fw from |
| 2151 | * mwifiex_main_work_queue directly. |
| 2152 | * The real difficulty with fw reset is to restore all the user |
| 2153 | * settings applied through ioctl. By destroying and recreating the |
| 2154 | * adapter, we take the easy way out, since we rely on user space to |
| 2155 | * restore them. We assume that user space will treat the new |
| 2156 | * incarnation of the adapter(interfaces) as if they had been just |
| 2157 | * discovered and initializes them from scratch. |
| 2158 | */ |
| 2159 | |
| 2160 | mwifiex_sdio_remove(func); |
| 2161 | |
| 2162 | /* power cycle the adapter */ |
| 2163 | sdio_claim_host(func); |
| 2164 | mmc_hw_reset(func->card->host); |
| 2165 | sdio_release_host(func); |
| 2166 | |
| 2167 | mwifiex_sdio_probe(func, device_id); |
| 2168 | } |
| 2169 | |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2170 | static struct mwifiex_adapter *save_adapter; |
Amitkumar Karwar | 088df42 | 2014-06-19 21:38:54 -0700 | [diff] [blame] | 2171 | static void mwifiex_sdio_card_reset_work(struct mwifiex_adapter *adapter) |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 2172 | { |
Amitkumar Karwar | 088df42 | 2014-06-19 21:38:54 -0700 | [diff] [blame] | 2173 | struct sdio_mmc_card *card = adapter->card; |
Tejun Heo | 7f5855c | 2012-12-21 17:56:57 -0800 | [diff] [blame] | 2174 | |
Andreas Fenkart | b4336a2 | 2015-07-16 18:50:01 +0200 | [diff] [blame] | 2175 | /* TODO card pointer is unprotected. If the adapter is removed |
| 2176 | * physically, sdio core might trigger mwifiex_sdio_remove, before this |
| 2177 | * workqueue is run, which will destroy the adapter struct. When this |
| 2178 | * workqueue eventually exceutes it will dereference an invalid adapter |
| 2179 | * pointer |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 2180 | */ |
Andreas Fenkart | b4336a2 | 2015-07-16 18:50:01 +0200 | [diff] [blame] | 2181 | mwifiex_recreate_adapter(card); |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 2182 | } |
Amitkumar Karwar | 8915d738 | 2014-06-19 21:38:53 -0700 | [diff] [blame] | 2183 | |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2184 | /* This function read/write firmware */ |
| 2185 | static enum |
| 2186 | rdwr_status mwifiex_sdio_rdwr_firmware(struct mwifiex_adapter *adapter, |
| 2187 | u8 doneflag) |
| 2188 | { |
| 2189 | struct sdio_mmc_card *card = adapter->card; |
| 2190 | int ret, tries; |
| 2191 | u8 ctrl_data = 0; |
| 2192 | |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 2193 | sdio_writeb(card->func, card->reg->fw_dump_host_ready, |
| 2194 | card->reg->fw_dump_ctrl, &ret); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2195 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2196 | mwifiex_dbg(adapter, ERROR, "SDIO Write ERR\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2197 | return RDWR_STATUS_FAILURE; |
| 2198 | } |
| 2199 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { |
| 2200 | ctrl_data = sdio_readb(card->func, card->reg->fw_dump_ctrl, |
| 2201 | &ret); |
| 2202 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2203 | mwifiex_dbg(adapter, ERROR, "SDIO read err\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2204 | return RDWR_STATUS_FAILURE; |
| 2205 | } |
| 2206 | if (ctrl_data == FW_DUMP_DONE) |
| 2207 | break; |
| 2208 | if (doneflag && ctrl_data == doneflag) |
| 2209 | return RDWR_STATUS_DONE; |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 2210 | if (ctrl_data != card->reg->fw_dump_host_ready) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2211 | mwifiex_dbg(adapter, WARN, |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 2212 | "The ctrl reg was changed, re-try again\n"); |
| 2213 | sdio_writeb(card->func, card->reg->fw_dump_host_ready, |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2214 | card->reg->fw_dump_ctrl, &ret); |
| 2215 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2216 | mwifiex_dbg(adapter, ERROR, "SDIO write err\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2217 | return RDWR_STATUS_FAILURE; |
| 2218 | } |
| 2219 | } |
| 2220 | usleep_range(100, 200); |
| 2221 | } |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 2222 | if (ctrl_data == card->reg->fw_dump_host_ready) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2223 | mwifiex_dbg(adapter, ERROR, |
| 2224 | "Fail to pull ctrl_data\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2225 | return RDWR_STATUS_FAILURE; |
| 2226 | } |
| 2227 | |
| 2228 | return RDWR_STATUS_SUCCESS; |
| 2229 | } |
| 2230 | |
| 2231 | /* This function dump firmware memory to file */ |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2232 | static void mwifiex_sdio_fw_dump(struct mwifiex_adapter *adapter) |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2233 | { |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2234 | struct sdio_mmc_card *card = adapter->card; |
| 2235 | int ret = 0; |
| 2236 | unsigned int reg, reg_start, reg_end; |
| 2237 | u8 *dbg_ptr, *end_ptr, dump_num, idx, i, read_reg, doneflag = 0; |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2238 | enum rdwr_status stat; |
| 2239 | u32 memory_size; |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2240 | |
Avinash Patil | b4e8aeb | 2015-02-11 23:12:26 +0530 | [diff] [blame] | 2241 | if (!card->can_dump_fw) |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2242 | return; |
| 2243 | |
| 2244 | for (idx = 0; idx < ARRAY_SIZE(mem_type_mapping_tbl); idx++) { |
| 2245 | struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx]; |
| 2246 | |
| 2247 | if (entry->mem_ptr) { |
| 2248 | vfree(entry->mem_ptr); |
| 2249 | entry->mem_ptr = NULL; |
| 2250 | } |
| 2251 | entry->mem_size = 0; |
| 2252 | } |
| 2253 | |
| 2254 | mwifiex_pm_wakeup_card(adapter); |
| 2255 | sdio_claim_host(card->func); |
| 2256 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2257 | mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump start ==\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2258 | |
| 2259 | stat = mwifiex_sdio_rdwr_firmware(adapter, doneflag); |
| 2260 | if (stat == RDWR_STATUS_FAILURE) |
| 2261 | goto done; |
| 2262 | |
| 2263 | reg = card->reg->fw_dump_start; |
| 2264 | /* Read the number of the memories which will dump */ |
| 2265 | dump_num = sdio_readb(card->func, reg, &ret); |
| 2266 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2267 | mwifiex_dbg(adapter, ERROR, "SDIO read memory length err\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2268 | goto done; |
| 2269 | } |
| 2270 | |
| 2271 | /* Read the length of every memory which will dump */ |
| 2272 | for (idx = 0; idx < dump_num; idx++) { |
| 2273 | struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx]; |
| 2274 | |
| 2275 | stat = mwifiex_sdio_rdwr_firmware(adapter, doneflag); |
| 2276 | if (stat == RDWR_STATUS_FAILURE) |
| 2277 | goto done; |
| 2278 | |
| 2279 | memory_size = 0; |
| 2280 | reg = card->reg->fw_dump_start; |
| 2281 | for (i = 0; i < 4; i++) { |
| 2282 | read_reg = sdio_readb(card->func, reg, &ret); |
| 2283 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2284 | mwifiex_dbg(adapter, ERROR, "SDIO read err\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2285 | goto done; |
| 2286 | } |
| 2287 | memory_size |= (read_reg << i*8); |
| 2288 | reg++; |
| 2289 | } |
| 2290 | |
| 2291 | if (memory_size == 0) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2292 | mwifiex_dbg(adapter, DUMP, "Firmware dump Finished!\n"); |
Amitkumar Karwar | e065ddb | 2015-05-26 06:34:27 -0700 | [diff] [blame] | 2293 | ret = mwifiex_write_reg(adapter, |
| 2294 | card->reg->fw_dump_ctrl, |
| 2295 | FW_DUMP_READ_DONE); |
| 2296 | if (ret) { |
| 2297 | mwifiex_dbg(adapter, ERROR, "SDIO write err\n"); |
| 2298 | return; |
| 2299 | } |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2300 | break; |
| 2301 | } |
| 2302 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2303 | mwifiex_dbg(adapter, DUMP, |
| 2304 | "%s_SIZE=0x%x\n", entry->mem_name, memory_size); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2305 | entry->mem_ptr = vmalloc(memory_size + 1); |
| 2306 | entry->mem_size = memory_size; |
| 2307 | if (!entry->mem_ptr) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2308 | mwifiex_dbg(adapter, ERROR, "Vmalloc %s failed\n", |
| 2309 | entry->mem_name); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2310 | goto done; |
| 2311 | } |
| 2312 | dbg_ptr = entry->mem_ptr; |
| 2313 | end_ptr = dbg_ptr + memory_size; |
| 2314 | |
| 2315 | doneflag = entry->done_flag; |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2316 | mwifiex_dbg(adapter, DUMP, |
| 2317 | "Start %s output, please wait...\n", |
| 2318 | entry->mem_name); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2319 | |
| 2320 | do { |
| 2321 | stat = mwifiex_sdio_rdwr_firmware(adapter, doneflag); |
| 2322 | if (stat == RDWR_STATUS_FAILURE) |
| 2323 | goto done; |
| 2324 | |
| 2325 | reg_start = card->reg->fw_dump_start; |
| 2326 | reg_end = card->reg->fw_dump_end; |
| 2327 | for (reg = reg_start; reg <= reg_end; reg++) { |
| 2328 | *dbg_ptr = sdio_readb(card->func, reg, &ret); |
| 2329 | if (ret) { |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2330 | mwifiex_dbg(adapter, ERROR, |
| 2331 | "SDIO read err\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2332 | goto done; |
| 2333 | } |
| 2334 | if (dbg_ptr < end_ptr) |
| 2335 | dbg_ptr++; |
| 2336 | else |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2337 | mwifiex_dbg(adapter, ERROR, |
| 2338 | "Allocated buf not enough\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | if (stat != RDWR_STATUS_DONE) |
| 2342 | continue; |
| 2343 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2344 | mwifiex_dbg(adapter, DUMP, "%s done: size=0x%tx\n", |
| 2345 | entry->mem_name, dbg_ptr - entry->mem_ptr); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2346 | break; |
| 2347 | } while (1); |
| 2348 | } |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2349 | mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump end ==\n"); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2350 | |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2351 | done: |
| 2352 | sdio_release_host(card->func); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 2355 | static void mwifiex_sdio_generic_fw_dump(struct mwifiex_adapter *adapter) |
| 2356 | { |
| 2357 | struct sdio_mmc_card *card = adapter->card; |
| 2358 | struct memory_type_mapping *entry = &generic_mem_type_map[0]; |
| 2359 | unsigned int reg, reg_start, reg_end; |
| 2360 | u8 start_flag = 0, done_flag = 0; |
| 2361 | u8 *dbg_ptr, *end_ptr; |
| 2362 | enum rdwr_status stat; |
| 2363 | int ret = -1, tries; |
| 2364 | |
| 2365 | if (!card->fw_dump_enh) |
| 2366 | return; |
| 2367 | |
| 2368 | if (entry->mem_ptr) { |
| 2369 | vfree(entry->mem_ptr); |
| 2370 | entry->mem_ptr = NULL; |
| 2371 | } |
| 2372 | entry->mem_size = 0; |
| 2373 | |
| 2374 | mwifiex_pm_wakeup_card(adapter); |
| 2375 | sdio_claim_host(card->func); |
| 2376 | |
| 2377 | mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump start ==\n"); |
| 2378 | |
| 2379 | stat = mwifiex_sdio_rdwr_firmware(adapter, done_flag); |
| 2380 | if (stat == RDWR_STATUS_FAILURE) |
| 2381 | goto done; |
| 2382 | |
| 2383 | reg_start = card->reg->fw_dump_start; |
| 2384 | reg_end = card->reg->fw_dump_end; |
| 2385 | for (reg = reg_start; reg <= reg_end; reg++) { |
| 2386 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { |
| 2387 | start_flag = sdio_readb(card->func, reg, &ret); |
| 2388 | if (ret) { |
| 2389 | mwifiex_dbg(adapter, ERROR, |
| 2390 | "SDIO read err\n"); |
| 2391 | goto done; |
| 2392 | } |
| 2393 | if (start_flag == 0) |
| 2394 | break; |
| 2395 | if (tries == MAX_POLL_TRIES) { |
| 2396 | mwifiex_dbg(adapter, ERROR, |
| 2397 | "FW not ready to dump\n"); |
| 2398 | ret = -1; |
| 2399 | goto done; |
| 2400 | } |
| 2401 | } |
| 2402 | usleep_range(100, 200); |
| 2403 | } |
| 2404 | |
| 2405 | entry->mem_ptr = vmalloc(0xf0000 + 1); |
| 2406 | if (!entry->mem_ptr) { |
| 2407 | ret = -1; |
| 2408 | goto done; |
| 2409 | } |
| 2410 | dbg_ptr = entry->mem_ptr; |
| 2411 | entry->mem_size = 0xf0000; |
| 2412 | end_ptr = dbg_ptr + entry->mem_size; |
| 2413 | |
| 2414 | done_flag = entry->done_flag; |
| 2415 | mwifiex_dbg(adapter, DUMP, |
| 2416 | "Start %s output, please wait...\n", entry->mem_name); |
| 2417 | |
| 2418 | while (true) { |
| 2419 | stat = mwifiex_sdio_rdwr_firmware(adapter, done_flag); |
| 2420 | if (stat == RDWR_STATUS_FAILURE) |
| 2421 | goto done; |
| 2422 | for (reg = reg_start; reg <= reg_end; reg++) { |
| 2423 | *dbg_ptr = sdio_readb(card->func, reg, &ret); |
| 2424 | if (ret) { |
| 2425 | mwifiex_dbg(adapter, ERROR, |
| 2426 | "SDIO read err\n"); |
| 2427 | goto done; |
| 2428 | } |
| 2429 | dbg_ptr++; |
| 2430 | if (dbg_ptr >= end_ptr) { |
| 2431 | u8 *tmp_ptr; |
| 2432 | |
| 2433 | tmp_ptr = vmalloc(entry->mem_size + 0x4000 + 1); |
| 2434 | if (!tmp_ptr) |
| 2435 | goto done; |
| 2436 | |
| 2437 | memcpy(tmp_ptr, entry->mem_ptr, |
| 2438 | entry->mem_size); |
| 2439 | vfree(entry->mem_ptr); |
| 2440 | entry->mem_ptr = tmp_ptr; |
| 2441 | tmp_ptr = NULL; |
| 2442 | dbg_ptr = entry->mem_ptr + entry->mem_size; |
| 2443 | entry->mem_size += 0x4000; |
| 2444 | end_ptr = entry->mem_ptr + entry->mem_size; |
| 2445 | } |
| 2446 | } |
| 2447 | if (stat == RDWR_STATUS_DONE) { |
| 2448 | entry->mem_size = dbg_ptr - entry->mem_ptr; |
| 2449 | mwifiex_dbg(adapter, DUMP, "dump %s done size=0x%x\n", |
| 2450 | entry->mem_name, entry->mem_size); |
| 2451 | ret = 0; |
| 2452 | break; |
| 2453 | } |
| 2454 | } |
| 2455 | mwifiex_dbg(adapter, MSG, "== mwifiex firmware dump end ==\n"); |
| 2456 | |
| 2457 | done: |
| 2458 | if (ret) { |
| 2459 | mwifiex_dbg(adapter, ERROR, "firmware dump failed\n"); |
| 2460 | if (entry->mem_ptr) { |
| 2461 | vfree(entry->mem_ptr); |
| 2462 | entry->mem_ptr = NULL; |
| 2463 | } |
| 2464 | entry->mem_size = 0; |
| 2465 | } |
| 2466 | sdio_release_host(card->func); |
| 2467 | } |
| 2468 | |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2469 | static void mwifiex_sdio_device_dump_work(struct mwifiex_adapter *adapter) |
| 2470 | { |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 2471 | struct sdio_mmc_card *card = adapter->card; |
| 2472 | |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2473 | mwifiex_drv_info_dump(adapter); |
Zhaoyang Liu | eee7f19 | 2015-08-05 06:09:41 -0700 | [diff] [blame] | 2474 | if (card->fw_dump_enh) |
| 2475 | mwifiex_sdio_generic_fw_dump(adapter); |
| 2476 | else |
| 2477 | mwifiex_sdio_fw_dump(adapter); |
Amitkumar Karwar | 57670ee | 2015-05-26 06:34:32 -0700 | [diff] [blame] | 2478 | mwifiex_upload_device_dump(adapter); |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Amitkumar Karwar | 8915d738 | 2014-06-19 21:38:53 -0700 | [diff] [blame] | 2481 | static void mwifiex_sdio_work(struct work_struct *work) |
| 2482 | { |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2483 | if (test_and_clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2484 | &iface_work_flags)) |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2485 | mwifiex_sdio_device_dump_work(save_adapter); |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2486 | if (test_and_clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET, |
| 2487 | &iface_work_flags)) |
| 2488 | mwifiex_sdio_card_reset_work(save_adapter); |
Amitkumar Karwar | 8915d738 | 2014-06-19 21:38:53 -0700 | [diff] [blame] | 2489 | } |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 2490 | |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2491 | static DECLARE_WORK(sdio_work, mwifiex_sdio_work); |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 2492 | /* This function resets the card */ |
| 2493 | static void mwifiex_sdio_card_reset(struct mwifiex_adapter *adapter) |
| 2494 | { |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2495 | save_adapter = adapter; |
| 2496 | if (test_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &iface_work_flags)) |
Amitkumar Karwar | 8915d738 | 2014-06-19 21:38:53 -0700 | [diff] [blame] | 2497 | return; |
| 2498 | |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2499 | set_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &iface_work_flags); |
Amitkumar Karwar | 8915d738 | 2014-06-19 21:38:53 -0700 | [diff] [blame] | 2500 | |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2501 | schedule_work(&sdio_work); |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2504 | /* This function dumps FW information */ |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2505 | static void mwifiex_sdio_device_dump(struct mwifiex_adapter *adapter) |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2506 | { |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2507 | save_adapter = adapter; |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2508 | if (test_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &iface_work_flags)) |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2509 | return; |
| 2510 | |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2511 | set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &iface_work_flags); |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2512 | schedule_work(&sdio_work); |
Amitkumar Karwar | 54881c6 | 2014-06-19 21:38:55 -0700 | [diff] [blame] | 2513 | } |
| 2514 | |
Xinming Hu | 809c6ea | 2014-12-23 19:14:11 +0530 | [diff] [blame] | 2515 | /* Function to dump SDIO function registers and SDIO scratch registers in case |
| 2516 | * of FW crash |
| 2517 | */ |
| 2518 | static int |
| 2519 | mwifiex_sdio_reg_dump(struct mwifiex_adapter *adapter, char *drv_buf) |
| 2520 | { |
| 2521 | char *p = drv_buf; |
| 2522 | struct sdio_mmc_card *cardp = adapter->card; |
| 2523 | int ret = 0; |
| 2524 | u8 count, func, data, index = 0, size = 0; |
| 2525 | u8 reg, reg_start, reg_end; |
| 2526 | char buf[256], *ptr; |
| 2527 | |
| 2528 | if (!p) |
| 2529 | return 0; |
| 2530 | |
Amitkumar Karwar | 9cc0dbf0 | 2015-05-26 06:34:30 -0700 | [diff] [blame] | 2531 | mwifiex_dbg(adapter, MSG, "SDIO register dump start\n"); |
Xinming Hu | 809c6ea | 2014-12-23 19:14:11 +0530 | [diff] [blame] | 2532 | |
| 2533 | mwifiex_pm_wakeup_card(adapter); |
| 2534 | |
| 2535 | sdio_claim_host(cardp->func); |
| 2536 | |
| 2537 | for (count = 0; count < 5; count++) { |
| 2538 | memset(buf, 0, sizeof(buf)); |
| 2539 | ptr = buf; |
| 2540 | |
| 2541 | switch (count) { |
| 2542 | case 0: |
| 2543 | /* Read the registers of SDIO function0 */ |
| 2544 | func = count; |
| 2545 | reg_start = 0; |
| 2546 | reg_end = 9; |
| 2547 | break; |
| 2548 | case 1: |
| 2549 | /* Read the registers of SDIO function1 */ |
| 2550 | func = count; |
| 2551 | reg_start = cardp->reg->func1_dump_reg_start; |
| 2552 | reg_end = cardp->reg->func1_dump_reg_end; |
| 2553 | break; |
| 2554 | case 2: |
| 2555 | index = 0; |
| 2556 | func = 1; |
| 2557 | reg_start = cardp->reg->func1_spec_reg_table[index++]; |
| 2558 | size = cardp->reg->func1_spec_reg_num; |
| 2559 | reg_end = cardp->reg->func1_spec_reg_table[size-1]; |
| 2560 | break; |
| 2561 | default: |
| 2562 | /* Read the scratch registers of SDIO function1 */ |
| 2563 | if (count == 4) |
| 2564 | mdelay(100); |
| 2565 | func = 1; |
| 2566 | reg_start = cardp->reg->func1_scratch_reg; |
| 2567 | reg_end = reg_start + MWIFIEX_SDIO_SCRATCH_SIZE; |
| 2568 | } |
| 2569 | |
| 2570 | if (count != 2) |
| 2571 | ptr += sprintf(ptr, "SDIO Func%d (%#x-%#x): ", |
| 2572 | func, reg_start, reg_end); |
| 2573 | else |
| 2574 | ptr += sprintf(ptr, "SDIO Func%d: ", func); |
| 2575 | |
| 2576 | for (reg = reg_start; reg <= reg_end;) { |
| 2577 | if (func == 0) |
| 2578 | data = sdio_f0_readb(cardp->func, reg, &ret); |
| 2579 | else |
| 2580 | data = sdio_readb(cardp->func, reg, &ret); |
| 2581 | |
| 2582 | if (count == 2) |
| 2583 | ptr += sprintf(ptr, "(%#x) ", reg); |
| 2584 | if (!ret) { |
| 2585 | ptr += sprintf(ptr, "%02x ", data); |
| 2586 | } else { |
| 2587 | ptr += sprintf(ptr, "ERR"); |
| 2588 | break; |
| 2589 | } |
| 2590 | |
| 2591 | if (count == 2 && reg < reg_end) |
| 2592 | reg = cardp->reg->func1_spec_reg_table[index++]; |
| 2593 | else |
| 2594 | reg++; |
| 2595 | } |
| 2596 | |
Zhaoyang Liu | acebe8c | 2015-05-12 00:48:20 +0530 | [diff] [blame] | 2597 | mwifiex_dbg(adapter, MSG, "%s\n", buf); |
Xinming Hu | 809c6ea | 2014-12-23 19:14:11 +0530 | [diff] [blame] | 2598 | p += sprintf(p, "%s\n", buf); |
| 2599 | } |
| 2600 | |
| 2601 | sdio_release_host(cardp->func); |
| 2602 | |
Amitkumar Karwar | 9cc0dbf0 | 2015-05-26 06:34:30 -0700 | [diff] [blame] | 2603 | mwifiex_dbg(adapter, MSG, "SDIO register dump end\n"); |
Xinming Hu | 809c6ea | 2014-12-23 19:14:11 +0530 | [diff] [blame] | 2604 | |
| 2605 | return p - drv_buf; |
| 2606 | } |
| 2607 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2608 | static struct mwifiex_if_ops sdio_ops = { |
| 2609 | .init_if = mwifiex_init_sdio, |
| 2610 | .cleanup_if = mwifiex_cleanup_sdio, |
| 2611 | .check_fw_status = mwifiex_check_fw_status, |
| 2612 | .prog_fw = mwifiex_prog_fw_w_helper, |
| 2613 | .register_dev = mwifiex_register_dev, |
| 2614 | .unregister_dev = mwifiex_unregister_dev, |
| 2615 | .enable_int = mwifiex_sdio_enable_host_int, |
Daniel Drake | 232fde0 | 2013-07-13 10:57:10 -0400 | [diff] [blame] | 2616 | .disable_int = mwifiex_sdio_disable_host_int, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2617 | .process_int_status = mwifiex_process_int_status, |
| 2618 | .host_to_card = mwifiex_sdio_host_to_card, |
| 2619 | .wakeup = mwifiex_pm_wakeup_card, |
| 2620 | .wakeup_complete = mwifiex_pm_wakeup_card_complete, |
| 2621 | |
| 2622 | /* SDIO specific */ |
| 2623 | .update_mp_end_port = mwifiex_update_mp_end_port, |
| 2624 | .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf, |
Amitkumar Karwar | d930fae | 2011-10-11 17:41:21 -0700 | [diff] [blame] | 2625 | .cmdrsp_complete = mwifiex_sdio_cmdrsp_complete, |
| 2626 | .event_complete = mwifiex_sdio_event_complete, |
Amitkumar Karwar | d31ab35 | 2012-11-01 18:44:14 -0700 | [diff] [blame] | 2627 | .card_reset = mwifiex_sdio_card_reset, |
Xinming Hu | 809c6ea | 2014-12-23 19:14:11 +0530 | [diff] [blame] | 2628 | .reg_dump = mwifiex_sdio_reg_dump, |
Amitkumar Karwar | fc69715 | 2015-05-26 06:34:31 -0700 | [diff] [blame] | 2629 | .device_dump = mwifiex_sdio_device_dump, |
Zhaoyang Liu | 92263a8 | 2015-03-13 17:37:58 +0530 | [diff] [blame] | 2630 | .deaggr_pkt = mwifiex_deaggr_sdio_pkt, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2631 | }; |
| 2632 | |
| 2633 | /* |
| 2634 | * This function initializes the SDIO driver. |
| 2635 | * |
| 2636 | * This initiates the semaphore and registers the device with |
| 2637 | * SDIO bus. |
| 2638 | */ |
| 2639 | static int |
| 2640 | mwifiex_sdio_init_module(void) |
| 2641 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2642 | sema_init(&add_remove_card_sem, 1); |
| 2643 | |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 2644 | /* Clear the flag in case user removes the card. */ |
| 2645 | user_rmmod = 0; |
| 2646 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 2647 | return sdio_register_driver(&mwifiex_sdio); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | /* |
| 2651 | * This function cleans up the SDIO driver. |
| 2652 | * |
| 2653 | * The following major steps are followed for cleanup - |
| 2654 | * - Resume the device if its suspended |
| 2655 | * - Disconnect the device if connected |
| 2656 | * - Shutdown the firmware |
| 2657 | * - Unregister the device from SDIO bus. |
| 2658 | */ |
| 2659 | static void |
| 2660 | mwifiex_sdio_cleanup_module(void) |
| 2661 | { |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 2662 | if (!down_interruptible(&add_remove_card_sem)) |
| 2663 | up(&add_remove_card_sem); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2664 | |
Amitkumar Karwar | 287546d | 2011-06-08 20:39:20 +0530 | [diff] [blame] | 2665 | /* Set the flag as user is removing this module. */ |
| 2666 | user_rmmod = 1; |
Maithili Hinge | 2f5872b | 2015-03-22 23:01:25 -0700 | [diff] [blame] | 2667 | cancel_work_sync(&sdio_work); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2668 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 2669 | sdio_unregister_driver(&mwifiex_sdio); |
| 2670 | } |
| 2671 | |
| 2672 | module_init(mwifiex_sdio_init_module); |
| 2673 | module_exit(mwifiex_sdio_cleanup_module); |
| 2674 | |
| 2675 | MODULE_AUTHOR("Marvell International Ltd."); |
| 2676 | MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION); |
| 2677 | MODULE_VERSION(SDIO_VERSION); |
| 2678 | MODULE_LICENSE("GPL v2"); |
WarheadsSE | 98e6b9d | 2012-04-24 15:57:21 -0400 | [diff] [blame] | 2679 | MODULE_FIRMWARE(SD8786_DEFAULT_FW_NAME); |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 2680 | MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME); |
| 2681 | MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME); |
Yogesh Ashok Powar | b60186f | 2013-05-17 17:54:58 -0700 | [diff] [blame] | 2682 | MODULE_FIRMWARE(SD8897_DEFAULT_FW_NAME); |
Avinash Patil | 030bb75 | 2014-10-01 10:55:26 -0700 | [diff] [blame] | 2683 | MODULE_FIRMWARE(SD8887_DEFAULT_FW_NAME); |
Zhaoyang Liu | 6d85ef0 | 2015-08-05 06:09:40 -0700 | [diff] [blame] | 2684 | MODULE_FIRMWARE(SD8997_DEFAULT_FW_NAME); |