From nobody Sun Apr 21 03:04:16 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VMYBT0fkTz5HGQ2; Sun, 21 Apr 2024 03:04:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VMYBT00PKz4Bfp; Sun, 21 Apr 2024 03:04:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713668657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sMKrgOEF+JS7E/7OGIF97bBKP5Ckht0lWiNSMeP6sjM=; b=ygN9GCLeq1U1ddO2+CN1TpNLHU5d53qM87+IDzn6qhUnMf+ZDMz6qhVGB4nCIyKb2GpMaC YQCcjR6+tiwpwc0z3WvDsXsOnDym2Tablg9sZiBqmKVjA3rE+/xtuDUShvUmRSWc5R/V3q m0HAgM5D2JbmYZcMp96aet0rozbezQ3BSBgkeL7rmEWs4Bc1mc17xOPFQLX3O+jr41BeHw JxpLEa8E18XVfJqq1Q84OMAUT/qquwt6k6aScaPtTcPtVwQvg1EhizQfg7P+5PEHJaeCOG t5Su8Nf32A9wFkEVScJiCPHu1c8Sq1yqHpTER6ZADFi46/wojF1bhNRgcZDdQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713668657; a=rsa-sha256; cv=none; b=XZDehT3J2AaFoeg7lR3dWHnDYL10J09SbpD7zYbRdptgWFA5LR9KgW2N/3P2YB54bxFK2V kfpEZ6GLuzt6r/mvVlvWmEGod4vL5pFWpF15h1pZD09j6Rkh1cpiRI2oIH8OH6rjw9+CWX 5uj7UEZ38cfXuXv2L8xgJQiVl13C12a6nob7sq0z0DnxJxLTomgisx94G1j13mWbdDmqgj KvNuFVDlmMpNf+D2IPruXdSvCdCHBi9BHOO9OsVjUAFNfhG6xgBUDgRiOSWHUGFhUOytHM Sh1HpNJxsawHFXsPkbvjRygtvoMutZjk5ML3/Vm36OZjqXU4ppIYjf/kU0WYlQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713668657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sMKrgOEF+JS7E/7OGIF97bBKP5Ckht0lWiNSMeP6sjM=; b=a30VoWzvRjSv7ypk/Dmr8rCjpG82YvrevH6Ux5zLXjPEv/5M5wyEjTdOZsUbuF+DgQh/+d /Dsl0s0m2frhFBB5O/40I1kBXY+wOvs994tPzZl1rOKofsGCtsD1ixbCGD3pjQT/J21pAU 0EEMpqfz5SR5qWDmwTd7IaUJLjDUc9tHCBLbbr1bE5VzYIm8vlDJu9FiQRvOzJECRM9R1z pSKBNPObBOl5niWE+x86zznjLo2HxQNeU1VezdXg6DNMxPDewswiOCFmsyldQJc1fIs2C2 LgtM8QfMjhOx4Y2LwM1gG/l7m67rYlMGclCKhRUpdIqpHAVv28FrN1aJ7YJa3Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VMYBS6Pz6z13v1; Sun, 21 Apr 2024 03:04:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43L34G8c097697; Sun, 21 Apr 2024 03:04:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43L34GOC097694; Sun, 21 Apr 2024 03:04:16 GMT (envelope-from git) Date: Sun, 21 Apr 2024 03:04:16 GMT Message-Id: <202404210304.43L34GOC097694@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 9dcf39575efb - main - ahc(4)/ahd(4): fix target mode on ARM List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9dcf39575efb2ff32f955d9e04e04af28d45d798 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=9dcf39575efb2ff32f955d9e04e04af28d45d798 commit 9dcf39575efb2ff32f955d9e04e04af28d45d798 Author: Kyle Evans AuthorDate: 2024-04-21 03:04:04 +0000 Commit: Kyle Evans CommitDate: 2024-04-21 03:04:04 +0000 ahc(4)/ahd(4): fix target mode on ARM One of the comments in ahc_execute_scb() notes that the CAM direction is actually w.r.t. the initiator. As a consequence, all of our sync ops end up being wrong because the direction is flipped from that of the transfer. Fix it to do proper invalidation and avoid spewing random garbage out on the SCSI bus. Reported and tested by: HP van Braam Reviewed by: imp, mav Differential Revision: https://reviews.freebsd.org/D44860 --- sys/dev/aic7xxx/aic79xx_osm.c | 35 +++++++++++++++++++++-------------- sys/dev/aic7xxx/aic7xxx_osm.c | 35 +++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/sys/dev/aic7xxx/aic79xx_osm.c b/sys/dev/aic7xxx/aic79xx_osm.c index df73b3fadfa4..4a1e3336fe5f 100644 --- a/sys/dev/aic7xxx/aic79xx_osm.c +++ b/sys/dev/aic7xxx/aic79xx_osm.c @@ -303,6 +303,25 @@ ahd_platform_intr(void *arg) ahd_unlock(ahd); } +static void +ahd_sync_ccb(struct ahd_softc *ahd, struct scb *scb, union ccb *ccb, bool post) +{ + bus_dmasync_op_t op; + uint32_t rdmask; + + if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) + rdmask = CAM_DIR_OUT; + else + rdmask = CAM_DIR_IN; + + if ((ccb->ccb_h.flags & CAM_DIR_MASK) == rdmask) + op = post ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_PREREAD; + else + op = post ? BUS_DMASYNC_POSTWRITE : BUS_DMASYNC_PREWRITE; + + bus_dmamap_sync(ahd->buffer_dmat, scb->dmamap, op); +} + /* * We have an scb which has been processed by the * adaptor, now we look to see how the operation @@ -324,13 +343,7 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb) callout_stop(&scb->io_timer); if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { - bus_dmasync_op_t op; - - if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) - op = BUS_DMASYNC_POSTREAD; - else - op = BUS_DMASYNC_POSTWRITE; - bus_dmamap_sync(ahd->buffer_dmat, scb->dmamap, op); + ahd_sync_ccb(ahd, scb, ccb, true); bus_dmamap_unload(ahd->buffer_dmat, scb->dmamap); } @@ -961,7 +974,6 @@ ahd_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments, scb->sg_count = 0; if (nsegments != 0) { void *sg; - bus_dmasync_op_t op; u_int i; /* Copy the segments into our SG list */ @@ -971,13 +983,8 @@ ahd_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments, /*last*/i == 1); dm_segs++; } - - if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) - op = BUS_DMASYNC_PREREAD; - else - op = BUS_DMASYNC_PREWRITE; - bus_dmamap_sync(ahd->buffer_dmat, scb->dmamap, op); + ahd_sync_ccb(ahd, scb, ccb, false); if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) { struct target_data *tdata; diff --git a/sys/dev/aic7xxx/aic7xxx_osm.c b/sys/dev/aic7xxx/aic7xxx_osm.c index 46c87defa3a5..04037773c528 100644 --- a/sys/dev/aic7xxx/aic7xxx_osm.c +++ b/sys/dev/aic7xxx/aic7xxx_osm.c @@ -302,6 +302,25 @@ ahc_platform_intr(void *arg) ahc_unlock(ahc); } +static void +ahc_sync_ccb(struct ahc_softc *ahc, struct scb *scb, union ccb *ccb, bool post) +{ + bus_dmasync_op_t op; + uint32_t rdmask; + + if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) + rdmask = CAM_DIR_OUT; + else + rdmask = CAM_DIR_IN; + + if ((ccb->ccb_h.flags & CAM_DIR_MASK) == rdmask) + op = post ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_PREREAD; + else + op = post ? BUS_DMASYNC_POSTWRITE : BUS_DMASYNC_PREWRITE; + + bus_dmamap_sync(ahc->buffer_dmat, scb->dmamap, op); +} + /* * We have an scb which has been processed by the * adaptor, now we look to see how the operation @@ -333,13 +352,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb) callout_stop(&scb->io_timer); if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { - bus_dmasync_op_t op; - - if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) - op = BUS_DMASYNC_POSTREAD; - else - op = BUS_DMASYNC_POSTWRITE; - bus_dmamap_sync(ahc->buffer_dmat, scb->dmamap, op); + ahc_sync_ccb(ahc, scb, ccb, true); bus_dmamap_unload(ahc->buffer_dmat, scb->dmamap); } @@ -943,7 +956,6 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments, if (nsegments != 0) { struct ahc_dma_seg *sg; bus_dma_segment_t *end_seg; - bus_dmasync_op_t op; end_seg = dm_segs + nsegments; @@ -968,12 +980,7 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments, */ scb->hscb->sgptr = aic_htole32(scb->sg_list_phys|SG_FULL_RESID); - if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) - op = BUS_DMASYNC_PREREAD; - else - op = BUS_DMASYNC_PREWRITE; - - bus_dmamap_sync(ahc->buffer_dmat, scb->dmamap, op); + ahc_sync_ccb(ahc, scb, ccb, false); if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) { struct target_data *tdata;