iPXE
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), size_t fake_bss_len)
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 legacy_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()

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,
36 iob_len ( iobuf ), iobuf->data );
37 netdev_tx_complete ( netdev, iobuf );
38 return 0;
39}
static struct net_device * netdev
Definition gdbudp.c:53
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define ETH_ZLEN
Definition if_ether.h:11
#define ntohs(value)
Definition byteswap.h:137
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
Definition iobpad.c:50
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
#define iob_pull(iobuf, len)
Definition iobuf.h:107
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition netdevice.h:767
An Ethernet link-layer header.
Definition if_ether.h:32
uint16_t h_protocol
Protocol ID.
Definition if_ether.h:38
uint8_t h_dest[ETH_ALEN]
Destination MAC address.
Definition if_ether.h:34
void * data
Start of data.
Definition iobuf.h:53
void(* transmit)(struct nic *, const char *, unsigned int, unsigned int, const char *)
Definition nic.h:71
Definition nic.h:49
struct nic_operations * nic_op
Definition nic.h:50

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, and nic_operations::transmit.

◆ legacy_poll()

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 + 4 /* possible VLAN */
46 + 4 /* possible CRC */ );
47 if ( ! iobuf )
48 return;
49
50 nic->packet = iobuf->data;
51 if ( nic->nic_op->poll ( nic, 1 ) ) {
52 DBG ( "Received %d bytes\n", nic->packetlen );
53 iob_put ( iobuf, nic->packetlen );
54 netdev_rx ( netdev, iobuf );
55 } else {
56 free_iob ( iobuf );
57 }
58}
#define ETH_FRAME_LEN
Definition if_ether.h:12
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition iobuf.c:131
#define iob_put(iobuf, len)
Definition iobuf.h:125
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
A persistent I/O buffer.
Definition iobuf.h:38
int(* poll)(struct nic *, int retrieve)
Definition nic.h:70
unsigned char * packet
Definition nic.h:53
unsigned int packetlen
Definition nic.h:54

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

◆ legacy_open()

int legacy_open ( struct net_device *netdev __unused)
static

Definition at line 60 of file legacy.c.

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

References __unused, and netdev.

◆ legacy_close()

void legacy_close ( struct net_device *netdev __unused)
static

Definition at line 65 of file legacy.c.

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

References __unused, and netdev.

◆ legacy_irq()

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

Definition at line 69 of file legacy.c.

69 {
70 struct nic *nic = netdev->priv;
71
72 nic->nic_op->irq ( nic, ( enable ? ENABLE : DISABLE ) );
73}
@ ENABLE
Definition nic.h:36
@ DISABLE
Definition nic.h:35
void(* irq)(struct nic *, irq_action_t)
Definition nic.h:73

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

◆ legacy_probe()

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),
size_t fake_bss_len )

Definition at line 83 of file legacy.c.

88 {
89 struct net_device *netdev;
90 struct nic *nic;
91 int rc;
92
93 if ( legacy_registered ) {
94 rc = -EBUSY;
95 goto err_registered;
96 }
97
98 netdev = alloc_etherdev ( 0 );
99 if ( ! netdev ) {
100 rc = -ENOMEM;
101 goto err_alloc;
102 }
104 nic = &legacy_nic;
105 netdev->priv = nic;
106 memset ( nic, 0, sizeof ( *nic ) );
107 set_drvdata ( hwdev, netdev );
108 netdev->dev = dev;
109
110 nic->node_addr = netdev->hw_addr;
111 nic->irqno = dev->desc.irq;
112
113 if ( fake_bss_len ) {
115 if ( ! nic->fake_bss ) {
116 rc = -ENOMEM;
117 goto err_fake_bss;
118 }
119 }
121
122 if ( ! probe ( nic, hwdev ) ) {
123 rc = -ENODEV;
124 goto err_probe;
125 }
126
127 /* Overwrite the IRQ number. Some legacy devices set
128 * nic->irqno to 0 in the probe routine to indicate that they
129 * don't support interrupts; doing this allows the timer
130 * interrupt to be used instead.
131 */
132 dev->desc.irq = nic->irqno;
133
134 if ( ( rc = register_netdev ( netdev ) ) != 0 )
135 goto err_register;
136
137 /* Mark as link up; legacy devices don't handle link state */
139
140 /* Do not remove this message */
141 printf ( "WARNING: Using legacy NIC wrapper on %s\n",
142 netdev->ll_protocol->ntoa ( nic->node_addr ) );
143
145 return 0;
146
147 err_register:
148 disable ( nic, hwdev );
149 err_probe:
150 if ( fake_bss_len )
152 err_fake_bss:
154 netdev_put ( netdev );
155 err_alloc:
156 err_registered:
157 return rc;
158}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
#define ENOMEM
Not enough space.
Definition errno.h:535
#define EBUSY
Device or resource busy.
Definition errno.h:339
#define ENODEV
No such device.
Definition errno.h:510
#define PAGE_SIZE
Page size.
Definition io.h:28
void * memset(void *dest, int character, size_t len) __nonnull
struct nic legacy_nic
Definition legacy.c:22
static struct net_device_operations legacy_operations
Definition legacy.c:75
static int legacy_registered
Definition legacy.c:24
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition malloc.c:707
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition malloc.c:723
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:789
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
unsigned int irq
IRQ.
Definition device.h:40
struct device_description desc
Device description.
Definition device.h:83
A network device.
Definition netdevice.h:353
void * fake_bss
Definition nic.h:60
unsigned char * node_addr
Definition nic.h:52
unsigned char irqno
Definition nic.h:56
size_t fake_bss_len
Definition nic.h:61
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References alloc_etherdev(), device::desc, EBUSY, ENODEV, ENOMEM, nic::fake_bss, nic::fake_bss_len, free_phys(), device_description::irq, nic::irqno, legacy_nic, legacy_operations, legacy_registered, malloc_phys(), memset(), netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), nic::node_addr, PAGE_SIZE, printf(), priv, rc, and register_netdev().

Referenced by t509_probe().

◆ legacy_remove()

void legacy_remove ( void * hwdev,
void *(* get_drvdata )(void *hwdev),
void(* disable )(struct nic *nic, void *hwdev) )

Definition at line 160 of file legacy.c.

162 {
163 struct net_device *netdev = get_drvdata ( hwdev );
164 struct nic *nic = netdev->priv;
165
167 disable ( nic, hwdev );
168 if ( nic->fake_bss_len )
171 netdev_put ( netdev );
173}
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942

References nic::fake_bss, nic::fake_bss_len, free_phys(), legacy_registered, netdev, netdev_nullify(), netdev_put(), and unregister_netdev().

Referenced by t509_remove().

◆ dummy_connect()

int dummy_connect ( struct nic *nic __unused)

Definition at line 175 of file legacy.c.

175 {
176 return 1;
177}

References __unused.

◆ dummy_irq()

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

Definition at line 179 of file legacy.c.

179 {
180 return;
181}

References __unused.

Variable Documentation

◆ legacy_nic

struct nic legacy_nic

Definition at line 22 of file legacy.c.

Referenced by eth_poll(), eth_transmit(), 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_open(struct net_device *netdev __unused)
Definition legacy.c:60
static void legacy_irq(struct net_device *netdev __unused, int enable)
Definition legacy.c:69
static void legacy_close(struct net_device *netdev __unused)
Definition legacy.c:65
static int legacy_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Definition legacy.c:26
static void legacy_poll(struct net_device *netdev)
Definition legacy.c:41

Definition at line 75 of file legacy.c.

75 {
76 .open = legacy_open,
77 .close = legacy_close,
78 .transmit = legacy_transmit,
79 .poll = legacy_poll,
80 .irq = legacy_irq,
81};

Referenced by legacy_probe().