Accessing the NIC A look at the mechanisms that software can use to interact with our 82573L network interface.

Slides:



Advertisements
Similar presentations
I/O Unit.
Advertisements

Khaled A. Al-Utaibi  Computers are Every Where  What is Computer Engineering?  Design Levels  Computer Engineering Fields  What.
CS-334: Computer Architecture
Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. PCI Devices NIC Cards NIC card architecture Access to NIC register – PCI access.
An introduction to the PCI configuration space registers
Programming Super-VGA Graphics Devices Introduction to VESA graphics modes and to organization of the linear frame-buffer memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
The RealTek interface Introduction to the RTL-8139 network controller registers.
A look at memory issues Data-transfers must occur between system memory and the network interface controller.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
Accessing network hardware The Network Interface Controllers are part of a larger scheme used in modern PCs for device control.
Exploring a modern NIC An introduction to programming the Intel 82573L gigabit ethernet network interface controller.
Direct I/O Programming An introduction to the Pentium’s mechanism for programming peripheral hardware components.
Computer System Overview
I/O Systems CS 3100 I/O Hardware1. I/O Hardware Incredible variety of I/O devices Common concepts ◦Port ◦Bus (daisy chain or shared direct access) ◦Controller.
Detecting PCI devices On identifying the peripheral equipment installed in our PC.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
A device-driver for Video Memory Introduction to basic principles of the PC’s graphics display.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
What’s needed to transmit? A look at the minimum steps required for programming our anchor nic’s to send packets.
Chapter 7 Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 2: 80386DX Internal Architecture & Data Organization.
Computer Organization and Assembly language
Copyright Arshi Khan1 System Programming Instructor Arshi Khan.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
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.
Computer Organization
C.S. Choy95 COMPUTER ORGANIZATION Logic Design Skill to design digital components JAVA Language Skill to program a computer Computer Organization Skill.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
1 CS503: Operating Systems Spring 2014 Dongyan Xu Department of Computer Science Purdue University.
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
Ihr Logo Operating Systems Internals & Design Principles Fifth Edition William Stallings Chapter 1 Computer System Overview.
2009 Sep 10SYSC Dept. Systems and Computer Engineering, Carleton University F09. SYSC2001-Ch7.ppt 1 Chapter 7 Input/Output 7.1 External Devices 7.2.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
January 10, Kits Workshop 1 Washington WASHINGTON UNIVERSITY IN ST LOUIS A Smart Port Card Tutorial --- Software John DeHart Washington University.
Introduction First 32 bit Processor in Intel Architecture. Full 32 bit processor family Sixth member of 8086 Family SX.
CH10 Input/Output DDDData Transfer EEEExternal Devices IIII/O Modules PPPProgrammed I/O IIIInterrupt-Driven I/O DDDDirect Memory.
Computer Hardware A computer is made of internal components Central Processor Unit Internal External and external components.
Computer Organization. The digital computer is a digital system that performs various computational tasks Digital computer use binary number system which.
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems Overview I/O Hardware Application.
I/O Interface. INTRO TO I/O INTERFACE I/O instructions (IN, INS, OUT, and OUTS) are explained. Also isolated (direct or I/O mapped I/O) and memory-mapped.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
بسم الله الرحمن الرحيم MEMORY AND I/O.
1 Computer Architecture. 2 Basic Elements Processor Main Memory –volatile –referred to as real memory or primary memory I/O modules –secondary memory.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Part IVI/O Systems Chapter 13: I/O Systems. I/O Hardware a typical PCI bus structure 2.
Block diagram of a computer system Basic components of a computer system using block diagrams: Cpu Memory Input and output unit Evolution of microprocessor.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Operating Systems.
Chapter 3 Getting Started. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Objectives To give an overview of the structure of a contemporary.
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction of microprocessor
CS 286 Computer Organization and Architecture
The PCI bus (Peripheral Component Interconnect ) is the most commonly used peripheral bus on desktops and bigger computers. higher-level bus architectures.
Today’s agenda Hardware architecture and runtime system
Presentation transcript:

Accessing the NIC A look at the mechanisms that software can use to interact with our 82573L network interface

Typical NIC hardware TX FIFO nic RX FIFO CPU packet main memory transceiver buffer LAN cable B U S RX FIFO CPU

No way to communicate SOFTWARE Linux operating system kernel (no knowledge of the NIC) These components lack a way to interact HARDWARE Network interface controller (no knowledge of the OS)

Role for a ‘device driver’ SOFTWARE Linux operating system kernel (no knowledge of the NIC) device driver module (knows about both the OS and the NIC) HARDWARE Network interface controller (no knowledge of the OS)

Three x86 address-spaces accessed using a large variety of processor instructions (mov, add, or, shr, push, etc.) and virtual-to-physical address-translation memory space (4GB) accessed only by using the processor’s special ‘in’ and ‘out’ instructions (without any translation of port-addresses) PCI configuration space (16MB) i/o space (64KB) i/o-ports 0x0CF8-0x0CFF dedicated to accessing PCI Configuration Space

Interface to PCI Configuration Space PCI Configuration Space Address Port (32-bits) 31 23 16 15 11 10 8 7 2 0 CONFADD ( 0x0CF8) E N reserved bus (8-bits) device (5-bits) function (3-bits) doubleword (6-bits) 00 Enable Configuration Space Mapping (1=yes, 0=no) PCI Configuration Space Data Port (32-bits) 31 0 CONFDAT ( 0x0CFC)

82573L Two mechanisms for accessing the NIC: I/O space (allows booting over the network) Memory-mapped I/O (available after booting) Both mechanisms require probing for PCI Configuration Space information (for I/O port-number or memory-mapped address) Probing requires knowing the device’s IDs (the VENDOR_ID and the DEVICE_ID)

Our NIC’s ID numbers The VENDOR_ID for Intel Corporation: 0x8086 (famous chip-number for IBM-PCs) The DEVICE_ID for Intel’s 82573L NIC: 0x109A (found in Intel’s documentation p.141)

NIC’s access mechanisms The two ways for accessing our network controller’s ‘control’ and ‘status’ registers are explained in Chapter 13 of the Intel Open Source Programmer’s Reference This Chapter also includes a detailed list of the names and functional descriptions for the various network interface registers All are accessed as 32-bit ‘doubewords’

PCI Configuration Space A non-volatile parameter-storage area for each PCI device-function PCI Configuration Space Header (16 doublewords – fixed format) PCI Configuration Space Body (48 doublewords – variable format) 64 doublewords

Class/SubClass/ProgIF Expansion ROM Base Address PCI Configuration Header 16 doublewords 31 0 31 0 Dwords Status Register Command Register Device ID Vendor ID 1 - 0 BIST Header Type Latency Timer Cache Line Size Class Code Class/SubClass/ProgIF Revision ID 3 - 2 Base Address 1 Base Address 0 5 - 4 Base Address 3 Base Address 2 7 - 6 Base Address 5 Base Address 4 9 - 8 Subsystem Device ID Subsystem Vendor ID CardBus CIS Pointer 11 - 10 reserved capabilities pointer Expansion ROM Base Address 13 - 12 Maximum Latency Minimum Grant Interrupt Pin Interrupt Line reserved 15 - 14

Interface to PCI Configuration Space PCI Configuration Space Address Port (32-bits) 31 23 16 15 11 10 8 7 2 0 CONFADD ( 0x0CF8) E N reserved bus (8-bits) device (5-bits) function (3-bits) doubleword (6-bits) 00 Enable Configuration Space Mapping (1=yes, 0=no) PCI Configuration Space Data Port (32-bits) 31 0 CONFDAT ( 0x0CFC)

Reading PCI Configuration Data Step one: Output the desired longword’s address (bus, device, function, and dword) with bit 31 set to 1 (to enable access) to the Configuration-Space Address-Port Step two: Read the designated data from the Configuration-Space Data-Port: # read the PCI Header-Type field (byte 2 of dword 3) for bus=0, device=0, function=0 movl $0x8000000C, %eax # setup address in EAX movw $0x0CF8, %dx # setup port-number in DX outl %eax, %dx # output address to port mov $0x0CFC, %dx # setup port-number in DX inl %dx, %eax # input configuration longword shr $16, %eax # shift word 2 into AL register movb %al, header_type # store Header Type in variable

Demo Program We created a short Linux utility that searches for and reports all of your system’s PCI devices It’s named “pciprobe.cpp” on our CS686 website It uses some C++ macros that expand to Intel input/output instructions -- which normally are ‘privileged’ instructions that a Linux application-program is not allowed to execute (segfault!) Our system administrator (Alex Fedosov) has created a utility (named “iopl3”) that will allow your command-shell to acquire I/O privileges

Example: network interface We identify the network interface controller in our classroom PC’s by class-code 0x02 The subclass-code 0x00 is for ‘ethernet’ We can identify the NIC from its VENDOR and DEVICE identification-numbers: VENDOR_ID = 0x8086 (for Intel Corporation) DEVICE_ID = 0x109A (for 82573L controller) You can use the ‘grep’ command to search for these numbers in this header-file: </usr/src/linux/include/linux/pci_ids.h>

Class/SubClass/ProgIF Expansion ROM Base Address The NIC’s PCI ‘resources’ 16 doublewords 31 0 31 0 Dwords Status Register Command Register DeviceID 0x109A VendorID 0x8086 1 - 0 BIST Header Type Latency Timer Cache Line Size Class Code Class/SubClass/ProgIF Revision ID 3 - 2 Base Address 1 Base Address 0 5 - 4 Base Address 3 Base Address 2 7 - 6 Base Address 5 Base Address 4 9 - 8 Subsystem Device ID Subsystem Vendor ID CardBus CIS Pointer 11 - 10 reserved capabilities pointer Expansion ROM Base Address 13 - 12 Maximum Latency Minimum Grant Interrupt Pin Interrupt Line reserved 15 - 14

Linux PCI helper-functions #include <linux/pci.h> struct pci_dev *devp; unsigned int mmio_base; unsigned int mmio_size; void *io; devp = pci_get_device( VENDOR_ID, DEVICE_ID, NULL ); if ( devp == NULL ) return –ENODEV; mmio_base = pci_resource_start( devp, 0 ); mmio_size = pci_resource_len( devp, 0 ); io = ioremap_nocache( mmio_base, iomm_size ); if ( io == NULL ) return –ENOSPC;

Mechanisms compared Each NIC register has its own address in memory (allows one-step access) kernel memory-space NIC i/o-memory io user memory-space Access to all of the NIC’s registers is muliplexed through a pair of I/O-ports (requires multiple instructions) addr data CPU’s ‘virtual’ address-space CPU’s ‘I/O’ address-space

C language hides complexity For the multiplexed i/o-space access… // Your module uses just one C statement to ‘input’ a NIC register-value: int device_status = inl( ioport + 0x0008 ); // but the C compiler translates this statement into SIX cpu-instructions: mov ioport, %dx mov $8, %eax out %eax, %dx add $4, %dx in %dx, %eax mov %eax, device_status

Seeing through the C For the i/o-memory ‘mapped’ access… // Your module uses just one C statement to ‘fetch’ a NIC register-value: int device_status = ioread32( io + 0x0008 ); // but the C compiler translates this statement into three cpu-instructions: mov io, %esi mov 8(%esi), %eax mov %eax, device_status

Course’s continuing theme is… “Using the computer to study the computer”

TimeStamp Counter The x86 processor has a 64-bit register named the TimeStamp Counter (TSC) It continuously increments each cpu cycle (so with a 2-GHz processor, it increments two-billion times every second) It can be read at any time using a special processor instruction (named RDTSC); its value appears in the EDX:EAX registers

Using CLI and STI For doing accurate timing measurements, your module can temporarily disable your CPU’s response to ‘interrupt’ requests Basic steps for performing an uninterrupted ‘elapsed time’ measurement: step 1: Turn off interrupts (using ‘cli’) step 2: Read the TimeStamp Counter step 3: Perform a NIC register access step 4: Read the TimeStamp Counter step 5: Turn on interrupts (using ‘sti’) step 6: Subtract start-time from finish-time

In-class exercise Look at our ‘timing.c’ demo module – for an ‘inline’ assembly language example using the ‘rdtsc’, ‘cli’ and ‘sti’ instructions Add some extra code of your own, and do an additional timing measurement, so you can compare the execution-times for the NIC’s two register-access mechanisms How much faster is memory-mapped I/O?