OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orpmon/] [include/] [net.h] - Blame information for rev 809

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 809 simons
/*
2
 *      LiMon Monitor (LiMon) - Network.
3
 *
4
 *      Copyright 1994 - 2000 Neil Russell.
5
 *      (See License)
6
 *
7
 *
8
 * History
9
 *      9/16/00   bor  adapted to TQM823L/STK8xxL board, RARP/TFTP boot added
10
 */
11
 
12
#ifndef __NET_H__
13
#define __NET_H__
14
 
15
 
16
/*
17
 *      The number of receive packet buffers, and the required packet buffer
18
 *      alignment in memory.
19
 *
20
 */
21
 
22
#define PKTBUFSRX       4
23
#define PKTALIGN        32
24
 
25
/****** from cpu_arch.h ************/
26
 
27
/* Byte swapping stuff (not needed on PPC). */
28
 
29
#define SWAP16(x)       (x)
30
#define SWAP16c(x)      (x)
31
#define SWAP32(x)       (x)
32
 
33
/****** end from cpu_arch.h **************/
34
 
35
typedef unsigned long           IPaddr_t;
36
 
37
 
38
 
39
/*
40
 * The current receive packet handler.  Called with a pointer to the
41
 * application packet, and a protocol type (PORT_BOOTPC or PORT_TFTP).
42
 * All other packets are dealt with without calling the handler.
43
 */
44
typedef void    rxhand_f(unsigned char *, unsigned, unsigned, unsigned);
45
 
46
/*
47
 *      A timeout handler.  Called after time interval has expired.
48
 */
49
typedef void    thand_f(void);
50
 
51
#ifdef CONFIG_NET_MULTI
52
 
53
#define NAMESIZE 16
54
 
55
enum eth_state_t {
56
        ETH_STATE_INIT,
57
        ETH_STATE_PASSIVE,
58
        ETH_STATE_ACTIVE
59
};
60
 
61
struct eth_device {
62
        char name[NAMESIZE];
63
        unsigned char enetaddr[6];
64
        int iobase;
65
        int state;
66
 
67
        int  (*init) (struct eth_device*, bd_t*);
68
        int  (*send) (struct eth_device*, volatile void* pachet, int length);
69
        int  (*recv) (struct eth_device*);
70
        void (*halt) (struct eth_device*);
71
 
72
        struct eth_device *next;
73
        void *priv;
74
};
75
 
76
extern int eth_initialize(bd_t *bis);           /* Initialize network subsystem */
77
extern int eth_register(struct eth_device* dev);/* Register network device      */
78
extern void eth_try_another(void);              /* Change the device            */
79
#endif
80
 
81
/**********************************************************************/
82
/*
83
 *      Protocol headers.
84
 */
85
 
86
/*
87
 *      Ethernet header
88
 */
89
typedef struct {
90
        unsigned char           et_dest[6];     /* Destination node             */
91
        unsigned char           et_src[6];      /* Source node                  */
92
        unsigned short          et_protlen;     /* Protocol or length           */
93
        unsigned char           et_dsap;        /* 802 DSAP                     */
94
        unsigned char           et_ssap;        /* 802 SSAP                     */
95
        unsigned char           et_ctl;         /* 802 control                  */
96
        unsigned char           et_snap1;       /* SNAP                         */
97
        unsigned char           et_snap2;
98
        unsigned char           et_snap3;
99
        unsigned short          et_prot;        /* 802 protocol                 */
100
} Ethernet_t;
101
 
102
#define ETHER_HDR_SIZE  14              /* Ethernet header size         */
103
#define E802_HDR_SIZE   22              /* 802 ethernet header size     */
104
#define PROT_IP         0x0800          /* IP protocol                  */
105
#define PROT_ARP        0x0806          /* IP ARP protocol              */
106
#define PROT_RARP       0x8035          /* IP ARP protocol              */
107
 
108
#define IPPROTO_ICMP     1      /* Internet Control Message Protocol    */
109
#define IPPROTO_UDP     17      /* User Datagram Protocol               */
110
 
111
/*
112
 *      Internet Protocol (IP) header.
113
 */
114
typedef struct {
115
        unsigned char           ip_hl_v;        /* header length and version    */
116
        unsigned char           ip_tos;         /* type of service              */
117
        unsigned short          ip_len;         /* total length                 */
118
        unsigned short          ip_id;          /* identification               */
119
        unsigned short          ip_off;         /* fragment offset field        */
120
        unsigned char           ip_ttl;         /* time to live                 */
121
        unsigned char           ip_p;           /* protocol                     */
122
        unsigned short          ip_sum;         /* checksum                     */
123
        IPaddr_t        ip_src;         /* Source IP address            */
124
        IPaddr_t        ip_dst;         /* Destination IP address       */
125
        unsigned short          udp_src;        /* UDP source port              */
126
        unsigned short          udp_dst;        /* UDP destination port         */
127
        unsigned short          udp_len;        /* Length of UDP packet         */
128
        unsigned short          udp_xsum;       /* Checksum                     */
129
} IP_t;
130
 
131
#define IP_HDR_SIZE_NO_UDP      (sizeof (IP_t) - 8)
132
#define IP_HDR_SIZE             (sizeof (IP_t))
133
 
134
 
135
/*
136
 *      Address Resolution Protocol (ARP) header.
137
 */
138
typedef struct
139
{
140
        unsigned short          ar_hrd;         /* Format of hardware address   */
141
#   define ARP_ETHER        1           /* Ethernet  hardware address   */
142
        unsigned short          ar_pro;         /* Format of protocol address   */
143
        unsigned char           ar_hln;         /* Length of hardware address   */
144
        unsigned char           ar_pln;         /* Length of protocol address   */
145
        unsigned short          ar_op;          /* Operation                    */
146
#   define ARPOP_REQUEST    1           /* Request  to resolve  address */
147
#   define ARPOP_REPLY      2           /* Response to previous request */
148
 
149
#   define RARPOP_REQUEST   3           /* Request  to resolve  address */
150
#   define RARPOP_REPLY     4           /* Response to previous request */
151
 
152
        /*
153
         * The remaining fields are variable in size, according to
154
         * the sizes above, and are defined as appropriate for
155
         * specific hardware/protocol combinations.
156
         */
157
        unsigned char           ar_data[0];
158
#if 0
159
        unsigned char           ar_sha[];       /* Sender hardware address      */
160
        unsigned char           ar_spa[];       /* Sender protocol address      */
161
        unsigned char           ar_tha[];       /* Target hardware address      */
162
        unsigned char           ar_tpa[];       /* Target protocol address      */
163
#endif /* 0 */
164
} ARP_t;
165
 
166
#define ARP_HDR_SIZE    (8+20)          /* Size assuming ethernet       */
167
 
168
/*
169
 * ICMP stuff (just enough to handle (host) redirect messages)
170
 */
171
#define ICMP_REDIRECT           5       /* Redirect (change route)      */
172
 
173
/* Codes for REDIRECT. */
174
#define ICMP_REDIR_NET          0        /* Redirect Net                 */
175
#define ICMP_REDIR_HOST         1       /* Redirect Host                */
176
 
177
typedef struct icmphdr {
178
        unsigned char           type;
179
        unsigned char           code;
180
        unsigned short          checksum;
181
        union {
182
                struct {
183
                        unsigned short  id;
184
                        unsigned short  sequence;
185
                } echo;
186
                unsigned long   gateway;
187
                struct {
188
                        unsigned short  __unused;
189
                        unsigned short  mtu;
190
                } frag;
191
        } un;
192
} ICMP_t;
193
 
194
 
195
 
196
/*
197
 * Maximum packet size; used to allocate packet storage.
198
 * TFTP packets can be 524 bytes + IP header + ethernet header.
199
 * Lets be conservative, and go for 38 * 16.  (Must also be
200
 * a multiple of 32 bytes).
201
 */
202
/*
203
 * AS.HARNOIS : Better to set PKTSIZE to maximum size because
204
 * traffic type is not always controlled
205
 * maximum packet size =  1518
206
 * maximum packet size and multiple of 32 bytes =  1536
207
 */
208
#define PKTSIZE                 1518
209
#define PKTSIZE_ALIGN           1536
210
/*#define PKTSIZE               608*/
211
 
212
/*
213
 * Maximum receive ring size; that is, the number of packets
214
 * we can buffer before overflow happens. Basically, this just
215
 * needs to be enough to prevent a packet being discarded while
216
 * we are processing the previous one.
217
 */
218
#define RINGSZ          4
219
#define RINGSZ_LOG2     2
220
 
221
/**********************************************************************/
222
/*
223
 *      Globals.
224
 */
225
 
226
/* net.c */
227
/** BOOTP EXTENTIONS **/
228
extern IPaddr_t         NetOurGatewayIP;        /* Our gateway IP addresse      */
229
extern IPaddr_t         NetOurSubnetMask;       /* Our subnet mask (0 = unknown)*/
230
extern IPaddr_t         NetOurDNSIP;     /* Our Domain Name Server (0 = unknown)*/
231
extern char             NetOurNISDomain[32];    /* Our NIS domain               */
232
extern char             NetOurHostName[32];     /* Our hostname                 */
233
extern char             NetOurRootPath[64];     /* Our root path                */
234
extern unsigned short           NetBootFileSize;        /* Our boot file size in blocks */
235
/** END OF BOOTP EXTENTIONS **/
236
extern unsigned long            NetBootFileXferSize;    /* size of bootfile in bytes    */
237
extern unsigned char            NetOurEther[6];         /* Our ethernet address         */
238
extern unsigned char            NetServerEther[6];      /* Boot server enet address     */
239
extern IPaddr_t         NetOurIP;               /* Our    IP addr (0 = unknown) */
240
extern IPaddr_t         NetServerIP;            /* Server IP addr (0 = unknown) */
241
extern volatile unsigned char * NetTxPacket;            /* THE transmit packet          */
242
extern volatile unsigned char * NetRxPackets[PKTBUFSRX];/* Receive packets              */
243
extern volatile unsigned char * NetRxPkt;               /* Current receive packet       */
244
extern int              NetRxPktLen;            /* Current rx packet length     */
245
extern unsigned         NetIPID;                /* IP ID (counting)             */
246
extern unsigned char            NetBcastAddr[6];        /* Ethernet boardcast address   */
247
 
248
extern int              NetState;               /* Network loop state           */
249
#define NETLOOP_CONTINUE        1
250
#define NETLOOP_RESTART         2
251
#define NETLOOP_SUCCESS         3
252
#define NETLOOP_FAIL            4
253
 
254
 
255
typedef enum { BOOTP, RARP, ARP, TFTP, DHCP } proto_t;
256
 
257
/* from net/net.c */
258
extern char     BootFile[128];                  /* Boot File name               */
259
 
260
/* Initialize the network adapter */
261
extern int      NetLoop(proto_t protocol);
262
 
263
/* Shutdown adapters and cleanup */
264
extern void     NetStop(void);
265
 
266
/* Load failed.  Start again. */
267
extern void     NetStartAgain(void);
268
 
269
/* Copy ethernet address */
270
extern void     NetCopyEther(volatile unsigned char *, unsigned char *);
271
 
272
/* Set ethernet header */
273
extern void     NetSetEther(volatile unsigned char *, unsigned char *, unsigned long);
274
 
275
/* Set IP header */
276
extern void     NetSetIP(volatile unsigned char *, IPaddr_t, int, int, int);
277
 
278
/* Checksum */
279
extern int      NetCksumOk(unsigned char *, int);       /* Return true if cksum OK      */
280
extern unsigned NetCksum(unsigned char *, int);         /* Calculate the checksum       */
281
 
282
/* Set callbacks */
283
extern void     NetSetHandler(rxhand_f *);      /* Set RX packet handler        */
284
extern void     NetSetTimeout(int, thand_f *);  /* Set timeout handler          */
285
 
286
/* Transmit "NetTxPacket" */
287
extern void     NetSendPacket(volatile unsigned char *, int);
288
 
289
/* Processes a received packet */
290
extern void     NetReceive(volatile unsigned char *, int);
291
 
292
/* Print an IP address on the console */
293
extern void     print_IPaddr (IPaddr_t);
294
 
295
/* Convert an IP address to a string */
296
extern void     ip_to_string (IPaddr_t x, char *s);
297
 
298
/* read an IP address from a environment variable */
299
extern IPaddr_t getenv_IPaddr (char *);
300
 
301
/* copy a filename (allow for "..." notation, limit length) */
302
extern void     copy_filename (unsigned char *dst, unsigned char *src, int size);
303
 
304
/**********************************************************************/
305
 
306
#endif /* __NET_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.