diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2009-05-14 22:58:21 +0000 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2009-05-14 22:58:21 +0000 |
commit | 530cb2d4f16c110d12852ecbb0d48860eb99bf5e (patch) | |
tree | a6b990b8d29e399ce20e888410f631e13061faa6 /nic3com.c | |
parent | 3b7e75a23e0d9f812e7e7792734846720dbfd648 (diff) | |
download | ast2050-flashrom-530cb2d4f16c110d12852ecbb0d48860eb99bf5e.zip ast2050-flashrom-530cb2d4f16c110d12852ecbb0d48860eb99bf5e.tar.gz |
Make the nic3com code check how many supported NICs are found
If we find multiple ones, abort with a message to the user, suggesting
to use the
flashrom -p nic3com=bb:dd.f
syntax. If exactly one supported NIC is found, use it. If none is found,
abort with an error.
Print the bb:dd.f numbers for all supported NICs we find, so the user
doesn't have to poke around in lspci output to find the desired bb:dd.f.
Also, drop one pci_read_long() in favor of using the already existing
base_addr[0] struct field.
Drop the BAR in user messages, it's not really useful for us. Instead,
explain the BDF syntax a bit more verbosely.
While I'm at it, update the manpage some more to mention and fully
document the external programmer support we have (or will have soon).
The patch is tested on hardware:
$ flashrom -p nic3com flashrom v0.9.0-r512 Found NIC "3COM 3C905C:
EtherLink 10/100 PCI (TX)" (10b7:9200, BDF 05:04.0) Found NIC "3COM
3C905C: EtherLink 10/100 PCI (TX)" (10b7:9200, BDF 05:03.0) Error:
Multiple supported NICs found. Please use 'flashrom -p nic3com=bb:dd.f'
to explicitly select the card with the given BDF (PCI bus, device,
function).
$ flashrom -p nic3com=05:04.0 flashrom v0.9.0-r512 Found NIC "3COM
3C905C: EtherLink 10/100 PCI (TX)" (10b7:9200, BDF 05:04.0) Calibrating
delay loop... OK. Found chip "Atmel AT49BV512" (64 KB) at physical
address 0xffff0000. No operations were specified.
Corresponding to flashrom svn r513.
Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Diffstat (limited to 'nic3com.c')
-rw-r--r-- | nic3com.c | 41 |
1 files changed, 24 insertions, 17 deletions
@@ -67,18 +67,18 @@ static struct nic_status { uint32_t nic3com_validate(struct pci_dev *dev) { - int i = 0; - uint32_t addr = -1; + int i; + uint32_t addr; for (i = 0; nics[i].device_name != NULL; i++) { if (dev->device_id != nics[i].device_id) continue; - addr = pci_read_long(dev, PCI_IO_BASE_ADDRESS) & ~0x03; + addr = (uint32_t)(dev->base_addr[0] & ~0x03); - printf("Found NIC \"3COM %s\" (%04x:%04x), addr = 0x%x\n", - nics[i].device_name, PCI_VENDOR_ID_3COM, - nics[i].device_id, addr); + printf("Found NIC \"3COM %s\" (%04x:%04x, BDF %02x:%02x.%x)\n", + nics[i].device_name, dev->vendor_id, + dev->device_id, dev->bus, dev->dev, dev->func); if (nics[i].status == NT) { printf("===\nThis NIC is UNTESTED. Please email a " @@ -90,41 +90,48 @@ uint32_t nic3com_validate(struct pci_dev *dev) return addr; } - return addr; + return 0; } int nic3com_init(void) { struct pci_dev *dev; char *msg = NULL; + int found = 0; get_io_perms(); pacc = pci_alloc(); /* Get the pci_access structure */ pci_init(pacc); /* Initialize the PCI library */ pci_scan_bus(pacc); /* We want to get the list of devices */ + pci_filter_init(pacc, &filter); + /* Filter by vendor and also bb:dd.f (if supplied by the user). */ + filter.vendor = PCI_VENDOR_ID_3COM; if (nic_pcidev != NULL) { - pci_filter_init(pacc, &filter); - if ((msg = pci_filter_parse_slot(&filter, nic_pcidev))) { fprintf(stderr, "Error: %s\n", msg); exit(1); } } - if (!filter.vendor && !filter.device) { - pci_filter_init(pacc, &filter); - filter.vendor = PCI_VENDOR_ID_3COM; + for (dev = pacc->devices; dev; dev = dev->next) { + if (pci_filter_match(&filter, dev)) { + if ((io_base_addr = nic3com_validate(dev)) != 0) + found++; + } } - dev = pci_dev_find_filter(filter); - - if (dev && (dev->vendor_id == PCI_VENDOR_ID_3COM)) - io_base_addr = nic3com_validate(dev); - else { + /* Only continue if exactly one supported NIC has been found. */ + if (found == 0) { fprintf(stderr, "Error: No supported 3COM NIC found.\n"); exit(1); + } else if (found > 1) { + fprintf(stderr, "Error: Multiple supported NICs found. " + "Please use 'flashrom -p nic3com=bb:dd.f' \n" + "to explicitly select the card with the given BDF " + "(PCI bus, device, function).\n"); + exit(1); } /* |