📄 lan.c
字号:
/* @(#) pSOSystem x86/V2.5.0: bsps/devices/lan/lan.c (&U&) 4.5 99/05/17 11:44:50 */
/***********************************************************************/
/* */
/* MODULE: bsps/template/src/lan.c */
/* DATE: 99/05/17 */
/* PURPOSE: chip specific lan driver */
/* */
/*---------------------------------------------------------------------*/
/* */
/* 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. */
/* */
/*---------------------------------------------------------------------*/
/* */
/* This file contains the template for the NI - Network Inteface. */
/* There is only one entry point to this file and that is NiLan. */
/* There are however several functions that appear in this file that */
/* break down the job of NiLan into more manageable pieces. */
/* */
/* Also include in this file are SNMP (MIB) support functions. If */
/* SNMP is not needed these functions my be omitted. */
/* */
/***********************************************************************/
#include "bsp.h"
#include <bspfuncs.h>
#include <psos.h>
#include <pna.h>
#include <pna_mib.h>
#include <ni_mib.h>
#include "board.h"
#include <prepc.h>
/*---------------------------------------------------------------------*/
/* Prototypes of static functions in this file */
/*---------------------------------------------------------------------*/
static UCHAR *ni_init(long (*p_ap_addr)(ULONG, char *, ULONG, ULONG,
char *, char *), long p_if_num, long p_ip_addr,
struct ni_funcs *funcs);
static ULONG ni_send(char *hwa_ptr, char *buff_addr, long type);
static ULONG ni_broadcast(char *buff_addr, long type);
static UCHAR *ni_getpkb(void);
static ULONG ni_retpkb(char *data);
static ULONG ni_poll(void);
static ULONG lan_isr(void);
/*---------------------------------------------------------------------*/
/* Prototypes of functions in this file called from I/O control */
/* functions of SNMP located in lan_mib.c. */
/*---------------------------------------------------------------------*/
void ni_pna_init(void);
long get_lan_indiscards (void);
long get_lan_outdiscards (void);
long get_lan_outerrors (void);
long get_lan_inerrors (void);
/*---------------------------------------------------------------------*/
/* Prototype of functions called by functions in this file. */
/*---------------------------------------------------------------------*/
extern ULONG ni_ioctl(ULONG if_num, ULONG cmd, long *arg, mib_stat *MG);
/*---------------------------------------------------------------------*/
/* Storage for the Announce_Packet function pointer, interface number, */
/* IP address and protocol layer functions esballoc and freemsg used */
/* provided by the protocol layer with the NI_INIT command */
/*---------------------------------------------------------------------*/
static long (* ap_addr)(ULONG, char *, ULONG, ULONG, char *, char *);
static ULONG if_num, ip_addr;
static struct ni_funcs Ni_funcs;
/***********************************************************************/
/* NiLan: Entry point to the NI */
/* */
/* INPUTS: function number */
/* pointer to parameter control block */
/* */
/* RETURNS: see individual function calls */
/* OUTPUTS: NONE */
/* NOTE(S): This is the only entry point into this driver. */
/* It will be called by a protocal layer above it. In */
/* most cases the pNA component will be the caller. */
/* */
/***********************************************************************/
long NiLan(ULONG svc, union nientry *pblk)
{
ULONG ret_val;
switch (svc)
{
case NI_INIT:
ret_val = (ULONG)ni_init(pblk->niinit.ap_addr,
pblk->niinit.if_num, pblk->niinit.ip_addr,
pblk->niinit.funcs);
break;
case NI_GETPKB:
ret_val = (ULONG)ni_getpkb();
break;
case NI_RETPKB:
ret_val = ni_retpkb(pblk->niretpkb.buff_addr);
break;
case NI_SEND:
MG_stat.outoctets += pblk->nisend.count;
MG_stat.outucastpkts++;
ret_val = ni_send(pblk->nisend.hwa_ptr, pblk->nisend.buff_addr,
pblk->nisend.type);
break;
case NI_BROADCAST:
MG_stat.outoctets += pblk->nibrdcast.count;
MG_stat.outnucastpkts++;
ret_val = ni_broadcast(pblk->nibrdcast.buff_addr,
pblk->nibrdcast.type);
break;
case NI_POLL:
ret_val = ni_poll();
break;
case NI_IOCTL:
ret_val = ni_ioctl(if_num, pblk->niioctl.cmd,
pblk->niioctl.arg, &MG_stat);
break;
default:
ret_val = -1;
}
return ret_val;
}
/***********************************************************************/
/* ni_init: Initialize the NI for the 82596 */
/* */
/* INPUTS: p_ap_add: "announce packet" entry point */
/* p_if_num: interface number */
/* p_ip_addr: internet address */
/* funcs: buffer managment functions */
/* */
/* RETURNS: Pointer to hardware address of NI, or -1 if failure */
/* */
/***********************************************************************/
static UCHAR *ni_init(long (*p_ap_addr)(ULONG, char *, ULONG, ULONG,
char *, char *), long p_if_num, long p_ip_addr,
struct ni_funcs *funcs)
{
extern long ifadminstatus; /* ifadminstatus defined in lan_mib.c */
/*---------------------------------------------------------------------*/
/* Additional Code Here to initialize your hardware. */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Initialize MIB structure */
/*---------------------------------------------------------------------*/
memset((UCHAR *)&MG_stat, 0x00, sizeof(mib_stat)); /* Zero MIB structure */
MG_stat.ifNum = p_if_num; /* Interface number of the caller */
MG_stat.ifDescr = "XXXX"; /* Replace XXXX with a string to describe the */
/* Ethernet Controller */
MG_stat.ifType = 6; /* Type of the interface */
MG_stat.ifMtu = BSP_LAN1_MTU; /* Maximum transmission unit */
MG_stat.ifSpeed = ; /* Speed of the interface */
for (i=0; i<6; ++i) /* Interface physical address */
MG_stat.ifPhysaddress[i] = ;
MG_stat.ifAdminstatus = ; /* Desired interface state */
MG_stat.ifOperstatus = ; /* Current operational status */
MG_stat.ifOutqlen = BSP_LAN1_PKB; /* Size of output queue */
MG_stat.ifSpecific = "0.0";/* MIB specific pointer */
MG_stat.if_ioctl = xyz_ioctl; /* Routine to serve the interface specific ioctls */
/*---------------------------------------------------------------------*/
/* Store the parameters in globals - do this after itnl_lpback(). */
/*---------------------------------------------------------------------*/
Ni_funcs = *funcs;
ap_addr = (long (*)(ULONG, char *, ULONG, ULONG, char *, char *))
p_ap_addr;
if_num = (ULONG)p_if_num;
ip_addr = (ULONG)p_ip_addr;
clear(&MG_stat, sizeof(MG_stat));
MG_stat.ifDescr = IFDESCR;
ifadminstatus = 1;
return Ether_Addr;
}
/***********************************************************************/
/* ni_getpkb: Get a packet from the NI driver's pool */
/* */
/* INPUTS: NONE */
/* */
/* RETURNS: address of buffer, or P_FAIL if none available */
/* OUTPUTS: NONE */
/* NOTE(S): This function needs to get the address of a data */
/* buffer to be used by the protocol layer above it. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -