📄 smend.c
字号:
/* smEnd.c - END shared memory backplane network interface driver *//* Copyright 1984-1999 Wind River Systems, Inc. *//*modification history--------------------01a,20jan1999,mas written based on if_sm.c version 01k but with no Unix.*//*DESCRIPTIONThis module implements the VxWorks shared memory backplane networkinterface enhanced network driver. This driver is designed to be moderately generic, operating unmodifiedacross most targets supported by VxWorks. To achieve this, the driver mustbe given several target-specific parameters, and some external supportroutines must be provided. These parameters are detailed below.There are no user-callable routines.This driver is layered between the shared memory packet library and the Muxmodules. The backplane driver gives CPUs residing on a common backplane the ability to communicate using IP (via shared memory).Macros:The macro SYS_INT_ENABLE is used to enable the interrupt level for theend device. It is called once during initialization. By default this isthe routine sysLanIntEnable(), defined in the module sysLib.o.The macro SYS_ENET_ADDR_GET is used to get the ethernet address (MAC)for the device. The single argument to this routine is the END_DEVICEpointer. By default this routine copies the ethernet address stored inthe global variable sysTemplateEnetAddr into the END_DEVICE structure.INCLUDES:end.h endLib.h etherMultiLib.hINTERNALData flow: ------- | MUX | | multiplexer: interface ------- | to network drivers | | | | -------------- | | smEnd | | shared memory -------------- | backplane driver | | | | ------------ | | smPktLib | | shared memory data ------------ | packetizer library | | | | ------------- | | smUtilLib | | H/W abstraction ------------- | | | | | =========================== | backplaneMUXImplements the interface between the protocol layer and the data link layerwhich contains the driver.smEndContains the network interface code that is common to all END basedsystems. It is the interface between the network modules and the backplane.It does the packet processing.smPktLibReformats data between IP packets and shared memory buffer packets.smUtilLibContains routines to abstract the hardware backplane, giving a uniforminterface to any type of backplane.MUX Interface:The interfaces into this module from the MUX module follow. smEndLoad - Called by the MUX, the routine initializes and attaches thisshared memory network interface driver to the MUX. It is the only globallyaccessible entry into this driver. This routine typically gets called twiceper backplane interface (device) and accepts a pointer to a string ofinitialization parameters. The first call to this routine will be made withan empty string; it signals the routine to return a device name, not to loadand intialize the driver. The second call will be with a valid parameterstring, signalling that the driver is to be loaded and initialized with theparameter values in the string. The shared memory region must have beensetup and initialized (via smPktSetup) prior to calling smEndLoad().Although initialized, no devices will become active until smEndStart() iscalled.The following routines are all local to this driver but are listed in thedriver entry function table:smEndUnload - Called by the MUX, this routine stops all associated devices,frees driver resources, and prepares this driver to be unloaded. If required,calls to smEndStop() will be made to all active devices.smEndStart - Called by the MUX, the routine starts this driver and device(s).The routine activates this driver and its device(s). The activities performedare dependent upon the selected mode of operation, interrupt or polled.smEndStop - Called by the MUX, the routine stops this driver by inactivatingthe driver and its associated device(s). Upon completion of this routine,this driver is left in the same state it was just after smEndLoad() execution.smEndRecv - This routine is not called from the MUX. It gets called fromthis drivers interrupt service routine (ISR) to process input shared memorypackets. It then passes them on to the MUX.smEndSend - Called by the MUX, this routine sends a packet via shared memory.smEndPollRecv - Called by the MUX, this routine polls the shared memory regiondesignated for this CPU to determine if any new packet buffers are availableto be read. If so, it reads the packet into the supplied mBlk and returns OKto the MUX. If the packet is too big for the mBlk or if no packets areavailable, EAGAIN is returned. If the device is not in polled mode, EIO isreturned.smEndPollSend - Called by the MUX, this routine does a polled send of onepacket to shared memory. Because shared memory buffers act as a message queue,this routine will attempt to put the polled mode packet at the head of the listof buffers. If no free buffers are available, the buffer currently appearingfirst in the list is overwritten with the packet.smEndIoctl - Called by the MUX, the routine accesses the control routines forthis driver.smEndMCastAddrAdd - Called by the MUX, this routine adds an address to adevice's multicast address list.smEndMCastAddrDel - Called by the MUX, this routine deletes an address from adevice's multicast address list.smEndMCastAddrGet - Called by the MUX, this routine gets the multicast addresslist maintained for a specified device.The following routines do not require shared memory specific logic so thedefault END library routines are referenced in the function table:endEtherAddressForm - Called by the MUX, this routine forms an address byadding appropriate link-level (shared memory) information to a specified mBlkin preparation for transmission.endEtherPacketDataGet - Called by the MUX, this routine derives the protocolspecific data within a specified mBlk by stripping the link-level (sharedmemory) information from it. The resulting data are copied to another mBlk.endEtherPacketAddrGet - Called by the MUX, this routine extracts addressinformation from one mBlk, ignoring all other data. Each source anddestination address is written to its own mBlk. For ethernet packets, thisroutine produces two output mBlks (an address pair). However, for non-ethernetpackets, up to four mBlks (two address pairs) may be produced; two for anintermediate address pair and two more for the terminal address pair..LPEXTERNAL SUPPORT REQUIREMENTSThe following routines/macros must be provided for this module: sysSmBspLoad() - a routine to dynamically build a parameter string for, and call into, smEndLoad(). This routine is typically contained within the sysSmCfg.c BSP module.The following routines/macros may be optionally provided for this module: .IP SM_PACKET_XFER().CS void SM_PACKET_XFER (void * source, void * destination, int numBytes);.CEThis macro transfers data between clusters and SM packets. It may optionallybe redefined in the BSP. By default, bcopy() is used: #define SM_PACKET_XFER(source,destination,numBytes) \\ bcopy((char*)source, (char*)destination, (int)numBytes)TARGET-SPECIFIC PARAMETERSThese parameters are input to this driver in an ASCII string format, usingcolon delimited values, via the sysSmBspLoad() routine in sysSmCfg.c. Eachparameter have a preselected radix in which they are expected to be read asshown below.The sysSmCfg.c module is included in sysLib.c and is compiled with the currentsettings for the target-specific parameters defined by the following:Parameter Radix Use----------------- ----- ------------------------------------------------------SM_BUS_SPACE 16 bus address space; NONE = local, else, a VME AM or PCI space selector [**not yet supported in smPktLib.c**]SM_ANCHOR_ADRS 16 shared memory anchor region @<SM_BUS_SPACE>SM_MEM_ADRS 16 shared memory (NONE = allocate) @<SM_BUS_SPACE> This value is used by the master CPU when building sm.SM_MEM_SIZE 16 total shared memory size in bytes This value is used by the master CPU when building sm.SM_TAS_TYPE 10 test-and-set type (SM_TAS_HARD or SM_TAS_SOFT)SM_CPUS_MAX 10 maximum number of CPUs supported on backplane (0 = default number)SM_MASTER_CPU 10 master CPU#SM_PKTS_SIZE 10 max number of data bytes per shared memory packet (0 = default)SM_MAX_INPUT_PKTS 10 max number of queued receive packets for this CPU (0 = default)SM_INT_TYPE 10 interrupt method (SM_INT_MAILBOX/_BUS/_NONE)SM_INT_ARG1 16 1st interrupt argumentSM_INT_ARG2 16 2nd interrupt argumentSM_INT_ARG3 16 3rd interrupt argumentSM_NUM_MBLKS 16 number of mBlks in driver memory pool (if < 16, a default value is used)SM_NUM_CBLKS 16 number of clBlks in driver memory pool (if < 16, a default value is used)DEBUG SUPPORTThis module has a define to enable compilation of debug instrumentation codecalled SM_DBG. There is also a conditionally compiled global called smEndDebugwhich is used as a bit array for enabling/disabling debug reporting in variousroutines in this module. This enables selective debugging with little or noextraneous information from other code sections.SEE ALSO: muxLib, endLib.I "Writing an Enhanced Network Driver"INTERNALThere are currently certain values stored in what are listed as reservedlocations within various sm structures. These must be treated with extremecare so as not to overwrite them:Structure Reserved field usage-------------------- ------------------------------------------------------SM_PKT_MEM_HDR reserved1 - master's sequential IP address reserved2 - sm heartbeat WD timer IDSM_CPU_DESC reserved1 - each CPU stores it's non-sequential IP address here. There is one SM_CPU_DESC per CPU in sm.*//* includes */#include "vxWorks.h"#include "stdlib.h"#include "stdio.h"#include "cacheLib.h"#include "intLib.h"#include "net/if_dl.h"#include "end.h" /* Common END structures. */#include "endLib.h"#include "lstLib.h" /* Needed to maintain protocol list. */#include "arpLib.h"#include "wdLib.h"#include "iv.h"#include "semLib.h"#include "taskLib.h"#include "etherLib.h"#include "logLib.h"#include "netLib.h"#include "sysLib.h"#include "errno.h"#include "errnoLib.h"#include "memLib.h"#include "muxLib.h"#include "etherMultiLib.h" /* multicast stuff. */#include "m2Lib.h"#include "netinet/if_ether.h"#include "net/if_subr.h"#include "net/mbuf.h"#include "net/unixLib.h"#include "net/protosw.h"#include "net/systm.h"#include "net/route.h"#include "sys/socket.h"#include "sys/ioctl.h"#include "sys/times.h"#include "drv/end/smEnd.h"#include "smLib.h"#include "smPktLib.h"#include "smUtilLib.h"IMPORT int endMultiLstCnt (END_OBJ * pEnd);/* defines *//* * Definitions for the shared memory END State flags field * * Flag Use * --------------- ------------------------------------------------------ * S_LOADED smEnd successfully loaded * S_CPU_ATTACHED local CPU is attached to shared memory * S_RUNNING local CPU active in shared memory * S_POLLED_SM shared memory interface is operating in polled mode * S_POLLED_SM_LOCKED sm interface locked in polled mode, can't enter * interrupt mode * S_POLLED_END MUX interface is operating in polled mode * S_RCV_TASK_ACTIVE interrupt driven receive task is active */#define S_LOADED 0x0001#define S_CPU_ATTACHED 0x0002#define S_RUNNING 0x0004#define S_POLLED_SM 0x0008#define S_POLLED_SM_LOCKED 0x0010#define S_POLLED_END 0x0020#define S_RCV_TASK_ACTIVE 0x0040/* shared memory END compound states */#define S_ACTIVE (S_LOADED | S_CPU_ATTACHED | S_RUNNING)#define S_POLLED_SM_RDY (S_ACTIVE | S_POLLED_SM)#define S_POLLED_END_RDY (S_ACTIVE | S_POLLED_END)#define S_POLLED_RDY (S_ACTIVE | S_POLLED_SM | S_POLLED_END)#define S_INTR_RDY (S_ACTIVE)#define MODE_INTR_MASK (S_ACTIVE | S_POLLED_RDY | S_RCV_TASK_ACTIVE)/* macros *//* * Default macro definitions for smUtilLib interface. * These macros must be redefined when architecture-neutral functional calls * exist for: intConnect(), intDisconnect(), intEnable(), intDisable(), * sysMailboxDisconnect(), and sysMailboxDisable(). *//* * XXXmas temporary; someday will have to make a real one based on a * functional intDisconnect()! */#define smUtilIntDisconnect(pri,pIsr,isrArg,iType,iArg1,iArg2,iArg3) OK/* XXXmas ditto: smUtilLib will someday have real versions of these: *//* Macro to enable the appropriate interrupt level */#ifndef smUtilIntEnable#define smUtilIntEnable(pSmEndDev) \ do \ { \ if (pSmEndDev->intType == SM_INT_BUS) \ sysIntEnable (pSmEndDev->intArg1); \ else if (pSmEndDev->intType != SM_INT_NONE) \ sysMailboxEnable ((char *)pSmEndDev->intArg2); \ else \ taskResume (pollTaskId); \ } while (0)#endif /* smUtilIntEnable *//* Macro to disable the appropriate interrupt level */#ifndef smUtilIntDisable#define smUtilIntDisable(pSmEndDev) \ do \ { \ if (pSmEndDev->intType == SM_INT_BUS) \ sysIntDisable (pSmEndDev->intArg1); \ else if (pSmEndDev->intType == SM_INT_NONE) \ taskSuspend (pollTaskId); \ } while (0)#endif /* smUtilIntDisable *//* A shortcut for getting the hardware address from the MIB II stuff. */#define END_HW_ADDR(pEnd) \ ((pEnd)->mib2Tbl.ifPhysAddress.phyAddress)#define END_HW_ADDR_LEN(pEnd) \ ((pEnd)->mib2Tbl.ifPhysAddress.addrLength)#define SM_END_PKT_LEN_GET(pPkt) ((pPkt)->header.nBytes)#define SM_END_IS_RUNNING \ ((END_FLAGS_GET (&pSmEndDev->end) & IFF_RUNNING) != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -