Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1178236lqb; Thu, 18 Apr 2024 02:24:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWdyLFylWTIl3y5/GmaCi82aUzu7r9G6w2yVHo5mNqDeEW+7DSK9ffSbBlO3mkJamKehoROW8oCmhdVSvGBK18u0XmRNAtHfhttKmNYwQ== X-Google-Smtp-Source: AGHT+IF20Yc0VmZQo5PNFScYxC3zOA7joCUjQEEhDUTUiWSNi9S1UvFDlvkjjcbDbGUKhgwInt+D X-Received: by 2002:a05:6830:3d0c:b0:6ea:23af:2bcb with SMTP id eu12-20020a0568303d0c00b006ea23af2bcbmr2392773otb.32.1713432273244; Thu, 18 Apr 2024 02:24:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713432273; cv=pass; d=google.com; s=arc-20160816; b=Igm+hoTcEM9LygNAa5Z7oFWcH8h/09rpvWzP68NquSVExIMga8GIatYuTWhPvSfOc1 Jg9gexZG70JixFBLDtIxwtxCrHFUFkI6/+n8aklTYkZWIEFwKWUr1OL72hMio5d4Qh/C 6mS4N7UuhLNfTrnV3vVSAlyPxdJFC5sSF3QNR4ydL25rjXKr2TVY3umBuF1Ks7Ai6OpK PPmm1o1N67nZwrP+CJVAzE0sH38UGabkWr1lmXnE+iHnQ2sZimoiSMRoBBR/eiYqNkke 7v9kxQR7ZSanRppjvu5RiW7pMKs60s3OP65mKrMI8WdqWJ9w41ZMl/8LxLbtsGvZXXaR HZ4Q== 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=/e7fuxX/vtKPR4pmRS6j0FIOy9tSq6SszBVnEsJ8ruY=; fh=5EQyDiYgg+kua2A2AF9eJME8jasrrRA/Pgg86y+lzvY=; b=f4Qy+rMNESE59fpQ+N2ble5YJlWoNodzg3nUNHiqvC03JknDF9GjVqp50vgj1+dsV5 mFhPigvo+IGntjL3GYixsO4aaXs481xAEPdUtHBEgSn6LVyt0Y0l9g33un6wcR9BJMCF yhHQ8YZLQHieo2RYRZJXA1Iyi+bpV1U/cg19HmzM2bwPXhulg+ur5cSI8iWnDOBzyGbj 9h7xo8DZkZVVc/gIR4nYlXrgpEX+/B9qiplmY8z+nE5a4dWL/4JkZ2HzCCZvaF9wtqCf DIDuUCPGwTnOsS/9EeslHRCpbiTgKBns4tWXXWuLlMpVOXeQEoEZpskBg1HPjuLqyD2j DaRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm3 header.b=cIQuXqn5; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=gvqfvSpP; 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-149795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sakamocchi.jp Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c194-20020a6335cb000000b005dccf9c08ebsi1078962pga.656.2024.04.18.02.24.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 02:24:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm3 header.b=cIQuXqn5; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=gvqfvSpP; 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-149795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149795-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CBDF828471C for ; Thu, 18 Apr 2024 09:24:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F08915D5A0; Thu, 18 Apr 2024 09:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="cIQuXqn5"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gvqfvSpP" 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 3799215B571 for ; Thu, 18 Apr 2024 09:23:18 +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=1713432199; cv=none; b=fkNLFOkW5fH7Seu/HWWbFs+kGcuvkSuwyfI2hJA1Wasa/ie1jp5KMo5kgKfQ35S9vcHEAAl+OYLYbB0JDQ2FPbsIrVMA9MmJXFaakSiCE9gtkXtToAwNM2dMPLll/1SVxRVBszecYYjF6ABFVhdwEKKXa7KfPvFCfeuc4bR5sPA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713432199; c=relaxed/simple; bh=3LZ2rckMN5vRD3KByODttuDnXLjALQHZtYdntvxbJI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cjaWlMvI5sB6vMuQaMC9sSqNU58rig3CpJioNrq69JMQWy/k04NzIZ2NkFxBBWSA+3EtIXUe5e4ZbIg9w13SgkjIYihPMmHZ1a0LYxZPx7tzQArlL0TKII3zkXBRRBDcdH7sIsMl1k/hwT70JYK+X/HtY6+L4DjIfRNatbzcUKA= 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=cIQuXqn5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gvqfvSpP; 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 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 55FBA13800CB; Thu, 18 Apr 2024 05:23:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 18 Apr 2024 05:23: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=fm3; t=1713432197; x= 1713518597; bh=/e7fuxX/vtKPR4pmRS6j0FIOy9tSq6SszBVnEsJ8ruY=; b=c IQuXqn5RTTU50peMfUul5nyiZEtfKOYIiEPCRpKHFIRdW3kYl0rQUEqz/6dNoQ9D zuph4b23SO/zal1EIbUDrYfIJgBcWO1KZLnpo+NB34lVnPh4x01tdAgeqPllj8x5 OPD6XcWuyH0rZIb7isCdFaXY5puzNv500Gq3w18D+JtiAfADV/n+3R9E0uwuNN/y MN8g95z/9TsILosGkLqiHhpuB04DGlYehqwHvb1eM0BTfB6OgwLV1I664H5jdKXv q77cF8lTRpt6CB7mdaESM/x857NQII5wOr4fXmscE/CCWknGjnbOsncoEA1xIOTR 5/AEyqeIYZ/jllg93W9UQ== 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=fm3; t=1713432197; x= 1713518597; bh=/e7fuxX/vtKPR4pmRS6j0FIOy9tSq6SszBVnEsJ8ruY=; b=g vqfvSpPRQVUjS6jsarxmFp/6Sn5uxv6PzN/+k0gIZ9NHfkoUS6IjZfIXl1/mq24o gqhnuqwGJgIlBDrWmE3RGmvbdz10uUA+H6+C7jCe5288TMcpGoMrGfHRrfxhBDZD Yftcb1r/f155RbO4jdgj5NeIDmLy8ZuHEvP0OlZg4davw5VDlQp6PMIx20da4QmO 02vN+DrAAgdD7BbDE0U+mSfSKHtSqb/yGxwsrEzngCRYsy1ozILxqBkwAyA+y/SX HuW6fv290TW5dBBI2ltwKIN5RqHpjcCJ/3rx+nVI/NwZntxnldxt4bNffu5DWGxM 1fwYGbvBeI3rKH30Tdrdw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudektddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 18 Apr 2024 05:23:16 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [RFC PATCH 07/13] firewire: core: add common macro to serialize/deserialize isochronous packet header Date: Thu, 18 Apr 2024 18:22:57 +0900 Message-ID: <20240418092303.19725-8-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418092303.19725-7-o-takashi@sakamocchi.jp> References: <20240418092303.19725-1-o-takashi@sakamocchi.jp> <20240418092303.19725-2-o-takashi@sakamocchi.jp> <20240418092303.19725-3-o-takashi@sakamocchi.jp> <20240418092303.19725-4-o-takashi@sakamocchi.jp> <20240418092303.19725-5-o-takashi@sakamocchi.jp> <20240418092303.19725-6-o-takashi@sakamocchi.jp> <20240418092303.19725-7-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 The packet for Asynchronous Streaming Packet includes the same header fields as the isochronous packet has. It is helpful to have some helper functions to serialize/deserialize them. This commit adds such helper functions with their test. Signed-off-by: Takashi Sakamoto --- drivers/firewire/packet-header-definitions.h | 66 ++++++++++++++++++++ drivers/firewire/packet-serdes-test.c | 44 +++++++++++++ 2 files changed, 110 insertions(+) diff --git a/drivers/firewire/packet-header-definitions.h b/drivers/firewire/packet-header-definitions.h index 83e550427706..ab9d0fa790d4 100644 --- a/drivers/firewire/packet-header-definitions.h +++ b/drivers/firewire/packet-header-definitions.h @@ -165,4 +165,70 @@ static inline void async_header_set_extended_tcode(u32 header[ASYNC_HEADER_QUADL header[3] |= (((u32)extended_tcode) << ASYNC_HEADER_Q3_EXTENDED_TCODE_SHIFT) & ASYNC_HEADER_Q3_EXTENDED_TCODE_MASK; } +#define ISOC_HEADER_DATA_LENGTH_SHIFT 16 +#define ISOC_HEADER_DATA_LENGTH_MASK 0xffff0000 +#define ISOC_HEADER_TAG_SHIFT 14 +#define ISOC_HEADER_TAG_MASK 0x0000c000 +#define ISOC_HEADER_CHANNEL_SHIFT 8 +#define ISOC_HEADER_CHANNEL_MASK 0x00003f00 +#define ISOC_HEADER_TCODE_SHIFT 4 +#define ISOC_HEADER_TCODE_MASK 0x000000f0 +#define ISOC_HEADER_SY_SHIFT 0 +#define ISOC_HEADER_SY_MASK 0x0000000f + +static inline unsigned int isoc_header_get_data_length(u32 header) +{ + return (header & ISOC_HEADER_DATA_LENGTH_MASK) >> ISOC_HEADER_DATA_LENGTH_SHIFT; +} + +static inline unsigned int isoc_header_get_tag(u32 header) +{ + return (header & ISOC_HEADER_TAG_MASK) >> ISOC_HEADER_TAG_SHIFT; +} + +static inline unsigned int isoc_header_get_channel(u32 header) +{ + return (header & ISOC_HEADER_CHANNEL_MASK) >> ISOC_HEADER_CHANNEL_SHIFT; +} + +static inline unsigned int isoc_header_get_tcode(u32 header) +{ + return (header & ISOC_HEADER_TCODE_MASK) >> ISOC_HEADER_TCODE_SHIFT; +} + +static inline unsigned int isoc_header_get_sy(u32 header) +{ + return (header & ISOC_HEADER_SY_MASK) >> ISOC_HEADER_SY_SHIFT; +} + +static inline void isoc_header_set_data_length(u32 *header, unsigned int data_length) +{ + *header &= ~ISOC_HEADER_DATA_LENGTH_MASK; + *header |= (((u32)data_length) << ISOC_HEADER_DATA_LENGTH_SHIFT) & ISOC_HEADER_DATA_LENGTH_MASK; +} + +static inline void isoc_header_set_tag(u32 *header, unsigned int tag) +{ + *header &= ~ISOC_HEADER_TAG_MASK; + *header |= (((u32)tag) << ISOC_HEADER_TAG_SHIFT) & ISOC_HEADER_TAG_MASK; +} + +static inline void isoc_header_set_channel(u32 *header, unsigned int channel) +{ + *header &= ~ISOC_HEADER_CHANNEL_MASK; + *header |= (((u32)channel) << ISOC_HEADER_CHANNEL_SHIFT) & ISOC_HEADER_CHANNEL_MASK; +} + +static inline void isoc_header_set_tcode(u32 *header, unsigned int tcode) +{ + *header &= ~ISOC_HEADER_TCODE_MASK; + *header |= (((u32)tcode) << ISOC_HEADER_TCODE_SHIFT) & ISOC_HEADER_TCODE_MASK; +} + +static inline void isoc_header_set_sy(u32 *header, unsigned int sy) +{ + *header &= ~ISOC_HEADER_SY_MASK; + *header |= (((u32)sy) << ISOC_HEADER_SY_SHIFT) & ISOC_HEADER_SY_MASK; +} + #endif // _FIREWIRE_PACKET_HEADER_DEFINITIONS_H diff --git a/drivers/firewire/packet-serdes-test.c b/drivers/firewire/packet-serdes-test.c index 299e9f908463..f93c966e794d 100644 --- a/drivers/firewire/packet-serdes-test.c +++ b/drivers/firewire/packet-serdes-test.c @@ -167,6 +167,26 @@ static void deserialize_async_header_block_response(const u32 header[ASYNC_HEADE *extended_tcode = async_header_get_extended_tcode(header); } +static void serialize_isoc_header(u32 *header, unsigned int data_length, unsigned int tag, + unsigned int channel, unsigned int tcode, unsigned int sy) +{ + isoc_header_set_data_length(header, data_length); + isoc_header_set_tag(header, tag); + isoc_header_set_channel(header, channel); + isoc_header_set_tcode(header, tcode); + isoc_header_set_sy(header, sy); +} + +static void deserialize_isoc_header(u32 header, unsigned int *data_length, unsigned int *tag, + unsigned int *channel, unsigned int *tcode, unsigned int *sy) +{ + *data_length = isoc_header_get_data_length(header); + *tag = isoc_header_get_tag(header); + *channel = isoc_header_get_channel(header); + *tcode = isoc_header_get_tcode(header); + *sy = isoc_header_get_sy(header); +} + static void test_async_header_write_quadlet_request(struct kunit *test) { static const u32 expected[ASYNC_HEADER_QUADLET_COUNT] = { @@ -515,6 +535,29 @@ static void test_async_header_lock_response(struct kunit *test) KUNIT_EXPECT_MEMEQ(test, header, expected, sizeof(expected)); } +static void test_isoc_header(struct kunit *test) +{ + const u32 expected = 0x00d08dec; + u32 header = 0; + + unsigned int data_length; + unsigned int tag; + unsigned int channel; + unsigned int tcode; + unsigned int sy; + + deserialize_isoc_header(expected, &data_length, &tag, &channel, &tcode, &sy); + + KUNIT_EXPECT_EQ(test, 0xd0, data_length); + KUNIT_EXPECT_EQ(test, 0x02, tag); + KUNIT_EXPECT_EQ(test, 0x0d, channel); + KUNIT_EXPECT_EQ(test, 0x0e, tcode); + KUNIT_EXPECT_EQ(test, 0x0c, sy); + + serialize_isoc_header(&header, data_length, tag, channel, tcode, sy); + + KUNIT_EXPECT_EQ(test, header, expected); +} static struct kunit_case packet_serdes_test_cases[] = { KUNIT_CASE(test_async_header_write_quadlet_request), @@ -526,6 +569,7 @@ static struct kunit_case packet_serdes_test_cases[] = { KUNIT_CASE(test_async_header_read_block_response), KUNIT_CASE(test_async_header_lock_request), KUNIT_CASE(test_async_header_lock_response), + KUNIT_CASE(test_isoc_header), {} }; -- 2.43.0