Received: by 2002:a05:7412:8d08:b0:f9:2d0a:d759 with SMTP id bj8csp68060rdb; Sun, 17 Dec 2023 02:32:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBuHQ1voY55T3a9o1PnrwHapaOUyOKN/eT+zQPolCrCRQvNhru0qClSORvBfOADfJtqhSC X-Received: by 2002:a17:907:7e84:b0:a1b:8297:f761 with SMTP id qb4-20020a1709077e8400b00a1b8297f761mr10373950ejc.66.1702809129842; Sun, 17 Dec 2023 02:32:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702809129; cv=none; d=google.com; s=arc-20160816; b=lmB4rSF21xq+Ji5XbQQTxk0QBeG2MAlzcxMSqXaiWwZTrOYTlz5X6MmTWUtMXFJnS1 jLjtHG/3BsoBbHdsmzu4CimbqG89S79Bf0xwyFV5rpopdg7WJmi/ZHP5MA9rSldoOXOg dv4LuZrfoHv4YNqVe/bVCdx87Tg3hcn2W/SYDYs0dcVOK9rMXCRHtUQ9pQAINss1qCUO haNVtJqS9Zqa5DGhiylQsT2dTcrCixWdqvHRO8NE6aAy014/1JGgOOFedaJaLVajgsjO 9eiOTHOxEB1D116CsmiX+l21+vB+zlBZn7H8fms//AxF5NThkIhTgTPZW1RNFbuUV4Ed bqkg== ARC-Message-Signature: i=1; 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=tlbzFSAVTLU8/7G01uILlJQsR6kJ19oJ8HcV/Gzb9L4=; fh=29+NP+Avo3KW5WAFiPrv+jdOjQZBDMQJMXZlHI+I9m4=; b=E7aD72OAynD7ttV5Lfm3vkL5OVgi6lV/if7cMM0ik65buZ4M/CXO4ZqmGyjDyAEAcQ dLq0/cAfW4WavKzDE564I67Gl6ta8HumNQiQm2C5A2UDqTySFdZ/D+NsK80XJPMfd373 BFLngYknHprjdHpiP388GVBiIDNJOU6ApOT6gmhLou2MYx51CjKvRbjjyjZ6QJM1xxfp PR7YGPg3CN2x1REFabgu9Z/TCk47NWXL8OWAcYXG/D26ckkf0IXSpS4fJaQQ3iWDwk5t i9eGMM0xNvYQYt09tphXNEfgvhf0KaSHu/ZzF+n8SKB+SJtHkPGB4lp04fslOoN52PGv fkZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm2 header.b=Rk1TfrRj; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=YAHuSqyy; spf=pass (google.com: domain of linux-kernel+bounces-2531-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2531-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sakamocchi.jp Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e18-20020a170906375200b00a234926c9b6si410638ejc.786.2023.12.17.02.32.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 02:32:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2531-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm2 header.b=Rk1TfrRj; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=YAHuSqyy; spf=pass (google.com: domain of linux-kernel+bounces-2531-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2531-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4BC021F221B4 for ; Sun, 17 Dec 2023 10:32:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F420CDDCE; Sun, 17 Dec 2023 10:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="Rk1TfrRj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YAHuSqyy" X-Original-To: linux-kernel@vger.kernel.org Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (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 71D9410780 for ; Sun, 17 Dec 2023 10:30:27 +0000 (UTC) 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 compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id AEBD45C0121; Sun, 17 Dec 2023 05:30:26 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sun, 17 Dec 2023 05:30:26 -0500 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=1702809026; x= 1702895426; bh=tlbzFSAVTLU8/7G01uILlJQsR6kJ19oJ8HcV/Gzb9L4=; b=R k1TfrRj48BMz1MjS4u8ALG0bH6VytvO3Ks+uyTt3tysT/qxD/F7+qn8ntX0/idLs qifyXWL5c7Ub3mTI6lkCsY0tz+XnWhnnz3JsXdqr6u5yXgJfnUwQ+nkRuxmhSQoy mfGpFgzEuwDHFfekEH3E8H0jtWBOejhWOrUgaVr29ZoCkILA3WJGgejGdZoa+JEh f4lf3Oat5d7R6jvypX5OsPNzgv8l5zCGLS1TU+Q2cpB2hgeTMs0fCNzdK9vZzbUS wh9o67eblJ/PUXZKPCnw5VsLHkGmVUqunTb3WUr6/kWe8CzYkuqglYk3Gb3W9Foo dGK+xCww6cfdoXmbezmBQ== 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=1702809026; x= 1702895426; bh=tlbzFSAVTLU8/7G01uILlJQsR6kJ19oJ8HcV/Gzb9L4=; b=Y AHuSqyylVf0N9ClmS5/VH/M860iogNWeUBXk+e91Mg5z+IXU8tbtQ0hRkc5MlCIk PTRb0qRp0lE+FuQXv1na0aTpKnvWwEViovUFXXIrUGCEABk3ZqTWFb3OjMz2wuWA 2rPuUaN1DB0XiGO9Jimm/9oPbGiLYXRZsYJCy5f1mIYqheAdP5jZm2JBTPD9UzdA 8YGg4e0LnkgUZfnrhlyOyEEeE2GCBPaeylY8OLQ7XXnBz0LOdrs2b/1Sqfb7a1xV qxVobTdUe1R2nTSaedwU1M8KxG2TGtj+jq0MoiGOqeW4MKnXOEP+xAeyuEXdmya6 i+b7Ntj+VlQpjUeIgzNiw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddtiedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpedvjefgje euvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdffkedvtdenucevlhhushht vghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehoqdhtrghkrghshhhise hsrghkrghmohgttghhihdrjhhp X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Dec 2023 05:30:25 -0500 (EST) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: adamg@pobox.com Subject: [RFC PATCH 6/8] firewire: core: detect numeric model identifier for legacy layout of configuration ROM Date: Sun, 17 Dec 2023 19:30:09 +0900 Message-Id: <20231217103012.41273-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231217103012.41273-1-o-takashi@sakamocchi.jp> References: <20231217103012.41273-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 As the part of support for legacy layout of configuration ROM, this commit traverse vendor directory as well as root directory when showing device attribute for node device. This change expects 'model' attribute appears in node device, however it is probable to see the other types of immediate values if the vendor directory includes. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-device.c | 57 +++++++++++++++++++++++++-------- drivers/firewire/csr-api-test.c | 5 +-- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 14c7461c05f6..dad5c9937b78 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -49,6 +49,22 @@ int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value) } EXPORT_SYMBOL(fw_csr_iterator_next); +static const u32 *search_directory(const u32 *directory, int search_key) +{ + struct fw_csr_iterator ci; + int key, value; + + search_key |= CSR_DIRECTORY; + + fw_csr_iterator_init(&ci, directory); + while (fw_csr_iterator_next(&ci, &key, &value)) { + if (key == search_key) + return ci.p - 1 + value; + } + + return NULL; +} + static const u32 *search_leaf(const u32 *directory, int search_key) { struct fw_csr_iterator ci; @@ -253,27 +269,42 @@ static ssize_t show_immediate(struct device *dev, struct config_rom_attribute *attr = container_of(dattr, struct config_rom_attribute, attr); struct fw_csr_iterator ci; - const u32 *dir; - int key, value, ret = -ENOENT; + const u32 *directories[] = {NULL, NULL}; + int i, value = -1; down_read(&fw_device_rwsem); - if (is_fw_unit(dev)) - dir = fw_unit(dev)->directory; - else - dir = fw_device(dev)->config_rom + ROOT_DIR_OFFSET; + if (is_fw_unit(dev)) { + directories[0] = fw_unit(dev)->directory; + } else { + const u32 *root_directory = fw_device(dev)->config_rom + ROOT_DIR_OFFSET; - fw_csr_iterator_init(&ci, dir); - while (fw_csr_iterator_next(&ci, &key, &value)) - if (attr->key == key) { - ret = snprintf(buf, buf ? PAGE_SIZE : 0, - "0x%06x\n", value); - break; + directories[0] = root_directory; + + // Legacy layout of configuration ROM described in Annex 1 of 'Configuration ROM + // for AV/C Devices 1.0 (December 12, 2000, 1394 Trading Association, TA Document + // 1999027)'. + directories[1] = search_directory(root_directory, CSR_VENDOR); + } + + for (i = 0; i < ARRAY_SIZE(directories) && !!directories[i]; ++i) { + int key, val; + + fw_csr_iterator_init(&ci, directories[i]); + while (fw_csr_iterator_next(&ci, &key, &val)) { + if (attr->key == key) { + value = val; + break; + } } + } up_read(&fw_device_rwsem); - return ret; + if (value < 0) + return -ENOENT; + + return snprintf(buf, buf ? PAGE_SIZE : 0, "0x%06x\n", value); } #define IMMEDIATE_ATTR(name, key) \ diff --git a/drivers/firewire/csr-api-test.c b/drivers/firewire/csr-api-test.c index 2430891c5dcb..7278e7b927a8 100644 --- a/drivers/firewire/csr-api-test.c +++ b/drivers/firewire/csr-api-test.c @@ -199,8 +199,9 @@ static void csr_api_legacy_avc_device(struct kunit *test) KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[0].attr, buf), 0); KUNIT_EXPECT_STREQ(test, buf, "0x012345\n"); - // Model immediate entry is not found. - KUNIT_EXPECT_LT(test, show_immediate(node_dev, &config_rom_attributes[4].attr, buf), 0); + // Model immediate entry is found. + KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[4].attr, buf), 0); + KUNIT_EXPECT_STREQ(test, buf, "0xfedcba\n"); // Descriptor leaf entry for vendor is not found. KUNIT_EXPECT_LT(test, show_text_leaf(node_dev, &config_rom_attributes[5].attr, buf), 0); -- 2.39.2