xref: /titanic_51/usr/src/uts/common/sys/ecppvar.h (revision 08ec77c5d4647cce340afb3d6cba733d508e7e94)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_ECPPVAR_H
287c478bd9Sstevel@tonic-gate #define	_SYS_ECPPVAR_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/note.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate struct ecppunit;
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Hardware-abstraction structure
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate struct ecpp_hw {
427c478bd9Sstevel@tonic-gate 	int	(*map_regs)(struct ecppunit *);		/* map registers */
437c478bd9Sstevel@tonic-gate 	void	(*unmap_regs)(struct ecppunit *);	/* unmap registers */
447c478bd9Sstevel@tonic-gate 	int	(*config_chip)(struct ecppunit *);	/* configure SuperIO */
457c478bd9Sstevel@tonic-gate 	void	(*config_mode)(struct ecppunit *);	/* config new mode */
467c478bd9Sstevel@tonic-gate 	void	(*mask_intr)(struct ecppunit *);	/* mask interrupts */
477c478bd9Sstevel@tonic-gate 	void	(*unmask_intr)(struct ecppunit *);	/* unmask interrupts */
487c478bd9Sstevel@tonic-gate 	int	(*dma_start)(struct ecppunit *);	/* start DMA transfer */
497c478bd9Sstevel@tonic-gate 	int	(*dma_stop)(struct ecppunit *, size_t *); /* stop DMA xfer */
507c478bd9Sstevel@tonic-gate 	size_t	(*dma_getcnt)(struct ecppunit *);	/* get DMA counter */
517c478bd9Sstevel@tonic-gate 	ddi_dma_attr_t	*attr;				/* DMA attributes */
527c478bd9Sstevel@tonic-gate };
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #define	ECPP_MAP_REGS(pp)		(pp)->hw->map_regs(pp)
557c478bd9Sstevel@tonic-gate #define	ECPP_UNMAP_REGS(pp)		(pp)->hw->unmap_regs(pp)
567c478bd9Sstevel@tonic-gate #define	ECPP_CONFIG_CHIP(pp)		(pp)->hw->config_chip(pp)
577c478bd9Sstevel@tonic-gate #define	ECPP_CONFIG_MODE(pp)		(pp)->hw->config_mode(pp)
587c478bd9Sstevel@tonic-gate #define	ECPP_MASK_INTR(pp)		(pp)->hw->mask_intr(pp)
597c478bd9Sstevel@tonic-gate #define	ECPP_UNMASK_INTR(pp)		(pp)->hw->unmask_intr(pp)
607c478bd9Sstevel@tonic-gate #define	ECPP_DMA_START(pp)		(pp)->hw->dma_start(pp)
617c478bd9Sstevel@tonic-gate #define	ECPP_DMA_STOP(pp, cnt)		(pp)->hw->dma_stop(pp, cnt)
627c478bd9Sstevel@tonic-gate #define	ECPP_DMA_GETCNT(pp)		(pp)->hw->dma_getcnt(pp)
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /* NSC 87332/97317 and EBus DMAC */
657c478bd9Sstevel@tonic-gate struct ecpp_ebus {
667c478bd9Sstevel@tonic-gate 	struct config_reg	*c_reg; 	/* configuration registers */
677c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	c_handle;	/* handle for conf regs */
687c478bd9Sstevel@tonic-gate 	struct cheerio_dma_reg	*dmac;		/* ebus dmac registers */
697c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	d_handle;	/* handle for dmac registers */
707c478bd9Sstevel@tonic-gate 	struct config2_reg	*c2_reg; 	/* 97317 2nd level conf regs */
717c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	c2_handle;	/* handle for c2_reg */
727c478bd9Sstevel@tonic-gate };
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /* Southbridge SuperIO and 8237 DMAC */
757c478bd9Sstevel@tonic-gate struct ecpp_m1553 {
767c478bd9Sstevel@tonic-gate 	struct isaspace		*isa_space;	/* all of isa space */
777c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	d_handle;	/* handle for isa space */
787c478bd9Sstevel@tonic-gate 	uint8_t			chn;		/* 8237 dma channel */
797c478bd9Sstevel@tonic-gate 	int			isadma_entered;	/* Southbridge DMA workaround */
807c478bd9Sstevel@tonic-gate };
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #if defined(__x86)
837c478bd9Sstevel@tonic-gate struct ecpp_x86 {
847c478bd9Sstevel@tonic-gate 	uint8_t			chn;
857c478bd9Sstevel@tonic-gate };
867c478bd9Sstevel@tonic-gate #endif
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Hardware binding structure
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate struct ecpp_hw_bind {
927c478bd9Sstevel@tonic-gate 	char		*name;		/* binding name */
937c478bd9Sstevel@tonic-gate 	struct ecpp_hw	*hw;		/* hw description */
947c478bd9Sstevel@tonic-gate 	char		*info;		/* info string */
957c478bd9Sstevel@tonic-gate };
967c478bd9Sstevel@tonic-gate 
97*08ec77c5SRichard Lowe /* ecpp e_busy states */
98*08ec77c5SRichard Lowe typedef enum {
99*08ec77c5SRichard Lowe 	ECPP_IDLE = 1,	/* No ongoing transfers */
100*08ec77c5SRichard Lowe 	ECPP_BUSY = 2,	/* Ongoing transfers on the cable */
101*08ec77c5SRichard Lowe 	ECPP_DATA = 3,	/* Not used */
102*08ec77c5SRichard Lowe 	ECPP_ERR = 4,	/* Bad status in Centronics mode */
103*08ec77c5SRichard Lowe 	ECPP_FLUSH = 5	/* Currently flushing the q */
104*08ec77c5SRichard Lowe } ecpp_busy_t;
105*08ec77c5SRichard Lowe 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * ecpp soft state structure
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate struct ecppunit {
1107c478bd9Sstevel@tonic-gate 	kmutex_t	umutex;		/* lock for this structure */
1117c478bd9Sstevel@tonic-gate 	int		instance;	/* instance number */
1127c478bd9Sstevel@tonic-gate 	dev_info_t	*dip;		/* device information */
1137c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t ecpp_trap_cookie;	/* interrupt cookie */
114*08ec77c5SRichard Lowe 	ecpp_busy_t	e_busy;		/* ecpp busy flag */
1157c478bd9Sstevel@tonic-gate 	kcondvar_t	pport_cv;	/* cv to signal idle state */
1167c478bd9Sstevel@tonic-gate 	/*
1177c478bd9Sstevel@tonic-gate 	 * common SuperIO registers
1187c478bd9Sstevel@tonic-gate 	 */
1197c478bd9Sstevel@tonic-gate 	struct info_reg		*i_reg; 	/* info registers */
1207c478bd9Sstevel@tonic-gate 	struct fifo_reg		*f_reg; 	/* fifo register */
1217c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	i_handle;
1227c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	f_handle;
1237c478bd9Sstevel@tonic-gate 	/*
1247c478bd9Sstevel@tonic-gate 	 * DMA support
1257c478bd9Sstevel@tonic-gate 	 */
1267c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t	dma_handle;	/* DMA handle */
1277c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t	dma_cookie;	/* current cookie */
1287c478bd9Sstevel@tonic-gate 	uint_t			dma_cookie_count;	/* # of cookies */
1297c478bd9Sstevel@tonic-gate 	uint_t			dma_nwin;	/* # of DMA windows */
1307c478bd9Sstevel@tonic-gate 	uint_t			dma_curwin;	/* current window number */
1317c478bd9Sstevel@tonic-gate 	uint_t			dma_dir;	/* transfer direction */
1327c478bd9Sstevel@tonic-gate 	/*
1337c478bd9Sstevel@tonic-gate 	 * hardware-dependent stuff
1347c478bd9Sstevel@tonic-gate 	 */
1357c478bd9Sstevel@tonic-gate 	struct ecpp_hw	*hw;		/* operations/attributes */
1367c478bd9Sstevel@tonic-gate 	union {				/* hw-dependent data */
1377c478bd9Sstevel@tonic-gate 		struct ecpp_ebus	ebus;
1387c478bd9Sstevel@tonic-gate 		struct ecpp_m1553	m1553;
1397c478bd9Sstevel@tonic-gate #if defined(__x86)
1407c478bd9Sstevel@tonic-gate 		struct ecpp_x86 	x86;
1417c478bd9Sstevel@tonic-gate #endif
1427c478bd9Sstevel@tonic-gate 	} uh;
1437c478bd9Sstevel@tonic-gate 	/*
1447c478bd9Sstevel@tonic-gate 	 * DDI/STREAMS stuff
1457c478bd9Sstevel@tonic-gate 	 */
1467c478bd9Sstevel@tonic-gate 	boolean_t	oflag;		/* instance open flag */
1477c478bd9Sstevel@tonic-gate 	queue_t		*readq;		/* pointer to readq */
1487c478bd9Sstevel@tonic-gate 	queue_t		*writeq;	/* pointer to writeq */
1497c478bd9Sstevel@tonic-gate 	mblk_t		*msg;		/* current message block */
1507c478bd9Sstevel@tonic-gate 	boolean_t	suspended;	/* driver suspended status */
1517c478bd9Sstevel@tonic-gate 	/*
1527c478bd9Sstevel@tonic-gate 	 * Modes of operation
1537c478bd9Sstevel@tonic-gate 	 */
1547c478bd9Sstevel@tonic-gate 	int		current_mode;	/* 1284 mode */
1557c478bd9Sstevel@tonic-gate 	uchar_t		current_phase;	/* 1284 phase */
1567c478bd9Sstevel@tonic-gate 	uchar_t		backchannel;	/* backchannel mode supported */
1577c478bd9Sstevel@tonic-gate 	uchar_t		io_mode;	/* transfer mode: PIO/DMA */
1587c478bd9Sstevel@tonic-gate 	/*
1597c478bd9Sstevel@tonic-gate 	 * Ioctls support
1607c478bd9Sstevel@tonic-gate 	 */
1617c478bd9Sstevel@tonic-gate 	struct ecpp_transfer_parms xfer_parms;	/* transfer parameters */
1627c478bd9Sstevel@tonic-gate 	struct ecpp_regs regs;		/* control/status registers */
1637c478bd9Sstevel@tonic-gate 	uint8_t		saved_dsr;	/* store the dsr returned from TESTIO */
1647c478bd9Sstevel@tonic-gate 	boolean_t	timeout_error;	/* store the timeout for GETERR */
1657c478bd9Sstevel@tonic-gate 	uchar_t		port;		/* xfer type: dma/pio/tfifo */
1667c478bd9Sstevel@tonic-gate 	struct prn_timeouts prn_timeouts; /* prnio timeouts */
1677c478bd9Sstevel@tonic-gate 	/*
1687c478bd9Sstevel@tonic-gate 	 * ecpp.conf parameters
1697c478bd9Sstevel@tonic-gate 	 */
1707c478bd9Sstevel@tonic-gate 	uchar_t		init_seq;	/* centronics init seq */
1717c478bd9Sstevel@tonic-gate 	uint32_t	wsrv_retry;	/* delay (ms) before next wsrv */
1727c478bd9Sstevel@tonic-gate 	uint32_t	wait_for_busy;	/* wait for BUSY to deassert */
1737c478bd9Sstevel@tonic-gate 	uint32_t	data_setup_time; /* pio centronics handshake */
1747c478bd9Sstevel@tonic-gate 	uint32_t	strobe_pulse_width; /* pio centronics handshake */
1757c478bd9Sstevel@tonic-gate 	uint8_t		fast_centronics; /* DMA/PIO centronics */
1767c478bd9Sstevel@tonic-gate 	uint8_t		fast_compat;	/* DMA/PIO 1284 compatible mode */
1777c478bd9Sstevel@tonic-gate 	uint32_t	ecp_rev_speed;	/* rev xfer speed in ECP, bytes/sec */
1787c478bd9Sstevel@tonic-gate 	uint32_t	rev_watchdog;	/* rev xfer watchdog period, ms */
1797c478bd9Sstevel@tonic-gate 	/*
1807c478bd9Sstevel@tonic-gate 	 * Timeouts
1817c478bd9Sstevel@tonic-gate 	 */
1827c478bd9Sstevel@tonic-gate 	timeout_id_t	timeout_id;	/* io transfers timer */
1837c478bd9Sstevel@tonic-gate 	timeout_id_t	fifo_timer_id;	/* drain SuperIO FIFO */
1847c478bd9Sstevel@tonic-gate 	timeout_id_t	wsrv_timer_id;	/* wsrv timeout */
1857c478bd9Sstevel@tonic-gate 	/*
1867c478bd9Sstevel@tonic-gate 	 * Softintr data
1877c478bd9Sstevel@tonic-gate 	 */
1887c478bd9Sstevel@tonic-gate 	ddi_softintr_t	softintr_id;
1897c478bd9Sstevel@tonic-gate 	int		softintr_flags;	/* flags indicating softintr task */
1907c478bd9Sstevel@tonic-gate 	uint8_t		softintr_pending;
1917c478bd9Sstevel@tonic-gate 	/*
1927c478bd9Sstevel@tonic-gate 	 * Misc stuff
1937c478bd9Sstevel@tonic-gate 	 */
1947c478bd9Sstevel@tonic-gate 	caddr_t		ioblock;	/* transfer buffer block */
1957c478bd9Sstevel@tonic-gate 	size_t		xfercnt;	/* # of bytes to transfer */
1967c478bd9Sstevel@tonic-gate 	size_t		resid;		/* # of bytes not transferred */
1977c478bd9Sstevel@tonic-gate 	caddr_t		next_byte;	/* next byte for PIO transfer */
1987c478bd9Sstevel@tonic-gate 	caddr_t		last_byte;	/* last byte for PIO transfer */
1997c478bd9Sstevel@tonic-gate 	uint32_t	ecpp_drain_counter;	/* allows fifo to drain */
2007c478bd9Sstevel@tonic-gate 	uchar_t		dma_cancelled;	/* flushed while dma'ing */
2017c478bd9Sstevel@tonic-gate 	uint8_t		tfifo_intr;	/* TFIFO switch interrupt workaround */
2027c478bd9Sstevel@tonic-gate 	size_t		nread;		/* requested read */
2037c478bd9Sstevel@tonic-gate 	size_t		last_dmacnt;	/* DMA counter value for rev watchdog */
2047c478bd9Sstevel@tonic-gate 	uint32_t	rev_timeout_cnt; /* number of watchdog invocations */
2057c478bd9Sstevel@tonic-gate 	/*
2067c478bd9Sstevel@tonic-gate 	 * Spurious interrupt detection
2077c478bd9Sstevel@tonic-gate 	 */
2087c478bd9Sstevel@tonic-gate 	hrtime_t	lastspur;	/* last time spurious intrs started */
2097c478bd9Sstevel@tonic-gate 	long		nspur;		/* spurious intrs counter */
2107c478bd9Sstevel@tonic-gate 	/*
2117c478bd9Sstevel@tonic-gate 	 * Statistics
2127c478bd9Sstevel@tonic-gate 	 */
2137c478bd9Sstevel@tonic-gate 	kstat_t		*ksp;		/* kstat pointer */
2147c478bd9Sstevel@tonic-gate 	kstat_t		*intrstats;	/* kstat interrupt counter */
2157c478bd9Sstevel@tonic-gate 	/*
2167c478bd9Sstevel@tonic-gate 	 * number of bytes, transferred in and out in each mode
2177c478bd9Sstevel@tonic-gate 	 */
2187c478bd9Sstevel@tonic-gate 	uint32_t	ctxpio_obytes;
2197c478bd9Sstevel@tonic-gate 	uint32_t	obytes[ECPP_EPP_MODE+1];
2207c478bd9Sstevel@tonic-gate 	uint32_t	ibytes[ECPP_EPP_MODE+1];
2217c478bd9Sstevel@tonic-gate 	/*
2227c478bd9Sstevel@tonic-gate 	 * other stats
2237c478bd9Sstevel@tonic-gate 	 */
2247c478bd9Sstevel@tonic-gate 	uint32_t	to_mode[ECPP_EPP_MODE+1]; /* # transitions to mode */
2257c478bd9Sstevel@tonic-gate 	uint32_t	xfer_tout;	/* # transfer timeouts */
2267c478bd9Sstevel@tonic-gate 	uint32_t	ctx_cf;		/* # periph check failures */
2277c478bd9Sstevel@tonic-gate 	uint32_t	joblen;		/* of bytes xfer'd since open */
2287c478bd9Sstevel@tonic-gate 	uint32_t	isr_reattempt_high;	/* max times isr has looped */
2297c478bd9Sstevel@tonic-gate 	/*
2307c478bd9Sstevel@tonic-gate 	 * interrupt stats
2317c478bd9Sstevel@tonic-gate 	 */
2327c478bd9Sstevel@tonic-gate 	uint_t		intr_hard;
2337c478bd9Sstevel@tonic-gate 	uint_t		intr_spurious;
2347c478bd9Sstevel@tonic-gate 	uint_t		intr_soft;
2357c478bd9Sstevel@tonic-gate 	/*
2367c478bd9Sstevel@tonic-gate 	 * identify second register set for ecp mode on Sx86
2377c478bd9Sstevel@tonic-gate 	 */
2387c478bd9Sstevel@tonic-gate 	int		noecpregs;
2397c478bd9Sstevel@tonic-gate };
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ecppunit::umutex, ecppunit))
2427c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::dip))
2437c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::instance))
2447c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::i_reg))
2457c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::f_reg))
2467c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::i_handle))
2477c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::f_handle))
2487c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::ecpp_trap_cookie))
2497c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::readq))
2507c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(ecppunit::writeq))
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * current_phase values
2547c478bd9Sstevel@tonic-gate  */
2557c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_INIT		0x00	/* initialization */
2567c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_NEGO		0x01	/* negotiation */
2577c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_TERM		0x02	/* termination */
2587c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_PO		0x03	/* power-on */
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_C_FWD_DMA	0x10	/* cntrx/compat fwd dma xfer */
2617c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_C_FWD_PIO	0x11	/* cntrx/compat fwd PIO xfer */
2627c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_C_IDLE	0x12	/* cntrx/compat idle */
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_NIBT_REVDATA	0x20	/* nibble/byte reverse data */
2657c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_NIBT_AVAIL	0x21	/* nibble/byte reverse data available */
2667c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_NIBT_NAVAIL	0x22	/* nibble/byte reverse data not avail */
2677c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_NIBT_REVIDLE	0x22	/* nibble/byte reverse idle */
2687c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_NIBT_REVINTR	0x23	/* nibble/byte reverse interrupt */
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_ECP_SETUP	0x30	/* ecp setup */
2717c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_ECP_FWD_XFER	0x31	/* ecp forward transfer */
2727c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_ECP_FWD_IDLE	0x32	/* ecp forward idle */
2737c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_ECP_FWD_REV	0x33	/* ecp forward to reverse */
2747c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_ECP_REV_XFER	0x34	/* ecp reverse transfer */
2757c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_ECP_REV_IDLE	0x35	/* ecp reverse idle */
2767c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_ECP_REV_FWD	0x36	/* ecp reverse to forward */
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_EPP_INIT_IDLE 0x40	/* epp init phase */
2797c478bd9Sstevel@tonic-gate #define	ECPP_PHASE_EPP_IDLE	0x41	/* epp all-round phase */
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate #define	FAILURE_PHASE		0x80
2827c478bd9Sstevel@tonic-gate #define	UNDEFINED_PHASE		0x81
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate /* ecpp return values */
2857c478bd9Sstevel@tonic-gate #define	SUCCESS		1
2867c478bd9Sstevel@tonic-gate #define	FAILURE		2
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate #define	TRUE		1
2897c478bd9Sstevel@tonic-gate #define	FALSE		0
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /* message type */
2927c478bd9Sstevel@tonic-gate #define	ECPP_BACKCHANNEL	0x45
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /* transfer modes */
2957c478bd9Sstevel@tonic-gate #define	ECPP_DMA		0x1
2967c478bd9Sstevel@tonic-gate #define	ECPP_PIO		0x2
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate /* tuneable timing defaults */
2997c478bd9Sstevel@tonic-gate #define	CENTRONICS_RETRY	750	/* 750 milliseconds */
3007c478bd9Sstevel@tonic-gate #define	WAIT_FOR_BUSY		1000	/* 1000 microseconds */
3017c478bd9Sstevel@tonic-gate #define	SUSPEND_TOUT		10	/* # seconds before suspend fails */
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate /* Centronics hanshaking defaults */
3047c478bd9Sstevel@tonic-gate #define	DATA_SETUP_TIME		2	/* 2 uSec Data Setup Time (2x min) */
3057c478bd9Sstevel@tonic-gate #define	STROBE_PULSE_WIDTH	2	/* 2 uSec Strobe Pulse (2x min) */
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate /* 1284 Extensibility Request values */
3087c478bd9Sstevel@tonic-gate #define	ECPP_XREQ_NIBBLE	0x00    /* Nibble Mode Rev Channel Transfer */
3097c478bd9Sstevel@tonic-gate #define	ECPP_XREQ_BYTE		0x01    /* Byte Mode Rev Channel Transfer */
3107c478bd9Sstevel@tonic-gate #define	ECPP_XREQ_ID		0x04    /* Request Device ID */
3117c478bd9Sstevel@tonic-gate #define	ECPP_XREQ_ECP		0x10    /* Request ECP Mode */
3127c478bd9Sstevel@tonic-gate #define	ECPP_XREQ_ECPRLE	0x30    /* Request ECP Mode with RLE */
3137c478bd9Sstevel@tonic-gate #define	ECPP_XREQ_EPP		0x40	/* Request EPP Mode */
3147c478bd9Sstevel@tonic-gate #define	ECPP_XREQ_XLINK		0x80    /* Request Extensibility Link */
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate /* softintr flags */
3177c478bd9Sstevel@tonic-gate #define	ECPP_SOFTINTR_PIONEXT	0x1	/* write next byte in PIO mode */
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate /* Stream  defaults */
3207c478bd9Sstevel@tonic-gate #define	IO_BLOCK_SZ	1024 * 128	/* transfer buffer size */
3217c478bd9Sstevel@tonic-gate #define	ECPPHIWAT	32 * 1024  * 6
3227c478bd9Sstevel@tonic-gate #define	ECPPLOWAT	32 * 1024  * 4
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate /* Loop timers */
3257c478bd9Sstevel@tonic-gate #define	ECPP_REG_WRITE_MAX_LOOP	100	/* cpu is faster than superio */
3267c478bd9Sstevel@tonic-gate #define	ECPP_ISR_MAX_DELAY	30	/* DMAC slow PENDING status */
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate /* misc constants */
3297c478bd9Sstevel@tonic-gate #define	ECPP_FIFO_SZ		16	/* FIFO size */
3307c478bd9Sstevel@tonic-gate #define	FIFO_DRAIN_PERIOD	250000	/* max FIFO drain period in usec */
3317c478bd9Sstevel@tonic-gate #define	NIBBLE_REV_BLKSZ	1024	/* send up to # bytes at a time */
3327c478bd9Sstevel@tonic-gate #define	FWD_TIMEOUT_DEFAULT	90	/* forward xfer timeout in seconds */
3337c478bd9Sstevel@tonic-gate #define	REV_TIMEOUT_DEFAULT	0	/* reverse xfer timeout in seconds */
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate /* ECP mode constants */
3367c478bd9Sstevel@tonic-gate #define	ECP_REV_BLKSZ		1024	/* send up to # bytes at a time */
3377c478bd9Sstevel@tonic-gate #define	ECP_REV_BLKSZ_MAX	(4 * 1024)	/* maximum of # bytes */
3387c478bd9Sstevel@tonic-gate #define	ECP_REV_SPEED		(1 * 1024 * 1024)	/* bytes/sec */
3397c478bd9Sstevel@tonic-gate #define	ECP_REV_MINTOUT		5	/* min ECP rev xfer timeout in ms */
3407c478bd9Sstevel@tonic-gate #define	REV_WATCHDOG		100	/* poll DMA counter every # ms */
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate /* spurious interrupt detection */
3437c478bd9Sstevel@tonic-gate #define	SPUR_CRITICAL		100	/* number of interrupts... */
3447c478bd9Sstevel@tonic-gate #define	SPUR_PERIOD		1000000000 /* in # ns */
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate /*
3477c478bd9Sstevel@tonic-gate  * Copyin/copyout states
3487c478bd9Sstevel@tonic-gate  */
3497c478bd9Sstevel@tonic-gate #define	ECPP_STRUCTIN		0
3507c478bd9Sstevel@tonic-gate #define	ECPP_STRUCTOUT		1
3517c478bd9Sstevel@tonic-gate #define	ECPP_ADDRIN 		2
3527c478bd9Sstevel@tonic-gate #define	ECPP_ADDROUT		3
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate  * As other ioctls require the same structure, put inner struct's into union
3567c478bd9Sstevel@tonic-gate  */
3577c478bd9Sstevel@tonic-gate struct ecpp_copystate {
3587c478bd9Sstevel@tonic-gate 	int	state;		/* see above */
3597c478bd9Sstevel@tonic-gate 	void	*uaddr;		/* user address of the following structure */
3607c478bd9Sstevel@tonic-gate 	union {
3617c478bd9Sstevel@tonic-gate 		struct ecpp_device_id		devid;
3627c478bd9Sstevel@tonic-gate 		struct prn_1284_device_id	prn_devid;
3637c478bd9Sstevel@tonic-gate 		struct prn_interface_info	prn_if;
3647c478bd9Sstevel@tonic-gate 	} un;
3657c478bd9Sstevel@tonic-gate };
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate /*
3687c478bd9Sstevel@tonic-gate  * The structure is dynamically created for each M_IOCTL and is bound to mblk
3697c478bd9Sstevel@tonic-gate  */
3707c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", ecpp_copystate))
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate /* kstat structure */
3737c478bd9Sstevel@tonic-gate struct ecppkstat {
3747c478bd9Sstevel@tonic-gate 	/*
3757c478bd9Sstevel@tonic-gate 	 * number of bytes, transferred in and out in each mode
3767c478bd9Sstevel@tonic-gate 	 */
3777c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_ctx_obytes;
3787c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_ctxpio_obytes;
3797c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_nib_ibytes;
3807c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_ecp_obytes;
3817c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_ecp_ibytes;
3827c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_epp_obytes;
3837c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_epp_ibytes;
3847c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_diag_obytes;
3857c478bd9Sstevel@tonic-gate 	/*
3867c478bd9Sstevel@tonic-gate 	 * number of transitions to particular mode
3877c478bd9Sstevel@tonic-gate 	 */
3887c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_to_ctx;
3897c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_to_nib;
3907c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_to_ecp;
3917c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_to_epp;
3927c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_to_diag;
3937c478bd9Sstevel@tonic-gate 	/*
3947c478bd9Sstevel@tonic-gate 	 * other stats
3957c478bd9Sstevel@tonic-gate 	 */
3967c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_xfer_tout;	/* # transfer timeouts */
3977c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_ctx_cf;	/* # periph check failures */
3987c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_joblen;	/* # bytes xfer'd since open */
3997c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_isr_reattempt_high;	/* max # times */
4007c478bd9Sstevel@tonic-gate 							/* isr has looped */
4017c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_mode;	/* 1284 mode */
4027c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_phase;	/* 1284 ECP phase */
4037c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_backchan;	/* backchannel mode supported */
4047c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_iomode;	/* transfer mode: pio/dma */
4057c478bd9Sstevel@tonic-gate 	struct kstat_named	ek_state;	/* ecpp busy flag */
4067c478bd9Sstevel@tonic-gate };
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /* Macros for superio programming */
4097c478bd9Sstevel@tonic-gate #define	PP_PUTB(x, y, z)  	ddi_put8(x, y, z)
4107c478bd9Sstevel@tonic-gate #define	PP_GETB(x, y)		ddi_get8(x, y)
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate #define	DSR_READ(pp)		PP_GETB((pp)->i_handle, &(pp)->i_reg->dsr)
4137c478bd9Sstevel@tonic-gate #define	DCR_READ(pp)		PP_GETB((pp)->i_handle, &(pp)->i_reg->dcr)
4147c478bd9Sstevel@tonic-gate #define	ECR_READ(pp)		\
4157c478bd9Sstevel@tonic-gate 	(pp->noecpregs) ? 0xff : PP_GETB((pp)->f_handle, &(pp)->f_reg->ecr)
4167c478bd9Sstevel@tonic-gate #define	DATAR_READ(pp)		PP_GETB((pp)->i_handle, &(pp)->i_reg->ir.datar)
4177c478bd9Sstevel@tonic-gate #define	DFIFO_READ(pp)		\
4187c478bd9Sstevel@tonic-gate 	(pp->noecpregs) ? 0xff : PP_GETB((pp)->f_handle, &(pp)->f_reg->fr.dfifo)
4197c478bd9Sstevel@tonic-gate #define	TFIFO_READ(pp)		\
4207c478bd9Sstevel@tonic-gate 	(pp->noecpregs) ? 0xff : PP_GETB((pp)->f_handle, &(pp)->f_reg->fr.tfifo)
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate #define	DCR_WRITE(pp, val)	PP_PUTB((pp)->i_handle, &(pp)->i_reg->dcr, val)
4237c478bd9Sstevel@tonic-gate #define	ECR_WRITE(pp, val)	\
4247c478bd9Sstevel@tonic-gate 	if (!pp->noecpregs) PP_PUTB((pp)->f_handle, &(pp)->f_reg->ecr, val)
4257c478bd9Sstevel@tonic-gate #define	DATAR_WRITE(pp, val)	\
4267c478bd9Sstevel@tonic-gate 			PP_PUTB((pp)->i_handle, &(pp)->i_reg->ir.datar, val)
4277c478bd9Sstevel@tonic-gate #define	DFIFO_WRITE(pp, val)	\
4287c478bd9Sstevel@tonic-gate 	if (!pp->noecpregs) PP_PUTB((pp)->f_handle, &(pp)->f_reg->fr.dfifo, val)
4297c478bd9Sstevel@tonic-gate #define	TFIFO_WRITE(pp, val)	\
4307c478bd9Sstevel@tonic-gate 	if (!pp->noecpregs) PP_PUTB((pp)->f_handle, &(pp)->f_reg->fr.tfifo, val)
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * Macros to manipulate register bits
4347c478bd9Sstevel@tonic-gate  */
4357c478bd9Sstevel@tonic-gate #define	OR_SET_BYTE_R(handle, addr, val) \
4367c478bd9Sstevel@tonic-gate {		\
4377c478bd9Sstevel@tonic-gate 	uint8_t tmpval;					\
4387c478bd9Sstevel@tonic-gate 	tmpval = ddi_get8(handle, (uint8_t *)addr);	\
4397c478bd9Sstevel@tonic-gate 	tmpval |= val;					\
4407c478bd9Sstevel@tonic-gate 	ddi_put8(handle, (uint8_t *)addr, tmpval);	\
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate #define	OR_SET_LONG_R(handle, addr, val) \
4447c478bd9Sstevel@tonic-gate {		\
4457c478bd9Sstevel@tonic-gate 	uint32_t tmpval;				\
4467c478bd9Sstevel@tonic-gate 	tmpval = ddi_get32(handle, (uint32_t *)addr);	\
4477c478bd9Sstevel@tonic-gate 	tmpval |= val;					\
4487c478bd9Sstevel@tonic-gate 	ddi_put32(handle, (uint32_t *)addr, tmpval);	\
4497c478bd9Sstevel@tonic-gate }
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate #define	AND_SET_BYTE_R(handle, addr, val) \
4527c478bd9Sstevel@tonic-gate {		\
4537c478bd9Sstevel@tonic-gate 	uint8_t tmpval;					\
4547c478bd9Sstevel@tonic-gate 	tmpval = ddi_get8(handle, (uint8_t *)addr);	\
4557c478bd9Sstevel@tonic-gate 	tmpval &= val; 					\
4567c478bd9Sstevel@tonic-gate 	ddi_put8(handle, (uint8_t *)addr, tmpval);	\
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate #define	AND_SET_LONG_R(handle, addr, val) \
4607c478bd9Sstevel@tonic-gate {		\
4617c478bd9Sstevel@tonic-gate 	uint32_t tmpval;				\
4627c478bd9Sstevel@tonic-gate 	tmpval = ddi_get32(handle, (uint32_t *)addr);	\
4637c478bd9Sstevel@tonic-gate 	tmpval &= val; 					\
4647c478bd9Sstevel@tonic-gate 	ddi_put32(handle, (uint32_t *)addr, tmpval);	\
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate #define	NOR_SET_LONG_R(handle, addr, val, mask) \
4687c478bd9Sstevel@tonic-gate {		\
4697c478bd9Sstevel@tonic-gate 	uint32_t tmpval;				\
4707c478bd9Sstevel@tonic-gate 	tmpval = ddi_get32(handle, (uint32_t *)addr);	\
4717c478bd9Sstevel@tonic-gate 	tmpval &= ~(mask);				\
4727c478bd9Sstevel@tonic-gate 	tmpval |= val;					\
4737c478bd9Sstevel@tonic-gate 	ddi_put32(handle, (uint32_t *)addr, tmpval);	\
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate /*
4777c478bd9Sstevel@tonic-gate  * Macros for Cheerio/RIO DMAC programming
4787c478bd9Sstevel@tonic-gate  */
4797c478bd9Sstevel@tonic-gate #define	SET_DMAC_CSR(pp, val)	ddi_put32(pp->uh.ebus.d_handle, \
4807c478bd9Sstevel@tonic-gate 				((uint32_t *)&pp->uh.ebus.dmac->csr), \
4817c478bd9Sstevel@tonic-gate 				((uint32_t)val))
4827c478bd9Sstevel@tonic-gate #define	GET_DMAC_CSR(pp)	ddi_get32(pp->uh.ebus.d_handle, \
4837c478bd9Sstevel@tonic-gate 				(uint32_t *)&(pp->uh.ebus.dmac->csr))
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate #define	SET_DMAC_ACR(pp, val)	ddi_put32(pp->uh.ebus.d_handle, \
4867c478bd9Sstevel@tonic-gate 				((uint32_t *)&pp->uh.ebus.dmac->acr), \
4877c478bd9Sstevel@tonic-gate 				((uint32_t)val))
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate #define	GET_DMAC_ACR(pp)	ddi_get32(pp->uh.ebus.d_handle, \
4907c478bd9Sstevel@tonic-gate 				(uint32_t *)&pp->uh.ebus.dmac->acr)
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate #define	SET_DMAC_BCR(pp, val)	ddi_put32(pp->uh.ebus.d_handle, \
4937c478bd9Sstevel@tonic-gate 				((uint32_t *)&pp->uh.ebus.dmac->bcr), \
4947c478bd9Sstevel@tonic-gate 				((uint32_t)val))
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate #define	GET_DMAC_BCR(pp)	ddi_get32(pp->uh.ebus.d_handle, \
4977c478bd9Sstevel@tonic-gate 				((uint32_t *)&pp->uh.ebus.dmac->bcr))
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate #define	DMAC_RESET_TIMEOUT	10000	/* in usec */
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate /*
5027c478bd9Sstevel@tonic-gate  * Macros to distinguish between PIO and DMA Compatibility mode
5037c478bd9Sstevel@tonic-gate  */
5047c478bd9Sstevel@tonic-gate #define	COMPAT_PIO(pp) (((pp)->io_mode == ECPP_PIO) &&		\
5057c478bd9Sstevel@tonic-gate 		    ((pp)->current_mode == ECPP_CENTRONICS ||	\
5067c478bd9Sstevel@tonic-gate 		    (pp)->current_mode == ECPP_COMPAT_MODE))
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate #define	COMPAT_DMA(pp) (((pp)->io_mode == ECPP_DMA) &&		\
5097c478bd9Sstevel@tonic-gate 		    ((pp)->current_mode == ECPP_CENTRONICS ||	\
5107c478bd9Sstevel@tonic-gate 		    (pp)->current_mode == ECPP_COMPAT_MODE))
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate /*
5137c478bd9Sstevel@tonic-gate  * Other useful macros
5147c478bd9Sstevel@tonic-gate  */
5157c478bd9Sstevel@tonic-gate #define	NELEM(a)	(sizeof (a) / sizeof (*(a)))
5167c478bd9Sstevel@tonic-gate #define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate #endif
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate #endif	/* _SYS_ECPPVAR_H */
523