From nobody Fri Dec 24 09:03:15 2021 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 13DE41909FC5; Fri, 24 Dec 2021 09:03:16 +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 4JL1LW5g9Nz4mYt; Fri, 24 Dec 2021 09:03:15 +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 98533214B0; Fri, 24 Dec 2021 09:03:15 +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 1BO93FSE057534; Fri, 24 Dec 2021 09:03:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BO93FlA057533; Fri, 24 Dec 2021 09:03:15 GMT (envelope-from git) Date: Fri, 24 Dec 2021 09:03:15 GMT Message-Id: <202112240903.1BO93FlA057533@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: 15910dc0bcb5 - main - adaspindown: check disk power mode before sending IDLE command 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 15910dc0bcb526d575f8cc49efe1f98a5091c88e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640336595; 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=blw0C0zujrwxB2m0lq+QVyxzjkQH8fsYPY40i9Gfk7Y=; b=Yy9NjB65bGmQEFNrgC8FjMwjo3TJd+hMJYs53MSB5NMKCp2aQ/jHmlFBlKiSabzm3dUe/0 je0Or8LuKvEZ9YqmsDwix/vDnbQ+CZZDpqf0rxW1rJFSxPUcuY8j6mzdmc9ZxjB0mGg+Pm 9Y3m8imetffre/ORfRpZm71tCyzIZvWPWUQlly8YzywhgfE4YEnpqd1dAQperlhKAipOuj 7i0qBXzs7WXBeSsPM0hsU20J3KkUP5l559GTYDUcTM+m6unClia6/2Ex4bu0FOTVyPV/Jd bxotE7qrZlZsUgco9IXncyLVjbKIzuZMe+ekkfCahlOb4jLjf9idu+2PBXJmeg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640336595; a=rsa-sha256; cv=none; b=h8N4QrLljwD2jbLa0C2BHd3XumxY2Mr5QCxO0IHbbtl9tnv1JiDOuyXc196Vi1oAoyRMcN RIOiyIm5F9MV0WEgZQqXFG5MdnZ5e70vgij5DjJH214JtDPVMHyoB1cfSytqViywAvI4k6 ekrSFOZUPZc5l5V+r3aCKlMNqiXNJ2Z9I1FSW7bB+iGzwHub1ZO2Mi2UJN6viI8fLb8nX1 lTuLeRDg++CkFQIBkBRwI3dfDeIif1Y7OhRiS7jfPjMD2m2NJslER42MTKtovtS11CZYf2 Euafj3cNVsBQyGVeDtlyNDlEhPbuf8mx0HCPKrXYwF4i0RDxcu8Y0habY9VNig== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=15910dc0bcb526d575f8cc49efe1f98a5091c88e commit 15910dc0bcb526d575f8cc49efe1f98a5091c88e Author: Andriy Gapon AuthorDate: 2021-12-24 09:02:22 +0000 Commit: Andriy Gapon CommitDate: 2021-12-24 09:02:22 +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. Reviewed by: mav MFC after: 4 weeks Differential Revision: https://reviews.freebsd.org/D33588 --- 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 c05a9fa49d1c..adfcc0ee1845 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -3611,6 +3611,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. */ @@ -3626,6 +3627,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");