From nobody Fri Dec 24 01:16:28 2021 X-Original-To: dev-commits-src-all@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 1792C190DC14; Fri, 24 Dec 2021 01:16:29 +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 4JKpzw3dhvz3CSV; Fri, 24 Dec 2021 01:16:28 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 463A21A8E7; Fri, 24 Dec 2021 01:16:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BO1GSuS030793; Fri, 24 Dec 2021 01:16:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BO1GSb1030792; Fri, 24 Dec 2021 01:16:28 GMT (envelope-from git) Date: Fri, 24 Dec 2021 01:16:28 GMT Message-Id: <202112240116.1BO1GSb1030792@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 4fd804ef6631 - stable/13 - ahci(4): Allow enclosure emulation without hardware. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4fd804ef66312e5b3a327871478b69ee042b0d9e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640308588; 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=u2Ag68sn0Q6lRQd0epMRZqhr9C5AIEqpjJwyqH2z2hY=; b=dBoudWR72Rxj6MJbk+sacHo0xwYljzgx7vLdkBJsDbmRIJLmFYvjT78sx+ROfmQGS/bhH9 7TxcSlr54j2PpTdVdUJclkfSNVxwQs1KFIxJCSgf0/LI9JE652EaB2jofiO0/bUXChWPRQ ubhjte09bNEG/M7rh9IaoRo3mtt3e3A987YDw8KtK3F8LmBuUS6pMeBwuM4zkNQvkdSfga Miv3EBp/cKe1QXgw+cJy/t1CkGFmvEXNX7dkz0DXk/r8wPpKY++96pa4QLNCwyVinvNPKG bIkz88IjbpIWx6EBB4gSV2M3PPcD2VZQcfdNJ8Bq+sll5Km8FtPtRPNXp4CiyA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640308588; a=rsa-sha256; cv=none; b=A3Gse3whnWxcJZ4MQ5gg7Y+2e64mGi/9UR+RVdwMvHayMT3367kn0RJNYzzLysmTY0Mjs4 +IHYkBgxfh7/6sNQ1sX70SBjKMV9uIlrnxULSuiw1l1oKx9JZS6QwxS54BctZrt7NwdHE+ Q8yg4g/5X6ZjFrGbDdQ0ev5hgkhJ7uP65U9Ecg20DheVhBatoTfcvdF9ORTpmE2GfJHWEW S80A19a0m7c867glzE9YV7r1FcCO09a6bHSNHvuex1qe3urlA9H8/z9aDKVk/wkQ4YSjUn PkhkFpaqYiBPpSgMxWeUVbJzp/bMiVoMWaZ+R0TU6qxkSbLR9mcduUnXwVLA/Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=4fd804ef66312e5b3a327871478b69ee042b0d9e commit 4fd804ef66312e5b3a327871478b69ee042b0d9e Author: Alexander Motin AuthorDate: 2021-12-17 20:24:56 +0000 Commit: Alexander Motin CommitDate: 2021-12-24 01:05:10 +0000 ahci(4): Allow enclosure emulation without hardware. After 53f5ac1310e allowed SATA device mapping to enclosure slots, it may have sense to provide enclosure device emulation even without real hardware interface like SGPIO just for purposes of physical device location tracking (still assuming straight cabling). MFC after: 1 week Sponsored by: iXsystems, Inc. (cherry picked from commit 9aba757e92aaf0751c83c0ce3f18f65f864f1811) --- share/man/man4/ahci.4 | 6 +++++- sys/dev/ahci/ahci.c | 7 ++++++- sys/dev/ahci/ahciem.c | 36 ++++++++++++++++++++++-------------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/share/man/man4/ahci.4 b/share/man/man4/ahci.4 index a7a70c6dd5bc..58b9fea7c838 100644 --- a/share/man/man4/ahci.4 +++ b/share/man/man4/ahci.4 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 21, 2019 +.Dd December 17, 2021 .Dt AHCI 4 .Os .Sh NAME @@ -73,6 +73,10 @@ controls whether the driver should use direct command completion from interrupt thread(s), or queue them to CAM completion threads. Default value depends on number of MSI interrupts supported and number of implemented SATA ports. +.It Va hint.ahci. Ns Ar X Ns Va .em +controls whether the driver should implement virtual enclosure management +device on top of SGPIO or other interface. +Default value depends on controller capabilities. .It Va hint.ahcich. Ns Ar X Ns Va .pm_level controls SATA interface Power Management for the specified channel, allowing some power to be saved at the cost of additional command diff --git a/sys/dev/ahci/ahci.c b/sys/dev/ahci/ahci.c index 054250d21668..c6cf273fdf0b 100644 --- a/sys/dev/ahci/ahci.c +++ b/sys/dev/ahci/ahci.c @@ -375,7 +375,10 @@ ahci_attach(device_t dev) device_set_ivars(child, (void *)(intptr_t)(unit | AHCI_REMAPPED_UNIT)); } - if (ctlr->caps & AHCI_CAP_EMS) { + int em = (ctlr->caps & AHCI_CAP_EMS) != 0; + resource_int_value(device_get_name(dev), device_get_unit(dev), + "em", &em); + if (em) { child = device_add_child(dev, "ahciem", -1); if (child == NULL) device_printf(dev, "failed to add enclosure device\n"); @@ -601,6 +604,8 @@ ahci_alloc_resource(device_t dev, device_t child, int type, int *rid, } else if (!is_em) { offset = AHCI_OFFSET + (unit << 7); size = 128; + } else if ((ctlr->caps & AHCI_CAP_EMS) == 0) { + break; } else if (*rid == 0) { offset = AHCI_EM_CTL; size = 4; diff --git a/sys/dev/ahci/ahciem.c b/sys/dev/ahci/ahciem.c index b1c3fbf1fdd4..20b36830ce9a 100644 --- a/sys/dev/ahci/ahciem.c +++ b/sys/dev/ahci/ahciem.c @@ -86,17 +86,18 @@ ahci_em_attach(device_t dev) enc->ichannels = ctlr->ichannels; mtx_init(&enc->mtx, "AHCI enclosure lock", NULL, MTX_DEF); rid = 0; - if (!(enc->r_memc = bus_alloc_resource_any(dev, SYS_RES_MEMORY, - &rid, RF_ACTIVE))) { - mtx_destroy(&enc->mtx); - return (ENXIO); - } - enc->capsem = ATA_INL(enc->r_memc, 0); - rid = 1; - if (!(enc->r_memt = bus_alloc_resource_any(dev, SYS_RES_MEMORY, - &rid, RF_ACTIVE))) { - error = ENXIO; - goto err0; + if ((enc->r_memc = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &rid, RF_ACTIVE)) != NULL) { + enc->capsem = ATA_INL(enc->r_memc, 0); + rid = 1; + if (!(enc->r_memt = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &rid, RF_ACTIVE))) { + error = ENXIO; + goto err0; + } + } else { + enc->capsem = AHCI_EM_XMT | AHCI_EM_SMB | AHCI_EM_LED; + enc->r_memt = NULL; } if ((enc->capsem & (AHCI_EM_XMT | AHCI_EM_SMB)) == 0) { rid = 2; @@ -194,7 +195,8 @@ err1: err0: if (enc->r_memt) bus_release_resource(dev, SYS_RES_MEMORY, 1, enc->r_memt); - bus_release_resource(dev, SYS_RES_MEMORY, 0, enc->r_memc); + if (enc->r_memc) + bus_release_resource(dev, SYS_RES_MEMORY, 0, enc->r_memc); mtx_destroy(&enc->mtx); return (error); } @@ -216,8 +218,10 @@ ahci_em_detach(device_t dev) cam_sim_free(enc->sim, /*free_devq*/TRUE); mtx_unlock(&enc->mtx); - bus_release_resource(dev, SYS_RES_MEMORY, 0, enc->r_memc); - bus_release_resource(dev, SYS_RES_MEMORY, 1, enc->r_memt); + if (enc->r_memc) + bus_release_resource(dev, SYS_RES_MEMORY, 0, enc->r_memc); + if (enc->r_memt) + bus_release_resource(dev, SYS_RES_MEMORY, 1, enc->r_memt); if (enc->r_memr) bus_release_resource(dev, SYS_RES_MEMORY, 2, enc->r_memr); mtx_destroy(&enc->mtx); @@ -231,6 +235,8 @@ ahci_em_reset(device_t dev) int i, timeout; enc = device_get_softc(dev); + if (enc->r_memc == NULL) + return (0); ATA_OUTL(enc->r_memc, 0, AHCI_EM_RST); timeout = 1000; while ((ATA_INL(enc->r_memc, 0) & AHCI_EM_RST) && @@ -292,6 +298,8 @@ ahci_em_setleds(device_t dev, int c) int16_t val; enc = device_get_softc(dev); + if (enc->r_memc == NULL) + return; val = 0; if (enc->status[c][2] & SESCTL_RQSACT) /* Activity */