/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident	"$Header: wp.h 1.6 89/10/23 $"

#ifndef	_SYS_WP_H_

/*
 * wp.h
 *	SSM-based parallel printer port command block and definitions.
 *
 * There are two CBs used for each parallel port:
 *    transmit and message-passing.
 */

/* $Log:	wp.h,v $
 */

struct wp_printer {
	int	wp_width;
	int	wp_ops;
	unchar	wp_interface;		/* flag for Centronics or DataProducts */
};

/* 
 * Printer port control structure.  One allocated per SSM printer port. 
 */

struct	wp_info {
	struct	ssm_desc  *wp_ssm;	/* description of ssm */
	short	wp_devno;		/* device number */
	unchar  wp_alive;		/* device is alive */
	queue_t	*wp_qptr;		/* pointer to write queue */
	mblk_t	*wp_msg;
	int	wp_timeid;
	unchar	wp_state;		/* state flags below */
	unchar	wp_ops;		/* character mapping mode */
	uint	wp_width;		/* page width */
	lock_t	wp_lock;		/* lock access */
	sema_t	wp_sema;		/* wait on events */ 
	int	wp_count;		/* count of chars in buffer */
	char	*wp_buf;		/* transmit pointer */
};

/*
 * State flags
 */
#define	WP_OPEN		0x01		/* device open */
#define WP_WOPEN	0x02		/* open in progress */ 
#define	WP_BUSY		0x04		/* device busy */
#define WP_TIMER	0x08		/* device ready */
#define WP_ERROR	0x10		/* printer error detected */
#define WP_DATAOUT	0x20		/* asynchronous I/O outstanding */

/*
 * Miscellaneous
 */
#define FORMFEED	'\f'		/* form feed char */
#define WP_SPL		SPL5		/* interrupt level of wp */ 
#define WPRBSIZE	100		/* size of staging buffer (on stack)*/
#define WP_BUFSIZE	4096		/* wp buffer size in bytes */
#define WPLONGLINE	1000		/* maximum line length */

/*
 * Hardware related defines
 */
#define	PCB_PORT0	0		/* only 1 printer port */

/*
 * Vectors for interrupts to SSM
 */
#define	PCB_XMIT_V	1		/* xmit */
#define	PCB_MSG_V	2		/* message */
#define PCB_FLUSH_V	3		/* flush */
/* Number of interrupt vectors per unit for outgoing interrupts */
#define NVEC_TO_SSM	4	
#define NVECSHIFT	2		/* log2(NVEC_TO_SSM) */

/*
 * Vectors for interrupts from SSM
 */
#define PCB_XMIT_COMPLETE	0	/* xmit complete */
#define PCB_READY		1	/* lp ready */
/* Number of interrupt vectors per unit for incoming interrupts */
#define NVEC_FROM_SSM		2

/*
 * Command block indices
 */
#define PCB_XMIT_CB	0		/* xmit */
#define PCB_MSG_CB	1		/* message */

#define PRINT_BASE_CB(base,dev)  ((base) + ((dev) * NCBPERPRINT))

/*
 * Given vector type 
 * compute SLIC interrupt vector
 */
#define	PRVEC(cbfunc)	(((PCB_PORT0) << NVECSHIFT) | (cbfunc))

/* 
 * cb_cmd values 
 */
#define	PCB_IENABLE	0x80		/* enable interrupts */
#define	PCB_CMD_MASK	0x0F		/* command bits */
#define	    PCB_XMIT	0x00		/* transmit data specified */
#define	    PCB_GSTAT	0x01		/* get interface line status */
#define	    PCB_INIT	0x02		/* init interrupt generation */
#define     PCB_FLUSH	0x04		/* flush current data */

/* 
 * cb_status values 
 */
#define	PCB_BUSY	0x00		/* working on command */
#define	PCB_OK		0x01		/* completed OK */
#define	PCB_ERR		0x02		/* completed due to ERROR line */
					/*    asserted by printer.     */
/*
 * Transmit CB 
 */
struct print_xcb {
	ulong	xcb_reserved;		/* reserved for Sequent use */
	ulong	xcb_addr;		/* physical addr of cblock */
	unchar	xcb_fill[3];		/* fill to PCB_SHSIZ bytes */
	unchar  xcb_pstatus;		/* printer status */
	ushort	xcb_count;		/* transfer count */
	unchar	xcb_cmd;		/* command byte */
	unchar	xcb_status;		/* xfer status */

	/* start of sw-only part */
	ulong	xcb_sw[PCB_SWSIZ/sizeof(ulong)];
};

/*
 * Message CB : get printer interface line status
 */
struct print_mcb {
	ulong	mcb_reserved;		/* reserved for Sequent use */
	unchar	mcb_fill[8];		/* pad to PCB_SHSIZ bytes */
	ushort	mcb_iface;		/* interface line status */
	unchar	mcb_cmd;		/* command byte */
	unchar	mcb_status;		/* command status */

	/* start of sw-only part */
	ulong	mcb_sw[PCB_SWSIZ/sizeof(ulong)];
};

/* 
 * mcb_iface values 
 */
#define	PCM_PE    	0x0001		/* Printer detected a PAPER ERROR */
#define	PCM_OFFLINE	0x0002		/* Printer is OFFLINE */ 
#define	PCM_ERR		0x0004		/* Printer detected an ERROR */

#define PCM_READY	0x0000		/* NOT(any of above bit fields) */

/*
 * Message CB : interrupt generation
 */
struct print_icb {
	ulong	icb_reserved;		/* reserved for Sequent use */
	unchar	icb_scmd;		/* SLIC command for interrupts */
	unchar	icb_dest;		/* SLIC dest for interrupts */
	unchar	icb_basevec;		/* SLIC base vector for intrs */
	unchar	icb_interface;		/* type of printer interface */
	unchar	icb_fill[6];		/* pad to PCB_SHSIZ bytes */
	unchar	icb_cmd;		/* command byte */
	unchar	icb_status;		/* xfer status */

	/* start of sw-only part */
	ulong	icb_sw[PCB_SWSIZ/sizeof(ulong)];
};

/*
 * icb_interface values
 */
#define ICB_CENTRON	0				/* Centronics interface */
#define ICB_DATAP	1				/* Data Products interface */

#define	_SYS_WP_H_
#endif	/* _SYS_WP_H_ */
