199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2000 Alfred Perlstein <alfred@freebsd.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2000 Paul Saab <ps@freebsd.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2000 John Baldwin <jhb@freebsd.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Allocate the PXE buffers statically instead of sticking grimy fingers into
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BTX's private data area. The scratch buffer is used to send information to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the PXE BIOS, and the data buffer is used to receive data from the PXE BIOS.
199767f8919635c4928607450d9e0abb932109ceToomas SoomeBOOTPLAYER bootplayer = {0}; /* PXE Cached information. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int pxe_init(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int pxe_strategy(void *devdata, int flag, daddr_t dblk,
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t offset, size_t size, char *buf, size_t *rsize);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void pxe_cleanup(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int pxe_netif_match(struct netif *nif, void *machdep_hint);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int pxe_netif_probe(struct netif *nif, void *machdep_hint);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void pxe_netif_init(struct iodesc *desc, void *machdep_hint);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int pxe_netif_get(struct iodesc *desc, void *pkt, size_t len,
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int pxe_netif_put(struct iodesc *desc, void *pkt, size_t len);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint nfs_getrootfh(struct iodesc*, char*, u_char*);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint nfs_getrootfh(struct iodesc*, char*, uint32_t*, u_char*);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void __bangpxeentry(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void __pxenventry(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* dif_unit dif_nsel dif_stats dif_private */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This function is called by the loader to enable PXE support if we
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are booted by PXE. The passed in pointer is a pointer to the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PXENV+ structure.
199767f8919635c4928607450d9e0abb932109ceToomas Soome pxe_p = (pxe_t *)PTOV(pxenv_p->PXEPtr.segment * 16 +
199767f8919635c4928607450d9e0abb932109ceToomas Soome * return true if pxe structures are found/initialized,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * also figures out our IP information via the pxe cached info struct
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* look for "PXENV+" */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (bcmp((void *)pxenv_p->Signature, S_SIZE("PXENV+"))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* make sure the size is something we can handle */
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("PXENV+ structure too large, ignoring\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome * do byte checksum:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * add up each byte in the structure, the total should be 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (counter = 0; counter < pxenv_p->Length; counter++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("PXENV+ structure failed checksum, ignoring\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PXENV+ passed, so use that if !PXE is not available or
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the checksum fails.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (bcmp((void *)pxe_p->Signature, S_SIZE("!PXE"))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (counter = 0; counter < pxe_p->StructLength;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\nPXE version %d.%d, real mode entry point ",
199767f8919635c4928607450d9e0abb932109ceToomas Soome pxenv_p->RMEntry.segment, pxenv_p->RMEntry.offset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome gci_p = (t_PXENV_GET_CACHED_INFO *) scratch_buffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome gci_p->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;
199767f8919635c4928607450d9e0abb932109ceToomas Soome bcopy(PTOV((gci_p->Buffer.segment << 4) + gci_p->Buffer.offset),
199767f8919635c4928607450d9e0abb932109ceToomas Soomepxe_strategy(void *devdata, int flag, daddr_t dblk, size_t offset, size_t size,
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *devname; /* Device part of file name (or NULL). */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* On first open, do netif open, mount, etc. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Find network interface. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Do a bootp/dhcp request to find out where our
199767f8919635c4928607450d9e0abb932109ceToomas Soome * NFS/TFTP server is. Even if we dont get back
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the proper information, fall back to the server
199767f8919635c4928607450d9e0abb932109ceToomas Soome * which brought us to life and a default rootpath.
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; rootpath[i] != '\0' && i < FNAME_SIZE; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (i && i != FNAME_SIZE && rootpath[i] == ':') {
199767f8919635c4928607450d9e0abb932109ceToomas Soome bcopy(&rootpath[i], &temp[0], strlen(&rootpath[i])+1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome bcopy(&temp[0], &rootpath[0], strlen(&rootpath[i])+1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("boot.netif.netmask", intoa(netmask), 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("boot.netif.gateway", inet_ntoa(gateip), 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pxe_open: server addr: %s\n", inet_ntoa(rootip));
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pxe_open: server path: %s\n", rootpath);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pxe_open: gateway ip: %s\n", inet_ntoa(gateip));
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("boot.nfsroot.server", inet_ntoa(rootip), 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome setenv("boot.netif.server", inet_ntoa(rootip), 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* On last close, do netif close, etc. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Extra close call? */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Not last close? */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* get an NFS filehandle for our root filesystem */
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(line, sizeof (line), " pxe0: %s:%s\n", inet_ntoa(rootip),
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pxe_cleanup: UNDI_SHUTDOWN failed %x\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pxe_cleanup: UNLOAD_STACK failed %x\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Reach inside the libstand NFS code and dig out an NFS handle
199767f8919635c4928607450d9e0abb932109ceToomas Soome * for the root filesystem.
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* structure truncated here */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((error = nfs_getrootfh(d, rootpath, nfs_root_node.fh)) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If NFS files were never opened, we need to do mount call
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ourselves. Use nfs_root_node.iodesc as flag indicating
199767f8919635c4928607450d9e0abb932109ceToomas Soome * previous NFS usage.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else /* !OLD_NFSV2 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* structure truncated */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((error = nfs_getrootfh(d, rootpath, &nfs_root_node.fhsize,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If NFS files were never opened, we need to do mount call
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ourselves. Use nfs_root_node.iodesc as flag indicating
199767f8919635c4928607450d9e0abb932109ceToomas Soome * previous NFS usage.
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < nfs_root_node.fhsize; i++, cp += 2)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* OLD_NFSV2 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* LOADER_NFS_SUPPORT */
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.addr = (VTOPSEG(__pxenventry) << 16) | VTOPOFF(__pxenventry);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.addr = (VTOPSEG(__bangpxeentry) << 16) | VTOPOFF(__bangpxeentry);
199767f8919635c4928607450d9e0abb932109ceToomas Soomepxe_netif_match(struct netif *nif, void *machdep_hint)
199767f8919635c4928607450d9e0abb932109ceToomas Soomepxe_netif_probe(struct netif *nif, void *machdep_hint)
199767f8919635c4928607450d9e0abb932109ceToomas Soome t_PXENV_UDP_OPEN *udpopen_p = (t_PXENV_UDP_OPEN *)scratch_buffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pxe_netif_probe: failed %x\n", udpopen_p->status);
199767f8919635c4928607450d9e0abb932109ceToomas Soome t_PXENV_UDP_CLOSE *udpclose_p = (t_PXENV_UDP_CLOSE *)scratch_buffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("pxe_end failed %x\n", udpclose_p->status);
199767f8919635c4928607450d9e0abb932109ceToomas Soomepxe_netif_init(struct iodesc *desc, void *machdep_hint)
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < 6; ++i)
199767f8919635c4928607450d9e0abb932109ceToomas Soomepxe_netif_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout)
199767f8919635c4928607450d9e0abb932109ceToomas Soomepxe_netif_put(struct iodesc *desc, void *pkt, size_t len)
199767f8919635c4928607450d9e0abb932109ceToomas Soomesendudp(struct iodesc *h, void *pkt, size_t len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome t_PXENV_UDP_WRITE *udpwrite_p = (t_PXENV_UDP_WRITE *)scratch_buffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (netmask == 0 || SAMENET(myip, h->destip, netmask))
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* XXX - I dont know why we need this. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* XXX: This happens a lot. It shouldn't. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("sendudp failed %x\n", udpwrite_p->status);
199767f8919635c4928607450d9e0abb932109ceToomas Soomereadudp(struct iodesc *h, void *pkt, size_t len, time_t timeout)
199767f8919635c4928607450d9e0abb932109ceToomas Soome t_PXENV_UDP_READ *udpread_p = (t_PXENV_UDP_READ *)scratch_buffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome udpread_p->buffer.segment = VTOPSEG(data_buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome udpread_p->buffer.offset = VTOPOFF(data_buffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* XXX - I dont know why we need this. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* XXX: This happens a lot. It shouldn't. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("readudp failed %x\n", udpread_p->status);