staging: brmc80211: cleaned up sdio related error codes
[deliverable/linux.git] / drivers / staging / brcm80211 / brcmfmac / bcmsdh_sdmmc.c
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16 #include <linux/types.h>
17 #include <linux/netdevice.h>
18 #include <linux/mmc/sdio.h>
19 #include <linux/mmc/core.h>
20 #include <linux/mmc/sdio_func.h>
21 #include <linux/mmc/sdio_ids.h>
22 #include <linux/suspend.h>
23 #include <linux/errno.h>
24
25 #include <defs.h>
26 #include <brcm_hw_ids.h>
27 #include <brcmu_utils.h>
28 #include <brcmu_wifi.h>
29 #include "sdio_host.h"
30 #include "bcmsdbus.h" /* bcmsdh to/from specific controller APIs */
31 #include "sdiovar.h" /* ioctl/iovars */
32 #include "dngl_stats.h"
33 #include "dhd.h"
34 #include "bcmsdh_sdmmc.h"
35
36 static void brcmf_sdioh_irqhandler(struct sdio_func *func);
37 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func);
38 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr);
39
40 uint sd_f2_blocksize = 512; /* Default blocksize */
41
42 uint sd_msglevel = 0x01;
43 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_byte_wait);
44 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_word_wait);
45 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_packet_wait);
46 BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait);
47
48 #define DMA_ALIGN_MASK 0x03
49
50 static int
51 brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
52 int regsize, u32 *data);
53
54 static int brcmf_sdioh_enablefuncs(struct sdioh_info *sd)
55 {
56 int err_ret;
57 u32 fbraddr;
58 u8 func;
59
60 sd_trace(("%s\n", __func__));
61
62 /* Get the Card's common CIS address */
63 sd->com_cis_ptr = brcmf_sdioh_get_cisaddr(sd, SDIO_CCCR_CIS);
64 sd->func_cis_ptr[0] = sd->com_cis_ptr;
65 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
66 sd->com_cis_ptr));
67
68 /* Get the Card's function CIS (for each function) */
69 for (fbraddr = SDIO_FBR_BASE(1), func = 1;
70 func <= sd->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) {
71 sd->func_cis_ptr[func] =
72 brcmf_sdioh_get_cisaddr(sd, SDIO_FBR_CIS + fbraddr);
73 sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__, func,
74 sd->func_cis_ptr[func]));
75 }
76
77 sd->func_cis_ptr[0] = sd->com_cis_ptr;
78 sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__,
79 sd->com_cis_ptr));
80
81 /* Enable Function 1 */
82 sdio_claim_host(gInstance->func[1]);
83 err_ret = sdio_enable_func(gInstance->func[1]);
84 sdio_release_host(gInstance->func[1]);
85 if (err_ret) {
86 sd_err(("bcmsdh_sdmmc: Failed to enable F1 Err: 0x%08x",
87 err_ret));
88 }
89
90 return false;
91 }
92
93 /*
94 * Public entry points & extern's
95 */
96 struct sdioh_info *brcmf_sdioh_attach(void *bar0, uint irq)
97 {
98 struct sdioh_info *sd;
99 int err_ret;
100
101 sd_trace(("%s\n", __func__));
102
103 if (gInstance == NULL) {
104 sd_err(("%s: SDIO Device not present\n", __func__));
105 return NULL;
106 }
107
108 sd = kzalloc(sizeof(struct sdioh_info), GFP_ATOMIC);
109 if (sd == NULL) {
110 sd_err(("sdioh_attach: out of memory\n"));
111 return NULL;
112 }
113 if (brcmf_sdioh_osinit(sd) != 0) {
114 sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__));
115 kfree(sd);
116 return NULL;
117 }
118
119 sd->num_funcs = 2;
120 sd->use_client_ints = true;
121 sd->client_block_size[0] = 64;
122
123 gInstance->sd = sd;
124
125 /* Claim host controller */
126 sdio_claim_host(gInstance->func[1]);
127
128 sd->client_block_size[1] = 64;
129 err_ret = sdio_set_block_size(gInstance->func[1], 64);
130 if (err_ret)
131 sd_err(("bcmsdh_sdmmc: Failed to set F1 blocksize\n"));
132
133 /* Release host controller F1 */
134 sdio_release_host(gInstance->func[1]);
135
136 if (gInstance->func[2]) {
137 /* Claim host controller F2 */
138 sdio_claim_host(gInstance->func[2]);
139
140 sd->client_block_size[2] = sd_f2_blocksize;
141 err_ret =
142 sdio_set_block_size(gInstance->func[2], sd_f2_blocksize);
143 if (err_ret)
144 sd_err(("bcmsdh_sdmmc: Failed to set F2 blocksize "
145 "to %d\n", sd_f2_blocksize));
146
147 /* Release host controller F2 */
148 sdio_release_host(gInstance->func[2]);
149 }
150
151 brcmf_sdioh_enablefuncs(sd);
152
153 sd_trace(("%s: Done\n", __func__));
154 return sd;
155 }
156
157 extern int brcmf_sdioh_detach(struct sdioh_info *sd)
158 {
159 sd_trace(("%s\n", __func__));
160
161 if (sd) {
162
163 /* Disable Function 2 */
164 sdio_claim_host(gInstance->func[2]);
165 sdio_disable_func(gInstance->func[2]);
166 sdio_release_host(gInstance->func[2]);
167
168 /* Disable Function 1 */
169 sdio_claim_host(gInstance->func[1]);
170 sdio_disable_func(gInstance->func[1]);
171 sdio_release_host(gInstance->func[1]);
172
173 /* deregister irq */
174 brcmf_sdioh_osfree(sd);
175
176 kfree(sd);
177 }
178 return 0;
179 }
180
181 /* Configure callback to client when we receive client interrupt */
182 extern int
183 brcmf_sdioh_interrupt_register(struct sdioh_info *sd, sdioh_cb_fn_t fn,
184 void *argh)
185 {
186 sd_trace(("%s: Entering\n", __func__));
187 if (fn == NULL) {
188 sd_err(("%s: interrupt handler is NULL, not registering\n",
189 __func__));
190 return -EINVAL;
191 }
192
193 sd->intr_handler = fn;
194 sd->intr_handler_arg = argh;
195 sd->intr_handler_valid = true;
196
197 /* register and unmask irq */
198 if (gInstance->func[2]) {
199 sdio_claim_host(gInstance->func[2]);
200 sdio_claim_irq(gInstance->func[2], brcmf_sdioh_irqhandler_f2);
201 sdio_release_host(gInstance->func[2]);
202 }
203
204 if (gInstance->func[1]) {
205 sdio_claim_host(gInstance->func[1]);
206 sdio_claim_irq(gInstance->func[1], brcmf_sdioh_irqhandler);
207 sdio_release_host(gInstance->func[1]);
208 }
209
210 return 0;
211 }
212
213 extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *sd)
214 {
215 sd_trace(("%s: Entering\n", __func__));
216
217 if (gInstance->func[1]) {
218 /* register and unmask irq */
219 sdio_claim_host(gInstance->func[1]);
220 sdio_release_irq(gInstance->func[1]);
221 sdio_release_host(gInstance->func[1]);
222 }
223
224 if (gInstance->func[2]) {
225 /* Claim host controller F2 */
226 sdio_claim_host(gInstance->func[2]);
227 sdio_release_irq(gInstance->func[2]);
228 /* Release host controller F2 */
229 sdio_release_host(gInstance->func[2]);
230 }
231
232 sd->intr_handler_valid = false;
233 sd->intr_handler = NULL;
234 sd->intr_handler_arg = NULL;
235
236 return 0;
237 }
238
239 extern int
240 brcmf_sdioh_interrupt_query(struct sdioh_info *sd, bool *onoff)
241 {
242 sd_trace(("%s: Entering\n", __func__));
243 *onoff = sd->client_intr_enabled;
244 return 0;
245 }
246
247 #if defined(BCMDBG)
248 extern bool brcmf_sdioh_interrupt_pending(struct sdioh_info *sd)
249 {
250 return 0;
251 }
252 #endif
253
254 uint brcmf_sdioh_query_iofnum(struct sdioh_info *sd)
255 {
256 return sd->num_funcs;
257 }
258
259 /* IOVar table */
260 enum {
261 IOV_MSGLEVEL = 1,
262 IOV_BLOCKSIZE,
263 IOV_USEINTS,
264 IOV_NUMINTS,
265 IOV_DEVREG,
266 IOV_HCIREGS,
267 IOV_RXCHAIN
268 };
269
270 const struct brcmu_iovar sdioh_iovars[] = {
271 {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0},
272 {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0},/* ((fn << 16) |
273 size) */
274 {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0},
275 {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0},
276 {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)}
277 ,
278 {"sd_rxchain", IOV_RXCHAIN, 0, IOVT_BOOL, 0}
279 ,
280 {NULL, 0, 0, 0, 0}
281 };
282
283 int
284 brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name,
285 void *params, int plen, void *arg, int len, bool set)
286 {
287 const struct brcmu_iovar *vi = NULL;
288 int bcmerror = 0;
289 int val_size;
290 s32 int_val = 0;
291 bool bool_val;
292 u32 actionid;
293
294 ASSERT(name);
295 ASSERT(len >= 0);
296
297 /* Get must have return space; Set does not take qualifiers */
298 ASSERT(set || (arg && len));
299 ASSERT(!set || (!params && !plen));
300
301 sd_trace(("%s: Enter (%s %s)\n", __func__, (set ? "set" : "get"),
302 name));
303
304 vi = brcmu_iovar_lookup(sdioh_iovars, name);
305 if (vi == NULL) {
306 bcmerror = -ENOTSUPP;
307 goto exit;
308 }
309
310 bcmerror = brcmu_iovar_lencheck(vi, arg, len, set);
311 if (bcmerror != 0)
312 goto exit;
313
314 /* Set up params so get and set can share the convenience variables */
315 if (params == NULL) {
316 params = arg;
317 plen = len;
318 }
319
320 if (vi->type == IOVT_VOID)
321 val_size = 0;
322 else if (vi->type == IOVT_BUFFER)
323 val_size = len;
324 else
325 val_size = sizeof(int);
326
327 if (plen >= (int)sizeof(int_val))
328 memcpy(&int_val, params, sizeof(int_val));
329
330 bool_val = (int_val != 0) ? true : false;
331
332 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
333 switch (actionid) {
334 case IOV_GVAL(IOV_MSGLEVEL):
335 int_val = (s32) sd_msglevel;
336 memcpy(arg, &int_val, val_size);
337 break;
338
339 case IOV_SVAL(IOV_MSGLEVEL):
340 sd_msglevel = int_val;
341 break;
342
343 case IOV_GVAL(IOV_BLOCKSIZE):
344 if ((u32) int_val > si->num_funcs) {
345 bcmerror = -EINVAL;
346 break;
347 }
348 int_val = (s32) si->client_block_size[int_val];
349 memcpy(arg, &int_val, val_size);
350 break;
351
352 case IOV_SVAL(IOV_BLOCKSIZE):
353 {
354 uint func = ((u32) int_val >> 16);
355 uint blksize = (u16) int_val;
356 uint maxsize;
357
358 if (func > si->num_funcs) {
359 bcmerror = -EINVAL;
360 break;
361 }
362
363 switch (func) {
364 case 0:
365 maxsize = 32;
366 break;
367 case 1:
368 maxsize = BLOCK_SIZE_4318;
369 break;
370 case 2:
371 maxsize = BLOCK_SIZE_4328;
372 break;
373 default:
374 maxsize = 0;
375 }
376 if (blksize > maxsize) {
377 bcmerror = -EINVAL;
378 break;
379 }
380 if (!blksize)
381 blksize = maxsize;
382
383 /* Now set it */
384 si->client_block_size[func] = blksize;
385
386 break;
387 }
388
389 case IOV_GVAL(IOV_RXCHAIN):
390 int_val = false;
391 memcpy(arg, &int_val, val_size);
392 break;
393
394 case IOV_GVAL(IOV_USEINTS):
395 int_val = (s32) si->use_client_ints;
396 memcpy(arg, &int_val, val_size);
397 break;
398
399 case IOV_SVAL(IOV_USEINTS):
400 si->use_client_ints = (bool) int_val;
401 if (si->use_client_ints)
402 si->intmask |= CLIENT_INTR;
403 else
404 si->intmask &= ~CLIENT_INTR;
405
406 break;
407
408 case IOV_GVAL(IOV_NUMINTS):
409 int_val = (s32) si->intrcount;
410 memcpy(arg, &int_val, val_size);
411 break;
412
413 case IOV_GVAL(IOV_DEVREG):
414 {
415 struct brcmf_sdreg *sd_ptr =
416 (struct brcmf_sdreg *) params;
417 u8 data = 0;
418
419 if (brcmf_sdioh_cfg_read
420 (si, sd_ptr->func, sd_ptr->offset, &data)) {
421 bcmerror = -EIO;
422 break;
423 }
424
425 int_val = (int)data;
426 memcpy(arg, &int_val, sizeof(int_val));
427 break;
428 }
429
430 case IOV_SVAL(IOV_DEVREG):
431 {
432 struct brcmf_sdreg *sd_ptr =
433 (struct brcmf_sdreg *) params;
434 u8 data = (u8) sd_ptr->value;
435
436 if (brcmf_sdioh_cfg_write
437 (si, sd_ptr->func, sd_ptr->offset, &data)) {
438 bcmerror = -EIO;
439 break;
440 }
441 break;
442 }
443
444 default:
445 bcmerror = -ENOTSUPP;
446 break;
447 }
448 exit:
449
450 return bcmerror;
451 }
452
453 extern int
454 brcmf_sdioh_cfg_read(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
455 {
456 int status;
457 /* No lock needed since brcmf_sdioh_request_byte does locking */
458 status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data);
459 return status;
460 }
461
462 extern int
463 brcmf_sdioh_cfg_write(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data)
464 {
465 /* No lock needed since brcmf_sdioh_request_byte does locking */
466 int status;
467 status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data);
468 return status;
469 }
470
471 static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr)
472 {
473 /* read 24 bits and return valid 17 bit addr */
474 int i;
475 u32 scratch, regdata;
476 u8 *ptr = (u8 *)&scratch;
477 for (i = 0; i < 3; i++) {
478 if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, &regdata)) !=
479 SUCCESS)
480 sd_err(("%s: Can't read!\n", __func__));
481
482 *ptr++ = (u8) regdata;
483 regaddr++;
484 }
485
486 /* Only the lower 17-bits are valid */
487 scratch = le32_to_cpu(scratch);
488 scratch &= 0x0001FFFF;
489 return scratch;
490 }
491
492 extern int
493 brcmf_sdioh_cis_read(struct sdioh_info *sd, uint func, u8 *cisd, u32 length)
494 {
495 u32 count;
496 int offset;
497 u32 foo;
498 u8 *cis = cisd;
499
500 sd_trace(("%s: Func = %d\n", __func__, func));
501
502 if (!sd->func_cis_ptr[func]) {
503 memset(cis, 0, length);
504 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
505 return -ENOTSUPP;
506 }
507
508 sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func,
509 sd->func_cis_ptr[func]));
510
511 for (count = 0; count < length; count++) {
512 offset = sd->func_cis_ptr[func] + count;
513 if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) {
514 sd_err(("%s: regread failed: Can't read CIS\n",
515 __func__));
516 return -EIO;
517 }
518
519 *cis = (u8) (foo & 0xff);
520 cis++;
521 }
522
523 return 0;
524 }
525
526 extern int
527 brcmf_sdioh_request_byte(struct sdioh_info *sd, uint rw, uint func,
528 uint regaddr, u8 *byte)
529 {
530 int err_ret;
531
532 sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func,
533 regaddr));
534
535 BRCMF_PM_RESUME_WAIT(sdioh_request_byte_wait);
536 BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
537 if (rw) { /* CMD52 Write */
538 if (func == 0) {
539 /* Can only directly write to some F0 registers.
540 * Handle F2 enable
541 * as a special case.
542 */
543 if (regaddr == SDIO_CCCR_IOEx) {
544 if (gInstance->func[2]) {
545 sdio_claim_host(gInstance->func[2]);
546 if (*byte & SDIO_FUNC_ENABLE_2) {
547 /* Enable Function 2 */
548 err_ret =
549 sdio_enable_func
550 (gInstance->func[2]);
551 if (err_ret)
552 sd_err(("bcmsdh_sdmmc: enable F2 failed:%d",
553 err_ret));
554 } else {
555 /* Disable Function 2 */
556 err_ret =
557 sdio_disable_func
558 (gInstance->func[2]);
559 if (err_ret)
560 sd_err(("bcmsdh_sdmmc: Disab F2 failed:%d",
561 err_ret));
562 }
563 sdio_release_host(gInstance->func[2]);
564 }
565 }
566 /* to allow abort command through F1 */
567 else if (regaddr == SDIO_CCCR_ABORT) {
568 sdio_claim_host(gInstance->func[func]);
569 /*
570 * this sdio_f0_writeb() can be replaced
571 * with another api
572 * depending upon MMC driver change.
573 * As of this time, this is temporaray one
574 */
575 sdio_writeb(gInstance->func[func], *byte,
576 regaddr, &err_ret);
577 sdio_release_host(gInstance->func[func]);
578 }
579 else if (regaddr < 0xF0) {
580 sd_err(("bcmsdh_sdmmc: F0 Wr:0x%02x: write "
581 "disallowed\n", regaddr));
582 } else {
583 /* Claim host controller, perform F0 write,
584 and release */
585 sdio_claim_host(gInstance->func[func]);
586 sdio_f0_writeb(gInstance->func[func], *byte,
587 regaddr, &err_ret);
588 sdio_release_host(gInstance->func[func]);
589 }
590 } else {
591 /* Claim host controller, perform Fn write,
592 and release */
593 sdio_claim_host(gInstance->func[func]);
594 sdio_writeb(gInstance->func[func], *byte, regaddr,
595 &err_ret);
596 sdio_release_host(gInstance->func[func]);
597 }
598 } else { /* CMD52 Read */
599 /* Claim host controller, perform Fn read, and release */
600 sdio_claim_host(gInstance->func[func]);
601
602 if (func == 0) {
603 *byte =
604 sdio_f0_readb(gInstance->func[func], regaddr,
605 &err_ret);
606 } else {
607 *byte =
608 sdio_readb(gInstance->func[func], regaddr,
609 &err_ret);
610 }
611
612 sdio_release_host(gInstance->func[func]);
613 }
614
615 if (err_ret)
616 sd_err(("bcmsdh_sdmmc: Failed to %s byte F%d:@0x%05x=%02x, "
617 "Err: %d\n", rw ? "Write" : "Read", func, regaddr,
618 *byte, err_ret));
619
620 return err_ret;
621 }
622
623 extern int
624 brcmf_sdioh_request_word(struct sdioh_info *sd, uint cmd_type, uint rw,
625 uint func, uint addr, u32 *word, uint nbytes)
626 {
627 int err_ret = -EIO;
628
629 if (func == 0) {
630 sd_err(("%s: Only CMD52 allowed to F0.\n", __func__));
631 return -EINVAL;
632 }
633
634 sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n",
635 __func__, cmd_type, rw, func, addr, nbytes));
636
637 BRCMF_PM_RESUME_WAIT(sdioh_request_word_wait);
638 BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
639 /* Claim host controller */
640 sdio_claim_host(gInstance->func[func]);
641
642 if (rw) { /* CMD52 Write */
643 if (nbytes == 4) {
644 sdio_writel(gInstance->func[func], *word, addr,
645 &err_ret);
646 } else if (nbytes == 2) {
647 sdio_writew(gInstance->func[func], (*word & 0xFFFF),
648 addr, &err_ret);
649 } else {
650 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
651 }
652 } else { /* CMD52 Read */
653 if (nbytes == 4) {
654 *word =
655 sdio_readl(gInstance->func[func], addr, &err_ret);
656 } else if (nbytes == 2) {
657 *word =
658 sdio_readw(gInstance->func[func], addr,
659 &err_ret) & 0xFFFF;
660 } else {
661 sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes));
662 }
663 }
664
665 /* Release host controller */
666 sdio_release_host(gInstance->func[func]);
667
668 if (err_ret) {
669 sd_err(("bcmsdh_sdmmc: Failed to %s word, Err: 0x%08x",
670 rw ? "Write" : "Read", err_ret));
671 }
672
673 return err_ret;
674 }
675
676 static int
677 brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write,
678 uint func, uint addr, struct sk_buff *pkt)
679 {
680 bool fifo = (fix_inc == SDIOH_DATA_FIX);
681 u32 SGCount = 0;
682 int err_ret = 0;
683
684 struct sk_buff *pnext;
685
686 sd_trace(("%s: Enter\n", __func__));
687
688 ASSERT(pkt);
689 BRCMF_PM_RESUME_WAIT(sdioh_request_packet_wait);
690 BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
691
692 /* Claim host controller */
693 sdio_claim_host(gInstance->func[func]);
694 for (pnext = pkt; pnext; pnext = pnext->next) {
695 uint pkt_len = pnext->len;
696 pkt_len += 3;
697 pkt_len &= 0xFFFFFFFC;
698
699 /* Make sure the packet is aligned properly.
700 * If it isn't, then this
701 * is the fault of brcmf_sdioh_request_buffer() which
702 * is supposed to give
703 * us something we can work with.
704 */
705 ASSERT(((u32) (pkt->data) & DMA_ALIGN_MASK) == 0);
706
707 if ((write) && (!fifo)) {
708 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
709 ((u8 *) (pnext->data)),
710 pkt_len);
711 } else if (write) {
712 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
713 ((u8 *) (pnext->data)),
714 pkt_len);
715 } else if (fifo) {
716 err_ret = sdio_readsb(gInstance->func[func],
717 ((u8 *) (pnext->data)),
718 addr, pkt_len);
719 } else {
720 err_ret = sdio_memcpy_fromio(gInstance->func[func],
721 ((u8 *) (pnext->data)),
722 addr, pkt_len);
723 }
724
725 if (err_ret) {
726 sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d,"
727 "ERR=0x%08x\n", __func__,
728 (write) ? "TX" : "RX",
729 pnext, SGCount, addr, pkt_len, err_ret));
730 } else {
731 sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n",
732 __func__,
733 (write) ? "TX" : "RX",
734 pnext, SGCount, addr, pkt_len));
735 }
736
737 if (!fifo)
738 addr += pkt_len;
739 SGCount++;
740
741 }
742
743 /* Release host controller */
744 sdio_release_host(gInstance->func[func]);
745
746 sd_trace(("%s: Exit\n", __func__));
747 return err_ret;
748 }
749
750 /*
751 * This function takes a buffer or packet, and fixes everything up
752 * so that in the end, a DMA-able packet is created.
753 *
754 * A buffer does not have an associated packet pointer,
755 * and may or may not be aligned.
756 * A packet may consist of a single packet, or a packet chain.
757 * If it is a packet chain, then all the packets in the chain
758 * must be properly aligned.
759 *
760 * If the packet data is not aligned, then there may only be
761 * one packet, and in this case, it is copied to a new
762 * aligned packet.
763 *
764 */
765 extern int
766 brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc,
767 uint write, uint func, uint addr, uint reg_width,
768 uint buflen_u, u8 *buffer, struct sk_buff *pkt)
769 {
770 int Status;
771 struct sk_buff *mypkt = NULL;
772
773 sd_trace(("%s: Enter\n", __func__));
774
775 BRCMF_PM_RESUME_WAIT(sdioh_request_buffer_wait);
776 BRCMF_PM_RESUME_RETURN_ERROR(-EIO);
777 /* Case 1: we don't have a packet. */
778 if (pkt == NULL) {
779 sd_data(("%s: Creating new %s Packet, len=%d\n",
780 __func__, write ? "TX" : "RX", buflen_u));
781 mypkt = brcmu_pkt_buf_get_skb(buflen_u);
782 if (!mypkt) {
783 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
784 __func__, buflen_u));
785 return -EIO;
786 }
787
788 /* For a write, copy the buffer data into the packet. */
789 if (write)
790 memcpy(mypkt->data, buffer, buflen_u);
791
792 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
793 addr, mypkt);
794
795 /* For a read, copy the packet data back to the buffer. */
796 if (!write)
797 memcpy(buffer, mypkt->data, buflen_u);
798
799 brcmu_pkt_buf_free_skb(mypkt);
800 } else if (((u32) (pkt->data) & DMA_ALIGN_MASK) != 0) {
801 /* Case 2: We have a packet, but it is unaligned. */
802
803 /* In this case, we cannot have a chain. */
804 ASSERT(pkt->next == NULL);
805
806 sd_data(("%s: Creating aligned %s Packet, len=%d\n",
807 __func__, write ? "TX" : "RX", pkt->len));
808 mypkt = brcmu_pkt_buf_get_skb(pkt->len);
809 if (!mypkt) {
810 sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n",
811 __func__, pkt->len));
812 return -EIO;
813 }
814
815 /* For a write, copy the buffer data into the packet. */
816 if (write)
817 memcpy(mypkt->data, pkt->data, pkt->len);
818
819 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
820 addr, mypkt);
821
822 /* For a read, copy the packet data back to the buffer. */
823 if (!write)
824 memcpy(pkt->data, mypkt->data, mypkt->len);
825
826 brcmu_pkt_buf_free_skb(mypkt);
827 } else { /* case 3: We have a packet and
828 it is aligned. */
829 sd_data(("%s: Aligned %s Packet, direct DMA\n",
830 __func__, write ? "Tx" : "Rx"));
831 Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func,
832 addr, pkt);
833 }
834
835 return Status;
836 }
837
838 /* this function performs "abort" for both of host & device */
839 extern int brcmf_sdioh_abort(struct sdioh_info *sd, uint func)
840 {
841 char t_func = (char)func;
842 sd_trace(("%s: Enter\n", __func__));
843
844 /* issue abort cmd52 command through F0 */
845 brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT,
846 &t_func);
847
848 sd_trace(("%s: Exit\n", __func__));
849 return 0;
850 }
851
852 /* Reset and re-initialize the device */
853 int brcmf_sdioh_reset(struct sdioh_info *si)
854 {
855 sd_trace(("%s: Enter\n", __func__));
856 sd_trace(("%s: Exit\n", __func__));
857 return 0;
858 }
859
860 /* Disable device interrupt */
861 void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd)
862 {
863 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
864 sd->intmask &= ~CLIENT_INTR;
865 }
866
867 /* Enable device interrupt */
868 void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd)
869 {
870 sd_trace(("%s: %d\n", __func__, sd->use_client_ints));
871 sd->intmask |= CLIENT_INTR;
872 }
873
874 /* Read client card reg */
875 int
876 brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr,
877 int regsize, u32 *data)
878 {
879
880 if ((func == 0) || (regsize == 1)) {
881 u8 temp = 0;
882
883 brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp);
884 *data = temp;
885 *data &= 0xff;
886 sd_data(("%s: byte read data=0x%02x\n", __func__, *data));
887 } else {
888 brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data,
889 regsize);
890 if (regsize == 2)
891 *data &= 0xffff;
892
893 sd_data(("%s: word read data=0x%08x\n", __func__, *data));
894 }
895
896 return SUCCESS;
897 }
898
899 /* bcmsdh_sdmmc interrupt handler */
900 static void brcmf_sdioh_irqhandler(struct sdio_func *func)
901 {
902 struct sdioh_info *sd;
903
904 sd_trace(("bcmsdh_sdmmc: ***IRQHandler\n"));
905 sd = gInstance->sd;
906
907 ASSERT(sd != NULL);
908 sdio_release_host(gInstance->func[0]);
909
910 if (sd->use_client_ints) {
911 sd->intrcount++;
912 ASSERT(sd->intr_handler);
913 ASSERT(sd->intr_handler_arg);
914 (sd->intr_handler) (sd->intr_handler_arg);
915 } else {
916 sd_err(("bcmsdh_sdmmc: ***IRQHandler\n"));
917
918 sd_err(("%s: Not ready for intr: enabled %d, handler %p\n",
919 __func__, sd->client_intr_enabled, sd->intr_handler));
920 }
921
922 sdio_claim_host(gInstance->func[0]);
923 }
924
925 /* bcmsdh_sdmmc interrupt handler for F2 (dummy handler) */
926 static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func)
927 {
928 struct sdioh_info *sd;
929
930 sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n"));
931
932 sd = gInstance->sd;
933
934 ASSERT(sd != NULL);
935 }
936
937 int brcmf_sdioh_start(struct sdioh_info *si, int stage)
938 {
939 return 0;
940 }
941
942 int brcmf_sdioh_stop(struct sdioh_info *si)
943 {
944 return 0;
945 }
This page took 0.049811 seconds and 6 git commands to generate.