From nobody@FreeBSD.org  Fri Apr 13 20:49:48 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 794C437B506
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Apr 2001 20:49:48 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id f3E3nmh47109;
	Fri, 13 Apr 2001 20:49:48 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200104140349.f3E3nmh47109@freefall.freebsd.org>
Date: Fri, 13 Apr 2001 20:49:48 -0700 (PDT)
From: ve3wwg@home.com
To: freebsd-gnats-submit@FreeBSD.org
Subject: /dev/lpt0 returns EBUSY when attempting to open "Ready Printer"
X-Send-Pr-Version: www-1.0

>Number:         26562
>Category:       kern
>Synopsis:       [lpt] [patch] /dev/lpt0 returns EBUSY when attempting to open "Ready Printer"
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 13 20:50:00 PDT 2001
>Closed-Date:    
>Last-Modified:  Wed Sep 14 07:05:00 GMT 2005
>Originator:     Warren W. Gay VE3WWG
>Release:        4.2-RELEASE & 4.3-RC
>Organization:
>Environment:
FreeBSD hibiscus.ve3wwg.org 4.3-RC FreeBSD 4.3-RC #4: Fri Apr 13 23:27:07 EDT 2001     
root@hibiscus.ve3wwg.org:/usr/src/sys/compile/hibiscus  i386
>Description:
The Canon BJC-4300 does not provide the LPS_SEL (Selected) signal (or
at least, my printer is not _now_ providing this signal). Consequently,
it becomes impossible to open the printer for printing under FreeBSD
(printing DOES work under Windows and Linux for this printer, on this
same machine, however).
>How-To-Repeat:
Nothing special. I tried all the BIOS and interrupt combinations, and
new kernels configured to match. None of these changes mitigated the
problem.

I would like to suggest a kernel "option" to configure the ability to
ignore the SELECT signal coming back from the printer.
>Fix:
Hack /usr/src/sys/dev/ppbus/lpt.c to ignore LPS_SEL. The following is
context diff of the working solution (email me for an unmangled copy
of this patch file, if you like):

# cat patches.lpt
*** lpt.c       Fri Apr 13 22:28:32 2001
--- hacked.lpt.c        Fri Apr 13 23:32:37 2001
***************
*** 171,183 ****
  
  
  /* status masks to interrogate printer status */
! #define RDY_MASK      (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)     /* ready ? */
! #define LP_READY      (LPS_SEL|LPS_NBSY|LPS_NERR)
  
  /* Printer Ready condition  - from lpa.c */
  /* Only used in polling code */
! #define       LPS_INVERT      (LPS_NBSY | LPS_NACK |           LPS_SEL | LPS_NERR)
! #define       LPS_MASK        (LPS_NBSY | LPS_NACK | LPS_OUT | LPS_SEL | LPS_NERR)
  #define       NOT_READY(ppbus) ((ppb_rstr(ppbus)^LPS_INVERT)&LPS_MASK)
  
  #define       MAX_SLEEP       (hz*5)  /* Timeout while waiting for device ready */
--- 171,183 ----
  
  
  /* status masks to interrogate printer status */
! #define RDY_MASK      (/*LPS_SEL|*/LPS_OUT|LPS_NBSY|LPS_NERR) /* ready ? */
! #define LP_READY      (/*LPS_SEL|*/LPS_NBSY|LPS_NERR)
  
  /* Printer Ready condition  - from lpa.c */
  /* Only used in polling code */
! #define       LPS_INVERT      (LPS_NBSY | LPS_NACK |           /*LPS_SEL |*/ LPS_NERR)
! #define       LPS_MASK        (LPS_NBSY | LPS_NACK | LPS_OUT | /*LPS_SEL |*/ LPS_NERR)
  #define       NOT_READY(ppbus) ((ppb_rstr(ppbus)^LPS_INVERT)&LPS_MASK)
  
  #define       MAX_SLEEP       (hz*5)  /* Timeout while waiting for device ready */
***************
*** 538,545 ****
  
                /* is printer online and ready for output */
        } while ((ppb_rstr(ppbus) &
!                       (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) !=
!                                       (LPS_SEL|LPS_NBSY|LPS_NERR));
  
        sc->sc_control = LPC_SEL|LPC_NINIT;
        if (sc->sc_flags & LP_AUTOLF)
--- 538,545 ----
  
                /* is printer online and ready for output */
        } while ((ppb_rstr(ppbus) &
!                       (/*LPS_SEL|*/LPS_OUT|LPS_NBSY|LPS_NERR)) !=
!                                       (/*LPS_SEL|*/LPS_NBSY|LPS_NERR));
  
        sc->sc_control = LPC_SEL|LPC_NINIT;
        if (sc->sc_flags & LP_AUTOLF)
***************
*** 598,605 ****
        /* if the last write was interrupted, don't complete it */
        if((!(sc->sc_state  & INTERRUPTED)) && (sc->sc_irq & LP_USE_IRQ))
                while ((ppb_rstr(ppbus) &
!                       (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) !=
!                       (LPS_SEL|LPS_NBSY|LPS_NERR) || sc->sc_xfercnt)
                        /* wait 1/4 second, give up if we get a signal */
                        if (tsleep((caddr_t)lptdev, LPPRI|PCATCH,
                                "lpclose", hz) != EWOULDBLOCK)
--- 598,605 ----
        /* if the last write was interrupted, don't complete it */
        if((!(sc->sc_state  & INTERRUPTED)) && (sc->sc_irq & LP_USE_IRQ))
                while ((ppb_rstr(ppbus) &
!                       (/*LPS_SEL|*/LPS_OUT|LPS_NBSY|LPS_NERR)) !=
!                       (/*LPS_SEL|*/LPS_NBSY|LPS_NERR) || sc->sc_xfercnt)
                        /* wait 1/4 second, give up if we get a signal */
                        if (tsleep((caddr_t)lptdev, LPPRI|PCATCH,
                                "lpclose", hz) != EWOULDBLOCK)

>Release-Note:
>Audit-Trail:

From: Michael Graziano <mikeg@hoflink.com>
To: freebsd-gnats-submit@FreeBSD.org, ve3wwg@home.com
Cc:  
Subject: Re: i386/26562: /dev/lpt0 returns EBUSY when attempting to open
 "Ready Printer"
Date: Sun, 15 Apr 2001 23:53:17 -0400

 This solves the problem on one of my machines as well.  If someone 
 wants to clean this up and commit this I would really appreciate it.
 
 /~mikeg
>Unformatted:
