From dcdb02de2463143b14b8f74d6c53b536a87e1219 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 6 Apr 2002 21:58:13 +0000 Subject: For PLX-based bridge cards, move printing of pcmcia card CIS strings out of generic wi_attach() and into wi_pci_attach(). This means we can't print the CIS info for embedded cards like the NCP130 but since those don't have a "real" pcmcia card in them this is really not a problem. Also check to see that there is actually a pcmcia present and give and error if not. CIS magic number taken from the Linux orinoco driver; there may be a better way to do this. --- sys/dev/ic/if_wi.c | 38 ++++++---------------------- sys/dev/pci/if_wi_pci.c | 58 +++++++++++++++++++++++++++++++++++++------ sys/dev/pcmcia/if_wi_pcmcia.c | 6 ++--- 3 files changed, 61 insertions(+), 41 deletions(-) diff --git a/sys/dev/ic/if_wi.c b/sys/dev/ic/if_wi.c index 894aedc589c..8fa834a7c4c 100644 --- a/sys/dev/ic/if_wi.c +++ b/sys/dev/ic/if_wi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_wi.c,v 1.46 2002/04/06 20:31:56 millert Exp $ */ +/* $OpenBSD: if_wi.c,v 1.47 2002/04/06 21:58:12 millert Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -124,7 +124,7 @@ u_int32_t widebug = WIDEBUG; #if !defined(lint) && !defined(__OpenBSD__) static const char rcsid[] = - "$OpenBSD: if_wi.c,v 1.46 2002/04/06 20:31:56 millert Exp $"; + "$OpenBSD: if_wi.c,v 1.47 2002/04/06 21:58:12 millert Exp $"; #endif /* lint */ #ifdef foo @@ -152,7 +152,7 @@ STATIC int wi_seek(struct wi_softc *, int, int, int); STATIC int wi_alloc_nicmem(struct wi_softc *, int, int *); STATIC void wi_inquire(void *); STATIC int wi_setdef(struct wi_softc *, struct wi_req *); -STATIC void wi_get_id(struct wi_softc *, int); +STATIC void wi_get_id(struct wi_softc *); STATIC int wi_media_change(struct ifnet *); STATIC void wi_media_status(struct ifnet *, struct ifmediareq *); @@ -165,7 +165,7 @@ STATIC int wi_set_pm(struct wi_softc *, struct ieee80211_power *); STATIC int wi_get_pm(struct wi_softc *, struct ieee80211_power *); int wi_intr(void *); -int wi_attach(struct wi_softc *, int); +int wi_attach(struct wi_softc *); void wi_init(struct wi_softc *); void wi_stop(struct wi_softc *); @@ -175,9 +175,8 @@ struct cfdriver wi_cd = { }; int -wi_attach(sc, print_cis) +wi_attach(sc) struct wi_softc *sc; - int print_cis; { struct wi_ltv_macaddr mac; struct wi_ltv_gen gen; @@ -199,7 +198,7 @@ wi_attach(sc, print_cis) bcopy((char *)&mac.wi_mac_addr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); - wi_get_id(sc, print_cis); + wi_get_id(sc); printf("address %s", ether_sprintf(sc->arpcom.ac_enaddr)); ifp = &sc->arpcom.ac_if; @@ -1923,36 +1922,13 @@ wi_shutdown(arg) } STATIC void -wi_get_id(sc, print_cis) +wi_get_id(sc) struct wi_softc *sc; - int print_cis; { struct wi_ltv_ver ver; - struct wi_ltv_cis cis; u_int16_t pri_fw_ver[3]; const char *p; - if (print_cis) { - /* - * For PCI attachments the CIS strings won't have been printed - * so print them here. - * XXX - messes up each odd character on Symbol cards - */ - cis.wi_type = WI_RID_CIS; - cis.wi_len = sizeof(cis.wi_cis); - if (wi_read_record(sc, (struct wi_ltv_gen *)&cis) == 0) { - char *cis_strings[3]; - - cis_strings[0] = (char *)&cis.wi_cis[11]; - cis_strings[1] = cis_strings[0] + - strlen(cis_strings[0]) + 1; - cis_strings[2] = cis_strings[1] + - strlen(cis_strings[1]) + 1; - printf("\n%s: \"%s, %s, %s\"", WI_PRT_ARG(sc), - cis_strings[0], cis_strings[1], cis_strings[2]); - } - } - /* get chip identity */ bzero(&ver, sizeof(ver)); ver.wi_type = WI_RID_CARD_ID; diff --git a/sys/dev/pci/if_wi_pci.c b/sys/dev/pci/if_wi_pci.c index 419ea224b1e..8bab8606a10 100644 --- a/sys/dev/pci/if_wi_pci.c +++ b/sys/dev/pci/if_wi_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_wi_pci.c,v 1.22 2002/04/06 20:31:56 millert Exp $ */ +/* $OpenBSD: if_wi_pci.c,v 1.23 2002/04/06 21:58:12 millert Exp $ */ /* * Copyright (c) 2001, 2002 Todd C. Miller @@ -91,11 +91,16 @@ #define WI_PCI_PLX 0x02 /* PLX 905x dumb bridge */ #define WI_PCI_TMD 0x03 /* TMD 7160 dumb bridge */ +/* For printing CIS of the actual PCMCIA card */ +#define CIS_MFG_NAME_OFFSET 0x16 +#define CIS_INFO_SIZE 256 + const struct wi_pci_product *wi_pci_lookup(struct pci_attach_args *pa); int wi_pci_match(struct device *, void *, void *); void wi_pci_attach(struct device *, struct device *, void *); +int wi_pci_handle_cis(struct wi_softc *); int wi_intr(void *); -int wi_attach(struct wi_softc *, int); +int wi_attach(struct wi_softc *); struct cfattach wi_pci_ca = { sizeof (struct wi_softc), wi_pci_match, wi_pci_attach @@ -282,7 +287,12 @@ wi_pci_attach(parent, self, aux) if (localsize != 0) bus_space_unmap(localt, localh, localsize); - wi_attach(sc, 1); + /* + * For PLX bridge cards, check for a PCMCIA card and + * print its CIS strings. + */ + if (localsize != 0 && wi_pci_handle_cis(sc) != 0) + return; break; case WI_PCI_PRISM: bus_space_write_2(iot, ioh, WI_PCI_COR_OFFSET, @@ -291,8 +301,6 @@ wi_pci_attach(parent, self, aux) bus_space_write_2(iot, ioh, WI_PCI_COR_OFFSET, WI_COR_CLEAR); DELAY(100*1000); /* 100 m sec */ sc->wi_cor_offset = WI_PCI_COR_OFFSET; - - wi_attach(sc, 0); break; case WI_PCI_TMD: bus_space_write_1(localt, localh, WI_TMD_COR_OFFSET, @@ -301,8 +309,44 @@ wi_pci_attach(parent, self, aux) if (bus_space_read_1(localt, localh, 0) != WI_TMD_COR_VALUE) printf(": unable to initialize TMD7160 "); sc->wi_cor_offset = WI_TMD_COR_OFFSET; - - wi_attach(sc, 1); break; } + wi_attach(sc); +} + +int +wi_pci_handle_cis(sc) + struct wi_softc *sc; +{ + int i, stringno; + char cisbuf[CIS_INFO_SIZE]; + char *cis_strings[3]; + u_int8_t value; + const u_int8_t cis_magic[] = { + 0x01, 0x03, 0x00, 0x00, 0xff, 0x17, 0x04, 0x67 + }; + + /* Make sure there really is a card there. */ + for (i = 0; i < 8; i++) { + value = bus_space_read_1(sc->wi_ltag, sc->wi_lhandle, i * 2); + if (value != cis_magic[i]) { + printf("\n%s: no PCMCIA card detected in bridge card\n", + WI_PRT_ARG(sc)); + return (ENODEV); + } + } + + cis_strings[0] = cisbuf; + stringno = 0; + for (i = 0; i < CIS_INFO_SIZE && stringno < 3; i++) { + cisbuf[i] = bus_space_read_1(sc->wi_ltag, + sc->wi_lhandle, (CIS_MFG_NAME_OFFSET + i) * 2); + if (cisbuf[i] == '\0' && ++stringno < 3) + cis_strings[stringno] = &cisbuf[i + 1]; + } + cisbuf[CIS_INFO_SIZE - 1] = '\0'; + printf("\n%s: \"%s, %s, %s\"", WI_PRT_ARG(sc), + cis_strings[0], cis_strings[1], cis_strings[2]); + + return (0); } diff --git a/sys/dev/pcmcia/if_wi_pcmcia.c b/sys/dev/pcmcia/if_wi_pcmcia.c index eb371023df4..bd12a0e9d82 100644 --- a/sys/dev/pcmcia/if_wi_pcmcia.c +++ b/sys/dev/pcmcia/if_wi_pcmcia.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_wi_pcmcia.c,v 1.25 2002/04/06 20:31:56 millert Exp $ */ +/* $OpenBSD: if_wi_pcmcia.c,v 1.26 2002/04/06 21:58:12 millert Exp $ */ /* $NetBSD: if_wi_pcmcia.c,v 1.14 2001/11/26 04:34:56 ichiro Exp $ */ /* @@ -76,7 +76,7 @@ int wi_pcmcia_detach(struct device *, int); int wi_pcmcia_activate(struct device *, enum devact); int wi_intr(void *); -int wi_attach(struct wi_softc *, int); +int wi_attach(struct wi_softc *); void wi_init(struct wi_softc *); void wi_stop(struct wi_softc *); @@ -358,7 +358,7 @@ wi_pcmcia_attach(parent, self, aux) goto bad; } - wi_attach(sc, 0); + wi_attach(sc); return; bad: -- cgit v1.2.3