From patchwork Sun Nov 22 20:29:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 11923987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7223CC63777 for ; Sun, 22 Nov 2020 20:32:17 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 15A8420776 for ; Sun, 22 Nov 2020 20:32:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="S0czN5Kj"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N4ywAcKD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15A8420776 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References:List-Owner; bh=jQteVGesjA8fqCp2yl3XurmfJTg46LZIpqAe3z35zG8=; b=S0czN5Kj28EJmg5S7dn3ycBgQi vD//503NQi+44N/WLuZfKFtedPWTh43LinEI1hBFXGbQqOVhDdxDMdVfjmSPYktu5+OgfBg/NCiSG NH5LJYJRdlT4CeGEdoDjSsIdbdMqmn8vBiiI7qM8qICzuaUX0kuQmFUGqVKR2U7E0g8CiabukD560 E7B1kcOGea7pRctjwUmunBdvmpToy4w0wo5SYUoN5KBxRdlx/4Svrz9bxh4kBFbDxaaxsGccktREw uFdHGIqP0kXFpoIQXiNpC7DAnknQr1RVgelTPHvOXrkJ5lX/VV1t/IE0Cl/UdPrdklajg2ZcCZOvv jDdIB3vQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kgvzy-000360-BA; Sun, 22 Nov 2020 20:30:14 +0000 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kgvzw-00035V-6A for linux-arm-kernel@lists.infradead.org; Sun, 22 Nov 2020 20:30:13 +0000 Received: by mail-qk1-x72c.google.com with SMTP id z188so3319167qke.9 for ; Sun, 22 Nov 2020 12:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kFhanjy6cq9u6pCyJCDCCRZRA7jLll7R0Ehj4TdK5o0=; b=N4ywAcKD2IvWeShu0qjc9ql+G8i0AyKLEQGeqLAX04FUo8WFkupSvGjf6I5PinnkpY 6KF9/k1gOcY832IArpj9f/54rNcebtRsmh9n08YwLmQ7IBG/CP7foNwWTRLJgxlX6mzr Pku/98VSxlAXi9yWYKctM+f3tJkZw4PD7GZ9LPC2p6ZoxxE7QH8/5zgABnVb5DbzG9pi u/y3d9WNjqhT+gldyR6dsHZyXEXAyQnISKn1cTo5MWlG8VkhpDFzuLKAExbe0VOhP61b 5PzZKvHVYWp9bojqZYUSAL0c1x9B1eGZZ8h+vXtfzHv/aeSconyzYn5a2mgkD7hIOFrW vvBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kFhanjy6cq9u6pCyJCDCCRZRA7jLll7R0Ehj4TdK5o0=; b=pjsrsuGfulk438gBDbqlrpTpSr58u95NrckA9ySKODUOoW0gZZPEjKv8gA+qRilWpc 6qE6LPi82PlVgKtUwitpvLWnnR4warRNx1In7HD+6H60F9XRYULuA5+4flI8d0vxxo5r O/ZfDwjcrEswVSDbHA3ofkDSYmJxOjpYtOAE+FqQZ2AYGY4NtT4dt7EMQrTexYeu0Yi9 +60sgyCJ6jH5vht/UVMJb1icyhlWtNdvKi2QusrH+vr13RhEtymYmNKnQPtErZTz0RI7 QGfCRKLlesnhSyEum8532CllGXgETHaFxjNkTPhAheUpqOdc4Svy6mQ9cUueTQ0IDzMm 4Raw== X-Gm-Message-State: AOAM531Zc6WsmwG1twqpHBpueR5OFedCTJ0IoJU6ZEo/ZdTBuhag3Qk5 02AJG+E88kErK1D0zGHEroI= X-Google-Smtp-Source: ABdhPJzq54eLjNm5Ffz3tvoJrUF/q/GsxjpylgX1f2FqFwqX4injx0UeWHvV3YrXi1CDe/3CrnEYaQ== X-Received: by 2002:a37:5103:: with SMTP id f3mr6622004qkb.460.1606077010337; Sun, 22 Nov 2020 12:30:10 -0800 (PST) Received: from localhost.localdomain (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id p73sm7446522qka.79.2020.11.22.12.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2020 12:30:09 -0800 (PST) From: William Breathitt Gray To: jic23@kernel.org Subject: [PATCH v6 0/5] Introduce the Counter character device interface Date: Sun, 22 Nov 2020 15:29:51 -0500 Message-Id: X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201122_153012_361202_6AE64B76 X-CRM114-Status: GOOD ( 26.59 ) 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: kamel.bouhara@bootlin.com, gwendal@chromium.org, a.fatoum@pengutronix.de, david@lechnology.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, mcoquelin.stm32@gmail.com, linux-kernel@vger.kernel.org, kernel@pengutronix.de, William Breathitt Gray , fabrice.gasnier@st.com, syednwaris@gmail.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, alexandre.torgue@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Changes in v6: - Consolidated the value member of struct counter_event down to a single u64; u64 should be capable of representing all component values - Removed extension width sysfs attributes; no longer needed when value is always u64 - Implemented COUNTER_COMPONENT_DUMMY to allow timestamp grabs without component data reads - Implemented events_config() callback; called during COUNTER_CLEAR_WATCHES_IOCTL and COUNTER_LOAD_WATCHES_IOCTL in order to allow devices a chance to adjust (enable/disable IRQ, etc.) for the new events configuration requested by the user - Simplified example code in Documentation by removing confusing use of poll() call - Removed redundant ida_simple_remove() from counter_register() - Renamed devm_counter_unreg() to devm_counter_unregister() - Renamed functions in counter-sysfs.c to be clearer - Fixed miscellaneous typos throughout files - Added more kernel doc comments; I've left some defines without comments if they seemed obvious -- but please let me know if further documentation is needed - Refactored quad8_irq_handler() to use WARN_ONCE() instead of returning on error; this should prevent interrupts from entering an endless loop - General refactoring and additional comments for clarity - Returns EOPNOTSUPP instead of EFAULT now if a Counter watch is added for unsupported component - Renamed COUNTER_SET_WATCH_IOCTL TO COUNTER_ADD_WATCH_IOCTL to make the use clear - Reimplemented the parent and id members of struct counter_component as __u8 instead of __u64; it's unlikely we'll ever have a device that supports more than 255 components - Reimplement __u64 variables in include/uapi/linux/counter.h as __aligned_u64 to prevent 32-bit vs 64-bit alignment issues - Fixed return value bug in counter_comp_u8_store(); enums set to a value with index > 0 should now work correctly - Fixed spectre issues in counter-chrdev.c - Removed redundant get_device() call from counter_register() - Moved put_device() to after the events_list is freed lest we leak memory I'm skipping the introduction blurb because it was just a rehashing of information included in the documentation patches within this patchset. Instead I will focus this cover letter on discussions about this patchset and the userspace interface implications. 1. Should standard Counter component data types be defined as u8 or u32? Many standard Counter component types such COUNTER_COMP_SIGNAL_LEVEL have standard values defined (e.g. COUNTER_SIGNAL_LEVEL_LOW and COUNTER_SIGNAL_LEVEL_HIGH). These values are currently handled by the Counter subsystem code as u8 data types. If u32 is used for these values instead, C enum structures could be used by driver authors to implicitly cast these values via the driver callback parameters. This question is primarily addressed to David Lechner. I'm somewhat confused about how this setup would look in device drivers. I've gone ahead and refactored the code to support u32 enums, and pushed it to a separate branch on my repository called counter_chrdev_v6_u32_enum: https://gitlab.com/vilhelmgray/iio/-/tree/counter_chrdev_v6_u32_enum Please check it out and let me know what you think. Is this the support you had in mind? I'm curious to see an example of how would your driver callback functions would look in this case. Is everything works out fine, then I'll submit this branch as v7 of this patchset. 2. How should we handle "raw" timestamps? Ahmad Fatoum brought up the possibility of returning "raw" timestamps similar to what the network stack offers (see the network stack SOF_TIMESTAMPING_{RAW,SYS}_HARDWARE support). I'm not very familiar with the networking stack code, but if I understand correctly the SOF_TIMESTAMPING_RAW_HARDWARE timestamps are values returned from the device. If so, I suspect we would be able to support these "raw" timestamps by defining them as Counter Extensions and returning them in struct counter_event elements similar to the other Extension values. William Breathitt Gray (5): counter: Internalize sysfs interface code docs: counter: Update to reflect sysfs internalization counter: Add character device interface docs: counter: Document character device interface counter: 104-quad-8: Add IRQ support for the ACCES 104-QUAD-8 Documentation/ABI/testing/sysfs-bus-counter | 18 +- .../ABI/testing/sysfs-bus-counter-104-quad-8 | 32 + Documentation/driver-api/generic-counter.rst | 411 ++++- .../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 2 +- drivers/counter/104-quad-8.c | 778 +++++---- drivers/counter/Kconfig | 6 +- drivers/counter/Makefile | 1 + drivers/counter/counter-chrdev.c | 476 ++++++ drivers/counter/counter-chrdev.h | 16 + drivers/counter/counter-core.c | 183 ++ drivers/counter/counter-sysfs.c | 806 +++++++++ drivers/counter/counter-sysfs.h | 13 + drivers/counter/counter.c | 1496 ----------------- drivers/counter/ftm-quaddec.c | 60 +- drivers/counter/microchip-tcb-capture.c | 114 +- drivers/counter/stm32-lptimer-cnt.c | 175 +- drivers/counter/stm32-timer-cnt.c | 145 +- drivers/counter/ti-eqep.c | 224 +-- include/linux/counter.h | 676 ++++---- include/linux/counter_enum.h | 45 - include/uapi/linux/counter.h | 105 ++ 22 files changed, 3094 insertions(+), 2689 deletions(-) create mode 100644 drivers/counter/counter-chrdev.c create mode 100644 drivers/counter/counter-chrdev.h create mode 100644 drivers/counter/counter-core.c create mode 100644 drivers/counter/counter-sysfs.c create mode 100644 drivers/counter/counter-sysfs.h delete mode 100644 drivers/counter/counter.c delete mode 100644 include/linux/counter_enum.h create mode 100644 include/uapi/linux/counter.h