2 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
31 #include <ipxe/netdevice.h>
32 #include <ipxe/ethernet.h>
33 #include <ipxe/if_ether.h>
34 #include <ipxe/iobuf.h>
35 #include <ipxe/malloc.h>
42 * Skeleton network driver
46 /******************************************************************************
50 ******************************************************************************
54 * Read from MII register
56 * @v mii MII interface
57 * @v reg Register address
58 * @ret value Data read, or negative error
60 static int skeleton_mii_read ( struct mii_interface *mii, unsigned int reg ) {
61 struct skeleton_nic *skel =
62 container_of ( mii, struct skeleton_nic, mii );
64 DBGC ( skel, "SKELETON %p does not yet support MII read\n", skel );
70 * Write to MII register
72 * @v mii MII interface
73 * @v reg Register address
74 * @v data Data to write
75 * @ret rc Return status code
77 static int skeleton_mii_write ( struct mii_interface *mii, unsigned int reg,
79 struct skeleton_nic *skel =
80 container_of ( mii, struct skeleton_nic, mii );
82 DBGC ( skel, "SKELETON %p does not yet support MII write\n", skel );
88 /** Skeleton MII operations */
89 static struct mii_operations skeleton_mii_operations = {
90 .read = skeleton_mii_read,
91 .write = skeleton_mii_write,
94 /******************************************************************************
98 ******************************************************************************
104 * @v skel Skeleton device
105 * @ret rc Return status code
107 static int skeleton_reset ( struct skeleton_nic *skel ) {
109 DBGC ( skel, "SKELETON %p does not yet support reset\n", skel );
113 /******************************************************************************
117 ******************************************************************************
123 * @v netdev Network device
125 static void skeleton_check_link ( struct net_device *netdev ) {
126 struct skeleton_nic *skel = netdev->priv;
128 DBGC ( skel, "SKELETON %p does not yet support link state\n", skel );
129 netdev_link_err ( netdev, -ENOTSUP );
132 /******************************************************************************
134 * Network device interface
136 ******************************************************************************
140 * Open network device
142 * @v netdev Network device
143 * @ret rc Return status code
145 static int skeleton_open ( struct net_device *netdev ) {
146 struct skeleton_nic *skel = netdev->priv;
148 DBGC ( skel, "SKELETON %p does not yet support open\n", skel );
153 * Close network device
155 * @v netdev Network device
157 static void skeleton_close ( struct net_device *netdev ) {
158 struct skeleton_nic *skel = netdev->priv;
160 DBGC ( skel, "SKELETON %p does not yet support close\n", skel );
166 * @v netdev Network device
167 * @v iobuf I/O buffer
168 * @ret rc Return status code
170 static int skeleton_transmit ( struct net_device *netdev,
171 struct io_buffer *iobuf ) {
172 struct skeleton_nic *skel = netdev->priv;
174 DBGC ( skel, "SKELETON %p does not yet support transmit\n", skel );
180 * Poll for completed and received packets
182 * @v netdev Network device
184 static void skeleton_poll ( struct net_device *netdev ) {
185 struct skeleton_nic *skel = netdev->priv;
187 /* Not yet implemented */
192 * Enable or disable interrupts
194 * @v netdev Network device
195 * @v enable Interrupts should be enabled
197 static void skeleton_irq ( struct net_device *netdev, int enable ) {
198 struct skeleton_nic *skel = netdev->priv;
200 DBGC ( skel, "SKELETON %p does not yet support interrupts\n", skel );
204 /** Skeleton network device operations */
205 static struct net_device_operations skeleton_operations = {
206 .open = skeleton_open,
207 .close = skeleton_close,
208 .transmit = skeleton_transmit,
209 .poll = skeleton_poll,
213 /******************************************************************************
217 ******************************************************************************
224 * @ret rc Return status code
226 static int skeleton_probe ( struct pci_device *pci ) {
227 struct net_device *netdev;
228 struct skeleton_nic *skel;
231 /* Allocate and initialise net device */
232 netdev = alloc_etherdev ( sizeof ( *skel ) );
237 netdev_init ( netdev, &skeleton_operations );
239 pci_set_drvdata ( pci, netdev );
240 netdev->dev = &pci->dev;
241 memset ( skel, 0, sizeof ( *skel ) );
243 /* Fix up PCI device */
244 adjust_pci_device ( pci );
247 skel->regs = ioremap ( pci->membase, SKELETON_BAR_SIZE );
248 if ( ! skel->regs ) {
254 if ( ( rc = skeleton_reset ( skel ) ) != 0 )
257 /* Initialise and reset MII interface */
258 mii_init ( &skel->mii, &skeleton_mii_operations );
259 if ( ( rc = mii_reset ( &skel->mii ) ) != 0 ) {
260 DBGC ( skel, "SKELETON %p could not reset MII: %s\n",
261 skel, strerror ( rc ) );
265 /* Register network device */
266 if ( ( rc = register_netdev ( netdev ) ) != 0 )
267 goto err_register_netdev;
269 /* Set initial link state */
270 skeleton_check_link ( netdev );
274 unregister_netdev ( netdev );
277 skeleton_reset ( skel );
279 iounmap ( skel->regs );
281 netdev_nullify ( netdev );
282 netdev_put ( netdev );
292 static void skeleton_remove ( struct pci_device *pci ) {
293 struct net_device *netdev = pci_get_drvdata ( pci );
294 struct skeleton_nic *skel = netdev->priv;
296 /* Unregister network device */
297 unregister_netdev ( netdev );
300 skeleton_reset ( skel );
302 /* Free network device */
303 iounmap ( skel->regs );
304 netdev_nullify ( netdev );
305 netdev_put ( netdev );
308 /** Skeleton PCI device IDs */
309 static struct pci_device_id skeleton_nics[] = {
310 PCI_ROM ( 0x5ce1, 0x5ce1, "skel", "Skeleton", 0 ),
313 /** Skeleton PCI driver */
314 struct pci_driver skeleton_driver __pci_driver = {
315 .ids = skeleton_nics,
316 .id_count = ( sizeof ( skeleton_nics ) / sizeof ( skeleton_nics[0] ) ),
317 .probe = skeleton_probe,
318 .remove = skeleton_remove,