Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sbmips / stand / netboot / if_cfe.c
blobab320a3e3c4283dfca98257504639b93c8a58ede
1 /* $NetBSD: if_cfe.c,v 1.4 2009/03/14 15:36:13 dsl Exp $ */
3 /*
4 * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
5 * Copyright (c) 1993 Adam Glass
6 * All rights reserved.
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. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Adam Glass.
19 * 4. The name of the Author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 #include <sys/param.h>
36 #include <sys/types.h>
38 #include <netinet/in.h>
39 #include <netinet/in_systm.h>
41 #include <lib/libsa/stand.h>
42 #include <lib/libsa/net.h>
43 #include <lib/libsa/netif.h>
44 #include <lib/libkern/libkern.h>
46 #include "stand/common/common.h"
47 #include "stand/common/bbinfo.h"
48 #include "stand/common/cfe_api.h"
49 #include "stand/common/cfe_ioctl.h"
51 int cfenet_probe(struct netif *, void *);
52 int cfenet_match(struct netif *, void *);
53 void cfenet_init(struct iodesc *, void *);
54 int cfenet_get(struct iodesc *, void *, size_t, saseconds_t);
55 int cfenet_put(struct iodesc *, void *, size_t);
56 void cfenet_end(struct netif *);
58 extern struct netif_stats cfenet_stats[];
60 struct netif_dif cfenet_ifs[] = {
61 /* dif_unit dif_nsel dif_stats dif_private */
62 { 0, 1, &cfenet_stats[0], 0, },
64 #define NCFENET_IFS (sizeof(cfenet_ifs) / sizeof(cfenet_ifs[0]))
66 struct netif_stats cfenet_stats[NCFENET_IFS];
68 struct netif_driver prom_netif_driver = {
69 "cfe", /* netif_bname */
70 cfenet_match, /* netif_match */
71 cfenet_probe, /* netif_probe */
72 cfenet_init, /* netif_init */
73 cfenet_get, /* netif_get */
74 cfenet_put, /* netif_put */
75 cfenet_end, /* netif_end */
76 cfenet_ifs, /* netif_ifs */
77 NCFENET_IFS /* netif_nifs */
80 int
81 cfenet_match(struct netif *nif, void *machdep_hint)
84 return (1);
87 int
88 cfenet_probe(struct netif *nif, void *machdep_hint)
91 return 0;
94 int
95 cfenet_put(struct iodesc *desc, void *pkt, size_t len)
98 cfe_write(booted_dev_fd,pkt,len);
100 return len;
105 cfenet_get(struct iodesc *desc, void *pkt, size_t len, saseconds_t timeout)
107 satime_t t;
108 int cc;
110 t = getsecs();
111 cc = 0;
112 while (((getsecs() - t) < timeout) && !cc) {
113 cc = cfe_read(booted_dev_fd,pkt,len);
114 if (cc < 0) break;
115 break;
118 return cc;
121 void
122 cfenet_init(struct iodesc *desc, void *machdep_hint)
124 u_int8_t eaddr[6];
125 int res;
127 res = cfe_ioctl(booted_dev_fd,IOCTL_ETHER_GETHWADDR,eaddr,sizeof(eaddr),NULL,0);
129 if (res < 0) {
130 printf("boot: boot device name does not contain ethernet address.\n");
131 goto punt;
134 memcpy(desc->myea, eaddr,6);
136 printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea));
137 return;
139 punt:
140 halt();
144 void
145 cfenet_end(struct netif *nif)
148 /* nothing to do */