1 /****************************************************************************** 2 * 3 * Filename: emac.h 4 * 5 * Definition of routine to set the MAC address. 6 * 7 * Revision information: 8 * 9 * 28AUG2004 kb_admin initial creation 10 * 11 * BEGIN_KBDD_BLOCK 12 * No warranty, expressed or implied, is included with this software. It is 13 * provided "AS IS" and no warranty of any kind including statutory or aspects 14 * relating to merchantability or fitness for any purpose is provided. All 15 * intellectual property rights of others is maintained with the respective 16 * owners. This software is not copyrighted and is intended for reference 17 * only. 18 * END_BLOCK 19 * 20 * $FreeBSD$ 21 *****************************************************************************/ 22 23 24 #ifndef _EMAC_H_ 25 #define _EMAC_H_ 26 27 extern void EMAC_SetMACAddress(unsigned char addr[6]); 28 extern void SetServerIPAddress(unsigned address); 29 extern void SetLocalIPAddress(unsigned address); 30 extern void EMAC_Init(void); 31 extern void TFTP_Download(unsigned address, char *filename); 32 33 #define MAX_RX_PACKETS 8 34 #define RX_PACKET_SIZE 1536 35 #define RX_BUFFER_START 0x21000000 36 #define RX_DATA_START (RX_BUFFER_START + (8 * MAX_RX_PACKETS)) 37 38 #define ARP_REQUEST 0x0001 39 #define ARP_REPLY 0x0002 40 #define PROTOCOL_ARP 0x0806 41 #define PROTOCOL_IP 0x0800 42 #define PROTOCOL_UDP 0x11 43 44 #define SWAP16(x) ((((x) & 0xff) << 8) | ((x) >> 8)) 45 46 typedef struct { 47 unsigned address; 48 unsigned size; 49 } receive_descriptor_t; 50 51 typedef struct { 52 53 unsigned char dest_mac[6]; 54 55 unsigned char src_mac[6]; 56 57 unsigned short frame_type; 58 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 73 typedef 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 86 typedef 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 94 typedef 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 101 typedef 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 130 extern unsigned char localMACAddr[6]; 131 extern unsigned localMAClow, localMAChigh; 132 extern unsigned localMACSet; 133 #define EMAC_Init() 134 135 #endif /* _EMAC_H_ */ 136