Our ‘xmit1000.c’ driver Implementing a ‘packet-transmit’ capability with the Intel 82573L network interface controller.

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
Hardware ‘flow control’ How we can activate our NIC’s ability to avoid overwhelming the capacities of its ‘link partner’
CS-334: Computer Architecture
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
Fixing some driver problems Most software is discovered to have some ‘design-flaws’ after it has been put into use for awhile.
Receiver ‘packet-splitting’
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
On using ‘tasklets’ An example of the Linux kernel’s ‘tasklet’ mechanism for deferring some interrupt-handling work.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
Hardware-address filtering How can we send packets to just one node on our ‘anchor’ cluster?
The RealTek interface Introduction to the RTL-8139 network controller registers.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
Exploring a modern NIC An introduction to programming the Intel 82573L gigabit ethernet network interface controller.
82573L Initializing our Pro/1000. Chicken-and-Egg? We want to create a Linux Kernel Module that can serve application-programs as a character-mode device-driver.
RTL-8139 experimentation Setting up an environment for studying the Network Controller.
A “real” network driver? We want to construct a Linux network device-driver that is able to send and receive packets.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Memory Management 2010.
Informationsteknologi Friday, November 16, 2007Computer Architecture I - Class 121 Today’s class Operating System Machine Level.
Our ‘nic.c’ module We create a ‘character-mode’ device-driver for the 82573L NIC to use in futrure experiments.
Our ‘nic.c’ module We create a ‘character-mode’ device-driver for the 82573L NIC to use in future experiments.
What’s needed to transmit? A look at the minimum steps required for programming our 82573L nic to send packets.
The ‘ioctl’ driver-function On implementing a way to query and modify our UART’s baudrate via the ‘device-file’ abstraction.
Adjusting out device-driver Here we complete the job of modifying our ‘nicf.c’ Linux driver to support ‘raw’ packet-transfers.
OPERATING SYSTEMS Introduction
What’s needed to transmit? A look at the minimum steps required for programming our anchor nic’s to send packets.
Hardware-address filtering How can we send packets to just one node on our ‘anchor’ cluster?
Building TCP/IP packets A look at the computation-steps which need to be performed for utilizing the TCP/IP protocol.
GigE Knowledge. BODE, Company Profile Page: 2 Table of contents  GigE Benefits  Network Card and Jumbo Frames  Camera - IP address obtainment  Multi.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
Chapter 7 Input/Output Luisa Botero Santiago Del Portillo Ivan Vega.
Chapter 8 Input/Output. Busses l Group of electrical conductors suitable for carrying computer signals from one location to another l Each conductor in.
Computer Organization
System Calls 1.
CSC 311 IEEE STANDARD ETHERNET Common Bus topology Uses CSMA/CD Named after “ether”, the imaginary substance many once believed occupied all of space.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
Segmentation & O/S Input/Output Chapter 4 & 5 Tuesday, April 3, 2007.
1 Lecture 20: I/O n I/O hardware n I/O structure n communication with controllers n device interrupts n device drivers n streams.
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
A Comparative Study of the Linux and Windows Device Driver Architectures with a focus on IEEE1394 (high speed serial bus) drivers Melekam Tsegaye
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
Output Devices. Printers Factors affecting choice Volume of output High volume require fast, heavy-duty printer Quality of print required Location of.
Ethernet Driver Changes for NET+OS V5.1. Design Changes Resides in bsp\devices\ethernet directory. Source code broken into more C files. Native driver.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public ITE PC v4.0 Chapter 1 1 Ethernet Network Fundamentals – Chapter 9.
Cisco 3 - Switching Perrine. J Page 16/4/2016 Chapter 4 Switches The performance of shared-medium Ethernet is affected by several factors: data frame broadcast.
Organisasi Sistem Komputer Materi VIII (Input Output)
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Connecting Devices CORPORATE INSTITUTE OF SCIENCE & TECHNOLOGY, BHOPAL Department of Electronics and.
4 Linking the Components Linking The Components A computer is a system with data and instructions flowing between its components in response to processor.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
+ Lecture#2: Ethernet Asma ALOsaimi. + Objectives In this chapter, you will learn to: Describe the operation of the Ethernet sublayers. Identify the major.
LonWorks Introduction Hwayoung Chae.
Chapter 2: The Linux System Part 4
Instructor Materials Chapter 5: Ethernet
Chapter 2: System Structures
Operating Systems Chapter 5: Input/Output Management
Who’s listening? Some experiments with an ‘echo’ service on our anchor-cluster’s local network of 82573L nic’s.
Presentation transcript:

Our ‘xmit1000.c’ driver Implementing a ‘packet-transmit’ capability with the Intel 82573L network interface controller

Remenber ‘echo’ and ‘cat’? Your device-driver module (named ‘uart.c’) was supposed to allow two programs that are running on a pair of adjacent PCs to communicate via a “null-modem” cable $ echo Hello > /dev/uart $ _ $ cat /dev/uart Hello _ Receiving…Transmitting…

‘keep it simple’ Let’s try to implement a ‘write()’ routine for our Intel Pro/1000 ethernet controllers that will provide the same basic functionality as we achieved with our serial UART driver It should allow us to transmit a message by using the familiar UNIX ‘cat’ command to redirect output to a character device-file Our device-file will be named ‘/dev/nic’

This function will program the actual data-transfer Driver’s components write my_fops my_write() module_init() module_exit() This function will allow us to inspect the transmit-descriptors This function will detect and configure the hardware, define page-mappings, allocate and initialize the descriptors, start the ‘transmit’ engine, create the pseudo-file and register ‘my_fops’ This function will do needed ‘cleanup’ when it’s time to unload our driver – turn off the ‘transmit’ engine, free the memory, delete page-table entries, the pseudo-file, and the ‘my_fops’ ‘struct’ holds one function-pointer my_get_info()

Kzalloc() Linux kernels since offer this convenient function for allocating pre-zeroed kernel memory It has the same syntax as the ‘kmalloc()’ function (described in our texts), but adds the after-effect of zeroing out the newly-allocated memory-area Thus it does two logically distinct actions (often coupled anyway) within a single function-call void *kmem = kmalloc( region_size, GFP_KERNEL ); memset( kmem, 0x00, region_size ); /* can be replaced with */ void *kmem = kzalloc( region_size, GFP_KERNEL );

Single page-frame option Packet-Buffer (3-KB) (reused for successive transmissions) 4KB Page- Frame Descriptor-Buffer (1-KB) (room for up to 256 descriptors)

Our Tx-Descriptor ring descriptor 0 Our ‘reusable’ transmit-buffer (1536 bytes) descriptor 1 descriptor 2 descriptor 3 descriptor 4 descriptor 5 descriptor 6 descriptor 7 Array of 8 transmit-descriptors one packet-buffer TAILHEAD After writing the data into our packet-buffer, and writing its length to the the current TAIL descriptor, our driver will advance the TAIL index; the NIC responds by reading the current HEAD descriptor, fetching its data, then advancing the HEAD index as it sends our data out over the wire.

‘/proc/xmit1000’ This pseudo-file can be examined anytime to find out what values (if any) the NIC has ‘written back’ into the transmit-descriptors (i.e., the descriptor-status information) and current values in registers TDH and TDT: $ cat /proc/xmit1000

Direct Memory Access The NIC is able to ‘fetch’ descriptors from host-system’s memory (and also can read the data from our packet-buffer) as well as ‘store’ a status-report back into the host’s memory by temporarily becoming the Bus Master (taking control of the system-bus away from the CPU so that it can perform the ‘fetch’ and ‘store’ operations directly, without CPU involvement or interference)

Configuration registers TIPG TCTL TDBAL TDBAH TDLEN TDH TDT TXDCTL CTRL CTRL_EXT Device Control Extended Device Control Transmit Inter-Packet Gap Transmit Control Transmit Descriptor-queue Base-Address (LOW) Transmit Descriptor-queue Base-Address (HIGH) Transmit Descriptor-queue Length Transmit Descriptor-queue HEAD Transmit Descriptor-queue TAIL Transmit Descriptor-queue Control

The ‘initialization’ sequence Detect the network interface controller Obtain its i/o-memory address and size Remap the i/o-memory into kernel-space Allocate memory for buffer and descriptors Initialize the array of transmit-descriptors Reset the NIC and configure its operations Create the ‘/proc/xmit1000’ pseudo-file Register our ‘write()’ driver-method

The ‘cleanup’ sequence Usually the steps here follow those in the initialization sequence -- but in backwards order: Unregister the device-driver’s file-operations Delete the ‘/proc/xmit1000’ pseudo-file Disable the NIC’s ‘transmit’ engine Release the allocated kernel-memory Unmap the NIC’s i/o-memory region

Our ‘write()’ algorithm Get index of the current TAIL descriptor Confine the amount of user-data Copy user-data into the packet-buffer Setup the packet’s Ethernet Header Setup packet-length in the TAIL descriptor Now hand over this descriptor to the NIC (by advancing the value in register TDT) Tell the kernel how many bytes were sent

Recall Tx-Descriptor Layout special 0x0 0x4 0x8 0xC CMD Buffer-Address high (bits ) Buffer-Address low (bits 31..0) 31 0 Packet Length (in bytes)CSO statusCSS reserved =0 Buffer-Address = the packet-buffer’s 64-bit address in physical memory Packet-Length = number of bytes in the data-packet to be transmitted CMD = Command-field CSO/CSS = Checksum Offset/Start (in bytes) STA = Status-field

Suggested C syntax typedef struct { unsigned long long base_addr; unsigned shortpkt_length; unsigned charcksum_off; unsigned chardesc_cmd; unsigned chardesc_stat; unsigned charcksum_org; unsigned shortspecial; } TX_DESCRIPTOR;

Transmit IPG (0x0410) 82573L IPG R =0 IPG After Deferral (Recommended value = 7) IPG Part 1 (Recommended value = 8) IPG Back-To-Back (Recommended value = 8) IPG = Inter-Packet Gap This register controls the Inter-Packet Gap timer for the Ethernet controller. Note that the recommended TIPG register-value to achieve IEEE compliant minimum transfer IPG values in full- and half-duplex operations would be (hexadecimal), equal to (7<<20) | (8<<10) | (8<<0).

Transmit Control (0x0400) R =0 R =0 R =0 MULRTXCSCMT UNO RTX RTLC R =0 SW XOFF COLD (upper 6-bits) (COLLISION DISTANCE) COLD (lower 4-bits) (COLLISION DISTANCE) 0ASDV ILOSILOS SLUSLU TBI mode PSPPSP 0 R = R =0 ENEN SPEED CT (COLLISION THRESHOLD) EN = Transmit EnableSWXOFF = Software XOFF Transmission PSP = Pad Short PacketsRLTC = Retransmit on Late Collision CT = Collision Threshold (=0xF)UNORTX = Underrun No Re-Transmit COLD = Collision Distance (=0x3F)TXCSCMT = TxDescriptor Minimum Threshold MULR = Multiple Request Support 82573L

Our driver’s elections int tx_control = 0; tx_control |= (0<<1);// EN-bit (Enable Transmit Engine) tx_control |= (1<<3);// PSP-bit (Pad Short Packets) tx_control |= (15<<4);// CT=15 (Collision Threshold) tx_control |= (63<<12);// COLD=63 (Collision Distance) tx_control |= (0<<22);// SWXOFF-bit (Software XOFF Tx) tx_control |= (1<<24);// RTLC-bit (Re-Transmit on Late Collision) tx_control |= (0<<25);// UNORTX-bit (Underrun No Re-Transmit) tx_control |= (0<<26);// TXCSMT=0 (Tx-descriptor Min Threshold) tx_control |= (0<<28);// MULR-bit (Multiple Request Support) iowrite32( tx_control, io + E1000_TCTL );// Transmit Control register 82573L Here’s a C programming style that ‘documents’ the programmer’s choices.

An ‘e1000.c’ anomaly? The official Linux kernel is delivered with a device-driver supporting Intel’s ‘Pro/1000’ gigabit ethernet controllers (several) Often this driver will get loaded by default during the system’s startup procedures But it will interfere with your own driver if you try to write a substitute for ‘e1000.ko’ So you will want to remove it with ‘rmmod’

Side-effect of ‘rmmod’ We’ve observed an unexpected side-effect of ‘unloading’ the ‘e1000.ko’ device-driver The PCI Configuration Space’s command register gets modified in a way that keeps the NIC from working with your own driver Specifically, the Bus Mastering capability gets disabled (by clearing bit #2 in the PCI Configuration Space’s word at address 4)

What to do about it? This effect doesn’t arise on our ‘anchor’ cluster machines, but you may encounter it when you try using our demo elsewhere Here’s the simple “fix” to turn Bus Master capability back on (in your ‘module_init()’) u16pci_cmd;// declares a 16-bit variable pci_read_config_word( devp, 4, &pci_cmd );// read current word pci_cmd |= (1<<2);// turn on the Bus Master enabled-bit pci_write_config_word( devp, 4, pci_cmd );// write modification

In-class demo We demonstrate our ‘xmit1000.c’ driver on an ‘anchor’ machine, with some help from a companion-module (named ‘recv1000.c’) which is soon-to-be discussed in class $ echo Hello > /dev/nic $ _ $ cat /dev/nic Hello _ Receiving… Transmitting… anchor01anchor05 LAN

In-class exercise Open three or more terminal-windows on your PC’s graphical desktop, and login to a different ‘anchor’ machine in each one Install the ‘xmit1000.ko’ module on one of the anchor machines, and then install our ‘recv1000.ko’ module on the other stations Execute the ‘cat /dev/nic’ command on the receiver-stations, and then run an ‘echo’ command on the transmitter-station