From patchwork Mon May 26 15:18:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Noever X-Patchwork-Id: 4243691 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 88B32BF90B for ; Mon, 26 May 2014 15:28:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B629220171 for ; Mon, 26 May 2014 15:28:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6D162012E for ; Mon, 26 May 2014 15:28:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752747AbaEZP2T (ORCPT ); Mon, 26 May 2014 11:28:19 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:42669 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752662AbaEZPS3 (ORCPT ); Mon, 26 May 2014 11:18:29 -0400 Received: by mail-wi0-f175.google.com with SMTP id f8so150339wiw.14 for ; Mon, 26 May 2014 08:18:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I6lP9uG1UY6MZyxJYJ+w47GztJTdIFnjuyia6HnXM98=; b=FrHGiTVlpfidhbc1XZF/uk+E5fLz9nbdTVMZVX8DnaEIeNUSOREtW6o1kb+MqZY8Fy N2kkd2ZBkEY12aT2zatlOWucbAZm1vL6+AK7Xk7k5/447LQh8tsMiSRZ5YUtYhp3kCR0 wZzAG14GWertARIV0dJZvuXZvieNea85PJGb1ARaD7Gd6bpF5kX2IllA+LHO9xGbIokw E/4b4QnIsJnj9e9YW+Bg+7St62uOmqaQ+Myv8ZvKhEm8ndovoi4qVJM2FA6U1uSrbtAA s8CSvpKyvGrnEVBHxBpQ0pRPyCgMpSJaDvajxR02OKvEVQu9OjVYKVAozoif3qr90JK/ Zc6w== X-Received: by 10.180.126.97 with SMTP id mx1mr3438229wib.29.1401117507703; Mon, 26 May 2014 08:18:27 -0700 (PDT) Received: from linuxbook.inf.ethz.ch (anoever.inf.ethz.ch. [129.132.153.240]) by mx.google.com with ESMTPSA id cv4sm27564479wjc.34.2014.05.26.08.18.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 May 2014 08:18:27 -0700 (PDT) From: Andreas Noever To: linux-kernel@vger.kernel.org, Matthew Garrett , Greg KH , Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Andreas Noever Subject: [PATCH v3 07/15] thunderbolt: Enable plug events Date: Mon, 26 May 2014 17:18:04 +0200 Message-Id: <1401117492-2870-8-git-send-email-andreas.noever@gmail.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1401117492-2870-1-git-send-email-andreas.noever@gmail.com> References: <1401117492-2870-1-git-send-email-andreas.noever@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Thunderbolt switches have a plug events capability. This patch adds the tb_plug_events_active method and uses it to activate plug events during switch allocation. Signed-off-by: Andreas Noever --- drivers/thunderbolt/switch.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/tb.h | 1 + 2 files changed, 47 insertions(+) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index e89121f..21457cc 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -99,6 +99,39 @@ static void tb_dump_switch(struct tb *tb, struct tb_regs_switch_header *sw) } /** + * tb_plug_events_active() - enable/disable plug events on a switch + * + * Also configures a sane plug_events_delay of 255ms. + * + * Return: Returns 0 on success or an error code on failure. + */ +static int tb_plug_events_active(struct tb_switch *sw, bool active) +{ + u32 data; + int res; + + sw->config.plug_events_delay = 0xff; + res = tb_sw_write(sw, ((u32 *) &sw->config) + 4, TB_CFG_SWITCH, 4, 1); + if (res) + return res; + + res = tb_sw_read(sw, &data, TB_CFG_SWITCH, sw->cap_plug_events + 1, 1); + if (res) + return res; + + if (active) { + data = data & 0xFFFFFF83; + if (sw->config.device_id == 0x1547) + data |= 4; + } else { + data = data | 0x7c; + } + return tb_sw_write(sw, &data, TB_CFG_SWITCH, + sw->cap_plug_events + 1, 1); +} + + +/** * tb_switch_free() - free a tb_switch and all downstream switches */ void tb_switch_free(struct tb_switch *sw) @@ -113,6 +146,8 @@ void tb_switch_free(struct tb_switch *sw) sw->ports[i].remote = NULL; } + tb_plug_events_active(sw, false); + kfree(sw->ports); kfree(sw); } @@ -125,6 +160,7 @@ void tb_switch_free(struct tb_switch *sw) struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route) { int i; + int cap; struct tb_switch *sw; int upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); if (upstream_port < 0) @@ -177,6 +213,16 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route) /* TODO: I2C, IECS, EEPROM, link controller */ + cap = tb_find_cap(&sw->ports[0], TB_CFG_SWITCH, TB_CAP_PLUG_EVENTS); + if (cap < 0) { + tb_sw_warn(sw, "cannot find TB_CAP_PLUG_EVENTS aborting\n"); + goto err; + } + sw->cap_plug_events = cap; + + if (tb_plug_events_active(sw, true)) + goto err; + return sw; err: kfree(sw->ports); diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index 38e4c23..af123c4 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -19,6 +19,7 @@ struct tb_switch { struct tb_regs_switch_header config; struct tb_port *ports; struct tb *tb; + int cap_plug_events; /* offset, zero if not found */ }; /**