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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [peripheral/] [ethernet_i.h] - Blame information for rev 1782

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
  /* Base address in memory */
132 1350 nogj
  oraddr_t baseaddr;
133 346 erez
 
134
  /* Which DMA controller is this MAC connected to */
135
  unsigned dma;
136
        unsigned tx_channel;
137
        unsigned rx_channel;
138
 
139 702 ivang
  /* Our address */
140 1244 hpanther
  unsigned char mac_address[ETHER_ADDR_LEN];
141 702 ivang
 
142
  /* interrupt line */
143
  unsigned long mac_int;
144 346 erez
 
145 889 ivang
  /* VAPI ID */
146
  unsigned long base_vapi_id;
147
 
148 346 erez
  /* RX and TX file names and handles */
149 1372 nogj
  char *rxfile, *txfile;
150 346 erez
        int txfd;
151
        int rxfd;
152
        off_t loopback_offset;
153
 
154 1372 nogj
  /* Socket interface name */
155
  char *sockif;
156
 
157 702 ivang
    int rtx_sock;
158
    int rtx_type;
159
    struct ifreq ifr;
160
    fd_set rfds, wfds;
161
 
162 346 erez
        /* Current TX state */
163
        struct
164
        {
165 695 ivang
            unsigned long state;
166
            unsigned long bd_index;
167
            unsigned long bd;
168
            unsigned long bd_addr;
169
            unsigned working, waiting_for_dma, error;
170 702 ivang
            long packet_length;
171 695 ivang
            unsigned minimum_length, maximum_length;
172
            unsigned add_crc;
173 702 ivang
            unsigned crc_dly;
174 695 ivang
            unsigned long crc_value;
175 702 ivang
            long bytes_left, bytes_sent;
176 346 erez
        } tx;
177
 
178
        /* Current RX state */
179
        struct
180
        {
181 695 ivang
            unsigned long state;
182
            unsigned long bd_index;
183
            unsigned long bd;
184 702 ivang
            unsigned long bd_addr;
185 695 ivang
            int fd;
186
            off_t *offset;
187
            unsigned working, error, waiting_for_dma;
188 702 ivang
            long packet_length, bytes_read, bytes_left;
189 346 erez
        } rx;
190
 
191
  /* Visible registers */
192
  struct
193
  {
194
    unsigned long moder;
195
    unsigned long int_source;
196
    unsigned long int_mask;
197
    unsigned long ipgt;
198
    unsigned long ipgr1;
199
    unsigned long ipgr2;
200
    unsigned long packetlen;
201
    unsigned long collconf;
202 418 erez
    unsigned long tx_bd_num;
203 346 erez
    unsigned long controlmoder;
204
    unsigned long miimoder;
205
    unsigned long miicommand;
206
    unsigned long miiaddress;
207
    unsigned long miitx_data;
208
    unsigned long miirx_data;
209
    unsigned long miistatus;
210 744 simons
    unsigned long hash0;
211
    unsigned long hash1;
212 346 erez
 
213 695 ivang
    /* Buffer descriptors */
214
    unsigned long bd_ram[ETH_BD_SPACE / 4];
215 346 erez
  } regs;
216 695 ivang
 
217 702 ivang
    unsigned char rx_buff[ETH_MAXPL];
218
    unsigned char tx_buff[ETH_MAXPL];
219
    unsigned char lo_buff[ETH_MAXPL];
220 346 erez
};
221
 
222
#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.