A minimal update to the device wiring code so that it looks at the

dynamic resource tables rather than relying on a duplicated cam-specific
table generated by config(8) in ioconf.c.  This was a major holdup to
getting loader / userconfig driven configuration of scsi wiring.
This commit is contained in:
peter 2000-01-23 18:03:38 +00:00
parent 11731c7644
commit e238f1c84f
3 changed files with 83 additions and 160 deletions

View File

@ -1,67 +0,0 @@
/*
* Data structures and definitions for linking CAM into the autoconf system.
*
* Copyright (c) 1997 Justin T. Gibbs.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _CAM_CAM_CONF_H
#define _CAM_CAM_CONF_H 1
#ifdef _KERNEL
#define CAMCONF_UNSPEC 255
#define CAMCONF_ANY 254
/*
* Macro that lets us know something is specified.
*/
#define IS_SPECIFIED(ARG) (ARG != CAMCONF_UNSPEC && ARG != CAMCONF_ANY)
struct cam_sim_config
{
int pathid;
char *sim_name;
int sim_unit;
int sim_bus;
};
struct cam_periph_config
{
char *periph_name;
int periph_unit; /* desired device unit */
int pathid; /* Controller unit */
int target;
int lun;
int flags; /* Flags from config */
};
extern struct cam_sim_config cam_sinit[];
extern struct cam_periph_config cam_pinit[];
#endif
#endif /* _CAM_CAM_CONF_H */

View File

@ -37,11 +37,11 @@
#include <sys/buf.h> #include <sys/buf.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/devicestat.h> #include <sys/devicestat.h>
#include <sys/bus.h>
#include <vm/vm.h> #include <vm/vm.h>
#include <vm/vm_extern.h> #include <vm/vm_extern.h>
#include <cam/cam.h> #include <cam/cam.h>
#include <cam/cam_conf.h>
#include <cam/cam_ccb.h> #include <cam/cam_ccb.h>
#include <cam/cam_xpt_periph.h> #include <cam/cam_xpt_periph.h>
#include <cam/cam_periph.h> #include <cam/cam_periph.h>
@ -264,9 +264,10 @@ static u_int
camperiphnextunit(struct periph_driver *p_drv, u_int newunit, int wired) camperiphnextunit(struct periph_driver *p_drv, u_int newunit, int wired)
{ {
struct cam_periph *periph; struct cam_periph *periph;
struct cam_periph_config *periph_conf; char *periph_name, *strval;
char *periph_name;
int s; int s;
int i, val, dunit;
const char *dname;
s = splsoftcam(); s = splsoftcam();
periph_name = p_drv->driver_name; periph_name = p_drv->driver_name;
@ -287,25 +288,27 @@ camperiphnextunit(struct periph_driver *p_drv, u_int newunit, int wired)
} }
continue; continue;
} }
if (wired)
break;
for (periph_conf = cam_pinit; /*
wired == 0 && periph_conf->periph_name != NULL; * Don't match entries like "da 4" as a wired down
periph_conf++) { * device, but do match entries like "da 4 target 5"
* or even "da 4 scbus 1".
/* */
* Don't match entries like "da 4" as a wired down i = -1;
* device, but do match entries like "da 4 target 5" while ((i = resource_locate(i, periph_name)) != -1) {
* or even "da 4 scbus 1". dname = resource_query_name(i);
*/ dunit = resource_query_unit(i);
if (IS_SPECIFIED(periph_conf->periph_unit) /* if no "target" and no specific scbus, skip */
&& (!strcmp(periph_name, periph_conf->periph_name)) if (resource_int_value(dname, dunit, "target", &val) &&
&& (IS_SPECIFIED(periph_conf->target) (resource_string_value(dname, dunit, "at",&strval)||
|| IS_SPECIFIED(periph_conf->pathid)) strcmp(strval, "scbus") == 0))
&& (newunit == periph_conf->periph_unit)) continue;
if (newunit == dunit)
break; break;
} }
if (i == -1)
if (wired != 0 || periph_conf->periph_name == NULL)
break; break;
} }
splx(s); splx(s);
@ -316,51 +319,44 @@ static u_int
camperiphunit(struct periph_driver *p_drv, path_id_t pathid, camperiphunit(struct periph_driver *p_drv, path_id_t pathid,
target_id_t target, lun_id_t lun) target_id_t target, lun_id_t lun)
{ {
struct cam_periph_config *periph_conf; u_int unit;
u_int unit; int hit, i, val, dunit;
int hit; const char *dname;
char pathbuf[32], *strval, *periph_name;
unit = 0; unit = 0;
hit = 0; hit = 0;
for (periph_conf = cam_pinit; periph_name = p_drv->driver_name;
periph_conf->periph_name != NULL; snprintf(pathbuf, sizeof(pathbuf), "scbus%d", pathid);
periph_conf++, hit = 0) { i = -1;
while ((i = resource_locate(i, periph_name)) != -1) {
if (!strcmp(p_drv->driver_name, periph_conf->periph_name) dname = resource_query_name(i);
&& IS_SPECIFIED(periph_conf->periph_unit)) { dunit = resource_query_unit(i);
if (resource_string_value(dname, dunit, "at", &strval) == 0) {
if (IS_SPECIFIED(periph_conf->pathid)) { if (strcmp(strval, pathbuf) != 0)
continue;
if (pathid != periph_conf->pathid) hit++;
continue; }
hit++; if (resource_int_value(dname, dunit, "target", &val) == 0) {
} if (val != target)
continue;
if (IS_SPECIFIED(periph_conf->target)) { hit++;
}
if (target != periph_conf->target) if (resource_int_value(dname, dunit, "lun", &val) == 0) {
continue; if (val != lun)
hit++; continue;
} hit++;
}
if (IS_SPECIFIED(periph_conf->lun)) { if (hit != 0) {
unit = dunit;
if (lun != periph_conf->lun) break;
continue;
hit++;
}
if (hit != 0) {
unit = periph_conf->periph_unit;
break;
}
} }
} }
/* /*
* Either start from 0 looking for the next unit or from * Either start from 0 looking for the next unit or from
* the unit number given in the periph_conf. This way, * the unit number given in the resource config. This way,
* if we have wildcard matches, we don't return the same * if we have wildcard matches, we don't return the same
* unit number twice. * unit number twice.
*/ */

View File

@ -39,6 +39,7 @@
#include <sys/md5.h> #include <sys/md5.h>
#include <sys/devicestat.h> #include <sys/devicestat.h>
#include <sys/interrupt.h> #include <sys/interrupt.h>
#include <sys/bus.h>
#ifdef PC98 #ifdef PC98
#include <pc98/pc98/pc98_machdep.h> /* geometry translation */ #include <pc98/pc98/pc98_machdep.h> /* geometry translation */
@ -48,7 +49,6 @@
#include <machine/ipl.h> #include <machine/ipl.h>
#include <cam/cam.h> #include <cam/cam.h>
#include <cam/cam_conf.h>
#include <cam/cam_ccb.h> #include <cam/cam_ccb.h>
#include <cam/cam_periph.h> #include <cam/cam_periph.h>
#include <cam/cam_sim.h> #include <cam/cam_sim.h>
@ -4088,7 +4088,7 @@ xptnextfreepathid(void)
{ {
struct cam_eb *bus; struct cam_eb *bus;
path_id_t pathid; path_id_t pathid;
struct cam_sim_config *sim_conf; char *strval;
pathid = 0; pathid = 0;
bus = TAILQ_FIRST(&xpt_busses); bus = TAILQ_FIRST(&xpt_busses);
@ -4105,17 +4105,10 @@ xptnextfreepathid(void)
* Ensure that this pathid is not reserved for * Ensure that this pathid is not reserved for
* a bus that may be registered in the future. * a bus that may be registered in the future.
*/ */
sim_conf = cam_sinit; if (resource_string_value("scbus", pathid, "at", &strval) == 0) {
while (sim_conf->sim_name != NULL) { ++pathid;
/* Start the search over */
if (IS_SPECIFIED(sim_conf->pathid) goto retry;
&& (pathid == sim_conf->pathid)) {
++pathid;
/* Start the search over */
goto retry;
} else {
sim_conf++;
}
} }
return (pathid); return (pathid);
} }
@ -4123,37 +4116,38 @@ xptnextfreepathid(void)
static path_id_t static path_id_t
xptpathid(const char *sim_name, int sim_unit, int sim_bus) xptpathid(const char *sim_name, int sim_unit, int sim_bus)
{ {
struct cam_sim_config *sim_conf;
path_id_t pathid; path_id_t pathid;
int i, dunit, val;
char buf[32], *strval;
pathid = CAM_XPT_PATH_ID; pathid = CAM_XPT_PATH_ID;
for (sim_conf = cam_sinit; sim_conf->sim_name != NULL; sim_conf++) { snprintf(buf, sizeof(buf), "%s%d", sim_name, sim_unit);
i = -1;
if (!IS_SPECIFIED(sim_conf->pathid)) while ((i = resource_locate(i, "scbus")) != -1) {
dunit = resource_query_unit(i);
if (dunit < 0) /* unwired?! */
continue; continue;
if (resource_string_value("scbus", dunit, "at", &strval) != 0)
if (!strcmp(sim_name, sim_conf->sim_name) continue;
&& (sim_unit == sim_conf->sim_unit)) { if (strcmp(buf, strval) != 0)
continue;
if (IS_SPECIFIED(sim_conf->sim_bus)) { if (resource_int_value("scbus", dunit, "bus", &val) == 0) {
if (sim_bus == sim_conf->sim_bus) { if (sim_bus == val) {
pathid = sim_conf->pathid; pathid = dunit;
break;
}
} else if (sim_bus == 0) {
/* Unspecified matches bus 0 */
pathid = sim_conf->pathid;
break; break;
} else {
printf("Ambiguous scbus configuration for %s%d "
"bus %d, cannot wire down. The kernel "
"config entry for scbus%d should "
"specify a controller bus.\n"
"Scbus will be assigned dynamically.\n",
sim_name, sim_unit, sim_bus,
sim_conf->pathid);
break;
} }
} else if (sim_bus == 0) {
/* Unspecified matches bus 0 */
pathid = dunit;
break;
} else {
printf("Ambiguous scbus configuration for %s%d "
"bus %d, cannot wire down. The kernel "
"config entry for scbus%d should "
"specify a controller bus.\n"
"Scbus will be assigned dynamically.\n",
sim_name, sim_unit, sim_bus, dunit);
break;
} }
} }