Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1900769ybl; Tue, 3 Dec 2019 14:40:38 -0800 (PST) X-Google-Smtp-Source: APXvYqzJ/78OngG/MVu5VH1gDKGFfZhXRnzynNZoHDmwGo69MSLYLhpIbXUO3kH3ZHU88XoCMVpt X-Received: by 2002:aca:4911:: with SMTP id w17mr10498oia.22.1575412838334; Tue, 03 Dec 2019 14:40:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575412838; cv=none; d=google.com; s=arc-20160816; b=082l65cFgfsI47sBS55KDLGRb+nlNn8xCcGNicxBtC6imSTwCf1pfQTuaBzXQGDlOY ejqsgoFhpkmD6qztAHD2PwnQzTPEyuagYxZfEeorbJEVOC7hk0KIrRW+Fuvsd+Cj/E/q bRTD0RLwZvyqV6+Lcp0nhAb12dYauPxyjPPAyMdTi9PDYWP9KIGqzHVK1SlziHZZ2Vye EUzqOMGDSfaSyznU6C39gIpZYAxXlvjed/Nru0idm2xIW16KhduKaWbkJMmjcOfzyRBZ 9Z/45e/Xlyb+z6bPIwh97MUjWi25AxO1vKsrLO2x2r449K/4oC9gM04WqxJJU0m6syMP tBWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6AxSB2b23SeGgx8dsG2G+nBrMwkn8HXRSWrLEc7JUzc=; b=g7mfh6Cury/EbQl8aMr02Z4xEh7iuEDdcFAY/dNSjj3+bgVMlfmiBSoMpFfjA0Yxr1 es9EhxY+tgAIXaa5vvOZ9rDqeBjj+S395S11a+UlHRlEr5jcODb9bpNjIw3+7BBZP1lR LiySFt73hFbzIAZGD9irL+92tzgr1Q/ck5IXUdGmK7SS8JAcphtJHUbtnwL3CrJA1EMz 2lHCeoLL94dUi9uA7XobcaPk/iM9nlERKL1dxrb8WH1WsOmIDJDy/H+x/64jFUxhlKTV YhYFaB2OuL30U4B2YnPLswe8aOpzUa85z6BNkXLjZzArR5WlYD7DqLDzZ/2FGdOTrSz7 kogA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ZTuaS/2Q"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10si2192272oto.293.2019.12.03.14.40.26; Tue, 03 Dec 2019 14:40:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ZTuaS/2Q"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727539AbfLCWjR (ORCPT + 99 others); Tue, 3 Dec 2019 17:39:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:49066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728171AbfLCWjO (ORCPT ); Tue, 3 Dec 2019 17:39:14 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 922AE207DD; Tue, 3 Dec 2019 22:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575412753; bh=Sn94HdVLW/OEn/8TqLeKciNkLqOP6DkWHZCCKHmmbSk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZTuaS/2QdIyQe+Vke0Y5PDblhSPmyO+BdVSm45JYhz9gKurheW0c9/T7VcnfL8+HG uBf3yhEB+Kp9a6DB3182xYwVUx63vo8crs2irzYCAI1N/neUuJVmpHJLR9OM2UuXbZ IkGwNGXErmx8y/xtwNPcVapeIY0FEHPXUhXE6gmc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, zang , Mika Westerberg Subject: [PATCH 5.4 14/46] thunderbolt: Power cycle the router if NVM authentication fails Date: Tue, 3 Dec 2019 23:35:34 +0100 Message-Id: <20191203212729.315284594@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191203212705.175425505@linuxfoundation.org> References: <20191203212705.175425505@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mika Westerberg commit 7a7ebfa85f4fac349f3ab219538c44efe18b0cf6 upstream. On zang's Dell XPS 13 9370 after Thunderbolt NVM firmware upgrade the Thunderbolt controller did not come back as expected. Only after the system was rebooted it became available again. It is not entirely clear what happened but I suspect the new NVM firmware image authentication failed for some reason. Regardless of this the router needs to be power cycled if NVM authentication fails in order to get it fully functional again. This modifies the driver to issue a power cycle in case the NVM authentication fails immediately when dma_port_flash_update_auth() returns. We also need to call tb_switch_set_uuid() earlier to be able to fetch possible NVM authentication failure when DMA port is added. Link: https://bugzilla.kernel.org/show_bug.cgi?id=205457 Reported-by: zang Cc: stable Signed-off-by: Mika Westerberg Signed-off-by: Greg Kroah-Hartman --- drivers/thunderbolt/switch.c | 54 +++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -168,7 +168,7 @@ static int nvm_validate_and_write(struct static int nvm_authenticate_host(struct tb_switch *sw) { - int ret; + int ret = 0; /* * Root switch NVM upgrade requires that we disconnect the @@ -176,6 +176,8 @@ static int nvm_authenticate_host(struct * already). */ if (!sw->safe_mode) { + u32 status; + ret = tb_domain_disconnect_all_paths(sw->tb); if (ret) return ret; @@ -184,7 +186,16 @@ static int nvm_authenticate_host(struct * everything goes well so getting timeout is expected. */ ret = dma_port_flash_update_auth(sw->dma_port); - return ret == -ETIMEDOUT ? 0 : ret; + if (!ret || ret == -ETIMEDOUT) + return 0; + + /* + * Any error from update auth operation requires power + * cycling of the host router. + */ + tb_sw_warn(sw, "failed to authenticate NVM, power cycling\n"); + if (dma_port_flash_update_auth_status(sw->dma_port, &status) > 0) + nvm_set_auth_status(sw, status); } /* @@ -192,7 +203,7 @@ static int nvm_authenticate_host(struct * switch. */ dma_port_power_cycle(sw->dma_port); - return 0; + return ret; } static int nvm_authenticate_device(struct tb_switch *sw) @@ -200,8 +211,16 @@ static int nvm_authenticate_device(struc int ret, retries = 10; ret = dma_port_flash_update_auth(sw->dma_port); - if (ret && ret != -ETIMEDOUT) + switch (ret) { + case 0: + case -ETIMEDOUT: + case -EACCES: + case -EINVAL: + /* Power cycle is required */ + break; + default: return ret; + } /* * Poll here for the authentication status. It takes some time @@ -1246,8 +1265,6 @@ static ssize_t nvm_authenticate_store(st */ nvm_authenticate_start(sw); ret = nvm_authenticate_host(sw); - if (ret) - nvm_authenticate_complete(sw); } else { ret = nvm_authenticate_device(sw); } @@ -1690,13 +1707,16 @@ static int tb_switch_add_dma_port(struct int ret; switch (sw->generation) { - case 3: - break; - case 2: /* Only root switch can be upgraded */ if (tb_route(sw)) return 0; + + /* fallthrough */ + case 3: + ret = tb_switch_set_uuid(sw); + if (ret) + return ret; break; default: @@ -1721,6 +1741,19 @@ static int tb_switch_add_dma_port(struct return 0; /* + * If there is status already set then authentication failed + * when the dma_port_flash_update_auth() returned. Power cycling + * is not needed (it was done already) so only thing we do here + * is to unblock runtime PM of the root port. + */ + nvm_get_auth_status(sw, &status); + if (status) { + if (!tb_route(sw)) + nvm_authenticate_complete(sw); + return 0; + } + + /* * Check status of the previous flash authentication. If there * is one we need to power cycle the switch in any case to make * it functional again. @@ -1735,9 +1768,6 @@ static int tb_switch_add_dma_port(struct if (status) { tb_sw_info(sw, "switch flash authentication failed\n"); - ret = tb_switch_set_uuid(sw); - if (ret) - return ret; nvm_set_auth_status(sw, status); }