2 * Copyright (C) 2007 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <undipreload.h>
36 * Find UNDI ROM for PCI device
39 * @ret undirom UNDI ROM, or NULL
41 * Try to find a driver for this device. Try an exact match on the
42 * ROM address first, then fall back to a vendor/device ID match only
44 static struct undi_rom * undipci_find_rom ( struct pci_device *pci ) {
45 struct undi_rom *undirom;
46 unsigned long rombase;
48 rombase = pci_bar_start ( pci, PCI_ROM_ADDRESS );
49 undirom = undirom_find_pci ( pci->vendor, pci->device, rombase );
51 undirom = undirom_find_pci ( pci->vendor, pci->device, 0 );
60 * @ret rc Return status code
62 static int undipci_probe ( struct pci_device *pci,
63 const struct pci_device_id *id __unused ) {
64 struct undi_device *undi;
65 struct undi_rom *undirom;
66 unsigned int busdevfn = ( ( pci->bus << 8 ) | pci->devfn );
69 /* Ignore non-network devices */
70 if ( PCI_BASE_CLASS ( pci->class ) != PCI_BASE_CLASS_NETWORK )
73 /* Allocate UNDI device structure */
74 undi = malloc ( sizeof ( *undi ) );
77 memset ( undi, 0, sizeof ( *undi ) );
78 pci_set_drvdata ( pci, undi );
80 /* Find/create our pixie */
81 if ( preloaded_undi.pci_busdevfn == busdevfn ) {
82 /* Claim preloaded UNDI device */
83 DBGC ( undi, "UNDI %p using preloaded UNDI device\n", undi );
84 memcpy ( undi, &preloaded_undi, sizeof ( *undi ) );
85 memset ( &preloaded_undi, 0, sizeof ( preloaded_undi ) );
87 /* Find UNDI ROM for PCI device */
88 if ( ! ( undirom = undipci_find_rom ( pci ) ) ) {
93 /* Call UNDI ROM loader to create pixie */
94 if ( ( rc = undi_load_pci ( undi, undirom, busdevfn ) ) != 0 )
98 /* Add to device hierarchy */
99 undi->dev.parent = &pci->dev;
100 INIT_LIST_HEAD ( &undi->dev.children );
101 list_add ( &undi->dev.siblings, &pci->dev.children );
103 /* Create network device */
104 if ( ( rc = undinet_probe ( undi ) ) != 0 )
105 goto err_undinet_probe;
110 undi_unload ( undi );
111 list_del ( &undi->dev.siblings );
115 pci_set_drvdata ( pci, NULL );
124 static void undipci_remove ( struct pci_device *pci ) {
125 struct undi_device *undi = pci_get_drvdata ( pci );
127 undi_unload ( undi );
128 list_del ( &undi->dev.siblings );
130 pci_set_drvdata ( pci, NULL );
133 static struct pci_device_id undipci_nics[] = {
134 PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)" ),
137 struct pci_driver undipci_driver __pci_driver = {
139 .id_count = ( sizeof ( undipci_nics ) / sizeof ( undipci_nics[0] ) ),
140 .probe = undipci_probe,
141 .remove = undipci_remove,