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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_1_0/] [or1ksim/] [peripheral/] [ethernet_i.h] - Blame information for rev 849

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

Line No. Rev Author Line
1 346 erez
/* ethernet_i.h -- Definition of internal types and structures for Ethernet MAC
2
   Copyright (C) 2001 Erez Volk, erez@mailandnews.comopencores.org
3
 
4
   This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10
 
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
*/
20
 
21
#ifndef __OR1KSIM_PERIPHERAL_ETHERNET_I_H
22
#define __OR1KSIM_PERIPHERAL_ETHERNET_I_H
23
 
24
#include "ethernet.h"
25
#include "config.h"
26 849 markom
 
27
#ifdef HAVE_ETH_PHY
28 702 ivang
#include <netpacket/packet.h>
29 849 markom
#endif /* HAVE_ETH_PHY */
30 702 ivang
#include <sys/ioctl.h>
31
#include <sys/socket.h>
32
#include <net/if.h>
33 346 erez
 
34
/*
35
 * Ethernet protocol definitions
36
 */
37
#if HAVE_NET_ETHERNET_H
38
# include <net/ethernet.h>
39
#else /* !HAVE_NET_ETHERNET_H -*/
40
 
41
#include <sys/types.h>
42
 
43 702 ivang
#define ETH_ALEN    6
44 346 erez
 
45
struct ether_addr
46
{
47
  u_int8_t ether_addr_octet[ETH_ALEN];
48
};
49
 
50
struct ether_header
51
{
52
  u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */
53
  u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */
54
  u_int16_t ether_type;                 /* packet type ID field */
55
};
56
 
57
/* Ethernet protocol ID's */
58
#define ETHERTYPE_PUP           0x0200          /* Xerox PUP */
59
#define ETHERTYPE_IP            0x0800          /* IP */
60
#define ETHERTYPE_ARP           0x0806          /* Address resolution */
61
#define ETHERTYPE_REVARP        0x8035          /* Reverse ARP */
62
 
63
#define ETHER_ADDR_LEN  ETH_ALEN                 /* size of ethernet addr */
64
#define ETHER_TYPE_LEN  2                        /* bytes in type field */
65
#define ETHER_CRC_LEN   4                        /* bytes in CRC field */
66
#define ETHER_HDR_LEN   ETH_HLEN                 /* total octets in header */
67
#define ETHER_MIN_LEN   (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
68
#define ETHER_MAX_LEN   (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
69
 
70
/* make sure ethenet length is valid */
71
#define ETHER_IS_VALID_LEN(foo) \
72
        ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
73
 
74
/*
75
 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
76
 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
77
 * by an ETHER type (as given above) and then the (variable-length) header.
78
 */
79
#define ETHERTYPE_TRAIL         0x1000          /* Trailer packet */
80
#define ETHERTYPE_NTRAILER      16
81
 
82
#define ETHERMTU        ETH_DATA_LEN
83
#define ETHERMIN        (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
84
 
85
#endif /* HAVE_NET_ETHERNET_H */
86
 
87
 
88
/*
89
 * Implementatino of Ethernet MAC Registers and State
90
 */
91 695 ivang
#define ETH_TXSTATE_IDLE        0
92
#define ETH_TXSTATE_WAIT4BD     10
93
#define ETH_TXSTATE_READFIFO    20
94
#define ETH_TXSTATE_TRANSMIT    30
95
 
96
#define ETH_RXSTATE_IDLE        0
97
#define ETH_RXSTATE_WAIT4BD     10
98
#define ETH_RXSTATE_RECV        20
99
#define ETH_RXSTATE_WRITEFIFO   30
100 702 ivang
 
101
#define ETH_RTX_FILE    0
102
#define ETH_RTX_SOCK    1
103
 
104
#define ETH_MAXPL   0x10000
105
 
106 346 erez
struct eth_device
107
{
108
  /* Base address in memory */
109
  unsigned long baseaddr;
110
 
111
  /* Which Ethernet MAC is this? */
112
  unsigned eth_number;
113
 
114
  /* Which DMA controller is this MAC connected to */
115
  unsigned dma;
116
        unsigned tx_channel;
117
        unsigned rx_channel;
118
 
119 702 ivang
  /* Our address */
120
  unsigned char mac_address[ETH_ALEN];
121
 
122
  /* interrupt line */
123
  unsigned long mac_int;
124 346 erez
 
125
  /* RX and TX file names and handles */
126
  const char *rxfile, *txfile;
127
        int txfd;
128
        int rxfd;
129
        off_t loopback_offset;
130
 
131 702 ivang
    int rtx_sock;
132
    int rtx_type;
133
    struct ifreq ifr;
134
    fd_set rfds, wfds;
135
 
136 346 erez
        /* Current TX state */
137
        struct
138
        {
139 695 ivang
            unsigned long state;
140
            unsigned long bd_index;
141
            unsigned long bd;
142
            unsigned long bd_addr;
143
            unsigned working, waiting_for_dma, error;
144 702 ivang
            long packet_length;
145 695 ivang
            unsigned minimum_length, maximum_length;
146
            unsigned add_crc;
147 702 ivang
            unsigned crc_dly;
148 695 ivang
            unsigned long crc_value;
149 702 ivang
            long bytes_left, bytes_sent;
150 346 erez
        } tx;
151
 
152
        /* Current RX state */
153
        struct
154
        {
155 695 ivang
            unsigned long state;
156
            unsigned long bd_index;
157
            unsigned long bd;
158 702 ivang
            unsigned long bd_addr;
159 695 ivang
            int fd;
160
            off_t *offset;
161
            unsigned working, error, waiting_for_dma;
162 702 ivang
            long packet_length, bytes_read, bytes_left;
163 346 erez
        } rx;
164
 
165
  /* Visible registers */
166
  struct
167
  {
168
    unsigned long moder;
169
    unsigned long int_source;
170
    unsigned long int_mask;
171
    unsigned long ipgt;
172
    unsigned long ipgr1;
173
    unsigned long ipgr2;
174
    unsigned long packetlen;
175
    unsigned long collconf;
176 418 erez
    unsigned long tx_bd_num;
177 346 erez
    unsigned long controlmoder;
178
    unsigned long miimoder;
179
    unsigned long miicommand;
180
    unsigned long miiaddress;
181
    unsigned long miitx_data;
182
    unsigned long miirx_data;
183
    unsigned long miistatus;
184 744 simons
    unsigned long hash0;
185
    unsigned long hash1;
186 346 erez
 
187 695 ivang
    /* Buffer descriptors */
188
    unsigned long bd_ram[ETH_BD_SPACE / 4];
189 346 erez
  } regs;
190 695 ivang
 
191 702 ivang
    unsigned char rx_buff[ETH_MAXPL];
192
    unsigned char tx_buff[ETH_MAXPL];
193
    unsigned char lo_buff[ETH_MAXPL];
194 346 erez
};
195
 
196
#endif /* __OR1KSIM_PERIPHERAL_ETHERNET_I_H */

powered by: WebSVN 2.1.0

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