[BACK]Return to if_le.c CVS log [TXT][DIR] Up to [local] / sys / arch / aviion / stand / netboot

Annotation of sys/arch/aviion/stand/netboot/if_le.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: if_le.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
                      2:
                      3: /*
                      4:  * Copyright (c) 1995 Theo de Raadt
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
                     16:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     18:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
                     19:  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     20:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     21:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     22:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     23:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     24:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     25:  * SUCH DAMAGE.
                     26:  *
                     27:  * Copyright (c) 1993 Adam Glass
                     28:  * All rights reserved.
                     29:  *
                     30:  * Redistribution and use in source and binary forms, with or without
                     31:  * modification, are permitted provided that the following conditions
                     32:  * are met:
                     33:  * 1. Redistributions of source code must retain the above copyright
                     34:  *    notice, this list of conditions and the following disclaimer.
                     35:  * 2. Redistributions in binary form must reproduce the above copyright
                     36:  *    notice, this list of conditions and the following disclaimer in the
                     37:  *    documentation and/or other materials provided with the distribution.
                     38:  * 3. All advertising materials mentioning features or use of this software
                     39:  *    must display the following acknowledgement:
                     40:  *     This product includes software developed by Adam Glass.
                     41:  * 4. The name of the Author may not be used to endorse or promote products
                     42:  *    derived from this software without specific prior written permission.
                     43:  *
                     44:  * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
                     45:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     46:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     47:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     48:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     49:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     50:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     51:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     52:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     53:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     54:  * SUCH DAMAGE.
                     55:  */
                     56:
                     57: #include <sys/param.h>
                     58: #include <sys/types.h>
                     59:
                     60: #include <netinet/in.h>
                     61: #include <netinet/in_systm.h>
                     62:
                     63: #include <machine/prom.h>
                     64:
                     65: #include "stand.h"
                     66: #include "libsa.h"
                     67: #include "net.h"
                     68: #include "netif.h"
                     69:
                     70: #include "if_lereg.h"
                     71:
                     72: int     le_debug = 0;
                     73:
                     74: void le_end(struct netif *);
                     75: void le_error(struct netif *, char *, volatile struct lereg1 *);
                     76: int le_get(struct iodesc *, void *, size_t, time_t);
                     77: void le_init(struct iodesc *, void *);
                     78: int le_match(struct netif *, void *);
                     79: int le_poll(struct iodesc *, void *, int);
                     80: int le_probe(struct netif *, void *);
                     81: int le_put(struct iodesc *, void *, size_t);
                     82: void le_reset(struct netif *, u_char *);
                     83: extern void machdep_common_ether(u_char *);
                     84:
                     85: struct netif_stats le_stats;
                     86:
                     87: struct netif_dif le0_dif = {
                     88:        0,                      /* unit */
                     89:        1,                      /* nsel */
                     90:        &le_stats,
                     91:        0,
                     92:        0,
                     93: };
                     94:
                     95: struct netif_driver le_driver = {
                     96:        "le",                   /* netif_bname */
                     97:        le_match,               /* match */
                     98:        le_probe,               /* probe */
                     99:        le_init,                /* init */
                    100:        le_get,                 /* get */
                    101:        le_put,                 /* put */
                    102:        le_end,                 /* end */
                    103:        &le0_dif,               /* netif_ifs */
                    104:        1,                      /* netif_nifs */
                    105: };
                    106:
                    107: struct le_configuration {
                    108:        unsigned int phys_addr;
                    109:        int     used;
                    110: } le_config[] = {
                    111:        { 0xfff8c000,   0 }     /* AV400 */
                    112: };
                    113:
                    114: int     nle_config = sizeof(le_config) / (sizeof(le_config[0]));
                    115:
                    116: struct {
                    117:        struct lereg1 *sc_r1;   /* LANCE registers */
                    118:        struct lereg2 *sc_r2;   /* RAM */
                    119:        int     next_rmd;
                    120:        int     next_tmd;
                    121: }       le_softc;
                    122:
                    123: int
                    124: le_match(nif, machdep_hint)
                    125:        struct netif *nif;
                    126:        void   *machdep_hint;
                    127: {
                    128:        char   *name;
                    129:        int     i, val = 0;
                    130:
                    131:        name = machdep_hint;
                    132:        if (name && !bcmp(le_driver.netif_bname, name, 2))
                    133:                val += 10;
                    134:        for (i = 0; i < nle_config; i++) {
                    135:                if (le_config[i].used)
                    136:                        continue;
                    137:                if (le_debug)
                    138:                        printf("le%d: le_match --> %d\n", i, val + 1);
                    139:                le_config[i].used++;
                    140:                return val + 1;
                    141:        }
                    142:        if (le_debug)
                    143:                printf("le%d: le_match --> 0\n", i);
                    144:        return 0;
                    145: }
                    146:
                    147: int
                    148: le_probe(nif, machdep_hint)
                    149:        struct netif *nif;
                    150:        void   *machdep_hint;
                    151: {
                    152:
                    153:        /* the set unit is the current unit */
                    154:        if (le_debug)
                    155:                printf("le%d: le_probe called\n", nif->nif_unit);
                    156:
                    157:        return 0;
                    158: }
                    159:
                    160: void
                    161: le_error(nif, str, ler1)
                    162:        struct netif *nif;
                    163:        char   *str;
                    164:        volatile struct lereg1 *ler1;
                    165: {
                    166:        /* ler1->ler1_rap = LE_CSRO done in caller */
                    167:        if (ler1->ler1_rdp & LE_C0_BABL)
                    168:                panic("le%d: been babbling, found by '%s'", nif->nif_unit, str);
                    169:        if (ler1->ler1_rdp & LE_C0_CERR) {
                    170:                le_stats.collision_error++;
                    171:                ler1->ler1_rdp = LE_C0_CERR;
                    172:        }
                    173:        if (ler1->ler1_rdp & LE_C0_MISS) {
                    174:                le_stats.missed++;
                    175:                ler1->ler1_rdp = LE_C0_MISS;
                    176:        }
                    177:        if (ler1->ler1_rdp & LE_C0_MERR) {
                    178:                printf("le%d: memory error in '%s'\n", nif->nif_unit, str);
                    179:                panic("memory error");
                    180:        }
                    181: }
                    182:
                    183: void
                    184: le_reset(nif, myea)
                    185:        struct netif *nif;
                    186:        u_char *myea;
                    187: {
                    188:        struct lereg1 *ler1 = le_softc.sc_r1;
                    189:        struct lereg2 *ler2 = le_softc.sc_r2;
                    190:        unsigned int a;
                    191:        int timo = 100000, stat = 0, i;
                    192:
                    193:        if (le_debug)
                    194:                printf("le%d: le_reset called\n", nif->nif_unit);
                    195:        ler1->ler1_rap = LE_CSR0;
                    196:        ler1->ler1_rdp = LE_C0_STOP;    /* do nothing until we are finished */
                    197:
                    198:        bzero(ler2, sizeof(*ler2));
                    199:
                    200:        ler2->ler2_mode = LE_MODE_NORMAL;
                    201:        ler2->ler2_padr[0] = myea[1];
                    202:        ler2->ler2_padr[1] = myea[0];
                    203:        ler2->ler2_padr[2] = myea[3];
                    204:        ler2->ler2_padr[3] = myea[2];
                    205:        ler2->ler2_padr[4] = myea[5];
                    206:        ler2->ler2_padr[5] = myea[4];
                    207:
                    208:        ler2->ler2_ladrf0 = 0;
                    209:        ler2->ler2_ladrf1 = 0;
                    210:
                    211:        a = (u_int) ler2->ler2_rmd;
                    212:        ler2->ler2_rlen = LE_RLEN | (a >> 16);
                    213:        ler2->ler2_rdra = a & LE_ADDR_LOW_MASK;
                    214:
                    215:        a = (u_int) ler2->ler2_tmd;
                    216:        ler2->ler2_tlen = LE_TLEN | (a >> 16);
                    217:        ler2->ler2_tdra = a & LE_ADDR_LOW_MASK;
                    218:
                    219:        ler1->ler1_rap = LE_CSR1;
                    220:        a = (u_int) ler2;
                    221:        ler1->ler1_rdp = a & LE_ADDR_LOW_MASK;
                    222:        ler1->ler1_rap = LE_CSR2;
                    223:        ler1->ler1_rdp = a >> 16;
                    224:
                    225:        for (i = 0; i < LERBUF; i++) {
                    226:                a = (u_int) & ler2->ler2_rbuf[i];
                    227:                ler2->ler2_rmd[i].rmd0 = a & LE_ADDR_LOW_MASK;
                    228:                ler2->ler2_rmd[i].rmd1_bits = LE_R1_OWN;
                    229:                ler2->ler2_rmd[i].rmd1_hadr = a >> 16;
                    230:                ler2->ler2_rmd[i].rmd2 = -LEMTU;
                    231:                ler2->ler2_rmd[i].rmd3 = 0;
                    232:        }
                    233:        for (i = 0; i < LETBUF; i++) {
                    234:                a = (u_int) & ler2->ler2_tbuf[i];
                    235:                ler2->ler2_tmd[i].tmd0 = a & LE_ADDR_LOW_MASK;
                    236:                ler2->ler2_tmd[i].tmd1_bits = 0;
                    237:                ler2->ler2_tmd[i].tmd1_hadr = a >> 16;
                    238:                ler2->ler2_tmd[i].tmd2 = 0;
                    239:                ler2->ler2_tmd[i].tmd3 = 0;
                    240:        }
                    241:
                    242:        ler1->ler1_rap = LE_CSR3;
                    243:        ler1->ler1_rdp = LE_C3_BSWP;
                    244:
                    245:        ler1->ler1_rap = LE_CSR0;
                    246:        ler1->ler1_rdp = LE_C0_INIT;
                    247:        do {
                    248:                if (--timo == 0) {
                    249:                        printf("le%d: init timeout, stat = 0x%x\n",
                    250:                            nif->nif_unit, stat);
                    251:                        break;
                    252:                }
                    253:                stat = ler1->ler1_rdp;
                    254:        } while ((stat & LE_C0_IDON) == 0);
                    255:
                    256:        ler1->ler1_rdp = LE_C0_IDON;
                    257:        le_softc.next_rmd = 0;
                    258:        le_softc.next_tmd = 0;
                    259:        ler1->ler1_rap = LE_CSR0;
                    260:        ler1->ler1_rdp = LE_C0_STRT;
                    261: }
                    262:
                    263: int
                    264: le_poll(desc, pkt, len)
                    265:        struct iodesc *desc;
                    266:        void   *pkt;
                    267:        int     len;
                    268: {
                    269:        struct lereg1 *ler1 = le_softc.sc_r1;
                    270:        struct lereg2 *ler2 = le_softc.sc_r2;
                    271:        unsigned int a;
                    272:        int     length;
                    273:        struct lermd *rmd;
                    274:
                    275:        ler1->ler1_rap = LE_CSR0;
                    276:        if ((ler1->ler1_rdp & LE_C0_RINT) != 0)
                    277:                ler1->ler1_rdp = LE_C0_RINT;
                    278:        rmd = &ler2->ler2_rmd[le_softc.next_rmd];
                    279:        if (rmd->rmd1_bits & LE_R1_OWN) {
                    280:                return (0);
                    281:        }
                    282:        if (ler1->ler1_rdp & LE_C0_ERR)
                    283:                le_error(desc->io_netif, "le_poll", ler1);
                    284:        if (rmd->rmd1_bits & LE_R1_ERR) {
                    285:                printf("le%d_poll: rmd status 0x%x\n", desc->io_netif->nif_unit,
                    286:                    rmd->rmd1_bits);
                    287:                length = 0;
                    288:                goto cleanup;
                    289:        }
                    290:        if ((rmd->rmd1_bits & (LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP))
                    291:                panic("le_poll: chained packet");
                    292:
                    293:        length = rmd->rmd3;
                    294:        if (length >= LEMTU) {
                    295:                length = 0;
                    296:                panic("csr0 when bad things happen: %x", ler1->ler1_rdp);
                    297:                goto cleanup;
                    298:        }
                    299:        if (!length)
                    300:                goto cleanup;
                    301:        length -= 4;
                    302:        if (length > 0) {
                    303:                /*
                    304:                 * if buffer is smaller than the packet truncate it.
                    305:                 * (is this wise?)
                    306:                 */
                    307:                if (length > len)
                    308:                        length = len;
                    309:
                    310:                bcopy((void *)&ler2->ler2_rbuf[le_softc.next_rmd], pkt, length);
                    311:        }
                    312: cleanup:
                    313:        a = (u_int) & ler2->ler2_rbuf[le_softc.next_rmd];
                    314:        rmd->rmd0 = a & LE_ADDR_LOW_MASK;
                    315:        rmd->rmd1_hadr = a >> 16;
                    316:        rmd->rmd2 = -LEMTU;
                    317:        le_softc.next_rmd =
                    318:            (le_softc.next_rmd == (LERBUF - 1)) ? 0 : (le_softc.next_rmd + 1);
                    319:        rmd->rmd1_bits = LE_R1_OWN;
                    320:        return length;
                    321: }
                    322:
                    323: int
                    324: le_put(desc, pkt, len)
                    325:        struct  iodesc *desc;
                    326:        void    *pkt;
                    327:        size_t  len;
                    328: {
                    329:        volatile struct lereg1 *ler1 = le_softc.sc_r1;
                    330:        volatile struct lereg2 *ler2 = le_softc.sc_r2;
                    331:        volatile struct letmd *tmd;
                    332:        int timo = 100000, stat = 0;
                    333:        unsigned int a;
                    334:
                    335:        ler1->ler1_rap = LE_CSR0;
                    336:        if (ler1->ler1_rdp & LE_C0_ERR)
                    337:                le_error(desc->io_netif, "le_put(way before xmit)", ler1);
                    338:        tmd = &ler2->ler2_tmd[le_softc.next_tmd];
                    339:        while (tmd->tmd1_bits & LE_T1_OWN) {
                    340:                printf("le%d: output buffer busy\n", desc->io_netif->nif_unit);
                    341:        }
                    342:        bcopy(pkt, (void *)ler2->ler2_tbuf[le_softc.next_tmd], len);
                    343:        if (len < 64)
                    344:                tmd->tmd2 = -64;
                    345:        else
                    346:                tmd->tmd2 = -len;
                    347:        tmd->tmd3 = 0;
                    348:        if (ler1->ler1_rdp & LE_C0_ERR)
                    349:                le_error(desc->io_netif, "le_put(before xmit)", ler1);
                    350:        tmd->tmd1_bits = LE_T1_STP | LE_T1_ENP | LE_T1_OWN;
                    351:        a = (u_int) & ler2->ler2_tbuf[le_softc.next_tmd];
                    352:        tmd->tmd0 = a & LE_ADDR_LOW_MASK;
                    353:        tmd->tmd1_hadr = a >> 16;
                    354:        ler1->ler1_rdp = LE_C0_TDMD;
                    355:        if (ler1->ler1_rdp & LE_C0_ERR)
                    356:                le_error(desc->io_netif, "le_put(after xmit)", ler1);
                    357:        do {
                    358:                if (--timo == 0) {
                    359:                        printf("le%d: transmit timeout, stat = 0x%x\n",
                    360:                            desc->io_netif->nif_unit, stat);
                    361:                        if (ler1->ler1_rdp & LE_C0_ERR)
                    362:                                le_error(desc->io_netif, "le_put(timeout)", ler1);
                    363:                        break;
                    364:                }
                    365:                stat = ler1->ler1_rdp;
                    366:        } while ((stat & LE_C0_TINT) == 0);
                    367:        ler1->ler1_rdp = LE_C0_TINT;
                    368:        if (ler1->ler1_rdp & LE_C0_ERR) {
                    369:                if ((ler1->ler1_rdp & (LE_C0_BABL | LE_C0_CERR | LE_C0_MISS |
                    370:                    LE_C0_MERR)) !=
                    371:                    LE_C0_CERR)
                    372:                        printf("le_put: xmit error, buf %d\n", le_softc.next_tmd);
                    373:                le_error(desc->io_netif, "le_put(xmit error)", ler1);
                    374:        }
                    375:        le_softc.next_tmd = 0;
                    376: /*     (le_softc.next_tmd == (LETBUF - 1)) ? 0 : le_softc.next_tmd + 1;*/
                    377:        if (tmd->tmd1_bits & LE_T1_DEF)
                    378:                le_stats.deferred++;
                    379:        if (tmd->tmd1_bits & LE_T1_ONE)
                    380:                le_stats.collisions++;
                    381:        if (tmd->tmd1_bits & LE_T1_MORE)
                    382:                le_stats.collisions += 2;
                    383:        if (tmd->tmd1_bits & LE_T1_ERR) {
                    384:                printf("le%d: transmit error, error = 0x%x\n", desc->io_netif->nif_unit,
                    385:                    tmd->tmd3);
                    386:                return -1;
                    387:        }
                    388:        if (le_debug) {
                    389:                printf("le%d: le_put() successful: sent %ld\n",
                    390:                    desc->io_netif->nif_unit, len);
                    391:                printf("le%d: le_put(): tmd1_bits: %x tmd3: %x\n",
                    392:                    desc->io_netif->nif_unit,
                    393:                    (unsigned int) tmd->tmd1_bits,
                    394:                    (unsigned int) tmd->tmd3);
                    395:        }
                    396:        return len;
                    397: }
                    398:
                    399: int
                    400: le_get(desc, pkt, len, timeout)
                    401:        struct  iodesc *desc;
                    402:        void    *pkt;
                    403:        size_t  len;
                    404:        time_t  timeout;
                    405: {
                    406:        time_t  t;
                    407:        int     cc;
                    408:
                    409:        t = getsecs();
                    410:        cc = 0;
                    411:        while (((getsecs() - t) < timeout) && !cc) {
                    412:                cc = le_poll(desc, pkt, len);
                    413:        }
                    414:        return cc;
                    415: }
                    416: /*
                    417:  * init le device.   return 0 on failure, 1 if ok.
                    418:  */
                    419: void
                    420: le_init(desc, machdep_hint)
                    421:        struct iodesc *desc;
                    422:        void   *machdep_hint;
                    423: {
                    424:        u_long eram = 4*1024*1024;
                    425:        struct netif *nif = desc->io_netif;
                    426:
                    427:        if (le_debug)
                    428:                printf("le%d: le_init called\n", desc->io_netif->nif_unit);
                    429:        machdep_common_ether(desc->myea);
                    430:        bzero(&le_softc, sizeof(le_softc));
                    431:        le_softc.sc_r1 =
                    432:            (struct lereg1 *) le_config[desc->io_netif->nif_unit].phys_addr;
                    433:        le_softc.sc_r2 = (struct lereg2 *) (eram - (1024 * 1024));
                    434:        le_reset(desc->io_netif, desc->myea);
                    435:        printf("device: %s%d attached to %s\n", nif->nif_driver->netif_bname,
                    436:            nif->nif_unit, ether_sprintf(desc->myea));
                    437: }
                    438:
                    439: void
                    440: le_end(nif)
                    441:        struct netif *nif;
                    442: {
                    443:        struct lereg1 *ler1 = le_softc.sc_r1;
                    444:
                    445:        if (le_debug)
                    446:                printf("le%d: le_end called\n", nif->nif_unit);
                    447:        ler1->ler1_rap = LE_CSR0;
                    448:        ler1->ler1_rdp = LE_C0_STOP;
                    449: }

CVSweb