Networking with the Printer Port
As far as the kernel proper is concerned, the PLIP device is just like any other network device. More specifically, it is like any other Ethernet interface even though its name is plipx instead of ethx.
When a datagram must be transmitted through a network interface, it is passed to the transmission function of the device driver. The driver receives a socket-buffer argument (struct sk_buff) and a pointer to itself (struct device).
With PLIP, transmission occurs by encapsulating the IP datagram into a “hardware header” for delivery, not unlike what happens for any other transmission medium. The difference with PLIP is that although it receives a data packet that already includes an Ethernet header, the driver adds its own header. A packet encapsulated by PLIP, as it travels over the parallel cable, is made up of the following fields:
Packet length: Transmission is headed by the length of the data packet in bytes, least significant byte first. The count is transmitted as a 16-bit number that doesn't include the count itself or the final checksum byte.
Ethernet header: PLIP uses Ethernet encapsulation, so that programming the first implementation (in the PC world, when Linux didn't exist) was simplified. These fourteen bytes are almost useless, but they are still present for backward compatibility.
IP data: IP data directly follow the header, just as with Ethernet interfaces.
Checksum byte: The trailing byte of a PLIP transmission is a checksum byte, which must equal the sum modulo 256 of every data byte in the packet, excluding the leading two bytes (the length) and the checksum itself.
Whenever a packet is transmitted, all of the bytes are sent through the cable using the 5-bit protocol described earlier. This is quite straightforward and works flawlessly, unless something goes haywire during transmission.
The interesting part of a PLIP communication channel is how asynchronous operations are handled. Transmission and reception of data packets must fit with other system operations and must be fault tolerant as much as possible. This involves several kernel resources and is quite interesting to anyone interested in kernel internals.
There are three problems to overcome to achieve reliable PLIP transmission. Outgoing packets must be transmitted asynchronously with respect to the rest of the system; even if transmission is CPU bound, it should happen outside of the normal computational flow. Incoming packets must also be received asynchronously, and they must be able to notify the PLIP device driver about their arrival. The last problem is fault tolerance; if one of the parties locks up transmission for any reason, we don't want the peer host to freeze while it waits for a strobe signal.
Asynchronous operation is achieved in PLIP by using the kernel task queues (which were introduced in the June 1996 issue of Linux Journal). Fault tolerance and timeouts are implemented using a state-machine implementation that interleaves PLIP transmission/reception with other computational activities without losing track of the internal status of the transmitter.
Let's look at PLIP cable connecting machines called Tanino and Romeo (Tanino = Tx, Romeo = Rx). The following paragraphs explain what happens when Tanino sends a packet to Romeo.
Tanino sends the signal to interrupt Romeo, disables interrupt reporting for itself and initiates the transmission loop by registering plip_bh in the immediate task queue and returning. When plip_bh runs, it knows that the interface is sending data and calls plip_send_packet.
Romeo, when interrupted (plip_interrupt), registers plip_bh in the immediate task queue. The plip_bh function dispatches computation to plip_receive_packet, which disables interrupt reporting in the interface and starts receiving bytes.
Tanino's loop is built on plip_send (which transmits a single byte) while Romeo's loop is built on plip_receive (which receives a single byte). These two functions are ready to detect a timeout condition, and in this case, they return the TIMEOUT macro to the calling function, which returns TIMEOUT to plip_bh.
When the callee aborts the loop by returning TIMEOUT, the plip_bh function registers a function in the timer task queue, so that the loop will be entered again at the next clock tick. If timeout continues after a few clock ticks, transmission or reception of this packet is aborted, and an error is registered in the enet_statistics structure; these errors are shown by the ifconfig command.
If the timeout condition doesn't persist at the next clock tick, data exchange goes on flawlessly. The state machine implemented in the interface is responsible for restarting communication at exactly the place where the timeout occurred.
As you see, the PLIP interface is fairly symmetrical.
- Readers' Choice Awards 2013
- Mars Needs Women
- IBM Will Minimize Impact of Future Disasters
- Sublime Text: One Editor to Rule Them All?
- December 2013 Issue of Linux Journal: Readers' Choice
- Raspberry Pi: the Perfect Home Server
- RSS Feeds
- Tech Tip: Really Simple HTTP Server with Python
- Linux Systems Administrator
- Senior Perl Developer
- Nothing is perfect
1 min 12 sec ago
- Mixtapes Community
5 hours 40 min ago
- KDE is one true DE
6 hours 14 min ago
- Command Line Shells (Bash, Zsh, etc.) are 2nd place
6 hours 43 min ago
8 hours 37 min ago
- yes it's Jupiter Broadcasting
9 hours 57 min ago
- nice to see PClinuxOS finally
12 hours 31 min ago
- Personally, I am no longer a
13 hours 27 min ago
- It's Jupiter
1 day 3 hours ago
- GIMP is certainly a graphic
1 day 4 hours ago