Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Aug 2009 12:17:11 GMT
From:      Alexander Motin <mav@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 167667 for review
Message-ID:  <200908231217.n7NCHBIm059720@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=167667

Change 167667 by mav@mav_mavbook on 2009/08/23 12:17:02

	Some more ATA_CAM improvements.

Affected files ...

.. //depot/projects/scottl-camlock/src/sys/dev/ata/ata-all.c#27 edit

Differences ...

==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata-all.c#27 (text+ko) ====

@@ -59,6 +59,7 @@
 #include <cam/cam_debug.h>
 #endif
 
+#ifndef ATA_CAM
 /* device structure */
 static  d_ioctl_t       ata_ioctl;
 static struct cdevsw ata_cdevsw = {
@@ -67,15 +68,16 @@
 	.d_ioctl =      ata_ioctl,
 	.d_name =       "ata",
 };
+#endif
 
 /* prototypes */
 #ifndef ATA_CAM
 static void ata_boot_attach(void);
+static device_t ata_add_child(device_t, struct ata_device *, int);
 #else
 static void ataaction(struct cam_sim *sim, union ccb *ccb);
 static void atapoll(struct cam_sim *sim);
 #endif
-static device_t ata_add_child(device_t, struct ata_device *, int);
 static void ata_conn_event(void *, int);
 static void bswap(int8_t *, int);
 static void btrim(int8_t *, int);
@@ -277,8 +279,11 @@
 ata_conn_event(void *context, int dummy)
 {
     device_t dev = (device_t)context;
+    struct ata_channel *ch = device_get_softc(dev);
 
+    mtx_lock(&ch->state_mtx);
     ata_reinit(dev);
+    mtx_unlock(&ch->state_mtx);
 }
 
 int
@@ -286,6 +291,7 @@
 {
     struct ata_channel *ch = device_get_softc(dev);
     struct ata_request *request;
+#ifndef ATA_CAM
     device_t *children;
     int nchildren, i;
 
@@ -372,7 +378,23 @@
 
     /* kick off requests on the queue */
     ata_start(dev);
-    return 0;
+#else
+	if ((request = ch->running)) {
+		ch->running = NULL;
+		if (ch->state == ATA_ACTIVE)
+		    ch->state = ATA_IDLE;
+		callout_stop(&request->callout);
+		if (ch->dma.unload)
+		    ch->dma.unload(request);
+		request->result = ERESTART;
+		ata_cam_end_transaction(dev, request);
+	}
+	/* reset the controller HW, the channel and device(s) */
+	ATA_RESET(dev);
+	/* Tell the XPT about the event */
+	xpt_async(AC_BUS_RESET, ch->path, NULL);
+#endif
+	return(0);
 }
 
 int
@@ -384,6 +406,7 @@
     if (!dev || !(ch = device_get_softc(dev)))
 	return ENXIO;
 
+#ifndef ATA_CAM
     /* wait for the channel to be IDLE or detached before suspending */
     while (ch->r_irq) {
 	mtx_lock(&ch->state_mtx);
@@ -396,7 +419,8 @@
 	tsleep(ch, PRIBIO, "atasusp", hz/10);
     }
     ATA_LOCKING(dev, ATA_LF_UNLOCK);
-    return 0;
+#endif
+    return(0);
 }
 
 int
@@ -411,8 +435,10 @@
     /* reinit the devices, we dont know what mode/state they are in */
     error = ata_reinit(dev);
 
+#ifndef ATA_CAM
     /* kick off requests on the queue */
     ata_start(dev);
+#endif
     return error;
 }
 
@@ -482,6 +508,7 @@
 /*
  * device related interfaces
  */
+#ifndef ATA_CAM
 static int
 ata_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
 	  int32_t flag, struct thread *td)
@@ -563,6 +590,7 @@
     }
     return error;
 }
+#endif
 
 int
 ata_device_ioctl(device_t dev, u_long cmd, caddr_t data)
@@ -692,6 +720,7 @@
 /*
  * misc support functions
  */
+#ifndef ATA_CAM
 static device_t
 ata_add_child(device_t parent, struct ata_device *atadev, int unit)
 {
@@ -706,6 +735,7 @@
     }
     return child;
 }
+#endif
 
 int
 ata_getparam(struct ata_device *atadev, int init)
@@ -802,6 +832,7 @@
     return error;
 }
 
+#ifndef ATA_CAM
 int
 ata_identify(device_t dev)
 {
@@ -875,6 +906,7 @@
     mtx_unlock(&Giant);
     return 0;
 }
+#endif
 
 void
 ata_default_registers(device_t dev)
@@ -1263,7 +1295,7 @@
 void
 ata_cam_end_transaction(device_t dev, struct ata_request *request)
 {
-//	struct ata_channel *ch = device_get_softc(dev);
+	struct ata_channel *ch = device_get_softc(dev);
 	union ccb *ccb = request->ccb;
 
 	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
@@ -1276,10 +1308,16 @@
 			ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
 			ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
 		}
-	} else if (request->result != 0)
+	} else if (request->result == ERESTART)
+		ccb->ccb_h.status |= CAM_REQUEUE_REQ;
+	else if (request->result != 0)
 		ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
 	else
 		ccb->ccb_h.status |= CAM_REQ_CMP;
+	if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
+		xpt_freeze_simq(ch->sim, 1);
+		ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
+	}
 	if (ccb->ccb_h.func_code == XPT_ATA_IO &&
 	    ((request->status & ATA_S_ERROR) ||
 	    (ccb->ataio.cmd.flags & CAM_ATAIO_NEEDRESULT))) {
@@ -1321,6 +1359,8 @@
 			xpt_done(ccb);
 			break;
 		}
+		if (ch->running)
+			device_printf(dev, "already running!\n");
 		if (ccb->ccb_h.func_code == XPT_ATA_IO &&
 		    (ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) &&
 		    (ccb->ataio.cmd.control & ATA_A_RESET)) {
@@ -1401,8 +1441,7 @@
 #endif
 	case XPT_RESET_BUS:		/* Reset the specified SCSI bus */
 	case XPT_RESET_DEV:	/* Bus Device Reset the specified SCSI device */
-		ATA_RESET(dev);
-		xpt_async(AC_BUS_RESET, ch->path, NULL);
+		ata_reinit(dev);
 		ccb->ccb_h.status = CAM_REQ_CMP;
 		xpt_done(ccb);
 		break;
@@ -1460,14 +1499,16 @@
 static int
 ata_module_event_handler(module_t mod, int what, void *arg)
 {
+#ifndef ATA_CAM
     static struct cdev *atacdev;
+#endif
 
     switch (what) {
     case MOD_LOAD:
+#ifndef ATA_CAM
 	/* register controlling device */
 	atacdev = make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "ata");
 
-#ifndef ATA_CAM
 	if (cold) {
 	    /* register boot attach to be run when interrupts are enabled */
 	    if (!(ata_delayed_attach = (struct intr_config_hook *)
@@ -1486,8 +1527,10 @@
 	return 0;
 
     case MOD_UNLOAD:
+#ifndef ATA_CAM
 	/* deregister controlling device */
 	destroy_dev(atacdev);
+#endif
 	return 0;
 
     default:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908231217.n7NCHBIm059720>