Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3221830rwd; Fri, 16 Jun 2023 14:12:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4glOy0RWbvHKmrgyASG8F8hll21tC63GvVd1cDN8fS8hzG/auaNsCJciI8V/z42CgomKkk X-Received: by 2002:a05:6a21:788a:b0:10c:ef9f:ddbd with SMTP id bf10-20020a056a21788a00b0010cef9fddbdmr3665924pzc.8.1686949929139; Fri, 16 Jun 2023 14:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686949929; cv=none; d=google.com; s=arc-20160816; b=uPLEfFAHj7000rSuBkGdJU3GhVvoFw4qv9liesWm5aL+QJl8wgKvrMmN7zjtFqL7rI z7BGKjS8/PhPN7o9JW5/PmQJIWKTLVbna+H0NgXa0gn9kjo1pkfmukai30tcUgNNPCTc TjnmTItX5kD2m3YSovWV256NYVaBcZkN1N09yvJeRC9i896qroeeL2SzNgdnkLd1N+j5 4Y2LXS6NcGsKXUSlBRtn3eyL3QFKC8XfnmFGCPw4ANgubR4Ar5IxBDIfsuf0sXjIjrKY tg4MEYha5Nf9I0FOuV9GJwOslSiOOauviHJXtAyak9gWC1KaLwcYQMzH2Ft/2Y7pY259 ZsKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JMRyH4XZ7BgD1JTlRQKDN/9z00oxbvpE6vrHZwAXptA=; b=ABRND8HQ2AwQXvtHQ34iI7k7PL4ulNhu6LxRlIuOUQz1+Ii3TIpgiuvZ0wzO7wCahC /ehkKRCa0G3M1yVoMHTT8VKOycG6Qil/Cc6jmD/Vyos5Ab8Zd+PleJ4y7Y2vV8m6mdCH y/zHNfIv24E4GttC++MUWIljGFozO0wJf2BF9g/iOsxN/DVSvs+/qhzNBi2S0puDyS49 CgVuwP2q+rVH6WsnkaJz+LzcCNJHxVIE20cLlOgNVhiA7MiG5qY+AoUZ+bnSHLrzPqED 1PM/34cLlXuYHph4NP+YQPQINYm+k9/0cfTHKO8XhvLQtiEIc4esHMMhEj20bCxLHC5i etfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J7i0S9sp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a170903234400b001b3dacdf717si5205898plh.608.2023.06.16.14.11.54; Fri, 16 Jun 2023 14:12:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J7i0S9sp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232709AbjFPVFn (ORCPT + 99 others); Fri, 16 Jun 2023 17:05:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjFPVFl (ORCPT ); Fri, 16 Jun 2023 17:05:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 306753596; Fri, 16 Jun 2023 14:05:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B6A0961B11; Fri, 16 Jun 2023 21:05:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7532C433C0; Fri, 16 Jun 2023 21:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686949539; bh=6cnCdUSqLz7VhNzN0lbB/Xqj6xFuU/O/NQabQhB7NiY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=J7i0S9spk/rq86bSVG2EN5JaWksv1VMyqy/uqYZvc+hC7ysTe5TqccRM2AMZgC4Gb 6hwENrxSEFBxJluOcHgbDa0OWR3ILdeMYbHMHyoX2OCc9lCWFTZBrWvgPNdsGzfRNn aV191+D8dJm0lWZwEBN67SJzMEFHZKTV13/HmKBR+g7Jd07SZKwN2XFltofW83J+P8 K0YGwMPdMkV2P6Gm5tunFN6kzHDp2DoJ876R+EtbmB8ty94hQRpldVLzmT2J2HhkXy AbGjNxMNOS6br8EFkos9pjzwAQolUgXD503u5DY+0bquBHgRMkcbgnhK3ptEYP8v2c ZsDo7r0cgzVLg== Date: Fri, 16 Jun 2023 22:05:32 +0100 From: Conor Dooley To: Eric Lin Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, maz@kernel.org, chenhuacai@kernel.org, baolu.lu@linux.intel.com, will@kernel.org, kan.liang@linux.intel.com, nnac123@linux.ibm.com, pierre.gondois@arm.com, huangguangbin2@huawei.com, jgross@suse.com, chao.gao@intel.com, maobibo@loongson.cn, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dslin1010@gmail.com, Nick Hu , Zong Li Subject: Re: [PATCH 1/3] soc: sifive: Add SiFive private L2 cache support Message-ID: <20230616-errand-glutton-f64783da058c@spud> References: <20230616063210.19063-1-eric.lin@sifive.com> <20230616063210.19063-2-eric.lin@sifive.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wC0nzxIhkPASdtVL" Content-Disposition: inline In-Reply-To: <20230616063210.19063-2-eric.lin@sifive.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --wC0nzxIhkPASdtVL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hey Eric, On Fri, Jun 16, 2023 at 02:32:08PM +0800, Eric Lin wrote: > This adds SiFive private L2 cache driver which will show > cache config information when booting and add cpu hotplug > callback functions. >=20 > Signed-off-by: Eric Lin > Signed-off-by: Nick Hu Missing a Co-developed-by for Nick? > +static void pl2_config_read(void __iomem *pl2_base, int cpu) > +{ > + u32 regval, bank, way, set, cacheline; > + > + regval =3D readl(pl2_base); > + bank =3D regval & 0xff; > + pr_info("in the CPU: %d\n", cpu); > + pr_info("No. of Banks in the cache: %d\n", bank); > + way =3D (regval & 0xff00) >> 8; > + pr_info("No. of ways per bank: %d\n", way); > + set =3D (regval & 0xff0000) >> 16; > + pr_info("Total sets: %llu\n", (uint64_t)1 << set); > + cacheline =3D (regval & 0xff000000) >> 24; > + pr_info("Bytes per cache block: %llu\n", (uint64_t)1 << cacheline); > + pr_info("Size: %d\n", way << (set + cacheline)); > +} Isn't this basically all information that we get anyway in sysfs based on what gets put into the DT, except printed out once per CPU at boottime? If there's reason to keep it, please do as suggested by Ben and cut down the number of lines emitted. Look at the ccache one for comparison: static void ccache_config_read(void) { u32 cfg; =09 cfg =3D readl(ccache_base + SIFIVE_CCACHE_CONFIG); pr_info("%llu banks, %llu ways, sets/bank=3D%llu, bytes/block=3D%llu\n", FIELD_GET(SIFIVE_CCACHE_CONFIG_BANK_MASK, cfg), FIELD_GET(SIFIVE_CCACHE_CONFIG_WAYS_MASK, cfg), BIT_ULL(FIELD_GET(SIFIVE_CCACHE_CONFIG_SETS_MASK, cfg)), BIT_ULL(FIELD_GET(SIFIVE_CCACHE_CONFIG_BLKS_MASK, cfg))); =09 cfg =3D readl(ccache_base + SIFIVE_CCACHE_WAYENABLE); pr_info("Index of the largest way enabled: %u\n", cfg); } It'd also be good to print the same things as the ccache, no? > +static int sifive_pl2_cache_dev_probe(struct platform_device *pdev) > +{ > + struct resource *res; > + int cpu, ret =3D -EINVAL; > + struct device_node *cpu_node, *pl2_node; > + struct sifive_pl2_state *pl2_state =3D NULL; > + void __iomem *pl2_base; Please pick a sensible ordering for variables. IDC if it is reverse xmas tree, or sorting by types, but this just seems quite random.. > + /* Traverse all cpu nodes to find the one mapping to its pl2 node. */ > + for_each_cpu(cpu, cpu_possible_mask) { > + cpu_node =3D of_cpu_device_node_get(cpu); > + pl2_node =3D of_parse_phandle(cpu_node, "next-level-cache", 0); > + > + /* Found it! */ > + if (dev_of_node(&pdev->dev) =3D=3D pl2_node) { > + /* Use cpu to get its percpu data sifive_pl2_state. */ > + pl2_state =3D per_cpu_ptr(&sifive_pl2_state, cpu); > + break; > + } > + } > + > + if (!pl2_state) { > + pr_err("Not found the corresponding cpu_node in dts.\n"); I don't think this error message is going to be helpful in figuring out where the problem is on a machine with many of the caches. More information about *which* cache caused it would be good. Also it is not grammatically correct, it should read something like "Failed to find CPU node for cache@abc" or something along those lines. > + goto early_err; early_err just returns ret. Why not just return the error directly? > + } > + > + /* Set base address of select and counter registers. */ > + pl2_base =3D devm_platform_get_and_ioremap_resource(pdev, 0, &res); > + if (IS_ERR(pl2_base)) { > + ret =3D PTR_ERR(pl2_base); > + goto early_err; > + } > + > + /* Print pL2 configs. */ > + pl2_config_read(pl2_base, cpu); > + pl2_state->pl2_base =3D pl2_base; > + > + return 0; > + > +early_err: > + return ret; > +} > +static struct platform_driver sifive_pl2_cache_driver =3D { > + .driver =3D { > + .name =3D "SiFive-pL2-cache", > + .of_match_table =3D sifive_pl2_cache_of_ids, > + }, > + .probe =3D sifive_pl2_cache_dev_probe, > +}; > + > +static int __init sifive_pl2_cache_init(void) > +{ > + int ret; > + > + ret =3D cpuhp_setup_state(CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE, > + "soc/sifive/pl2:online", > + sifive_pl2_online_cpu, > + sifive_pl2_offline_cpu); Got some weird use of whitespace here & above, please remove the spaces. Cheers, Conor. --wC0nzxIhkPASdtVL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZIzOnAAKCRB4tDGHoIJi 0qXrAP9I4dkOKQEZhScuLXuEiX6wodn8UZXmdAIfrNoRy5PCeQD/S7nbJJrzxs/e 2tvhVnxiJgt1PdRYTwuj6gILbgvnpwM= =fRw3 -----END PGP SIGNATURE----- --wC0nzxIhkPASdtVL--