fall 2004fsu cis 5930 internet protocols1 network devices reading: chapter 5

22
Fall 2004 FSU CIS 5930 Internet Protocols 1 Network Devices Reading: Chapter 5

Upload: erick-golden

Post on 29-Dec-2015

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 1

Network Devices

Reading: Chapter 5

Page 2: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 2

Network devices

• Interface between network adapters and software protocols

• Asynchronous input/output point of protocol stack

Page 3: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 3

(Network) Hardware Properties

• I/O ports (base address)– Address of the hardware (in I/O address space)

• Interrupt ReQuest (IRQ)– Informing kernel something happens at

hardware

• DMA channel– Direct Memory Access

Page 4: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 4

Network device interface

• Abstract from technical details of network adapters

• Uniform interface for access by protocol instances– dev.c (net/core/dev.c)

• Providing interface/functions for upper layer

– net_device structure (include/linux/netdevice.h)

• Hiding specific details in network drivers

– xxx_driver.c (drivers/net/xxx_driver.c)• Implementation of specific network drivers

Page 5: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 5

Network device interface (Cont’d)

driver.cdriver.c

net_tx

net_interrupt

net_rx

skbskb skbskb

skbskb

net_start_xmit

net_open net_stop

net_devicenet_device

dev.cdev.c

netif_rx

dev->hard_start_xmit dev->open dev->stop

dev_queue_xmit dev_open dev_close

Higher protocol instancesHigher protocol instances

Network devices(Adapter-independent)

Network-devicesinterface

Network driver(Adapter-specifics)

Abstraction from Adapter specfics

Page 6: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 6

net_device structure

• Defined in include/linux/netdevice.h– Abtract from network adapter specifics– Containing network adapter information– Configuration data of the adapter

– General fields of a network device– Hardware-specific fields– Data on physical layer– Data on network layer– Device-driver methods/functions

Page 7: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 7

General fields of a network device

• Name– For example, eth0, lo

• ifindex• State

– For example, if the adapter is up

• qdisc– Queue discipline– How packets are served

• And other fields

Page 8: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 8

Hardware-specific fields

• rmem_start, rmem_end, mem_start, mem_end– Memory for sending/receiving packets

• base_addr– I/O base address

• irq– Interrupt ReQuest

• DMA channel• And other fields

Page 9: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 9

Data on physical layer

• hard_header_length– Layer-2 packet header length

• mtu– Maximum transfer unit

• addr_len, dev_addr[MAX_ADDR_LEN]– Layer-2 address length and address

• And other fields

Page 10: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 10

Data on network layer

• ip_ptr, ip6_ptr, etc– Corresponding layer-3 pointers

• family– Address family, e.g., AF_INET for IP

• pa_alen– Address length for the family, e.g, 4 for IP

• pa_addr, pa_mask– Address and mask

• And other fields

Page 11: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 11

Device-driver methods• They are function pointers. Adapter drivers

need to implement and map to them• Initialization/activation/de-activation

– init(), destructor(), open(), close()

• Transmission of data– hard_start_xmit()

• Control functions– do_ioctl(), set_config()

• Helpful functions– dard_header(), hard_header_parse(), etc

• Other functions

Page 12: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 12

Managing Network Devices

dev_basedev_base

name: eth0name: eth0

statestate

nextnext

privpriv

net_device

......

HardwareHardware

MAC LayerMAC Layer

Network layerNetwork layer

local1private driver structurelocal1private driver structure

name: eth1name: eth1

statestate

nextnext

privpriv

net_device

......

HardwareHardware

MAC LayerMAC Layer

Network layerNetwork layer

local2private driver structurelocal2private driver structure

net_devicenet_device

openopen

stopstop

hard_start_xmithard_start_xmit

......

adapter_open()

adapter_stop()

adapter_start_xmit()

openopen

stopstop

hard_start_xmithard_start_xmit

......

adapter2_open()

adapter2_stop()

adapter2_start_xmit()

Page 13: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 13

Functions to manage devices

• Registering/unregistering devices• Opening/closing devices• Creating/finding devices• Transmitting over devices

• Provided in the following two files– net/core/dev.c– drivers/net/net_init.c

Page 14: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 14

Registering/unregistering devices

• init_netdev(dev, sizeof_priv, mask, setup)

• init_etherdev(dev, priv_size)• ether_setup(dev)• register_netdevice(dev)• unregister_netdevice(dev)

Page 15: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 15

Opening/closing devices

• dev_open(dev)• dev_close(dev)

Page 16: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 16

Creating/finding devices

• dev_alloc_name(dev, name)• dev_alloc(name, err)• dev_get_by_name(name)• dev_get(name)• dev_getbyhwaddr(type, ha)• dev_load(name)

Page 17: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 17

Transmitting over network devices

• dev_queue_xmit(skb)

Page 18: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 18

Network drivers

• They implement adapter specific functions– Initializing adapters– Opening and closing network adapters– Transmitting/receiving data

– We use sample driver isa_skeleton.c to discuss functions (drivers/net/isa_skeleton.c)

Page 19: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 19

Initializing adapters

• net_init()/net_probe()– netcard_probe(dev)– netcard_probe1(dev, ioaddr)

• Helper functions to allocate system resources– Request_region(), release_region(),

check_region()– Request_irq(), free_irq()– Request_dma(), free_dma()

Page 20: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 20

Opening/closing adapters

• net_open(dev)• net_stop(dev)

Page 21: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 21

Transmitting data

• net_send_packet(skb, dev)• net_interrupt(irq, dev_id, regs)

– net_tx(dev)– net_rx(dev)

dev.cdev.c

driver.cdriver.c

net_interrupt

netif_rx

net_rxnet_tx

Receiving a packetCompletingA transmission process

net_error

Errow situation

Page 22: Fall 2004FSU CIS 5930 Internet Protocols1 Network Devices Reading: Chapter 5

Fall 2004 FSU CIS 5930 Internet Protocols 22

About the project

• Progress, problems encountered