undi.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <stdint.h>
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <string.h>
00025 #include <gpxe/pci.h>
00026 #include <undi.h>
00027 #include <undirom.h>
00028 #include <undiload.h>
00029 #include <undinet.h>
00030 #include <undipreload.h>
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 static struct undi_rom * undipci_find_rom ( struct pci_device *pci ) {
00048 struct undi_rom *undirom;
00049 unsigned long rombase;
00050
00051 rombase = pci_bar_start ( pci, PCI_ROM_ADDRESS );
00052 undirom = undirom_find_pci ( pci->vendor, pci->device, rombase );
00053 if ( ! undirom )
00054 undirom = undirom_find_pci ( pci->vendor, pci->device, 0 );
00055 return undirom;
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065 static int undipci_probe ( struct pci_device *pci,
00066 const struct pci_device_id *id __unused ) {
00067 struct undi_device *undi;
00068 struct undi_rom *undirom;
00069 unsigned int busdevfn = PCI_BUSDEVFN ( pci->bus, pci->devfn );
00070 int rc;
00071
00072
00073 if ( PCI_BASE_CLASS ( pci->class ) != PCI_BASE_CLASS_NETWORK )
00074 return -ENOTTY;
00075
00076
00077 undi = zalloc ( sizeof ( *undi ) );
00078 if ( ! undi )
00079 return -ENOMEM;
00080 pci_set_drvdata ( pci, undi );
00081
00082
00083 if ( preloaded_undi.pci_busdevfn == busdevfn ) {
00084
00085 DBGC ( undi, "UNDI %p using preloaded UNDI device\n", undi );
00086 memcpy ( undi, &preloaded_undi, sizeof ( *undi ) );
00087 memset ( &preloaded_undi, 0, sizeof ( preloaded_undi ) );
00088 } else {
00089
00090 if ( ! ( undirom = undipci_find_rom ( pci ) ) ) {
00091 rc = -ENODEV;
00092 goto err_find_rom;
00093 }
00094
00095
00096 if ( ( rc = undi_load_pci ( undi, undirom, busdevfn ) ) != 0 )
00097 goto err_load_pci;
00098 }
00099
00100
00101 snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
00102 "UNDI-%s", pci->dev.name );
00103 memcpy ( &undi->dev.desc, &pci->dev.desc, sizeof ( undi->dev.desc ) );
00104 undi->dev.parent = &pci->dev;
00105 INIT_LIST_HEAD ( &undi->dev.children );
00106 list_add ( &undi->dev.siblings, &pci->dev.children );
00107
00108
00109 if ( ( rc = undinet_probe ( undi ) ) != 0 )
00110 goto err_undinet_probe;
00111
00112 return 0;
00113
00114 err_undinet_probe:
00115 undi_unload ( undi );
00116 list_del ( &undi->dev.siblings );
00117 err_find_rom:
00118 err_load_pci:
00119 free ( undi );
00120 pci_set_drvdata ( pci, NULL );
00121 return rc;
00122 }
00123
00124
00125
00126
00127
00128
00129 static void undipci_remove ( struct pci_device *pci ) {
00130 struct undi_device *undi = pci_get_drvdata ( pci );
00131
00132 undinet_remove ( undi );
00133 undi_unload ( undi );
00134 list_del ( &undi->dev.siblings );
00135 free ( undi );
00136 pci_set_drvdata ( pci, NULL );
00137 }
00138
00139 static struct pci_device_id undipci_nics[] = {
00140 PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)", 0 ),
00141 };
00142
00143 struct pci_driver undipci_driver __pci_driver = {
00144 .ids = undipci_nics,
00145 .id_count = ( sizeof ( undipci_nics ) / sizeof ( undipci_nics[0] ) ),
00146 .probe = undipci_probe,
00147 .remove = undipci_remove,
00148 };