From patchwork Mon May 29 11:33:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1443235vqr; Mon, 29 May 2023 04:37:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4uLJrluV/wU7k1xBdFKmaOEtlP9QujMAUfwVShM4e+o3ZfWRUI7vDZxT+aJh1CrQpPwSAC X-Received: by 2002:a17:902:bc8a:b0:1ac:d03a:9702 with SMTP id bb10-20020a170902bc8a00b001acd03a9702mr9473883plb.67.1685360230368; Mon, 29 May 2023 04:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685360230; cv=none; d=google.com; s=arc-20160816; b=Adle7AyHwF7EvJTfbRdOPwFPkmQB14R4mDOOSK5hTRgL2f+Tn35LFaBX7l81O35/Rj yg2OaZF61VkW1kR/NsPCNite0TvUpR/mLzqvFcE8+hvXHFI40x1lkCMLMJtXvrtuUw+4 pSF3OKSw7JEMhDMpTT2mvWZOKDEksrvvkqikusRvpD6XfX519GAU0VjTE7PUmB242qj/ 63uiRGRkjjFyqJ3L21JTluDYWR6r+MDDnpCgmiy/r2DoM//mQqiyrSh5/KK1+k7nLmS9 oVZHDYtG7af6wIc/AWttfstn+hyHqpx2NB2tXBuebVdDO/z+n+G0nTU9Pb00XxKw7fFg 9uEA== 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=XeLnfsJTYRFC+mqbvqrSh1wTAjnlzKtXrc+Y+tTPQDdodvK5rgK1qLuanO22VJ9Puh O814QjDk2fSbNuN8V0zzuihfTYtc5G8E8ZwWokGznui6tSgKEX9w97uLOfAaO8yJbQU2 3Gp/UkOweAsIFhDFN2Uo2lcP5/boy/IrzHA7KUJ/02zvwo5TLuD7aF2o5OjlN7sOjo/l SHFVMVOV/x93LV1kkjmObU3E1QEUb9lIGkyD2rlx9jSnzQNafQYzHy7Is7iGyF7qVwum QhvSHXggaDGlwBtI/aisWQaBXqjCBncHbISGUjSHamEjkW15LPXXDOgVza94bbZej+H0 AQtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=vFnlkzXv; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=AYcer1p4; 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 q8-20020a17090311c800b0019e9c8e51f4si2393954plh.165.2023.05.29.04.36.56; Mon, 29 May 2023 04:37:10 -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=vFnlkzXv; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=AYcer1p4; 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 S231533AbjE2LeS (ORCPT + 99 others); Mon, 29 May 2023 07:34:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231509AbjE2LeR (ORCPT ); Mon, 29 May 2023 07:34:17 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8615BE for ; Mon, 29 May 2023 04:34:15 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id C752F320091F; Mon, 29 May 2023 07:34:14 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 29 May 2023 07:34:15 -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=1685360054; x= 1685446454; bh=JW0p8/eDaYU/cW3GeziZHaBybYl27FrC9hzeWZqxqbk=; b=v FnlkzXvIaoeUJG2V7A6I+SlEcQjMThQZZv35UNB4qNEfjcE6kKzEzA5WSyEiompo m1N3baGcPJBpbQVSr4wfFbSSO8aUPJq8MuW2Zskr4s8qKNSyNBYcqQeT0NZ/fteH wDteuuAmrjCU5vpVbTLIMTnMF0VqKpJpgKGJGtlDhYvlUHeoWL4hGnghbaa2kPNx BiqZ5RADuv+pPdrCN2Lf5BPLcZusYZqDQsAcYHZQXi3SwFAxJvir6eKNLtiKp9na 3rV9Qa+SA10kTiYyTMfefurN7PYxN/5CK9K4zidYqaw7EPAOqRGRP1NE7nEEDB97 xfmrt2a7rjlHuO7CAvbZQ== 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=1685360054; x= 1685446454; bh=JW0p8/eDaYU/cW3GeziZHaBybYl27FrC9hzeWZqxqbk=; b=A Ycer1p4RYkzYrb9aRjz1THEgwEW8CYs4RzwzAAcnBR/nI05NRjBDOO6yYcaIpjle wIN3Ivh9q4/CGZS+Nr25+TN+ZX2cs5N+LlhN9dBHWVFFSDTte4Gtkauca0IO7Nsj gwi7HCsmGtX6AeVcbmmRumvOyO46TQYMqMU2Z2hWYjLpd6e6zHKFocrjvB1mebtU ewDmTE2ckKn1BHN7DLZQ0pVfatuMLJ5bROAwi/LYyvTzBXgVnh/8QLyPS7k0CIgD 2yQUONsydfsUfvQT6gAVxQcJJ6E0H8EtKz41YgmA0JHHHhBJwOMheankksxJBxWZ QKUy7vlNgwPLq02/kXzRg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeduuddttd euueduledvleethfetleeuledvvddvjeeiueekkeektdegudekffdvveenucffohhmrghi nhepvdejrdhithdpthgvshhtrghnhihthhhinhhgrdhorhhgnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihesshgrkhgr mhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:13 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: kunit-dev@googlegroups.com Subject: [PATCH v3 01/12] firewire: add KUnit test to check layout of UAPI structures Date: Mon, 29 May 2023 20:33:55 +0900 Message-Id: <20230529113406.986289-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767228288671847622?= X-GMAIL-MSGID: =?utf-8?q?1767228288671847622?= 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 Mon May 29 11:33:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1451542vqr; Mon, 29 May 2023 04:53:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Oh0vDve7Aam98jsV8gFmxZEIO70sxovJ9aRvvb0xoQx6FjQO+ym21fHFBRPR7/AgalIP8 X-Received: by 2002:a05:6a20:3d93:b0:110:6146:1020 with SMTP id s19-20020a056a203d9300b0011061461020mr8411793pzi.53.1685361207187; Mon, 29 May 2023 04:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685361207; cv=none; d=google.com; s=arc-20160816; b=jFgNgqMXFv8O1te865I1CDaKOwLnYA+4odpf5owLsGlKpQVDXeFMb60dB3k/l1X1Dd M11d04aXDRRLRNs+Tsc0eEcIpKlAEUZRLNNP4gyXw4DIV3gNtOLy9ukU6z2aCeTg+bRe vLJKEW/AGoklezLucWoNMXPoKwb1kZO8l+xOYws//QVSlDII9SPZ1yRx+dK/PMT5iW8v 3HLkIJlMCcPPLC6j/8RpQyXQH1Pry+6lB+j66AFdg6lr1aob8fFXo6hmUq5X05Af08F0 MhOLtI7wNKAim8TqpEgmvtwkq412WUzXjzGAi9uARtu5pXcV4VFxNXFFERB5uTN6jGAR Bhig== 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=hPICvvJyN01FeQX1myCxTwggQ3ABUCLi/5+DEUBxRZk=; b=Cu84q3rc980AcV6LjPUBMOr6/ROAo+oKZw8FT+FkSmyOxfcJR86xl8RFfVDISyDn8C WzZDrrX9aNf+0+nhfaZ1m7+R1XW79d6DH3eniq0+YYzLHBoC4c33C28J/rFXcjxPspEv Sz+udzpvjtajc0XvFbUygmqrSLU+qGMufMoZLsZ95n9YKoPt/j3e7drlegcPtzjSW2xF lW0tCsSZYdBvE6078iAafh6pkPMO59TNVqA2bfjtwQWTxW/zu8oU6AltqtAQuI4zABI3 etZLHm58pP/EB1QdFMHlEd0CMnymU4c4uYwoLF5hIGpK/mkNcS7qa1SaEHIIApYfm5LV zCnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=M7YJ7oLH; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=VCVUebQV; 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 bt19-20020a632913000000b00528cea36032si9618298pgb.10.2023.05.29.04.53.15; Mon, 29 May 2023 04:53:27 -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=M7YJ7oLH; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=VCVUebQV; 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 S231553AbjE2LeY (ORCPT + 99 others); Mon, 29 May 2023 07:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231529AbjE2LeS (ORCPT ); Mon, 29 May 2023 07:34:18 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64E8BD2 for ; Mon, 29 May 2023 04:34:17 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id D20013200392; Mon, 29 May 2023 07:34:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 29 May 2023 07:34:17 -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=1685360056; x= 1685446456; bh=hPICvvJyN01FeQX1myCxTwggQ3ABUCLi/5+DEUBxRZk=; b=M 7YJ7oLHvqaZh2l/KtuCvFNsjAflw42UxQe0JDywXvV79TmwQBfiPuR0VFJNp9KIi 8B44QjseZ5Lcd1GPPd1IX3UIz+dc3TPSVkS+nLbZkaVOXBoOOBwA4L7JU85eR2CO zo2D2jEYAYoNzblrbJBBTu0ZxewEfgxyhQBPDQgYKQ4Qs7mlfPeye43dhBksvips W08+nyn6Hlmbsg035ss2DnfS7KFyKz3ScNM9CkGTvPmFsfRxf6NfvMaYE4xU8sVO M+s1YrLccC6E2YI4htfyBR7twa6DY9qEAT++9pRoY/La29V1BPHk9fBQ5KPA8c+9 6gqg9xJhN89e9+ms4Tq0g== 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=1685360056; x=1685446456; bh=h PICvvJyN01FeQX1myCxTwggQ3ABUCLi/5+DEUBxRZk=; b=VCVUebQVMWUe61t4N rEU0nlN/S9Yeu6b4Dm5s09fGKLui8fh8sNl3jjmCFVIvzAbz7MnlTyRwUCdgJQxG TdRP2kzv921AQ356W4Bp5vPgQhIXf2mZM37bD2KFq/ViO/bEwDSOSO+ojltaSYxc JbWsAP46zgdrehWISNOeP56H7IzDWmUV1TNaibbYHAqvfPze1YKuMQ48Zcyd2Y3h 9+QsS1Cj1eVbaCC6usaVUPNJhZy2rfuOtPLJJZOrTJSrH3WbQGnhDglTTx5rrLo+ A8OBqw3Djrl5n7lWOIqlxGj9hB3dC6ZyyQEa7m+3YB+qPr0pIoFDhsLxQc7UDOFP wq0CQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:15 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 02/12] firewire: cdev: add new version of ABI to notify time stamp at request/response subaction of transaction Date: Mon, 29 May 2023 20:33:56 +0900 Message-Id: <20230529113406.986289-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767229313287453811?= X-GMAIL-MSGID: =?utf-8?q?1767229313287453811?= 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..76441eb551e5 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.5) - added some event for subactions of asynchronous transaction with time stamp */ /** From patchwork Mon May 29 11:33:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1443363vqr; Mon, 29 May 2023 04:37:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6QqxGbJbTq2CktObPtavc8o0RAuOj+jEIug7Thu7c7nnnnUPegEkMWpfyIP8fDegEpxZNM X-Received: by 2002:a05:6a20:9c97:b0:104:b7b4:e044 with SMTP id mj23-20020a056a209c9700b00104b7b4e044mr7819072pzb.48.1685360245954; Mon, 29 May 2023 04:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685360245; cv=none; d=google.com; s=arc-20160816; b=C8msce5rtkcSduRxKjl1gx6rcjmMJ9Her90H3elvBTwVanepaJe0HnKV9zUow6qJ00 GH4wlIr/YzrPjvw+HFpnOIhCURq+f8b5gHzcVAx3LAL9WYZErDpc5oAQ46a24azYCuje L0Ayut1xEQGtGUaSsbS0WptO28VKazjeLvB0UfdHUXoacahMy3wljKgF2iB+IPdWO0UN A9X+w6gNk/VmbC/v4Oa5POLhSD392PfZ6l9wHeZkUyXjsYrOMZubGgeK7fpm2fUk2dRm S4A6cf2NK3Nf1z3L/DRJwDrudaUZpuHRZMLibpKx14pBK6CuJpeX9BpfarEqR58QNPcV kNbw== 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=xxh+4Ob84PVG3kps5os2pmFHAOXJL6U/3gEdo7CtgRM=; b=HHsIrc+DSM4A0txnu4/ynQrIyiE7gzRvLD/RGHsv5Nn0HcOCSX2u5mOuUJTNNMUTGm d04zjOpk1Ra9IrwzRdYNVIi7hwo1aWT0KafHMP73zyqFphWVy9SDn1JnGTBpHZ5/bBs6 or+lHz/oxlsoZoGwdsJU7wVJjopogA4iiI7anLhg6iqcEcfeCHC6kKsjiydesHUKZ0C+ bT7hMK1WsXxr0rC9kknCZK82XmDpxfX39/vXfPQwC14qGm5R4AX/8aQVsFliiPLzh2Ld A6SPpITZsHHBleIDd7ZhgmbRguwHunbZdH3lyfsTI9ojrYgS8lsdIXvCyNCbqmfSsJJb 2aCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=TnqLc3zL; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=NgSUs+nr; 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 g21-20020a633755000000b0053f3d04e66bsi3827956pgn.698.2023.05.29.04.37.12; Mon, 29 May 2023 04:37:25 -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=TnqLc3zL; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=NgSUs+nr; 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 S230487AbjE2Le1 (ORCPT + 99 others); Mon, 29 May 2023 07:34:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbjE2LeV (ORCPT ); Mon, 29 May 2023 07:34:21 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F14BE for ; Mon, 29 May 2023 04:34:19 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 05E6D3200929; Mon, 29 May 2023 07:34:18 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 29 May 2023 07:34:19 -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=1685360058; x= 1685446458; bh=xxh+4Ob84PVG3kps5os2pmFHAOXJL6U/3gEdo7CtgRM=; b=T nqLc3zLPnfCp7wxS6pUyCxfgxNBod5PX+chArtZK5WrtFLkAvHQ0fgNsXoD9NPqX gEAcAKSIbQBExHxY0FlI+1/o7aAcqI94YBJ9mgPI6n+6mEEAs+81myq0n6fUyuKp NfO+6mw1YxgyMnsfv5nndsAFEocvHS3duch7BY0KXcptdIH79bkrYyMTleQPBw+o R1qco4I3iLYF5ZVIS1z+e4ADs/NVds0WoZ2sBTXMNBgLJsEAse5erIBGRtjGxLUC 5n3BZSD/NfLaCZEpvmose7fzztRqZyMeEomlyHqtWiEeW83dULYaUku3k1b5ny+7 BUusGO54xZ8UD6ee2h3Hw== 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=1685360058; x= 1685446458; bh=xxh+4Ob84PVG3kps5os2pmFHAOXJL6U/3gEdo7CtgRM=; b=N gSUs+nrVqxIQZ9pFDnGnmjJIa/gkZKGCMH+wgktaZEaRePMagRM+5qEtfzBWJxB3 nrtZE46VuKZzf8uP9MXWc9wNhLPtHKKhM6y+dGREBqIiNAfM4Q9xeA0x4vFu8O5L znnZJ3d+Sk63i4yo8xy4qjleqztQqEvY4Ls0WPs/YrsmoHiLQsvwQ8C1lpfx+l88 RFhzFacMsaqkI9Fh/9e9rdG0iLnZSgWQBxj8PddcwVBq+vUuMp3UKBJaMJZLIHXG 81B0kXbRp4jDdfyfwO/P6YQGwGuUaZ6LX7fFoH3QWO5fzt1GbCeyUsPNEoZSWthW 0xdj3e8+GWxKf3FZsaFYA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:17 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: kunit-dev@googlegroups.com Subject: [PATCH v3 03/12] firewire: cdev: add new event to notify request subaction with time stamp Date: Mon, 29 May 2023 20:33:57 +0900 Message-Id: <20230529113406.986289-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767228305279073857?= X-GMAIL-MSGID: =?utf-8?q?1767228305279073857?= 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..dd95899de316 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.5. +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 76441eb551e5..7767cd53a013 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.5 */ +#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.5 */ }; /* 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.5) - added some event for subactions of asynchronous transaction with time stamp + * - %FW_CDEV_EVENT_REQUEST3 */ /** From patchwork Mon May 29 11:33:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1443376vqr; Mon, 29 May 2023 04:37:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ44BR49bX+c2q+x/6LGaZPfSnd4xylQ8m3P1VyEiSGd7Jxif12K3sIBRmR5jq680nHTbE1K X-Received: by 2002:a17:903:5cc:b0:1ac:8148:8c40 with SMTP id kf12-20020a17090305cc00b001ac81488c40mr10369912plb.53.1685360247525; Mon, 29 May 2023 04:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685360247; cv=none; d=google.com; s=arc-20160816; b=SK6RWkLcE7dKwYkMQuXs2zCVh8pkWuEdwGF5wONyu0/jWWrHTmy+y8H1klYopeq7Sj ptUmeaK68kIXozdzFFw7BUws2LC0K7c+Zo71gF6UC6e5IwysGterSJiIjb3WY2uHYHMV gRsOSzPonUB9e+f6JgsrpW74DFqWPu3rImVh2AJamylOn81m61MJTUGtzDClgUxTC1bS BL1NusOfc3FQzp9m4Sqla1qn471RxwnM+SzsUQ8ALzDC3hOjLnKnyHCEdO18Dx22sH40 p7v495ogdzRDslOrJuz9F/rFZzF3GofXXhhHYkfyJqrTMvHOzpsVtQPelQ7BT/QxeKiR Ujmg== 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=kg5h/sBjXbaMxPsrYtzTheP+7brgWtgzet1FandZT3bAsw6wh2ZrQWKgSnuV7dowYc dqrU7vBYJTwfMCZE0bpWv93jDWoz1FgeM+glktQikWxWJRafBybDipP4l/8amElc8Lxf qEn705eFgKrq5Hig41FzZu4Dp5VlGXrJ3LKI5bMl+8vkgHokCGVojeC1S0jcr6ETwy3F AlfXz3WAUtUvalVtNc4o6j4hMClvlyzTgwJcnpqiQs8e55bS1n3yBtLXhgd+3JVep71N mmhR7fhPHDMotccc4b0SIU9hcYVee8y0Tfb7MAprE5MTXNyccKL4+8hVBlbonLQvNnEc 89JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=CltzJyT9; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=N5ZJrem5; 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 f9-20020a170902ce8900b001affb5906aasi2123624plg.4.2023.05.29.04.37.13; Mon, 29 May 2023 04:37:27 -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=CltzJyT9; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=N5ZJrem5; 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 S231565AbjE2Le3 (ORCPT + 99 others); Mon, 29 May 2023 07:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231548AbjE2LeW (ORCPT ); Mon, 29 May 2023 07:34:22 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2B2CD8 for ; Mon, 29 May 2023 04:34:21 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 28BE232003AC; Mon, 29 May 2023 07:34:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 29 May 2023 07:34:21 -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=1685360060; x= 1685446460; bh=vLnKaQC1H8MrzTAmo/K64YxxQOflNTjfEH6QTfOvlSY=; b=C ltzJyT9C90mD+pOF+VQG7jxa6Xa3pLsm6imlObuloFvVeKLNHwxcT1RBDHFCAhoz ep0okZriQIJTF2P678LVrgOadawGS+mX8/G+FkUWRgoJI1Nd/B1GICVcbluy595Z 2a9Uz6k90vtL6Ix5YxCNxPt1BMImKjVQ13ThqnUCkKfBIGL4vyFQD5ZVpgBNcfrg YI78/8+RPkaG4fdabMzEX2M4NuvjtuiUI45acVjHKyzOGEq6f/aNW73eHgBse2IM 0ncuiTCPB0z0hf06v4vzUS1NJobzjson/yaoyOxw4h+bA8fw492Tk+seIK01gokF 0yF8WJ/WycDGY7OfIaGeQ== 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=1685360060; x=1685446460; bh=v LnKaQC1H8MrzTAmo/K64YxxQOflNTjfEH6QTfOvlSY=; b=N5ZJrem5eSTvzJ0hB qgp6y/SpeBdP1HkTBp30KjO5q7gEqUrIu5Q4RQA0GG9VqkLRbuMKHSxsoVS7ho6V E7AEglwqijH5baaUismXk/bwhVjCHLoO+2qw+FMI4gTRUEEsRqL/Qso+QqDh5zH1 vzkn2ynHKZzn9bP8bnIPR0OP2+jtXQXaIfv+yhD8DBE3ntFsAfZmuWj68cAhVpB2 Lde/JFzKWiDCGrck5/cmPdOnkNYVW4FjapK+DbSYTgZ3aF3hfAROzys+iwPLoD9/ 9iTZ5N+4GaC9ZfMUGWux/tt+9kE5z7KvmMe/QIc7r1VI1drEO4MLT+pBFRyPmPEl IPU+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:19 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/12] firewire: cdev: implement new event to notify request subaction with time stamp Date: Mon, 29 May 2023 20:33:58 +0900 Message-Id: <20230529113406.986289-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767228306670295776?= X-GMAIL-MSGID: =?utf-8?q?1767228306670295776?= 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 Mon May 29 11:33:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1443407vqr; Mon, 29 May 2023 04:37:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7srv+5z3ClA0l+6+3OHgK3EmHS7Rc9vaqPNeJvdGk8QB6dCGO2EFf0YmnOTWUN0lXLIyf1 X-Received: by 2002:a05:6a20:258b:b0:111:997d:d216 with SMTP id k11-20020a056a20258b00b00111997dd216mr969835pzd.31.1685360251449; Mon, 29 May 2023 04:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685360251; cv=none; d=google.com; s=arc-20160816; b=FzY1VsYglp6U1rycnhqI1j5LcN2eKy59nBirN4wgDwUx/Ps8/+mC9xjoJAfO481dMw h+BfKGBi2PgRCmzk4IGVb5VHsbi+uqRNl6qKrLkjKuZc284zOzn32WZNnQrjsKzpMqhP AG1HHt+H8c7v1hdIX1ZSMNN7gttz/LzqCMAiabg29v5Ws6+K541IYpLrsScmxpy76LTU kU7rrWzdxdJyXvq/xdvYYYtw1vczRdHJPc34yJGUB6J/yqt3WZC1fUJ67a/BZooFdLiI yOtkXqgBZQKFDFtmB+2+zLNGaVjNS46kQfZCHdj9yvIZd07yEBmPzA4hIDSXHPeItpuB B0UQ== 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=0N3wGDshNMJ9F2Or6E+bbP7FA9nQus0FxxCwP57t3pP3Q006eWvAWEzj4ww27kYqe5 0O9CXObHAOiR1xNnxzZ3mGnwiXw4Ub5InN+CKx/uvs/4twdlbk/RkDau0BEYLK1/3lLa TV7SGDLEJy2s75s5tBbyWKXLU2VtT2K5EIwZdyxdZxs2gVbzrCmQXR7S9p2SB/SSfLTu 24G21k0vlAebOiuDBXbpMp3GMOrx4PwUAVo2vpVSkyF0hn0lQ04mgwPJYA7GOzPIngJP u3GhDCsroh/cbo7q/v8ju3CFSkDyAPgAOXfAdCZtNzFCwYLnHH/SeFyuySLXk4mtIEYT msMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=sPBOBL5p; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=MQYCAPFZ; 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 b124-20020a62cf82000000b0064140b05b6dsi44778pfg.228.2023.05.29.04.37.18; Mon, 29 May 2023 04:37: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=sPBOBL5p; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=MQYCAPFZ; 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 S231578AbjE2Lec (ORCPT + 99 others); Mon, 29 May 2023 07:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231556AbjE2LeZ (ORCPT ); Mon, 29 May 2023 07:34:25 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1FA9BE for ; Mon, 29 May 2023 04:34:23 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 4AF713200935; Mon, 29 May 2023 07:34:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 29 May 2023 07:34:23 -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=1685360062; x= 1685446462; bh=hOQR9q6EZS1DH1YormYT1kFTGnL+BePtUImO4q3mnKw=; b=s PBOBL5pWjPkrrxUbluWQxBYR6AHO/oHExBA5KFF0gF+oTfLvO+lTZpSIzGDB7O9t TvZf26zkdosUmE0ELJCq23BpGqslOAtxALMWBDxM9f2C1ln0YiriZoSsVFA6ymfe LZaT2bTWWw6UOGGpOJmms7+9CeoEBwyLVRVdaaimKeRyzQmkkhV5cI+J9Via9NVv rkF1GpRL9RmNmgfM31gdZbi54p8pTBcyXn/4+KFrytuuwvyRwKZz3Onl/mWNMMCt d9lEcYCtHkByzQBq91tABsMxvZaUJZhfCm/AxwcpVylaWg/R16ah/Zga/yZbgIiS X4G7+FshPsb6nexMck+bw== 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=1685360062; x=1685446462; bh=h OQR9q6EZS1DH1YormYT1kFTGnL+BePtUImO4q3mnKw=; b=MQYCAPFZ4yd7kk7NO +FWESy5u/XNkejyLSbA0fWnse+D9tcM+p+mwwAPbSHM++NAy0iWQae2YscckwWBB r63g1wV97QkBXbWKMDHvmVSQ0o8td51gXSJMcqTJ8j1JEONl7r5lJfl1AAaqJB2+ 2kONb+XlYsa67ubEAW3HydnSETulh5ugbAAZlopO3hwapYqQTRExepmweY5PXIJr inh+01EsQ3g3rgXx5KCCq0AS+QEzLb3h9YMBeit2QAtQG7oeqiH8j5AofM7gDB7o Dx/bFfjYmyTpGSRyZw2toVqzXB7zLyH9RH8mijUJZF6AVO0GZqQop1LcrCpeKave gpshA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:21 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 05/12] firewire: core: use union for callback of transaction completion Date: Mon, 29 May 2023 20:33:59 +0900 Message-Id: <20230529113406.986289-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767228311175988690?= X-GMAIL-MSGID: =?utf-8?q?1767228311175988690?= 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 Mon May 29 11:34:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1443514vqr; Mon, 29 May 2023 04:37:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7TqB4YmrzHfOyUxc3Ujnex5qLtlawb0/QcMnOCGrPNSxsaJXl6UJzA5v9YKzhyj7I+9Z0m X-Received: by 2002:aa7:88d3:0:b0:64f:49ee:1a61 with SMTP id k19-20020aa788d3000000b0064f49ee1a61mr14401290pff.34.1685360265249; Mon, 29 May 2023 04:37:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685360265; cv=none; d=google.com; s=arc-20160816; b=PAZ0DaJ/rjyfiJ5qL28xFlvXmYjSfihUrKT5gEtV95dgLgRec4HXPKP2H7fNE1pl19 ka668btYUr2sfuFDRZfinhI6qbpoGonUniQfeyn/QUp3f7kJziJc30w35ulBla/agh/J heCX7ER/nsLBBpj8v82OtNSyHzgi90fAHeGgpgCvbG65BBz9hnvTo/kJov8rJ26ma4ms KxxcPAxi5KgIySH+qAj1l8qhB2GtqoUcGZuQbABjIc1LAqvsn5ie/IsHBb0LVJCDPafe koKacSqp6+EybCP83SyIqBpNmAD7ZVQmtt/atrWbS4YVFWQK5oCFQqLjvJkitF8JCsz/ 5WaQ== 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=O+crugC2crx1liGIc4qcC6LdHAM32/Lucb+X/ihOApWNvFyzPQUN4FoBu159+2TwuF yzLgNVRjISiNGXzqgErKesGvzOGL/uNCbDunHiDVH/fS+8XJrtkSdvOf//DDTrE0cLu0 wVZvwiOVjUZA2DIncTpBRqxf+FBm7SzCKkccnac9UmfrbjM3AfY8PN87BM+CpCAsJH8d O/ermK7m1ZdHyWmHa8jwOT1Vj+gpNx0NTfEip/lBJ1m24t44SXtl939AKy/zLrGKrTny mO8vj2ujRw3xXs86I5sEPcKn1olTDyJXYiabFzGOyTjGVX0ZXZUJPeAe0/yMwJDDraFR K2bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=i2A7DnyP; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=rHy0fOgd; 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 l62-20020a638841000000b005030a59a81dsi8933661pgd.159.2023.05.29.04.37.31; Mon, 29 May 2023 04:37:45 -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=i2A7DnyP; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=rHy0fOgd; 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 S229453AbjE2Leg (ORCPT + 99 others); Mon, 29 May 2023 07:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbjE2Le2 (ORCPT ); Mon, 29 May 2023 07:34:28 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BBB7E4 for ; Mon, 29 May 2023 04:34:26 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 42F9E3200392; Mon, 29 May 2023 07:34:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 29 May 2023 07:34:25 -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=1685360064; x= 1685446464; bh=Zx5vRuZcoTFwzB00ySCuly08OEL537Ypl8d8EH6oHiA=; b=i 2A7DnyPey/vY8w8dZY1/Sf2qnTaXL8TpEhP4UDEls+xyt4rC8XI3TS8DMYCKQmlw WRa/1FnSjbJDRM1wtPmpby7UbxdGdqB+kXAquNFnwqu0pOykWNEoBn6Yev1ynZsI 5ww+igXez/118tHu6cza+nhzozeLM3HLe3trn6e/C/TLcG7IpZCNVjhhPcqy92TW Gy6Rux8s/tCz6enjKbJWEtxAyjY0NioTEiZCfAWZpe8vej1Bmpsc5FNm0ooiAHkW LuMri+mQeqs2aZrqDrVUI6RWeBQDpNIN0SrfN0u09hk/AqgFg2TknOW4csKlGWcS SUVD2omT9g3wCbDqW5nCg== 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=1685360064; x=1685446464; bh=Z x5vRuZcoTFwzB00ySCuly08OEL537Ypl8d8EH6oHiA=; b=rHy0fOgdVxFdQoiAn Ob2MhSTuufPVZsLgK6KgMTBJoNQZA5nYiZ1j4mNPYnncPsie5s+48V7jG0LxeQZ7 t7x3satvNB4HSGjrHjr0vdrp4biMYWivFpoHpXKm8sDb5TsQdhgKXVipoVxd82Py cby2Spv5Eu29/4tXyyEBr9y+gijE1irWUtxkFpiCxmdmZnd11eHQA1M4oOyzx+i/ Hs0Qaf3fs48YHTJFSHjb2t6C6DzFKIsGRHUykrTCyI/CkPmton6ca0U0UoSZBAA2 jgM9R12LmtTj/mKE6jg9emAOAVHjf8kf6EdCPQoCwNTnBCe8dyYseRN/i4v7+afo 7IOOw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:23 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 06/12] firewire: core: implement variations to send request and wait for response with time stamp Date: Mon, 29 May 2023 20:34:00 +0900 Message-Id: <20230529113406.986289-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767228325728350363?= X-GMAIL-MSGID: =?utf-8?q?1767228325728350363?= 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 Mon May 29 11:34:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100225 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1443808vqr; Mon, 29 May 2023 04:38:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7jCvSNLn++JS//zd4b06dXKF9QoOHeA3Rf6X1OGkHiuNLF5/+nS9svWeDP0G4LZh+AAOsk X-Received: by 2002:a17:902:c1c6:b0:1a9:86ca:38cd with SMTP id c6-20020a170902c1c600b001a986ca38cdmr10558129plc.2.1685360300907; Mon, 29 May 2023 04:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685360300; cv=none; d=google.com; s=arc-20160816; b=yrM9+0f1Vni21VZpH5E4aUeeEMWSfqzzm/yolXIT3JJgTMviHBRC8PUbXZnlRAxv5J 9JFfo/rGr+r2Z5DSs+nIYDpqH/ZC64MquPv/n4cK5hs0wamOQ+5bEB91AooFFQKWP67M LqNlrvnnR61hihag4WDIxzm0Xn/tiJk9BAJG8DPJs42zLoQTVltkCxDitVhMrKa6zrjw wC8IgoJoGyOk2qFol5vstjbTOsbdTnGYmjBtfo2PrZlgOOk38urcKk5yfIzFcajNTC4G xyLtq2Yzi9Z7DIIevup01uH330F+XbTJsVzOHLBlLK7aI2bvZHrjODIcxgSKUnLwjYqn oB8A== 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=O1lWYsFzjnu4aYXnpwgfGgYp+GZOTVLFsjfc9tqUxuJjS3j0/M0yBMGDTsBvvJHCzd YcY7jNIp/0/Nok/Jc/GI6l0ZjxuaUFPwQ9GFKfNm7cTvHNYbzWeJwdPsLnh1z4wQyO4a 98ejKn2f49EtJW2LrInhpxfIAozOHYs3CHr8QEbfXNlMHZTk2BII8aCf1BbOFvVPf7lj cJ8RvystSzhZh39xwMz9zONGmbvKS6H9o5bG6TNjR7Soi11PpATZqjTjjNKXJ9ueDTr7 na+SVv+dv060losy2YS2+Nk3LikR35mo9i+iiTpWiE+h2f0Md8hgG0v7LP91DK+jRepy njTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b="q3/PXv12"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=BTn8MYuw; 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 k15-20020a170902c40f00b001ac4f733007si10622258plk.549.2023.05.29.04.38.05; Mon, 29 May 2023 04:38:20 -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="q3/PXv12"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=BTn8MYuw; 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 S231627AbjE2Lev (ORCPT + 99 others); Mon, 29 May 2023 07:34:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231494AbjE2Leq (ORCPT ); Mon, 29 May 2023 07:34:46 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AE94FE for ; Mon, 29 May 2023 04:34:28 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 3DC163200929; Mon, 29 May 2023 07:34:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 29 May 2023 07:34:27 -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=1685360066; x= 1685446466; bh=hCn80S16t5KWMrqhGJtFmBVIPiQ9NKvnaZBu9C4Y5xc=; b=q 3/PXv12ub3R543er7mtSqTG+UOl9z9RizPLl3+jLjcqk5V7W/0HqO8BjbPb5hmll ImZTRuZ+HREPQDUxoS0yCVs4zh2hBcGw8IDobLfre9D4Wbij9YFsJNd19CRuFYqp GjtzNwEgKBMun/4HXcr3Mp1BJsvhR0cQmTtCQnWQ03CKMa5NJnagzJXdBNwSm+Gd vttC3Gg+IJ+pQsd5N/2Pj5nyqP17wU+DU+3pObOUDoQlzvZVHeWQf8c+C311TJfT /KsezunhzL5BpsOh5Ql7ctUnRxPj0a0E7M/vMMzNwTBdcWHssoBO9TKvIHcgW871 rpTEUf4F1i4e8W0mt+8eQ== 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=1685360066; x=1685446466; bh=h Cn80S16t5KWMrqhGJtFmBVIPiQ9NKvnaZBu9C4Y5xc=; b=BTn8MYuwszk8Iw27z MXblbdH/e4Ca9imlzuRm1qKQo6+2rKHcyIIXu1eK7vHR9dMvR537eRidlzctB8sD XzGHo48+GTorW3YpQpJQQuYR8Khuodiu1rpcJCDZvld6pPwQFVyMfnz3diiIBayy nhBOQB8mW1m7mGVCqDGxV8wtylJqL+IKSimuU0AnWuAT3uhFvn20NxtXF8+7AfK5 jxOjpXXQMsZ8YUm1C1XTO5p6/KPBxdd9W3muxqos38PI5oIciOC/9HyGHzZLXR8B F+b93LZEUVkAvRsRrHdFJms9h+TMcGcyoLp8Q/crL1YqGAxFusUdGUnhFMfp53He /hXiA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:25 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 07/12] firewire: cdev: code refactoring to operate event of response Date: Mon, 29 May 2023 20:34:01 +0900 Message-Id: <20230529113406.986289-8-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767228362642623133?= X-GMAIL-MSGID: =?utf-8?q?1767228362642623133?= 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 Mon May 29 11:34:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1443973vqr; Mon, 29 May 2023 04:38:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Y8Zi/Fk+swBwQQwPxXtKeq55Nt1chm7T5haPj0kJkR33JmgTpp5uwneolWwzhmPO7BRzz X-Received: by 2002:a17:902:db0a:b0:1ab:28ec:bf10 with SMTP id m10-20020a170902db0a00b001ab28ecbf10mr12130588plx.51.1685360314734; Mon, 29 May 2023 04:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685360314; cv=none; d=google.com; s=arc-20160816; b=G8URY3kRQIANTHXjRwqohe3TiyhF1aobtxbp94dtCCm+tU6AFfJBEWDvlg2k2b9Wzj Bm9yWtTEj+nypjqmrcu1rNq8L/mE96T569qWBy97LqOfNsGrDBoNdQCl/40ZjiaWZEXa wasYqNLyxaaTRljZEK1SK4j6vf4hs2OjqKOyjLBTQ4UWUyOfpOg0MElkEdwTaRubgFir +3v4ipe0nEsiFYz4MKpDRvvpt9RElkzHd4sKK/1T9urBqINLARTpjOTM0kmdXMyXS2RQ yJCQbn8ajtMIyjP8NnZEBem+KtSn5cFCXG0rxTcvcZnT0YF7jp/+mXn9lBK16bljKOIx gFbA== 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=y2dyz0bs0I2fbKhF3IYp4zE0pAAIp0ALOv0TsADA8wU=; b=rhggVY8YyidSgFfyl6cfOHLj78Fp1fGgc70NqrMMAHFlqP/soUWxpDIcyc8WE2A7ek 6c+7ljRGce1VbVE+Xzlh5OsVcBL34YsfynucXRr+EierxUiGrJ1tBAM6fgMDGO257mV7 Jb07iYqEk68YT8/ARgB7SAnY5KeIWLYRo/V/MOgGoiqgkduQV+OYStuFT/ANw3ssE9Eg uFaKaxguuY088aV3Gs77pmjOZ2glA3MR6jZofXkiMH2S/LXE5VDHEQeLMFpbJ7NLpdk/ ZdbQVoHDSczykRaTj/k//PhXC5Dgq/9nhea2qbA3SXgz6l0XOQu74YFxiYpYXYTKgzjJ 11zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=jftBtRqw; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=op+yUw+p; 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 z15-20020a170903018f00b001b03a1a3169si2588705plg.257.2023.05.29.04.38.20; Mon, 29 May 2023 04:38:34 -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=jftBtRqw; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=op+yUw+p; 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 S231494AbjE2Le5 (ORCPT + 99 others); Mon, 29 May 2023 07:34:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjE2Les (ORCPT ); Mon, 29 May 2023 07:34:48 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EE75109 for ; Mon, 29 May 2023 04:34:30 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 637303200932; Mon, 29 May 2023 07:34:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 29 May 2023 07:34:29 -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=1685360069; x= 1685446469; bh=y2dyz0bs0I2fbKhF3IYp4zE0pAAIp0ALOv0TsADA8wU=; b=j ftBtRqwCCirR4laF+AGrG5xCtXrjSKHUBQJZ0UHCyP36yN9HTvj9urvd1pqJHXXf txBQvKju8kzbfRcMjjUCWPNA1+Cf2QGTgtSSRmrbQMbz0SJTv+kVR2JLTU8ij9eG CRAtr39snEixduSZvuZlGPGzBeGb6WJQtef3c3OD74bLhaoiZOmod35T1FLRYZpX Qml+Dret2Jh9xGB/+b5C5FH/7eX3LDTWo7G7WXTmF2xP+v7qu9uTSKTn1ajY8CId Izo03Q92Z6lhzyEaCVWPXYFMhc0kgJB7osAPRGgQyYFWxwxIVSEVk941lxV6c++I Js0bpAoMgf5++EHSdS5yA== 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=1685360069; x= 1685446469; bh=y2dyz0bs0I2fbKhF3IYp4zE0pAAIp0ALOv0TsADA8wU=; b=o p+yUw+p7cpeSwkR2Bpc3/CvxBLdbdV4ny22j+kLXWtUPvN56s8aGEVy7J8NjZMUh JO6Rq+PnG7D2dNGcTKxpzLVi+HBXJ6FN86nVMFtSCoxI3vZq5Ba/BILmA+wBiXfW KuZfwSfw3sGtnO30aEWH7yaxwW0uFWNbx5EOBazgbyemHnDg25gjQ7/pc2nGFCXo UjrsdQ1RBAjw9BiajtrxWowAuNZbzd5yImfXLY5qio1A7xF0iyiHgIl2QbQe6g6M hRH9uFfXen4CsOMm4supocrQlrIqpPINHVaU8U/Mnsdo86acgtwdQoSMZPX2P5Iq 54O5vA+mBBbRcFXuk6koQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:27 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: kunit-dev@googlegroups.com Subject: [PATCH v3 08/12] firewire: cdev: add new event to notify response subaction with time stamp Date: Mon, 29 May 2023 20:34:02 +0900 Message-Id: <20230529113406.986289-9-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767228377090852072?= X-GMAIL-MSGID: =?utf-8?q?1767228377090852072?= 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 dd95899de316..640e5c05415a 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.5. +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 7767cd53a013..13892016c266 100644 --- a/include/uapi/linux/firewire-cdev.h +++ b/include/uapi/linux/firewire-cdev.h @@ -48,6 +48,7 @@ /* available since kernel version 6.5 */ #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.5 */ + struct fw_cdev_event_response2 response2; /* added in 6.5 */ }; /* available since kernel version 2.6.22 */ @@ -507,6 +546,7 @@ union fw_cdev_event { * - added %FW_CDEV_IOC_FLUSH_ISO * 6 (6.5) - 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 Mon May 29 11:34:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1455378vqr; Mon, 29 May 2023 05:01:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6AE2BB3AmQ3hp3sL9cTz3MzAgE16UmFSqNLIf6ADwpRlUWfd66CxTDyfkUfHVaxEVB+gH9 X-Received: by 2002:a05:6a21:99a6:b0:10f:d1d4:40d4 with SMTP id ve38-20020a056a2199a600b0010fd1d440d4mr9777406pzb.14.1685361670596; Mon, 29 May 2023 05:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685361670; cv=none; d=google.com; s=arc-20160816; b=wEhN1lehEZRMSa7GhQ/0D02y/1sguENmh8NwDWjamP+u6WjMpq9Vuvwk4tB5oave0B pPQ8dJKbr4Jmt90WvE0S2V41lcfxiE6iq1Rar821qxwUdTV7h6r97JyhZEdzi1MWVDI8 LeBAkTfuoNY/nU849qGH7Gi/HTCmod1a1t1A7f5gxEYPF+KQ47hGwJZmlEfpQUSfCyKc xJTjetUFkdCWXrUMK2w9YsGf5WgKCoNHzNTn0CdXMnQYtMGzwo/MyFxC2NU4KFYV4g9l PRkkrUMgtVO1ESoI1rW0qicSJ/+TyQ0hDl4QcPJ/S41i4boA3bqVCm53JYhL/I9bacux r+JA== 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=Ofc/UE50D9fZ5zJQFUYfdWtBx0PkeaOusTLRfScDefzC8foCdyUBSAVuLuW0uTVVtb BWUxieeBlZPSeSnLgCNp6a/ktzi6S0XJm82SSpcRVZoGdMt2KUdO6gdiaeFaA1sT/m4r YuqoazxHEdXhRfU1su9tGwGjlanC8zZLuIDsZYa32dfp6fppufrZX1TFlTpRdZt/zKu5 7i+Ax9W66FmhlFNepe/csAl0lJtCzvVhhC3lC0z+SMKJU6Ia6fp6xlHhbWb5wKEa11mh 4z0+Mlr9BAjHj5gbI/o++kjryvotr9wVKhiKqvDFtZy8pVLNqMDF3oq2wSbXAS3YI0Sk PbbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=fVu2ThrH; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=YZdQMWgN; 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 bu17-20020a632951000000b005346d98e74asi8826915pgb.36.2023.05.29.05.00.57; Mon, 29 May 2023 05:01:10 -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=fVu2ThrH; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=YZdQMWgN; 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 S231609AbjE2LfB (ORCPT + 99 others); Mon, 29 May 2023 07:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231638AbjE2Lew (ORCPT ); Mon, 29 May 2023 07:34:52 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58F20121 for ; Mon, 29 May 2023 04:34:32 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 6FE6832004CE; Mon, 29 May 2023 07:34:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 29 May 2023 07:34:31 -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=1685360071; x= 1685446471; bh=19oDU4fEk+sheHYZWOnoN5cHboklhnnlKJrCnG0DjSI=; b=f Vu2ThrHMZYnWxx/VPt3E9aDHlxv35J9s3YH7epWvBi8RJhUlJv8qRUAKHd2MpSUP Hh5x4ltcuv347uPGyT+JYANMH4c9hL5Gqlds+cR89gBjVI1gQ2w1N6a5N5R92Foo qyYzYxk5xFXFtAoLGV4Trq35ZnPZjf9/HdAQrkRuTaKZtLvPCMF2Mvot4OI7xDIV 4A83JfWK8iy2ua4S/IIjJwv96cK+YKC5H0DGAXl5aaO+n9okgA5R29Bb5H8FbYxf nRLLis014TKu+e3SXP0I51elJd/MmgoKpunSKUB03bZuLpquy25g0wYUqLtfKCNF 94XrmERtJ3lw2ALfDuAeg== 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=1685360071; x=1685446471; bh=1 9oDU4fEk+sheHYZWOnoN5cHboklhnnlKJrCnG0DjSI=; b=YZdQMWgNnc91Co2nh CRi3lb9z9uwMwuAwY+QU8bivt0qVB5wJikOCSa5+drJJ2kQ28QZyHtLp6bUJL8pr WdIjtGPfQIFiBu6Qv8qmkQ4V6/x1t+T49Z//AYYsVBissiBnY4hNiv0ua8MjCywf 5L8SAiYaPZoqfCifieUkmzmzYpH1Vh8qP8vN08CE+WBp+qfQdvmo/HhExJ5mHhT/ JV2gOJH9RzRsfDWBbgskVBfS4qSmuC0Mu7W6b3uKypeeyNc1iDJ6qBS8UqoXv2E7 qmfjCyZmcCzWNzCOX6HdjcovwAPoF+rJosVxPWV4lawU0uMHlIGTjayxV5Qv9ikq b4thQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:29 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 09/12] firewire: cdev: implement new event to notify response subaction with time stamp Date: Mon, 29 May 2023 20:34:03 +0900 Message-Id: <20230529113406.986289-10-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767229798719763124?= X-GMAIL-MSGID: =?utf-8?q?1767229798719763124?= 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 Mon May 29 11:34:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1454343vqr; Mon, 29 May 2023 04:59:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6UMYn2Sah2XWhm3KJSgstc8lqY5TO3w6etufLNVSc/SWfvRa3ul4CmC2YZCq8DDNvajOxI X-Received: by 2002:a17:902:c155:b0:1b0:4527:3716 with SMTP id 21-20020a170902c15500b001b045273716mr2197965plj.15.1685361594134; Mon, 29 May 2023 04:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685361594; cv=none; d=google.com; s=arc-20160816; b=H8yNbtWUS0Ov3EyL3zgvLDYbJ6GIrAHTIzGndiUljsnZFz1ludq5A7mHBC3b4TL8e7 x1YRuiOvBjIWdLobRnLmOBqovuoM1CrvBv4ZGY2sjHBmVc9KjoQa/AsjO0QcoyrTKJMk Gruk6gJwGNB/8XwDLBHTeW2QaGXt7n5my1mKPhLt1FHp1jbt8V2tBp3een0tih6Wh8mT lRmB7zhVwiMa5zaRt54exnFRSL9HFEx4gYoDjLah5hGDrbqtV7oqpOfgTYQQvkmRrd33 f6uuwNyzQzCCjQay6u0SibdxVnmf/gNtfq2Irt3ElOaASNJnV5A686vDXjSVt2kmTLqG lsNA== 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=J3FjkK6PaS1n3V9LlSPPMi+UekpcebfOzMgc1WoK+ItO4bjXuuK6oiRWlgqPCgATVB N+ZHmcJjgViwQNHHLEwr1q80OI6aZowGTbHVLWnS2gQARRCmP5PGiuasfT92XmCNZL+P hn4nex8HOvo2b84UgsMlSeOUK5yN8X2Z/+6eLoUOyIq/lZOoHBZ6wgf71PMf+qKokZ/L K3HnKuI5Q5JJuVCPY9GhY88CvX9+ZZMcIGQz24qfa2OgV+OCsE84TCIpOG8nSPOww4GG 5B2tin7EDLEEf/5Dxe1REplqof/FoZYlgV0mRlgGfF0LKYOpblwb7iXyXAw4L3sddc9E midQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=kq3hQNcE; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=BLufKp+E; 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 c15-20020a170903234f00b001a654cdcce0si2944283plh.103.2023.05.29.04.59.42; Mon, 29 May 2023 04:59:54 -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=kq3hQNcE; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=BLufKp+E; 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 S231650AbjE2LfF (ORCPT + 99 others); Mon, 29 May 2023 07:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231669AbjE2Lex (ORCPT ); Mon, 29 May 2023 07:34:53 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2780413A for ; Mon, 29 May 2023 04:34:34 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 60C0232003AC; Mon, 29 May 2023 07:34:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 29 May 2023 07:34:33 -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=1685360072; x= 1685446472; bh=fzYN89ZMFMfUx+g08kllNmIdNawZyAy6SkyrK59Skkc=; b=k q3hQNcEvdYLw7WNM+QLeh3rgSjaYsz613Grs8OI7jadHAgNSo1gJqCR6/MfyRqOC siD6aLZYuLvHi0QoEtS10YWdpVZ0Q6vE770Q+7Fm/DkzCfbozlE0u6vvShaBYX5S AWeXGIbu2zBQckWsdXpBts2sEFTZyhXpQgEbj2a9nrBgEmbGe61ozCKf+YgP4/Pz AI7MPB2Bo+wOahuKgf6lvF3yyO8uOIXAUz8R5NLqK+/m9hZSDLs9w8LulSUQTm7j y104fYWcBWv+Si2RrD8Rh2yeWENCiLUHo7NA7Y+z5JMcSijC52CcyTJwQwchiH9O cRZE0Z2GW7iVghUPlPB2Q== 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=1685360072; x=1685446472; bh=f zYN89ZMFMfUx+g08kllNmIdNawZyAy6SkyrK59Skkc=; b=BLufKp+ELSaoycQKt Q8YQSe4Mhqp7965Ghn0MdjqVQnfnQ9psuPSwhbBSi1BAP4XIjw+GT8gu3x73+omL 6+CEQYSJ8fUgz0uF0PB7eOJ6SwHHy5GH8Nl6g6Z7J3ny3rO1jCf1/Y0P97T0UhiF Zy3ZAbl5oEuQAhsa9z7rXyJQZ3q93iG7fuGH3vbFVFN1ZPD/I/AFE26JfEBDnsso +XgBIBb4egA70fpIvSEBOWCPQAANbcpdvS17oKJYCrNsZEqklA6zrgpOsW3DNwoP UIfvUMHLnZwqVOvdPApq+7X9F4pNR1XpxfVNwEAlD4Niq3MySkkdqBgODnybOEf+ na4/w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:31 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 10/12] firewire: cdev: code refactoring to dispatch event for phy packet Date: Mon, 29 May 2023 20:34:04 +0900 Message-Id: <20230529113406.986289-11-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767229719098409425?= X-GMAIL-MSGID: =?utf-8?q?1767229719098409425?= 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 Mon May 29 11:34:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1443708vqr; Mon, 29 May 2023 04:38:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5q8gkUvZ/mww4US38s977s3ijvhSS+KGm6H2eux0ip4iWxZoFlMhIyRqocf2K32leVwzZH X-Received: by 2002:a05:6a00:18a5:b0:64d:5c4c:7e20 with SMTP id x37-20020a056a0018a500b0064d5c4c7e20mr15609640pfh.26.1685360289677; Mon, 29 May 2023 04:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685360289; cv=none; d=google.com; s=arc-20160816; b=czQlbT42f4NDUF9r6vtNtkcw3LaSKZy0RaZBhoAHyh1SxVGcyQTC4JiFLlalk1cqYi IE3WML7qcsdaez4lSyvQO53CSoCxAle3ccJlClyWZg2WkvRRxCWULkKqj7TSgp2VGGwU 3m6wlShxzWcF/xcSeJ7AlBTPn/hHIuWFzr2HHsSLq0FQ/AuHrVv0DnMgKdzbsM0RWP58 7jznvKoGpM1kTzxXLfHpmvjbQx2pygfAlT8aFit+V7uDDaaWYvQwp6HN2DmFRXzbyknA 3N3SjHp+1wV+0Sfj/e/rEGqi0k0j3rTKuPB0JqvigmB/xYYgpR2WmhINWs8lIqyOybPd jcnw== 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=5bqeeWc/myARY7M6zJ6hvcbWqg8JkLV/tpb1msg4Npk=; b=WfttGjOis3FAcG3WolihexIrmRFyqR64mXa7q34QF19Jaq64/kr5vRbXCXV6UyYJ+i IuWcmO9UExL5tPFHOV/6E4QtrjwZrJbQdmolJ0xQUVw7/0mtcbs7dEJMJoDcBCwemdOD XNi5Ff3IwD6cG7rwNLIknOXRQGL4qL0vyfZ1XT3kwCPaQ73SfNNrhfSyufHcFOgrSYYz kCPwBJKZCRcuOOxqa4jVLjDhBXfJpJcmU2noy6HEgYqU4R3XDFEkEhQhQ7VYGAkmDIit J1h4wn0YJvR9g8p+A2dDkTtfZUTQkAIVdCxS8DiHCcXKx94RMtuc2M8q3yP6fWqar/Yp WsJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=HKAmWDQC; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=t3r+QgEL; 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 b124-20020a62cf82000000b0064140b05b6dsi44778pfg.228.2023.05.29.04.37.56; Mon, 29 May 2023 04:38: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=HKAmWDQC; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=t3r+QgEL; 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 S231605AbjE2LfY (ORCPT + 99 others); Mon, 29 May 2023 07:35:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231611AbjE2LfM (ORCPT ); Mon, 29 May 2023 07:35:12 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BE31E51 for ; Mon, 29 May 2023 04:34:43 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 811023200392; Mon, 29 May 2023 07:34:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 29 May 2023 07:34:35 -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=1685360075; x= 1685446475; bh=5bqeeWc/myARY7M6zJ6hvcbWqg8JkLV/tpb1msg4Npk=; b=H KAmWDQCQ+AJ4sQ1YYaBgVvuXP7lxrtfUdM5VJfEFSR4M1BepmcKEKUugFzPTeDZd Ua9L4A1p/9mq8W1bKZN3zU0UcDvEfPqyBHGIxkb0knawPxCxUFI2e7nQmFP77roa Ikl1ZAHD5JkHaZQGClxyY1sqoYjtxXskp9fHjSNPekomE67a19J86tRdERrK038Q NB3xWTA0NPojdENJe2EIDBibmlfjD71khNds49kY+NjHnpQxCaWG5dWSQBLqM01x aIBgK1VEAGMVziZKYo33O+Jll/ZDE5P5YlejekbHGpOYf21x3/SX3eLgmmn9x9q1 nIdCyYLmrFAQIYpWcrExw== 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=1685360075; x= 1685446475; bh=5bqeeWc/myARY7M6zJ6hvcbWqg8JkLV/tpb1msg4Npk=; b=t 3r+QgELfaKnKSwrAJLovPzeqK3t2MjB3ErsnuInlqwMOVbxtLsccay9jvGN90D0i 68X3cVd28U7sdeRNxMtlyONP8lk2HS8MDNSKi0UYJvwA/MDJcOJ2eihP3zv7jEjw 1JbWKL4WJWOnS+RpF5/DeH5/SHet3g49ajVbF5rIQE8JtKSvoltjMAy2RoWfO79s 8BBI2X8PcwcBdOQb76FRBPqeSGNlu2YaNgNjKBHAtaWEFeFlbnUPd6Ws+8JP4ire +eKnUzlx0Lz++Fg/83Xpo8/Km3DlR3gjEKh3ESs9OQOKXlVad9dwu9l3qDYbqCdo Lxc7Ket/HE4IwHOZgV+zA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:33 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: kunit-dev@googlegroups.com Subject: [PATCH v3 11/12] firewire: cdev: add new event to notify phy packet with time stamp Date: Mon, 29 May 2023 20:34:05 +0900 Message-Id: <20230529113406.986289-12-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767228350806141532?= X-GMAIL-MSGID: =?utf-8?q?1767228350806141532?= 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 640e5c05415a..c6ebf02e3d45 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.5. +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 13892016c266..d72705b49687 100644 --- a/include/uapi/linux/firewire-cdev.h +++ b/include/uapi/linux/firewire-cdev.h @@ -49,6 +49,8 @@ /* available since kernel version 6.5 */ #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.5 */ struct fw_cdev_event_response2 response2; /* added in 6.5 */ + struct fw_cdev_event_phy_packet2 phy_packet2; /* added in 6.5 */ }; /* available since kernel version 2.6.22 */ @@ -547,6 +591,8 @@ union fw_cdev_event { * 6 (6.5) - 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 Mon May 29 11:34:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 100231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1457367vqr; Mon, 29 May 2023 05:03:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6fFtuYwKeFO6LiTXPtgB/O0mBFLdTwyGKbT74jJEAyJI3svVacHkPXVKL4pzqSBblmkWTV X-Received: by 2002:a05:6a20:9388:b0:110:f66c:a0e1 with SMTP id x8-20020a056a20938800b00110f66ca0e1mr3800688pzh.14.1685361803189; Mon, 29 May 2023 05:03:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685361803; cv=none; d=google.com; s=arc-20160816; b=hz7JEHVKvU9pO4Kra3gTx/IBsN97MPSI9BrskpRtLCcJylGnsbyA4UtqMJCupCSxCr TLQ2aTODV+bYcKO0LkvCYi2k0IhjXtKhE5pv1/HxHo2vErWScTzbaOfx+OtDYN8Ou4SM 5vkMT7IFTYX3ci7e4VHyEwNXJganfBXW84LXExNdzXnuN6neei4rCOMd0fZAVbshad4X qnF8roqEo9L2dzLqwU+uVKla3San6xzOnz78RXfWVx+VhiZ3OxAbnmvC3Nqi420baL8L m6sVuXn+h4LXzAaKmXUFHBoeEkS7nGrEBDB0EvlN27i3oaVi239Ws19QfF0DJMoJel9G wekw== 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=nH5UHrfUQb6kUt40pgWHNtDWLiDGYAp9KVVoIunCmw/L4WjE/u6UNdYvMOL3ZNbAhU 7BWH0XQjz4H/y6jkAcewW1WjHIip1mR1TOxL5/KxmmT+5rqfx14+Z9UeII7j8Gm7BkrF cnxBQEf7poEz57Zn6TqnZwqCnh/XqJ8VavMFwSKlbQ0Dy/gZIFBPMX/b4tx13K79xQR6 tr1YNFsg7YkDrSbazpu8fEPC86AWPWNOQz/xOo+H0OnpR7XuZ3CFyR9uYp7T7XxsSN1p BwRr3M5VhJYH9zwsQNEpsTgOKyBeN4iita4YAI7aGvr/hlC7cUwkn++f0HSSxMLcd6z0 hY/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=VLGXMcp4; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=WmWPabBh; 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 z10-20020aa7990a000000b0063f1cb928bdsi9298731pff.313.2023.05.29.05.03.10; Mon, 29 May 2023 05:03: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=VLGXMcp4; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=WmWPabBh; 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 S230342AbjE2Lfb (ORCPT + 99 others); Mon, 29 May 2023 07:35:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbjE2LfW (ORCPT ); Mon, 29 May 2023 07:35:22 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13A3DE0 for ; Mon, 29 May 2023 04:34:55 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 8C4DF320093D; Mon, 29 May 2023 07:34:37 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 29 May 2023 07:34:37 -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=1685360077; x= 1685446477; bh=CwMQ3mRgLz5XKiLhS8Bwc8Qm3NwjUti4uZQkCUexV3s=; b=V LGXMcp4ht63Clh35SxVozb6VFsiRHdaUNdo/RlE5pwuoyuK5Z6Tt+29HiJD+02TV kJ7TwOw3ZErysVCDPK1NlBfWygR82xnO6BV5BpQDlUkpix5qvKYiTgfen+jqL/4U UfN6qd0+6MCyRzWMHoJRl6q8Lkhc+88ioxOpVju37vEIlgBgVM3/dbq65fnWSZSJ bwE05tV545c/noUtZVdbN/Dh8n8sK/QiU3qyFRRxw26qVEW7RCPz2mKOG3jc2Z4z 6rq3e5A+7wQkEL7H92nrJAY5PsEKzNgmNH/ijEXfIy4UZxF4dleT+Vhrn79zcrA2 7G0tZTMguGXxv5JAfhGiQ== 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=1685360077; x=1685446477; bh=C wMQ3mRgLz5XKiLhS8Bwc8Qm3NwjUti4uZQkCUexV3s=; b=WmWPabBhTVuCAushw 3v5jJwLROWfCyXLe3wqDCLrgheYHcLC+06904VXoc0+ufYc8nJnvBCLts29SiQkN XQSOL3BI/LpE2F9maHT4Ukk9gk8/74vSTie2bWLi9KfWVQFmqFIyY/cpzmXjAy+a AUxRdTXOnl9cdNL4xK+m253WGeinqk6JSCZmZSNBoLsrv7hPpPNj4RkV6hiFEsz6 PipHBRo8LCm8wP0hPUZ0V0tcO84nKIaISzAi24sDiWzNmq9UyCEpy79pem1TK4Gv xhxmQ3Dvp7jQqDob4BM8Q/9gL6D1F+143feO/EOkL4dTe6Te+iV/eFWlksEwc+k0 CFNOA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekhedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 May 2023 07:34:36 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 12/12] firewire: cdev: implement new event relevant to phy packet with time stamp Date: Mon, 29 May 2023 20:34:06 +0900 Message-Id: <20230529113406.986289-13-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529113406.986289-1-o-takashi@sakamocchi.jp> References: <20230529113406.986289-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,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767229937883012080?= X-GMAIL-MSGID: =?utf-8?q?1767229937883012080?= 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);