Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp438759ybb; Thu, 28 Mar 2019 05:43:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/Ybl9zZ4J2Wrin2uNFJ9f8DNkhFKVdGJc/AnCg6w4JFLNyPgroYhUawH+lhHJUbzjZumm X-Received: by 2002:a62:1d0d:: with SMTP id d13mr6289283pfd.96.1553776982128; Thu, 28 Mar 2019 05:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553776982; cv=none; d=google.com; s=arc-20160816; b=z6GlHRzeD2zcoGumA6aS+T+aosEnPkm5JDATaCpsfcBICUFpG/Q4BVObF/2i2eJj4a adPNYkeD2kwqUnj5oj+CPLCPfJ3liVEykCtjXAtGyfkXXl9bmd/Qdm5mIFGcRu0XyNeh IXs8E5fodoq0VR3ZnWJvgUwbm5DnB/dQnmE8DtpisQaJYcY/jJh7aA5kKFoKzNE6SimL 0rZ854cgnu7X5vy1UeK58CL5jRsfuA9NAVTKklJSu93/dg5ZFKXtQSA07XhkKCIx3Aoi 58/9IFcAvfA9fNfkOTpu3uATPt5c/0uHfZXdyDXbby6YIyRddl1jvze9PK59LlE1ThCR zKVw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+HMI4mPPYNN5gjW+/JkxW/r7rOXWoFPtMVglNMjnIZ8=; b=YnghBNMuSFiNys5ZTfmjQ3p4/EmvD1fJT7a2bdvJCYiWcDJcEdwoRELpbVDNGsPbUs KNr24fiw1BB7ZtVQyOKxkomlh5wogwXtmv6CUE43MtP797gQvx/IO/V12+w5t96ffs4s ajAZ2UwY3kMMlCLywjYeVR7WtVj8KR1yEmE9TKpPXo9dcWKiybBdbcW8bc3F4qvc3drO f3qm/bmaU3tM0CknEd212QITml8rs9eas6XlUdu4mrA/kDDAy4AJco+cu1oODuyyfR/U TUJHOZmeT+tg9Yet3Y3qA/JGdpkoD0Ze6IV3CDcTmzN5ir4T+dDGtXNKTQfWyw+8LShA d1Jg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q81si4293543pfc.126.2019.03.28.05.42.46; Thu, 28 Mar 2019 05:43:02 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727517AbfC1Mj6 (ORCPT + 99 others); Thu, 28 Mar 2019 08:39:58 -0400 Received: from mga09.intel.com ([134.134.136.24]:34151 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726971AbfC1Mgn (ORCPT ); Thu, 28 Mar 2019 08:36:43 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2019 05:36:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,280,1549958400"; d="scan'208";a="138009642" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 28 Mar 2019 05:36:39 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 538268B4; Thu, 28 Mar 2019 14:36:34 +0200 (EET) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Michael Jamet , Yehezkel Bernat , Andreas Noever , Lukas Wunner , "David S . Miller" , Andy Shevchenko , Christian Kellner , Mario.Limonciello@dell.com, Mika Westerberg , netdev@vger.kernel.org Subject: [PATCH v3 12/36] thunderbolt: Properly disable path Date: Thu, 28 Mar 2019 15:36:09 +0300 Message-Id: <20190328123633.42882-13-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190328123633.42882-1-mika.westerberg@linux.intel.com> References: <20190328123633.42882-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We need to wait until all buffers have been drained before the path can be considered disabled. Do this for every hop in a path. Also if the switch is physically disconnected, do not bother disabling it anymore (it is not present anyway). This adds another bit field to struct tb_regs_hop even if we are trying to get rid of them but we can clean them up another day. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/path.c | 48 ++++++++++++++++++++++++++++++++--- drivers/thunderbolt/tb_regs.h | 3 ++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/drivers/thunderbolt/path.c b/drivers/thunderbolt/path.c index a11956522bac..97f37f86fb75 100644 --- a/drivers/thunderbolt/path.c +++ b/drivers/thunderbolt/path.c @@ -7,6 +7,8 @@ #include #include +#include +#include #include "tb.h" @@ -74,13 +76,53 @@ static void __tb_path_deallocate_nfc(struct tb_path *path, int first_hop) } } +static int __tb_path_deactivate_hop(struct tb_port *port, int hop_index) +{ + struct tb_regs_hop hop; + ktime_t timeout; + int ret; + + if (port->sw->is_unplugged) + return 0; + + /* Disable the path */ + ret = tb_port_read(port, &hop, TB_CFG_HOPS, 2 * hop_index, 2); + if (ret) + return ret; + + /* Already disabled */ + if (!hop.enable) + return 0; + + hop.enable = 0; + + ret = tb_port_write(port, &hop, TB_CFG_HOPS, 2 * hop_index, 2); + if (ret) + return ret; + + /* Wait until it is drained */ + timeout = ktime_add_ms(ktime_get(), 500); + do { + ret = tb_port_read(port, &hop, TB_CFG_HOPS, 2 * hop_index, 2); + if (ret) + return ret; + + if (!hop.pending) + return 0; + + usleep_range(10, 20); + } while (ktime_before(ktime_get(), timeout)); + + return -ETIMEDOUT; +} + static void __tb_path_deactivate_hops(struct tb_path *path, int first_hop) { int i, res; - struct tb_regs_hop hop = { }; + for (i = first_hop; i < path->path_length; i++) { - res = tb_port_write(path->hops[i].in_port, &hop, TB_CFG_HOPS, - 2 * path->hops[i].in_hop_index, 2); + res = __tb_path_deactivate_hop(path->hops[i].in_port, + path->hops[i].in_hop_index); if (res) tb_port_warn(path->hops[i].in_port, "hop deactivation failed for hop %d, index %d\n", diff --git a/drivers/thunderbolt/tb_regs.h b/drivers/thunderbolt/tb_regs.h index 1ab6e0fb31c0..82ac4ec8757f 100644 --- a/drivers/thunderbolt/tb_regs.h +++ b/drivers/thunderbolt/tb_regs.h @@ -234,7 +234,8 @@ struct tb_regs_hop { bool egress_fc:1; bool ingress_shared_buffer:1; bool egress_shared_buffer:1; - u32 unknown3:4; /* set to zero */ + bool pending:1; + u32 unknown3:3; /* set to zero */ } __packed; /* Common link controller registers */ -- 2.20.1