From nobody Fri Jan 21 07:02:18 2022 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 B7434195E6FC; Fri, 21 Jan 2022 07:02:18 +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 4Jg9L23wqSz4fTX; Fri, 21 Jan 2022 07:02:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642748538; 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=I8Of+BVVuwt04+K99Y2Jyw8hPpY5EWzsMKgTSOQXlFw=; b=nW4ZYZCHB0ZPIYQiSDH9kOZo1CaXplWfQZ4L4K3/ZM6CIZY8Z5OIOzriPmIgdaliUw7fDm aEWcEiODydlgeh6KoeiaUUal5z4aRGOKgxR+QfPplezmxUgFlYJIRh66QieAV9jVV3oJEh kFFdrL6B3MFB8Ud9+d2vaPtKtk1K2ktL0E2y9KSGOpD0CNikzPQ05/AxbZwq9ITfHEGHXV XaequlIs5tgU9rK4d1jWqY1Cf4C3AV3R1IqY+1sseavvAEpQi0P/TtyJl5UCA2HRhDXfN9 2bI/HbowyJ2/+eIOq5X+Klo4Rr7UN4TCBFFD+oJhYCZD8+HGBn0WOYlt2lgDhA== 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 430FC176B1; Fri, 21 Jan 2022 07:02:18 +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 20L72IPh075721; Fri, 21 Jan 2022 07:02:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20L72Inc075720; Fri, 21 Jan 2022 07:02:18 GMT (envelope-from git) Date: Fri, 21 Jan 2022 07:02:18 GMT Message-Id: <202201210702.20L72Inc075720@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andriy Gapon Subject: git: c902b6082a84 - stable/12 - adaspindown: check disk power mode before sending IDLE command 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: avg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: c902b6082a84a95b478d40da08f3964500b2f9ff Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642748538; 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=I8Of+BVVuwt04+K99Y2Jyw8hPpY5EWzsMKgTSOQXlFw=; b=d1YLh4ILulCupkbXlB5KoxCzlKUcsBo1/sJPjOjtLdTrIvZwHeEATxeu38R7aCUzvx8u8d 04s6BT9NTJmcbfBucwCAzM5RcD5183WhyfI2RhJOijM60rIQSebuIM8XfvtRTOJAn7D+Dq NaAmMGlV7k22ylu0bnaBcjbSWBlXixIcRPaY0uziHjc/CV98dwU5QK4HnA3RPKr8/WNAtt XmvZMIw5I4RhdZGnLRvsTgyJeqqAB+9Sa/Utb0H0Hwl6h5yo7l52hzJsswVf9ib1sLw0PR UNQz/n8aEcBAUw0dnKgnftpgx3zsRt5JjYr7c3jJnOlMkvxx9s+i/LcaPKz1Mw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642748538; a=rsa-sha256; cv=none; b=khUHvOh1pztG6TX3JMoygiD6Bxgpzdvewi9XaLiIxquqXgM5ZrTvZPZ7P+P0PAal2fG7yw GUtakxh6XnTtkPorW6fVtRAQzhXl8rZvPteXXMvel3yqPD69veWftaK5rj2N5ZjxY3JDtX Y8vS4WAZ4QRXFklyZiEYWbuqOdN869HJEIxO8MTa2/rhK+90A9fXjEGIw9vZ7K05T7NdV5 XHZF8rgvne8/uFKGMg2kc4dp3eHgtfs4hx5WmcjvPHC6iGqQWBVdGJ/us5JfKCgZm9cu6d hJVXm/aum+tDgeEQOr35lDHAr8cDfUYcUdG1D+jMgC486s0u7ejqYNzn6O7MeQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=c902b6082a84a95b478d40da08f3964500b2f9ff commit c902b6082a84a95b478d40da08f3964500b2f9ff Author: Andriy Gapon AuthorDate: 2021-12-24 09:02:22 +0000 Commit: Andriy Gapon CommitDate: 2022-01-21 07:01:48 +0000 adaspindown: check disk power mode before sending IDLE command If a disk is already in STANDBY mode, then setting IDLE mode can actually spin it up. (cherry picked from commit 15910dc0bcb526d575f8cc49efe1f98a5091c88e) --- sys/cam/ata/ata_da.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c index 75c1e4dc0495..6d01c332c056 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -3489,6 +3489,7 @@ adaspindown(uint8_t cmd, int flags) struct ada_softc *softc; struct ccb_ataio local_ccb; int error; + int mode; CAM_PERIPH_FOREACH(periph, &adadriver) { /* If we paniced with lock held - not recurse here. */ @@ -3504,6 +3505,52 @@ adaspindown(uint8_t cmd, int flags) continue; } + /* + * Additionally check if we would spin up the drive instead of + * spinning it down. + */ + if (cmd == ATA_IDLE_IMMEDIATE) { + memset(&local_ccb, 0, sizeof(local_ccb)); + xpt_setup_ccb(&local_ccb.ccb_h, periph->path, + CAM_PRIORITY_NORMAL); + local_ccb.ccb_h.ccb_state = ADA_CCB_DUMP; + + cam_fill_ataio(&local_ccb, 0, NULL, CAM_DIR_NONE, + 0, NULL, 0, ada_default_timeout * 1000); + ata_28bit_cmd(&local_ccb, ATA_CHECK_POWER_MODE, + 0, 0, 0); + local_ccb.cmd.flags |= CAM_ATAIO_NEEDRESULT; + + error = cam_periph_runccb((union ccb *)&local_ccb, + adaerror, /*cam_flags*/0, + /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY, + softc->disk->d_devstat); + if (error != 0) { + xpt_print(periph->path, + "Failed to read current power mode\n"); + } else { + mode = local_ccb.res.sector_count; +#ifdef DIAGNOSTIC + if (bootverbose) { + xpt_print(periph->path, + "disk power mode 0x%02x\n", mode); + } +#endif + switch (mode) { + case 0x00: + case 0x01: + if (bootverbose) { + xpt_print(periph->path, + "already spun down\n"); + } + cam_periph_unlock(periph); + continue; + default: + break; + } + } + } + if (bootverbose) xpt_print(periph->path, "spin-down\n");