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.
|Dynamic DNS—an Object Lesson in Problem Solving||May 21, 2013|
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
|Non-Linux FOSS: Seashore||May 10, 2013|
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Dynamic DNS—an Object Lesson in Problem Solving
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Tech Tip: Really Simple HTTP Server with Python
10 min 31 sec ago
- Keeping track of IP address
2 hours 1 min ago
- Roll your own dynamic dns
7 hours 14 min ago
- Please correct the URL for Salt Stack's web site
10 hours 26 min ago
- Android is Linux -- why no better inter-operation
12 hours 41 min ago
- Connecting Android device to desktop Linux via USB
13 hours 10 min ago
- Find new cell phone and tablet pc
14 hours 8 min ago
15 hours 37 min ago
- Automatically updating Guest Additions
16 hours 45 min ago
- I like your topic on android
17 hours 32 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi
It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?