Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: SDIO specific handling | |
3 | * | |
4 | * Copyright (C) 2011, Marvell International Ltd. | |
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 | ||
287546df AK |
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 | ||
5e6e3a92 BZ |
49 | static struct mwifiex_if_ops sdio_ops; |
50 | ||
51 | static struct semaphore add_remove_card_sem; | |
52 | ||
53 | /* | |
54 | * SDIO probe. | |
55 | * | |
56 | * This function probes an mwifiex device and registers it. It allocates | |
57 | * the card structure, enables SDIO function number and initiates the | |
58 | * device registration and initialization procedure by adding a logical | |
59 | * interface. | |
60 | */ | |
61 | static int | |
62 | mwifiex_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id) | |
63 | { | |
270e58e8 | 64 | int ret; |
5e6e3a92 BZ |
65 | struct sdio_mmc_card *card = NULL; |
66 | ||
67 | pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n", | |
5dbd326c | 68 | func->vendor, func->device, func->class, func->num); |
5e6e3a92 BZ |
69 | |
70 | card = kzalloc(sizeof(struct sdio_mmc_card), GFP_KERNEL); | |
e404decb | 71 | if (!card) |
5e6e3a92 | 72 | return -ENOMEM; |
5e6e3a92 BZ |
73 | |
74 | card->func = func; | |
75 | ||
76 | func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; | |
77 | ||
05889f82 AK |
78 | if (id->driver_data) { |
79 | struct mwifiex_sdio_device *data = (void *)id->driver_data; | |
80 | ||
81 | card->firmware = data->firmware; | |
82 | card->reg = data->reg; | |
83 | card->max_ports = data->max_ports; | |
84 | card->mp_agg_pkt_limit = data->mp_agg_pkt_limit; | |
b60186f8 YAP |
85 | card->supports_sdio_new_mode = data->supports_sdio_new_mode; |
86 | card->has_control_mask = data->has_control_mask; | |
828cf222 | 87 | card->tx_buf_size = data->tx_buf_size; |
e1aa93a4 AK |
88 | card->mp_tx_agg_buf_size = data->mp_tx_agg_buf_size; |
89 | card->mp_rx_agg_buf_size = data->mp_rx_agg_buf_size; | |
05889f82 AK |
90 | } |
91 | ||
5e6e3a92 BZ |
92 | sdio_claim_host(func); |
93 | ret = sdio_enable_func(func); | |
94 | sdio_release_host(func); | |
95 | ||
96 | if (ret) { | |
97 | pr_err("%s: failed to enable function\n", __func__); | |
b53575ec | 98 | kfree(card); |
5e6e3a92 BZ |
99 | return -EIO; |
100 | } | |
101 | ||
d930faee AK |
102 | if (mwifiex_add_card(card, &add_remove_card_sem, &sdio_ops, |
103 | MWIFIEX_SDIO)) { | |
5e6e3a92 BZ |
104 | pr_err("%s: add card failed\n", __func__); |
105 | kfree(card); | |
106 | sdio_claim_host(func); | |
107 | ret = sdio_disable_func(func); | |
108 | sdio_release_host(func); | |
109 | ret = -1; | |
110 | } | |
111 | ||
112 | return ret; | |
113 | } | |
114 | ||
2cdf359a AK |
115 | /* |
116 | * SDIO resume. | |
117 | * | |
118 | * Kernel needs to suspend all functions separately. Therefore all | |
119 | * registered functions must have drivers with suspend and resume | |
120 | * methods. Failing that the kernel simply removes the whole card. | |
121 | * | |
122 | * If already not resumed, this function turns on the traffic and | |
123 | * sends a host sleep cancel request to the firmware. | |
124 | */ | |
125 | static int mwifiex_sdio_resume(struct device *dev) | |
126 | { | |
127 | struct sdio_func *func = dev_to_sdio_func(dev); | |
128 | struct sdio_mmc_card *card; | |
129 | struct mwifiex_adapter *adapter; | |
130 | mmc_pm_flag_t pm_flag = 0; | |
131 | ||
132 | if (func) { | |
133 | pm_flag = sdio_get_host_pm_caps(func); | |
134 | card = sdio_get_drvdata(func); | |
135 | if (!card || !card->adapter) { | |
136 | pr_err("resume: invalid card or adapter\n"); | |
137 | return 0; | |
138 | } | |
139 | } else { | |
140 | pr_err("resume: sdio_func is not specified\n"); | |
141 | return 0; | |
142 | } | |
143 | ||
144 | adapter = card->adapter; | |
145 | ||
146 | if (!adapter->is_suspended) { | |
147 | dev_warn(adapter->dev, "device already resumed\n"); | |
148 | return 0; | |
149 | } | |
150 | ||
151 | adapter->is_suspended = false; | |
152 | ||
153 | /* Disable Host Sleep */ | |
154 | mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA), | |
155 | MWIFIEX_ASYNC_CMD); | |
156 | ||
157 | return 0; | |
158 | } | |
159 | ||
5e6e3a92 BZ |
160 | /* |
161 | * SDIO remove. | |
162 | * | |
163 | * This function removes the interface and frees up the card structure. | |
164 | */ | |
165 | static void | |
166 | mwifiex_sdio_remove(struct sdio_func *func) | |
167 | { | |
168 | struct sdio_mmc_card *card; | |
287546df | 169 | struct mwifiex_adapter *adapter; |
5dbd326c | 170 | struct mwifiex_private *priv; |
5e6e3a92 BZ |
171 | |
172 | pr_debug("info: SDIO func num=%d\n", func->num); | |
173 | ||
287546df AK |
174 | card = sdio_get_drvdata(func); |
175 | if (!card) | |
176 | return; | |
177 | ||
178 | adapter = card->adapter; | |
179 | if (!adapter || !adapter->priv_num) | |
180 | return; | |
181 | ||
8915d738 AK |
182 | cancel_work_sync(&adapter->iface_work); |
183 | ||
287546df AK |
184 | if (user_rmmod) { |
185 | if (adapter->is_suspended) | |
186 | mwifiex_sdio_resume(adapter->dev); | |
187 | ||
848819f4 | 188 | mwifiex_deauthenticate_all(adapter); |
287546df | 189 | |
5dbd326c YAP |
190 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
191 | mwifiex_disable_auto_ds(priv); | |
192 | mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN); | |
5e6e3a92 | 193 | } |
287546df AK |
194 | |
195 | mwifiex_remove_card(card->adapter, &add_remove_card_sem); | |
5e6e3a92 BZ |
196 | } |
197 | ||
198 | /* | |
199 | * SDIO suspend. | |
200 | * | |
201 | * Kernel needs to suspend all functions separately. Therefore all | |
202 | * registered functions must have drivers with suspend and resume | |
203 | * methods. Failing that the kernel simply removes the whole card. | |
204 | * | |
205 | * If already not suspended, this function allocates and sends a host | |
206 | * sleep activate request to the firmware and turns off the traffic. | |
207 | */ | |
208 | static int mwifiex_sdio_suspend(struct device *dev) | |
209 | { | |
210 | struct sdio_func *func = dev_to_sdio_func(dev); | |
211 | struct sdio_mmc_card *card; | |
270e58e8 | 212 | struct mwifiex_adapter *adapter; |
5e6e3a92 | 213 | mmc_pm_flag_t pm_flag = 0; |
5e6e3a92 BZ |
214 | int ret = 0; |
215 | ||
216 | if (func) { | |
217 | pm_flag = sdio_get_host_pm_caps(func); | |
218 | pr_debug("cmd: %s: suspend: PM flag = 0x%x\n", | |
5dbd326c | 219 | sdio_func_id(func), pm_flag); |
5e6e3a92 BZ |
220 | if (!(pm_flag & MMC_PM_KEEP_POWER)) { |
221 | pr_err("%s: cannot remain alive while host is" | |
222 | " suspended\n", sdio_func_id(func)); | |
223 | return -ENOSYS; | |
224 | } | |
225 | ||
226 | card = sdio_get_drvdata(func); | |
227 | if (!card || !card->adapter) { | |
228 | pr_err("suspend: invalid card or adapter\n"); | |
229 | return 0; | |
230 | } | |
231 | } else { | |
232 | pr_err("suspend: sdio_func is not specified\n"); | |
233 | return 0; | |
234 | } | |
235 | ||
236 | adapter = card->adapter; | |
237 | ||
238 | /* Enable the Host Sleep */ | |
dd321acd BZ |
239 | if (!mwifiex_enable_hs(adapter)) { |
240 | dev_err(adapter->dev, "cmd: failed to suspend\n"); | |
c0dbba66 | 241 | adapter->hs_enabling = false; |
dd321acd | 242 | return -EFAULT; |
5e6e3a92 BZ |
243 | } |
244 | ||
dd321acd BZ |
245 | dev_dbg(adapter->dev, "cmd: suspend with MMC_PM_KEEP_POWER\n"); |
246 | ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); | |
247 | ||
5e6e3a92 BZ |
248 | /* Indicate device suspended */ |
249 | adapter->is_suspended = true; | |
c0dbba66 | 250 | adapter->hs_enabling = false; |
5e6e3a92 | 251 | |
5e6e3a92 BZ |
252 | return ret; |
253 | } | |
254 | ||
98e6b9df W |
255 | /* Device ID for SD8786 */ |
256 | #define SDIO_DEVICE_ID_MARVELL_8786 (0x9116) | |
5e6e3a92 BZ |
257 | /* Device ID for SD8787 */ |
258 | #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119) | |
e3bea1c8 BZ |
259 | /* Device ID for SD8797 */ |
260 | #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129) | |
b60186f8 YAP |
261 | /* Device ID for SD8897 */ |
262 | #define SDIO_DEVICE_ID_MARVELL_8897 (0x912d) | |
5e6e3a92 BZ |
263 | |
264 | /* WLAN IDs */ | |
265 | static const struct sdio_device_id mwifiex_ids[] = { | |
05889f82 AK |
266 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8786), |
267 | .driver_data = (unsigned long) &mwifiex_sdio_sd8786}, | |
268 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787), | |
269 | .driver_data = (unsigned long) &mwifiex_sdio_sd8787}, | |
270 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797), | |
271 | .driver_data = (unsigned long) &mwifiex_sdio_sd8797}, | |
b60186f8 YAP |
272 | {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8897), |
273 | .driver_data = (unsigned long) &mwifiex_sdio_sd8897}, | |
5e6e3a92 BZ |
274 | {}, |
275 | }; | |
276 | ||
277 | MODULE_DEVICE_TABLE(sdio, mwifiex_ids); | |
278 | ||
279 | static const struct dev_pm_ops mwifiex_sdio_pm_ops = { | |
280 | .suspend = mwifiex_sdio_suspend, | |
281 | .resume = mwifiex_sdio_resume, | |
282 | }; | |
283 | ||
284 | static struct sdio_driver mwifiex_sdio = { | |
285 | .name = "mwifiex_sdio", | |
286 | .id_table = mwifiex_ids, | |
287 | .probe = mwifiex_sdio_probe, | |
288 | .remove = mwifiex_sdio_remove, | |
289 | .drv = { | |
290 | .owner = THIS_MODULE, | |
291 | .pm = &mwifiex_sdio_pm_ops, | |
292 | } | |
293 | }; | |
294 | ||
232fde06 DD |
295 | /* Write data into SDIO card register. Caller claims SDIO device. */ |
296 | static int | |
297 | mwifiex_write_reg_locked(struct sdio_func *func, u32 reg, u8 data) | |
298 | { | |
299 | int ret = -1; | |
300 | sdio_writeb(func, data, reg, &ret); | |
301 | return ret; | |
302 | } | |
303 | ||
5e6e3a92 BZ |
304 | /* |
305 | * This function writes data into SDIO card register. | |
306 | */ | |
307 | static int | |
ab93d4ff | 308 | mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u8 data) |
5e6e3a92 BZ |
309 | { |
310 | struct sdio_mmc_card *card = adapter->card; | |
232fde06 | 311 | int ret; |
5e6e3a92 BZ |
312 | |
313 | sdio_claim_host(card->func); | |
232fde06 | 314 | ret = mwifiex_write_reg_locked(card->func, reg, data); |
5e6e3a92 BZ |
315 | sdio_release_host(card->func); |
316 | ||
317 | return ret; | |
318 | } | |
319 | ||
320 | /* | |
321 | * This function reads data from SDIO card register. | |
322 | */ | |
323 | static int | |
ab93d4ff | 324 | mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u8 *data) |
5e6e3a92 BZ |
325 | { |
326 | struct sdio_mmc_card *card = adapter->card; | |
327 | int ret = -1; | |
328 | u8 val; | |
329 | ||
330 | sdio_claim_host(card->func); | |
331 | val = sdio_readb(card->func, reg, &ret); | |
332 | sdio_release_host(card->func); | |
333 | ||
334 | *data = val; | |
335 | ||
336 | return ret; | |
337 | } | |
338 | ||
339 | /* | |
340 | * This function writes multiple data into SDIO card memory. | |
341 | * | |
342 | * This does not work in suspended mode. | |
343 | */ | |
344 | static int | |
345 | mwifiex_write_data_sync(struct mwifiex_adapter *adapter, | |
572e8f3e | 346 | u8 *buffer, u32 pkt_len, u32 port) |
5e6e3a92 BZ |
347 | { |
348 | struct sdio_mmc_card *card = adapter->card; | |
5b2e2ecc | 349 | int ret; |
5e6e3a92 BZ |
350 | u8 blk_mode = |
351 | (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE; | |
352 | u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1; | |
353 | u32 blk_cnt = | |
354 | (blk_mode == | |
355 | BLOCK_MODE) ? (pkt_len / | |
356 | MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len; | |
357 | u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK); | |
358 | ||
359 | if (adapter->is_suspended) { | |
360 | dev_err(adapter->dev, | |
361 | "%s: not allowed while suspended\n", __func__); | |
362 | return -1; | |
363 | } | |
364 | ||
365 | sdio_claim_host(card->func); | |
366 | ||
5b2e2ecc | 367 | ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size); |
5e6e3a92 BZ |
368 | |
369 | sdio_release_host(card->func); | |
370 | ||
371 | return ret; | |
372 | } | |
373 | ||
374 | /* | |
375 | * This function reads multiple data from SDIO card memory. | |
376 | */ | |
572e8f3e AK |
377 | static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer, |
378 | u32 len, u32 port, u8 claim) | |
5e6e3a92 BZ |
379 | { |
380 | struct sdio_mmc_card *card = adapter->card; | |
5b2e2ecc | 381 | int ret; |
5dbd326c YAP |
382 | u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE |
383 | : BLOCK_MODE; | |
5e6e3a92 | 384 | u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1; |
5dbd326c YAP |
385 | u32 blk_cnt = (blk_mode == BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE) |
386 | : len; | |
5e6e3a92 BZ |
387 | u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK); |
388 | ||
389 | if (claim) | |
390 | sdio_claim_host(card->func); | |
391 | ||
5b2e2ecc | 392 | ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size); |
5e6e3a92 BZ |
393 | |
394 | if (claim) | |
395 | sdio_release_host(card->func); | |
396 | ||
397 | return ret; | |
398 | } | |
399 | ||
400 | /* | |
401 | * This function wakes up the card. | |
402 | * | |
403 | * A host power up command is written to the card configuration | |
404 | * register to wake up the card. | |
405 | */ | |
406 | static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter) | |
407 | { | |
5e6e3a92 | 408 | dev_dbg(adapter->dev, "event: wakeup device...\n"); |
5e6e3a92 | 409 | |
636c4598 | 410 | return mwifiex_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP); |
5e6e3a92 BZ |
411 | } |
412 | ||
413 | /* | |
414 | * This function is called after the card has woken up. | |
415 | * | |
416 | * The card configuration register is reset. | |
417 | */ | |
418 | static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter) | |
419 | { | |
5e6e3a92 | 420 | dev_dbg(adapter->dev, "cmd: wakeup device completed\n"); |
5e6e3a92 | 421 | |
636c4598 | 422 | return mwifiex_write_reg(adapter, CONFIGURATION_REG, 0); |
5e6e3a92 BZ |
423 | } |
424 | ||
425 | /* | |
b60186f8 YAP |
426 | * This function is used to initialize IO ports for the |
427 | * chipsets supporting SDIO new mode eg SD8897. | |
428 | */ | |
429 | static int mwifiex_init_sdio_new_mode(struct mwifiex_adapter *adapter) | |
430 | { | |
431 | u8 reg; | |
432 | ||
433 | adapter->ioport = MEM_PORT; | |
434 | ||
435 | /* enable sdio new mode */ | |
436 | if (mwifiex_read_reg(adapter, CARD_CONFIG_2_1_REG, ®)) | |
437 | return -1; | |
438 | if (mwifiex_write_reg(adapter, CARD_CONFIG_2_1_REG, | |
439 | reg | CMD53_NEW_MODE)) | |
440 | return -1; | |
441 | ||
442 | /* Configure cmd port and enable reading rx length from the register */ | |
443 | if (mwifiex_read_reg(adapter, CMD_CONFIG_0, ®)) | |
444 | return -1; | |
445 | if (mwifiex_write_reg(adapter, CMD_CONFIG_0, reg | CMD_PORT_RD_LEN_EN)) | |
446 | return -1; | |
447 | ||
448 | /* Enable Dnld/Upld ready auto reset for cmd port after cmd53 is | |
449 | * completed | |
450 | */ | |
451 | if (mwifiex_read_reg(adapter, CMD_CONFIG_1, ®)) | |
452 | return -1; | |
453 | if (mwifiex_write_reg(adapter, CMD_CONFIG_1, reg | CMD_PORT_AUTO_EN)) | |
454 | return -1; | |
455 | ||
456 | return 0; | |
457 | } | |
458 | ||
459 | /* This function initializes the IO ports. | |
5e6e3a92 BZ |
460 | * |
461 | * The following operations are performed - | |
462 | * - Read the IO ports (0, 1 and 2) | |
463 | * - Set host interrupt Reset-To-Read to clear | |
464 | * - Set auto re-enable interrupt | |
465 | */ | |
466 | static int mwifiex_init_sdio_ioport(struct mwifiex_adapter *adapter) | |
467 | { | |
ab93d4ff | 468 | u8 reg; |
05889f82 | 469 | struct sdio_mmc_card *card = adapter->card; |
5e6e3a92 BZ |
470 | |
471 | adapter->ioport = 0; | |
472 | ||
b60186f8 YAP |
473 | if (card->supports_sdio_new_mode) { |
474 | if (mwifiex_init_sdio_new_mode(adapter)) | |
475 | return -1; | |
476 | goto cont; | |
477 | } | |
478 | ||
5e6e3a92 BZ |
479 | /* Read the IO port */ |
480 | if (!mwifiex_read_reg(adapter, IO_PORT_0_REG, ®)) | |
481 | adapter->ioport |= (reg & 0xff); | |
482 | else | |
483 | return -1; | |
484 | ||
485 | if (!mwifiex_read_reg(adapter, IO_PORT_1_REG, ®)) | |
486 | adapter->ioport |= ((reg & 0xff) << 8); | |
487 | else | |
488 | return -1; | |
489 | ||
490 | if (!mwifiex_read_reg(adapter, IO_PORT_2_REG, ®)) | |
491 | adapter->ioport |= ((reg & 0xff) << 16); | |
492 | else | |
493 | return -1; | |
b60186f8 | 494 | cont: |
5e6e3a92 BZ |
495 | pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter->ioport); |
496 | ||
497 | /* Set Host interrupt reset to read to clear */ | |
498 | if (!mwifiex_read_reg(adapter, HOST_INT_RSR_REG, ®)) | |
499 | mwifiex_write_reg(adapter, HOST_INT_RSR_REG, | |
05889f82 | 500 | reg | card->reg->sdio_int_mask); |
5e6e3a92 BZ |
501 | else |
502 | return -1; | |
503 | ||
504 | /* Dnld/Upld ready set to auto reset */ | |
05889f82 AK |
505 | if (!mwifiex_read_reg(adapter, card->reg->card_misc_cfg_reg, ®)) |
506 | mwifiex_write_reg(adapter, card->reg->card_misc_cfg_reg, | |
5e6e3a92 BZ |
507 | reg | AUTO_RE_ENABLE_INT); |
508 | else | |
509 | return -1; | |
510 | ||
511 | return 0; | |
512 | } | |
513 | ||
514 | /* | |
515 | * This function sends data to the card. | |
516 | */ | |
517 | static int mwifiex_write_data_to_card(struct mwifiex_adapter *adapter, | |
518 | u8 *payload, u32 pkt_len, u32 port) | |
519 | { | |
520 | u32 i = 0; | |
270e58e8 | 521 | int ret; |
5e6e3a92 BZ |
522 | |
523 | do { | |
572e8f3e | 524 | ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port); |
5e6e3a92 BZ |
525 | if (ret) { |
526 | i++; | |
527 | dev_err(adapter->dev, "host_to_card, write iomem" | |
528 | " (%d) failed: %d\n", i, ret); | |
5dbd326c | 529 | if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04)) |
5e6e3a92 BZ |
530 | dev_err(adapter->dev, "write CFG reg failed\n"); |
531 | ||
532 | ret = -1; | |
533 | if (i > MAX_WRITE_IOMEM_RETRY) | |
534 | return ret; | |
535 | } | |
536 | } while (ret == -1); | |
537 | ||
538 | return ret; | |
539 | } | |
540 | ||
541 | /* | |
542 | * This function gets the read port. | |
543 | * | |
544 | * If control port bit is set in MP read bitmap, the control port | |
545 | * is returned, otherwise the current read port is returned and | |
546 | * the value is increased (provided it does not reach the maximum | |
547 | * limit, in which case it is reset to 1) | |
548 | */ | |
549 | static int mwifiex_get_rd_port(struct mwifiex_adapter *adapter, u8 *port) | |
550 | { | |
551 | struct sdio_mmc_card *card = adapter->card; | |
05889f82 | 552 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
5ac253d5 | 553 | u32 rd_bitmap = card->mp_rd_bitmap; |
5e6e3a92 | 554 | |
5ac253d5 | 555 | dev_dbg(adapter->dev, "data: mp_rd_bitmap=0x%08x\n", rd_bitmap); |
5e6e3a92 | 556 | |
b60186f8 YAP |
557 | if (card->supports_sdio_new_mode) { |
558 | if (!(rd_bitmap & reg->data_port_mask)) | |
559 | return -1; | |
560 | } else { | |
561 | if (!(rd_bitmap & (CTRL_PORT_MASK | reg->data_port_mask))) | |
562 | return -1; | |
563 | } | |
5e6e3a92 | 564 | |
b60186f8 YAP |
565 | if ((card->has_control_mask) && |
566 | (card->mp_rd_bitmap & CTRL_PORT_MASK)) { | |
5ac253d5 | 567 | card->mp_rd_bitmap &= (u32) (~CTRL_PORT_MASK); |
5e6e3a92 | 568 | *port = CTRL_PORT; |
5ac253d5 | 569 | dev_dbg(adapter->dev, "data: port=%d mp_rd_bitmap=0x%08x\n", |
5dbd326c | 570 | *port, card->mp_rd_bitmap); |
e6a52030 | 571 | return 0; |
5e6e3a92 | 572 | } |
e6a52030 AK |
573 | |
574 | if (!(card->mp_rd_bitmap & (1 << card->curr_rd_port))) | |
575 | return -1; | |
576 | ||
577 | /* We are now handling the SDIO data ports */ | |
578 | card->mp_rd_bitmap &= (u32)(~(1 << card->curr_rd_port)); | |
579 | *port = card->curr_rd_port; | |
580 | ||
581 | if (++card->curr_rd_port == card->max_ports) | |
582 | card->curr_rd_port = reg->start_rd_port; | |
583 | ||
584 | dev_dbg(adapter->dev, | |
585 | "data: port=%d mp_rd_bitmap=0x%08x -> 0x%08x\n", | |
586 | *port, rd_bitmap, card->mp_rd_bitmap); | |
587 | ||
5e6e3a92 BZ |
588 | return 0; |
589 | } | |
590 | ||
591 | /* | |
592 | * This function gets the write port for data. | |
593 | * | |
594 | * The current write port is returned if available and the value is | |
595 | * increased (provided it does not reach the maximum limit, in which | |
596 | * case it is reset to 1) | |
597 | */ | |
0fc0d43b | 598 | static int mwifiex_get_wr_port_data(struct mwifiex_adapter *adapter, u32 *port) |
5e6e3a92 BZ |
599 | { |
600 | struct sdio_mmc_card *card = adapter->card; | |
b60186f8 | 601 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
5ac253d5 | 602 | u32 wr_bitmap = card->mp_wr_bitmap; |
5e6e3a92 | 603 | |
5ac253d5 | 604 | dev_dbg(adapter->dev, "data: mp_wr_bitmap=0x%08x\n", wr_bitmap); |
5e6e3a92 | 605 | |
b60186f8 YAP |
606 | if (card->supports_sdio_new_mode && |
607 | !(wr_bitmap & reg->data_port_mask)) { | |
608 | adapter->data_sent = true; | |
609 | return -EBUSY; | |
610 | } else if (!card->supports_sdio_new_mode && | |
611 | !(wr_bitmap & card->mp_data_port_mask)) { | |
5e6e3a92 | 612 | return -1; |
b60186f8 | 613 | } |
5e6e3a92 BZ |
614 | |
615 | if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) { | |
5ac253d5 | 616 | card->mp_wr_bitmap &= (u32) (~(1 << card->curr_wr_port)); |
5e6e3a92 | 617 | *port = card->curr_wr_port; |
b60186f8 YAP |
618 | if (((card->supports_sdio_new_mode) && |
619 | (++card->curr_wr_port == card->max_ports)) || | |
620 | ((!card->supports_sdio_new_mode) && | |
621 | (++card->curr_wr_port == card->mp_end_port))) | |
622 | card->curr_wr_port = reg->start_wr_port; | |
5e6e3a92 BZ |
623 | } else { |
624 | adapter->data_sent = true; | |
625 | return -EBUSY; | |
626 | } | |
627 | ||
b60186f8 | 628 | if ((card->has_control_mask) && (*port == CTRL_PORT)) { |
5ac253d5 AK |
629 | dev_err(adapter->dev, |
630 | "invalid data port=%d cur port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n", | |
5dbd326c YAP |
631 | *port, card->curr_wr_port, wr_bitmap, |
632 | card->mp_wr_bitmap); | |
5e6e3a92 BZ |
633 | return -1; |
634 | } | |
635 | ||
5ac253d5 | 636 | dev_dbg(adapter->dev, "data: port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n", |
5dbd326c | 637 | *port, wr_bitmap, card->mp_wr_bitmap); |
5e6e3a92 BZ |
638 | |
639 | return 0; | |
640 | } | |
641 | ||
642 | /* | |
643 | * This function polls the card status. | |
644 | */ | |
645 | static int | |
646 | mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits) | |
647 | { | |
05889f82 | 648 | struct sdio_mmc_card *card = adapter->card; |
5e6e3a92 | 649 | u32 tries; |
ab93d4ff | 650 | u8 cs; |
5e6e3a92 BZ |
651 | |
652 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { | |
05889f82 | 653 | if (mwifiex_read_reg(adapter, card->reg->poll_reg, &cs)) |
5e6e3a92 BZ |
654 | break; |
655 | else if ((cs & bits) == bits) | |
656 | return 0; | |
657 | ||
e7891ba2 | 658 | usleep_range(10, 20); |
5e6e3a92 BZ |
659 | } |
660 | ||
5dbd326c YAP |
661 | dev_err(adapter->dev, "poll card status failed, tries = %d\n", tries); |
662 | ||
5e6e3a92 BZ |
663 | return -1; |
664 | } | |
665 | ||
666 | /* | |
667 | * This function reads the firmware status. | |
668 | */ | |
669 | static int | |
670 | mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat) | |
671 | { | |
05889f82 AK |
672 | struct sdio_mmc_card *card = adapter->card; |
673 | const struct mwifiex_sdio_card_reg *reg = card->reg; | |
ab93d4ff | 674 | u8 fws0, fws1; |
5e6e3a92 | 675 | |
05889f82 | 676 | if (mwifiex_read_reg(adapter, reg->status_reg_0, &fws0)) |
5e6e3a92 BZ |
677 | return -1; |
678 | ||
05889f82 | 679 | if (mwifiex_read_reg(adapter, reg->status_reg_1, &fws1)) |
5e6e3a92 BZ |
680 | return -1; |
681 | ||
682 | *dat = (u16) ((fws1 << 8) | fws0); | |
683 | ||
684 | return 0; | |
685 | } | |
686 | ||
687 | /* | |
688 | * This function disables the host interrupt. | |
689 | * | |
690 | * The host interrupt mask is read, the disable bit is reset and | |
691 | * written back to the card host interrupt mask register. | |
692 | */ | |
232fde06 | 693 | static void mwifiex_sdio_disable_host_int(struct mwifiex_adapter *adapter) |
5e6e3a92 | 694 | { |
232fde06 DD |
695 | struct sdio_mmc_card *card = adapter->card; |
696 | struct sdio_func *func = card->func; | |
5e6e3a92 | 697 | |
232fde06 DD |
698 | sdio_claim_host(func); |
699 | mwifiex_write_reg_locked(func, HOST_INT_MASK_REG, 0); | |
700 | sdio_release_irq(func); | |
701 | sdio_release_host(func); | |
5e6e3a92 BZ |
702 | } |
703 | ||
2cdf359a AK |
704 | /* |
705 | * This function reads the interrupt status from card. | |
706 | */ | |
707 | static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter) | |
708 | { | |
709 | struct sdio_mmc_card *card = adapter->card; | |
710 | u8 sdio_ireg; | |
711 | unsigned long flags; | |
712 | ||
713 | if (mwifiex_read_data_sync(adapter, card->mp_regs, | |
714 | card->reg->max_mp_regs, | |
715 | REG_PORT | MWIFIEX_SDIO_BYTE_MODE_MASK, 0)) { | |
716 | dev_err(adapter->dev, "read mp_regs failed\n"); | |
717 | return; | |
718 | } | |
719 | ||
720 | sdio_ireg = card->mp_regs[HOST_INTSTATUS_REG]; | |
721 | if (sdio_ireg) { | |
722 | /* | |
723 | * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS | |
724 | * For SDIO new mode CMD port interrupts | |
725 | * DN_LD_CMD_PORT_HOST_INT_STATUS and/or | |
726 | * UP_LD_CMD_PORT_HOST_INT_STATUS | |
727 | * Clear the interrupt status register | |
728 | */ | |
729 | dev_dbg(adapter->dev, "int: sdio_ireg = %#x\n", sdio_ireg); | |
730 | spin_lock_irqsave(&adapter->int_lock, flags); | |
731 | adapter->int_status |= sdio_ireg; | |
732 | spin_unlock_irqrestore(&adapter->int_lock, flags); | |
733 | } | |
734 | } | |
735 | ||
736 | /* | |
737 | * SDIO interrupt handler. | |
738 | * | |
739 | * This function reads the interrupt status from firmware and handles | |
740 | * the interrupt in current thread (ksdioirqd) right away. | |
741 | */ | |
742 | static void | |
743 | mwifiex_sdio_interrupt(struct sdio_func *func) | |
744 | { | |
745 | struct mwifiex_adapter *adapter; | |
746 | struct sdio_mmc_card *card; | |
747 | ||
748 | card = sdio_get_drvdata(func); | |
749 | if (!card || !card->adapter) { | |
750 | pr_debug("int: func=%p card=%p adapter=%p\n", | |
751 | func, card, card ? card->adapter : NULL); | |
752 | return; | |
753 | } | |
754 | adapter = card->adapter; | |
755 | ||
756 | if (!adapter->pps_uapsd_mode && adapter->ps_state == PS_STATE_SLEEP) | |
757 | adapter->ps_state = PS_STATE_AWAKE; | |
758 | ||
759 | mwifiex_interrupt_status(adapter); | |
760 | mwifiex_main_process(adapter); | |
761 | } | |
762 | ||
5e6e3a92 BZ |
763 | /* |
764 | * This function enables the host interrupt. | |
765 | * | |
766 | * The host interrupt enable mask is written to the card | |
767 | * host interrupt mask register. | |
768 | */ | |
769 | static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter *adapter) | |
770 | { | |
05889f82 | 771 | struct sdio_mmc_card *card = adapter->card; |
232fde06 DD |
772 | struct sdio_func *func = card->func; |
773 | int ret; | |
774 | ||
775 | sdio_claim_host(func); | |
776 | ||
777 | /* Request the SDIO IRQ */ | |
778 | ret = sdio_claim_irq(func, mwifiex_sdio_interrupt); | |
779 | if (ret) { | |
780 | dev_err(adapter->dev, "claim irq failed: ret=%d\n", ret); | |
781 | goto out; | |
782 | } | |
05889f82 | 783 | |
5e6e3a92 | 784 | /* Simply write the mask to the register */ |
232fde06 DD |
785 | ret = mwifiex_write_reg_locked(func, HOST_INT_MASK_REG, |
786 | card->reg->host_int_enable); | |
787 | if (ret) { | |
5e6e3a92 | 788 | dev_err(adapter->dev, "enable host interrupt failed\n"); |
232fde06 | 789 | sdio_release_irq(func); |
5e6e3a92 | 790 | } |
232fde06 DD |
791 | |
792 | out: | |
793 | sdio_release_host(func); | |
794 | return ret; | |
5e6e3a92 BZ |
795 | } |
796 | ||
797 | /* | |
798 | * This function sends a data buffer to the card. | |
799 | */ | |
800 | static int mwifiex_sdio_card_to_host(struct mwifiex_adapter *adapter, | |
801 | u32 *type, u8 *buffer, | |
802 | u32 npayload, u32 ioport) | |
803 | { | |
270e58e8 | 804 | int ret; |
5e6e3a92 BZ |
805 | u32 nb; |
806 | ||
807 | if (!buffer) { | |
808 | dev_err(adapter->dev, "%s: buffer is NULL\n", __func__); | |
809 | return -1; | |
810 | } | |
811 | ||
572e8f3e | 812 | ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1); |
5e6e3a92 BZ |
813 | |
814 | if (ret) { | |
815 | dev_err(adapter->dev, "%s: read iomem failed: %d\n", __func__, | |
5dbd326c | 816 | ret); |
5e6e3a92 BZ |
817 | return -1; |
818 | } | |
819 | ||
820 | nb = le16_to_cpu(*(__le16 *) (buffer)); | |
821 | if (nb > npayload) { | |
5dbd326c YAP |
822 | dev_err(adapter->dev, "%s: invalid packet, nb=%d npayload=%d\n", |
823 | __func__, nb, npayload); | |
5e6e3a92 BZ |
824 | return -1; |
825 | } | |
826 | ||
827 | *type = le16_to_cpu(*(__le16 *) (buffer + 2)); | |
828 | ||
829 | return ret; | |
830 | } | |
831 | ||
832 | /* | |
833 | * This function downloads the firmware to the card. | |
834 | * | |
835 | * Firmware is downloaded to the card in blocks. Every block download | |
836 | * is tested for CRC errors, and retried a number of times before | |
837 | * returning failure. | |
838 | */ | |
839 | static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter, | |
840 | struct mwifiex_fw_image *fw) | |
841 | { | |
05889f82 AK |
842 | struct sdio_mmc_card *card = adapter->card; |
843 | const struct mwifiex_sdio_card_reg *reg = card->reg; | |
270e58e8 | 844 | int ret; |
5e6e3a92 BZ |
845 | u8 *firmware = fw->fw_buf; |
846 | u32 firmware_len = fw->fw_len; | |
847 | u32 offset = 0; | |
ab93d4ff | 848 | u8 base0, base1; |
5e6e3a92 BZ |
849 | u8 *fwbuf; |
850 | u16 len = 0; | |
270e58e8 | 851 | u32 txlen, tx_blocks = 0, tries; |
5e6e3a92 BZ |
852 | u32 i = 0; |
853 | ||
854 | if (!firmware_len) { | |
5dbd326c YAP |
855 | dev_err(adapter->dev, |
856 | "firmware image not found! Terminating download\n"); | |
5e6e3a92 BZ |
857 | return -1; |
858 | } | |
859 | ||
860 | dev_dbg(adapter->dev, "info: downloading FW image (%d bytes)\n", | |
5dbd326c | 861 | firmware_len); |
5e6e3a92 BZ |
862 | |
863 | /* Assume that the allocated buffer is 8-byte aligned */ | |
864 | fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL); | |
0d2e7a5c | 865 | if (!fwbuf) |
b53575ec | 866 | return -ENOMEM; |
5e6e3a92 BZ |
867 | |
868 | /* Perform firmware data transfer */ | |
869 | do { | |
870 | /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY | |
871 | bits */ | |
872 | ret = mwifiex_sdio_poll_card_status(adapter, CARD_IO_READY | | |
873 | DN_LD_CARD_RDY); | |
874 | if (ret) { | |
875 | dev_err(adapter->dev, "FW download with helper:" | |
5dbd326c | 876 | " poll status timeout @ %d\n", offset); |
5e6e3a92 BZ |
877 | goto done; |
878 | } | |
879 | ||
880 | /* More data? */ | |
881 | if (offset >= firmware_len) | |
882 | break; | |
883 | ||
884 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { | |
05889f82 | 885 | ret = mwifiex_read_reg(adapter, reg->base_0_reg, |
5e6e3a92 BZ |
886 | &base0); |
887 | if (ret) { | |
5dbd326c YAP |
888 | dev_err(adapter->dev, |
889 | "dev BASE0 register read failed: " | |
890 | "base0=%#04X(%d). Terminating dnld\n", | |
891 | base0, base0); | |
5e6e3a92 BZ |
892 | goto done; |
893 | } | |
05889f82 | 894 | ret = mwifiex_read_reg(adapter, reg->base_1_reg, |
5e6e3a92 BZ |
895 | &base1); |
896 | if (ret) { | |
5dbd326c YAP |
897 | dev_err(adapter->dev, |
898 | "dev BASE1 register read failed: " | |
899 | "base1=%#04X(%d). Terminating dnld\n", | |
900 | base1, base1); | |
5e6e3a92 BZ |
901 | goto done; |
902 | } | |
903 | len = (u16) (((base1 & 0xff) << 8) | (base0 & 0xff)); | |
904 | ||
905 | if (len) | |
906 | break; | |
907 | ||
e7891ba2 | 908 | usleep_range(10, 20); |
5e6e3a92 BZ |
909 | } |
910 | ||
911 | if (!len) { | |
912 | break; | |
913 | } else if (len > MWIFIEX_UPLD_SIZE) { | |
5dbd326c YAP |
914 | dev_err(adapter->dev, |
915 | "FW dnld failed @ %d, invalid length %d\n", | |
916 | offset, len); | |
5e6e3a92 BZ |
917 | ret = -1; |
918 | goto done; | |
919 | } | |
920 | ||
921 | txlen = len; | |
922 | ||
923 | if (len & BIT(0)) { | |
924 | i++; | |
925 | if (i > MAX_WRITE_IOMEM_RETRY) { | |
5dbd326c YAP |
926 | dev_err(adapter->dev, |
927 | "FW dnld failed @ %d, over max retry\n", | |
928 | offset); | |
5e6e3a92 BZ |
929 | ret = -1; |
930 | goto done; | |
931 | } | |
932 | dev_err(adapter->dev, "CRC indicated by the helper:" | |
5dbd326c | 933 | " len = 0x%04X, txlen = %d\n", len, txlen); |
5e6e3a92 BZ |
934 | len &= ~BIT(0); |
935 | /* Setting this to 0 to resend from same offset */ | |
936 | txlen = 0; | |
937 | } else { | |
938 | i = 0; | |
939 | ||
940 | /* Set blocksize to transfer - checking for last | |
941 | block */ | |
942 | if (firmware_len - offset < txlen) | |
943 | txlen = firmware_len - offset; | |
944 | ||
5dbd326c YAP |
945 | tx_blocks = (txlen + MWIFIEX_SDIO_BLOCK_SIZE - 1) |
946 | / MWIFIEX_SDIO_BLOCK_SIZE; | |
5e6e3a92 BZ |
947 | |
948 | /* Copy payload to buffer */ | |
949 | memmove(fwbuf, &firmware[offset], txlen); | |
950 | } | |
951 | ||
952 | ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks * | |
953 | MWIFIEX_SDIO_BLOCK_SIZE, | |
572e8f3e | 954 | adapter->ioport); |
5e6e3a92 | 955 | if (ret) { |
5dbd326c YAP |
956 | dev_err(adapter->dev, |
957 | "FW download, write iomem (%d) failed @ %d\n", | |
958 | i, offset); | |
5e6e3a92 BZ |
959 | if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04)) |
960 | dev_err(adapter->dev, "write CFG reg failed\n"); | |
961 | ||
962 | ret = -1; | |
963 | goto done; | |
964 | } | |
965 | ||
966 | offset += txlen; | |
967 | } while (true); | |
968 | ||
969 | dev_dbg(adapter->dev, "info: FW download over, size %d bytes\n", | |
5dbd326c | 970 | offset); |
5e6e3a92 BZ |
971 | |
972 | ret = 0; | |
973 | done: | |
974 | kfree(fwbuf); | |
975 | return ret; | |
976 | } | |
977 | ||
978 | /* | |
979 | * This function checks the firmware status in card. | |
980 | * | |
981 | * The winner interface is also determined by this function. | |
982 | */ | |
983 | static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter, | |
d930faee | 984 | u32 poll_num) |
5e6e3a92 | 985 | { |
05889f82 | 986 | struct sdio_mmc_card *card = adapter->card; |
5e6e3a92 BZ |
987 | int ret = 0; |
988 | u16 firmware_stat; | |
989 | u32 tries; | |
ab93d4ff | 990 | u8 winner_status; |
5e6e3a92 BZ |
991 | |
992 | /* Wait for firmware initialization event */ | |
993 | for (tries = 0; tries < poll_num; tries++) { | |
994 | ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat); | |
995 | if (ret) | |
996 | continue; | |
d930faee | 997 | if (firmware_stat == FIRMWARE_READY_SDIO) { |
5e6e3a92 BZ |
998 | ret = 0; |
999 | break; | |
1000 | } else { | |
a76b20e5 | 1001 | msleep(100); |
5e6e3a92 BZ |
1002 | ret = -1; |
1003 | } | |
1004 | } | |
1005 | ||
d930faee | 1006 | if (ret) { |
5e6e3a92 | 1007 | if (mwifiex_read_reg |
05889f82 | 1008 | (adapter, card->reg->status_reg_0, &winner_status)) |
5e6e3a92 BZ |
1009 | winner_status = 0; |
1010 | ||
1011 | if (winner_status) | |
d930faee | 1012 | adapter->winner = 0; |
5e6e3a92 | 1013 | else |
d930faee | 1014 | adapter->winner = 1; |
5e6e3a92 BZ |
1015 | } |
1016 | return ret; | |
1017 | } | |
1018 | ||
5e6e3a92 BZ |
1019 | /* |
1020 | * This function decodes a received packet. | |
1021 | * | |
1022 | * Based on the type, the packet is treated as either a data, or | |
1023 | * a command response, or an event, and the correct handler | |
1024 | * function is invoked. | |
1025 | */ | |
1026 | static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter, | |
1027 | struct sk_buff *skb, u32 upld_typ) | |
1028 | { | |
1029 | u8 *cmd_buf; | |
d03b4aa7 AP |
1030 | __le16 *curr_ptr = (__le16 *)skb->data; |
1031 | u16 pkt_len = le16_to_cpu(*curr_ptr); | |
5e6e3a92 | 1032 | |
d03b4aa7 | 1033 | skb_trim(skb, pkt_len); |
5e6e3a92 BZ |
1034 | skb_pull(skb, INTF_HEADER_LEN); |
1035 | ||
1036 | switch (upld_typ) { | |
1037 | case MWIFIEX_TYPE_DATA: | |
1038 | dev_dbg(adapter->dev, "info: --- Rx: Data packet ---\n"); | |
1039 | mwifiex_handle_rx_packet(adapter, skb); | |
1040 | break; | |
1041 | ||
1042 | case MWIFIEX_TYPE_CMD: | |
1043 | dev_dbg(adapter->dev, "info: --- Rx: Cmd Response ---\n"); | |
1044 | /* take care of curr_cmd = NULL case */ | |
1045 | if (!adapter->curr_cmd) { | |
1046 | cmd_buf = adapter->upld_buf; | |
1047 | ||
1048 | if (adapter->ps_state == PS_STATE_SLEEP_CFM) | |
1049 | mwifiex_process_sleep_confirm_resp(adapter, | |
5dbd326c YAP |
1050 | skb->data, |
1051 | skb->len); | |
5e6e3a92 | 1052 | |
5dbd326c YAP |
1053 | memcpy(cmd_buf, skb->data, |
1054 | min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, | |
1055 | skb->len)); | |
5e6e3a92 BZ |
1056 | |
1057 | dev_kfree_skb_any(skb); | |
1058 | } else { | |
1059 | adapter->cmd_resp_received = true; | |
1060 | adapter->curr_cmd->resp_skb = skb; | |
1061 | } | |
1062 | break; | |
1063 | ||
1064 | case MWIFIEX_TYPE_EVENT: | |
1065 | dev_dbg(adapter->dev, "info: --- Rx: Event ---\n"); | |
cfcd926e | 1066 | adapter->event_cause = le32_to_cpu(*(__le32 *) skb->data); |
5e6e3a92 | 1067 | |
5e6e3a92 | 1068 | if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE)) |
e80c81dc AK |
1069 | memcpy(adapter->event_body, |
1070 | skb->data + MWIFIEX_EVENT_HEADER_LEN, | |
1071 | skb->len); | |
5e6e3a92 BZ |
1072 | |
1073 | /* event cause has been saved to adapter->event_cause */ | |
1074 | adapter->event_received = true; | |
1075 | adapter->event_skb = skb; | |
1076 | ||
1077 | break; | |
1078 | ||
1079 | default: | |
1080 | dev_err(adapter->dev, "unknown upload type %#x\n", upld_typ); | |
1081 | dev_kfree_skb_any(skb); | |
1082 | break; | |
1083 | } | |
1084 | ||
1085 | return 0; | |
1086 | } | |
1087 | ||
1088 | /* | |
1089 | * This function transfers received packets from card to driver, performing | |
1090 | * aggregation if required. | |
1091 | * | |
1092 | * For data received on control port, or if aggregation is disabled, the | |
1093 | * received buffers are uploaded as separate packets. However, if aggregation | |
1094 | * is enabled and required, the buffers are copied onto an aggregation buffer, | |
1095 | * provided there is space left, processed and finally uploaded. | |
1096 | */ | |
1097 | static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter *adapter, | |
1098 | struct sk_buff *skb, u8 port) | |
1099 | { | |
1100 | struct sdio_mmc_card *card = adapter->card; | |
1101 | s32 f_do_rx_aggr = 0; | |
1102 | s32 f_do_rx_cur = 0; | |
1103 | s32 f_aggr_cur = 0; | |
1104 | struct sk_buff *skb_deaggr; | |
270e58e8 | 1105 | u32 pind; |
0fc0d43b | 1106 | u32 pkt_len, pkt_type, mport; |
5e6e3a92 BZ |
1107 | u8 *curr_ptr; |
1108 | u32 rx_len = skb->len; | |
1109 | ||
b60186f8 | 1110 | if ((card->has_control_mask) && (port == CTRL_PORT)) { |
5e6e3a92 BZ |
1111 | /* Read the command Resp without aggr */ |
1112 | dev_dbg(adapter->dev, "info: %s: no aggregation for cmd " | |
5dbd326c | 1113 | "response\n", __func__); |
5e6e3a92 BZ |
1114 | |
1115 | f_do_rx_cur = 1; | |
1116 | goto rx_curr_single; | |
1117 | } | |
1118 | ||
1119 | if (!card->mpa_rx.enabled) { | |
1120 | dev_dbg(adapter->dev, "info: %s: rx aggregation disabled\n", | |
5dbd326c | 1121 | __func__); |
5e6e3a92 BZ |
1122 | |
1123 | f_do_rx_cur = 1; | |
1124 | goto rx_curr_single; | |
1125 | } | |
1126 | ||
b60186f8 YAP |
1127 | if ((!card->has_control_mask && (card->mp_rd_bitmap & |
1128 | card->reg->data_port_mask)) || | |
1129 | (card->has_control_mask && (card->mp_rd_bitmap & | |
1130 | (~((u32) CTRL_PORT_MASK))))) { | |
5e6e3a92 BZ |
1131 | /* Some more data RX pending */ |
1132 | dev_dbg(adapter->dev, "info: %s: not last packet\n", __func__); | |
1133 | ||
1134 | if (MP_RX_AGGR_IN_PROGRESS(card)) { | |
1135 | if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len)) { | |
1136 | f_aggr_cur = 1; | |
1137 | } else { | |
1138 | /* No room in Aggr buf, do rx aggr now */ | |
1139 | f_do_rx_aggr = 1; | |
1140 | f_do_rx_cur = 1; | |
1141 | } | |
1142 | } else { | |
1143 | /* Rx aggr not in progress */ | |
1144 | f_aggr_cur = 1; | |
1145 | } | |
1146 | ||
1147 | } else { | |
1148 | /* No more data RX pending */ | |
1149 | dev_dbg(adapter->dev, "info: %s: last packet\n", __func__); | |
1150 | ||
1151 | if (MP_RX_AGGR_IN_PROGRESS(card)) { | |
1152 | f_do_rx_aggr = 1; | |
1153 | if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len)) | |
1154 | f_aggr_cur = 1; | |
1155 | else | |
1156 | /* No room in Aggr buf, do rx aggr now */ | |
1157 | f_do_rx_cur = 1; | |
1158 | } else { | |
1159 | f_do_rx_cur = 1; | |
1160 | } | |
1161 | } | |
1162 | ||
1163 | if (f_aggr_cur) { | |
1164 | dev_dbg(adapter->dev, "info: current packet aggregation\n"); | |
1165 | /* Curr pkt can be aggregated */ | |
c23b7c8f | 1166 | mp_rx_aggr_setup(card, skb, port); |
5e6e3a92 BZ |
1167 | |
1168 | if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) || | |
c23b7c8f | 1169 | mp_rx_aggr_port_limit_reached(card)) { |
5e6e3a92 | 1170 | dev_dbg(adapter->dev, "info: %s: aggregated packet " |
5dbd326c | 1171 | "limit reached\n", __func__); |
5e6e3a92 BZ |
1172 | /* No more pkts allowed in Aggr buf, rx it */ |
1173 | f_do_rx_aggr = 1; | |
1174 | } | |
1175 | } | |
1176 | ||
1177 | if (f_do_rx_aggr) { | |
1178 | /* do aggr RX now */ | |
1179 | dev_dbg(adapter->dev, "info: do_rx_aggr: num of packets: %d\n", | |
5dbd326c | 1180 | card->mpa_rx.pkt_cnt); |
5e6e3a92 | 1181 | |
b60186f8 YAP |
1182 | if (card->supports_sdio_new_mode) { |
1183 | int i; | |
1184 | u32 port_count; | |
1185 | ||
1186 | for (i = 0, port_count = 0; i < card->max_ports; i++) | |
1187 | if (card->mpa_rx.ports & BIT(i)) | |
1188 | port_count++; | |
1189 | ||
1190 | /* Reading data from "start_port + 0" to "start_port + | |
1191 | * port_count -1", so decrease the count by 1 | |
1192 | */ | |
1193 | port_count--; | |
1194 | mport = (adapter->ioport | SDIO_MPA_ADDR_BASE | | |
1195 | (port_count << 8)) + card->mpa_rx.start_port; | |
1196 | } else { | |
1197 | mport = (adapter->ioport | SDIO_MPA_ADDR_BASE | | |
1198 | (card->mpa_rx.ports << 4)) + | |
1199 | card->mpa_rx.start_port; | |
1200 | } | |
0fc0d43b | 1201 | |
5e6e3a92 | 1202 | if (mwifiex_read_data_sync(adapter, card->mpa_rx.buf, |
0fc0d43b | 1203 | card->mpa_rx.buf_len, mport, 1)) |
17a60b48 | 1204 | goto error; |
5e6e3a92 BZ |
1205 | |
1206 | curr_ptr = card->mpa_rx.buf; | |
1207 | ||
1208 | for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) { | |
1209 | ||
1210 | /* get curr PKT len & type */ | |
cfcd926e TW |
1211 | pkt_len = le16_to_cpu(*(__le16 *) &curr_ptr[0]); |
1212 | pkt_type = le16_to_cpu(*(__le16 *) &curr_ptr[2]); | |
5e6e3a92 BZ |
1213 | |
1214 | /* copy pkt to deaggr buf */ | |
1215 | skb_deaggr = card->mpa_rx.skb_arr[pind]; | |
1216 | ||
1217 | if ((pkt_type == MWIFIEX_TYPE_DATA) && (pkt_len <= | |
1218 | card->mpa_rx.len_arr[pind])) { | |
1219 | ||
1220 | memcpy(skb_deaggr->data, curr_ptr, pkt_len); | |
1221 | ||
1222 | skb_trim(skb_deaggr, pkt_len); | |
1223 | ||
1224 | /* Process de-aggr packet */ | |
1225 | mwifiex_decode_rx_packet(adapter, skb_deaggr, | |
1226 | pkt_type); | |
1227 | } else { | |
1228 | dev_err(adapter->dev, "wrong aggr pkt:" | |
1229 | " type=%d len=%d max_len=%d\n", | |
1230 | pkt_type, pkt_len, | |
1231 | card->mpa_rx.len_arr[pind]); | |
1232 | dev_kfree_skb_any(skb_deaggr); | |
1233 | } | |
1234 | curr_ptr += card->mpa_rx.len_arr[pind]; | |
1235 | } | |
1236 | MP_RX_AGGR_BUF_RESET(card); | |
1237 | } | |
1238 | ||
1239 | rx_curr_single: | |
1240 | if (f_do_rx_cur) { | |
1241 | dev_dbg(adapter->dev, "info: RX: port: %d, rx_len: %d\n", | |
1242 | port, rx_len); | |
1243 | ||
1244 | if (mwifiex_sdio_card_to_host(adapter, &pkt_type, | |
1245 | skb->data, skb->len, | |
1246 | adapter->ioport + port)) | |
17a60b48 | 1247 | goto error; |
5e6e3a92 BZ |
1248 | |
1249 | mwifiex_decode_rx_packet(adapter, skb, pkt_type); | |
1250 | } | |
1251 | ||
1252 | return 0; | |
17a60b48 AP |
1253 | |
1254 | error: | |
1255 | if (MP_RX_AGGR_IN_PROGRESS(card)) { | |
1256 | /* Multiport-aggregation transfer failed - cleanup */ | |
1257 | for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) { | |
1258 | /* copy pkt to deaggr buf */ | |
1259 | skb_deaggr = card->mpa_rx.skb_arr[pind]; | |
1260 | dev_kfree_skb_any(skb_deaggr); | |
1261 | } | |
1262 | MP_RX_AGGR_BUF_RESET(card); | |
1263 | } | |
1264 | ||
1265 | if (f_do_rx_cur) | |
1266 | /* Single transfer pending. Free curr buff also */ | |
1267 | dev_kfree_skb_any(skb); | |
1268 | ||
1269 | return -1; | |
5e6e3a92 BZ |
1270 | } |
1271 | ||
1272 | /* | |
1273 | * This function checks the current interrupt status. | |
1274 | * | |
1275 | * The following interrupts are checked and handled by this function - | |
1276 | * - Data sent | |
1277 | * - Command sent | |
1278 | * - Packets received | |
1279 | * | |
1280 | * Since the firmware does not generate download ready interrupt if the | |
1281 | * port updated is command port only, command sent interrupt checking | |
1282 | * should be done manually, and for every SDIO interrupt. | |
1283 | * | |
1284 | * In case of Rx packets received, the packets are uploaded from card to | |
1285 | * host and processed accordingly. | |
1286 | */ | |
1287 | static int mwifiex_process_int_status(struct mwifiex_adapter *adapter) | |
1288 | { | |
1289 | struct sdio_mmc_card *card = adapter->card; | |
05889f82 | 1290 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
5e6e3a92 BZ |
1291 | int ret = 0; |
1292 | u8 sdio_ireg; | |
270e58e8 | 1293 | struct sk_buff *skb; |
5e6e3a92 BZ |
1294 | u8 port = CTRL_PORT; |
1295 | u32 len_reg_l, len_reg_u; | |
1296 | u32 rx_blocks; | |
1297 | u16 rx_len; | |
1298 | unsigned long flags; | |
b60186f8 YAP |
1299 | u32 bitmap; |
1300 | u8 cr; | |
5e6e3a92 BZ |
1301 | |
1302 | spin_lock_irqsave(&adapter->int_lock, flags); | |
1303 | sdio_ireg = adapter->int_status; | |
1304 | adapter->int_status = 0; | |
1305 | spin_unlock_irqrestore(&adapter->int_lock, flags); | |
1306 | ||
1307 | if (!sdio_ireg) | |
1308 | return ret; | |
1309 | ||
b60186f8 YAP |
1310 | /* Following interrupt is only for SDIO new mode */ |
1311 | if (sdio_ireg & DN_LD_CMD_PORT_HOST_INT_STATUS && adapter->cmd_sent) | |
1312 | adapter->cmd_sent = false; | |
1313 | ||
1314 | /* Following interrupt is only for SDIO new mode */ | |
1315 | if (sdio_ireg & UP_LD_CMD_PORT_HOST_INT_STATUS) { | |
1316 | u32 pkt_type; | |
1317 | ||
1318 | /* read the len of control packet */ | |
1319 | rx_len = card->mp_regs[CMD_RD_LEN_1] << 8; | |
1320 | rx_len |= (u16) card->mp_regs[CMD_RD_LEN_0]; | |
1321 | rx_blocks = DIV_ROUND_UP(rx_len, MWIFIEX_SDIO_BLOCK_SIZE); | |
1322 | if (rx_len <= INTF_HEADER_LEN || | |
1323 | (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) > | |
1324 | MWIFIEX_RX_DATA_BUF_SIZE) | |
1325 | return -1; | |
1326 | rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE); | |
1327 | ||
1328 | skb = dev_alloc_skb(rx_len); | |
1329 | if (!skb) | |
1330 | return -1; | |
1331 | ||
1332 | skb_put(skb, rx_len); | |
1333 | ||
1334 | if (mwifiex_sdio_card_to_host(adapter, &pkt_type, skb->data, | |
1335 | skb->len, adapter->ioport | | |
1336 | CMD_PORT_SLCT)) { | |
1337 | dev_err(adapter->dev, | |
1338 | "%s: failed to card_to_host", __func__); | |
1339 | dev_kfree_skb_any(skb); | |
1340 | goto term_cmd; | |
1341 | } | |
1342 | ||
1343 | if ((pkt_type != MWIFIEX_TYPE_CMD) && | |
1344 | (pkt_type != MWIFIEX_TYPE_EVENT)) | |
1345 | dev_err(adapter->dev, | |
1346 | "%s:Received wrong packet on cmd port", | |
1347 | __func__); | |
1348 | ||
1349 | mwifiex_decode_rx_packet(adapter, skb, pkt_type); | |
1350 | } | |
1351 | ||
5e6e3a92 | 1352 | if (sdio_ireg & DN_LD_HOST_INT_STATUS) { |
b60186f8 YAP |
1353 | bitmap = (u32) card->mp_regs[reg->wr_bitmap_l]; |
1354 | bitmap |= ((u32) card->mp_regs[reg->wr_bitmap_u]) << 8; | |
1355 | if (card->supports_sdio_new_mode) { | |
1356 | bitmap |= | |
1357 | ((u32) card->mp_regs[reg->wr_bitmap_1l]) << 16; | |
1358 | bitmap |= | |
1359 | ((u32) card->mp_regs[reg->wr_bitmap_1u]) << 24; | |
1360 | } | |
1361 | card->mp_wr_bitmap = bitmap; | |
1362 | ||
1363 | dev_dbg(adapter->dev, "int: DNLD: wr_bitmap=0x%x\n", | |
5dbd326c | 1364 | card->mp_wr_bitmap); |
5e6e3a92 BZ |
1365 | if (adapter->data_sent && |
1366 | (card->mp_wr_bitmap & card->mp_data_port_mask)) { | |
1367 | dev_dbg(adapter->dev, | |
1368 | "info: <--- Tx DONE Interrupt --->\n"); | |
1369 | adapter->data_sent = false; | |
1370 | } | |
1371 | } | |
1372 | ||
1373 | /* As firmware will not generate download ready interrupt if the port | |
1374 | updated is command port only, cmd_sent should be done for any SDIO | |
1375 | interrupt. */ | |
b60186f8 | 1376 | if (card->has_control_mask && adapter->cmd_sent) { |
5e6e3a92 BZ |
1377 | /* Check if firmware has attach buffer at command port and |
1378 | update just that in wr_bit_map. */ | |
1379 | card->mp_wr_bitmap |= | |
05889f82 | 1380 | (u32) card->mp_regs[reg->wr_bitmap_l] & CTRL_PORT_MASK; |
5e6e3a92 BZ |
1381 | if (card->mp_wr_bitmap & CTRL_PORT_MASK) |
1382 | adapter->cmd_sent = false; | |
1383 | } | |
1384 | ||
1385 | dev_dbg(adapter->dev, "info: cmd_sent=%d data_sent=%d\n", | |
5dbd326c | 1386 | adapter->cmd_sent, adapter->data_sent); |
5e6e3a92 | 1387 | if (sdio_ireg & UP_LD_HOST_INT_STATUS) { |
b60186f8 YAP |
1388 | bitmap = (u32) card->mp_regs[reg->rd_bitmap_l]; |
1389 | bitmap |= ((u32) card->mp_regs[reg->rd_bitmap_u]) << 8; | |
1390 | if (card->supports_sdio_new_mode) { | |
1391 | bitmap |= | |
1392 | ((u32) card->mp_regs[reg->rd_bitmap_1l]) << 16; | |
1393 | bitmap |= | |
1394 | ((u32) card->mp_regs[reg->rd_bitmap_1u]) << 24; | |
1395 | } | |
1396 | card->mp_rd_bitmap = bitmap; | |
1397 | dev_dbg(adapter->dev, "int: UPLD: rd_bitmap=0x%x\n", | |
5dbd326c | 1398 | card->mp_rd_bitmap); |
5e6e3a92 BZ |
1399 | |
1400 | while (true) { | |
1401 | ret = mwifiex_get_rd_port(adapter, &port); | |
1402 | if (ret) { | |
1403 | dev_dbg(adapter->dev, | |
1404 | "info: no more rd_port available\n"); | |
1405 | break; | |
1406 | } | |
05889f82 AK |
1407 | len_reg_l = reg->rd_len_p0_l + (port << 1); |
1408 | len_reg_u = reg->rd_len_p0_u + (port << 1); | |
5e6e3a92 BZ |
1409 | rx_len = ((u16) card->mp_regs[len_reg_u]) << 8; |
1410 | rx_len |= (u16) card->mp_regs[len_reg_l]; | |
1411 | dev_dbg(adapter->dev, "info: RX: port=%d rx_len=%u\n", | |
5dbd326c | 1412 | port, rx_len); |
5e6e3a92 BZ |
1413 | rx_blocks = |
1414 | (rx_len + MWIFIEX_SDIO_BLOCK_SIZE - | |
1415 | 1) / MWIFIEX_SDIO_BLOCK_SIZE; | |
5dbd326c YAP |
1416 | if (rx_len <= INTF_HEADER_LEN || |
1417 | (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) > | |
1418 | MWIFIEX_RX_DATA_BUF_SIZE) { | |
5e6e3a92 | 1419 | dev_err(adapter->dev, "invalid rx_len=%d\n", |
5dbd326c | 1420 | rx_len); |
5e6e3a92 BZ |
1421 | return -1; |
1422 | } | |
1423 | rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE); | |
1424 | ||
1425 | skb = dev_alloc_skb(rx_len); | |
1426 | ||
1427 | if (!skb) { | |
1428 | dev_err(adapter->dev, "%s: failed to alloc skb", | |
5dbd326c | 1429 | __func__); |
5e6e3a92 BZ |
1430 | return -1; |
1431 | } | |
1432 | ||
1433 | skb_put(skb, rx_len); | |
1434 | ||
1435 | dev_dbg(adapter->dev, "info: rx_len = %d skb->len = %d\n", | |
5dbd326c | 1436 | rx_len, skb->len); |
5e6e3a92 BZ |
1437 | |
1438 | if (mwifiex_sdio_card_to_host_mp_aggr(adapter, skb, | |
1439 | port)) { | |
5e6e3a92 | 1440 | dev_err(adapter->dev, "card_to_host_mpa failed:" |
5dbd326c | 1441 | " int status=%#x\n", sdio_ireg); |
b60186f8 | 1442 | goto term_cmd; |
5e6e3a92 BZ |
1443 | } |
1444 | } | |
1445 | } | |
1446 | ||
1447 | return 0; | |
b60186f8 YAP |
1448 | |
1449 | term_cmd: | |
1450 | /* terminate cmd */ | |
1451 | if (mwifiex_read_reg(adapter, CONFIGURATION_REG, &cr)) | |
1452 | dev_err(adapter->dev, "read CFG reg failed\n"); | |
1453 | else | |
1454 | dev_dbg(adapter->dev, "info: CFG reg val = %d\n", cr); | |
1455 | ||
1456 | if (mwifiex_write_reg(adapter, CONFIGURATION_REG, (cr | 0x04))) | |
1457 | dev_err(adapter->dev, "write CFG reg failed\n"); | |
1458 | else | |
1459 | dev_dbg(adapter->dev, "info: write success\n"); | |
1460 | ||
1461 | if (mwifiex_read_reg(adapter, CONFIGURATION_REG, &cr)) | |
1462 | dev_err(adapter->dev, "read CFG reg failed\n"); | |
1463 | else | |
1464 | dev_dbg(adapter->dev, "info: CFG reg val =%x\n", cr); | |
1465 | ||
1466 | return -1; | |
5e6e3a92 BZ |
1467 | } |
1468 | ||
1469 | /* | |
1470 | * This function aggregates transmission buffers in driver and downloads | |
1471 | * the aggregated packet to card. | |
1472 | * | |
1473 | * The individual packets are aggregated by copying into an aggregation | |
1474 | * buffer and then downloaded to the card. Previous unsent packets in the | |
1475 | * aggregation buffer are pre-copied first before new packets are added. | |
1476 | * Aggregation is done till there is space left in the aggregation buffer, | |
1477 | * or till new packets are available. | |
1478 | * | |
1479 | * The function will only download the packet to the card when aggregation | |
1480 | * stops, otherwise it will just aggregate the packet in aggregation buffer | |
1481 | * and return. | |
1482 | */ | |
1483 | static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter *adapter, | |
0fc0d43b | 1484 | u8 *payload, u32 pkt_len, u32 port, |
5e6e3a92 BZ |
1485 | u32 next_pkt_len) |
1486 | { | |
1487 | struct sdio_mmc_card *card = adapter->card; | |
1488 | int ret = 0; | |
1489 | s32 f_send_aggr_buf = 0; | |
1490 | s32 f_send_cur_buf = 0; | |
1491 | s32 f_precopy_cur_buf = 0; | |
1492 | s32 f_postcopy_cur_buf = 0; | |
0fc0d43b | 1493 | u32 mport; |
5e6e3a92 | 1494 | |
b60186f8 YAP |
1495 | if (!card->mpa_tx.enabled || |
1496 | (card->has_control_mask && (port == CTRL_PORT)) || | |
1497 | (card->supports_sdio_new_mode && (port == CMD_PORT_SLCT))) { | |
5e6e3a92 | 1498 | dev_dbg(adapter->dev, "info: %s: tx aggregation disabled\n", |
5dbd326c | 1499 | __func__); |
5e6e3a92 BZ |
1500 | |
1501 | f_send_cur_buf = 1; | |
1502 | goto tx_curr_single; | |
1503 | } | |
1504 | ||
1505 | if (next_pkt_len) { | |
1506 | /* More pkt in TX queue */ | |
1507 | dev_dbg(adapter->dev, "info: %s: more packets in queue.\n", | |
5dbd326c | 1508 | __func__); |
5e6e3a92 BZ |
1509 | |
1510 | if (MP_TX_AGGR_IN_PROGRESS(card)) { | |
c23b7c8f | 1511 | if (!mp_tx_aggr_port_limit_reached(card) && |
5e6e3a92 BZ |
1512 | MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) { |
1513 | f_precopy_cur_buf = 1; | |
1514 | ||
1515 | if (!(card->mp_wr_bitmap & | |
5dbd326c YAP |
1516 | (1 << card->curr_wr_port)) || |
1517 | !MP_TX_AGGR_BUF_HAS_ROOM( | |
1518 | card, pkt_len + next_pkt_len)) | |
5e6e3a92 BZ |
1519 | f_send_aggr_buf = 1; |
1520 | } else { | |
1521 | /* No room in Aggr buf, send it */ | |
1522 | f_send_aggr_buf = 1; | |
1523 | ||
c23b7c8f | 1524 | if (mp_tx_aggr_port_limit_reached(card) || |
5e6e3a92 BZ |
1525 | !(card->mp_wr_bitmap & |
1526 | (1 << card->curr_wr_port))) | |
1527 | f_send_cur_buf = 1; | |
1528 | else | |
1529 | f_postcopy_cur_buf = 1; | |
1530 | } | |
1531 | } else { | |
5dbd326c YAP |
1532 | if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len) && |
1533 | (card->mp_wr_bitmap & (1 << card->curr_wr_port))) | |
5e6e3a92 BZ |
1534 | f_precopy_cur_buf = 1; |
1535 | else | |
1536 | f_send_cur_buf = 1; | |
1537 | } | |
1538 | } else { | |
1539 | /* Last pkt in TX queue */ | |
1540 | dev_dbg(adapter->dev, "info: %s: Last packet in Tx Queue.\n", | |
5dbd326c | 1541 | __func__); |
5e6e3a92 BZ |
1542 | |
1543 | if (MP_TX_AGGR_IN_PROGRESS(card)) { | |
1544 | /* some packs in Aggr buf already */ | |
1545 | f_send_aggr_buf = 1; | |
1546 | ||
1547 | if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) | |
1548 | f_precopy_cur_buf = 1; | |
1549 | else | |
1550 | /* No room in Aggr buf, send it */ | |
1551 | f_send_cur_buf = 1; | |
1552 | } else { | |
1553 | f_send_cur_buf = 1; | |
1554 | } | |
1555 | } | |
1556 | ||
1557 | if (f_precopy_cur_buf) { | |
1558 | dev_dbg(adapter->dev, "data: %s: precopy current buffer\n", | |
5dbd326c | 1559 | __func__); |
5e6e3a92 BZ |
1560 | MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port); |
1561 | ||
1562 | if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) || | |
c23b7c8f | 1563 | mp_tx_aggr_port_limit_reached(card)) |
5e6e3a92 BZ |
1564 | /* No more pkts allowed in Aggr buf, send it */ |
1565 | f_send_aggr_buf = 1; | |
1566 | } | |
1567 | ||
1568 | if (f_send_aggr_buf) { | |
1569 | dev_dbg(adapter->dev, "data: %s: send aggr buffer: %d %d\n", | |
5dbd326c | 1570 | __func__, |
5e6e3a92 | 1571 | card->mpa_tx.start_port, card->mpa_tx.ports); |
b60186f8 YAP |
1572 | if (card->supports_sdio_new_mode) { |
1573 | u32 port_count; | |
1574 | int i; | |
1575 | ||
1576 | for (i = 0, port_count = 0; i < card->max_ports; i++) | |
1577 | if (card->mpa_tx.ports & BIT(i)) | |
1578 | port_count++; | |
1579 | ||
1580 | /* Writing data from "start_port + 0" to "start_port + | |
1581 | * port_count -1", so decrease the count by 1 | |
1582 | */ | |
1583 | port_count--; | |
1584 | mport = (adapter->ioport | SDIO_MPA_ADDR_BASE | | |
1585 | (port_count << 8)) + card->mpa_tx.start_port; | |
1586 | } else { | |
1587 | mport = (adapter->ioport | SDIO_MPA_ADDR_BASE | | |
1588 | (card->mpa_tx.ports << 4)) + | |
1589 | card->mpa_tx.start_port; | |
1590 | } | |
1591 | ||
5e6e3a92 | 1592 | ret = mwifiex_write_data_to_card(adapter, card->mpa_tx.buf, |
0fc0d43b | 1593 | card->mpa_tx.buf_len, mport); |
5e6e3a92 BZ |
1594 | |
1595 | MP_TX_AGGR_BUF_RESET(card); | |
1596 | } | |
1597 | ||
1598 | tx_curr_single: | |
1599 | if (f_send_cur_buf) { | |
1600 | dev_dbg(adapter->dev, "data: %s: send current buffer %d\n", | |
5dbd326c | 1601 | __func__, port); |
5e6e3a92 BZ |
1602 | ret = mwifiex_write_data_to_card(adapter, payload, pkt_len, |
1603 | adapter->ioport + port); | |
1604 | } | |
1605 | ||
1606 | if (f_postcopy_cur_buf) { | |
1607 | dev_dbg(adapter->dev, "data: %s: postcopy current buffer\n", | |
5dbd326c | 1608 | __func__); |
5e6e3a92 BZ |
1609 | MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port); |
1610 | } | |
1611 | ||
1612 | return ret; | |
1613 | } | |
1614 | ||
1615 | /* | |
1616 | * This function downloads data from driver to card. | |
1617 | * | |
1618 | * Both commands and data packets are transferred to the card by this | |
1619 | * function. | |
1620 | * | |
1621 | * This function adds the SDIO specific header to the front of the buffer | |
1622 | * before transferring. The header contains the length of the packet and | |
1623 | * the type. The firmware handles the packets based upon this set type. | |
1624 | */ | |
1625 | static int mwifiex_sdio_host_to_card(struct mwifiex_adapter *adapter, | |
d930faee | 1626 | u8 type, struct sk_buff *skb, |
5e6e3a92 BZ |
1627 | struct mwifiex_tx_param *tx_param) |
1628 | { | |
1629 | struct sdio_mmc_card *card = adapter->card; | |
270e58e8 | 1630 | int ret; |
5e6e3a92 BZ |
1631 | u32 buf_block_len; |
1632 | u32 blk_size; | |
0fc0d43b | 1633 | u32 port = CTRL_PORT; |
d930faee AK |
1634 | u8 *payload = (u8 *)skb->data; |
1635 | u32 pkt_len = skb->len; | |
5e6e3a92 BZ |
1636 | |
1637 | /* Allocate buffer and copy payload */ | |
1638 | blk_size = MWIFIEX_SDIO_BLOCK_SIZE; | |
1639 | buf_block_len = (pkt_len + blk_size - 1) / blk_size; | |
83e612f6 TM |
1640 | *(__le16 *)&payload[0] = cpu_to_le16((u16)pkt_len); |
1641 | *(__le16 *)&payload[2] = cpu_to_le16(type); | |
5e6e3a92 BZ |
1642 | |
1643 | /* | |
1644 | * This is SDIO specific header | |
1645 | * u16 length, | |
1646 | * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1, | |
1647 | * MWIFIEX_TYPE_EVENT = 3) | |
1648 | */ | |
1649 | if (type == MWIFIEX_TYPE_DATA) { | |
1650 | ret = mwifiex_get_wr_port_data(adapter, &port); | |
1651 | if (ret) { | |
1652 | dev_err(adapter->dev, "%s: no wr_port available\n", | |
5dbd326c | 1653 | __func__); |
5e6e3a92 BZ |
1654 | return ret; |
1655 | } | |
1656 | } else { | |
1657 | adapter->cmd_sent = true; | |
1658 | /* Type must be MWIFIEX_TYPE_CMD */ | |
1659 | ||
1660 | if (pkt_len <= INTF_HEADER_LEN || | |
1661 | pkt_len > MWIFIEX_UPLD_SIZE) | |
1662 | dev_err(adapter->dev, "%s: payload=%p, nb=%d\n", | |
5dbd326c | 1663 | __func__, payload, pkt_len); |
b60186f8 YAP |
1664 | |
1665 | if (card->supports_sdio_new_mode) | |
1666 | port = CMD_PORT_SLCT; | |
5e6e3a92 BZ |
1667 | } |
1668 | ||
1669 | /* Transfer data to card */ | |
1670 | pkt_len = buf_block_len * blk_size; | |
1671 | ||
1672 | if (tx_param) | |
1673 | ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len, | |
5dbd326c YAP |
1674 | port, tx_param->next_pkt_len |
1675 | ); | |
5e6e3a92 BZ |
1676 | else |
1677 | ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len, | |
5dbd326c | 1678 | port, 0); |
5e6e3a92 BZ |
1679 | |
1680 | if (ret) { | |
1681 | if (type == MWIFIEX_TYPE_CMD) | |
1682 | adapter->cmd_sent = false; | |
bb71d01a | 1683 | if (type == MWIFIEX_TYPE_DATA) { |
5e6e3a92 | 1684 | adapter->data_sent = false; |
bb71d01a AP |
1685 | /* restore curr_wr_port in error cases */ |
1686 | card->curr_wr_port = port; | |
1687 | card->mp_wr_bitmap |= (u32)(1 << card->curr_wr_port); | |
1688 | } | |
5e6e3a92 BZ |
1689 | } else { |
1690 | if (type == MWIFIEX_TYPE_DATA) { | |
1691 | if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port))) | |
1692 | adapter->data_sent = true; | |
1693 | else | |
1694 | adapter->data_sent = false; | |
1695 | } | |
1696 | } | |
1697 | ||
1698 | return ret; | |
1699 | } | |
1700 | ||
1701 | /* | |
1702 | * This function allocates the MPA Tx and Rx buffers. | |
1703 | */ | |
1704 | static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter, | |
1705 | u32 mpa_tx_buf_size, u32 mpa_rx_buf_size) | |
1706 | { | |
1707 | struct sdio_mmc_card *card = adapter->card; | |
1708 | int ret = 0; | |
1709 | ||
1710 | card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL); | |
1711 | if (!card->mpa_tx.buf) { | |
5e6e3a92 BZ |
1712 | ret = -1; |
1713 | goto error; | |
1714 | } | |
1715 | ||
1716 | card->mpa_tx.buf_size = mpa_tx_buf_size; | |
1717 | ||
1718 | card->mpa_rx.buf = kzalloc(mpa_rx_buf_size, GFP_KERNEL); | |
1719 | if (!card->mpa_rx.buf) { | |
5e6e3a92 BZ |
1720 | ret = -1; |
1721 | goto error; | |
1722 | } | |
1723 | ||
1724 | card->mpa_rx.buf_size = mpa_rx_buf_size; | |
1725 | ||
1726 | error: | |
1727 | if (ret) { | |
1728 | kfree(card->mpa_tx.buf); | |
1729 | kfree(card->mpa_rx.buf); | |
1730 | } | |
1731 | ||
1732 | return ret; | |
1733 | } | |
1734 | ||
1735 | /* | |
1736 | * This function unregisters the SDIO device. | |
1737 | * | |
1738 | * The SDIO IRQ is released, the function is disabled and driver | |
1739 | * data is set to null. | |
1740 | */ | |
1741 | static void | |
1742 | mwifiex_unregister_dev(struct mwifiex_adapter *adapter) | |
1743 | { | |
1744 | struct sdio_mmc_card *card = adapter->card; | |
1745 | ||
1746 | if (adapter->card) { | |
5e6e3a92 | 1747 | sdio_claim_host(card->func); |
5e6e3a92 BZ |
1748 | sdio_disable_func(card->func); |
1749 | sdio_release_host(card->func); | |
5e6e3a92 BZ |
1750 | } |
1751 | } | |
1752 | ||
1753 | /* | |
1754 | * This function registers the SDIO device. | |
1755 | * | |
1756 | * SDIO IRQ is claimed, block size is set and driver data is initialized. | |
1757 | */ | |
1758 | static int mwifiex_register_dev(struct mwifiex_adapter *adapter) | |
1759 | { | |
232fde06 | 1760 | int ret; |
5e6e3a92 BZ |
1761 | struct sdio_mmc_card *card = adapter->card; |
1762 | struct sdio_func *func = card->func; | |
1763 | ||
1764 | /* save adapter pointer in card */ | |
1765 | card->adapter = adapter; | |
828cf222 | 1766 | adapter->tx_buf_size = card->tx_buf_size; |
5e6e3a92 BZ |
1767 | |
1768 | sdio_claim_host(func); | |
1769 | ||
5e6e3a92 BZ |
1770 | /* Set block size */ |
1771 | ret = sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE); | |
232fde06 | 1772 | sdio_release_host(func); |
5e6e3a92 BZ |
1773 | if (ret) { |
1774 | pr_err("cannot set SDIO block size\n"); | |
232fde06 | 1775 | return ret; |
5e6e3a92 BZ |
1776 | } |
1777 | ||
5e6e3a92 BZ |
1778 | |
1779 | adapter->dev = &func->dev; | |
e3bea1c8 | 1780 | |
05889f82 | 1781 | strcpy(adapter->fw_name, card->firmware); |
5e6e3a92 BZ |
1782 | |
1783 | return 0; | |
5e6e3a92 BZ |
1784 | } |
1785 | ||
1786 | /* | |
1787 | * This function initializes the SDIO driver. | |
1788 | * | |
1789 | * The following initializations steps are followed - | |
1790 | * - Read the Host interrupt status register to acknowledge | |
1791 | * the first interrupt got from bootloader | |
1792 | * - Disable host interrupt mask register | |
1793 | * - Get SDIO port | |
5e6e3a92 BZ |
1794 | * - Initialize SDIO variables in card |
1795 | * - Allocate MP registers | |
1796 | * - Allocate MPA Tx and Rx buffers | |
1797 | */ | |
1798 | static int mwifiex_init_sdio(struct mwifiex_adapter *adapter) | |
1799 | { | |
1800 | struct sdio_mmc_card *card = adapter->card; | |
05889f82 | 1801 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
5e6e3a92 | 1802 | int ret; |
ab93d4ff | 1803 | u8 sdio_ireg; |
5e6e3a92 | 1804 | |
3c59e328 AK |
1805 | sdio_set_drvdata(card->func, card); |
1806 | ||
5e6e3a92 BZ |
1807 | /* |
1808 | * Read the HOST_INT_STATUS_REG for ACK the first interrupt got | |
1809 | * from the bootloader. If we don't do this we get a interrupt | |
1810 | * as soon as we register the irq. | |
1811 | */ | |
1812 | mwifiex_read_reg(adapter, HOST_INTSTATUS_REG, &sdio_ireg); | |
1813 | ||
5e6e3a92 BZ |
1814 | /* Get SDIO ioport */ |
1815 | mwifiex_init_sdio_ioport(adapter); | |
1816 | ||
5e6e3a92 BZ |
1817 | /* Initialize SDIO variables in card */ |
1818 | card->mp_rd_bitmap = 0; | |
1819 | card->mp_wr_bitmap = 0; | |
05889f82 AK |
1820 | card->curr_rd_port = reg->start_rd_port; |
1821 | card->curr_wr_port = reg->start_wr_port; | |
5e6e3a92 | 1822 | |
05889f82 | 1823 | card->mp_data_port_mask = reg->data_port_mask; |
5e6e3a92 BZ |
1824 | |
1825 | card->mpa_tx.buf_len = 0; | |
1826 | card->mpa_tx.pkt_cnt = 0; | |
1827 | card->mpa_tx.start_port = 0; | |
1828 | ||
7d7ab022 | 1829 | card->mpa_tx.enabled = 1; |
05889f82 | 1830 | card->mpa_tx.pkt_aggr_limit = card->mp_agg_pkt_limit; |
5e6e3a92 BZ |
1831 | |
1832 | card->mpa_rx.buf_len = 0; | |
1833 | card->mpa_rx.pkt_cnt = 0; | |
1834 | card->mpa_rx.start_port = 0; | |
1835 | ||
7d7ab022 | 1836 | card->mpa_rx.enabled = 1; |
05889f82 | 1837 | card->mpa_rx.pkt_aggr_limit = card->mp_agg_pkt_limit; |
5e6e3a92 BZ |
1838 | |
1839 | /* Allocate buffers for SDIO MP-A */ | |
05889f82 | 1840 | card->mp_regs = kzalloc(reg->max_mp_regs, GFP_KERNEL); |
0d2e7a5c | 1841 | if (!card->mp_regs) |
b53575ec | 1842 | return -ENOMEM; |
5e6e3a92 | 1843 | |
c23b7c8f AK |
1844 | /* Allocate skb pointer buffers */ |
1845 | card->mpa_rx.skb_arr = kzalloc((sizeof(void *)) * | |
1846 | card->mp_agg_pkt_limit, GFP_KERNEL); | |
1847 | card->mpa_rx.len_arr = kzalloc(sizeof(*card->mpa_rx.len_arr) * | |
1848 | card->mp_agg_pkt_limit, GFP_KERNEL); | |
5e6e3a92 | 1849 | ret = mwifiex_alloc_sdio_mpa_buffers(adapter, |
e1aa93a4 AK |
1850 | card->mp_tx_agg_buf_size, |
1851 | card->mp_rx_agg_buf_size); | |
5e6e3a92 BZ |
1852 | if (ret) { |
1853 | dev_err(adapter->dev, "failed to alloc sdio mp-a buffers\n"); | |
1854 | kfree(card->mp_regs); | |
1855 | return -1; | |
1856 | } | |
1857 | ||
1858 | return ret; | |
1859 | } | |
1860 | ||
1861 | /* | |
1862 | * This function resets the MPA Tx and Rx buffers. | |
1863 | */ | |
1864 | static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter *adapter) | |
1865 | { | |
1866 | struct sdio_mmc_card *card = adapter->card; | |
1867 | ||
1868 | MP_TX_AGGR_BUF_RESET(card); | |
1869 | MP_RX_AGGR_BUF_RESET(card); | |
1870 | } | |
1871 | ||
1872 | /* | |
1873 | * This function cleans up the allocated card buffers. | |
1874 | * | |
1875 | * The following are freed by this function - | |
1876 | * - MP registers | |
1877 | * - MPA Tx buffer | |
1878 | * - MPA Rx buffer | |
1879 | */ | |
1880 | static void mwifiex_cleanup_sdio(struct mwifiex_adapter *adapter) | |
1881 | { | |
1882 | struct sdio_mmc_card *card = adapter->card; | |
1883 | ||
1884 | kfree(card->mp_regs); | |
c23b7c8f AK |
1885 | kfree(card->mpa_rx.skb_arr); |
1886 | kfree(card->mpa_rx.len_arr); | |
5e6e3a92 BZ |
1887 | kfree(card->mpa_tx.buf); |
1888 | kfree(card->mpa_rx.buf); | |
3c59e328 AK |
1889 | sdio_set_drvdata(card->func, NULL); |
1890 | kfree(card); | |
5e6e3a92 BZ |
1891 | } |
1892 | ||
1893 | /* | |
1894 | * This function updates the MP end port in card. | |
1895 | */ | |
1896 | static void | |
1897 | mwifiex_update_mp_end_port(struct mwifiex_adapter *adapter, u16 port) | |
1898 | { | |
1899 | struct sdio_mmc_card *card = adapter->card; | |
05889f82 | 1900 | const struct mwifiex_sdio_card_reg *reg = card->reg; |
5e6e3a92 BZ |
1901 | int i; |
1902 | ||
1903 | card->mp_end_port = port; | |
1904 | ||
05889f82 | 1905 | card->mp_data_port_mask = reg->data_port_mask; |
5e6e3a92 | 1906 | |
b60186f8 YAP |
1907 | if (reg->start_wr_port) { |
1908 | for (i = 1; i <= card->max_ports - card->mp_end_port; i++) | |
1909 | card->mp_data_port_mask &= | |
1910 | ~(1 << (card->max_ports - i)); | |
1911 | } | |
5e6e3a92 | 1912 | |
05889f82 | 1913 | card->curr_wr_port = reg->start_wr_port; |
5e6e3a92 BZ |
1914 | |
1915 | dev_dbg(adapter->dev, "cmd: mp_end_port %d, data port mask 0x%x\n", | |
5dbd326c | 1916 | port, card->mp_data_port_mask); |
5e6e3a92 BZ |
1917 | } |
1918 | ||
d31ab357 | 1919 | static struct mmc_host *reset_host; |
8915d738 | 1920 | static void mwifiex_sdio_card_reset_work(struct work_struct *work) |
d31ab357 | 1921 | { |
7f5855c9 TH |
1922 | struct mmc_host *target = reset_host; |
1923 | ||
d31ab357 AK |
1924 | /* The actual reset operation must be run outside of driver thread. |
1925 | * This is because mmc_remove_host() will cause the device to be | |
1926 | * instantly destroyed, and the driver then needs to end its thread, | |
1927 | * leading to a deadlock. | |
1928 | * | |
1929 | * We run it in a totally independent workqueue. | |
1930 | */ | |
1931 | ||
1932 | pr_err("Resetting card...\n"); | |
7f5855c9 | 1933 | mmc_remove_host(target); |
d31ab357 AK |
1934 | /* 20ms delay is based on experiment with sdhci controller */ |
1935 | mdelay(20); | |
7f5855c9 | 1936 | mmc_add_host(target); |
d31ab357 | 1937 | } |
8915d738 AK |
1938 | |
1939 | static void mwifiex_sdio_work(struct work_struct *work) | |
1940 | { | |
1941 | struct mwifiex_adapter *adapter = | |
1942 | container_of(work, struct mwifiex_adapter, iface_work); | |
1943 | ||
1944 | if (test_and_clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET, | |
1945 | &adapter->iface_work_flags)) | |
1946 | mwifiex_sdio_card_reset_work(work); | |
1947 | } | |
d31ab357 AK |
1948 | |
1949 | /* This function resets the card */ | |
1950 | static void mwifiex_sdio_card_reset(struct mwifiex_adapter *adapter) | |
1951 | { | |
1952 | struct sdio_mmc_card *card = adapter->card; | |
1953 | ||
8915d738 AK |
1954 | if (test_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &adapter->iface_work_flags)) |
1955 | return; | |
1956 | ||
1957 | set_bit(MWIFIEX_IFACE_WORK_CARD_RESET, &adapter->iface_work_flags); | |
1958 | ||
d31ab357 | 1959 | reset_host = card->func->card->host; |
8915d738 | 1960 | schedule_work(&adapter->iface_work); |
d31ab357 AK |
1961 | } |
1962 | ||
5e6e3a92 BZ |
1963 | static struct mwifiex_if_ops sdio_ops = { |
1964 | .init_if = mwifiex_init_sdio, | |
1965 | .cleanup_if = mwifiex_cleanup_sdio, | |
1966 | .check_fw_status = mwifiex_check_fw_status, | |
1967 | .prog_fw = mwifiex_prog_fw_w_helper, | |
1968 | .register_dev = mwifiex_register_dev, | |
1969 | .unregister_dev = mwifiex_unregister_dev, | |
1970 | .enable_int = mwifiex_sdio_enable_host_int, | |
232fde06 | 1971 | .disable_int = mwifiex_sdio_disable_host_int, |
5e6e3a92 BZ |
1972 | .process_int_status = mwifiex_process_int_status, |
1973 | .host_to_card = mwifiex_sdio_host_to_card, | |
1974 | .wakeup = mwifiex_pm_wakeup_card, | |
1975 | .wakeup_complete = mwifiex_pm_wakeup_card_complete, | |
1976 | ||
1977 | /* SDIO specific */ | |
1978 | .update_mp_end_port = mwifiex_update_mp_end_port, | |
1979 | .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf, | |
d930faee AK |
1980 | .cmdrsp_complete = mwifiex_sdio_cmdrsp_complete, |
1981 | .event_complete = mwifiex_sdio_event_complete, | |
d31ab357 | 1982 | .card_reset = mwifiex_sdio_card_reset, |
8915d738 | 1983 | .iface_work = mwifiex_sdio_work, |
5e6e3a92 BZ |
1984 | }; |
1985 | ||
1986 | /* | |
1987 | * This function initializes the SDIO driver. | |
1988 | * | |
1989 | * This initiates the semaphore and registers the device with | |
1990 | * SDIO bus. | |
1991 | */ | |
1992 | static int | |
1993 | mwifiex_sdio_init_module(void) | |
1994 | { | |
5e6e3a92 BZ |
1995 | sema_init(&add_remove_card_sem, 1); |
1996 | ||
287546df AK |
1997 | /* Clear the flag in case user removes the card. */ |
1998 | user_rmmod = 0; | |
1999 | ||
636c4598 | 2000 | return sdio_register_driver(&mwifiex_sdio); |
5e6e3a92 BZ |
2001 | } |
2002 | ||
2003 | /* | |
2004 | * This function cleans up the SDIO driver. | |
2005 | * | |
2006 | * The following major steps are followed for cleanup - | |
2007 | * - Resume the device if its suspended | |
2008 | * - Disconnect the device if connected | |
2009 | * - Shutdown the firmware | |
2010 | * - Unregister the device from SDIO bus. | |
2011 | */ | |
2012 | static void | |
2013 | mwifiex_sdio_cleanup_module(void) | |
2014 | { | |
287546df AK |
2015 | if (!down_interruptible(&add_remove_card_sem)) |
2016 | up(&add_remove_card_sem); | |
5e6e3a92 | 2017 | |
287546df AK |
2018 | /* Set the flag as user is removing this module. */ |
2019 | user_rmmod = 1; | |
5e6e3a92 | 2020 | |
5e6e3a92 BZ |
2021 | sdio_unregister_driver(&mwifiex_sdio); |
2022 | } | |
2023 | ||
2024 | module_init(mwifiex_sdio_init_module); | |
2025 | module_exit(mwifiex_sdio_cleanup_module); | |
2026 | ||
2027 | MODULE_AUTHOR("Marvell International Ltd."); | |
2028 | MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION); | |
2029 | MODULE_VERSION(SDIO_VERSION); | |
2030 | MODULE_LICENSE("GPL v2"); | |
98e6b9df | 2031 | MODULE_FIRMWARE(SD8786_DEFAULT_FW_NAME); |
e3bea1c8 BZ |
2032 | MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME); |
2033 | MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME); | |
b60186f8 | 2034 | MODULE_FIRMWARE(SD8897_DEFAULT_FW_NAME); |