1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/mii.h>
#include "skeleton.h"
/** @file
*
* Skeleton network driver
*
*/
/******************************************************************************
*
* MII interface
*
******************************************************************************
*/
/**
* Read from MII register
*
* @v mii MII interface
* @v reg Register address
* @ret value Data read, or negative error
*/
static int skeleton_mii_read ( struct mii_interface *mii, unsigned int reg ) {
struct skeleton_nic *skel =
container_of ( mii, struct skeleton_nic, mii );
DBGC ( skel, "SKELETON %p does not yet support MII read\n", skel );
( void ) reg;
return -ENOTSUP;
}
/**
* Write to MII register
*
* @v mii MII interface
* @v reg Register address
* @v data Data to write
* @ret rc Return status code
*/
static int skeleton_mii_write ( struct mii_interface *mii, unsigned int reg,
unsigned int data) {
struct skeleton_nic *skel =
container_of ( mii, struct skeleton_nic, mii );
DBGC ( skel, "SKELETON %p does not yet support MII write\n", skel );
( void ) reg;
( void ) data;
return -ENOTSUP;
}
/** Skeleton MII operations */
static struct mii_operations skeleton_mii_operations = {
.read = skeleton_mii_read,
.write = skeleton_mii_write,
};
/******************************************************************************
*
* Device reset
*
******************************************************************************
*/
/**
* Reset hardware
*
* @v skel Skeleton device
* @ret rc Return status code
*/
static int skeleton_reset ( struct skeleton_nic *skel ) {
DBGC ( skel, "SKELETON %p does not yet support reset\n", skel );
return -ENOTSUP;
}
/******************************************************************************
*
* Link state
*
******************************************************************************
*/
/**
* Check link state
*
* @v netdev Network device
*/
static void skeleton_check_link ( struct net_device *netdev ) {
struct skeleton_nic *skel = netdev->priv;
DBGC ( skel, "SKELETON %p does not yet support link state\n", skel );
netdev_link_err ( netdev, -ENOTSUP );
}
/******************************************************************************
*
* Network device interface
*
******************************************************************************
*/
/**
* Open network device
*
* @v netdev Network device
* @ret rc Return status code
*/
static int skeleton_open ( struct net_device *netdev ) {
struct skeleton_nic *skel = netdev->priv;
DBGC ( skel, "SKELETON %p does not yet support open\n", skel );
return -ENOTSUP;
}
/**
* Close network device
*
* @v netdev Network device
*/
static void skeleton_close ( struct net_device *netdev ) {
struct skeleton_nic *skel = netdev->priv;
DBGC ( skel, "SKELETON %p does not yet support close\n", skel );
}
/**
* Transmit packet
*
* @v netdev Network device
* @v iobuf I/O buffer
* @ret rc Return status code
*/
static int skeleton_transmit ( struct net_device *netdev,
struct io_buffer *iobuf ) {
struct skeleton_nic *skel = netdev->priv;
DBGC ( skel, "SKELETON %p does not yet support transmit\n", skel );
( void ) iobuf;
return -ENOTSUP;
}
/**
* Poll for completed and received packets
*
* @v netdev Network device
*/
static void skeleton_poll ( struct net_device *netdev ) {
struct skeleton_nic *skel = netdev->priv;
/* Not yet implemented */
( void ) skel;
}
/**
* Enable or disable interrupts
*
* @v netdev Network device
* @v enable Interrupts should be enabled
*/
static void skeleton_irq ( struct net_device *netdev, int enable ) {
struct skeleton_nic *skel = netdev->priv;
DBGC ( skel, "SKELETON %p does not yet support interrupts\n", skel );
( void ) enable;
}
/** Skeleton network device operations */
static struct net_device_operations skeleton_operations = {
.open = skeleton_open,
.close = skeleton_close,
.transmit = skeleton_transmit,
.poll = skeleton_poll,
.irq = skeleton_irq,
};
/******************************************************************************
*
* PCI interface
*
******************************************************************************
*/
/**
* Probe PCI device
*
* @v pci PCI device
* @ret rc Return status code
*/
static int skeleton_probe ( struct pci_device *pci ) {
struct net_device *netdev;
struct skeleton_nic *skel;
int rc;
/* Allocate and initialise net device */
netdev = alloc_etherdev ( sizeof ( *skel ) );
if ( ! netdev ) {
rc = -ENOMEM;
goto err_alloc;
}
netdev_init ( netdev, &skeleton_operations );
skel = netdev->priv;
pci_set_drvdata ( pci, netdev );
netdev->dev = &pci->dev;
memset ( skel, 0, sizeof ( *skel ) );
/* Fix up PCI device */
adjust_pci_device ( pci );
/* Map registers */
skel->regs = ioremap ( pci->membase, SKELETON_BAR_SIZE );
if ( ! skel->regs ) {
rc = -ENODEV;
goto err_ioremap;
}
/* Reset the NIC */
if ( ( rc = skeleton_reset ( skel ) ) != 0 )
goto err_reset;
/* Initialise and reset MII interface */
mii_init ( &skel->mii, &skeleton_mii_operations );
if ( ( rc = mii_reset ( &skel->mii ) ) != 0 ) {
DBGC ( skel, "SKELETON %p could not reset MII: %s\n",
skel, strerror ( rc ) );
goto err_mii_reset;
}
/* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 )
goto err_register_netdev;
/* Set initial link state */
skeleton_check_link ( netdev );
return 0;
unregister_netdev ( netdev );
err_register_netdev:
err_mii_reset:
skeleton_reset ( skel );
err_reset:
iounmap ( skel->regs );
err_ioremap:
netdev_nullify ( netdev );
netdev_put ( netdev );
err_alloc:
return rc;
}
/**
* Remove PCI device
*
* @v pci PCI device
*/
static void skeleton_remove ( struct pci_device *pci ) {
struct net_device *netdev = pci_get_drvdata ( pci );
struct skeleton_nic *skel = netdev->priv;
/* Unregister network device */
unregister_netdev ( netdev );
/* Reset card */
skeleton_reset ( skel );
/* Free network device */
iounmap ( skel->regs );
netdev_nullify ( netdev );
netdev_put ( netdev );
}
/** Skeleton PCI device IDs */
static struct pci_device_id skeleton_nics[] = {
PCI_ROM ( 0x5ce1, 0x5ce1, "skel", "Skeleton", 0 ),
};
/** Skeleton PCI driver */
struct pci_driver skeleton_driver __pci_driver = {
.ids = skeleton_nics,
.id_count = ( sizeof ( skeleton_nics ) / sizeof ( skeleton_nics[0] ) ),
.probe = skeleton_probe,
.remove = skeleton_remove,
};
|