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