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