Module Name: src Committed By: tsutsui Date: Mon Jul 5 14:03:46 UTC 2021
Modified Files: src/sys/arch/hp300/dev: ct.c hpib.c hpibvar.h mt.c rd.c Log Message: Pull HP-IB probe fixes from OpenBSD/hp300. https://marc.info/?l=openbsd-cvs&m=113217630426615&w=2 > Overhaul the way HP-IB devices are probed. We will now do an exhaustive > probe of the (slave, punit) tuple space, since this is the only way we > can get a dual disk or dual tape enclosure to attach two devices of the > same kind. This allows using multiple rd(4) disk images on the same slave emulated by HPDisk (and probably the real 9122D with dual floppy disk drives). Thanks to Miod Vallat for suggesting this fix. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/sys/arch/hp300/dev/ct.c cvs rdiff -u -r1.42 -r1.43 src/sys/arch/hp300/dev/hpib.c cvs rdiff -u -r1.21 -r1.22 src/sys/arch/hp300/dev/hpibvar.h cvs rdiff -u -r1.54 -r1.55 src/sys/arch/hp300/dev/mt.c cvs rdiff -u -r1.104 -r1.105 src/sys/arch/hp300/dev/rd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/hp300/dev/ct.c diff -u src/sys/arch/hp300/dev/ct.c:1.61 src/sys/arch/hp300/dev/ct.c:1.62 --- src/sys/arch/hp300/dev/ct.c:1.61 Fri Jul 25 08:10:33 2014 +++ src/sys/arch/hp300/dev/ct.c Mon Jul 5 14:03:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ct.c,v 1.61 2014/07/25 08:10:33 dholland Exp $ */ +/* $NetBSD: ct.c,v 1.62 2021/07/05 14:03:46 tsutsui Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -75,7 +75,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ct.c,v 1.61 2014/07/25 08:10:33 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ct.c,v 1.62 2021/07/05 14:03:46 tsutsui Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -270,13 +270,12 @@ ctident(device_t parent, struct ct_softc /* Is it one of the tapes we support? */ for (id = 0; id < nctinfo; id++) - if (ha->ha_id == ctinfo[id].hwid) + if (ha->ha_id == ctinfo[id].hwid && + ha->ha_punit == ctinfo[id].punit) break; if (id == nctinfo) return 0; - ha->ha_punit = ctinfo[id].punit; - /* * So far, so good. Get drive parameters. Note command * is always issued to unit 0. Index: src/sys/arch/hp300/dev/hpib.c diff -u src/sys/arch/hp300/dev/hpib.c:1.42 src/sys/arch/hp300/dev/hpib.c:1.43 --- src/sys/arch/hp300/dev/hpib.c:1.42 Sat Apr 24 23:36:37 2021 +++ src/sys/arch/hp300/dev/hpib.c Mon Jul 5 14:03:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: hpib.c,v 1.42 2021/04/24 23:36:37 thorpej Exp $ */ +/* $NetBSD: hpib.c,v 1.43 2021/07/05 14:03:46 tsutsui Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -65,7 +65,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: hpib.c,v 1.42 2021/04/24 23:36:37 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hpib.c,v 1.43 2021/07/05 14:03:46 tsutsui Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -89,14 +89,9 @@ CFATTACH_DECL_NEW(hpibbus, sizeof(struct hpibbusmatch, hpibbusattach, NULL, NULL); static void hpibbus_attach_children(struct hpibbus_softc *); -static int hpibbussearch(device_t, cfdata_t, const int *, void *); +static int hpibbussubmatch(device_t, cfdata_t, const int *ldesc, void *); static int hpibbusprint(void *, const char *); -static int hpibbus_alloc(struct hpibbus_softc *, int, int); -#if 0 -static void hpibbus_free(struct hpibbus_softc *, int, int); -#endif - static void hpibstart(void *); static void hpibdone(void *); @@ -121,17 +116,9 @@ int hpibdmathresh = 3; /* byte count bey * have ID tags, and often the host cannot even tell if such * a device is attached to the system! * - * These two nasty bits mean that we have to treat HP-IB as - * an indirect bus. However, since we are given some ID - * information, it is unreasonable to disallow cloning of - * CS/80 devices. - * - * To deal with all of this, we use the semi-twisted scheme - * in hpibbus_attach_children(). For each HP-IB slave, we loop - * through all of the possibly-configured children, allowing - * them to modify the punit parameter (but NOT the slave!). - * - * This is evil, but what can you do? + * * We nevertheless probe the whole (slave, punit) tuple space, since + * drivers for devices with a unique ID know exactly where to attach; + * and we disallow ``star'' locators for other drivers. */ static int @@ -177,64 +164,51 @@ static void hpibbus_attach_children(struct hpibbus_softc *sc) { struct hpibbus_attach_args ha; - int slave; + int id, slave, punit; + int i; - for (slave = 0; slave < 8; slave++) { + for (slave = 0; slave < HPIB_NSLAVES; slave++) { /* * Get the ID tag for the device, if any. * Plotters won't identify themselves, and * get the same value as non-existent devices. + * However, aging HP-IB drives are slow to respond; try up + * to three times to get a valid ID. */ - ha.ha_id = hpibid(device_unit(sc->sc_dev), slave); - - ha.ha_slave = slave; /* not to be modified by children */ - ha.ha_punit = 0; /* children modify this */ + for (i = 0; i < 3; i++) { + id = hpibid(device_unit(sc->sc_dev), slave); + if ((id & 0x200) != 0) + break; + delay(10000); + } - /* - * Search though all configured children for this bus. - */ - config_search(sc->sc_dev, &ha, - CFARG_SEARCH, hpibbussearch, - CFARG_EOL); + for (punit = 0; punit < HPIB_NPUNITS; punit++) { + /* + * Search through all configured children for this bus. + */ + ha.ha_id = id; + ha.ha_slave = slave; + ha.ha_punit = punit; + config_found(sc->sc_dev, &ha, hpibbusprint, + CFARG_SUBMATCH, hpibbussubmatch, + CFARG_EOL); + } } } static int -hpibbussearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux) +hpibbussubmatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux) { - struct hpibbus_softc *sc = device_private(parent); struct hpibbus_attach_args *ha = aux; - /* Make sure this is in a consistent state. */ - ha->ha_punit = 0; - - if (config_probe(parent, cf, ha)) { - /* - * The device probe has succeeded, and filled in - * the punit information. Make sure the configuration - * allows for this slave/punit combination. - */ - if (cf->hpibbuscf_slave != HPIBBUSCF_SLAVE_DEFAULT && - cf->hpibbuscf_slave != ha->ha_slave) - goto out; - if (cf->hpibbuscf_punit != HPIBBUSCF_PUNIT_DEFAULT && - cf->hpibbuscf_punit != ha->ha_punit) - goto out; - - /* - * Allocate the device's address from the bus's - * resource map. - */ - if (hpibbus_alloc(sc, ha->ha_slave, ha->ha_punit)) - goto out; + if (cf->hpibbuscf_slave != HPIBBUSCF_SLAVE_DEFAULT && + cf->hpibbuscf_slave != ha->ha_slave) + return 0; + if (cf->hpibbuscf_punit != HPIBBUSCF_PUNIT_DEFAULT && + cf->hpibbuscf_punit != ha->ha_punit) + return 0; - /* - * This device is allowed; attach it. - */ - config_attach(parent, cf, ha, hpibbusprint, CFARG_EOL); - } - out: - return 0; + return config_match(parent, cf, aux); } static int @@ -242,6 +216,11 @@ hpibbusprint(void *aux, const char *pnp) { struct hpibbus_attach_args *ha = aux; + if (pnp != NULL) { + if (ha->ha_id == 0 || ha->ha_punit != 0 /* XXX */) + return QUIET; + printf("HP-IB device (id %04X) at %s", ha->ha_id, pnp); + } aprint_normal(" slave %d punit %d", ha->ha_slave, ha->ha_punit); return UNCONF; } @@ -418,36 +397,3 @@ hpibintr(void *arg) return (sc->sc_ops->hpib_intr)(arg); } - -static int -hpibbus_alloc(struct hpibbus_softc *sc, int slave, int punit) -{ - - if (slave >= HPIB_NSLAVES || - punit >= HPIB_NPUNITS) - panic("hpibbus_alloc: device address out of range"); - - if (sc->sc_rmap[slave][punit] == 0) { - sc->sc_rmap[slave][punit] = 1; - return 0; - } - return 1; -} - -#if 0 -static void -hpibbus_free(struct hpibbus_softc *sc, int slave, int punit) -{ - - if (slave >= HPIB_NSLAVES || - punit >= HPIB_NPUNITS) - panic("hpibbus_free: device address out of range"); - -#ifdef DIAGNOSTIC - if (sc->sc_rmap[slave][punit] == 0) - panic("hpibbus_free: not allocated"); -#endif - - sc->sc_rmap[slave][punit] = 0; -} -#endif Index: src/sys/arch/hp300/dev/hpibvar.h diff -u src/sys/arch/hp300/dev/hpibvar.h:1.21 src/sys/arch/hp300/dev/hpibvar.h:1.22 --- src/sys/arch/hp300/dev/hpibvar.h:1.21 Sat Oct 13 06:12:23 2012 +++ src/sys/arch/hp300/dev/hpibvar.h Mon Jul 5 14:03:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: hpibvar.h,v 1.21 2012/10/13 06:12:23 tsutsui Exp $ */ +/* $NetBSD: hpibvar.h,v 1.22 2021/07/05 14:03:46 tsutsui Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -174,12 +174,6 @@ struct hpibbus_softc { char *sc_addr; int sc_count; int sc_curcnt; - - /* - * HP-IB is an indirect bus; this cheezy resource map - * keeps track of slave/punit allocations. - */ - char sc_rmap[HPIB_NSLAVES][HPIB_NPUNITS]; }; /* sc_flags */ Index: src/sys/arch/hp300/dev/mt.c diff -u src/sys/arch/hp300/dev/mt.c:1.54 src/sys/arch/hp300/dev/mt.c:1.55 --- src/sys/arch/hp300/dev/mt.c:1.54 Fri Jul 25 08:10:33 2014 +++ src/sys/arch/hp300/dev/mt.c Mon Jul 5 14:03:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: mt.c,v 1.54 2014/07/25 08:10:33 dholland Exp $ */ +/* $NetBSD: mt.c,v 1.55 2021/07/05 14:03:46 tsutsui Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: mt.c,v 1.54 2014/07/25 08:10:33 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mt.c,v 1.55 2021/07/05 14:03:46 tsutsui Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -224,7 +224,8 @@ mtident(struct mt_softc *sc, struct hpib int i; for (i = 0; i < nmtinfo; i++) { - if (ha->ha_id == mtinfo[i].hwid) { + if (ha->ha_id == mtinfo[i].hwid && + ha->ha_punit == 0) { if (sc != NULL) { sc->sc_type = mtinfo[i].hwid; aprint_normal(": %s tape\n", mtinfo[i].desc); Index: src/sys/arch/hp300/dev/rd.c diff -u src/sys/arch/hp300/dev/rd.c:1.104 src/sys/arch/hp300/dev/rd.c:1.105 --- src/sys/arch/hp300/dev/rd.c:1.104 Wed Jun 30 14:54:03 2021 +++ src/sys/arch/hp300/dev/rd.c Mon Jul 5 14:03:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: rd.c,v 1.104 2021/06/30 14:54:03 tsutsui Exp $ */ +/* $NetBSD: rd.c,v 1.105 2021/07/05 14:03:46 tsutsui Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -72,7 +72,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rd.c,v 1.104 2021/06/30 14:54:03 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rd.c,v 1.105 2021/07/05 14:03:46 tsutsui Exp $"); #include "opt_useleds.h" @@ -172,13 +172,13 @@ static const char *err_info[] = { 0, 0 }; -int rddebug = 0x80; #define RDB_FOLLOW 0x01 #define RDB_STATUS 0x02 #define RDB_IDENT 0x04 #define RDB_IO 0x08 #define RDB_ASYNC 0x10 #define RDB_ERROR 0x80 +int rddebug = HDB_ERROR | HDB_IDENT; #endif /* @@ -312,25 +312,7 @@ rdmatch(device_t parent, cfdata_t cf, vo { struct hpibbus_attach_args *ha = aux; - /* - * Set punit if operator specified one in the kernel - * configuration file. - */ - if (cf->hpibbuscf_punit != HPIBBUSCF_PUNIT_DEFAULT && - cf->hpibbuscf_punit < HPIB_NPUNITS) - ha->ha_punit = cf->hpibbuscf_punit; - - if (rdident(parent, NULL, ha) == 0) { - /* - * XXX Some aging HP-IB drives are slow to - * XXX respond; give them a chance to catch - * XXX up and probe them again. - */ - delay(10000); - ha->ha_id = hpibid(device_unit(parent), ha->ha_slave); - return rdident(parent, NULL, ha); - } - return 1; + return rdident(parent, NULL, ha); } static void @@ -396,9 +378,10 @@ rdident(device_t parent, struct rd_softc /* Is it one of the disks we support? */ for (id = 0; id < numrdidentinfo; id++) - if (ha->ha_id == rdidentinfo[id].ri_hwid) + if (ha->ha_id == rdidentinfo[id].ri_hwid && + ha->ha_punit <= rdidentinfo[id].ri_maxunum) break; - if (id == numrdidentinfo || ha->ha_punit > rdidentinfo[id].ri_maxunum) + if (id == numrdidentinfo) return 0; /*