From nobody Thu Feb 12 23:08:57 2026 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5FFB1607B9 for ; Wed, 5 Jun 2024 23:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631525; cv=none; b=iSOxgHD6GhBBzl4M7pyLXE1rvaAyumt5otbwVA9l6VKSGkXNZ2u/w6T+TNntDgK2pwUQJDgoxlnaFIH7DBupuMwSlXgwBQcEEcXhcg7goIaCZnYxm3hOMfwPF8mKAlzeV05sv6KN1MpQ27e2fYcnaBRRBLPRkTlNOgxJXqht9Fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631525; c=relaxed/simple; bh=j+hFn2QjRtNbQi2JXNDC2xNSexaHta7Qh5NFU0AsFDY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CvmDn0UwurClvysttSdCR9Vycs1xpU61xIdjKOMbbAhoisv48hblIuYEUvTiarumgbyJrIy9uo9JG5P/i+5I6mJ9GaolYn1pYkSQ1Hdw9WMk6pSx2WwlMrQDw+/LMuHuiUKYie/sLsCHozwUpterEvnAiyuY8BWeTVZZt5oCNO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=IbaCDoD/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=N8LOSN+f; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="IbaCDoD/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="N8LOSN+f" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id D2EE11800113; Wed, 5 Jun 2024 19:52:02 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 05 Jun 2024 19:52:03 -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:subject:subject:to:to; s=fm1; t=1717631522; x= 1717717922; bh=RyBiXfJ2B/10rFRCmtbmj2xM5yya0ZOnplKlH9vtagY=; b=I baCDoD/Tob1RlvGLAY4nbRB4goGZSe9pGPX4FIUH+bAbbHGf0B77XUZ/T1tsUvSP fsnLWwsXz0dAutl3oP71JU4sbjf7mPRnvMMwg8RffR6483aL1kXJ3FgNsFDu3LQl MiDnbvW2MErfUhqXXqTmPyH/iEPQWgCxdfx0nuXgNAKFMk0hyAmT8qMKYLoyPo8P pNDBhK9/Of4GWRPPv0c62+oR5MRoaeQCyqHOgDJ4O3gtuxD6+hE5iXkTZqOecrdE hUnqYFxvcmTy39DH1b7weGakUNwZsq7Y4A4qG4QsDtbf5x0WAQSugUm9QTH6el/7 afGERkWPcfMmhET6hfJCA== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631522; x= 1717717922; bh=RyBiXfJ2B/10rFRCmtbmj2xM5yya0ZOnplKlH9vtagY=; b=N 8LOSN+fV8lFXRvLfvp9P12GkZx/s3Km7TOR4S6CRHFR+Uq4XBGwUesZMv3vg4hav Z7+RakzPbPL3glV7BBJGua6aJe//mV6OFktKLNNKNsuAAVeDUBBWD6bc80joZ6g/ oVGd6rpBz4U6ylvIvcjJaKrciLIGBsDes8dRK7mEEJdFdDS2FfBMLrj4UX/F88KR Y2/KMq2fzvfYr9bn7vS1tF7R7KKoym7tb/fFFmlK0O36WHTc3uU+mv0406CfwRTr j+AWNYlNi8JBVu8CGO79OAX56op3wy/OjH/rP4feJZ0xdgZX+okKz4Fk/t3QNOvi YRYgnATeUGWuIwguU13UQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeeugfevtd efhfeffeeuudduhfekhffgveejfeeiiefftdethfduudevjeekveffleenucffohhmrghi nhepthgvshhtrghnhihthhhinhhgrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhi rdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:01 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 01/11] firewire: core: add enumerator of self ID sequences and its KUnit test Date: Thu, 6 Jun 2024 08:51:45 +0900 Message-ID: <20240605235155.116468-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the state of bus reset finishes, 1394 OHCI driver constructs self ID sequences, then it calls fw_core_handle_bus_reset() in core function. The core function enumerates the self ID sequences to build bus topology. This commit adds a structure and some helper functions for the enumeration, and adds a KUnit test suite to ensure its expected behaviour. Signed-off-by: Takashi Sakamoto --- drivers/firewire/.kunitconfig | 1 + drivers/firewire/Kconfig | 15 ++++ drivers/firewire/Makefile | 1 + drivers/firewire/phy-packet-definitions.h | 78 ++++++++++++++++++ .../firewire/self-id-sequence-helper-test.c | 79 +++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 drivers/firewire/phy-packet-definitions.h create mode 100644 drivers/firewire/self-id-sequence-helper-test.c diff --git a/drivers/firewire/.kunitconfig b/drivers/firewire/.kunitconfig index 60d9e7c35417..74259204fcdd 100644 --- a/drivers/firewire/.kunitconfig +++ b/drivers/firewire/.kunitconfig @@ -4,3 +4,4 @@ CONFIG_FIREWIRE=3Dy CONFIG_FIREWIRE_KUNIT_UAPI_TEST=3Dy CONFIG_FIREWIRE_KUNIT_DEVICE_ATTRIBUTE_TEST=3Dy CONFIG_FIREWIRE_KUNIT_PACKET_SERDES_TEST=3Dy +CONFIG_FIREWIRE_KUNIT_SELF_ID_SEQUENCE_HELPER_TEST=3Dy diff --git a/drivers/firewire/Kconfig b/drivers/firewire/Kconfig index 869598b20e3a..49ba692d17d8 100644 --- a/drivers/firewire/Kconfig +++ b/drivers/firewire/Kconfig @@ -66,6 +66,21 @@ config FIREWIRE_KUNIT_PACKET_SERDES_TEST For more information on KUnit and unit tests in general, refer to the KUnit documentation in Documentation/dev-tools/kunit/. =20 +config FIREWIRE_KUNIT_SELF_ID_SEQUENCE_HELPER_TEST + tristate "KUnit tests for helpers of self ID sequence" if !KUNIT_ALL_TESTS + depends on FIREWIRE && KUNIT + default KUNIT_ALL_TESTS + help + This builds the KUnit tests for helpers of self ID sequence. + + 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 75c47d046925..21b975e0a387 100644 --- a/drivers/firewire/Makefile +++ b/drivers/firewire/Makefile @@ -18,3 +18,4 @@ obj-$(CONFIG_PROVIDE_OHCI1394_DMA_INIT) +=3D init_ohci139= 4_dma.o =20 obj-$(CONFIG_FIREWIRE_KUNIT_UAPI_TEST) +=3D uapi-test.o obj-$(CONFIG_FIREWIRE_KUNIT_PACKET_SERDES_TEST) +=3D packet-serdes-test.o +obj-$(CONFIG_FIREWIRE_KUNIT_SELF_ID_SEQUENCE_HELPER_TEST) +=3D self-id-seq= uence-helper-test.o diff --git a/drivers/firewire/phy-packet-definitions.h b/drivers/firewire/p= hy-packet-definitions.h new file mode 100644 index 000000000000..479bb3431afb --- /dev/null +++ b/drivers/firewire/phy-packet-definitions.h @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// +// phy-packet-definitions.h - The definitions of phy packet for IEEE 1394. +// +// Copyright (c) 2024 Takashi Sakamoto + +#ifndef _FIREWIRE_PHY_PACKET_DEFINITIONS_H +#define _FIREWIRE_PHY_PACKET_DEFINITIONS_H + +#define SELF_ID_EXTENDED_MASK 0x00800000 +#define SELF_ID_EXTENDED_SHIFT 23 +#define SELF_ID_MORE_PACKETS_MASK 0x00000001 +#define SELF_ID_MORE_PACKETS_SHIFT 0 + +#define SELF_ID_EXTENDED_SEQUENCE_MASK 0x00700000 +#define SELF_ID_EXTENDED_SEQUENCE_SHIFT 20 + +#define SELF_ID_SEQUENCE_MAXIMUM_QUADLET_COUNT 4 + +static inline bool phy_packet_self_id_get_extended(u32 quadlet) +{ + return (quadlet & SELF_ID_EXTENDED_MASK) >> SELF_ID_EXTENDED_SHIFT; +} + +static inline bool phy_packet_self_id_get_more_packets(u32 quadlet) +{ + return (quadlet & SELF_ID_MORE_PACKETS_MASK) >> SELF_ID_MORE_PACKETS_SHIF= T; +} + +static inline unsigned int phy_packet_self_id_extended_get_sequence(u32 qu= adlet) +{ + return (quadlet & SELF_ID_EXTENDED_SEQUENCE_MASK) >> SELF_ID_EXTENDED_SEQ= UENCE_SHIFT; +} + +struct self_id_sequence_enumerator { + const u32 *cursor; + unsigned int quadlet_count; +}; + +static inline const u32 *self_id_sequence_enumerator_next( + struct self_id_sequence_enumerator *enumerator, unsigned int *quadlet_co= unt) +{ + const u32 *self_id_sequence, *cursor; + u32 quadlet; + unsigned int count; + unsigned int sequence; + + if (enumerator->cursor =3D=3D NULL || enumerator->quadlet_count =3D=3D 0) + return ERR_PTR(-ENODATA); + cursor =3D enumerator->cursor; + count =3D 1; + + quadlet =3D *cursor; + sequence =3D 0; + while (phy_packet_self_id_get_more_packets(quadlet)) { + if (count >=3D enumerator->quadlet_count || + count >=3D SELF_ID_SEQUENCE_MAXIMUM_QUADLET_COUNT) + return ERR_PTR(-EPROTO); + ++cursor; + ++count; + quadlet =3D *cursor; + + if (!phy_packet_self_id_get_extended(quadlet) || + sequence !=3D phy_packet_self_id_extended_get_sequence(quadlet)) + return ERR_PTR(-EPROTO); + ++sequence; + } + + *quadlet_count =3D count; + self_id_sequence =3D enumerator->cursor; + + enumerator->cursor +=3D count; + enumerator->quadlet_count -=3D count; + + return self_id_sequence; +} + +#endif // _FIREWIRE_PHY_PACKET_DEFINITIONS_H diff --git a/drivers/firewire/self-id-sequence-helper-test.c b/drivers/fire= wire/self-id-sequence-helper-test.c new file mode 100644 index 000000000000..e8a435e20241 --- /dev/null +++ b/drivers/firewire/self-id-sequence-helper-test.c @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// +// self-id-sequence-helper-test.c - An application of Kunit to test helper= s of self ID sequence. +// +// Copyright (c) 2024 Takashi Sakamoto + +#include + +#include "phy-packet-definitions.h" + +static void test_self_id_sequence_enumerator_valid(struct kunit *test) +{ + static const u32 valid_sequences[] =3D { + 0x00000000, + 0x00000001, 0x00800000, + 0x00000001, 0x00800001, 0x00900000, + 0x00000000, + }; + struct self_id_sequence_enumerator enumerator; + const u32 *entry; + unsigned int quadlet_count; + + enumerator.cursor =3D valid_sequences; + enumerator.quadlet_count =3D ARRAY_SIZE(valid_sequences); + + entry =3D self_id_sequence_enumerator_next(&enumerator, &quadlet_count); + KUNIT_EXPECT_PTR_EQ(test, entry, &valid_sequences[0]); + KUNIT_EXPECT_EQ(test, quadlet_count, 1); + KUNIT_EXPECT_EQ(test, enumerator.quadlet_count, 6); + + entry =3D self_id_sequence_enumerator_next(&enumerator, &quadlet_count); + KUNIT_EXPECT_PTR_EQ(test, entry, &valid_sequences[1]); + KUNIT_EXPECT_EQ(test, quadlet_count, 2); + KUNIT_EXPECT_EQ(test, enumerator.quadlet_count, 4); + + entry =3D self_id_sequence_enumerator_next(&enumerator, &quadlet_count); + KUNIT_EXPECT_PTR_EQ(test, entry, &valid_sequences[3]); + KUNIT_EXPECT_EQ(test, quadlet_count, 3); + KUNIT_EXPECT_EQ(test, enumerator.quadlet_count, 1); + + entry =3D self_id_sequence_enumerator_next(&enumerator, &quadlet_count); + KUNIT_EXPECT_PTR_EQ(test, entry, &valid_sequences[6]); + KUNIT_EXPECT_EQ(test, quadlet_count, 1); + KUNIT_EXPECT_EQ(test, enumerator.quadlet_count, 0); + + entry =3D self_id_sequence_enumerator_next(&enumerator, &quadlet_count); + KUNIT_EXPECT_EQ(test, PTR_ERR(entry), -ENODATA); +} + +static void test_self_id_sequence_enumerator_invalid(struct kunit *test) +{ + static const u32 invalid_sequences[] =3D { + 0x00000001, + }; + struct self_id_sequence_enumerator enumerator; + const u32 *entry; + unsigned int count; + + enumerator.cursor =3D invalid_sequences; + enumerator.quadlet_count =3D ARRAY_SIZE(invalid_sequences); + + entry =3D self_id_sequence_enumerator_next(&enumerator, &count); + KUNIT_EXPECT_EQ(test, PTR_ERR(entry), -EPROTO); +} + +static struct kunit_case self_id_sequence_helper_test_cases[] =3D { + KUNIT_CASE(test_self_id_sequence_enumerator_valid), + KUNIT_CASE(test_self_id_sequence_enumerator_invalid), + {} +}; + +static struct kunit_suite self_id_sequence_helper_test_suite =3D { + .name =3D "self-id-sequence-helper", + .test_cases =3D self_id_sequence_helper_test_cases, +}; +kunit_test_suite(self_id_sequence_helper_test_suite); + +MODULE_DESCRIPTION("Unit test suite for helpers of self ID sequence"); +MODULE_LICENSE("GPL"); --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C14C1168C21 for ; Wed, 5 Jun 2024 23:52:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631527; cv=none; b=COOfVfDBb26tfCrrUuoqaRy3+U7MfTbd+h1qE+LYxvRLGeZehGwi+w6F2Btr5hdU3mtEhOtQUB4lLGtMH0JVqkkjVv+Yfa8Q/nBbEi57+vAQWqNoXqBJOPTmWd6v9mNGUFsN6xPH1foip0O4bzrjEfNn2qPfao/1AvOtccBKnho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631527; c=relaxed/simple; bh=9QOTyVMAdy8uCsXMMw3kF6ZJlcRvN7TSTx4DhNKqy1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r3e5u6N0nDWwlyvW9lOcuM2j9lcyiQmaAHwixQf9znLqeP7cwu0AoOuya/YIDTphvSVH2kfX2jeF1NsosZrf1UwK8eVVQqk04d/pq+ynregGlNtwJZyc8pk5Gf1e0XenS40HpmWVgWJigrskBQIquK7XYrWgHOroUJDC7hgj+ZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=GCm0nEee; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WQxoqwk5; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="GCm0nEee"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WQxoqwk5" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id DCA641C0005B; Wed, 5 Jun 2024 19:52:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 05 Jun 2024 19:52:05 -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:subject:subject:to:to; s=fm1; t=1717631524; x= 1717717924; bh=1mJaF1de45yn5OE6CI3ft4NIkPoDExHyNENgh8KNRtk=; b=G Cm0nEeeWOPVJJJarcYIdirZhBgmJOooYl5l++ptVObMeO+nG8NaFmhY0vNH0ocHA Cjv5GEcNAXXQy4jID/B5kxNAc0DE9Z7axk8xgamfHjurv0kH/yAwTHiHeXc2GTcX GHRqnXJ7B+L2Q0F4jdcv1J6rGEem45aUfINNH1leVkKB6hjVtmxVBeSwinUod23R IfM/cP42W2E4Y07+2rJXLP04HMFZ8KfKBgTW9s5/Tu/RWOJcUl1JmRs8gtwYSQ/K bwfrZjYuJKeqsW6GTkX1eUfcNnaP/dXlqYMZYbUER0zPRveacTDuXkjT5jNrYLKb nJtXoQZZ9MfhLi46yw8uw== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631524; x= 1717717924; bh=1mJaF1de45yn5OE6CI3ft4NIkPoDExHyNENgh8KNRtk=; b=W Qxoqwk5y22n8p8hlDt4gEp3GsFNpNQNZxxqtZcCo9rmNeTQ7lfK0odLRAmrIZcr8 0CMZo7mJZ7eqXjrwqk2LF4gzKPkDe//O6IDoMRH8nwtRufhaNdXO26odTVoiZUyA +NBy769xfHzpYnbJ0d7ig7AxVUKJKOm/RqZHwJDRX/oofFGqZv1Fol5GCShn9sYQ apT5sdLeXK3NVYzQ3ILsqeFVxsko6YrjcjKDnTUh0+0uQk6VTHgkPT96on5DsZ9W KImOaIJNaKzZkROXbmC16qyZqNzDXjO7EJJCN9ZiNgSPZRzgMEZ3od8/lvtC5Nyx OtihRMZjy5mxGJAqdxQlQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:03 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 02/11] firewire: core: add helper function to handle port status from self ID sequence and its KUnit test Date: Thu, 6 Jun 2024 08:51:46 +0900 Message-ID: <20240605235155.116468-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The self ID sequence delivers the information about the state of port. This commit adds some enumerations to express the state of port, and some helper functions to handle the state. It adds a KUnit test for them, too. Signed-off-by: Takashi Sakamoto --- drivers/firewire/phy-packet-definitions.h | 43 +++++++++++ .../firewire/self-id-sequence-helper-test.c | 73 +++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/drivers/firewire/phy-packet-definitions.h b/drivers/firewire/p= hy-packet-definitions.h index 479bb3431afb..4ba8b18aa993 100644 --- a/drivers/firewire/phy-packet-definitions.h +++ b/drivers/firewire/phy-packet-definitions.h @@ -15,6 +15,8 @@ #define SELF_ID_EXTENDED_SEQUENCE_MASK 0x00700000 #define SELF_ID_EXTENDED_SEQUENCE_SHIFT 20 =20 +#define SELF_ID_PORT_STATUS_MASK 0x3 + #define SELF_ID_SEQUENCE_MAXIMUM_QUADLET_COUNT 4 =20 static inline bool phy_packet_self_id_get_extended(u32 quadlet) @@ -75,4 +77,45 @@ static inline const u32 *self_id_sequence_enumerator_nex= t( return self_id_sequence; } =20 +enum phy_packet_self_id_port_status { + PHY_PACKET_SELF_ID_PORT_STATUS_NONE =3D 0, + PHY_PACKET_SELF_ID_PORT_STATUS_NCONN =3D 1, + PHY_PACKET_SELF_ID_PORT_STATUS_PARENT =3D 2, + PHY_PACKET_SELF_ID_PORT_STATUS_CHILD =3D 3, +}; + +static inline unsigned int self_id_sequence_get_port_capacity(unsigned int= quadlet_count) +{ + return quadlet_count * 8 - 5; +} + +static inline enum phy_packet_self_id_port_status self_id_sequence_get_por= t_status( + const u32 *self_id_sequence, unsigned int quadlet_count, unsigned int po= rt_index) +{ + unsigned int index, shift; + + index =3D (port_index + 5) / 8; + shift =3D 16 - ((port_index + 5) % 8) * 2; + + if (index < quadlet_count && index < SELF_ID_SEQUENCE_MAXIMUM_QUADLET_COU= NT) + return (self_id_sequence[index] >> shift) & SELF_ID_PORT_STATUS_MASK; + + return PHY_PACKET_SELF_ID_PORT_STATUS_NONE; +} + +static inline void self_id_sequence_set_port_status(u32 *self_id_sequence,= unsigned int quadlet_count, + unsigned int port_index, + enum phy_packet_self_id_port_status status) +{ + unsigned int index, shift; + + index =3D (port_index + 5) / 8; + shift =3D 16 - ((port_index + 5) % 8) * 2; + + if (index < quadlet_count) { + self_id_sequence[index] &=3D ~(SELF_ID_PORT_STATUS_MASK << shift); + self_id_sequence[index] |=3D status << shift; + } +} + #endif // _FIREWIRE_PHY_PACKET_DEFINITIONS_H diff --git a/drivers/firewire/self-id-sequence-helper-test.c b/drivers/fire= wire/self-id-sequence-helper-test.c index e8a435e20241..eed7a2294e64 100644 --- a/drivers/firewire/self-id-sequence-helper-test.c +++ b/drivers/firewire/self-id-sequence-helper-test.c @@ -63,9 +63,82 @@ static void test_self_id_sequence_enumerator_invalid(str= uct kunit *test) KUNIT_EXPECT_EQ(test, PTR_ERR(entry), -EPROTO); } =20 +static void test_self_id_sequence_get_port_status(struct kunit *test) +{ + static const u32 expected[] =3D { + 0x000000e5, + 0x00839e79, + 0x0091e79d, + 0x00a279e4, + }; + u32 quadlets [] =3D { + 0x00000001, + 0x00800001, + 0x00900001, + 0x00a00000, + }; + enum phy_packet_self_id_port_status port_status[28]; + unsigned int port_capacity; + unsigned int port_index; + + KUNIT_ASSERT_EQ(test, ARRAY_SIZE(expected), ARRAY_SIZE(quadlets)); + + // With an extra port. + port_capacity =3D self_id_sequence_get_port_capacity(ARRAY_SIZE(expected)= ) + 1; + KUNIT_ASSERT_EQ(test, port_capacity, ARRAY_SIZE(port_status)); + + for (port_index =3D 0; port_index < port_capacity; ++port_index) { + port_status[port_index] =3D + self_id_sequence_get_port_status(expected, ARRAY_SIZE(expected), port_i= ndex); + self_id_sequence_set_port_status(quadlets, ARRAY_SIZE(quadlets), port_in= dex, + port_status[port_index]); + } + + // Self ID zero. + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[0= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 1]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[2= ]); + + // Self ID one. + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[3= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 4]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[5= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[6= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 7]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[8= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[9= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 10]); + + // Self ID two. + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[1= 1]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[1= 2]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 13]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[1= 4]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[1= 5]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 16]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[1= 7]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[1= 8]); + + // Self ID three. + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 19]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[2= 0]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[2= 1]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 22]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[2= 3]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[2= 4]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 25]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[2= 6]); + + // Our of order. + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NONE, port_status[27= ]); + + KUNIT_EXPECT_MEMEQ(test, quadlets, expected, sizeof(expected)); +} + static struct kunit_case self_id_sequence_helper_test_cases[] =3D { KUNIT_CASE(test_self_id_sequence_enumerator_valid), KUNIT_CASE(test_self_id_sequence_enumerator_invalid), + KUNIT_CASE(test_self_id_sequence_get_port_status), {} }; =20 --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5E0416ABCE for ; Wed, 5 Jun 2024 23:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631529; cv=none; b=kqNcXYehAC60vowE74sgiRmSOA37pbtPs0nqhta/wp10N6cfdkFDKiZ0XppIe8Yh/69XUDU/+H8WrbAJ40dnp3GIxS73TSN3al+1yAAXolSPvgX01+Quk10gN4bksY83YpG5weg7rNGdv30JxkgFFzLgIi5EvL4gwG608sDaqak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631529; c=relaxed/simple; bh=NgEEf4d684CncBM/JTi6jXqL40cqTGcloTccTf3mAb0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZkDfqWqWBZaMAuwsxF4acAM4KMBdxaNSX3tEBzWoypRCpLBk26G3oooW1XheBrA9UIQ1uKfwerJCm/QwYjUMqi9n/j63CNigi9eKFL5F8PfHS5+Zf7C22yroHCei0RXb/AZvYkaH8bILEziIZR86Ho6IPECabQVknhV7tx3MO/A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=XvrMfI6y; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ef9PfqWb; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="XvrMfI6y"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ef9PfqWb" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id E8CC91800124; Wed, 5 Jun 2024 19:52:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 05 Jun 2024 19:52:07 -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:subject:subject:to:to; s=fm1; t=1717631526; x= 1717717926; bh=V1TVjKe7dwYJE6Q/S0G6qvmCcYsfTJyJOHYYPXE4GI4=; b=X vrMfI6ysLPMQFljgayKpbPcIch6zg5Z8ksfXRxK64JCxZ//Zh52K6iWLQmgrGoUb XstwWrhhfRqEgGwEIEYtLMZskNup7Ocmo9SVlsdgihwY6WxyLuIUBTg3OUxh395b /nw57UGAHKhzori+igEYOt4sBrYc8VOI1Q47x/fMlBbZH/g6SX5Y0Ced7P6sllzR GQM5pltvxNw6260GHjfKcIH6f4/2UnKQyxcxypw1qPPgxh3MJfrfpYdp13aAexnT Fydj2fcdKPshYl9UMBLXYD/iXMYZJgtNpI5deAS57pkkQ5ib77glnnkAvjMpTAOv qedUTe3nYxypH48i7UjTg== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631526; x= 1717717926; bh=V1TVjKe7dwYJE6Q/S0G6qvmCcYsfTJyJOHYYPXE4GI4=; b=E f9PfqWbTK3+sOYwRfk00w0CBqy+SMZHTvLBVYqNQ4W06//vgi/6sFig9CZ43092N agT2iE259sXNWMWXaqVwK/IS+mOXw1wUQWmRlEDtvnNl1J+01e/C/w3dVLj459EJ Efo3vBxcnom6EcvWGasPnEL9eJzvEEmhID8mNj0mn7wAsILFRFna8WoLfqJm6eRn LsaxsOHGrzA5y/OjHCQhBRiInRnkvrZJnPzHC1qBXbnKuXq34XPpGBEV5PCDHK76 x15yKQsXOVly0fDWKZTRoSj794NEfDeInjl28qQRp4d5jIauHh7Dx96qULM0CNTI 9M6jOksqerRflWfTbwj1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:05 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 03/11] firewire: core: minor code refactoring for topology builder Date: Thu, 6 Jun 2024 08:51:47 +0900 Message-ID: <20240605235155.116468-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Current implementation to build tree according to self ID sequences has the rest to be refactored; e.g. putting local variables into block. This commit is for the purpose. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-topology.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topol= ogy.c index 837cc44d8d9f..6a039293ee63 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -38,14 +38,11 @@ #define SELFID_PORT_NCONN 0x1 #define SELFID_PORT_NONE 0x0 =20 -static u32 *count_ports(u32 *sid, int *total_port_count, int *child_port_c= ount) +static const u32 *count_ports(const u32 *sid, int *total_port_count, int *= child_port_count) { u32 q; int port_type, shift, seq; =20 - *total_port_count =3D 0; - *child_port_count =3D 0; - shift =3D 6; q =3D *sid; seq =3D 0; @@ -89,7 +86,7 @@ static u32 *count_ports(u32 *sid, int *total_port_count, = int *child_port_count) } } =20 -static int get_port_type(u32 *sid, int port_index) +static int get_port_type(const u32 *sid, int port_index) { int index, shift; =20 @@ -169,13 +166,12 @@ static inline struct fw_node *fw_node(struct list_hea= d *l) * internally consistent. On success this function returns the * fw_node corresponding to the local card otherwise NULL. */ -static struct fw_node *build_tree(struct fw_card *card, - u32 *sid, int self_id_count) +static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, in= t self_id_count) { struct fw_node *node, *child, *local_node, *irm_node; - struct list_head stack, *h; - u32 *next_sid, *end, q; - int i, port_count, child_port_count, phy_id, parent_count, stack_depth; + struct list_head stack; + const u32 *end; + int phy_id, stack_depth; int gap_count; bool beta_repeaters_present; =20 @@ -190,8 +186,15 @@ static struct fw_node *build_tree(struct fw_card *card, beta_repeaters_present =3D false; =20 while (sid < end) { - next_sid =3D count_ports(sid, &port_count, &child_port_count); + int port_count =3D 0; + int child_port_count =3D 0; + int parent_count =3D 0; + const u32 *next_sid; + u32 q; + struct list_head *h; + int i; =20 + next_sid =3D count_ports(sid, &port_count, &child_port_count); if (next_sid =3D=3D NULL) { fw_err(card, "inconsistent extended self IDs\n"); return NULL; --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D955516C864 for ; Wed, 5 Jun 2024 23:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631532; cv=none; b=BnPJsC80s2xWEcKWmgZ4zGxo8cAwkrern2CrOkbzJoMFTNT6knzg8UCneVwGc8Z9kC0Y1BolJONTTlnvzIB/fy7zf4DFzGWDRzIdNMgooFg0Wc8rTG2ya+aiEDZKG0kcmy1oGCMZlQDQp4PXap4L6Lf+FOAHU23m5uYeGypO/sI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631532; c=relaxed/simple; bh=CcTJ2hXsAQcrYr0T8FwNXmr1zWjQFOatTtsGZ7PucoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DVCLY//zUSTykIgTiOlrOMr2kF+7iE/Rd5KQRWYYDNjLf3zawv0fGSIzYxGHXKNpNqxo/DTkw7xInKUXkA2/DEpmfyXCx3UkTtteUgZWrdOVq69nRvvgtWGH0kVIK1dkHcphJQR3fmXu7pK3eVmuB6TpA5ON7gsph2Yd01B9Z+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=ZchT7BhK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OsebbhZq; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="ZchT7BhK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OsebbhZq" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id EF056180012C; Wed, 5 Jun 2024 19:52:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 05 Jun 2024 19:52:09 -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:subject:subject:to:to; s=fm1; t=1717631528; x= 1717717928; bh=bWof0tvW+gB1Bs1dWeYtyZYYo8ZfFi7RpvNi77t2sIw=; b=Z chT7BhKOt27y3TKOHYIUMg0hooTAw2Uyqkf3nlGn3wTe8Bv60tQSC4rr7gIwMYX6 b3WoYDZPzQTRh9wTbBFNZ3fbPuRWA8WygjlcXGCnIear2oA5PwYsNQuY3Aqbjwg0 IZsZziYRrzNCzOMbyndGchTuiHGML6UsslxfP7tLuPe7DB/vgeJixmJHNT+J49t2 YP9Nl95hRFEwigziM/nJqwrYrVnYTBC05FlGyMpZ5cmd+i99KrGBJkGTvnH6g6xN W7MS1TqLn87jKQTTmRAL6mpVqdba6GgR7Dh7TMJ4kVq0ciIb0FZjZ78pRj7/te0N OvxEkjmBxKuJZds/V5WJQ== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631528; x= 1717717928; bh=bWof0tvW+gB1Bs1dWeYtyZYYo8ZfFi7RpvNi77t2sIw=; b=O sebbhZqZXNcq3iVeTaH+nChpBD1mTI8Sq7uOOv10+bxDC1DJYKlfDwqVoqrx1pjK p7z2uBCnUUERHbAbjN5nmidcaCjAgSRGO8N5UWp1oZHD/cr6k6+JpdQ/6pVWrASN 3g/suDQ49X7Gem5COz0EIRxYRmT8w05wgg5dzEU+dFMqHdmR+VDb4ux6Ktee8/DQ CkLTRoHCOLuD9YejUHaf+3tD19MCCD5Xfn9kqt5DLY1SqWfaBDeaUpLnHIa1d7Io W28sFtxQNf08SQj9T6ZeUB/G4XBghqEGEWIxhC933DadP2ldrcWacOEqAXkrrv3U nslMoR+enev1SuJqGZAQQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:07 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 04/11] firewire: ohci: minor code refactoring for self ID logging Date: Thu, 6 Jun 2024 08:51:48 +0900 Message-ID: <20240605235155.116468-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Current implementation to log self ID sequence has the rest to be refactored; e.g. moving translation-unit level variables to the dependent block. This commit is for the purpose. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index f6de0b3a9a55..0ef76cf7b328 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -437,22 +437,21 @@ static void log_irqs(struct fw_ohci *ohci, u32 evt) ? " ?" : ""); } =20 -static const char *speed[] =3D { - [0] =3D "S100", [1] =3D "S200", [2] =3D "S400", [3] =3D "beta", -}; -static const char *power[] =3D { - [0] =3D "+0W", [1] =3D "+15W", [2] =3D "+30W", [3] =3D "+45W", - [4] =3D "-3W", [5] =3D " ?W", [6] =3D "-3..-6W", [7] =3D "-3..-10W", -}; -static const char port[] =3D { '.', '-', 'p', 'c', }; - -static char _p(u32 *s, int shift) +static unsigned int _p(u32 *s, int shift) { - return port[*s >> shift & 3]; + return *s >> shift & 3; } =20 static void log_selfids(struct fw_ohci *ohci, int generation, int self_id_= count) { + static const char *const speed[] =3D { + [0] =3D "S100", [1] =3D "S200", [2] =3D "S400", [3] =3D "beta", + }; + static const char *const power[] =3D { + [0] =3D "+0W", [1] =3D "+15W", [2] =3D "+30W", [3] =3D "+45W", + [4] =3D "-3W", [5] =3D " ?W", [6] =3D "-3..-6W", [7] =3D "-3..-10W", + }; + static const char port[] =3D { '.', '-', 'p', 'c', }; u32 *s; =20 if (likely(!(param_debug & OHCI_PARAM_DEBUG_SELFIDS))) @@ -465,7 +464,10 @@ static void log_selfids(struct fw_ohci *ohci, int gene= ration, int self_id_count) if ((*s & 1 << 23) =3D=3D 0) ohci_notice(ohci, "selfID 0: %08x, phy %d [%c%c%c] %s gc=3D%d %s %s%s%s\n", - *s, *s >> 24 & 63, _p(s, 6), _p(s, 4), _p(s, 2), + *s, *s >> 24 & 63, + port[_p(s, 6)], + port[_p(s, 4)], + port[_p(s, 2)], speed[*s >> 14 & 3], *s >> 16 & 63, power[*s >> 8 & 7], *s >> 22 & 1 ? "L" : "", *s >> 11 & 1 ? "c" : "", *s & 2 ? "i" : ""); @@ -473,8 +475,14 @@ static void log_selfids(struct fw_ohci *ohci, int gene= ration, int self_id_count) ohci_notice(ohci, "selfID n: %08x, phy %d [%c%c%c%c%c%c%c%c]\n", *s, *s >> 24 & 63, - _p(s, 16), _p(s, 14), _p(s, 12), _p(s, 10), - _p(s, 8), _p(s, 6), _p(s, 4), _p(s, 2)); + port[_p(s, 16)], + port[_p(s, 14)], + port[_p(s, 12)], + port[_p(s, 10)], + port[_p(s, 8)], + port[_p(s, 6)], + port[_p(s, 4)], + port[_p(s, 2)]); } =20 static const char *evts[] =3D { --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 034B516D4C0 for ; Wed, 5 Jun 2024 23:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631533; cv=none; b=ee1wjZ699AqtcdlYfAKMxjqu+cJfuhBmhKDMW2OrSgtd9hJ72a4DXx7vopQcTEmKBnGbOhSSJEG3LlT/izBZxgdd1CsYPXVQoB0u4eAB/vBf7QdKQ61/h8AYYcZ4ATjmXgO+ty3zh5kOuN6XcI8xAIW7vC1/nzQRteFBrZMYgrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631533; c=relaxed/simple; bh=/5xshN40U+7I8IHbkcf+CZCJ0n9pk0XHPKGSe2YUy5o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cXRqWg12CCqsG9UrkKYIAaPmy2RaJmEWfRPVagW3qmWtvAx4uGpoVoKle5Yvc/dm2H2efjVPJWGzH2OjDgMZiFrlkzFUnH6utlEDVz3Pw7YF2fB4LmrVTkHK5zGPngRlxiWFJT0dMojFgAUMFEJP53OsQylqC1rwsWHnXHEFKGA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=KobBh3wM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cdmgG+Ct; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="KobBh3wM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cdmgG+Ct" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 2040F1C000F9; Wed, 5 Jun 2024 19:52:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 05 Jun 2024 19:52:11 -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:subject:subject:to:to; s=fm1; t=1717631530; x= 1717717930; bh=H+eY1/AV2QPj0CXHcejIiaTss5Dil3imgP/c8kjn9RY=; b=K obBh3wMy/aNAP5mRghBPI5f7n+8W93AW7I6MlXz3Cco9POoNrO52gOJPZwRLnUi7 FFANvRZEAhMWF9ODZUBODUm6euBB1TkYWmXXoM89BqCbwqmz/8UfrMfCyMHaNTx7 7iwYTJ+OX+9f4K/+J61z8owLrlTs+7VSTmzSnWUCw46d0yFwOmy4b2c7rwYWy7rl 5Z+vtFl22WpZKhkkGuRCJQM+Li8PkzplGDS+mEOiYO4nwM6ODcIgMk/fp/nxPkLU dicZgBuA650OBS7bNXZ+sarIG4W4zxqFs8NlcpVugr1FWo+Rv5rugZxprbMEk9Gk DJE+YGZvwlxDjzeSDJs5A== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631530; x= 1717717930; bh=H+eY1/AV2QPj0CXHcejIiaTss5Dil3imgP/c8kjn9RY=; b=c dmgG+Ct4uI1ox70rhZ+fD0OQSOhYFdFD8/36tT+noXmIC/9Du9wjqOveTcEwyYoa Dl8ls/4/uZoAZsI/E6AprzOWGUM+2fFPoYv7EA4/OPa0t2mCDlcuRWnfKCE+pjNl 3I3JNWdkwDg1bUNoTv/ohIl+TRoMy1n6G8CjrX//x+9EUfd5yluBxZ1tYYV6eehl zf/YAj2R0euqWZWB9Wi3oeBPzZxdzK+d5jTVswIwtd5+ovPEKKAIi9i+QyOL6Gqy lwY1I59+8HTGZXk8xrw1GwBS3GhBlPZd2vAB6PXLfzBBpUszHJKx06HUTS08STDu wrRHnrvwTCtefBnoyLUoA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:09 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 05/11] firewire: core: use helper functions for self ID sequence Date: Thu, 6 Jun 2024 08:51:49 +0900 Message-ID: <20240605235155.116468-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit replaces the existing implementation with the helper functions for self ID sequence. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-topology.c | 189 +++++++++++-------------------- 1 file changed, 69 insertions(+), 120 deletions(-) diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topol= ogy.c index 6a039293ee63..999ba2b121cd 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -20,80 +20,15 @@ #include =20 #include "core.h" +#include "phy-packet-definitions.h" #include =20 #define SELF_ID_PHY_ID(q) (((q) >> 24) & 0x3f) -#define SELF_ID_EXTENDED(q) (((q) >> 23) & 0x01) #define SELF_ID_LINK_ON(q) (((q) >> 22) & 0x01) #define SELF_ID_GAP_COUNT(q) (((q) >> 16) & 0x3f) #define SELF_ID_PHY_SPEED(q) (((q) >> 14) & 0x03) #define SELF_ID_CONTENDER(q) (((q) >> 11) & 0x01) #define SELF_ID_PHY_INITIATOR(q) (((q) >> 1) & 0x01) -#define SELF_ID_MORE_PACKETS(q) (((q) >> 0) & 0x01) - -#define SELF_ID_EXT_SEQUENCE(q) (((q) >> 20) & 0x07) - -#define SELFID_PORT_CHILD 0x3 -#define SELFID_PORT_PARENT 0x2 -#define SELFID_PORT_NCONN 0x1 -#define SELFID_PORT_NONE 0x0 - -static const u32 *count_ports(const u32 *sid, int *total_port_count, int *= child_port_count) -{ - u32 q; - int port_type, shift, seq; - - shift =3D 6; - q =3D *sid; - seq =3D 0; - - while (1) { - port_type =3D (q >> shift) & 0x03; - switch (port_type) { - case SELFID_PORT_CHILD: - (*child_port_count)++; - fallthrough; - case SELFID_PORT_PARENT: - case SELFID_PORT_NCONN: - (*total_port_count)++; - fallthrough; - case SELFID_PORT_NONE: - break; - } - - shift -=3D 2; - if (shift =3D=3D 0) { - if (!SELF_ID_MORE_PACKETS(q)) - return sid + 1; - - shift =3D 16; - sid++; - q =3D *sid; - - /* - * Check that the extra packets actually are - * extended self ID packets and that the - * sequence numbers in the extended self ID - * packets increase as expected. - */ - - if (!SELF_ID_EXTENDED(q) || - seq !=3D SELF_ID_EXT_SEQUENCE(q)) - return NULL; - - seq++; - } - } -} - -static int get_port_type(const u32 *sid, int port_index) -{ - int index, shift; - - index =3D (port_index + 5) / 8; - shift =3D 16 - ((port_index + 5) & 7) * 2; - return (sid[index] >> shift) & 0x03; -} =20 static struct fw_node *fw_node_create(u32 sid, int port_count, int color) { @@ -168,9 +103,12 @@ static inline struct fw_node *fw_node(struct list_head= *l) */ static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, in= t self_id_count) { + struct self_id_sequence_enumerator enumerator =3D { + .cursor =3D sid, + .quadlet_count =3D self_id_count, + }; struct fw_node *node, *child, *local_node, *irm_node; struct list_head stack; - const u32 *end; int phy_id, stack_depth; int gap_count; bool beta_repeaters_present; @@ -179,31 +117,54 @@ static struct fw_node *build_tree(struct fw_card *car= d, const u32 *sid, int self node =3D NULL; INIT_LIST_HEAD(&stack); stack_depth =3D 0; - end =3D sid + self_id_count; phy_id =3D 0; irm_node =3D NULL; gap_count =3D SELF_ID_GAP_COUNT(*sid); beta_repeaters_present =3D false; =20 - while (sid < end) { - int port_count =3D 0; - int child_port_count =3D 0; - int parent_count =3D 0; - const u32 *next_sid; - u32 q; + while (enumerator.quadlet_count > 0) { + unsigned int child_port_count =3D 0; + unsigned int total_port_count =3D 0; + unsigned int parent_count =3D 0; + unsigned int quadlet_count; + const u32 *self_id_sequence; + unsigned int port_capacity; + enum phy_packet_self_id_port_status port_status; + unsigned int port_index; struct list_head *h; int i; =20 - next_sid =3D count_ports(sid, &port_count, &child_port_count); - if (next_sid =3D=3D NULL) { - fw_err(card, "inconsistent extended self IDs\n"); - return NULL; + self_id_sequence =3D self_id_sequence_enumerator_next(&enumerator, &quad= let_count); + if (IS_ERR(self_id_sequence)) { + if (PTR_ERR(self_id_sequence) !=3D -ENODATA) { + fw_err(card, "inconsistent extended self IDs: %ld\n", + PTR_ERR(self_id_sequence)); + return NULL; + } + break; } =20 - q =3D *sid; - if (phy_id !=3D SELF_ID_PHY_ID(q)) { + port_capacity =3D self_id_sequence_get_port_capacity(quadlet_count); + for (port_index =3D 0; port_index < port_capacity; ++port_index) { + port_status =3D self_id_sequence_get_port_status(self_id_sequence, quad= let_count, + port_index); + switch (port_status) { + case PHY_PACKET_SELF_ID_PORT_STATUS_CHILD: + ++child_port_count; + fallthrough; + case PHY_PACKET_SELF_ID_PORT_STATUS_PARENT: + case PHY_PACKET_SELF_ID_PORT_STATUS_NCONN: + ++total_port_count; + fallthrough; + case PHY_PACKET_SELF_ID_PORT_STATUS_NONE: + default: + break; + } + } + + if (phy_id !=3D SELF_ID_PHY_ID(self_id_sequence[0])) { fw_err(card, "PHY ID mismatch in self ID: %d !=3D %d\n", - phy_id, SELF_ID_PHY_ID(q)); + phy_id, SELF_ID_PHY_ID(self_id_sequence[0])); return NULL; } =20 @@ -224,7 +185,7 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self */ child =3D fw_node(h); =20 - node =3D fw_node_create(q, port_count, card->color); + node =3D fw_node_create(self_id_sequence[0], total_port_count, card->col= or); if (node =3D=3D NULL) { fw_err(card, "out of memory while building topology\n"); return NULL; @@ -233,48 +194,40 @@ static struct fw_node *build_tree(struct fw_card *car= d, const u32 *sid, int self if (phy_id =3D=3D (card->node_id & 0x3f)) local_node =3D node; =20 - if (SELF_ID_CONTENDER(q)) + if (SELF_ID_CONTENDER(self_id_sequence[0])) irm_node =3D node; =20 - parent_count =3D 0; - - for (i =3D 0; i < port_count; i++) { - switch (get_port_type(sid, i)) { - case SELFID_PORT_PARENT: - /* - * Who's your daddy? We dont know the - * parent node at this time, so we - * temporarily abuse node->color for - * remembering the entry in the - * node->ports array where the parent - * node should be. Later, when we - * handle the parent node, we fix up - * the reference. - */ - parent_count++; + for (port_index =3D 0; port_index < total_port_count; ++port_index) { + port_status =3D self_id_sequence_get_port_status(self_id_sequence, quad= let_count, + port_index); + switch (port_status) { + case PHY_PACKET_SELF_ID_PORT_STATUS_PARENT: + // Who's your daddy? We dont know the parent node at this time, so + // we temporarily abuse node->color for remembering the entry in + // the node->ports array where the parent node should be. Later, + // when we handle the parent node, we fix up the reference. + ++parent_count; node->color =3D i; break; =20 - case SELFID_PORT_CHILD: - node->ports[i] =3D child; - /* - * Fix up parent reference for this - * child node. - */ + case PHY_PACKET_SELF_ID_PORT_STATUS_CHILD: + node->ports[port_index] =3D child; + // Fix up parent reference for this child node. child->ports[child->color] =3D node; child->color =3D card->color; child =3D fw_node(child->link.next); break; + case PHY_PACKET_SELF_ID_PORT_STATUS_NCONN: + case PHY_PACKET_SELF_ID_PORT_STATUS_NONE: + default: + break; } } =20 - /* - * Check that the node reports exactly one parent - * port, except for the root, which of course should - * have no parents. - */ - if ((next_sid =3D=3D end && parent_count !=3D 0) || - (next_sid < end && parent_count !=3D 1)) { + // Check that the node reports exactly one parent port, except for the r= oot, which + // of course should have no parents. + if ((enumerator.quadlet_count =3D=3D 0 && parent_count !=3D 0) || + (enumerator.quadlet_count > 0 && parent_count !=3D 1)) { fw_err(card, "parent port inconsistency for node %d: " "parent_count=3D%d\n", phy_id, parent_count); return NULL; @@ -285,20 +238,16 @@ static struct fw_node *build_tree(struct fw_card *car= d, const u32 *sid, int self list_add_tail(&node->link, &stack); stack_depth +=3D 1 - child_port_count; =20 - if (node->phy_speed =3D=3D SCODE_BETA && - parent_count + child_port_count > 1) + if (node->phy_speed =3D=3D SCODE_BETA && parent_count + child_port_count= > 1) beta_repeaters_present =3D true; =20 - /* - * If PHYs report different gap counts, set an invalid count - * which will force a gap count reconfiguration and a reset. - */ - if (SELF_ID_GAP_COUNT(q) !=3D gap_count) + // If PHYs report different gap counts, set an invalid count which will = force a gap + // count reconfiguration and a reset. + if (SELF_ID_GAP_COUNT(self_id_sequence[0]) !=3D gap_count) gap_count =3D 0; =20 update_hop_count(node); =20 - sid =3D next_sid; phy_id++; } =20 --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E66E168C2E for ; Wed, 5 Jun 2024 23:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631535; cv=none; b=FIOHGBDTEDZSKPp8lkgP4clB4vgOJMCGMRx0fjwEsaFowq9RnBHU7hjUl1aq+vfOt79VqyDPNR+WxaHU20bAn7jVjyT7iP8lUGf1Jcl9Tfh4Ezxg7dkgHQFuXtFm3BuGJDo3zNK2+aDrj+H9xe2rj8i8opiL5qNDahRXWj4h7wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631535; c=relaxed/simple; bh=j7AYul+E3SNchcFdpNyT4iDK9RXRnUgJ1OtxzdywbSk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VEv0MAZPCgTNqLG+wEiW85IVrai+ICki0IQGiDGDa/5gDjPHrIgjMNGkLzhTT77xYBd3crIGdaySsW1tR3SiS35KQFPOyiZogi28LhyRrLQOrG/1gc7ajL6wKRU81KnCD6Zff7H7yNsKCVw6QrmpN8iXfiVguBcHFilx/xHmXCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=OZ+9m358; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QvEdmz6X; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="OZ+9m358"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QvEdmz6X" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 44DD01C000F6; Wed, 5 Jun 2024 19:52:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 05 Jun 2024 19:52:13 -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:subject:subject:to:to; s=fm1; t=1717631532; x= 1717717932; bh=/hGv3vJEc747DzmJ/9VfAfyTUxjs3kdRF01FRUOE/pw=; b=O Z+9m358aGLTCduScfSN048PZa99HfCZyObOKRTIm6bTsz5tqCKkCprwsWt92n0AR jLzoKHDz9AemtWHL/yOZW1mXwu1KFK8Jm6fXIIWDsj7awY5OhKuCHfsTbiKB2CRZ vEx4kufoLuXxkM+EMhq2KsYR0nf8Qd/VExLSCU8jAY/10JQFctQPj8AienUWiaTn 6fsz2AXEFRvmukubJicnvdOL2glvlbJMdSK/Lr6kOad3vuPt4nCbO8Qh6488Tz7l tXVhSAUux5rdM6oNGnW+v9AAhY+YbmMpyGXF5v+eS2Yq1/FayJyoUakkWzQPn01p vzwamJr2olNffZCN7Z52A== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631532; x= 1717717932; bh=/hGv3vJEc747DzmJ/9VfAfyTUxjs3kdRF01FRUOE/pw=; b=Q vEdmz6X+LcTYjqIsPVViaVBO7b4pvuydIcoggOLl6ZhdsWKTK06FlJ9NU9r2ojIO kvd+yMIOsyofVwv80xTWnawc2+NUr9TUgRDWDfx5JN04qnK4Z7PeOyr+4Na9q+x9 fhtKu0L2tnxHumMAufVoWcryamFqFnW3ZBqBF6wINKz8R6i59CndYwPbIoI9nU6M 5qJtFTFWrC8OC9jjb/g0kmhKYB9rcoXxC4O1gffBEhFmmVp9x8ctgAV/DXgwudTr sOXyHq1NHR5LTljUeKPoqOfRFJCPdlbfwV6XygRukbt3HqfLe/bttV33e4EaC36d lJKMTCiI0KCfoYZITgTxQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:11 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 06/11] firewire: ohci: use helper functions for self ID sequence Date: Thu, 6 Jun 2024 08:51:50 +0900 Message-ID: <20240605235155.116468-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit replaces the existing implementation with the helper functions for self ID sequence. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 77 ++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 0ef76cf7b328..342407d8bc9b 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -41,6 +41,7 @@ #include "core.h" #include "ohci.h" #include "packet-header-definitions.h" +#include "phy-packet-definitions.h" =20 #define ohci_info(ohci, f, args...) dev_info(ohci->card.device, f, ##args) #define ohci_notice(ohci, f, args...) dev_notice(ohci->card.device, f, ##a= rgs) @@ -437,11 +438,6 @@ static void log_irqs(struct fw_ohci *ohci, u32 evt) ? " ?" : ""); } =20 -static unsigned int _p(u32 *s, int shift) -{ - return *s >> shift & 3; -} - static void log_selfids(struct fw_ohci *ohci, int generation, int self_id_= count) { static const char *const speed[] =3D { @@ -451,8 +447,16 @@ static void log_selfids(struct fw_ohci *ohci, int gene= ration, int self_id_count) [0] =3D "+0W", [1] =3D "+15W", [2] =3D "+30W", [3] =3D "+45W", [4] =3D "-3W", [5] =3D " ?W", [6] =3D "-3..-6W", [7] =3D "-3..-10W", }; - static const char port[] =3D { '.', '-', 'p', 'c', }; - u32 *s; + static const char port[] =3D { + [PHY_PACKET_SELF_ID_PORT_STATUS_NONE] =3D '.', + [PHY_PACKET_SELF_ID_PORT_STATUS_NCONN] =3D '-', + [PHY_PACKET_SELF_ID_PORT_STATUS_PARENT] =3D 'p', + [PHY_PACKET_SELF_ID_PORT_STATUS_CHILD] =3D 'c', + }; + struct self_id_sequence_enumerator enumerator =3D { + .cursor =3D ohci->self_id_buffer, + .quadlet_count =3D self_id_count, + }; =20 if (likely(!(param_debug & OHCI_PARAM_DEBUG_SELFIDS))) return; @@ -460,29 +464,46 @@ static void log_selfids(struct fw_ohci *ohci, int gen= eration, int self_id_count) ohci_notice(ohci, "%d selfIDs, generation %d, local node ID %04x\n", self_id_count, generation, ohci->node_id); =20 - for (s =3D ohci->self_id_buffer; self_id_count--; ++s) - if ((*s & 1 << 23) =3D=3D 0) - ohci_notice(ohci, - "selfID 0: %08x, phy %d [%c%c%c] %s gc=3D%d %s %s%s%s\n", - *s, *s >> 24 & 63, - port[_p(s, 6)], - port[_p(s, 4)], - port[_p(s, 2)], - speed[*s >> 14 & 3], *s >> 16 & 63, - power[*s >> 8 & 7], *s >> 22 & 1 ? "L" : "", - *s >> 11 & 1 ? "c" : "", *s & 2 ? "i" : ""); - else + while (enumerator.quadlet_count > 0) { + unsigned int quadlet_count; + unsigned int port_index; + const u32 *s; + int i; + + s =3D self_id_sequence_enumerator_next(&enumerator, &quadlet_count); + if (IS_ERR(s)) + break; + + ohci_notice(ohci, + "selfID 0: %08x, phy %d [%c%c%c] %s gc=3D%d %s %s%s%s\n", + *s, + *s >> 24 & 63, + port[self_id_sequence_get_port_status(s, quadlet_count, 0)], + port[self_id_sequence_get_port_status(s, quadlet_count, 1)], + port[self_id_sequence_get_port_status(s, quadlet_count, 2)], + speed[*s >> 14 & 3], *s >> 16 & 63, + power[*s >> 8 & 7], *s >> 22 & 1 ? "L" : "", + *s >> 11 & 1 ? "c" : "", *s & 2 ? "i" : ""); + + port_index =3D 3; + for (i =3D 1; i < quadlet_count; ++i) { ohci_notice(ohci, "selfID n: %08x, phy %d [%c%c%c%c%c%c%c%c]\n", - *s, *s >> 24 & 63, - port[_p(s, 16)], - port[_p(s, 14)], - port[_p(s, 12)], - port[_p(s, 10)], - port[_p(s, 8)], - port[_p(s, 6)], - port[_p(s, 4)], - port[_p(s, 2)]); + s[i], + s[i] >> 24 & 63, + port[self_id_sequence_get_port_status(s, quadlet_count, port_index)= ], + port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 1)], + port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 2)], + port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 3)], + port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 4)], + port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 5)], + port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 6)], + port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 7)] + ); + + port_index +=3D 8; + } + } } =20 static const char *evts[] =3D { --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45C4D16EBE4 for ; Wed, 5 Jun 2024 23:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631538; cv=none; b=kMD3N1Jn6Bcz32T7z1XvqCrJ3RxTDzGIaOx2bwnlPNssvjA3u3uN/4acyWp48XQGS1oalCOt2UKU9sLvJ0nZmP+r1B06fQbnEoGjMwUTebhIdYMCJV947/956RfZ/QJ8X7DIfa0bo++igwO2O85JoYaHZCs5VWkYNnKK5CY7pM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631538; c=relaxed/simple; bh=NTRt9E+C5xRQqaC/Uvbn6Ytg1QV2WuULGzLYg+a1XAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GVHomjkP92Oc9BeMTLKeRucABOPQmcbnZfSz1mNZiaxOkeRctdb7GOgRFKnzjBn5+4CYnzztgitb4O8DldtL4BqJvxrZ6fyEygkFnG1HLlN7bnfV9xa+nld0Wwflh37IXU6wpbEkjDOjhUhiOb/7W9ewGLhwqhfoyO5HKYAdj+A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=R7M5gYwq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bSxvLFpG; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="R7M5gYwq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bSxvLFpG" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 7E6F61C000A2; Wed, 5 Jun 2024 19:52:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 05 Jun 2024 19:52: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:subject:subject:to:to; s=fm1; t=1717631535; x= 1717717935; bh=vHlq0ZKzEwlpJxFJg/r2e4RZVzz0LGqjE3vNcaSDf6M=; b=R 7M5gYwqjghTO2SeAknk+HjnMK3FvZ/UqBGEALdYLdGJwxVpCHDhCP0KTAo668244 HBt4XdLRtb/vZ02F37TYel0xrzzBXLLLcoSQPoSv2Ipe4EYnBL+4CGPKTNFgJ22g sB6Ekyk0PAXj5jiNAiSZuMSXk+tpss7tQENC6q8IjWXte8iAH2ei89FQ3Uv5TsEM shlcL06P79TfMvaTvshGGzbL87x3/59BLR0Va6vYCuyDs8kKbQyisWItPxxLEt0P YyXApzfLyJ4vsQPbMMKkHPoIglmAfGpiAQGS6aXHcoR4D5eVKENCC0BOn7TyeO5z jIlscl83gHYFEmhfesYzg== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631535; x= 1717717935; bh=vHlq0ZKzEwlpJxFJg/r2e4RZVzz0LGqjE3vNcaSDf6M=; b=b SxvLFpGHZOfnrDrwnLcjexBQsHHkOhInBLKG1ghAa2D2ZriPeODKE2zawm8dURMy JbhWoicUNMRtyObK3q7evyIdIk6J4hYajo+cAeG3lQq/YEjzYuttnywksk+3AoOn nJe7pqKBVwCSLnj8RpP/n2DFPftH8sFHLQ9ikVfUI3HlXhki4Z3KNttSKYZ7ZhEq 9r823wm2G1k/t1vjnq7YmHblpXiaNimUN5iEY5FUBNOifGBhiwt4N4frMKrn9ZHo GCZTdw4nZZEr0drnio18K/JFskTsQmygKlE6EhJRxypICEkPmuynAu8IZmNeL9sx hmLwchuw0vOTOrRxIKFQQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:13 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 07/11] firewire: core: add common inline functions to serialize/deserialize self ID packet Date: Thu, 6 Jun 2024 08:51:51 +0900 Message-ID: <20240605235155.116468-8-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Within FireWire subsystem, the serializations and deserializations of phy packet are implemented in several parts. They includes some redundancies. This commit adds a series of helper functions for the serializations and deserializations of self ID packet with a Kunit test suite. Signed-off-by: Takashi Sakamoto --- drivers/firewire/packet-serdes-test.c | 255 ++++++++++++++++++++++ drivers/firewire/phy-packet-definitions.h | 126 +++++++++++ 2 files changed, 381 insertions(+) diff --git a/drivers/firewire/packet-serdes-test.c b/drivers/firewire/packe= t-serdes-test.c index e83b1fece780..c56199e84f91 100644 --- a/drivers/firewire/packet-serdes-test.c +++ b/drivers/firewire/packet-serdes-test.c @@ -10,6 +10,7 @@ #include =20 #include "packet-header-definitions.h" +#include "phy-packet-definitions.h" =20 static void serialize_async_header_common(u32 header[ASYNC_HEADER_QUADLET_= COUNT], unsigned int dst_id, unsigned int tlabel, @@ -187,6 +188,66 @@ static void deserialize_isoc_header(u32 header, unsign= ed int *data_length, unsig *sy =3D isoc_header_get_sy(header); } =20 +static void serialize_phy_packet_self_id_zero(u32 *quadlet, unsigned int p= acket_identifier, + unsigned int phy_id, bool extended, + bool link_is_active, unsigned int gap_count, + unsigned int scode, bool is_contender, + unsigned int power_class, bool is_initiated_reset, + bool has_more_packets) +{ + phy_packet_set_packet_identifier(quadlet, packet_identifier); + phy_packet_self_id_set_phy_id(quadlet, phy_id); + phy_packet_self_id_set_extended(quadlet, extended); + phy_packet_self_id_zero_set_link_active(quadlet, link_is_active); + phy_packet_self_id_zero_set_gap_count(quadlet, gap_count); + phy_packet_self_id_zero_set_scode(quadlet, scode); + phy_packet_self_id_zero_set_contender(quadlet, is_contender); + phy_packet_self_id_zero_set_power_class(quadlet, power_class); + phy_packet_self_id_zero_set_initiated_reset(quadlet, is_initiated_reset); + phy_packet_self_id_set_more_packets(quadlet, has_more_packets); +} + +static void deserialize_phy_packet_self_id_zero(u32 quadlet, unsigned int = *packet_identifier, + unsigned int *phy_id, bool *extended, + bool *link_is_active, unsigned int *gap_count, + unsigned int *scode, bool *is_contender, + unsigned int *power_class, + bool *is_initiated_reset, bool *has_more_packets) +{ + *packet_identifier =3D phy_packet_get_packet_identifier(quadlet); + *phy_id =3D phy_packet_self_id_get_phy_id(quadlet); + *extended =3D phy_packet_self_id_get_extended(quadlet); + *link_is_active =3D phy_packet_self_id_zero_get_link_active(quadlet); + *gap_count =3D phy_packet_self_id_zero_get_gap_count(quadlet); + *scode =3D phy_packet_self_id_zero_get_scode(quadlet); + *is_contender =3D phy_packet_self_id_zero_get_contender(quadlet); + *power_class =3D phy_packet_self_id_zero_get_power_class(quadlet); + *is_initiated_reset =3D phy_packet_self_id_zero_get_initiated_reset(quadl= et); + *has_more_packets =3D phy_packet_self_id_get_more_packets(quadlet); +} + +static void serialize_phy_packet_self_id_extended(u32 *quadlet, unsigned i= nt packet_identifier, + unsigned int phy_id, bool extended, + unsigned int sequence, bool has_more_packets) +{ + phy_packet_set_packet_identifier(quadlet, packet_identifier); + phy_packet_self_id_set_phy_id(quadlet, phy_id); + phy_packet_self_id_set_extended(quadlet, extended); + phy_packet_self_id_extended_set_sequence(quadlet, sequence); + phy_packet_self_id_set_more_packets(quadlet, has_more_packets); +} + +static void deserialize_phy_packet_self_id_extended(u32 quadlet, unsigned = int *packet_identifier, + unsigned int *phy_id, bool *extended, + unsigned int *sequence, bool *has_more_packets) +{ + *packet_identifier =3D phy_packet_get_packet_identifier(quadlet); + *phy_id =3D phy_packet_self_id_get_phy_id(quadlet); + *extended =3D phy_packet_self_id_get_extended(quadlet); + *sequence =3D phy_packet_self_id_extended_get_sequence(quadlet); + *has_more_packets =3D phy_packet_self_id_get_more_packets(quadlet); +} + static void test_async_header_write_quadlet_request(struct kunit *test) { static const u32 expected[ASYNC_HEADER_QUADLET_COUNT] =3D { @@ -559,6 +620,197 @@ static void test_isoc_header(struct kunit *test) KUNIT_EXPECT_EQ(test, header, expected); } =20 +static void test_phy_packet_self_id_zero_case0(struct kunit *test) +{ + // TSB41AB1/2 with 1 port. + const u32 expected[] =3D {0x80458c80}; + u32 quadlets[] =3D {0}; + + unsigned int packet_identifier; + unsigned int phy_id; + bool extended; + bool link_is_active; + unsigned int gap_count; + unsigned int scode; + bool is_contender; + unsigned int power_class; + enum phy_packet_self_id_port_status port_status[3]; + bool is_initiated_reset; + bool has_more_packets; + unsigned int port_index; + + deserialize_phy_packet_self_id_zero(expected[0], &packet_identifier, &phy= _id, &extended, + &link_is_active, &gap_count, &scode, &is_contender, + &power_class, &is_initiated_reset, &has_more_packets); + + KUNIT_EXPECT_EQ(test, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID, packet_identi= fier); + KUNIT_EXPECT_EQ(test, 0, phy_id); + KUNIT_EXPECT_FALSE(test, extended); + KUNIT_EXPECT_TRUE(test, link_is_active); + KUNIT_EXPECT_EQ(test, 0x05, gap_count); + KUNIT_EXPECT_EQ(test, SCODE_400, scode); + KUNIT_EXPECT_TRUE(test, is_contender); + KUNIT_EXPECT_EQ(test, 0x4, power_class); + KUNIT_EXPECT_FALSE(test, is_initiated_reset); + KUNIT_EXPECT_FALSE(test, has_more_packets); + + serialize_phy_packet_self_id_zero(quadlets, packet_identifier, phy_id, ex= tended, + link_is_active, gap_count, scode, is_contender, + power_class, is_initiated_reset, has_more_packets); + + for (port_index =3D 0; port_index < ARRAY_SIZE(port_status); ++port_index= ) { + port_status[port_index] =3D + self_id_sequence_get_port_status(expected, ARRAY_SIZE(expected), port_i= ndex); + } + + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 0]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NONE, port_status[1]= ); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NONE, port_status[2]= ); + + for (port_index =3D 0; port_index < ARRAY_SIZE(port_status); ++port_index= ) { + self_id_sequence_set_port_status(quadlets, ARRAY_SIZE(quadlets), port_in= dex, + port_status[port_index]); + } + + KUNIT_EXPECT_MEMEQ(test, quadlets, expected, sizeof(expected)); +} + +static void test_phy_packet_self_id_zero_case1(struct kunit *test) +{ + // XIO2213 and TSB81BA3E with 3 ports. + const u32 expected[] =3D {0x817fcc5e}; + u32 quadlets[] =3D {0}; + + unsigned int packet_identifier; + unsigned int phy_id; + bool extended; + bool link_is_active; + unsigned int gap_count; + unsigned int scode; + bool is_contender; + unsigned int power_class; + enum phy_packet_self_id_port_status port_status[3]; + bool is_initiated_reset; + bool has_more_packets; + unsigned int port_index; + + deserialize_phy_packet_self_id_zero(expected[0], &packet_identifier, &phy= _id, &extended, + &link_is_active, &gap_count, &scode, &is_contender, + &power_class, &is_initiated_reset, &has_more_packets); + + KUNIT_EXPECT_EQ(test, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID, packet_identi= fier); + KUNIT_EXPECT_EQ(test, 1, phy_id); + KUNIT_EXPECT_FALSE(test, extended); + KUNIT_EXPECT_TRUE(test, link_is_active); + KUNIT_EXPECT_EQ(test, 0x3f, gap_count); + KUNIT_EXPECT_EQ(test, SCODE_800, scode); + KUNIT_EXPECT_TRUE(test, is_contender); + KUNIT_EXPECT_EQ(test, 0x4, power_class); + KUNIT_EXPECT_TRUE(test, is_initiated_reset); + KUNIT_EXPECT_FALSE(test, has_more_packets); + + serialize_phy_packet_self_id_zero(quadlets, packet_identifier, phy_id, ex= tended, + link_is_active, gap_count, scode, is_contender, + power_class, is_initiated_reset, has_more_packets); + + for (port_index =3D 0; port_index < ARRAY_SIZE(port_status); ++port_index= ) { + port_status[port_index] =3D + self_id_sequence_get_port_status(expected, ARRAY_SIZE(expected), port_i= ndex); + } + + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[0= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[1= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD, port_status[2= ]); + + for (port_index =3D 0; port_index < ARRAY_SIZE(port_status); ++port_index= ) { + self_id_sequence_set_port_status(quadlets, ARRAY_SIZE(quadlets), port_in= dex, + port_status[port_index]); + } + + KUNIT_EXPECT_MEMEQ(test, quadlets, expected, sizeof(expected)); +} + +static void test_phy_packet_self_id_zero_and_one(struct kunit *test) +{ + // TSB41LV06A with 6 ports. + const u32 expected[] =3D { + 0x803f8459, + 0x80815000, + }; + u32 quadlets[] =3D {0, 0}; + + unsigned int packet_identifier; + unsigned int phy_id; + bool extended; + bool link_is_active; + unsigned int gap_count; + unsigned int scode; + bool is_contender; + unsigned int power_class; + enum phy_packet_self_id_port_status port_status[11]; + bool is_initiated_reset; + bool has_more_packets; + + unsigned int sequence; + unsigned int port_index; + + deserialize_phy_packet_self_id_zero(expected[0], &packet_identifier, &phy= _id, &extended, + &link_is_active, &gap_count, &scode, &is_contender, + &power_class, &is_initiated_reset, &has_more_packets); + + KUNIT_EXPECT_EQ(test, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID, packet_identi= fier); + KUNIT_EXPECT_EQ(test, 0, phy_id); + KUNIT_EXPECT_FALSE(test, extended); + KUNIT_EXPECT_FALSE(test, link_is_active); + KUNIT_EXPECT_EQ(test, 0x3f, gap_count); + KUNIT_EXPECT_EQ(test, SCODE_400, scode); + KUNIT_EXPECT_FALSE(test, is_contender); + KUNIT_EXPECT_EQ(test, 0x4, power_class); + KUNIT_EXPECT_FALSE(test, is_initiated_reset); + KUNIT_EXPECT_TRUE(test, has_more_packets); + + serialize_phy_packet_self_id_zero(quadlets, packet_identifier, phy_id, ex= tended, + link_is_active, gap_count, scode, is_contender, + power_class, is_initiated_reset, has_more_packets); + + deserialize_phy_packet_self_id_extended(expected[1], &packet_identifier, = &phy_id, &extended, + &sequence, &has_more_packets); + + KUNIT_EXPECT_EQ(test, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID, packet_identi= fier); + KUNIT_EXPECT_EQ(test, 0, phy_id); + KUNIT_EXPECT_TRUE(test, extended); + KUNIT_EXPECT_EQ(test, 0, sequence); + KUNIT_EXPECT_FALSE(test, has_more_packets); + + serialize_phy_packet_self_id_extended(&quadlets[1], packet_identifier, ph= y_id, extended, + sequence, has_more_packets); + + + for (port_index =3D 0; port_index < ARRAY_SIZE(port_status); ++port_index= ) { + port_status[port_index] =3D + self_id_sequence_get_port_status(expected, ARRAY_SIZE(expected), port_i= ndex); + } + + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[0= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[1= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT, port_status[= 2]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[3= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[4= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN, port_status[5= ]); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NONE, port_status[6]= ); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NONE, port_status[7]= ); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NONE, port_status[8]= ); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NONE, port_status[9]= ); + KUNIT_EXPECT_EQ(test, PHY_PACKET_SELF_ID_PORT_STATUS_NONE, port_status[10= ]); + + for (port_index =3D 0; port_index < ARRAY_SIZE(port_status); ++port_index= ) { + self_id_sequence_set_port_status(quadlets, ARRAY_SIZE(quadlets), port_in= dex, + port_status[port_index]); + } + + KUNIT_EXPECT_MEMEQ(test, quadlets, expected, sizeof(expected)); +} + static struct kunit_case packet_serdes_test_cases[] =3D { KUNIT_CASE(test_async_header_write_quadlet_request), KUNIT_CASE(test_async_header_write_block_request), @@ -570,6 +822,9 @@ static struct kunit_case packet_serdes_test_cases[] =3D= { KUNIT_CASE(test_async_header_lock_request), KUNIT_CASE(test_async_header_lock_response), KUNIT_CASE(test_isoc_header), + KUNIT_CASE(test_phy_packet_self_id_zero_case0), + KUNIT_CASE(test_phy_packet_self_id_zero_case1), + KUNIT_CASE(test_phy_packet_self_id_zero_and_one), {} }; =20 diff --git a/drivers/firewire/phy-packet-definitions.h b/drivers/firewire/p= hy-packet-definitions.h index 4ba8b18aa993..8f78494ad371 100644 --- a/drivers/firewire/phy-packet-definitions.h +++ b/drivers/firewire/phy-packet-definitions.h @@ -7,11 +7,42 @@ #ifndef _FIREWIRE_PHY_PACKET_DEFINITIONS_H #define _FIREWIRE_PHY_PACKET_DEFINITIONS_H =20 +#define PACKET_IDENTIFIER_MASK 0xc0000000 +#define PACKET_IDENTIFIER_SHIFT 30 + +static inline unsigned int phy_packet_get_packet_identifier(u32 quadlet) +{ + return (quadlet & PACKET_IDENTIFIER_MASK) >> PACKET_IDENTIFIER_SHIFT; +} + +static inline void phy_packet_set_packet_identifier(u32 *quadlet, unsigned= int packet_identifier) +{ + *quadlet &=3D ~PACKET_IDENTIFIER_MASK; + *quadlet |=3D (packet_identifier << PACKET_IDENTIFIER_SHIFT) & PACKET_IDE= NTIFIER_MASK; +} + +#define PHY_PACKET_PACKET_IDENTIFIER_SELF_ID 2 + +#define SELF_ID_PHY_ID_MASK 0x3f000000 +#define SELF_ID_PHY_ID_SHIFT 24 #define SELF_ID_EXTENDED_MASK 0x00800000 #define SELF_ID_EXTENDED_SHIFT 23 #define SELF_ID_MORE_PACKETS_MASK 0x00000001 #define SELF_ID_MORE_PACKETS_SHIFT 0 =20 +#define SELF_ID_ZERO_LINK_ACTIVE_MASK 0x00400000 +#define SELF_ID_ZERO_LINK_ACTIVE_SHIFT 22 +#define SELF_ID_ZERO_GAP_COUNT_MASK 0x003f0000 +#define SELF_ID_ZERO_GAP_COUNT_SHIFT 16 +#define SELF_ID_ZERO_SCODE_MASK 0x0000c000 +#define SELF_ID_ZERO_SCODE_SHIFT 14 +#define SELF_ID_ZERO_CONTENDER_MASK 0x00000800 +#define SELF_ID_ZERO_CONTENDER_SHIFT 11 +#define SELF_ID_ZERO_POWER_CLASS_MASK 0x00000700 +#define SELF_ID_ZERO_POWER_CLASS_SHIFT 8 +#define SELF_ID_ZERO_INITIATED_RESET_MASK 0x00000002 +#define SELF_ID_ZERO_INITIATED_RESET_SHIFT 1 + #define SELF_ID_EXTENDED_SEQUENCE_MASK 0x00700000 #define SELF_ID_EXTENDED_SEQUENCE_SHIFT 20 =20 @@ -19,21 +50,116 @@ =20 #define SELF_ID_SEQUENCE_MAXIMUM_QUADLET_COUNT 4 =20 +static inline unsigned int phy_packet_self_id_get_phy_id(u32 quadlet) +{ + return (quadlet & SELF_ID_PHY_ID_MASK) >> SELF_ID_PHY_ID_SHIFT; +} + +static inline void phy_packet_self_id_set_phy_id(u32 *quadlet, unsigned in= t phy_id) +{ + *quadlet &=3D ~SELF_ID_PHY_ID_MASK; + *quadlet |=3D (phy_id << SELF_ID_PHY_ID_SHIFT) & SELF_ID_PHY_ID_MASK; +} + static inline bool phy_packet_self_id_get_extended(u32 quadlet) { return (quadlet & SELF_ID_EXTENDED_MASK) >> SELF_ID_EXTENDED_SHIFT; } =20 +static inline void phy_packet_self_id_set_extended(u32 *quadlet, bool exte= nded) +{ + *quadlet &=3D ~SELF_ID_EXTENDED_MASK; + *quadlet |=3D (extended << SELF_ID_EXTENDED_SHIFT) & SELF_ID_EXTENDED_MAS= K; +} + +static inline bool phy_packet_self_id_zero_get_link_active(u32 quadlet) +{ + return (quadlet & SELF_ID_ZERO_LINK_ACTIVE_MASK) >> SELF_ID_ZERO_LINK_ACT= IVE_SHIFT; +} + +static inline void phy_packet_self_id_zero_set_link_active(u32 *quadlet, b= ool is_active) +{ + *quadlet &=3D ~SELF_ID_ZERO_LINK_ACTIVE_MASK; + *quadlet |=3D (is_active << SELF_ID_ZERO_LINK_ACTIVE_SHIFT) & SELF_ID_ZER= O_LINK_ACTIVE_MASK; +} + +static inline unsigned int phy_packet_self_id_zero_get_gap_count(u32 quadl= et) +{ + return (quadlet & SELF_ID_ZERO_GAP_COUNT_MASK) >> SELF_ID_ZERO_GAP_COUNT_= SHIFT; +} + +static inline void phy_packet_self_id_zero_set_gap_count(u32 *quadlet, uns= igned int gap_count) +{ + *quadlet &=3D ~SELF_ID_ZERO_GAP_COUNT_MASK; + *quadlet |=3D (gap_count << SELF_ID_ZERO_GAP_COUNT_SHIFT) & SELF_ID_ZERO_= GAP_COUNT_MASK; +} + +static inline unsigned int phy_packet_self_id_zero_get_scode(u32 quadlet) +{ + return (quadlet & SELF_ID_ZERO_SCODE_MASK) >> SELF_ID_ZERO_SCODE_SHIFT; +} + +static inline void phy_packet_self_id_zero_set_scode(u32 *quadlet, unsigne= d int speed) +{ + *quadlet &=3D ~SELF_ID_ZERO_SCODE_MASK; + *quadlet |=3D (speed << SELF_ID_ZERO_SCODE_SHIFT) & SELF_ID_ZERO_SCODE_MA= SK; +} + +static inline bool phy_packet_self_id_zero_get_contender(u32 quadlet) +{ + return (quadlet & SELF_ID_ZERO_CONTENDER_MASK) >> SELF_ID_ZERO_CONTENDER_= SHIFT; +} + +static inline void phy_packet_self_id_zero_set_contender(u32 *quadlet, boo= l is_contender) +{ + *quadlet &=3D ~SELF_ID_ZERO_CONTENDER_MASK; + *quadlet |=3D (is_contender << SELF_ID_ZERO_CONTENDER_SHIFT) & SELF_ID_ZE= RO_CONTENDER_MASK; +} + +static inline unsigned int phy_packet_self_id_zero_get_power_class(u32 qua= dlet) +{ + return (quadlet & SELF_ID_ZERO_POWER_CLASS_MASK) >> SELF_ID_ZERO_POWER_CL= ASS_SHIFT; +} + +static inline void phy_packet_self_id_zero_set_power_class(u32 *quadlet, u= nsigned int power_class) +{ + *quadlet &=3D ~SELF_ID_ZERO_POWER_CLASS_MASK; + *quadlet |=3D (power_class << SELF_ID_ZERO_POWER_CLASS_SHIFT) & SELF_ID_Z= ERO_POWER_CLASS_MASK; +} + +static inline bool phy_packet_self_id_zero_get_initiated_reset(u32 quadlet) +{ + return (quadlet & SELF_ID_ZERO_INITIATED_RESET_MASK) >> SELF_ID_ZERO_INIT= IATED_RESET_SHIFT; +} + +static inline void phy_packet_self_id_zero_set_initiated_reset(u32 *quadle= t, bool is_initiated_reset) +{ + *quadlet &=3D ~SELF_ID_ZERO_INITIATED_RESET_MASK; + *quadlet |=3D (is_initiated_reset << SELF_ID_ZERO_INITIATED_RESET_SHIFT) = & SELF_ID_ZERO_INITIATED_RESET_MASK; +} + static inline bool phy_packet_self_id_get_more_packets(u32 quadlet) { return (quadlet & SELF_ID_MORE_PACKETS_MASK) >> SELF_ID_MORE_PACKETS_SHIF= T; } =20 +static inline void phy_packet_self_id_set_more_packets(u32 *quadlet, bool = is_more_packets) +{ + *quadlet &=3D ~SELF_ID_MORE_PACKETS_MASK; + *quadlet |=3D (is_more_packets << SELF_ID_MORE_PACKETS_SHIFT) & SELF_ID_M= ORE_PACKETS_MASK; +} + static inline unsigned int phy_packet_self_id_extended_get_sequence(u32 qu= adlet) { return (quadlet & SELF_ID_EXTENDED_SEQUENCE_MASK) >> SELF_ID_EXTENDED_SEQ= UENCE_SHIFT; } =20 +static inline void phy_packet_self_id_extended_set_sequence(u32 *quadlet, = unsigned int sequence) +{ + *quadlet &=3D ~SELF_ID_EXTENDED_SEQUENCE_MASK; + *quadlet |=3D (sequence << SELF_ID_EXTENDED_SHIFT) & SELF_ID_EXTENDED_SEQ= UENCE_MASK; +} + struct self_id_sequence_enumerator { const u32 *cursor; unsigned int quadlet_count; --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BCB116FF2E for ; Wed, 5 Jun 2024 23:52:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631539; cv=none; b=AKtzdZLAU3ctC6F/1nqXR6eCaWSdA/dSLvMmSfWeHSrjtz5CgL1ELHr6fkPjYuI21QlWzVNncOfSOpNCWHBZPFNRwXdXJOLTxrJrl68HK6b2zCOa8qCYdok1RRTFZrr7yhWE4ZYxVo8ed9v8S3oZl+INMCU1AHBShMtPrs5OJag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631539; c=relaxed/simple; bh=ebmLsfA0LlsB0ePd7GOHkiCsMBiHmH04Q7vyI11vts8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ivRs96+swNZ0rgz3IJ64Ulodf423jgQebIQ4tipmvTdjGi/KxC5XgVOMKN2JMoeN6ea7b3XZwET5GABaWf3zbqVj7+H4+fxFbAwfXJhIWxUGi3P2Mgo14+XoAXzRi6Ls7iBomTtcXa0wa44hheqGj/HbcX3urPjfyc8xn7LK6wE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=ROQGTVMo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=agncoT60; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="ROQGTVMo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="agncoT60" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 8B2F71C0005B; Wed, 5 Jun 2024 19:52:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 05 Jun 2024 19:52:17 -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:subject:subject:to:to; s=fm1; t=1717631537; x= 1717717937; bh=qWFO7zoF+O3PVNs52gcGbFCEy0eI0C7UgJjzmWKpW4M=; b=R OQGTVMomLqSTv3VH+Y59El3gBqQUuTxNqEUZqFZt8r3U5walYP4RCrLkqootNYnp PNVYugQ1pWbA1WSiq2ml2GfOmo0Y8knR3zmyuHmA1adJnKL4OXtNdNedEpXKaeI2 MjjIvZIuwAWNlugm/J8eMAy+ObwkUTF9Tey6iG0LgX3Eb+IHsnmsmekl78Y+C97R qKV8JJNe7OPQowfnXyEVyuCu/PI6JApWY3HQWPeuXAUwDJj+2MGWG8weIZBKXiw1 SGwzr4mnGFsb3Z8iTxDOfjSxvsZLmuWI5MBHUhX0iTe23WeEKtiMcyfqdprpHosF QUXPfIh4Vu2t1spSa+T1Q== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631537; x= 1717717937; bh=qWFO7zoF+O3PVNs52gcGbFCEy0eI0C7UgJjzmWKpW4M=; b=a gncoT60BiYOu5cWM92bVrwh4BRGZxTDcKYnWBXC9k+zN02UnbNbKEcwG/U/mwBwe eTsKXZdYCxvlaIbz746po+mlzdmhyLy2iaAxNhdGOWhkBAK8VceiacW1uF24NECZ JY1TH6R1xL5W6nMeIQMnkGlMvSHZ7PVvAKjaKROeFB0FpVx9iVHM++SQBM5XjH/d MrEEVRyNascOw+qOyJgdKf4BBOSwlhm1/rHkQPP3a7QeJl0DLMXQ82ad7tGLkkiL 94enZpBNqeK/59hIG3opkoPe0tRURRv948MDphGdwHSREjxWMV4MBVN0M+qFApij ZIrNHce04mGk9T7v5VvNQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:15 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 08/11] firewire: core: use helper inline functions to deserialize self ID packet Date: Thu, 6 Jun 2024 08:51:52 +0900 Message-ID: <20240605235155.116468-9-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit replaces the existing implementation with the helper functions for self ID packet. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-topology.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topol= ogy.c index 999ba2b121cd..6ec100e17500 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -23,13 +23,6 @@ #include "phy-packet-definitions.h" #include =20 -#define SELF_ID_PHY_ID(q) (((q) >> 24) & 0x3f) -#define SELF_ID_LINK_ON(q) (((q) >> 22) & 0x01) -#define SELF_ID_GAP_COUNT(q) (((q) >> 16) & 0x3f) -#define SELF_ID_PHY_SPEED(q) (((q) >> 14) & 0x03) -#define SELF_ID_CONTENDER(q) (((q) >> 11) & 0x01) -#define SELF_ID_PHY_INITIATOR(q) (((q) >> 1) & 0x01) - static struct fw_node *fw_node_create(u32 sid, int port_count, int color) { struct fw_node *node; @@ -39,10 +32,11 @@ static struct fw_node *fw_node_create(u32 sid, int port= _count, int color) return NULL; =20 node->color =3D color; - node->node_id =3D LOCAL_BUS | SELF_ID_PHY_ID(sid); - node->link_on =3D SELF_ID_LINK_ON(sid); - node->phy_speed =3D SELF_ID_PHY_SPEED(sid); - node->initiated_reset =3D SELF_ID_PHY_INITIATOR(sid); + node->node_id =3D LOCAL_BUS | phy_packet_self_id_get_phy_id(sid); + node->link_on =3D phy_packet_self_id_zero_get_link_active(sid); + // NOTE: Only two bits, thus only for SCODE_100, SCODE_200, SCODE_400, an= d SCODE_BETA. + node->phy_speed =3D phy_packet_self_id_zero_get_scode(sid); + node->initiated_reset =3D phy_packet_self_id_zero_get_initiated_reset(sid= ); node->port_count =3D port_count; =20 refcount_set(&node->ref_count, 1); @@ -119,7 +113,7 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self stack_depth =3D 0; phy_id =3D 0; irm_node =3D NULL; - gap_count =3D SELF_ID_GAP_COUNT(*sid); + gap_count =3D phy_packet_self_id_zero_get_gap_count(*sid); beta_repeaters_present =3D false; =20 while (enumerator.quadlet_count > 0) { @@ -162,9 +156,9 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self } } =20 - if (phy_id !=3D SELF_ID_PHY_ID(self_id_sequence[0])) { + if (phy_id !=3D phy_packet_self_id_get_phy_id(self_id_sequence[0])) { fw_err(card, "PHY ID mismatch in self ID: %d !=3D %d\n", - phy_id, SELF_ID_PHY_ID(self_id_sequence[0])); + phy_id, phy_packet_self_id_get_phy_id(self_id_sequence[0])); return NULL; } =20 @@ -194,7 +188,7 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self if (phy_id =3D=3D (card->node_id & 0x3f)) local_node =3D node; =20 - if (SELF_ID_CONTENDER(self_id_sequence[0])) + if (phy_packet_self_id_zero_get_contender(self_id_sequence[0])) irm_node =3D node; =20 for (port_index =3D 0; port_index < total_port_count; ++port_index) { @@ -243,7 +237,7 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self =20 // If PHYs report different gap counts, set an invalid count which will = force a gap // count reconfiguration and a reset. - if (SELF_ID_GAP_COUNT(self_id_sequence[0]) !=3D gap_count) + if (phy_packet_self_id_zero_get_gap_count(self_id_sequence[0]) !=3D gap_= count) gap_count =3D 0; =20 update_hop_count(node); --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B2DD17167B for ; Wed, 5 Jun 2024 23:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631542; cv=none; b=dIVcMGgCKUKJdobgmMLiazd7Q3CAggdPDucFJSSKFdLdoZIf/mbqUFlEMZdOVHzpe0w4QmsjMhCaj36ijNTdbormRfiJxRbvX6eplGDAXhLqXFSV1eSLT+XTZwQt8aFfK4UQ/McyEdERt3BUN08+NqbrpcnuF3z6iMM9dTVJjgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631542; c=relaxed/simple; bh=uk9h3Wx0jSORRrHDHQSRvVeuJxvNL1Zwsnc30WAZZ4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M6ZdftETMsWX+AlYmPpsBIVmi6cw2ziEsEc8n34s0iPGL8kQj20KQJGapW6TKACqthd9WkHN9xM0x1OkmijCxox2RfVuujs/TJfJaOuZYYFw/iZyFcGsiK5rvap7VAXGqcWO+WZ0VnLlQ95c9BN5pKv95v54NHY+5SJFRu6wkk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=eOSSw3/R; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z2L7dX6F; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="eOSSw3/R"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z2L7dX6F" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 9731C1C000FB; Wed, 5 Jun 2024 19:52:19 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 05 Jun 2024 19:52: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:subject:subject:to:to; s=fm1; t=1717631539; x= 1717717939; bh=AB80wdRifDotWyffJuTSQTTcEEsAJXA4WZpWq0bUy8E=; b=e OSSw3/RpFGMk4leo2UEieIUx2A3danNKIDOUPtq8OSI4N2pGkTAw7WXRtS0isezo bpTixwOo1VuF1Iv/mXn9MfcLT5ke3lAVCvGrZFB06m85BFFbLwh7JBJ6hspIay/7 L1Jgy1AMVkVIeVf0B+9Cj8rq3nxFdFga/5GicrfK/rxs+2Nzj9Z/4xczpjA3LV4y zX8Be6ZlBXgdf1+hFqorhYnCeBTvihgwBlMR0mTQRURDrK5TozZQBJps1LdKV+hO yOigwBQHFIOQZwaEmGTyjas85JMcJPvQbC048M4Wk9Mqq4MYwDI4YG6hIkdlmmw6 JX9tBzOL2MT7UdywLYRdA== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631539; x= 1717717939; bh=AB80wdRifDotWyffJuTSQTTcEEsAJXA4WZpWq0bUy8E=; b=Z 2L7dX6F732FA7CZWTNDbwSkFoEQXYHgYnPHhLP8VvfjUxzVrbLbs9ctWM7rtFtnu tmN85I4A46F5yiwmj+qM/fa9IYlq/ndvPL2WTFzy3IUrCloLaazWylMqNAyQ9NeE +IwFpydXfqZnqnaYQtessBsycjW5tHtSNPVTYJQL6kh33+LxgUNzwA4NHT+eX6qC ZcXlMN6cdHRMCeh6NC/6RfzLHJRvZezuGvCiUi/ZRw8d3yQM4fzPP7i3e+UW6Ska LBVpmgUhmtREEzrdi27Zqux+cfzxuUcTq7MP13JmV512MCJq3O7FqA1u8qT7hCCP VGcEpj+GuJa0GPJV6rCtg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:18 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 09/11] firewire: ohci: use helper inline functions to serialize/deserialize self ID packet Date: Thu, 6 Jun 2024 08:51:53 +0900 Message-ID: <20240605235155.116468-10-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit replaces the existing implementation with the helper functions for self ID packet. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 69 +++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 342407d8bc9b..1f6097a6366c 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -477,7 +477,7 @@ static void log_selfids(struct fw_ohci *ohci, int gener= ation, int self_id_count) ohci_notice(ohci, "selfID 0: %08x, phy %d [%c%c%c] %s gc=3D%d %s %s%s%s\n", *s, - *s >> 24 & 63, + phy_packet_self_id_get_phy_id(*s), port[self_id_sequence_get_port_status(s, quadlet_count, 0)], port[self_id_sequence_get_port_status(s, quadlet_count, 1)], port[self_id_sequence_get_port_status(s, quadlet_count, 2)], @@ -490,7 +490,7 @@ static void log_selfids(struct fw_ohci *ohci, int gener= ation, int self_id_count) ohci_notice(ohci, "selfID n: %08x, phy %d [%c%c%c%c%c%c%c%c]\n", s[i], - s[i] >> 24 & 63, + phy_packet_self_id_get_phy_id(s[i]), port[self_id_sequence_get_port_status(s, quadlet_count, port_index)= ], port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 1)], port[self_id_sequence_get_port_status(s, quadlet_count, port_index = + 2)], @@ -1846,7 +1846,8 @@ static u32 update_bus_time(struct fw_ohci *ohci) return ohci->bus_time | cycle_time_seconds; } =20 -static int get_status_for_port(struct fw_ohci *ohci, int port_index) +static int get_status_for_port(struct fw_ohci *ohci, int port_index, + enum phy_packet_self_id_port_status *status) { int reg; =20 @@ -1860,33 +1861,44 @@ static int get_status_for_port(struct fw_ohci *ohci= , int port_index) =20 switch (reg & 0x0f) { case 0x06: - return 2; /* is child node (connected to parent node) */ + // is child node (connected to parent node) + *status =3D PHY_PACKET_SELF_ID_PORT_STATUS_PARENT; + break; case 0x0e: - return 3; /* is parent node (connected to child node) */ + // is parent node (connected to child node) + *status =3D PHY_PACKET_SELF_ID_PORT_STATUS_CHILD; + break; + default: + // not connected + *status =3D PHY_PACKET_SELF_ID_PORT_STATUS_NCONN; + break; } - return 1; /* not connected */ + + return 0; } =20 static int get_self_id_pos(struct fw_ohci *ohci, u32 self_id, int self_id_count) { + unsigned int left_phy_id =3D phy_packet_self_id_get_phy_id(self_id); int i; - u32 entry; =20 for (i =3D 0; i < self_id_count; i++) { - entry =3D ohci->self_id_buffer[i]; - if ((self_id & 0xff000000) =3D=3D (entry & 0xff000000)) + u32 entry =3D ohci->self_id_buffer[i]; + unsigned int right_phy_id =3D phy_packet_self_id_get_phy_id(entry); + + if (left_phy_id =3D=3D right_phy_id) return -1; - if ((self_id & 0xff000000) < (entry & 0xff000000)) + if (left_phy_id < right_phy_id) return i; } return i; } =20 -static int initiated_reset(struct fw_ohci *ohci) +static bool initiated_reset(struct fw_ohci *ohci) { int reg; - int ret =3D 0; + int ret =3D false; =20 mutex_lock(&ohci->phy_reg_mutex); reg =3D write_phy_reg(ohci, 7, 0xe0); /* Select page 7 */ @@ -1899,7 +1911,7 @@ static int initiated_reset(struct fw_ohci *ohci) if (reg >=3D 0) { if ((reg & 0x08) =3D=3D 0x08) { /* bit 3 indicates "initiated reset" */ - ret =3D 0x2; + ret =3D true; } } } @@ -1915,9 +1927,14 @@ static int initiated_reset(struct fw_ohci *ohci) */ static int find_and_insert_self_id(struct fw_ohci *ohci, int self_id_count) { - int reg, i, pos, status; - /* link active 1, speed 3, bridge 0, contender 1, more packets 0 */ - u32 self_id =3D 0x8040c800; + int reg, i, pos; + u32 self_id =3D 0; + + // link active 1, speed 3, bridge 0, contender 1, more packets 0. + phy_packet_set_packet_identifier(&self_id, PHY_PACKET_PACKET_IDENTIFIER_S= ELF_ID); + phy_packet_self_id_zero_set_link_active(&self_id, true); + phy_packet_self_id_zero_set_scode(&self_id, SCODE_800); + phy_packet_self_id_zero_set_contender(&self_id, true); =20 reg =3D reg_read(ohci, OHCI1394_NodeID); if (!(reg & OHCI1394_NodeID_idValid)) { @@ -1925,26 +1942,30 @@ static int find_and_insert_self_id(struct fw_ohci *= ohci, int self_id_count) "node ID not valid, new bus reset in progress\n"); return -EBUSY; } - self_id |=3D ((reg & 0x3f) << 24); /* phy ID */ + phy_packet_self_id_set_phy_id(&self_id, reg & 0x3f); =20 reg =3D ohci_read_phy_reg(&ohci->card, 4); if (reg < 0) return reg; - self_id |=3D ((reg & 0x07) << 8); /* power class */ + phy_packet_self_id_zero_set_power_class(&self_id, reg & 0x07); =20 reg =3D ohci_read_phy_reg(&ohci->card, 1); if (reg < 0) return reg; - self_id |=3D ((reg & 0x3f) << 16); /* gap count */ + phy_packet_self_id_zero_set_gap_count(&self_id, reg & 0x3f); =20 for (i =3D 0; i < 3; i++) { - status =3D get_status_for_port(ohci, i); - if (status < 0) - return status; - self_id |=3D ((status & 0x3) << (6 - (i * 2))); + enum phy_packet_self_id_port_status status; + int err; + + err =3D get_status_for_port(ohci, i, &status); + if (err < 0) + return err; + + self_id_sequence_set_port_status(&self_id, 1, i, status); } =20 - self_id |=3D initiated_reset(ohci); + phy_packet_self_id_zero_set_initiated_reset(&self_id, initiated_reset(ohc= i)); =20 pos =3D get_self_id_pos(ohci, self_id, self_id_count); if (pos >=3D 0) { --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfout2-smtp.messagingengine.com (wfout2-smtp.messagingengine.com [64.147.123.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7315A175563 for ; Wed, 5 Jun 2024 23:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631543; cv=none; b=IyyvFGm62n5R6z711meqmhQ9sbIu7m0Yoy9fsQ01sX5FEkrzfIqXBkrwRElTcHJPjfoHQOOv60bIGbPLtPDOxQHbO9vgCQtHMg04tRH93S/RtzXGZNg+DSvz7ZmlqHAjLG2COqDBGq066HdOlVr8MvWb5ZnpzmK0lK6rWHR3QhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631543; c=relaxed/simple; bh=3iuK0NrtiFinpip/uVNKKVi8nhUphaZFCh8RR+1TZOI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T1okuMx57cX6l7Fb1XDBAH/LVi+n200ISQ9zc829We5WUHHWL4BlMf7X3jrxz3KsGjgl1jQwQEK9c1/aMJTqw7hWN3Ls9eBsLpQngZ5w6tWOCbk9Hlc6PaNO+mh33Eb02xAav0u8sTFywzLhB/xT9KSXz+cx6TVKOGEbaS5qrA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=Tn6ON1w/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a+Hznjbh; arc=none smtp.client-ip=64.147.123.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="Tn6ON1w/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a+Hznjbh" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id A0F5A1C0012D; Wed, 5 Jun 2024 19:52:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 05 Jun 2024 19:52:21 -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:subject:subject:to:to; s=fm1; t=1717631541; x= 1717717941; bh=YhYZ47zvMT0a++wOZL0Bg5VQ35AEPyrocZUAtMVjskY=; b=T n6ON1w/AwhxRzf+DZ/QDpnuw3B0iIIohQ+0qh077GAnHcDCrVdhgK9PHv6QWVZ+r pCNDZI0KKG6EWKO1zG/ZaYoR6xsJZR2MRaHlx26kxs6CFzL6BaTBC59GD21DX5OB HqioJREy9QvtypYftr/HhmPeyTUb/X6TBt9MYRzvL3s7RFkCK6TMr92nvAtonRzk HxFdeeGYJ1KJW8pWLsdhVLE0Q0ijjmlABAQhh1q43zyxTsh61FBc3qc6kNHMARoo av6FkINNMNd77iaAFVMFczD8JptWJleMPNSLor/luMCrKu7GTZeCjakgtNLeKz0N dTzvZMEByirtfAJHVnvHg== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631541; x= 1717717941; bh=YhYZ47zvMT0a++wOZL0Bg5VQ35AEPyrocZUAtMVjskY=; b=a +HznjbhNUem4NAKdtGW9Z32SAXA2FvtxaWb4kBPp2FX5fItTpE0j9wdSfzbzCJ4z 7LSxqvB9pjqq2DuPuJb2rhsetANCOwB5HIxknYJ84TDyqRhQAcSZtiQrismixaLI dCGGiT/1g9AKhHjKSYA5I58HaCtzRQGBcd5u171fTG9EopQL4XjWClZM38VgAnmz udKmz9GmsGOuGB6RhUEtGnrIkmeMqCpRU2VwA1zwDJ8yCULeC5GHkPIP1NIOfanC xCuxAU1h3I6jcKzqFfK5++GsLaGQ3xMe+c9SR98W5EbeAUe0CpY3vyMff9FVObB5 Pl0KnFNXTyfc1FQ31mZjQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:20 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 10/11] firewire: core: arrangement header inclusion for tracepoints events Date: Thu, 6 Jun 2024 08:51:54 +0900 Message-ID: <20240605235155.116468-11-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is a bit inconvenient to put the relative path to local header from tree-wide header. This commit delegates the selection to include headers into users. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-trace.c | 3 +++ drivers/firewire/core-transaction.c | 2 +- drivers/firewire/packet-header-definitions.h | 2 ++ include/trace/events/firewire.h | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/core-trace.c b/drivers/firewire/core-trace.c index 96cbd9d384dc..7cbf850f3719 100644 --- a/drivers/firewire/core-trace.c +++ b/drivers/firewire/core-trace.c @@ -1,5 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright (c) 2024 Takashi Sakamoto =20 +#include +#include "packet-header-definitions.h" + #define CREATE_TRACE_POINTS #include diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index 571fdff65c2b..6868ff17dc10 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -29,8 +29,8 @@ #include =20 #include "core.h" -#include #include "packet-header-definitions.h" +#include =20 #define HEADER_DESTINATION_IS_BROADCAST(header) \ ((async_header_get_destination(header) & 0x3f) =3D=3D 0x3f) diff --git a/drivers/firewire/packet-header-definitions.h b/drivers/firewir= e/packet-header-definitions.h index ab9d0fa790d4..87a5a31845c3 100644 --- a/drivers/firewire/packet-header-definitions.h +++ b/drivers/firewire/packet-header-definitions.h @@ -7,6 +7,8 @@ #ifndef _FIREWIRE_PACKET_HEADER_DEFINITIONS_H #define _FIREWIRE_PACKET_HEADER_DEFINITIONS_H =20 +#include + #define ASYNC_HEADER_QUADLET_COUNT 4 =20 #define ASYNC_HEADER_Q0_DESTINATION_SHIFT 16 diff --git a/include/trace/events/firewire.h b/include/trace/events/firewir= e.h index d695a560673f..1f4ef0ed65bc 100644 --- a/include/trace/events/firewire.h +++ b/include/trace/events/firewire.h @@ -11,7 +11,7 @@ =20 #include =20 -#include "../../../drivers/firewire/packet-header-definitions.h" +// Some macros are defined in 'drivers/firewire/packet-header-definitions.= h'. =20 // The content of TP_printk field is preprocessed, then put to the module = binary. #define ASYNC_HEADER_GET_DESTINATION(header) \ --=20 2.43.0 From nobody Thu Feb 12 23:08:57 2026 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DEC417A906 for ; Wed, 5 Jun 2024 23:52:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631545; cv=none; b=KjQAGbFaQAXgs2ujBCjvFVz1uuruDbWGTX9T3PtQbp9Bj+CxrjUnzuJNHKPgTswB5ujb7YhWwkKzogcK4Au8MOyIBdBFIozI8E47qXnJn3ss4KZrkHjnv8ceb7ck1I3y9tRZpFXZaLEtSEhfkTOZG4LbIKqjhOO3T0yFbML7GCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717631545; c=relaxed/simple; bh=puOjsXCpTLLDHFN23XdWATe1c+0fFNhQUGaNsCJYEfw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sKMp4+Pp0JkwakPixhT2wvBDxClVfvG5utVgHPVarpD3ygGwEYbsPAWktAg7EEl+skUvPl4V4iCwYchSFVQP8k7XA16vNSKj5ETC9tKajXTVg2tZK7SL6hPKmpA0wSr0hHAC/WVWM3Aq2E7pm2SxRKTQHB2WfZxuYh7FsLklOgY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=FCOyQRTQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DJ4yzf2m; arc=none smtp.client-ip=64.147.123.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="FCOyQRTQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DJ4yzf2m" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id A96771800124; Wed, 5 Jun 2024 19:52:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 05 Jun 2024 19:52:23 -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:subject:subject:to:to; s=fm1; t=1717631543; x= 1717717943; bh=mFLRPY8Emv7QgVYkbWBjf7n/0RQSBEsg8Su4xKUqlzM=; b=F COyQRTQp65TYKhNrarr04rO868DSMZRojvdmk8bPb6Yc7YlxjXWax4ndmBay0bKE gnoVq8qc3kdICfT1cwpFnMQ7JZF3eIySf2Qyd1OL99/73dFBGDLYxWbddsfHCnJn Tj5ukmzEpWg0vSl3qAW3XyN2hyWPJD8KZUhXb7hEvs+wFaOkh4RbRt+gIgm6YY0I zMyYVXMzKeP8dZxifVrCpn3q5oDfcHT97jnXAjA/M2EDnjwcR0DOy+McvPmEFWYN J5jqqSsav9z+jvcM+AlPb9+6ldjvq9r+Qu4JQ3PGzYzoagBO1nm5gyQ4a3JMFdr6 G8cuBOq1B1vaVox1E3H7Q== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717631543; x= 1717717943; bh=mFLRPY8Emv7QgVYkbWBjf7n/0RQSBEsg8Su4xKUqlzM=; b=D J4yzf2mCGdKbb46ZDM3jvxOZ63Fhljlm5j75BWzgmy92ALE+dy90hhvXt5HzdNTF Dg/OPYwsH7F7akZofd6YTLOuHAnGHCWQ9UAtPTsAYlU3+dXwO2lmOOKfQQ9MNmsQ Tm3VMu+/F5em76wgXyJQI8pmnlvOGUb+Wn9dJaeTWUQ0WnxVXljdwe+XRAH3v3Qs AkoVi4Idw77wIiDMSE4Oq1O/v96ZFa6zYAbj9QjTc88JmUmV4gWUjwg8WIK4rn2z 7TaYZOhcShX1JHmQKuZ52upXJLrJLAZ/1UyhHTqXLut7v5UXqbf4k2VmYuDmYeH+ NyvoJIpgqPhJ4Y7lhe9EQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeljedgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Jun 2024 19:52:22 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 11/11] firewire: core: add tracepoints event for self_id_sequence Date: Thu, 6 Jun 2024 08:51:55 +0900 Message-ID: <20240605235155.116468-12-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605235155.116468-1-o-takashi@sakamocchi.jp> References: <20240605235155.116468-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is helpful to trace the content of self ID sequence when the core function building bus topology. This commit adds a tracepoints event fot the purpose. It seems not to achieve printing variable length of array in print time without any storage, thus the structure of event includes a superfluous array to store the state of port. Additionally, there is no helper function to print symbol array, thus the state of port is printed as raw value. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-topology.c | 7 ++-- drivers/firewire/core-trace.c | 15 ++++++++ include/trace/events/firewire.h | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topol= ogy.c index 6ec100e17500..4a0b273392ab 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -95,7 +95,8 @@ static inline struct fw_node *fw_node(struct list_head *l) * internally consistent. On success this function returns the * fw_node corresponding to the local card otherwise NULL. */ -static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, in= t self_id_count) +static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, in= t self_id_count, + unsigned int generation) { struct self_id_sequence_enumerator enumerator =3D { .cursor =3D sid, @@ -139,6 +140,8 @@ static struct fw_node *build_tree(struct fw_card *card,= const u32 *sid, int self } =20 port_capacity =3D self_id_sequence_get_port_capacity(quadlet_count); + trace_self_id_sequence(self_id_sequence, quadlet_count, generation); + for (port_index =3D 0; port_index < port_capacity; ++port_index) { port_status =3D self_id_sequence_get_port_status(self_id_sequence, quad= let_count, port_index); @@ -482,7 +485,7 @@ void fw_core_handle_bus_reset(struct fw_card *card, int= node_id, int generation, card->bm_abdicate =3D bm_abdicate; fw_schedule_bm_work(card, 0); =20 - local_node =3D build_tree(card, self_ids, self_id_count); + local_node =3D build_tree(card, self_ids, self_id_count, generation); =20 update_topology_map(card, self_ids, self_id_count); =20 diff --git a/drivers/firewire/core-trace.c b/drivers/firewire/core-trace.c index 7cbf850f3719..c9bc4990d66e 100644 --- a/drivers/firewire/core-trace.c +++ b/drivers/firewire/core-trace.c @@ -2,7 +2,22 @@ // Copyright (c) 2024 Takashi Sakamoto =20 #include +#include #include "packet-header-definitions.h" +#include "phy-packet-definitions.h" =20 #define CREATE_TRACE_POINTS #include + +#ifdef TRACEPOINTS_ENABLED +void copy_port_status(u8 *port_status, unsigned int port_capacity, + const u32 *self_id_sequence, unsigned int quadlet_count) +{ + unsigned int port_index; + + for (port_index =3D 0; port_index < port_capacity; ++port_index) { + port_status[port_index] =3D + self_id_sequence_get_port_status(self_id_sequence, quadlet_count, port_= index); + } +} +#endif diff --git a/include/trace/events/firewire.h b/include/trace/events/firewir= e.h index 1f4ef0ed65bc..4761b700ff84 100644 --- a/include/trace/events/firewire.h +++ b/include/trace/events/firewire.h @@ -341,6 +341,65 @@ TRACE_EVENT(bus_reset_handle, ) ); =20 +// Some macros are defined in 'drivers/firewire/phy-packet-definitions.h'. + +// The content of TP_printk field is preprocessed, then put to the module = binary. + +#define PHY_PACKET_SELF_ID_GET_PHY_ID(quads) \ + ((((const u32 *)quads)[0] & SELF_ID_PHY_ID_MASK) >> SELF_ID_PHY_ID_SHIFT) + +#define PHY_PACKET_SELF_ID_GET_LINK_ACTIVE(quads) \ + ((((const u32 *)quads)[0] & SELF_ID_ZERO_LINK_ACTIVE_MASK) >> SELF_ID_ZER= O_LINK_ACTIVE_SHIFT) + +#define PHY_PACKET_SELF_ID_GET_GAP_COUNT(quads) \ + ((((const u32 *)quads)[0] & SELF_ID_ZERO_GAP_COUNT_MASK) >> SELF_ID_ZERO_= GAP_COUNT_SHIFT) + +#define PHY_PACKET_SELF_ID_GET_SCODE(quads) \ + ((((const u32 *)quads)[0] & SELF_ID_ZERO_SCODE_MASK) >> SELF_ID_ZERO_SCOD= E_SHIFT) + +#define PHY_PACKET_SELF_ID_GET_CONTENDER(quads) \ + ((((const u32 *)quads)[0] & SELF_ID_ZERO_CONTENDER_MASK) >> SELF_ID_ZERO_= CONTENDER_SHIFT) + +#define PHY_PACKET_SELF_ID_GET_POWER_CLASS(quads) \ + ((((const u32 *)quads)[0] & SELF_ID_ZERO_POWER_CLASS_MASK) >> SELF_ID_ZER= O_POWER_CLASS_SHIFT) + +#define PHY_PACKET_SELF_ID_GET_INITIATED_RESET(quads) \ + ((((const u32 *)quads)[0] & SELF_ID_ZERO_INITIATED_RESET_MASK) >> SELF_ID= _ZERO_INITIATED_RESET_SHIFT) + +void copy_port_status(u8 *port_status, unsigned int port_capacity, const u= 32 *self_id_sequence, + unsigned int quadlet_count); + +TRACE_EVENT(self_id_sequence, + TP_PROTO(const u32 *self_id_sequence, unsigned int quadlet_count, unsigne= d int generation), + TP_ARGS(self_id_sequence, quadlet_count, generation), + TP_STRUCT__entry( + __field(u8, generation) + __dynamic_array(u8, port_status, self_id_sequence_get_port_capacity(quad= let_count)) + __dynamic_array(u32, self_id_sequence, quadlet_count) + ), + TP_fast_assign( + __entry->generation =3D generation; + copy_port_status(__get_dynamic_array(port_status), __get_dynamic_array_l= en(port_status), + self_id_sequence, quadlet_count); + memcpy(__get_dynamic_array(self_id_sequence), self_id_sequence, + __get_dynamic_array_len(self_id_sequence)); + ), + TP_printk( + "generation=3D%u phy_id=3D0x%02x link_active=3D%s gap_count=3D%u scode= =3D%u contender=3D%s power_class=3D%u initiated_reset=3D%s port_status=3D%s= self_id_sequence=3D%s", + __entry->generation, + PHY_PACKET_SELF_ID_GET_PHY_ID(__get_dynamic_array(self_id_sequence)), + PHY_PACKET_SELF_ID_GET_LINK_ACTIVE(__get_dynamic_array(self_id_sequence)= ) ? "true" : "false", + PHY_PACKET_SELF_ID_GET_GAP_COUNT(__get_dynamic_array(self_id_sequence)), + PHY_PACKET_SELF_ID_GET_SCODE(__get_dynamic_array(self_id_sequence)), + PHY_PACKET_SELF_ID_GET_CONTENDER(__get_dynamic_array(self_id_sequence)) = ? "true" : "false", + PHY_PACKET_SELF_ID_GET_POWER_CLASS(__get_dynamic_array(self_id_sequence)= ), + PHY_PACKET_SELF_ID_GET_INITIATED_RESET(__get_dynamic_array(self_id_seque= nce)) ? "true" : "false", + __print_array(__get_dynamic_array(port_status), __get_dynamic_array_len(= port_status), 1), + __print_array(__get_dynamic_array(self_id_sequence), + __get_dynamic_array_len(self_id_sequence) / QUADLET_SIZE, QUADLET= _SIZE) + ) +); + #undef QUADLET_SIZE =20 #endif // _FIREWIRE_TRACE_EVENT_H --=20 2.43.0