[PARPORT] Patch: 2.3.99pre8-lp.c Report Printer Status

From: Gunther Mayer (gunther.mayer@braunschweig.okersurf.de)
Date: Sun May 14 2000 - 09:23:02 EDT

  • Next message: Peter Pregler: "Re: [PARPORT] ECP read - FIFO/DMA"

    Hi,
    this patch improves printer status reporting.
    Before, it was too quiet and even if switched to
    non-quiet (LP_CAREFUL) it masked valuable status.

    These messages are purely informative and do not change any
    policies in the lp-driver !

    Only with this patch you can learn what your printer does with it's
    status lines:
    May 14 14:43:26 linux kernel: lp0 printer-not-ready out-of-paper (0x7f)
    # Switched OFF
    May 14 14:43:40 linux kernel: lp0 printer-not-ready off-line (0x4f) #
    Becoming ready
    May 14 14:43:50 linux kernel: lp0 printer-OK (0xdf)
    May 14 14:44:15 linux kernel: lp0 printer-not-ready out-of-paper (0x7f)
    May 14 14:44:25 linux kernel: lp0 out-of-paper (0xff)
    May 14 14:44:25 linux kernel: lp0 printer-OK (0xdf)
    May 14 14:44:50 linux kernel: lp0 out-of-paper off-line (0xef) # Paper
    empty
    May 14 14:45:26 linux kernel: lp0 printer-OK (0xdf)

    In the case some printer doesn't set these lines at all the user will
    learn quickly how to interpret (or ignore) these messages. Only deltas
    are shown,
    so even then the logs are not flooded.

    Tim, I think this would be of great value for novice users (first time
    printing with linux).
    Will you test/ send to the kernel for inclusion in 2.4 ?

    Regards, Gunther


    --- linux-2399p8-orig/drivers/char/lp.c Thu Feb 24 19:30:25 2000
    +++ linux/drivers/char/lp.c Sun May 14 14:42:18 2000
    @@ -189,41 +189,42 @@
             else parport_yield_blocking (lp_table[minor].dev);
     }
     
    +/* Report errors as deltas.
    + This helps users with conforming printers and should be
    + quiet enough for old nonobeying printers.
    + */
     static int lp_check_status(int minor)
     {
    - int error = 0;
    + int error = 0, status;
             unsigned int last = lp_table[minor].last_error;
    - unsigned char status = r_str(minor);
    - if ((status & LP_PERRORP) && !(LP_F(minor) & LP_CAREFUL))
    - /* No error. */
    - last = 0;
    - else if ((status & LP_POUTPA)) {
    - if (last != LP_POUTPA) {
    - last = LP_POUTPA;
    - printk(KERN_INFO "lp%d out of paper\n", minor);
    - }
    - error = -ENOSPC;
    - } else if (!(status & LP_PSELECD)) {
    - if (last != LP_PSELECD) {
    - last = LP_PSELECD;
    - printk(KERN_INFO "lp%d off-line\n", minor);
    - }
    - error = -EIO;
    - } else if (!(status & LP_PERRORP)) {
    - if (last != LP_PERRORP) {
    - last = LP_PERRORP;
    - printk(KERN_INFO "lp%d on fire\n", minor);
    - }
    - error = -EIO;
    - } else {
    - last = 0; /* Come here if LP_CAREFUL is set and no
    - errors are reported. */
    - }
    + unsigned int str = r_str(minor);
    +
    + status = str & ( LP_PERRORP | LP_POUTPA | LP_PSELECD | LP_PBUSY);
     
    - lp_table[minor].last_error = last;
    + if ( status != last ) {
    + printk("lp%d",minor);
    + if (!(status & LP_PERRORP)) {
    + printk(" printer-error");
    + error=-EIO;
    + }
    + if (!(status & LP_PBUSY)) {
    + printk(" printer-not-ready");
    + error=-EIO;
    + }
    + if (status & LP_POUTPA) {
    + printk(" out-of-paper");
    + error=-ENOSPC;
    + }
    + if (!(status & LP_PSELECD)) {
    + printk(" off-line");
    + error= -EIO;
    + }
    + if(!error)
    + printk(" printer-OK");
    + printk(" (0x%02x)\n",str);
    + }
     
    - if (last != 0)
    - lp_error(minor);
    + lp_table[minor].last_error = status;
     
             return error;
     }
    @@ -267,6 +268,7 @@
     
             do {
                     /* Write the data. */
    + lp_check_status(minor);
                     written = parport_write (port, kbuf, copy_size);
                     if (written >= 0) {
                             copy_size -= written;
    @@ -285,6 +287,7 @@
                     if (copy_size > 0) {
                             /* incomplete write -> check error ! */
                             int error = lp_check_status (minor);
    + if (error) lp_error(minor);
     
                             if (LP_F(minor) & LP_ABORT) {
                                     if (retv == 0)
    @@ -308,8 +311,9 @@
                             }
                     }
             } while (count > 0);
    -
    - parport_release (lp_table[minor].dev);
    + lp_check_status(minor);
    +
    + parport_release (lp_table[minor].dev);
     
             up (&lp_table[minor].port_mutex);
     
    @@ -384,23 +388,23 @@
                have commandeered O_NONBLOCK, even though it is being used in
                a non-standard manner. This is strictly a Linux hack, and
                should most likely only ever be used by the tunelp application. */
    +
    + lp_check_status(minor);
    +
             if ((LP_F(minor) & LP_ABORTOPEN) && !(file->f_flags & O_NONBLOCK)) {
                     int status;
                     parport_claim_or_block (lp_table[minor].dev);
                     status = r_str(minor);
                     parport_release (lp_table[minor].dev);
                     if (status & LP_POUTPA) {
    - printk(KERN_INFO "lp%d out of paper\n", minor);
                             MOD_DEC_USE_COUNT;
                             LP_F(minor) &= ~LP_BUSY;
                             return -ENOSPC;
                     } else if (!(status & LP_PSELECD)) {
    - printk(KERN_INFO "lp%d off-line\n", minor);
                             MOD_DEC_USE_COUNT;
                             LP_F(minor) &= ~LP_BUSY;
                             return -EIO;
                     } else if (!(status & LP_PERRORP)) {
    - printk(KERN_ERR "lp%d printer error\n", minor);
                             MOD_DEC_USE_COUNT;
                             LP_F(minor) &= ~LP_BUSY;
                             return -EIO;
    @@ -419,6 +423,7 @@
     {
             unsigned int minor = MINOR(inode->i_rdev);
     
    + lp_check_status(minor);
             kfree_s(lp_table[minor].lp_buffer, LP_BUFFER_SIZE);
             lp_table[minor].lp_buffer = NULL;
             MOD_DEC_USE_COUNT;

    -- To unsubscribe, send mail to: linux-parport-request@torque.net --
    -- with the single word "unsubscribe" in the body of the message. --



    This archive was generated by hypermail 2b29 : Sun May 14 2000 - 09:26:40 EDT