1157873Simp/****************************************************************************** 2157873Simp * 3157873Simp * Filename: emac.h 4157873Simp * 5157873Simp * Definition of routine to set the MAC address. 6157873Simp * 7157873Simp * Revision information: 8157873Simp * 9157873Simp * 28AUG2004 kb_admin initial creation 10157873Simp * 11157873Simp * BEGIN_KBDD_BLOCK 12157873Simp * No warranty, expressed or implied, is included with this software. It is 13157873Simp * provided "AS IS" and no warranty of any kind including statutory or aspects 14157873Simp * relating to merchantability or fitness for any purpose is provided. All 15157873Simp * intellectual property rights of others is maintained with the respective 16157873Simp * owners. This software is not copyrighted and is intended for reference 17157873Simp * only. 18157873Simp * END_BLOCK 19157873Simp * 20157873Simp * $FreeBSD: releng/11.0/sys/boot/arm/at91/libat91/emac.h 171426 2007-07-13 14:27:05Z imp $ 21157873Simp *****************************************************************************/ 22157873Simp 23157873Simp 24157873Simp#ifndef _EMAC_H_ 25157873Simp#define _EMAC_H_ 26157873Simp 27161370Simpextern void EMAC_SetMACAddress(unsigned char addr[6]); 28157873Simpextern void SetServerIPAddress(unsigned address); 29157873Simpextern void SetLocalIPAddress(unsigned address); 30157873Simpextern void EMAC_Init(void); 31157873Simpextern void TFTP_Download(unsigned address, char *filename); 32157873Simp 33157873Simp#define MAX_RX_PACKETS 8 34157873Simp#define RX_PACKET_SIZE 1536 35157873Simp#define RX_BUFFER_START 0x21000000 36157873Simp#define RX_DATA_START (RX_BUFFER_START + (8 * MAX_RX_PACKETS)) 37157873Simp 38157873Simp#define ARP_REQUEST 0x0001 39157873Simp#define ARP_REPLY 0x0002 40157873Simp#define PROTOCOL_ARP 0x0806 41157873Simp#define PROTOCOL_IP 0x0800 42157873Simp#define PROTOCOL_UDP 0x11 43157873Simp 44157873Simp#define SWAP16(x) ((((x) & 0xff) << 8) | ((x) >> 8)) 45157873Simp 46157873Simptypedef struct { 47157873Simp unsigned address; 48157873Simp unsigned size; 49157873Simp} receive_descriptor_t; 50157873Simp 51157873Simptypedef struct { 52157873Simp 53157873Simp unsigned char dest_mac[6]; 54157873Simp 55157873Simp unsigned char src_mac[6]; 56157873Simp 57157873Simp unsigned short frame_type; 58157873Simp unsigned short hard_type; 59157873Simp unsigned short prot_type; 60157873Simp unsigned char hard_size; 61157873Simp unsigned char prot_size; 62157873Simp 63157873Simp unsigned short operation; 64157873Simp 65157873Simp unsigned char sender_mac[6]; 66157873Simp unsigned char sender_ip[4]; 67157873Simp 68157873Simp unsigned char target_mac[6]; 69157873Simp unsigned char target_ip[4]; 70157873Simp 71157873Simp} __attribute__((__packed__)) arp_header_t; 72157873Simp 73157873Simptypedef struct { 74157873Simp unsigned char ip_v_hl; 75157873Simp unsigned char ip_tos; 76157873Simp unsigned short ip_len; 77157873Simp unsigned short ip_id; 78157873Simp unsigned short ip_off; 79157873Simp unsigned char ip_ttl; 80157873Simp unsigned char ip_p; 81157873Simp unsigned short ip_sum; 82157873Simp unsigned char ip_src[4]; 83157873Simp unsigned char ip_dst[4]; 84157873Simp} __attribute__((__packed__)) ip_header_t; 85157873Simp 86157873Simptypedef struct { 87157873Simp unsigned char dest_mac[6]; 88157873Simp unsigned char src_mac[6]; 89157873Simp unsigned short proto_mac; 90157873Simp unsigned short packet_length; 91157873Simp ip_header_t iphdr; 92157873Simp} __attribute__((__packed__)) transmit_header_t; 93157873Simp 94157873Simptypedef struct { 95157873Simp unsigned short src_port; 96157873Simp unsigned short dst_port; 97157873Simp unsigned short udp_len; 98157873Simp unsigned short udp_cksum; 99157873Simp} __attribute__((__packed__)) udp_header_t; 100157873Simp 101157873Simptypedef struct { 102157873Simp unsigned short opcode; 103157873Simp unsigned short block_num; 104157873Simp unsigned char data[512]; 105157873Simp} __attribute__((__packed__)) tftp_header_t; 106157873Simp 107161196Simp// Preswap bytes 108161196Simp#define TFTP_RRQ_OPCODE 0x0100 109161196Simp#define TFTP_WRQ_OPCODE 0x0200 110161196Simp#define TFTP_DATA_OPCODE 0x0300 111161196Simp#define TFTP_ACK_OPCODE 0x0400 112161196Simp#define TFTP_ERROR_OPCODE 0x0500 113157873Simp 114157873Simp/* MII registers definition */ 115157873Simp#define MII_STS_REG 0x01 116161196Simp#define MII_STS_LINK_STAT 0x04 117171426Simp#if defined(BOOT_KB920X) || defined(BOOT_CENTIPAD) 118157873Simp#define MII_STS2_REG 0x11 119161196Simp#define MII_STS2_LINK 0x400 120161196Simp#define MII_STS2_100TX 0x4000 121161196Simp#define MII_STS2_FDX 0x200 122161196Simp#else 123161196Simp#define MII_SPEC_STS_REG 0x11 124161196Simp#define MII_SSTS_100FDX 0x8000 125161196Simp#define MII_SSTS_100HDX 0x4000 126161196Simp#define MII_SSTS_10FDX 0x2000 127161196Simp#define MII_SSTS_10HDX 0x1000 128161196Simp#endif 129157873Simp 130161370Simpextern unsigned char localMACAddr[6]; 131161370Simpextern unsigned localMAClow, localMAChigh; 132163533Simpextern unsigned localMACSet; 133163533Simp#define EMAC_Init() 134161370Simp 135157873Simp#endif /* _EMAC_H_ */ 136