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 695

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