staging: brcm80211: assure common sources are truly common
[pandora-kernel.git] / drivers / staging / brcm80211 / util / aiutils.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
17 #include <linux/delay.h>
18 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <bcmdefs.h>
21 #include <osl.h>
22 #include <linux/module.h>
23 #include <linux/pci.h>
24 #include <bcmutils.h>
25 #include <siutils.h>
26 #include <hndsoc.h>
27 #include <sbchipc.h>
28 #include <pcicfg.h>
29 #include <bcmdevs.h>
30
31 #define BCM47162_DMP() ((sih->chip == BCM47162_CHIP_ID) && \
32                 (sih->chiprev == 0) && \
33                 (sii->coreid[sii->curidx] == MIPS74K_CORE_ID))
34
35 /* EROM parsing */
36
37 static u32
38 get_erom_ent(si_t *sih, u32 **eromptr, u32 mask, u32 match)
39 {
40         u32 ent;
41         uint inv = 0, nom = 0;
42
43         while (true) {
44                 ent = R_REG(si_osh(sih), *eromptr);
45                 (*eromptr)++;
46
47                 if (mask == 0)
48                         break;
49
50                 if ((ent & ER_VALID) == 0) {
51                         inv++;
52                         continue;
53                 }
54
55                 if (ent == (ER_END | ER_VALID))
56                         break;
57
58                 if ((ent & mask) == match)
59                         break;
60
61                 nom++;
62         }
63
64         SI_VMSG(("%s: Returning ent 0x%08x\n", __func__, ent));
65         if (inv + nom) {
66                 SI_VMSG(("  after %d invalid and %d non-matching entries\n",
67                          inv, nom));
68         }
69         return ent;
70 }
71
72 static u32
73 get_asd(si_t *sih, u32 **eromptr, uint sp, uint ad, uint st,
74         u32 *addrl, u32 *addrh, u32 *sizel, u32 *sizeh)
75 {
76         u32 asd, sz, szd;
77
78         asd = get_erom_ent(sih, eromptr, ER_VALID, ER_VALID);
79         if (((asd & ER_TAG1) != ER_ADD) ||
80             (((asd & AD_SP_MASK) >> AD_SP_SHIFT) != sp) ||
81             ((asd & AD_ST_MASK) != st)) {
82                 /* This is not what we want, "push" it back */
83                 (*eromptr)--;
84                 return 0;
85         }
86         *addrl = asd & AD_ADDR_MASK;
87         if (asd & AD_AG32)
88                 *addrh = get_erom_ent(sih, eromptr, 0, 0);
89         else
90                 *addrh = 0;
91         *sizeh = 0;
92         sz = asd & AD_SZ_MASK;
93         if (sz == AD_SZ_SZD) {
94                 szd = get_erom_ent(sih, eromptr, 0, 0);
95                 *sizel = szd & SD_SZ_MASK;
96                 if (szd & SD_SG32)
97                         *sizeh = get_erom_ent(sih, eromptr, 0, 0);
98         } else
99                 *sizel = AD_SZ_BASE << (sz >> AD_SZ_SHIFT);
100
101         SI_VMSG(("  SP %d, ad %d: st = %d, 0x%08x_0x%08x @ 0x%08x_0x%08x\n",
102                  sp, ad, st, *sizeh, *sizel, *addrh, *addrl));
103
104         return asd;
105 }
106
107 static void ai_hwfixup(si_info_t *sii)
108 {
109 }
110
111 /* parse the enumeration rom to identify all cores */
112 void ai_scan(si_t *sih, void *regs, uint devid)
113 {
114         si_info_t *sii = SI_INFO(sih);
115         chipcregs_t *cc = (chipcregs_t *) regs;
116         u32 erombase, *eromptr, *eromlim;
117
118         erombase = R_REG(sii->osh, &cc->eromptr);
119
120         switch (sih->bustype) {
121         case SI_BUS:
122                 eromptr = (u32 *) REG_MAP(erombase, SI_CORE_SIZE);
123                 break;
124
125         case PCI_BUS:
126                 /* Set wrappers address */
127                 sii->curwrap = (void *)((unsigned long)regs + SI_CORE_SIZE);
128
129                 /* Now point the window at the erom */
130                 pci_write_config_dword(sii->osh->pdev, PCI_BAR0_WIN, erombase);
131                 eromptr = regs;
132                 break;
133
134         case SPI_BUS:
135         case SDIO_BUS:
136                 eromptr = (u32 *)(unsigned long)erombase;
137                 break;
138
139         default:
140                 SI_ERROR(("Don't know how to do AXI enumertion on bus %d\n",
141                           sih->bustype));
142                 ASSERT(0);
143                 return;
144         }
145         eromlim = eromptr + (ER_REMAPCONTROL / sizeof(u32));
146
147         SI_VMSG(("ai_scan: regs = 0x%p, erombase = 0x%08x, eromptr = 0x%p, eromlim = 0x%p\n", regs, erombase, eromptr, eromlim));
148         while (eromptr < eromlim) {
149                 u32 cia, cib, cid, mfg, crev, nmw, nsw, nmp, nsp;
150                 u32 mpd, asd, addrl, addrh, sizel, sizeh;
151                 u32 *base;
152                 uint i, j, idx;
153                 bool br;
154
155                 br = false;
156
157                 /* Grok a component */
158                 cia = get_erom_ent(sih, &eromptr, ER_TAG, ER_CI);
159                 if (cia == (ER_END | ER_VALID)) {
160                         SI_VMSG(("Found END of erom after %d cores\n",
161                                  sii->numcores));
162                         ai_hwfixup(sii);
163                         return;
164                 }
165                 base = eromptr - 1;
166                 cib = get_erom_ent(sih, &eromptr, 0, 0);
167
168                 if ((cib & ER_TAG) != ER_CI) {
169                         SI_ERROR(("CIA not followed by CIB\n"));
170                         goto error;
171                 }
172
173                 cid = (cia & CIA_CID_MASK) >> CIA_CID_SHIFT;
174                 mfg = (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
175                 crev = (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
176                 nmw = (cib & CIB_NMW_MASK) >> CIB_NMW_SHIFT;
177                 nsw = (cib & CIB_NSW_MASK) >> CIB_NSW_SHIFT;
178                 nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT;
179                 nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT;
180
181                 SI_VMSG(("Found component 0x%04x/0x%04x rev %d at erom addr 0x%p, with nmw = %d, " "nsw = %d, nmp = %d & nsp = %d\n", mfg, cid, crev, base, nmw, nsw, nmp, nsp));
182
183                 if (((mfg == MFGID_ARM) && (cid == DEF_AI_COMP)) || (nsp == 0))
184                         continue;
185                 if ((nmw + nsw == 0)) {
186                         /* A component which is not a core */
187                         if (cid == OOB_ROUTER_CORE_ID) {
188                                 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE,
189                                               &addrl, &addrh, &sizel, &sizeh);
190                                 if (asd != 0) {
191                                         sii->oob_router = addrl;
192                                 }
193                         }
194                         continue;
195                 }
196
197                 idx = sii->numcores;
198 /*              sii->eromptr[idx] = base; */
199                 sii->cia[idx] = cia;
200                 sii->cib[idx] = cib;
201                 sii->coreid[idx] = cid;
202
203                 for (i = 0; i < nmp; i++) {
204                         mpd = get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID);
205                         if ((mpd & ER_TAG) != ER_MP) {
206                                 SI_ERROR(("Not enough MP entries for component 0x%x\n", cid));
207                                 goto error;
208                         }
209                         SI_VMSG(("  Master port %d, mp: %d id: %d\n", i,
210                                  (mpd & MPD_MP_MASK) >> MPD_MP_SHIFT,
211                                  (mpd & MPD_MUI_MASK) >> MPD_MUI_SHIFT));
212                 }
213
214                 /* First Slave Address Descriptor should be port 0:
215                  * the main register space for the core
216                  */
217                 asd =
218                     get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh,
219                             &sizel, &sizeh);
220                 if (asd == 0) {
221                         /* Try again to see if it is a bridge */
222                         asd =
223                             get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl,
224                                     &addrh, &sizel, &sizeh);
225                         if (asd != 0)
226                                 br = true;
227                         else if ((addrh != 0) || (sizeh != 0)
228                                  || (sizel != SI_CORE_SIZE)) {
229                                 SI_ERROR(("First Slave ASD for core 0x%04x malformed " "(0x%08x)\n", cid, asd));
230                                 goto error;
231                         }
232                 }
233                 sii->coresba[idx] = addrl;
234                 sii->coresba_size[idx] = sizel;
235                 /* Get any more ASDs in port 0 */
236                 j = 1;
237                 do {
238                         asd =
239                             get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl,
240                                     &addrh, &sizel, &sizeh);
241                         if ((asd != 0) && (j == 1) && (sizel == SI_CORE_SIZE)) {
242                                 sii->coresba2[idx] = addrl;
243                                 sii->coresba2_size[idx] = sizel;
244                         }
245                         j++;
246                 } while (asd != 0);
247
248                 /* Go through the ASDs for other slave ports */
249                 for (i = 1; i < nsp; i++) {
250                         j = 0;
251                         do {
252                                 asd =
253                                     get_asd(sih, &eromptr, i, j++, AD_ST_SLAVE,
254                                             &addrl, &addrh, &sizel, &sizeh);
255                         } while (asd != 0);
256                         if (j == 0) {
257                                 SI_ERROR((" SP %d has no address descriptors\n",
258                                           i));
259                                 goto error;
260                         }
261                 }
262
263                 /* Now get master wrappers */
264                 for (i = 0; i < nmw; i++) {
265                         asd =
266                             get_asd(sih, &eromptr, i, 0, AD_ST_MWRAP, &addrl,
267                                     &addrh, &sizel, &sizeh);
268                         if (asd == 0) {
269                                 SI_ERROR(("Missing descriptor for MW %d\n", i));
270                                 goto error;
271                         }
272                         if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
273                                 SI_ERROR(("Master wrapper %d is not 4KB\n", i));
274                                 goto error;
275                         }
276                         if (i == 0)
277                                 sii->wrapba[idx] = addrl;
278                 }
279
280                 /* And finally slave wrappers */
281                 for (i = 0; i < nsw; i++) {
282                         uint fwp = (nsp == 1) ? 0 : 1;
283                         asd =
284                             get_asd(sih, &eromptr, fwp + i, 0, AD_ST_SWRAP,
285                                     &addrl, &addrh, &sizel, &sizeh);
286                         if (asd == 0) {
287                                 SI_ERROR(("Missing descriptor for SW %d\n", i));
288                                 goto error;
289                         }
290                         if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
291                                 SI_ERROR(("Slave wrapper %d is not 4KB\n", i));
292                                 goto error;
293                         }
294                         if ((nmw == 0) && (i == 0))
295                                 sii->wrapba[idx] = addrl;
296                 }
297
298                 /* Don't record bridges */
299                 if (br)
300                         continue;
301
302                 /* Done with core */
303                 sii->numcores++;
304         }
305
306         SI_ERROR(("Reached end of erom without finding END"));
307
308  error:
309         sii->numcores = 0;
310         return;
311 }
312
313 /* This function changes the logical "focus" to the indicated core.
314  * Return the current core's virtual address.
315  */
316 void *ai_setcoreidx(si_t *sih, uint coreidx)
317 {
318         si_info_t *sii = SI_INFO(sih);
319         u32 addr = sii->coresba[coreidx];
320         u32 wrap = sii->wrapba[coreidx];
321         void *regs;
322
323         if (coreidx >= sii->numcores)
324                 return NULL;
325
326         /*
327          * If the user has provided an interrupt mask enabled function,
328          * then assert interrupts are disabled before switching the core.
329          */
330         ASSERT((sii->intrsenabled_fn == NULL)
331                || !(*(sii)->intrsenabled_fn) ((sii)->intr_arg));
332
333         switch (sih->bustype) {
334         case SI_BUS:
335                 /* map new one */
336                 if (!sii->regs[coreidx]) {
337                         sii->regs[coreidx] = REG_MAP(addr, SI_CORE_SIZE);
338                         ASSERT(GOODREGS(sii->regs[coreidx]));
339                 }
340                 sii->curmap = regs = sii->regs[coreidx];
341                 if (!sii->wrappers[coreidx]) {
342                         sii->wrappers[coreidx] = REG_MAP(wrap, SI_CORE_SIZE);
343                         ASSERT(GOODREGS(sii->wrappers[coreidx]));
344                 }
345                 sii->curwrap = sii->wrappers[coreidx];
346                 break;
347
348         case PCI_BUS:
349                 /* point bar0 window */
350                 pci_write_config_dword(sii->osh->pdev, PCI_BAR0_WIN, addr);
351                 regs = sii->curmap;
352                 /* point bar0 2nd 4KB window */
353                 pci_write_config_dword(sii->osh->pdev, PCI_BAR0_WIN2, wrap);
354                 break;
355
356         case SPI_BUS:
357         case SDIO_BUS:
358                 sii->curmap = regs = (void *)(unsigned long)addr;
359                 sii->curwrap = (void *)(unsigned long)wrap;
360                 break;
361
362         default:
363                 ASSERT(0);
364                 regs = NULL;
365                 break;
366         }
367
368         sii->curmap = regs;
369         sii->curidx = coreidx;
370
371         return regs;
372 }
373
374 /* Return the number of address spaces in current core */
375 int ai_numaddrspaces(si_t *sih)
376 {
377         return 2;
378 }
379
380 /* Return the address of the nth address space in the current core */
381 u32 ai_addrspace(si_t *sih, uint asidx)
382 {
383         si_info_t *sii;
384         uint cidx;
385
386         sii = SI_INFO(sih);
387         cidx = sii->curidx;
388
389         if (asidx == 0)
390                 return sii->coresba[cidx];
391         else if (asidx == 1)
392                 return sii->coresba2[cidx];
393         else {
394                 SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n", __func__, asidx));
395                 return 0;
396         }
397 }
398
399 /* Return the size of the nth address space in the current core */
400 u32 ai_addrspacesize(si_t *sih, uint asidx)
401 {
402         si_info_t *sii;
403         uint cidx;
404
405         sii = SI_INFO(sih);
406         cidx = sii->curidx;
407
408         if (asidx == 0)
409                 return sii->coresba_size[cidx];
410         else if (asidx == 1)
411                 return sii->coresba2_size[cidx];
412         else {
413                 SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n", __func__, asidx));
414                 return 0;
415         }
416 }
417
418 uint ai_flag(si_t *sih)
419 {
420         si_info_t *sii;
421         aidmp_t *ai;
422
423         sii = SI_INFO(sih);
424         if (BCM47162_DMP()) {
425                 SI_ERROR(("%s: Attempting to read MIPS DMP registers on 47162a0", __func__));
426                 return sii->curidx;
427         }
428         ai = sii->curwrap;
429
430         return R_REG(sii->osh, &ai->oobselouta30) & 0x1f;
431 }
432
433 void ai_setint(si_t *sih, int siflag)
434 {
435 }
436
437 void ai_write_wrap_reg(si_t *sih, u32 offset, u32 val)
438 {
439         si_info_t *sii = SI_INFO(sih);
440         u32 *w = (u32 *) sii->curwrap;
441         W_REG(sii->osh, w + (offset / 4), val);
442         return;
443 }
444
445 uint ai_corevendor(si_t *sih)
446 {
447         si_info_t *sii;
448         u32 cia;
449
450         sii = SI_INFO(sih);
451         cia = sii->cia[sii->curidx];
452         return (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
453 }
454
455 uint ai_corerev(si_t *sih)
456 {
457         si_info_t *sii;
458         u32 cib;
459
460         sii = SI_INFO(sih);
461         cib = sii->cib[sii->curidx];
462         return (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
463 }
464
465 bool ai_iscoreup(si_t *sih)
466 {
467         si_info_t *sii;
468         aidmp_t *ai;
469
470         sii = SI_INFO(sih);
471         ai = sii->curwrap;
472
473         return (((R_REG(sii->osh, &ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) ==
474                  SICF_CLOCK_EN)
475                 && ((R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET) == 0));
476 }
477
478 /*
479  * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set operation,
480  * switch back to the original core, and return the new value.
481  *
482  * When using the silicon backplane, no fiddling with interrupts or core switches is needed.
483  *
484  * Also, when using pci/pcie, we can optimize away the core switching for pci registers
485  * and (on newer pci cores) chipcommon registers.
486  */
487 uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
488 {
489         uint origidx = 0;
490         u32 *r = NULL;
491         uint w;
492         uint intr_val = 0;
493         bool fast = false;
494         si_info_t *sii;
495
496         sii = SI_INFO(sih);
497
498         ASSERT(GOODIDX(coreidx));
499         ASSERT(regoff < SI_CORE_SIZE);
500         ASSERT((val & ~mask) == 0);
501
502         if (coreidx >= SI_MAXCORES)
503                 return 0;
504
505         if (sih->bustype == SI_BUS) {
506                 /* If internal bus, we can always get at everything */
507                 fast = true;
508                 /* map if does not exist */
509                 if (!sii->regs[coreidx]) {
510                         sii->regs[coreidx] = REG_MAP(sii->coresba[coreidx],
511                                                      SI_CORE_SIZE);
512                         ASSERT(GOODREGS(sii->regs[coreidx]));
513                 }
514                 r = (u32 *) ((unsigned char *) sii->regs[coreidx] + regoff);
515         } else if (sih->bustype == PCI_BUS) {
516                 /* If pci/pcie, we can get at pci/pcie regs and on newer cores to chipc */
517
518                 if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) {
519                         /* Chipc registers are mapped at 12KB */
520
521                         fast = true;
522                         r = (u32 *) ((char *)sii->curmap +
523                                         PCI_16KB0_CCREGS_OFFSET + regoff);
524                 } else if (sii->pub.buscoreidx == coreidx) {
525                         /* pci registers are at either in the last 2KB of an 8KB window
526                          * or, in pcie and pci rev 13 at 8KB
527                          */
528                         fast = true;
529                         if (SI_FAST(sii))
530                                 r = (u32 *) ((char *)sii->curmap +
531                                                 PCI_16KB0_PCIREGS_OFFSET +
532                                                 regoff);
533                         else
534                                 r = (u32 *) ((char *)sii->curmap +
535                                                 ((regoff >= SBCONFIGOFF) ?
536                                                  PCI_BAR0_PCISBR_OFFSET :
537                                                  PCI_BAR0_PCIREGS_OFFSET) +
538                                                 regoff);
539                 }
540         }
541
542         if (!fast) {
543                 INTR_OFF(sii, intr_val);
544
545                 /* save current core index */
546                 origidx = si_coreidx(&sii->pub);
547
548                 /* switch core */
549                 r = (u32 *) ((unsigned char *) ai_setcoreidx(&sii->pub, coreidx) +
550                                 regoff);
551         }
552         ASSERT(r != NULL);
553
554         /* mask and set */
555         if (mask || val) {
556                 w = (R_REG(sii->osh, r) & ~mask) | val;
557                 W_REG(sii->osh, r, w);
558         }
559
560         /* readback */
561         w = R_REG(sii->osh, r);
562
563         if (!fast) {
564                 /* restore core index */
565                 if (origidx != coreidx)
566                         ai_setcoreidx(&sii->pub, origidx);
567
568                 INTR_RESTORE(sii, intr_val);
569         }
570
571         return w;
572 }
573
574 void ai_core_disable(si_t *sih, u32 bits)
575 {
576         si_info_t *sii;
577         volatile u32 dummy;
578         aidmp_t *ai;
579
580         sii = SI_INFO(sih);
581
582         ASSERT(GOODREGS(sii->curwrap));
583         ai = sii->curwrap;
584
585         /* if core is already in reset, just return */
586         if (R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET)
587                 return;
588
589         W_REG(sii->osh, &ai->ioctrl, bits);
590         dummy = R_REG(sii->osh, &ai->ioctrl);
591         udelay(10);
592
593         W_REG(sii->osh, &ai->resetctrl, AIRC_RESET);
594         udelay(1);
595 }
596
597 /* reset and re-enable a core
598  * inputs:
599  * bits - core specific bits that are set during and after reset sequence
600  * resetbits - core specific bits that are set only during reset sequence
601  */
602 void ai_core_reset(si_t *sih, u32 bits, u32 resetbits)
603 {
604         si_info_t *sii;
605         aidmp_t *ai;
606         volatile u32 dummy;
607
608         sii = SI_INFO(sih);
609         ASSERT(GOODREGS(sii->curwrap));
610         ai = sii->curwrap;
611
612         /*
613          * Must do the disable sequence first to work for arbitrary current core state.
614          */
615         ai_core_disable(sih, (bits | resetbits));
616
617         /*
618          * Now do the initialization sequence.
619          */
620         W_REG(sii->osh, &ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
621         dummy = R_REG(sii->osh, &ai->ioctrl);
622         W_REG(sii->osh, &ai->resetctrl, 0);
623         udelay(1);
624
625         W_REG(sii->osh, &ai->ioctrl, (bits | SICF_CLOCK_EN));
626         dummy = R_REG(sii->osh, &ai->ioctrl);
627         udelay(1);
628 }
629
630 void ai_core_cflags_wo(si_t *sih, u32 mask, u32 val)
631 {
632         si_info_t *sii;
633         aidmp_t *ai;
634         u32 w;
635
636         sii = SI_INFO(sih);
637
638         if (BCM47162_DMP()) {
639                 SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0",
640                           __func__));
641                 return;
642         }
643
644         ASSERT(GOODREGS(sii->curwrap));
645         ai = sii->curwrap;
646
647         ASSERT((val & ~mask) == 0);
648
649         if (mask || val) {
650                 w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val);
651                 W_REG(sii->osh, &ai->ioctrl, w);
652         }
653 }
654
655 u32 ai_core_cflags(si_t *sih, u32 mask, u32 val)
656 {
657         si_info_t *sii;
658         aidmp_t *ai;
659         u32 w;
660
661         sii = SI_INFO(sih);
662         if (BCM47162_DMP()) {
663                 SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0",
664                           __func__));
665                 return 0;
666         }
667
668         ASSERT(GOODREGS(sii->curwrap));
669         ai = sii->curwrap;
670
671         ASSERT((val & ~mask) == 0);
672
673         if (mask || val) {
674                 w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val);
675                 W_REG(sii->osh, &ai->ioctrl, w);
676         }
677
678         return R_REG(sii->osh, &ai->ioctrl);
679 }
680
681 u32 ai_core_sflags(si_t *sih, u32 mask, u32 val)
682 {
683         si_info_t *sii;
684         aidmp_t *ai;
685         u32 w;
686
687         sii = SI_INFO(sih);
688         if (BCM47162_DMP()) {
689                 SI_ERROR(("%s: Accessing MIPS DMP register (iostatus) on 47162a0", __func__));
690                 return 0;
691         }
692
693         ASSERT(GOODREGS(sii->curwrap));
694         ai = sii->curwrap;
695
696         ASSERT((val & ~mask) == 0);
697         ASSERT((mask & ~SISF_CORE_BITS) == 0);
698
699         if (mask || val) {
700                 w = ((R_REG(sii->osh, &ai->iostatus) & ~mask) | val);
701                 W_REG(sii->osh, &ai->iostatus, w);
702         }
703
704         return R_REG(sii->osh, &ai->iostatus);
705 }
706