BSP and Device Driver Development Guide
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
arpcom
structure.
ifp->if_name
name
entry in the configuration structure.
ifp->if_unit
ifp->if_name
is `scc
' and ifp->if_unit
is `1
',
the full device name would be `scc1
'. The unit number should be
obtained from the `name' entry in the configuration structure.
ifp->if_mtu
ifp->if_flags
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
ifqmaxlen
.
ifp->if_init
ifp->if_start
ifp->if_ioctl
ifp->if_output
ether_output
.
RTEMS provides a function to parse the driver name in the configuration structure into a device name and unit number.
int rtems_bsdnet_parse_driver_name ( const struct rtems_bsdnet_ifconfig *config, char **namep );
The function takes two arguments; a pointer to the configuration structure and a pointer to a pointer to a character. The function parses the configuration name entry, allocates memory for the driver name, places the driver name in this memory, sets the second argument to point to the name and returns the unit number. On error, a message is printed and -1 is returned.
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.
BSP and Device Driver Development Guide
Copyright © 1988-2000 OAR Corporation