Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5550393rdb; Wed, 13 Dec 2023 11:54:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfUcdUXCKhbkrTNP/TPK3qJoEjO6Y/djy61OHyXHBphAEuoTmaLKhfu4Nna2c1x3vw2dUr X-Received: by 2002:a50:c945:0:b0:54c:60f0:7511 with SMTP id p5-20020a50c945000000b0054c60f07511mr5358912edh.35.1702497245642; Wed, 13 Dec 2023 11:54:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702497245; cv=none; d=google.com; s=arc-20160816; b=SM4xTOvBe0/mHDWYPW8GQRlbXGEV4BeveSxlAOwYUAqIYHyX1VszgebP2K/ClTSaxD BEbUywq9PwawHckrHbjAT6W9E6PH0NwX42sZmeFZE6sIXEYovuP0+cJB1VTRQE/WUcVg RAoZUmmA3jiPex7kSj/JbKf6A4dAfwf+iVPivQe9hQ0d0kE05RDUkYBD89/q98odSrDf Kc4uoifLvbh+Y9wE/HHQGMtLScoJq7Sf1CuFQSku4SrEj4eAnCHfit4zh0zwtfqiELet STkC8OuTJcmGICkUGBaARBhzaK76UWcYwHuVdfTIUEnaUDS2vo8rEdfEzYEATdNKYmTT a+QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=aVsI+6uJK2inSOtfQDvUKJlMoBKdDZ7mdyVe5lZZM1s=; fh=XRRtlggx+X1+q83/KJpawgO/3JrFg54jALcPHF/9h3Q=; b=McAjzX/gjgLvx9o+tfzTEzkrrKwL9i5kcE9p7oUccoo6Hkc5LVSjEjrgbUk1W/GaJz QrjAkziXL64Y8MlN2IY6vyyNHzS1JK/eMsTkCFHQKkEuQ6bRZub9r9akbAhKmoYEEQhP aNhCNgfbUWX7mkquFmERuK4WBaTDdC7/ZcXTTVEAj66E9pf8MXN5LYvDi6zm5h973OIL RVfmEe5q+TpfpRkTirCZodmYMTXe7D1vDvpI2THQtkGx0CCGcE0XnG5KANAmyENz6c77 Bx4qIK9/Dq0PAB0w0iHSzv6ed4aCcQcKEjK7a+bdYwEGI+WnR2tuuhMpBU6HZtxvfrwq iVUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VMybQw20; spf=pass (google.com: domain of linux-crypto+bounces-818-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a14-20020a509b4e000000b0054c9694d110si5874724edj.199.2023.12.13.11.54.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 11:54:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-818-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=@kernel.org header.s=k20201202 header.b=VMybQw20; spf=pass (google.com: domain of linux-crypto+bounces-818-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 2D5EE1F217A5 for ; Wed, 13 Dec 2023 19:54:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD1917D8A3; Wed, 13 Dec 2023 19:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VMybQw20" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 84F2A6829A; Wed, 13 Dec 2023 19:53:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A929AC433C7; Wed, 13 Dec 2023 19:53:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702497239; bh=dcjUy2QND46YM2W9IosA0LzvC8ULdjGPyZnZLP6Ia3I=; h=Date:Subject:To:References:From:In-Reply-To:From; b=VMybQw20CoC5U8K+WyP5dgGTjp4Bl0IOQeA6Srubt/Kpgugo/8IwNYBD3Sigla1gj XaVzHYKbDNnpr5AHt1yeu70EHuOeQMW81wGzjmhy4INjCkG5mLpf6PD0+H89bPQV3B nPGmzsn84GT1eyIY3uNzKYgN0s13je2jVb5xNvXXoxi6Q2pxxFCCGO0fpNgREdOb3Y +3YcuOHHahFofUriI3VTMo1muq+Wvny0oUOapUfcQK1mucO3cwP/5yYciLvxjgbYnI EG+L9nx+wzwDn43j9Me34XpBY21CY4HzDz7v2aqAhb9qd4Hj+NQxY18ydU+owmXfk/ 5goU8DheuihiA== Message-ID: <52340f6e-e253-4eef-b395-2805aeac65a9@kernel.org> Date: Wed, 13 Dec 2023 20:53:52 +0100 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/5] crypto: tegra: Add Tegra Security Engine driver Content-Language: en-US To: Akhil R , herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, thierry.reding@gmail.com, jonathanh@nvidia.com, linux-tegra@vger.kernel.org References: <20231213122030.11734-1-akhilrajeev@nvidia.com> <20231213122030.11734-4-akhilrajeev@nvidia.com> From: Krzysztof Kozlowski Autocrypt: addr=krzk@kernel.org; keydata= xsFNBFVDQq4BEAC6KeLOfFsAvFMBsrCrJ2bCalhPv5+KQF2PS2+iwZI8BpRZoV+Bd5kWvN79 cFgcqTTuNHjAvxtUG8pQgGTHAObYs6xeYJtjUH0ZX6ndJ33FJYf5V3yXqqjcZ30FgHzJCFUu JMp7PSyMPzpUXfU12yfcRYVEMQrmplNZssmYhiTeVicuOOypWugZKVLGNm0IweVCaZ/DJDIH gNbpvVwjcKYrx85m9cBVEBUGaQP6AT7qlVCkrf50v8bofSIyVa2xmubbAwwFA1oxoOusjPIE J3iadrwpFvsZjF5uHAKS+7wHLoW9hVzOnLbX6ajk5Hf8Pb1m+VH/E8bPBNNYKkfTtypTDUCj NYcd27tjnXfG+SDs/EXNUAIRefCyvaRG7oRYF3Ec+2RgQDRnmmjCjoQNbFrJvJkFHlPeHaeS BosGY+XWKydnmsfY7SSnjAzLUGAFhLd/XDVpb1Een2XucPpKvt9ORF+48gy12FA5GduRLhQU vK4tU7ojoem/G23PcowM1CwPurC8sAVsQb9KmwTGh7rVz3ks3w/zfGBy3+WmLg++C2Wct6nM Pd8/6CBVjEWqD06/RjI2AnjIq5fSEH/BIfXXfC68nMp9BZoy3So4ZsbOlBmtAPvMYX6U8VwD TNeBxJu5Ex0Izf1NV9CzC3nNaFUYOY8KfN01X5SExAoVTr09ewARAQABzSVLcnp5c3p0b2Yg S296bG93c2tpIDxrcnprQGtlcm5lbC5vcmc+wsGVBBMBCgA/AhsDBgsJCAcDAgYVCAIJCgsE FgID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gcan8mCoqhJkbqrL7+nXG2 5Q/GS5M9RFWS+nYyJh+c3OcfKqVcZQNANItt7+ULzdNJuhvTRRdC3g9hmCEuNSr+CLMdnRBY fv0= In-Reply-To: <20231213122030.11734-4-akhilrajeev@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 13/12/2023 13:20, Akhil R wrote: > Add support for Tegra Security Engine which can accelerates various > crypto algorithms. The Engine has two separate instances within for > AES and HASH algorithms respectively. > > The driver registers two crypto engines - one for AES and another for > HASH algorithms and these operate independently and both uses the host1x > bus. Additionally, it provides hardware-assisted key protection for up > to 15 symmetric keys which it can use for the cipher operations. > > Signed-off-by: Akhil R > --- ... > + > +int tegra_init_hash(struct tegra_se *se) > +{ > + struct ahash_engine_alg *alg; > + int i, ret; > + > + se->manifest = tegra_hash_kac_manifest; > + > + for (i = 0; i < ARRAY_SIZE(tegra_hash_algs); i++) { > + tegra_hash_algs[i].se_dev = se; > + alg = &tegra_hash_algs[i].alg.ahash; > + > + ret = crypto_engine_register_ahash(alg); > + if (ret) { > + dev_err(se->dev, "failed to register %s\n", > + alg->base.halg.base.cra_name); > + goto sha_err; > + } > + } > + > + dev_info(se->dev, "registered HASH algorithms\n"); Drop, not needed. Actually drop simple success messages. Drivers do not spam dmesg without need. ... > + > +int tegra_se_host1x_register(struct tegra_se *se) > +{ > + INIT_LIST_HEAD(&se->client.list); > + se->client.dev = se->dev; > + se->client.ops = &tegra_se_client_ops; > + se->client.class = se->hw->host1x_class; > + se->client.num_syncpts = 1; > + > + host1x_client_register(&se->client); > + > + return 0; > +} > + > +static int tegra_se_clk_init(struct tegra_se *se) > +{ > + int i, ret; > + > + se->clk = devm_clk_get(se->dev, NULL); > + if (IS_ERR(se->clk)) { > + dev_err(se->dev, "failed to get clock\n"); Why do you print failures multiple times? Once here, second in probe. return dev_err_probe > + return PTR_ERR(se->clk); > + } > + > + ret = clk_set_rate(se->clk, ULONG_MAX); > + if (ret) { > + dev_err(se->dev, "failed to set %d clock rate", i); Same comments > + return ret; > + } > + > + ret = clk_prepare_enable(se->clk); > + if (ret) { > + dev_err(se->dev, "failed to enable clocks\n"); Same comments > + return ret; > + } > + > + return 0; > +} > + > +static void tegra_se_clk_deinit(struct tegra_se *se) > +{ > + clk_disable_unprepare(se->clk); Why aren't you using devm_clk_get_enabled? This looks like porting some old, out-of-tree vendor crappy driver :( > +} > + > +static int tegra_se_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct tegra_se *se; > + int ret; > + > + se = devm_kzalloc(dev, sizeof(*se), GFP_KERNEL); > + if (!se) > + return -ENOMEM; > + > + se->dev = dev; > + se->owner = TEGRA_GPSE_ID; > + se->hw = device_get_match_data(&pdev->dev); > + > + se->base = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(se->base)) > + return PTR_ERR(se->base); > + > + dma_set_mask_and_coherent(dev, DMA_BIT_MASK(39)); > + platform_set_drvdata(pdev, se); > + > + ret = tegra_se_clk_init(se); > + if (ret) { > + dev_err(dev, "failed to init clocks\n"); Syntax is: return dev_err_probe > + return ret; > + } > + > + if (!tegra_dev_iommu_get_stream_id(dev, &se->stream_id)) { > + dev_err(dev, "failed to get IOMMU stream ID\n"); dev_err_probe > + goto clk_deinit; > + } > + > + se_writel(se, se->stream_id, SE_STREAM_ID); > + > + se->engine = crypto_engine_alloc_init(dev, 0); > + if (!se->engine) { > + dev_err(dev, "failed to init crypto engine\n"); Really? Test your code with coccinelle. Drop. > + ret = -ENOMEM; > + goto iommu_free; > + } > + > + ret = crypto_engine_start(se->engine); > + if (ret) { > + dev_err(dev, "failed to start crypto engine\n"); dev_err_probe > + goto engine_exit; > + } > + > + ret = tegra_se_host1x_register(se); > + if (ret) { > + dev_err(dev, "failed to init host1x params\n"); dev_err_probe > + goto engine_stop; > + } > + > + return 0; > + > +engine_stop: > + crypto_engine_stop(se->engine); > +engine_exit: > + crypto_engine_exit(se->engine); > +iommu_free: > + iommu_fwspec_free(se->dev); > +clk_deinit: > + tegra_se_clk_deinit(se); > + > + return ret; > +} > + > +static int tegra_se_remove(struct platform_device *pdev) > +{ > + struct tegra_se *se = platform_get_drvdata(pdev); > + > + crypto_engine_stop(se->engine); > + crypto_engine_exit(se->engine); > + iommu_fwspec_free(se->dev); > + host1x_client_unregister(&se->client); > + tegra_se_clk_deinit(se); > + > + return 0; > +} > + > +static const struct tegra_se_regs tegra234_aes1_regs = { > + .config = SE_AES1_CFG, > + .op = SE_AES1_OPERATION, > + .last_blk = SE_AES1_LAST_BLOCK, > + .linear_ctr = SE_AES1_LINEAR_CTR, > + .aad_len = SE_AES1_AAD_LEN, > + .cryp_msg_len = SE_AES1_CRYPTO_MSG_LEN, > + .manifest = SE_AES1_KEYMANIFEST, > + .key_addr = SE_AES1_KEY_ADDR, > + .key_data = SE_AES1_KEY_DATA, > + .key_dst = SE_AES1_KEY_DST, > + .result = SE_AES1_CMAC_RESULT, > +}; > + > +static const struct tegra_se_regs tegra234_hash_regs = { > + .config = SE_SHA_CFG, > + .op = SE_SHA_OPERATION, > + .manifest = SE_SHA_KEYMANIFEST, > + .key_addr = SE_SHA_KEY_ADDR, > + .key_data = SE_SHA_KEY_DATA, > + .key_dst = SE_SHA_KEY_DST, > + .result = SE_SHA_HASH_RESULT, > +}; > + > +static const struct tegra_se_hw tegra234_aes_hw = { > + .regs = &tegra234_aes1_regs, > + .kac_ver = 1, > + .host1x_class = 0x3b, > + .init_alg = tegra_init_aes, > + .deinit_alg = tegra_deinit_aes, > +}; > + > +static const struct tegra_se_hw tegra234_hash_hw = { > + .regs = &tegra234_hash_regs, > + .kac_ver = 1, > + .host1x_class = 0x3d, > + .init_alg = tegra_init_hash, > + .deinit_alg = tegra_deinit_hash, > +}; > + > +static const struct of_device_id tegra_se_of_match[] = { > + { > + .compatible = "nvidia,tegra234-se2-aes", > + .data = &tegra234_aes_hw > + }, { > + .compatible = "nvidia,tegra234-se4-hash", > + .data = &tegra234_hash_hw, > + }, > + { }, > +}; > +MODULE_DEVICE_TABLE(of, tegra_se_of_match); > + > +static struct platform_driver tegra_se_driver = { > + .driver = { > + .name = "tegra-se", > + .of_match_table = tegra_se_of_match, > + }, > + .probe = tegra_se_probe, > + .remove = tegra_se_remove, > +}; > + > +static int tegra_se_host1x_probe(struct host1x_device *dev) > +{ > + return host1x_device_init(dev); > +} > + > +static int tegra_se_host1x_remove(struct host1x_device *dev) > +{ > + host1x_device_exit(dev); > + > + return 0; > +} > + ... > + return -EINVAL; > +} > + > +/* Functions */ > +int tegra_init_aead(struct tegra_se *se); I look for it and cannot find it... Drop. > +int tegra_init_aes(struct tegra_se *se); > +int tegra_init_hash(struct tegra_se *se); > +void tegra_deinit_aes(struct tegra_se *se); > +void tegra_deinit_hash(struct tegra_se *se); > + > +int tegra_key_submit(struct tegra_se *se, const u8 *key, u32 keylen, u32 alg, u32 *keyid); > +unsigned int tegra_key_get_idx(struct tegra_se *se, u32 keyid); > +void tegra_key_invalidate(struct tegra_se *se, u32 keyid, u32 alg); > + > +int tegra_se_host1x_register(struct tegra_se *se); > +int tegra_se_host1x_submit(struct tegra_se *se, u32 size); Everything looks bogus... > + > +static inline void se_writel(struct tegra_se *se, u32 val, > + unsigned int offset) > +{ > + writel_relaxed(val, se->base + offset); > +} > + > +static inline u32 se_readl(struct tegra_se *se, unsigned int offset) > +{ > + return readl_relaxed(se->base + offset); > +} Both wrappers are useless. > + > +/**** > + * Use Linux coding style comments. > + * HOST1x OPCODES > + * > + ****/ > + ... > + > +static inline u32 host1x_opcode_nonincr(unsigned int offset, unsigned int count) > +{ > + return (2 << 28) | (offset << 16) | count; > +} > + > +static inline u32 host1x_uclass_incr_syncpt_cond_f(u32 v) > +{ > + return (v & 0xff) << 10; Fix indentation, in other places as well. Best regards, Krzysztof