Ignore:
Timestamp:
Jul 7, 2006, 12:14:16 AM (19 years ago)
Author:
Waldemar Brodkorb <wbx@…>
Branches:
freewrt_1_0, freewrt_2_0
Children:
dfb8263
Parents:
b232ea4
Message:

use OpenWrt whiterussian system code and wireless driver

  • make it build with 2.4.32
  • add netgear wgt634u patches (untested)
  • keep newest flash map stuff
  • add wlcompat and wl.o from whiterussian
  • add diag_led.c from whiterussian

git-svn-id: svn://www.freewrt.org/trunk/freewrt@177 afb5a338-a214-0410-bd46-81f09a774fd1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • target/linux/brcm-2.4/patches/001-bcm47xx.patch

    rb232ea4 r2268d20  
    1 diff -urN linux.old/arch/mips/Makefile linux.dev/arch/mips/Makefile
    2 --- linux.old/arch/mips/Makefile        2006-04-27 18:04:37.000000000 +0200
    3 +++ linux.dev/arch/mips/Makefile        2006-04-27 19:24:19.000000000 +0200
    4 @@ -726,6 +726,19 @@
     1diff -Nur linux-2.4.32/arch/mips/Makefile linux-2.4.32-freewrt/arch/mips/Makefile
     2--- linux-2.4.32/arch/mips/Makefile     2005-01-19 15:09:26.000000000 +0100
     3+++ linux-2.4.32-freewrt/arch/mips/Makefile     2006-07-06 00:32:54.000000000 +0200
     4@@ -715,6 +715,19 @@
    55 endif
    66 
     
    99+#
    1010+ifdef CONFIG_BCM947XX
    11 +LIBS           += arch/mips/bcm947xx/generic/brcm.o arch/mips/bcm947xx/bcm947xx.o
    12 +SUBDIRS                += arch/mips/bcm947xx/generic arch/mips/bcm947xx
    13 +LOADADDR       := 0x80001000
     11+LIBS           += arch/mips/bcm947xx/generic/brcm.o arch/mips/bcm947xx/bcm947xx.o
     12+SUBDIRS                += arch/mips/bcm947xx/generic arch/mips/bcm947xx
     13+LOADADDR       := 0x80001000
    1414+
    1515+zImage: vmlinux
     
    2222 # error messages during linking.  Select a default linkscript if
    2323 # none has been choosen above.
    24 @@ -778,6 +791,7 @@
     24@@ -767,6 +780,7 @@
    2525        $(MAKE) -C arch/$(ARCH)/tools clean
    2626        $(MAKE) -C arch/mips/baget clean
     
    3030 archmrproper:
    3131        @$(MAKEBOOT) mrproper
    32 diff -urN linux.old/arch/mips/bcm947xx/Makefile linux.dev/arch/mips/bcm947xx/Makefile
    33 --- linux.old/arch/mips/bcm947xx/Makefile       1970-01-01 01:00:00.000000000 +0100
    34 +++ linux.dev/arch/mips/bcm947xx/Makefile       2006-05-02 17:46:22.000000000 +0200
    35 @@ -0,0 +1,17 @@
     32diff -Nur linux-2.4.32/arch/mips/bcm947xx/Makefile linux-2.4.32-freewrt/arch/mips/bcm947xx/Makefile
     33--- linux-2.4.32/arch/mips/bcm947xx/Makefile    1970-01-01 01:00:00.000000000 +0100
     34+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/Makefile    2006-07-02 21:58:25.000000000 +0200
     35@@ -0,0 +1,15 @@
    3636+#
    3737+# Makefile for the BCM947xx specific kernel interface routines
     
    4343+O_TARGET        := bcm947xx.o
    4444+
    45 +export-objs     := export.o
     45+export-objs     := nvram_linux.o setup.o
    4646+obj-y          := prom.o setup.o time.o sbmips.o gpio.o
    47 +obj-y          += nvram.o nvram_linux.o sflash.o cfe_env.o
    48 +obj-y          += sbutils.o bcmutils.o bcmsrom.o hndchipc.o
     47+obj-y          += nvram.o nvram_linux.o
    4948+obj-$(CONFIG_PCI) += sbpci.o pcibios.o
    50 +obj-y          += export.o
    5149+
    5250+include $(TOPDIR)/Rules.make
    53 diff -urN linux.old/arch/mips/bcm947xx/bcmsrom.c linux.dev/arch/mips/bcm947xx/bcmsrom.c
    54 --- linux.old/arch/mips/bcm947xx/bcmsrom.c      1970-01-01 01:00:00.000000000 +0100
    55 +++ linux.dev/arch/mips/bcm947xx/bcmsrom.c      2006-04-27 20:32:48.000000000 +0200
    56 @@ -0,0 +1,1212 @@
    57 +/*
    58 + *  Misc useful routines to access NIC SROM/OTP .
    59 + *
    60 + * Copyright 2006, Broadcom Corporation
    61 + * All Rights Reserved.
    62 + *
    63 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    64 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    65 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    66 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    67 + * $Id: bcmsrom.c,v 1.1.1.14 2006/04/15 01:28:25 michael Exp $
    68 + */
    69 +
    70 +#include <typedefs.h>
    71 +#include <bcmdefs.h>
    72 +#include <osl.h>
    73 +#include <bcmutils.h>
    74 +#include <bcmsrom.h>
    75 +#include <bcmdevs.h>
    76 +#include <bcmendian.h>
    77 +#include <sbpcmcia.h>
    78 +#include <pcicfg.h>
    79 +#include <sbutils.h>
    80 +#include <bcmnvram.h>
    81 +
    82 +/* debug/trace */
    83 +#if defined(WLTEST)
    84 +#define        BS_ERROR(args)  printf args
    85 +#else
    86 +#define        BS_ERROR(args)
    87 +#endif /* BCMDBG_ERR || WLTEST */
    88 +
    89 +#define        VARS_MAX        4096    /* should be reduced */
    90 +
    91 +#define WRITE_ENABLE_DELAY     500     /* 500 ms after write enable/disable toggle */
    92 +#define WRITE_WORD_DELAY       20      /* 20 ms between each word write */
    93 +
    94 +static int initvars_srom_pci(void *sbh, void *curmap, char **vars, uint *count);
    95 +static int initvars_cis_pcmcia(void *sbh, osl_t *osh, char **vars, uint *count);
    96 +static int initvars_flash_sb(void *sbh, char **vars, uint *count);
    97 +static int srom_parsecis(osl_t *osh, uint8 **pcis, uint ciscnt, char **vars, uint *count);
    98 +static int sprom_cmd_pcmcia(osl_t *osh, uint8 cmd);
    99 +static int sprom_read_pcmcia(osl_t *osh, uint16 addr, uint16 *data);
    100 +static int sprom_write_pcmcia(osl_t *osh, uint16 addr, uint16 data);
    101 +static int sprom_read_pci(osl_t *osh, uint16 *sprom, uint wordoff, uint16 *buf, uint nwords,
    102 +                          bool check_crc);
    103 +
    104 +static int initvars_table(osl_t *osh, char *start, char *end, char **vars, uint *count);
    105 +static int initvars_flash(osl_t *osh, char **vp, uint len, char *devpath);
    106 +
    107 +/*
    108 + * Initialize local vars from the right source for this platform.
    109 + * Return 0 on success, nonzero on error.
    110 + */
    111 +int
    112 +srom_var_init(void *sbh, uint bustype, void *curmap, osl_t *osh, char **vars, uint *count)
    113 +{
    114 +       ASSERT(bustype == BUSTYPE(bustype));
    115 +       if (vars == NULL || count == NULL)
    116 +               return (0);
    117 +
    118 +       switch (BUSTYPE(bustype)) {
    119 +       case SB_BUS:
    120 +       case JTAG_BUS:
    121 +               return initvars_flash_sb(sbh, vars, count);
    122 +
    123 +       case PCI_BUS:
    124 +               ASSERT(curmap); /* can not be NULL */
    125 +               return initvars_srom_pci(sbh, curmap, vars, count);
    126 +
    127 +       case PCMCIA_BUS:
    128 +               return initvars_cis_pcmcia(sbh, osh, vars, count);
    129 +
    130 +
    131 +       default:
    132 +               ASSERT(0);
    133 +       }
    134 +       return (-1);
    135 +}
    136 +
    137 +/* support only 16-bit word read from srom */
    138 +int
    139 +srom_read(uint bustype, void *curmap, osl_t *osh, uint byteoff, uint nbytes, uint16 *buf)
    140 +{
    141 +       void *srom;
    142 +       uint i, off, nw;
    143 +
    144 +       ASSERT(bustype == BUSTYPE(bustype));
    145 +
    146 +       /* check input - 16-bit access only */
    147 +       if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > (SPROM_SIZE * 2))
    148 +               return 1;
    149 +
    150 +       off = byteoff / 2;
    151 +       nw = nbytes / 2;
    152 +
    153 +       if (BUSTYPE(bustype) == PCI_BUS) {
    154 +               if (!curmap)
    155 +                       return 1;
    156 +               srom = (uchar*)curmap + PCI_BAR0_SPROM_OFFSET;
    157 +               if (sprom_read_pci(osh, srom, off, buf, nw, FALSE))
    158 +                       return 1;
    159 +       } else if (BUSTYPE(bustype) == PCMCIA_BUS) {
    160 +               for (i = 0; i < nw; i++) {
    161 +                       if (sprom_read_pcmcia(osh, (uint16)(off + i), (uint16*)(buf + i)))
    162 +                               return 1;
    163 +               }
    164 +       } else {
    165 +               return 1;
    166 +       }
    167 +
    168 +       return 0;
    169 +}
    170 +
    171 +/* support only 16-bit word write into srom */
    172 +int
    173 +srom_write(uint bustype, void *curmap, osl_t *osh, uint byteoff, uint nbytes, uint16 *buf)
    174 +{
    175 +       uint16 *srom;
    176 +       uint i, nw, crc_range;
    177 +       uint16 image[SPROM_SIZE];
    178 +       uint8 crc;
    179 +       volatile uint32 val32;
    180 +
    181 +       ASSERT(bustype == BUSTYPE(bustype));
    182 +
    183 +       /* check input - 16-bit access only */
    184 +       if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > (SPROM_SIZE * 2))
    185 +               return 1;
    186 +
    187 +       /* Are we writing the whole thing at once? */
    188 +       if ((byteoff == 0) &&
    189 +           ((nbytes == SPROM_SIZE) ||
    190 +            (nbytes == (SPROM_CRC_RANGE * 2)) ||
    191 +            (nbytes == (SROM4_WORDS * 2)))) {
    192 +               crc_range = nbytes;
    193 +               bcopy((void*)buf, (void*)image, nbytes);
    194 +               nw = nbytes / 2;
    195 +       } else {
    196 +               if ((BUSTYPE(bustype) == PCMCIA_BUS) || (BUSTYPE(bustype) == SDIO_BUS))
    197 +                       crc_range = SPROM_SIZE;
    198 +               else
    199 +                       crc_range = SPROM_CRC_RANGE * 2;        /* Tentative */
    200 +
    201 +               nw = crc_range / 2;
    202 +               /* read first 64 words from srom */
    203 +               if (srom_read(bustype, curmap, osh, 0, nw * 2, image))
    204 +                       return 1;
    205 +               if (image[SROM4_SIGN] == SROM4_SIGNATURE) {
    206 +                       crc_range = SROM4_WORDS;
    207 +                       nw = crc_range / 2;
    208 +                       if (srom_read(bustype, curmap, osh, 0, nw * 2, image))
    209 +                               return 1;
    210 +               }
    211 +               /* make changes */
    212 +               bcopy((void*)buf, (void*)&image[byteoff / 2], nbytes);
    213 +       }
    214 +
    215 +       /* calculate crc */
    216 +       htol16_buf(image, crc_range);
    217 +       crc = ~hndcrc8((uint8 *)image, crc_range - 1, CRC8_INIT_VALUE);
    218 +       ltoh16_buf(image, crc_range);
    219 +       image[(crc_range / 2) - 1] = (crc << 8) | (image[(crc_range / 2) - 1] & 0xff);
    220 +
    221 +       if (BUSTYPE(bustype) == PCI_BUS) {
    222 +               srom = (uint16*)((uchar*)curmap + PCI_BAR0_SPROM_OFFSET);
    223 +               /* enable writes to the SPROM */
    224 +               val32 = OSL_PCI_READ_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32));
    225 +               val32 |= SPROM_WRITEEN;
    226 +               OSL_PCI_WRITE_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32), val32);
    227 +               bcm_mdelay(WRITE_ENABLE_DELAY);
    228 +               /* write srom */
    229 +               for (i = 0; i < nw; i++) {
    230 +                       W_REG(osh, &srom[i], image[i]);
    231 +                       bcm_mdelay(WRITE_WORD_DELAY);
    232 +               }
    233 +               /* disable writes to the SPROM */
    234 +               OSL_PCI_WRITE_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32), val32 &
    235 +                                    ~SPROM_WRITEEN);
    236 +       } else if (BUSTYPE(bustype) == PCMCIA_BUS) {
    237 +               /* enable writes to the SPROM */
    238 +               if (sprom_cmd_pcmcia(osh, SROM_WEN))
    239 +                       return 1;
    240 +               bcm_mdelay(WRITE_ENABLE_DELAY);
    241 +               /* write srom */
    242 +               for (i = 0; i < nw; i++) {
    243 +                       sprom_write_pcmcia(osh, (uint16)(i), image[i]);
    244 +                       bcm_mdelay(WRITE_WORD_DELAY);
    245 +               }
    246 +               /* disable writes to the SPROM */
    247 +               if (sprom_cmd_pcmcia(osh, SROM_WDS))
    248 +                       return 1;
    249 +       } else {
    250 +               return 1;
    251 +       }
    252 +
    253 +       bcm_mdelay(WRITE_ENABLE_DELAY);
    254 +       return 0;
    255 +}
    256 +
    257 +
    258 +static int
    259 +srom_parsecis(osl_t *osh, uint8 **pcis, uint ciscnt, char **vars, uint *count)
    260 +{
    261 +       char eabuf[32];
    262 +       char *vp, *base;
    263 +       uint8 *cis, tup, tlen, sromrev = 1;
    264 +       int i, j;
    265 +       uint varsize;
    266 +       bool ag_init = FALSE;
    267 +       uint32 w32;
    268 +
    269 +       ASSERT(vars);
    270 +       ASSERT(count);
    271 +
    272 +       base = vp = MALLOC(osh, VARS_MAX);
    273 +       ASSERT(vp);
    274 +       if (!vp)
    275 +               return -2;
    276 +
    277 +       while (ciscnt--) {
    278 +               cis = *pcis++;
    279 +               i = 0;
    280 +               do {
    281 +                       tup = cis[i++];
    282 +                       tlen = cis[i++];
    283 +                       if ((i + tlen) >= CIS_SIZE)
    284 +                               break;
    285 +
    286 +                       switch (tup) {
    287 +                       case CISTPL_MANFID:
    288 +                               vp += sprintf(vp, "manfid=%d", (cis[i + 1] << 8) + cis[i]);
    289 +                               vp++;
    290 +                               vp += sprintf(vp, "prodid=%d", (cis[i + 3] << 8) + cis[i + 2]);
    291 +                               vp++;
    292 +                               break;
    293 +
    294 +                       case CISTPL_FUNCE:
    295 +                               switch (cis[i]) {
    296 +                               case LAN_NID:
    297 +                                       ASSERT(cis[i + 1] == 6);
    298 +                                       bcm_ether_ntoa((struct ether_addr *)&cis[i + 2], eabuf);
    299 +                                       vp += sprintf(vp, "il0macaddr=%s", eabuf);
    300 +                                       vp++;
    301 +                                       break;
    302 +                               case 1:         /* SDIO Extended Data */
    303 +                                       vp += sprintf(vp, "sdmaxblk=%d",
    304 +                                                     (cis[i + 13] << 8) | cis[i + 12]);
    305 +                                       vp++;
    306 +                                       break;
    307 +                               }
    308 +                               break;
    309 +
    310 +                       case CISTPL_CFTABLE:
    311 +                               vp += sprintf(vp, "regwindowsz=%d", (cis[i + 7] << 8) | cis[i + 6]);
    312 +                               vp++;
    313 +                               break;
    314 +
    315 +                       case CISTPL_BRCM_HNBU:
    316 +                               switch (cis[i]) {
    317 +                               case HNBU_SROMREV:
    318 +                                       sromrev = cis[i + 1];
    319 +                                       break;
    320 +
    321 +                               case HNBU_CHIPID:
    322 +                                       vp += sprintf(vp, "vendid=%d", (cis[i + 2] << 8) +
    323 +                                                     cis[i + 1]);
    324 +                                       vp++;
    325 +                                       vp += sprintf(vp, "devid=%d", (cis[i + 4] << 8) +
    326 +                                                     cis[i + 3]);
    327 +                                       vp++;
    328 +                                       if (tlen == 7) {
    329 +                                               vp += sprintf(vp, "chiprev=%d",
    330 +                                                             (cis[i + 6] << 8) + cis[i + 5]);
    331 +                                               vp++;
    332 +                                       }
    333 +                                       break;
    334 +
    335 +                               case HNBU_BOARDREV:
    336 +                                       vp += sprintf(vp, "boardrev=%d", cis[i + 1]);
    337 +                                       vp++;
    338 +                                       break;
    339 +
    340 +                               case HNBU_AA:
    341 +                                       vp += sprintf(vp, "aa2g=%d", cis[i + 1]);
    342 +                                       vp++;
    343 +                                       break;
    344 +
    345 +                               case HNBU_AG:
    346 +                                       vp += sprintf(vp, "ag0=%d", cis[i + 1]);
    347 +                                       vp++;
    348 +                                       ag_init = TRUE;
    349 +                                       break;
    350 +
    351 +                               case HNBU_CC:
    352 +                                       ASSERT(sromrev == 1);
    353 +                                       vp += sprintf(vp, "cc=%d", cis[i + 1]);
    354 +                                       vp++;
    355 +                                       break;
    356 +
    357 +                               case HNBU_PAPARMS:
    358 +                                       if (tlen == 2) {
    359 +                                               ASSERT(sromrev == 1);
    360 +                                               vp += sprintf(vp, "pa0maxpwr=%d", cis[i + 1]);
    361 +                                               vp++;
    362 +                                       } else if (tlen >= 9) {
    363 +                                               if (tlen == 10) {
    364 +                                                       ASSERT(sromrev == 2);
    365 +                                                       vp += sprintf(vp, "opo=%d", cis[i + 9]);
    366 +                                                       vp++;
    367 +                                               } else
    368 +                                                       ASSERT(tlen == 9);
    369 +
    370 +                                               for (j = 0; j < 3; j++) {
    371 +                                                       vp += sprintf(vp, "pa0b%d=%d", j,
    372 +                                                                     (cis[i + (j * 2) + 2] << 8) +
    373 +                                                                     cis[i + (j * 2) + 1]);
    374 +                                                       vp++;
    375 +                                               }
    376 +                                               vp += sprintf(vp, "pa0itssit=%d", cis[i + 7]);
    377 +                                               vp++;
    378 +                                               vp += sprintf(vp, "pa0maxpwr=%d", cis[i + 8]);
    379 +                                               vp++;
    380 +                                       } else
    381 +                                               ASSERT(tlen >= 9);
    382 +                                       break;
    383 +
    384 +                               case HNBU_OEM:
    385 +                                       ASSERT(sromrev == 1);
    386 +                                       vp += sprintf(vp, "oem=%02x%02x%02x%02x%02x%02x%02x%02x",
    387 +                                                     cis[i + 1], cis[i + 2],
    388 +                                                     cis[i + 3], cis[i + 4],
    389 +                                                     cis[i + 5], cis[i + 6],
    390 +                                                     cis[i + 7], cis[i + 8]);
    391 +                                       vp++;
    392 +                                       break;
    393 +
    394 +                               case HNBU_BOARDFLAGS:
    395 +                                       w32 = (cis[i + 2] << 8) + cis[i + 1];
    396 +                                       if (tlen == 5)
    397 +                                               w32 |= (cis[i + 4] << 24) + (cis[i + 3] << 16);
    398 +                                       vp += sprintf(vp, "boardflags=0x%x", w32);
    399 +                                       vp++;
    400 +                                       break;
    401 +
    402 +                               case HNBU_LEDS:
    403 +                                       if (cis[i + 1] != 0xff) {
    404 +                                               vp += sprintf(vp, "ledbh0=%d", cis[i + 1]);
    405 +                                               vp++;
    406 +                                       }
    407 +                                       if (cis[i + 2] != 0xff) {
    408 +                                               vp += sprintf(vp, "ledbh1=%d", cis[i + 2]);
    409 +                                               vp++;
    410 +                                       }
    411 +                                       if (cis[i + 3] != 0xff) {
    412 +                                               vp += sprintf(vp, "ledbh2=%d", cis[i + 3]);
    413 +                                               vp++;
    414 +                                       }
    415 +                                       if (cis[i + 4] != 0xff) {
    416 +                                               vp += sprintf(vp, "ledbh3=%d", cis[i + 4]);
    417 +                                               vp++;
    418 +                                       }
    419 +                                       break;
    420 +
    421 +                               case HNBU_CCODE:
    422 +                               {
    423 +                                       char str[3];
    424 +                                       ASSERT(sromrev > 1);
    425 +                                       str[0] = cis[i + 1];
    426 +                                       str[1] = cis[i + 2];
    427 +                                       str[2] = 0;
    428 +                                       vp += sprintf(vp, "ccode=%s", str);
    429 +                                       vp++;
    430 +                                       vp += sprintf(vp, "cctl=0x%x", cis[i + 3]);
    431 +                                       vp++;
    432 +                                       break;
    433 +                               }
    434 +
    435 +                               case HNBU_CCKPO:
    436 +                                       ASSERT(sromrev > 2);
    437 +                                       vp += sprintf(vp, "cckpo=0x%x",
    438 +                                                     (cis[i + 2] << 8) | cis[i + 1]);
    439 +                                       vp++;
    440 +                                       break;
    441 +
    442 +                               case HNBU_OFDMPO:
    443 +                                       ASSERT(sromrev > 2);
    444 +                                       vp += sprintf(vp, "ofdmpo=0x%x",
    445 +                                                     (cis[i + 4] << 24) |
    446 +                                                     (cis[i + 3] << 16) |
    447 +                                                     (cis[i + 2] << 8) |
    448 +                                                     cis[i + 1]);
    449 +                                       vp++;
    450 +                                       break;
    451 +                               }
    452 +                               break;
    453 +
    454 +                       }
    455 +                       i += tlen;
    456 +               } while (tup != 0xff);
    457 +       }
    458 +
    459 +       /* Set the srom version */
    460 +       vp += sprintf(vp, "sromrev=%d", sromrev);
    461 +       vp++;
    462 +
    463 +       /* if there is no antenna gain field, set default */
    464 +       if (ag_init == FALSE) {
    465 +               ASSERT(sromrev == 1);
    466 +               vp += sprintf(vp, "ag0=%d", 0xff);
    467 +               vp++;
    468 +       }
    469 +
    470 +       /* final nullbyte terminator */
    471 +       *vp++ = '\0';
    472 +       varsize = (uint)(vp - base);
    473 +
    474 +       ASSERT((vp - base) < VARS_MAX);
    475 +
    476 +       if (varsize == VARS_MAX) {
    477 +               *vars = base;
    478 +       } else {
    479 +               vp = MALLOC(osh, varsize);
    480 +               ASSERT(vp);
    481 +               if (vp)
    482 +                       bcopy(base, vp, varsize);
    483 +               MFREE(osh, base, VARS_MAX);
    484 +               *vars = vp;
    485 +               if (!vp) {
    486 +                       *count = 0;
    487 +                       return -2;
    488 +               }
    489 +       }
    490 +       *count = varsize;
    491 +
    492 +       return (0);
    493 +}
    494 +
    495 +
    496 +/* set PCMCIA sprom command register */
    497 +static int
    498 +sprom_cmd_pcmcia(osl_t *osh, uint8 cmd)
    499 +{
    500 +       uint8 status = 0;
    501 +       uint wait_cnt = 1000;
    502 +
    503 +       /* write sprom command register */
    504 +       OSL_PCMCIA_WRITE_ATTR(osh, SROM_CS, &cmd, 1);
    505 +
    506 +       /* wait status */
    507 +       while (wait_cnt--) {
    508 +               OSL_PCMCIA_READ_ATTR(osh, SROM_CS, &status, 1);
    509 +               if (status & SROM_DONE)
    510 +                       return 0;
    511 +       }
    512 +
    513 +       return 1;
    514 +}
    515 +
    516 +/* read a word from the PCMCIA srom */
    517 +static int
    518 +sprom_read_pcmcia(osl_t *osh, uint16 addr, uint16 *data)
    519 +{
    520 +       uint8 addr_l, addr_h, data_l, data_h;
    521 +
    522 +       addr_l = (uint8)((addr * 2) & 0xff);
    523 +       addr_h = (uint8)(((addr * 2) >> 8) & 0xff);
    524 +
    525 +       /* set address */
    526 +       OSL_PCMCIA_WRITE_ATTR(osh, SROM_ADDRH, &addr_h, 1);
    527 +       OSL_PCMCIA_WRITE_ATTR(osh, SROM_ADDRL, &addr_l, 1);
    528 +
    529 +       /* do read */
    530 +       if (sprom_cmd_pcmcia(osh, SROM_READ))
    531 +               return 1;
    532 +
    533 +       /* read data */
    534 +       data_h = data_l = 0;
    535 +       OSL_PCMCIA_READ_ATTR(osh, SROM_DATAH, &data_h, 1);
    536 +       OSL_PCMCIA_READ_ATTR(osh, SROM_DATAL, &data_l, 1);
    537 +
    538 +       *data = (data_h << 8) | data_l;
    539 +       return 0;
    540 +}
    541 +
    542 +/* write a word to the PCMCIA srom */
    543 +static int
    544 +sprom_write_pcmcia(osl_t *osh, uint16 addr, uint16 data)
    545 +{
    546 +       uint8 addr_l, addr_h, data_l, data_h;
    547 +
    548 +       addr_l = (uint8)((addr * 2) & 0xff);
    549 +       addr_h = (uint8)(((addr * 2) >> 8) & 0xff);
    550 +       data_l = (uint8)(data & 0xff);
    551 +       data_h = (uint8)((data >> 8) & 0xff);
    552 +
    553 +       /* set address */
    554 +       OSL_PCMCIA_WRITE_ATTR(osh, SROM_ADDRH, &addr_h, 1);
    555 +       OSL_PCMCIA_WRITE_ATTR(osh, SROM_ADDRL, &addr_l, 1);
    556 +
    557 +       /* write data */
    558 +       OSL_PCMCIA_WRITE_ATTR(osh, SROM_DATAH, &data_h, 1);
    559 +       OSL_PCMCIA_WRITE_ATTR(osh, SROM_DATAL, &data_l, 1);
    560 +
    561 +       /* do write */
    562 +       return sprom_cmd_pcmcia(osh, SROM_WRITE);
    563 +}
    564 +
    565 +/*
    566 + * Read in and validate sprom.
    567 + * Return 0 on success, nonzero on error.
    568 + */
    569 +static int
    570 +sprom_read_pci(osl_t *osh, uint16 *sprom, uint wordoff, uint16 *buf, uint nwords, bool check_crc)
    571 +{
    572 +       int err = 0;
    573 +       uint i;
    574 +
    575 +       /* read the sprom */
    576 +       for (i = 0; i < nwords; i++)
    577 +               buf[i] = R_REG(osh, &sprom[wordoff + i]);
    578 +
    579 +       if (check_crc) {
    580 +               /* fixup the endianness so crc8 will pass */
    581 +               htol16_buf(buf, nwords * 2);
    582 +               if (hndcrc8((uint8*)buf, nwords * 2, CRC8_INIT_VALUE) != CRC8_GOOD_VALUE)
    583 +                       err = 1;
    584 +               /* now correct the endianness of the byte array */
    585 +               ltoh16_buf(buf, nwords * 2);
    586 +       }
    587 +
    588 +       return err;
    589 +}
    590 +
    591 +/*
    592 +* Create variable table from memory.
    593 +* Return 0 on success, nonzero on error.
    594 +*/
    595 +static int
    596 +initvars_table(osl_t *osh, char *start, char *end, char **vars, uint *count)
    597 +{
    598 +       int c = (int)(end - start);
    599 +
    600 +       /* do it only when there is more than just the null string */
    601 +       if (c > 1) {
    602 +               char *vp = MALLOC(osh, c);
    603 +               ASSERT(vp);
    604 +               if (!vp)
    605 +                       return BCME_NOMEM;
    606 +               bcopy(start, vp, c);
    607 +               *vars = vp;
    608 +               *count = c;
    609 +       }
    610 +       else {
    611 +               *vars = NULL;
    612 +               *count = 0;
    613 +       }
    614 +
    615 +       return 0;
    616 +}
    617 +
    618 +/*
    619 + * Find variables with <devpath> from flash. 'base' points to the beginning
    620 + * of the table upon enter and to the end of the table upon exit when success.
    621 + * Return 0 on success, nonzero on error.
    622 + */
    623 +static int
    624 +initvars_flash(osl_t *osh, char **base, uint len, char *devpath)
    625 +{
    626 +       char *vp = *base;
    627 +       char *flash;
    628 +       int err;
    629 +       char *s;
    630 +       uint l, dl, copy_len;
    631 +
    632 +       /* allocate memory and read in flash */
    633 +       if (!(flash = MALLOC(osh, NVRAM_SPACE)))
    634 +               return BCME_NOMEM;
    635 +       if ((err = nvram_getall(flash, NVRAM_SPACE)))
    636 +               goto exit;
    637 +
    638 +       /* grab vars with the <devpath> prefix in name */
    639 +       dl = strlen(devpath);
    640 +       for (s = flash; s && *s; s += l + 1) {
    641 +               l = strlen(s);
    642 +
    643 +               /* skip non-matching variable */
    644 +               if (strncmp(s, devpath, dl))
    645 +                       continue;
    646 +
    647 +               /* is there enough room to copy? */
    648 +               copy_len = l - dl + 1;
    649 +               if (len < copy_len) {
    650 +                       err = BCME_BUFTOOSHORT;
    651 +                       goto exit;
    652 +               }
    653 +
    654 +               /* no prefix, just the name=value */
    655 +               strcpy(vp, &s[dl]);
    656 +               vp += copy_len;
    657 +               len -= copy_len;
    658 +       }
    659 +
    660 +       /* add null string as terminator */
    661 +       if (len < 1) {
    662 +               err = BCME_BUFTOOSHORT;
    663 +               goto exit;
    664 +       }
    665 +       *vp++ = '\0';
    666 +
    667 +       *base = vp;
    668 +
    669 +exit:  MFREE(osh, flash, NVRAM_SPACE);
    670 +       return err;
    671 +}
    672 +
    673 +/*
    674 + * Initialize nonvolatile variable table from flash.
    675 + * Return 0 on success, nonzero on error.
    676 + */
    677 +static int
    678 +initvars_flash_sb(void *sbh, char **vars, uint *count)
    679 +{
    680 +       osl_t *osh = sb_osh(sbh);
    681 +       char devpath[SB_DEVPATH_BUFSZ];
    682 +       char *vp, *base;
    683 +       int err;
    684 +
    685 +       ASSERT(vars);
    686 +       ASSERT(count);
    687 +
    688 +       if ((err = sb_devpath(sbh, devpath, sizeof(devpath))))
    689 +               return err;
    690 +
    691 +       base = vp = MALLOC(osh, VARS_MAX);
    692 +       ASSERT(vp);
    693 +       if (!vp)
    694 +               return BCME_NOMEM;
    695 +
    696 +       if ((err = initvars_flash(osh, &vp, VARS_MAX, devpath)))
    697 +               goto err;
    698 +
    699 +       err = initvars_table(osh, base, vp, vars, count);
    700 +
    701 +err:   MFREE(osh, base, VARS_MAX);
    702 +       return err;
    703 +}
    704 +
    705 +#ifdef WLTEST
    706 +char mfgsromvars[256];
    707 +char *defaultsromvars = "il0macaddr=00:11:22:33:44:51\0"
    708 +               "et0macaddr=00:11:22:33:44:52\0"
    709 +               "et1macaddr=00:11:22:33:44:53\0"
    710 +               "boardtype=0xffff\0"
    711 +               "boardrev=0x10\0"
    712 +               "boardflags=8\0"
    713 +               "sromrev=2\0"
    714 +               "aa2g=3";
    715 +#define        MFGSROM_DEFVARSLEN      147 /* default srom len */
    716 +#endif /* WL_TEST */
    717 +
    718 +/*
    719 + * Initialize nonvolatile variable table from sprom.
    720 + * Return 0 on success, nonzero on error.
    721 + */
    722 +static int
    723 +initvars_srom_pci(void *sbh, void *curmap, char **vars, uint *count)
    724 +{
    725 +       uint16 w, *b;
    726 +       uint8 sromrev = 0;
    727 +       struct ether_addr ea;
    728 +       char eabuf[32];
    729 +       uint32 w32;
    730 +       int woff, i;
    731 +       char *vp, *base;
    732 +       osl_t *osh = sb_osh(sbh);
    733 +       bool flash = FALSE;
    734 +       char name[SB_DEVPATH_BUFSZ+16], *value;
    735 +       char devpath[SB_DEVPATH_BUFSZ];
    736 +       int err;
    737 +
    738 +       /*
    739 +        * Apply CRC over SROM content regardless SROM is present or not,
    740 +        * and use variable <devpath>sromrev's existance in flash to decide
    741 +        * if we should return an error when CRC fails or read SROM variables
    742 +        * from flash.
    743 +        */
    744 +       b = MALLOC(osh, SROM_MAX);
    745 +       ASSERT(b);
    746 +       if (!b)
    747 +               return -2;
    748 +
    749 +       err = sprom_read_pci(osh, (void*)((int8*)curmap + PCI_BAR0_SPROM_OFFSET), 0, b,
    750 +                            64, TRUE);
    751 +       if (err == 0) {
    752 +               /* srom is good and is rev < 4 */
    753 +               /* top word of sprom contains version and crc8 */
    754 +               sromrev = b[63] & 0xff;
    755 +               /* bcm4401 sroms misprogrammed */
    756 +               if (sromrev == 0x10)
    757 +                       sromrev = 1;
    758 +       } else if (b[SROM4_SIGN] == SROM4_SIGNATURE) {
    759 +               /* If sromrev >= 4, read more */
    760 +               err = sprom_read_pci(osh, (void*)((int8*)curmap + PCI_BAR0_SPROM_OFFSET), 0, b,
    761 +                                    SROM4_WORDS, TRUE);
    762 +               sromrev = b[SROM4_WORDS - 1] & 0xff;
    763 +       }
    764 +
    765 +       if (err) {
    766 +#ifdef WLTEST
    767 +               BS_ERROR(("SROM Crc Error, so see if we could use a default\n"));
    768 +               w32 = OSL_PCI_READ_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32));
    769 +               if (w32 & SPROM_OTPIN_USE) {
    770 +                       BS_ERROR(("srom crc failed with OTP, use default vars....\n"));
    771 +                       vp = base =  mfgsromvars;
    772 +                       if (sb_chip(sbh) == BCM4311_CHIP_ID) {
    773 +                               BS_ERROR(("setting the devid to be 4311\n"));
    774 +                               vp += sprintf(vp, "devid=0x4311");
    775 +                               vp++;
    776 +                       }
    777 +                       bcopy(defaultsromvars,  vp, MFGSROM_DEFVARSLEN);
    778 +                       vp += MFGSROM_DEFVARSLEN;
    779 +                       goto varsdone;
    780 +               } else {
    781 +                       BS_ERROR(("srom crc failed with SPROM....\n"));
    782 +#endif /* WLTEST */
    783 +                       if ((err = sb_devpath(sbh, devpath, sizeof(devpath))))
    784 +                               return err;
    785 +                       sprintf(name, "%ssromrev", devpath);
    786 +                       if (!(value = getvar(NULL, name)))
    787 +                               return (-1);
    788 +                       sromrev = (uint8)bcm_strtoul(value, NULL, 0);
    789 +                       flash = TRUE;
    790 +#ifdef WLTEST
    791 +               }
    792 +#endif /* WLTEST */
    793 +       }
    794 +
    795 +       /* srom version check */
    796 +       if (sromrev > 4)
    797 +               return (-2);
    798 +
    799 +       ASSERT(vars);
    800 +       ASSERT(count);
    801 +
    802 +       base = vp = MALLOC(osh, VARS_MAX);
    803 +       ASSERT(vp);
    804 +       if (!vp)
    805 +               return -2;
    806 +
    807 +       /* read variables from flash */
    808 +       if (flash) {
    809 +               if ((err = initvars_flash(osh, &vp, VARS_MAX, devpath)))
    810 +                       goto err;
    811 +               goto varsdone;
    812 +       }
    813 +
    814 +       vp += sprintf(vp, "sromrev=%d", sromrev);
    815 +       vp++;
    816 +
    817 +       if (sromrev >= 4) {
    818 +               uint path, pathbase;
    819 +               const uint pathbases[MAX_PATH] = {SROM4_PATH0, SROM4_PATH1,
    820 +                                                 SROM4_PATH2, SROM4_PATH3};
    821 +
    822 +               vp += sprintf(vp, "boardrev=%d", b[SROM4_BREV]);
    823 +               vp++;
    824 +
    825 +               vp += sprintf(vp, "boardflags=%d", (b[SROM4_BFL1] << 16) | b[SROM4_BFL0]);
    826 +               vp++;
    827 +
    828 +               vp += sprintf(vp, "boardflags2=%d", (b[SROM4_BFL3] << 16) | b[SROM4_BFL2]);
    829 +               vp++;
    830 +
    831 +               /* The macaddr */
    832 +               ea.octet[0] = (b[SROM4_MACHI] >> 8) & 0xff;
    833 +               ea.octet[1] = b[SROM4_MACHI] & 0xff;
    834 +               ea.octet[2] = (b[SROM4_MACMID] >> 8) & 0xff;
    835 +               ea.octet[3] = b[SROM4_MACMID] & 0xff;
    836 +               ea.octet[4] = (b[SROM4_MACLO] >> 8) & 0xff;
    837 +               ea.octet[5] = b[SROM4_MACLO] & 0xff;
    838 +               bcm_ether_ntoa(&ea, eabuf);
    839 +               vp += sprintf(vp, "macaddr=%s", eabuf);
    840 +               vp++;
    841 +
    842 +               w = b[SROM4_CCODE];
    843 +               if (w == 0)
    844 +                       vp += sprintf(vp, "ccode=");
    845 +               else
    846 +                       vp += sprintf(vp, "ccode=%c%c", (w >> 8), (w & 0xff));
    847 +               vp++;
    848 +               vp += sprintf(vp, "regrev=%d", b[SROM4_REGREV]);
    849 +               vp++;
    850 +
    851 +               w = b[SROM4_LEDBH10];
    852 +               if ((w != 0) && (w != 0xffff)) {
    853 +                       /* ledbh0 */
    854 +                       vp += sprintf(vp, "ledbh0=%d", (w & 0xff));
    855 +                       vp++;
    856 +
    857 +                       /* ledbh1 */
    858 +                       vp += sprintf(vp, "ledbh1=%d", (w >> 8) & 0xff);
    859 +                       vp++;
    860 +               }
    861 +               w = b[SROM4_LEDBH32];
    862 +               if ((w != 0) && (w != 0xffff)) {
    863 +                       /* ledbh2 */
    864 +                       vp += sprintf(vp, "ledbh2=%d", w & 0xff);
    865 +                       vp++;
    866 +
    867 +                       /* ledbh3 */
    868 +                       vp += sprintf(vp, "ledbh3=%d", (w >> 8) & 0xff);
    869 +                       vp++;
    870 +               }
    871 +               /* LED Powersave duty cycle (oncount >> 24) (offcount >> 8) */
    872 +               w = b[SROM4_LEDDC];
    873 +               w32 = ((uint32)((unsigned char)(w >> 8) & 0xff) << 24) |  /* oncount */
    874 +                       ((uint32)((unsigned char)(w & 0xff)) << 8); /* offcount */
    875 +               vp += sprintf(vp, "leddc=%d", w32);
    876 +               vp++;
    877 +
    878 +               w = b[SROM4_AA];
    879 +               vp += sprintf(vp, "aa2g=%d", w & SROM4_AA2G_MASK);
    880 +               vp++;
    881 +               vp += sprintf(vp, "aa5g=%d", w >> SROM4_AA5G_SHIFT);
    882 +               vp++;
    883 +
    884 +               w = b[SROM4_AG10];
    885 +               vp += sprintf(vp, "ag0=%d", w & 0xff);
    886 +               vp++;
    887 +               vp += sprintf(vp, "ag1=%d", (w >> 8) & 0xff);
    888 +               vp++;
    889 +               w = b[SROM4_AG32];
    890 +               vp += sprintf(vp, "ag2=%d", w & 0xff);
    891 +               vp++;
    892 +               vp += sprintf(vp, "ag3=%d", (w >> 8) & 0xff);
    893 +               vp++;
    894 +
    895 +               /* Fixed power indices when power control is disabled */
    896 +               for (i = 0; i < 2; i++) {
    897 +                       w = b[SROM4_TXPID2G + i];
    898 +                       vp += sprintf(vp, "txpid2ga%d=%d", 2 * i, w & 0xff);
    899 +                       vp++;
    900 +                       vp += sprintf(vp, "txpid2ga%d=%d", (2 * i) + 1, (w >> 8) & 0xff);
    901 +                       vp++;
    902 +                       w = b[SROM4_TXPID5G + i];
    903 +                       vp += sprintf(vp, "txpid5ga%d=%d", 2 * i, w & 0xff);
    904 +                       vp++;
    905 +                       vp += sprintf(vp, "txpid5ga%d=%d", (2 * i) + 1, (w >> 8) & 0xff);
    906 +                       vp++;
    907 +                       w = b[SROM4_TXPID5GL + i];
    908 +                       vp += sprintf(vp, "txpid5gla%d=%d", 2 * i, w & 0xff);
    909 +                       vp++;
    910 +                       vp += sprintf(vp, "txpid5gla%d=%d", (2 * i) + 1, (w >> 8) & 0xff);
    911 +                       vp++;
    912 +                       w = b[SROM4_TXPID5GH + i];
    913 +                       vp += sprintf(vp, "txpid5gha%d=%d", 2 * i, w & 0xff);
    914 +                       vp++;
    915 +                       vp += sprintf(vp, "txpid5gha%d=%d", (2 * i) + 1, (w >> 8) & 0xff);
    916 +                       vp++;
    917 +               }
    918 +
    919 +               /* Per path variables */
    920 +               for (path = 0; path < MAX_PATH; path++) {
    921 +                       pathbase = pathbases[path];
    922 +                       w = b[pathbase + SROM4_2G_ITT_MAXP];
    923 +                       vp += sprintf(vp, "itt2ga%d=%d", path, w >> B2G_ITT_SHIFT);
    924 +                       vp++;
    925 +                       vp += sprintf(vp, "maxp2ga%d=%d", path, w & B2G_MAXP_MASK);
    926 +                       vp++;
    927 +
    928 +                       for (i = 0; i < 4; i++) {
    929 +                               vp += sprintf(vp, "pa2gw%da%d=%d", i, path,
    930 +                                             b[pathbase + SROM4_2G_PA + i]);
    931 +                               vp++;
    932 +                       }
    933 +
    934 +                       w = b[pathbase + SROM4_5G_ITT_MAXP];
    935 +                       vp += sprintf(vp, "itt5ga%d=%d", path, w >> B5G_ITT_SHIFT);
    936 +                       vp++;
    937 +                       vp += sprintf(vp, "maxp5ga%d=%d", path, w & B5G_MAXP_MASK);
    938 +                       vp++;
    939 +
    940 +                       w = b[pathbase + SROM4_5GLH_MAXP];
    941 +                       vp += sprintf(vp, "maxp5lga%d=%d", path, w >> B5GL_MAXP_SHIFT);
    942 +                       vp++;
    943 +                       vp += sprintf(vp, "maxp5gha%d=%d", path, w & B5GH_MAXP_MASK);
    944 +                       vp++;
    945 +
    946 +                       for (i = 0; i < 4; i++) {
    947 +                               vp += sprintf(vp, "pa5gw%da%d=%d", i, path,
    948 +                                             b[pathbase + SROM4_5G_PA + i]);
    949 +                               vp++;
    950 +                               vp += sprintf(vp, "pa5glw%da%d=%d", i, path,
    951 +                                             b[pathbase + SROM4_5GL_PA + i]);
    952 +                               vp++;
    953 +                               vp += sprintf(vp, "pa5hgw%da%d=%d", i, path,
    954 +                                             b[pathbase + SROM4_5GH_PA + i]);
    955 +                               vp++;
    956 +                       }
    957 +               }
    958 +
    959 +               vp += sprintf(vp, "cck2gpo=%d", b[SROM4_2G_CCKPO]);
    960 +               vp++;
    961 +
    962 +               w32 = ((uint32)b[SROM4_2G_OFDMPO + 1] << 16) | b[SROM4_2G_OFDMPO];
    963 +               vp += sprintf(vp, "ofdm2gpo=%d", w32);
    964 +               vp++;
    965 +
    966 +               w32 = ((uint32)b[SROM4_5G_OFDMPO + 1] << 16) | b[SROM4_5G_OFDMPO];
    967 +               vp += sprintf(vp, "ofdm5gpo=%d", w32);
    968 +               vp++;
    969 +
    970 +               w32 = ((uint32)b[SROM4_5GL_OFDMPO + 1] << 16) | b[SROM4_5GL_OFDMPO];
    971 +               vp += sprintf(vp, "ofdm5glpo=%d", w32);
    972 +               vp++;
    973 +
    974 +               w32 = ((uint32)b[SROM4_5GH_OFDMPO + 1] << 16) | b[SROM4_5GH_OFDMPO];
    975 +               vp += sprintf(vp, "ofdm5ghpo=%d", w32);
    976 +               vp++;
    977 +
    978 +               for (i = 0; i < 8; i++) {
    979 +                       vp += sprintf(vp, "mcs2gpo%d=%d", i, b[SROM4_2G_MCSPO]);
    980 +                       vp++;
    981 +                       vp += sprintf(vp, "mcs5gpo%d=%d", i, b[SROM4_5G_MCSPO]);
    982 +                       vp++;
    983 +                       vp += sprintf(vp, "mcs5glpo%d=%d", i, b[SROM4_5GL_MCSPO]);
    984 +                       vp++;
    985 +                       vp += sprintf(vp, "mcs5ghpo%d=%d", i, b[SROM4_5GH_MCSPO]);
    986 +                       vp++;
    987 +               }
    988 +
    989 +               vp += sprintf(vp, "ccdpo%d=%d", i, b[SROM4_CCDPO]);
    990 +               vp++;
    991 +               vp += sprintf(vp, "stbcpo%d=%d", i, b[SROM4_STBCPO]);
    992 +               vp++;
    993 +               vp += sprintf(vp, "bw40po%d=%d", i, b[SROM4_BW40PO]);
    994 +               vp++;
    995 +               vp += sprintf(vp, "bwduppo%d=%d", i, b[SROM4_BWDUPPO]);
    996 +               vp++;
    997 +
    998 +               goto done;
    999 +       }
    1000 +       if (sromrev >= 3) {
    1001 +               /* New section takes over the 3th hardware function space */
    1002 +
    1003 +               /* Words 22+23 are 11a (mid) ofdm power offsets */
    1004 +               w32 = ((uint32)b[23] << 16) | b[22];
    1005 +               vp += sprintf(vp, "ofdmapo=%d", w32);
    1006 +               vp++;
    1007 +
    1008 +               /* Words 24+25 are 11a (low) ofdm power offsets */
    1009 +               w32 = ((uint32)b[25] << 16) | b[24];
    1010 +               vp += sprintf(vp, "ofdmalpo=%d", w32);
    1011 +               vp++;
    1012 +
    1013 +               /* Words 26+27 are 11a (high) ofdm power offsets */
    1014 +               w32 = ((uint32)b[27] << 16) | b[26];
    1015 +               vp += sprintf(vp, "ofdmahpo=%d", w32);
    1016 +               vp++;
    1017 +
    1018 +               /* LED Powersave duty cycle (oncount >> 24) (offcount >> 8) */
    1019 +               w32 = ((uint32)((unsigned char)(b[21] >> 8) & 0xff) << 24) |  /* oncount */
    1020 +                       ((uint32)((unsigned char)(b[21] & 0xff)) << 8); /* offcount */
    1021 +               vp += sprintf(vp, "leddc=%d", w32);
    1022 +
    1023 +               vp++;
    1024 +       }
    1025 +
    1026 +       if (sromrev >= 2) {
    1027 +               /* New section takes over the 4th hardware function space */
    1028 +
    1029 +               /* Word 29 is max power 11a high/low */
    1030 +               w = b[29];
    1031 +               vp += sprintf(vp, "pa1himaxpwr=%d", w & 0xff);
    1032 +               vp++;
    1033 +               vp += sprintf(vp, "pa1lomaxpwr=%d", (w >> 8) & 0xff);
    1034 +               vp++;
    1035 +
    1036 +               /* Words 30-32 set the 11alow pa settings,
    1037 +                * 33-35 are the 11ahigh ones.
    1038 +                */
    1039 +               for (i = 0; i < 3; i++) {
    1040 +                       vp += sprintf(vp, "pa1lob%d=%d", i, b[30 + i]);
    1041 +                       vp++;
    1042 +                       vp += sprintf(vp, "pa1hib%d=%d", i, b[33 + i]);
    1043 +                       vp++;
    1044 +               }
    1045 +               w = b[59];
    1046 +               if (w == 0)
    1047 +                       vp += sprintf(vp, "ccode=");
    1048 +               else
    1049 +                       vp += sprintf(vp, "ccode=%c%c", (w >> 8), (w & 0xff));
    1050 +               vp++;
    1051 +
    1052 +       }
    1053 +
    1054 +       /* parameter section of sprom starts at byte offset 72 */
    1055 +       woff = 72/2;
    1056 +
    1057 +       /* first 6 bytes are il0macaddr */
    1058 +       ea.octet[0] = (b[woff] >> 8) & 0xff;
    1059 +       ea.octet[1] = b[woff] & 0xff;
    1060 +       ea.octet[2] = (b[woff+1] >> 8) & 0xff;
    1061 +       ea.octet[3] = b[woff+1] & 0xff;
    1062 +       ea.octet[4] = (b[woff+2] >> 8) & 0xff;
    1063 +       ea.octet[5] = b[woff+2] & 0xff;
    1064 +       woff += 3;
    1065 +       bcm_ether_ntoa(&ea, eabuf);
    1066 +       vp += sprintf(vp, "il0macaddr=%s", eabuf);
    1067 +       vp++;
    1068 +
    1069 +       /* next 6 bytes are et0macaddr */
    1070 +       ea.octet[0] = (b[woff] >> 8) & 0xff;
    1071 +       ea.octet[1] = b[woff] & 0xff;
    1072 +       ea.octet[2] = (b[woff+1] >> 8) & 0xff;
    1073 +       ea.octet[3] = b[woff+1] & 0xff;
    1074 +       ea.octet[4] = (b[woff+2] >> 8) & 0xff;
    1075 +       ea.octet[5] = b[woff+2] & 0xff;
    1076 +       woff += 3;
    1077 +       bcm_ether_ntoa(&ea, eabuf);
    1078 +       vp += sprintf(vp, "et0macaddr=%s", eabuf);
    1079 +       vp++;
    1080 +
    1081 +       /* next 6 bytes are et1macaddr */
    1082 +       ea.octet[0] = (b[woff] >> 8) & 0xff;
    1083 +       ea.octet[1] = b[woff] & 0xff;
    1084 +       ea.octet[2] = (b[woff+1] >> 8) & 0xff;
    1085 +       ea.octet[3] = b[woff+1] & 0xff;
    1086 +       ea.octet[4] = (b[woff+2] >> 8) & 0xff;
    1087 +       ea.octet[5] = b[woff+2] & 0xff;
    1088 +       woff += 3;
    1089 +       bcm_ether_ntoa(&ea, eabuf);
    1090 +       vp += sprintf(vp, "et1macaddr=%s", eabuf);
    1091 +       vp++;
    1092 +
    1093 +       /*
    1094 +        * Enet phy settings one or two singles or a dual
    1095 +        * Bits 4-0 : MII address for enet0 (0x1f for not there)
    1096 +        * Bits 9-5 : MII address for enet1 (0x1f for not there)
    1097 +        * Bit 14   : Mdio for enet0
    1098 +        * Bit 15   : Mdio for enet1
    1099 +        */
    1100 +       w = b[woff];
    1101 +       vp += sprintf(vp, "et0phyaddr=%d", (w & 0x1f));
    1102 +       vp++;
    1103 +       vp += sprintf(vp, "et1phyaddr=%d", ((w >> 5) & 0x1f));
    1104 +       vp++;
    1105 +       vp += sprintf(vp, "et0mdcport=%d", ((w >> 14) & 0x1));
    1106 +       vp++;
    1107 +       vp += sprintf(vp, "et1mdcport=%d", ((w >> 15) & 0x1));
    1108 +       vp++;
    1109 +
    1110 +       /* Word 46 has board rev, antennas 0/1 & Country code/control */
    1111 +       w = b[46];
    1112 +       vp += sprintf(vp, "boardrev=%d", w & 0xff);
    1113 +       vp++;
    1114 +
    1115 +       if (sromrev > 1)
    1116 +               vp += sprintf(vp, "cctl=%d", (w >> 8) & 0xf);
    1117 +       else
    1118 +               vp += sprintf(vp, "cc=%d", (w >> 8) & 0xf);
    1119 +       vp++;
    1120 +
    1121 +       vp += sprintf(vp, "aa2g=%d", (w >> 12) & 0x3);
    1122 +       vp++;
    1123 +
    1124 +       vp += sprintf(vp, "aa5g=%d", (w >> 14) & 0x3);
    1125 +       vp++;
    1126 +
    1127 +       /* Words 47-49 set the (wl) pa settings */
    1128 +       woff = 47;
    1129 +
    1130 +       for (i = 0; i < 3; i++) {
    1131 +               vp += sprintf(vp, "pa0b%d=%d", i, b[woff+i]);
    1132 +               vp++;
    1133 +               vp += sprintf(vp, "pa1b%d=%d", i, b[woff+i+6]);
    1134 +               vp++;
    1135 +       }
    1136 +
    1137 +       /*
    1138 +        * Words 50-51 set the customer-configured wl led behavior.
    1139 +        * 8 bits/gpio pin.  High bit:  activehi=0, activelo=1;
    1140 +        * LED behavior values defined in wlioctl.h .
    1141 +        */
    1142 +       w = b[50];
    1143 +       if ((w != 0) && (w != 0xffff)) {
    1144 +               /* ledbh0 */
    1145 +               vp += sprintf(vp, "ledbh0=%d", (w & 0xff));
    1146 +               vp++;
    1147 +
    1148 +               /* ledbh1 */
    1149 +               vp += sprintf(vp, "ledbh1=%d", (w >> 8) & 0xff);
    1150 +               vp++;
    1151 +       }
    1152 +       w = b[51];
    1153 +       if ((w != 0) && (w != 0xffff)) {
    1154 +               /* ledbh2 */
    1155 +               vp += sprintf(vp, "ledbh2=%d", w & 0xff);
    1156 +               vp++;
    1157 +
    1158 +               /* ledbh */
    1159 +               vp += sprintf(vp, "ledbh3=%d", (w >> 8) & 0xff);
    1160 +               vp++;
    1161 +       }
    1162 +
    1163 +       /* Word 52 is max power 0/1 */
    1164 +       w = b[52];
    1165 +       vp += sprintf(vp, "pa0maxpwr=%d", w & 0xff);
    1166 +       vp++;
    1167 +       vp += sprintf(vp, "pa1maxpwr=%d", (w >> 8) & 0xff);
    1168 +       vp++;
    1169 +
    1170 +       /* Word 56 is idle tssi target 0/1 */
    1171 +       w = b[56];
    1172 +       vp += sprintf(vp, "pa0itssit=%d", w & 0xff);
    1173 +       vp++;
    1174 +       vp += sprintf(vp, "pa1itssit=%d", (w >> 8) & 0xff);
    1175 +       vp++;
    1176 +
    1177 +       /* Word 57 is boardflags, if not programmed make it zero */
    1178 +       w32 = (uint32)b[57];
    1179 +       if (w32 == 0xffff) w32 = 0;
    1180 +       if (sromrev > 1) {
    1181 +               /* Word 28 is the high bits of boardflags */
    1182 +               w32 |= (uint32)b[28] << 16;
    1183 +       }
    1184 +       vp += sprintf(vp, "boardflags=%d", w32);
    1185 +       vp++;
    1186 +
    1187 +       /* Word 58 is antenna gain 0/1 */
    1188 +       w = b[58];
    1189 +       vp += sprintf(vp, "ag0=%d", w & 0xff);
    1190 +       vp++;
    1191 +
    1192 +       vp += sprintf(vp, "ag1=%d", (w >> 8) & 0xff);
    1193 +       vp++;
    1194 +
    1195 +       if (sromrev == 1) {
    1196 +               /* set the oem string */
    1197 +               vp += sprintf(vp, "oem=%02x%02x%02x%02x%02x%02x%02x%02x",
    1198 +                             ((b[59] >> 8) & 0xff), (b[59] & 0xff),
    1199 +                             ((b[60] >> 8) & 0xff), (b[60] & 0xff),
    1200 +                             ((b[61] >> 8) & 0xff), (b[61] & 0xff),
    1201 +                             ((b[62] >> 8) & 0xff), (b[62] & 0xff));
    1202 +               vp++;
    1203 +       } else if (sromrev == 2) {
    1204 +               /* Word 60 OFDM tx power offset from CCK level */
    1205 +               /* OFDM Power Offset - opo */
    1206 +               vp += sprintf(vp, "opo=%d", b[60] & 0xff);
    1207 +               vp++;
    1208 +       } else {
    1209 +               /* Word 60: cck power offsets */
    1210 +               vp += sprintf(vp, "cckpo=%d", b[60]);
    1211 +               vp++;
    1212 +
    1213 +               /* Words 61+62: 11g ofdm power offsets */
    1214 +               w32 = ((uint32)b[62] << 16) | b[61];
    1215 +               vp += sprintf(vp, "ofdmgpo=%d", w32);
    1216 +               vp++;
    1217 +       }
    1218 +
    1219 +       /* final nullbyte terminator */
    1220 +done:  *vp++ = '\0';
    1221 +
    1222 +       ASSERT((vp - base) <= VARS_MAX);
    1223 +
    1224 +varsdone:
    1225 +       err = initvars_table(osh, base, vp, vars, count);
    1226 +
    1227 +err:
    1228 +#ifdef WLTEST
    1229 +       if (base != mfgsromvars)
    1230 +#endif
    1231 +               MFREE(osh, base, VARS_MAX);
    1232 +       MFREE(osh, b, SROM_MAX);
    1233 +       return err;
    1234 +}
    1235 +
    1236 +/*
    1237 + * Read the cis and call parsecis to initialize the vars.
    1238 + * Return 0 on success, nonzero on error.
    1239 + */
    1240 +static int
    1241 +initvars_cis_pcmcia(void *sbh, osl_t *osh, char **vars, uint *count)
    1242 +{
    1243 +       uint8 *cis = NULL;
    1244 +       int rc;
    1245 +       uint data_sz;
    1246 +
    1247 +       data_sz = (sb_pcmciarev(sbh) == 1) ? (SPROM_SIZE * 2) : CIS_SIZE;
    1248 +
    1249 +       if ((cis = MALLOC(osh, data_sz)) == NULL)
    1250 +               return (-2);
    1251 +
    1252 +       if (sb_pcmciarev(sbh) == 1) {
    1253 +               if (srom_read(PCMCIA_BUS, (void *)NULL, osh, 0, data_sz, (uint16 *)cis)) {
    1254 +                       MFREE(osh, cis, data_sz);
    1255 +                       return (-1);
    1256 +               }
    1257 +               /* fix up endianess for 16-bit data vs 8-bit parsing */
    1258 +               ltoh16_buf((uint16 *)cis, data_sz);
    1259 +       } else
    1260 +               OSL_PCMCIA_READ_ATTR(osh, 0, cis, data_sz);
    1261 +
    1262 +       rc = srom_parsecis(osh, &cis, 1, vars, count);
    1263 +
    1264 +       MFREE(osh, cis, data_sz);
    1265 +
    1266 +       return (rc);
    1267 +}
    1268 +
    1269 diff -urN linux.old/arch/mips/bcm947xx/bcmutils.c linux.dev/arch/mips/bcm947xx/bcmutils.c
    1270 --- linux.old/arch/mips/bcm947xx/bcmutils.c     1970-01-01 01:00:00.000000000 +0100
    1271 +++ linux.dev/arch/mips/bcm947xx/bcmutils.c     2006-04-28 00:34:02.000000000 +0200
    1272 @@ -0,0 +1,247 @@
    1273 +/*
    1274 + * Misc useful OS-independent routines.
    1275 + *
    1276 + * Copyright 2006, Broadcom Corporation
    1277 + * All Rights Reserved.
    1278 + *
    1279 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    1280 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    1281 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    1282 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    1283 + * $Id: bcmutils.c,v 1.1.1.12 2006/02/27 03:43:16 honor Exp $
    1284 + */
    1285 +
    1286 +#include <typedefs.h>
    1287 +#include <bcmdefs.h>
    1288 +#include <stdarg.h>
    1289 +#include <bcmutils.h>
    1290 +#include <osl.h>
    1291 +#include <sbutils.h>
    1292 +#include <bcmnvram.h>
    1293 +#include <bcmendian.h>
    1294 +#include <bcmdevs.h>
    1295 +
    1296 +unsigned char bcm_ctype[] = {
    1297 +       _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,                        /* 0-7 */
    1298 +       _BCM_C, _BCM_C|_BCM_S, _BCM_C|_BCM_S, _BCM_C|_BCM_S, _BCM_C|_BCM_S, _BCM_C|_BCM_S, _BCM_C,
    1299 +       _BCM_C, /* 8-15 */
    1300 +       _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,                        /* 16-23 */
    1301 +       _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,                        /* 24-31 */
    1302 +       _BCM_S|_BCM_SP,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,                /* 32-39 */
    1303 +       _BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,                        /* 40-47 */
    1304 +       _BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,                        /* 48-55 */
    1305 +       _BCM_D,_BCM_D,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,                        /* 56-63 */
    1306 +       _BCM_P, _BCM_U|_BCM_X, _BCM_U|_BCM_X, _BCM_U|_BCM_X, _BCM_U|_BCM_X, _BCM_U|_BCM_X,
    1307 +       _BCM_U|_BCM_X, _BCM_U, /* 64-71 */
    1308 +       _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,                        /* 72-79 */
    1309 +       _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,                        /* 80-87 */
    1310 +       _BCM_U,_BCM_U,_BCM_U,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,                        /* 88-95 */
    1311 +       _BCM_P, _BCM_L|_BCM_X, _BCM_L|_BCM_X, _BCM_L|_BCM_X, _BCM_L|_BCM_X, _BCM_L|_BCM_X,
    1312 +       _BCM_L|_BCM_X, _BCM_L, /* 96-103 */
    1313 +       _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L, /* 104-111 */
    1314 +       _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L, /* 112-119 */
    1315 +       _BCM_L,_BCM_L,_BCM_L,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_C, /* 120-127 */
    1316 +       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,         /* 128-143 */
    1317 +       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,         /* 144-159 */
    1318 +       _BCM_S|_BCM_SP, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P,
    1319 +       _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, /* 160-175 */
    1320 +       _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P,
    1321 +       _BCM_P, _BCM_P, _BCM_P, _BCM_P, _BCM_P, /* 176-191 */
    1322 +       _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U,
    1323 +       _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, /* 192-207 */
    1324 +       _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_P, _BCM_U, _BCM_U, _BCM_U,
    1325 +       _BCM_U, _BCM_U, _BCM_U, _BCM_U, _BCM_L, /* 208-223 */
    1326 +       _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L,
    1327 +       _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, /* 224-239 */
    1328 +       _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_P, _BCM_L, _BCM_L, _BCM_L,
    1329 +       _BCM_L, _BCM_L, _BCM_L, _BCM_L, _BCM_L /* 240-255 */
    1330 +};
    1331 +
    1332 +
    1333 +ulong
    1334 +bcm_strtoul(char *cp, char **endp, uint base)
    1335 +{
    1336 +       ulong result, value;
    1337 +       bool minus;
    1338 +
    1339 +       minus = FALSE;
    1340 +
    1341 +       while (bcm_isspace(*cp))
    1342 +               cp++;
    1343 +
    1344 +       if (cp[0] == '+')
    1345 +               cp++;
    1346 +       else if (cp[0] == '-') {
    1347 +               minus = TRUE;
    1348 +               cp++;
    1349 +       }
    1350 +
    1351 +       if (base == 0) {
    1352 +               if (cp[0] == '0') {
    1353 +                       if ((cp[1] == 'x') || (cp[1] == 'X')) {
    1354 +                               base = 16;
    1355 +                               cp = &cp[2];
    1356 +                       } else {
    1357 +                               base = 8;
    1358 +                               cp = &cp[1];
    1359 +                       }
    1360 +               } else
    1361 +                       base = 10;
    1362 +       } else if (base == 16 && (cp[0] == '0') && ((cp[1] == 'x') || (cp[1] == 'X'))) {
    1363 +               cp = &cp[2];
    1364 +       }
    1365 +
    1366 +       result = 0;
    1367 +
    1368 +       while (bcm_isxdigit(*cp) &&
    1369 +              (value = bcm_isdigit(*cp) ? *cp-'0' : bcm_toupper(*cp)-'A'+10) < base) {
    1370 +               result = result*base + value;
    1371 +               cp++;
    1372 +       }
    1373 +
    1374 +       if (minus)
    1375 +               result = (ulong)(result * -1);
    1376 +
    1377 +       if (endp)
    1378 +               *endp = (char *)cp;
    1379 +
    1380 +       return (result);
    1381 +}
    1382 +
    1383 +uchar
    1384 +bcm_toupper(uchar c)
    1385 +{
    1386 +       if (bcm_islower(c))
    1387 +               c -= 'a'-'A';
    1388 +       return (c);
    1389 +}
    1390 +
    1391 +char*
    1392 +bcm_ether_ntoa(struct ether_addr *ea, char *buf)
    1393 +{
    1394 +       sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
    1395 +               ea->octet[0]&0xff, ea->octet[1]&0xff, ea->octet[2]&0xff,
    1396 +               ea->octet[3]&0xff, ea->octet[4]&0xff, ea->octet[5]&0xff);
    1397 +       return (buf);
    1398 +}
    1399 +
    1400 +
    1401 +/*
    1402 + * Search the name=value vars for a specific one and return its value.
    1403 + * Returns NULL if not found.
    1404 + */
    1405 +char*
    1406 +getvar(char *vars, char *name)
    1407 +{
    1408 +       char *s;
    1409 +       int len;
    1410 +
    1411 +       len = strlen(name);
    1412 +
    1413 +       /* first look in vars[] */
    1414 +       for (s = vars; s && *s;) {
    1415 +               /* CSTYLED */
    1416 +               if ((memcmp(s, name, len) == 0) && (s[len] == '='))
    1417 +                       return (&s[len+1]);
    1418 +
    1419 +               while (*s++)
    1420 +                       ;
    1421 +       }
    1422 +
    1423 +       /* then query nvram */
    1424 +       return (nvram_get(name));
    1425 +}
    1426 +
    1427 +/*
    1428 + * Search the vars for a specific one and return its value as
    1429 + * an integer. Returns 0 if not found.
    1430 + */
    1431 +int
    1432 +getintvar(char *vars, char *name)
    1433 +{
    1434 +       char *val;
    1435 +
    1436 +       if ((val = getvar(vars, name)) == NULL)
    1437 +               return (0);
    1438 +
    1439 +       return (bcm_strtoul(val, NULL, 0));
    1440 +}
    1441 +
    1442 +
    1443 +/*******************************************************************************
    1444 + * crc8
    1445 + *
    1446 + * Computes a crc8 over the input data using the polynomial:
    1447 + *
    1448 + *       x^8 + x^7 +x^6 + x^4 + x^2 + 1
    1449 + *
    1450 + * The caller provides the initial value (either CRC8_INIT_VALUE
    1451 + * or the previous returned value) to allow for processing of
    1452 + * discontiguous blocks of data.  When generating the CRC the
    1453 + * caller is responsible for complementing the final return value
    1454 + * and inserting it into the byte stream.  When checking, a final
    1455 + * return value of CRC8_GOOD_VALUE indicates a valid CRC.
    1456 + *
    1457 + * Reference: Dallas Semiconductor Application Note 27
    1458 + *   Williams, Ross N., "A Painless Guide to CRC Error Detection Algorithms",
    1459 + *     ver 3, Aug 1993, ross@guest.adelaide.edu.au, Rocksoft Pty Ltd.,
    1460 + *     ftp://ftp.rocksoft.com/clients/rocksoft/papers/crc_v3.txt
    1461 + *
    1462 + * ****************************************************************************
    1463 + */
    1464 +
    1465 +static uint8 crc8_table[256] = {
    1466 +    0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
    1467 +    0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
    1468 +    0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
    1469 +    0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
    1470 +    0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
    1471 +    0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
    1472 +    0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
    1473 +    0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
    1474 +    0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
    1475 +    0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
    1476 +    0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
    1477 +    0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
    1478 +    0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
    1479 +    0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
    1480 +    0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
    1481 +    0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
    1482 +    0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
    1483 +    0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
    1484 +    0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
    1485 +    0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
    1486 +    0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
    1487 +    0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
    1488 +    0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
    1489 +    0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
    1490 +    0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
    1491 +    0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
    1492 +    0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
    1493 +    0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
    1494 +    0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
    1495 +    0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
    1496 +    0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
    1497 +    0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F
    1498 +};
    1499 +
    1500 +#define CRC_INNER_LOOP(n, c, x) \
    1501 +       (c) = ((c) >> 8) ^ crc##n##_table[((c) ^ (x)) & 0xff]
    1502 +
    1503 +uint8
    1504 +hndcrc8(
    1505 +       uint8 *pdata,   /* pointer to array of data to process */
    1506 +       uint  nbytes,   /* number of input data bytes to process */
    1507 +       uint8 crc       /* either CRC8_INIT_VALUE or previous return value */
    1508 +)
    1509 +{
    1510 +       /* hard code the crc loop instead of using CRC_INNER_LOOP macro
    1511 +        * to avoid the undefined and unnecessary (uint8 >> 8) operation.
    1512 +        */
    1513 +       while (nbytes-- > 0)
    1514 +               crc = crc8_table[(crc ^ *pdata++) & 0xff];
    1515 +
    1516 +       return crc;
    1517 +}
    1518 +
    1519 +
    1520 diff -urN linux.old/arch/mips/bcm947xx/cfe_env.c linux.dev/arch/mips/bcm947xx/cfe_env.c
    1521 --- linux.old/arch/mips/bcm947xx/cfe_env.c      1970-01-01 01:00:00.000000000 +0100
    1522 +++ linux.dev/arch/mips/bcm947xx/cfe_env.c      2006-04-27 19:24:19.000000000 +0200
    1523 @@ -0,0 +1,234 @@
    1524 +/*
    1525 + * NVRAM variable manipulation (Linux kernel half)
    1526 + *
    1527 + * Copyright 2001-2003, Broadcom Corporation
    1528 + * All Rights Reserved.
    1529 + *
    1530 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    1531 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    1532 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    1533 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    1534 + *
    1535 + * $Id$
    1536 + */
    1537 +
    1538 +#include <linux/config.h>
    1539 +#include <linux/init.h>
    1540 +#include <linux/module.h>
    1541 +#include <linux/kernel.h>
    1542 +#include <linux/string.h>
    1543 +#include <asm/io.h>
    1544 +#include <asm/uaccess.h>
    1545 +
    1546 +#include <typedefs.h>
    1547 +#include <osl.h>
    1548 +#include <bcmendian.h>
    1549 +#include <bcmutils.h>
    1550 +
    1551 +#define NVRAM_SIZE       (0x1ff0)
    1552 +static char _nvdata[NVRAM_SIZE] __initdata;
    1553 +static char _valuestr[256] __initdata;
    1554 +
    1555 +/*
    1556 + * TLV types.  These codes are used in the "type-length-value"
    1557 + * encoding of the items stored in the NVRAM device (flash or EEPROM)
    1558 + *
    1559 + * The layout of the flash/nvram is as follows:
    1560 + *
    1561 + * <type> <length> <data ...> <type> <length> <data ...> <type_end>
    1562 + *
    1563 + * The type code of "ENV_TLV_TYPE_END" marks the end of the list.
    1564 + * The "length" field marks the length of the data section, not
    1565 + * including the type and length fields.
    1566 + *
    1567 + * Environment variables are stored as follows:
    1568 + *
    1569 + * <type_env> <length> <flags> <name> = <value>
    1570 + *
    1571 + * If bit 0 (low bit) is set, the length is an 8-bit value.
    1572 + * If bit 0 (low bit) is clear, the length is a 16-bit value
    1573 + *
    1574 + * Bit 7 set indicates "user" TLVs.  In this case, bit 0 still
    1575 + * indicates the size of the length field. 
    1576 + *
    1577 + * Flags are from the constants below:
    1578 + *
    1579 + */
    1580 +#define ENV_LENGTH_16BITS      0x00    /* for low bit */
    1581 +#define ENV_LENGTH_8BITS       0x01
    1582 +
    1583 +#define ENV_TYPE_USER          0x80
    1584 +
    1585 +#define ENV_CODE_SYS(n,l) (((n)<<1)|(l))
    1586 +#define ENV_CODE_USER(n,l) ((((n)<<1)|(l)) | ENV_TYPE_USER)
    1587 +
    1588 +/*
    1589 + * The actual TLV types we support
    1590 + */
    1591 +
    1592 +#define ENV_TLV_TYPE_END       0x00   
    1593 +#define ENV_TLV_TYPE_ENV       ENV_CODE_SYS(0,ENV_LENGTH_8BITS)
    1594 +
    1595 +/*
    1596 + * Environment variable flags
    1597 + */
    1598 +
    1599 +#define ENV_FLG_NORMAL         0x00    /* normal read/write */
    1600 +#define ENV_FLG_BUILTIN                0x01    /* builtin - not stored in flash */
    1601 +#define ENV_FLG_READONLY       0x02    /* read-only - cannot be changed */
    1602 +
    1603 +#define ENV_FLG_MASK           0xFF    /* mask of attributes we keep */
    1604 +#define ENV_FLG_ADMIN          0x100   /* lets us internally override permissions */
    1605 +
    1606 +
    1607 +/*  *********************************************************************
    1608 +    *  _nvram_read(buffer,offset,length)
    1609 +    * 
    1610 +    *  Read data from the NVRAM device
    1611 +    * 
    1612 +    *  Input parameters:
    1613 +    *             buffer - destination buffer
    1614 +    *             offset - offset of data to read
    1615 +    *             length - number of bytes to read
    1616 +    *             
    1617 +    *  Return value:
    1618 +    *             number of bytes read, or <0 if error occured
    1619 +    ********************************************************************* */
    1620 +static int
    1621 +_nvram_read(unsigned char *nv_buf, unsigned char *buffer, int offset, int length)
    1622 +{
    1623 +    int i;
    1624 +    if (offset > NVRAM_SIZE)
    1625 +       return -1;
    1626 +
    1627 +    for ( i = 0; i < length; i++) {
    1628 +       buffer[i] = ((volatile unsigned char*)nv_buf)[offset + i];
    1629 +    }
    1630 +    return length;
    1631 +}
    1632 +
    1633 +
    1634 +static char*
    1635 +_strnchr(const char *dest,int c,size_t cnt)
    1636 +{
    1637 +       while (*dest && (cnt > 0)) {
    1638 +       if (*dest == c) return (char *) dest;
    1639 +       dest++;
    1640 +       cnt--;
    1641 +       }
    1642 +       return NULL;
    1643 +}
    1644 +
    1645 +
    1646 +
    1647 +/*
    1648 + * Core support API: Externally visible.
    1649 + */
    1650 +
    1651 +/*
    1652 + * Get the value of an NVRAM variable
    1653 + * @param      name    name of variable to get
    1654 + * @return     value of variable or NULL if undefined
    1655 + */
    1656 +
    1657 +char*
    1658 +cfe_env_get(unsigned char *nv_buf, char* name)
    1659 +{
    1660 +    int size;
    1661 +    unsigned char *buffer;
    1662 +    unsigned char *ptr;
    1663 +    unsigned char *envval;
    1664 +    unsigned int reclen;
    1665 +    unsigned int rectype;
    1666 +    int offset;
    1667 +    int flg;
    1668 +   
    1669 +    size = NVRAM_SIZE;
    1670 +    buffer = &_nvdata[0];
    1671 +
    1672 +    ptr = buffer;
    1673 +    offset = 0;
    1674 +
    1675 +    /* Read the record type and length */
    1676 +    if (_nvram_read(nv_buf, ptr,offset,1) != 1) {
    1677 +       goto error;
    1678 +    }
    1679 +   
    1680 +    while ((*ptr != ENV_TLV_TYPE_END)  && (size > 1)) {
    1681 +
    1682 +       /* Adjust pointer for TLV type */
    1683 +       rectype = *(ptr);
    1684 +       offset++;
    1685 +       size--;
    1686 +
    1687 +       /*
    1688 +        * Read the length.  It can be either 1 or 2 bytes
    1689 +        * depending on the code
    1690 +        */
    1691 +       if (rectype & ENV_LENGTH_8BITS) {
    1692 +           /* Read the record type and length - 8 bits */
    1693 +           if (_nvram_read(nv_buf, ptr,offset,1) != 1) {
    1694 +               goto error;
    1695 +           }
    1696 +           reclen = *(ptr);
    1697 +           size--;
    1698 +           offset++;
    1699 +       }
    1700 +       else {
    1701 +           /* Read the record type and length - 16 bits, MSB first */
    1702 +           if (_nvram_read(nv_buf, ptr,offset,2) != 2) {
    1703 +               goto error;
    1704 +           }
    1705 +           reclen = (((unsigned int) *(ptr)) << 8) + (unsigned int) *(ptr+1);
    1706 +           size -= 2;
    1707 +           offset += 2;
    1708 +       }
    1709 +
    1710 +       if (reclen > size)
    1711 +           break;      /* should not happen, bad NVRAM */
    1712 +
    1713 +       switch (rectype) {
    1714 +           case ENV_TLV_TYPE_ENV:
    1715 +               /* Read the TLV data */
    1716 +               if (_nvram_read(nv_buf, ptr,offset,reclen) != reclen)
    1717 +                   goto error;
    1718 +               flg = *ptr++;
    1719 +               envval = (unsigned char *) _strnchr(ptr,'=',(reclen-1));
    1720 +               if (envval) {
    1721 +                   *envval++ = '\0';
    1722 +                   memcpy(_valuestr,envval,(reclen-1)-(envval-ptr));
    1723 +                   _valuestr[(reclen-1)-(envval-ptr)] = '\0';
    1724 +#if 0                 
    1725 +                   printk(KERN_INFO "NVRAM:%s=%s\n", ptr, _valuestr);
    1726 +#endif
    1727 +                   if(!strcmp(ptr, name)){
    1728 +                       return _valuestr;
    1729 +                   }
    1730 +                   if((strlen(ptr) > 1) && !strcmp(&ptr[1], name))
    1731 +                       return _valuestr;
    1732 +               }
    1733 +               break;
    1734 +               
    1735 +           default:
    1736 +               /* Unknown TLV type, skip it. */
    1737 +               break;
    1738 +           }
    1739 +
    1740 +       /*
    1741 +        * Advance to next TLV
    1742 +        */
    1743 +               
    1744 +       size -= (int)reclen;
    1745 +       offset += reclen;
    1746 +
    1747 +       /* Read the next record type */
    1748 +       ptr = buffer;
    1749 +       if (_nvram_read(nv_buf, ptr,offset,1) != 1)
    1750 +           goto error;
    1751 +       }
    1752 +
    1753 +error:
    1754 +    return NULL;
    1755 +
    1756 +}
    1757 +
    1758 diff -urN linux.old/arch/mips/bcm947xx/compressed/Makefile linux.dev/arch/mips/bcm947xx/compressed/Makefile
    1759 --- linux.old/arch/mips/bcm947xx/compressed/Makefile    1970-01-01 01:00:00.000000000 +0100
    1760 +++ linux.dev/arch/mips/bcm947xx/compressed/Makefile    2006-04-27 19:24:19.000000000 +0200
     51diff -Nur linux-2.4.32/arch/mips/bcm947xx/compressed/Makefile linux-2.4.32-freewrt/arch/mips/bcm947xx/compressed/Makefile
     52--- linux-2.4.32/arch/mips/bcm947xx/compressed/Makefile 1970-01-01 01:00:00.000000000 +0100
     53+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/compressed/Makefile 2006-07-02 21:58:25.000000000 +0200
    176154@@ -0,0 +1,33 @@
    176255+#
     
    179386+clean:
    179487+       rm -f vmlinuz piggy
    1795 diff -urN linux.old/arch/mips/bcm947xx/export.c linux.dev/arch/mips/bcm947xx/export.c
    1796 --- linux.old/arch/mips/bcm947xx/export.c       1970-01-01 01:00:00.000000000 +0100
    1797 +++ linux.dev/arch/mips/bcm947xx/export.c       2006-04-28 02:57:34.000000000 +0200
    1798 @@ -0,0 +1,62 @@
    1799 +#include <linux/module.h>
    1800 +
    1801 +#define _export(n) \
    1802 +               void n(void); \
    1803 +               EXPORT_SYMBOL(n);
    1804 +
    1805 +_export(bcm947xx_sbh)
    1806 +
    1807 +_export(sb_attach)
    1808 +_export(sb_boardtype)
    1809 +_export(sb_boardvendor)
    1810 +_export(sb_btcgpiowar)
    1811 +_export(sb_bus)
    1812 +_export(sb_chip)
    1813 +_export(sb_chiprev)
    1814 +_export(sb_chipcrev)
    1815 +_export(sb_chippkg)
    1816 +_export(sb_clkctl_clk)
    1817 +_export(sb_clkctl_fast_pwrup_delay)
    1818 +_export(sb_clkctl_init)
    1819 +_export(sb_clkctl_xtal)
    1820 +_export(sb_core_disable)
    1821 +_export(sb_core_reset)
    1822 +_export(sb_core_tofixup)
    1823 +_export(sb_coreflags)
    1824 +_export(sb_coreflagshi)
    1825 +_export(sb_coreidx)
    1826 +_export(sb_corerev)
    1827 +_export(sb_coreunit)
    1828 +_export(sb_detach)
    1829 +_export(sb_deviceremoved)
    1830 +_export(sb_gpiocontrol)
    1831 +_export(sb_gpioled)
    1832 +_export(sb_gpioin)
    1833 +_export(sb_gpioout)
    1834 +_export(sb_gpioouten)
    1835 +_export(sb_gpiotimerval)
    1836 +_export(sb_iscoreup)
    1837 +_export(sb_pci_setup)
    1838 +_export(sb_pcirev)
    1839 +_export(sb_pcmcia_init)
    1840 +_export(sb_pcmciarev)
    1841 +_export(sb_register_intr_callback)
    1842 +_export(sb_setcore)
    1843 +_export(sb_war16165)
    1844 +_export(sb_osh)
    1845 +               
    1846 +_export(getvar)
    1847 +_export(getintvar)
    1848 +_export(bcm_strtoul)
    1849 +_export(bcm_ctype)
    1850 +_export(bcm_toupper)
    1851 +_export(bcm_ether_ntoa)
    1852 +
    1853 +_export(nvram_get)
    1854 +_export(nvram_getall)
    1855 +_export(nvram_set)
    1856 +_export(nvram_unset)
    1857 +_export(nvram_commit)
    1858 +
    1859 +_export(srom_read)
    1860 +_export(srom_write)
    1861 diff -urN linux.old/arch/mips/bcm947xx/generic/Makefile linux.dev/arch/mips/bcm947xx/generic/Makefile
    1862 --- linux.old/arch/mips/bcm947xx/generic/Makefile       1970-01-01 01:00:00.000000000 +0100
    1863 +++ linux.dev/arch/mips/bcm947xx/generic/Makefile       2006-04-27 19:24:19.000000000 +0200
     88diff -Nur linux-2.4.32/arch/mips/bcm947xx/generic/Makefile linux-2.4.32-freewrt/arch/mips/bcm947xx/generic/Makefile
     89--- linux-2.4.32/arch/mips/bcm947xx/generic/Makefile    1970-01-01 01:00:00.000000000 +0100
     90+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/generic/Makefile    2006-07-02 21:58:25.000000000 +0200
    186491@@ -0,0 +1,15 @@
    186592+#
     
    1878105+
    1879106+include $(TOPDIR)/Rules.make
    1880 diff -urN linux.old/arch/mips/bcm947xx/generic/int-handler.S linux.dev/arch/mips/bcm947xx/generic/int-handler.S
    1881 --- linux.old/arch/mips/bcm947xx/generic/int-handler.S  1970-01-01 01:00:00.000000000 +0100
    1882 +++ linux.dev/arch/mips/bcm947xx/generic/int-handler.S  2006-04-27 19:24:19.000000000 +0200
     107diff -Nur linux-2.4.32/arch/mips/bcm947xx/generic/int-handler.S linux-2.4.32-freewrt/arch/mips/bcm947xx/generic/int-handler.S
     108--- linux-2.4.32/arch/mips/bcm947xx/generic/int-handler.S       1970-01-01 01:00:00.000000000 +0100
     109+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/generic/int-handler.S       2006-07-02 21:58:25.000000000 +0200
    1883110@@ -0,0 +1,51 @@
    1884111+/*
     
    1933160+               
    1934161+       END(brcmIRQ)
    1935 diff -urN linux.old/arch/mips/bcm947xx/generic/irq.c linux.dev/arch/mips/bcm947xx/generic/irq.c
    1936 --- linux.old/arch/mips/bcm947xx/generic/irq.c  1970-01-01 01:00:00.000000000 +0100
    1937 +++ linux.dev/arch/mips/bcm947xx/generic/irq.c  2006-04-27 19:24:19.000000000 +0200
     162diff -Nur linux-2.4.32/arch/mips/bcm947xx/generic/irq.c linux-2.4.32-freewrt/arch/mips/bcm947xx/generic/irq.c
     163--- linux-2.4.32/arch/mips/bcm947xx/generic/irq.c       1970-01-01 01:00:00.000000000 +0100
     164+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/generic/irq.c       2006-07-02 21:58:25.000000000 +0200
    1938165@@ -0,0 +1,130 @@
    1939166+/*
     
    2067294+#endif
    2068295+}
    2069 diff -urN linux.old/arch/mips/bcm947xx/gpio.c linux.dev/arch/mips/bcm947xx/gpio.c
    2070 --- linux.old/arch/mips/bcm947xx/gpio.c 1970-01-01 01:00:00.000000000 +0100
    2071 +++ linux.dev/arch/mips/bcm947xx/gpio.c 2006-04-27 23:09:33.000000000 +0200
    2072 @@ -0,0 +1,159 @@
     296diff -Nur linux-2.4.32/arch/mips/bcm947xx/gpio.c linux-2.4.32-freewrt/arch/mips/bcm947xx/gpio.c
     297--- linux-2.4.32/arch/mips/bcm947xx/gpio.c      1970-01-01 01:00:00.000000000 +0100
     298+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/gpio.c      2006-07-02 21:58:25.000000000 +0200
     299@@ -0,0 +1,158 @@
    2073300+/*
    2074301+ * GPIO char driver
    2075302+ *
    2076 + * Copyright 2005, Broadcom Corporation
     303+ * Copyright 2004, Broadcom Corporation
    2077304+ * All Rights Reserved.
    2078305+ *
     
    2082309+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    2083310+ *
    2084 + * $Id$
     311+ * $Id: gpio.c,v 1.1 2005/03/16 13:49:59 wbx Exp $
    2085312+ */
    2086313+
     
    2092319+
    2093320+#include <typedefs.h>
    2094 +#include <osl.h>
    2095321+#include <bcmutils.h>
    2096322+#include <sbutils.h>
    2097323+#include <bcmdevs.h>
    2098324+
    2099 +static sb_t *gpio_sbh;
     325+static void *gpio_sbh;
    2100326+static int gpio_major;
    2101327+static devfs_handle_t gpio_dir;
     
    2137363+               break;
    2138364+       case 1:
    2139 +               val = sb_gpioout(gpio_sbh, 0, 0, GPIO_DRV_PRIORITY);
     365+               val = sb_gpioout(gpio_sbh, 0, 0);
    2140366+               break;
    2141367+       case 2:
    2142 +               val = sb_gpioouten(gpio_sbh, 0, 0, GPIO_DRV_PRIORITY);
     368+               val = sb_gpioouten(gpio_sbh, 0, 0);
    2143369+               break;
    2144370+       case 3:
    2145 +               val = sb_gpiocontrol(gpio_sbh, 0, 0, GPIO_DRV_PRIORITY);
     371+               val = sb_gpiocontrol(gpio_sbh, 0, 0);
    2146372+               break;
    2147373+       default:
     
    2167393+               return -EACCES;
    2168394+       case 1:
    2169 +               sb_gpioout(gpio_sbh, ~0, val, GPIO_DRV_PRIORITY);
     395+               sb_gpioout(gpio_sbh, ~0, val);
    2170396+               break;
    2171397+       case 2:
    2172 +               sb_gpioouten(gpio_sbh, ~0, val, GPIO_DRV_PRIORITY);
     398+               sb_gpioouten(gpio_sbh, ~0, val);
    2173399+               break;
    2174400+       case 3:
    2175 +               sb_gpiocontrol(gpio_sbh, ~0, val, GPIO_DRV_PRIORITY);
     401+               sb_gpiocontrol(gpio_sbh, ~0, val);
    2176402+               break;
    2177403+       default:
     
    2209435+                                                    gpio_file[i].name,
    2210436+                                                    DEVFS_FL_DEFAULT, gpio_major, i,
    2211 +                                                    S_IFCHR | S_IRUGO | S_IWUGO,
     437+                                                    S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP,
    2212438+                                                    &gpio_fops, NULL);
    2213439+       }
     
    2230456+module_init(gpio_init);
    2231457+module_exit(gpio_exit);
    2232 diff -urN linux.old/arch/mips/bcm947xx/hndchipc.c linux.dev/arch/mips/bcm947xx/hndchipc.c
    2233 --- linux.old/arch/mips/bcm947xx/hndchipc.c     1970-01-01 01:00:00.000000000 +0100
    2234 +++ linux.dev/arch/mips/bcm947xx/hndchipc.c     2006-04-28 00:33:05.000000000 +0200
    2235 @@ -0,0 +1,158 @@
     458diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/bcmdevs.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmdevs.h
     459--- linux-2.4.32/arch/mips/bcm947xx/include/bcmdevs.h   1970-01-01 01:00:00.000000000 +0100
     460+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmdevs.h   2006-07-02 21:58:25.000000000 +0200
     461@@ -0,0 +1,369 @@
    2236462+/*
    2237 + * BCM47XX support code for some chipcommon (old extif) facilities (uart)
     463+ * Broadcom device-specific manifest constants.
    2238464+ *
    2239 + * Copyright 2006, Broadcom Corporation
    2240 + * All Rights Reserved.
    2241 + *
    2242 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    2243 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    2244 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    2245 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    2246 + *
    2247 + * $Id: hndchipc.c,v 1.1.1.1 2006/02/27 03:43:16 honor Exp $
    2248 + */
    2249 +
    2250 +#include <typedefs.h>
    2251 +#include <bcmdefs.h>
    2252 +#include <osl.h>
    2253 +#include <bcmutils.h>
    2254 +#include <sbutils.h>
    2255 +#include <bcmdevs.h>
    2256 +#include <bcmnvram.h>
    2257 +#include <sbconfig.h>
    2258 +#include <sbextif.h>
    2259 +#include <sbchipc.h>
    2260 +#include <hndcpu.h>
    2261 +
    2262 +/*
    2263 + * Returns TRUE if an external UART exists at the given base
    2264 + * register.
    2265 + */
    2266 +static bool
    2267 +BCMINITFN(serial_exists)(osl_t *osh, uint8 *regs)
    2268 +{
    2269 +       uint8 save_mcr, status1;
    2270 +
    2271 +       save_mcr = R_REG(osh, &regs[UART_MCR]);
    2272 +       W_REG(osh, &regs[UART_MCR], UART_MCR_LOOP | 0x0a);
    2273 +       status1 = R_REG(osh, &regs[UART_MSR]) & 0xf0;
    2274 +       W_REG(osh, &regs[UART_MCR], save_mcr);
    2275 +
    2276 +       return (status1 == 0x90);
    2277 +}
    2278 +
    2279 +/*
    2280 + * Initializes UART access. The callback function will be called once
    2281 + * per found UART.
    2282 + */
    2283 +void
    2284 +BCMINITFN(sb_serial_init)(sb_t *sbh, void (*add)(void *regs, uint irq, uint baud_base,
    2285 +                                                 uint reg_shift))
    2286 +{
    2287 +       osl_t *osh;
    2288 +       void *regs;
    2289 +       ulong base;
    2290 +       uint irq;
    2291 +       int i, n;
    2292 +
    2293 +       osh = sb_osh(sbh);
    2294 +
    2295 +       if ((regs = sb_setcore(sbh, SB_EXTIF, 0))) {
    2296 +               extifregs_t *eir = (extifregs_t *) regs;
    2297 +               sbconfig_t *sb;
    2298 +
    2299 +               /* Determine external UART register base */
    2300 +               sb = (sbconfig_t *)((ulong) eir + SBCONFIGOFF);
    2301 +               base = EXTIF_CFGIF_BASE(sb_base(R_REG(osh, &sb->sbadmatch1)));
    2302 +
    2303 +               /* Determine IRQ */
    2304 +               irq = sb_irq(sbh);
    2305 +
    2306 +               /* Disable GPIO interrupt initially */
    2307 +               W_REG(osh, &eir->gpiointpolarity, 0);
    2308 +               W_REG(osh, &eir->gpiointmask, 0);
    2309 +
    2310 +               /* Search for external UARTs */
    2311 +               n = 2;
    2312 +               for (i = 0; i < 2; i++) {
    2313 +                       regs = (void *) REG_MAP(base + (i * 8), 8);
    2314 +                       if (serial_exists(osh, regs)) {
    2315 +                               /* Set GPIO 1 to be the external UART IRQ */
    2316 +                               W_REG(osh, &eir->gpiointmask, 2);
    2317 +                               /* XXXDetermine external UART clock */
    2318 +                               if (add)
    2319 +                                       add(regs, irq, 13500000, 0);
    2320 +                       }
    2321 +               }
    2322 +
    2323 +               /* Add internal UART if enabled */
    2324 +               if (R_REG(osh, &eir->corecontrol) & CC_UE)
    2325 +                       if (add)
    2326 +                               add((void *) &eir->uartdata, irq, sb_clock(sbh), 2);
    2327 +       } else if ((regs = sb_setcore(sbh, SB_CC, 0))) {
    2328 +               chipcregs_t *cc = (chipcregs_t *) regs;
    2329 +               uint32 rev, cap, pll, baud_base, div;
    2330 +
    2331 +               /* Determine core revision and capabilities */
    2332 +               rev = sb_corerev(sbh);
    2333 +               cap = R_REG(osh, &cc->capabilities);
    2334 +               pll = cap & CAP_PLL_MASK;
    2335 +
    2336 +               /* Determine IRQ */
    2337 +               irq = sb_irq(sbh);
    2338 +
    2339 +               if (pll == PLL_TYPE1) {
    2340 +                       /* PLL clock */
    2341 +                       baud_base = sb_clock_rate(pll,
    2342 +                                                 R_REG(osh, &cc->clockcontrol_n),
    2343 +                                                 R_REG(osh, &cc->clockcontrol_m2));
    2344 +                       div = 1;
    2345 +               } else {
    2346 +                       /* Fixed ALP clock */
    2347 +                       if (rev >= 11 && rev != 15) {
    2348 +                               baud_base = 20000000;
    2349 +                               div = 1;
    2350 +                               /* Set the override bit so we don't divide it */
    2351 +                               W_REG(osh, &cc->corecontrol, CC_UARTCLKO);
    2352 +                       }
    2353 +                       /* Internal backplane clock */
    2354 +                       else if (rev >= 3) {
    2355 +                               baud_base = sb_clock(sbh);
    2356 +                               div = 2;        /* Minimum divisor */
    2357 +                               W_REG(osh, &cc->clkdiv,
    2358 +                                     ((R_REG(osh, &cc->clkdiv) & ~CLKD_UART) | div));
    2359 +                       }
    2360 +                       /* Fixed internal backplane clock */
    2361 +                       else {
    2362 +                               baud_base = 88000000;
    2363 +                               div = 48;
    2364 +                       }
    2365 +
    2366 +                       /* Clock source depends on strapping if UartClkOverride is unset */
    2367 +                       if ((rev > 0) &&
    2368 +                           ((R_REG(osh, &cc->corecontrol) & CC_UARTCLKO) == 0)) {
    2369 +                               if ((cap & CAP_UCLKSEL) == CAP_UINTCLK) {
    2370 +                                       /* Internal divided backplane clock */
    2371 +                                       baud_base /= div;
    2372 +                               } else {
    2373 +                                       /* Assume external clock of 1.8432 MHz */
    2374 +                                       baud_base = 1843200;
    2375 +                               }
    2376 +                       }
    2377 +               }
    2378 +
    2379 +               /* Add internal UARTs */
    2380 +               n = cap & CAP_UARTS_MASK;
    2381 +               for (i = 0; i < n; i++) {
    2382 +                       /* Register offset changed after revision 0 */
    2383 +                       if (rev)
    2384 +                               regs = (void *)((ulong) &cc->uart0data + (i * 256));
    2385 +                       else
    2386 +                               regs = (void *)((ulong) &cc->uart0data + (i * 8));
    2387 +
    2388 +                       if (add)
    2389 +                               add(regs, irq, baud_base, 0);
    2390 +               }
    2391 +       }
    2392 +}
    2393 +
    2394 diff -urN linux.old/arch/mips/bcm947xx/include/bcm4710.h linux.dev/arch/mips/bcm947xx/include/bcm4710.h
    2395 --- linux.old/arch/mips/bcm947xx/include/bcm4710.h      1970-01-01 01:00:00.000000000 +0100
    2396 +++ linux.dev/arch/mips/bcm947xx/include/bcm4710.h      2006-04-27 22:30:01.000000000 +0200
    2397 @@ -0,0 +1,91 @@
    2398 +/*
    2399 + * BCM4710 address space map and definitions
    2400 + * Think twice before adding to this file, this is not the kitchen sink
    2401 + * These definitions are not guaranteed for all 47xx chips, only the 4710
    2402 + *
    2403 + * Copyright 2004, Broadcom Corporation   
     465+ * Copyright 2005, Broadcom Corporation   
    2404466+ * All Rights Reserved.   
    2405467+ *   
     
    2408470+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS   
    2409471+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.   
    2410 + *
    2411 + * $Id: bcm4710.h,v 1.3 2004/09/27 07:23:30 tallest Exp $
    2412 + */
    2413 +
    2414 +#ifndef _bcm4710_h_
    2415 +#define _bcm4710_h_
    2416 +
    2417 +/* Address map */
    2418 +#define BCM4710_SDRAM          0x00000000      /* Physical SDRAM */
    2419 +#define BCM4710_PCI_MEM                0x08000000      /* Host Mode PCI memory access space (64 MB) */
    2420 +#define BCM4710_PCI_CFG                0x0c000000      /* Host Mode PCI configuration space (64 MB) */
    2421 +#define BCM4710_PCI_DMA                0x40000000      /* Client Mode PCI memory access space (1 GB) */
    2422 +#define        BCM4710_SDRAM_SWAPPED   0x10000000      /* Byteswapped Physical SDRAM */
    2423 +#define BCM4710_ENUM           0x18000000      /* Beginning of core enumeration space */
    2424 +
    2425 +/* Core register space */
    2426 +#define BCM4710_REG_SDRAM      0x18000000      /* SDRAM core registers */
    2427 +#define BCM4710_REG_ILINE20    0x18001000      /* InsideLine20 core registers */
    2428 +#define BCM4710_REG_EMAC0      0x18002000      /* Ethernet MAC 0 core registers */
    2429 +#define BCM4710_REG_CODEC      0x18003000      /* Codec core registers */
    2430 +#define BCM4710_REG_USB                0x18004000      /* USB core registers */
    2431 +#define BCM4710_REG_PCI                0x18005000      /* PCI core registers */
    2432 +#define BCM4710_REG_MIPS       0x18006000      /* MIPS core registers */
    2433 +#define BCM4710_REG_EXTIF      0x18007000      /* External Interface core registers */
    2434 +#define BCM4710_REG_EMAC1      0x18008000      /* Ethernet MAC 1 core registers */
    2435 +
    2436 +#define        BCM4710_EXTIF           0x1f000000      /* External Interface base address */
    2437 +#define BCM4710_PCMCIA_MEM     0x1f000000      /* External Interface PCMCIA memory access */
    2438 +#define BCM4710_PCMCIA_IO      0x1f100000      /* PCMCIA I/O access */
    2439 +#define BCM4710_PCMCIA_CONF    0x1f200000      /* PCMCIA configuration */
    2440 +#define BCM4710_PROG           0x1f800000      /* Programable interface */
    2441 +#define BCM4710_FLASH          0x1fc00000      /* Flash */
    2442 +
    2443 +#define        BCM4710_EJTAG           0xff200000      /* MIPS EJTAG space (2M) */
    2444 +
    2445 +#define        BCM4710_UART            (BCM4710_REG_EXTIF + 0x00000300)
    2446 +
    2447 +#define        BCM4710_EUART           (BCM4710_EXTIF + 0x00800000)
    2448 +#define        BCM4710_LED             (BCM4710_EXTIF + 0x00900000)
    2449 +
    2450 +#define        SBFLAG_PCI      0
    2451 +#define        SBFLAG_ENET0    1
    2452 +#define        SBFLAG_ILINE20  2
    2453 +#define        SBFLAG_CODEC    3
    2454 +#define        SBFLAG_USB      4
    2455 +#define        SBFLAG_EXTIF    5
    2456 +#define        SBFLAG_ENET1    6
    2457 +
    2458 +#ifdef CONFIG_HWSIM
    2459 +#define        BCM4710_TRACE(trval)        do { *((int *)0xa0000f18) = (trval); } while (0)
    2460 +#else
    2461 +#define        BCM4710_TRACE(trval)
    2462 +#endif
    2463 +
    2464 +
    2465 +/* BCM94702 CPCI -ExtIF used for LocalBus devs */
    2466 +
    2467 +#define BCM94702_CPCI_RESET_ADDR        BCM4710_EXTIF
    2468 +#define BCM94702_CPCI_BOARDID_ADDR     (BCM4710_EXTIF | 0x4000)
    2469 +#define BCM94702_CPCI_DOC_ADDR         (BCM4710_EXTIF | 0x6000)
    2470 +#define BCM94702_DOC_ADDR                BCM94702_CPCI_DOC_ADDR
    2471 +#define BCM94702_CPCI_LED_ADDR         (BCM4710_EXTIF | 0xc000)
    2472 +#define BCM94702_CPCI_NVRAM_ADDR       (BCM4710_EXTIF | 0xe000)
    2473 +#define BCM94702_CPCI_NVRAM_SIZE         0x1ff0 /* 8K NVRAM : DS1743/STM48txx*/
    2474 +#define BCM94702_CPCI_TOD_REG_BASE       (BCM94702_CPCI_NVRAM_ADDR | 0x1ff0)
    2475 +
    2476 +#define LED_REG(x)      \
    2477 + (*(volatile unsigned char *) (KSEG1ADDR(BCM94702_CPCI_LED_ADDR) + (x)))
    2478 +
    2479 +/*
    2480 + * Reset function implemented in PLD.  Read or write should trigger hard reset
    2481 + */
    2482 +#define SYS_HARD_RESET()   \
    2483 +    { for (;;) \
    2484 +     *( (volatile unsigned char *)\
    2485 +      KSEG1ADDR(BCM94702_CPCI_RESET_ADDR) ) = 0x80; \
    2486 +    }
    2487 +
    2488 +#endif /* _bcm4710_h_ */
    2489 diff -urN linux.old/arch/mips/bcm947xx/include/bcmdefs.h linux.dev/arch/mips/bcm947xx/include/bcmdefs.h
    2490 --- linux.old/arch/mips/bcm947xx/include/bcmdefs.h      1970-01-01 01:00:00.000000000 +0100
    2491 +++ linux.dev/arch/mips/bcm947xx/include/bcmdefs.h      2006-04-27 20:12:21.000000000 +0200
    2492 @@ -0,0 +1,106 @@
    2493 +/*
    2494 + * Misc system wide definitions
    2495 + *
    2496 + * Copyright 2006, Broadcom Corporation
    2497 + * All Rights Reserved.
    2498 + *
    2499 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    2500 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    2501 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    2502 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    2503 + * $Id: bcmdefs.h,v 1.1.1.3 2006/04/08 06:13:39 honor Exp $
    2504 + */
    2505 +
    2506 +#ifndef        _bcmdefs_h_
    2507 +#define        _bcmdefs_h_
    2508 +
    2509 +/*
    2510 + * One doesn't need to include this file explicitly, gets included automatically if
    2511 + * typedefs.h is included.
    2512 + */
    2513 +
    2514 +/* Reclaiming text and data :
    2515 + * The following macros specify special linker sections that can be reclaimed
    2516 + * after a system is considered 'up'.
    2517 + */
    2518 +#if defined(__GNUC__) && defined(BCMRECLAIM)
    2519 +extern bool    bcmreclaimed;
    2520 +#define BCMINITDATA(_data)     __attribute__ ((__section__ (".dataini." #_data))) _data
    2521 +#define BCMINITFN(_fn)         __attribute__ ((__section__ (".textini." #_fn))) _fn
    2522 +#else /* #if defined(__GNUC__) && defined(BCMRECLAIM) */
    2523 +#define BCMINITDATA(_data)     _data
    2524 +#define BCMINITFN(_fn)         _fn
    2525 +#define bcmreclaimed           0
    2526 +#endif /* #if defined(__GNUC__) && defined(BCMRECLAIM) */
    2527 +
    2528 +/* Reclaim uninit functions if BCMNODOWN is defined            */
    2529 +/* and if they are not already removed by -gc-sections */
    2530 +#ifdef BCMNODOWN
    2531 +#define BCMUNINITFN(_fn)               BCMINITFN(_fn)
    2532 +#else
    2533 +#define BCMUNINITFN(_fn)               _fn
    2534 +#endif
    2535 +
    2536 +#ifdef BCMRECLAIM
    2537 +#define CONST
    2538 +#else
    2539 +#define CONST  const
    2540 +#endif /* BCMRECLAIM */
    2541 +
    2542 +/* Compatibility with old-style BCMRECLAIM */
    2543 +#define BCMINIT(_id)           _id
    2544 +
    2545 +
    2546 +/* Put some library data/code into ROM to reduce RAM requirements */
    2547 +#if defined(__GNUC__) && defined(BCMROMOFFLOAD)
    2548 +#define BCMROMDATA(_data)      __attribute__ ((__section__ (".datarom." #_data))) _data
    2549 +#define BCMROMFN(_fn)          __attribute__ ((__section__ (".textrom." #_fn))) _fn
    2550 +#else
    2551 +#define BCMROMDATA(_data)      _data
    2552 +#define BCMROMFN(_fn)          _fn
    2553 +#endif
    2554 +
    2555 +/* Bus types */
    2556 +#define        SB_BUS                  0       /* Silicon Backplane */
    2557 +#define        PCI_BUS                 1       /* PCI target */
    2558 +#define        PCMCIA_BUS              2       /* PCMCIA target */
    2559 +#define SDIO_BUS               3       /* SDIO target */
    2560 +#define JTAG_BUS               4       /* JTAG */
    2561 +#define NO_BUS                 0xFF    /* Bus that does not support R/W REG */
    2562 +
    2563 +/* Allows optimization for single-bus support */
    2564 +#ifdef BCMBUSTYPE
    2565 +#define BUSTYPE(bus) (BCMBUSTYPE)
    2566 +#else
    2567 +#define BUSTYPE(bus) (bus)
    2568 +#endif
    2569 +
    2570 +/* Defines for DMA Address Width - Shared between OSL and HNDDMA */
    2571 +#define DMADDR_MASK_32 0x0             /* Address mask for 32-bits */
    2572 +#define DMADDR_MASK_30 0xc0000000      /* Address mask for 30-bits */
    2573 +#define DMADDR_MASK_0  0xffffffff      /* Address mask for 0-bits (hi-part) */
    2574 +
    2575 +#define        DMADDRWIDTH_30  30 /* 30-bit addressing capability */
    2576 +#define        DMADDRWIDTH_32  32 /* 32-bit addressing capability */
    2577 +#define        DMADDRWIDTH_63  63 /* 64-bit addressing capability */
    2578 +#define        DMADDRWIDTH_64  64 /* 64-bit addressing capability */
    2579 +
    2580 +/* packet headroom necessary to accomodate the largest header in the system, (i.e TXOFF).
    2581 + * By doing, we avoid the need  to allocate an extra buffer for the header when bridging to WL.
    2582 + * There is a compile time check in wlc.c which ensure that this value is at least as big
    2583 + * as TXOFF. This value is used in dma_rxfill (hnddma.c).
    2584 + */
    2585 +#define BCMEXTRAHDROOM 160
    2586 +
    2587 +/* Headroom required for dongle-to-host communication.  Packets allocated
    2588 + * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should
    2589 + * leave this much room in front for low-level message headers which may
    2590 + * be needed to get across the dongle bus to the host.  (These messages
    2591 + * don't go over the network, so room for the full WL header above would
    2592 + * be a waste.)
    2593 + */
    2594 +#define BCMDONGLEHDRSZ 8
    2595 +
    2596 +
    2597 +
    2598 +#endif /* _bcmdefs_h_ */
    2599 diff -urN linux.old/arch/mips/bcm947xx/include/bcmdevs.h linux.dev/arch/mips/bcm947xx/include/bcmdevs.h
    2600 --- linux.old/arch/mips/bcm947xx/include/bcmdevs.h      1970-01-01 01:00:00.000000000 +0100
    2601 +++ linux.dev/arch/mips/bcm947xx/include/bcmdevs.h      2006-04-27 22:30:25.000000000 +0200
    2602 @@ -0,0 +1,369 @@
    2603 +/*
    2604 + * Broadcom device-specific manifest constants.
    2605 + *
    2606 + * Copyright 2006, Broadcom Corporation
    2607 + * All Rights Reserved.
    2608 + *
    2609 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    2610 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    2611 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    2612 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    2613 + * $Id: bcmdevs.h,v 1.1.1.17 2006/04/15 01:29:08 michael Exp $
     472+ * $Id$
    2614473+ */
    2615474+
     
    2617476+#define        _BCMDEVS_H
    2618477+
    2619 +#include "bcm4710.h"
    2620478+
    2621479+/* Known PCI vendor Id's */
     
    2657515+#define        BCM47XX_USB20H_ID       0x471a          /* 47xx usb 2.0 host */
    2658516+#define        BCM47XX_USB20D_ID       0x471b          /* 47xx usb 2.0 device */
    2659 +#define        BCM47XX_ATA100_ID       0x471d          /* 47xx parallel ATA */
    2660 +#define        BCM47XX_SATAXOR_ID      0x471e          /* 47xx serial ATA & XOR DMA */
    2661 +#define        BCM47XX_GIGETH_ID       0x471f          /* 47xx GbE (5700) */
    2662 +
    2663 +#define BCM47XX_SMBUS_EMU_ID   0x47fe          /* 47xx emulated SMBus device */
    2664 +#define        BCM47XX_XOR_EMU_ID      0x47ff          /* 47xx emulated XOR engine */
    2665 +
    2666 +#define        BCM4710_CHIP_ID         0x4710          /* 4710 chipid returned by sb_chip() */
     517+
    2667518+#define        BCM4710_DEVICE_ID       0x4710          /* 4710 primary function 0 */
    2668519+
    2669 +#define        BCM4402_CHIP_ID         0x4402          /* 4402 chipid */
     520+#define        BCM4610_DEVICE_ID       0x4610          /* 4610 primary function 0 */
     521+#define        BCM4610_ILINE_ID        0x4611          /* 4610 iline100 */
     522+#define        BCM4610_V90_ID          0x4612          /* 4610 v90 codec */
     523+#define        BCM4610_ENET_ID         0x4613          /* 4610 enet */
     524+#define        BCM4610_EXT_ID          0x4614          /* 4610 external i/f */
     525+#define        BCM4610_USB_ID          0x4615          /* 4610 usb */
     526+
     527+#define        BCM4402_DEVICE_ID       0x4402          /* 4402 primary function 0 */
    2670528+#define        BCM4402_ENET_ID         0x4402          /* 4402 enet */
    2671529+#define        BCM4402_V90_ID          0x4403          /* 4402 v90 codec */
    2672530+#define        BCM4401_ENET_ID         0x170c          /* 4401b0 production enet cards */
    2673531+
    2674 +#define        BCM4306_CHIP_ID         0x4306          /* 4306 chipcommon chipid */
     532+#define        BCM4301_DEVICE_ID       0x4301          /* 4301 primary function 0 */
     533+#define        BCM4301_D11B_ID         0x4301          /* 4301 802.11b */
     534+
     535+#define        BCM4307_DEVICE_ID       0x4307          /* 4307 primary function 0 */
     536+#define        BCM4307_V90_ID          0x4305          /* 4307 v90 codec */
     537+#define        BCM4307_ENET_ID         0x4306          /* 4307 enet */
     538+#define        BCM4307_D11B_ID         0x4307          /* 4307 802.11b */
     539+
     540+#define        BCM4306_DEVICE_ID       0x4306          /* 4306 chipcommon chipid */
    2675541+#define        BCM4306_D11G_ID         0x4320          /* 4306 802.11g */
    2676542+#define        BCM4306_D11G_ID2        0x4325         
     
    2682548+#define        BCM4309_PKG_ID          1               /* 4309 package id */
    2683549+
    2684 +#define        BCM4311_CHIP_ID         0x4311          /* 4311 PCIe 802.11a/b/g */
    2685 +#define        BCM4311_D11G_ID         0x4311          /* 4311 802.11b/g id */
    2686 +#define        BCM4311_D11DUAL_ID      0x4312          /* 4311 802.11a/b/g id */
    2687 +#define        BCM4311_D11A_ID         0x4313          /* 4311 802.11a id */
    2688 +
    2689550+#define        BCM4303_D11B_ID         0x4303          /* 4303 802.11b */
    2690551+#define        BCM4303_PKG_ID          2               /* 4303 package id */
    2691552+
     553+#define        BCM4310_DEVICE_ID       0x4310          /* 4310 chipcommon chipid */
     554+#define        BCM4310_D11B_ID         0x4311          /* 4310 802.11b */
     555+#define        BCM4310_UART_ID         0x4312          /* 4310 uart */
     556+#define        BCM4310_ENET_ID         0x4313          /* 4310 enet */
     557+#define        BCM4310_USB_ID          0x4315          /* 4310 usb */
     558+
    2692559+#define        BCMGPRS_UART_ID         0x4333          /* Uart id used by 4306/gprs card */
    2693 +#define        BCMGPRS2_UART_ID        0x4344          /* Uart id used by 4306/gprs card */
    2694 +
    2695 +#define        BCM4704_CHIP_ID         0x4704          /* 4704 chipcommon chipid */
     560+
     561+#define        BCM4704_DEVICE_ID       0x4704          /* 4704 chipcommon chipid */
    2696562+#define        BCM4704_ENET_ID         0x4706          /* 4704 enet (Use 47XX_ENET_ID instead!) */
    2697563+
    2698 +#define        BCM4318_CHIP_ID         0x4318          /* 4318 chip common chipid */
    2699 +#define        BCM4318_D11G_ID         0x4318          /* 4318 802.11b/g id */
    2700 +#define        BCM4318_D11DUAL_ID      0x4319          /* 4318 802.11a/b/g id */
    2701 +#define        BCM4318_D11A_ID         0x431a          /* 4318 802.11a id */
    2702 +
    2703 +#define        BCM4321_CHIP_ID         0x4321          /* 4321 chip common chipid */
    2704 +#define        BCM4321_D11N_ID         0x4328          /* 4321 802.11n dualband id */
    2705 +#define        BCM4321_D11N2G_ID       0x4329          /* 4321 802.11n 2.4Hgz band id */
    2706 +#define        BCM4321_D11N5G_ID       0x432a          /* 4321 802.11n 5Ghz band id */
    2707 +
    2708 +#define BCM4331_CHIP_ID                0x4331          /* 4331 chip common chipid */
    2709 +#define BCM4331_D11N2G_ID      0x4330          /* 4331 802.11n 2.4Ghz band id */
    2710 +#define BCM4331_D11N_ID                0x4331          /* 4331 802.11n dualband id */
    2711 +#define BCM4331_D11N5G_ID      0x4332          /* 4331 802.11n 5Ghz band id */
    2712 +
    2713 +#define HDLSIM5350_PKG_ID      1               /* HDL simulator package id for a 5350 */
    2714 +#define HDLSIM_PKG_ID          14              /* HDL simulator package id */
    2715 +#define HWSIM_PKG_ID           15              /* Hardware simulator package id */
    2716 +
    2717 +#define        BCM4712_CHIP_ID         0x4712          /* 4712 chipcommon chipid */
     564+#define        BCM4317_DEVICE_ID       0x4317          /* 4317 chip common chipid */
     565+
     566+#define        BCM4318_DEVICE_ID       0x4318          /* 4318 chip common chipid */
     567+#define        BCM4318_D11G_ID         0x4318          /* 4318 801.11b/g id */
     568+#define        BCM4318_D11DUAL_ID      0x4319          /* 4318 801.11a/b/g id */
     569+#define BCM4318_JTAGM_ID       0x4331          /* 4318 jtagm device id */
     570+
     571+#define FPGA_JTAGM_ID          0x4330          /* ??? */
     572+
     573+/* Address map */
     574+#define BCM4710_SDRAM           0x00000000      /* Physical SDRAM */
     575+#define BCM4710_PCI_MEM         0x08000000      /* Host Mode PCI memory access space (64 MB) */
     576+#define BCM4710_PCI_CFG         0x0c000000      /* Host Mode PCI configuration space (64 MB) */
     577+#define BCM4710_PCI_DMA         0x40000000      /* Client Mode PCI memory access space (1 GB) */
     578+#define BCM4710_SDRAM_SWAPPED   0x10000000      /* Byteswapped Physical SDRAM */
     579+#define BCM4710_ENUM            0x18000000      /* Beginning of core enumeration space */
     580+
     581+/* Core register space */
     582+#define BCM4710_REG_SDRAM       0x18000000      /* SDRAM core registers */
     583+#define BCM4710_REG_ILINE20     0x18001000      /* InsideLine20 core registers */
     584+#define BCM4710_REG_EMAC0       0x18002000      /* Ethernet MAC 0 core registers */
     585+#define BCM4710_REG_CODEC       0x18003000      /* Codec core registers */
     586+#define BCM4710_REG_USB         0x18004000      /* USB core registers */
     587+#define BCM4710_REG_PCI         0x18005000      /* PCI core registers */
     588+#define BCM4710_REG_MIPS        0x18006000      /* MIPS core registers */
     589+#define BCM4710_REG_EXTIF       0x18007000      /* External Interface core registers */
     590+#define BCM4710_REG_EMAC1       0x18008000      /* Ethernet MAC 1 core registers */
     591+
     592+#define BCM4710_EXTIF           0x1f000000      /* External Interface base address */
     593+#define BCM4710_PCMCIA_MEM      0x1f000000      /* External Interface PCMCIA memory access */
     594+#define BCM4710_PCMCIA_IO       0x1f100000      /* PCMCIA I/O access */
     595+#define BCM4710_PCMCIA_CONF     0x1f200000      /* PCMCIA configuration */
     596+#define BCM4710_PROG            0x1f800000      /* Programable interface */
     597+#define BCM4710_FLASH           0x1fc00000      /* Flash */
     598+
     599+#define BCM4710_EJTAG           0xff200000      /* MIPS EJTAG space (2M) */
     600+
     601+#define BCM4710_UART            (BCM4710_REG_EXTIF + 0x00000300)
     602+
     603+#define BCM4710_EUART           (BCM4710_EXTIF + 0x00800000)
     604+#define BCM4710_LED             (BCM4710_EXTIF + 0x00900000)
     605+
     606+#define        BCM4712_DEVICE_ID       0x4712          /* 4712 chipcommon chipid */
    2718607+#define        BCM4712_MIPS_ID         0x4720          /* 4712 base devid */
    2719608+#define        BCM4712LARGE_PKG_ID     0               /* 340pin 4712 package id */
     
    2721610+#define        BCM4712MID_PKG_ID       2               /* 225pin 4712 package id */
    2722611+
    2723 +#define BCM5365_CHIP_ID                0x5365          /* 5365 chipcommon chipid */
    2724 +#define        BCM5350_CHIP_ID         0x5350          /* bcm5350 chipcommon chipid */
    2725 +#define        BCM5352_CHIP_ID         0x5352          /* bcm5352 chipcommon chipid */
    2726 +
    2727 +#define        BCM4320_CHIP_ID         0x4320          /* bcm4320 chipcommon chipid */
    2728 +
    2729 +#define BCM4328_CHIP_ID                0x4328          /* bcm4328 chipcommon chipid */
    2730 +
    2731 +#define FPGA_JTAGM_ID          0x43f0          /* FPGA jtagm device id */
    2732 +#define BCM43XX_JTAGM_ID       0x43f1          /* 43xx jtagm device id */
    2733 +#define BCM43XXOLD_JTAGM_ID    0x4331          /* 43xx old jtagm device id */
    2734 +
    2735 +#define SDIOH_FPGA_ID          0x43f2          /* sdio host fpga */
    2736 +#define SDIOD_FPGA_ID          0x43f4          /* sdio device fpga */
    2737 +
    2738 +#define MIMO_FPGA_ID           0x43f8          /* FPGA mimo minimacphy device id */
    2739 +
    2740 +#define BCM4785_CHIP_ID                0x4785          /* 4785 chipcommon chipid */
     612+#define        SDIOH_FPGA_ID           0x4380          /* sdio host fpga */
     613+
     614+#define BCM5365_DEVICE_ID       0x5365          /* 5365 chipcommon chipid */
     615+#define        BCM5350_DEVICE_ID       0x5350          /* bcm5350 chipcommon chipid */
     616+#define        BCM5352_DEVICE_ID       0x5352          /* bcm5352 chipcommon chipid */
     617+
     618+#define        BCM4320_DEVICE_ID       0x4320          /* bcm4320 chipcommon chipid */
    2741619+
    2742620+/* PCMCIA vendor Id's */
     
    2762640+#define BFL_HGPA               0x2000  /* This board has a high gain PA */
    2763641+#define        BFL_BTCMOD              0x4000  /* This board' BTCOEXIST is in the alternate gpios */
    2764 +#define        BFL_ALTIQ               0x8000  /* Alternate I/Q settings */
    2765 +
    2766 +/* boardflags2 */
    2767 +#define BFL2_RXBB_INT_REG_DIS  0x00000001      /* This board has an external rxbb regulator */
    2768 +#define BFL2_SSWITCH_AVAIL     0x00000002      /* This board has a superswitch for > 2 antennas */
    2769 +#define BFL2_TXPWRCTRL_EN      0x00000004      /* This board permits TX Power Control to be enabled */
    2770 +
    2771 +/* board specific GPIO assignment, gpio 0-3 are also customer-configurable led */
    2772 +#define        BOARD_GPIO_BTCMOD_IN    0x010   /* bit 4 is the alternate BT Coexistance Input */
    2773 +#define        BOARD_GPIO_BTCMOD_OUT   0x020   /* bit 5 is the alternate BT Coexistance Out */
    2774 +#define        BOARD_GPIO_BTC_IN       0x080   /* bit 7 is BT Coexistance Input */
    2775 +#define        BOARD_GPIO_BTC_OUT      0x100   /* bit 8 is BT Coexistance Out */
    2776 +#define        BOARD_GPIO_PACTRL       0x200   /* bit 9 controls the PA on new 4306 boards */
    2777 +#define        PCI_CFG_GPIO_SCS        0x10    /* PCI config space bit 4 for 4306c0 slow clock source */
    2778 +#define PCI_CFG_GPIO_HWRAD     0x20    /* PCI config space GPIO 13 for hw radio disable */
    2779 +#define PCI_CFG_GPIO_XTAL      0x40    /* PCI config space GPIO 14 for Xtal powerup */
    2780 +#define PCI_CFG_GPIO_PLL       0x80    /* PCI config space GPIO 15 for PLL powerdown */
    2781 +
    2782 +/* power control defines */
    2783 +#define PLL_DELAY              150             /* us pll on delay */
    2784 +#define FREF_DELAY             200             /* us fref change delay */
    2785 +#define MIN_SLOW_CLK           32              /* us Slow clock period */
    2786 +#define        XTAL_ON_DELAY           1000            /* us crystal power-on delay */
    2787 +
    2788 +/* Reference Board Types */
    2789 +
    2790 +#define        BU4710_BOARD            0x0400
    2791 +#define        VSIM4710_BOARD          0x0401
    2792 +#define        QT4710_BOARD            0x0402
    2793 +
    2794 +#define        BU4309_BOARD            0x040a
    2795 +#define        BCM94309CB_BOARD        0x040b
    2796 +#define        BCM94309MP_BOARD        0x040c
    2797 +#define        BCM4309AP_BOARD         0x040d
    2798 +
    2799 +#define        BCM94302MP_BOARD        0x040e
    2800 +
    2801 +#define        BU4306_BOARD            0x0416
    2802 +#define        BCM94306CB_BOARD        0x0417
    2803 +#define        BCM94306MP_BOARD        0x0418
    2804 +
    2805 +#define        BCM94710D_BOARD         0x041a
    2806 +#define        BCM94710R1_BOARD        0x041b
    2807 +#define        BCM94710R4_BOARD        0x041c
    2808 +#define        BCM94710AP_BOARD        0x041d
    2809 +
    2810 +#define        BU2050_BOARD            0x041f
    2811 +
    2812 +
    2813 +#define        BCM94309G_BOARD         0x0421
    2814 +
    2815 +#define        BU4704_BOARD            0x0423
    2816 +#define        BU4702_BOARD            0x0424
    2817 +
    2818 +#define        BCM94306PC_BOARD        0x0425          /* pcmcia 3.3v 4306 card */
    2819 +
    2820 +
    2821 +#define        BCM94702MN_BOARD        0x0428
    2822 +
    2823 +/* BCM4702 1U CompactPCI Board */
    2824 +#define        BCM94702CPCI_BOARD      0x0429
    2825 +
    2826 +/* BCM4702 with BCM95380 VLAN Router */
    2827 +#define        BCM95380RR_BOARD        0x042a
    2828 +
    2829 +/* cb4306 with SiGe PA */
    2830 +#define        BCM94306CBSG_BOARD      0x042b
    2831 +
    2832 +/* cb4306 with SiGe PA */
    2833 +#define        PCSG94306_BOARD         0x042d
    2834 +
    2835 +/* bu4704 with sdram */
    2836 +#define        BU4704SD_BOARD          0x042e
    2837 +
    2838 +/* Dual 11a/11g Router */
    2839 +#define        BCM94704AGR_BOARD       0x042f
    2840 +
    2841 +/* 11a-only minipci */
    2842 +#define        BCM94308MP_BOARD        0x0430
    2843 +
    2844 +
    2845 +
    2846 +#define BU4712_BOARD           0x0444
    2847 +#define        BU4712SD_BOARD          0x045d
    2848 +#define        BU4712L_BOARD           0x045f
    2849 +
    2850 +/* BCM4712 boards */
    2851 +#define BCM94712AP_BOARD       0x0445
    2852 +#define BCM94712P_BOARD                0x0446
    2853 +
    2854 +/* BCM4318 boards */
    2855 +#define BU4318_BOARD           0x0447
    2856 +#define CB4318_BOARD           0x0448
    2857 +#define MPG4318_BOARD          0x0449
    2858 +#define MP4318_BOARD           0x044a
    2859 +#define SD4318_BOARD           0x044b
    2860 +
    2861 +/* BCM63XX boards */
    2862 +#define BCM96338_BOARD         0x6338
    2863 +#define BCM96348_BOARD         0x6348
    2864 +
    2865 +/* Another mp4306 with SiGe */
    2866 +#define        BCM94306P_BOARD         0x044c
    2867 +
    2868 +/* mp4303 */
    2869 +#define        BCM94303MP_BOARD        0x044e
    2870 +
    2871 +/* mpsgh4306 */
    2872 +#define        BCM94306MPSGH_BOARD     0x044f
    2873 +
    2874 +/* BRCM 4306 w/ Front End Modules */
    2875 +#define BCM94306MPM            0x0450
    2876 +#define BCM94306MPL            0x0453
    2877 +
    2878 +/* 4712agr */
    2879 +#define        BCM94712AGR_BOARD       0x0451
    2880 +
    2881 +/* pcmcia 4303 */
    2882 +#define        PC4303_BOARD            0x0454
    2883 +
    2884 +/* 5350K */
    2885 +#define        BCM95350K_BOARD         0x0455
    2886 +
    2887 +/* 5350R */
    2888 +#define        BCM95350R_BOARD         0x0456
    2889 +
    2890 +/* 4306mplna */
    2891 +#define        BCM94306MPLNA_BOARD     0x0457
    2892 +
    2893 +/* 4320 boards */
    2894 +#define        BU4320_BOARD            0x0458
    2895 +#define        BU4320S_BOARD           0x0459
    2896 +#define        BCM94320PH_BOARD        0x045a
    2897 +
    2898 +/* 4306mph */
    2899 +#define        BCM94306MPH_BOARD       0x045b
    2900 +
    2901 +/* 4306pciv */
    2902 +#define        BCM94306PCIV_BOARD      0x045c
    2903 +
    2904 +#define        BU4712SD_BOARD          0x045d
    2905 +
    2906 +#define        BCM94320PFLSH_BOARD     0x045e
    2907 +
    2908 +#define        BU4712L_BOARD           0x045f
    2909 +#define        BCM94712LGR_BOARD       0x0460
    2910 +#define        BCM94320R_BOARD         0x0461
    2911 +
    2912 +#define        BU5352_BOARD            0x0462
    2913 +
    2914 +#define        BCM94318MPGH_BOARD      0x0463
    2915 +
    2916 +#define        BU4311_BOARD            0x0464
    2917 +#define        BCM94311MC_BOARD        0x0465
    2918 +#define        BCM94311MCAG_BOARD      0x0466
    2919 +
    2920 +#define        BCM95352GR_BOARD        0x0467
    2921 +
    2922 +/* bcm95351agr */
    2923 +#define        BCM95351AGR_BOARD       0x0470
    2924 +
    2925 +/* bcm94704mpcb */
    2926 +#define        BCM94704MPCB_BOARD      0x0472
    2927 +
    2928 +/* 4785 boards */
    2929 +#define BU4785_BOARD           0x0478
    2930 +
    2931 +/* 4321 boards */
    2932 +#define BU4321_BOARD           0x046b
    2933 +#define BU4321E_BOARD          0x047c
    2934 +#define MP4321_BOARD           0x046c
    2935 +#define CB2_4321_BOARD         0x046d
    2936 +#define MC4321_BOARD           0x046e
    2937 +
    2938 +/* # of GPIO pins */
    2939 +#define GPIO_NUMPINS           16
    2940 +
    2941 +/* radio ID codes */
    2942 +#define        NORADIO_ID              0xe4f5
    2943 +#define        NORADIO_IDCODE          0x4e4f5246
    2944 +
    2945 +#define        BCM2050_ID              0x2050
    2946 +#define        BCM2050_IDCODE          0x02050000
    2947 +#define        BCM2050A0_IDCODE        0x1205017f
    2948 +#define        BCM2050A1_IDCODE        0x2205017f
    2949 +#define        BCM2050R8_IDCODE        0x8205017f
    2950 +
    2951 +#define BCM2055_ID             0x2055
    2952 +#define BCM2055_IDCODE         0x02055000
    2953 +#define BCM2055A0_IDCODE       0x1205517f
    2954 +
    2955 +#define        BCM2060_ID              0x2060
    2956 +#define        BCM2060_IDCODE          0x02060000
    2957 +#define        BCM2060WW_IDCODE        0x1206017f
    2958 +
    2959 +#define BCM2062_ID             0x2062
    2960 +#define BCM2062_IDCODE         0x02062000
    2961 +#define BCM2062A0_IDCODE       0x0206217f
    2962 +
    2963 +/* parts of an idcode: */
    2964 +#define        IDCODE_MFG_MASK         0x00000fff
    2965 +#define        IDCODE_MFG_SHIFT        0
    2966 +#define        IDCODE_ID_MASK          0x0ffff000
    2967 +#define        IDCODE_ID_SHIFT         12
    2968 +#define        IDCODE_REV_MASK         0xf0000000
    2969 +#define        IDCODE_REV_SHIFT        28
    2970 +
    2971 +#endif /* _BCMDEVS_H */
    2972 diff -urN linux.old/arch/mips/bcm947xx/include/bcmdevs1.h linux.dev/arch/mips/bcm947xx/include/bcmdevs1.h
    2973 --- linux.old/arch/mips/bcm947xx/include/bcmdevs1.h     1970-01-01 01:00:00.000000000 +0100
    2974 +++ linux.dev/arch/mips/bcm947xx/include/bcmdevs1.h     2006-05-02 04:32:03.000000000 +0200
    2975 @@ -0,0 +1,391 @@
    2976 +/*
    2977 + * Broadcom device-specific manifest constants.
    2978 + *
    2979 + * Copyright 2005, Broadcom Corporation   
    2980 + * All Rights Reserved.   
    2981 + *   
    2982 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY   
    2983 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM   
    2984 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS   
    2985 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.   
    2986 + * $Id$
    2987 + */
    2988 +
    2989 +#ifndef        _BCMDEVS_H
    2990 +#define        _BCMDEVS_H
    2991 +
    2992 +
    2993 +/* Known PCI vendor Id's */
    2994 +#define        VENDOR_EPIGRAM          0xfeda
    2995 +#define        VENDOR_BROADCOM         0x14e4
    2996 +#define        VENDOR_3COM             0x10b7
    2997 +#define        VENDOR_NETGEAR          0x1385
    2998 +#define        VENDOR_DIAMOND          0x1092
    2999 +#define        VENDOR_DELL             0x1028
    3000 +#define        VENDOR_HP               0x0e11
    3001 +#define        VENDOR_APPLE            0x106b
    3002 +
    3003 +/* PCI Device Id's */
    3004 +#define        BCM4210_DEVICE_ID       0x1072          /* never used */
    3005 +#define        BCM4211_DEVICE_ID       0x4211
    3006 +#define        BCM4230_DEVICE_ID       0x1086          /* never used */
    3007 +#define        BCM4231_DEVICE_ID       0x4231
    3008 +
    3009 +#define        BCM4410_DEVICE_ID       0x4410          /* bcm44xx family pci iline */
    3010 +#define        BCM4430_DEVICE_ID       0x4430          /* bcm44xx family cardbus iline */
    3011 +#define        BCM4412_DEVICE_ID       0x4412          /* bcm44xx family pci enet */
    3012 +#define        BCM4432_DEVICE_ID       0x4432          /* bcm44xx family cardbus enet */
    3013 +
    3014 +#define        BCM3352_DEVICE_ID       0x3352          /* bcm3352 device id */
    3015 +#define        BCM3360_DEVICE_ID       0x3360          /* bcm3360 device id */
    3016 +
    3017 +#define        EPI41210_DEVICE_ID      0xa0fa          /* bcm4210 */
    3018 +#define        EPI41230_DEVICE_ID      0xa10e          /* bcm4230 */
    3019 +
    3020 +#define        BCM47XX_ILINE_ID        0x4711          /* 47xx iline20 */
    3021 +#define        BCM47XX_V90_ID          0x4712          /* 47xx v90 codec */
    3022 +#define        BCM47XX_ENET_ID         0x4713          /* 47xx enet */
    3023 +#define        BCM47XX_EXT_ID          0x4714          /* 47xx external i/f */
    3024 +#define        BCM47XX_USB_ID          0x4715          /* 47xx usb */
    3025 +#define        BCM47XX_USBH_ID         0x4716          /* 47xx usb host */
    3026 +#define        BCM47XX_USBD_ID         0x4717          /* 47xx usb device */
    3027 +#define        BCM47XX_IPSEC_ID        0x4718          /* 47xx ipsec */
    3028 +#define        BCM47XX_ROBO_ID         0x4719          /* 47xx/53xx roboswitch core */
    3029 +#define        BCM47XX_USB20H_ID       0x471a          /* 47xx usb 2.0 host */
    3030 +#define        BCM47XX_USB20D_ID       0x471b          /* 47xx usb 2.0 device */
    3031 +
    3032 +#define        BCM4710_DEVICE_ID       0x4710          /* 4710 primary function 0 */
    3033 +
    3034 +#define        BCM4610_DEVICE_ID       0x4610          /* 4610 primary function 0 */
    3035 +#define        BCM4610_ILINE_ID        0x4611          /* 4610 iline100 */
    3036 +#define        BCM4610_V90_ID          0x4612          /* 4610 v90 codec */
    3037 +#define        BCM4610_ENET_ID         0x4613          /* 4610 enet */
    3038 +#define        BCM4610_EXT_ID          0x4614          /* 4610 external i/f */
    3039 +#define        BCM4610_USB_ID          0x4615          /* 4610 usb */
    3040 +
    3041 +#define        BCM4402_DEVICE_ID       0x4402          /* 4402 primary function 0 */
    3042 +#define        BCM4402_ENET_ID         0x4402          /* 4402 enet */
    3043 +#define        BCM4402_V90_ID          0x4403          /* 4402 v90 codec */
    3044 +#define        BCM4401_ENET_ID         0x170c          /* 4401b0 production enet cards */
    3045 +
    3046 +#define        BCM4301_DEVICE_ID       0x4301          /* 4301 primary function 0 */
    3047 +#define        BCM4301_D11B_ID         0x4301          /* 4301 802.11b */
    3048 +
    3049 +#define        BCM4307_DEVICE_ID       0x4307          /* 4307 primary function 0 */
    3050 +#define        BCM4307_V90_ID          0x4305          /* 4307 v90 codec */
    3051 +#define        BCM4307_ENET_ID         0x4306          /* 4307 enet */
    3052 +#define        BCM4307_D11B_ID         0x4307          /* 4307 802.11b */
    3053 +
    3054 +#define        BCM4306_DEVICE_ID       0x4306          /* 4306 chipcommon chipid */
    3055 +#define        BCM4306_D11G_ID         0x4320          /* 4306 802.11g */
    3056 +#define        BCM4306_D11G_ID2        0x4325         
    3057 +#define        BCM4306_D11A_ID         0x4321          /* 4306 802.11a */
    3058 +#define        BCM4306_UART_ID         0x4322          /* 4306 uart */
    3059 +#define        BCM4306_V90_ID          0x4323          /* 4306 v90 codec */
    3060 +#define        BCM4306_D11DUAL_ID      0x4324          /* 4306 dual A+B */
    3061 +
    3062 +#define        BCM4309_PKG_ID          1               /* 4309 package id */
    3063 +
    3064 +#define        BCM4303_D11B_ID         0x4303          /* 4303 802.11b */
    3065 +#define        BCM4303_PKG_ID          2               /* 4303 package id */
    3066 +
    3067 +#define        BCM4310_DEVICE_ID       0x4310          /* 4310 chipcommon chipid */
    3068 +#define        BCM4310_D11B_ID         0x4311          /* 4310 802.11b */
    3069 +#define        BCM4310_UART_ID         0x4312          /* 4310 uart */
    3070 +#define        BCM4310_ENET_ID         0x4313          /* 4310 enet */
    3071 +#define        BCM4310_USB_ID          0x4315          /* 4310 usb */
    3072 +
    3073 +#define        BCMGPRS_UART_ID         0x4333          /* Uart id used by 4306/gprs card */
    3074 +#define        BCMGPRS2_UART_ID        0x4344          /* Uart id used by 4306/gprs card */
    3075 +
    3076 +
    3077 +#define        BCM4704_DEVICE_ID       0x4704          /* 4704 chipcommon chipid */
    3078 +#define        BCM4704_ENET_ID         0x4706          /* 4704 enet (Use 47XX_ENET_ID instead!) */
    3079 +
    3080 +#define        BCM4317_DEVICE_ID       0x4317          /* 4317 chip common chipid */
    3081 +
    3082 +#define        BCM4318_DEVICE_ID       0x4318          /* 4318 chip common chipid */
    3083 +#define        BCM4318_D11G_ID         0x4318          /* 4318 801.11b/g id */
    3084 +#define        BCM4318_D11DUAL_ID      0x4319          /* 4318 801.11a/b/g id */
    3085 +#define BCM4318_JTAGM_ID       0x4331          /* 4318 jtagm device id */
    3086 +
    3087 +#define FPGA_JTAGM_ID          0x4330          /* ??? */
    3088 +
    3089 +/* Address map */
    3090 +#define BCM4710_SDRAM           0x00000000      /* Physical SDRAM */
    3091 +#define BCM4710_PCI_MEM         0x08000000      /* Host Mode PCI memory access space (64 MB) */
    3092 +#define BCM4710_PCI_CFG         0x0c000000      /* Host Mode PCI configuration space (64 MB) */
    3093 +#define BCM4710_PCI_DMA         0x40000000      /* Client Mode PCI memory access space (1 GB) */
    3094 +#define BCM4710_SDRAM_SWAPPED   0x10000000      /* Byteswapped Physical SDRAM */
    3095 +#define BCM4710_ENUM            0x18000000      /* Beginning of core enumeration space */
    3096 +
    3097 +/* Core register space */
    3098 +#define BCM4710_REG_SDRAM       0x18000000      /* SDRAM core registers */
    3099 +#define BCM4710_REG_ILINE20     0x18001000      /* InsideLine20 core registers */
    3100 +#define BCM4710_REG_EMAC0       0x18002000      /* Ethernet MAC 0 core registers */
    3101 +#define BCM4710_REG_CODEC       0x18003000      /* Codec core registers */
    3102 +#define BCM4710_REG_USB         0x18004000      /* USB core registers */
    3103 +#define BCM4710_REG_PCI         0x18005000      /* PCI core registers */
    3104 +#define BCM4710_REG_MIPS        0x18006000      /* MIPS core registers */
    3105 +#define BCM4710_REG_EXTIF       0x18007000      /* External Interface core registers */
    3106 +#define BCM4710_REG_EMAC1       0x18008000      /* Ethernet MAC 1 core registers */
    3107 +
    3108 +#define BCM4710_EXTIF           0x1f000000      /* External Interface base address */
    3109 +#define BCM4710_PCMCIA_MEM      0x1f000000      /* External Interface PCMCIA memory access */
    3110 +#define BCM4710_PCMCIA_IO       0x1f100000      /* PCMCIA I/O access */
    3111 +#define BCM4710_PCMCIA_CONF     0x1f200000      /* PCMCIA configuration */
    3112 +#define BCM4710_PROG            0x1f800000      /* Programable interface */
    3113 +#define BCM4710_FLASH           0x1fc00000      /* Flash */
    3114 +
    3115 +#define BCM4710_EJTAG           0xff200000      /* MIPS EJTAG space (2M) */
    3116 +
    3117 +#define BCM4710_UART            (BCM4710_REG_EXTIF + 0x00000300)
    3118 +
    3119 +#define BCM4710_EUART           (BCM4710_EXTIF + 0x00800000)
    3120 +#define BCM4710_LED             (BCM4710_EXTIF + 0x00900000)
    3121 +
    3122 +#define        BCM4712_DEVICE_ID       0x4712          /* 4712 chipcommon chipid */
    3123 +#define        BCM4712_MIPS_ID         0x4720          /* 4712 base devid */
    3124 +#define        BCM4712LARGE_PKG_ID     0               /* 340pin 4712 package id */
    3125 +#define        BCM4712SMALL_PKG_ID     1               /* 200pin 4712 package id */
    3126 +#define        BCM4712MID_PKG_ID       2               /* 225pin 4712 package id */
    3127 +
    3128 +#define        SDIOH_FPGA_ID           0x4380          /* sdio host fpga */
    3129 +
    3130 +#define BCM5365_DEVICE_ID       0x5365          /* 5365 chipcommon chipid */
    3131 +#define        BCM5350_DEVICE_ID       0x5350          /* bcm5350 chipcommon chipid */
    3132 +#define        BCM5352_DEVICE_ID       0x5352          /* bcm5352 chipcommon chipid */
    3133 +
    3134 +#define        BCM4320_DEVICE_ID       0x4320          /* bcm4320 chipcommon chipid */
    3135 +
    3136 +/* PCMCIA vendor Id's */
    3137 +
    3138 +#define        VENDOR_BROADCOM_PCMCIA  0x02d0
    3139 +
    3140 +/* SDIO vendor Id's */
    3141 +#define        VENDOR_BROADCOM_SDIO    0x00BF
    3142 +
    3143 +
    3144 +/* boardflags */
    3145 +#define        BFL_BTCOEXIST           0x0001  /* This board implements Bluetooth coexistance */
    3146 +#define        BFL_PACTRL              0x0002  /* This board has gpio 9 controlling the PA */
    3147 +#define        BFL_AIRLINEMODE         0x0004  /* This board implements gpio13 radio disable indication */
    3148 +#define        BFL_ENETROBO            0x0010  /* This board has robo switch or core */
    3149 +#define        BFL_CCKHIPWR            0x0040  /* Can do high-power CCK transmission */
    3150 +#define        BFL_ENETADM             0x0080  /* This board has ADMtek switch */
    3151 +#define        BFL_ENETVLAN            0x0100  /* This board has vlan capability */
    3152 +#define        BFL_AFTERBURNER         0x0200  /* This board supports Afterburner mode */
    3153 +#define BFL_NOPCI              0x0400  /* This board leaves PCI floating */
    3154 +#define BFL_FEM                        0x0800  /* This board supports the Front End Module */
    3155 +#define BFL_EXTLNA             0x1000  /* This board has an external LNA */
    3156 +#define BFL_HGPA               0x2000  /* This board has a high gain PA */
    3157 +#define        BFL_BTCMOD              0x4000  /* This board' BTCOEXIST is in the alternate gpios */
    3158 +#define        BFL_ALTIQ               0x8000  /* Alternate I/Q settings */
    3159642+
    3160643+/* board specific GPIO assignment, gpio 0-3 are also customer-configurable led */
     
    3185668+
    3186669+/* power control defines */
    3187 +#define PLL_DELAY              150             /* us pll on delay */
    3188 +#define FREF_DELAY             200             /* us fref change delay */
    3189 +#define MIN_SLOW_CLK           32              /* us Slow clock period */
    3190 +#define        XTAL_ON_DELAY           1000            /* us crystal power-on delay */
     670+#define PLL_DELAY              150             /* 150us pll on delay */
     671+#define FREF_DELAY             200             /* 200us fref change delay */
     672+#define MIN_SLOW_CLK           32              /* 32us Slow clock period */
    3191673+
    3192674+/* Reference Board Types */
     
    3293775+#define SD4318_BOARD           0x044b
    3294776+
    3295 +/* BCM63XX boards */
    3296 +#define BCM96338_BOARD         0x6338
    3297 +#define BCM96345_BOARD         0x6345
    3298 +#define BCM96348_BOARD         0x6348
    3299 +
    3300777+/* Another mp4306 with SiGe */
    3301778+#define        BCM94306P_BOARD         0x044c
     
    3332809+#define        BCM94306MPLNA_BOARD     0x0457
    3333810+
    3334 +/* 4320 boards */
    3335 +#define        BU4320_BOARD            0x0458
    3336 +#define        BU4320S_BOARD           0x0459
    3337 +#define        BCM94320PH_BOARD        0x045a
    3338811+
    3339812+/* 4306mph */
     
    3345818+#define        BU4712SD_BOARD          0x045d
    3346819+
    3347 +#define        BCM94320PFLSH_BOARD     0x045e
    3348820+
    3349821+#define        BU4712L_BOARD           0x045f
    3350822+#define        BCM94712LGR_BOARD       0x0460
    3351 +#define        BCM94320R_BOARD         0x0461
    3352823+
    3353824+#define        BU5352_BOARD            0x0462
    3354 +
    3355 +#define        BCM94318MPGH_BOARD      0x0463
    3356 +
    3357 +
    3358825+#define        BCM95352GR_BOARD        0x0467
    3359 +
    3360 +/* bcm95351agr */
    3361 +#define        BCM95351AGR_BOARD       0x0470
    3362826+
    3363827+/* # of GPIO pins */
     
    3365829+
    3366830+#endif /* _BCMDEVS_H */
    3367 diff -urN linux.old/arch/mips/bcm947xx/include/bcmendian.h linux.dev/arch/mips/bcm947xx/include/bcmendian.h
    3368 --- linux.old/arch/mips/bcm947xx/include/bcmendian.h    1970-01-01 01:00:00.000000000 +0100
    3369 +++ linux.dev/arch/mips/bcm947xx/include/bcmendian.h    2006-04-27 20:08:35.000000000 +0200
    3370 @@ -0,0 +1,198 @@
     831diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/bcmendian.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmendian.h
     832--- linux-2.4.32/arch/mips/bcm947xx/include/bcmendian.h 1970-01-01 01:00:00.000000000 +0100
     833+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmendian.h 2006-07-02 21:58:25.000000000 +0200
     834@@ -0,0 +1,168 @@
    3371835+/*
    3372836+ * local version of endian.h - byte order defines
    3373837+ *
    3374 + * Copyright 2006, Broadcom Corporation
    3375 + * All Rights Reserved.
    3376 + *
    3377 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    3378 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    3379 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    3380 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
     838+ * Copyright 2005, Broadcom Corporation   
     839+ * All Rights Reserved.   
     840+ *    
     841+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY   
     842+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM   
     843+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS   
     844+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.   
    3381845+ *
    3382 + *  $Id: bcmendian.h,v 1.1.1.10 2006/02/27 03:43:16 honor Exp $
     846+ *  $Id$
    3383847+*/
    3384848+
     
    3390854+/* Byte swap a 16 bit value */
    3391855+#define BCMSWAP16(val) \
    3392 +       ((uint16)(\
     856+       ((uint16)( \
    3393857+               (((uint16)(val) & (uint16)0x00ffU) << 8) | \
    3394 +               (((uint16)(val) & (uint16)0xff00U) >> 8)))
    3395 +
     858+               (((uint16)(val) & (uint16)0xff00U) >> 8) ))
     859+       
    3396860+/* Byte swap a 32 bit value */
    3397861+#define BCMSWAP32(val) \
    3398 +       ((uint32)(\
     862+       ((uint32)( \
    3399863+               (((uint32)(val) & (uint32)0x000000ffUL) << 24) | \
    3400864+               (((uint32)(val) & (uint32)0x0000ff00UL) <<  8) | \
    3401865+               (((uint32)(val) & (uint32)0x00ff0000UL) >>  8) | \
    3402 +               (((uint32)(val) & (uint32)0xff000000UL) >> 24)))
    3403 +
    3404 +/* 2 Byte swap a 32 bit value */
    3405 +#define BCMSWAP32BY16(val) \
    3406 +       ((uint32)(\
    3407 +               (((uint32)(val) & (uint32)0x0000ffffUL) << 16) | \
    3408 +               (((uint32)(val) & (uint32)0xffff0000UL) >> 16)))
    3409 +
     866+               (((uint32)(val) & (uint32)0xff000000UL) >> 24) ))
    3410867+
    3411868+static INLINE uint16
     
    3419876+{
    3420877+       return BCMSWAP32(val);
    3421 +}
    3422 +
    3423 +static INLINE uint32
    3424 +bcmswap32by16(uint32 val)
    3425 +{
    3426 +       return BCMSWAP32BY16(val);
    3427878+}
    3428879+
     
    3434885+       len = len/2;
    3435886+
    3436 +       while (len--) {
     887+       while(len--){
    3437888+               *buf = bcmswap16(*buf);
    3438889+               buf++;
     
    3461912+#define htol16(i) bcmswap16(i)
    3462913+#define htol32(i) bcmswap32(i)
    3463 +#endif /* IL_BIGENDIAN */
    3464 +#endif /* hton16 */
     914+#endif
     915+#endif
    3465916+
    3466917+#ifndef IL_BIGENDIAN
     
    3470921+#define ltoh16_buf(buf, i) bcmswap16_buf((uint16*)buf, i)
    3471922+#define htol16_buf(buf, i) bcmswap16_buf((uint16*)buf, i)
    3472 +#endif /* IL_BIGENDIAN */
    3473 +
    3474 +/*
    3475 +* store 16-bit value to unaligned little endian byte array.
    3476 +*/
    3477 +static INLINE void
    3478 +htol16_ua_store(uint16 val, uint8 *bytes)
    3479 +{
    3480 +       bytes[0] = val&0xff;
    3481 +       bytes[1] = val>>8;
    3482 +}
    3483 +
    3484 +/*
    3485 +* store 32-bit value to unaligned little endian byte array.
    3486 +*/
    3487 +static INLINE void
    3488 +htol32_ua_store(uint32 val, uint8 *bytes)
    3489 +{
    3490 +       bytes[0] = val&0xff;
    3491 +       bytes[1] = (val>>8)&0xff;
    3492 +       bytes[2] = (val>>16)&0xff;
    3493 +       bytes[3] = val>>24;
    3494 +}
    3495 +
    3496 +/*
    3497 +* store 16-bit value to unaligned network(big) endian byte array.
    3498 +*/
    3499 +static INLINE void
    3500 +hton16_ua_store(uint16 val, uint8 *bytes)
    3501 +{
    3502 +       bytes[1] = val&0xff;
    3503 +       bytes[0] = val>>8;
    3504 +}
    3505 +
    3506 +/*
    3507 +* store 32-bit value to unaligned network(big) endian byte array.
    3508 +*/
    3509 +static INLINE void
    3510 +hton32_ua_store(uint32 val, uint8 *bytes)
    3511 +{
    3512 +       bytes[3] = val&0xff;
    3513 +       bytes[2] = (val>>8)&0xff;
    3514 +       bytes[1] = (val>>16)&0xff;
    3515 +       bytes[0] = val>>24;
    3516 +}
     923+#endif
    3517924+
    3518925+/*
     
    3520927+*/
    3521928+static INLINE uint16
    3522 +ltoh16_ua(void *bytes)
    3523 +{
    3524 +       return (((uint8*)bytes)[1]<<8)+((uint8 *)bytes)[0];
     929+ltoh16_ua(uint8 *bytes)
     930+{
     931+       return (bytes[1]<<8)+bytes[0];
    3525932+}
    3526933+
     
    3529936+*/
    3530937+static INLINE uint32
    3531 +ltoh32_ua(void *bytes)
    3532 +{
    3533 +       return (((uint8*)bytes)[3]<<24)+(((uint8*)bytes)[2]<<16)+
    3534 +              (((uint8*)bytes)[1]<<8)+((uint8*)bytes)[0];
     938+ltoh32_ua(uint8 *bytes)
     939+{
     940+       return (bytes[3]<<24)+(bytes[2]<<16)+(bytes[1]<<8)+bytes[0];
    3535941+}
    3536942+
     
    3539945+*/
    3540946+static INLINE uint16
    3541 +ntoh16_ua(void *bytes)
    3542 +{
    3543 +       return (((uint8*)bytes)[0]<<8)+((uint8*)bytes)[1];
     947+ntoh16_ua(uint8 *bytes)
     948+{
     949+       return (bytes[0]<<8)+bytes[1];
    3544950+}
    3545951+
     
    3548954+*/
    3549955+static INLINE uint32
    3550 +ntoh32_ua(void *bytes)
    3551 +{
    3552 +       return (((uint8*)bytes)[0]<<24)+(((uint8*)bytes)[1]<<16)+
    3553 +              (((uint8*)bytes)[2]<<8)+((uint8*)bytes)[3];
    3554 +}
    3555 +
    3556 +#define ltoh_ua(ptr) (\
    3557 +       sizeof(*(ptr)) == sizeof(uint8) ?  *(uint8 *)ptr : \
    3558 +       sizeof(*(ptr)) == sizeof(uint16) ? (((uint8 *)ptr)[1]<<8)+((uint8 *)ptr)[0] : \
    3559 +       (((uint8 *)ptr)[3]<<24)+(((uint8 *)ptr)[2]<<16)+(((uint8 *)ptr)[1]<<8)+((uint8 *)ptr)[0] \
    3560 +)
    3561 +
    3562 +#define ntoh_ua(ptr) (\
    3563 +       sizeof(*(ptr)) == sizeof(uint8) ?  *(uint8 *)ptr : \
    3564 +       sizeof(*(ptr)) == sizeof(uint16) ? (((uint8 *)ptr)[0]<<8)+((uint8 *)ptr)[1] : \
    3565 +       (((uint8 *)ptr)[0]<<24)+(((uint8 *)ptr)[1]<<16)+(((uint8 *)ptr)[2]<<8)+((uint8 *)ptr)[3] \
    3566 +)
     956+ntoh32_ua(uint8 *bytes)
     957+{
     958+       return (bytes[0]<<24)+(bytes[1]<<16)+(bytes[2]<<8)+bytes[3];
     959+}
     960+
     961+/* get_ua adapted from Linux asm-mips/unaligned.h */
     962+#ifdef IL_BIGENDIAN
     963+#define get_ua(ptr)                                            \
     964+({                                                                     \
     965+       __typeof__(*(ptr)) __val;                                       \
     966+                                                                       \
     967+       switch (sizeof(*(ptr))) {                                       \
     968+       case 1:                                                         \
     969+               __val = *(uint8 *)ptr;                  \
     970+               break;                                                  \
     971+       case 2:                                                         \
     972+               __val = ntoh16_ua((uint8 *)ptr);                \
     973+               break;                                                  \
     974+       case 4:                                                         \
     975+               __val = ntoh32_ua((uint8 *)ptr);                \
     976+               break;                                                  \
     977+       }                                                               \
     978+                                                                       \
     979+       __val;                                                          \
     980+})
     981+#else
     982+#define get_ua(ptr)                                            \
     983+({                                                                     \
     984+       __typeof__(*(ptr)) __val;                                       \
     985+                                                                       \
     986+       switch (sizeof(*(ptr))) {                                       \
     987+       case 1:                                                         \
     988+               __val = *(uint8 *)ptr;                  \
     989+               break;                                                  \
     990+       case 2:                                                         \
     991+               __val = ltoh16_ua((uint8 *)ptr);                \
     992+               break;                                                  \
     993+       case 4:                                                         \
     994+               __val = ltoh32_ua((uint8 *)ptr);                \
     995+               break;                                                  \
     996+       }                                                               \
     997+                                                                       \
     998+       __val;                                                          \
     999+})
     1000+#endif
    35671001+
    35681002+#endif /* _BCMENDIAN_H_ */
    3569 diff -urN linux.old/arch/mips/bcm947xx/include/bcmnvram.h linux.dev/arch/mips/bcm947xx/include/bcmnvram.h
    3570 --- linux.old/arch/mips/bcm947xx/include/bcmnvram.h     1970-01-01 01:00:00.000000000 +0100
    3571 +++ linux.dev/arch/mips/bcm947xx/include/bcmnvram.h     2006-04-27 23:29:18.000000000 +0200
    3572 @@ -0,0 +1,159 @@
     1003diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/bcmnvram.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmnvram.h
     1004--- linux-2.4.32/arch/mips/bcm947xx/include/bcmnvram.h  1970-01-01 01:00:00.000000000 +0100
     1005+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmnvram.h  2006-07-02 21:58:25.000000000 +0200
     1006@@ -0,0 +1,132 @@
    35731007+/*
    35741008+ * NVRAM variable manipulation
    35751009+ *
    3576 + * Copyright 2006, Broadcom Corporation
     1010+ * Copyright 2005, Broadcom Corporation
    35771011+ * All Rights Reserved.
    35781012+ *
     
    35821016+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    35831017+ *
    3584 + * $Id: bcmnvram.h,v 1.17 2006/03/02 12:33:44 honor Exp $
     1018+ * $Id$
    35851019+ */
    35861020+
     
    35911025+
    35921026+#include <typedefs.h>
    3593 +#include <bcmdefs.h>
    35941027+
    35951028+struct nvram_header {
    35961029+       uint32 magic;
    35971030+       uint32 len;
    3598 +       uint32 crc_ver_init;    /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
    3599 +       uint32 config_refresh;  /* 0:15 sdram_config, 16:31 sdram_refresh */
     1031+       uint32 crc_ver_init;    /* 0:7 crc, 8:15 ver, 16:27 init, mem. test 28, 29-31 reserved */
     1032+       uint32 config_refresh;  /* 0:15 config, 16:31 refresh */
    36001033+       uint32 config_ncdl;     /* ncdl values for memc */
    36011034+};
     
    36111044+ * platforms.
    36121045+ */
    3613 +extern int nvram_init(void *sbh);
     1046+extern int BCMINIT(nvram_init)(void *sbh);
    36141047+
    36151048+/*
     
    36171050+ * platforms.
    36181051+ */
    3619 +extern void nvram_exit(void *sbh);
     1052+extern void BCMINIT(nvram_exit)(void);
    36201053+
    36211054+/*
     
    36251058+ * @return     value of variable or NULL if undefined
    36261059+ */
    3627 +extern char * nvram_get(const char *name);
    3628 +
    3629 +/*
    3630 + * Read the reset GPIO value from the nvram and set the GPIO
    3631 + * as input
    3632 + */
    3633 +extern int BCMINITFN(nvram_resetgpio_init)(void *sbh);
    3634 +extern int BCMINITFN(nvram_gpio_init)(const char *name, void *sbh);
    3635 +extern int BCMINITFN(nvram_gpio_set)(const char *name, void *sbh, int type);
     1060+extern char * BCMINIT(nvram_get)(const char *name);
    36361061+
    36371062+/*
     
    36401065+ * @return     value of variable or NUL if undefined
    36411066+ */
    3642 +#define nvram_safe_get(name) (nvram_get(name) ? : "")
    3643 +
    3644 +#define nvram_safe_unset(name) ({ \
    3645 +       if(nvram_get(name)) \
    3646 +               nvram_unset(name); \
    3647 +})
    3648 +
    3649 +#define nvram_safe_set(name, value) ({ \
    3650 +       if(!nvram_get(name) || strcmp(nvram_get(name), value)) \
    3651 +               nvram_set(name, value); \
    3652 +})
     1067+#define nvram_safe_get(name) (BCMINIT(nvram_get)(name) ? : "")
    36531068+
    36541069+/*
     
    36611076+static INLINE int
    36621077+nvram_match(char *name, char *match) {
    3663 +       const char *value = nvram_get(name);
     1078+       const char *value = BCMINIT(nvram_get)(name);
    36641079+       return (value && !strcmp(value, match));
    36651080+}
     
    36741089+static INLINE int
    36751090+nvram_invmatch(char *name, char *invmatch) {
    3676 +       const char *value = nvram_get(name);
     1091+       const char *value = BCMINIT(nvram_get)(name);
    36771092+       return (value && strcmp(value, invmatch));
    36781093+}
     
    36871102+ * @return     0 on success and errno on failure
    36881103+ */
    3689 +extern int nvram_set(const char *name, const char *value);
     1104+extern int BCMINIT(nvram_set)(const char *name, const char *value);
    36901105+
    36911106+/*
     
    36961111+ * NOTE: use nvram_commit to commit this change to flash.
    36971112+ */
    3698 +extern int nvram_unset(const char *name);
     1113+extern int BCMINIT(nvram_unset)(const char *name);
    36991114+
    37001115+/*
     
    37041119+ * @return     0 on success and errno on failure
    37051120+ */
    3706 +extern int nvram_commit(void);
     1121+extern int BCMINIT(nvram_commit)(void);
    37071122+
    37081123+/*
     
    37121127+ * @return     0 on success and errno on failure
    37131128+ */
    3714 +extern int nvram_getall(char *buf, int count);
    3715 +
    3716 +extern int file2nvram(char *filename, char *varname);
    3717 +extern int nvram2file(char *varname, char *filename);
     1129+extern int BCMINIT(nvram_getall)(char *buf, int count);
    37181130+
    37191131+#endif /* _LANGUAGE_ASSEMBLY */
    37201132+
    37211133+#define NVRAM_MAGIC            0x48534C46      /* 'FLSH' */
    3722 +#define NVRAM_CLEAR_MAGIC              0x0
    3723 +#define NVRAM_INVALID_MAGIC    0xFFFFFFFF
    37241134+#define NVRAM_VERSION          1
    37251135+#define NVRAM_HEADER_SIZE      20
    37261136+#define NVRAM_SPACE            0x8000
    37271137+
    3728 +#define NVRAM_MAX_VALUE_LEN 255
    3729 +#define NVRAM_MAX_PARAM_LEN 64
    3730 +
    37311138+#endif /* _bcmnvram_h_ */
    3732 diff -urN linux.old/arch/mips/bcm947xx/include/bcmsrom.h linux.dev/arch/mips/bcm947xx/include/bcmsrom.h
    3733 --- linux.old/arch/mips/bcm947xx/include/bcmsrom.h      1970-01-01 01:00:00.000000000 +0100
    3734 +++ linux.dev/arch/mips/bcm947xx/include/bcmsrom.h      2006-04-27 20:27:33.000000000 +0200
    3735 @@ -0,0 +1,108 @@
     1139diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/bcmsrom.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmsrom.h
     1140--- linux-2.4.32/arch/mips/bcm947xx/include/bcmsrom.h   1970-01-01 01:00:00.000000000 +0100
     1141+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmsrom.h   2006-07-02 21:58:25.000000000 +0200
     1142@@ -0,0 +1,22 @@
    37361143+/*
    37371144+ * Misc useful routines to access NIC local SROM/OTP .
    37381145+ *
    3739 + * Copyright 2006, Broadcom Corporation
     1146+ * Copyright 2005, Broadcom Corporation
    37401147+ * All Rights Reserved.
    37411148+ *
     
    37451152+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    37461153+ *
    3747 + * $Id: bcmsrom.h,v 1.1.1.13 2006/04/15 01:29:08 michael Exp $
     1154+ * $Id$
    37481155+ */
    37491156+
     
    37511158+#define        _bcmsrom_h_
    37521159+
    3753 +/* Maximum srom: 4 Kilobits == 512 bytes */
    3754 +#define        SROM_MAX        512
    3755 +
    3756 +/* SROM Rev 4: Reallocate the software part of the srom to accomodate
    3757 + * MIMO features. It assumes up to two PCIE functions and 440 bytes
    3758 + * of useable srom i.e. the useable storage in chips with OTP that
    3759 + * implements hardware redundancy.
    3760 + */
    3761 +
    3762 +#define        SROM4_WORDS             220
    3763 +
    3764 +#define        SROM4_SIGN              32
    3765 +#define        SROM4_SIGNATURE         0x5372
    3766 +
    3767 +#define        SROM4_BREV              33
    3768 +
    3769 +#define        SROM4_BFL0              34
    3770 +#define        SROM4_BFL1              35
    3771 +#define        SROM4_BFL2              36
    3772 +#define        SROM4_BFL3              37
    3773 +
    3774 +#define        SROM4_MACHI             38
    3775 +#define        SROM4_MACMID            39
    3776 +#define        SROM4_MACLO             40
    3777 +
    3778 +#define        SROM4_CCODE             41
    3779 +#define        SROM4_REGREV            42
    3780 +
    3781 +#define        SROM4_LEDBH10           43
    3782 +#define        SROM4_LEDBH32           44
    3783 +
    3784 +#define        SROM4_LEDDC             45
    3785 +
    3786 +#define        SROM4_AA                46
    3787 +#define        SROM4_AA2G_MASK         0x00ff
    3788 +#define        SROM4_AA2G_SHIFT        0
    3789 +#define        SROM4_AA5G_MASK         0xff00
    3790 +#define        SROM4_AA5G_SHIFT        8
    3791 +
    3792 +#define        SROM4_AG10              47
    3793 +#define        SROM4_AG32              48
    3794 +
    3795 +#define        SROM4_TXPID2G           49
    3796 +#define        SROM4_TXPID5G           51
    3797 +#define        SROM4_TXPID5GL          53
    3798 +#define        SROM4_TXPID5GH          55
    3799 +
    3800 +/* Per-path fields */
    3801 +#define        MAX_PATH                4
    3802 +#define        SROM4_PATH0             64
    3803 +#define        SROM4_PATH1             87
    3804 +#define        SROM4_PATH2             110
    3805 +#define        SROM4_PATH3             133
    3806 +
    3807 +#define        SROM4_2G_ITT_MAXP       0
    3808 +#define        SROM4_2G_PA             1
    3809 +#define        SROM4_5G_ITT_MAXP       5
    3810 +#define        SROM4_5GLH_MAXP         6
    3811 +#define        SROM4_5G_PA             7
    3812 +#define        SROM4_5GL_PA            11
    3813 +#define        SROM4_5GH_PA            15
    3814 +
    3815 +/* Fields in the ITT_MAXP and 5GLH_MAXP words */
    3816 +#define        B2G_MAXP_MASK           0xff
    3817 +#define        B2G_ITT_SHIFT           8
    3818 +#define        B5G_MAXP_MASK           0xff
    3819 +#define        B5G_ITT_SHIFT           8
    3820 +#define        B5GH_MAXP_MASK          0xff
    3821 +#define        B5GL_MAXP_SHIFT         8
    3822 +
    3823 +/* All the miriad power offsets */
    3824 +#define        SROM4_2G_CCKPO          156
    3825 +#define        SROM4_2G_OFDMPO         157
    3826 +#define        SROM4_5G_OFDMPO         159
    3827 +#define        SROM4_5GL_OFDMPO        161
    3828 +#define        SROM4_5GH_OFDMPO        163
    3829 +#define        SROM4_2G_MCSPO          165
    3830 +#define        SROM4_5G_MCSPO          173
    3831 +#define        SROM4_5GL_MCSPO         181
    3832 +#define        SROM4_5GH_MCSPO         189
    3833 +#define        SROM4_CCDPO             197
    3834 +#define        SROM4_STBCPO            198
    3835 +#define        SROM4_BW40PO            199
    3836 +#define        SROM4_BWDUPPO           200
    3837 +
    3838 +extern int srom_var_init(void *sbh, uint bus, void *curmap, osl_t *osh, char **vars, uint *count);
    3839 +
    3840 +extern int srom_read(uint bus, void *curmap, osl_t *osh, uint byteoff, uint nbytes, uint16 *buf);
    3841 +extern int srom_write(uint bus, void *curmap, osl_t *osh, uint byteoff, uint nbytes, uint16 *buf);
    3842 +
     1160+extern int srom_var_init(void *sbh, uint bus, void *curmap, void *osh, char **vars, int *count);
     1161+extern int srom_read(uint bus, void *curmap, void *osh, uint byteoff, uint nbytes, uint16 *buf);
     1162+extern int srom_write(uint bus, void *curmap, void *osh, uint byteoff, uint nbytes, uint16 *buf);
     1163+         
    38431164+#endif /* _bcmsrom_h_ */
    3844 diff -urN linux.old/arch/mips/bcm947xx/include/bcmutils.h linux.dev/arch/mips/bcm947xx/include/bcmutils.h
    3845 --- linux.old/arch/mips/bcm947xx/include/bcmutils.h     1970-01-01 01:00:00.000000000 +0100
    3846 +++ linux.dev/arch/mips/bcm947xx/include/bcmutils.h     2006-05-02 01:52:12.000000000 +0200
    3847 @@ -0,0 +1,433 @@
     1165diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/bcmutils.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmutils.h
     1166--- linux-2.4.32/arch/mips/bcm947xx/include/bcmutils.h  1970-01-01 01:00:00.000000000 +0100
     1167+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/bcmutils.h  2006-07-02 21:58:25.000000000 +0200
     1168@@ -0,0 +1,239 @@
    38481169+/*
    38491170+ * Misc useful os-independent macros and functions.
    38501171+ *
    3851 + * Copyright 2006, Broadcom Corporation
     1172+ * Copyright 2005, Broadcom Corporation
    38521173+ * All Rights Reserved.
    38531174+ *
     
    38561177+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    38571178+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    3858 + * $Id: bcmutils.h,v 1.1.1.16 2006/04/08 06:13:39 honor Exp $
     1179+ * $Id$
    38591180+ */
    38601181+
     
    38621183+#define        _bcmutils_h_
    38631184+
    3864 +/* ** driver-only section ** */
     1185+/*** driver-only section ***/
    38651186+#ifdef BCMDRIVER
     1187+#include <osl.h>
    38661188+
    38671189+#define _BCM_U 0x01    /* upper */
     
    38731195+#define _BCM_X 0x40    /* hex digit */
    38741196+#define _BCM_SP        0x80    /* hard space (0x20) */
    3875 +
    3876 +#define GPIO_PIN_NOTDEFINED    0x20    /* Pin not defined */
    38771197+
    38781198+extern unsigned char bcm_ctype[];
     
    39041224+}
    39051225+
    3906 +struct  ether_addr {
    3907 +       uint8 octet[6];
    3908 +} __attribute__((packed));
    3909 +
     1226+/* generic osl packet queue */
     1227+struct pktq {
     1228+       void *head;     /* first packet to dequeue */
     1229+       void *tail;     /* last packet to dequeue */
     1230+       uint len;       /* number of queued packets */
     1231+       uint maxlen;    /* maximum number of queued packets */
     1232+       bool priority;  /* enqueue by packet priority */
     1233+       uint8 prio_map[MAXPRIO+1]; /* user priority to packet enqueue policy map */
     1234+};
     1235+#define DEFAULT_QLEN   128
     1236+
     1237+#define        pktq_len(q)     ((q)->len)
     1238+#define        pktq_avail(q)   ((q)->maxlen - (q)->len)
     1239+#define        pktq_head(q)    ((q)->head)
     1240+#define        pktq_full(q)    ((q)->len >= (q)->maxlen)
     1241+#define        _pktq_pri(q, pri)       ((q)->prio_map[pri])
     1242+#define        pktq_tailpri(q) ((q)->tail ? _pktq_pri(q, PKTPRIO((q)->tail)) : _pktq_pri(q, 0))
     1243+
     1244+/* externs */
     1245+/* packet */
     1246+extern uint pktcopy(void *drv, void *p, uint offset, int len, uchar *buf);
     1247+extern uint pkttotlen(void *drv, void *);
     1248+extern void pktq_init(struct pktq *q, uint maxlen, const uint8 prio_map[]);
     1249+extern void pktenq(struct pktq *q, void *p, bool lifo);
     1250+extern void *pktdeq(struct pktq *q);
     1251+extern void *pktdeqtail(struct pktq *q);
    39101252+/* string */
     1253+extern uint bcm_atoi(char *s);
    39111254+extern uchar bcm_toupper(uchar c);
    39121255+extern ulong bcm_strtoul(char *cp, char **endp, uint base);
     
    39151258+extern ulong wchar2ascii(char *abuf, ushort *wbuf, ushort wbuflen, ulong abuflen);
    39161259+/* ethernet address */
    3917 +extern char *bcm_ether_ntoa(struct ether_addr *ea, char *buf);
     1260+extern char *bcm_ether_ntoa(char *ea, char *buf);
     1261+extern int bcm_ether_atoe(char *p, char *ea);
     1262+/* delay */
     1263+extern void bcm_mdelay(uint ms);
    39181264+/* variable access */
    39191265+extern char *getvar(char *vars, char *name);
    39201266+extern int getintvar(char *vars, char *name);
    39211267+extern uint getgpiopin(char *vars, char *pin_name, uint def_pin);
    3922 +#ifdef BCMPERFSTATS
    3923 +extern void bcm_perf_enable(void);
    3924 +extern void bcmstats(char *fmt);
    3925 +extern void bcmlog(char *fmt, uint a1, uint a2);
    3926 +extern void bcmdumplog(char *buf, int size);
    3927 +extern int bcmdumplogent(char *buf, uint idx);
    3928 +#else
    3929 +#define bcm_perf_enable()
    3930 +#define bcmstats(fmt)
    39311268+#define        bcmlog(fmt, a1, a2)
    39321269+#define        bcmdumplog(buf, size)   *buf = '\0'
    39331270+#define        bcmdumplogent(buf, idx) -1
    3934 +#endif /* BCMPERFSTATS */
    3935 +extern char *bcm_nvram_vars(uint *length);
    3936 +extern int bcm_nvram_cache(void *sbh);
    3937 +
    3938 +/* Support for sharing code across in-driver iovar implementations.
    3939 + * The intent is that a driver use this structure to map iovar names
    3940 + * to its (private) iovar identifiers, and the lookup function to
    3941 + * find the entry.  Macros are provided to map ids and get/set actions
    3942 + * into a single number space for a switch statement.
    3943 + */
    3944 +
    3945 +/* iovar structure */
    3946 +typedef struct bcm_iovar {
    3947 +       const char *name;       /* name for lookup and display */
    3948 +       uint16 varid;           /* id for switch */
    3949 +       uint16 flags;           /* driver-specific flag bits */
    3950 +       uint16 type;            /* base type of argument */
    3951 +       uint16 minlen;          /* min length for buffer vars */
    3952 +} bcm_iovar_t;
    3953 +
    3954 +/* varid definitions are per-driver, may use these get/set bits */
    3955 +
    3956 +/* IOVar action bits for id mapping */
    3957 +#define IOV_GET 0 /* Get an iovar */
    3958 +#define IOV_SET 1 /* Set an iovar */
    3959 +
    3960 +/* Varid to actionid mapping */
    3961 +#define IOV_GVAL(id)           ((id)*2)
    3962 +#define IOV_SVAL(id)           (((id)*2)+IOV_SET)
    3963 +#define IOV_ISSET(actionid)    ((actionid & IOV_SET) == IOV_SET)
    3964 +
    3965 +/* flags are per-driver based on driver attributes */
    3966 +
    3967 +/* Base type definitions */
    3968 +#define IOVT_VOID      0       /* no value (implictly set only) */
    3969 +#define IOVT_BOOL      1       /* any value ok (zero/nonzero) */
    3970 +#define IOVT_INT8      2       /* integer values are range-checked */
    3971 +#define IOVT_UINT8     3       /* unsigned int 8 bits */
    3972 +#define IOVT_INT16     4       /* int 16 bits */
    3973 +#define IOVT_UINT16    5       /* unsigned int 16 bits */
    3974 +#define IOVT_INT32     6       /* int 32 bits */
    3975 +#define IOVT_UINT32    7       /* unsigned int 32 bits */
    3976 +#define IOVT_BUFFER    8       /* buffer is size-checked as per minlen */
    3977 +
    3978 +extern const bcm_iovar_t *bcm_iovar_lookup(const bcm_iovar_t *table, const char *name);
    3979 +extern int bcm_iovar_lencheck(const bcm_iovar_t *table, void *arg, int len, bool set);
    3980 +
    39811271+#endif /* #ifdef BCMDRIVER */
    39821272+
    3983 +/* ** driver/apps-shared section ** */
    3984 +
    3985 +#define BCME_STRLEN            64      /* Max string length for BCM errors */
    3986 +#define VALID_BCMERROR(e)  ((e <= 0) && (e >= BCME_LAST))
    3987 +
    3988 +
    3989 +/*
    3990 + * error codes could be added but the defined ones shouldn't be changed/deleted
    3991 + * these error codes are exposed to the user code
    3992 + * when ever a new error code is added to this list
    3993 + * please update errorstring table with the related error string and
    3994 + * update osl files with os specific errorcode map
    3995 +*/
    3996 +
    3997 +#define BCME_OK                                0       /* Success */
    3998 +#define BCME_ERROR                     -1      /* Error generic */
    3999 +#define BCME_BADARG                    -2      /* Bad Argument */
    4000 +#define BCME_BADOPTION                 -3      /* Bad option */
    4001 +#define BCME_NOTUP                     -4      /* Not up */
    4002 +#define BCME_NOTDOWN                   -5      /* Not down */
    4003 +#define BCME_NOTAP                     -6      /* Not AP */
    4004 +#define BCME_NOTSTA                    -7      /* Not STA  */
    4005 +#define BCME_BADKEYIDX                 -8      /* BAD Key Index */
    4006 +#define BCME_RADIOOFF                  -9      /* Radio Off */
    4007 +#define BCME_NOTBANDLOCKED             -10     /* Not  band locked */
    4008 +#define BCME_NOCLK                     -11     /* No Clock */
    4009 +#define BCME_BADRATESET                        -12     /* BAD Rate valueset */
    4010 +#define BCME_BADBAND                   -13     /* BAD Band */
    4011 +#define BCME_BUFTOOSHORT               -14     /* Buffer too short */
    4012 +#define BCME_BUFTOOLONG                        -15     /* Buffer too long */
    4013 +#define BCME_BUSY                      -16     /* Busy */
    4014 +#define BCME_NOTASSOCIATED             -17     /* Not Associated */
    4015 +#define BCME_BADSSIDLEN                        -18     /* Bad SSID len */
    4016 +#define BCME_OUTOFRANGECHAN            -19     /* Out of Range Channel */
    4017 +#define BCME_BADCHAN                   -20     /* Bad Channel */
    4018 +#define BCME_BADADDR                   -21     /* Bad Address */
    4019 +#define BCME_NORESOURCE                        -22     /* Not Enough Resources */
    4020 +#define BCME_UNSUPPORTED               -23     /* Unsupported */
    4021 +#define BCME_BADLEN                    -24     /* Bad length */
    4022 +#define BCME_NOTREADY                  -25     /* Not Ready */
    4023 +#define BCME_EPERM                     -26     /* Not Permitted */
    4024 +#define BCME_NOMEM                     -27     /* No Memory */
    4025 +#define BCME_ASSOCIATED                        -28     /* Associated */
    4026 +#define BCME_RANGE                     -29     /* Not In Range */
    4027 +#define BCME_NOTFOUND                  -30     /* Not Found */
    4028 +#define BCME_WME_NOT_ENABLED           -31     /* WME Not Enabled */
    4029 +#define BCME_TSPEC_NOTFOUND            -32     /* TSPEC Not Found */
    4030 +#define BCME_ACM_NOTSUPPORTED          -33     /* ACM Not Supported */
    4031 +#define BCME_NOT_WME_ASSOCIATION       -34     /* Not WME Association */
    4032 +#define BCME_SDIO_ERROR                        -35     /* SDIO Bus Error */
    4033 +#define BCME_DONGLE_DOWN               -36     /* Dongle Not Accessible */
    4034 +#define BCME_LAST                      BCME_DONGLE_DOWN
    4035 +
    4036 +/* These are collection of BCME Error strings */
    4037 +#define BCMERRSTRINGTABLE {            \
    4038 +       "OK",                           \
    4039 +       "Undefined error",              \
    4040 +       "Bad Argument",                 \
    4041 +       "Bad Option",                   \
    4042 +       "Not up",                       \
    4043 +       "Not down",                     \
    4044 +       "Not AP",                       \
    4045 +       "Not STA",                      \
    4046 +       "Bad Key Index",                \
    4047 +       "Radio Off",                    \
    4048 +       "Not band locked",              \
    4049 +       "No clock",                     \
    4050 +       "Bad Rate valueset",            \
    4051 +       "Bad Band",                     \
    4052 +       "Buffer too short",             \
    4053 +       "Buffer too long",              \
    4054 +       "Busy",                         \
    4055 +       "Not Associated",               \
    4056 +       "Bad SSID len",                 \
    4057 +       "Out of Range Channel",         \
    4058 +       "Bad Channel",                  \
    4059 +       "Bad Address",                  \
    4060 +       "Not Enough Resources",         \
    4061 +       "Unsupported",                  \
    4062 +       "Bad length",                   \
    4063 +       "Not Ready",                    \
    4064 +       "Not Permitted",                \
    4065 +       "No Memory",                    \
    4066 +       "Associated",                   \
    4067 +       "Not In Range",                 \
    4068 +       "Not Found",                    \
    4069 +       "WME Not Enabled",              \
    4070 +       "TSPEC Not Found",              \
    4071 +       "ACM Not Supported",            \
    4072 +       "Not WME Association",          \
    4073 +       "SDIO Bus Error",               \
    4074 +       "Dongle Not Accessible"         \
    4075 +}
    4076 +
    4077 +#ifndef ABS
    4078 +#define        ABS(a)                  (((a) < 0)?-(a):(a))
    4079 +#endif /* ABS */
    4080 +
     1273+/*** driver/apps-shared section ***/
    40811274+#ifndef MIN
    4082 +#define        MIN(a, b)               (((a) < (b))?(a):(b))
    4083 +#endif /* MIN */
     1275+#define        MIN(a, b)               (((a)<(b))?(a):(b))
     1276+#endif
    40841277+
    40851278+#ifndef MAX
    4086 +#define        MAX(a, b)               (((a) > (b))?(a):(b))
    4087 +#endif /* MAX */
     1279+#define        MAX(a, b)               (((a)>(b))?(a):(b))
     1280+#endif
    40881281+
    40891282+#define CEIL(x, y)             (((x) + ((y)-1)) / (y))
    40901283+#define        ROUNDUP(x, y)           ((((x)+((y)-1))/(y))*(y))
    40911284+#define        ISALIGNED(a, x)         (((a) & ((x)-1)) == 0)
    4092 +#define        ISPOWEROF2(x)           ((((x)-1)&(x)) == 0)
    4093 +#define VALID_MASK(mask)       !((mask) & ((mask) + 1))
     1285+#define        ISPOWEROF2(x)           ((((x)-1)&(x))==0)
    40941286+#define        OFFSETOF(type, member)  ((uint)(uintptr)&((type *)0)->member)
    40951287+#define ARRAYSIZE(a)           (sizeof(a)/sizeof(a[0]))
     
    40971289+/* bit map related macros */
    40981290+#ifndef setbit
    4099 +#ifndef NBBY               /* the BSD family defines NBBY */
    41001291+#define        NBBY    8       /* 8 bits per byte */
    4101 +#endif /* #ifndef NBBY */
    4102 +#define        setbit(a, i)    (((uint8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
    4103 +#define        clrbit(a, i)    (((uint8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
    4104 +#define        isset(a, i)     (((uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
    4105 +#define        isclr(a, i)     ((((uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
    4106 +#endif /* setbit */
    4107 +
    4108 +#define        NBITS(type)     (sizeof(type) * 8)
    4109 +#define NBITVAL(nbits) (1 << (nbits))
    4110 +#define MAXBITVAL(nbits)       ((1 << (nbits)) - 1)
    4111 +#define        NBITMASK(nbits) MAXBITVAL(nbits)
    4112 +#define MAXNBVAL(nbyte)        MAXBITVAL((nbyte) * 8)
    4113 +
    4114 +/* basic mux operation - can be optimized on several architectures */
    4115 +#define MUX(pred, true, false) ((pred) ? (true) : (false))
    4116 +
    4117 +/* modulo inc/dec - assumes x E [0, bound - 1] */
    4118 +#define MODDEC(x, bound) MUX((x) == 0, (bound) - 1, (x) - 1)
    4119 +#define MODINC(x, bound) MUX((x) == (bound) - 1, 0, (x) + 1)
    4120 +
    4121 +/* modulo inc/dec, bound = 2^k */
    4122 +#define MODDEC_POW2(x, bound) (((x) - 1) & ((bound) - 1))
    4123 +#define MODINC_POW2(x, bound) (((x) + 1) & ((bound) - 1))
    4124 +
    4125 +/* modulo add/sub - assumes x, y E [0, bound - 1] */
    4126 +#define MODADD(x, y, bound) \
    4127 +    MUX((x) + (y) >= (bound), (x) + (y) - (bound), (x) + (y))
    4128 +#define MODSUB(x, y, bound) \
    4129 +    MUX(((int)(x)) - ((int)(y)) < 0, (x) - (y) + (bound), (x) - (y))
    4130 +
    4131 +/* module add/sub, bound = 2^k */
    4132 +#define MODADD_POW2(x, y, bound) (((x) + (y)) & ((bound) - 1))
    4133 +#define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1))
     1292+#define        setbit(a,i)     (((uint8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
     1293+#define        clrbit(a,i)     (((uint8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
     1294+#define        isset(a,i)      (((uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
     1295+#define        isclr(a,i)      ((((uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
     1296+#endif
     1297+
     1298+#define        NBITS(type)     (sizeof (type) * 8)
    41341299+
    41351300+/* crc defines */
     
    41551320+
    41561321+/* Check that bcm_tlv_t fits into the given buflen */
    4157 +#define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (int)(buflen) >= (int)(2 + (elt)->len))
     1322+#define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (buflen) >= 2 + (elt)->len)
    41581323+
    41591324+/* buffer length for ethernet address from bcm_ether_ntoa() */
    4160 +#define ETHER_ADDR_STR_LEN     18      /* 18-bytes of Ethernet address buffer length */
     1325+#define ETHER_ADDR_STR_LEN     18
    41611326+
    41621327+/* unaligned load and store macros */
     
    42201385+}
    42211386+
    4222 +#endif /* IL_BIGENDIAN */
     1387+#endif
    42231388+
    42241389+/* externs */
     
    42281393+extern uint32 hndcrc32(uint8 *p, uint nbytes, uint32 crc);
    42291394+/* format/print */
    4230 +extern void printfbig(char *buf);
    4231 +
    42321395+/* IE parsing */
    42331396+extern bcm_tlv_t *bcm_next_tlv(bcm_tlv_t *elt, int *buflen);
    42341397+extern bcm_tlv_t *bcm_parse_tlvs(void *buf, int buflen, uint key);
    42351398+extern bcm_tlv_t *bcm_parse_ordered_tlvs(void *buf, int buflen, uint key);
    4236 +
    4237 +/* bcmerror */
    4238 +extern const char *bcmerrorstr(int bcmerror);
    42391399+
    42401400+/* multi-bool data type: set of bools, mbool is true if any is set */
     
    42451405+#define        mboolmaskset(mb, mask, val)     ((mb) = (((mb) & ~(mask)) | (val)))
    42461406+
    4247 +/* power conversion */
    4248 +extern uint16 bcm_qdbm_to_mw(uint8 qdbm);
    4249 +extern uint8 bcm_mw_to_qdbm(uint16 mw);
    4250 +
    4251 +/* generic datastruct to help dump routines */
    4252 +struct fielddesc {
    4253 +       char    *nameandfmt;
    4254 +       uint32  offset;
    4255 +       uint32  len;
    4256 +};
    4257 +
    4258 +/* Buffer structure for collecting string-formatted data
    4259 +* using bcm_bprintf() API.
    4260 +* Use bcm_binit() to initialize before use
    4261 +*/
    4262 +struct bcmstrbuf
    4263 +{
    4264 +       char *buf;      /* pointer to current position in origbuf */
    4265 +       uint size;      /* current (residual) size in bytes */
    4266 +       char *origbuf;  /* unmodified pointer to orignal buffer */
    4267 +       uint origsize;  /* unmodified orignal buffer size in bytes */
    4268 +};
    4269 +
    4270 +extern void bcm_binit(struct bcmstrbuf *b, char *buf, uint size);
    4271 +extern int bcm_bprintf(struct bcmstrbuf *b, const char *fmt, ...);
    4272 +
    4273 +typedef  uint32 (*readreg_rtn)(void *arg0, void *arg1, uint32 offset);
    4274 +extern uint bcmdumpfields(readreg_rtn func_ptr, void *arg0, void *arg1, struct fielddesc *str,
    4275 +                          char *buf, uint32 bufsize);
    4276 +
    4277 +extern uint bcm_mkiovar(char *name, char *data, uint datalen, char *buf, uint len);
    4278 +extern uint bcm_bitcount(uint8 *bitmap, uint bytelength);
    4279 +
    42801407+#endif /* _bcmutils_h_ */
    4281 diff -urN linux.old/arch/mips/bcm947xx/include/hndcpu.h linux.dev/arch/mips/bcm947xx/include/hndcpu.h
    4282 --- linux.old/arch/mips/bcm947xx/include/hndcpu.h       1970-01-01 01:00:00.000000000 +0100
    4283 +++ linux.dev/arch/mips/bcm947xx/include/hndcpu.h       2006-04-27 22:14:38.000000000 +0200
    4284 @@ -0,0 +1,28 @@
     1408diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/hnddma.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/hnddma.h
     1409--- linux-2.4.32/arch/mips/bcm947xx/include/hnddma.h    1970-01-01 01:00:00.000000000 +0100
     1410+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/hnddma.h    2006-07-02 21:58:25.000000000 +0200
     1411@@ -0,0 +1,184 @@
    42851412+/*
    4286 + * HND SiliconBackplane MIPS/ARM cores software interface.
     1413+ * Generic Broadcom Home Networking Division (HND) DMA engine definitions.
     1414+ * This supports the following chips: BCM42xx, 44xx, 47xx .
    42871415+ *
    4288 + * Copyright 2006, Broadcom Corporation
     1416+ * Copyright 2005, Broadcom Corporation     
     1417+ * All Rights Reserved.     
     1418+ *       
     1419+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     1420+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     1421+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     1422+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     1423+ * $Id$
     1424+ */
     1425+
     1426+#ifndef        _hnddma_h_
     1427+#define        _hnddma_h_
     1428+
     1429+/*
     1430+ * Each DMA processor consists of a transmit channel and a receive channel.
     1431+ */
     1432+typedef volatile struct {
     1433+       /* transmit channel */
     1434+       uint32  xmtcontrol;                     /* enable, et al */
     1435+       uint32  xmtaddr;                        /* descriptor ring base address (4K aligned) */
     1436+       uint32  xmtptr;                         /* last descriptor posted to chip */
     1437+       uint32  xmtstatus;                      /* current active descriptor, et al */
     1438+
     1439+       /* receive channel */
     1440+       uint32  rcvcontrol;                     /* enable, et al */
     1441+       uint32  rcvaddr;                        /* descriptor ring base address (4K aligned) */
     1442+       uint32  rcvptr;                         /* last descriptor posted to chip */
     1443+       uint32  rcvstatus;                      /* current active descriptor, et al */
     1444+} dmaregs_t;
     1445+
     1446+typedef volatile struct {
     1447+       /* diag access */
     1448+       uint32  fifoaddr;                       /* diag address */
     1449+       uint32  fifodatalow;                    /* low 32bits of data */
     1450+       uint32  fifodatahigh;                   /* high 32bits of data */
     1451+       uint32  pad;                            /* reserved */
     1452+} dmafifo_t;
     1453+
     1454+/* transmit channel control */
     1455+#define        XC_XE           ((uint32)1 << 0)        /* transmit enable */
     1456+#define        XC_SE           ((uint32)1 << 1)        /* transmit suspend request */
     1457+#define        XC_LE           ((uint32)1 << 2)        /* loopback enable */
     1458+#define        XC_FL           ((uint32)1 << 4)        /* flush request */
     1459+
     1460+/* transmit descriptor table pointer */
     1461+#define        XP_LD_MASK      0xfff                   /* last valid descriptor */
     1462+
     1463+/* transmit channel status */
     1464+#define        XS_CD_MASK      0x0fff                  /* current descriptor pointer */
     1465+#define        XS_XS_MASK      0xf000                  /* transmit state */
     1466+#define        XS_XS_SHIFT     12
     1467+#define        XS_XS_DISABLED  0x0000                  /* disabled */
     1468+#define        XS_XS_ACTIVE    0x1000                  /* active */
     1469+#define        XS_XS_IDLE      0x2000                  /* idle wait */
     1470+#define        XS_XS_STOPPED   0x3000                  /* stopped */
     1471+#define        XS_XS_SUSP      0x4000                  /* suspend pending */
     1472+#define        XS_XE_MASK      0xf0000                 /* transmit errors */
     1473+#define        XS_XE_SHIFT     16
     1474+#define        XS_XE_NOERR     0x00000                 /* no error */
     1475+#define        XS_XE_DPE       0x10000                 /* descriptor protocol error */
     1476+#define        XS_XE_DFU       0x20000                 /* data fifo underrun */
     1477+#define        XS_XE_BEBR      0x30000                 /* bus error on buffer read */
     1478+#define        XS_XE_BEDA      0x40000                 /* bus error on descriptor access */
     1479+#define        XS_AD_MASK      0xfff00000              /* active descriptor */
     1480+#define        XS_AD_SHIFT     20
     1481+
     1482+/* receive channel control */
     1483+#define        RC_RE           ((uint32)1 << 0)        /* receive enable */
     1484+#define        RC_RO_MASK      0xfe                    /* receive frame offset */
     1485+#define        RC_RO_SHIFT     1
     1486+#define        RC_FM           ((uint32)1 << 8)        /* direct fifo receive (pio) mode */
     1487+
     1488+/* receive descriptor table pointer */
     1489+#define        RP_LD_MASK      0xfff                   /* last valid descriptor */
     1490+
     1491+/* receive channel status */
     1492+#define        RS_CD_MASK      0x0fff                  /* current descriptor pointer */
     1493+#define        RS_RS_MASK      0xf000                  /* receive state */
     1494+#define        RS_RS_SHIFT     12
     1495+#define        RS_RS_DISABLED  0x0000                  /* disabled */
     1496+#define        RS_RS_ACTIVE    0x1000                  /* active */
     1497+#define        RS_RS_IDLE      0x2000                  /* idle wait */
     1498+#define        RS_RS_STOPPED   0x3000                  /* reserved */
     1499+#define        RS_RE_MASK      0xf0000                 /* receive errors */
     1500+#define        RS_RE_SHIFT     16
     1501+#define        RS_RE_NOERR     0x00000                 /* no error */
     1502+#define        RS_RE_DPE       0x10000                 /* descriptor protocol error */
     1503+#define        RS_RE_DFO       0x20000                 /* data fifo overflow */
     1504+#define        RS_RE_BEBW      0x30000                 /* bus error on buffer write */
     1505+#define        RS_RE_BEDA      0x40000                 /* bus error on descriptor access */
     1506+#define        RS_AD_MASK      0xfff00000              /* active descriptor */
     1507+#define        RS_AD_SHIFT     20
     1508+
     1509+/* fifoaddr */
     1510+#define        FA_OFF_MASK     0xffff                  /* offset */
     1511+#define        FA_SEL_MASK     0xf0000                 /* select */
     1512+#define        FA_SEL_SHIFT    16
     1513+#define        FA_SEL_XDD      0x00000                 /* transmit dma data */
     1514+#define        FA_SEL_XDP      0x10000                 /* transmit dma pointers */
     1515+#define        FA_SEL_RDD      0x40000                 /* receive dma data */
     1516+#define        FA_SEL_RDP      0x50000                 /* receive dma pointers */
     1517+#define        FA_SEL_XFD      0x80000                 /* transmit fifo data */
     1518+#define        FA_SEL_XFP      0x90000                 /* transmit fifo pointers */
     1519+#define        FA_SEL_RFD      0xc0000                 /* receive fifo data */
     1520+#define        FA_SEL_RFP      0xd0000                 /* receive fifo pointers */
     1521+
     1522+/*
     1523+ * DMA Descriptor
     1524+ * Descriptors are only read by the hardware, never written back.
     1525+ */
     1526+typedef volatile struct {
     1527+       uint32  ctrl;           /* misc control bits & bufcount */
     1528+       uint32  addr;           /* data buffer address */
     1529+} dmadd_t;
     1530+
     1531+/*
     1532+ * Each descriptor ring must be 4096byte aligned
     1533+ * and fit within a single 4096byte page.
     1534+ */
     1535+#define        DMAMAXRINGSZ    4096
     1536+#define        DMARINGALIGN    4096
     1537+
     1538+/* control flags */
     1539+#define        CTRL_BC_MASK    0x1fff                  /* buffer byte count */
     1540+#define        CTRL_EOT        ((uint32)1 << 28)       /* end of descriptor table */
     1541+#define        CTRL_IOC        ((uint32)1 << 29)       /* interrupt on completion */
     1542+#define        CTRL_EOF        ((uint32)1 << 30)       /* end of frame */
     1543+#define        CTRL_SOF        ((uint32)1 << 31)       /* start of frame */
     1544+
     1545+/* control flags in the range [27:20] are core-specific and not defined here */
     1546+#define        CTRL_CORE_MASK  0x0ff00000
     1547+
     1548+/* export structure */
     1549+typedef volatile struct {
     1550+       /* rx error counters */
     1551+       uint            rxgiants;       /* rx giant frames */
     1552+       uint            rxnobuf;        /* rx out of dma descriptors */
     1553+       /* tx error counters */
     1554+       uint            txnobuf;        /* tx out of dma descriptors */
     1555+} hnddma_t;
     1556+
     1557+#ifndef di_t
     1558+#define        di_t    void
     1559+#endif
     1560+
     1561+/* externs */
     1562+extern void * dma_attach(void *drv, void *dev, char *name, dmaregs_t *dmaregs,
     1563+       uint ntxd, uint nrxd, uint rxbufsize, uint nrxpost, uint rxoffset,
     1564+       uint ddoffset, uint dataoffset, uint *msg_level);
     1565+extern void dma_detach(di_t *di);
     1566+extern void dma_txreset(di_t *di);
     1567+extern void dma_rxreset(di_t *di);
     1568+extern void dma_txinit(di_t *di);
     1569+extern bool dma_txenabled(di_t *di);
     1570+extern void dma_rxinit(di_t *di);
     1571+extern void dma_rxenable(di_t *di);
     1572+extern bool dma_rxenabled(di_t *di);
     1573+extern void dma_txsuspend(di_t *di);
     1574+extern void dma_txresume(di_t *di);
     1575+extern bool dma_txsuspended(di_t *di);
     1576+extern bool dma_txstopped(di_t *di);
     1577+extern bool dma_rxstopped(di_t *di);
     1578+extern int dma_txfast(di_t *di, void *p, uint32 coreflags);
     1579+extern int dma_tx(di_t *di, void *p, uint32 coreflags);
     1580+extern void dma_fifoloopbackenable(di_t *di);
     1581+extern void *dma_rx(di_t *di);
     1582+extern void dma_rxfill(di_t *di);
     1583+extern void dma_txreclaim(di_t *di, bool forceall);
     1584+extern void dma_rxreclaim(di_t *di);
     1585+extern uintptr dma_getvar(di_t *di, char *name);
     1586+extern void *dma_getnexttxp(di_t *di, bool forceall);
     1587+extern void *dma_peeknexttxp(di_t *di);
     1588+extern void *dma_getnextrxp(di_t *di, bool forceall);
     1589+extern void dma_txblock(di_t *di);
     1590+extern void dma_txunblock(di_t *di);
     1591+extern uint dma_txactive(di_t *di);
     1592+extern void dma_txrotate(di_t *di);
     1593+
     1594+
     1595+#endif /* _hnddma_h_ */
     1596diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/hndmips.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/hndmips.h
     1597--- linux-2.4.32/arch/mips/bcm947xx/include/hndmips.h   1970-01-01 01:00:00.000000000 +0100
     1598+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/hndmips.h   2006-07-02 21:58:25.000000000 +0200
     1599@@ -0,0 +1,16 @@
     1600+/*
     1601+ * Alternate include file for HND sbmips.h since CFE also ships with
     1602+ * a sbmips.h.
     1603+ *
     1604+ * Copyright 2005, Broadcom Corporation
    42891605+ * All Rights Reserved.
    42901606+ *
     
    42941610+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    42951611+ *
    4296 + * $Id: hndcpu.h,v 1.1.1.1 2006/02/27 03:43:16 honor Exp $
     1612+ * $Id$
    42971613+ */
    42981614+
    4299 +#ifndef _hndcpu_h_
    4300 +#define _hndcpu_h_
    4301 +
    4302 +#if defined(mips)
    4303 +#include <hndmips.h>
    4304 +#elif defined(__ARM_ARCH_4T__)
    4305 +#include <hndarm.h>
    4306 +#endif
    4307 +
    4308 +extern uint sb_irq(sb_t *sbh);
    4309 +extern uint32 sb_cpu_clock(sb_t *sbh);
    4310 +extern void sb_cpu_wait(void);
    4311 +
    4312 +#endif /* _hndcpu_h_ */
    4313 diff -urN linux.old/arch/mips/bcm947xx/include/hndmips.h linux.dev/arch/mips/bcm947xx/include/hndmips.h
    4314 --- linux.old/arch/mips/bcm947xx/include/hndmips.h      1970-01-01 01:00:00.000000000 +0100
    4315 +++ linux.dev/arch/mips/bcm947xx/include/hndmips.h      2006-04-27 20:43:42.000000000 +0200
    4316 @@ -0,0 +1,45 @@
     1615+#include "sbmips.h"
     1616diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/linux_osl.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/linux_osl.h
     1617--- linux-2.4.32/arch/mips/bcm947xx/include/linux_osl.h 1970-01-01 01:00:00.000000000 +0100
     1618+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/linux_osl.h 2006-07-02 21:58:25.000000000 +0200
     1619@@ -0,0 +1,341 @@
    43171620+/*
    4318 + * HND SiliconBackplane MIPS core software interface.
     1621+ * Linux OS Independent Layer
    43191622+ *
    4320 + * Copyright 2006, Broadcom Corporation
     1623+ * Copyright 2005, Broadcom Corporation
    43211624+ * All Rights Reserved.
    43221625+ *
     
    43261629+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    43271630+ *
    4328 + * $Id: hndmips.h,v 1.1.1.8 2006/02/27 03:43:16 honor Exp $
     1631+ * $Id$
    43291632+ */
    43301633+
    4331 +#ifndef _hndmips_h_
    4332 +#define _hndmips_h_
    4333 +
    4334 +extern void sb_mips_init(sb_t *sbh, uint shirq_map_base);
    4335 +extern bool sb_mips_setclock(sb_t *sbh, uint32 mipsclock, uint32 sbclock, uint32 pciclock);
    4336 +extern void enable_pfc(uint32 mode);
    4337 +extern uint32 sb_memc_get_ncdl(sb_t *sbh);
    4338 +
    4339 +#if defined(BCMPERFSTATS)
    4340 +/* enable counting - exclusive version. Only one set of counters allowed at a time */
    4341 +extern void hndmips_perf_instrcount_enable(void);
    4342 +extern void hndmips_perf_icachecount_enable(void);
    4343 +extern void hndmips_perf_dcachecount_enable(void);
    4344 +/* start and stop counting */
    4345 +#define hndmips_perf_start01() \
    4346 +       MTC0(C0_PERFORMANCE, 4, MFC0(C0_PERFORMANCE, 4) | 0x80008000)
    4347 +#define hndmips_perf_stop01() \
    4348 +       MTC0(C0_PERFORMANCE, 4, MFC0(C0_PERFORMANCE, 4) & ~0x80008000)
    4349 +/* retrieve coutners - counters *decrement* */
    4350 +#define hndmips_perf_read0() -(long)(MFC0(C0_PERFORMANCE, 0))
    4351 +#define hndmips_perf_read1() -(long)(MFC0(C0_PERFORMANCE, 1))
    4352 +#define hndmips_perf_read2() -(long)(MFC0(C0_PERFORMANCE, 2))
    4353 +/* enable counting - modular version. Each counters can be enabled separately. */
    4354 +extern void hndmips_perf_icache_hit_enable(void);
    4355 +extern void hndmips_perf_icache_miss_enable(void);
    4356 +extern uint32 hndmips_perf_read_instrcount(void);
    4357 +extern uint32 hndmips_perf_read_cache_miss(void);
    4358 +extern uint32 hndmips_perf_read_cache_hit(void);
    4359 +#endif /*  defined(BCMINTERNAL) || defined (BCMPERFSTATS) */
    4360 +
    4361 +#endif /* _hndmips_h_ */
    4362 diff -urN linux.old/arch/mips/bcm947xx/include/hndpci.h linux.dev/arch/mips/bcm947xx/include/hndpci.h
    4363 --- linux.old/arch/mips/bcm947xx/include/hndpci.h       1970-01-01 01:00:00.000000000 +0100
    4364 +++ linux.dev/arch/mips/bcm947xx/include/hndpci.h       2006-04-27 20:36:48.000000000 +0200
    4365 @@ -0,0 +1,30 @@
     1634+#ifndef _linux_osl_h_
     1635+#define _linux_osl_h_
     1636+
     1637+#include <typedefs.h>
     1638+
     1639+/* use current 2.4.x calling conventions */
     1640+#include <linuxver.h>
     1641+
     1642+/* assert and panic */
     1643+#define        ASSERT(exp)             do {} while (0)
     1644+
     1645+/* PCMCIA attribute space access macros */
     1646+#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
     1647+struct pcmcia_dev {
     1648+       dev_link_t link;        /* PCMCIA device pointer */
     1649+       dev_node_t node;        /* PCMCIA node structure */
     1650+       void *base;             /* Mapped attribute memory window */
     1651+       size_t size;            /* Size of window */
     1652+       void *drv;              /* Driver data */
     1653+};
     1654+#endif
     1655+#define        OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
     1656+       osl_pcmcia_read_attr((osh), (offset), (buf), (size))
     1657+#define        OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
     1658+       osl_pcmcia_write_attr((osh), (offset), (buf), (size))
     1659+extern void osl_pcmcia_read_attr(void *osh, uint offset, void *buf, int size);
     1660+extern void osl_pcmcia_write_attr(void *osh, uint offset, void *buf, int size);
     1661+
     1662+/* PCI configuration space access macros */
     1663+#define        OSL_PCI_READ_CONFIG(osh, offset, size) \
     1664+       osl_pci_read_config((osh), (offset), (size))
     1665+#define        OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
     1666+       osl_pci_write_config((osh), (offset), (size), (val))
     1667+extern uint32 osl_pci_read_config(void *osh, uint size, uint offset);
     1668+extern void osl_pci_write_config(void *osh, uint offset, uint size, uint val);
     1669+
     1670+/* OSL initialization */
     1671+extern void *osl_attach(void *pdev);
     1672+extern void osl_detach(void *osh);
     1673+
     1674+/* host/bus architecture-specific byte swap */
     1675+#define BUS_SWAP32(v)          (v)
     1676+
     1677+/* general purpose memory allocation */
     1678+
     1679+#if defined(BCMDBG_MEM)
     1680+
     1681+#define        MALLOC(osh, size)       osl_debug_malloc((osh), (size), __LINE__, __FILE__)
     1682+#define        MFREE(osh, addr, size)  osl_debug_mfree((osh), (addr), (size), __LINE__, __FILE__)
     1683+#define MALLOCED(osh)          osl_malloced((osh))
     1684+#define        MALLOC_DUMP(osh, buf, sz) osl_debug_memdump((osh), (buf), (sz))
     1685+extern void *osl_debug_malloc(void *osh, uint size, int line, char* file);
     1686+extern void osl_debug_mfree(void *osh, void *addr, uint size, int line, char* file);
     1687+extern char *osl_debug_memdump(void *osh, char *buf, uint sz);
     1688+
     1689+#else
     1690+
     1691+#define        MALLOC(osh, size)       osl_malloc((osh), (size))
     1692+#define        MFREE(osh, addr, size)  osl_mfree((osh), (addr), (size))
     1693+#define MALLOCED(osh)          osl_malloced((osh))
     1694+
     1695+#endif /* BCMDBG_MEM */
     1696+
     1697+#define        MALLOC_FAILED(osh)      osl_malloc_failed((osh))
     1698+
     1699+extern void *osl_malloc(void *osh, uint size);
     1700+extern void osl_mfree(void *osh, void *addr, uint size);
     1701+extern uint osl_malloced(void *osh);
     1702+extern uint osl_malloc_failed(void *osh);
     1703+
     1704+/* allocate/free shared (dma-able) consistent memory */
     1705+#define        DMA_CONSISTENT_ALIGN    PAGE_SIZE
     1706+#define        DMA_ALLOC_CONSISTENT(osh, size, pap) \
     1707+       osl_dma_alloc_consistent((osh), (size), (pap))
     1708+#define        DMA_FREE_CONSISTENT(osh, va, size, pa) \
     1709+       osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
     1710+extern void *osl_dma_alloc_consistent(void *osh, uint size, ulong *pap);
     1711+extern void osl_dma_free_consistent(void *osh, void *va, uint size, ulong pa);
     1712+
     1713+/* map/unmap direction */
     1714+#define        DMA_TX  1
     1715+#define        DMA_RX  2
     1716+
     1717+/* map/unmap shared (dma-able) memory */
     1718+#define        DMA_MAP(osh, va, size, direction, p) \
     1719+       osl_dma_map((osh), (va), (size), (direction))
     1720+#define        DMA_UNMAP(osh, pa, size, direction, p) \
     1721+       osl_dma_unmap((osh), (pa), (size), (direction))
     1722+extern uint osl_dma_map(void *osh, void *va, uint size, int direction);
     1723+extern void osl_dma_unmap(void *osh, uint pa, uint size, int direction);
     1724+
     1725+/* register access macros */
     1726+#if defined(BCMJTAG)
     1727+struct bcmjtag_info;
     1728+extern uint32 bcmjtag_read(struct bcmjtag_info *ejh, uint32 addr, uint size);
     1729+extern void bcmjtag_write(struct bcmjtag_info *ejh, uint32 addr, uint32 val, uint size);
     1730+#define        R_REG(r)        bcmjtag_read(NULL, (uint32)(r), sizeof (*(r)))
     1731+#define        W_REG(r, v)     bcmjtag_write(NULL, (uint32)(r), (uint32)(v), sizeof (*(r)))
     1732+#endif
     1733+
    43661734+/*
    4367 + * HND SiliconBackplane PCI core software interface.
     1735+ * BINOSL selects the slightly slower function-call-based binary compatible osl.
     1736+ * Macros expand to calls to functions defined in linux_osl.c .
     1737+ */
     1738+#ifndef BINOSL
     1739+
     1740+/* string library, kernel mode */
     1741+#define        printf(fmt, args...)    printk(fmt, ## args)
     1742+#include <linux/kernel.h>
     1743+#include <linux/string.h>
     1744+
     1745+/* register access macros */
     1746+#if !defined(BCMJTAG)
     1747+#define R_REG(r) ( \
     1748+       sizeof(*(r)) == sizeof(uint8) ? readb((volatile uint8*)(r)) : \
     1749+       sizeof(*(r)) == sizeof(uint16) ? readw((volatile uint16*)(r)) : \
     1750+       readl((volatile uint32*)(r)) \
     1751+)
     1752+#define W_REG(r, v) do { \
     1753+       switch (sizeof(*(r))) { \
     1754+       case sizeof(uint8):     writeb((uint8)(v), (volatile uint8*)(r)); break; \
     1755+       case sizeof(uint16):    writew((uint16)(v), (volatile uint16*)(r)); break; \
     1756+       case sizeof(uint32):    writel((uint32)(v), (volatile uint32*)(r)); break; \
     1757+       } \
     1758+} while (0)
     1759+#endif
     1760+
     1761+#define        AND_REG(r, v)           W_REG((r), R_REG(r) & (v))
     1762+#define        OR_REG(r, v)            W_REG((r), R_REG(r) | (v))
     1763+
     1764+/* bcopy, bcmp, and bzero */
     1765+#define        bcopy(src, dst, len)    memcpy((dst), (src), (len))
     1766+#define        bcmp(b1, b2, len)       memcmp((b1), (b2), (len))
     1767+#define        bzero(b, len)           memset((b), '\0', (len))
     1768+
     1769+/* uncached virtual address */
     1770+#ifdef mips
     1771+#define OSL_UNCACHED(va)       KSEG1ADDR((va))
     1772+#include <asm/addrspace.h>
     1773+#else
     1774+#define OSL_UNCACHED(va)       (va)
     1775+#endif
     1776+
     1777+/* get processor cycle count */
     1778+#if defined(mips)
     1779+#define        OSL_GETCYCLES(x)        ((x) = read_c0_count() * 2)
     1780+#elif defined(__i386__)
     1781+#define        OSL_GETCYCLES(x)        rdtscl((x))
     1782+#else
     1783+#define OSL_GETCYCLES(x)       ((x) = 0)
     1784+#endif
     1785+
     1786+/* dereference an address that may cause a bus exception */
     1787+#ifdef mips
     1788+#if defined(MODULE) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,17))
     1789+#define BUSPROBE(val, addr)    panic("get_dbe() will not fixup a bus exception when compiled into a module")
     1790+#else
     1791+#define        BUSPROBE(val, addr)     get_dbe((val), (addr))
     1792+#include <asm/paccess.h>
     1793+#endif
     1794+#else
     1795+#define        BUSPROBE(val, addr)     ({ (val) = R_REG((addr)); 0; })
     1796+#endif
     1797+
     1798+/* map/unmap physical to virtual I/O */
     1799+#define        REG_MAP(pa, size)       ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
     1800+#define        REG_UNMAP(va)           iounmap((void *)(va))
     1801+
     1802+/* microsecond delay */
     1803+#define        OSL_DELAY(usec)         udelay(usec)
     1804+#include <linux/delay.h>
     1805+
     1806+/* shared (dma-able) memory access macros */
     1807+#define        R_SM(r)                 *(r)
     1808+#define        W_SM(r, v)              (*(r) = (v))
     1809+#define        BZERO_SM(r, len)        memset((r), '\0', (len))
     1810+
     1811+/* packet primitives */
     1812+#define        PKTGET(drv, len, send)          osl_pktget((drv), (len), (send))
     1813+#define        PKTFREE(drv, skb, send)         osl_pktfree((skb))
     1814+#define        PKTDATA(drv, skb)               (((struct sk_buff*)(skb))->data)
     1815+#define        PKTLEN(drv, skb)                (((struct sk_buff*)(skb))->len)
     1816+#define PKTHEADROOM(drv, skb)          (PKTDATA(drv,skb)-(((struct sk_buff*)(skb))->head))
     1817+#define PKTTAILROOM(drv, skb)          ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
     1818+#define        PKTNEXT(drv, skb)               (((struct sk_buff*)(skb))->next)
     1819+#define        PKTSETNEXT(skb, x)              (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
     1820+#define        PKTSETLEN(drv, skb, len)        __skb_trim((struct sk_buff*)(skb), (len))
     1821+#define        PKTPUSH(drv, skb, bytes)        skb_push((struct sk_buff*)(skb), (bytes))
     1822+#define        PKTPULL(drv, skb, bytes)        skb_pull((struct sk_buff*)(skb), (bytes))
     1823+#define        PKTDUP(drv, skb)                skb_clone((struct sk_buff*)(skb), GFP_ATOMIC)
     1824+#define        PKTCOOKIE(skb)                  ((void*)((struct sk_buff*)(skb))->csum)
     1825+#define        PKTSETCOOKIE(skb, x)            (((struct sk_buff*)(skb))->csum = (uint)(x))
     1826+#define        PKTLINK(skb)                    (((struct sk_buff*)(skb))->prev)
     1827+#define        PKTSETLINK(skb, x)              (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
     1828+#define        PKTPRIO(skb)                    (((struct sk_buff*)(skb))->priority)
     1829+#define        PKTSETPRIO(skb, x)              (((struct sk_buff*)(skb))->priority = (x))
     1830+extern void *osl_pktget(void *drv, uint len, bool send);
     1831+extern void osl_pktfree(void *skb);
     1832+
     1833+#else  /* BINOSL */                                   
     1834+
     1835+/* string library */
     1836+#ifndef LINUX_OSL
     1837+#undef printf
     1838+#define        printf(fmt, args...)            osl_printf((fmt), ## args)
     1839+#undef sprintf
     1840+#define sprintf(buf, fmt, args...)     osl_sprintf((buf), (fmt), ## args)
     1841+#undef strcmp
     1842+#define        strcmp(s1, s2)                  osl_strcmp((s1), (s2))
     1843+#undef strncmp
     1844+#define        strncmp(s1, s2, n)              osl_strncmp((s1), (s2), (n))
     1845+#undef strlen
     1846+#define strlen(s)                      osl_strlen((s))
     1847+#undef strcpy
     1848+#define        strcpy(d, s)                    osl_strcpy((d), (s))
     1849+#undef strncpy
     1850+#define        strncpy(d, s, n)                osl_strncpy((d), (s), (n))
     1851+#endif
     1852+extern int osl_printf(const char *format, ...);
     1853+extern int osl_sprintf(char *buf, const char *format, ...);
     1854+extern int osl_strcmp(const char *s1, const char *s2);
     1855+extern int osl_strncmp(const char *s1, const char *s2, uint n);
     1856+extern int osl_strlen(char *s);
     1857+extern char* osl_strcpy(char *d, const char *s);
     1858+extern char* osl_strncpy(char *d, const char *s, uint n);
     1859+
     1860+/* register access macros */
     1861+#if !defined(BCMJTAG)
     1862+#define R_REG(r) ( \
     1863+       sizeof(*(r)) == sizeof(uint8) ? osl_readb((volatile uint8*)(r)) : \
     1864+       sizeof(*(r)) == sizeof(uint16) ? osl_readw((volatile uint16*)(r)) : \
     1865+       osl_readl((volatile uint32*)(r)) \
     1866+)
     1867+#define W_REG(r, v) do { \
     1868+       switch (sizeof(*(r))) { \
     1869+       case sizeof(uint8):     osl_writeb((uint8)(v), (volatile uint8*)(r)); break; \
     1870+       case sizeof(uint16):    osl_writew((uint16)(v), (volatile uint16*)(r)); break; \
     1871+       case sizeof(uint32):    osl_writel((uint32)(v), (volatile uint32*)(r)); break; \
     1872+       } \
     1873+} while (0)
     1874+#endif
     1875+
     1876+#define        AND_REG(r, v)           W_REG((r), R_REG(r) & (v))
     1877+#define        OR_REG(r, v)            W_REG((r), R_REG(r) | (v))
     1878+extern uint8 osl_readb(volatile uint8 *r);
     1879+extern uint16 osl_readw(volatile uint16 *r);
     1880+extern uint32 osl_readl(volatile uint32 *r);
     1881+extern void osl_writeb(uint8 v, volatile uint8 *r);
     1882+extern void osl_writew(uint16 v, volatile uint16 *r);
     1883+extern void osl_writel(uint32 v, volatile uint32 *r);
     1884+
     1885+/* bcopy, bcmp, and bzero */
     1886+extern void bcopy(const void *src, void *dst, int len);
     1887+extern int bcmp(const void *b1, const void *b2, int len);
     1888+extern void bzero(void *b, int len);
     1889+
     1890+/* uncached virtual address */
     1891+#define OSL_UNCACHED(va)       osl_uncached((va))
     1892+extern void *osl_uncached(void *va);
     1893+
     1894+/* get processor cycle count */
     1895+#define OSL_GETCYCLES(x)       ((x) = osl_getcycles())
     1896+extern uint osl_getcycles(void);
     1897+
     1898+/* dereference an address that may target abort */
     1899+#define        BUSPROBE(val, addr)     osl_busprobe(&(val), (addr))
     1900+extern int osl_busprobe(uint32 *val, uint32 addr);
     1901+
     1902+/* map/unmap physical to virtual */
     1903+#define        REG_MAP(pa, size)       osl_reg_map((pa), (size))
     1904+#define        REG_UNMAP(va)           osl_reg_unmap((va))
     1905+extern void *osl_reg_map(uint32 pa, uint size);
     1906+extern void osl_reg_unmap(void *va);
     1907+
     1908+/* microsecond delay */
     1909+#define        OSL_DELAY(usec)         osl_delay((usec))
     1910+extern void osl_delay(uint usec);
     1911+
     1912+/* shared (dma-able) memory access macros */
     1913+#define        R_SM(r)                 *(r)
     1914+#define        W_SM(r, v)              (*(r) = (v))
     1915+#define        BZERO_SM(r, len)        bzero((r), (len))
     1916+
     1917+/* packet primitives */
     1918+#define        PKTGET(drv, len, send)          osl_pktget((drv), (len), (send))
     1919+#define        PKTFREE(drv, skb, send)         osl_pktfree((skb))
     1920+#define        PKTDATA(drv, skb)               osl_pktdata((drv), (skb))
     1921+#define        PKTLEN(drv, skb)                osl_pktlen((drv), (skb))
     1922+#define PKTHEADROOM(drv, skb)          osl_pktheadroom((drv), (skb))
     1923+#define PKTTAILROOM(drv, skb)          osl_pkttailroom((drv), (skb))
     1924+#define        PKTNEXT(drv, skb)               osl_pktnext((drv), (skb))
     1925+#define        PKTSETNEXT(skb, x)              osl_pktsetnext((skb), (x))
     1926+#define        PKTSETLEN(drv, skb, len)        osl_pktsetlen((drv), (skb), (len))
     1927+#define        PKTPUSH(drv, skb, bytes)        osl_pktpush((drv), (skb), (bytes))
     1928+#define        PKTPULL(drv, skb, bytes)        osl_pktpull((drv), (skb), (bytes))
     1929+#define        PKTDUP(drv, skb)                osl_pktdup((drv), (skb))
     1930+#define        PKTCOOKIE(skb)                  osl_pktcookie((skb))
     1931+#define        PKTSETCOOKIE(skb, x)            osl_pktsetcookie((skb), (x))
     1932+#define        PKTLINK(skb)                    osl_pktlink((skb))
     1933+#define        PKTSETLINK(skb, x)              osl_pktsetlink((skb), (x))
     1934+#define        PKTPRIO(skb)                    osl_pktprio((skb))
     1935+#define        PKTSETPRIO(skb, x)              osl_pktsetprio((skb), (x))
     1936+extern void *osl_pktget(void *drv, uint len, bool send);
     1937+extern void osl_pktfree(void *skb);
     1938+extern uchar *osl_pktdata(void *drv, void *skb);
     1939+extern uint osl_pktlen(void *drv, void *skb);
     1940+extern uint osl_pktheadroom(void *drv, void *skb);
     1941+extern uint osl_pkttailroom(void *drv, void *skb);
     1942+extern void *osl_pktnext(void *drv, void *skb);
     1943+extern void osl_pktsetnext(void *skb, void *x);
     1944+extern void osl_pktsetlen(void *drv, void *skb, uint len);
     1945+extern uchar *osl_pktpush(void *drv, void *skb, int bytes);
     1946+extern uchar *osl_pktpull(void *drv, void *skb, int bytes);
     1947+extern void *osl_pktdup(void *drv, void *skb);
     1948+extern void *osl_pktcookie(void *skb);
     1949+extern void osl_pktsetcookie(void *skb, void *x);
     1950+extern void *osl_pktlink(void *skb);
     1951+extern void osl_pktsetlink(void *skb, void *x);
     1952+extern uint osl_pktprio(void *skb);
     1953+extern void osl_pktsetprio(void *skb, uint x);
     1954+
     1955+#endif /* BINOSL */
     1956+
     1957+/* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
     1958+#define        PKTBUFSZ        2048
     1959+
     1960+#endif /* _linux_osl_h_ */
     1961diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/linuxver.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/linuxver.h
     1962--- linux-2.4.32/arch/mips/bcm947xx/include/linuxver.h  1970-01-01 01:00:00.000000000 +0100
     1963+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/linuxver.h  2006-07-02 21:58:25.000000000 +0200
     1964@@ -0,0 +1,399 @@
     1965+/*
     1966+ * Linux-specific abstractions to gain some independence from linux kernel versions.
     1967+ * Pave over some 2.2 versus 2.4 versus 2.6 kernel differences.
    43681968+ *
    4369 + * $Id: hndpci.h,v 1.1.1.1 2006/02/27 03:43:16 honor Exp $
    4370 + * Copyright 2006, Broadcom Corporation
     1969+ * Copyright 2005, Broadcom Corporation
    43711970+ * All Rights Reserved.
    43721971+ *
     
    43751974+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    43761975+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    4377 + */
    4378 +
    4379 +#ifndef _hndpci_h_
    4380 +#define _hndpci_h_
    4381 +
    4382 +extern int sbpci_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf,
    4383 +                             int len);
    4384 +extern int extpci_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf,
    4385 +                              int len);
    4386 +extern int sbpci_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf,
    4387 +                              int len);
    4388 +extern int extpci_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf,
    4389 +                               int len);
    4390 +extern void sbpci_ban(uint16 core);
    4391 +extern int sbpci_init(sb_t *sbh);
    4392 +extern int sbpci_init_pci(sb_t *sbh);
    4393 +extern void sbpci_check(sb_t *sbh);
    4394 +
    4395 +#endif /* _hndpci_h_ */
    4396 diff -urN linux.old/arch/mips/bcm947xx/include/linuxver.h linux.dev/arch/mips/bcm947xx/include/linuxver.h
    4397 --- linux.old/arch/mips/bcm947xx/include/linuxver.h     1970-01-01 01:00:00.000000000 +0100
    4398 +++ linux.dev/arch/mips/bcm947xx/include/linuxver.h     2006-04-27 20:10:08.000000000 +0200
    4399 @@ -0,0 +1,417 @@
    4400 +/*
    4401 + * Linux-specific abstractions to gain some independence from linux kernel versions.
    4402 + * Pave over some 2.2 versus 2.4 versus 2.6 kernel differences.
    4403 + *
    4404 + * Copyright 2006, Broadcom Corporation
    4405 + * All Rights Reserved.
    4406 + *
    4407 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    4408 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    4409 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    4410 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    4411 + *
    4412 + * $Id: linuxver.h,v 1.1.1.10 2006/02/27 03:43:16 honor Exp $
     1976+ *   
     1977+ * $Id$
    44131978+ */
    44141979+
     
    44191984+#include <linux/version.h>
    44201985+
    4421 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0))
     1986+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
    44221987+/* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
    44231988+#ifdef __UNDEF_NO_VERSION__
     
    44261991+#define __NO_VERSION__
    44271992+#endif
    4428 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0) */
     1993+#endif
    44291994+
    44301995+#if defined(MODULE) && defined(MODVERSIONS)
     
    44321997+#endif
    44331998+
    4434 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
    4435 +#include <linux/moduleparam.h>
    4436 +#endif
    4437 +
    4438 +
    4439 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
    4440 +#define module_param(_name_, _type_, _perm_)   MODULE_PARM(_name_, "i")
    4441 +#define module_param_string(_name_, _string_, _size_, _perm_) \
    4442 +               MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
    4443 +#endif
    4444 +
    44451999+/* linux/malloc.h is deprecated, use linux/slab.h instead. */
    4446 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 9))
     2000+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9))
    44472001+#include <linux/malloc.h>
    44482002+#else
     
    44592013+#include <asm/io.h>
    44602014+
    4461 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41))
     2015+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))
    44622016+#include <linux/workqueue.h>
    44632017+#else
     
    44752029+#define flush_scheduled_work() flush_scheduled_tasks()
    44762030+#endif
    4477 +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 41) */
    4478 +
    4479 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
     2031+#endif
     2032+
     2033+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
    44802034+/* Some distributions have their own 2.6.x compatibility layers */
    44812035+#ifndef IRQ_NONE
     
    44852039+#define IRQ_RETVAL(x)
    44862040+#endif
    4487 +#else
    4488 +typedef irqreturn_t(*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
    4489 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) */
     2041+#endif
    44902042+
    44912043+#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
     
    44982050+#include <pcmcia/ds.h>
    44992051+
    4500 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 69))
     2052+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,69))
    45012053+/* In 2.5 (as of 2.5.69 at least) there is a cs_error exported which
    4502 + * does this, but it's not in 2.4 so we do our own for now.
    4503 + */
     2054+ * does this, but it's not in 2.4 so we do our own for now. */
    45042055+static inline void
    45052056+cs_error(client_handle_t handle, int func, int ret)
     
    45282079+#endif
    45292080+
    4530 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0))
     2081+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
    45312082+
    45322083+#define pci_get_drvdata(dev)           (dev)->sysdata
    4533 +#define pci_set_drvdata(dev, value)    (dev)->sysdata = (value)
     2084+#define pci_set_drvdata(dev, value)    (dev)->sysdata=(value)
    45342085+
    45352086+/*
     
    45482099+       char *name;
    45492100+       const struct pci_device_id *id_table;   /* NULL if wants all devices */
    4550 +       int (*probe)(struct pci_dev *dev,
    4551 +                    const struct pci_device_id *id); /* New device inserted */
    4552 +       void (*remove)(struct pci_dev *dev);    /* Device removed (NULL if not a hot-plug
    4553 +                                                * capable driver)
    4554 +                                                */
     2101+       int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);      /* New device inserted */
     2102+       void (*remove)(struct pci_dev *dev);    /* Device removed (NULL if not a hot-plug capable driver) */
    45552103+       void (*suspend)(struct pci_dev *dev);   /* Device suspended */
    45562104+       void (*resume)(struct pci_dev *dev);    /* Device woken up */
     
    45672115+#endif /* PCI registration */
    45682116+
    4569 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18))
     2117+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18))
    45702118+#ifdef MODULE
    45712119+#define module_init(x) int init_module(void) { return x(); }
     
    45752123+#define module_exit(x) __exitcall(x);
    45762124+#endif
    4577 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18) */
    4578 +
    4579 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 48))
     2125+#endif
     2126+
     2127+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48))
    45802128+#define list_for_each(pos, head) \
    45812129+       for (pos = (head)->next; pos != (head); pos = pos->next)
    45822130+#endif
    45832131+
    4584 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 13))
     2132+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13))
    45852133+#define pci_resource_start(dev, bar)   ((dev)->base_address[(bar)])
    4586 +#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 44))
     2134+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,44))
    45872135+#define pci_resource_start(dev, bar)   ((dev)->resource[(bar)].start)
    45882136+#endif
    45892137+
    4590 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 23))
     2138+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,23))
    45912139+#define pci_enable_device(dev) do { } while (0)
    45922140+#endif
    45932141+
    4594 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 14))
     2142+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,14))
    45952143+#define net_device device
    45962144+#endif
    45972145+
    4598 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 42))
     2146+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,42))
    45992147+
    46002148+/*
     
    46262174+
    46272175+static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
    4628 +                                        dma_addr_t *dma_handle)
     2176+                                        dma_addr_t *dma_handle)
    46292177+{
    46302178+       void *ret;
     
    46402188+}
    46412189+static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
    4642 +                                       void *vaddr, dma_addr_t dma_handle)
     2190+                                      void *vaddr, dma_addr_t dma_handle)
    46432191+{
    46442192+       free_pages((unsigned long)vaddr, get_order(size));
     
    46542202+#endif /* DMA mapping */
    46552203+
    4656 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43))
     2204+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43))
    46572205+
    46582206+#define dev_kfree_skb_any(a)           dev_kfree_skb(a)
    4659 +#define netif_down(dev)                        do { (dev)->start = 0; } while (0)
     2207+#define netif_down(dev)                        do { (dev)->start = 0; } while(0)
    46602208+
    46612209+/* pcmcia-cs provides its own netdevice compatibility layer */
     
    46732221+ */
    46742222+
    4675 +#define dev_kfree_skb_irq(a)   dev_kfree_skb(a)
    4676 +#define netif_wake_queue(dev) \
    4677 +               do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while (0)
    4678 +#define netif_stop_queue(dev)  set_bit(0, &(dev)->tbusy)
     2223+#define dev_kfree_skb_irq(a)           dev_kfree_skb(a)
     2224+#define netif_wake_queue(dev)          do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while(0)
     2225+#define netif_stop_queue(dev)          set_bit(0, &(dev)->tbusy)
    46792226+
    46802227+static inline void netif_start_queue(struct net_device *dev)
     
    47022249+
    47032250+static inline void tasklet_init(struct tasklet_struct *tasklet,
    4704 +                                void (*func)(unsigned long),
    4705 +                                unsigned long data)
     2251+                               void (*func)(unsigned long),
     2252+                               unsigned long data)
    47062253+{
    47072254+       tasklet->next = NULL;
     
    47102257+       tasklet->data = (void *)data;
    47112258+}
    4712 +#define tasklet_kill(tasklet)  { do{} while (0); }
     2259+#define tasklet_kill(tasklet)                  {do{} while(0);}
    47132260+
    47142261+/* 2.4.x introduced del_timer_sync() */
     
    47212268+#endif /* SoftNet */
    47222269+
    4723 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3))
     2270+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3))
    47242271+
    47252272+/*
     
    47422289+       } while (0)
    47432290+
    4744 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3) */
    4745 +
    4746 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 6))
     2291+#endif
     2292+
     2293+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6))
    47472294+
    47482295+/* Power management related routines */
     
    47542301+       if (buffer) {
    47552302+               for (i = 0; i < 16; i++)
    4756 +                       pci_read_config_dword(dev, i * 4, &buffer[i]);
     2303+                       pci_read_config_dword(dev, i * 4,&buffer[i]);
    47572304+       }
    47582305+       return 0;
    47592306+}
    47602307+
    4761 +static inline int
     2308+static inline int 
    47622309+pci_restore_state(struct pci_dev *dev, u32 *buffer)
    47632310+{
     
    47662313+       if (buffer) {
    47672314+               for (i = 0; i < 16; i++)
    4768 +                       pci_write_config_dword(dev, i * 4, buffer[i]);
     2315+                       pci_write_config_dword(dev,i * 4, buffer[i]);
    47692316+       }
    47702317+       /*
     
    47732320+        * combined with a D3(hot)->D0 transition causes PCI config
    47742321+        * header data to be forgotten.
    4775 +        */
     2322+        */     
    47762323+       else {
    47772324+               for (i = 0; i < 6; i ++)
    47782325+                       pci_write_config_dword(dev,
    4779 +                                              PCI_BASE_ADDRESS_0 + (i * 4),
    4780 +                                              pci_resource_start(dev, i));
     2326+                                              PCI_BASE_ADDRESS_0 + (i * 4),
     2327+                                              pci_resource_start(dev, i));
    47812328+               pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
    47822329+       }
     
    47872334+
    47882335+/* Old cp0 access macros deprecated in 2.4.19 */
    4789 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 19))
     2336+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
    47902337+#define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
    47912338+#endif
     
    48092356+#endif
    48102357+
    4811 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
     2358+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
    48122359+/* struct packet_type redefined in 2.6.x */
    48132360+#define af_packet_priv                 data
     
    48152362+
    48162363+#endif /* _linuxver_h_ */
    4817 diff -urN linux.old/arch/mips/bcm947xx/include/mipsinc.h linux.dev/arch/mips/bcm947xx/include/mipsinc.h
    4818 --- linux.old/arch/mips/bcm947xx/include/mipsinc.h      1970-01-01 01:00:00.000000000 +0100
    4819 +++ linux.dev/arch/mips/bcm947xx/include/mipsinc.h      2006-04-27 22:12:20.000000000 +0200
    4820 @@ -0,0 +1,541 @@
     2364diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/mipsinc.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/mipsinc.h
     2365--- linux-2.4.32/arch/mips/bcm947xx/include/mipsinc.h   1970-01-01 01:00:00.000000000 +0100
     2366+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/mipsinc.h   2006-07-02 21:58:25.000000000 +0200
     2367@@ -0,0 +1,524 @@
    48212368+/*
    48222369+ * HND Run Time Environment for standalone MIPS programs.
    48232370+ *
    4824 + * Copyright 2006, Broadcom Corporation
     2371+ * Copyright 2005, Broadcom Corporation
    48252372+ * All Rights Reserved.
    48262373+ *
     
    48302377+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    48312378+ *
    4832 + * $Id: mipsinc.h,v 1.1.1.5 2006/02/27 03:43:16 honor Exp $
     2379+ * $Id$
    48332380+ */
    48342381+
    48352382+#ifndef        _MISPINC_H
    4836 +#define _MISPINC_H
     2383+#define        _MISPINC_H
    48372384+
    48382385+
     
    48802427+
    48812428+
    4882 +/* CP0 Registers */
     2429+/*  *********************************************************************
     2430+    *  CP0 Registers
     2431+    ********************************************************************* */
    48832432+
    48842433+#define C0_INX         $0
     
    49062455+#define C0_DIAGNOSTIC  $22
    49072456+#define C0_BROADCOM    C0_DIAGNOSTIC
    4908 +#define        C0_PERFORMANCE  $25
    49092457+#define C0_ECC         $26
    49102458+#define C0_CACHEERR    $27
     
    49172465+ * LEAF - declare leaf routine
    49182466+ */
    4919 +#define LEAF(symbol)                           \
     2467+#define        LEAF(symbol)                            \
    49202468+               .globl  symbol;                 \
    49212469+               .align  2;                      \
    4922 +               .type   symbol, @function;      \
    4923 +               .ent    symbol, 0;              \
    4924 +symbol:                .frame  sp, 0, ra
     2470+               .type   symbol,@function;       \
     2471+               .ent    symbol,0;               \
     2472+symbol:                .frame  sp,0,ra
    49252473+
    49262474+/*
    49272475+ * END - mark end of function
    49282476+ */
    4929 +#define END(function)                          \
     2477+#define        END(function)                           \
    49302478+               .end    function;               \
    4931 +               .size   function, . - function
    4932 +
    4933 +#define _ULCAST_
    4934 +
    4935 +#define MFC0_SEL(dst, src, sel) \
    4936 +               .word\t(0x40000000 | ((dst) << 16) | ((src) << 11) | (sel))
    4937 +
    4938 +
    4939 +#define MTC0_SEL(dst, src, sel) \
    4940 +               .word\t(0x40800000 | ((dst) << 16) | ((src) << 11) | (sel))
     2479+               .size   function,.-function
     2480+
     2481+#define        _ULCAST_
    49412482+
    49422483+#else
     
    49532494+#endif
    49542495+
    4955 +#define _ULCAST_ (unsigned long)
    4956 +
    4957 +
    4958 +/* CP0 Registers */
     2496+#define        _ULCAST_ (unsigned long)
     2497+
     2498+
     2499+/*  *********************************************************************
     2500+    *  CP0 Registers
     2501+    ********************************************************************* */
    49592502+
    49602503+#define C0_INX         0               /* CP0: TLB Index */
     
    49822525+#define C0_DIAGNOSTIC  22              /* CP0: Diagnostic */
    49832526+#define C0_BROADCOM    C0_DIAGNOSTIC   /* CP0: Broadcom Register */
    4984 +#define        C0_PERFORMANCE  25              /* CP0: Performance Counter/Control Registers */
    49852527+#define C0_ECC         26              /* CP0: ECC */
    49862528+#define C0_CACHEERR    27              /* CP0: CacheErr */
     
    50272569+ * Cache Operations
    50282570+ */
    5029 +#define Index_Invalidate_I     0x00
    5030 +#define Index_Writeback_Inv_D  0x01
    5031 +#define Index_Invalidate_SI    0x02
    5032 +#define Index_Writeback_Inv_SD 0x03
     2571+#define Index_Invalidate_I      0x00
     2572+#define Index_Writeback_Inv_D   0x01
     2573+#define Index_Invalidate_SI     0x02
     2574+#define Index_Writeback_Inv_SD  0x03
    50332575+#define Index_Load_Tag_I       0x04
    50342576+#define Index_Load_Tag_D       0x05
     
    50582600+#define Hit_Set_Virtual_SI     0x1e
    50592601+#define Hit_Set_Virtual_SD     0x1f
    5060 +#endif /* !Index_Invalidate_I */
     2602+#endif
     2603+
     2604+#ifndef        _LANGUAGE_ASSEMBLY
     2605+
     2606+/*
     2607+ * Macros to access the system control coprocessor
     2608+ */
     2609+
     2610+#define MFC0(source, sel)                                      \
     2611+({                                                             \
     2612+       int __res;                                              \
     2613+       __asm__ __volatile__(                                   \
     2614+       ".set\tnoreorder\n\t"                                   \
     2615+       ".set\tnoat\n\t"                                        \
     2616+       ".word\t"STR(0x40010000 | ((source)<<11) | (sel))"\n\t" \
     2617+       "move\t%0,$1\n\t"                                       \
     2618+       ".set\tat\n\t"                                          \
     2619+       ".set\treorder"                                         \
     2620+       :"=r" (__res)                                           \
     2621+       :                                                       \
     2622+       :"$1");                                                 \
     2623+       __res;                                                  \
     2624+})
     2625+
     2626+#define MTC0(source, sel, value)                               \
     2627+do {                                                           \
     2628+       __asm__ __volatile__(                                   \
     2629+       ".set\tnoreorder\n\t"                                   \
     2630+       ".set\tnoat\n\t"                                        \
     2631+       "move\t$1,%z0\n\t"                                      \
     2632+       ".word\t"STR(0x40810000 | ((source)<<11) | (sel))"\n\t" \
     2633+       ".set\tat\n\t"                                          \
     2634+       ".set\treorder"                                         \
     2635+       :                                                       \
     2636+       :"jr" (value)                                           \
     2637+       :"$1");                                                 \
     2638+} while (0)
     2639+
     2640+#define get_c0_count()                                         \
     2641+({                                                             \
     2642+       int __res;                                              \
     2643+       __asm__ __volatile__(                                   \
     2644+       ".set\tnoreorder\n\t"                                   \
     2645+       ".set\tnoat\n\t"                                        \
     2646+       "mfc0\t%0,$9\n\t"                                       \
     2647+       ".set\tat\n\t"                                          \
     2648+       ".set\treorder"                                         \
     2649+       :"=r" (__res));                                         \
     2650+       __res;                                                  \
     2651+})
     2652+
     2653+static INLINE void icache_probe(uint32 config1, uint *size, uint *lsize)
     2654+{
     2655+       uint lsz, sets, ways;
     2656+
     2657+       /* Instruction Cache Size = Associativity * Line Size * Sets Per Way */
     2658+       if ((lsz = ((config1 >> 19) & 7)))
     2659+               lsz = 2 << lsz;
     2660+       sets = 64 << ((config1 >> 22) & 7);
     2661+       ways = 1 + ((config1 >> 16) & 7);
     2662+       *size = lsz * sets * ways;
     2663+       *lsize = lsz;
     2664+}
     2665+
     2666+static INLINE void dcache_probe(uint32 config1, uint *size, uint *lsize)
     2667+{
     2668+       uint lsz, sets, ways;
     2669+
     2670+       /* Data Cache Size = Associativity * Line Size * Sets Per Way */
     2671+       if ((lsz = ((config1 >> 10) & 7)))
     2672+               lsz = 2 << lsz;
     2673+       sets = 64 << ((config1 >> 13) & 7);
     2674+       ways = 1 + ((config1 >> 7) & 7);
     2675+       *size = lsz * sets * ways;
     2676+       *lsize = lsz;
     2677+}
     2678+
     2679+#define cache_unroll(base,op)                  \
     2680+       __asm__ __volatile__("                  \
     2681+               .set noreorder;                 \
     2682+               .set mips3;                     \
     2683+                cache %1, (%0);                        \
     2684+               .set mips0;                     \
     2685+               .set reorder"                   \
     2686+               :                               \
     2687+               : "r" (base),                   \
     2688+                 "i" (op));
     2689+
     2690+#endif /* !_LANGUAGE_ASSEMBLY */
    50612691+
    50622692+
     
    50642694+ * R4x00 interrupt enable / cause bits
    50652695+ */
    5066 +#define IE_SW0                 (_ULCAST_(1) <<  8)
    5067 +#define IE_SW1                 (_ULCAST_(1) <<  9)
    5068 +#define IE_IRQ0                        (_ULCAST_(1) << 10)
    5069 +#define IE_IRQ1                        (_ULCAST_(1) << 11)
    5070 +#define IE_IRQ2                        (_ULCAST_(1) << 12)
    5071 +#define IE_IRQ3                        (_ULCAST_(1) << 13)
    5072 +#define IE_IRQ4                        (_ULCAST_(1) << 14)
    5073 +#define IE_IRQ5                        (_ULCAST_(1) << 15)
    5074 +
    5075 +#ifndef        ST0_UM
     2696+#undef IE_SW0
     2697+#undef IE_SW1
     2698+#undef IE_IRQ0
     2699+#undef IE_IRQ1
     2700+#undef IE_IRQ2
     2701+#undef IE_IRQ3
     2702+#undef IE_IRQ4
     2703+#undef IE_IRQ5
     2704+#define IE_SW0         (1<< 8)
     2705+#define IE_SW1         (1<< 9)
     2706+#define IE_IRQ0                (1<<10)
     2707+#define IE_IRQ1                (1<<11)
     2708+#define IE_IRQ2                (1<<12)
     2709+#define IE_IRQ3                (1<<13)
     2710+#define IE_IRQ4                (1<<14)
     2711+#define IE_IRQ5                (1<<15)
     2712+
    50762713+/*
    50772714+ * Bitfields in the mips32 cp0 status register
     
    50802717+#define ST0_EXL                        0x00000002
    50812718+#define ST0_ERL                        0x00000004
     2719+/* already defined
    50822720+#define ST0_UM                 0x00000010
    50832721+#define ST0_SWINT0             0x00000100
    50842722+#define ST0_SWINT1             0x00000200
     2723+*/
    50852724+#define ST0_HWINT0             0x00000400
    50862725+#define ST0_HWINT1             0x00000800
     
    51012740+#define ST0_CU2                        0x40000000
    51022741+#define ST0_CU3                        0x80000000
    5103 +#endif /* !ST0_UM */
    51042742+
    51052743+
     
    51112749+#define C_INT                  0x0000ff00
    51122750+#define C_INT_SHIFT            8
    5113 +#define C_SW0                  (_ULCAST_(1) <<  8)
    5114 +#define C_SW1                  (_ULCAST_(1) <<  9)
    5115 +#define C_IRQ0                 (_ULCAST_(1) << 10)
    5116 +#define C_IRQ1                 (_ULCAST_(1) << 11)
    5117 +#define C_IRQ2                 (_ULCAST_(1) << 12)
    5118 +#define C_IRQ3                 (_ULCAST_(1) << 13)
    5119 +#define C_IRQ4                 (_ULCAST_(1) << 14)
    5120 +#define C_IRQ5                 (_ULCAST_(1) << 15)
     2751+/* already defined
     2752+#define C_SW0                  0x00000100
     2753+#define C_SW1                  0x00000200
     2754+#define C_IRQ0                 0x00000400
     2755+#define C_IRQ1                 0x00000800
     2756+#define C_IRQ2                 0x00001000
     2757+#define C_IRQ3                 0x00002000
     2758+#define C_IRQ4                 0x00004000
     2759+#define C_IRQ5                 0x00008000
     2760+*/
    51212761+#define C_WP                   0x00400000
    51222762+#define C_IV                   0x00800000
     
    51602800+#define CONF_IB                                (_ULCAST_(1) <<  5)
    51612801+#define CONF_SE                                (_ULCAST_(1) << 12)
    5162 +#ifndef CONF_BE                                    /* duplicate in mipsregs.h */
    5163 +#define CONF_BE                                (_ULCAST_(1) << 15)
    5164 +#endif
    51652802+#define CONF_SC                                (_ULCAST_(1) << 17)
    51662803+#define CONF_AC                                (_ULCAST_(1) << 23)
    51672804+#define CONF_HALT                      (_ULCAST_(1) << 25)
    5168 +#ifndef CONF_M                             /* duplicate in mipsregs.h */
    5169 +#define CONF_M                         (_ULCAST_(1) << 31)
    5170 +#endif
    51712805+
    51722806+
     
    51742808+ * Bits in the cp0 config register select 1.
    51752809+ */
    5176 +#define CONF1_FP               0x00000001      /* FPU present */
    5177 +#define CONF1_EP               0x00000002      /* EJTAG present */
    5178 +#define CONF1_CA               0x00000004      /* mips16 implemented */
    5179 +#define CONF1_WR               0x00000008      /* Watch registers present */
    5180 +#define CONF1_PC               0x00000010      /* Performance counters present */
    5181 +#define CONF1_DA_SHIFT         7               /* D$ associativity */
    5182 +#define CONF1_DA_MASK          0x00000380
    5183 +#define CONF1_DA_BASE          1
    5184 +#define CONF1_DL_SHIFT         10              /* D$ line size */
    5185 +#define CONF1_DL_MASK          0x00001c00
    5186 +#define CONF1_DL_BASE          2
    5187 +#define CONF1_DS_SHIFT         13              /* D$ sets/way */
    5188 +#define CONF1_DS_MASK          0x0000e000
    5189 +#define CONF1_DS_BASE          64
    5190 +#define CONF1_IA_SHIFT         16              /* I$ associativity */
    5191 +#define CONF1_IA_MASK          0x00070000
    5192 +#define CONF1_IA_BASE          1
    5193 +#define CONF1_IL_SHIFT         19              /* I$ line size */
    5194 +#define CONF1_IL_MASK          0x00380000
    5195 +#define CONF1_IL_BASE          2
    5196 +#define CONF1_IS_SHIFT         22              /* Instruction cache sets/way */
    5197 +#define CONF1_IS_MASK          0x01c00000
    5198 +#define CONF1_IS_BASE          64
    5199 +#define CONF1_MS_MASK          0x7e000000      /* Number of tlb entries */
    5200 +#define CONF1_MS_SHIFT         25
     2810+#define CONF1_FP                       0x00000001              /* FPU present */
     2811+#define CONF1_EP                       0x00000002              /* EJTAG present */
     2812+#define CONF1_CA                       0x00000004              /* mips16 implemented */
     2813+#define CONF1_WR                       0x00000008              /* Watch registers present */
     2814+#define CONF1_PC                       0x00000010              /* Performance counters present */
     2815+#define        CONF1_DA_SHIFT                  7                       /* D$ associativity */
     2816+#define CONF1_DA_MASK                  0x00000380
     2817+#define CONF1_DA_BASE                  1
     2818+#define CONF1_DL_SHIFT                 10                      /* D$ line size */
     2819+#define CONF1_DL_MASK                  0x00001c00
     2820+#define CONF1_DL_BASE                  2
     2821+#define CONF1_DS_SHIFT                 13                      /* D$ sets/way */
     2822+#define CONF1_DS_MASK                  0x0000e000
     2823+#define CONF1_DS_BASE                  64
     2824+#define CONF1_IA_SHIFT                 16                      /* I$ associativity */
     2825+#define CONF1_IA_MASK                  0x00070000
     2826+#define CONF1_IA_BASE                  1
     2827+#define CONF1_IL_SHIFT                 19                      /* I$ line size */
     2828+#define CONF1_IL_MASK                  0x00380000
     2829+#define CONF1_IL_BASE                  2
     2830+#define CONF1_IS_SHIFT                 22                      /* Instruction cache sets/way */
     2831+#define CONF1_IS_MASK                  0x01c00000
     2832+#define CONF1_IS_BASE                  64
     2833+#define CONF1_MS_MASK                  0x7e000000              /* Number of tlb entries */
     2834+#define CONF1_MS_SHIFT                 25
    52012835+
    52022836+/* PRID register */
     
    52142848+#define PRID_IMP_BCM3302       0x9000
    52152849+#define PRID_IMP_BCM3303       0x9100
     2850+#define        PRID_IMP_BCM3303        0x9100
    52162851+
    52172852+#define PRID_IMP_UNKNOWN       0xff00
    52182853+
    5219 +#define BCM330X(id) \
    5220 +               (((id & (PRID_COMP_MASK | PRID_IMP_MASK)) == \
    5221 +                (PRID_COMP_BROADCOM | PRID_IMP_BCM3302)) || \
    5222 +               ((id & (PRID_COMP_MASK | PRID_IMP_MASK)) == \
    5223 +                (PRID_COMP_BROADCOM | PRID_IMP_BCM3303)))
     2854+#define       BCM330X(id) \
     2855+       (((id & (PRID_COMP_MASK | PRID_IMP_MASK)) == (PRID_COMP_BROADCOM | PRID_IMP_BCM3302)) \
     2856+       || ((id & (PRID_COMP_MASK | PRID_IMP_MASK)) == (PRID_COMP_BROADCOM | PRID_IMP_BCM3303)))
    52242857+
    52252858+/* Bits in C0_BROADCOM */
    5226 +#define BRCM_PFC_AVAIL         0x20000000      /* PFC is available */
    5227 +#define BRCM_DC_ENABLE         0x40000000      /* Enable Data $ */
    5228 +#define BRCM_IC_ENABLE         0x80000000      /* Enable Instruction $ */
    5229 +#define BRCM_PFC_ENABLE                0x00400000      /* Obsolete? Enable PFC (at least on 4310) */
    5230 +#define BRCM_CLF_ENABLE                0x00100000      /* Enable cache line first feature */
     2859+#define        BRCM_PFC_AVAIL          0x20000000      /* PFC is available */
     2860+#define        BRCM_DC_ENABLE          0x40000000      /* Enable Data $ */
     2861+#define        BRCM_IC_ENABLE          0x80000000      /* Enable Instruction $ */
     2862+#define        BRCM_PFC_ENABLE         0x00400000      /* Obsolete? Enable PFC (at least on 4310) */
    52312863+
    52322864+/* PreFetch Cache aka Read Ahead Cache */
    52332865+
    5234 +#define PFC_CR0                        0xff400000      /* control reg 0 */
    5235 +#define PFC_CR1                        0xff400004      /* control reg 1 */
    5236 +
    5237 +/* PFC operations */
    5238 +#define PFC_I                  0x00000001      /* Enable PFC use for instructions */
    5239 +#define PFC_D                  0x00000002      /* Enable PFC use for data */
    5240 +#define PFC_PFI                        0x00000004      /* Enable seq. prefetch for instructions */
    5241 +#define PFC_PFD                        0x00000008      /* Enable seq. prefetch for data */
    5242 +#define PFC_CINV               0x00000010      /* Enable selective (i/d) cacheop flushing */
    5243 +#define PFC_NCH                        0x00000020      /* Disable flushing based on cacheops */
    5244 +#define PFC_DPF                        0x00000040      /* Enable directional prefetching */
    5245 +#define PFC_FLUSH              0x00000100      /* Flush the PFC */
    5246 +#define PFC_BRR                        0x40000000      /* Bus error indication */
    5247 +#define PFC_PWR                        0x80000000      /* Disable power saving (clock gating) */
    5248 +
    5249 +/* Handy defaults */
    5250 +#define PFC_DISABLED           0
    5251 +#define PFC_AUTO                       0xffffffff      /* auto select the default mode */
    5252 +#define PFC_INST               (PFC_I | PFC_PFI | PFC_CINV)
    5253 +#define PFC_INST_NOPF          (PFC_I | PFC_CINV)
    5254 +#define PFC_DATA               (PFC_D | PFC_PFD | PFC_CINV)
    5255 +#define PFC_DATA_NOPF          (PFC_D | PFC_CINV)
    5256 +#define PFC_I_AND_D            (PFC_INST | PFC_DATA)
    5257 +#define PFC_I_AND_D_NOPF       (PFC_INST_NOPF | PFC_DATA_NOPF)
    5258 +
    5259 +#ifndef        _LANGUAGE_ASSEMBLY
    5260 +
     2866+#define        PFC_CR0         0xff400000      /* control reg 0 */
     2867+#define        PFC_CR1         0xff400004      /* control reg 1 */
     2868+
     2869+/*
     2870+ * These are the UART port assignments, expressed as offsets from the base
     2871+ * register.  These assignments should hold for any serial port based on
     2872+ * a 8250, 16450, or 16550(A).
     2873+ */
     2874+
     2875+#define UART_RX                0       /* In:  Receive buffer (DLAB=0) */
     2876+#define UART_TX                0       /* Out: Transmit buffer (DLAB=0) */
     2877+#define UART_DLL       0       /* Out: Divisor Latch Low (DLAB=1) */
     2878+#define UART_DLM       1       /* Out: Divisor Latch High (DLAB=1) */
     2879+#define UART_LCR       3       /* Out: Line Control Register */
     2880+#define UART_MCR       4       /* Out: Modem Control Register */
     2881+#define UART_LSR       5       /* In:  Line Status Register */
     2882+#define UART_MSR       6       /* In:  Modem Status Register */
     2883+#define UART_SCR       7       /* I/O: Scratch Register */
     2884+#define UART_LCR_DLAB  0x80    /* Divisor latch access bit */
     2885+#define UART_LCR_WLEN8  0x03   /* Wordlength: 8 bits */
     2886+#define UART_MCR_LOOP  0x10    /* Enable loopback test mode */
     2887+#define UART_LSR_THRE  0x20    /* Transmit-hold-register empty */
     2888+#define UART_LSR_RXRDY 0x01    /* Receiver ready */
     2889+
     2890+
     2891+#endif /* _MISPINC_H */
     2892diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/osl.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/osl.h
     2893--- linux-2.4.32/arch/mips/bcm947xx/include/osl.h       1970-01-01 01:00:00.000000000 +0100
     2894+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/osl.h       2006-07-02 21:58:25.000000000 +0200
     2895@@ -0,0 +1,39 @@
    52612896+/*
    5262 + * Macros to access the system control coprocessor
     2897+ * OS Independent Layer
     2898+ *
     2899+ * Copyright 2005, Broadcom Corporation     
     2900+ * All Rights Reserved.     
     2901+ *       
     2902+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     2903+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     2904+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     2905+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     2906+ * $Id$
    52632907+ */
    52642908+
    5265 +#define MFC0(source, sel)                                      \
    5266 +({                                                             \
    5267 +       int __res;                                              \
    5268 +       __asm__ __volatile__("                                  \
    5269 +       .set\tnoreorder;                                        \
    5270 +       .set\tnoat;                                             \
    5271 +       .word\t"STR(0x40010000 | ((source) << 11) | (sel))";    \
    5272 +       move\t%0, $1;                                           \
    5273 +       .set\tat;                                               \
    5274 +       .set\treorder"                                          \
    5275 +       :"=r" (__res)                                           \
    5276 +       :                                                       \
    5277 +       :"$1");                                                 \
    5278 +       __res;                                                  \
    5279 +})
    5280 +
    5281 +#define MTC0(source, sel, value)                               \
    5282 +do {                                                           \
    5283 +       __asm__ __volatile__("                                  \
    5284 +       .set\tnoreorder;                                        \
    5285 +       .set\tnoat;                                             \
    5286 +       move\t$1, %z0;                                          \
    5287 +       .word\t"STR(0x40810000 | ((source) << 11) | (sel))";    \
    5288 +       .set\tat;                                               \
    5289 +       .set\treorder"                                          \
    5290 +       :                                                       \
    5291 +       :"jr" (value)                                           \
    5292 +       :"$1");                                                 \
    5293 +} while (0)
    5294 +
    5295 +#define get_c0_count()                                         \
    5296 +({                                                             \
    5297 +       int __res;                                              \
    5298 +       __asm__ __volatile__("                                  \
    5299 +       .set\tnoreorder;                                        \
    5300 +       .set\tnoat;                                             \
    5301 +       mfc0\t%0, $9;                                           \
    5302 +       .set\tat;                                               \
    5303 +       .set\treorder"                                          \
    5304 +       :"=r" (__res));                                         \
    5305 +       __res;                                                  \
    5306 +})
    5307 +
    5308 +static INLINE void icache_probe(uint32 config1, uint *size, uint *lsize)
    5309 +{
    5310 +       uint lsz, sets, ways;
    5311 +
    5312 +       /* Instruction Cache Size = Associativity * Line Size * Sets Per Way */
    5313 +       if ((lsz = ((config1 & CONF1_IL_MASK) >> CONF1_IL_SHIFT)))
    5314 +               lsz = CONF1_IL_BASE << lsz;
    5315 +       sets = CONF1_IS_BASE << ((config1 & CONF1_IS_MASK) >> CONF1_IS_SHIFT);
    5316 +       ways = CONF1_IA_BASE + ((config1 & CONF1_IA_MASK) >> CONF1_IA_SHIFT);
    5317 +       *size = lsz * sets * ways;
    5318 +       *lsize = lsz;
    5319 +}
    5320 +
    5321 +static INLINE void dcache_probe(uint32 config1, uint *size, uint *lsize)
    5322 +{
    5323 +       uint lsz, sets, ways;
    5324 +
    5325 +       /* Data Cache Size = Associativity * Line Size * Sets Per Way */
    5326 +       if ((lsz = ((config1 & CONF1_DL_MASK) >> CONF1_DL_SHIFT)))
    5327 +               lsz = CONF1_DL_BASE << lsz;
    5328 +       sets = CONF1_DS_BASE << ((config1 & CONF1_DS_MASK) >> CONF1_DS_SHIFT);
    5329 +       ways = CONF1_DA_BASE + ((config1 & CONF1_DA_MASK) >> CONF1_DA_SHIFT);
    5330 +       *size = lsz * sets * ways;
    5331 +       *lsize = lsz;
    5332 +}
    5333 +
    5334 +#define cache_op(base, op)                     \
    5335 +       __asm__ __volatile__("                  \
    5336 +               .set noreorder;                 \
    5337 +               .set mips3;                     \
    5338 +               cache %1, (%0);                 \
    5339 +               .set mips0;                     \
    5340 +               .set reorder"                   \
    5341 +               :                               \
    5342 +               : "r" (base),                   \
    5343 +                 "i" (op));
    5344 +
    5345 +#define cache_unroll4(base, delta, op)         \
    5346 +       __asm__ __volatile__("                  \
    5347 +               .set noreorder;                 \
    5348 +               .set mips3;                     \
    5349 +               cache %1, 0(%0);                \
    5350 +               cache %1, delta(%0);            \
    5351 +               cache %1, (2 * delta)(%0);      \
    5352 +               cache %1, (3 * delta)(%0);      \
    5353 +               .set mips0;                     \
    5354 +               .set reorder"                   \
    5355 +               :                               \
    5356 +               : "r" (base),                   \
    5357 +                 "i" (op));
    5358 +
    5359 +#endif /* !_LANGUAGE_ASSEMBLY */
    5360 +
    5361 +#endif /* _MISPINC_H */
    5362 diff -urN linux.old/arch/mips/bcm947xx/include/osl.h linux.dev/arch/mips/bcm947xx/include/osl.h
    5363 --- linux.old/arch/mips/bcm947xx/include/osl.h  1970-01-01 01:00:00.000000000 +0100
    5364 +++ linux.dev/arch/mips/bcm947xx/include/osl.h  2006-05-02 17:40:43.000000000 +0200
    5365 @@ -0,0 +1,179 @@
    5366 +#ifndef __osl_h
    5367 +#define __osl_h
    5368 +
    5369 +#include <linux/delay.h>
    5370 +#include <typedefs.h>
    5371 +#include <linuxver.h>
    5372 +#include <bcmutils.h>
    5373 +#include <pcicfg.h>
    5374 +
    5375 +#define ASSERT(n)
    5376 +
    5377 +/* Pkttag flag should be part of public information */
    5378 +struct osl_pubinfo {
    5379 +       bool pkttag;
    5380 +       uint pktalloced; /* Number of allocated packet buffers */
    5381 +};
    5382 +
    5383 +struct osl_info {
    5384 +       struct osl_pubinfo pub;
    5385 +       uint magic;
    5386 +       void *pdev;
    5387 +       uint malloced;
    5388 +       uint failed;
    5389 +       void *dbgmem_list;
    5390 +};
    5391 +
    5392 +typedef struct osl_info osl_t;
    5393 +
    5394 +#define PCI_CFG_RETRY                10
    5395 +
    5396 +/* map/unmap direction */
    5397 +#define DMA_TX  1   /* TX direction for DMA */
    5398 +#define DMA_RX  2   /* RX direction for DMA */
    5399 +
    5400 +#define        AND_REG(osh, r, v)              W_REG(osh, (r), R_REG(osh, r) & (v))
    5401 +#define        OR_REG(osh, r, v)               W_REG(osh, (r), R_REG(osh, r) | (v))
    5402 +#define SET_REG(osh, r, mask, val)     W_REG((osh), (r), ((R_REG((osh), r) & ~(mask)) | (val)))
    5403 +
    5404 +/* bcopy, bcmp, and bzero */
    5405 +#define        bcopy(src, dst, len)    memcpy((dst), (src), (len))
    5406 +#define        bcmp(b1, b2, len)       memcmp((b1), (b2), (len))
    5407 +#define        bzero(b, len)           memset((b), '\0', (len))
    5408 +
    5409 +/* uncached virtual address */
    5410 +#ifdef mips
    5411 +#define OSL_UNCACHED(va)       KSEG1ADDR((va))
    5412 +#include <asm/addrspace.h>
     2909+#ifndef _osl_h_
     2910+#define _osl_h_
     2911+
     2912+#if defined(linux)
     2913+#include <linux_osl.h>
     2914+#elif defined(NDIS)
     2915+#include <ndis_osl.h>
     2916+#elif defined(_CFE_)
     2917+#include <cfe_osl.h>
     2918+#elif defined(_HNDRTE_)
     2919+#include <hndrte_osl.h>
     2920+#elif defined(_MINOSL_)
     2921+#include <min_osl.h>
     2922+#elif PMON
     2923+#include <pmon_osl.h>
     2924+#elif defined(MACOSX)
     2925+#include <macosx_osl.h>
    54132926+#else
    5414 +#define OSL_UNCACHED(va)       (va)
    5415 +#endif /* mips */
    5416 +
    5417 +
    5418 +#ifndef IL_BIGENDIAN
    5419 +#define R_REG(osh, r) (\
    5420 +       sizeof(*(r)) == sizeof(uint8) ? readb((volatile uint8*)(r)) : \
    5421 +       sizeof(*(r)) == sizeof(uint16) ? readw((volatile uint16*)(r)) : \
    5422 +       readl((volatile uint32*)(r)) \
    5423 +)
    5424 +#define W_REG(osh, r, v) do { \
    5425 +       switch (sizeof(*(r))) { \
    5426 +       case sizeof(uint8):     writeb((uint8)(v), (volatile uint8*)(r)); break; \
    5427 +       case sizeof(uint16):    writew((uint16)(v), (volatile uint16*)(r)); break; \
    5428 +       case sizeof(uint32):    writel((uint32)(v), (volatile uint32*)(r)); break; \
    5429 +       } \
    5430 +} while (0)
    5431 +#else  /* IL_BIGENDIAN */
    5432 +#define R_REG(osh, r) ({ \
    5433 +       __typeof(*(r)) __osl_v; \
    5434 +       switch (sizeof(*(r))) { \
    5435 +       case sizeof(uint8):     __osl_v = readb((volatile uint8*)((uint32)r^3)); break; \
    5436 +       case sizeof(uint16):    __osl_v = readw((volatile uint16*)((uint32)r^2)); break; \
    5437 +       case sizeof(uint32):    __osl_v = readl((volatile uint32*)(r)); break; \
    5438 +       } \
    5439 +       __osl_v; \
    5440 +})
    5441 +#define W_REG(osh, r, v) do { \
    5442 +       switch (sizeof(*(r))) { \
    5443 +       case sizeof(uint8):     writeb((uint8)(v), (volatile uint8*)((uint32)r^3)); break; \
    5444 +       case sizeof(uint16):    writew((uint16)(v), (volatile uint16*)((uint32)r^2)); break; \
    5445 +       case sizeof(uint32):    writel((uint32)(v), (volatile uint32*)(r)); break; \
    5446 +       } \
    5447 +} while (0)
    5448 +#endif /* IL_BIGENDIAN */
    5449 +
    5450 +/* dereference an address that may cause a bus exception */
    5451 +#define        BUSPROBE(val, addr)     get_dbe((val), (addr))
    5452 +#include <asm/paccess.h>
    5453 +
    5454 +/* map/unmap physical to virtual I/O */
    5455 +#define        REG_MAP(pa, size)       ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
    5456 +#define        REG_UNMAP(va)           iounmap((void *)(va))
    5457 +
    5458 +/* shared (dma-able) memory access macros */
    5459 +#define        R_SM(r)                 *(r)
    5460 +#define        W_SM(r, v)              (*(r) = (v))
    5461 +#define        BZERO_SM(r, len)        memset((r), '\0', (len))
    5462 +
    5463 +#define        MALLOC(osh, size)       kmalloc((size), GFP_ATOMIC)
    5464 +#define        MFREE(osh, addr, size)  kfree((addr))
    5465 +#define MALLOCED(osh)  (0)     
    5466 +
    5467 +#define        osl_delay               OSL_DELAY
    5468 +static inline void OSL_DELAY(uint usec)
    5469 +{
    5470 +       uint d;
    5471 +
    5472 +       while (usec > 0) {
    5473 +               d = MIN(usec, 1000);
    5474 +               udelay(d);
    5475 +               usec -= d;
    5476 +       }
    5477 +}
    5478 +
    5479 +static inline void
    5480 +bcm_mdelay(uint ms)
    5481 +{
    5482 +       uint i;
    5483 +
    5484 +       for (i = 0; i < ms; i++) {
    5485 +               OSL_DELAY(1000);
    5486 +       }
    5487 +}
    5488 +
    5489 +
    5490 +#define        OSL_PCMCIA_READ_ATTR(osh, offset, buf, size)
    5491 +#define        OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size)
    5492 +
    5493 +#define        OSL_PCI_READ_CONFIG(osh, offset, size) \
    5494 +       osl_pci_read_config((osh), (offset), (size))
    5495 +
    5496 +static inline uint32
    5497 +osl_pci_read_config(osl_t *osh, uint offset, uint size)
    5498 +{
    5499 +       uint val;
    5500 +       uint retry = PCI_CFG_RETRY;     
    5501 +
    5502 +       do {
    5503 +               pci_read_config_dword(osh->pdev, offset, &val);
    5504 +               if (val != 0xffffffff)
    5505 +                       break;
    5506 +       } while (retry--);
    5507 +
    5508 +       return (val);
    5509 +}
    5510 +
    5511 +#define        OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
    5512 +       osl_pci_write_config((osh), (offset), (size), (val))
    5513 +static inline void
    5514 +osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val)
    5515 +{
    5516 +       uint retry = PCI_CFG_RETRY;     
    5517 +
    5518 +       do {
    5519 +               pci_write_config_dword(osh->pdev, offset, val);
    5520 +               if (offset != PCI_BAR0_WIN)
    5521 +                       break;
    5522 +               if (osl_pci_read_config(osh, offset, size) == val)
    5523 +                       break;
    5524 +       } while (retry--);
    5525 +}
    5526 +
    5527 +
    5528 +/* return bus # for the pci device pointed by osh->pdev */
    5529 +#define OSL_PCI_BUS(osh)       osl_pci_bus(osh)
    5530 +static inline uint
    5531 +osl_pci_bus(osl_t *osh)
    5532 +{
    5533 +       return ((struct pci_dev *)osh->pdev)->bus->number;
    5534 +}
    5535 +
    5536 +/* return slot # for the pci device pointed by osh->pdev */
    5537 +#define OSL_PCI_SLOT(osh)      osl_pci_slot(osh)
    5538 +static inline uint
    5539 +osl_pci_slot(osl_t *osh)
    5540 +{
    5541 +       return PCI_SLOT(((struct pci_dev *)osh->pdev)->devfn);
    5542 +}
    5543 +
     2927+#error "Unsupported OSL requested"
    55442928+#endif
    5545 diff -urN linux.old/arch/mips/bcm947xx/include/pcicfg.h linux.dev/arch/mips/bcm947xx/include/pcicfg.h
    5546 --- linux.old/arch/mips/bcm947xx/include/pcicfg.h       1970-01-01 01:00:00.000000000 +0100
    5547 +++ linux.dev/arch/mips/bcm947xx/include/pcicfg.h       2006-04-27 20:31:41.000000000 +0200
    5548 @@ -0,0 +1,495 @@
     2929+
     2930+/* handy */
     2931+#define        SET_REG(r, mask, val)   W_REG((r), ((R_REG(r) & ~(mask)) | (val)))
     2932+#define        MAXPRIO         7       /* 0-7 */
     2933+
     2934+#endif /* _osl_h_ */
     2935diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/pcicfg.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/pcicfg.h
     2936--- linux-2.4.32/arch/mips/bcm947xx/include/pcicfg.h    1970-01-01 01:00:00.000000000 +0100
     2937+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/pcicfg.h    2006-07-02 21:58:25.000000000 +0200
     2938@@ -0,0 +1,369 @@
    55492939+/*
    5550 + * pcicfg.h: PCI configuration constants and structures.
     2940+ * pcicfg.h: PCI configuration  constants and structures.
    55512941+ *
    5552 + * Copyright 2006, Broadcom Corporation
     2942+ * Copyright 2005, Broadcom Corporation
    55532943+ * All Rights Reserved.
    55542944+ *
     
    55582948+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    55592949+ *
    5560 + * $Id: pcicfg.h,v 1.1.1.11 2006/04/08 06:13:40 honor Exp $
     2950+ * $Id$
    55612951+ */
    55622952+
    5563 +#ifndef        _h_pcicfg_
    5564 +#define        _h_pcicfg_
     2953+#ifndef        _h_pci_
     2954+#define        _h_pci_
    55652955+
    55662956+/* The following inside ifndef's so we don't collide with NTDDK.H */
     
    55882978+#define        PCICFG_SLOT_SHIFT       11      /* Slot shift */
    55892979+#define        PCICFG_FUN_SHIFT        8       /* Function shift */
    5590 +#define        PCICFG_OFF_SHIFT        0       /* Register shift */
     2980+#define        PCICFG_OFF_SHIFT        0       /* Bus shift */
    55912981+
    55922982+#define        PCICFG_BUS_MASK         0xff    /* Bus mask */
     
    56062996+#define        PCI_CONFIG_OFF(a)       (((a) >> PCICFG_OFF_SHIFT) & PCICFG_OFF_MASK)
    56072997+
    5608 +/* PCIE Config space accessing MACROS */
    5609 +
    5610 +#define        PCIECFG_BUS_SHIFT       24      /* Bus shift */
    5611 +#define        PCIECFG_SLOT_SHIFT      19      /* Slot/Device shift */
    5612 +#define        PCIECFG_FUN_SHIFT       16      /* Function shift */
    5613 +#define        PCIECFG_OFF_SHIFT       0       /* Register shift */
    5614 +
    5615 +#define        PCIECFG_BUS_MASK        0xff    /* Bus mask */
    5616 +#define        PCIECFG_SLOT_MASK       0x1f    /* Slot/Device mask */
    5617 +#define        PCIECFG_FUN_MASK        7       /* Function mask */
    5618 +#define        PCIECFG_OFF_MASK        0x3ff   /* Register mask */
    5619 +
    5620 +#define        PCIE_CONFIG_ADDR(b, s, f, o)                                    \
    5621 +               ((((b) & PCIECFG_BUS_MASK) << PCIECFG_BUS_SHIFT)                \
    5622 +                | (((s) & PCIECFG_SLOT_MASK) << PCIECFG_SLOT_SHIFT)    \
    5623 +                | (((f) & PCIECFG_FUN_MASK) << PCIECFG_FUN_SHIFT)      \
    5624 +                | (((o) & PCIECFG_OFF_MASK) << PCIECFG_OFF_SHIFT))
    5625 +
    5626 +#define        PCIE_CONFIG_BUS(a)      (((a) >> PCIECFG_BUS_SHIFT) & PCIECFG_BUS_MASK)
    5627 +#define        PCIE_CONFIG_SLOT(a)     (((a) >> PCIECFG_SLOT_SHIFT) & PCIECFG_SLOT_MASK)
    5628 +#define        PCIE_CONFIG_FUN(a)      (((a) >> PCIECFG_FUN_SHIFT) & PCIECFG_FUN_MASK)
    5629 +#define        PCIE_CONFIG_OFF(a)      (((a) >> PCIECFG_OFF_SHIFT) & PCIECFG_OFF_MASK)
    56302998+
    56312999+/* The actual config space */
     
    56373005+#define        PCR_RSVDA_MAX           2
    56383006+
    5639 +/* Bits in PCI bars' flags */
    5640 +
    5641 +#define        PCIBAR_FLAGS            0xf
    5642 +#define        PCIBAR_IO               0x1
    5643 +#define        PCIBAR_MEM1M            0x2
    5644 +#define        PCIBAR_MEM64            0x4
    5645 +#define        PCIBAR_PREFETCH         0x8
    5646 +#define        PCIBAR_MEM32_MASK       0xFFFFFF80
    5647 +
    5648 +/* pci config status reg has a bit to indicate that capability ptr is present */
    5649 +
    5650 +#define PCI_CAPPTR_PRESENT     0x0010
    5651 +
    56523007+typedef struct _pci_config_regs {
    5653 +       unsigned short  vendor;
    5654 +       unsigned short  device;
    5655 +       unsigned short  command;
    5656 +       unsigned short  status;
    5657 +       unsigned char   rev_id;
    5658 +       unsigned char   prog_if;
    5659 +       unsigned char   sub_class;
    5660 +       unsigned char   base_class;
    5661 +       unsigned char   cache_line_size;
    5662 +       unsigned char   latency_timer;
    5663 +       unsigned char   header_type;
    5664 +       unsigned char   bist;
    5665 +       unsigned long   base[PCI_BAR_MAX];
    5666 +       unsigned long   cardbus_cis;
    5667 +       unsigned short  subsys_vendor;
    5668 +       unsigned short  subsys_id;
    5669 +       unsigned long   baserom;
    5670 +       unsigned long   rsvd_a[PCR_RSVDA_MAX];
    5671 +       unsigned char   int_line;
    5672 +       unsigned char   int_pin;
    5673 +       unsigned char   min_gnt;
    5674 +       unsigned char   max_lat;
    5675 +       unsigned char   dev_dep[192];
     3008+    unsigned short     vendor;
     3009+    unsigned short     device;
     3010+    unsigned short     command;
     3011+    unsigned short     status;
     3012+    unsigned char      rev_id;
     3013+    unsigned char      prog_if;
     3014+    unsigned char      sub_class;
     3015+    unsigned char      base_class;
     3016+    unsigned char      cache_line_size;
     3017+    unsigned char      latency_timer;
     3018+    unsigned char      header_type;
     3019+    unsigned char      bist;
     3020+    unsigned long      base[PCI_BAR_MAX];
     3021+    unsigned long      cardbus_cis;
     3022+    unsigned short     subsys_vendor;
     3023+    unsigned short     subsys_id;
     3024+    unsigned long      baserom;
     3025+    unsigned long      rsvd_a[PCR_RSVDA_MAX];
     3026+    unsigned char      int_line;
     3027+    unsigned char      int_pin;
     3028+    unsigned char      min_gnt;
     3029+    unsigned char      max_lat;
     3030+    unsigned char      dev_dep[192];
    56763031+} pci_config_regs;
    56773032+
     
    57053060+#define        PCI_CFG_SSID            0x2e
    57063061+#define        PCI_CFG_ROMBAR          0x30
    5707 +#define PCI_CFG_CAPPTR         0x34
    57083062+#define        PCI_CFG_INT             0x3c
    57093063+#define        PCI_CFG_PIN             0x3d
     
    57113065+#define        PCI_CFG_MAXLAT          0x3f
    57123066+
    5713 +#ifdef __NetBSD__
    5714 +#undef PCI_CLASS_DISPLAY
    5715 +#undef PCI_CLASS_MEMORY
    5716 +#undef PCI_CLASS_BRIDGE
    5717 +#undef PCI_CLASS_INPUT
    5718 +#undef PCI_CLASS_DOCK
    5719 +#endif /* __NetBSD__ */
    5720 +
    57213067+/* Classes and subclasses */
    57223068+
    57233069+typedef enum {
    5724 +       PCI_CLASS_OLD = 0,
    5725 +       PCI_CLASS_DASDI,
    5726 +       PCI_CLASS_NET,
    5727 +       PCI_CLASS_DISPLAY,
    5728 +       PCI_CLASS_MMEDIA,
    5729 +       PCI_CLASS_MEMORY,
    5730 +       PCI_CLASS_BRIDGE,
    5731 +       PCI_CLASS_COMM,
    5732 +       PCI_CLASS_BASE,
    5733 +       PCI_CLASS_INPUT,
    5734 +       PCI_CLASS_DOCK,
    5735 +       PCI_CLASS_CPU,
    5736 +       PCI_CLASS_SERIAL,
    5737 +       PCI_CLASS_INTELLIGENT = 0xe,
    5738 +       PCI_CLASS_SATELLITE,
    5739 +       PCI_CLASS_CRYPT,
    5740 +       PCI_CLASS_DSP,
    5741 +       PCI_CLASS_XOR = 0xfe
     3070+    PCI_CLASS_OLD = 0,
     3071+    PCI_CLASS_DASDI,
     3072+    PCI_CLASS_NET,
     3073+    PCI_CLASS_DISPLAY,
     3074+    PCI_CLASS_MMEDIA,
     3075+    PCI_CLASS_MEMORY,
     3076+    PCI_CLASS_BRIDGE,
     3077+    PCI_CLASS_COMM,
     3078+    PCI_CLASS_BASE,
     3079+    PCI_CLASS_INPUT,
     3080+    PCI_CLASS_DOCK,
     3081+    PCI_CLASS_CPU,
     3082+    PCI_CLASS_SERIAL,
     3083+    PCI_CLASS_INTELLIGENT = 0xe,
     3084+    PCI_CLASS_SATELLITE,
     3085+    PCI_CLASS_CRYPT,
     3086+    PCI_CLASS_DSP,
     3087+    PCI_CLASS_MAX
    57423088+} pci_classes;
    57433089+
    57443090+typedef enum {
    5745 +       PCI_DASDI_SCSI,
    5746 +       PCI_DASDI_IDE,
    5747 +       PCI_DASDI_FLOPPY,
    5748 +       PCI_DASDI_IPI,
    5749 +       PCI_DASDI_RAID,
    5750 +       PCI_DASDI_OTHER = 0x80
     3091+    PCI_DASDI_SCSI,
     3092+    PCI_DASDI_IDE,
     3093+    PCI_DASDI_FLOPPY,
     3094+    PCI_DASDI_IPI,
     3095+    PCI_DASDI_RAID,
     3096+    PCI_DASDI_OTHER = 0x80
    57513097+} pci_dasdi_subclasses;
    57523098+
    57533099+typedef enum {
    5754 +       PCI_NET_ETHER,
    5755 +       PCI_NET_TOKEN,
    5756 +       PCI_NET_FDDI,
    5757 +       PCI_NET_ATM,
    5758 +       PCI_NET_OTHER = 0x80
     3100+    PCI_NET_ETHER,
     3101+    PCI_NET_TOKEN,
     3102+    PCI_NET_FDDI,
     3103+    PCI_NET_ATM,
     3104+    PCI_NET_OTHER = 0x80
    57593105+} pci_net_subclasses;
    57603106+
    57613107+typedef enum {
    5762 +       PCI_DISPLAY_VGA,
    5763 +       PCI_DISPLAY_XGA,
    5764 +       PCI_DISPLAY_3D,
    5765 +       PCI_DISPLAY_OTHER = 0x80
     3108+    PCI_DISPLAY_VGA,
     3109+    PCI_DISPLAY_XGA,
     3110+    PCI_DISPLAY_3D,
     3111+    PCI_DISPLAY_OTHER = 0x80
    57663112+} pci_display_subclasses;
    57673113+
    57683114+typedef enum {
    5769 +       PCI_MMEDIA_VIDEO,
    5770 +       PCI_MMEDIA_AUDIO,
    5771 +       PCI_MMEDIA_PHONE,
    5772 +       PCI_MEDIA_OTHER = 0x80
     3115+    PCI_MMEDIA_VIDEO,
     3116+    PCI_MMEDIA_AUDIO,
     3117+    PCI_MMEDIA_PHONE,
     3118+    PCI_MEDIA_OTHER = 0x80
    57733119+} pci_mmedia_subclasses;
    57743120+
    57753121+typedef enum {
    5776 +       PCI_MEMORY_RAM,
    5777 +       PCI_MEMORY_FLASH,
    5778 +       PCI_MEMORY_OTHER = 0x80
     3122+    PCI_MEMORY_RAM,
     3123+    PCI_MEMORY_FLASH,
     3124+    PCI_MEMORY_OTHER = 0x80
    57793125+} pci_memory_subclasses;
    57803126+
    57813127+typedef enum {
    5782 +       PCI_BRIDGE_HOST,
    5783 +       PCI_BRIDGE_ISA,
    5784 +       PCI_BRIDGE_EISA,
    5785 +       PCI_BRIDGE_MC,
    5786 +       PCI_BRIDGE_PCI,
    5787 +       PCI_BRIDGE_PCMCIA,
    5788 +       PCI_BRIDGE_NUBUS,
    5789 +       PCI_BRIDGE_CARDBUS,
    5790 +       PCI_BRIDGE_RACEWAY,
    5791 +       PCI_BRIDGE_OTHER = 0x80
     3128+    PCI_BRIDGE_HOST,
     3129+    PCI_BRIDGE_ISA,
     3130+    PCI_BRIDGE_EISA,
     3131+    PCI_BRIDGE_MC,
     3132+    PCI_BRIDGE_PCI,
     3133+    PCI_BRIDGE_PCMCIA,
     3134+    PCI_BRIDGE_NUBUS,
     3135+    PCI_BRIDGE_CARDBUS,
     3136+    PCI_BRIDGE_RACEWAY,
     3137+    PCI_BRIDGE_OTHER = 0x80
    57923138+} pci_bridge_subclasses;
    57933139+
    57943140+typedef enum {
    5795 +       PCI_COMM_UART,
    5796 +       PCI_COMM_PARALLEL,
    5797 +       PCI_COMM_MULTIUART,
    5798 +       PCI_COMM_MODEM,
    5799 +       PCI_COMM_OTHER = 0x80
     3141+    PCI_COMM_UART,
     3142+    PCI_COMM_PARALLEL,
     3143+    PCI_COMM_MULTIUART,
     3144+    PCI_COMM_MODEM,
     3145+    PCI_COMM_OTHER = 0x80
    58003146+} pci_comm_subclasses;
    58013147+
    58023148+typedef enum {
    5803 +       PCI_BASE_PIC,
    5804 +       PCI_BASE_DMA,
    5805 +       PCI_BASE_TIMER,
    5806 +       PCI_BASE_RTC,
    5807 +       PCI_BASE_PCI_HOTPLUG,
    5808 +       PCI_BASE_OTHER = 0x80
     3149+    PCI_BASE_PIC,
     3150+    PCI_BASE_DMA,
     3151+    PCI_BASE_TIMER,
     3152+    PCI_BASE_RTC,
     3153+    PCI_BASE_PCI_HOTPLUG,
     3154+    PCI_BASE_OTHER = 0x80
    58093155+} pci_base_subclasses;
    58103156+
    58113157+typedef enum {
    5812 +       PCI_INPUT_KBD,
    5813 +       PCI_INPUT_PEN,
    5814 +       PCI_INPUT_MOUSE,
    5815 +       PCI_INPUT_SCANNER,
    5816 +       PCI_INPUT_GAMEPORT,
    5817 +       PCI_INPUT_OTHER = 0x80
     3158+    PCI_INPUT_KBD,
     3159+    PCI_INPUT_PEN,
     3160+    PCI_INPUT_MOUSE,
     3161+    PCI_INPUT_SCANNER,
     3162+    PCI_INPUT_GAMEPORT,
     3163+    PCI_INPUT_OTHER = 0x80
    58183164+} pci_input_subclasses;
    58193165+
    58203166+typedef enum {
    5821 +       PCI_DOCK_GENERIC,
    5822 +       PCI_DOCK_OTHER = 0x80
     3167+    PCI_DOCK_GENERIC,
     3168+    PCI_DOCK_OTHER = 0x80
    58233169+} pci_dock_subclasses;
    58243170+
    58253171+typedef enum {
    5826 +       PCI_CPU_386,
    5827 +       PCI_CPU_486,
    5828 +       PCI_CPU_PENTIUM,
    5829 +       PCI_CPU_ALPHA = 0x10,
    5830 +       PCI_CPU_POWERPC = 0x20,
    5831 +       PCI_CPU_MIPS = 0x30,
    5832 +       PCI_CPU_COPROC = 0x40,
    5833 +       PCI_CPU_OTHER = 0x80
     3172+    PCI_CPU_386,
     3173+    PCI_CPU_486,
     3174+    PCI_CPU_PENTIUM,
     3175+    PCI_CPU_ALPHA = 0x10,
     3176+    PCI_CPU_POWERPC = 0x20,
     3177+    PCI_CPU_MIPS = 0x30,
     3178+    PCI_CPU_COPROC = 0x40,
     3179+    PCI_CPU_OTHER = 0x80
    58343180+} pci_cpu_subclasses;
    58353181+
    58363182+typedef enum {
    5837 +       PCI_SERIAL_IEEE1394,
    5838 +       PCI_SERIAL_ACCESS,
    5839 +       PCI_SERIAL_SSA,
    5840 +       PCI_SERIAL_USB,
    5841 +       PCI_SERIAL_FIBER,
    5842 +       PCI_SERIAL_SMBUS,
    5843 +       PCI_SERIAL_OTHER = 0x80
     3183+    PCI_SERIAL_IEEE1394,
     3184+    PCI_SERIAL_ACCESS,
     3185+    PCI_SERIAL_SSA,
     3186+    PCI_SERIAL_USB,
     3187+    PCI_SERIAL_FIBER,
     3188+    PCI_SERIAL_SMBUS,
     3189+    PCI_SERIAL_OTHER = 0x80
    58443190+} pci_serial_subclasses;
    58453191+
    58463192+typedef enum {
    5847 +       PCI_INTELLIGENT_I2O
     3193+    PCI_INTELLIGENT_I2O,
    58483194+} pci_intelligent_subclasses;
    58493195+
    58503196+typedef enum {
    5851 +       PCI_SATELLITE_TV,
    5852 +       PCI_SATELLITE_AUDIO,
    5853 +       PCI_SATELLITE_VOICE,
    5854 +       PCI_SATELLITE_DATA,
    5855 +       PCI_SATELLITE_OTHER = 0x80
     3197+    PCI_SATELLITE_TV,
     3198+    PCI_SATELLITE_AUDIO,
     3199+    PCI_SATELLITE_VOICE,
     3200+    PCI_SATELLITE_DATA,
     3201+    PCI_SATELLITE_OTHER = 0x80
    58563202+} pci_satellite_subclasses;
    58573203+
    58583204+typedef enum {
    5859 +       PCI_CRYPT_NETWORK,
    5860 +       PCI_CRYPT_ENTERTAINMENT,
    5861 +       PCI_CRYPT_OTHER = 0x80
     3205+    PCI_CRYPT_NETWORK,
     3206+    PCI_CRYPT_ENTERTAINMENT,
     3207+    PCI_CRYPT_OTHER = 0x80
    58623208+} pci_crypt_subclasses;
    58633209+
    58643210+typedef enum {
    5865 +       PCI_DSP_DPIO,
    5866 +       PCI_DSP_OTHER = 0x80
     3211+    PCI_DSP_DPIO,
     3212+    PCI_DSP_OTHER = 0x80
    58673213+} pci_dsp_subclasses;
    5868 +
    5869 +typedef enum {
    5870 +       PCI_XOR_QDMA,
    5871 +       PCI_XOR_OTHER = 0x80
    5872 +} pci_xor_subclasses;
    58733214+
    58743215+/* Header types */
     
    58863227+
    58873228+typedef struct _ppb_config_regs {
    5888 +       unsigned short  vendor;
    5889 +       unsigned short  device;
    5890 +       unsigned short  command;
    5891 +       unsigned short  status;
    5892 +       unsigned char   rev_id;
    5893 +       unsigned char   prog_if;
    5894 +       unsigned char   sub_class;
    5895 +       unsigned char   base_class;
    5896 +       unsigned char   cache_line_size;
    5897 +       unsigned char   latency_timer;
    5898 +       unsigned char   header_type;
    5899 +       unsigned char   bist;
    5900 +       unsigned long   rsvd_a[PPB_RSVDA_MAX];
    5901 +       unsigned char   prim_bus;
    5902 +       unsigned char   sec_bus;
    5903 +       unsigned char   sub_bus;
    5904 +       unsigned char   sec_lat;
    5905 +       unsigned char   io_base;
    5906 +       unsigned char   io_lim;
    5907 +       unsigned short  sec_status;
    5908 +       unsigned short  mem_base;
    5909 +       unsigned short  mem_lim;
    5910 +       unsigned short  pf_mem_base;
    5911 +       unsigned short  pf_mem_lim;
    5912 +       unsigned long   pf_mem_base_hi;
    5913 +       unsigned long   pf_mem_lim_hi;
    5914 +       unsigned short  io_base_hi;
    5915 +       unsigned short  io_lim_hi;
    5916 +       unsigned short  subsys_vendor;
    5917 +       unsigned short  subsys_id;
    5918 +       unsigned long   rsvd_b;
    5919 +       unsigned char   rsvd_c;
    5920 +       unsigned char   int_pin;
    5921 +       unsigned short  bridge_ctrl;
    5922 +       unsigned char   chip_ctrl;
    5923 +       unsigned char   diag_ctrl;
    5924 +       unsigned short  arb_ctrl;
    5925 +       unsigned long   rsvd_d[PPB_RSVDD_MAX];
    5926 +       unsigned char   dev_dep[192];
     3229+    unsigned short     vendor;
     3230+    unsigned short     device;
     3231+    unsigned short     command;
     3232+    unsigned short     status;
     3233+    unsigned char      rev_id;
     3234+    unsigned char      prog_if;
     3235+    unsigned char      sub_class;
     3236+    unsigned char      base_class;
     3237+    unsigned char      cache_line_size;
     3238+    unsigned char      latency_timer;
     3239+    unsigned char      header_type;
     3240+    unsigned char      bist;
     3241+    unsigned long      rsvd_a[PPB_RSVDA_MAX];
     3242+    unsigned char      prim_bus;
     3243+    unsigned char      sec_bus;
     3244+    unsigned char      sub_bus;
     3245+    unsigned char      sec_lat;
     3246+    unsigned char      io_base;
     3247+    unsigned char      io_lim;
     3248+    unsigned short     sec_status;
     3249+    unsigned short     mem_base;
     3250+    unsigned short     mem_lim;
     3251+    unsigned short     pf_mem_base;
     3252+    unsigned short     pf_mem_lim;
     3253+    unsigned long      pf_mem_base_hi;
     3254+    unsigned long      pf_mem_lim_hi;
     3255+    unsigned short     io_base_hi;
     3256+    unsigned short     io_lim_hi;
     3257+    unsigned short     subsys_vendor;
     3258+    unsigned short     subsys_id;
     3259+    unsigned long      rsvd_b;
     3260+    unsigned char      rsvd_c;
     3261+    unsigned char      int_pin;
     3262+    unsigned short     bridge_ctrl;
     3263+    unsigned char      chip_ctrl;
     3264+    unsigned char      diag_ctrl;
     3265+    unsigned short     arb_ctrl;
     3266+    unsigned long      rsvd_d[PPB_RSVDD_MAX];
     3267+    unsigned char      dev_dep[192];
    59273268+} ppb_config_regs;
    59283269+
    5929 +
    5930 +/* PCI CAPABILITY DEFINES */
    5931 +#define PCI_CAP_POWERMGMTCAP_ID                0x01
    5932 +#define PCI_CAP_MSICAP_ID              0x05
    5933 +#define PCI_CAP_PCIECAP_ID             0x10
    5934 +
    5935 +/* Data structure to define the Message Signalled Interrupt facility
    5936 + * Valid for PCI and PCIE configurations
    5937 + */
    5938 +typedef struct _pciconfig_cap_msi {
    5939 +       unsigned char capID;
    5940 +       unsigned char nextptr;
    5941 +       unsigned short msgctrl;
    5942 +       unsigned int msgaddr;
    5943 +} pciconfig_cap_msi;
    5944 +
    5945 +/* Data structure to define the Power managment facility
    5946 + * Valid for PCI and PCIE configurations
    5947 + */
    5948 +typedef struct _pciconfig_cap_pwrmgmt {
    5949 +       unsigned char capID;
    5950 +       unsigned char nextptr;
    5951 +       unsigned short pme_cap;
    5952 +       unsigned short pme_sts_ctrl;
    5953 +       unsigned char pme_bridge_ext;
    5954 +       unsigned char data;
    5955 +} pciconfig_cap_pwrmgmt;
    5956 +
    5957 +/* Data structure to define the PCIE capability */
    5958 +typedef struct _pciconfig_cap_pcie {
    5959 +       unsigned char capID;
    5960 +       unsigned char nextptr;
    5961 +       unsigned short pcie_cap;
    5962 +       unsigned int dev_cap;
    5963 +       unsigned short dev_ctrl;
    5964 +       unsigned short dev_status;
    5965 +       unsigned int link_cap;
    5966 +       unsigned short link_ctrl;
    5967 +       unsigned short link_status;
    5968 +} pciconfig_cap_pcie;
    5969 +
    5970 +/* PCIE Enhanced CAPABILITY DEFINES */
    5971 +#define PCIE_EXTCFG_OFFSET     0x100
    5972 +#define PCIE_ADVERRREP_CAPID   0x0001
    5973 +#define PCIE_VC_CAPID          0x0002
    5974 +#define PCIE_DEVSNUM_CAPID     0x0003
    5975 +#define PCIE_PWRBUDGET_CAPID   0x0004
    5976 +
    5977 +/* Header to define the PCIE specific capabilities in the extended config space */
    5978 +typedef struct _pcie_enhanced_caphdr {
    5979 +       unsigned short capID;
    5980 +       unsigned short cap_ver : 4;
    5981 +       unsigned short next_ptr : 12;
    5982 +} pcie_enhanced_caphdr;
    5983 +
    5984 +
    5985 +/* Everything below is BRCM HND proprietary */
    5986 +
    5987 +
    5988 +/* Brcm PCI configuration registers */
    5989 +#define cap_list       rsvd_a[0]
    5990 +#define bar0_window    dev_dep[0x80 - 0x40]
    5991 +#define bar1_window    dev_dep[0x84 - 0x40]
    5992 +#define sprom_control  dev_dep[0x88 - 0x40]
     3270+/* Eveything below is BRCM HND proprietary */
    59933271+
    59943272+#define        PCI_BAR0_WIN            0x80    /* backplane addres space accessed by BAR0 */
     
    60003278+#define PCI_TO_SB_MB           0x98    /* signal backplane interrupts */
    60013279+#define PCI_BACKPLANE_ADDR     0xA0    /* address an arbitrary location on the system backplane */
    6002 +#define PCI_BACKPLANE_DATA     0xA4    /* data at the location specified by above address */
     3280+#define PCI_BACKPLANE_DATA     0xA4    /* data at the location specified by above address register */
    60033281+#define        PCI_GPIO_IN             0xb0    /* pci config space gpio input (>=rev3) */
    60043282+#define        PCI_GPIO_OUT            0xb4    /* pci config space gpio output (>=rev3) */
    60053283+#define        PCI_GPIO_OUTEN          0xb8    /* pci config space gpio output enable (>=rev3) */
    60063284+
    6007 +#define        PCI_BAR0_SHADOW_OFFSET  (2 * 1024)      /* bar0 + 2K accesses sprom shadow (in pci core) */
    60083285+#define        PCI_BAR0_SPROM_OFFSET   (4 * 1024)      /* bar0 + 4K accesses external sprom */
    60093286+#define        PCI_BAR0_PCIREGS_OFFSET (6 * 1024)      /* bar0 + 6K accesses pci core registers */
    6010 +#define        PCI_BAR0_PCISBR_OFFSET  (4 * 1024)      /* pci core SB registers are at the end of the
    6011 +                                                * 8KB window, so their address is the "regular"
    6012 +                                                * address plus 4K
    6013 +                                                */
    6014 +#define PCI_BAR0_WINSZ         8192            /* bar0 window size */
    6015 +
    6016 +/* On pci corerev >= 13 and all pcie, the bar0 is now 16KB and it maps: */
    6017 +#define        PCI_16KB0_PCIREGS_OFFSET (8 * 1024)     /* bar0 + 8K accesses pci/pcie core registers */
    6018 +#define        PCI_16KB0_CCREGS_OFFSET (12 * 1024)     /* bar0 + 12K accesses chipc core registers */
    6019 +#define PCI_16KBB0_WINSZ       (16 * 1024)     /* bar0 window size */
    60203287+
    60213288+/* PCI_INT_STATUS */
     
    60283295+
    60293296+/* PCI_SPROM_CONTROL */
    6030 +#define SPROM_SZ_MSK           0x02    /* SPROM Size Mask */
    6031 +#define SPROM_LOCKED           0x08    /* SPROM Locked */
    6032 +#define        SPROM_BLANK             0x04    /* indicating a blank SPROM */
    6033 +#define SPROM_WRITEEN          0x10    /* SPROM write enable */
     3297+#define        SPROM_BLANK             0x04    /* indicating a blank sprom */
     3298+#define SPROM_WRITEEN          0x10    /* sprom write enable */
    60343299+#define SPROM_BOOTROM_WE       0x20    /* external bootrom write enable */
    6035 +#define SPROM_OTPIN_USE                0x80    /* device OTP In use */
    60363300+
    60373301+#define        SPROM_SIZE              256     /* sprom size in 16-bit */
     
    60413305+#define PCI_CFG_CMD_STAT_TA    0x08000000      /* target abort status */
    60423306+
    6043 +#endif /* _h_pcicfg_ */
    6044 diff -urN linux.old/arch/mips/bcm947xx/include/sbchipc.h linux.dev/arch/mips/bcm947xx/include/sbchipc.h
    6045 --- linux.old/arch/mips/bcm947xx/include/sbchipc.h      1970-01-01 01:00:00.000000000 +0100
    6046 +++ linux.dev/arch/mips/bcm947xx/include/sbchipc.h      2006-04-27 22:11:01.000000000 +0200
    6047 @@ -0,0 +1,516 @@
     3307+#endif
     3308diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbchipc.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbchipc.h
     3309--- linux-2.4.32/arch/mips/bcm947xx/include/sbchipc.h   1970-01-01 01:00:00.000000000 +0100
     3310+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbchipc.h   2006-07-02 21:58:25.000000000 +0200
     3311@@ -0,0 +1,394 @@
    60483312+/*
    60493313+ * SiliconBackplane Chipcommon core hardware definitions.
     
    60533317+ * gpio interface, extbus, and support for serial and parallel flashes.
    60543318+ *
    6055 + * $Id: sbchipc.h,v 1.1.1.14 2006/04/15 01:29:08 michael Exp $
    6056 + * Copyright 2006, Broadcom Corporation
     3319+ * $Id$
     3320+ * Copyright 2005, Broadcom Corporation
    60573321+ * All Rights Reserved.
    60583322+ *
     
    61233387+       /* Watchdog timer */
    61243388+       uint32  watchdog;               /* 0x80 */
    6125 +       uint32  PAD[1];
    6126 +
    6127 +       /* GPIO based LED powersave registers corerev >= 16 */
    6128 +       uint32  gpiotimerval;           /* 0x88 */
    6129 +       uint32  gpiotimeroutmask;
     3389+       uint32  PAD[3];
    61303390+
    61313391+       /* clock control */
     
    61343394+       uint32  clockcontrol_pci;       /* aka m1 */
    61353395+       uint32  clockcontrol_m2;        /* mii/uart/mipsref */
    6136 +       uint32  clockcontrol_m3;        /* cpu */
     3396+       uint32  clockcontrol_mips;      /* aka m3 */
    61373397+       uint32  clkdiv;                 /* corerev >= 3 */
    61383398+       uint32  PAD[2];
     
    61623422+       uint32  flash_config;
    61633423+       uint32  flash_waitcount;
    6164 +       uint32  PAD[44];
    6165 +
    6166 +       /* Clock control and hardware workarounds */
    6167 +       uint32  clk_ctl_st;
    6168 +       uint32  hw_war;
    6169 +       uint32  PAD[70];
     3424+       uint32  PAD[116];
    61703425+
    61713426+       /* uarts */
     
    61983453+#define        CC_JTAGDR               0x38
    61993454+#define        CC_JTAGCTRL             0x3c
    6200 +#define        CC_WATCHDOG             0x80
    6201 +#define        CC_CLKC_N               0x90
    6202 +#define        CC_CLKC_M0              0x94
    6203 +#define        CC_CLKC_M1              0x98
    6204 +#define        CC_CLKC_M2              0x9c
    6205 +#define        CC_CLKC_M3              0xa0
    62063455+#define        CC_CLKDIV               0xa4
    6207 +#define        CC_SYS_CLK_CTL          0xc0
    62083456+#define        CC_OTP                  0x800
    62093457+
    62103458+/* chipid */
    6211 +#define        CID_ID_MASK             0x0000ffff      /* Chip Id mask */
    6212 +#define        CID_REV_MASK            0x000f0000      /* Chip Revision mask */
    6213 +#define        CID_REV_SHIFT           16              /* Chip Revision shift */
    6214 +#define        CID_PKG_MASK            0x00f00000      /* Package Option mask */
    6215 +#define        CID_PKG_SHIFT           20              /* Package Option shift */
    6216 +#define        CID_CC_MASK             0x0f000000      /* CoreCount (corerev >= 4) */
     3459+#define        CID_ID_MASK             0x0000ffff              /* Chip Id mask */
     3460+#define        CID_REV_MASK            0x000f0000              /* Chip Revision mask */
     3461+#define        CID_REV_SHIFT           16                      /* Chip Revision shift */
     3462+#define        CID_PKG_MASK            0x00f00000              /* Package Option mask */
     3463+#define        CID_PKG_SHIFT           20                      /* Package Option shift */
     3464+#define        CID_CC_MASK             0x0f000000              /* CoreCount (corerev >= 4) */
    62173465+#define CID_CC_SHIFT           24
    62183466+
    62193467+/* capabilities */
    6220 +#define        CAP_UARTS_MASK          0x00000003      /* Number of uarts */
    6221 +#define CAP_MIPSEB             0x00000004      /* MIPS is in big-endian mode */
    6222 +#define CAP_UCLKSEL            0x00000018      /* UARTs clock select */
    6223 +#define CAP_UINTCLK            0x00000008      /* UARTs are driven by internal divided clock */
    6224 +#define CAP_UARTGPIO           0x00000020      /* UARTs own Gpio's 15:12 */
    6225 +#define CAP_EXTBUS_MASK                0x000000c0      /* External bus mask */
    6226 +#define CAP_EXTBUS_NONE                0x00000000      /* No ExtBus present */
    6227 +#define CAP_EXTBUS_FULL                0x00000040      /* ExtBus: PCMCIA, IDE & Prog */
    6228 +#define CAP_EXTBUS_PROG                0x00000080      /* ExtBus: ProgIf only */
    6229 +#define        CAP_FLASH_MASK          0x00000700      /* Type of flash */
    6230 +#define        CAP_PLL_MASK            0x00038000      /* Type of PLL */
    6231 +#define CAP_PWR_CTL            0x00040000      /* Power control */
    6232 +#define CAP_OTPSIZE            0x00380000      /* OTP Size (0 = none) */
    6233 +#define CAP_OTPSIZE_SHIFT      19              /* OTP Size shift */
    6234 +#define CAP_OTPSIZE_BASE       5               /* OTP Size base */
    6235 +#define CAP_JTAGP              0x00400000      /* JTAG Master Present */
    6236 +#define CAP_ROM                        0x00800000      /* Internal boot rom active */
    6237 +#define CAP_BKPLN64            0x08000000      /* 64-bit backplane */
     3468+#define        CAP_UARTS_MASK          0x00000003              /* Number of uarts */
     3469+#define CAP_MIPSEB             0x00000004              /* MIPS is in big-endian mode */
     3470+#define CAP_UCLKSEL            0x00000018              /* UARTs clock select */
     3471+#define CAP_UINTCLK            0x00000008              /* UARTs are driven by internal divided clock */
     3472+#define CAP_UARTGPIO           0x00000020              /* UARTs own Gpio's 15:12 */
     3473+#define CAP_EXTBUS             0x00000040              /* External bus present */
     3474+#define        CAP_FLASH_MASK          0x00000700              /* Type of flash */
     3475+#define        CAP_PLL_MASK            0x00038000              /* Type of PLL */
     3476+#define CAP_PWR_CTL            0x00040000              /* Power control */
     3477+#define CAP_OTPSIZE            0x00380000              /* OTP Size (0 = none) */
     3478+#define CAP_OTPSIZE_SHIFT      19                      /* OTP Size shift */
     3479+#define CAP_JTAGP              0x00400000              /* JTAG Master Present */
     3480+#define CAP_ROM                        0x00800000              /* Internal boot rom active */
    62383481+
    62393482+/* PLL type */
    62403483+#define PLL_NONE               0x00000000
    6241 +#define PLL_TYPE1              0x00010000      /* 48Mhz base, 3 dividers */
    6242 +#define PLL_TYPE2              0x00020000      /* 48Mhz, 4 dividers */
    6243 +#define PLL_TYPE3              0x00030000      /* 25Mhz, 2 dividers */
    6244 +#define PLL_TYPE4              0x00008000      /* 48Mhz, 4 dividers */
    6245 +#define PLL_TYPE5              0x00018000      /* 25Mhz, 4 dividers */
    6246 +#define PLL_TYPE6              0x00028000      /* 100/200 or 120/240 only */
    6247 +#define PLL_TYPE7              0x00038000      /* 25Mhz, 4 dividers */
     3484+#define PLL_TYPE1              0x00010000              /* 48Mhz base, 3 dividers */
     3485+#define PLL_TYPE2              0x00020000              /* 48Mhz, 4 dividers */
     3486+#define PLL_TYPE3              0x00030000              /* 25Mhz, 2 dividers */
     3487+#define PLL_TYPE4              0x00008000              /* 48Mhz, 4 dividers */
     3488+#define PLL_TYPE5              0x00018000              /* 25Mhz, 4 dividers */
     3489+#define PLL_TYPE6              0x00028000              /* 100/200 or 120/240 only */
     3490+#define PLL_TYPE7              0x00038000              /* 25Mhz, 4 dividers */
    62483491+
    62493492+/* corecontrol */
    6250 +#define CC_UARTCLKO            0x00000001      /* Drive UART with internal clock */
    6251 +#define        CC_SE                   0x00000002      /* sync clk out enable (corerev >= 3) */
    6252 +
    6253 +/* chipcontrol */
    6254 +#define CHIPCTRL_4321A0_DEFAULT        0x3a4           
    6255 +#define CHIPCTRL_4321A1_DEFAULT        0x0a4           
    6256 +
    6257 +/* Fields in the otpstatus register */
    6258 +#define        OTPS_PROGFAIL           0x80000000
    6259 +#define        OTPS_PROTECT            0x00000007
    6260 +#define        OTPS_HW_PROTECT         0x00000001
    6261 +#define        OTPS_SW_PROTECT         0x00000002
    6262 +#define        OTPS_CID_PROTECT        0x00000004
    6263 +
    6264 +/* Fields in the otpcontrol register */
    6265 +#define        OTPC_RECWAIT            0xff000000
    6266 +#define        OTPC_PROGWAIT           0x00ffff00
    6267 +#define        OTPC_PRW_SHIFT          8
    6268 +#define        OTPC_MAXFAIL            0x00000038
    6269 +#define        OTPC_VSEL               0x00000006
    6270 +#define        OTPC_SELVL              0x00000001
    6271 +
    6272 +/* Fields in otpprog */
    6273 +#define        OTPP_COL_MASK           0x000000ff
    6274 +#define        OTPP_ROW_MASK           0x0000ff00
    6275 +#define        OTPP_ROW_SHIFT          8
    6276 +#define        OTPP_READERR            0x10000000
    6277 +#define        OTPP_VALUE              0x20000000
    6278 +#define        OTPP_VALUE_SHIFT                29
    6279 +#define        OTPP_READ               0x40000000
    6280 +#define        OTPP_START              0x80000000
    6281 +#define        OTPP_BUSY               0x80000000
     3493+#define CC_UARTCLKO            0x00000001              /* Drive UART with internal clock */
     3494+#define        CC_SE                   0x00000002              /* sync clk out enable (corerev >= 3) */
    62823495+
    62833496+/* jtagcmd */
     
    62933506+#define JCMD0_ACC_PDR          0x00005000
    62943507+#define JCMD0_IRW_MASK         0x00000f00
    6295 +#define JCMD_ACC_MASK          0x000f0000      /* Changes for corerev 11 */
     3508+#define JCMD_ACC_MASK          0x000f0000              /* Changes for corerev 11 */
    62963509+#define JCMD_ACC_IRDR          0x00000000
    62973510+#define JCMD_ACC_DR            0x00010000
     
    63053518+
    63063519+/* jtagctrl */
    6307 +#define JCTRL_FORCE_CLK                4               /* Force clock */
    6308 +#define JCTRL_EXT_EN           2               /* Enable external targets */
    6309 +#define JCTRL_EN               1               /* Enable Jtag master */
     3520+#define JCTRL_FORCE_CLK                4                       /* Force clock */
     3521+#define JCTRL_EXT_EN           2                       /* Enable external targets */
     3522+#define JCTRL_EN               1                       /* Enable Jtag master */
    63103523+
    63113524+/* Fields in clkdiv */
    63123525+#define        CLKD_SFLASH             0x0f000000
    6313 +#define        CLKD_SFLASH_SHIFT       24
     3526+#define        CLKD_SFLASH_SHIFT               24
    63143527+#define        CLKD_OTP                0x000f0000
    63153528+#define        CLKD_OTP_SHIFT          16
    63163529+#define        CLKD_JTAG               0x00000f00
    6317 +#define        CLKD_JTAG_SHIFT         8
     3530+#define        CLKD_JTAG_SHIFT         8               
    63183531+#define        CLKD_UART               0x000000ff
    63193532+
    63203533+/* intstatus/intmask */
    6321 +#define        CI_GPIO                 0x00000001      /* gpio intr */
    6322 +#define        CI_EI                   0x00000002      /* ro: ext intr pin (corerev >= 3) */
    6323 +#define        CI_WDRESET              0x80000000      /* watchdog reset occurred */
     3534+#define        CI_GPIO                 0x00000001              /* gpio intr */
     3535+#define        CI_EI                   0x00000002              /* ro: ext intr pin (corerev >= 3) */
     3536+#define        CI_WDRESET              0x80000000              /* watchdog reset occurred */
    63243537+
    63253538+/* slow_clk_ctl */
    6326 +#define SCC_SS_MASK            0x00000007      /* slow clock source mask */
    6327 +#define        SCC_SS_LPO              0x00000000      /* source of slow clock is LPO */
    6328 +#define        SCC_SS_XTAL             0x00000001      /* source of slow clock is crystal */
    6329 +#define        SCC_SS_PCI              0x00000002      /* source of slow clock is PCI */
    6330 +#define SCC_LF                 0x00000200      /* LPOFreqSel, 1: 160Khz, 0: 32KHz */
    6331 +#define SCC_LP                 0x00000400      /* LPOPowerDown, 1: LPO is disabled,
    6332 +                                                * 0: LPO is enabled
    6333 +                                                */
    6334 +#define SCC_FS                 0x00000800      /* ForceSlowClk, 1: sb/cores running on slow clock,
    6335 +                                                * 0: power logic control
    6336 +                                                */
    6337 +#define SCC_IP                 0x00001000      /* IgnorePllOffReq, 1/0: power logic ignores/honors
    6338 +                                                * PLL clock disable requests from core
    6339 +                                                */
    6340 +#define SCC_XC                 0x00002000      /* XtalControlEn, 1/0: power logic does/doesn't
    6341 +                                                * disable crystal when appropriate
    6342 +                                                */
    6343 +#define SCC_XP                 0x00004000      /* XtalPU (RO), 1/0: crystal running/disabled */
    6344 +#define SCC_CD_MASK            0xffff0000      /* ClockDivider (SlowClk = 1/(4+divisor)) */
    6345 +#define SCC_CD_SHIFT           16
    6346 +
    6347 +/* system_clk_ctl */
    6348 +#define        SYCC_IE                 0x00000001      /* ILPen: Enable Idle Low Power */
    6349 +#define        SYCC_AE                 0x00000002      /* ALPen: Enable Active Low Power */
    6350 +#define        SYCC_FP                 0x00000004      /* ForcePLLOn */
    6351 +#define        SYCC_AR                 0x00000008      /* Force ALP (or HT if ALPen is not set */
    6352 +#define        SYCC_HR                 0x00000010      /* Force HT */
    6353 +#define SYCC_CD_MASK           0xffff0000      /* ClkDiv  (ILP = 1/(4 * (divisor + 1)) */
    6354 +#define SYCC_CD_SHIFT          16
    6355 +
    6356 +/* gpiotimerval */
    6357 +#define GPIO_ONTIME_SHIFT      16
     3539+#define SCC_SS_MASK            0x00000007              /* slow clock source mask */
     3540+#define        SCC_SS_LPO              0x00000000              /* source of slow clock is LPO */
     3541+#define        SCC_SS_XTAL             0x00000001              /* source of slow clock is crystal */
     3542+#define        SCC_SS_PCI              0x00000002              /* source of slow clock is PCI */
     3543+#define SCC_LF                 0x00000200              /* LPOFreqSel, 1: 160Khz, 0: 32KHz */
     3544+#define SCC_LP                 0x00000400              /* LPOPowerDown, 1: LPO is disabled, 0: LPO is enabled */
     3545+#define SCC_FS                 0x00000800              /* ForceSlowClk, 1: sb/cores running on slow clock, 0: power logic control */
     3546+#define SCC_IP                 0x00001000              /* IgnorePllOffReq, 1/0: power logic ignores/honors PLL clock disable requests from core */
     3547+#define SCC_XC                 0x00002000              /* XtalControlEn, 1/0: power logic does/doesn't disable crystal when appropriate */
     3548+#define SCC_XP                 0x00004000              /* XtalPU (RO), 1/0: crystal running/disabled */
     3549+#define SCC_CD_MASK            0xffff0000              /* ClockDivider mask, SlowClk = 1/(4+divisor) * crystal/PCI clock */
     3550+#define SCC_CD_SHF             16                      /* CLockDivider shift */
     3551+
     3552+/* sys_clk_ctl */
     3553+#define        SYCC_IE                 0x00000001              /* ILPen: Enable Idle Low Power */
     3554+#define        SYCC_AE                 0x00000002              /* ALPen: Enable Active Low Power */
     3555+#define        SYCC_FP                 0x00000004              /* ForcePLLOn */
     3556+#define        SYCC_AR                 0x00000008              /* Force ALP (or HT if ALPen is not set */
     3557+#define        SYCC_HR                 0x00000010              /* Force HT */
     3558+#define SYCC_CD_MASK           0xffff0000              /* ClockDivider mask, SlowClk = 1/(4+divisor) * crystal/PCI clock */
     3559+#define SYCC_CD_SHF            16                      /* CLockDivider shift */
    63583560+
    63593561+/* clockcontrol_n */
    6360 +#define        CN_N1_MASK              0x3f            /* n1 control */
    6361 +#define        CN_N2_MASK              0x3f00          /* n2 control */
     3562+#define        CN_N1_MASK              0x3f                    /* n1 control */
     3563+#define        CN_N2_MASK              0x3f00                  /* n2 control */
    63623564+#define        CN_N2_SHIFT             8
    6363 +#define        CN_PLLC_MASK            0xf0000         /* pll control */
     3565+#define        CN_PLLC_MASK            0xf0000                 /* pll control */
    63643566+#define        CN_PLLC_SHIFT           16
    63653567+
    63663568+/* clockcontrol_sb/pci/uart */
    6367 +#define        CC_M1_MASK              0x3f            /* m1 control */
    6368 +#define        CC_M2_MASK              0x3f00          /* m2 control */
     3569+#define        CC_M1_MASK              0x3f                    /* m1 control */
     3570+#define        CC_M2_MASK              0x3f00                  /* m2 control */
    63693571+#define        CC_M2_SHIFT             8
    6370 +#define        CC_M3_MASK              0x3f0000        /* m3 control */
     3572+#define        CC_M3_MASK              0x3f0000                /* m3 control */
    63713573+#define        CC_M3_SHIFT             16
    6372 +#define        CC_MC_MASK              0x1f000000      /* mux control */
     3574+#define        CC_MC_MASK              0x1f000000              /* mux control */
    63733575+#define        CC_MC_SHIFT             24
    63743576+
     3577+/* N3M Clock control values for 125Mhz */
     3578+#define        CC_125_N                0x0802                  /* Default values for bcm4310 */
     3579+#define        CC_125_M                0x04020009
     3580+#define        CC_125_M25              0x11090009
     3581+#define        CC_125_M33              0x11090005
     3582+
    63753583+/* N3M Clock control magic field values */
    6376 +#define        CC_F6_2                 0x02            /* A factor of 2 in */
    6377 +#define        CC_F6_3                 0x03            /* 6-bit fields like */
    6378 +#define        CC_F6_4                 0x05            /* N1, M1 or M3 */
     3584+#define        CC_F6_2                 0x02                    /* A factor of 2 in */
     3585+#define        CC_F6_3                 0x03                    /* 6-bit fields like */
     3586+#define        CC_F6_4                 0x05                    /* N1, M1 or M3 */
    63793587+#define        CC_F6_5                 0x09
    63803588+#define        CC_F6_6                 0x11
    63813589+#define        CC_F6_7                 0x21
    63823590+
    6383 +#define        CC_F5_BIAS              5               /* 5-bit fields get this added */
     3591+#define        CC_F5_BIAS              5                       /* 5-bit fields get this added */
    63843592+
    63853593+#define        CC_MC_BYPASS            0x08
     
    63903598+
    63913599+/* Type 2 Clock control magic field values */
    6392 +#define        CC_T2_BIAS              2               /* n1, n2, m1 & m3 bias */
    6393 +#define        CC_T2M2_BIAS            3               /* m2 bias */
     3600+#define        CC_T2_BIAS              2                       /* n1, n2, m1 & m3 bias */
     3601+#define        CC_T2M2_BIAS            3                       /* m2 bias */
    63943602+
    63953603+#define        CC_T2MC_M1BYP           1
     
    63983606+
    63993607+/* Type 6 Clock control magic field values */
    6400 +#define        CC_T6_MMASK             1               /* bits of interest in m */
    6401 +#define        CC_T6_M0                120000000       /* sb clock for m = 0 */
    6402 +#define        CC_T6_M1                100000000       /* sb clock for m = 1 */
     3608+#define        CC_T6_MMASK             1                       /* bits of interest in m */
     3609+#define        CC_T6_M0                120000000               /* sb clock for m = 0 */
     3610+#define        CC_T6_M1                100000000               /* sb clock for m = 1 */
    64033611+#define        SB2MIPS_T6(sb)          (2 * (sb))
    64043612+
    64053613+/* Common clock base */
    6406 +#define        CC_CLOCK_BASE1          24000000        /* Half the clock freq */
    6407 +#define CC_CLOCK_BASE2         12500000        /* Alternate crystal on some PLL's */
    6408 +
    6409 +/* Clock control values for 200Mhz in 5350 */
    6410 +#define        CLKC_5350_N             0x0311
    6411 +#define        CLKC_5350_M             0x04020009
     3614+#define        CC_CLOCK_BASE1          24000000                /* Half the clock freq */
     3615+#define CC_CLOCK_BASE2         12500000                /* Alternate crystal on some PLL's */
    64123616+
    64133617+/* Flash types in the chipcommon capabilities register */
     
    64173621+#define        PFLASH                  0x700           /* Parallel flash */
    64183622+
    6419 +/* Bits in the ExtBus config registers */
     3623+/* Bits in the config registers */
    64203624+#define        CC_CFG_EN               0x0001          /* Enable */
    64213625+#define        CC_CFG_EM_MASK          0x000e          /* Extif Mode */
    6422 +#define        CC_CFG_EM_ASYNC         0x0000          /*   Async/Parallel flash */
    6423 +#define        CC_CFG_EM_SYNC          0x0002          /*   Synchronous */
    6424 +#define        CC_CFG_EM_PCMCIA        0x0004          /*   PCMCIA */
    6425 +#define        CC_CFG_EM_IDE           0x0006          /*   IDE */
     3626+#define        CC_CFG_EM_ASYNC         0x0002          /*   Async/Parallel flash */
     3627+#define        CC_CFG_EM_SYNC          0x0004          /*   Synchronous */
     3628+#define        CC_CFG_EM_PCMCIA        0x0008          /*   PCMCIA */
     3629+#define        CC_CFG_EM_IDE           0x000a          /*   IDE */
    64263630+#define        CC_CFG_DS               0x0010          /* Data size, 0=8bit, 1=16bit */
    64273631+#define        CC_CFG_CD_MASK          0x0060          /* Sync: Clock divisor */
     
    64293633+#define        CC_CFG_SB               0x0100          /* Sync: Size/Bytestrobe */
    64303634+
    6431 +/* ExtBus address space */
    6432 +#define        CC_EB_BASE              0x1a000000      /* Chipc ExtBus base address */
    6433 +#define        CC_EB_PCMCIA_MEM        0x1a000000      /* PCMCIA 0 memory base address */
    6434 +#define        CC_EB_PCMCIA_IO         0x1a200000      /* PCMCIA 0 I/O base address */
    6435 +#define        CC_EB_PCMCIA_CFG        0x1a400000      /* PCMCIA 0 config base address */
    6436 +#define        CC_EB_IDE               0x1a800000      /* IDE memory base */
    6437 +#define        CC_EB_PCMCIA1_MEM       0x1a800000      /* PCMCIA 1 memory base address */
    6438 +#define        CC_EB_PCMCIA1_IO        0x1aa00000      /* PCMCIA 1 I/O base address */
    6439 +#define        CC_EB_PCMCIA1_CFG       0x1ac00000      /* PCMCIA 1 config base address */
    6440 +#define        CC_EB_PROGIF            0x1b000000      /* ProgIF Async/Sync base address */
    6441 +
    6442 +
    64433635+/* Start/busy bit in flashcontrol */
    6444 +#define SFLASH_OPCODE          0x000000ff
    6445 +#define SFLASH_ACTION          0x00000700
    64463636+#define SFLASH_START           0x80000000
    64473637+#define SFLASH_BUSY            SFLASH_START
    64483638+
    6449 +/* flashcontrol action codes */
    6450 +#define        SFLASH_ACT_OPONLY       0x0000          /* Issue opcode only */
    6451 +#define        SFLASH_ACT_OP1D         0x0100          /* opcode + 1 data byte */
    6452 +#define        SFLASH_ACT_OP3A         0x0200          /* opcode + 3 address bytes */
    6453 +#define        SFLASH_ACT_OP3A1D       0x0300          /* opcode + 3 addres & 1 data bytes */
    6454 +#define        SFLASH_ACT_OP3A4D       0x0400          /* opcode + 3 addres & 4 data bytes */
    6455 +#define        SFLASH_ACT_OP3A4X4D     0x0500          /* opcode + 3 addres, 4 don't care & 4 data bytes */
    6456 +#define        SFLASH_ACT_OP3A1X4D     0x0700          /* opcode + 3 addres, 1 don't care & 4 data bytes */
    6457 +
    6458 +/* flashcontrol action+opcodes for ST flashes */
     3639+/* flashcontrol opcodes for ST flashes */
    64593640+#define SFLASH_ST_WREN         0x0006          /* Write Enable */
    64603641+#define SFLASH_ST_WRDIS                0x0004          /* Write Disable */
     
    64753656+#define SFLASH_ST_SRWD         0x80            /* Status Register Write Disable */
    64763657+
    6477 +/* flashcontrol action+opcodes for Atmel flashes */
     3658+/* flashcontrol opcodes for Atmel flashes */
    64783659+#define SFLASH_AT_READ                         0x07e8
    64793660+#define SFLASH_AT_PAGE_READ                    0x07d2
     
    65043685+#define SFLASH_AT_ID_SHIFT                     3
    65053686+
    6506 +/* OTP regions */
    6507 +#define        OTP_HW_REGION   OTPS_HW_PROTECT
    6508 +#define        OTP_SW_REGION   OTPS_SW_PROTECT
    6509 +#define        OTP_CID_REGION  OTPS_CID_PROTECT
    6510 +
    6511 +/* OTP regions (Byte offsets from otp size) */
    6512 +#define        OTP_SWLIM_OFF   (-8)
    6513 +#define        OTP_CIDBASE_OFF 0
    6514 +#define        OTP_CIDLIM_OFF  8
    6515 +
    6516 +/* Predefined OTP words (Word offset from otp size) */
    6517 +#define        OTP_BOUNDARY_OFF (-4)
    6518 +#define        OTP_HWSIGN_OFF  (-3)
    6519 +#define        OTP_SWSIGN_OFF  (-2)
    6520 +#define        OTP_CIDSIGN_OFF (-1)
    6521 +
    6522 +#define        OTP_CID_OFF     0
    6523 +#define        OTP_PKG_OFF     1
    6524 +#define        OTP_FID_OFF     2
    6525 +#define        OTP_RSV_OFF     3
    6526 +#define        OTP_LIM_OFF     4
     3687+/* OTP conventions */
     3688+#define        OTP_HWBASE      0
     3689+#define        OTP_SWLIM       256
     3690+#define        OTP_CIDBASE     256
     3691+#define        OTP_CIDLIM      260
     3692+
     3693+#define        OTP_BOUNDARY    252
     3694+#define        OTP_HWSIGN      253
     3695+#define        OTP_SWSIGN      254
     3696+#define        OTP_CIDSIGN     255
     3697+
     3698+#define        OTP_CID         256
     3699+#define        OTP_PKG         257
     3700+#define        OTP_FID         258
    65273701+
    65283702+#define        OTP_SIGNATURE   0x578a
    65293703+#define        OTP_MAGIC       0x4e56
    65303704+
    6531 +/*
    6532 + * These are the UART port assignments, expressed as offsets from the base
    6533 + * register.  These assignments should hold for any serial port based on
    6534 + * a 8250, 16450, or 16550(A).
    6535 + */
    6536 +
    6537 +#define UART_RX                0       /* In:  Receive buffer (DLAB=0) */
    6538 +#define UART_TX                0       /* Out: Transmit buffer (DLAB=0) */
    6539 +#define UART_DLL       0       /* Out: Divisor Latch Low (DLAB=1) */
    6540 +#define UART_IER       1       /* In/Out: Interrupt Enable Register (DLAB=0) */
    6541 +#define UART_DLM       1       /* Out: Divisor Latch High (DLAB=1) */
    6542 +#define UART_IIR       2       /* In: Interrupt Identity Register  */
    6543 +#define UART_FCR       2       /* Out: FIFO Control Register */
    6544 +#define UART_LCR       3       /* Out: Line Control Register */
    6545 +#define UART_MCR       4       /* Out: Modem Control Register */
    6546 +#define UART_LSR       5       /* In:  Line Status Register */
    6547 +#define UART_MSR       6       /* In:  Modem Status Register */
    6548 +#define UART_SCR       7       /* I/O: Scratch Register */
    6549 +#define UART_LCR_DLAB  0x80    /* Divisor latch access bit */
    6550 +#define UART_LCR_WLEN8 0x03    /* Wordlength: 8 bits */
    6551 +#define UART_MCR_OUT2  0x08    /* MCR GPIO out 2 */
    6552 +#define UART_MCR_LOOP  0x10    /* Enable loopback test mode */
    6553 +#define UART_LSR_THRE  0x20    /* Transmit-hold-register empty */
    6554 +#define UART_LSR_RXRDY 0x01    /* Receiver ready */
    6555 +#define UART_FCR_FIFO_ENABLE 1 /* FIFO control register bit controlling FIFO enable/disable */
    6556 +
    6557 +/* Interrupt Enable Register (IER) bits */
    6558 +#define UART_IER_EDSSI 8       /* enable modem status interrupt */
    6559 +#define UART_IER_ELSI  4       /* enable receiver line status interrupt */
    6560 +#define UART_IER_ETBEI  2      /* enable transmitter holding register empty interrupt */
    6561 +#define UART_IER_ERBFI 1       /* enable data available interrupt */
    6562 +
    65633705+#endif /* _SBCHIPC_H */
    6564 diff -urN linux.old/arch/mips/bcm947xx/include/sbconfig.h linux.dev/arch/mips/bcm947xx/include/sbconfig.h
    6565 --- linux.old/arch/mips/bcm947xx/include/sbconfig.h     1970-01-01 01:00:00.000000000 +0100
    6566 +++ linux.dev/arch/mips/bcm947xx/include/sbconfig.h     2006-04-27 22:14:11.000000000 +0200
    6567 @@ -0,0 +1,369 @@
     3706diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbconfig.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbconfig.h
     3707--- linux-2.4.32/arch/mips/bcm947xx/include/sbconfig.h  1970-01-01 01:00:00.000000000 +0100
     3708+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbconfig.h  2006-07-02 21:58:25.000000000 +0200
     3709@@ -0,0 +1,324 @@
    65683710+/*
    65693711+ * Broadcom SiliconBackplane hardware register definitions.
    65703712+ *
    6571 + * Copyright 2006, Broadcom Corporation
    6572 + * All Rights Reserved.
    6573 + *
    6574 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    6575 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    6576 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    6577 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    6578 + *
    6579 + * $Id: sbconfig.h,v 1.1.1.11 2006/02/27 03:43:16 honor Exp $
     3713+ * Copyright 2005, Broadcom Corporation     
     3714+ * All Rights Reserved.     
     3715+ *       
     3716+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     3717+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     3718+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     3719+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     3720+ * $Id$
    65803721+ */
    65813722+
     
    65963737+#define SB_SDRAM_BASE          0x00000000      /* Physical SDRAM */
    65973738+#define SB_PCI_MEM             0x08000000      /* Host Mode sb2pcitranslation0 (64 MB) */
    6598 +#define SB_PCI_MEM_SZ          (64 * 1024 * 1024)
    65993739+#define SB_PCI_CFG             0x0c000000      /* Host Mode sb2pcitranslation1 (64 MB) */
    66003740+#define        SB_SDRAM_SWAPPED        0x10000000      /* Byteswapped Physical SDRAM */
     
    66063746+
    66073747+#define        SB_EXTIF_BASE           0x1f000000      /* External Interface region base address */
    6608 +#define        SB_FLASH1               0x1fc00000      /* MIPS Flash Region 1 */
    6609 +#define        SB_FLASH1_SZ            0x00400000      /* MIPS Size of Flash Region 1 */
    6610 +
    6611 +#define        SB_ROM                  0x20000000      /* ARM ROM */
    6612 +#define        SB_SRAM2                0x80000000      /* ARM SRAM Region 2 */
    6613 +#define        SB_ARM_FLASH1           0xffff0000      /* ARM Flash Region 1 */
    6614 +#define        SB_ARM_FLASH1_SZ        0x00010000      /* ARM Size of Flash Region 1 */
     3748+#define        SB_FLASH1               0x1fc00000      /* Flash Region 1 */
     3749+#define        SB_FLASH1_SZ            0x00400000      /* Size of Flash Region 1 */
    66153750+
    66163751+#define SB_PCI_DMA             0x40000000      /* Client Mode sb2pcitranslation2 (1 GB) */
    66173752+#define SB_PCI_DMA_SZ          0x40000000      /* Client Mode sb2pcitranslation2 size in bytes */
    6618 +#define SB_PCIE_DMA_L32                0x00000000      /* PCIE Client Mode sb2pcitranslation2
    6619 +                                                * (2 ZettaBytes), low 32 bits
    6620 +                                                */
    6621 +#define SB_PCIE_DMA_H32                0x80000000      /* PCIE Client Mode sb2pcitranslation2
    6622 +                                                * (2 ZettaBytes), high 32 bits
    6623 +                                                */
    66243753+#define        SB_EUART                (SB_EXTIF_BASE + 0x00800000)
    66253754+#define        SB_LED                  (SB_EXTIF_BASE + 0x00900000)
    6626 +
    66273755+
    66283756+/* enumeration space related defs */
    66293757+#define SB_CORE_SIZE           0x1000          /* each core gets 4Kbytes for registers */
    66303758+#define        SB_MAXCORES             ((SB_ENUM_LIM - SB_ENUM_BASE)/SB_CORE_SIZE)
    6631 +#define SB_MAXFUNCS            4               /* max. # functions per core */
    66323759+#define        SBCONFIGOFF             0xf00           /* core sbconfig regs are top 256bytes of regs */
    66333760+#define        SBCONFIGSIZE            256             /* sizeof (sbconfig_t) */
     
    66623789+#define SBIDLOW                        0xf8
    66633790+#define SBIDHIGH               0xfc
    6664 +
    6665 +/* All the previous registers are above SBCONFIGOFF, but with Sonics 2.3, we have
    6666 + * a few registers *below* that line. I think it would be very confusing to try
    6667 + * and change the value of SBCONFIGOFF, so I'm definig them as absolute offsets here,
    6668 + */
    6669 +
    6670 +#define SBIMERRLOGA            0xea8
    6671 +#define SBIMERRLOG             0xeb0
    6672 +#define SBTMPORTCONNID0                0xed8
    6673 +#define SBTMPORTLOCK0          0xef8
    66743791+
    66753792+#ifndef _LANGUAGE_ASSEMBLY
     
    67513868+/* sbtmstatelow */
    67523869+#define        SBTML_RESET             0x1             /* reset */
    6753 +#define        SBTML_REJ_MASK          0x6             /* reject */
    6754 +#define        SBTML_REJ_SHIFT         1
     3870+#define        SBTML_REJ               0x2             /* reject */
    67553871+#define        SBTML_CLK               0x10000         /* clock enable */
    67563872+#define        SBTML_FGC               0x20000         /* force gated clocks on */
     
    67653881+#define        SBTMH_TO                0x00000020      /* timeout (sonics >= 2.3) */
    67663882+#define        SBTMH_FL_MASK           0x1fff0000      /* core-specific flags */
    6767 +#define SBTMH_DMA64            0x10000000      /* supports DMA with 64-bit addresses */
    67683883+#define        SBTMH_GCR               0x20000000      /* gated clock request */
    67693884+#define        SBTMH_BISTF             0x40000000      /* bist failed */
    67703885+#define        SBTMH_BISTD             0x80000000      /* bist done */
    6771 +
    67723886+
    67733887+/* sbbwa0 */
     
    68583972+#define        SBIDL_RV_MASK           0xf0000000      /* sonics backplane revision code */
    68593973+#define        SBIDL_RV_SHIFT          28
    6860 +#define        SBIDL_RV_2_2            0x00000000      /* version 2.2 or earlier */
    6861 +#define        SBIDL_RV_2_3            0x10000000      /* version 2.3 */
    68623974+
    68633975+/* sbidhigh */
    6864 +#define        SBIDH_RC_MASK           0x000f          /* revision code */
    6865 +#define        SBIDH_RCE_MASK          0x7000          /* revision code extension field */
    6866 +#define        SBIDH_RCE_SHIFT         8
    6867 +#define        SBCOREREV(sbidh) \
    6868 +       ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK))
    6869 +#define        SBIDH_CC_MASK           0x8ff0          /* core code */
     3976+#define        SBIDH_RC_MASK           0xf             /* revision code*/
     3977+#define        SBIDH_CC_MASK           0xfff0          /* core code */
    68703978+#define        SBIDH_CC_SHIFT          4
    68713979+#define        SBIDH_VC_MASK           0xffff0000      /* vendor code */
     
    68783986+
    68793987+/* core codes */
    6880 +#define        SB_NODEV                0x700           /* Invalid coreid */
    68813988+#define        SB_CC                   0x800           /* chipcommon core */
    68823989+#define        SB_ILINE20              0x801           /* iline20 core */
     
    68913998+#define        SB_IPSEC                0x80b           /* ipsec core */
    68923999+#define        SB_PCMCIA               0x80d           /* pcmcia core */
    6893 +#define SB_SDIOD               SB_PCMCIA       /* pcmcia core has sdio device */
    68944000+#define        SB_SOCRAM               0x80e           /* internal memory core */
    68954001+#define        SB_MEMC                 0x80f           /* memc sdram core */
     
    69064012+#define        SB_SATAXOR              0x81e           /* serial ATA & XOR DMA core */
    69074013+#define        SB_GIGETH               0x81f           /* gigabit ethernet core */
    6908 +#define        SB_PCIE                 0x820           /* pci express core */
    6909 +#define        SB_MIMO                 0x821           /* MIMO phy core */
    6910 +#define        SB_SRAMC                0x822           /* SRAM controller core */
    6911 +#define        SB_MINIMAC              0x823           /* MINI MAC/phy core */
    6912 +#define        SB_ARM11                0x824           /* ARM 1176 core */
    6913 +#define        SB_ARM7                 0x825           /* ARM 7tdmi core */
    6914 +
    6915 +#define        SB_CC_IDX               0               /* chipc, when present, is always core 0 */
    69164014+
    69174015+/* Not really related to Silicon Backplane, but a couple of software
     
    69324030+#define        BISZ_BSSST_IDX          5               /*      5: text start */
    69334031+#define        BISZ_BSSEND_IDX         6               /*      6: text start */
    6934 +#define BISZ_SIZE              7               /* descriptor size in 32-bit intergers */
    69354032+
    69364033+#endif /* _SBCONFIG_H */
    6937 diff -urN linux.old/arch/mips/bcm947xx/include/sbextif.h linux.dev/arch/mips/bcm947xx/include/sbextif.h
    6938 --- linux.old/arch/mips/bcm947xx/include/sbextif.h      1970-01-01 01:00:00.000000000 +0100
    6939 +++ linux.dev/arch/mips/bcm947xx/include/sbextif.h      2006-04-27 22:13:03.000000000 +0200
    6940 @@ -0,0 +1,243 @@
     4034diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbextif.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbextif.h
     4035--- linux-2.4.32/arch/mips/bcm947xx/include/sbextif.h   1970-01-01 01:00:00.000000000 +0100
     4036+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbextif.h   2006-07-02 21:58:25.000000000 +0200
     4037@@ -0,0 +1,242 @@
    69414038+/*
    69424039+ * Hardware-specific External Interface I/O core definitions
     
    69534050+ * frequency control, a watchdog interrupt timer, and a GPIO interface.
    69544051+ *
    6955 + * Copyright 2006, Broadcom Corporation
    6956 + * All Rights Reserved.
    6957 + *
    6958 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    6959 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    6960 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    6961 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    6962 + *
    6963 + * $Id: sbextif.h,v 1.1.1.8 2006/02/27 03:43:16 honor Exp $
     4052+ * Copyright 2005, Broadcom Corporation     
     4053+ * All Rights Reserved.     
     4054+ *       
     4055+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     4056+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     4057+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     4058+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     4059+ * $Id$
    69644060+ */
    69654061+
     
    71824278+
    71834279+#endif /* _SBEXTIF_H */
    7184 diff -urN linux.old/arch/mips/bcm947xx/include/sbhndmips.h linux.dev/arch/mips/bcm947xx/include/sbhndmips.h
    7185 --- linux.old/arch/mips/bcm947xx/include/sbhndmips.h    1970-01-01 01:00:00.000000000 +0100
    7186 +++ linux.dev/arch/mips/bcm947xx/include/sbhndmips.h    2006-04-27 20:43:56.000000000 +0200
    7187 @@ -0,0 +1,47 @@
    7188 +/*
    7189 + * Broadcom SiliconBackplane MIPS definitions
    7190 + *
    7191 + * SB MIPS cores are custom MIPS32 processors with SiliconBackplane
    7192 + * OCP interfaces. The CP0 processor ID is 0x00024000, where bits
    7193 + * 23:16 mean Broadcom and bits 15:8 mean a MIPS core with an OCP
    7194 + * interface. The core revision is stored in the SB ID register in SB
    7195 + * configuration space.
    7196 + *
    7197 + * Copyright 2006, Broadcom Corporation
    7198 + * All Rights Reserved.
    7199 + *
    7200 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    7201 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    7202 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    7203 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    7204 + *
    7205 + * $Id: sbhndmips.h,v 1.1.1.1 2006/02/27 03:43:16 honor Exp $
    7206 + */
    7207 +
    7208 +#ifndef        _sbhndmips_h_
    7209 +#define        _sbhndmips_h_
    7210 +
    7211 +#include <mipsinc.h>
    7212 +
    7213 +#ifndef _LANGUAGE_ASSEMBLY
    7214 +
    7215 +/* cpp contortions to concatenate w/arg prescan */
    7216 +#ifndef PAD
    7217 +#define        _PADLINE(line)  pad ## line
    7218 +#define        _XSTR(line)     _PADLINE(line)
    7219 +#define        PAD             _XSTR(__LINE__)
    7220 +#endif /* PAD */
    7221 +
    7222 +typedef volatile struct {
    7223 +       uint32  corecontrol;
    7224 +       uint32  PAD[2];
    7225 +       uint32  biststatus;
    7226 +       uint32  PAD[4];
    7227 +       uint32  intstatus;
    7228 +       uint32  intmask;
    7229 +       uint32  timer;
    7230 +} mipsregs_t;
    7231 +
    7232 +#endif /* _LANGUAGE_ASSEMBLY */
    7233 +
    7234 +#endif /* _sbhndmips_h_ */
    7235 diff -urN linux.old/arch/mips/bcm947xx/include/sbmemc.h linux.dev/arch/mips/bcm947xx/include/sbmemc.h
    7236 --- linux.old/arch/mips/bcm947xx/include/sbmemc.h       1970-01-01 01:00:00.000000000 +0100
    7237 +++ linux.dev/arch/mips/bcm947xx/include/sbmemc.h       2006-04-27 22:12:41.000000000 +0200
     4280diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbmemc.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbmemc.h
     4281--- linux-2.4.32/arch/mips/bcm947xx/include/sbmemc.h    1970-01-01 01:00:00.000000000 +0100
     4282+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbmemc.h    2006-07-02 21:58:25.000000000 +0200
    72384283@@ -0,0 +1,147 @@
    72394284+/*
    72404285+ * BCM47XX Sonics SiliconBackplane DDR/SDRAM controller core hardware definitions.
    72414286+ *
    7242 + * Copyright 2006, Broadcom Corporation
    7243 + * All Rights Reserved.
    7244 + *
    7245 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    7246 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    7247 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    7248 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
     4287+ * Copyright 2005, Broadcom Corporation     
     4288+ * All Rights Reserved.     
     4289+ *      
     4290+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     4291+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     4292+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     4293+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
    72494294+ *
    7250 + * $Id: sbmemc.h,v 1.6 2006/03/02 12:33:44 honor Exp $
     4295+ * $Id$
    72514296+ */
    72524297+
     
    72784323+#define        MEMC_CORE               0x54
    72794324+
    7280 +#else  /* !_LANGUAGE_ASSEMBLY */
     4325+
     4326+#else
    72814327+
    72824328+/* Sonics side: MEMC core registers */
     
    73064352+} sbmemcregs_t;
    73074353+
    7308 +#endif /* _LANGUAGE_ASSEMBLY */
     4354+#endif
    73094355+
    73104356+/* MEMC Core Init values (OCP ID 0x80f) */
     
    73394385+#define MEMC_DRAMTIM25_INIT    0x000754d9
    73404386+#define MEMC_RDNCDLCOR_INIT    0x00000000
    7341 +#define MEMC_RDNCDLCOR_SIMINIT 0xf6f6f6f6      /* For hdl sim */
    73424387+#define MEMC_WRNCDLCOR_INIT    0x49351200
    73434388+#define MEMC_1_WRNCDLCOR_INIT  0x14500200
     
    73844429+
    73854430+#endif /* _SBMEMC_H */
    7386 diff -urN linux.old/arch/mips/bcm947xx/include/sbpci.h linux.dev/arch/mips/bcm947xx/include/sbpci.h
    7387 --- linux.old/arch/mips/bcm947xx/include/sbpci.h        1970-01-01 01:00:00.000000000 +0100
    7388 +++ linux.dev/arch/mips/bcm947xx/include/sbpci.h        2006-05-02 17:20:14.000000000 +0200
    7389 @@ -0,0 +1,114 @@
     4431diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbmips.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbmips.h
     4432--- linux-2.4.32/arch/mips/bcm947xx/include/sbmips.h    1970-01-01 01:00:00.000000000 +0100
     4433+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbmips.h    2006-07-02 21:58:25.000000000 +0200
     4434@@ -0,0 +1,60 @@
    73904435+/*
    7391 + * HND SiliconBackplane PCI core hardware definitions.
     4436+ * Broadcom SiliconBackplane MIPS definitions
    73924437+ *
    7393 + * Copyright 2006, Broadcom Corporation
     4438+ * SB MIPS cores are custom MIPS32 processors with SiliconBackplane
     4439+ * OCP interfaces. The CP0 processor ID is 0x00024000, where bits
     4440+ * 23:16 mean Broadcom and bits 15:8 mean a MIPS core with an OCP
     4441+ * interface. The core revision is stored in the SB ID register in SB
     4442+ * configuration space.
     4443+ *
     4444+ * Copyright 2005, Broadcom Corporation
    73944445+ * All Rights Reserved.
    73954446+ *
     
    73994450+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    74004451+ *
    7401 + * $Id: sbpci.h,v 1.1.1.11 2006/02/27 03:43:16 honor Exp $
     4452+ * $Id$
    74024453+ */
    74034454+
    7404 +#ifndef        _sbpci_h_
    7405 +#define        _sbpci_h_
     4455+#ifndef        _SBMIPS_H
     4456+#define        _SBMIPS_H
    74064457+
    74074458+#ifndef _LANGUAGE_ASSEMBLY
     4459+
     4460+/* cpp contortions to concatenate w/arg prescan */
     4461+#ifndef PAD
     4462+#define        _PADLINE(line)  pad ## line
     4463+#define        _XSTR(line)     _PADLINE(line)
     4464+#define        PAD             _XSTR(__LINE__)
     4465+#endif /* PAD */
     4466+
     4467+typedef volatile struct {
     4468+       uint32  corecontrol;
     4469+       uint32  PAD[2];
     4470+       uint32  biststatus;
     4471+       uint32  PAD[4];
     4472+       uint32  intstatus;
     4473+       uint32  intmask;
     4474+       uint32  timer;
     4475+} mipsregs_t;
     4476+
     4477+extern uint32 sb_flag(void *sbh);
     4478+extern uint sb_irq(void *sbh);
     4479+
     4480+extern void BCMINIT(sb_serial_init)(void *sbh, void (*add)(void *regs, uint irq, uint baud_base, uint reg_shift));
     4481+
     4482+extern void *sb_jtagm_init(void *sbh, uint clkd, bool exttap);
     4483+extern void sb_jtagm_disable(void *h);
     4484+extern uint32 jtag_rwreg(void *h, uint32 ir, uint32 dr);
     4485+extern void BCMINIT(sb_mips_init)(void *sbh);
     4486+extern uint32 BCMINIT(sb_mips_clock)(void *sbh);
     4487+extern bool BCMINIT(sb_mips_setclock)(void *sbh, uint32 mipsclock, uint32 sbclock, uint32 pciclock);
     4488+
     4489+extern uint32 BCMINIT(sb_memc_get_ncdl)(void *sbh);
     4490+extern uint32 BCMINIT(sb_mips_get_pfc)(void *sbh);
     4491+
     4492+#endif /* _LANGUAGE_ASSEMBLY */
     4493+
     4494+#endif /* _SBMIPS_H */
     4495diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbpci.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbpci.h
     4496--- linux-2.4.32/arch/mips/bcm947xx/include/sbpci.h     1970-01-01 01:00:00.000000000 +0100
     4497+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbpci.h     2006-07-02 21:58:25.000000000 +0200
     4498@@ -0,0 +1,117 @@
     4499+/*
     4500+ * BCM47XX Sonics SiliconBackplane PCI core hardware definitions.
     4501+ *
     4502+ * $Id$
     4503+ * Copyright 2005, Broadcom Corporation     
     4504+ * All Rights Reserved.     
     4505+ *       
     4506+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     4507+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     4508+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     4509+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     4510+ */
     4511+
     4512+#ifndef        _SBPCI_H
     4513+#define        _SBPCI_H
    74084514+
    74094515+/* cpp contortions to concatenate w/arg prescan */
     
    74354541+       uint32 sbtopci1;        /* Sonics to PCI translation 1 */
    74364542+       uint32 sbtopci2;        /* Sonics to PCI translation 2 */
    7437 +       uint32 PAD[189];
    7438 +       uint32 pcicfg[4][64];   /* 0x400 - 0x7FF, PCI Cfg Space (>=rev8) */
     4543+       uint32 PAD[445];
    74394544+       uint16 sprom[36];       /* SPROM shadow Area */
    74404545+       uint32 PAD[46];
    74414546+} sbpciregs_t;
    7442 +
    7443 +#endif /* _LANGUAGE_ASSEMBLY */
    74444547+
    74454548+/* PCI control */
     
    74474550+#define PCI_RST                0x02    /* Value driven out to pin */
    74484551+#define PCI_CLK_OE     0x04    /* When set, drives clock as gated by PCI_CLK out to pin */
    7449 +#define PCI_CLK                0x08    /* Gate for clock driven out to pin */
     4552+#define PCI_CLK                0x08    /* Gate for clock driven out to pin */ 
    74504553+
    74514554+/* PCI arbiter control */
    74524555+#define PCI_INT_ARB    0x01    /* When set, use an internal arbiter */
    74534556+#define PCI_EXT_ARB    0x02    /* When set, use an external arbiter */
    7454 +/* ParkID - for PCI corerev >= 8 */
    7455 +#define PCI_PARKID_MASK                0x1c    /* Selects which agent is parked on an idle bus */
    7456 +#define PCI_PARKID_SHIFT       2
    7457 +#define PCI_PARKID_EXT0                0       /* External master 0 */
    7458 +#define PCI_PARKID_EXT1                1       /* External master 1 */
    7459 +#define PCI_PARKID_EXT2                2       /* External master 2 */
    7460 +#define PCI_PARKID_INT         3       /* Internal master */
    7461 +#define PCI_PARKID_LAST                4       /* Last active master */
     4557+#define PCI_PARKID_MASK        0x06    /* Selects which agent is parked on an idle bus */
     4558+#define PCI_PARKID_SHIFT   1
     4559+#define PCI_PARKID_LAST           0    /* Last requestor */
     4560+#define PCI_PARKID_4710           1    /* 4710 */
     4561+#define PCI_PARKID_EXTREQ0 2   /* External requestor 0 */
     4562+#define PCI_PARKID_EXTREQ1 3   /* External requestor 1 */
    74624563+
    74634564+/* Interrupt status/mask */
     
    74964597+#define        SBTOPCI_RC_READMULTI    0x20    /* memory read multiple */
    74974598+
    7498 +/* PCI core index in SROM shadow area */
    7499 +#define SRSH_PI_OFFSET 0       /* first word */
    7500 +#define SRSH_PI_MASK   0xf000  /* bit 15:12 */
    7501 +#define SRSH_PI_SHIFT  12      /* bit 15:12 */
    7502 +
    7503 +#endif /* _sbpci_h_ */
    7504 diff -urN linux.old/arch/mips/bcm947xx/include/sbpcie.h linux.dev/arch/mips/bcm947xx/include/sbpcie.h
    7505 --- linux.old/arch/mips/bcm947xx/include/sbpcie.h       1970-01-01 01:00:00.000000000 +0100
    7506 +++ linux.dev/arch/mips/bcm947xx/include/sbpcie.h       2006-04-27 20:42:22.000000000 +0200
    7507 @@ -0,0 +1,200 @@
    7508 +/*
    7509 + * BCM43XX SiliconBackplane PCIE core hardware definitions.
    7510 + *
    7511 + * Copyright 2006, Broadcom Corporation
    7512 + * All Rights Reserved.
    7513 + *
    7514 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    7515 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    7516 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    7517 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    7518 + *
    7519 + * $Id: sbpcie.h,v 1.1.1.2 2006/02/27 03:43:16 honor Exp $
    7520 + */
    7521 +
    7522 +#ifndef        _SBPCIE_H
    7523 +#define        _SBPCIE_H
    7524 +
    7525 +/* cpp contortions to concatenate w/arg prescan */
    7526 +#ifndef PAD
    7527 +#define        _PADLINE(line)  pad ## line
    7528 +#define        _XSTR(line)     _PADLINE(line)
    7529 +#define        PAD             _XSTR(__LINE__)
    7530 +#endif
    7531 +
    7532 +/* PCIE Enumeration space offsets */
    7533 +#define  PCIE_CORE_CONFIG_OFFSET       0x0
    7534 +#define  PCIE_FUNC0_CONFIG_OFFSET      0x400
    7535 +#define  PCIE_FUNC1_CONFIG_OFFSET      0x500
    7536 +#define  PCIE_FUNC2_CONFIG_OFFSET      0x600
    7537 +#define  PCIE_FUNC3_CONFIG_OFFSET      0x700
    7538 +#define  PCIE_SPROM_SHADOW_OFFSET      0x800
    7539 +#define  PCIE_SBCONFIG_OFFSET          0xE00
    7540 +
    7541 +/* PCIE Bar0 Address Mapping. Each function maps 16KB config space */
    7542 +#define PCIE_DEV_BAR0_SIZE             0x4000
    7543 +#define PCIE_BAR0_WINMAPCORE_OFFSET    0x0
    7544 +#define PCIE_BAR0_EXTSPROM_OFFSET      0x1000
    7545 +#define PCIE_BAR0_PCIECORE_OFFSET      0x2000
    7546 +#define PCIE_BAR0_CCCOREREG_OFFSET     0x3000
    7547 +
    7548 +/* SB side: PCIE core and host control registers */
    7549 +typedef struct sbpcieregs {
    7550 +       uint32 PAD[3];
    7551 +       uint32 biststatus;      /* bist Status: 0x00C */
    7552 +       uint32 PAD[6];
    7553 +       uint32 sbtopcimailbox;  /* sb to pcie mailbox: 0x028 */
    7554 +       uint32 PAD[54];
    7555 +       uint32 sbtopcie0;       /* sb to pcie translation 0: 0x100 */
    7556 +       uint32 sbtopcie1;       /* sb to pcie translation 1: 0x104 */
    7557 +       uint32 sbtopcie2;       /* sb to pcie translation 2: 0x108 */
    7558 +       uint32 PAD[4];
    7559 +
    7560 +       /* pcie core supports in direct access to config space */
    7561 +       uint32 configaddr;      /* pcie config space access: Address field: 0x120 */
    7562 +       uint32 configdata;      /* pcie config space access: Data field: 0x124 */
    7563 +
    7564 +       /* mdio access to serdes */
    7565 +       uint32 mdiocontrol;     /* controls the mdio access: 0x128 */
    7566 +       uint32 mdiodata;        /* Data to the mdio access: 0x12c */
    7567 +
    7568 +       /* pcie protocol phy/dllp/tlp register access mechanism */
    7569 +       uint32 pcieaddr;        /* address of the internal registeru: 0x130 */
    7570 +       uint32 pciedata;        /* Data to/from the internal regsiter: 0x134 */
    7571 +
    7572 +       uint32 PAD[434];
    7573 +       uint16 sprom[36];       /* SPROM shadow Area */
    7574 +} sbpcieregs_t;
    7575 +
    7576 +/* SB to PCIE translation masks */
    7577 +#define SBTOPCIE0_MASK 0xfc000000
    7578 +#define SBTOPCIE1_MASK 0xfc000000
    7579 +#define SBTOPCIE2_MASK 0xc0000000
    7580 +
    7581 +/* Access type bits (0:1) */
    7582 +#define SBTOPCIE_MEM   0
    7583 +#define SBTOPCIE_IO    1
    7584 +#define SBTOPCIE_CFG0  2
    7585 +#define SBTOPCIE_CFG1  3
    7586 +
    7587 +/* Prefetch enable bit 2 */
    7588 +#define SBTOPCIE_PF            4
    7589 +
    7590 +/* Write Burst enable for memory write bit 3 */
    7591 +#define SBTOPCIE_WR_BURST      8
    7592 +
    7593 +/* config access */
    7594 +#define CONFIGADDR_FUNC_MASK   0x7000
    7595 +#define CONFIGADDR_FUNC_SHF    12
    7596 +#define CONFIGADDR_REG_MASK    0x0FFF
    7597 +#define CONFIGADDR_REG_SHF     0
    7598 +
    7599 +/* PCIE protocol regs Indirect Address */
    7600 +#define PCIEADDR_PROT_MASK     0x300
    7601 +#define PCIEADDR_PROT_SHF      8
    7602 +#define PCIEADDR_PL_TLP                0
    7603 +#define PCIEADDR_PL_DLLP       1
    7604 +#define PCIEADDR_PL_PLP                2
    7605 +
    7606 +/* PCIE protocol PHY diagnostic registers */
    7607 +#define        PCIE_PLP_MODEREG                0x200 /* Mode */
    7608 +#define        PCIE_PLP_STATUSREG              0x204 /* Status */
    7609 +#define PCIE_PLP_LTSSMCTRLREG          0x208 /* LTSSM control */
    7610 +#define PCIE_PLP_LTLINKNUMREG          0x20c /* Link Training Link number */
    7611 +#define PCIE_PLP_LTLANENUMREG          0x210 /* Link Training Lane number */
    7612 +#define PCIE_PLP_LTNFTSREG             0x214 /* Link Training N_FTS */
    7613 +#define PCIE_PLP_ATTNREG               0x218 /* Attention */
    7614 +#define PCIE_PLP_ATTNMASKREG           0x21C /* Attention Mask */
    7615 +#define PCIE_PLP_RXERRCTR              0x220 /* Rx Error */
    7616 +#define PCIE_PLP_RXFRMERRCTR           0x224 /* Rx Framing Error */
    7617 +#define PCIE_PLP_RXERRTHRESHREG                0x228 /* Rx Error threshold */
    7618 +#define PCIE_PLP_TESTCTRLREG           0x22C /* Test Control reg */
    7619 +#define PCIE_PLP_SERDESCTRLOVRDREG     0x230 /* SERDES Control Override */
    7620 +#define PCIE_PLP_TIMINGOVRDREG         0x234 /* Timing param override */
    7621 +#define PCIE_PLP_RXTXSMDIAGREG         0x238 /* RXTX State Machine Diag */
    7622 +#define PCIE_PLP_LTSSMDIAGREG          0x23C /* LTSSM State Machine Diag */
    7623 +
    7624 +/* PCIE protocol DLLP diagnostic registers */
    7625 +#define PCIE_DLLP_LCREG                        0x100 /* Link Control */
    7626 +#define PCIE_DLLP_LSREG                        0x104 /* Link Status */
    7627 +#define PCIE_DLLP_LAREG                        0x108 /* Link Attention */
    7628 +#define PCIE_DLLP_LAMASKREG            0x10C /* Link Attention Mask */
    7629 +#define PCIE_DLLP_NEXTTXSEQNUMREG      0x110 /* Next Tx Seq Num */
    7630 +#define PCIE_DLLP_ACKEDTXSEQNUMREG     0x114 /* Acked Tx Seq Num */
    7631 +#define PCIE_DLLP_PURGEDTXSEQNUMREG    0x118 /* Purged Tx Seq Num */
    7632 +#define PCIE_DLLP_RXSEQNUMREG          0x11C /* Rx Sequence Number */
    7633 +#define PCIE_DLLP_LRREG                        0x120 /* Link Replay */
    7634 +#define PCIE_DLLP_LACKTOREG            0x124 /* Link Ack Timeout */
    7635 +#define PCIE_DLLP_PMTHRESHREG          0x128 /* Power Management Threshold */
    7636 +#define PCIE_DLLP_RTRYWPREG            0x12C /* Retry buffer write ptr */
    7637 +#define PCIE_DLLP_RTRYRPREG            0x130 /* Retry buffer Read ptr */
    7638 +#define PCIE_DLLP_RTRYPPREG            0x134 /* Retry buffer Purged ptr */
    7639 +#define PCIE_DLLP_RTRRWREG             0x138 /* Retry buffer Read/Write */
    7640 +#define PCIE_DLLP_ECTHRESHREG          0x13C /* Error Count Threshold */
    7641 +#define PCIE_DLLP_TLPERRCTRREG         0x140 /* TLP Error Counter */
    7642 +#define PCIE_DLLP_ERRCTRREG            0x144 /* Error Counter */
    7643 +#define PCIE_DLLP_NAKRXCTRREG          0x148 /* NAK Received Counter */
    7644 +#define PCIE_DLLP_TESTREG              0x14C /* Test */
    7645 +#define PCIE_DLLP_PKTBIST              0x150 /* Packet BIST */
    7646 +
    7647 +/* PCIE protocol TLP diagnostic registers */
    7648 +#define PCIE_TLP_CONFIGREG             0x000 /* Configuration */
    7649 +#define PCIE_TLP_WORKAROUNDSREG                0x004 /* TLP Workarounds */
    7650 +#define PCIE_TLP_WRDMAUPPER            0x010 /* Write DMA Upper Address */
    7651 +#define PCIE_TLP_WRDMALOWER            0x014 /* Write DMA Lower Address */
    7652 +#define PCIE_TLP_WRDMAREQ_LBEREG       0x018 /* Write DMA Len/ByteEn Req */
    7653 +#define PCIE_TLP_RDDMAUPPER            0x01C /* Read DMA Upper Address */
    7654 +#define PCIE_TLP_RDDMALOWER            0x020 /* Read DMA Lower Address */
    7655 +#define PCIE_TLP_RDDMALENREG           0x024 /* Read DMA Len Req */
    7656 +#define PCIE_TLP_MSIDMAUPPER           0x028 /* MSI DMA Upper Address */
    7657 +#define PCIE_TLP_MSIDMALOWER           0x02C /* MSI DMA Lower Address */
    7658 +#define PCIE_TLP_MSIDMALENREG          0x030 /* MSI DMA Len Req */
    7659 +#define PCIE_TLP_SLVREQLENREG          0x034 /* Slave Request Len */
    7660 +#define PCIE_TLP_FCINPUTSREQ           0x038 /* Flow Control Inputs */
    7661 +#define PCIE_TLP_TXSMGRSREQ            0x03C /* Tx StateMachine and Gated Req */
    7662 +#define PCIE_TLP_ADRACKCNTARBLEN       0x040 /* Address Ack XferCnt and ARB Len */
    7663 +#define PCIE_TLP_DMACPLHDR0            0x044 /* DMA Completion Hdr 0 */
    7664 +#define PCIE_TLP_DMACPLHDR1            0x048 /* DMA Completion Hdr 1 */
    7665 +#define PCIE_TLP_DMACPLHDR2            0x04C /* DMA Completion Hdr 2 */
    7666 +#define PCIE_TLP_DMACPLMISC0           0x050 /* DMA Completion Misc0 */
    7667 +#define PCIE_TLP_DMACPLMISC1           0x054 /* DMA Completion Misc1 */
    7668 +#define PCIE_TLP_DMACPLMISC2           0x058 /* DMA Completion Misc2 */
    7669 +#define PCIE_TLP_SPTCTRLLEN            0x05C /* Split Controller Req len */
    7670 +#define PCIE_TLP_SPTCTRLMSIC0          0x060 /* Split Controller Misc 0 */
    7671 +#define PCIE_TLP_SPTCTRLMSIC1          0x064 /* Split Controller Misc 1 */
    7672 +#define PCIE_TLP_BUSDEVFUNC            0x068 /* Bus/Device/Func */
    7673 +#define PCIE_TLP_RESETCTR              0x06C /* Reset Counter */
    7674 +#define PCIE_TLP_RTRYBUF               0x070 /* Retry Buffer value */
    7675 +#define PCIE_TLP_TGTDEBUG1             0x074 /* Target Debug Reg1 */
    7676 +#define PCIE_TLP_TGTDEBUG2             0x078 /* Target Debug Reg2 */
    7677 +#define PCIE_TLP_TGTDEBUG3             0x07C /* Target Debug Reg3 */
    7678 +#define PCIE_TLP_TGTDEBUG4             0x080 /* Target Debug Reg4 */
    7679 +
    7680 +/* MDIO control */
    7681 +#define MDIOCTL_DIVISOR_MASK           0x7f    /* clock to be used on MDIO */
    7682 +#define MDIOCTL_DIVISOR_VAL            0x2
    7683 +#define MDIOCTL_PREAM_EN               0x80    /* Enable preamble sequnce */
    7684 +#define MDIOCTL_ACCESS_DONE            0x100   /* Tranaction complete */
    7685 +
    7686 +/* MDIO Data */
    7687 +#define MDIODATA_MASK                  0x0000ffff      /* data 2 bytes */
    7688 +#define MDIODATA_TA                    0x00020000      /* Turnaround */
    7689 +#define MDIODATA_REGADDR_SHF           18              /* Regaddr shift */
    7690 +#define MDIODATA_REGADDR_MASK          0x003c0000      /* Regaddr Mask */
    7691 +#define MDIODATA_DEVADDR_SHF           22              /* Physmedia devaddr shift */
    7692 +#define MDIODATA_DEVADDR_MASK          0x0fc00000      /* Physmedia devaddr Mask */
    7693 +#define MDIODATA_WRITE                 0x10000000      /* write Transaction */
    7694 +#define MDIODATA_READ                  0x20000000      /* Read Transaction */
    7695 +#define MDIODATA_START                 0x40000000      /* start of Transaction */
    7696 +
    7697 +/* MDIO devices (SERDES modules) */
    7698 +#define MDIODATA_DEV_PLL                       0x1d    /* SERDES PLL Dev */
    7699 +#define MDIODATA_DEV_TX                        0x1e    /* SERDES TX Dev */
    7700 +#define MDIODATA_DEV_RX                        0x1f    /* SERDES RX Dev */
    7701 +
    7702 +/* SERDES registers */
    7703 +#define SERDES_RX_TIMER1               2       /* Rx Timer1 */
    7704 +#define SERDES_RX_CDR                  6       /* CDR */
    7705 +#define SERDES_RX_CDRBW                        7       /* CDR BW */
    7706 +
    7707 +#endif /* _SBPCIE_H */
    7708 diff -urN linux.old/arch/mips/bcm947xx/include/sbpcmcia.h linux.dev/arch/mips/bcm947xx/include/sbpcmcia.h
    7709 --- linux.old/arch/mips/bcm947xx/include/sbpcmcia.h     1970-01-01 01:00:00.000000000 +0100
    7710 +++ linux.dev/arch/mips/bcm947xx/include/sbpcmcia.h     2006-04-27 20:29:47.000000000 +0200
    7711 @@ -0,0 +1,147 @@
     4599+/* PCI side: Reserved PCI configuration registers (see pcicfg.h) */
     4600+#define cap_list       rsvd_a[0]
     4601+#define bar0_window    dev_dep[0x80 - 0x40]
     4602+#define bar1_window    dev_dep[0x84 - 0x40]
     4603+#define sprom_control  dev_dep[0x88 - 0x40]
     4604+
     4605+#ifndef _LANGUAGE_ASSEMBLY
     4606+
     4607+extern int sbpci_read_config(void *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len);
     4608+extern int sbpci_write_config(void *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len);
     4609+extern void sbpci_ban(uint16 core);
     4610+extern int sbpci_init(void *sbh);
     4611+extern void sbpci_check(void *sbh);
     4612+
     4613+#endif /* !_LANGUAGE_ASSEMBLY */
     4614+
     4615+#endif /* _SBPCI_H */
     4616diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbpcmcia.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbpcmcia.h
     4617--- linux-2.4.32/arch/mips/bcm947xx/include/sbpcmcia.h  1970-01-01 01:00:00.000000000 +0100
     4618+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbpcmcia.h  2006-07-02 21:58:25.000000000 +0200
     4619@@ -0,0 +1,139 @@
    77124620+/*
    77134621+ * BCM43XX Sonics SiliconBackplane PCMCIA core hardware definitions.
    77144622+ *
    7715 + * Copyright 2006, Broadcom Corporation
    7716 + * All Rights Reserved.
    7717 + *
    7718 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    7719 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    7720 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    7721 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    7722 + *
    7723 + * $Id: sbpcmcia.h,v 1.1.1.9 2006/02/27 03:43:16 honor Exp $
     4623+ * $Id$
     4624+ * Copyright 2005, Broadcom Corporation     
     4625+ * All Rights Reserved.     
     4626+ *       
     4627+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     4628+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     4629+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     4630+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
    77244631+ */
    77254632+
     
    78294736+/* Subtypes of BRCM_HNBU: */
    78304737+
    7831 +#define HNBU_SROMREV           0x00            /* A byte with sromrev, 1 if not present */
    7832 +#define HNBU_CHIPID            0x01            /* Two 16bit values: PCI vendor & device id */
    7833 +#define HNBU_BOARDREV          0x02            /* One byte board revision */
    7834 +#define HNBU_PAPARMS           0x03            /* PA parameters: 8 (sromrev == 1)
    7835 +                                                * or 9 (sromrev > 1) bytes
     4738+#define        HNBU_CHIPID             0x01            /* Six bytes with PCI vendor &
     4739+                                                * device id and chiprev
    78364740+                                                */
    7837 +#define HNBU_OEM               0x04            /* Eight bytes OEM data (sromrev == 1) */
    7838 +#define HNBU_CC                        0x05            /* Default country code (sromrev == 1) */
     4741+#define        HNBU_BOARDREV           0x02            /* Two bytes board revision */
     4742+#define        HNBU_PAPARMS            0x03            /* Eleven bytes PA parameters */
     4743+#define        HNBU_OEM                0x04            /* Eight bytes OEM data */
     4744+#define        HNBU_CC                 0x05            /* Default country code */
    78394745+#define        HNBU_AA                 0x06            /* Antennas available */
    78404746+#define        HNBU_AG                 0x07            /* Antenna gain */
    7841 +#define HNBU_BOARDFLAGS                0x08            /* board flags (2 or 4 bytes) */
    7842 +#define HNBU_LEDS              0x09            /* LED set */
    7843 +#define HNBU_CCODE             0x0a            /* Country code (2 bytes ascii + 1 byte cctl)
    7844 +                                                * in rev 2
    7845 +                                                */
    7846 +#define HNBU_CCKPO             0x0b            /* 2 byte cck power offsets in rev 3 */
    7847 +#define HNBU_OFDMPO            0x0c            /* 4 byte 11g ofdm power offsets in rev 3 */
    7848 +#define HNBU_GPIOTIMER         0x0d            /* 2 bytes with on/off values in rev 3 */
     4747+#define HNBU_BOARDFLAGS                0x08            /* board flags */
     4748+#define HNBU_LED               0x09            /* LED set */
    78494749+
    78504750+
     
    78574757+
    78584758+#endif /* _SBPCMCIA_H */
    7859 diff -urN linux.old/arch/mips/bcm947xx/include/sbsdram.h linux.dev/arch/mips/bcm947xx/include/sbsdram.h
    7860 --- linux.old/arch/mips/bcm947xx/include/sbsdram.h      1970-01-01 01:00:00.000000000 +0100
    7861 +++ linux.dev/arch/mips/bcm947xx/include/sbsdram.h      2006-04-27 20:36:08.000000000 +0200
    7862 @@ -0,0 +1,85 @@
     4759diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbsdram.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbsdram.h
     4760--- linux-2.4.32/arch/mips/bcm947xx/include/sbsdram.h   1970-01-01 01:00:00.000000000 +0100
     4761+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbsdram.h   2006-07-02 21:58:25.000000000 +0200
     4762@@ -0,0 +1,75 @@
    78634763+/*
    78644764+ * BCM47XX Sonics SiliconBackplane SDRAM controller core hardware definitions.
    78654765+ *
    7866 + * Copyright 2006, Broadcom Corporation
    7867 + * All Rights Reserved.
    7868 + *
    7869 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    7870 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    7871 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    7872 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    7873 + *
    7874 + * $Id: sbsdram.h,v 1.1.1.9 2006/03/02 13:03:52 honor Exp $
     4766+ * Copyright 2005, Broadcom Corporation     
     4767+ * All Rights Reserved.     
     4768+ *       
     4769+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     4770+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     4771+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     4772+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     4773+ * $Id$
    78754774+ */
    78764775+
     
    78894788+} sbsdramregs_t;
    78904789+
    7891 +/* SDRAM simulation */
    7892 +#ifdef RAMSZ
    7893 +#define        SDRAMSZ         RAMSZ
    7894 +#else
    7895 +#define SDRAMSZ                (4 * 1024 * 1024)
    78964790+#endif
    7897 +
    7898 +extern uchar sdrambuf[SDRAMSZ];
    7899 +
    7900 +#endif /* _LANGUAGE_ASSEMBLY */
    79014791+
    79024792+/* SDRAM initialization control (initcontrol) register bits */
     
    79464836+
    79474837+#endif /* _SBSDRAM_H */
    7948 diff -urN linux.old/arch/mips/bcm947xx/include/sbsocram.h linux.dev/arch/mips/bcm947xx/include/sbsocram.h
    7949 --- linux.old/arch/mips/bcm947xx/include/sbsocram.h     1970-01-01 01:00:00.000000000 +0100
    7950 +++ linux.dev/arch/mips/bcm947xx/include/sbsocram.h     2006-04-27 22:13:19.000000000 +0200
    7951 @@ -0,0 +1,64 @@
     4838diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbsocram.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbsocram.h
     4839--- linux-2.4.32/arch/mips/bcm947xx/include/sbsocram.h  1970-01-01 01:00:00.000000000 +0100
     4840+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbsocram.h  2006-07-02 21:58:25.000000000 +0200
     4841@@ -0,0 +1,37 @@
    79524842+/*
    79534843+ * BCM47XX Sonics SiliconBackplane embedded ram core
    79544844+ *
    7955 + * Copyright 2006, Broadcom Corporation
     4845+ * Copyright 2005, Broadcom Corporation     
     4846+ * All Rights Reserved.     
     4847+ *       
     4848+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     4849+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     4850+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     4851+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     4852+ *
     4853+ * $Id$
     4854+ */
     4855+
     4856+#ifndef        _SBSOCRAM_H
     4857+#define        _SBSOCRAM_H
     4858+
     4859+#define        SOCRAM_MEMSIZE          0x00
     4860+#define        SOCRAM_BISTSTAT         0x0c
     4861+
     4862+
     4863+#ifndef _LANGUAGE_ASSEMBLY
     4864+
     4865+/* Memcsocram core registers */
     4866+typedef volatile struct sbsocramregs {
     4867+       uint32  memsize;
     4868+       uint32  biststat;
     4869+} sbsocramregs_t;
     4870+
     4871+#endif
     4872+
     4873+/* Them memory size is 2 to the power of the following
     4874+ * base added to the contents of the memsize register.
     4875+ */
     4876+#define SOCRAM_MEMSIZE_BASESHIFT 16
     4877+
     4878+#endif /* _SBSOCRAM_H */
     4879diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sbutils.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbutils.h
     4880--- linux-2.4.32/arch/mips/bcm947xx/include/sbutils.h   1970-01-01 01:00:00.000000000 +0100
     4881+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sbutils.h   2006-07-04 09:37:18.000000000 +0200
     4882@@ -0,0 +1,91 @@
     4883+/*
     4884+ * Misc utility routines for accessing chip-specific features
     4885+ * of Broadcom HNBU SiliconBackplane-based chips.
     4886+ *
     4887+ * Copyright 2005, Broadcom Corporation
    79564888+ * All Rights Reserved.
    79574889+ *
     
    79614893+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    79624894+ *
    7963 + * $Id: sbsocram.h,v 1.1.1.3 2006/02/27 03:43:16 honor Exp $
    7964 + */
    7965 +
    7966 +#ifndef        _SBSOCRAM_H
    7967 +#define        _SBSOCRAM_H
    7968 +
    7969 +#define        SR_COREINFO             0x00
    7970 +#define        SR_BWALLOC              0x04
    7971 +#define        SR_BISTSTAT             0x0c
    7972 +#define        SR_BANKINDEX            0x10
    7973 +#define        SR_BANKSTBYCTL          0x14
    7974 +
    7975 +
    7976 +#ifndef _LANGUAGE_ASSEMBLY
    7977 +
    7978 +/* Memcsocram core registers */
    7979 +typedef volatile struct sbsocramregs {
    7980 +       uint32  coreinfo;
    7981 +       uint32  bwalloc;
    7982 +       uint32  PAD;
    7983 +       uint32  biststat;
    7984 +       uint32  bankidx;
    7985 +       uint32  standbyctrl;
    7986 +} sbsocramregs_t;
    7987 +
    7988 +#endif
    7989 +
    7990 +/* Coreinfo register */
    7991 +#define        SRCI_PT_MASK            0x30000
    7992 +#define        SRCI_PT_SHIFT           16
    7993 +
    7994 +/* In corerev 0, the memory size is 2 to the power of the
    7995 + * base plus 16 plus to the contents of the memsize field plus 1.
    7996 + */
    7997 +#define        SRCI_MS0_MASK           0xf
    7998 +#define SR_MS0_BASE            16
    7999 +
    8000 +/*
    8001 + * In corerev 1 the bank size is 2 ^ the bank size field plus 14,
    8002 + * the memory size is number of banks times bank size.
    8003 + * The same applies to rom size.
    8004 + */
    8005 +#define        SRCI_ROMNB_MASK         0xf000
    8006 +#define        SRCI_ROMNB_SHIFT        12
    8007 +#define        SRCI_ROMBSZ_MASK        0xf00
    8008 +#define        SRCI_ROMBSZ_SHIFT       8
    8009 +#define        SRCI_SRNB_MASK          0xf0
    8010 +#define        SRCI_SRNB_SHIFT         4
    8011 +#define        SRCI_SRBSZ_MASK         0xf
    8012 +#define        SRCI_SRBSZ_SHIFT        0
    8013 +
    8014 +#define SR_BSZ_BASE            14
    8015 +#endif /* _SBSOCRAM_H */
    8016 diff -urN linux.old/arch/mips/bcm947xx/include/sbutils.h linux.dev/arch/mips/bcm947xx/include/sbutils.h
    8017 --- linux.old/arch/mips/bcm947xx/include/sbutils.h      1970-01-01 01:00:00.000000000 +0100
    8018 +++ linux.dev/arch/mips/bcm947xx/include/sbutils.h      2006-04-27 23:09:25.000000000 +0200
    8019 @@ -0,0 +1,150 @@
    8020 +/*
    8021 + * Misc utility routines for accessing chip-specific features
    8022 + * of Broadcom HNBU SiliconBackplane-based chips.
    8023 + *
    8024 + * Copyright 2006, Broadcom Corporation
    8025 + * All Rights Reserved.
    8026 + *
    8027 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    8028 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    8029 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    8030 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    8031 + *
    8032 + * $Id: sbutils.h,v 1.4 2006/04/08 07:12:42 honor Exp $
     4895+ * $Id$
    80334896+ */
    80344897+
    80354898+#ifndef        _sbutils_h_
    80364899+#define        _sbutils_h_
    8037 +
    8038 +/*
    8039 + * Datastructure to export all chip specific common variables
    8040 + * public (read-only) portion of sbutils handle returned by
    8041 + * sb_attach()/sb_kattach()
    8042 +*/
    8043 +
    8044 +struct sb_pub {
    8045 +
    8046 +       uint    bustype;                /* SB_BUS, PCI_BUS  */
    8047 +       uint    buscoretype;            /* SB_PCI, SB_PCMCIA, SB_PCIE */
    8048 +       uint    buscorerev;             /* buscore rev */
    8049 +       uint    buscoreidx;             /* buscore index */
    8050 +       int     ccrev;                  /* chip common core rev */
    8051 +       uint    boardtype;              /* board type */
    8052 +       uint    boardvendor;            /* board vendor */
    8053 +       uint    chip;                   /* chip number */
    8054 +       uint    chiprev;                /* chip revision */
    8055 +       uint    chippkg;                /* chip package option */
    8056 +       uint    sonicsrev;              /* sonics backplane rev */
    8057 +};
    8058 +
    8059 +typedef const struct sb_pub  sb_t;
    80604900+
    80614901+/*
     
    80674907+ */
    80684908+
    8069 +#define        SB_OSH          NULL    /* Use for sb_kattach when no osh is available */
    80704909+/* exported externs */
    8071 +extern sb_t *sb_attach(uint pcidev, osl_t *osh, void *regs, uint bustype,
    8072 +                       void *sdh, char **vars, uint *varsz);
    8073 +extern sb_t *sb_kattach(void);
    8074 +extern void sb_detach(sb_t *sbh);
    8075 +extern uint sb_chip(sb_t *sbh);
    8076 +extern uint sb_chiprev(sb_t *sbh);
    8077 +extern uint sb_chipcrev(sb_t *sbh);
    8078 +extern uint sb_chippkg(sb_t *sbh);
    8079 +extern uint sb_pcirev(sb_t *sbh);
    8080 +extern bool sb_war16165(sb_t *sbh);
    8081 +extern uint sb_pcmciarev(sb_t *sbh);
    8082 +extern uint sb_boardvendor(sb_t *sbh);
    8083 +extern uint sb_boardtype(sb_t *sbh);
    8084 +extern uint sb_bus(sb_t *sbh);
    8085 +extern uint sb_buscoretype(sb_t *sbh);
    8086 +extern uint sb_buscorerev(sb_t *sbh);
    8087 +extern uint sb_corelist(sb_t *sbh, uint coreid[]);
    8088 +extern uint sb_coreid(sb_t *sbh);
    8089 +extern uint sb_coreidx(sb_t *sbh);
    8090 +extern uint sb_coreunit(sb_t *sbh);
    8091 +extern uint sb_corevendor(sb_t *sbh);
    8092 +extern uint sb_corerev(sb_t *sbh);
    8093 +extern void *sb_osh(sb_t *sbh);
    8094 +extern void sb_setosh(sb_t *sbh, osl_t *osh);
    8095 +extern void *sb_coreregs(sb_t *sbh);
    8096 +extern uint32 sb_coreflags(sb_t *sbh, uint32 mask, uint32 val);
    8097 +extern uint32 sb_coreflagshi(sb_t *sbh, uint32 mask, uint32 val);
    8098 +extern bool sb_iscoreup(sb_t *sbh);
    8099 +extern void *sb_setcoreidx(sb_t *sbh, uint coreidx);
    8100 +extern void *sb_setcore(sb_t *sbh, uint coreid, uint coreunit);
    8101 +extern int sb_corebist(sb_t *sbh);
    8102 +extern void sb_commit(sb_t *sbh);
     4910+extern void * BCMINIT(sb_attach)(uint pcidev, void *osh, void *regs, uint bustype, void *sdh, char **vars, int *varsz);
     4911+extern void * BCMINIT(sb_kattach)(void);
     4912+extern void sb_detach(void *sbh);
     4913+extern uint BCMINIT(sb_chip)(void *sbh);
     4914+extern uint BCMINIT(sb_chiprev)(void *sbh);
     4915+extern uint BCMINIT(sb_chipcrev)(void *sbh);
     4916+extern uint BCMINIT(sb_chippkg)(void *sbh);
     4917+extern uint BCMINIT(sb_pcirev)(void *sbh);
     4918+extern uint BCMINIT(sb_pcmciarev)(void *sbh);
     4919+extern uint BCMINIT(sb_boardvendor)(void *sbh);
     4920+extern uint BCMINIT(sb_boardtype)(void *sbh);
     4921+extern uint sb_bus(void *sbh);
     4922+extern uint sb_corelist(void *sbh, uint coreid[]);
     4923+extern uint sb_coreid(void *sbh);
     4924+extern uint sb_coreidx(void *sbh);
     4925+extern uint sb_coreunit(void *sbh);
     4926+extern uint sb_corevendor(void *sbh);
     4927+extern uint sb_corerev(void *sbh);
     4928+extern void *sb_osh(void *sbh);
     4929+extern void *sb_coreregs(void *sbh);
     4930+extern uint32 sb_coreflags(void *sbh, uint32 mask, uint32 val);
     4931+extern uint32 sb_coreflagshi(void *sbh, uint32 mask, uint32 val);
     4932+extern bool sb_iscoreup(void *sbh);
     4933+extern void *sb_setcoreidx(void *sbh, uint coreidx);
     4934+extern void *sb_setcore(void *sbh, uint coreid, uint coreunit);
     4935+extern void sb_commit(void *sbh);
    81034936+extern uint32 sb_base(uint32 admatch);
    81044937+extern uint32 sb_size(uint32 admatch);
    8105 +extern void sb_core_reset(sb_t *sbh, uint32 bits, uint32 resetbits);
    8106 +extern void sb_core_tofixup(sb_t *sbh);
    8107 +extern void sb_core_disable(sb_t *sbh, uint32 bits);
     4938+extern void sb_core_reset(void *sbh, uint32 bits);
     4939+extern void sb_core_tofixup(void *sbh);
     4940+extern void sb_core_disable(void *sbh, uint32 bits);
    81084941+extern uint32 sb_clock_rate(uint32 pll_type, uint32 n, uint32 m);
    8109 +extern uint32 sb_clock(sb_t *sbh);
    8110 +extern void sb_pci_setup(sb_t *sbh, uint coremask);
    8111 +extern void sb_pcmcia_init(sb_t *sbh);
    8112 +extern void sb_watchdog(sb_t *sbh, uint ticks);
    8113 +extern void *sb_gpiosetcore(sb_t *sbh);
    8114 +extern uint32 sb_gpiocontrol(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
    8115 +extern uint32 sb_gpioouten(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
    8116 +extern uint32 sb_gpioout(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
    8117 +extern uint32 sb_gpioin(sb_t *sbh);
    8118 +extern uint32 sb_gpiointpolarity(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
    8119 +extern uint32 sb_gpiointmask(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
    8120 +extern uint32 sb_gpioled(sb_t *sbh, uint32 mask, uint32 val);
    8121 +extern uint32 sb_gpioreserve(sb_t *sbh, uint32 gpio_num, uint8 priority);
    8122 +extern uint32 sb_gpiorelease(sb_t *sbh, uint32 gpio_num, uint8 priority);
    8123 +
    8124 +extern void sb_clkctl_init(sb_t *sbh);
    8125 +extern uint16 sb_clkctl_fast_pwrup_delay(sb_t *sbh);
    8126 +extern bool sb_clkctl_clk(sb_t *sbh, uint mode);
    8127 +extern int sb_clkctl_xtal(sb_t *sbh, uint what, bool on);
    8128 +extern void sb_register_intr_callback(sb_t *sbh, void *intrsoff_fn, void *intrsrestore_fn,
    8129 +                                      void *intrsenabled_fn, void *intr_arg);
    8130 +extern uint32 sb_set_initiator_to(sb_t *sbh, uint32 to);
    8131 +extern int sb_corepciid(sb_t *sbh, uint func, uint16 *pcivendor, uint16 *pcidevice,
    8132 +                        uint8 *pciclass, uint8 *pcisubclass, uint8 *pciprogif,
    8133 +                        uint8 *pciheader);
    8134 +extern uint sb_pcie_readreg(void *sbh, void* arg1, uint offset);
    8135 +extern uint sb_pcie_writereg(sb_t *sbh, void *arg1,  uint offset, uint val);
    8136 +extern uint32 sb_gpiotimerval(sb_t *sbh, uint32 mask, uint32 val);
    8137 +extern bool sb_backplane64(sb_t *sbh);
    8138 +extern void sb_btcgpiowar(sb_t *sbh);
    8139 +
    8140 +
    8141 +
    8142 +
    8143 +extern bool sb_deviceremoved(sb_t *sbh);
    8144 +extern uint32 sb_socram_size(sb_t *sbh);
    8145 +
    8146 +/*
    8147 +* Build device path. Path size must be >= SB_DEVPATH_BUFSZ.
    8148 +* The returned path is NULL terminated and has trailing '/'.
    8149 +* Return 0 on success, nonzero otherwise.
    8150 +*/
    8151 +extern int sb_devpath(sb_t *sbh, char *path, int size);
    8152 +
    8153 +/* clkctl xtal what flags */
    8154 +#define        XTAL                    0x1             /* primary crystal oscillator (2050) */
    8155 +#define        PLL                     0x2             /* main chip pll */
    8156 +
    8157 +/* clkctl clk mode */
    8158 +#define        CLK_FAST                0               /* force fast (pll) clock */
    8159 +#define        CLK_DYNAMIC             2               /* enable dynamic clock control */
    8160 +
     4942+extern uint32 sb_clock(void *sbh);
     4943+extern void sb_pci_setup(void *sbh, uint32 *dmaoffset, uint coremask);
     4944+extern void sb_pcmcia_init(void *sbh);
     4945+extern void sb_watchdog(void *sbh, uint ticks);
     4946+extern void *sb_gpiosetcore(void *sbh);
     4947+extern uint32 sb_gpiocontrol(void *sbh, uint32 mask, uint32 val);
     4948+extern uint32 sb_gpioouten(void *sbh, uint32 mask, uint32 val);
     4949+extern uint32 sb_gpioout(void *sbh, uint32 mask, uint32 val);
     4950+extern uint32 sb_gpioin(void *sbh);
     4951+extern uint32 sb_gpiointpolarity(void *sbh, uint32 mask, uint32 val);
     4952+extern uint32 sb_gpiointmask(void *sbh, uint32 mask, uint32 val);
     4953+extern void sb_pwrctl_init(void *sbh);
     4954+extern uint16 sb_pwrctl_fast_pwrup_delay(void *sbh);
     4955+extern bool sb_pwrctl_clk(void *sbh, uint mode);
     4956+extern int sb_pwrctl_xtal(void *sbh, uint what, bool on);
     4957+extern int sb_pwrctl_slowclk(void *sbh, bool set, uint *div);
     4958+extern void sb_register_intr_callback(void *sbh, void *intrsoff_fn, void *intrsrestore_fn, void *intrsenabled_fn, void *intr_arg);
     4959+
     4960+/* pwrctl xtal what flags */
     4961+#define        XTAL            0x1                     /* primary crystal oscillator (2050) */
     4962+#define        PLL             0x2                     /* main chip pll */
     4963+
     4964+/* pwrctl clk mode */
     4965+#define        CLK_FAST        0                       /* force fast (pll) clock */
     4966+#define        CLK_SLOW        1                       /* force slow clock */
     4967+#define        CLK_DYNAMIC     2                       /* enable dynamic power control */
    81614968+
    81624969+/* GPIO usage priorities */
    8163 +#define GPIO_DRV_PRIORITY      0               /* Driver */
    8164 +#define GPIO_APP_PRIORITY      1               /* Application */
    8165 +
    8166 +/* device path */
    8167 +#define SB_DEVPATH_BUFSZ       16              /* min buffer size in bytes */
     4970+#define GPIO_DRV_PRIORITY      0               /* Driver */
     4971+#define GPIO_APP_PRIORITY      1               /* Application */
    81684972+
    81694973+#endif /* _sbutils_h_ */
    8170 diff -urN linux.old/arch/mips/bcm947xx/include/sflash.h linux.dev/arch/mips/bcm947xx/include/sflash.h
    8171 --- linux.old/arch/mips/bcm947xx/include/sflash.h       1970-01-01 01:00:00.000000000 +0100
    8172 +++ linux.dev/arch/mips/bcm947xx/include/sflash.h       2006-04-27 22:13:51.000000000 +0200
     4974diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/sflash.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sflash.h
     4975--- linux-2.4.32/arch/mips/bcm947xx/include/sflash.h    1970-01-01 01:00:00.000000000 +0100
     4976+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/sflash.h    2006-07-02 21:58:25.000000000 +0200
    81734977@@ -0,0 +1,36 @@
    81744978+/*
    81754979+ * Broadcom SiliconBackplane chipcommon serial flash interface
    81764980+ *
    8177 + * Copyright 2006, Broadcom Corporation
    8178 + * All Rights Reserved.
    8179 + *
    8180 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    8181 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    8182 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    8183 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
     4981+ * Copyright 2005, Broadcom Corporation     
     4982+ * All Rights Reserved.     
     4983+ *      
     4984+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     4985+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     4986+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     4987+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
    81844988+ *
    8185 + * $Id: sflash.h,v 1.1.1.8 2006/02/27 03:43:16 honor Exp $
     4989+ * $Id$
    81864990+ */
    81874991+
     
    82085012+
    82095013+#endif /* _sflash_h_ */
    8210 diff -urN linux.old/arch/mips/bcm947xx/include/trxhdr.h linux.dev/arch/mips/bcm947xx/include/trxhdr.h
    8211 --- linux.old/arch/mips/bcm947xx/include/trxhdr.h       1970-01-01 01:00:00.000000000 +0100
    8212 +++ linux.dev/arch/mips/bcm947xx/include/trxhdr.h       2006-04-27 19:24:19.000000000 +0200
     5014diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/trxhdr.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/trxhdr.h
     5015--- linux-2.4.32/arch/mips/bcm947xx/include/trxhdr.h    1970-01-01 01:00:00.000000000 +0100
     5016+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/trxhdr.h    2006-07-02 21:58:25.000000000 +0200
    82135017@@ -0,0 +1,33 @@
    82145018+/*
     
    82455049+/* Compatibility */
    82465050+typedef struct trx_header TRXHDR, *PTRXHDR;
    8247 diff -urN linux.old/arch/mips/bcm947xx/include/typedefs.h linux.dev/arch/mips/bcm947xx/include/typedefs.h
    8248 --- linux.old/arch/mips/bcm947xx/include/typedefs.h     1970-01-01 01:00:00.000000000 +0100
    8249 +++ linux.dev/arch/mips/bcm947xx/include/typedefs.h     2006-04-27 23:47:30.000000000 +0200
    8250 @@ -0,0 +1,361 @@
     5051diff -Nur linux-2.4.32/arch/mips/bcm947xx/include/typedefs.h linux-2.4.32-freewrt/arch/mips/bcm947xx/include/typedefs.h
     5052--- linux-2.4.32/arch/mips/bcm947xx/include/typedefs.h  1970-01-01 01:00:00.000000000 +0100
     5053+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/include/typedefs.h  2006-07-02 21:58:25.000000000 +0200
     5054@@ -0,0 +1,322 @@
    82515055+/*
    8252 + * Copyright 2006, Broadcom Corporation
    8253 + * All Rights Reserved.
    8254 + *
    8255 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    8256 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    8257 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    8258 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    8259 + * $Id: typedefs.h,v 1.1.1.12 2006/04/08 06:13:40 honor Exp $
     5056+ * Copyright 2005, Broadcom Corporation     
     5057+ * All Rights Reserved.     
     5058+ *      
     5059+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     5060+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     5061+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     5062+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     5063+ * $Id$
    82605064+ */
    82615065+
     
    82795083+#ifdef SITE_TYPEDEFS
    82805084+
    8281 +/*
     5085+/*******************************************************************************
    82825086+ * Site Specific Typedefs
    8283 + *
    8284 + */
     5087+ *******************************************************************************/
    82855088+
    82865089+#include "site_typedefs.h"
     
    82885091+#else
    82895092+
    8290 +/*
     5093+/*******************************************************************************
    82915094+ * Inferred Typedefs
    8292 + *
    8293 + */
     5095+ *******************************************************************************/
    82945096+
    82955097+/* Infer the compile environment based on preprocessor symbols and pramas.
     
    83265128+#endif
    83275129+
    8328 +
    8329 +#if defined(_MINOSL_)
    8330 +#define _NEED_SIZE_T_
    8331 +#endif
    8332 +
    8333 +#if defined(_NEED_SIZE_T_)
    8334 +typedef long unsigned int size_t;
    8335 +#endif
    8336 +
    8337 +#ifdef __DJGPP__
    8338 +typedef long unsigned int size_t;
    8339 +#endif /* __DJGPP__ */
    8340 +
    83415130+#ifdef _MSC_VER            /* Microsoft C */
    83425131+#define TYPEDEF_INT64
     
    83465135+#endif
    83475136+
    8348 +#if defined(MACOSX)
     5137+#if defined(MACOSX) && defined(KERNEL)
    83495138+#define TYPEDEF_BOOL
    8350 +#endif
    8351 +
    8352 +#if defined(__NetBSD__)
    8353 +#define TYPEDEF_ULONG
    83545139+#endif
    83555140+
     
    83615146+#endif
    83625147+
    8363 +#if !defined(linux) && !defined(_WIN32) && !defined(_CFE_) && \
    8364 +       !defined(_HNDRTE_) && !defined(_MINOSL_) && !defined(__DJGPP__)
     5148+#if !defined(linux) && !defined(_WIN32) && !defined(PMON) && !defined(_CFE_) && !defined(_HNDRTE_) && !defined(_MINOSL_)
    83655149+#define TYPEDEF_UINT
    83665150+#define TYPEDEF_USHORT
     
    83755159+
    83765160+/* ICL accepts unsigned 64 bit type only, and complains in ANSI mode
    8377 + * for singned or unsigned
    8378 + */
     5161+ * for singned or unsigned */
    83795162+#if defined(__ICL)
    83805163+
     
    83875170+#endif /* __ICL */
    83885171+
    8389 +#if !defined(_WIN32) && !defined(_CFE_) && !defined(_MINOSL_) && \
    8390 +       !defined(__DJGPP__)
     5172+
     5173+#if !defined(_WIN32) && !defined(PMON) && !defined(_CFE_) && !defined(_HNDRTE_) && !defined(_MINOSL_)
    83915174+
    83925175+/* pick up ushort & uint from standard types.h */
     
    83975180+#else
    83985181+
    8399 +#include <sys/types.h>
     5182+#include <sys/types.h> 
    84005183+
    84015184+#endif
    84025185+
    8403 +#endif /* !_WIN32 && !PMON && !_CFE_ && !_HNDRTE_  && !_MINOSL_ && !__DJGPP__ */
    8404 +
    8405 +#if defined(MACOSX)
    8406 +
    8407 +#ifdef __BIG_ENDIAN__
    8408 +#define IL_BIGENDIAN
    8409 +#else
    8410 +#ifdef IL_BIGENDIAN
    8411 +#error "IL_BIGENDIAN was defined for a little-endian compile"
     5186+#endif /* !_WIN32 && !PMON && !_CFE_ && !_HNDRTE_  && !_MINOSL_ */
     5187+
     5188+#if defined(MACOSX) && defined(KERNEL)
     5189+#include <IOKit/IOTypes.h>
    84125190+#endif
    8413 +#endif /* __BIG_ENDIAN__ */
    8414 +
    8415 +#if !defined(__cplusplus)
    8416 +
    8417 +#if defined(__i386__)
    8418 +typedef unsigned char bool;
    8419 +#else
    8420 +typedef unsigned int bool;
    8421 +#endif
    8422 +#define TYPE_BOOL 1
    8423 +enum {
    8424 +    false      = 0,
    8425 +    true       = 1
    8426 +};
    8427 +
    8428 +#if defined(KERNEL)
    8429 +#include <IOKit/IOTypes.h>
    8430 +#endif /* KERNEL */
    8431 +
    8432 +#endif /* __cplusplus */
    8433 +
    8434 +#endif /* MACOSX */
    84355191+
    84365192+
     
    84415197+
    84425198+
    8443 +/*
     5199+/*******************************************************************************
    84445200+ * Default Typedefs
    8445 + *
    8446 + */
     5201+ *******************************************************************************/
    84475202+
    84485203+#ifdef USE_TYPEDEF_DEFAULTS
     
    84505205+
    84515206+#ifndef TYPEDEF_BOOL
    8452 +typedef        /* @abstract@ */ unsigned char  bool;
     5207+typedef        /*@abstract@*/ unsigned char    bool;
    84535208+#endif
    84545209+
    8455 +/* define uchar, ushort, uint, ulong */
     5210+/*----------------------- define uchar, ushort, uint, ulong ------------------*/
    84565211+
    84575212+#ifndef TYPEDEF_UCHAR
     
    84715226+#endif
    84725227+
    8473 +/* define [u]int8/16/32/64, uintptr */
     5228+/*----------------------- define [u]int8/16/32/64, uintptr --------------------*/
    84745229+
    84755230+#ifndef TYPEDEF_UINT8
     
    85095264+#endif
    85105265+
    8511 +/* define float32/64, float_t */
     5266+/*----------------------- define float32/64, float_t -----------------------*/
    85125267+
    85135268+#ifndef TYPEDEF_FLOAT32
     
    85355290+#endif /* TYPEDEF_FLOAT_T */
    85365291+
    8537 +/* define macro values */
     5292+/*----------------------- define macro values -----------------------------*/
    85385293+
    85395294+#ifndef FALSE
     
    85425297+
    85435298+#ifndef TRUE
    8544 +#define TRUE   1  /* TRUE */
     5299+#define TRUE   1
    85455300+#endif
    85465301+
     
    85545309+
    85555310+#ifndef ON
    8556 +#define        ON      1  /* ON = 1 */
     5311+#define        ON      1
    85575312+#endif
    85585313+
    8559 +#define        AUTO    (-1) /* Auto = -1 */
    8560 +
    8561 +/* define PTRSZ, INLINE */
     5314+#define        AUTO    (-1)
     5315+
     5316+/* Reclaiming text and data :
     5317+   The following macros specify special linker sections that can be reclaimed
     5318+   after a system is considered 'up'.
     5319+ */
     5320+#if defined(__GNUC__) && defined(BCMRECLAIM)
     5321+extern bool    bcmreclaimed;
     5322+#define BCMINITDATA(_data)     __attribute__ ((__section__ (".dataini." #_data))) _data##_ini         
     5323+#define BCMINITFN(_fn)         __attribute__ ((__section__ (".textini." #_fn))) _fn##_ini
     5324+#define BCMINIT(_id)           _id##_ini
     5325+#else
     5326+#define BCMINITDATA(_data)     _data           
     5327+#define BCMINITFN(_fn)         _fn
     5328+#define BCMINIT(_id)           _id
     5329+#define bcmreclaimed           0
     5330+#endif
     5331+
     5332+/*----------------------- define PTRSZ, INLINE ----------------------------*/
    85625333+
    85635334+#ifndef PTRSZ
    8564 +#define        PTRSZ   sizeof(char*)
     5335+#define        PTRSZ   sizeof (char*)
    85655336+#endif
    85665337+
     
    86035374+#endif /* USE_TYPEDEF_DEFAULTS */
    86045375+
    8605 +/*
    8606 + * Including the bcmdefs.h here, to make sure everyone including typedefs.h
    8607 + * gets this automatically
    8608 +*/
    8609 +#include "bcmdefs.h"
    8610 +
    86115376+#endif /* _TYPEDEFS_H_ */
    8612 diff -urN linux.old/arch/mips/bcm947xx/nvram.c linux.dev/arch/mips/bcm947xx/nvram.c
    8613 --- linux.old/arch/mips/bcm947xx/nvram.c        1970-01-01 01:00:00.000000000 +0100
    8614 +++ linux.dev/arch/mips/bcm947xx/nvram.c        2006-04-27 23:11:58.000000000 +0200
    8615 @@ -0,0 +1,315 @@
     5377diff -Nur linux-2.4.32/arch/mips/bcm947xx/nvram.c linux-2.4.32-freewrt/arch/mips/bcm947xx/nvram.c
     5378--- linux-2.4.32/arch/mips/bcm947xx/nvram.c     1970-01-01 01:00:00.000000000 +0100
     5379+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/nvram.c     2006-07-02 21:58:25.000000000 +0200
     5380@@ -0,0 +1,321 @@
    86165381+/*
    86175382+ * NVRAM variable manipulation (common)
     
    86255390+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    86265391+ *
     5392+ * $Id$
    86275393+ */
    86285394+
     
    89105676+       struct nvram_header *header;
    89115677+       int ret;
    8912 +
    8913 +       if (!(header = (struct nvram_header *) kmalloc(NVRAM_SPACE, GFP_ATOMIC))) {
     5678+       void *osh;
     5679+
     5680+       /* get kernel osl handler */
     5681+       osh = osl_attach(NULL);
     5682+
     5683+       if (!(header = (struct nvram_header *) MALLOC(osh, NVRAM_SPACE))) {
     5684+               printf("nvram_init: out of memory, malloced %d bytes\n", MALLOCED(osh));
    89145685+               return -12; /* -ENOMEM */
    89155686+       }
     
    89195690+               BCMINIT(nvram_rehash)(header);
    89205691+
    8921 +       kfree(header);
     5692+       MFREE(osh, header, NVRAM_SPACE);
    89225693+       return ret;
    89235694+}
     
    89295700+       BCMINIT(nvram_free)();
    89305701+}
    8931 diff -urN linux.old/arch/mips/bcm947xx/nvram_linux.c linux.dev/arch/mips/bcm947xx/nvram_linux.c
    8932 --- linux.old/arch/mips/bcm947xx/nvram_linux.c  1970-01-01 01:00:00.000000000 +0100
    8933 +++ linux.dev/arch/mips/bcm947xx/nvram_linux.c  2006-04-27 23:30:07.000000000 +0200
    8934 @@ -0,0 +1,723 @@
     5702diff -Nur linux-2.4.32/arch/mips/bcm947xx/nvram_linux.c linux-2.4.32-freewrt/arch/mips/bcm947xx/nvram_linux.c
     5703--- linux-2.4.32/arch/mips/bcm947xx/nvram_linux.c       1970-01-01 01:00:00.000000000 +0100
     5704+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/nvram_linux.c       2006-07-02 21:58:25.000000000 +0200
     5705@@ -0,0 +1,617 @@
    89355706+/*
    89365707+ * NVRAM variable manipulation (Linux kernel half)
    89375708+ *
    8938 + * Copyright 2006, Broadcom Corporation
     5709+ * Copyright 2004, Broadcom Corporation
    89395710+ * All Rights Reserved.
    89405711+ *
     
    89445715+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    89455716+ *
    8946 + * $Id: nvram_linux.c,v 1.19 2006/04/08 07:12:42 honor Exp $
     5717+ * $Id$
    89475718+ */
    89485719+
     
    89655736+
    89665737+#include <typedefs.h>
    8967 +#include <osl.h>
    89685738+#include <bcmendian.h>
    89695739+#include <bcmnvram.h>
     
    89725742+#include <sbchipc.h>
    89735743+#include <sbutils.h>
    8974 +#include <hndmips.h>
    8975 +#include <sflash.h>
     5744+#include <sbmips.h>
    89765745+
    89775746+/* In BSS to minimize text size and page aligned so it can be mmap()-ed */
     
    89875756+extern void *bcm947xx_sbh;
    89885757+extern spinlock_t bcm947xx_sbh_lock;
    8989 +
    8990 +static int cfe_env;
    8991 +extern char *cfe_env_get(char *nv_buf, const char *name);
    89925758+
    89935759+/* Convenience */
     
    90035769+       struct nvram_header *header;
    90045770+       chipcregs_t *cc;
    9005 +       struct sflash *info = NULL;
    90065771+       int i;
    90075772+       uint32 base, off, lim;
    9008 +       u32 *src, *dst;
    90095773+
    90105774+       if ((cc = sb_setcore(sbh, SB_CC, 0)) != NULL) {
     
    90175781+               case SFLASH_ST:
    90185782+               case SFLASH_AT:
    9019 +                       if ((info = sflash_init(cc)) == NULL)
    9020 +                               return;
    9021 +                       lim = info->size;
    9022 +                       break;
    9023 +
    90245783+               case FLASH_NONE:
    90255784+               default:
     
    90325791+       }
    90335792+
    9034 +       /* XXX: hack for supporting the CFE environment stuff on WGT634U */
    9035 +       src = (u32 *) KSEG1ADDR(base + 8 * 1024 * 1024 - 0x2000);
    9036 +       dst = (u32 *) nvram_buf;
    9037 +       if ((lim == 0x02000000) && ((*src & 0xff00ff) == 0x000001)) {
    9038 +               printk("early_nvram_init: WGT634U NVRAM found.\n");
    9039 +
    9040 +               for (i = 0; i < 0x1ff0; i++) {
    9041 +                       if (*src == 0xFFFFFFFF)
    9042 +                               break;
    9043 +                       *dst++ = *src++;
    9044 +               }
    9045 +               cfe_env = 1;
    9046 +               return;
    9047 +       }
    9048 +
    90495793+       off = FLASH_MIN;
    90505794+       while (off <= lim) {
    90515795+               /* Windowed flash access */
    90525796+               header = (struct nvram_header *) KSEG1ADDR(base + off - NVRAM_SPACE);
    9053 +               if (header->magic == NVRAM_MAGIC)
    9054 +                       goto found;
    9055 +               off <<= 1;
    9056 +       }
    9057 +
    9058 +       /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
    9059 +       header = (struct nvram_header *) KSEG1ADDR(base + 4 KB);
    9060 +       if (header->magic == NVRAM_MAGIC)
    9061 +               goto found;
    9062 +       
    9063 +       header = (struct nvram_header *) KSEG1ADDR(base + 1 KB);
    9064 +       if (header->magic == NVRAM_MAGIC)
    9065 +               goto found;
    9066 +       
    9067 +       printk("early_nvram_init: NVRAM not found\n");
    9068 +       return;
    9069 +
    9070 +found:
    9071 +       src = (u32 *) header;
    9072 +       dst = (u32 *) nvram_buf;
    9073 +       for (i = 0; i < sizeof(struct nvram_header); i += 4)
    9074 +               *dst++ = *src++;
    9075 +       for (; i < header->len && i < NVRAM_SPACE; i += 4)
    9076 +               *dst++ = ltoh32(*src++);
     5797+               if (header->magic == NVRAM_MAGIC) {
     5798+                       u32 *src = (u32 *) header;
     5799+                       u32 *dst = (u32 *) nvram_buf;
     5800+                       for (i = 0; i < sizeof(struct nvram_header); i += 4)
     5801+                               *dst++ = *src++;
     5802+                       for (; i < header->len && i < NVRAM_SPACE; i += 4)
     5803+                               *dst++ = ltoh32(*src++);
     5804+                       return;
     5805+               }
     5806+
     5807+               /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
     5808+               if (off == 1 KB)
     5809+                       break;
     5810+               else if (off == 4 KB)
     5811+                       off = 1 KB;
     5812+               else if (off == lim)
     5813+                       off = 4 KB;
     5814+               else
     5815+                       off <<= 1;
     5816+       }
    90775817+}
    90785818+
     
    90865826+               return NULL;
    90875827+
    9088 +       /* Too early? */
    9089 +       if (sbh == NULL)
    9090 +               return NULL;
    9091 +
    90925828+       if (!nvram_buf[0])
    90935829+               early_nvram_init();
    9094 +
    9095 +       if (cfe_env)
    9096 +               return cfe_env_get(nvram_buf, name);
    90975830+
    90985831+       /* Look for name=value and return value */
     
    91115844+}
    91125845+
    9113 +static int __init
    9114 +early_nvram_getall(char *buf, int count)
    9115 +{
    9116 +       char *var, *end;
    9117 +       int len = 0;
    9118 +       
    9119 +       /* Too early? */
    9120 +       if (sbh == NULL)
    9121 +               return -1;
    9122 +
    9123 +       if (!nvram_buf[0])
    9124 +               early_nvram_init();
    9125 +
    9126 +       bzero(buf, count);
    9127 +
    9128 +       /* Write name=value\0 ... \0\0 */
    9129 +       var = &nvram_buf[sizeof(struct nvram_header)];
    9130 +       end = nvram_buf + sizeof(nvram_buf) - 2;
    9131 +       end[0] = end[1] = '\0';
    9132 +       for (; *var; var += strlen(var) + 1) {
    9133 +               if ((count - len) <= (strlen(var) + 1))
    9134 +                       break;
    9135 +               len += sprintf(buf + len, "%s", var) + 1;
    9136 +       }
    9137 +
    9138 +       return 0;
    9139 +}
    91405846+#endif /* !MODULE */
    91415847+
     
    91455851+extern int _nvram_getall(char *buf, int count);
    91465852+extern int _nvram_commit(struct nvram_header *header);
    9147 +extern int _nvram_init(void *sbh);
     5853+extern int _nvram_init(void);
    91485854+extern void _nvram_exit(void);
    91495855+
     
    92765982+{
    92775983+       char *buf;
    9278 +       size_t erasesize, len, magic_len;
     5984+       size_t erasesize, len;
    92795985+       unsigned int i;
    92805986+       int ret;
     
    92855991+       wait_queue_head_t wait_q;
    92865992+       struct erase_info erase;
    9287 +       u_int32_t magic_offset = 0; /* Offset for writing MAGIC # */
    92885993+
    92895994+       if (!nvram_mtd) {
     
    93166021+               }
    93176022+               header = (struct nvram_header *)(buf + i);
    9318 +               magic_offset = i + ((void *)&header->magic - (void *)header);
    93196023+       } else {
    93206024+               offset = nvram_mtd->size - NVRAM_SPACE;
    9321 +               magic_offset = ((void *)&header->magic - (void *)header);
    93226025+               header = (struct nvram_header *)buf;
    93236026+       }
    93246027+
    9325 +       /* clear the existing magic # to mark the NVRAM as unusable
    9326 +                we can pull MAGIC bits low without erase       */
    9327 +       header->magic = NVRAM_CLEAR_MAGIC; /* All zeros magic */
    9328 +
    9329 +       /* Unlock sector blocks (for Intel 28F320C3B flash) , 20060309 */
    9330 +       if(nvram_mtd->unlock)
    9331 +               nvram_mtd->unlock(nvram_mtd, offset, nvram_mtd->erasesize);
    9332 +
    9333 +       ret = MTD_WRITE(nvram_mtd, offset + magic_offset, sizeof(header->magic),
    9334 +                                                                       &magic_len, (char *)&header->magic);
    9335 +       if (ret || magic_len != sizeof(header->magic)) {
    9336 +               printk("nvram_commit: clear MAGIC error\n");
    9337 +               ret = -EIO;
    9338 +               goto done;
    9339 +       }
    9340 +
    9341 +       header->magic = NVRAM_MAGIC; /* reset MAGIC before we regenerate the NVRAM,
    9342 +                                                                                                                               otherwise we'll have an incorrect CRC */
    93436028+       /* Regenerate NVRAM */
    93446029+       spin_lock_irqsave(&nvram_lock, flags);
     
    93776062+
    93786063+       /* Write partition up to end of data area */
    9379 +       header->magic = NVRAM_INVALID_MAGIC; /* All ones magic */
    93806064+       offset = nvram_mtd->size - erasesize;
    93816065+       i = erasesize - NVRAM_SPACE + header->len;
     
    93876071+       }
    93886072+
    9389 +       /* Now mark the NVRAM in flash as "valid" by setting the correct
    9390 +                MAGIC # */
    9391 +       header->magic = NVRAM_MAGIC;
    9392 +       ret = MTD_WRITE(nvram_mtd, offset + magic_offset, sizeof(header->magic),
    9393 +                                                                       &magic_len, (char *)&header->magic);
    9394 +       if (ret || magic_len != sizeof(header->magic)) {
    9395 +               printk("nvram_commit: write MAGIC error\n");
    9396 +               ret = -EIO;
    9397 +               goto done;
    9398 +       }
    9399 +
    9400 +       /*
    9401 +        * Reading a few bytes back here will put the device
    9402 +        * back to the correct mode on certain flashes */
    94036073+       offset = nvram_mtd->size - erasesize;
    94046074+       ret = MTD_READ(nvram_mtd, offset, 4, &len, buf);
     
    94076077+       up(&nvram_sem);
    94086078+       kfree(buf);
    9409 +
    94106079+       return ret;
    94116080+}
     
    94186087+
    94196088+       spin_lock_irqsave(&nvram_lock, flags);
    9420 +       if (nvram_major >= 0)
    9421 +               ret = _nvram_getall(buf, count);
    9422 +       else
    9423 +               ret = early_nvram_getall(buf, count);
     6089+       ret = _nvram_getall(buf, count);
    94246090+       spin_unlock_irqrestore(&nvram_lock, flags);
    94256091+
     
    94276093+}
    94286094+
    9429 +
    9430 +
    9431 +
    9432 +
    9433 +
     6095+EXPORT_SYMBOL(nvram_get);
     6096+EXPORT_SYMBOL(nvram_getall);
     6097+EXPORT_SYMBOL(nvram_set);
     6098+EXPORT_SYMBOL(nvram_unset);
     6099+EXPORT_SYMBOL(nvram_commit);
    94346100+
    94356101+/* User mode interface below */
     
    95236189+       if (cmd != NVRAM_MAGIC)
    95246190+               return -EINVAL;
    9525 +
    95266191+       return nvram_commit();
    95276192+}
     
    96296294+
    96306295+       /* Initialize hash table */
    9631 +       _nvram_init(sbh);
     6296+       _nvram_init();
    96326297+
    96336298+       /* Create /dev/nvram handle */
     
    96566321+module_init(dev_nvram_init);
    96576322+module_exit(dev_nvram_exit);
    9658 diff -urN linux.old/arch/mips/bcm947xx/pcibios.c linux.dev/arch/mips/bcm947xx/pcibios.c
    9659 --- linux.old/arch/mips/bcm947xx/pcibios.c      1970-01-01 01:00:00.000000000 +0100
    9660 +++ linux.dev/arch/mips/bcm947xx/pcibios.c      2006-04-27 23:42:50.000000000 +0200
    9661 @@ -0,0 +1,380 @@
     6323diff -Nur linux-2.4.32/arch/mips/bcm947xx/pcibios.c linux-2.4.32-freewrt/arch/mips/bcm947xx/pcibios.c
     6324--- linux-2.4.32/arch/mips/bcm947xx/pcibios.c   1970-01-01 01:00:00.000000000 +0100
     6325+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/pcibios.c   2006-07-02 21:58:25.000000000 +0200
     6326@@ -0,0 +1,355 @@
    96626327+/*
    96636328+ * Low-Level PCI and SB support for BCM47xx (Linux support code)
    96646329+ *
    9665 + * Copyright 2006, Broadcom Corporation
     6330+ * Copyright 2004, Broadcom Corporation
    96666331+ * All Rights Reserved.
    96676332+ *
     
    96716336+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    96726337+ *
    9673 + * $Id: pcibios.c,v 1.1.1.9 2006/02/27 03:42:55 honor Exp $
     6338+ * $Id$
    96746339+ */
    96756340+
     
    96866351+
    96876352+#include <typedefs.h>
    9688 +#include <osl.h>
    96896353+#include <bcmutils.h>
    96906354+#include <sbconfig.h>
     6355+#include <sbpci.h>
     6356+#include <pcicfg.h>
    96916357+#include <sbutils.h>
    9692 +#include <hndpci.h>
    9693 +#include <pcicfg.h>
    96946358+#include <bcmdevs.h>
    96956359+#include <bcmnvram.h>
    96966360+
    96976361+/* Global SB handle */
    9698 +extern sb_t *bcm947xx_sbh;
     6362+extern void *bcm947xx_sbh;
    96996363+extern spinlock_t bcm947xx_sbh_lock;
    97006364+
     
    97106374+
    97116375+       spin_lock_irqsave(&sbh_lock, flags);
    9712 +       ret = sbpci_read_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn),
    9713 +               PCI_FUNC(dev->devfn), where, value, sizeof(*value));
     6376+       ret = sbpci_read_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), where, value, sizeof(*value));
    97146377+       spin_unlock_irqrestore(&sbh_lock, flags);
    97156378+       return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
     
    97236386+
    97246387+       spin_lock_irqsave(&sbh_lock, flags);
    9725 +       ret = sbpci_read_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn),
    9726 +               PCI_FUNC(dev->devfn), where, value, sizeof(*value));
     6388+       ret = sbpci_read_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), where, value, sizeof(*value));
    97276389+       spin_unlock_irqrestore(&sbh_lock, flags);
    97286390+       return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
     
    97366398+
    97376399+       spin_lock_irqsave(&sbh_lock, flags);
    9738 +       ret = sbpci_read_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn),
    9739 +               PCI_FUNC(dev->devfn), where, value, sizeof(*value));
     6400+       ret = sbpci_read_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), where, value, sizeof(*value));
    97406401+       spin_unlock_irqrestore(&sbh_lock, flags);
    97416402+       return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
     
    97496410+
    97506411+       spin_lock_irqsave(&sbh_lock, flags);
    9751 +       ret = sbpci_write_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn),
    9752 +               PCI_FUNC(dev->devfn), where, &value, sizeof(value));
     6412+       ret = sbpci_write_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), where, &value, sizeof(value));
    97536413+       spin_unlock_irqrestore(&sbh_lock, flags);
    97546414+       return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
     
    97626422+
    97636423+       spin_lock_irqsave(&sbh_lock, flags);
    9764 +       ret = sbpci_write_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn),
    9765 +               PCI_FUNC(dev->devfn), where, &value, sizeof(value));
     6424+       ret = sbpci_write_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), where, &value, sizeof(value));
    97666425+       spin_unlock_irqrestore(&sbh_lock, flags);
    97676426+       return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
     
    97756434+
    97766435+       spin_lock_irqsave(&sbh_lock, flags);
    9777 +       ret = sbpci_write_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn),
    9778 +               PCI_FUNC(dev->devfn), where, &value, sizeof(value));
     6436+       ret = sbpci_write_config(sbh, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), where, &value, sizeof(value));
    97796437+       spin_unlock_irqrestore(&sbh_lock, flags);
    97806438+       return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
     
    98066464+       set_io_port_base((unsigned long) ioremap_nocache(SB_PCI_MEM, 0x04000000));
    98076465+
     6466+       mdelay(300); //By Joey for Atheros Card
     6467+
    98086468+       /* Scan the SB bus */
    98096469+       pci_scan_bus(0, &pcibios_ops, NULL);
     
    98356495+       u8 irq;
    98366496+
    9837 +       printk("PCI: Fixing up bus %d\n", b->number);
     6497+               printk("PCI: Fixing up bus %d\n", b->number);
    98386498+
    98396499+       /* Fix up SB */
    98406500+       if (b->number == 0) {
    9841 +               for (ln = b->devices.next; ln != &b->devices; ln = ln->next) {
     6501+               for (ln=b->devices.next; ln != &b->devices; ln=ln->next) {
    98426502+                       d = pci_dev_b(ln);
    98436503+                       /* Fix up interrupt lines */
     
    98506510+       /* Fix up external PCI */
    98516511+       else {
    9852 +               for (ln = b->devices.next; ln != &b->devices; ln = ln->next) {
     6512+               for (ln=b->devices.next; ln != &b->devices; ln=ln->next) {
    98536513+                       d = pci_dev_b(ln);
    98546514+                       /* Fix up resource bases */
     
    98586518+                               if (res->end) {
    98596519+                                       size = res->end - res->start + 1;
    9860 +                                       if (*base & (size - 1))
    9861 +                                               *base = (*base + size) & ~(size - 1);
    9862 +                                       res->start = *base;
    9863 +                                       res->end = res->start + size - 1;
    9864 +                                       *base += size;
    9865 +                                       pci_write_config_dword(d,
    9866 +                                               PCI_BASE_ADDRESS_0 + (pos << 2), res->start);
     6520+                                       if (*base & (size - 1))
     6521+                                               *base = (*base + size) & ~(size - 1);
     6522+                                       res->start = *base;
     6523+                                       res->end = res->start + size - 1;
     6524+                                       *base += size;
     6525+                                       pci_write_config_dword(d, PCI_BASE_ADDRESS_0 + (pos << 2), res->start);
    98676526+                               }
    98686527+                               /* Fix up PCI bridge BAR0 only */
     
    98866545+void
    98876546+pcibios_align_resource(void *data, struct resource *res,
    9888 +       unsigned long size, unsigned long align)
     6547+                      unsigned long size, unsigned long align)
    98896548+{
    98906549+}
     
    99036562+       pci_read_config_word(dev, PCI_COMMAND, &cmd);
    99046563+       old_cmd = cmd;
    9905 +       for (idx = 0; idx < 6; idx++) {
     6564+       for(idx=0; idx<6; idx++) {
    99066565+               r = &dev->resource[idx];
    99076566+               if (r->flags & IORESOURCE_IO)
     
    99246583+       ulong flags;
    99256584+       uint coreidx;
    9926 +       void *regs;
    99276585+
    99286586+       /* External PCI device enable */
     
    99396597+       spin_lock_irqsave(&sbh_lock, flags);
    99406598+       coreidx = sb_coreidx(sbh);
    9941 +       regs = sb_setcoreidx(sbh, PCI_SLOT(dev->devfn));
    9942 +       if (!regs)
     6599+       if (!sb_setcoreidx(sbh, PCI_SLOT(dev->devfn)))
    99436600+               return PCIBIOS_DEVICE_NOT_FOUND;
    99446601+
     
    99546611+       if (sb_coreid(sbh) == SB_USB) {
    99556612+               sb_core_disable(sbh, sb_coreflags(sbh, 0, 0));
    9956 +               sb_core_reset(sbh, 1 << 29, 0);
    9957 +       }
    9958 +       /*
    9959 +        * USB 2.0 special considerations:
    9960 +        *
    9961 +        * 1. Since the core supports both OHCI and EHCI functions, it must
    9962 +        *    only be reset once.
    9963 +        *
    9964 +        * 2. In addition to the standard SB reset sequence, the Host Control
    9965 +        *    Register must be programmed to bring the USB core and various
    9966 +        *    phy components out of reset.
    9967 +        */
    9968 +       else if (sb_coreid(sbh) == SB_USB20H) {
    9969 +               if (!sb_iscoreup(sbh)) {
    9970 +                       sb_core_reset(sbh, 0, 0);
    9971 +                       writel(0x7FF, (ulong)regs + 0x200);
    9972 +                       udelay(1);
    9973 +               }
     6613+               sb_core_reset(sbh, 1 << 29);
    99746614+       } else
    9975 +               sb_core_reset(sbh, 0, 0);
     6615+               sb_core_reset(sbh, 0);
    99766616+
    99776617+       sb_setcoreidx(sbh, coreidx);
    99786618+       spin_unlock_irqrestore(&sbh_lock, flags);
    9979 +
     6619+       
    99806620+       return 0;
    99816621+}
     
    99836623+void
    99846624+pcibios_update_resource(struct pci_dev *dev, struct resource *root,
    9985 +       struct resource *res, int resource)
     6625+                       struct resource *res, int resource)
    99866626+{
    99876627+       unsigned long where, size;
     
    100406680+}
    100416681+
    10042 diff -urN linux.old/arch/mips/bcm947xx/prom.c linux.dev/arch/mips/bcm947xx/prom.c
    10043 --- linux.old/arch/mips/bcm947xx/prom.c 1970-01-01 01:00:00.000000000 +0100
    10044 +++ linux.dev/arch/mips/bcm947xx/prom.c 2006-04-27 19:24:19.000000000 +0200
     6682diff -Nur linux-2.4.32/arch/mips/bcm947xx/prom.c linux-2.4.32-freewrt/arch/mips/bcm947xx/prom.c
     6683--- linux-2.4.32/arch/mips/bcm947xx/prom.c      1970-01-01 01:00:00.000000000 +0100
     6684+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/prom.c      2006-07-02 21:58:25.000000000 +0200
    100456685@@ -0,0 +1,41 @@
    100466686+/*
     
    100856725+{
    100866726+}
    10087 diff -urN linux.old/arch/mips/bcm947xx/sbmips.c linux.dev/arch/mips/bcm947xx/sbmips.c
    10088 --- linux.old/arch/mips/bcm947xx/sbmips.c       1970-01-01 01:00:00.000000000 +0100
    10089 +++ linux.dev/arch/mips/bcm947xx/sbmips.c       2006-05-02 04:43:13.000000000 +0200
    10090 @@ -0,0 +1,1132 @@
     6727diff -Nur linux-2.4.32/arch/mips/bcm947xx/sbmips.c linux-2.4.32-freewrt/arch/mips/bcm947xx/sbmips.c
     6728--- linux-2.4.32/arch/mips/bcm947xx/sbmips.c    1970-01-01 01:00:00.000000000 +0100
     6729+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/sbmips.c    2006-07-02 21:58:25.000000000 +0200
     6730@@ -0,0 +1,1033 @@
    100916731+/*
    100926732+ * BCM47XX Sonics SiliconBackplane MIPS core routines
    100936733+ *
    10094 + * Copyright 2006, Broadcom Corporation
     6734+ * Copyright 2005, Broadcom Corporation
    100956735+ * All Rights Reserved.
    100966736+ *
     
    101006740+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    101016741+ *
    10102 + * $Id: hndmips.c,v 1.1.1.1 2006/02/27 03:43:16 honor Exp $
     6742+ * $Id: sbmips.c,v 1.3 2005/03/07 08:35:32 kanki Exp $
    101036743+ */
    101046744+
    101056745+#include <typedefs.h>
    10106 +#include <bcmdefs.h>
    101076746+#include <osl.h>
    10108 +#include <bcmutils.h>
    101096747+#include <sbutils.h>
    101106748+#include <bcmdevs.h>
    101116749+#include <bcmnvram.h>
     6750+#include <bcmutils.h>
     6751+#include <hndmips.h>
    101126752+#include <sbconfig.h>
    101136753+#include <sbextif.h>
     
    101156755+#include <sbmemc.h>
    101166756+#include <mipsinc.h>
    10117 +#include <sbhndmips.h>
    10118 +#include <hndcpu.h>
    10119 +
    10120 +/* sbipsflag register format, indexed by irq. */
     6757+
     6758+/*
     6759+ * Returns TRUE if an external UART exists at the given base
     6760+ * register.
     6761+ */
     6762+static bool   
     6763+BCMINITFN(serial_exists)(uint8 *regs)
     6764+{
     6765+       uint8 save_mcr, status1;
     6766+
     6767+       save_mcr = R_REG(&regs[UART_MCR]);
     6768+       W_REG(&regs[UART_MCR], UART_MCR_LOOP | 0x0a);
     6769+       status1 = R_REG(&regs[UART_MSR]) & 0xf0;
     6770+       W_REG(&regs[UART_MCR], save_mcr);
     6771+
     6772+       return (status1 == 0x90);
     6773+}
     6774+
     6775+/*
     6776+ * Initializes UART access. The callback function will be called once
     6777+ * per found UART.
     6778+ */
     6779+void
     6780+BCMINITFN(sb_serial_init)(void *sbh, void (*add)(void *regs, uint irq, uint baud_base, uint reg_shift))
     6781+{
     6782+       void *regs;
     6783+       ulong base;
     6784+       uint irq;
     6785+       int i, n;
     6786+
     6787+       if ((regs = sb_setcore(sbh, SB_EXTIF, 0))) {
     6788+               extifregs_t *eir = (extifregs_t *) regs;
     6789+               sbconfig_t *sb;
     6790+
     6791+               /* Determine external UART register base */
     6792+               sb = (sbconfig_t *)((ulong) eir + SBCONFIGOFF);
     6793+               base = EXTIF_CFGIF_BASE(sb_base(R_REG(&sb->sbadmatch1)));
     6794+
     6795+               /* Determine IRQ */
     6796+               irq = sb_irq(sbh);
     6797+
     6798+               /* Disable GPIO interrupt initially */
     6799+               W_REG(&eir->gpiointpolarity, 0);
     6800+               W_REG(&eir->gpiointmask, 0);
     6801+
     6802+               /* Search for external UARTs */
     6803+               n = 2;
     6804+               for (i = 0; i < 2; i++) {
     6805+                       regs = (void *) REG_MAP(base + (i * 8), 8);
     6806+                       if (BCMINIT(serial_exists)(regs)) {
     6807+                               /* Set GPIO 1 to be the external UART IRQ */
     6808+                               W_REG(&eir->gpiointmask, 2);
     6809+                               if (add)
     6810+                                       add(regs, irq, 13500000, 0);
     6811+                       }
     6812+               }
     6813+
     6814+               /* Add internal UART if enabled */
     6815+               if (R_REG(&eir->corecontrol) & CC_UE)
     6816+                       if (add)
     6817+                               add((void *) &eir->uartdata, irq, sb_clock(sbh), 2);
     6818+       } else if ((regs = sb_setcore(sbh, SB_CC, 0))) {
     6819+               chipcregs_t *cc = (chipcregs_t *) regs;
     6820+               uint32 rev, cap, pll, baud_base, div;
     6821+
     6822+               /* Determine core revision and capabilities */
     6823+               rev = sb_corerev(sbh);
     6824+               cap = R_REG(&cc->capabilities);
     6825+               pll = cap & CAP_PLL_MASK;
     6826+
     6827+               /* Determine IRQ */
     6828+               irq = sb_irq(sbh);
     6829+
     6830+               if (pll == PLL_TYPE1) {
     6831+                       /* PLL clock */
     6832+                       baud_base = sb_clock_rate(pll,
     6833+                                                 R_REG(&cc->clockcontrol_n),
     6834+                                                 R_REG(&cc->clockcontrol_m2));
     6835+                       div = 1;
     6836+               } else {
     6837+                       if (rev >= 11) {
     6838+                               /* Fixed ALP clock */
     6839+                               baud_base = 20000000;
     6840+                               div = 1;
     6841+                               /* Set the override bit so we don't divide it */
     6842+                               W_REG(&cc->corecontrol, CC_UARTCLKO);
     6843+                       } else if (rev >= 3) {
     6844+                               /* Internal backplane clock */
     6845+                               baud_base = sb_clock(sbh);
     6846+                               div = 2;        /* Minimum divisor */
     6847+                               W_REG(&cc->clkdiv, ((R_REG(&cc->clkdiv) & ~CLKD_UART) | div));
     6848+                       } else {
     6849+                               /* Fixed internal backplane clock */
     6850+                               baud_base = 88000000;
     6851+                               div = 48;
     6852+                       }
     6853+
     6854+                       /* Clock source depends on strapping if UartClkOverride is unset */
     6855+                       if ((rev > 0) &&
     6856+                           ((R_REG(&cc->corecontrol) & CC_UARTCLKO) == 0)) {
     6857+                               if ((cap & CAP_UCLKSEL) == CAP_UINTCLK) {
     6858+                                       /* Internal divided backplane clock */
     6859+                                       baud_base /= div;
     6860+                               } else {
     6861+                                       /* Assume external clock of 1.8432 MHz */
     6862+                                       baud_base = 1843200;
     6863+                               }
     6864+                       }
     6865+               }
     6866+
     6867+               /* Add internal UARTs */
     6868+               n = cap & CAP_UARTS_MASK;
     6869+               for (i = 0; i < n; i++) {
     6870+                       /* Register offset changed after revision 0 */
     6871+                       if (rev)
     6872+                               regs = (void *)((ulong) &cc->uart0data + (i * 256));
     6873+                       else
     6874+                               regs = (void *)((ulong) &cc->uart0data + (i * 8));
     6875+
     6876+                       if (add)
     6877+                               add(regs, irq, baud_base, 0);
     6878+               }
     6879+       }
     6880+}
     6881+
     6882+/*
     6883+ * Initialize jtag master and return handle for
     6884+ * jtag_rwreg. Returns NULL on failure.
     6885+ */
     6886+void *
     6887+sb_jtagm_init(void *sbh, uint clkd, bool exttap)
     6888+{
     6889+       void *regs;
     6890+
     6891+       if ((regs = sb_setcore(sbh, SB_CC, 0)) != NULL) {
     6892+               chipcregs_t *cc = (chipcregs_t *) regs;
     6893+               uint32 tmp;
     6894+
     6895+               /*
     6896+                * Determine jtagm availability from
     6897+                * core revision and capabilities.
     6898+                */
     6899+               tmp = sb_corerev(sbh);
     6900+               /*
     6901+                * Corerev 10 has jtagm, but the only chip
     6902+                * with it does not have a mips, and
     6903+                * the layout of the jtagcmd register is
     6904+                * different. We'll only accept >= 11.
     6905+                */
     6906+               if (tmp < 11)
     6907+                       return (NULL);
     6908+
     6909+               tmp = R_REG(&cc->capabilities);
     6910+               if ((tmp & CAP_JTAGP) == 0)
     6911+                       return (NULL);
     6912+
     6913+               /* Set clock divider if requested */
     6914+               if (clkd != 0) {
     6915+                       tmp = R_REG(&cc->clkdiv);
     6916+                       tmp = (tmp & ~CLKD_JTAG) |
     6917+                               ((clkd << CLKD_JTAG_SHIFT) & CLKD_JTAG);
     6918+                       W_REG(&cc->clkdiv, tmp);
     6919+               }
     6920+
     6921+               /* Enable jtagm */
     6922+               tmp = JCTRL_EN | (exttap ? JCTRL_EXT_EN : 0);
     6923+               W_REG(&cc->jtagctrl, tmp);
     6924+       }
     6925+
     6926+       return (regs);
     6927+}
     6928+
     6929+void
     6930+sb_jtagm_disable(void *h)
     6931+{
     6932+       chipcregs_t *cc = (chipcregs_t *)h;
     6933+
     6934+       W_REG(&cc->jtagctrl, R_REG(&cc->jtagctrl) & ~JCTRL_EN);
     6935+}
     6936+
     6937+/*
     6938+ * Read/write a jtag register. Assumes a target with
     6939+ * 8 bit IR and 32 bit DR.
     6940+ */
     6941+#define        IRWIDTH         8
     6942+#define        DRWIDTH         32
     6943+uint32
     6944+jtag_rwreg(void *h, uint32 ir, uint32 dr)
     6945+{
     6946+       chipcregs_t *cc = (chipcregs_t *) h;
     6947+       uint32 tmp;
     6948+
     6949+       W_REG(&cc->jtagir, ir);
     6950+       W_REG(&cc->jtagdr, dr);
     6951+       tmp = JCMD_START | JCMD_ACC_IRDR |
     6952+               ((IRWIDTH - 1) << JCMD_IRW_SHIFT) |
     6953+               (DRWIDTH - 1);
     6954+       W_REG(&cc->jtagcmd, tmp);
     6955+       while (((tmp = R_REG(&cc->jtagcmd)) & JCMD_BUSY) == JCMD_BUSY) {
     6956+               /* OSL_DELAY(1); */
     6957+       }
     6958+
     6959+       tmp = R_REG(&cc->jtagdr);
     6960+       return (tmp);
     6961+}
     6962+
     6963+/* Returns the SB interrupt flag of the current core. */
     6964+uint32
     6965+sb_flag(void *sbh)
     6966+{
     6967+       void *regs;
     6968+       sbconfig_t *sb;
     6969+
     6970+       regs = sb_coreregs(sbh);
     6971+       sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
     6972+
     6973+       return (R_REG(&sb->sbtpsflag) & SBTPS_NUM0_MASK);
     6974+}
     6975+
    101216976+static const uint32 sbips_int_mask[] = {
    10122 +       0,      /* placeholder */
     6977+       0,
    101236978+       SBIPS_INT1_MASK,
    101246979+       SBIPS_INT2_MASK,
     
    101286983+
    101296984+static const uint32 sbips_int_shift[] = {
    10130 +       0,      /* placeholder */
    10131 +       SBIPS_INT1_SHIFT,
     6985+       0,
     6986+       0,
    101326987+       SBIPS_INT2_SHIFT,
    101336988+       SBIPS_INT3_SHIFT,
     
    101356990+};
    101366991+
    10137 +/*
    10138 + * Map SB cores sharing the MIPS hardware IRQ0 to virtual dedicated OS IRQs.
    10139 + * Per-port BSP code is required to provide necessary translations between
    10140 + * the shared MIPS IRQ and the virtual OS IRQs based on SB core flag.
    10141 + *
    10142 + * See sb_irq() for the mapping.
    10143 + */
    10144 +static uint shirq_map_base = 0;
    10145 +
    10146 +/* Returns the SB interrupt flag of the current core. */
    10147 +static uint32
    10148 +sb_getflag(sb_t *sbh)
    10149 +{
    10150 +       osl_t *osh;
    10151 +       void *regs;
    10152 +       sbconfig_t *sb;
    10153 +
    10154 +       osh = sb_osh(sbh);
    10155 +       regs = sb_coreregs(sbh);
    10156 +       sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
    10157 +
    10158 +       return (R_REG(osh, &sb->sbtpsflag) & SBTPS_NUM0_MASK);
    10159 +}
    10160 +
    10161 +/*
     6992+/*
    101626993+ * Returns the MIPS IRQ assignment of the current core. If unassigned,
    101636994+ * 0 is returned.
    101646995+ */
    101656996+uint
    10166 +sb_irq(sb_t *sbh)
    10167 +{
    10168 +       osl_t *osh;
     6997+sb_irq(void *sbh)
     6998+{
    101696999+       uint idx;
    101707000+       void *regs;
     
    101737003+       uint irq = 0;
    101747004+
    10175 +       osh = sb_osh(sbh);
    10176 +       flag = sb_getflag(sbh);
     7005+       flag = sb_flag(sbh);
    101777006+
    101787007+       idx = sb_coreidx(sbh);
     
    101837012+
    101847013+               /* sbipsflag specifies which core is routed to interrupts 1 to 4 */
    10185 +               sbipsflag = R_REG(osh, &sb->sbipsflag);
     7014+               sbipsflag = R_REG(&sb->sbipsflag);
    101867015+               for (irq = 1; irq <= 4; irq++) {
    101877016+                       if (((sbipsflag & sbips_int_mask[irq]) >> sbips_int_shift[irq]) == flag)
     
    101987027+
    101997028+/* Clears the specified MIPS IRQ. */
    10200 +static void
    10201 +BCMINITFN(sb_clearirq)(sb_t *sbh, uint irq)
    10202 +{
    10203 +       osl_t *osh;
     7029+static void
     7030+BCMINITFN(sb_clearirq)(void *sbh, uint irq)
     7031+{
    102047032+       void *regs;
    102057033+       sbconfig_t *sb;
    10206 +
    10207 +       osh = sb_osh(sbh);
    102087034+
    102097035+       if (!(regs = sb_setcore(sbh, SB_MIPS, 0)) &&
     
    102137039+
    102147040+       if (irq == 0)
    10215 +               W_REG(osh, &sb->sbintvec, 0);
     7041+               W_REG(&sb->sbintvec, 0);
    102167042+       else
    10217 +               OR_REG(osh, &sb->sbipsflag, sbips_int_mask[irq]);
    10218 +}
    10219 +
    10220 +/*
     7043+               OR_REG(&sb->sbipsflag, sbips_int_mask[irq]);
     7044+}
     7045+
     7046+/* 
    102217047+ * Assigns the specified MIPS IRQ to the specified core. Shared MIPS
    102227048+ * IRQ 0 may be assigned more than once.
    10223 + *
    10224 + * The old assignment to the specified core is removed first.
    102257049+ */
    10226 +static void
    10227 +BCMINITFN(sb_setirq)(sb_t *sbh, uint irq, uint coreid, uint coreunit)
    10228 +{
    10229 +       osl_t *osh;
     7050+static void
     7051+BCMINITFN(sb_setirq)(void *sbh, uint irq, uint coreid, uint coreunit)
     7052+{
    102307053+       void *regs;
    102317054+       sbconfig_t *sb;
    102327055+       uint32 flag;
    10233 +       uint oldirq;
    10234 +
    10235 +       osh = sb_osh(sbh);
    102367056+
    102377057+       regs = sb_setcore(sbh, coreid, coreunit);
    102387058+       ASSERT(regs);
    10239 +       flag = sb_getflag(sbh);
    10240 +       oldirq = sb_irq(sbh);
    10241 +       if (oldirq)
    10242 +               sb_clearirq(sbh, oldirq);
     7059+       flag = sb_flag(sbh);
    102437060+
    102447061+       if (!(regs = sb_setcore(sbh, SB_MIPS, 0)) &&
     
    102477064+       sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
    102487065+
    10249 +       if (!oldirq)
    10250 +               AND_REG(osh, &sb->sbintvec, ~(1 << flag));
    10251 +
    102527066+       if (irq == 0)
    10253 +               OR_REG(osh, &sb->sbintvec, 1 << flag);
     7067+               OR_REG(&sb->sbintvec, 1 << flag);
    102547068+       else {
    102557069+               flag <<= sbips_int_shift[irq];
    102567070+               ASSERT(!(flag & ~sbips_int_mask[irq]));
    10257 +               flag |= R_REG(osh, &sb->sbipsflag) & ~sbips_int_mask[irq];
    10258 +               W_REG(osh, &sb->sbipsflag, flag);
    10259 +       }
    10260 +}
    10261 +
    10262 +/*
     7071+               flag |= R_REG(&sb->sbipsflag) & ~sbips_int_mask[irq];
     7072+               W_REG(&sb->sbipsflag, flag);
     7073+       }
     7074+}     
     7075+
     7076+/* 
    102637077+ * Initializes clocks and interrupts. SB and NVRAM access must be
    102647078+ * initialized prior to calling.
    10265 + *
    10266 + * 'shirqmap' enables virtual dedicated OS IRQ mapping if non-zero.
    102677079+ */
    10268 +void
    10269 +BCMINITFN(sb_mips_init)(sb_t *sbh, uint shirqmap)
    10270 +{
    10271 +       osl_t *osh;
     7080+void
     7081+BCMINITFN(sb_mips_init)(void *sbh)
     7082+{
    102727083+       ulong hz, ns, tmp;
    102737084+       extifregs_t *eir;
     
    102767087+       uint irq;
    102777088+
    10278 +       osh = sb_osh(sbh);
    10279 +
    102807089+       /* Figure out current SB clock speed */
    102817090+       if ((hz = sb_clock(sbh)) == 0)
     
    102867095+       if ((eir = sb_setcore(sbh, SB_EXTIF, 0))) {
    102877096+               /* Initialize extif so we can get to the LEDs and external UART */
    10288 +               W_REG(osh, &eir->prog_config, CF_EN);
     7097+               W_REG(&eir->prog_config, CF_EN);
    102897098+
    102907099+               /* Set timing for the flash */
     
    102927101+               tmp = tmp | (CEIL(40, ns) << FW_W1_SHIFT); /* W1 = 40nS */
    102937102+               tmp = tmp | CEIL(120, ns);              /* W0 = 120nS */
    10294 +               W_REG(osh, &eir->prog_waitcount, tmp);  /* 0x01020a0c for a 100Mhz clock */
     7103+               W_REG(&eir->prog_waitcount, tmp);       /* 0x01020a0c for a 100Mhz clock */
    102957104+
    102967105+               /* Set programmable interface timing for external uart */
     
    102997108+               tmp = tmp | (CEIL(100, ns) << FW_W1_SHIFT); /* W1 = 100nS */
    103007109+               tmp = tmp | CEIL(120, ns);              /* W0 = 120nS */
    10301 +               W_REG(osh, &eir->prog_waitcount, tmp);  /* 0x01020a0c for a 100Mhz clock */
     7110+               W_REG(&eir->prog_waitcount, tmp);       /* 0x01020a0c for a 100Mhz clock */
    103027111+       } else if ((cc = sb_setcore(sbh, SB_CC, 0))) {
     7112+//==================================tallest===============================================
     7113+               /* set register for external IO to control LED. */
     7114+                W_REG(&cc->prog_config, 0x11);
     7115+                tmp = CEIL(10, ns) << FW_W3_SHIFT;      /* W3 = 10nS */
     7116+                tmp = tmp | (CEIL(40, ns) << FW_W1_SHIFT); /* W1 = 40nS */
     7117+                tmp = tmp | CEIL(240, ns);              /* W0 = 120nS */
     7118+                W_REG(&cc->prog_waitcount, tmp);        /* 0x01020a0c for a 100Mhz clock */
     7119+//========================================================================================
    103037120+               /* Set timing for the flash */
    103047121+               tmp = CEIL(10, ns) << FW_W3_SHIFT;      /* W3 = 10nS */
    103057122+               tmp |= CEIL(10, ns) << FW_W1_SHIFT;     /* W1 = 10nS */
    103067123+               tmp |= CEIL(120, ns);                   /* W0 = 120nS */
    10307 +               if ((sb_corerev(sbh) < 9) ||
    10308 +                       (BCMINIT(sb_chip)(sbh) == 0x5365))
    10309 +                       W_REG(osh, &cc->flash_waitcount, tmp);
    10310 +
    10311 +               if ((sb_corerev(sbh) < 9) ||
    10312 +                   ((sb_chip(sbh) == BCM5350_CHIP_ID) && sb_chiprev(sbh) == 0) ||
    10313 +                       (BCMINIT(sb_chip)(sbh) == 0x5365)) {
    10314 +                       W_REG(osh, &cc->pcmcia_memwait, tmp);
     7124+
     7125+               // Added by Chen-I for 5365
     7126+               if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID)
     7127+               {
     7128+                       W_REG(&cc->flash_waitcount, tmp);
     7129+                       W_REG(&cc->pcmcia_memwait, tmp);
    103157130+               }
    10316 +
    10317 +               /* Save shared IRQ mapping base */
    10318 +               shirq_map_base = shirqmap;
     7131+               else
     7132+               {
     7133+                       if (sb_corerev(sbh) < 9) 
     7134+                               W_REG(&cc->flash_waitcount, tmp);
     7135+       
     7136+                       if ( (sb_corerev(sbh) < 9) ||
     7137+                            ((BCMINIT(sb_chip)(sbh) == BCM5350_DEVICE_ID) && BCMINIT(sb_chiprev)(sbh) == 0) ) {
     7138+                               W_REG(&cc->pcmcia_memwait, tmp);
     7139+                       }
     7140+               }
     7141+
     7142+               // Added by Chen-I & Yen for enabling 5350 EXTIF
     7143+               if (BCMINIT(sb_chip)(sbh) == BCM5350_DEVICE_ID)
     7144+               {
     7145+                       /* Set programmable interface timing for external uart */
     7146+                       tmp = CEIL(10, ns) << FW_W3_SHIFT;      /* W3 = 10nS */
     7147+                       tmp = tmp | (CEIL(20, ns) << FW_W2_SHIFT); /* W2 = 20nS */
     7148+                       tmp = tmp | (CEIL(100, ns) << FW_W1_SHIFT); /* W1 = 100nS */
     7149+                       tmp = tmp | CEIL(120, ns);              /* W0 = 120nS */
     7150+                       W_REG(&cc->prog_waitcount, tmp);       /* 0x01020a0c for a 100Mhz clock */
     7151+                       //printf("===========config_REG=%d\n", R_REG(&cc->prog_config));
     7152+                       //printf("-----------config_REG_addr=%x\n", &cc->prog_config);
     7153+                       //printf("===========waitcount_REG=%d\n", R_REG(&cc->prog_waitcount));
     7154+                       //printf("-----------waitcount_REG=%x\n", &cc->prog_waitcount);
     7155+               }
    103197156+       }
    103207157+
    103217158+       /* Chip specific initialization */
    10322 +       switch (sb_chip(sbh)) {
    10323 +       case BCM4710_CHIP_ID:
     7159+       switch (BCMINIT(sb_chip)(sbh)) {
     7160+       case BCM4710_DEVICE_ID:
    103247161+               /* Clear interrupt map */
    103257162+               for (irq = 0; irq <= 4; irq++)
    10326 +                       sb_clearirq(sbh, irq);
    10327 +               sb_setirq(sbh, 0, SB_CODEC, 0);
    10328 +               sb_setirq(sbh, 0, SB_EXTIF, 0);
    10329 +               sb_setirq(sbh, 2, SB_ENET, 1);
    10330 +               sb_setirq(sbh, 3, SB_ILINE20, 0);
    10331 +               sb_setirq(sbh, 4, SB_PCI, 0);
     7163+                       BCMINIT(sb_clearirq)(sbh, irq);
     7164+               BCMINIT(sb_setirq)(sbh, 0, SB_CODEC, 0);
     7165+               BCMINIT(sb_setirq)(sbh, 0, SB_EXTIF, 0);
     7166+               BCMINIT(sb_setirq)(sbh, 2, SB_ENET, 1);
     7167+               BCMINIT(sb_setirq)(sbh, 3, SB_ILINE20, 0);
     7168+               BCMINIT(sb_setirq)(sbh, 4, SB_PCI, 0);
    103327169+               ASSERT(eir);
    10333 +               value = nvram_get("et0phyaddr");
     7170+               value = BCMINIT(nvram_get)("et0phyaddr");
    103347171+               if (value && !strcmp(value, "31")) {
    103357172+                       /* Enable internal UART */
    10336 +                       W_REG(osh, &eir->corecontrol, CC_UE);
     7173+                       W_REG(&eir->corecontrol, CC_UE);
    103377174+                       /* Give USB its own interrupt */
    10338 +                       sb_setirq(sbh, 1, SB_USB, 0);
     7175+                       BCMINIT(sb_setirq)(sbh, 1, SB_USB, 0);
    103397176+               } else {
    103407177+                       /* Disable internal UART */
    10341 +                       W_REG(osh, &eir->corecontrol, 0);
     7178+                       W_REG(&eir->corecontrol, 0);
    103427179+                       /* Give Ethernet its own interrupt */
    10343 +                       sb_setirq(sbh, 1, SB_ENET, 0);
    10344 +                       sb_setirq(sbh, 0, SB_USB, 0);
     7180+                       BCMINIT(sb_setirq)(sbh, 1, SB_ENET, 0);
     7181+                       BCMINIT(sb_setirq)(sbh, 0, SB_USB, 0);
    103457182+               }
    103467183+               break;
    10347 +       case BCM5350_CHIP_ID:
    10348 +               /* Clear interrupt map */
    10349 +               for (irq = 0; irq <= 4; irq++)
    10350 +                       sb_clearirq(sbh, irq);
    10351 +               sb_setirq(sbh, 0, SB_CC, 0);
    10352 +               sb_setirq(sbh, 0, SB_MIPS33, 0);
    10353 +               sb_setirq(sbh, 1, SB_D11, 0);
    10354 +               sb_setirq(sbh, 2, SB_ENET, 0);
    10355 +               sb_setirq(sbh, 3, SB_PCI, 0);
    10356 +               sb_setirq(sbh, 4, SB_USB, 0);
     7184+       case BCM4310_DEVICE_ID:
     7185+               MTC0(C0_BROADCOM, 0, MFC0(C0_BROADCOM, 0) & ~(1 << 22));
    103577186+               break;
    10358 +       case BCM4785_CHIP_ID:
    10359 +               /* Reassign PCI to irq 4 */
    10360 +               sb_setirq(sbh, 4, SB_PCI, 0);
     7187+        case BCM5350_DEVICE_ID:
     7188+                /* Clear interrupt map */
     7189+                for (irq = 0; irq <= 4; irq++)
     7190+                        BCMINIT(sb_clearirq)(sbh, irq);
     7191+                BCMINIT(sb_setirq)(sbh, 0, SB_CC, 0);
     7192+                BCMINIT(sb_setirq)(sbh, 1, SB_D11, 0);
     7193+                BCMINIT(sb_setirq)(sbh, 2, SB_ENET, 0);
     7194+               BCMINIT(sb_setirq)(sbh, 3, SB_IPSEC, 0);
     7195+                BCMINIT(sb_setirq)(sbh, 4, SB_USB, 0);
    103617196+               break;
    103627197+       }
     
    103647199+
    103657200+uint32
    10366 +BCMINITFN(sb_cpu_clock)(sb_t *sbh)
     7201+BCMINITFN(sb_mips_clock)(void *sbh)
    103677202+{
    103687203+       extifregs_t *eir;
     
    103787213+       /* switch to extif or chipc core */
    103797214+       if ((eir = (extifregs_t *) sb_setcore(sbh, SB_EXTIF, 0))) {
    10380 +               n = R_REG(osh, &eir->clockcontrol_n);
    10381 +               m = R_REG(osh, &eir->clockcontrol_sb);
     7215+               n = R_REG(&eir->clockcontrol_n);
     7216+               m = R_REG(&eir->clockcontrol_sb);
    103827217+       } else if ((cc = (chipcregs_t *) sb_setcore(sbh, SB_CC, 0))) {
    10383 +               pll_type = R_REG(osh, &cc->capabilities) & CAP_PLL_MASK;
    10384 +               n = R_REG(osh, &cc->clockcontrol_n);
     7218+               pll_type = R_REG(&cc->capabilities) & CAP_PLL_MASK;
     7219+               n = R_REG(&cc->clockcontrol_n);
    103857220+               if ((pll_type == PLL_TYPE2) ||
    103867221+                   (pll_type == PLL_TYPE4) ||
    103877222+                   (pll_type == PLL_TYPE6) ||
    103887223+                   (pll_type == PLL_TYPE7))
    10389 +                       m = R_REG(osh, &cc->clockcontrol_m3);
     7224+                       m = R_REG(&cc->clockcontrol_mips);
    103907225+               else if (pll_type == PLL_TYPE5) {
    103917226+                       rate = 200000000;
     
    103937228+               }
    103947229+               else if (pll_type == PLL_TYPE3) {
    10395 +                       if (sb_chip(sbh) == BCM5365_CHIP_ID) {
     7230+                       if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID) { /* 5365 is also type3 */
    103967231+                               rate = 200000000;
    103977232+                               goto out;
    10398 +                       }
    10399 +                       /* 5350 uses m2 to control mips */
    10400 +                       else
    10401 +                               m = R_REG(osh, &cc->clockcontrol_m2);
     7233+                       } else
     7234+                               m = R_REG(&cc->clockcontrol_m2); /* 5350 uses m2 to control mips */
    104027235+               } else
    10403 +                       m = R_REG(osh, &cc->clockcontrol_sb);
     7236+                       m = R_REG(&cc->clockcontrol_sb);
    104047237+       } else
    104057238+               goto out;
    104067239+
    10407 +
    10408 +       /* calculate rate */
    10409 +       if (BCMINIT(sb_chip)(sbh) == 0x5365)
     7240+       // Added by Chen-I for 5365
     7241+       if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID)
    104107242+               rate = 100000000;
    104117243+       else
     7244+               /* calculate rate */
    104127245+               rate = sb_clock_rate(pll_type, n, m);
    104137246+
     
    104247257+#define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4)
    104257258+
    10426 +static void
     7259+static void 
    104277260+BCMINITFN(handler)(void)
    104287261+{
    10429 +       __asm__(
     7262+       /* Step 11 */
     7263+       __asm__ (
    104307264+               ".set\tmips32\n\t"
    104317265+               "ssnop\n\t"
     
    104417275+               "nop\n\t"
    104427276+               "nop\n\t"
    10443 +               ".set\tmips0");
     7277+               ".set\tmips0"
     7278+       );
    104447279+}
    104457280+
    104467281+/* The following MUST come right after handler() */
    10447 +static void
     7282+static void 
    104487283+BCMINITFN(afterhandler)(void)
    104497284+{
     
    104527287+/*
    104537288+ * Set the MIPS, backplane and PCI clocks as closely as possible.
    10454 + *
    10455 + * MIPS clocks synchronization function has been moved from PLL in chipcommon
    10456 + * core rev. 15 to a DLL inside the MIPS core in 4785.
    104577289+ */
    10458 +bool
    10459 +BCMINITFN(sb_mips_setclock)(sb_t *sbh, uint32 mipsclock, uint32 sbclock, uint32 pciclock)
     7290+bool 
     7291+BCMINITFN(sb_mips_setclock)(void *sbh, uint32 mipsclock, uint32 sbclock, uint32 pciclock)
    104607292+{
    104617293+       extifregs_t *eir = NULL;
     
    104677299+       uint ic_size, ic_lsize;
    104687300+       uint idx, i;
    10469 +
    10470 +       /* PLL configuration: type 1 */
    104717301+       typedef struct {
    104727302+               uint32 mipsclock;
     
    104777307+       } n3m_table_t;
    104787308+       static n3m_table_t BCMINITDATA(type1_table)[] = {
    10479 +               /* 96.000 32.000 24.000 */
    10480 +               { 96000000, 0x0303, 0x04020011, 0x11030011, 0x11050011 },
    10481 +               /* 100.000 33.333 25.000 */
    10482 +               { 100000000, 0x0009, 0x04020011, 0x11030011, 0x11050011 },
    10483 +               /* 104.000 31.200 24.960 */
    10484 +               { 104000000, 0x0802, 0x04020011, 0x11050009, 0x11090009 },
    10485 +               /* 108.000 32.400 24.923 */
    10486 +               { 108000000, 0x0403, 0x04020011, 0x11050009, 0x02000802 },
    10487 +               /* 112.000 32.000 24.889 */
    10488 +               { 112000000, 0x0205, 0x04020011, 0x11030021, 0x02000403 },
    10489 +               /* 115.200 32.000 24.000 */
    10490 +               { 115200000, 0x0303, 0x04020009, 0x11030011, 0x11050011 },
    10491 +               /* 120.000 30.000 24.000 */
    10492 +               { 120000000, 0x0011, 0x04020011, 0x11050011, 0x11090011 },
    10493 +               /* 124.800 31.200 24.960 */
    10494 +               { 124800000, 0x0802, 0x04020009, 0x11050009, 0x11090009 },
    10495 +               /* 128.000 32.000 24.000 */
    10496 +               { 128000000, 0x0305, 0x04020011, 0x11050011, 0x02000305 },
    10497 +               /* 132.000 33.000 24.750 */
    10498 +               { 132000000, 0x0603, 0x04020011, 0x11050011, 0x02000305 },
    10499 +               /* 136.000 32.640 24.727 */
    10500 +               { 136000000, 0x0c02, 0x04020011, 0x11090009, 0x02000603 },
    10501 +               /* 140.000 30.000 24.706 */
    10502 +               { 140000000, 0x0021, 0x04020011, 0x11050021, 0x02000c02 },
    10503 +               /* 144.000 30.857 24.686 */
    10504 +               { 144000000, 0x0405, 0x04020011, 0x01020202, 0x11090021 },
    10505 +               /* 150.857 33.000 24.000 */
    10506 +               { 150857142, 0x0605, 0x04020021, 0x02000305, 0x02000605 },
    10507 +               /* 152.000 32.571 24.000 */
    10508 +               { 152000000, 0x0e02, 0x04020011, 0x11050021, 0x02000e02 },
    10509 +               /* 156.000 31.200 24.960 */
    10510 +               { 156000000, 0x0802, 0x04020005, 0x11050009, 0x11090009 },
    10511 +               /* 160.000 32.000 24.000 */
    10512 +               { 160000000, 0x0309, 0x04020011, 0x11090011, 0x02000309 },
    10513 +               /* 163.200 32.640 24.727 */
    10514 +               { 163200000, 0x0c02, 0x04020009, 0x11090009, 0x02000603 },
    10515 +               /* 168.000 32.000 24.889 */
    10516 +               { 168000000, 0x0205, 0x04020005, 0x11030021, 0x02000403 },
    10517 +               /* 176.000 33.000 24.000 */
    10518 +               { 176000000, 0x0602, 0x04020003, 0x11050005, 0x02000602 },
    10519 +               };
    10520 +
    10521 +       /* PLL configuration: type 3 */
     7309+               {  96000000, 0x0303, 0x04020011, 0x11030011, 0x11050011 }, /*  96.000 32.000 24.000 */
     7310+               { 100000000, 0x0009, 0x04020011, 0x11030011, 0x11050011 }, /* 100.000 33.333 25.000 */
     7311+               { 104000000, 0x0802, 0x04020011, 0x11050009, 0x11090009 }, /* 104.000 31.200 24.960 */
     7312+               { 108000000, 0x0403, 0x04020011, 0x11050009, 0x02000802 }, /* 108.000 32.400 24.923 */
     7313+               { 112000000, 0x0205, 0x04020011, 0x11030021, 0x02000403 }, /* 112.000 32.000 24.889 */
     7314+               { 115200000, 0x0303, 0x04020009, 0x11030011, 0x11050011 }, /* 115.200 32.000 24.000 */
     7315+               { 120000000, 0x0011, 0x04020011, 0x11050011, 0x11090011 }, /* 120.000 30.000 24.000 */
     7316+               { 124800000, 0x0802, 0x04020009, 0x11050009, 0x11090009 }, /* 124.800 31.200 24.960 */
     7317+               { 128000000, 0x0305, 0x04020011, 0x11050011, 0x02000305 }, /* 128.000 32.000 24.000 */
     7318+               { 132000000, 0x0603, 0x04020011, 0x11050011, 0x02000305 }, /* 132.000 33.000 24.750 */
     7319+               { 136000000, 0x0c02, 0x04020011, 0x11090009, 0x02000603 }, /* 136.000 32.640 24.727 */
     7320+               { 140000000, 0x0021, 0x04020011, 0x11050021, 0x02000c02 }, /* 140.000 30.000 24.706 */
     7321+               { 144000000, 0x0405, 0x04020011, 0x01020202, 0x11090021 }, /* 144.000 30.857 24.686 */
     7322+               { 150857142, 0x0605, 0x04020021, 0x02000305, 0x02000605 }, /* 150.857 33.000 24.000 */
     7323+               { 152000000, 0x0e02, 0x04020011, 0x11050021, 0x02000e02 }, /* 152.000 32.571 24.000 */
     7324+               { 156000000, 0x0802, 0x04020005, 0x11050009, 0x11090009 }, /* 156.000 31.200 24.960 */
     7325+               { 160000000, 0x0309, 0x04020011, 0x11090011, 0x02000309 }, /* 160.000 32.000 24.000 */
     7326+               { 163200000, 0x0c02, 0x04020009, 0x11090009, 0x02000603 }, /* 163.200 32.640 24.727 */
     7327+               { 168000000, 0x0205, 0x04020005, 0x11030021, 0x02000403 }, /* 168.000 32.000 24.889 */
     7328+               { 176000000, 0x0602, 0x04020003, 0x11050005, 0x02000602 }, /* 176.000 33.000 24.000 */
     7329+       };
    105227330+       typedef struct {
    105237331+               uint32 mipsclock;
     
    105257333+               uint32 m2; /* that is the clockcontrol_m2 */
    105267334+       } type3_table_t;
    10527 +       static type3_table_t type3_table[] = {
    10528 +               /* for 5350, mips clock is always double sb clock */
    10529 +               { 150000000, 0x311, 0x4020005 },
    10530 +               { 200000000, 0x311, 0x4020003 },
    10531 +               };
    10532 +
    10533 +       /* PLL configuration: type 2, 4, 7 */
     7335+       static type3_table_t type3_table[] = { /* for 5350, mips clock is always double sb clock */
     7336+               { 150000000, 0x311, 0x4020005 },
     7337+               { 200000000, 0x311, 0x4020003 },
     7338+       };
    105347339+       typedef struct {
    105357340+               uint32 mipsclock;
     
    105427347+               uint32 ratio_cfg;
    105437348+               uint32 ratio_parm;
    10544 +               uint32 d11_r1;
    10545 +               uint32 d11_r2;
    105467349+       } n4m_table_t;
     7350+
    105477351+       static n4m_table_t BCMINITDATA(type2_table)[] = {
    10548 +               { 120000000, 60000000, 0x0303, 0x01000200, 0x01000600, 0x01000200, 0x05000200, 11,
    10549 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10550 +               { 150000000, 75000000, 0x0303, 0x01000100, 0x01000600, 0x01000100, 0x05000100, 11,
    10551 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10552 +               { 180000000, 80000000, 0x0403, 0x01010000, 0x01020300, 0x01020600, 0x05000100, 8,
    10553 +               0x012a00a9, 9 /* ratio  4/9 */, 0x012a00a9 },
    10554 +               { 180000000, 90000000, 0x0403, 0x01000100, 0x01020300, 0x01000100, 0x05000100, 11,
    10555 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10556 +               { 200000000, 100000000, 0x0303, 0x02010000, 0x02040001, 0x02010000, 0x06000001, 11,
    10557 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10558 +               { 211200000, 105600000, 0x0902, 0x01000200, 0x01030400, 0x01000200, 0x05000200, 11,
    10559 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10560 +               { 220800000, 110400000, 0x1500, 0x01000200, 0x01030400, 0x01000200, 0x05000200, 11,
    10561 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10562 +               { 230400000, 115200000, 0x0604, 0x01000200, 0x01020600, 0x01000200, 0x05000200, 11,
    10563 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10564 +               { 234000000, 104000000, 0x0b01, 0x01010000, 0x01010700, 0x01020600, 0x05000100, 8,
    10565 +               0x012a00a9, 9 /* ratio  4/9 */, 0x012a00a9 },
    10566 +               { 240000000, 120000000, 0x0803, 0x01000200, 0x01020600, 0x01000200, 0x05000200, 11,
    10567 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10568 +               { 252000000, 126000000, 0x0504, 0x01000100, 0x01020500, 0x01000100, 0x05000100, 11,
    10569 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10570 +               { 264000000, 132000000, 0x0903, 0x01000200, 0x01020700, 0x01000200, 0x05000200, 11,
    10571 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10572 +               { 270000000, 120000000, 0x0703, 0x01010000, 0x01030400, 0x01020600, 0x05000100, 8,
    10573 +               0x012a00a9, 9 /* ratio  4/9 */, 0x012a00a9 },
    10574 +               { 276000000, 122666666, 0x1500, 0x01010000, 0x01030400, 0x01020600, 0x05000100, 8,
    10575 +               0x012a00a9, 9 /* ratio  4/9 */, 0x012a00a9 },
    10576 +               { 280000000, 140000000, 0x0503, 0x01000000, 0x01010600, 0x01000000, 0x05000000, 11,
    10577 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10578 +               { 288000000, 128000000, 0x0604, 0x01010000, 0x01030400, 0x01020600, 0x05000100, 8,
    10579 +               0x012a00a9, 9 /* ratio  4/9 */, 0x012a00a9 },
    10580 +               { 288000000, 144000000, 0x0404, 0x01000000, 0x01010600, 0x01000000, 0x05000000, 11,
    10581 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10582 +               { 300000000, 133333333, 0x0803, 0x01010000, 0x01020600, 0x01010100, 0x05000100, 8,
    10583 +               0x012a00a9, 9 /* ratio  4/9 */, 0x012a00a9 },
    10584 +               { 300000000, 150000000, 0x0803, 0x01000100, 0x01020600, 0x01010100, 0x05000100, 11,
    10585 +               0x0aaa0555, 8 /* ratio  4/8 */, 0x00aa0055 },
    10586 +               { 330000000, 132000000, 0x0903, 0x01000200, 0x00020200, 0x01010100, 0x05000100, 0,
    10587 +               0, 10 /* ratio 4/10 */, 0x02520129 },
    10588 +               { 330000000, 146666666, 0x0903, 0x01010000, 0x00020200, 0x01010100, 0x05000100, 0,
    10589 +               0, 9 /* ratio 4/9 */, 0x012a00a9 },
    10590 +               { 330000000, 165000000, 0x0903, 0x01000100, 0x00020200, 0x01010100, 0x05000100, 0,
    10591 +               0, 8 /* ratio 4/8 */, 0x00aa0055 },
    10592 +               { 360000000, 120000000, 0x0a03, 0x01000300, 0x00010201, 0x01010200, 0x05000100, 0,
    10593 +               0, 12 /* ratio 4/12 */, 0x04920492 },
    10594 +               { 360000000, 144000000, 0x0a03, 0x01000200, 0x00010201, 0x01010200, 0x05000100, 0,
    10595 +               0, 10 /* ratio 4/10 */, 0x02520129 },
    10596 +               { 360000000, 160000000, 0x0a03, 0x01010000, 0x00010201, 0x01010200, 0x05000100, 0,
    10597 +               0, 9 /* ratio 4/9 */, 0x012a00a9 },
    10598 +               { 360000000, 180000000, 0x0a03, 0x01000100, 0x00010201, 0x01010200, 0x05000100, 0,
    10599 +               0, 8 /* ratio 4/8 */, 0x00aa0055 },
    10600 +               { 390000000, 130000000, 0x0b03, 0x01010100, 0x00020101, 0x01020100, 0x05000100, 0,
    10601 +               0, 12 /* ratio 4/12 */, 0x04920492 },
    10602 +               { 390000000, 156000000, 0x0b03, 0x01000200, 0x00020101, 0x01020100, 0x05000100, 0,
    10603 +               0, 10 /* ratio 4/10 */, 0x02520129 },
    10604 +               { 390000000, 173000000, 0x0b03, 0x01010000, 0x00020101, 0x01020100, 0x05000100, 0,
    10605 +               0, 9 /* ratio 4/9 */, 0x012a00a9 },
    10606 +               { 390000000, 195000000, 0x0b03, 0x01000100, 0x00020101, 0x01020100, 0x05000100, 0,
    10607 +               0, 8 /* ratio 4/8 */, 0x00aa0055 },
     7352+               { 180000000,  80000000, 0x0403, 0x01010000, 0x01020300, 0x01020600, 0x05000100,  8, 0x012a00a9 },
     7353+               { 180000000,  90000000, 0x0403, 0x01000100, 0x01020300, 0x01000100, 0x05000100, 11, 0x0aaa0555 },
     7354+               { 200000000, 100000000, 0x0303, 0x02010000, 0x02040001, 0x02010000, 0x06000001, 11, 0x0aaa0555 },
     7355+               { 211200000, 105600000, 0x0902, 0x01000200, 0x01030400, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
     7356+               { 220800000, 110400000, 0x1500, 0x01000200, 0x01030400, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
     7357+               { 230400000, 115200000, 0x0604, 0x01000200, 0x01020600, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
     7358+               { 234000000, 104000000, 0x0b01, 0x01010000, 0x01010700, 0x01020600, 0x05000100,  8, 0x012a00a9 },
     7359+               { 240000000, 120000000, 0x0803, 0x01000200, 0x01020600, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
     7360+               { 252000000, 126000000, 0x0504, 0x01000100, 0x01020500, 0x01000100, 0x05000100, 11, 0x0aaa0555 },
     7361+               { 264000000, 132000000, 0x0903, 0x01000200, 0x01020700, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
     7362+               { 270000000, 120000000, 0x0703, 0x01010000, 0x01030400, 0x01020600, 0x05000100,  8, 0x012a00a9 },
     7363+               { 276000000, 122666666, 0x1500, 0x01010000, 0x01030400, 0x01020600, 0x05000100,  8, 0x012a00a9 },
     7364+               { 280000000, 140000000, 0x0503, 0x01000000, 0x01010600, 0x01000000, 0x05000000, 11, 0x0aaa0555 },
     7365+               { 288000000, 128000000, 0x0604, 0x01010000, 0x01030400, 0x01020600, 0x05000100,  8, 0x012a00a9 },
     7366+               { 288000000, 144000000, 0x0404, 0x01000000, 0x01010600, 0x01000000, 0x05000000, 11, 0x0aaa0555 },
     7367+               { 300000000, 133333333, 0x0803, 0x01010000, 0x01020600, 0x01020600, 0x05000100,  8, 0x012a00a9 },
     7368+               { 300000000, 150000000, 0x0803, 0x01000100, 0x01020600, 0x01000100, 0x05000100, 11, 0x0aaa0555 }
    106087369+       };
     7370+
    106097371+       static n4m_table_t BCMINITDATA(type4_table)[] = {
    10610 +               { 120000000, 60000000, 0x0009, 0x11020009, 0x01030203, 0x11020009, 0x04000009, 11,
    10611 +               0x0aaa0555 },
    10612 +               { 150000000, 75000000, 0x0009, 0x11050002, 0x01030203, 0x11050002, 0x04000005, 11,
    10613 +               0x0aaa0555 },
    10614 +               { 192000000, 96000000, 0x0702, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11,
    10615 +               0x0aaa0555 },
    10616 +               { 198000000, 99000000, 0x0603, 0x11020005, 0x11030011, 0x11020005, 0x04000005, 11,
    10617 +               0x0aaa0555 },
    10618 +               { 200000000, 100000000, 0x0009, 0x04020011, 0x11030011, 0x04020011, 0x04020003, 11,
    10619 +               0x0aaa0555 },
    10620 +               { 204000000, 102000000, 0x0c02, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11,
    10621 +               0x0aaa0555 },
    10622 +               { 208000000, 104000000, 0x0802, 0x11030002, 0x11090005, 0x11030002, 0x04000003, 11,
    10623 +               0x0aaa0555 },
    10624 +               { 210000000, 105000000, 0x0209, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11,
    10625 +               0x0aaa0555 },
    10626 +               { 216000000, 108000000, 0x0111, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11,
    10627 +               0x0aaa0555 },
    10628 +               { 224000000, 112000000, 0x0205, 0x11030002, 0x02002103, 0x11030002, 0x04000003, 11,
    10629 +               0x0aaa0555 },
    10630 +               { 228000000, 101333333, 0x0e02, 0x11030003, 0x11210005, 0x01030305, 0x04000005, 8,
    10631 +               0x012a00a9 },
    10632 +               { 228000000, 114000000, 0x0e02, 0x11020005, 0x11210005, 0x11020005, 0x04000005, 11,
    10633 +               0x0aaa0555 },
    10634 +               { 240000000, 102857143, 0x0109, 0x04000021, 0x01050203, 0x11030021, 0x04000003, 13,
    10635 +               0x254a14a9 },
    10636 +               { 240000000, 120000000, 0x0109, 0x11030002, 0x01050203, 0x11030002, 0x04000003, 11,
    10637 +               0x0aaa0555 },
    10638 +               { 252000000, 100800000, 0x0203, 0x04000009, 0x11050005, 0x02000209, 0x04000002, 9,
    10639 +               0x02520129 },
    10640 +               { 252000000, 126000000, 0x0203, 0x04000005, 0x11050005, 0x04000005, 0x04000002, 11,
    10641 +               0x0aaa0555 },
    10642 +               { 264000000, 132000000, 0x0602, 0x04000005, 0x11050005, 0x04000005, 0x04000002, 11,
    10643 +               0x0aaa0555 },
    10644 +               { 272000000, 116571428, 0x0c02, 0x04000021, 0x02000909, 0x02000221, 0x04000003, 13,
    10645 +               0x254a14a9 },
    10646 +               { 280000000, 120000000, 0x0209, 0x04000021, 0x01030303, 0x02000221, 0x04000003, 13,
    10647 +               0x254a14a9 },
    10648 +               { 288000000, 123428571, 0x0111, 0x04000021, 0x01030303, 0x02000221, 0x04000003, 13,
    10649 +               0x254a14a9 },
    10650 +               { 300000000, 120000000, 0x0009, 0x04000009, 0x01030203, 0x02000902, 0x04000002, 9,
    10651 +               0x02520129 },
    10652 +               { 300000000, 150000000, 0x0009, 0x04000005, 0x01030203, 0x04000005, 0x04000002, 11,
    10653 +               0x0aaa0555 }
     7372+               { 192000000,  96000000, 0x0702, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11, 0x0aaa0555 },
     7373+               { 198000000,  99000000, 0x0603, 0x11020005, 0x11030011, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7374+               { 200000000, 100000000, 0x0009, 0x04020011, 0x11030011, 0x04020011, 0x04020003, 11, 0x0aaa0555 },
     7375+               { 204000000, 102000000, 0x0c02, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7376+               { 208000000, 104000000, 0x0802, 0x11030002, 0x11090005, 0x11030002, 0x04000003, 11, 0x0aaa0555 },
     7377+               { 210000000, 105000000, 0x0209, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7378+               { 216000000, 108000000, 0x0111, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7379+               { 224000000, 112000000, 0x0205, 0x11030002, 0x02002103, 0x11030002, 0x04000003, 11, 0x0aaa0555 },
     7380+               { 228000000, 101333333, 0x0e02, 0x11030003, 0x11210005, 0x01030305, 0x04000005,  8, 0x012a00a9 },
     7381+               { 228000000, 114000000, 0x0e02, 0x11020005, 0x11210005, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7382+               { 240000000, 102857143, 0x0109, 0x04000021, 0x01050203, 0x11030021, 0x04000003, 13, 0x254a14a9 },
     7383+               { 240000000, 120000000, 0x0109, 0x11030002, 0x01050203, 0x11030002, 0x04000003, 11, 0x0aaa0555 },
     7384+               { 252000000, 100800000, 0x0203, 0x04000009, 0x11050005, 0x02000209, 0x04000002,  9, 0x02520129 },
     7385+               { 252000000, 126000000, 0x0203, 0x04000005, 0x11050005, 0x04000005, 0x04000002, 11, 0x0aaa0555 },
     7386+               { 264000000, 132000000, 0x0602, 0x04000005, 0x11050005, 0x04000005, 0x04000002, 11, 0x0aaa0555 },
     7387+               { 272000000, 116571428, 0x0c02, 0x04000021, 0x02000909, 0x02000221, 0x04000003, 13, 0x254a14a9 },
     7388+               { 280000000, 120000000, 0x0209, 0x04000021, 0x01030303, 0x02000221, 0x04000003, 13, 0x254a14a9 },
     7389+               { 288000000, 123428571, 0x0111, 0x04000021, 0x01030303, 0x02000221, 0x04000003, 13, 0x254a14a9 },
     7390+               { 300000000, 120000000, 0x0009, 0x04000009, 0x01030203, 0x02000902, 0x04000002,  9, 0x02520129 },
     7391+               { 300000000, 150000000, 0x0009, 0x04000005, 0x01030203, 0x04000005, 0x04000002, 11, 0x0aaa0555 }
    106547392+       };
     7393+
    106557394+       static n4m_table_t BCMINITDATA(type7_table)[] = {
    10656 +               { 183333333, 91666666, 0x0605, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11,
    10657 +               0x0aaa0555 },
    10658 +               { 187500000, 93750000, 0x0a03, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11,
    10659 +               0x0aaa0555 },
    10660 +               { 196875000, 98437500, 0x1003, 0x11020005, 0x11050011, 0x11020005, 0x04000005, 11,
    10661 +               0x0aaa0555 },
    10662 +               { 200000000, 100000000, 0x0311, 0x04000011, 0x11030011, 0x04000009, 0x04000003, 11,
    10663 +               0x0aaa0555 },
    10664 +               { 200000000, 100000000, 0x0311, 0x04020011, 0x11030011, 0x04020011, 0x04020003, 11,
    10665 +               0x0aaa0555 },
    10666 +               { 206250000, 103125000, 0x1103, 0x11020005, 0x11050011, 0x11020005, 0x04000005, 11,
    10667 +               0x0aaa0555 },
    10668 +               { 212500000, 106250000, 0x0c05, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11,
    10669 +               0x0aaa0555 },
    10670 +               { 215625000, 107812500, 0x1203, 0x11090009, 0x11050005, 0x11020005, 0x04000005, 11,
    10671 +               0x0aaa0555 },
    10672 +               { 216666666, 108333333, 0x0805, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11,
    10673 +               0x0aaa0555 },
    10674 +               { 225000000, 112500000, 0x0d03, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11,
    10675 +               0x0aaa0555 },
    10676 +               { 233333333, 116666666, 0x0905, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11,
    10677 +               0x0aaa0555 },
    10678 +               { 237500000, 118750000, 0x0e05, 0x11020005, 0x11210005, 0x11020005, 0x04000005, 11,
    10679 +               0x0aaa0555 },
    10680 +               { 240000000, 120000000, 0x0b11, 0x11020009, 0x11210009, 0x11020009, 0x04000009, 11,
    10681 +               0x0aaa0555 },
    10682 +               { 250000000, 125000000, 0x0f03, 0x11020003, 0x11210003, 0x11020003, 0x04000003, 11,
    10683 +               0x0aaa0555 }
     7395+               { 183333333,  91666666, 0x0605, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11, 0x0aaa0555 },
     7396+               { 187500000,  93750000, 0x0a03, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11, 0x0aaa0555 },
     7397+               { 196875000,  98437500, 0x1003, 0x11020005, 0x11050011, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7398+               { 200000000, 100000000, 0x0311, 0x04000011, 0x11030011, 0x04000009, 0x04000003, 11, 0x0aaa0555 },
     7399+               { 200000000, 100000000, 0x0311, 0x04020011, 0x11030011, 0x04020011, 0x04020003, 11, 0x0aaa0555 },
     7400+               { 206250000, 103125000, 0x1103, 0x11020005, 0x11050011, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7401+               { 212500000, 106250000, 0x0c05, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7402+               { 215625000, 107812500, 0x1203, 0x11090009, 0x11050005, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7403+               { 216666666, 108333333, 0x0805, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11, 0x0aaa0555 },
     7404+               { 225000000, 112500000, 0x0d03, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11, 0x0aaa0555 },
     7405+               { 233333333, 116666666, 0x0905, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11, 0x0aaa0555 },
     7406+               { 237500000, 118750000, 0x0e05, 0x11020005, 0x11210005, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
     7407+               { 240000000, 120000000, 0x0b11, 0x11020009, 0x11210009, 0x11020009, 0x04000009, 11, 0x0aaa0555 },
     7408+               { 250000000, 125000000, 0x0f03, 0x11020003, 0x11210003, 0x11020003, 0x04000003, 11, 0x0aaa0555 }
    106847409+       };
    106857410+
    106867411+       ulong start, end, dst;
    106877412+       bool ret = FALSE;
    10688 +
    10689 +       volatile uint32 *dll_ctrl = (volatile uint32 *)0xff400008;
    10690 +       volatile uint32 *dll_r1 = (volatile uint32 *)0xff400010;
    10691 +       volatile uint32 *dll_r2 = (volatile uint32 *)0xff400018;
    10692 +
     7413+       
    106937414+       /* get index of the current core */
    106947415+       idx = sb_coreidx(sbh);
     
    107037424+               clockcontrol_m2 = &cc->clockcontrol_m2;
    107047425+       } else if ((cc = (chipcregs_t *) sb_setcore(sbh, SB_CC, 0))) {
    10705 +               pll_type = R_REG(osh, &cc->capabilities) & CAP_PLL_MASK;
     7426+               pll_type = R_REG(&cc->capabilities) & CAP_PLL_MASK;
    107067427+               if (pll_type == PLL_TYPE6) {
    107077428+                       clockcontrol_n = NULL;
     
    107127433+                       clockcontrol_sb = &cc->clockcontrol_sb;
    107137434+                       clockcontrol_pci = &cc->clockcontrol_pci;
    10714 +                       clockcontrol_m2 = &cc->clockcontrol_m2;
     7435+               clockcontrol_m2 = &cc->clockcontrol_m2;
    107157436+               }
    107167437+       } else
     
    107227443+       } else {
    107237444+               /* Store the current clock register values */
    10724 +               orig_n = R_REG(osh, clockcontrol_n);
    10725 +               orig_sb = R_REG(osh, clockcontrol_sb);
    10726 +               orig_pci = R_REG(osh, clockcontrol_pci);
     7445+               orig_n = R_REG(clockcontrol_n);
     7446+               orig_sb = R_REG(clockcontrol_sb);
     7447+               orig_pci = R_REG(clockcontrol_pci);
    107277448+       }
    107287449+
     
    107307451+               /* Keep the current PCI clock if not specified */
    107317452+               if (pciclock == 0) {
    10732 +                       pciclock = sb_clock_rate(pll_type, R_REG(osh, clockcontrol_n),
    10733 +                                                R_REG(osh, clockcontrol_pci));
     7453+                       pciclock = sb_clock_rate(pll_type, R_REG(clockcontrol_n), R_REG(clockcontrol_pci));
    107347454+                       pciclock = (pciclock <= 25000000) ? 25000000 : 33000000;
    107357455+               }
    107367456+
    107377457+               /* Search for the closest MIPS clock less than or equal to a preferred value */
    10738 +               for (i = 0; i < ARRAYSIZE(type1_table); i++) {
    10739 +                       ASSERT(type1_table[i].mipsclock ==
    10740 +                              sb_clock_rate(pll_type, type1_table[i].n,
    10741 +                              type1_table[i].sb));
    10742 +                       if (type1_table[i].mipsclock > mipsclock)
     7458+               for (i = 0; i < ARRAYSIZE(BCMINIT(type1_table)); i++) {
     7459+                       ASSERT(BCMINIT(type1_table)[i].mipsclock ==
     7460+                              sb_clock_rate(pll_type, BCMINIT(type1_table)[i].n, BCMINIT(type1_table)[i].sb));
     7461+                       if (BCMINIT(type1_table)[i].mipsclock > mipsclock)
    107437462+                               break;
    107447463+               }
     
    107507469+                       i--;
    107517470+               }
    10752 +               ASSERT(type1_table[i].mipsclock <= mipsclock);
     7471+               ASSERT(BCMINIT(type1_table)[i].mipsclock <= mipsclock);
    107537472+
    107547473+               /* No PLL change */
    10755 +               if ((orig_n == type1_table[i].n) &&
    10756 +                   (orig_sb == type1_table[i].sb) &&
    10757 +                   (orig_pci == type1_table[i].pci33))
     7474+               if ((orig_n == BCMINIT(type1_table)[i].n) &&
     7475+                   (orig_sb == BCMINIT(type1_table)[i].sb) &&
     7476+                   (orig_pci == BCMINIT(type1_table)[i].pci33))
    107587477+                       goto done;
    107597478+
    107607479+               /* Set the PLL controls */
    10761 +               W_REG(osh, clockcontrol_n, type1_table[i].n);
    10762 +               W_REG(osh, clockcontrol_sb, type1_table[i].sb);
     7480+               W_REG(clockcontrol_n, BCMINIT(type1_table)[i].n);
     7481+               W_REG(clockcontrol_sb, BCMINIT(type1_table)[i].sb);
    107637482+               if (pciclock == 25000000)
    10764 +                       W_REG(osh, clockcontrol_pci, type1_table[i].pci25);
     7483+                       W_REG(clockcontrol_pci, BCMINIT(type1_table)[i].pci25);
    107657484+               else
    10766 +                       W_REG(osh, clockcontrol_pci, type1_table[i].pci33);
     7485+                       W_REG(clockcontrol_pci, BCMINIT(type1_table)[i].pci33);
     7486+
     7487+               /* Reset */
     7488+               sb_watchdog(sbh, 1);
     7489+
     7490+               while (1);
     7491+       } else if ((pll_type == PLL_TYPE3) &&
     7492+                  (BCMINIT(sb_chip)(sbh) != BCM5365_DEVICE_ID)) {
     7493+               /* 5350 */
     7494+               /* Search for the closest MIPS clock less than or equal to a preferred value */
     7495+
     7496+               for (i = 0; i < ARRAYSIZE(type3_table); i++) {
     7497+                       if (type3_table[i].mipsclock > mipsclock)
     7498+                               break;
     7499+               }
     7500+               if (i == 0) {
     7501+                       ret = FALSE;
     7502+                       goto done;
     7503+               } else {
     7504+                       ret = TRUE;
     7505+                       i--;
     7506+               }
     7507+               ASSERT(type3_table[i].mipsclock <= mipsclock);
     7508+
     7509+               /* No PLL change */
     7510+               orig_m2 = R_REG(&cc->clockcontrol_m2);
     7511+               if ((orig_n == type3_table[i].n) &&
     7512+                   (orig_m2 == type3_table[i].m2))  {
     7513+                       goto done;
     7514+               }
     7515+               
     7516+               /* Set the PLL controls */
     7517+               W_REG(clockcontrol_n, type3_table[i].n);
     7518+               W_REG(clockcontrol_m2, type3_table[i].m2);
    107677519+
    107687520+               /* Reset */
    107697521+               sb_watchdog(sbh, 1);
    107707522+               while (1);
    10771 +       } else if (pll_type == PLL_TYPE3) {
    10772 +               /* 5350 */
    10773 +               if (sb_chip(sbh) != BCM5365_CHIP_ID) {
    10774 +                       /*
    10775 +                        * Search for the closest MIPS clock less than or equal to
    10776 +                        * a preferred value.
    10777 +                        */
    10778 +                       for (i = 0; i < ARRAYSIZE(type3_table); i++) {
    10779 +                               if (type3_table[i].mipsclock > mipsclock)
    10780 +                                       break;
    10781 +                       }
    10782 +                       if (i == 0) {
    10783 +                               ret = FALSE;
    10784 +                               goto done;
    10785 +                       } else {
    10786 +                               ret = TRUE;
    10787 +                               i--;
    10788 +                       }
    10789 +                       ASSERT(type3_table[i].mipsclock <= mipsclock);
    10790 +
    10791 +                       /* No PLL change */
    10792 +                       orig_m2 = R_REG(osh, &cc->clockcontrol_m2);
    10793 +                       if ((orig_n == type3_table[i].n) &&
    10794 +                           (orig_m2 == type3_table[i].m2)) {
    10795 +                               goto done;
    10796 +                       }
    10797 +
    10798 +                       /* Set the PLL controls */
    10799 +                       W_REG(osh, clockcontrol_n, type3_table[i].n);
    10800 +                       W_REG(osh, clockcontrol_m2, type3_table[i].m2);
    10801 +
    10802 +                       /* Reset */
    10803 +                       sb_watchdog(sbh, 1);
    10804 +                       while (1);
    10805 +               }
    108067523+       } else if ((pll_type == PLL_TYPE2) ||
    10807 +                  (pll_type == PLL_TYPE4) ||
    10808 +                  (pll_type == PLL_TYPE6) ||
    10809 +                  (pll_type == PLL_TYPE7)) {
     7524+                  (pll_type == PLL_TYPE4) ||
     7525+                  (pll_type == PLL_TYPE6) ||
     7526+                  (pll_type == PLL_TYPE7)) {
    108107527+               n4m_table_t *table = NULL, *te;
    108117528+               uint tabsz = 0;
     
    108137530+               ASSERT(cc);
    108147531+
    10815 +               orig_mips = R_REG(osh, &cc->clockcontrol_m3);
    10816 +
    10817 +               switch (pll_type) {
    10818 +               case PLL_TYPE6: {
     7532+               orig_mips = R_REG(&cc->clockcontrol_mips);
     7533+
     7534+               if (pll_type == PLL_TYPE6) {
    108197535+                       uint32 new_mips = 0;
    108207536+
     
    108267542+                               goto done;
    108277543+
    10828 +                       W_REG(osh, &cc->clockcontrol_m3, new_mips);
     7544+                       W_REG(&cc->clockcontrol_mips, new_mips);
    108297545+                       goto end_fill;
    108307546+               }
    10831 +               case PLL_TYPE2:
    10832 +                       table = type2_table;
    10833 +                       tabsz = ARRAYSIZE(type2_table);
    10834 +                       break;
    10835 +               case PLL_TYPE4:
    10836 +                       table = type4_table;
    10837 +                       tabsz = ARRAYSIZE(type4_table);
    10838 +                       break;
    10839 +               case PLL_TYPE7:
    10840 +                       table = type7_table;
    10841 +                       tabsz = ARRAYSIZE(type7_table);
    10842 +                       break;
    10843 +               default:
    10844 +                       ASSERT("No table for plltype" == NULL);
    10845 +                       break;
    10846 +               }
     7547+
     7548+               if (pll_type == PLL_TYPE2) {
     7549+                       table = BCMINIT(type2_table);
     7550+                       tabsz = ARRAYSIZE(BCMINIT(type2_table));
     7551+               } else if (pll_type == PLL_TYPE4) {
     7552+                       table = BCMINIT(type4_table);
     7553+                       tabsz = ARRAYSIZE(BCMINIT(type4_table));
     7554+               } else if (pll_type == PLL_TYPE7) {
     7555+                       table = BCMINIT(type7_table);
     7556+                       tabsz = ARRAYSIZE(BCMINIT(type7_table));
     7557+               } else
     7558+                       ASSERT((char *)"No table for plltype" == NULL);
    108477559+
    108487560+               /* Store the current clock register values */
    10849 +               orig_m2 = R_REG(osh, &cc->clockcontrol_m2);
     7561+               orig_m2 = R_REG(&cc->clockcontrol_m2);
    108507562+               orig_ratio_parm = 0;
    108517563+               orig_ratio_cfg = 0;
     
    108897601+
    108907602+               /* Set the PLL controls */
    10891 +               W_REG(osh, clockcontrol_n, te->n);
    10892 +               W_REG(osh, clockcontrol_sb, te->sb);
    10893 +               W_REG(osh, clockcontrol_pci, te->pci33);
    10894 +               W_REG(osh, &cc->clockcontrol_m2, te->m2);
    10895 +               W_REG(osh, &cc->clockcontrol_m3, te->m3);
     7603+               W_REG(clockcontrol_n, te->n);
     7604+               W_REG(clockcontrol_sb, te->sb);
     7605+               W_REG(clockcontrol_pci, te->pci33);
     7606+               W_REG(&cc->clockcontrol_m2, te->m2);
     7607+               W_REG(&cc->clockcontrol_mips, te->m3);
    108967608+
    108977609+               /* Set the chipcontrol bit to change mipsref to the backplane divider if needed */
    10898 +               if ((pll_type == PLL_TYPE7) && (te->sb != te->m2) &&
     7610+               if ((pll_type == PLL_TYPE7) &&
     7611+                   (te->sb != te->m2) &&
    108997612+                   (sb_clock_rate(pll_type, te->n, te->m2) == 120000000))
    10900 +                       W_REG(osh, &cc->chipcontrol,
    10901 +                             R_REG(osh, &cc->chipcontrol) | 0x100);
     7613+                       W_REG(&cc->chipcontrol, R_REG(&cc->chipcontrol) | 0x100);
    109027614+
    109037615+               /* No ratio change */
    10904 +               if (sb_chip(sbh) != BCM4785_CHIP_ID) {
    10905 +                       if (orig_ratio_parm == te->ratio_parm)
    10906 +                               goto end_fill;
    10907 +               }
     7616+               if (orig_ratio_parm == te->ratio_parm)
     7617+                       goto end_fill;
     7618+
     7619+               icache_probe(MFC0(C0_CONFIG, 1), &ic_size, &ic_lsize);
    109087620+
    109097621+               /* Preload the code into the cache */
    10910 +               icache_probe(MFC0(C0_CONFIG, 1), &ic_size, &ic_lsize);
    10911 +               if (sb_chip(sbh) == BCM4785_CHIP_ID) {
    10912 +                       start = ((ulong) &&start_fill_4785) & ~(ic_lsize - 1);
    10913 +                       end = ((ulong) &&end_fill_4785 + (ic_lsize - 1)) & ~(ic_lsize - 1);
    10914 +               }
    10915 +               else {
    10916 +                       start = ((ulong) &&start_fill) & ~(ic_lsize - 1);
    10917 +                       end = ((ulong) &&end_fill + (ic_lsize - 1)) & ~(ic_lsize - 1);
    10918 +               }
     7622+               start = ((ulong) &&start_fill) & ~(ic_lsize - 1);
     7623+               end = ((ulong) &&end_fill + (ic_lsize - 1)) & ~(ic_lsize - 1);
    109197624+               while (start < end) {
    10920 +                       cache_op(start, Fill_I);
     7625+                       cache_unroll(start, Fill_I);
    109217626+                       start += ic_lsize;
    109227627+               }
    109237628+
    109247629+               /* Copy the handler */
    10925 +               start = (ulong) &handler;
    10926 +               end = (ulong) &afterhandler;
     7630+               start = (ulong) &BCMINIT(handler);
     7631+               end = (ulong) &BCMINIT(afterhandler);
    109277632+               dst = KSEG1ADDR(0x180);
    109287633+               for (i = 0; i < (end - start); i += 4)
    109297634+                       *((ulong *)(dst + i)) = *((ulong *)(start + i));
    10930 +
    10931 +               /* Preload the handler into the cache one line at a time */
    10932 +               for (i = 0; i < (end - start); i += ic_lsize)
    10933 +                       cache_op(dst + i, Fill_I);
     7635+               
     7636+               /* Preload handler into the cache one line at a time */
     7637+               for (i = 0; i < (end - start); i += 4)
     7638+                       cache_unroll(dst + i, Fill_I);
    109347639+
    109357640+               /* Clear BEV bit */
     
    109397644+               MTC0(C0_STATUS, 0, MFC0(C0_STATUS, 0) | (ALLINTS | ST0_IE));
    109407645+
    10941 +               /* 4785 clock freq change procedures */
    10942 +               if (sb_chip(sbh) == BCM4785_CHIP_ID) {
    10943 +       start_fill_4785:
    10944 +                       /* Switch to async */
    10945 +                       MTC0(C0_BROADCOM, 4, (1 << 22));
    10946 +
    10947 +                       /* Set clock ratio in MIPS */
    10948 +                       *dll_r1 = (*dll_r1 & 0xfffffff0) | (te->d11_r1 - 1);
    10949 +                       *dll_r2 = te->d11_r2;
    10950 +
    10951 +                       /* Enable new settings in MIPS */
    10952 +                       *dll_r1 = *dll_r1 | 0xc0000000;
    10953 +
    10954 +                       /* Set active cfg */
    10955 +                       MTC0(C0_BROADCOM, 2, MFC0(C0_BROADCOM, 2) | (1 << 3) | 1);
    10956 +
    10957 +                       /* Fake soft reset (clock cfg registers not reset) */
    10958 +                       MTC0(C0_BROADCOM, 5, MFC0(C0_BROADCOM, 5) | (1 << 2));
    10959 +
    10960 +                       /* Clear active cfg */
    10961 +                       MTC0(C0_BROADCOM, 2, MFC0(C0_BROADCOM, 2) & ~(1 << 3));
    10962 +
    10963 +                       /* set watchdog timer */
    10964 +                       W_REG(osh, &cc->watchdog, 20);
    10965 +                       (void) R_REG(osh, &cc->chipid);
    10966 +
    10967 +                       /* wait for timer interrupt */
    10968 +                       __asm__ __volatile__(
    10969 +                               ".set\tmips3\n\t"
    10970 +                               "sync\n\t"
    10971 +                               "wait\n\t"
    10972 +                               ".set\tmips0");
    10973 +       end_fill_4785:
    10974 +                       while (1);
    10975 +               }
    10976 +               /* Generic clock freq change procedures */
    10977 +               else {
    10978 +                       /* Enable MIPS timer interrupt */
    10979 +                       if (!(mipsr = sb_setcore(sbh, SB_MIPS, 0)) &&
    10980 +                           !(mipsr = sb_setcore(sbh, SB_MIPS33, 0)))
    10981 +                               ASSERT(mipsr);
    10982 +                       W_REG(osh, &mipsr->intmask, 1);
     7646+               /* Enable MIPS timer interrupt */
     7647+               if (!(mipsr = sb_setcore(sbh, SB_MIPS, 0)) &&
     7648+                   !(mipsr = sb_setcore(sbh, SB_MIPS33, 0)))
     7649+                       ASSERT(mipsr);
     7650+               W_REG(&mipsr->intmask, 1);
    109837651+
    109847652+       start_fill:
    10985 +                       /* step 1, set clock ratios */
    10986 +                       MTC0(C0_BROADCOM, 3, te->ratio_parm);
    10987 +                       MTC0(C0_BROADCOM, 1, te->ratio_cfg);
    10988 +
    10989 +                       /* step 2: program timer intr */
    10990 +                       W_REG(osh, &mipsr->timer, 100);
    10991 +                       (void) R_REG(osh, &mipsr->timer);
    10992 +
    10993 +                       /* step 3, switch to async */
    10994 +                       sync_mode = MFC0(C0_BROADCOM, 4);
    10995 +                       MTC0(C0_BROADCOM, 4, 1 << 22);
    10996 +
    10997 +                       /* step 4, set cfg active */
    10998 +                       MTC0(C0_BROADCOM, 2, (1 << 3) | 1);
    10999 +
    11000 +                       /* steps 5 & 6 */
    11001 +                       __asm__ __volatile__(
    11002 +                               ".set\tmips3\n\t"
    11003 +                               "wait\n\t"
    11004 +                               ".set\tmips0");
    11005 +
    11006 +                       /* step 7, clear cfg active */
    11007 +                       MTC0(C0_BROADCOM, 2, 0);
    11008 +
    11009 +                       /* Additional Step: set back to orig sync mode */
    11010 +                       MTC0(C0_BROADCOM, 4, sync_mode);
    11011 +
    11012 +                       /* step 8, fake soft reset */
    11013 +                       MTC0(C0_BROADCOM, 5, MFC0(C0_BROADCOM, 5) | (1 << 2));
     7653+               /* step 1, set clock ratios */
     7654+               MTC0(C0_BROADCOM, 3, te->ratio_parm);
     7655+               MTC0(C0_BROADCOM, 1, te->ratio_cfg);
     7656+
     7657+               /* step 2: program timer intr */
     7658+               W_REG(&mipsr->timer, 100);
     7659+               (void) R_REG(&mipsr->timer);
     7660+
     7661+               /* step 3, switch to async */
     7662+               sync_mode = MFC0(C0_BROADCOM, 4);
     7663+               MTC0(C0_BROADCOM, 4, 1 << 22);
     7664+
     7665+               /* step 4, set cfg active */
     7666+               MTC0(C0_BROADCOM, 2, 0x9);
     7667+
     7668+
     7669+               /* steps 5 & 6 */
     7670+               __asm__ __volatile__ (
     7671+                       ".set\tmips3\n\t"
     7672+                       "wait\n\t"
     7673+                       ".set\tmips0"
     7674+               );
     7675+
     7676+               /* step 7, clear cfg_active */
     7677+               MTC0(C0_BROADCOM, 2, 0);
     7678+               
     7679+               /* Additional Step: set back to orig sync mode */
     7680+               MTC0(C0_BROADCOM, 4, sync_mode);
     7681+
     7682+               /* step 8, fake soft reset */
     7683+               MTC0(C0_BROADCOM, 5, MFC0(C0_BROADCOM, 5) | 4);
    110147684+
    110157685+       end_fill:
    11016 +                       /* set watchdog timer */
    11017 +                       W_REG(osh, &cc->watchdog, 20);
    11018 +                       (void) R_REG(osh, &cc->chipid);
    11019 +
    11020 +                       /* wait for timer interrupt */
    11021 +                       __asm__ __volatile__(
    11022 +                               ".set\tmips3\n\t"
    11023 +                               "sync\n\t"
    11024 +                               "wait\n\t"
    11025 +                               ".set\tmips0");
    11026 +                       while (1);
    11027 +               }
     7686+               /* step 9 set watchdog timer */
     7687+               sb_watchdog(sbh, 20);
     7688+               (void) R_REG(&cc->chipid);
     7689+
     7690+               /* step 11 */
     7691+               __asm__ __volatile__ (
     7692+                       ".set\tmips3\n\t"
     7693+                       "sync\n\t"
     7694+                       "wait\n\t"
     7695+                       ".set\tmips0"
     7696+               );
     7697+               while (1);
    110287698+       }
    110297699+
    110307700+done:
    11031 +       /* Enable 4785 DLL */
    11032 +       if (sb_chip(sbh) == BCM4785_CHIP_ID) {
    11033 +               uint32 tmp;
    11034 +
    11035 +               /* set mask to 1e, enable DLL (bit 0) */
    11036 +               *dll_ctrl |= 0x0041e021;
    11037 +
    11038 +               /* enable aggressive hardware mode */
    11039 +               *dll_ctrl |= 0x00000080;
    11040 +
    11041 +               /* wait for lock flag to clear */
    11042 +               while ((*dll_ctrl & 0x2) == 0);
    11043 +
    11044 +               /* clear sticky flags (clear on write 1) */
    11045 +               tmp = *dll_ctrl;
    11046 +               *dll_ctrl = tmp;
    11047 +
    11048 +               /* set mask to 5b'10001 */
    11049 +               *dll_ctrl = (*dll_ctrl & 0xfffc1fff) | 0x00022000;
    11050 +
    11051 +               /* enable sync mode */
    11052 +               MTC0(C0_BROADCOM, 4, MFC0(C0_BROADCOM, 4) & 0xfe3fffff);
    11053 +               (void)MFC0(C0_BROADCOM, 4);
    11054 +       }
    11055 +
    110567701+       /* switch back to previous core */
    110577702+       sb_setcoreidx(sbh, idx);
     
    110607705+}
    110617706+
    11062 +void
    11063 +BCMINITFN(enable_pfc)(uint32 mode)
    11064 +{
    11065 +       ulong start, end;
    11066 +       uint ic_size, ic_lsize;
    11067 +
    11068 +       /* If auto then choose the correct mode for this
    11069 +        * platform, currently we only ever select one mode
    11070 +        */
    11071 +       if (mode == PFC_AUTO)
    11072 +               mode = PFC_INST;
    11073 +
    11074 +       icache_probe(MFC0(C0_CONFIG, 1), &ic_size, &ic_lsize);
    11075 +
    11076 +       /* enable prefetch cache if available */
    11077 +       if (MFC0(C0_BROADCOM, 0) & BRCM_PFC_AVAIL) {
    11078 +               start = ((ulong) &&setpfc_start) & ~(ic_lsize - 1);
    11079 +               end = ((ulong) &&setpfc_end + (ic_lsize - 1)) & ~(ic_lsize - 1);
    11080 +
    11081 +               /* Preload setpfc code into the cache one line at a time */
    11082 +               while (start < end) {
    11083 +                       cache_op(start, Fill_I);
    11084 +                       start += ic_lsize;
    11085 +               }
    11086 +
    11087 +               /* Now set the pfc */
    11088 +       setpfc_start:
    11089 +               /* write range */
    11090 +               *(volatile uint32 *)PFC_CR1 = 0xffff0000;
    11091 +
    11092 +               /* enable */
    11093 +               *(volatile uint32 *)PFC_CR0 = mode;
    11094 +       setpfc_end:
    11095 +               /* Compiler foder */
    11096 +               ic_size = 0;
    11097 +       }
    11098 +}
    110997707+
    111007708+/* returns the ncdl value to be programmed into sdram_ncdl for calibration */
    111017709+uint32
    11102 +BCMINITFN(sb_memc_get_ncdl)(sb_t *sbh)
    11103 +{
    11104 +       osl_t *osh;
     7710+BCMINITFN(sb_memc_get_ncdl)(void *sbh)
     7711+{
    111057712+       sbmemcregs_t *memc;
    111067713+       uint32 ret = 0;
     
    111087715+       uint idx, rev;
    111097716+
    11110 +       osh = sb_osh(sbh);
    11111 +
    111127717+       idx = sb_coreidx(sbh);
    111137718+
     
    111187723+       rev = sb_corerev(sbh);
    111197724+
    11120 +       config = R_REG(osh, &memc->config);
    11121 +       wr = R_REG(osh, &memc->wrncdlcor);
    11122 +       rd = R_REG(osh, &memc->rdncdlcor);
    11123 +       misc = R_REG(osh, &memc->miscdlyctl);
    11124 +       dqsg = R_REG(osh, &memc->dqsgatencdl);
     7725+       config = R_REG(&memc->config);
     7726+       wr = R_REG(&memc->wrncdlcor);
     7727+       rd = R_REG(&memc->rdncdlcor);
     7728+       misc = R_REG(&memc->miscdlyctl);
     7729+       dqsg = R_REG(&memc->dqsgatencdl);
    111257730+
    111267731+       rd &= MEMC_RDNCDLCOR_RD_MASK;
    11127 +       wr &= MEMC_WRNCDLCOR_WR_MASK;
     7732+       wr &= MEMC_WRNCDLCOR_WR_MASK; 
    111287733+       dqsg &= MEMC_DQSGATENCDL_G_MASK;
    111297734+
     
    111317736+               ret = (wr << 16) | (rd << 8) | dqsg;
    111327737+       } else {
    11133 +               if (rev > 0)
     7738+               if ((rev > 0) || (sb_chip(sbh) == BCM5365_DEVICE_ID))
    111347739+                       cd = rd;
    111357740+               else
     
    111477752+}
    111487753+
    11149 +#if defined(BCMPERFSTATS)
    11150 +/*
    11151 + * CP0 Register 25 supports 4 semi-independent 32bit performance counters.
    11152 + * $25 select 0, 1, 2, and 3 are the counters.  The counters *decrement* (who thought this one up?)
    11153 + * $25 select 4 and 5 each contain 2-16bit control fields, one for each of the 4 counters
    11154 + * $25 select 6 is the global perf control register.
    11155 + */
    11156 +/* enable and start instruction counting */
    11157 +
    11158 +void
    11159 +hndmips_perf_instrcount_enable()
    11160 +{
    11161 +       MTC0(C0_PERFORMANCE, 6, 0x80000200);    /* global enable perf counters */
    11162 +       MTC0(C0_PERFORMANCE, 4,
    11163 +            0x8044 | MFC0(C0_PERFORMANCE, 4)); /* enable instruction counting for counter 0 */
    11164 +       MTC0(C0_PERFORMANCE, 0, 0);             /* zero counter zero */
    11165 +}
    11166 +
    11167 +/* enable and start I$ hit and I$ miss counting */
    11168 +void
    11169 +hndmips_perf_icachecount_enable(void)
    11170 +{
    11171 +       MTC0(C0_PERFORMANCE, 6, 0x80000218);    /* enable I$ counting */
    11172 +       MTC0(C0_PERFORMANCE, 4, 0x80148018);    /* count I$ hits in cntr 0 and misses in cntr 1 */
    11173 +       MTC0(C0_PERFORMANCE, 0, 0);             /* zero counter 0 - # I$ hits */
    11174 +       MTC0(C0_PERFORMANCE, 1, 0);             /* zero counter 1 - # I$ misses */
    11175 +}
    11176 +
    11177 +/* enable and start D$ hit and I$ miss counting */
    11178 +void
    11179 +hndmips_perf_dcachecount_enable(void)
    11180 +{
    11181 +       MTC0(C0_PERFORMANCE, 6, 0x80000211);    /* enable D$ counting */
    11182 +       MTC0(C0_PERFORMANCE, 4, 0x80248028);    /* count D$ hits in cntr 0 and misses in cntr 1 */
    11183 +       MTC0(C0_PERFORMANCE, 0, 0);             /* zero counter 0 - # D$ hits */
    11184 +       MTC0(C0_PERFORMANCE, 1, 0);             /* zero counter 1 - # D$ misses */
    11185 +}
    11186 +
    11187 +void
    11188 +hndmips_perf_icache_miss_enable()
    11189 +{
    11190 +       MTC0(C0_PERFORMANCE, 4,
    11191 +            0x80140000 | MFC0(C0_PERFORMANCE, 4)); /* enable cache misses counting for counter 1 */
    11192 +       MTC0(C0_PERFORMANCE, 1, 0); /* zero counter one */
    11193 +}
    11194 +
    11195 +
    11196 +void
    11197 +hndmips_perf_icache_hit_enable()
    11198 +{
    11199 +       MTC0(C0_PERFORMANCE, 5, 0x8018 | MFC0(C0_PERFORMANCE, 5));
    11200 +       /* enable cache hits counting for counter 2 */
    11201 +       MTC0(C0_PERFORMANCE, 2, 0);             /* zero counter 2 */
    11202 +}
     7754+/* returns the PFC values to be used based on the chip ID*/
    112037755+
    112047756+uint32
    11205 +hndmips_perf_read_instrcount()
    11206 +{
    11207 +       return -(long)(MFC0(C0_PERFORMANCE, 0));
    11208 +}
    11209 +
    11210 +uint32
    11211 +hndmips_perf_read_cache_miss()
    11212 +{
    11213 +       return -(long)(MFC0(C0_PERFORMANCE, 1));
    11214 +}
    11215 +
    11216 +uint32
    11217 +hndmips_perf_read_cache_hit()
    11218 +{
    11219 +       return -(long)(MFC0(C0_PERFORMANCE, 2));
    11220 +}
    11221 +
    11222 +#endif /* BCMINTERNAL | BCMPERFSTATS */
    11223 diff -urN linux.old/arch/mips/bcm947xx/sbpci.c linux.dev/arch/mips/bcm947xx/sbpci.c
    11224 --- linux.old/arch/mips/bcm947xx/sbpci.c        1970-01-01 01:00:00.000000000 +0100
    11225 +++ linux.dev/arch/mips/bcm947xx/sbpci.c        2006-05-02 17:37:13.000000000 +0200
    11226 @@ -0,0 +1,768 @@
     7757+BCMINITFN(sb_mips_get_pfc)(void *sbh)
     7758+{
     7759+       if (BCMINIT(sb_chip)(sbh) == BCM5350_DEVICE_ID)
     7760+               return 0x11;
     7761+       else
     7762+               return 0x15;
     7763+}
     7764diff -Nur linux-2.4.32/arch/mips/bcm947xx/sbpci.c linux-2.4.32-freewrt/arch/mips/bcm947xx/sbpci.c
     7765--- linux-2.4.32/arch/mips/bcm947xx/sbpci.c     1970-01-01 01:00:00.000000000 +0100
     7766+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/sbpci.c     2006-07-02 21:58:25.000000000 +0200
     7767@@ -0,0 +1,588 @@
    112277768+/*
    112287769+ * Low-Level PCI and SB support for BCM47xx
    112297770+ *
    11230 + * Copyright 2006, Broadcom Corporation
     7771+ * Copyright 2005, Broadcom Corporation
    112317772+ * All Rights Reserved.
    112327773+ *
     
    112367777+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    112377778+ *
    11238 + * $Id: hndpci.c,v 1.1.1.3 2006/04/08 06:13:39 honor Exp $
     7779+ * $Id: sbpci.c,v 1.7 2005/03/07 08:35:32 kanki Exp $
    112397780+ */
    112407781+
    112417782+#include <typedefs.h>
    11242 +#include <osl.h>
    112437783+#include <pcicfg.h>
    112447784+#include <bcmdevs.h>
    112457785+#include <sbconfig.h>
     7786+#include <sbpci.h>
     7787+#include <osl.h>
     7788+#include <bcmendian.h>
    112467789+#include <bcmutils.h>
    112477790+#include <sbutils.h>
    11248 +#include <sbpci.h>
    11249 +#include <bcmendian.h>
    112507791+#include <bcmnvram.h>
    11251 +#include <hndcpu.h>
    112527792+#include <hndmips.h>
    11253 +#include <hndpci.h>
    11254 +
    11255 +/* debug/trace */
    11256 +#ifdef BCMDBG_PCI
    11257 +#define        PCI_MSG(args)   printf args
    11258 +#else
    11259 +#define        PCI_MSG(args)
    11260 +#endif /* BCMDBG_PCI */
    112617793+
    112627794+/* Can free sbpci_init() memory after boot */
    112637795+#ifndef linux
    112647796+#define __init
    11265 +#endif /* linux */
     7797+#endif
    112667798+
    112677799+/* Emulated configuration space */
    11268 +typedef struct {
    11269 +       int     n;
    11270 +       uint    size0;
    11271 +       uint    size1;
    11272 +       uint    size2;
    11273 +       uint    size3;
    11274 +} sb_bar_cfg_t;
    112757800+static pci_config_regs sb_config_regs[SB_MAXCORES];
    11276 +static sb_bar_cfg_t sb_bar_cfg[SB_MAXCORES];
    11277 +
    11278 +/* Links to emulated and real PCI configuration spaces */
    11279 +#define MAXFUNCS  2
    11280 +typedef struct {
    11281 +       pci_config_regs *emu;   /* emulated PCI config */
    11282 +       pci_config_regs *pci;   /* real PCI config */
    11283 +       sb_bar_cfg_t *bar;      /* region sizes */
    11284 +} sb_pci_cfg_t;
    11285 +static sb_pci_cfg_t sb_pci_cfg[SB_MAXCORES][MAXFUNCS];
    11286 +
    11287 +/* Special emulated config space for non-existing device */
    11288 +static pci_config_regs sb_pci_null = { 0xffff, 0xffff };
    112897801+
    112907802+/* Banned cores */
    11291 +static uint16 pci_ban[SB_MAXCORES] = { 0 };
     7803+static uint16 pci_ban[32] = { 0 };
    112927804+static uint pci_banned = 0;
    112937805+
     
    112977809+/* Disable PCI host core */
    112987810+static bool pci_disabled = FALSE;
    11299 +
    11300 +/* Host bridge slot #, default to 0 */
    11301 +static uint8 pci_hbslot = 0;
    11302 +
    11303 +/* Internal macros */
    11304 +#define PCI_SLOTAD_MAP 16      /* SLOT<n> mapps to AD<n+16> */
    11305 +#define PCI_HBSBCFG_REV        8       /* MIN. core rev. required to
    11306 +                                * access host bridge PCI cfg space
    11307 +                                * from SB
    11308 +                                */
    113097811+
    113107812+/*
     
    113137815+
    113147816+/* Assume one-hot slot wiring */
    11315 +#define PCI_SLOT_MAX 16        /* Max. PCI Slots */
     7817+#define PCI_SLOT_MAX 16
    113167818+
    113177819+static uint32
    11318 +config_cmd(sb_t *sbh, uint bus, uint dev, uint func, uint off)
     7820+config_cmd(void *sbh, uint bus, uint dev, uint func, uint off)
    113197821+{
    113207822+       uint coreidx;
    113217823+       sbpciregs_t *regs;
    113227824+       uint32 addr = 0;
    11323 +       osl_t *osh;
    113247825+
    113257826+       /* CardBusMode supports only one device */
    113267827+       if (cardbus && dev > 1)
    113277828+               return 0;
    11328 +
    11329 +       osh = sb_osh(sbh);
    113307829+
    113317830+       coreidx = sb_coreidx(sbh);
     
    113367835+               /* Skip unwired slots */
    113377836+               if (dev < PCI_SLOT_MAX) {
    11338 +                       uint32 win;
    11339 +
    113407837+                       /* Slide the PCI window to the appropriate slot */
    11341 +                       win = (SBTOPCI_CFG0 | ((1 << (dev + PCI_SLOTAD_MAP)) & SBTOPCI1_MASK));
    11342 +                       W_REG(osh, &regs->sbtopci1, win);
    11343 +                       addr = SB_PCI_CFG |
    11344 +                               ((1 << (dev + PCI_SLOTAD_MAP)) & ~SBTOPCI1_MASK) |
    11345 +                               (func << PCICFG_FUN_SHIFT) |
    11346 +                               (off & ~3);
     7838+                       W_REG(&regs->sbtopci1, SBTOPCI_CFG0 | ((1 << (dev + 16)) & SBTOPCI1_MASK));
     7839+                       addr = SB_PCI_CFG | ((1 << (dev + 16)) & ~SBTOPCI1_MASK) |
     7840+                               (func << 8) | (off & ~3);
    113477841+               }
    11348 +       } else {
    11349 +               /* Type 1 transaction */
    11350 +               W_REG(osh, &regs->sbtopci1, SBTOPCI_CFG1);
    11351 +               addr = SB_PCI_CFG |
    11352 +                       (bus << PCICFG_BUS_SHIFT) |
    11353 +                       (dev << PCICFG_SLOT_SHIFT) |
    11354 +                       (func << PCICFG_FUN_SHIFT) |
    11355 +                       (off & ~3);
     7842+       }
     7843+
     7844+       /* Type 1 transaction */
     7845+       else {
     7846+               W_REG(&regs->sbtopci1, SBTOPCI_CFG1);
     7847+               addr = SB_PCI_CFG | (bus << 16) | (dev << 11) | (func << 8) | (off & ~3);
    113567848+       }
    113577849+
     
    113617853+}
    113627854+
    11363 +/*
    11364 + * Read host bridge PCI config registers from Silicon Backplane (>=rev8).
    11365 + *
    11366 + * It returns TRUE to indicate that access to the host bridge's pci config
    11367 + * from SB is ok, and values in 'addr' and 'val' are valid.
    11368 + *
    11369 + * It can only read registers at multiple of 4-bytes. Callers must pick up
    11370 + * needed bytes from 'val' based on 'off' value. Value in 'addr' reflects
    11371 + * the register address where value in 'val' is read.
    11372 + */
    11373 +static bool
    11374 +sb_pcihb_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off,
    11375 +                  uint32 **addr, uint32 *val)
    11376 +{
    11377 +       sbpciregs_t *regs;
    11378 +       osl_t *osh;
    11379 +       uint coreidx;
    11380 +       bool ret = FALSE;
    11381 +
    11382 +       /* sanity check */
    11383 +       ASSERT(bus == 1);
    11384 +       ASSERT(dev == pci_hbslot);
    11385 +       ASSERT(func == 0);
    11386 +
    11387 +       osh = sb_osh(sbh);
    11388 +
    11389 +       /* read pci config when core rev >= 8 */
    11390 +       coreidx = sb_coreidx(sbh);
    11391 +       regs = (sbpciregs_t *)sb_setcore(sbh, SB_PCI, 0);
    11392 +       if (regs && sb_corerev(sbh) >= PCI_HBSBCFG_REV) {
    11393 +               *addr = (uint32 *)&regs->pcicfg[func][off >> 2];
    11394 +               *val = R_REG(osh, *addr);
    11395 +               ret = TRUE;
    11396 +       }
    11397 +       sb_setcoreidx(sbh, coreidx);
    11398 +
    11399 +       return ret;
    11400 +}
    11401 +
    11402 +int
    11403 +extpci_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
    11404 +{
    11405 +       uint32 addr = 0, *reg = NULL, val;
     7855+static int
     7856+extpci_read_config(void *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
     7857+{
     7858+       uint32 addr, *reg = NULL, val;
    114067859+       int ret = 0;
    114077860+
    11408 +       /*
    11409 +        * Set value to -1 when:
    11410 +        *      flag 'pci_disabled' is true;
    11411 +        *      value of 'addr' is zero;
    11412 +        *      REG_MAP() fails;
    11413 +        *      BUSPROBE() fails;
    11414 +        */
    11415 +       if (pci_disabled)
     7861+       if (pci_disabled ||
     7862+           !(addr = config_cmd(sbh, bus, dev, func, off)) ||
     7863+           !(reg = (uint32 *) REG_MAP(addr, len)) ||
     7864+           BUSPROBE(val, reg))
    114167865+               val = 0xffffffff;
    11417 +       else if (bus == 1 && dev == pci_hbslot && func == 0 &&
    11418 +                sb_pcihb_read_config(sbh, bus, dev, func, off, &reg, &val))
    11419 +               ;
    11420 +       else if (((addr = config_cmd(sbh, bus, dev, func, off)) == 0) ||
    11421 +                ((reg = (uint32 *)REG_MAP(addr, len)) == 0) ||
    11422 +                (BUSPROBE(val, reg) != 0))
    11423 +               val = 0xffffffff;
    11424 +
    11425 +       PCI_MSG(("%s: 0x%x <= 0x%p(0x%x), len %d, off 0x%x, buf 0x%p\n",
    11426 +              __FUNCTION__, val, reg, addr, len, off, buf));
    114277866+
    114287867+       val >>= 8 * (off & 3);
     
    114367875+               ret = -1;
    114377876+
    11438 +       if (reg && addr)
     7877+       if (reg)
    114397878+               REG_UNMAP(reg);
    114407879+
     
    114427881+}
    114437882+
    11444 +int
    11445 +extpci_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
    11446 +{
    11447 +       osl_t *osh;
    11448 +       uint32 addr = 0, *reg = NULL, val;
     7883+static int
     7884+extpci_write_config(void *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
     7885+{
     7886+       uint32 addr, *reg = NULL, val;
    114497887+       int ret = 0;
    114507888+
    11451 +       osh = sb_osh(sbh);
    11452 +
    11453 +       /*
    11454 +        * Ignore write attempt when:
    11455 +        *      flag 'pci_disabled' is true;
    11456 +        *      value of 'addr' is zero;
    11457 +        *      REG_MAP() fails;
    11458 +        *      BUSPROBE() fails;
    11459 +        */
    11460 +       if (pci_disabled)
    11461 +               return 0;
    11462 +       else if (bus == 1 && dev == pci_hbslot && func == 0 &&
    11463 +                sb_pcihb_read_config(sbh, bus, dev, func, off, &reg, &val))
    11464 +               ;
    11465 +       else if (((addr = config_cmd(sbh, bus, dev, func, off)) == 0) ||
    11466 +                ((reg = (uint32 *) REG_MAP(addr, len)) == 0) ||
    11467 +                (BUSPROBE(val, reg) != 0))
     7889+       if (pci_disabled ||
     7890+           !(addr = config_cmd(sbh, bus, dev, func, off)) ||
     7891+           !(reg = (uint32 *) REG_MAP(addr, len)) ||
     7892+           BUSPROBE(val, reg))
    114687893+               goto done;
    114697894+
     
    114767901+               val &= ~(0xff << (8 * (off & 3)));
    114777902+               val |= *((uint8 *) buf) << (8 * (off & 3));
    11478 +       } else {
     7903+       } else
    114797904+               ret = -1;
    11480 +               goto done;
    11481 +       }
    11482 +
    11483 +       PCI_MSG(("%s: 0x%x => 0x%p\n", __FUNCTION__, val, reg));
    11484 +
    11485 +       W_REG(osh, reg, val);
    11486 +
    11487 +done:
    11488 +       if (reg && addr)
     7905+
     7906+       W_REG(reg, val);
     7907+
     7908+ done:
     7909+       if (reg)
    114897910+               REG_UNMAP(reg);
    114907911+
    114917912+       return ret;
    11492 +}
    11493 +
    11494 +/*
    11495 + * Must access emulated PCI configuration at these locations even when
    11496 + * the real PCI config space exists and is accessible.
    11497 + *
    11498 + * PCI_CFG_VID (0x00)
    11499 + * PCI_CFG_DID (0x02)
    11500 + * PCI_CFG_PROGIF (0x09)
    11501 + * PCI_CFG_SUBCL  (0x0a)
    11502 + * PCI_CFG_BASECL (0x0b)
    11503 + * PCI_CFG_HDR (0x0e)
    11504 + * PCI_CFG_INT (0x3c)
    11505 + * PCI_CFG_PIN (0x3d)
    11506 + */
    11507 +#define FORCE_EMUCFG(off, len) \
    11508 +       ((off == PCI_CFG_VID) || (off == PCI_CFG_DID) || \
    11509 +        (off == PCI_CFG_PROGIF) || \
    11510 +        (off == PCI_CFG_SUBCL) || (off == PCI_CFG_BASECL) || \
    11511 +        (off == PCI_CFG_HDR) || \
    11512 +        (off == PCI_CFG_INT) || (off == PCI_CFG_PIN))
    11513 +
    11514 +/* Sync the emulation registers and the real PCI config registers. */
    11515 +static void
    11516 +sb_pcid_read_config(sb_t *sbh, uint coreidx, sb_pci_cfg_t *cfg,
    11517 +                    uint off, uint len)
    11518 +{
    11519 +       osl_t *osh;
    11520 +       uint oldidx;
    11521 +
    11522 +       ASSERT(cfg);
    11523 +       ASSERT(cfg->emu);
    11524 +       ASSERT(cfg->pci);
    11525 +
    11526 +       /* decide if real PCI config register access is necessary */
    11527 +       if (FORCE_EMUCFG(off, len))
    11528 +               return;
    11529 +
    11530 +       osh = sb_osh(sbh);
    11531 +
    11532 +       /* access to the real pci config space only when the core is up */
    11533 +       oldidx = sb_coreidx(sbh);
    11534 +       sb_setcoreidx(sbh, coreidx);
    11535 +       if (sb_iscoreup(sbh)) {
    11536 +               if (len == 4)
    11537 +                       *(uint32 *)((ulong)cfg->emu + off) =
    11538 +                               htol32(R_REG(osh, (uint32 *)((ulong)cfg->pci + off)));
    11539 +               else if (len == 2)
    11540 +                       *(uint16 *)((ulong)cfg->emu + off) =
    11541 +                               htol16(R_REG(osh, (uint16 *)((ulong)cfg->pci + off)));
    11542 +               else if (len == 1)
    11543 +                       *(uint8 *)((ulong)cfg->emu + off) =
    11544 +                               R_REG(osh, (uint8 *)((ulong)cfg->pci + off));
    11545 +       }
    11546 +       sb_setcoreidx(sbh, oldidx);
    11547 +}
    11548 +
    11549 +static void
    11550 +sb_pcid_write_config(sb_t *sbh, uint coreidx, sb_pci_cfg_t *cfg,
    11551 +                     uint off, uint len)
    11552 +{
    11553 +       osl_t *osh;
    11554 +       uint oldidx;
    11555 +
    11556 +       ASSERT(cfg);
    11557 +       ASSERT(cfg->emu);
    11558 +       ASSERT(cfg->pci);
    11559 +
    11560 +       osh = sb_osh(sbh);
    11561 +
    11562 +       /* decide if real PCI config register access is necessary */
    11563 +       if (FORCE_EMUCFG(off, len))
    11564 +               return;
    11565 +
    11566 +       /* access to the real pci config space only when the core is up */
    11567 +       oldidx = sb_coreidx(sbh);
    11568 +       sb_setcoreidx(sbh, coreidx);
    11569 +       if (sb_iscoreup(sbh)) {
    11570 +               if (len == 4)
    11571 +                       W_REG(osh, (uint32 *)((ulong)cfg->pci + off),
    11572 +                             ltoh32(*(uint32 *)((ulong)cfg->emu + off)));
    11573 +               else if (len == 2)
    11574 +                       W_REG(osh, (uint16 *)((ulong)cfg->pci + off),
    11575 +                             ltoh16(*(uint16 *)((ulong)cfg->emu + off)));
    11576 +               else if (len == 1)
    11577 +                       W_REG(osh, (uint8 *)((ulong)cfg->pci + off),
    11578 +                             *(uint8 *)((ulong)cfg->emu + off));
    11579 +       }
    11580 +       sb_setcoreidx(sbh, oldidx);
    115817913+}
    115827914+
     
    115847916+ * Functions for accessing translated SB configuration space
    115857917+ */
     7918+
    115867919+static int
    11587 +sb_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
     7920+sb_read_config(void *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
    115887921+{
    115897922+       pci_config_regs *cfg;
    115907923+
    11591 +       if (dev >= SB_MAXCORES || func >= MAXFUNCS || (off + len) > sizeof(pci_config_regs))
     7924+       if (dev >= SB_MAXCORES || (off + len) > sizeof(pci_config_regs))
    115927925+               return -1;
    11593 +       cfg = sb_pci_cfg[dev][func].emu;
     7926+       cfg = &sb_config_regs[dev];
    115947927+
    115957928+       ASSERT(ISALIGNED(off, len));
    115967929+       ASSERT(ISALIGNED((uintptr)buf, len));
    11597 +
    11598 +       /* use special config space if the device does not exist */
    11599 +       if (!cfg)
    11600 +               cfg = &sb_pci_null;
    11601 +       /* sync emulation with real PCI config if necessary */
    11602 +       else if (sb_pci_cfg[dev][func].pci)
    11603 +               sb_pcid_read_config(sbh, dev, &sb_pci_cfg[dev][func], off, len);
    116047930+
    116057931+       if (len == 4)
     
    116167942+
    116177943+static int
    11618 +sb_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
    11619 +{
    11620 +       uint coreidx;
     7944+sb_write_config(void *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
     7945+{
     7946+       uint coreidx, n;
    116217947+       void *regs;
     7948+       sbconfig_t *sb;
    116227949+       pci_config_regs *cfg;
    11623 +       osl_t *osh;
    11624 +       sb_bar_cfg_t *bar;
    11625 +
    11626 +       if (dev >= SB_MAXCORES || func >= MAXFUNCS || (off + len) > sizeof(pci_config_regs))
     7950+
     7951+       if (dev >= SB_MAXCORES || (off + len) > sizeof(pci_config_regs))
    116277952+               return -1;
    11628 +       cfg = sb_pci_cfg[dev][func].emu;
    11629 +       if (!cfg)
    11630 +               return -1;
     7953+       cfg = &sb_config_regs[dev];
    116317954+
    116327955+       ASSERT(ISALIGNED(off, len));
    116337956+       ASSERT(ISALIGNED((uintptr)buf, len));
    116347957+
    11635 +       osh = sb_osh(sbh);
    11636 +
    116377958+       /* Emulate BAR sizing */
    11638 +       if (off >= OFFSETOF(pci_config_regs, base[0]) &&
    11639 +           off <= OFFSETOF(pci_config_regs, base[3]) &&
     7959+       if (off >= OFFSETOF(pci_config_regs, base[0]) && off <= OFFSETOF(pci_config_regs, base[3]) &&
    116407960+           len == 4 && *((uint32 *) buf) == ~0) {
    116417961+               coreidx = sb_coreidx(sbh);
    116427962+               if ((regs = sb_setcoreidx(sbh, dev))) {
    11643 +                       bar = sb_pci_cfg[dev][func].bar;
     7963+                       sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
    116447964+                       /* Highest numbered address match register */
     7965+                       n = (R_REG(&sb->sbidlow) & SBIDL_AR_MASK) >> SBIDL_AR_SHIFT;
    116457966+                       if (off == OFFSETOF(pci_config_regs, base[0]))
    11646 +                               cfg->base[0] = ~(bar->size0 - 1);
    11647 +                       else if (off == OFFSETOF(pci_config_regs, base[1]) && bar->n >= 1)
    11648 +                               cfg->base[1] = ~(bar->size1 - 1);
    11649 +                       else if (off == OFFSETOF(pci_config_regs, base[2]) && bar->n >= 2)
    11650 +                               cfg->base[2] = ~(bar->size2 - 1);
    11651 +                       else if (off == OFFSETOF(pci_config_regs, base[3]) && bar->n >= 3)
    11652 +                               cfg->base[3] = ~(bar->size3 - 1);
     7967+                               cfg->base[0] = ~(sb_size(R_REG(&sb->sbadmatch0)) - 1);
     7968+                       else if (off == OFFSETOF(pci_config_regs, base[1]) && n >= 1)
     7969+                               cfg->base[1] = ~(sb_size(R_REG(&sb->sbadmatch1)) - 1);
     7970+                       else if (off == OFFSETOF(pci_config_regs, base[2]) && n >= 2)
     7971+                               cfg->base[2] = ~(sb_size(R_REG(&sb->sbadmatch2)) - 1);
     7972+                       else if (off == OFFSETOF(pci_config_regs, base[3]) && n >= 3)
     7973+                               cfg->base[3] = ~(sb_size(R_REG(&sb->sbadmatch3)) - 1);
    116537974+               }
    116547975+               sb_setcoreidx(sbh, coreidx);
    11655 +       }
    11656 +       else if (len == 4)
     7976+               return 0;
     7977+       }
     7978+
     7979+       if (len == 4)
    116577980+               *((uint32 *)((ulong) cfg + off)) = htol32(*((uint32 *) buf));
    116587981+       else if (len == 2)
     
    116637986+               return -1;
    116647987+
    11665 +       /* sync emulation with real PCI config if necessary */
    11666 +       if (sb_pci_cfg[dev][func].pci)
    11667 +               sb_pcid_write_config(sbh, dev, &sb_pci_cfg[dev][func], off, len);
    11668 +
    116697988+       return 0;
    116707989+}
    116717990+
    116727991+int
    11673 +sbpci_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
     7992+sbpci_read_config(void *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
    116747993+{
    116757994+       if (bus == 0)
     
    116807999+
    116818000+int
    11682 +sbpci_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
     8001+sbpci_write_config(void *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
    116838002+{
    116848003+       if (bus == 0)
     
    116958014+}
    116968015+
    11697 +/*
    11698 + * Initiliaze PCI core. Return 0 after a successful initialization.
    11699 + * Otherwise return -1 to indicate there is no PCI core and return 1
    11700 + * to indicate PCI core is disabled.
    11701 + */
    11702 +int __init
    11703 +sbpci_init_pci(sb_t *sbh)
     8016+static int
     8017+sbpci_init_pci(void *sbh)
    117048018+{
    117058019+       uint chip, chiprev, chippkg, host;
     
    117078021+       sbpciregs_t *pci;
    117088022+       sbconfig_t *sb;
     8023+       int CT4712_WR;
    117098024+       uint32 val;
    11710 +       int ret = 0;
    11711 +       char *hbslot;
    11712 +       osl_t *osh;
    117138025+
    117148026+       chip = sb_chip(sbh);
     
    117168028+       chippkg = sb_chippkg(sbh);
    117178029+
    11718 +       osh = sb_osh(sbh);
    11719 +
    117208030+       if (!(pci = (sbpciregs_t *) sb_setcore(sbh, SB_PCI, 0))) {
    11721 +               printk("PCI: no core\n");
     8031+               printf("PCI: no core\n");
    117228032+               pci_disabled = TRUE;
    117238033+               return -1;
    117248034+       }
    11725 +
    11726 +       if ((chip == 0x4310) && (chiprev == 0))
     8035+       sb_core_reset(sbh, 0);
     8036+
     8037+       boardflags = (uint32) getintvar(NULL, "boardflags");
     8038+
     8039+       if ((chip == BCM4310_DEVICE_ID) && (chiprev == 0))
    117278040+               pci_disabled = TRUE;
    11728 +       
    11729 +       sb = (sbconfig_t *)((ulong) pci + SBCONFIGOFF);
    11730 +
    11731 +       boardflags = (uint32) getintvar(NULL, "boardflags");
    117328041+
    117338042+       /*
     
    117368045+        * floating.
    117378046+        */
    11738 +       if (((chip == BCM4712_CHIP_ID) &&
     8047+       if (((chip == BCM4712_DEVICE_ID) &&
    117398048+            ((chippkg == BCM4712SMALL_PKG_ID) ||
    117408049+             (chippkg == BCM4712MID_PKG_ID))) ||
    117418050+           (boardflags & BFL_NOPCI))
    117428051+               pci_disabled = TRUE;
    11743 +
    11744 +       /* Enable the core */
    11745 +       sb_core_reset(sbh, 0, 0);
    117468052+
    117478053+       /*
     
    117578063+
    117588064+       if (!host) {
    11759 +               ret = 1;
    11760 +
    117618065+               /* Disable PCI interrupts in client mode */
    11762 +               W_REG(osh, &sb->sbintvec, 0);
     8066+               sb = (sbconfig_t *)((ulong) pci + SBCONFIGOFF);
     8067+               W_REG(&sb->sbintvec, 0);
    117638068+
    117648069+               /* Disable the PCI bridge in client mode */
    117658070+               sbpci_ban(SB_PCI);
    11766 +               sb_core_disable(sbh, 0);
    11767 +
    11768 +               printk("PCI: Disabled\n");
     8071+               printf("PCI: Disabled\n");
    117698072+       } else {
    11770 +               printk("PCI: Initializing host\n");
    11771 +
    11772 +               /* Disable PCI SBReqeustTimeout for BCM4785 */
    11773 +               if (chip == BCM4785_CHIP_ID) {
    11774 +                       AND_REG(osh, &sb->sbimconfiglow, ~0x00000070);
    11775 +                       sb_commit(sbh);
     8073+               /* Reset the external PCI bus and enable the clock */
     8074+               W_REG(&pci->control, 0x5);              /* enable the tristate drivers */
     8075+               W_REG(&pci->control, 0xd);              /* enable the PCI clock */
     8076+               OSL_DELAY(150);                         /* delay > 100 us */
     8077+               W_REG(&pci->control, 0xf);              /* deassert PCI reset */
     8078+               W_REG(&pci->arbcontrol, PCI_INT_ARB);   /* use internal arbiter */
     8079+               OSL_DELAY(1);                           /* delay 1 us */
     8080+
     8081+               /* Enable CardBusMode */
     8082+               cardbus = nvram_match("cardbus", "1");
     8083+               if (cardbus) {
     8084+                       printf("PCI: Enabling CardBus\n");
     8085+                       /* GPIO 1 resets the CardBus device on bcm94710ap */
     8086+                       sb_gpioout(sbh, 1, 1);
     8087+                       sb_gpioouten(sbh, 1, 1);
     8088+                       W_REG(&pci->sprom[0], R_REG(&pci->sprom[0]) | 0x400);
    117768089+               }
    117778090+
    11778 +               /* Reset the external PCI bus and enable the clock */
    11779 +               W_REG(osh, &pci->control, 0x5);         /* enable the tristate drivers */
    11780 +               W_REG(osh, &pci->control, 0xd);         /* enable the PCI clock */
    11781 +               OSL_DELAY(150);                         /* delay > 100 us */
    11782 +               W_REG(osh, &pci->control, 0xf);         /* deassert PCI reset */
    11783 +               /* Use internal arbiter and park REQ/GRNT at external master 0 */
    11784 +               W_REG(osh, &pci->arbcontrol, PCI_INT_ARB);
    11785 +               OSL_DELAY(1);                           /* delay 1 us */
    11786 +               if (sb_corerev(sbh) >= 8) {
    11787 +                       val = getintvar(NULL, "parkid");
    11788 +                       ASSERT(val <= PCI_PARKID_LAST);
    11789 +                       OR_REG(osh, &pci->arbcontrol, val << PCI_PARKID_SHIFT);
    11790 +                       OSL_DELAY(1);
    11791 +               }
    11792 +
    11793 +               /* Enable CardBusMode */
    11794 +               cardbus = getintvar(NULL, "cardbus") == 1;
    11795 +               if (cardbus) {
    11796 +                       printk("PCI: Enabling CardBus\n");
    11797 +                       /* GPIO 1 resets the CardBus device on bcm94710ap */
    11798 +                       sb_gpioout(sbh, 1, 1, GPIO_DRV_PRIORITY);
    11799 +                       sb_gpioouten(sbh, 1, 1, GPIO_DRV_PRIORITY);
    11800 +                       W_REG(osh, &pci->sprom[0], R_REG(osh, &pci->sprom[0]) | 0x400);
    11801 +               }
    11802 +
    118038091+               /* 64 MB I/O access window */
    11804 +               W_REG(osh, &pci->sbtopci0, SBTOPCI_IO);
     8092+               W_REG(&pci->sbtopci0, SBTOPCI_IO);
    118058093+               /* 64 MB configuration access window */
    11806 +               W_REG(osh, &pci->sbtopci1, SBTOPCI_CFG0);
     8094+               W_REG(&pci->sbtopci1, SBTOPCI_CFG0);
    118078095+               /* 1 GB memory access window */
    11808 +               W_REG(osh, &pci->sbtopci2, SBTOPCI_MEM | SB_PCI_DMA);
    11809 +
    11810 +               /* Host bridge slot # nvram overwrite */
    11811 +               if ((hbslot = nvram_get("pcihbslot"))) {
    11812 +                       pci_hbslot = bcm_strtoul(hbslot, NULL, 0);
    11813 +                       ASSERT(pci_hbslot < PCI_MAX_DEVICES);
    11814 +               }
     8096+               W_REG(&pci->sbtopci2, SBTOPCI_MEM | SB_PCI_DMA);
    118158097+
    118168098+               /* Enable PCI bridge BAR0 prefetch and burst */
    118178099+               val = 6;
    11818 +               sbpci_write_config(sbh, 1, pci_hbslot, 0, PCI_CFG_CMD, &val, sizeof(val));
     8100+               sbpci_write_config(sbh, 1, 0, 0, PCI_CFG_CMD, &val, sizeof(val));
    118198101+
    118208102+               /* Enable PCI interrupts */
    11821 +               W_REG(osh, &pci->intmask, PCI_INTA);
    11822 +       }
    11823 +
    11824 +       return ret;
    11825 +}
    11826 +
    11827 +/*
    11828 + * Get the PCI region address and size information.
    11829 + */
    11830 +static void __init
    11831 +sbpci_init_regions(sb_t *sbh, uint func, pci_config_regs *cfg, sb_bar_cfg_t *bar)
    11832 +{
    11833 +       osl_t *osh;
    11834 +       uint16 coreid;
     8103+               W_REG(&pci->intmask, PCI_INTA);
     8104+       }
     8105+       
     8106+       return 0;
     8107+}
     8108+
     8109+static int
     8110+sbpci_init_cores(void *sbh)
     8111+{
     8112+       uint chip, chiprev, chippkg, coreidx, i;
     8113+       sbconfig_t *sb;
     8114+       pci_config_regs *cfg;
    118358115+       void *regs;
    11836 +       sbconfig_t *sb;
    11837 +       uint32 base;
    11838 +
    11839 +       osh     = sb_osh(sbh);
    11840 +       coreid  = sb_coreid(sbh);
    11841 +       regs    = sb_coreregs(sbh);
    11842 +       sb      = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
    11843 +
    11844 +       switch (coreid) {
    11845 +       case SB_USB20H:
    11846 +               base = htol32(sb_base(R_REG(osh, &sb->sbadmatch0)));
    11847 +
    11848 +               cfg->base[0] = func == 0 ? base : base + 0x800;  /* OHCI/EHCI */
    11849 +               cfg->base[1] = 0;
    11850 +               cfg->base[2] = 0;
    11851 +               cfg->base[3] = 0;
    11852 +               cfg->base[4] = 0;
    11853 +               cfg->base[5] = 0;
    11854 +               bar->n       = 1;
    11855 +               bar->size0   = func == 0 ? 0x200 : 0x100;  /* OHCI/EHCI */
    11856 +               bar->size1   = 0;
    11857 +               bar->size2   = 0;
    11858 +               bar->size3   = 0;
    11859 +               break;
    11860 +       default:
    11861 +               cfg->base[0] = htol32(sb_base(R_REG(osh, &sb->sbadmatch0)));
    11862 +               cfg->base[1] = htol32(sb_base(R_REG(osh, &sb->sbadmatch1)));
    11863 +               cfg->base[2] = htol32(sb_base(R_REG(osh, &sb->sbadmatch2)));
    11864 +               cfg->base[3] = htol32(sb_base(R_REG(osh, &sb->sbadmatch3)));
    11865 +               cfg->base[4] = 0;
    11866 +               cfg->base[5] = 0;
    11867 +               bar->n       = (R_REG(osh, &sb->sbidlow) & SBIDL_AR_MASK) >> SBIDL_AR_SHIFT;
    11868 +               bar->size0   = sb_size(R_REG(osh, &sb->sbadmatch0));
    11869 +               bar->size1   = sb_size(R_REG(osh, &sb->sbadmatch1));
    11870 +               bar->size2   = sb_size(R_REG(osh, &sb->sbadmatch2));
    11871 +               bar->size3   = sb_size(R_REG(osh, &sb->sbadmatch3));
    11872 +               break;
    11873 +       }
    11874 +}
    11875 +
    11876 +/*
    11877 + * Construct PCI config spaces for SB cores so that they
    11878 + * can be accessed as if they were PCI devices.
    11879 + */
    11880 +static void __init
    11881 +sbpci_init_cores(sb_t *sbh)
    11882 +{
    11883 +       uint chiprev, coreidx, i;
    11884 +       sbconfig_t *sb;
    11885 +       pci_config_regs *cfg, *pci;
    11886 +       sb_bar_cfg_t *bar;
    11887 +       void *regs;
    11888 +       osl_t *osh;
    11889 +       uint16 vendor, device;
    11890 +       uint16 coreid;
     8116+       char varname[8];
     8117+       uint wlidx = 0;
     8118+       uint16 vendor, core;
    118918119+       uint8 class, subclass, progif;
    11892 +       uint dev;
    11893 +       uint8 header;
    11894 +       uint func;
    11895 +
     8120+       uint32 val;
     8121+       uint32 sbips_int_mask[] = { 0, SBIPS_INT1_MASK, SBIPS_INT2_MASK, SBIPS_INT3_MASK, SBIPS_INT4_MASK };
     8122+       uint32 sbips_int_shift[] = { 0, 0, SBIPS_INT2_SHIFT, SBIPS_INT3_SHIFT, SBIPS_INT4_SHIFT };
     8123+
     8124+       chip = sb_chip(sbh);
    118968125+       chiprev = sb_chiprev(sbh);
     8126+       chippkg = sb_chippkg(sbh);
    118978127+       coreidx = sb_coreidx(sbh);
    11898 +
    11899 +       osh = sb_osh(sbh);
    119008128+
    119018129+       /* Scan the SB bus */
    119028130+       bzero(sb_config_regs, sizeof(sb_config_regs));
    11903 +       bzero(sb_bar_cfg, sizeof(sb_bar_cfg));
    11904 +       bzero(sb_pci_cfg, sizeof(sb_pci_cfg));
    11905 +       memset(&sb_pci_null, -1, sizeof(sb_pci_null));
    11906 +       cfg = sb_config_regs;
    11907 +       bar = sb_bar_cfg;
    11908 +       for (dev = 0; dev < SB_MAXCORES; dev ++) {
    11909 +               /* Check if the core exists */
    11910 +               if (!(regs = sb_setcoreidx(sbh, dev)))
     8131+       for (cfg = sb_config_regs; cfg < &sb_config_regs[SB_MAXCORES]; cfg++) {
     8132+               cfg->vendor = 0xffff;
     8133+               if (!(regs = sb_setcoreidx(sbh, cfg - sb_config_regs)))
    119118134+                       continue;
    119128135+               sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
    119138136+
     8137+               /* Read ID register and parse vendor and core */
     8138+               val = R_REG(&sb->sbidhigh);
     8139+               vendor = (val & SBIDH_VC_MASK) >> SBIDH_VC_SHIFT;
     8140+               core = (val & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT;
     8141+               progif = 0;
     8142+
    119148143+               /* Check if this core is banned */
    11915 +               coreid = sb_coreid(sbh);
    119168144+               for (i = 0; i < pci_banned; i++)
    11917 +                       if (coreid == pci_ban[i])
     8145+                       if (core == pci_ban[i])
    119188146+                               break;
    119198147+               if (i < pci_banned)
    119208148+                       continue;
    119218149+
    11922 +               for (func = 0; func < MAXFUNCS; ++func) {
    11923 +                       /* Make sure we won't go beyond the limit */
    11924 +                       if (cfg >= &sb_config_regs[SB_MAXCORES]) {
    11925 +                               printk("PCI: too many emulated devices\n");
    11926 +                               goto done;
    11927 +                       }
    11928 +
    11929 +                       /* Convert core id to pci id */
    11930 +                       if (sb_corepciid(sbh, func, &vendor, &device, &class, &subclass,
    11931 +                                        &progif, &header))
    11932 +                               continue;
    11933 +
    11934 +                       /*
    11935 +                        * Differentiate real PCI config from emulated.
    11936 +                        * non zero 'pci' indicate there is a real PCI config space
    11937 +                        * for this device.
    11938 +                        */
    11939 +                       switch (device) {
    11940 +                       case BCM47XX_GIGETH_ID:
    11941 +                               pci = (pci_config_regs *)((uint32)regs + 0x800);
    11942 +                               break;
    11943 +                       case BCM47XX_SATAXOR_ID:
    11944 +                               pci = (pci_config_regs *)((uint32)regs + 0x400);
    11945 +                               break;
    11946 +                       case BCM47XX_ATA100_ID:
    11947 +                               pci = (pci_config_regs *)((uint32)regs + 0x800);
    11948 +                               break;
    11949 +                       default:
    11950 +                               pci = NULL;
    11951 +                               break;
    11952 +                       }
    11953 +                       /* Supported translations */
    11954 +                       cfg->vendor = htol16(vendor);
    11955 +                       cfg->device = htol16(device);
    11956 +                       cfg->rev_id = chiprev;
    11957 +                       cfg->prog_if = progif;
    11958 +                       cfg->sub_class = subclass;
    11959 +                       cfg->base_class = class;
    11960 +                       cfg->header_type = header;
    11961 +                       sbpci_init_regions(sbh, func, cfg, bar);
    11962 +                       /* Save core interrupt flag */
    11963 +                       cfg->int_pin = R_REG(osh, &sb->sbtpsflag) & SBTPS_NUM0_MASK;
    11964 +                       /* Save core interrupt assignment */
    11965 +                       cfg->int_line = sb_irq(sbh);
    11966 +                       /* Indicate there is no SROM */
    11967 +                       *((uint32 *) &cfg->sprom_control) = 0xffffffff;
    11968 +
    11969 +                       /* Point to the PCI config spaces */
    11970 +                       sb_pci_cfg[dev][func].emu = cfg;
    11971 +                       sb_pci_cfg[dev][func].pci = pci;
    11972 +                       sb_pci_cfg[dev][func].bar = bar;
    11973 +                       cfg ++;
    11974 +                       bar ++;
    11975 +               }
    11976 +       }
    11977 +
    11978 +done:
    11979 +       sb_setcoreidx(sbh, coreidx);
    11980 +}
    11981 +
    11982 +/*
    11983 + * Initialize PCI core and construct PCI config spaces for SB cores.
    11984 + * Must propagate sbpci_init_pci() return value to the caller to let
    11985 + * them know the PCI core initialization status.
    11986 + */
    11987 +int __init
    11988 +sbpci_init(sb_t *sbh)
    11989 +{
    11990 +       int status = sbpci_init_pci(sbh);
    11991 +       sbpci_init_cores(sbh);
    11992 +       return status;
    11993 +}
    11994 +
    11995 diff -urN linux.old/arch/mips/bcm947xx/sbutils.c linux.dev/arch/mips/bcm947xx/sbutils.c
    11996 --- linux.old/arch/mips/bcm947xx/sbutils.c      1970-01-01 01:00:00.000000000 +0100
    11997 +++ linux.dev/arch/mips/bcm947xx/sbutils.c      2006-05-02 04:33:16.000000000 +0200
    11998 @@ -0,0 +1,3081 @@
    11999 +/*
    12000 + * Misc utility routines for accessing chip-specific features
    12001 + * of the SiliconBackplane-based Broadcom chips.
    12002 + *
    12003 + * Copyright 2006, Broadcom Corporation
    12004 + * All Rights Reserved.
    12005 + *
    12006 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    12007 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    12008 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    12009 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    12010 + * $Id: sbutils.c,v 1.10 2006/04/08 07:12:42 honor Exp $
    12011 + */
    12012 +
    12013 +#include <typedefs.h>
    12014 +#include <bcmdefs.h>
    12015 +#include <osl.h>
    12016 +#include <bcmutils.h>
    12017 +#include <sbutils.h>
    12018 +#include <bcmdevs.h>
    12019 +#include <sbconfig.h>
    12020 +#include <sbchipc.h>
    12021 +#include <sbpci.h>
    12022 +#include <sbpcie.h>
    12023 +#include <pcicfg.h>
    12024 +#include <sbpcmcia.h>
    12025 +#include <sbextif.h>
    12026 +#include <sbsocram.h>
    12027 +#include <bcmsrom.h>
    12028 +#ifdef __mips__
    12029 +#include <mipsinc.h>
    12030 +#endif /* __mips__ */
    12031 +
    12032 +/* debug/trace */
    12033 +#define        SB_ERROR(args)
    12034 +
    12035 +typedef uint32 (*sb_intrsoff_t)(void *intr_arg);
    12036 +typedef void (*sb_intrsrestore_t)(void *intr_arg, uint32 arg);
    12037 +typedef bool (*sb_intrsenabled_t)(void *intr_arg);
    12038 +
    12039 +/* misc sb info needed by some of the routines */
    12040 +typedef struct sb_info {
    12041 +
    12042 +       struct sb_pub   sb;             /* back plane public state (must be first field) */
    12043 +
    12044 +       void    *osh;                   /* osl os handle */
    12045 +       void    *sdh;                   /* bcmsdh handle */
    12046 +
    12047 +       void    *curmap;                /* current regs va */
    12048 +       void    *regs[SB_MAXCORES];     /* other regs va */
    12049 +
    12050 +       uint    curidx;                 /* current core index */
    12051 +       uint    dev_coreid;             /* the core provides driver functions */
    12052 +
    12053 +       bool    memseg;                 /* flag to toggle MEM_SEG register */
    12054 +
    12055 +       uint    gpioidx;                /* gpio control core index */
    12056 +       uint    gpioid;                 /* gpio control coretype */
    12057 +
    12058 +       uint    numcores;               /* # discovered cores */
    12059 +       uint    coreid[SB_MAXCORES];    /* id of each core */
    12060 +
    12061 +       void    *intr_arg;              /* interrupt callback function arg */
    12062 +       sb_intrsoff_t           intrsoff_fn;            /* turns chip interrupts off */
    12063 +       sb_intrsrestore_t       intrsrestore_fn;        /* restore chip interrupts */
    12064 +       sb_intrsenabled_t       intrsenabled_fn;        /* check if interrupts are enabled */
    12065 +
    12066 +} sb_info_t;
    12067 +
    12068 +/* local prototypes */
    12069 +static sb_info_t * sb_doattach(sb_info_t *si, uint devid, osl_t *osh, void *regs,
    12070 +       uint bustype, void *sdh, char **vars, uint *varsz);
    12071 +static void sb_scan(sb_info_t *si);
    12072 +static uint sb_corereg(sb_info_t *si, uint coreidx, uint regoff, uint mask, uint val);
    12073 +static uint _sb_coreidx(sb_info_t *si);
    12074 +static uint sb_findcoreidx(sb_info_t *si, uint coreid, uint coreunit);
    12075 +static uint sb_pcidev2chip(uint pcidev);
    12076 +static uint sb_chip2numcores(uint chip);
    12077 +static bool sb_ispcie(sb_info_t *si);
    12078 +static bool sb_find_pci_capability(sb_info_t *si, uint8 req_cap_id, uchar *buf, uint32 *buflen);
    12079 +static int sb_pci_fixcfg(sb_info_t *si);
    12080 +
    12081 +/* routines to access mdio slave device registers */
    12082 +static int sb_pcie_mdiowrite(sb_info_t *si,  uint physmedia, uint readdr, uint val);
    12083 +static void sb_war30841(sb_info_t *si);
    12084 +
    12085 +/* delay needed between the mdio control/ mdiodata register data access */
    12086 +#define PR28829_DELAY() OSL_DELAY(10)
    12087 +
    12088 +/* size that can take bitfielddump */
    12089 +#define BITFIELD_DUMP_SIZE  32
    12090 +
    12091 +/* global variable to indicate reservation/release of gpio's */
    12092 +static uint32 sb_gpioreservation = 0;
    12093 +
    12094 +#define        SB_INFO(sbh)    (sb_info_t*)sbh
    12095 +#define        SET_SBREG(si, r, mask, val)     \
    12096 +               W_SBREG((si), (r), ((R_SBREG((si), (r)) & ~(mask)) | (val)))
    12097 +#define        GOODCOREADDR(x) (((x) >= SB_ENUM_BASE) && ((x) <= SB_ENUM_LIM) && \
    12098 +               ISALIGNED((x), SB_CORE_SIZE))
    12099 +#define        GOODREGS(regs)  ((regs) && ISALIGNED((uintptr)(regs), SB_CORE_SIZE))
    12100 +#define        REGS2SB(va)     (sbconfig_t*) ((int8*)(va) + SBCONFIGOFF)
    12101 +#define        GOODIDX(idx)    (((uint)idx) < SB_MAXCORES)
    12102 +#define        BADIDX          (SB_MAXCORES+1)
    12103 +#define        NOREV           -1              /* Invalid rev */
    12104 +
    12105 +#define PCI(si)                ((BUSTYPE(si->sb.bustype) == PCI_BUS) && (si->sb.buscoretype == SB_PCI))
    12106 +#define PCIE(si)       ((BUSTYPE(si->sb.bustype) == PCI_BUS) && (si->sb.buscoretype == SB_PCIE))
    12107 +
    12108 +/* sonicsrev */
    12109 +#define        SONICS_2_2      (SBIDL_RV_2_2 >> SBIDL_RV_SHIFT)
    12110 +#define        SONICS_2_3      (SBIDL_RV_2_3 >> SBIDL_RV_SHIFT)
    12111 +
    12112 +#define        R_SBREG(si, sbr)        sb_read_sbreg((si), (sbr))
    12113 +#define        W_SBREG(si, sbr, v)     sb_write_sbreg((si), (sbr), (v))
    12114 +#define        AND_SBREG(si, sbr, v)   W_SBREG((si), (sbr), (R_SBREG((si), (sbr)) & (v)))
    12115 +#define        OR_SBREG(si, sbr, v)    W_SBREG((si), (sbr), (R_SBREG((si), (sbr)) | (v)))
    12116 +
    12117 +/*
    12118 + * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts before/
    12119 + * after core switching to avoid invalid register accesss inside ISR.
    12120 + */
    12121 +#define INTR_OFF(si, intr_val) \
    12122 +       if ((si)->intrsoff_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) {      \
    12123 +               intr_val = (*(si)->intrsoff_fn)((si)->intr_arg); }
    12124 +#define INTR_RESTORE(si, intr_val) \
    12125 +       if ((si)->intrsrestore_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) {  \
    12126 +               (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val); }
    12127 +
    12128 +/* dynamic clock control defines */
    12129 +#define        LPOMINFREQ              25000           /* low power oscillator min */
    12130 +#define        LPOMAXFREQ              43000           /* low power oscillator max */
    12131 +#define        XTALMINFREQ             19800000        /* 20 MHz - 1% */
    12132 +#define        XTALMAXFREQ             20200000        /* 20 MHz + 1% */
    12133 +#define        PCIMINFREQ              25000000        /* 25 MHz */
    12134 +#define        PCIMAXFREQ              34000000        /* 33 MHz + fudge */
    12135 +
    12136 +#define        ILP_DIV_5MHZ            0               /* ILP = 5 MHz */
    12137 +#define        ILP_DIV_1MHZ            4               /* ILP = 1 MHz */
    12138 +
    12139 +/* different register spaces to access thr'u pcie indirect access */
    12140 +#define PCIE_CONFIGREGS        1               /* Access to config space */
    12141 +#define PCIE_PCIEREGS          2               /* Access to pcie registers */
    12142 +
    12143 +/* GPIO Based LED powersave defines */
    12144 +#define DEFAULT_GPIO_ONTIME    10              /* Default: 10% on */
    12145 +#define DEFAULT_GPIO_OFFTIME   90              /* Default: 10% on */
    12146 +
    12147 +#define DEFAULT_GPIOTIMERVAL  ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
    12148 +
    12149 +static uint32
    12150 +sb_read_sbreg(sb_info_t *si, volatile uint32 *sbr)
    12151 +{
    12152 +       uint8 tmp;
    12153 +       uint32 val, intr_val = 0;
    12154 +
    12155 +
    12156 +       /*
    12157 +        * compact flash only has 11 bits address, while we needs 12 bits address.
    12158 +        * MEM_SEG will be OR'd with other 11 bits address in hardware,
    12159 +        * so we program MEM_SEG with 12th bit when necessary(access sb regsiters).
    12160 +        * For normal PCMCIA bus(CFTable_regwinsz > 2k), do nothing special
    12161 +        */
    12162 +       if (si->memseg) {
    12163 +               INTR_OFF(si, intr_val);
    12164 +               tmp = 1;
    12165 +               OSL_PCMCIA_WRITE_ATTR(si->osh, MEM_SEG, &tmp, 1);
    12166 +               sbr = (volatile uint32 *)((uintptr)sbr & ~(1 << 11)); /* mask out bit 11 */
    12167 +       }
    12168 +
    12169 +       val = R_REG(si->osh, sbr);
    12170 +
    12171 +       if (si->memseg) {
    12172 +               tmp = 0;
    12173 +               OSL_PCMCIA_WRITE_ATTR(si->osh, MEM_SEG, &tmp, 1);
    12174 +               INTR_RESTORE(si, intr_val);
    12175 +       }
    12176 +
    12177 +       return (val);
    12178 +}
    12179 +
    12180 +static void
    12181 +sb_write_sbreg(sb_info_t *si, volatile uint32 *sbr, uint32 v)
    12182 +{
    12183 +       uint8 tmp;
    12184 +       volatile uint32 dummy;
    12185 +       uint32 intr_val = 0;
    12186 +
    12187 +
    12188 +       /*
    12189 +        * compact flash only has 11 bits address, while we needs 12 bits address.
    12190 +        * MEM_SEG will be OR'd with other 11 bits address in hardware,
    12191 +        * so we program MEM_SEG with 12th bit when necessary(access sb regsiters).
    12192 +        * For normal PCMCIA bus(CFTable_regwinsz > 2k), do nothing special
    12193 +        */
    12194 +       if (si->memseg) {
    12195 +               INTR_OFF(si, intr_val);
    12196 +               tmp = 1;
    12197 +               OSL_PCMCIA_WRITE_ATTR(si->osh, MEM_SEG, &tmp, 1);
    12198 +               sbr = (volatile uint32 *)((uintptr)sbr & ~(1 << 11)); /* mask out bit 11 */
    12199 +       }
    12200 +
    12201 +       if (BUSTYPE(si->sb.bustype) == PCMCIA_BUS) {
    12202 +#ifdef IL_BIGENDIAN
    12203 +               dummy = R_REG(si->osh, sbr);
    12204 +               W_REG(si->osh, ((volatile uint16 *)sbr + 1), (uint16)((v >> 16) & 0xffff));
    12205 +               dummy = R_REG(si->osh, sbr);
    12206 +               W_REG(si->osh, (volatile uint16 *)sbr, (uint16)(v & 0xffff));
    12207 +#else
    12208 +               dummy = R_REG(si->osh, sbr);
    12209 +               W_REG(si->osh, (volatile uint16 *)sbr, (uint16)(v & 0xffff));
    12210 +               dummy = R_REG(si->osh, sbr);
    12211 +               W_REG(si->osh, ((volatile uint16 *)sbr + 1), (uint16)((v >> 16) & 0xffff));
    12212 +#endif /* IL_BIGENDIAN */
    12213 +       } else
    12214 +               W_REG(si->osh, sbr, v);
    12215 +
    12216 +       if (si->memseg) {
    12217 +               tmp = 0;
    12218 +               OSL_PCMCIA_WRITE_ATTR(si->osh, MEM_SEG, &tmp, 1);
    12219 +               INTR_RESTORE(si, intr_val);
    12220 +       }
    12221 +}
    12222 +
    12223 +/*
    12224 + * Allocate a sb handle.
    12225 + * devid - pci device id (used to determine chip#)
    12226 + * osh - opaque OS handle
    12227 + * regs - virtual address of initial core registers
    12228 + * bustype - pci/pcmcia/sb/sdio/etc
    12229 + * vars - pointer to a pointer area for "environment" variables
    12230 + * varsz - pointer to int to return the size of the vars
    12231 + */
    12232 +sb_t *
    12233 +BCMINITFN(sb_attach)(uint devid, osl_t *osh, void *regs,
    12234 +                     uint bustype, void *sdh, char **vars, uint *varsz)
    12235 +{
    12236 +       sb_info_t *si;
    12237 +
    12238 +       /* alloc sb_info_t */
    12239 +       if ((si = MALLOC(osh, sizeof (sb_info_t))) == NULL) {
    12240 +               SB_ERROR(("sb_attach: malloc failed! malloced %d bytes\n", MALLOCED(osh)));
    12241 +               return (NULL);
    12242 +       }
    12243 +
    12244 +       if (sb_doattach(si, devid, osh, regs, bustype, sdh, vars, (uint*)varsz) == NULL) {
    12245 +               MFREE(osh, si, sizeof(sb_info_t));
    12246 +               return (NULL);
    12247 +       }
    12248 +
    12249 +       return (sb_t *)si;
    12250 +}
    12251 +
    12252 +/* Using sb_kattach depends on SB_BUS support, either implicit  */
    12253 +/* no limiting BCMBUSTYPE value) or explicit (value is SB_BUS). */
    12254 +#if !defined(BCMBUSTYPE) || (BCMBUSTYPE == SB_BUS)
    12255 +
    12256 +/* global kernel resource */
    12257 +static sb_info_t ksi;
    12258 +static bool ksi_attached = FALSE;
    12259 +
    12260 +/* generic kernel variant of sb_attach() */
    12261 +sb_t *
    12262 +BCMINITFN(sb_kattach)(void)
    12263 +{
    12264 +       osl_t *osh = NULL;
    12265 +       uint32 *regs;
    12266 +
    12267 +       if (!ksi_attached) {
    12268 +               uint32 cid;
    12269 +
    12270 +               regs = (uint32 *)REG_MAP(SB_ENUM_BASE, SB_CORE_SIZE);
    12271 +               cid = R_REG(osh, (uint32 *)regs);
    12272 +               if (((cid & CID_ID_MASK) == BCM4712_CHIP_ID) &&
    12273 +                   ((cid & CID_PKG_MASK) != BCM4712LARGE_PKG_ID) &&
    12274 +                   ((cid & CID_REV_MASK) <= (3 << CID_REV_SHIFT))) {
    12275 +                       uint32 *scc, val;
    12276 +
    12277 +                       scc = (uint32 *)((uchar*)regs + OFFSETOF(chipcregs_t, slow_clk_ctl));
    12278 +                       val = R_REG(osh, scc);
    12279 +                       SB_ERROR(("    initial scc = 0x%x\n", val));
    12280 +                       val |= SCC_SS_XTAL;
    12281 +                       W_REG(osh, scc, val);
    12282 +               }
    12283 +
    12284 +               if (sb_doattach(&ksi, BCM4710_DEVICE_ID, osh, (void*)regs,
    12285 +                       SB_BUS, NULL, NULL, NULL) == NULL) {
    12286 +                       return NULL;
    12287 +               }
    12288 +               else
    12289 +                       ksi_attached = TRUE;
    12290 +       }
    12291 +
    12292 +       return (sb_t *)&ksi;
    12293 +}
    12294 +#endif /* !BCMBUSTYPE || (BCMBUSTYPE == SB_BUS) */
    12295 +
    12296 +static sb_info_t  *
    12297 +BCMINITFN(sb_doattach)(sb_info_t *si, uint devid, osl_t *osh, void *regs,
    12298 +                       uint bustype, void *sdh, char **vars, uint *varsz)
    12299 +{
    12300 +       uint origidx;
    12301 +       chipcregs_t *cc;
    12302 +       sbconfig_t *sb;
    12303 +       uint32 w;
    12304 +
    12305 +       ASSERT(GOODREGS(regs));
    12306 +
    12307 +       bzero((uchar*)si, sizeof(sb_info_t));
    12308 +
    12309 +       si->sb.buscoreidx = si->gpioidx = BADIDX;
    12310 +
    12311 +       si->curmap = regs;
    12312 +       si->sdh = sdh;
    12313 +       si->osh = osh;
    12314 +
    12315 +       /* check to see if we are a sb core mimic'ing a pci core */
    12316 +       if (bustype == PCI_BUS) {
    12317 +               if (OSL_PCI_READ_CONFIG(si->osh, PCI_SPROM_CONTROL, sizeof(uint32)) == 0xffffffff) {
    12318 +                       SB_ERROR(("%s: incoming bus is PCI but it's a lie, switching to SB "
    12319 +                                 "devid:0x%x\n", __FUNCTION__, devid));
    12320 +                       bustype = SB_BUS;
    12321 +               }
    12322 +       }
    12323 +
    12324 +       si->sb.bustype = bustype;
    12325 +       if (si->sb.bustype != BUSTYPE(si->sb.bustype)) {
    12326 +               SB_ERROR(("sb_doattach: bus type %d does not match configured bus type %d\n",
    12327 +                         si->sb.bustype, BUSTYPE(si->sb.bustype)));
    12328 +               return NULL;
    12329 +       }
    12330 +
    12331 +       /* need to set memseg flag for CF card first before any sb registers access */
    12332 +       if (BUSTYPE(si->sb.bustype) == PCMCIA_BUS)
    12333 +               si->memseg = TRUE;
    12334 +
    12335 +       /* kludge to enable the clock on the 4306 which lacks a slowclock */
    12336 +       if (BUSTYPE(si->sb.bustype) == PCI_BUS)
    12337 +               sb_clkctl_xtal(&si->sb, XTAL|PLL, ON);
    12338 +
    12339 +       if (BUSTYPE(si->sb.bustype) == PCI_BUS) {
    12340 +               w = OSL_PCI_READ_CONFIG(si->osh, PCI_BAR0_WIN, sizeof(uint32));
    12341 +               if (!GOODCOREADDR(w))
    12342 +                       OSL_PCI_WRITE_CONFIG(si->osh, PCI_BAR0_WIN, sizeof(uint32), SB_ENUM_BASE);
    12343 +       }
    12344 +
    12345 +       /* initialize current core index value */
    12346 +       si->curidx = _sb_coreidx(si);
    12347 +
    12348 +       if (si->curidx == BADIDX) {
    12349 +               SB_ERROR(("sb_doattach: bad core index\n"));
    12350 +               return NULL;
    12351 +       }
    12352 +
    12353 +       /* get sonics backplane revision */
    12354 +       sb = REGS2SB(si->curmap);
    12355 +       si->sb.sonicsrev = (R_SBREG(si, &sb->sbidlow) & SBIDL_RV_MASK) >> SBIDL_RV_SHIFT;
    12356 +
    12357 +       /* keep and reuse the initial register mapping */
    12358 +       origidx = si->curidx;
    12359 +       if (BUSTYPE(si->sb.bustype) == SB_BUS)
    12360 +               si->regs[origidx] = regs;
    12361 +
    12362 +       /* is core-0 a chipcommon core? */
    12363 +       si->numcores = 1;
    12364 +       cc = (chipcregs_t*) sb_setcoreidx(&si->sb, 0);
    12365 +       if (sb_coreid(&si->sb) != SB_CC)
    12366 +               cc = NULL;
    12367 +
    12368 +       /* determine chip id and rev */
    12369 +       if (cc) {
    12370 +               /* chip common core found! */
    12371 +               si->sb.chip = R_REG(si->osh, &cc->chipid) & CID_ID_MASK;
    12372 +               si->sb.chiprev = (R_REG(si->osh, &cc->chipid) & CID_REV_MASK) >> CID_REV_SHIFT;
    12373 +               si->sb.chippkg = (R_REG(si->osh, &cc->chipid) & CID_PKG_MASK) >> CID_PKG_SHIFT;
    12374 +       } else {
    12375 +               /* no chip common core -- must convert device id to chip id */
    12376 +               if ((si->sb.chip = sb_pcidev2chip(devid)) == 0) {
    12377 +                       SB_ERROR(("sb_doattach: unrecognized device id 0x%04x\n", devid));
    12378 +                       sb_setcoreidx(&si->sb, origidx);
    12379 +                       return NULL;
    12380 +               }
    12381 +       }
    12382 +
    12383 +       /* get chipcommon rev */
    12384 +       si->sb.ccrev = cc ? (int)sb_corerev(&si->sb) : NOREV;
    12385 +
    12386 +       /* determine numcores */
    12387 +       if (cc && ((si->sb.ccrev == 4) || (si->sb.ccrev >= 6)))
    12388 +               si->numcores = (R_REG(si->osh, &cc->chipid) & CID_CC_MASK) >> CID_CC_SHIFT;
    12389 +       else
    12390 +               si->numcores = sb_chip2numcores(si->sb.chip);
    12391 +
    12392 +       /* return to original core */
    12393 +       sb_setcoreidx(&si->sb, origidx);
    12394 +
    12395 +       /* sanity checks */
    12396 +       ASSERT(si->sb.chip);
    12397 +
    12398 +       /* scan for cores */
    12399 +       sb_scan(si);
    12400 +
    12401 +       /* fixup necessary chip/core configurations */
    12402 +       if (BUSTYPE(si->sb.bustype) == PCI_BUS) {
    12403 +               if (sb_pci_fixcfg(si)) {
    12404 +                       SB_ERROR(("sb_doattach: sb_pci_fixcfg failed\n"));
    12405 +                       return NULL;
    12406 +               }
    12407 +       }
    12408 +
    12409 +       /* srom_var_init() depends on sb_scan() info */
    12410 +       if (srom_var_init(si, si->sb.bustype, si->curmap, si->osh, vars, varsz)) {
    12411 +               SB_ERROR(("sb_doattach: srom_var_init failed: bad srom\n"));
    12412 +               return (NULL);
    12413 +       }
    12414 +
    12415 +       if (cc == NULL) {
    12416 +               /*
    12417 +                * The chip revision number is hardwired into all
    12418 +                * of the pci function config rev fields and is
    12419 +                * independent from the individual core revision numbers.
    12420 +                * For example, the "A0" silicon of each chip is chip rev 0.
    12421 +                * For PCMCIA we get it from the CIS instead.
    12422 +                */
    12423 +               if (BUSTYPE(si->sb.bustype) == PCMCIA_BUS) {
    12424 +                       ASSERT(vars);
    12425 +                       si->sb.chiprev = getintvar(*vars, "chiprev");
    12426 +               } else if (BUSTYPE(si->sb.bustype) == PCI_BUS) {
    12427 +                       w = OSL_PCI_READ_CONFIG(si->osh, PCI_CFG_REV, sizeof(uint32));
    12428 +                       si->sb.chiprev = w & 0xff;
    12429 +               } else
    12430 +                       si->sb.chiprev = 0;
    12431 +       }
    12432 +
    12433 +       if (BUSTYPE(si->sb.bustype) == PCMCIA_BUS) {
    12434 +               w = getintvar(*vars, "regwindowsz");
    12435 +               si->memseg = (w <= CFTABLE_REGWIN_2K) ? TRUE : FALSE;
    12436 +       }
    12437 +
    12438 +       /* gpio control core is required */
    12439 +       if (!GOODIDX(si->gpioidx)) {
    12440 +               SB_ERROR(("sb_doattach: gpio control core not found\n"));
    12441 +               return NULL;
    12442 +       }
    12443 +
    12444 +       /* get boardtype and boardrev */
    12445 +       switch (BUSTYPE(si->sb.bustype)) {
    12446 +       case PCI_BUS:
    12447 +               /* do a pci config read to get subsystem id and subvendor id */
    12448 +               w = OSL_PCI_READ_CONFIG(si->osh, PCI_CFG_SVID, sizeof(uint32));
    12449 +               si->sb.boardvendor = w & 0xffff;
    12450 +               si->sb.boardtype = (w >> 16) & 0xffff;
    12451 +               break;
    12452 +
    12453 +       case PCMCIA_BUS:
    12454 +       case SDIO_BUS:
    12455 +               si->sb.boardvendor = getintvar(*vars, "manfid");
    12456 +               si->sb.boardtype = getintvar(*vars, "prodid");
    12457 +               break;
    12458 +
    12459 +       case SB_BUS:
    12460 +       case JTAG_BUS:
    12461 +               si->sb.boardvendor = VENDOR_BROADCOM;
    12462 +               if ((si->sb.boardtype = getintvar(NULL, "boardtype")) == 0)
    12463 +                       si->sb.boardtype = 0xffff;
    12464 +               break;
    12465 +       }
    12466 +
    12467 +       if (si->sb.boardtype == 0) {
    12468 +               SB_ERROR(("sb_doattach: unknown board type\n"));
    12469 +               ASSERT(si->sb.boardtype);
    12470 +       }
    12471 +
    12472 +       /* setup the GPIO based LED powersave register */
    12473 +       if (si->sb.ccrev >= 16) {
    12474 +               if ((vars == NULL) || ((w = getintvar(*vars, "leddc")) == 0))
    12475 +                       w = DEFAULT_GPIOTIMERVAL;
    12476 +               sb_corereg(si, 0, OFFSETOF(chipcregs_t, gpiotimerval), ~0, w);
    12477 +       }
    12478 +       if ((si->sb.chip == BCM4311_CHIP_ID) && (si->sb.chiprev <= 1)) {
    12479 +               /* set proper clk setup delays before forcing HT */
    12480 +               sb_clkctl_init((void *)si);
    12481 +               sb_corereg((void*)si, SB_CC_IDX, OFFSETOF(chipcregs_t, system_clk_ctl),
    12482 +                          SYCC_HR, SYCC_HR);
    12483 +       }
    12484 +
    12485 +
    12486 +       return (si);
    12487 +}
    12488 +
    12489 +uint
    12490 +sb_coreid(sb_t *sbh)
    12491 +{
    12492 +       sb_info_t *si;
    12493 +       sbconfig_t *sb;
    12494 +
    12495 +       si = SB_INFO(sbh);
    12496 +       sb = REGS2SB(si->curmap);
    12497 +
    12498 +       return ((R_SBREG(si, &sb->sbidhigh) & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT);
    12499 +}
    12500 +
    12501 +uint
    12502 +sb_coreidx(sb_t *sbh)
    12503 +{
    12504 +       sb_info_t *si;
    12505 +
    12506 +       si = SB_INFO(sbh);
    12507 +       return (si->curidx);
    12508 +}
    12509 +
    12510 +/* return current index of core */
    12511 +static uint
    12512 +_sb_coreidx(sb_info_t *si)
    12513 +{
    12514 +       sbconfig_t *sb;
    12515 +       uint32 sbaddr = 0;
    12516 +
    12517 +       ASSERT(si);
    12518 +
    12519 +       switch (BUSTYPE(si->sb.bustype)) {
    12520 +       case SB_BUS:
    12521 +               sb = REGS2SB(si->curmap);
    12522 +               sbaddr = sb_base(R_SBREG(si, &sb->sbadmatch0));
    12523 +               break;
    12524 +
    12525 +       case PCI_BUS:
    12526 +               sbaddr = OSL_PCI_READ_CONFIG(si->osh, PCI_BAR0_WIN, sizeof(uint32));
    12527 +               break;
    12528 +
    12529 +       case PCMCIA_BUS: {
    12530 +               uint8 tmp = 0;
    12531 +
    12532 +               OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_ADDR0, &tmp, 1);
    12533 +               sbaddr  = (uint)tmp << 12;
    12534 +               OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_ADDR1, &tmp, 1);
    12535 +               sbaddr |= (uint)tmp << 16;
    12536 +               OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_ADDR2, &tmp, 1);
    12537 +               sbaddr |= (uint)tmp << 24;
    12538 +               break;
    12539 +       }
    12540 +
    12541 +#ifdef BCMJTAG
    12542 +       case JTAG_BUS:
    12543 +               sbaddr = (uint32)si->curmap;
    12544 +               break;
    12545 +#endif /* BCMJTAG */
    12546 +
    12547 +       default:
    12548 +               ASSERT(0);
    12549 +       }
    12550 +
    12551 +       if (!GOODCOREADDR(sbaddr))
    12552 +               return BADIDX;
    12553 +
    12554 +       return ((sbaddr - SB_ENUM_BASE) / SB_CORE_SIZE);
    12555 +}
    12556 +
    12557 +uint
    12558 +sb_corevendor(sb_t *sbh)
    12559 +{
    12560 +       sb_info_t *si;
    12561 +       sbconfig_t *sb;
    12562 +
    12563 +       si = SB_INFO(sbh);
    12564 +       sb = REGS2SB(si->curmap);
    12565 +
    12566 +       return ((R_SBREG(si, &sb->sbidhigh) & SBIDH_VC_MASK) >> SBIDH_VC_SHIFT);
    12567 +}
    12568 +
    12569 +uint
    12570 +sb_corerev(sb_t *sbh)
    12571 +{
    12572 +       sb_info_t *si;
    12573 +       sbconfig_t *sb;
    12574 +       uint sbidh;
    12575 +
    12576 +       si = SB_INFO(sbh);
    12577 +       sb = REGS2SB(si->curmap);
    12578 +       sbidh = R_SBREG(si, &sb->sbidhigh);
    12579 +
    12580 +       return (SBCOREREV(sbidh));
    12581 +}
    12582 +
    12583 +void *
    12584 +sb_osh(sb_t *sbh)
    12585 +{
    12586 +       sb_info_t *si;
    12587 +
    12588 +       si = SB_INFO(sbh);
    12589 +       return si->osh;
    12590 +}
    12591 +
    12592 +void
    12593 +sb_setosh(sb_t *sbh, osl_t *osh)
    12594 +{
    12595 +       sb_info_t *si;
    12596 +
    12597 +       si = SB_INFO(sbh);
    12598 +       if (si->osh != NULL) {
    12599 +               SB_ERROR(("osh is already set....\n"));
    12600 +               ASSERT(!si->osh);
    12601 +       }
    12602 +       si->osh = osh;
    12603 +}
    12604 +
    12605 +/* set/clear sbtmstatelow core-specific flags */
    12606 +uint32
    12607 +sb_coreflags(sb_t *sbh, uint32 mask, uint32 val)
    12608 +{
    12609 +       sb_info_t *si;
    12610 +       sbconfig_t *sb;
    12611 +       uint32 w;
    12612 +
    12613 +       si = SB_INFO(sbh);
    12614 +       sb = REGS2SB(si->curmap);
    12615 +
    12616 +       ASSERT((val & ~mask) == 0);
    12617 +
    12618 +       /* mask and set */
    12619 +       if (mask || val) {
    12620 +               w = (R_SBREG(si, &sb->sbtmstatelow) & ~mask) | val;
    12621 +               W_SBREG(si, &sb->sbtmstatelow, w);
    12622 +       }
    12623 +
    12624 +       /* return the new value */
    12625 +       return (R_SBREG(si, &sb->sbtmstatelow));
    12626 +}
    12627 +
    12628 +/* set/clear sbtmstatehigh core-specific flags */
    12629 +uint32
    12630 +sb_coreflagshi(sb_t *sbh, uint32 mask, uint32 val)
    12631 +{
    12632 +       sb_info_t *si;
    12633 +       sbconfig_t *sb;
    12634 +       uint32 w;
    12635 +
    12636 +       si = SB_INFO(sbh);
    12637 +       sb = REGS2SB(si->curmap);
    12638 +
    12639 +       ASSERT((val & ~mask) == 0);
    12640 +       ASSERT((mask & ~SBTMH_FL_MASK) == 0);
    12641 +
    12642 +       /* mask and set */
    12643 +       if (mask || val) {
    12644 +               w = (R_SBREG(si, &sb->sbtmstatehigh) & ~mask) | val;
    12645 +               W_SBREG(si, &sb->sbtmstatehigh, w);
    12646 +       }
    12647 +
    12648 +       /* return the new value */
    12649 +       return (R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_FL_MASK);
    12650 +}
    12651 +
    12652 +/* Run bist on current core. Caller needs to take care of core-specific bist hazards */
    12653 +int
    12654 +sb_corebist(sb_t *sbh)
    12655 +{
    12656 +       uint32 sblo;
    12657 +       sb_info_t *si;
    12658 +       sbconfig_t *sb;
    12659 +       int result = 0;
    12660 +
    12661 +       si = SB_INFO(sbh);
    12662 +       sb = REGS2SB(si->curmap);
    12663 +
    12664 +       sblo = R_SBREG(si, &sb->sbtmstatelow);
    12665 +       W_SBREG(si, &sb->sbtmstatelow, (sblo | SBTML_FGC | SBTML_BE));
    12666 +
    12667 +       SPINWAIT(((R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_BISTD) == 0), 100000);
    12668 +
    12669 +       if (R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_BISTF)
    12670 +               result = BCME_ERROR;
    12671 +
    12672 +       W_SBREG(si, &sb->sbtmstatelow, sblo);
    12673 +
    12674 +       return result;
    12675 +}
    12676 +
    12677 +bool
    12678 +sb_iscoreup(sb_t *sbh)
    12679 +{
    12680 +       sb_info_t *si;
    12681 +       sbconfig_t *sb;
    12682 +
    12683 +       si = SB_INFO(sbh);
    12684 +       sb = REGS2SB(si->curmap);
    12685 +
    12686 +       return ((R_SBREG(si, &sb->sbtmstatelow) &
    12687 +                (SBTML_RESET | SBTML_REJ_MASK | SBTML_CLK)) == SBTML_CLK);
    12688 +}
    12689 +
    12690 +/*
    12691 + * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set operation,
    12692 + * switch back to the original core, and return the new value.
    12693 + *
    12694 + * When using the silicon backplane, no fidleing with interrupts or core switches are needed.
    12695 + *
    12696 + * Also, when using pci/pcie, we can optimize away the core switching for pci registers
    12697 + * and (on newer pci cores) chipcommon registers.
    12698 + */
    12699 +static uint
    12700 +sb_corereg(sb_info_t *si, uint coreidx, uint regoff, uint mask, uint val)
    12701 +{
    12702 +       uint origidx = 0;
    12703 +       uint32 *r = NULL;
    12704 +       uint w;
    12705 +       uint intr_val = 0;
    12706 +       bool fast = FALSE;
    12707 +
    12708 +       ASSERT(GOODIDX(coreidx));
    12709 +       ASSERT(regoff < SB_CORE_SIZE);
    12710 +       ASSERT((val & ~mask) == 0);
    12711 +
    12712 +#ifdef notyet
    12713 +       if (si->sb.bustype == SB_BUS) {
    12714 +               /* If internal bus, we can always get at everything */
    12715 +               fast = TRUE;
    12716 +               r = (uint32 *)((uchar *)si->regs[coreidx] + regoff);
    12717 +       } else if (si->sb.bustype == PCI_BUS) {
    12718 +               /* If pci/pcie, we can get at pci/pcie regs and on newer cores to chipc */
    12719 +
    12720 +               if ((si->coreid[coreidx] == SB_CC) &&
    12721 +                   ((si->sb.buscoretype == SB_PCIE) ||
    12722 +                    (si->sb.buscorerev >= 13))) {
    12723 +                       /* Chipc registers are mapped at 12KB */
    12724 +
    12725 +                       fast = TRUE;
    12726 +                       r = (uint32 *)((char *)si->curmap + PCI_16KB0_CCREGS_OFFSET + regoff);
    12727 +               } else if (si->sb.buscoreidx == coreidx) {
    12728 +                       /* pci registers are at either in the last 2KB of an 8KB window
    12729 +                        * or, in pcie and pci rev 13 at 8KB
    12730 +                        */
    12731 +                       fast = TRUE;
    12732 +                       if ((si->sb.buscoretype == SB_PCIE) ||
    12733 +                           (si->sb.buscorerev >= 13))
    12734 +                               r = (uint32 *)((char *)si->curmap +
    12735 +                                              PCI_16KB0_PCIREGS_OFFSET + regoff);
    12736 +                       else
    12737 +                               r = (uint32 *)((char *)si->curmap +
    12738 +                                              ((regoff >= SBCONFIGOFF) ?
    12739 +                                               PCI_BAR0_PCISBR_OFFSET : PCI_BAR0_PCIREGS_OFFSET) +
    12740 +                                              regoff);
    12741 +               }
    12742 +       }
    12743 +#endif /* notyet */
    12744 +
    12745 +       if (!fast) {
    12746 +               INTR_OFF(si, intr_val);
    12747 +
    12748 +               /* save current core index */
    12749 +               origidx = sb_coreidx(&si->sb);
    12750 +
    12751 +               /* switch core */
    12752 +               r = (uint32*) ((uchar*) sb_setcoreidx(&si->sb, coreidx) + regoff);
    12753 +       }
    12754 +       ASSERT(r);
    12755 +
    12756 +       /* mask and set */
    12757 +       if (mask || val) {
    12758 +               if (regoff >= SBCONFIGOFF) {
    12759 +                       w = (R_SBREG(si, r) & ~mask) | val;
    12760 +                       W_SBREG(si, r, w);
    12761 +               } else {
    12762 +                       w = (R_REG(si->osh, r) & ~mask) | val;
    12763 +                       W_REG(si->osh, r, w);
    12764 +               }
    12765 +       }
    12766 +
    12767 +       /* readback */
    12768 +       if (regoff >= SBCONFIGOFF)
    12769 +               w = R_SBREG(si, r);
    12770 +       else
    12771 +               w = R_REG(si->osh, r);
    12772 +
    12773 +       if (!fast) {
    12774 +               /* restore core index */
    12775 +               if (origidx != coreidx)
    12776 +                       sb_setcoreidx(&si->sb, origidx);
    12777 +
    12778 +               INTR_RESTORE(si, intr_val);
    12779 +       }
    12780 +
    12781 +       return (w);
    12782 +}
    12783 +
    12784 +#define DWORD_ALIGN(x)  (x & ~(0x03))
    12785 +#define BYTE_POS(x) (x & 0x3)
    12786 +#define WORD_POS(x) (x & 0x1)
    12787 +
    12788 +#define BYTE_SHIFT(x)  (8 * BYTE_POS(x))
    12789 +#define WORD_SHIFT(x)  (16 * WORD_POS(x))
    12790 +
    12791 +#define BYTE_VAL(a, x) ((a >> BYTE_SHIFT(x)) & 0xFF)
    12792 +#define WORD_VAL(a, x) ((a >> WORD_SHIFT(x)) & 0xFFFF)
    12793 +
    12794 +#define read_pci_cfg_byte(a) \
    12795 +       (BYTE_VAL(OSL_PCI_READ_CONFIG(si->osh, DWORD_ALIGN(a), 4), a) & 0xff)
    12796 +
    12797 +#define read_pci_cfg_write(a) \
    12798 +       (WORD_VAL(OSL_PCI_READ_CONFIG(si->osh, DWORD_ALIGN(a), 4), a) & 0xffff)
    12799 +
    12800 +
    12801 +/* return TRUE if requested capability exists in the PCI config space */
    12802 +static bool
    12803 +sb_find_pci_capability(sb_info_t *si, uint8 req_cap_id, uchar *buf, uint32 *buflen)
    12804 +{
    12805 +       uint8 cap_id;
    12806 +       uint8 cap_ptr;
    12807 +       uint32  bufsize;
    12808 +       uint8 byte_val;
    12809 +
    12810 +       if (BUSTYPE(si->sb.bustype) != PCI_BUS)
    12811 +               return FALSE;
    12812 +
    12813 +       /* check for Header type 0 */
    12814 +       byte_val = read_pci_cfg_byte(PCI_CFG_HDR);
    12815 +       if ((byte_val & 0x7f) != PCI_HEADER_NORMAL)
    12816 +               return FALSE;
    12817 +
    12818 +       /* check if the capability pointer field exists */
    12819 +       byte_val = read_pci_cfg_byte(PCI_CFG_STAT);
    12820 +       if (!(byte_val & PCI_CAPPTR_PRESENT))
    12821 +               return FALSE;
    12822 +
    12823 +       cap_ptr = read_pci_cfg_byte(PCI_CFG_CAPPTR);
    12824 +       /* check if the capability pointer is 0x00 */
    12825 +       if (cap_ptr == 0x00)
    12826 +               return FALSE;
    12827 +
    12828 +
    12829 +       /* loop thr'u the capability list and see if the pcie capabilty exists */
    12830 +
    12831 +       cap_id = read_pci_cfg_byte(cap_ptr);
    12832 +
    12833 +       while (cap_id != req_cap_id) {
    12834 +               cap_ptr = read_pci_cfg_byte((cap_ptr+1));
    12835 +               if (cap_ptr == 0x00) break;
    12836 +               cap_id = read_pci_cfg_byte(cap_ptr);
    12837 +       }
    12838 +       if (cap_id != req_cap_id) {
    12839 +               return FALSE;
    12840 +       }
    12841 +       /* found the caller requested capability */
    12842 +       if ((buf != NULL) && (buflen != NULL)) {
    12843 +               bufsize = *buflen;
    12844 +               if (!bufsize) goto end;
    12845 +               *buflen = 0;
    12846 +               /* copy the cpability data excluding cap ID and next ptr */
    12847 +               cap_ptr += 2;
    12848 +               if ((bufsize + cap_ptr)  > SZPCR)
    12849 +                       bufsize = SZPCR - cap_ptr;
    12850 +               *buflen = bufsize;
    12851 +               while (bufsize--) {
    12852 +                       *buf = read_pci_cfg_byte(cap_ptr);
    12853 +                       cap_ptr++;
    12854 +                       buf++;
    12855 +               }
    12856 +       }
    12857 +end:
    12858 +       return TRUE;
    12859 +}
    12860 +
    12861 +/* return TRUE if PCIE capability exists the pci config space */
    12862 +static inline bool
    12863 +sb_ispcie(sb_info_t *si)
    12864 +{
    12865 +       return (sb_find_pci_capability(si, PCI_CAP_PCIECAP_ID, NULL, NULL));
    12866 +}
    12867 +
    12868 +/* scan the sb enumerated space to identify all cores */
    12869 +static void
    12870 +BCMINITFN(sb_scan)(sb_info_t *si)
    12871 +{
    12872 +       uint origidx;
    12873 +       uint i;
    12874 +       bool pci;
    12875 +       bool pcie;
    12876 +       uint pciidx;
    12877 +       uint pcieidx;
    12878 +       uint pcirev;
    12879 +       uint pcierev;
    12880 +
    12881 +
    12882 +       /* numcores should already be set */
    12883 +       ASSERT((si->numcores > 0) && (si->numcores <= SB_MAXCORES));
    12884 +
    12885 +       /* save current core index */
    12886 +       origidx = sb_coreidx(&si->sb);
    12887 +
    12888 +       si->sb.buscorerev = NOREV;
    12889 +       si->sb.buscoreidx = BADIDX;
    12890 +
    12891 +       si->gpioidx = BADIDX;
    12892 +
    12893 +       pci = pcie = FALSE;
    12894 +       pcirev = pcierev = NOREV;
    12895 +       pciidx = pcieidx = BADIDX;
    12896 +
    12897 +       for (i = 0; i < si->numcores; i++) {
    12898 +               sb_setcoreidx(&si->sb, i);
    12899 +               si->coreid[i] = sb_coreid(&si->sb);
    12900 +
    12901 +               if (si->coreid[i] == SB_PCI) {
    12902 +                       pciidx = i;
    12903 +                       pcirev = sb_corerev(&si->sb);
    12904 +                       pci = TRUE;
    12905 +               } else if (si->coreid[i] == SB_PCIE) {
    12906 +                       pcieidx = i;
    12907 +                       pcierev = sb_corerev(&si->sb);
    12908 +                       pcie = TRUE;
    12909 +               } else if (si->coreid[i] == SB_PCMCIA) {
    12910 +                       si->sb.buscorerev = sb_corerev(&si->sb);
    12911 +                       si->sb.buscoretype = si->coreid[i];
    12912 +                       si->sb.buscoreidx = i;
    12913 +               }
    12914 +       }
    12915 +       if (pci && pcie) {
    12916 +               if (sb_ispcie(si))
    12917 +                       pci = FALSE;
    12918 +               else
    12919 +                       pcie = FALSE;
    12920 +       }
    12921 +       if (pci) {
    12922 +               si->sb.buscoretype = SB_PCI;
    12923 +               si->sb.buscorerev = pcirev;
    12924 +               si->sb.buscoreidx = pciidx;
    12925 +       } else if (pcie) {
    12926 +               si->sb.buscoretype = SB_PCIE;
    12927 +               si->sb.buscorerev = pcierev;
    12928 +               si->sb.buscoreidx = pcieidx;
    12929 +       }
    12930 +
    12931 +       /*
    12932 +        * Find the gpio "controlling core" type and index.
    12933 +        * Precedence:
    12934 +        * - if there's a chip common core - use that
    12935 +        * - else if there's a pci core (rev >= 2) - use that
    12936 +        * - else there had better be an extif core (4710 only)
    12937 +        */
    12938 +       if (GOODIDX(sb_findcoreidx(si, SB_CC, 0))) {
    12939 +               si->gpioidx = sb_findcoreidx(si, SB_CC, 0);
    12940 +               si->gpioid = SB_CC;
    12941 +       } else if (PCI(si) && (si->sb.buscorerev >= 2)) {
    12942 +               si->gpioidx = si->sb.buscoreidx;
    12943 +               si->gpioid = SB_PCI;
    12944 +       } else if (sb_findcoreidx(si, SB_EXTIF, 0)) {
    12945 +               si->gpioidx = sb_findcoreidx(si, SB_EXTIF, 0);
    12946 +               si->gpioid = SB_EXTIF;
    12947 +       } else
    12948 +               ASSERT(si->gpioidx != BADIDX);
    12949 +
    12950 +       /* return to original core index */
    12951 +       sb_setcoreidx(&si->sb, origidx);
    12952 +}
    12953 +
    12954 +/* may be called with core in reset */
    12955 +void
    12956 +sb_detach(sb_t *sbh)
    12957 +{
    12958 +       sb_info_t *si;
    12959 +       uint idx;
    12960 +
    12961 +       si = SB_INFO(sbh);
    12962 +
    12963 +       if (si == NULL)
    12964 +               return;
    12965 +
    12966 +       if (BUSTYPE(si->sb.bustype) == SB_BUS)
    12967 +               for (idx = 0; idx < SB_MAXCORES; idx++)
    12968 +                       if (si->regs[idx]) {
    12969 +                               REG_UNMAP(si->regs[idx]);
    12970 +                               si->regs[idx] = NULL;
    12971 +                       }
    12972 +#if !defined(BCMBUSTYPE) || (BCMBUSTYPE == SB_BUS)
    12973 +       if (si != &ksi)
    12974 +#endif /* !BCMBUSTYPE || (BCMBUSTYPE == SB_BUS) */
    12975 +               MFREE(si->osh, si, sizeof(sb_info_t));
    12976 +
    12977 +}
    12978 +
    12979 +/* use pci dev id to determine chip id for chips not having a chipcommon core */
    12980 +static uint
    12981 +BCMINITFN(sb_pcidev2chip)(uint pcidev)
    12982 +{
    12983 +       if ((pcidev >= BCM4710_DEVICE_ID) && (pcidev <= BCM47XX_USB_ID))
    12984 +               return (BCM4710_CHIP_ID);
    12985 +       if ((pcidev >= BCM4402_ENET_ID) && (pcidev <= BCM4402_V90_ID))
    12986 +               return (BCM4402_CHIP_ID);
    12987 +       if (pcidev == BCM4401_ENET_ID)
    12988 +               return (BCM4402_CHIP_ID);
    12989 +
    12990 +       return (0);
    12991 +}
    12992 +
    12993 +/* convert chip number to number of i/o cores */
    12994 +static uint
    12995 +BCMINITFN(sb_chip2numcores)(uint chip)
    12996 +{
    12997 +       if (chip == BCM4710_CHIP_ID)
    12998 +               return (9);
    12999 +       if (chip == BCM4402_CHIP_ID)
    13000 +               return (3);
    13001 +       if (chip == BCM4306_CHIP_ID)    /* < 4306c0 */
    13002 +               return (6);
    13003 +       if (chip == BCM4704_CHIP_ID)
    13004 +               return (9);
    13005 +       if (chip == BCM5365_CHIP_ID)
    13006 +               return (7);
    13007 +
    13008 +       SB_ERROR(("sb_chip2numcores: unsupported chip 0x%x\n", chip));
    13009 +       ASSERT(0);
    13010 +       return (1);
    13011 +}
    13012 +
    13013 +/* return index of coreid or BADIDX if not found */
    13014 +static uint
    13015 +sb_findcoreidx(sb_info_t *si, uint coreid, uint coreunit)
    13016 +{
    13017 +       uint found;
    13018 +       uint i;
    13019 +
    13020 +       found = 0;
    13021 +
    13022 +       for (i = 0; i < si->numcores; i++)
    13023 +               if (si->coreid[i] == coreid) {
    13024 +                       if (found == coreunit)
    13025 +                               return (i);
    13026 +                       found++;
    13027 +               }
    13028 +
    13029 +       return (BADIDX);
    13030 +}
    13031 +
    13032 +/*
    13033 + * this function changes logical "focus" to the indiciated core,
    13034 + * must be called with interrupt off.
    13035 + * Moreover, callers should keep interrupts off during switching out of and back to d11 core
    13036 + */
    13037 +void*
    13038 +sb_setcoreidx(sb_t *sbh, uint coreidx)
    13039 +{
    13040 +       sb_info_t *si;
    13041 +       uint32 sbaddr;
    13042 +       uint8 tmp;
    13043 +
    13044 +       si = SB_INFO(sbh);
    13045 +
    13046 +       if (coreidx >= si->numcores)
    13047 +               return (NULL);
    13048 +
    13049 +       /*
    13050 +        * If the user has provided an interrupt mask enabled function,
    13051 +        * then assert interrupts are disabled before switching the core.
    13052 +        */
    13053 +       ASSERT((si->intrsenabled_fn == NULL) || !(*(si)->intrsenabled_fn)((si)->intr_arg));
    13054 +
    13055 +       sbaddr = SB_ENUM_BASE + (coreidx * SB_CORE_SIZE);
    13056 +
    13057 +       switch (BUSTYPE(si->sb.bustype)) {
    13058 +       case SB_BUS:
    13059 +               /* map new one */
    13060 +               if (!si->regs[coreidx]) {
    13061 +                       si->regs[coreidx] = (void*)REG_MAP(sbaddr, SB_CORE_SIZE);
    13062 +                       ASSERT(GOODREGS(si->regs[coreidx]));
    13063 +               }
    13064 +               si->curmap = si->regs[coreidx];
    13065 +               break;
    13066 +
    13067 +       case PCI_BUS:
    13068 +               /* point bar0 window */
    13069 +               OSL_PCI_WRITE_CONFIG(si->osh, PCI_BAR0_WIN, 4, sbaddr);
    13070 +               break;
    13071 +
    13072 +       case PCMCIA_BUS:
    13073 +               tmp = (sbaddr >> 12) & 0x0f;
    13074 +               OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_ADDR0, &tmp, 1);
    13075 +               tmp = (sbaddr >> 16) & 0xff;
    13076 +               OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_ADDR1, &tmp, 1);
    13077 +               tmp = (sbaddr >> 24) & 0xff;
    13078 +               OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_ADDR2, &tmp, 1);
    13079 +               break;
    13080 +#ifdef BCMJTAG
    13081 +       case JTAG_BUS:
    13082 +               /* map new one */
    13083 +               if (!si->regs[coreidx]) {
    13084 +                       si->regs[coreidx] = (void *)sbaddr;
    13085 +                       ASSERT(GOODREGS(si->regs[coreidx]));
    13086 +               }
    13087 +               si->curmap = si->regs[coreidx];
    13088 +               break;
    13089 +#endif /* BCMJTAG */
    13090 +       }
    13091 +
    13092 +       si->curidx = coreidx;
    13093 +
    13094 +       return (si->curmap);
    13095 +}
    13096 +
    13097 +/*
    13098 + * this function changes logical "focus" to the indiciated core,
    13099 + * must be called with interrupt off.
    13100 + * Moreover, callers should keep interrupts off during switching out of and back to d11 core
    13101 + */
    13102 +void*
    13103 +sb_setcore(sb_t *sbh, uint coreid, uint coreunit)
    13104 +{
    13105 +       sb_info_t *si;
    13106 +       uint idx;
    13107 +
    13108 +       si = SB_INFO(sbh);
    13109 +       idx = sb_findcoreidx(si, coreid, coreunit);
    13110 +       if (!GOODIDX(idx))
    13111 +               return (NULL);
    13112 +
    13113 +       return (sb_setcoreidx(sbh, idx));
    13114 +}
    13115 +
    13116 +/* return chip number */
    13117 +uint
    13118 +sb_chip(sb_t *sbh)
    13119 +{
    13120 +       sb_info_t *si;
    13121 +
    13122 +       si = SB_INFO(sbh);
    13123 +       return (si->sb.chip);
    13124 +}
    13125 +
    13126 +/* return chip revision number */
    13127 +uint
    13128 +sb_chiprev(sb_t *sbh)
    13129 +{
    13130 +       sb_info_t *si;
    13131 +
    13132 +       si = SB_INFO(sbh);
    13133 +       return (si->sb.chiprev);
    13134 +}
    13135 +
    13136 +/* return chip common revision number */
    13137 +uint
    13138 +sb_chipcrev(sb_t *sbh)
    13139 +{
    13140 +       sb_info_t *si;
    13141 +
    13142 +       si = SB_INFO(sbh);
    13143 +       return (si->sb.ccrev);
    13144 +}
    13145 +
    13146 +/* return chip package option */
    13147 +uint
    13148 +sb_chippkg(sb_t *sbh)
    13149 +{
    13150 +       sb_info_t *si;
    13151 +
    13152 +       si = SB_INFO(sbh);
    13153 +       return (si->sb.chippkg);
    13154 +}
    13155 +
    13156 +/* return PCI core rev. */
    13157 +uint
    13158 +sb_pcirev(sb_t *sbh)
    13159 +{
    13160 +       sb_info_t *si;
    13161 +
    13162 +       si = SB_INFO(sbh);
    13163 +       return (si->sb.buscorerev);
    13164 +}
    13165 +
    13166 +bool
    13167 +BCMINITFN(sb_war16165)(sb_t *sbh)
    13168 +{
    13169 +       sb_info_t *si;
    13170 +
    13171 +       si = SB_INFO(sbh);
    13172 +
    13173 +       return (PCI(si) && (si->sb.buscorerev <= 10));
    13174 +}
    13175 +
    13176 +static void
    13177 +BCMINITFN(sb_war30841)(sb_info_t *si)
    13178 +{
    13179 +       sb_pcie_mdiowrite(si, MDIODATA_DEV_RX, SERDES_RX_TIMER1, 0x8128);
    13180 +       sb_pcie_mdiowrite(si, MDIODATA_DEV_RX, SERDES_RX_CDR, 0x0100);
    13181 +       sb_pcie_mdiowrite(si, MDIODATA_DEV_RX, SERDES_RX_CDRBW, 0x1466);
    13182 +}
    13183 +
    13184 +/* return PCMCIA core rev. */
    13185 +uint
    13186 +BCMINITFN(sb_pcmciarev)(sb_t *sbh)
    13187 +{
    13188 +       sb_info_t *si;
    13189 +
    13190 +       si = SB_INFO(sbh);
    13191 +       return (si->sb.buscorerev);
    13192 +}
    13193 +
    13194 +/* return board vendor id */
    13195 +uint
    13196 +sb_boardvendor(sb_t *sbh)
    13197 +{
    13198 +       sb_info_t *si;
    13199 +
    13200 +       si = SB_INFO(sbh);
    13201 +       return (si->sb.boardvendor);
    13202 +}
    13203 +
    13204 +/* return boardtype */
    13205 +uint
    13206 +sb_boardtype(sb_t *sbh)
    13207 +{
    13208 +       sb_info_t *si;
    13209 +       char *var;
    13210 +
    13211 +       si = SB_INFO(sbh);
    13212 +
    13213 +       if (BUSTYPE(si->sb.bustype) == SB_BUS && si->sb.boardtype == 0xffff) {
    13214 +               /* boardtype format is a hex string */
    13215 +               si->sb.boardtype = getintvar(NULL, "boardtype");
    13216 +
    13217 +               /* backward compatibility for older boardtype string format */
    13218 +               if ((si->sb.boardtype == 0) && (var = getvar(NULL, "boardtype"))) {
    13219 +                       if (!strcmp(var, "bcm94710dev"))
    13220 +                               si->sb.boardtype = BCM94710D_BOARD;
    13221 +                       else if (!strcmp(var, "bcm94710ap"))
    13222 +                               si->sb.boardtype = BCM94710AP_BOARD;
    13223 +                       else if (!strcmp(var, "bu4710"))
    13224 +                               si->sb.boardtype = BU4710_BOARD;
    13225 +                       else if (!strcmp(var, "bcm94702mn"))
    13226 +                               si->sb.boardtype = BCM94702MN_BOARD;
    13227 +                       else if (!strcmp(var, "bcm94710r1"))
    13228 +                               si->sb.boardtype = BCM94710R1_BOARD;
    13229 +                       else if (!strcmp(var, "bcm94710r4"))
    13230 +                               si->sb.boardtype = BCM94710R4_BOARD;
    13231 +                       else if (!strcmp(var, "bcm94702cpci"))
    13232 +                               si->sb.boardtype = BCM94702CPCI_BOARD;
    13233 +                       else if (!strcmp(var, "bcm95380_rr"))
    13234 +                               si->sb.boardtype = BCM95380RR_BOARD;
    13235 +               }
    13236 +       }
    13237 +
    13238 +       return (si->sb.boardtype);
    13239 +}
    13240 +
    13241 +/* return bus type of sbh device */
    13242 +uint
    13243 +sb_bus(sb_t *sbh)
    13244 +{
    13245 +       sb_info_t *si;
    13246 +
    13247 +       si = SB_INFO(sbh);
    13248 +       return (si->sb.bustype);
    13249 +}
    13250 +
    13251 +/* return bus core type */
    13252 +uint
    13253 +sb_buscoretype(sb_t *sbh)
    13254 +{
    13255 +       sb_info_t *si;
    13256 +
    13257 +       si = SB_INFO(sbh);
    13258 +
    13259 +       return (si->sb.buscoretype);
    13260 +}
    13261 +
    13262 +/* return bus core revision */
    13263 +uint
    13264 +sb_buscorerev(sb_t *sbh)
    13265 +{
    13266 +       sb_info_t *si;
    13267 +       si = SB_INFO(sbh);
    13268 +
    13269 +       return (si->sb.buscorerev);
    13270 +}
    13271 +
    13272 +/* return list of found cores */
    13273 +uint
    13274 +sb_corelist(sb_t *sbh, uint coreid[])
    13275 +{
    13276 +       sb_info_t *si;
    13277 +
    13278 +       si = SB_INFO(sbh);
    13279 +
    13280 +       bcopy((uchar*)si->coreid, (uchar*)coreid, (si->numcores * sizeof(uint)));
    13281 +       return (si->numcores);
    13282 +}
    13283 +
    13284 +/* return current register mapping */
    13285 +void *
    13286 +sb_coreregs(sb_t *sbh)
    13287 +{
    13288 +       sb_info_t *si;
    13289 +
    13290 +       si = SB_INFO(sbh);
    13291 +       ASSERT(GOODREGS(si->curmap));
    13292 +
    13293 +       return (si->curmap);
    13294 +}
    13295 +
    13296 +
    13297 +/* do buffered registers update */
    13298 +void
    13299 +sb_commit(sb_t *sbh)
    13300 +{
    13301 +       sb_info_t *si;
    13302 +       uint origidx;
    13303 +       uint intr_val = 0;
    13304 +
    13305 +       si = SB_INFO(sbh);
    13306 +
    13307 +       origidx = si->curidx;
    13308 +       ASSERT(GOODIDX(origidx));
    13309 +
    13310 +       INTR_OFF(si, intr_val);
    13311 +
    13312 +       /* switch over to chipcommon core if there is one, else use pci */
    13313 +       if (si->sb.ccrev != NOREV) {
    13314 +               chipcregs_t *ccregs = (chipcregs_t *)sb_setcore(sbh, SB_CC, 0);
    13315 +
    13316 +               /* do the buffer registers update */
    13317 +               W_REG(si->osh, &ccregs->broadcastaddress, SB_COMMIT);
    13318 +               W_REG(si->osh, &ccregs->broadcastdata, 0x0);
    13319 +       } else if (PCI(si)) {
    13320 +               sbpciregs_t *pciregs = (sbpciregs_t *)sb_setcore(sbh, SB_PCI, 0);
    13321 +
    13322 +               /* do the buffer registers update */
    13323 +               W_REG(si->osh, &pciregs->bcastaddr, SB_COMMIT);
    13324 +               W_REG(si->osh, &pciregs->bcastdata, 0x0);
    13325 +       } else
    13326 +               ASSERT(0);
    13327 +
    13328 +       /* restore core index */
    13329 +       sb_setcoreidx(sbh, origidx);
    13330 +       INTR_RESTORE(si, intr_val);
    13331 +}
    13332 +
    13333 +/* reset and re-enable a core
    13334 + * inputs:
    13335 + * bits - core specific bits that are set during and after reset sequence
    13336 + * resetbits - core specific bits that are set only during reset sequence
    13337 + */
    13338 +void
    13339 +sb_core_reset(sb_t *sbh, uint32 bits, uint32 resetbits)
    13340 +{
    13341 +       sb_info_t *si;
    13342 +       sbconfig_t *sb;
    13343 +       volatile uint32 dummy;
    13344 +
    13345 +       si = SB_INFO(sbh);
    13346 +       ASSERT(GOODREGS(si->curmap));
    13347 +       sb = REGS2SB(si->curmap);
    13348 +
    13349 +       /*
    13350 +        * Must do the disable sequence first to work for arbitrary current core state.
    13351 +        */
    13352 +       sb_core_disable(sbh, (bits | resetbits));
    13353 +
    13354 +       /*
    13355 +        * Now do the initialization sequence.
    13356 +        */
    13357 +
    13358 +       /* set reset while enabling the clock and forcing them on throughout the core */
    13359 +       W_SBREG(si, &sb->sbtmstatelow, (SBTML_FGC | SBTML_CLK | SBTML_RESET | bits | resetbits));
    13360 +       dummy = R_SBREG(si, &sb->sbtmstatelow);
    13361 +       OSL_DELAY(1);
    13362 +
    13363 +       if (R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_SERR) {
    13364 +               W_SBREG(si, &sb->sbtmstatehigh, 0);
    13365 +       }
    13366 +       if ((dummy = R_SBREG(si, &sb->sbimstate)) & (SBIM_IBE | SBIM_TO)) {
    13367 +               AND_SBREG(si, &sb->sbimstate, ~(SBIM_IBE | SBIM_TO));
    13368 +       }
    13369 +
    13370 +       /* clear reset and allow it to propagate throughout the core */
    13371 +       W_SBREG(si, &sb->sbtmstatelow, (SBTML_FGC | SBTML_CLK | bits));
    13372 +       dummy = R_SBREG(si, &sb->sbtmstatelow);
    13373 +       OSL_DELAY(1);
    13374 +
    13375 +       /* leave clock enabled */
    13376 +       W_SBREG(si, &sb->sbtmstatelow, (SBTML_CLK | bits));
    13377 +       dummy = R_SBREG(si, &sb->sbtmstatelow);
    13378 +       OSL_DELAY(1);
    13379 +}
    13380 +
    13381 +void
    13382 +sb_core_tofixup(sb_t *sbh)
    13383 +{
    13384 +       sb_info_t *si;
    13385 +       sbconfig_t *sb;
    13386 +
    13387 +       si = SB_INFO(sbh);
    13388 +
    13389 +       if ((BUSTYPE(si->sb.bustype) != PCI_BUS) || PCIE(si) ||
    13390 +           (PCI(si) && (si->sb.buscorerev >= 5)))
    13391 +               return;
    13392 +
    13393 +       ASSERT(GOODREGS(si->curmap));
    13394 +       sb = REGS2SB(si->curmap);
    13395 +
    13396 +       if (BUSTYPE(si->sb.bustype) == SB_BUS) {
    13397 +               SET_SBREG(si, &sb->sbimconfiglow,
    13398 +                         SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
    13399 +                         (0x5 << SBIMCL_RTO_SHIFT) | 0x3);
    13400 +       } else {
    13401 +               if (sb_coreid(sbh) == SB_PCI) {
    13402 +                       SET_SBREG(si, &sb->sbimconfiglow,
    13403 +                                 SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
    13404 +                                 (0x3 << SBIMCL_RTO_SHIFT) | 0x2);
    13405 +               } else {
    13406 +                       SET_SBREG(si, &sb->sbimconfiglow, (SBIMCL_RTO_MASK | SBIMCL_STO_MASK), 0);
    13407 +               }
    13408 +       }
    13409 +
    13410 +       sb_commit(sbh);
    13411 +}
    13412 +
    13413 +/*
    13414 + * Set the initiator timeout for the "master core".
    13415 + * The master core is defined to be the core in control
    13416 + * of the chip and so it issues accesses to non-memory
    13417 + * locations (Because of dma *any* core can access memeory).
    13418 + *
    13419 + * The routine uses the bus to decide who is the master:
    13420 + *     SB_BUS => mips
    13421 + *     JTAG_BUS => chipc
    13422 + *     PCI_BUS => pci or pcie
    13423 + *     PCMCIA_BUS => pcmcia
    13424 + *     SDIO_BUS => pcmcia
    13425 + *
    13426 + * This routine exists so callers can disable initiator
    13427 + * timeouts so accesses to very slow devices like otp
    13428 + * won't cause an abort. The routine allows arbitrary
    13429 + * settings of the service and request timeouts, though.
    13430 + *
    13431 + * Returns the timeout state before changing it or -1
    13432 + * on error.
    13433 + */
    13434 +
    13435 +#define        TO_MASK (SBIMCL_RTO_MASK | SBIMCL_STO_MASK)
    13436 +
    13437 +uint32
    13438 +sb_set_initiator_to(sb_t *sbh, uint32 to)
    13439 +{
    13440 +       sb_info_t *si;
    13441 +       uint origidx, idx;
    13442 +       uint intr_val = 0;
    13443 +       uint32 tmp, ret = 0xffffffff;
    13444 +       sbconfig_t *sb;
    13445 +
    13446 +       si = SB_INFO(sbh);
    13447 +
    13448 +       if ((to & ~TO_MASK) != 0)
    13449 +               return ret;
    13450 +
    13451 +       /* Figure out the master core */
    13452 +       idx = BADIDX;
    13453 +       switch (BUSTYPE(si->sb.bustype)) {
    13454 +       case PCI_BUS:
    13455 +               idx = si->sb.buscoreidx;
    13456 +               break;
    13457 +       case JTAG_BUS:
    13458 +               idx = SB_CC_IDX;
    13459 +               break;
    13460 +       case PCMCIA_BUS:
    13461 +       case SDIO_BUS:
    13462 +               idx = sb_findcoreidx(si, SB_PCMCIA, 0);
    13463 +               break;
    13464 +       case SB_BUS:
    13465 +               if ((idx = sb_findcoreidx(si, SB_MIPS33, 0)) == BADIDX)
    13466 +                       idx = sb_findcoreidx(si, SB_MIPS, 0);
    13467 +               break;
    13468 +       default:
    13469 +               ASSERT(0);
    13470 +       }
    13471 +       if (idx == BADIDX)
    13472 +               return ret;
    13473 +
    13474 +       INTR_OFF(si, intr_val);
    13475 +       origidx = sb_coreidx(sbh);
    13476 +
    13477 +       sb = REGS2SB(sb_setcoreidx(sbh, idx));
    13478 +
    13479 +       tmp = R_SBREG(si, &sb->sbimconfiglow);
    13480 +       ret = tmp & TO_MASK;
    13481 +       W_SBREG(si, &sb->sbimconfiglow, (tmp & ~TO_MASK) | to);
    13482 +
    13483 +       sb_commit(sbh);
    13484 +       sb_setcoreidx(sbh, origidx);
    13485 +       INTR_RESTORE(si, intr_val);
    13486 +       return ret;
    13487 +}
    13488 +
    13489 +void
    13490 +sb_core_disable(sb_t *sbh, uint32 bits)
    13491 +{
    13492 +       sb_info_t *si;
    13493 +       volatile uint32 dummy;
    13494 +       uint32 rej;
    13495 +       sbconfig_t *sb;
    13496 +
    13497 +       si = SB_INFO(sbh);
    13498 +
    13499 +       ASSERT(GOODREGS(si->curmap));
    13500 +       sb = REGS2SB(si->curmap);
    13501 +
    13502 +       /* if core is already in reset, just return */
    13503 +       if (R_SBREG(si, &sb->sbtmstatelow) & SBTML_RESET)
    13504 +               return;
    13505 +
    13506 +       /* reject value changed between sonics 2.2 and 2.3 */
    13507 +       if (si->sb.sonicsrev == SONICS_2_2)
    13508 +               rej = (1 << SBTML_REJ_SHIFT);
    13509 +       else
    13510 +               rej = (2 << SBTML_REJ_SHIFT);
    13511 +
    13512 +       /* if clocks are not enabled, put into reset and return */
    13513 +       if ((R_SBREG(si, &sb->sbtmstatelow) & SBTML_CLK) == 0)
    13514 +               goto disable;
    13515 +
    13516 +       /* set target reject and spin until busy is clear (preserve core-specific bits) */
    13517 +       OR_SBREG(si, &sb->sbtmstatelow, rej);
    13518 +       dummy = R_SBREG(si, &sb->sbtmstatelow);
    13519 +       OSL_DELAY(1);
    13520 +       SPINWAIT((R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_BUSY), 100000);
    13521 +       if (R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_BUSY)
    13522 +               SB_ERROR(("%s: target state still busy\n", __FUNCTION__));
    13523 +
    13524 +       if (R_SBREG(si, &sb->sbidlow) & SBIDL_INIT) {
    13525 +               OR_SBREG(si, &sb->sbimstate, SBIM_RJ);
    13526 +               dummy = R_SBREG(si, &sb->sbimstate);
    13527 +               OSL_DELAY(1);
    13528 +               SPINWAIT((R_SBREG(si, &sb->sbimstate) & SBIM_BY), 100000);
    13529 +       }
    13530 +
    13531 +       /* set reset and reject while enabling the clocks */
    13532 +       W_SBREG(si, &sb->sbtmstatelow, (bits | SBTML_FGC | SBTML_CLK | rej | SBTML_RESET));
    13533 +       dummy = R_SBREG(si, &sb->sbtmstatelow);
    13534 +       OSL_DELAY(10);
    13535 +
    13536 +       /* don't forget to clear the initiator reject bit */
    13537 +       if (R_SBREG(si, &sb->sbidlow) & SBIDL_INIT)
    13538 +               AND_SBREG(si, &sb->sbimstate, ~SBIM_RJ);
    13539 +
    13540 +disable:
    13541 +       /* leave reset and reject asserted */
    13542 +       W_SBREG(si, &sb->sbtmstatelow, (bits | rej | SBTML_RESET));
    13543 +       OSL_DELAY(1);
    13544 +}
    13545 +
    13546 +/* set chip watchdog reset timer to fire in 'ticks' backplane cycles */
    13547 +void
    13548 +sb_watchdog(sb_t *sbh, uint ticks)
    13549 +{
    13550 +       sb_info_t *si = SB_INFO(sbh);
    13551 +
    13552 +       /* make sure we come up in fast clock mode */
    13553 +       sb_clkctl_clk(sbh, CLK_FAST);
    13554 +
    13555 +       /* instant NMI */
    13556 +       switch (si->gpioid) {
    13557 +       case SB_CC:
    13558 +#ifdef __mips__
    13559 +               if (sb_chip(sbh) == BCM4785_CHIP_ID && ticks <= 1)
    13560 +                       MTC0(C0_BROADCOM, 4, (1 << 22));
    13561 +#endif /* __mips__ */
    13562 +               sb_corereg(si, 0, OFFSETOF(chipcregs_t, watchdog), ~0, ticks);
    13563 +#ifdef __mips__
    13564 +               if (sb_chip(sbh) == BCM4785_CHIP_ID && ticks <= 1) {
    13565 +                       __asm__ __volatile__ (
    13566 +                               ".set\tmips3\n\t"
    13567 +                               "sync\n\t"
    13568 +                               "wait\n\t"
    13569 +                               ".set\tmips0"
    13570 +                       );
    13571 +                       while (1);
    13572 +               }
    13573 +#endif /* __mips__ */
    13574 +               break;
    13575 +       case SB_EXTIF:
    13576 +               sb_corereg(si, si->gpioidx, OFFSETOF(extifregs_t, watchdog), ~0, ticks);
    13577 +               break;
    13578 +       }
    13579 +}
    13580 +
    13581 +/* initialize the pcmcia core */
    13582 +void
    13583 +sb_pcmcia_init(sb_t *sbh)
    13584 +{
    13585 +       sb_info_t *si;
    13586 +       uint8 cor = 0;
    13587 +
    13588 +       si = SB_INFO(sbh);
    13589 +
    13590 +       /* enable d11 mac interrupts */
    13591 +       OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_FCR0 + PCMCIA_COR, &cor, 1);
    13592 +       cor |= COR_IRQEN | COR_FUNEN;
    13593 +       OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_FCR0 + PCMCIA_COR, &cor, 1);
    13594 +
    13595 +}
    13596 +
    13597 +
    13598 +/*
    13599 + * Configure the pci core for pci client (NIC) action
    13600 + * coremask is the bitvec of cores by index to be enabled.
    13601 + */
    13602 +void
    13603 +BCMINITFN(sb_pci_setup)(sb_t *sbh, uint coremask)
    13604 +{
    13605 +       sb_info_t *si;
    13606 +       sbconfig_t *sb;
    13607 +       sbpciregs_t *pciregs;
    13608 +       uint32 sbflag;
    13609 +       uint32 w;
    13610 +       uint idx;
    13611 +       int reg_val;
    13612 +
    13613 +       si = SB_INFO(sbh);
    13614 +
    13615 +       /* if not pci bus, we're done */
    13616 +       if (BUSTYPE(si->sb.bustype) != PCI_BUS)
    13617 +               return;
    13618 +
    13619 +       ASSERT(PCI(si) || PCIE(si));
    13620 +       ASSERT(si->sb.buscoreidx != BADIDX);
    13621 +
    13622 +       /* get current core index */
    13623 +       idx = si->curidx;
    13624 +
    13625 +       /* we interrupt on this backplane flag number */
    13626 +       ASSERT(GOODREGS(si->curmap));
    13627 +       sb = REGS2SB(si->curmap);
    13628 +       sbflag = R_SBREG(si, &sb->sbtpsflag) & SBTPS_NUM0_MASK;
    13629 +
    13630 +       /* switch over to pci core */
    13631 +       pciregs = (sbpciregs_t*) sb_setcoreidx(sbh, si->sb.buscoreidx);
    13632 +       sb = REGS2SB(pciregs);
    13633 +
    13634 +       /*
    13635 +        * Enable sb->pci interrupts.  Assume
    13636 +        * PCI rev 2.3 support was added in pci core rev 6 and things changed..
    13637 +        */
    13638 +       if (PCIE(si) || (PCI(si) && ((si->sb.buscorerev) >= 6))) {
    13639 +               /* pci config write to set this core bit in PCIIntMask */
    13640 +               w = OSL_PCI_READ_CONFIG(si->osh, PCI_INT_MASK, sizeof(uint32));
    13641 +               w |= (coremask << PCI_SBIM_SHIFT);
    13642 +               OSL_PCI_WRITE_CONFIG(si->osh, PCI_INT_MASK, sizeof(uint32), w);
    13643 +       } else {
    13644 +               /* set sbintvec bit for our flag number */
    13645 +               OR_SBREG(si, &sb->sbintvec, (1 << sbflag));
    13646 +       }
    13647 +
    13648 +       if (PCI(si)) {
    13649 +               OR_REG(si->osh, &pciregs->sbtopci2, (SBTOPCI_PREF|SBTOPCI_BURST));
    13650 +               if (si->sb.buscorerev >= 11)
    13651 +                       OR_REG(si->osh, &pciregs->sbtopci2, SBTOPCI_RC_READMULTI);
    13652 +               if (si->sb.buscorerev < 5) {
    13653 +                       SET_SBREG(si, &sb->sbimconfiglow, SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
    13654 +                               (0x3 << SBIMCL_RTO_SHIFT) | 0x2);
    13655 +                       sb_commit(sbh);
    13656 +               }
    13657 +       }
    13658 +
    13659 +#ifdef PCIE_SUPPOER
    13660 +       /* PCIE workarounds */
    13661 +       if (PCIE(si)) {
    13662 +               if ((si->sb.buscorerev == 0) || (si->sb.buscorerev == 1)) {
    13663 +                       reg_val = sb_pcie_readreg((void *)sbh, (void *)PCIE_PCIEREGS,
    13664 +                               PCIE_TLP_WORKAROUNDSREG);
    13665 +                       reg_val |= 0x8;
    13666 +                       sb_pcie_writereg((void *)sbh, (void *)PCIE_PCIEREGS,
    13667 +                               PCIE_TLP_WORKAROUNDSREG, reg_val);
    13668 +               }
    13669 +
    13670 +               if (si->sb.buscorerev == 1) {
    13671 +                       reg_val = sb_pcie_readreg((void *)sbh, (void *)PCIE_PCIEREGS,
    13672 +                               PCIE_DLLP_LCREG);
    13673 +                       reg_val |= (0x40);
    13674 +                       sb_pcie_writereg(sbh, (void *)PCIE_PCIEREGS, PCIE_DLLP_LCREG, reg_val);
    13675 +               }
    13676 +
    13677 +               if (si->sb.buscorerev == 0)
    13678 +                       sb_war30841(si);
    13679 +       }
    13680 +#endif
    13681 +
    13682 +       /* switch back to previous core */
    13683 +       sb_setcoreidx(sbh, idx);
    13684 +}
    13685 +
    13686 +uint32
    13687 +sb_base(uint32 admatch)
    13688 +{
    13689 +       uint32 base;
    13690 +       uint type;
    13691 +
    13692 +       type = admatch & SBAM_TYPE_MASK;
    13693 +       ASSERT(type < 3);
    13694 +
    13695 +       base = 0;
    13696 +
    13697 +       if (type == 0) {
    13698 +               base = admatch & SBAM_BASE0_MASK;
    13699 +       } else if (type == 1) {
    13700 +               ASSERT(!(admatch & SBAM_ADNEG));        /* neg not supported */
    13701 +               base = admatch & SBAM_BASE1_MASK;
    13702 +       } else if (type == 2) {
    13703 +               ASSERT(!(admatch & SBAM_ADNEG));        /* neg not supported */
    13704 +               base = admatch & SBAM_BASE2_MASK;
    13705 +       }
    13706 +
    13707 +       return (base);
    13708 +}
    13709 +
    13710 +uint32
    13711 +sb_size(uint32 admatch)
    13712 +{
    13713 +       uint32 size;
    13714 +       uint type;
    13715 +
    13716 +       type = admatch & SBAM_TYPE_MASK;
    13717 +       ASSERT(type < 3);
    13718 +
    13719 +       size = 0;
    13720 +
    13721 +       if (type == 0) {
    13722 +               size = 1 << (((admatch & SBAM_ADINT0_MASK) >> SBAM_ADINT0_SHIFT) + 1);
    13723 +       } else if (type == 1) {
    13724 +               ASSERT(!(admatch & SBAM_ADNEG));        /* neg not supported */
    13725 +               size = 1 << (((admatch & SBAM_ADINT1_MASK) >> SBAM_ADINT1_SHIFT) + 1);
    13726 +       } else if (type == 2) {
    13727 +               ASSERT(!(admatch & SBAM_ADNEG));        /* neg not supported */
    13728 +               size = 1 << (((admatch & SBAM_ADINT2_MASK) >> SBAM_ADINT2_SHIFT) + 1);
    13729 +       }
    13730 +
    13731 +       return (size);
    13732 +}
    13733 +
    13734 +/* return the core-type instantiation # of the current core */
    13735 +uint
    13736 +sb_coreunit(sb_t *sbh)
    13737 +{
    13738 +       sb_info_t *si;
    13739 +       uint idx;
    13740 +       uint coreid;
    13741 +       uint coreunit;
    13742 +       uint i;
    13743 +
    13744 +       si = SB_INFO(sbh);
    13745 +       coreunit = 0;
    13746 +
    13747 +       idx = si->curidx;
    13748 +
    13749 +       ASSERT(GOODREGS(si->curmap));
    13750 +       coreid = sb_coreid(sbh);
    13751 +
    13752 +       /* count the cores of our type */
    13753 +       for (i = 0; i < idx; i++)
    13754 +               if (si->coreid[i] == coreid)
    13755 +                       coreunit++;
    13756 +
    13757 +       return (coreunit);
    13758 +}
    13759 +
    13760 +static INLINE uint32
    13761 +factor6(uint32 x)
    13762 +{
    13763 +       switch (x) {
    13764 +       case CC_F6_2:   return 2;
    13765 +       case CC_F6_3:   return 3;
    13766 +       case CC_F6_4:   return 4;
    13767 +       case CC_F6_5:   return 5;
    13768 +       case CC_F6_6:   return 6;
    13769 +       case CC_F6_7:   return 7;
    13770 +       default:        return 0;
    13771 +       }
    13772 +}
    13773 +
    13774 +/* calculate the speed the SB would run at given a set of clockcontrol values */
    13775 +uint32
    13776 +sb_clock_rate(uint32 pll_type, uint32 n, uint32 m)
    13777 +{
    13778 +       uint32 n1, n2, clock, m1, m2, m3, mc;
    13779 +
    13780 +       n1 = n & CN_N1_MASK;
    13781 +       n2 = (n & CN_N2_MASK) >> CN_N2_SHIFT;
    13782 +
    13783 +       if (pll_type == PLL_TYPE6) {
    13784 +               if (m & CC_T6_MMASK)
    13785 +                       return CC_T6_M1;
    13786 +               else
    13787 +                       return CC_T6_M0;
    13788 +       } else if ((pll_type == PLL_TYPE1) ||
    13789 +                  (pll_type == PLL_TYPE3) ||
    13790 +                  (pll_type == PLL_TYPE4) ||
    13791 +                  (pll_type == PLL_TYPE7)) {
    13792 +               n1 = factor6(n1);
    13793 +               n2 += CC_F5_BIAS;
    13794 +       } else if (pll_type == PLL_TYPE2) {
    13795 +               n1 += CC_T2_BIAS;
    13796 +               n2 += CC_T2_BIAS;
    13797 +               ASSERT((n1 >= 2) && (n1 <= 7));
    13798 +               ASSERT((n2 >= 5) && (n2 <= 23));
    13799 +       } else if (pll_type == PLL_TYPE5) {
    13800 +               return (100000000);
    13801 +       } else
    13802 +               ASSERT(0);
    13803 +       /* PLL types 3 and 7 use BASE2 (25Mhz) */
    13804 +       if ((pll_type == PLL_TYPE3) ||
    13805 +           (pll_type == PLL_TYPE7)) {
    13806 +               clock =  CC_CLOCK_BASE2 * n1 * n2;
    13807 +       } else
    13808 +               clock = CC_CLOCK_BASE1 * n1 * n2;
    13809 +
    13810 +       if (clock == 0)
    13811 +               return 0;
    13812 +
    13813 +       m1 = m & CC_M1_MASK;
    13814 +       m2 = (m & CC_M2_MASK) >> CC_M2_SHIFT;
    13815 +       m3 = (m & CC_M3_MASK) >> CC_M3_SHIFT;
    13816 +       mc = (m & CC_MC_MASK) >> CC_MC_SHIFT;
    13817 +
    13818 +       if ((pll_type == PLL_TYPE1) ||
    13819 +           (pll_type == PLL_TYPE3) ||
    13820 +           (pll_type == PLL_TYPE4) ||
    13821 +           (pll_type == PLL_TYPE7)) {
    13822 +               m1 = factor6(m1);
    13823 +               if ((pll_type == PLL_TYPE1) || (pll_type == PLL_TYPE3))
    13824 +                       m2 += CC_F5_BIAS;
    13825 +               else
    13826 +                       m2 = factor6(m2);
    13827 +               m3 = factor6(m3);
    13828 +
    13829 +               switch (mc) {
    13830 +               case CC_MC_BYPASS:      return (clock);
    13831 +               case CC_MC_M1:          return (clock / m1);
    13832 +               case CC_MC_M1M2:        return (clock / (m1 * m2));
    13833 +               case CC_MC_M1M2M3:      return (clock / (m1 * m2 * m3));
    13834 +               case CC_MC_M1M3:        return (clock / (m1 * m3));
    13835 +               default:                return (0);
    13836 +               }
    13837 +       } else {
    13838 +               ASSERT(pll_type == PLL_TYPE2);
    13839 +
    13840 +               m1 += CC_T2_BIAS;
    13841 +               m2 += CC_T2M2_BIAS;
    13842 +               m3 += CC_T2_BIAS;
    13843 +               ASSERT((m1 >= 2) && (m1 <= 7));
    13844 +               ASSERT((m2 >= 3) && (m2 <= 10));
    13845 +               ASSERT((m3 >= 2) && (m3 <= 7));
    13846 +
    13847 +               if ((mc & CC_T2MC_M1BYP) == 0)
    13848 +                       clock /= m1;
    13849 +               if ((mc & CC_T2MC_M2BYP) == 0)
    13850 +                       clock /= m2;
    13851 +               if ((mc & CC_T2MC_M3BYP) == 0)
    13852 +                       clock /= m3;
    13853 +
    13854 +               return (clock);
    13855 +       }
    13856 +}
    13857 +
    13858 +/* returns the current speed the SB is running at */
    13859 +uint32
    13860 +sb_clock(sb_t *sbh)
    13861 +{
    13862 +       sb_info_t *si;
    13863 +       extifregs_t *eir;
    13864 +       chipcregs_t *cc;
    13865 +       uint32 n, m;
    13866 +       uint idx;
    13867 +       uint32 pll_type, rate;
    13868 +       uint intr_val = 0;
    13869 +
    13870 +       si = SB_INFO(sbh);
    13871 +       idx = si->curidx;
    13872 +       pll_type = PLL_TYPE1;
    13873 +
    13874 +       INTR_OFF(si, intr_val);
    13875 +
    13876 +       /* switch to extif or chipc core */
    13877 +       if ((eir = (extifregs_t *) sb_setcore(sbh, SB_EXTIF, 0))) {
    13878 +               n = R_REG(si->osh, &eir->clockcontrol_n);
    13879 +               m = R_REG(si->osh, &eir->clockcontrol_sb);
    13880 +       } else if ((cc = (chipcregs_t *) sb_setcore(sbh, SB_CC, 0))) {
    13881 +               pll_type = R_REG(si->osh, &cc->capabilities) & CAP_PLL_MASK;
    13882 +               if (pll_type == PLL_NONE) {
    13883 +                       INTR_RESTORE(si, intr_val);
    13884 +                       return 80000000;
    13885 +               }
    13886 +               n = R_REG(si->osh, &cc->clockcontrol_n);
    13887 +               if (pll_type == PLL_TYPE6)
    13888 +                       m = R_REG(si->osh, &cc->clockcontrol_m3);
    13889 +               else if ((pll_type == PLL_TYPE3) && !(BCMINIT(sb_chip)(sbh) == 0x5365))
    13890 +                       m = R_REG(si->osh, &cc->clockcontrol_m2);
    13891 +               else
    13892 +                       m = R_REG(si->osh, &cc->clockcontrol_sb);
    13893 +       } else {
    13894 +               INTR_RESTORE(si, intr_val);
    13895 +               return 0;
    13896 +       }
    13897 +
    13898 +       /* calculate rate */
    13899 +       if (BCMINIT(sb_chip)(sbh) == 0x5365)
    13900 +               rate = 100000000;
    13901 +       else {
    13902 +               rate = sb_clock_rate(pll_type, n, m);
    13903 +
    13904 +               if (pll_type == PLL_TYPE3)
    13905 +                       rate = rate / 2;
    13906 +       }
    13907 +
    13908 +       /* switch back to previous core */
    13909 +       sb_setcoreidx(sbh, idx);
    13910 +
    13911 +       INTR_RESTORE(si, intr_val);
    13912 +
    13913 +       return rate;
    13914 +}
    13915 +
    13916 +/* change logical "focus" to the gpio core for optimized access */
    13917 +void*
    13918 +sb_gpiosetcore(sb_t *sbh)
    13919 +{
    13920 +       sb_info_t *si;
    13921 +
    13922 +       si = SB_INFO(sbh);
    13923 +
    13924 +       return (sb_setcoreidx(sbh, si->gpioidx));
    13925 +}
    13926 +
    13927 +/* mask&set gpiocontrol bits */
    13928 +uint32
    13929 +sb_gpiocontrol(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
    13930 +{
    13931 +       sb_info_t *si;
    13932 +       uint regoff;
    13933 +
    13934 +       si = SB_INFO(sbh);
    13935 +       regoff = 0;
    13936 +
    13937 +       priority = GPIO_DRV_PRIORITY; /* compatibility hack */
    13938 +
    13939 +       /* gpios could be shared on router platforms */
    13940 +       if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
    13941 +               mask = priority ? (sb_gpioreservation & mask) :
    13942 +                       ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
    13943 +               val &= mask;
    13944 +       }
    13945 +
    13946 +       switch (si->gpioid) {
    13947 +       case SB_CC:
    13948 +               regoff = OFFSETOF(chipcregs_t, gpiocontrol);
    13949 +               break;
    13950 +
    13951 +       case SB_PCI:
    13952 +               regoff = OFFSETOF(sbpciregs_t, gpiocontrol);
    13953 +               break;
    13954 +
    13955 +       case SB_EXTIF:
    13956 +               return (0);
    13957 +       }
    13958 +
    13959 +       return (sb_corereg(si, si->gpioidx, regoff, mask, val));
    13960 +}
    13961 +
    13962 +/* mask&set gpio output enable bits */
    13963 +uint32
    13964 +sb_gpioouten(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
    13965 +{
    13966 +       sb_info_t *si;
    13967 +       uint regoff;
    13968 +
    13969 +       si = SB_INFO(sbh);
    13970 +       regoff = 0;
    13971 +
    13972 +       priority = GPIO_DRV_PRIORITY; /* compatibility hack */
    13973 +
    13974 +       /* gpios could be shared on router platforms */
    13975 +       if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
    13976 +               mask = priority ? (sb_gpioreservation & mask) :
    13977 +                       ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
    13978 +               val &= mask;
    13979 +       }
    13980 +
    13981 +       switch (si->gpioid) {
    13982 +       case SB_CC:
    13983 +               regoff = OFFSETOF(chipcregs_t, gpioouten);
    13984 +               break;
    13985 +
    13986 +       case SB_PCI:
    13987 +               regoff = OFFSETOF(sbpciregs_t, gpioouten);
    13988 +               break;
    13989 +
    13990 +       case SB_EXTIF:
    13991 +               regoff = OFFSETOF(extifregs_t, gpio[0].outen);
    13992 +               break;
    13993 +       }
    13994 +
    13995 +       return (sb_corereg(si, si->gpioidx, regoff, mask, val));
    13996 +}
    13997 +
    13998 +/* mask&set gpio output bits */
    13999 +uint32
    14000 +sb_gpioout(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
    14001 +{
    14002 +       sb_info_t *si;
    14003 +       uint regoff;
    14004 +
    14005 +       si = SB_INFO(sbh);
    14006 +       regoff = 0;
    14007 +
    14008 +       priority = GPIO_DRV_PRIORITY; /* compatibility hack */
    14009 +
    14010 +       /* gpios could be shared on router platforms */
    14011 +       if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
    14012 +               mask = priority ? (sb_gpioreservation & mask) :
    14013 +                       ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
    14014 +               val &= mask;
    14015 +       }
    14016 +
    14017 +       switch (si->gpioid) {
    14018 +       case SB_CC:
    14019 +               regoff = OFFSETOF(chipcregs_t, gpioout);
    14020 +               break;
    14021 +
    14022 +       case SB_PCI:
    14023 +               regoff = OFFSETOF(sbpciregs_t, gpioout);
    14024 +               break;
    14025 +
    14026 +       case SB_EXTIF:
    14027 +               regoff = OFFSETOF(extifregs_t, gpio[0].out);
    14028 +               break;
    14029 +       }
    14030 +
    14031 +       return (sb_corereg(si, si->gpioidx, regoff, mask, val));
    14032 +}
    14033 +
    14034 +/* reserve one gpio */
    14035 +uint32
    14036 +sb_gpioreserve(sb_t *sbh, uint32 gpio_bitmask, uint8 priority)
    14037 +{
    14038 +       sb_info_t *si;
    14039 +
    14040 +       si = SB_INFO(sbh);
    14041 +
    14042 +       priority = GPIO_DRV_PRIORITY; /* compatibility hack */
    14043 +
    14044 +       /* only cores on SB_BUS share GPIO's and only applcation users need to
    14045 +        * reserve/release GPIO
    14046 +        */
    14047 +       if ((BUSTYPE(si->sb.bustype) != SB_BUS) || (!priority))  {
    14048 +               ASSERT((BUSTYPE(si->sb.bustype) == SB_BUS) && (priority));
    14049 +               return -1;
    14050 +       }
    14051 +       /* make sure only one bit is set */
    14052 +       if ((!gpio_bitmask) || ((gpio_bitmask) & (gpio_bitmask - 1))) {
    14053 +               ASSERT((gpio_bitmask) && !((gpio_bitmask) & (gpio_bitmask - 1)));
    14054 +               return -1;
    14055 +       }
    14056 +
    14057 +       /* already reserved */
    14058 +       if (sb_gpioreservation & gpio_bitmask)
    14059 +               return -1;
    14060 +       /* set reservation */
    14061 +       sb_gpioreservation |= gpio_bitmask;
    14062 +
    14063 +       return sb_gpioreservation;
    14064 +}
    14065 +
    14066 +/* release one gpio */
    14067 +/*
    14068 + * releasing the gpio doesn't change the current value on the GPIO last write value
    14069 + * persists till some one overwrites it
    14070 +*/
    14071 +
    14072 +uint32
    14073 +sb_gpiorelease(sb_t *sbh, uint32 gpio_bitmask, uint8 priority)
    14074 +{
    14075 +       sb_info_t *si;
    14076 +
    14077 +       si = SB_INFO(sbh);
    14078 +
    14079 +       priority = GPIO_DRV_PRIORITY; /* compatibility hack */
    14080 +
    14081 +       /* only cores on SB_BUS share GPIO's and only applcation users need to
    14082 +        * reserve/release GPIO
    14083 +        */
    14084 +       if ((BUSTYPE(si->sb.bustype) != SB_BUS) || (!priority))  {
    14085 +               ASSERT((BUSTYPE(si->sb.bustype) == SB_BUS) && (priority));
    14086 +               return -1;
    14087 +       }
    14088 +       /* make sure only one bit is set */
    14089 +       if ((!gpio_bitmask) || ((gpio_bitmask) & (gpio_bitmask - 1))) {
    14090 +               ASSERT((gpio_bitmask) && !((gpio_bitmask) & (gpio_bitmask - 1)));
    14091 +               return -1;
    14092 +       }
    14093 +
    14094 +       /* already released */
    14095 +       if (!(sb_gpioreservation & gpio_bitmask))
    14096 +               return -1;
    14097 +
    14098 +       /* clear reservation */
    14099 +       sb_gpioreservation &= ~gpio_bitmask;
    14100 +
    14101 +       return sb_gpioreservation;
    14102 +}
    14103 +
    14104 +/* return the current gpioin register value */
    14105 +uint32
    14106 +sb_gpioin(sb_t *sbh)
    14107 +{
    14108 +       sb_info_t *si;
    14109 +       uint regoff;
    14110 +
    14111 +       si = SB_INFO(sbh);
    14112 +       regoff = 0;
    14113 +
    14114 +       switch (si->gpioid) {
    14115 +       case SB_CC:
    14116 +               regoff = OFFSETOF(chipcregs_t, gpioin);
    14117 +               break;
    14118 +
    14119 +       case SB_PCI:
    14120 +               regoff = OFFSETOF(sbpciregs_t, gpioin);
    14121 +               break;
    14122 +
    14123 +       case SB_EXTIF:
    14124 +               regoff = OFFSETOF(extifregs_t, gpioin);
    14125 +               break;
    14126 +       }
    14127 +
    14128 +       return (sb_corereg(si, si->gpioidx, regoff, 0, 0));
    14129 +}
    14130 +
    14131 +/* mask&set gpio interrupt polarity bits */
    14132 +uint32
    14133 +sb_gpiointpolarity(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
    14134 +{
    14135 +       sb_info_t *si;
    14136 +       uint regoff;
    14137 +
    14138 +       si = SB_INFO(sbh);
    14139 +       regoff = 0;
    14140 +
    14141 +       priority = GPIO_DRV_PRIORITY; /* compatibility hack */
    14142 +
    14143 +       /* gpios could be shared on router platforms */
    14144 +       if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
    14145 +               mask = priority ? (sb_gpioreservation & mask) :
    14146 +                       ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
    14147 +               val &= mask;
    14148 +       }
    14149 +
    14150 +       switch (si->gpioid) {
    14151 +       case SB_CC:
    14152 +               regoff = OFFSETOF(chipcregs_t, gpiointpolarity);
    14153 +               break;
    14154 +
    14155 +       case SB_PCI:
    14156 +               /* pci gpio implementation does not support interrupt polarity */
    14157 +               ASSERT(0);
    14158 +               break;
    14159 +
    14160 +       case SB_EXTIF:
    14161 +               regoff = OFFSETOF(extifregs_t, gpiointpolarity);
    14162 +               break;
    14163 +       }
    14164 +
    14165 +       return (sb_corereg(si, si->gpioidx, regoff, mask, val));
    14166 +}
    14167 +
    14168 +/* mask&set gpio interrupt mask bits */
    14169 +uint32
    14170 +sb_gpiointmask(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
    14171 +{
    14172 +       sb_info_t *si;
    14173 +       uint regoff;
    14174 +
    14175 +       si = SB_INFO(sbh);
    14176 +       regoff = 0;
    14177 +
    14178 +       priority = GPIO_DRV_PRIORITY; /* compatibility hack */
    14179 +
    14180 +       /* gpios could be shared on router platforms */
    14181 +       if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
    14182 +               mask = priority ? (sb_gpioreservation & mask) :
    14183 +                       ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
    14184 +               val &= mask;
    14185 +       }
    14186 +
    14187 +       switch (si->gpioid) {
    14188 +       case SB_CC:
    14189 +               regoff = OFFSETOF(chipcregs_t, gpiointmask);
    14190 +               break;
    14191 +
    14192 +       case SB_PCI:
    14193 +               /* pci gpio implementation does not support interrupt mask */
    14194 +               ASSERT(0);
    14195 +               break;
    14196 +
    14197 +       case SB_EXTIF:
    14198 +               regoff = OFFSETOF(extifregs_t, gpiointmask);
    14199 +               break;
    14200 +       }
    14201 +
    14202 +       return (sb_corereg(si, si->gpioidx, regoff, mask, val));
    14203 +}
    14204 +
    14205 +/* assign the gpio to an led */
    14206 +uint32
    14207 +sb_gpioled(sb_t *sbh, uint32 mask, uint32 val)
    14208 +{
    14209 +       sb_info_t *si;
    14210 +
    14211 +       si = SB_INFO(sbh);
    14212 +       if (si->sb.ccrev < 16)
    14213 +               return -1;
    14214 +
    14215 +       /* gpio led powersave reg */
    14216 +       return (sb_corereg(si, 0, OFFSETOF(chipcregs_t, gpiotimeroutmask), mask, val));
    14217 +}
    14218 +
    14219 +/* mask & set gpio timer val */
    14220 +uint32
    14221 +sb_gpiotimerval(sb_t *sbh, uint32 mask, uint32 gpiotimerval)
    14222 +{
    14223 +       sb_info_t *si;
    14224 +       si = SB_INFO(sbh);
    14225 +
    14226 +       if (si->sb.ccrev < 16)
    14227 +               return -1;
    14228 +
    14229 +       return (sb_corereg(si, 0, OFFSETOF(chipcregs_t, gpiotimerval), mask, gpiotimerval));
    14230 +}
    14231 +
    14232 +
    14233 +/* return the slow clock source - LPO, XTAL, or PCI */
    14234 +static uint
    14235 +sb_slowclk_src(sb_info_t *si)
    14236 +{
    14237 +       chipcregs_t *cc;
    14238 +
    14239 +
    14240 +       ASSERT(sb_coreid(&si->sb) == SB_CC);
    14241 +
    14242 +       if (si->sb.ccrev < 6) {
    14243 +               if ((BUSTYPE(si->sb.bustype) == PCI_BUS) &&
    14244 +                   (OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUT, sizeof(uint32)) &
    14245 +                    PCI_CFG_GPIO_SCS))
    14246 +                       return (SCC_SS_PCI);
    14247 +               else
    14248 +                       return (SCC_SS_XTAL);
    14249 +       } else if (si->sb.ccrev < 10) {
    14250 +               cc = (chipcregs_t*) sb_setcoreidx(&si->sb, si->curidx);
    14251 +               return (R_REG(si->osh, &cc->slow_clk_ctl) & SCC_SS_MASK);
    14252 +       } else  /* Insta-clock */
    14253 +               return (SCC_SS_XTAL);
    14254 +}
    14255 +
    14256 +/* return the ILP (slowclock) min or max frequency */
    14257 +static uint
    14258 +sb_slowclk_freq(sb_info_t *si, bool max)
    14259 +{
    14260 +       chipcregs_t *cc;
    14261 +       uint32 slowclk;
    14262 +       uint div;
    14263 +
    14264 +
    14265 +       ASSERT(sb_coreid(&si->sb) == SB_CC);
    14266 +
    14267 +       cc = (chipcregs_t*) sb_setcoreidx(&si->sb, si->curidx);
    14268 +
    14269 +       /* shouldn't be here unless we've established the chip has dynamic clk control */
    14270 +       ASSERT(R_REG(si->osh, &cc->capabilities) & CAP_PWR_CTL);
    14271 +
    14272 +       slowclk = sb_slowclk_src(si);
    14273 +       if (si->sb.ccrev < 6) {
    14274 +               if (slowclk == SCC_SS_PCI)
    14275 +                       return (max? (PCIMAXFREQ/64) : (PCIMINFREQ/64));
    14276 +               else
    14277 +                       return (max? (XTALMAXFREQ/32) : (XTALMINFREQ/32));
    14278 +       } else if (si->sb.ccrev < 10) {
    14279 +               div = 4 * (((R_REG(si->osh, &cc->slow_clk_ctl) & SCC_CD_MASK) >> SCC_CD_SHIFT) + 1);
    14280 +               if (slowclk == SCC_SS_LPO)
    14281 +                       return (max? LPOMAXFREQ : LPOMINFREQ);
    14282 +               else if (slowclk == SCC_SS_XTAL)
    14283 +                       return (max? (XTALMAXFREQ/div) : (XTALMINFREQ/div));
    14284 +               else if (slowclk == SCC_SS_PCI)
    14285 +                       return (max? (PCIMAXFREQ/div) : (PCIMINFREQ/div));
    14286 +               else
    14287 +                       ASSERT(0);
    14288 +       } else {
    14289 +               /* Chipc rev 10 is InstaClock */
    14290 +               div = R_REG(si->osh, &cc->system_clk_ctl) >> SYCC_CD_SHIFT;
    14291 +               div = 4 * (div + 1);
    14292 +               return (max ? XTALMAXFREQ : (XTALMINFREQ/div));
    14293 +       }
    14294 +       return (0);
    14295 +}
    14296 +
    14297 +static void
    14298 +BCMINITFN(sb_clkctl_setdelay)(sb_info_t *si, void *chipcregs)
    14299 +{
    14300 +       chipcregs_t * cc;
    14301 +       uint slowmaxfreq, pll_delay, slowclk;
    14302 +       uint pll_on_delay, fref_sel_delay;
    14303 +
    14304 +       pll_delay = PLL_DELAY;
    14305 +
    14306 +       /* If the slow clock is not sourced by the xtal then add the xtal_on_delay
    14307 +        * since the xtal will also be powered down by dynamic clk control logic.
    14308 +        */
    14309 +
    14310 +       slowclk = sb_slowclk_src(si);
    14311 +       if (slowclk != SCC_SS_XTAL)
    14312 +               pll_delay += XTAL_ON_DELAY;
    14313 +
    14314 +       /* Starting with 4318 it is ILP that is used for the delays */
    14315 +       slowmaxfreq = sb_slowclk_freq(si, (si->sb.ccrev >= 10) ? FALSE : TRUE);
    14316 +
    14317 +       pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
    14318 +       fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
    14319 +
    14320 +       cc = (chipcregs_t *)chipcregs;
    14321 +       W_REG(si->osh, &cc->pll_on_delay, pll_on_delay);
    14322 +       W_REG(si->osh, &cc->fref_sel_delay, fref_sel_delay);
    14323 +}
    14324 +
    14325 +/* initialize power control delay registers */
    14326 +void
    14327 +BCMINITFN(sb_clkctl_init)(sb_t *sbh)
    14328 +{
    14329 +       sb_info_t *si;
    14330 +       uint origidx;
    14331 +       chipcregs_t *cc;
    14332 +
    14333 +       si = SB_INFO(sbh);
    14334 +
    14335 +       origidx = si->curidx;
    14336 +
    14337 +       if ((cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0)) == NULL)
    14338 +               return;
    14339 +
    14340 +       if ((si->sb.chip == BCM4321_CHIP_ID) && (si->sb.chiprev < 2))
    14341 +               W_REG(si->osh, &cc->chipcontrol,
    14342 +                     (si->sb.chiprev == 0) ? CHIPCTRL_4321A0_DEFAULT : CHIPCTRL_4321A1_DEFAULT);
    14343 +
    14344 +       if (!(R_REG(si->osh, &cc->capabilities) & CAP_PWR_CTL))
    14345 +               goto done;
    14346 +
    14347 +       /* set all Instaclk chip ILP to 1 MHz */
    14348 +       else if (si->sb.ccrev >= 10)
    14349 +               SET_REG(si->osh, &cc->system_clk_ctl, SYCC_CD_MASK,
    14350 +                       (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
    14351 +
    14352 +       sb_clkctl_setdelay(si, (void *)cc);
    14353 +
    14354 +done:
    14355 +       sb_setcoreidx(sbh, origidx);
    14356 +}
    14357 +
    14358 +/* return the value suitable for writing to the dot11 core FAST_PWRUP_DELAY register */
    14359 +uint16
    14360 +sb_clkctl_fast_pwrup_delay(sb_t *sbh)
    14361 +{
    14362 +       sb_info_t *si;
    14363 +       uint origidx;
    14364 +       chipcregs_t *cc;
    14365 +       uint slowminfreq;
    14366 +       uint16 fpdelay;
    14367 +       uint intr_val = 0;
    14368 +
    14369 +       si = SB_INFO(sbh);
    14370 +       fpdelay = 0;
    14371 +       origidx = si->curidx;
    14372 +
    14373 +       INTR_OFF(si, intr_val);
    14374 +
    14375 +       if ((cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0)) == NULL)
    14376 +               goto done;
    14377 +
    14378 +       if (!(R_REG(si->osh, &cc->capabilities) & CAP_PWR_CTL))
    14379 +               goto done;
    14380 +
    14381 +       slowminfreq = sb_slowclk_freq(si, FALSE);
    14382 +       fpdelay = (((R_REG(si->osh, &cc->pll_on_delay) + 2) * 1000000) +
    14383 +                  (slowminfreq - 1)) / slowminfreq;
    14384 +
    14385 +done:
    14386 +       sb_setcoreidx(sbh, origidx);
    14387 +       INTR_RESTORE(si, intr_val);
    14388 +       return (fpdelay);
    14389 +}
    14390 +
    14391 +/* turn primary xtal and/or pll off/on */
    14392 +int
    14393 +sb_clkctl_xtal(sb_t *sbh, uint what, bool on)
    14394 +{
    14395 +       sb_info_t *si;
    14396 +       uint32 in, out, outen;
    14397 +
    14398 +       si = SB_INFO(sbh);
    14399 +
    14400 +       switch (BUSTYPE(si->sb.bustype)) {
    14401 +
    14402 +
    14403 +               case PCMCIA_BUS:
    14404 +                       return (0);
    14405 +
    14406 +
    14407 +               case PCI_BUS:
    14408 +
    14409 +                       /* pcie core doesn't have any mapping to control the xtal pu */
    14410 +                       if (PCIE(si))
    14411 +                               return -1;
    14412 +
    14413 +                       in = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_IN, sizeof(uint32));
    14414 +                       out = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUT, sizeof(uint32));
    14415 +                       outen = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUTEN, sizeof(uint32));
    14416 +
    14417 +                       /*
    14418 +                        * Avoid glitching the clock if GPRS is already using it.
    14419 +                        * We can't actually read the state of the PLLPD so we infer it
    14420 +                        * by the value of XTAL_PU which *is* readable via gpioin.
    14421 +                        */
    14422 +                       if (on && (in & PCI_CFG_GPIO_XTAL))
    14423 +                               return (0);
    14424 +
    14425 +                       if (what & XTAL)
    14426 +                               outen |= PCI_CFG_GPIO_XTAL;
    14427 +                       if (what & PLL)
    14428 +                               outen |= PCI_CFG_GPIO_PLL;
    14429 +
    14430 +                       if (on) {
    14431 +                               /* turn primary xtal on */
    14432 +                               if (what & XTAL) {
    14433 +                                       out |= PCI_CFG_GPIO_XTAL;
    14434 +                                       if (what & PLL)
    14435 +                                               out |= PCI_CFG_GPIO_PLL;
    14436 +                                       OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT,
    14437 +                                                            sizeof(uint32), out);
    14438 +                                       OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUTEN,
    14439 +                                                            sizeof(uint32), outen);
    14440 +                                       OSL_DELAY(XTAL_ON_DELAY);
    14441 +                               }
    14442 +
    14443 +                               /* turn pll on */
    14444 +                               if (what & PLL) {
    14445 +                                       out &= ~PCI_CFG_GPIO_PLL;
    14446 +                                       OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT,
    14447 +                                                            sizeof(uint32), out);
    14448 +                                       OSL_DELAY(2000);
    14449 +                               }
    14450 +                       } else {
    14451 +                               if (what & XTAL)
    14452 +                                       out &= ~PCI_CFG_GPIO_XTAL;
    14453 +                               if (what & PLL)
    14454 +                                       out |= PCI_CFG_GPIO_PLL;
    14455 +                               OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT, sizeof(uint32), out);
    14456 +                               OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUTEN, sizeof(uint32),
    14457 +                                                    outen);
    14458 +                       }
    14459 +
    14460 +               default:
    14461 +                       return (-1);
    14462 +       }
    14463 +
    14464 +       return (0);
    14465 +}
    14466 +
    14467 +/* set dynamic clk control mode (forceslow, forcefast, dynamic) */
    14468 +/*   returns true if we are forcing fast clock */
    14469 +bool
    14470 +sb_clkctl_clk(sb_t *sbh, uint mode)
    14471 +{
    14472 +       sb_info_t *si;
    14473 +       uint origidx;
    14474 +       chipcregs_t *cc;
    14475 +       uint32 scc;
    14476 +       uint intr_val = 0;
    14477 +
    14478 +       si = SB_INFO(sbh);
    14479 +
    14480 +       /* chipcommon cores prior to rev6 don't support dynamic clock control */
    14481 +       if (si->sb.ccrev < 6)
    14482 +               return (FALSE);
    14483 +
    14484 +
    14485 +       /* Chips with ccrev 10 are EOL and they don't have SYCC_HR which we use below */
    14486 +       ASSERT(si->sb.ccrev != 10);
    14487 +
    14488 +       INTR_OFF(si, intr_val);
    14489 +
    14490 +       origidx = si->curidx;
    14491 +
    14492 +       if (sb_setcore(sbh, SB_MIPS33, 0) && (sb_corerev(&si->sb) <= 7) &&
    14493 +           (BUSTYPE(si->sb.bustype) == SB_BUS) && (si->sb.ccrev >= 10))
    14494 +               goto done;
    14495 +
    14496 +       /* PR32414WAR  "Force HT clock on" all the time, no dynamic clk ctl */
    14497 +       if ((si->sb.chip == BCM4311_CHIP_ID) && (si->sb.chiprev <= 1))
    14498 +               goto done;
    14499 +
    14500 +       cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0);
    14501 +       ASSERT(cc != NULL);
    14502 +
    14503 +       if (!(R_REG(si->osh, &cc->capabilities) & CAP_PWR_CTL))
    14504 +               goto done;
    14505 +
    14506 +       switch (mode) {
    14507 +       case CLK_FAST:  /* force fast (pll) clock */
    14508 +               if (si->sb.ccrev < 10) {
    14509 +                       /* don't forget to force xtal back on before we clear SCC_DYN_XTAL.. */
    14510 +                       sb_clkctl_xtal(&si->sb, XTAL, ON);
    14511 +
    14512 +                       SET_REG(si->osh, &cc->slow_clk_ctl, (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
    14513 +               } else
    14514 +                       OR_REG(si->osh, &cc->system_clk_ctl, SYCC_HR);
    14515 +               /* wait for the PLL */
    14516 +               OSL_DELAY(PLL_DELAY);
    14517 +               break;
    14518 +
    14519 +       case CLK_DYNAMIC:       /* enable dynamic clock control */
    14520 +
    14521 +               if (si->sb.ccrev < 10) {
    14522 +                       scc = R_REG(si->osh, &cc->slow_clk_ctl);
    14523 +                       scc &= ~(SCC_FS | SCC_IP | SCC_XC);
    14524 +                       if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
    14525 +                               scc |= SCC_XC;
    14526 +                       W_REG(si->osh, &cc->slow_clk_ctl, scc);
    14527 +
    14528 +                       /* for dynamic control, we have to release our xtal_pu "force on" */
    14529 +                       if (scc & SCC_XC)
    14530 +                               sb_clkctl_xtal(&si->sb, XTAL, OFF);
    14531 +               } else {
    14532 +                       /* Instaclock */
    14533 +                       AND_REG(si->osh, &cc->system_clk_ctl, ~SYCC_HR);
    14534 +               }
    14535 +               break;
    14536 +
    14537 +       default:
    14538 +               ASSERT(0);
    14539 +       }
    14540 +
    14541 +done:
    14542 +       sb_setcoreidx(sbh, origidx);
    14543 +       INTR_RESTORE(si, intr_val);
    14544 +       return (mode == CLK_FAST);
    14545 +}
    14546 +
    14547 +/* register driver interrupt disabling and restoring callback functions */
    14548 +void
    14549 +sb_register_intr_callback(sb_t *sbh, void *intrsoff_fn, void *intrsrestore_fn,
    14550 +                          void *intrsenabled_fn, void *intr_arg)
    14551 +{
    14552 +       sb_info_t *si;
    14553 +
    14554 +       si = SB_INFO(sbh);
    14555 +       si->intr_arg = intr_arg;
    14556 +       si->intrsoff_fn = (sb_intrsoff_t)intrsoff_fn;
    14557 +       si->intrsrestore_fn = (sb_intrsrestore_t)intrsrestore_fn;
    14558 +       si->intrsenabled_fn = (sb_intrsenabled_t)intrsenabled_fn;
    14559 +       /* save current core id.  when this function called, the current core
    14560 +        * must be the core which provides driver functions(il, et, wl, etc.)
    14561 +        */
    14562 +       si->dev_coreid = si->coreid[si->curidx];
    14563 +}
    14564 +
    14565 +
    14566 +int
    14567 +sb_corepciid(sb_t *sbh, uint func, uint16 *pcivendor, uint16 *pcidevice,
    14568 +             uint8 *pciclass, uint8 *pcisubclass, uint8 *pciprogif,
    14569 +             uint8 *pciheader)
    14570 +{
    14571 +       uint16 vendor = 0xffff, device = 0xffff;
    14572 +       uint core, unit;
    14573 +       uint chip, chippkg;
    14574 +       uint nfunc;
    14575 +       char varname[SB_DEVPATH_BUFSZ + 8];
    14576 +       uint8 class, subclass, progif;
    14577 +       char devpath[SB_DEVPATH_BUFSZ];
    14578 +       uint8 header;
    14579 +
    14580 +       core = sb_coreid(sbh);
    14581 +       unit = sb_coreunit(sbh);
    14582 +
    14583 +       chip = sb_chip(sbh);
    14584 +       chippkg = sb_chippkg(sbh);
    14585 +
    14586 +       progif = 0;
    14587 +       header = PCI_HEADER_NORMAL;
    14588 +
    14589 +       /* Verify whether the function exists for the core */
    14590 +       nfunc = (core == SB_USB20H) ? 2 : 1;
    14591 +       if (func >= nfunc)
    14592 +               return BCME_ERROR;
    14593 +
    14594 +       /* Known vendor translations */
    14595 +       switch (sb_corevendor(sbh)) {
    14596 +       case SB_VEND_BCM:
    14597 +               vendor = VENDOR_BROADCOM;
    14598 +               break;
    14599 +       default:
    14600 +               return BCME_ERROR;
    14601 +       }
    14602 +
    14603 +       /* Determine class based on known core codes */
    14604 +       switch (core) {
    14605 +       case SB_ILINE20:
    14606 +               class = PCI_CLASS_NET;
    14607 +               subclass = PCI_NET_ETHER;
    14608 +               device = BCM47XX_ILINE_ID;
    14609 +               break;
    14610 +       case SB_ENET:
    14611 +               class = PCI_CLASS_NET;
    14612 +               subclass = PCI_NET_ETHER;
    14613 +               device = BCM47XX_ENET_ID;
    14614 +               break;
    14615 +       case SB_GIGETH:
    14616 +               class = PCI_CLASS_NET;
    14617 +               subclass = PCI_NET_ETHER;
    14618 +               device = BCM47XX_GIGETH_ID;
    14619 +               break;
    14620 +       case SB_SDRAM:
    14621 +       case SB_MEMC:
    14622 +               class = PCI_CLASS_MEMORY;
    14623 +               subclass = PCI_MEMORY_RAM;
    14624 +               device = (uint16)core;
    14625 +               break;
    14626 +       case SB_PCI:
    14627 +       case SB_PCIE:
    14628 +               class = PCI_CLASS_BRIDGE;
    14629 +               subclass = PCI_BRIDGE_PCI;
    14630 +               device = (uint16)core;
    14631 +               header = PCI_HEADER_BRIDGE;
    14632 +               break;
    14633 +       case SB_MIPS:
    14634 +       case SB_MIPS33:
    14635 +               class = PCI_CLASS_CPU;
    14636 +               subclass = PCI_CPU_MIPS;
    14637 +               device = (uint16)core;
    14638 +               break;
    14639 +       case SB_CODEC:
    14640 +               class = PCI_CLASS_COMM;
    14641 +               subclass = PCI_COMM_MODEM;
    14642 +               device = BCM47XX_V90_ID;
    14643 +               break;
    14644 +       case SB_USB:
    14645 +               class = PCI_CLASS_SERIAL;
    14646 +               subclass = PCI_SERIAL_USB;
    14647 +               progif = 0x10; /* OHCI */
    14648 +               device = BCM47XX_USB_ID;
    14649 +               break;
    14650 +       case SB_USB11H:
    14651 +               class = PCI_CLASS_SERIAL;
    14652 +               subclass = PCI_SERIAL_USB;
    14653 +               progif = 0x10; /* OHCI */
    14654 +               device = BCM47XX_USBH_ID;
    14655 +               break;
    14656 +       case SB_USB20H:
    14657 +               class = PCI_CLASS_SERIAL;
    14658 +               subclass = PCI_SERIAL_USB;
    14659 +               progif = func == 0 ? 0x10 : 0x20; /* OHCI/EHCI */
    14660 +               device = BCM47XX_USB20H_ID;
    14661 +               header = 0x80; /* multifunction */
    14662 +               break;
    14663 +       case SB_USB11D:
    14664 +               class = PCI_CLASS_SERIAL;
    14665 +               subclass = PCI_SERIAL_USB;
    14666 +               device = BCM47XX_USBD_ID;
    14667 +               break;
    14668 +       case SB_USB20D:
    14669 +               class = PCI_CLASS_SERIAL;
    14670 +               subclass = PCI_SERIAL_USB;
    14671 +               device = BCM47XX_USB20D_ID;
    14672 +               break;
    14673 +       case SB_IPSEC:
    14674 +               class = PCI_CLASS_CRYPT;
    14675 +               subclass = PCI_CRYPT_NETWORK;
    14676 +               device = BCM47XX_IPSEC_ID;
    14677 +               break;
    14678 +       case SB_ROBO:
    14679 +               class = PCI_CLASS_NET;
    14680 +               subclass = PCI_NET_OTHER;
    14681 +               device = BCM47XX_ROBO_ID;
    14682 +               break;
    14683 +       case SB_EXTIF:
    14684 +       case SB_CC:
    14685 +               class = PCI_CLASS_MEMORY;
    14686 +               subclass = PCI_MEMORY_FLASH;
    14687 +               device = (uint16)core;
    14688 +               break;
    14689 +       case SB_D11:
    14690 +               class = PCI_CLASS_NET;
    14691 +               subclass = PCI_NET_OTHER;
    14692 +               /* Let nvram variable override core ID */
    14693 +               sb_devpath(sbh, devpath, sizeof(devpath));
    14694 +               sprintf(varname, "%sdevid", devpath);
    14695 +               if ((device = (uint16)getintvar(NULL, varname)))
    14696 +                       break;
    14697 +               /*
    14698 +               * no longer support wl%did, but keep the code
    14699 +               * here for backward compatibility.
    14700 +               */
    14701 +               sprintf(varname, "wl%did", unit);
    14702 +               if ((device = (uint16)getintvar(NULL, varname)))
    14703 +                       break;
    14704 +               /* Chip specific conversion */
    14705 +               if (chip == BCM4712_CHIP_ID) {
    14706 +                       if (chippkg == BCM4712SMALL_PKG_ID)
    14707 +                               device = BCM4306_D11G_ID;
    14708 +                       else
    14709 +                               device = BCM4306_D11DUAL_ID;
     8150+               /* Known vendor translations */
     8151+               switch (vendor) {
     8152+               case SB_VEND_BCM:
     8153+                       vendor = VENDOR_BROADCOM;
    147108154+                       break;
    147118155+               }
    14712 +               /* ignore it */
    14713 +               device = 0xffff;
    14714 +               break;
    14715 +       case SB_SATAXOR:
    14716 +               class = PCI_CLASS_XOR;
    14717 +               subclass = PCI_XOR_QDMA;
    14718 +               device = BCM47XX_SATAXOR_ID;
    14719 +               break;
    14720 +       case SB_ATA100:
    14721 +               class = PCI_CLASS_DASDI;
    14722 +               subclass = PCI_DASDI_IDE;
    14723 +               device = BCM47XX_ATA100_ID;
    14724 +               break;
    14725 +
    14726 +       default:
    14727 +               class = subclass = progif = 0xff;
    14728 +               device = (uint16)core;
    14729 +               break;
    14730 +       }
    14731 +
    14732 +       *pcivendor = vendor;
    14733 +       *pcidevice = device;
    14734 +       *pciclass = class;
    14735 +       *pcisubclass = subclass;
    14736 +       *pciprogif = progif;
    14737 +       *pciheader = header;
    14738 +
     8156+
     8157+               /* Determine class based on known core codes */
     8158+               switch (core) {
     8159+               case SB_ILINE20:
     8160+                       class = PCI_CLASS_NET;
     8161+                       subclass = PCI_NET_ETHER;
     8162+                       core = BCM47XX_ILINE_ID;
     8163+                       break;
     8164+               case SB_ILINE100:
     8165+                       class = PCI_CLASS_NET;
     8166+                       subclass = PCI_NET_ETHER;
     8167+                       core = BCM4610_ILINE_ID;
     8168+                       break;
     8169+               case SB_ENET:
     8170+                       class = PCI_CLASS_NET;
     8171+                       subclass = PCI_NET_ETHER;
     8172+                       core = BCM47XX_ENET_ID;
     8173+                       break;
     8174+               case SB_SDRAM:
     8175+               case SB_MEMC:
     8176+                       class = PCI_CLASS_MEMORY;
     8177+                       subclass = PCI_MEMORY_RAM;
     8178+                       break;
     8179+               case SB_PCI:
     8180+                       class = PCI_CLASS_BRIDGE;
     8181+                       subclass = PCI_BRIDGE_PCI;
     8182+                       break;
     8183+               case SB_MIPS:
     8184+               case SB_MIPS33:
     8185+                       class = PCI_CLASS_CPU;
     8186+                       subclass = PCI_CPU_MIPS;
     8187+                       break;
     8188+               case SB_CODEC:
     8189+                       class = PCI_CLASS_COMM;
     8190+                       subclass = PCI_COMM_MODEM;
     8191+                       core = BCM47XX_V90_ID;
     8192+                       break;
     8193+               case SB_USB:
     8194+                       class = PCI_CLASS_SERIAL;
     8195+                       subclass = PCI_SERIAL_USB;
     8196+                       progif = 0x10; /* OHCI */
     8197+                       core = BCM47XX_USB_ID;
     8198+                       break;
     8199+               case SB_USB11H:
     8200+                       class = PCI_CLASS_SERIAL;
     8201+                       subclass = PCI_SERIAL_USB;
     8202+                       progif = 0x10; /* OHCI */
     8203+                       core = BCM47XX_USBH_ID;
     8204+                       break;
     8205+               case SB_USB11D:
     8206+                       class = PCI_CLASS_SERIAL;
     8207+                       subclass = PCI_SERIAL_USB;
     8208+                       core = BCM47XX_USBD_ID;
     8209+                       break;
     8210+               case SB_IPSEC:
     8211+                       class = PCI_CLASS_CRYPT;
     8212+                       subclass = PCI_CRYPT_NETWORK;
     8213+                       core = BCM47XX_IPSEC_ID;
     8214+                       break;
     8215+               case SB_ROBO:
     8216+                       class = PCI_CLASS_NET;
     8217+                       subclass = PCI_NET_OTHER;
     8218+                       core = BCM47XX_ROBO_ID;
     8219+                       break;
     8220+               case SB_EXTIF:
     8221+               case SB_CC:
     8222+                       class = PCI_CLASS_MEMORY;
     8223+                       subclass = PCI_MEMORY_FLASH;
     8224+                       break;
     8225+               case SB_D11:
     8226+                       class = PCI_CLASS_NET;
     8227+                       subclass = PCI_NET_OTHER;
     8228+                       /* Let an nvram variable override this */
     8229+                       sprintf(varname, "wl%did", wlidx);
     8230+                       wlidx++;
     8231+                       if ((core = getintvar(NULL, varname)) == 0) {
     8232+                               if (chip == BCM4712_DEVICE_ID) {
     8233+                                       if (chippkg == BCM4712SMALL_PKG_ID)
     8234+                                               core = BCM4306_D11G_ID;
     8235+                                       else
     8236+                                               core = BCM4306_D11DUAL_ID;
     8237+                               } else {
     8238+                                       /* 4310 */
     8239+                                       core = BCM4310_D11B_ID;
     8240+                               }
     8241+                       }
     8242+                       break;
     8243+
     8244+               default:
     8245+                       class = subclass = progif = 0xff;
     8246+                       break;
     8247+               }
     8248+
     8249+               /* Supported translations */
     8250+               cfg->vendor = htol16(vendor);
     8251+               cfg->device = htol16(core);
     8252+               cfg->rev_id = chiprev;
     8253+               cfg->prog_if = progif;
     8254+               cfg->sub_class = subclass;
     8255+               cfg->base_class = class;
     8256+               cfg->base[0] = htol32(sb_base(R_REG(&sb->sbadmatch0)));
     8257+               cfg->base[1] = htol32(sb_base(R_REG(&sb->sbadmatch1)));
     8258+               cfg->base[2] = htol32(sb_base(R_REG(&sb->sbadmatch2)));
     8259+               cfg->base[3] = htol32(sb_base(R_REG(&sb->sbadmatch3)));
     8260+               cfg->base[4] = 0;
     8261+               cfg->base[5] = 0;
     8262+               if (class == PCI_CLASS_BRIDGE && subclass == PCI_BRIDGE_PCI)
     8263+                       cfg->header_type = PCI_HEADER_BRIDGE;
     8264+               else
     8265+                       cfg->header_type = PCI_HEADER_NORMAL;
     8266+               /* Save core interrupt flag */
     8267+               cfg->int_pin = R_REG(&sb->sbtpsflag) & SBTPS_NUM0_MASK;
     8268+               /* Default to MIPS shared interrupt 0 */
     8269+               cfg->int_line = 0;
     8270+               /* MIPS sbipsflag maps core interrupt flags to interrupts 1 through 4 */
     8271+               if ((regs = sb_setcore(sbh, SB_MIPS, 0)) ||
     8272+                   (regs = sb_setcore(sbh, SB_MIPS33, 0))) {
     8273+                       sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
     8274+                       val = R_REG(&sb->sbipsflag);
     8275+                       for (cfg->int_line = 1; cfg->int_line <= 4; cfg->int_line++) {
     8276+                               if (((val & sbips_int_mask[cfg->int_line]) >> sbips_int_shift[cfg->int_line]) == cfg->int_pin)
     8277+                                       break;
     8278+                       }
     8279+                       if (cfg->int_line > 4)
     8280+                               cfg->int_line = 0;
     8281+               }
     8282+               /* Emulated core */
     8283+               *((uint32 *) &cfg->sprom_control) = 0xffffffff;
     8284+       }
     8285+
     8286+       sb_setcoreidx(sbh, coreidx);
    147398287+       return 0;
    147408288+}
    147418289+
    14742 +
    14743 +
    14744 +/* use the mdio interface to write to mdio slaves */
    14745 +static int
    14746 +sb_pcie_mdiowrite(sb_info_t *si,  uint physmedia, uint regaddr, uint val)
    14747 +{
    14748 +       uint mdiodata;
    14749 +       uint i = 0;
    14750 +       sbpcieregs_t *pcieregs;
    14751 +
    14752 +       pcieregs = (sbpcieregs_t*) sb_setcoreidx(&si->sb, si->sb.buscoreidx);
    14753 +       ASSERT(pcieregs);
    14754 +
    14755 +       /* enable mdio access to SERDES */
    14756 +       W_REG(si->osh, (&pcieregs->mdiocontrol), MDIOCTL_PREAM_EN | MDIOCTL_DIVISOR_VAL);
    14757 +
    14758 +       mdiodata = MDIODATA_START | MDIODATA_WRITE |
    14759 +               (physmedia << MDIODATA_DEVADDR_SHF) |
    14760 +               (regaddr << MDIODATA_REGADDR_SHF) | MDIODATA_TA | val;
    14761 +
    14762 +       W_REG(si->osh, (&pcieregs->mdiodata), mdiodata);
    14763 +
    14764 +       PR28829_DELAY();
    14765 +
    14766 +       /* retry till the transaction is complete */
    14767 +       while (i < 10) {
    14768 +               if (R_REG(si->osh, &(pcieregs->mdiocontrol)) & MDIOCTL_ACCESS_DONE) {
    14769 +                       /* Disable mdio access to SERDES */
    14770 +                       W_REG(si->osh, (&pcieregs->mdiocontrol), 0);
    14771 +                       return 0;
     8290+int __init
     8291+sbpci_init(void *sbh)
     8292+{
     8293+       sbpci_init_pci(sbh);
     8294+       sbpci_init_cores(sbh);
     8295+       return 0;
     8296+}
     8297+
     8298+void
     8299+sbpci_check(void *sbh)
     8300+{
     8301+       uint coreidx;
     8302+       sbpciregs_t *pci;
     8303+       uint32 sbtopci1;
     8304+       uint32 buf[64], *ptr, i;
     8305+       ulong pa;
     8306+       volatile uint j;
     8307+
     8308+       coreidx = sb_coreidx(sbh);
     8309+       pci = (sbpciregs_t *) sb_setcore(sbh, SB_PCI, 0);
     8310+
     8311+       /* Clear the test array */
     8312+       pa = (ulong) DMA_MAP(NULL, buf, sizeof(buf), DMA_RX, NULL);
     8313+       ptr = (uint32 *) OSL_UNCACHED(&buf[0]);
     8314+       memset(ptr, 0, sizeof(buf));
     8315+
     8316+       /* Point PCI window 1 to memory */
     8317+       sbtopci1 = R_REG(&pci->sbtopci1);
     8318+       W_REG(&pci->sbtopci1, SBTOPCI_MEM | (pa & SBTOPCI1_MASK));
     8319+
     8320+       /* Fill the test array via PCI window 1 */
     8321+       ptr = (uint32 *) REG_MAP(SB_PCI_CFG + (pa & ~SBTOPCI1_MASK), sizeof(buf));
     8322+       for (i = 0; i < ARRAYSIZE(buf); i++) {
     8323+               for (j = 0; j < 2; j++);
     8324+               W_REG(&ptr[i], i);
     8325+       }
     8326+       REG_UNMAP(ptr);
     8327+
     8328+       /* Restore PCI window 1 */
     8329+       W_REG(&pci->sbtopci1, sbtopci1);
     8330+
     8331+       /* Check the test array */
     8332+       DMA_UNMAP(NULL, pa, sizeof(buf), DMA_RX, NULL);
     8333+       ptr = (uint32 *) OSL_UNCACHED(&buf[0]);
     8334+       for (i = 0; i < ARRAYSIZE(buf); i++) {
     8335+               if (ptr[i] != i)
     8336+                       break;
     8337+       }
     8338+
     8339+       /* Change the clock if the test fails */
     8340+       if (i < ARRAYSIZE(buf)) {
     8341+               uint32 req, cur;
     8342+
     8343+               cur = sb_clock(sbh);
     8344+               printf("PCI: Test failed at %d MHz\n", (cur + 500000) / 1000000);
     8345+               for (req = 104000000; req < 176000000; req += 4000000) {
     8346+                       printf("PCI: Resetting to %d MHz\n", (req + 500000) / 1000000);
     8347+                       /* This will only reset if the clocks are valid and have changed */
     8348+                       sb_mips_setclock(sbh, req, 0, 0);
    147728349+               }
    14773 +               OSL_DELAY(1000);
    14774 +               i++;
    14775 +       }
    14776 +
    14777 +       SB_ERROR(("sb_pcie_mdiowrite: timed out\n"));
    14778 +       /* Disable mdio access to SERDES */
    14779 +       W_REG(si->osh, (&pcieregs->mdiocontrol), 0);
    14780 +       ASSERT(0);
    14781 +       return 1;
    14782 +
    14783 +}
    14784 +
    14785 +/* indirect way to read pcie config regs */
    14786 +uint
    14787 +sb_pcie_readreg(void *sb, void* arg1, uint offset)
    14788 +{
    14789 +       sb_info_t *si;
    14790 +       sb_t   *sbh;
    14791 +       uint retval = 0xFFFFFFFF;
    14792 +       sbpcieregs_t *pcieregs;
    14793 +       uint addrtype;
    14794 +
    14795 +       sbh = (sb_t *)sb;
    14796 +       si = SB_INFO(sbh);
    14797 +       ASSERT(PCIE(si));
    14798 +
    14799 +       pcieregs = (sbpcieregs_t *)sb_setcore(sbh, SB_PCIE, 0);
    14800 +       ASSERT(pcieregs);
    14801 +
    14802 +       addrtype = (uint)((uintptr)arg1);
    14803 +       switch (addrtype) {
    14804 +               case PCIE_CONFIGREGS:
    14805 +                       W_REG(si->osh, (&pcieregs->configaddr), offset);
    14806 +                       retval = R_REG(si->osh, &(pcieregs->configdata));
    14807 +                       break;
    14808 +               case PCIE_PCIEREGS:
    14809 +                       W_REG(si->osh, &(pcieregs->pcieaddr), offset);
    14810 +                       retval = R_REG(si->osh, &(pcieregs->pciedata));
    14811 +                       break;
    14812 +               default:
    14813 +                       ASSERT(0);
    14814 +                       break;
    14815 +       }
    14816 +       return retval;
    14817 +}
    14818 +
    14819 +/* indirect way to write pcie config/mdio/pciecore regs */
    14820 +uint
    14821 +sb_pcie_writereg(sb_t *sbh, void *arg1,  uint offset, uint val)
    14822 +{
    14823 +       sb_info_t *si;
    14824 +       sbpcieregs_t *pcieregs;
    14825 +       uint addrtype;
    14826 +
    14827 +       si = SB_INFO(sbh);
    14828 +       ASSERT(PCIE(si));
    14829 +
    14830 +       pcieregs = (sbpcieregs_t *)sb_setcore(sbh, SB_PCIE, 0);
    14831 +       ASSERT(pcieregs);
    14832 +
    14833 +       addrtype = (uint)((uintptr)arg1);
    14834 +
    14835 +       switch (addrtype) {
    14836 +               case PCIE_CONFIGREGS:
    14837 +                       W_REG(si->osh, (&pcieregs->configaddr), offset);
    14838 +                       W_REG(si->osh, (&pcieregs->configdata), val);
    14839 +                       break;
    14840 +               case PCIE_PCIEREGS:
    14841 +                       W_REG(si->osh, (&pcieregs->pcieaddr), offset);
    14842 +                       W_REG(si->osh, (&pcieregs->pciedata), val);
    14843 +                       break;
    14844 +               default:
    14845 +                       ASSERT(0);
    14846 +                       break;
    14847 +       }
    14848 +       return 0;
    14849 +}
    14850 +
    14851 +/* Build device path. Support SB, PCI, and JTAG for now. */
    14852 +int
    14853 +sb_devpath(sb_t *sbh, char *path, int size)
    14854 +{
    14855 +       ASSERT(path);
    14856 +       ASSERT(size >= SB_DEVPATH_BUFSZ);
    14857 +
    14858 +       switch (BUSTYPE((SB_INFO(sbh))->sb.bustype)) {
    14859 +       case SB_BUS:
    14860 +       case JTAG_BUS:
    14861 +               sprintf(path, "sb/%u/", sb_coreidx(sbh));
    14862 +               break;
    14863 +       case PCI_BUS:
    14864 +               ASSERT((SB_INFO(sbh))->osh);
    14865 +               sprintf(path, "pci/%u/%u/", OSL_PCI_BUS((SB_INFO(sbh))->osh),
    14866 +                       OSL_PCI_SLOT((SB_INFO(sbh))->osh));
    14867 +               break;
    14868 +       case PCMCIA_BUS:
    14869 +               SB_ERROR(("sb_devpath: OSL_PCMCIA_BUS() not implemented, bus 1 assumed\n"));
    14870 +               SB_ERROR(("sb_devpath: OSL_PCMCIA_SLOT() not implemented, slot 1 assumed\n"));
    14871 +               sprintf(path, "pc/%u/%u/", 1, 1);
    14872 +               break;
    14873 +       case SDIO_BUS:
    14874 +               SB_ERROR(("sb_devpath: device 0 assumed\n"));
    14875 +               sprintf(path, "sd/%u/", sb_coreidx(sbh));
    14876 +               break;
    14877 +       default:
     8350+               /* Should not reach here */
    148788351+               ASSERT(0);
    14879 +               break;
    14880 +       }
    14881 +
    14882 +       return 0;
    14883 +}
    14884 +
     8352+       }
     8353+
     8354+       sb_setcoreidx(sbh, coreidx);
     8355+}
     8356diff -Nur linux-2.4.32/arch/mips/bcm947xx/setup.c linux-2.4.32-freewrt/arch/mips/bcm947xx/setup.c
     8357--- linux-2.4.32/arch/mips/bcm947xx/setup.c     1970-01-01 01:00:00.000000000 +0100
     8358+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/setup.c     2006-07-06 08:36:07.000000000 +0200
     8359@@ -0,0 +1,199 @@
    148858360+/*
    14886 + * Fixup SROMless PCI device's configuration.
    14887 + * The current core may be changed upon return.
    14888 + */
    14889 +static int
    14890 +sb_pci_fixcfg(sb_info_t *si)
    14891 +{
    14892 +       uint origidx, pciidx;
    14893 +       sbpciregs_t *pciregs;
    14894 +       sbpcieregs_t *pcieregs;
    14895 +       uint16 val16, *reg16;
    14896 +       char name[SB_DEVPATH_BUFSZ+16], *value;
    14897 +       char devpath[SB_DEVPATH_BUFSZ];
    14898 +
    14899 +       ASSERT(BUSTYPE(si->sb.bustype) == PCI_BUS);
    14900 +
    14901 +       /* Fixup PI in SROM shadow area to enable the correct PCI core access */
    14902 +       /* save the current index */
    14903 +       origidx = sb_coreidx(&si->sb);
    14904 +
    14905 +       /* check 'pi' is correct and fix it if not */
    14906 +       if (si->sb.buscoretype == SB_PCIE) {
    14907 +               pcieregs = (sbpcieregs_t *)sb_setcore(&si->sb, SB_PCIE, 0);
    14908 +               ASSERT(pcieregs);
    14909 +               reg16 = &pcieregs->sprom[SRSH_PI_OFFSET];
    14910 +       } else if (si->sb.buscoretype == SB_PCI) {
    14911 +               pciregs = (sbpciregs_t *)sb_setcore(&si->sb, SB_PCI, 0);
    14912 +               ASSERT(pciregs);
    14913 +               reg16 = &pciregs->sprom[SRSH_PI_OFFSET];
    14914 +       } else {
    14915 +               ASSERT(0);
    14916 +               return -1;
    14917 +       }
    14918 +       pciidx = sb_coreidx(&si->sb);
    14919 +       val16 = R_REG(si->osh, reg16);
    14920 +       if (((val16 & SRSH_PI_MASK) >> SRSH_PI_SHIFT) != (uint16)pciidx) {
    14921 +               val16 = (uint16)(pciidx << SRSH_PI_SHIFT) | (val16 & ~SRSH_PI_MASK);
    14922 +               W_REG(si->osh, reg16, val16);
    14923 +       }
    14924 +
    14925 +       /* restore the original index */
    14926 +       sb_setcoreidx(&si->sb, origidx);
    14927 +
    14928 +       /*
    14929 +        * Fixup bar0window in PCI config space to make the core indicated
    14930 +        * by the nvram variable the current core.
    14931 +        * !Do it last, it may change the current core!
    14932 +        */
    14933 +       if (sb_devpath(&si->sb, devpath, sizeof(devpath)))
    14934 +               return -1;
    14935 +       sprintf(name, "%sb0w", devpath);
    14936 +       if ((value = getvar(NULL, name))) {
    14937 +               OSL_PCI_WRITE_CONFIG(si->osh, PCI_BAR0_WIN, sizeof(uint32),
    14938 +                       bcm_strtoul(value, NULL, 16));
    14939 +               /* update curidx since the current core is changed */
    14940 +               si->curidx = _sb_coreidx(si);
    14941 +               if (si->curidx == BADIDX) {
    14942 +                       SB_ERROR(("sb_pci_fixcfg: bad core index\n"));
    14943 +                       return -1;
    14944 +               }
    14945 +       }
    14946 +
    14947 +       return 0;
    14948 +}
    14949 +
    14950 +static uint
    14951 +sb_chipc_capability(sb_t *sbh)
    14952 +{
    14953 +       sb_info_t *si;
    14954 +
    14955 +       si = SB_INFO(sbh);
    14956 +
    14957 +       /* Make sure that there is ChipCommon core present */
    14958 +       if (si->coreid[SB_CC_IDX] == SB_CC)
    14959 +               return (sb_corereg(si, SB_CC_IDX, OFFSETOF(chipcregs_t, capabilities),
    14960 +                                  0, 0));
    14961 +       return 0;
    14962 +}
    14963 +
    14964 +/* Return ADDR64 capability of the backplane */
    14965 +bool
    14966 +sb_backplane64(sb_t *sbh)
    14967 +{
    14968 +       return ((sb_chipc_capability(sbh) & CAP_BKPLN64) != 0);
    14969 +}
    14970 +
    14971 +void
    14972 +sb_btcgpiowar(sb_t *sbh)
    14973 +{
    14974 +       sb_info_t *si;
    14975 +       uint origidx;
    14976 +       uint intr_val = 0;
    14977 +       chipcregs_t *cc;
    14978 +       si = SB_INFO(sbh);
    14979 +
    14980 +       /* Make sure that there is ChipCommon core present &&
    14981 +        * UART_TX is strapped to 1
    14982 +        */
    14983 +       if (!(sb_chipc_capability(sbh) & CAP_UARTGPIO))
    14984 +               return;
    14985 +
    14986 +       /* sb_corereg cannot be used as we have to guarantee 8-bit read/writes */
    14987 +       INTR_OFF(si, intr_val);
    14988 +
    14989 +       origidx = sb_coreidx(sbh);
    14990 +
    14991 +       cc = (chipcregs_t *)sb_setcore(sbh, SB_CC, 0);
    14992 +       if (cc == NULL)
    14993 +               goto end;
    14994 +
    14995 +       W_REG(si->osh, &cc->uart0mcr, R_REG(si->osh, &cc->uart0mcr) | 0x04);
    14996 +
    14997 +end:
    14998 +       /* restore the original index */
    14999 +       sb_setcoreidx(sbh, origidx);
    15000 +
    15001 +       INTR_RESTORE(si, intr_val);
    15002 +}
    15003 +
    15004 +/* check if the device is removed */
    15005 +bool
    15006 +sb_deviceremoved(sb_t *sbh)
    15007 +{
    15008 +       uint32 w;
    15009 +       sb_info_t *si;
    15010 +
    15011 +       si = SB_INFO(sbh);
    15012 +
    15013 +       switch (BUSTYPE(si->sb.bustype)) {
    15014 +       case PCI_BUS:
    15015 +               ASSERT(si->osh);
    15016 +               w = OSL_PCI_READ_CONFIG(si->osh, PCI_CFG_VID, sizeof(uint32));
    15017 +               if ((w & 0xFFFF) != VENDOR_BROADCOM)
    15018 +                       return TRUE;
    15019 +               else
    15020 +                       return FALSE;
    15021 +       default:
    15022 +               return FALSE;
    15023 +       }
    15024 +       return FALSE;
    15025 +}
    15026 +
    15027 +/* Return the RAM size of the SOCRAM core */
    15028 +uint32
    15029 +sb_socram_size(sb_t *sbh)
    15030 +{
    15031 +       sb_info_t *si;
    15032 +       uint origidx;
    15033 +       uint intr_val = 0;
    15034 +
    15035 +       sbsocramregs_t *regs;
    15036 +       bool wasup;
    15037 +       uint corerev;
    15038 +       uint32 coreinfo;
    15039 +       uint memsize = 0;
    15040 +
    15041 +       si = SB_INFO(sbh);
    15042 +       ASSERT(si);
    15043 +
    15044 +       /* Block ints and save current core */
    15045 +       INTR_OFF(si, intr_val);
    15046 +       origidx = sb_coreidx(sbh);
    15047 +
    15048 +       /* Switch to SOCRAM core */
    15049 +       if (!(regs = sb_setcore(sbh, SB_SOCRAM, 0)))
    15050 +               goto done;
    15051 +
    15052 +       /* Get info for determining size */
    15053 +       if (!(wasup = sb_iscoreup(sbh)))
    15054 +               sb_core_reset(sbh, 0, 0);
    15055 +       corerev = sb_corerev(sbh);
    15056 +       coreinfo = R_REG(si->osh, &regs->coreinfo);
    15057 +
    15058 +       /* Calculate size from coreinfo based on rev */
    15059 +       switch (corerev) {
    15060 +       case 0:
    15061 +               memsize = 1 << (16 + (coreinfo & SRCI_MS0_MASK));
    15062 +               break;
    15063 +       default: /* rev >= 1 */
    15064 +               memsize = 1 << (SR_BSZ_BASE + (coreinfo & SRCI_SRBSZ_MASK));
    15065 +               memsize *= (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
    15066 +               break;
    15067 +       }
    15068 +
    15069 +       /* Return to previous state and core */
    15070 +       if (!wasup)
    15071 +               sb_core_disable(sbh, 0);
    15072 +       sb_setcoreidx(sbh, origidx);
    15073 +
    15074 +done:
    15075 +       INTR_RESTORE(si, intr_val);
    15076 +       return memsize;
    15077 +}
    15078 +
    15079 +
    15080 diff -urN linux.old/arch/mips/bcm947xx/setup.c linux.dev/arch/mips/bcm947xx/setup.c
    15081 --- linux.old/arch/mips/bcm947xx/setup.c        1970-01-01 01:00:00.000000000 +0100
    15082 +++ linux.dev/arch/mips/bcm947xx/setup.c        2006-04-27 23:22:53.000000000 +0200
    15083 @@ -0,0 +1,241 @@
    15084 +/*
    15085 + *  Generic setup routines for Broadcom MIPS boards
     8361+ * Generic setup routines for Broadcom MIPS boards
    150868362+ *
    15087 + *  Copyright (C) 2005 Felix Fietkau <nbd@openwrt.org>
    15088 + *
    15089 + *  This program is free software; you can redistribute  it and/or modify it
    15090 + *  under  the terms of  the GNU General  Public License as published by the
    15091 + *  Free Software Foundation;  either version 2 of the  License, or (at your
    15092 + *  option) any later version.
    15093 + *
    15094 + *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
    15095 + *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
    15096 + *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
    15097 + *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
    15098 + *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    15099 + *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
    15100 + *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    15101 + *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
    15102 + *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    15103 + *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    15104 + *
    15105 + *  You should have received a copy of the  GNU General Public License along
    15106 + *  with this program; if not, write  to the Free Software Foundation, Inc.,
    15107 + *  675 Mass Ave, Cambridge, MA 02139, USA.
    15108 + *
    15109 + *
    15110 + * Copyright 2005, Broadcom Corporation
     8363+ * Copyright 2004, Broadcom Corporation
    151118364+ * All Rights Reserved.
    151128365+ *
     
    151168369+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    151178370+ *
     8371+ * $Id: setup.c,v 1.2 2005/04/02 12:12:57 wbx Exp $
    151188372+ */
    151198373+
     
    151218375+#include <linux/init.h>
    151228376+#include <linux/kernel.h>
    15123 +#include <linux/module.h>
    151248377+#include <linux/serialP.h>
    151258378+#include <linux/ide.h>
    151268379+#include <asm/bootinfo.h>
    15127 +#include <asm/cpu.h>
    151288380+#include <asm/time.h>
    151298381+#include <asm/reboot.h>
    151308382+
    151318383+#include <typedefs.h>
    15132 +#include <osl.h>
    15133 +#include <sbutils.h>
    151348384+#include <bcmutils.h>
    151358385+#include <bcmnvram.h>
    15136 +#include <sbhndmips.h>
    15137 +#include <hndmips.h>
     8386+#include <sbmips.h>
     8387+#include <sbutils.h>
    151388388+#include <trxhdr.h>
    15139 +
    15140 +/* Virtual IRQ base, after last hw IRQ */
    15141 +#define SBMIPS_VIRTIRQ_BASE 6
    15142 +
    15143 +/* # IRQs, hw and sw IRQs */
    15144 +#define SBMIPS_NUMIRQS  8
    15145 +
    15146 +/* Global SB handle */
    15147 +sb_t *bcm947xx_sbh = NULL;
    15148 +spinlock_t bcm947xx_sbh_lock = SPIN_LOCK_UNLOCKED;
    15149 +
    15150 +/* Convenience */
    15151 +#define sbh bcm947xx_sbh
    15152 +#define sbh_lock bcm947xx_sbh_lock
    151538389+
    151548390+extern void bcm947xx_time_init(void);
    151558391+extern void bcm947xx_timer_setup(struct irqaction *irq);
     8392+extern void check_enable_mips_pfc(int val);
    151568393+
    151578394+#ifdef CONFIG_REMOTE_DEBUG
     
    151658402+#endif
    151668403+
     8404+/* Global SB handle */
     8405+void *bcm947xx_sbh = NULL;
     8406+spinlock_t bcm947xx_sbh_lock = SPIN_LOCK_UNLOCKED;
     8407+EXPORT_SYMBOL(bcm947xx_sbh);
     8408+EXPORT_SYMBOL(bcm947xx_sbh_lock);
     8409+
     8410+/* Convenience */
     8411+#define sbh bcm947xx_sbh
     8412+#define sbh_lock bcm947xx_sbh_lock
     8413+
    151678414+/* Kernel command line */
    151688415+char arcs_cmdline[CL_SIZE] __initdata = CONFIG_CMDLINE;
    15169 +extern void sb_serial_init(sb_t *sbh, void (*add)(void *regs, uint irq, uint baud_base, uint reg_shift));
    151708416+
    151718417+void
     
    152388484+        s.io_type = SERIAL_IO_MEM;
    152398485+        s.iomem_reg_shift = reg_shift;
    15240 +
    152418486+        if (early_serial_setup(&s) != 0) {
    152428487+                printk(KERN_ERR "Serial setup failed!\n");
     
    152528497+       int i;
    152538498+       char *value;
     8499+       uint  pfc_val;
    152548500+
    152558501+       /* Get global SB handle */
     
    152578503+
    152588504+       /* Initialize clocks and interrupts */
    15259 +       sb_mips_init(sbh, SBMIPS_VIRTIRQ_BASE);
    15260 +
    15261 +       if (BCM330X(current_cpu_data.processor_id) &&
    15262 +               (read_c0_diag() & BRCM_PFC_AVAIL)) {
    15263 +               /*
    15264 +                * Now that the sbh is inited set the  proper PFC value
    15265 +                */     
    15266 +               printk("Setting the PFC to its default value\n");
    15267 +               enable_pfc(PFC_AUTO);
    15268 +       }
    15269 +
     8505+       sb_mips_init(sbh);
     8506+
     8507+       /*
     8508+        * Now that the sbh is inited set the  proper PFC value
     8509+        */     
     8510+       pfc_val = sb_mips_get_pfc(sbh);
     8511+       printk("Setting the PFC value as 0x%x\n", pfc_val);
     8512+       check_enable_mips_pfc(pfc_val);
    152708513+
    152718514+#ifdef CONFIG_SERIAL
    152728515+       sb_serial_init(sbh, serial_add);
    15273 +
    152748516+       /* reverse serial ports if nvram variable starts with console=ttyS1 */
    152758517+       /* Initialize UARTs */
     
    153078549+get_system_type(void)
    153088550+{
    15309 +       static char s[32];
    15310 +
    15311 +       if (bcm947xx_sbh) {
    15312 +               sprintf(s, "Broadcom BCM%X chip rev %d", sb_chip(bcm947xx_sbh),
    15313 +                       sb_chiprev(bcm947xx_sbh));
    15314 +               return s;
    15315 +       }
    15316 +       else
    15317 +               return "Broadcom BCM947XX";
     8551+       return "Broadcom BCM947XX";
    153188552+}
    153198553+
     
    153238557+}
    153248558+
    15325 diff -urN linux.old/arch/mips/bcm947xx/sflash.c linux.dev/arch/mips/bcm947xx/sflash.c
    15326 --- linux.old/arch/mips/bcm947xx/sflash.c       1970-01-01 01:00:00.000000000 +0100
    15327 +++ linux.dev/arch/mips/bcm947xx/sflash.c       2006-04-27 22:11:27.000000000 +0200
    15328 @@ -0,0 +1,422 @@
     8559diff -Nur linux-2.4.32/arch/mips/bcm947xx/time.c linux-2.4.32-freewrt/arch/mips/bcm947xx/time.c
     8560--- linux-2.4.32/arch/mips/bcm947xx/time.c      1970-01-01 01:00:00.000000000 +0100
     8561+++ linux-2.4.32-freewrt/arch/mips/bcm947xx/time.c      2006-07-02 21:58:25.000000000 +0200
     8562@@ -0,0 +1,102 @@
    153298563+/*
    15330 + * Broadcom SiliconBackplane chipcommon serial flash interface
    15331 + *
    15332 + * Copyright 2006, Broadcom Corporation
     8564+ * Copyright 2004, Broadcom Corporation
    153338565+ * All Rights Reserved.
    153348566+ *
     
    153388570+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    153398571+ *
    15340 + * $Id: sflash.c,v 1.1.1.13 2006/02/27 03:43:16 honor Exp $
    15341 + */
    15342 +
    15343 +#include <osl.h>
    15344 +#include <typedefs.h>
    15345 +#include <sbconfig.h>
    15346 +#include <sbchipc.h>
    15347 +#include <mipsinc.h>
    15348 +#include <bcmutils.h>
    15349 +#include <bcmdevs.h>
    15350 +#include <sflash.h>
    15351 +
    15352 +/* Private global state */
    15353 +static struct sflash sflash;
    15354 +
    15355 +/* Issue a serial flash command */
    15356 +static INLINE void
    15357 +sflash_cmd(chipcregs_t *cc, uint opcode)
    15358 +{
    15359 +       W_REG(NULL, &cc->flashcontrol, SFLASH_START | opcode);
    15360 +       while (R_REG(NULL, &cc->flashcontrol) & SFLASH_BUSY);
    15361 +}
    15362 +
    15363 +/* Initialize serial flash access */
    15364 +struct sflash *
    15365 +sflash_init(chipcregs_t *cc)
    15366 +{
    15367 +       uint32 id, id2;
    15368 +
    15369 +       bzero(&sflash, sizeof(sflash));
    15370 +
    15371 +       sflash.type = R_REG(NULL, &cc->capabilities) & CAP_FLASH_MASK;
    15372 +
    15373 +       switch (sflash.type) {
    15374 +       case SFLASH_ST:
    15375 +               /* Probe for ST chips */
    15376 +               sflash_cmd(cc, SFLASH_ST_DP);
    15377 +               sflash_cmd(cc, SFLASH_ST_RES);
    15378 +               id = R_REG(NULL, &cc->flashdata);
    15379 +               switch (id) {
    15380 +               case 0x11:
    15381 +                       /* ST M25P20 2 Mbit Serial Flash */
    15382 +                       sflash.blocksize = 64 * 1024;
    15383 +                       sflash.numblocks = 4;
    15384 +                       break;
    15385 +               case 0x12:
    15386 +                       /* ST M25P40 4 Mbit Serial Flash */
    15387 +                       sflash.blocksize = 64 * 1024;
    15388 +                       sflash.numblocks = 8;
    15389 +                       break;
    15390 +               case 0x13:
    15391 +                       /* ST M25P80 8 Mbit Serial Flash */
    15392 +                       sflash.blocksize = 64 * 1024;
    15393 +                       sflash.numblocks = 16;
    15394 +                       break;
    15395 +               case 0x14:
    15396 +                       /* ST M25P16 16 Mbit Serial Flash */
    15397 +                       sflash.blocksize = 64 * 1024;
    15398 +                       sflash.numblocks = 32;
    15399 +                       break;
    15400 +               case 0x15:
    15401 +                       /* ST M25P32 32 Mbit Serial Flash */
    15402 +                       sflash.blocksize = 64 * 1024;
    15403 +                       sflash.numblocks = 64;
    15404 +                       break;
    15405 +               case 0x16:
    15406 +                       /* ST M25P64 64 Mbit Serial Flash */
    15407 +                       sflash.blocksize = 64 * 1024;
    15408 +                       sflash.numblocks = 128;
    15409 +                       break;
    15410 +               case 0xbf:
    15411 +                       W_REG(NULL, &cc->flashaddress, 1);
    15412 +                       sflash_cmd(cc, SFLASH_ST_RES);
    15413 +                       id2 = R_REG(NULL, &cc->flashdata);
    15414 +                       if (id2 == 0x44) {
    15415 +                               /* SST M25VF80 4 Mbit Serial Flash */
    15416 +                               sflash.blocksize = 64 * 1024;
    15417 +                               sflash.numblocks = 8;
    15418 +                       }
    15419 +                       break;
    15420 +               }
    15421 +               break;
    15422 +
    15423 +       case SFLASH_AT:
    15424 +               /* Probe for Atmel chips */
    15425 +               sflash_cmd(cc, SFLASH_AT_STATUS);
    15426 +               id = R_REG(NULL, &cc->flashdata) & 0x3c;
    15427 +               switch (id) {
    15428 +               case 0xc:
    15429 +                       /* Atmel AT45DB011 1Mbit Serial Flash */
    15430 +                       sflash.blocksize = 256;
    15431 +                       sflash.numblocks = 512;
    15432 +                       break;
    15433 +               case 0x14:
    15434 +                       /* Atmel AT45DB021 2Mbit Serial Flash */
    15435 +                       sflash.blocksize = 256;
    15436 +                       sflash.numblocks = 1024;
    15437 +                       break;
    15438 +               case 0x1c:
    15439 +                       /* Atmel AT45DB041 4Mbit Serial Flash */
    15440 +                       sflash.blocksize = 256;
    15441 +                       sflash.numblocks = 2048;
    15442 +                       break;
    15443 +               case 0x24:
    15444 +                       /* Atmel AT45DB081 8Mbit Serial Flash */
    15445 +                       sflash.blocksize = 256;
    15446 +                       sflash.numblocks = 4096;
    15447 +                       break;
    15448 +               case 0x2c:
    15449 +                       /* Atmel AT45DB161 16Mbit Serial Flash */
    15450 +                       sflash.blocksize = 512;
    15451 +                       sflash.numblocks = 4096;
    15452 +                       break;
    15453 +               case 0x34:
    15454 +                       /* Atmel AT45DB321 32Mbit Serial Flash */
    15455 +                       sflash.blocksize = 512;
    15456 +                       sflash.numblocks = 8192;
    15457 +                       break;
    15458 +               case 0x3c:
    15459 +                       /* Atmel AT45DB642 64Mbit Serial Flash */
    15460 +                       sflash.blocksize = 1024;
    15461 +                       sflash.numblocks = 8192;
    15462 +                       break;
    15463 +               }
    15464 +               break;
    15465 +       }
    15466 +
    15467 +       sflash.size = sflash.blocksize * sflash.numblocks;
    15468 +       return sflash.size ? &sflash : NULL;
    15469 +}
    15470 +
    15471 +/* Read len bytes starting at offset into buf. Returns number of bytes read. */
    15472 +int
    15473 +sflash_read(chipcregs_t *cc, uint offset, uint len, uchar *buf)
    15474 +{
    15475 +       int cnt;
    15476 +       uint32 *from, *to;
    15477 +
    15478 +       if (!len)
    15479 +               return 0;
    15480 +
    15481 +       if ((offset + len) > sflash.size)
    15482 +               return -22;
    15483 +
    15484 +       if ((len >= 4) && (offset & 3))
    15485 +               cnt = 4 - (offset & 3);
    15486 +       else if ((len >= 4) && ((uint32)buf & 3))
    15487 +               cnt = 4 - ((uint32)buf & 3);
    15488 +       else
    15489 +               cnt = len;
    15490 +
    15491 +       from = (uint32 *)KSEG1ADDR(SB_FLASH2 + offset);
    15492 +       to = (uint32 *)buf;
    15493 +
    15494 +       if (cnt < 4) {
    15495 +               bcopy(from, to, cnt);
    15496 +               return cnt;
    15497 +       }
    15498 +
    15499 +       while (cnt >= 4) {
    15500 +               *to++ = *from++;
    15501 +               cnt -= 4;
    15502 +       }
    15503 +
    15504 +       return (len - cnt);
    15505 +}
    15506 +
    15507 +/* Poll for command completion. Returns zero when complete. */
    15508 +int
    15509 +sflash_poll(chipcregs_t *cc, uint offset)
    15510 +{
    15511 +       if (offset >= sflash.size)
    15512 +               return -22;
    15513 +
    15514 +       switch (sflash.type) {
    15515 +       case SFLASH_ST:
    15516 +               /* Check for ST Write In Progress bit */
    15517 +               sflash_cmd(cc, SFLASH_ST_RDSR);
    15518 +               return R_REG(NULL, &cc->flashdata) & SFLASH_ST_WIP;
    15519 +       case SFLASH_AT:
    15520 +               /* Check for Atmel Ready bit */
    15521 +               sflash_cmd(cc, SFLASH_AT_STATUS);
    15522 +               return !(R_REG(NULL, &cc->flashdata) & SFLASH_AT_READY);
    15523 +       }
    15524 +
    15525 +       return 0;
    15526 +}
    15527 +
    15528 +/* Write len bytes starting at offset into buf. Returns number of bytes
    15529 + * written. Caller should poll for completion.
    15530 + */
    15531 +int
    15532 +sflash_write(chipcregs_t *cc, uint offset, uint len, const uchar *buf)
    15533 +{
    15534 +       struct sflash *sfl;
    15535 +       int ret = 0;
    15536 +       bool is4712b0;
    15537 +       uint32 page, byte, mask;
    15538 +
    15539 +       if (!len)
    15540 +               return 0;
    15541 +
    15542 +       if ((offset + len) > sflash.size)
    15543 +               return -22;
    15544 +
    15545 +       sfl = &sflash;
    15546 +       switch (sfl->type) {
    15547 +       case SFLASH_ST:
    15548 +               mask = R_REG(NULL, &cc->chipid);
    15549 +               is4712b0 = (((mask & CID_ID_MASK) == BCM4712_CHIP_ID) &&
    15550 +                           ((mask & CID_REV_MASK) == (3 << CID_REV_SHIFT)));
    15551 +               /* Enable writes */
    15552 +               sflash_cmd(cc, SFLASH_ST_WREN);
    15553 +               if (is4712b0) {
    15554 +                       mask = 1 << 14;
    15555 +                       W_REG(NULL, &cc->flashaddress, offset);
    15556 +                       W_REG(NULL, &cc->flashdata, *buf++);
    15557 +                       /* Set chip select */
    15558 +                       OR_REG(NULL, &cc->gpioout, mask);
    15559 +                       /* Issue a page program with the first byte */
    15560 +                       sflash_cmd(cc, SFLASH_ST_PP);
    15561 +                       ret = 1;
    15562 +                       offset++;
    15563 +                       len--;
    15564 +                       while (len > 0) {
    15565 +                               if ((offset & 255) == 0) {
    15566 +                                       /* Page boundary, drop cs and return */
    15567 +                                       AND_REG(NULL, &cc->gpioout, ~mask);
    15568 +                                       if (!sflash_poll(cc, offset)) {
    15569 +                                               /* Flash rejected command */
    15570 +                                               return -11;
    15571 +                                       }
    15572 +                                       return ret;
    15573 +                               } else {
    15574 +                                       /* Write single byte */
    15575 +                                       sflash_cmd(cc, *buf++);
    15576 +                               }
    15577 +                               ret++;
    15578 +                               offset++;
    15579 +                               len--;
    15580 +                       }
    15581 +                       /* All done, drop cs if needed */
    15582 +                       if ((offset & 255) != 1) {
    15583 +                               /* Drop cs */
    15584 +                               AND_REG(NULL, &cc->gpioout, ~mask);
    15585 +                               if (!sflash_poll(cc, offset)) {
    15586 +                                       /* Flash rejected command */
    15587 +                                       return -12;
    15588 +                               }
    15589 +                       }
    15590 +               } else {
    15591 +                       ret = 1;
    15592 +                       W_REG(NULL, &cc->flashaddress, offset);
    15593 +                       W_REG(NULL, &cc->flashdata, *buf);
    15594 +                       /* Page program */
    15595 +                       sflash_cmd(cc, SFLASH_ST_PP);
    15596 +               }
    15597 +               break;
    15598 +       case SFLASH_AT:
    15599 +               mask = sfl->blocksize - 1;
    15600 +               page = (offset & ~mask) << 1;
    15601 +               byte = offset & mask;
    15602 +               /* Read main memory page into buffer 1 */
    15603 +               if (byte || (len < sfl->blocksize)) {
    15604 +                       W_REG(NULL, &cc->flashaddress, page);
    15605 +                       sflash_cmd(cc, SFLASH_AT_BUF1_LOAD);
    15606 +                       /* 250 us for AT45DB321B */
    15607 +                       SPINWAIT(sflash_poll(cc, offset), 1000);
    15608 +                       ASSERT(!sflash_poll(cc, offset));
    15609 +               }
    15610 +               /* Write into buffer 1 */
    15611 +               for (ret = 0; (ret < (int)len) && (byte < sfl->blocksize); ret++) {
    15612 +                       W_REG(NULL, &cc->flashaddress, byte++);
    15613 +                       W_REG(NULL, &cc->flashdata, *buf++);
    15614 +                       sflash_cmd(cc, SFLASH_AT_BUF1_WRITE);
    15615 +               }
    15616 +               /* Write buffer 1 into main memory page */
    15617 +               W_REG(NULL, &cc->flashaddress, page);
    15618 +               sflash_cmd(cc, SFLASH_AT_BUF1_PROGRAM);
    15619 +               break;
    15620 +       }
    15621 +
    15622 +       return ret;
    15623 +}
    15624 +
    15625 +/* Erase a region. Returns number of bytes scheduled for erasure.
    15626 + * Caller should poll for completion.
    15627 + */
    15628 +int
    15629 +sflash_erase(chipcregs_t *cc, uint offset)
    15630 +{
    15631 +       struct sflash *sfl;
    15632 +
    15633 +       if (offset >= sflash.size)
    15634 +               return -22;
    15635 +
    15636 +       sfl = &sflash;
    15637 +       switch (sfl->type) {
    15638 +       case SFLASH_ST:
    15639 +               sflash_cmd(cc, SFLASH_ST_WREN);
    15640 +               W_REG(NULL, &cc->flashaddress, offset);
    15641 +               sflash_cmd(cc, SFLASH_ST_SE);
    15642 +               return sfl->blocksize;
    15643 +       case SFLASH_AT:
    15644 +               W_REG(NULL, &cc->flashaddress, offset << 1);
    15645 +               sflash_cmd(cc, SFLASH_AT_PAGE_ERASE);
    15646 +               return sfl->blocksize;
    15647 +       }
    15648 +
    15649 +       return 0;
    15650 +}
    15651 +
    15652 +/*
    15653 + * writes the appropriate range of flash, a NULL buf simply erases
    15654 + * the region of flash
    15655 + */
    15656 +int
    15657 +sflash_commit(chipcregs_t *cc, uint offset, uint len, const uchar *buf)
    15658 +{
    15659 +       struct sflash *sfl;
    15660 +       uchar *block = NULL, *cur_ptr, *blk_ptr;
    15661 +       uint blocksize = 0, mask, cur_offset, cur_length, cur_retlen, remainder;
    15662 +       uint blk_offset, blk_len, copied;
    15663 +       int bytes, ret = 0;
    15664 +
    15665 +       /* Check address range */
    15666 +       if (len <= 0)
    15667 +               return 0;
    15668 +
    15669 +       sfl = &sflash;
    15670 +       if ((offset + len) > sfl->size)
    15671 +               return -1;
    15672 +
    15673 +       blocksize = sfl->blocksize;
    15674 +       mask = blocksize - 1;
    15675 +
    15676 +       /* Allocate a block of mem */
    15677 +       if (!(block = MALLOC(NULL, blocksize)))
    15678 +               return -1;
    15679 +
    15680 +       while (len) {
    15681 +               /* Align offset */
    15682 +               cur_offset = offset & ~mask;
    15683 +               cur_length = blocksize;
    15684 +               cur_ptr = block;
    15685 +
    15686 +               remainder = blocksize - (offset & mask);
    15687 +               if (len < remainder)
    15688 +                       cur_retlen = len;
    15689 +               else
    15690 +                       cur_retlen = remainder;
    15691 +
    15692 +               /* buf == NULL means erase only */
    15693 +               if (buf) {
    15694 +                       /* Copy existing data into holding block if necessary */
    15695 +                       if ((offset & mask) || (len < blocksize)) {
    15696 +                               blk_offset = cur_offset;
    15697 +                               blk_len = cur_length;
    15698 +                               blk_ptr = cur_ptr;
    15699 +
    15700 +                               /* Copy entire block */
    15701 +                               while (blk_len) {
    15702 +                                       copied = sflash_read(cc, blk_offset, blk_len, blk_ptr);
    15703 +                                       blk_offset += copied;
    15704 +                                       blk_len -= copied;
    15705 +                                       blk_ptr += copied;
    15706 +                               }
    15707 +                       }
    15708 +
    15709 +                       /* Copy input data into holding block */
    15710 +                       memcpy(cur_ptr + (offset & mask), buf, cur_retlen);
    15711 +               }
    15712 +
    15713 +               /* Erase block */
    15714 +               if ((ret = sflash_erase(cc, (uint) cur_offset)) < 0)
    15715 +                       goto done;
    15716 +               while (sflash_poll(cc, (uint) cur_offset));
    15717 +
    15718 +               /* buf == NULL means erase only */
    15719 +               if (!buf) {
    15720 +                       offset += cur_retlen;
    15721 +                       len -= cur_retlen;
    15722 +                       continue;
    15723 +               }
    15724 +
    15725 +               /* Write holding block */
    15726 +               while (cur_length > 0) {
    15727 +                       if ((bytes = sflash_write(cc,
    15728 +                                                 (uint) cur_offset,
    15729 +                                                 (uint) cur_length,
    15730 +                                                 (uchar *) cur_ptr)) < 0) {
    15731 +                               ret = bytes;
    15732 +                               goto done;
    15733 +                       }
    15734 +                       while (sflash_poll(cc, (uint) cur_offset));
    15735 +                       cur_offset += bytes;
    15736 +                       cur_length -= bytes;
    15737 +                       cur_ptr += bytes;
    15738 +               }
    15739 +
    15740 +               offset += cur_retlen;
    15741 +               len -= cur_retlen;
    15742 +               buf += cur_retlen;
    15743 +       }
    15744 +
    15745 +       ret = len;
    15746 +done:
    15747 +       if (block)
    15748 +               MFREE(NULL, block, blocksize);
    15749 +       return ret;
    15750 +}
    15751 diff -urN linux.old/arch/mips/bcm947xx/time.c linux.dev/arch/mips/bcm947xx/time.c
    15752 --- linux.old/arch/mips/bcm947xx/time.c 1970-01-01 01:00:00.000000000 +0100
    15753 +++ linux.dev/arch/mips/bcm947xx/time.c 2006-04-28 00:45:40.000000000 +0200
    15754 @@ -0,0 +1,104 @@
    15755 +/*
    15756 + * Copyright 2006, Broadcom Corporation
    15757 + * All Rights Reserved.
    15758 + *
    15759 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    15760 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    15761 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    15762 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    15763 + *
    15764 + * $Id: time.c,v 1.1.1.10 2006/02/27 03:42:55 honor Exp $
     8572+ * $Id: time.c,v 1.1 2005/03/16 13:49:59 wbx Exp $
    157658573+ */
    157668574+#include <linux/config.h>
     
    157758583+
    157768584+#include <typedefs.h>
    15777 +#include <osl.h>
    157788585+#include <bcmnvram.h>
    157798586+#include <sbconfig.h>
    157808587+#include <sbextif.h>
    157818588+#include <sbutils.h>
    15782 +#include <hndmips.h>
    15783 +#include <mipsinc.h>
    15784 +#include <hndcpu.h>
     8589+#include <sbmips.h>
    157858590+
    157868591+/* Global SB handle */
     
    158098614+       write_c0_compare(0xffff);
    158108615+
    15811 +       if (!(hz = sb_cpu_clock(sbh)))
     8616+       if (!(hz = sb_mips_clock(sbh)))
    158128617+               hz = 100000000;
    158138618+
     
    158208625+       /* Set watchdog interval in ms */
    158218626+       watchdog = simple_strtoul(nvram_safe_get("watchdog"), NULL, 0);
    15822 +
    15823 +       /* Please set the watchdog to 3 sec if it is less than 3 but not equal to 0 */
     8627+       
     8628+       /* Please set the watchdog to 3 sec if it is less than 3 but not equal to 0 */
    158248629+       if (watchdog > 0) {
    158258630+               if (watchdog < 3000)
    158268631+                       watchdog = 3000;
    158278632+       }
     8633+
    158288634+
    158298635+       /* Set panic timeout in seconds */
     
    158578663+       setup_irq(7, &bcm947xx_timer_irqaction);
    158588664+}
    15859 diff -urN linux.old/arch/mips/config-shared.in linux.dev/arch/mips/config-shared.in
    15860 --- linux.old/arch/mips/config-shared.in        2006-04-27 18:04:37.000000000 +0200
    15861 +++ linux.dev/arch/mips/config-shared.in        2006-04-27 19:24:19.000000000 +0200
    15862 @@ -208,6 +208,14 @@
     8665diff -Nur linux-2.4.32/arch/mips/config-shared.in linux-2.4.32-freewrt/arch/mips/config-shared.in
     8666--- linux-2.4.32/arch/mips/config-shared.in     2005-01-19 15:09:27.000000000 +0100
     8667+++ linux-2.4.32-freewrt/arch/mips/config-shared.in     2006-07-02 21:58:25.000000000 +0200
     8668@@ -205,6 +205,14 @@
    158638669    fi
    158648670    define_bool CONFIG_MIPS_RTC y
     
    158758681 bool 'Support for TANBAC TB0226 (Mbase)' CONFIG_TANBAC_TB0226
    158768682 bool 'Support for TANBAC TB0229 (VR4131DIMM)' CONFIG_TANBAC_TB0229
    15877 @@ -229,6 +237,11 @@
     8683@@ -226,6 +234,11 @@
    158788684 define_bool CONFIG_RWSEM_XCHGADD_ALGORITHM n
    158798685 
     
    158878693 #
    158888694 if [ "$CONFIG_ACER_PICA_61" = "y" ]; then
    15889 @@ -554,6 +567,13 @@
     8695@@ -533,6 +546,13 @@
    158908696    define_bool CONFIG_SWAP_IO_SPACE_L y
    158918697    define_bool CONFIG_BOOT_ELF32 y
     
    159018707    define_bool CONFIG_ARC32 y
    159028708    define_bool CONFIG_ARC_MEMORY y
    15903 @@ -1042,7 +1062,11 @@
     8709@@ -1011,7 +1031,11 @@
    159048710 
    159058711 bool 'Are you using a crosscompiler' CONFIG_CROSSCOMPILE
     
    159148720 if [ "$CONFIG_KGDB" = "y" ]; then
    159158721    define_bool CONFIG_DEBUG_INFO y
    15916 diff -urN linux.old/arch/mips/kernel/cpu-probe.c linux.dev/arch/mips/kernel/cpu-probe.c
    15917 --- linux.old/arch/mips/kernel/cpu-probe.c      2006-04-27 18:04:37.000000000 +0200
    15918 +++ linux.dev/arch/mips/kernel/cpu-probe.c      2006-04-27 19:24:19.000000000 +0200
    15919 @@ -162,7 +162,7 @@
     8722diff -Nur linux-2.4.32/arch/mips/kernel/cpu-probe.c linux-2.4.32-freewrt/arch/mips/kernel/cpu-probe.c
     8723--- linux-2.4.32/arch/mips/kernel/cpu-probe.c   2005-01-19 15:09:29.000000000 +0100
     8724+++ linux-2.4.32-freewrt/arch/mips/kernel/cpu-probe.c   2006-07-02 21:58:25.000000000 +0200
     8725@@ -174,7 +174,7 @@
    159208726 
    159218727 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
     
    159268732                c->cputype = CPU_R2000;
    159278733                c->isa_level = MIPS_CPU_ISA_I;
    15928 @@ -172,7 +172,7 @@
     8734@@ -184,7 +184,7 @@
    159298735                c->tlbsize = 64;
    159308736                break;
     
    159358741                                c->cputype = CPU_R3081E;
    159368742                        else
    15937 @@ -187,12 +187,12 @@
     8743@@ -199,12 +199,12 @@
    159388744                break;
    159398745        case PRID_IMP_R4000:
     
    159508756                        else
    159518757                                c->cputype = CPU_R4000SC;
    15952 @@ -438,7 +438,7 @@
     8758@@ -450,7 +450,7 @@
    159538759 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
    159548760 {
     
    159598765                c->cputype = CPU_4KC;
    159608766                c->isa_level = MIPS_CPU_ISA_M32;
    15961 @@ -479,10 +479,10 @@
     8767@@ -491,10 +491,10 @@
    159628768 {
    159638769        decode_config1(c);
     
    159728778                        c->cputype = CPU_AU1000;
    159738779                        break;
    15974 @@ -510,10 +510,34 @@
     8780@@ -522,10 +522,34 @@
    159758781        }
    159768782 }
     
    160088814                c->cputype = CPU_SB1;
    160098815                c->isa_level = MIPS_CPU_ISA_M64;
    16010 @@ -535,7 +559,7 @@
     8816@@ -547,7 +571,7 @@
    160118817 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
    160128818 {
     
    160178823                c->cputype = CPU_SR71000;
    160188824                c->isa_level = MIPS_CPU_ISA_M64;
    16019 @@ -560,7 +584,7 @@
     8825@@ -572,7 +596,7 @@
    160208826        c->cputype      = CPU_UNKNOWN;
    160218827 
     
    160268832        case PRID_COMP_LEGACY:
    160278833                cpu_probe_legacy(c);
    16028 @@ -571,6 +595,9 @@
     8834@@ -583,6 +607,9 @@
    160298835        case PRID_COMP_ALCHEMY:
    160308836                cpu_probe_alchemy(c);
     
    160368842                cpu_probe_sibyte(c);
    160378843                break;
    16038 diff -urN linux.old/arch/mips/kernel/head.S linux.dev/arch/mips/kernel/head.S
    16039 --- linux.old/arch/mips/kernel/head.S   2006-04-27 18:04:37.000000000 +0200
    16040 +++ linux.dev/arch/mips/kernel/head.S   2006-04-27 19:24:19.000000000 +0200
     8844diff -Nur linux-2.4.32/arch/mips/kernel/head.S linux-2.4.32-freewrt/arch/mips/kernel/head.S
     8845--- linux-2.4.32/arch/mips/kernel/head.S        2005-01-19 15:09:29.000000000 +0100
     8846+++ linux-2.4.32-freewrt/arch/mips/kernel/head.S        2006-07-02 21:58:25.000000000 +0200
    160418847@@ -28,12 +28,20 @@
    160428848 #include <asm/mipsregs.h>
     
    160618867                /* The following two symbols are used for kernel profiling. */
    160628868                EXPORT(stext)
    16063 diff -urN linux.old/arch/mips/kernel/proc.c linux.dev/arch/mips/kernel/proc.c
    16064 --- linux.old/arch/mips/kernel/proc.c   2006-04-27 18:04:37.000000000 +0200
    16065 +++ linux.dev/arch/mips/kernel/proc.c   2006-04-27 19:24:19.000000000 +0200
     8869diff -Nur linux-2.4.32/arch/mips/kernel/proc.c linux-2.4.32-freewrt/arch/mips/kernel/proc.c
     8870--- linux-2.4.32/arch/mips/kernel/proc.c        2005-01-19 15:09:29.000000000 +0100
     8871+++ linux-2.4.32-freewrt/arch/mips/kernel/proc.c        2006-07-02 21:58:25.000000000 +0200
    160668872@@ -78,9 +78,10 @@
    160678873        [CPU_AU1550]    "Au1550",
     
    160768882 {
    160778883        unsigned int version = current_cpu_data.processor_id;
    16078 diff -urN linux.old/arch/mips/kernel/setup.c linux.dev/arch/mips/kernel/setup.c
    16079 --- linux.old/arch/mips/kernel/setup.c  2006-04-27 18:04:37.000000000 +0200
    16080 +++ linux.dev/arch/mips/kernel/setup.c  2006-04-27 19:24:19.000000000 +0200
    16081 @@ -493,6 +493,7 @@
     8884diff -Nur linux-2.4.32/arch/mips/kernel/setup.c linux-2.4.32-freewrt/arch/mips/kernel/setup.c
     8885--- linux-2.4.32/arch/mips/kernel/setup.c       2005-01-19 15:09:29.000000000 +0100
     8886+++ linux-2.4.32-freewrt/arch/mips/kernel/setup.c       2006-07-02 21:58:25.000000000 +0200
     8887@@ -495,6 +495,7 @@
    160828888        void swarm_setup(void);
    160838889        void hp_setup(void);
     
    160878893 
    160888894        frame_info_init();
    16089 @@ -691,6 +692,11 @@
     8895@@ -693,6 +694,11 @@
    160908896                 pmc_yosemite_setup();
    160918897                 break;
     
    160998905                panic("Unsupported architecture");
    161008906        }
    16101 diff -urN linux.old/arch/mips/kernel/traps.c linux.dev/arch/mips/kernel/traps.c
    16102 --- linux.old/arch/mips/kernel/traps.c  2006-04-27 18:04:37.000000000 +0200
    16103 +++ linux.dev/arch/mips/kernel/traps.c  2006-04-27 19:24:19.000000000 +0200
    16104 @@ -920,6 +920,7 @@
     8907diff -Nur linux-2.4.32/arch/mips/kernel/traps.c linux-2.4.32-freewrt/arch/mips/kernel/traps.c
     8908--- linux-2.4.32/arch/mips/kernel/traps.c       2005-01-19 15:09:29.000000000 +0100
     8909+++ linux-2.4.32-freewrt/arch/mips/kernel/traps.c       2006-07-02 21:58:25.000000000 +0200
     8910@@ -913,6 +913,7 @@
    161058911 void __init trap_init(void)
    161068912 {
     
    161108916        extern char except_vec_ejtag_debug;
    161118917        extern char except_vec4;
    16112 @@ -927,6 +928,7 @@
     8918@@ -922,6 +923,7 @@
    161138919 
    161148920        /* Copy the generic exception handler code to it's final destination. */
     
    161188924        /*
    161198925         * Setup default vectors
    16120 @@ -985,6 +987,12 @@
     8926@@ -980,6 +982,12 @@
    161218927        set_except_vector(13, handle_tr);
    161228928        set_except_vector(22, handle_mdmx);
     
    161318937                set_except_vector(15, handle_fpe);
    161328938 
    16133 diff -urN linux.old/arch/mips/mm/c-r4k.c linux.dev/arch/mips/mm/c-r4k.c
    16134 --- linux.old/arch/mips/mm/c-r4k.c      2006-04-27 18:04:37.000000000 +0200
    16135 +++ linux.dev/arch/mips/mm/c-r4k.c      2006-04-27 19:24:19.000000000 +0200
    16136 @@ -1166,3 +1166,47 @@
     8939diff -Nur linux-2.4.32/arch/mips/mm/c-r4k.c linux-2.4.32-freewrt/arch/mips/mm/c-r4k.c
     8940--- linux-2.4.32/arch/mips/mm/c-r4k.c   2005-01-19 15:09:29.000000000 +0100
     8941+++ linux-2.4.32-freewrt/arch/mips/mm/c-r4k.c   2006-07-02 21:58:25.000000000 +0200
     8942@@ -1114,3 +1114,47 @@
    161378943        build_clear_page();
    161388944        build_copy_page();
     
    161828988+
    161838989+
    16184 diff -urN linux.old/arch/mips/pci/Makefile linux.dev/arch/mips/pci/Makefile
    16185 --- linux.old/arch/mips/pci/Makefile    2006-04-27 18:04:37.000000000 +0200
    16186 +++ linux.dev/arch/mips/pci/Makefile    2006-04-27 19:24:19.000000000 +0200
     8990diff -Nur linux-2.4.32/arch/mips/pci/Makefile linux-2.4.32-freewrt/arch/mips/pci/Makefile
     8991--- linux-2.4.32/arch/mips/pci/Makefile 2005-01-19 15:09:29.000000000 +0100
     8992+++ linux-2.4.32-freewrt/arch/mips/pci/Makefile 2006-07-02 21:58:25.000000000 +0200
    161878993@@ -13,7 +13,9 @@
    161888994 obj-$(CONFIG_MIPS_MSC)         += ops-msc.o
     
    161959001 
    161969002 include $(TOPDIR)/Rules.make
    16197 diff -urN linux.old/drivers/char/serial.c linux.dev/drivers/char/serial.c
    16198 --- linux.old/drivers/char/serial.c     2006-04-27 18:04:37.000000000 +0200
    16199 +++ linux.dev/drivers/char/serial.c     2006-04-27 19:24:19.000000000 +0200
    16200 @@ -444,6 +444,10 @@
     9003diff -Nur linux-2.4.32/drivers/char/serial.c linux-2.4.32-freewrt/drivers/char/serial.c
     9004--- linux-2.4.32/drivers/char/serial.c  2005-11-16 20:12:54.000000000 +0100
     9005+++ linux-2.4.32-freewrt/drivers/char/serial.c  2006-07-02 21:58:25.000000000 +0200
     9006@@ -422,6 +422,10 @@
    162019007                return inb(info->port+1);
    162029008 #endif
     
    162099015                             (offset<<info->iomem_reg_shift));
    162109016        default:
    16211 @@ -464,6 +468,9 @@
     9017@@ -442,6 +446,9 @@
    162129018        case SERIAL_IO_MEM:
    162139019                writeb(value, (unsigned long) info->iomem_base +
     
    162199025        default:
    162209026                outb(value, info->port+offset);
    16221 @@ -1728,7 +1735,7 @@
     9027@@ -1704,7 +1711,7 @@
    162229028                        /* Special case since 134 is really 134.5 */
    162239029                        quot = (2*baud_base / 269);
     
    162289034        /* If the quotient is zero refuse the change */
    162299035        if (!quot && old_termios) {
    16230 @@ -1745,12 +1752,12 @@
     9036@@ -1721,12 +1728,12 @@
    162319037                                /* Special case since 134 is really 134.5 */
    162329038                                quot = (2*baud_base / 269);
     
    162439049         * Work around a bug in the Oxford Semiconductor 952 rev B
    162449050         * chip which causes it to seriously miscalculate baud rates
    16245 @@ -5994,6 +6001,13 @@
     9051@@ -5982,6 +5989,13 @@
    162469052         *      Divisor, bytesize and parity
    162479053         */
     
    162579063                state->flags |= ASYNC_CONS_FLOW;
    162589064        info = &async_sercons;
    16259 @@ -6007,7 +6021,7 @@
     9065@@ -5995,7 +6009,7 @@
    162609066        info->io_type = state->io_type;
    162619067        info->iomem_base = state->iomem_base;
     
    162669072 #if defined(__powerpc__) || defined(__alpha__)
    162679073        cval >>= 8;
    16268 diff -urN linux.old/drivers/net/Config.in linux.dev/drivers/net/Config.in
    16269 --- linux.old/drivers/net/Config.in     2006-04-27 18:04:38.000000000 +0200
    16270 +++ linux.dev/drivers/net/Config.in     2006-04-27 19:24:19.000000000 +0200
     9074diff -Nur linux-2.4.32/drivers/net/Config.in linux-2.4.32-freewrt/drivers/net/Config.in
     9075--- linux-2.4.32/drivers/net/Config.in  2005-01-19 15:09:56.000000000 +0100
     9076+++ linux-2.4.32-freewrt/drivers/net/Config.in  2006-07-02 21:58:25.000000000 +0200
    162719077@@ -2,6 +2,8 @@
    162729078 # Network device configuration
     
    162789084 
    162799085 tristate 'Dummy net driver support' CONFIG_DUMMY
    16280 diff -urN linux.old/drivers/net/Makefile linux.dev/drivers/net/Makefile
    16281 --- linux.old/drivers/net/Makefile      2006-04-27 18:04:38.000000000 +0200
    16282 +++ linux.dev/drivers/net/Makefile      2006-05-04 01:41:03.000000000 +0200
     9086diff -Nur linux-2.4.32/drivers/net/Makefile linux-2.4.32-freewrt/drivers/net/Makefile
     9087--- linux-2.4.32/drivers/net/Makefile   2005-01-19 15:09:56.000000000 +0100
     9088+++ linux-2.4.32-freewrt/drivers/net/Makefile   2006-07-02 21:58:25.000000000 +0200
    162839089@@ -3,6 +3,8 @@
    162849090 # Makefile for the Linux network (ethercard) device drivers.
     
    162909096 obj-m           :=
    162919097 obj-n           :=
    16292 @@ -39,6 +41,7 @@
     9098@@ -39,6 +41,8 @@
    162939099   obj-$(CONFIG_ISDN) += slhc.o
    162949100 endif
    162959101 
     9102+subdir-$(CONFIG_HND) += hnd
    162969103+subdir-$(CONFIG_WL) += wl
    162979104 subdir-$(CONFIG_NET_PCMCIA) += pcmcia
    162989105 subdir-$(CONFIG_NET_WIRELESS) += wireless
    162999106 subdir-$(CONFIG_TULIP) += tulip
    16300 diff -urN linux.old/drivers/net/wireless/Config.in linux.dev/drivers/net/wireless/Config.in
    16301 --- linux.old/drivers/net/wireless/Config.in    2006-04-27 18:04:38.000000000 +0200
    16302 +++ linux.dev/drivers/net/wireless/Config.in    2006-05-04 01:42:48.000000000 +0200
    16303 @@ -13,6 +13,7 @@
    16304  fi
     9107@@ -69,6 +73,13 @@
     9108 obj-$(CONFIG_MYRI_SBUS) += myri_sbus.o
     9109 obj-$(CONFIG_SUNGEM) += sungem.o
    163059110 
    16306  if [ "$CONFIG_PCI" = "y" ]; then
    16307 +   dep_tristate '    Proprietary Broadcom BCM43xx 802.11 Wireless support' CONFIG_WL
    16308     dep_tristate '    Hermes in PLX9052 based PCI adaptor support (Netgear MA301 etc.) (EXPERIMENTAL)' CONFIG_PLX_HERMES $CONFIG_HERMES $CONFIG_EXPERIMENTAL
    16309     dep_tristate '    Hermes in TMD7160/NCP130 based PCI adaptor support (Pheecom WL-PCI etc.) (EXPERIMENTAL)' CONFIG_TMD_HERMES $CONFIG_HERMES $CONFIG_EXPERIMENTAL
    16310     dep_tristate '    Prism 2.5 PCI 802.11b adaptor support (EXPERIMENTAL)' CONFIG_PCI_HERMES $CONFIG_HERMES $CONFIG_EXPERIMENTAL
    16311 diff -urN linux.old/drivers/net/wl/patchtable.pl linux.dev/drivers/net/wl/patchtable.pl
    16312 --- linux.old/drivers/net/wl/patchtable.pl      1970-01-01 01:00:00.000000000 +0100
    16313 +++ linux.dev/drivers/net/wl/patchtable.pl      2006-04-28 01:33:52.000000000 +0200
    16314 @@ -0,0 +1,54 @@
    16315 +#!/usr/bin/perl
    16316 +use strict;
    16317 +
    16318 +my $TABLE = pack("V", 0xbadc0ded);
    16319 +my $TABLE_SIZE = 512;
    16320 +my $SLT1 = "\x01\x00\x00\x00";
    16321 +my $SLT2 = "\x02\x00\x00\x00";
    16322 +my $ACKW = "\x03\x00\x00\x00";
    16323 +my $PTABLE_END = "\xff\xff\xff\xff";
    16324 +
    16325 +my $addr = "";
    16326 +my $opcode = "";
    16327 +my $function = "";
    16328 +
    16329 +sub add_entry {
    16330 +       my $key = shift;
    16331 +       my $value = shift;
    16332 +       my $default = shift;
    16333 +
    16334 +       $TABLE .= $key;
    16335 +       $TABLE .= pack("V", $value);
    16336 +       $TABLE .= pack("V", $default);
    16337 +}
    16338 +
    16339 +while (<>) {
    16340 +       $addr = $opcode = "";
    16341 +       /^\w{8}\s*<(.*)>:$/ and $function = $1;
    16342 +       /^\s*(\w+):\s*(\w{8})\s*/ and do {
    16343 +               $addr = $1;
    16344 +               $opcode = $2;
    16345 +       };
    16346 +
    16347 +       ($function eq 'wlc_update_slot_timing') and do {
    16348 +               # li    a2,9    -- short slot time
    16349 +               ($opcode eq '24060009') and add_entry($SLT1, hex($addr), hex($opcode));
    16350 +               # li    v0,519  -- 510 + short slot time
    16351 +               ($opcode eq '24020207') and add_entry($SLT2, hex($addr), hex($opcode));
    16352 +               
    16353 +               # li    a2,20   -- long slot time
    16354 +               ($opcode eq '24060014') and add_entry($SLT1, hex($addr), hex($opcode));
    16355 +               # li    v0,530  -- 510 + long slot time
    16356 +               ($opcode eq '24020212') and add_entry($SLT2, hex($addr), hex($opcode));
    16357 +       };
    16358 +       ($function eq 'wlc_d11hdrs') and do {
    16359 +               # ori   s6,s6,0x1 -- ack flag (new)
    16360 +               ($opcode eq '36d60001') and add_entry($ACKW, hex($addr), hex($opcode));
    16361 +               # ori   s3,s3,0x1 -- ack flag (old)
    16362 +               ($opcode eq '36730001') and add_entry($ACKW, hex($addr), hex($opcode));
    16363 +       }
    16364 +}
    16365 +
    16366 +$TABLE .= $PTABLE_END;
    16367 +$TABLE .= ("\x00" x ($TABLE_SIZE - length($TABLE)));
    16368 +print $TABLE;
    16369 diff -urN linux.old/drivers/net/wl/Makefile linux.dev/drivers/net/wl/Makefile
    16370 --- linux.old/drivers/net/wl/Makefile   1970-01-01 01:00:00.000000000 +0100
    16371 +++ linux.dev/drivers/net/wl/Makefile   2006-04-28 01:33:52.000000000 +0200
    16372 @@ -0,0 +1,32 @@
     9111+ifeq ($(CONFIG_HND),y)
     9112+  obj-y += hnd/hnd.o
     9113+endif
     9114+ifeq ($(CONFIG_WL),y)
     9115+  obj-y += wl/wl.o
     9116+endif
     9117+
     9118 obj-$(CONFIG_MACE) += mace.o
     9119 obj-$(CONFIG_BMAC) += bmac.o
     9120 obj-$(CONFIG_GMAC) += gmac.o
     9121diff -Nur linux-2.4.32/drivers/net/hnd/Makefile linux-2.4.32-freewrt/drivers/net/hnd/Makefile
     9122--- linux-2.4.32/drivers/net/hnd/Makefile       1970-01-01 01:00:00.000000000 +0100
     9123+++ linux-2.4.32-freewrt/drivers/net/hnd/Makefile       2006-07-02 21:58:25.000000000 +0200
     9124@@ -0,0 +1,19 @@
    163739125+#
    16374 +# Makefile for the Broadcom wl driver
     9126+# Makefile for the BCM47xx specific kernel interface routines
     9127+# under Linux.
    163759128+#
    16376 +# Copyright 2004, Broadcom Corporation
    16377 +# All Rights Reserved.
    16378 +#
    16379 +# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    16380 +# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    16381 +# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    16382 +# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    16383 +#
    16384 +# $Id: Makefile,v 1.2 2005/03/29 03:32:18 mbm Exp $
    16385 +
    16386 +EXTRA_CFLAGS += -I$(TOPDIR)/arch/mips/bcm947xx/include -DBCMDRIVER
    16387 +
    16388 +O_TARGET       := wl_link.o
    16389 +
    16390 +obj-y          := wl_mod.o
    16391 +obj-y          += bcmutils.o hnddma.o linux_osl.o
    16392 +
    16393 +obj-m          := $(O_TARGET)
    16394 +
    16395 +wl_mod.o: wl_apsta.o
    16396 +       cp $< $@ && perl -pi -e 's,eth%d,wl%d\x00,g' $@
    16397 +
    16398 +wl.o: wl_link.o
    16399 +       $(OBJDUMP) -d $< | perl patchtable.pl > patchtable.bin
    16400 +       cat wl_link.o patchtable.bin > $@
    16401 +
    16402 +modules: wl.o
     9129+
     9130+EXTRA_CFLAGS   += -I$(TOPDIR)/arch/mips/bcm947xx/include -DBCMDRIVER
     9131+
     9132+O_TARGET       := hnd.o
     9133+
     9134+HND_OBJS       := bcmutils.o hnddma.o linux_osl.o sbutils.o bcmsrom.o
     9135+
     9136+export-objs    := shared_ksyms.o
     9137+obj-y          := shared_ksyms.o $(HND_OBJS)
     9138+obj-m           := $(O_TARGET)
    164039139+
    164049140+include $(TOPDIR)/Rules.make
    16405 diff -urN linux.old/drivers/net/wl/bcmip.h linux.dev/drivers/net/wl/bcmip.h
    16406 --- linux.old/drivers/net/wl/bcmip.h    1970-01-01 01:00:00.000000000 +0100
    16407 +++ linux.dev/drivers/net/wl/bcmip.h    2006-04-28 02:11:28.000000000 +0200
    16408 @@ -0,0 +1,101 @@
     9141+
     9142+shared_ksyms.c: shared_ksyms.sh $(HND_OBJS)
     9143+       sh -e $< $(HND_OBJS) > $@
     9144diff -Nur linux-2.4.32/drivers/net/hnd/bcmsrom.c linux-2.4.32-freewrt/drivers/net/hnd/bcmsrom.c
     9145--- linux-2.4.32/drivers/net/hnd/bcmsrom.c      1970-01-01 01:00:00.000000000 +0100
     9146+++ linux-2.4.32-freewrt/drivers/net/hnd/bcmsrom.c      2006-07-02 21:58:25.000000000 +0200
     9147@@ -0,0 +1,716 @@
    164099148+/*
    16410 + * Copyright 2006, Broadcom Corporation
    16411 + * All Rights Reserved.
    16412 + *
    16413 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    16414 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    16415 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    16416 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
     9149+ *  Misc useful routines to access NIC SROM/OTP .
    164179150+ *
    16418 + * Fundamental constants relating to IP Protocol
    16419 + *
    16420 + * $Id: bcmip.h,v 1.1.1.3 2006/02/27 03:43:16 honor Exp $
     9151+ * Copyright 2004, Broadcom Corporation     
     9152+ * All Rights Reserved.     
     9153+ *       
     9154+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     9155+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     9156+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     9157+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     9158+ * $Id$
    164219159+ */
    164229160+
    16423 +#ifndef _bcmip_h_
    16424 +#define _bcmip_h_
    16425 +
    16426 +/* IPV4 and IPV6 common */
    16427 +#define IP_VER_OFFSET          0x0     /* offset to version field */
    16428 +#define IP_VER_MASK            0xf0    /* version mask */
    16429 +#define IP_VER_SHIFT           4       /* version shift */
    16430 +#define IP_VER_4               4       /* version number for IPV4 */
    16431 +#define IP_VER_6               6       /* version number for IPV6 */
    16432 +
    16433 +#define IP_VER(ip_body) \
    16434 +       ((((uint8 *)(ip_body))[IP_VER_OFFSET] & IP_VER_MASK) >> IP_VER_SHIFT)
    16435 +
    16436 +#define IP_PROT_ICMP           0x1     /* ICMP protocol */
    16437 +#define IP_PROT_TCP            0x6     /* TCP protocol */
    16438 +#define IP_PROT_UDP            0x11    /* UDP protocol type */
    16439 +
    16440 +/* IPV4 field offsets */
    16441 +#define IPV4_VER_HL_OFFSET     0       /* version and ihl byte offset */
    16442 +#define IPV4_TOS_OFFSET                1       /* type of service offset */
    16443 +#define IPV4_PROT_OFFSET       9       /* protocol type offset */
    16444 +#define IPV4_CHKSUM_OFFSET     10      /* IP header checksum offset */
    16445 +#define IPV4_SRC_IP_OFFSET     12      /* src IP addr offset */
    16446 +#define IPV4_DEST_IP_OFFSET    16      /* dest IP addr offset */
    16447 +
    16448 +/* IPV4 field decodes */
    16449 +#define IPV4_VER_MASK          0xf0    /* IPV4 version mask */
    16450 +#define IPV4_VER_SHIFT         4       /* IPV4 version shift */
    16451 +
    16452 +#define IPV4_HLEN_MASK         0x0f    /* IPV4 header length mask */
    16453 +#define IPV4_HLEN(ipv4_body)   (4 * (((uint8 *)(ipv4_body))[IPV4_VER_HL_OFFSET] & IPV4_HLEN_MASK))
    16454 +
    16455 +#define IPV4_ADDR_LEN          4       /* IPV4 address length */
    16456 +
    16457 +#define IPV4_ADDR_NULL(a)      ((((uint8 *)(a))[0] | ((uint8 *)(a))[1] | \
    16458 +                                 ((uint8 *)(a))[2] | ((uint8 *)(a))[3]) == 0)
    16459 +
    16460 +#define        IPV4_TOS_DSCP_MASK      0xfc    /* DiffServ codepoint mask */
    16461 +#define        IPV4_TOS_DSCP_SHIFT     2       /* DiffServ codepoint shift */
    16462 +
    16463 +#define        IPV4_TOS(ipv4_body)     (((uint8 *)(ipv4_body))[IPV4_TOS_OFFSET])
    16464 +
    16465 +#define        IPV4_TOS_PREC_MASK      0xe0    /* Historical precedence mask */
    16466 +#define        IPV4_TOS_PREC_SHIFT     5       /* Historical precedence shift */
    16467 +
    16468 +#define IPV4_TOS_LOWDELAY      0x10    /* Lowest delay requested */
    16469 +#define IPV4_TOS_THROUGHPUT    0x8     /* Best throughput requested */
    16470 +#define IPV4_TOS_RELIABILITY   0x4     /* Most reliable delivery requested */
    16471 +
    16472 +#define IPV4_PROT(ipv4_body)   (((uint8 *)(ipv4_body))[IPV4_PROT_OFFSET])
    16473 +
    16474 +#define IPV4_ADDR_STR_LEN      16      /* Max IP address length in string format */
    16475 +
    16476 +/* IPV6 field offsets */
    16477 +#define IPV6_PAYLOAD_LEN_OFFSET        4       /* payload length offset */
    16478 +#define IPV6_NEXT_HDR_OFFSET   6       /* next header/protocol offset */
    16479 +#define IPV6_HOP_LIMIT_OFFSET  7       /* hop limit offset */
    16480 +#define IPV6_SRC_IP_OFFSET     8       /* src IP addr offset */
    16481 +#define IPV6_DEST_IP_OFFSET    24      /* dst IP addr offset */
    16482 +
    16483 +/* IPV6 field decodes */
    16484 +#define IPV6_TRAFFIC_CLASS(ipv6_body) \
    16485 +       (((((uint8 *)(ipv6_body))[0] & 0x0f) << 4) | \
    16486 +        ((((uint8 *)(ipv6_body))[1] & 0xf0) >> 4))
    16487 +
    16488 +#define IPV6_FLOW_LABEL(ipv6_body) \
    16489 +       (((((uint8 *)(ipv6_body))[1] & 0x0f) << 16) | \
    16490 +        (((uint8 *)(ipv6_body))[2] << 8) | \
    16491 +        (((uint8 *)(ipv6_body))[3]))
    16492 +
    16493 +#define IPV6_PAYLOAD_LEN(ipv6_body) \
    16494 +       ((((uint8 *)(ipv6_body))[IPV6_PAYLOAD_LEN_OFFSET + 0] << 8) | \
    16495 +        ((uint8 *)(ipv6_body))[IPV6_PAYLOAD_LEN_OFFSET + 1])
    16496 +
    16497 +#define IPV6_NEXT_HDR(ipv6_body) \
    16498 +       (((uint8 *)(ipv6_body))[IPV6_NEXT_HDR_OFFSET])
    16499 +
    16500 +#define IPV6_PROT(ipv6_body)   IPV6_NEXT_HDR(ipv6_body)
    16501 +
    16502 +#define IPV6_ADDR_LEN          16      /* IPV6 address length */
    16503 +
    16504 +/* IPV4 TOS or IPV6 Traffic Classifier or 0 */
    16505 +#define IP_TOS(ip_body) \
    16506 +       (IP_VER(ip_body) == IP_VER_4 ? IPV4_TOS(ip_body) : \
    16507 +        IP_VER(ip_body) == IP_VER_6 ? IPV6_TRAFFIC_CLASS(ip_body) : 0)
    16508 +
    16509 +#endif /* _bcmip_h_ */
    16510 diff -urN linux.old/drivers/net/wl/bcmutils.c linux.dev/drivers/net/wl/bcmutils.c
    16511 --- linux.old/drivers/net/wl/bcmutils.c 1970-01-01 01:00:00.000000000 +0100
    16512 +++ linux.dev/drivers/net/wl/bcmutils.c 2006-04-28 02:27:20.000000000 +0200
    16513 @@ -0,0 +1,857 @@
     9161+#include <typedefs.h>
     9162+#include <osl.h>
     9163+#include <bcmutils.h>
     9164+#include <bcmsrom.h>
     9165+#include <bcmdevs.h>
     9166+#include <bcmendian.h>
     9167+#include <sbpcmcia.h>
     9168+#include <pcicfg.h>
     9169+#include <sbutils.h>
     9170+
     9171+struct  ether_addr {
     9172+       uint8 octet[6];
     9173+} PACKED;
     9174+
     9175+#define        VARS_MAX        4096    /* should be reduced */
     9176+
     9177+#define WRITE_ENABLE_DELAY     500     /* 500 ms after write enable/disable toggle */
     9178+#define WRITE_WORD_DELAY       20      /* 20 ms between each word write */
     9179+
     9180+static int initvars_srom_pci(void *osh, void *curmap, char **vars, int *count);
     9181+static int initvars_cis_pcmcia(void *sbh, void *curmap, void *osh, char **vars, int *count);
     9182+static int srom_parsecis(void *osh, uint8 *cis, char **vars, int *count);
     9183+static int sprom_cmd_pcmcia(void *osh, uint8 cmd);
     9184+static int sprom_read_pcmcia(void *osh, uint16 addr, uint16 *data);
     9185+static int sprom_write_pcmcia(void *osh, uint16 addr, uint16 data);
     9186+static int sprom_read_pci(uint16 *sprom, uint wordoff, uint16 *buf, uint nwords, bool check_crc);
     9187+
     9188+/*
     9189+ * Initialize local vars from the right source for this platform.
     9190+ * Return 0 on success, nonzero on error.
     9191+ */
     9192+int
     9193+srom_var_init(void *sbh, uint bustype, void *curmap, void *osh, char **vars, int *count)
     9194+{
     9195+       ASSERT(bustype == BUSTYPE(bustype));
     9196+       if (vars == NULL)
     9197+               return (0);
     9198+
     9199+       switch (BUSTYPE(bustype)) {
     9200+       case SB_BUS:
     9201+               /* These two could be asserts ... */
     9202+               *vars = NULL;
     9203+               *count = 0;
     9204+               return(0);
     9205+
     9206+       case PCI_BUS:
     9207+               ASSERT(curmap); /* can not be NULL */
     9208+               return(initvars_srom_pci(osh, curmap, vars, count));
     9209+
     9210+       case PCMCIA_BUS:
     9211+               return(initvars_cis_pcmcia(sbh, curmap, osh, vars, count));
     9212+
     9213+
     9214+       default:
     9215+               ASSERT(0);
     9216+       }
     9217+       return (-1);
     9218+}
     9219+
     9220+/* support only 16-bit word read from srom */
     9221+int
     9222+srom_read(uint bustype, void *curmap, void *osh, uint byteoff, uint nbytes, uint16 *buf)
     9223+{
     9224+       void *srom;
     9225+       uint i, off, nw;
     9226+
     9227+       ASSERT(bustype == BUSTYPE(bustype));
     9228+
     9229+       /* check input - 16-bit access only */
     9230+       if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > (SPROM_SIZE * 2))
     9231+               return 1;
     9232+
     9233+       off = byteoff / 2;
     9234+       nw = nbytes / 2;
     9235+
     9236+       if (BUSTYPE(bustype) == PCI_BUS) {
     9237+               if (!curmap)
     9238+                       return 1;
     9239+               srom = (uchar*)curmap + PCI_BAR0_SPROM_OFFSET;
     9240+               if (sprom_read_pci(srom, off, buf, nw, FALSE))
     9241+                       return 1;
     9242+       } else if (BUSTYPE(bustype) == PCMCIA_BUS) {
     9243+               for (i = 0; i < nw; i++) {
     9244+                       if (sprom_read_pcmcia(osh, (uint16)(off + i), (uint16*)(buf + i)))
     9245+                               return 1;
     9246+               }
     9247+       } else {
     9248+               return 1;
     9249+       }
     9250+
     9251+       return 0;
     9252+}
     9253+
     9254+/* support only 16-bit word write into srom */
     9255+int
     9256+srom_write(uint bustype, void *curmap, void *osh, uint byteoff, uint nbytes, uint16 *buf)
     9257+{
     9258+       uint16 *srom;
     9259+       uint i, off, nw, crc_range;
     9260+       uint16 image[SPROM_SIZE], *p;
     9261+       uint8 crc;
     9262+       volatile uint32 val32;
     9263+
     9264+       ASSERT(bustype == BUSTYPE(bustype));
     9265+
     9266+       /* check input - 16-bit access only */
     9267+       if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > (SPROM_SIZE * 2))
     9268+               return 1;
     9269+
     9270+       crc_range = (((BUSTYPE(bustype) == PCMCIA_BUS) || (BUSTYPE(bustype) == SDIO_BUS)) ? SPROM_SIZE : SPROM_CRC_RANGE) * 2;
     9271+
     9272+       /* if changes made inside crc cover range */
     9273+       if (byteoff < crc_range) {
     9274+               nw = (((byteoff + nbytes) > crc_range) ? byteoff + nbytes : crc_range) / 2;
     9275+               /* read data including entire first 64 words from srom */
     9276+               if (srom_read(bustype, curmap, osh, 0, nw * 2, image))
     9277+                       return 1;
     9278+               /* make changes */
     9279+               bcopy((void*)buf, (void*)&image[byteoff / 2], nbytes);
     9280+               /* calculate crc */
     9281+               htol16_buf(image, crc_range);
     9282+               crc = ~hndcrc8((uint8 *)image, crc_range - 1, CRC8_INIT_VALUE);
     9283+               ltoh16_buf(image, crc_range);
     9284+               image[(crc_range / 2) - 1] = (crc << 8) | (image[(crc_range / 2) - 1] & 0xff);
     9285+               p = image;
     9286+               off = 0;
     9287+       } else {
     9288+               p = buf;
     9289+               off = byteoff / 2;
     9290+               nw = nbytes / 2;
     9291+       }
     9292+
     9293+       if (BUSTYPE(bustype) == PCI_BUS) {
     9294+               srom = (uint16*)((uchar*)curmap + PCI_BAR0_SPROM_OFFSET);
     9295+               /* enable writes to the SPROM */
     9296+               val32 = OSL_PCI_READ_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32));
     9297+               val32 |= SPROM_WRITEEN;
     9298+               OSL_PCI_WRITE_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32), val32);
     9299+               bcm_mdelay(WRITE_ENABLE_DELAY);
     9300+               /* write srom */
     9301+               for (i = 0; i < nw; i++) {
     9302+                       W_REG(&srom[off + i], p[i]);
     9303+                       bcm_mdelay(WRITE_WORD_DELAY);
     9304+               }
     9305+               /* disable writes to the SPROM */
     9306+               OSL_PCI_WRITE_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32), val32 & ~SPROM_WRITEEN);
     9307+       } else if (BUSTYPE(bustype) == PCMCIA_BUS) {
     9308+               /* enable writes to the SPROM */
     9309+               if (sprom_cmd_pcmcia(osh, SROM_WEN))
     9310+                       return 1;
     9311+               bcm_mdelay(WRITE_ENABLE_DELAY);
     9312+               /* write srom */
     9313+               for (i = 0; i < nw; i++) {
     9314+                       sprom_write_pcmcia(osh, (uint16)(off + i), p[i]);
     9315+                       bcm_mdelay(WRITE_WORD_DELAY);
     9316+               }
     9317+               /* disable writes to the SPROM */
     9318+               if (sprom_cmd_pcmcia(osh, SROM_WDS))
     9319+                       return 1;
     9320+       } else {
     9321+               return 1;
     9322+       }
     9323+
     9324+       bcm_mdelay(WRITE_ENABLE_DELAY);
     9325+       return 0;
     9326+}
     9327+
     9328+
     9329+static int
     9330+srom_parsecis(void *osh, uint8 *cis, char **vars, int *count)
     9331+{
     9332+       char eabuf[32];
     9333+       char *vp, *base;
     9334+       uint8 tup, tlen, sromrev = 1;
     9335+       int i, j;
     9336+       uint varsize;
     9337+       bool ag_init = FALSE;
     9338+       uint16 w;
     9339+
     9340+       ASSERT(vars);
     9341+       ASSERT(count);
     9342+
     9343+       base = vp = MALLOC(osh, VARS_MAX);
     9344+       ASSERT(vp);
     9345+
     9346+       i = 0;
     9347+       do {
     9348+               tup = cis[i++];
     9349+               tlen = cis[i++];
     9350+               if ((i + tlen) >= CIS_SIZE)
     9351+                       break;
     9352+
     9353+               switch (tup) {
     9354+               case CISTPL_MANFID:
     9355+                       vp += sprintf(vp, "manfid=%d", (cis[i + 1] << 8) + cis[i]);
     9356+                       vp++;
     9357+                       vp += sprintf(vp, "prodid=%d", (cis[i + 3] << 8) + cis[i + 2]);
     9358+                       vp++;
     9359+                       break;
     9360+
     9361+               case CISTPL_FUNCE:
     9362+                       if (cis[i] == LAN_NID) {
     9363+                               ASSERT(cis[i + 1] == 6);
     9364+                               bcm_ether_ntoa((uchar*)&cis[i + 2], eabuf);
     9365+                               vp += sprintf(vp, "il0macaddr=%s", eabuf);
     9366+                               vp++;
     9367+                       }
     9368+                       break;
     9369+
     9370+               case CISTPL_CFTABLE:
     9371+                       vp += sprintf(vp, "regwindowsz=%d", (cis[i + 7] << 8) | cis[i + 6]);
     9372+                       vp++;
     9373+                       break;
     9374+
     9375+               case CISTPL_BRCM_HNBU:
     9376+                       switch (cis[i]) {
     9377+                       case HNBU_CHIPID:
     9378+                               vp += sprintf(vp, "vendid=%d", (cis[i + 2] << 8) + cis[i + 1]);
     9379+                               vp++;
     9380+                               vp += sprintf(vp, "devid=%d", (cis[i + 4] << 8) + cis[i + 3]);
     9381+                               vp++;
     9382+                               if (tlen == 7) {
     9383+                                       vp += sprintf(vp, "chiprev=%d", (cis[i + 6] << 8) + cis[i + 5]);
     9384+                                       vp++;
     9385+                               }
     9386+                               break;
     9387+
     9388+                       case HNBU_BOARDREV:
     9389+                               vp += sprintf(vp, "boardrev=%d", cis[i + 1]);
     9390+                               vp++;
     9391+                               break;
     9392+
     9393+                       case HNBU_AA:
     9394+                               vp += sprintf(vp, "aa0=%d", cis[i + 1]);
     9395+                               vp++;
     9396+                               break;
     9397+
     9398+                       case HNBU_AG:
     9399+                               vp += sprintf(vp, "ag0=%d", cis[i + 1]);
     9400+                               vp++;
     9401+                               ag_init = TRUE;
     9402+                               break;
     9403+
     9404+                       case HNBU_CC:
     9405+                               vp += sprintf(vp, "cc=%d", cis[i + 1]);
     9406+                               vp++;
     9407+                               break;
     9408+
     9409+                       case HNBU_PAPARMS:
     9410+                               vp += sprintf(vp, "pa0maxpwr=%d", cis[i + tlen - 1]);
     9411+                               vp++;
     9412+                               if (tlen == 9) {
     9413+                                       /* New version */
     9414+                                       for (j = 0; j < 3; j++) {
     9415+                                               vp += sprintf(vp, "pa0b%d=%d", j,
     9416+                                                             (cis[i + (j * 2) + 2] << 8) + cis[i + (j * 2) + 1]);
     9417+                                               vp++;
     9418+                                       }
     9419+                                       vp += sprintf(vp, "pa0itssit=%d", cis[i + 7]);
     9420+                                       vp++;
     9421+                               }
     9422+                               break;
     9423+
     9424+                       case HNBU_OEM:
     9425+                               vp += sprintf(vp, "oem=%02x%02x%02x%02x%02x%02x%02x%02x",
     9426+                                       cis[i + 1], cis[i + 2], cis[i + 3], cis[i + 4],
     9427+                                       cis[i + 5], cis[i + 6], cis[i + 7], cis[i + 8]);
     9428+                               vp++;
     9429+                               break;
     9430+                       case HNBU_BOARDFLAGS:
     9431+                               w = (cis[i + 2] << 8) + cis[i + 1];
     9432+                               if (w == 0xffff) w = 0;
     9433+                               vp += sprintf(vp, "boardflags=%d", w);
     9434+                               vp++;
     9435+                               break;
     9436+                       case HNBU_LED:
     9437+                               if (cis[i + 1] != 0xff) {
     9438+                                       vp += sprintf(vp, "wl0gpio0=%d", cis[i + 1]);
     9439+                                       vp++;
     9440+                               }
     9441+                               if (cis[i + 2] != 0xff) {
     9442+                                       vp += sprintf(vp, "wl0gpio1=%d", cis[i + 2]);
     9443+                                       vp++;
     9444+                               }
     9445+                               if (cis[i + 3] != 0xff) {
     9446+                                       vp += sprintf(vp, "wl0gpio2=%d", cis[i + 3]);
     9447+                                       vp++;
     9448+                               }
     9449+                               if (cis[i + 4] != 0xff) {
     9450+                                       vp += sprintf(vp, "wl0gpio3=%d", cis[i + 4]);
     9451+                                       vp++;
     9452+                               }
     9453+                               break;
     9454+                       }
     9455+                       break;
     9456+
     9457+               }
     9458+               i += tlen;
     9459+       } while (tup != 0xff);
     9460+
     9461+       /* Set the srom version */
     9462+       vp += sprintf(vp, "sromrev=%d", sromrev);
     9463+       vp++;
     9464+
     9465+       /* For now just set boardflags2 to zero */
     9466+       vp += sprintf(vp, "boardflags2=0");
     9467+       vp++;
     9468+
     9469+       /* if there is no antenna gain field, set default */
     9470+       if (ag_init == FALSE) {
     9471+               vp += sprintf(vp, "ag0=%d", 0xff);
     9472+               vp++;
     9473+       }
     9474+
     9475+       /* final nullbyte terminator */
     9476+       *vp++ = '\0';
     9477+       varsize = (uint)(vp - base);
     9478+
     9479+       ASSERT((vp - base) < VARS_MAX);
     9480+
     9481+       if (varsize == VARS_MAX) {
     9482+               *vars = base;
     9483+       } else {
     9484+               vp = MALLOC(osh, varsize);
     9485+               ASSERT(vp);
     9486+               bcopy(base, vp, varsize);
     9487+               MFREE(osh, base, VARS_MAX);
     9488+               *vars = vp;
     9489+       }
     9490+       *count = varsize;
     9491+
     9492+       return (0);
     9493+}
     9494+
     9495+
     9496+/* set PCMCIA sprom command register */
     9497+static int
     9498+sprom_cmd_pcmcia(void *osh, uint8 cmd)
     9499+{
     9500+       uint8 status = 0;
     9501+       uint wait_cnt = 1000;
     9502+
     9503+       /* write sprom command register */
     9504+       OSL_PCMCIA_WRITE_ATTR(osh, SROM_CS, &cmd, 1);
     9505+
     9506+       /* wait status */
     9507+       while (wait_cnt--) {
     9508+               OSL_PCMCIA_READ_ATTR(osh, SROM_CS, &status, 1);
     9509+               if (status & SROM_DONE)
     9510+                       return 0;
     9511+       }
     9512+
     9513+       return 1;
     9514+}
     9515+
     9516+/* read a word from the PCMCIA srom */
     9517+static int
     9518+sprom_read_pcmcia(void *osh, uint16 addr, uint16 *data)
     9519+{
     9520+       uint8 addr_l, addr_h, data_l, data_h;
     9521+
     9522+       addr_l = (uint8)((addr * 2) & 0xff);
     9523+       addr_h = (uint8)(((addr * 2) >> 8) & 0xff);
     9524+
     9525+       /* set address */
     9526+       OSL_PCMCIA_WRITE_ATTR(osh, SROM_ADDRH, &addr_h, 1);
     9527+       OSL_PCMCIA_WRITE_ATTR(osh, SROM_ADDRL, &addr_l, 1);
     9528+
     9529+       /* do read */
     9530+       if (sprom_cmd_pcmcia(osh, SROM_READ))
     9531+               return 1;
     9532+
     9533+       /* read data */
     9534+       data_h = data_l = 0;
     9535+       OSL_PCMCIA_READ_ATTR(osh, SROM_DATAH, &data_h, 1);
     9536+       OSL_PCMCIA_READ_ATTR(osh, SROM_DATAL, &data_l, 1);
     9537+
     9538+       *data = (data_h << 8) | data_l;
     9539+       return 0;
     9540+}
     9541+
     9542+/* write a word to the PCMCIA srom */
     9543+static int
     9544+sprom_write_pcmcia(void *osh, uint16 addr, uint16 data)
     9545+{
     9546+       uint8 addr_l, addr_h, data_l, data_h;
     9547+
     9548+       addr_l = (uint8)((addr * 2) & 0xff);
     9549+       addr_h = (uint8)(((addr * 2) >> 8) & 0xff);
     9550+       data_l = (uint8)(data & 0xff);
     9551+       data_h = (uint8)((data >> 8) & 0xff);
     9552+
     9553+       /* set address */
     9554+       OSL_PCMCIA_WRITE_ATTR(osh, SROM_ADDRH, &addr_h, 1);
     9555+       OSL_PCMCIA_WRITE_ATTR(osh, SROM_ADDRL, &addr_l, 1);
     9556+
     9557+       /* write data */
     9558+       OSL_PCMCIA_WRITE_ATTR(osh, SROM_DATAH, &data_h, 1);
     9559+       OSL_PCMCIA_WRITE_ATTR(osh, SROM_DATAL, &data_l, 1);
     9560+
     9561+       /* do write */
     9562+       return sprom_cmd_pcmcia(osh, SROM_WRITE);
     9563+}
     9564+
     9565+/*
     9566+ * Read in and validate sprom.
     9567+ * Return 0 on success, nonzero on error.
     9568+ */
     9569+static int
     9570+sprom_read_pci(uint16 *sprom, uint wordoff, uint16 *buf, uint nwords, bool check_crc)
     9571+{
     9572+       uint8 chk8;
     9573+       uint i;
     9574+
     9575+       /* read the sprom */
     9576+       for (i = 0; i < nwords; i++)
     9577+               buf[i] = R_REG(&sprom[wordoff + i]);
     9578+
     9579+       if (check_crc) {
     9580+               /* fixup the endianness so crc8 will pass */
     9581+               htol16_buf(buf, nwords * 2);
     9582+               if ((chk8 = hndcrc8((uchar*)buf, nwords * 2, CRC8_INIT_VALUE)) != CRC8_GOOD_VALUE)
     9583+                       return (1);
     9584+               /* now correct the endianness of the byte array */
     9585+               ltoh16_buf(buf, nwords * 2);
     9586+       }
     9587+
     9588+       return (0);
     9589+}
     9590+
     9591+/*
     9592+ * Initialize nonvolatile variable table from sprom.
     9593+ * Return 0 on success, nonzero on error.
     9594+ */
     9595+
     9596+static int
     9597+initvars_srom_pci(void *osh, void *curmap, char **vars, int *count)
     9598+{
     9599+       uint16 w, b[64];
     9600+       uint8 sromrev;
     9601+       struct ether_addr ea;
     9602+       char eabuf[32];             
     9603+       uint32 bfl;
     9604+       int c, woff, i;
     9605+       char *vp, *base;
     9606+
     9607+       if (sprom_read_pci((void*)((int8*)curmap + PCI_BAR0_SPROM_OFFSET), 0, b, sizeof(b)/sizeof(b[0]), TRUE))
     9608+               return (-1);
     9609+
     9610+       /* top word of sprom contains version and crc8 */
     9611+       sromrev = b[63] & 0xff;
     9612+       /* bcm4401 sroms misprogrammed */
     9613+       if (sromrev == 0x10)
     9614+               sromrev = 1;
     9615+       if ((sromrev != 1) && (sromrev != 2))
     9616+               return (-2);
     9617+
     9618+       ASSERT(vars);
     9619+       ASSERT(count);
     9620+
     9621+       base = vp = MALLOC(osh, VARS_MAX);
     9622+       ASSERT(vp);
     9623+
     9624+       vp += sprintf(vp, "sromrev=%d", sromrev);
     9625+       vp++;
     9626+
     9627+       if (sromrev >= 2) {
     9628+               /* New section takes over the 4th hardware function space */
     9629+
     9630+               /* Word 29 is max power 11a high/low */
     9631+               w = b[29];
     9632+               vp += sprintf(vp, "pa1himaxpwr=%d", w & 0xff);
     9633+               vp++;
     9634+               vp += sprintf(vp, "pa1lomaxpwr=%d", (w >> 8) & 0xff);
     9635+               vp++;
     9636+
     9637+               /* Words 30-32 set the 11alow pa settings,
     9638+                * 33-35 are the 11ahigh ones.
     9639+                */
     9640+               for (i = 0; i < 3; i++) {
     9641+                       vp += sprintf(vp, "pa1lob%d=%d", i, b[30 + i]);
     9642+                       vp++;
     9643+                       vp += sprintf(vp, "pa1hib%d=%d", i, b[33 + i]);
     9644+                       vp++;
     9645+               }
     9646+               w = b[59];
     9647+               if (w == 0)
     9648+                       vp += sprintf(vp, "ccode=");
     9649+               else
     9650+                       vp += sprintf(vp, "ccode=%c%c", (w >> 8), (w & 0xff));
     9651+               vp++;
     9652+
     9653+       }
     9654+
     9655+       /* parameter section of sprom starts at byte offset 72 */
     9656+       woff = 72/2;
     9657+
     9658+       /* first 6 bytes are il0macaddr */
     9659+       ea.octet[0] = (b[woff] >> 8) & 0xff;
     9660+       ea.octet[1] = b[woff] & 0xff;
     9661+       ea.octet[2] = (b[woff+1] >> 8) & 0xff;
     9662+       ea.octet[3] = b[woff+1] & 0xff;
     9663+       ea.octet[4] = (b[woff+2] >> 8) & 0xff;
     9664+       ea.octet[5] = b[woff+2] & 0xff;
     9665+       woff += 3;
     9666+       bcm_ether_ntoa((uchar*)&ea, eabuf);
     9667+       vp += sprintf(vp, "il0macaddr=%s", eabuf);
     9668+       vp++;
     9669+
     9670+       /* next 6 bytes are et0macaddr */
     9671+       ea.octet[0] = (b[woff] >> 8) & 0xff;
     9672+       ea.octet[1] = b[woff] & 0xff;
     9673+       ea.octet[2] = (b[woff+1] >> 8) & 0xff;
     9674+       ea.octet[3] = b[woff+1] & 0xff;
     9675+       ea.octet[4] = (b[woff+2] >> 8) & 0xff;
     9676+       ea.octet[5] = b[woff+2] & 0xff;
     9677+       woff += 3;
     9678+       bcm_ether_ntoa((uchar*)&ea, eabuf);
     9679+       vp += sprintf(vp, "et0macaddr=%s", eabuf);
     9680+       vp++;
     9681+
     9682+       /* next 6 bytes are et1macaddr */
     9683+       ea.octet[0] = (b[woff] >> 8) & 0xff;
     9684+       ea.octet[1] = b[woff] & 0xff;
     9685+       ea.octet[2] = (b[woff+1] >> 8) & 0xff;
     9686+       ea.octet[3] = b[woff+1] & 0xff;
     9687+       ea.octet[4] = (b[woff+2] >> 8) & 0xff;
     9688+       ea.octet[5] = b[woff+2] & 0xff;
     9689+       woff += 3;
     9690+       bcm_ether_ntoa((uchar*)&ea, eabuf);
     9691+       vp += sprintf(vp, "et1macaddr=%s", eabuf);
     9692+       vp++;
     9693+
     9694+       /*
     9695+        * Enet phy settings one or two singles or a dual
     9696+        * Bits 4-0 : MII address for enet0 (0x1f for not there)
     9697+        * Bits 9-5 : MII address for enet1 (0x1f for not there)
     9698+        * Bit 14   : Mdio for enet0
     9699+        * Bit 15   : Mdio for enet1
     9700+        */
     9701+       w = b[woff];
     9702+       vp += sprintf(vp, "et0phyaddr=%d", (w & 0x1f));
     9703+       vp++;
     9704+       vp += sprintf(vp, "et1phyaddr=%d", ((w >> 5) & 0x1f));
     9705+       vp++;
     9706+       vp += sprintf(vp, "et0mdcport=%d", ((w >> 14) & 0x1));
     9707+       vp++;
     9708+       vp += sprintf(vp, "et1mdcport=%d", ((w >> 15) & 0x1));
     9709+       vp++;
     9710+
     9711+       /* Word 46 has board rev, antennas 0/1 & Country code/control */
     9712+       w = b[46];
     9713+       vp += sprintf(vp, "boardrev=%d", w & 0xff);
     9714+       vp++;
     9715+
     9716+       if (sromrev > 1)
     9717+               vp += sprintf(vp, "cctl=%d", (w >> 8) & 0xf);
     9718+       else
     9719+               vp += sprintf(vp, "cc=%d", (w >> 8) & 0xf);
     9720+       vp++;
     9721+
     9722+       vp += sprintf(vp, "aa0=%d", (w >> 12) & 0x3);
     9723+       vp++;
     9724+
     9725+       vp += sprintf(vp, "aa1=%d", (w >> 14) & 0x3);
     9726+       vp++;
     9727+
     9728+       /* Words 47-49 set the (wl) pa settings */
     9729+       woff = 47;
     9730+
     9731+       for (i = 0; i < 3; i++) {
     9732+               vp += sprintf(vp, "pa0b%d=%d", i, b[woff+i]);
     9733+               vp++;
     9734+               vp += sprintf(vp, "pa1b%d=%d", i, b[woff+i+6]);
     9735+               vp++;
     9736+       }
     9737+
     9738+       /*
     9739+        * Words 50-51 set the customer-configured wl led behavior.
     9740+        * 8 bits/gpio pin.  High bit:  activehi=0, activelo=1;
     9741+        * LED behavior values defined in wlioctl.h .
     9742+        */
     9743+       w = b[50];
     9744+       if ((w != 0) && (w != 0xffff)) {
     9745+               /* gpio0 */
     9746+               vp += sprintf(vp, "wl0gpio0=%d", (w & 0xff));
     9747+               vp++;
     9748+
     9749+               /* gpio1 */
     9750+               vp += sprintf(vp, "wl0gpio1=%d", (w >> 8) & 0xff);
     9751+               vp++;
     9752+       }
     9753+       w = b[51];
     9754+       if ((w != 0) && (w != 0xffff)) {
     9755+               /* gpio2 */
     9756+               vp += sprintf(vp, "wl0gpio2=%d", w & 0xff);
     9757+               vp++;
     9758+
     9759+               /* gpio3 */
     9760+               vp += sprintf(vp, "wl0gpio3=%d", (w >> 8) & 0xff);
     9761+               vp++;
     9762+       }
     9763+       
     9764+       /* Word 52 is max power 0/1 */
     9765+       w = b[52];
     9766+       vp += sprintf(vp, "pa0maxpwr=%d", w & 0xff);
     9767+       vp++;
     9768+       vp += sprintf(vp, "pa1maxpwr=%d", (w >> 8) & 0xff);
     9769+       vp++;
     9770+
     9771+       /* Word 56 is idle tssi target 0/1 */
     9772+       w = b[56];
     9773+       vp += sprintf(vp, "pa0itssit=%d", w & 0xff);
     9774+       vp++;
     9775+       vp += sprintf(vp, "pa1itssit=%d", (w >> 8) & 0xff);
     9776+       vp++;
     9777+
     9778+       /* Word 57 is boardflags, if not programmed make it zero */
     9779+       bfl = (uint32)b[57];
     9780+       if (bfl == 0xffff) bfl = 0;
     9781+       if (sromrev > 1) {
     9782+               /* Word 28 is boardflags2 */
     9783+               bfl |= (uint32)b[28] << 16;
     9784+       }
     9785+       vp += sprintf(vp, "boardflags=%d", bfl);
     9786+       vp++;
     9787+
     9788+       /* Word 58 is antenna gain 0/1 */
     9789+       w = b[58];
     9790+       vp += sprintf(vp, "ag0=%d", w & 0xff);
     9791+       vp++;
     9792+
     9793+       vp += sprintf(vp, "ag1=%d", (w >> 8) & 0xff);
     9794+       vp++;
     9795+
     9796+       if (sromrev == 1) {
     9797+               /* set the oem string */
     9798+               vp += sprintf(vp, "oem=%02x%02x%02x%02x%02x%02x%02x%02x",
     9799+                             ((b[59] >> 8) & 0xff), (b[59] & 0xff),
     9800+                             ((b[60] >> 8) & 0xff), (b[60] & 0xff),
     9801+                             ((b[61] >> 8) & 0xff), (b[61] & 0xff),
     9802+                             ((b[62] >> 8) & 0xff), (b[62] & 0xff));
     9803+               vp++;
     9804+       } else {
     9805+               /* Word 60 OFDM tx power offset from CCK level */
     9806+               /* OFDM Power Offset - opo */
     9807+               vp += sprintf(vp, "opo=%d", b[60] & 0xff);
     9808+               vp++;
     9809+       }
     9810+
     9811+       /* final nullbyte terminator */
     9812+       *vp++ = '\0';
     9813+
     9814+       c = (int)(vp - base);
     9815+       ASSERT((vp - base) <= VARS_MAX);
     9816+
     9817+       if (c == VARS_MAX) {
     9818+               *vars = base;
     9819+       } else {
     9820+               vp = MALLOC(osh, c);
     9821+               ASSERT(vp);
     9822+               bcopy(base, vp, c);
     9823+               MFREE(osh, base, VARS_MAX);
     9824+               *vars = vp;
     9825+       }
     9826+       *count = c;
     9827+
     9828+       return (0);
     9829+}
     9830+
     9831+/*
     9832+ * Read the cis and call parsecis to initialize the vars.
     9833+ * Return 0 on success, nonzero on error.
     9834+ */
     9835+static int
     9836+initvars_cis_pcmcia(void *sbh, void *curmap, void *osh, char **vars, int *count)
     9837+{
     9838+       uint8 *cis = NULL;
     9839+       int rc;
     9840+       uint data_sz;
     9841+
     9842+       data_sz = (sb_pcmciarev(sbh) == 1) ? (SPROM_SIZE * 2) : CIS_SIZE;
     9843+
     9844+       if ((cis = MALLOC(osh, data_sz)) == NULL)
     9845+               return (-2);
     9846+
     9847+       if (sb_pcmciarev(sbh) == 1) {
     9848+               if (srom_read(PCMCIA_BUS, (void *)NULL, osh, 0, data_sz, (uint16 *)cis)) {
     9849+                       MFREE(osh, cis, data_sz);
     9850+                       return (-1);
     9851+               }
     9852+               /* fix up endianess for 16-bit data vs 8-bit parsing */
     9853+               ltoh16_buf((uint16 *)cis, data_sz);
     9854+       } else
     9855+               OSL_PCMCIA_READ_ATTR(osh, 0, cis, data_sz);
     9856+
     9857+       rc = srom_parsecis(osh, cis, vars, count);
     9858+
     9859+       MFREE(osh, cis, data_sz);
     9860+
     9861+       return (rc);
     9862+}
     9863+
     9864diff -Nur linux-2.4.32/drivers/net/hnd/bcmutils.c linux-2.4.32-freewrt/drivers/net/hnd/bcmutils.c
     9865--- linux-2.4.32/drivers/net/hnd/bcmutils.c     1970-01-01 01:00:00.000000000 +0100
     9866+++ linux-2.4.32-freewrt/drivers/net/hnd/bcmutils.c     2006-07-02 21:58:25.000000000 +0200
     9867@@ -0,0 +1,862 @@
    165149868+/*
    165159869+ * Misc useful OS-independent routines.
    165169870+ *
    16517 + * Copyright 2006, Broadcom Corporation
    16518 + * All Rights Reserved.
    16519 + *
    16520 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    16521 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    16522 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    16523 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    16524 + * $Id: bcmutils.c,v 1.1.1.12 2006/02/27 03:43:16 honor Exp $
     9871+ * Copyright 2004, Broadcom Corporation     
     9872+ * All Rights Reserved.     
     9873+ *      
     9874+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     9875+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     9876+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     9877+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     9878+ * $Id$
    165259879+ */
    165269880+
    165279881+#include <typedefs.h>
    16528 +#include <bcmdefs.h>
    16529 +#include <stdarg.h>
    165309882+#include <osl.h>
    16531 +#include "linux_osl.h"
    16532 +#include "pktq.h"
     9883+#include <bcmnvram.h>
    165339884+#include <bcmutils.h>
    16534 +#include <sbutils.h>
    16535 +#include <bcmnvram.h>
    165369885+#include <bcmendian.h>
    165379886+#include <bcmdevs.h>
    16538 +#include "bcmip.h"
    16539 +
    16540 +#define ETHER_TYPE_8021Q       0x8100
    16541 +#define ETHER_TYPE_IP          0x0800
    16542 +#define VLAN_PRI_SHIFT             13
    16543 +#define VLAN_PRI_MASK               7
    16544 +
    16545 +
    16546 +struct  ether_header {
    16547 +       uint8   ether_dhost[6];
    16548 +       uint8   ether_shost[6];
    16549 +       uint16  ether_type;
    16550 +} __attribute__((packed));
    16551 +
    16552 +
    16553 +struct ethervlan_header {
    16554 +       uint8   ether_dhost[6];
    16555 +       uint8   ether_shost[6];
    16556 +       uint16  vlan_type;              /* 0x8100 */
    16557 +       uint16  vlan_tag;               /* priority, cfi and vid */
    16558 +       uint16  ether_type;
    16559 +};
    16560 +
     9887+
     9888+#ifdef BCMDRIVER
    165619889+/* copy a pkt buffer chain into a buffer */
    165629890+uint
    16563 +pktcopy(osl_t *osh, void *p, uint offset, int len, uchar *buf)
     9891+pktcopy(void *drv, void *p, uint offset, int len, uchar *buf)
    165649892+{
    165659893+       uint n, ret = 0;
     
    165699897+
    165709898+       /* skip 'offset' bytes */
    16571 +       for (; p && offset; p = PKTNEXT(osh, p)) {
    16572 +               if (offset < (uint)PKTLEN(osh, p))
     9899+       for (; p && offset; p = PKTNEXT(drv, p)) {
     9900+               if (offset < (uint)PKTLEN(drv, p))
    165739901+                       break;
    16574 +               offset -= PKTLEN(osh, p);
     9902+               offset -= PKTLEN(drv, p);
    165759903+       }
    165769904+
     
    165799907+
    165809908+       /* copy the data */
    16581 +       for (; p && len; p = PKTNEXT(osh, p)) {
    16582 +               n = MIN((uint)PKTLEN(osh, p) - offset, (uint)len);
    16583 +               bcopy(PKTDATA(osh, p) + offset, buf, n);
     9909+       for (; p && len; p = PKTNEXT(drv, p)) {
     9910+               n = MIN((uint)PKTLEN(drv, p) - offset, (uint)len);
     9911+               bcopy(PKTDATA(drv, p) + offset, buf, n);
    165849912+               buf += n;
    165859913+               len -= n;
     
    165939921+/* return total length of buffer chain */
    165949922+uint
    16595 +pkttotlen(osl_t *osh, void *p)
     9923+pkttotlen(void *drv, void *p)
    165969924+{
    165979925+       uint total;
    165989926+
    165999927+       total = 0;
    16600 +       for (; p; p = PKTNEXT(osh, p))
    16601 +               total += PKTLEN(osh, p);
     9928+       for (; p; p = PKTNEXT(drv, p))
     9929+               total += PKTLEN(drv, p);
    166029930+       return (total);
    166039931+}
    166049932+
    16605 +/* return the last buffer of chained pkt */
    16606 +void *
    16607 +pktlast(osl_t *osh, void *p)
    16608 +{
    16609 +       for (; PKTNEXT(osh, p); p = PKTNEXT(osh, p))
    16610 +               ;
     9933+void
     9934+pktq_init(struct pktq *q, uint maxlen, const bool prio_map[])
     9935+{
     9936+       q->head = q->tail = NULL;
     9937+       q->maxlen = maxlen;
     9938+       q->len = 0;
     9939+       if (prio_map) {
     9940+               q->priority = TRUE;
     9941+               bcopy(prio_map, q->prio_map, sizeof(q->prio_map));
     9942+       }
     9943+       else
     9944+               q->priority = FALSE;
     9945+}
     9946+
     9947+/* should always check pktq_full before calling pktenq */
     9948+void
     9949+pktenq(struct pktq *q, void *p, bool lifo)
     9950+{
     9951+       void *next, *prev;
     9952+
     9953+       /* allow 10 pkts slack */
     9954+       ASSERT(q->len < (q->maxlen + 10));
     9955+
     9956+       /* Queueing chains not allowed */
     9957+       ASSERT(PKTLINK(p) == NULL);
     9958+
     9959+       /* Queue is empty */
     9960+       if (q->tail == NULL) {
     9961+               ASSERT(q->head == NULL);
     9962+               q->head = q->tail = p;
     9963+       }
     9964+
     9965+       /* Insert at head or tail */
     9966+       else if (q->priority == FALSE) {
     9967+               /* Insert at head (LIFO) */
     9968+               if (lifo) {
     9969+                       PKTSETLINK(p, q->head);
     9970+                       q->head = p;
     9971+               }
     9972+               /* Insert at tail (FIFO) */
     9973+               else {
     9974+                       ASSERT(PKTLINK(q->tail) == NULL);
     9975+                       PKTSETLINK(q->tail, p);
     9976+                       PKTSETLINK(p, NULL);
     9977+                       q->tail = p;
     9978+               }
     9979+       }
     9980+
     9981+       /* Insert by priority */
     9982+       else {
     9983+               /* legal priorities 0-7 */
     9984+               ASSERT(PKTPRIO(p) <= MAXPRIO);
     9985+
     9986+               ASSERT(q->head);
     9987+               ASSERT(q->tail);
     9988+               /* Shortcut to insertion at tail */
     9989+               if (_pktq_pri(q, PKTPRIO(p)) < _pktq_pri(q, PKTPRIO(q->tail)) ||
     9990+                   (!lifo && _pktq_pri(q, PKTPRIO(p)) <= _pktq_pri(q, PKTPRIO(q->tail)))) {
     9991+                       prev = q->tail;
     9992+                       next = NULL;
     9993+               }
     9994+               /* Insert at head or in the middle */
     9995+               else {
     9996+                       prev = NULL;
     9997+                       next = q->head;
     9998+               }
     9999+               /* Walk the queue */
     10000+               for (; next; prev = next, next = PKTLINK(next)) {
     10001+                       /* Priority queue invariant */
     10002+                       ASSERT(!prev || _pktq_pri(q, PKTPRIO(prev)) >= _pktq_pri(q, PKTPRIO(next)));
     10003+                       /* Insert at head of string of packets of same priority (LIFO) */
     10004+                       if (lifo) {
     10005+                               if (_pktq_pri(q, PKTPRIO(p)) >= _pktq_pri(q, PKTPRIO(next)))
     10006+                                       break;
     10007+                       }
     10008+                       /* Insert at tail of string of packets of same priority (FIFO) */
     10009+                       else {
     10010+                               if (_pktq_pri(q, PKTPRIO(p)) > _pktq_pri(q, PKTPRIO(next)))
     10011+                                       break;
     10012+                       }
     10013+               }
     10014+               /* Insert at tail */
     10015+               if (next == NULL) {
     10016+                       ASSERT(PKTLINK(q->tail) == NULL);
     10017+                       PKTSETLINK(q->tail, p);
     10018+                       PKTSETLINK(p, NULL);
     10019+                       q->tail = p;
     10020+               }
     10021+               /* Insert in the middle */
     10022+               else if (prev) {
     10023+                       PKTSETLINK(prev, p);
     10024+                       PKTSETLINK(p, next);
     10025+               }
     10026+               /* Insert at head */
     10027+               else {
     10028+                       PKTSETLINK(p, q->head);
     10029+                       q->head = p;
     10030+               }
     10031+       }
     10032+
     10033+       /* List invariants after insertion */
     10034+       ASSERT(q->head);
     10035+       ASSERT(PKTLINK(q->tail) == NULL);
     10036+
     10037+       q->len++;
     10038+}
     10039+
     10040+/* dequeue packet at head */
     10041+void*
     10042+pktdeq(struct pktq *q)
     10043+{
     10044+       void *p;
     10045+
     10046+       if ((p = q->head)) {
     10047+               ASSERT(q->tail);
     10048+               q->head = PKTLINK(p);
     10049+               PKTSETLINK(p, NULL);
     10050+               q->len--;
     10051+               if (q->head == NULL)
     10052+                       q->tail = NULL;
     10053+       }
     10054+       else {
     10055+               ASSERT(q->tail == NULL);
     10056+       }
    1661110057+
    1661210058+       return (p);
    1661310059+}
    1661410060+
    16615 +
    16616 +/*
    16617 + * osl multiple-precedence packet queue
    16618 + * hi_prec is always >= the number of the highest non-empty queue
    16619 + */
    16620 +void *
    16621 +pktq_penq(struct pktq *pq, int prec, void *p)
    16622 +{
    16623 +       struct pktq_prec *q;
    16624 +
    16625 +       ASSERT(prec >= 0 && prec < pq->num_prec);
    16626 +       ASSERT(PKTLINK(p) == NULL);         /* queueing chains not allowed */
    16627 +
    16628 +       ASSERT(!pktq_full(pq));
    16629 +       ASSERT(!pktq_pfull(pq, prec));
    16630 +
    16631 +       q = &pq->q[prec];
    16632 +
    16633 +       if (q->head)
    16634 +               PKTSETLINK(q->tail, p);
    16635 +       else
    16636 +               q->head = p;
    16637 +
    16638 +       q->tail = p;
    16639 +       q->len++;
    16640 +
    16641 +       pq->len++;
    16642 +
    16643 +       if (pq->hi_prec < prec)
    16644 +               pq->hi_prec = (uint8)prec;
    16645 +
    16646 +       return p;
    16647 +}
    16648 +
    16649 +void *
    16650 +pktq_penq_head(struct pktq *pq, int prec, void *p)
    16651 +{
    16652 +       struct pktq_prec *q;
    16653 +
    16654 +       ASSERT(prec >= 0 && prec < pq->num_prec);
    16655 +       ASSERT(PKTLINK(p) == NULL);         /* queueing chains not allowed */
    16656 +
    16657 +       ASSERT(!pktq_full(pq));
    16658 +       ASSERT(!pktq_pfull(pq, prec));
    16659 +
    16660 +       q = &pq->q[prec];
    16661 +
    16662 +       if (q->head == NULL)
    16663 +               q->tail = p;
    16664 +
    16665 +       PKTSETLINK(p, q->head);
    16666 +       q->head = p;
    16667 +       q->len++;
    16668 +
    16669 +       pq->len++;
    16670 +
    16671 +       if (pq->hi_prec < prec)
    16672 +               pq->hi_prec = (uint8)prec;
    16673 +
    16674 +       return p;
    16675 +}
    16676 +
    16677 +void *
    16678 +pktq_pdeq(struct pktq *pq, int prec)
    16679 +{
    16680 +       struct pktq_prec *q;
     10061+/* dequeue packet at tail */
     10062+void*
     10063+pktdeqtail(struct pktq *q)
     10064+{
    1668110065+       void *p;
    16682 +
    16683 +       ASSERT(prec >= 0 && prec < pq->num_prec);
    16684 +
    16685 +       q = &pq->q[prec];
    16686 +
    16687 +       if ((p = q->head) == NULL)
    16688 +               return NULL;
    16689 +
    16690 +       if ((q->head = PKTLINK(p)) == NULL)
    16691 +               q->tail = NULL;
    16692 +
    16693 +       q->len--;
    16694 +
    16695 +       pq->len--;
    16696 +
    16697 +       PKTSETLINK(p, NULL);
    16698 +
    16699 +       return p;
    16700 +}
    16701 +
    16702 +void *
    16703 +pktq_pdeq_tail(struct pktq *pq, int prec)
    16704 +{
    16705 +       struct pktq_prec *q;
    16706 +       void *p, *prev;
    16707 +
    16708 +       ASSERT(prec >= 0 && prec < pq->num_prec);
    16709 +
    16710 +       q = &pq->q[prec];
    16711 +
    16712 +       if ((p = q->head) == NULL)
    16713 +               return NULL;
    16714 +
    16715 +       for (prev = NULL; p != q->tail; p = PKTLINK(p))
    16716 +               prev = p;
    16717 +
    16718 +       if (prev)
    16719 +               PKTSETLINK(prev, NULL);
    16720 +       else
    16721 +               q->head = NULL;
    16722 +
     10066+       void *next, *prev;
     10067+
     10068+       if (q->head == q->tail) {  /* last packet on queue or queue empty */
     10069+               p = q->head;
     10070+               q->head = q->tail = NULL;
     10071+               q->len = 0;
     10072+               return(p);
     10073+       }
     10074+
     10075+       /* start walk at head */
     10076+       prev = NULL;
     10077+       next = q->head;
     10078+
     10079+       /* Walk the queue to find prev of q->tail */
     10080+       for (; next; prev = next, next = PKTLINK(next)) {
     10081+               if (next == q->tail)
     10082+                       break;
     10083+       }
     10084+
     10085+       ASSERT(prev);
     10086+
     10087+       PKTSETLINK(prev, NULL);
    1672310088+       q->tail = prev;
    1672410089+       q->len--;
    16725 +
    16726 +       pq->len--;
    16727 +
    16728 +       return p;
    16729 +}
    16730 +
    16731 +void
    16732 +pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir)
    16733 +{
    16734 +       struct pktq_prec *q;
    16735 +       void *p;
    16736 +
    16737 +       q = &pq->q[prec];
    16738 +       p = q->head;
    16739 +       while (p) {
    16740 +               q->head = PKTLINK(p);
    16741 +               PKTSETLINK(p, NULL);
    16742 +               PKTFREE(osh, p, dir);
    16743 +               q->len--;
    16744 +               pq->len--;
    16745 +               p = q->head;
    16746 +       }
    16747 +       ASSERT(q->len == 0);
    16748 +       q->tail = NULL;
    16749 +}
    16750 +
    16751 +bool
    16752 +pktq_pdel(struct pktq *pq, void *pktbuf, int prec)
    16753 +{
    16754 +       struct pktq_prec *q;
    16755 +       void *p;
    16756 +
    16757 +       ASSERT(prec >= 0 && prec < pq->num_prec);
    16758 +
    16759 +       if (!pktbuf)
    16760 +               return FALSE;
    16761 +
    16762 +       q = &pq->q[prec];
    16763 +
    16764 +       if (q->head == pktbuf) {
    16765 +               if ((q->head = PKTLINK(pktbuf)) == NULL)
    16766 +                       q->tail = NULL;
    16767 +       } else {
    16768 +               for (p = q->head; p && PKTLINK(p) != pktbuf; p = PKTLINK(p))
    16769 +                       ;
    16770 +               if (p == NULL)
    16771 +                       return FALSE;
    16772 +
    16773 +               PKTSETLINK(p, PKTLINK(pktbuf));
    16774 +               if (q->tail == pktbuf)
    16775 +                       q->tail = p;
    16776 +       }
    16777 +
    16778 +       q->len--;
    16779 +       pq->len--;
    16780 +       PKTSETLINK(pktbuf, NULL);
    16781 +       return TRUE;
    16782 +}
    16783 +
    16784 +void
    16785 +pktq_init(struct pktq *pq, int num_prec, int max_len)
    16786 +{
    16787 +       int prec;
    16788 +
    16789 +       ASSERT(num_prec > 0 && num_prec <= PKTQ_MAX_PREC);
    16790 +
    16791 +       bzero(pq, sizeof(*pq));
    16792 +
    16793 +       pq->num_prec = (uint16)num_prec;
    16794 +
    16795 +       pq->max = (uint16)max_len;
    16796 +
    16797 +       for (prec = 0; prec < num_prec; prec++)
    16798 +               pq->q[prec].max = pq->max;
    16799 +}
    16800 +
    16801 +void *
    16802 +pktq_deq(struct pktq *pq, int *prec_out)
    16803 +{
    16804 +       struct pktq_prec *q;
    16805 +       void *p;
    16806 +       int prec;
    16807 +
    16808 +       if (pq->len == 0)
    16809 +               return NULL;
    16810 +
    16811 +       while ((prec = pq->hi_prec) > 0 && pq->q[prec].head == NULL)
    16812 +               pq->hi_prec--;
    16813 +
    16814 +       q = &pq->q[prec];
    16815 +
    16816 +       if ((p = q->head) == NULL)
    16817 +               return NULL;
    16818 +
    16819 +       if ((q->head = PKTLINK(p)) == NULL)
    16820 +               q->tail = NULL;
    16821 +
    16822 +       q->len--;
    16823 +
    16824 +       pq->len--;
    16825 +
    16826 +       if (prec_out)
    16827 +               *prec_out = prec;
    16828 +
    16829 +       PKTSETLINK(p, NULL);
    16830 +
    16831 +       return p;
    16832 +}
    16833 +
    16834 +void *
    16835 +pktq_deq_tail(struct pktq *pq, int *prec_out)
    16836 +{
    16837 +       struct pktq_prec *q;
    16838 +       void *p, *prev;
    16839 +       int prec;
    16840 +
    16841 +       if (pq->len == 0)
    16842 +               return NULL;
    16843 +
    16844 +       for (prec = 0; prec < pq->hi_prec; prec++)
    16845 +               if (pq->q[prec].head)
    16846 +                       break;
    16847 +
    16848 +       q = &pq->q[prec];
    16849 +
    16850 +       if ((p = q->head) == NULL)
    16851 +               return NULL;
    16852 +
    16853 +       for (prev = NULL; p != q->tail; p = PKTLINK(p))
    16854 +               prev = p;
    16855 +
    16856 +       if (prev)
    16857 +               PKTSETLINK(prev, NULL);
    16858 +       else
    16859 +               q->head = NULL;
    16860 +
    16861 +       q->tail = prev;
    16862 +       q->len--;
    16863 +
    16864 +       pq->len--;
    16865 +
    16866 +       if (prec_out)
    16867 +               *prec_out = prec;
    16868 +
    16869 +       PKTSETLINK(p, NULL);
    16870 +
    16871 +       return p;
    16872 +}
    16873 +
    16874 +void *
    16875 +pktq_peek(struct pktq *pq, int *prec_out)
    16876 +{
    16877 +       int prec;
    16878 +
    16879 +       if (pq->len == 0)
    16880 +               return NULL;
    16881 +
    16882 +       while ((prec = pq->hi_prec) > 0 && pq->q[prec].head == NULL)
    16883 +               pq->hi_prec--;
    16884 +
    16885 +       if (prec_out)
    16886 +               *prec_out = prec;
    16887 +
    16888 +       return (pq->q[prec].head);
    16889 +}
    16890 +
    16891 +void *
    16892 +pktq_peek_tail(struct pktq *pq, int *prec_out)
    16893 +{
    16894 +       int prec;
    16895 +
    16896 +       if (pq->len == 0)
    16897 +               return NULL;
    16898 +
    16899 +       for (prec = 0; prec < pq->hi_prec; prec++)
    16900 +               if (pq->q[prec].head)
    16901 +                       break;
    16902 +
    16903 +       if (prec_out)
    16904 +               *prec_out = prec;
    16905 +
    16906 +       return (pq->q[prec].tail);
    16907 +}
    16908 +
    16909 +void
    16910 +pktq_flush(osl_t *osh, struct pktq *pq, bool dir)
    16911 +{
    16912 +       int prec;
    16913 +       for (prec = 0; prec < pq->num_prec; prec++)
    16914 +               pktq_pflush(osh, pq, prec, dir);
    16915 +       ASSERT(pq->len == 0);
    16916 +}
    16917 +
    16918 +/* Return sum of lengths of a specific set of precedences */
    16919 +int
    16920 +pktq_mlen(struct pktq *pq, uint prec_bmp)
    16921 +{
    16922 +       int prec, len;
    16923 +
    16924 +       len = 0;
    16925 +
    16926 +       for (prec = 0; prec <= pq->hi_prec; prec++)
    16927 +               if (prec_bmp & (1 << prec))
    16928 +                       len += pq->q[prec].len;
    16929 +
    16930 +       return len;
    16931 +}
    16932 +
    16933 +/* Priority dequeue from a specific set of precedences */
    16934 +void *
    16935 +pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out)
    16936 +{
    16937 +       struct pktq_prec *q;
    16938 +       void *p;
    16939 +       int prec;
    16940 +
    16941 +       if (pq->len == 0)
    16942 +               return NULL;
    16943 +
    16944 +       while ((prec = pq->hi_prec) > 0 && pq->q[prec].head == NULL)
    16945 +               pq->hi_prec--;
    16946 +
    16947 +       while ((prec_bmp & (1 << prec)) == 0 || pq->q[prec].head == NULL)
    16948 +               if (prec-- == 0)
    16949 +                       return NULL;
    16950 +
    16951 +       q = &pq->q[prec];
    16952 +
    16953 +       if ((p = q->head) == NULL)
    16954 +               return NULL;
    16955 +
    16956 +       if ((q->head = PKTLINK(p)) == NULL)
    16957 +               q->tail = NULL;
    16958 +
    16959 +       q->len--;
    16960 +
    16961 +       if (prec_out)
    16962 +               *prec_out = prec;
    16963 +
    16964 +       pq->len--;
    16965 +
    16966 +       PKTSETLINK(p, NULL);
    16967 +
    16968 +       return p;
     10090+       p = next;
     10091+
     10092+       return (p);
     10093+}
     10094+
     10095+unsigned char bcm_ctype[] = {
     10096+       _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,                        /* 0-7 */
     10097+       _BCM_C,_BCM_C|_BCM_S,_BCM_C|_BCM_S,_BCM_C|_BCM_S,_BCM_C|_BCM_S,_BCM_C|_BCM_S,_BCM_C,_BCM_C,             /* 8-15 */
     10098+       _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,                        /* 16-23 */
     10099+       _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,                        /* 24-31 */
     10100+       _BCM_S|_BCM_SP,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,                        /* 32-39 */
     10101+       _BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,                        /* 40-47 */
     10102+       _BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,                        /* 48-55 */
     10103+       _BCM_D,_BCM_D,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,                        /* 56-63 */
     10104+       _BCM_P,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U,      /* 64-71 */
     10105+       _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,                        /* 72-79 */
     10106+       _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,                        /* 80-87 */
     10107+       _BCM_U,_BCM_U,_BCM_U,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,                        /* 88-95 */
     10108+       _BCM_P,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L,      /* 96-103 */
     10109+       _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,                        /* 104-111 */
     10110+       _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,                        /* 112-119 */
     10111+       _BCM_L,_BCM_L,_BCM_L,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_C,                        /* 120-127 */
     10112+       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 128-143 */
     10113+       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 144-159 */
     10114+       _BCM_S|_BCM_SP,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,   /* 160-175 */
     10115+       _BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,       /* 176-191 */
     10116+       _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,       /* 192-207 */
     10117+       _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_P,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_L,       /* 208-223 */
     10118+       _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,       /* 224-239 */
     10119+       _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_P,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L        /* 240-255 */
     10120+};
     10121+
     10122+uchar
     10123+bcm_toupper(uchar c)
     10124+{
     10125+       if (bcm_islower(c))
     10126+               c -= 'a'-'A';
     10127+       return (c);
     10128+}
     10129+
     10130+ulong
     10131+bcm_strtoul(char *cp, char **endp, uint base)
     10132+{
     10133+       ulong result, value;
     10134+       bool minus;
     10135+       
     10136+       minus = FALSE;
     10137+
     10138+       while (bcm_isspace(*cp))
     10139+               cp++;
     10140+       
     10141+       if (cp[0] == '+')
     10142+               cp++;
     10143+       else if (cp[0] == '-') {
     10144+               minus = TRUE;
     10145+               cp++;
     10146+       }
     10147+       
     10148+       if (base == 0) {
     10149+               if (cp[0] == '0') {
     10150+                       if ((cp[1] == 'x') || (cp[1] == 'X')) {
     10151+                               base = 16;
     10152+                               cp = &cp[2];
     10153+                       } else {
     10154+                               base = 8;
     10155+                               cp = &cp[1];
     10156+                       }
     10157+               } else
     10158+                       base = 10;
     10159+       } else if (base == 16 && (cp[0] == '0') && ((cp[1] == 'x') || (cp[1] == 'X'))) {
     10160+               cp = &cp[2];
     10161+       }
     10162+                 
     10163+       result = 0;
     10164+
     10165+       while (bcm_isxdigit(*cp) &&
     10166+              (value = bcm_isdigit(*cp) ? *cp-'0' : bcm_toupper(*cp)-'A'+10) < base) {
     10167+               result = result*base + value;
     10168+               cp++;
     10169+       }
     10170+
     10171+       if (minus)
     10172+               result = (ulong)(result * -1);
     10173+
     10174+       if (endp)
     10175+               *endp = (char *)cp;
     10176+
     10177+       return (result);
     10178+}
     10179+
     10180+uint
     10181+bcm_atoi(char *s)
     10182+{
     10183+       uint n;
     10184+
     10185+       n = 0;
     10186+
     10187+       while (bcm_isdigit(*s))
     10188+               n = (n * 10) + *s++ - '0';
     10189+       return (n);
     10190+}
     10191+
     10192+/* return pointer to location of substring 'needle' in 'haystack' */
     10193+char*
     10194+bcmstrstr(char *haystack, char *needle)
     10195+{
     10196+       int len, nlen;
     10197+       int i;
     10198+
     10199+       if ((haystack == NULL) || (needle == NULL))
     10200+               return (haystack);
     10201+
     10202+       nlen = strlen(needle);
     10203+       len = strlen(haystack) - nlen + 1;
     10204+
     10205+       for (i = 0; i < len; i++)
     10206+               if (bcmp(needle, &haystack[i], nlen) == 0)
     10207+                       return (&haystack[i]);
     10208+       return (NULL);
    1696910209+}
    1697010210+
     
    1697610216+}
    1697710217+
     10218+#if defined(CONFIG_USBRNDIS_RETAIL) || defined(NDIS_MINIPORT_DRIVER)
     10219+/* registry routine buffer preparation utility functions:
     10220+ * parameter order is like strncpy, but returns count
     10221+ * of bytes copied. Minimum bytes copied is null char(1)/wchar(2)
     10222+ */
     10223+ulong
     10224+wchar2ascii(
     10225+       char *abuf,
     10226+       ushort *wbuf,
     10227+       ushort wbuflen,
     10228+       ulong abuflen
     10229+)
     10230+{
     10231+       ulong copyct = 1;
     10232+       ushort i;
     10233+
     10234+       if (abuflen == 0)
     10235+               return 0;
     10236+
     10237+       /* wbuflen is in bytes */
     10238+       wbuflen /= sizeof(ushort);
     10239+
     10240+       for (i = 0; i < wbuflen; ++i) {
     10241+               if (--abuflen == 0)
     10242+                       break;
     10243+               *abuf++ = (char) *wbuf++;
     10244+               ++copyct;
     10245+       }
     10246+       *abuf = '\0';
     10247+
     10248+       return copyct;
     10249+}
     10250+#endif
     10251+
    1697810252+char*
    16979 +bcm_ether_ntoa(struct ether_addr *ea, char *buf)
    16980 +{
    16981 +       sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
    16982 +               ea->octet[0]&0xff, ea->octet[1]&0xff, ea->octet[2]&0xff,
    16983 +               ea->octet[3]&0xff, ea->octet[4]&0xff, ea->octet[5]&0xff);
     10253+bcm_ether_ntoa(char *ea, char *buf)
     10254+{
     10255+       sprintf(buf,"%02x:%02x:%02x:%02x:%02x:%02x",
     10256+               (uchar)ea[0]&0xff, (uchar)ea[1]&0xff, (uchar)ea[2]&0xff,
     10257+               (uchar)ea[3]&0xff, (uchar)ea[4]&0xff, (uchar)ea[5]&0xff);
    1698410258+       return (buf);
    1698510259+}
     
    1698710261+/* parse a xx:xx:xx:xx:xx:xx format ethernet address */
    1698810262+int
    16989 +bcm_ether_atoe(char *p, struct ether_addr *ea)
     10263+bcm_ether_atoe(char *p, char *ea)
    1699010264+{
    1699110265+       int i = 0;
    1699210266+
    1699310267+       for (;;) {
    16994 +               ea->octet[i++] = (char) bcm_strtoul(p, &p, 16);
     10268+               ea[i++] = (char) bcm_strtoul(p, &p, 16);
    1699510269+               if (!*p++ || i == 6)
    1699610270+                       break;
     
    1700010274+}
    1700110275+
    17002 +/* Takes an Ethernet frame and sets out-of-bound PKTPRIO
    17003 + * Also updates the inplace vlan tag if requested
     10276+void
     10277+bcm_mdelay(uint ms)
     10278+{
     10279+       uint i;
     10280+
     10281+       for (i = 0; i < ms; i++) {
     10282+               OSL_DELAY(1000);
     10283+       }
     10284+}
     10285+
     10286+/*
     10287+ * Search the name=value vars for a specific one and return its value.
     10288+ * Returns NULL if not found.
    1700410289+ */
    17005 +void
    17006 +pktsetprio(void *pkt, bool update_vtag)
    17007 +{
    17008 +       struct ether_header *eh;
    17009 +       struct ethervlan_header *evh;
    17010 +       uint8 *pktdata;
    17011 +       int priority = 0;
    17012 +
    17013 +       pktdata = (uint8 *) PKTDATA(NULL, pkt);
    17014 +       ASSERT(ISALIGNED((uintptr)pktdata, sizeof(uint16)));
    17015 +
    17016 +       eh = (struct ether_header *) pktdata;
    17017 +
    17018 +       if (ntoh16(eh->ether_type) == ETHER_TYPE_8021Q) {
    17019 +               uint16 vlan_tag;
    17020 +               int vlan_prio, dscp_prio = 0;
    17021 +
    17022 +               evh = (struct ethervlan_header *)eh;
    17023 +
    17024 +               vlan_tag = ntoh16(evh->vlan_tag);
    17025 +               vlan_prio = (int) (vlan_tag >> VLAN_PRI_SHIFT) & VLAN_PRI_MASK;
    17026 +
    17027 +               if (ntoh16(evh->ether_type) == ETHER_TYPE_IP) {
    17028 +                       uint8 *ip_body = pktdata + sizeof(struct ethervlan_header);
    17029 +                       uint8 tos_tc = IP_TOS(ip_body);
    17030 +                       dscp_prio = (int)(tos_tc >> IPV4_TOS_PREC_SHIFT);
    17031 +               }
    17032 +
    17033 +               /* DSCP priority gets precedence over 802.1P (vlan tag) */
    17034 +               priority = (dscp_prio != 0) ? dscp_prio : vlan_prio;
    17035 +
    17036 +               /*
    17037 +                * If the DSCP priority is not the same as the VLAN priority,
    17038 +                * then overwrite the priority field in the vlan tag, with the
    17039 +                * DSCP priority value. This is required for Linux APs because
    17040 +                * the VLAN driver on Linux, overwrites the skb->priority field
    17041 +                * with the priority value in the vlan tag
    17042 +                */
    17043 +               if (update_vtag && (priority != vlan_prio)) {
    17044 +                       vlan_tag &= ~(VLAN_PRI_MASK << VLAN_PRI_SHIFT);
    17045 +                       vlan_tag |= (uint16)priority << VLAN_PRI_SHIFT;
    17046 +                       evh->vlan_tag = hton16(vlan_tag);
    17047 +               }
    17048 +       } else if (ntoh16(eh->ether_type) == ETHER_TYPE_IP) {
    17049 +               uint8 *ip_body = pktdata + sizeof(struct ether_header);
    17050 +               uint8 tos_tc = IP_TOS(ip_body);
    17051 +               priority = (int)(tos_tc >> IPV4_TOS_PREC_SHIFT);
    17052 +       }
    17053 +
    17054 +       ASSERT(priority >= 0 && priority <= MAXPRIO);
    17055 +       PKTSETPRIO(pkt, priority);
    17056 +}
    17057 +
    17058 +static char bcm_undeferrstr[BCME_STRLEN];
    17059 +
    17060 +static const char *bcmerrorstrtable[] = BCMERRSTRINGTABLE;
    17061 +
    17062 +/* Convert the Error codes into related Error strings  */
    17063 +const char *
    17064 +bcmerrorstr(int bcmerror)
    17065 +{
    17066 +       int abs_bcmerror;
    17067 +
    17068 +       abs_bcmerror = ABS(bcmerror);
    17069 +
    17070 +       /* check if someone added a bcmerror code but forgot to add errorstring */
    17071 +       ASSERT(ABS(BCME_LAST) == (ARRAYSIZE(bcmerrorstrtable) - 1));
    17072 +       if ((bcmerror > 0) || (abs_bcmerror > ABS(BCME_LAST))) {
    17073 +               sprintf(bcm_undeferrstr, "undefined Error %d", bcmerror);
    17074 +               return bcm_undeferrstr;
    17075 +       }
    17076 +
    17077 +       ASSERT((strlen((char*)bcmerrorstrtable[abs_bcmerror])) < BCME_STRLEN);
    17078 +
    17079 +       return bcmerrorstrtable[abs_bcmerror];
    17080 +}
    17081 +
    17082 +
     10290+char*
     10291+getvar(char *vars, char *name)
     10292+{
     10293+       char *s;
     10294+       int len;
     10295+
     10296+       len = strlen(name);
     10297+
     10298+       /* first look in vars[] */
     10299+       for (s = vars; s && *s; ) {
     10300+               if ((bcmp(s, name, len) == 0) && (s[len] == '='))
     10301+                       return (&s[len+1]);
     10302+
     10303+               while (*s++)
     10304+                       ;
     10305+       }
     10306+
     10307+       /* then query nvram */
     10308+       return (BCMINIT(nvram_get)(name));
     10309+}
     10310+
     10311+/*
     10312+ * Search the vars for a specific one and return its value as
     10313+ * an integer. Returns 0 if not found.
     10314+ */
    1708310315+int
    17084 +bcm_iovar_lencheck(const bcm_iovar_t *vi, void *arg, int len, bool set)
    17085 +{
    17086 +       int bcmerror = 0;
    17087 +
    17088 +       /* length check on io buf */
    17089 +       switch (vi->type) {
    17090 +       case IOVT_BOOL:
    17091 +       case IOVT_INT8:
    17092 +       case IOVT_INT16:
    17093 +       case IOVT_INT32:
    17094 +       case IOVT_UINT8:
    17095 +       case IOVT_UINT16:
    17096 +       case IOVT_UINT32:
    17097 +               /* all integers are int32 sized args at the ioctl interface */
    17098 +               if (len < (int)sizeof(int)) {
    17099 +                       bcmerror = BCME_BUFTOOSHORT;
    17100 +               }
    17101 +               break;
    17102 +
    17103 +       case IOVT_BUFFER:
    17104 +               /* buffer must meet minimum length requirement */
    17105 +               if (len < vi->minlen) {
    17106 +                       bcmerror = BCME_BUFTOOSHORT;
    17107 +               }
    17108 +               break;
    17109 +
    17110 +       case IOVT_VOID:
    17111 +               if (!set) {
    17112 +                       /* Cannot return nil... */
    17113 +                       bcmerror = BCME_UNSUPPORTED;
    17114 +               } else if (len) {
    17115 +                       /* Set is an action w/o parameters */
    17116 +                       bcmerror = BCME_BUFTOOLONG;
    17117 +               }
    17118 +               break;
    17119 +
    17120 +       default:
    17121 +               /* unknown type for length check in iovar info */
    17122 +               ASSERT(0);
    17123 +               bcmerror = BCME_UNSUPPORTED;
    17124 +       }
    17125 +
    17126 +       return bcmerror;
    17127 +}
     10316+getintvar(char *vars, char *name)
     10317+{
     10318+       char *val;
     10319+
     10320+       if ((val = getvar(vars, name)) == NULL)
     10321+               return (0);
     10322+
     10323+       return (bcm_strtoul(val, NULL, 0));
     10324+}
     10325+
     10326+/* Return gpio pin number assigned to the named pin */
     10327+/*
     10328+* Variable should be in format:
     10329+*
     10330+*      gpio<N>=pin_name
     10331+*
     10332+* 'def_pin' is returned if there is no such variable found.
     10333+*/
     10334+uint
     10335+getgpiopin(char *vars, char *pin_name, uint def_pin)
     10336+{
     10337+       char name[] = "gpioXXXX";
     10338+       char *val;
     10339+       uint pin;
     10340+
     10341+       /* Go thru all possibilities till a match in pin name */
     10342+       for (pin = 0; pin < GPIO_NUMPINS; pin ++) {
     10343+               sprintf(name, "gpio%d", pin);
     10344+               val = getvar(vars, name);
     10345+               if (val && !strcmp(val, pin_name))
     10346+                       return pin;
     10347+       }
     10348+       return def_pin;
     10349+}
     10350+
     10351+#endif /* #ifdef BCMDRIVER */
     10352+
     10353+/*******************************************************************************
     10354+ * crc8
     10355+ *
     10356+ * Computes a crc8 over the input data using the polynomial:
     10357+ *
     10358+ *       x^8 + x^7 +x^6 + x^4 + x^2 + 1
     10359+ *
     10360+ * The caller provides the initial value (either CRC8_INIT_VALUE
     10361+ * or the previous returned value) to allow for processing of
     10362+ * discontiguous blocks of data.  When generating the CRC the
     10363+ * caller is responsible for complementing the final return value
     10364+ * and inserting it into the byte stream.  When checking, a final
     10365+ * return value of CRC8_GOOD_VALUE indicates a valid CRC.
     10366+ *
     10367+ * Reference: Dallas Semiconductor Application Note 27
     10368+ *   Williams, Ross N., "A Painless Guide to CRC Error Detection Algorithms",
     10369+ *     ver 3, Aug 1993, ross@guest.adelaide.edu.au, Rocksoft Pty Ltd.,
     10370+ *     ftp://ftp.rocksoft.com/clients/rocksoft/papers/crc_v3.txt
     10371+ *
     10372+ ******************************************************************************/
     10373+
     10374+static uint8 crc8_table[256] = {
     10375+    0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
     10376+    0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
     10377+    0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
     10378+    0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
     10379+    0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
     10380+    0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
     10381+    0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
     10382+    0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
     10383+    0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
     10384+    0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
     10385+    0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
     10386+    0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
     10387+    0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
     10388+    0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
     10389+    0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
     10390+    0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
     10391+    0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
     10392+    0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
     10393+    0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
     10394+    0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
     10395+    0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
     10396+    0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
     10397+    0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
     10398+    0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
     10399+    0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
     10400+    0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
     10401+    0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
     10402+    0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
     10403+    0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
     10404+    0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
     10405+    0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
     10406+    0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F
     10407+};
    1712810408+
    1712910409+#define CRC_INNER_LOOP(n, c, x) \
    17130 +                   (c) = ((c) >> 8) ^ crc##n##_table[((c) ^ (x)) & 0xff]
     10410+    (c) = ((c) >> 8) ^ crc##n##_table[((c) ^ (x)) & 0xff]
     10411+
     10412+uint8
     10413+hndcrc8(
     10414+       uint8 *pdata,   /* pointer to array of data to process */
     10415+       uint  nbytes,   /* number of input data bytes to process */
     10416+       uint8 crc       /* either CRC8_INIT_VALUE or previous return value */
     10417+)
     10418+{
     10419+       /* hard code the crc loop instead of using CRC_INNER_LOOP macro
     10420+        * to avoid the undefined and unnecessary (uint8 >> 8) operation. */
     10421+       while (nbytes-- > 0)
     10422+               crc = crc8_table[(crc ^ *pdata++) & 0xff];
     10423+
     10424+       return crc;
     10425+}
     10426+
     10427+/*******************************************************************************
     10428+ * crc16
     10429+ *
     10430+ * Computes a crc16 over the input data using the polynomial:
     10431+ *
     10432+ *       x^16 + x^12 +x^5 + 1
     10433+ *
     10434+ * The caller provides the initial value (either CRC16_INIT_VALUE
     10435+ * or the previous returned value) to allow for processing of
     10436+ * discontiguous blocks of data.  When generating the CRC the
     10437+ * caller is responsible for complementing the final return value
     10438+ * and inserting it into the byte stream.  When checking, a final
     10439+ * return value of CRC16_GOOD_VALUE indicates a valid CRC.
     10440+ *
     10441+ * Reference: Dallas Semiconductor Application Note 27
     10442+ *   Williams, Ross N., "A Painless Guide to CRC Error Detection Algorithms",
     10443+ *     ver 3, Aug 1993, ross@guest.adelaide.edu.au, Rocksoft Pty Ltd.,
     10444+ *     ftp://ftp.rocksoft.com/clients/rocksoft/papers/crc_v3.txt
     10445+ *
     10446+ ******************************************************************************/
     10447+
     10448+static uint16 crc16_table[256] = {
     10449+    0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
     10450+    0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
     10451+    0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E,
     10452+    0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876,
     10453+    0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD,
     10454+    0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
     10455+    0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C,
     10456+    0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974,
     10457+    0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB,
     10458+    0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3,
     10459+    0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A,
     10460+    0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
     10461+    0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9,
     10462+    0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
     10463+    0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738,
     10464+    0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70,
     10465+    0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7,
     10466+    0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
     10467+    0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036,
     10468+    0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E,
     10469+    0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5,
     10470+    0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD,
     10471+    0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134,
     10472+    0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
     10473+    0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3,
     10474+    0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB,
     10475+    0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232,
     10476+    0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
     10477+    0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1,
     10478+    0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
     10479+    0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330,
     10480+    0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
     10481+};
     10482+
     10483+uint16
     10484+hndcrc16(
     10485+    uint8 *pdata,  /* pointer to array of data to process */
     10486+    uint nbytes, /* number of input data bytes to process */
     10487+    uint16 crc     /* either CRC16_INIT_VALUE or previous return value */
     10488+)
     10489+{
     10490+    while (nbytes-- > 0)
     10491+        CRC_INNER_LOOP(16, crc, *pdata++);
     10492+    return crc;
     10493+}
    1713110494+
    1713210495+static uint32 crc32_table[256] = {
     
    1720410567+)
    1720510568+{
    17206 +       uint8 *pend;
     10569+    uint8 *pend;
    1720710570+#ifdef __mips__
    17208 +       uint8 tmp[4];
    17209 +       ulong *tptr = (ulong *)tmp;
     10571+    uint8 tmp[4];
     10572+    ulong *tptr = (ulong *)tmp;
    1721010573+
    1721110574+       /* in case the beginning of the buffer isn't aligned */
     
    1721510578+               CRC_INNER_LOOP(32, crc, *pdata++);
    1721610579+
    17217 +       /* handle bulk of data as 32-bit words */
    17218 +       pend = pdata + (nbytes & 0xfffffffc);
    17219 +       while (pdata < pend) {
    17220 +               *tptr = *(ulong *)pdata;
    17221 +               pdata += sizeof(ulong *);
    17222 +               CRC_INNER_LOOP(32, crc, tmp[0]);
    17223 +               CRC_INNER_LOOP(32, crc, tmp[1]);
    17224 +               CRC_INNER_LOOP(32, crc, tmp[2]);
    17225 +               CRC_INNER_LOOP(32, crc, tmp[3]);
    17226 +       }
    17227 +
    17228 +       /* 1-3 bytes at end of buffer */
    17229 +       pend = pdata + (nbytes & 0x03);
    17230 +       while (pdata < pend)
    17231 +               CRC_INNER_LOOP(32, crc, *pdata++);
     10580+    /* handle bulk of data as 32-bit words */
     10581+    pend = pdata + (nbytes & 0xfffffffc);
     10582+    while (pdata < pend) {
     10583+       *tptr = *((ulong *)pdata)++;
     10584+        CRC_INNER_LOOP(32, crc, tmp[0]);
     10585+        CRC_INNER_LOOP(32, crc, tmp[1]);
     10586+        CRC_INNER_LOOP(32, crc, tmp[2]);
     10587+        CRC_INNER_LOOP(32, crc, tmp[3]);
     10588+    }
     10589+
     10590+    /* 1-3 bytes at end of buffer */
     10591+    pend = pdata + (nbytes & 0x03);
     10592+    while (pdata < pend)
     10593+        CRC_INNER_LOOP(32, crc, *pdata++);
    1723210594+#else
    17233 +       pend = pdata + nbytes;
    17234 +       while (pdata < pend)
    17235 +               CRC_INNER_LOOP(32, crc, *pdata++);
    17236 +#endif /* __mips__ */
    17237 +
    17238 +       return crc;
    17239 +}
    17240 +
    17241 +
    17242 +/*
    17243 + * Advance from the current 1-byte tag/1-byte length/variable-length value
     10595+    pend = pdata + nbytes;
     10596+    while (pdata < pend)
     10597+        CRC_INNER_LOOP(32, crc, *pdata++);
     10598+#endif
     10599+       
     10600+    return crc;
     10601+}
     10602+
     10603+#ifdef notdef
     10604+#define CLEN   1499
     10605+#define CBUFSIZ        (CLEN+4)
     10606+#define CNBUFS         5
     10607+
     10608+void testcrc32(void)
     10609+{
     10610+       uint j,k,l;
     10611+       uint8 *buf;
     10612+       uint len[CNBUFS];
     10613+       uint32 crcr;
     10614+       uint32 crc32tv[CNBUFS] =
     10615+               {0xd2cb1faa, 0xd385c8fa, 0xf5b4f3f3, 0x55789e20, 0x00343110};
     10616+
     10617+       ASSERT((buf = MALLOC(CBUFSIZ*CNBUFS)) != NULL);
     10618+
     10619+       /* step through all possible alignments */
     10620+       for (l=0;l<=4;l++) {
     10621+               for (j=0; j<CNBUFS; j++) {
     10622+                       len[j] = CLEN;
     10623+                       for (k=0; k<len[j]; k++)
     10624+                               *(buf + j*CBUFSIZ + (k+l)) = (j+k) & 0xff;
     10625+               }
     10626+
     10627+               for (j=0; j<CNBUFS; j++) {
     10628+                       crcr = crc32(buf + j*CBUFSIZ + l, len[j], CRC32_INIT_VALUE);
     10629+                       ASSERT(crcr == crc32tv[j]);
     10630+               }
     10631+       }
     10632+
     10633+       MFREE(buf, CBUFSIZ*CNBUFS);
     10634+       return;
     10635+}
     10636+#endif
     10637+
     10638+
     10639+/*
     10640+ * Advance from the current 1-byte tag/1-byte length/variable-length value
    1724410641+ * triple, to the next, returning a pointer to the next.
    17245 + * If the current or next TLV is invalid (does not fit in given buffer length),
    17246 + * NULL is returned.
    17247 + * *buflen is not modified if the TLV elt parameter is invalid, or is decremented
    17248 + * by the TLV paramter's length if it is valid.
    1724910642+ */
    1725010643+bcm_tlv_t *
     
    1725410647+
    1725510648+       /* validate current elt */
    17256 +       if (!bcm_valid_tlv(elt, *buflen))
     10649+       if (*buflen < 2) {
    1725710650+               return NULL;
    17258 +
    17259 +       /* advance to next elt */
     10651+       }
     10652+       
    1726010653+       len = elt->len;
    17261 +       elt = (bcm_tlv_t*)(elt->data + len);
    17262 +       *buflen -= (2 + len);
    17263 +
    17264 +       /* validate next elt */
    17265 +       if (!bcm_valid_tlv(elt, *buflen))
    17266 +               return NULL;
    17267 +
     10654+
     10655+       /* validate remaining buflen */
     10656+       if (*buflen >= (2 + len + 2)) {
     10657+               elt = (bcm_tlv_t*)(elt->data + len);
     10658+               *buflen -= (2 + len);
     10659+       } else {
     10660+               elt = NULL;
     10661+       }
     10662+       
    1726810663+       return elt;
    1726910664+}
    1727010665+
    17271 +/*
    17272 + * Traverse a string of 1-byte tag/1-byte length/variable-length value
    17273 + * triples, returning a pointer to the substring whose first element
     10666+/* 
     10667+ * Traverse a string of 1-byte tag/1-byte length/variable-length value 
     10668+ * triples, returning a pointer to the substring whose first element 
    1727410669+ * matches tag
    1727510670+ */
     
    1729410689+               totlen -= (len + 2);
    1729510690+       }
    17296 +
     10691+       
    1729710692+       return NULL;
    1729810693+}
    1729910694+
    17300 +/*
    17301 + * Traverse a string of 1-byte tag/1-byte length/variable-length value
    17302 + * triples, returning a pointer to the substring whose first element
     10695+/* 
     10696+ * Traverse a string of 1-byte tag/1-byte length/variable-length value 
     10697+ * triples, returning a pointer to the substring whose first element 
    1730310698+ * matches tag.  Stop parsing when we see an element whose ID is greater
    17304 + * than the target key.
     10699+ * than the target key. 
    1730510700+ */
    1730610701+bcm_tlv_t *
     
    1731710712+               uint id = elt->id;
    1731810713+               int len = elt->len;
    17319 +
     10714+               
    1732010715+               /* Punt if we start seeing IDs > than target key */
    1732110716+               if (id > key)
    17322 +                       return (NULL);
     10717+                       return(NULL);
    1732310718+
    1732410719+               /* validate remaining totlen */
     
    1733310728+
    1733410729+
    17335 +/* Initialization of bcmstrbuf structure */
    17336 +void
    17337 +bcm_binit(struct bcmstrbuf *b, char *buf, uint size)
    17338 +{
    17339 +       b->origsize = b->size = size;
    17340 +       b->origbuf = b->buf = buf;
    17341 +}
    17342 +
    17343 +/* Buffer sprintf wrapper to guard against buffer overflow */
    17344 +int
    17345 +bcm_bprintf(struct bcmstrbuf *b, const char *fmt, ...)
    17346 +{
    17347 +       va_list ap;
    17348 +       int r;
    17349 +
    17350 +       va_start(ap, fmt);
    17351 +       r = vsnprintf(b->buf, b->size, fmt, ap);
    17352 +
    17353 +       /* Non Ansi C99 compliant returns -1,
    17354 +        * Ansi compliant return r >= b->size,
    17355 +        * bcmstdlib returns 0, handle all
    17356 +        */
    17357 +       if ((r == -1) || (r >= (int)b->size) || (r == 0))
    17358 +       {
    17359 +               b->size = 0;
    17360 +       }
    17361 +       else
    17362 +       {
    17363 +               b->size -= r;
    17364 +               b->buf += r;
    17365 +       }
    17366 +
    17367 +       va_end(ap);
    17368 +
    17369 +       return r;
    17370 +}
    17371 diff -urN linux.old/drivers/net/wl/hnddma.c linux.dev/drivers/net/wl/hnddma.c
    17372 --- linux.old/drivers/net/wl/hnddma.c   1970-01-01 01:00:00.000000000 +0100
    17373 +++ linux.dev/drivers/net/wl/hnddma.c   2006-05-02 17:42:13.000000000 +0200
    17374 @@ -0,0 +1,1157 @@
     10730diff -Nur linux-2.4.32/drivers/net/hnd/hnddma.c linux-2.4.32-freewrt/drivers/net/hnd/hnddma.c
     10731--- linux-2.4.32/drivers/net/hnd/hnddma.c       1970-01-01 01:00:00.000000000 +0100
     10732+++ linux-2.4.32-freewrt/drivers/net/hnd/hnddma.c       2006-07-02 21:58:25.000000000 +0200
     10733@@ -0,0 +1,865 @@
    1737510734+/*
    1737610735+ * Generic Broadcom Home Networking Division (HND) DMA module.
    1737710736+ * This supports the following chips: BCM42xx, 44xx, 47xx .
    1737810737+ *
    17379 + * Copyright 2006, Broadcom Corporation
     10738+ * Copyright 2004, Broadcom Corporation
    1738010739+ * All Rights Reserved.
    1738110740+ *
     
    1738510744+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    1738610745+ *
    17387 + * $Id: hnddma.c,v 1.11 2006/04/08 07:12:42 honor Exp $
     10746+ * $Id$
    1738810747+ */
    1738910748+
    1739010749+#include <typedefs.h>
    17391 +#include <bcmdefs.h>
    1739210750+#include <osl.h>
    17393 +#include "linux_osl.h"
    1739410751+#include <bcmendian.h>
    1739510752+#include <sbconfig.h>
    1739610753+#include <bcmutils.h>
    17397 +#include <bcmdevs.h>
    17398 +#include <sbutils.h>
    17399 +
    17400 +#include "sbhnddma.h"
    17401 +#include "hnddma.h"
     10754+
     10755+struct dma_info;       /* forward declaration */
     10756+#define di_t struct dma_info
     10757+#include <hnddma.h>
    1740210758+
    1740310759+/* debug/trace */
    17404 +#define        DMA_ERROR(args)
     10760+#define DMA_ERROR(args)
    1740510761+#define        DMA_TRACE(args)
    1740610762+
    17407 +/* default dma message level (if input msg_level pointer is null in dma_attach()) */
    17408 +static uint dma_msg_level =
    17409 +       0;
    17410 +
    17411 +#define        MAXNAMEL        8               /* 8 char names */
    17412 +
    17413 +#define        DI_INFO(dmah)   (dma_info_t *)dmah
     10763+/* default dma message level(if input msg_level pointer is null in dma_attach()) */
     10764+static uint dma_msg_level = 0;
     10765+
     10766+#define        MAXNAMEL        8
     10767+#define        MAXDD           (DMAMAXRINGSZ / sizeof (dmadd_t))
    1741410768+
    1741510769+/* dma engine software state */
    1741610770+typedef struct dma_info {
    17417 +       struct hnddma_pub hnddma;       /* exported structure, don't use hnddma_t,
    17418 +                                        * which could be const
    17419 +                                        */
     10771+       hnddma_t        hnddma;         /* exported structure */
    1742010772+       uint            *msg_level;     /* message level pointer */
     10773+
    1742110774+       char            name[MAXNAMEL]; /* callers name for diag msgs */
    17422 +
     10775+       void            *drv;           /* driver handle */
    1742310776+       void            *osh;           /* os handle */
    17424 +       sb_t            *sbh;           /* sb handle */
    17425 +
    17426 +       bool            dma64;          /* dma64 enabled */
    17427 +       bool            addrext;        /* this dma engine supports DmaExtendedAddrChanges */
    17428 +
    17429 +       dma32regs_t     *d32txregs;     /* 32 bits dma tx engine registers */
    17430 +       dma32regs_t     *d32rxregs;     /* 32 bits dma rx engine registers */
    17431 +       dma64regs_t     *d64txregs;     /* 64 bits dma tx engine registers */
    17432 +       dma64regs_t     *d64rxregs;     /* 64 bits dma rx engine registers */
    17433 +
    17434 +       uint32          dma64align;     /* either 8k or 4k depends on number of dd */
    17435 +       dma32dd_t       *txd32;         /* pointer to dma32 tx descriptor ring */
    17436 +       dma64dd_t       *txd64;         /* pointer to dma64 tx descriptor ring */
    17437 +       uint            ntxd;           /* # tx descriptors tunable */
     10777+       dmaregs_t       *regs;          /* dma engine registers */
     10778+
     10779+       dmadd_t         *txd;           /* pointer to chip-specific tx descriptor ring */
    1743810780+       uint            txin;           /* index of next descriptor to reclaim */
    1743910781+       uint            txout;          /* index of next descriptor to post */
     10782+       uint            txavail;        /* # free tx descriptors */
    1744010783+       void            **txp;          /* pointer to parallel array of pointers to packets */
    17441 +       osldma_t        *tx_dmah;       /* DMA TX descriptor ring handle */
    17442 +       osldma_t        **txp_dmah;     /* DMA TX packet data handle */
    1744310784+       ulong           txdpa;          /* physical address of descriptor ring */
    1744410785+       uint            txdalign;       /* #bytes added to alloc'd mem to align txd */
    1744510786+       uint            txdalloc;       /* #bytes allocated for the ring */
    1744610787+
    17447 +       dma32dd_t       *rxd32;         /* pointer to dma32 rx descriptor ring */
    17448 +       dma64dd_t       *rxd64;         /* pointer to dma64 rx descriptor ring */
    17449 +       uint            nrxd;           /* # rx descriptors tunable */
     10788+       dmadd_t         *rxd;           /* pointer to chip-specific rx descriptor ring */
    1745010789+       uint            rxin;           /* index of next descriptor to reclaim */
    1745110790+       uint            rxout;          /* index of next descriptor to post */
    1745210791+       void            **rxp;          /* pointer to parallel array of pointers to packets */
    17453 +       osldma_t        *rx_dmah;       /* DMA RX descriptor ring handle */
    17454 +       osldma_t        **rxp_dmah;     /* DMA RX packet data handle */
    1745510792+       ulong           rxdpa;          /* physical address of descriptor ring */
    1745610793+       uint            rxdalign;       /* #bytes added to alloc'd mem to align rxd */
     
    1745810795+
    1745910796+       /* tunables */
    17460 +       uint            rxbufsize;      /* rx buffer size in bytes,
    17461 +                                          not including the extra headroom
    17462 +                                       */
     10797+       uint            ntxd;           /* # tx descriptors */
     10798+       uint            nrxd;           /* # rx descriptors */
     10799+       uint            rxbufsize;      /* rx buffer size in bytes */
    1746310800+       uint            nrxpost;        /* # rx buffers to keep posted */
    1746410801+       uint            rxoffset;       /* rxcontrol offset */
    17465 +       uint            ddoffsetlow;    /* add to get dma address of descriptor ring, low 32 bits */
    17466 +       uint            ddoffsethigh;   /*   high 32 bits */
    17467 +       uint            dataoffsetlow;  /* add to get dma address of data buffer, low 32 bits */
    17468 +       uint            dataoffsethigh; /*   high 32 bits */
     10802+       uint            ddoffset;       /* add to get dma address of descriptor ring */
     10803+       uint            dataoffset;     /* add to get dma address of data buffer */
    1746910804+} dma_info_t;
    1747010805+
    1747110806+/* descriptor bumping macros */
    17472 +#define        XXD(x, n)       ((x) & ((n) - 1))       /* faster than %, but n must be power of 2 */
     10807+#define        XXD(x, n)       ((x) & ((n) - 1))
    1747310808+#define        TXD(x)          XXD((x), di->ntxd)
    1747410809+#define        RXD(x)          XXD((x), di->nrxd)
     
    1748010815+
    1748110816+/* macros to convert between byte offsets and indexes */
    17482 +#define        B2I(bytes, type)        ((bytes) / sizeof(type))
    17483 +#define        I2B(index, type)        ((index) * sizeof(type))
    17484 +
    17485 +#define        PCI32ADDR_HIGH          0xc0000000      /* address[31:30] */
    17486 +#define        PCI32ADDR_HIGH_SHIFT    30              /* address[31:30] */
    17487 +
    17488 +
    17489 +/* common prototypes */
    17490 +static bool _dma_isaddrext(dma_info_t *di);
    17491 +static bool dma32_alloc(dma_info_t *di, uint direction);
    17492 +static void _dma_detach(dma_info_t *di);
    17493 +static void _dma_ddtable_init(dma_info_t *di, uint direction, ulong pa);
    17494 +static void _dma_rxinit(dma_info_t *di);
    17495 +static void *_dma_rx(dma_info_t *di);
    17496 +static void _dma_rxfill(dma_info_t *di);
    17497 +static void _dma_rxreclaim(dma_info_t *di);
    17498 +static void _dma_rxenable(dma_info_t *di);
    17499 +static void * _dma_getnextrxp(dma_info_t *di, bool forceall);
    17500 +
    17501 +static void _dma_txblock(dma_info_t *di);
    17502 +static void _dma_txunblock(dma_info_t *di);
    17503 +static uint _dma_txactive(dma_info_t *di);
    17504 +
    17505 +static void* _dma_peeknexttxp(dma_info_t *di);
    17506 +static uintptr _dma_getvar(dma_info_t *di, char *name);
    17507 +static void _dma_counterreset(dma_info_t *di);
    17508 +static void _dma_fifoloopbackenable(dma_info_t *di);
    17509 +
    17510 +/* ** 32 bit DMA prototypes */
    17511 +static bool dma32_alloc(dma_info_t *di, uint direction);
    17512 +static bool dma32_txreset(dma_info_t *di);
    17513 +static bool dma32_rxreset(dma_info_t *di);
    17514 +static bool dma32_txsuspendedidle(dma_info_t *di);
    17515 +static int  dma32_txfast(dma_info_t *di, void *p0, bool commit);
    17516 +static void *dma32_getnexttxp(dma_info_t *di, bool forceall);
    17517 +static void *dma32_getnextrxp(dma_info_t *di, bool forceall);
    17518 +static void dma32_txrotate(dma_info_t *di);
    17519 +static bool dma32_rxidle(dma_info_t *di);
    17520 +static void dma32_txinit(dma_info_t *di);
    17521 +static bool dma32_txenabled(dma_info_t *di);
    17522 +static void dma32_txsuspend(dma_info_t *di);
    17523 +static void dma32_txresume(dma_info_t *di);
    17524 +static bool dma32_txsuspended(dma_info_t *di);
    17525 +static void dma32_txreclaim(dma_info_t *di, bool forceall);
    17526 +static bool dma32_txstopped(dma_info_t *di);
    17527 +static bool dma32_rxstopped(dma_info_t *di);
    17528 +static bool dma32_rxenabled(dma_info_t *di);
    17529 +static bool _dma32_addrext(osl_t *osh, dma32regs_t *dma32regs);
    17530 +
    17531 +
    17532 +static di_fcn_t dma32proc = {
    17533 +       (di_detach_t)_dma_detach,
    17534 +       (di_txinit_t)dma32_txinit,
    17535 +       (di_txreset_t)dma32_txreset,
    17536 +       (di_txenabled_t)dma32_txenabled,
    17537 +       (di_txsuspend_t)dma32_txsuspend,
    17538 +       (di_txresume_t)dma32_txresume,
    17539 +       (di_txsuspended_t)dma32_txsuspended,
    17540 +       (di_txsuspendedidle_t)dma32_txsuspendedidle,
    17541 +       (di_txfast_t)dma32_txfast,
    17542 +       (di_txstopped_t)dma32_txstopped,
    17543 +       (di_txreclaim_t)dma32_txreclaim,
    17544 +       (di_getnexttxp_t)dma32_getnexttxp,
    17545 +       (di_peeknexttxp_t)_dma_peeknexttxp,
    17546 +       (di_txblock_t)_dma_txblock,
    17547 +       (di_txunblock_t)_dma_txunblock,
    17548 +       (di_txactive_t)_dma_txactive,
    17549 +       (di_txrotate_t)dma32_txrotate,
    17550 +
    17551 +       (di_rxinit_t)_dma_rxinit,
    17552 +       (di_rxreset_t)dma32_rxreset,
    17553 +       (di_rxidle_t)dma32_rxidle,
    17554 +       (di_rxstopped_t)dma32_rxstopped,
    17555 +       (di_rxenable_t)_dma_rxenable,
    17556 +       (di_rxenabled_t)dma32_rxenabled,
    17557 +       (di_rx_t)_dma_rx,
    17558 +       (di_rxfill_t)_dma_rxfill,
    17559 +       (di_rxreclaim_t)_dma_rxreclaim,
    17560 +       (di_getnextrxp_t)_dma_getnextrxp,
    17561 +
    17562 +       (di_fifoloopbackenable_t)_dma_fifoloopbackenable,
    17563 +       (di_getvar_t)_dma_getvar,
    17564 +       (di_counterreset_t)_dma_counterreset,
    17565 +
    17566 +       NULL,
    17567 +       NULL,
    17568 +       NULL,
    17569 +       34
    17570 +};
    17571 +
    17572 +hnddma_t *
    17573 +dma_attach(osl_t *osh, char *name, sb_t *sbh, void *dmaregstx, void *dmaregsrx,
    17574 +           uint ntxd, uint nrxd, uint rxbufsize, uint nrxpost, uint rxoffset, uint *msg_level)
     10817+#define        B2I(bytes)      ((bytes) / sizeof (dmadd_t))
     10818+#define        I2B(index)      ((index) * sizeof (dmadd_t))
     10819+
     10820+/*
     10821+ * This assume the largest i/o address is, in fact, the pci big window
     10822+ * and that the pci core sb2pcitranslation2 register has been left with
     10823+ * the default 0x0 pci base address.
     10824+ */
     10825+#define        MAXDMAADDR              SB_PCI_DMA_SZ
     10826+#define        DMA_ADDRESSABLE(x)      !((x) & ~(MAXDMAADDR - 1))
     10827+
     10828+/* prototypes */
     10829+
     10830+void*
     10831+dma_attach(void *drv, void *osh, char *name, dmaregs_t *regs, uint ntxd, uint nrxd,
     10832+       uint rxbufsize, uint nrxpost, uint rxoffset, uint ddoffset, uint dataoffset, uint *msg_level)
    1757510833+{
    1757610834+       dma_info_t *di;
    1757710835+       uint size;
     10836+       void *va;
     10837+
     10838+       ASSERT(ntxd <= MAXDD);
     10839+       ASSERT(ISPOWEROF2(ntxd));
     10840+       ASSERT(nrxd <= MAXDD);
     10841+       ASSERT(ISPOWEROF2(nrxd));
    1757810842+
    1757910843+       /* allocate private info structure */
     
    1758110845+               return (NULL);
    1758210846+       }
    17583 +       bzero((char *)di, sizeof(dma_info_t));
    17584 +
     10847+       bzero((char*)di, sizeof (dma_info_t));
     10848+
     10849+       /* allocate tx packet pointer vector */
     10850+       if (ntxd) {
     10851+               size = ntxd * sizeof (void*);
     10852+               if ((di->txp = MALLOC(osh, size)) == NULL)
     10853+                       goto fail;
     10854+               bzero((char*)di->txp, size);
     10855+       }
     10856+
     10857+       /* allocate rx packet pointer vector */
     10858+       if (nrxd) {
     10859+               size = nrxd * sizeof (void*);
     10860+               if ((di->rxp = MALLOC(osh, size)) == NULL)
     10861+                       goto fail;
     10862+               bzero((char*)di->rxp, size);
     10863+       }
     10864+
     10865+       /* set message level */
    1758510866+       di->msg_level = msg_level ? msg_level : &dma_msg_level;
    1758610867+
    17587 +       /* old chips w/o sb is no longer supported */
    17588 +       ASSERT(sbh != NULL);
    17589 +
    17590 +       /* check arguments */
    17591 +       ASSERT(ISPOWEROF2(ntxd));
    17592 +       ASSERT(ISPOWEROF2(nrxd));
    17593 +       if (nrxd == 0)
    17594 +               ASSERT(dmaregsrx == NULL);
    17595 +       if (ntxd == 0)
    17596 +               ASSERT(dmaregstx == NULL);
    17597 +
    17598 +
    17599 +       /* init dma reg pointer */
    17600 +       ASSERT(ntxd <= D32MAXDD);
    17601 +       ASSERT(nrxd <= D32MAXDD);
    17602 +       di->d32txregs = (dma32regs_t *)dmaregstx;
    17603 +       di->d32rxregs = (dma32regs_t *)dmaregsrx;
    17604 +
    17605 +       DMA_TRACE(("%s: dma_attach: %s osh %p ntxd %d nrxd %d rxbufsize %d nrxpost %d "
    17606 +                  "rxoffset %d dmaregstx %p dmaregsrx %p\n",
    17607 +                  name, "DMA32", osh, ntxd, nrxd, rxbufsize,
    17608 +                  nrxpost, rxoffset, dmaregstx, dmaregsrx));
     10868+       DMA_TRACE(("%s: dma_attach: drv %p osh %p regs %p ntxd %d nrxd %d rxbufsize %d nrxpost %d rxoffset %d ddoffset 0x%x dataoffset 0x%x\n", name, drv, osh, regs, ntxd, nrxd, rxbufsize, nrxpost, rxoffset, ddoffset, dataoffset));
    1760910869+
    1761010870+       /* make a private copy of our callers name */
     
    1761210872+       di->name[MAXNAMEL-1] = '\0';
    1761310873+
     10874+       di->drv = drv;
    1761410875+       di->osh = osh;
    17615 +       di->sbh = sbh;
     10876+       di->regs = regs;
     10877+
     10878+       /* allocate transmit descriptor ring */
     10879+       if (ntxd) {
     10880+               /* only need ntxd descriptors but it must be DMARINGALIGNed */
     10881+               size = ntxd * sizeof (dmadd_t);
     10882+               if (!ISALIGNED(DMA_CONSISTENT_ALIGN, DMARINGALIGN))
     10883+                       size += DMARINGALIGN;
     10884+               if ((va = DMA_ALLOC_CONSISTENT(osh, size, &di->txdpa)) == NULL)
     10885+                       goto fail;
     10886+               di->txd = (dmadd_t*) ROUNDUP((uintptr)va, DMARINGALIGN);
     10887+               di->txdalign = (uint)((int8*)di->txd - (int8*)va);
     10888+               di->txdpa += di->txdalign;
     10889+               di->txdalloc = size;
     10890+               ASSERT(ISALIGNED((uintptr)di->txd, DMARINGALIGN));
     10891+               ASSERT(DMA_ADDRESSABLE(di->txdpa));
     10892+       }
     10893+
     10894+       /* allocate receive descriptor ring */
     10895+       if (nrxd) {
     10896+               /* only need nrxd descriptors but it must be DMARINGALIGNed */
     10897+               size = nrxd * sizeof (dmadd_t);
     10898+               if (!ISALIGNED(DMA_CONSISTENT_ALIGN, DMARINGALIGN))
     10899+                       size += DMARINGALIGN;
     10900+               if ((va = DMA_ALLOC_CONSISTENT(osh, size, &di->rxdpa)) == NULL)
     10901+                       goto fail;
     10902+               di->rxd = (dmadd_t*) ROUNDUP((uintptr)va, DMARINGALIGN);
     10903+               di->rxdalign = (uint)((int8*)di->rxd - (int8*)va);
     10904+               di->rxdpa += di->rxdalign;
     10905+               di->rxdalloc = size;
     10906+               ASSERT(ISALIGNED((uintptr)di->rxd, DMARINGALIGN));
     10907+               ASSERT(DMA_ADDRESSABLE(di->rxdpa));
     10908+       }
    1761610909+
    1761710910+       /* save tunables */
    1761810911+       di->ntxd = ntxd;
    1761910912+       di->nrxd = nrxd;
    17620 +
    17621 +       /* the actual dma size doesn't include the extra headroom */
    17622 +       if (rxbufsize > BCMEXTRAHDROOM)
    17623 +               di->rxbufsize = rxbufsize - BCMEXTRAHDROOM;
    17624 +       else
    17625 +               di->rxbufsize = rxbufsize;
    17626 +
     10913+       di->rxbufsize = rxbufsize;
    1762710914+       di->nrxpost = nrxpost;
    1762810915+       di->rxoffset = rxoffset;
    17629 +
    17630 +       /*
    17631 +        * figure out the DMA physical address offset for dd and data
    17632 +        *   for old chips w/o sb, use zero
    17633 +        *   for new chips w sb,
    17634 +        *     PCI/PCIE: they map silicon backplace address to zero based memory, need offset
    17635 +        *     Other bus: use zero
    17636 +        *     SB_BUS BIGENDIAN kludge: use sdram swapped region for data buffer, not descriptor
    17637 +        */
    17638 +       di->ddoffsetlow = 0;
    17639 +       di->dataoffsetlow = 0;
    17640 +       /* for pci bus, add offset */
    17641 +       if (sbh->bustype == PCI_BUS) {
    17642 +               di->ddoffsetlow = SB_PCI_DMA;
    17643 +               di->ddoffsethigh = 0;
    17644 +               di->dataoffsetlow =  di->ddoffsetlow;
    17645 +               di->dataoffsethigh =  di->ddoffsethigh;
    17646 +       }
    17647 +
    17648 +#if defined(__mips__) && defined(IL_BIGENDIAN)
    17649 +       di->dataoffsetlow = di->dataoffsetlow + SB_SDRAM_SWAPPED;
    17650 +#endif
    17651 +
    17652 +       di->addrext = _dma_isaddrext(di);
    17653 +
    17654 +       /* allocate tx packet pointer vector */
    17655 +       if (ntxd) {
    17656 +               size = ntxd * sizeof(void *);
    17657 +               if ((di->txp = MALLOC(osh, size)) == NULL) {
    17658 +                       DMA_ERROR(("%s: dma_attach: out of tx memory, malloced %d bytes\n",
    17659 +                                  di->name, MALLOCED(osh)));
    17660 +                       goto fail;
    17661 +               }
    17662 +               bzero((char *)di->txp, size);
    17663 +       }
    17664 +
    17665 +       /* allocate rx packet pointer vector */
    17666 +       if (nrxd) {
    17667 +               size = nrxd * sizeof(void *);
    17668 +               if ((di->rxp = MALLOC(osh, size)) == NULL) {
    17669 +                       DMA_ERROR(("%s: dma_attach: out of rx memory, malloced %d bytes\n",
    17670 +                                  di->name, MALLOCED(osh)));
    17671 +                       goto fail;
    17672 +               }
    17673 +               bzero((char *)di->rxp, size);
    17674 +       }
    17675 +
    17676 +       /* allocate transmit descriptor ring, only need ntxd descriptors but it must be aligned */
    17677 +       if (ntxd) {
    17678 +               if (!dma32_alloc(di, DMA_TX))
    17679 +                       goto fail;
    17680 +       }
    17681 +
    17682 +       /* allocate receive descriptor ring, only need nrxd descriptors but it must be aligned */
    17683 +       if (nrxd) {
    17684 +               if (!dma32_alloc(di, DMA_RX))
    17685 +                       goto fail;
    17686 +       }
    17687 +
    17688 +       if ((di->ddoffsetlow == SB_PCI_DMA) && (di->txdpa > SB_PCI_DMA_SZ) && !di->addrext) {
    17689 +               DMA_ERROR(("%s: dma_attach: txdpa 0x%lx: addrext not supported\n",
    17690 +                          di->name, di->txdpa));
    17691 +               goto fail;
    17692 +       }
    17693 +       if ((di->ddoffsetlow == SB_PCI_DMA) && (di->rxdpa > SB_PCI_DMA_SZ) && !di->addrext) {
    17694 +               DMA_ERROR(("%s: dma_attach: rxdpa 0x%lx: addrext not supported\n",
    17695 +                          di->name, di->rxdpa));
    17696 +               goto fail;
    17697 +       }
    17698 +
    17699 +       DMA_TRACE(("ddoffsetlow 0x%x ddoffsethigh 0x%x dataoffsetlow 0x%x dataoffsethigh "
    17700 +                  "0x%x addrext %d\n", di->ddoffsetlow, di->ddoffsethigh, di->dataoffsetlow,
    17701 +                  di->dataoffsethigh, di->addrext));
    17702 +
    17703 +       /* allocate tx packet pointer vector and DMA mapping vectors */
    17704 +       if (ntxd) {
    17705 +
    17706 +               size = ntxd * sizeof(osldma_t **);
    17707 +               if ((di->txp_dmah = (osldma_t **)MALLOC(osh, size)) == NULL)
    17708 +                       goto fail;
    17709 +               bzero((char*)di->txp_dmah, size);
    17710 +       }else
    17711 +               di->txp_dmah = NULL;
    17712 +
    17713 +       /* allocate rx packet pointer vector and DMA mapping vectors */
    17714 +       if (nrxd) {
    17715 +
    17716 +               size = nrxd * sizeof(osldma_t **);
    17717 +               if ((di->rxp_dmah = (osldma_t **)MALLOC(osh, size)) == NULL)
    17718 +                       goto fail;
    17719 +               bzero((char*)di->rxp_dmah, size);
    17720 +
    17721 +       } else
    17722 +               di->rxp_dmah = NULL;
    17723 +
    17724 +       /* initialize opsvec of function pointers */
    17725 +       di->hnddma.di_fn = dma32proc;
    17726 +
    17727 +       return ((hnddma_t *)di);
     10916+       di->ddoffset = ddoffset;
     10917+       di->dataoffset = dataoffset;
     10918+
     10919+       return ((void*)di);
    1772810920+
    1772910921+fail:
    17730 +       _dma_detach(di);
     10922+       dma_detach((void*)di);
    1773110923+       return (NULL);
    1773210924+}
    1773310925+
    17734 +/* init the tx or rx descriptor */
    17735 +static INLINE void
    17736 +dma32_dd_upd(dma_info_t *di, dma32dd_t *ddring, ulong pa, uint outidx, uint32 *flags,
    17737 +             uint32 bufcount)
    17738 +{
    17739 +       /* dma32 uses 32 bits control to fit both flags and bufcounter */
    17740 +       *flags = *flags | (bufcount & CTRL_BC_MASK);
    17741 +
    17742 +       if ((di->dataoffsetlow != SB_PCI_DMA) || !(pa & PCI32ADDR_HIGH)) {
    17743 +               W_SM(&ddring[outidx].addr, BUS_SWAP32(pa + di->dataoffsetlow));
    17744 +               W_SM(&ddring[outidx].ctrl, BUS_SWAP32(*flags));
    17745 +       } else {
    17746 +               /* address extension */
    17747 +               uint32 ae;
    17748 +               ASSERT(di->addrext);
    17749 +               ae = (pa & PCI32ADDR_HIGH) >> PCI32ADDR_HIGH_SHIFT;
    17750 +               pa &= ~PCI32ADDR_HIGH;
    17751 +
    17752 +               *flags |= (ae << CTRL_AE_SHIFT);
    17753 +               W_SM(&ddring[outidx].addr, BUS_SWAP32(pa + di->dataoffsetlow));
    17754 +               W_SM(&ddring[outidx].ctrl, BUS_SWAP32(*flags));
    17755 +       }
    17756 +}
    17757 +
    17758 +static bool
    17759 +_dma32_addrext(osl_t *osh, dma32regs_t *dma32regs)
    17760 +{
    17761 +       uint32 w;
    17762 +
    17763 +       OR_REG(osh, &dma32regs->control, XC_AE);
    17764 +       w = R_REG(osh, &dma32regs->control);
    17765 +       AND_REG(osh, &dma32regs->control, ~XC_AE);
    17766 +       return ((w & XC_AE) == XC_AE);
    17767 +}
    17768 +
    17769 +/* !! may be called with core in reset */
    17770 +static void
    17771 +_dma_detach(dma_info_t *di)
     10926+/* may be called with core in reset */
     10927+void
     10928+dma_detach(dma_info_t *di)
    1777210929+{
    1777310930+       if (di == NULL)
     
    1778110938+
    1778210939+       /* free dma descriptor rings */
    17783 +       if (di->txd32)
    17784 +               DMA_FREE_CONSISTENT(di->osh, ((int8*)di->txd32 - di->txdalign),
    17785 +                                   di->txdalloc, (di->txdpa - di->txdalign), &di->tx_dmah);
    17786 +       if (di->rxd32)
    17787 +               DMA_FREE_CONSISTENT(di->osh, ((int8*)di->rxd32 - di->rxdalign),
    17788 +                                   di->rxdalloc, (di->rxdpa - di->rxdalign), &di->rx_dmah);
     10940+       if (di->txd)
     10941+               DMA_FREE_CONSISTENT(di->osh, ((int8*)di->txd - di->txdalign),
     10942+                       di->txdalloc, (di->txdpa - di->txdalign));
     10943+       if (di->rxd)
     10944+               DMA_FREE_CONSISTENT(di->osh, ((int8*)di->rxd - di->rxdalign),
     10945+                       di->rxdalloc, (di->rxdpa - di->rxdalign));
    1778910946+
    1779010947+       /* free packet pointer vectors */
    1779110948+       if (di->txp)
    17792 +               MFREE(di->osh, (void *)di->txp, (di->ntxd * sizeof(void *)));
     10949+               MFREE(di->osh, (void*)di->txp, (di->ntxd * sizeof (void*)));
    1779310950+       if (di->rxp)
    17794 +               MFREE(di->osh, (void *)di->rxp, (di->nrxd * sizeof(void *)));
    17795 +
    17796 +       /* free tx packet DMA handles */
    17797 +       if (di->txp_dmah)
    17798 +               MFREE(di->osh, (void *)di->txp_dmah, di->ntxd * sizeof(osldma_t **));
    17799 +
    17800 +       /* free rx packet DMA handles */
    17801 +       if (di->rxp_dmah)
    17802 +               MFREE(di->osh, (void *)di->rxp_dmah, di->nrxd * sizeof(osldma_t **));
     10951+               MFREE(di->osh, (void*)di->rxp, (di->nrxd * sizeof (void*)));
    1780310952+
    1780410953+       /* free our private info structure */
    17805 +       MFREE(di->osh, (void *)di, sizeof(dma_info_t));
    17806 +
    17807 +}
    17808 +
    17809 +/* return TRUE if this dma engine supports DmaExtendedAddrChanges, otherwise FALSE */
    17810 +static bool
    17811 +_dma_isaddrext(dma_info_t *di)
    17812 +{
    17813 +       if (di->d32txregs)
    17814 +               return (_dma32_addrext(di->osh, di->d32txregs));
    17815 +       else if (di->d32rxregs)
    17816 +               return (_dma32_addrext(di->osh, di->d32rxregs));
    17817 +       return FALSE;
    17818 +}
    17819 +
    17820 +/* initialize descriptor table base address */
    17821 +static void
    17822 +_dma_ddtable_init(dma_info_t *di, uint direction, ulong pa)
    17823 +{
    17824 +       if ((di->ddoffsetlow != SB_PCI_DMA) || !(pa & PCI32ADDR_HIGH)) {
    17825 +               if (direction == DMA_TX)
    17826 +                       W_REG(di->osh, &di->d32txregs->addr, (pa + di->ddoffsetlow));
    17827 +               else
    17828 +                       W_REG(di->osh, &di->d32rxregs->addr, (pa + di->ddoffsetlow));
    17829 +       } else {
    17830 +               /* dma32 address extension */
    17831 +               uint32 ae;
    17832 +               ASSERT(di->addrext);
    17833 +
    17834 +               /* shift the high bit(s) from pa to ae */
    17835 +               ae = (pa & PCI32ADDR_HIGH) >> PCI32ADDR_HIGH_SHIFT;
    17836 +               pa &= ~PCI32ADDR_HIGH;
    17837 +
    17838 +               if (direction == DMA_TX) {
    17839 +                       W_REG(di->osh, &di->d32txregs->addr, (pa + di->ddoffsetlow));
    17840 +                       SET_REG(di->osh, &di->d32txregs->control, XC_AE, ae <<XC_AE_SHIFT);
    17841 +               } else {
    17842 +                       W_REG(di->osh, &di->d32rxregs->addr, (pa + di->ddoffsetlow));
    17843 +                       SET_REG(di->osh, &di->d32rxregs->control, RC_AE, ae <<RC_AE_SHIFT);
     10954+       MFREE(di->osh, (void*)di, sizeof (dma_info_t));
     10955+}
     10956+
     10957+
     10958+void
     10959+dma_txreset(dma_info_t *di)
     10960+{
     10961+       uint32 status;
     10962+
     10963+       DMA_TRACE(("%s: dma_txreset\n", di->name));
     10964+
     10965+       /* suspend tx DMA first */
     10966+       W_REG(&di->regs->xmtcontrol, XC_SE);
     10967+       SPINWAIT((status = (R_REG(&di->regs->xmtstatus) & XS_XS_MASK)) != XS_XS_DISABLED &&
     10968+                status != XS_XS_IDLE &&
     10969+                status != XS_XS_STOPPED,
     10970+                10000);
     10971+
     10972+       W_REG(&di->regs->xmtcontrol, 0);
     10973+       SPINWAIT((status = (R_REG(&di->regs->xmtstatus) & XS_XS_MASK)) != XS_XS_DISABLED,
     10974+                10000);
     10975+
     10976+       if (status != XS_XS_DISABLED) {
     10977+               DMA_ERROR(("%s: dma_txreset: dma cannot be stopped\n", di->name));
     10978+       }
     10979+
     10980+       /* wait for the last transaction to complete */
     10981+       OSL_DELAY(300);
     10982+}
     10983+
     10984+void
     10985+dma_rxreset(dma_info_t *di)
     10986+{
     10987+       uint32 status;
     10988+
     10989+       DMA_TRACE(("%s: dma_rxreset\n", di->name));
     10990+
     10991+       W_REG(&di->regs->rcvcontrol, 0);
     10992+       SPINWAIT((status = (R_REG(&di->regs->rcvstatus) & RS_RS_MASK)) != RS_RS_DISABLED,
     10993+                10000);
     10994+
     10995+       if (status != RS_RS_DISABLED) {
     10996+               DMA_ERROR(("%s: dma_rxreset: dma cannot be stopped\n", di->name));
     10997+       }
     10998+}
     10999+
     11000+void
     11001+dma_txinit(dma_info_t *di)
     11002+{
     11003+       DMA_TRACE(("%s: dma_txinit\n", di->name));
     11004+
     11005+       di->txin = di->txout = 0;
     11006+       di->txavail = di->ntxd - 1;
     11007+
     11008+       /* clear tx descriptor ring */
     11009+       BZERO_SM((void*)di->txd, (di->ntxd * sizeof (dmadd_t)));
     11010+
     11011+       W_REG(&di->regs->xmtcontrol, XC_XE);
     11012+       W_REG(&di->regs->xmtaddr, (di->txdpa + di->ddoffset));
     11013+}
     11014+
     11015+bool
     11016+dma_txenabled(dma_info_t *di)
     11017+{
     11018+       uint32 xc;
     11019+
     11020+       /* If the chip is dead, it is not enabled :-) */
     11021+       xc = R_REG(&di->regs->xmtcontrol);
     11022+       return ((xc != 0xffffffff) && (xc & XC_XE));
     11023+}
     11024+
     11025+void
     11026+dma_txsuspend(dma_info_t *di)
     11027+{
     11028+       DMA_TRACE(("%s: dma_txsuspend\n", di->name));
     11029+       OR_REG(&di->regs->xmtcontrol, XC_SE);
     11030+}
     11031+
     11032+void
     11033+dma_txresume(dma_info_t *di)
     11034+{
     11035+       DMA_TRACE(("%s: dma_txresume\n", di->name));
     11036+       AND_REG(&di->regs->xmtcontrol, ~XC_SE);
     11037+}
     11038+
     11039+bool
     11040+dma_txsuspended(dma_info_t *di)
     11041+{
     11042+       if (!(R_REG(&di->regs->xmtcontrol) & XC_SE))
     11043+               return 0;
     11044+       
     11045+       if ((R_REG(&di->regs->xmtstatus) & XS_XS_MASK) != XS_XS_IDLE)
     11046+               return 0;
     11047+
     11048+       OSL_DELAY(2);
     11049+       return ((R_REG(&di->regs->xmtstatus) & XS_XS_MASK) == XS_XS_IDLE);
     11050+}
     11051+
     11052+bool
     11053+dma_txstopped(dma_info_t *di)
     11054+{
     11055+       return ((R_REG(&di->regs->xmtstatus) & XS_XS_MASK) == XS_XS_STOPPED);
     11056+}
     11057+
     11058+bool
     11059+dma_rxstopped(dma_info_t *di)
     11060+{
     11061+       return ((R_REG(&di->regs->rcvstatus) & RS_RS_MASK) == RS_RS_STOPPED);
     11062+}
     11063+
     11064+void
     11065+dma_fifoloopbackenable(dma_info_t *di)
     11066+{
     11067+       DMA_TRACE(("%s: dma_fifoloopbackenable\n", di->name));
     11068+       OR_REG(&di->regs->xmtcontrol, XC_LE);
     11069+}
     11070+
     11071+void
     11072+dma_rxinit(dma_info_t *di)
     11073+{
     11074+       DMA_TRACE(("%s: dma_rxinit\n", di->name));
     11075+
     11076+       di->rxin = di->rxout = 0;
     11077+
     11078+       /* clear rx descriptor ring */
     11079+       BZERO_SM((void*)di->rxd, (di->nrxd * sizeof (dmadd_t)));
     11080+
     11081+       dma_rxenable(di);
     11082+       W_REG(&di->regs->rcvaddr, (di->rxdpa + di->ddoffset));
     11083+}
     11084+
     11085+void
     11086+dma_rxenable(dma_info_t *di)
     11087+{
     11088+       DMA_TRACE(("%s: dma_rxenable\n", di->name));
     11089+       W_REG(&di->regs->rcvcontrol, ((di->rxoffset << RC_RO_SHIFT) | RC_RE));
     11090+}
     11091+
     11092+bool
     11093+dma_rxenabled(dma_info_t *di)
     11094+{
     11095+       uint32 rc;
     11096+
     11097+       rc = R_REG(&di->regs->rcvcontrol);
     11098+       return ((rc != 0xffffffff) && (rc & RC_RE));
     11099+}
     11100+
     11101+/*
     11102+ * The BCM47XX family supports full 32bit dma engine buffer addressing so
     11103+ * dma buffers can cross 4 Kbyte page boundaries.
     11104+ */
     11105+int
     11106+dma_txfast(dma_info_t *di, void *p0, uint32 coreflags)
     11107+{
     11108+       void *p, *next;
     11109+       uchar *data;
     11110+       uint len;
     11111+       uint txout;
     11112+       uint32 ctrl;
     11113+       uint32 pa;
     11114+
     11115+       DMA_TRACE(("%s: dma_txfast\n", di->name));
     11116+
     11117+       txout = di->txout;
     11118+       ctrl = 0;
     11119+
     11120+       /*
     11121+        * Walk the chain of packet buffers
     11122+        * allocating and initializing transmit descriptor entries.
     11123+        */
     11124+       for (p = p0; p; p = next) {
     11125+               data = PKTDATA(di->drv, p);
     11126+               len = PKTLEN(di->drv, p);
     11127+               next = PKTNEXT(di->drv, p);
     11128+
     11129+               /* return nonzero if out of tx descriptors */
     11130+               if (NEXTTXD(txout) == di->txin)
     11131+                       goto outoftxd;
     11132+
     11133+               if (len == 0)
     11134+                       continue;
     11135+
     11136+               /* get physical address of buffer start */
     11137+               pa = (uint32) DMA_MAP(di->osh, data, len, DMA_TX, p);
     11138+               ASSERT(DMA_ADDRESSABLE(pa));
     11139+
     11140+               /* build the descriptor control value */
     11141+               ctrl = len & CTRL_BC_MASK;
     11142+
     11143+               ctrl |= coreflags;
     11144+               
     11145+               if (p == p0)
     11146+                       ctrl |= CTRL_SOF;
     11147+               if (next == NULL)
     11148+                       ctrl |= (CTRL_IOC | CTRL_EOF);
     11149+               if (txout == (di->ntxd - 1))
     11150+                       ctrl |= CTRL_EOT;
     11151+
     11152+               /* init the tx descriptor */
     11153+               W_SM(&di->txd[txout].ctrl, BUS_SWAP32(ctrl));
     11154+               W_SM(&di->txd[txout].addr, BUS_SWAP32(pa + di->dataoffset));
     11155+
     11156+               ASSERT(di->txp[txout] == NULL);
     11157+
     11158+               txout = NEXTTXD(txout);
     11159+       }
     11160+
     11161+       /* if last txd eof not set, fix it */
     11162+       if (!(ctrl & CTRL_EOF))
     11163+               W_SM(&di->txd[PREVTXD(txout)].ctrl, BUS_SWAP32(ctrl | CTRL_IOC | CTRL_EOF));
     11164+
     11165+       /* save the packet */
     11166+       di->txp[PREVTXD(txout)] = p0;
     11167+
     11168+       /* bump the tx descriptor index */
     11169+       di->txout = txout;
     11170+
     11171+       /* kick the chip */
     11172+       W_REG(&di->regs->xmtptr, I2B(txout));
     11173+
     11174+       /* tx flow control */
     11175+       di->txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
     11176+
     11177+       return (0);
     11178+
     11179+outoftxd:
     11180+       DMA_ERROR(("%s: dma_txfast: out of txds\n", di->name));
     11181+       PKTFREE(di->drv, p0, TRUE);
     11182+       di->txavail = 0;
     11183+       di->hnddma.txnobuf++;
     11184+       return (-1);
     11185+}
     11186+
     11187+#define        PAGESZ          4096
     11188+#define        PAGEBASE(x)     ((uintptr)(x) & ~4095)
     11189+
     11190+/*
     11191+ * Just like above except go through the extra effort of splitting
     11192+ * buffers that cross 4Kbyte boundaries into multiple tx descriptors.
     11193+ */
     11194+int
     11195+dma_tx(dma_info_t *di, void *p0, uint32 coreflags)
     11196+{
     11197+       void *p, *next;
     11198+       uchar *data;
     11199+       uint plen, len;
     11200+       uchar *page, *start, *end;
     11201+       uint txout;
     11202+       uint32 ctrl;
     11203+       uint32 pa;
     11204+
     11205+       DMA_TRACE(("%s: dma_tx\n", di->name));
     11206+
     11207+       txout = di->txout;
     11208+       ctrl = 0;
     11209+
     11210+       /*
     11211+        * Walk the chain of packet buffers
     11212+        * splitting those that cross 4 Kbyte boundaries
     11213+        * allocating and initializing transmit descriptor entries.
     11214+        */
     11215+       for (p = p0; p; p = next) {
     11216+               data = PKTDATA(di->drv, p);
     11217+               plen = PKTLEN(di->drv, p);
     11218+               next = PKTNEXT(di->drv, p);
     11219+
     11220+               if (plen == 0)
     11221+                       continue;
     11222+
     11223+               for (page = (uchar*)PAGEBASE(data);
     11224+                       page <= (uchar*)PAGEBASE(data + plen - 1);
     11225+                       page += PAGESZ) {
     11226+
     11227+                       /* return nonzero if out of tx descriptors */
     11228+                       if (NEXTTXD(txout) == di->txin)
     11229+                               goto outoftxd;
     11230+
     11231+                       start = (page == (uchar*)PAGEBASE(data))?  data: page;
     11232+                       end = (page == (uchar*)PAGEBASE(data + plen))?
     11233+                               (data + plen): (page + PAGESZ);
     11234+                       len = (uint)(end - start);
     11235+
     11236+                       /* build the descriptor control value */
     11237+                       ctrl = len & CTRL_BC_MASK;
     11238+
     11239+                       ctrl |= coreflags;
     11240+
     11241+                       if ((p == p0) && (start == data))
     11242+                               ctrl |= CTRL_SOF;
     11243+                       if ((next == NULL) && (end == (data + plen)))
     11244+                               ctrl |= (CTRL_IOC | CTRL_EOF);
     11245+                       if (txout == (di->ntxd - 1))
     11246+                               ctrl |= CTRL_EOT;
     11247+
     11248+                       /* get physical address of buffer start */
     11249+                       pa = (uint32) DMA_MAP(di->osh, start, len, DMA_TX, p);
     11250+                       ASSERT(DMA_ADDRESSABLE(pa));
     11251+
     11252+                       /* init the tx descriptor */
     11253+                       W_SM(&di->txd[txout].ctrl, BUS_SWAP32(ctrl));
     11254+                       W_SM(&di->txd[txout].addr, BUS_SWAP32(pa + di->dataoffset));
     11255+
     11256+                       ASSERT(di->txp[txout] == NULL);
     11257+
     11258+                       txout = NEXTTXD(txout);
    1784411259+               }
    1784511260+       }
    17846 +}
    17847 +
    17848 +static void
    17849 +_dma_fifoloopbackenable(dma_info_t *di)
    17850 +{
    17851 +       DMA_TRACE(("%s: dma_fifoloopbackenable\n", di->name));
    17852 +       OR_REG(di->osh, &di->d32txregs->control, XC_LE);
    17853 +}
    17854 +
    17855 +static void
    17856 +_dma_rxinit(dma_info_t *di)
    17857 +{
    17858 +       DMA_TRACE(("%s: dma_rxinit\n", di->name));
    17859 +
    17860 +       if (di->nrxd == 0)
    17861 +               return;
    17862 +
    17863 +       di->rxin = di->rxout = 0;
    17864 +
    17865 +       /* clear rx descriptor ring */
    17866 +       BZERO_SM((void *)di->rxd32, (di->nrxd * sizeof(dma32dd_t)));
    17867 +       _dma_rxenable(di);
    17868 +       _dma_ddtable_init(di, DMA_RX, di->rxdpa);
    17869 +}
    17870 +
    17871 +static void
    17872 +_dma_rxenable(dma_info_t *di)
    17873 +{
    17874 +       DMA_TRACE(("%s: dma_rxenable\n", di->name));
    17875 +
    17876 +       W_REG(di->osh, &di->d32rxregs->control, ((di->rxoffset << RC_RO_SHIFT) | RC_RE));
    17877 +}
    17878 +
    17879 +/* !! rx entry routine, returns a pointer to the next frame received,
    17880 + * or NULL if there are no more
    17881 + */
    17882 +static void *
    17883 +_dma_rx(dma_info_t *di)
     11261+
     11262+       /* if last txd eof not set, fix it */
     11263+       if (!(ctrl & CTRL_EOF))
     11264+               W_SM(&di->txd[PREVTXD(txout)].ctrl, BUS_SWAP32(ctrl | CTRL_IOC | CTRL_EOF));
     11265+
     11266+       /* save the packet */
     11267+       di->txp[PREVTXD(txout)] = p0;
     11268+
     11269+       /* bump the tx descriptor index */
     11270+       di->txout = txout;
     11271+
     11272+       /* kick the chip */
     11273+       W_REG(&di->regs->xmtptr, I2B(txout));
     11274+
     11275+       /* tx flow control */
     11276+       di->txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
     11277+
     11278+       return (0);
     11279+
     11280+outoftxd:
     11281+       DMA_ERROR(("%s: dma_tx: out of txds\n", di->name));
     11282+       PKTFREE(di->drv, p0, TRUE);
     11283+       di->txavail = 0;
     11284+       di->hnddma.txnobuf++;
     11285+       return (-1);
     11286+}
     11287+
     11288+/* returns a pointer to the next frame received, or NULL if there are no more */
     11289+void*
     11290+dma_rx(dma_info_t *di)
    1788411291+{
    1788511292+       void *p;
     
    1788711294+       int skiplen = 0;
    1788811295+
    17889 +       while ((p = _dma_getnextrxp(di, FALSE))) {
     11296+       while ((p = dma_getnextrxp(di, FALSE))) {
    1789011297+               /* skip giant packets which span multiple rx descriptors */
    1789111298+               if (skiplen > 0) {
     
    1789311300+                       if (skiplen < 0)
    1789411301+                               skiplen = 0;
    17895 +                       PKTFREE(di->osh, p, FALSE);
     11302+                       PKTFREE(di->drv, p, FALSE);
    1789611303+                       continue;
    1789711304+               }
    1789811305+
    17899 +               len = ltoh16(*(uint16*)(PKTDATA(di->osh, p)));
     11306+               len = ltoh16(*(uint16*)(PKTDATA(di->drv, p)));
    1790011307+               DMA_TRACE(("%s: dma_rx len %d\n", di->name, len));
    1790111308+
     
    1790511312+                       if (len > 0)
    1790611313+                               skiplen = len - (di->rxbufsize - di->rxoffset);
    17907 +                       PKTFREE(di->osh, p, FALSE);
     11314+                       PKTFREE(di->drv, p, FALSE);
    1790811315+                       di->hnddma.rxgiants++;
    1790911316+                       continue;
     
    1791111318+
    1791211319+               /* set actual length */
    17913 +               PKTSETLEN(di->osh, p, (di->rxoffset + len));
     11320+               PKTSETLEN(di->drv, p, (di->rxoffset + len));
    1791411321+
    1791511322+               break;
     
    1792011327+
    1792111328+/* post receive buffers */
    17922 +static void
    17923 +_dma_rxfill(dma_info_t *di)
     11329+void
     11330+dma_rxfill(dma_info_t *di)
    1792411331+{
    1792511332+       void *p;
    1792611333+       uint rxin, rxout;
    17927 +       uint32 flags = 0;
     11334+       uint ctrl;
    1792811335+       uint n;
    1792911336+       uint i;
    1793011337+       uint32 pa;
    17931 +       uint extra_offset = 0;
     11338+       uint rxbufsize;
    1793211339+
    1793311340+       /*
     
    1793911346+       rxin = di->rxin;
    1794011347+       rxout = di->rxout;
     11348+       rxbufsize = di->rxbufsize;
    1794111349+
    1794211350+       n = di->nrxpost - NRXDACTIVE(rxin, rxout);
     
    1794411352+       DMA_TRACE(("%s: dma_rxfill: post %d\n", di->name, n));
    1794511353+
    17946 +       if (di->rxbufsize > BCMEXTRAHDROOM)
    17947 +               extra_offset = BCMEXTRAHDROOM;
    17948 +
    1794911354+       for (i = 0; i < n; i++) {
    17950 +               /* the di->rxbufsize doesn't include the extra headroom, we need to add it to the
    17951 +                  size to be allocated
    17952 +               */
    17953 +               if ((p = PKTGET(di->osh, di->rxbufsize + extra_offset,
    17954 +                               FALSE)) == NULL) {
     11355+               if ((p = PKTGET(di->drv, rxbufsize, FALSE)) == NULL) {
    1795511356+                       DMA_ERROR(("%s: dma_rxfill: out of rxbufs\n", di->name));
    1795611357+                       di->hnddma.rxnobuf++;
    1795711358+                       break;
    1795811359+               }
    17959 +               /* reserve an extra headroom, if applicable */
    17960 +               if (extra_offset)
    17961 +                       PKTPULL(di->osh, p, extra_offset);
    17962 +
    17963 +               /* Do a cached write instead of uncached write since DMA_MAP
    17964 +                * will flush the cache.
    17965 +                */
    17966 +               *(uint32*)(PKTDATA(di->osh, p)) = 0;
    17967 +
    17968 +               pa = (uint32) DMA_MAP(di->osh, PKTDATA(di->osh, p),
    17969 +                                     di->rxbufsize, DMA_RX, p);
    17970 +
     11360+
     11361+               *(uint32*)(OSL_UNCACHED(PKTDATA(di->drv, p))) = 0;
     11362+
     11363+               pa = (uint32) DMA_MAP(di->osh, PKTDATA(di->drv, p), rxbufsize, DMA_RX, p);
    1797111364+               ASSERT(ISALIGNED(pa, 4));
     11365+               ASSERT(DMA_ADDRESSABLE(pa));
    1797211366+
    1797311367+               /* save the free packet pointer */
     
    1797511369+               di->rxp[rxout] = p;
    1797611370+
    17977 +               /* reset flags for each descriptor */
    17978 +               flags = 0;
     11371+               /* prep the descriptor control value */
     11372+               ctrl = rxbufsize;
    1797911373+               if (rxout == (di->nrxd - 1))
    17980 +                       flags = CTRL_EOT;
    17981 +               dma32_dd_upd(di, di->rxd32, pa, rxout, &flags, di->rxbufsize);
     11374+                       ctrl |= CTRL_EOT;
     11375+
     11376+               /* init the rx descriptor */
     11377+               W_SM(&di->rxd[rxout].ctrl, BUS_SWAP32(ctrl));
     11378+               W_SM(&di->rxd[rxout].addr, BUS_SWAP32(pa + di->dataoffset));
     11379+
    1798211380+               rxout = NEXTRXD(rxout);
    1798311381+       }
     
    1798611384+
    1798711385+       /* update the chip lastdscr pointer */
    17988 +       W_REG(di->osh, &di->d32rxregs->ptr, I2B(rxout, dma32dd_t));
    17989 +}
    17990 +
    17991 +/* like getnexttxp but no reclaim */
    17992 +static void *
    17993 +_dma_peeknexttxp(dma_info_t *di)
    17994 +{
    17995 +       uint end, i;
    17996 +
    17997 +       if (di->ntxd == 0)
    17998 +               return (NULL);
    17999 +
    18000 +       end = B2I(R_REG(di->osh, &di->d32txregs->status) & XS_CD_MASK, dma32dd_t);
    18001 +
    18002 +       for (i = di->txin; i != end; i = NEXTTXD(i))
    18003 +               if (di->txp[i])
    18004 +                       return (di->txp[i]);
    18005 +
    18006 +       return (NULL);
    18007 +}
    18008 +
    18009 +static void
    18010 +_dma_rxreclaim(dma_info_t *di)
     11386+       W_REG(&di->regs->rcvptr, I2B(rxout));
     11387+}
     11388+
     11389+void
     11390+dma_txreclaim(dma_info_t *di, bool forceall)
    1801111391+{
    1801211392+       void *p;
    1801311393+
    18014 +       /* "unused local" warning suppression for OSLs that
    18015 +        * define PKTFREE() without using the di->osh arg
    18016 +        */
    18017 +       di = di;
    18018 +
    18019 +       DMA_TRACE(("%s: dma_rxreclaim\n", di->name));
    18020 +
    18021 +       while ((p = _dma_getnextrxp(di, TRUE)))
    18022 +               PKTFREE(di->osh, p, FALSE);
    18023 +}
    18024 +
    18025 +static void *
    18026 +_dma_getnextrxp(dma_info_t *di, bool forceall)
    18027 +{
    18028 +       if (di->nrxd == 0)
    18029 +               return (NULL);
    18030 +
    18031 +       return dma32_getnextrxp(di, forceall);
    18032 +}
    18033 +
    18034 +static void
    18035 +_dma_txblock(dma_info_t *di)
    18036 +{
    18037 +       di->hnddma.txavail = 0;
    18038 +}
    18039 +
    18040 +static void
    18041 +_dma_txunblock(dma_info_t *di)
    18042 +{
    18043 +       di->hnddma.txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
    18044 +}
    18045 +
    18046 +static uint
    18047 +_dma_txactive(dma_info_t *di)
    18048 +{
    18049 +       return (NTXDACTIVE(di->txin, di->txout));
    18050 +}
    18051 +
    18052 +static void
    18053 +_dma_counterreset(dma_info_t *di)
    18054 +{
    18055 +       /* reset all software counter */
    18056 +       di->hnddma.rxgiants = 0;
    18057 +       di->hnddma.rxnobuf = 0;
    18058 +       di->hnddma.txnobuf = 0;
    18059 +}
    18060 +
    18061 +/* get the address of the var in order to change later */
    18062 +static uintptr
    18063 +_dma_getvar(dma_info_t *di, char *name)
    18064 +{
    18065 +       if (!strcmp(name, "&txavail"))
    18066 +               return ((uintptr) &(di->hnddma.txavail));
    18067 +       else {
    18068 +               ASSERT(0);
    18069 +       }
    18070 +       return (0);
    18071 +}
    18072 +
    18073 +void
    18074 +dma_txpioloopback(osl_t *osh, dma32regs_t *regs)
    18075 +{
    18076 +       OR_REG(osh, &regs->control, XC_LE);
    18077 +}
    18078 +
    18079 +
    18080 +
    18081 +/* 32 bits DMA functions */
    18082 +static void
    18083 +dma32_txinit(dma_info_t *di)
    18084 +{
    18085 +       DMA_TRACE(("%s: dma_txinit\n", di->name));
    18086 +
    18087 +       if (di->ntxd == 0)
    18088 +               return;
    18089 +
    18090 +       di->txin = di->txout = 0;
    18091 +       di->hnddma.txavail = di->ntxd - 1;
    18092 +
    18093 +       /* clear tx descriptor ring */
    18094 +       BZERO_SM((void *)di->txd32, (di->ntxd * sizeof(dma32dd_t)));
    18095 +       W_REG(di->osh, &di->d32txregs->control, XC_XE);
    18096 +       _dma_ddtable_init(di, DMA_TX, di->txdpa);
    18097 +}
    18098 +
    18099 +static bool
    18100 +dma32_txenabled(dma_info_t *di)
    18101 +{
    18102 +       uint32 xc;
    18103 +
    18104 +       /* If the chip is dead, it is not enabled :-) */
    18105 +       xc = R_REG(di->osh, &di->d32txregs->control);
    18106 +       return ((xc != 0xffffffff) && (xc & XC_XE));
    18107 +}
    18108 +
    18109 +static void
    18110 +dma32_txsuspend(dma_info_t *di)
    18111 +{
    18112 +       DMA_TRACE(("%s: dma_txsuspend\n", di->name));
    18113 +
    18114 +       if (di->ntxd == 0)
    18115 +               return;
    18116 +
    18117 +       OR_REG(di->osh, &di->d32txregs->control, XC_SE);
    18118 +}
    18119 +
    18120 +static void
    18121 +dma32_txresume(dma_info_t *di)
    18122 +{
    18123 +       DMA_TRACE(("%s: dma_txresume\n", di->name));
    18124 +
    18125 +       if (di->ntxd == 0)
    18126 +               return;
    18127 +
    18128 +       AND_REG(di->osh, &di->d32txregs->control, ~XC_SE);
    18129 +}
    18130 +
    18131 +static bool
    18132 +dma32_txsuspended(dma_info_t *di)
    18133 +{
    18134 +       return (di->ntxd == 0) || ((R_REG(di->osh, &di->d32txregs->control) & XC_SE) == XC_SE);
    18135 +}
    18136 +
    18137 +static void
    18138 +dma32_txreclaim(dma_info_t *di, bool forceall)
    18139 +{
    18140 +       void *p;
    18141 +
    1814211394+       DMA_TRACE(("%s: dma_txreclaim %s\n", di->name, forceall ? "all" : ""));
    1814311395+
    18144 +       while ((p = dma32_getnexttxp(di, forceall)))
    18145 +               PKTFREE(di->osh, p, TRUE);
    18146 +}
    18147 +
    18148 +static bool
    18149 +dma32_txstopped(dma_info_t *di)
    18150 +{
    18151 +       return ((R_REG(di->osh, &di->d32txregs->status) & XS_XS_MASK) == XS_XS_STOPPED);
    18152 +}
    18153 +
    18154 +static bool
    18155 +dma32_rxstopped(dma_info_t *di)
    18156 +{
    18157 +       return ((R_REG(di->osh, &di->d32rxregs->status) & RS_RS_MASK) == RS_RS_STOPPED);
    18158 +}
    18159 +
    18160 +static bool
    18161 +dma32_alloc(dma_info_t *di, uint direction)
    18162 +{
    18163 +       uint size;
    18164 +       uint ddlen;
    18165 +       void *va;
    18166 +
    18167 +       ddlen = sizeof(dma32dd_t);
    18168 +
    18169 +       size = (direction == DMA_TX) ? (di->ntxd * ddlen) : (di->nrxd * ddlen);
    18170 +
    18171 +       if (!ISALIGNED(DMA_CONSISTENT_ALIGN, D32RINGALIGN))
    18172 +               size += D32RINGALIGN;
    18173 +
    18174 +
    18175 +       if (direction == DMA_TX) {
    18176 +               if ((va = DMA_ALLOC_CONSISTENT(di->osh, size, &di->txdpa, &di->tx_dmah)) == NULL) {
    18177 +                       DMA_ERROR(("%s: dma_attach: DMA_ALLOC_CONSISTENT(ntxd) failed\n",
    18178 +                                  di->name));
    18179 +                       return FALSE;
    18180 +               }
    18181 +
    18182 +               di->txd32 = (dma32dd_t *) ROUNDUP((uintptr)va, D32RINGALIGN);
    18183 +               di->txdalign = (uint)((int8*)di->txd32 - (int8*)va);
    18184 +               di->txdpa += di->txdalign;
    18185 +               di->txdalloc = size;
    18186 +               ASSERT(ISALIGNED((uintptr)di->txd32, D32RINGALIGN));
    18187 +       } else {
    18188 +               if ((va = DMA_ALLOC_CONSISTENT(di->osh, size, &di->rxdpa, &di->rx_dmah)) == NULL) {
    18189 +                       DMA_ERROR(("%s: dma_attach: DMA_ALLOC_CONSISTENT(nrxd) failed\n",
    18190 +                                  di->name));
    18191 +                       return FALSE;
    18192 +               }
    18193 +               di->rxd32 = (dma32dd_t *) ROUNDUP((uintptr)va, D32RINGALIGN);
    18194 +               di->rxdalign = (uint)((int8*)di->rxd32 - (int8*)va);
    18195 +               di->rxdpa += di->rxdalign;
    18196 +               di->rxdalloc = size;
    18197 +               ASSERT(ISALIGNED((uintptr)di->rxd32, D32RINGALIGN));
    18198 +       }
    18199 +
    18200 +       return TRUE;
    18201 +}
    18202 +
    18203 +static bool
    18204 +dma32_txreset(dma_info_t *di)
    18205 +{
    18206 +       uint32 status;
    18207 +
    18208 +       if (di->ntxd == 0)
    18209 +               return TRUE;
    18210 +
    18211 +       /* suspend tx DMA first */
    18212 +       W_REG(di->osh, &di->d32txregs->control, XC_SE);
    18213 +       SPINWAIT(((status = (R_REG(di->osh, &di->d32txregs->status) & XS_XS_MASK))
    18214 +                != XS_XS_DISABLED) &&
    18215 +                (status != XS_XS_IDLE) &&
    18216 +                (status != XS_XS_STOPPED),
    18217 +                (10000));
    18218 +
    18219 +       W_REG(di->osh, &di->d32txregs->control, 0);
    18220 +       SPINWAIT(((status = (R_REG(di->osh,
    18221 +                &di->d32txregs->status) & XS_XS_MASK)) != XS_XS_DISABLED),
    18222 +                10000);
    18223 +
    18224 +       /* wait for the last transaction to complete */
    18225 +       OSL_DELAY(300);
    18226 +
    18227 +       return (status == XS_XS_DISABLED);
    18228 +}
    18229 +
    18230 +static bool
    18231 +dma32_rxidle(dma_info_t *di)
    18232 +{
    18233 +       DMA_TRACE(("%s: dma_rxidle\n", di->name));
    18234 +
    18235 +       if (di->nrxd == 0)
    18236 +               return TRUE;
    18237 +
    18238 +       return ((R_REG(di->osh, &di->d32rxregs->status) & RS_CD_MASK) ==
    18239 +               R_REG(di->osh, &di->d32rxregs->ptr));
    18240 +}
    18241 +
    18242 +static bool
    18243 +dma32_rxreset(dma_info_t *di)
    18244 +{
    18245 +       uint32 status;
    18246 +
    18247 +       if (di->nrxd == 0)
    18248 +               return TRUE;
    18249 +
    18250 +       W_REG(di->osh, &di->d32rxregs->control, 0);
    18251 +       SPINWAIT(((status = (R_REG(di->osh,
    18252 +                &di->d32rxregs->status) & RS_RS_MASK)) != RS_RS_DISABLED),
    18253 +                10000);
    18254 +
    18255 +       return (status == RS_RS_DISABLED);
    18256 +}
    18257 +
    18258 +static bool
    18259 +dma32_rxenabled(dma_info_t *di)
    18260 +{
    18261 +       uint32 rc;
    18262 +
    18263 +       rc = R_REG(di->osh, &di->d32rxregs->control);
    18264 +       return ((rc != 0xffffffff) && (rc & RC_RE));
    18265 +}
    18266 +
    18267 +static bool
    18268 +dma32_txsuspendedidle(dma_info_t *di)
    18269 +{
    18270 +       if (di->ntxd == 0)
    18271 +               return TRUE;
    18272 +
    18273 +       if (!(R_REG(di->osh, &di->d32txregs->control) & XC_SE))
    18274 +               return 0;
    18275 +
    18276 +       if ((R_REG(di->osh, &di->d32txregs->status) & XS_XS_MASK) != XS_XS_IDLE)
    18277 +               return 0;
    18278 +
    18279 +       OSL_DELAY(2);
    18280 +       return ((R_REG(di->osh, &di->d32txregs->status) & XS_XS_MASK) == XS_XS_IDLE);
    18281 +}
    18282 +
    18283 +/* !! tx entry routine
    18284 + * supports full 32bit dma engine buffer addressing so
    18285 + * dma buffers can cross 4 Kbyte page boundaries.
    18286 + */
    18287 +static int
    18288 +dma32_txfast(dma_info_t *di, void *p0, bool commit)
    18289 +{
    18290 +       void *p, *next;
    18291 +       uchar *data;
    18292 +       uint len;
    18293 +       uint txout;
    18294 +       uint32 flags = 0;
    18295 +       uint32 pa;
    18296 +
    18297 +       DMA_TRACE(("%s: dma_txfast\n", di->name));
    18298 +
    18299 +       txout = di->txout;
    18300 +
    18301 +       /*
    18302 +        * Walk the chain of packet buffers
    18303 +        * allocating and initializing transmit descriptor entries.
    18304 +        */
    18305 +       for (p = p0; p; p = next) {
    18306 +               data = PKTDATA(di->osh, p);
    18307 +               len = PKTLEN(di->osh, p);
    18308 +               next = PKTNEXT(di->osh, p);
    18309 +
    18310 +               /* return nonzero if out of tx descriptors */
    18311 +               if (NEXTTXD(txout) == di->txin)
    18312 +                       goto outoftxd;
    18313 +
    18314 +               if (len == 0)
    18315 +                       continue;
    18316 +
    18317 +               /* get physical address of buffer start */
    18318 +               pa = (uint32) DMA_MAP(di->osh, data, len, DMA_TX, p);
    18319 +
    18320 +               flags = 0;
    18321 +               if (p == p0)
    18322 +                       flags |= CTRL_SOF;
    18323 +               if (next == NULL)
    18324 +                       flags |= (CTRL_IOC | CTRL_EOF);
    18325 +               if (txout == (di->ntxd - 1))
    18326 +                       flags |= CTRL_EOT;
    18327 +
    18328 +               dma32_dd_upd(di, di->txd32, pa, txout, &flags, len);
    18329 +               ASSERT(di->txp[txout] == NULL);
    18330 +
    18331 +               txout = NEXTTXD(txout);
    18332 +       }
    18333 +
    18334 +       /* if last txd eof not set, fix it */
    18335 +       if (!(flags & CTRL_EOF))
    18336 +               W_SM(&di->txd32[PREVTXD(txout)].ctrl, BUS_SWAP32(flags | CTRL_IOC | CTRL_EOF));
    18337 +
    18338 +       /* save the packet */
    18339 +       di->txp[PREVTXD(txout)] = p0;
    18340 +
    18341 +       /* bump the tx descriptor index */
    18342 +       di->txout = txout;
    18343 +
    18344 +       /* kick the chip */
    18345 +       if (commit)
    18346 +               W_REG(di->osh, &di->d32txregs->ptr, I2B(txout, dma32dd_t));
    18347 +
    18348 +       /* tx flow control */
    18349 +       di->hnddma.txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
    18350 +
    18351 +       return (0);
    18352 +
    18353 +outoftxd:
    18354 +       DMA_ERROR(("%s: dma_txfast: out of txds\n", di->name));
    18355 +       PKTFREE(di->osh, p0, TRUE);
    18356 +       di->hnddma.txavail = 0;
    18357 +       di->hnddma.txnobuf++;
    18358 +       return (-1);
     11396+       while ((p = dma_getnexttxp(di, forceall)))
     11397+               PKTFREE(di->drv, p, TRUE);
    1835911398+}
    1836011399+
     
    1836511404+ * regardless of the value of the hardware "curr" pointer.
    1836611405+ */
    18367 +static void *
    18368 +dma32_getnexttxp(dma_info_t *di, bool forceall)
     11406+void*
     11407+dma_getnexttxp(dma_info_t *di, bool forceall)
    1836911408+{
    1837011409+       uint start, end, i;
     
    1837211411+
    1837311412+       DMA_TRACE(("%s: dma_getnexttxp %s\n", di->name, forceall ? "all" : ""));
    18374 +
    18375 +       if (di->ntxd == 0)
    18376 +               return (NULL);
    1837711413+
    1837811414+       txp = NULL;
     
    1838211418+               end = di->txout;
    1838311419+       else
    18384 +               end = B2I(R_REG(di->osh, &di->d32txregs->status) & XS_CD_MASK, dma32dd_t);
     11420+               end = B2I(R_REG(&di->regs->xmtstatus) & XS_CD_MASK);
    1838511421+
    1838611422+       if ((start == 0) && (end > di->txout))
     
    1838811424+
    1838911425+       for (i = start; i != end && !txp; i = NEXTTXD(i)) {
    18390 +               DMA_UNMAP(di->osh, (BUS_SWAP32(R_SM(&di->txd32[i].addr)) - di->dataoffsetlow),
    18391 +                         (BUS_SWAP32(R_SM(&di->txd32[i].ctrl)) & CTRL_BC_MASK),
    18392 +                         DMA_TX, di->txp[i]);
    18393 +
    18394 +               W_SM(&di->txd32[i].addr, 0xdeadbeef);
     11426+               DMA_UNMAP(di->osh, (BUS_SWAP32(R_SM(&di->txd[i].addr)) - di->dataoffset),
     11427+                         (BUS_SWAP32(R_SM(&di->txd[i].ctrl)) & CTRL_BC_MASK), DMA_TX, di->txp[i]);
     11428+               W_SM(&di->txd[i].addr, 0xdeadbeef);
    1839511429+               txp = di->txp[i];
    1839611430+               di->txp[i] = NULL;
     
    1840011434+
    1840111435+       /* tx flow control */
    18402 +       di->hnddma.txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
     11436+       di->txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
    1840311437+
    1840411438+       return (txp);
     
    1841211446+}
    1841311447+
    18414 +static void *
    18415 +dma32_getnextrxp(dma_info_t *di, bool forceall)
     11448+/* like getnexttxp but no reclaim */
     11449+void*
     11450+dma_peeknexttxp(dma_info_t *di)
     11451+{
     11452+       uint end, i;
     11453+
     11454+       end = B2I(R_REG(&di->regs->xmtstatus) & XS_CD_MASK);
     11455+
     11456+       for (i = di->txin; i != end; i = NEXTTXD(i))
     11457+               if (di->txp[i])
     11458+                       return (di->txp[i]);
     11459+
     11460+       return (NULL);
     11461+}
     11462+
     11463+void
     11464+dma_rxreclaim(dma_info_t *di)
     11465+{
     11466+       void *p;
     11467+
     11468+       DMA_TRACE(("%s: dma_rxreclaim\n", di->name));
     11469+
     11470+       while ((p = dma_getnextrxp(di, TRUE)))
     11471+               PKTFREE(di->drv, p, FALSE);
     11472+}
     11473+
     11474+void *
     11475+dma_getnextrxp(dma_info_t *di, bool forceall)
    1841611476+{
    1841711477+       uint i;
     
    1841911479+
    1842011480+       /* if forcing, dma engine must be disabled */
    18421 +       ASSERT(!forceall || !dma32_rxenabled(di));
     11481+       ASSERT(!forceall || !dma_rxenabled(di));
    1842211482+
    1842311483+       i = di->rxin;
     
    1842811488+
    1842911489+       /* ignore curr if forceall */
    18430 +       if (!forceall && (i == B2I(R_REG(di->osh, &di->d32rxregs->status) & RS_CD_MASK, dma32dd_t)))
     11490+       if (!forceall && (i == B2I(R_REG(&di->regs->rcvstatus) & RS_CD_MASK)))
    1843111491+               return (NULL);
    1843211492+
     
    1843711497+
    1843811498+       /* clear this packet from the descriptor ring */
    18439 +       DMA_UNMAP(di->osh, (BUS_SWAP32(R_SM(&di->rxd32[i].addr)) - di->dataoffsetlow),
    18440 +                 di->rxbufsize, DMA_RX, rxp);
    18441 +
    18442 +       W_SM(&di->rxd32[i].addr, 0xdeadbeef);
     11499+       DMA_UNMAP(di->osh, (BUS_SWAP32(R_SM(&di->rxd[i].addr)) - di->dataoffset),
     11500+                 di->rxbufsize, DMA_RX, rxp);
     11501+       W_SM(&di->rxd[i].addr, 0xdeadbeef);
    1844311502+
    1844411503+       di->rxin = NEXTRXD(i);
    1844511504+
    1844611505+       return (rxp);
     11506+}
     11507+
     11508+
     11509+uintptr
     11510+dma_getvar(dma_info_t *di, char *name)
     11511+{
     11512+       if (!strcmp(name, "&txavail"))
     11513+               return ((uintptr) &di->txavail);
     11514+       else {
     11515+               ASSERT(0);
     11516+       }
     11517+       return (0);
     11518+}
     11519+
     11520+void
     11521+dma_txblock(dma_info_t *di)
     11522+{
     11523+       di->txavail = 0;
     11524+}
     11525+
     11526+void
     11527+dma_txunblock(dma_info_t *di)
     11528+{
     11529+       di->txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
     11530+}
     11531+
     11532+uint
     11533+dma_txactive(dma_info_t *di)
     11534+{
     11535+       return (NTXDACTIVE(di->txin, di->txout));
    1844711536+}
    1844811537+
     
    1845011539+ * Rotate all active tx dma ring entries "forward" by (ActiveDescriptor - txin).
    1845111540+ */
    18452 +static void
    18453 +dma32_txrotate(dma_info_t *di)
     11541+void
     11542+dma_txrotate(di_t *di)
    1845411543+{
    1845511544+       uint ad;
     
    1846011549+       uint first, last;
    1846111550+
    18462 +       ASSERT(dma32_txsuspendedidle(di));
    18463 +
    18464 +       nactive = _dma_txactive(di);
    18465 +       ad = B2I(((R_REG(di->osh, &di->d32txregs->status) & XS_AD_MASK) >> XS_AD_SHIFT), dma32dd_t);
     11551+       ASSERT(dma_txsuspended(di));
     11552+
     11553+       nactive = dma_txactive(di);
     11554+       ad = B2I((R_REG(&di->regs->xmtstatus) & XS_AD_MASK) >> XS_AD_SHIFT);
    1846611555+       rot = TXD(ad - di->txin);
    1846711556+
     
    1848511574+                * EOT is set only in the last entry in the ring.
    1848611575+                */
    18487 +               w = BUS_SWAP32(R_SM(&di->txd32[old].ctrl)) & ~CTRL_EOT;
     11576+               w = R_SM(&di->txd[old].ctrl) & ~CTRL_EOT;
    1848811577+               if (new == (di->ntxd - 1))
    1848911578+                       w |= CTRL_EOT;
    18490 +               W_SM(&di->txd32[new].ctrl, BUS_SWAP32(w));
    18491 +               W_SM(&di->txd32[new].addr, R_SM(&di->txd32[old].addr));
     11579+               W_SM(&di->txd[new].ctrl, w);
     11580+               W_SM(&di->txd[new].addr, R_SM(&di->txd[old].addr));
    1849211581+
    1849311582+               /* zap the old tx dma descriptor address field */
    18494 +               W_SM(&di->txd32[old].addr, BUS_SWAP32(0xdeadbeef));
     11583+               W_SM(&di->txd[old].addr, 0xdeadbeef);
    1849511584+
    1849611585+               /* move the corresponding txp[] entry */
     
    1850311592+       di->txin = ad;
    1850411593+       di->txout = TXD(di->txout + rot);
    18505 +       di->hnddma.txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
     11594+       di->txavail = di->ntxd - NTXDACTIVE(di->txin, di->txout) - 1;
    1850611595+
    1850711596+       /* kick the chip */
    18508 +       W_REG(di->osh, &di->d32txregs->ptr, I2B(di->txout, dma32dd_t));
    18509 +}
    18510 +
    18511 +
    18512 +uint
    18513 +dma_addrwidth(sb_t *sbh, void *dmaregs)
    18514 +{
    18515 +       dma32regs_t *dma32regs;
    18516 +       osl_t *osh;
    18517 +
    18518 +       osh = sb_osh(sbh);
    18519 +
    18520 +       /* Start checking for 32-bit / 30-bit addressing */
    18521 +       dma32regs = (dma32regs_t *)dmaregs;
    18522 +
    18523 +       /* For System Backplane, PCIE bus or addrext feature, 32-bits ok */
    18524 +       if ((BUSTYPE(sbh->bustype) == SB_BUS) ||
    18525 +           ((BUSTYPE(sbh->bustype) == PCI_BUS) && sbh->buscoretype == SB_PCIE) ||
    18526 +           (_dma32_addrext(osh, dma32regs)))
    18527 +               return (DMADDRWIDTH_32);
    18528 +
    18529 +       /* Fallthru */
    18530 +       return (DMADDRWIDTH_30);
    18531 +}
    18532 diff -urN linux.old/drivers/net/wl/hnddma.h linux.dev/drivers/net/wl/hnddma.h
    18533 --- linux.old/drivers/net/wl/hnddma.h   1970-01-01 01:00:00.000000000 +0100
    18534 +++ linux.dev/drivers/net/wl/hnddma.h   2006-04-28 02:20:44.000000000 +0200
    18535 @@ -0,0 +1,156 @@
    18536 +/*
    18537 + * Generic Broadcom Home Networking Division (HND) DMA engine SW interface
    18538 + * This supports the following chips: BCM42xx, 44xx, 47xx .
    18539 + *
    18540 + * Copyright 2006, Broadcom Corporation
    18541 + * All Rights Reserved.
    18542 + *
    18543 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    18544 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    18545 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    18546 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    18547 + * $Id: hnddma.h,v 1.1.1.13 2006/04/08 06:13:39 honor Exp $
    18548 + */
    18549 +
    18550 +#ifndef        _hnddma_h_
    18551 +#define        _hnddma_h_
    18552 +
    18553 +typedef const struct hnddma_pub hnddma_t;
    18554 +
    18555 +/* dma function type */
    18556 +typedef void (*di_detach_t)(hnddma_t *dmah);
    18557 +typedef bool (*di_txreset_t)(hnddma_t *dmah);
    18558 +typedef bool (*di_rxreset_t)(hnddma_t *dmah);
    18559 +typedef bool (*di_rxidle_t)(hnddma_t *dmah);
    18560 +typedef void (*di_txinit_t)(hnddma_t *dmah);
    18561 +typedef bool (*di_txenabled_t)(hnddma_t *dmah);
    18562 +typedef void (*di_rxinit_t)(hnddma_t *dmah);
    18563 +typedef void (*di_txsuspend_t)(hnddma_t *dmah);
    18564 +typedef void (*di_txresume_t)(hnddma_t *dmah);
    18565 +typedef bool (*di_txsuspended_t)(hnddma_t *dmah);
    18566 +typedef bool (*di_txsuspendedidle_t)(hnddma_t *dmah);
    18567 +typedef int (*di_txfast_t)(hnddma_t *dmah, void *p, bool commit);
    18568 +typedef void (*di_fifoloopbackenable_t)(hnddma_t *dmah);
    18569 +typedef bool  (*di_txstopped_t)(hnddma_t *dmah);
    18570 +typedef bool  (*di_rxstopped_t)(hnddma_t *dmah);
    18571 +typedef bool  (*di_rxenable_t)(hnddma_t *dmah);
    18572 +typedef bool  (*di_rxenabled_t)(hnddma_t *dmah);
    18573 +typedef void* (*di_rx_t)(hnddma_t *dmah);
    18574 +typedef void (*di_rxfill_t)(hnddma_t *dmah);
    18575 +typedef void (*di_txreclaim_t)(hnddma_t *dmah, bool forceall);
    18576 +typedef void (*di_rxreclaim_t)(hnddma_t *dmah);
    18577 +typedef        uintptr (*di_getvar_t)(hnddma_t *dmah, char *name);
    18578 +typedef void* (*di_getnexttxp_t)(hnddma_t *dmah, bool forceall);
    18579 +typedef void* (*di_getnextrxp_t)(hnddma_t *dmah, bool forceall);
    18580 +typedef void* (*di_peeknexttxp_t)(hnddma_t *dmah);
    18581 +typedef void (*di_txblock_t)(hnddma_t *dmah);
    18582 +typedef void (*di_txunblock_t)(hnddma_t *dmah);
    18583 +typedef uint (*di_txactive_t)(hnddma_t *dmah);
    18584 +typedef void (*di_txrotate_t)(hnddma_t *dmah);
    18585 +typedef void (*di_counterreset_t)(hnddma_t *dmah);
    18586 +typedef char* (*di_dump_t)(hnddma_t *dmah, struct bcmstrbuf *b, bool dumpring);
    18587 +typedef char* (*di_dumptx_t)(hnddma_t *dmah, struct bcmstrbuf *b, bool dumpring);
    18588 +typedef char* (*di_dumprx_t)(hnddma_t *dmah, struct bcmstrbuf *b, bool dumpring);
    18589 +
    18590 +/* dma opsvec */
    18591 +typedef struct di_fcn_s {
    18592 +       di_detach_t             detach;
    18593 +       di_txinit_t             txinit;
    18594 +       di_txreset_t            txreset;
    18595 +       di_txenabled_t          txenabled;
    18596 +       di_txsuspend_t          txsuspend;
    18597 +       di_txresume_t           txresume;
    18598 +       di_txsuspended_t        txsuspended;
    18599 +       di_txsuspendedidle_t    txsuspendedidle;
    18600 +       di_txfast_t             txfast;
    18601 +       di_txstopped_t          txstopped;
    18602 +       di_txreclaim_t          txreclaim;
    18603 +       di_getnexttxp_t         getnexttxp;
    18604 +       di_peeknexttxp_t        peeknexttxp;
    18605 +       di_txblock_t            txblock;
    18606 +       di_txunblock_t          txunblock;
    18607 +       di_txactive_t           txactive;
    18608 +       di_txrotate_t           txrotate;
    18609 +
    18610 +       di_rxinit_t             rxinit;
    18611 +       di_rxreset_t            rxreset;
    18612 +       di_rxidle_t             rxidle;
    18613 +       di_rxstopped_t          rxstopped;
    18614 +       di_rxenable_t           rxenable;
    18615 +       di_rxenabled_t          rxenabled;
    18616 +       di_rx_t                 rx;
    18617 +       di_rxfill_t             rxfill;
    18618 +       di_rxreclaim_t          rxreclaim;
    18619 +       di_getnextrxp_t         getnextrxp;
    18620 +
    18621 +       di_fifoloopbackenable_t fifoloopbackenable;
    18622 +       di_getvar_t             d_getvar;
    18623 +       di_counterreset_t       counterreset;
    18624 +       di_dump_t               dump;
    18625 +       di_dumptx_t             dumptx;
    18626 +       di_dumprx_t             dumprx;
    18627 +       uint                    endnum;
    18628 +} di_fcn_t;
    18629 +
    18630 +/*
    18631 + * Exported data structure (read-only)
    18632 + */
    18633 +/* export structure */
    18634 +struct hnddma_pub {
    18635 +       di_fcn_t        di_fn;          /* DMA function pointers */
    18636 +       uint            txavail;        /* # free tx descriptors */
    18637 +
    18638 +       /* rx error counters */
    18639 +       uint            rxgiants;       /* rx giant frames */
    18640 +       uint            rxnobuf;        /* rx out of dma descriptors */
    18641 +       /* tx error counters */
    18642 +       uint            txnobuf;        /* tx out of dma descriptors */
    18643 +};
    18644 +
    18645 +
    18646 +extern hnddma_t * dma_attach(osl_t *osh, char *name, sb_t *sbh, void *dmaregstx, void *dmaregsrx,
    18647 +                             uint ntxd, uint nrxd, uint rxbufsize, uint nrxpost, uint rxoffset,
    18648 +                             uint *msg_level);
    18649 +#define dma_detach(di)                 ((di)->di_fn.detach(di))
    18650 +#define dma_txreset(di)                        ((di)->di_fn.txreset(di))
    18651 +#define dma_rxreset(di)                        ((di)->di_fn.rxreset(di))
    18652 +#define dma_rxidle(di)                 ((di)->di_fn.rxidle(di))
    18653 +#define dma_txinit(di)                  ((di)->di_fn.txinit(di))
    18654 +#define dma_txenabled(di)               ((di)->di_fn.txenabled(di))
    18655 +#define dma_rxinit(di)                  ((di)->di_fn.rxinit(di))
    18656 +#define dma_txsuspend(di)               ((di)->di_fn.txsuspend(di))
    18657 +#define dma_txresume(di)                ((di)->di_fn.txresume(di))
    18658 +#define dma_txsuspended(di)             ((di)->di_fn.txsuspended(di))
    18659 +#define dma_txsuspendedidle(di)         ((di)->di_fn.txsuspendedidle(di))
    18660 +#define dma_txfast(di, p, commit)      ((di)->di_fn.txfast(di, p, commit))
    18661 +#define dma_fifoloopbackenable(di)      ((di)->di_fn.fifoloopbackenable(di))
    18662 +#define dma_txstopped(di)               ((di)->di_fn.txstopped(di))
    18663 +#define dma_rxstopped(di)               ((di)->di_fn.rxstopped(di))
    18664 +#define dma_rxenable(di)                ((di)->di_fn.rxenable(di))
    18665 +#define dma_rxenabled(di)               ((di)->di_fn.rxenabled(di))
    18666 +#define dma_rx(di)                      ((di)->di_fn.rx(di))
    18667 +#define dma_rxfill(di)                  ((di)->di_fn.rxfill(di))
    18668 +#define dma_txreclaim(di, forceall)    ((di)->di_fn.txreclaim(di, forceall))
    18669 +#define dma_rxreclaim(di)               ((di)->di_fn.rxreclaim(di))
    18670 +#define dma_getvar(di, name)           ((di)->di_fn.d_getvar(di, name))
    18671 +#define dma_getnexttxp(di, forceall)    ((di)->di_fn.getnexttxp(di, forceall))
    18672 +#define dma_getnextrxp(di, forceall)    ((di)->di_fn.getnextrxp(di, forceall))
    18673 +#define dma_peeknexttxp(di)             ((di)->di_fn.peeknexttxp(di))
    18674 +#define dma_txblock(di)                 ((di)->di_fn.txblock(di))
    18675 +#define dma_txunblock(di)               ((di)->di_fn.txunblock(di))
    18676 +#define dma_txactive(di)                ((di)->di_fn.txactive(di))
    18677 +#define dma_txrotate(di)                ((di)->di_fn.txrotate(di))
    18678 +#define dma_counterreset(di)            ((di)->di_fn.counterreset(di))
    18679 +
    18680 +#define DMA_DUMP_SIZE 2048
    18681 +/* return addresswidth allowed
    18682 + * This needs to be done after SB attach but before dma attach.
    18683 + * SB attach provides ability to probe backplane and dma core capabilities
    18684 + * This info is needed by DMA_ALLOC_CONSISTENT in dma attach
    18685 + */
    18686 +extern uint dma_addrwidth(sb_t *sbh, void *dmaregs);
    18687 +
    18688 +/* pio helpers */
    18689 +void dma_txpioloopback(osl_t *osh, dma32regs_t *);
    18690 +
    18691 +#endif /* _hnddma_h_ */
    18692 diff -urN linux.old/drivers/net/wl/linux_osl.c linux.dev/drivers/net/wl/linux_osl.c
    18693 --- linux.old/drivers/net/wl/linux_osl.c        1970-01-01 01:00:00.000000000 +0100
    18694 +++ linux.dev/drivers/net/wl/linux_osl.c        2006-04-28 02:29:46.000000000 +0200
    18695 @@ -0,0 +1,269 @@
     11597+       W_REG(&di->regs->xmtptr, I2B(di->txout));
     11598+}
     11599diff -Nur linux-2.4.32/drivers/net/hnd/linux_osl.c linux-2.4.32-freewrt/drivers/net/hnd/linux_osl.c
     11600--- linux-2.4.32/drivers/net/hnd/linux_osl.c    1970-01-01 01:00:00.000000000 +0100
     11601+++ linux-2.4.32-freewrt/drivers/net/hnd/linux_osl.c    2006-07-02 21:58:25.000000000 +0200
     11602@@ -0,0 +1,640 @@
    1869611603+/*
    1869711604+ * Linux OS Independent Layer
    1869811605+ *
    18699 + * Copyright 2006, Broadcom Corporation
     11606+ * Copyright 2004, Broadcom Corporation
    1870011607+ * All Rights Reserved.
    1870111608+ *
     
    1870511612+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    1870611613+ *
    18707 + * $Id: linux_osl.c,v 1.1.1.14 2006/04/08 06:13:39 honor Exp $
     11614+ * $Id$
    1870811615+ */
    1870911616+
     
    1871411621+#include <linux/module.h>
    1871511622+#include <linuxver.h>
    18716 +#include <bcmdefs.h>
    18717 +#include <osl.h>
    18718 +#include "linux_osl.h"
     11623+#include <linux_osl.h>
    1871911624+#include <bcmutils.h>
    1872011625+#include <linux/delay.h>
    1872111626+#ifdef mips
    1872211627+#include <asm/paccess.h>
    18723 +#endif /* mips */
     11628+#endif
    1872411629+#include <pcicfg.h>
    1872511630+
    1872611631+#define PCI_CFG_RETRY          10     
    1872711632+
    18728 +#define OS_HANDLE_MAGIC                0x1234abcd      /* Magic # to recognise osh */
    18729 +#define BCM_MEM_FILENAME_LEN   24              /* Mem. filename length */
     11633+#define OS_HANDLE_MAGIC                0x1234abcd
     11634+#define BCM_MEM_FILENAME_LEN   24
    1873011635+
    1873111636+typedef struct bcm_mem_link {
     
    1873711642+} bcm_mem_link_t;
    1873811643+
    18739 +static int16 linuxbcmerrormap[] =  \
    18740 +{      0,                      /* 0 */
    18741 +       -EINVAL,                /* BCME_ERROR */
    18742 +       -EINVAL,                /* BCME_BADARG */
    18743 +       -EINVAL,                /* BCME_BADOPTION */
    18744 +       -EINVAL,                /* BCME_NOTUP */
    18745 +       -EINVAL,                /* BCME_NOTDOWN */
    18746 +       -EINVAL,                /* BCME_NOTAP */
    18747 +       -EINVAL,                /* BCME_NOTSTA */
    18748 +       -EINVAL,                /* BCME_BADKEYIDX */
    18749 +       -EINVAL,                /* BCME_RADIOOFF */
    18750 +       -EINVAL,                /* BCME_NOTBANDLOCKED */
    18751 +       -EINVAL,                /* BCME_NOCLK */
    18752 +       -EINVAL,                /* BCME_BADRATESET */
    18753 +       -EINVAL,                /* BCME_BADBAND */
    18754 +       -E2BIG,                 /* BCME_BUFTOOSHORT */
    18755 +       -E2BIG,                 /* BCME_BUFTOOLONG */
    18756 +       -EBUSY,                 /* BCME_BUSY */
    18757 +       -EINVAL,                /* BCME_NOTASSOCIATED */
    18758 +       -EINVAL,                /* BCME_BADSSIDLEN */
    18759 +       -EINVAL,                /* BCME_OUTOFRANGECHAN */
    18760 +       -EINVAL,                /* BCME_BADCHAN */
    18761 +       -EFAULT,                /* BCME_BADADDR */
    18762 +       -ENOMEM,                /* BCME_NORESOURCE */
    18763 +       -EOPNOTSUPP,            /* BCME_UNSUPPORTED */
    18764 +       -EMSGSIZE,              /* BCME_BADLENGTH */
    18765 +       -EINVAL,                /* BCME_NOTREADY */
    18766 +       -EPERM,                 /* BCME_NOTPERMITTED */
    18767 +       -ENOMEM,                /* BCME_NOMEM */
    18768 +       -EINVAL,                /* BCME_ASSOCIATED */
    18769 +       -ERANGE,                /* BCME_RANGE */
    18770 +       -EINVAL,                /* BCME_NOTFOUND */
    18771 +       -EINVAL,                /* BCME_WME_NOT_ENABLED */
    18772 +       -EINVAL,                /* BCME_TSPEC_NOTFOUND */
    18773 +       -EINVAL,                /* BCME_ACM_NOTSUPPORTED */
    18774 +       -EINVAL,                /* BCME_NOT_WME_ASSOCIATION */
    18775 +       -EIO,                   /* BCME_SDIO_ERROR */
    18776 +       -ENODEV                 /* BCME_DONGLE_DOWN */
    18777 +};
    18778 +
    18779 +/* translate bcmerrors into linux errors */
    18780 +int
    18781 +osl_error(int bcmerror)
    18782 +{
    18783 +       int abs_bcmerror;
    18784 +       int array_size = ARRAYSIZE(linuxbcmerrormap);
    18785 +
    18786 +       abs_bcmerror = ABS(bcmerror);
    18787 +
    18788 +       if (bcmerror > 0)
    18789 +               abs_bcmerror = 0;
    18790 +
    18791 +       else if (abs_bcmerror >= array_size)
    18792 +               abs_bcmerror = BCME_ERROR;
    18793 +
    18794 +       return linuxbcmerrormap[abs_bcmerror];
    18795 +}
    18796 +
    18797 +osl_t *
    18798 +osl_attach(void *pdev, bool pkttag)
    18799 +{
    18800 +       osl_t *osh;
    18801 +
    18802 +       osh = kmalloc(sizeof(osl_t), GFP_ATOMIC);
     11644+typedef struct os_handle {
     11645+       uint magic;
     11646+       void *pdev;
     11647+       uint malloced;
     11648+       uint failed;
     11649+       bcm_mem_link_t *dbgmem_list;
     11650+} os_handle_t;
     11651+
     11652+void *
     11653+osl_attach(void *pdev)
     11654+{
     11655+       os_handle_t *osh;
     11656+
     11657+       osh = kmalloc(sizeof(os_handle_t), GFP_ATOMIC);
    1880311658+       ASSERT(osh);
    18804 +
    18805 +       bzero(osh, sizeof(osl_t));
    18806 +
    18807 +       /*
    18808 +        * check the cases where
    18809 +        * 1.Error code Added to bcmerror table, but forgot to add it to the OS
    18810 +        * dependent error code
    18811 +        * 2. Error code is added to the bcmerror table, but forgot to add the
    18812 +        * corresponding errorstring(dummy call to bcmerrorstr)
    18813 +        */
    18814 +       bcmerrorstr(0);
    18815 +       ASSERT(ABS(BCME_LAST) == (ARRAYSIZE(linuxbcmerrormap) - 1));
    1881611659+
    1881711660+       osh->magic = OS_HANDLE_MAGIC;
     
    1882011663+       osh->dbgmem_list = NULL;
    1882111664+       osh->pdev = pdev;
    18822 +       osh->pub.pkttag = pkttag;
    1882311665+
    1882411666+       return osh;
     
    1882611668+
    1882711669+void
    18828 +osl_detach(osl_t *osh)
    18829 +{
    18830 +       if (osh == NULL)
    18831 +               return;
    18832 +
    18833 +       ASSERT(osh->magic == OS_HANDLE_MAGIC);
     11670+osl_detach(void *osh)
     11671+{
     11672+       ASSERT((osh && (((os_handle_t *)osh)->magic == OS_HANDLE_MAGIC)));
    1883411673+       kfree(osh);
    1883511674+}
    1883611675+
    18837 +/* Return a new packet. zero out pkttag */
    1883811676+void*
    18839 +osl_pktget(osl_t *osh, uint len, bool send)
     11677+osl_pktget(void *drv, uint len, bool send)
    1884011678+{
    1884111679+       struct sk_buff *skb;
    1884211680+
    18843 +       if ((skb = dev_alloc_skb(len))) {
    18844 +               skb_put(skb, len);
    18845 +               skb->priority = 0;
    18846 +
    18847 +#ifdef BCMDBG_PKT
    18848 +       pktlist_add(&(osh->pktlist), (void *) skb);
    18849 +#endif  /* BCMDBG_PKT */
    18850 +
    18851 +               osh->pub.pktalloced++;
    18852 +       }
     11681+       if ((skb = dev_alloc_skb(len)) == NULL)
     11682+               return (NULL);
     11683+
     11684+       skb_put(skb, len);
     11685+
     11686+       /* ensure the cookie field is cleared */
     11687+       PKTSETCOOKIE(skb, NULL);
    1885311688+
    1885411689+       return ((void*) skb);
    1885511690+}
    1885611691+
    18857 +/* Free the driver packet. Free the tag if present */
    1885811692+void
    18859 +osl_pktfree(osl_t *osh, void *p)
     11693+osl_pktfree(void *p)
    1886011694+{
    1886111695+       struct sk_buff *skb, *nskb;
     
    1886711701+               nskb = skb->next;
    1886811702+               skb->next = NULL;
    18869 +
    18870 +#ifdef BCMDBG_PKT
    18871 +               pktlist_remove(&(osh->pktlist), (void *) skb);
    18872 +#endif  /* BCMDBG_PKT */
    18873 +
    1887411703+               if (skb->destructor) {
    18875 +                       /* cannot kfree_skb() on hard IRQ (net/core/skbuff.c) if destructor exists
    18876 +                        */
     11704+                       /* cannot kfree_skb() on hard IRQ (net/core/skbuff.c) if destructor exists */
    1887711705+                       dev_kfree_skb_any(skb);
    1887811706+               } else {
     
    1888011708+                       dev_kfree_skb(skb);
    1888111709+               }
    18882 +
    18883 +               osh->pub.pktalloced--;
    18884 +
    1888511710+               skb = nskb;
    1888611711+       }
    1888711712+}
    1888811713+
     11714+uint32
     11715+osl_pci_read_config(void *osh, uint offset, uint size)
     11716+{
     11717+       struct pci_dev *pdev;
     11718+       uint val;
     11719+       uint retry=PCI_CFG_RETRY;       
     11720+
     11721+       ASSERT((osh && (((os_handle_t *)osh)->magic == OS_HANDLE_MAGIC)));
     11722+
     11723+       /* only 4byte access supported */
     11724+       ASSERT(size == 4);
     11725+
     11726+       pdev = ((os_handle_t *)osh)->pdev;
     11727+       do {
     11728+               pci_read_config_dword(pdev, offset, &val);
     11729+               if (val != 0xffffffff)
     11730+                       break;
     11731+       } while (retry--);
     11732+
     11733+
     11734+       return (val);
     11735+}
     11736+
     11737+void
     11738+osl_pci_write_config(void *osh, uint offset, uint size, uint val)
     11739+{
     11740+       struct pci_dev *pdev;
     11741+       uint retry=PCI_CFG_RETRY;       
     11742+
     11743+       ASSERT((osh && (((os_handle_t *)osh)->magic == OS_HANDLE_MAGIC)));
     11744+
     11745+       /* only 4byte access supported */
     11746+       ASSERT(size == 4);
     11747+
     11748+       pdev = ((os_handle_t *)osh)->pdev;
     11749+
     11750+       do {
     11751+               pci_write_config_dword(pdev, offset, val);
     11752+               if (offset!=PCI_BAR0_WIN)
     11753+                       break;
     11754+               if (osl_pci_read_config(osh,offset,size) == val)
     11755+                       break;
     11756+       } while (retry--);
     11757+
     11758+}
     11759+
     11760+static void
     11761+osl_pcmcia_attr(void *osh, uint offset, char *buf, int size, bool write)
     11762+{
     11763+}
     11764+
     11765+void
     11766+osl_pcmcia_read_attr(void *osh, uint offset, void *buf, int size)
     11767+{
     11768+       osl_pcmcia_attr(osh, offset, (char *) buf, size, FALSE);
     11769+}
     11770+
     11771+void
     11772+osl_pcmcia_write_attr(void *osh, uint offset, void *buf, int size)
     11773+{
     11774+       osl_pcmcia_attr(osh, offset, (char *) buf, size, TRUE);
     11775+}
     11776+
     11777+
     11778+#ifdef BCMDBG_MEM
     11779+
    1888911780+void*
    18890 +osl_malloc(osl_t *osh, uint size)
    18891 +{
     11781+osl_debug_malloc(void *osh, uint size, int line, char* file)
     11782+{
     11783+       bcm_mem_link_t *p;
     11784+       char* basename;
     11785+       os_handle_t *h = (os_handle_t *)osh;
     11786+       
     11787+       if (size == 0) {
     11788+               return NULL;
     11789+       }
     11790+       
     11791+       p = (bcm_mem_link_t*)osl_malloc(osh, sizeof(bcm_mem_link_t) + size);
     11792+       if (p == NULL)
     11793+               return p;
     11794+       
     11795+       p->size = size;
     11796+       p->line = line;
     11797+       
     11798+       basename = strrchr(file, '/');
     11799+       /* skip the '/' */
     11800+       if (basename)
     11801+               basename++;
     11802+
     11803+       if (!basename)
     11804+               basename = file;
     11805+       
     11806+       strncpy(p->file, basename, BCM_MEM_FILENAME_LEN);
     11807+       p->file[BCM_MEM_FILENAME_LEN - 1] = '\0';
     11808+
     11809+       /* link this block */
     11810+       p->prev = NULL;
     11811+       p->next = h->dbgmem_list;
     11812+       if (p->next)
     11813+               p->next->prev = p;
     11814+       h->dbgmem_list = p;
     11815+
     11816+       return p + 1;
     11817+}
     11818+
     11819+void
     11820+osl_debug_mfree(void *osh, void *addr, uint size, int line, char* file)
     11821+{
     11822+       bcm_mem_link_t *p = (bcm_mem_link_t *)((int8*)addr - sizeof(bcm_mem_link_t));
     11823+       os_handle_t *h = (os_handle_t *)osh;
     11824+       
     11825+       ASSERT((h && (h->magic == OS_HANDLE_MAGIC)));
     11826+
     11827+       if (p->size == 0) {
     11828+               printk("osl_debug_mfree: double free on addr 0x%x size %d at line %d file %s\n",
     11829+                       (uint)addr, size, line, file);
     11830+               return;
     11831+       }
     11832+
     11833+       if (p->size != size) {
     11834+               printk("osl_debug_mfree: dealloc size %d does not match alloc size %d on addr 0x%x at line %d file %s\n",
     11835+                      size, p->size, (uint)addr, line, file);
     11836+               return;
     11837+       }
     11838+
     11839+       /* unlink this block */
     11840+       if (p->prev)
     11841+               p->prev->next = p->next;
     11842+       if (p->next)
     11843+               p->next->prev = p->prev;
     11844+       if (h->dbgmem_list == p)
     11845+               h->dbgmem_list = p->next;
     11846+       p->next = p->prev = NULL;
     11847+
     11848+       osl_mfree(osh, p, size + sizeof(bcm_mem_link_t));
     11849+}
     11850+
     11851+char*
     11852+osl_debug_memdump(void *osh, char *buf, uint sz)
     11853+{
     11854+       bcm_mem_link_t *p;
     11855+       char *obuf;
     11856+       os_handle_t *h = (os_handle_t *)osh;
     11857+
     11858+       ASSERT((h && (h->magic == OS_HANDLE_MAGIC)));
     11859+       obuf = buf;
     11860+
     11861+       buf += sprintf(buf, "   Address\tSize\tFile:line\n");
     11862+       for (p = h->dbgmem_list; p && ((buf - obuf) < (sz - 128)); p = p->next)
     11863+               buf += sprintf(buf, "0x%08x\t%5d\t%s:%d\n",
     11864+                       (int)p + sizeof(bcm_mem_link_t), p->size, p->file, p->line);
     11865+
     11866+       return (obuf);
     11867+}
     11868+
     11869+#endif /* BCMDBG_MEM */
     11870+
     11871+void*
     11872+osl_malloc(void *osh, uint size)
     11873+{
     11874+       os_handle_t *h = (os_handle_t *)osh;
    1889211875+       void *addr;
    1889311876+
    18894 +       /* only ASSERT if osh is defined */
    18895 +       if (osh)
    18896 +               ASSERT(osh->magic == OS_HANDLE_MAGIC);
    18897 +
    18898 +       if ((addr = kmalloc(size, GFP_ATOMIC)) == NULL) {
    18899 +               if (osh)
    18900 +                       osh->failed++;
    18901 +               return (NULL);
    18902 +       }
    18903 +       if (osh)
    18904 +               osh->malloced += size;
    18905 +
     11877+       ASSERT((h && (h->magic == OS_HANDLE_MAGIC)));
     11878+       h->malloced += size;
     11879+       addr = kmalloc(size, GFP_ATOMIC);
     11880+       if (!addr)
     11881+               h->failed++;
    1890611882+       return (addr);
    1890711883+}
    1890811884+
    1890911885+void
    18910 +osl_mfree(osl_t *osh, void *addr, uint size)
    18911 +{
    18912 +       if (osh) {
    18913 +               ASSERT(osh->magic == OS_HANDLE_MAGIC);
    18914 +               osh->malloced -= size;
    18915 +       }
     11886+osl_mfree(void *osh, void *addr, uint size)
     11887+{
     11888+       os_handle_t *h = (os_handle_t *)osh;
     11889+
     11890+       ASSERT((h && (h->magic == OS_HANDLE_MAGIC)));
     11891+       h->malloced -= size;
    1891611892+       kfree(addr);
    1891711893+}
    1891811894+
    1891911895+uint
    18920 +osl_malloced(osl_t *osh)
    18921 +{
    18922 +       ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
    18923 +       return (osh->malloced);
    18924 +}
    18925 +
    18926 +uint osl_malloc_failed(osl_t *osh)
    18927 +{
    18928 +       ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
    18929 +       return (osh->failed);
    18930 +}
    18931 +
    18932 +#undef osl_delay
     11896+osl_malloced(void *osh)
     11897+{
     11898+       os_handle_t *h = (os_handle_t *)osh;
     11899+
     11900+       ASSERT((h && (h->magic == OS_HANDLE_MAGIC)));
     11901+       return (h->malloced);
     11902+}
     11903+
     11904+uint osl_malloc_failed(void *osh)
     11905+{
     11906+       os_handle_t *h = (os_handle_t *)osh;
     11907+
     11908+       ASSERT((h && (h->magic == OS_HANDLE_MAGIC)));
     11909+       return (h->failed);
     11910+}
     11911+
     11912+void*
     11913+osl_dma_alloc_consistent(void *osh, uint size, ulong *pap)
     11914+{
     11915+       struct pci_dev *dev;
     11916+
     11917+       ASSERT((osh && (((os_handle_t *)osh)->magic == OS_HANDLE_MAGIC)));
     11918+
     11919+       dev = ((os_handle_t *)osh)->pdev;
     11920+       return (pci_alloc_consistent(dev, size, (dma_addr_t*)pap));
     11921+}
     11922+
     11923+void
     11924+osl_dma_free_consistent(void *osh, void *va, uint size, ulong pa)
     11925+{
     11926+       struct pci_dev *dev;
     11927+
     11928+       ASSERT((osh && (((os_handle_t *)osh)->magic == OS_HANDLE_MAGIC)));
     11929+
     11930+       dev = ((os_handle_t *)osh)->pdev;
     11931+       pci_free_consistent(dev, size, va, (dma_addr_t)pa);
     11932+}
     11933+
     11934+uint
     11935+osl_dma_map(void *osh, void *va, uint size, int direction)
     11936+{
     11937+       int dir;
     11938+       struct pci_dev *dev;
     11939+
     11940+       ASSERT((osh && (((os_handle_t *)osh)->magic == OS_HANDLE_MAGIC)));
     11941+
     11942+       dev = ((os_handle_t *)osh)->pdev;
     11943+       dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
     11944+       return (pci_map_single(dev, va, size, dir));
     11945+}
     11946+
     11947+void
     11948+osl_dma_unmap(void *osh, uint pa, uint size, int direction)
     11949+{
     11950+       int dir;
     11951+       struct pci_dev *dev;
     11952+
     11953+       ASSERT((osh && (((os_handle_t *)osh)->magic == OS_HANDLE_MAGIC)));
     11954+
     11955+       dev = ((os_handle_t *)osh)->pdev;
     11956+       dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
     11957+       pci_unmap_single(dev, (uint32)pa, size, dir);
     11958+}
     11959+
     11960+#if defined(BINOSL)
     11961+void
     11962+osl_assert(char *exp, char *file, int line)
     11963+{
     11964+       char tempbuf[255];
     11965+
     11966+       sprintf(tempbuf, "assertion \"%s\" failed: file \"%s\", line %d\n", exp, file, line);
     11967+       panic(tempbuf);
     11968+}
     11969+#endif /* BCMDBG || BINOSL */
     11970+
     11971+/*
     11972+ * BINOSL selects the slightly slower function-call-based binary compatible osl.
     11973+ */
     11974+#ifdef BINOSL
     11975+
     11976+int
     11977+osl_printf(const char *format, ...)
     11978+{
     11979+       va_list args;
     11980+       char buf[1024];
     11981+       int len;
     11982+
     11983+       /* sprintf into a local buffer because there *is* no "vprintk()".. */
     11984+       va_start(args, format);
     11985+       len = vsprintf(buf, format, args);
     11986+       va_end(args);
     11987+
     11988+       if (len > sizeof (buf)) {
     11989+               printk("osl_printf: buffer overrun\n");
     11990+               return (0);
     11991+       }
     11992+
     11993+       return (printk(buf));
     11994+}
     11995+
     11996+int
     11997+osl_sprintf(char *buf, const char *format, ...)
     11998+{
     11999+       va_list args;
     12000+       int rc;
     12001+
     12002+       va_start(args, format);
     12003+       rc = vsprintf(buf, format, args);
     12004+       va_end(args);
     12005+       return (rc);
     12006+}
     12007+
     12008+int
     12009+osl_strcmp(const char *s1, const char *s2)
     12010+{
     12011+       return (strcmp(s1, s2));
     12012+}
     12013+
     12014+int
     12015+osl_strncmp(const char *s1, const char *s2, uint n)
     12016+{
     12017+       return (strncmp(s1, s2, n));
     12018+}
     12019+
     12020+int
     12021+osl_strlen(char *s)
     12022+{
     12023+       return (strlen(s));
     12024+}
     12025+
     12026+char*
     12027+osl_strcpy(char *d, const char *s)
     12028+{
     12029+       return (strcpy(d, s));
     12030+}
     12031+
     12032+char*
     12033+osl_strncpy(char *d, const char *s, uint n)
     12034+{
     12035+       return (strncpy(d, s, n));
     12036+}
     12037+
     12038+void
     12039+bcopy(const void *src, void *dst, int len)
     12040+{
     12041+       memcpy(dst, src, len);
     12042+}
     12043+
     12044+int
     12045+bcmp(const void *b1, const void *b2, int len)
     12046+{
     12047+       return (memcmp(b1, b2, len));
     12048+}
     12049+
     12050+void
     12051+bzero(void *b, int len)
     12052+{
     12053+       memset(b, '\0', len);
     12054+}
     12055+
     12056+uint32
     12057+osl_readl(volatile uint32 *r)
     12058+{
     12059+       return (readl(r));
     12060+}
     12061+
     12062+uint16
     12063+osl_readw(volatile uint16 *r)
     12064+{
     12065+       return (readw(r));
     12066+}
     12067+
     12068+uint8
     12069+osl_readb(volatile uint8 *r)
     12070+{
     12071+       return (readb(r));
     12072+}
     12073+
     12074+void
     12075+osl_writel(uint32 v, volatile uint32 *r)
     12076+{
     12077+       writel(v, r);
     12078+}
     12079+
     12080+void
     12081+osl_writew(uint16 v, volatile uint16 *r)
     12082+{
     12083+       writew(v, r);
     12084+}
     12085+
     12086+void
     12087+osl_writeb(uint8 v, volatile uint8 *r)
     12088+{
     12089+       writeb(v, r);
     12090+}
     12091+
     12092+void *
     12093+osl_uncached(void *va)
     12094+{
     12095+#ifdef mips
     12096+       return ((void*)KSEG1ADDR(va));
     12097+#else
     12098+       return ((void*)va);
     12099+#endif
     12100+}
     12101+
     12102+uint
     12103+osl_getcycles(void)
     12104+{
     12105+       uint cycles;
     12106+
     12107+#if defined(mips)
     12108+       cycles = read_c0_count() * 2;
     12109+#elif defined(__i386__)
     12110+       rdtscl(cycles);
     12111+#else
     12112+       cycles = 0;
     12113+#endif
     12114+       return cycles;
     12115+}
     12116+
     12117+void *
     12118+osl_reg_map(uint32 pa, uint size)
     12119+{
     12120+       return (ioremap_nocache((unsigned long)pa, (unsigned long)size));
     12121+}
     12122+
     12123+void
     12124+osl_reg_unmap(void *va)
     12125+{
     12126+       iounmap(va);
     12127+}
     12128+
     12129+int
     12130+osl_busprobe(uint32 *val, uint32 addr)
     12131+{
     12132+#ifdef mips
     12133+       return get_dbe(*val, (uint32*)addr);
     12134+#else
     12135+       *val = readl(addr);
     12136+       return 0;
     12137+#endif
     12138+}
     12139+
    1893312140+void
    1893412141+osl_delay(uint usec)
    1893512142+{
    18936 +       OSL_DELAY(usec);
    18937 +}
    18938 +
    18939 +/* Clone a packet.
    18940 + * The pkttag contents are NOT cloned.
    18941 + */
    18942 +void *
    18943 +osl_pktdup(osl_t *osh, void *skb)
    18944 +{
    18945 +       void * p;
    18946 +
    18947 +       if ((p = skb_clone((struct sk_buff*)skb, GFP_ATOMIC)) == NULL)
    18948 +               return NULL;
    18949 +
    18950 +       /* skb_clone copies skb->cb.. we don't want that */
    18951 +       if (osh->pub.pkttag)
    18952 +               bzero((void*)((struct sk_buff *)p)->cb, OSL_PKTTAG_SZ);
    18953 +
    18954 +       /* Increment the packet counter */
    18955 +       osh->pub.pktalloced++;
    18956 +       return (p);
     12143+       udelay(usec);
     12144+}
     12145+
     12146+uchar*
     12147+osl_pktdata(void *drv, void *skb)
     12148+{
     12149+       return (((struct sk_buff*)skb)->data);
    1895712150+}
    1895812151+
    1895912152+uint
    18960 +osl_pktalloced(osl_t *osh)
    18961 +{
    18962 +       return (osh->pub.pktalloced);
    18963 +}
    18964 +
    18965 diff -urN linux.old/drivers/net/wl/linux_osl.h linux.dev/drivers/net/wl/linux_osl.h
    18966 --- linux.old/drivers/net/wl/linux_osl.h        1970-01-01 01:00:00.000000000 +0100
    18967 +++ linux.dev/drivers/net/wl/linux_osl.h        2006-05-02 17:44:29.000000000 +0200
    18968 @@ -0,0 +1,171 @@
     12153+osl_pktlen(void *drv, void *skb)
     12154+{
     12155+       return (((struct sk_buff*)skb)->len);
     12156+}
     12157+
     12158+uint
     12159+osl_pktheadroom(void *drv, void *skb)
     12160+{
     12161+       return (uint) skb_headroom((struct sk_buff *) skb);
     12162+}
     12163+
     12164+uint
     12165+osl_pkttailroom(void *drv, void *skb)
     12166+{
     12167+       return (uint) skb_tailroom((struct sk_buff *) skb);
     12168+}
     12169+
     12170+void*
     12171+osl_pktnext(void *drv, void *skb)
     12172+{
     12173+       return (((struct sk_buff*)skb)->next);
     12174+}
     12175+
     12176+void
     12177+osl_pktsetnext(void *skb, void *x)
     12178+{
     12179+       ((struct sk_buff*)skb)->next = (struct sk_buff*)x;
     12180+}
     12181+
     12182+void
     12183+osl_pktsetlen(void *drv, void *skb, uint len)
     12184+{
     12185+       __skb_trim((struct sk_buff*)skb, len);
     12186+}
     12187+
     12188+uchar*
     12189+osl_pktpush(void *drv, void *skb, int bytes)
     12190+{
     12191+       return (skb_push((struct sk_buff*)skb, bytes));
     12192+}
     12193+
     12194+uchar*
     12195+osl_pktpull(void *drv, void *skb, int bytes)
     12196+{
     12197+       return (skb_pull((struct sk_buff*)skb, bytes));
     12198+}
     12199+
     12200+void*
     12201+osl_pktdup(void *drv, void *skb)
     12202+{
     12203+       return (skb_clone((struct sk_buff*)skb, GFP_ATOMIC));
     12204+}
     12205+
     12206+void*
     12207+osl_pktcookie(void *skb)
     12208+{
     12209+       return ((void*)((struct sk_buff*)skb)->csum);
     12210+}
     12211+
     12212+void
     12213+osl_pktsetcookie(void *skb, void *x)
     12214+{
     12215+       ((struct sk_buff*)skb)->csum = (uint)x;
     12216+}
     12217+
     12218+void*
     12219+osl_pktlink(void *skb)
     12220+{
     12221+       return (((struct sk_buff*)skb)->prev);
     12222+}
     12223+
     12224+void
     12225+osl_pktsetlink(void *skb, void *x)
     12226+{
     12227+       ((struct sk_buff*)skb)->prev = (struct sk_buff*)x;
     12228+}
     12229+
     12230+uint
     12231+osl_pktprio(void *skb)
     12232+{
     12233+       return (((struct sk_buff*)skb)->priority);
     12234+}
     12235+
     12236+void
     12237+osl_pktsetprio(void *skb, uint x)
     12238+{
     12239+       ((struct sk_buff*)skb)->priority = x;
     12240+}
     12241+
     12242+#endif /* BINOSL */
     12243diff -Nur linux-2.4.32/drivers/net/hnd/sbutils.c linux-2.4.32-freewrt/drivers/net/hnd/sbutils.c
     12244--- linux-2.4.32/drivers/net/hnd/sbutils.c      1970-01-01 01:00:00.000000000 +0100
     12245+++ linux-2.4.32-freewrt/drivers/net/hnd/sbutils.c      2006-07-02 21:58:25.000000000 +0200
     12246@@ -0,0 +1,2061 @@
    1896912247+/*
    18970 + * Linux OS Independent Layer
     12248+ * Misc utility routines for accessing chip-specific features
     12249+ * of the SiliconBackplane-based Broadcom chips.
    1897112250+ *
    18972 + * Copyright 2006, Broadcom Corporation
     12251+ * Copyright 2005, Broadcom Corporation
    1897312252+ * All Rights Reserved.
    1897412253+ *
     
    1897712256+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    1897812257+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    18979 + *
    18980 + * $Id: linux_osl.h,v 1.1.1.13 2006/04/08 06:13:39 honor Exp $
     12258+ * $Id: sbutils.c,v 1.6 2005/03/07 08:35:32 kanki Exp $
    1898112259+ */
    1898212260+
    18983 +#ifndef _linux_osl_h_
    18984 +#define _linux_osl_h_
    18985 +
    1898612261+#include <typedefs.h>
    18987 +#include <linuxver.h>
    1898812262+#include <osl.h>
    18989 +
    18990 +#define OSL_PKTTAG_SZ     32 /* Size of PktTag */
    18991 +
    18992 +/* osl handle type forward declaration */
    18993 +typedef struct osl_dmainfo osldma_t;
    18994 +
    18995 +/* OSL initialization */
    18996 +extern osl_t *osl_attach(void *pdev, bool pkttag);
    18997 +extern void osl_detach(osl_t *osh);
    18998 +
    18999 +/* host/bus architecture-specific byte swap */
    19000 +#define BUS_SWAP32(v)          (v)
    19001 +#define        MALLOC_FAILED(osh)      osl_malloc_failed((osh))
    19002 +
    19003 +extern void *osl_malloc(osl_t *osh, uint size);
    19004 +extern void osl_mfree(osl_t *osh, void *addr, uint size);
    19005 +extern uint osl_malloced(osl_t *osh);
    19006 +extern uint osl_malloc_failed(osl_t *osh);
    19007 +
    19008 +/* API for DMA addressing capability */
    19009 +#define        DMA_MAP(osh, va, size, direction, p) \
    19010 +       osl_dma_map((osh), (va), (size), (direction))
    19011 +#define        DMA_UNMAP(osh, pa, size, direction, p) \
    19012 +       osl_dma_unmap((osh), (pa), (size), (direction))
    19013 +static inline uint
    19014 +osl_dma_map(void *osh, void *va, uint size, int direction)
    19015 +{
    19016 +       int dir;
    19017 +       struct pci_dev *dev;
    19018 +
    19019 +       dev = (osh == NULL ? NULL : ((osl_t *)osh)->pdev);
    19020 +       dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
    19021 +       return (pci_map_single(dev, va, size, dir));
    19022 +}
    19023 +
    19024 +static inline void
    19025 +osl_dma_unmap(void *osh, uint pa, uint size, int direction)
    19026 +{
    19027 +       int dir;
    19028 +       struct pci_dev *dev;
    19029 +
    19030 +       dev = (osh == NULL ? NULL : ((osl_t *)osh)->pdev);
    19031 +       dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
    19032 +       pci_unmap_single(dev, (uint32)pa, size, dir);
    19033 +}
    19034 +
    19035 +#define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
    19036 +#define        DMA_CONSISTENT_ALIGN    PAGE_SIZE
    19037 +#define        DMA_ALLOC_CONSISTENT(osh, size, pap, dmah) \
    19038 +       osl_dma_alloc_consistent((osh), (size), (pap))
    19039 +#define        DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
    19040 +       osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
    19041 +static inline void*
    19042 +osl_dma_alloc_consistent(osl_t *osh, uint size, ulong *pap)
    19043 +{
    19044 +       return (pci_alloc_consistent(osh->pdev, size, (dma_addr_t*)pap));
    19045 +}
    19046 +
    19047 +static inline void
    19048 +osl_dma_free_consistent(osl_t *osh, void *va, uint size, ulong pa)
    19049 +{
    19050 +       pci_free_consistent(osh->pdev, size, va, (dma_addr_t)pa);
    19051 +}
    19052 +
    19053 +
    19054 +/* register access macros */
    19055 +#if defined(BCMJTAG)
    19056 +#include <bcmjtag.h>
    19057 +#define        R_REG(osh, r)   bcmjtag_read(NULL, (uint32)(r), sizeof(*(r)))
    19058 +#define        W_REG(osh, r, v)        bcmjtag_write(NULL, (uint32)(r), (uint32)(v), sizeof(*(r)))
    19059 +#endif /* defined(BCMSDIO) */
    19060 +
    19061 +/* packet primitives */
    19062 +#define        PKTGET(osh, len, send)          osl_pktget((osh), (len), (send))
    19063 +#define        PKTFREE(osh, skb, send)         osl_pktfree((osh), (skb))
    19064 +#define        PKTDATA(osh, skb)               (((struct sk_buff*)(skb))->data)
    19065 +#define        PKTLEN(osh, skb)                (((struct sk_buff*)(skb))->len)
    19066 +#define PKTHEADROOM(osh, skb)          (PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head))
    19067 +#define PKTTAILROOM(osh, skb) ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
    19068 +#define        PKTNEXT(osh, skb)               (((struct sk_buff*)(skb))->next)
    19069 +#define        PKTSETNEXT(osh, skb, x)         (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
    19070 +#define        PKTSETLEN(osh, skb, len)        __skb_trim((struct sk_buff*)(skb), (len))
    19071 +#define        PKTPUSH(osh, skb, bytes)        skb_push((struct sk_buff*)(skb), (bytes))
    19072 +#define        PKTPULL(osh, skb, bytes)        skb_pull((struct sk_buff*)(skb), (bytes))
    19073 +#define        PKTDUP(osh, skb)                osl_pktdup((osh), (skb))
    19074 +#define        PKTTAG(skb)                     ((void*)(((struct sk_buff*)(skb))->cb))
    19075 +#define PKTALLOCED(osh)                        osl_pktalloced((osh))
    19076 +#define PKTLIST_DUMP(osh, buf)
    19077 +
    19078 +/* Convert a native(OS) packet to driver packet.
    19079 + * In the process, native packet is destroyed, there is no copying
    19080 + * Also, a packettag is zeroed out
     12263+#include <bcmutils.h>
     12264+#include <bcmdevs.h>
     12265+#include <sbconfig.h>
     12266+#include <sbchipc.h>
     12267+#include <sbpci.h>
     12268+#include <pcicfg.h>
     12269+#include <sbpcmcia.h>
     12270+#include <sbextif.h>
     12271+#include <sbutils.h>
     12272+#include <bcmsrom.h>
     12273+
     12274+/* debug/trace */
     12275+#define        SB_ERROR(args)
     12276+
     12277+
     12278+typedef uint32 (*sb_intrsoff_t)(void *intr_arg);
     12279+typedef void (*sb_intrsrestore_t)(void *intr_arg, uint32 arg);
     12280+typedef bool (*sb_intrsenabled_t)(void *intr_arg);
     12281+
     12282+/* misc sb info needed by some of the routines */
     12283+typedef struct sb_info {
     12284+       uint    chip;                   /* chip number */
     12285+       uint    chiprev;                /* chip revision */
     12286+       uint    chippkg;                /* chip package option */
     12287+       uint    boardtype;              /* board type */
     12288+       uint    boardvendor;            /* board vendor id */
     12289+       uint    bustype;                /* what bus type we are going through */
     12290+
     12291+       void    *osh;                   /* osl os handle */
     12292+       void    *sdh;                   /* bcmsdh handle */
     12293+
     12294+       void    *curmap;                /* current regs va */
     12295+       void    *regs[SB_MAXCORES];     /* other regs va */
     12296+
     12297+       uint    curidx;                 /* current core index */
     12298+       uint    dev_coreid;             /* the core provides driver functions */
     12299+       uint    pciidx;                 /* pci core index */
     12300+       uint    pcirev;                 /* pci core rev */
     12301+
     12302+       uint    pcmciaidx;              /* pcmcia core index */
     12303+       uint    pcmciarev;              /* pcmcia core rev */
     12304+       bool    memseg;                 /* flag to toggle MEM_SEG register */
     12305+
     12306+       uint    ccrev;                  /* chipc core rev */
     12307+
     12308+       uint    gpioidx;                /* gpio control core index */
     12309+       uint    gpioid;                 /* gpio control coretype */
     12310+
     12311+       uint    numcores;               /* # discovered cores */
     12312+       uint    coreid[SB_MAXCORES];    /* id of each core */
     12313+
     12314+       void    *intr_arg;              /* interrupt callback function arg */
     12315+       sb_intrsoff_t           intrsoff_fn;            /* function turns chip interrupts off */
     12316+       sb_intrsrestore_t       intrsrestore_fn;        /* function restore chip interrupts */
     12317+       sb_intrsenabled_t       intrsenabled_fn;        /* function to check if chip interrupts are enabled */
     12318+} sb_info_t;
     12319+
     12320+/* local prototypes */
     12321+static void* BCMINIT(sb_doattach)(sb_info_t *si, uint devid, void *osh, void *regs, uint bustype, void *sdh, char **vars, int *varsz);
     12322+static void BCMINIT(sb_scan)(sb_info_t *si);
     12323+static uint sb_corereg(void *sbh, uint coreidx, uint regoff, uint mask, uint val);
     12324+static uint _sb_coreidx(void *sbh);
     12325+static uint sb_findcoreidx(void *sbh, uint coreid, uint coreunit);
     12326+static uint BCMINIT(sb_pcidev2chip)(uint pcidev);
     12327+static uint BCMINIT(sb_chip2numcores)(uint chip);
     12328+
     12329+#define        SB_INFO(sbh)    (sb_info_t*)sbh
     12330+#define        SET_SBREG(sbh, r, mask, val)    W_SBREG((sbh), (r), ((R_SBREG((sbh), (r)) & ~(mask)) | (val)))
     12331+#define        GOODCOREADDR(x) (((x) >= SB_ENUM_BASE) && ((x) <= SB_ENUM_LIM) && ISALIGNED((x), SB_CORE_SIZE))
     12332+#define        GOODREGS(regs)  ((regs) && ISALIGNED((uintptr)(regs), SB_CORE_SIZE))
     12333+#define        REGS2SB(va)     (sbconfig_t*) ((int8*)(va) + SBCONFIGOFF)
     12334+#define        GOODIDX(idx)    (((uint)idx) < SB_MAXCORES)
     12335+#define        BADIDX          (SB_MAXCORES+1)
     12336+#define        NOREV           (SBIDH_RC_MASK + 1)
     12337+
     12338+#define        R_SBREG(sbh, sbr)       sb_read_sbreg((sbh), (sbr))
     12339+#define        W_SBREG(sbh, sbr, v)    sb_write_sbreg((sbh), (sbr), (v))
     12340+#define        AND_SBREG(sbh, sbr, v)  W_SBREG((sbh), (sbr), (R_SBREG((sbh), (sbr)) & (v)))
     12341+#define        OR_SBREG(sbh, sbr, v)   W_SBREG((sbh), (sbr), (R_SBREG((sbh), (sbr)) | (v)))
     12342+
     12343+/*
     12344+ * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts before/
     12345+ * after core switching to avoid invalid register accesss inside ISR.
    1908112346+ */
    19082 +static INLINE void *
    19083 +osl_pkt_frmnative(struct osl_pubinfo *osh, struct sk_buff *skb)
    19084 +{
    19085 +       struct sk_buff *nskb;
    19086 +
    19087 +       if (osh->pkttag)
    19088 +               bzero((void*)skb->cb, OSL_PKTTAG_SZ);
    19089 +
    19090 +       /* Increment the packet counter */
    19091 +       for (nskb = skb; nskb; nskb = nskb->next) {
    19092 +               osh->pktalloced++;
    19093 +       }
    19094 +
    19095 +       return (void *)skb;
    19096 +}
    19097 +#define PKTFRMNATIVE(osh, skb) osl_pkt_frmnative(((struct osl_pubinfo *)osh), \
    19098 +                                                       (struct sk_buff*)(skb))
    19099 +
    19100 +/* Convert a driver packet to native(OS) packet
    19101 + * In the process, packettag is zeroed out before sending up
    19102 + * IP code depends on skb->cb to be setup correctly with various options
    19103 + * In our case, that means it should be 0
     12347+#define INTR_OFF(si, intr_val) \
     12348+       if ((si)->intrsoff_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) {      \
     12349+               intr_val = (*(si)->intrsoff_fn)((si)->intr_arg); }
     12350+#define INTR_RESTORE(si, intr_val) \
     12351+       if ((si)->intrsrestore_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) {  \
     12352+               (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val); }
     12353+
     12354+/* power control defines */
     12355+#define        LPOMINFREQ      25000                   /* low power oscillator min */
     12356+#define        LPOMAXFREQ      43000                   /* low power oscillator max */
     12357+#define        XTALMINFREQ     19800000                /* 20mhz - 1% */
     12358+#define        XTALMAXFREQ     20200000                /* 20mhz + 1% */
     12359+#define        PCIMINFREQ      25000000                /* 25mhz */
     12360+#define        PCIMAXFREQ      34000000                /* 33mhz + fudge */
     12361+#define SCC_DEF_DIV    0                       /* default slow clock divider */
     12362+
     12363+#define XTAL_ON_DELAY          1000    /* Xtal power on delay in us */
     12364+
     12365+#define SCC_LOW2FAST_LIMIT     5000    /* turn on fast clock time, in unit of ms */
     12366+
     12367+static uint32
     12368+sb_read_sbreg(void *sbh, volatile uint32 *sbr)
     12369+{
     12370+       sb_info_t *si;
     12371+       uint8 tmp;
     12372+       uint32 val, intr_val = 0;
     12373+
     12374+       si = SB_INFO(sbh);
     12375+
     12376+       /*
     12377+        * compact flash only has 11 bits address, while we needs 12 bits address.
     12378+        * MEM_SEG will be OR'd with other 11 bits address in hardware,
     12379+        * so we program MEM_SEG with 12th bit when necessary(access sb regsiters).
     12380+        * For normal PCMCIA bus(CFTable_regwinsz > 2k), do nothing special
     12381+        */
     12382+       if(si->memseg) {
     12383+               INTR_OFF(si, intr_val);
     12384+               tmp = 1;
     12385+               OSL_PCMCIA_WRITE_ATTR(si->osh, MEM_SEG, &tmp, 1);
     12386+               (uintptr)sbr &= ~(1 << 11);     /* mask out bit 11*/
     12387+       }
     12388+
     12389+       val = R_REG(sbr);
     12390+
     12391+       if(si->memseg) {
     12392+               tmp = 0;
     12393+               OSL_PCMCIA_WRITE_ATTR(si->osh, MEM_SEG, &tmp, 1);
     12394+               INTR_RESTORE(si, intr_val);
     12395+       }
     12396+
     12397+       return (val);
     12398+}
     12399+
     12400+static void
     12401+sb_write_sbreg(void *sbh, volatile uint32 *sbr, uint32 v)
     12402+{
     12403+       sb_info_t *si;
     12404+       uint8 tmp;
     12405+       volatile uint32 dummy;
     12406+       uint32 intr_val = 0;
     12407+
     12408+       si = SB_INFO(sbh);
     12409+
     12410+       /*
     12411+        * compact flash only has 11 bits address, while we needs 12 bits address.
     12412+        * MEM_SEG will be OR'd with other 11 bits address in hardware,
     12413+        * so we program MEM_SEG with 12th bit when necessary(access sb regsiters).
     12414+        * For normal PCMCIA bus(CFTable_regwinsz > 2k), do nothing special
     12415+        */
     12416+       if(si->memseg) {
     12417+               INTR_OFF(si, intr_val);
     12418+               tmp = 1;
     12419+               OSL_PCMCIA_WRITE_ATTR(si->osh, MEM_SEG, &tmp, 1);
     12420+               (uintptr)sbr &= ~(1 << 11);     /* mask out bit 11 */
     12421+       }
     12422+
     12423+       if (BUSTYPE(si->bustype) == PCMCIA_BUS) {
     12424+#ifdef IL_BIGENDIAN
     12425+               dummy = R_REG(sbr);
     12426+               W_REG(((volatile uint16 *)sbr + 1), (uint16)((v >> 16) & 0xffff));
     12427+               dummy = R_REG(sbr);
     12428+               W_REG((volatile uint16 *)sbr, (uint16)(v & 0xffff));
     12429+#else
     12430+               dummy = R_REG(sbr);
     12431+               W_REG((volatile uint16 *)sbr, (uint16)(v & 0xffff));
     12432+               dummy = R_REG(sbr);
     12433+               W_REG(((volatile uint16 *)sbr + 1), (uint16)((v >> 16) & 0xffff));
     12434+#endif
     12435+       } else
     12436+               W_REG(sbr, v);
     12437+
     12438+       if(si->memseg) {
     12439+               tmp = 0;
     12440+               OSL_PCMCIA_WRITE_ATTR(si->osh, MEM_SEG, &tmp, 1);
     12441+               INTR_RESTORE(si, intr_val);
     12442+       }
     12443+}
     12444+
     12445+/*
     12446+ * Allocate a sb handle.
     12447+ * devid - pci device id (used to determine chip#)
     12448+ * osh - opaque OS handle
     12449+ * regs - virtual address of initial core registers
     12450+ * bustype - pci/pcmcia/sb/sdio/etc
     12451+ * vars - pointer to a pointer area for "environment" variables
     12452+ * varsz - pointer to int to return the size of the vars
    1910412453+ */
    19105 +static INLINE struct sk_buff *
    19106 +osl_pkt_tonative(struct osl_pubinfo *osh, void *pkt)
    19107 +{
    19108 +       struct sk_buff *nskb;
    19109 +
    19110 +       if (osh->pkttag)
    19111 +               bzero(((struct sk_buff*)pkt)->cb, OSL_PKTTAG_SZ);
    19112 +
    19113 +       /* Decrement the packet counter */
    19114 +       for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
    19115 +               osh->pktalloced--;
    19116 +       }
    19117 +
    19118 +       return (struct sk_buff *)pkt;
    19119 +}
    19120 +#define PKTTONATIVE(osh, pkt)          osl_pkt_tonative((struct osl_pubinfo *)(osh), (pkt))
    19121 +
    19122 +#define        PKTLINK(skb)                    (((struct sk_buff*)(skb))->prev)
    19123 +#define        PKTSETLINK(skb, x)              (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
    19124 +#define        PKTPRIO(skb)                    (((struct sk_buff*)(skb))->priority)
    19125 +#define        PKTSETPRIO(skb, x)              (((struct sk_buff*)(skb))->priority = (x))
    19126 +#define PKTSHARED(skb)                  (((struct sk_buff*)(skb))->cloned)
    19127 +
    19128 +extern void *osl_pktget(osl_t *osh, uint len, bool send);
    19129 +extern void osl_pktfree(osl_t *osh, void *skb);
    19130 +extern void *osl_pktdup(osl_t *osh, void *skb);
    19131 +extern uint osl_pktalloced(osl_t *osh);
    19132 +
    19133 +#define OSL_ERROR(bcmerror)    osl_error(bcmerror)
    19134 +extern int osl_error(int bcmerror);
    19135 +
    19136 +/* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
    19137 +#define        PKTBUFSZ        2048   /* largest reasonable packet buffer, driver uses for ethernet MTU */
    19138 +
    19139 +#endif /* _linux_osl_h_ */
    19140 diff -urN linux.old/drivers/net/wl/pktq.h linux.dev/drivers/net/wl/pktq.h
    19141 --- linux.old/drivers/net/wl/pktq.h     1970-01-01 01:00:00.000000000 +0100
    19142 +++ linux.dev/drivers/net/wl/pktq.h     2006-04-28 02:11:49.000000000 +0200
    19143 @@ -0,0 +1,97 @@
     12454+void*
     12455+BCMINITFN(sb_attach)(uint devid, void *osh, void *regs, uint bustype, void *sdh, char **vars, int *varsz)
     12456+{
     12457+       sb_info_t *si;
     12458+
     12459+       /* alloc sb_info_t */
     12460+       if ((si = MALLOC(osh, sizeof (sb_info_t))) == NULL) {
     12461+               SB_ERROR(("sb_attach: malloc failed! malloced %d bytes\n", MALLOCED(osh)));
     12462+               return (NULL);
     12463+       }
     12464+
     12465+       if (BCMINIT(sb_doattach)(si, devid, osh, regs, bustype, sdh, vars, varsz) == NULL) {
     12466+               MFREE(osh, si, sizeof (sb_info_t));
     12467+               return (NULL);
     12468+       }
     12469+       return si;
     12470+}
     12471+
     12472+/* Using sb_kattach depends on SB_BUS support, either implicit  */
     12473+/* no limiting BCMBUSTYPE value) or explicit (value is SB_BUS). */
     12474+#if !defined(BCMBUSTYPE) || (BCMBUSTYPE == SB_BUS)
     12475+
     12476+/* global kernel resource */
     12477+static sb_info_t ksi;
     12478+
     12479+/* generic kernel variant of sb_attach() */
     12480+void*
     12481+BCMINITFN(sb_kattach)()
     12482+{
     12483+       uint32 *regs;
     12484+       char *unused;
     12485+       int varsz;
     12486+
     12487+       if (ksi.curmap == NULL) {
     12488+               uint32 cid;
     12489+
     12490+               regs = (uint32 *)REG_MAP(SB_ENUM_BASE, SB_CORE_SIZE);
     12491+               cid = R_REG((uint32 *)regs);
     12492+               if (((cid & CID_ID_MASK) == BCM4712_DEVICE_ID) &&
     12493+                   ((cid & CID_PKG_MASK) != BCM4712LARGE_PKG_ID) &&
     12494+                   ((cid & CID_REV_MASK) <= (3 << CID_REV_SHIFT))) {
     12495+                       uint32 *scc, val;
     12496+
     12497+                       scc = (uint32 *)((uchar*)regs + OFFSETOF(chipcregs_t, slow_clk_ctl));
     12498+                       val = R_REG(scc);
     12499+                       SB_ERROR(("    initial scc = 0x%x\n", val));
     12500+                       val |= SCC_SS_XTAL;
     12501+                       W_REG(scc, val);
     12502+               }
     12503+
     12504+               if (BCMINIT(sb_doattach)(&ksi, BCM4710_DEVICE_ID, NULL, (void*)regs,
     12505+                       SB_BUS, NULL, &unused, &varsz) == NULL) {
     12506+                       return NULL;
     12507+               }
     12508+       }
     12509+
     12510+       return &ksi;
     12511+}
     12512+#endif
     12513+
     12514+static void*
     12515+BCMINITFN(sb_doattach)(sb_info_t *si, uint devid, void *osh, void *regs, uint bustype, void *sdh, char **vars, int *varsz)
     12516+{
     12517+       uint origidx;
     12518+       chipcregs_t *cc;
     12519+       uint32 w;
     12520+       int res;
     12521+
     12522+       ASSERT(GOODREGS(regs));
     12523+
     12524+       bzero((uchar*)si, sizeof (sb_info_t));
     12525+
     12526+       si->pciidx = si->gpioidx = BADIDX;
     12527+
     12528+       si->osh = osh;
     12529+       si->curmap = regs;
     12530+       si->sdh = sdh;
     12531+
     12532+       /* check to see if we are a sb core mimic'ing a pci core */
     12533+       if (bustype == PCI_BUS) {
     12534+               if (OSL_PCI_READ_CONFIG(osh, PCI_SPROM_CONTROL, sizeof (uint32)) == 0xffffffff)
     12535+                       bustype = SB_BUS;
     12536+               else
     12537+                       bustype = PCI_BUS;
     12538+       }
     12539+
     12540+       si->bustype = bustype;
     12541+       if (si->bustype != BUSTYPE(si->bustype)) {
     12542+               SB_ERROR(("sb_doattach: bus type %d does not match configured bus type %d\n",
     12543+                         si->bustype, BUSTYPE(si->bustype)));
     12544+               return NULL;
     12545+       }
     12546+
     12547+       /* need to set memseg flag for CF card first before any sb registers access */
     12548+       if (BUSTYPE(si->bustype) == PCMCIA_BUS)
     12549+               si->memseg = TRUE;
     12550+
     12551+       /* kludge to enable the clock on the 4306 which lacks a slowclock */
     12552+       if (BUSTYPE(si->bustype) == PCI_BUS)
     12553+               sb_pwrctl_xtal((void*)si, XTAL|PLL, ON);
     12554+
     12555+       /* initialize current core index value */
     12556+       si->curidx = _sb_coreidx((void*)si);
     12557+       if (si->curidx == BADIDX) {
     12558+               return NULL;
     12559+       }
     12560+
     12561+       /* keep and reuse the initial register mapping */
     12562+       origidx = si->curidx;
     12563+       if (BUSTYPE(si->bustype) == SB_BUS)
     12564+               si->regs[origidx] = regs;
     12565+
     12566+       /* is core-0 a chipcommon core? */
     12567+       si->numcores = 1;
     12568+       cc = (chipcregs_t*) sb_setcoreidx((void*)si, 0);
     12569+       if (sb_coreid((void*)si) != SB_CC)
     12570+               cc = NULL;
     12571+
     12572+       /* determine chip id and rev */
     12573+       if (cc) {
     12574+               /* chip common core found! */
     12575+               si->chip = R_REG(&cc->chipid) & CID_ID_MASK;
     12576+               si->chiprev = (R_REG(&cc->chipid) & CID_REV_MASK) >> CID_REV_SHIFT;
     12577+               si->chippkg = (R_REG(&cc->chipid) & CID_PKG_MASK) >> CID_PKG_SHIFT;
     12578+       } else {
     12579+               /* The only pcmcia chip without a chipcommon core is a 4301 */
     12580+               if (BUSTYPE(si->bustype) == PCMCIA_BUS)
     12581+                       devid = BCM4301_DEVICE_ID;
     12582+
     12583+               /* no chip common core -- must convert device id to chip id */
     12584+               if ((si->chip = BCMINIT(sb_pcidev2chip)(devid)) == 0) {
     12585+                       SB_ERROR(("sb_attach: unrecognized device id 0x%04x\n", devid));
     12586+                       return NULL;
     12587+               }
     12588+       }
     12589+
     12590+       /* get chipcommon rev */
     12591+       si->ccrev = cc ? sb_corerev((void*)si) : NOREV;
     12592+
     12593+       /* determine numcores */
     12594+       if (cc && ((si->ccrev == 4) || (si->ccrev >= 6)))
     12595+               si->numcores = (R_REG(&cc->chipid) & CID_CC_MASK) >> CID_CC_SHIFT;
     12596+       else
     12597+               si->numcores = BCMINIT(sb_chip2numcores)(si->chip);
     12598+
     12599+       /* return to original core */
     12600+       sb_setcoreidx((void*)si, origidx);
     12601+
     12602+       /* sanity checks */
     12603+       ASSERT(si->chip);
     12604+
     12605+       /* scan for cores */
     12606+       BCMINIT(sb_scan)(si);
     12607+
     12608+       /* srom_var_init() depends on sb_scan() info */
     12609+       if ((res = srom_var_init(si, si->bustype, si->curmap, osh, vars, varsz))) {
     12610+               SB_ERROR(("sb_attach: srom_var_init failed: bad srom\n"));
     12611+               return (NULL);
     12612+       }
     12613+       
     12614+       if (cc == NULL) {
     12615+               /*
     12616+                * The chip revision number is hardwired into all
     12617+                * of the pci function config rev fields and is
     12618+                * independent from the individual core revision numbers.
     12619+                * For example, the "A0" silicon of each chip is chip rev 0.
     12620+                * For PCMCIA we get it from the CIS instead.
     12621+                */
     12622+               if (BUSTYPE(si->bustype) == PCMCIA_BUS) {
     12623+                       ASSERT(vars);
     12624+                       si->chiprev = getintvar(*vars, "chiprev");
     12625+               } else if (BUSTYPE(si->bustype) == PCI_BUS) {
     12626+                       w = OSL_PCI_READ_CONFIG(osh, PCI_CFG_REV, sizeof (uint32));
     12627+                       si->chiprev = w & 0xff;
     12628+               } else
     12629+                       si->chiprev = 0;
     12630+       }
     12631+
     12632+       if (BUSTYPE(si->bustype) == PCMCIA_BUS) {
     12633+               w = getintvar(*vars, "regwindowsz");
     12634+               si->memseg = (w <= CFTABLE_REGWIN_2K) ? TRUE : FALSE;
     12635+       }
     12636+
     12637+       /* gpio control core is required */
     12638+       if (!GOODIDX(si->gpioidx)) {
     12639+               SB_ERROR(("sb_attach: gpio control core not found\n"));
     12640+               return NULL;
     12641+       }
     12642+
     12643+       /* get boardtype and boardrev */
     12644+       switch (BUSTYPE(si->bustype)) {
     12645+       case PCI_BUS:
     12646+               /* do a pci config read to get subsystem id and subvendor id */
     12647+               w = OSL_PCI_READ_CONFIG(osh, PCI_CFG_SVID, sizeof (uint32));
     12648+               si->boardvendor = w & 0xffff;
     12649+               si->boardtype = (w >> 16) & 0xffff;
     12650+               break;
     12651+
     12652+       case PCMCIA_BUS:
     12653+       case SDIO_BUS:
     12654+               si->boardvendor = getintvar(*vars, "manfid");
     12655+               si->boardtype = getintvar(*vars, "prodid");
     12656+               break;
     12657+
     12658+       case SB_BUS:
     12659+               si->boardvendor = VENDOR_BROADCOM;
     12660+               si->boardtype = 0xffff;
     12661+               break;
     12662+       }
     12663+
     12664+       if (si->boardtype == 0) {
     12665+               SB_ERROR(("sb_attach: unknown board type\n"));
     12666+               ASSERT(si->boardtype);
     12667+       }
     12668+
     12669+
     12670+       return ((void*)si);
     12671+}
     12672+
     12673+uint
     12674+sb_coreid(void *sbh)
     12675+{
     12676+       sb_info_t *si;
     12677+       sbconfig_t *sb;
     12678+
     12679+       si = SB_INFO(sbh);
     12680+       sb = REGS2SB(si->curmap);
     12681+
     12682+       return ((R_SBREG(sbh, &(sb)->sbidhigh) & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT);
     12683+}
     12684+
     12685+uint
     12686+sb_coreidx(void *sbh)
     12687+{
     12688+       sb_info_t *si;
     12689+
     12690+       si = SB_INFO(sbh);
     12691+       return (si->curidx);
     12692+}
     12693+
     12694+/* return current index of core */
     12695+static uint
     12696+_sb_coreidx(void *sbh)
     12697+{
     12698+       sb_info_t *si;
     12699+       sbconfig_t *sb;
     12700+       uint32 sbaddr = 0;
     12701+
     12702+       si = SB_INFO(sbh);
     12703+       ASSERT(si);
     12704+
     12705+       switch (BUSTYPE(si->bustype)) {
     12706+       case SB_BUS:
     12707+               sb = REGS2SB(si->curmap);
     12708+               sbaddr = sb_base(R_SBREG(sbh, &sb->sbadmatch0));
     12709+               break;
     12710+
     12711+       case PCI_BUS:
     12712+               sbaddr = OSL_PCI_READ_CONFIG(si->osh, PCI_BAR0_WIN, sizeof (uint32));
     12713+               break;
     12714+
     12715+       case PCMCIA_BUS: {
     12716+               uint8 tmp = 0;
     12717+
     12718+               OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_ADDR0, &tmp, 1);
     12719+               sbaddr  = (uint)tmp << 12;
     12720+               OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_ADDR1, &tmp, 1);
     12721+               sbaddr |= (uint)tmp << 16;
     12722+               OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_ADDR2, &tmp, 1);
     12723+               sbaddr |= (uint)tmp << 24;
     12724+               break;
     12725+       }
     12726+       default:
     12727+               ASSERT(0);
     12728+       }
     12729+
     12730+       if (!GOODCOREADDR(sbaddr))
     12731+               return BADIDX;
     12732+
     12733+       return ((sbaddr - SB_ENUM_BASE) / SB_CORE_SIZE);
     12734+}
     12735+
     12736+uint
     12737+sb_corevendor(void *sbh)
     12738+{
     12739+       sb_info_t *si;
     12740+       sbconfig_t *sb;
     12741+
     12742+       si = SB_INFO(sbh);
     12743+       sb = REGS2SB(si->curmap);
     12744+
     12745+       return ((R_SBREG(sbh, &(sb)->sbidhigh) & SBIDH_VC_MASK) >> SBIDH_VC_SHIFT);
     12746+}
     12747+
     12748+uint
     12749+sb_corerev(void *sbh)
     12750+{
     12751+       sb_info_t *si;
     12752+       sbconfig_t *sb;
     12753+
     12754+       si = SB_INFO(sbh);
     12755+       sb = REGS2SB(si->curmap);
     12756+
     12757+       return (R_SBREG(sbh, &(sb)->sbidhigh) & SBIDH_RC_MASK);
     12758+}
     12759+
     12760+void *
     12761+sb_osh(void *sbh)
     12762+{
     12763+       sb_info_t *si;
     12764+
     12765+       si = SB_INFO(sbh);
     12766+       return si->osh;
     12767+}
     12768+
     12769+#define        SBTML_ALLOW     (SBTML_PE | SBTML_FGC | SBTML_FL_MASK)
     12770+
     12771+/* set/clear sbtmstatelow core-specific flags */
     12772+uint32
     12773+sb_coreflags(void *sbh, uint32 mask, uint32 val)
     12774+{
     12775+       sb_info_t *si;
     12776+       sbconfig_t *sb;
     12777+       uint32 w;
     12778+
     12779+       si = SB_INFO(sbh);
     12780+       sb = REGS2SB(si->curmap);
     12781+
     12782+       ASSERT((val & ~mask) == 0);
     12783+       ASSERT((mask & ~SBTML_ALLOW) == 0);
     12784+
     12785+       /* mask and set */
     12786+       if (mask || val) {
     12787+               w = (R_SBREG(sbh, &sb->sbtmstatelow) & ~mask) | val;
     12788+               W_SBREG(sbh, &sb->sbtmstatelow, w);
     12789+       }
     12790+
     12791+       /* return the new value */
     12792+       return (R_SBREG(sbh, &sb->sbtmstatelow) & SBTML_ALLOW);
     12793+}
     12794+
     12795+/* set/clear sbtmstatehigh core-specific flags */
     12796+uint32
     12797+sb_coreflagshi(void *sbh, uint32 mask, uint32 val)
     12798+{
     12799+       sb_info_t *si;
     12800+       sbconfig_t *sb;
     12801+       uint32 w;
     12802+
     12803+       si = SB_INFO(sbh);
     12804+       sb = REGS2SB(si->curmap);
     12805+
     12806+       ASSERT((val & ~mask) == 0);
     12807+       ASSERT((mask & ~SBTMH_FL_MASK) == 0);
     12808+
     12809+       /* mask and set */
     12810+       if (mask || val) {
     12811+               w = (R_SBREG(sbh, &sb->sbtmstatehigh) & ~mask) | val;
     12812+               W_SBREG(sbh, &sb->sbtmstatehigh, w);
     12813+       }
     12814+
     12815+       /* return the new value */
     12816+       return (R_SBREG(sbh, &sb->sbtmstatehigh) & SBTMH_FL_MASK);
     12817+}
     12818+
     12819+bool
     12820+sb_iscoreup(void *sbh)
     12821+{
     12822+       sb_info_t *si;
     12823+       sbconfig_t *sb;
     12824+
     12825+       si = SB_INFO(sbh);
     12826+       sb = REGS2SB(si->curmap);
     12827+
     12828+       return ((R_SBREG(sbh, &(sb)->sbtmstatelow) & (SBTML_RESET | SBTML_REJ | SBTML_CLK)) == SBTML_CLK);
     12829+}
     12830+
    1914412831+/*
    19145 + * Misc useful os-independent macros and functions.
    19146 + *
    19147 + * Copyright 2006, Broadcom Corporation
    19148 + * All Rights Reserved.
    19149 + *
    19150 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    19151 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    19152 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    19153 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    19154 + * $Id: bcmutils.h,v 1.1.1.16 2006/04/08 06:13:39 honor Exp $
     12832+ * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set operation,
     12833+ * switch back to the original core, and return the new value.
    1915512834+ */
    19156 +
    19157 +#ifndef        _pktq_h_
    19158 +#define        _pktq_h_
    19159 +#include <osl.h>
    19160 +
    19161 +/* osl multi-precedence packet queue */
    19162 +
    19163 +#define PKTQ_LEN_DEFAULT        128    /* Max 128 packets */
    19164 +#define PKTQ_MAX_PREC           16     /* Maximum precedence levels */
    19165 +
    19166 +struct pktq {
    19167 +       struct pktq_prec {
    19168 +               void *head;     /* first packet to dequeue */
    19169 +               void *tail;     /* last packet to dequeue */
    19170 +               uint16 len;     /* number of queued packets */
    19171 +               uint16 max;     /* maximum number of queued packets */
    19172 +       } q[PKTQ_MAX_PREC];
    19173 +       uint16 num_prec;        /* number of precedences in use */
    19174 +       uint16 hi_prec;         /* rapid dequeue hint (>= highest non-empty prec) */
    19175 +       uint16 max;             /* total max packets */
    19176 +       uint16 len;             /* total number of packets */
    19177 +};
    19178 +
    19179 +#define PKTQ_PREC_ITER(pq, prec)        for (prec = (pq)->num_prec - 1; prec >= 0; prec--)
    19180 +
    19181 +/* forward definition of ether_addr structure used by some function prototypes */
    19182 +
    19183 +struct ether_addr;
    19184 +
    19185 +/* operations on a specific precedence in packet queue */
    19186 +
    19187 +#define pktq_psetmax(pq, prec, _max)    ((pq)->q[prec].max = (_max))
    19188 +#define pktq_plen(pq, prec)             ((pq)->q[prec].len)
    19189 +#define pktq_pavail(pq, prec)           ((pq)->q[prec].max - (pq)->q[prec].len)
    19190 +#define pktq_pfull(pq, prec)            ((pq)->q[prec].len >= (pq)->q[prec].max)
    19191 +#define pktq_pempty(pq, prec)           ((pq)->q[prec].len == 0)
    19192 +
    19193 +#define pktq_ppeek(pq, prec)            ((pq)->q[prec].head)
    19194 +#define pktq_ppeek_tail(pq, prec)       ((pq)->q[prec].tail)
    19195 +
    19196 +extern void *pktq_penq(struct pktq *pq, int prec, void *p);
    19197 +extern void *pktq_penq_head(struct pktq *pq, int prec, void *p);
    19198 +extern void *pktq_pdeq(struct pktq *pq, int prec);
    19199 +extern void *pktq_pdeq_tail(struct pktq *pq, int prec);
    19200 +/* Empty the queue at particular precedence level */
    19201 +extern void pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir);
    19202 +/* Remove a specified packet from its queue */
    19203 +extern bool pktq_pdel(struct pktq *pq, void *p, int prec);
    19204 +
    19205 +/* operations on a set of precedences in packet queue */
    19206 +
    19207 +extern int pktq_mlen(struct pktq *pq, uint prec_bmp);
    19208 +extern void *pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out);
    19209 +
    19210 +/* operations on packet queue as a whole */
    19211 +
    19212 +#define pktq_len(pq)                    ((int)(pq)->len)
    19213 +#define pktq_max(pq)                    ((int)(pq)->max)
    19214 +#define pktq_avail(pq)                  ((int)((pq)->max - (pq)->len))
    19215 +#define pktq_full(pq)                   ((pq)->len >= (pq)->max)
    19216 +#define pktq_empty(pq)                  ((pq)->len == 0)
    19217 +
    19218 +/* operations for single precedence queues */
    19219 +#define pktenq(pq, p)          pktq_penq((pq), 0, (p))
    19220 +#define pktenq_head(pq, p)     pktq_penq_head((pq), 0, (p))
    19221 +#define pktdeq(pq)             pktq_pdeq((pq), 0)
    19222 +#define pktdeq_tail(pq)                pktq_pdeq_tail((pq), 0)
    19223 +
    19224 +extern void pktq_init(struct pktq *pq, int num_prec, int max_len);
    19225 +/* prec_out may be NULL if caller is not interested in return value */
    19226 +extern void *pktq_deq(struct pktq *pq, int *prec_out);
    19227 +extern void *pktq_deq_tail(struct pktq *pq, int *prec_out);
    19228 +extern void *pktq_peek(struct pktq *pq, int *prec_out);
    19229 +extern void *pktq_peek_tail(struct pktq *pq, int *prec_out);
    19230 +extern void pktq_flush(osl_t *osh, struct pktq *pq, bool dir); /* Empty the entire queue */
    19231 +
    19232 +/* externs */
    19233 +/* packet */
    19234 +extern uint pktcopy(osl_t *osh, void *p, uint offset, int len, uchar *buf);
    19235 +extern uint pkttotlen(osl_t *osh, void *p);
    19236 +extern void *pktlast(osl_t *osh, void *p);
    19237 +
    19238 +extern void pktsetprio(void *pkt, bool update_vtag);
    19239 +
    19240 +#endif /* _pktq_h_ */
    19241 diff -urN linux.old/drivers/net/wl/sbhnddma.h linux.dev/drivers/net/wl/sbhnddma.h
    19242 --- linux.old/drivers/net/wl/sbhnddma.h 1970-01-01 01:00:00.000000000 +0100
    19243 +++ linux.dev/drivers/net/wl/sbhnddma.h 2006-04-28 02:20:47.000000000 +0200
    19244 @@ -0,0 +1,284 @@
     12835+static uint
     12836+sb_corereg(void *sbh, uint coreidx, uint regoff, uint mask, uint val)
     12837+{
     12838+       sb_info_t *si;
     12839+       uint origidx;
     12840+       uint32 *r;
     12841+       uint w;
     12842+       uint intr_val = 0;
     12843+
     12844+       ASSERT(GOODIDX(coreidx));
     12845+       ASSERT(regoff < SB_CORE_SIZE);
     12846+       ASSERT((val & ~mask) == 0);
     12847+
     12848+       si = SB_INFO(sbh);
     12849+
     12850+       INTR_OFF(si, intr_val);
     12851+
     12852+       /* save current core index */
     12853+       origidx = sb_coreidx(sbh);
     12854+
     12855+       /* switch core */
     12856+       r = (uint32*) ((uchar*) sb_setcoreidx(sbh, coreidx) + regoff);
     12857+
     12858+       /* mask and set */
     12859+       if (mask || val) {
     12860+               if (regoff >= SBCONFIGOFF) {
     12861+                       w = (R_SBREG(sbh, r) & ~mask) | val;
     12862+                       W_SBREG(sbh, r, w);
     12863+               } else {
     12864+                       w = (R_REG(r) & ~mask) | val;
     12865+                       W_REG(r, w);
     12866+               }
     12867+       }
     12868+
     12869+       /* readback */
     12870+       if (regoff >= SBCONFIGOFF)
     12871+               w = R_SBREG(sbh, r);
     12872+       else
     12873+               w = R_REG(r);
     12874+
     12875+       /* restore core index */
     12876+       if (origidx != coreidx)
     12877+               sb_setcoreidx(sbh, origidx);
     12878+
     12879+       INTR_RESTORE(si, intr_val);
     12880+       return (w);
     12881+}
     12882+
     12883+/* scan the sb enumerated space to identify all cores */
     12884+static void
     12885+BCMINITFN(sb_scan)(sb_info_t *si)
     12886+{
     12887+       void *sbh;
     12888+       uint origidx;
     12889+       uint i;
     12890+
     12891+       sbh = (void*) si;
     12892+
     12893+       /* numcores should already be set */
     12894+       ASSERT((si->numcores > 0) && (si->numcores <= SB_MAXCORES));
     12895+
     12896+       /* save current core index */
     12897+       origidx = sb_coreidx(sbh);
     12898+
     12899+       si->pciidx = si->pcmciaidx = si->gpioidx = BADIDX;
     12900+       si->pcirev = si->pcmciarev = NOREV;
     12901+
     12902+       for (i = 0; i < si->numcores; i++) {
     12903+               sb_setcoreidx(sbh, i);
     12904+               si->coreid[i] = sb_coreid(sbh);
     12905+
     12906+               if (si->coreid[i] == SB_PCI) {
     12907+                       si->pciidx = i;
     12908+                       si->pcirev = sb_corerev(sbh);
     12909+
     12910+               } else if (si->coreid[i] == SB_PCMCIA) {
     12911+                       si->pcmciaidx = i;
     12912+                       si->pcmciarev = sb_corerev(sbh);
     12913+               }
     12914+       }
     12915+
     12916+       /*
     12917+        * Find the gpio "controlling core" type and index.
     12918+        * Precedence:
     12919+        * - if there's a chip common core - use that
     12920+        * - else if there's a pci core (rev >= 2) - use that
     12921+        * - else there had better be an extif core (4710 only)
     12922+        */
     12923+       if (GOODIDX(sb_findcoreidx(sbh, SB_CC, 0))) {
     12924+               si->gpioidx = sb_findcoreidx(sbh, SB_CC, 0);
     12925+               si->gpioid = SB_CC;
     12926+       } else if (GOODIDX(si->pciidx) && (si->pcirev >= 2)) {
     12927+               si->gpioidx = si->pciidx;
     12928+               si->gpioid = SB_PCI;
     12929+       } else if (sb_findcoreidx(sbh, SB_EXTIF, 0)) {
     12930+               si->gpioidx = sb_findcoreidx(sbh, SB_EXTIF, 0);
     12931+               si->gpioid = SB_EXTIF;
     12932+       } else
     12933+               ASSERT(si->gpioidx != BADIDX);
     12934+
     12935+       /* return to original core index */
     12936+       sb_setcoreidx(sbh, origidx);
     12937+}
     12938+
     12939+/* may be called with core in reset */
     12940+void
     12941+sb_detach(void *sbh)
     12942+{
     12943+       sb_info_t *si;
     12944+       uint idx;
     12945+
     12946+       si = SB_INFO(sbh);
     12947+
     12948+       if (si == NULL)
     12949+               return;
     12950+
     12951+       if (BUSTYPE(si->bustype) == SB_BUS)
     12952+               for (idx = 0; idx < SB_MAXCORES; idx++)
     12953+                       if (si->regs[idx]) {
     12954+                               REG_UNMAP(si->regs[idx]);
     12955+                               si->regs[idx] = NULL;
     12956+                       }
     12957+
     12958+       MFREE(si->osh, si, sizeof (sb_info_t));
     12959+}
     12960+
     12961+/* use pci dev id to determine chip id for chips not having a chipcommon core */
     12962+static uint
     12963+BCMINITFN(sb_pcidev2chip)(uint pcidev)
     12964+{
     12965+       if ((pcidev >= BCM4710_DEVICE_ID) && (pcidev <= BCM47XX_USB_ID))
     12966+               return (BCM4710_DEVICE_ID);
     12967+       if ((pcidev >= BCM4610_DEVICE_ID) && (pcidev <= BCM4610_USB_ID))
     12968+               return (BCM4610_DEVICE_ID);
     12969+       if ((pcidev >= BCM4402_DEVICE_ID) && (pcidev <= BCM4402_V90_ID))
     12970+               return (BCM4402_DEVICE_ID);
     12971+       if (pcidev == BCM4401_ENET_ID)
     12972+               return (BCM4402_DEVICE_ID);
     12973+       if ((pcidev >= BCM4307_V90_ID) && (pcidev <= BCM4307_D11B_ID))
     12974+               return (BCM4307_DEVICE_ID);
     12975+       if (pcidev == BCM4301_DEVICE_ID)
     12976+               return (BCM4301_DEVICE_ID);
     12977+
     12978+       return (0);
     12979+}
     12980+
     12981+/* convert chip number to number of i/o cores */
     12982+static uint
     12983+BCMINITFN(sb_chip2numcores)(uint chip)
     12984+{
     12985+       if (chip == 0x4710)
     12986+               return (9);
     12987+       if (chip == 0x4610)
     12988+               return (9);
     12989+       if (chip == 0x4402)
     12990+               return (3);
     12991+       if ((chip == 0x4307) || (chip == 0x4301))
     12992+               return (5);
     12993+       if (chip == 0x4310)
     12994+               return (8);
     12995+       if (chip == 0x4306)     /* < 4306c0 */
     12996+               return (6);
     12997+       if (chip == 0x4704)
     12998+               return (9);
     12999+       if (chip == 0x5365)
     13000+               return (7);
     13001+
     13002+       SB_ERROR(("sb_chip2numcores: unsupported chip 0x%x\n", chip));
     13003+       ASSERT(0);
     13004+       return (1);
     13005+}
     13006+
     13007+/* return index of coreid or BADIDX if not found */
     13008+static uint
     13009+sb_findcoreidx(void *sbh, uint coreid, uint coreunit)
     13010+{
     13011+       sb_info_t *si;
     13012+       uint found;
     13013+       uint i;
     13014+
     13015+       si = SB_INFO(sbh);
     13016+       found = 0;
     13017+
     13018+       for (i = 0; i < si->numcores; i++)
     13019+               if (si->coreid[i] == coreid) {
     13020+                       if (found == coreunit)
     13021+                               return (i);
     13022+                       found++;
     13023+               }
     13024+
     13025+       return (BADIDX);
     13026+}
     13027+
     13028+/*
     13029+ * this function changes logical "focus" to the indiciated core,
     13030+ * must be called with interrupt off.
     13031+ * Moreover, callers should keep interrupts off during switching out of and back to d11 core
     13032+ */
     13033+void*
     13034+sb_setcoreidx(void *sbh, uint coreidx)
     13035+{
     13036+       sb_info_t *si;
     13037+       uint32 sbaddr;
     13038+       uint8 tmp;
     13039+
     13040+       si = SB_INFO(sbh);
     13041+
     13042+       if (coreidx >= si->numcores)
     13043+               return (NULL);
     13044+       
     13045+       /*
     13046+        * If the user has provided an interrupt mask enabled function,
     13047+        * then assert interrupts are disabled before switching the core.
     13048+        */
     13049+       ASSERT((si->intrsenabled_fn == NULL) || !(*(si)->intrsenabled_fn)((si)->intr_arg));
     13050+
     13051+       sbaddr = SB_ENUM_BASE + (coreidx * SB_CORE_SIZE);
     13052+
     13053+       switch (BUSTYPE(si->bustype)) {
     13054+       case SB_BUS:
     13055+               /* map new one */
     13056+               if (!si->regs[coreidx]) {
     13057+                       si->regs[coreidx] = (void*)REG_MAP(sbaddr, SB_CORE_SIZE);
     13058+                       ASSERT(GOODREGS(si->regs[coreidx]));
     13059+               }
     13060+               si->curmap = si->regs[coreidx];
     13061+               break;
     13062+
     13063+       case PCI_BUS:
     13064+               /* point bar0 window */
     13065+               OSL_PCI_WRITE_CONFIG(si->osh, PCI_BAR0_WIN, 4, sbaddr);
     13066+               break;
     13067+
     13068+       case PCMCIA_BUS:
     13069+               tmp = (sbaddr >> 12) & 0x0f;
     13070+               OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_ADDR0, &tmp, 1);
     13071+               tmp = (sbaddr >> 16) & 0xff;
     13072+               OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_ADDR1, &tmp, 1);
     13073+               tmp = (sbaddr >> 24) & 0xff;
     13074+               OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_ADDR2, &tmp, 1);
     13075+               break;
     13076+       }
     13077+
     13078+       si->curidx = coreidx;
     13079+
     13080+       return (si->curmap);
     13081+}
     13082+
     13083+/*
     13084+ * this function changes logical "focus" to the indiciated core,
     13085+ * must be called with interrupt off.
     13086+ * Moreover, callers should keep interrupts off during switching out of and back to d11 core
     13087+ */
     13088+void*
     13089+sb_setcore(void *sbh, uint coreid, uint coreunit)
     13090+{
     13091+       sb_info_t *si;
     13092+       uint idx;
     13093+
     13094+       si = SB_INFO(sbh);
     13095+
     13096+       idx = sb_findcoreidx(sbh, coreid, coreunit);
     13097+       if (!GOODIDX(idx))
     13098+               return (NULL);
     13099+
     13100+       return (sb_setcoreidx(sbh, idx));
     13101+}
     13102+
     13103+/* return chip number */
     13104+uint
     13105+BCMINITFN(sb_chip)(void *sbh)
     13106+{
     13107+       sb_info_t *si;
     13108+
     13109+       si = SB_INFO(sbh);
     13110+       return (si->chip);
     13111+}
     13112+
     13113+/* return chip revision number */
     13114+uint
     13115+BCMINITFN(sb_chiprev)(void *sbh)
     13116+{
     13117+       sb_info_t *si;
     13118+
     13119+       si = SB_INFO(sbh);
     13120+       return (si->chiprev);
     13121+}
     13122+
     13123+/* return chip common revision number */
     13124+uint
     13125+BCMINITFN(sb_chipcrev)(void *sbh)
     13126+{
     13127+       sb_info_t *si;
     13128+
     13129+       si = SB_INFO(sbh);
     13130+       return (si->ccrev);
     13131+}
     13132+
     13133+/* return chip package option */
     13134+uint
     13135+BCMINITFN(sb_chippkg)(void *sbh)
     13136+{
     13137+       sb_info_t *si;
     13138+
     13139+       si = SB_INFO(sbh);
     13140+       return (si->chippkg);
     13141+}
     13142+
     13143+/* return PCI core rev. */
     13144+uint
     13145+BCMINITFN(sb_pcirev)(void *sbh)
     13146+{
     13147+       sb_info_t *si;
     13148+
     13149+       si = SB_INFO(sbh);
     13150+       return (si->pcirev);
     13151+}
     13152+
     13153+/* return PCMCIA core rev. */
     13154+uint
     13155+BCMINITFN(sb_pcmciarev)(void *sbh)
     13156+{
     13157+       sb_info_t *si;
     13158+
     13159+       si = SB_INFO(sbh);
     13160+       return (si->pcmciarev);
     13161+}
     13162+
     13163+/* return board vendor id */
     13164+uint
     13165+BCMINITFN(sb_boardvendor)(void *sbh)
     13166+{
     13167+       sb_info_t *si;
     13168+
     13169+       si = SB_INFO(sbh);
     13170+       return (si->boardvendor);
     13171+}
     13172+
     13173+/* return boardtype */
     13174+uint
     13175+BCMINITFN(sb_boardtype)(void *sbh)
     13176+{
     13177+       sb_info_t *si;
     13178+       char *var;
     13179+
     13180+       si = SB_INFO(sbh);
     13181+
     13182+       if (BUSTYPE(si->bustype) == SB_BUS && si->boardtype == 0xffff) {
     13183+               /* boardtype format is a hex string */
     13184+               si->boardtype = getintvar(NULL, "boardtype");
     13185+
     13186+               /* backward compatibility for older boardtype string format */
     13187+               if ((si->boardtype == 0) && (var = getvar(NULL, "boardtype"))) {
     13188+                       if (!strcmp(var, "bcm94710dev"))
     13189+                               si->boardtype = BCM94710D_BOARD;
     13190+                       else if (!strcmp(var, "bcm94710ap"))
     13191+                               si->boardtype = BCM94710AP_BOARD;
     13192+                       else if (!strcmp(var, "bcm94310u"))
     13193+                               si->boardtype = BCM94310U_BOARD;
     13194+                       else if (!strcmp(var, "bu4711"))
     13195+                               si->boardtype = BU4711_BOARD;
     13196+                       else if (!strcmp(var, "bu4710"))
     13197+                               si->boardtype = BU4710_BOARD;
     13198+                       else if (!strcmp(var, "bcm94702mn"))
     13199+                               si->boardtype = BCM94702MN_BOARD;
     13200+                       else if (!strcmp(var, "bcm94710r1"))
     13201+                               si->boardtype = BCM94710R1_BOARD;
     13202+                       else if (!strcmp(var, "bcm94710r4"))
     13203+                               si->boardtype = BCM94710R4_BOARD;
     13204+                       else if (!strcmp(var, "bcm94702cpci"))
     13205+                               si->boardtype = BCM94702CPCI_BOARD;
     13206+                       else if (!strcmp(var, "bcm95380_rr"))
     13207+                               si->boardtype = BCM95380RR_BOARD;
     13208+               }
     13209+       }
     13210+
     13211+       return (si->boardtype);
     13212+}
     13213+
     13214+/* return bus type of sdh device */
     13215+uint
     13216+sb_bus(void *sbh)
     13217+{
     13218+       sb_info_t *si;
     13219+
     13220+       si = SB_INFO(sbh);
     13221+       return (si->bustype);
     13222+}
     13223+
     13224+/* return list of found cores */
     13225+uint
     13226+sb_corelist(void *sbh, uint coreid[])
     13227+{
     13228+       sb_info_t *si;
     13229+
     13230+       si = SB_INFO(sbh);
     13231+
     13232+       bcopy((uchar*)si->coreid, (uchar*)coreid, (si->numcores * sizeof (uint)));
     13233+       return (si->numcores);
     13234+}
     13235+
     13236+/* return current register mapping */
     13237+void *
     13238+sb_coreregs(void *sbh)
     13239+{
     13240+       sb_info_t *si;
     13241+
     13242+       si = SB_INFO(sbh);
     13243+       ASSERT(GOODREGS(si->curmap));
     13244+
     13245+       return (si->curmap);
     13246+}
     13247+
     13248+
     13249+/* do buffered registers update */
     13250+void
     13251+sb_commit(void *sbh)
     13252+{
     13253+       sb_info_t *si;
     13254+       uint origidx;
     13255+       uint intr_val = 0;
     13256+
     13257+       si = SB_INFO(sbh);
     13258+
     13259+       origidx = si->curidx;
     13260+       ASSERT(GOODIDX(origidx));
     13261+
     13262+       INTR_OFF(si, intr_val);
     13263+
     13264+       /* switch over to chipcommon core if there is one, else use pci */
     13265+       if (si->ccrev != NOREV) {
     13266+               chipcregs_t *ccregs = (chipcregs_t *)sb_setcore(sbh, SB_CC, 0);
     13267+
     13268+               /* do the buffer registers update */
     13269+               W_REG(&ccregs->broadcastaddress, SB_COMMIT);
     13270+               W_REG(&ccregs->broadcastdata, 0x0);
     13271+       } else if (si->pciidx != BADIDX) {
     13272+               sbpciregs_t *pciregs = (sbpciregs_t *)sb_setcore(sbh, SB_PCI, 0);
     13273+
     13274+               /* do the buffer registers update */
     13275+               W_REG(&pciregs->bcastaddr, SB_COMMIT);
     13276+               W_REG(&pciregs->bcastdata, 0x0);
     13277+       } else {
     13278+               ASSERT((si->ccrev != NOREV) && (si->pciidx != BADIDX));
     13279+       }
     13280+
     13281+       /* restore core index */
     13282+       sb_setcoreidx(sbh, origidx);
     13283+       INTR_RESTORE(si, intr_val);
     13284+}
     13285+
     13286+/* reset and re-enable a core */
     13287+void
     13288+sb_core_reset(void *sbh, uint32 bits)
     13289+{
     13290+       sb_info_t *si;
     13291+       sbconfig_t *sb;
     13292+       volatile uint32 dummy;
     13293+
     13294+       si = SB_INFO(sbh);
     13295+       ASSERT(GOODREGS(si->curmap));
     13296+       sb = REGS2SB(si->curmap);
     13297+
     13298+       /*
     13299+        * Must do the disable sequence first to work for arbitrary current core state.
     13300+        */
     13301+       sb_core_disable(sbh, bits);
     13302+
     13303+       /*
     13304+        * Now do the initialization sequence.
     13305+        */
     13306+
     13307+       /* set reset while enabling the clock and forcing them on throughout the core */
     13308+       W_SBREG(sbh, &sb->sbtmstatelow, (SBTML_FGC | SBTML_CLK | SBTML_RESET | bits));
     13309+       dummy = R_SBREG(sbh, &sb->sbtmstatelow);
     13310+
     13311+       if (sb_coreid(sbh) == SB_ILINE100) {
     13312+               bcm_mdelay(50);
     13313+       } else {
     13314+               OSL_DELAY(1);
     13315+       }
     13316+
     13317+       if (R_SBREG(sbh, &sb->sbtmstatehigh) & SBTMH_SERR) {
     13318+               W_SBREG(sbh, &sb->sbtmstatehigh, 0);
     13319+       }
     13320+       if ((dummy = R_SBREG(sbh, &sb->sbimstate)) & (SBIM_IBE | SBIM_TO)) {
     13321+               AND_SBREG(sbh, &sb->sbimstate, ~(SBIM_IBE | SBIM_TO));
     13322+       }
     13323+
     13324+       /* clear reset and allow it to propagate throughout the core */
     13325+       W_SBREG(sbh, &sb->sbtmstatelow, (SBTML_FGC | SBTML_CLK | bits));
     13326+       dummy = R_SBREG(sbh, &sb->sbtmstatelow);
     13327+       OSL_DELAY(1);
     13328+
     13329+       /* leave clock enabled */
     13330+       W_SBREG(sbh, &sb->sbtmstatelow, (SBTML_CLK | bits));
     13331+       dummy = R_SBREG(sbh, &sb->sbtmstatelow);
     13332+       OSL_DELAY(1);
     13333+}
     13334+
     13335+void
     13336+sb_core_tofixup(void *sbh)
     13337+{
     13338+       sb_info_t *si;
     13339+       sbconfig_t *sb;
     13340+
     13341+       si = SB_INFO(sbh);
     13342+
     13343+       if ((si->pciidx == BADIDX) || (si->pcirev >= 5))
     13344+               return;
     13345+
     13346+       ASSERT(GOODREGS(si->curmap));
     13347+       sb = REGS2SB(si->curmap);
     13348+
     13349+       if (BUSTYPE(si->bustype) == SB_BUS) {
     13350+               SET_SBREG(sbh, &sb->sbimconfiglow,
     13351+                         SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
     13352+                         (0x5 << SBIMCL_RTO_SHIFT) | 0x3);
     13353+       } else {
     13354+               if (sb_coreid(sbh) == SB_PCI) {
     13355+                       SET_SBREG(sbh, &sb->sbimconfiglow,
     13356+                                 SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
     13357+                                 (0x3 << SBIMCL_RTO_SHIFT) | 0x2);
     13358+               } else {
     13359+                       SET_SBREG(sbh, &sb->sbimconfiglow, (SBIMCL_RTO_MASK | SBIMCL_STO_MASK), 0);
     13360+               }
     13361+       }
     13362+
     13363+       sb_commit(sbh);
     13364+}
     13365+
     13366+void
     13367+sb_core_disable(void *sbh, uint32 bits)
     13368+{
     13369+       sb_info_t *si;
     13370+       volatile uint32 dummy;
     13371+       sbconfig_t *sb;
     13372+
     13373+       si = SB_INFO(sbh);
     13374+
     13375+       ASSERT(GOODREGS(si->curmap));
     13376+       sb = REGS2SB(si->curmap);
     13377+
     13378+       /* if core is already in reset, just return */
     13379+       if (R_SBREG(sbh, &sb->sbtmstatelow) & SBTML_RESET)
     13380+               return;
     13381+
     13382+       /* if clocks are not enabled, put into reset and return */
     13383+       if ((R_SBREG(sbh, &sb->sbtmstatelow) & SBTML_CLK) == 0)
     13384+               goto disable;
     13385+
     13386+       /* set the target reject bit and spin until busy is clear */
     13387+       W_SBREG(sbh, &sb->sbtmstatelow, (SBTML_CLK | SBTML_REJ));
     13388+       dummy = R_SBREG(sbh, &sb->sbtmstatelow);
     13389+       OSL_DELAY(1);
     13390+       SPINWAIT((R_SBREG(sbh, &sb->sbtmstatehigh) & SBTMH_BUSY), 100000);
     13391+
     13392+       if (R_SBREG(sbh, &sb->sbidlow) & SBIDL_INIT) {
     13393+               OR_SBREG(sbh, &sb->sbimstate, SBIM_RJ);
     13394+               dummy = R_SBREG(sbh, &sb->sbimstate);
     13395+               OSL_DELAY(1);
     13396+               SPINWAIT((R_SBREG(sbh, &sb->sbimstate) & SBIM_BY), 100000);
     13397+       }
     13398+
     13399+       /* set reset and reject while enabling the clocks */
     13400+       W_SBREG(sbh, &sb->sbtmstatelow, (bits | SBTML_FGC | SBTML_CLK | SBTML_REJ | SBTML_RESET));
     13401+       dummy = R_SBREG(sbh, &sb->sbtmstatelow);
     13402+       OSL_DELAY(10);
     13403+
     13404+       /* don't forget to clear the initiator reject bit */
     13405+       if (R_SBREG(sbh, &sb->sbidlow) & SBIDL_INIT)
     13406+               AND_SBREG(sbh, &sb->sbimstate, ~SBIM_RJ);
     13407+
     13408+disable:
     13409+       /* leave reset and reject asserted */
     13410+       W_SBREG(sbh, &sb->sbtmstatelow, (bits | SBTML_REJ | SBTML_RESET));
     13411+       OSL_DELAY(1);
     13412+}
     13413+
     13414+void
     13415+sb_watchdog(void *sbh, uint ticks)
     13416+{
     13417+       sb_info_t *si = SB_INFO(sbh);
     13418+
     13419+       /* instant NMI */
     13420+       switch (si->gpioid) {
     13421+       case SB_CC:
     13422+               sb_corereg(sbh, si->gpioidx, OFFSETOF(chipcregs_t, watchdog), ~0, ticks);
     13423+               break;
     13424+       case SB_EXTIF:
     13425+               sb_corereg(sbh, si->gpioidx, OFFSETOF(extifregs_t, watchdog), ~0, ticks);
     13426+               break;
     13427+       }
     13428+}
     13429+
     13430+/* initialize the pcmcia core */
     13431+void
     13432+sb_pcmcia_init(void *sbh)
     13433+{
     13434+       sb_info_t *si;
     13435+       uint8 cor;
     13436+
     13437+       si = SB_INFO(sbh);
     13438+
     13439+       /* enable d11 mac interrupts */
     13440+       if (si->chip == BCM4301_DEVICE_ID) {
     13441+               /* Have to use FCR2 in 4301 */
     13442+               OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_FCR2 + PCMCIA_COR, &cor, 1);
     13443+               cor |= COR_IRQEN | COR_FUNEN;
     13444+               OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_FCR2 + PCMCIA_COR, &cor, 1);
     13445+       } else {
     13446+               OSL_PCMCIA_READ_ATTR(si->osh, PCMCIA_FCR0 + PCMCIA_COR, &cor, 1);
     13447+               cor |= COR_IRQEN | COR_FUNEN;
     13448+               OSL_PCMCIA_WRITE_ATTR(si->osh, PCMCIA_FCR0 + PCMCIA_COR, &cor, 1);
     13449+       }
     13450+
     13451+}
     13452+
     13453+
    1924513454+/*
    19246 + * Generic Broadcom Home Networking Division (HND) DMA engine HW interface
    19247 + * This supports the following chips: BCM42xx, 44xx, 47xx .
    19248 + *
    19249 + * Copyright 2006, Broadcom Corporation
    19250 + * All Rights Reserved.
    19251 + *
    19252 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
    19253 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
    19254 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
    19255 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
    19256 + *
    19257 + * $Id: sbhnddma.h,v 1.1.1.2 2006/02/27 03:43:16 honor Exp $
     13455+ * Configure the pci core for pci client (NIC) action
     13456+ * and get appropriate dma offset value.
     13457+ * coremask is the bitvec of cores by index to be enabled.
    1925813458+ */
    19259 +
    19260 +#ifndef        _sbhnddma_h_
    19261 +#define        _sbhnddma_h_
    19262 +
    19263 +/* DMA structure:
    19264 + *  support two DMA engines: 32 bits address or 64 bit addressing
    19265 + *  basic DMA register set is per channel(transmit or receive)
    19266 + *  a pair of channels is defined for convenience
     13459+void
     13460+sb_pci_setup(void *sbh, uint32 *dmaoffset, uint coremask)
     13461+{
     13462+       sb_info_t *si;
     13463+       sbconfig_t *sb;
     13464+       sbpciregs_t *pciregs;
     13465+       uint32 sbflag;
     13466+       uint32 w;
     13467+       uint idx;
     13468+
     13469+       si = SB_INFO(sbh);
     13470+
     13471+       if (dmaoffset)
     13472+               *dmaoffset = 0;
     13473+
     13474+       /* if not pci bus, we're done */
     13475+       if (BUSTYPE(si->bustype) != PCI_BUS)
     13476+               return;
     13477+
     13478+       ASSERT(si->pciidx != BADIDX);
     13479+
     13480+       /* get current core index */
     13481+       idx = si->curidx;
     13482+
     13483+       /* we interrupt on this backplane flag number */
     13484+       ASSERT(GOODREGS(si->curmap));
     13485+       sb = REGS2SB(si->curmap);
     13486+       sbflag = R_SBREG(sbh, &sb->sbtpsflag) & SBTPS_NUM0_MASK;
     13487+
     13488+       /* switch over to pci core */
     13489+       pciregs = (sbpciregs_t*) sb_setcoreidx(sbh, si->pciidx);
     13490+       sb = REGS2SB(pciregs);
     13491+
     13492+       /*
     13493+        * Enable sb->pci interrupts.  Assume
     13494+        * PCI rev 2.3 support was added in pci core rev 6 and things changed..
     13495+        */
     13496+       if (si->pcirev < 6) {
     13497+               /* set sbintvec bit for our flag number */
     13498+               OR_SBREG(sbh, &sb->sbintvec, (1 << sbflag));
     13499+       } else {
     13500+               /* pci config write to set this core bit in PCIIntMask */
     13501+               w = OSL_PCI_READ_CONFIG(si->osh, PCI_INT_MASK, sizeof(uint32));
     13502+               w |= (coremask << PCI_SBIM_SHIFT);
     13503+               OSL_PCI_WRITE_CONFIG(si->osh, PCI_INT_MASK, sizeof(uint32), w);
     13504+       }
     13505+
     13506+       /* enable prefetch and bursts for dma big window */
     13507+       OR_REG(&pciregs->sbtopci2, (SBTOPCI_PREF|SBTOPCI_BURST));
     13508+
     13509+       /* enable read multiple for dma big window */
     13510+       if (si->pcirev >= 11)
     13511+               OR_REG(&pciregs->sbtopci2, SBTOPCI_RC_READMULTI);
     13512+
     13513+       if (si->pcirev < 5) {
     13514+               SET_SBREG(sbh, &sb->sbimconfiglow, SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
     13515+                       (0x3 << SBIMCL_RTO_SHIFT) | 0x2);
     13516+               sb_commit(sbh);
     13517+       }
     13518+
     13519+       /* switch back to previous core */
     13520+       sb_setcoreidx(sbh, idx);
     13521+
     13522+       /* use large sb pci dma window */
     13523+       if (dmaoffset)
     13524+               *dmaoffset = SB_PCI_DMA;
     13525+}
     13526+
     13527+uint32
     13528+sb_base(uint32 admatch)
     13529+{
     13530+       uint32 base;
     13531+       uint type;
     13532+
     13533+       type = admatch & SBAM_TYPE_MASK;
     13534+       ASSERT(type < 3);
     13535+
     13536+       base = 0;
     13537+
     13538+       if (type == 0) {
     13539+               base = admatch & SBAM_BASE0_MASK;
     13540+       } else if (type == 1) {
     13541+               ASSERT(!(admatch & SBAM_ADNEG));        /* neg not supported */
     13542+               base = admatch & SBAM_BASE1_MASK;
     13543+       } else if (type == 2) {
     13544+               ASSERT(!(admatch & SBAM_ADNEG));        /* neg not supported */
     13545+               base = admatch & SBAM_BASE2_MASK;
     13546+       }
     13547+
     13548+       return (base);
     13549+}
     13550+
     13551+uint32
     13552+sb_size(uint32 admatch)
     13553+{
     13554+       uint32 size;
     13555+       uint type;
     13556+
     13557+       type = admatch & SBAM_TYPE_MASK;
     13558+       ASSERT(type < 3);
     13559+
     13560+       size = 0;
     13561+
     13562+       if (type == 0) {
     13563+               size = 1 << (((admatch & SBAM_ADINT0_MASK) >> SBAM_ADINT0_SHIFT) + 1);
     13564+       } else if (type == 1) {
     13565+               ASSERT(!(admatch & SBAM_ADNEG));        /* neg not supported */
     13566+               size = 1 << (((admatch & SBAM_ADINT1_MASK) >> SBAM_ADINT1_SHIFT) + 1);
     13567+       } else if (type == 2) {
     13568+               ASSERT(!(admatch & SBAM_ADNEG));        /* neg not supported */
     13569+               size = 1 << (((admatch & SBAM_ADINT2_MASK) >> SBAM_ADINT2_SHIFT) + 1);
     13570+       }
     13571+
     13572+       return (size);
     13573+}
     13574+
     13575+/* return the core-type instantiation # of the current core */
     13576+uint
     13577+sb_coreunit(void *sbh)
     13578+{
     13579+       sb_info_t *si;
     13580+       uint idx;
     13581+       uint coreid;
     13582+       uint coreunit;
     13583+       uint i;
     13584+
     13585+       si = SB_INFO(sbh);
     13586+       coreunit = 0;
     13587+
     13588+       idx = si->curidx;
     13589+
     13590+       ASSERT(GOODREGS(si->curmap));
     13591+       coreid = sb_coreid(sbh);
     13592+
     13593+       /* count the cores of our type */
     13594+       for (i = 0; i < idx; i++)
     13595+               if (si->coreid[i] == coreid)
     13596+                       coreunit++;
     13597+
     13598+       return (coreunit);
     13599+}
     13600+
     13601+static INLINE uint32
     13602+factor6(uint32 x)
     13603+{
     13604+       switch (x) {
     13605+       case CC_F6_2:   return 2;
     13606+       case CC_F6_3:   return 3;
     13607+       case CC_F6_4:   return 4;
     13608+       case CC_F6_5:   return 5;
     13609+       case CC_F6_6:   return 6;
     13610+       case CC_F6_7:   return 7;
     13611+       default:        return 0;
     13612+       }
     13613+}
     13614+
     13615+/* calculate the speed the SB would run at given a set of clockcontrol values */
     13616+uint32
     13617+sb_clock_rate(uint32 pll_type, uint32 n, uint32 m)
     13618+{
     13619+       uint32 n1, n2, clock, m1, m2, m3, mc;
     13620+
     13621+       n1 = n & CN_N1_MASK;
     13622+       n2 = (n & CN_N2_MASK) >> CN_N2_SHIFT;
     13623+
     13624+       if (pll_type == PLL_TYPE6) {
     13625+               if (m & CC_T6_MMASK)
     13626+                       return CC_T6_M1;
     13627+               else
     13628+                       return CC_T6_M0;
     13629+       } else if ((pll_type == PLL_TYPE1) ||
     13630+                  (pll_type == PLL_TYPE3) ||
     13631+                  (pll_type == PLL_TYPE4) ||
     13632+                  (pll_type == PLL_TYPE7)) {
     13633+               n1 = factor6(n1);
     13634+               n2 += CC_F5_BIAS;
     13635+       } else if (pll_type == PLL_TYPE2) {
     13636+               n1 += CC_T2_BIAS;
     13637+               n2 += CC_T2_BIAS;
     13638+               ASSERT((n1 >= 2) && (n1 <= 7));
     13639+               ASSERT((n2 >= 5) && (n2 <= 23));
     13640+       } else if (pll_type == PLL_TYPE5) {
     13641+               return (100000000);
     13642+       } else
     13643+               ASSERT((pll_type >= PLL_TYPE1) && (pll_type <= PLL_TYPE4));
     13644+       /* PLL types 3 and 7 use BASE2 (25Mhz) */
     13645+       if ((pll_type == PLL_TYPE3) ||
     13646+           (pll_type == PLL_TYPE7)) {
     13647+               clock =  CC_CLOCK_BASE2 * n1 * n2;
     13648+       }
     13649+       else
     13650+               clock = CC_CLOCK_BASE1 * n1 * n2;
     13651+
     13652+       if (clock == 0)
     13653+               return 0;
     13654+
     13655+       m1 = m & CC_M1_MASK;
     13656+       m2 = (m & CC_M2_MASK) >> CC_M2_SHIFT;
     13657+       m3 = (m & CC_M3_MASK) >> CC_M3_SHIFT;
     13658+       mc = (m & CC_MC_MASK) >> CC_MC_SHIFT;
     13659+
     13660+       if ((pll_type == PLL_TYPE1) ||
     13661+           (pll_type == PLL_TYPE3) ||
     13662+           (pll_type == PLL_TYPE4) ||
     13663+           (pll_type == PLL_TYPE7)) {
     13664+               m1 = factor6(m1);
     13665+               if ((pll_type == PLL_TYPE1) || (pll_type == PLL_TYPE3))
     13666+                       m2 += CC_F5_BIAS;
     13667+               else
     13668+                       m2 = factor6(m2);
     13669+               m3 = factor6(m3);
     13670+
     13671+               switch (mc) {
     13672+               case CC_MC_BYPASS:      return (clock);
     13673+               case CC_MC_M1:          return (clock / m1);
     13674+               case CC_MC_M1M2:        return (clock / (m1 * m2));
     13675+               case CC_MC_M1M2M3:      return (clock / (m1 * m2 * m3));
     13676+               case CC_MC_M1M3:        return (clock / (m1 * m3));
     13677+               default:                return (0);
     13678+               }
     13679+       } else {
     13680+               ASSERT(pll_type == PLL_TYPE2);
     13681+
     13682+               m1 += CC_T2_BIAS;
     13683+               m2 += CC_T2M2_BIAS;
     13684+               m3 += CC_T2_BIAS;
     13685+               ASSERT((m1 >= 2) && (m1 <= 7));
     13686+               ASSERT((m2 >= 3) && (m2 <= 10));
     13687+               ASSERT((m3 >= 2) && (m3 <= 7));
     13688+
     13689+               if ((mc & CC_T2MC_M1BYP) == 0)
     13690+                       clock /= m1;
     13691+               if ((mc & CC_T2MC_M2BYP) == 0)
     13692+                       clock /= m2;
     13693+               if ((mc & CC_T2MC_M3BYP) == 0)
     13694+                       clock /= m3;
     13695+
     13696+               return(clock);
     13697+       }
     13698+}
     13699+
     13700+/* returns the current speed the SB is running at */
     13701+uint32
     13702+sb_clock(void *sbh)
     13703+{
     13704+       sb_info_t *si;
     13705+       extifregs_t *eir;
     13706+       chipcregs_t *cc;
     13707+       uint32 n, m;
     13708+       uint idx;
     13709+       uint32 pll_type, rate;
     13710+       uint intr_val = 0;
     13711+
     13712+       si = SB_INFO(sbh);
     13713+       idx = si->curidx;
     13714+       pll_type = PLL_TYPE1;
     13715+
     13716+       INTR_OFF(si, intr_val);
     13717+
     13718+       /* switch to extif or chipc core */
     13719+       if ((eir = (extifregs_t *) sb_setcore(sbh, SB_EXTIF, 0))) {
     13720+               n = R_REG(&eir->clockcontrol_n);
     13721+               m = R_REG(&eir->clockcontrol_sb);
     13722+       } else if ((cc = (chipcregs_t *) sb_setcore(sbh, SB_CC, 0))) {
     13723+               pll_type = R_REG(&cc->capabilities) & CAP_PLL_MASK;
     13724+               n = R_REG(&cc->clockcontrol_n);
     13725+               if (pll_type == PLL_TYPE6)
     13726+                       m = R_REG(&cc->clockcontrol_mips);
     13727+               else if ((pll_type == PLL_TYPE3) && (BCMINIT(sb_chip)(sbh) != BCM5365_DEVICE_ID))
     13728+                       m = R_REG(&cc->clockcontrol_m2);
     13729+               else
     13730+                       m = R_REG(&cc->clockcontrol_sb);
     13731+       } else {
     13732+               INTR_RESTORE(si, intr_val);
     13733+               return 0;
     13734+       }
     13735+
     13736+       if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID) {
     13737+               rate = 100000000;
     13738+       } else {
     13739+               /* calculate rate */
     13740+               rate = sb_clock_rate(pll_type, n, m);
     13741+               if (pll_type == PLL_TYPE3)
     13742+                       rate = rate / 2;
     13743+       }
     13744+
     13745+
     13746+       /* switch back to previous core */
     13747+       sb_setcoreidx(sbh, idx);
     13748+
     13749+       INTR_RESTORE(si, intr_val);
     13750+
     13751+       return rate;
     13752+}
     13753+
     13754+/* change logical "focus" to the gpio core for optimized access */
     13755+void*
     13756+sb_gpiosetcore(void *sbh)
     13757+{
     13758+       sb_info_t *si;
     13759+
     13760+       si = SB_INFO(sbh);
     13761+
     13762+       return (sb_setcoreidx(sbh, si->gpioidx));
     13763+}
     13764+
     13765+/* mask&set gpiocontrol bits */
     13766+uint32
     13767+sb_gpiocontrol(void *sbh, uint32 mask, uint32 val)
     13768+{
     13769+       sb_info_t *si;
     13770+       uint regoff;
     13771+
     13772+       si = SB_INFO(sbh);
     13773+       regoff = 0;
     13774+
     13775+       switch (si->gpioid) {
     13776+       case SB_CC:
     13777+               regoff = OFFSETOF(chipcregs_t, gpiocontrol);
     13778+               break;
     13779+
     13780+       case SB_PCI:
     13781+               regoff = OFFSETOF(sbpciregs_t, gpiocontrol);
     13782+               break;
     13783+
     13784+       case SB_EXTIF:
     13785+               return (0);
     13786+       }
     13787+
     13788+       return (sb_corereg(sbh, si->gpioidx, regoff, mask, val));
     13789+}
     13790+
     13791+/* mask&set gpio output enable bits */
     13792+uint32
     13793+sb_gpioouten(void *sbh, uint32 mask, uint32 val)
     13794+{
     13795+       sb_info_t *si;
     13796+       uint regoff;
     13797+
     13798+       si = SB_INFO(sbh);
     13799+       regoff = 0;
     13800+
     13801+       switch (si->gpioid) {
     13802+       case SB_CC:
     13803+               regoff = OFFSETOF(chipcregs_t, gpioouten);
     13804+               break;
     13805+
     13806+       case SB_PCI:
     13807+               regoff = OFFSETOF(sbpciregs_t, gpioouten);
     13808+               break;
     13809+
     13810+       case SB_EXTIF:
     13811+               regoff = OFFSETOF(extifregs_t, gpio[0].outen);
     13812+               break;
     13813+       }
     13814+
     13815+       return (sb_corereg(sbh, si->gpioidx, regoff, mask, val));
     13816+}
     13817+
     13818+/* mask&set gpio output bits */
     13819+uint32
     13820+sb_gpioout(void *sbh, uint32 mask, uint32 val)
     13821+{
     13822+       sb_info_t *si;
     13823+       uint regoff;
     13824+
     13825+       si = SB_INFO(sbh);
     13826+       regoff = 0;
     13827+
     13828+       switch (si->gpioid) {
     13829+       case SB_CC:
     13830+               regoff = OFFSETOF(chipcregs_t, gpioout);
     13831+               break;
     13832+
     13833+       case SB_PCI:
     13834+               regoff = OFFSETOF(sbpciregs_t, gpioout);
     13835+               break;
     13836+
     13837+       case SB_EXTIF:
     13838+               regoff = OFFSETOF(extifregs_t, gpio[0].out);
     13839+               break;
     13840+       }
     13841+
     13842+       return (sb_corereg(sbh, si->gpioidx, regoff, mask, val));
     13843+}
     13844+
     13845+/* return the current gpioin register value */
     13846+uint32
     13847+sb_gpioin(void *sbh)
     13848+{
     13849+       sb_info_t *si;
     13850+       uint regoff;
     13851+
     13852+       si = SB_INFO(sbh);
     13853+       regoff = 0;
     13854+
     13855+       switch (si->gpioid) {
     13856+       case SB_CC:
     13857+               regoff = OFFSETOF(chipcregs_t, gpioin);
     13858+               break;
     13859+
     13860+       case SB_PCI:
     13861+               regoff = OFFSETOF(sbpciregs_t, gpioin);
     13862+               break;
     13863+
     13864+       case SB_EXTIF:
     13865+               regoff = OFFSETOF(extifregs_t, gpioin);
     13866+               break;
     13867+       }
     13868+
     13869+       return (sb_corereg(sbh, si->gpioidx, regoff, 0, 0));
     13870+}
     13871+
     13872+/* mask&set gpio interrupt polarity bits */
     13873+uint32
     13874+sb_gpiointpolarity(void *sbh, uint32 mask, uint32 val)
     13875+{
     13876+       sb_info_t *si;
     13877+       uint regoff;
     13878+
     13879+       si = SB_INFO(sbh);
     13880+       regoff = 0;
     13881+
     13882+       switch (si->gpioid) {
     13883+       case SB_CC:
     13884+               regoff = OFFSETOF(chipcregs_t, gpiointpolarity);
     13885+               break;
     13886+
     13887+       case SB_PCI:
     13888+               /* pci gpio implementation does not support interrupt polarity */
     13889+               ASSERT(0);
     13890+               break;
     13891+
     13892+       case SB_EXTIF:
     13893+               regoff = OFFSETOF(extifregs_t, gpiointpolarity);
     13894+               break;
     13895+       }
     13896+
     13897+       return (sb_corereg(sbh, si->gpioidx, regoff, mask, val));
     13898+}
     13899+
     13900+/* mask&set gpio interrupt mask bits */
     13901+uint32
     13902+sb_gpiointmask(void *sbh, uint32 mask, uint32 val)
     13903+{
     13904+       sb_info_t *si;
     13905+       uint regoff;
     13906+
     13907+       si = SB_INFO(sbh);
     13908+       regoff = 0;
     13909+
     13910+       switch (si->gpioid) {
     13911+       case SB_CC:
     13912+               regoff = OFFSETOF(chipcregs_t, gpiointmask);
     13913+               break;
     13914+
     13915+       case SB_PCI:
     13916+               /* pci gpio implementation does not support interrupt mask */
     13917+               ASSERT(0);
     13918+               break;
     13919+
     13920+       case SB_EXTIF:
     13921+               regoff = OFFSETOF(extifregs_t, gpiointmask);
     13922+               break;
     13923+       }
     13924+
     13925+       return (sb_corereg(sbh, si->gpioidx, regoff, mask, val));
     13926+}
     13927+
     13928+
     13929+/*
     13930+ * Return the slow clock source.
     13931+ * Three sources of SLOW CLOCK: LPO, Xtal, PCI
    1926713932+ */
    19268 +
    19269 +
    19270 +/* 32 bits addressing */
    19271 +
    19272 +/* dma registers per channel(xmt or rcv) */
    19273 +typedef volatile struct {
    19274 +       uint32  control;                /* enable, et al */
    19275 +       uint32  addr;                   /* descriptor ring base address (4K aligned) */
    19276 +       uint32  ptr;                    /* last descriptor posted to chip */
    19277 +       uint32  status;                 /* current active descriptor, et al */
    19278 +} dma32regs_t;
    19279 +
    19280 +typedef volatile struct {
    19281 +       dma32regs_t     xmt;            /* dma tx channel */
    19282 +       dma32regs_t     rcv;            /* dma rx channel */
    19283 +} dma32regp_t;
    19284 +
    19285 +typedef volatile struct {      /* diag access */
    19286 +       uint32  fifoaddr;               /* diag address */
    19287 +       uint32  fifodatalow;            /* low 32bits of data */
    19288 +       uint32  fifodatahigh;           /* high 32bits of data */
    19289 +       uint32  pad;                    /* reserved */
    19290 +} dma32diag_t;
     13933+static uint
     13934+sb_slowclk_src(void *sbh)
     13935+{
     13936+       sb_info_t *si;
     13937+       chipcregs_t *cc;
     13938+       uint32 v;
     13939+
     13940+       si = SB_INFO(sbh);
     13941+
     13942+       ASSERT(sb_coreid(sbh) == SB_CC);
     13943+
     13944+       if (si->ccrev < 6) {
     13945+               switch (BUSTYPE(si->bustype)) {
     13946+                       case PCMCIA_BUS: return (SCC_SS_XTAL);
     13947+                       case PCI_BUS:
     13948+                               v = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32));
     13949+                               if (v & PCI_CFG_GPIO_SCS)
     13950+                                       return (SCC_SS_PCI);
     13951+                               else
     13952+                                       return (SCC_SS_XTAL);
     13953+                       default: return (SCC_SS_XTAL);
     13954+               }
     13955+       } else if (si->ccrev < 10) {
     13956+               cc = (chipcregs_t*) sb_setcoreidx(sbh, si->curidx);
     13957+               v = R_REG(&cc->slow_clk_ctl) & SCC_SS_MASK;
     13958+               return (v);
     13959+       } else {
     13960+               return (SCC_SS_XTAL);
     13961+       }
     13962+}
    1929113963+
    1929213964+/*
    19293 + * DMA Descriptor
    19294 + * Descriptors are only read by the hardware, never written back.
     13965+ * Return the slowclock min or max frequency.
     13966+ * Three sources of SLOW CLOCK:
     13967+ *     1. On Chip LPO          -       32khz or 160khz
     13968+ *     2. On Chip Xtal OSC     -       20mhz/4*(divider+1)
     13969+ *     3. External PCI clock   -       66mhz/4*(divider+1)
    1929513970+ */
    19296 +typedef volatile struct {
    19297 +       uint32  ctrl;           /* misc control bits & bufcount */
    19298 +       uint32  addr;           /* data buffer address */
    19299 +} dma32dd_t;
    19300 +
    19301 +/*
    19302 + * Each descriptor ring must be 4096byte aligned, and fit within a single 4096byte page.
    19303 + */
    19304 +#define        D32MAXRINGSZ    4096
    19305 +#define        D32RINGALIGN    4096
    19306 +#define        D32MAXDD        (D32MAXRINGSZ / sizeof (dma32dd_t))
    19307 +
    19308 +/* transmit channel control */
    19309 +#define        XC_XE           ((uint32)1 << 0)        /* transmit enable */
    19310 +#define        XC_SE           ((uint32)1 << 1)        /* transmit suspend request */
    19311 +#define        XC_LE           ((uint32)1 << 2)        /* loopback enable */
    19312 +#define        XC_FL           ((uint32)1 << 4)        /* flush request */
    19313 +#define        XC_AE           ((uint32)3 << 16)       /* address extension bits */
    19314 +#define        XC_AE_SHIFT     16
    19315 +
    19316 +/* transmit descriptor table pointer */
    19317 +#define        XP_LD_MASK      0xfff                   /* last valid descriptor */
    19318 +
    19319 +/* transmit channel status */
    19320 +#define        XS_CD_MASK      0x0fff                  /* current descriptor pointer */
    19321 +#define        XS_XS_MASK      0xf000                  /* transmit state */
    19322 +#define        XS_XS_SHIFT     12
    19323 +#define        XS_XS_DISABLED  0x0000                  /* disabled */
    19324 +#define        XS_XS_ACTIVE    0x1000                  /* active */
    19325 +#define        XS_XS_IDLE      0x2000                  /* idle wait */
    19326 +#define        XS_XS_STOPPED   0x3000                  /* stopped */
    19327 +#define        XS_XS_SUSP      0x4000                  /* suspend pending */
    19328 +#define        XS_XE_MASK      0xf0000                 /* transmit errors */
    19329 +#define        XS_XE_SHIFT     16
    19330 +#define        XS_XE_NOERR     0x00000                 /* no error */
    19331 +#define        XS_XE_DPE       0x10000                 /* descriptor protocol error */
    19332 +#define        XS_XE_DFU       0x20000                 /* data fifo underrun */
    19333 +#define        XS_XE_BEBR      0x30000                 /* bus error on buffer read */
    19334 +#define        XS_XE_BEDA      0x40000                 /* bus error on descriptor access */
    19335 +#define        XS_AD_MASK      0xfff00000              /* active descriptor */
    19336 +#define        XS_AD_SHIFT     20
    19337 +
    19338 +/* receive channel control */
    19339 +#define        RC_RE           ((uint32)1 << 0)        /* receive enable */
    19340 +#define        RC_RO_MASK      0xfe                    /* receive frame offset */
    19341 +#define        RC_RO_SHIFT     1
    19342 +#define        RC_FM           ((uint32)1 << 8)        /* direct fifo receive (pio) mode */
    19343 +#define        RC_AE           ((uint32)3 << 16)       /* address extension bits */
    19344 +#define        RC_AE_SHIFT     16
    19345 +
    19346 +/* receive descriptor table pointer */
    19347 +#define        RP_LD_MASK      0xfff                   /* last valid descriptor */
    19348 +
    19349 +/* receive channel status */
    19350 +#define        RS_CD_MASK      0x0fff                  /* current descriptor pointer */
    19351 +#define        RS_RS_MASK      0xf000                  /* receive state */
    19352 +#define        RS_RS_SHIFT     12
    19353 +#define        RS_RS_DISABLED  0x0000                  /* disabled */
    19354 +#define        RS_RS_ACTIVE    0x1000                  /* active */
    19355 +#define        RS_RS_IDLE      0x2000                  /* idle wait */
    19356 +#define        RS_RS_STOPPED   0x3000                  /* reserved */
    19357 +#define        RS_RE_MASK      0xf0000                 /* receive errors */
    19358 +#define        RS_RE_SHIFT     16
    19359 +#define        RS_RE_NOERR     0x00000                 /* no error */
    19360 +#define        RS_RE_DPE       0x10000                 /* descriptor protocol error */
    19361 +#define        RS_RE_DFO       0x20000                 /* data fifo overflow */
    19362 +#define        RS_RE_BEBW      0x30000                 /* bus error on buffer write */
    19363 +#define        RS_RE_BEDA      0x40000                 /* bus error on descriptor access */
    19364 +#define        RS_AD_MASK      0xfff00000              /* active descriptor */
    19365 +#define        RS_AD_SHIFT     20
    19366 +
    19367 +/* fifoaddr */
    19368 +#define        FA_OFF_MASK     0xffff                  /* offset */
    19369 +#define        FA_SEL_MASK     0xf0000                 /* select */
    19370 +#define        FA_SEL_SHIFT    16
    19371 +#define        FA_SEL_XDD      0x00000                 /* transmit dma data */
    19372 +#define        FA_SEL_XDP      0x10000                 /* transmit dma pointers */
    19373 +#define        FA_SEL_RDD      0x40000                 /* receive dma data */
    19374 +#define        FA_SEL_RDP      0x50000                 /* receive dma pointers */
    19375 +#define        FA_SEL_XFD      0x80000                 /* transmit fifo data */
    19376 +#define        FA_SEL_XFP      0x90000                 /* transmit fifo pointers */
    19377 +#define        FA_SEL_RFD      0xc0000                 /* receive fifo data */
    19378 +#define        FA_SEL_RFP      0xd0000                 /* receive fifo pointers */
    19379 +#define        FA_SEL_RSD      0xe0000                 /* receive frame status data */
    19380 +#define        FA_SEL_RSP      0xf0000                 /* receive frame status pointers */
    19381 +
    19382 +/* descriptor control flags */
    19383 +#define        CTRL_BC_MASK    0x1fff                  /* buffer byte count */
    19384 +#define        CTRL_AE         ((uint32)3 << 16)       /* address extension bits */
    19385 +#define        CTRL_AE_SHIFT   16
    19386 +#define        CTRL_EOT        ((uint32)1 << 28)       /* end of descriptor table */
    19387 +#define        CTRL_IOC        ((uint32)1 << 29)       /* interrupt on completion */
    19388 +#define        CTRL_EOF        ((uint32)1 << 30)       /* end of frame */
    19389 +#define        CTRL_SOF        ((uint32)1 << 31)       /* start of frame */
    19390 +
    19391 +/* control flags in the range [27:20] are core-specific and not defined here */
    19392 +#define        CTRL_CORE_MASK  0x0ff00000
    19393 +
    19394 +/* 64 bits addressing */
    19395 +
    19396 +/* dma registers per channel(xmt or rcv) */
    19397 +typedef volatile struct {
    19398 +       uint32  control;                /* enable, et al */
    19399 +       uint32  ptr;                    /* last descriptor posted to chip */
    19400 +       uint32  addrlow;                /* descriptor ring base address low 32-bits (8K aligned) */
    19401 +       uint32  addrhigh;               /* descriptor ring base address bits 63:32 (8K aligned) */
    19402 +       uint32  status0;                /* current descriptor, xmt state */
    19403 +       uint32  status1;                /* active descriptor, xmt error */
    19404 +} dma64regs_t;
    19405 +
    19406 +typedef volatile struct {
    19407 +       dma64regs_t     tx;             /* dma64 tx channel */
    19408 +       dma64regs_t     rx;             /* dma64 rx channel */
    19409 +} dma64regp_t;
    19410 +
    19411 +typedef volatile struct {              /* diag access */
    19412 +       uint32  fifoaddr;               /* diag address */
    19413 +       uint32  fifodatalow;            /* low 32bits of data */
    19414 +       uint32  fifodatahigh;           /* high 32bits of data */
    19415 +       uint32  pad;                    /* reserved */
    19416 +} dma64diag_t;
    19417 +
    19418 +/*
    19419 + * DMA Descriptor
    19420 + * Descriptors are only read by the hardware, never written back.
    19421 + */
    19422 +typedef volatile struct {
    19423 +       uint32  ctrl1;          /* misc control bits & bufcount */
    19424 +       uint32  ctrl2;          /* buffer count and address extension */
    19425 +       uint32  addrlow;        /* memory address of the date buffer, bits 31:0 */
    19426 +       uint32  addrhigh;       /* memory address of the date buffer, bits 63:32 */
    19427 +} dma64dd_t;
    19428 +
    19429 +/*
    19430 + * Each descriptor ring must be 8kB aligned, and fit within a contiguous 8kB physical addresss.
    19431 + */
    19432 +#define        D64MAXRINGSZ    8192
    19433 +#define        D64RINGALIGN    8192
    19434 +#define        D64MAXDD        (D64MAXRINGSZ / sizeof (dma64dd_t))
    19435 +
    19436 +/* transmit channel control */
    19437 +#define        D64_XC_XE               0x00000001      /* transmit enable */
    19438 +#define        D64_XC_SE               0x00000002      /* transmit suspend request */
    19439 +#define        D64_XC_LE               0x00000004      /* loopback enable */
    19440 +#define        D64_XC_FL               0x00000010      /* flush request */
    19441 +#define        D64_XC_AE               0x00030000      /* address extension bits */
    19442 +#define        D64_XC_AE_SHIFT         16
    19443 +
    19444 +/* transmit descriptor table pointer */
    19445 +#define        D64_XP_LD_MASK          0x00000fff      /* last valid descriptor */
    19446 +
    19447 +/* transmit channel status */
    19448 +#define        D64_XS0_CD_MASK         0x00001fff      /* current descriptor pointer */
    19449 +#define        D64_XS0_XS_MASK         0xf0000000      /* transmit state */
    19450 +#define        D64_XS0_XS_SHIFT                28
    19451 +#define        D64_XS0_XS_DISABLED     0x00000000      /* disabled */
    19452 +#define        D64_XS0_XS_ACTIVE       0x10000000      /* active */
    19453 +#define        D64_XS0_XS_IDLE         0x20000000      /* idle wait */
    19454 +#define        D64_XS0_XS_STOPPED      0x30000000      /* stopped */
    19455 +#define        D64_XS0_XS_SUSP         0x40000000      /* suspend pending */
    19456 +
    19457 +#define        D64_XS1_AD_MASK         0x0001ffff      /* active descriptor */
    19458 +#define        D64_XS1_XE_MASK         0xf0000000      /* transmit errors */
    19459 +#define        D64_XS1_XE_SHIFT                28
    19460 +#define        D64_XS1_XE_NOERR        0x00000000      /* no error */
    19461 +#define        D64_XS1_XE_DPE          0x10000000      /* descriptor protocol error */
    19462 +#define        D64_XS1_XE_DFU          0x20000000      /* data fifo underrun */
    19463 +#define        D64_XS1_XE_DTE          0x30000000      /* data transfer error */
    19464 +#define        D64_XS1_XE_DESRE        0x40000000      /* descriptor read error */
    19465 +#define        D64_XS1_XE_COREE        0x50000000      /* core error */
    19466 +
    19467 +/* receive channel control */
    19468 +#define        D64_RC_RE               0x00000001      /* receive enable */
    19469 +#define        D64_RC_RO_MASK          0x000000fe      /* receive frame offset */
    19470 +#define        D64_RC_RO_SHIFT         1
    19471 +#define        D64_RC_FM               0x00000100      /* direct fifo receive (pio) mode */
    19472 +#define        D64_RC_AE               0x00030000      /* address extension bits */
    19473 +#define        D64_RC_AE_SHIFT         16
    19474 +
    19475 +/* receive descriptor table pointer */
    19476 +#define        D64_RP_LD_MASK          0x00000fff      /* last valid descriptor */
    19477 +
    19478 +/* receive channel status */
    19479 +#define        D64_RS0_CD_MASK         0x00001fff      /* current descriptor pointer */
    19480 +#define        D64_RS0_RS_MASK         0xf0000000      /* receive state */
    19481 +#define        D64_RS0_RS_SHIFT                28
    19482 +#define        D64_RS0_RS_DISABLED     0x00000000      /* disabled */
    19483 +#define        D64_RS0_RS_ACTIVE       0x10000000      /* active */
    19484 +#define        D64_RS0_RS_IDLE         0x20000000      /* idle wait */
    19485 +#define        D64_RS0_RS_STOPPED      0x30000000      /* stopped */
    19486 +#define        D64_RS0_RS_SUSP         0x40000000      /* suspend pending */
    19487 +
    19488 +#define        D64_RS1_AD_MASK         0x0001ffff      /* active descriptor */
    19489 +#define        D64_RS1_RE_MASK         0xf0000000      /* receive errors */
    19490 +#define        D64_RS1_RE_SHIFT                28
    19491 +#define        D64_RS1_RE_NOERR        0x00000000      /* no error */
    19492 +#define        D64_RS1_RE_DPO          0x10000000      /* descriptor protocol error */
    19493 +#define        D64_RS1_RE_DFU          0x20000000      /* data fifo overflow */
    19494 +#define        D64_RS1_RE_DTE          0x30000000      /* data transfer error */
    19495 +#define        D64_RS1_RE_DESRE        0x40000000      /* descriptor read error */
    19496 +#define        D64_RS1_RE_COREE        0x50000000      /* core error */
    19497 +
    19498 +/* fifoaddr */
    19499 +#define        D64_FA_OFF_MASK         0xffff          /* offset */
    19500 +#define        D64_FA_SEL_MASK         0xf0000         /* select */
    19501 +#define        D64_FA_SEL_SHIFT        16
    19502 +#define        D64_FA_SEL_XDD          0x00000         /* transmit dma data */
    19503 +#define        D64_FA_SEL_XDP          0x10000         /* transmit dma pointers */
    19504 +#define        D64_FA_SEL_RDD          0x40000         /* receive dma data */
    19505 +#define        D64_FA_SEL_RDP          0x50000         /* receive dma pointers */
    19506 +#define        D64_FA_SEL_XFD          0x80000         /* transmit fifo data */
    19507 +#define        D64_FA_SEL_XFP          0x90000         /* transmit fifo pointers */
    19508 +#define        D64_FA_SEL_RFD          0xc0000         /* receive fifo data */
    19509 +#define        D64_FA_SEL_RFP          0xd0000         /* receive fifo pointers */
    19510 +#define        D64_FA_SEL_RSD          0xe0000         /* receive frame status data */
    19511 +#define        D64_FA_SEL_RSP          0xf0000         /* receive frame status pointers */
    19512 +
    19513 +/* descriptor control flags 1 */
    19514 +#define        D64_CTRL1_EOT           ((uint32)1 << 28)       /* end of descriptor table */
    19515 +#define        D64_CTRL1_IOC           ((uint32)1 << 29)       /* interrupt on completion */
    19516 +#define        D64_CTRL1_EOF           ((uint32)1 << 30)       /* end of frame */
    19517 +#define        D64_CTRL1_SOF           ((uint32)1 << 31)       /* start of frame */
    19518 +
    19519 +/* descriptor control flags 2 */
    19520 +#define        D64_CTRL2_BC_MASK       0x00007fff      /* buffer byte count mask */
    19521 +#define        D64_CTRL2_AE            0x00030000      /* address extension bits */
    19522 +#define        D64_CTRL2_AE_SHIFT      16
    19523 +
    19524 +/* control flags in the range [27:20] are core-specific and not defined here */
    19525 +#define        D64_CTRL_CORE_MASK      0x0ff00000
    19526 +
    19527 +
    19528 +#endif /* _sbhnddma_h_ */
    19529 diff -urN linux.old/drivers/parport/Config.in linux.dev/drivers/parport/Config.in
    19530 --- linux.old/drivers/parport/Config.in 2006-04-27 18:04:38.000000000 +0200
    19531 +++ linux.dev/drivers/parport/Config.in 2006-04-27 19:24:19.000000000 +0200
     13971+static uint
     13972+sb_slowclk_freq(void *sbh, bool max)
     13973+{
     13974+       sb_info_t *si;
     13975+       chipcregs_t *cc;
     13976+       uint32 slowclk;
     13977+       uint div;
     13978+
     13979+       si = SB_INFO(sbh);
     13980+
     13981+       ASSERT(sb_coreid(sbh) == SB_CC);
     13982+
     13983+       cc = (chipcregs_t*) sb_setcoreidx(sbh, si->curidx);
     13984+
     13985+       /* shouldn't be here unless we've established the chip has dynamic power control */
     13986+       ASSERT(R_REG(&cc->capabilities) & CAP_PWR_CTL);
     13987+
     13988+       slowclk = sb_slowclk_src(sbh);
     13989+       if (si->ccrev < 6) {
     13990+               if (slowclk == SCC_SS_PCI)
     13991+                       return (max? (PCIMAXFREQ/64) : (PCIMINFREQ/64));
     13992+               else
     13993+                       return (max? (XTALMAXFREQ/32) : (XTALMINFREQ/32));
     13994+       } else if (si->ccrev < 10) {
     13995+               div = 4 * (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >> SCC_CD_SHF) + 1);
     13996+               if (slowclk == SCC_SS_LPO)
     13997+                       return (max? LPOMAXFREQ : LPOMINFREQ);
     13998+               else if (slowclk == SCC_SS_XTAL)
     13999+                       return (max? (XTALMAXFREQ/div) : (XTALMINFREQ/div));
     14000+               else if (slowclk == SCC_SS_PCI)
     14001+                       return (max? (PCIMAXFREQ/div) : (PCIMINFREQ/div));
     14002+               else
     14003+                       ASSERT(0);
     14004+       } else {
     14005+               /* Chipc rev 10 is InstaClock */
     14006+               div = R_REG(&cc->system_clk_ctl) >> SYCC_CD_SHF;
     14007+               div = 4 * (div + 1);
     14008+               return (max ? XTALMAXFREQ : (XTALMINFREQ/div));
     14009+       }
     14010+       return (0);
     14011+}
     14012+
     14013+static void
     14014+sb_pwrctl_setdelay(void *sbh, void *chipcregs)
     14015+{
     14016+       sb_info_t *si;
     14017+       chipcregs_t * cc;
     14018+       uint slowmaxfreq, pll_delay, slowclk;
     14019+       uint pll_on_delay, fref_sel_delay;
     14020+
     14021+       si = SB_INFO(sbh);
     14022+       pll_delay = PLL_DELAY;
     14023+
     14024+       /* If the slow clock is not sourced by the xtal then add the xtal_on_delay
     14025+        * since the xtal will also be powered down by dynamic power control logic.
     14026+        */
     14027+       slowclk = sb_slowclk_src(sbh);
     14028+       if (slowclk != SCC_SS_XTAL)
     14029+               pll_delay += XTAL_ON_DELAY;
     14030+
     14031+       /* Starting with 4318 it is ILP that is used for the delays */
     14032+       slowmaxfreq = sb_slowclk_freq(sbh, (si->ccrev >= 10) ? FALSE : TRUE);
     14033+
     14034+       pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
     14035+       fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
     14036+
     14037+       cc = (chipcregs_t *)chipcregs;
     14038+       W_REG(&cc->pll_on_delay, pll_on_delay);
     14039+       W_REG(&cc->fref_sel_delay, fref_sel_delay);
     14040+}
     14041+
     14042+/* set or get slow clock divider */
     14043+int
     14044+sb_pwrctl_slowclk(void *sbh, bool set, uint *div)
     14045+{
     14046+       sb_info_t *si;
     14047+       uint origidx;
     14048+       chipcregs_t *cc;
     14049+       uint intr_val = 0;
     14050+       uint err = 0;
     14051+       
     14052+       si = SB_INFO(sbh);
     14053+
     14054+       /* chipcommon cores prior to rev6 don't support slowclkcontrol */
     14055+       if (si->ccrev < 6)
     14056+               return 1;
     14057+
     14058+       /* chipcommon cores rev10 are a whole new ball game */
     14059+       if (si->ccrev >= 10)
     14060+               return 1;
     14061+
     14062+       if (set && ((*div % 4) || (*div < 4)))
     14063+               return 2;
     14064+       
     14065+       INTR_OFF(si, intr_val);
     14066+       origidx = si->curidx;
     14067+       cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0);
     14068+       ASSERT(cc != NULL);
     14069+       
     14070+       if (!(R_REG(&cc->capabilities) & CAP_PWR_CTL)) {
     14071+               err = 3;
     14072+               goto done;
     14073+       }
     14074+
     14075+       if (set) {
     14076+               SET_REG(&cc->slow_clk_ctl, SCC_CD_MASK, ((*div / 4 - 1) << SCC_CD_SHF));
     14077+               sb_pwrctl_setdelay(sbh, (void *)cc);
     14078+       } else
     14079+               *div = 4 * (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >> SCC_CD_SHF) + 1);
     14080+
     14081+done:
     14082+       sb_setcoreidx(sbh, origidx);
     14083+       INTR_RESTORE(si, intr_val);
     14084+       return err;
     14085+}
     14086+
     14087+/* initialize power control delay registers */
     14088+void
     14089+sb_pwrctl_init(void *sbh)
     14090+{
     14091+       sb_info_t *si;
     14092+       uint origidx;
     14093+       chipcregs_t *cc;
     14094+
     14095+       si = SB_INFO(sbh);
     14096+
     14097+       origidx = si->curidx;
     14098+
     14099+       if ((cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0)) == NULL)
     14100+               return;
     14101+
     14102+       if (!(R_REG(&cc->capabilities) & CAP_PWR_CTL))
     14103+               goto done;
     14104+
     14105+       /* 4317pc does not work with SlowClock less than 5Mhz */
     14106+       if (BUSTYPE(si->bustype) == PCMCIA_BUS) {
     14107+               if ((si->ccrev >= 6) && (si->ccrev < 10))
     14108+                       SET_REG(&cc->slow_clk_ctl, SCC_CD_MASK, (SCC_DEF_DIV << SCC_CD_SHF));
     14109+       }
     14110+       
     14111+       sb_pwrctl_setdelay(sbh, (void *)cc);
     14112+
     14113+done:
     14114+       sb_setcoreidx(sbh, origidx);
     14115+}
     14116+
     14117+/* return the value suitable for writing to the dot11 core FAST_PWRUP_DELAY register */
     14118+uint16
     14119+sb_pwrctl_fast_pwrup_delay(void *sbh)
     14120+{
     14121+       sb_info_t *si;
     14122+       uint origidx;
     14123+       chipcregs_t *cc;
     14124+       uint slowminfreq;
     14125+       uint16 fpdelay;
     14126+       uint intr_val = 0;
     14127+
     14128+       si = SB_INFO(sbh);
     14129+       fpdelay = 0;
     14130+       origidx = si->curidx;
     14131+
     14132+       if (BUSTYPE(si->bustype) == SB_BUS)
     14133+               goto done;
     14134+
     14135+       INTR_OFF(si, intr_val);
     14136+
     14137+       if ((cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0)) == NULL)
     14138+               goto done;
     14139+
     14140+       if (!(R_REG(&cc->capabilities) & CAP_PWR_CTL))
     14141+               goto done;
     14142+
     14143+       slowminfreq = sb_slowclk_freq(sbh, FALSE);
     14144+       fpdelay = (((R_REG(&cc->pll_on_delay) + 2) * 1000000) + (slowminfreq - 1)) / slowminfreq;
     14145+
     14146+done:
     14147+       sb_setcoreidx(sbh, origidx);
     14148+       INTR_RESTORE(si, intr_val);
     14149+       return (fpdelay);
     14150+}
     14151+
     14152+/* turn primary xtal and/or pll off/on */
     14153+int
     14154+sb_pwrctl_xtal(void *sbh, uint what, bool on)
     14155+{
     14156+       sb_info_t *si;
     14157+       uint32 in, out, outen;
     14158+
     14159+       si = SB_INFO(sbh);
     14160+
     14161+       switch (BUSTYPE(si->bustype)) {
     14162+
     14163+
     14164+               case PCMCIA_BUS:
     14165+                       return (0);
     14166+
     14167+
     14168+               case PCI_BUS:
     14169+
     14170+                       in = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_IN, sizeof (uint32));
     14171+                       out = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32));
     14172+                       outen = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUTEN, sizeof (uint32));
     14173+
     14174+                       /*
     14175+                        * Avoid glitching the clock if GPRS is already using it.
     14176+                        * We can't actually read the state of the PLLPD so we infer it
     14177+                        * by the value of XTAL_PU which *is* readable via gpioin.
     14178+                        */
     14179+                       if (on && (in & PCI_CFG_GPIO_XTAL))
     14180+                               return (0);
     14181+
     14182+                       if (what & XTAL)
     14183+                               outen |= PCI_CFG_GPIO_XTAL;
     14184+                       if (what & PLL)
     14185+                               outen |= PCI_CFG_GPIO_PLL;
     14186+
     14187+                       if (on) {
     14188+                               /* turn primary xtal on */
     14189+                               if (what & XTAL) {
     14190+                                       out |= PCI_CFG_GPIO_XTAL;
     14191+                                       if (what & PLL)
     14192+                                               out |= PCI_CFG_GPIO_PLL;
     14193+                                       OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32), out);
     14194+                                       OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUTEN, sizeof (uint32), outen);
     14195+                                       OSL_DELAY(XTAL_ON_DELAY);
     14196+                               }
     14197+
     14198+                               /* turn pll on */
     14199+                               if (what & PLL) {
     14200+                                       out &= ~PCI_CFG_GPIO_PLL;
     14201+                                       OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32), out);
     14202+                                       OSL_DELAY(2000);
     14203+                               }
     14204+                       } else {
     14205+                               if (what & XTAL)
     14206+                                       out &= ~PCI_CFG_GPIO_XTAL;
     14207+                               if (what & PLL)
     14208+                                       out |= PCI_CFG_GPIO_PLL;
     14209+                               OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32), out);
     14210+                               OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUTEN, sizeof (uint32), outen);
     14211+                       }
     14212+
     14213+               default:
     14214+                       return (-1);
     14215+       }
     14216+
     14217+       return (0);
     14218+}
     14219+
     14220+/* set dynamic power control mode (forceslow, forcefast, dynamic) */
     14221+/*   returns true if ignore pll off is set and false if it is not */
     14222+bool
     14223+sb_pwrctl_clk(void *sbh, uint mode)
     14224+{
     14225+       sb_info_t *si;
     14226+       uint origidx;
     14227+       chipcregs_t *cc;
     14228+       uint32 scc;
     14229+       bool forcefastclk=FALSE;
     14230+       uint intr_val = 0;
     14231+
     14232+       si = SB_INFO(sbh);
     14233+
     14234+       /* chipcommon cores prior to rev6 don't support slowclkcontrol */
     14235+       if (si->ccrev < 6)
     14236+               return (FALSE);
     14237+
     14238+       /* chipcommon cores rev10 are a whole new ball game */
     14239+       if (si->ccrev >= 10)
     14240+               return (FALSE);
     14241+
     14242+       INTR_OFF(si, intr_val);
     14243+
     14244+       origidx = si->curidx;
     14245+
     14246+       cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0);
     14247+       ASSERT(cc != NULL);
     14248+
     14249+       if (!(R_REG(&cc->capabilities) & CAP_PWR_CTL))
     14250+               goto done;
     14251+
     14252+       switch (mode) {
     14253+       case CLK_FAST:  /* force fast (pll) clock */
     14254+               /* don't forget to force xtal back on before we clear SCC_DYN_XTAL.. */
     14255+               sb_pwrctl_xtal(sbh, XTAL, ON);
     14256+
     14257+               SET_REG(&cc->slow_clk_ctl, (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
     14258+               break;
     14259+
     14260+       case CLK_SLOW:  /* force slow clock */
     14261+               if ((BUSTYPE(si->bustype) == SDIO_BUS) || (BUSTYPE(si->bustype) == PCMCIA_BUS))
     14262+                       return (-1);
     14263+
     14264+               if (si->ccrev >= 6)
     14265+                       OR_REG(&cc->slow_clk_ctl, SCC_FS);
     14266+               break;
     14267+
     14268+       case CLK_DYNAMIC:       /* enable dynamic power control */
     14269+               scc = R_REG(&cc->slow_clk_ctl);
     14270+               scc &= ~(SCC_FS | SCC_IP | SCC_XC);
     14271+               if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
     14272+                       scc |= SCC_XC;
     14273+               W_REG(&cc->slow_clk_ctl, scc);
     14274+
     14275+               /* for dynamic control, we have to release our xtal_pu "force on" */
     14276+               if (scc & SCC_XC)
     14277+                       sb_pwrctl_xtal(sbh, XTAL, OFF);
     14278+               break;
     14279+       }
     14280+
     14281+       /* Is the h/w forcing the use of the fast clk */
     14282+       forcefastclk = (bool)((R_REG(&cc->slow_clk_ctl) & SCC_IP) == SCC_IP);
     14283+
     14284+done:
     14285+       sb_setcoreidx(sbh, origidx);
     14286+       INTR_RESTORE(si, intr_val);
     14287+       return (forcefastclk);
     14288+}
     14289+
     14290+/* register driver interrupt disabling and restoring callback functions */
     14291+void
     14292+sb_register_intr_callback(void *sbh, void *intrsoff_fn, void *intrsrestore_fn, void *intrsenabled_fn, void *intr_arg)
     14293+{
     14294+       sb_info_t *si;
     14295+
     14296+       si = SB_INFO(sbh);
     14297+       si->intr_arg = intr_arg;
     14298+       si->intrsoff_fn = (sb_intrsoff_t)intrsoff_fn;
     14299+       si->intrsrestore_fn = (sb_intrsrestore_t)intrsrestore_fn;
     14300+       si->intrsenabled_fn = (sb_intrsenabled_t)intrsenabled_fn;
     14301+       /* save current core id.  when this function called, the current core
     14302+        * must be the core which provides driver functions(il, et, wl, etc.)
     14303+        */
     14304+       si->dev_coreid = si->coreid[si->curidx];
     14305+}
     14306+
     14307+
     14308diff -Nur linux-2.4.32/drivers/net/hnd/shared_ksyms.sh linux-2.4.32-freewrt/drivers/net/hnd/shared_ksyms.sh
     14309--- linux-2.4.32/drivers/net/hnd/shared_ksyms.sh        1970-01-01 01:00:00.000000000 +0100
     14310+++ linux-2.4.32-freewrt/drivers/net/hnd/shared_ksyms.sh        2006-07-02 21:58:25.000000000 +0200
     14311@@ -0,0 +1,21 @@
     14312+#!/bin/sh
     14313+#
     14314+# Copyright 2004, Broadcom Corporation     
     14315+# All Rights Reserved.     
     14316+#       
     14317+# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY     
     14318+# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM     
     14319+# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS     
     14320+# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.     
     14321+#
     14322+# $Id: shared_ksyms.sh,v 1.1 2005/03/16 13:50:00 wbx Exp $
     14323+#
     14324+
     14325+cat <<EOF
     14326+#include <linux/config.h>
     14327+#include <linux/module.h>
     14328+EOF
     14329+
     14330+for file in $* ; do
     14331+    ${NM} $file | sed -ne 's/[0-9A-Fa-f]* [DT] \([^ ]*\)/extern void \1; EXPORT_SYMBOL(\1);/p'
     14332+done
     14333diff -Nur linux-2.4.32/drivers/net/wireless/Config.in linux-2.4.32-freewrt/drivers/net/wireless/Config.in
     14334--- linux-2.4.32/drivers/net/wireless/Config.in 2004-11-17 12:54:21.000000000 +0100
     14335+++ linux-2.4.32-freewrt/drivers/net/wireless/Config.in 2006-07-02 21:58:25.000000000 +0200
     14336@@ -13,6 +13,7 @@
     14337 fi
     14338 
     14339 if [ "$CONFIG_PCI" = "y" ]; then
     14340+   dep_tristate '    Proprietary Broadcom BCM43xx 802.11 Wireless support' CONFIG_WL
     14341    dep_tristate '    Hermes in PLX9052 based PCI adaptor support (Netgear MA301 etc.) (EXPERIMENTAL)' CONFIG_PLX_HERMES $CONFIG_HERMES $CONFIG_EXPERIMENTAL
     14342    dep_tristate '    Hermes in TMD7160/NCP130 based PCI adaptor support (Pheecom WL-PCI etc.) (EXPERIMENTAL)' CONFIG_TMD_HERMES $CONFIG_HERMES $CONFIG_EXPERIMENTAL
     14343    dep_tristate '    Prism 2.5 PCI 802.11b adaptor support (EXPERIMENTAL)' CONFIG_PCI_HERMES $CONFIG_HERMES $CONFIG_EXPERIMENTAL
     14344diff -Nur linux-2.4.32/drivers/net/wl/Makefile linux-2.4.32-freewrt/drivers/net/wl/Makefile
     14345--- linux-2.4.32/drivers/net/wl/Makefile        1970-01-01 01:00:00.000000000 +0100
     14346+++ linux-2.4.32-freewrt/drivers/net/wl/Makefile        2006-07-02 21:58:25.000000000 +0200
     14347@@ -0,0 +1,26 @@
     14348+#
     14349+# Makefile for the Broadcom wl driver
     14350+#
     14351+# Copyright 2004, Broadcom Corporation
     14352+# All Rights Reserved.
     14353+#
     14354+# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
     14355+# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
     14356+# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
     14357+# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
     14358+#
     14359+# $Id: Makefile,v 1.2 2005/03/29 03:32:18 mbm Exp $
     14360+
     14361+EXTRA_CFLAGS += -I$(TOPDIR)/arch/mips/bcm947xx/include
     14362+
     14363+O_TARGET       := wl.o
     14364+
     14365+obj-y          := apsta_aeskeywrap.o apsta_aes.o apsta_bcmwpa.o apsta_d11ucode.o
     14366+obj-y          += apsta_hmac.o apsta_md5.o apsta_passhash.o apsta_prf.o apsta_rc4.o
     14367+obj-y          += apsta_rijndael-alg-fst.o apsta_sha1.o apsta_tkhash.o apsta_wlc_led.o
     14368+obj-y          += apsta_wlc_phy.o apsta_wlc_rate.o apsta_wlc_security.o
     14369+obj-y          += apsta_wlc_sup.o apsta_wlc_wet.o apsta_wl_linux.o apsta_wlc.o
     14370+
     14371+obj-m          := $(O_TARGET)
     14372+
     14373+include $(TOPDIR)/Rules.make
     14374diff -Nur linux-2.4.32/drivers/parport/Config.in linux-2.4.32-freewrt/drivers/parport/Config.in
     14375--- linux-2.4.32/drivers/parport/Config.in      2004-02-18 14:36:31.000000000 +0100
     14376+++ linux-2.4.32-freewrt/drivers/parport/Config.in      2006-07-02 21:58:25.000000000 +0200
    1953214377@@ -11,6 +11,7 @@
    1953314378 tristate 'Parallel port support' CONFIG_PARPORT
     
    1953814383       if [ "$CONFIG_SERIAL" = "m" ]; then
    1953914384          define_tristate CONFIG_PARPORT_PC_CML1 m
    19540 diff -urN linux.old/drivers/parport/Makefile linux.dev/drivers/parport/Makefile
    19541 --- linux.old/drivers/parport/Makefile  2006-04-27 18:04:38.000000000 +0200
    19542 +++ linux.dev/drivers/parport/Makefile  2006-04-27 19:24:19.000000000 +0200
     14385diff -Nur linux-2.4.32/drivers/parport/Makefile linux-2.4.32-freewrt/drivers/parport/Makefile
     14386--- linux-2.4.32/drivers/parport/Makefile       2004-08-08 01:26:05.000000000 +0200
     14387+++ linux-2.4.32-freewrt/drivers/parport/Makefile       2006-07-02 21:58:25.000000000 +0200
    1954314388@@ -22,6 +22,7 @@
    1954414389 
     
    1954914394 obj-$(CONFIG_PARPORT_AMIGA)    += parport_amiga.o
    1955014395 obj-$(CONFIG_PARPORT_MFC3)     += parport_mfc3.o
    19551 diff -urN linux.old/drivers/parport/parport_splink.c linux.dev/drivers/parport/parport_splink.c
    19552 --- linux.old/drivers/parport/parport_splink.c  1970-01-01 01:00:00.000000000 +0100
    19553 +++ linux.dev/drivers/parport/parport_splink.c  2006-04-27 19:24:19.000000000 +0200
     14396diff -Nur linux-2.4.32/drivers/parport/parport_splink.c linux-2.4.32-freewrt/drivers/parport/parport_splink.c
     14397--- linux-2.4.32/drivers/parport/parport_splink.c       1970-01-01 01:00:00.000000000 +0100
     14398+++ linux-2.4.32-freewrt/drivers/parport/parport_splink.c       2006-07-02 21:58:25.000000000 +0200
    1955414399@@ -0,0 +1,345 @@
    1955514400+/* Low-level parallel port routines for the ASUS WL-500g built-in port
     
    1989814743+module_exit(parport_splink_cleanup)
    1989914744+
    19900 diff -urN linux.old/include/asm-mips/bootinfo.h linux.dev/include/asm-mips/bootinfo.h
    19901 --- linux.old/include/asm-mips/bootinfo.h       2006-04-27 18:04:38.000000000 +0200
    19902 +++ linux.dev/include/asm-mips/bootinfo.h       2006-04-27 19:24:19.000000000 +0200
     14745diff -Nur linux-2.4.32/drivers/pcmcia/Makefile linux-2.4.32-freewrt/drivers/pcmcia/Makefile
     14746--- linux-2.4.32/drivers/pcmcia/Makefile        2004-02-18 14:36:31.000000000 +0100
     14747+++ linux-2.4.32-freewrt/drivers/pcmcia/Makefile        2006-07-02 21:58:25.000000000 +0200
     14748@@ -65,6 +65,10 @@
     14749 au1000_ss-objs-$(CONFIG_PCMCIA_DB1X00)         += au1000_db1x00.o
     14750 au1000_ss-objs-$(CONFIG_PCMCIA_XXS1500)        += au1000_xxs1500.o
     14751 
     14752+obj-$(CONFIG_PCMCIA_BCM4710)   += bcm4710_ss.o
     14753+bcm4710_ss-objs                                        := bcm4710_generic.o
     14754+bcm4710_ss-objs                                        += bcm4710_pcmcia.o
     14755+
     14756 obj-$(CONFIG_PCMCIA_SA1100)    += sa1100_cs.o
     14757 obj-$(CONFIG_PCMCIA_M8XX)      += m8xx_pcmcia.o
     14758 obj-$(CONFIG_PCMCIA_SIBYTE)    += sibyte_generic.o
     14759@@ -102,5 +106,8 @@
     14760 au1x00_ss.o: $(au1000_ss-objs-y)
     14761        $(LD) -r -o $@ $(au1000_ss-objs-y)
     14762 
     14763+bcm4710_ss.o: $(bcm4710_ss-objs)
     14764+       $(LD) -r -o $@ $(bcm4710_ss-objs)
     14765+
     14766 yenta_socket.o: $(yenta_socket-objs)
     14767        $(LD) $(LD_RFLAG) -r -o $@ $(yenta_socket-objs)
     14768diff -Nur linux-2.4.32/drivers/pcmcia/bcm4710_generic.c linux-2.4.32-freewrt/drivers/pcmcia/bcm4710_generic.c
     14769--- linux-2.4.32/drivers/pcmcia/bcm4710_generic.c       1970-01-01 01:00:00.000000000 +0100
     14770+++ linux-2.4.32-freewrt/drivers/pcmcia/bcm4710_generic.c       2006-07-02 21:58:25.000000000 +0200
     14771@@ -0,0 +1,912 @@
     14772+/*
     14773+ *
     14774+ * bcm47xx pcmcia driver
     14775+ *
     14776+ * Copyright 2004, Broadcom Corporation
     14777+ * All Rights Reserved.
     14778+ *
     14779+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
     14780+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
     14781+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
     14782+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
     14783+ *
     14784+ * Based on sa1100_generic.c from www.handhelds.org,
     14785+ *     and au1000_generic.c from oss.sgi.com.
     14786+ *
     14787+ * $Id: bcm4710_generic.c,v 1.1 2005/03/16 13:50:00 wbx Exp $
     14788+ */
     14789+#include <linux/module.h>
     14790+#include <linux/init.h>
     14791+#include <linux/config.h>
     14792+#include <linux/delay.h>
     14793+#include <linux/ioport.h>
     14794+#include <linux/kernel.h>
     14795+#include <linux/tqueue.h>
     14796+#include <linux/timer.h>
     14797+#include <linux/mm.h>
     14798+#include <linux/proc_fs.h>
     14799+#include <linux/version.h>
     14800+#include <linux/types.h>
     14801+#include <linux/vmalloc.h>
     14802+
     14803+#include <pcmcia/version.h>
     14804+#include <pcmcia/cs_types.h>
     14805+#include <pcmcia/cs.h>
     14806+#include <pcmcia/ss.h>
     14807+#include <pcmcia/bulkmem.h>
     14808+#include <pcmcia/cistpl.h>
     14809+#include <pcmcia/bus_ops.h>
     14810+#include "cs_internal.h"
     14811+
     14812+#include <asm/io.h>
     14813+#include <asm/irq.h>
     14814+#include <asm/system.h>
     14815+
     14816+#include <typedefs.h>
     14817+#include <bcm4710.h>
     14818+#include <sbextif.h>
     14819+
     14820+#include "bcm4710pcmcia.h"
     14821+
     14822+#ifdef PCMCIA_DEBUG
     14823+static int pc_debug = PCMCIA_DEBUG;
     14824+#endif
     14825+
     14826+MODULE_DESCRIPTION("Linux PCMCIA Card Services: bcm47xx Socket Controller");
     14827+
     14828+/* This structure maintains housekeeping state for each socket, such
     14829+ * as the last known values of the card detect pins, or the Card Services
     14830+ * callback value associated with the socket:
     14831+ */
     14832+static struct bcm47xx_pcmcia_socket *pcmcia_socket;
     14833+static int socket_count;
     14834+
     14835+
     14836+/* Returned by the low-level PCMCIA interface: */
     14837+static struct pcmcia_low_level *pcmcia_low_level;
     14838+
     14839+/* Event poll timer structure */
     14840+static struct timer_list poll_timer;
     14841+
     14842+
     14843+/* Prototypes for routines which are used internally: */
     14844+
     14845+static int  bcm47xx_pcmcia_driver_init(void);
     14846+static void bcm47xx_pcmcia_driver_shutdown(void);
     14847+static void bcm47xx_pcmcia_task_handler(void *data);
     14848+static void bcm47xx_pcmcia_poll_event(unsigned long data);
     14849+static void bcm47xx_pcmcia_interrupt(int irq, void *dev, struct pt_regs *regs);
     14850+static struct tq_struct bcm47xx_pcmcia_task;
     14851+
     14852+#ifdef CONFIG_PROC_FS
     14853+static int bcm47xx_pcmcia_proc_status(char *buf, char **start,
     14854+               off_t pos, int count, int *eof, void *data);
     14855+#endif
     14856+
     14857+
     14858+/* Prototypes for operations which are exported to the
     14859+ * in-kernel PCMCIA core:
     14860+ */
     14861+
     14862+static int bcm47xx_pcmcia_init(unsigned int sock);
     14863+static int bcm47xx_pcmcia_suspend(unsigned int sock);
     14864+static int bcm47xx_pcmcia_register_callback(unsigned int sock,
     14865+               void (*handler)(void *, unsigned int), void *info);
     14866+static int bcm47xx_pcmcia_inquire_socket(unsigned int sock, socket_cap_t *cap);
     14867+static int bcm47xx_pcmcia_get_status(unsigned int sock, u_int *value);
     14868+static int bcm47xx_pcmcia_get_socket(unsigned int sock, socket_state_t *state);
     14869+static int bcm47xx_pcmcia_set_socket(unsigned int sock, socket_state_t *state);
     14870+static int bcm47xx_pcmcia_get_io_map(unsigned int sock, struct pccard_io_map *io);
     14871+static int bcm47xx_pcmcia_set_io_map(unsigned int sock, struct pccard_io_map *io);
     14872+static int bcm47xx_pcmcia_get_mem_map(unsigned int sock, struct pccard_mem_map *mem);
     14873+static int bcm47xx_pcmcia_set_mem_map(unsigned int sock, struct pccard_mem_map *mem);
     14874+#ifdef CONFIG_PROC_FS
     14875+static void bcm47xx_pcmcia_proc_setup(unsigned int sock, struct proc_dir_entry *base);
     14876+#endif
     14877+
     14878+static struct pccard_operations bcm47xx_pcmcia_operations = {
     14879+       bcm47xx_pcmcia_init,
     14880+       bcm47xx_pcmcia_suspend,
     14881+       bcm47xx_pcmcia_register_callback,
     14882+       bcm47xx_pcmcia_inquire_socket,
     14883+       bcm47xx_pcmcia_get_status,
     14884+       bcm47xx_pcmcia_get_socket,
     14885+       bcm47xx_pcmcia_set_socket,
     14886+       bcm47xx_pcmcia_get_io_map,
     14887+       bcm47xx_pcmcia_set_io_map,
     14888+       bcm47xx_pcmcia_get_mem_map,
     14889+       bcm47xx_pcmcia_set_mem_map,
     14890+#ifdef CONFIG_PROC_FS
     14891+       bcm47xx_pcmcia_proc_setup
     14892+#endif
     14893+};
     14894+
     14895+
     14896+/*
     14897+ * bcm47xx_pcmcia_driver_init()
     14898+ *
     14899+ * This routine performs a basic sanity check to ensure that this
     14900+ * kernel has been built with the appropriate board-specific low-level
     14901+ * PCMCIA support, performs low-level PCMCIA initialization, registers
     14902+ * this socket driver with Card Services, and then spawns the daemon
     14903+ * thread which is the real workhorse of the socket driver.
     14904+ *
     14905+ * Please see linux/Documentation/arm/SA1100/PCMCIA for more information
     14906+ * on the low-level kernel interface.
     14907+ *
     14908+ * Returns: 0 on success, -1 on error
     14909+ */
     14910+static int __init bcm47xx_pcmcia_driver_init(void)
     14911+{
     14912+       servinfo_t info;
     14913+       struct pcmcia_init pcmcia_init;
     14914+       struct pcmcia_state state;
     14915+       unsigned int i;
     14916+       unsigned long tmp;
     14917+
     14918+
     14919+       printk("\nBCM47XX PCMCIA (CS release %s)\n", CS_RELEASE);
     14920+
     14921+       CardServices(GetCardServicesInfo, &info);
     14922+
     14923+       if (info.Revision != CS_RELEASE_CODE) {
     14924+               printk(KERN_ERR "Card Services release codes do not match\n");
     14925+               return -1;
     14926+       }
     14927+
     14928+#ifdef CONFIG_BCM4710
     14929+       pcmcia_low_level=&bcm4710_pcmcia_ops;
     14930+#else
     14931+#error Unsupported Broadcom BCM47XX board.
     14932+#endif
     14933+
     14934+       pcmcia_init.handler=bcm47xx_pcmcia_interrupt;
     14935+
     14936+       if ((socket_count = pcmcia_low_level->init(&pcmcia_init)) < 0) {
     14937+               printk(KERN_ERR "Unable to initialize PCMCIA service.\n");
     14938+               return -EIO;
     14939+       } else {
     14940+               printk("\t%d PCMCIA sockets initialized.\n", socket_count);
     14941+       }
     14942+
     14943+       pcmcia_socket =
     14944+               kmalloc(sizeof(struct bcm47xx_pcmcia_socket) * socket_count,
     14945+                               GFP_KERNEL);
     14946+       memset(pcmcia_socket, 0,
     14947+                       sizeof(struct bcm47xx_pcmcia_socket) * socket_count);
     14948+       if (!pcmcia_socket) {
     14949+               printk(KERN_ERR "Card Services can't get memory \n");
     14950+               return -1;
     14951+       }
     14952+                       
     14953+       for (i = 0; i < socket_count; i++) {
     14954+               if (pcmcia_low_level->socket_state(i, &state) < 0) {
     14955+                       printk(KERN_ERR "Unable to get PCMCIA status\n");
     14956+                       return -EIO;
     14957+               }
     14958+               pcmcia_socket[i].k_state = state;
     14959+               pcmcia_socket[i].cs_state.csc_mask = SS_DETECT;
     14960+               
     14961+               if (i == 0) {
     14962+                       pcmcia_socket[i].virt_io =
     14963+                               (unsigned long)ioremap_nocache(EXTIF_PCMCIA_IOBASE(BCM4710_EXTIF), 0x1000);
     14964+                       /* Substract ioport base which gets added by in/out */
     14965+                       pcmcia_socket[i].virt_io -= mips_io_port_base;
     14966+                       pcmcia_socket[i].phys_attr =
     14967+                               (unsigned long)EXTIF_PCMCIA_CFGBASE(BCM4710_EXTIF);
     14968+                       pcmcia_socket[i].phys_mem =
     14969+                               (unsigned long)EXTIF_PCMCIA_MEMBASE(BCM4710_EXTIF);
     14970+               } else  {
     14971+                       printk(KERN_ERR "bcm4710: socket 1 not supported\n");
     14972+                       return 1;
     14973+               }
     14974+       }
     14975+
     14976+       /* Only advertise as many sockets as we can detect: */
     14977+       if (register_ss_entry(socket_count, &bcm47xx_pcmcia_operations) < 0) {
     14978+               printk(KERN_ERR "Unable to register socket service routine\n");
     14979+               return -ENXIO;
     14980+       }
     14981+
     14982+       /* Start the event poll timer. 
     14983+        * It will reschedule by itself afterwards.
     14984+        */
     14985+       bcm47xx_pcmcia_poll_event(0);
     14986+
     14987+       DEBUG(1, "bcm4710: initialization complete\n");
     14988+       return 0;
     14989+
     14990+}
     14991+
     14992+module_init(bcm47xx_pcmcia_driver_init);
     14993+
     14994+
     14995+/*
     14996+ * bcm47xx_pcmcia_driver_shutdown()
     14997+ *
     14998+ * Invokes the low-level kernel service to free IRQs associated with this
     14999+ * socket controller and reset GPIO edge detection.
     15000+ */
     15001+static void __exit bcm47xx_pcmcia_driver_shutdown(void)
     15002+{
     15003+       int i;
     15004+
     15005+       del_timer_sync(&poll_timer);
     15006+       unregister_ss_entry(&bcm47xx_pcmcia_operations);
     15007+       pcmcia_low_level->shutdown();
     15008+       flush_scheduled_tasks();
     15009+       for (i = 0; i < socket_count; i++) {
     15010+               if (pcmcia_socket[i].virt_io)
     15011+                       iounmap((void *)pcmcia_socket[i].virt_io);
     15012+               if (pcmcia_socket[i].phys_attr)
     15013+                       iounmap((void *)pcmcia_socket[i].phys_attr);
     15014+               if (pcmcia_socket[i].phys_mem)
     15015+                       iounmap((void *)pcmcia_socket[i].phys_mem);
     15016+       }
     15017+       DEBUG(1, "bcm4710: shutdown complete\n");
     15018+}
     15019+
     15020+module_exit(bcm47xx_pcmcia_driver_shutdown);
     15021+
     15022+/*
     15023+ * bcm47xx_pcmcia_init()
     15024+ * We perform all of the interesting initialization tasks in
     15025+ * bcm47xx_pcmcia_driver_init().
     15026+ *
     15027+ * Returns: 0
     15028+ */
     15029+static int bcm47xx_pcmcia_init(unsigned int sock)
     15030+{
     15031+       DEBUG(1, "%s(): initializing socket %u\n", __FUNCTION__, sock);
     15032+
     15033+       return 0;
     15034+}
     15035+
     15036+/*
     15037+ * bcm47xx_pcmcia_suspend()
     15038+ *
     15039+ * We don't currently perform any actions on a suspend.
     15040+ *
     15041+ * Returns: 0
     15042+ */
     15043+static int bcm47xx_pcmcia_suspend(unsigned int sock)
     15044+{
     15045+       DEBUG(1, "%s(): suspending socket %u\n", __FUNCTION__, sock);
     15046+
     15047+       return 0;
     15048+}
     15049+
     15050+
     15051+/*
     15052+ * bcm47xx_pcmcia_events()
     15053+ *
     15054+ * Helper routine to generate a Card Services event mask based on
     15055+ * state information obtained from the kernel low-level PCMCIA layer
     15056+ * in a recent (and previous) sampling. Updates `prev_state'.
     15057+ *
     15058+ * Returns: an event mask for the given socket state.
     15059+ */
     15060+static inline unsigned
     15061+bcm47xx_pcmcia_events(struct pcmcia_state *state,
     15062+               struct pcmcia_state *prev_state,
     15063+               unsigned int mask, unsigned int flags)
     15064+{
     15065+       unsigned int events=0;
     15066+
     15067+       if (state->bvd1 != prev_state->bvd1) {
     15068+
     15069+               DEBUG(3, "%s(): card BVD1 value %u\n", __FUNCTION__, state->bvd1);
     15070+
     15071+               events |= mask & (flags & SS_IOCARD) ? SS_STSCHG : SS_BATDEAD;
     15072+       }
     15073+
     15074+       if (state->bvd2 != prev_state->bvd2) {
     15075+
     15076+               DEBUG(3, "%s(): card BVD2 value %u\n", __FUNCTION__, state->bvd2);
     15077+
     15078+               events |= mask & (flags & SS_IOCARD) ? 0 : SS_BATWARN;
     15079+       }
     15080+
     15081+       if (state->detect != prev_state->detect) {
     15082+
     15083+               DEBUG(3, "%s(): card detect value %u\n", __FUNCTION__, state->detect);
     15084+
     15085+               events |= mask & SS_DETECT;
     15086+       }
     15087+
     15088+
     15089+       if (state->ready != prev_state->ready) {
     15090+
     15091+               DEBUG(3, "%s(): card ready value %u\n", __FUNCTION__, state->ready);
     15092+
     15093+               events |= mask & ((flags & SS_IOCARD) ? 0 : SS_READY);
     15094+       }
     15095+
     15096+       if (events != 0) {
     15097+               DEBUG(2, "events: %s%s%s%s%s\n",
     15098+                     (events & SS_DETECT) ? "DETECT " : "",
     15099+                     (events & SS_READY) ? "READY " : "",
     15100+                     (events & SS_BATDEAD) ? "BATDEAD " : "",
     15101+                     (events & SS_BATWARN) ? "BATWARN " : "",
     15102+                     (events & SS_STSCHG) ? "STSCHG " : "");
     15103+       }
     15104+
     15105+       *prev_state=*state;
     15106+       return events;
     15107+}
     15108+
     15109+
     15110+/*
     15111+ * bcm47xx_pcmcia_task_handler()
     15112+ *
     15113+ * Processes serviceable socket events using the "eventd" thread context.
     15114+ *
     15115+ * Event processing (specifically, the invocation of the Card Services event
     15116+ * callback) occurs in this thread rather than in the actual interrupt
     15117+ * handler due to the use of scheduling operations in the PCMCIA core.
     15118+ */
     15119+static void bcm47xx_pcmcia_task_handler(void *data)
     15120+{
     15121+       struct pcmcia_state state;
     15122+       int i, events, irq_status;
     15123+
     15124+       DEBUG(4, "%s(): entering PCMCIA monitoring thread\n", __FUNCTION__);
     15125+
     15126+       for (i = 0; i < socket_count; i++)  {
     15127+               if ((irq_status = pcmcia_low_level->socket_state(i, &state)) < 0)
     15128+                       printk(KERN_ERR "Error in kernel low-level PCMCIA service.\n");
     15129+
     15130+               events = bcm47xx_pcmcia_events(&state,
     15131+                                              &pcmcia_socket[i].k_state,
     15132+                                              pcmcia_socket[i].cs_state.csc_mask,
     15133+                                              pcmcia_socket[i].cs_state.flags);
     15134+
     15135+               if (pcmcia_socket[i].handler != NULL) {
     15136+                       pcmcia_socket[i].handler(pcmcia_socket[i].handler_info,
     15137+                                                events);
     15138+               }
     15139+       }
     15140+}
     15141+
     15142+static struct tq_struct bcm47xx_pcmcia_task = {
     15143+       routine: bcm47xx_pcmcia_task_handler
     15144+};
     15145+
     15146+
     15147+/*
     15148+ * bcm47xx_pcmcia_poll_event()
     15149+ *
     15150+ * Let's poll for events in addition to IRQs since IRQ only is unreliable...
     15151+ */
     15152+static void bcm47xx_pcmcia_poll_event(unsigned long dummy)
     15153+{
     15154+       DEBUG(4, "%s(): polling for events\n", __FUNCTION__);
     15155+
     15156+       poll_timer.function = bcm47xx_pcmcia_poll_event;
     15157+       poll_timer.expires = jiffies + BCM47XX_PCMCIA_POLL_PERIOD;
     15158+       add_timer(&poll_timer);
     15159+       schedule_task(&bcm47xx_pcmcia_task);
     15160+}
     15161+
     15162+
     15163+/*
     15164+ * bcm47xx_pcmcia_interrupt()
     15165+ *
     15166+ * Service routine for socket driver interrupts (requested by the
     15167+ * low-level PCMCIA init() operation via bcm47xx_pcmcia_thread()).
     15168+ *
     15169+ * The actual interrupt-servicing work is performed by
     15170+ * bcm47xx_pcmcia_task(), largely because the Card Services event-
     15171+ * handling code performs scheduling operations which cannot be
     15172+ * executed from within an interrupt context.
     15173+ */
     15174+static void
     15175+bcm47xx_pcmcia_interrupt(int irq, void *dev, struct pt_regs *regs)
     15176+{
     15177+       DEBUG(3, "%s(): servicing IRQ %d\n", __FUNCTION__, irq);
     15178+       schedule_task(&bcm47xx_pcmcia_task);
     15179+}
     15180+
     15181+
     15182+/*
     15183+ * bcm47xx_pcmcia_register_callback()
     15184+ *
     15185+ * Implements the register_callback() operation for the in-kernel
     15186+ * PCMCIA service (formerly SS_RegisterCallback in Card Services). If
     15187+ * the function pointer `handler' is not NULL, remember the callback
     15188+ * location in the state for `sock', and increment the usage counter
     15189+ * for the driver module. (The callback is invoked from the interrupt
     15190+ * service routine, bcm47xx_pcmcia_interrupt(), to notify Card Services
     15191+ * of interesting events.) Otherwise, clear the callback pointer in the
     15192+ * socket state and decrement the module usage count.
     15193+ *
     15194+ * Returns: 0
     15195+ */
     15196+static int
     15197+bcm47xx_pcmcia_register_callback(unsigned int sock,
     15198+               void (*handler)(void *, unsigned int), void *info)
     15199+{
     15200+       if (handler == NULL) {
     15201+               pcmcia_socket[sock].handler = NULL;
     15202+               MOD_DEC_USE_COUNT;
     15203+       } else {
     15204+               MOD_INC_USE_COUNT;
     15205+               pcmcia_socket[sock].handler = handler;
     15206+               pcmcia_socket[sock].handler_info = info;
     15207+       }
     15208+       return 0;
     15209+}
     15210+
     15211+
     15212+/*
     15213+ * bcm47xx_pcmcia_inquire_socket()
     15214+ *
     15215+ * Implements the inquire_socket() operation for the in-kernel PCMCIA
     15216+ * service (formerly SS_InquireSocket in Card Services). Of note is
     15217+ * the setting of the SS_CAP_PAGE_REGS bit in the `features' field of
     15218+ * `cap' to "trick" Card Services into tolerating large "I/O memory"
     15219+ * addresses. Also set is SS_CAP_STATIC_MAP, which disables the memory
     15220+ * resource database check. (Mapped memory is set up within the socket
     15221+ * driver itself.)
     15222+ *
     15223+ * In conjunction with the STATIC_MAP capability is a new field,
     15224+ * `io_offset', recommended by David Hinds. Rather than go through
     15225+ * the SetIOMap interface (which is not quite suited for communicating
     15226+ * window locations up from the socket driver), we just pass up
     15227+ * an offset which is applied to client-requested base I/O addresses
     15228+ * in alloc_io_space().
     15229+ *
     15230+ * Returns: 0 on success, -1 if no pin has been configured for `sock'
     15231+ */
     15232+static int
     15233+bcm47xx_pcmcia_inquire_socket(unsigned int sock, socket_cap_t *cap)
     15234+{
     15235+       struct pcmcia_irq_info irq_info;
     15236+
     15237+       if (sock >= socket_count) {
     15238+               printk(KERN_ERR "bcm47xx: socket %u not configured\n", sock);
     15239+               return -1;
     15240+       }
     15241+
     15242+       /* SS_CAP_PAGE_REGS: used by setup_cis_mem() in cistpl.c to set the
     15243+        *   force_low argument to validate_mem() in rsrc_mgr.c -- since in
     15244+        *   general, the mapped * addresses of the PCMCIA memory regions
     15245+        *   will not be within 0xffff, setting force_low would be
     15246+        *   undesirable.
     15247+        *
     15248+        * SS_CAP_STATIC_MAP: don't bother with the (user-configured) memory
     15249+        *   resource database; we instead pass up physical address ranges
     15250+        *   and allow other parts of Card Services to deal with remapping.
     15251+        *
     15252+        * SS_CAP_PCCARD: we can deal with 16-bit PCMCIA & CF cards, but
     15253+        *   not 32-bit CardBus devices.
     15254+        */
     15255+       cap->features = (SS_CAP_PAGE_REGS  | SS_CAP_STATIC_MAP | SS_CAP_PCCARD);
     15256+
     15257+       irq_info.sock = sock;
     15258+       irq_info.irq = -1;
     15259+
     15260+       if (pcmcia_low_level->get_irq_info(&irq_info) < 0) {
     15261+               printk(KERN_ERR "Error obtaining IRQ info socket %u\n", sock);
     15262+               return -1;
     15263+       }
     15264+
     15265+       cap->irq_mask = 0;
     15266+       cap->map_size = PAGE_SIZE;
     15267+       cap->pci_irq = irq_info.irq;
     15268+       cap->io_offset = pcmcia_socket[sock].virt_io;
     15269+
     15270+       return 0;
     15271+}
     15272+
     15273+
     15274+/*
     15275+ * bcm47xx_pcmcia_get_status()
     15276+ *
     15277+ * Implements the get_status() operation for the in-kernel PCMCIA
     15278+ * service (formerly SS_GetStatus in Card Services). Essentially just
     15279+ * fills in bits in `status' according to internal driver state or
     15280+ * the value of the voltage detect chipselect register.
     15281+ *
     15282+ * As a debugging note, during card startup, the PCMCIA core issues
     15283+ * three set_socket() commands in a row the first with RESET deasserted,
     15284+ * the second with RESET asserted, and the last with RESET deasserted
     15285+ * again. Following the third set_socket(), a get_status() command will
     15286+ * be issued. The kernel is looking for the SS_READY flag (see
     15287+ * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
     15288+ *
     15289+ * Returns: 0
     15290+ */
     15291+static int
     15292+bcm47xx_pcmcia_get_status(unsigned int sock, unsigned int *status)
     15293+{
     15294+       struct pcmcia_state state;
     15295+
     15296+
     15297+       if ((pcmcia_low_level->socket_state(sock, &state)) < 0) {
     15298+               printk(KERN_ERR "Unable to get PCMCIA status from kernel.\n");
     15299+               return -1;
     15300+       }
     15301+
     15302+       pcmcia_socket[sock].k_state = state;
     15303+
     15304+       *status = state.detect ? SS_DETECT : 0;
     15305+
     15306+       *status |= state.ready ? SS_READY : 0;
     15307+
     15308+       /* The power status of individual sockets is not available
     15309+        * explicitly from the hardware, so we just remember the state
     15310+        * and regurgitate it upon request:
     15311+        */
     15312+       *status |= pcmcia_socket[sock].cs_state.Vcc ? SS_POWERON : 0;
     15313+
     15314+       if (pcmcia_socket[sock].cs_state.flags & SS_IOCARD)
     15315+               *status |= state.bvd1 ? SS_STSCHG : 0;
     15316+       else {
     15317+               if (state.bvd1 == 0)
     15318+                       *status |= SS_BATDEAD;
     15319+               else if (state.bvd2 == 0)
     15320+                       *status |= SS_BATWARN;
     15321+       }
     15322+
     15323+       *status |= state.vs_3v ? SS_3VCARD : 0;
     15324+
     15325+       *status |= state.vs_Xv ? SS_XVCARD : 0;
     15326+
     15327+       DEBUG(2, "\tstatus: %s%s%s%s%s%s%s%s\n",
     15328+             (*status&SS_DETECT)?"DETECT ":"",
     15329+             (*status&SS_READY)?"READY ":"",
     15330+             (*status&SS_BATDEAD)?"BATDEAD ":"",
     15331+             (*status&SS_BATWARN)?"BATWARN ":"",
     15332+             (*status&SS_POWERON)?"POWERON ":"",
     15333+             (*status&SS_STSCHG)?"STSCHG ":"",
     15334+             (*status&SS_3VCARD)?"3VCARD ":"",
     15335+             (*status&SS_XVCARD)?"XVCARD ":"");
     15336+
     15337+       return 0;
     15338+}
     15339+
     15340+
     15341+/*
     15342+ * bcm47xx_pcmcia_get_socket()
     15343+ *
     15344+ * Implements the get_socket() operation for the in-kernel PCMCIA
     15345+ * service (formerly SS_GetSocket in Card Services). Not a very
     15346+ * exciting routine.
     15347+ *
     15348+ * Returns: 0
     15349+ */
     15350+static int
     15351+bcm47xx_pcmcia_get_socket(unsigned int sock, socket_state_t *state)
     15352+{
     15353+       DEBUG(2, "%s() for sock %u\n", __FUNCTION__, sock);
     15354+
     15355+       /* This information was given to us in an earlier call to set_socket(),
     15356+        * so we're just regurgitating it here:
     15357+        */
     15358+       *state = pcmcia_socket[sock].cs_state;
     15359+       return 0;
     15360+}
     15361+
     15362+
     15363+/*
     15364+ * bcm47xx_pcmcia_set_socket()
     15365+ *
     15366+ * Implements the set_socket() operation for the in-kernel PCMCIA
     15367+ * service (formerly SS_SetSocket in Card Services). We more or
     15368+ * less punt all of this work and let the kernel handle the details
     15369+ * of power configuration, reset, &c. We also record the value of
     15370+ * `state' in order to regurgitate it to the PCMCIA core later.
     15371+ *
     15372+ * Returns: 0
     15373+ */
     15374+static int
     15375+bcm47xx_pcmcia_set_socket(unsigned int sock, socket_state_t *state)
     15376+{
     15377+       struct pcmcia_configure configure;
     15378+
     15379+       DEBUG(2, "\tmask:  %s%s%s%s%s%s\n\tflags: %s%s%s%s%s%s\n"
     15380+             "\tVcc %d  Vpp %d  irq %d\n",
     15381+             (state->csc_mask == 0) ? "<NONE>" : "",
     15382+             (state->csc_mask & SS_DETECT) ? "DETECT " : "",
     15383+             (state->csc_mask & SS_READY) ? "READY " : "",
     15384+             (state->csc_mask & SS_BATDEAD) ? "BATDEAD " : "",
     15385+             (state->csc_mask & SS_BATWARN) ? "BATWARN " : "",
     15386+             (state->csc_mask & SS_STSCHG) ? "STSCHG " : "",
     15387+             (state->flags == 0) ? "<NONE>" : "",
     15388+             (state->flags & SS_PWR_AUTO) ? "PWR_AUTO " : "",
     15389+             (state->flags & SS_IOCARD) ? "IOCARD " : "",
     15390+             (state->flags & SS_RESET) ? "RESET " : "",
     15391+             (state->flags & SS_SPKR_ENA) ? "SPKR_ENA " : "",
     15392+             (state->flags & SS_OUTPUT_ENA) ? "OUTPUT_ENA " : "",
     15393+             state->Vcc, state->Vpp, state->io_irq);
     15394+
     15395+       configure.sock = sock;
     15396+       configure.vcc = state->Vcc;
     15397+       configure.vpp = state->Vpp;
     15398+       configure.output = (state->flags & SS_OUTPUT_ENA) ? 1 : 0;
     15399+       configure.speaker = (state->flags & SS_SPKR_ENA) ? 1 : 0;
     15400+       configure.reset = (state->flags & SS_RESET) ? 1 : 0;
     15401+
     15402+       if (pcmcia_low_level->configure_socket(&configure) < 0) {
     15403+               printk(KERN_ERR "Unable to configure socket %u\n", sock);
     15404+               return -1;
     15405+       }
     15406+
     15407+       pcmcia_socket[sock].cs_state = *state;
     15408+       return 0;
     15409+}
     15410+
     15411+
     15412+/*
     15413+ * bcm47xx_pcmcia_get_io_map()
     15414+ *
     15415+ * Implements the get_io_map() operation for the in-kernel PCMCIA
     15416+ * service (formerly SS_GetIOMap in Card Services). Just returns an
     15417+ * I/O map descriptor which was assigned earlier by a set_io_map().
     15418+ *
     15419+ * Returns: 0 on success, -1 if the map index was out of range
     15420+ */
     15421+static int
     15422+bcm47xx_pcmcia_get_io_map(unsigned int sock, struct pccard_io_map *map)
     15423+{
     15424+       DEBUG(2, "bcm47xx_pcmcia_get_io_map: sock %d\n", sock);
     15425+
     15426+       if (map->map >= MAX_IO_WIN) {
     15427+               printk(KERN_ERR "%s(): map (%d) out of range\n",
     15428+                      __FUNCTION__, map->map);
     15429+               return -1;
     15430+       }
     15431+
     15432+       *map = pcmcia_socket[sock].io_map[map->map];
     15433+       return 0;
     15434+}
     15435+
     15436+
     15437+/*
     15438+ * bcm47xx_pcmcia_set_io_map()
     15439+ *
     15440+ * Implements the set_io_map() operation for the in-kernel PCMCIA
     15441+ * service (formerly SS_SetIOMap in Card Services). We configure
     15442+ * the map speed as requested, but override the address ranges
     15443+ * supplied by Card Services.
     15444+ *
     15445+ * Returns: 0 on success, -1 on error
     15446+ */
     15447+int
     15448+bcm47xx_pcmcia_set_io_map(unsigned int sock, struct pccard_io_map *map)
     15449+{
     15450+       unsigned int speed;
     15451+       unsigned long start;
     15452+
     15453+       DEBUG(2, "\tmap %u  speed %u\n\tstart 0x%08lx  stop 0x%08lx\n"
     15454+             "\tflags: %s%s%s%s%s%s%s%s\n",
     15455+             map->map, map->speed, map->start, map->stop,
     15456+             (map->flags == 0) ? "<NONE>" : "",
     15457+             (map->flags & MAP_ACTIVE) ? "ACTIVE " : "",
     15458+             (map->flags & MAP_16BIT) ? "16BIT " : "",
     15459+             (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "",
     15460+             (map->flags & MAP_0WS) ? "0WS " : "",
     15461+             (map->flags & MAP_WRPROT) ? "WRPROT " : "",
     15462+             (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "",
     15463+             (map->flags & MAP_PREFETCH) ? "PREFETCH " : "");
     15464+
     15465+       if (map->map >= MAX_IO_WIN) {
     15466+               printk(KERN_ERR "%s(): map (%d) out of range\n",
     15467+                               __FUNCTION__, map->map);
     15468+               return -1;
     15469+       }
     15470+
     15471+       if (map->flags & MAP_ACTIVE) {
     15472+               speed = (map->speed > 0) ? map->speed : BCM47XX_PCMCIA_IO_SPEED;
     15473+               pcmcia_socket[sock].speed_io = speed;
     15474+       }
     15475+
     15476+       start = map->start;
     15477+
     15478+       if (map->stop == 1) {
     15479+               map->stop = PAGE_SIZE - 1;
     15480+       }
     15481+
     15482+       map->start = pcmcia_socket[sock].virt_io;
     15483+       map->stop = map->start + (map->stop - start);
     15484+       pcmcia_socket[sock].io_map[map->map] = *map;
     15485+       DEBUG(2, "set_io_map %d start %x stop %x\n",
     15486+             map->map, map->start, map->stop);
     15487+       return 0;
     15488+}
     15489+
     15490+
     15491+/*
     15492+ * bcm47xx_pcmcia_get_mem_map()
     15493+ *
     15494+ * Implements the get_mem_map() operation for the in-kernel PCMCIA
     15495+ * service (formerly SS_GetMemMap in Card Services). Just returns a
     15496+ *  memory map descriptor which was assigned earlier by a
     15497+ *  set_mem_map() request.
     15498+ *
     15499+ * Returns: 0 on success, -1 if the map index was out of range
     15500+ */
     15501+static int
     15502+bcm47xx_pcmcia_get_mem_map(unsigned int sock, struct pccard_mem_map *map)
     15503+{
     15504+       DEBUG(2, "%s() for sock %u\n", __FUNCTION__, sock);
     15505+
     15506+       if (map->map >= MAX_WIN) {
     15507+               printk(KERN_ERR "%s(): map (%d) out of range\n",
     15508+                      __FUNCTION__, map->map);
     15509+               return -1;
     15510+       }
     15511+
     15512+       *map = pcmcia_socket[sock].mem_map[map->map];
     15513+       return 0;
     15514+}
     15515+
     15516+
     15517+/*
     15518+ * bcm47xx_pcmcia_set_mem_map()
     15519+ *
     15520+ * Implements the set_mem_map() operation for the in-kernel PCMCIA
     15521+ * service (formerly SS_SetMemMap in Card Services). We configure
     15522+ * the map speed as requested, but override the address ranges
     15523+ * supplied by Card Services.
     15524+ *
     15525+ * Returns: 0 on success, -1 on error
     15526+ */
     15527+static int
     15528+bcm47xx_pcmcia_set_mem_map(unsigned int sock, struct pccard_mem_map *map)
     15529+{
     15530+       unsigned int speed;
     15531+       unsigned long start;
     15532+       u_long flags;
     15533+
     15534+       if (map->map >= MAX_WIN) {
     15535+               printk(KERN_ERR "%s(): map (%d) out of range\n",
     15536+                      __FUNCTION__, map->map);
     15537+               return -1;
     15538+       }
     15539+
     15540+       DEBUG(2, "\tmap %u  speed %u\n\tsys_start  %#lx\n"
     15541+             "\tsys_stop   %#lx\n\tcard_start %#x\n"
     15542+             "\tflags: %s%s%s%s%s%s%s%s\n",
     15543+             map->map, map->speed, map->sys_start, map->sys_stop,
     15544+             map->card_start, (map->flags == 0) ? "<NONE>" : "",
     15545+             (map->flags & MAP_ACTIVE) ? "ACTIVE " : "",
     15546+             (map->flags & MAP_16BIT) ? "16BIT " : "",
     15547+             (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "",
     15548+             (map->flags & MAP_0WS) ? "0WS " : "",
     15549+             (map->flags & MAP_WRPROT) ? "WRPROT " : "",
     15550+             (map->flags & MAP_ATTRIB) ? "ATTRIB " : "",
     15551+             (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "");
     15552+
     15553+       if (map->flags & MAP_ACTIVE) {
     15554+               /* When clients issue RequestMap, the access speed is not always
     15555+                * properly configured:
     15556+                */
     15557+               speed = (map->speed > 0) ? map->speed : BCM47XX_PCMCIA_MEM_SPEED;
     15558+
     15559+               /* TBD */
     15560+               if (map->flags & MAP_ATTRIB) {
     15561+                       pcmcia_socket[sock].speed_attr = speed;
     15562+               } else {
     15563+                       pcmcia_socket[sock].speed_mem = speed;
     15564+               }
     15565+       }
     15566+
     15567+       save_flags(flags);
     15568+       cli();
     15569+       start = map->sys_start;
     15570+
     15571+       if (map->sys_stop == 0)
     15572+               map->sys_stop = PAGE_SIZE - 1;
     15573+
     15574+       if (map->flags & MAP_ATTRIB) {
     15575+               map->sys_start = pcmcia_socket[sock].phys_attr +
     15576+                       map->card_start;
     15577+       } else {
     15578+               map->sys_start = pcmcia_socket[sock].phys_mem +
     15579+                       map->card_start;
     15580+       }
     15581+
     15582+       map->sys_stop = map->sys_start + (map->sys_stop - start);
     15583+       pcmcia_socket[sock].mem_map[map->map] = *map;
     15584+       restore_flags(flags);
     15585+       DEBUG(2, "set_mem_map %d start %x stop %x card_start %x\n",
     15586+                       map->map, map->sys_start, map->sys_stop,
     15587+                       map->card_start);
     15588+       return 0;
     15589+}
     15590+
     15591+
     15592+#if defined(CONFIG_PROC_FS)
     15593+
     15594+/*
     15595+ * bcm47xx_pcmcia_proc_setup()
     15596+ *
     15597+ * Implements the proc_setup() operation for the in-kernel PCMCIA
     15598+ * service (formerly SS_ProcSetup in Card Services).
     15599+ *
     15600+ * Returns: 0 on success, -1 on error
     15601+ */
     15602+static void
     15603+bcm47xx_pcmcia_proc_setup(unsigned int sock, struct proc_dir_entry *base)
     15604+{
     15605+       struct proc_dir_entry *entry;
     15606+
     15607+       if ((entry = create_proc_entry("status", 0, base)) == NULL) {
     15608+               printk(KERN_ERR "Unable to install \"status\" procfs entry\n");
     15609+               return;
     15610+       }
     15611+
     15612+       entry->read_proc = bcm47xx_pcmcia_proc_status;
     15613+       entry->data = (void *)sock;
     15614+}
     15615+
     15616+
     15617+/*
     15618+ * bcm47xx_pcmcia_proc_status()
     15619+ *
     15620+ * Implements the /proc/bus/pccard/??/status file.
     15621+ *
     15622+ * Returns: the number of characters added to the buffer
     15623+ */
     15624+static int
     15625+bcm47xx_pcmcia_proc_status(char *buf, char **start, off_t pos,
     15626+                          int count, int *eof, void *data)
     15627+{
     15628+       char *p = buf;
     15629+       unsigned int sock = (unsigned int)data;
     15630+
     15631+       p += sprintf(p, "k_flags  : %s%s%s%s%s%s%s\n",
     15632+                    pcmcia_socket[sock].k_state.detect ? "detect " : "",
     15633+                    pcmcia_socket[sock].k_state.ready ? "ready " : "",
     15634+                    pcmcia_socket[sock].k_state.bvd1 ? "bvd1 " : "",
     15635+                    pcmcia_socket[sock].k_state.bvd2 ? "bvd2 " : "",
     15636+                    pcmcia_socket[sock].k_state.wrprot ? "wrprot " : "",
     15637+                    pcmcia_socket[sock].k_state.vs_3v ? "vs_3v " : "",
     15638+                    pcmcia_socket[sock].k_state.vs_Xv ? "vs_Xv " : "");
     15639+
     15640+       p += sprintf(p, "status   : %s%s%s%s%s%s%s%s%s\n",
     15641+                    pcmcia_socket[sock].k_state.detect ? "SS_DETECT " : "",
     15642+                    pcmcia_socket[sock].k_state.ready ? "SS_READY " : "",
     15643+                    pcmcia_socket[sock].cs_state.Vcc ? "SS_POWERON " : "",
     15644+                    pcmcia_socket[sock].cs_state.flags & SS_IOCARD ? "SS_IOCARD " : "",
     15645+                    (pcmcia_socket[sock].cs_state.flags & SS_IOCARD &&
     15646+                     pcmcia_socket[sock].k_state.bvd1) ? "SS_STSCHG " : "",
     15647+                    ((pcmcia_socket[sock].cs_state.flags & SS_IOCARD) == 0 &&
     15648+                     (pcmcia_socket[sock].k_state.bvd1 == 0)) ? "SS_BATDEAD " : "",
     15649+                    ((pcmcia_socket[sock].cs_state.flags & SS_IOCARD) == 0 &&
     15650+                     (pcmcia_socket[sock].k_state.bvd2 == 0)) ? "SS_BATWARN " : "",
     15651+                    pcmcia_socket[sock].k_state.vs_3v ? "SS_3VCARD " : "",
     15652+                    pcmcia_socket[sock].k_state.vs_Xv ? "SS_XVCARD " : "");
     15653+
     15654+       p += sprintf(p, "mask     : %s%s%s%s%s\n",
     15655+                    pcmcia_socket[sock].cs_state.csc_mask & SS_DETECT ? "SS_DETECT " : "",
     15656+                    pcmcia_socket[sock].cs_state.csc_mask & SS_READY ? "SS_READY " : "",
     15657+                    pcmcia_socket[sock].cs_state.csc_mask & SS_BATDEAD ? "SS_BATDEAD " : "",
     15658+                    pcmcia_socket[sock].cs_state.csc_mask & SS_BATWARN ? "SS_BATWARN " : "",
     15659+                    pcmcia_socket[sock].cs_state.csc_mask & SS_STSCHG ? "SS_STSCHG " : "");
     15660+
     15661+       p += sprintf(p, "cs_flags : %s%s%s%s%s\n",
     15662+                    pcmcia_socket[sock].cs_state.flags & SS_PWR_AUTO ?
     15663+                       "SS_PWR_AUTO " : "",
     15664+                    pcmcia_socket[sock].cs_state.flags & SS_IOCARD ?
     15665+                       "SS_IOCARD " : "",
     15666+                    pcmcia_socket[sock].cs_state.flags & SS_RESET ?
     15667+                       "SS_RESET " : "",
     15668+                    pcmcia_socket[sock].cs_state.flags & SS_SPKR_ENA ?
     15669+                       "SS_SPKR_ENA " : "",
     15670+                    pcmcia_socket[sock].cs_state.flags & SS_OUTPUT_ENA ?
     15671+                       "SS_OUTPUT_ENA " : "");
     15672+
     15673+       p += sprintf(p, "Vcc      : %d\n", pcmcia_socket[sock].cs_state.Vcc);
     15674+       p += sprintf(p, "Vpp      : %d\n", pcmcia_socket[sock].cs_state.Vpp);
     15675+       p += sprintf(p, "irq      : %d\n", pcmcia_socket[sock].cs_state.io_irq);
     15676+       p += sprintf(p, "I/O      : %u\n", pcmcia_socket[sock].speed_io);
     15677+       p += sprintf(p, "attribute: %u\n", pcmcia_socket[sock].speed_attr);
     15678+       p += sprintf(p, "common   : %u\n", pcmcia_socket[sock].speed_mem);
     15679+       return p-buf;
     15680+}
     15681+
     15682+
     15683+#endif  /* defined(CONFIG_PROC_FS) */
     15684diff -Nur linux-2.4.32/drivers/pcmcia/bcm4710_pcmcia.c linux-2.4.32-freewrt/drivers/pcmcia/bcm4710_pcmcia.c
     15685--- linux-2.4.32/drivers/pcmcia/bcm4710_pcmcia.c        1970-01-01 01:00:00.000000000 +0100
     15686+++ linux-2.4.32-freewrt/drivers/pcmcia/bcm4710_pcmcia.c        2006-07-02 21:58:25.000000000 +0200
     15687@@ -0,0 +1,266 @@
     15688+/*
     15689+ * BCM4710 specific pcmcia routines.
     15690+ *
     15691+ * Copyright 2004, Broadcom Corporation
     15692+ * All Rights Reserved.
     15693+ *
     15694+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
     15695+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
     15696+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
     15697+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
     15698+ *
     15699+ * $Id: bcm4710_pcmcia.c,v 1.1 2005/03/16 13:50:00 wbx Exp $
     15700+ */
     15701+#include <linux/module.h>
     15702+#include <linux/init.h>
     15703+#include <linux/config.h>
     15704+#include <linux/delay.h>
     15705+#include <linux/ioport.h>
     15706+#include <linux/kernel.h>
     15707+#include <linux/tqueue.h>
     15708+#include <linux/timer.h>
     15709+#include <linux/mm.h>
     15710+#include <linux/proc_fs.h>
     15711+#include <linux/version.h>
     15712+#include <linux/types.h>
     15713+#include <linux/pci.h>
     15714+
     15715+#include <pcmcia/version.h>
     15716+#include <pcmcia/cs_types.h>
     15717+#include <pcmcia/cs.h>
     15718+#include <pcmcia/ss.h>
     15719+#include <pcmcia/bulkmem.h>
     15720+#include <pcmcia/cistpl.h>
     15721+#include <pcmcia/bus_ops.h>
     15722+#include "cs_internal.h"
     15723+
     15724+#include <asm/io.h>
     15725+#include <asm/irq.h>
     15726+#include <asm/system.h>
     15727+
     15728+
     15729+#include <typedefs.h>
     15730+#include <bcmdevs.h>
     15731+#include <bcm4710.h>
     15732+#include <sbconfig.h>
     15733+#include <sbextif.h>
     15734+
     15735+#include "bcm4710pcmcia.h"
     15736+
     15737+/* Use a static var for irq dev_id */
     15738+static int bcm47xx_pcmcia_dev_id;
     15739+
     15740+/* Do we think we have a card or not? */
     15741+static int bcm47xx_pcmcia_present = 0;
     15742+
     15743+
     15744+static void bcm4710_pcmcia_reset(void)
     15745+{
     15746+       extifregs_t *eir;
     15747+       unsigned long s;
     15748+       uint32 out0, out1, outen;
     15749+
     15750+
     15751+       eir = (extifregs_t *) ioremap_nocache(BCM4710_REG_EXTIF, sizeof(extifregs_t));
     15752+
     15753+       save_and_cli(s);
     15754+
     15755+       /* Use gpio7 to reset the pcmcia slot */
     15756+       outen = readl(&eir->gpio[0].outen);
     15757+       outen |= BCM47XX_PCMCIA_RESET;
     15758+       out0 = readl(&eir->gpio[0].out);
     15759+       out0 &= ~(BCM47XX_PCMCIA_RESET);
     15760+       out1 = out0 | BCM47XX_PCMCIA_RESET;
     15761+
     15762+       writel(out0, &eir->gpio[0].out);
     15763+       writel(outen, &eir->gpio[0].outen);
     15764+       mdelay(1);
     15765+       writel(out1, &eir->gpio[0].out);
     15766+       mdelay(1);
     15767+       writel(out0, &eir->gpio[0].out);
     15768+
     15769+       restore_flags(s);
     15770+}
     15771+
     15772+
     15773+static int bcm4710_pcmcia_init(struct pcmcia_init *init)
     15774+{
     15775+       struct pci_dev *pdev;
     15776+       extifregs_t *eir;
     15777+       uint32 outen, intp, intm, tmp;
     15778+       uint16 *attrsp;
     15779+       int rc = 0, i;
     15780+       extern unsigned long bcm4710_cpu_cycle;
     15781+
     15782+
     15783+       if (!(pdev = pci_find_device(VENDOR_BROADCOM, SB_EXTIF, NULL))) {
     15784+               printk(KERN_ERR "bcm4710_pcmcia: extif not found\n");
     15785+               return -ENODEV;
     15786+       }
     15787+       eir = (extifregs_t *) ioremap_nocache(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
     15788+
     15789+       /* Initialize the pcmcia i/f: 16bit no swap */
     15790+       writel(CF_EM_PCMCIA | CF_DS | CF_EN, &eir->pcmcia_config);
     15791+
     15792+#ifdef notYet
     15793+
     15794+       /* Set the timing for memory accesses */
     15795+       tmp = (19 / bcm4710_cpu_cycle) << 24;           /* W3 = 10nS */
     15796+       tmp = tmp | ((29 / bcm4710_cpu_cycle) << 16);   /* W2 = 20nS */
     15797+       tmp = tmp | ((109 / bcm4710_cpu_cycle) << 8);   /* W1 = 100nS */
     15798+       tmp = tmp | (129 / bcm4710_cpu_cycle);          /* W0 = 120nS */
     15799+       writel(tmp, &eir->pcmcia_memwait);              /* 0x01020a0c for a 100Mhz clock */
     15800+
     15801+       /* Set the timing for I/O accesses */
     15802+       tmp = (19 / bcm4710_cpu_cycle) << 24;           /* W3 = 10nS */
     15803+       tmp = tmp | ((29 / bcm4710_cpu_cycle) << 16);   /* W2 = 20nS */
     15804+       tmp = tmp | ((109 / bcm4710_cpu_cycle) << 8);   /* W1 = 100nS */
     15805+       tmp = tmp | (129 / bcm4710_cpu_cycle);          /* W0 = 120nS */
     15806+       writel(tmp, &eir->pcmcia_iowait);               /* 0x01020a0c for a 100Mhz clock */
     15807+
     15808+       /* Set the timing for attribute accesses */
     15809+       tmp = (19 / bcm4710_cpu_cycle) << 24;           /* W3 = 10nS */
     15810+       tmp = tmp | ((29 / bcm4710_cpu_cycle) << 16);   /* W2 = 20nS */
     15811+       tmp = tmp | ((109 / bcm4710_cpu_cycle) << 8);   /* W1 = 100nS */
     15812+       tmp = tmp | (129 / bcm4710_cpu_cycle);          /* W0 = 120nS */
     15813+       writel(tmp, &eir->pcmcia_attrwait);             /* 0x01020a0c for a 100Mhz clock */
     15814+
     15815+#endif
     15816+       /* Make sure gpio0 and gpio5 are inputs */
     15817+       outen = readl(&eir->gpio[0].outen);
     15818+       outen &= ~(BCM47XX_PCMCIA_WP | BCM47XX_PCMCIA_STSCHG | BCM47XX_PCMCIA_RESET);
     15819+       writel(outen, &eir->gpio[0].outen);
     15820+
     15821+       /* Issue a reset to the pcmcia socket */
     15822+       bcm4710_pcmcia_reset();
     15823+
     15824+#ifdef DO_BCM47XX_PCMCIA_INTERRUPTS
     15825+       /* Setup gpio5 to be the STSCHG interrupt */
     15826+       intp = readl(&eir->gpiointpolarity);
     15827+       writel(intp | BCM47XX_PCMCIA_STSCHG, &eir->gpiointpolarity);    /* Active low */
     15828+       intm = readl(&eir->gpiointmask);
     15829+       writel(intm | BCM47XX_PCMCIA_STSCHG, &eir->gpiointmask);        /* Enable it */
     15830+#endif
     15831+
     15832+       DEBUG(2, "bcm4710_pcmcia after reset:\n");
     15833+       DEBUG(2, "\textstatus\t= 0x%08x:\n", readl(&eir->extstatus));
     15834+       DEBUG(2, "\tpcmcia_config\t= 0x%08x:\n", readl(&eir->pcmcia_config));
     15835+       DEBUG(2, "\tpcmcia_memwait\t= 0x%08x:\n", readl(&eir->pcmcia_memwait));
     15836+       DEBUG(2, "\tpcmcia_attrwait\t= 0x%08x:\n", readl(&eir->pcmcia_attrwait));
     15837+       DEBUG(2, "\tpcmcia_iowait\t= 0x%08x:\n", readl(&eir->pcmcia_iowait));
     15838+       DEBUG(2, "\tgpioin\t\t= 0x%08x:\n", readl(&eir->gpioin));
     15839+       DEBUG(2, "\tgpio_outen0\t= 0x%08x:\n", readl(&eir->gpio[0].outen));
     15840+       DEBUG(2, "\tgpio_out0\t= 0x%08x:\n", readl(&eir->gpio[0].out));
     15841+       DEBUG(2, "\tgpiointpolarity\t= 0x%08x:\n", readl(&eir->gpiointpolarity));
     15842+       DEBUG(2, "\tgpiointmask\t= 0x%08x:\n", readl(&eir->gpiointmask));
     15843+
     15844+#ifdef DO_BCM47XX_PCMCIA_INTERRUPTS
     15845+       /* Request pcmcia interrupt */
     15846+       rc =  request_irq(BCM47XX_PCMCIA_IRQ, init->handler, SA_INTERRUPT,
     15847+                         "PCMCIA Interrupt", &bcm47xx_pcmcia_dev_id);
     15848+#endif
     15849+
     15850+       attrsp = (uint16 *)ioremap_nocache(EXTIF_PCMCIA_CFGBASE(BCM4710_EXTIF), 0x1000);
     15851+       tmp = readw(&attrsp[0]);
     15852+       DEBUG(2, "\tattr[0] = 0x%04x\n", tmp);
     15853+       if ((tmp == 0x7fff) || (tmp == 0x7f00)) {
     15854+               bcm47xx_pcmcia_present = 0;
     15855+       } else {
     15856+               bcm47xx_pcmcia_present = 1;
     15857+       }
     15858+
     15859+       /* There's only one socket */
     15860+       return 1;
     15861+}
     15862+
     15863+static int bcm4710_pcmcia_shutdown(void)
     15864+{
     15865+       extifregs_t *eir;
     15866+       uint32 intm;
     15867+
     15868+       eir = (extifregs_t *) ioremap_nocache(BCM4710_REG_EXTIF, sizeof(extifregs_t));
     15869+
     15870+       /* Disable the pcmcia i/f */
     15871+       writel(0, &eir->pcmcia_config);
     15872+
     15873+       /* Reset gpio's */
     15874+       intm = readl(&eir->gpiointmask);
     15875+       writel(intm & ~BCM47XX_PCMCIA_STSCHG, &eir->gpiointmask);       /* Disable it */
     15876+
     15877+       free_irq(BCM47XX_PCMCIA_IRQ, &bcm47xx_pcmcia_dev_id);
     15878+
     15879+       return 0;
     15880+}
     15881+
     15882+static int
     15883+bcm4710_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
     15884+{
     15885+       extifregs_t *eir;
     15886+
     15887+       eir = (extifregs_t *) ioremap_nocache(BCM4710_REG_EXTIF, sizeof(extifregs_t));
     15888+
     15889+
     15890+       if (sock != 0) {
     15891+               printk(KERN_ERR "bcm4710 socket_state bad sock %d\n", sock);
     15892+               return -1;
     15893+       }
     15894+
     15895+       if (bcm47xx_pcmcia_present) {
     15896+               state->detect = 1;
     15897+               state->ready = 1;
     15898+               state->bvd1 = 1;
     15899+               state->bvd2 = 1;
     15900+               state->wrprot = (readl(&eir->gpioin) & BCM47XX_PCMCIA_WP) == BCM47XX_PCMCIA_WP;
     15901+               state->vs_3v = 0;
     15902+               state->vs_Xv = 0;
     15903+       } else {
     15904+               state->detect = 0;
     15905+               state->ready = 0;
     15906+       }
     15907+
     15908+       return 1;
     15909+}
     15910+
     15911+
     15912+static int bcm4710_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
     15913+{
     15914+       if (info->sock >= BCM47XX_PCMCIA_MAX_SOCK) return -1;
     15915+
     15916+       info->irq = BCM47XX_PCMCIA_IRQ;         
     15917+
     15918+       return 0;
     15919+}
     15920+
     15921+
     15922+static int
     15923+bcm4710_pcmcia_configure_socket(const struct pcmcia_configure *configure)
     15924+{
     15925+       if (configure->sock >= BCM47XX_PCMCIA_MAX_SOCK) return -1;
     15926+
     15927+
     15928+       DEBUG(2, "Vcc %dV Vpp %dV output %d speaker %d reset %d\n", configure->vcc,
     15929+             configure->vpp, configure->output, configure->speaker, configure->reset);
     15930+
     15931+       if ((configure->vcc != 50) || (configure->vpp != 50)) {
     15932+               printk("%s: bad Vcc/Vpp (%d:%d)\n", __FUNCTION__, configure->vcc,
     15933+                      configure->vpp);
     15934+       }
     15935+
     15936+       if (configure->reset) {
     15937+               /* Issue a reset to the pcmcia socket */
     15938+               DEBUG(1, "%s: Reseting socket\n", __FUNCTION__);
     15939+               bcm4710_pcmcia_reset();
     15940+       }
     15941+
     15942+
     15943+       return 0;
     15944+}
     15945+
     15946+struct pcmcia_low_level bcm4710_pcmcia_ops = {
     15947+       bcm4710_pcmcia_init,
     15948+       bcm4710_pcmcia_shutdown,
     15949+       bcm4710_pcmcia_socket_state,
     15950+       bcm4710_pcmcia_get_irq_info,
     15951+       bcm4710_pcmcia_configure_socket
     15952+};
     15953+
     15954diff -Nur linux-2.4.32/drivers/pcmcia/bcm4710pcmcia.h linux-2.4.32-freewrt/drivers/pcmcia/bcm4710pcmcia.h
     15955--- linux-2.4.32/drivers/pcmcia/bcm4710pcmcia.h 1970-01-01 01:00:00.000000000 +0100
     15956+++ linux-2.4.32-freewrt/drivers/pcmcia/bcm4710pcmcia.h 2006-07-02 21:58:25.000000000 +0200
     15957@@ -0,0 +1,118 @@
     15958+/*
     15959+ *
     15960+ * bcm47xx pcmcia driver
     15961+ *
     15962+ * Copyright 2004, Broadcom Corporation
     15963+ * All Rights Reserved.
     15964+ *
     15965+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
     15966+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
     15967+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
     15968+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
     15969+ *
     15970+ * Based on sa1100.h and include/asm-arm/arch-sa1100/pcmica.h
     15971+ *     from www.handhelds.org,
     15972+ * and au1000_generic.c from oss.sgi.com.
     15973+ *
     15974+ * $Id: bcm4710pcmcia.h,v 1.1 2005/03/16 13:50:00 wbx Exp $
     15975+ */
     15976+
     15977+#if !defined(_BCM4710PCMCIA_H)
     15978+#define _BCM4710PCMCIA_H
     15979+
     15980+#include <pcmcia/cs_types.h>
     15981+#include <pcmcia/ss.h>
     15982+#include <pcmcia/bulkmem.h>
     15983+#include <pcmcia/cistpl.h>
     15984+#include "cs_internal.h"
     15985+
     15986+
     15987+/* The 47xx can only support one socket */
     15988+#define BCM47XX_PCMCIA_MAX_SOCK                1
     15989+
     15990+/* In the bcm947xx gpio's are used for some pcmcia functions */
     15991+#define        BCM47XX_PCMCIA_WP               0x01            /* Bit 0 is WP input */
     15992+#define        BCM47XX_PCMCIA_STSCHG           0x20            /* Bit 5 is STSCHG input/interrupt */
     15993+#define        BCM47XX_PCMCIA_RESET            0x80            /* Bit 7 is RESET */
     15994+
     15995+#define        BCM47XX_PCMCIA_IRQ              2
     15996+
     15997+/* The socket driver actually works nicely in interrupt-driven form,
     15998+ * so the (relatively infrequent) polling is "just to be sure."
     15999+ */
     16000+#define BCM47XX_PCMCIA_POLL_PERIOD    (2 * HZ)
     16001+
     16002+#define BCM47XX_PCMCIA_IO_SPEED       (255)
     16003+#define BCM47XX_PCMCIA_MEM_SPEED      (300)
     16004+
     16005+
     16006+struct pcmcia_state {
     16007+       unsigned detect: 1,
     16008+               ready: 1,
     16009+               bvd1: 1,
     16010+               bvd2: 1,
     16011+               wrprot: 1,
     16012+               vs_3v: 1,
     16013+               vs_Xv: 1;
     16014+};
     16015+
     16016+
     16017+struct pcmcia_configure {
     16018+       unsigned sock: 8,
     16019+               vcc: 8,
     16020+               vpp: 8,
     16021+               output: 1,
     16022+               speaker: 1,
     16023+               reset: 1;
     16024+};
     16025+
     16026+struct pcmcia_irq_info {
     16027+       unsigned int sock;
     16028+       unsigned int irq;
     16029+};
     16030+
     16031+/* This structure encapsulates per-socket state which we might need to
     16032+ * use when responding to a Card Services query of some kind.
     16033+ */
     16034+struct bcm47xx_pcmcia_socket {
     16035+  socket_state_t        cs_state;
     16036+  struct pcmcia_state   k_state;
     16037+  unsigned int          irq;
     16038+  void                  (*handler)(void *, unsigned int);
     16039+  void                  *handler_info;
     16040+  pccard_io_map         io_map[MAX_IO_WIN];
     16041+  pccard_mem_map        mem_map[MAX_WIN];
     16042+  ioaddr_t              virt_io, phys_attr, phys_mem;
     16043+  unsigned short        speed_io, speed_attr, speed_mem;
     16044+};
     16045+
     16046+struct pcmcia_init {
     16047+       void (*handler)(int irq, void *dev, struct pt_regs *regs);
     16048+};
     16049+
     16050+struct pcmcia_low_level {
     16051+       int (*init)(struct pcmcia_init *);
     16052+       int (*shutdown)(void);
     16053+       int (*socket_state)(unsigned sock, struct pcmcia_state *);
     16054+       int (*get_irq_info)(struct pcmcia_irq_info *);
     16055+       int (*configure_socket)(const struct pcmcia_configure *);
     16056+};
     16057+
     16058+extern struct pcmcia_low_level bcm47xx_pcmcia_ops;
     16059+
     16060+/* I/O pins replacing memory pins
     16061+ * (PCMCIA System Architecture, 2nd ed., by Don Anderson, p.75)
     16062+ *
     16063+ * These signals change meaning when going from memory-only to
     16064+ * memory-or-I/O interface:
     16065+ */
     16066+#define iostschg bvd1
     16067+#define iospkr   bvd2
     16068+
     16069+
     16070+/*
     16071+ * Declaration for implementation specific low_level operations.
     16072+ */
     16073+extern struct pcmcia_low_level bcm4710_pcmcia_ops;
     16074+
     16075+#endif  /* !defined(_BCM4710PCMCIA_H) */
     16076diff -Nur linux-2.4.32/include/asm-mips/bootinfo.h linux-2.4.32-freewrt/include/asm-mips/bootinfo.h
     16077--- linux-2.4.32/include/asm-mips/bootinfo.h    2004-02-18 14:36:32.000000000 +0100
     16078+++ linux-2.4.32-freewrt/include/asm-mips/bootinfo.h    2006-07-02 21:58:25.000000000 +0200
    1990316079@@ -37,6 +37,7 @@
    1990416080 #define MACH_GROUP_HP_LJ       20 /* Hewlett Packard LaserJet               */
     
    1990916085 /*
    1991016086  * Valid machtype values for group unknown (low order halfword of mips_machtype)
    19911 @@ -197,6 +198,15 @@
     16087@@ -194,6 +195,15 @@
    1991216088 #define MACH_TANBAC_TB0229     7       /* TANBAC TB0229 (VR4131DIMM) */
    1991316089 
     
    1992516101  */
    1992616102 #define        MACH_TITAN_YOSEMITE     1       /* PMC-Sierra Yosemite */
    19927 diff -urN linux.old/include/asm-mips/cpu.h linux.dev/include/asm-mips/cpu.h
    19928 --- linux.old/include/asm-mips/cpu.h    2006-04-27 18:04:38.000000000 +0200
    19929 +++ linux.dev/include/asm-mips/cpu.h    2006-04-27 19:24:19.000000000 +0200
     16103diff -Nur linux-2.4.32/include/asm-mips/cpu.h linux-2.4.32-freewrt/include/asm-mips/cpu.h
     16104--- linux-2.4.32/include/asm-mips/cpu.h 2005-01-19 15:10:11.000000000 +0100
     16105+++ linux-2.4.32-freewrt/include/asm-mips/cpu.h 2006-07-02 21:58:25.000000000 +0200
    1993016106@@ -22,6 +22,11 @@
    1993116107    spec.
     
    1997616152 /*
    1997716153  * ISA Level encodings
    19978 diff -urN linux.old/include/asm-mips/r4kcache.h linux.dev/include/asm-mips/r4kcache.h
    19979 --- linux.old/include/asm-mips/r4kcache.h       2006-04-27 18:04:38.000000000 +0200
    19980 +++ linux.dev/include/asm-mips/r4kcache.h       2006-04-27 19:24:19.000000000 +0200
    19981 @@ -658,4 +658,17 @@
     16154diff -Nur linux-2.4.32/include/asm-mips/r4kcache.h linux-2.4.32-freewrt/include/asm-mips/r4kcache.h
     16155--- linux-2.4.32/include/asm-mips/r4kcache.h    2004-02-18 14:36:32.000000000 +0100
     16156+++ linux-2.4.32-freewrt/include/asm-mips/r4kcache.h    2006-07-02 21:58:25.000000000 +0200
     16157@@ -567,4 +567,17 @@
    1998216158                        cache128_unroll32(addr|ws,Index_Writeback_Inv_SD);
    1998316159 }
     
    1999716173+
    1999816174 #endif /* __ASM_R4KCACHE_H */
    19999 diff -urN linux.old/include/asm-mips/serial.h linux.dev/include/asm-mips/serial.h
    20000 --- linux.old/include/asm-mips/serial.h 2006-04-27 18:04:38.000000000 +0200
    20001 +++ linux.dev/include/asm-mips/serial.h 2006-04-27 19:24:19.000000000 +0200
     16175diff -Nur linux-2.4.32/include/asm-mips/serial.h linux-2.4.32-freewrt/include/asm-mips/serial.h
     16176--- linux-2.4.32/include/asm-mips/serial.h      2005-01-19 15:10:12.000000000 +0100
     16177+++ linux-2.4.32-freewrt/include/asm-mips/serial.h      2006-07-02 21:58:25.000000000 +0200
    2000216178@@ -223,6 +223,13 @@
    2000316179 #define TXX927_SERIAL_PORT_DEFNS
     
    2002216198        DDB5477_SERIAL_PORT_DEFNS               \
    2002316199        EV96100_SERIAL_PORT_DEFNS               \
    20024 diff -urN linux.old/init/do_mounts.c linux.dev/init/do_mounts.c
    20025 --- linux.old/init/do_mounts.c  2006-04-27 18:04:38.000000000 +0200
    20026 +++ linux.dev/init/do_mounts.c  2006-04-27 19:24:19.000000000 +0200
    20027 @@ -254,7 +254,13 @@
     16200diff -Nur linux-2.4.32/init/do_mounts.c linux-2.4.32-freewrt/init/do_mounts.c
     16201--- linux-2.4.32/init/do_mounts.c       2003-11-28 19:26:21.000000000 +0100
     16202+++ linux-2.4.32-freewrt/init/do_mounts.c       2006-07-02 21:58:25.000000000 +0200
     16203@@ -253,7 +253,13 @@
    2002816204        { "ftlb", 0x2c08 },
    2002916205        { "ftlc", 0x2c10 },
Note: See TracChangeset for help on using the changeset viewer.