2 * LiMon Monitor (LiMon) - Network.
4 * Copyright 1994 - 2000 Neil Russell.
9 * 9/16/00 bor adapted to TQM823L/STK8xxL board, RARP/TFTP boot added
15 #if !defined(CONFIG_NET_MULTI) && defined(CONFIG_8xx)
17 #if defined(FEC_ENET) || defined(SCC_ENET)
18 #define CONFIG_NET_MULTI
21 #include <asm/byteorder.h> /* for nton* / ntoh* stuff */
25 * The number of receive packet buffers, and the required packet buffer
26 * alignment in memory.
33 typedef ulong IPaddr_t
;
38 * The current receive packet handler. Called with a pointer to the
39 * application packet, and a protocol type (PORT_BOOTPC or PORT_TFTP).
40 * All other packets are dealt with without calling the handler.
42 typedef void rxhand_f(uchar
*, unsigned, unsigned, unsigned);
45 * A timeout handler. Called after time interval has expired.
47 typedef void thand_f(void);
49 #ifdef CONFIG_NET_MULTI
61 unsigned char enetaddr
[6];
65 int (*init
) (struct eth_device
*, bd_t
*);
66 int (*send
) (struct eth_device
*, volatile void* pachet
, int length
);
67 int (*recv
) (struct eth_device
*);
68 void (*halt
) (struct eth_device
*);
70 struct eth_device
*next
;
74 extern int eth_initialize(bd_t
*bis
); /* Initialize network subsystem */
75 extern int eth_register(struct eth_device
* dev
);/* Register network device */
76 extern void eth_try_another(int first_restart
); /* Change the device */
77 extern struct eth_device
*eth_get_dev(void); /* get the current device MAC */
78 extern void eth_set_enetaddr(int num
, char* a
); /* Set new MAC address */
81 extern int eth_init(bd_t
*bis
); /* Initialize the device */
82 extern int eth_send(volatile void *packet
, int length
); /* Send a packet */
83 extern int eth_rx(void); /* Check for received packets */
84 extern void eth_halt(void); /* stop SCC */
87 /**********************************************************************/
96 uchar et_dest
[6]; /* Destination node */
97 uchar et_src
[6]; /* Source node */
98 ushort et_protlen
; /* Protocol or length */
99 uchar et_dsap
; /* 802 DSAP */
100 uchar et_ssap
; /* 802 SSAP */
101 uchar et_ctl
; /* 802 control */
102 uchar et_snap1
; /* SNAP */
105 ushort et_prot
; /* 802 protocol */
108 #define ETHER_HDR_SIZE 14 /* Ethernet header size */
109 #define E802_HDR_SIZE 22 /* 802 ethernet header size */
110 #define PROT_IP 0x0800 /* IP protocol */
111 #define PROT_ARP 0x0806 /* IP ARP protocol */
112 #define PROT_RARP 0x8035 /* IP ARP protocol */
114 #define IPPROTO_ICMP 1 /* Internet Control Message Protocol */
115 #define IPPROTO_UDP 17 /* User Datagram Protocol */
118 * Internet Protocol (IP) header.
121 uchar ip_hl_v
; /* header length and version */
122 uchar ip_tos
; /* type of service */
123 ushort ip_len
; /* total length */
124 ushort ip_id
; /* identification */
125 ushort ip_off
; /* fragment offset field */
126 uchar ip_ttl
; /* time to live */
127 uchar ip_p
; /* protocol */
128 ushort ip_sum
; /* checksum */
129 IPaddr_t ip_src
; /* Source IP address */
130 IPaddr_t ip_dst
; /* Destination IP address */
131 ushort udp_src
; /* UDP source port */
132 ushort udp_dst
; /* UDP destination port */
133 ushort udp_len
; /* Length of UDP packet */
134 ushort udp_xsum
; /* Checksum */
137 #define IP_HDR_SIZE_NO_UDP (sizeof (IP_t) - 8)
138 #define IP_HDR_SIZE (sizeof (IP_t))
142 * Address Resolution Protocol (ARP) header.
146 ushort ar_hrd
; /* Format of hardware address */
147 # define ARP_ETHER 1 /* Ethernet hardware address */
148 ushort ar_pro
; /* Format of protocol address */
149 uchar ar_hln
; /* Length of hardware address */
150 uchar ar_pln
; /* Length of protocol address */
151 ushort ar_op
; /* Operation */
152 # define ARPOP_REQUEST 1 /* Request to resolve address */
153 # define ARPOP_REPLY 2 /* Response to previous request */
155 # define RARPOP_REQUEST 3 /* Request to resolve address */
156 # define RARPOP_REPLY 4 /* Response to previous request */
159 * The remaining fields are variable in size, according to
160 * the sizes above, and are defined as appropriate for
161 * specific hardware/protocol combinations.
165 uchar ar_sha
[]; /* Sender hardware address */
166 uchar ar_spa
[]; /* Sender protocol address */
167 uchar ar_tha
[]; /* Target hardware address */
168 uchar ar_tpa
[]; /* Target protocol address */
172 #define ARP_HDR_SIZE (8+20) /* Size assuming ethernet */
175 * ICMP stuff (just enough to handle (host) redirect messages)
177 #define ICMP_REDIRECT 5 /* Redirect (change route) */
179 /* Codes for REDIRECT. */
180 #define ICMP_REDIR_NET 0 /* Redirect Net */
181 #define ICMP_REDIR_HOST 1 /* Redirect Host */
183 typedef struct icmphdr
{
203 * Maximum packet size; used to allocate packet storage.
204 * TFTP packets can be 524 bytes + IP header + ethernet header.
205 * Lets be conservative, and go for 38 * 16. (Must also be
206 * a multiple of 32 bytes).
209 * AS.HARNOIS : Better to set PKTSIZE to maximum size because
210 * traffic type is not always controlled
211 * maximum packet size = 1518
212 * maximum packet size and multiple of 32 bytes = 1536
215 #define PKTSIZE_ALIGN 1536
216 /*#define PKTSIZE 608*/
219 * Maximum receive ring size; that is, the number of packets
220 * we can buffer before overflow happens. Basically, this just
221 * needs to be enough to prevent a packet being discarded while
222 * we are processing the previous one.
225 #define RINGSZ_LOG2 2
227 /**********************************************************************/
233 * All variables of type IPaddr_t are stored in NETWORK byte order
238 /** BOOTP EXTENTIONS **/
239 extern IPaddr_t NetOurGatewayIP
; /* Our gateway IP addresse */
240 extern IPaddr_t NetOurSubnetMask
; /* Our subnet mask (0 = unknown)*/
241 extern IPaddr_t NetOurDNSIP
; /* Our Domain Name Server (0 = unknown)*/
242 extern char NetOurNISDomain
[32]; /* Our NIS domain */
243 extern char NetOurHostName
[32]; /* Our hostname */
244 extern char NetOurRootPath
[64]; /* Our root path */
245 extern ushort NetBootFileSize
; /* Our boot file size in blocks */
246 /** END OF BOOTP EXTENTIONS **/
247 extern ulong NetBootFileXferSize
; /* size of bootfile in bytes */
248 extern uchar NetOurEther
[6]; /* Our ethernet address */
249 extern uchar NetServerEther
[6]; /* Boot server enet address */
250 extern IPaddr_t NetOurIP
; /* Our IP addr (0 = unknown) */
251 extern IPaddr_t NetServerIP
; /* Server IP addr (0 = unknown) */
252 extern volatile uchar
* NetTxPacket
; /* THE transmit packet */
253 extern volatile uchar
* NetRxPackets
[PKTBUFSRX
];/* Receive packets */
254 extern volatile uchar
* NetRxPkt
; /* Current receive packet */
255 extern int NetRxPktLen
; /* Current rx packet length */
256 extern unsigned NetIPID
; /* IP ID (counting) */
257 extern uchar NetBcastAddr
[6]; /* Ethernet boardcast address */
259 extern int NetState
; /* Network loop state */
260 #define NETLOOP_CONTINUE 1
261 #define NETLOOP_RESTART 2
262 #define NETLOOP_SUCCESS 3
263 #define NETLOOP_FAIL 4
265 #ifdef CONFIG_NET_MULTI
266 extern int NetRestartWrap
; /* Tried all network devices */
269 typedef enum { BOOTP
, RARP
, ARP
, TFTP
, DHCP
} proto_t
;
272 extern char BootFile
[128]; /* Boot File name */
274 /* Initialize the network adapter */
275 extern int NetLoop(proto_t
);
277 /* Shutdown adapters and cleanup */
278 extern void NetStop(void);
280 /* Load failed. Start again. */
281 extern void NetStartAgain(void);
283 /* Set ethernet header */
284 extern void NetSetEther(volatile uchar
*, uchar
*, uint
);
287 extern void NetSetIP(volatile uchar
*, IPaddr_t
, int, int, int);
290 extern int NetCksumOk(uchar
*, int); /* Return true if cksum OK */
291 extern uint
NetCksum(uchar
*, int); /* Calculate the checksum */
294 extern void NetSetHandler(rxhand_f
*); /* Set RX packet handler */
295 extern void NetSetTimeout(int, thand_f
*); /* Set timeout handler */
297 /* Transmit "NetTxPacket" */
298 extern void NetSendPacket(volatile uchar
*, int);
300 /* Processes a received packet */
301 extern void NetReceive(volatile uchar
*, int);
303 /* Print an IP address on the console */
304 extern void print_IPaddr (IPaddr_t
);
307 * The following functions are a bit ugly, but necessary to deal with
308 * alignment restrictions on ARM.
310 * We're using inline functions, which had the smallest memory
311 * footprint in our tests.
313 /* return IP *in network byteorder* */
314 static inline IPaddr_t
NetReadIP(void *from
)
317 memcpy((void*)&ip
, from
, sizeof(ip
));
321 /* return ulong *in network byteorder* */
322 static inline ulong
NetReadLong(ulong
*from
)
325 memcpy((void*)&l
, (void*)from
, sizeof(l
));
329 /* write IP *in network byteorder* */
330 static inline void NetWriteIP(void *to
, IPaddr_t ip
)
332 memcpy(to
, (void*)&ip
, sizeof(ip
));
336 static inline void NetCopyIP(void *to
, void *from
)
338 memcpy(to
, from
, sizeof(IPaddr_t
));
342 static inline void NetCopyLong(ulong
*to
, ulong
*from
)
344 memcpy((void*)to
, (void*)from
, sizeof(ulong
));
347 /* Convert an IP address to a string */
348 extern void ip_to_string (IPaddr_t x
, char *s
);
350 /* read an IP address from a environment variable */
351 extern IPaddr_t
getenv_IPaddr (char *);
353 /* copy a filename (allow for "..." notation, limit length) */
354 extern void copy_filename (uchar
*dst
, uchar
*src
, int size
);
356 /**********************************************************************/
358 #endif /* __NET_H__ */