Compaq Information Technologies Group, L.P.inthe United States and other countries.
UNIX and X/Open are trademarks of The Open Group in the United States and other countries. All other
product names mentioned herein may be trademarks of their respective companies.
Confidential computer software. Valid license from Compaq required for possession, use, or copying.
Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software
Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under
vendor’s standard commercial license.
Compaq shall not be liable for technical or editorial errors or omissions contained herein. The information
in this document is provided “as is” without warranty of any kind and is subject to change without
notice. The warranties for Compaq products are set forth in the express limited warranty statements
accompanying such products. Nothing herein should be construed as constituting an additional warranty.
About This Manual
1Network Device Driver Environment
1.1
1.2
1.2.1
1.2.2
1.2.3
1.2.4
1.3
1.4
1.5
1.6
1.7
1.8
1.9
1.10
1.11
Include Files Section for a Network Driver .......................1–3
Declarations Section for a Network Driver .......................1–4
External and Forward Declarations ..........................1–5
Declaring softc and controller Data Structure Arrays ......1–6
Declaring and Initializing the driver Data Structure ......1–7
This manual discusses how to write network device drivers for computer
systems that run the Compaq Tru64™ UNIX operating system.
Audience
This manual is intended for systems engineers who:
•Use standard library routines to develop programs in the C language
•Know the Bourne shell or some other shell that is based on the UNIX
•Understand basic Tru64 UNIX concepts such as kernel, shell, process,
•Understand how to use the Tru64 UNIX programming tools, compilers,
•Develop programs in an environment that involves dynamic memory
•Understand the hardware device for which the driver is being written
•Understand the basics of the CPU hardware architecture, including
About This Manual
operating system
configuration, and autoconfiguration
and debuggers
allocation, linked list data structures, and multitasking
interrupts, direct memory access (DMA) operations, and I/O
Before you write a network device driver, we recommend that you be familiar
with the networking subsystem that the Tru64 UNIX operating system
provides. This manual assumes that you are familiar with the following
network interface types:
•Ethernet
•Fiber Distributed Data Interface (FDDI)
•Token Ring
See the Tru64 UNIX Technical Overview for descriptions of the data link
media.
This manual also assumes that you have some knowledge of the Tru64 UNIX
network programming environment, particularly:
•Data link provider interface
•X/Open transport interface
•Sockets
About This Manual xi
•Socket and XTI programming examples
•TCP specific programming information
•Information for Token Ring driver developers
•Data link interface
See the Tru64 UNIX Network Programmer’s Guide for descriptions of these
topics.
Scope of this Manual
This manual builds on the concepts and topics that are presented in Writing
Device Drivers, which is the core manual for developing device drivers on
Tru64 UNIX. It introduces topics that are specific to writing a device driver
for a local area network (LAN) device and that are beyond the scope of the
core manual.
In this manual, you can study a network driver called if_el. The if_el
driver supports the driver interface requirements for a LAN device,
specifically the 3Com 3C589C series PCMCIA adapter. The if_el driver
was implemented according to the specifications detailed in Ethernet III
Parallel Tasking ISA, EISA, Micro Channel, and PCMCIA Adapter Drivers
Technical Reference . This specification is published by 3Com Corporation,
and the manual part number is 09-0398-002B.
You can access the if_el source code in the device driver examples directory
(if you have installed it on your system). Ethernet is the network interface
type that is associated with the if_el driver. However, the explanations
point out where differences exist between Ethernet and other network
interfaces, including fiber distributed data interface (FDDI) and Token Ring.
The example network driver operates on multiple buses (specifically, the
PCMCIA bus and the ISA bus). It uses the common ifnet interface to
communicate with the upper layers of the Tru64 UNIX operating system.
The example does not emphasize any specific types of network device
drivers. However, mastering the concepts presented in this manual is useful
preparation for writing network device drivers that operate on a variety
of buses.
The manual does not discuss:
•How to write STREAMS network device drivers
•Topics associated with wide area networks (WANs)
•How to write an asynchronous transfer mode (ATM) device driver
•Details related to the network programming environment
xii About This Manual
New and Changed Features
This revision of the manual documents the following new features:
•Enabling support for enhanced hardware management
Enhanced hardware management (EHM) allows you to modify hardware
attributes, such as the type of LAN device, on either a local or a remote
system. See
Section 3.2 for more information about how a network device
driver uses routines to define and export hardware attributes.
•The unattach( ) routine
The unattach( ) routine stops the network device and frees resources
prior to unloading the device driver or powering off the bus to which the
device is attached. See Chapter 7 for more information.
Organization
This manual is organized as follows:
Chapter 1Describes the sections that make up a
Chapter 2Describes the device register offset
Chapter 3Describes how to define a softc data
Chapter 4Describes how to implement a
Chapter 5Describes how to implement a probe
Chapter 6Describes how to implement an attach
Chapter 7Describes how to implement an
network driver and compares them to
the sections that are associated with
block and character drivers.
definitions for the if_el device driver’s
associated LAN device, the 3Com 3C5x9
series Ethernet adapter.
structure, usingthe if_el devicedriver’s
el_softc structure as an example.
configure interface, using the if_el
device driver’s el_configure( )
routine as an example.
interface and associated routines, using
the if_el device driver’s el_probe( )
routine as an example.
interface, using the if_el device driver’s
el_attach( ) routine as an example.
unattach( ) routine to stop the device.
About This Manual xiii
Chapter 8Describes how to implement an init
interface and associated routines, using
the if_el device driver’s el_init( )
routine as an example.
Chapter 9Describes how to implement a start
interface and associated routines, using
the if_el device driver’s el_start( )
routine as an example.
Chapter 10Describes how to implement a watchdog
Chapter 11Describes how to implement a reset
Chapter 12Describes how to implement an ioctl
Chapter 13
Chapter 14Describes the sysconfigtab option
interface, using the if_el device driver’s
el_watch( ) routine as an example.
interface and associated routines, using
the if_el device driver’s el_reset( )
routine as an example.
interface, using the if_el device driver’s
el_ioctl( ) routine as an example.
Describes how to implement an
interrupt handler, using the if_el
device driver’s el_intr interrupt
handler as an example.
entries necessary for configuring network
device drivers on different bus types.
Related Documentation
The following examples and documents supplement information in this
manual.
Examples
The directory /usr/examples/ddk/src/network includes the example
source files that are used throughout this manual: if_el.c, if_elreg.h,
files, and sysconfigtab.
Manuals
The following documents provide important information that supplements
the information in this manual:
•Installation Instructions and Release Notes contains instructions on how
to install the Device Driver Kit Version 2.0 product, including source
code with examples and user manuals. It also describes changes to the
product and documentation since the Device Driver Kit Release 1.0.
xiv About This Manual
•Writing Device Drivers contains information that you need to develop
device drivers on the Compaq Tru64 UNIX operating system.
•Writing Kernel Modules describes topics for all kernel modules
such as kernel threads and writing kernel modules in a symmetric
multiprocessing (SMP) environment.
•Writing PCI Bus Device Drivers describes PCI bus-specific topics,
including PCI bus architecture and data structures that PCI bus device
drivers use.
•Writing VMEbus Device Drivers describes VMEbus-specific topics,
including VMEbus architecture and routines that VMEbus device
drivers use.
•The Guide to Preparing Product Kits describes how to create kernel
(device driver) product kits and layered product kits.
•Kernel Debugging describes how to use the
debuggers to find problems in kernel code. It also describes how to write
a kdbx utility extension and how to create and analyze a crash dump file.
•Programming Support Tools describes several commands and utilities in
the Tru64UNIX system, including facilities for text manipulation, macro
and program generation, and source file management.
•The Programmer’s Guide describes the programming environment of the
Tru64 UNIX operating system, with an emphasis on the C programming
language.
dbx, kdbx, and kdebug
•The Network Programmer’s Guide describes the Tru64 UNIX network
programming environment and provides information on STREAMS
programming.
•System Administration describes how to configure, use, and maintain
the Tru64 UNIX operating system.
Reference Pages
Tru64 UNIX reference pages (also called manpages) contain descriptions of
the routines (Section 9r), data structures (Section 9s), loadable services
routines (Section 9u), and global variables (Section 9v) that apply to device
drivers.
Reader’s Comments
Compaq welcomes any comments and suggestions you have on this and
other Tru64 UNIX manuals.
•Internet electronic mail: readers_comment@zk3.dec.com
A Reader’s Comment form is located on your system in the following
location:
/usr/doc/readers_comment.txt
Please include the following information along with your comments:
•The full title of the book and the order number. (The order number is
printed on the title page of this book and on its back cover.)
•The section numbers and page numbers of the information on which
you are commenting.
•The version of Tru64 UNIX that you are using.
•If known, the type of processor that is running the Tru64 UNIX software.
The Tru64 UNIX Publications group cannot respond to system problems
or technical support inquiries. Please address technical questions to your
local system vendor or to the appropriate Compaq technical support office.
Information provided with the software media explains how to send problem
reports to Compaq.
Conventions
This manual uses the following conventions:
.
.
.
...
file
buf
[]
xvi About This Manual
A vertical ellipsis indicates that a portion of an
example that would normally be present is not
shown.
In syntax definitions, a horizontal ellipsis indicates
that the preceding item can be repeated one or
more times.
Italic (slanted) type indicates variable values,
placeholders, and function parameter names.
In function definitions and syntax definitions used in
driver configuration, this typeface indicates names
that you must type exactly as shown.
In formal parameter declarations in function
definitions and in structure declarations, brackets
indicate arrays. Brackets also specify ranges for
device minor numbers and device special files in
file fragments. However, for the syntax definitions
that are used in driver configuration, these brackets
indicate items that are optional.
|Vertical bars separating items that appear in the
syntax definitions used in driver configuration
indicate that you choose one item from among those
listed.
About This Manual xvii
1
Network Device Driver Environment
A network device is responsible for both transmitting and receiving frames
over the network media. Network devices have network device drivers
associated with them. A network device driver attaches a network subsystem
to a network interface, prepares the network interface for operation, and
governs the transmission and reception of network frames over the network
interface. Examples of network interface types include Ethernet, Fiber
Distributed Data Interface (FDDI), and Token Ring.
Similar to the character and block device drivers that are discussed in
Writing Device Drivers, a network device driver has the following sections:
•An include files section (Section 1.1)
•A declarations section (Section 1.2)
•A configure section (Section 1.3)
•An autoconfiguration support section (Section 1.4)
•An ioctl section (Section 1.9)
•An interrupt section (Section 1.10)
Similar to a character device driver, a network device driver can also have a
reset section (Section 1.8).
Unlike a character or block device driver, a network device driver contains
the following network driver-specific sections:
•An initialization section (Section 1.5)
•A start transmit section (Section 1.6)
•A watchdog section (Section 1.7)
•An output section (Section 1.11)
Figure 1–1 shows the sections that a typical network device driver can
contain. Network device drivers are not required to have all of these
sections, and more complex network drivers can have additional sections.
However, all network drivers must have a configure section, and because
network device drivers are associated with some device, they also must have
a device register header file.
Network Device Driver Environment 1–1
Figure 1–1: Sections of a Network Device Driver
Network Device Driver
/* Include Files Section */
/* Declarations Section */
/* Configure Section */
/* Initialization Section */
/* Autoconfiguration Support Section */
/* Start Transmit Section */
/* Ioctl Section */
/* Interrupt Section */
/* Reset Section */
/* Watchdog Section */
Unlike for block and character drivers, you do not specify network driver
entry points in the dsent data structure. This means that a network
driver has no exposure into the file system and, therefore, has no entry in
the /dev directory. Thus, network drivers do not have block and character
driver-specific interfaces such as open, close, read, write, and strategy.
1–2 Network Device Driver Environment
ZK-0818U-AI
Instead of registering its entry points in a dsent data structure, a network
driver registers its entry points with the upper layers of the Tru64 UNIX
operating system in an ifnet data structure. For example, a network driver
registers entry points for queueing data for transmission and for starting
data transmission.
In addition to storing the entry points for a network driver’s associated
interfaces, the ifnet data structure stores parameter-related information
such as the transmission medium and statistics to track the performance of
the interface and network.
The ifnet data structure also contains a queue of data packets that the
network driver sends to the network device. These packets are linked lists
of mbuf data structures. Each such linked list represents one data packet.
Depending on how a network driver fills in certain members of the ifnet
data structure, the upper-level network code fragments the data to be sent
out over a network. In the case of the Ethernet network interface, the
upper-level code never hands off to the driver a single packet that exceeds
1514 bytes.
1.1 Include Files Section for a Network Driver
A network device driver includes header files that define data structures
and constant values that the driver references. A network device driver
includes some of the same files as a block or character device driver, such as
errno.h. It can also include the header files that are specific to network
device drivers. For example:
1Includes the ioctl.h include file, which defines common ioctl com-
3
4
5
6
7
mands. The ioctl.h file is located in /usr/include/sys/ioctl.h.
2Includes the sysconfig.h header file, which defines the constants that
all device drivers use during configuration. The sysconfig.h file is
located in /usr/include/sys/sysconfig.h.
3Includes the if_ether.h header file, which defines the ether_header
data structure. All network drivers typically include this file.
If you are writing the network driver for FDDI media, you also include
the header file if_fddi.h. If you are writing the network driver for
Token Ring media, you also include the header file if_trn.h.
4Includes the devdriver.h header file, which defines common device
driver data structures and constants. The devdriver.h file is located
in /usr/include/io/common/devdriver.h.
5Includes the header file eisa.h, which is associated with the ISA bus.
If you are writing the driver to operate on multiple bus architectures,
you must include the bus-specific header file. The if_el device driver
is implemented to operate on two buses: the ISA and the PCMCIA.
6Includes the header files pcmcia.h and cardinfo.h, which are
associated with the PCMCIA bus.
7Includes the lan_common.h file, which contains definitions that all
local area network (LAN) device drivers need.
8Includes the device register header file. The directory specification you
make here depends on where you put the device register header file.
1.2 Declarations Section for a Network Driver
The declarations section for a network device driver contains the following
categories of information:
1–4 Network Device Driver Environment
•External and forward declarations (Section 1.2.1)
•Declaration of softc and controller data structure arrays
(Section 1.2.2)
•Declaration of the driver data structure (Section 1.2.3)
•Definitions of driver-specific macros (Section 1.2.4)
The following sections discuss each of these categories of declarations, using
the if_el device driver as an example.
The declarations section also contains the definition of the softc data
structure and declarations for configure-related variables and data
structures. Chapter 3 discusses the definition of a network driver’s softc
data structure. Section 4.1 discusses the declarations that are related to
configuration.
1.2.1 External and Forward Declarations
The following code shows the external and forward declarations for the
if_el device driver:
int el_configure(cfg_op_t, cfg_attr_t *, size_t, cfg_attr_t *, size_t); 1
1Declares the function prototype definitions for all exported functions.
2Declares the driver interfaces for the if_el device driver.
3Declares the external timeval data structure called time. Various
ioctl commands use this data structure.
Network Device Driver Environment 1–5
4Declares a pointer to the external task_t data structure called
first_task. The task_t data structure is an opaque data structure;
that is, all of its associated members are referenced and manipulated by
the Tru64 UNIX operating system and not by the user of kernel threads.
Every kernel thread must be part of a task.
The if_el driver’s el_probe interface uses this data structure when
it creates a kernel thread.
1.2.2 Declaring softc and controller Data Structure Arrays
The following code shows the declarations for the el_softc and
controller data structure arrays. The system uses these arrays to find out
which softc and controller data structures are associated with a specific
3Com 3C5x9 device. The driver’s el_probe interface initializes these arrays
if the probe operation is successful.
The arrays of el_softc and controller data structures need to be static
for the if_el device driver. Be aware that static arrays fix the maximum
number of devices that the user can configure on the system.
static int el_isa_tag = 0; 4
static int el_isa_reset = 0; 5
decl_simple_lock_info(static, el_lock_info); 6
1Defines a constant called el_MAXDEV, which allocates data structures
that the if_el device driver needs. A maximum of seven instances of
the 3C5x9 controller can be on the system. This means that el_MAXDEV
is the maximum number of controllers that the if_el driver can
support. This is a small number of instances of the driver, and the data
structures themselves are not large, so it is acceptable to allocate for the
maximum configuration.
2Declares an array of pointers to el_softc data structures and calls it
el_softc. The el_MAXDEV constant specifies the size of this array.
3Declares an array of pointers to controller data structures and calls
it el_info. The el_MAXDEV constant specifies the size of this array.
4Declares a variable called el_isa_tag and initializes it to the value
0 (zero). The if_el driver’s el_isa_activate interface uses this
variable.
5Declares a variable called el_isa_reset and initializes it to the value
0 (zero). The if_el driver’s el_probe interface uses this variable.
6Uses the decl_simple_lock_info( ) routine to declare a simple lock
data structure called el_lock_info.
1–6 Network Device Driver Environment
1.2.3 Declaring and Initializing the driver Data Structure
The following code shows how the if_el device driver declares and
initializes the driver data structure with the names of its entry points:
1Declares and initializes the driver data structure called eldriver.
Because a network device driver does not have exposure to the file
system, it does not provide open, close, read, write, and strategy
interfaces. The members of the driver data structure that specify
these entry points are initialized to 0 (zero).
The if_el driver initializes the following members to nonzero values:
•probe, which specifies the driver’s probe interface, el_probe
•cattach, which specifies the driver’s controller attach interface,
el_attach
•ctlr_name, which specifies the controller name, el
•ctlr_list, which specifies a pointer to the array of pointers to
controller data structures, el_info
•ctlr_unattach, which specifies the driver’s controller unattach
interface, el_unattach
1.2.4 Defining Driver-Specific Macros
To help you write more portable device drivers, Tru64 UNIX provides the
following kernel routines, which allow you to read from and write to a
control status register (CSR) address without directly accessing its device
registers. These macros call the read_io_port( ) or write_io_port( )
generic routines.
Network Device Driver Environment 1–7
READ_BUS_D8
READ_BUS_D16
READ_BUS_D32
READ_BUS_D64
WRITE_BUS_D8
WRITE_BUS_D16
WRITE_BUS_D32
WRITE_BUS_D64
Reads a byte (8 bits) from a device register.
Reads a word (16 bits) from a device register.
Reads a longword (32 bits) from a device register.
Reads a quadword (64 bits) from a device register.
Writes a byte (8 bits) to a device register.
Writes a word (16 bits) to a device register.
Writes a longword (32 bits) to a device register.
Writes a quadword (64 bits) to a device register.
The following code shows how the if_el driver uses the READ_BUS_D16,
READ_BUS_D32, WRITE_BUS_D16, and WRITE_BUS_D32 kernel routines to
construct driver-specific macros to perform read and write operations on the
3Com 3C5x9 device:
1Constructs driver-specific macros to read from and write to the 3Com
3C5x9 device’s CSRs.
The first argument to these macros specifies an I/O handle that
references a device register or memory that is located in bus address
space (either I/O space or memory space). You can perform standard
C mathematical operations (addition and subtraction only) on the I/O
handle. The READ_CCR, WRITE_CCR, and the other macros construct
the first argument by referencing the I/O handle that is defined in the
el_softc data structure.
1–8 Network Device Driver Environment
The second argument to the WRITE_CCR and the other write macros
specifies the data to be written to the device register in bus address
space. These write macros construct the second argument by referencing
the val variable. For the if_el driver, this data is typically one of the
device register offsets that is defined in the if_elreg.h file.
The read and write driver-specific macros call the mb( ) kernel routine
to perform a memory barrier. The mb( ) kernel routine ensures that
the read or write operation is issued before the CPU executes any
subsequent code. See Section 7.5 of the Tru64 UNIX
Writing Device
Drivers manual for more information about the mb( ) routine and
when to use it.
Table 1–1 provides information on the driver-specific macros.
Table 1–1: Driver-Specific Macros
MacroDescription
READ_CCR and WRITE_CCR Read from and write to the 3Com 3C5x9 device’s
configuration control register.
READ_ACR and WRITE_ACR Read from and write to the 3Com 3C5x9 device’s
address control register.
WRITE_RCR
WRITE_ECR
READ_EDR
WRITE_CMD
READ_STS
READ_DATA and
WRITE_DATA
READ_ND and WRITE_NDRead from and write to the 3Com 3C5x9 device’s
READ_MD and WRITE_MDRead from and write to the 3Com 3C5x9 device’s media
READ_TXF and READ_RXFRead from the 3Com 3C5x9 device’s transmit and
WRITE_AD1, WRITE_AD2,
and WRITE_AD3
READ_TXS and WRITE_TXS Read from and write to the 3Com 3C5x9 device’s
Write to the 3Com 3C5x9 device’s resource
configuration register.
Write to the 3Com 3C5x9 device’s EEPROM command
register.
Read from the 3Com 3C5x9 device’s EEPROM data
register.
Write to the 3Com 3C5x9 device’s command port
registers.
Read from the 3Com 3C5x9 device’s I/O status register.
Read from and write to the 3Com 3C5x9 device’s
receive data and transmit data registers.
network diagnostic register.
type and status register.
receive FIFO registers.
Set the LAN physical address for the 3Com 3C5x9
device.
transmit status register.
Network Device Driver Environment 1–9
Table 1–1: Driver-Specific Macros (cont.)
MacroDescription
READ_RXS
READ_FDP
Read from the 3Com 3C5x9 device’s receive status
register.
Read from the 3Com 3C5x9 device’s FIFO diagnostic
port register.
1.3 Configure Section for a Network Driver
The configure section for a network device driver contains a configure
interface. The cfgmgr framework calls the driver’s configure interface
at system startup to handle static configuration requests. The cfgmgr
framework can also call the driver’s configure interface to handle
user-level requests to dynamically configure, unconfigure, query, and
reconfigure a device driver at run time. If you implement the driver as a
single binary module, the configure interface can handle both static and
dynamic configuration.
1.4 Autoconfiguration Support Section for a Network Driver
The autoconfiguration support section for a network device driver contains
the following entry points:
•A probe interface, which determines if the network device exists and is
functional on the system
•An attach interface, which establishes communication with the device
and initializes the driver’s ifnet data structure.
You define the entry point for each of these interfaces in the driver data
structure.
1.5 Initialization Section for a Network Driver
The initialization section for a network device driver prepares the network
to transmit and receive data packets.
1.6 Start Section for a Network Driver
The start section for a network device driver contains a start interface,
which transmits data packets on the network interface. You define the
entry point for the start interface in the ifnet data structure. However,
before this interface can be called, the network adapter must be enabled for
data packet transmission and reception. You enable the network adapter
by invoking the SIOCSIFADDR ioctl command.
1–10 Network Device Driver Environment
1.7 Watchdog Section for a Network Driver
The watchdog section for a network device driver contains a watchdog
interface, which attempts to restart the adapter. The watchdog interface is
optional in a network device driver. If the network device driver implements
it, watchdog is called by a kernel thread if the driver’s interrupt handler has
not shut down the countdown timer within a certain number of seconds of
queueing a data packet for transmission from the upper layer. This indicates
that the adapter is no longer on line.
1.8 Reset Section for a Network Driver
The reset section for a network device driver contains a reset interface.
The reset interface resets the LAN adapter. This interface is called to
restart the device following a network failure. This interface resets all of the
counters and local variables. It can also free up and reallocate all of the
buffers that the network driver uses.
1.9 ioctl Section for a Network Driver
The ioctl section for network device drivers performs miscellaneous tasks
that have nothing to do with data packet transmission and reception.
Typically, these tasks relate to turning specific features of the hardware
on or off.
The ioctl section contains an ioctl interface. You define this entry point in
the ifnet data structure.
1.10 Interrupt Section for a Network Driver
The interrupt section for a network device driver contains an interrupt
handler. The interrupt handler processes network device interrupts. You
define the entry point for the interrupt handler by calling the handler
interfaces. The interrupt handler is called each time that the network
interface receives an interrupt. After identifying which type of interrupt was
received — transmit or receive — the interrupt handler calls the appropriate
routine to process the interrupt.
1.11 Output Section for a Network Driver
The output section for a network device driver formats a data packet for
transmission on the network. The ether_output( ) routine formats
data packets for Tru64 UNIX network drivers. Despite its name,
ether_output( ) handles the frame formats for Ethernet, token ring, and
FDDI. After it has properly formatted the data packet, ether_output( )
enqueues the packet on the driver’s send queue and calls the driver’s start
Network Device Driver Environment 1–11
interface to transmit the data. All network drivers must set the output
member of the ifnet data structure to ether_output.
1–12 Network Device Driver Environment
Loading...
+ 129 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.