From nobody Fri Feb 13 00:31:59 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