From patchwork Thu May 25 10:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98939 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp252743vqr; Thu, 25 May 2023 03:18:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5opdWe5IUEHRHUPMnWvVIeeIqL66iduiKq8/hyEomW/4eQRnwF5fC6RPKOzVFlkk5Z+gX5 X-Received: by 2002:a17:903:191:b0:1af:bbfd:1c07 with SMTP id z17-20020a170903019100b001afbbfd1c07mr1064267plg.57.1685009896724; Thu, 25 May 2023 03:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685009896; cv=none; d=google.com; s=arc-20160816; b=Oa4a2NvRhdSJ9nUXJRfroHHj3F9VwQbNKyZAIzGkVBvix0AgoQUzfTVmgvJDQytY1h 53Z6akQo0HakOTNzmYZoe8QGOaTH9QuQtXEQXY7Qyo5QW1LnzqsMMH44bQg3Jq6/wuIe 7OgOd7ufCxS86bmFFGl4/iw5zf6194ZIAS2CYQQhBwR0HwBFlf5AmogLVKmpMp5DseAn qpfjssIA5x/PxiGGCI9dNHncFuUKDrApv6oAiqH3RrgSj1QtZPVvytueDYELuXe7fP87 6MRZ5aBY4B56yR7Uxlz3UY9QT4TecntQTwOIRC34MHOEOYAyOxo0Qmg1doT9G0yxUFXO WcGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=JW0p8/eDaYU/cW3GeziZHaBybYl27FrC9hzeWZqxqbk=; b=r/42iYMs02KQpmJuLdfBDIFkDzPwstToFiTrS1OonnpYxZ1wvMtEQlXQVTPZoYcksU e68wG9rNUjii6jFA042cYai45WYZpMlLIP6xrJj5WIIfA6Ud/q+SPKeRsketJN4qj+BG cdDGbWZewBPn7F9w3vcxGR7v6pkyYWA/xFpYWaEIp9OuC2wx9SJTdE4c9Fxff7efLxlR Sovr7lw7Dw3G0sMa6yYRP8x1KSeqdHHB4yLSJhDcOdSq2HOofldv4is7+tYGp6l7SFcm TFenXRg3rNLZXGEk1MfQPOdA7j4f2XPWcXC5ft1hVQj4lHZenvErQQLzCN57R/maHplZ /BXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=M38HuQLB; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=rwlAKzTu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a170902a50300b001a92875cda9si1068234plq.288.2023.05.25.03.18.04; Thu, 25 May 2023 03:18:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=M38HuQLB; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=rwlAKzTu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240387AbjEYKR0 (ORCPT + 99 others); Thu, 25 May 2023 06:17:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240917AbjEYKQj (ORCPT ); Thu, 25 May 2023 06:16:39 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79AA61A1 for ; Thu, 25 May 2023 03:16:33 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 9BF0C5C0185; Thu, 25 May 2023 06:16:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 25 May 2023 06:16:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009791; x= 1685096191; bh=JW0p8/eDaYU/cW3GeziZHaBybYl27FrC9hzeWZqxqbk=; b=M 38HuQLBfosmKb8msy8QXeWAgz9AL5eSQIhTGBE0JIvDunZ5bcc1Db3Qc5nX8Lzfd vNBZ2wnjUX3p78KO/oSUksA0Xgz5OE6jpFZcRJoW1IsFoSAfntWB8RHUvyuXHRLq pdbQ6Jxig5+Bz6yHo2fD3S8Ty09mNRVtPCdKbCibhIGemUTHL8+HtLCWRiemotp0 er5DPfFwpdy5dGV0jJs+BUtF+y3qFnojUmQbIqFMPWQXpdRk1KNm6vWjiAcJ4gQW FaUBSotqY+kwXZnWYhbzds+3REGi7ohTcpypi1E3mqMnEmIqv1tl4hLAHRfPgsCh GD81EAOx9RpKe2y396M7A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type: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=fm1; t=1685009791; x= 1685096191; bh=JW0p8/eDaYU/cW3GeziZHaBybYl27FrC9hzeWZqxqbk=; b=r wlAKzTuDanT/5QAAVyo+XdEGMUNsmC0L7csDWOLf9mZYcoL/G1bFzQX+Hzgn3hrS S6gLkVvVxDgi0i2AXOZFA19oLsG+GLJYeshqmMBetHyITTXQxI1Oe1SFtMu9xktx qCcF6iWKwnNweBlGKB0ZFhInqRk/4bTUPh5lES66HIkqgSN+urIDJRJQjICESCT/ TEmxskSLEVCC2CRTVTy+gVvFPN7Su7nYfommglqFY3ARPyu5YK7gidRkyVNJRLV2 ycNgiJ9+rvcpDFDelGX+oVq8IB6fPNPn16LA4oO6KJ920TG9IJj/Bh0wK9/DD5/t VSrNMR72oK1Wmj1XBWftg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeduuddttd euueduledvleethfetleeuledvvddvjeeiueekkeektdegudekffdvveenucffohhmrghi nhepvdejrdhithdpthgvshhtrghnhihthhhinhhgrdhorhhgnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihesshgrkhgr mhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:30 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: kunit-dev@googlegroups.com Subject: [PATCH v2 01/12] firewire: add KUnit test to check layout of UAPI structures Date: Thu, 25 May 2023 19:16:14 +0900 Message-Id: <20230525101625.888906-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766860937356916883?= X-GMAIL-MSGID: =?utf-8?q?1766860937356916883?= In future commits, some new structure will be added to express new type of event. They are exposed to user space as the part of UAPI. It is likely to get trouble in ioctl compatibility layer for 32 bit binaries in 64 bit host machine since the layout of structure could differ depending on System V ABI for these architectures. Actually the subsystem already got such trouble at v2.6.27. It is preferable to decide the layout of structure carefully so that the layer is free from such trouble. This commit utilizes KUnit framework to check the layout of structure for the purpose. A test is added for the existent issue. Cc: kunit-dev@googlegroups.com Signed-off-by: Takashi Sakamoto --- drivers/firewire/.kunitconfig | 4 ++++ drivers/firewire/Kconfig | 16 +++++++++++++++ drivers/firewire/Makefile | 3 +++ drivers/firewire/uapi-test.c | 38 +++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 drivers/firewire/.kunitconfig create mode 100644 drivers/firewire/uapi-test.c diff --git a/drivers/firewire/.kunitconfig b/drivers/firewire/.kunitconfig new file mode 100644 index 000000000000..1599e069395f --- /dev/null +++ b/drivers/firewire/.kunitconfig @@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_PCI=y +CONFIG_FIREWIRE=y +CONFIG_FIREWIRE_KUNIT_UAPI_TEST=y diff --git a/drivers/firewire/Kconfig b/drivers/firewire/Kconfig index ec00a6f70da8..0a6596b027db 100644 --- a/drivers/firewire/Kconfig +++ b/drivers/firewire/Kconfig @@ -18,6 +18,22 @@ config FIREWIRE To compile this driver as a module, say M here: the module will be called firewire-core. +config FIREWIRE_KUNIT_UAPI_TEST + tristate "KUnit tests for layout of structure in UAPI" if !KUNIT_ALL_TESTS + depends on FIREWIRE && KUNIT + default KUNIT_ALL_TESTS + help + This builds the KUnit tests whether structures exposed to user + space have expected layout. + + KUnit tests run during boot and output the results to the debug + log in TAP format (https://testanything.org/). Only useful for + kernel devs running KUnit test harness and are not for inclusion + into a production build. + + For more information on KUnit and unit tests in general, refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + config FIREWIRE_OHCI tristate "OHCI-1394 controllers" depends on PCI && FIREWIRE && MMU diff --git a/drivers/firewire/Makefile b/drivers/firewire/Makefile index e58c8c794778..b24b2879ac34 100644 --- a/drivers/firewire/Makefile +++ b/drivers/firewire/Makefile @@ -15,3 +15,6 @@ obj-$(CONFIG_FIREWIRE_SBP2) += firewire-sbp2.o obj-$(CONFIG_FIREWIRE_NET) += firewire-net.o obj-$(CONFIG_FIREWIRE_NOSY) += nosy.o obj-$(CONFIG_PROVIDE_OHCI1394_DMA_INIT) += init_ohci1394_dma.o + +firewire-uapi-test-objs += uapi-test.o +obj-$(CONFIG_FIREWIRE_KUNIT_UAPI_TEST) += firewire-uapi-test.o diff --git a/drivers/firewire/uapi-test.c b/drivers/firewire/uapi-test.c new file mode 100644 index 000000000000..4dc633b91336 --- /dev/null +++ b/drivers/firewire/uapi-test.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// uapi_test.c - An application of Kunit to check layout of structures exposed to user space for +// FireWire subsystem. +// +// Copyright (c) 2023 Takashi Sakamoto + +#include +#include + +// Known issue added at v2.6.27 kernel. +static void structure_layout_event_response(struct kunit *test) +{ +#if defined(CONFIG_X86_32) + // 4 bytes alignment for aggregate type including 8 bytes storage types. + KUNIT_EXPECT_EQ(test, 20, sizeof(struct fw_cdev_event_response)); +#else + // 8 bytes alignment for aggregate type including 8 bytes storage types. + KUNIT_EXPECT_EQ(test, 24, sizeof(struct fw_cdev_event_response)); +#endif + + KUNIT_EXPECT_EQ(test, 0, offsetof(struct fw_cdev_event_response, closure)); + KUNIT_EXPECT_EQ(test, 8, offsetof(struct fw_cdev_event_response, type)); + KUNIT_EXPECT_EQ(test, 12, offsetof(struct fw_cdev_event_response, rcode)); + KUNIT_EXPECT_EQ(test, 16, offsetof(struct fw_cdev_event_response, length)); + KUNIT_EXPECT_EQ(test, 20, offsetof(struct fw_cdev_event_response, data)); +} + +static struct kunit_case structure_layout_test_cases[] = { + KUNIT_CASE(structure_layout_event_response), + {} +}; + +static struct kunit_suite structure_layout_test_suite = { + .name = "firewire-uapi-structure-layout", + .test_cases = structure_layout_test_cases, +}; +kunit_test_suite(structure_layout_test_suite); From patchwork Thu May 25 10:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp259515vqr; Thu, 25 May 2023 03:31:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6zROOUe3imRPZbL9yPOvXUJluLeCQvql0B27Lt2EvU2T8HSzi4AAYUDELGPUESGKFnV4m6 X-Received: by 2002:a05:6a20:938d:b0:107:35ed:28a7 with SMTP id x13-20020a056a20938d00b0010735ed28a7mr23504230pzh.8.1685010717675; Thu, 25 May 2023 03:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685010717; cv=none; d=google.com; s=arc-20160816; b=Heyz7FHDINHxIfonLeLQTfLalPu2FeD/tYmSduHysHLiW+W2Gic30eNPVYfxKz3037 b7TNkaT/cZCVLBapWPbdQvVVY9HM34k4vJkapRVzeR4HUMJxDdmMIzfyD8o+skASxb8J ivEHbJedEQqNZa3bfz1mBCxJ97PKR0qwzEtbJAFPm/aiB34vYA6VaunxXLIuMxHSmxTE TbyvfqtcGF/9CHzBSziDXsdF6EMnd0UpKzLNaxPn9bdefPX0nNCsP+ypLVrx3ecHevJv EnVmjldo5XM56P9tSLqgMQkOLuwlzyiA8rtvipCOq6FOyey1XZ4k2AUM/NUSfB6A2Mw5 k3pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from:feedback-id :dkim-signature:dkim-signature; bh=Scx2YERYya4XNfuQABUzrTu3FrRelGdDymkzNIze9SM=; b=uGVHw5hPE1YxKBb6GTbrQkSWJS8fD3O5nD+GKwPst8JHVjY4UqS24nzjbTXtqJAMsi lJtykN17MN5G3uUZTd9XguNd37g8F1TJpOC4vVR/OTitTJIy5YIWZCxc/iM0Y2r98JRA +rXnewhNoRhG3JH8tZu3ljUU5pHlewJnyIAtu7s4J0S7usZYg8/bLeb5wQD0pLwhjNFZ e5oVtgLqD8PTsQgMuBslD0RgjrvisfNbocDDWM4q9tsi6tUFB0srfFMGpOV2oiqvgwsb iNFnluvE1F3XdIIRPBKDcWcz1wK3phWfeNgEU+Xx66yKa98DURoDbupXtOnmoMbLi/0k bjUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=tURz73Qy; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=RIlv5kRu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h16-20020a633850000000b0053477896e81si832304pgn.187.2023.05.25.03.31.42; Thu, 25 May 2023 03:31:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=tURz73Qy; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=RIlv5kRu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240932AbjEYKRd (ORCPT + 99 others); Thu, 25 May 2023 06:17:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238966AbjEYKRB (ORCPT ); Thu, 25 May 2023 06:17:01 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 800BF10B for ; Thu, 25 May 2023 03:16:33 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C76315C005E; Thu, 25 May 2023 06:16:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 25 May 2023 06:16:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009792; x= 1685096192; bh=Scx2YERYya4XNfuQABUzrTu3FrRelGdDymkzNIze9SM=; b=t URz73QyTJeNYVfkWY4u8oGDpXhfvPRD4wmi9qORH7g4LETGWvIGVmPu8lfLUMIF9 CXE/laTx96Xb0kHoUdWyQIktPXBxl5mn76XNr83bAdK7kaaGcZw7JvZTaoZrfS1V 52mZh/Ckm5FGNHpUc3c+zK+4MWmtTLdVU1OvqOQlZekBI6acw5YioKUGt6souALf qS0AwQ/KKS7yE0Uhdlmqk9qV1Z2k67pH485EllcZfZqI6HU8r90xlAY0YEsBPMAR DNgLQGOhd3XTkq6OlOrlnQZRyHztzkjvJllC3kRxN44KwRZylP9lBYFho5RndlId GsyTOvk0k5UpP1JJ5TSvA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=fm1; t=1685009792; x=1685096192; bh=S cx2YERYya4XNfuQABUzrTu3FrRelGdDymkzNIze9SM=; b=RIlv5kRuoe2I7bagc HKNwjq7jiM+akJ66uEsfL1gqofg2EGh213DjhuXyWzx5nEQKwGbhageywJOWcnwI IFwOajenEdad7HrteyCmeJksvbL4lMZQOyZSHTxoxI/P1Q2e15WC9QQiT2FHuioc ZtkC74kzNlagxJpNKJDLBWifbQ2QeVu+HuaiS3mpDr8YJCkvaZt5KZ0+opY8AJ5S hNOgfjuDFwVtpfWOES7srSeHh5boR6fYbVXL0RdWyn0hrE4rH6CXaCoeiTvgApW1 ZPy1frlDtIR02P68s9bBbqolfD6PjimAUzB6XGTTj1+YPHBF+QK+J4n41FzQ54My dXHVg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:31 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/12] firewire: cdev: add new version of ABI to notify time stamp at request/response subaction of transaction Date: Thu, 25 May 2023 19:16:15 +0900 Message-Id: <20230525101625.888906-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766861798097219541?= X-GMAIL-MSGID: =?utf-8?q?1766861798097219541?= 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 struct client { u32 version; diff --git a/include/uapi/linux/firewire-cdev.h b/include/uapi/linux/firewire-cdev.h index 92be3ea3c6e0..e3d463b2c288 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.4) - added some event for subactions of asynchronous transaction with time stamp */ /** From patchwork Thu May 25 10:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98948 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp260222vqr; Thu, 25 May 2023 03:33:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54dERCviKExzDiOBCgyU4cJ7PDKzeP4Kpcn4wQpVs5TzHwpEmpY3h5+5jF1u98YmWrhRgo X-Received: by 2002:a17:902:f54b:b0:1ae:4ee3:e3e6 with SMTP id h11-20020a170902f54b00b001ae4ee3e3e6mr1252374plf.32.1685010803120; Thu, 25 May 2023 03:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685010803; cv=none; d=google.com; s=arc-20160816; b=RZk9o3Kuuo0S/fdT0oBlgZRokWYF81kvwu5t8fpEjh/WxUt7jwoOOkVd/C9iIRLPlX Nof0MzgGWwXn91gbnKhkhwbPSxz4gq2ZytEV6C6fGAlhqWS7NGzTA7yre/OUK6CbpT+S CXTMyed0igmt4eezrbElhuV9aF1oMSyzy1VVFak5oxzxAbHRfSaf8OdWoeuAF19cHE/X hWRWKKhKKDq8DMX0K89RAME/Z1tgjjappuRtjfQ6iys8uxXksIR9m5ro2rej49A9JGHu +ooWImVvKverZgNKqQLsi3sopzFD97fOQ8gtISRV+THS0CE8FYmUv1GGaqQADfgoopDb Upng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=r495ZagNUl310AfgMMzJgvZvJuQiL4XuaB6fjhkP/AM=; b=JyNZN/qBaWw4+nPd/58IEGhAv5Qnnqf0dHYgutK0KkUzSe8h1cjE9+lPC43Xx41VlU ujXegJrWannzRvKwm4srSyeXi8P4Cz0LUexyJVcgBzkCJVASuLKZuHt5KZJNDS3wlhtA 8YEv7kr4uek29G6HwgwIPJOadH2KOmiQG74mZE0xKCjUozYC8269zerByToXYJPYU5I9 sXtP0EJW6TaXUd+JRB+plZFKYNOfc7Yn60IsIysxRx6FfLEABHvcWAOaNwAO/EbDqbh7 WKoeMBzExJUDHQrxSrV4RQBuf1HsX3k84DKnQQ2Ch1VJb4ZR9iolEQYKHhXsaKuBof0d DfzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="iqgF/nnY"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=wEFYEc6u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jb12-20020a170903258c00b001a95b85b070si1080479plb.604.2023.05.25.03.33.09; Thu, 25 May 2023 03:33:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="iqgF/nnY"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=wEFYEc6u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240938AbjEYKRj (ORCPT + 99 others); Thu, 25 May 2023 06:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240760AbjEYKRB (ORCPT ); Thu, 25 May 2023 06:17:01 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C055C97 for ; Thu, 25 May 2023 03:16:34 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3C0525C0073; Thu, 25 May 2023 06:16:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 25 May 2023 06:16:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009794; x= 1685096194; bh=r495ZagNUl310AfgMMzJgvZvJuQiL4XuaB6fjhkP/AM=; b=i qgF/nnYKwfppxuAEfHdL6pIOQPgJlZpK+d6Va+j4q1EagO9KBToJpvoVcYlwxFMI JJVV0kx/WJun0FOD6uQKFTTncaIadoFdtsiW63NLrYOd5eTdBPmLxCCOrCwP42Ha KN+XfWstVXN+DNErclkBGqV49reGUsvfynww4gq9Zymcc/wNKYOcG5Ux+bZlQjjV c9822Bn5bE/7AYBDvwjj7Igl0J7qKD/tw2gI8Dd+Y8ivtEm2pRWd+1imK8Iprwv4 rzyECmoTBqRuBtNpqHFf8RTAqwcA3I/zRXxBpKp+nI+KHFNrhcXIS+oFepXICDKV mdnNUoO2U/PlWf5hujgTg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type: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=fm1; t=1685009794; x= 1685096194; bh=r495ZagNUl310AfgMMzJgvZvJuQiL4XuaB6fjhkP/AM=; b=w EFYEc6uOvXpXWYdYkuJ9i6bxI3y5bj/DI1btRroDa/F/gEYG0vSrFZzOdt1vgcVy Uh6khPeQ/Qnzwx0orXFDqB5nkRWm96xmOD4QcotHhayVuIeTNjnlfLmn/S/Abyca 7PDFd4vLXiqvdJdvHiVdATINP0hc5/l4sX7sIYdr0KejmzrAYLts46xtcwbvqoLj q7Nuf0/XyPpKfRUyXi+sI+cvHKKR3jqJdgBjDkJ6xfeRbflOSpmAvDPl0vfCA9wE ezw0F1zFHZ1YnomV/MKXDrZe7TgiGGI7XXXSL+fZSm+spnWXY9ePfb9XMAyFJN32 FhfoRnOJ7M2vi/9KH9q6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:32 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: kunit-dev@googlegroups.com Subject: [PATCH v2 03/12] firewire: cdev: add new event to notify request subaction with time stamp Date: Thu, 25 May 2023 19:16:16 +0900 Message-Id: <20230525101625.888906-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766861887529188042?= X-GMAIL-MSGID: =?utf-8?q?1766861887529188042?= 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. Cc: kunit-dev@googlegroups.com Signed-off-by: Takashi Sakamoto --- drivers/firewire/uapi-test.c | 20 +++++++++++ include/uapi/linux/firewire-cdev.h | 53 ++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/uapi-test.c b/drivers/firewire/uapi-test.c index 4dc633b91336..c7c713babaa0 100644 --- a/drivers/firewire/uapi-test.c +++ b/drivers/firewire/uapi-test.c @@ -26,8 +26,28 @@ static void structure_layout_event_response(struct kunit *test) KUNIT_EXPECT_EQ(test, 20, offsetof(struct fw_cdev_event_response, data)); } +// Added at v6.4. +static void structure_layout_event_request3(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, 56, sizeof(struct fw_cdev_event_request3)); + + KUNIT_EXPECT_EQ(test, 0, offsetof(struct fw_cdev_event_request3, closure)); + KUNIT_EXPECT_EQ(test, 8, offsetof(struct fw_cdev_event_request3, type)); + KUNIT_EXPECT_EQ(test, 12, offsetof(struct fw_cdev_event_request3, tcode)); + KUNIT_EXPECT_EQ(test, 16, offsetof(struct fw_cdev_event_request3, offset)); + KUNIT_EXPECT_EQ(test, 24, offsetof(struct fw_cdev_event_request3, source_node_id)); + KUNIT_EXPECT_EQ(test, 28, offsetof(struct fw_cdev_event_request3, destination_node_id)); + KUNIT_EXPECT_EQ(test, 32, offsetof(struct fw_cdev_event_request3, card)); + KUNIT_EXPECT_EQ(test, 36, offsetof(struct fw_cdev_event_request3, generation)); + KUNIT_EXPECT_EQ(test, 40, offsetof(struct fw_cdev_event_request3, handle)); + KUNIT_EXPECT_EQ(test, 44, offsetof(struct fw_cdev_event_request3, length)); + KUNIT_EXPECT_EQ(test, 48, offsetof(struct fw_cdev_event_request3, tstamp)); + KUNIT_EXPECT_EQ(test, 56, offsetof(struct fw_cdev_event_request3, data)); +} + static struct kunit_case structure_layout_test_cases[] = { KUNIT_CASE(structure_layout_event_response), + KUNIT_CASE(structure_layout_event_request3), {} }; diff --git a/include/uapi/linux/firewire-cdev.h b/include/uapi/linux/firewire-cdev.h index e3d463b2c288..cc9b03244a62 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 +/* 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 <= 5. It has the lack of time stamp field comparing to &fw_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 arrived. + * @data: Incoming data, if any + * * This event is sent when the stack receives an incoming request to an address * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl. The request is * guaranteed to be completely contained in the specified region. Userspace is @@ -191,10 +226,14 @@ struct fw_cdev_event_request { * sent. * * If the client subsequently needs to initiate requests to the sender node 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 format 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 architectures since + * 4 byte alignment is used for 8 byte of object type in System V ABI for i386 architecture. + */ + __u32 padding; __u32 data[]; }; @@ -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 == %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 further * 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.36 */ 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 */ }; /* 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.4) - added some event for subactions of asynchronous transaction with time stamp + * - %FW_CDEV_EVENT_REQUEST3 */ /** From patchwork Thu May 25 10:16:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp263368vqr; Thu, 25 May 2023 03:40:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ78VZzHLVKol+3HvhY9MO3bfjoA5hjJ3RiXxArC+0qIrNzFBbGqcZip5IOwAjO8k5VeQ/bm X-Received: by 2002:a17:903:230a:b0:1af:9c18:a160 with SMTP id d10-20020a170903230a00b001af9c18a160mr1418682plh.17.1685011231040; Thu, 25 May 2023 03:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685011231; cv=none; d=google.com; s=arc-20160816; b=jlnf0bQ+MorpZmpn79rYIXmJoLT8Qoe+q/Eyi1874VgKdfxXh33Q/TIdBfWQAX8/aZ BZIC0HKVnx33f/9b+NT4iDdlZLqhJA5Vzy2tfXac8mmStENeNcn9/PMYeSwVcO2c1Yuf ixphVglZD1vv0Mq2w9Gh4wy7Uhjwy08NgkyhGkjuwYlnGK1sVHlwv+uRV5t8YqWQZamL FLDAiqdY6dJ3v/HxNWLUZ9TxrzUIu8h2NIuenmMBupVWi1B2sxKgqfmrRnZymN6ZWAgg wg1I5sRn+aBtm+pBd6Hqg2bZncc264oWE00Ey5Yzy0pnfXkhuvFfCodJu0jnMJv3ji2h uA3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from:feedback-id :dkim-signature:dkim-signature; bh=vLnKaQC1H8MrzTAmo/K64YxxQOflNTjfEH6QTfOvlSY=; b=Rhx6NGYFZ3B+otBPzyomguojmI28In/Fgrt6OT9TrCokCtWxbOEjFjwbG1VgfRmAKe 7uCtpiynY5FS6ahGQJNvJN4E76HIrVrE28aeAPaGsmpBCeSeVmZGfi1zVcDcbhYcuObC +/SvwxOHfalkvOQfqbeRCYtMgex/xbqDP5r4KOw4DpsbCIfSlivdxPS89vSb/mWuv6Vr huCKshErGgNo2fR7cUOkKZBQ2YstgC4K8KHztDWSfg+PgJP0dbO99oAR3ZZM4ps+Nbcr Dz8BVJMri5YNCuEsyUPHYnXhUgroK50jZfLGozRyKt6y6SBKgnjUEhKK4JqE8Mj+GSrK hHTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=rMe9UGIK; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=lS+pVgxA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t15-20020a170902e84f00b001a64b603189si1293930plg.100.2023.05.25.03.40.16; Thu, 25 May 2023 03:40:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=rMe9UGIK; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=lS+pVgxA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240960AbjEYKRr (ORCPT + 99 others); Thu, 25 May 2023 06:17:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240840AbjEYKRC (ORCPT ); Thu, 25 May 2023 06:17:02 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 059BF1A8 for ; Thu, 25 May 2023 03:16:36 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 64BEA5C01ED; Thu, 25 May 2023 06:16:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 25 May 2023 06:16:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009795; x= 1685096195; bh=vLnKaQC1H8MrzTAmo/K64YxxQOflNTjfEH6QTfOvlSY=; b=r Me9UGIKIYubaxAzCMoCJuLL34vKW9rQ3GKszPnxYTlYZ1j8KDBcMffbPNecKOSXH cRKo3FdfbF2rlgaibRS2mNdaq9LGhseuxU2Fb3PviqgSrOfacDVquY3Fj6dVyn1X +bspzWcyN5IZVHGR1c2MdoKVmWxMMixL9KRE01X45W7zRBxYGMcQy5nA/zq7ZSM0 DP01O7xVbW+x2UMNy9XCrgernAQMZ2rcM4LusRFuWA5MGGbj02cQJ+TKE/rAlyy3 gok6gx22YZh9T7suL7AoWCm/7ZKgQ8449UA203Av61ZP070y8c7rgNxPH66UrM1B EiQdMORotKg6Px9NyXaiQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=fm1; t=1685009795; x=1685096195; bh=v LnKaQC1H8MrzTAmo/K64YxxQOflNTjfEH6QTfOvlSY=; b=lS+pVgxAzWARH2r9Y T+6JkJEWcgIJaDGl6EQORgrlc6Qet4reqm7KqQ7q8CifGvzj/l/01Zv5to9yXvu9 vu0mT3Neil9g2/rJB3/rggUHOvVH0prXaxQDJ7/KLc5q/kJNjRys/KWAgw8DmZKq v3caOZUX70cjtwWiAVy//MeJvDzoRLv6g703KVhDJac10ReHOPz7OJLoKWKnbs29 DYHQYiHGuFXCurMBuEQuSO7Mg74hlKBk+SW1U0JnNg+ZdFDFMM6WFveV96w1eZh8 ASDku0nzuqR2KYHRTxnLHSxdYM56gAR0sHvSBDDPuPs9qL7a++t30YHnB+S4ksk1 hfNDQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:34 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/12] firewire: cdev: implement new event to notify request subaction with time stamp Date: Thu, 25 May 2023 19:16:17 +0900 Message-Id: <20230525101625.888906-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766862336502965202?= X-GMAIL-MSGID: =?utf-8?q?1766862336502965202?= 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; }; @@ -709,7 +710,7 @@ static void handle_request(struct fw_card *card, struct fw_request *request, req->handle = r->resource.handle; req->closure = handler->closure; event_size0 = sizeof(*req); - } else { + } else if (handler->client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { struct fw_cdev_event_request2 *req = &e->req.request2; req->type = FW_CDEV_EVENT_REQUEST2; @@ -723,6 +724,21 @@ static void handle_request(struct fw_card *card, struct fw_request *request, req->handle = r->resource.handle; req->closure = handler->closure; event_size0 = sizeof(*req); + } else { + struct fw_cdev_event_request3 *req = &e->req.with_tstamp; + + req->type = FW_CDEV_EVENT_REQUEST3; + req->tcode = tcode; + req->offset = offset; + req->source_node_id = source; + req->destination_node_id = destination; + req->card = card->index; + req->generation = generation; + req->length = length; + req->handle = r->resource.handle; + req->closure = handler->closure; + req->tstamp = fw_request_get_timestamp(request); + event_size0 = sizeof(*req); } queue_event(handler->client, &e->event, From patchwork Thu May 25 10:16:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp260766vqr; Thu, 25 May 2023 03:34:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4cW24j2YRdAIF91oIVg9+uj7L3dRXdodKYYWfd3Cn2CamWsFwhn+UWcFec/qsSICdoq/i/ X-Received: by 2002:a05:6a20:2453:b0:103:558c:516 with SMTP id t19-20020a056a20245300b00103558c0516mr19217411pzc.55.1685010871745; Thu, 25 May 2023 03:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685010871; cv=none; d=google.com; s=arc-20160816; b=pqKBVADJloHCjLFqoBZrMXvV5e8xubeYxZ2dRkHzT/tgz3j8zzxqLJE09lS9H5ZJlF /mYzHWD1ExMfon+fznuCnBk1TUsEwppDnDNDQS/zJ5SXCj5C7+wIm9jOsmdOMTFgZlAA tzbtplxANrbRwwKTsPIwHK5/n3h3TUSksLGmnPVdvT2vdsiJBO29Jstz+vKvUDIBUw0M pfBeDW00P9yCFg/ovOmqfWXu7wgURNIp1x1yQ6Hduoz0+4eNwG2sQy96Pwz4PIbB7qCF 57hJN6eXeSpYO93v41SL6Iw2v8FSvkPHVJMH3HPWywUwU/lzsXXD3b45+12Z/hHtfLmC R+yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from:feedback-id :dkim-signature:dkim-signature; bh=hOQR9q6EZS1DH1YormYT1kFTGnL+BePtUImO4q3mnKw=; b=yActGTV1HdCPywMrSKiC62hfy3abZWs27ipXeorYffhiUA4BkhlcaFr0xWHUsy9+u2 9YeLGiqKZpzHl+uo0NjtlZEa7kZAEQVE7sv56QDWVIL7GWPwol+7smQ1UVriLGjWBR5D 9tm9/Fr7+bS/ZTaJ3N1m+jFnKxnFLl4qIW83ha4Br3LzEBTFPLwjkRHEVXFBBU0zccRr 9TWVd1CKVDvW1hxj++raWuen1wg1U/Y56AJIAHwEr0OQYMkXlhCM+Z3Uqt5T1QuzNUto hSxkpPzqr6xVHsqsoW1S76o+gKy/mLn3jC8fQ0mRn+pDkTyF6rUaK4uV3hv5sWjJeBLY 2NnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=gr7hJ3vQ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=LN7GnfEn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt15-20020a63290f000000b0053efcd2001fsi285489pgb.883.2023.05.25.03.34.16; Thu, 25 May 2023 03:34:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=gr7hJ3vQ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=LN7GnfEn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240968AbjEYKRv (ORCPT + 99 others); Thu, 25 May 2023 06:17:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240896AbjEYKRE (ORCPT ); Thu, 25 May 2023 06:17:04 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22C5D139 for ; Thu, 25 May 2023 03:16:38 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id DD9E85C02D3; Thu, 25 May 2023 06:16:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 25 May 2023 06:16:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009796; x= 1685096196; bh=hOQR9q6EZS1DH1YormYT1kFTGnL+BePtUImO4q3mnKw=; b=g r7hJ3vQm5QJME7340Sc4YOiTBy8PFPziGNXeIP3aH1d2oOIJh1EysP8CDBze8RVE IR7b+hVYG9XoBT4Mo5Xk8xFlJlxXb4YGNei3cLWe1cI1QHS4KtYVa30nx2sgTDUV CR0Fl5e+21oO8NwzLQAwHvqoEQPXMJnSHnkaf6f/rN/enLBTj/ffnjVOJOgViewb aGd5OxzPRa4r5DZ9Y0SJp0nbuIzQj/jDR2xYzp9siCJa3MbOU4gYcTYZQHPb8yBP NW3bvrzpCRYc9GCPUF4rVZH4fkJnoRt43KV7HjyLTnIUUvJVpdHwp83Z5s/pHtUF iltevI/SPI4EmDw7FEs9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=fm1; t=1685009796; x=1685096196; bh=h OQR9q6EZS1DH1YormYT1kFTGnL+BePtUImO4q3mnKw=; b=LN7GnfEnUGzZRK5D6 pK9987dlhXbcZBACuvDueol19Gtj0wnnw41bPSeC4+2jfWeHrNOya+x3XJHqSY7H 1UqPA2r0tder52PtzpwQ3ehHtS2mF6WKqvoqlkfwaxIEaw/OTjYDyj+8T9OGhFdP 7X+heh3WD9ynbsFA3F2JCYFwHMGBkvxJWSZmysT/0SmSu9iN1p3SclI2mRsB5/9L 1yvQGYYwfdmLN7wg8xKnmWhKvEEmxNgdS4uFw7As990Je29fMPQTF2XMgXSbTNJI qSwES/xj540QBmBhOGqWRrjF05JvZPlkHkotwHUNkubfAlEjggeSStQ/fLyc6ca+ npC4Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:35 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/12] firewire: core: use union for callback of transaction completion Date: Thu, 25 May 2023 19:16:18 +0900 Message-Id: <20230525101625.888906-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766861959539887600?= X-GMAIL-MSGID: =?utf-8?q?1766861959539887600?= 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-transaction.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; } -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 = NULL, *iter; unsigned long flags; @@ -92,7 +92,12 @@ static int close_transaction(struct fw_transaction *transaction, spin_unlock_irqrestore(&card->lock, flags); 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_tstamp, + NULL, 0, t->callback_data); + } return 0; } @@ -107,6 +112,8 @@ static int close_transaction(struct fw_transaction *transaction, 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. */ - return close_transaction(transaction, card, RCODE_CANCELLED); + if (transaction->packet.ack == 0) { + // The timestamp is reused since it was just read now. + tstamp = transaction->packet.timestamp; + } else { + u32 curr_cycle_time = 0; + + (void)fw_card_read_cycle_time(card, &curr_cycle_time); + tstamp = cycle_time_to_ohci_tstamp(curr_cycle_time); + } + + return close_transaction(transaction, card, RCODE_CANCELLED, tstamp); } EXPORT_SYMBOL(fw_cancel_transaction); @@ -140,7 +157,12 @@ static void split_transaction_timeout_callback(struct timer_list *timer) card->tlabel_mask &= ~(1ULL << t->tlabel); spin_unlock_irqrestore(&card->lock, flags); - 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_data); + } else { + t->callback.with_tstamp(card, RCODE_CANCELLED, t->packet.timestamp, + t->split_timeout_cycle, NULL, 0, t->callback_data); + } } static void start_split_transaction_timeout(struct fw_transaction *t, @@ -162,6 +184,8 @@ static void start_split_transaction_timeout(struct fw_transaction *t, spin_unlock_irqrestore(&card->lock, flags); } +static u32 compute_split_timeout_timestamp(struct fw_card *card, u32 request_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_packet *packet, 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 = + 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_transaction *t, int tcode, t->is_split_transaction = false; timer_setup(&t->split_timeout_timer, split_transaction_timeout_callback, 0); - t->callback = callback; + t->callback.without_tstamp = callback; + t->with_tstamp = false; t->callback_data = callback_data; fw_fill_request(&t->packet, tcode, t->tlabel, @@ -1047,7 +1076,12 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p) */ card->driver->cancel_packet(card, &t->packet); - 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_data); + } else { + t->callback.with_tstamp(card, rcode, t->packet.timestamp, p->timestamp, data, + data_length, t->callback_data); + } } EXPORT_SYMBOL(fw_core_handle_response); 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); +// Convert the value of IEEE 1394 CYCLE_TIME register to the format of timeStamp 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) } } +static u32 get_cycle_time(struct fw_ohci *ohci); + static void at_context_transmit(struct context *ctx, struct fw_packet *packet) { 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]) == ctx->ohci->node_id && ctx->ohci->generation == packet->generation) { spin_unlock_irqrestore(&ctx->ohci->lock, flags); + + // Timestamping on behalf of the hardware. + packet->timestamp = 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 = at_context_queue_packet(ctx, packet); spin_unlock_irqrestore(&ctx->ohci->lock, flags); - if (ret < 0) - packet->callback(packet, &ctx->ohci->card, packet->ack); + if (ret < 0) { + // Timestamping on behalf of the hardware. + packet->timestamp = cycle_time_to_ohci_tstamp(get_cycle_time(ctx->ohci)); + packet->callback(packet, &ctx->ohci->card, packet->ack); + } } 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 = NULL; packet->ack = RCODE_CANCELLED; + + // Timestamping on behalf of the hardware. + packet->timestamp = cycle_time_to_ohci_tstamp(get_cycle_time(ohci)); + packet->callback(packet, &ohci->card, packet->ack); ret = 0; out: diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 1716c01c4e54..d61693341da1 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -261,6 +261,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. @@ -312,6 +321,7 @@ struct fw_transaction { struct fw_card *card; bool is_split_transaction; struct timer_list split_timeout_timer; + u32 split_timeout_cycle; struct fw_packet packet; @@ -319,7 +329,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; }; From patchwork Thu May 25 10:16:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98959 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp265402vqr; Thu, 25 May 2023 03:45:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6WffSxlqFv6K95MptAFTmgaurhHkFUtTbVVb52HLr2MZiz2T9M4xAAO+wHjRnCw9qp3cgh X-Received: by 2002:a17:902:8649:b0:1a6:74f6:fa92 with SMTP id y9-20020a170902864900b001a674f6fa92mr1359912plt.19.1685011500115; Thu, 25 May 2023 03:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685011500; cv=none; d=google.com; s=arc-20160816; b=HzyVvDe1+zeQTjB8O/5Z2jRdfAOVqmfgkO99gTCrymOQc//lPWd3yTKS7KsJMdsq9T Iz7rTbR6lHMbDpFecRv82QXXYxXif3+HEQ/Zg41JgbglSRW0jzWPH1GlhVukMZIb4vef xgVwMsaw+LHckU6UGQgq4gHYluN3ar5xyKutYpuxT2QIcfNRdzL+l/irykkEFI7xBAok erdao4uUr4UtRX/Oib0eYjdaLWl69kzlFCziCRfHBMM2cNtG51i287oaOAWfK2348Tg8 Htmdggt/R0eqaMO8ZveESueRvUnGjUGy9PIYmyWleWHHUeenI47tbdJRhvDTIbeRJPP1 oP+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from:feedback-id :dkim-signature:dkim-signature; bh=Zx5vRuZcoTFwzB00ySCuly08OEL537Ypl8d8EH6oHiA=; b=iDcDGknaLIVK1IhsiXmufFzhwIKBe+YDnGbyWIMkBHr4df5vz+DJS5DV+mEjtxYJ4W DWlxc9L2t+9bUGQCIQOkCbhJvobRJom6BgPjovwsLZlewsUBH6uQY5uouGGL0RnMMTo1 ihK0hyoeF/tR4Hybt817CMf224zn/b7ypUPLwh6lAYt8OkSODEPcAD5bIS4/1cdurnaN ifpIepe0DxGLgQrkMPOxn/HH/RkjJoZHve/L34Tp88cOoDNOGWey6pDYEq043heMwQHd uC/tkNAEVI5kElPV9IEPsHbiK4Hz29h93cvba7ccq4Ei5t1pJSr7A8miFW/jNXz/PDEh +koA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=lm74cWIz; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=gimzlISC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t15-20020a170902e84f00b001a64b603189si1293930plg.100.2023.05.25.03.44.32; Thu, 25 May 2023 03:45:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=lm74cWIz; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=gimzlISC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240973AbjEYKRz (ORCPT + 99 others); Thu, 25 May 2023 06:17:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240910AbjEYKRE (ORCPT ); Thu, 25 May 2023 06:17:04 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22EF61B9 for ; Thu, 25 May 2023 03:16:38 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 296265C0244; Thu, 25 May 2023 06:16:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 25 May 2023 06:16:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009798; x= 1685096198; bh=Zx5vRuZcoTFwzB00ySCuly08OEL537Ypl8d8EH6oHiA=; b=l m74cWIzolzGl1ucQMSKLGaBg07P2vizDWBXWO0+s6MAi+KHg+JNgGT8bJeJxdNSf VCqkbw/l8lsRh/jXmNJC+aUsTWyy24BrXrlXh62Bklvz3hHwvqMyFX4dcFJdb1K7 3oF0+sAmP91Wba/EtzxkEgra/BT37rMEDOeI1U/VxvuDt4pn+10LddS4+muEYJ0S bgApsubG/EUbmcsvQq2mdq4XY+j+OebRoQUoyrFl6qM5gILktTjAZR2Kw0Rskpbl CzUEsGy1svOOmH3/VWSPI5yK1cJjA+GKhxTC2KK536SGOOSA5ERnoWE8DfM1LK/k NJQ8EUoeqC1Vmst9lKGWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=fm1; t=1685009798; x=1685096198; bh=Z x5vRuZcoTFwzB00ySCuly08OEL537Ypl8d8EH6oHiA=; b=gimzlISCzlg/ojFrl quqOQaRddmnklRE08uxjIIgoReweKBeyICy5sfqxBifEDrQDPmDR7VQZJ13A9WQy sADtAcCS4I1zL/p0lMaXlGhZKhqSQbBxXcswCTWy4EiAeygSa7ZsQSfubA+sCORf X3VFduQItKfOe/uAawXouYPRtENiz+tjp2kmrmfji9F6SYpMVA8aigit05nNL8Vu fgWtxYCymOFNRgvGF05WQeL4fv9AmDa6WRG7kjBRwdBxjpIUP4LtimN/EZgBGIfB snnR9YAnrfx+1eYqbqMpouYHESntwzKz3A3/jRcwoOCqzyaPk+Kb33r5bb6N0Mmp 6UIIw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:37 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/12] firewire: core: implement variations to send request and wait for response with time stamp Date: Thu, 25 May 2023 19:16:19 +0900 Message-Id: <20230525101625.888906-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766862618734803993?= X-GMAIL-MSGID: =?utf-8?q?1766862618734803993?= 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-transaction.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) } /** - * fw_send_request() - submit a request packet for transmission + * __fw_send_request() - submit a request packet for transmission to generate 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 subaction. * @callback_data: data to be passed to the transaction completion callback * * Submit a request packet into the asynchronous request transmission queue. @@ -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 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) { unsigned long flags; int tlabel; @@ -381,7 +384,19 @@ void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, tlabel = 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 = 0; + u32 tstamp; + + (void)fw_card_read_cycle_time(card, &curr_cycle_time); + tstamp = cycle_time_to_ohci_tstamp(curr_cycle_time); + + callback.with_tstamp(card, RCODE_SEND_ERROR, tstamp, tstamp, NULL, 0, + callback_data); + } return; } @@ -389,14 +404,12 @@ void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, t->tlabel = tlabel; t->card = card; t->is_split_transaction = false; - timer_setup(&t->split_timeout_timer, - split_transaction_timeout_callback, 0); - t->callback.without_tstamp = callback; - t->with_tstamp = false; + timer_setup(&t->split_timeout_timer, split_transaction_timeout_callback, 0); + t->callback = callback; + t->with_tstamp = with_tstamp; t->callback_data = callback_data; - 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 = transmit_complete_callback; @@ -406,7 +419,7 @@ void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, card->driver->send_request(card, &t->packet); } -EXPORT_SYMBOL(fw_send_request); +EXPORT_SYMBOL_GPL(__fw_send_request); struct transaction_callback_data { struct completion done; diff --git a/include/linux/firewire.h b/include/linux/firewire.h index d61693341da1..a7fd23d0010d 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -356,10 +356,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 generate 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 subaction without time + * stamp. + */ +static inline 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) +{ + union fw_transaction_callback cb = { + .without_tstamp = callback, + }; + __fw_send_request(card, t, tcode, destination_id, generation, speed, offset, payload, + length, cb, false, callback_data); +} + +/** + * fw_send_request_with_tstamp() - submit a request packet for transmission 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 subaction with time stamp. + */ +static inline void fw_send_request_with_tstamp(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_with_tstamp_t callback, + void *callback_data) +{ + union fw_transaction_callback cb = { + .with_tstamp = callback, + }; + __fw_send_request(card, t, tcode, destination_id, generation, speed, offset, 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, From patchwork Thu May 25 10:16:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp265011vqr; Thu, 25 May 2023 03:44:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Kts0mCELCdy90QAeqw80aGnFj1nVIJL+TeDIIJ1mZ5hDPjPR0mMhQzuVL5Id/lW8bYR+y X-Received: by 2002:a17:902:8d8a:b0:1ad:ea13:1914 with SMTP id v10-20020a1709028d8a00b001adea131914mr884477plo.30.1685011449116; Thu, 25 May 2023 03:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685011449; cv=none; d=google.com; s=arc-20160816; b=xI0T1Pu9PpJr07ApvoYlTU1LpK+6nfGcf5pvB8eHSBbDeZoAw0tcDquPkPEtJHiAOK zlufOHythf1Sf500BbhqN1IzrU7YBtAxheaJzhMtMJ5+RpCBFE3knwylDX0uHkk7H4Xz uiizd7UGRtmS5rLGl5c/Eda+vbnazcYFC80vNEruCEd6S8VNv+IL1LhLKyvtaHAK8it6 u4uVCNNz7xiSdrJpxx1n51UazWiYmP+hVtOcWrHkb4IDLVtPZO8mxLCnb/IpBSKr6nYd mqxAvTSo/WuanT+Roq6RogofUTF+jbVuRf3hezz+NvDMnVpxThGZy17fgMbQztBaBvMd HMsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from:feedback-id :dkim-signature:dkim-signature; bh=hCn80S16t5KWMrqhGJtFmBVIPiQ9NKvnaZBu9C4Y5xc=; b=FTQkv6Ogq+CJf4xepf/bJznrm3FElc6DBd9zvaRVJCJRLH0K6E5lq6Y5Q4/enXy9uu HtWaXotKXNCQZD8i6eRG57s4j+jaxZZuCmWjmxbxrmSfAYajvaHrzMKQFS8B4A7I18ub Zrh4M5mgbMzujePFjdIwOXu27LwIo7NiST6EWlSIecxdXIya5LUroUuNoF8C5eRMhV0R ECxHPh8eLJCj/jz6dqmGmGYIHBvrSAm2Sx5yYnUf3SRRLs5Qik5WBDYKp5hgfiCza3WG vjNzLNcJqRixfWPJxizMHWSZlYw92VzElLksbkU3hz6R9ec1h9JSYnQgdKek50udTpxr cl/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="SpX+U/7b"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ygaLTXeB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 7-20020a17090a018700b00247ad6e4188si1576090pjc.51.2023.05.25.03.43.54; Thu, 25 May 2023 03:44:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="SpX+U/7b"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ygaLTXeB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240979AbjEYKR6 (ORCPT + 99 others); Thu, 25 May 2023 06:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240912AbjEYKRE (ORCPT ); Thu, 25 May 2023 06:17:04 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F21661B5 for ; Thu, 25 May 2023 03:16:39 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 67BD85C01A2; Thu, 25 May 2023 06:16:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 25 May 2023 06:16:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009799; x= 1685096199; bh=hCn80S16t5KWMrqhGJtFmBVIPiQ9NKvnaZBu9C4Y5xc=; b=S pX+U/7bbNrznA7H2rB6zu/T594d7BHGsU1A5ERwF0Xgu9TYlHw1XjggBptgpLH/x jF/EHY+ykLsMS3bSZVw2WcED+vJtDDVh3K5lphxGcy5QyVNG5p7MrYPbqbaiRnM+ mCDh9M3xkAjKR0mSgl97bAvDqWsWr65H6IjExxTbd/ZC4nlixOWdu7bC8iH3IVaO XMBefErDfgizeI09MXW8HlnkcQLxTSSV4XGbQTaycND9ZHhm7XItdStXJ5TKyEpX EuitHfReSaucXfZjoRX7tv0XzRRNqOkXD6IneJM5BCoVL4l6WiwRXioRGb2WCGkN BhOl15iPWZmfEThmHNMrQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=fm1; t=1685009799; x=1685096199; bh=h Cn80S16t5KWMrqhGJtFmBVIPiQ9NKvnaZBu9C4Y5xc=; b=ygaLTXeBUT6MZMicC 7rM0fte9LEZe6X/8daKcUvK1/RTt132TipqEhhdaUzWKXhnDBScr3rIixUCvkmkH 2Mgmq8NC9VloOvPo88+fCco4P0uoLUpAgBScWq+tpqSkg5FxHZbFSdFAxUR2BPmJ J0RCpPyzeBHokygzF2iWFYan+p5wm7pG3a6+Zoz/EySqsMEy4g9DlQdSNIU/lO2g jVL4jwSBG2ybzws89yb2rjQ1PtihB/411JkJoMRxqG24EpIWsBk1md+jNaFwa96x bVX7r7dnEl1B9adPu+w3l0bc+P60Uhn9ql0PqWAHhyGYslphrvG5mWvuhuxLIMtQ kse5w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:38 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/12] firewire: cdev: code refactoring to operate event of response Date: Thu, 25 May 2023 19:16:20 +0900 Message-Id: <20230525101625.888906-8-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766862565005587638?= X-GMAIL-MSGID: =?utf-8?q?1766862565005587638?= 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; }; 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 = data; - struct fw_cdev_event_response *rsp = &e->response; + struct fw_cdev_event_response *rsp = &e->rsp.without_tstamp; struct client *client = e->client; unsigned long flags; @@ -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; if (request->tcode != TCODE_STREAM_DATA && @@ -594,14 +598,14 @@ static int init_request(struct client *client, e = kmalloc(sizeof(*e) + request->length, GFP_KERNEL); if (e == NULL) return -ENOMEM; - e->client = client; - e->response.length = request->length; - e->response.closure = request->closure; - if (request->data && - copy_from_user(e->response.data, - u64_to_uptr(request->data), request->length)) { + rsp = &e->rsp.without_tstamp; + rsp->length = request->length; + rsp->closure = request->closure; + payload = rsp->data; + + if (request->data && copy_from_user(payload, u64_to_uptr(request->data), request->length)) { ret = -EFAULT; goto failed; } @@ -611,10 +615,9 @@ static int init_request(struct client *client, if (ret < 0) goto failed; - 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; failed: From patchwork Thu May 25 10:16:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp256853vqr; Thu, 25 May 2023 03:25:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7791ECEFMk93z2K8yYb2pxQd5uYTDbEmX/V9+T4QCmecSgq6+g1DAZZ+PLjyh8CyLHaUgo X-Received: by 2002:a05:6a20:1446:b0:102:a593:a17c with SMTP id a6-20020a056a20144600b00102a593a17cmr2949956pzi.0.1685010352447; Thu, 25 May 2023 03:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685010352; cv=none; d=google.com; s=arc-20160816; b=e+eOknFavyVIUGgQlbiTwyMOKPFzfMB61TfZ3q1jGTSr5HExO3lcUKr1joEec+EMJz Dr/aoNDt97Puq7dVRcxA0MBHoQ9L1j3rUvCH5SydTcXzga9VwWwipypzHTqrTTHy9WaY R2is3n+ts/nVuuy5rooeAU8U/DQLKuJFYHrtbpqFeLbaYgjaeIwq6aaLZm1cT6+tf4Wa z/sPq2cvpvORUmTErPXpN6sya3f57W/pDjRpT78K/jT5O6EDrRXe9P1CDqGrxv3e7k1D 1V8rT+3Rkef95gGJJCWpbyEp5/r5sJo4TP0MCPF+TAq0n88F480uPCMFM0QCNwMMVtOZ WANA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=cS/28RDTzVsKafSd+dry2URWS1xJwH24SgaemkBRLZQ=; b=OV3XAImqlHcce5nYNyygfNNMFkM7gmbEWkFi4/rNzF7/ww3g9kU1pE6iVKO0qwNPiQ CuxBdNWVxPzNHsiKUj6itrP8mKAMem6PuyR4TreS0g2NnyGt9dVOzx0DptEjqTZWrsBm GJY3x7CdJxAJoUr9vuiDr1r0zqPn35tnJenNsOs3PTXAVuLEMGSgZjIXp5bX28fVDRx/ YHR5r1mq20vKGduIys5e6r++D8+QdgeS4Yuf3Rn53ZXl02IYNklSyhd/PBpFddO1t31V 2F/aTjc2/UHAOi4adG93lFPOay1O0nTRP2rRWRdz1i+4BHwGCtNTaSu2/OVoP2a0G3Iy dJEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="WY/VGEky"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=WRRPIa3O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s124-20020a632c82000000b00519e8003677si774429pgs.664.2023.05.25.03.25.36; Thu, 25 May 2023 03:25:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="WY/VGEky"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=WRRPIa3O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240984AbjEYKSC (ORCPT + 99 others); Thu, 25 May 2023 06:18:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240842AbjEYKRQ (ORCPT ); Thu, 25 May 2023 06:17:16 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CAB01BF for ; Thu, 25 May 2023 03:16:41 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DD4055C028E; Thu, 25 May 2023 06:16:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 25 May 2023 06:16:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009800; x= 1685096200; bh=cS/28RDTzVsKafSd+dry2URWS1xJwH24SgaemkBRLZQ=; b=W Y/VGEky1g2eY/d87Y3hj0P5BfYx978NPFTlXWJ+FVQxgiaZTV9yO47scI647nNpK lZKBV8tOZdqqVYtsP38CKZftUQuPVCDzyhKqEFzcLRY53aYk0hl0OH3+DIQv8PKE 4s5/EcvIempHZFn+RPDjRP8u5Aj5QBvdlJdZ3ZJXVOcSHeX9sn2+kxQrsZvWqamW 7K3rTczfZYIycXJYfZiIuqEvXU4vhLq7B+wUsSzOFG8+SgHQy3/V6NOJCESfYLGN zTizGBNIxGEAdMC4EU6Wy8GQzDyFcF+3XcPV6loSOSyc+G+HsZFw9T1/NE8rp7kd osCPQpxvSrZnNrOrirkaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type: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=fm1; t=1685009800; x= 1685096200; bh=cS/28RDTzVsKafSd+dry2URWS1xJwH24SgaemkBRLZQ=; b=W RRPIa3OUnXn1/jj8y2JlGZ5X2RRZvY0yB8vElewa321tTsGy1ADLcINxbILsq8RH TS2s24e9/QeXCktAQ/KJad1hdnY0k36ECN0CbFTKdNM1fAwJT/snwdXttdAONyzn IyiNp2o6ZmHyeD5AcqfcUOjRFX6OhyVeGiTfm0MaBDdgE0/nvw9UexyOZtNFEBqq SVeDB+Wp32qWzvSOzVHGLiHBNQ5oNoYslyd79Nh0xUbh29nz36mMYGOmC+6D60Ha FtWSawXWwGg+LTw9YVU2iOxTDYdlovUHCnXGSnRmxoTeXWqCHRXX7i/IkC3sQNcK iNCs6g+5WqS97OoLtrkeQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:39 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: kunit-dev@googlegroups.com Subject: [PATCH v2 08/12] firewire: cdev: add new event to notify response subaction with time stamp Date: Thu, 25 May 2023 19:16:21 +0900 Message-Id: <20230525101625.888906-9-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766861415367649774?= X-GMAIL-MSGID: =?utf-8?q?1766861415367649774?= 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. Cc: kunit-dev@googlegroups.com Signed-off-by: Takashi Sakamoto --- drivers/firewire/uapi-test.c | 15 ++++++++ include/uapi/linux/firewire-cdev.h | 59 +++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/drivers/firewire/uapi-test.c b/drivers/firewire/uapi-test.c index c7c713babaa0..c342ba474ee6 100644 --- a/drivers/firewire/uapi-test.c +++ b/drivers/firewire/uapi-test.c @@ -45,9 +45,24 @@ static void structure_layout_event_request3(struct kunit *test) KUNIT_EXPECT_EQ(test, 56, offsetof(struct fw_cdev_event_request3, data)); } +// Added at v6.4. +static void structure_layout_event_response2(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, 32, sizeof(struct fw_cdev_event_response2)); + + KUNIT_EXPECT_EQ(test, 0, offsetof(struct fw_cdev_event_response2, closure)); + KUNIT_EXPECT_EQ(test, 8, offsetof(struct fw_cdev_event_response2, type)); + KUNIT_EXPECT_EQ(test, 12, offsetof(struct fw_cdev_event_response2, rcode)); + KUNIT_EXPECT_EQ(test, 16, offsetof(struct fw_cdev_event_response2, length)); + KUNIT_EXPECT_EQ(test, 20, offsetof(struct fw_cdev_event_response2, request_tstamp)); + KUNIT_EXPECT_EQ(test, 24, offsetof(struct fw_cdev_event_response2, response_tstamp)); + KUNIT_EXPECT_EQ(test, 32, offsetof(struct fw_cdev_event_response2, data)); +} + static struct kunit_case structure_layout_test_cases[] = { KUNIT_CASE(structure_layout_event_response), KUNIT_CASE(structure_layout_event_request3), + KUNIT_CASE(structure_layout_event_response2), {} }; diff --git a/include/uapi/linux/firewire-cdev.h b/include/uapi/linux/firewire-cdev.h index cc9b03244a62..ae8ccf7d7d2a 100644 --- a/include/uapi/linux/firewire-cdev.h +++ b/include/uapi/linux/firewire-cdev.h @@ -48,6 +48,7 @@ /* available since kernel version 6.3 */ #define FW_CDEV_EVENT_REQUEST3 0x0a +#define FW_CDEV_EVENT_RESPONSE2 0x0b /** * 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 <= 5. It has the lack of time stamp field comparing to &fw_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 received + * @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 request was sent. + * @request_tstamp: The time stamp of isochronous cycle at which the response was sent. + * @data: Payload data, if any + * * This event is sent when the stack receives a response to an outgoing request * 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 the request was sent to + * initiate the transaction. The value of @response_tstamp expresses the isochronous cycle at which + * the response arrived to complete the transaction. Each value is unsigned 16 bit integer + * containing three low order bits of second field and all 13 bits of cycle 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 architectures since + * 4 byte alignment is used for 8 byte of object type in System V ABI for i386 architecture. + */ + __u32 padding; __u32 data[]; }; @@ -421,6 +458,7 @@ struct fw_cdev_event_phy_packet { * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED * * @request3: Valid if @common.type == %FW_CDEV_EVENT_REQUEST3 + * @response2: Valid if @common.type == %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 further @@ -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 */ }; /* available since kernel version 2.6.22 */ @@ -507,6 +546,7 @@ union fw_cdev_event { * - added %FW_CDEV_IOC_FLUSH_ISO * 6 (6.4) - added some event for subactions of asynchronous transaction with time stamp * - %FW_CDEV_EVENT_REQUEST3 + * - %FW_CDEV_EVENT_RESPONSE2 */ /** @@ -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 requests. - * 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 requests. 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 to 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 failure 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 failure of the transmission. */ struct fw_cdev_send_stream_packet { __u32 length; From patchwork Thu May 25 10:16:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98943 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp258426vqr; Thu, 25 May 2023 03:29:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64jcKwfnQSOOmGWyG3oJvIffPCLisC1UzR96L6i74Ot5r8u+dMGVmjJhGGBhQDKCTN9qZi X-Received: by 2002:a17:902:eb4c:b0:1ac:3605:97ec with SMTP id i12-20020a170902eb4c00b001ac360597ecmr1102252pli.62.1685010598471; Thu, 25 May 2023 03:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685010598; cv=none; d=google.com; s=arc-20160816; b=CC29q1lQYi/nV81jO4rW/8Fu1kd3l8BU7mFVqgz36INwAFgfWUzuGsaZjHr9ExeOTm is4AUhcczTcAgIiT332YScjl4HOnNPvCixf9XxYhhc0tloAclUg/OG3Rk4nH/VHf4u3C MmKyI3L/zuNjSuyfiLFN7MPV7DRuMjj1zV4oZaA+mDLGaqKrmppv7f44blrrjfEQfUeH TBx2vgA9LBEv/EKXenxfsu8T6kIS/MIzsE+t9HkvIsnVQ9sijExVEGEBzJzlQmDyb3F4 IE5QM1md4lm2o559yoL1oPrZVIQ68710SjnQlAZV1YImkvp451ExMkpQIP7T6tKocNJq Scmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from:feedback-id :dkim-signature:dkim-signature; bh=19oDU4fEk+sheHYZWOnoN5cHboklhnnlKJrCnG0DjSI=; b=xlnMgJ5PNJbd6hOS5hVttxBx9688IO+mxZ0TGRKR9C095ssa4LjHpfqen/2voHaudr JcHvXPyF5IslZ9BKazSuYZVHVIABc2HetKnu/g18iZrYh8WEXIXhsZB9j/NjF5fNNCdO p4CIVxQl+9tgmm4GPMUrCo2MX6+W1lEOSfbmC1fbZkv0q5ZT/q5OEsfMhEbDZEBb6EHD sr05dEvLwyhvTgVOXLmyak2woBAGmF9yCuoL2GS2GMvsJZoBRcXMhoXunlkqUFUSAhNN AaoIfa9E9LtDCC1Qu/vdtPJ2u5s3k38A/v9Hbl/pB8/yNydRGtUmuB57duo9HOOlS7By bXFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=rBcmxBjG; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Oba7zdEb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id je20-20020a170903265400b001ab256f90b2si1114320plb.460.2023.05.25.03.29.42; Thu, 25 May 2023 03:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=rBcmxBjG; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Oba7zdEb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241012AbjEYKSP (ORCPT + 99 others); Thu, 25 May 2023 06:18:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240923AbjEYKRV (ORCPT ); Thu, 25 May 2023 06:17:21 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D85A8E45 for ; Thu, 25 May 2023 03:16:42 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 323365C0360; Thu, 25 May 2023 06:16:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 25 May 2023 06:16:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009802; x= 1685096202; bh=19oDU4fEk+sheHYZWOnoN5cHboklhnnlKJrCnG0DjSI=; b=r BcmxBjGPa1eBGC55TNvobO2r/EacjmyELkVNJjhNSrrsdqhMUQjGjHbEbHtzkpag BKKj2nUCyldCEcOO15mV8bgnbrr3n6vXwqua9BkYOUcp3sKp/TzoM3Mmr5uhVcZV JZnn5sog2scuNy+fyoopUzm4MWV6NN7cvpO1K/eY9u2ypczIsfNE3yIm99BqF/1A FakuQc+Qo3IOxaXWmk9nCS6aQ9GPfIP9lV2tzgK/Cntu4iYtcDclrNq/Op9pqJtl zVe6Zr9HIK0YdoDkVZrCbkPjG5MF1NVIipQtE9nCofZCyx1e1eE81wbl0QZMskkL 5lJymfrr2Hs7QBU0keIJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=fm1; t=1685009802; x=1685096202; bh=1 9oDU4fEk+sheHYZWOnoN5cHboklhnnlKJrCnG0DjSI=; b=Oba7zdEb4kSo36YfS uIefAHiT5zoGkmJxoesxCekOJJ/x29uz9n3kRQM2nikLOnmOug3omkdHy/v+MDgp FaNNcugGG3/dx25TxkDIndNZ7r28xSGButJYDGo9KXMziNcGPm0QqiLAdR01ENsu /w3RiMSbbZIdAJrqochccTMCq5fDgCVVH2EnbQdCecNF1qzhLHYQFgFSyC87cMRR HwWWiKGM7N9p8jAfWvOxNTnuWUcAL2MjF80/kWJq60wRaK9prlsI33vGOHz5f7ML w+Ne/YCS5ByLy57CdPiidttssGTjJNTMOJH08At4xN150jPIFG8n9BoHlFZChmNa +pH1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:41 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/12] firewire: cdev: implement new event to notify response subaction with time stamp Date: Thu, 25 May 2023 19:16:22 +0900 Message-Id: <20230525101625.888906-10-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766861673367361468?= X-GMAIL-MSGID: =?utf-8?q?1766861673367361468?= 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; }; @@ -538,41 +539,64 @@ static void release_transaction(struct client *client, { } -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 request_tstamp, + u32 response_tstamp, void *payload, size_t length, void *data) { struct outbound_transaction_event *e = data; - struct fw_cdev_event_response *rsp = &e->rsp.without_tstamp; struct client *client = e->client; unsigned long flags; - if (length < rsp->length) - rsp->length = length; - if (rcode == 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); - rsp->type = FW_CDEV_EVENT_RESPONSE; - rsp->rcode = rcode; + switch (e->rsp.without_tstamp.type) { + case FW_CDEV_EVENT_RESPONSE: + { + struct fw_cdev_event_response *rsp = &e->rsp.without_tstamp; + + if (length < rsp->length) + rsp->length = length; + if (rcode == RCODE_COMPLETE) + memcpy(rsp->data, payload, rsp->length); + + rsp->rcode = 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 <= 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); - /* - * 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 <= 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 = &e->rsp.with_tstamp; + + if (length < rsp->length) + rsp->length = length; + if (rcode == RCODE_COMPLETE) + memcpy(rsp->data, payload, rsp->length); + + rsp->rcode = rcode; + rsp->request_tstamp = request_tstamp; + rsp->response_tstamp = response_tstamp; + + queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, NULL, 0); + + break; + default: + WARN_ON(1); + break; + } + } /* 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; @@ -600,10 +623,21 @@ static int init_request(struct client *client, return -ENOMEM; e->client = client; - rsp = &e->rsp.without_tstamp; - rsp->length = request->length; - rsp->closure = request->closure; - payload = rsp->data; + if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { + struct fw_cdev_event_response *rsp = &e->rsp.without_tstamp; + + rsp->type = FW_CDEV_EVENT_RESPONSE; + rsp->length = request->length; + rsp->closure = request->closure; + payload = rsp->data; + } else { + struct fw_cdev_event_response2 *rsp = &e->rsp.with_tstamp; + + rsp->type = FW_CDEV_EVENT_RESPONSE2; + rsp->length = request->length; + rsp->closure = request->closure; + payload = rsp->data; + } if (request->data && copy_from_user(payload, u64_to_uptr(request->data), request->length)) { ret = -EFAULT; @@ -615,9 +649,9 @@ static int init_request(struct client *client, if (ret < 0) goto failed; - 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, request->tcode, + destination_id, request->generation, speed, request->offset, + payload, request->length, complete_transaction, e); return 0; failed: From patchwork Thu May 25 10:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp262925vqr; Thu, 25 May 2023 03:39:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4czTJvaZ34DTjkKAOsiE4uJyZgOuyC2B2MU0w54zHTE7fS52J+S0uyzq4XeX8KNqXC7v2y X-Received: by 2002:a17:902:f544:b0:1ae:e84:268d with SMTP id h4-20020a170902f54400b001ae0e84268dmr1526802plf.25.1685011178196; Thu, 25 May 2023 03:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685011178; cv=none; d=google.com; s=arc-20160816; b=AOlowJtJO+BgR7D00DQDJ8smpXFOHupTt2KMbGgxI6H0Zk+gCD7MLlm0Fj12TZcpZ1 nsIUfbABP2X8hczlvtZXKVg1g/utrvD/U+Zx7dssesjIPgN1PfTNigPTVizeKqJ/w5FE 7jCGASQu52T1ui1AhqHI2y9Rh5/RZLKDLDJ3P4xptSBI4uUjBPlHvCCHz+MD/xxM6ILa WD65ld7g4zHgcrw94loiW8vwDutFjyoh65STn8h6EENODjj3vVrP93AfI1178PHI7ylP vKnJLDpatAZDC/wK1jmWUeT34GQtynWygYt12lh/R+bciyGKAD9OTzj4+Mj9rCE/hU8n O4tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from:feedback-id :dkim-signature:dkim-signature; bh=fzYN89ZMFMfUx+g08kllNmIdNawZyAy6SkyrK59Skkc=; b=Iuql9HV8c5LpSQeSsa9QXaItFJ0jmkJjkEK5qYr6gNQk8AX5vXE7eQs0xz2GsDig1Q KKvqkG1rOFWlJHgge2SPYxQR5wA9Fmb5aO+4tgwlxFOz9Ueacry1YKWT8NzRiEEmLniG k4DdLZZdgPTqXOMpSOByKc1+wY40UtCngqQweDmZdW3ph3RhdPDRCh325ABrRrhDaUtC +4njsNf9lX51xaoYsJm5fY9egw10EHFfpM0zhoshTMqZFGLcaArt89sVTIiA2JF6pLon MCVSiW3sgssm0xaw9EEqQ4TW6ZQ4IGIW2v5unlJN0Rl/WsH5aTET69LizeF7uBZC5ryn hztQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=F0VuqqdX; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=EazNkTfe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e10-20020a17090301ca00b001aac7641a19si1319348plh.257.2023.05.25.03.39.23; Thu, 25 May 2023 03:39:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=F0VuqqdX; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=EazNkTfe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240950AbjEYKSV (ORCPT + 99 others); Thu, 25 May 2023 06:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240882AbjEYKRZ (ORCPT ); Thu, 25 May 2023 06:17:25 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 000C8E46 for ; Thu, 25 May 2023 03:16:43 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 709885C0185; Thu, 25 May 2023 06:16:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 25 May 2023 06:16:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009803; x= 1685096203; bh=fzYN89ZMFMfUx+g08kllNmIdNawZyAy6SkyrK59Skkc=; b=F 0VuqqdXAeFD4ribq3a6zoFeRVwEo3s2BwQFhQ5Ed1FFNHntqvVgbEXJwIW2RfcnQ oTCygI1KZUTfueidnzaoHwMgWmHYt8j/VFrgC3gLuMq4WILf+Z9fWzHX2XuKsE86 tRjS73fhtVt9oil9SHTaVRmN/1DsFUKXUCo5xKw4sAPAR+uAG9SSYpE5/HdYCMWF pvdKNXPPp96tR4hDoFlHX8eeX37vsoNGQFQt5BExpzTGYP0EEs7Tz3/2/yu+gzXS h6sjd5c8QbC7kJvWWet0Pj7BN1R2Cfy8NIZvT47hIOnaxS4uAkg873Ad2hsB5yK4 hT8SytrSFr5qJPtAWBdBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=fm1; t=1685009803; x=1685096203; bh=f zYN89ZMFMfUx+g08kllNmIdNawZyAy6SkyrK59Skkc=; b=EazNkTfe58wOJhsQA AAgUGJff6YdfIjNEzwaaEB+ESLjBKx9oBQ0dXA1Tc3xr1QSniFFi6ZE69PTjHD6x Y6j5WuCU+NO4pea3Atkn5JfjwPIk0mMarcfThFSLhcTV+DnsWkBveASBfTPeShvL SgNkWS0AbhIkjYS5RuO3n2fc98zcFMVD0BxRkoz3Dz88onvJUbUrJIFnfUxP6JEM r/b5tDXeOS63dqyqJsKkLQtwZQ8Zur9mTiIcEjHOp9KgyTAxPfvd2Y2wac/lj578 Wmz0MPZVYxYx7/vDOxAbPGk3Z8q7SDVEObPqiACBs+7+MDLCWzxrRWev3WGD2ni/ RiddQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:42 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/12] firewire: cdev: code refactoring to dispatch event for phy packet Date: Thu, 25 May 2023 19:16:23 +0900 Message-Id: <20230525101625.888906-11-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766862281457282281?= X-GMAIL-MSGID: =?utf-8?q?1766862281457282281?= 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; }; 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; }; #ifdef CONFIG_COMPAT @@ -1549,26 +1553,41 @@ static void outbound_phy_packet_callback(struct fw_packet *packet, { struct outbound_phy_packet_event *e = container_of(packet, struct outbound_phy_packet_event, p); - struct client *e_client; + struct client *e_client = e->client; + u32 rcode; + struct fw_cdev_event_phy_packet *pp; switch (status) { - /* expected: */ - case ACK_COMPLETE: e->phy_packet.rcode = RCODE_COMPLETE; break; - /* should never happen with PHY packets: */ - case ACK_PENDING: e->phy_packet.rcode = RCODE_COMPLETE; break; + // expected: + case ACK_COMPLETE: + rcode = RCODE_COMPLETE; + break; + // should never happen with PHY packets: + case ACK_PENDING: + rcode = RCODE_COMPLETE; + break; case ACK_BUSY_X: case ACK_BUSY_A: - case ACK_BUSY_B: e->phy_packet.rcode = RCODE_BUSY; break; - case ACK_DATA_ERROR: e->phy_packet.rcode = RCODE_DATA_ERROR; break; - case ACK_TYPE_ERROR: e->phy_packet.rcode = RCODE_TYPE_ERROR; break; - /* stale generation; cancelled; on certain controllers: no ack */ - default: e->phy_packet.rcode = status; break; + case ACK_BUSY_B: + rcode = RCODE_BUSY; + break; + case ACK_DATA_ERROR: + rcode = RCODE_DATA_ERROR; + break; + case ACK_TYPE_ERROR: + rcode = RCODE_TYPE_ERROR; + break; + // stale generation; cancelled; on certain controllers: no ack + default: + rcode = status; + break; } - e->phy_packet.data[0] = packet->timestamp; - e_client = e->client; - queue_event(e->client, &e->event, &e->phy_packet, - sizeof(e->phy_packet) + e->phy_packet.length, NULL, 0); + pp = &e->phy_packet.without_tstamp; + pp->rcode = rcode; + pp->data[0] = packet->timestamp; + queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->length, NULL, 0); + client_put(e_client); } @@ -1577,6 +1596,7 @@ static int ioctl_send_phy_packet(struct client *client, union ioctl_arg *arg) struct fw_cdev_send_phy_packet *a = &arg->send_phy_packet; struct fw_card *card = client->device->card; struct outbound_phy_packet_event *e; + struct fw_cdev_event_phy_packet *pp; /* 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 *client, union ioctl_arg *arg) e->p.header[2] = a->data[1]; e->p.header_length = 12; e->p.callback = outbound_phy_packet_callback; - e->phy_packet.closure = a->closure; - e->phy_packet.type = FW_CDEV_EVENT_PHY_PACKET_SENT; + + pp = &e->phy_packet.without_tstamp; + pp->closure = a->closure; + pp->type = FW_CDEV_EVENT_PHY_PACKET_SENT; if (is_ping_packet(a->data)) - e->phy_packet.length = 4; + pp->length = 4; card->driver->send_request(card, &e->p); @@ -1633,18 +1655,20 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p) spin_lock_irqsave(&card->lock, flags); list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { + struct fw_cdev_event_phy_packet *pp; + e = kmalloc(sizeof(*e) + 8, GFP_ATOMIC); if (e == NULL) break; - e->phy_packet.closure = client->phy_receiver_closure; - e->phy_packet.type = FW_CDEV_EVENT_PHY_PACKET_RECEIVED; - e->phy_packet.rcode = RCODE_COMPLETE; - e->phy_packet.length = 8; - e->phy_packet.data[0] = p->header[1]; - e->phy_packet.data[1] = p->header[2]; - queue_event(client, &e->event, - &e->phy_packet, sizeof(e->phy_packet) + 8, NULL, 0); + pp = &e->phy_packet.without_tstamp; + pp->closure = client->phy_receiver_closure; + pp->type = FW_CDEV_EVENT_PHY_PACKET_RECEIVED; + pp->rcode = RCODE_COMPLETE; + pp->length = 8; + pp->data[0] = p->header[1]; + pp->data[1] = p->header[2]; + queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0); } spin_unlock_irqrestore(&card->lock, flags); From patchwork Thu May 25 10:16:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98949 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp260361vqr; Thu, 25 May 2023 03:33:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5k2BlvB4yfK3XMr9mtpYrPEjCrt6ft32JBsh64cRL538FvVLGsBCikCUv1lLDzMSiAosjz X-Received: by 2002:a17:90a:4b43:b0:24e:5a5a:1050 with SMTP id o3-20020a17090a4b4300b0024e5a5a1050mr1089486pjl.24.1685010823318; Thu, 25 May 2023 03:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685010823; cv=none; d=google.com; s=arc-20160816; b=jhvFpESexj0j3LqCchgyibuTuSrxq/UzZAYfF6vvZnFlh89SlMF63rEwOh6F6yQKL6 iQGU2aVyYGZbwR8S2SWulXLF4LFNZCCFucdE1s1Py+goDilcdjl6wuSmjG6XmB5pPJES PHlN0yMEzcXudtKB9S7I1ShqJCWAYVQPPA7MUScjC73FTxVJ9gMpoot5kLHtNVJ8+2gb E18DX2s8AQILolH23uIdAAd3tzFAaMCjmvAI9NLMhmJrhlNrG5rt1huKH1g8J8mfp2tL WrLfj5+yyI8kjkGSfmiQWe76qq0VHkTWwvVlCBjvdvtbOExZ489TrMYG65R2a3oGE8Kd 7mKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=DKCYLbsQPb/xchwUl7JQfieNs7hWP6tRXhDTBLxytjU=; b=sLPkxfoyrybuZMA3zjNVswByAzXcgdlAoDK1V8CJ9FhFlOTNZdwSM7B2aXvJAQw2Pn OntR9PJhGJuuDHYoDz9qQmaE4LIw4QSbuAMvHePOS96d2u/X4JmIZb43VxdG+/B3bTse 3MmzDdokkOMrRj8FO2gybaIvXfPPx/5JIHHNN3Sa8PIEpGtWye6SIQ85Caz/IUL0/YNW LSPpCmGt6oK/soRnX1pWrlO04DrJFyd5dKWzL4iJu2jaFMMoZGiB04agN8untDiBxU3m bJXoTW7jcKvYakKf1sNV7On/QUfzHjhR9y+pQyvhYMOuiCXTFAyGg6LTRC2kspCJRjyi I5iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="Q7k+jH/f"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Z4BNLzrG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 7-20020a17090a018700b00247ad6e4188si1576090pjc.51.2023.05.25.03.33.28; Thu, 25 May 2023 03:33:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="Q7k+jH/f"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Z4BNLzrG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241045AbjEYKSY (ORCPT + 99 others); Thu, 25 May 2023 06:18:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240928AbjEYKRZ (ORCPT ); Thu, 25 May 2023 06:17:25 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59AF0E4A for ; Thu, 25 May 2023 03:16:45 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C5D385C0120; Thu, 25 May 2023 06:16:44 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 25 May 2023 06:16:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009804; x= 1685096204; bh=DKCYLbsQPb/xchwUl7JQfieNs7hWP6tRXhDTBLxytjU=; b=Q 7k+jH/f5wit+CZkzKHfERBOmCWq8slg2aDJZIzSYPVHiYaSkCTo3FminrQ+e4GK2 98bbTX4eo7DCt+CZHszE1M7FqOsRdzEoWmVlE8xnTJXjj++Ty2C646LU2RejbVn8 uJ4OY06FHCfBvk/7MmEkJouM1ba1VmdPM3dQ7hOna/kfHkLyrGiPjRHsdlomn2Kr x/rn6h3LmciCYuE6lEgMTKuiDguRIEMl8LUjyEU6lPjjvOfhHEWO+FyHkRAzSLv3 WBdNDbsBqsCqS08Z6iRvOuwnzEo4+1c+reJvYmb6m4C5irtdHXJY+KrWhyt3TNvi w9S238/OgQ4eoi5B38BQA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type: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=fm1; t=1685009804; x= 1685096204; bh=DKCYLbsQPb/xchwUl7JQfieNs7hWP6tRXhDTBLxytjU=; b=Z 4BNLzrGaxaNtEk7ybIvpjzZ3Robav7jU7OQG3tei5urogPQ5BT5rfX0d4k8hLCq1 d0952Zch0PQl2Hr6dnfLypt9e+iV0wcIeQqS5wwnoY84+/aPYfBjyqWncfgGIzM7 QGUzR/R3qvKrZmEqKN9N0YAdGLbweyJD7YupeGXF7+RnOCTGYaRl2dGFzwI5Zwld s2SHKfVWskqnd3rLkmzEVm6erfmue27f1pzm3wiQy+Yw5J8lkWadCkMMnS+HoamY rmpQO7s6laYzoQoPZM41/s/kdE076KiyEHiEhyt0JGAWkRZ4i9MTdxVoMZfNzIL2 8RVzEFdI81g0Z3Pdl/9Tg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:43 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: kunit-dev@googlegroups.com Subject: [PATCH v2 11/12] firewire: cdev: add new event to notify phy packet with time stamp Date: Thu, 25 May 2023 19:16:24 +0900 Message-Id: <20230525101625.888906-12-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766861909012602256?= X-GMAIL-MSGID: =?utf-8?q?1766861909012602256?= 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. Cc: kunit-dev@googlegroups.com Signed-off-by: Takashi Sakamoto --- drivers/firewire/uapi-test.c | 14 +++++++ include/uapi/linux/firewire-cdev.h | 67 +++++++++++++++++++++++++----- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/drivers/firewire/uapi-test.c b/drivers/firewire/uapi-test.c index c342ba474ee6..9732b5be3844 100644 --- a/drivers/firewire/uapi-test.c +++ b/drivers/firewire/uapi-test.c @@ -59,10 +59,24 @@ static void structure_layout_event_response2(struct kunit *test) KUNIT_EXPECT_EQ(test, 32, offsetof(struct fw_cdev_event_response2, data)); } +// Added at v6.4. +static void structure_layout_event_phy_packet2(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, 24, sizeof(struct fw_cdev_event_phy_packet2)); + + KUNIT_EXPECT_EQ(test, 0, offsetof(struct fw_cdev_event_phy_packet2, closure)); + KUNIT_EXPECT_EQ(test, 8, offsetof(struct fw_cdev_event_phy_packet2, type)); + KUNIT_EXPECT_EQ(test, 12, offsetof(struct fw_cdev_event_phy_packet2, rcode)); + KUNIT_EXPECT_EQ(test, 16, offsetof(struct fw_cdev_event_phy_packet2, length)); + KUNIT_EXPECT_EQ(test, 20, offsetof(struct fw_cdev_event_phy_packet2, tstamp)); + KUNIT_EXPECT_EQ(test, 24, offsetof(struct fw_cdev_event_phy_packet2, data)); +} + static struct kunit_case structure_layout_test_cases[] = { KUNIT_CASE(structure_layout_event_response), KUNIT_CASE(structure_layout_event_request3), KUNIT_CASE(structure_layout_event_response2), + KUNIT_CASE(structure_layout_event_phy_packet2), {} }; diff --git a/include/uapi/linux/firewire-cdev.h b/include/uapi/linux/firewire-cdev.h index ae8ccf7d7d2a..155e71598cb4 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 /** * 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 <= 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 received 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_RECEIVED2 + * @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 isochronous 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 sent 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 empty, - * except in case of a ping packet: Then, @length is 4, and @data[0] is the - * 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 consists 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 expresses three low order bits + * of second field and the rest 13 bits expresses cycle field in the format 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 isochronous 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 controller 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[]; }; @@ -459,6 +500,8 @@ struct fw_cdev_event_phy_packet { * * @request3: Valid if @common.type == %FW_CDEV_EVENT_REQUEST3 * @response2: Valid if @common.type == %FW_CDEV_EVENT_RESPONSE2 + * @phy_packet2: Valid if @common.type == %FW_CDEV_EVENT_PHY_PACKET_SENT2 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 further @@ -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 */ }; /* available since kernel version 2.6.22 */ @@ -547,6 +591,8 @@ union fw_cdev_event { * 6 (6.4) - added some event for subactions of asynchronous transaction with time stamp * - %FW_CDEV_EVENT_REQUEST3 * - %FW_CDEV_EVENT_RESPONSE2 + * - %FW_CDEV_EVENT_PHY_PACKET_SENT2 + * - %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2 */ /** @@ -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 event 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_RECEIVED or + * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2 due to incoming PHY packets from any node on the same bus + * as the device. * * The ioctl is only permitted on device files which represent a local node. */ From patchwork Thu May 25 10:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 98947 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp259916vqr; Thu, 25 May 2023 03:32:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7cmJPjISVaguWwxBn/kP/Q4Q5/SpxXXdIp3yrMIvb9xb+f5qAQMLjC3X+0S24PJrJmubdp X-Received: by 2002:a17:903:18f:b0:1a9:bc13:7e20 with SMTP id z15-20020a170903018f00b001a9bc137e20mr1389793plg.44.1685010767571; Thu, 25 May 2023 03:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685010767; cv=none; d=google.com; s=arc-20160816; b=cGJ0EJGv+k/Fyf4YSMQAEEGaIwuzuQpz9HSs4bFSXxPKx7HldUa++QOxElkWpQ6dwU mnKmXTTsqqULuK8X+E9Net//Ff6vBzTbuKWDhiIS9hj5hj5OxQw7coHxKc2dXNBQGtbJ dgU2t8FUrXVW4EkBPGZroLlR7WbgltrshIMm8XDNJ9ibqXZXlim79obQkXODAKvdgJwd uiYuBwgrPTbUgLkenT2YILniM3clZtEHCxNzKQsVGY20IzBkGsbaTseuTqu4AwlOWcrx AJqSvVed4CiiMG2j66aBmtBOH45AAF+Zelr2BtXRrIAL1sjmwCQwDXquKOcdvP1dkHC7 XJKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from:feedback-id :dkim-signature:dkim-signature; bh=CwMQ3mRgLz5XKiLhS8Bwc8Qm3NwjUti4uZQkCUexV3s=; b=NaFFc/ZK+aKXrVqfrKrZy7R58FXzFwor60gErJW5FqkPti2p7s3Edou4E7bjCgI14x CvwcC55NFS6/gzdzfSMlg5o4UqsFsZns1hBsIFfSeqn/fnJrzgtUswSriGkmwjU8PKm4 j3JNF6/FYqy9VoD9Zdi8MPPKtbkCofEp2EFnfbaAGY9w/Y7WiFYyyElD77zA+8Wk55aD O0LfHLbtDjRmrc1/HQ2GXt6IOoyzhu/v2rG0KTr5WBLyXaYVdlJYxN2vOnrrWwqa3WHW 7FLBGWN4g0eb7dBDkokK1YGtKFU7JvarpgtOjV37sViIwZd28KFI5ffWN82WPOTk2T3n cO8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=X6ADm6Vm; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=DY+SVeD8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jb12-20020a170903258c00b001a95b85b070si1080479plb.604.2023.05.25.03.32.33; Thu, 25 May 2023 03:32:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=X6ADm6Vm; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=DY+SVeD8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241000AbjEYKS2 (ORCPT + 99 others); Thu, 25 May 2023 06:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240760AbjEYKRp (ORCPT ); Thu, 25 May 2023 06:17:45 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95363E51 for ; Thu, 25 May 2023 03:16:46 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 11DCA5C0073; Thu, 25 May 2023 06:16:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 25 May 2023 06:16:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1685009806; x= 1685096206; bh=CwMQ3mRgLz5XKiLhS8Bwc8Qm3NwjUti4uZQkCUexV3s=; b=X 6ADm6VmVdvfMbXrcDmvKQF75wkZM1Y9gmHEjaOdUk0zeZ7sXuBp4j+V7/qjWut30 ULMvUTP/Yx3X5oh2AZn98pzXFuAzqq2WzHMjZI5629/Z/XCq6+6igd1piOgHsImS LKAfrTkk9c3yiWoKGKMHwRF0XlsB49wOnlXZ+cg2cig5zyqbYxbPHh9E9w7U8p6V C8Ckk+WJue2suAlhCNn48uG2PRRajJGu8imzvuw79irtIgaJpNJmEmuCCQVZArvP 1sr8eYZhOo6yrMF9cxrlzBKvqWlsudQ793uzKlZ6Y4w4fek4D72iYySDQIljLsWU o1Wkj6O1qtU8KuLVcLr8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :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=fm1; t=1685009806; x=1685096206; bh=C wMQ3mRgLz5XKiLhS8Bwc8Qm3NwjUti4uZQkCUexV3s=; b=DY+SVeD85NeZ9wveQ L5SDs4ppqzV8x53QxsZi23SPlWTe084qAu/tQQR8oGjkDPjbODW8F+NHxACAW0zB z0Ns7A5m1wewrclY7Do388+MQzbFCmhwp/uau9uX5UpgD2EFbNzJ3dAhOLrnkeNW 15j48ZbOwImtewdA1hhFe2N8WRf99w4nViz+kWfaghIuRE0kxKcVMzoQVqShd8zs zGYIs9u/pNPd+e9V+m5kbZSU8YHxWOXMoOR67u1J1eh7kWK6H1D6gVVB6QS5jaT7 CHz74ZsgcYU1/zPLdqFLchuRyuBoyuUxbBfV9E+tunSG4leWiMr6Bxq0ES1v9vtl Ks+yw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 06:16:44 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 12/12] firewire: cdev: implement new event relevant to phy packet with time stamp Date: Thu, 25 May 2023 19:16:25 +0900 Message-Id: <20230525101625.888906-13-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525101625.888906-1-o-takashi@sakamocchi.jp> References: <20230525101625.888906-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766861850487369750?= X-GMAIL-MSGID: =?utf-8?q?1766861850487369750?= 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; }; @@ -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; }; @@ -1555,7 +1557,6 @@ static void outbound_phy_packet_callback(struct fw_packet *packet, container_of(packet, struct outbound_phy_packet_event, p); struct client *e_client = e->client; u32 rcode; - struct fw_cdev_event_phy_packet *pp; switch (status) { // expected: @@ -1583,10 +1584,31 @@ static void outbound_phy_packet_callback(struct fw_packet *packet, break; } - pp = &e->phy_packet.without_tstamp; - pp->rcode = rcode; - pp->data[0] = packet->timestamp; - queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->length, NULL, 0); + switch (e->phy_packet.without_tstamp.type) { + case FW_CDEV_EVENT_PHY_PACKET_SENT: + { + struct fw_cdev_event_phy_packet *pp = &e->phy_packet.without_tstamp; + + pp->rcode = rcode; + pp->data[0] = packet->timestamp; + queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->length, + NULL, 0); + break; + } + case FW_CDEV_EVENT_PHY_PACKET_SENT2: + { + struct fw_cdev_event_phy_packet2 *pp = &e->phy_packet.with_tstamp; + + pp->rcode = rcode; + pp->tstamp = packet->timestamp; + queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->length, + NULL, 0); + break; + } + default: + WARN_ON(1); + break; + } client_put(e_client); } @@ -1596,13 +1618,12 @@ static int ioctl_send_phy_packet(struct client *client, union ioctl_arg *arg) struct fw_cdev_send_phy_packet *a = &arg->send_phy_packet; struct fw_card *card = client->device->card; struct outbound_phy_packet_event *e; - struct fw_cdev_event_phy_packet *pp; /* Access policy: Allow this ioctl only on local nodes' device files. */ if (!client->device->is_local) return -ENOSYS; - e = kzalloc(sizeof(*e) + 4, GFP_KERNEL); + e = kzalloc(sizeof(*e) + sizeof(a->data), GFP_KERNEL); if (e == NULL) return -ENOMEM; @@ -1616,11 +1637,23 @@ static int ioctl_send_phy_packet(struct client *client, union ioctl_arg *arg) e->p.header_length = 12; e->p.callback = outbound_phy_packet_callback; - pp = &e->phy_packet.without_tstamp; - pp->closure = a->closure; - pp->type = FW_CDEV_EVENT_PHY_PACKET_SENT; - if (is_ping_packet(a->data)) - pp->length = 4; + if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { + struct fw_cdev_event_phy_packet *pp = &e->phy_packet.without_tstamp; + + pp->closure = a->closure; + pp->type = FW_CDEV_EVENT_PHY_PACKET_SENT; + if (is_ping_packet(a->data)) + pp->length = 4; + } else { + struct fw_cdev_event_phy_packet2 *pp = &e->phy_packet.with_tstamp; + + pp->closure = a->closure; + pp->type = FW_CDEV_EVENT_PHY_PACKET_SENT2; + // Keep the data field so that application can match the response event to the + // request. + pp->length = sizeof(a->data); + memcpy(pp->data, a->data, sizeof(a->data)); + } card->driver->send_request(card, &e->p); @@ -1655,20 +1688,33 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p) spin_lock_irqsave(&card->lock, flags); list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { - struct fw_cdev_event_phy_packet *pp; - e = kmalloc(sizeof(*e) + 8, GFP_ATOMIC); if (e == NULL) break; - pp = &e->phy_packet.without_tstamp; - pp->closure = client->phy_receiver_closure; - pp->type = FW_CDEV_EVENT_PHY_PACKET_RECEIVED; - pp->rcode = RCODE_COMPLETE; - pp->length = 8; - pp->data[0] = p->header[1]; - pp->data[1] = 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 = &e->phy_packet.without_tstamp; + + pp->closure = client->phy_receiver_closure; + pp->type = FW_CDEV_EVENT_PHY_PACKET_RECEIVED; + pp->rcode = RCODE_COMPLETE; + pp->length = 8; + pp->data[0] = p->header[1]; + pp->data[1] = p->header[2]; + queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0); + } else { + struct fw_cdev_event_phy_packet2 *pp = &e->phy_packet.with_tstamp; + + pp = &e->phy_packet.with_tstamp; + pp->closure = client->phy_receiver_closure; + pp->type = FW_CDEV_EVENT_PHY_PACKET_RECEIVED2; + pp->rcode = RCODE_COMPLETE; + pp->length = 8; + pp->tstamp = p->timestamp; + pp->data[0] = p->header[1]; + pp->data[1] = p->header[2]; + queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0); + } } spin_unlock_irqrestore(&card->lock, flags);