emac.h revision 256281
1234353Sdim/******************************************************************************
2224133Sdim *
3224133Sdim * Filename: emac.h
4224133Sdim *
5224133Sdim * Definition of routine to set the MAC address.
6224133Sdim *
7224133Sdim * Revision information:
8224133Sdim *
9224133Sdim * 28AUG2004	kb_admin	initial creation
10224133Sdim *
11224133Sdim * BEGIN_KBDD_BLOCK
12224133Sdim * No warranty, expressed or implied, is included with this software.  It is
13224133Sdim * provided "AS IS" and no warranty of any kind including statutory or aspects
14224133Sdim * relating to merchantability or fitness for any purpose is provided.  All
15224133Sdim * intellectual property rights of others is maintained with the respective
16224133Sdim * owners.  This software is not copyrighted and is intended for reference
17224133Sdim * only.
18224133Sdim * END_BLOCK
19224133Sdim *
20224133Sdim * $FreeBSD: stable/10/sys/boot/arm/at91/libat91/emac.h 171426 2007-07-13 14:27:05Z imp $
21224133Sdim *****************************************************************************/
22224133Sdim
23224133Sdim
24224133Sdim#ifndef _EMAC_H_
25234353Sdim#define _EMAC_H_
26234353Sdim
27224133Sdimextern void EMAC_SetMACAddress(unsigned char addr[6]);
28224133Sdimextern void SetServerIPAddress(unsigned address);
29224133Sdimextern void SetLocalIPAddress(unsigned address);
30226633Sdimextern void EMAC_Init(void);
31226633Sdimextern void TFTP_Download(unsigned address, char *filename);
32239462Sdim
33226633Sdim#define MAX_RX_PACKETS		8
34224133Sdim#define RX_PACKET_SIZE		1536
35224133Sdim#define	RX_BUFFER_START		0x21000000
36224133Sdim#define	RX_DATA_START		(RX_BUFFER_START + (8 * MAX_RX_PACKETS))
37224133Sdim
38224133Sdim#define ARP_REQUEST		0x0001
39224133Sdim#define ARP_REPLY		0x0002
40234353Sdim#define PROTOCOL_ARP		0x0806
41234353Sdim#define PROTOCOL_IP		0x0800
42224133Sdim#define PROTOCOL_UDP		0x11
43224133Sdim
44224133Sdim#define SWAP16(x)	((((x) & 0xff) << 8) | ((x) >> 8))
45224133Sdim
46224133Sdimtypedef struct {
47224133Sdim	unsigned	address;
48226633Sdim	unsigned	size;
49226633Sdim} receive_descriptor_t;
50226633Sdim
51224133Sdimtypedef struct {
52226633Sdim
53224133Sdim	unsigned char	dest_mac[6];
54224133Sdim
55224133Sdim	unsigned char	src_mac[6];
56224133Sdim
57224133Sdim	unsigned short	frame_type;
58224133Sdim	unsigned short	hard_type;
59	unsigned short	prot_type;
60	unsigned char	hard_size;
61	unsigned char	prot_size;
62
63	unsigned short	operation;
64
65	unsigned char	sender_mac[6];
66	unsigned char	sender_ip[4];
67
68	unsigned char	target_mac[6];
69	unsigned char	target_ip[4];
70
71} __attribute__((__packed__)) arp_header_t;
72
73typedef struct {
74	unsigned char	ip_v_hl;
75	unsigned char	ip_tos;
76	unsigned short	ip_len;
77	unsigned short	ip_id;
78	unsigned short	ip_off;
79	unsigned char	ip_ttl;
80	unsigned char	ip_p;
81	unsigned short	ip_sum;
82	unsigned char	ip_src[4];
83	unsigned char	ip_dst[4];
84} __attribute__((__packed__)) ip_header_t;
85
86typedef struct {
87	unsigned char	dest_mac[6];
88	unsigned char	src_mac[6];
89	unsigned short	proto_mac;
90	unsigned short	packet_length;
91	ip_header_t	iphdr;
92} __attribute__((__packed__)) transmit_header_t;
93
94typedef struct {
95	unsigned short	src_port;
96	unsigned short	dst_port;
97	unsigned short	udp_len;
98	unsigned short	udp_cksum;
99} __attribute__((__packed__)) udp_header_t;
100
101typedef struct {
102	unsigned short	opcode;
103	unsigned short	block_num;
104	unsigned char	data[512];
105} __attribute__((__packed__)) tftp_header_t;
106
107// Preswap bytes
108#define	TFTP_RRQ_OPCODE		0x0100
109#define TFTP_WRQ_OPCODE		0x0200
110#define TFTP_DATA_OPCODE	0x0300
111#define TFTP_ACK_OPCODE		0x0400
112#define TFTP_ERROR_OPCODE	0x0500
113
114/* MII registers definition */
115#define MII_STS_REG	0x01
116#define MII_STS_LINK_STAT	0x04
117#if defined(BOOT_KB920X) || defined(BOOT_CENTIPAD)
118#define MII_STS2_REG	0x11
119#define MII_STS2_LINK	0x400
120#define MII_STS2_100TX	0x4000
121#define MII_STS2_FDX	0x200
122#else
123#define MII_SPEC_STS_REG 0x11
124#define MII_SSTS_100FDX	0x8000
125#define MII_SSTS_100HDX	0x4000
126#define MII_SSTS_10FDX	0x2000
127#define MII_SSTS_10HDX	0x1000
128#endif
129
130extern unsigned char localMACAddr[6];
131extern unsigned localMAClow, localMAChigh;
132extern unsigned localMACSet;
133#define EMAC_Init()
134
135#endif /* _EMAC_H_ */
136