iPXE
nic.h
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of the
5 * License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18FILE_LICENCE ( GPL2_OR_LATER );
19
20#ifndef NIC_H
21#define NIC_H
22
23#include <stdint.h>
24#include <string.h>
25#include <stdio.h>
26#include <byteswap.h>
27#include <ipxe/pci.h>
28#include <ipxe/isapnp.h>
29#include <ipxe/isa.h>
30#include <ipxe/eisa.h>
31#include <ipxe/mca.h>
32#include <ipxe/io.h>
33
34typedef enum {
39
44
45/*
46 * Structure returned from eth_probe and passed to other driver
47 * functions.
48 */
49struct nic {
51 int flags; /* driver specific flags */
52 unsigned char *node_addr;
53 unsigned char *packet;
54 unsigned int packetlen;
55 unsigned int ioaddr;
56 unsigned char irqno;
57 unsigned int mbps;
59 void *priv_data; /* driver private data */
60 void *fake_bss;
62};
63
64#define NIC_FAKE_BSS_PTR( type ) ( ( type * ) legacy_nic.fake_bss )
65#define NIC_FAKE_BSS( type ) ( * NIC_FAKE_BSS_PTR ( type ) )
66extern struct {} no_fake_bss;
67
69 int ( *connect ) ( struct nic * );
70 int ( *poll ) ( struct nic *, int retrieve );
71 void ( *transmit ) ( struct nic *, const char *,
72 unsigned int, unsigned int, const char * );
73 void ( *irq ) ( struct nic *, irq_action_t );
74};
75
76extern struct nic legacy_nic;
77
78static inline int eth_poll ( int retrieve ) {
79 struct nic *nic = &legacy_nic;
80 return nic->nic_op->poll ( nic, retrieve );
81}
82
83static inline void eth_transmit ( const char *dest, unsigned int type,
84 unsigned int size, const void *packet ) {
85 struct nic *nic = &legacy_nic;
87}
88
89/*
90 * Function prototypes
91 *
92 */
93extern int dummy_connect ( struct nic *nic );
94extern void dummy_irq ( struct nic *nic, irq_action_t irq_action );
95extern int legacy_probe ( void *hwdev,
96 void ( * set_drvdata ) ( void *hwdev, void *priv ),
97 struct device *dev,
98 int ( * probe ) ( struct nic *nic, void *hwdev ),
99 void ( * disable ) ( struct nic *nic, void *hwdev ),
100 size_t fake_bss_len );
101void legacy_remove ( void *hwdev,
102 void * ( * get_drvdata ) ( void *hwdev ),
103 void ( * disable ) ( struct nic *nic, void *hwdev ) );
104
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 );
117
118static inline void legacy_pci_set_drvdata ( void *hwdev, void *priv ) {
119 pci_set_drvdata ( hwdev, priv );
120}
121static inline void * legacy_pci_get_drvdata ( void *hwdev ) {
122 return pci_get_drvdata ( hwdev );
123}
124
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 );
138
139static inline void legacy_isapnp_set_drvdata ( void *hwdev, void *priv ) {
140 isapnp_set_drvdata ( hwdev, priv );
141}
142static inline void * legacy_isapnp_get_drvdata ( void *hwdev ) {
143 return isapnp_get_drvdata ( hwdev );
144}
145
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 );
159
160static inline void legacy_eisa_set_drvdata ( void *hwdev, void *priv ) {
161 eisa_set_drvdata ( hwdev, priv );
162}
163static inline void * legacy_eisa_get_drvdata ( void *hwdev ) {
164 return eisa_get_drvdata ( hwdev );
165}
166
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 );
180
181static inline void legacy_mca_set_drvdata ( void *hwdev, void *priv ) {
182 mca_set_drvdata ( hwdev, priv );
183}
184static inline void * legacy_mca_get_drvdata ( void *hwdev ) {
185 return mca_get_drvdata ( hwdev );
186}
187
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 );
211
212static inline void legacy_isa_set_drvdata ( void *hwdev, void *priv ) {
213 isa_set_drvdata ( hwdev, priv );
214}
215static inline void * legacy_isa_get_drvdata ( void *hwdev ) {
216 return isa_get_drvdata ( hwdev );
217}
218
219#undef DRIVER
220#define DRIVER( _name_text, _unused2, _unused3, _name, _probe, _disable, \
221 _fake_bss ) \
222 static __attribute__ (( unused )) const char \
223 _name ## _text[] = _name_text; \
224 static inline int \
225 _name ## _probe ( struct nic *nic, void *hwdev ) { \
226 return _probe ( nic, hwdev ); \
227 } \
228 static inline void \
229 _name ## _disable ( struct nic *nic, void *hwdev ) { \
230 _disable ( nic, hwdev ); \
231 } \
232 static inline int \
233 _name ## _pci_legacy_probe ( struct pci_device *pci ) { \
234 return legacy_probe ( pci, legacy_pci_set_drvdata, \
235 &pci->dev, _name ## _probe, \
236 _name ## _disable, \
237 sizeof ( _fake_bss ) ); \
238 } \
239 static inline void \
240 _name ## _pci_legacy_remove ( struct pci_device *pci ) { \
241 return legacy_remove ( pci, legacy_pci_get_drvdata, \
242 _name ## _disable ); \
243 } \
244 static inline int \
245 _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
246 const struct isapnp_device_id *id __unused ) { \
247 return legacy_probe ( isapnp, legacy_isapnp_set_drvdata, \
248 &isapnp->dev, _name ## _probe, \
249 _name ## _disable, \
250 sizeof ( _fake_bss ) ); \
251 } \
252 static inline void \
253 _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ) { \
254 return legacy_remove ( isapnp, legacy_isapnp_get_drvdata, \
255 _name ## _disable ); \
256 } \
257 static inline int \
258 _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
259 const struct eisa_device_id *id __unused ) { \
260 return legacy_probe ( eisa, legacy_eisa_set_drvdata, \
261 &eisa->dev, _name ## _probe, \
262 _name ## _disable, \
263 sizeof ( _fake_bss ) ); \
264 } \
265 static inline void \
266 _name ## _eisa_legacy_remove ( struct eisa_device *eisa ) { \
267 return legacy_remove ( eisa, legacy_eisa_get_drvdata, \
268 _name ## _disable ); \
269 } \
270 static inline int \
271 _name ## _mca_legacy_probe ( struct mca_device *mca, \
272 const struct mca_device_id *id __unused ) { \
273 return legacy_probe ( mca, legacy_mca_set_drvdata, \
274 &mca->dev, _name ## _probe, \
275 _name ## _disable, \
276 sizeof ( _fake_bss ) ); \
277 } \
278 static inline void \
279 _name ## _mca_legacy_remove ( struct mca_device *mca ) { \
280 return legacy_remove ( mca, legacy_mca_get_drvdata, \
281 _name ## _disable ); \
282 } \
283 static inline int \
284 _name ## _isa_legacy_probe ( struct isa_device *isa ) { \
285 return legacy_probe ( isa, legacy_isa_set_drvdata, \
286 &isa->dev, _name ## _probe, \
287 _name ## _disable, \
288 sizeof ( _fake_bss ) ); \
289 } \
290 static inline void \
291 _name ## _isa_legacy_remove ( struct isa_device *isa ) { \
292 return legacy_remove ( isa, legacy_isa_get_drvdata, \
293 _name ## _disable ); \
294 } \
295 PROVIDE_REQUIRING_SYMBOL()
296
297#endif /* NIC_H */
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
#define HALF_DUPLEX
Definition atl1e.h:53
#define FULL_DUPLEX
Definition atl1e.h:54
static void eisa_set_drvdata(struct eisa_device *eisa, void *priv)
Set EISA driver-private data.
Definition eisa.h:114
static void * eisa_get_drvdata(struct eisa_device *eisa)
Get EISA driver-private data.
Definition eisa.h:124
uint32_t type
Operating system type.
Definition ena.h:1
uint16_t size
Buffer size.
Definition dwmac.h:3
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
iPXE I/O API
static void isa_set_drvdata(struct isa_device *isa, void *priv)
Set ISA driver-private data.
Definition isa.h:73
static void * isa_get_drvdata(struct isa_device *isa)
Get ISA driver-private data.
Definition isa.h:83
String functions.
static void * isapnp_get_drvdata(struct isapnp_device *isapnp)
Get ISAPnP driver-private data.
Definition isapnp.h:267
static void isapnp_set_drvdata(struct isapnp_device *isapnp, void *priv)
Set ISAPnP driver-private data.
Definition isapnp.h:256
struct nic legacy_nic
Definition legacy.c:22
static void mca_set_drvdata(struct mca_device *mca, void *priv)
Set MCA driver-private data.
Definition mca.h:92
static void * mca_get_drvdata(struct mca_device *mca)
Get MCA driver-private data.
Definition mca.h:102
static void legacy_mca_set_drvdata(void *hwdev, void *priv)
Definition nic.h:181
static void * legacy_eisa_get_drvdata(void *hwdev)
Definition nic.h:163
int dummy_connect(struct nic *nic)
duplex
Definition nic.h:40
static void * legacy_isa_get_drvdata(void *hwdev)
Definition nic.h:215
static void legacy_pci_set_drvdata(void *hwdev, void *priv)
Definition nic.h:118
irq_action_t
Definition nic.h:34
@ FORCE
Definition nic.h:37
@ ENABLE
Definition nic.h:36
@ DISABLE
Definition nic.h:35
static void legacy_isapnp_set_drvdata(void *hwdev, void *priv)
Definition nic.h:139
static void legacy_eisa_set_drvdata(void *hwdev, void *priv)
Definition nic.h:160
static void legacy_isa_set_drvdata(void *hwdev, void *priv)
Definition nic.h:212
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 legacy.c:83
static int eth_poll(int retrieve)
Definition nic.h:78
static void * legacy_isapnp_get_drvdata(void *hwdev)
Definition nic.h:142
void dummy_irq(struct nic *nic, irq_action_t irq_action)
static void eth_transmit(const char *dest, unsigned int type, unsigned int size, const void *packet)
Definition nic.h:83
static void * legacy_pci_get_drvdata(void *hwdev)
Definition nic.h:121
struct @002057171240057303273132130141036221271355330106 no_fake_bss
static void * legacy_mca_get_drvdata(void *hwdev)
Definition nic.h:184
void legacy_remove(void *hwdev, void *(*get_drvdata)(void *hwdev), void(*disable)(struct nic *nic, void *hwdev))
Definition legacy.c:160
enum duplex duplex_t
PCI bus.
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:366
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:376
A hardware device.
Definition device.h:77
void(* transmit)(struct nic *, const char *, unsigned int, unsigned int, const char *)
Definition nic.h:71
void(* irq)(struct nic *, irq_action_t)
Definition nic.h:73
int(* connect)(struct nic *)
Definition nic.h:69
int(* poll)(struct nic *, int retrieve)
Definition nic.h:70
Definition nic.h:49
int flags
Definition nic.h:51
duplex_t duplex
Definition nic.h:58
void * fake_bss
Definition nic.h:60
unsigned char * packet
Definition nic.h:53
unsigned int mbps
Definition nic.h:57
void * priv_data
Definition nic.h:59
unsigned char * node_addr
Definition nic.h:52
unsigned int packetlen
Definition nic.h:54
unsigned char irqno
Definition nic.h:56
size_t fake_bss_len
Definition nic.h:61
unsigned int ioaddr
Definition nic.h:55
struct nic_operations * nic_op
Definition nic.h:50
static struct tlan_private * priv
Definition tlan.c:225