/*
	 Copyright 2001 (c) by Authors,
	 Swiss Federal Institute of Technology,
	 Computer Engineering and Networks Laboratory.
 
	 TOPSY -- A Teachable Operating System.
	 Implementation of a tiny and simple
	 micro kernel for teaching purposes.
 
	 For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
	 This software is provided under the terms of the GNU General Public 
	 Licence. A full copy of the GNU GPL is provided in the file COPYING 
	 found in the development root of Topsy.
*/

/*
 
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/IO/sa1100/Drivers/Attic/IXPuEInit.h,v $
	Affiliation:           ETH Zuerich, TIK
	Version:               $Revision: 2922 $
	Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $  by: $Author: baderma $
 
*/


#ifndef _IXPUEINIT_H_
#define _IXPUEINIT_H_


#include "IXPuCode.h"
#include "types.h"


/*** Constants from config ***/

/* Scratch Memory Allocation */
#define SA_DMXMSG_ARR_ADDR     0
#define SA_DBGMSG_ARR_ADDR     24
#define RCV_COUNT_ARR_ADDR     48
#define XMT_COUNT_ARR_ADDR     56
#define TFIFO_NUMBER_ADDR      64
#define RCV_DECISION_ARR_ADDR  65
#define PACKET_Q_RDY_ARR_ADDR  89
#define VRP_TO_SA_RATE_ADDR    115
#define BAD_PF_COUNT_ADDR      122
#define NON_SOP_PF_COUNT_ADDR  123
#define SA_TO_P_PF_COUNT_ADDR  148
#define SA_FM_P_PF_COUNT_ADDR  149
#define VRP_DROP_PF_COUNT_ADDR 150
#define UE_TO_SA_PF_COUNT_ADDR 151
#define UE_FM_SA_PF_COUNT_ADDR 152
#define PACKET_QMUTEX_ARR_ADDR 154
#define PORT_PF_ADDR_ARR_ADDR  180
#define PACKET_QINFO_ARR_ADDR  188
#define SA_PID_MSG_ARR_ADDR    316
#define SA_NTID_MSG_ARR_ADDR   340

/* Packet Buffer (DRAM) Settings */
#define MAX_PID           8
#define SA_PID            MAX_PID
#define DROP_PID          (MAX_PID + 1)
#define PACKET_BUF_STRIDE 9


#define QUEUE_ADDR_BITS   10
#define QUEUE_NO_BITS     3
#define XMT_Q_COUNT       (1 << QUEUE_NO_BITS)
#define XMT_Q_ENTRY_COUNT (1 << (QUEUE_ADDR_BITS + QUEUE_NO_BITS))
#define XMT_PORT_COUNT    8
#define XMT_Q_ENTRY_TOTAL (XMT_Q_ENTRY_COUNT * (XMT_PORT_COUNT + 1))

/* SRAM Memory Allocation */
#define XMT_Q_ARR_ADDR           0
#define PORT_MUTEX_SRAM_ARR_ADDR (XMT_Q_ARR_ADDR + XMT_Q_ENTRY_TOTAL)

#define VRP_FORWARDER_TABLE     (PORT_MUTEX_SRAM_ARR_ADDR + SA_PID)
#define VRP_FT_NUM_ENTRIES      4096
#define VRP_FT_FLOWS_PER_ENTRY  16
#define VRP_FT_FLOW_SIZE        4
#define VRP_FT_ENTRY_SIZE       (VRP_FT_FLOWS_PER_ENTRY * VRP_FT_FLOW_SIZE)

#define VRP_FT_SIZE             (VRP_FT_NUM_ENTRIES * VRP_FT_ENTRY_SIZE)

/* The offset from the end of the code which contains the first function to be
 * executed on all packets. This should probably go in Scratch. */
#define VRP_ALL_FORWARDERS      (VRP_FORWARDER_TABLE + VRP_FT_SIZE)
#define VRP_FLOW_STATE          (VRP_ALL_FORWARDERS + 1)

#define VRP_ROUTE_CACHE_BASE VRP_FLOW_STATE

/* uE Packet Addr Settings */
#define EOP_BYTE_ADDR_BITS        24
#define PACKET_NO_OFFSET          11
#define PACKET_FRAGMENT_NO_OFFSET 6

/* uE Thread Assignments */
#define RCV_BASE_UE   0
#define RCV_UE_COUNT  2
#define RCV_CTX_COUNT 8

#define XMT_BASE_UE   4
#define XMT_UE_COUNT  2
#define XMT_CTX_COUNT 8


/* uE Interrupt Message Flags */
#define SA_MSG_RCV_RDY     1
#define SA_MSG_XMT_RDY     2
#define SA_MSG_DEBUG       4
#define SA_MSG_FATAL_ERROR 8


/* A random number, used to ACK uE debug messages */
#define SA_DEBUG_ACK_MSG 0xBDF892E6


/* Disable SA check of uE ACKs on xmt */
#define DISABLE_FAST_SA_UE_XMT_PROTOCOL 1


/* VRP constants */
#define BIG_ENDIAN      0
#define LITTLE_ENDIAN   1
#define EOF_NOP_COUNT   3

/* Register B11. ABS_DEST format in *.uci. */
#define VRP_FORWARDER_STATE_REGISTER 0xDB


/*** function prototypes from IXPuEInit.c ***/
void    Control_BootUEs(uEng_uCodeInfo rcv_uCode, uEng_uCodeInfo xmt_uCode);
void    Control_LoadUEs(uEng_uCodeInfo info, int where, uint32 data);


#endif
