⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mac_au1000.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
#define MAC_RECEIVE_WT_MASK	(1 << MAC_RECEIVE_WT)
#define MAC_RECEIVE_L_MASK	(0x3fff << MAC_RECEIVE_L)

/************************************************************************
 *      Public variables
 ************************************************************************/

/************************************************************************
 *      Static variables
 ************************************************************************/
static UINT32 poll_count = 0 ;
static char msg[160] ;

/* Global driver state */
static UINT32 MAC_AU1000_state = MAC_AU1000_DRIVER_IS_STOPPED ;

/* MAC broadcast address */
static t_mac_addr mac_broadcast_adr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } ;

/* User registered receive handler */
static UINT32 (*usr_receive)( UINT32 length, UINT8 *data ) = NULL ;

/* Device context per minor device for this driver */
static t_MAC_AU1000_device   minor_device[MAC_MINOR_AU1000_DEVICES] ;

/* Dynamic allocated memory */
static void *lan_dma_buffers  = NULL ;

/************************************************************************
 *      Static function prototypes, local helper functions
 ************************************************************************/

static void MAC_AU1000_wait( UINT32 millisec ) ;
static INT32 MAC_AU1000_allocate_buffers( t_MAC_AU1000_device *pdevice ) ; 
static INT32 MAC_AU1000_stop( t_MAC_AU1000_device *pdevice ) ;            
static INT32 MAC_AU1000_MII_init( t_MAC_AU1000_device *pdevice ) ;        
static INT32 MAC_AU1000_MII_status( t_MAC_AU1000_device *pdevice ) ;        
static INT32 MAC_AU1000_control_init( t_MAC_AU1000_device *pdevice ) ;
static INT32 MAC_AU1000_DMA_init( t_MAC_AU1000_device *pdevice ) ;        
static INT32 MAC_AU1000_dump_regs( t_MAC_AU1000_device *pdevice ) ;
static INT32 MAC_AU1000_dump_status( t_MAC_AU1000_device *pdevice ) ;
void	bosporus_init_switch();

/************************************************************************
 *      Static function prototypes, device driver IO functions
 ************************************************************************/

static
INT32 MAC_AU1000_init(
          UINT32 major,          /* IN: major device number             */
          UINT32 minor,          /* IN: minor device number             */
          void   *p_param ) ;    /* INOUT: device parameter block       */

static
INT32 MAC_AU1000_open(
          UINT32 major,          /* IN: major device number             */
          UINT32 minor,          /* IN: minor device number             */
          t_LAN_OPEN_desc *p_param ) ; /* IN: receive handler reference */

static
INT32 MAC_AU1000_read(
          UINT32 major,          /* IN: major device number             */
          UINT32 minor,          /* IN: minor device number             */
          t_LAN_IO_desc *p_param ) ; /* INOUT: LAN frame           */

static
INT32 MAC_AU1000_write(
          UINT32 major,          /* IN: major device number             */
          UINT32 minor,          /* IN: minor device number             */
          t_LAN_IO_desc *p_param ) ; /* OUT: frame to transmit     */

static
INT32 MAC_AU1000_ctrl(
          UINT32 major,          /* IN: major device number             */
          UINT32 minor,          /* IN: minor device number             */
          t_LAN_CTRL_desc *p_param ) ; /* IN-OUT:                       */


/************************************************************************
 *      Implementation : Public functions
 ************************************************************************/


/************************************************************************
 *
 *                          MAC_AU1000_install
 *  Description :
 *  -------------
 *
 *  Installs the AU1000 LAN device drivers services in 
 *  the IO system at the reserved device slot, found in the
 *  'sysdev.h' file, which defines all major device numbers.
 *
 *  Note:
 *  This service is the only public declared interface function; all
 *  provided device driver services are static declared, but this
 *  function installs the function pointers in the io-system to
 *  enable the provided public driver services.
 *
 *  Parameters :
 *  ------------
 *
 *  -
 *
 *
 *  Return values :
 *  ---------------
 *
 *  'OK'(=0)
 *  'ERROR_IO_ILLEGAL_MAJOR':  Illegal major device number
 *  'ERROR_IO_NO_SPACE':       Device slot already allocated
 *
 ************************************************************************/
INT32 MAC_AU1000_install( void )
{


	
	
    /* pre-initialize local variables and install device services */
    memset( minor_device, sizeof(minor_device), 0) ;
    return( IO_install(   SYS_MAJOR_MAC_AU1000, /* major device number */
           (t_io_service) MAC_AU1000_init,      /* 'init'  service     */
           (t_io_service) MAC_AU1000_open,      /* 'open'  service     */
                          NULL,                  /* 'close' service  na */
           (t_io_service) MAC_AU1000_read,      /* 'read'  service     */
           (t_io_service) MAC_AU1000_write,     /* 'write' service     */
           (t_io_service) MAC_AU1000_ctrl ) ) ; /* 'ctrl'  service     */
}


/************************************************************************
 *      Implementation : Static functions
 ************************************************************************/


/************************************************************************
 *      Implementation : Local helper functions
 ************************************************************************/


/************************************************************************
 *
 *                         MAC_AU1000_wait 
 *  Description :
 *  -------------
 * 
 *  Wait specified number of milliseconds.
 * 
 *
 *  Parameters :
 *  ------------
 *
 *  millisec                            Number of milliseconds to wait
 *
 *  Return values :
 *  ---------------
 *
 *  -
 *
 ************************************************************************/
static
void MAC_AU1000_wait( UINT32 millisec )
{
	UINT32 rc, first, latest, previous, accumulate ;
	
	accumulate = 0 ;
	
	/* get millisecond count */
	
	rc = SYSCON_read( SYSCON_BOARD_GET_MILLISEC_ID,
		&first,
		sizeof(first) ) ;
	
	previous = first ;
	
	while ( 1 )
	{
		/* get millisecond count */
		rc = SYSCON_read( SYSCON_BOARD_GET_MILLISEC_ID,
			&latest,
			sizeof(latest) ) ;
		if ( latest >= previous )
		{
			/* counter still not wrapped */
			if ( (accumulate + (latest - first)) > millisec )
			{
				break ;
			}
		}
		else
		{
			/* counter did wrap */
			accumulate = accumulate + (previous - first) ;
			if ( (accumulate + latest) > millisec )
			{
				break ;
			}
			
			/* reset first */
			first = 0 ;
		}

		/* prepare next delta time */
		previous = latest ;
	}
}


/************************************************************************
 *
 *                          MAC_AU1000_allocate_buffers
 *  Description :
 *  -------------
 *     This routine allocates memory for:
 *
 *     - Receive buffers
 *     - Transmit buffer
 *  
 *
 *  Parameters :
 *  ------------
 *
 *  'pdevice',     IN,    reference for this device  context
 *
 *
 *  Return values :
 *  ---------------
 *
 *  'OK'(=0)
 *
 *
 *
 ************************************************************************/
static
INT32 MAC_AU1000_allocate_buffers( t_MAC_AU1000_device *pdevice )  
{
    INT32				 rcode ;
    t_sys_malloc		 mem ;
    void				 *Pa;
    UINT32				 i, j ;

    if(lan_dma_buffers == NULL)
    {	
        /* allocate all RX and TX packets in one chunk on a 2K boundary. */
        mem.size= MAC_AU1000_PACKET_SIZE * MAC_AU1000_TX_BUFFERS
                            + MAC_AU1000_PACKET_SIZE * MAC_AU1000_RX_BUFFERS;
        mem.boundary = MAC_AU1000_PACKET_SIZE;
        mem.memory	 = &Pa;

        /* request RX and TX memory in one chunk */
        rcode = SYSCON_read( SYSCON_BOARD_MALLOC_ID,
                            &mem,
                            sizeof(t_sys_malloc) ) ;
        if (rcode != OK)
        {
                return( rcode ) ;
        }

        /* cache this reference */
        lan_dma_buffers = Pa ;
    }
    else
    {
        /* not first time */
        Pa = lan_dma_buffers;
    }
    
    /* Initialize buffer space */
    mem.size = MAC_AU1000_PACKET_SIZE * MAC_AU1000_TX_BUFFERS
                + MAC_AU1000_PACKET_SIZE * MAC_AU1000_RX_BUFFERS;
    
    Pa = (void*) KSEG1((UINT32)Pa);
    memset( Pa, 0, mem.size );

    /* Init RX buffer pointers */
    for ( i=0; i < MAC_AU1000_RX_BUFFERS; i++ )
    {
        pdevice->RcvBuffer[i] = PHYS((UINT32) Pa);
        Pa += MAC_AU1000_PACKET_SIZE ;
    }

    /* Init TX buffer pointers */
    for ( i=0; i < MAC_AU1000_TX_BUFFERS; i++ )
    {
        pdevice->TxmBuffer[i] = PHYS((UINT32) Pa);
        Pa += MAC_AU1000_PACKET_SIZE ;
    }

    return( OK );
}


/************************************************************************
 *
 *                          MAC_AU1000_stop
 *  Description :
 *  -------------
 *   This routine stops the AU1000 LAN controller
 *   by stoping  DMA transfer and resetting the chip.
 *  
 *
 *  Parameters :
 *  ------------
 *
 *  'pdevice',     IN,    reference for this device  context
 *
 *
 *  Return values :
 *  ---------------
 *
 *  'OK'(=0)
 *
 *
 *
 ************************************************************************/
static
INT32 MAC_AU1000_stop( t_MAC_AU1000_device *pdevice )			   
{
	int i;

	/* Clear active low Reset Bits and set DMA RESET (active high) */
	MACREG( pdevice->pAU1000EnReg, MAC_ENABLE ) = SET(MAC_ENABLE_DMARESET);
	
	/* Clear Enable for Tx DMA */

	for (i=0; i< MAC_AU1000_TX_BUFFERS ; i++) {
		
		MACREG( pdevice->pAU1000DMARegs, 
			SETV(DMA_TRANSMIT, MAC_DMA_TXRX) |	
			SETV(i,MAC_DMA_BUF)	|				/* i selects buffer to disable */
			SETV(DMA_ADDRESS_EN ,MAC_DMA_REG)  )
			= 0 /*&= MAC_DMA_DISABLE_MASK*/;
	}

	/* Clear Enable for Rx DMA */

	for (i=0; i< MAC_AU1000_RX_BUFFERS ; i++) {
		
		MACREG( pdevice->pAU1000DMARegs, 
			SETV(DMA_RECEIVE , MAC_DMA_TXRX) |		
			SETV(i,MAC_DMA_BUF)  |				/* i selects buffer to disable */
			SETV(DMA_ADDRESS_EN ,MAC_DMA_REG)  )				
			= 0 /*&= MAC_DMA_DISABLE_MASK*/;
	}

	MAC_AU1000_state = MAC_AU1000_DRIVER_IS_STOPPED;

	return( OK );
}



/************************************************************************
 *
 *                          MAC_AU1000_MII_init
 *  Description :
 *  -------------
 *    Initialize physical device
 *  
 *
 *  Parameters :
 *  ------------
 *
 *  'pdevice',     IN,    reference for this device  context
 *
 *
 *  Return values :
 *  ---------------
 *

 *  'OK'(=0)
 *
 *
 *
 ************************************************************************/
static MAC_MII_WRITE(
					t_MAC_AU1000_device *pdevice,
					int reg, int val
					)
{
	/* check link status, spin here till done */
	while ( MACREG( pdevice->pAU1000CtrlRegs, MAC_MIICTRL) 
					& MAC_MIICTRL_MBUSY_MASK) ;

	MACREG(pdevice->pAU1000CtrlRegs, MAC_MIIDATA) = val;
	MACREG(pdevice->pAU1000CtrlRegs, MAC_MIICTRL) = (reg << 6) | 0x02;

	/* check link status, spin here till done */
	while ( MACREG( pdevice->pAU1000CtrlRegs, MAC_MIICTRL) 
					& MAC_MIICTRL_MBUSY_MASK) ;
}

static int MAC_MII_READ(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -