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.
28 #include <undipreload.h>
37 * Find UNDI ROM for PCI device
40 * @ret undirom UNDI ROM, or NULL
42 * Try to find a driver for this device. Try an exact match on the
43 * ROM address first, then fall back to a vendor/device ID match only
45 static struct undi_rom * undipci_find_rom ( struct pci_device *pci ) {
46 struct undi_rom *undirom;
47 unsigned long rombase;
49 rombase = pci_bar_start ( pci, PCI_ROM_ADDRESS );
50 undirom = undirom_find_pci ( pci->vendor, pci->device, rombase );
52 undirom = undirom_find_pci ( pci->vendor, pci->device, 0 );
61 * @ret rc Return status code
63 static int undipci_probe ( struct pci_device *pci,
64 const struct pci_device_id *id __unused ) {
65 struct undi_device *undi;
66 struct undi_rom *undirom;
67 unsigned int busdevfn = PCI_BUSDEVFN ( pci->bus, pci->devfn );
70 /* Ignore non-network devices */
71 if ( PCI_BASE_CLASS ( pci->class ) != PCI_BASE_CLASS_NETWORK )
74 /* Allocate UNDI device structure */
75 undi = malloc ( sizeof ( *undi ) );
78 memset ( undi, 0, sizeof ( *undi ) );
79 pci_set_drvdata ( pci, undi );
81 /* Find/create our pixie */
82 if ( preloaded_undi.pci_busdevfn == busdevfn ) {
83 /* Claim preloaded UNDI device */
84 DBGC ( undi, "UNDI %p using preloaded UNDI device\n", undi );
85 memcpy ( undi, &preloaded_undi, sizeof ( *undi ) );
86 memset ( &preloaded_undi, 0, sizeof ( preloaded_undi ) );
88 /* Find UNDI ROM for PCI device */
89 if ( ! ( undirom = undipci_find_rom ( pci ) ) ) {
94 /* Call UNDI ROM loader to create pixie */
95 if ( ( rc = undi_load_pci ( undi, undirom, busdevfn ) ) != 0 )
99 /* Add to device hierarchy */
100 snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
101 "UNDI-%s", pci->dev.name );
102 memcpy ( &undi->dev.desc, &pci->dev.desc, sizeof ( undi->dev.desc ) );
103 undi->dev.parent = &pci->dev;
104 INIT_LIST_HEAD ( &undi->dev.children );
105 list_add ( &undi->dev.siblings, &pci->dev.children );
107 /* Create network device */
108 if ( ( rc = undinet_probe ( undi ) ) != 0 )
109 goto err_undinet_probe;
114 undi_unload ( undi );
115 list_del ( &undi->dev.siblings );
119 pci_set_drvdata ( pci, NULL );
128 static void undipci_remove ( struct pci_device *pci ) {
129 struct undi_device *undi = pci_get_drvdata ( pci );
131 undinet_remove ( undi );
132 undi_unload ( undi );
133 list_del ( &undi->dev.siblings );
135 pci_set_drvdata ( pci, NULL );
138 static struct pci_device_id undipci_nics[] = {
139 PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)" ),
142 struct pci_driver undipci_driver __pci_driver = {
144 .id_count = ( sizeof ( undipci_nics ) / sizeof ( undipci_nics[0] ) ),
145 .probe = undipci_probe,
146 .remove = undipci_remove,