OAR

RTEMS 4.0.0 On-Line Library


Write your driver attach function

PREV UP NEXT Bookshelf RTEMS Network Supplement

2.4: Write your driver attach function

The driver attach function is responsible for configuring the driver and making the connection between the network stack and the driver.

Driver attach functions take a pointer to an rtems_bsdnet_ifconfig structure as their only argument. and set the driver parameters based on the values in this structure. If an entry in the configuration structure is zero the attach function chooses an appropriate default value for that parameter.

The driver should then set up several fields in the ifnet structure in the device-dependent data structure supplied and maintained by the driver:

ifp->if_softc
Pointer to the device-dependent data. The first entry in the device-dependent data structure must be an arpcom structure.
ifp->if_name
The name of the device. The network stack uses this string and the device number for device name lookups. The name should not contain digits as these will be assumed to be part of the unit number and not part of the device name.
ifp->if_unit
The device number. The network stack uses this number and the device name for device name lookups. For example, if ifp->if_name is `scc', and ifp->if_unit is `1', the full device name would be `scc1'.
ifp->if_mtu
The maximum transmission unit for the device. For Ethernet devices this value should almost always be 1500.
ifp->if_flags
The device flags. Ethernet devices should set the flags to IFF_BROADCAST|IFF_SIMPLEX, indicating that the device can broadcast packets to multiple destinations and does not receive and transmit at the same time.
ifp->if_snd.ifq_maxlen
The maximum length of the queue of packets waiting to be sent to the driver. This is normally set to ifqmaxlen.
ifp->if_init
The address of the driver initialization function.
ifp->if_start
The address of the driver start function.
ifp->if_ioctl
The address of the driver ioctl function.
ifp->if_output
The address of the output function. Ethernet devices should set this to ether_output.

Once the attach function has set up the above entries it must link the driver data structure onto the list of devices by calling if_attach. Ethernet devices should then call ether_ifattach. Both functions take a pointer to the device's ifnet structure as their only argument.

The attach function should return a non-zero value to indicate that the driver has been successfully configured and attached.


PREV UP NEXT Bookshelf RTEMS Network Supplement

Copyright © 1988-1998 OAR Corporation