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