From nobody Mon Jun 29 08:58:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41828C433FE for ; Sat, 12 Feb 2022 02:31:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbiBLCbG (ORCPT ); Fri, 11 Feb 2022 21:31:06 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbiBLCbC (ORCPT ); Fri, 11 Feb 2022 21:31:02 -0500 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B80932252E for ; Fri, 11 Feb 2022 18:30:55 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id E01A73200EF5; Fri, 11 Feb 2022 21:21:41 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 11 Feb 2022 21:21:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; bh=JWFE8l2LwYg3yX aZ5RQpFz+ELRAlfDvXI+Y8nvTXfcI=; b=SU9TfOAmfOd2RM33aQTVx90C+2btNl kbRTDHWoFEdvBSZd8FVCz22OvfVC43SD+AHe8K2KPqsLguMYkUtkrmJHVsElN+Xb deAYrDCFEnnZvtKbqomgnvu4npNvGbG929/fDNSheun87gvFZANqIyEOQ60IThnZ JXJgVvY2EvqF6d5OUCUSpZDNcNFJCjApibBQXqQ93VVfV0w1CJNblvcfM9aCtQDo JWsgkYyKDTsLk4Sm3FI6IC6+Oh+88exeCqrG3x4wGEdxQ9HEE/WbjqYPySR5we+D zKTPCeR0P0whGf837YCyA/lh5qLceXOv1x8RkpSctICKGZeESL4QuJaA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=JWFE8l 2LwYg3yXaZ5RQpFz+ELRAlfDvXI+Y8nvTXfcI=; b=iybvG0IkqLctK1+15AJAw/ W3C6vogCbXckVWkMJSUYxy/1Sr0pnYh5vQ23zfgxuvHxyUWB0go30Eyaa6JlTssk DBJF0gTam3pggSg/BPwkNNcEpj6JEXNwqgWBJ8E41kcAx9HAEsP6NJFeM3hqS3iy si+YK1106ucaPdIYl5ZoI6L5UbrUPuIU8wfjj61DllkOnjOB86TbzKzckqrIR/Xz MQ1ksJWYKpHFm2mJjdDHgAxDbg9//0Og8O7wbl4ZXCsQ2JAvS7WsWKuRszHwNWjF 9zYXl8lSZYWIj6Q9NtV3b4hn/R02yb5cl9XrSzPY28gpH0Q6ebrkwXcuNjujz5iw == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrieeggdeghecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghkrghs hhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeevfefffeekte fgveegfeelheffhfeujedtjeevtefhkeevkedtjeejvddtjefhjeenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhisehsrg hkrghmohgttghhihdrjhhp X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 11 Feb 2022 21:21:39 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, clemens@ladisch.de, alsa-devel@alsa-project.org, Hector Martin Subject: [PATCH v2 1/3] firewire: Add dummy read_csr/write_csr functions Date: Sat, 12 Feb 2022 11:21:29 +0900 Message-Id: <20220212022131.199855-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220212022131.199855-1-o-takashi@sakamocchi.jp> References: <20220212022131.199855-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Hector Martin (Hector Martin wrote) This fixes segfaults when a card gets yanked off of the PCIe bus while busy, e.g. with a userspace app trying to get the cycle time: [8638860.994310] Call Trace: [8638860.994313] ioctl_get_cycle_timer2+0x4f/0xd0 [firewire_core] [8638860.994323] fw_device_op_ioctl+0xae/0x150 [firewire_core] [8638860.994328] __x64_sys_ioctl+0x7d/0xb0 [8638860.994332] do_syscall_64+0x45/0x80 [8638860.994337] entry_SYSCALL_64_after_hwframe+0x44/0xae (Takashi Sakamoto wrote) As long as reading commit 20802224298c ("firewire: core: add forgotten dummy driver methods, remove unused ones"), three functions are not implemeted in dummy driver for reason; .read_csr, .write_csr, and .set_config_rom. In core of Linux FireWire subsystem, the callback of .set_config_rom is under acquisition of mutual exclusive for local list of card. The acquision is also done in process for removal of card, therefore it's safe for missing implementation of .set_config_rom. On the other hand, no lock primitive accompanies any call of .read_csr and .write_csr. For userspace client, check of node shutdown is done in the beginning of dispatch of ioctl request, while node shifts to shutdown state in workqueue context enough after card shifts to dummy driver. It's probable that these two functions are called for the dummy driver by the code of userspace client. In-kernel unit driver has similar situation. It's better to add implementation of the two functions for dummy driver. Signed-off-by: Hector Martin --- drivers/firewire/core-card.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index 54be88167c60..d994da6cf465 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -616,6 +616,15 @@ static struct fw_iso_context *dummy_allocate_iso_conte= xt(struct fw_card *card, return ERR_PTR(-ENODEV); } =20 +static u32 dummy_read_csr(struct fw_card *card, int csr_offset) +{ + return 0; +} + +static void dummy_write_csr(struct fw_card *card, int csr_offset, u32 valu= e) +{ +} + static int dummy_start_iso(struct fw_iso_context *ctx, s32 cycle, u32 sync, u32 tags) { @@ -649,6 +658,8 @@ static const struct fw_card_driver dummy_driver_templat= e =3D { .send_response =3D dummy_send_response, .cancel_packet =3D dummy_cancel_packet, .enable_phys_dma =3D dummy_enable_phys_dma, + .read_csr =3D dummy_read_csr, + .write_csr =3D dummy_write_csr, .allocate_iso_context =3D dummy_allocate_iso_context, .start_iso =3D dummy_start_iso, .set_iso_channels =3D dummy_set_iso_channels, --=20 2.32.0 From nobody Mon Jun 29 08:58:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49515C433F5 for ; Sat, 12 Feb 2022 02:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230186AbiBLCbI (ORCPT ); Fri, 11 Feb 2022 21:31:08 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbiBLCbD (ORCPT ); Fri, 11 Feb 2022 21:31:03 -0500 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7DB622529 for ; Fri, 11 Feb 2022 18:30:55 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id B5CDE3201DDC; Fri, 11 Feb 2022 21:21:44 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 11 Feb 2022 21:21:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; bh=CKPMl2YxUJUh2M qSztvTrLvGYfWLn3bjixL4oc5KIsM=; b=OuMe0BbOfP9poZT+guPdF3YNbgMbAD XFni9CzYDZO2X48OyHVqnxTdCHaPrgF1hlebeubCHqah8fP5bqcDzEaHNYVfHjtG nQaNbcvxjgK9BPh7ZiuemIXaDeo17Teyn7pP+ny6ROEAMN+qNKL+HRaL76hX7lmx LPF77Wp8UBAyyFWo5v19ttYZ6qEwP42pgf++Wex0ufvfU1ibhBCbk4AwvNGZzjOd N+mIti5u/BM48N4Ho7HmAHvn5twBmpmPTfc9SYVXayiGAsc8+ITr+V8i62KyUfwH DrWUnOVZ4sFIgqvO7AiXeInqjBiBazAAsW5TkwST0vVQFX797RQr3FcQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=CKPMl2 YxUJUh2MqSztvTrLvGYfWLn3bjixL4oc5KIsM=; b=IA5Mjd75FFWv3zcsM/MRmh 0CAzN7AHjntOcOZ3rJFSw/92j18ID2pkp7BN2WInWS0pTMkQn85gFMML5q1U8Y39 IlbN1LA3y7dhhSrpQ9c1A+2C82m0GwTkUKn/HcwADdyLgrspyMMhPyKMy8MfO6Oe JLl5jhR7jQFZ1eb5ybNps8usaAg9MvXIhBazY3T5xN/lf0sVHWgPHEAlhU5kLt+z Js8SyXoisTLzNFtPOKNbCpnKPNIuORESZqQ5Vl2ByNOE7lrHHsq4ecdSpj8wD8GF odE54004y4l33YY1TNltKaU5VCbg5agkBL+GDq3/rLYR4NhAmPRzkqKqNmQslFQA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrieeggdeghecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghkrghs hhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeevfefffeekte fgveegfeelheffhfeujedtjeevtefhkeevkedtjeejvddtjefhjeenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhisehsrg hkrghmohgttghhihdrjhhp X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 11 Feb 2022 21:21:42 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, clemens@ladisch.de, alsa-devel@alsa-project.org Subject: [PATCH v2 2/3] firewire: add kernel API to access CYCLE_TIME register Date: Sat, 12 Feb 2022 11:21:30 +0900 Message-Id: <20220212022131.199855-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220212022131.199855-1-o-takashi@sakamocchi.jp> References: <20220212022131.199855-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 1394 OHCI specification defined Isochronous Cycle Timer Register to get value of CYCLE_TIME register defined by IEEE 1394 for CSR architecture defined by ISO/IEC 13213. Unit driver can calculate packet time by compute with the value of CYCLE_TIME and timeStamp field in descriptor of each isochronous and asynchronous context. The resolution of CYCLE_TIME is 49.576 MHz, while the one of timeStamp is 8,000 Hz. Current implementation of Linux FireWire subsystem allows the driver to get the value of CYCLE_TIMER CSR register by transaction service. The transaction service has overhead in regard of access to MMIO register. This commit adds kernel API for unit driver to access the register directly. --- drivers/firewire/core-card.c | 28 ++++++++++++++++++++++++++++ drivers/firewire/core-cdev.c | 6 ++++-- include/linux/firewire.h | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index d994da6cf465..cd09de61bc4f 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -702,3 +702,31 @@ void fw_core_remove_card(struct fw_card *card) WARN_ON(!list_empty(&card->transaction_list)); } EXPORT_SYMBOL(fw_core_remove_card); + +/** + * fw_card_read_cycle_time: read from Isochronous Cycle Timer Register of = 1394 OHCI in MMIO region + * for controller card. + * @card: The instance of card for 1394 OHCI controller. + * @cycle_time: The mutual reference to value of cycle time for the read o= peration. + * + * Read value from Isochronous Cycle Timer Register of 1394 OHCI in MMIO r= egion for the given + * controller card. This function accesses the region without any lock pri= mitives or IRQ mask. + * When returning successfully, the content of @value argument has value a= ligned to host endianness, + * formetted by CYCLE_TIME CSR Register of IEEE 1394 std. + * + * Context: Any context. + * Return: + * * 0 - Read successfully. + * * -ENODEV - The controller is unavailable due to being removed or unbou= nd. + */ +int fw_card_read_cycle_time(struct fw_card *card, u32 *cycle_time) +{ + if (card->driver->read_csr =3D=3D dummy_read_csr) + return -ENODEV; + + // It's possible to switch to dummy driver between the above and the belo= w. This is the best + // effort to return -ENODEV. + *cycle_time =3D card->driver->read_csr(card, CSR_CYCLE_TIME); + return 0; +} +EXPORT_SYMBOL_GPL(fw_card_read_cycle_time); diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 9f89c17730b1..8e9670036e5c 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -1216,7 +1216,9 @@ static int ioctl_get_cycle_timer2(struct client *clie= nt, union ioctl_arg *arg) =20 local_irq_disable(); =20 - cycle_time =3D card->driver->read_csr(card, CSR_CYCLE_TIME); + ret =3D fw_card_read_cycle_time(card, &cycle_time); + if (ret < 0) + goto end; =20 switch (a->clk_id) { case CLOCK_REALTIME: ktime_get_real_ts64(&ts); break; @@ -1225,7 +1227,7 @@ static int ioctl_get_cycle_timer2(struct client *clie= nt, union ioctl_arg *arg) default: ret =3D -EINVAL; } - +end: local_irq_enable(); =20 a->tv_sec =3D ts.tv_sec; diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 07967a450eaa..2f467c52bdec 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -150,6 +150,8 @@ static inline void fw_card_put(struct fw_card *card) kref_put(&card->kref, fw_card_release); } =20 +int fw_card_read_cycle_time(struct fw_card *card, u32 *cycle_time); + struct fw_attribute_group { struct attribute_group *groups[2]; struct attribute_group group; --=20 2.32.0 From nobody Mon Jun 29 08:58:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D059C433EF for ; Sat, 12 Feb 2022 02:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230221AbiBLCbM (ORCPT ); Fri, 11 Feb 2022 21:31:12 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbiBLCbD (ORCPT ); Fri, 11 Feb 2022 21:31:03 -0500 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B789722528 for ; Fri, 11 Feb 2022 18:30:55 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 6B5353201DBF; Fri, 11 Feb 2022 21:21:47 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 11 Feb 2022 21:21:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; bh=IERouoOAZT+69o dSGZES8xOT3FLde6UiHl1oXWy+mRQ=; b=eyyJmmKSjgIH15wxeePanwMPcsB9JE UyYy6JS7gpri7o+4dwyS+E+P8itcmD7DF2lIDg3pFIT/JGm4Wi0Thagxsy+QJL9y 2EAtCTO27wnBpHby3Wa3OAP63KKhuR3K/UcyqJ90YKx2+/9xg1itN+jUK4VGQ4Gk zGD5EGxhyWALNrrYYME18Hp9IgyC29JmG4ZT4qGw5Q+B4K3DIe5P8x1U8lZfBTGy 7aVPuPuctkYusTLBRhwdS+qMN8jIVRA/RUAcNkjCK1zWpIitV7YrSvD1GHDlo/XV jeEmvW9HdH3ecG2+QbBTUh52rorLvCThukwb99v0wFWc3A+OuW7LciOg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=IERouo OAZT+69odSGZES8xOT3FLde6UiHl1oXWy+mRQ=; b=IMWpl2DjkcwCiIiQDfj/8J sq9kUaYeSy/4hHZjR/Fsu3DlrIAG+NteM3IzQRzR6QQIaGV0wyL3wDnCuTNY51za Y6XL8BPHPu0fBOwT0DScH3+t6kLIpI4IewtBBdinetxIO0KHRML5imQmEXJUPrR4 H4PULL4vaCE3ptJvsw/4oNmeHvYl1PyR4EvzTn/sEFPsONtkZVaPezTneIl5rxfZ Hn+V9E4557T6dmM8tCmzRFYcoM1NZk8R0pnW7xFPd7TqigxX6NQnnHRo2RJ14YQg hPBkbDoef3CaLsHhZZ1nBFLYhAYGOJWNCk82XBIAno6ScqStFWDM6lbkTczX7BRQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrieeggdeghecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghkrghs hhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeevfefffeekte fgveegfeelheffhfeujedtjeevtefhkeevkedtjeejvddtjefhjeenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhisehsrg hkrghmohgttghhihdrjhhp X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 11 Feb 2022 21:21:45 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, clemens@ladisch.de, alsa-devel@alsa-project.org Subject: [PATCH v2 3/3] firewire: add kernel API to access packet structure in request structure for AR context Date: Sat, 12 Feb 2022 11:21:31 +0900 Message-Id: <20220212022131.199855-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220212022131.199855-1-o-takashi@sakamocchi.jp> References: <20220212022131.199855-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In 1394 OHCI specification, descriptor of Asynchronous Receive DMA context has timeStamp field in its trailer quadlet. The field is written by the host controller for the time to receive asynchronous request subaction in isochronous cycle time. In Linux FireWire subsystem, the value of field is stored to fw_packet structure and copied to fw_request structure as the part. The fw_request structure is hidden from unit driver and passed as opaque pointer when calling registered handler. It's inconvenient to the unit driver which needs timestamp of packet. This commit adds kernel API to pick up timestamp from opaque pointer to fw_request structure. --- drivers/firewire/core-transaction.c | 18 ++++++++++++++++++ include/linux/firewire.h | 1 + 2 files changed, 19 insertions(+) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index ac487c96bb71..e12a0a4c33f7 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -619,6 +619,7 @@ struct fw_request { struct fw_packet response; u32 request_header[4]; int ack; + u32 timestamp; u32 length; u32 data[]; }; @@ -788,6 +789,7 @@ static struct fw_request *allocate_request(struct fw_ca= rd *card, request->response.ack =3D 0; request->response.callback =3D free_response_callback; request->ack =3D p->ack; + request->timestamp =3D p->timestamp; request->length =3D length; if (data) memcpy(request->data, data, length); @@ -832,6 +834,22 @@ int fw_get_request_speed(struct fw_request *request) } EXPORT_SYMBOL(fw_get_request_speed); =20 +/** + * fw_request_get_timestamp: Get timestamp of the request. + * @request: The opaque pointer to request structure. + * + * Get timestamp when 1394 OHCI controller receives the asynchronous reque= st subaction. The + * timestamp consists of the low order 3 bits of second field and the full= 13 bits of count + * field of isochronous cycle time register. + * + * Returns: timestamp of the request. + */ +u32 fw_request_get_timestamp(const struct fw_request *request) +{ + return request->timestamp; +} +EXPORT_SYMBOL_GPL(fw_request_get_timestamp); + static void handle_exclusive_region_request(struct fw_card *card, struct fw_packet *p, struct fw_request *request, diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 2f467c52bdec..980019053e54 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -354,6 +354,7 @@ void fw_core_remove_address_handler(struct fw_address_h= andler *handler); void fw_send_response(struct fw_card *card, struct fw_request *request, int rcode); int fw_get_request_speed(struct fw_request *request); +u32 fw_request_get_timestamp(const struct fw_request *request); void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, int destination_id, int generation, int speed, unsigned long long offset, void *payload, size_t length, --=20 2.32.0