Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Nov 2019 00:52:58 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r354782 - stable/11/sys/cam/ctl
Message-ID:  <201911170052.xAH0qwod070777@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sun Nov 17 00:52:58 2019
New Revision: 354782
URL: https://svnweb.freebsd.org/changeset/base/354782

Log:
  MFC r354268: Remove lock from CTL camsim frontend.
  
  CAM does not need a SIM lock for quite a while, and CTL never needed it.

Modified:
  stable/11/sys/cam/ctl/ctl_frontend_cam_sim.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/cam/ctl/ctl_frontend_cam_sim.c
==============================================================================
--- stable/11/sys/cam/ctl/ctl_frontend_cam_sim.c	Sun Nov 17 00:52:23 2019	(r354781)
+++ stable/11/sys/cam/ctl/ctl_frontend_cam_sim.c	Sun Nov 17 00:52:58 2019	(r354782)
@@ -44,12 +44,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/kernel.h>
 #include <sys/types.h>
 #include <sys/malloc.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/condvar.h>
-#include <sys/queue.h>
 #include <sys/bus.h>
 #include <sys/sysctl.h>
+#include <machine/atomic.h>
 #include <machine/bus.h>
 #include <sys/sbuf.h>
 
@@ -78,7 +75,6 @@ struct cfcs_softc {
 	struct cam_sim *sim;
 	struct cam_devq *devq;
 	struct cam_path *path;
-	struct mtx lock;
 	uint64_t wwnn;
 	uint64_t wwpn;
 	uint32_t cur_tag_num;
@@ -133,7 +129,6 @@ cfcs_init(void)
 
 	softc = &cfcs_softc;
 	bzero(softc, sizeof(*softc));
-	mtx_init(&softc->lock, "ctl2cam", NULL, MTX_DEF);
 	port = &softc->port;
 
 	port->frontend = &cfcs_frontend;
@@ -158,7 +153,6 @@ cfcs_init(void)
 	if (retval != 0) {
 		printf("%s: ctl_port_register() failed with error %d!\n",
 		       __func__, retval);
-		mtx_destroy(&softc->lock);
 		return (retval);
 	}
 
@@ -180,7 +174,6 @@ cfcs_init(void)
 		softc->wwpn = port->wwpn;
 	}
 
-	mtx_lock(&softc->lock);
 	softc->devq = cam_simq_alloc(port->num_requested_ctl_io);
 	if (softc->devq == NULL) {
 		printf("%s: error allocating devq\n", __func__);
@@ -189,7 +182,7 @@ cfcs_init(void)
 	}
 
 	softc->sim = cam_sim_alloc(cfcs_action, cfcs_poll, softc->port_name,
-				   softc, /*unit*/ 0, &softc->lock, 1,
+				   softc, /*unit*/ 0, NULL, 1,
 				   port->num_requested_ctl_io, softc->devq);
 	if (softc->sim == NULL) {
 		printf("%s: error allocating SIM\n", __func__);
@@ -213,8 +206,6 @@ cfcs_init(void)
 		goto bailout;
 	}
 
-	mtx_unlock(&softc->lock);
-
 	return (retval);
 
 bailout:
@@ -222,9 +213,6 @@ bailout:
 		cam_sim_free(softc->sim, /*free_devq*/ TRUE);
 	else if (softc->devq)
 		cam_simq_free(softc->devq);
-	mtx_unlock(&softc->lock);
-	mtx_destroy(&softc->lock);
-
 	return (retval);
 }
 
@@ -237,12 +225,9 @@ cfcs_shutdown(void)
 
 	ctl_port_offline(port);
 
-	mtx_lock(&softc->lock);
 	xpt_free_path(softc->path);
 	xpt_bus_deregister(cam_sim_path(softc->sim));
 	cam_sim_free(softc->sim, /*free_devq*/ TRUE);
-	mtx_unlock(&softc->lock);
-	mtx_destroy(&softc->lock);
 
 	if ((error = ctl_port_deregister(port)) != 0)
 		printf("%s: cam_sim port deregistration failed\n", __func__);
@@ -258,18 +243,15 @@ cfcs_poll(struct cam_sim *sim)
 static void
 cfcs_onoffline(void *arg, int online)
 {
-	struct cfcs_softc *softc;
+	struct cfcs_softc *softc = (struct cfcs_softc *)arg;
 	union ccb *ccb;
 
-	softc = (struct cfcs_softc *)arg;
-
-	mtx_lock(&softc->lock);
 	softc->online = online;
 
 	ccb = xpt_alloc_ccb_nowait();
 	if (ccb == NULL) {
 		printf("%s: unable to allocate CCB for rescan\n", __func__);
-		goto bailout;
+		return;
 	}
 
 	if (xpt_create_path(&ccb->ccb_h.path, NULL,
@@ -277,12 +259,9 @@ cfcs_onoffline(void *arg, int online)
 			    CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
 		printf("%s: can't allocate path for rescan\n", __func__);
 		xpt_free_ccb(ccb);
-		goto bailout;
+		return;
 	}
 	xpt_rescan(ccb);
-
-bailout:
-	mtx_unlock(&softc->lock);
 }
 
 static void
@@ -496,13 +475,13 @@ cfcs_done(union ctl_io *io)
 		ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
 		break;
 	}
+	ctl_free_io(io);
 	if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP &&
 	    (ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
 		xpt_freeze_devq(ccb->ccb_h.path, 1);
 		ccb->ccb_h.status |= CAM_DEV_QFRZN;
 	}
 	xpt_done(ccb);
-	ctl_free_io(io);
 }
 
 void
@@ -512,7 +491,6 @@ cfcs_action(struct cam_sim *sim, union ccb *ccb)
 	int err;
 
 	softc = (struct cfcs_softc *)cam_sim_softc(sim);
-	mtx_assert(&softc->lock, MA_OWNED);
 
 	switch (ccb->ccb_h.func_code) {
 	case XPT_SCSI_IO: {
@@ -572,7 +550,7 @@ cfcs_action(struct cam_sim *sim, union ccb *ccb)
 		 * enough for now.  Since we're using unsigned ints,
 		 * they'll just wrap around.
 		 */
-		io->scsiio.tag_num = softc->cur_tag_num++;
+		io->scsiio.tag_num = atomic_fetchadd_32(&softc->cur_tag_num, 1);
 		csio->tag_id = io->scsiio.tag_num;
 		switch (csio->tag_action) {
 		case CAM_TAG_ACTION_NONE:
@@ -778,13 +756,13 @@ cfcs_action(struct cam_sim *sim, union ccb *ccb)
 		cpi->target_sprt = 0;
 		cpi->hba_misc = PIM_EXTLUNS;
 		cpi->hba_eng_cnt = 0;
-		cpi->max_target = 1;
+		cpi->max_target = 0;
 		cpi->max_lun = 1024;
 		/* Do we really have a limit? */
 		cpi->maxio = 1024 * 1024;
 		cpi->async_flags = 0;
 		cpi->hpath_id = 0;
-		cpi->initiator_id = 0;
+		cpi->initiator_id = 1;
 
 		strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
 		strlcpy(cpi->hba_vid, "FreeBSD", HBA_IDLEN);



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