Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp941278rdf; Fri, 3 Nov 2023 23:48:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUYlVe46pHYbnM/akvFZxg6Uosx+4zOk7apdyylksf2BIhpnNaX1O+CrXT/n30vCnGyeuw X-Received: by 2002:a05:6214:1d04:b0:66f:bb3d:b02d with SMTP id e4-20020a0562141d0400b0066fbb3db02dmr12914044qvd.16.1699080487629; Fri, 03 Nov 2023 23:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699080487; cv=none; d=google.com; s=arc-20160816; b=MowIyzZU4/dOYYR3Ze5uGOxudTlCqt6v9Jp/G4NZhSoVv6rGQftRYCRWnN4VG3n2oU diYTvsS1syJnvbAxT9WO6HAJHJpqI8GkagatzieiAoIjyUZ1QhtaPk4vdF/Ap0Xx1W0T 5Twi9liRXJHqhBu/pi2B/54f/4DRrDtsQy6QwtvggRB7RGwwMAk1+Rm8LgI+wJNe58wL jvfDAab9//ZoN6rLMZBCDS2ywM+BG9NYosr4fzPahFGdSQbVrcmL3SgnViiga1LY3B0t pFlyKApwEgZBbHQksoAiTO5h1sG5YqoH/v1avPNlRusbEO+jwXRribxMdbyck9PrPSnC kWmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=HOr5YFxqngkf4s7Pho5cobKMiAKu9hrPyTwYmmJrnrY=; fh=d3qej8N8oEwoDi4946F/IhSPaeU492mqImsNcFeFjcI=; b=YDQ8ajrhEYKXyb/bpoUsCWGGXOoaR6Rraj3meKYE4BR4O66olPYrIDVPiZP4BK4P+G uxu5Y57UhKVjzLxv+7s7iQdFvpD/2HibJ96jNQsSbk+NSDuFO7oY+rMz/3DbR5chHJvo 1ebaHcceoSgCaLo3y8AEpylnOm3KtF1cvXaYEUz2cpXiYC+tiL2N5Ssq8SGH/aq30/oY quNF11QnKv/J36zPXECIXuGvthR8mTU8T0+b4On8a7HmGuVlKON+FtdNZtnhn/RA/E82 w9NjiCz1PAvWtblgeG5cowl0cgxs5CVIe4lFJ0LmdZ87LpCPgHHRk3IOZJtHzXQxbke3 aoMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id l7-20020a63ba47000000b005b7364d5dbfsi3165216pgu.49.2023.11.03.23.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 23:48:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D2CCE80AE226; Fri, 3 Nov 2023 23:47:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbjKDGr2 (ORCPT + 99 others); Sat, 4 Nov 2023 02:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjKDGr1 (ORCPT ); Sat, 4 Nov 2023 02:47:27 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D6D51B9; Fri, 3 Nov 2023 23:47:23 -0700 (PDT) Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SMp7m5zRbz4f3lVR; Sat, 4 Nov 2023 14:47:16 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 764561A016F; Sat, 4 Nov 2023 14:47:20 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.107]) by APP4 (Coremail) with SMTP id gCh0CgDnfd3z6EVlglQtEw--.50758S6; Sat, 04 Nov 2023 14:47:20 +0800 (CST) From: Zhang Xiaoxu To: zhangxiaoxu5@huawei.com, weiyongjun1@huawei.com, broonie@kernel.org, rostedt@goodmis.org, mingo@redhat.com, frowand.list@gmail.com, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer Date: Sat, 4 Nov 2023 14:46:47 +0800 Message-Id: <20231104064650.972687-3-zhangxiaoxu@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231104064650.972687-1-zhangxiaoxu@huaweicloud.com> References: <20231104064650.972687-1-zhangxiaoxu@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgDnfd3z6EVlglQtEw--.50758S6 X-Coremail-Antispam: 1UD129KBjvJXoWxWryrZF4rZF4rZF4UKr1UAwb_yoW7Jw1UpF yUCF45KrW8Jw429F4furW8Ary3Aa1kurW7K3sI9wnIyr1UtF1kXa1qgry5tFy8JrsrKFyU uFZ2kryjkr45Zw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxU2-B_UUUUU X-CM-SenderInfo: x2kd0wp0ld053x6k3tpzhluzxrxghudrp/ X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 03 Nov 2023 23:47:47 -0700 (PDT) From: Zhang Xiaoxu Add writeable tracepoint for transfer_one_message(), then bpf program can be used to control read and write data from spi host, as mockup chip's expectation. For example: #include "vmlinux.h" #include #include SEC("raw_tp.w/spi_transfer_writeable") int BPF_PROG(spi_transfer_writeable_test, struct spi_msg_ctx *msg, u8 chip, unsigned int len) { if (msg->tx_nbits) msg->data[0] = 0x20; return 0; } char LICENSE[] SEC("license") = "GPL"; This will be useful for writing spi device mockup backend. Signed-off-by: Wei Yongjun Signed-off-by: Zhang Xiaoxu --- drivers/spi/Kconfig | 1 + drivers/spi/spi-mockup.c | 52 +++++++++++++++++++++++++++++-- include/linux/spi/spi-mockup.h | 17 ++++++++++ include/trace/events/spi_mockup.h | 31 ++++++++++++++++++ 4 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 include/linux/spi/spi-mockup.h create mode 100644 include/trace/events/spi_mockup.h diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 9169081cfecb..871e3824b8eb 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -1221,6 +1221,7 @@ config SPI_TLE62X0 config SPI_MOCKUP tristate "SPI controller Testing Driver" depends on OF + select BPF_EVENTS help This enables SPI controller testing driver, which provides a way to test SPI subsystem. diff --git a/drivers/spi/spi-mockup.c b/drivers/spi/spi-mockup.c index 683a0fc43f0d..fcaaa61bdb38 100644 --- a/drivers/spi/spi-mockup.c +++ b/drivers/spi/spi-mockup.c @@ -13,6 +13,9 @@ #include #include +#define CREATE_TRACE_POINTS +#include + #define MOCKUP_CHIPSELECT_MAX 8 struct mockup_spi { @@ -149,13 +152,58 @@ static struct attribute *spi_mockup_attrs[] = { }; ATTRIBUTE_GROUPS(spi_mockup); +static int spi_mockup_transfer_writeable(struct spi_message *msg) +{ + struct spi_msg_ctx *ctx; + struct spi_transfer *t; + int ret = 0; + + ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC); + if (!ctx) + return -ENOMEM; + + list_for_each_entry(t, &msg->transfers, transfer_list) { + if (t->len > SPI_BUFSIZ_MAX) + return -E2BIG; + + memset(ctx, 0, sizeof(*ctx)); + ctx->cs_off = t->cs_off; + ctx->cs_change = t->cs_change; + ctx->tx_nbits = t->tx_nbits; + ctx->rx_nbits = t->rx_nbits; + + if (t->tx_nbits) + memcpy(ctx->data, t->tx_buf, t->len); + + trace_spi_transfer_writeable(ctx, msg->spi->chip_select, t->len); + + if (ctx->ret) { + ret = ctx->ret; + break; + } + + if (t->rx_nbits) + memcpy(t->rx_buf, ctx->data, t->len); + msg->actual_length += t->len; + } + + kfree(ctx); + + return ret; +} + static int spi_mockup_transfer(struct spi_controller *ctrl, struct spi_message *msg) { - msg->status = 0; + int ret = 0; + + if (trace_spi_transfer_writeable_enabled()) + ret = spi_mockup_transfer_writeable(msg); + + msg->status = ret; spi_finalize_current_message(ctrl); - return 0; + return ret; } static int spi_mockup_probe(struct platform_device *pdev) diff --git a/include/linux/spi/spi-mockup.h b/include/linux/spi/spi-mockup.h new file mode 100644 index 000000000000..224894b416fb --- /dev/null +++ b/include/linux/spi/spi-mockup.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LINUX_SPI_MOCKUP_H +#define __LINUX_SPI_MOCKUP_H + +#define SPI_BUFSIZ_MAX 0x1000 + +struct spi_msg_ctx { + int ret; + unsigned cs_off:1; + unsigned cs_change:1; + unsigned tx_nbits:3; + unsigned rx_nbits:3; + __u8 data[SPI_BUFSIZ_MAX]; +}; + +#endif diff --git a/include/trace/events/spi_mockup.h b/include/trace/events/spi_mockup.h new file mode 100644 index 000000000000..46debf26a5e3 --- /dev/null +++ b/include/trace/events/spi_mockup.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * SPI mockup controller transfer writeable tracepoint + * + * Copyright(c) 2022 Huawei Technologies Co., Ltd. + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM spi_mockup + +#if !defined(_TRACE_SPI_MOCKUP_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_SPI_MOCKUP_H + +#include +#include + +#ifndef DECLARE_TRACE_WRITABLE +#define DECLARE_TRACE_WRITABLE(call, proto, args, size) \ + DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) +#endif + +DECLARE_TRACE_WRITABLE(spi_transfer_writeable, + TP_PROTO(struct spi_msg_ctx *msg, u8 chip_select, unsigned int len), + TP_ARGS(msg, chip_select, len), + sizeof(struct spi_msg_ctx) +); + +#endif /* _TRACE_SPI_MOCKUP_H */ + +/* This part must be outside protection */ +#include -- 2.34.1