Fully synchronize sys/boot from FreeBSD-5.x, but add / to the module path
[dragonfly.git] / sys / boot / pc32 / libi386 / pxe.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000 Alfred Perlstein <alfred@freebsd.org>
3 * All rights reserved.
4 * Copyright (c) 2000 Paul Saab <ps@freebsd.org>
5 * All rights reserved.
6 * Copyright (c) 2000 John Baldwin <jhb@freebsd.org>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD: src/sys/boot/i386/libi386/pxe.h,v 1.6 2002/09/23 18:54:26 alfred Exp $
31 * $DragonFly: src/sys/boot/pc32/libi386/pxe.h,v 1.3 2003/11/10 06:08:36 dillon Exp $
32 */
33
34/*
35 * The typedefs and structures declared in this file
36 * clearly violate style(9), the reason for this is to conform to the
37 * typedefs/structure-names used in the Intel literature to avoid confusion.
38 *
39 * It's for your own good. :)
40 */
41
42/* It seems that intel didn't think about ABI,
43 * either that or 16bit ABI != 32bit ABI (which seems reasonable)
44 * I have to thank Intel for the hair loss I incurred trying to figure
45 * out why PXE was mis-reading structures I was passing it (at least
46 * from my point of view)
47 *
48 * Solution: use gcc's '__packed' to correctly align
49 * structures passed into PXE
50 * Question: does this really work for PXE's expected ABI?
51 */
52#define PACKED __attribute__((__packed__))
53
54#define S_SIZE(s) s, sizeof(s) - 1
55
56#define IP_STR "%d.%d.%d.%d"
57#define IP_ARGS(ip) \
58 (int)(ip >> 24) & 0xff, (int)(ip >> 16) & 0xff, \
59 (int)(ip >> 8) & 0xff, (int)ip & 0xff
60
61#define MAC_STR "%02x:%02x:%02x:%02x:%02x:%02x"
62#define MAC_ARGS(mac) \
63 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
64
65#define PXENFSROOTPATH "/pxeroot"
66
67typedef struct {
68 uint16_t offset;
69 uint16_t segment;
70} SEGOFF16_t;
71
72typedef struct {
73 uint16_t Seg_Addr;
74 uint32_t Phy_Addr;
75 uint16_t Seg_Size;
76} SEGDESC_t;
77
78typedef uint16_t SEGSEL_t;
79typedef uint16_t PXENV_STATUS_t;
80typedef uint32_t IP4_t;
81typedef uint32_t ADDR32_t;
82typedef uint16_t UDP_PORT_t;
83
84#define MAC_ADDR_LEN 16
85typedef uint8_t MAC_ADDR[MAC_ADDR_LEN];
86
87/* PXENV+ */
88typedef struct {
89 uint8_t Signature[6]; /* 'PXENV+' */
90 uint16_t Version; /* MSB = major, LSB = minor */
91 uint8_t Length; /* structure length */
92 uint8_t Checksum; /* checksum pad */
93 SEGOFF16_t RMEntry; /* SEG:OFF to PXE entry point */
94 /* don't use PMOffset and PMSelector (from the 2.1 PXE manual) */
95 uint32_t PMOffset; /* Protected mode entry */
96 SEGSEL_t PMSelector; /* Protected mode selector */
97 SEGSEL_t StackSeg; /* Stack segment address */
98 uint16_t StackSize; /* Stack segment size (bytes) */
99 SEGSEL_t BC_CodeSeg; /* BC Code segment address */
100 uint16_t BC_CodeSize; /* BC Code segment size (bytes) */
101 SEGSEL_t BC_DataSeg; /* BC Data segment address */
102 uint16_t BC_DataSize; /* BC Data segment size (bytes) */
103 SEGSEL_t UNDIDataSeg; /* UNDI Data segment address */
104 uint16_t UNDIDataSize; /* UNDI Data segment size (bytes) */
105 SEGSEL_t UNDICodeSeg; /* UNDI Code segment address */
106 uint16_t UNDICodeSize; /* UNDI Code segment size (bytes) */
107 SEGOFF16_t PXEPtr; /* SEG:OFF to !PXE struct,
108 only present when Version > 2.1 */
109} PACKED pxenv_t;
110
111/* !PXE */
112typedef struct {
113 uint8_t Signature[4];
114 uint8_t StructLength;
115 uint8_t StructCksum;
116 uint8_t StructRev;
117 uint8_t reserved_1;
118 SEGOFF16_t UNDIROMID;
119 SEGOFF16_t BaseROMID;
120 SEGOFF16_t EntryPointSP;
121 SEGOFF16_t EntryPointESP;
122 SEGOFF16_t StatusCallout;
123 uint8_t reserved_2;
124 uint8_t SegDescCn;
125 SEGSEL_t FirstSelector;
126 SEGDESC_t Stack;
127 SEGDESC_t UNDIData;
128 SEGDESC_t UNDICode;
129 SEGDESC_t UNDICodeWrite;
130 SEGDESC_t BC_Data;
131 SEGDESC_t BC_Code;
132 SEGDESC_t BC_CodeWrite;
133} PACKED pxe_t;
134
135#define PXENV_START_UNDI 0x0000
136typedef struct {
137 PXENV_STATUS_t Status;
138 uint16_t ax;
139 uint16_t bx;
140 uint16_t dx;
141 uint16_t di;
142 uint16_t es;
143} PACKED t_PXENV_START_UNDI;
144
145#define PXENV_UNDI_STARTUP 0x0001
146typedef struct {
147 PXENV_STATUS_t Status;
148} PACKED t_PXENV_UNDI_STARTUP;
149
150#define PXENV_UNDI_CLEANUP 0x0002
151typedef struct {
152 PXENV_STATUS_t Status;
153} PACKED t_PXENV_UNDI_CLEANUP;
154
155#define PXENV_UNDI_INITIALIZE 0x0003
156typedef struct {
157 PXENV_STATUS_t Status;
158 ADDR32_t ProtocolIni; /* Phys addr of a copy of the driver module */
159 uint8_t reserved[8];
160} PACKED t_PXENV_UNDI_INITALIZE;
161
162
163#define MAXNUM_MCADDR 8
164typedef struct {
165 PXENV_STATUS_t Status;
166 uint16_t MCastAddrCount;
167 MAC_ADDR McastAddr[MAXNUM_MCADDR];
168} PACKED t_PXENV_UNDI_MCAST_ADDRESS;
169
170#define PXENV_UNDI_RESET_ADAPTER 0x0004
171typedef struct {
172 PXENV_STATUS_t Status;
173 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
174} PACKED t_PXENV_UNDI_RESET;
175
176#define PXENV_UNDI_SHUTDOWN 0x0005
177typedef struct {
178 PXENV_STATUS_t Status;
179} PACKED t_PXENV_UNDI_SHUTDOWN;
180
181#define PXENV_UNDI_OPEN 0x0006
182typedef struct {
183 PXENV_STATUS_t Status;
184 uint16_t OpenFlag;
185 uint16_t PktFilter;
186# define FLTR_DIRECTED 0x0001
187# define FLTR_BRDCST 0x0002
188# define FLTR_PRMSCS 0x0003
189# define FLTR_SRC_RTG 0x0004
190
191 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
192} PACKED t_PXENV_UNDI_OPEN;
193
194#define PXENV_UNDI_CLOSE 0x0007
195typedef struct {
196 PXENV_STATUS_t Status;
197} PACKED t_PXENV_UNDI_CLOSE;
198
199#define PXENV_UNDI_TRANSMIT 0x0008
200typedef struct {
201 PXENV_STATUS_t Status;
202 uint8_t Protocol;
203# define P_UNKNOWN 0
204# define P_IP 1
205# define P_ARP 2
206# define P_RARP 3
207
208 uint8_t XmitFlag;
209# define XMT_DESTADDR 0x0000
210# define XMT_BROADCAST 0x0001
211
212 SEGOFF16_t DestAddr;
213 SEGOFF16_t TBD;
214 uint32_t Reserved[2];
215} PACKED t_PXENV_UNDI_TRANSMIT;
216
217#define MAX_DATA_BLKS 8
218typedef struct {
219 uint16_t ImmedLength;
220 SEGOFF16_t Xmit;
221 uint16_t DataBlkCount;
222 struct DataBlk {
223 uint8_t TDPtrType;
224 uint8_t TDRsvdByte;
225 uint16_t TDDataLen;
226 SEGOFF16_t TDDataPtr;
227 } DataBlock[MAX_DATA_BLKS];
228} PACKED t_PXENV_UNDI_TBD;
229
230#define PXENV_UNDI_SET_MCAST_ADDRESS 0x0009
231typedef struct {
232 PXENV_STATUS_t Status;
233 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
234} PACKED t_PXENV_UNDI_SET_MCAST_ADDR;
235
236#define PXENV_UNDI_SET_STATION_ADDRESS 0x000A
237typedef struct {
238 PXENV_STATUS_t Status;
239 MAC_ADDR StationAddress; /* Temp MAC addres to use */
240} PACKED t_PXENV_UNDI_SET_STATION_ADDR;
241
242#define PXENV_UNDI_SET_PACKET_FILTER 0x000B
243typedef struct {
244 PXENV_STATUS_t Status;
245 uint8_t filter; /* see UNDI_OPEN (0x0006) */
246} PACKED t_PXENV_UNDI_SET_PACKET_FILTER;
247
248#define PXENV_UNDI_GET_INFORMATION 0x000C
249typedef struct {
250 PXENV_STATUS_t Status;
251 uint16_t BaseIo; /* Adapter base I/O address */
252 uint16_t IntNumber; /* Adapter IRQ number */
253 uint16_t MaxTranUnit; /* Adapter maximum transmit unit */
254 uint16_t HwType; /* Type of protocol at the hardware addr */
255# define ETHER_TYPE 1
256# define EXP_ETHER_TYPE 2
257# define IEEE_TYPE 6
258# define ARCNET_TYPE 7
259
260 uint16_t HwAddrLen; /* Length of hardware address */
261 MAC_ADDR CurrentNodeAddress; /* Current hardware address */
262 MAC_ADDR PermNodeAddress; /* Permanent hardware address */
263 SEGSEL_t ROMAddress; /* Real mode ROM segment address */
264 uint16_t RxBufCt; /* Receive queue length */
265 uint16_t TxBufCt; /* Transmit queue length */
266} PACKED t_PXENV_UNDI_GET_INFORMATION;
267
268#define PXENV_UNDI_GET_STATISTICS 0x000D
269typedef struct {
270 PXENV_STATUS_t Status;
271 uint32_t XmitGoodFrames; /* Number of successful transmissions */
272 uint32_t RcvGoodFrames; /* Number of good frames received */
273 uint32_t RcvCRCErrors; /* Number of frames with CRC errors */
274 uint32_t RcvResourceErrors; /* Number of frames dropped */
275} PACKED t_PXENV_UNDI_GET_STATISTICS;
276
277#define PXENV_UNDI_CLEAR_STATISTICS 0x000E
278typedef struct {
279 PXENV_STATUS_t Status;
280} PACKED t_PXENV_UNDI_CLEAR_STATISTICS;
281
282#define PXENV_UNDI_INITIATE_DIAGS 0x000F
283typedef struct {
284 PXENV_STATUS_t Status;
285} PACKED t_PXENV_UNDI_INITIATE_DIAGS;
286
287#define PXENV_UNDI_FORCE_INTERRUPT 0x0010
288typedef struct {
289 PXENV_STATUS_t Status;
290} PACKED t_PXENV_UNDI_FORCE_INTERRUPT;
291
292#define PXENV_UNDI_GET_MCAST_ADDRESS 0x0011
293typedef struct {
294 PXENV_STATUS_t Status;
295 IP4_t InetAddr; /* IP mulicast address */
296 MAC_ADDR MediaAddr; /* MAC multicast address */
297} PACKED t_PXENV_UNDI_GET_MCAST_ADDR;
298
299#define PXENV_UNDI_GET_NIC_TYPE 0x0012
300typedef struct {
301 PXENV_STATUS_t Status;
302 uint8_t NicType; /* Type of NIC */
303# define PCI_NIC 2
304# define PnP_NIC 3
305# define CardBus_NIC 4
306
307 union {
308 struct {
309 uint16_t Vendor_ID;
310 uint16_t Dev_ID;
311 uint8_t Base_Class;
312 uint8_t Sub_Class;
313 uint8_t Prog_Intf;
314 uint8_t Rev;
315 uint16_t BusDevFunc;
316 uint16_t SubVendor_ID;
317 uint16_t SubDevice_ID;
318 } pci, cardbus;
319 struct {
320 uint32_t EISA_Dev_ID;
321 uint8_t Base_Class;
322 uint8_t Sub_Class;
323 uint8_t Prog_Intf;
324 uint16_t CardSelNum;
325 } pnp;
326 } info;
327} PACKED t_PXENV_UNDI_GET_NIC_TYPE;
328
329#define PXENV_UNDI_GET_IFACE_INFO 0x0013
330typedef struct {
331 PXENV_STATUS_t Status;
332 uint8_t IfaceType[16]; /* Name of MAC type in ASCII. */
333 uint32_t LinkSpeed; /* Defined in NDIS 2.0 spec */
334 uint32_t ServiceFlags; /* Defined in NDIS 2.0 spec */
335 uint32_t Reserved[4]; /* must be 0 */
336} PACKED t_PXENV_UNDI_GET_NDIS_INFO;
337
338#define PXENV_UNDI_ISR 0x0014
339typedef struct {
340 PXENV_STATUS_t Status;
341 uint16_t FuncFlag; /* PXENV_UNDI_ISR_OUT_xxx */
342 uint16_t BufferLength; /* Length of Frame */
343 uint16_t FrameLength; /* Total length of reciever frame */
344 uint16_t FrameHeaderLength; /* Length of the media header in Frame */
345 SEGOFF16_t Frame; /* receive buffer */
346 uint8_t ProtType; /* Protocol type */
347 uint8_t PktType; /* Packet Type */
348# define PXENV_UNDI_ISR_IN_START 1
349# define PXENV_UNDI_ISR_IN_PROCESS 2
350# define PXENV_UNDI_ISR_IN_GET_NEXT 3
351
352 /* one of these will be returned for PXENV_UNDI_ISR_IN_START */
353# define PXENV_UNDI_ISR_OUT_OURS 0
354# define PXENV_UNDI_ISR_OUT_NOT_OUTS 1
355
356 /*
357 * one of these will bre returnd for PXEND_UNDI_ISR_IN_PROCESS
358 * and PXENV_UNDI_ISR_IN_GET_NEXT
359 */
360# define PXENV_UNDI_ISR_OUT_DONE 0
361# define PXENV_UNDI_ISR_OUT_TRANSMIT 2
362# define PXENV_UNDI_ISR_OUT_RECIEVE 3
363# define PXENV_UNDI_ISR_OUT_BUSY 4
364} PACKED t_PXENV_UNDI_ISR;
365
366#define PXENV_STOP_UNDI 0x0015
367typedef struct {
368 PXENV_STATUS_t Status;
369} PACKED t_PXENV_STOP_UNDI;
370
371#define PXENV_TFTP_OPEN 0x0020
372typedef struct {
373 PXENV_STATUS_t Status;
374 IP4_t ServerIPAddress;
375 IP4_t GatewayIPAddress;
376 uint8_t FileName[128];
377 UDP_PORT_t TFTPPort;
378 uint16_t PacketSize;
379} PACKED t_PXENV_TFTP_OPEN;
380
381#define PXENV_TFTP_CLOSE 0x0021
382typedef struct {
383 PXENV_STATUS_t Status;
384} PACKED t_PXENV_TFTP_CLOSE;
385
386#define PXENV_TFTP_READ 0x0022
387typedef struct {
388 PXENV_STATUS_t Status;
389 uint16_t PacketNumber;
390 uint16_t BufferSize;
391 SEGOFF16_t Buffer;
392} PACKED t_PXENV_TFTP_READ;
393
394#define PXENV_TFTP_READ_FILE 0x0023
395typedef struct {
396 PXENV_STATUS_t Status;
397 uint8_t FileName[128];
398 uint32_t BufferSize;
399 ADDR32_t Buffer;
400 IP4_t ServerIPAddress;
401 IP4_t GatewayIPAdress;
402 IP4_t McastIPAdress;
403 UDP_PORT_t TFTPClntPort;
404 UDP_PORT_t TFTPSrvPort;
405 uint16_t TFTPOpenTimeOut;
406 uint16_t TFTPReopenDelay;
407} PACKED t_PXENV_TFTP_READ_FILE;
408
409#define PXENV_TFTP_GET_FSIZE 0x0025
410typedef struct {
411 PXENV_STATUS_t Status;
412 IP4_t ServerIPAddress;
413 IP4_t GatewayIPAdress;
414 uint8_t FileName[128];
415 uint32_t FileSize;
416} PACKED t_PXENV_TFTP_GET_FSIZE;
417
418#define PXENV_UDP_OPEN 0x0030
419typedef struct {
420 PXENV_STATUS_t status;
421 IP4_t src_ip; /* IP address of this station */
422} PACKED t_PXENV_UDP_OPEN;
423
424#define PXENV_UDP_CLOSE 0x0031
425typedef struct {
426 PXENV_STATUS_t status;
427} PACKED t_PXENV_UDP_CLOSE;
428
429#define PXENV_UDP_READ 0x0032
430typedef struct {
431 PXENV_STATUS_t status;
432 IP4_t src_ip; /* IP of sender */
433 IP4_t dest_ip; /* Only accept packets sent to this IP */
434 UDP_PORT_t s_port; /* UDP source port of sender */
435 UDP_PORT_t d_port; /* Only accept packets sent to this port */
436 uint16_t buffer_size; /* Size of the packet buffer */
437 SEGOFF16_t buffer; /* SEG:OFF to the packet buffer */
438} PACKED t_PXENV_UDP_READ;
439
440#define PXENV_UDP_WRITE 0x0033
441typedef struct {
442 PXENV_STATUS_t status;
443 IP4_t ip; /* dest ip addr */
444 IP4_t gw; /* ip gateway */
445 UDP_PORT_t src_port; /* source udp port */
446 UDP_PORT_t dst_port; /* destination udp port */
447 uint16_t buffer_size; /* Size of the packet buffer */
448 SEGOFF16_t buffer; /* SEG:OFF to the packet buffer */
449} PACKED t_PXENV_UDP_WRITE;
450
451#define PXENV_UNLOAD_STACK 0x0070
452typedef struct {
453 PXENV_STATUS_t Status;
454 uint8_t reserved[10];
455} PACKED t_PXENV_UNLOAD_STACK;
456
457
458#define PXENV_GET_CACHED_INFO 0x0071
459typedef struct {
460 PXENV_STATUS_t Status;
461 uint16_t PacketType; /* type (defined right here) */
462# define PXENV_PACKET_TYPE_DHCP_DISCOVER 1
463# define PXENV_PACKET_TYPE_DHCP_ACK 2
464# define PXENV_PACKET_TYPE_BINL_REPLY 3
465 uint16_t BufferSize; /* max to copy, leave at 0 for pointer */
466 SEGOFF16_t Buffer; /* copy to, leave at 0 for pointer */
467 uint16_t BufferLimit; /* max size of buffer in BC dataseg ? */
468} PACKED t_PXENV_GET_CACHED_INFO;
469
470
471/* structure filled in by PXENV_GET_CACHED_INFO
472 * (how we determine which IP we downloaded the initial bootstrap from)
473 * words can't describe...
474 */
475typedef struct {
476 uint8_t opcode;
477# define BOOTP_REQ 1
478# define BOOTP_REP 2
479 uint8_t Hardware; /* hardware type */
480 uint8_t Hardlen; /* hardware addr len */
481 uint8_t Gatehops; /* zero it */
482 uint32_t ident; /* random number chosen by client */
483 uint16_t seconds; /* seconds since did initial bootstrap */
484 uint16_t Flags; /* seconds since did initial bootstrap */
485# define BOOTP_BCAST 0x8000 /* ? */
486 IP4_t cip; /* Client IP */
487 IP4_t yip; /* Your IP */
488 IP4_t sip; /* IP to use for next boot stage */
489 IP4_t gip; /* Relay IP ? */
490 MAC_ADDR CAddr; /* Client hardware address */
491 uint8_t Sname[64]; /* Server's hostname (Optional) */
492 uint8_t bootfile[128]; /* boot filename */
493 union {
494# if 1
495# define BOOTP_DHCPVEND 1024 /* DHCP extended vendor field size */
496# else
497# define BOOTP_DHCPVEND 312 /* DHCP standard vendor field size */
498# endif
499 uint8_t d[BOOTP_DHCPVEND]; /* raw array of vendor/dhcp options */
500 struct {
501 uint8_t magic[4]; /* DHCP magic cookie */
502# ifndef VM_RFC1048
503# define VM_RFC1048 0x63825363L /* ? */
504# endif
505 uint32_t flags; /* bootp flags/opcodes */
506 uint8_t pad[56]; /* I don't think intel knows what a
507 union does... */
508 } v;
509 } vendor;
510} PACKED BOOTPLAYER;
511
512#define PXENV_RESTART_TFTP 0x0073
513#define t_PXENV_RESTART_TFTP t_PXENV_TFTP_READ_FILE
514
515#define PXENV_START_BASE 0x0075
516typedef struct {
517 PXENV_STATUS_t Status;
518} PACKED t_PXENV_START_BASE;
519
520#define PXENV_STOP_BASE 0x0076
521typedef struct {
522 PXENV_STATUS_t Status;
523} PACKED t_PXENV_STOP_BASE;