From patchwork Tue Oct 1 12:46:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1169901 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46jJtd5pXjz9sQm; Tue, 1 Oct 2019 22:46:49 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iFHYC-0005Mt-Er; Tue, 01 Oct 2019 12:46:44 +0000 Received: from mail-pf1-f171.google.com ([209.85.210.171]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iFHY7-0005Hu-Qw for kernel-team@lists.ubuntu.com; Tue, 01 Oct 2019 12:46:39 +0000 Received: by mail-pf1-f171.google.com with SMTP id a2so7900078pfo.10 for ; Tue, 01 Oct 2019 05:46:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SlXc6OOlSXcj0jgARAX7D1hxXpClk7lZ5nnMxqNGRy4=; b=rb8XYqTHwRKP8Dz5WxqOfL9k9C+zXn+DRiQTt0siztOQ5sep53fXtTSyzWOQoFvBE/ X4R3U+lzatBsj4PN5ZvedEv4nt6rbQqYK580+tc60FRUALCY14sK49QUzbEPf3FV3ICK 2/6QkkSZwf3fZPV6KsUz7P7jX3IdxfcNwe+5cS5emXN8TQ+bZG8zaOxPlan2W1zw2uXM TXelA3GyWwnroGyBgKRRGe3nBkxPRxlyP63OXxu/Sj3mZJXuvEJvkA8I6YK9khhwuDgZ 2jZwwGzfWoU3WNUdTNNGu6XQTx15A+YMM63RC/IFwjPjw+TxUPxP4jPZM43IfnjRSM1O La/A== X-Gm-Message-State: APjAAAXhiLovlEYhIML7l0XN8PSTPgllK+eMfMUlyvyLtIVYb9z6nm8v 7A0B4n5Pjv1dGeXE9s6J7QG2tQesOaw= X-Google-Smtp-Source: APXvYqwZ9po6WZrKNlRWlaTVP1rb7/BlwOt41vjKG0Wn8876DdveYENb2Q7eoWzD0alGjoeqrU2W8w== X-Received: by 2002:aa7:96b8:: with SMTP id g24mr9097489pfk.163.1569933997971; Tue, 01 Oct 2019 05:46:37 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id e127sm17108608pfe.37.2019.10.01.05.46.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2019 05:46:37 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 13/17][SRU][OEM-OSP1-B] thunderbolt: Do not fail adding switch if some port is not implemented Date: Tue, 1 Oct 2019 20:46:06 +0800 Message-Id: <20191001124610.10587-14-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191001124610.10587-1-vicamo.yang@canonical.com> References: <20191001124610.10587-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Mika Westerberg BugLink: https://bugs.launchpad.net/bugs/1844680 There are two ways to mark a port as unimplemented. Typical way is to return port type as TB_TYPE_INACTIVE when its config space is read. Alternatively if the port is not physically present (such as ports 10 and 11 in ICL) reading from port config space returns TB_CFG_ERROR_INVALID_CONFIG_SPACE instead. Currently the driver bails out from adding the switch if it receives any error during port inititialization which is wrong. Handle this properly and just leave the port as TB_TYPE_INACTIVE before continuing to the next port. This also allows us to get rid of special casing for Light Ridge port 5 in eeprom.c. Signed-off-by: Mika Westerberg Reviewed-by: Yehezkel Bernat Tested-by: Mario Limonciello (cherry picked from commit d94dcbb10183f3b384c84e65724d2b753aa53c4d) Signed-off-by: You-Sheng Yang --- drivers/thunderbolt/ctl.c | 23 +++++++++++++++++++---- drivers/thunderbolt/eeprom.c | 4 ---- drivers/thunderbolt/switch.c | 8 +++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c index 73b386de4d15..d1d0c1dc8cb2 100644 --- a/drivers/thunderbolt/ctl.c +++ b/drivers/thunderbolt/ctl.c @@ -930,6 +930,23 @@ struct tb_cfg_result tb_cfg_write_raw(struct tb_ctl *ctl, const void *buffer, return res; } +static int tb_cfg_get_error(struct tb_ctl *ctl, enum tb_cfg_space space, + const struct tb_cfg_result *res) +{ + /* + * For unimplemented ports access to port config space may return + * TB_CFG_ERROR_INVALID_CONFIG_SPACE (alternatively their type is + * set to TB_TYPE_INACTIVE). In the former case return -ENODEV so + * that the caller can mark the port as disabled. + */ + if (space == TB_CFG_PORT && + res->tb_error == TB_CFG_ERROR_INVALID_CONFIG_SPACE) + return -ENODEV; + + tb_cfg_print_error(ctl, res); + return -EIO; +} + int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port, enum tb_cfg_space space, u32 offset, u32 length) { @@ -942,8 +959,7 @@ int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port, case 1: /* Thunderbolt error, tb_error holds the actual number */ - tb_cfg_print_error(ctl, &res); - return -EIO; + return tb_cfg_get_error(ctl, space, &res); case -ETIMEDOUT: tb_ctl_warn(ctl, "timeout reading config space %u from %#x\n", @@ -969,8 +985,7 @@ int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port, case 1: /* Thunderbolt error, tb_error holds the actual number */ - tb_cfg_print_error(ctl, &res); - return -EIO; + return tb_cfg_get_error(ctl, space, &res); case -ETIMEDOUT: tb_ctl_warn(ctl, "timeout writing config space %u to %#x\n", diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c index 81e8ac4c5805..3b2fb4aafd92 100644 --- a/drivers/thunderbolt/eeprom.c +++ b/drivers/thunderbolt/eeprom.c @@ -525,10 +525,6 @@ int tb_drom_read(struct tb_switch *sw) sw->ports[3].dual_link_port = &sw->ports[4]; sw->ports[4].dual_link_port = &sw->ports[3]; - /* Port 5 is inaccessible on this gen 1 controller */ - if (sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE) - sw->ports[5].disabled = true; - return 0; } diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index e81eb3751678..3473f235fe4d 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -575,8 +575,14 @@ static int tb_init_port(struct tb_port *port) int cap; res = tb_port_read(port, &port->config, TB_CFG_PORT, 0, 8); - if (res) + if (res) { + if (res == -ENODEV) { + tb_dbg(port->sw->tb, " Port %d: not implemented\n", + port->port); + return 0; + } return res; + } /* Port 0 is the switch itself and has no PHY. */ if (port->config.type == TB_TYPE_PORT && port->port != 0) {