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

📄 rtlcpp.c

📁 MPC8241:本程序是freescale的824*系列的BSP源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif /*SYS_OUT_SHORT_CSR*/

#ifndef	SYS_IN_SHORT_CSR
#define	SYS_IN_SHORT_CSR(pDrvCtrl,addr,pData) \
    (*(USHORT *)pData =	*(USHORT *)addr)
#endif /*SYS_IN_SHORT_CSR*/


#define	SYS_DELAY(count)	{						\
			volatile int cx	= 0;				\
			for (cx	= 0; cx	< (count); cx++);		\
			}

#ifndef	SYS_ENET_ADDR_GET
#define	SYS_ENET_ADDR_GET(pDrvCtrl, pAddress) \
    { \
    IMPORT STATUS sysRtl81x9EnetAddrGet	(RTL81X9END_DEVICE *pDrvCtrl, \
				     char * enetAdrs); \
    sysRtl81x9EnetAddrGet (pDrvCtrl, pAddress);	\
    }
#endif /* SYS_ENET_ADDR_GET */


/* Cache macros	*/

#define	RTL_CACHE_INVALIDATE(address, len) \
	CACHE_DRV_INVALIDATE (&pDrvCtrl->cacheFuncs, (address),	(len))

#define	RTL_CACHE_VIRT_TO_PHYS(address)	\
	CACHE_DRV_VIRT_TO_PHYS (&pDrvCtrl->cacheFuncs, (address))


/*
 * MII access routines are provided for	the 8129, which
 * doesn't have	a built-in PHY.	For the	8139, we fake things
 * up by diverting rl_phy_readreg()/rl_phy_writereg() to the
 * direct access PHY registers.
 */

#define	MII_SET(x)					\
	rtl81x9CsrWriteByte (pDrvCtrl, RTL_REGS_MII,				\
		rtl81x9CsrReadByte(pDrvCtrl, RTL_REGS_MII, RTL_WIN_0) |	x, RTL_WIN_0 )

#define	MII_CLR(x)					\
	rtl81x9CsrWriteByte (pDrvCtrl, RTL_REGS_MII,				\
		rtl81x9CsrReadByte(pDrvCtrl, RTL_REGS_MII, RTL_WIN_0) &	~x, RTL_WIN_0 )

/* EEPROM Macros */

#define	EE_SET(x)					\
	rtl81x9CsrWriteByte (pDrvCtrl, RTL_REGS_CFG_9346,			\
		rtl81x9CsrReadByte(pDrvCtrl, RTL_REGS_CFG_9346,	RTL_WIN_0) | x,	RTL_WIN_0)

#define	EE_CLR(x)					\
	rtl81x9CsrWriteByte(pDrvCtrl, RTL_REGS_CFG_9346,			\
		rtl81x9CsrReadByte(pDrvCtrl, RTL_REGS_CFG_9346,	RTL_WIN_0) & ~x, RTL_WIN_0)



/***** LOCALS *****/

LOCAL int rtlRsize = RTL_RMD_RLEN;    /* recv ring size	*/
LOCAL int rtlTsize = RTL_TMD_RLEN;    /* tx ring size */

/* forward static functions */

LOCAL STATUS	rtl81x9Reset ();
LOCAL void	    rtl81x9Int			(RTL81X9END_DEVICE *);
LOCAL void		rtl81x9HandleRecvInt(RTL81X9END_DEVICE *);
/* LOCAL void		rtl81x9HandleTxInt	(RTL81X9END_DEVICE *);
LOCAL void		rtl81x9Restart		(RTL81X9END_DEVICE *); */
LOCAL STATUS	rtl81x9RestartSetup (RTL81X9END_DEVICE *);
LOCAL void		rtl81x9Config		(RTL81X9END_DEVICE *);
LOCAL void		rtl81x9AddrFilterSet(RTL81X9END_DEVICE *);
				
/* END Specific	interfaces. */


/******kongfq2005.8.29********/
LOCAL STATUS    rtl81x9Send_byCallFT (RTL81X9END_DEVICE *pDrvCtrl,UCHAR *pInBuf, int iLength);
/* This	is the only externally visible interface. */

END_OBJ	*		rtlcpEndLoad (char *initString);

LOCAL STATUS	rtl81x9Start		(RTL81X9END_DEVICE *);
LOCAL STATUS	rtl81x9Stop		(RTL81X9END_DEVICE *);
LOCAL STATUS	rtl81x9Unload		(RTL81X9END_DEVICE *);
LOCAL int		rtl81x9Ioctl		(RTL81X9END_DEVICE *, int, caddr_t);
LOCAL STATUS	rtl81x9Send		(RTL81X9END_DEVICE *, M_BLK *);
LOCAL STATUS	rtl81x9MCastAddrAdd (RTL81X9END_DEVICE *, char *);
LOCAL STATUS	rtl81x9MCastAddrDel (RTL81X9END_DEVICE *, char *);
LOCAL STATUS	rtl81x9MCastAddrGet (RTL81X9END_DEVICE *, MULTI_TABLE *);
LOCAL STATUS	rtl81x9PollSend		(RTL81X9END_DEVICE *, M_BLK *);
LOCAL STATUS	rtl81x9PollReceive	(RTL81X9END_DEVICE *, M_BLK *);
LOCAL STATUS	rtl81x9PollStart	(RTL81X9END_DEVICE *); 
LOCAL STATUS	rtl81x9PollStop		(RTL81X9END_DEVICE *);
LOCAL STATUS	rtl81x9InitParse	(RTL81X9END_DEVICE *, char *);
LOCAL STATUS	rtl81x9InitMem		(RTL81X9END_DEVICE *);


LOCAL void		rtl81x9LowPowerMode (RTL81X9END_DEVICE *);
LOCAL UCHAR		rtl81x9CsrReadByte  (RTL81X9END_DEVICE *, USHORT, int);
LOCAL USHORT	rtl81x9CsrReadWord  (RTL81X9END_DEVICE *, USHORT, int);
LOCAL ULONG		rtl81x9CsrReadLong  (RTL81X9END_DEVICE *, USHORT, int);
LOCAL void		rtl81x9CsrWriteByte (RTL81X9END_DEVICE *, USHORT, UCHAR, int);
LOCAL void		rtl81x9CsrWriteWord (RTL81X9END_DEVICE *, USHORT, USHORT, int);
LOCAL void		rtl81x9CsrWriteLong (RTL81X9END_DEVICE *, USHORT, ULONG, int);
      void		rtl81x9ReadEEPROM	(RTL81X9END_DEVICE *, UCHAR *, ULONG, ULONG, ULONG);
LOCAL void		rtl81x9EEPROMPutByte(RTL81X9END_DEVICE *, ULONG);
LOCAL void		rtl81x9EEPROMGetWord(RTL81X9END_DEVICE *, ULONG, USHORT*);
      void		rtl81x9WriteEEPROM	(RTL81X9END_DEVICE *, UCHAR *, ULONG, ULONG, ULONG);
LOCAL void		rtl81x9EEPROMSetByte(RTL81X9END_DEVICE *, ULONG);

LOCAL void		rtl81x9EEPROMSetWord(RTL81X9END_DEVICE *, ULONG, USHORT*);
LOCAL void		rtl81x9WriteENABLE(RTL81X9END_DEVICE * );

LOCAL void		rtl81x9Phy_writereg (RTL81X9END_DEVICE *, int, int);
LOCAL USHORT	rtl81x9Phy_readreg	(RTL81X9END_DEVICE *, int);
LOCAL int		rtl81x9MII_writereg (RTL81X9END_DEVICE *, RTL_MII_FRAME	*);
LOCAL void		rtl81x9MII_sync		(RTL81X9END_DEVICE *);
LOCAL void		rtl81x9MII_send		(RTL81X9END_DEVICE *, ULONG, int);
LOCAL int		rtl81x9MII_readreg  (RTL81X9END_DEVICE *, RTL_MII_FRAME	*);
LOCAL void		rtl81x9AutoNegTx	(RTL81X9END_DEVICE *);
LOCAL int		rtl81x9MII_autoneg	(RTL81X9END_DEVICE *);
LOCAL int		rtl81x9MediaSet		(RTL81X9END_DEVICE *, int);
LOCAL int		rtl81x9MediaConfig	(RTL81X9END_DEVICE *);

/* 
 * Define the device function table.  This is static across all	driver
 * instances.
 */

LOCAL NET_FUNCS	rtlFuncTable = 
  {
  (FUNCPTR)rtl81x9Start,		/* start func. */		  
  (FUNCPTR)rtl81x9Stop,			/* stop	func. */
  (FUNCPTR)rtl81x9Unload,		/* unload func.	*/		  
  (FUNCPTR)rtl81x9Ioctl,		/* ioctl func. */		  
  (FUNCPTR)rtl81x9Send,			/* send	func. */		  
  (FUNCPTR)rtl81x9MCastAddrAdd,	/* multicast add func. */	  
  (FUNCPTR)rtl81x9MCastAddrDel,	/* multicast delete func. */	  
  (FUNCPTR)rtl81x9MCastAddrGet,	/* multicast get fun. */	  
  (FUNCPTR)rtl81x9PollSend,		/* polling send	func. */	  
  (FUNCPTR)rtl81x9PollReceive,	/* polling receive func. */	  
  endEtherAddressForm,			/* put address info into a NET_BUFFER */
  endEtherPacketDataGet,		/* get pointer to data in NET_BUFFER */
  endEtherPacketAddrGet			/* Get packet addresses. */
  };				

unsigned long g_ul8139ClusterNum =200; /* 8139 cluster数目:add by zoutl 2003-3-31 21:17 */

/*******************************************************************************
*
* rtl81x9EndLoad - initialize the driver and device
*
* This routine initializes the driver and the device to	the operational	state.
* All of the device-specific parameters	are passed in <initString>, which
* expects a string of the following format:
*
* <unit>:<CSR_reg_addr>:<RAP_reg_addr>:<int_vector>:<int_level>:<shmem_addr>:
* <shmem_size>:<shmem_width>
*
* This routine can be called in	two modes. If it is called with	an empty but
* allocated string, it places the name of this device (that is,	"rtl") into 
* the <initString> and returns 0.
*
* If the string	is allocated and not empty, the	routine	attempts to load
* the driver using the values specified	in the string.
*
* RETURNS: An END object pointer, or NULL on error, or 0 and the name of the
* device if the	<initString> was NULL.
*/

END_OBJ* rtlcpEndLoad
    (
    char* initString		/* string to be	parse by the driver */
    )
    {
    RTL81X9END_DEVICE	*pDrvCtrl;
	USHORT				rtl_dev_id = 0;
    int					speed;
	int					i;

/*****************kongfq**************/
/*
    logMsg("Loading rtlcp...\n", 1, 2, 3, 4, 5, 6);
    logMsg("initString is : %s",initString,2,3,4,5,6);
*/
    if (initString == NULL)
	return (NULL);
    
    if (initString[0] == NULL)
	{
	bcopy((char *)RTL_DEV_NAME, initString,	RTL_DEV_NAME_LEN);
	return (0);
	}
    
    /* allocate	the device structure */

    pDrvCtrl = (RTL81X9END_DEVICE *)calloc (sizeof (RTL81X9END_DEVICE),	1);


    pgDrvCtrl = (RTL81X9END_DEVICE *)calloc (sizeof (RTL81X9END_DEVICE), 1);/* add	by liuliping 200-6-22 */

    if (pDrvCtrl == NULL)
		goto errorExit;
	memset(pDrvCtrl,0,sizeof (RTL81X9END_DEVICE)); /* add	by zou for test	2003-4-21 15:27 */	

    
    /* parse the init string, filling in the device structure */

    if (rtl81x9InitParse (pDrvCtrl, initString)	== ERROR)
		goto errorExit;


	/* Reset the adaptor */
	rtl81x9Reset (pDrvCtrl);

	/* Read	the station address */
	for (i=0; i < 6; i++)
		{
		pDrvCtrl->enetAddr[i] =	rtl81x9CsrReadByte (pDrvCtrl, RTL_REGS_IDR0 + i, RTL_WIN_0);
		}
				
	/*
	 * Now read the	exact device type from the EEPROM to find
	 * out if it's an 8129 or 8139.
	 */
	 rtl81x9ReadEEPROM (pDrvCtrl, (UCHAR *)	&rtl_dev_id, RTL_EE_PCI_DID, 1,	0);


    /* Perform memory allocation */

    if (rtl81x9InitMem (pDrvCtrl) == ERROR)
		goto errorExit;

    rtl_dev_id = RTL_DEVICEID_8139;
    
	if (rtl_dev_id == RTL_DEVICEID_8139 )
	{
	if ((rtl81x9CsrReadLong	(pDrvCtrl, RTL_REGS_TX_CONFIG, NONE) & RTL_TXCG_BLID))
			pDrvCtrl->devType = RTL_DEV_8139A;
		else
			pDrvCtrl->devType = RTL_DEV_8139B;
		}
	else if	(rtl_dev_id == RTL_DEVICEID_8129)
		pDrvCtrl->devType = RTL_DEV_8129;
	else {
	DRV_LOG	(DRV_DEBUG_LOAD, "rtl: unknown device ID: %x\n", rtl_dev_id, 2,	3, 4, 5, 6);
		goto errorExit;
	}
	
    speed =  rtl81x9MediaConfig	(pDrvCtrl);

	/*pDrvCtrl->nextDesc = 0;*/
	/*pDrvCtrl->freeDesc = RTL_NUM_TX_DESC;*/

/*	for (i=0; i < RTL_NUM_TX_DESC; i++)
		pDrvCtrl->pDescMem[i] =	NULL; */


    /* Perform memory distribution and reset and reconfigure the device	*/


    if (rtl81x9RestartSetup (pDrvCtrl) == ERROR)
	goto errorExit;


    /* initialize the END and MIB2 parts of the	structure */

   if (END_OBJ_INIT (&pDrvCtrl->end, (DEV_OBJ *)pDrvCtrl, RTL_DEV_NAME,
		    pDrvCtrl->unit, &rtlFuncTable,
		      "RTL 81x9	Fast Ethernet Enhanced Network Driver")	== ERROR
     ||	END_MIB_INIT (&pDrvCtrl->end, M2_ifType_ethernet_csmacd,
		      &pDrvCtrl->enetAddr[0], 6, ETHERMTU,
		      speed)
		    == ERROR)
		goto errorExit;


    /* set the flags to	indicate readiness */

    END_OBJ_READY (&pDrvCtrl->end,
		    IFF_UP | IFF_RUNNING | IFF_NOTRAILERS | IFF_BROADCAST
		    | IFF_MULTICAST | IFF_SIMPLEX);

    DRV_LOG (DRV_DEBUG_ALL, "Done loading rtl...\n", 1,	2, 3, 4, 5, 6);
    
    pgDrvCtrl = pDrvCtrl; /*add by liuliping 2005-6-22 */

    return (&pDrvCtrl->end);

errorExit:
    if (pDrvCtrl != NULL)
		free ((char *)pDrvCtrl);

    return NULL;
    }



/*******************************************************************************
*
* rtl81x9InitParse - parse parameter values from initString
*
* Parse	the input string.  Fill	in values in the driver	control	structure.
*
* The initialization string format is:
* "<device addr>:<PCI addr>:<ivec>:<ilevel>:<mem base>:<mem size>:	\
*  <user flags>:<offset>"
*
* .IP <device addr>
* base address of hardware device registers
* .IP <PCI addr>
* main memory address over the PCI bus
* .IP <ivec>
* interrupt vector number
* .IP <ilevel>
* interrupt level
* .IP <mem base>
* base address of a DMA-able, cache free,pre-allocated	memory
* .IP <mem size>
* size of the pre-allocated memory
* .IP <user flags>
* User flags control the run-time characteristics of the chip
* .IP <offset>
* Memory offset	for alignment
* .LP
*
* RETURNS: OK or ERROR for invalid arguments.
*/

LOCAL STATUS rtl81x9InitParse
    (
    RTL81X9END_DEVICE *	pDrvCtrl,
    char *	initString
    )
    {
    char *		tok;
    /*char**	  holder = NULL;*/
    char*      holder =	NULL;	/* vicadd*/
    UINT32	devMemAddr;
    UINT32	devIoAddr;

    /* Parse the initString */

	/*************kongfq2005.8.16********************/
    /*logMsg("Parse starting ...\n", 1,	2, 3, 4, 5, 6);*/

    /* Unit number. */

    tok	= strtok_r (initString,	":", &holder);
    if (tok == NULL)
	return ERROR;

    pDrvCtrl->unit = atoi (tok);

	/*************kongfq2005.8.16********************/
    /*logMsg("Unit : %d	...\n",	pDrvCtrl->unit,	2, 3, 4, 5, 6);*/

    /* devAdrs address.	*/

    tok	= strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    devMemAddr = (UINT32) strtoul (tok,	NULL, 16);

	/*************kongfq2005.8.16********************/
    /*logMsg("devMemAddr : 0x%X	...\n",	devMemAddr,
	     2,	3, 4, 5, 6);*/

    /* devIoAddrs address */

    tok	= strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    devIoAddr =	(UINT32) strtoul (tok, NULL, 16);


    /* always use memory mapped	IO if provided,	else use io map	*/
    
    if ((devMemAddr == NONE) &&	(devIoAddr == NONE))
		{
	logMsg("No memory or IO base specified ...\n",
		 1, 2, 3, 4, 5,	6);
	return (ERROR);
		}
    else if (devMemAddr	!= NONE)
	{
	pDrvCtrl->devAdrs = devMemAddr;
	pDrvCtrl->flags	  |= RTL_FLG_MODE_MEM_IO_MAP;
	/*************kongfq2005.8.16********************/
	/*logMsg("devMemAddr specified for devAdrs ...\n",
		 1, 2, 3, 4, 5,	6);*/
	}
    else
		{
	pDrvCtrl->devAdrs = devIoAddr;
	/*************kongfq2005.8.16********************/
	/*logMsg("devIoAddr specified for devAdrs - 0x%X ...\n",
		 devIoAddr, 2, 3, 4, 5,	6);*/
		}
	
    /* PCI memory base address as seen from the	CPU */
    
    tok	= strtok_r (NULL, ":", &holder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->pciMemBase = strtoul (tok, NULL, 16);

    /*************kongfq2005.8.16********************/
	/*
    logMsg("Pci : 0x%X ...\n", pDrvCtrl->pciMemBase,
	     2,	3, 4, 5, 6);*/

    /* Interrupt vector. */

    tok	= strtok_r (NULL, ":", &holder);
    /*if (tok == NULL)
	return ERROR;*/   /************kongfq 2005.8.15************/
    pDrvCtrl->ivec = atoi (tok);
    

⌨️ 快捷键说明

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