From nobody Sun Sep 14 08:09:35 2025 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 9F785C54E94 for ; Wed, 25 Jan 2023 12:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235304AbjAYMDN (ORCPT ); Wed, 25 Jan 2023 07:03:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbjAYMDK (ORCPT ); Wed, 25 Jan 2023 07:03:10 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44BFB568A2 for ; Wed, 25 Jan 2023 04:03:09 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 53C255C0099; Wed, 25 Jan 2023 07:03:08 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 25 Jan 2023 07:03:08 -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; t=1674648188; x= 1674734588; bh=hZ7RuQIyW+uO5lxrWZkD8RA7gqZCCqok8mXl9QhbwOw=; b=I MW2g/5LyJYS+42oOzu3Cj9Vcwc/3YoVkBS3xgk4gAQOxYN9ikRFFIZnDhrbAgZ9r njPluiEfvCP6sxJbJzjXIvX6myT/CN7ewe7MrsUhP0MPmPnSuAgjojZ/+VxMYY9x EMEsMubc/Q8DingX9wY0glifnWMbXKTgxSmOttanpx1e3ASQnf9cXVeTLBHHv0DO mRKNl610cdv6mzlG4TAehH+wpPdcGv7vuHssokKbRm3awZ/ut4E8V2V5IBlGuX4e s4gsyFabmMPVJWpO5hKGsPZTTH6waTMYBLsdc91k3VMd9chMm/3cKjZIinJYA1ra buHX0iCDrQxljOqOZmtow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648188; x=1674734588; bh=hZ7RuQIyW+uO5 lxrWZkD8RA7gqZCCqok8mXl9QhbwOw=; b=FS2mTxpAKmYyZPsbtyJj7pIVmTG/1 X+Nfmzm7cZBuTXTHOx4dghUqSYK84Blmh2mAb8kdJlAgqGc0koX3eQvjLMKA8p1l 9WB/ZU0DOAGKCSrWf75BdTe0sXjjoWpN1XA7bl06HrTKf92hGy69ffuYALH+3dz5 IIrnTI6/BIGyeY4aS4BXqlOtvmNQoWpWBG6C1X3q0MrVLJzMCO2h49Uc1RXqQAsH kijKmPN3/eklgPuiE2KydIP+UyITiIQNfUdKVF6qcXA3S9/L2EFzIG2b2Yq0HNhr VM4vVvwwAT0GPOR0rk3keBOUdu4pBCZ5O82H46MuqpafRLWJ7gNwUA9Rw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:07 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 01/11] firewire: cdev: add new version of ABI to notify time stamp at request/response subaction of transaction Date: Wed, 25 Jan 2023 21:02:51 +0900 Message-Id: <20230125120301.51585-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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" This commit adds new version of ABI for future new events with time stamp for request/response subaction of asynchronous transaction to user space. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 1 + include/uapi/linux/firewire-cdev.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 2c16ee8fd842..88c8b5fac5e5 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -43,6 +43,7 @@ #define FW_CDEV_VERSION_EVENT_REQUEST2 4 #define FW_CDEV_VERSION_ALLOCATE_REGION_END 4 #define FW_CDEV_VERSION_AUTO_FLUSH_ISO_OVERFLOW 5 +#define FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP 6 =20 struct client { u32 version; diff --git a/include/uapi/linux/firewire-cdev.h b/include/uapi/linux/firewi= re-cdev.h index 92be3ea3c6e0..621ee56d11b5 100644 --- a/include/uapi/linux/firewire-cdev.h +++ b/include/uapi/linux/firewire-cdev.h @@ -457,6 +457,7 @@ union fw_cdev_event { * 5 (3.4) - send %FW_CDEV_EVENT_ISO_INTERRUPT events when needed to * avoid dropping data * - added %FW_CDEV_IOC_FLUSH_ISO + * 6 (6.3) - added some event for subactions of asynchronous transac= tion with time stamp */ =20 /** --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 A0CF0C27C76 for ; Wed, 25 Jan 2023 12:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235483AbjAYMDS (ORCPT ); Wed, 25 Jan 2023 07:03:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234264AbjAYMDL (ORCPT ); Wed, 25 Jan 2023 07:03:11 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D78568A7 for ; Wed, 25 Jan 2023 04:03:10 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id CB9305C007C; Wed, 25 Jan 2023 07:03:09 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 25 Jan 2023 07:03:09 -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; t=1674648189; x= 1674734589; bh=mhbmLZ5ifTaOHOF/yXnONpnLZPjUXL3DFTwSnnNSvwY=; b=S B+BYx1yjRqCI0WXovu2K9Q4Zcude4clN/OK82O70XCgjubM4ng9IAcRWy6RbqqZZ 6AWYpsH7QEURWCbTUcIAT0UR3fNqA9R8rBA8Hzr1IT0ZUBYPjVnmkpI2Du8tC65Z F7bchCAAK+hMOyiHUlKPgDSZqXBeXBbtf1eX2ta9+jopIFxa0Jh7erB1VCW602XZ WuThmoMPUJ+M19V42fVWU00h9fZC1UsV0+hu+3L4/Bz99I//vOEnQvoUKVLdiWzA 8M7PP0ZL6CpOP0M7W2ub88qpNeLfY3jnLvNcPbBdMj+cHvW4few8RSXDcPnERvoc XVQufy0VLJbyyFyONPr4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648189; x=1674734589; bh=mhbmLZ5ifTaOH OF/yXnONpnLZPjUXL3DFTwSnnNSvwY=; b=hJUJI5SIP7KEQIwmNhPfPdyhu24dY D06VYrJgQ34jNuaxMteQi5pQx8265GVlSknkSCAIg77ou3w8wtdr2VvAtGAVeSTD xSV5/bVfwEmwnLAS0PQhuTdW3vBWkEuv+wm02VqqK6UO0ed+WgIahZDY1nTyo9yY 5rkQ91IHwlDxjv6FyNYqYsjM2i3jcK6m1vIfDi3HY90l/iCEcqmoTboJ5i5BfHFN VqbPS2WapYD4b/1UknJd9eftDR9ib8Y0Umb8WFZXyy/g9EZpf0ta/MuzYAualS3V 8PCRqOF4WrW31LlEOOGByH91TtjHmSe6onl+S4Z1up0ZdQJTfDEQtLbVA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:08 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 02/11] firewire: cdev: add new event to notify request subaction with time stamp Date: Wed, 25 Jan 2023 21:02:52 +0900 Message-Id: <20230125120301.51585-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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" This commit adds new event to notify event of request subaction with time stamp field. Current compiler implementation of System V ABI selects one of structure members which has the maximum alignment size in the structure to decide the size of structure. In the case of fw_cdev_event_request3 structure, it is closure member which has 8 byte storage. The size of alignment for the type of 8 byte storage differs depending on architectures; 4 byte for i386 architecture and 8 byte for the others including x32 architecture. It is inconvenient to device driver developer to use structure layout which varies between architectures since the developer takes care of ioctl compat layer. This commit adds 32 bit member for padding to keep the size of structure as multiples of 8. Signed-off-by: Takashi Sakamoto --- include/uapi/linux/firewire-cdev.h | 53 ++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/firewire-cdev.h b/include/uapi/linux/firewi= re-cdev.h index 621ee56d11b5..827b226eabb1 100644 --- a/include/uapi/linux/firewire-cdev.h +++ b/include/uapi/linux/firewire-cdev.h @@ -46,6 +46,9 @@ #define FW_CDEV_EVENT_PHY_PACKET_RECEIVED 0x08 #define FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL 0x09 =20 +/* available since kernel version 6.3 */ +#define FW_CDEV_EVENT_REQUEST3 0x0a + /** * struct fw_cdev_event_common - Common part of all fw_cdev_event_* types * @closure: For arbitrary use by userspace @@ -159,6 +162,38 @@ struct fw_cdev_event_request { * @length: Data length, i.e. the request's payload size in bytes * @data: Incoming data, if any * + * This event is sent instead of &fw_cdev_event_request3 if the kernel or = the client implements + * ABI version <=3D 5. It has the lack of time stamp field comparing to &f= w_cdev_event_request3. + */ +struct fw_cdev_event_request2 { + __u64 closure; + __u32 type; + __u32 tcode; + __u64 offset; + __u32 source_node_id; + __u32 destination_node_id; + __u32 card; + __u32 generation; + __u32 handle; + __u32 length; + __u32 data[]; +}; + +/** + * struct fw_cdev_event_request3 - Sent on incoming request to an address = region + * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl + * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2 + * @tcode: Transaction code of the incoming request + * @offset: The offset into the 48-bit per-node address space + * @source_node_id: Sender node ID + * @destination_node_id: Destination node ID + * @card: The index of the card from which the request came + * @generation: Bus generation in which the request is valid + * @handle: Reference to the kernel-side pending request + * @length: Data length, i.e. the request's payload size in bytes + * @tstamp: The time stamp of isochronous cycle at which the request arriv= ed. + * @data: Incoming data, if any + * * This event is sent when the stack receives an incoming request to an ad= dress * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl. The request is * guaranteed to be completely contained in the specified region. Userspa= ce is @@ -191,10 +226,14 @@ struct fw_cdev_event_request { * sent. * * If the client subsequently needs to initiate requests to the sender nod= e of - * an &fw_cdev_event_request2, it needs to use a device file with matching + * an &fw_cdev_event_request3, it needs to use a device file with matching * card index, node ID, and generation for outbound requests. + * + * @tstamp is isochronous cycle at which the request arrived. It is 16 bit= integer value and the + * higher 3 bits expresses three low order bits of second field in the for= mat of CYCLE_TIME + * register and the rest 13 bits expresses cycle field. */ -struct fw_cdev_event_request2 { +struct fw_cdev_event_request3 { __u64 closure; __u32 type; __u32 tcode; @@ -205,6 +244,12 @@ struct fw_cdev_event_request2 { __u32 generation; __u32 handle; __u32 length; + __u32 tstamp; + /* + * Padding to keep the size of structure as multiples of 8 in various arc= hitectures since + * 4 byte alignment is used for 8 byte of object type in System V ABI for= i386 architecture. + */ + __u32 padding; __u32 data[]; }; =20 @@ -375,6 +420,8 @@ struct fw_cdev_event_phy_packet { * %FW_CDEV_EVENT_PHY_PACKET_SENT or * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED * + * @request3: Valid if @common.type =3D=3D %FW_CDEV_EVENT_REQUEST3 + * * Convenience union for userspace use. Events could be read(2) into an * appropriately aligned char buffer and then cast to this union for furth= er * processing. Note that for a request, response or iso_interrupt event, @@ -393,6 +440,7 @@ union fw_cdev_event { struct fw_cdev_event_iso_interrupt_mc iso_interrupt_mc; /* added in 2.6.3= 6 */ struct fw_cdev_event_iso_resource iso_resource; /* added in 2.6.30 */ struct fw_cdev_event_phy_packet phy_packet; /* added in 2.6.36 */ + struct fw_cdev_event_request3 request3; /* added in 6.3 */ }; =20 /* available since kernel version 2.6.22 */ @@ -458,6 +506,7 @@ union fw_cdev_event { * avoid dropping data * - added %FW_CDEV_IOC_FLUSH_ISO * 6 (6.3) - added some event for subactions of asynchronous transac= tion with time stamp + * - %FW_CDEV_EVENT_REQUEST3 */ =20 /** --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 885D9C27C76 for ; Wed, 25 Jan 2023 12:03:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235549AbjAYMDV (ORCPT ); Wed, 25 Jan 2023 07:03:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235247AbjAYMDM (ORCPT ); Wed, 25 Jan 2023 07:03:12 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D95CB5689F for ; Wed, 25 Jan 2023 04:03:11 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 50F5A5C01B0; Wed, 25 Jan 2023 07:03:11 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 25 Jan 2023 07:03:11 -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; t=1674648191; x= 1674734591; bh=vxkfReO71prrNWdj/ls9FxWUEiwc8tsI0fkpO1vRHYI=; b=g CcUsXMhP/iS0ZOgXVGbyoru3SKvETDxPDdO5Ehqp8ekpRZheA6+4TarNidxmBu0y vqpCRqBvfSOfCV5TNmKVutRDatHnzP0DjsCK2Pb79iilVJ8K9OTCfI10F7h42qw+ FMZqZVPJqkW1UNku6VtxOPXZMsYaci47IBfA4zS8Q8IJNx00aspL6/3qBOulcPtu BWb/zRjuvjttyt+05hugR9LU0c/RgPxp1BCIzcJU2b+3/UjuUC2smT69uWlSqPL7 ku5MYIoaoTX0UW4mPyhvdW6EwOPi0dfJpsLPiaOaz8twX4LN6h5qrqMRpLP4BXqV rCo8PYYfjRwpiKYPN4tAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648191; x=1674734591; bh=vxkfReO71prrN Wdj/ls9FxWUEiwc8tsI0fkpO1vRHYI=; b=mX6CP2QGKCJkbigXCYDQZXaVHQfZj AzXuA6i81ltjT2vf/dnG1WMPG2kGki7ljhKcGdpiuGe4TUox5LbV6eisuZVj3xvn NenozAQQkdAnZWDgPnIHQSqw3DiRdP79XMIrUbKY8enIL2UANxXfEWlJwZYlepsE FZL1Xh6/TkWiAB1GnPK9ANHHJrn7TLOSR06xkou/cm3kuwiGxEG0VMcPuVWy0aO1 gNlRcy9DIk9vptIStQ+5KhS35zhI5SfDzMkCHU7GhMcG2QhkxIwvH/wIFKL2jiWu m/D9jzeQuPGckLGzKezl4qSRVfOk3xzAZkPTC6d2vtEoNxiR5okZnQdFg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:09 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 03/11] firewire: cdev: implement new event to notify request subaction with time stamp Date: Wed, 25 Jan 2023 21:02:53 +0900 Message-Id: <20230125120301.51585-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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, the trailer quadlet of descriptor in Asynchronous Receive (AR) request context has timeStamp field, in which the 1394 OHCI controller record the isochronous cycle when the packet arrived. Current implementation of 1394 OHCI controller driver stores the value of field to internal structure as time stamp, while the implementation of FireWire character device doesn't have a field for the time stamp, thus it is not available in user space. The time stamp is convenient to some kind of application in which data from several sources are compared in isochronous cycle unit. This commit implement the new event, fw_cdev_event_request3, with an additional field, tstamp. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 88c8b5fac5e5..5a9446d30447 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -178,6 +178,7 @@ struct inbound_transaction_event { union { struct fw_cdev_event_request request; struct fw_cdev_event_request2 request2; + struct fw_cdev_event_request3 with_tstamp; } req; }; =20 @@ -709,7 +710,7 @@ static void handle_request(struct fw_card *card, struct= fw_request *request, req->handle =3D r->resource.handle; req->closure =3D handler->closure; event_size0 =3D sizeof(*req); - } else { + } else if (handler->client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP)= { struct fw_cdev_event_request2 *req =3D &e->req.request2; =20 req->type =3D FW_CDEV_EVENT_REQUEST2; @@ -723,6 +724,21 @@ static void handle_request(struct fw_card *card, struc= t fw_request *request, req->handle =3D r->resource.handle; req->closure =3D handler->closure; event_size0 =3D sizeof(*req); + } else { + struct fw_cdev_event_request3 *req =3D &e->req.with_tstamp; + + req->type =3D FW_CDEV_EVENT_REQUEST3; + req->tcode =3D tcode; + req->offset =3D offset; + req->source_node_id =3D source; + req->destination_node_id =3D destination; + req->card =3D card->index; + req->generation =3D generation; + req->length =3D length; + req->handle =3D r->resource.handle; + req->closure =3D handler->closure; + req->tstamp =3D fw_request_get_timestamp(request); + event_size0 =3D sizeof(*req); } =20 queue_event(handler->client, &e->event, --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 548ECC54E94 for ; Wed, 25 Jan 2023 12:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235712AbjAYMD0 (ORCPT ); Wed, 25 Jan 2023 07:03:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235358AbjAYMDP (ORCPT ); Wed, 25 Jan 2023 07:03:15 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67B7F568BF for ; Wed, 25 Jan 2023 04:03:13 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id D2DC25C0071; Wed, 25 Jan 2023 07:03:12 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 25 Jan 2023 07:03:12 -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; t=1674648192; x= 1674734592; bh=F/oiWi7cRJV73Nbt/8UWuzBAGbYHl7xZd9sd5G9Zctc=; b=c mcfVXXZNOODMceROvEsX/FZ/y9RRSkfuq6/qi7U2AOAA9kI3YmOB53jy0ubgGD4+ adSSsgE6WnvtkN6+0Dx7SlOUPaQG3hhAuSA7sM3ZDPbjv53lAsX7S16D4L2ugUtr JlWTjLtwwO5QdKzKriQYcMPWFPNiWpdyxOXymk3epY4hSbqsSxTLuxhxUWmY4OfB 01N2ApcCZy8JEnGE++Rdryoo6hN99xVSCRxR1vy8DTSjsutJUxDVBhi3ecrNK9j0 Ri7bApaO5EBCBSq7AMTEiKopfoZasvepN52QodzjkfzUDJWVld/b2NrvOR+VhjiV k0xklMid99WegqIjFTA7g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648192; x=1674734592; bh=F/oiWi7cRJV73 Nbt/8UWuzBAGbYHl7xZd9sd5G9Zctc=; b=fKxDhgz0PGadoyZWgW+twIAzPEZkC LG793D6wCXOzOzo9TvIoqG5rSY54qwEtRjiyI0MKFrPMfk20b6TpQZnpeXzi/oEG PbHBpX9AtV2Ra/IqOX5wBAnPWNcle8fwi2B7lhpNx+kfg/2F0hWMkzxdb+8a1l1u rEbyrnmEMhoymxDbwE6CDgXsRNMl5pD3vkccOdrRXRYbO5JR0mBgP4F5XEOA8h++ q2/tNhtXbjKQeiR5apVIUs52qvoZVFYjRq6wRP0d0OycpjQ+Omwa8OKqjn6eo9ge nM6ly50227eoxygNvunLeJk1il9Fx9MxbrFSJKXwcWlzD2fvuWRTT6rug== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:11 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 04/11] firewire: core: use union for callback of transaction completion Date: Wed, 25 Jan 2023 21:02:54 +0900 Message-Id: <20230125120301.51585-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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, the OUTPUT_LAST descriptor of Asynchronous Transmit (AT) request context has timeStamp field, in which 1394 OHCI controller record the isochronous cycle when the packet was sent for the request subaction. Additionally, for the case of split transaction in IEEE 1394, Asynchronous Receive (AT) request context is used for response subaction to finish the transaction. The trailer quadlet of descriptor in the context has timeStamp field, in which 1394 OHCI controller records the isochronous cycle when the packet arrived. Current implementation of 1394 OHCI controller driver stores values of both fields to internal structure as time stamp, while Linux FireWire subsystem provides no way to access to it. When using asynchronous transaction service provided by the subsystem, callback function is passed to kernel API. The prototype of callback function has the lack of argument for the values. This commit adds a new callback function for the purpose. It has an additional argument to point to the constant array with two elements. For backward compatibility to kernel space, a new union is also adds to wrap two different prototype of callback function. The fw_transaction structure has the union as a member and a boolean flag to express which function callback is available. The core function is changed to handle the two cases; with or without time stamp. For the error path to process transaction, the isochronous cycle is computed by current value of CYCLE_TIMER register in 1394 OHCI controller. Especially for the case of timeout of split transaction, the expected isochronous cycle is computed. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-transaction.c | 58 +++++++++++++++++++++++------ drivers/firewire/core.h | 7 ++++ drivers/firewire/ohci.c | 17 ++++++++- include/linux/firewire.h | 13 ++++++- 4 files changed, 80 insertions(+), 15 deletions(-) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index a9f70c96323e..a20f97fdd06c 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -70,8 +70,8 @@ static int try_cancel_split_timeout(struct fw_transaction= *t) return 1; } =20 -static int close_transaction(struct fw_transaction *transaction, - struct fw_card *card, int rcode) +static int close_transaction(struct fw_transaction *transaction, struct fw= _card *card, int rcode, + u32 response_tstamp) { struct fw_transaction *t =3D NULL, *iter; unsigned long flags; @@ -92,7 +92,12 @@ static int close_transaction(struct fw_transaction *tran= saction, spin_unlock_irqrestore(&card->lock, flags); =20 if (t) { - t->callback(card, rcode, NULL, 0, t->callback_data); + if (!t->with_tstamp) { + t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data); + } else { + t->callback.with_tstamp(card, rcode, t->packet.timestamp, response_tsta= mp, + NULL, 0, t->callback_data); + } return 0; } =20 @@ -107,6 +112,8 @@ static int close_transaction(struct fw_transaction *tra= nsaction, int fw_cancel_transaction(struct fw_card *card, struct fw_transaction *transaction) { + u32 tstamp; + /* * Cancel the packet transmission if it's still queued. That * will call the packet transmission callback which cancels @@ -121,7 +128,17 @@ int fw_cancel_transaction(struct fw_card *card, * if the transaction is still pending and remove it in that case. */ =20 - return close_transaction(transaction, card, RCODE_CANCELLED); + if (transaction->packet.ack =3D=3D 0) { + // The timestamp is reused since it was just read now. + tstamp =3D transaction->packet.timestamp; + } else { + u32 curr_cycle_time =3D 0; + + (void)fw_card_read_cycle_time(card, &curr_cycle_time); + tstamp =3D cycle_time_to_ohci_tstamp(curr_cycle_time); + } + + return close_transaction(transaction, card, RCODE_CANCELLED, tstamp); } EXPORT_SYMBOL(fw_cancel_transaction); =20 @@ -140,7 +157,12 @@ static void split_transaction_timeout_callback(struct = timer_list *timer) card->tlabel_mask &=3D ~(1ULL << t->tlabel); spin_unlock_irqrestore(&card->lock, flags); =20 - t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data); + if (!t->with_tstamp) { + t->callback.without_tstamp(card, RCODE_CANCELLED, NULL, 0, t->callback_d= ata); + } else { + t->callback.with_tstamp(card, RCODE_CANCELLED, t->packet.timestamp, + t->split_timeout_cycle, NULL, 0, t->callback_data); + } } =20 static void start_split_transaction_timeout(struct fw_transaction *t, @@ -162,6 +184,8 @@ static void start_split_transaction_timeout(struct fw_t= ransaction *t, spin_unlock_irqrestore(&card->lock, flags); } =20 +static u32 compute_split_timeout_timestamp(struct fw_card *card, u32 reque= st_timestamp); + static void transmit_complete_callback(struct fw_packet *packet, struct fw_card *card, int status) { @@ -170,28 +194,32 @@ static void transmit_complete_callback(struct fw_pack= et *packet, =20 switch (status) { case ACK_COMPLETE: - close_transaction(t, card, RCODE_COMPLETE); + close_transaction(t, card, RCODE_COMPLETE, packet->timestamp); break; case ACK_PENDING: + { + t->split_timeout_cycle =3D + compute_split_timeout_timestamp(card, packet->timestamp) & 0xffff; start_split_transaction_timeout(t, card); break; + } case ACK_BUSY_X: case ACK_BUSY_A: case ACK_BUSY_B: - close_transaction(t, card, RCODE_BUSY); + close_transaction(t, card, RCODE_BUSY, packet->timestamp); break; case ACK_DATA_ERROR: - close_transaction(t, card, RCODE_DATA_ERROR); + close_transaction(t, card, RCODE_DATA_ERROR, packet->timestamp); break; case ACK_TYPE_ERROR: - close_transaction(t, card, RCODE_TYPE_ERROR); + close_transaction(t, card, RCODE_TYPE_ERROR, packet->timestamp); break; default: /* * In this case the ack is really a juju specific * rcode, so just forward that to the callback. */ - close_transaction(t, card, status); + close_transaction(t, card, status, packet->timestamp); break; } } @@ -363,7 +391,8 @@ void fw_send_request(struct fw_card *card, struct fw_tr= ansaction *t, int tcode, t->is_split_transaction =3D false; timer_setup(&t->split_timeout_timer, split_transaction_timeout_callback, 0); - t->callback =3D callback; + t->callback.without_tstamp =3D callback; + t->with_tstamp =3D false; t->callback_data =3D callback_data; =20 fw_fill_request(&t->packet, tcode, t->tlabel, @@ -1047,7 +1076,12 @@ void fw_core_handle_response(struct fw_card *card, s= truct fw_packet *p) */ card->driver->cancel_packet(card, &t->packet); =20 - t->callback(card, rcode, data, data_length, t->callback_data); + if (!t->with_tstamp) { + t->callback.without_tstamp(card, rcode, data, data_length, t->callback_d= ata); + } else { + t->callback.with_tstamp(card, rcode, t->packet.timestamp, p->timestamp, = data, + data_length, t->callback_data); + } } EXPORT_SYMBOL(fw_core_handle_response); =20 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index eafa4eaae737..2a05f411328f 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h @@ -247,6 +247,13 @@ void fw_fill_response(struct fw_packet *response, u32 = *request_header, void fw_request_get(struct fw_request *request); void fw_request_put(struct fw_request *request); =20 +// Convert the value of IEEE 1394 CYCLE_TIME register to the format of tim= eStamp field in +// descriptors of 1394 OHCI. +static inline u32 cycle_time_to_ohci_tstamp(u32 tstamp) +{ + return (tstamp & 0x0ffff000) >> 12; +} + #define FW_PHY_CONFIG_NO_NODE_ID -1 #define FW_PHY_CONFIG_CURRENT_GAP_COUNT -1 void fw_send_phy_config(struct fw_card *card, diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 17c9d825188b..06386c3b7f03 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -1623,6 +1623,8 @@ static void handle_local_request(struct context *ctx,= struct fw_packet *packet) } } =20 +static u32 get_cycle_time(struct fw_ohci *ohci); + static void at_context_transmit(struct context *ctx, struct fw_packet *pac= ket) { unsigned long flags; @@ -1633,6 +1635,10 @@ static void at_context_transmit(struct context *ctx,= struct fw_packet *packet) if (HEADER_GET_DESTINATION(packet->header[0]) =3D=3D ctx->ohci->node_id && ctx->ohci->generation =3D=3D packet->generation) { spin_unlock_irqrestore(&ctx->ohci->lock, flags); + + // Timestamping on behalf of the hardware. + packet->timestamp =3D cycle_time_to_ohci_tstamp(get_cycle_time(ctx->ohci= )); + handle_local_request(ctx, packet); return; } @@ -1640,9 +1646,12 @@ static void at_context_transmit(struct context *ctx,= struct fw_packet *packet) ret =3D at_context_queue_packet(ctx, packet); spin_unlock_irqrestore(&ctx->ohci->lock, flags); =20 - if (ret < 0) - packet->callback(packet, &ctx->ohci->card, packet->ack); + if (ret < 0) { + // Timestamping on behalf of the hardware. + packet->timestamp =3D cycle_time_to_ohci_tstamp(get_cycle_time(ctx->ohci= )); =20 + packet->callback(packet, &ctx->ohci->card, packet->ack); + } } =20 static void detect_dead_context(struct fw_ohci *ohci, @@ -2557,6 +2566,10 @@ static int ohci_cancel_packet(struct fw_card *card, = struct fw_packet *packet) log_ar_at_event(ohci, 'T', packet->speed, packet->header, 0x20); driver_data->packet =3D NULL; packet->ack =3D RCODE_CANCELLED; + + // Timestamping on behalf of the hardware. + packet->timestamp =3D cycle_time_to_ohci_tstamp(get_cycle_time(ohci)); + packet->callback(packet, &ohci->card, packet->ack); ret =3D 0; out: diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 56505436d159..365a07783604 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -270,6 +270,15 @@ typedef void (*fw_packet_callback_t)(struct fw_packet = *packet, typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode, void *data, size_t length, void *callback_data); +typedef void (*fw_transaction_callback_with_tstamp_t)(struct fw_card *card= , int rcode, + u32 request_tstamp, u32 response_tstamp, void *data, + size_t length, void *callback_data); + +union fw_transaction_callback { + fw_transaction_callback_t without_tstamp; + fw_transaction_callback_with_tstamp_t with_tstamp; +}; + /* * This callback handles an inbound request subaction. It is called in * RCU read-side context, therefore must not sleep. @@ -321,6 +330,7 @@ struct fw_transaction { struct fw_card *card; bool is_split_transaction; struct timer_list split_timeout_timer; + u32 split_timeout_cycle; =20 struct fw_packet packet; =20 @@ -328,7 +338,8 @@ struct fw_transaction { * The data passed to the callback is valid only during the * callback. */ - fw_transaction_callback_t callback; + union fw_transaction_callback callback; + bool with_tstamp; void *callback_data; }; =20 --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 77740C27C76 for ; Wed, 25 Jan 2023 12:03:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235629AbjAYMDX (ORCPT ); Wed, 25 Jan 2023 07:03:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233619AbjAYMDQ (ORCPT ); Wed, 25 Jan 2023 07:03:16 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0924B56EE3 for ; Wed, 25 Jan 2023 04:03:14 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 63D805C01B5; Wed, 25 Jan 2023 07:03:14 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 25 Jan 2023 07:03:14 -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; t=1674648194; x= 1674734594; bh=Lh823ox4xQVLDrtgezk53A8XHMzDS8P8L+Vhf9BFKyo=; b=S 4cU5eaxiMpzHoQ28J59/Dn97cmTI8UseH4oA8MhJtqG8zgXo4ky6drRWLyIcKBDl hLBP38LMM3ETaoyFe8l2ZiibLifTI8KU/aqf+TYJG+yKt69vBoMJSYPry/3Y3WQT VfRdQ+A7cNoYDrthvINWeFw1fh69L874ITvlKn/JKKmfs0PocSUvasATKsmeAMwP i/Jd7f5R3k5GQTe1s2oxcw927WA0O+o9U/8UTV2PJgy8PJVUsNm/4luC76QrJcsH sqWCChDpj/Qkv/U2iq0CTwE6LX43hUiqlMl7S8WB5O8kojvq/uA4sREU6QNEoxp3 DsuUykvkUaHAWi9g8Npnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648194; x=1674734594; bh=Lh823ox4xQVLD rtgezk53A8XHMzDS8P8L+Vhf9BFKyo=; b=UV7tFSxmQ3HB8KTTHZhbDKeVBEkYO jMml0NH3R0hkGZHLqDpj3W7NwRGJYHYXl272AsIYIO/UNHnznGqKyT34/DFCQija YPzNJ0/Ik6vDIRX/RP/KLQlaqx3IfFauXP3Iuujy97XCahQ1g+64y8v1zjSW1ROd pklUOWZcGYxffLFsMXK3s2GLrbGlXaVjZOR1Ih1m0BIid/mTLgF6uwDnkuejY6Xf YcW/G7KCB9DME1gsDiqk8ic7NdmrpAvmfIqsQ0dsuHJkuoFa6xVfuiIIYVsjdrET dlIXbyI9845qpf2LpFGicw3RkYdgC3z3PqD3JoTJXWmH0ACPr7h26/8vQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:13 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 05/11] firewire: core: implement variations to send request and wait for response with time stamp Date: Wed, 25 Jan 2023 21:02:55 +0900 Message-Id: <20230125120301.51585-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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 the previous commit, the core function of Linux FireWire subsystem was changed for two cases to operate asynchronous transaction with or without time stamp. This commit changes kernel API for the two cases. Current kernel API, fw_send_request(), is changed to be static inline function to call __fw_send_request(), which receives two argument for union and flag of callback function. The new kernel API, fw_send_request_with_tstamp() is also added as static inline function, too. When calling, the two arguments are copied to internal structure, then used in softIRQ context. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-transaction.c | 41 +++++++++++------ include/linux/firewire.h | 69 +++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 18 deletions(-) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index a20f97fdd06c..130b95aca629 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -316,7 +316,8 @@ static int allocate_tlabel(struct fw_card *card) } =20 /** - * fw_send_request() - submit a request packet for transmission + * __fw_send_request() - submit a request packet for transmission to gener= ate callback for response + * subaction with or without time stamp. * @card: interface to send the request at * @t: transaction instance to which the request belongs * @tcode: transaction code @@ -326,7 +327,9 @@ static int allocate_tlabel(struct fw_card *card) * @offset: 48bit wide offset into destination's address space * @payload: data payload for the request subaction * @length: length of the payload, in bytes - * @callback: function to be called when the transaction is completed + * @callback: union of two functions whether to receive time stamp or not= for response + * subaction. + * @with_tstamp: Whether to receive time stamp or not for response subacti= on. * @callback_data: data to be passed to the transaction completion callback * * Submit a request packet into the asynchronous request transmission queu= e. @@ -363,10 +366,10 @@ static int allocate_tlabel(struct fw_card *card) * transaction completion and hence execution of @callback may happen even * before fw_send_request() returns. */ -void fw_send_request(struct fw_card *card, struct fw_transaction *t, int t= code, - int destination_id, int generation, int speed, - unsigned long long offset, void *payload, size_t length, - fw_transaction_callback_t callback, void *callback_data) +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, union fw_transaction_callback callback, + bool with_tstamp, void *callback_data) { unsigned long flags; int tlabel; @@ -381,7 +384,19 @@ void fw_send_request(struct fw_card *card, struct fw_t= ransaction *t, int tcode, tlabel =3D allocate_tlabel(card); if (tlabel < 0) { spin_unlock_irqrestore(&card->lock, flags); - callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data); + if (!with_tstamp) { + callback.without_tstamp(card, RCODE_SEND_ERROR, NULL, 0, callback_data); + } else { + // Timestamping on behalf of hardware. + u32 curr_cycle_time =3D 0; + u32 tstamp; + + (void)fw_card_read_cycle_time(card, &curr_cycle_time); + tstamp =3D cycle_time_to_ohci_tstamp(curr_cycle_time); + + callback.with_tstamp(card, RCODE_SEND_ERROR, tstamp, tstamp, NULL, 0, + callback_data); + } return; } =20 @@ -389,14 +404,12 @@ void fw_send_request(struct fw_card *card, struct fw_= transaction *t, int tcode, t->tlabel =3D tlabel; t->card =3D card; t->is_split_transaction =3D false; - timer_setup(&t->split_timeout_timer, - split_transaction_timeout_callback, 0); - t->callback.without_tstamp =3D callback; - t->with_tstamp =3D false; + timer_setup(&t->split_timeout_timer, split_transaction_timeout_callback, = 0); + t->callback =3D callback; + t->with_tstamp =3D with_tstamp; t->callback_data =3D callback_data; =20 - fw_fill_request(&t->packet, tcode, t->tlabel, - destination_id, card->node_id, generation, + fw_fill_request(&t->packet, tcode, t->tlabel, destination_id, card->node_= id, generation, speed, offset, payload, length); t->packet.callback =3D transmit_complete_callback; =20 @@ -406,7 +419,7 @@ void fw_send_request(struct fw_card *card, struct fw_tr= ansaction *t, int tcode, =20 card->driver->send_request(card, &t->packet); } -EXPORT_SYMBOL(fw_send_request); +EXPORT_SYMBOL_GPL(__fw_send_request); =20 struct transaction_callback_data { struct completion done; diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 365a07783604..962afd24c7ca 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -365,10 +365,71 @@ 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, - fw_transaction_callback_t callback, void *callback_data); + +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, union fw_transaction_callback callback, + bool with_tstamp, void *callback_data); + +/** + * fw_send_request() - submit a request packet for transmission to generat= e callback for response + * subaction without time stamp. + * @card: interface to send the request at + * @t: transaction instance to which the request belongs + * @tcode: transaction code + * @destination_id: destination node ID, consisting of bus_ID and phy_ID + * @generation: bus generation in which request and response are valid + * @speed: transmission speed + * @offset: 48bit wide offset into destination's address space + * @payload: data payload for the request subaction + * @length: length of the payload, in bytes + * @callback: function to be called when the transaction is completed + * @callback_data: data to be passed to the transaction completion callback + * + * A variation of __fw_send_request() to generate callback for response su= baction without time + * stamp. + */ +static inline void fw_send_request(struct fw_card *card, struct fw_transac= tion *t, int tcode, + int destination_id, int generation, int speed, + unsigned long long offset, void *payload, size_t length, + fw_transaction_callback_t callback, void *callback_data) +{ + union fw_transaction_callback cb =3D { + .without_tstamp =3D callback, + }; + __fw_send_request(card, t, tcode, destination_id, generation, speed, offs= et, payload, + length, cb, false, callback_data); +} + +/** + * fw_send_request_with_tstamp() - submit a request packet for transmissio= n to generate callback for + * response with time stamp. + * @card: interface to send the request at + * @t: transaction instance to which the request belongs + * @tcode: transaction code + * @destination_id: destination node ID, consisting of bus_ID and phy_ID + * @generation: bus generation in which request and response are valid + * @speed: transmission speed + * @offset: 48bit wide offset into destination's address space + * @payload: data payload for the request subaction + * @length: length of the payload, in bytes + * @callback: function to be called when the transaction is completed + * @callback_data: data to be passed to the transaction completion callback + * + * A variation of __fw_send_request() to generate callback for response su= baction with time stamp. + */ +static inline void fw_send_request_with_tstamp(struct fw_card *card, struc= t fw_transaction *t, + int tcode, int destination_id, int generation, int speed, unsigned long l= ong offset, + void *payload, size_t length, fw_transaction_callback_with_tstamp_t callb= ack, + void *callback_data) +{ + union fw_transaction_callback cb =3D { + .with_tstamp =3D callback, + }; + __fw_send_request(card, t, tcode, destination_id, generation, speed, offs= et, payload, + length, cb, true, callback_data); +} + int fw_cancel_transaction(struct fw_card *card, struct fw_transaction *transaction); int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 3DC2CC27C76 for ; Wed, 25 Jan 2023 12:03:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235303AbjAYMDa (ORCPT ); Wed, 25 Jan 2023 07:03:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235454AbjAYMDR (ORCPT ); Wed, 25 Jan 2023 07:03:17 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73FBE568BF for ; Wed, 25 Jan 2023 04:03:16 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id E12C95C00CC; Wed, 25 Jan 2023 07:03:15 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 25 Jan 2023 07:03:15 -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; t=1674648195; x= 1674734595; bh=Td3n4i3eo0pZ/YzFAwc9ILQot5TU2fewRmEKzxit+m4=; b=k Uo0gQLyLNJW+UyVAOirV8jtoAfLzOmECRH+ra9/HiP4BjMmeHEOxQ5e68rTeMXdo FG7lbhieHIEmTVM7DdjS/ooqrY1gIWYfIyHz0OTyU1WmgJBPqLkQ+u9ZDDGhpOZg O53WZXQR7VIyHH73PS0ltggUvVdcGgjLveWyY/iw1BApSUTorZUGZ2tY9zZ1WC8x isitWWQz1T2/8o+hQJatHdIRQBiXZKUJ3wQKitVPdbADXsv1MWlxD1TTpDMKEi2k gd0YdN/T8zRFXdP65X3xYQ8EyQRZfVBn/e2AtTJuKJi5G8j2ta+Nbk3Rv39Y9aw6 3YW1SYgYqZgekm7lxxxnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648195; x=1674734595; bh=Td3n4i3eo0pZ/ YzFAwc9ILQot5TU2fewRmEKzxit+m4=; b=btzLo31dmt8bZiNJi7JAcRsOv+PsL ttF33H/qTOiQQ/Sf9qBfhAGXUc3sRusyannd+0/r3hdDwyTTuUOESOq/aiXsAu9G kKF0yxOO0CmZw3VbB5rReg4UJyhwNRiYHzT9KXViDmG3jDSR1KA8d0hS4+iBtNmc cBmdREuMh7s9P1PgcGswzynLr7n6Hmk3Z3o0sD8H0aieDkx/vPTNa1JQDSRVSVPH wyggnykR2W0YYwYPRVZfTisikoGsaQdOWOzeYsRaTtDxBPOtrVsRvK1W/uTnh200 HglAzghZhKx6sGxXBN+XYxy/TsV0+3dBYtAJUzIzkoeusUdgudFn+Y/kw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:14 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 06/11] firewire: cdev: code refactoring to operate event of response Date: Wed, 25 Jan 2023 21:02:56 +0900 Message-Id: <20230125120301.51585-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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" This commit is a preparation to handle time stamp of asynchronous transaction for user space application. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 5a9446d30447..315ebc8c545d 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -170,7 +170,9 @@ struct outbound_transaction_event { struct event event; struct client *client; struct outbound_transaction_resource r; - struct fw_cdev_event_response response; + union { + struct fw_cdev_event_response without_tstamp; + } rsp; }; =20 struct inbound_transaction_event { @@ -540,7 +542,7 @@ static void complete_transaction(struct fw_card *card, = int rcode, void *payload, size_t length, void *data) { struct outbound_transaction_event *e =3D data; - struct fw_cdev_event_response *rsp =3D &e->response; + struct fw_cdev_event_response *rsp =3D &e->rsp.without_tstamp; struct client *client =3D e->client; unsigned long flags; =20 @@ -581,6 +583,8 @@ static int init_request(struct client *client, int destination_id, int speed) { struct outbound_transaction_event *e; + struct fw_cdev_event_response *rsp; + void *payload; int ret; =20 if (request->tcode !=3D TCODE_STREAM_DATA && @@ -594,14 +598,14 @@ static int init_request(struct client *client, e =3D kmalloc(sizeof(*e) + request->length, GFP_KERNEL); if (e =3D=3D NULL) return -ENOMEM; - e->client =3D client; - e->response.length =3D request->length; - e->response.closure =3D request->closure; =20 - if (request->data && - copy_from_user(e->response.data, - u64_to_uptr(request->data), request->length)) { + rsp =3D &e->rsp.without_tstamp; + rsp->length =3D request->length; + rsp->closure =3D request->closure; + payload =3D rsp->data; + + if (request->data && copy_from_user(payload, u64_to_uptr(request->data), = request->length)) { ret =3D -EFAULT; goto failed; } @@ -611,10 +615,9 @@ static int init_request(struct client *client, if (ret < 0) goto failed; =20 - fw_send_request(client->device->card, &e->r.transaction, - request->tcode, destination_id, request->generation, - speed, request->offset, e->response.data, - request->length, complete_transaction, e); + fw_send_request(client->device->card, &e->r.transaction, request->tcode, = destination_id, + request->generation, speed, request->offset, payload, request->length, + complete_transaction, e); return 0; =20 failed: --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 7467DC54EAA for ; Wed, 25 Jan 2023 12:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235810AbjAYMDc (ORCPT ); Wed, 25 Jan 2023 07:03:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235449AbjAYMDT (ORCPT ); Wed, 25 Jan 2023 07:03:19 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E150577C6 for ; Wed, 25 Jan 2023 04:03:18 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 763D25C01B4; Wed, 25 Jan 2023 07:03:17 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 25 Jan 2023 07:03:17 -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; t=1674648197; x= 1674734597; bh=19vVTUmVz4c8yNVs+anY4mvaR+1Dv/o34ILhLMx+310=; b=f JxisbbAZhjhg8HRy1JI30dzwszF78Liq9d14jvD2a/tIYaAk7f4fycS/skXObPbY d7X7OpNqo3lHPIqKES9XpA8VNBOAbpGI3Q+tpQmJde0Y/b0ZI91L1KNtOUSNrdsz 7ZMWO+v2eQ/f4aFboO5weXuO8SYfIKbzjPgYvAgkU6IzCdW+yyAPNb6EwbRMI4Ag 28nIhGBfKTlv7SU7ISYW+ZwzOsykPtUFrxXX2fji8FNdqmZphFLq/28AJbR18oJN LX2uHf8AotLYK8ij0pEAjft/J3GHwZNkFkXAGw9u+z2X/2e99sgvuKSoZW0jQbGR md2tWDkfimmxdpNFJ7joQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648197; x=1674734597; bh=19vVTUmVz4c8y NVs+anY4mvaR+1Dv/o34ILhLMx+310=; b=QPkevexRXdiUmKoFeyKWAJdRx5RYo Nkp73ntxZOuYV+MmRpiiknKzF/wG2JyKs8KVWhkHJOa0LzdAmFk9EJgvrj1Kimom cXQaHaDhF7SaFn3KGlbrIt4tqA7k04mCihZ5y1NyCOgu2Mw2hPU5rgdBxi8C8zta CMUYib5OmzN7F8q6KyWSSwiaVc/S07whcISQVhqTlVfAAiHcLEtgMuw97H67/rQZ J0ytlbOiIYh8oli53zNp1PUq4P0TgOa3vnprOEiBpNRlRcxq5mMsyQbIkMJLixzA UuLxH94uwXpMw/Ywdv76mZv1wvORFlv827n29k5ANyN+3wRTx9DK5kRVg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:16 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 07/11] firewire: cdev: add new event to notify response subaction with time stamp Date: Wed, 25 Jan 2023 21:02:57 +0900 Message-Id: <20230125120301.51585-8-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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" This commit adds new event to notify event of response subaction with time stamp field. Current compiler implementation of System V ABI selects one of structure members which has the maximum alignment size in the structure to decide the size of structure. In the case of fw_cdev_event_request3 structure, it is closure member which has 8 byte storage. The size of alignment for the type of 8 byte storage differs depending on architectures; 4 byte for i386 architecture and 8 byte for the others including x32 architecture. It is inconvenient to device driver developer to use structure layout which varies between architectures since the developer takes care of ioctl compat layer. This commit adds 32 bit member for padding to keep the size of structure as multiples of 8. Signed-off-by: Takashi Sakamoto --- include/uapi/linux/firewire-cdev.h | 59 +++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/include/uapi/linux/firewire-cdev.h b/include/uapi/linux/firewi= re-cdev.h index 827b226eabb1..2bd6ab023fc4 100644 --- a/include/uapi/linux/firewire-cdev.h +++ b/include/uapi/linux/firewire-cdev.h @@ -48,6 +48,7 @@ =20 /* available since kernel version 6.3 */ #define FW_CDEV_EVENT_REQUEST3 0x0a +#define FW_CDEV_EVENT_RESPONSE2 0x0b =20 /** * struct fw_cdev_event_common - Common part of all fw_cdev_event_* types @@ -106,6 +107,29 @@ struct fw_cdev_event_bus_reset { * @length: Data length, i.e. the response's payload size in bytes * @data: Payload data, if any * + * This event is sent instead of &fw_cdev_event_response if the kernel or = the client implements + * ABI version <=3D 5. It has the lack of time stamp field comparing to &f= w_cdev_event_response2. + */ +struct fw_cdev_event_response { + __u64 closure; + __u32 type; + __u32 rcode; + __u32 length; + __u32 data[]; +}; + +/** + * struct fw_cdev_event_response2 - Sent when a response packet was receiv= ed + * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST + * or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST + * or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl + * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE + * @rcode: Response code returned by the remote node + * @length: Data length, i.e. the response's payload size in bytes + * @request_tstamp: The time stamp of isochronous cycle at which the reque= st was sent. + * @request_tstamp: The time stamp of isochronous cycle at which the respo= nse was sent. + * @data: Payload data, if any + * * This event is sent when the stack receives a response to an outgoing re= quest * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl. The payload data for responses * carrying data (read and lock responses) follows immediately and can be @@ -115,12 +139,25 @@ struct fw_cdev_event_bus_reset { * involve response packets. This includes unified write transactions, * broadcast write transactions, and transmission of asynchronous stream * packets. @rcode indicates success or failure of such transmissions. + * + * The value of @request_tstamp expresses the isochronous cycle at which t= he request was sent to + * initiate the transaction. The value of @response_tstamp expresses the i= sochronous cycle at which + * the response arrived to complete the transaction. Each value is unsigne= d 16 bit integer + * containing three low order bits of second field and all 13 bits of cycl= e field in format of + * CYCLE_TIMER register. */ -struct fw_cdev_event_response { +struct fw_cdev_event_response2 { __u64 closure; __u32 type; __u32 rcode; __u32 length; + __u32 request_tstamp; + __u32 response_tstamp; + /* + * Padding to keep the size of structure as multiples of 8 in various arc= hitectures since + * 4 byte alignment is used for 8 byte of object type in System V ABI for= i386 architecture. + */ + __u32 padding; __u32 data[]; }; =20 @@ -421,6 +458,7 @@ struct fw_cdev_event_phy_packet { * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED * * @request3: Valid if @common.type =3D=3D %FW_CDEV_EVENT_REQUEST3 + * @response2: Valid if @common.type =3D=3D %FW_CDEV_EVENT_RESPONSE2 * * Convenience union for userspace use. Events could be read(2) into an * appropriately aligned char buffer and then cast to this union for furth= er @@ -441,6 +479,7 @@ union fw_cdev_event { struct fw_cdev_event_iso_resource iso_resource; /* added in 2.6.30 */ struct fw_cdev_event_phy_packet phy_packet; /* added in 2.6.36 */ struct fw_cdev_event_request3 request3; /* added in 6.3 */ + struct fw_cdev_event_response2 response2; /* added in 6.3 */ }; =20 /* available since kernel version 2.6.22 */ @@ -507,6 +546,7 @@ union fw_cdev_event { * - added %FW_CDEV_IOC_FLUSH_ISO * 6 (6.3) - added some event for subactions of asynchronous transac= tion with time stamp * - %FW_CDEV_EVENT_REQUEST3 + * - %FW_CDEV_EVENT_RESPONSE2 */ =20 /** @@ -552,11 +592,11 @@ struct fw_cdev_get_info { * @data: Userspace pointer to payload * @generation: The bus generation where packet is valid * - * Send a request to the device. This ioctl implements all outgoing reque= sts. - * Both quadlet and block request specify the payload as a pointer to the = data - * in the @data field. Once the transaction completes, the kernel writes = an - * &fw_cdev_event_response event back. The @closure field is passed back = to - * user space in the response event. + * Send a request to the device. This ioctl implements all outgoing reque= sts. Both quadlet and + * block request specify the payload as a pointer to the data in the @data= field. Once the + * transaction completes, the kernel writes either &fw_cdev_event_response= event or + * &fw_cdev_event_response event back. The @closure field is passed back t= o user space in the + * response event. */ struct fw_cdev_send_request { __u32 tcode; @@ -1039,10 +1079,9 @@ struct fw_cdev_allocate_iso_resource { * @generation: The bus generation where packet is valid * @speed: Speed to transmit at * - * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream = packet - * to every device which is listening to the specified channel. The kernel - * writes an &fw_cdev_event_response event which indicates success or fail= ure of - * the transmission. + * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream = packet to every device + * which is listening to the specified channel. The kernel writes either &= fw_cdev_event_response + * event or &fw_cdev_event_response2 event which indicates success or fail= ure of the transmission. */ struct fw_cdev_send_stream_packet { __u32 length; --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 41786C54E94 for ; Wed, 25 Jan 2023 12:03:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235812AbjAYMDk (ORCPT ); Wed, 25 Jan 2023 07:03:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235727AbjAYMD2 (ORCPT ); Wed, 25 Jan 2023 07:03:28 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C89058290 for ; Wed, 25 Jan 2023 04:03:19 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 063845C01B3; Wed, 25 Jan 2023 07:03:19 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 25 Jan 2023 07:03:19 -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; t=1674648199; x= 1674734599; bh=4qNJoZP3xhEdcFzYFpHl0G/Z8VsY9m5iDjOTEFzn2zE=; b=l zXMNCFet1y42P0mzSdaY6LlTG80H8x0KrAeXmnAjoCR9zvwFa6Gqnftph+ePZpQv OST1QSDYIfwCw78Zbk1rCKdyWU5OBNkAPnRjKHcxifz5EYgLu1kYeiZvkaRVkDVM cCqO8KOb+zgQ/CQ9pclXAKOMnQNraL+dyPB4jsOoCcTU970F0zd+lo7p+mcxBGLY SAVr09R9HULj6WdhNZ4TpkrHVAjIZdKLHlig0MnsIgQTk8kgioi0HE18GvRIhp/3 rf1+HFT0LdSvYkDOrfJkdZNFWluX7nbYdzTyvc1Q0jHD88trn/NPM3nagGBQWy1F TH2Ll5RgYLLETuc6Us+5A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648199; x=1674734599; bh=4qNJoZP3xhEdc FzYFpHl0G/Z8VsY9m5iDjOTEFzn2zE=; b=kzRuWlN4/vhhXo0yq3PYHhwnSd3Td ardoKNn5FqDWUj2oweQA9iAxaF7Y6yXwgTqBVL2ZcmMfLYItS6zJlXff7EPGCV6/ CfQf26e4zlnL4toK20B73XfEWxiEMjUiUD9TZPFLuLOOe32QzmJzwRrLi2OXaJf7 RFlzMGioY2dGv6kVrY8HbDyApSZHriciIxQIssDJ/iAKabXajmfYbAXANkfsP7kB MV1lV1Fi4XW8QJuH1RQF0exnAbp0hxrW5Vikyz76NrlxRuQ/V1YuRrn3xXs45ufD S1uE01QQ6TDLEMBkzbUpAsmR7dW2ezkBk46Ikv0NCOp6a1Fj4msaU1rtg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:17 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 08/11] firewire: cdev: implement new event to notify response subaction with time stamp Date: Wed, 25 Jan 2023 21:02:58 +0900 Message-Id: <20230125120301.51585-9-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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" The callback function now receives an argument for time stamps relevant to asynchronous transaction. This commit implements a new event to notify response subaction with the time stamps for user space. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 96 ++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 315ebc8c545d..8b24abdd51b8 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -172,6 +172,7 @@ struct outbound_transaction_event { struct outbound_transaction_resource r; union { struct fw_cdev_event_response without_tstamp; + struct fw_cdev_event_response2 with_tstamp; } rsp; }; =20 @@ -538,41 +539,64 @@ static void release_transaction(struct client *client, { } =20 -static void complete_transaction(struct fw_card *card, int rcode, - void *payload, size_t length, void *data) +static void complete_transaction(struct fw_card *card, int rcode, u32 requ= est_tstamp, + u32 response_tstamp, void *payload, size_t length, void *data) { struct outbound_transaction_event *e =3D data; - struct fw_cdev_event_response *rsp =3D &e->rsp.without_tstamp; struct client *client =3D e->client; unsigned long flags; =20 - if (length < rsp->length) - rsp->length =3D length; - if (rcode =3D=3D RCODE_COMPLETE) - memcpy(rsp->data, payload, rsp->length); - spin_lock_irqsave(&client->lock, flags); idr_remove(&client->resource_idr, e->r.resource.handle); if (client->in_shutdown) wake_up(&client->tx_flush_wait); spin_unlock_irqrestore(&client->lock, flags); =20 - rsp->type =3D FW_CDEV_EVENT_RESPONSE; - rsp->rcode =3D rcode; + switch (e->rsp.without_tstamp.type) { + case FW_CDEV_EVENT_RESPONSE: + { + struct fw_cdev_event_response *rsp =3D &e->rsp.without_tstamp; + + if (length < rsp->length) + rsp->length =3D length; + if (rcode =3D=3D RCODE_COMPLETE) + memcpy(rsp->data, payload, rsp->length); + + rsp->rcode =3D rcode; + + // In the case that sizeof(*rsp) doesn't align with the position of the + // data, and the read is short, preserve an extra copy of the data + // to stay compatible with a pre-2.6.27 bug. Since the bug is harmless + // for short reads and some apps depended on it, this is both safe + // and prudent for compatibility. + if (rsp->length <=3D sizeof(*rsp) - offsetof(typeof(*rsp), data)) + queue_event(client, &e->event, rsp, sizeof(*rsp), rsp->data, rsp->lengt= h); + else + queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, NULL, 0= ); =20 - /* - * In the case that sizeof(*rsp) doesn't align with the position of the - * data, and the read is short, preserve an extra copy of the data - * to stay compatible with a pre-2.6.27 bug. Since the bug is harmless - * for short reads and some apps depended on it, this is both safe - * and prudent for compatibility. - */ - if (rsp->length <=3D sizeof(*rsp) - offsetof(typeof(*rsp), data)) - queue_event(client, &e->event, rsp, sizeof(*rsp), - rsp->data, rsp->length); - else - queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, - NULL, 0); + break; + } + case FW_CDEV_EVENT_RESPONSE2: + { + struct fw_cdev_event_response2 *rsp =3D &e->rsp.with_tstamp; + + if (length < rsp->length) + rsp->length =3D length; + if (rcode =3D=3D RCODE_COMPLETE) + memcpy(rsp->data, payload, rsp->length); + + rsp->rcode =3D rcode; + rsp->request_tstamp =3D request_tstamp; + rsp->response_tstamp =3D response_tstamp; + + queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, NULL, 0); + + break; + default: + WARN_ON(1); + break; + } + } =20 /* Drop the idr's reference */ client_put(client); @@ -583,7 +607,6 @@ static int init_request(struct client *client, int destination_id, int speed) { struct outbound_transaction_event *e; - struct fw_cdev_event_response *rsp; void *payload; int ret; =20 @@ -600,10 +623,21 @@ static int init_request(struct client *client, return -ENOMEM; e->client =3D client; =20 - rsp =3D &e->rsp.without_tstamp; - rsp->length =3D request->length; - rsp->closure =3D request->closure; - payload =3D rsp->data; + if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { + struct fw_cdev_event_response *rsp =3D &e->rsp.without_tstamp; + + rsp->type =3D FW_CDEV_EVENT_RESPONSE; + rsp->length =3D request->length; + rsp->closure =3D request->closure; + payload =3D rsp->data; + } else { + struct fw_cdev_event_response2 *rsp =3D &e->rsp.with_tstamp; + + rsp->type =3D FW_CDEV_EVENT_RESPONSE2; + rsp->length =3D request->length; + rsp->closure =3D request->closure; + payload =3D rsp->data; + } =20 if (request->data && copy_from_user(payload, u64_to_uptr(request->data), = request->length)) { ret =3D -EFAULT; @@ -615,9 +649,9 @@ static int init_request(struct client *client, if (ret < 0) goto failed; =20 - fw_send_request(client->device->card, &e->r.transaction, request->tcode, = destination_id, - request->generation, speed, request->offset, payload, request->length, - complete_transaction, e); + fw_send_request_with_tstamp(client->device->card, &e->r.transaction, requ= est->tcode, + destination_id, request->generation, speed, request->offset, + payload, request->length, complete_transaction, e); return 0; =20 failed: --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 D1177C54EAA for ; Wed, 25 Jan 2023 12:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235671AbjAYMDn (ORCPT ); Wed, 25 Jan 2023 07:03:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235817AbjAYMDg (ORCPT ); Wed, 25 Jan 2023 07:03:36 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16E0F577E2 for ; Wed, 25 Jan 2023 04:03:21 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 86B245C01B7; Wed, 25 Jan 2023 07:03:20 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 25 Jan 2023 07:03:20 -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; t=1674648200; x= 1674734600; bh=ahqs1LYctapqd3obfcgxXTbiu9HxxUAsecH2A0pcwOo=; b=H xHPjCINz7UPVaQ0a70ohdvxAVldZo4NeDXnkFV8L/TKVi0VChMCZiSaBtMjJUB5c oWWarWJx5zyU8JCZBz+4Wt3q4mn0xKN7TMTgp8d/kZ3SHum1qX9NmrI/GDM9/0aA dOX6MVj3M4xkmmVuj5cB1BMbhQ01/9ZhMQLInuS3eapN0EoflSbd2IHb7E4wVB6D wnv1KhDBz4+gJ6tK6PowDL5tz2G5g/qbQghMw0d3K6M2Gy38T2zVArn8MCEyLo5g CLFhVh9c7zs6WHMOOya2DP/BhKHLsHIfVst3brfhQwAHUK3bauSW+5WREKqQktDu 7VxVqopty9hAvjwnncFCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648200; x=1674734600; bh=ahqs1LYctapqd 3obfcgxXTbiu9HxxUAsecH2A0pcwOo=; b=X0iMZwkCCyaKwV2nIbcITALUnh9mj eblsuVBDZXJM/jTI3t2JqL0YEnU0O5QpQsECPUsUp8SpDYr8O87i0kLkbDMZdD4Y 3iKwc4sAiLjgFHNXMS/L4FWVwc071RI7R3ympFypAqvtNK9AcEuTNBCrlnFiRe8a N30nDxfqRGQYSl/d9nKygKV99dv8znjJ54JugPu7d92d5KRU/a2A15JWiHzSRdl0 2WMtAxGwhCFQGUJXin55vql3luE9hd6PtuBXxKqGRxzIwgGE9BXxOr+GNK1P5dJJ xku8omaZ3V6PXvE9vdnACnX1jz0w01crxJ5e07bRWfKF6qiLB/bW+RQJQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:19 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 09/11] firewire: cdev: code refactoring to dispatch event for phy packet Date: Wed, 25 Jan 2023 21:02:59 +0900 Message-Id: <20230125120301.51585-10-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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, both Asynchronous Transmit (AT) and Asynchronous Receive (AR) contexts are used to deliver the phy packet of IEEE 1394. The time stamp is available as well as the usual asynchronous transaction. This commit is a preparation for future commit to handle the time stamp. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 78 +++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 8b24abdd51b8..2220de3c945e 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -204,12 +204,16 @@ struct outbound_phy_packet_event { struct event event; struct client *client; struct fw_packet p; - struct fw_cdev_event_phy_packet phy_packet; + union { + struct fw_cdev_event_phy_packet without_tstamp; + } phy_packet; }; =20 struct inbound_phy_packet_event { struct event event; - struct fw_cdev_event_phy_packet phy_packet; + union { + struct fw_cdev_event_phy_packet without_tstamp; + } phy_packet; }; =20 #ifdef CONFIG_COMPAT @@ -1549,26 +1553,41 @@ static void outbound_phy_packet_callback(struct fw_= packet *packet, { struct outbound_phy_packet_event *e =3D container_of(packet, struct outbound_phy_packet_event, p); - struct client *e_client; + struct client *e_client =3D e->client; + u32 rcode; + struct fw_cdev_event_phy_packet *pp; =20 switch (status) { - /* expected: */ - case ACK_COMPLETE: e->phy_packet.rcode =3D RCODE_COMPLETE; break; - /* should never happen with PHY packets: */ - case ACK_PENDING: e->phy_packet.rcode =3D RCODE_COMPLETE; break; + // expected: + case ACK_COMPLETE: + rcode =3D RCODE_COMPLETE; + break; + // should never happen with PHY packets: + case ACK_PENDING: + rcode =3D RCODE_COMPLETE; + break; case ACK_BUSY_X: case ACK_BUSY_A: - case ACK_BUSY_B: e->phy_packet.rcode =3D RCODE_BUSY; break; - case ACK_DATA_ERROR: e->phy_packet.rcode =3D RCODE_DATA_ERROR; break; - case ACK_TYPE_ERROR: e->phy_packet.rcode =3D RCODE_TYPE_ERROR; break; - /* stale generation; cancelled; on certain controllers: no ack */ - default: e->phy_packet.rcode =3D status; break; + case ACK_BUSY_B: + rcode =3D RCODE_BUSY; + break; + case ACK_DATA_ERROR: + rcode =3D RCODE_DATA_ERROR; + break; + case ACK_TYPE_ERROR: + rcode =3D RCODE_TYPE_ERROR; + break; + // stale generation; cancelled; on certain controllers: no ack + default: + rcode =3D status; + break; } - e->phy_packet.data[0] =3D packet->timestamp; =20 - e_client =3D e->client; - queue_event(e->client, &e->event, &e->phy_packet, - sizeof(e->phy_packet) + e->phy_packet.length, NULL, 0); + pp =3D &e->phy_packet.without_tstamp; + pp->rcode =3D rcode; + pp->data[0] =3D packet->timestamp; + queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->lengt= h, NULL, 0); + client_put(e_client); } =20 @@ -1577,6 +1596,7 @@ static int ioctl_send_phy_packet(struct client *clien= t, union ioctl_arg *arg) struct fw_cdev_send_phy_packet *a =3D &arg->send_phy_packet; struct fw_card *card =3D client->device->card; struct outbound_phy_packet_event *e; + struct fw_cdev_event_phy_packet *pp; =20 /* Access policy: Allow this ioctl only on local nodes' device files. */ if (!client->device->is_local) @@ -1595,10 +1615,12 @@ static int ioctl_send_phy_packet(struct client *cli= ent, union ioctl_arg *arg) e->p.header[2] =3D a->data[1]; e->p.header_length =3D 12; e->p.callback =3D outbound_phy_packet_callback; - e->phy_packet.closure =3D a->closure; - e->phy_packet.type =3D FW_CDEV_EVENT_PHY_PACKET_SENT; + + pp =3D &e->phy_packet.without_tstamp; + pp->closure =3D a->closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_SENT; if (is_ping_packet(a->data)) - e->phy_packet.length =3D 4; + pp->length =3D 4; =20 card->driver->send_request(card, &e->p); =20 @@ -1633,18 +1655,20 @@ void fw_cdev_handle_phy_packet(struct fw_card *card= , struct fw_packet *p) spin_lock_irqsave(&card->lock, flags); =20 list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { + struct fw_cdev_event_phy_packet *pp; + e =3D kmalloc(sizeof(*e) + 8, GFP_ATOMIC); if (e =3D=3D NULL) break; =20 - e->phy_packet.closure =3D client->phy_receiver_closure; - e->phy_packet.type =3D FW_CDEV_EVENT_PHY_PACKET_RECEIVED; - e->phy_packet.rcode =3D RCODE_COMPLETE; - e->phy_packet.length =3D 8; - e->phy_packet.data[0] =3D p->header[1]; - e->phy_packet.data[1] =3D p->header[2]; - queue_event(client, &e->event, - &e->phy_packet, sizeof(e->phy_packet) + 8, NULL, 0); + pp =3D &e->phy_packet.without_tstamp; + pp->closure =3D client->phy_receiver_closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_RECEIVED; + pp->rcode =3D RCODE_COMPLETE; + pp->length =3D 8; + pp->data[0] =3D p->header[1]; + pp->data[1] =3D p->header[2]; + queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0); } =20 spin_unlock_irqrestore(&card->lock, flags); --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 5729CC54E94 for ; Wed, 25 Jan 2023 12:03:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235735AbjAYMDr (ORCPT ); Wed, 25 Jan 2023 07:03:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235711AbjAYMDh (ORCPT ); Wed, 25 Jan 2023 07:03:37 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF02E56ED4 for ; Wed, 25 Jan 2023 04:03:22 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 0DED85C01B1; Wed, 25 Jan 2023 07:03:22 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 25 Jan 2023 07:03:22 -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; t=1674648202; x= 1674734602; bh=t0nvS0Pz00hKfcsEBgTOMv0+ZOgK+W8dh2NdTtPTXB0=; b=m oZ1IFzVDCL4HK7DjPsCxAMIhSxHdes6gZ9tHLNmJnOl6zY037nDF+EOtXhu0ZEEI RhZLnmmmEh/yMM93qA6PMmNBWXbEsXYfJduwuv/my+J3oco49ZrekckCN9/6GfCq aywCT806M3hHiXmWAxsyMgeoXdMS6j8DK94QX0N4FflgL07tgSa63mYWgMrhWEUC kQfSbRaYFR/GVIlSwjVVsgxLosx90XsWpCnmL3TBCEGgPYjjJxApeYwhvdbYOwzv FpC69V//e9oJj1hCzPakyV914EAV6FuetyFaZyY47BvHwQSjSr8QNyD1G4WZyWLu P5ACwsSHgxhkExOrfd7Ig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648202; x=1674734602; bh=t0nvS0Pz00hKf csEBgTOMv0+ZOgK+W8dh2NdTtPTXB0=; b=SGUeqcVJL8ScKQedUqawJ36VwOSzh xUiKIvzQtd7ShDMAIfsKaKWYWvi+LYHB+G0xP4u08ANBhajFx5wLKhVO5vpkSAdR qTsDPbkoEkqucssN6Iu+NWWYyngzOCSX1ZO2/2mIVTA8f73pIr+chlzEViyIPe7W Foes1guDkWGn3Yl0m1b9+fuTIeDCU0ElrkfXOU+MpG631GnUdFaDTlRw2vO8I7I8 SH7fWaPljn7NvNTMry8krnb5A9scvWwE9uYWMCZbrvbECb6TWFDYV+uQU91jZpgx IUSjud0FpPIFzJIcDq99T1mXSqZJrOhDM4Ijb3Mj0d2YM3RBhtqaQOv6g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:20 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 10/11] firewire: cdev: add new event to notify phy packet with time stamp Date: Wed, 25 Jan 2023 21:03:00 +0900 Message-Id: <20230125120301.51585-11-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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" This commit adds new event to notify event of phy packet with time stamp field. Unlike the fw_cdev_event_request3 and fw_cdev_event_response2, the size of new structure, fw_cdev_event_phy_packet2, is multiples of 8, thus padding is not required to keep the same size between System V ABI for different architectures. It is noticeable that for the case of ping request 1394 OHCI controller does not record the isochronous cycle at which the packet was sent for the request subaction. Instead, it records round-trip count measured by hardware at 42.195 MHz resolution. Signed-off-by: Takashi Sakamoto --- include/uapi/linux/firewire-cdev.h | 67 +++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/include/uapi/linux/firewire-cdev.h b/include/uapi/linux/firewi= re-cdev.h index 2bd6ab023fc4..dede13813c1d 100644 --- a/include/uapi/linux/firewire-cdev.h +++ b/include/uapi/linux/firewire-cdev.h @@ -49,6 +49,8 @@ /* available since kernel version 6.3 */ #define FW_CDEV_EVENT_REQUEST3 0x0a #define FW_CDEV_EVENT_RESPONSE2 0x0b +#define FW_CDEV_EVENT_PHY_PACKET_SENT2 0x0c +#define FW_CDEV_EVENT_PHY_PACKET_RECEIVED2 0x0d =20 /** * struct fw_cdev_event_common - Common part of all fw_cdev_event_* types @@ -423,20 +425,59 @@ struct fw_cdev_event_iso_resource { * @type: %FW_CDEV_EVENT_PHY_PACKET_SENT or %..._RECEIVED * @rcode: %RCODE_..., indicates success or failure of transmission * @length: Data length in bytes + * @data: Incoming data for %FW_CDEV_IOC_RECEIVE_PHY_PACKETS. For %FW_CDEV= _IOC_SEND_PHY_PACKET + * the field has the same data in the request, thus the length of 8 bytes. + * + * This event is sent instead of &fw_cdev_event_phy_packet2 if the kernel = or + * the client implements ABI version <=3D 5. It has the lack of time stamp= field comparing to + * &fw_cdev_event_phy_packet2. + */ +struct fw_cdev_event_phy_packet { + __u64 closure; + __u32 type; + __u32 rcode; + __u32 length; + __u32 data[]; +}; + +/** + * struct fw_cdev_event_phy_packet2 - A PHY packet was transmitted or rece= ived with time stamp. + * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_PHY_PACKET + * or %FW_CDEV_IOC_RECEIVE_PHY_PACKETS ioctl + * @type: %FW_CDEV_EVENT_PHY_PACKET_SENT2 or %FW_CDEV_EVENT_PHY_PACKET_REC= EIVED2 + * @rcode: %RCODE_..., indicates success or failure of transmission + * @length: Data length in bytes + * @tstamp: For %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2, the time stamp of iso= chronous cycle at + * which the packet arrived. For %FW_CDEV_EVENT_PHY_PACKET_SENT2 and non-= ping packet, + * the time stamp of isochronous cycle at which the packet was sent. For = ping packet, + * the tick count for round-trip time measured by 1394 OHCI controller. + * The time stamp of isochronous cycle at which either the response was se= nt for + * %FW_CDEV_EVENT_PHY_PACKET_SENT2 or the request arrived for + * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2. * @data: Incoming data * - * If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT, @length is 0 and @data empt= y, - * except in case of a ping packet: Then, @length is 4, and @data[0] is t= he - * ping time in 49.152MHz clocks if @rcode is %RCODE_COMPLETE. + * If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT2, @length is 8 and @data con= sists of the two PHY + * packet quadlets to be sent, in host byte order, * - * If @type is %FW_CDEV_EVENT_PHY_PACKET_RECEIVED, @length is 8 and @data - * consists of the two PHY packet quadlets, in host byte order. + * If @type is %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2, @length is 8 and @data= consists of the two PHY + * packet quadlets, in host byte order. + * + * For %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2, the @tstamp is the isochronous= cycle at which the + * packet arrived. It is 16 bit integer value and the higher 3 bits expres= ses three low order bits + * of second field and the rest 13 bits expresses cycle field in the forma= t of CYCLE_TIME register. + * + * For %FW_CDEV_EVENT_PHY_PACKET_SENT2, the @tstamp has different meanings= whether to sent the + * packet for ping or not. If it's not for ping, the @tstamp is the isochr= onous cycle at which the + * packet was sent, and use the same format as the case of %FW_CDEV_EVENT_= PHY_PACKET_SENT2. If it's + * for ping, the @tstamp is for round-trip time measured by 1394 OHCI cont= roller with 42.195 MHz + * resolution. */ -struct fw_cdev_event_phy_packet { +struct fw_cdev_event_phy_packet2 { __u64 closure; __u32 type; __u32 rcode; __u32 length; + __u32 tstamp; __u32 data[]; }; =20 @@ -459,6 +500,8 @@ struct fw_cdev_event_phy_packet { * * @request3: Valid if @common.type =3D=3D %FW_CDEV_EVENT_REQUEST3 * @response2: Valid if @common.type =3D=3D %FW_CDEV_EVENT_RESPONSE2 + * @phy_packet2: Valid if @common.type =3D=3D %FW_CDEV_EVENT_PHY_PACKET_SE= NT2 or + * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2 * * Convenience union for userspace use. Events could be read(2) into an * appropriately aligned char buffer and then cast to this union for furth= er @@ -480,6 +523,7 @@ union fw_cdev_event { struct fw_cdev_event_phy_packet phy_packet; /* added in 2.6.36 */ struct fw_cdev_event_request3 request3; /* added in 6.3 */ struct fw_cdev_event_response2 response2; /* added in 6.3 */ + struct fw_cdev_event_phy_packet2 phy_packet2; /* added in 6.3 */ }; =20 /* available since kernel version 2.6.22 */ @@ -547,6 +591,8 @@ union fw_cdev_event { * 6 (6.3) - added some event for subactions of asynchronous transac= tion with time stamp * - %FW_CDEV_EVENT_REQUEST3 * - %FW_CDEV_EVENT_RESPONSE2 + * - %FW_CDEV_EVENT_PHY_PACKET_SENT2 + * - %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2 */ =20 /** @@ -1100,8 +1146,8 @@ struct fw_cdev_send_stream_packet { * @data: First and second quadlet of the PHY packet * @generation: The bus generation where packet is valid * - * The %FW_CDEV_IOC_SEND_PHY_PACKET ioctl sends a PHY packet to all nodes - * on the same card as this device. After transmission, an + * The %FW_CDEV_IOC_SEND_PHY_PACKET ioctl sends a PHY packet to all nodes = on the same card as this + * device. After transmission, either %FW_CDEV_EVENT_PHY_PACKET_SENT even= t or * %FW_CDEV_EVENT_PHY_PACKET_SENT event is generated. * * The payload @data\[\] shall be specified in host byte order. Usually, @@ -1120,8 +1166,9 @@ struct fw_cdev_send_phy_packet { * struct fw_cdev_receive_phy_packets - start reception of PHY packets * @closure: Passed back to userspace in phy packet events * - * This ioctl activates issuing of %FW_CDEV_EVENT_PHY_PACKET_RECEIVED due = to - * incoming PHY packets from any node on the same bus as the device. + * This ioctl activates issuing of either %FW_CDEV_EVENT_PHY_PACKET_RECEIV= ED or + * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2 due to incoming PHY packets from an= y node on the same bus + * as the device. * * The ioctl is only permitted on device files which represent a local nod= e. */ --=20 2.37.2 From nobody Sun Sep 14 08:09:35 2025 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 10281C27C76 for ; Wed, 25 Jan 2023 12:04:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235888AbjAYMD6 (ORCPT ); Wed, 25 Jan 2023 07:03:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235843AbjAYMDj (ORCPT ); Wed, 25 Jan 2023 07:03:39 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F1458671 for ; Wed, 25 Jan 2023 04:03:24 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8CCB55C01BD; Wed, 25 Jan 2023 07:03:23 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 25 Jan 2023 07:03:23 -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; t=1674648203; x= 1674734603; bh=emwjPuAJA02+UQjUpJ9j6SBs61cts4zb343YeiC8Exw=; b=d qLEnG1ZrdLHsiaHZH7Se3GHhqs9Br/qGT+OGCKVkk1WJf1PB4HRHwu8k46120LIj PDH2waylB5SM/c2A+ki42oiziu0kS8+coqzRqsAiSZQ2gA1EUSGYucmX8DyefT0E ZqMsn54i7Y89l8FFex2XQyJ4HDlFO1ILUlE8s2T/gDVGEIGC4PD6D8nDC7DsNBhk Fnlz/kZmirHX3g21HBn3wa+29U0C61VCNJdUGl+Q+vyRzYc1OYg7MT/Z+wkSjH5D o+pJQOT+A8YNdti2Hbe1+zxWKSl9bCtotfN6HzAkJAte1NSiByPpmT+fmQoNLArF qSeQQKG5bA8mr3IHoJShw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id: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=fm3; t=1674648203; x=1674734603; bh=emwjPuAJA02+U QjUpJ9j6SBs61cts4zb343YeiC8Exw=; b=DpKHuLaiwd3eJEJYICQnRol7s+Ptu xXknM4A4Li1yjpuGRojoxJexGfFWGbGJvqoskK6UIZedwQJKI1rlRRczVzLW+ezM IoIt6vs0RPGUhOYvqmHxsEQuQcVo8fXKIjVPfkfE27zrOC+yyl3+5n+3M/dhRv+H ryuvEF80cQgUh9GaM7vD/o1o8L5waLHwRFJYpMwLLh0CLFv8zZQmH3Lq4eGN6CYk VNwzCNKX7VVIpcLEBlR+9JTmyAFu7jB3cN/eXk6frG4rf4Jz8jTtDhWuSJo5HIRB +iNwGPHd9/8jU30qZKUWOX6YkzvpEujAD6NER6Ybb8YhNvImpUNekXjlQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvvddgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Jan 2023 07:03:22 -0500 (EST) From: Takashi Sakamoto To: stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, tiwai@suse.de Subject: [PATCH 11/11] firewire: cdev: implement new event relevant to phy packet with time stamp Date: Wed, 25 Jan 2023 21:03:01 +0900 Message-Id: <20230125120301.51585-12-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125120301.51585-1-o-takashi@sakamocchi.jp> References: <20230125120301.51585-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, the OUTPUT_LAST descriptor of Asynchronous Transmit (AT) context has timeStamp field, in which 1394 OHCI controller record the isochronous cycle when the packet was sent for the request subaction. Additionally, the trailing quadlet of Asynchronous Receive (AR) context has timeStamp field as well in which 1394 OHCI controller record the isochronous cycle when the packet arrived. The time stamps are also available for the cases to send and receive phy packet. This commit implements new events with time stamp field for user space. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 90 +++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 2220de3c945e..6274b86eb943 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -206,6 +206,7 @@ struct outbound_phy_packet_event { struct fw_packet p; union { struct fw_cdev_event_phy_packet without_tstamp; + struct fw_cdev_event_phy_packet2 with_tstamp; } phy_packet; }; =20 @@ -213,6 +214,7 @@ struct inbound_phy_packet_event { struct event event; union { struct fw_cdev_event_phy_packet without_tstamp; + struct fw_cdev_event_phy_packet2 with_tstamp; } phy_packet; }; =20 @@ -1555,7 +1557,6 @@ static void outbound_phy_packet_callback(struct fw_pa= cket *packet, container_of(packet, struct outbound_phy_packet_event, p); struct client *e_client =3D e->client; u32 rcode; - struct fw_cdev_event_phy_packet *pp; =20 switch (status) { // expected: @@ -1583,10 +1584,31 @@ static void outbound_phy_packet_callback(struct fw_= packet *packet, break; } =20 - pp =3D &e->phy_packet.without_tstamp; - pp->rcode =3D rcode; - pp->data[0] =3D packet->timestamp; - queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->lengt= h, NULL, 0); + switch (e->phy_packet.without_tstamp.type) { + case FW_CDEV_EVENT_PHY_PACKET_SENT: + { + struct fw_cdev_event_phy_packet *pp =3D &e->phy_packet.without_tstamp; + + pp->rcode =3D rcode; + pp->data[0] =3D packet->timestamp; + queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->leng= th, + NULL, 0); + break; + } + case FW_CDEV_EVENT_PHY_PACKET_SENT2: + { + struct fw_cdev_event_phy_packet2 *pp =3D &e->phy_packet.with_tstamp; + + pp->rcode =3D rcode; + pp->tstamp =3D packet->timestamp; + queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->leng= th, + NULL, 0); + break; + } + default: + WARN_ON(1); + break; + } =20 client_put(e_client); } @@ -1596,13 +1618,12 @@ static int ioctl_send_phy_packet(struct client *cli= ent, union ioctl_arg *arg) struct fw_cdev_send_phy_packet *a =3D &arg->send_phy_packet; struct fw_card *card =3D client->device->card; struct outbound_phy_packet_event *e; - struct fw_cdev_event_phy_packet *pp; =20 /* Access policy: Allow this ioctl only on local nodes' device files. */ if (!client->device->is_local) return -ENOSYS; =20 - e =3D kzalloc(sizeof(*e) + 4, GFP_KERNEL); + e =3D kzalloc(sizeof(*e) + sizeof(a->data), GFP_KERNEL); if (e =3D=3D NULL) return -ENOMEM; =20 @@ -1616,11 +1637,23 @@ static int ioctl_send_phy_packet(struct client *cli= ent, union ioctl_arg *arg) e->p.header_length =3D 12; e->p.callback =3D outbound_phy_packet_callback; =20 - pp =3D &e->phy_packet.without_tstamp; - pp->closure =3D a->closure; - pp->type =3D FW_CDEV_EVENT_PHY_PACKET_SENT; - if (is_ping_packet(a->data)) - pp->length =3D 4; + if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { + struct fw_cdev_event_phy_packet *pp =3D &e->phy_packet.without_tstamp; + + pp->closure =3D a->closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_SENT; + if (is_ping_packet(a->data)) + pp->length =3D 4; + } else { + struct fw_cdev_event_phy_packet2 *pp =3D &e->phy_packet.with_tstamp; + + pp->closure =3D a->closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_SENT2; + // Keep the data field so that application can match the response event = to the + // request. + pp->length =3D sizeof(a->data); + memcpy(pp->data, a->data, sizeof(a->data)); + } =20 card->driver->send_request(card, &e->p); =20 @@ -1655,20 +1688,33 @@ void fw_cdev_handle_phy_packet(struct fw_card *card= , struct fw_packet *p) spin_lock_irqsave(&card->lock, flags); =20 list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { - struct fw_cdev_event_phy_packet *pp; - e =3D kmalloc(sizeof(*e) + 8, GFP_ATOMIC); if (e =3D=3D NULL) break; =20 - pp =3D &e->phy_packet.without_tstamp; - pp->closure =3D client->phy_receiver_closure; - pp->type =3D FW_CDEV_EVENT_PHY_PACKET_RECEIVED; - pp->rcode =3D RCODE_COMPLETE; - pp->length =3D 8; - pp->data[0] =3D p->header[1]; - pp->data[1] =3D p->header[2]; - queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0); + if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { + struct fw_cdev_event_phy_packet *pp =3D &e->phy_packet.without_tstamp; + + pp->closure =3D client->phy_receiver_closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_RECEIVED; + pp->rcode =3D RCODE_COMPLETE; + pp->length =3D 8; + pp->data[0] =3D p->header[1]; + pp->data[1] =3D p->header[2]; + queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0= ); + } else { + struct fw_cdev_event_phy_packet2 *pp =3D &e->phy_packet.with_tstamp; + + pp =3D &e->phy_packet.with_tstamp; + pp->closure =3D client->phy_receiver_closure; + pp->type =3D FW_CDEV_EVENT_PHY_PACKET_RECEIVED2; + pp->rcode =3D RCODE_COMPLETE; + pp->length =3D 8; + pp->tstamp =3D p->timestamp; + pp->data[0] =3D p->header[1]; + pp->data[1] =3D p->header[2]; + queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0= ); + } } =20 spin_unlock_irqrestore(&card->lock, flags); --=20 2.37.2