From patchwork Fri Feb 14 15:35:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 11382565 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D44DA13A4 for ; Fri, 14 Feb 2020 15:40:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C49F2467E for ; Fri, 14 Feb 2020 15:40:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BJuWvTtc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C49F2467E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=XBIE0MZeIV3hd5ghXApAGFTJ6haBNapL8Xv02Thrdp0=; b=BJuWvTtcmmYqPIVrOsvcTl1GYL s2zCYGgguryNoACNKl53K+XZWzO4vJo1quOA9DsmG+e9+lKXzAKssjSsXyGlxbL4O3AEtu+LOgZ7M 1kSTnfPtNdoqlRj0Ho9RYjNOpeoq8DmZ0d3C8HvxTEqn8l+5WMw1bs4ynHzckM7VrIGwHJGk3xY3T gwsU93GJLcDMTXuOjrozIaBmUylG+mRwoQ1XPLcUO24rICWI6IfpL8CGuMV3hg9lPi8An9zRNSkg2 T5vsDikmTdMRRT2O08YL0SvUR7G6U0xYup5AcPb4hX2abhQlbWD2MOQxs0jHrP+VEy8Yakwh3tCAy y4Bc/mgQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2d4O-0004r5-FI; Fri, 14 Feb 2020 15:39:56 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j2d1F-0001iN-Kd for linux-arm-kernel@lists.infradead.org; Fri, 14 Feb 2020 15:36:43 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7F1B9101E; Fri, 14 Feb 2020 07:36:41 -0800 (PST) Received: from e120937-lin.cambridge.arm.com (e120937-lin.cambridge.arm.com [10.1.197.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7E1923F68E; Fri, 14 Feb 2020 07:36:40 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH v2 13/13] firmware: arm_scmi: Add Base notifications support Date: Fri, 14 Feb 2020 15:35:35 +0000 Message-Id: <20200214153535.32046-14-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200214153535.32046-1-cristian.marussi@arm.com> References: <20200214153535.32046-1-cristian.marussi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200214_073641_777772_932E2EF7 X-CRM114-Status: GOOD ( 14.47 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [217.140.110.172 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jonathan.Cameron@Huawei.com, cristian.marussi@arm.com, james.quinlan@broadcom.com, lukasz.luba@arm.com, sudeep.holla@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Make SCMI Base protocol register with the notification core. Signed-off-by: Cristian Marussi --- V1 --> V2 - simplified .set_notify_enabled() implementation moving the ALL_SRCIDs logic out of protocol. ALL_SRCIDs logic is now in charge of the notification core, together with proper reference counting of enables - switched to devres protocol-registration --- drivers/firmware/arm_scmi/base.c | 114 +++++++++++++++++++++++++++++++ include/linux/scmi_protocol.h | 8 +++ 2 files changed, 122 insertions(+) diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c index ce7d9203e41b..df9fae9a0cff 100644 --- a/drivers/firmware/arm_scmi/base.c +++ b/drivers/firmware/arm_scmi/base.c @@ -6,6 +6,9 @@ */ #include "common.h" +#include "notify.h" + +#define SCMI_BASE_NUM_SOURCES 1 enum scmi_base_protocol_cmd { BASE_DISCOVER_VENDOR = 0x3, @@ -29,6 +32,21 @@ struct scmi_msg_resp_base_attributes { __le16 reserved; }; +struct scmi_msg_base_error_notify { + __le32 event_control; +#define BASE_TP_NOTIFY_ALL BIT(0) +}; + +struct scmi_base_error_notify_payld { + __le32 agent_id; + __le32 error_status; +#define IS_FATAL_ERROR(x) ((x) & BIT(31)) +#define ERROR_CMD_COUNT(x) FIELD_GET(GENMASK(9, 0), (x)) + __le64 msg_reports[8192]; +}; + +static const struct scmi_handle *protocol_handle; + /** * scmi_base_attributes_get() - gets the implementation details * that are associated with the base protocol. @@ -222,6 +240,95 @@ static int scmi_base_discover_agent_get(const struct scmi_handle *handle, return ret; } +static int scmi_base_error_notify(const struct scmi_handle *handle, bool enable) +{ + int ret; + u32 evt_cntl = enable ? BASE_TP_NOTIFY_ALL : 0; + struct scmi_xfer *t; + struct scmi_msg_base_error_notify *cfg; + + ret = scmi_xfer_get_init(handle, BASE_NOTIFY_ERRORS, + SCMI_PROTOCOL_BASE, sizeof(*cfg), 0, &t); + if (ret) + return ret; + + cfg = t->tx.buf; + cfg->event_control = cpu_to_le32(evt_cntl); + + ret = scmi_do_xfer(handle, t); + + scmi_xfer_put(handle, t); + return ret; +} + +static bool scmi_base_set_notify_enabled(u8 evt_id, u32 src_id, bool enable) +{ + int ret; + + if (!protocol_handle) + return false; + + ret = scmi_base_error_notify(protocol_handle, enable); + if (ret) + pr_warn("SCMI Notifications - Proto:%X - FAIL_ENABLED - evt[%X] ret:%d\n", + SCMI_PROTOCOL_BASE, evt_id, ret); + + return !ret ? true : false; +} + +static void *scmi_base_fill_custom_report(u8 evt_id, u64 timestamp, + const void *payld, size_t payld_sz, + void *report, u32 *src_id) +{ + void *rep = NULL; + + switch (evt_id) { + case BASE_ERROR_EVENT: + { + int i; + const struct scmi_base_error_notify_payld *p = payld; + struct scmi_base_error_report *r = report; + + /* + * BaseError notification payload is variable in size but + * up to a maximum length determined by the struct ponted by p. + * Instead payld_sz is the effective length of this notification + * payload so cannot be greater of the maximum allowed size as + * pointed by p. + */ + if (sizeof(*p) < payld_sz) + break; + + r->timestamp = timestamp; + r->agent_id = le32_to_cpu(p->agent_id); + r->fatal = IS_FATAL_ERROR(le32_to_cpu(p->error_status)); + r->cmd_count = ERROR_CMD_COUNT(le32_to_cpu(p->error_status)); + for (i = 0; i < r->cmd_count; i++) + r->reports[i] = le64_to_cpu(p->msg_reports[i]); + *src_id = 0; + rep = r; + break; + } + default: + break; + } + + return rep; +} + +static const struct scmi_event base_events[] = { + { + .evt_id = BASE_ERROR_EVENT, + .max_payld_sz = 8192, + .max_report_sz = sizeof(struct scmi_base_error_report), + }, +}; + +static const struct scmi_protocol_event_ops base_event_ops = { + .set_notify_enabled = scmi_base_set_notify_enabled, + .fill_custom_report = scmi_base_fill_custom_report, +}; + int scmi_base_protocol_init(struct scmi_handle *h) { int id, ret; @@ -256,10 +363,17 @@ int scmi_base_protocol_init(struct scmi_handle *h) dev_dbg(dev, "Found %d protocol(s) %d agent(s)\n", rev->num_protocols, rev->num_agents); + scmi_register_protocol_events(handle->dev, + SCMI_PROTOCOL_BASE, (4 * PAGE_SIZE), + &base_event_ops, base_events, + ARRAY_SIZE(base_events), + SCMI_BASE_NUM_SOURCES); + for (id = 0; id < rev->num_agents; id++) { scmi_base_discover_agent_get(handle, id, name); dev_dbg(dev, "Agent %d: %s\n", id, name); } + protocol_handle = handle; return 0; } diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index e6d4fc01d560..16b184a36c22 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -424,4 +424,12 @@ struct scmi_reset_issued_report { u32 reset_state; }; +struct scmi_base_error_report { + ktime_t timestamp; + u32 agent_id; + bool fatal; + u16 cmd_count; + u64 reports[8192]; +}; + #endif /* _LINUX_SCMI_PROTOCOL_H */