From patchwork Tue Jun 3 20:04: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: 4290671 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E7AEC9F1D6 for ; Tue, 3 Jun 2014 20:09:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20A7E20212 for ; Tue, 3 Jun 2014 20:09:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 357F8201DE for ; Tue, 3 Jun 2014 20:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933718AbaFCUJN (ORCPT ); Tue, 3 Jun 2014 16:09:13 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:55746 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934075AbaFCUE6 (ORCPT ); Tue, 3 Jun 2014 16:04:58 -0400 Received: by mail-wg0-f48.google.com with SMTP id k14so7229980wgh.31 for ; Tue, 03 Jun 2014 13:04:57 -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=15RpQRvuwN8g9aXDhGUMLDVd5DcZe0RS7/eQ+d6gxdU=; b=s96USr3nauHtnT5fKcIPJ4DLpceX8VLLuOyrczypt+p0Fhr5T7c5HsYxjWtm0P2FMW Pd3mOWyJsnkNMnRMC7byZhwa5kKYxb/IUCJC/IopRCqCiT9V1afLYGjWmQSKcJ8Hhpbu kA6XGxiSxPzOeYoTpJqWcNhDiEKghABVsscR4+Za+ck8KCrsyyeEaDiWVMK5zJrU4wOy gu3WVXs5UdPuXZW+QJB+aNc00HN70G19EMltii3lP2umyLW6XIzKHGkQpPa0d9SBIB/e QilJt8qrwbORE1i5WXyjlS0yvwaKbIYd+eiW3coD6iC4OCyGnS+c8rH8SCTM5qd1LeKS c1EQ== X-Received: by 10.194.7.36 with SMTP id g4mr8497527wja.37.1401825897077; Tue, 03 Jun 2014 13:04:57 -0700 (PDT) Received: from localhost.localdomain (77-58-151-250.dclient.hispeed.ch. [77.58.151.250]) by mx.google.com with ESMTPSA id vm8sm615536wjc.27.2014.06.03.13.04.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Jun 2014 13:04:56 -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 v5 07/15] thunderbolt: Enable plug events Date: Tue, 3 Jun 2014 22:04:04 +0200 Message-Id: <1401825852-4745-8-git-send-email-andreas.noever@gmail.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1401825852-4745-1-git-send-email-andreas.noever@gmail.com> References: <1401825852-4745-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 | 52 ++++++++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/tb.h | 1 + 2 files changed, 53 insertions(+) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index e89121f..6d193a2 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -99,6 +99,45 @@ 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; + switch (sw->config.device_id) { + case 0x1513: + case 0x151a: + case 0x1549: + break; + default: + 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 +152,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 +166,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 +219,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 */ }; /**