/*
 * This file is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify this file without charge, but are not authorized to
 * license or distribute it to anyone else except as part of a product
 * or program developed by the user.
 *
 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 *
 * This file is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 *
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
 * OR ANY PART THEREOF.
 *
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even
 * if Sun has been advised of the possibility of such damages.
 *
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

#pragma ident	"@(#)psli.h	1.2	94/06/22 Sun Microsystems Inc."

#ifdef  __cplusplus
extern "C" {
#endif

/*
 * psli.h header for the Sample Streams DLPI Driver
 */

/*
 * XXX Note that values used for #defines are bogus. You need to use
 * values that are appropriate for your driver/device. Also feel free
 * to add fields in the structs defined in this file.
 */

/*
 * XXX Declarations specific to the medium
 */

#define	MEDIUM_MTU	(1500)		/* max frame w/o header */
#define	MEDIUM_MIN	(60)		/* max frame w/header w/o fcs */
#define	MEDIUM_MAX	(1514)		/* max frame w/header w/o fcs */


#define	MEDIUMTYPE_MAX	(0xffff)	/* max valid medium type */

/*
 * XXX Medium address length
 */

#define	MEDIUM_ADDRL		(25)

/*
 * XXX structure for the medium specific address
 */

struct medium_addr {
	u_char medaddr[MEDIUM_ADDRL];
};

/*
 * XXX structure for the medium specific header
 */

struct medium_header {
	struct 	medium_addr	med_dhost;
	struct 	medium_addr	med_shost;
	u_short med_type;
};

/*
 * XXX Maximum # of multicast address per Stream
 */

#define	DEVMAXMC	64
#define	DEVMCALLOC	(DEVMAXMC * sizeof (struct medium_addr))

/*
 * XXX Declarations and definitions specific to the device. Add fields
 * as necessary.
 */

struct psliregs {
	u_short	regstuff;
};


/*
 * XXX Definitions for modupsli_info.
 * Fill in values appropriate for your driver.
 * Contact USL to obtain a unique "registered" module ID number
 */

#define	PSLIIDNUM	(999)	/* module ID number */
#define	PSLINAME	"psli"	/* module name */
#define	PSLIMINPSZ	(0)	/* min packet size */
#define	PSLIMAXPSZ	64	/* max packet size */
#define	PSLIHIWAT	(65536)	/* hi-water mark */
#define	PSLILOWAT	(1)	/* lo-water mark */


/*
 * Per-Stream instance state information.
 *
 * Each instance is dynamically allocated at open() and free'd at
 * close(). Each per-stream instance points to at most one per-device
 * structure using the sl_pslip field. All instances are threaded
 * together into one list of active instances ordered on minor device
 * number.
 */

struct pslistr {
	struct pslistr *sl_nextp;	/* next in list */
	queue_t *sl_rq;			/* ptr to our rq */
	struct psli *sl_pslip;		/* attached device */
	u_long sl_state;		/* current state */
	u_long sl_sap;			/* bound sap */
	u_long sl_flags;		/* misc flags */
	u_int  sl_mccount;		/* # enabled multicast addrs */
	struct medium_addr *sl_mctab;	/* table of multicast addrs */
	u_long sl_minor;		/* minor device number */
	kmutex_t sl_lock;		/* protect this struct */
};


/* per-stream flags */
#define	SLRAW		0x02	/* M_DATA plain raw mode */
#define	SLALLPHYS	0x04	/* "promiscuous mode" */
#define	SLALLMULTI	0x08	/* enable all multicast addresses */
#define	SLALLSAP	0x10	/* enable all ether type values */

/*
 * Per-Device instance state information.
 *
 * Each instance is dynamically allocated on first attach.
 */
struct  psli {
	struct psli	*psli_nextp; 	/* next in linked list */
	volatile struct psliregs *psli_regsp; /* addr of register set */
	dev_info_t	*psli_dip;	/* dev info */
	struct medium_addr *psli_ouraddr; /* XXX individual address */
	u_int		psli_flags;	/* misc. flags */
	u_int		psli_wantw;	/* out of resources */
	kmutex_t	psli_xmitlock;	/* protect xmit side */
	kmutex_t	psli_intrlock;	/* protect intr side */
	caddr_t		psli_arg;	/* device specific arg */
	ddi_iblock_cookie_t iblock_cookie; /* cookie for intr */

	/* counters to keep stats for netstat support */
	ulong_t psli_ipackets;		/* # packets received */
	ulong_t psli_ierrors;		/* # total input errors */
	ulong_t psli_opackets;		/* # packets sent */
	ulong_t psli_oerrors;		/* # total output errors */
	ulong_t psli_collisions;	/* # collisions */
};

/* flags */
#define	PSLIRUNNING	0x01	/* chip is initialized */
#define	PSLISLAVE	0x02	/* slave device (no DMA) */
#define	PSLIPROMISC	0x04	/* promiscuous mode enabled */


/*
 * XXX Define offset to receive descriptor.
 */

#define	PSLIHEADROOM	34

/*
 * Private DLPI full dlsap address format.
 * You need to specify a physical address (dl_phys) appropriate for
 * your medium
 */


struct pslidladdr {
	struct medium_addr	dl_phys;
	u_short dl_sap;
};

/*
 * Full DLSAP address length
 * You need to customize this based on your dladdr struct.
 */

#define	DEVICE_ADDRL (sizeof (u_short) + MEDIUM_ADDRL)

#define	DLADDRL	(80)

#ifdef KSTAT

/*
 * "Export" a few of the error counters via the kstats mechanism.
 */
struct  pslistat {
	struct kstat_named les_ipackets;
	struct kstat_named les_ierrors;
	struct kstat_named les_opackets;
	struct kstat_named les_oerrors;
	struct kstat_named les_collisions;
};

#endif KSTAT

/* Some streams defines */

#define	DB_BASE(mp)		((mp)->b_datap->db_base)
#define	DB_LIM(mp)		((mp)->b_datap->db_lim)
#define	DB_REF(mp)		((mp)->b_datap->db_ref)
#define	DB_TYPE(mp)		((mp)->b_datap->db_type)

#define	MBLKL(mp)		((mp)->b_wptr - (mp)->b_rptr)
#define	MBLKSIZE(mp)	((mp)->b_datap->db_lim - (mp)->b_datap->db_base)
#define	MBLKHEAD(mp)	((mp)->b_rptr - (mp)->b_datap->db_base)
#define	MBLKTAIL(mp)	((mp)->b_datap->db_lim - (mp)->b_wptr)
#define	MBLKIN(mp, off, len)	(((mp)->b_rptr + off + len) <= (mp)->b_wptr)

#define	OFFSET(base, p)	((caddr_t)(p) - (caddr_t)(base))

#ifdef  __cplusplus
}
#endif
