📄 dec21140.c
字号:
static long InErrors, outerrors;
static long lc_err;
/***********************************************************************/
/* Function Prototypes */
/***********************************************************************/
int ReadSrom(UCHAR, USHORT *);
int d21140EnetAddr(char *);
void d21140AuiMiiInit(void);
void d21140SelectMedia(void);
UCHAR d21140SROMVersion(void);
static void bzero(UCHAR *ptr, int length);
static void lanPciInit(void);
static void lanInit(void);
static void InitBuffers(void);
static void lanChipReset(void);
/*---------------------------------------------------------------------*/
/* Ni interface routines */
/*---------------------------------------------------------------------*/
static long ni_init(void);
static void ni_send(char *hwa_p, char *pkb_p, USHORT type);
static void ni_isr(void);
static void ni_poll(void);
static ULONG ni_ioctl(long cmd, long *arg);
static void ni_pna_init(void);
/*---------------------------------------------------------------------*/
/* Packet reception processing routines */
/*---------------------------------------------------------------------*/
static void RxBufDetach(LAN_RX_BUF *env_ptr);
static void RxBufRcv(void);
static void RxBufAttach(void);
/*---------------------------------------------------------------------*/
/* Packet transmission processing routines */
/*---------------------------------------------------------------------*/
static void TxFillDesc(void);
static void TxBufAttach(void *addr, int len, ULONG ctrl, ULONG stat);
static void TxBufDetach(void);
/*---------------------------------------------------------------------*/
/* SROM information etc. */
/*---------------------------------------------------------------------*/
MediaBlocksType srMediaBlocks; /* SROM Media Data */
/*---------------------------------------------------------------------*/
/* Multicast support routines */
/*---------------------------------------------------------------------*/
static void lan_addr_clear(void);
static ULONG lan_add_mcast(UCHAR *addr);
static ULONG lan_del_mcast(UCHAR *addr);
static void lan_addr_write(void);
/***********************************************************************/
/* Ni Local Function Definitions */
/***********************************************************************/
/***********************************************************************/
/* lanPciInit: Initialize the LAN PCI Configuration Registers */
/* */
/* NOTE: Initializes everything related to lan except the receive */
/* and transmit buffer descriptors. All Multibyte registers */
/* follow little endian byte ordering. */
/* */
/***********************************************************************/
static void lanPciInit(void)
{
/*-------------------------------------------------------------------*/
/* PCI Command Register - clear */
/*-------------------------------------------------------------------*/
WrPciCfg16(CF_CMD, 0);
/*-------------------------------------------------------------------*/
/* PCI Status Register - clear */
/*-------------------------------------------------------------------*/
WrPciCfg16(CF_STATUS, LAN_DS_PER | LAN_DS_SERR | LAN_DS_MA |
LAN_DS_RTA | LAN_DS_STA | LAN_DS_DPAR);
/*-------------------------------------------------------------------*/
/* PCI IO Map Base register - Set IO Space Base Address */
/*-------------------------------------------------------------------*/
WrPciCfg32(CBIO, LAN_PCI_IO_BASE);
/*-------------------------------------------------------------------*/
/* PCI Latency Timer Register - initialize */
/*-------------------------------------------------------------------*/
WrPciCfg8(CF_LATENCY, 0xFF);
/*-------------------------------------------------------------------*/
/* PCI Cache Line Size - initialize */
/*-------------------------------------------------------------------*/
WrPciCfg8(CF_LINE_SZ, 16);
/*-------------------------------------------------------------------*/
/* PCI driver area register - Set initialized status */
/*-------------------------------------------------------------------*/
WrPciCfg8(CF_DRIVER, 1);
/*-------------------------------------------------------------------*/
/* PCI Command Register - Set */
/*-------------------------------------------------------------------*/
WrPciCfg16(CF_CMD, LAN_COM_IOSE | LAN_COM_BME);
}
/***********************************************************************/
/* lanInit: Initialize MAC Control and Status Registers */
/* */
/* NOTE: Initializes everything related to lan except the receive */
/* and transmit buffer descriptors. */
/* */
/***********************************************************************/
static void lanInit(void)
{
/*-------------------------------------------------------------------*/
/* Perform software reset of the chip. */
/*-------------------------------------------------------------------*/
lanChipReset();
/*-------------------------------------------------------------------*/
/* Disable software reset bit & set the CSR0 parameters */
/*-------------------------------------------------------------------*/
ioLongWrite(CSR0, LAN_CSR0_CAL16L | LAN_CSR0_PBL16 | LAN_CSR0_RME);
/*-------------------------------------------------------------------*/
/* Clear all Status bits - CSR5 */
/*-------------------------------------------------------------------*/
ioLongWrite(CSR5, 0x0000FFFF);
/*-------------------------------------------------------------------*/
/* Determine physical interface and set CSR6. */
/*-------------------------------------------------------------------*/
ioLongWrite(CSR6, 0);
d21140AuiMiiInit();
/*-------------------------------------------------------------------*/
/* Receive List Base Address - CSR3 */
/*-------------------------------------------------------------------*/
ioLongWrite(CSR3, (ULONG)RxDesc);
/*-------------------------------------------------------------------*/
/* Transmit List Base Address - CSR4 */
/*-------------------------------------------------------------------*/
ioLongWrite(CSR4, (ULONG)TxDesc);
/*-------------------------------------------------------------------*/
/* SIA Register programming - CSR15 */
/*-------------------------------------------------------------------*/
ioLongWrite(CSR15, LAN_CSR15_JCK | LAN_CSR15_HUJ);
}
/***********************************************************************/
/* InitBuffers: Initialize receive buffer and transmit header pools */
/* */
/***********************************************************************/
static void InitBuffers(void)
{
int i;
/*-------------------------------------------------------------------*/
/* Zero out the transmit headers */
/*-------------------------------------------------------------------*/
bzero((UCHAR *)TxHeaders, sizeof(LAN_TX_HDR) * TxNumHdrs);
/*-------------------------------------------------------------------*/
/* Link transmit headers in a free list */
/*-------------------------------------------------------------------*/
TxHdrFreeHead = &TxHeaders[0];
for (i = 0; i < (TxNumHdrs - 1); ++i)
TxHeaders[i].next = &TxHeaders[i + 1];
TxHeaders[TxNumHdrs - 1].next = NULL;
/*-------------------------------------------------------------------*/
/* Initialize the list of queued transmit headers to empty. */
/*-------------------------------------------------------------------*/
TxHdrOutHead = TxHdrOutTail = NULL;
/*-------------------------------------------------------------------*/
/* Zero out the memory to be used for the receive buffers. */
/*-------------------------------------------------------------------*/
bzero((UCHAR *)RxBuffers, sizeof(LAN_RX_BUF) * RxNumBufs);
/*-------------------------------------------------------------------*/
/* Link the receive buffers together in the free list. */
/*-------------------------------------------------------------------*/
RxBufFreeHead = RxBuffers;
for (i = 0; i < (RxNumBufs - 1); ++i)
RxBuffers[i].next = &RxBuffers[i + 1];
RxBuffers[RxNumBufs - 1].next = NULL;
}
/***********************************************************************/
/* RxBufDetach: Return a receive buffer to the free list */
/* */
/* INPUTS: buf_ptr: Pointer to the buffer being returned */
/* OUTPUTS: None */
/* */
/* NOTES: This is the "Free Routine" called by pNA+ after it has */
/* unlinked the buffer from the message block structure to */
/* return it to the driver's buffer poll. */
/* */
/***********************************************************************/
static void RxBufDetach(LAN_RX_BUF *buf_ptr)
{
Bool ien;
/*-------------------------------------------------------------------*/
/* Mask interrupts */
/*-------------------------------------------------------------------*/
ien = intCLEAR_IEN();
/*-------------------------------------------------------------------*/
/* Link returned buffer to the buffer previously at the top of the */
/* free queue and point "free_head" to the newly returned buffer. */
/*-------------------------------------------------------------------*/
buf_ptr->next = RxBufFreeHead;
RxBufFreeHead = buf_ptr;
/*-------------------------------------------------------------------*/
/* Unmask interrupts */
/*-------------------------------------------------------------------*/
intRESTORE_IEN(ien);
/*-------------------------------------------------------------------*/
/* Attach buffers to receive descriptors */
/*-------------------------------------------------------------------*/
RxBufAttach();
}
/***********************************************************************/
/* RxBufAttach: Attach buffers to receive descriptors */
/* */
/* NOTES: Beginning with first receive descriptor used to receive */
/* a packet since this function last assigned a buffer, */
/* reassign buffers to "used" receive descriptors, and mark */
/* them owned by MAC, available to be filled again. */
/* */
/***********************************************************************/
static void RxBufAttach(void)
{
int attachFlag = 0;
Bool ien;
/*-------------------------------------------------------------------*/
/* Disable Interrupts */
/*-------------------------------------------------------------------*/
ien = intCLEAR_IEN();
/*-------------------------------------------------------------------*/
/* Pass through receive descriptors and assign buffers if possible. */
/*-------------------------------------------------------------------*/
for (;;)
{
#if 0 /* timmer */
/*-----------------------------------------------------------------*/
/* If descriptor is owned by MAC, break out of loop. */
/*-----------------------------------------------------------------*/
if (RxUsedBD->status & MAC_OWNS_DESC)
break;
#else
/*-----------------------------------------------------------------*/
/* If buffer assigned but not processed by ISR, break out of loop. */
/*-----------------------------------------------------------------*/
if (RxUsedBD->buffAddr1)
break;
#endif
/*-----------------------------------------------------------------*/
/* If no free receive buffers, break out of loop. */
/*-----------------------------------------------------------------*/
if (RxBufFreeHead == NULL)
break;
/*-----------------------------------------------------------------*/
/* Assign packet, prepare descriptor, and advance pointer. */
/*-----------------------------------------------------------------*/
RxUsedBD->buffAddr1 = (void *)RxBufFreeHead;
RxBufFreeHead = RxBufFreeHead->next;
RxUsedBD->ctrlNsize = LAN_RCVD_RCH | 1518;
RxUsedBD->status = MAC_OWNS_DESC;
COPYBACK((void *)RxUsedBD, 1);
RxUsedBD = RxUsedBD->nextDesc;
attachFlag = 1;
}
/*-------------------------------------------------------------------*/
/* Enable Interrupts */
/*-------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -