/*
 * Module: WD8003
 * Project: System V ViaNet
 *
 *		Copyright (c) 1987 by Western Digital Corporation.
 *		All rights reserved.  Contains confidential information and
 *		trade secrets proprietary to
 *			Western Digital Corporation
 *			2445 McCabe Way
 *			Irvine, California 92714
 */

#ident "@(#)wd.h	1.3 - 88/08/09"

/*
 * Configuration options for WD 8003
 */

#define WDVPKTSZ	(3*256)
#define WDHIWAT		(32*WDVPKTSZ)
#define WDLOWAT		(8*WDVPKTSZ)
#define WDMAXPKT	1500
#define WDMAXPKTLLC	1497	/* max packet when using LLC1 */
#define WDMINSEND	60	/* 64 - 4 bytes CRC */

struct wddev {
   unsigned short  wd_flags;	/* flags to indicate various status' */
   unsigned short  wd_type;	/* LLC/Ether */
   queue_t	  *wd_qptr;	/* points queue associated with open device */
   unsigned short  wd_mask;	/* mask for ether type or LLC SAPs */
   unsigned short  wd_state;	/* state variable for DL_INFO */
   unsigned short  wd_sap;	/* sap or ethertype depending on wd_type */
   unsigned short  wd_snap[3];	/* for SNAP and other extentions */
   unsigned short  wd_rws;	/* receive window size - for LLC2 */
   unsigned short  wd_sws;	/* send window size - for LLC2 */
   unsigned short  wd_rseq;	/* receive sequence number - for LLC2 */
   unsigned short  wd_sseq;	/* send sequence number - for LLC2 */
};

/* status bits */
#define WDS_OPEN	0x01	/* minor device is opened */
#define WDS_PROM	0x02	/* promiscuous mode enabled */
#define WDS_XWAIT	0x04	/* waiting to be rescheduled */
#define WDS_SU		0x80	/* opened by priviledged user */
#define WDS_RWAIT	0x100	/* waiting for read reschedule */
/* link protocol type */
/* defined in lihdr.h */

struct wdparams {
   short    wd_int;		/* interrupt level */
   short    wd_ioaddr;		/* I/O port for device */
   caddr_t  wd_base;		/* address of board's memory */
   long     wd_memsize;		/* size of on-board memory */
};

/* Debug Flags and other info */

#define WDSYSCALL	0x01	/* trace syscall functions */
#define WDPUTPROC	0x02	/* trace put procedures */
#define WDSRVPROC	0x04	/* trace service procedures */
#define WDRECV		0x08	/* trace receive processing */
#define WDRCVERR	0x10	/* trace receive errors */
#define WDDLPRIM	0x20	/* trace DL primitives */
#define WDINFODMP	0x40	/* dump info req data */
#define WDDLPRIMERR	0x80	/* mostly llccmds errors */
#define WDDLSTATE      0x100	/* print state chages */
#define WDTRACE	       0x200	/* trace loops */
#define WDINTR	       0x400	/* trace interrupt processing */
#define WDBOARD	       0x800	/* trace access to the board */
#define WDLLC1	      0x1000	/* trace llc1 processing */
#define WDSEND	      0x2000	/* trace sending */
#define WDBUFFER      0x4000	/* trace buffer/canput fails */
#define WDSCHED       0x8000	/* trace scheduler calls */
#define WDXTRACE      0x10000	/* trace wdsend attempts */

/* define llc class 1 and mac structures and macros */

struct llctype {
   unsigned short	llc_length;
   unsigned char	llc_dsap;
   unsigned char	llc_ssap;
   unsigned char	llc_control;
   unsigned char	llc_info[1];
};

struct ethertype {
   unsigned short ether_type;
   unsigned char ether_data[1];
};

struct wd_machdr {
   unsigned char mac_dst[6];
   unsigned char mac_src[6];
   union {
      struct ethertype ether;
      struct llctype llc;
   } mac_llc;
};

typedef struct wd_machdr machdr_t;

#define LLC_SAP_LEN	1	/* length of sap only field */
#define LLC_LSAP_LEN	2	/* length of sap/type field  */
#define LLC_TYPE_LEN    2	/* ethernet type field length */
#define LLC_ADDR_LEN	6	/* length of 802.3/ethernet address */
#define LLC_LSAP_HDR_SIZE 3
#define LLC_HDR_SIZE	(LLC_ADDR_LEN+LLC_ADDR_LEN+LLC_LSAP_HDR_SIZE+LLC_LSAP_LEN)
#define LLC_EHDR_SIZE	(LLC_ADDR_LEN+LLC_ADDR_LEN+LLC_TYPE_LEN)

#define LLC_LIADDR_LEN	(LLC_ADDR_LEN+LLC_SAP_LEN)
#define LLC_ENADDR_LEN  (LLC_ADDR_LEN+LLC_TYPE_LEN)

union llc_bind_fmt {
   struct llca {
      unsigned char  lbf_addr[LLC_ADDR_LEN];
      unsigned short lbf_sap;
   } llca;
   struct llcb {
      unsigned char  lbf_addr[LLC_ADDR_LEN];
      unsigned short lbf_sap;
      unsigned long  lbf_xsap;
      unsigned long  lbf_type;
   } llcb;
   struct llcc {
      unsigned char lbf_addr[LLC_ADDR_LEN];
      unsigned char lbf_sap;
   } llcc;
};

#define LLC_LENGTH(m)	ntohs(((struct wd_machdr *)m)->mac_llc.llc.llc_length)
#define LLC_DSAP(m)	(((struct wd_machdr *)m)->mac_llc.llc.llc_dsap)
#define LLC_SSAP(m)	(((struct wd_machdr *)m)->mac_llc.llc.llc_ssap)
#define LLC_CONTROL(m)	(((struct wd_machdr *)m)->mac_llc.llc.llc_control)

#define ETHER_TYPE(m)	ntohs(((struct wd_machdr *)m)->mac_llc.ether.ether_type)

#define WDMAXSAPVALUE	0xFF	/* larges LSAP value */

/* other useful macros */

#define HIGH(x) ((x>>8)&0xFF)
#define LOW(x)	(x&0xFF)

/* recoverable error conditions */

#define WDE_OK		0	/* normal condition */
#define WDE_NOBUFFER	1	/* couldn't allocb */
#define WDE_INVALID	2	/* operation isn't valid at this time */
#define WDE_BOUND	3	/* stream is already bound */
#define WDE_BLOCKED	4	/* blocked at next queue */

/* LLC specific data - should be in separate header (later) */

#define LLC_UI		0x03	/* unnumbered information field */
#define LLC_XID		0xAF	/* XID with P == 0 */
#define LLC_TEST	0xE3	/* TEST with P == 0 */

#define LLC_P		0x10	/* P bit for use with XID/TEST */
#define LLC_XID_FMTID	0x81	/* XID format identifier */
#define LLC_SERVICES	0x01	/* Services supported */
#define LLC_GLOBAL_SAP	0XFF	/* Global SAP address */
#define LLC_GROUP_ADDR	0x01	/* indication in DSAP of a group address */
#define LLC_RESPONSE	0x01	/* indication in SSAP of a response */

#define LLC_XID_INFO_SIZE	3 /* length of the INFO field */

struct rcv_buf {
	unsigned char	status;
	unsigned char	nxtpg;
	short		datalen;
	machdr_t	pkthdr;
};

typedef struct rcv_buf rcv_buf_t;

/*
 * WD 800X event statistics
 */

struct wdstats {
   /* transmit */
   ulong	wds_xpkts;	/* 0 */
   ulong	wds_xbytes;	/* 1 */
   ulong	wds_excoll;	/* 2 */
   ulong	wds_coll;	/* 3 */
   ulong	wds_fifounder;	/* 4 */
   ulong	wds_carrier;	/* 5 */

   /* receive */
   ulong	wds_rpkts;	/* 6 */
   ulong	wds_rbytes;	/* 7 */
   ulong	wds_crc;	/* 8 */
   ulong	wds_align;	/* 9 */
   ulong	wds_fifoover;	/* 10 */
   ulong	wds_lost;	/* 11 */
   ulong	wds_multicast;	/* 12 */

   /* non-hardware */
   ulong	wds_nobuffer;	/* 13 */
   ulong	wds_blocked;	/* 14 */
   ulong	wds_blocked2;	/* 15 */
};

/* ioctl functions to board */
/* NET_ names are for WD/ViaNet compatibility */

#define NET_INIT	(('D' << 8) | 1)
#define NET_UNINIT	(('D' << 8) | 2)
#define NET_GETBROAD	(('D' << 8) | 3)
#define DLGBROAD	(('D' << 8) | 3)
#define NET_GETSTATUS	(('D' << 8) | 4)
#define DLGSTAT		(('D' << 8) | 4)
#define NET_ADDR	(('D' << 8) | 5)
#define DLGADDR		(('D' << 8) | 5)
#define NET_SETPROM	(('D' << 8) | 6)
#define DLPROM		(('D' << 8) | 6)
#define DLSADDR		(('D' << 8) | 7)
#define NET_WDBRDTYPE	(('D' << 8) | 8)
#define NET_WDSTATUS	(('D' << 8) | 9)
