From 7c929cf95bd72ff5e00efe9ce72fa21a2bafaf96 Mon Sep 17 00:00:00 2001 From: Jung-uk Kim Date: Mon, 18 Dec 2006 16:40:04 +0000 Subject: [PATCH] - Remove stale VPD support and its comment and get device name from VPD API. - Do not repeatedly read vendor/device IDs while probing. - Remove redundant bzero(3) for softc. device_get_softc(9) does it for free[1]. Reviewed by: glebius Suggested by: glebius[1] --- sys/dev/bge/if_bge.c | 42 +++++++++++++++++++---------------------- sys/dev/bge/if_bgereg.h | 25 ------------------------ 2 files changed, 19 insertions(+), 48 deletions(-) diff --git a/sys/dev/bge/if_bge.c b/sys/dev/bge/if_bge.c index 378f1c28fc2..2bae61818ee 100644 --- a/sys/dev/bge/if_bge.c +++ b/sys/dev/bge/if_bge.c @@ -1659,40 +1659,42 @@ bge_lookup_vendor(uint16_t vid) * against our list and return its name if we find a match. * * Note that since the Broadcom controller contains VPD support, we - * can get the device name string from the controller itself instead - * of the compiled-in string. This is a little slow, but it guarantees - * we'll always announce the right product name. Unfortunately, this - * is possible only later in bge_attach(), when we have established - * access to EEPROM. + * try to get the device name string from the controller itself instead + * of the compiled-in string. It guarantees we'll always announce the + * right product name. We fall back to the compiled-in string when + * VPD is unavailable or corrupt. */ static int bge_probe(device_t dev) { struct bge_type *t = bge_devs; struct bge_softc *sc = device_get_softc(dev); + uint16_t vid, did; - bzero(sc, sizeof(struct bge_softc)); sc->bge_dev = dev; - + vid = pci_get_vendor(dev); + did = pci_get_device(dev); while(t->bge_vid != 0) { - if ((pci_get_vendor(dev) == t->bge_vid) && - (pci_get_device(dev) == t->bge_did)) { - char buf[64]; + if ((vid == t->bge_vid) && (did == t->bge_did)) { + char model[64], buf[96]; const struct bge_revision *br; const struct bge_vendor *v; + const char *pname; uint32_t id; id = pci_read_config(dev, BGE_PCI_MISC_CTL, 4) & BGE_PCIMISCCTL_ASICREV; br = bge_lookup_rev(id); - id >>= 16; - v = bge_lookup_vendor(t->bge_vid); - if (br == NULL) - snprintf(buf, 64, "%s unknown ASIC (%#04x)", - v->v_name, id); + v = bge_lookup_vendor(vid); + if (pci_get_vpd_ident(dev, &pname)) + snprintf(model, 64, "%s %s", + v->v_name, + br != NULL ? br->br_name : + "NetXtreme Ethernet Controller"); else - snprintf(buf, 64, "%s %s, ASIC rev. %#04x", - v->v_name, br->br_name, id); + snprintf(model, 64, "%s", pname); + snprintf(buf, 96, "%s, %sASIC rev. %#04x", model, + br != NULL ? "" : "unknown ", id >> 16); device_set_desc_copy(dev, buf); if (pci_get_subvendor(dev) == DELL_VENDORID) sc->bge_flags |= BGE_FLAG_NO3LED; @@ -2501,12 +2503,6 @@ bge_release_resources(struct bge_softc *sc) dev = sc->bge_dev; - if (sc->bge_vpd_prodname != NULL) - free(sc->bge_vpd_prodname, M_DEVBUF); - - if (sc->bge_vpd_readonly != NULL) - free(sc->bge_vpd_readonly, M_DEVBUF); - if (sc->bge_intrhand != NULL) bus_teardown_intr(dev, sc->bge_irq, sc->bge_intrhand); diff --git a/sys/dev/bge/if_bgereg.h b/sys/dev/bge/if_bgereg.h index b0259fa23fd..112f4ca036b 100644 --- a/sys/dev/bge/if_bgereg.h +++ b/sys/dev/bge/if_bgereg.h @@ -2302,29 +2302,6 @@ struct bge_gib { */ #define BGE_INC(x, y) (x) = (x + 1) % y -/* - * Vital product data and structures. - */ -#define BGE_VPD_FLAG 0x8000 - -/* VPD structures */ -struct vpd_res { - uint8_t vr_id; - uint8_t vr_len; - uint8_t vr_pad; -}; - -struct vpd_key { - char vk_key[2]; - uint8_t vk_len; -}; - -#define VPD_RES_ID 0x82 /* ID string */ -#define VPD_RES_READ 0x90 /* start of read only area */ -#define VPD_RES_WRITE 0x81 /* start of read/write area */ -#define VPD_RES_END 0x78 /* end tag */ - - /* * Register access macros. The Tigon always uses memory mapped register * accesses and all registers must be accessed with 32 bit operations. @@ -2504,8 +2481,6 @@ struct bge_softc { int bge_link_evt; /* pending link event */ int bge_timer; struct callout bge_stat_ch; - char *bge_vpd_prodname; - char *bge_vpd_readonly; uint32_t bge_rx_discards; uint32_t bge_tx_discards; uint32_t bge_tx_collisions;