RTEMS Logo

RTEMS 4.8.0 On-Line Library


Networking Driver Write the Driver Attach Function

PREV UP NEXT Bookshelf BSP and Device Driver Development Guide

15.5: Write the 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 device name should be obtained from the name entry in the configuration structure.
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'. The unit number should be obtained from the `name' entry in the configuration structure.
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.

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.


PREV UP NEXT Bookshelf BSP and Device Driver Development Guide

Copyright © 1988-2007OAR Corporation