network driver info
The
HyperNews
Linux KHG
Discussion Pages
network driver infoForum: Device DriversRe:
Re: Network Device Drivers (Paul Gortmaker)Re:
Re: Network Device Drivers (Neal Tucker)Keywords: network driver functionsDate: Sat, 15 Jun 1996 03:33:21 GMTFrom: Neal Tucker <ntucker@adobe.com>Earlier, I posted a pointer to a bit of info on network
device drivers, and the site that the web page is on is
going away, so I am including what was there here...
How a Network Device Gets Added to the Kernel
There is a global variable called dev_base which points to a
linked list of "device" structures. Each record represents a network
device, and contains a pointer to the device driver's initialization
function. The initialization function is the first code from the driver
to ever get executed, and is responsible for setting up the hooks to the
other driver code.At boot time, the function device_setup (drivers/block/genhd.c)
calls a function called net_dev_init (net/core/dev.c) which walks through
the linked list pointed to by dev_base, calling each device's init function.
If the init indicates failure (by returning a nonzero result),
net_dev_init removes the device from the linked list and continues
on.This brings up the question of how the devices get added to the linked
list of devices before any of their code is executed. That is accomplished
by a clever piece of C preprocessor work in drivers/net/Space.c. This file
has the static declarations for each device's "device" struct, including
the pointer to the next device in the list. How can we define these links
statically without knowing which devices are going to be included? Here's
how it's done (from drivers/net/Space.c):
#define NEXT_DEV NULL
#if defined(CONFIG_SLIP)
static struct device slip_dev =
{
device name and some other info goes here
...
NEXT_DEV, /* base_addr;
if ((base_addr == 0xffe0) || (base_addr == 1))
return 1;
if (1 /* note start of expression here */
#ifdef CONFIG_DGRS
&& dgrs_probe(dev)
#endif
#ifdef CONFIG_VORTEX
&& tc59x_probe(dev)
#endif
#ifdef CONFIG_NE2000
&& ne_probe(dev)
#endif
&& 1 ) { /* end of expression here */
return 1;
}
return 0;
}
The result is that the if statement bails out as false if any of
the probe calls returns zero (success), and only one ethernet
card is initialized and used, no matter how many drivers you have
installed. For the drivers that aren't installed, the #ifdef
removes the code completely, and the expression gets a bit smaller.
The implications of this scheme are that supporting multiple ethernet
cards is now a special case, and requires providing command line
parameters to the kernel which cause ethif_probe to be
executed multiple times.
Messages
Inline:
Outline:
1.
Network Driver Desprately Needed by Paul Atkinsonto: "network driver info"