From patchwork Tue Jul 21 19:35:46 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: 11676545 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 0617013B1 for ; Tue, 21 Jul 2020 19:38:10 +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 C3E39206C1 for ; Tue, 21 Jul 2020 19:38:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ea4H38rj"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fJImzWua" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3E39206C1 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+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=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=zTxbVbuD3T0WAJCSDktwkVGuOPKuKdAf0BDAaTgVIoU=; b=Ea4H38rj2UhxmhFLV7gt4YjgEd f7ouzHuxn+ogz+Ys3Ga577Y45b1yQITWrlAqgZ0JVUKru8bMiJBOZZKlmvgQJbSsg3vq/ki3s4Z4d MKX1Ubo6ZOj1jSVX8qmXF2KfDapn7pK+MakbOh9iIqfns3q2rjkQjhLUlr+wXd3emEtf3pw8z1zpM wbUD2G5Uwvs0XufECNVCwYbkcSiEbhfZMDDoMki8nBNCC8vxKc3kaD64RcP+GMe5DjWnTqjLZY9TL f1Z9kZp/BePucJ91bWDdSUgC3EDcP7yy9CYUUNpiQxG4moxevCszPCqQtP5Lhw1+WWEO/KRTidskE Kd+CAWYg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxy3h-00012S-EQ; Tue, 21 Jul 2020 19:36:13 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxy3f-00011y-99 for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2020 19:36:12 +0000 Received: by mail-qt1-x842.google.com with SMTP id b25so57284qto.2 for ; Tue, 21 Jul 2020 12:36:09 -0700 (PDT) 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=q7rGcqeaKO7k4itsNk5qHhnQB9CfMz1CeEei7jxa15c=; b=fJImzWua3xh+vbSoJVn0n3E7PGhZCPcwgMGLNoAuVR+N/l13zae7Z+q9j9ensSesqI 1MB88z+61Ra/QsDPCIzqAzIZN6zlfRFmO6E4+emq0dJMuU0OAvQbi/ywL7qw15OlcA2P zvVwRVJeObz51Mi+fmKbpa16lXfxqagrZHMDKIYV9cHUgxX+HlGA6FuBOQ/XdULwSdTl 1dlweGzzxXhWkL5XP+4RfPHKUEIZH/KhquQdoQBRySJZe8IQJEJaQSTX1ECRZtLNJeb9 EzulkKH+yK2IBJ2ObMiVBl7VbNbbToQdy9m5wWIX0irbuYhhSKZA8IEcpDYBPApl1kd+ s2KA== 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=q7rGcqeaKO7k4itsNk5qHhnQB9CfMz1CeEei7jxa15c=; b=NhkDwTpiGRo674k3T9lVtId3kpqBUDgMMIt3qQBxP2nH3VJBSbdg/Vn0zg36zgJSwX BNNLLk/GS4jY6/ZfFOU6b5U8EvQCFilXMwIQTHbk4rrDnE74xeS6y75g2bRJ4ix3hupG fWmAxQ/oUnOLU0iqrnp+7m+lvCue1BJQNG42URgXdPQ8iCraZ43Uh8tU0oM++4A44cc0 YPYUru87qKNJcYpbMTrWaGQ21lwlXnvUfahkLH79Rsg/694HimonVVVq8KjDTBE/Jy6Z MXMg0PeIlfXLmKxebNz1eg/IYgHUwcmSoV4xATOYJFLsA29Ko/Bh+u4MmLe4Q2rgCftr txeg== X-Gm-Message-State: AOAM533x3Q3IF6n7z+Z/7ui2qv3cEdbpbk6CQiUomFiYs5pSGN73w/2D Xiq5LFpC90mp1Tmhyh3xLkbuA4dugkyR1Q== X-Google-Smtp-Source: ABdhPJy2upr/MmRoCYuzhDs6LsS0n7B1rfn3tjkfkvdDtWR4Yw53st1TQCy/HckhwyUXfJ4aRlS2/A== X-Received: by 2002:ac8:2fa9:: with SMTP id l38mr31189613qta.40.1595360168605; Tue, 21 Jul 2020 12:36:08 -0700 (PDT) Received: from localhost.localdomain (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id j72sm3331351qke.20.2020.07.21.12.36.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 12:36:07 -0700 (PDT) From: William Breathitt Gray To: jic23@kernel.org Subject: [PATCH v4 0/5] Introduce the Counter character device interface Date: Tue, 21 Jul 2020 15:35:46 -0400 Message-Id: X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200721_153611_338069_42DC912C X-CRM114-Status: GOOD ( 25.69 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:842 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [vilhelm.gray[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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, david@lechnology.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, mcoquelin.stm32@gmail.com, 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Changes in v4: - Reimplement character device interface to report Counter events - Implement Counter timestamps - Implement poll() support - Convert microchip-tcb-capture.c to new driver interface - Add IRQ support for the 104-quad-8 Counter driver Over the past couple years we have noticed some shortcomings with the Counter sysfs interface. Although useful in the majority of situations, there are certain use-cases where interacting through sysfs attributes can become cumbersome and inefficient. A desire to support more advanced functionality such as timestamps, multi-axes positioning tables, and other such latency-sensitive applications, has motivated a reevaluation of the Counter subsystem. I believe a character device interface will be helpful for this more niche area of counter device use. To quell any concerns from the offset: this patchset makes no changes to the existing Counter sysfs userspace interface -- existing userspace applications will continue to work with no modifications necessary. I request that driver maintainers please test their applications to verify that this is true, and report any discrepancies if they arise. However, this patchset does contain a major reimplementation of the Counter subsystem core and driver API. A reimplementation was necessary in order to separate the sysfs code from the counter device drivers and internalize it as a dedicated component of the core Counter subsystem module. A minor benefit from all of this is that the sysfs interface is now ensured a certain amount of consistency because the translation is performed outside of individual counter device drivers. Essentially, the reimplementation has enabled counter device drivers to pass and handle data as native C datatypes now rather than the sysfs strings from before. A high-level view of how a count value is passed down from a counter device driver can be exemplified by the following: ---------------------- / Counter device \ +----------------------+ | Count register: 0x28 | +----------------------+ | ----------------- / raw count data / ----------------- | V +----------------------------+ | Counter device driver |----------+ +----------------------------+ | | Processes data from device | ------------------- |----------------------------| / driver callbacks / | Type: u64 | ------------------- | Value: 42 | | +----------------------------+ | | | ---------- | / u64 / | ---------- | | | | V | +----------------------+ | | Counter core | | +----------------------+ | | Routes device driver | | | callbacks to the | | | userspace interfaces | | +----------------------+ | | | ------------------- | / driver callbacks / | ------------------- | | +-------+---------------+ | | | | | +-------|-------+ | | | V | V +--------------------+ | +---------------------+ | Counter sysfs |<-+->| Counter chrdev | +--------------------+ +---------------------+ | Translates to the | | Translates to the | | standard Counter | | standard Counter | | sysfs output | | character device | |--------------------| |---------------------+ | Type: const char * | | Type: u64 | | Value: "42" | | Value: 42 | +--------------------+ +---------------------+ | | --------------- ----------------------- / const char * / / struct counter_event / --------------- ----------------------- | | | V | +-----------+ | | read | | +-----------+ | \ Count: 42 / | ----------- | V +--------------------------------------------------+ | `/sys/bus/counter/devices/counterX/countY/count` | +--------------------------------------------------+ \ Count: "42" / -------------------------------------------------- Counter device data is exposed through standard character device read operations. Device data is gathered when a Counter event is pushed by the respective Counter device driver. Configuration is handled via ioctl operations on the respective Counter character device node. The following are some questions I have about this patchset: 1. Should I support multiple file descriptors for the character device in this introduction patchset? I intend to add support for multiple file descriptors to the Counter character device, but I restricted this patchset to a single file descriptor to simplify the code logic for the sake of review. If there is enough interest, I can add support for multiple file descriptors in the next revision; I anticipate that this should be simple to implement through the allocation of a kfifo for each file descriptor during the open callback. 2. Should struct counter_event have a union for different value types, or just a value u8 array? Currently I expose the event data value via a union containing the various possible Counter data types (value_u8 and value_u64). It is up to the user to select the right union member for the data they received. Would it make sense to return this data in a u8 array instead, with the expectation that the user will cast to the necessary data type? 3. How should errors be returned for Counter data reads performed by Counter events? Counter events are configured with a list of Counter data read operations to perform for the user. Any one of those data reads can return an error code, but not necessarily all of them. Currently, the code exits early when an error code is returned. Should the code instead continue on, saving the error code to the struct counter_event for userspace to handle? 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 .../ABI/testing/sysfs-bus-counter-104-quad-8 | 32 + Documentation/driver-api/generic-counter.rst | 363 +++- .../userspace-api/ioctl/ioctl-number.rst | 1 + MAINTAINERS | 2 +- drivers/counter/104-quad-8.c | 753 +++++---- drivers/counter/Kconfig | 6 +- drivers/counter/Makefile | 1 + drivers/counter/counter-chrdev.c | 441 +++++ drivers/counter/counter-chrdev.h | 16 + drivers/counter/counter-core.c | 188 +++ drivers/counter/counter-sysfs.c | 849 ++++++++++ drivers/counter/counter-sysfs.h | 14 + drivers/counter/counter.c | 1496 ----------------- drivers/counter/ftm-quaddec.c | 59 +- drivers/counter/microchip-tcb-capture.c | 104 +- drivers/counter/stm32-lptimer-cnt.c | 161 +- drivers/counter/stm32-timer-cnt.c | 139 +- drivers/counter/ti-eqep.c | 211 +-- include/linux/counter.h | 633 +++---- include/linux/counter_enum.h | 45 - include/uapi/linux/counter.h | 90 + 21 files changed, 2919 insertions(+), 2685 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