*BSD News Article 71759


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!cs.mu.OZ.AU!munnari.OZ.AU!news.hawaii.edu!news.uoregon.edu!vixen.cso.uiuc.edu!uwm.edu!lll-winken.llnl.gov!nntp.coast.net!fu-berlin.de!news.belwue.de!news.uni-stuttgart.de!uniol!uni-erlangen.de!news.tu-chemnitz.de!irz401!orion.sax.de!uriah.heep!news
From: j@uriah.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Printer slow, Help !
Date: 22 Jun 1996 12:22:10 GMT
Organization: Private BSD site, Dresden
Lines: 105
Message-ID: <4qgohi$q31@uriah.heep.sax.de>
References: <BZukPD1w165w@tusia.kiel.org> <31CAEE8B.13E5@fsl.noaa.gov>
Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
NNTP-Posting-Host: localhost.heep.sax.de
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: knews 0.9.6
X-Phone: +49-351-2012 669
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F  93 21 E0 7D F9 12 D6 4E

Sean Kelly <kelly@fsl.noaa.gov> wrote:

> Some newer HP printers are told to not work correctly in interrupt mode,
> apparently due to some (not yet exactly understood) timing problem.

The following patch is supposed to fix this.  Give it a try (it will,
of course, be in FreeBSD 2.1.5):

Index: /sys/i386/isa/lpt.c
===================================================================
RCS file: /home/cvs/src/sys/i386/isa/lpt.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -u -r1.52 -r1.53
--- lpt.c	1996/03/29 11:54:56	1.52
+++ lpt.c	1996/04/04 12:28:36	1.53
@@ -149,7 +149,8 @@
 
 
 #define	LPINITRDY	4	/* wait up to 4 seconds for a ready */
-#define	LPTOUTTIME	4	/* wait up to 4 seconds for a ready */
+#define	LPTOUTINITIAL	10	/* initial timeout to wait for ready 1/10 s */
+#define	LPTOUTMAX	1	/* maximal timeout 1 s */
 #define	LPPRI		(PZERO+8)
 #define	BUFSIZE		1024
 
@@ -221,6 +222,7 @@
 #define LP_HAS_IRQ	0x01	/* we have an irq available */
 #define LP_USE_IRQ	0x02	/* we are using our irq */
 #define LP_ENABLE_IRQ	0x04	/* enable IRQ on open */
+	u_char	sc_backoff ;	/* time to call lptout() again */
 
 #ifdef INET
 	struct  ifnet	sc_if;
@@ -590,7 +592,8 @@
 	lprintf("irq %x\n", sc->sc_irq);
 	if (sc->sc_irq & LP_USE_IRQ) {
 		sc->sc_state |= TOUT;
-		timeout ((timeout_func_t)lptout, (caddr_t)sc, hz/2);
+		timeout ((timeout_func_t)lptout, (caddr_t)sc,
+			 (sc->sc_backoff = hz/LPTOUTINITIAL));
 	}
 
 	lprintf("opened.\n");
@@ -602,9 +605,12 @@
 {	int pl;
 
 	lprintf ("T %x ", inb(sc->sc_port+lpt_status));
-	if (sc->sc_state & OPEN)
-		timeout ((timeout_func_t)lptout, (caddr_t)sc, hz/2);
-	else
+	if (sc->sc_state & OPEN) {
+		sc->sc_backoff++;
+		if (sc->sc_backoff > hz/LPTOUTMAX)
+			sc->sc_backoff = sc->sc_backoff > hz/LPTOUTMAX;
+		timeout ((timeout_func_t)lptout, (caddr_t)sc, sc->sc_backoff);
+	} else
 		sc->sc_state &= ~TOUT;
 
 	if (sc->sc_state & ERROR)
@@ -785,6 +791,7 @@
 {
 	struct lpt_softc *sc = lpt_sc + unit;
 	int port = sc->sc_port, sts;
+	int i;
 
 #ifdef INET
 	if(sc->sc_if.if_flags & IFF_UP) {
@@ -793,9 +800,19 @@
 	}
 #endif /* INET */
 
-	/* is printer online and ready for output */
-	if (((sts=inb(port+lpt_status)) & RDY_MASK) == LP_READY) {
+	/*
+	 * Is printer online and ready for output?
+	 *
+	 * Avoid falling back to lptout() too quickly.  First spin-loop
+	 * to see if the printer will become ready ``really soon now''.
+	 */
+	for (i = 0;
+	     i < 100 &&
+	     ((sts=inb(port+lpt_status)) & RDY_MASK) != LP_READY;
+	     i++) ;
+	if ((sts & RDY_MASK) == LP_READY) {
 		sc->sc_state = (sc->sc_state | OBUSY) & ~ERROR;
+		sc->sc_backoff = hz/LPTOUTINITIAL;
 
 		if (sc->sc_xfercnt) {
 			/* send char */
@@ -822,6 +839,7 @@
 		if(((sts & (LPS_NERR | LPS_OUT) ) != LPS_NERR) &&
 				(sc->sc_state & OPEN))
 			sc->sc_state |= ERROR;
+		/* lptout() will jump in and try to restart. */
 	}
 	lprintf("sts %x ", sts);
 }

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)