[PATCH] PLIP driver support for parallel ports with no IRQ

Nimrod Zimerman (zimerman@mailandnews.com)
Sun, 1 Aug 1999 15:08:05 +0300


Hello.

For a long time I've been facing the problem of using the PLIP driver on a
parallel port that cannot have an IRQ assigned to it, for whatever reason
(one common reason is that there are simply no available IRQs).

The included patch (which can also be found on
http://thor.prohosting.com/~zimerman), adds support for this. I hope that it
can find its way to the stock kernel sooner or later.

This version of the patch applies on kernel 2.2.10, and likely on all
other kernels in the 2.2.x domain.

Nimrod

--- ./linux/drivers/net/plip.c.ORIG-plip Tue Mar 9 11:47:18 1999
+++ ./linux/drivers/net/plip.c Fri Jul 30 15:00:47 1999
@@ -11,8 +11,10 @@
*
* Modularization and ifreq/ifmap support by Alan Cox.
* Rewritten by Niibe Yutaka.
- * parport-sharing awareness code by Philip Blundell.
+ * parport-sharing awareness code by Philip Blundell.
* SMP locking by Niibe Yutaka.
+ * Support for parallel ports with no IRQ (poll mode)
+ * by Nimrod Zimerman <zimerman@mailandnews.com>.
*
* Fixes:
* Niibe Yutaka
@@ -49,7 +51,7 @@
* To use with DOS box, please do (Turn on ARP switch):
* # ifconfig plip[0-2] arp
*/
-static const char *version = "NET3 PLIP version 2.3-parport gniibe@mri.co.jp\n";
+static const char *version = "NET3 PLIP version 2.4-parport gniibe@mri.co.jp\n";

/*
Sources:
@@ -112,6 +114,7 @@
#include <asm/irq.h>
#include <asm/byteorder.h>
#include <asm/spinlock.h>
+#include <asm/semaphore.h>

#include <linux/parport.h>

@@ -124,8 +127,8 @@
#endif
static unsigned int net_debug = NET_DEBUG;

-#define ENABLE(irq) enable_irq(irq)
-#define DISABLE(irq) disable_irq(irq)
+#define ENABLE(irq) if (irq != -1) enable_irq(irq)
+#define DISABLE(irq) if (irq != -1) disable_irq(irq)

/* In micro second */
#define PLIP_DELAY_UNIT 1
@@ -142,9 +145,22 @@
#define PAR_STATUS(dev) ((dev)->base_addr+1)
#define PAR_CONTROL(dev) ((dev)->base_addr+2)

-/* Bottom halfs */
+inline static void enable_parport_interrupts (struct device *dev)
+{
+ if (dev->irq != -1)
+ outb (PAR_INTR_ON, PAR_CONTROL(dev));
+}
+
+inline static void disable_parport_interrupts (struct device *dev)
+{
+ if (dev->irq != -1)
+ outb (PAR_INTR_OFF, PAR_CONTROL(dev));
+}
+
+/* Bottom halves */
static void plip_kick_bh(struct device *dev);
static void plip_bh(struct device *dev);
+static void plip_timer_bh(struct device *dev);

/* Interrupt handler */
static void plip_interrupt(int irq, void *dev_id, struct pt_regs *regs);
@@ -210,6 +226,7 @@
struct net_device_stats enet_stats;
struct tq_struct immediate;
struct tq_struct deferred;
+ struct tq_struct timer;
struct plip_local snd_data;
struct plip_local rcv_data;
struct pardevice *pardev;
@@ -222,6 +239,8 @@
int should_relinquish;
int (*orig_rebuild_header)(struct sk_buff *skb);
spinlock_t lock;
+ atomic_t kill_timer;
+ struct semaphore killed_timer_sem;
};

/* Entry point of PLIP driver.
@@ -243,8 +262,8 @@
dev->base_addr = pb->base;

if (pb->irq == -1) {
- printk(KERN_INFO "plip: %s has no IRQ.\n", pb->name);
- return -ENODEV;
+ printk(KERN_INFO "plip: %s has no IRQ. Using IRQ-less mode,"
+ "which is fairly inefficient!\n", pb->name);
}

pardev = parport_register_device(pb, dev->name, plip_preempt,
@@ -255,8 +274,12 @@
return -ENODEV;

printk(KERN_INFO "%s", version);
- printk(KERN_INFO "%s: Parallel port at %#3lx, using IRQ %d\n", dev->name,
- dev->base_addr, dev->irq);
+ if (dev->irq != -1)
+ printk(KERN_INFO "%s: Parallel port at %#3lx, using IRQ %d.\n",
+ dev->name, dev->base_addr, dev->irq);
+ else
+ printk(KERN_INFO "%s: Parallel port at %#3lx, not using IRQ.\n",
+ dev->name, dev->base_addr);

/* Fill in the generic fields of the device structure. */
ether_setup(dev);
@@ -295,13 +318,23 @@
/* Initialize task queue structures */
nl->immediate.next = NULL;
nl->immediate.sync = 0;
- nl->immediate.routine = (void *)(void *)plip_bh;
+ nl->immediate.routine = (void (*)(void *))plip_bh;
nl->immediate.data = dev;

nl->deferred.next = NULL;
nl->deferred.sync = 0;
- nl->deferred.routine = (void *)(void *)plip_kick_bh;
+ nl->deferred.routine = (void (*)(void *))plip_kick_bh;
nl->deferred.data = dev;
+
+ if (dev->irq == -1) {
+ nl->timer.next = NULL;
+ nl->timer.sync = 0;
+ nl->timer.routine = (void (*)(void *))plip_timer_bh;
+ nl->timer.data = dev;
+ atomic_set (&nl->kill_timer, 0);
+ sema_init (&nl->killed_timer_sem, 0);
+ }
+
spin_lock_init(&nl->lock);

return 0;
@@ -373,6 +406,22 @@
}
}

+static void
+plip_timer_bh(struct device *dev)
+{
+ struct net_local *nl = (struct net_local *)dev->priv;
+
+ if (!(atomic_read (&nl->kill_timer))) {
+ if (!dev->interrupt)
+ plip_interrupt (-1, dev, NULL);
+
+ queue_task (&nl->timer, &tq_timer);
+ }
+ else {
+ up (&nl->killed_timer_sem);
+ }
+}
+
static int
plip_bh_timeout_error(struct device *dev, struct net_local *nl,
struct plip_local *snd, struct plip_local *rcv,
@@ -441,7 +490,7 @@
DISABLE(dev->irq);
synchronize_irq();
}
- outb(PAR_INTR_OFF, PAR_CONTROL(dev));
+ disable_parport_interrupts (dev);
dev->tbusy = 1;
nl->connection = PLIP_CN_ERROR;
outb(0x00, PAR_DATA(dev));
@@ -520,7 +569,7 @@
case PLIP_PK_TRIGGER:
DISABLE(dev->irq);
/* Don't need to synchronize irq, as we can safely ignore it */
- outb(PAR_INTR_OFF, PAR_CONTROL(dev));
+ disable_parport_interrupts (dev);
dev->interrupt = 0;
outb(0x01, PAR_DATA(dev)); /* send ACK */
if (net_debug > 2)
@@ -537,7 +586,7 @@
nl->is_deferred = 1;
nl->connection = PLIP_CN_SEND;
queue_task(&nl->deferred, &tq_timer);
- outb(PAR_INTR_ON, PAR_CONTROL(dev));
+ enable_parport_interrupts (dev);
ENABLE(dev->irq);
return OK;
}
@@ -611,13 +660,13 @@
spin_unlock_irq(&nl->lock);
queue_task(&nl->immediate, &tq_immediate);
mark_bh(IMMEDIATE_BH);
- outb(PAR_INTR_ON, PAR_CONTROL(dev));
+ enable_parport_interrupts (dev);
ENABLE(dev->irq);
return OK;
} else {
nl->connection = PLIP_CN_NONE;
spin_unlock_irq(&nl->lock);
- outb(PAR_INTR_ON, PAR_CONTROL(dev));
+ enable_parport_interrupts (dev);
ENABLE(dev->irq);
return OK;
}
@@ -724,7 +773,7 @@
nl->enet_stats.collisions++;
return OK;
}
- outb(PAR_INTR_OFF, PAR_CONTROL(dev));
+ disable_parport_interrupts (dev);
if (net_debug > 2)
printk(KERN_DEBUG "%s: send start\n", dev->name);
snd->state = PLIP_PK_LENGTH_LSB;
@@ -783,7 +832,7 @@
nl->connection = PLIP_CN_CLOSING;
nl->is_deferred = 1;
queue_task(&nl->deferred, &tq_timer);
- outb(PAR_INTR_ON, PAR_CONTROL(dev));
+ enable_parport_interrupts (dev);
ENABLE(dev->irq);
return OK;
}
@@ -823,7 +872,7 @@
nl->should_relinquish = 0;
dev->tbusy = 0;
dev->interrupt = 0;
- outb(PAR_INTR_ON, PAR_CONTROL(dev));
+ enable_parport_interrupts (dev);
ENABLE(dev->irq);
mark_bh(NET_BH);
} else {
@@ -856,7 +905,7 @@

c0 = inb(PAR_STATUS(dev));
if ((c0 & 0xf8) != 0xc0) {
- if (net_debug > 1)
+ if ((dev->irq != -1) && (net_debug > 1))
printk(KERN_DEBUG "%s: spurious interrupt\n", dev->name);
return;
}
@@ -979,7 +1028,9 @@
outb (0x00, PAR_DATA(dev));

/* Enable rx interrupt. */
- outb(PAR_INTR_ON, PAR_CONTROL(dev));
+ enable_parport_interrupts (dev);
+ if (dev->irq == -1)
+ queue_task (&nl->timer, &tq_timer);

/* Initialize the state machine. */
nl->rcv_data.state = nl->snd_data.state = PLIP_PK_DONE;
@@ -1026,6 +1077,12 @@
dev->start = 0;
DISABLE(dev->irq);
synchronize_irq();
+
+ if (dev->irq == -1)
+ {
+ atomic_set (&nl->kill_timer, 1);
+ down (&nl->killed_timer_sem);
+ }

#ifdef NOTDEF
outb(0x00, PAR_DATA(dev));
--- ./linux/Documentation/networking/PLIP.txt.ORIG-plip Thu May 21 04:54:34 1998
+++ ./linux/Documentation/networking/PLIP.txt Wed Jul 28 15:17:55 1999
@@ -49,17 +49,69 @@
SLIP).

Performance
-==========
+===========

PLIP easily outperforms Ethernet cards....(ups, I was dreaming, but
it *is* getting late. EOB)

+PLIP driver details
+-------------------
+
+The Linux PLIP driver is an implementation of the original Crynwr protocol,
+that uses the parallel port subsystem of the kernel in order to properly
+share parallel ports between PLIP and other services.
+
+IRQs and trigger timeouts
+=========================
+
+When a parallel port used for a PLIP driver has an IRQ configured to it, the
+PLIP driver is signaled whenever data is sent to it via the cable, such that
+when no data is available, the driver isn't being used.
+
+However, on some machines it is hard, if not impossible, to configure an IRQ
+to a certain parallel port, mainly because it is used by some other device.
+On these machines, the PLIP driver can be used in IRQ-less mode, where
+the PLIP driver would constantly poll the parallel port for data waiting,
+and if such data is available, process it. This mode is less efficient than
+the IRQ mode, because the driver has to check the parallel port many times
+per second, even when no data at all is sent. Some rough measurements
+indicate that there isn't a noticeable performance drop when using IRQ-less
+mode as compared to IRQ mode as far as the data transfer speed is involved.
+There is a performance drop on the machine hosting the driver.
+
+When the PLIP driver is used in IRQ mode, the timeout used for triggering a
+data transfer (the maximal time the PLIP driver would allow the other side
+before announcing a timeout, when trying to handshake a transfer of some
+data) is, by default, 500usec. As IRQ delivery is more or less immediate,
+this timeout is quite sufficient.
+
+When in IRQ-less mode, the PLIP driver polls the parallel port HZ times
+per second (where HZ is typically 100 on most platforms, and 1024 on an
+Alpha, as of this writing). Between two such polls, there are 10^6/HZ usecs.
+On an i386, for example, 10^6/100 = 10000usec. It is easy to see that it is
+quite possible for the trigger timeout to expire between two such polls, as
+the timeout is only 500usec long. As a result, it is required to change the
+trigger timeout on the *other* side of a PLIP connection, to about
+10^6/HZ usecs. If both sides of a PLIP connection are used in IRQ-less mode,
+this timeout is required on both sides.
+
+It appears that in practice, the trigger timeout can be shorter than in the
+above calculation. It isn't an important issue, unless the wire is faulty,
+in which case a long timeout would stall the machine when, for whatever
+reason, bits are dropped.
+
+A utility that can perform this change in Linux is plipconfig, which is part
+of the net-tools package (its location can be found in the
+Documentation/Changes file). An example command would be
+'plipconfig plipX trigger 10000', where plipX is the appropriate
+PLIP device.
+
PLIP hardware interconnection
-----------------------------

PLIP uses several different data transfer methods. The first (and the
only one implemented in the early version of the code) uses a standard
-printer "null" cable to transfers data four bits at a time using
+printer "null" cable to transfer data four bits at a time using
data bit outputs connected to status bit inputs.

The second data transfer method relies on both machines having
@@ -138,18 +190,18 @@
The PLIP driver is compatible with the "Crynwr" parallel port transfer
standard in Mode 0. That standard specifies the following protocol:

- send header nibble '8'
+ send header nibble '0x08'
count-low octet
count-high octet
... data octets
checksum octet

Each octet is sent as
- <wait for rx. '1'> <send 0x10+(octet&0x0F)>
- <wait for rx. '0'> <send 0x00+((octet>>4)&0x0F)>
+ <wait for rx. '0x1?'> <send 0x10+(octet&0x0F)>
+ <wait for rx. '0x0?'> <send 0x00+((octet>>4)&0x0F)>

To start a transfer the transmitting machine outputs a nibble 0x08.
-The raises the ACK line, triggering an interrupt in the receiving
+That raises the ACK line, triggering an interrupt in the receiving
machine. The receiving machine disables interrupts and raises its own ACK
line.

--- ./linux/Documentation/Configure.help.ORIG-plip Mon Jun 14 22:54:12 1999
+++ ./linux/Documentation/Configure.help Wed Jul 21 19:54:12 1999
@@ -5045,6 +5045,23 @@
The kernels on both machines need to have this PLIP option enabled
for this to work.

+ The plipconfig utility, can be used to change several parameters
+ of the plip driver once it has been opened. It is part of the net-tools
+ package, whose location and current version number is contained in
+ the file Documentation/Changes.
+
+ This drivers performs better if the parallel port used has an IRQ
+ associated with it, but can also work in poll mode with no IRQ.
+ If IRQ-less mode is used, it is required to change the trigger timeout
+ on the *other* side of the connection to about 10000usec (on a i386),
+ though values as small as 5000usec are known to work. If both sides are
+ used in IRQ-less mode, both sides need to use said trigger timeout.
+ In order to perform this change on a Linux, the command
+ 'plipconfig plipX trigger 10000' can be used, where plipX is the
+ appropriate PLIP device.
+ For a discussion on the trigger timeout, see
+ Documentation/networking/PLIP.txt.
+
The PLIP driver has two modes, mode 0 and mode 1. The parallel ports
(the connectors at the computers with 25 holes) are connected with
"null printer" or "Turbo Laplink" cables which can transmit 4 bits

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/