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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [peripheral/] [eth.c] - Diff between revs 429 and 434

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 429 Rev 434
Line 30... Line 30...
#include "port.h"
#include "port.h"
 
 
/* System includes */
/* System includes */
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <sys/types.h>
 
 
#include <sys/socket.h>
 
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/stat.h>
 
#include <sys/types.h>
#include <fcntl.h>
#include <fcntl.h>
 
 
#include <sys/poll.h>
#include <sys/poll.h>
#include <sys/time.h>
 
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#include <netinet/in.h>
 
#include <sys/ioctl.h>
#include <linux/if.h>
#include <sys/socket.h>
#include <linux/if_tun.h>
#include <net/if.h>
 
 
 
/* Package includes */
/* Package includes */
#include "arch.h"
#include "arch.h"
#include "config.h"
#include "config.h"
#include "abstract.h"
#include "abstract.h"
Line 82... Line 84...
  unsigned long base_vapi_id;
  unsigned long base_vapi_id;
 
 
  /* Ethernet PHY address */
  /* Ethernet PHY address */
  unsigned long phy_addr;
  unsigned long phy_addr;
 
 
  /* RX and TX file names and handles */
  /* What sort of external I/F: FILE or TAP */
 
  int rtx_type;
 
 
 
  /* RX and TX file names and handles for FILE type connection. */
  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 */
  /* Info for TAP type connections */
  char *sockif;
  int   rtx_fd;
 
  char *tap_dev;
  int rtx_sock;
 
  int rtx_type;
 
  struct ifreq ifr;
 
  fd_set rfds, wfds;
 
 
 
  /* Current TX state */
  /* Current TX state */
  struct
  struct
  {
  {
    unsigned long state;
    unsigned long state;
Line 171... Line 172...
static ssize_t eth_read_rx_file (struct eth_device *, void *, size_t);
static ssize_t eth_read_rx_file (struct eth_device *, void *, size_t);
static void eth_skip_rx_file (struct eth_device *, off_t);
static void eth_skip_rx_file (struct eth_device *, off_t);
static void eth_rx_next_packet (struct eth_device *);
static void eth_rx_next_packet (struct eth_device *);
static void eth_write_tx_bd_num (struct eth_device *, unsigned long value);
static void eth_write_tx_bd_num (struct eth_device *, unsigned long value);
static void eth_miim_trans (void *dat);
static void eth_miim_trans (void *dat);
 
 
 
 
 
/* ========================================================================== */
 
/* Dummy socket routines. These are the points where we spoof an Ethernet     */
 
/* network.                                                                   */
 
/* -------------------------------------------------------------------------- */
 
 
 
 
/* ========================================================================= */
/* ========================================================================= */
/*  TX LOGIC                                                                 */
/*  TX LOGIC                                                                 */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
 
 
/*
/*
Line 184... Line 193...
static void
static void
eth_controller_tx_clock (void *dat)
eth_controller_tx_clock (void *dat)
{
{
  struct eth_device *eth = dat;
  struct eth_device *eth = dat;
  int bAdvance = 1;
  int bAdvance = 1;
#if HAVE_ETH_PHY
 
  struct sockaddr_ll sll;
 
#endif /* HAVE_ETH_PHY */
 
  long nwritten = 0;
  long nwritten = 0;
  unsigned long read_word;
  unsigned long read_word;
 
 
  switch (eth->tx.state)
  switch (eth->tx.state)
    {
    {
Line 261... Line 267...
        }
        }
 
 
      /* stay in this state if (TXEN && !READY) */
      /* stay in this state if (TXEN && !READY) */
      break;
      break;
    case ETH_TXSTATE_READFIFO:
    case ETH_TXSTATE_READFIFO:
#if 1
 
      if (eth->tx.bytes_sent < eth->tx.packet_length)
      if (eth->tx.bytes_sent < eth->tx.packet_length)
        {
        {
          read_word =
          read_word =
            eval_direct32 (eth->tx.bytes_sent + eth->tx.bd_addr, 0, 0);
            eval_direct32 (eth->tx.bytes_sent + eth->tx.bd_addr, 0, 0);
          eth->tx_buff[eth->tx.bytes_sent] =
          eth->tx_buff[eth->tx.bytes_sent] =
Line 275... Line 280...
          eth->tx_buff[eth->tx.bytes_sent + 2] =
          eth->tx_buff[eth->tx.bytes_sent + 2] =
            (unsigned char) (read_word >> 8);
            (unsigned char) (read_word >> 8);
          eth->tx_buff[eth->tx.bytes_sent + 3] = (unsigned char) (read_word);
          eth->tx_buff[eth->tx.bytes_sent + 3] = (unsigned char) (read_word);
          eth->tx.bytes_sent += 4;
          eth->tx.bytes_sent += 4;
        }
        }
#else
 
      if (eth->tx.bytes_sent < eth->tx.packet_length)
 
        {
 
          eth->tx_buff[eth->tx.bytes_sent] =
 
            eval_direct8 (eth->tx.bytes_sent + eth->tx.bd_addr, 0, 0);
 
          eth->tx.bytes_sent += 1;
 
        }
 
#endif
 
      else
      else
        {
        {
          eth->tx.state = ETH_TXSTATE_TRANSMIT;
          eth->tx.state = ETH_TXSTATE_TRANSMIT;
        }
        }
      break;
      break;
Line 295... Line 292...
      switch (eth->rtx_type)
      switch (eth->rtx_type)
        {
        {
        case ETH_RTX_FILE:
        case ETH_RTX_FILE:
          nwritten = write (eth->txfd, eth->tx_buff, eth->tx.packet_length);
          nwritten = write (eth->txfd, eth->tx_buff, eth->tx.packet_length);
          break;
          break;
#if HAVE_ETH_PHY
        case ETH_RTX_TAP:
        case ETH_RTX_SOCK:
          printf ("Writing TAP\n");
          memset (&sll, 0, sizeof (sll));
          nwritten = write (eth->rtx_fd, eth->tx_buff, eth->tx.packet_length);
          sll.sll_ifindex = eth->ifr.ifr_ifindex;
          break;
          nwritten =
 
            sendto (eth->rtx_sock, eth->tx_buff, eth->tx.packet_length, 0,
 
                    (struct sockaddr *) &sll, sizeof (sll));
 
#endif /* HAVE_ETH_PHY */
 
        }
        }
 
 
      /* set BD status */
      /* set BD status */
      if (nwritten == eth->tx.packet_length)
      if (nwritten == eth->tx.packet_length)
        {
        {
Line 330... Line 323...
      /* generate OK interrupt */
      /* generate OK interrupt */
      if (TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, TXE_M) ||
      if (TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, TXE_M) ||
          TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, TXB_M))
          TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, TXB_M))
        {
        {
          if (TEST_FLAG (eth->tx.bd, ETH_TX_BD, IRQ))
          if (TEST_FLAG (eth->tx.bd, ETH_TX_BD, IRQ))
 
            {
 
              printf ("ETH_TXSTATE_TRANSMIT interrupt\n");
            report_interrupt (eth->mac_int);
            report_interrupt (eth->mac_int);
        }
        }
 
        }
 
 
      /* advance to next BD */
      /* advance to next BD */
      if (bAdvance)
      if (bAdvance)
        {
        {
          if (TEST_FLAG (eth->tx.bd, ETH_TX_BD, WRAP) ||
          if (TEST_FLAG (eth->tx.bd, ETH_TX_BD, WRAP) ||
Line 365... Line 361...
 */
 */
static void
static void
eth_controller_rx_clock (void *dat)
eth_controller_rx_clock (void *dat)
{
{
  struct eth_device *eth = dat;
  struct eth_device *eth = dat;
  long nread;
  long               nread = 0;
  unsigned long send_word;
  unsigned long send_word;
 
  struct pollfd      fds[1];
 
  int                n;
 
 
 
 
  switch (eth->rx.state)
  switch (eth->rx.state)
    {
    {
    case ETH_RXSTATE_IDLE:
    case ETH_RXSTATE_IDLE:
      eth->rx.state = ETH_RXSTATE_WAIT4BD;
      eth->rx.state = ETH_RXSTATE_WAIT4BD;
      break;
      break;
 
 
    case ETH_RXSTATE_WAIT4BD:
    case ETH_RXSTATE_WAIT4BD:
 
 
      eth->rx.bd = eth->regs.bd_ram[eth->rx.bd_index];
      eth->rx.bd = eth->regs.bd_ram[eth->rx.bd_index];
      eth->rx.bd_addr = eth->regs.bd_ram[eth->rx.bd_index + 1];
      eth->rx.bd_addr = eth->regs.bd_ram[eth->rx.bd_index + 1];
 
 
      if (TEST_FLAG (eth->rx.bd, ETH_RX_BD, READY))
      if (TEST_FLAG (eth->rx.bd, ETH_RX_BD, READY))
        {
        {
Line 410... Line 409...
        {
        {
          eth->rx.state = ETH_RXSTATE_IDLE;
          eth->rx.state = ETH_RXSTATE_IDLE;
        }
        }
      else
      else
        {
        {
          nread =
          /* Poll to see if there is data to read */
            recv (eth->rtx_sock, eth->rx_buff, ETH_MAXPL, /*MSG_PEEK | */
          struct pollfd  fds[1];
                  MSG_DONTWAIT);
          int    n;
          if (nread > 0)
 
 
          fds[0].fd = eth->rtx_fd;
 
          fds[0].events = POLLIN;
 
 
 
          n = poll (fds, 1, 0);
 
          if (n < 0)
 
            {
 
              fprintf (stderr, "Warning: Poll of WAIT4BD failed %s: ignored.\n",
 
                       strerror (errno));
 
            }
 
          else if ((n > 0) && ((fds[0].revents & POLLIN) == POLLIN))
 
            {
 
              printf ("Reading TAP\n");
 
              nread = read (eth->rtx_fd, eth->rx_buff, ETH_MAXPL);
 
 
 
              if (nread < 0)
 
                {
 
                  fprintf (stderr,
 
                           "Warning: Read of WAIT4BD failed %s: ignored\n",
 
                           strerror (errno));
 
                }
 
              else if (nread > 0)
            {
            {
              SET_FLAG (eth->regs.int_source, ETH_INT_SOURCE, BUSY);
              SET_FLAG (eth->regs.int_source, ETH_INT_SOURCE, BUSY);
 
 
              if (TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, BUSY_M))
              if (TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, BUSY_M))
 
                    {
 
                      printf ("ETH_RXSTATE_WAIT4BD interrupt\n");
                report_interrupt (eth->mac_int);
                report_interrupt (eth->mac_int);
            }
            }
        }
        }
 
            }
 
        }
 
 
      break;
      break;
 
 
    case ETH_RXSTATE_RECV:
    case ETH_RXSTATE_RECV:
 
 
      switch (eth->rtx_type)
      switch (eth->rtx_type)
        {
        {
        case ETH_RTX_FILE:
        case ETH_RTX_FILE:
          /* Read packet length */
          /* Read packet length */
          if (eth_read_rx_file
          if (eth_read_rx_file
              (eth, &(eth->rx.packet_length),
              (eth, &(eth->rx.packet_length),
               sizeof (eth->rx.packet_length)) <
               sizeof (eth->rx.packet_length)) <
              sizeof (eth->rx.packet_length))
              sizeof (eth->rx.packet_length))
            {
            {
              /* TODO: just do what real ethernet would do (some kind of error state) */
              /* TODO: just do what real ethernet would do (some kind of error
 
                 state) */
              sim_done ();
              sim_done ();
              break;
              break;
            }
            }
 
 
          /* Packet must be big enough to hold a header */
          /* Packet must be big enough to hold a header */
Line 465... Line 493...
 
 
          eth->rx.state = ETH_RXSTATE_WRITEFIFO;
          eth->rx.state = ETH_RXSTATE_WRITEFIFO;
 
 
          break;
          break;
 
 
        case ETH_RTX_SOCK:
        case ETH_RTX_TAP:
          nread = recv (eth->rtx_sock, eth->rx_buff, ETH_MAXPL, MSG_DONTWAIT);
          /* Poll to see if there is data to read */
 
          fds[0].fd     = eth->rtx_fd;
 
          fds[0].events = POLLIN;
 
 
          if (nread == 0)
          n = poll (fds, 1, 0);
 
          if (n < 0)
            {
            {
              break;
              fprintf (stderr,
 
                       "Warning: Poll of RXTATE_RECV failed %s: ignored.\n",
 
                       strerror (errno));
            }
            }
          else if (nread < 0)
          else if ((n > 0) && ((fds[0].revents & POLLIN) == POLLIN))
            {
            {
              if (errno != EAGAIN)
              printf ("Reading TAP\n");
 
              nread = read (eth->rtx_fd, eth->rx_buff, ETH_MAXPL);
 
 
 
              if (nread < 0)
                {
                {
                  break;
                  fprintf (stderr,
 
                           "Warning: Read of RXTATE_RECV failed %s: ignored\n",
 
                           strerror (errno));
                }
                }
              else
              else if (nread > 0)
                break;
                {
 
                  SET_FLAG (eth->regs.int_source, ETH_INT_SOURCE, BUSY);
 
 
 
                  if (TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, BUSY_M))
 
                    {
 
                      printf ("ETH_RXTATE_RECV interrupt\n");
 
                      report_interrupt (eth->mac_int);
            }
            }
 
                }
 
            }
 
 
          /* If not promiscouos mode, check the destination address */
          /* If not promiscouos mode, check the destination address */
          if (!TEST_FLAG (eth->regs.moder, ETH_MODER, PRO))
          if (!TEST_FLAG (eth->regs.moder, ETH_MODER, PRO))
            {
            {
              if (TEST_FLAG (eth->regs.moder, ETH_MODER, IAM)
              if (TEST_FLAG (eth->regs.moder, ETH_MODER, IAM)
                  && (eth->rx_buff[0] & 1))
                  && (eth->rx_buff[0] & 1))
Line 512... Line 559...
          break;
          break;
        }
        }
      break;
      break;
 
 
    case ETH_RXSTATE_WRITEFIFO:
    case ETH_RXSTATE_WRITEFIFO:
#if 1
 
      send_word = ((unsigned long) eth->rx_buff[eth->rx.bytes_read] << 24) |
      send_word = ((unsigned long) eth->rx_buff[eth->rx.bytes_read] << 24) |
        ((unsigned long) eth->rx_buff[eth->rx.bytes_read + 1] << 16) |
        ((unsigned long) eth->rx_buff[eth->rx.bytes_read + 1] << 16) |
        ((unsigned long) eth->rx_buff[eth->rx.bytes_read + 2] << 8) |
        ((unsigned long) eth->rx_buff[eth->rx.bytes_read + 2] << 8) |
        ((unsigned long) eth->rx_buff[eth->rx.bytes_read + 3]);
        ((unsigned long) eth->rx_buff[eth->rx.bytes_read + 3]);
      set_direct32 (eth->rx.bd_addr + eth->rx.bytes_read, send_word, 0, 0);
      set_direct32 (eth->rx.bd_addr + eth->rx.bytes_read, send_word, 0, 0);
      /* update counters */
      /* update counters */
      eth->rx.bytes_left -= 4;
      eth->rx.bytes_left -= 4;
      eth->rx.bytes_read += 4;
      eth->rx.bytes_read += 4;
#else
 
      set_direct8 (eth->rx.bd_addr + eth->rx.bytes_read,
 
                   eth->rx_buff[eth->rx.bytes_read], 0, 0);
 
      eth->rx.bytes_left -= 1;
 
      eth->rx.bytes_read += 1;
 
#endif
 
 
 
      if (eth->rx.bytes_left <= 0)
      if (eth->rx.bytes_left <= 0)
        {
        {
          /* Write result to bd */
          /* Write result to bd */
          SET_FIELD (eth->rx.bd, ETH_RX_BD, LENGTH, eth->rx.packet_length);
          SET_FIELD (eth->rx.bd, ETH_RX_BD, LENGTH, eth->rx.packet_length);
Line 554... Line 594...
            eth->rx.bd_index += 2;
            eth->rx.bd_index += 2;
 
 
          if ((TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, RXB_M)) &&
          if ((TEST_FLAG (eth->regs.int_mask, ETH_INT_MASK, RXB_M)) &&
              (TEST_FLAG (eth->rx.bd, ETH_RX_BD, IRQ)))
              (TEST_FLAG (eth->rx.bd, ETH_RX_BD, IRQ)))
            {
            {
 
              printf ("ETH_RXSTATE_WRITEFIFO interrupt\n");
              report_interrupt (eth->mac_int);
              report_interrupt (eth->mac_int);
            }
            }
 
 
          /* ready to receive next packet */
          /* ready to receive next packet */
          eth->rx.state = ETH_RXSTATE_IDLE;
          eth->rx.state = ETH_RXSTATE_IDLE;
Line 613... Line 654...
  return result;
  return result;
}
}
 
 
/* ========================================================================= */
/* ========================================================================= */
 
 
/*
 
  Reset. Initializes all registers to default and places devices in
/* -------------------------------------------------------------------------- */
         memory address space.
/*!Reset the Ethernet.
*/
 
 
   Open the correct type of simulation interface to the outside world.
 
 
 
   Initialize all registers to default and places devices in memory address
 
   space.
 
 
 
   @param[in] dat  The Ethernet interface data structure.                     */
 
/* -------------------------------------------------------------------------- */
static void
static void
eth_reset (void *dat)
eth_reset (void *dat)
{
{
  struct eth_device *eth = dat;
  struct eth_device *eth = dat;
#if HAVE_ETH_PHY
  struct ifreq       ifr;
  int j;
 
  struct sockaddr_ll sll;
 
#endif /* HAVE_ETH_PHY */
 
 
 
  if (eth->baseaddr != 0)
  printf ("Resetting Ethernet\n");
 
 
 
  /* Nothing to do if we do not have a base address set.
 
 
 
     TODO: Surely this should test for being enabled? */
 
  if (0 == eth->baseaddr)
    {
    {
 
      return;
 
    }
 
 
      switch (eth->rtx_type)
      switch (eth->rtx_type)
        {
        {
        case ETH_RTX_FILE:
        case ETH_RTX_FILE:
 
 
          /* (Re-)open TX/RX files */
          /* (Re-)open TX/RX files */
          if (eth->rxfd > 0)
      if (eth->rxfd >= 0)
 
        {
            close (eth->rxfd);
            close (eth->rxfd);
          if (eth->txfd > 0)
        }
 
 
 
      if (eth->txfd >= 0)
 
        {
            close (eth->txfd);
            close (eth->txfd);
          eth->rxfd = eth->txfd = -1;
        }
 
 
 
      eth->rxfd = -1;
 
      eth->txfd = -1;
 
 
 
      eth->rxfd = open (eth->rxfile, O_RDONLY);
 
      if (eth->rxfd < 0)
 
        {
 
          fprintf (stderr, "Warning: Cannot open Ethernet RX file \"%s\": %s\n",
 
                   eth->rxfile, strerror (errno));
 
        }
 
 
          if ((eth->rxfd = open (eth->rxfile, O_RDONLY)) < 0)
      eth->txfd = open (eth->txfile,
            fprintf (stderr, "Cannot open Ethernet RX file \"%s\"\n",
#if defined(O_SYNC)             /* BSD/MacOS X doesn't know about O_SYNC */
                     eth->rxfile);
                        O_SYNC |
          if ((eth->txfd = open (eth->txfile, O_RDWR | O_CREAT | O_APPEND
 
#if defined(O_SYNC)             /* BSD / Mac OS X manual doesn't know about O_SYNC */
 
                                 | O_SYNC
 
#endif
#endif
                                 ,
                        O_RDWR | O_CREAT | O_APPEND,
                                 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0)
                        S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
            fprintf (stderr, "Cannot open Ethernet TX file \"%s\"\n",
      if (eth->txfd < 0)
                     eth->txfile);
        {
          eth->loopback_offset = lseek (eth->txfd, 0, SEEK_END);
          fprintf (stderr, "Warning: Cannot open Ethernet TX file \"%s\": %s\n",
 
                   eth->txfile, strerror (errno));
 
        }
 
 
 
      eth->loopback_offset = lseek (eth->txfd, 0, SEEK_END);
          break;
          break;
#if HAVE_ETH_PHY
 
        case ETH_RTX_SOCK:
 
          /* (Re-)open TX/RX sockets */
 
          if (eth->rtx_sock != 0)
 
            break;
 
 
 
          eth->rtx_sock = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
    case ETH_RTX_TAP:
          if (eth->rtx_sock == -1)
 
 
      /* (Re-)open TAP interface if necessary */
 
      if (eth->rtx_fd != 0)
            {
            {
              fprintf (stderr, "Cannot open rtx_sock.\n");
          break;
              return;
 
            }
            }
 
 
          /* get interface index number */
      /* Open the TUN/TAP device */
          memset (&(eth->ifr), 0, sizeof (eth->ifr));
      eth->rtx_fd = open ("/dev/net/tun", O_RDWR);
          strncpy (eth->ifr.ifr_name, eth->sockif, IFNAMSIZ);
      if( eth->rtx_fd < 0 )
          if (ioctl (eth->rtx_sock, SIOCGIFINDEX, &(eth->ifr)) == -1)
 
            {
            {
              fprintf (stderr, "SIOCGIFINDEX failed!\n");
          fprintf (stderr, "Warning: Failed to open TUN/TAP device: %s\n",
 
                   strerror (errno));
 
          eth->rtx_fd = 0;
              return;
              return;
            }
            }
 
 
          /* Bind to interface... */
      /* Turn it into a specific TAP device. If we haven't specified a
          memset (&sll, 0xff, sizeof (sll));
         specific (persistent) device, one will be created, but that requires
          sll.sll_family = AF_PACKET;   /* allways AF_PACKET */
         superuser, or at least CAP_NET_ADMIN capabilities. */
          sll.sll_protocol = htons (ETH_P_ALL);
      memset (&ifr, 0, sizeof(ifr));
          sll.sll_ifindex = eth->ifr.ifr_ifindex;
      ifr.ifr_flags = IFF_TAP;
          if (bind (eth->rtx_sock, (struct sockaddr *) &sll, sizeof (sll)) ==
      strncpy (ifr.ifr_name, eth->tap_dev, IFNAMSIZ);
              -1)
 
 
      if (ioctl (eth->rtx_fd, TUNSETIFF, (void *) &ifr) < 0)
            {
            {
              fprintf (stderr, "Error bind().\n");
          fprintf (stderr, "Warning: Failed to set TAP device: %s\n",
 
                   strerror (errno));
 
          close (eth->rtx_fd);
 
          eth->rtx_fd = 0;
              return;
              return;
            }
            }
 
 
          /* first, flush all received packets. */
      PRINTF ("Opened TAP %s\n", ifr.ifr_name);
          do
 
            {
 
              fd_set fds;
 
              struct timeval t;
 
 
 
              FD_ZERO (&fds);
 
              FD_SET (eth->rtx_sock, &fds);
 
              memset (&t, 0, sizeof (t));
 
              j = select (FD_SETSIZE, &fds, NULL, NULL, &t);
 
              if (j > 0)
 
                recv (eth->rtx_sock, eth->rx_buff, j, 0);
 
            }
 
          while (j);
 
 
 
 
      /* Do we need to flush any packets? */
          break;
          break;
#else /* HAVE_ETH_PHY */
 
        case ETH_RTX_SOCK:
 
          fprintf (stderr,
 
                   "Ethernet phy not enabled in this configuration.  Configure with --enable-ethphy.\n");
 
          exit (1);
 
          break;
 
#endif /* HAVE_ETH_PHY */
 
        }
        }
 
 
      /* Set registers to default values */
      /* Set registers to default values */
      /* Zero all registers */
 
      memset (&(eth->regs), 0, sizeof (eth->regs));
      memset (&(eth->regs), 0, sizeof (eth->regs));
      /* Set those with non-zero reset defaults */
 
      eth->regs.moder = 0x0000A000;
      eth->regs.moder = 0x0000A000;
      eth->regs.ipgt = 0x00000012;
      eth->regs.ipgt = 0x00000012;
      eth->regs.ipgr1 = 0x0000000C;
      eth->regs.ipgr1 = 0x0000000C;
      eth->regs.ipgr2 = 0x00000012;
      eth->regs.ipgr2 = 0x00000012;
      eth->regs.packetlen = 0x003C0600;
      eth->regs.packetlen = 0x003C0600;
      eth->regs.collconf = 0x000F003F;
      eth->regs.collconf = 0x000F003F;
      eth->regs.miimoder = 0x00000064;
      eth->regs.miimoder = 0x00000064;
      eth->regs.tx_bd_num = 0x00000040;
      eth->regs.tx_bd_num = 0x00000040;
 
 
      /* Initialize TX/RX status */
  /* Clear TX/RX status and initialize buffer descriptor index. */
      memset (&(eth->tx), 0, sizeof (eth->tx));
      memset (&(eth->tx), 0, sizeof (eth->tx));
      memset (&(eth->rx), 0, sizeof (eth->rx));
      memset (&(eth->rx), 0, sizeof (eth->rx));
 
 
      eth->rx.bd_index = eth->regs.tx_bd_num << 1;
      eth->rx.bd_index = eth->regs.tx_bd_num << 1;
 
 
      /* Initialize VAPI */
      /* Initialize VAPI */
      if (eth->base_vapi_id)
      if (eth->base_vapi_id)
        {
        {
          vapi_install_multi_handler (eth->base_vapi_id, ETH_NUM_VAPI_IDS,
          vapi_install_multi_handler (eth->base_vapi_id, ETH_NUM_VAPI_IDS,
                                      eth_vapi_read, dat);
                                      eth_vapi_read, dat);
        }
        }
 
}       /* eth_reset () */
    }
 
}
 
 
 
/* ========================================================================= */
 
 
 
 
 
/*
/*
  Print register values on stdout
  Print register values on stdout
*/
*/
Line 1078... Line 1124...
 
 
 
 
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*!Set the Ethernet interface type
/*!Set the Ethernet interface type
 
 
   Currently two types are supported, file and socket. Use of the socket
   Currently two types are supported, file and tap.
   requires a compile time option.
 
 
 
   @param[in] val  The value to use. 0 for file, 1 for socket.
   @param[in] val  The value to use. Currently "file" and "tap" are supported.
   @param[in] dat  The config data structure                                 */
   @param[in] dat  The config data structure                                 */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
static void
static void
eth_rtx_type (union param_val  val,
eth_rtx_type (union param_val  val,
              void            *dat)
              void            *dat)
{
{
  struct eth_device *eth = dat;
  struct eth_device *eth = dat;
 
 
  if (val.int_val)
  if (0 == strcasecmp ("file", val.str_val))
    {
    {
#ifndef HAVE_ETH_PHY
      printf ("Ethernet FILE type\n");
      fprintf (stderr, "Warning: Ethernet PHY socket not enabled in this "
      eth->rtx_type = ETH_RTX_FILE;
               "configuration (configure with --enable-ethphy): ignored\n");
    }
      return;
  else if (0 == strcasecmp ("tap", val.str_val))
#endif
    {
 
      printf ("Ethernet TAP type\n");
 
      eth->rtx_type = ETH_RTX_TAP;
 
    }
 
  else
 
    {
 
      fprintf (stderr, "Warning: Unknown Ethernet type: file assumed.\n");
 
      eth->rtx_type = ETH_RTX_FILE;
    }
    }
 
 
  eth->rtx_type = val.int_val;
 
 
 
}       /* eth_rtx_type() */
}       /* eth_rtx_type() */
 
 
 
 
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*!Set the Ethernet DMA Rx channel
/*!Set the Ethernet DMA Rx channel
Line 1203... Line 1252...
    }
    }
}       /* eth_txfile() */
}       /* eth_txfile() */
 
 
 
 
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*!Set the Ethernet socket interface
/*!Set the Ethernet TAP device.
 
 
   Free any previously allocated value. This is only meaningful if the socket
   If we are not superuser (or do not have CAP_NET_ADMIN priviledges), then we
   interface is configured.
   must work with a persistent TAP device that is already set up. This option
 
   specifies the device to user.
 
 
   @param[in] val  The value to use
   @param[in] val  The value to use.
   @param[in] dat  The config data structure                                 */
   @param[in] dat  The config data structure                                 */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
static void
static void
eth_sockif (union param_val  val,
eth_tap_dev (union param_val  val,
            void            *dat)
            void            *dat)
{
{
  struct eth_device *eth = dat;
  struct eth_device *eth = dat;
 
 
#ifndef HAVE_ETH_PHY
  if (NULL != eth->tap_dev)
  fprintf (stderr, "Warning: Ethernet PHY socket not enabled in this "
 
           "configuration (configure with --enable-ethphy): "
 
           "sockif ignored\n");
 
  return;
 
#endif
 
 
 
  if (NULL != eth->sockif)
 
    {
    {
      free (eth->sockif);
      free (eth->tap_dev);
      eth->sockif = NULL;
      eth->tap_dev = NULL;
    }
    }
 
 
  if (!(eth->sockif = strdup (val.str_val)))
  eth->tap_dev = strdup (val.str_val);
 
 
 
  if (NULL == eth->tap_dev)
    {
    {
      fprintf (stderr, "Peripheral Ethernet: Run out of memory\n");
      fprintf (stderr, "ERROR: Peripheral Ethernet: Run out of memory\n");
      exit (-1);
      exit (-1);
    }
    }
}       /* eth_sockif() */
}       /* eth_tap_dev() */
 
 
 
 
static void
static void
eth_vapi_id (union param_val  val,
eth_vapi_id (union param_val  val,
             void            *dat)
             void            *dat)
Line 1408... Line 1453...
 
 
  new->enabled      = 1;
  new->enabled      = 1;
  new->baseaddr     = 0;
  new->baseaddr     = 0;
  new->dma          = 0;
  new->dma          = 0;
  new->mac_int      = 0;
  new->mac_int      = 0;
  new->rtx_type     = 0;
  new->rtx_type     = ETH_RTX_FILE;
  new->rx_channel   = 0;
  new->rx_channel   = 0;
  new->tx_channel   = 0;
  new->tx_channel   = 0;
  new->rxfile       = strdup ("eth_rx");
  new->rxfile       = strdup ("eth_rx");
  new->txfile       = strdup ("eth_tx");
  new->txfile       = strdup ("eth_tx");
  new->sockif       = strdup ("or1ksim_eth");
  new->tap_dev      = strdup ("");
  new->base_vapi_id = 0;
  new->base_vapi_id = 0;
  new->phy_addr     = 0;
  new->phy_addr     = 0;
 
 
  return new;
  return new;
}
}
Line 1430... Line 1475...
 
 
  if (!eth->enabled)
  if (!eth->enabled)
    {
    {
      free (eth->rxfile);
      free (eth->rxfile);
      free (eth->txfile);
      free (eth->txfile);
      free (eth->sockif);
      free (eth->tap_dev);
      free (eth);
      free (eth);
      return;
      return;
    }
    }
 
 
  memset (&ops, 0, sizeof (struct mem_ops));
  memset (&ops, 0, sizeof (struct mem_ops));
Line 1464... Line 1509...
 
 
  reg_config_param (sec, "enabled",    PARAMT_INT,  eth_enabled);
  reg_config_param (sec, "enabled",    PARAMT_INT,  eth_enabled);
  reg_config_param (sec, "baseaddr",   PARAMT_ADDR, eth_baseaddr);
  reg_config_param (sec, "baseaddr",   PARAMT_ADDR, eth_baseaddr);
  reg_config_param (sec, "dma",        PARAMT_INT,  eth_dma);
  reg_config_param (sec, "dma",        PARAMT_INT,  eth_dma);
  reg_config_param (sec, "irq",        PARAMT_INT,  eth_irq);
  reg_config_param (sec, "irq",        PARAMT_INT,  eth_irq);
  reg_config_param (sec, "rtx_type",   PARAMT_INT,  eth_rtx_type);
  reg_config_param (sec, "rtx_type",   PARAMT_STR,  eth_rtx_type);
  reg_config_param (sec, "rx_channel", PARAMT_INT,  eth_rx_channel);
  reg_config_param (sec, "rx_channel", PARAMT_INT,  eth_rx_channel);
  reg_config_param (sec, "tx_channel", PARAMT_INT,  eth_tx_channel);
  reg_config_param (sec, "tx_channel", PARAMT_INT,  eth_tx_channel);
  reg_config_param (sec, "rxfile",     PARAMT_STR,  eth_rxfile);
  reg_config_param (sec, "rxfile",     PARAMT_STR,  eth_rxfile);
  reg_config_param (sec, "txfile",     PARAMT_STR,  eth_txfile);
  reg_config_param (sec, "txfile",     PARAMT_STR,  eth_txfile);
  reg_config_param (sec, "sockif",     PARAMT_STR,  eth_sockif);
  reg_config_param (sec, "tap_dev",    PARAMT_STR,  eth_tap_dev);
  reg_config_param (sec, "vapi_id",    PARAMT_INT,  eth_vapi_id);
  reg_config_param (sec, "vapi_id",    PARAMT_INT,  eth_vapi_id);
  reg_config_param (sec, "phy_addr",   PARAMT_INT,  eth_phy_addr);
  reg_config_param (sec, "phy_addr",   PARAMT_INT,  eth_phy_addr);
 
 
}       /* reg_ethernet_sec() */
}       /* reg_ethernet_sec() */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.