Skip to content

Commit

Permalink
[undi] Clean up driver and device name information
Browse files Browse the repository at this point in the history
Fix the <NULL> driver name reported by "ifstat" when using the undipci
driver (due to the unnecessary extra device node inserted as a child
of the PCI device).

Remove the "UNDI-" prefix from device names since the driver name is
also now visible via "ifstat", and tidy up the device name to match
the format used by standard PCI devices.

The output from "ifstat" now resembles:

  iPXE> ifstat
  net0: 52:54:00:12:34:56 using undipci on 0000:00:03.0

  iPXE> ifstat
  net0: 52:54:00:12:34:56 using undionly on 0000:00:03.0

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Dec 5, 2016
1 parent cc40fcb commit 6997d3c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 39 deletions.
12 changes: 1 addition & 11 deletions src/arch/x86/drivers/net/undi.c
Expand Up @@ -94,23 +94,14 @@ static int undipci_probe ( struct pci_device *pci ) {
}
}

/* Add to device hierarchy */
snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
"UNDI-%s", pci->dev.name );
memcpy ( &undi->dev.desc, &pci->dev.desc, sizeof ( undi->dev.desc ) );
undi->dev.parent = &pci->dev;
INIT_LIST_HEAD ( &undi->dev.children );
list_add ( &undi->dev.siblings, &pci->dev.children );

/* Create network device */
if ( ( rc = undinet_probe ( undi ) ) != 0 )
if ( ( rc = undinet_probe ( undi, &pci->dev ) ) != 0 )
goto err_undinet_probe;

return 0;

err_undinet_probe:
undi_unload ( undi );
list_del ( &undi->dev.siblings );
err_find_rom:
err_load_pci:
free ( undi );
Expand All @@ -128,7 +119,6 @@ static void undipci_remove ( struct pci_device *pci ) {

undinet_remove ( undi );
undi_unload ( undi );
list_del ( &undi->dev.siblings );
free ( undi );
pci_set_drvdata ( pci, NULL );
}
Expand Down
17 changes: 9 additions & 8 deletions src/arch/x86/drivers/net/undinet.c
Expand Up @@ -598,19 +598,19 @@ static const struct undinet_irq_broken undinet_irq_broken_list[] = {
/**
* Check for devices with broken support for generating interrupts
*
* @v undi UNDI device
* @v desc Device description
* @ret irq_is_broken Interrupt support is broken; no interrupts are generated
*/
static int undinet_irq_is_broken ( struct undi_device *undi ) {
static int undinet_irq_is_broken ( struct device_description *desc ) {
const struct undinet_irq_broken *broken;
unsigned int i;

for ( i = 0 ; i < ( sizeof ( undinet_irq_broken_list ) /
sizeof ( undinet_irq_broken_list[0] ) ) ; i++ ) {
broken = &undinet_irq_broken_list[i];
if ( ( undi->dev.desc.bus_type == BUS_TYPE_PCI ) &&
( undi->dev.desc.vendor == broken->pci_vendor ) &&
( undi->dev.desc.device == broken->pci_device ) ) {
if ( ( desc->bus_type == BUS_TYPE_PCI ) &&
( desc->vendor == broken->pci_vendor ) &&
( desc->device == broken->pci_device ) ) {
return 1;
}
}
Expand All @@ -621,9 +621,10 @@ static int undinet_irq_is_broken ( struct undi_device *undi ) {
* Probe UNDI device
*
* @v undi UNDI device
* @v dev Underlying generic device
* @ret rc Return status code
*/
int undinet_probe ( struct undi_device *undi ) {
int undinet_probe ( struct undi_device *undi, struct device *dev ) {
struct net_device *netdev;
struct undi_nic *undinic;
struct s_PXENV_START_UNDI start_undi;
Expand All @@ -644,7 +645,7 @@ int undinet_probe ( struct undi_device *undi ) {
netdev_init ( netdev, &undinet_operations );
undinic = netdev->priv;
undi_set_drvdata ( undi, netdev );
netdev->dev = &undi->dev;
netdev->dev = dev;
memset ( undinic, 0, sizeof ( *undinic ) );
undinet_entry = undi->entry;
DBGC ( undinic, "UNDINIC %p using UNDI %p\n", undinic, undi );
Expand Down Expand Up @@ -733,7 +734,7 @@ int undinet_probe ( struct undi_device *undi ) {
undinic );
undinic->hacks |= UNDI_HACK_EB54;
}
if ( undinet_irq_is_broken ( undi ) ) {
if ( undinet_irq_is_broken ( &dev->desc ) ) {
DBGC ( undinic, "UNDINIC %p forcing polling mode due to "
"broken interrupts\n", undinic );
undinic->irq_supported = 0;
Expand Down
37 changes: 20 additions & 17 deletions src/arch/x86/drivers/net/undionly.c
Expand Up @@ -50,6 +50,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
* addition to the UNDI driver, build e.g. "bin/undi.dsk".
*/

/** UNDI root bus device */
static struct device undibus_dev;

/**
* Probe UNDI root bus
*
Expand All @@ -60,6 +63,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/
static int undibus_probe ( struct root_device *rootdev ) {
struct undi_device *undi = &preloaded_undi;
struct device *dev = &undibus_dev;
int rc;

/* Check for a valie preloaded UNDI device */
Expand All @@ -69,34 +73,32 @@ static int undibus_probe ( struct root_device *rootdev ) {
}

/* Add to device hierarchy */
undi->dev.driver_name = "undionly";
dev->driver_name = "undionly";
if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
undi->dev.desc.bus_type = BUS_TYPE_PCI;
undi->dev.desc.location = undi->pci_busdevfn;
undi->dev.desc.vendor = undi->pci_vendor;
undi->dev.desc.device = undi->pci_device;
snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
"UNDI-PCI%02x:%02x.%x",
PCI_BUS ( undi->pci_busdevfn ),
dev->desc.bus_type = BUS_TYPE_PCI;
dev->desc.location = undi->pci_busdevfn;
dev->desc.vendor = undi->pci_vendor;
dev->desc.device = undi->pci_device;
snprintf ( dev->name, sizeof ( dev->name ),
"0000:%02x:%02x.%x", PCI_BUS ( undi->pci_busdevfn ),
PCI_SLOT ( undi->pci_busdevfn ),
PCI_FUNC ( undi->pci_busdevfn ) );
} else if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
undi->dev.desc.bus_type = BUS_TYPE_ISAPNP;
snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
"UNDI-ISAPNP" );
dev->desc.bus_type = BUS_TYPE_ISAPNP;
snprintf ( dev->name, sizeof ( dev->name ), "ISAPNP" );
}
undi->dev.parent = &rootdev->dev;
list_add ( &undi->dev.siblings, &rootdev->dev.children);
INIT_LIST_HEAD ( &undi->dev.children );
dev->parent = &rootdev->dev;
list_add ( &dev->siblings, &rootdev->dev.children);
INIT_LIST_HEAD ( &dev->children );

/* Create network device */
if ( ( rc = undinet_probe ( undi ) ) != 0 )
if ( ( rc = undinet_probe ( undi, dev ) ) != 0 )
goto err;

return 0;

err:
list_del ( &undi->dev.siblings );
list_del ( &dev->siblings );
return rc;
}

Expand All @@ -107,9 +109,10 @@ static int undibus_probe ( struct root_device *rootdev ) {
*/
static void undibus_remove ( struct root_device *rootdev __unused ) {
struct undi_device *undi = &preloaded_undi;
struct device *dev = &undibus_dev;

undinet_remove ( undi );
list_del ( &undi->dev.siblings );
list_del ( &dev->siblings );
}

/** UNDI bus root device driver */
Expand Down
2 changes: 0 additions & 2 deletions src/arch/x86/include/undi.h
Expand Up @@ -53,8 +53,6 @@ struct undi_device {
*/
UINT16_t flags;

/** Generic device */
struct device dev;
/** Driver-private data
*
* Use undi_set_drvdata() and undi_get_drvdata() to access this
Expand Down
3 changes: 2 additions & 1 deletion src/arch/x86/include/undinet.h
Expand Up @@ -10,8 +10,9 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

struct undi_device;
struct device;

extern int undinet_probe ( struct undi_device *undi );
extern int undinet_probe ( struct undi_device *undi, struct device *dev );
extern void undinet_remove ( struct undi_device *undi );

#endif /* _UNDINET_H */

0 comments on commit 6997d3c

Please sign in to comment.