Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp710613lqt; Thu, 6 Jun 2024 16:52:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUkWBCqr/1iclrMJMFdMO2Ebq+fXCiGkRn0+72WOE1h6q+SUXHJ+iIQ74qkXZv48KmcCldZ12NwyDadwALX4zsJ+zWuKuglXefKGQTu7w== X-Google-Smtp-Source: AGHT+IGFYkaaAhgp/Z8ioZHvkqF6qH8u1BK/dhps0FvRMzZq8fBLkAy/6mhUi/Hz5hNYUwx8qcXH X-Received: by 2002:a54:4515:0:b0:3d2:c88:14dc with SMTP id 5614622812f47-3d210d3317bmr1017141b6e.10.1717717921049; Thu, 06 Jun 2024 16:52:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717717921; cv=pass; d=google.com; s=arc-20160816; b=jYXPAmFJkrhi2e6uJwSymAsXc/VC7Suv/H6lNauRhpFUy+qQnGgZuutZjARyamly7r 7HG3UoenFTmEt6jxau39lsw5HUlvb+oj2r90E56hkAXcFGjAtTE2F0voxMtBwrrpfE2C d/trKteCpGCDFcVfhzNdfBXtY6BwWKdYjn6Y0DqZ3RymmOlHJgh6nUiw0S/RJY+DxfCe K9Ds3xp+D6CT5XKizwgvX0wu0UFDZmPZJsMbTw9XsUumgTHAufYosicGzQC3+pouyfOu r3EKdnR35njSk7eA2I3v0gmgnnTGBKL8eEIbxTFi9ihkrMR4hC6f3Hw2stb/RTcO7w4g v9yg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:feedback-id:dkim-signature:dkim-signature; bh=hgIseeRWLwrqaDf1AxemlHyL2UEM6IH/z/P6IZmSF1k=; fh=5EQyDiYgg+kua2A2AF9eJME8jasrrRA/Pgg86y+lzvY=; b=wfrZGeccpe0u/lATDqK2/q8CYRAq/hA5fhnNkImYD87NdLSiZBGHvHBrENaiE+sQTu h4WJ1W3gcnjAFfw8Jz/VJKzUTPkoQ9TryAuTEapv4rCBJ6dHhHOK9huLYzyma2ojo1+B iyVc/2jYCGmIV/LAsMB12Y+UwauZBMZh+CEs6ZUrtmomMiopM2FlypnsUv1k9ESHzOrC rq3mEBqHlt5o34ms8Dy1c7VDlZ8CdoMmH6d4ef7+ec4GnDZs6Phcr3N96EQtgdLFPPAs fJIFIgOW02VkuV9xyyu2jv84j5GD/A4My2c5qNGgi24v0Af74H9lIV7s1M3WmAvhnV+Z J8Xg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=fXI0rXUH; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=qwsTcpzn; arc=pass (i=1 spf=pass spfdomain=sakamocchi.jp dkim=pass dkdomain=sakamocchi.jp dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sakamocchi.jp); spf=pass (google.com: domain of linux-kernel+bounces-205170-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205170-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sakamocchi.jp Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-79537f5ef5dsi160445785a.786.2024.06.06.16.52.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 16:52:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205170-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm1 header.b=fXI0rXUH; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=qwsTcpzn; arc=pass (i=1 spf=pass spfdomain=sakamocchi.jp dkim=pass dkdomain=sakamocchi.jp dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sakamocchi.jp); spf=pass (google.com: domain of linux-kernel+bounces-205170-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205170-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sakamocchi.jp Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id ADF5B1C2371A for ; Thu, 6 Jun 2024 23:52:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 890171419BA; Thu, 6 Jun 2024 23:51:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="fXI0rXUH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qwsTcpzn" Received: from wfhigh4-smtp.messagingengine.com (wfhigh4-smtp.messagingengine.com [64.147.123.155]) (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 3A35B13E05C for ; Thu, 6 Jun 2024 23:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.155 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717717904; cv=none; b=h6GNOkU3PplIqC4SvIUDm/cJC6jEO2eoF/9kYwZ/Qps4q1jwunpa9G13gws9iovAWRtoRh9Q7EZdvO5H03L00s7vVK86l+mqRkZRtq4uWZ3jOmrVSf5bZWRVSsZggliyspHuMfKsV/FYBsFeD2EQSep0QN2dPcjMFB9symS2wAs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717717904; c=relaxed/simple; bh=Kmj+i0v+DFwKiujBpyuW7KQ0Fg35R84W8KNYnly7maw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kiPUNYhP8oZRQl3nVsEd54DlaxyW78jNymSRWRTQhOtZZXfGG8vBxRkP4PtrGNZBOq/EBDDRMNbJU8Ffvj0SZPeBZEuFdcaFWvnbP48VOmFIDsOFnrzYTJpdLwZ270/NgG+shDnKo7vh8QdZuHU0dsHpN1aC2zA0x30fIB2E3AU= 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=fXI0rXUH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qwsTcpzn; arc=none smtp.client-ip=64.147.123.155 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 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 5AE0118000BA; Thu, 6 Jun 2024 19:51:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 06 Jun 2024 19:51:41 -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=1717717901; x= 1717804301; bh=hgIseeRWLwrqaDf1AxemlHyL2UEM6IH/z/P6IZmSF1k=; b=f XI0rXUHUHazDHTPrgaB3xJ8mqp52t2aR3/wRZ4YQjLAfr1gIlPOAxxGaDqqPDr4t dIU6rHKnBa/b9CDVzkC/ZpZwMk4RXj7zidJvSzY45T++l5TkYTvtRVQDZtYKqiOB CxFIJR/AmqwfMpd1R9Ue6uWoqgmr66sZ5qrXl9XFyO/Va1T3+BrozV8PTJ4pSzQD lC9RG3J5mLpIwQ5gbz2ibyCUaunVlWZqHPlnNdGyxAUKr5nV4hJ8P033fYDGzWZs kftG/rZiCGaPm/NsjDLh1rJmi/+uZ4Wzxm9CFuLRP8w9ctGVhnlvs3CRdqiWRzJw tZr7YyUe8Wy80FsywWHLg== 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=1717717901; x= 1717804301; bh=hgIseeRWLwrqaDf1AxemlHyL2UEM6IH/z/P6IZmSF1k=; b=q wsTcpznBs+woSy2dl1UTr1YDYgDDwDCoRiDa5vmXcmQf//DhrNREzsfKCttmm4Gl CKNuN1oMGx1F7TvlES3fqGdZJAeOdSrTi6ZONHBRDNOwPFqO5HNtTgenyCn0WdA3 QI2ROKm92gUH9Fq/HgWtKPJtT6isJTtS4PrcOh49WE6SF4UMHC/RSDaunb1mVGvq lBTNeALsuPfjRZNbo9HZsfOsPQphqrKDvDdtmQ4ojc7agRQaxpk+rKf7uEO5pZKb u/DvAwi9k6d+KuaAhRxgIbPtZFczfO0I4lFkjjI1NHEh2kyF2ERE8lFuR6RK915N u12tLR39gMyzXjUbSraTA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelledgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 Jun 2024 19:51:39 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] firewire: core: add tests for serialization/deserialization of phy config packet Date: Fri, 7 Jun 2024 08:51:32 +0900 Message-ID: <20240606235133.231543-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240606235133.231543-1-o-takashi@sakamocchi.jp> References: <20240606235133.231543-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: 8bit In the protocol of IEEE 1394, phy configuration packet is broadcasted to the bus to configure all PHYs residing on the bus. It includes two purposes; selecting root node and optimizing gap count. This commit adds some helper function to serialize/deserialize the content of phy configuration packet, as well as some KUnit tests for it. Signed-off-by: Takashi Sakamoto --- drivers/firewire/packet-serdes-test.c | 79 +++++++++++++++++++++++ drivers/firewire/phy-packet-definitions.h | 55 ++++++++++++++++ 2 files changed, 134 insertions(+) diff --git a/drivers/firewire/packet-serdes-test.c b/drivers/firewire/packet-serdes-test.c index 65cfbf1baee7..35b966eec8a5 100644 --- a/drivers/firewire/packet-serdes-test.c +++ b/drivers/firewire/packet-serdes-test.c @@ -248,6 +248,29 @@ static void deserialize_phy_packet_self_id_extended(u32 quadlet, unsigned int *p *has_more_packets = phy_packet_self_id_get_more_packets(quadlet); } +static void serialize_phy_packet_phy_config(u32 *quadlet, unsigned int packet_identifier, + unsigned int root_id, bool has_force_root_node, + bool has_gap_count_optimization, unsigned int gap_count) +{ + phy_packet_set_packet_identifier(quadlet, packet_identifier); + phy_packet_phy_config_set_root_id(quadlet, root_id); + phy_packet_phy_config_set_force_root_node(quadlet, has_force_root_node); + phy_packet_phy_config_set_gap_count_optimization(quadlet, has_gap_count_optimization); + phy_packet_phy_config_set_gap_count(quadlet, gap_count); +} + +static void deserialize_phy_packet_phy_config(u32 quadlet, unsigned int *packet_identifier, + unsigned int *root_id, bool *has_force_root_node, + bool *has_gap_count_optimization, + unsigned int *gap_count) +{ + *packet_identifier = phy_packet_get_packet_identifier(quadlet); + *root_id = phy_packet_phy_config_get_root_id(quadlet); + *has_force_root_node = phy_packet_phy_config_get_force_root_node(quadlet); + *has_gap_count_optimization = phy_packet_phy_config_get_gap_count_optimization(quadlet); + *gap_count = phy_packet_phy_config_get_gap_count(quadlet); +} + static void test_async_header_write_quadlet_request(struct kunit *test) { static const u32 expected[ASYNC_HEADER_QUADLET_COUNT] = { @@ -811,6 +834,60 @@ static void test_phy_packet_self_id_zero_and_one(struct kunit *test) KUNIT_EXPECT_MEMEQ(test, quadlets, expected, sizeof(expected)); } +static void test_phy_packet_phy_config_force_root_node(struct kunit *test) +{ + const u32 expected = 0x02800000; + u32 quadlet = 0; + + unsigned int packet_identifier; + unsigned int root_id; + bool has_force_root_node; + bool has_gap_count_optimization; + unsigned int gap_count; + + deserialize_phy_packet_phy_config(expected, &packet_identifier, &root_id, + &has_force_root_node, &has_gap_count_optimization, + &gap_count); + + KUNIT_EXPECT_EQ(test, PHY_PACKET_PACKET_IDENTIFIER_PHY_CONFIG, packet_identifier); + KUNIT_EXPECT_EQ(test, 0x02, root_id); + KUNIT_EXPECT_TRUE(test, has_force_root_node); + KUNIT_EXPECT_FALSE(test, has_gap_count_optimization); + KUNIT_EXPECT_EQ(test, 0, gap_count); + + serialize_phy_packet_phy_config(&quadlet, packet_identifier, root_id, has_force_root_node, + has_gap_count_optimization, gap_count); + + KUNIT_EXPECT_EQ(test, quadlet, expected); +} + +static void test_phy_packet_phy_config_gap_count_optimization(struct kunit *test) +{ + const u32 expected = 0x034f0000; + u32 quadlet = 0; + + unsigned int packet_identifier; + unsigned int root_id; + bool has_force_root_node; + bool has_gap_count_optimization; + unsigned int gap_count; + + deserialize_phy_packet_phy_config(expected, &packet_identifier, &root_id, + &has_force_root_node, &has_gap_count_optimization, + &gap_count); + + KUNIT_EXPECT_EQ(test, PHY_PACKET_PACKET_IDENTIFIER_PHY_CONFIG, packet_identifier); + KUNIT_EXPECT_EQ(test, 0x03, root_id); + KUNIT_EXPECT_FALSE(test, has_force_root_node); + KUNIT_EXPECT_TRUE(test, has_gap_count_optimization); + KUNIT_EXPECT_EQ(test, 0x0f, gap_count); + + serialize_phy_packet_phy_config(&quadlet, packet_identifier, root_id, has_force_root_node, + has_gap_count_optimization, gap_count); + + KUNIT_EXPECT_EQ(test, quadlet, expected); +} + static struct kunit_case packet_serdes_test_cases[] = { KUNIT_CASE(test_async_header_write_quadlet_request), KUNIT_CASE(test_async_header_write_block_request), @@ -825,6 +902,8 @@ static struct kunit_case packet_serdes_test_cases[] = { 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), + KUNIT_CASE(test_phy_packet_phy_config_force_root_node), + KUNIT_CASE(test_phy_packet_phy_config_gap_count_optimization), {} }; diff --git a/drivers/firewire/phy-packet-definitions.h b/drivers/firewire/phy-packet-definitions.h index 8f78494ad371..03c7c606759f 100644 --- a/drivers/firewire/phy-packet-definitions.h +++ b/drivers/firewire/phy-packet-definitions.h @@ -21,6 +21,61 @@ static inline void phy_packet_set_packet_identifier(u32 *quadlet, unsigned int p *quadlet |= (packet_identifier << PACKET_IDENTIFIER_SHIFT) & PACKET_IDENTIFIER_MASK; } +#define PHY_PACKET_PACKET_IDENTIFIER_PHY_CONFIG 0 + +#define PHY_CONFIG_ROOT_ID_MASK 0x3f000000 +#define PHY_CONFIG_ROOT_ID_SHIFT 24 +#define PHY_CONFIG_FORCE_ROOT_NODE_MASK 0x00800000 +#define PHY_CONFIG_FORCE_ROOT_NODE_SHIFT 23 +#define PHY_CONFIG_GAP_COUNT_OPTIMIZATION_MASK 0x00400000 +#define PHY_CONFIG_GAP_COUNT_OPTIMIZATION_SHIFT 22 +#define PHY_CONFIG_GAP_COUNT_MASK 0x003f0000 +#define PHY_CONFIG_GAP_COUNT_SHIFT 16 + +static inline unsigned int phy_packet_phy_config_get_root_id(u32 quadlet) +{ + return (quadlet & PHY_CONFIG_ROOT_ID_MASK) >> PHY_CONFIG_ROOT_ID_SHIFT; +} + +static inline void phy_packet_phy_config_set_root_id(u32 *quadlet, unsigned int root_id) +{ + *quadlet &= ~PHY_CONFIG_ROOT_ID_MASK; + *quadlet |= (root_id << PHY_CONFIG_ROOT_ID_SHIFT) & PHY_CONFIG_ROOT_ID_MASK; +} + +static inline bool phy_packet_phy_config_get_force_root_node(u32 quadlet) +{ + return (quadlet & PHY_CONFIG_FORCE_ROOT_NODE_MASK) >> PHY_CONFIG_FORCE_ROOT_NODE_SHIFT; +} + +static inline void phy_packet_phy_config_set_force_root_node(u32 *quadlet, bool has_force_root_node) +{ + *quadlet &= ~PHY_CONFIG_FORCE_ROOT_NODE_MASK; + *quadlet |= (has_force_root_node << PHY_CONFIG_FORCE_ROOT_NODE_SHIFT) & PHY_CONFIG_FORCE_ROOT_NODE_MASK; +} + +static inline bool phy_packet_phy_config_get_gap_count_optimization(u32 quadlet) +{ + return (quadlet & PHY_CONFIG_GAP_COUNT_OPTIMIZATION_MASK) >> PHY_CONFIG_GAP_COUNT_OPTIMIZATION_SHIFT; +} + +static inline void phy_packet_phy_config_set_gap_count_optimization(u32 *quadlet, bool has_gap_count_optimization) +{ + *quadlet &= ~PHY_CONFIG_GAP_COUNT_OPTIMIZATION_MASK; + *quadlet |= (has_gap_count_optimization << PHY_CONFIG_GAP_COUNT_OPTIMIZATION_SHIFT) & PHY_CONFIG_GAP_COUNT_OPTIMIZATION_MASK; +} + +static inline unsigned int phy_packet_phy_config_get_gap_count(u32 quadlet) +{ + return (quadlet & PHY_CONFIG_GAP_COUNT_MASK) >> PHY_CONFIG_GAP_COUNT_SHIFT; +} + +static inline void phy_packet_phy_config_set_gap_count(u32 *quadlet, unsigned int gap_count) +{ + *quadlet &= ~PHY_CONFIG_GAP_COUNT_MASK; + *quadlet |= (gap_count << PHY_CONFIG_GAP_COUNT_SHIFT) & PHY_CONFIG_GAP_COUNT_MASK; +} + #define PHY_PACKET_PACKET_IDENTIFIER_SELF_ID 2 #define SELF_ID_PHY_ID_MASK 0x3f000000 -- 2.43.0