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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [peripheral/] [eth.c] - Diff between revs 1366 and 1372

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

Rev 1366 Rev 1372
Line 46... Line 46...
#include "sim-config.h"
#include "sim-config.h"
#include "fields.h"
#include "fields.h"
#include "crc32.h"
#include "crc32.h"
#include "vapi.h"
#include "vapi.h"
#include "pic.h"
#include "pic.h"
 
#include "sched.h"
#include "debug.h"
#include "debug.h"
 
 
static struct eth_device eths[MAX_ETHERNETS];
DEFAULT_DEBUG_CHANNEL(eth);
 
 
/* simulator interface */
/* simulator interface */
static void eth_reset_controller( struct eth_device *eth);
 
static void eth_vapi_read( unsigned long id, unsigned long data, void *dat);
static void eth_vapi_read( unsigned long id, unsigned long data, void *dat);
/* register interface */
/* register interface */
static void eth_write32( oraddr_t addr, uint32_t value, void *dat );
static void eth_write32( oraddr_t addr, uint32_t value, void *dat );
static uint32_t eth_read32( oraddr_t addr, void *dat );
static uint32_t eth_read32( oraddr_t addr, void *dat );
/* clock */
/* clock */
static void eth_controller_tx_clock( struct eth_device * );
static void eth_controller_tx_clock( void * );
static void eth_controller_rx_clock( struct eth_device * );
static void eth_controller_rx_clock( void * );
/* utility functions */
/* utility functions */
static int eth_find_controller( oraddr_t addr, struct eth_device **eth, oraddr_t *reladdr );
 
struct eth_device *eth_find_vapi_device (unsigned long id, unsigned long *which);
 
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_rewind_rx_file( struct eth_device *, off_t );
static void eth_rewind_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 );
Line 75... Line 73...
 
 
/*
/*
 * TX clock
 * TX clock
 * Responsible for starting and finishing TX
 * Responsible for starting and finishing TX
 */
 */
void eth_controller_tx_clock( struct eth_device *eth )
void eth_controller_tx_clock( void *dat )
{
{
 
    struct eth_device *eth = dat;
    int breakpoint = 0;
    int breakpoint = 0;
    int bAdvance   = 1;
    int bAdvance   = 1;
#if HAVE_ETH_PHY
#if HAVE_ETH_PHY
    struct sockaddr_ll sll;
    struct sockaddr_ll sll;
#endif /* HAVE_ETH_PHY */
#endif /* HAVE_ETH_PHY */
    long nwritten;
    long nwritten;
    unsigned long read_word;
    unsigned long read_word;
 
 
    switch (eth->tx.state) {
    switch (eth->tx.state) {
        case ETH_TXSTATE_IDLE:
        case ETH_TXSTATE_IDLE:
        if ( TEST_FLAG( eth->regs.moder, ETH_MODER, TXEN ) ) {
 
 
 
            /* wait for TxBuffer to be ready */
 
                debug (3, "TX - entering state WAIT4BD (%ld)\n", eth->tx.bd_index);
                debug (3, "TX - entering state WAIT4BD (%ld)\n", eth->tx.bd_index);
            eth->tx.state = ETH_TXSTATE_WAIT4BD;
            eth->tx.state = ETH_TXSTATE_WAIT4BD;
        }
 
        break;
        break;
    case ETH_TXSTATE_WAIT4BD:
    case ETH_TXSTATE_WAIT4BD:
        /* Read buffer descriptor */
        /* Read buffer descriptor */
        eth->tx.bd = eth->regs.bd_ram[eth->tx.bd_index];
        eth->tx.bd = eth->regs.bd_ram[eth->tx.bd_index];
        eth->tx.bd_addr = eth->regs.bd_ram[eth->tx.bd_index + 1];
        eth->tx.bd_addr = eth->regs.bd_ram[eth->tx.bd_index + 1];
Line 154... Line 149...
            /************************************************/
            /************************************************/
            /* start transmit with reading packet into FIFO */
            /* start transmit with reading packet into FIFO */
                debug (3, "TX - entering state READFIFO\n");
                debug (3, "TX - entering state READFIFO\n");
            eth->tx.state = ETH_TXSTATE_READFIFO;
            eth->tx.state = ETH_TXSTATE_READFIFO;
        }
        }
        else if ( !TEST_FLAG( eth->regs.moder, ETH_MODER, TXEN ) ) {
 
            /* stop TX logic */
 
                debug (3, "TX - entering state IDLE\n");
 
            eth->tx.state = ETH_TXSTATE_IDLE;
 
        }
 
 
 
        /* 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 1
Line 203... Line 193...
        if (nwritten == eth->tx.packet_length) {
        if (nwritten == eth->tx.packet_length) {
            CLEAR_FLAG (eth->tx.bd, ETH_TX_BD, READY);
            CLEAR_FLAG (eth->tx.bd, ETH_TX_BD, READY);
            SET_FLAG (eth->regs.int_source, ETH_INT_SOURCE, TXB);
            SET_FLAG (eth->regs.int_source, ETH_INT_SOURCE, TXB);
            debug (4, "ETH_INT_SOURCE = %0lx\n", eth->regs.int_source);
            debug (4, "ETH_INT_SOURCE = %0lx\n", eth->regs.int_source);
 
 
            debug (3, "TX - entering state IDLE\n");
            debug (3, "TX - entering state WAIT4BD\n");
            eth->tx.state = ETH_TXSTATE_IDLE;
            eth->tx.state = ETH_TXSTATE_WAIT4BD;
            debug (3, "send (%ld)bytes OK\n", nwritten);
            debug (3, "send (%ld)bytes OK\n", nwritten);
        }
        }
        else {
        else {
            /* XXX - implement retry mechanism here! */
            /* XXX - implement retry mechanism here! */
            CLEAR_FLAG (eth->tx.bd, ETH_TX_BD, READY);
            CLEAR_FLAG (eth->tx.bd, ETH_TX_BD, READY);
            CLEAR_FLAG (eth->tx.bd, ETH_TX_BD, COLLISION);
            CLEAR_FLAG (eth->tx.bd, ETH_TX_BD, COLLISION);
            SET_FLAG (eth->regs.int_source, ETH_INT_SOURCE, TXE);
            SET_FLAG (eth->regs.int_source, ETH_INT_SOURCE, TXE);
            debug (4, "ETH_INT_SOURCE = %0lx\n", eth->regs.int_source);
            debug (4, "ETH_INT_SOURCE = %0lx\n", eth->regs.int_source);
 
 
            debug (3, "TX - entering state IDLE\n");
            debug (3, "TX - entering state WAIT4BD\n");
            eth->tx.state = ETH_TXSTATE_IDLE;
            eth->tx.state = ETH_TXSTATE_WAIT4BD;
            debug (3, "send FAILED!\n");
            debug (3, "send FAILED!\n");
        }
        }
 
 
        eth->regs.bd_ram[eth->tx.bd_index] = eth->tx.bd;
        eth->regs.bd_ram[eth->tx.bd_index] = eth->tx.bd;
 
 
Line 240... Line 230...
                eth->tx.bd_index += 2;
                eth->tx.bd_index += 2;
        }
        }
 
 
        break;
        break;
    }
    }
 
 
 
    /* Reschedule */
 
    SCHED_ADD( eth_controller_tx_clock, dat, runtime.sim.cycles + 1 );
}
}
/* ========================================================================= */
/* ========================================================================= */
 
 
 
 
/* ========================================================================= */
/* ========================================================================= */
Line 252... Line 245...
 
 
/*
/*
 * RX clock
 * RX clock
 * Responsible for starting and finishing RX
 * Responsible for starting and finishing RX
 */
 */
void eth_controller_rx_clock( struct eth_device *eth )
void eth_controller_rx_clock( void *dat )
{
{
 
    struct eth_device *eth = dat;
    int breakpoint = 0;
    int breakpoint = 0;
    long nread;
    long nread;
    unsigned long send_word;
    unsigned long send_word;
 
 
 
 
    switch (eth->rx.state) {
    switch (eth->rx.state) {
    case ETH_RXSTATE_IDLE:
    case ETH_RXSTATE_IDLE:
        if ( TEST_FLAG( eth->regs.moder, ETH_MODER, RXEN) ) {
 
                debug (3, "RX - entering state WAIT4BD (%ld)\n", eth->rx.bd_index);
                debug (3, "RX - entering state WAIT4BD (%ld)\n", eth->rx.bd_index);
            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];
Line 326... Line 318...
            /* Packet must be big enough to hold a header */
            /* Packet must be big enough to hold a header */
            if ( eth->rx.packet_length < ETHER_HDR_LEN ){
            if ( eth->rx.packet_length < ETHER_HDR_LEN ){
                debug( 3,  "eth_start_rx(): Packet too small\n" );
                debug( 3,  "eth_start_rx(): Packet too small\n" );
                eth_rx_next_packet( eth );
                eth_rx_next_packet( eth );
 
 
                debug (3, "RX - entering state IDLE\n");
                debug (3, "RX - entering state WAIT4BD\n");
                eth->rx.state = ETH_RXSTATE_IDLE;
                eth->rx.state = ETH_RXSTATE_WAIT4BD;
                break;
                break;
            }
            }
 
 
            eth->rx.bytes_read = 0;
            eth->rx.bytes_read = 0;
            eth->rx.bytes_left = eth->rx.packet_length;
            eth->rx.bytes_left = eth->rx.packet_length;
Line 440... Line 432...
                debug (3, "RX - entering state IDLE\n");
                debug (3, "RX - entering state IDLE\n");
            eth->rx.state = ETH_RXSTATE_IDLE;
            eth->rx.state = ETH_RXSTATE_IDLE;
        }
        }
        break;
        break;
    }
    }
 
 
 
    /* Reschedule */
 
    SCHED_ADD( eth_controller_rx_clock, dat, runtime.sim.cycles + 1 );
}
}
 
 
/* ========================================================================= */
/* ========================================================================= */
/* Move to next RX BD */
/* Move to next RX BD */
void eth_rx_next_packet( struct eth_device *eth )
void eth_rx_next_packet( struct eth_device *eth )
Line 494... Line 489...
 
 
/*
/*
  Reset. Initializes all registers to default and places devices in
  Reset. Initializes all registers to default and places devices in
         memory address space.
         memory address space.
*/
*/
void eth_reset()
void eth_reset(void *dat)
{
 
    static int first_time = 1;
 
    unsigned i;
 
 
 
    if (!config.nethernets)
 
        return;
 
 
 
    if ( first_time )
 
        memset( eths, 0, sizeof(eths) );
 
 
 
    for ( i = 0; i < MAX_ETHERNETS; ++ i ) {
 
        struct eth_device *eth = &(eths[i]);
 
 
 
        if (!HAVE_ETH_PHY && eth->rtx_type == ETH_RTX_SOCK) {
 
          fprintf (stderr, "Ethernet phy not enabled in this configuration.  Configure with --enable-ethphy.\n");
 
          exit (1);
 
        }
 
        eth->eth_number = i;
 
        eth_reset_controller( eth );
 
        if ( eth->baseaddr && first_time )
 
            register_memoryarea( eth->baseaddr, ETH_ADDR_SPACE, 4, 0, eth_read32, eth_write32, NULL );
 
    }
 
 
 
    if ( first_time )
 
        first_time = 0;
 
}
 
 
 
/* ========================================================================= */
 
 
 
 
 
static void eth_reset_controller(struct eth_device *eth)
 
{
{
    int i = eth->eth_number;
    struct eth_device *eth = dat;
#if HAVE_ETH_PHY
#if HAVE_ETH_PHY
    int j;
    int j;
    struct sockaddr_ll sll;
    struct sockaddr_ll sll;
#endif /* HAVE_ETH_PHY */
#endif /* HAVE_ETH_PHY */
 
 
    eth->baseaddr = config.ethernets[i].baseaddr;
 
 
 
    if ( eth->baseaddr != 0 ) {
    if ( eth->baseaddr != 0 ) {
        /* Mark which DMA controller and channels */
 
        eth->dma        = config.ethernets[i].dma;
 
        eth->mac_int    = config.ethernets[i].irq;
 
        eth->tx_channel = config.ethernets[i].tx_channel;
 
        eth->rx_channel = config.ethernets[i].rx_channel;
 
        eth->rtx_type   = config.ethernets[i].rtx_type;
 
 
 
        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 */
            eth->rxfile = config.ethernets[i].rxfile;
 
            eth->txfile = config.ethernets[i].txfile;
 
 
 
            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 = eth->txfd = -1;
Line 585... Line 537...
            }
            }
 
 
            /* get interface index number */
            /* get interface index number */
            debug (3, "RTX getting interface...\n");
            debug (3, "RTX getting interface...\n");
            memset(&(eth->ifr), 0, sizeof(eth->ifr));
            memset(&(eth->ifr), 0, sizeof(eth->ifr));
            strncpy(eth->ifr.ifr_name, config.ethernets[i].sockif, IFNAMSIZ);
            strncpy(eth->ifr.ifr_name, eth->sockif, IFNAMSIZ);
            if (ioctl(eth->rtx_sock, SIOCGIFINDEX, &(eth->ifr)) == -1) {
            if (ioctl(eth->rtx_sock, SIOCGIFINDEX, &(eth->ifr)) == -1) {
                fprintf( stderr, "SIOCGIFINDEX failed!\n");
                fprintf( stderr, "SIOCGIFINDEX failed!\n");
                return;
                return;
            }
            }
            debug (3, "RTX Socket Interface : %d\n", eth->ifr.ifr_ifindex);
            debug (3, "RTX Socket Interface : %d\n", eth->ifr.ifr_ifindex);
Line 620... Line 572...
                    recv(eth->rtx_sock, eth->rx_buff, j, 0);
                    recv(eth->rtx_sock, eth->rx_buff, j, 0);
            } while (j);
            } while (j);
            debug (3, "\n");
            debug (3, "\n");
 
 
            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 */
#endif /* HAVE_ETH_PHY */
        }
        }
 
 
        /* Set registers to default values */
        /* Set registers to default values */
        memset( &(eth->regs), 0, sizeof(eth->regs) );
        memset( &(eth->regs), 0, sizeof(eth->regs) );
Line 640... Line 597...
        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 (config.ethernets[i].base_vapi_id) {
        if (eth->base_vapi_id) {
            eth->base_vapi_id = config.ethernets[i].base_vapi_id;
            vapi_install_multi_handler( eth->base_vapi_id, ETH_NUM_VAPI_IDS, eth_vapi_read, dat );
            vapi_install_multi_handler( eth->base_vapi_id, ETH_NUM_VAPI_IDS, eth_vapi_read, NULL );
 
        }
        }
    }
    }
}
}
/* ========================================================================= */
/* ========================================================================= */
 
 
 
 
/*
/*
  Print register values on stdout
  Print register values on stdout
*/
*/
void eth_status( void )
void eth_status( void *dat )
{
{
    unsigned i;
    struct eth_device *eth = dat;
 
 
    for ( i = 0; i < MAX_ETHERNETS; ++ i ) {
 
        struct eth_device *eth = &(eths[i]);
 
 
 
        if ( eth->baseaddr == 0 )
 
            continue;
 
 
 
        PRINTF( "\nEthernet MAC %u at 0x%"PRIxADDR":\n", i, eth->baseaddr );
    PRINTF( "\nEthernet MAC at 0x%"PRIxADDR":\n", eth->baseaddr );
        PRINTF( "MODER        : 0x%08lX\n", eth->regs.moder );
        PRINTF( "MODER        : 0x%08lX\n", eth->regs.moder );
        PRINTF( "INT_SOURCE   : 0x%08lX\n", eth->regs.int_source );
        PRINTF( "INT_SOURCE   : 0x%08lX\n", eth->regs.int_source );
        PRINTF( "INT_MASK     : 0x%08lX\n", eth->regs.int_mask );
        PRINTF( "INT_MASK     : 0x%08lX\n", eth->regs.int_mask );
        PRINTF( "IPGT         : 0x%08lX\n", eth->regs.ipgt );
        PRINTF( "IPGT         : 0x%08lX\n", eth->regs.ipgt );
        PRINTF( "IPGR1        : 0x%08lX\n", eth->regs.ipgr1 );
        PRINTF( "IPGR1        : 0x%08lX\n", eth->regs.ipgr1 );
Line 685... Line 635...
                eth->mac_address[0], eth->mac_address[1], eth->mac_address[2],
                eth->mac_address[0], eth->mac_address[1], eth->mac_address[2],
                eth->mac_address[3], eth->mac_address[4], eth->mac_address[5] );
                eth->mac_address[3], eth->mac_address[4], eth->mac_address[5] );
        PRINTF( "HASH0        : 0x%08lX\n", eth->regs.hash0 );
        PRINTF( "HASH0        : 0x%08lX\n", eth->regs.hash0 );
        PRINTF( "HASH1        : 0x%08lX\n", eth->regs.hash1 );
        PRINTF( "HASH1        : 0x%08lX\n", eth->regs.hash1 );
    }
    }
}
 
/* ========================================================================= */
 
 
 
 
 
/*
 
  Simulation hook. Must be called every clock cycle to simulate Ethernet MAC.
 
*/
 
void eth_clock()
 
{
 
    unsigned i;
 
 
 
    for ( i = 0; i < config.nethernets; ++ i ) {
 
        eth_controller_tx_clock( &(eths[i]) );
 
        eth_controller_rx_clock( &(eths[i]) );
 
    }
 
}
 
/* ========================================================================= */
/* ========================================================================= */
 
 
 
 
/*
/*
  Read a register
  Read a register
*/
*/
uint32_t eth_read32( oraddr_t addr, void *dat )
uint32_t eth_read32( oraddr_t addr, void *dat )
{
{
    struct eth_device *eth;
    struct eth_device *eth = dat;
    if ( !eth_find_controller( addr, &eth, &addr ) )    {
    addr -= eth->baseaddr;
        PRINTF( "eth_read32( 0x%"PRIxADDR" ): Not in registered range(s)\n", addr );
 
        return 0;
 
    }
 
 
 
    switch( addr ) {
    switch( addr ) {
    case ETH_MODER: return eth->regs.moder;
    case ETH_MODER: return eth->regs.moder;
    case ETH_INT_SOURCE: return eth->regs.int_source;
    case ETH_INT_SOURCE: return eth->regs.int_source;
    case ETH_INT_MASK: return eth->regs.int_mask;
    case ETH_INT_MASK: return eth->regs.int_mask;
Line 759... Line 690...
/*
/*
  Write a register
  Write a register
*/
*/
void eth_write32( oraddr_t addr, uint32_t value, void *dat )
void eth_write32( oraddr_t addr, uint32_t value, void *dat )
{
{
    struct eth_device *eth;
    struct eth_device *eth = dat;
    if ( !eth_find_controller( addr, &eth, &addr ) )    {
 
        PRINTF( "eth_write32( 0x%"PRIxADDR" ): Not in registered range(s)\n", addr );
    addr -= eth->baseaddr;
    return;
 
    }
 
 
 
    switch( addr ) {
    switch( addr ) {
    case ETH_MODER: eth->regs.moder = value; if (TEST_FLAG(value, ETH_MODER, RST)) eth_reset(); return;
    case ETH_MODER:
 
 
 
        if ( !TEST_FLAG( eth->regs.moder, ETH_MODER, RXEN) &&
 
             TEST_FLAG( value, ETH_MODER, RXEN) )
 
            SCHED_ADD( eth_controller_rx_clock, dat, runtime.sim.cycles + 1 );
 
        else if ( !TEST_FLAG( value, ETH_MODER, RXEN) )
 
            SCHED_FIND_REMOVE( eth_controller_rx_clock, dat);
 
 
 
        if ( !TEST_FLAG( eth->regs.moder, ETH_MODER, TXEN) &&
 
             TEST_FLAG( value, ETH_MODER, TXEN) )
 
            SCHED_ADD( eth_controller_tx_clock, dat, runtime.sim.cycles + 1 );
 
        else if ( !TEST_FLAG( value, ETH_MODER, TXEN) )
 
            SCHED_FIND_REMOVE( eth_controller_tx_clock, dat);
 
 
 
        eth->regs.moder = value;
 
 
 
        if (TEST_FLAG(value, ETH_MODER, RST))
 
            eth_reset( dat );
 
        return;
    case ETH_INT_SOURCE: eth->regs.int_source &= ~value; return;
    case ETH_INT_SOURCE: eth->regs.int_source &= ~value; return;
    case ETH_INT_MASK: eth->regs.int_mask = value; return;
    case ETH_INT_MASK: eth->regs.int_mask = value; return;
    case ETH_IPGT: eth->regs.ipgt = value; return;
    case ETH_IPGT: eth->regs.ipgt = value; return;
    case ETH_IPGR1: eth->regs.ipgr1 = value; return;
    case ETH_IPGR1: eth->regs.ipgr1 = value; return;
    case ETH_IPGR2: eth->regs.ipgr2 = value; return;
    case ETH_IPGR2: eth->regs.ipgr2 = value; return;
Line 817... Line 764...
 *   VAPI connection to outside
 *   VAPI connection to outside
 */
 */
static void eth_vapi_read (unsigned long id, unsigned long data, void *dat)
static void eth_vapi_read (unsigned long id, unsigned long data, void *dat)
{
{
    unsigned long which;
    unsigned long which;
    struct eth_device *eth = eth_find_vapi_device( id, &which );
    struct eth_device *eth = dat;
 
 
 
    which = id - eth->base_vapi_id;
 
 
    debug( 5, "ETH: id %08lx, data %08lx\n", id, data );
    debug( 5, "ETH: id %08lx, data %08lx\n", id, data );
 
 
    if ( !eth ) {
    if ( !eth ) {
        debug( 1, "ETH: VAPI ID %08lx is not ours!\n", id );
        debug( 1, "ETH: VAPI ID %08lx is not ours!\n", id );
Line 842... Line 791...
void eth_write_tx_bd_num( struct eth_device *eth, unsigned long value )
void eth_write_tx_bd_num( struct eth_device *eth, unsigned long value )
{
{
    eth->regs.tx_bd_num = value & 0xFF;
    eth->regs.tx_bd_num = value & 0xFF;
    eth->rx.bd_index = eth->regs.tx_bd_num << 1;
    eth->rx.bd_index = eth->regs.tx_bd_num << 1;
}
}
/* ========================================================================= */
 
 
 
 
/* ========================================================================= */
 
 
/*
/*-----------------------------------------------[ Ethernet configuration ]---*/
  Convert a memory address to a oontroller struct and relative address.
void eth_baseaddr(union param_val val, void *dat)
  Return nonzero on success
 
*/
 
int eth_find_controller( oraddr_t addr, struct eth_device **eth, oraddr_t *reladdr )
 
{
{
    unsigned i;
  struct eth_device *eth = dat;
    *eth = NULL;
  eth->baseaddr = val.addr_val;
 
 
    for ( i = 0; i < MAX_ETHERNETS && *eth == NULL; ++ i ) {
 
        if ( (addr >= eths[i].baseaddr) && (addr < eths[i].baseaddr + ETH_ADDR_SPACE) )
 
            *eth = &(eths[i]);
 
        }
        }
 
 
    /* verify we found a controller */
void eth_dma(union param_val val, void *dat)
    if ( *eth == NULL )
{
        return 0;
  struct eth_device *eth = dat;
 
  eth->dma = val.addr_val;
    /* Verify legal address */
 
    if ( (addr - (*eth)->baseaddr) % 4 != 0 )
 
        return 0;
 
 
 
    *reladdr = addr - (*eth)->baseaddr;
 
    return 1;
 
}
}
 
 
/*
void eth_rtx_type(union param_val val, void *dat)
 * Convert VAPI id to controller struct and relative address.
 
 */
 
struct eth_device *eth_find_vapi_device( unsigned long id, unsigned long *which )
 
{
{
    unsigned i;
  struct eth_device *eth = dat;
 
  eth->rtx_type = val.int_val;
    for ( i=0; i<config.nethernets; i++) {
 
        if ( (id>=eths[i].base_vapi_id) && (id < eths[i].base_vapi_id + ETH_NUM_VAPI_IDS)) {
 
            *which = id - eths[i].base_vapi_id;
 
            return &(eths[i]);
 
        }
 
    }
    }
 
 
    return NULL;
void eth_rx_channel(union param_val val, void *dat)
 
{
 
  struct eth_device *eth = dat;
 
  eth->rx_channel = val.int_val;
}
}
 
 
/*-----------------------------------------------[ Ethernet configuration ]---*/
void eth_tx_channel(union param_val val, void *dat)
void eth_nethernets (union param_val val, void *dat) {
{
  if (val.int_val >= 0 && val.int_val < MAX_ETHERNETS)
  struct eth_device *eth = dat;
    config.nethernets = val.int_val;
  eth->tx_channel = val.int_val;
  else
 
    CONFIG_ERROR("invalid number of devices.");
 
}
}
 
 
void eth_baseaddr (union param_val val, void *dat) {
void eth_rxfile(union param_val val, void *dat)
  if (current_device >= 0 && current_device < config.nethernets)
{
    config.ethernets[current_device].baseaddr = val.addr_val;
  struct eth_device *eth = dat;
  else
  if(!(eth->rxfile = strdup(val.str_val))) {
    CONFIG_ERROR("invalid device number.");
    fprintf(stderr, "Peripheral Ethernet: Run out of memory\n");
 
    exit(-1);
}
}
 
 
void eth_dma (union param_val val, void *dat) {
 
  if (current_device >= 0 && current_device < config.nethernets)
 
    config.ethernets[current_device].dma = val.int_val;
 
  else
 
    CONFIG_ERROR("invalid device number.");
 
}
}
 
 
void eth_rtx_type (union param_val val, void *dat) {
void eth_txfile(union param_val val, void *dat)
  if (current_device >= 0 && current_device < config.nethernets)
{
    config.ethernets[current_device].rtx_type = val.int_val;
  struct eth_device *eth = dat;
  else
  if(!(eth->txfile = strdup(val.str_val))) {
    CONFIG_ERROR("invalid device number.");
    fprintf(stderr, "Peripheral Ethernet: Run out of memory\n");
 
    exit(-1);
}
}
 
 
void eth_rx_channel (union param_val val, void *dat) {
 
  if (current_device >= 0 && current_device < config.nethernets)
 
    config.ethernets[current_device].rx_channel = val.int_val;
 
  else
 
    CONFIG_ERROR("invalid device number.");
 
}
}
 
 
void eth_tx_channel (union param_val val, void *dat) {
void eth_sockif(union param_val val, void *dat)
  if (current_device >= 0 && current_device < config.nethernets)
{
    config.ethernets[current_device].rx_channel = val.int_val;
  struct eth_device *eth = dat;
  else
  if(!(eth->sockif = strdup(val.str_val))) {
    CONFIG_ERROR("invalid device number.");
    fprintf(stderr, "Peripheral Ethernet: Run out of memory\n");
 
    exit(-1);
}
}
 
 
void eth_rxfile (union param_val val, void *dat) {
 
  if (current_device >= 0 && current_device < config.nethernets)
 
    strcpy (config.ethernets[current_device].rxfile, val.str_val);
 
  else
 
    CONFIG_ERROR("invalid device number.");
 
}
}
 
 
void eth_txfile(union param_val val, void *dat)
void eth_irq(union param_val val, void *dat)
{
{
  if (current_device >= 0 && current_device < config.nethernets)
  struct eth_device *eth = dat;
    strcpy (config.ethernets[current_device].txfile, val.str_val);
  eth->mac_int = val.int_val;
  else
 
    CONFIG_ERROR("invalid device number.");
 
}
}
 
 
void eth_sockif(union param_val val, void *dat)
void eth_vapi_id(union param_val val, void *dat)
{
{
  if (current_device >= 0 && current_device < config.nethernets)
  struct eth_device *eth = dat;
    strcpy (config.ethernets[current_device].sockif, val.str_val);
  eth->base_vapi_id = val.int_val;
  else
 
    CONFIG_ERROR("invalid device number.");
 
}
}
 
 
void eth_irq(union param_val val, void *dat)
void *eth_sec_start(void)
{
{
  if (current_device >= 0 && current_device < config.nethernets)
  struct eth_device *new = malloc(sizeof(struct eth_device));
    config.ethernets[current_device].irq = val.int_val;
 
  else
  if(!new) {
    CONFIG_ERROR("invalid device number.");
    fprintf(stderr, "Peripheral Eth: Run out of memory\n");
 
    exit(-1);
}
}
 
 
void eth_vapi_id(union param_val val, void *dat)
  return new;
 
}
 
 
 
void eth_sec_end(void *dat)
{
{
  if (current_device >= 0 && current_device < config.nethernets)
  struct eth_device *eth = dat;
    config.ethernets[current_device].base_vapi_id = val.int_val;
 
  else
  register_memoryarea( eth->baseaddr, ETH_ADDR_SPACE, 4, 0, eth_read32, eth_write32, dat );
    CONFIG_ERROR("invalid device number.");
  reg_sim_stat( eth_status, dat );
 
  reg_sim_reset( eth_reset, dat );
}
}
 
 
void reg_ethernet_sec(void)
void reg_ethernet_sec(void)
{
{
  struct config_section *sec = reg_config_sec("ethernet", NULL, NULL);
  struct config_section *sec = reg_config_sec("ethernet", eth_sec_start, eth_sec_end);
 
 
  reg_config_param(sec, "nethernets", paramt_int, eth_nethernets);
 
  reg_config_param(sec, "device", paramt_int, change_device);
 
  reg_config_param(sec, "irq", paramt_int, eth_irq);
  reg_config_param(sec, "irq", paramt_int, eth_irq);
  reg_config_param(sec, "enddevice", paramt_int, end_device);
 
  reg_config_param(sec, "baseaddr", paramt_int, eth_baseaddr);
  reg_config_param(sec, "baseaddr", paramt_int, eth_baseaddr);
  reg_config_param(sec, "dma", paramt_int, eth_dma);
  reg_config_param(sec, "dma", paramt_int, eth_dma);
  reg_config_param(sec, "rtx_type", paramt_int, eth_rtx_type);
  reg_config_param(sec, "rtx_type", paramt_int, 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);

powered by: WebSVN 2.1.0

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