From nobody Thu Apr 25 04:00:44 2024 X-Original-To: dev-commits-src-branches@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 4VQ2Fn4z5Xz5JpkD; Thu, 25 Apr 2024 04:00:45 +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 4VQ2Fm4Y2nz4LgZ; Thu, 25 Apr 2024 04:00:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714017644; 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=56EPwbUl2upzR9hbJkgiys37T6ASDV+AUCXX6ysdezw=; b=jIz0hIdmAx47rdxR1mZshLI60AjLi108KY077/4IPtnWla84PNIuTnVntm84HwUhgQ1/tz Zn6MELnzze8NstupIxWd/2c/vYD+IcstV/AreGH2ZAPYJXnK2EZUfnkFFR4b9SIE4zrrdd 5ECN3L/RkTPfIbB+ipqXGLpBpSvwrG9GIaLQncLY/n66jo/DlUhIiuR8jfle4INbUCAaa0 I8c8wB0A0yKy6BEzw0YzTNNiFPw4YFyMDNuCJAX+gllemd7O5kGT6BmC0CnBIjlELM/bl0 7npR0/9HGJISO+KZ5qnn679Ix+dbWShdU/g0lV9pNkLhaKSmt/1mhkbY2QWOyA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714017644; a=rsa-sha256; cv=none; b=QOkY2h4Ebj/p50aV8pVr6y8Il+v+JRgA8TMiIgV2Nrz8P/6HsARZUNXMR/Y28lkA7msH+M U44eziNGZYjs//s+Ou3qD1j4rkfWhbBV4iSxLhyVVzyu5vrjEyRvTlMkMVobLvND5jnvD+ /vFJ0/6Zw3+A4Ur904qwVqRknHwNdrU5Y/25SMY1Jh9YNngHfYy3fKHhb4XfHhTr06TWQ4 J+jTgTcJ2wkQcyKNLwKqW0y1j86YUyV8RuxZoarAPeX6atgvM4PmMgZGggNmT110VITxEt yTNAlLDDqE2ZF3MiJs9tScypL3SzQPZXoRqnQNQeAa5Fe2Sa17mKQndSrV87tw== 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=1714017644; 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=56EPwbUl2upzR9hbJkgiys37T6ASDV+AUCXX6ysdezw=; b=YGo8oHYxNZcTMNQ09q7yrM7f6JolHI4TRAbx25J+YylEbOQj1AuIGyCOi4EXGPDwj+XYix OCRpd0iKVh7+Gv/mnTMccQu03s/eiIexqC3ZluySSqUF0MJTF5nDHOPYct2JYHdJUYdWKS hCQYlDKAHGqh2E8b18+Z9JoJYW52XsQhshTySTMpwLrGStgCHes5njQB8uKAqul9LKfpzE otbYCiGQb7MToZvh58uTKHY8LEpIbbSLknuziXyyftfM/yH9hLi9GPKDYNOfhgKhXWe5Jw hTR9kossjobCXRpPse7+GA0x7toQU36V8LR8E4/KKAaAZUc+a/OuPV0+4M2vaQ== 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 4VQ2Fm49FTzkX4; Thu, 25 Apr 2024 04:00:44 +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 43P40iE2056134; Thu, 25 Apr 2024 04:00:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43P40isB056131; Thu, 25 Apr 2024 04:00:44 GMT (envelope-from git) Date: Thu, 25 Apr 2024 04:00:44 GMT Message-Id: <202404250400.43P40isB056131@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: cef3d542b700 - stable/13 - ahc(4)/ahd(4): fix target mode on ARM List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: cef3d542b7009f7823f09cfd12ac671c0fbf87a7 Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=cef3d542b7009f7823f09cfd12ac671c0fbf87a7 commit cef3d542b7009f7823f09cfd12ac671c0fbf87a7 Author: Kyle Evans AuthorDate: 2024-04-21 03:04:04 +0000 Commit: Kyle Evans CommitDate: 2024-04-25 03:59:14 +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 (cherry picked from commit 9dcf39575efb2ff32f955d9e04e04af28d45d798) --- 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 c59770291786..d06a9c6e686b 100644 --- a/sys/dev/aic7xxx/aic79xx_osm.c +++ b/sys/dev/aic7xxx/aic79xx_osm.c @@ -302,6 +302,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 @@ -323,13 +342,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); } @@ -960,7 +973,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 */ @@ -970,13 +982,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 d2eb8528849a..d8d8115e5aab 100644 --- a/sys/dev/aic7xxx/aic7xxx_osm.c +++ b/sys/dev/aic7xxx/aic7xxx_osm.c @@ -303,6 +303,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 @@ -334,13 +353,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); } @@ -944,7 +957,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; @@ -969,12 +981,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;