PERFORCE change 54290 for review

Scott Long scottl at FreeBSD.org
Mon Jun 7 04:35:31 GMT 2004


http://perforce.freebsd.org/chv.cgi?CH=54290

Change 54290 by scottl at scottl-esp-sparc64 on 2004/06/07 04:34:52

	Change ncr53c9x_attach() to return an int so that it can pass
	up error codes.
	Use time_second for getting the approximate time
	Add some CAM includes
	Convert ncr53c9x_attach() to do the CAM thing.  Disable
	ncr53c9x_detach() for now.

Affected files ...

.. //depot/projects/scottl-esp/src/sys/dev/esp/ncr53c9x.c#7 edit
.. //depot/projects/scottl-esp/src/sys/dev/esp/ncr53c9xvar.h#6 edit

Differences ...

==== //depot/projects/scottl-esp/src/sys/dev/esp/ncr53c9x.c#7 (text+ko) ====

@@ -87,11 +87,16 @@
 #include <sys/lock.h>
 #include <sys/mutex.h>
 #include <sys/queue.h>
+#include <sys/time.h>
 #include <vm/uma.h>
 
 #include <cam/cam.h>
 #include <cam/cam_ccb.h>
+#include <cam/cam_debug.h>
+#include <cam/cam_sim.h>
+#include <cam/cam_xpt_sim.h>
 #include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_message.h>
 
 #include <dev/esp/ncr53c9xreg.h>
 #include <dev/esp/ncr53c9xvar.h>
@@ -104,7 +109,7 @@
 static void	ncr53c9x_select(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
 static int	ncr53c9x_reselect(struct ncr53c9x_softc *, int, int, int);
 static void	ncr53c9x_scsi_reset(struct ncr53c9x_softc *);
-static int	ncr53c9x_poll(struct cam_sim *);
+static void	ncr53c9x_poll(struct cam_sim *);
 static void	ncr53c9x_sched(struct ncr53c9x_softc *);
 static void	ncr53c9x_done(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
 static void	ncr53c9x_msgin(struct ncr53c9x_softc *);
@@ -184,14 +189,14 @@
 /*
  * Attach this instance, and then all the sub-devices
  */
-void
-ncr53c9x_attach(sc)
-	struct ncr53c9x_softc *sc;
+int
+ncr53c9x_attach(struct ncr53c9x_softc *sc)
 {
-	struct scsipi_adapter *adapt = &sc->sc_adapter;
-	struct scsipi_channel *chan = &sc->sc_channel;
+	struct cam_devq *devq;
+	struct cam_sim *sim;
+	struct cam_path *path;
 
-	mtx_init(&sc->sc_lock, "ncr" "ncr53c9x lock", MTX_DEF);
+	mtx_init(&sc->sc_lock, "ncr", "ncr53c9x lock", MTX_DEF);
 	sc->dv_name = device_get_nameunit(sc->sc_dev);
 
 	/*
@@ -200,7 +205,7 @@
 	if (sc->sc_rev >= NCR_VARIANT_MAX) {
 		printf("\n%s: unknown variant %d, devices not attached\n",
 		    sc->dv_name, sc->sc_rev);
-		return;
+		return (EINVAL);
 	}
 
 	printf(": %s, %dMHz, SCSI ID %d\n",
@@ -225,7 +230,7 @@
 
 	if (!sc->sc_omess || !sc->sc_imess || !sc->sc_tinfo) {
 		printf("out of memory\n");
-		return;
+		return (ENOMEM);
 	}
 
 	callout_init(&sc->sc_watchdog, 0);
@@ -260,48 +265,42 @@
 	sc->sc_ccf &= 7;
 
 	/*
-	 * Fill in the scsipi_adapter.
+	 * Register with CAM
 	 */
-	adapt->adapt_dev = &sc->sc_dev;
-	adapt->adapt_nchannels = 1;
-	adapt->adapt_openings = 256;
-	adapt->adapt_max_periph = 256;
-	/* adapt_request initialized by front-end */
-	/* adapt_minphys initialized by front-end */
+	devq = cam_simq_alloc(sc->sc_ntarg);
+	if (devq == NULL)
+		return (ENOMEM);
 
-	/*
-	 * Fill in the scsipi_channel.
-	 */
-	memset(chan, 0, sizeof(*chan));
-	chan->chan_adapter = adapt;
-	chan->chan_bustype = &scsi_bustype;
-	chan->chan_channel = 0;
-	chan->chan_ntargets = sc->sc_ntarg;
-	chan->chan_nluns = 8;
-	chan->chan_id = sc->sc_id;
+	sim = cam_sim_alloc(ncr53c9x_action, ncr53c9x_poll, "esp", sc,
+			    device_get_unit(sc->sc_dev), 256, 1, devq);
+	if (sim == NULL) {
+		cam_simq_free(devq);
+		return (ENOMEM);
+	}
+	if (xpt_bus_register(sim, 0) != CAM_SUCCESS) {
+		cam_sim_free(sim, TRUE);
+		return (EIO);
+	}
 
-	/*
-	 * Add reference to adapter so that we drop the reference after
-	 * config_found() to make sure the adatper is disabled.
-	 */
-	if (scsipi_adapter_addref(adapt) != 0) {
-		printf("%s: unable to enable controller\n",
-		    sc->dv_name);
-		return;
+	if (xpt_create_path(&path, NULL, cam_sim_path(sim),
+			    CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD)
+			    != CAM_REQ_CMP) {
+		xpt_bus_deregister(cam_sim_path(sim));
+		cam_sim_free(sim, TRUE);
+		return (EIO);
 	}
 
+	sc->sc_sim = sim;
+	sc->sc_path = path;
+
 	/* Reset state & bus */
 	sc->sc_cfflags = sc->sc_dev.dv_cfdata->cf_flags;
 	sc->sc_state = 0;
 	ncr53c9x_init(sc, 1);
 
-	/*
-	 * Now try to attach all the sub-devices
-	 */
-	sc->sc_child = config_found(&sc->sc_dev, &sc->sc_channel, scsiprint);
+	callout_reset(&sc->sc_watchdog, 60*hz, ncr53c9x_watch, sc);
 
-	scsipi_adapter_delref(adapt);
-	callout_reset(&sc->sc_watchdog, 60*hz, ncr53c9x_watch, sc);
+	return (0);
 }
 
 int
@@ -309,18 +308,13 @@
 	struct ncr53c9x_softc *sc;
 	int flags;
 {
-	int error;
 
-	if (sc->sc_child) {
-		error = config_detach(sc->sc_child, flags);
-		if (error)
-			return (error);
-	}
-
+#if 0	/* don't allow detach for now */
 	free(sc->sc_imess, M_DEVBUF);
 	free(sc->sc_omess, M_DEVBUF);
+#endif
 
-	return (0);
+	return (EINVAL);
 }
 
 /*
@@ -1033,7 +1027,7 @@
 			if (lun < NCR_NLUN)
 				ti->lun[lun] = li;
 		}
-		li->last_used = time.tv_sec;
+		li->last_used = time_second;
 		if (tag == 0) {
 			/* Try to issue this as an un-tagged command */
 			if (li->untagged == NULL)
@@ -2866,7 +2860,7 @@
 	struct ncr53c9x_linfo *li;
 	int t;
 	/* Delete any structures that have not been used in 10min. */
-	time_t old = time.tv_sec - (10 * 60);
+	time_t old = time_second - (10 * 60);
 
 	mtx_lock(&sc->sc_lock);
 	for (t = 0; t < sc->sc_ntarg; t++) {

==== //depot/projects/scottl-esp/src/sys/dev/esp/ncr53c9xvar.h#6 (text+ko) ====

@@ -272,11 +272,8 @@
 	device_t sc_dev;			/* us as a device */
 	char *dv_name;
 
-	struct cam_sim	*sim;			/* our scsi adapter */
-	struct cam_path	*path;			/* our scsi channel */
-#if 0
-	struct device *sc_child;		/* attached scsibus, if any */
-#endif
+	struct cam_sim	*sc_sim;		/* our scsi adapter */
+	struct cam_path	*sc_path;		/* our scsi channel */
 	struct callout sc_watchdog;		/* periodic timer */
 
 	struct ncr53c9x_glue *sc_glue;		/* glue to MD code */
@@ -445,7 +442,7 @@
 #define	ncr53c9x_cpb2stp(sc, cpb)	\
 	((250 * (cpb)) / (sc)->sc_freq)
 
-void	ncr53c9x_attach(struct ncr53c9x_softc *);
+int	ncr53c9x_attach(struct ncr53c9x_softc *);
 int	ncr53c9x_detach(struct ncr53c9x_softc *, int);
 void	ncr53c9x_action(struct cam_sim *, union ccb *);
 void	ncr53c9x_reset(struct ncr53c9x_softc *);


More information about the p4-projects mailing list