iPXE
Functions | Variables
legacy.c File Reference
#include <stdint.h>
#include <stdio.h>
#include <errno.h>
#include <ipxe/if_ether.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/iobuf.h>
#include <nic.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int legacy_transmit (struct net_device *netdev, struct io_buffer *iobuf)
static void legacy_poll (struct net_device *netdev)
static int legacy_open (struct net_device *netdev __unused)
static void legacy_close (struct net_device *netdev __unused)
static void legacy_irq (struct net_device *netdev __unused, int enable)
int legacy_probe (void *hwdev, void(*set_drvdata)(void *hwdev, void *priv), struct device *dev, int(*probe)(struct nic *nic, void *hwdev), void(*disable)(struct nic *nic, void *hwdev))
void legacy_remove (void *hwdev, void *(*get_drvdata)(void *hwdev), void(*disable)(struct nic *nic, void *hwdev))
int dummy_connect (struct nic *nic __unused)
void dummy_irq (struct nic *nic __unused, irq_action_t irq_action __unused)

Variables

struct nic nic
static int legacy_registered = 0
static struct net_device_operations legacy_operations

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int legacy_transmit ( struct net_device netdev,
struct io_buffer iobuf 
) [static]

Definition at line 26 of file legacy.c.

References io_buffer::data, DBG, ETH_ZLEN, ethhdr::h_dest, ethhdr::h_protocol, iob_len(), iob_pad(), iob_pull, netdev_tx_complete(), nic, ntohs, and net_device::priv.

                                                                                  {
        struct nic *nic = netdev->priv;
        struct ethhdr *ethhdr;

        DBG ( "Transmitting %zd bytes\n", iob_len ( iobuf ) );
        iob_pad ( iobuf, ETH_ZLEN );
        ethhdr = iobuf->data;
        iob_pull ( iobuf, sizeof ( *ethhdr ) );
        nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
                                ntohs ( ethhdr->h_protocol ),
                                iob_len ( iobuf ), iobuf->data );
        netdev_tx_complete ( netdev, iobuf );
        return 0;
}
static void legacy_poll ( struct net_device netdev) [static]

Definition at line 41 of file legacy.c.

References alloc_iob(), io_buffer::data, DBG, ETH_FRAME_LEN, free_iob(), iob_put, netdev_rx(), nic, and net_device::priv.

                                                      {
        struct nic *nic = netdev->priv;
        struct io_buffer *iobuf;

        iobuf = alloc_iob ( ETH_FRAME_LEN );
        if ( ! iobuf )
                return;

        nic->packet = iobuf->data;
        if ( nic->nic_op->poll ( nic, 1 ) ) {
                DBG ( "Received %d bytes\n", nic->packetlen );
                iob_put ( iobuf, nic->packetlen );
                netdev_rx ( netdev, iobuf );
        } else {
                free_iob ( iobuf );
        }
}
static int legacy_open ( struct net_device *netdev  __unused) [static]

Definition at line 59 of file legacy.c.

                                                              {
        /* Nothing to do */
        return 0;
}
static void legacy_close ( struct net_device *netdev  __unused) [static]

Definition at line 64 of file legacy.c.

                                                                {
        /* Nothing to do */
}
static void legacy_irq ( struct net_device *netdev  __unused,
int  enable 
) [static]

Definition at line 68 of file legacy.c.

References netdev, nic, and net_device::priv.

                                                                          {
        struct nic *nic = netdev->priv;

        nic->nic_op->irq ( nic, ( enable ? ENABLE : DISABLE ) );
}
int legacy_probe ( void *  hwdev,
void(*)(void *hwdev, void *priv set_drvdata,
struct device dev,
int(*)(struct nic *nic, void *hwdev)  probe,
void(*)(struct nic *nic, void *hwdev)  disable 
)

Definition at line 82 of file legacy.c.

References alloc_etherdev(), device::desc, net_device::dev, EBUSY, ENODEV, ENOMEM, net_device::hw_addr, device_description::irq, legacy_registered, net_device::ll_protocol, memset(), netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), nic, ll_protocol::ntoa, printf(), net_device::priv, rc, and register_netdev().

Referenced by t509_probe().

                                                                         {
        struct net_device *netdev;
        int rc;

        if ( legacy_registered )
                return -EBUSY;
        
        netdev = alloc_etherdev ( 0 );
        if ( ! netdev )
                return -ENOMEM;
        netdev_init ( netdev, &legacy_operations );
        netdev->priv = &nic;
        memset ( &nic, 0, sizeof ( nic ) );
        set_drvdata ( hwdev, netdev );
        netdev->dev = dev;

        nic.node_addr = netdev->hw_addr;
        nic.irqno = dev->desc.irq;

        if ( ! probe ( &nic, hwdev ) ) {
                rc = -ENODEV;
                goto err_probe;
        }

        /* Overwrite the IRQ number.  Some legacy devices set
         * nic->irqno to 0 in the probe routine to indicate that they
         * don't support interrupts; doing this allows the timer
         * interrupt to be used instead.
         */
        dev->desc.irq = nic.irqno;

        if ( ( rc = register_netdev ( netdev ) ) != 0 )
                goto err_register;

        /* Mark as link up; legacy devices don't handle link state */
        netdev_link_up ( netdev );

        /* Do not remove this message */
        printf ( "WARNING: Using legacy NIC wrapper on %s\n",
                 netdev->ll_protocol->ntoa ( nic.node_addr ) );

        legacy_registered = 1;
        return 0;

 err_register:
        disable ( &nic, hwdev );
 err_probe:
        netdev_nullify ( netdev );
        netdev_put ( netdev );
        return rc;
}
void legacy_remove ( void *  hwdev,
void *(*)(void *hwdev)  get_drvdata,
void(*)(struct nic *nic, void *hwdev)  disable 
)

Definition at line 138 of file legacy.c.

References legacy_registered, netdev, netdev_nullify(), netdev_put(), net_device::priv, and unregister_netdev().

Referenced by t509_remove().

                                                                           {
        struct net_device *netdev = get_drvdata ( hwdev );
        struct nic *nic = netdev->priv;

        unregister_netdev ( netdev );
        disable ( nic, hwdev );
        netdev_nullify ( netdev );
        netdev_put ( netdev );
        legacy_registered = 0;
}
int dummy_connect ( struct nic *nic  __unused)

Definition at line 151 of file legacy.c.

                                               {
        return 1;
}
void dummy_irq ( struct nic *nic  __unused,
irq_action_t irq_action  __unused 
)

Definition at line 155 of file legacy.c.

                                                                              {
        return;
}

Variable Documentation

struct nic nic
int legacy_registered = 0 [static]

Definition at line 24 of file legacy.c.

Referenced by legacy_probe(), and legacy_remove().

Initial value:
 {
        .open           = legacy_open,
        .close          = legacy_close,
        .transmit       = legacy_transmit,
        .poll           = legacy_poll,
        .irq            = legacy_irq,
}

Definition at line 74 of file legacy.c.