diff options
Diffstat (limited to 'bsd_eth_drivers/libbsdport/devicet.c')
-rw-r--r-- | bsd_eth_drivers/libbsdport/devicet.c | 87 |
1 files changed, 58 insertions, 29 deletions
diff --git a/bsd_eth_drivers/libbsdport/devicet.c b/bsd_eth_drivers/libbsdport/devicet.c index f197da4..7d678fb 100644 --- a/bsd_eth_drivers/libbsdport/devicet.c +++ b/bsd_eth_drivers/libbsdport/devicet.c @@ -1,5 +1,9 @@ #define DEVICET_EXTERN_INLINE +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + #include "devicet.h" #include <rtems/rtems_bsdnet.h> #include <sys/malloc.h> @@ -12,7 +16,12 @@ #include <sys/bus.h> #include "libbsdport_api.h" -#undef DEBUG +#ifdef HAVE_LIBBSPEXT +#include <bsp/bspExt.h> +#endif + +#define DEBUG 0 +int libbsdportAttachVerbose = DEBUG; extern void real_libc_free(void*); @@ -65,11 +74,11 @@ devattach(device_t dev, int unit, struct rtems_bsdnet_ifconfig *cfg) { int error; -#ifdef DEBUG - printf("Now attaching %s%d: (0x%x:%x.%x)\n", - dev->name, unit, - dev->bushdr.pci.bus, dev->bushdr.pci.dev, dev->bushdr.pci.fun); -#endif + if ( libbsdportAttachVerbose ) { + printf("Now attaching %s%d: (0x%x:%x.%x)\n", + dev->name, unit, + dev->bushdr.pci.bus, dev->bushdr.pci.dev, dev->bushdr.pci.fun); + } dev->unit = unit; dev->ifconfig = cfg; @@ -144,7 +153,7 @@ get_name_unit(const char *drvnam, char *nm, int *punit) int l = strlen(drvnam); int i; if ( l > 0 ) { - for ( i=l-1; i>=0 && isdigit(drvnam[i]); i-- ) + for ( i=l-1; i>=0 && isdigit(((unsigned char)drvnam[i])); i-- ) /* nothing else to do */; if ( 1 != sscanf(drvnam+i,"%d",punit) ) *punit = 0; /* wildcard */ @@ -247,29 +256,48 @@ device_t tmpdev; int error = 0; int bdfunit; +int n_bus; + if ( !attaching ) return ENOTSUP; +#ifdef HAVE_LIBBSPEXT + bspExtInit(); +#endif + if ( (wantedunit = get_pci_triple(cfg->name)) < 0 ) { get_name_unit(cfg->name, nm, &wantedunit); } else { wantedunit |= 1<<31; nm[0]=0; } -#ifdef DEBUG - printf("Wanted unit is 0x%x, pattern '%s'\n", wantedunit, nm); + if ( libbsdportAttachVerbose ) + printf("Wanted unit is 0x%x, pattern '%s'\n", wantedunit, nm); + + n_bus = pci_bus_count(); +#ifdef __i386__ + /* ugliest of all hacks -- RTEMS routine is currently (4.9) + * still broken; it reports the (0-based) highest bus number + * instead of the count. + */ + n_bus++; #endif unit = 0; for ( i=0; (dr=libbsdport_netdriver_table[i]); i++ ) { + + /* unused slot ? */ + if ( 0 == dr->name && 0 == dr->methods ) + continue; + /* Find matching driver */ -#ifdef DEBUG - printf("Trying driver '%s' ...", dr->name); -#endif + if ( libbsdportAttachVerbose ) + printf("Trying driver '%s' ...", dr->name); + if ( matches(dr, nm) ) { -#ifdef DEBUG - printf("MATCH\n"); -#endif + + if ( libbsdportAttachVerbose ) + printf("MATCH\n"); assert( dr->methods ); @@ -281,7 +309,7 @@ int bdfunit; } dev = devalloc(dr); - for ( b=0; b<pci_bus_count(); b++) + for ( b=0; b<n_bus; b++ ) for ( d=0; d<PCI_MAX_DEVICES; d++ ) { for ( f=0; f<pci_num_functions(b,d); f++ ) { if ( ! pci_is_ether(b,d,f) ) @@ -293,10 +321,10 @@ int bdfunit; bdfunit = (b<<8) | PCI_DEVFN(d,f); -#ifdef DEBUG - printf("Probing PCI 0x%x:%x.%x\n", - bdfunit>>8, PCI_SLOT(bdfunit), PCI_FUNC(bdfunit)); -#endif + if ( libbsdportAttachVerbose ) { + printf("Probing PCI 0x%x:%x.%x\n", + bdfunit>>8, PCI_SLOT(bdfunit), PCI_FUNC(bdfunit)); + } /* has this device been attached already ? */ if ( (tmpdev = devattached(dev)) ) { @@ -319,9 +347,9 @@ int bdfunit; /* wanted unit == 0 means next avail. * unit is acceptable. */ -#ifdef DEBUG - printf("->SUCCESS\n"); -#endif + if ( libbsdportAttachVerbose ) + printf("->SUCCESS\n"); + if ( 0 == wantedunit || UNITMATCH(wantedunit, unit, bdfunit) ) { error = devattach(dev, thisunit, cfg); if ( !error ) @@ -331,9 +359,8 @@ int bdfunit; break; default: -#ifdef DEBUG - printf("->FAILED\n"); -#endif + if ( libbsdportAttachVerbose ) + printf("->FAILED\n"); /* probe failed */ break; } @@ -343,9 +370,11 @@ int bdfunit; } /* for all busses + slots */ devfree(dev); dev = 0; } /* matching driver */ -#ifdef DEBUG - else printf("NO MATCH\n"); -#endif + else + { + if ( libbsdportAttachVerbose ) + printf("NO MATCH\n"); + } } /* for all drivers */ /* Nothing found */ |