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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [peripheral/] [ethernet_i.h] - Blame information for rev 1461

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 867 markom
#if 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 1323 phoenix
#elif HAVE_SYS_ETHERNET_H
40
# include <sys/ethernet.h>
41
#ifndef ETHER_ADDR_LEN
42
#define ETHER_ADDR_LEN ETHERADDRL
43
#endif
44
#ifndef ETHER_HDR_LEN
45
#define ETHER_HDR_LEN sizeof(struct ether_header)
46
#endif
47
#else /* !HAVE_NET_ETHERNET_H && !HAVE_SYS_ETHERNET_H -*/
48 346 erez
 
49
#include <sys/types.h>
50
 
51 1146 phoenix
#ifdef __CYGWIN__
52
/* define some missing cygwin defines.
53
 *
54
 * NOTE! there is no nonblocking socket option implemented in cygwin.dll
55
 *       so defining MSG_DONTWAIT is just (temporary) workaround !!!
56
 */
57
#define MSG_DONTWAIT  0x40
58
#define ETH_HLEN      14
59
#endif /* __CYGWIN__ */
60
 
61 702 ivang
#define ETH_ALEN    6
62 346 erez
 
63
struct ether_addr
64
{
65
  u_int8_t ether_addr_octet[ETH_ALEN];
66
};
67
 
68
struct ether_header
69
{
70
  u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */
71
  u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */
72
  u_int16_t ether_type;                 /* packet type ID field */
73
};
74
 
75
/* Ethernet protocol ID's */
76
#define ETHERTYPE_PUP           0x0200          /* Xerox PUP */
77
#define ETHERTYPE_IP            0x0800          /* IP */
78
#define ETHERTYPE_ARP           0x0806          /* Address resolution */
79
#define ETHERTYPE_REVARP        0x8035          /* Reverse ARP */
80
 
81
#define ETHER_ADDR_LEN  ETH_ALEN                 /* size of ethernet addr */
82
#define ETHER_TYPE_LEN  2                        /* bytes in type field */
83
#define ETHER_CRC_LEN   4                        /* bytes in CRC field */
84
#define ETHER_HDR_LEN   ETH_HLEN                 /* total octets in header */
85
#define ETHER_MIN_LEN   (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
86
#define ETHER_MAX_LEN   (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
87
 
88
/* make sure ethenet length is valid */
89
#define ETHER_IS_VALID_LEN(foo) \
90
        ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
91
 
92
/*
93
 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
94
 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
95
 * by an ETHER type (as given above) and then the (variable-length) header.
96
 */
97
#define ETHERTYPE_TRAIL         0x1000          /* Trailer packet */
98
#define ETHERTYPE_NTRAILER      16
99
 
100
#define ETHERMTU        ETH_DATA_LEN
101
#define ETHERMIN        (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
102
 
103
#endif /* HAVE_NET_ETHERNET_H */
104
 
105
 
106
/*
107
 * Implementatino of Ethernet MAC Registers and State
108
 */
109 695 ivang
#define ETH_TXSTATE_IDLE        0
110
#define ETH_TXSTATE_WAIT4BD     10
111
#define ETH_TXSTATE_READFIFO    20
112
#define ETH_TXSTATE_TRANSMIT    30
113
 
114
#define ETH_RXSTATE_IDLE        0
115
#define ETH_RXSTATE_WAIT4BD     10
116
#define ETH_RXSTATE_RECV        20
117
#define ETH_RXSTATE_WRITEFIFO   30
118 702 ivang
 
119
#define ETH_RTX_FILE    0
120
#define ETH_RTX_SOCK    1
121 889 ivang
#define ETH_RTX_VAPI    2
122 702 ivang
 
123
#define ETH_MAXPL   0x10000
124
 
125 889 ivang
enum { ETH_VAPI_DATA = 0,
126
       ETH_VAPI_CTRL,
127
       ETH_NUM_VAPI_IDS };
128
 
129 346 erez
struct eth_device
130
{
131 1461 nogj
  /* Is peripheral enabled */
132
  int enabled;
133
 
134 346 erez
  /* Base address in memory */
135 1350 nogj
  oraddr_t baseaddr;
136 346 erez
 
137
  /* Which DMA controller is this MAC connected to */
138
  unsigned dma;
139
        unsigned tx_channel;
140
        unsigned rx_channel;
141
 
142 702 ivang
  /* Our address */
143 1244 hpanther
  unsigned char mac_address[ETHER_ADDR_LEN];
144 702 ivang
 
145
  /* interrupt line */
146
  unsigned long mac_int;
147 346 erez
 
148 889 ivang
  /* VAPI ID */
149
  unsigned long base_vapi_id;
150
 
151 346 erez
  /* RX and TX file names and handles */
152 1372 nogj
  char *rxfile, *txfile;
153 346 erez
        int txfd;
154
        int rxfd;
155
        off_t loopback_offset;
156
 
157 1372 nogj
  /* Socket interface name */
158
  char *sockif;
159
 
160 702 ivang
    int rtx_sock;
161
    int rtx_type;
162
    struct ifreq ifr;
163
    fd_set rfds, wfds;
164
 
165 346 erez
        /* Current TX state */
166
        struct
167
        {
168 695 ivang
            unsigned long state;
169
            unsigned long bd_index;
170
            unsigned long bd;
171
            unsigned long bd_addr;
172
            unsigned working, waiting_for_dma, error;
173 702 ivang
            long packet_length;
174 695 ivang
            unsigned minimum_length, maximum_length;
175
            unsigned add_crc;
176 702 ivang
            unsigned crc_dly;
177 695 ivang
            unsigned long crc_value;
178 702 ivang
            long bytes_left, bytes_sent;
179 346 erez
        } tx;
180
 
181
        /* Current RX state */
182
        struct
183
        {
184 695 ivang
            unsigned long state;
185
            unsigned long bd_index;
186
            unsigned long bd;
187 702 ivang
            unsigned long bd_addr;
188 695 ivang
            int fd;
189
            off_t *offset;
190
            unsigned working, error, waiting_for_dma;
191 702 ivang
            long packet_length, bytes_read, bytes_left;
192 346 erez
        } rx;
193
 
194
  /* Visible registers */
195
  struct
196
  {
197
    unsigned long moder;
198
    unsigned long int_source;
199
    unsigned long int_mask;
200
    unsigned long ipgt;
201
    unsigned long ipgr1;
202
    unsigned long ipgr2;
203
    unsigned long packetlen;
204
    unsigned long collconf;
205 418 erez
    unsigned long tx_bd_num;
206 346 erez
    unsigned long controlmoder;
207
    unsigned long miimoder;
208
    unsigned long miicommand;
209
    unsigned long miiaddress;
210
    unsigned long miitx_data;
211
    unsigned long miirx_data;
212
    unsigned long miistatus;
213 744 simons
    unsigned long hash0;
214
    unsigned long hash1;
215 346 erez
 
216 695 ivang
    /* Buffer descriptors */
217
    unsigned long bd_ram[ETH_BD_SPACE / 4];
218 346 erez
  } regs;
219 695 ivang
 
220 702 ivang
    unsigned char rx_buff[ETH_MAXPL];
221
    unsigned char tx_buff[ETH_MAXPL];
222
    unsigned char lo_buff[ETH_MAXPL];
223 346 erez
};
224
 
225
#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.