Annotation of sys/arch/mvme88k/stand/netboot/dev_net.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: dev_net.c,v 1.4 2006/05/16 22:52:09 miod Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 1995 Gordon W. Ross
! 5: * All rights reserved.
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. Redistributions in binary form must reproduce the above copyright
! 13: * notice, this list of conditions and the following disclaimer in the
! 14: * documentation and/or other materials provided with the distribution.
! 15: * 3. The name of the author may not be used to endorse or promote products
! 16: * derived from this software without specific prior written permission.
! 17: * 4. All advertising materials mentioning features or use of this software
! 18: * must display the following acknowledgement:
! 19: * This product includes software developed by Gordon W. Ross
! 20: *
! 21: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 22: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 23: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 24: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 25: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 26: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 27: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 28: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 29: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! 30: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 31: */
! 32:
! 33: /*
! 34: * This module implements a "raw device" interface suitable for
! 35: * use by the stand-alone I/O library NFS code. This interface
! 36: * does not support any "block" access, and exists only for the
! 37: * purpose of initializing the network interface, getting boot
! 38: * parameters, and performing the NFS mount.
! 39: *
! 40: * At open time, this does:
! 41: *
! 42: * find interface - netif_open()
! 43: * RARP for IP address - rarp_getipaddress()
! 44: * RPC/bootparams - callrpc(d, RPC_BOOTPARAMS, ...)
! 45: * RPC/mountd - nfs_mount(sock, ip, path)
! 46: *
! 47: * the root file handle from mountd is saved in a global
! 48: * for use by the NFS open code (NFS/lookup).
! 49: */
! 50:
! 51: #include <sys/param.h>
! 52: #include <sys/socket.h>
! 53: #include <net/if.h>
! 54: #include <netinet/in.h>
! 55: #include <netinet/if_ether.h>
! 56: #include <netinet/in_systm.h>
! 57:
! 58: #include <machine/prom.h>
! 59:
! 60: #include "stand.h"
! 61: #include "libsa.h"
! 62: #include "net.h"
! 63: #include "netif.h"
! 64: #include "config.h"
! 65: #include "bootparam.h"
! 66: #include "nfs.h"
! 67:
! 68: extern int nfs_root_node[]; /* XXX - get from nfs_mount() */
! 69:
! 70: struct in_addr myip, rootip, gateip, mask;
! 71: char rootpath[FNAME_SIZE];
! 72:
! 73: int netdev_sock = -1;
! 74: static int open_count;
! 75:
! 76: int net_mountroot(struct open_file *, char *);
! 77:
! 78: /*
! 79: * Called by devopen after it sets f->f_dev to our devsw entry.
! 80: * This opens the low-level device and sets f->f_devdata.
! 81: */
! 82: int
! 83: net_open(f, devname)
! 84: struct open_file *f;
! 85: char *devname; /* Device part of file name (or NULL). */
! 86: {
! 87: int error = 0;
! 88:
! 89: /* On first open, do netif open, mount, etc. */
! 90: if (open_count == 0) {
! 91: /* Find network interface. */
! 92: if ((netdev_sock = netif_open(devname)) < 0)
! 93: return (error=ENXIO);
! 94: if ((error = net_mountroot(f, devname)) != 0)
! 95: return (error);
! 96: }
! 97: open_count++;
! 98: f->f_devdata = nfs_root_node;
! 99: return (error);
! 100: }
! 101:
! 102: int
! 103: net_close(f)
! 104: struct open_file *f;
! 105: {
! 106: /* On last close, do netif close, etc. */
! 107: if (open_count > 0)
! 108: if (--open_count == 0)
! 109: netif_close(netdev_sock);
! 110: f->f_devdata = NULL;
! 111: return (0);
! 112: }
! 113:
! 114: int
! 115: net_ioctl()
! 116: {
! 117: return EIO;
! 118: }
! 119:
! 120: int
! 121: net_strategy()
! 122: {
! 123: return EIO;
! 124: }
! 125:
! 126: int
! 127: net_mountroot(f, devname)
! 128: struct open_file *f;
! 129: char *devname; /* Device part of file name (or NULL). */
! 130: {
! 131: int error;
! 132:
! 133: #ifdef DEBUG
! 134: printf("net_mountroot: %s\n", devname);
! 135: #endif
! 136:
! 137: /*
! 138: * Get info for NFS boot: our IP address, our hostname,
! 139: * server IP address, and our root path on the server.
! 140: * There are two ways to do this: The old, Sun way,
! 141: * and the more modern, BOOTP way. (RFC951, RFC1048)
! 142: */
! 143:
! 144: #ifdef SUN_BOOTPARAMS
! 145: /* Get boot info using RARP and Sun bootparams. */
! 146:
! 147: /* Get our IP address. (rarp.c) */
! 148: if (rarp_getipaddress(netdev_sock) == -1)
! 149: return (EIO);
! 150: printf("boot: client IP address: %s\n", intoa(myip.s_addr));
! 151:
! 152: /* Get our hostname, server IP address. */
! 153: if (bp_whoami(netdev_sock))
! 154: return (EIO);
! 155: printf("boot: client name: %s\n", hostname);
! 156:
! 157: /* Get the root pathname. */
! 158: if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
! 159: return (EIO);
! 160:
! 161: #else
! 162:
! 163: /* Get boot info using BOOTP way. (RFC951, RFC1048) */
! 164: bootp(netdev_sock);
! 165:
! 166: printf("Using IP address: %s\n", intoa(myip.s_addr));
! 167:
! 168: printf("myip: %s (%s)", hostname, intoa(myip));
! 169: if (gateip)
! 170: printf(", gateip: %s", intoa(gateip));
! 171: if (mask)
! 172: printf(", mask: %s", intoa(mask));
! 173: printf("\n");
! 174:
! 175: #endif
! 176:
! 177: printf("root addr=%s path=%s\n", intoa(rootip.s_addr), rootpath);
! 178:
! 179: /* Get the NFS file handle (mount). */
! 180: error = nfs_mount(netdev_sock, rootip, rootpath);
! 181:
! 182: return (error);
! 183: }
! 184:
! 185: /*
! 186: * machdep_common_ether: get ethernet address
! 187: */
! 188: void
! 189: machdep_common_ether(ether)
! 190: u_char *ether;
! 191: {
! 192: u_char *ea;
! 193:
! 194: ea = (u_char *) ETHER_ADDR_16X;
! 195:
! 196: if (ea[0] + ea[1] + ea[2] + ea[3] + ea[4] + ea[5] == 0)
! 197: panic("ERROR: ethernet address not set!");
! 198: ether[0] = ea[0];
! 199: ether[1] = ea[1];
! 200: ether[2] = ea[2];
! 201: ether[3] = ea[3];
! 202: ether[4] = ea[4];
! 203: ether[5] = ea[5];
! 204: }
CVSweb