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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_50/] [or1ksim/] [peripheral/] [ethernet_i.h] - Blame information for rev 889

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
#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 889 ivang
#define ETH_RTX_VAPI    2
104 702 ivang
 
105
#define ETH_MAXPL   0x10000
106
 
107 889 ivang
enum { ETH_VAPI_DATA = 0,
108
       ETH_VAPI_CTRL,
109
       ETH_NUM_VAPI_IDS };
110
 
111 346 erez
struct eth_device
112
{
113
  /* Base address in memory */
114
  unsigned long baseaddr;
115
 
116
  /* Which Ethernet MAC is this? */
117
  unsigned eth_number;
118
 
119
  /* Which DMA controller is this MAC connected to */
120
  unsigned dma;
121
        unsigned tx_channel;
122
        unsigned rx_channel;
123
 
124 702 ivang
  /* Our address */
125
  unsigned char mac_address[ETH_ALEN];
126
 
127
  /* interrupt line */
128
  unsigned long mac_int;
129 346 erez
 
130 889 ivang
  /* VAPI ID */
131
  unsigned long base_vapi_id;
132
 
133 346 erez
  /* RX and TX file names and handles */
134
  const char *rxfile, *txfile;
135
        int txfd;
136
        int rxfd;
137
        off_t loopback_offset;
138
 
139 702 ivang
    int rtx_sock;
140
    int rtx_type;
141
    struct ifreq ifr;
142
    fd_set rfds, wfds;
143
 
144 346 erez
        /* Current TX state */
145
        struct
146
        {
147 695 ivang
            unsigned long state;
148
            unsigned long bd_index;
149
            unsigned long bd;
150
            unsigned long bd_addr;
151
            unsigned working, waiting_for_dma, error;
152 702 ivang
            long packet_length;
153 695 ivang
            unsigned minimum_length, maximum_length;
154
            unsigned add_crc;
155 702 ivang
            unsigned crc_dly;
156 695 ivang
            unsigned long crc_value;
157 702 ivang
            long bytes_left, bytes_sent;
158 346 erez
        } tx;
159
 
160
        /* Current RX state */
161
        struct
162
        {
163 695 ivang
            unsigned long state;
164
            unsigned long bd_index;
165
            unsigned long bd;
166 702 ivang
            unsigned long bd_addr;
167 695 ivang
            int fd;
168
            off_t *offset;
169
            unsigned working, error, waiting_for_dma;
170 702 ivang
            long packet_length, bytes_read, bytes_left;
171 346 erez
        } rx;
172
 
173
  /* Visible registers */
174
  struct
175
  {
176
    unsigned long moder;
177
    unsigned long int_source;
178
    unsigned long int_mask;
179
    unsigned long ipgt;
180
    unsigned long ipgr1;
181
    unsigned long ipgr2;
182
    unsigned long packetlen;
183
    unsigned long collconf;
184 418 erez
    unsigned long tx_bd_num;
185 346 erez
    unsigned long controlmoder;
186
    unsigned long miimoder;
187
    unsigned long miicommand;
188
    unsigned long miiaddress;
189
    unsigned long miitx_data;
190
    unsigned long miirx_data;
191
    unsigned long miistatus;
192 744 simons
    unsigned long hash0;
193
    unsigned long hash1;
194 346 erez
 
195 695 ivang
    /* Buffer descriptors */
196
    unsigned long bd_ram[ETH_BD_SPACE / 4];
197 346 erez
  } regs;
198 695 ivang
 
199 702 ivang
    unsigned char rx_buff[ETH_MAXPL];
200
    unsigned char tx_buff[ETH_MAXPL];
201
    unsigned char lo_buff[ETH_MAXPL];
202 346 erez
};
203
 
204
#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.