From owner-svn-src-stable@freebsd.org Mon Mar 6 06:25:34 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E59EACFAA38; Mon, 6 Mar 2017 06:25:34 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A530B1C1F; Mon, 6 Mar 2017 06:25:34 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v266PXDQ095145; Mon, 6 Mar 2017 06:25:33 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v266PXPA095144; Mon, 6 Mar 2017 06:25:33 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201703060625.v266PXPA095144@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 6 Mar 2017 06:25:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r314738 - stable/11/sys/cam/ctl X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Mar 2017 06:25:35 -0000 Author: mav Date: Mon Mar 6 06:25:33 2017 New Revision: 314738 URL: https://svnweb.freebsd.org/changeset/base/314738 Log: MFC r314196: Unify ATIO/INOT CCBs requeuing. Modified: stable/11/sys/cam/ctl/scsi_ctl.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/cam/ctl/scsi_ctl.c ============================================================================== --- stable/11/sys/cam/ctl/scsi_ctl.c Mon Mar 6 06:24:53 2017 (r314737) +++ stable/11/sys/cam/ctl/scsi_ctl.c Mon Mar 6 06:25:33 2017 (r314738) @@ -210,6 +210,10 @@ static void ctlfe_dump_queue(struct ctl static void ctlfe_datamove(union ctl_io *io); static void ctlfe_done(union ctl_io *io); static void ctlfe_dump(void); +static void ctlfe_free_ccb(struct cam_periph *periph, + union ccb *ccb); +static void ctlfe_requeue_ccb(struct cam_periph *periph, + union ccb *ccb, int unlock); static struct periph_driver ctlfe_driver = { @@ -808,6 +812,7 @@ ctlfestart(struct cam_periph *periph, un softc = (struct ctlfe_lun_softc *)periph->softc; softc->ccbs_alloced++; +next: ccb_h = TAILQ_FIRST(&softc->work_queue); if (ccb_h == NULL) { softc->ccbs_freed++; @@ -851,26 +856,12 @@ ctlfestart(struct cam_periph *periph, un start_ccb->ccb_h.func_code = XPT_ABORT; start_ccb->cab.abort_ccb = (union ccb *)atio; xpt_action(start_ccb); - softc->ccbs_freed++; - xpt_release_ccb(start_ccb); - /* - * Send the ATIO back down to the SIM. - * For a wildcard attachment, commands can come in - * with a specific target/lun. Reset the target and - * LUN fields back to the wildcard values before we - * send them back down to the SIM. - */ - if (softc->flags & CTLFE_LUN_WILDCARD) { - atio->ccb_h.target_id = CAM_TARGET_WILDCARD; - atio->ccb_h.target_lun = CAM_LUN_WILDCARD; - } - xpt_action((union ccb *)atio); + ctlfe_requeue_ccb(periph, (union ccb *)atio, + /* unlock */0); - /* If we still have work to do, ask for another CCB. */ - if (!TAILQ_EMPTY(&softc->work_queue)) - xpt_schedule(periph, /*priority*/ 1); - return; + /* XPT_ABORT is not queued, so we can take next I/O. */ + goto next; } data_ptr = NULL; dxfer_len = 0; @@ -1003,6 +994,37 @@ ctlfe_free_ccb(struct cam_periph *periph } } +/* + * Send the ATIO/INOT back to the SIM, or free it if periph was invalidated. + */ +static void +ctlfe_requeue_ccb(struct cam_periph *periph, union ccb *ccb, int unlock) +{ + struct ctlfe_lun_softc *softc; + + if (periph->flags & CAM_PERIPH_INVALID) { + ctlfe_free_ccb(periph, ccb); + if (unlock) + cam_periph_unlock(periph); + return; + } + if (unlock) + cam_periph_unlock(periph); + + /* + * For a wildcard attachment, commands can come in with a specific + * target/lun. Reset the target and LUN fields back to the wildcard + * values before we send them back down to the SIM. + */ + softc = (struct ctlfe_lun_softc *)periph->softc; + if (softc->flags & CTLFE_LUN_WILDCARD) { + ccb->ccb_h.target_id = CAM_TARGET_WILDCARD; + ccb->ccb_h.target_lun = CAM_LUN_WILDCARD; + } + + xpt_action(ccb); +} + static int ctlfe_adjust_cdb(struct ccb_accept_tio *atio, uint32_t offset) { @@ -1266,25 +1288,9 @@ ctlfedone(struct cam_periph *periph, uni if ((io->io_hdr.flags & CTL_FLAG_DMA_INPROG) == 0) { softc->ccbs_freed++; xpt_release_ccb(done_ccb); - /* - * For a wildcard attachment, commands can come in - * with a specific target/lun. Reset the target - * and LUN fields back to the wildcard values before - * we send them back down to the SIM. The SIM has - * a wildcard LUN enabled, not whatever target/lun - * these happened to be. - */ - if (softc->flags & CTLFE_LUN_WILDCARD) { - atio->ccb_h.target_id = CAM_TARGET_WILDCARD; - atio->ccb_h.target_lun = CAM_LUN_WILDCARD; - } - if (periph->flags & CAM_PERIPH_INVALID) { - ctlfe_free_ccb(periph, (union ccb *)atio); - } else { - mtx_unlock(mtx); - xpt_action((union ccb *)atio); - return; - } + ctlfe_requeue_ccb(periph, (union ccb *)atio, + /* unlock */1); + return; } else { struct ctlfe_cmd_info *cmd_info; struct ccb_scsiio *csio; @@ -1489,18 +1495,11 @@ ctlfedone(struct cam_periph *periph, uni break; } case XPT_NOTIFY_ACKNOWLEDGE: - if (periph->flags & CAM_PERIPH_INVALID) { - ctlfe_free_ccb(periph, done_ccb); - goto out; - } - - /* - * Queue this back down to the SIM as an immediate notify. - */ + /* Queue this back down to the SIM as an immediate notify. */ done_ccb->ccb_h.status = CAM_REQ_INPROG; done_ccb->ccb_h.func_code = XPT_IMMEDIATE_NOTIFY; - xpt_action(done_ccb); - break; + ctlfe_requeue_ccb(periph, done_ccb, /* unlock */1); + return; case XPT_SET_SIM_KNOB: case XPT_GET_SIM_KNOB: case XPT_GET_SIM_KNOB_OLD: @@ -2004,17 +2003,8 @@ ctlfe_done(union ctl_io *io) ccb->cna2.arg |= scsi_3btoul(io->taskio.task_resp) << 8; xpt_action(ccb); } else if (io->io_hdr.flags & CTL_FLAG_STATUS_SENT) { - if (softc->flags & CTLFE_LUN_WILDCARD) { - ccb->ccb_h.target_id = CAM_TARGET_WILDCARD; - ccb->ccb_h.target_lun = CAM_LUN_WILDCARD; - } - if (periph->flags & CAM_PERIPH_INVALID) { - ctlfe_free_ccb(periph, ccb); - } else { - cam_periph_unlock(periph); - xpt_action(ccb); - return; - } + ctlfe_requeue_ccb(periph, ccb, /* unlock */1); + return; } else { io->io_hdr.flags |= CTL_FLAG_STATUS_QUEUED; TAILQ_INSERT_TAIL(&softc->work_queue, &ccb->ccb_h,