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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc3/] [or1ksim/] [peripheral/] [ethernet_i.h] - Diff between revs 1648 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 1648 Rev 1765
/* ethernet_i.h -- Definition of internal types and structures for Ethernet MAC
/* ethernet_i.h -- Definition of internal types and structures for Ethernet MAC
   Copyright (C) 2001 Erez Volk, erez@mailandnews.comopencores.org
   Copyright (C) 2001 Erez Volk, erez@mailandnews.comopencores.org
 
 
   This file is part of OpenRISC 1000 Architectural Simulator.
   This file is part of OpenRISC 1000 Architectural Simulator.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
*/
 
 
#ifndef __OR1KSIM_PERIPHERAL_ETHERNET_I_H
#ifndef __OR1KSIM_PERIPHERAL_ETHERNET_I_H
#define __OR1KSIM_PERIPHERAL_ETHERNET_I_H
#define __OR1KSIM_PERIPHERAL_ETHERNET_I_H
 
 
#include "ethernet.h"
#include "ethernet.h"
#include "config.h"
#include "config.h"
 
 
#if HAVE_ETH_PHY
#if HAVE_ETH_PHY
#include <netpacket/packet.h>
#include <netpacket/packet.h>
#endif /* HAVE_ETH_PHY */
#endif /* HAVE_ETH_PHY */
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if.h>
 
 
/*
/*
 * Ethernet protocol definitions
 * Ethernet protocol definitions
 */
 */
#if HAVE_NET_ETHERNET_H
#if HAVE_NET_ETHERNET_H
# include <net/ethernet.h>
# include <net/ethernet.h>
#elif HAVE_SYS_ETHERNET_H
#elif HAVE_SYS_ETHERNET_H
# include <sys/ethernet.h>
# include <sys/ethernet.h>
#ifndef ETHER_ADDR_LEN
#ifndef ETHER_ADDR_LEN
#define ETHER_ADDR_LEN ETHERADDRL
#define ETHER_ADDR_LEN ETHERADDRL
#endif
#endif
#ifndef ETHER_HDR_LEN
#ifndef ETHER_HDR_LEN
#define ETHER_HDR_LEN sizeof(struct ether_header)
#define ETHER_HDR_LEN sizeof(struct ether_header)
#endif
#endif
#else /* !HAVE_NET_ETHERNET_H && !HAVE_SYS_ETHERNET_H -*/
#else /* !HAVE_NET_ETHERNET_H && !HAVE_SYS_ETHERNET_H -*/
 
 
#include <sys/types.h>
#include <sys/types.h>
 
 
#ifdef __CYGWIN__
#ifdef __CYGWIN__
/* define some missing cygwin defines.
/* define some missing cygwin defines.
 *
 *
 * NOTE! there is no nonblocking socket option implemented in cygwin.dll
 * NOTE! there is no nonblocking socket option implemented in cygwin.dll
 *       so defining MSG_DONTWAIT is just (temporary) workaround !!!
 *       so defining MSG_DONTWAIT is just (temporary) workaround !!!
 */
 */
#define MSG_DONTWAIT  0x40
#define MSG_DONTWAIT  0x40
#define ETH_HLEN      14
#define ETH_HLEN      14
#endif /* __CYGWIN__ */
#endif /* __CYGWIN__ */
 
 
#define ETH_ALEN    6
#define ETH_ALEN    6
 
 
struct ether_addr
struct ether_addr
{
{
  u_int8_t ether_addr_octet[ETH_ALEN];
  u_int8_t ether_addr_octet[ETH_ALEN];
};
};
 
 
struct ether_header
struct ether_header
{
{
  u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */
  u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */
  u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */
  u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */
  u_int16_t ether_type;                 /* packet type ID field */
  u_int16_t ether_type;                 /* packet type ID field */
};
};
 
 
/* Ethernet protocol ID's */
/* Ethernet protocol ID's */
#define ETHERTYPE_PUP           0x0200          /* Xerox PUP */
#define ETHERTYPE_PUP           0x0200          /* Xerox PUP */
#define ETHERTYPE_IP            0x0800          /* IP */
#define ETHERTYPE_IP            0x0800          /* IP */
#define ETHERTYPE_ARP           0x0806          /* Address resolution */
#define ETHERTYPE_ARP           0x0806          /* Address resolution */
#define ETHERTYPE_REVARP        0x8035          /* Reverse ARP */
#define ETHERTYPE_REVARP        0x8035          /* Reverse ARP */
 
 
#define ETHER_ADDR_LEN  ETH_ALEN                 /* size of ethernet addr */
#define ETHER_ADDR_LEN  ETH_ALEN                 /* size of ethernet addr */
#define ETHER_TYPE_LEN  2                        /* bytes in type field */
#define ETHER_TYPE_LEN  2                        /* bytes in type field */
#define ETHER_CRC_LEN   4                        /* bytes in CRC field */
#define ETHER_CRC_LEN   4                        /* bytes in CRC field */
#define ETHER_HDR_LEN   ETH_HLEN                 /* total octets in header */
#define ETHER_HDR_LEN   ETH_HLEN                 /* total octets in header */
#define ETHER_MIN_LEN   (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
#define ETHER_MIN_LEN   (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */
#define ETHER_MAX_LEN   (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
#define ETHER_MAX_LEN   (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */
 
 
/* make sure ethenet length is valid */
/* make sure ethenet length is valid */
#define ETHER_IS_VALID_LEN(foo) \
#define ETHER_IS_VALID_LEN(foo) \
        ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
        ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
 
 
/*
/*
 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
 * by an ETHER type (as given above) and then the (variable-length) header.
 * by an ETHER type (as given above) and then the (variable-length) header.
 */
 */
#define ETHERTYPE_TRAIL         0x1000          /* Trailer packet */
#define ETHERTYPE_TRAIL         0x1000          /* Trailer packet */
#define ETHERTYPE_NTRAILER      16
#define ETHERTYPE_NTRAILER      16
 
 
#define ETHERMTU        ETH_DATA_LEN
#define ETHERMTU        ETH_DATA_LEN
#define ETHERMIN        (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
#define ETHERMIN        (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
 
 
#endif /* HAVE_NET_ETHERNET_H */
#endif /* HAVE_NET_ETHERNET_H */
 
 
 
 
/*
/*
 * Implementatino of Ethernet MAC Registers and State
 * Implementatino of Ethernet MAC Registers and State
 */
 */
#define ETH_TXSTATE_IDLE        0
#define ETH_TXSTATE_IDLE        0
#define ETH_TXSTATE_WAIT4BD     10
#define ETH_TXSTATE_WAIT4BD     10
#define ETH_TXSTATE_READFIFO    20
#define ETH_TXSTATE_READFIFO    20
#define ETH_TXSTATE_TRANSMIT    30
#define ETH_TXSTATE_TRANSMIT    30
 
 
#define ETH_RXSTATE_IDLE        0
#define ETH_RXSTATE_IDLE        0
#define ETH_RXSTATE_WAIT4BD     10
#define ETH_RXSTATE_WAIT4BD     10
#define ETH_RXSTATE_RECV        20
#define ETH_RXSTATE_RECV        20
#define ETH_RXSTATE_WRITEFIFO   30
#define ETH_RXSTATE_WRITEFIFO   30
 
 
#define ETH_RTX_FILE    0
#define ETH_RTX_FILE    0
#define ETH_RTX_SOCK    1
#define ETH_RTX_SOCK    1
#define ETH_RTX_VAPI    2
#define ETH_RTX_VAPI    2
 
 
#define ETH_MAXPL   0x10000
#define ETH_MAXPL   0x10000
 
 
enum { ETH_VAPI_DATA = 0,
enum { ETH_VAPI_DATA = 0,
       ETH_VAPI_CTRL,
       ETH_VAPI_CTRL,
       ETH_NUM_VAPI_IDS };
       ETH_NUM_VAPI_IDS };
 
 
struct eth_device
struct eth_device
{
{
  /* Is peripheral enabled */
  /* Is peripheral enabled */
  int enabled;
  int enabled;
 
 
  /* Base address in memory */
  /* Base address in memory */
  oraddr_t baseaddr;
  oraddr_t baseaddr;
 
 
  /* Which DMA controller is this MAC connected to */
  /* Which DMA controller is this MAC connected to */
  unsigned dma;
  unsigned dma;
        unsigned tx_channel;
        unsigned tx_channel;
        unsigned rx_channel;
        unsigned rx_channel;
 
 
  /* Our address */
  /* Our address */
  unsigned char mac_address[ETHER_ADDR_LEN];
  unsigned char mac_address[ETHER_ADDR_LEN];
 
 
  /* interrupt line */
  /* interrupt line */
  unsigned long mac_int;
  unsigned long mac_int;
 
 
  /* VAPI ID */
  /* VAPI ID */
  unsigned long base_vapi_id;
  unsigned long base_vapi_id;
 
 
  /* RX and TX file names and handles */
  /* RX and TX file names and handles */
  char *rxfile, *txfile;
  char *rxfile, *txfile;
        int txfd;
        int txfd;
        int rxfd;
        int rxfd;
        off_t loopback_offset;
        off_t loopback_offset;
 
 
  /* Socket interface name */
  /* Socket interface name */
  char *sockif;
  char *sockif;
 
 
    int rtx_sock;
    int rtx_sock;
    int rtx_type;
    int rtx_type;
    struct ifreq ifr;
    struct ifreq ifr;
    fd_set rfds, wfds;
    fd_set rfds, wfds;
 
 
        /* Current TX state */
        /* Current TX state */
        struct
        struct
        {
        {
            unsigned long state;
            unsigned long state;
            unsigned long bd_index;
            unsigned long bd_index;
            unsigned long bd;
            unsigned long bd;
            unsigned long bd_addr;
            unsigned long bd_addr;
            unsigned working, waiting_for_dma, error;
            unsigned working, waiting_for_dma, error;
            long packet_length;
            long packet_length;
            unsigned minimum_length, maximum_length;
            unsigned minimum_length, maximum_length;
            unsigned add_crc;
            unsigned add_crc;
            unsigned crc_dly;
            unsigned crc_dly;
            unsigned long crc_value;
            unsigned long crc_value;
            long bytes_left, bytes_sent;
            long bytes_left, bytes_sent;
        } tx;
        } tx;
 
 
        /* Current RX state */
        /* Current RX state */
        struct
        struct
        {
        {
            unsigned long state;
            unsigned long state;
            unsigned long bd_index;
            unsigned long bd_index;
            unsigned long bd;
            unsigned long bd;
            unsigned long bd_addr;
            unsigned long bd_addr;
            int fd;
            int fd;
            off_t *offset;
            off_t *offset;
            unsigned working, error, waiting_for_dma;
            unsigned working, error, waiting_for_dma;
            long packet_length, bytes_read, bytes_left;
            long packet_length, bytes_read, bytes_left;
        } rx;
        } rx;
 
 
  /* Visible registers */
  /* Visible registers */
  struct
  struct
  {
  {
    unsigned long moder;
    unsigned long moder;
    unsigned long int_source;
    unsigned long int_source;
    unsigned long int_mask;
    unsigned long int_mask;
    unsigned long ipgt;
    unsigned long ipgt;
    unsigned long ipgr1;
    unsigned long ipgr1;
    unsigned long ipgr2;
    unsigned long ipgr2;
    unsigned long packetlen;
    unsigned long packetlen;
    unsigned long collconf;
    unsigned long collconf;
    unsigned long tx_bd_num;
    unsigned long tx_bd_num;
    unsigned long controlmoder;
    unsigned long controlmoder;
    unsigned long miimoder;
    unsigned long miimoder;
    unsigned long miicommand;
    unsigned long miicommand;
    unsigned long miiaddress;
    unsigned long miiaddress;
    unsigned long miitx_data;
    unsigned long miitx_data;
    unsigned long miirx_data;
    unsigned long miirx_data;
    unsigned long miistatus;
    unsigned long miistatus;
    unsigned long hash0;
    unsigned long hash0;
    unsigned long hash1;
    unsigned long hash1;
 
 
    /* Buffer descriptors */
    /* Buffer descriptors */
    unsigned long bd_ram[ETH_BD_SPACE / 4];
    unsigned long bd_ram[ETH_BD_SPACE / 4];
  } regs;
  } regs;
 
 
    unsigned char rx_buff[ETH_MAXPL];
    unsigned char rx_buff[ETH_MAXPL];
    unsigned char tx_buff[ETH_MAXPL];
    unsigned char tx_buff[ETH_MAXPL];
    unsigned char lo_buff[ETH_MAXPL];
    unsigned char lo_buff[ETH_MAXPL];
};
};
 
 
#endif /* __OR1KSIM_PERIPHERAL_ETHERNET_I_H */
#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.