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

Annotation of sys/arch/mvme68k/stand/sboot/if_le.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: if_le.c,v 1.7 2003/08/19 10:22:30 deraadt 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/cdefs.h>
        !            58: #include <stand.h>
        !            59: #include "sboot.h"
        !            60: #include "if_lereg.h"
        !            61:
        !            62: struct {
        !            63:        struct lereg1 *sc_r1;   /* LANCE registers */
        !            64:        struct lereg2 *sc_r2;   /* RAM */
        !            65:        int     next_rmd;
        !            66:        int     next_tmd;
        !            67: }       le_softc;
        !            68:
        !            69: static void
        !            70: le_error(char *str, struct lereg1 *ler1)
        !            71: {
        !            72:        /* ler1->ler1_rap = LE_CSRO done in caller */
        !            73:        if (ler1->ler1_rdp & LE_C0_BABL) {
        !            74:                printf("le0: been babbling, found by '%s'\n", str);
        !            75:                callrom();
        !            76:        }
        !            77:        if (ler1->ler1_rdp & LE_C0_CERR) {
        !            78:                ler1->ler1_rdp = LE_C0_CERR;
        !            79:        }
        !            80:        if (ler1->ler1_rdp & LE_C0_MISS) {
        !            81:                ler1->ler1_rdp = LE_C0_MISS;
        !            82:        }
        !            83:        if (ler1->ler1_rdp & LE_C0_MERR) {
        !            84:                printf("le0: memory error in '%s'\n", str);
        !            85:                callrom();
        !            86:        }
        !            87: }
        !            88:
        !            89: static void
        !            90: le_reset(u_char *myea)
        !            91: {
        !            92:        struct lereg1 *ler1 = le_softc.sc_r1;
        !            93:        struct lereg2 *ler2 = le_softc.sc_r2;
        !            94:        unsigned int a;
        !            95:        int     timo = 100000, stat, i;
        !            96:
        !            97:        ler1->ler1_rap = LE_CSR0;
        !            98:        ler1->ler1_rdp = LE_C0_STOP;    /* do nothing until we are finished */
        !            99:
        !           100:        bzero(ler2, sizeof(*ler2));
        !           101:
        !           102:        ler2->ler2_mode = LE_MODE_NORMAL;
        !           103:        ler2->ler2_padr[0] = myea[1];
        !           104:        ler2->ler2_padr[1] = myea[0];
        !           105:        ler2->ler2_padr[2] = myea[3];
        !           106:        ler2->ler2_padr[3] = myea[2];
        !           107:        ler2->ler2_padr[4] = myea[5];
        !           108:        ler2->ler2_padr[5] = myea[4];
        !           109:
        !           110:        ler2->ler2_ladrf0 = 0;
        !           111:        ler2->ler2_ladrf1 = 0;
        !           112:
        !           113:        a = (u_int) ler2->ler2_rmd;
        !           114:        ler2->ler2_rlen = LE_RLEN | (a >> 16);
        !           115:        ler2->ler2_rdra = a & LE_ADDR_LOW_MASK;
        !           116:
        !           117:        a = (u_int) ler2->ler2_tmd;
        !           118:        ler2->ler2_tlen = LE_TLEN | (a >> 16);
        !           119:        ler2->ler2_tdra = a & LE_ADDR_LOW_MASK;
        !           120:
        !           121:        ler1->ler1_rap = LE_CSR1;
        !           122:        a = (u_int) ler2;
        !           123:        ler1->ler1_rdp = a & LE_ADDR_LOW_MASK;
        !           124:        ler1->ler1_rap = LE_CSR2;
        !           125:        ler1->ler1_rdp = a >> 16;
        !           126:
        !           127:        for (i = 0; i < LERBUF; i++) {
        !           128:                a = (u_int) & ler2->ler2_rbuf[i];
        !           129:                ler2->ler2_rmd[i].rmd0 = a & LE_ADDR_LOW_MASK;
        !           130:                ler2->ler2_rmd[i].rmd1_bits = LE_R1_OWN;
        !           131:                ler2->ler2_rmd[i].rmd1_hadr = a >> 16;
        !           132:                ler2->ler2_rmd[i].rmd2 = -LEMTU;
        !           133:                ler2->ler2_rmd[i].rmd3 = 0;
        !           134:        }
        !           135:        for (i = 0; i < LETBUF; i++) {
        !           136:                a = (u_int) & ler2->ler2_tbuf[i];
        !           137:                ler2->ler2_tmd[i].tmd0 = a & LE_ADDR_LOW_MASK;
        !           138:                ler2->ler2_tmd[i].tmd1_bits = 0;
        !           139:                ler2->ler2_tmd[i].tmd1_hadr = a >> 16;
        !           140:                ler2->ler2_tmd[i].tmd2 = 0;
        !           141:                ler2->ler2_tmd[i].tmd3 = 0;
        !           142:        }
        !           143:
        !           144:        ler1->ler1_rap = LE_CSR3;
        !           145:        ler1->ler1_rdp = LE_C3_BSWP;
        !           146:
        !           147:        ler1->ler1_rap = LE_CSR0;
        !           148:        ler1->ler1_rdp = LE_C0_INIT;
        !           149:        do {
        !           150:                if (--timo == 0) {
        !           151:                        printf("le0: init timeout, stat = 0x%x\n", stat);
        !           152:                        break;
        !           153:                }
        !           154:                stat = ler1->ler1_rdp;
        !           155:        } while ((stat & LE_C0_IDON) == 0);
        !           156:
        !           157:        ler1->ler1_rdp = LE_C0_IDON;
        !           158:        le_softc.next_rmd = 0;
        !           159:        le_softc.next_tmd = 0;
        !           160:        ler1->ler1_rap = LE_CSR0;
        !           161:        ler1->ler1_rdp = LE_C0_STRT;
        !           162: }
        !           163:
        !           164: static int
        !           165: le_poll(void *pkt, int len)
        !           166: {
        !           167:        struct lereg1 *ler1 = le_softc.sc_r1;
        !           168:        struct lereg2 *ler2 = le_softc.sc_r2;
        !           169:        unsigned int a;
        !           170:        int     length;
        !           171:        struct lermd *rmd;
        !           172:
        !           173:        ler1->ler1_rap = LE_CSR0;
        !           174:        if ((ler1->ler1_rdp & LE_C0_RINT) != 0)
        !           175:                ler1->ler1_rdp = LE_C0_RINT;
        !           176:        rmd = &ler2->ler2_rmd[le_softc.next_rmd];
        !           177:        if (rmd->rmd1_bits & LE_R1_OWN) {
        !           178:                return (0);
        !           179:        }
        !           180:        if (ler1->ler1_rdp & LE_C0_ERR)
        !           181:                le_error("le_poll", ler1);
        !           182:        if (rmd->rmd1_bits & LE_R1_ERR) {
        !           183:                printf("le0_poll: rmd status 0x%x\n", rmd->rmd1_bits);
        !           184:                length = 0;
        !           185:                goto cleanup;
        !           186:        }
        !           187:        if ((rmd->rmd1_bits & (LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP)) {
        !           188:                printf("le_poll: chained packet\n");
        !           189:                callrom();
        !           190:        }
        !           191:        length = rmd->rmd3;
        !           192:        if (length >= LEMTU) {
        !           193:                length = 0;
        !           194:                printf("csr0 when bad things happen: %x\n", ler1->ler1_rdp);
        !           195:                callrom();
        !           196:                goto cleanup;
        !           197:        }
        !           198:        if (!length)
        !           199:                goto cleanup;
        !           200:        length -= 4;
        !           201:        if (length > 0)
        !           202:                bcopy((char *) &ler2->ler2_rbuf[le_softc.next_rmd], pkt, length);
        !           203:
        !           204: cleanup:
        !           205:        a = (u_int) & ler2->ler2_rbuf[le_softc.next_rmd];
        !           206:        rmd->rmd0 = a & LE_ADDR_LOW_MASK;
        !           207:        rmd->rmd1_hadr = a >> 16;
        !           208:        rmd->rmd2 = -LEMTU;
        !           209:        le_softc.next_rmd =
        !           210:            (le_softc.next_rmd == (LERBUF - 1)) ? 0 : (le_softc.next_rmd + 1);
        !           211:        rmd->rmd1_bits = LE_R1_OWN;
        !           212:        return length;
        !           213: }
        !           214:
        !           215: int
        !           216: le_put(u_char *pkt, size_t len)
        !           217: {
        !           218:        struct lereg1 *ler1 = le_softc.sc_r1;
        !           219:        struct lereg2 *ler2 = le_softc.sc_r2;
        !           220:        struct letmd *tmd;
        !           221:        int     timo = 100000, stat, i;
        !           222:        unsigned int a;
        !           223:
        !           224:        ler1->ler1_rap = LE_CSR0;
        !           225:        if (ler1->ler1_rdp & LE_C0_ERR)
        !           226:                le_error("le_put(way before xmit)", ler1);
        !           227:        tmd = &ler2->ler2_tmd[le_softc.next_tmd];
        !           228:        while (tmd->tmd1_bits & LE_T1_OWN) {
        !           229:                printf("le0: output buffer busy\n");
        !           230:        }
        !           231:        bcopy(pkt, (char *) ler2->ler2_tbuf[le_softc.next_tmd], len);
        !           232:        if (len < 64)
        !           233:                tmd->tmd2 = -64;
        !           234:        else
        !           235:                tmd->tmd2 = -len;
        !           236:        tmd->tmd3 = 0;
        !           237:        if (ler1->ler1_rdp & LE_C0_ERR)
        !           238:                le_error("le_put(before xmit)", ler1);
        !           239:        tmd->tmd1_bits = LE_T1_STP | LE_T1_ENP | LE_T1_OWN;
        !           240:        a = (u_int) & ler2->ler2_tbuf[le_softc.next_tmd];
        !           241:        tmd->tmd0 = a & LE_ADDR_LOW_MASK;
        !           242:        tmd->tmd1_hadr = a >> 16;
        !           243:        ler1->ler1_rdp = LE_C0_TDMD;
        !           244:        if (ler1->ler1_rdp & LE_C0_ERR)
        !           245:                le_error("le_put(after xmit)", ler1);
        !           246:        do {
        !           247:                if (--timo == 0) {
        !           248:                        printf("le0: transmit timeout, stat = 0x%x\n",
        !           249:                            stat);
        !           250:                        if (ler1->ler1_rdp & LE_C0_ERR)
        !           251:                                le_error("le_put(timeout)", ler1);
        !           252:                        break;
        !           253:                }
        !           254:                stat = ler1->ler1_rdp;
        !           255:        } while ((stat & LE_C0_TINT) == 0);
        !           256:        ler1->ler1_rdp = LE_C0_TINT;
        !           257:        if (ler1->ler1_rdp & LE_C0_ERR) {
        !           258:                if ((ler1->ler1_rdp & (LE_C0_BABL | LE_C0_CERR | LE_C0_MISS | LE_C0_MERR)) !=
        !           259:                    LE_C0_CERR)
        !           260:                        printf("le_put: xmit error, buf %d\n", le_softc.next_tmd);
        !           261:                le_error("le_put(xmit error)", ler1);
        !           262:        }
        !           263:        le_softc.next_tmd = 0;
        !           264: /*     (le_softc.next_tmd == (LETBUF - 1)) ? 0 : le_softc.next_tmd + 1;*/
        !           265:        if (tmd->tmd1_bits & LE_T1_ERR) {
        !           266:                printf("le0: transmit error, error = 0x%x\n",
        !           267:                    tmd->tmd3);
        !           268:                return -1;
        !           269:        }
        !           270:        return len;
        !           271: }
        !           272:
        !           273: int
        !           274: le_get(u_char *pkt, size_t len, u_long timeout)
        !           275: {
        !           276:        int     cc;
        !           277:        int     now, then;
        !           278:        int     stopat = ttime() + timeout;
        !           279:        then = 0;
        !           280:
        !           281:        cc = 0;
        !           282:        while ((now = ttime()) < stopat && !cc) {
        !           283:                cc = le_poll(pkt, len);
        !           284:                if (then != now) {
        !           285: #ifdef LE_DEBUG
        !           286:                        printf("%d  \r", stopat - now);
        !           287: #endif
        !           288:                        then = now;
        !           289:                }
        !           290:                if (cc && (pkt[0] != myea[0] || pkt[1] != myea[1] ||
        !           291:                        pkt[2] != myea[2] || pkt[3] != myea[3] ||
        !           292:                        pkt[4] != myea[4] || pkt[5] != myea[5])) {
        !           293:                        cc = 0; /* ignore broadcast / multicast */
        !           294: #ifdef LE_DEBUG
        !           295:                        printf("reject (%d sec left)\n", stopat - now);
        !           296: #endif
        !           297:                }
        !           298:        }
        !           299: #ifdef LE_DEBUG
        !           300:        printf("\n");
        !           301: #endif
        !           302:        return cc;
        !           303: }
        !           304:
        !           305: void
        !           306: le_init(void)
        !           307: {
        !           308:        caddr_t addr;
        !           309:        int    *ea = (int *) LANCE_ADDR;
        !           310:        u_long *eram = (u_long *) ERAM_ADDR;
        !           311:        u_long  e = *ea;
        !           312:
        !           313:        if ((e & 0x2fffff00) == 0x2fffff00) {
        !           314:                printf("ERROR: ethernet address not set!  Use LSAD.\n");
        !           315:                callrom();
        !           316:        }
        !           317:        myea[0] = 0x08;
        !           318:        myea[1] = 0x00;
        !           319:        myea[2] = 0x3e;
        !           320:        e = e >> 8;
        !           321:        myea[5] = e & 0xff;
        !           322:        e = e >> 8;
        !           323:        myea[4] = e & 0xff;
        !           324:        e = e >> 8;
        !           325:        myea[3] = e;
        !           326:        printf("le0: ethernet address: %x:%x:%x:%x:%x:%x\n",
        !           327:            myea[0], myea[1], myea[2], myea[3], myea[4], myea[5]);
        !           328:        bzero(&le_softc, sizeof(le_softc));
        !           329:        le_softc.sc_r1 = (struct lereg1 *) LANCE_REG_ADDR;
        !           330:        le_softc.sc_r2 = (struct lereg2 *) (*eram - (1024 * 1024));
        !           331:        le_reset(myea);
        !           332: }
        !           333:
        !           334: void
        !           335: le_end(void)
        !           336: {
        !           337:        struct lereg1 *ler1 = le_softc.sc_r1;
        !           338:
        !           339:        ler1->ler1_rap = LE_CSR0;
        !           340:        ler1->ler1_rdp = LE_C0_STOP;
        !           341: }

CVSweb