#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "teac.h"
/* Notes-
* -Why is elan3_fini dropping core? It's intermittent, and seems to
* depend on relative timing of multiple calls.
*/
#ifdef CHROMIUM
#include <cr_string.h>
#include <cr_mem.h>
#include <cr_error.h>
#else
abort(); \
} \
}
#include <stdarg.h>
}
#endif
/* We need some defs to handle changes in structures between software
* revisions.
*/
/* Capability shape is the same between KITE and pre-KITE */
#ifdef ELAN_PRE_KITE
/* software level is PRE_KITE */
#define TEAC_DEVINFO_TYPE 0
#define TEAC_CAP_TYPE 0
#else
#ifdef ELAN_PRE_EAGLE
/* software level is KITE */
#ifdef LINUX
#else
#define TEAC_DEVINFO_TYPE 0
#define TEAC_CREATE_TYPE 0
#endif
#else
/* software level is EAGLE */
#endif
#endif
#if (TEAC_CAP_TYPE == 2)
#else
#endif
/* In the future we will use the bitwise AND of the rail masks */
#define RAIL 0
#ifndef HOST_TABLE_FILENAME
#endif
static int nodeTablesInitialized= 0;
static int nodeTableSize= 0;
static int nodeCount= 0;
static int read_node_map()
{
int i;
int iLine;
INITIAL_HOST_TABLE_SIZE*sizeof(host_t));
abort();
}
abort();
}
i= 0;
iLine= 0;
char* tmp;
char* string;
iLine++;
if (i>=nodeTableSize) {
/* We need to grow the table */
}
abort();
}
abort();
}
errno= 0;
if (errno != 0) {
abort();
}
abort();
}
errno= 0;
if (errno != 0) {
abort();
}
abort();
}
errno= 0;
if (errno != 0) {
abort();
}
abort();
}
errno= 0;
if (errno != 0) {
abort();
}
#if 0
crDebug("line %d: %d: got <%s> %d %d 0x%x 0x%x\n",
#endif
i++;
}
if (ferror(f)) {
perror("Error reading host table");
abort();
}
(void)fclose(f);
return i;
}
{
}
{
}
static void initialize_node_tables()
{
if (!nodeTablesInitialized) {
int nodeMin;
int nodeMax;
int nodeRange;
int i;
/* Load information about Quadrics network */
if (nodeCount==0) {
"libteac: initialize_node_tables: no valid nodes in %s!\n",
abort();
}
/*
* Build the offset tables. Offsets are looked up by node ID, so we
* have to avoid redundant IDs and order the tables correctly.
*/
for (i=1; i<nodeCount; i++) {
}
"libteac: initialize_node_tables: unable to allocate %d bytes!\n",
nodeRange*sizeof(sdramaddr_t));
abort();
}
"libteac: initialize_node_tables: unable to allocate %d bytes!\n",
abort();
}
for (i=0; i<nodeRange; i++) {
sdramAddrBase[i]= (sdramaddr_t)0;
elanAddrBase[i]= (E3_Addr)0;
}
for (i=0; i<nodeCount; i++) {
}
/* Sort the host table alphabetically by host name for faster lookup */
/* Build an ordered index into the hosts table */
nodeCount*sizeof(int));
abort();
}
for (i=0; i<nodeRange; i++) hostsIndex[i]= 0;
}
}
#if 0
char buf[128];
int i;
i= 0;
buf[i]= '\0';
#endif
#if 0
if (h) {
crDebug("Lookup <%s> got <%s> <%d> <%x> <%x>\n",
}
#endif
if (h) return h->id;
else return -1;
}
/*
* A version of address translation with some safety checks
*/
{
/*
crDebug("mapping %0lx -> %d; addressable %d\n",
main_addr,result,elan3_addressable(ctx,main_addr,64));
*/
if (result==ELAN_BAD_ADDR) {
(int)main_addr);
abort();
}
return result;
}
const unsigned char key[TEAC_KEY_SIZE])
{
#if (TEAC_DEVINFO_TYPE == 2)
#else
#endif
int i;
int j;
int a;
int b;
char* here;
#if ( TEAC_CREATE_TYPE == 0 )
void* control;
#endif
sizeof(Tcomm));
return(NULL);
}
result->rbuf_pull_event = 0;
result->poll_shift = 0;
a = trans_host(lh);
b = trans_host(hh);
#if (TEAC_CAP_TYPE == 2)
/* Initialize the UserKey to the given value */
#else
/* Initialize the UserKey to the given value */
#endif
== NULL) {
return(NULL);
}
#if ( TEAC_CREATE_TYPE == 0 )
crDebug("elan3_create failed with <%s>, but that's OK!\n",
errno= 0;
}
}
else {
perror("elan3_control_open failed");
return NULL;
}
crDebug("elan3_create failed with <%s>, but that's OK!\n",
errno= 0;
}
#else
/* I don't think we have to do anything here! */
#endif
#if (TEAC_DEVINFO_TYPE == 2)
crDebug("Position mode %d, NodeID %d, NumNodes %d, NumLevels %d\n",
elan3_devinfo(0, &info);
crDebug("NodeId: %d, NumNodes: %d, NumLevels: %d, NodeLevel: %d\n",
#else
elan3_devinfo(0, &info);
crDebug("NodeId: %d, NumLevels: %d, NodeLevel: %d\n",
#endif
#if 0
{
static char junkString[256];
#if (TEAC_CAP_TYPE == 2)
crDebug("Capability: <%s>\n",
#else
crDebug("Capability: <%s>\n",
#endif
}
#endif
/* Reality check. */
perror("Can't get my own host name");
return NULL;
}
#if (TEAC_DEVINFO_TYPE == 2)
"teac_Init: Expected Quadrics port id %d does not match real value %d!\n",
return NULL;
}
"teac_Init: Expected Quadrics port id %d does not match real value %d!\n",
return NULL;
}
#else
"teac_Init: Expected Quadrics port id %d does not match real value %d!\n",
return NULL;
}
#endif
return(NULL);
}
return(NULL);
}
return(NULL);
}
return(NULL);
}
* sizeof(sdramaddr_t) ))) {
return(NULL);
}
perror("teac_Init: elan3_allocElan failed for r_event block");
return(NULL);
}
}
for (j=0; j<TEAC_CAP_ENTRIES(cap); j++)
for (i=1; i<NUM_SEND_BUFFERS; i++) {
}
#if 0
#endif
return(NULL);
}
perror("teac_Init: elan3_allocMain failed for m_rcv block");
return(NULL);
}
#if 0
crDebug("Base of m_rcv is %lx -> %lx\n",
#endif
return(NULL);
}
perror("teac_Init: elan3_allocMain failed for mbuff block");
return(NULL);
}
#if 0
crDebug("Base of mbuff is %lx -> %lx\n",
#endif
E3_DMA_ALIGN, sizeof(E3_DMA_MAIN)))) {
perror("teac_Init: elan3_allocMain failed for dma");
return(NULL);
}
perror("teac_Init: elan3_allocElan failed for e_dma");
return(NULL);
}
sizeof(E3_BlockCopyEvent)))) {
perror("teac_Init: elan3_allocElan failed for s_event");
return(NULL);
}
#if 0
#endif
if (!(result->sbuf_pull_event[0]=
NUM_SEND_BUFFERS*sizeof(E3_BlockCopyEvent)))) {
perror("teac_Init: elan3_allocElan failed for sbuf_pull_event block");
return(NULL);
}
for (i=1; i<NUM_SEND_BUFFERS; i++)
result->sbuf_pull_event[i]=
if (!(result->rbuf_pull_event=
sizeof(E3_BlockCopyEvent)))) {
perror("teac_Init: elan3_allocElan failed for rbuf_pull_event");
return(NULL);
}
sizeof(E3_uint32)))) {
perror("teac_Init: elan3_allocMain failed for m_snd");
return(NULL);
}
NUM_SEND_BUFFERS*sizeof(E3_uint32)))) {
perror("teac_Init: elan3_allocMain failed for sbuf_ready block");
return(NULL);
}
for (i=1; i<NUM_SEND_BUFFERS; i++)
if (!(result->sendWrappers[0]=
NUM_SEND_BUFFERS*sizeof(SBuffer));
return(NULL);
}
for (i=1; i<NUM_SEND_BUFFERS; i++)
sizeof(E3_uint32)))) {
perror("teac_Init: elan3_allocMain failed for rbuf_ready");
return(NULL);
}
for (i=0; i<NUM_SEND_BUFFERS; i++) {
char* buf;
perror("teac_Init: elan3_allocMain failed for buffer block");
return(NULL);
}
}
for (i=0; i<NUM_SEND_BUFFERS; i++) {
}
for (j=0; j<TEAC_CAP_ENTRIES(cap); j++)
for (i=0; i<NUM_SEND_BUFFERS; i++) {
}
/* Get the message receive events ready to fire, in case something
* comes in before receive gets called.
*/
for (j=0; j<TEAC_CAP_ENTRIES(cap); j++)
for (i=0; i<NUM_SEND_BUFFERS; i++) {
}
/* Fire the sbuffer free events, so that the buffers look free when
* the first call to send happens.
*/
for (i=0; i<NUM_SEND_BUFFERS; i++) {
}
/* And now we're ready to face the world. */
return(result);
}
{
int i;
if (tcomm) {
/* First we have to wait until all pending messages have been
* pulled (assuming they got initialized in the first place).
*/
for (i=0; i<NUM_SEND_BUFFERS; i++) {
}
crDebug("All TEAC messages have reported home!\n");
}
}
}
if (tcomm->sbuf_pull_event[0] != 0)
for (i=0; i<NUM_SEND_BUFFERS; i++) {
}
}
}
if (tcomm->rbuf_pull_event != 0)
}
}
#if (TEAC_CREATE_TYPE==2)
#else
/* elan3_detach and elan3_destroy seem to crash sometimes in
* these versions.
*/
#endif
}
}
{
int id;
while (timeout-- > 0) {
}
return -1;
}
{
int i;
int j;
for (j=0; j<num_ids; j++) {
for (i=0; i<NUM_SEND_BUFFERS; i++) {
#ifdef never
#endif
return thisId;
}
}
}
return -1;
}
{
int i;
for (i=0; i<NUM_SEND_BUFFERS; i++) {
return 1;
}
return 0;
}
{
/* Find a free send buffer. We'll busy wait in this poll loop
* if necessary.
*/
int i= 0;
while (1) {
1)) break;
if (++i == NUM_SEND_BUFFERS) i= 0;
}
/* We will use this buffer! */
#if 0
crDebug("Allocated message buffer %d\n",i);
#endif
/* If the associated chunk of memory is smaller than that requested,
* replace it with something larger.
*/
perror("teac_getSendBuffer: failed to grow send buffer");
exit(-1);
}
}
return tcomm->sendWrappers[i];
}
{
sizeof(SBuffer));
abort();
}
#if 0
crDebug("Allocated an unready message buffer!\n");
#endif
/* Allocate some DMA-able memory */
perror("teac_getUnreadySendBuffer: failed to allocate elan3 memory");
exit(-1);
}
return result;
}
{
int i= 0;
/* If the input buffer is already ready, just return it */
/* Find a free send buffer. We'll busy wait in this poll loop
* if necessary.
*/
while (1) {
1)) break;
if (++i == NUM_SEND_BUFFERS) i= 0;
}
/* We will use this buffer! */
#if 0
crDebug("Allocated message buffer %d in makeSendBufferReady\n",i);
#endif
/* Substitute the unready payload for the old payload */
return tcomm->sendWrappers[i];
}
{
int iBuf;
int iDest;
/* Complain loudly if this is an unready buffer */
return 0;
}
/* Reality check: is this one of my buffers? */
return 0;
}
/* Reality check: did they write too much into the message? */
abort();
return 0;
}
else
/* Set up the parts of the DMA that are not specific to destination */
/* Send this message off to each destination */
#if 0
crDebug("DMA dest event %x, dest mem %lx\n",
crDebug("Mem shifts are %x %x based on %d %d\n",
crDebug("Send msg %d in buffer %d to %d (list index %d)...",
#endif
#if 0
crDebug("message away!\n");
#endif
}
return 1;
}
{
int iEvent= 0;
int iBuf= 0;
int i;
int lowestMsgnum;
/* poll until we get an incoming message from the given sender */
while (1) {
break;
}
/* This may not be the earliest event, however. */
lowestMsgnum= -1;
for (i=0; i<NUM_SEND_BUFFERS; i++) {
#if 0
crDebug("Testing for new msg at %lx -> %lx\n",
#endif
if ((lowestMsgnum < 0)
iBuf= i;
}
}
}
if (lowestMsgnum<0) {
"teac_Recv: internal error: can't find message I just got!\n");
return NULL;
}
#if 0
crDebug("got msg %d in buffer %d from %d!\n",
#endif
/* Make some space to put the message when it arrives */
sizeof(RBuffer));
return NULL;
}
#if 0
perror("teac_Recv: elan3_allocMain failed for buffer");
return(NULL);
}
#endif
perror("teac_Recv: elan3_allocMain failed for buffer");
return(NULL);
}
/* Set up the DMA to pull the message */
*(tcomm->rbuf_ready)= 0;
return(result);
}
{
return 0;
}
{
"<vp= %d, host range %d-%d, ctxnum range %d-%d, msg %d>",
return buf;
}
{
#if 0
#endif
return buf;
}
{
#if 0
crDebug("getConnId: <%s> %d %d maps to %d %d\n",
#endif
}
long* sdramBaseAddr, long* elanBaseAddr)
{
#if (TEAC_DEVINFO_TYPE == 2)
#else
#endif
char* here;
perror("Can't get my own host name");
return 0;
}
#if (TEAC_DEVINFO_TYPE == 2)
elan3_devinfo(0, &info);
#else
elan3_devinfo(0, &info);
#endif
#if (TEAC_CAP_TYPE == 2)
#else
#endif
*sdramBaseAddr= (int)c->r_event[0][0];
return 1;
}