Table of Contents

gPXE Network Driver API Documentation

net_device::open ( struct net_device *netdev )

Here MAC address is programmed over the device (NIC). Then receive buffer for the device is created and its memory is released in net_device::close(). This address for the ring buffer is transfer to the NIC’s register. This is the place where configuration of the device is also done like enable transmission, receive. Other parameters like burst rate, transfer threshold, reception of broadcast and multicast is also set here.

net_device::close ( struct net_device *netdev )

The crucial task here is to reset the device (may use a command available with the hardware), to free the memory allocated for the Receive ring buffer in net_device:open() and to stop any pending transmission.

net_device::transmit ( struct net_device *netdev, struct io_buffer *iobuf )

Initiate transmission of the packet, i.e. add packet to the card's TX queue. Don't wait for transmission to complete; the completion will be picked up by a later call to net_device::poll(). Takes ownership of the I/O buffer; the buffer will be freed when the TX completion occurs.

Some cards have alignment or padding requirements; iob_pad() can generally be used to satisfy these.

net_device::poll ( struct net_device *netdev, unsigned int rx_quota )

The poll function is called periodically to check for any received packets and also to check that packets which were marked for transmission have been transmitted successfully or not. In some NIC’s like rtl8139, whenever a data is successfully transmitted Transmit OK bit is set in the Interrupt Status Register. And if ISR is enabled it will be called. However in our case as we are using polling so one needs to reset it every time, before we can again start transmitting. When a packet is successfully transmitted, it is removed from the Transmission queue here in poll (). Remember to use netdev_tx_complete to free the transmit iobuf In each call to poll(), receive buffer is checked. If it is non empty then memory is allocated for the length of received packet and is copied from the received buffer of driver to network device’s receive queue. Here one is not concerned with releasing the memory allocated to received packet.

net_device::probe ( struct pci_device *pci, const struct pci_device_id *id )

Here actual device probe is not done. It is done by pci::pci_probe(), which looks for the correct driver for this device found. If found, then net_device::probe() of that driver is called. In this probe one needs to ensure that NIC if has busmaster mode capability then it should be enabled, if by any chance BIOS was not able to do it. pci::adjust_pci_device() can do this work. Other work to be done here includes allocating memory for net_device. Information required from PCI configuration block like I/O address (ioaddr) and device information (dev) are copied from pci_device to net_device object. Once all allocation is done, the device is reset and EEPROM is initialized and MAC address is read from the EEPROM.

Function alias are created (open,close,transmit,poll) to NIC specific routines. Lastly we need to register Network device and non-volatile storage (EEPROM) which can be done using register_netdev and nvo_register.