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

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ legacy_transmit()

static int legacy_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Definition at line 26 of file legacy.c.

26  {
27  struct nic *nic = netdev->priv;
28  struct ethhdr *ethhdr;
29 
30  DBG ( "Transmitting %zd bytes\n", iob_len ( iobuf ) );
31  iob_pad ( iobuf, ETH_ZLEN );
32  ethhdr = iobuf->data;
33  iob_pull ( iobuf, sizeof ( *ethhdr ) );
34  nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
35  ntohs ( ethhdr->h_protocol ),
36  iob_len ( iobuf ), iobuf->data );
37  netdev_tx_complete ( netdev, iobuf );
38  return 0;
39 }
uint16_t h_protocol
Protocol ID.
Definition: if_ether.h:37
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:752
#define ntohs(value)
Definition: byteswap.h:136
void(* transmit)(struct nic *, const char *, unsigned int, unsigned int, const char *)
Definition: nic.h:65
uint8_t h_dest[ETH_ALEN]
Destination MAC address.
Definition: if_ether.h:33
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
#define ETH_ZLEN
Definition: if_ether.h:10
Definition: nic.h:49
void * data
Start of data.
Definition: iobuf.h:48
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
struct nic_operations * nic_op
Definition: nic.h:50
An Ethernet link-layer header.
Definition: if_ether.h:31
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
Definition: iobpad.c:49

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

◆ legacy_poll()

static void legacy_poll ( struct net_device netdev)
static

Definition at line 41 of file legacy.c.

41  {
42  struct nic *nic = netdev->priv;
43  struct io_buffer *iobuf;
44 
45  iobuf = alloc_iob ( ETH_FRAME_LEN );
46  if ( ! iobuf )
47  return;
48 
49  nic->packet = iobuf->data;
50  if ( nic->nic_op->poll ( nic, 1 ) ) {
51  DBG ( "Received %d bytes\n", nic->packetlen );
52  iob_put ( iobuf, nic->packetlen );
53  netdev_rx ( netdev, iobuf );
54  } else {
55  free_iob ( iobuf );
56  }
57 }
int(* poll)(struct nic *, int retrieve)
Definition: nic.h:64
#define iob_put(iobuf, len)
Definition: iobuf.h:120
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
#define ETH_FRAME_LEN
Definition: if_ether.h:11
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned int packetlen
Definition: nic.h:54
Definition: nic.h:49
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
unsigned char * packet
Definition: nic.h:53
void * data
Start of data.
Definition: iobuf.h:48
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
struct nic_operations * nic_op
Definition: nic.h:50
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), io_buffer::data, DBG, ETH_FRAME_LEN, free_iob(), iob_put, netdev, netdev_rx(), nic::nic_op, nic::packet, nic::packetlen, nic_operations::poll, and net_device::priv.

◆ legacy_open()

static int legacy_open ( struct net_device *netdev  __unused)
static

Definition at line 59 of file legacy.c.

59  {
60  /* Nothing to do */
61  return 0;
62 }

◆ legacy_close()

static void legacy_close ( struct net_device *netdev  __unused)
static

Definition at line 64 of file legacy.c.

64  {
65  /* Nothing to do */
66 }

◆ legacy_irq()

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

Definition at line 68 of file legacy.c.

68  {
69  struct nic *nic = netdev->priv;
70 
71  nic->nic_op->irq ( nic, ( enable ? ENABLE : DISABLE ) );
72 }
Definition: nic.h:35
void(* irq)(struct nic *, irq_action_t)
Definition: nic.h:67
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
Definition: nic.h:49
Definition: nic.h:36
struct nic_operations * nic_op
Definition: nic.h:50

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

◆ legacy_probe()

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.

86  {
87  struct net_device *netdev;
88  int rc;
89 
90  if ( legacy_registered )
91  return -EBUSY;
92 
93  netdev = alloc_etherdev ( 0 );
94  if ( ! netdev )
95  return -ENOMEM;
97  netdev->priv = &nic;
98  memset ( &nic, 0, sizeof ( nic ) );
99  set_drvdata ( hwdev, netdev );
100  netdev->dev = dev;
101 
103  nic.irqno = dev->desc.irq;
104 
105  if ( ! probe ( &nic, hwdev ) ) {
106  rc = -ENODEV;
107  goto err_probe;
108  }
109 
110  /* Overwrite the IRQ number. Some legacy devices set
111  * nic->irqno to 0 in the probe routine to indicate that they
112  * don't support interrupts; doing this allows the timer
113  * interrupt to be used instead.
114  */
115  dev->desc.irq = nic.irqno;
116 
117  if ( ( rc = register_netdev ( netdev ) ) != 0 )
118  goto err_register;
119 
120  /* Mark as link up; legacy devices don't handle link state */
122 
123  /* Do not remove this message */
124  printf ( "WARNING: Using legacy NIC wrapper on %s\n",
126 
127  legacy_registered = 1;
128  return 0;
129 
130  err_register:
131  disable ( &nic, hwdev );
132  err_probe:
134  netdev_put ( netdev );
135  return rc;
136 }
unsigned char irqno
Definition: nic.h:56
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define EBUSY
Device or resource busy.
Definition: errno.h:338
static struct net_device_operations legacy_operations
Definition: legacy.c:74
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
unsigned int irq
IRQ.
Definition: device.h:39
void * priv
Driver private data.
Definition: netdevice.h:431
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:774
static struct net_device * netdev
Definition: gdbudp.c:52
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
Definition: nic.h:49
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
unsigned char * node_addr
Definition: nic.h:52
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
struct device_description desc
Device description.
Definition: device.h:79
const char *(* ntoa)(const void *ll_addr)
Transcribe link-layer address.
Definition: netdevice.h:163
struct nic nic
Definition: legacy.c:22
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
static int legacy_registered
Definition: legacy.c:24
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
void * memset(void *dest, int character, size_t len) __nonnull

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

Referenced by t509_probe().

◆ legacy_remove()

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.

140  {
141  struct net_device *netdev = get_drvdata ( hwdev );
142  struct nic *nic = netdev->priv;
143 
145  disable ( nic, hwdev );
147  netdev_put ( netdev );
148  legacy_registered = 0;
149 }
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
Definition: nic.h:49
static int legacy_registered
Definition: legacy.c:24

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

Referenced by t509_remove().

◆ dummy_connect()

int dummy_connect ( struct nic *nic  __unused)

Definition at line 151 of file legacy.c.

151  {
152  return 1;
153 }

◆ dummy_irq()

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

Definition at line 155 of file legacy.c.

155  {
156  return;
157 }

Variable Documentation

◆ nic

struct nic nic

Definition at line 22 of file legacy.c.

Referenced by amd8111e_probe(), bnx2_init_board(), ibft_install(), and legacy_probe().

◆ legacy_registered

int legacy_registered = 0
static

Definition at line 24 of file legacy.c.

Referenced by legacy_probe(), and legacy_remove().

◆ legacy_operations

struct net_device_operations legacy_operations
static
Initial value:
= {
.open = legacy_open,
.close = legacy_close,
.transmit = legacy_transmit,
.poll = legacy_poll,
.irq = legacy_irq,
}
static int legacy_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Definition: legacy.c:26
static void legacy_close(struct net_device *netdev __unused)
Definition: legacy.c:64
static void legacy_irq(struct net_device *netdev __unused, int enable)
Definition: legacy.c:68
static void legacy_poll(struct net_device *netdev)
Definition: legacy.c:41
static int legacy_open(struct net_device *netdev __unused)
Definition: legacy.c:59

Definition at line 74 of file legacy.c.

Referenced by legacy_probe().