Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / newsmips / stand / boot / net.c
blobc433f7ca647744d8caaf612aec2d7a0f09ee7f6d
1 /* $NetBSD: net.c,v 1.4 2005/12/11 12:18:25 christos Exp $ */
3 /*
4 * Copyright (c) 1995 Gordon W. Ross
5 * All rights reserved.
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * This module implements a "raw device" interface suitable for
30 * use by the stand-alone I/O library NFS code. This interface
31 * does not support any "block" access, and exists only for the
32 * purpose of initializing the network interface, getting boot
33 * parameters, and performing the NFS mount.
35 * At open time, this does:
37 * find interface - netif_open()
38 * RARP for IP address - rarp_getipaddress()
39 * RPC/bootparams - callrpc(d, RPC_BOOTPARAMS, ...)
40 * RPC/mountd - nfs_mount(sock, ip, path)
42 * the root file handle from mountd is saved in a global
43 * for use by the NFS open code (NFS/lookup).
46 #include <sys/param.h>
47 #include <sys/socket.h>
48 #include <net/if.h>
49 #include <netinet/in.h>
50 #include <netinet/in_systm.h>
52 #include <lib/libsa/stand.h>
53 #include <lib/libsa/net.h>
54 #include <lib/libsa/bootparam.h>
55 #include <lib/libsa/nfs.h>
57 #include <lib/libkern/libkern.h>
59 #include <promdev.h>
61 #include "netif_news.h"
63 char rootpath[FNAME_SIZE];
65 int netdev_sock = -1;
66 static int open_count;
69 * Called by devopen after it sets f->f_dev to our devsw entry.
70 * This opens the low-level device and sets f->f_devdata.
72 int
73 net_open(struct romdev *pd)
75 int error = 0;
77 /* On first open, do netif open, mount, etc. */
78 if (open_count == 0) {
79 /* Find network interface. */
80 if ((netdev_sock = netif_news_open(pd)) < 0) {
81 error = errno;
82 goto bad;
84 if ((error = net_mountroot()) != 0)
85 goto bad;
87 open_count++;
88 bad:
89 return error;
92 int
93 net_close(struct romdev *pd)
95 /* On last close, do netif close, etc. */
96 if (open_count <= 0)
97 return 0;
99 if (--open_count == 0)
100 netif_news_close(netdev_sock);
102 return 0;
106 net_mountroot(void)
109 #ifdef DEBUG
110 printf("net_mountroot\n");
111 #endif
114 * Get info for NFS boot: our IP address, our hostname,
115 * server IP address, and our root path on the server.
116 * There are two ways to do this: The old, Sun way,
117 * and the more modern, BOOTP way. (RFC951, RFC1048)
120 #ifdef SUN_BOOTPARAMS
121 /* Get boot info using RARP and Sun bootparams. */
123 /* Get our IP address. (rarp.c) */
124 if (rarp_getipaddress(netdev_sock) == -1)
125 return (errno);
127 printf("boot: client IP address: %s\n", inet_ntoa(myip));
129 /* Get our hostname, server IP address. */
130 if (bp_whoami(netdev_sock))
131 return (errno);
133 printf("boot: client name: %s\n", hostname);
135 /* Get the root pathname. */
136 if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
137 return (errno);
139 #else
141 /* Get boot info using BOOTP way. (RFC951, RFC1048) */
142 bootp(netdev_sock);
144 printf("Using IP address: %s\n", inet_ntoa(myip));
146 printf("myip: %s (%s)", hostname, inet_ntoa(myip));
147 if (gateip)
148 printf(", gateip: %s", inet_ntoa(gateip));
149 if (netmask)
150 printf(", netmask: %s", intoa(netmask));
151 printf("\n");
153 #endif
155 printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
157 /* Get the NFS file handle (mount). */
158 if (nfs_mount(netdev_sock, rootip, rootpath) != 0)
159 return (errno);
161 return 0;