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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc3/] [or1ksim/] [peripheral/] [ethernet_i.h] - Blame information for rev 744

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 702 ivang
#include <netpacket/packet.h>
27
#include <sys/ioctl.h>
28
#include <sys/socket.h>
29
#include <net/if.h>
30 346 erez
 
31
/*
32
 * Ethernet protocol definitions
33
 */
34
#if HAVE_NET_ETHERNET_H
35
# include <net/ethernet.h>
36
#else /* !HAVE_NET_ETHERNET_H -*/
37
 
38
#include <sys/types.h>
39
 
40 702 ivang
#define ETH_ALEN    6
41 346 erez
 
42
struct ether_addr
43
{
44
  u_int8_t ether_addr_octet[ETH_ALEN];
45
};
46
 
47
struct ether_header
48
{
49
  u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */
50
  u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */
51
  u_int16_t ether_type;                 /* packet type ID field */
52
};
53
 
54
/* Ethernet protocol ID's */
55
#define ETHERTYPE_PUP           0x0200          /* Xerox PUP */
56
#define ETHERTYPE_IP            0x0800          /* IP */
57
#define ETHERTYPE_ARP           0x0806          /* Address resolution */
58
#define ETHERTYPE_REVARP        0x8035          /* Reverse ARP */
59
 
60
#define ETHER_ADDR_LEN  ETH_ALEN                 /* size of ethernet addr */
61
#define ETHER_TYPE_LEN  2                        /* bytes in type field */
62
#define ETHER_CRC_LEN   4                        /* bytes in CRC field */
63
#define ETHER_HDR_LEN   ETH_HLEN                 /* total octets in header */
64
#define ETHER_MIN_LEN   (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
65
#define ETHER_MAX_LEN   (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
66
 
67
/* make sure ethenet length is valid */
68
#define ETHER_IS_VALID_LEN(foo) \
69
        ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
70
 
71
/*
72
 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
73
 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
74
 * by an ETHER type (as given above) and then the (variable-length) header.
75
 */
76
#define ETHERTYPE_TRAIL         0x1000          /* Trailer packet */
77
#define ETHERTYPE_NTRAILER      16
78
 
79
#define ETHERMTU        ETH_DATA_LEN
80
#define ETHERMIN        (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
81
 
82
#endif /* HAVE_NET_ETHERNET_H */
83
 
84
 
85
/*
86
 * Implementatino of Ethernet MAC Registers and State
87
 */
88 695 ivang
#define ETH_TXSTATE_IDLE        0
89
#define ETH_TXSTATE_WAIT4BD     10
90
#define ETH_TXSTATE_READFIFO    20
91
#define ETH_TXSTATE_TRANSMIT    30
92
 
93
#define ETH_RXSTATE_IDLE        0
94
#define ETH_RXSTATE_WAIT4BD     10
95
#define ETH_RXSTATE_RECV        20
96
#define ETH_RXSTATE_WRITEFIFO   30
97 702 ivang
 
98
#define ETH_RTX_FILE    0
99
#define ETH_RTX_SOCK    1
100
 
101
#define ETH_MAXPL   0x10000
102
 
103 346 erez
struct eth_device
104
{
105
  /* Base address in memory */
106
  unsigned long baseaddr;
107
 
108
  /* Which Ethernet MAC is this? */
109
  unsigned eth_number;
110
 
111
  /* Which DMA controller is this MAC connected to */
112
  unsigned dma;
113
        unsigned tx_channel;
114
        unsigned rx_channel;
115
 
116 702 ivang
  /* Our address */
117
  unsigned char mac_address[ETH_ALEN];
118
 
119
  /* interrupt line */
120
  unsigned long mac_int;
121 346 erez
 
122
  /* RX and TX file names and handles */
123
  const char *rxfile, *txfile;
124
        int txfd;
125
        int rxfd;
126
        off_t loopback_offset;
127
 
128 702 ivang
    int rtx_sock;
129
    int rtx_type;
130
    struct ifreq ifr;
131
    fd_set rfds, wfds;
132
 
133 346 erez
        /* Current TX state */
134
        struct
135
        {
136 695 ivang
            unsigned long state;
137
            unsigned long bd_index;
138
            unsigned long bd;
139
            unsigned long bd_addr;
140
            unsigned working, waiting_for_dma, error;
141 702 ivang
            long packet_length;
142 695 ivang
            unsigned minimum_length, maximum_length;
143
            unsigned add_crc;
144 702 ivang
            unsigned crc_dly;
145 695 ivang
            unsigned long crc_value;
146 702 ivang
            long bytes_left, bytes_sent;
147 346 erez
        } tx;
148
 
149
        /* Current RX state */
150
        struct
151
        {
152 695 ivang
            unsigned long state;
153
            unsigned long bd_index;
154
            unsigned long bd;
155 702 ivang
            unsigned long bd_addr;
156 695 ivang
            int fd;
157
            off_t *offset;
158
            unsigned working, error, waiting_for_dma;
159 702 ivang
            long packet_length, bytes_read, bytes_left;
160 346 erez
        } rx;
161
 
162
  /* Visible registers */
163
  struct
164
  {
165
    unsigned long moder;
166
    unsigned long int_source;
167
    unsigned long int_mask;
168
    unsigned long ipgt;
169
    unsigned long ipgr1;
170
    unsigned long ipgr2;
171
    unsigned long packetlen;
172
    unsigned long collconf;
173 418 erez
    unsigned long tx_bd_num;
174 346 erez
    unsigned long controlmoder;
175
    unsigned long miimoder;
176
    unsigned long miicommand;
177
    unsigned long miiaddress;
178
    unsigned long miitx_data;
179
    unsigned long miirx_data;
180
    unsigned long miistatus;
181 744 simons
    unsigned long hash0;
182
    unsigned long hash1;
183 346 erez
 
184 695 ivang
    /* Buffer descriptors */
185
    unsigned long bd_ram[ETH_BD_SPACE / 4];
186 346 erez
  } regs;
187 695 ivang
 
188 702 ivang
    unsigned char rx_buff[ETH_MAXPL];
189
    unsigned char tx_buff[ETH_MAXPL];
190
    unsigned char lo_buff[ETH_MAXPL];
191 346 erez
};
192
 
193
 
194
 
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.