From nobody Fri Jan 21 07:01:39 2022 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 3F37F195DDD8; Fri, 21 Jan 2022 07:01:40 +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 4Jg9KJ1Jwdz4f3T; Fri, 21 Jan 2022 07:01:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642748500; 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=4G8bJDpYpDSxyHqNiSS1ZX1gqIBURbnVEH9F7fhLHNU=; b=bK9b1EG9RF3+316nC0NSY6TI12nA+c20Zn+a665rouSWhG6r+8/eOvGhM8lSn7NrqUG0sr 1eiaDirbjUIbzC0p7hwcPsCofBN/t6hm3aCrzcCAGEawBVz96cCkr1LhST5AmZA7n8eNko a5+1ls0nHF+hzqFTAsBxOjUs+z0dsEK7y9Oj+752vB6MA5dPyrpDUde4k0hi/+fnWQjeka PX3v0QCjr6ur1ADfyOMjrWL2gakZ9rUU7Aigc+SFlAy75jyIYWQzwVqsSO4qQ1OmNKMuKC /e+zexAkDVcfHfr/IOHj4CYnvgXLZ18EM+HVVxXs2IcJGiKQ46JpLaAh4Vg8qQ== 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 0DBFF1767F; Fri, 21 Jan 2022 07:01:40 +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 20L71d5W075570; Fri, 21 Jan 2022 07:01:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20L71dsB075569; Fri, 21 Jan 2022 07:01:39 GMT (envelope-from git) Date: Fri, 21 Jan 2022 07:01:39 GMT Message-Id: <202201210701.20L71dsB075569@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: 89ac48cf3ba1 - stable/13 - adaspindown: check disk power mode before sending IDLE command 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: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13 X-Git-Reftype: branch X-Git-Commit: 89ac48cf3ba178074a638da75bbf7101576305c2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642748500; 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=4G8bJDpYpDSxyHqNiSS1ZX1gqIBURbnVEH9F7fhLHNU=; b=jheermZkxjfBw9lnGViuWMebMIzITNqXkm+9qZqEMRWMCMRUC+E2KbT4MyqiBfE3RVpm9w 4l9nMhmHHtAmrEtLA7WuEs81rmGcZc5wgKPT9JfV8RAeGhVJxTRQJvCWGBrgD1mNzlgQ5F 5tAdViF5i7ieLLzdHl01wOJ+AeEbs4hi1aabqcdaddwLZFvoYeQi4xEEOHH2lAG5MLoPOn 6H/c+vnBHuBx/YVz4OT3VZjhSiHaEefsSefsUOi6SR+oIAmuNIkCHOcXDpNdZ4lW6JxIKg 02Fjr58kiBKrFf2P2Sy5Xr/gLPrHLc1zHN3lxsE+Nc1+suSP+rZIniHURaMh6Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642748500; a=rsa-sha256; cv=none; b=rSbMAAowIfZdGdgk3HJ7VCMG7Ob+iB6utY1hvrsFpc6ZvwxHDt7mcV4v24hmLzJOZBq5ua NcSpKE6VOuGHMg3oSRZVihQ/JIbztHa/9HC//hsDhzhaHaNWcZZIes0UVGEcBoWCiVV5Rv dHvrba+Qz/v7b1rtXl4CrjTaJVRc6M0l+mx6gbE8Q9aMjjAbTM+pggnlGfk2hIkfuCeLHw JsDrTb8VtS6Furc6Uv6ZJhNcBiEaXwinRElmHnwjWmRkGHOhhllJViY7YQB1TDUTzJA1f6 WhONIaKROpBeMe3SWsni+FngZYTR0CAt2iNdWUb27taXdW19SCYxMMvN/5+Q/Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=89ac48cf3ba178074a638da75bbf7101576305c2 commit 89ac48cf3ba178074a638da75bbf7101576305c2 Author: Andriy Gapon AuthorDate: 2021-12-24 09:02:22 +0000 Commit: Andriy Gapon CommitDate: 2022-01-21 07:01:09 +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 d49ef81f6009..5aa29174f71a 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -3576,6 +3576,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. */ @@ -3591,6 +3592,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");