pxe.c revision 1.3.4.3 1 1.3.4.3 nathanw /* $NetBSD: pxe.c,v 1.3.4.3 2002/04/01 07:40:44 nathanw Exp $ */
2 1.3.4.2 nathanw
3 1.3.4.2 nathanw /*
4 1.3.4.2 nathanw * Copyright 2001 Wasabi Systems, Inc.
5 1.3.4.2 nathanw * All rights reserved.
6 1.3.4.2 nathanw *
7 1.3.4.2 nathanw * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.3.4.2 nathanw *
9 1.3.4.2 nathanw * Redistribution and use in source and binary forms, with or without
10 1.3.4.2 nathanw * modification, are permitted provided that the following conditions
11 1.3.4.2 nathanw * are met:
12 1.3.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
13 1.3.4.2 nathanw * notice, this list of conditions and the following disclaimer.
14 1.3.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
16 1.3.4.2 nathanw * documentation and/or other materials provided with the distribution.
17 1.3.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
18 1.3.4.2 nathanw * must display the following acknowledgement:
19 1.3.4.2 nathanw * This product includes software developed for the NetBSD Project by
20 1.3.4.2 nathanw * Wasabi Systems, Inc.
21 1.3.4.2 nathanw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.3.4.2 nathanw * or promote products derived from this software without specific prior
23 1.3.4.2 nathanw * written permission.
24 1.3.4.2 nathanw *
25 1.3.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.3.4.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.3.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.3.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.3.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.3.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.3.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.3.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.3.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.3.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.3.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
36 1.3.4.2 nathanw */
37 1.3.4.2 nathanw
38 1.3.4.2 nathanw /*
39 1.3.4.2 nathanw * Copyright (c) 2000 Alfred Perlstein <alfred (at) freebsd.org>
40 1.3.4.2 nathanw * All rights reserved.
41 1.3.4.2 nathanw * Copyright (c) 2000 Paul Saab <ps (at) freebsd.org>
42 1.3.4.2 nathanw * All rights reserved.
43 1.3.4.2 nathanw * Copyright (c) 2000 John Baldwin <jhb (at) freebsd.org>
44 1.3.4.2 nathanw * All rights reserved.
45 1.3.4.2 nathanw *
46 1.3.4.2 nathanw * Redistribution and use in source and binary forms, with or without
47 1.3.4.2 nathanw * modification, are permitted provided that the following conditions
48 1.3.4.2 nathanw * are met:
49 1.3.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
50 1.3.4.2 nathanw * notice, this list of conditions and the following disclaimer.
51 1.3.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
52 1.3.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
53 1.3.4.2 nathanw * documentation and/or other materials provided with the distribution.
54 1.3.4.2 nathanw *
55 1.3.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
56 1.3.4.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 1.3.4.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 1.3.4.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
59 1.3.4.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 1.3.4.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 1.3.4.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 1.3.4.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 1.3.4.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 1.3.4.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 1.3.4.2 nathanw * SUCH DAMAGE.
66 1.3.4.2 nathanw */
67 1.3.4.2 nathanw
68 1.3.4.2 nathanw /*
69 1.3.4.2 nathanw * Support for the Intel Preboot Execution Environment (PXE).
70 1.3.4.2 nathanw *
71 1.3.4.2 nathanw * PXE provides a UDP implementation as well as a UNDI network device
72 1.3.4.2 nathanw * driver. UNDI is much more complicated to use than PXE UDP, so we
73 1.3.4.2 nathanw * use PXE UDP as a cheap and easy way to get PXE support.
74 1.3.4.2 nathanw */
75 1.3.4.2 nathanw
76 1.3.4.2 nathanw #include <sys/param.h>
77 1.3.4.2 nathanw #include <sys/socket.h>
78 1.3.4.2 nathanw
79 1.3.4.2 nathanw #ifdef _STANDALONE
80 1.3.4.2 nathanw #include <lib/libkern/libkern.h>
81 1.3.4.2 nathanw #else
82 1.3.4.2 nathanw #include <string.h>
83 1.3.4.2 nathanw #endif
84 1.3.4.2 nathanw
85 1.3.4.2 nathanw #include <netinet/in.h>
86 1.3.4.2 nathanw #include <netinet/in_systm.h>
87 1.3.4.2 nathanw #include <netinet/ip.h>
88 1.3.4.2 nathanw #include <netinet/ip_var.h>
89 1.3.4.2 nathanw #include <netinet/udp.h>
90 1.3.4.2 nathanw #include <netinet/udp_var.h>
91 1.3.4.2 nathanw
92 1.3.4.2 nathanw #include <net/if_ether.h>
93 1.3.4.2 nathanw
94 1.3.4.2 nathanw #include <lib/libsa/stand.h>
95 1.3.4.2 nathanw #include <lib/libsa/net.h>
96 1.3.4.2 nathanw #include <lib/libsa/netif.h>
97 1.3.4.2 nathanw #include <lib/libsa/bootp.h>
98 1.3.4.2 nathanw
99 1.3.4.2 nathanw #include <libi386.h>
100 1.3.4.2 nathanw #include <bootinfo.h>
101 1.3.4.2 nathanw
102 1.3.4.2 nathanw #include "pxeboot.h"
103 1.3.4.2 nathanw #include "pxe.h"
104 1.3.4.2 nathanw
105 1.3.4.2 nathanw void (*pxe_call)(u_int16_t);
106 1.3.4.2 nathanw
107 1.3.4.2 nathanw void pxecall_bangpxe(u_int16_t); /* pxe_call.S */
108 1.3.4.2 nathanw void pxecall_pxenv(u_int16_t); /* pxe_call.S */
109 1.3.4.2 nathanw
110 1.3.4.2 nathanw char pxe_command_buf[256];
111 1.3.4.2 nathanw
112 1.3.4.2 nathanw BOOTPLAYER bootplayer;
113 1.3.4.2 nathanw
114 1.3.4.2 nathanw /*****************************************************************************
115 1.3.4.2 nathanw * This section is a replacement for libsa/udp.c
116 1.3.4.2 nathanw *****************************************************************************/
117 1.3.4.2 nathanw
118 1.3.4.2 nathanw /* Caller must leave room for ethernet, ip, and udp headers in front!! */
119 1.3.4.2 nathanw ssize_t
120 1.3.4.2 nathanw sendudp(struct iodesc *d, void *pkt, size_t len)
121 1.3.4.2 nathanw {
122 1.3.4.2 nathanw t_PXENV_UDP_WRITE *uw = (void *) pxe_command_buf;
123 1.3.4.2 nathanw
124 1.3.4.2 nathanw uw->status = 0;
125 1.3.4.2 nathanw
126 1.3.4.2 nathanw uw->ip = d->destip.s_addr;
127 1.3.4.2 nathanw uw->gw = gateip.s_addr;
128 1.3.4.2 nathanw uw->src_port = d->myport;
129 1.3.4.2 nathanw uw->dst_port = d->destport;
130 1.3.4.2 nathanw uw->buffer_size = len;
131 1.3.4.2 nathanw uw->buffer.segment = VTOPSEG(pkt);
132 1.3.4.2 nathanw uw->buffer.offset = VTOPOFF(pkt);
133 1.3.4.2 nathanw
134 1.3.4.2 nathanw pxe_call(PXENV_UDP_WRITE);
135 1.3.4.2 nathanw
136 1.3.4.2 nathanw if (uw->status != PXENV_STATUS_SUCCESS) {
137 1.3.4.2 nathanw /* XXX This happens a lot; it shouldn't. */
138 1.3.4.2 nathanw if (uw->status != PXENV_STATUS_FAILURE)
139 1.3.4.2 nathanw printf("sendudp: PXENV_UDP_WRITE failed: 0x%x\n",
140 1.3.4.2 nathanw uw->status);
141 1.3.4.2 nathanw return (-1);
142 1.3.4.2 nathanw }
143 1.3.4.2 nathanw
144 1.3.4.2 nathanw return (len);
145 1.3.4.2 nathanw }
146 1.3.4.2 nathanw
147 1.3.4.2 nathanw /*
148 1.3.4.2 nathanw * Receive a UDP packet and validate it for us.
149 1.3.4.2 nathanw * Caller leaves room for the headers (Ether, IP, UDP).
150 1.3.4.2 nathanw */
151 1.3.4.2 nathanw ssize_t
152 1.3.4.2 nathanw readudp(struct iodesc *d, void *pkt, size_t len, time_t tleft)
153 1.3.4.2 nathanw {
154 1.3.4.2 nathanw t_PXENV_UDP_READ *ur = (void *) pxe_command_buf;
155 1.3.4.2 nathanw struct udphdr *uh;
156 1.3.4.2 nathanw struct ip *ip;
157 1.3.4.2 nathanw
158 1.3.4.2 nathanw uh = (struct udphdr *)pkt - 1;
159 1.3.4.2 nathanw ip = (struct ip *)uh - 1;
160 1.3.4.2 nathanw
161 1.3.4.2 nathanw bzero(ur, sizeof(*ur));
162 1.3.4.2 nathanw
163 1.3.4.2 nathanw ur->dest_ip = d->myip.s_addr;
164 1.3.4.2 nathanw ur->d_port = d->myport;
165 1.3.4.2 nathanw ur->buffer_size = len;
166 1.3.4.2 nathanw ur->buffer.segment = VTOPSEG(pkt);
167 1.3.4.2 nathanw ur->buffer.offset = VTOPOFF(pkt);
168 1.3.4.2 nathanw
169 1.3.4.2 nathanw /* XXX Timeout unused. */
170 1.3.4.2 nathanw
171 1.3.4.2 nathanw pxe_call(PXENV_UDP_READ);
172 1.3.4.2 nathanw
173 1.3.4.2 nathanw if (ur->status != PXENV_STATUS_SUCCESS) {
174 1.3.4.2 nathanw /* XXX This happens a lot; it shouldn't. */
175 1.3.4.2 nathanw if (ur->status != PXENV_STATUS_FAILURE)
176 1.3.4.2 nathanw printf("readudp: PXENV_UDP_READ_failed: 0x%0x\n",
177 1.3.4.2 nathanw ur->status);
178 1.3.4.2 nathanw return (-1);
179 1.3.4.2 nathanw }
180 1.3.4.2 nathanw
181 1.3.4.2 nathanw ip->ip_src.s_addr = ur->src_ip;
182 1.3.4.2 nathanw uh->uh_sport = ur->s_port;
183 1.3.4.2 nathanw uh->uh_dport = d->myport;
184 1.3.4.2 nathanw
185 1.3.4.2 nathanw return (len);
186 1.3.4.2 nathanw }
187 1.3.4.2 nathanw
188 1.3.4.2 nathanw /*****************************************************************************
189 1.3.4.2 nathanw * PXE "netif" back-end
190 1.3.4.2 nathanw *****************************************************************************/
191 1.3.4.2 nathanw
192 1.3.4.2 nathanw int pxe_netif_match(struct netif *, void *);
193 1.3.4.2 nathanw int pxe_netif_probe(struct netif *, void *);
194 1.3.4.2 nathanw void pxe_netif_init(struct iodesc *, void *);
195 1.3.4.2 nathanw int pxe_netif_get(struct iodesc *, void *, size_t, time_t);
196 1.3.4.2 nathanw int pxe_netif_put(struct iodesc *, void *, size_t);
197 1.3.4.2 nathanw void pxe_netif_end(struct netif *);
198 1.3.4.2 nathanw
199 1.3.4.2 nathanw struct netif_stats pxe_netif_stats;
200 1.3.4.2 nathanw
201 1.3.4.2 nathanw struct netif_dif pxe0_dif = {
202 1.3.4.2 nathanw 0, /* unit */
203 1.3.4.2 nathanw 1, /* nsel */
204 1.3.4.2 nathanw &pxe_netif_stats,
205 1.3.4.2 nathanw 0,
206 1.3.4.2 nathanw 0,
207 1.3.4.2 nathanw };
208 1.3.4.2 nathanw
209 1.3.4.2 nathanw struct netif_driver pxe_netif_driver = {
210 1.3.4.2 nathanw "pxe", /* netif_bname */
211 1.3.4.2 nathanw pxe_netif_match, /* match */
212 1.3.4.2 nathanw pxe_netif_probe, /* probe */
213 1.3.4.2 nathanw pxe_netif_init, /* init */
214 1.3.4.2 nathanw pxe_netif_get, /* get */
215 1.3.4.2 nathanw pxe_netif_put, /* put */
216 1.3.4.2 nathanw pxe_netif_end, /* end */
217 1.3.4.2 nathanw &pxe0_dif, /* netif_ifs */
218 1.3.4.2 nathanw 1, /* netif_nifs */
219 1.3.4.2 nathanw };
220 1.3.4.2 nathanw
221 1.3.4.2 nathanw int
222 1.3.4.2 nathanw pxe_netif_match(struct netif *nif, void *machdep_hint)
223 1.3.4.2 nathanw {
224 1.3.4.2 nathanw
225 1.3.4.2 nathanw return (1);
226 1.3.4.2 nathanw }
227 1.3.4.2 nathanw
228 1.3.4.2 nathanw int
229 1.3.4.2 nathanw pxe_netif_probe(struct netif *nif, void *machdep_hint)
230 1.3.4.2 nathanw {
231 1.3.4.2 nathanw t_PXENV_UDP_OPEN *uo = (void *) pxe_command_buf;
232 1.3.4.2 nathanw
233 1.3.4.2 nathanw pxe_init();
234 1.3.4.2 nathanw
235 1.3.4.2 nathanw if (pxe_call == NULL)
236 1.3.4.2 nathanw return (1);
237 1.3.4.2 nathanw
238 1.3.4.2 nathanw bzero(uo, sizeof(*uo));
239 1.3.4.2 nathanw
240 1.3.4.2 nathanw uo->src_ip = bootplayer.yip;
241 1.3.4.2 nathanw
242 1.3.4.2 nathanw pxe_call(PXENV_UDP_OPEN);
243 1.3.4.2 nathanw
244 1.3.4.2 nathanw if (uo->status != PXENV_STATUS_SUCCESS) {
245 1.3.4.2 nathanw printf("pxe_netif_probe: PXENV_UDP_OPEN failed: 0x%x\n",
246 1.3.4.2 nathanw uo->status);
247 1.3.4.2 nathanw pxe_fini();
248 1.3.4.2 nathanw return (1);
249 1.3.4.2 nathanw }
250 1.3.4.2 nathanw
251 1.3.4.2 nathanw return (0);
252 1.3.4.2 nathanw }
253 1.3.4.2 nathanw
254 1.3.4.2 nathanw void
255 1.3.4.2 nathanw pxe_netif_init(struct iodesc *desc, void *machdep_hint)
256 1.3.4.2 nathanw {
257 1.3.4.2 nathanw struct netif *nif = desc->io_netif;
258 1.3.4.2 nathanw
259 1.3.4.2 nathanw bcopy(bootplayer.CAddr, desc->myea, ETHER_ADDR_LEN);
260 1.3.4.2 nathanw
261 1.3.4.2 nathanw /*
262 1.3.4.2 nathanw * Since the PXE BIOS has already done DHCP, make sure we
263 1.3.4.2 nathanw * don't reuse any of its transaction IDs.
264 1.3.4.2 nathanw */
265 1.3.4.2 nathanw desc->xid = bootplayer.ident;
266 1.3.4.2 nathanw
267 1.3.4.2 nathanw printf("%s%d: Ethernet address %s\n", nif->nif_driver->netif_bname,
268 1.3.4.2 nathanw nif->nif_unit, ether_sprintf(desc->myea));
269 1.3.4.2 nathanw }
270 1.3.4.2 nathanw
271 1.3.4.2 nathanw int
272 1.3.4.2 nathanw pxe_netif_put(struct iodesc *desc, void *pkt, size_t len)
273 1.3.4.2 nathanw {
274 1.3.4.2 nathanw
275 1.3.4.2 nathanw return (-1);
276 1.3.4.2 nathanw }
277 1.3.4.2 nathanw
278 1.3.4.2 nathanw int
279 1.3.4.2 nathanw pxe_netif_get(struct iodesc *desc, void *pkt, size_t len, time_t tleft)
280 1.3.4.2 nathanw {
281 1.3.4.2 nathanw
282 1.3.4.2 nathanw return (-1);
283 1.3.4.2 nathanw }
284 1.3.4.2 nathanw
285 1.3.4.2 nathanw void
286 1.3.4.2 nathanw pxe_netif_end(struct netif *nif)
287 1.3.4.2 nathanw {
288 1.3.4.2 nathanw t_PXENV_UDP_CLOSE *uc = (void *) pxe_command_buf;
289 1.3.4.2 nathanw
290 1.3.4.2 nathanw uc->status = 0;
291 1.3.4.2 nathanw
292 1.3.4.2 nathanw pxe_call(PXENV_UDP_CLOSE);
293 1.3.4.2 nathanw
294 1.3.4.2 nathanw if (uc->status != PXENV_STATUS_SUCCESS)
295 1.3.4.2 nathanw printf("pxe_netif_end: PXENV_UDP_CLOSE failed: 0x%x\n",
296 1.3.4.2 nathanw uc->status);
297 1.3.4.2 nathanw
298 1.3.4.2 nathanw pxe_fini();
299 1.3.4.2 nathanw }
300 1.3.4.2 nathanw
301 1.3.4.2 nathanw /*****************************************************************************
302 1.3.4.2 nathanw * PXE initialization and support routines
303 1.3.4.2 nathanw *****************************************************************************/
304 1.3.4.2 nathanw
305 1.3.4.2 nathanw u_int16_t pxe_command_buf_seg;
306 1.3.4.2 nathanw u_int16_t pxe_command_buf_off;
307 1.3.4.2 nathanw
308 1.3.4.2 nathanw extern u_int16_t bangpxe_off, bangpxe_seg;
309 1.3.4.2 nathanw extern u_int16_t pxenv_off, pxenv_seg;
310 1.3.4.2 nathanw
311 1.3.4.2 nathanw static struct btinfo_netif bi_netif;
312 1.3.4.2 nathanw
313 1.3.4.2 nathanw int
314 1.3.4.2 nathanw pxe_init(void)
315 1.3.4.2 nathanw {
316 1.3.4.2 nathanw t_PXENV_GET_CACHED_INFO *gci = (void *) pxe_command_buf;
317 1.3.4.2 nathanw t_PXENV_UNDI_GET_NIC_TYPE *gnt = (void *) pxe_command_buf;
318 1.3.4.2 nathanw pxenv_t *pxenv;
319 1.3.4.2 nathanw pxe_t *pxe;
320 1.3.4.2 nathanw char *cp;
321 1.3.4.2 nathanw int i;
322 1.3.4.2 nathanw u_int8_t cksum, *ucp;
323 1.3.4.2 nathanw
324 1.3.4.2 nathanw /*
325 1.3.4.2 nathanw * Checking for the presence of PXE is a machine-dependent
326 1.3.4.2 nathanw * operation. On the IA-32, this can be done two ways:
327 1.3.4.2 nathanw *
328 1.3.4.2 nathanw * Int 0x1a function 0x5650
329 1.3.4.2 nathanw *
330 1.3.4.2 nathanw * Scan memory for the !PXE or PXENV+ signatures
331 1.3.4.2 nathanw *
332 1.3.4.2 nathanw * We do the latter, since the Int method returns a pointer
333 1.3.4.2 nathanw * to a deprecated structure (PXENV+).
334 1.3.4.2 nathanw */
335 1.3.4.2 nathanw
336 1.3.4.2 nathanw pxenv = NULL;
337 1.3.4.2 nathanw pxe = NULL;
338 1.3.4.2 nathanw
339 1.3.4.3 nathanw for (cp = (char *)0xa0000; cp > (char *)0x10000; cp -= 2) {
340 1.3.4.2 nathanw if (pxenv == NULL) {
341 1.3.4.2 nathanw pxenv = (pxenv_t *)cp;
342 1.3.4.2 nathanw if (bcmp(pxenv->Signature, S_SIZE("PXENV+")))
343 1.3.4.2 nathanw pxenv = NULL;
344 1.3.4.2 nathanw else {
345 1.3.4.2 nathanw for (i = 0, ucp = (u_int8_t *)cp, cksum = 0;
346 1.3.4.2 nathanw i < pxenv->Length; i++)
347 1.3.4.2 nathanw cksum += ucp[i];
348 1.3.4.2 nathanw if (cksum != 0) {
349 1.3.4.2 nathanw printf("pxe_init: bad cksum (0x%x) "
350 1.3.4.2 nathanw "for PXENV+ at 0x%lx\n", cksum,
351 1.3.4.2 nathanw (u_long) cp);
352 1.3.4.2 nathanw pxenv = NULL;
353 1.3.4.2 nathanw }
354 1.3.4.2 nathanw }
355 1.3.4.2 nathanw }
356 1.3.4.2 nathanw
357 1.3.4.2 nathanw if (pxe == NULL) {
358 1.3.4.2 nathanw pxe = (pxe_t *)cp;
359 1.3.4.2 nathanw if (bcmp(pxe->Signature, S_SIZE("!PXE")))
360 1.3.4.2 nathanw pxe = NULL;
361 1.3.4.2 nathanw else {
362 1.3.4.2 nathanw for (i = 0, ucp = (u_int8_t *)cp, cksum = 0;
363 1.3.4.2 nathanw i < pxe->StructLength; i++)
364 1.3.4.2 nathanw cksum += ucp[i];
365 1.3.4.2 nathanw if (cksum != 0) {
366 1.3.4.2 nathanw printf("pxe_init: bad cksum (0x%x) "
367 1.3.4.2 nathanw "for !PXE at 0x%lx\n", cksum,
368 1.3.4.2 nathanw (u_long) cp);
369 1.3.4.2 nathanw pxe = NULL;
370 1.3.4.2 nathanw }
371 1.3.4.2 nathanw }
372 1.3.4.2 nathanw }
373 1.3.4.2 nathanw
374 1.3.4.2 nathanw if (pxe != NULL && pxenv != NULL)
375 1.3.4.2 nathanw break;
376 1.3.4.2 nathanw }
377 1.3.4.2 nathanw
378 1.3.4.2 nathanw if (pxe == NULL && pxenv == NULL) {
379 1.3.4.2 nathanw printf("pxe_init: No PXE BIOS found.\n");
380 1.3.4.2 nathanw return (1);
381 1.3.4.2 nathanw }
382 1.3.4.2 nathanw
383 1.3.4.2 nathanw if (pxenv != NULL) {
384 1.3.4.2 nathanw printf("PXE BIOS Version %d.%d\n",
385 1.3.4.2 nathanw (pxenv->Version >> 8) & 0xff, pxenv->Version & 0xff);
386 1.3.4.2 nathanw if (pxenv->Version >= 0x0201 && pxe != NULL) {
387 1.3.4.2 nathanw /* 2.1 or greater -- don't use PXENV+ */
388 1.3.4.2 nathanw pxenv = NULL;
389 1.3.4.2 nathanw }
390 1.3.4.2 nathanw }
391 1.3.4.2 nathanw
392 1.3.4.2 nathanw if (pxe != NULL) {
393 1.3.4.2 nathanw pxe_call = pxecall_bangpxe;
394 1.3.4.2 nathanw bangpxe_off = pxe->EntryPointSP.offset;
395 1.3.4.2 nathanw bangpxe_seg = pxe->EntryPointSP.segment;
396 1.3.4.2 nathanw } else {
397 1.3.4.2 nathanw pxe_call = pxecall_pxenv;
398 1.3.4.2 nathanw pxenv_off = pxenv->RMEntry.offset;
399 1.3.4.2 nathanw pxenv_seg = pxenv->RMEntry.segment;
400 1.3.4.2 nathanw }
401 1.3.4.2 nathanw
402 1.3.4.2 nathanw /*
403 1.3.4.2 nathanw * Pre-compute the segment/offset of the pxe_command_buf
404 1.3.4.2 nathanw * to make things nicer in the low-level calling glue.
405 1.3.4.2 nathanw */
406 1.3.4.2 nathanw pxe_command_buf_seg = VTOPSEG(pxe_command_buf);
407 1.3.4.2 nathanw pxe_command_buf_off = VTOPOFF(pxe_command_buf);
408 1.3.4.2 nathanw
409 1.3.4.2 nathanw /*
410 1.3.4.2 nathanw * Get the cached info from the server's Discovery reply packet.
411 1.3.4.2 nathanw */
412 1.3.4.2 nathanw bzero(gci, sizeof(*gci));
413 1.3.4.2 nathanw gci->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;
414 1.3.4.2 nathanw pxe_call(PXENV_GET_CACHED_INFO);
415 1.3.4.2 nathanw if (gci->Status != PXENV_STATUS_SUCCESS) {
416 1.3.4.2 nathanw printf("pxe_init: PXENV_GET_CACHED_INFO failed: 0x%x\n",
417 1.3.4.2 nathanw gci->Status);
418 1.3.4.2 nathanw return (1);
419 1.3.4.2 nathanw }
420 1.3.4.2 nathanw pvbcopy((void *)((gci->Buffer.segment << 4) + gci->Buffer.offset),
421 1.3.4.2 nathanw &bootplayer, gci->BufferSize);
422 1.3.4.2 nathanw
423 1.3.4.2 nathanw /*
424 1.3.4.2 nathanw * Get network interface information.
425 1.3.4.2 nathanw */
426 1.3.4.2 nathanw bzero(gnt, sizeof(*gnt));
427 1.3.4.2 nathanw pxe_call(PXENV_UNDI_GET_NIC_TYPE);
428 1.3.4.2 nathanw
429 1.3.4.2 nathanw if (gnt->Status != PXENV_STATUS_SUCCESS) {
430 1.3.4.2 nathanw printf("pxe_init: PXENV_UNDI_GET_NIC_TYPE failed: 0x%x\n",
431 1.3.4.2 nathanw gnt->Status);
432 1.3.4.2 nathanw return (0);
433 1.3.4.2 nathanw }
434 1.3.4.2 nathanw
435 1.3.4.2 nathanw switch (gnt->NicType) {
436 1.3.4.2 nathanw case PCI_NIC:
437 1.3.4.2 nathanw case CardBus_NIC:
438 1.3.4.2 nathanw strncpy(bi_netif.ifname, "pxe", sizeof(bi_netif.ifname));
439 1.3.4.2 nathanw bi_netif.bus = BI_BUS_PCI;
440 1.3.4.2 nathanw bi_netif.addr.tag = gnt->info.pci.BusDevFunc;
441 1.3.4.2 nathanw
442 1.3.4.2 nathanw BI_ADD(&bi_netif, BTINFO_NETIF, sizeof(bi_netif));
443 1.3.4.2 nathanw
444 1.3.4.2 nathanw printf("Using %s device at bus %d device %d function %d\n",
445 1.3.4.2 nathanw gnt->NicType == PCI_NIC ? "PCI" : "CardBus",
446 1.3.4.2 nathanw (gnt->info.pci.BusDevFunc >> 8) & 0xff,
447 1.3.4.2 nathanw (gnt->info.pci.BusDevFunc >> 3) & 0x1f,
448 1.3.4.2 nathanw gnt->info.pci.BusDevFunc & 0x7);
449 1.3.4.2 nathanw break;
450 1.3.4.2 nathanw
451 1.3.4.2 nathanw case PnP_NIC:
452 1.3.4.2 nathanw /* XXX Make bootinfo work with this. */
453 1.3.4.2 nathanw printf("Using PnP device at 0x%x\n", gnt->info.pnp.CardSelNum);
454 1.3.4.2 nathanw }
455 1.3.4.2 nathanw
456 1.3.4.2 nathanw return (0);
457 1.3.4.2 nathanw }
458 1.3.4.2 nathanw
459 1.3.4.2 nathanw void
460 1.3.4.2 nathanw pxe_fini(void)
461 1.3.4.2 nathanw {
462 1.3.4.2 nathanw t_PXENV_UNLOAD_STACK *unload = (void *) pxe_command_buf;
463 1.3.4.2 nathanw t_PXENV_UNDI_SHUTDOWN *shutdown = (void *) pxe_command_buf;
464 1.3.4.2 nathanw
465 1.3.4.2 nathanw if (pxe_call == NULL)
466 1.3.4.2 nathanw return;
467 1.3.4.2 nathanw
468 1.3.4.2 nathanw pxe_call(PXENV_UNDI_SHUTDOWN);
469 1.3.4.2 nathanw
470 1.3.4.2 nathanw if (shutdown->Status != PXENV_STATUS_SUCCESS)
471 1.3.4.2 nathanw printf("pxe_fini: PXENV_UNDI_SHUTDOWN failed: 0x%x\n",
472 1.3.4.2 nathanw shutdown->Status);
473 1.3.4.2 nathanw
474 1.3.4.2 nathanw pxe_call(PXENV_UNLOAD_STACK);
475 1.3.4.2 nathanw
476 1.3.4.2 nathanw if (unload->Status != PXENV_STATUS_SUCCESS)
477 1.3.4.2 nathanw printf("pxe_fini: PXENV_UNLOAD_STACK failed: 0x%x\n",
478 1.3.4.2 nathanw unload->Status);
479 1.3.4.2 nathanw }
480