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