From nobody Fri Dec 19 11:02:25 2025 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 B656B1DA305 for ; Tue, 2 Jul 2024 22:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958843; cv=none; b=U4ptYwsdDfayR6KEhoJ4daa80UDmqD8GEmw41tgvwtlRfq8zaeYrVcnIjiHAi/7JQVwZS6q28VJZH5sRh6KbdMnPg65iwtrrfZt5weKZ5PiRyTaKQdCd+Pb6wwYNI2i3LK982TF6wL0/0EYD++Iki6pvyXLzBq+AXLuTkhBnlto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958843; c=relaxed/simple; bh=a3w1NaKXzJXHpguonxHRTIK78MBDrlXZQHjMGFBZsYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hTmS9jrUjiryDlmHVh+8FY/FEk4tmphqEHcnBXvpy1Y4QCTsgcQMfO165aFxtVJNEJQySzG9VDLiy3r7eaRjX2ruc2zBUzj3FGlajV5KSx0rmlE902Z/fjoblzZ0NUFCq2/2+dDTDPoHp1hqR7/YCYIqjzQFB1eNEvs82AtoYRE= 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=R5jpVYNX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FiRZCrT8; arc=none smtp.client-ip=103.168.172.154 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="R5jpVYNX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FiRZCrT8" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7C29611401FA; Tue, 2 Jul 2024 18:20:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 02 Jul 2024 18:20:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1719958840; x= 1720045240; bh=EbApcb2/ZG1b4FTbJnSVe3gmHko9rsuV4/ihawAZkWM=; b=R 5jpVYNX+AnXMwzSz31HvDw/vaRZqRnhw+Q+Cv7wcAe6J7/N0HFozpBxKdTcSgeMP tIICfCYaFa4w22FLuZCjGl1P6/cOjrGsn4Ruy61QLGzRKp2uWdxnJWgmNwXJdE4j nEyO7jv+LtY4E5rdjxy1rrfOrZ262jQUp2/CrGrMMBn1z77qiX08Yn5rj1tXokb9 ohRUzo9yB5ZFf8No334ZP0OsHlXuxvm6LE31yZYCQaHV597iOw0Q1XTt4fdKzuRw yxrNrDl33Vva0eR/kQ8G+PU3l0EaiIvMsgy0gEFdsjzzTp+3wApXBJmqeR841+6I REgZsd5zGWeqccx/26nDg== 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=fm2; t=1719958840; x= 1720045240; bh=EbApcb2/ZG1b4FTbJnSVe3gmHko9rsuV4/ihawAZkWM=; b=F iRZCrT82916bi4M2IEzm9JnRWiVH/T0kwDANNWg3aMlrG3CvX4L/bGoQOC5P5nQS tNC5IFxxhGlEJ8L56QBcvqhy9nXSBW88isqxgSfUe/5aROXGLQNZNlBYESxTUWnu eOWnqqP3UDjndCenGOJtfgoWu3dtgzDUZahVNDlRHIjwSSv5uVZAT+fbhH9O8m0x 9Zj2nYlZrW53z82Kd4nfqXt10srnZnFuGa1V3OxZROch/LO8UwFCsC8EQSGgP5fM kfjCYdUKM7YDd7rEz9nbpK1HnVKPNyOxC9DNGcK2I4GWAp5K3EGPBPnYbS8YiN4G 6LeoPRZpkdzKzW8dGPs/A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jul 2024 18:20:39 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/5] firewire: ohci: use common macro to interpret be32 data in le32 buffer Date: Wed, 3 Jul 2024 07:20:30 +0900 Message-ID: <20240702222034.1378764-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240702222034.1378764-1-o-takashi@sakamocchi.jp> References: <20240702222034.1378764-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 1394 OHCI driver configures the hardware to transfer the data quadlets of packet via DMA after converting it to little endian, therefore the data is typed as __le32. Nevertheless some actual hardware ignores the configuration. In the case, the data in DMA buffer is aligned to big endian (__be32). For the case in big-endian machine, the driver includes the following interpretation from __le32 to u32 (host-endian =3D __be32): * (__force __u32)(v) In include/linux/byteorder/generic.h, be32_to_cpu() is available. It is expanded to the following expression in 'include/uapi/linux/byteorder/big_endian.h': * (__force __u32)(__be32)(x) This commit replace the ad-hoc endian interpretation with the above. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index df16a8f4ee7f..a2d6d1d1ec2b 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -876,7 +876,7 @@ static void ar_sync_buffers_for_cpu(struct ar_context *= ctx, =20 #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) #define cond_le32_to_cpu(v) \ - (ohci->quirks & QUIRK_BE_HEADERS ? (__force __u32)(v) : le32_to_cpu(v)) + (ohci->quirks & QUIRK_BE_HEADERS ? be32_to_cpu(v) : le32_to_cpu(v)) #else #define cond_le32_to_cpu(v) le32_to_cpu(v) #endif --=20 2.43.0 From nobody Fri Dec 19 11:02:25 2025 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 CDA2A1DA30B for ; Tue, 2 Jul 2024 22:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958844; cv=none; b=Teil/YGOmdoPl2LS4Bj/ICqaEXCmRX1dReN5GifII/LlZZhczObpoTlSicjj57QreeTT78n/272Vz5zXJ8Rn5jFaoih58Hxa501tAxVJ/0neoPoWpazufX9aNsatmg42qfWDVtqnpQsgc3766BMB50DvvkqAXYg3HUNhH32PfwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958844; c=relaxed/simple; bh=igV8auFnypklRCHzN9sXLhaA8n/nhB5hXwLqbpBrO/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ifur5leXhv7+rU0VN7Bi6cKv8lcf86YJyco938OsMlPsXL4/A0LqKtIaEWQOS9kp76VyHXISXYou5JASTpMFx0vBgPInhAWnduXwL1KwEUh6UGIBu7G8a00uMYCB0Ej3kV3Ez03P+lvgrLqZyUl4dV922bFdCRCFDPjv+t2ft7A= 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=WpbYje2d; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YoCUocon; arc=none smtp.client-ip=103.168.172.149 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="WpbYje2d"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YoCUocon" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id EF282138029E; Tue, 2 Jul 2024 18:20:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 02 Jul 2024 18:20: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=fm2; t=1719958841; x= 1720045241; bh=etDpKLQEG9p50XNu4SoX4u7Bb/CdovZOaSYuiOBy3+I=; b=W pbYje2dXayXePLYb8bBbUOX1tFV5QSEYRDUuXKTFfCRFhf6msYQldwzN/b73dATJ O2DaZ0V0k9iKJytVwpXNESW48Rv1sxeBhxHM3fBJ6PWdQxa1N1Tj0JJkZ7+wzEC0 1VTX5CHV4TTDTjHZfH/5SpxoU2J+Of8vi2cOipWZRlkGREdYm7LI9Ok6gh0y8+qX 9Oki0j8F5rEWIw21a57xiJO4q83V7rdUhINwvU12GrTevo2VNcdY99dek7Cbc7dH y8jEYeBNZohZZsTbfpjayyJR1DOkQnDqkb6EdjIe9Hw/Kv6W5F1ypeejFp7fV/7f YG6becVhIxq6tQMMWOWMg== 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=fm2; t=1719958841; x= 1720045241; bh=etDpKLQEG9p50XNu4SoX4u7Bb/CdovZOaSYuiOBy3+I=; b=Y oCUoconE5n1sy1F2V7k3/L5fV7cPd68p3kBJJN3HGkX4Hheo943yY4hWzzJyifLl rLxkwZDEnRHzNRlsEZycXvjCVE9NJvggMy0Bakr9VXTNxZ4XeNObw9Nx758reuY4 OXGp3Rr0/vEA45DKuRLkJFTk1WQilSNIWfEaqKNDt5IuOHI8XiaiWmmTVCpoNMle J1f+kjKUavmTYmZXTkLEiTFQpRzhkeOyDypz3IKKDOFfO8Y6v1yXdfC0lUjH+lLX zWGhvNpsT+iaQUV8iLkUg8J8VPxJ8qIek8rIg6F04sntDc8ZzOYqlO4t3SE2t0jZ v/sKoOtfMmriheuVQoMaw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jul 2024 18:20:40 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/5] firewire: ohci: use static function to handle endian issue on PowerPC platform Date: Wed, 3 Jul 2024 07:20:31 +0900 Message-ID: <20240702222034.1378764-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240702222034.1378764-1-o-takashi@sakamocchi.jp> References: <20240702222034.1378764-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 preferable to use static function instead of functional macro in some points. It checks type of argument, but would be optimized to embedded code instead of function calls. This commit obsoletes the functional macro with the static function. Additionally this commit refactors quirk detection to ease the later work. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index a2d6d1d1ec2b..5b90ca72fa64 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -875,10 +875,25 @@ static void ar_sync_buffers_for_cpu(struct ar_context= *ctx, } =20 #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) -#define cond_le32_to_cpu(v) \ - (ohci->quirks & QUIRK_BE_HEADERS ? be32_to_cpu(v) : le32_to_cpu(v)) +static u32 cond_le32_to_cpu(__le32 value, bool has_be_header_quirk) +{ + return has_be_header_quirk ? be32_to_cpu(value) : le32_to_cpu(value); +} + +static bool has_be_header_quirk(const struct fw_ohci *ohci) +{ + return !!(ohci->quirks & QUIRK_BE_HEADERS); +} #else -#define cond_le32_to_cpu(v) le32_to_cpu(v) +static u32 cond_le32_to_cpu(__le32 value, bool has_be_header_quirk __maybe= _unused) +{ + return le32_to_cpu(value); +} + +static bool has_be_header_quirk(const struct fw_ohci *ohci) +{ + return false; +} #endif =20 static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) @@ -888,9 +903,9 @@ static __le32 *handle_ar_packet(struct ar_context *ctx,= __le32 *buffer) u32 status, length, tcode; int evt; =20 - p.header[0] =3D cond_le32_to_cpu(buffer[0]); - p.header[1] =3D cond_le32_to_cpu(buffer[1]); - p.header[2] =3D cond_le32_to_cpu(buffer[2]); + p.header[0] =3D cond_le32_to_cpu(buffer[0], has_be_header_quirk(ohci)); + p.header[1] =3D cond_le32_to_cpu(buffer[1], has_be_header_quirk(ohci)); + p.header[2] =3D cond_le32_to_cpu(buffer[2], has_be_header_quirk(ohci)); =20 tcode =3D async_header_get_tcode(p.header); switch (tcode) { @@ -902,7 +917,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx,= __le32 *buffer) break; =20 case TCODE_READ_BLOCK_REQUEST : - p.header[3] =3D cond_le32_to_cpu(buffer[3]); + p.header[3] =3D cond_le32_to_cpu(buffer[3], has_be_header_quirk(ohci)); p.header_length =3D 16; p.payload_length =3D 0; break; @@ -911,7 +926,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx,= __le32 *buffer) case TCODE_READ_BLOCK_RESPONSE: case TCODE_LOCK_REQUEST: case TCODE_LOCK_RESPONSE: - p.header[3] =3D cond_le32_to_cpu(buffer[3]); + p.header[3] =3D cond_le32_to_cpu(buffer[3], has_be_header_quirk(ohci)); p.header_length =3D 16; p.payload_length =3D async_header_get_data_length(p.header); if (p.payload_length > MAX_ASYNC_PAYLOAD) { @@ -936,7 +951,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx,= __le32 *buffer) =20 /* FIXME: What to do about evt_* errors? */ length =3D (p.header_length + p.payload_length + 3) / 4; - status =3D cond_le32_to_cpu(buffer[length]); + status =3D cond_le32_to_cpu(buffer[length], has_be_header_quirk(ohci)); evt =3D (status >> 16) & 0x1f; =20 p.ack =3D evt - 16; @@ -2030,12 +2045,12 @@ static void bus_reset_work(struct work_struct *work) return; } =20 - generation =3D (cond_le32_to_cpu(ohci->self_id[0]) >> 16) & 0xff; + generation =3D (cond_le32_to_cpu(ohci->self_id[0], has_be_header_quirk(oh= ci)) >> 16) & 0xff; rmb(); =20 for (i =3D 1, j =3D 0; j < self_id_count; i +=3D 2, j++) { - u32 id =3D cond_le32_to_cpu(ohci->self_id[i]); - u32 id2 =3D cond_le32_to_cpu(ohci->self_id[i + 1]); + u32 id =3D cond_le32_to_cpu(ohci->self_id[i], has_be_header_quirk(ohci)= ); + u32 id2 =3D cond_le32_to_cpu(ohci->self_id[i + 1], has_be_header_quirk(o= hci)); =20 if (id !=3D ~id2) { /* --=20 2.43.0 From nobody Fri Dec 19 11:02:25 2025 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 7B1EE17A580 for ; Tue, 2 Jul 2024 22:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958846; cv=none; b=ZXDLnMa53n1Lmlfp89DinkTMPa4XYm8cJ3gPrY+FkEOd+JPHN1b6NL2Q+jWH4vtQcuRB6nhncZJ0KC6HT/dmjD6+dz80wiPxC7ZiOiiLKbBh5QZaif996qCd5Dn2DxPdwp4qfT2ayMhFbiuVkT68p3VIpVo4w2BSdwxs1iorDAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958846; c=relaxed/simple; bh=cW1PaWPoUro0FwYsinK+HNJjsOZpL+zet4AFH0rZ11s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ioLyPK3tmS2N1J6ImxfjnYOcFSELcAHhwiEox75qUA6ihzhwvSM2c1lSoQtoHCEcNtjClCEqNGtf47PP6q2N7UCNwmk4Z1Gg5eNDftc4I++OTx7mtf9zuu3/hFcnHxMk4atHpIrrNeCA1Q7v8szF+7voJDdL/KrZ7k8I/ivOSzI= 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=jAa5HVXD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Pzyee007; arc=none smtp.client-ip=103.168.172.149 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="jAa5HVXD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Pzyee007" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 7EF221380297; Tue, 2 Jul 2024 18:20:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 02 Jul 2024 18:20:43 -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=fm2; t=1719958843; x= 1720045243; bh=NtOsPI/vL3wkycVVvPccbjCj69PvW3xTQTZrO5lK/Gg=; b=j Aa5HVXDC1BrRBAqox3y0ZJ2XsqGqXFPVVZ66cuHpQXFRjVJffTpaOfcZ5Get8xJ8 VP3upThf+DFciHW409tuOU1toSaLbBFon8/DVpbX55erGnToYcNyHgXLv7N9CF9R zfR/HT3pV3fqbO6I7598S0NdHOvviWmXysiblWyJAERkvXRwiu/9dITVhU0LgjYw SC/kZSi/ZqNNyt40xS0HZ/QeCQY/2duGVX0rm1xYP88fPDSDVkwG+yGvZDrPlpV1 E03ALQcIjhyhRDwh9wzimVauMWtQwDWE3nsK4GGHRNrkuqgYsg0pj1mmhvhOtDWr Ml8M+fTCayJqYtesNseRw== 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=fm2; t=1719958843; x= 1720045243; bh=NtOsPI/vL3wkycVVvPccbjCj69PvW3xTQTZrO5lK/Gg=; b=P zyee007aju4PWEd3f6jXMz2jWty6G2u/MWM6b8EEI+XuWTHKF4J3zLVhVXkCJxCg R65D5leqasqyV59xt0WiwEaJnTcRA0RMJ1wy12zeXpFD0vvEHHo0x2g+b2Tpzu1O C38RHo55L7zkEsSJE9sOp8a96SktWDKq9NnY8j7C8nr6ML4iSBt5GIeA+4UhMnuO Z63wLcWNm2YsELwp7rxvTXiUmjs956nZlcmVpDqM9pSd+QXBrpuZ3gtDLln4s9FD 7mwF3sYTndc19LBhzLbMyyusBvx5SQ2qfzwSzoa/UgLLY9W0djVkcmamh95oytBP fQJMBzGYPZbsiEO6wAYGw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepuefgvedtfe fhfeefueduudfhkefhgfevjeefieeiffdttefhudduveejkeevffelnecuffhomhgrihhn pehtvghsthgrnhihthhhihhnghdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdr jhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jul 2024 18:20:42 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/5] firewire: ohci: add static inline functions to deserialize for Self-ID DMA operation Date: Wed, 3 Jul 2024 07:20:32 +0900 Message-ID: <20240702222034.1378764-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240702222034.1378764-1-o-takashi@sakamocchi.jp> References: <20240702222034.1378764-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 SelfI-ID is one type of DMAs defined in 1394 OHCI specification. It is operated by two registers, one interrupt, and has one format of buffer. This commit adds some static inline functions to deserialize the data in the buffer and registers. Some KUnit tests are also added to check their reliability. Signed-off-by: Takashi Sakamoto --- drivers/firewire/.kunitconfig | 1 + drivers/firewire/Kconfig | 16 +++++++++ drivers/firewire/Makefile | 1 + drivers/firewire/ohci-serdes-test.c | 56 +++++++++++++++++++++++++++++ drivers/firewire/ohci.h | 42 ++++++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 drivers/firewire/ohci-serdes-test.c diff --git a/drivers/firewire/.kunitconfig b/drivers/firewire/.kunitconfig index 74259204fcdd..21b7e9eef63d 100644 --- a/drivers/firewire/.kunitconfig +++ b/drivers/firewire/.kunitconfig @@ -5,3 +5,4 @@ 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 +CONFIG_FIREWIRE_KUNIT_OHCI_SERDES_TEST=3Dy diff --git a/drivers/firewire/Kconfig b/drivers/firewire/Kconfig index 95e72e0b592b..905c82e26ce7 100644 --- a/drivers/firewire/Kconfig +++ b/drivers/firewire/Kconfig @@ -92,6 +92,22 @@ config FIREWIRE_OHCI To compile this driver as a module, say M here: The module will be called firewire-ohci. =20 +config FIREWIRE_KUNIT_OHCI_SERDES_TEST + tristate "KUnit tests for serialization/deserialization of data in buffer= s/registers" if !KUNIT_ALL_TESTS + depends on FIREWIRE && KUNIT + default KUNIT_ALL_TESTS + help + This builds the KUnit tests to check serialization and deserialization + of data in buffers and registers defined in 1394 OHCI specification. + + 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_SBP2 tristate "Storage devices (SBP-2 protocol)" depends on FIREWIRE && SCSI diff --git a/drivers/firewire/Makefile b/drivers/firewire/Makefile index 21b975e0a387..1ff550e93a8c 100644 --- a/drivers/firewire/Makefile +++ b/drivers/firewire/Makefile @@ -19,3 +19,4 @@ obj-$(CONFIG_PROVIDE_OHCI1394_DMA_INIT) +=3D init_ohci139= 4_dma.o 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 +obj-$(CONFIG_FIREWIRE_KUNIT_OHCI_SERDES_TEST) +=3D ohci-serdes-test.o diff --git a/drivers/firewire/ohci-serdes-test.c b/drivers/firewire/ohci-se= rdes-test.c new file mode 100644 index 000000000000..304a09ff528e --- /dev/null +++ b/drivers/firewire/ohci-serdes-test.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// +// ohci-serdes-test.c - An application of Kunit to check serialization/des= erialization of data in +// buffers and registers defined in 1394 OHCI specification. +// +// Copyright (c) 2024 Takashi Sakamoto + +#include + +#include "ohci.h" + + +static void test_self_id_count_register_deserialization(struct kunit *test) +{ + const u32 expected =3D 0x803d0594; + + bool is_error =3D ohci1394_self_id_count_is_error(expected); + u8 generation =3D ohci1394_self_id_count_get_generation(expected); + u32 size =3D ohci1394_self_id_count_get_size(expected); + + KUNIT_EXPECT_TRUE(test, is_error); + KUNIT_EXPECT_EQ(test, 0x3d, generation); + KUNIT_EXPECT_EQ(test, 0x165, size); +} + +static void test_self_id_receive_buffer_deserialization(struct kunit *test) +{ + const u32 buffer[] =3D { + 0x0006f38b, + 0x807fcc56, + 0x7f8033a9, + 0x8145cc5e, + 0x7eba33a1, + }; + + u8 generation =3D ohci1394_self_id_receive_q0_get_generation(buffer[0]); + u16 timestamp =3D ohci1394_self_id_receive_q0_get_timestamp(buffer[0]); + + KUNIT_EXPECT_EQ(test, 0x6, generation); + KUNIT_EXPECT_EQ(test, 0xf38b, timestamp); +} + +static struct kunit_case ohci_serdes_test_cases[] =3D { + KUNIT_CASE(test_self_id_count_register_deserialization), + KUNIT_CASE(test_self_id_receive_buffer_deserialization), + {} +}; + +static struct kunit_suite ohci_serdes_test_suite =3D { + .name =3D "firewire-ohci-serdes", + .test_cases =3D ohci_serdes_test_cases, +}; +kunit_test_suite(ohci_serdes_test_suite); + +MODULE_DESCRIPTION("FireWire buffers and registers serialization/deseriali= zation unit test suite"); +MODULE_LICENSE("GPL"); diff --git a/drivers/firewire/ohci.h b/drivers/firewire/ohci.h index c4d005a9901a..d83fd4731d56 100644 --- a/drivers/firewire/ohci.h +++ b/drivers/firewire/ohci.h @@ -156,4 +156,46 @@ =20 #define OHCI1394_phy_tcode 0xe =20 +// Self-ID DMA. + +#define OHCI1394_SelfIDCount_selfIDError_MASK 0x80000000 +#define OHCI1394_SelfIDCount_selfIDError_SHIFT 31 +#define OHCI1394_SelfIDCount_selfIDGeneration_MASK 0x00ff0000 +#define OHCI1394_SelfIDCount_selfIDGeneration_SHIFT 16 +#define OHCI1394_SelfIDCount_selfIDSize_MASK 0x000007fc +#define OHCI1394_SelfIDCount_selfIDSize_SHIFT 2 + +static inline bool ohci1394_self_id_count_is_error(u32 value) +{ + return !!((value & OHCI1394_SelfIDCount_selfIDError_MASK) >> OHCI1394_Sel= fIDCount_selfIDError_SHIFT); +} + +static inline u8 ohci1394_self_id_count_get_generation(u32 value) +{ + return (value & OHCI1394_SelfIDCount_selfIDGeneration_MASK) >> OHCI1394_S= elfIDCount_selfIDGeneration_SHIFT; +} + +// In 1394 OHCI specification, the maximum size of self ID stream is 504 q= uadlets +// (=3D 63 devices * 4 self ID packets * 2 quadlets). The selfIDSize field= accommodates it and its +// additional first quadlet, since the field is 9 bits (0x1ff =3D 511). +static inline u32 ohci1394_self_id_count_get_size(u32 value) +{ + return (value & OHCI1394_SelfIDCount_selfIDSize_MASK) >> OHCI1394_SelfIDC= ount_selfIDSize_SHIFT; +} + +#define OHCI1394_SELF_ID_RECEIVE_Q0_GENERATION_MASK 0x00ff0000 +#define OHCI1394_SELF_ID_RECEIVE_Q0_GENERATION_SHIFT 16 +#define OHCI1394_SELF_ID_RECEIVE_Q0_TIMESTAMP_MASK 0x0000ffff +#define OHCI1394_SELF_ID_RECEIVE_Q0_TIMESTAMP_SHIFT 0 + +static inline u8 ohci1394_self_id_receive_q0_get_generation(u32 quadlet0) +{ + return (quadlet0 & OHCI1394_SELF_ID_RECEIVE_Q0_GENERATION_MASK) >> OHCI13= 94_SELF_ID_RECEIVE_Q0_GENERATION_SHIFT; +} + +static inline u16 ohci1394_self_id_receive_q0_get_timestamp(u32 quadlet0) +{ + return (quadlet0 & OHCI1394_SELF_ID_RECEIVE_Q0_TIMESTAMP_MASK) >> OHCI139= 4_SELF_ID_RECEIVE_Q0_TIMESTAMP_SHIFT; +} + #endif /* _FIREWIRE_OHCI_H */ --=20 2.43.0 From nobody Fri Dec 19 11:02:25 2025 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 DE97217A5A4 for ; Tue, 2 Jul 2024 22:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958847; cv=none; b=btv7shZQAGwdFV2vxDc4wasRKGR73AimFZyq+NCvz/W+GlYnM6uUfRkH1jbdIHnjatgRYAg1+0SH0wggovAhwR5ol0t+8Sia5zU2mtMTeTcx5ouLxD9iA7cMzdDwwDtStLhyqYTCe7GQ4mZLJYlMqCkkenpGV54RHEGQHSllDkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958847; c=relaxed/simple; bh=FAjamNAqol9oFFwGy78qp37v4RAzWv+5EK5yNCkx7zM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WroTONbfm7PYk0T0qJi/HOwjlmqfJ6Oovao+6Wa8vfm+A6n1S8sENQOMNcDaBZlDiMqUzKWx3Fkw3oPmX8QYAsyEtShAkU9DghCevvz/OZHzIc5R0/GB0E61Tio0Tvf0j7sxqR8o9ZwZ7sFJ37N5fqvwAuKN5Ep+MjRMl9Rl9ik= 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=Y9PSy9V9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=c94TL3NO; arc=none smtp.client-ip=103.168.172.149 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="Y9PSy9V9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="c94TL3NO" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 0BCC113802A7; Tue, 2 Jul 2024 18:20:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 02 Jul 2024 18:20:45 -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=fm2; t=1719958845; x= 1720045245; bh=ody5HCrdHgBlLUVNyBxe9FK0hNGkd1ti0Yfpg/IrLj0=; b=Y 9PSy9V9NLsyVpuHiZW54jxXen4AvlvDfSlNRHKO70vfnTX38pUtwQHqrFroIzLIG 9Wfqor5dkYX+4sOf1940a6fil8oC/UGcrLH9fEwTjkihTGDEFW1ExgPWIR1JwW73 PQPcKH1pEVCggJYEtk39P8aRheK4dsD3bl7vdRWLoUWJY+oqYizj3O3o6IFUJsxK mrA3UMzegYLJdqwcHT64CQegZnK23q9xoaP1dHd1xxPyJlcVTD1VtL9BZVbUZvC1 iGKCRlzxNg9ZU9jlUf1+qk2UjBqUnPODqJwVgR/GKHUunkkthIXQk1OWi8WwNHr2 985Q9EIXtOClrH1PaV+fg== 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=fm2; t=1719958845; x= 1720045245; bh=ody5HCrdHgBlLUVNyBxe9FK0hNGkd1ti0Yfpg/IrLj0=; b=c 94TL3NOb/yhWq3K/UtRbcAzGOXjMF5XQaP5nyIgWTC49MHa7n5SKWsrBKL4lyxpi E0JJofEQBGnCgT5IPIzcn8Q5gqQfZudMGZDKQh2HYwgA8VUFCD+bEP2eFMgqeeXP CO9PiOZi6t5w5mmaleNQzkxF2j9sCj0dtbhgWZOW2EVlLl9N14eexxjBIPJ+Fmvd 7tLbuKS79bPeFUUfWCpgiw5iJMWgf+XKpHGaZQ9dhD+ltg2Pb3Oed/iYJerYcthf +9KsmnNbJZ5gyt+SUEWMTrvYP1mwI0+h4H2afIRbaunWzUsXs3jL91BAYRiuiBzX usaJw26t7CG3HFA6ATL8Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jul 2024 18:20:43 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/5] firewire: ohci: use inline functions to operate data of self-ID DMA Date: Wed, 3 Jul 2024 07:20:33 +0900 Message-ID: <20240702222034.1378764-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240702222034.1378764-1-o-takashi@sakamocchi.jp> References: <20240702222034.1378764-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 code of 1394 OHCI driver includes hard-coded magic number to operate data of Self-ID DMA. This commit replaces them with the inline functions added/tested in the former commit. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 12 +++++++----- drivers/firewire/ohci.h | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 5b90ca72fa64..c95f26c74e2b 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -2003,7 +2003,7 @@ static void bus_reset_work(struct work_struct *work) struct fw_ohci *ohci =3D container_of(work, struct fw_ohci, bus_reset_work); int self_id_count, generation, new_generation, i, j; - u32 reg; + u32 reg, quadlet; void *free_rom =3D NULL; dma_addr_t free_rom_bus =3D 0; bool is_new_root; @@ -2028,7 +2028,7 @@ static void bus_reset_work(struct work_struct *work) ohci->is_root =3D is_new_root; =20 reg =3D reg_read(ohci, OHCI1394_SelfIDCount); - if (reg & OHCI1394_SelfIDCount_selfIDError) { + if (ohci1394_self_id_count_is_error(reg)) { ohci_notice(ohci, "self ID receive error\n"); return; } @@ -2038,14 +2038,15 @@ static void bus_reset_work(struct work_struct *work) * the inverted quadlets and a header quadlet, we shift one * bit extra to get the actual number of self IDs. */ - self_id_count =3D (reg >> 3) & 0xff; + self_id_count =3D ohci1394_self_id_count_get_size(reg) >> 1; =20 if (self_id_count > 252) { ohci_notice(ohci, "bad selfIDSize (%08x)\n", reg); return; } =20 - generation =3D (cond_le32_to_cpu(ohci->self_id[0], has_be_header_quirk(oh= ci)) >> 16) & 0xff; + quadlet =3D cond_le32_to_cpu(ohci->self_id[0], has_be_header_quirk(ohci)); + generation =3D ohci1394_self_id_receive_q0_get_generation(quadlet); rmb(); =20 for (i =3D 1, j =3D 0; j < self_id_count; i +=3D 2, j++) { @@ -2102,7 +2103,8 @@ static void bus_reset_work(struct work_struct *work) * of self IDs. */ =20 - new_generation =3D (reg_read(ohci, OHCI1394_SelfIDCount) >> 16) & 0xff; + reg =3D reg_read(ohci, OHCI1394_SelfIDCount); + new_generation =3D ohci1394_self_id_count_get_generation(reg); if (new_generation !=3D generation) { ohci_notice(ohci, "new bus reset, discarding self ids\n"); return; diff --git a/drivers/firewire/ohci.h b/drivers/firewire/ohci.h index d83fd4731d56..71c2ed84cafb 100644 --- a/drivers/firewire/ohci.h +++ b/drivers/firewire/ohci.h @@ -31,7 +31,6 @@ #define OHCI1394_HCControl_softReset 0x00010000 #define OHCI1394_SelfIDBuffer 0x064 #define OHCI1394_SelfIDCount 0x068 -#define OHCI1394_SelfIDCount_selfIDError 0x80000000 #define OHCI1394_IRMultiChanMaskHiSet 0x070 #define OHCI1394_IRMultiChanMaskHiClear 0x074 #define OHCI1394_IRMultiChanMaskLoSet 0x078 --=20 2.43.0 From nobody Fri Dec 19 11:02:25 2025 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 3884D17A5BF for ; Tue, 2 Jul 2024 22:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958848; cv=none; b=Wmiy46jAJtAY7B11+fM8xataIeriw5YXpLg56MA0yQZU8TSbcduntz59hXTvV5Guv9gurCjr/PlRVt+BUa6eQZ9L8kS8IMwD4tt0AyzJy4UoaFvdgWfB+VKDJjFFIF2YWewakY6sr2fsLaLRhemLITgvM6r0zp/3KdCuYTahV/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719958848; c=relaxed/simple; bh=jbcMa376uObBTkouPaJPfroBY9kEJbXMkW0Yopmlbb8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hEMR8lS1P96LxT/OqJ6dPHsBQboxZM5YDbd67G//DU4fjdPEavYnFWKaq3MKdEJoJwlfDRILqQWsl86hk9kGatGsHnVV/qdkfkQK5FUV7EgdF5pswQpat3FewN1SZdvAIAwh0Fg5iWBqtNV6hbu5lTIFHP+jvJV6YD5wZFXhhfM= 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=hBajqO7k; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CmvlRRE1; arc=none smtp.client-ip=103.168.172.154 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="hBajqO7k"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CmvlRRE1" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 80E1E114023D; Tue, 2 Jul 2024 18:20:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 02 Jul 2024 18:20:46 -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=fm2; t=1719958846; x= 1720045246; bh=IPVHX16LbTeOoMwyZ1FrhOHGKcwF2+L0k84yqEHpcRo=; b=h BajqO7k8Kdl2+Nvvn0KZYIm4FuG3GIk8aFoXaZtuyVzoCuv2ainunQ3ysZF453vQ jIdw7Nms7oJfjYFACUcUEQdenPtCqOn1zCPE6oqwQdOjhecjs8bj7hSdMWE/81bO 5xrfnr4mzCcugPn59scMxRS4a18Gkya7bWJrLU7gO56nCLvTAQ0r8ieoiac+618S XClmfWsGIKklfXPWx4n8SOTX1bJ7yhO8gicPWi854Y4WzRYg653bDAKGvyN40D8d DJTVkgadVtMQjuOxLGSv3BCJWEaoij0UW6qjvzBKuKTiWKc6lXcyq738yKH6otGY SzHSvWdS+8ZYEt/K1FQKg== 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=fm2; t=1719958846; x= 1720045246; bh=IPVHX16LbTeOoMwyZ1FrhOHGKcwF2+L0k84yqEHpcRo=; b=C mvlRRE1v9QEud7/88ydddrViWfl1+NGTyrNwKWfNvVEXAlp8wfiAGgERzWHnZQr0 VKzL7B2DFNYDUKHEp6rAhmKUcVliyag8KRW1iQzaYxjvclNDjaNguXCDEJOBrT0U Rm3MH0qEGx9OoV1RN8PR59wG3XXjx4NwGR3V00IZ+tpEvNvf5rZAIQ6y4AJNiClJ lUmtNIeBQLUU8EmTT8GT92Lsf0ktUzNBpjwhYD+6mfnV+AA7e86uam18e3rXzOfS +6xSPYZfRioJhZE526oUNVNOwl/jSTwx8m2dYJkQa/FasESMgyl3gNEz9OXVFk7t 3mt9j6qkAlV08QKz1/5EA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeigddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepjedvteetud fhiedvheegiedvkefgkedtleeftdetleejkedvueekheekvdfggfevnecuffhomhgrihhn pehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jul 2024 18:20:45 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/5] firewire: ohci: add tracepoints event for data of Self-ID DMA Date: Wed, 3 Jul 2024 07:20:34 +0900 Message-ID: <20240702222034.1378764-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240702222034.1378764-1-o-takashi@sakamocchi.jp> References: <20240702222034.1378764-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" In 1394 OHCI, the SelfIDComplete event occurs when the hardware has finished transmitting all of the self ID packets received during the bus initialization process to the host memory by DMA. This commit adds a tracepoints event for this event to trace the timing and packet data of Self-ID DMA. It is the part of following tracepoints events helpful to debug some events at bus reset; e.g. the issue addressed at a commit d0b06dc48fb1 ("firewire: core: use long bus reset on gap count error")[1]: * firewire_ohci:irqs * firewire_ohci:self_id_complete * firewire:bus_reset_handle * firewire:self_id_sequence They would be also helpful in the problem about invocation timing of hardIRQ/softIRQ contexts. We can often see this kind of problem with -rt kernel[2]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/comm= it/?id=3Dd0b06dc48fb1 [2] https://lore.kernel.org/linux-rt-users/YAwPoaUZ1gTD5y+k@hmbx/ Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 11 +++++- include/trace/events/firewire_ohci.h | 54 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index c95f26c74e2b..f8d880574c19 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -45,6 +45,8 @@ =20 #include =20 +static u32 cond_le32_to_cpu(__le32 value, bool has_be_header_quirk); + #define CREATE_TRACE_POINTS #include =20 @@ -2208,8 +2210,15 @@ static irqreturn_t irq_handler(int irq, void *data) if (event & OHCI1394_busReset) reg_write(ohci, OHCI1394_IntMaskClear, OHCI1394_busReset); =20 - if (event & OHCI1394_selfIDComplete) + if (event & OHCI1394_selfIDComplete) { + if (trace_self_id_complete_enabled()) { + u32 reg =3D reg_read(ohci, OHCI1394_SelfIDCount); + + trace_self_id_complete(ohci->card.index, reg, ohci->self_id, + has_be_header_quirk(ohci)); + } queue_work(selfid_workqueue, &ohci->bus_reset_work); + } =20 if (event & OHCI1394_RQPkt) tasklet_schedule(&ohci->ar_request_ctx.tasklet); diff --git a/include/trace/events/firewire_ohci.h b/include/trace/events/fi= rewire_ohci.h index 483aeeb033af..4f9a7f2577f3 100644 --- a/include/trace/events/firewire_ohci.h +++ b/include/trace/events/firewire_ohci.h @@ -9,6 +9,8 @@ =20 #include =20 +// Some macros and helper functions are defined in 'drivers/firewire/ohci.= c'. + TRACE_EVENT(irqs, TP_PROTO(unsigned int card_index, u32 events), TP_ARGS(card_index, events), @@ -42,6 +44,58 @@ TRACE_EVENT(irqs, ) ); =20 +#define QUADLET_SIZE 4 + +#define SELF_ID_COUNT_IS_ERROR(reg) \ + (!!(((reg) & OHCI1394_SelfIDCount_selfIDError_MASK) >> OHCI1394_SelfIDCou= nt_selfIDError_SHIFT)) + +#define SELF_ID_COUNT_GET_GENERATION(reg) \ + (((reg) & OHCI1394_SelfIDCount_selfIDGeneration_MASK) >> OHCI1394_SelfIDC= ount_selfIDGeneration_SHIFT) + +#define SELF_ID_RECEIVE_Q0_GET_GENERATION(quadlet) \ + (((quadlet) & OHCI1394_SELF_ID_RECEIVE_Q0_GENERATION_MASK) >> OHCI1394_SE= LF_ID_RECEIVE_Q0_GENERATION_SHIFT) + +#define SELF_ID_RECEIVE_Q0_GET_TIMESTAMP(quadlet) \ + (((quadlet) & OHCI1394_SELF_ID_RECEIVE_Q0_TIMESTAMP_MASK) >> OHCI1394_SEL= F_ID_RECEIVE_Q0_TIMESTAMP_SHIFT) + +TRACE_EVENT(self_id_complete, + TP_PROTO(unsigned int card_index, u32 reg, const __le32 *self_id_receive,= bool has_be_header_quirk), + TP_ARGS(card_index, reg, self_id_receive, has_be_header_quirk), + TP_STRUCT__entry( + __field(u8, card_index) + __field(u32, reg) + __dynamic_array(u32, self_id_receive, ohci1394_self_id_count_get_size(re= g)) + ), + TP_fast_assign( + __entry->card_index =3D card_index; + __entry->reg =3D reg; + { + u32 *ptr =3D __get_dynamic_array(self_id_receive); + int i; + + for (i =3D 0; i < __get_dynamic_array_len(self_id_receive) / QUADLET_SI= ZE; ++i) + ptr[i] =3D cond_le32_to_cpu(self_id_receive[i], has_be_header_quirk); + } + ), + TP_printk( + "card_index=3D%u is_error=3D%s generation_at_bus_reset=3D%u generation_a= t_completion=3D%u timestamp=3D0x%04x packet_data=3D%s", + __entry->card_index, + SELF_ID_COUNT_IS_ERROR(__entry->reg) ? "true" : "false", + SELF_ID_COUNT_GET_GENERATION(__entry->reg), + SELF_ID_RECEIVE_Q0_GET_GENERATION(((const u32 *)__get_dynamic_array(self= _id_receive))[0]), + SELF_ID_RECEIVE_Q0_GET_TIMESTAMP(((const u32 *)__get_dynamic_array(self_= id_receive))[0]), + __print_array(((const u32 *)__get_dynamic_array(self_id_receive)) + 1, + (__get_dynamic_array_len(self_id_receive) / QUADLET_SIZE) - 1, QU= ADLET_SIZE) + ) +); + +#undef SELF_ID_COUNT_IS_ERROR +#undef SELF_ID_COUNT_GET_GENERATION +#undef SELF_ID_RECEIVE_Q0_GET_GENERATION +#undef SELF_ID_RECEIVE_Q0_GET_TIMESTAMP + +#undef QUADLET_SIZE + #endif // _FIREWIRE_OHCI_TRACE_EVENT_H =20 #include --=20 2.43.0