From nobody Tue Feb 22 17:43:34 2022 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 B104219ECEC9; Tue, 22 Feb 2022 17:43:34 +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 4K363B4clSz3mHZ; Tue, 22 Feb 2022 17:43:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645551814; 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=HT/luSjagFC2rIuZUmeLkzLWIIuO1eB9bnOWgb27X7g=; b=WOvq5hw0/0afgnoeXd180cmriDZr2HM9tHMUAUNzmq0LVcLD8X6WdxOWZw91CPGsPLZ3ko HI8g7jtqRUhRAqV5Y7JXWLO7OGX3WV7Y6EEKG0V0Q5ANNBfufoHwbpCP8vra9gZFxP39zv jXXhckhMane73Gdp/wjSmNYj2Yf6KkqHN8RULqdLoXlpIds92CkH9pnN7qt1b/S+LKAhMZ 4mozLRmubxC0fLVVjO8picKM7dai1v+o05/g9XtKWL624hfIcV7VSLmiyURzQ+/3yvk/7m xtMPX8XwIsvp8mwwx8+NOGXisPn/XJ7lMBhyRlCK1kVtSFw9JHJ8L6qIdp7FxA== 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 7E6CA74A; Tue, 22 Feb 2022 17:43:34 +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 21MHhYUp049249; Tue, 22 Feb 2022 17:43:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21MHhYDE049248; Tue, 22 Feb 2022 17:43:34 GMT (envelope-from git) Date: Tue, 22 Feb 2022 17:43:34 GMT Message-Id: <202202221743.21MHhYDE049248@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 9835900cb95b - main - camcontrol: Force a rescan of the lun after firmware download. 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9835900cb95bcd068774934961fb1419719d595b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645551814; 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=HT/luSjagFC2rIuZUmeLkzLWIIuO1eB9bnOWgb27X7g=; b=RfVwCHItOXDCVfo/B9jutGG2C4Vx3ljr8zbLIG13chLSNM1D2SCNFIwXhkgBInoFUb8cG6 0yOdPVzPZtlGcJK/JkJV5pQdLDPbDExRMYwplpq06TDjYNfv+XQI1XMOzkTHaRbBqHyPjq GlkA6bOyZdjRlG8Td6bY6r+MfqHBuyJpCq8gFQoVUjEdZyLu7wAmztBDoaYpMcn3bjftPa svYnGAsc9vWiilMtDC6XDatu92tEYd46asTM2pZxhYSwrfH68dhmKaHKLZZ2MJc31TghHe 5qVtf+p/+iWGGT7cD2GZz2F2l8ShYuk/P25+h3klG5ly39BFQA1n7ohIf/lTxA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645551814; a=rsa-sha256; cv=none; b=Ou8daYy9vm51kYMY8VFuV4ZV47NjszCmIK5iiDXLLZksmx8m/WAsQ2kNebq3pNI0rzrmK1 f7w/wWJMuAZogWnC2WWyTFV9lTEDzw1DLc6olVObaus+IHk6V+FTwkJ/1qq/wfXPYqBviK Xtm7myd0bXuDfHw+uDBqAj2kPEglXV+2d4znBuS/p+vtQo00yNg8qY7v3GVMxgErIF2kJm pBjQKllONC2QgwJqDv/buyoDmWeAucCA734woHprlWpIzRmJE1b3O7CbemFRSS7LlDuUIi fYsLlFItbT1QfotUF3oNib0L98SrEWsXEswEQC6lnrm+Y5to+yHu5Is17SjIIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=9835900cb95bcd068774934961fb1419719d595b commit 9835900cb95bcd068774934961fb1419719d595b Author: Warner Losh AuthorDate: 2022-02-22 17:34:36 +0000 Commit: Warner Losh CommitDate: 2022-02-22 17:43:26 +0000 camcontrol: Force a rescan of the lun after firmware download. After downloading the firmware to a device, it's inquiry data likely will change. Force a rescan of the target with the CAM_EXPECT_INQ_CHANGE flag to get it to record the new inqury data as being expected. This avoids the need for a 'camcontrol rescan' on the device which detaches and re-attaches the disk (da, ada) device. This brings fwdownload up to nvmecontrol's ability to do the same thing w/o changing the exposed nvme/nvd/nda device. We scan the target and not the LUN because dual actuator drives have multiple LUNs, but the firmware is global across many vendors' drives (and the so far theoretical ones that aren't won't be harmed by the rescan). Since the underlying struct disk is now preserved accross this operation, it's now possible to upgrade firmware of a root device w/o crashing the system. On systems that are quite busy, the worst that happens is that certain operaions are reported cancelled when the new firmware is activated. These operations are retried with the normal CAM recovery mechanisms and will work on the retry. The only visible hiccup is the time that new firmware is flashing / initializing. One should not consider this operation completely risk free, however, since not all drives are well behaved after a firmware download. MFC After: 1 week Relnotes: yes Sponsored by: Netflix Feedback by: mav Differential Revision: https://reviews.freebsd.org/D34325 --- sbin/camcontrol/fwdownload.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/sbin/camcontrol/fwdownload.c b/sbin/camcontrol/fwdownload.c index dc97b3a221db..5463f4e0b52c 100644 --- a/sbin/camcontrol/fwdownload.c +++ b/sbin/camcontrol/fwdownload.c @@ -57,12 +57,15 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include #include +#include #include +#include #include #include @@ -759,6 +762,67 @@ bailout: return (retval); } +/* + * After the firmware is downloaded, we know the sense data has changed (or is + * likely to change since it contains the firmware version). Rescan the target + * with a flag to tell the kernel it's OK. This allows us to continnue using the + * old periph/disk in the kernel, which is less disruptive. We rescan the target + * because multilun devices usually update all the luns after the first firmware + * download. + */ +static int +fw_rescan_lun(struct cam_device *dev, bool printerrors) +{ + union ccb ccb; + int fd; + target_id_t target; + uint32_t bus; + + /* Can only send XPT_SCAN_TGT via /dev/xpt, not pass device in *dev */ + if ((fd = open(XPT_DEVICE, O_RDWR)) < 0) { + warnx("error opening transport layer device %s\n", + XPT_DEVICE); + warn("%s", XPT_DEVICE); + return (1); + } + + /* Fill in the bus and target IDs as they don't seem to be in *dev */ + bzero(&ccb, sizeof(union ccb)); + ccb.ccb_h.func_code = XPT_GDEVLIST; + strlcpy(ccb.cgdl.periph_name, dev->device_name, sizeof(ccb.cgdl.periph_name)); + ccb.cgdl.unit_number = dev->dev_unit_num; + if (cam_send_ccb(dev, &ccb) < 0) { + warn("send_ccb GDEVLIST failed\n"); + close(fd); + return (1); + } + bus = ccb.ccb_h.path_id; + target = ccb.ccb_h.target_id; + + /* Rescan the target */ + bzero(&ccb, sizeof(union ccb)); + ccb.ccb_h.func_code = XPT_SCAN_TGT; + ccb.ccb_h.path_id = bus; + ccb.ccb_h.target_id = target; + ccb.ccb_h.target_lun = CAM_LUN_WILDCARD; + ccb.crcn.flags = CAM_EXPECT_INQ_CHANGE; + ccb.ccb_h.pinfo.priority = 5; /* run this at a low priority */ + + if (ioctl(fd, CAMIOCOMMAND, &ccb) < 0) { + warn("CAMIOCOMMAND XPT_SCAN_TGT ioctl failed"); + close(fd); + return (1); + } + if ((ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { + warn("Can't send rescan lun"); + if (printerrors) + cam_error_print(dev, &ccb, CAM_ESF_ALL, CAM_EPF_ALL, + stderr); + return (1); + } + return (0); +} + /* * Download firmware stored in buf to cam_dev. If simulation mode * is enabled, only show what packet sizes would be sent to the @@ -912,6 +976,9 @@ bailout: if (quiet == 0) progress_complete(&progress, size - img_size); cam_freeccb(ccb); + if (retval == 0 && !sim_mode) { + fw_rescan_lun(cam_dev, printerrors); + } return (retval); }