📄 if_bp.c
字号:
/* if_bp.c - original VxWorks (and SunOS) backplane network interface driver *//* Copyright 1984 - 1997 Wind River Systems, Inc. */#ifndef UNIX#include "copyright_wrs.h"#else /* UNIX */static char *copyright= "Copyright 1984 - 1997 Wind River Systems, Inc.";#endif /* UNIX *//*modification history--------------------01u,09oct97,spm removed driver initialization from ioctl support (SPR #8831)01t,07apr97,spm code cleanup, corrected statistics, and upgraded to BSD 4.401s,25aug95,hk use cacheDmaMalloc() for shared memory on SH7600 targets.01r,12nov94,tmk removed some IMPORTed function decs and included unixLib.h01q,29mar94,caf use cacheDmaMalloc() for shared memory on MIPS targets.01p,23apr93,caf ansification: changed cast of free() parameter.01o,22feb93,jdi documentation cleanup.01n,18sep92,jcf clean up of warnings.01m,09sep92,gae documentation tweaks.01l,18jul92,smb Changed errno.h to errnoLib.h.01k,11jun92,elh fixed memory sizing bug - SPR 1481.01j,04jun92,ajm added test and set suport for mips01i,26may92,rrr the tree shuffle -changed includes to have absolute path from h/01h,26may92,ajm got rid of HOST_DEC def's (new compiler)04g,05may92,wmd changed LITTLE_ENDIAN to _LITTLE_ENDIAN, removed conditional for i960 to pass IPL vec parameter in sysMailboxEnable().04f,07apr92,yao removed duplicated macro ROUND_UP. removed unneccessary ROUND_UP for SPARC. changed copyright notice.04e,14feb92,wmd added BP_NTOHS, BP_HTONS for BUF_NODE->b_len conversions. Fixed ansi warnings.04d,27nov91,rfs fixed bug in bpStart(), which did not handle errors correctly, causing memory depletion. Also fixed ANSI warnings.04c,07oct91,rrr turned off some checking in the r300004b,04oct91,rrr passed through the ansification filter -changed functions to ansi style -changed functions to ansi style -changed includes to have absolute path from h/ -fixed #else and #endif -changed READ, WRITE and UPDATE to O_RDONLY O_WRONLY and O_RDWR -changed VOID to void -changed copyright notice04a,01oct91,ajm got rid of conditional comp (MIPS) for ItoKval, and KtoIval03z,10sep91,wmd added conditionals for MIPS.03y,21aug91,ajm added macros to allocate and free mips dynamic memory from uncached space cast line 1250 comparison with 0 to struct mbuf * to resolve warning in mips land03x,15aug91,rrr added IPL to sysMailboxEnable() for I960_FAMILY03w,23jul91,rrr added hton and ntoh stuff so I960 would work03v,12jul91,wmd minor cleanup of 03u. Added Al Maillet's fix to bpXmit for the case that ringput returns > 1 available slots.03u,24may91,hvh deleted 'short-macros' because they screwed up +jwt and besides, they are not needed since a short on the SPARC is 2 bytes (so no aligment problem); deleted 'KLUDGES' for SPARC since they make no sence and introduce gigantic interrupt-latencys in, what is supposed to be, a realtime operating system; included ELH 29dec91 bpPollTask check for NULL bp; fixed TAS(x) macro for Sun-1E and others - bpTas().03t,29apr91,hdn use SIZEOF_ETHERHEADER instead of sizeof(ether_header).03s,10apr91,jdi documentation cleanup; doc review by dnw.03r,29dec91,elh changed bpPollTask to check if bp is null.03q,10aug90,dnw fixed forward declarations for void functions. added include of if_subr.h.03p,12aug90,hjb added bpSlotCheck() to help BOOTP. changed bp pseudo-Ethernet addr to be all 00.03o,18jul90,hjb deleted cluster-loan code temporarily; fixed a bug caused by the macro ROUND_UP.03n,15jul90,dnw added b_pad to BUF_NODE structure to make it long aligned. changed to round up BP_BUFSIZ to be long aligned. removed B_COPY, B_ASSIGN, B_FROM macros coerced malloc() to (char*) where necessary.03m,11jul90,hjb removed references to ipintr().03l,26jun90,hjb fixes to accommodate SunOS; copy_from_mbufs() & m_freem() fix; changed params to build_cluster()03k,19apr90,hjb deleted param.h, added BP_SLOT_NUM, BP_MAX_LOANS, DEBUG_OPTION_5, bpRIngFree(), modified bpRead() to optimize throughput via cluster-callback-hack.03j,18mar90,hjb isolated out SunOS compatible routines for if_subr.c.03i,07aug89,gae adjusted BUF_NODE definition to work on SPARC; changed iv68k.h to iv.h; fixed ether_attach to not append unit.03h,14jun89,gae glitch in 03g: left bpParity on and wrong poll task priority.03g,14mar89,gae used unsigned int's for pointer arithmetic. made Ethernet address unique for multiple units. slight reorganization of bpPollTask. Added more DEBUG levels.03f,28mar89,gae turned off debugging; fixed bp BUFSIZ to be bigger than MTU to allow for ether_header overhead -- bug fix.03e,10feb89,gae taught SunOS to do mailboxes and about bus interrupts; +jcf added testing in bpInit for sufficient memory; +dnw added read mailboxes; fixed mbuf bug in copy_to_mbufs. UNIX ver. now compiles under SunOS 4.0 and has SUN3_5 flag.03c,10dec88,gae SunOS version tweaks.03b,20nov88,dnw lint03a,13sep88,gae merged SunOS and VxWorks versions. Documentation. +dnw debugged SunOS version. +ak wrote SunOS version.02l,23jun88,rdc added IFF_BROADCAST to if_flags.02k,06jun88,dnw changed taskSpawn/taskCreate args. changed NCPU from 9 to 32.02j,30may88,dnw changed to v4 names.02i,12apr88,gae added include of ioLib.h for O_RDONLY/O_WRONLY/O_RDWR.02h,28jan88,jcf made kernel independent.02g,20feb88,dnw lint02f,05jan88,rdc added include of systm.h02e,20nov87,ecs lint dnw changed bpattach to take int vec num instead of vec adrs.02d,13nov87,dnw added heartbeat & anchor.02c,03nov87,dnw fixed bug in bpRead of throwing away packets that were larger than 1500 bytes. make bpPoll be global so that it is legible in i(). added intConnect() call for bus interrupt connects in bpConnect(). changed bpReboot() into bpReset().02b,26oct87,jcf added bpConnect that does a sysMailboxConnect in the case of & mailbox interrupts or a spawn of bpPoll for non-interrupt dnw driven backplanes changed to not probe shared memory unless cpu 0.02a,22apr87,dnw rewritten.01b,08apr87,rdc moved call to bpConnect from bpAttach to bpInit.01x,01apr87,jlf delinted, removed ifdef CLEAN. changed calls to tas () to vxTas (). added copyright.*//*DESCRIPTIONThis module implements the original VxWorks backplane network interface driver.The backplane driver allows several CPUs to communicate via sharedmemory. Usually, the first CPU to boot in a card cage is considered thebackplane master. This CPU has either dual-ported memory or an additionalmemory board which all other CPUs can access. Each CPU must beinterruptible by another CPU, as well as be able to interrupt all otherCPUs. There are three interrupt types: polling, mailboxes, and VMEbusinterrupts. Polling is used when there are no hardware interrupts; eachCPU spawns a polling task to manage transfers. Mailbox interrupts are thepreferred method, because they do not require an interrupt level. VMEbusinterrupts offer better performance than polling; however, they mayrequire hardware jumpers.There are three user-callable routines: bpInit(), bpattach(), and bpShow().The backplane master, usually processor 0, must initialize the backplanememory and structures by first calling bpInit(). Once the backplane hasbeen initialized, all processors can be attached via bpattach(). Usually,bpInit() and bpattach() are called automatically in usrConfig.c whenbackplane parameters have been specified in the boot line.The bpShow() routine is provided as a diagnostic aidto show all the CPUs configured on a backplane.For more information about SunOS use of this driver, see the .I "Guide to the VxWorks Backplane Driver for SunOS."This driver has been replaced by if_sm and is included here for backwardscompatibility.MEMORY LAYOUTAll pointers in shared memory are relative to the start of shared memory,since dual-ported memory may appear in different places on different CPUs..ne 11.CS ---------------------------- low address (anchor) | ready value | 1234567 | heartbeat | increments 1/sec | pointer to bp header | | watchdog | for backplane master CPU -------------------------- the backplane header may be contiguous or allocated elsewhere on the master CPU.ne 7 ---------------------------- backplane header | backplane header | 1234567 | num CPUs | unused | Ethernet address | (6 bytes) | pointer to free ring | |--------------------------|.ne 11 |--------------------------| cpu descriptor | active | true/false | processor number | 0-NCPU | unit | 0-NBP | pointer to input ring | | interrupt type | POLL | MAILBOX | BUS | interrupt arg1 | none | addr space | level | interrupt arg2 | none | address | vector | interrupt arg3 | none | value | none |--------------------------| ... repeated MAXCPU times.ne 16 |--------------------------| | free ring | contains pointers to buffer nodes |--------------------------| | input ring 1 | contains pointers to buffer nodes |--------------------------| ... |--------------------------| | input ring n | |--------------------------| |--------------------------| buffer node 1 | address, length | |--------------------------| | data buffer 1 | |--------------------------| ....ne 6 |--------------------------| buffer node m | address, length | |--------------------------| | data buffer m | ---------------------------- high address.CEBOARD LAYOUTThis device is "software only." A jumpering diagram is not applicable.INTERNAL SOFTWARE ARCHITECTURE.CS bpIoctl | bpOutput bpPoll bpattach bpReset bpInit | __/ | | / \ | | / | | / \ | | / | | / \ | bpIfinit ether_output | bpAlive bpInit* bpSizeMem / | \ | | bpAlive|bpIntEnable bpPut | bpConnect | | (interrupt level) | bpXmit / / | \ / / bpPollTask \ / / bpPollUnix \ / / \ / __/ bpintr | bpReadAll | bpRead * UNIX only; called directly in VxWorks.CESEE ALSO: ifLib*/#ifdef UNIX#ifndef KERNEL#define KERNEL#endif /* KERNEL */#ifdef SUN3_5#include "h/types.h"#include "h/systm.h"#include "h/mbuf.h"#include "h/buf.h"#include "h/map.h"#include "h/socket.h"#include "h/vmmac.h"#include "h/errno.h"#else /* SUN3_5 */#include "sys/types.h"#include "sys/systm.h"#include "sys/mbuf.h"#include "sys/buf.h"#include "sys/map.h"#include "sys/socket.h"#include "sys/param.h"#include "sys/vmmac.h"#include "sys/errno.h"#endif /* SUN3_5 */#include "machine/param.h"#include "machine/pte.h"#ifdef SUN3_5#include "h/time.h"#include "h/kernel.h"#include "h/ioctl.h"#else /* SUN3_5 */#include "sys/time.h"#include "sys/kernel.h"#include "sys/ioctl.h"#endif /* SUN3_5 */#include "net/if.h"#include "netinet/in.h"#include "netinet/if_ether.h"#include "sundev/mbvar.h"#ifdef SUN3_5#include "h/protosw.h"#else /* SUN3_5 */#include "sys/protosw.h"#endif /* SUN3_5 */#include "net/route.h"#include "netinet/in_systm.h"#include "netinet/ip.h"#include "netinet/ip_var.h"#ifdef INET /* "vxWorks.h" defines INET */#undef INET#endif /* INET */#include "vxWorks.h"#include "vme.h" /* vxWorks vme AM's */#define BP_MASTER (bp_procnum == 0)IMPORT int bp_tas;IMPORT int bp_procnum;IMPORT int bp_n;IMPORT int bp_mem_size;IMPORT char *bp_mem_adrs;IMPORT int bp_int_type;IMPORT int bp_int_arg1;IMPORT int bp_int_arg2;IMPORT int bp_int_arg3;IMPORT void wakeup ();IMPORT struct mbuf *copy_to_mbufs ();#else /* UNIX */#include "vxWorks.h"#include "iv.h"#include "taskLib.h"#include "memLib.h"#include "ioLib.h"#include "ioctl.h"#include "etherLib.h"#include "wdLib.h"#include "iosLib.h"#include "intLib.h"#include "logLib.h"#include "netLib.h"#include "net/mbuf.h"#include "socket.h"#include "net/protosw.h"#include "errnoLib.h"#include "net/systm.h"#include "net/route.h"#include "netinet/in.h"#include "netinet/in_systm.h"#include "netinet/ip.h"#include "netinet/ip_var.h"#include "net/if.h"#include "net/unixLib.h"#include "netinet/if_ether.h"#include "net/if_subr.h"#include "netinet/in_var.h"#include "vxLib.h"#include "stdio.h"#include "stdlib.h"#include "sysLib.h"#if ((CPU_FAMILY==MIPS) || (CPU_FAMILY==SH))#include "cacheLib.h"#endif /* CPU_FAMILY==MIPS || CPU_FAMILY==SH */#endif /* UNIX */#include "drv/netif/if_ring.h"#include "if_bp.h"IMPORT struct ifnet *ifunit ();#if defined (BSD43_DRIVER) || defined (UNIX)IMPORT int ether_output (struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, FUNCPTR startRtn, struct arpcom *pArpcom);#endifIMPORT int set_if_addr (struct ifnet *ifp,char *data,u_char *enaddr);IMPORT void m_freem (struct mbuf *m);#define MAXCPU 32 /* don't change! */#define NCPU 32 /* number of input rings to init */#define MINPKTSIZE 60 /* minimum packet size to send */#define BP_SLOT_NUM 32 /* number of the input ring slots */#define BP_MTU ((2 * 1024) + 128)int bp_mtu = BP_MTU; /* patch before calling bpInit *//* round up bufsiz to be long aligned */#define BP_BUFSIZ (ROUND_UP (bp_mtu + SIZEOF_ETHERHEADER, 4))#ifdef UNIX#define logMsg printf#define WDOG_ID int#define vir2phys(v) (unsigned)ptob((unsigned)hat_getkpfnum(v))#define splimp() spl3()#define NBP 1 /* max # bp interfaces */#else /* UNIX */#define hz (sysClkRateGet ())#define NBP 2 /* max. # bp interfaces */#define vir2phys(v) (v)#endif /* UNIX */typedef struct ring RING;typedef struct /* buffer node */ { char *b_addr; /* buffer address (as offset) */ short b_len; /* buffer length */ short b_pad; /* padding to make structure long aligned */ } BUF_NODE;typedef struct /* CPU descriptor in bp header */ { BOOL cd_active; /* CPU is present */ int cd_cpuNum; /* processor number */ int cd_unit; /* unit on own CPU */ RING *cd_pInputRing; int cd_intType; /* interrupt: poll, bus, or mailbox */ int cd_intArg1; int cd_intArg2; int cd_intArg3; } CPU_DESC;typedef struct /* bp header */ { int hdr_ready; /* used only as marker for debugging */ short hdr_ncpu; /* unused */ u_char hdr_enetAdrs[6];/* "Ethernet address" */ RING *hdr_pFreeRing; CPU_DESC hdr_cpuDesc[MAXCPU]; } BP_HEADER;typedef struct /* bp anchor */ { int an_ready; /* special value 1234.... */ UINT an_heartbeat; /* increments every second */ BP_HEADER *an_pHdr; /* separate to minimize usage of low memory */ WDOG_ID an_wdog; /* for VxWorks version only */ } BP_ANCHOR;#define BP_READY 0x12345678 /* distinctive ready value */#define BP_READY_SOFT_TAS 0x12344321 /* ready value with software tas */#if _BYTE_ORDER==_LITTLE_ENDIAN#define BP_NTOHL(v) ntohl(v)#define BP_NTOHS(v) ntohs(v)#define BP_HTONL(v) htonl(v)#define BP_HTONS(v) htons(v)#else#define BP_NTOHL(v) (v)#define BP_NTOHS(v) (v)#define BP_HTONL(v) (v)#define BP_HTONS(v) (v)#endif /* _BYTE_ORDER==_LITTLE_ENDIAN */#define ItoKval(p,type,base) ((type)(ntohl((u_int)(p)) + (u_int)(base)))#define KtoIval(p,type,base) ((type)htonl((u_int)(p) - (u_int)(base)))/* * Net software status per interface. * * Each interface is referenced by a network interface structure, * bs_if, which the routing code uses to locate the interface. * This structure contains the output queue for the interface, its address, ... */typedef struct { struct arpcom bs_ac; /* common Ethernet structures */#define bs_if bs_ac.ac_if /* network-visible interface */#define bs_enaddr bs_ac.ac_enaddr /* hardware Ethernet address */ int bs_procNum; /* processor number on this net */ BP_ANCHOR *bs_pAnchor; /* pointer to bp anchor */ BP_HEADER *bs_pHdr; /* pointer to bp header */ volatile RING *bs_pFreeRing; /* pointer to free ring */ volatile RING *bs_pInputRing; /* pointer to our input ring */ volatile BOOL bs_readPending; /* read interrupt is outstanding */ int bs_intType; /* interrupt type: poll, bus, mailbox */ int bs_intArg1; int bs_intArg2; int bs_intArg3;#ifdef UNIX caddr_t bs_addr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -