legacy.c File Reference

#include <stdint.h>
#include <stdio.h>
#include <errno.h>
#include <gpxe/if_ether.h>
#include <gpxe/netdevice.h>
#include <gpxe/ethernet.h>
#include <gpxe/iobuf.h>
#include <nic.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
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   ) 

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::nic_op, ntohs, net_device::priv, and nic_operations::transmit.

00026                                                                                   {
00027         struct nic *nic = netdev->priv;
00028         struct ethhdr *ethhdr;
00029 
00030         DBG ( "Transmitting %zd bytes\n", iob_len ( iobuf ) );
00031         iob_pad ( iobuf, ETH_ZLEN );
00032         ethhdr = iobuf->data;
00033         iob_pull ( iobuf, sizeof ( *ethhdr ) );
00034         nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
00035                                 ntohs ( ethhdr->h_protocol ),
00036                                 iob_len ( iobuf ), iobuf->data );
00037         netdev_tx_complete ( netdev, iobuf );
00038         return 0;
00039 }

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::nic_op, nic::packet, nic::packetlen, nic_operations::poll, and net_device::priv.

00041                                                       {
00042         struct nic *nic = netdev->priv;
00043         struct io_buffer *iobuf;
00044 
00045         iobuf = alloc_iob ( ETH_FRAME_LEN );
00046         if ( ! iobuf )
00047                 return;
00048 
00049         nic->packet = iobuf->data;
00050         if ( nic->nic_op->poll ( nic, 1 ) ) {
00051                 DBG ( "Received %d bytes\n", nic->packetlen );
00052                 iob_put ( iobuf, nic->packetlen );
00053                 netdev_rx ( netdev, iobuf );
00054         } else {
00055                 free_iob ( iobuf );
00056         }
00057 }

static int legacy_open ( struct net_device *netdev  __unused  )  [static]

Definition at line 59 of file legacy.c.

00059                                                               {
00060         /* Nothing to do */
00061         return 0;
00062 }

static void legacy_close ( struct net_device *netdev  __unused  )  [static]

Definition at line 64 of file legacy.c.

00064                                                                 {
00065         /* Nothing to do */
00066 }

static void legacy_irq ( struct net_device *netdev  __unused,
int  enable 
) [static]

Definition at line 68 of file legacy.c.

References DISABLE, ENABLE, nic_operations::irq, netdev, nic::nic_op, and net_device::priv.

00068                                                                           {
00069         struct nic *nic = netdev->priv;
00070 
00071         nic->nic_op->irq ( nic, ( enable ? ENABLE : DISABLE ) );
00072 }

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, nic::irqno, legacy_registered, net_device::ll_protocol, memset(), netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), nic::node_addr, ll_protocol::ntoa, printf(), net_device::priv, and register_netdev().

Referenced by t509_probe().

00086                                                                          {
00087         struct net_device *netdev;
00088         int rc;
00089 
00090         if ( legacy_registered )
00091                 return -EBUSY;
00092         
00093         netdev = alloc_etherdev ( 0 );
00094         if ( ! netdev )
00095                 return -ENOMEM;
00096         netdev_init ( netdev, &legacy_operations );
00097         netdev->priv = &nic;
00098         memset ( &nic, 0, sizeof ( nic ) );
00099         set_drvdata ( hwdev, netdev );
00100         netdev->dev = dev;
00101 
00102         nic.node_addr = netdev->hw_addr;
00103         nic.irqno = dev->desc.irq;
00104 
00105         if ( ! probe ( &nic, hwdev ) ) {
00106                 rc = -ENODEV;
00107                 goto err_probe;
00108         }
00109 
00110         /* Overwrite the IRQ number.  Some legacy devices set
00111          * nic->irqno to 0 in the probe routine to indicate that they
00112          * don't support interrupts; doing this allows the timer
00113          * interrupt to be used instead.
00114          */
00115         dev->desc.irq = nic.irqno;
00116 
00117         /* Mark as link up; legacy devices don't handle link state */
00118         netdev_link_up ( netdev );
00119 
00120         if ( ( rc = register_netdev ( netdev ) ) != 0 )
00121                 goto err_register;
00122 
00123         /* Do not remove this message */
00124         printf ( "WARNING: Using legacy NIC wrapper on %s\n",
00125                  netdev->ll_protocol->ntoa ( nic.node_addr ) );
00126 
00127         legacy_registered = 1;
00128         return 0;
00129 
00130  err_register:
00131         disable ( &nic, hwdev );
00132  err_probe:
00133         netdev_nullify ( netdev );
00134         netdev_put ( netdev );
00135         return rc;
00136 }

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().

00140                                                                            {
00141         struct net_device *netdev = get_drvdata ( hwdev );
00142         struct nic *nic = netdev->priv;
00143 
00144         unregister_netdev ( netdev );
00145         disable ( nic, hwdev );
00146         netdev_nullify ( netdev );
00147         netdev_put ( netdev );
00148         legacy_registered = 0;
00149 }

int dummy_connect ( struct nic *nic  __unused  ) 

Definition at line 151 of file legacy.c.

00151                                                {
00152         return 1;
00153 }

void dummy_irq ( struct nic *nic  __unused,
irq_action_t irq_action  __unused 
)

Definition at line 155 of file legacy.c.

00155                                                                               {
00156         return;
00157 }


Variable Documentation

struct nic nic

Definition at line 22 of file legacy.c.

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.


Generated on Tue Apr 6 20:01:36 2010 for gPXE by  doxygen 1.5.7.1