Allocating The Ether_Driver Data Structure - Compaq Tru64 UNIX Installation Manual

Writing network device drivers
Table of Contents

Advertisement

if (el_softc[unit]) {
sc = el_softc[unit];
sc->cardout = 0;
sc->reprobe = 1;
} else {
2
MALLOC(sc, void*, sizeof(struct el_softc), M_DEVBUF, M_WAIT | M_ZERO);
if (!sc) {
printf("el%d: el_probe: failed to get buffer memory for softc\n",
return(0);
}
If the user removed and returned the PCMCIA card to its slot:
1
Locates the existing el_softc data structure for this device. The
controller number (which is stored in the unit variable) is used as
an index into the array of el_softc data structures to determine
which el_softc data structure is associated with this 3Com 3C5x9
device.
Sets the cardout member of the el_softc data structure to the
value 0 (zero) to indicate that the PCMCIA card is not currently
removed from its slot.
Sets the reprobe member of the el_softc data structure to the
value 1 to indicate that the PCMCIA card was reinserted into its slot.
If this is an ISA device or if the user did not remove and replace the
2
card, calls the MALLOC macro to allocate memory for the el_softc
data structure.
If MALLOC could not allocate the memory, calls the printf( ) routine to
3
display an appropriate message on the console terminal. The printf( )
routine also displays the controller number for the device.
Returns the value 0 (zero) to the bus configuration code to indicate
4
that the probe operation failed.

5.1.5 Allocating the ether_driver Data Structure

The following code shows how the el_probe( ) routine calls if_alloc( )
to allocate the ether_driver data structure for this device. if_alloc( )
returns an ether_driver data structure, which contains the ifnet data
structure, and initializes the if_name, if_unit, and if_index fields.
Make sure that your driver allocates its ether_driver data structure in
the same way.
sc->is_ed = if_alloc("el", unit, sizeof(struct ether_driver));
CLEAR_LAN_COUNTERS(sc->is_ed);
Calls a routine that returns an ether_driver data structure and
1
initializes the ifnet portion of it.
1
3
unit);
4
2
Implementing the Autoconfiguration Support Section (probe) 5–7
1

Advertisement

Table of Contents
loading

Table of Contents