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

📄 ns8390x.c

📁 基于psos操作系统的ns8390驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* @(#) pSOSystem x86/V2.5.0: bsps/devices/lan/ns8390x.c 4.7 99/04/02 15:47:27 */
/***********************************************************************/
/*                                                                     */
/*   MODULE:  bsps/devices/lan/ns8390x.c                               */
/*   DATE:    99/04/02                                                 */
/*   PURPOSE: Ethernet chip driver for the NIC DP8390x                 */
/*                                                                     */
/*---------------------------------------------------------------------*/
/*                                                                     */
/*           Copyright 1991 - 1999, Integrated Systems, Inc.           */
/*                      ALL RIGHTS RESERVED                            */
/*                                                                     */
/*   Permission is hereby granted to licensees of Integrated Systems,  */
/*   Inc. products to use or abstract this computer program for the    */
/*   sole purpose of implementing a product based on Integrated        */
/*   Systems, Inc. products.   No other rights to reproduce, use,      */
/*   or disseminate this computer program, whether in part or in       */
/*   whole, are granted.                                               */
/*                                                                     */
/*   Integrated Systems, Inc. makes no representation or warranties    */
/*   with respect to the performance of this computer program, and     */
/*   specifically disclaims any responsibility for any damages,        */
/*   special or consequential, connected with the use of this program. */
/*                                                                     */
/***********************************************************************/
#include "bsp.h"
#include "board.h"
#include <drv_intf.h>            
#include <pna.h>
#include <pna_mib.h>            
#include <ni_mib.h>            
#include <lan/lan_type.h>
#include <lan/ns8390x.h>


/*---------------------------------------------------------------------*/
/* Define debug macros                                                 */
/*---------------------------------------------------------------------*/
#define DEBUG          0                  /* Debugging 1:On 0:Off  */
#if DEBUG
#define STATIC
#else
#define STATIC        static
#endif /* DEBUG */

/*---------------------------------------------------------------------*/
/* Number of lans (from bsp.h)                                         */
/*---------------------------------------------------------------------*/
#if (BSP_LAN1_MODEL == NS8390)
#define MY_LAN1     1
#define MY_FLAGS1   BSP_LAN1_FLAGS
#define MY_MTU1     BSP_LAN1_MTU
#else
#define MY_LAN1     0
#define MY_FLAGS1   0
#define MY_MTU1     0
#endif

#if (BSP_LAN2_MODEL == NS8390)
#define MY_LAN2     1
#define MY_FLAGS2   BSP_LAN2_FLAGS
#define MY_MTU2     BSP_LAN2_MTU
#else
#define MY_LAN2     0
#define MY_FLAGS2   0
#define MY_MTU2     0
#endif

#if (BSP_LAN3_MODEL == NS8390)
#define MY_LAN3     1
#define MY_FLAGS3   BSP_LAN3_FLAGS
#define MY_MTU3     BSP_LAN3_MTU
#else
#define MY_LAN3     0
#define MY_FLAGS3   0
#define MY_MTU3     0
#endif

#define  NUM_NS8390    (MY_LAN1 + MY_LAN2 + MY_LAN3)
#define  BOARD_FLAGS   (MY_FLAGS1 | MY_FLAGS2 | MY_FLAGS3)

#if MY_MTU1
#define  BOARD_MTU      MY_MTU1
#elif MY_MTU2
#define  BOARD_MTU      MY_MTU2
#elif MY_MTU3
#define  BOARD_MTU      MY_MTU3
#endif


#if NUM_NS8390

/**************************************************************************/
/* Lan Interface Configuration Table                                      */
/**************************************************************************/
STATIC struct lan_cfg_info ns8390_cfgs[NUM_NS8390] =
{
#if MY_LAN1
   { BSP_LAN1_INTLEV,   BSP_LAN1_IO_BASE, BSP_LAN1_RAM_BASE, 
     BSP_LAN1_RAM_SIZE, BSP_LAN1_DMA,     BSP_LAN1_16BIT,    BSP_LAN1_SFTCFG 
   },
#endif

#if MY_LAN2
   { BSP_LAN2_INTLEV,   BSP_LAN2_IO_BASE, BSP_LAN2_RAM_BASE, 
     BSP_LAN2_RAM_SIZE, BSP_LAN2_DMA,     BSP_LAN2_16BIT,    BSP_LAN2_SFTCFG 
   },
#endif

#if MY_LAN3
   { BSP_LAN3_INTLEV,   BSP_LAN3_IO_BASE, BSP_LAN3_RAM_BASE, 
     BSP_LAN3_RAM_SIZE, BSP_LAN3_DMA,     BSP_LAN3_16BIT,    BSP_LAN3_SFTCFG 
   },
#endif
};

/*---------------------------------------------------------------------*/
/* External Variable Definitions                                       */
/*---------------------------------------------------------------------*/


/*---------------------------------------------------------------------*/
/* External Function Definitions                                       */
/*---------------------------------------------------------------------*/
extern void          movlrc(void*, void*, ULONG);
extern void          zfill(void *, ULONG);
extern ULONG         splx(ULONG);
extern ULONG         splhigh();
extern UCHAR         inb(ULONG);
extern void          outb(ULONG, UCHAR);
extern USHORT        inw(ULONG);
extern void          outw(ULONG, USHORT);
 
/*---------------------------------------------------------------------*/
/* ni_ioctl is a common (to all ni) routine defined in ni_mib.c.       */
/* It, in turns, calls interface specific ns8390_ioctl routine to      */
/* serve any interface specific commands.                              */
/*---------------------------------------------------------------------*/
extern ULONG ni_ioctl(ULONG, ULONG, long *, mib_stat *);

/*---------------------------------------------------------------------*/
/* Symbol & Macro definitions                                          */
/*---------------------------------------------------------------------*/
#define LAN_IP              0x0800           /* IP type                */
#define LAN_ARP             0x0806           /* ARP type               */
#define LAN_RARP            0x8035           /* RARP type              */
#define LAN_MIN_FRAME           46           /* Minimum Frame Length   */

#ifndef TRUE
#define TRUE                     1
#endif

#ifndef FALSE
#define FALSE                    0
#endif

#ifndef NULL
#define NULL                     0
#endif

#define REMOTE_READ              0
#define REMOTE_WRITE             1
#define RCV_OFLOW             TRUE
#define RCV_NO_OFLOW         FALSE

/*---------------------------------------------------------------------*/
/* Page ring structure for NIC NS8390x.                                */
/*---------------------------------------------------------------------*/
typedef volatile struct RcvBuffHdr
    {
    UCHAR    frameStat;                 /* Frame Status                */
    UCHAR    nextPage;                  /* Next Page #                 */
    UCHAR    sizeLsb;                   /* Frame Size LSBs             */
    UCHAR    sizeMsb;                   /* Frame Size MSBs             */
    } RCV_BUFF_STAT;

typedef volatile union
    {
    ULONG           dataPage[64];       /* Data Page = 256 bytes       */
    volatile struct xx
       {
       RCV_BUFF_STAT Stat;              /* Receive Frame Status        */
       ULONG         dataBuf[63];       /* First frame data field      */
       } BUFF1;
    } STNIC_RING_BUFF;

/*---------------------------------------------------------------------*/
/* ST-NIC Receive & Transmit Buffer Ring.                              */
/*                                                                     */
/* This data structure is 64k bytes in size max.                       */
/*                                                                     */
/* The way the 403GA evaluation board is wired the above size cannot   */
/* be used. The schematics for the ethernet chip show that only 13 of  */
/* the possible 16 address lines are used. This means that 32 bit addr */
/* mode cannot be used. Also, the size of the ring is limited to 8192  */
/* bytes. Since, the page start register cannot be initialized to zero,*/
/* the first few buffers are used for transmission and the rest for    */
/* reception.                                                          */
/*                                                                     */
/* An attempt is made to make the driver as generic as possible.       */
/*                                                                     */
/*---------------------------------------------------------------------*/
/* Number of buffers in the ring allocated to receive & transmit       */
/*---------------------------------------------------------------------*/
#define LAN_NUM_BUFFS      64
#define LAN_TXSTART        64
#define LAN_NUM_TXBUFFS    12
#define LAN_NUM_RXBUFFS    (LAN_NUM_BUFFS - LAN_NUM_TXBUFFS)
#define LAN_RXSTART        LAN_TXSTART+LAN_NUM_TXBUFFS
#define LAN_RXSTOP         LAN_TXSTART+LAN_NUM_BUFFS

/***********************************************************************/
/* Local Variables                                                     */
/***********************************************************************/
/*---------------------------------------------------------------------*/
/*                         TRANSMIT HEADERS                            */
/*---------------------------------------------------------------------*/
/* When the driver is given a message to transmit, it must prepend an  */
/* Ethernet header (fields "daddr", "saddr", and "type"). The transmit */
/* header structure provides a place to put this information.  The     */
/* transmit header also contains a pointer to the msg block triplet.   */
/*                                                                     */
/* When ns8390_send() is called, a transmit header is taken from free  */
/* list (pointed to by TxHdrFreeHead), and filled in with the info for */
/* the frame.  Then it is put into a queue of headers awaiting         */
/* transmission.  TxHdrOutHead and TxHdrOutTail point to the head and  */
/* tail of this list.                                                  */
/*                                                                     */
/* TxFillBuffs() takes the queued headers and sets up DP83902A pages   */
/* by copying data into them.                                          */
/*                                                                     */
/* LAN_NUM_TXHDRS defines the number of transmit headers. It is defined*/
/* to be half of BSP_LAN1_BUFFS_MAX                                    */
/*                                                                     */
/*---------------------------------------------------------------------*/
typedef volatile struct TxHdr
    {
    e_addr           daddr;            /* Destination Hardware Address */
    e_addr           saddr;            /* source hardware address      */
    USHORT           type;             /* IP, ARP, RARP or other       */
    mblk_t          *msg_ptr;          /* Ptr to rest of msg (triplet) */
    ULONG            numBytes;         /* # of bytes                   */
    ULONG            NoRetFlag;        /* TRUE: don't return *msg_ptr  */
    long             dev_num;          /* Header device number         */
    volatile struct TxHdr *next;       /* Ptr to next hdr in free list */
    } LAN_TX_HDR;

/*---------------------------------------------------------------------*/
/* Define transmit headers & transmission related variables            */
/*---------------------------------------------------------------------*/
STATIC ULONG LanNrTxHdrs;                  /* Number of Tx heades      */
STATIC LAN_TX_HDR *TxHeaders[NUM_NS8390]; /* The actual headers    */
STATIC LAN_TX_HDR *TxHdrFreeHead[NUM_NS8390]; /* Free list of transmit headers*/
STATIC LAN_TX_HDR *TxHdrOutHead[NUM_NS8390];  /* Head of hdrs awaiting buffs  */
STATIC LAN_TX_HDR *TxHdrOutTail[NUM_NS8390];  /* Tail of hdrs awaiting buffs  */
STATIC LAN_TX_HDR *TxCurrHdrPtr[NUM_NS8390][2]; /* Ptr to Curr Tx Hdr Xmitting  */

STATIC int TxAbortpageNum[NUM_NS8390];      /* Transmit on. Resend this page */
STATIC int TxAbortnumBytes[NUM_NS8390];     /* Transmit on. number of bytes  */

/*---------------------------------------------------------------------*/
/*                      RECEIVE BUFFERS                                */
/*---------------------------------------------------------------------*/
/* When a packet is received in the ring buffer, data is copied into   */
/* receive packets, a message block header is allocated from           */
/* pNA and the receive packet is attached to it.                       */
/* Then the entire thing is given to pNA via the "announce packet"     */
/* call.                                                               */
/*                                                                     */
/*---------------------------------------------------------------------*/
typedef struct RxPktHdr
    {
    RCV_BUFF_STAT    bufStat;            /* Receive buffer status info  */
    USHORT           filler;             /* Align pktbuf to long word   */
    e_addr           daddr;              /* destination hardware address*/
    e_addr           saddr;              /* source hardware address     */
    USHORT           type;               /* IP, ARP, or RARP            */
    UCHAR            pktbuf[1500];       /* pNA data                    */
    UCHAR            crc[4];             /* STNIC generated             */
    ULONG            pageNum;            /* Page number in buffer ring  */
    long             dev_num;            /* Header device number         */
    USHORT           dataLen;            /* Length of the packet        */
    struct RxPktHdr *next;               /* Ptr to next envelope in Q   */
    } LAN_RXPKT_LIST;

⌨️ 快捷键说明

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