-- File: DriverDefs.Mesa,  Last Edit:
  -- MAS  Apr 17, 1980 11:53 PM
  -- HGM  October 23, 1979  8:49 PM
-- Last doStats: MAS  October 14, 1980  10:44 AM

-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  StatsDefs: FROM "StatsDefs" USING [StatCounterIndex],
  BufferDefs: FROM "BufferDefs" USING [
    BufferType, Buffer, PupBuffer, RppBuffer, Queue, QueueObject],
  PupTypes: FROM "PupTypes" USING [PupHostID, PupErrorCode],
  DriverTypes: FROM "DriverTypes" USING [DeviceType];

DriverDefs: DEFINITIONS =
BEGIN OPEN BufferDefs;

-- Compile Time Switches
doStats: BOOLEAN = TRUE;  -- TRUE for FatPup, FALSE for TinyPup
doErrors: BOOLEAN = TRUE;
doDebug: BOOLEAN = doStats;
doSee: BOOLEAN = TRUE;
doCheck: BOOLEAN = TRUE;
doStorms: BOOLEAN = doStats;
doShow: BOOLEAN = doStats;

-- Interface from device drivers to Dispatcher and QueuePackage
PutOnGlobalInputQueue: PROCEDURE [Buffer];
PutOnGlobalDoneQueue: PROCEDURE [Buffer];
GetInputBuffer: PROCEDURE RETURNS [Buffer];  -- b.length (words) includes encap
ReturnFreeBuffer: PROCEDURE [Buffer];

-- These will return the last buffer.  They never wait.  Be careful.  NIL if its empty.
MaybeGetFreePupBuffer: PROCEDURE RETURNS [PupBuffer];
MaybeGetFreeRppBuffer: PROCEDURE RETURNS [RppBuffer];
MaybeGetFreeBuffer: PROCEDURE RETURNS [Buffer];


-- Interface to Routers
Router: TYPE = POINTER TO RouterObject;
RouterObject: TYPE = RECORD [
  input: PROCEDURE [Buffer],
  broadcast: PROCEDURE [Buffer],
  addNetwork: PROCEDURE [Network],
  removeNetwork: PROCEDURE [Network] ];


-- Interface to Device Drivers
Network: TYPE = POINTER TO NetworkObject;
NetworkObject: TYPE = RECORD [
  next: Network,
  decapsulateBuffer: PROCEDURE [Buffer] RETURNS [BufferDefs.BufferType],
  encapsulatePup: PROCEDURE [PupBuffer, PupTypes.PupHostID],
  encapsulateRpp: PROCEDURE [RppBuffer, PupTypes.PupHostID],
  sendBuffer: PROCEDURE [Buffer],
  forwardBuffer: PROCEDURE [Buffer] RETURNS [PupTypes.PupErrorCode],
  activateDriver: PROCEDURE,
  deactivateDriver: PROCEDURE,
  deleteDriver: PROCEDURE,
  interrupt: PROCEDURE,  -- to lock things in memory
  index: [0..400B),  -- assigned by AddDeviceToChain (starts at 1)
  device: DriverTypes.DeviceType,  -- 4 bits
  alive: BOOLEAN,
  speed: CARDINAL,  -- KiloBits/Sec
  netNumber: CARDINAL,
  hostNumber: CARDINAL,  -- This is the Pup host number
  pupStats: PROCEDURE [PupBuffer, Network] RETURNS [BOOLEAN],
  stats: LONG POINTER ];  -- and debugging

-- ON/OFF
CommPackageGo: PROCEDURE;
CommPackageOff: PROCEDURE;
SetPupRouter: PROCEDURE [Router];  -- NIL to Deactivate

-- Device Things
AddDeviceToChain: PROCEDURE [network: Network, iocbSize: CARDINAL];
RemoveDeviceFromChain: PROCEDURE [Network];
GetDeviceChain: PROCEDURE RETURNS [Network];

-- Setting up individual device drivers
CreateDefaultEthernetDriver: PROCEDURE RETURNS [BOOLEAN];
CreateEthernetDriver: PROCEDURE [
  netNumber: CARDINAL, deviceNumber: [0..3) ] RETURNS [BOOLEAN];
CreateSlaDriver: PROCEDURE [host, net, lines: CARDINAL] RETURNS [BOOLEAN];
CreatePacketRadioDriver: PROCEDURE [host, net, other: CARDINAL] RETURNS [BOOLEAN];
CreateLoopBackNetwork: PROCEDURE RETURNS [BOOLEAN];

-- Stats linkage
EthernetStats: PROCEDURE [PupBuffer, Network] RETURNS [BOOLEAN];
SlaStats: PROCEDURE [PupBuffer, Network] RETURNS [BOOLEAN];
PacketRadioStats: PROCEDURE [PupBuffer, Network] RETURNS [BOOLEAN];

-- Internal routines
FreeQueueMake: PROCEDURE;
FreeQueueDestroy: PROCEDURE;
DispatcherOn: PROCEDURE;
DispatcherOff: PROCEDURE;


-- General catchall for things that shouldn't happen
Glitch: PROCEDURE [ERROR];

-- Buffer pool info
numberOfBuffers: CARDINAL;
dataWordsPerBuffer: CARDINAL;  -- for software
wordsPerIocb: CARDINAL;

-- DispatcherInternal
dispatcherPleaseDie: BOOLEAN;
dispatcherLock: MONITORLOCK;
dispatcherReady: CONDITION;
globalInputQueue: QueueObject;
globalOutputQueue: QueueObject;
pupRouter: Router;
MainDispatcher: PROCEDURE;
DummyInputer: PROCEDURE [Buffer];

-- things from Boss
firstNetwork: Network;
giantVector: LONG POINTER TO GiantVector;
useCount: CARDINAL;

-- QueueInternal
freeQueueLock: MONITORLOCK;
freeQueueNotEmpty: CONDITION;
freeQueue: QueueObject;
firstBuffer: Buffer;
bufferSize: CARDINAL;  -- for IO drivers

-- For getting things STARTed
DispatcherCold, DispatcherHot: PROGRAM;
QueueCold, QueueCool, QueueIn, QueueOut: PROGRAM;

-- Beware MakeImage does not preserve debugPointer.

GiantVector: TYPE = RECORD [
  firstNetwork: Network,
  firstBuffer: Buffer,
  bufferPoolSize: CARDINAL,
  wordsPerBuffer: CARDINAL,
  pupRoutingTable: DESCRIPTOR FOR ARRAY OF UNSPECIFIED,
  firstPupSocket: POINTER,
  freeQueue, globalInputQueue, globalOutputQueue: Queue,
  -- hacks until we get more drivers
  ethernetOutputQueue: Queue,
  currentInputBuffer, nextInputBuffer, currentOutputBuffer: POINTER TO Buffer,
  statCounters: POINTER TO ARRAY StatsDefs.StatCounterIndex OF LONG CARDINAL,
  statStrings: POINTER TO ARRAY StatsDefs.StatCounterIndex OF STRING,
  slaThings: POINTER,
  prThings: POINTER,
  spare: POINTER ];

END.