Annotation of sys/arch/mvme68k/stand/netboot/dev_net.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: dev_net.c,v 1.8 2003/08/20 00:26:00 deraadt 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 "dev_net.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: static int
77: net_mountroot(struct open_file *f, char *devname)
78: {
79: int error;
80:
81: #ifdef DEBUG
82: printf("net_mountroot: %s\n", devname);
83: #endif
84:
85: /*
86: * Get info for NFS boot: our IP address, our hostname,
87: * server IP address, and our root path on the server.
88: * There are two ways to do this: The old, Sun way,
89: * and the more modern, BOOTP way. (RFC951, RFC1048)
90: */
91:
92: #ifdef SUN_BOOTPARAMS
93: /* Get boot info using RARP and Sun bootparams. */
94:
95: /* Get our IP address. (rarp.c) */
96: if (rarp_getipaddress(netdev_sock) == -1)
97: return (EIO);
98: printf("boot: client IP address: %s\n", intoa(myip.s_addr));
99:
100: /* Get our hostname, server IP address. */
101: if (bp_whoami(netdev_sock))
102: return (EIO);
103: printf("boot: client name: %s\n", hostname);
104:
105: /* Get the root pathname. */
106: if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
107: return (EIO);
108:
109: #else
110:
111: /* Get boot info using BOOTP way. (RFC951, RFC1048) */
112: bootp(netdev_sock);
113:
114: printf("Using IP address: %s\n", intoa(myip.s_addr));
115:
116: printf("myip: %s (%s)", hostname, intoa(myip));
117: if (gateip)
118: printf(", gateip: %s", intoa(gateip));
119: if (mask)
120: printf(", mask: %s", intoa(mask));
121: printf("\n");
122:
123: #endif
124:
125: printf("root addr=%s path=%s\n", intoa(rootip.s_addr), rootpath);
126:
127: /* Get the NFS file handle (mount). */
128: error = nfs_mount(netdev_sock, rootip, rootpath);
129:
130: return (error);
131: }
132:
133: /*
134: * machdep_common_ether: get ethernet address
135: */
136: void
137: machdep_common_ether(u_char *ether)
138: {
139: u_char *ea;
140:
141: if (bugargs.cputyp == CPU_147) {
142: ea = (u_char *) ETHER_ADDR_147;
143:
144: if ((*(int *) ea & 0x2fffff00) == 0x2fffff00)
145: panic("ERROR: ethernet address not set!");
146: ether[0] = 0x08;
147: ether[1] = 0x00;
148: ether[2] = 0x3e;
149: ether[3] = ea[0];
150: ether[4] = ea[1];
151: ether[5] = ea[2];
152: } else {
153: ea = (u_char *) ETHER_ADDR_16X;
154:
155: if (ea[0] + ea[1] + ea[2] + ea[3] + ea[4] + ea[5] == 0)
156: panic("ERROR: ethernet address not set!");
157: ether[0] = ea[0];
158: ether[1] = ea[1];
159: ether[2] = ea[2];
160: ether[3] = ea[3];
161: ether[4] = ea[4];
162: ether[5] = ea[5];
163: }
164: }
165:
166: /*
167: * Called by devopen after it sets f->f_dev to our devsw entry.
168: * This opens the low-level device and sets f->f_devdata.
169: */
170: int
171: net_open(struct open_file *f, char *devname)
172: {
173: int error = 0;
174:
175: /* On first open, do netif open, mount, etc. */
176: if (open_count == 0) {
177: /* Find network interface. */
178: if ((netdev_sock = netif_open(devname)) < 0)
179: return (error=ENXIO);
180: if ((error = net_mountroot(f, devname)) != 0)
181: return (error);
182: }
183: open_count++;
184: f->f_devdata = nfs_root_node;
185: return (error);
186: }
187:
188: int
189: net_close(struct open_file *f)
190: {
191: /* On last close, do netif close, etc. */
192: if (open_count > 0)
193: if (--open_count == 0)
194: netif_close(netdev_sock);
195: f->f_devdata = NULL;
196: }
197:
198: int
199: net_ioctl(struct open_file *f, u_long cmd, void *data)
200: {
201: return EIO;
202: }
203:
204: int
205: net_strategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
206: size_t *rsize)
207: {
208: return EIO;
209: }
210:
CVSweb