DOC PREVIEW
U of I CS 498 - Network Drivers

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 498 Lecture 8 Network DriversNetwork Device InterfacesProcedures to Look at in Network Driversinit()When is init() Invoked?Searching for a Network AdapterSlide 7Initializing physical/MAC fields in net_deviceHelper FunctionsSlide 10Opening a Network AdapterClosing a Network AdapterTransmitting Data PacketsSlide 14Receiving Packets/Control InformationCases Under Which Interrupts Are UsedSlide 17Slide 18Receiving Data PacketsSlide 20Problems in Transmitting PacketsCS 498 Lecture 8Network DriversJennifer HouDepartment of Computer Science University of Illinois at Urbana-ChampaignReading: Chapters 5.3, The Linux Networking Architecture: Design and Implementation of Network Protocols in the Linux KernelNetwork Device Interfacesdriver.cdriver.cnet_txnet_interruptnet_rxskbskbskbskbskbskbnet_start_xmitnet_open net_stopnet_devicenet_devicedev.cdev.cnetif_rxdev->hard_start_xmit dev->open dev->stopdev_queue_xmitdev_open dev_closeHigher Protocol InstancesHigher Protocol InstancesNetwork devices(adapter-independent)Network devicesinterfaceNetwork driver(adapter-specific)Abstraction from Adapter specificsProcedures to Look at in Network Drivers Initializing network adaptersOpening and closing a network adapterSending data packets to a network adapterReceiving data packets from a network adapterinit()An example is netcard_probe(dev) in net/core/isa-skeleton.c (lines 135-157).Major functionsSearch for a matched adapter and discover the I/O port for devbase_addr.Initialize the net_device structure with driver information.When is init() Invoked?Recall in register_netdevice()•If devinit() exists, the network adapter is first searched and initialized with the function init().•If a net_device with the same name is already in the list dev_base, return an error message; otherwise, add the dev_device, dev, to the list.•Sets devstate to LINK_STATE_PRESENT•dev_init_scheduler() (i) sets the scheduling discipline to FIFO; (ii) initializes the timer devwatchdog_timer with dev_watchdog_init(). •The network device is assigned a new index (devifindex).•notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev) calls all the registered methods in netdev_chainSearching for a Network AdapterCase 1: If the base address is already specified when the module is loaded or when the system is booted, it can be used to locate the network adapter.In the case of modularized drivers, the I/O base address (e.g., io=0x280) is transferred to the net_device structure in init_module() of the driver module.In the case of integrated drivers, the base address is maintained in the list dev_boot_setup of the method netdev_boot_setup_check() at system boot time. The base address is then set in the net_device structure in init_netdev().Searching for a Network AdapterCase 2: The base address is not specified:A network adapter generally supports a set of defined port addresses.The addresses in the pre-defined set can be probed one after another to locate a network adapter. In either case, the I/O port, starting at the base address, are reserved by request_region (ioaddr,NETCARD_IO_EXTENT, cardname).Initializing physical/MAC fields in net_deviceIf the network adapter does not support dynamic interrupt allocation, then the irq number is determined (through autoirq_setup() followed by autoirq_report()). The irq request is made via request_irq()A list of reserved interrupts can be viewed in /proc/interruptsThe DMA channel is determined and reserved by request_dma().The memory for the private data structure devpriv is reserved and initialized.The references to driver-specific methods are set in the net_device structure. Methods specific to the MAC protocol is set via ether_setup().Helper Functionsrequest_region(port,range,name) reserves a region of I/O ports, starting with port, and marks them as allocated.release_region(start,n) releases allocated port ranges.check_region(port,range) checks if the range has already been taken.Helper Functionsrequest_irq(irq, handler, flags, device, dev_id) reserves and initializes the interrupt line with number irq.free_irq(irq,dev_id) releases a reserved interrupt.Opening a Network Adapterifconfig  ioctl()  dev_open() in dev.c  [ devopen() ]  net_open() in driver.clines 335-367 in isa-skeleton.cFor modern adapters that support dynamic interrupt allocation, IRQ and DMA are reserved in net_open().The reference count is increased using MOD_INC_USE_COUNT.The adapter is initialized by writing a specific value to a hardware register (I/O port) of the adapter.netif_start_queue(dev) sets devstate to LINK_STATE_START.Closing a Network AdapterLines 557-582 in isa-skeleton.cnetif_stop_queue() sets devstate to LINK_STATE_OFF.Disable DMA and free the DMA channel (set in devdma).Free the IRQ (set in devirq).Release the physical interrupt line.Decrement the reference count using MOD_INC_USE_COUNT.Transmitting Data Packetsdev_queue_xmt  [ devhard_start_xmit ]  net_start_xmt.net_send_packet(skb,dev) in lines 374--434devhard_start_xmit(skb,dev)The ring buffer of modern network adapters usually consists of 16-64 pointers to socket buffers.Before the call, netif_queue_stopped(dev) has been used to make sure that there is at least one free pointer in the ring buffer.To send a packet, skb, the pointer to the skb is inserted into the ring buffer.Transmitting Data Packetsdevtrans_start = jiffiesAfter the insertion, one needs to check for whether or not there are more free buffers. If not, invoke netif_stop_queue(dev).The socket buffer remains in the ring buffer until the network adapter notifies that the packet has been transmitted via an interrupt. In the interrupt-handling routine, the socket buffer will be removed from the ring buffer and freed via dev_kfree_skb().Receiving Packets/Control InformationA network adapter uses interrupts and its driver-specific interrupt-handling routine to communicate with the kernel.There are three cases in which a network adapter will use an interrupt:Receiving a data packetAcknowledging a packet transmissionNotifying an error.Cases Under Which Interrupts Are Useddev.cdev.cdriver.cdriver.cnet_interruptnetif_rxnet_rxnet_txReceiving a packetCompleting a transmissionprocessnet_errorError conditionReceiving Packets/Control InformationExample: net_interrupt() in lines 476--503The status is read from the state register to determine the case.If a packet is received,


View Full Document

U of I CS 498 - Network Drivers

Documents in this Course
Lecture 5

Lecture 5

13 pages

LECTURE

LECTURE

39 pages

Assurance

Assurance

44 pages

LECTURE

LECTURE

36 pages

Pthreads

Pthreads

29 pages

Load more
Download Network Drivers
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Network Drivers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Network Drivers 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?