iPXE
nic.h File Reference
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <byteswap.h>
#include <ipxe/pci.h>
#include <ipxe/isapnp.h>
#include <ipxe/isa.h>
#include <ipxe/eisa.h>
#include <ipxe/mca.h>
#include <ipxe/io.h>

Go to the source code of this file.

Data Structures

struct  nic
struct  nic_operations

Macros

#define NIC_H
#define NIC_FAKE_BSS_PTR(type)
#define NIC_FAKE_BSS(type)
#define PCI_DRIVER(_name, _ids, _class)
#define ISAPNP_DRIVER(_name, _ids)
#define EISA_DRIVER(_name, _ids)
#define MCA_DRIVER(_name, _ids)
#define ISA_DRIVER(_name, _probe_addrs, _probe_addr, _vendor_id, _prod_id)
#define DRIVER(_name_text, _unused2, _unused3, _name, _probe, _disable, _fake_bss)

Typedefs

typedef enum duplex duplex_t

Enumerations

enum  irq_action_t { DISABLE = 0 , ENABLE , FORCE }
enum  duplex { HALF_DUPLEX = 1 , FULL_DUPLEX }

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static int eth_poll (int retrieve)
static void eth_transmit (const char *dest, unsigned int type, unsigned int size, const void *packet)
int dummy_connect (struct nic *nic)
void dummy_irq (struct nic *nic, irq_action_t irq_action)
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))
static void legacy_pci_set_drvdata (void *hwdev, void *priv)
static void * legacy_pci_get_drvdata (void *hwdev)
static void legacy_isapnp_set_drvdata (void *hwdev, void *priv)
static void * legacy_isapnp_get_drvdata (void *hwdev)
static void legacy_eisa_set_drvdata (void *hwdev, void *priv)
static void * legacy_eisa_get_drvdata (void *hwdev)
static void legacy_mca_set_drvdata (void *hwdev, void *priv)
static void * legacy_mca_get_drvdata (void *hwdev)
static void legacy_isa_set_drvdata (void *hwdev, void *priv)
static void * legacy_isa_get_drvdata (void *hwdev)

Variables

struct { 
no_fake_bss
struct nic legacy_nic

Macro Definition Documentation

◆ NIC_H

#define NIC_H

Definition at line 21 of file nic.h.

◆ NIC_FAKE_BSS_PTR

#define NIC_FAKE_BSS_PTR ( type)
Value:
( ( type * ) legacy_nic.fake_bss )
uint32_t type
Operating system type.
Definition ena.h:1
struct nic legacy_nic
Definition legacy.c:22

Definition at line 64 of file nic.h.

◆ NIC_FAKE_BSS

#define NIC_FAKE_BSS ( type)
Value:
#define NIC_FAKE_BSS_PTR(type)
Definition nic.h:64

Definition at line 65 of file nic.h.

◆ PCI_DRIVER

#define PCI_DRIVER ( _name,
_ids,
_class )
Value:
static inline int \
_name ## _pci_legacy_probe ( struct pci_device *pci ); \
static inline void \
_name ## _pci_legacy_remove ( struct pci_device *pci ); \
struct pci_driver _name __pci_driver = { \
.ids = _ids, \
.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
.probe = _name ## _pci_legacy_probe, \
.remove = _name ## _pci_legacy_remove, \
}; \
REQUIRE_OBJECT ( pci );
#define __pci_driver
Declare a PCI driver.
Definition pci.h:278
A PCI device.
Definition pci.h:211
A PCI driver.
Definition pci.h:252

Definition at line 105 of file nic.h.

105#define PCI_DRIVER(_name,_ids,_class) \
106 static inline int \
107 _name ## _pci_legacy_probe ( struct pci_device *pci ); \
108 static inline void \
109 _name ## _pci_legacy_remove ( struct pci_device *pci ); \
110 struct pci_driver _name __pci_driver = { \
111 .ids = _ids, \
112 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
113 .probe = _name ## _pci_legacy_probe, \
114 .remove = _name ## _pci_legacy_remove, \
115 }; \
116 REQUIRE_OBJECT ( pci );

◆ ISAPNP_DRIVER

#define ISAPNP_DRIVER ( _name,
_ids )
Value:
static inline int \
_name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
const struct isapnp_device_id *id ); \
static inline void \
_name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ); \
struct isapnp_driver _name __isapnp_driver = { \
.ids = _ids, \
.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
.probe = _name ## _isapnp_legacy_probe, \
.remove = _name ## _isapnp_legacy_remove, \
}; \
REQUIRE_OBJECT ( isapnp );
#define __isapnp_driver
Declare an ISAPnP driver.
Definition isapnp.h:225
An ISAPnP device ID list entry.
Definition isapnp.h:163
An ISAPnP device.
Definition isapnp.h:173
An ISAPnP driver.
Definition isapnp.h:199

Definition at line 125 of file nic.h.

125#define ISAPNP_DRIVER(_name,_ids) \
126 static inline int \
127 _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
128 const struct isapnp_device_id *id ); \
129 static inline void \
130 _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ); \
131 struct isapnp_driver _name __isapnp_driver = { \
132 .ids = _ids, \
133 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
134 .probe = _name ## _isapnp_legacy_probe, \
135 .remove = _name ## _isapnp_legacy_remove, \
136 }; \
137 REQUIRE_OBJECT ( isapnp );

◆ EISA_DRIVER

#define EISA_DRIVER ( _name,
_ids )
Value:
static inline int \
_name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
const struct eisa_device_id *id ); \
static inline void \
_name ## _eisa_legacy_remove ( struct eisa_device *eisa ); \
struct eisa_driver _name __eisa_driver = { \
.ids = _ids, \
.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
.probe = _name ## _eisa_legacy_probe, \
.remove = _name ## _eisa_legacy_remove, \
}; \
REQUIRE_OBJECT ( eisa );
#define __eisa_driver
Declare an EISA driver.
Definition eisa.h:86
An EISA device ID list entry.
Definition eisa.h:28
An EISA device.
Definition eisa.h:38
An EISA driver.
Definition eisa.h:60

Definition at line 146 of file nic.h.

146#define EISA_DRIVER(_name,_ids) \
147 static inline int \
148 _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
149 const struct eisa_device_id *id ); \
150 static inline void \
151 _name ## _eisa_legacy_remove ( struct eisa_device *eisa ); \
152 struct eisa_driver _name __eisa_driver = { \
153 .ids = _ids, \
154 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
155 .probe = _name ## _eisa_legacy_probe, \
156 .remove = _name ## _eisa_legacy_remove, \
157 }; \
158 REQUIRE_OBJECT ( eisa );

◆ MCA_DRIVER

#define MCA_DRIVER ( _name,
_ids )
Value:
static inline int \
_name ## _mca_legacy_probe ( struct mca_device *mca, \
const struct mca_device_id *id ); \
static inline void \
_name ## _mca_legacy_remove ( struct mca_device *mca ); \
struct mca_driver _name __mca_driver = { \
.ids = _ids, \
.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
.probe = _name ## _mca_legacy_probe, \
.remove = _name ## _mca_legacy_remove, \
}; \
REQUIRE_OBJECT ( mca );
#define __mca_driver
Declare an MCA driver.
Definition mca.h:84
An MCA device ID list entry.
Definition mca.h:30
An MCA device.
Definition mca.h:38
An MCA driver.
Definition mca.h:58

Definition at line 167 of file nic.h.

167#define MCA_DRIVER(_name,_ids) \
168 static inline int \
169 _name ## _mca_legacy_probe ( struct mca_device *mca, \
170 const struct mca_device_id *id ); \
171 static inline void \
172 _name ## _mca_legacy_remove ( struct mca_device *mca ); \
173 struct mca_driver _name __mca_driver = { \
174 .ids = _ids, \
175 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
176 .probe = _name ## _mca_legacy_probe, \
177 .remove = _name ## _mca_legacy_remove, \
178 }; \
179 REQUIRE_OBJECT ( mca );

◆ ISA_DRIVER

#define ISA_DRIVER ( _name,
_probe_addrs,
_probe_addr,
_vendor_id,
_prod_id )
Value:
static inline int \
_name ## _isa_legacy_probe ( struct isa_device *isa ); \
static inline int \
_name ## _isa_legacy_probe_at_addr ( struct isa_device *isa ) { \
if ( ! _probe_addr ( isa->ioaddr ) ) \
return -ENODEV; \
return _name ## _isa_legacy_probe ( isa ); \
} \
static inline void \
_name ## _isa_legacy_remove ( struct isa_device *isa ); \
static const char _name ## _text[]; \
struct isa_driver _name __isa_driver = { \
.name = _name ## _text, \
.probe_addrs = _probe_addrs, \
.addr_count = ( sizeof ( _probe_addrs ) / \
sizeof ( _probe_addrs[0] ) ), \
.vendor_id = _vendor_id, \
.prod_id = _prod_id, \
.probe = _name ## _isa_legacy_probe_at_addr, \
.remove = _name ## _isa_legacy_remove, \
}; \
REQUIRE_OBJECT ( isa );
#define ENODEV
No such device.
Definition errno.h:510
uint8_t vendor_id[3]
Definition ib_mad.h:11
#define __isa_driver
Declare an ISA driver.
Definition isa.h:65
An ISA device.
Definition isa.h:12
uint16_t ioaddr
I/O address.
Definition isa.h:16
An ISA driver.
Definition isa.h:34
static struct xen_remove_from_physmap * remove
Definition xenmem.h:40

Definition at line 188 of file nic.h.

188#define ISA_DRIVER(_name,_probe_addrs,_probe_addr,_vendor_id,_prod_id) \
189 static inline int \
190 _name ## _isa_legacy_probe ( struct isa_device *isa ); \
191 static inline int \
192 _name ## _isa_legacy_probe_at_addr ( struct isa_device *isa ) { \
193 if ( ! _probe_addr ( isa->ioaddr ) ) \
194 return -ENODEV; \
195 return _name ## _isa_legacy_probe ( isa ); \
196 } \
197 static inline void \
198 _name ## _isa_legacy_remove ( struct isa_device *isa ); \
199 static const char _name ## _text[]; \
200 struct isa_driver _name __isa_driver = { \
201 .name = _name ## _text, \
202 .probe_addrs = _probe_addrs, \
203 .addr_count = ( sizeof ( _probe_addrs ) / \
204 sizeof ( _probe_addrs[0] ) ), \
205 .vendor_id = _vendor_id, \
206 .prod_id = _prod_id, \
207 .probe = _name ## _isa_legacy_probe_at_addr, \
208 .remove = _name ## _isa_legacy_remove, \
209 }; \
210 REQUIRE_OBJECT ( isa );

◆ DRIVER

#define DRIVER ( _name_text,
_unused2,
_unused3,
_name,
_probe,
_disable,
_fake_bss )

Definition at line 220 of file nic.h.

Typedef Documentation

◆ duplex_t

typedef enum duplex duplex_t

Enumeration Type Documentation

◆ irq_action_t

Enumerator
DISABLE 
ENABLE 
FORCE 

Definition at line 34 of file nic.h.

34 {
35 DISABLE = 0,
36 ENABLE,
37 FORCE
irq_action_t
Definition nic.h:34
@ FORCE
Definition nic.h:37
@ ENABLE
Definition nic.h:36
@ DISABLE
Definition nic.h:35

◆ duplex

enum duplex
Enumerator
HALF_DUPLEX 
FULL_DUPLEX 

Definition at line 40 of file nic.h.

40 {
41 HALF_DUPLEX = 1,
43} duplex_t;
#define HALF_DUPLEX
Definition atl1e.h:53
#define FULL_DUPLEX
Definition atl1e.h:54
enum duplex duplex_t

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ eth_poll()

int eth_poll ( int retrieve)
inlinestatic

Definition at line 78 of file nic.h.

78 {
79 struct nic *nic = &legacy_nic;
80 return nic->nic_op->poll ( nic, retrieve );
81}
int(* poll)(struct nic *, int retrieve)
Definition nic.h:70
Definition nic.h:49
struct nic_operations * nic_op
Definition nic.h:50

References legacy_nic, nic::nic_op, and nic_operations::poll.

◆ eth_transmit()

void eth_transmit ( const char * dest,
unsigned int type,
unsigned int size,
const void * packet )
inlinestatic

Definition at line 83 of file nic.h.

84 {
85 struct nic *nic = &legacy_nic;
87}
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
uint16_t size
Buffer size.
Definition dwmac.h:3
void(* transmit)(struct nic *, const char *, unsigned int, unsigned int, const char *)
Definition nic.h:71
unsigned char * packet
Definition nic.h:53

References dest, legacy_nic, nic::nic_op, nic::packet, size, nic_operations::transmit, and type.

◆ dummy_connect()

int dummy_connect ( struct nic * nic)
extern

◆ dummy_irq()

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

References priv.

◆ 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 )
extern

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
static struct net_device * netdev
Definition gdbudp.c:53
#define ENOMEM
Not enough space.
Definition errno.h:535
#define EBUSY
Device or resource busy.
Definition errno.h:339
#define PAGE_SIZE
Page size.
Definition io.h:28
void * memset(void *dest, int character, size_t len) __nonnull
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().

◆ legacy_pci_set_drvdata()

void legacy_pci_set_drvdata ( void * hwdev,
void * priv )
inlinestatic

Definition at line 118 of file nic.h.

118 {
119 pci_set_drvdata ( hwdev, priv );
120}
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:366
static struct tlan_private * priv
Definition tlan.c:225

References pci_set_drvdata(), and priv.

◆ legacy_pci_get_drvdata()

void * legacy_pci_get_drvdata ( void * hwdev)
inlinestatic

Definition at line 121 of file nic.h.

121 {
122 return pci_get_drvdata ( hwdev );
123}
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:376

References pci_get_drvdata().

◆ legacy_isapnp_set_drvdata()

void legacy_isapnp_set_drvdata ( void * hwdev,
void * priv )
inlinestatic

Definition at line 139 of file nic.h.

139 {
140 isapnp_set_drvdata ( hwdev, priv );
141}
static void isapnp_set_drvdata(struct isapnp_device *isapnp, void *priv)
Set ISAPnP driver-private data.
Definition isapnp.h:256

References isapnp_set_drvdata(), and priv.

◆ legacy_isapnp_get_drvdata()

void * legacy_isapnp_get_drvdata ( void * hwdev)
inlinestatic

Definition at line 142 of file nic.h.

142 {
143 return isapnp_get_drvdata ( hwdev );
144}
static void * isapnp_get_drvdata(struct isapnp_device *isapnp)
Get ISAPnP driver-private data.
Definition isapnp.h:267

References isapnp_get_drvdata().

◆ legacy_eisa_set_drvdata()

void legacy_eisa_set_drvdata ( void * hwdev,
void * priv )
inlinestatic

Definition at line 160 of file nic.h.

160 {
161 eisa_set_drvdata ( hwdev, priv );
162}
static void eisa_set_drvdata(struct eisa_device *eisa, void *priv)
Set EISA driver-private data.
Definition eisa.h:114

References eisa_set_drvdata(), and priv.

◆ legacy_eisa_get_drvdata()

void * legacy_eisa_get_drvdata ( void * hwdev)
inlinestatic

Definition at line 163 of file nic.h.

163 {
164 return eisa_get_drvdata ( hwdev );
165}
static void * eisa_get_drvdata(struct eisa_device *eisa)
Get EISA driver-private data.
Definition eisa.h:124

References eisa_get_drvdata().

◆ legacy_mca_set_drvdata()

void legacy_mca_set_drvdata ( void * hwdev,
void * priv )
inlinestatic

Definition at line 181 of file nic.h.

181 {
182 mca_set_drvdata ( hwdev, priv );
183}
static void mca_set_drvdata(struct mca_device *mca, void *priv)
Set MCA driver-private data.
Definition mca.h:92

References mca_set_drvdata(), and priv.

◆ legacy_mca_get_drvdata()

void * legacy_mca_get_drvdata ( void * hwdev)
inlinestatic

Definition at line 184 of file nic.h.

184 {
185 return mca_get_drvdata ( hwdev );
186}
static void * mca_get_drvdata(struct mca_device *mca)
Get MCA driver-private data.
Definition mca.h:102

References mca_get_drvdata().

◆ legacy_isa_set_drvdata()

void legacy_isa_set_drvdata ( void * hwdev,
void * priv )
inlinestatic

Definition at line 212 of file nic.h.

212 {
213 isa_set_drvdata ( hwdev, priv );
214}
static void isa_set_drvdata(struct isa_device *isa, void *priv)
Set ISA driver-private data.
Definition isa.h:73

References isa_set_drvdata(), and priv.

◆ legacy_isa_get_drvdata()

void * legacy_isa_get_drvdata ( void * hwdev)
inlinestatic

Definition at line 215 of file nic.h.

215 {
216 return isa_get_drvdata ( hwdev );
217}
static void * isa_get_drvdata(struct isa_device *isa)
Get ISA driver-private data.
Definition isa.h:83

References isa_get_drvdata().

Variable Documentation

◆ [struct]

struct { ... } no_fake_bss

◆ legacy_nic

struct nic legacy_nic
extern

Definition at line 22 of file legacy.c.

Referenced by eth_poll(), eth_transmit(), and legacy_probe().