Interrupt-Driven Operation

Most hardware interfaces are controlled by means of an interrupt handler. The interface interrupts the processor to signal one of two possible events: a new packet has arrived or transmission of an outgoing packet is complete. This generalization doesn’t always apply, but it does account for all the problems related to asynchronous packet transmission. PLIP and PPP are examples of interfaces that don’t fit this generalization. They deal with the same events, but the low-level interrupt handling is slightly different.

The usual interrupt routine can tell the difference between a new-packet-arrived interrupt and a done-transmitting notification by checking a status register found on the physical device. The snull interface works similarly, but its status word lives in dev->priv. The interrupt handler for a network interface looks like this:

void snull_interrupt(int irq, void *dev_id, struct pt_regs *regs) { int statusword; struct snull_priv *privptr; /* * As usual, check the "device" pointer for shared handlers. * Then assign "struct device *dev" */ #if 0 /* This is the way to do things for non-shared handlers */ struct device *dev = (struct device *)(irq2dev_map[irq]); #else /* Otherwise use this SA_SHIRQ-safe approach */ struct device *dev = (struct device *)dev_id; /* ... and check with hw if it's really ours */ #endif if (!dev /*paranoid*/ ) return; dev->interrupt = 1; /* lock */ /* retrieve statusword: real netdevices use inb() or inw() */ privptr ...

Get Linux Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.