[BACK]Return to netif_sun.c CVS log [TXT][DIR] Up to [local] / sys / arch / sparc / stand / common

Annotation of sys/arch/sparc/stand/common/netif_sun.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: netif_sun.c,v 1.1 1997/09/17 10:46:18 downsj Exp $    */
        !             2: /*     $NetBSD: netif_sun.c,v 1.2 1995/09/18 21:31:48 pk Exp $ */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1995 Gordon W. Ross
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms, with or without
        !             9:  * modification, are permitted provided that the following conditions
        !            10:  * are met:
        !            11:  * 1. Redistributions of source code must retain the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer.
        !            13:  * 2. Redistributions in binary form must reproduce the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer in the
        !            15:  *    documentation and/or other materials provided with the distribution.
        !            16:  * 3. The name of the author may not be used to endorse or promote products
        !            17:  *    derived from this software without specific prior written permission.
        !            18:  * 4. All advertising materials mentioning features or use of this software
        !            19:  *    must display the following acknowledgement:
        !            20:  *      This product includes software developed by Gordon W. Ross
        !            21:  *
        !            22:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            23:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            24:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            25:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            26:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            27:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            28:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            29:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            30:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
        !            31:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            32:  */
        !            33:
        !            34: /*
        !            35:  * The Sun PROM has a fairly general set of network drivers,
        !            36:  * so it is easiest to just replace the netif module with
        !            37:  * this adaptation to the PROM network interface.
        !            38:  */
        !            39:
        !            40: #include <sys/param.h>
        !            41: #include <sys/socket.h>
        !            42: #include <string.h>
        !            43: #include <time.h>
        !            44:
        !            45: #include <net/if.h>
        !            46:
        !            47: #include <netinet/in.h>
        !            48: #include <netinet/if_ether.h>
        !            49: #include <netinet/in_systm.h>
        !            50:
        !            51: #include <lib/libsa/stand.h>
        !            52: #include <lib/libsa/net.h>
        !            53: #include <lib/libsa/netif.h>
        !            54:
        !            55: #include <sparc/stand/common/promdev.h>
        !            56:
        !            57: static struct netif netif_prom;
        !            58:
        !            59: #ifdef NETIF_DEBUG
        !            60: int netif_debug;
        !            61: #endif
        !            62:
        !            63: struct iodesc sockets[SOPEN_MAX];
        !            64:
        !            65: struct iodesc *
        !            66: socktodesc(sock)
        !            67:        int sock;
        !            68: {
        !            69:        if (sock != 0) {
        !            70:                return(NULL);
        !            71:        }
        !            72:        return (sockets);
        !            73: }
        !            74:
        !            75: int
        !            76: netif_open(machdep_hint)
        !            77:        void *machdep_hint;
        !            78: {
        !            79:        struct promdata *pd = machdep_hint;
        !            80:        struct iodesc *io;
        !            81:        int fd, error;
        !            82:
        !            83:        /* find a free socket */
        !            84:        io = sockets;
        !            85:        if (io->io_netif) {
        !            86: #ifdef DEBUG
        !            87:                printf("netif_open: device busy\n");
        !            88: #endif
        !            89:                errno = ENFILE;
        !            90:                return (-1);
        !            91:        }
        !            92:        bzero(io, sizeof(*io));
        !            93:
        !            94:        netif_prom.nif_devdata = pd;
        !            95:        io->io_netif = &netif_prom;
        !            96:
        !            97:        /* Put our ethernet address in io->myea */
        !            98:        prom_getether(pd->fd, io->myea);
        !            99:
        !           100:        return(0);
        !           101: }
        !           102:
        !           103: int
        !           104: netif_close(fd)
        !           105:        int fd;
        !           106: {
        !           107:        struct iodesc *io;
        !           108:        struct netif *ni;
        !           109:
        !           110:        if (fd != 0) {
        !           111:                errno = EBADF;
        !           112:                return(-1);
        !           113:        }
        !           114:
        !           115:        io = &sockets[fd];
        !           116:        ni = io->io_netif;
        !           117:        if (ni != NULL) {
        !           118:                ni->nif_devdata = NULL;
        !           119:                io->io_netif = NULL;
        !           120:        }
        !           121:        return(0);
        !           122: }
        !           123:
        !           124: /*
        !           125:  * Send a packet.  The ether header is already there.
        !           126:  * Return the length sent (or -1 on error).
        !           127:  */
        !           128: ssize_t
        !           129: netif_put(desc, pkt, len)
        !           130:        struct iodesc *desc;
        !           131:        void *pkt;
        !           132:        size_t len;
        !           133: {
        !           134:        struct promdata *pd;
        !           135:        ssize_t rv;
        !           136:        size_t sendlen;
        !           137:
        !           138:        pd = (struct promdata *)desc->io_netif->nif_devdata;
        !           139:
        !           140: #ifdef NETIF_DEBUG
        !           141:        if (netif_debug) {
        !           142:                struct ether_header *eh;
        !           143:
        !           144:                printf("netif_put: desc=0x%x pkt=0x%x len=%d\n",
        !           145:                           desc, pkt, len);
        !           146:                eh = pkt;
        !           147:                printf("dst: %s ", ether_sprintf(eh->ether_dhost));
        !           148:                printf("src: %s ", ether_sprintf(eh->ether_shost));
        !           149:                printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
        !           150:        }
        !           151: #endif
        !           152:
        !           153:        sendlen = len;
        !           154:        if (sendlen < 60) {
        !           155:                sendlen = 60;
        !           156: #ifdef NETIF_DEBUG
        !           157:                printf("netif_put: length padded to %d\n", sendlen);
        !           158: #endif
        !           159:        }
        !           160:
        !           161:        rv = (*pd->xmit)(pd, pkt, sendlen);
        !           162:
        !           163: #ifdef NETIF_DEBUG
        !           164:        if (netif_debug)
        !           165:                printf("netif_put: xmit returned %d\n", rv);
        !           166: #endif
        !           167:
        !           168:        return rv;
        !           169: }
        !           170:
        !           171: /*
        !           172:  * Receive a packet, including the ether header.
        !           173:  * Return the total length received (or -1 on error).
        !           174:  */
        !           175: ssize_t
        !           176: netif_get(desc, pkt, maxlen, timo)
        !           177:        struct iodesc *desc;
        !           178:        void *pkt;
        !           179:        size_t maxlen;
        !           180:        time_t timo;
        !           181: {
        !           182:        struct promdata *pd;
        !           183:        int tick0, tmo_ticks;
        !           184:        ssize_t len;
        !           185:
        !           186:        pd = (struct promdata *)desc->io_netif->nif_devdata;
        !           187:
        !           188: #ifdef NETIF_DEBUG
        !           189:        if (netif_debug)
        !           190:                printf("netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n",
        !           191:                           pkt, maxlen, timo);
        !           192: #endif
        !           193:
        !           194:        tmo_ticks = timo * hz;
        !           195:        tick0 = getticks();
        !           196:
        !           197:        do {
        !           198:                len = (*pd->recv)(pd, pkt, maxlen);
        !           199:        } while ((len == 0) && ((getticks() - tick0) < tmo_ticks));
        !           200:
        !           201: #ifdef NETIF_DEBUG
        !           202:        if (netif_debug)
        !           203:                printf("netif_get: received len=%d\n", len);
        !           204: #endif
        !           205:
        !           206:        if (len < 12)
        !           207:                return -1;
        !           208:
        !           209: #ifdef NETIF_DEBUG
        !           210:        if (netif_debug) {
        !           211:                struct ether_header *eh = pkt;
        !           212:
        !           213:                printf("dst: %s ", ether_sprintf(eh->ether_dhost));
        !           214:                printf("src: %s ", ether_sprintf(eh->ether_shost));
        !           215:                printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
        !           216:        }
        !           217: #endif
        !           218:
        !           219:        return len;
        !           220: }

CVSweb