1
2
3
4
5
6
7
8
9
10
11
12#ifndef __NET_H__
13#define __NET_H__
14
15#if defined(CONFIG_8xx)
16#include <commproc.h>
17# if !defined(CONFIG_NET_MULTI)
18# if defined(FEC_ENET) || defined(SCC_ENET)
19# define CONFIG_NET_MULTI
20# endif
21# endif
22#endif
23
24#if defined(CONFIG_MPC5xxx)
25# if !defined(CONFIG_NET_MULTI)
26# if defined(CONFIG_MPC5xxx_FEC)
27# define CONFIG_NET_MULTI
28# endif
29# endif
30#endif
31
32#if !defined(CONFIG_NET_MULTI) && defined(CONFIG_CPM2)
33#include <config.h>
34#if defined(CONFIG_ETHER_ON_FCC)
35#if defined(CONFIG_ETHER_ON_SCC)
36#error "Ethernet not correctly defined"
37#endif
38#define CONFIG_NET_MULTI
39#if (CONFIG_ETHER_INDEX == 1)
40#define CONFIG_ETHER_ON_FCC1
41# define CONFIG_SYS_CMXFCR_MASK1 CONFIG_SYS_CMXFCR_MASK
42# define CONFIG_SYS_CMXFCR_VALUE1 CONFIG_SYS_CMXFCR_VALUE
43#elif (CONFIG_ETHER_INDEX == 2)
44#define CONFIG_ETHER_ON_FCC2
45# define CONFIG_SYS_CMXFCR_MASK2 CONFIG_SYS_CMXFCR_MASK
46# define CONFIG_SYS_CMXFCR_VALUE2 CONFIG_SYS_CMXFCR_VALUE
47#elif (CONFIG_ETHER_INDEX == 3)
48#define CONFIG_ETHER_ON_FCC3
49# define CONFIG_SYS_CMXFCR_MASK3 CONFIG_SYS_CMXFCR_MASK
50# define CONFIG_SYS_CMXFCR_VALUE3 CONFIG_SYS_CMXFCR_VALUE
51#endif
52#endif
53#endif
54
55#include <asm/byteorder.h>
56
57
58
59
60
61
62
63
64#ifdef CONFIG_SYS_RX_ETH_BUFFER
65# define PKTBUFSRX CONFIG_SYS_RX_ETH_BUFFER
66#else
67# define PKTBUFSRX 4
68#endif
69
70#define PKTALIGN 32
71
72typedef ulong IPaddr_t;
73
74
75
76
77
78
79
80
81
82
83typedef void rxhand_f(uchar *pkt, unsigned dport,
84 IPaddr_t sip, unsigned sport,
85 unsigned len);
86
87
88
89
90typedef void thand_f(void);
91
92#define NAMESIZE 16
93
94enum eth_state_t {
95 ETH_STATE_INIT,
96 ETH_STATE_PASSIVE,
97 ETH_STATE_ACTIVE
98};
99
100struct eth_device {
101 char name[NAMESIZE];
102 unsigned char enetaddr[6];
103 int iobase;
104 int state;
105
106 int (*init) (struct eth_device*, bd_t*);
107 int (*send) (struct eth_device*, volatile void* packet, int length);
108 int (*recv) (struct eth_device*);
109 void (*halt) (struct eth_device*);
110#ifdef CONFIG_MCAST_TFTP
111 int (*mcast) (struct eth_device*, u32 ip, u8 set);
112#endif
113 int (*write_hwaddr) (struct eth_device*);
114 struct eth_device *next;
115 void *priv;
116};
117
118extern int eth_initialize(bd_t *bis);
119extern int eth_register(struct eth_device* dev);
120extern void eth_try_another(int first_restart);
121#ifdef CONFIG_NET_MULTI
122extern void eth_set_current(void);
123#endif
124extern struct eth_device *eth_get_dev(void);
125extern struct eth_device *eth_get_dev_by_name(const char *devname);
126extern struct eth_device *eth_get_dev_by_index(int index);
127extern int eth_get_dev_index (void);
128extern void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
129extern int eth_getenv_enetaddr(char *name, uchar *enetaddr);
130extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr);
131
132
133
134
135
136
137
138
139
140
141extern int eth_getenv_enetaddr_by_index(const char *base_name, int index,
142 uchar *enetaddr);
143
144extern int usb_eth_initialize(bd_t *bi);
145extern int eth_init(bd_t *bis);
146extern int eth_send(volatile void *packet, int length);
147
148#ifdef CONFIG_API
149extern int eth_receive(volatile void *packet, int length);
150#endif
151extern int eth_rx(void);
152extern void eth_halt(void);
153extern char *eth_get_name(void);
154
155
156
157
158
159
160
161
162
163
164int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
165 int eth_number);
166
167#ifdef CONFIG_MCAST_TFTP
168int eth_mcast_join( IPaddr_t mcast_addr, u8 join);
169u32 ether_crc (size_t len, unsigned char const *p);
170#endif
171
172
173
174
175
176
177
178
179
180
181typedef struct {
182 uchar et_dest[6];
183 uchar et_src[6];
184 ushort et_protlen;
185 uchar et_dsap;
186 uchar et_ssap;
187 uchar et_ctl;
188 uchar et_snap1;
189 uchar et_snap2;
190 uchar et_snap3;
191 ushort et_prot;
192} Ethernet_t;
193
194#define ETHER_HDR_SIZE 14
195#define E802_HDR_SIZE 22
196
197
198
199
200typedef struct {
201 uchar vet_dest[6];
202 uchar vet_src[6];
203 ushort vet_vlan_type;
204 ushort vet_tag;
205 ushort vet_type;
206} VLAN_Ethernet_t;
207
208#define VLAN_ETHER_HDR_SIZE 18
209
210#define PROT_IP 0x0800
211#define PROT_ARP 0x0806
212#define PROT_RARP 0x8035
213#define PROT_VLAN 0x8100
214
215#define IPPROTO_ICMP 1
216#define IPPROTO_UDP 17
217
218
219
220
221typedef struct {
222 uchar ip_hl_v;
223 uchar ip_tos;
224 ushort ip_len;
225 ushort ip_id;
226 ushort ip_off;
227 uchar ip_ttl;
228 uchar ip_p;
229 ushort ip_sum;
230 IPaddr_t ip_src;
231 IPaddr_t ip_dst;
232 ushort udp_src;
233 ushort udp_dst;
234 ushort udp_len;
235 ushort udp_xsum;
236} IP_t;
237
238#define IP_OFFS 0x1fff
239#define IP_FLAGS 0xe000
240#define IP_FLAGS_RES 0x8000
241#define IP_FLAGS_DFRAG 0x4000
242#define IP_FLAGS_MFRAG 0x2000
243
244#define IP_HDR_SIZE_NO_UDP (sizeof (IP_t) - 8)
245#define IP_HDR_SIZE (sizeof (IP_t))
246
247
248
249
250
251typedef struct
252{
253 ushort ar_hrd;
254# define ARP_ETHER 1
255 ushort ar_pro;
256 uchar ar_hln;
257 uchar ar_pln;
258 ushort ar_op;
259# define ARPOP_REQUEST 1
260# define ARPOP_REPLY 2
261
262# define RARPOP_REQUEST 3
263# define RARPOP_REPLY 4
264
265
266
267
268
269
270 uchar ar_data[0];
271#if 0
272 uchar ar_sha[];
273 uchar ar_spa[];
274 uchar ar_tha[];
275 uchar ar_tpa[];
276#endif
277} ARP_t;
278
279#define ARP_HDR_SIZE (8+20)
280
281
282
283
284#define ICMP_ECHO_REPLY 0
285#define ICMP_REDIRECT 5
286#define ICMP_ECHO_REQUEST 8
287
288
289#define ICMP_REDIR_NET 0
290#define ICMP_REDIR_HOST 1
291
292typedef struct icmphdr {
293 uchar type;
294 uchar code;
295 ushort checksum;
296 union {
297 struct {
298 ushort id;
299 ushort sequence;
300 } echo;
301 ulong gateway;
302 struct {
303 ushort __unused;
304 ushort mtu;
305 } frag;
306 } un;
307} ICMP_t;
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322#define PKTSIZE 1518
323#define PKTSIZE_ALIGN 1536
324
325
326
327
328
329
330
331
332#define RINGSZ 4
333#define RINGSZ_LOG2 2
334
335
336
337
338
339
340
341
342
343
344
345
346
347extern IPaddr_t NetOurGatewayIP;
348extern IPaddr_t NetOurSubnetMask;
349extern IPaddr_t NetOurDNSIP;
350#if defined(CONFIG_BOOTP_DNS2)
351extern IPaddr_t NetOurDNS2IP;
352#endif
353extern char NetOurNISDomain[32];
354extern char NetOurHostName[32];
355extern char NetOurRootPath[64];
356extern ushort NetBootFileSize;
357
358extern ulong NetBootFileXferSize;
359extern uchar NetOurEther[6];
360extern uchar NetServerEther[6];
361extern IPaddr_t NetOurIP;
362extern IPaddr_t NetServerIP;
363extern volatile uchar * NetTxPacket;
364extern volatile uchar * NetRxPackets[PKTBUFSRX];
365extern volatile uchar * NetRxPacket;
366extern int NetRxPacketLen;
367extern unsigned NetIPID;
368extern uchar NetBcastAddr[6];
369extern uchar NetEtherNullAddr[6];
370
371#define VLAN_NONE 4095
372#define VLAN_IDMASK 0x0fff
373extern ushort NetOurVLAN;
374extern ushort NetOurNativeVLAN;
375
376extern uchar NetCDPAddr[6];
377extern ushort CDPNativeVLAN;
378extern ushort CDPApplianceVLAN;
379
380extern int NetState;
381#define NETLOOP_CONTINUE 1
382#define NETLOOP_RESTART 2
383#define NETLOOP_SUCCESS 3
384#define NETLOOP_FAIL 4
385
386#ifdef CONFIG_NET_MULTI
387extern int NetRestartWrap;
388#endif
389
390typedef enum { BOOTP, RARP, ARP, TFTP, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
391 TFTPSRV } proto_t;
392
393
394extern char BootFile[128];
395
396#if defined(CONFIG_CMD_DNS)
397extern char *NetDNSResolve;
398extern char *NetDNSenvvar;
399#endif
400
401#if defined(CONFIG_CMD_PING)
402extern IPaddr_t NetPingIP;
403#endif
404
405#if defined(CONFIG_CMD_CDP)
406
407extern ushort CDPNativeVLAN;
408extern ushort CDPApplianceVLAN;
409#endif
410
411#if defined(CONFIG_CMD_SNTP)
412extern IPaddr_t NetNtpServerIP;
413extern int NetTimeOffset;
414#endif
415
416
417extern int NetLoop(proto_t);
418
419
420extern void NetStop(void);
421
422
423extern void NetStartAgain(void);
424
425
426extern int NetEthHdrSize(void);
427
428
429extern int NetSetEther(volatile uchar *, uchar *, uint);
430
431
432extern void NetSetIP(volatile uchar *, IPaddr_t, int, int, int);
433
434
435extern int NetCksumOk(uchar *, int);
436extern uint NetCksum(uchar *, int);
437
438
439extern void NetSetHandler(rxhand_f *);
440extern void NetSetTimeout(ulong, thand_f *);
441
442
443extern void NetSendPacket(volatile uchar *, int);
444
445
446extern int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len);
447
448
449extern void NetReceive(volatile uchar *, int);
450
451
452
453
454
455
456
457
458
459static inline IPaddr_t NetReadIP(volatile void *from)
460{
461 IPaddr_t ip;
462 memcpy((void*)&ip, (void*)from, sizeof(ip));
463 return ip;
464}
465
466
467static inline ulong NetReadLong(ulong *from)
468{
469 ulong l;
470 memcpy((void*)&l, (void*)from, sizeof(l));
471 return l;
472}
473
474
475static inline void NetWriteIP(void *to, IPaddr_t ip)
476{
477 memcpy(to, (void*)&ip, sizeof(ip));
478}
479
480
481static inline void NetCopyIP(volatile void *to, void *from)
482{
483 memcpy((void*)to, from, sizeof(IPaddr_t));
484}
485
486
487static inline void NetCopyLong(ulong *to, ulong *from)
488{
489 memcpy((void*)to, (void*)from, sizeof(ulong));
490}
491
492
493
494
495
496
497
498static inline int is_zero_ether_addr(const u8 *addr)
499{
500 return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
501}
502
503
504
505
506
507
508
509
510static inline int is_multicast_ether_addr(const u8 *addr)
511{
512 return (0x01 & addr[0]);
513}
514
515
516
517
518
519
520
521static inline int is_broadcast_ether_addr(const u8 *addr)
522{
523 return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
524}
525
526
527
528
529
530
531
532
533
534
535static inline int is_valid_ether_addr(const u8 *addr)
536{
537
538
539 return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
540}
541
542
543extern void ip_to_string (IPaddr_t x, char *s);
544
545
546extern IPaddr_t string_to_ip(const char *s);
547
548
549extern void VLAN_to_string (ushort x, char *s);
550
551
552extern ushort string_to_VLAN(const char *s);
553
554
555extern ushort getenv_VLAN(char *);
556
557
558extern void copy_filename (char *dst, const char *src, int size);
559
560
561extern unsigned int random_port(void);
562
563
564
565#endif
566