ethernet.h 3.57 KB
/*
 * Copyright (C) 1996-1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * 
 * This file is part of the SimOS distribution. 
 * See LICENSE file for terms of the license. 
 *
 */

/*
 * sim_ether.h - Interface to the ethernet.  
 *
 * Created by: Ed Bugnion, 06/95
 * Revised: Dan Teodosiu, 07/95
 */

/* ************************************************************************
 * In the new version, we model an ethernet controller capable of
 * handling multiple outstanding sends and receives.  The controller
 * is controlled through uncached reads/writes in the I/O space.  It
 * can handle ETHER_MAX_RCV_ENTRIES incoming packets before dropping
 * them on the floor.  On the way out, it can buffer up to
 * ETHER_MAX_SND_ENTRIES requests and support a scatter-gather of the
 * chunks of the packets. The maximum number of packet chunks is set
 * to ETHER_MAX_SND_CHUNKS.
 *
 * The controller maintains 3 circular buffers, received packets, send
 * packets and the send packet chunks.  It will issue an interrupt if
 * at least one of the
 * **************************************************************************/

#ifndef _SIM_ETHER_H
#define _SIM_ETHER_H

#define ETHER_MAX_CONTROLLERS     32
#define ETHER_MAX_RCV_ENTRIES     64
#define ETHER_MAX_SND_ENTRIES     64
#define ETHER_MAX_SND_CHUNKS      128

#include "../../cpus/simos/machine_defs.h"
typedef DevRegister EthRegister; 

/*
 * Ethernet controller registers.
 */
typedef struct SimetherRegisters {
  EthRegister etheraddr[6]; /* Controller tells OS its internal ethernet address. */
  EthRegister numRcvEntries;/* Read by OS, set by controller. Indicates how many
			* receive ring buffer entries will be used. OS must
			* allocate a rcv buffer for each of these entries. */
  EthRegister numSndEntries;/* Read by OS, set by contr. Informs the OS how many
			* send ring buff entries will be used so it knows when
			* to wrap its index pointer. */
  EthRegister numSndChunks; /* Same as numSndEntries. */

  struct {
    EthRegister pAddr;
    EthRegister maxLen;
    EthRegister len;
    EthRegister flag;         
  } rcvEntries[ ETHER_MAX_RCV_ENTRIES ];

  struct {
    EthRegister firstChunk;
    EthRegister lastChunk;
    EthRegister flag;
  } sndEntries[ ETHER_MAX_SND_ENTRIES ];

  struct { 
    EthRegister pAddr;
    EthRegister len;
  } sndChunks[ETHER_MAX_SND_CHUNKS ]; 

  EthRegister intrCPU;      /* OS tells controller which CPU to interrupt */

} SimetherRegisters;

/* values for flag field: */
#define OS_OWNED         1
#define CONTROLLER_OWNED 2

#define SIMETHER_MAX_TRANSFER_SIZE	1800


/*** SimOS interface ***/

typedef void (*EtherIntFunc)(int iface_num, int on);

extern int   SimetherInit(int restore, EtherIntFunc int_f);
extern void  SimetherInitCluster(void);
extern char* SimetherAddr(int iface_num);
extern void  SimetherPoll(void); /* poll function, called periodically */

/* called from cluster.c */
extern int   SimetherReceivePacket(int iface_num,char *packet,int packetSize);

/* parameters */

extern char *EthersimHostname;
extern char *EtherAddress;
extern int   EtherSendPort;
extern int   RestoreEthernet;


/*** OS interface ***/

/* Note: for the following function, offs is the offset in BYTES
 * from the beginning of a SimetherRegisters structures. Legal offsets
 * are all uint (word) aligned.
 *
 * The function is used for reading/writing ether registers. Certain
 * registers (such as flags) trigger actions (sending a packet).
 *
 * Only dword-sized accesses are supported.
 */
extern EthRegister SimetherIO(int iface_num, int offset, int is_write, EthRegister data);

#endif /* _SIM_ETHER_H */