From patchwork Thu Jun 28 13:07:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140438 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2165468ljj; Thu, 28 Jun 2018 06:07:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL7GajEGbJpU1se9kzdvaVVc9njgR6+vYWwKldwUg5Qbf+5ATj71kKJ88AjGeTdJaZttcju X-Received: by 2002:a17:902:9a06:: with SMTP id v6-v6mr10466050plp.21.1530191257453; Thu, 28 Jun 2018 06:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191257; cv=none; d=google.com; s=arc-20160816; b=F3zt9MVKohi7Qipu7XPrMcWpDomrf3tvK4KnT5fRkBzqy77Y+nolln9tM9aCct3EoS 5rQrtSAF+ymIuLcbHEFpScKkYyUDVM58Y0wSDTcF8egw9uy0OJ15kY9fz0QCHM3vZ7/P fgiGarfKtKgDDTkCB+dkspJECk0LpnqVR1AwKAA4bympMsOrdwGTZdTZJh25jO4ixG6/ dgCrtsWV0aWVKP5L1X8M/Vqb6e5XXXmZn/+5DmYAVO/qdjV7z+bZMJDPgPu0p8USWhDg 5KqZtMM+prUTyUT+ojTNX4aWqIi/3m5Bb7lZOGpzvIqak3JFbF75tvpXieAShfijknnW SfkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=V9ECP2ySTpSXKVWkiHHc8Wx4krHcDvQVclbVZAFAQoA=; b=RlM8gzjYp+Fu9VthNteaXgLIypoe/wJS3U93CwN0MJQvGHLwwaDNocrZ02UfehaBTy hIXKEyI/5ByHj/cPj9CwzFVqXWQypylXyNwYzqnD3BV1x6Gjy2CyiUYV5KPLoLDXQn2q IBd1Y4AF2L9uMsdM6XccmyIozz2puAj+s18WedBK3E+7CNQ8M10qL0uV5+CilMNkBJn0 eDubD+PatqZ3hxhj+2H3LQh4xUXQhjS1OokFrANpNW2yzWKG9qfRuCsCe/B+9i3LDq8h C4yplFf7Bi6uylIv4XkFmDFDQBovp5c+A86SP3/Mcg2/yS9lcpRG54WVQDIT8zQvrIUX umfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cMzehrpT; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6-v6si1703418pls.419.2018.06.28.06.07.37; Thu, 28 Jun 2018 06:07:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cMzehrpT; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964908AbeF1NHg (ORCPT + 1 other); Thu, 28 Jun 2018 09:07:36 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:40222 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964849AbeF1NHf (ORCPT ); Thu, 28 Jun 2018 09:07:35 -0400 Received: by mail-lj1-f196.google.com with SMTP id a6-v6so4457535ljj.7 for ; Thu, 28 Jun 2018 06:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=V9ECP2ySTpSXKVWkiHHc8Wx4krHcDvQVclbVZAFAQoA=; b=cMzehrpTcVOo4zQuoMJ1IM86u09rFgYndllYaLZf6r9fM7eCLU4i3U24pD15bjLGIt zaZpFC7MjuR9eZfDOkaIDP10sTxP9ZG7hCCRpLrJeRcg2ghV10p9CoPPZNETUehbGsCb uQM8N4L/Om/iMuhUzKz5V+2b0sITbKSLsLiAo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=V9ECP2ySTpSXKVWkiHHc8Wx4krHcDvQVclbVZAFAQoA=; b=faEPNHS579f72DMyjSFmuzLqfR0Nr4aqWtLyOUbSvEO7/wFMMF6CqA21pt1XUzU/sQ gFFRAiqLzxKHqJDqvMAfkGcPMFOKfJMAvAgBIpwJxnhfTi4OEM1f+8ulE+xSD35H92gg OAZ1dhTORfEths2Q56UClReCYQ85JXCggU4fJvOy5t9NKGXObAf4I4Oqiid16XJhTSiu 92Gm9+fy5eWvhXazdZ1cAjlZMvEpnHybKBBw2SCrCkMV6SHkEPEtypCLk24bvMooxNb8 O6esGf9cULDvTmmwb5HtaCzM2BNX+CXfYZI80NDqRZRaJw2tcmgndtCrLG/3tAUEW9Eb PdJA== X-Gm-Message-State: APt69E1STEZ+IBOfgTWEA6+WWjcl0JgI4I4wvq9sUj1zH/6v7fHIuwtC 8E+KFW5Va04aFmlqo+/J13HpvVs68Fo= X-Received: by 2002:a2e:8185:: with SMTP id e5-v6mr65327ljg.93.1530191254111; Thu, 28 Jun 2018 06:07:34 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:33 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 1/9 v2] crypto: atmel-ecc: Make available for other platforms Date: Thu, 28 Jun 2018 15:07:21 +0200 Message-Id: <20180628130729.17589-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This is a pure I2C driver, and this device appears on the 96boards Secure96 mezzanine card, so we want to enable the driver on other devices. Cut the Kconfig limitations to Atmel SoC only. Reviewed-by: Tudor Ambarus Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Collect Tudor's review tag. --- drivers/crypto/Kconfig | 1 - 1 file changed, 1 deletion(-) -- 2.17.0 diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index 43cccf6aff61..b4dd64d2d4ca 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -519,7 +519,6 @@ config CRYPTO_DEV_ATMEL_SHA config CRYPTO_DEV_ATMEL_ECC tristate "Support for Microchip / Atmel ECC hw accelerator" - depends on ARCH_AT91 || COMPILE_TEST depends on I2C select CRYPTO_ECDH select CRC16 From patchwork Thu Jun 28 13:07:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140439 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2165529ljj; Thu, 28 Jun 2018 06:07:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJdp/ee6Dh8EnCjon7GgKUKvKuqUgvodOje0mRXVUa3cmTW8XFqHTiAp+SD+/5q97MbxZFQ X-Received: by 2002:a63:6a89:: with SMTP id f131-v6mr8873991pgc.311.1530191259848; Thu, 28 Jun 2018 06:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191259; cv=none; d=google.com; s=arc-20160816; b=EI9HD51cQ3OYsqNvzG8Jkyf5GGGd9pgshrcC/4yV6lRbB5AM/z5Mb9ibNAjw30Vwyf O2smcjNajUhqtOGY+TBF09Oci4ivBdwmPIzTQlWlmWOllp7NRnOjvUgGS0UZAfAsIVRO AXr4et3wFvJ8STQhEDc8ZIwmdXM8XfaSHFxYBwdAGNT/10TeCubBU6xV/H2gU/2DLFQW D3MjNs1cdpjkAaJGXT3gjtKLAs7uB7mR6IA5f3CRxUeHCHtiQTL9QKnOd/V+j7sIiJ6T pmJATCm9J/PLhtR6dHnFs8pqDaoIcYx4PeyOVJ05qXgnoNvw1iwV5rSc0P+JDLBr4j2/ lqzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=awd2jvEyEmmZRePhnDihWg10R3+ZTozX7h2ek8tKBfE=; b=eNSp+gRKEUdhXCXK0V2rn5LeWEIIY5bZ1IMXPGptY79/BhgbKbdiVvS5TdSATALglX koOvjnAOtAn/zGGS1q+wYwPyDrCarjSYFYS8UsqkKQT1ZEyRRXnwVvOI7P/9v4qQwiIZ YOA7wXqEgMFpOXD87iCJWXV1PgAOwUvPQuy6Vd35thkHKE4ts1ABNd6L0bl5PPnkV0T2 eGkmVNNNUy0Gz4+p/+FCwo63dvTDJ3AkMEcABgaTgIBq8MphqC3h3oBr75EEayw7twWK gUFXaaL6ZdG7iUEcV33NAIoRoZjGfPMdYB6n2a1VTVp/mf04zrD49MJGN4e5TTyV4Bpi R8qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JOq09eum; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6-v6si1703418pls.419.2018.06.28.06.07.39; Thu, 28 Jun 2018 06:07:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JOq09eum; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965012AbeF1NHi (ORCPT + 1 other); Thu, 28 Jun 2018 09:07:38 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:37325 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964849AbeF1NHi (ORCPT ); Thu, 28 Jun 2018 09:07:38 -0400 Received: by mail-lj1-f196.google.com with SMTP id c11-v6so4453912lja.4 for ; Thu, 28 Jun 2018 06:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=awd2jvEyEmmZRePhnDihWg10R3+ZTozX7h2ek8tKBfE=; b=JOq09eumRNaSzhUbD9wJ4CeqGIKij5/OPDW0dzb1PYNWywjO9rMc+caTvyTqcth2z9 rioeVEBvxe257AAqioK2/5GvPnjml6GgwrH5yvAiZrnUovlFreuAmgn3lXXl/lbbBxG3 65+reISvKAEpaqZUxVEAFCZ9/chUzyb6qGT3Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=awd2jvEyEmmZRePhnDihWg10R3+ZTozX7h2ek8tKBfE=; b=cKazqzhp/oXl3cxTR/xMJqbEFvOy87jg0QiHKNpxW7i8OuSaLpnFKI8GEQxjnmQ23I 7D1ydJR0b5OgZH04Rg49hF55Qmg/QvCJGFvUtR0ZgGiv3QervcKzR63NeTY2OwxWsBFQ eVinlPFdCnEQOnN8oLpQ2bzMdMVeSSi3+A5WdnpJB65dodIjttIFyPNB2/4dKp2YrEGI 9ua9/JhaAbbEkihVgGqfw8iHsB0t6zwjFZqv0bI06Nfinq2b6Ogr37HtaNwOKKGhia3i 3QSq2bWqtc0ECFGqDa3HFOJR9yshyQzmYgOxLvvZDem593w8QySNUar0MD++M7CS/gyI hZfw== X-Gm-Message-State: APt69E0ZpNU7wfE5KvE+ENlMw/yYnVYFGXIgU+xCpkTOxnv31PkN3y3q 6sn4aRWiTOFQ1E8TFgmK0Ov7BXuvreQ= X-Received: by 2002:a2e:534e:: with SMTP id t14-v6mr6878194ljd.73.1530191256625; Thu, 28 Jun 2018 06:07:36 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:35 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 2/9 v2] crypto: atmel-ecc: Just warn on missing clock frequency Date: Thu, 28 Jun 2018 15:07:22 +0200 Message-Id: <20180628130729.17589-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The Atmel ECC driver contains a check for the I2C bus clock frequency, so as to check that the I2C adapter in use satisfies the device specs. If the device is connected to a device tree node that does not contain a clock frequency setting, such as an I2C mux or gate, this blocks the probe. Make the probe continue with a warning if no clock frequency can be found, assuming it is safe. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Instead of silently ignoring the missing clock frequency, issue a warning and continue. --- drivers/crypto/atmel-ecc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index e66f18a0ddd0..33773920e4bf 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -659,12 +659,9 @@ static int atmel_ecc_probe(struct i2c_client *client, ret = of_property_read_u32(client->adapter->dev.of_node, "clock-frequency", &bus_clk_rate); - if (ret) { - dev_err(dev, "of: failed to read clock-frequency property\n"); - return ret; - } - - if (bus_clk_rate > 1000000L) { + if (ret) + dev_warn(dev, "i2c host missing clock frequency information\n"); + else if (bus_clk_rate > 1000000L) { dev_err(dev, "%d exceeds maximum supported clock frequency (1MHz)\n", bus_clk_rate); return -EINVAL; From patchwork Thu Jun 28 13:07:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140440 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2165719ljj; Thu, 28 Jun 2018 06:07:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJEw1piESjmzUOvweh8TgqmbS2x7FgmekMKePGZEQ2nL7bB/zkpRflblZfG6/5EnONxpr01 X-Received: by 2002:a17:902:43a4:: with SMTP id j33-v6mr10497671pld.118.1530191266538; Thu, 28 Jun 2018 06:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191266; cv=none; d=google.com; s=arc-20160816; b=iNaBf+OYXxr6o23YIiQA1W9n2j6+gnE7EP8xlj9plXE2uUp/f68uklFmF/DQr6e2f5 CcaYiEVz2BwFMdQnN+BvkqQBcqPqXldj5DsxwDw1qQmkkX4egOGwJuk7DdRZnJFjUcgV eqdlzFjrFslxIzCvHgo4DEXqjfdmmIBFDZsVYYx8SaBKrEM2GZo5n33VPJCOV7xnTnZg 2LFafCkEC4b65My5BVsgXFa0SAoTdGlohm6g/zXfOxB5VZJfaFcdaHKH4WUNseL2thkk gvTcZS+nvRVlCCOl4dcGZHQJVi/frgR7/e+BxDW3sUu1P7fOG6I7kQ/Q23HYbHPGZBlZ yt3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=se/vxmp7nkVG7uhxmaj52atkM34NStXapZjQpW93EF0=; b=hbZz7bpDclISRPjTdUWn4s4ubY5z/dnP5i29w6LsR3aR6hl6sqbJIpzfdR4VM7aDxM GXMnbCaukYWaEDz0PBJlxT3By5BcufdDaR8nHjgAGBuLxWoNZrXLsZtuq0x8ujm2Ei/z hfUYaVrDMvzcLzBgHiwQTUWtHhfvMz6+akS2eYLNBTBFSsb1CAwF9WDAWFyxNYefqCUA VJq4cRl5u7NQu5PYTc3Doy44wWTiQCmJBYYSydYDeFBR8iGEXWYqzPadKGrsmV86mYKX 0tP0TeWHIw22cn4lGA24olZCNrYIU9e/bG1GEv6D8WlTsX6JeY2UAs+dt6CxUUfxsG6C 1OeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W3JTLi87; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9-v6si6556676plo.206.2018.06.28.06.07.46; Thu, 28 Jun 2018 06:07:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W3JTLi87; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964849AbeF1NHm (ORCPT + 1 other); Thu, 28 Jun 2018 09:07:42 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:43889 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965245AbeF1NHl (ORCPT ); Thu, 28 Jun 2018 09:07:41 -0400 Received: by mail-lj1-f194.google.com with SMTP id h2-v6so1216423ljb.10 for ; Thu, 28 Jun 2018 06:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=se/vxmp7nkVG7uhxmaj52atkM34NStXapZjQpW93EF0=; b=W3JTLi87U82S5euM/Bv2KNdqrHnrkej7clgWZUAq8fLf7/a+U48jOLqxM6wDWZEaGV fpg8vQGcwVa5XG74yzW8yl44MZP9Zio35hzB6UHX7x3+etdmcypnjp9HcDhVgPE0svjW vRDACK5L5SB2Hzv3dJczzdcfwsEf4YU7b8xp8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=se/vxmp7nkVG7uhxmaj52atkM34NStXapZjQpW93EF0=; b=GVqVa+QnY0AhyYAGGZmB8gCXjBhmf69gI/20x4Xb8gBUTUoNv3tqKEgr5bH3aE6BjJ bFZecusBe6UY7OXvpHUkGBW7B+7jb4Kt8c8fPJI4yqBGpKbiULqRFfRTYUrS2huWVaY6 N3qFbp35uicXE4nQ/DyIBgXuFWHh3RzpRcBmrS45KoE6a14l7BJy8haohSmuAR7BnjNz UMvlNX9wvQg9qJSzkS2hXo6+oXdaMnaK1fgHpuFYQ1e9424iNsI8iZG43brwVjxPT5kd IOpeFJsMgqDvBbkpYxUGcYD3JH6Rn+IYaq0tOHTlNN10DhNNsVlWZzfzbAtX2GDbCR9w C3pA== X-Gm-Message-State: APt69E1bk8EnokQnee+Sx+tLUVZ46B4hR1T/YBfXuTueOGaDEmrTQ/rb kVbmhFcO6jZLGXT3uG8PyL5iNHt2AlI= X-Received: by 2002:a2e:4811:: with SMTP id v17-v6mr6938418lja.39.1530191259185; Thu, 28 Jun 2018 06:07:39 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:37 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 3/9 v2] crypto: atmel-ecc: More helpful error messages Date: Thu, 28 Jun 2018 15:07:23 +0200 Message-Id: <20180628130729.17589-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Report errors once when they happen on the I2C bus so we get good information in cases such as when the wrong I2C address is used. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Strip some comments that are now obvious from the context with the error messages. - Do not print the excess ECC error message, atmel_ecc_status() already prints error messages. --- drivers/crypto/atmel-ecc.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 33773920e4bf..baef0d07164d 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -310,26 +310,31 @@ static int atmel_ecc_send_receive(struct i2c_client *client, mutex_lock(&i2c_priv->lock); ret = atmel_ecc_wakeup(client); - if (ret) + if (ret) { + dev_err(&client->dev, "wakeup failed\n"); goto err; + } - /* send the command */ ret = i2c_master_send(client, (u8 *)cmd, cmd->count + WORD_ADDR_SIZE); - if (ret < 0) + if (ret < 0) { + dev_err(&client->dev, "command send failed\n"); goto err; + } /* delay the appropriate amount of time for command to execute */ msleep(cmd->msecs); - /* receive the response */ ret = i2c_master_recv(client, cmd->data, cmd->rxsize); - if (ret < 0) + if (ret < 0) { + dev_err(&client->dev, "getting response failed\n"); goto err; + } - /* put the device into low-power mode */ ret = atmel_ecc_sleep(client); - if (ret < 0) + if (ret < 0) { + dev_err(&client->dev, "putting to sleep failed\n"); goto err; + } mutex_unlock(&i2c_priv->lock); return atmel_ecc_status(&client->dev, cmd->data); @@ -624,8 +629,11 @@ static int device_sanity_check(struct i2c_client *client) atmel_ecc_init_read_cmd(cmd); ret = atmel_ecc_send_receive(client, cmd); - if (ret) + if (ret) { + dev_err(&client->dev, + "failed to send ECC init command\n"); goto free_cmd; + } /* * It is vital that the Configuration, Data and OTP zones be locked From patchwork Thu Jun 28 13:07:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140441 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2165740ljj; Thu, 28 Jun 2018 06:07:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIzeT7gPKQgluSicLF8X/T1SzgpxEFPiExFQF9n1RZzwxWqA8960k/29HEJcUXzXmSo9cV1 X-Received: by 2002:a17:902:ab8e:: with SMTP id f14-v6mr10628859plr.5.1530191267513; Thu, 28 Jun 2018 06:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191267; cv=none; d=google.com; s=arc-20160816; b=XaEJp3IF85Hr2uAKtzPQ6mTviBMoMpzP/h0gagJQTqNr1E00H8VR4gSJVeyPEorGnI 2O5Cu8/KWx6aJbVbfTYKV1ze3mAwAkilKx6eQZy1PQPrYjy3cOLTSl9G2FVHdkAa2lB/ 5Dq4KeFjSBMvBY5Rw3UWg3Uwb9i9a3qXNxXSdLw1lLPxJZ1iGVLacILhsmuw6UTuNJ79 S8kakuJNjExsOG1B8ZjxbccOhKkvtPSY6avVvNXX2Ko4WysQRdJ7ApKcE05puVbpClgV lgWE1w8uLRprMjU5nLKakJ3caghoTx3JUvYnbV5lWszZS+JAj0htUVJDVQlbhY6XCEMz x5Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=AgxcxdlfOQPaVfkFXmBs8u5Ntq7lvuhH8awgjSkSh0I=; b=gdfZHg7QlTt2VtZLkEWru/gGVB/hHYHUE+d+FkyjdvVg9072Bk0Ra7IgQO4OPt6PpH 2AEv23XhWlvkR3PcJxybsuBN6Eez4Whz9ma0vW1z+NwM0XDVt06DMU8LZ/HntW4LG3PO 9yzJFbnb7y+Jz9+vU7m8U1KcJoFasNod6z3C4hdXThiLZLfC0vt3Bs7xJvdTwYGa1i/H wL/EbaWk8BBlEFcAbKxqg818Zo7xwN4/I4XjNCAtsHoDypp+Cankt9wby1jVUKRUCEyw /xUQfxoEqSSg9OCL7ZtGixMBTo58htwvF78GNRdRoGXnKTZTvq8oc0xTKRe1XzdrpbKw 6EYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M0um8YLI; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9-v6si6556676plo.206.2018.06.28.06.07.47; Thu, 28 Jun 2018 06:07:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M0um8YLI; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965496AbeF1NHp (ORCPT + 1 other); Thu, 28 Jun 2018 09:07:45 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:42201 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965245AbeF1NHn (ORCPT ); Thu, 28 Jun 2018 09:07:43 -0400 Received: by mail-lj1-f194.google.com with SMTP id k20-v6so4451233ljk.9 for ; Thu, 28 Jun 2018 06:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AgxcxdlfOQPaVfkFXmBs8u5Ntq7lvuhH8awgjSkSh0I=; b=M0um8YLILfxdSY7413gX7TpEVvdJXNu47oWv4zDqYZAzOKSeYm4gp8dmIVOVchD56n A8jboNSZZu2QNPVQNYFllBnpALqvovw3Jv6+w4EYDYDMmzQtDSyO12QZaQhOHIUkf7Ii LfQDX0ux0gJYLg75a1nnc0VFJUblGzChf31cU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AgxcxdlfOQPaVfkFXmBs8u5Ntq7lvuhH8awgjSkSh0I=; b=gAoksyZIwFyTBrRLEI/8eckcD9X0tT6vzhZ+xfGGNW+1mM7wd6nmGuA3xdet3tjT6W cS6op4c6KrkYcxS97xMO/vFBRji5mOVNOG5YT1T/wlXJIQD/MdVECZlBGHxtWCyUPFmr UvKkgl5O9CT49AqdVYJPmfCAL3AWh0bIjaxiCqee+pmRpH0LELddkU5WKqbj9Q7Tkkpc SPAx2TP6/BvoCtKhU1I+/Vx+BlL/fExEBWtzH7EslKly7YbNtgKnzi1PXrpxecdUrGlq MBBnUACBBHPb9PhIWQk3fRKh644dbQNgKrkcYBnogzIi2hC4hBawOpWwpjzuJiNalytq Uxrg== X-Gm-Message-State: APt69E13D5bN+BXPPR/3g8F6H8aPl225OsHhn0piBKAD9M4KsstFi6xW jT6Tf+fZNb24dWAZTpjKIOWbxYRJeRY= X-Received: by 2002:a2e:3819:: with SMTP id f25-v6mr5191792lja.25.1530191261579; Thu, 28 Jun 2018 06:07:41 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:40 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 4/9 v2] crypto: atmel-ecc: Provide config zone defines Date: Thu, 28 Jun 2018 15:07:24 +0200 Message-Id: <20180628130729.17589-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The config zone has 0x16 words of 4 bytes each, so provide some basic defines so that we can address these individually. Rename the last word to "footer", this is where we currently look to see if the configuration is locked. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Diet the defines down to the ones used in this patch set. --- drivers/crypto/atmel-ecc.c | 2 +- drivers/crypto/atmel-ecc.h | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index baef0d07164d..98f9322ca303 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -145,7 +145,7 @@ static void atmel_ecc_init_read_cmd(struct atmel_ecc_cmd *cmd) * (UserExtra, Selector, LockValue, LockConfig). */ cmd->param1 = CONFIG_ZONE; - cmd->param2 = DEVICE_LOCK_ADDR; + cmd->param2 = CONFIG_ZONE_FOOTER; cmd->count = READ_COUNT; atmel_ecc_checksum(cmd); diff --git a/drivers/crypto/atmel-ecc.h b/drivers/crypto/atmel-ecc.h index 25232c8abcc2..d941c4f3d28f 100644 --- a/drivers/crypto/atmel-ecc.h +++ b/drivers/crypto/atmel-ecc.h @@ -89,8 +89,13 @@ static const struct { #define RSP_DATA_IDX 1 /* buffer index of data in response */ #define DATA_SLOT_2 2 /* used for ECDH private key */ -/* Definitions for the device lock state */ -#define DEVICE_LOCK_ADDR 0x15 +/* Definitions for the configuration zone words, these are 4 bytes each */ +#define CONFIG_ZONE_SERIAL_0_3 0x00 +#define CONFIG_ZONE_REVISION 0x01 +#define CONFIG_ZONE_SERIAL_4_7 0x02 +#define CONFIG_ZONE_SERIAL_8_I2CEN 0x03 +#define CONFIG_ZONE_I2C_OTP 0x04 +#define CONFIG_ZONE_FOOTER 0x15 #define LOCK_VALUE_IDX (RSP_DATA_IDX + 2) #define LOCK_CONFIG_IDX (RSP_DATA_IDX + 3) From patchwork Thu Jun 28 13:07:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140446 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2167326ljj; Thu, 28 Jun 2018 06:09:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIH0xX9midTmeoQTv43VgI5CdoxO5lNWcSYJ+qD1g7BUWKLLU0tBLwQN3KOzj0JW8mTn8DF X-Received: by 2002:a17:902:8a95:: with SMTP id p21-v6mr10418961plo.91.1530191341922; Thu, 28 Jun 2018 06:09:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191341; cv=none; d=google.com; s=arc-20160816; b=UG9IvdnW8t3eY+VCMJ4ypnY5bQeqBg9jwLZwgO+VpJW21LTLRf1C7neD07NgyUoy3o Txnj/EUku+p9rk7mX7lssie1M/YhEnwA75w8+MAAQaggFHFjrjkb3iOZl70fxDHEfYTD FlD7jJKYe+4GB8MZYCpPLuEgdMbNR3CRF4zgpS3tic3GjGX18gy0cMvhZNCTAmkiPx3B BFuDJW7lO1caQsccMQSqoC3/dbATT3ow2e9KkOo9UOqIp1k+IlpMQBf0rYPmgrpotFJ6 fOkJiZd5O9sTVj4honLM19uPSkCXYwZtZvf3V8xUemnqI85f7LYzdMkQT+SCxqEPEz7y 8sPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=RCUZOTlkGLi6p/CY8nAqZie/MEHQ0+WtYX7Cnp+kF/w=; b=zS0LBC+9grkQk6aI/77tu0xAX99P5y60c7h59dyuRRkpi7c9E65PQGRs3Q+MMDSZve T/I3oKeEqRc4e+bRjvTc5NsXeO32WK3e0sRgidFlH/QvBgkYLYBlpMvVHryr2xEndk3a eYXkzpJyZKZlahKrFqPr2ddE5pM92jwjDPogt3+DomWZCyqO724nF6fX//5kUZicuP1Z TeY/HHhv8M7yMjYG9PpfieUXU6icFr3rXvCmuEag2rfrxgiLsziuot5+aBYvGzWT/bVK m75PSlBb8eR3xXESL5vgASe92PVFKFPwDlZxMPobAiJLJlOWxhMnuYlf/zkqCr/UJteE kSCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=McoSqrqB; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i130-v6si5408126pgd.691.2018.06.28.06.09.01; Thu, 28 Jun 2018 06:09:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=McoSqrqB; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965895AbeF1NIp (ORCPT + 1 other); Thu, 28 Jun 2018 09:08:45 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:37334 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965485AbeF1NHp (ORCPT ); Thu, 28 Jun 2018 09:07:45 -0400 Received: by mail-lj1-f193.google.com with SMTP id c11-v6so4454266lja.4 for ; Thu, 28 Jun 2018 06:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RCUZOTlkGLi6p/CY8nAqZie/MEHQ0+WtYX7Cnp+kF/w=; b=McoSqrqBwgplQxgSboqPCE5oZNmkZoA8fAwgGBfjXbtcC22bgqcdtRWo0CpnL87aSu NQdTnA/hJNr4iUX8extgtkBJf4FRv2G0tpV9kDnfuLwGsNH4Hh3RAxgQc+gOCyIdQ3V8 9jD5df0WjheZO1frvaQV17IK/xbgtinHs+aAU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RCUZOTlkGLi6p/CY8nAqZie/MEHQ0+WtYX7Cnp+kF/w=; b=JyseguEfD0Mq+qXUo6IT5wqqRtPA2EDIkfMzSGhdSzoHJmHaGR/oTUOmYcn+OaHZ6A W+UKXg1T1Zn91QyO+qHFGKex3vyu2BIgRunmm1gqnr+PMPlQiQQB2AXYGpyUXFFvD++y Zt08UkNEb+EmFxEIOcXpJ+jh85pXJa+AgqMlkHTDGr7zMUvcdDFdiwShj7PxK1dm+a9+ SHZ5oEd2CUYy8XDdT2FKm3dh/FlmJdxem1leunOPtRxW8tVnnbVNaKXhzUsPbWDebTiT 5Xv+Ztu4MkWPdS24dXR1BeGR9aE5psNA1ngClN7qzTVa7Su4h5V40bAGmnl4VGJ549CU 4L9A== X-Gm-Message-State: APt69E1DHwrU4hfIVFTIv2X88KWx+2zkJYwI+eZWn/Ra04w9IGv6RyaX F27bVWXl2Nm4vuwks08KSFYrPSe7/NQ= X-Received: by 2002:a2e:7603:: with SMTP id r3-v6mr6926166ljc.81.1530191263584; Thu, 28 Jun 2018 06:07:43 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:42 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 5/9 v2] crypto: atmel-ecc: Create a config word reader Date: Thu, 28 Jun 2018 15:07:25 +0200 Message-Id: <20180628130729.17589-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Rewrite the function atmel_ecc_init_read_cmd() into a more general atmel_ecc_init_read_config_word() function to read any word from the configuration zone, and use this parameterized with what we want to read out. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebased --- drivers/crypto/atmel-ecc.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 98f9322ca303..2ec570d06a27 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -136,16 +136,13 @@ static void atmel_ecc_checksum(struct atmel_ecc_cmd *cmd) *crc16 = atmel_ecc_crc16(0, data, len); } -static void atmel_ecc_init_read_cmd(struct atmel_ecc_cmd *cmd) +static void atmel_ecc_init_read_config_word(struct atmel_ecc_cmd *cmd, + u16 config_word) { cmd->word_addr = COMMAND; cmd->opcode = OPCODE_READ; - /* - * Read the word from Configuration zone that contains the lock bytes - * (UserExtra, Selector, LockValue, LockConfig). - */ cmd->param1 = CONFIG_ZONE; - cmd->param2 = CONFIG_ZONE_FOOTER; + cmd->param2 = config_word; cmd->count = READ_COUNT; atmel_ecc_checksum(cmd); @@ -626,7 +623,7 @@ static int device_sanity_check(struct i2c_client *client) if (!cmd) return -ENOMEM; - atmel_ecc_init_read_cmd(cmd); + atmel_ecc_init_read_config_word(cmd, CONFIG_ZONE_FOOTER); ret = atmel_ecc_send_receive(client, cmd); if (ret) { From patchwork Thu Jun 28 13:07:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140444 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2166511ljj; Thu, 28 Jun 2018 06:08:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcnRNnZjyQRTl4T2Blkhe5i6bXX01NIPB+blvP+MGG0mqYGi1g8Mx6MREfl6sfvnBV7ySrU X-Received: by 2002:a65:498c:: with SMTP id r12-v6mr157504pgs.112.1530191302878; Thu, 28 Jun 2018 06:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191302; cv=none; d=google.com; s=arc-20160816; b=F3Jlk9jKn7NXAcH4y23MVesUH74Oy059Urt/DI2enxVcpGHA2F3KJPTC6Kli7XrU9o YsUDNodoeP6YaLwkeGFGap8q/yXh4vKfm2LbyJXrCAmGC4C07eu3ph8sP3NWMgyL2sia CQ3f5UqwME+TAZad4q9o+UyrQnKFIeIiNRvMrc4/7OvoRE+D6+9To313Xv0Nr/yUoYVt W+GLQZAm2B/NMPCRs3C074REfb+qIq04erVukVIL0+eGjqvumqA5fkgjFxAsszikRhgc C0WnuIkfIRMqlW+mpr4zoVfqn+Nr5z6qOPaJs5dbVlscId0GVkJ+D+VSAR+Xb7ajtlsy UWzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=znQp7iv1eckxnsCUtLYnt+wbxxbUmE18px2GlzrAhgM=; b=QWxeg01NAqcjZl8A4urmx8qz8XwXzY9I1gthD2JjhKkdygfp1W9YRCsqeKgFDjudbv XzMRoL2xBqwXv06Eed9/LILzSyX08W4PdpimJhqZNplcb5baNHGs3afgV/bAs1sU4iBW IhDIhQrAjIeb/8KacyUAVZuME0GQvXsWvO0OhgibcGSrUOFNxg1njphjJKp9LFJuIoXN zM6qlBwqLMWSFwCL/mwDltPg6xrfUbgTZ/VwDhNSUFI7jUvjPCGYdINtR6n/PU8qkyiA wznXXHEMVs0eRYBtpW98G8dhoPikEKwVPyhTd0pKaPaP0UjcvfKAMswwJbzn1bkKbScb kJIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fkPtPNWt; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p88-v6si6621399pfj.294.2018.06.28.06.08.22; Thu, 28 Jun 2018 06:08:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fkPtPNWt; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965269AbeF1NHy (ORCPT + 1 other); Thu, 28 Jun 2018 09:07:54 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41978 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965644AbeF1NHr (ORCPT ); Thu, 28 Jun 2018 09:07:47 -0400 Received: by mail-lj1-f195.google.com with SMTP id a17-v6so1345809ljd.8 for ; Thu, 28 Jun 2018 06:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=znQp7iv1eckxnsCUtLYnt+wbxxbUmE18px2GlzrAhgM=; b=fkPtPNWtcgAtbTJeGqIUMbBnimeyZ1pZIuJ9NpKnNHBa3md56OvfvliIAuoji90ViQ Ze0npT5qj8kk8py3ZiWoyI+WBrHLEZTzfi85UAK7MedpqVDlNUuu682IwgwBZ3ISx5sm dyfcEm5Nbe3cTwRSyqwcoyX+VBGBERaBchycs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=znQp7iv1eckxnsCUtLYnt+wbxxbUmE18px2GlzrAhgM=; b=nrjfeskGg58+BzrItaXIzHmhQX957I8o5ZH/+6h7PNm9A8qDcloOu0uKnlhySPSgF7 OH4bhPrQ5HqHQqvyRKoLm27x+B8F2X4F23WPtn967Hom+oK3W26bxEGHMwEkktKdwNtv 0m0j1AD0QeMlpeELpU5Mx5oeVSVlTlqmmnYaRPl9kUrdJi+BjE9J+rQwpBv+/C5Sntp/ Fs0UCcVgGP5XJMQ+l/dbtmrTne+dPVnXVdKXtW11UNXdA7HVnASJbheQcHAA1LWv+0rH 8QuAFyeKsoBCCdZ2gbMYF4ysnwWqBT8iCoILHhn0F8DaIgcL1q+qoCzeFPdrPCfVt++C 8H7w== X-Gm-Message-State: APt69E2lt1vTQu2ONbcrfym+rDMCsChvnoD19JIEwm2PNLxuC5GACYci JLJeZ0H6BUcGwd36FEHov11wPTCqTsU= X-Received: by 2002:a2e:18b:: with SMTP id f11-v6mr7056951lji.83.1530191265439; Thu, 28 Jun 2018 06:07:45 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:44 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 6/9 v2] crypto: atmel-ecc: Marshal the command while sending Date: Thu, 28 Jun 2018 15:07:26 +0200 Message-Id: <20180628130729.17589-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of casting the struct for the command into (u8 *) which is problematic in many ways, and instead of calculating the CRC sum in a separate function, marshal, checksum and send the command in one single function. Instead of providing the length of the whole command in defines, it makes more sense to provide the length of the data buffer used with the command. This avoids the hazzle to try to keep the command structure in the device endianness, we fix up the endianness when marshalling the command instead. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on other changes. --- drivers/crypto/atmel-ecc.c | 72 ++++++++++++++++++-------------------- drivers/crypto/atmel-ecc.h | 13 +++---- 2 files changed, 41 insertions(+), 44 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 2ec570d06a27..f3322fae454e 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -113,29 +113,6 @@ struct atmel_ecc_work_data { struct atmel_ecc_cmd cmd; }; -static u16 atmel_ecc_crc16(u16 crc, const u8 *buffer, size_t len) -{ - return cpu_to_le16(bitrev16(crc16(crc, buffer, len))); -} - -/** - * atmel_ecc_checksum() - Generate 16-bit CRC as required by ATMEL ECC. - * CRC16 verification of the count, opcode, param1, param2 and data bytes. - * The checksum is saved in little-endian format in the least significant - * two bytes of the command. CRC polynomial is 0x8005 and the initial register - * value should be zero. - * - * @cmd : structure used for communicating with the device. - */ -static void atmel_ecc_checksum(struct atmel_ecc_cmd *cmd) -{ - u8 *data = &cmd->count; - size_t len = cmd->count - CRC_SIZE; - u16 *crc16 = (u16 *)(data + len); - - *crc16 = atmel_ecc_crc16(0, data, len); -} - static void atmel_ecc_init_read_config_word(struct atmel_ecc_cmd *cmd, u16 config_word) { @@ -143,10 +120,7 @@ static void atmel_ecc_init_read_config_word(struct atmel_ecc_cmd *cmd, cmd->opcode = OPCODE_READ; cmd->param1 = CONFIG_ZONE; cmd->param2 = config_word; - cmd->count = READ_COUNT; - - atmel_ecc_checksum(cmd); - + cmd->datasz = READ_DATASZ; cmd->msecs = MAX_EXEC_TIME_READ; cmd->rxsize = READ_RSP_SIZE; } @@ -154,14 +128,11 @@ static void atmel_ecc_init_read_config_word(struct atmel_ecc_cmd *cmd, static void atmel_ecc_init_genkey_cmd(struct atmel_ecc_cmd *cmd, u16 keyid) { cmd->word_addr = COMMAND; - cmd->count = GENKEY_COUNT; + cmd->datasz = GENKEY_DATASZ; cmd->opcode = OPCODE_GENKEY; cmd->param1 = GENKEY_MODE_PRIVATE; /* a random private key will be generated and stored in slot keyID */ - cmd->param2 = cpu_to_le16(keyid); - - atmel_ecc_checksum(cmd); - + cmd->param2 = keyid; cmd->msecs = MAX_EXEC_TIME_GENKEY; cmd->rxsize = GENKEY_RSP_SIZE; } @@ -172,11 +143,11 @@ static int atmel_ecc_init_ecdh_cmd(struct atmel_ecc_cmd *cmd, size_t copied; cmd->word_addr = COMMAND; - cmd->count = ECDH_COUNT; + cmd->datasz = ECDH_DATASZ; cmd->opcode = OPCODE_ECDH; cmd->param1 = ECDH_PREFIX_MODE; /* private key slot */ - cmd->param2 = cpu_to_le16(DATA_SLOT_2); + cmd->param2 = DATA_SLOT_2; /* * The device only supports NIST P256 ECC keys. The public key size will @@ -186,9 +157,6 @@ static int atmel_ecc_init_ecdh_cmd(struct atmel_ecc_cmd *cmd, copied = sg_copy_to_buffer(pubkey, 1, cmd->data, ATMEL_ECC_PUBKEY_SIZE); if (copied != ATMEL_ECC_PUBKEY_SIZE) return -EINVAL; - - atmel_ecc_checksum(cmd); - cmd->msecs = MAX_EXEC_TIME_ECDH; cmd->rxsize = ECDH_RSP_SIZE; @@ -302,7 +270,11 @@ static int atmel_ecc_send_receive(struct i2c_client *client, struct atmel_ecc_cmd *cmd) { struct atmel_ecc_i2c_client_priv *i2c_priv = i2c_get_clientdata(client); + u8 buf[MAX_CMD_SIZE]; + u16 cmdcrc; + u8 cmdlen; int ret; + int i; mutex_lock(&i2c_priv->lock); @@ -312,7 +284,31 @@ static int atmel_ecc_send_receive(struct i2c_client *client, goto err; } - ret = i2c_master_send(client, (u8 *)cmd, cmd->count + WORD_ADDR_SIZE); + /* Marshal the command */ + cmdlen = 6 + cmd->datasz + CRC_SIZE; + buf[0] = cmd->word_addr; + /* This excludes the word address, includes CRC */ + buf[1] = cmdlen - 1; + buf[2] = cmd->opcode; + buf[3] = cmd->param1; + /* Enforce little-endian byte order */ + buf[4] = cmd->param2 & 0xff; + buf[5] = (cmd->param2 >> 8); + /* Copy over the data array */ + for (i = 0; i < cmd->datasz; i++) + buf[6+i] = cmd->data[i]; + /* + * CRC sum the command, do not include word addr or CRC. The + * bit order in the CRC16 algorithm inside the chip is reversed, + * so we need to swizzle the bits with bitrev16(). + */ + cmdcrc = bitrev16(crc16(0x0000, buf+1, cmdlen - 1 - CRC_SIZE)); + /* Enforce little-endian byte order */ + buf[6+i] = (cmdcrc & 0xff); + buf[6+i+1] = (cmdcrc >> 8); + + /* send the command */ + ret = i2c_master_send(client, buf, cmdlen); if (ret < 0) { dev_err(&client->dev, "command send failed\n"); goto err; diff --git a/drivers/crypto/atmel-ecc.h b/drivers/crypto/atmel-ecc.h index d941c4f3d28f..4458585ab588 100644 --- a/drivers/crypto/atmel-ecc.h +++ b/drivers/crypto/atmel-ecc.h @@ -41,29 +41,30 @@ CMD_OVERHEAD_SIZE) #define READ_RSP_SIZE (4 + CMD_OVERHEAD_SIZE) #define MAX_RSP_SIZE GENKEY_RSP_SIZE +#define MAX_CMD_SIZE (9 + MAX_RSP_SIZE) /** * atmel_ecc_cmd - structure used for communicating with the device. * @word_addr: indicates the function of the packet sent to the device. This * byte should have a value of COMMAND for normal operation. - * @count : number of bytes to be transferred to (or from) the device. * @opcode : the command code. * @param1 : the first parameter; always present. * @param2 : the second parameter; always present. + * @datasz : size of the data field * @data : optional remaining input data. Includes a 2-byte CRC. * @rxsize : size of the data received from i2c client. * @msecs : command execution time in milliseconds */ struct atmel_ecc_cmd { u8 word_addr; - u8 count; u8 opcode; u8 param1; u16 param2; + u8 datasz; u8 data[MAX_RSP_SIZE]; u8 msecs; u16 rxsize; -} __packed; +}; /* Status/Error codes */ #define STATUS_SIZE 0x04 @@ -120,14 +121,14 @@ static const struct { #define OPCODE_READ 0x02 /* Definitions for the READ Command */ -#define READ_COUNT 7 +#define READ_DATASZ 0 /* Definitions for the GenKey Command */ -#define GENKEY_COUNT 7 +#define GENKEY_DATASZ 0 #define GENKEY_MODE_PRIVATE 0x04 /* Definitions for the ECDH Command */ -#define ECDH_COUNT 71 +#define ECDH_DATASZ 64 #define ECDH_PREFIX_MODE 0x00 #endif /* __ATMEL_ECC_H__ */ From patchwork Thu Jun 28 13:07:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140445 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2166571ljj; Thu, 28 Jun 2018 06:08:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpccVh5pA1fkI++dvryFRgGpXtDeT/QBDB38USFouswiLgFH8/c2j+BQeyULA6sb11sSAygQ X-Received: by 2002:a65:6411:: with SMTP id a17-v6mr5148249pgv.287.1530191306097; Thu, 28 Jun 2018 06:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191306; cv=none; d=google.com; s=arc-20160816; b=V2ISB4mSKmvb0RaBqWaX7Pkk74WR1OHoZ1hYHdzVPQxUTJs/8xoTU5uko3S43adTe+ fxfdVCCQiiyNRIVF7USt3efJbNJDbCoz4L5g39S2EaMxlIMt2ZXT6o5zT1RP+jh+Wz8I 5aHLYpC9AKKJBAolsHfVN49kESOmF0AKO7MOszB1PAJIMtb1X8I/zR5z7hJSGzK3U1rc XPEAZwj3hRaBqkaHcZ7lPUkavbZrykRwBmQQOzCxmzXN49WQZ4yIKtlH1FNrgqhlkJbX vbjMwF/NSN5+F+pKkupAIi+ZB0a3Kfp+Srw7Z44sOXEUvacc/UEJzdWTgRf9RMeHccBF Q2Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=j7vnUMwkXU79GNOCdUCd+2LIZtCrXIjov+Vq8J0206g=; b=Nj2yjY4c76PPf+P0PWfRUOMaIBjw6ICUXAslDgYk+udD94jRexp827FSx/Ok7hXd9e OsaLED4wU0uDkvO9B6fQS+2Y5MRTjBzeov0tG+mpSm6yq75GPRJ97aKCJykkTbV1Lxv2 L0rRunMiJGRLQ3o/zyhFYwnMY25PwVr5A1K3PfurhXLPMLQDZG+qejgAgViLi1wX5lpk MZZ8BArtOwgGGnT03Vzucy03z2cMytejMY0kjunntFHZ7sVmn5Yx0WXlOTEvKHjX4WtU P8aCO9rGoU7m3l/zsRpZfhAGBsDqe48fgHkJc19EJ9AiW3XIaG+j15iCpf+Illr9w8le af6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kaYrVTpd; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p88-v6si6621399pfj.294.2018.06.28.06.08.25; Thu, 28 Jun 2018 06:08:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kaYrVTpd; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965127AbeF1NIX (ORCPT + 1 other); Thu, 28 Jun 2018 09:08:23 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41983 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934371AbeF1NHv (ORCPT ); Thu, 28 Jun 2018 09:07:51 -0400 Received: by mail-lj1-f195.google.com with SMTP id a17-v6so1345976ljd.8 for ; Thu, 28 Jun 2018 06:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=j7vnUMwkXU79GNOCdUCd+2LIZtCrXIjov+Vq8J0206g=; b=kaYrVTpd3hSLzVmDIY0wNSrQtOHcPtxEyAY+EMwoV6y5KoHKHYvngNJwHUkuS8CReR A7yAJofqRfKKX5uyq/0iu0D8ofn7pVLqvCFJO9QzbUWd0aUf0fB0vKfnX1OYlgcyIMER f1pmwWyo8uq9I7jSMaIoU5UNDX3GSl0E59ySI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j7vnUMwkXU79GNOCdUCd+2LIZtCrXIjov+Vq8J0206g=; b=iMAR0Ob+94VhHrqYdo2uaHHqlbzcQ2B8ljLqHeQCualOrbMB0EaMwICxJM1PqtK0WY DywaqiAeF7WWxX937Qbv7xuhDiHgt6rREYcO7Cm5glLWuVlWUiyUurMnQXXeq+Djr64r o330uqNx5n0yxHyYPU9GzOPeIQX3eXDiB1w6EE0Tw4+gSIiAg4iES7z9e9PlrdVXYANo vqZNbDD5tUfF3Iup81EvyyveERE4qlf1eUWyP8n1eRgXpqq02ossSo8PRWb1o74gpf5E FdE0r8fFQlyt/7KcBzQCz1H37fR5par3BsI7e2AvLk6wxZXCUgzYpBi1w7L71vCE+Vby 5IhA== X-Gm-Message-State: APt69E27tr4T70t8QJ+iAAizZhh7Yond32VK4rUwG7AqL/JaKg2YVfi4 lca0bAk6P78eU5ISAi/tMeqix70EhpI= X-Received: by 2002:a2e:86d5:: with SMTP id n21-v6mr3687615ljj.48.1530191269176; Thu, 28 Jun 2018 06:07:49 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:47 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 7/9 v2] crypto: atmel-ecc: Print out serial number Date: Thu, 28 Jun 2018 15:07:27 +0200 Message-Id: <20180628130729.17589-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This reads out the serial number of the crypto chip and prints it, also toss this into the entropy pool as it is device-unique data. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - kfree(cmd) was missed. Fix it with a goto construction. - Coding style fixes. --- drivers/crypto/atmel-ecc.c | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index f3322fae454e..659cb3cf37a9 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -610,6 +611,61 @@ static inline size_t atmel_ecc_wake_token_sz(u32 bus_clk_rate) return DIV_ROUND_UP(no_of_bits, 8); } +static int atmel_ecc_get_serial(struct i2c_client *client) +{ + struct atmel_ecc_cmd *cmd; + int ret; + int i; + u8 serial[9]; + + cmd = kmalloc(sizeof(*cmd), GFP_KERNEL); + if (!cmd) + return -ENOMEM; + + atmel_ecc_init_read_config_word(cmd, CONFIG_ZONE_SERIAL_0_3); + ret = atmel_ecc_send_receive(client, cmd); + if (ret) { + dev_err(&client->dev, + "failed to read serial byte 0-3\n"); + goto out_free_cmd; + } + for (i = 0; i < 4; i++) + serial[i] = cmd->data[RSP_DATA_IDX + i]; + + atmel_ecc_init_read_config_word(cmd, CONFIG_ZONE_SERIAL_4_7); + ret = atmel_ecc_send_receive(client, cmd); + if (ret) { + dev_err(&client->dev, + "failed to read serial byte 4-7\n"); + goto out_free_cmd; + } + for (i = 0; i < 4; i++) + serial[4 + i] = cmd->data[RSP_DATA_IDX + i]; + + + atmel_ecc_init_read_config_word(cmd, CONFIG_ZONE_SERIAL_8_I2CEN); + ret = atmel_ecc_send_receive(client, cmd); + if (ret) { + kfree(cmd); + dev_err(&client->dev, + "failed to read serial byte 8\n"); + goto out_free_cmd; + } + serial[8] = cmd->data[RSP_DATA_IDX]; + + /* This is device-unique data so it goes into the entropy pool */ + add_device_randomness(serial, sizeof(serial)); + + dev_info(&client->dev, + "serial number: %02x%02x%02x%02x%02x%02x%02x%02x%02x\n", + serial[0], serial[1], serial[2], serial[3], serial[4], + serial[5], serial[6], serial[7], serial[8]); + +out_free_cmd: + kfree(cmd); + return ret; +} + static int device_sanity_check(struct i2c_client *client) { struct atmel_ecc_cmd *cmd; @@ -692,6 +748,10 @@ static int atmel_ecc_probe(struct i2c_client *client, if (ret) return ret; + ret = atmel_ecc_get_serial(client); + if (ret) + return ret; + spin_lock(&driver_data.i2c_list_lock); list_add_tail(&i2c_priv->i2c_client_list_node, &driver_data.i2c_client_list); From patchwork Thu Jun 28 13:07:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140443 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2166165ljj; Thu, 28 Jun 2018 06:08:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI2K8zGZZ6a/LdqBm/ckjx3b0aRgYAPBmRDlCmhvIdu3KYulMnnldEMTh1a88z9gLNE9iGa X-Received: by 2002:a65:6101:: with SMTP id z1-v6mr8726759pgu.282.1530191287167; Thu, 28 Jun 2018 06:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191287; cv=none; d=google.com; s=arc-20160816; b=HSVHp3hR85tVZ7OhE14KSnBV10u//nHuVgqwm/TRYr/t78Kh5y8hLb6WKNi5nLrbLK W+halXeyA/p9ReJmFwS90+hk1OCnuMlI06T774cp4AfsD3jfzlt5c1IMsH9nSduN+ZaV yvsiN+wCCyFZst/lm7XdmNjukprk6N8wxYRDsMTmU/gFm2YP+I+TWV4XIj3CCAp8mqvK rq6ykgeFLFH/nI2SvwrZK6VkHtTeJ8uCh+8O2cVLrUrRlFC3WTH1CZCiQbe2L3Na2iDk xAfvCOTtXqP7r1gePyoFqpXdLLpMqkGQ8qJh1NY9/4zcYT/7onvdHlF0mJBbyyIP+vuF 5m6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=n8xdOgR9xdzvzWB90Up/sa7t8scWSSkMLPBwbUPPKZE=; b=vR1X0pYyefszfp13jn3uPJtWPFm53H/XB+rKvFZqhAPYRBzGuh4Jqf/gdLuVdg02dD WW5cOv3ZbPSJmHiInG9PCdI0flP3UpzCQMVLb7jh8U2vW+FMy/3bBA7F87MD5lDRaard JHctOtqRwYNknSTZbuIFydxAbdw+MpX47Z5HoBYpIpvKQE/QzClFVg07lRh6t3uDto3R IM/iO61b7FrNJMthgCZ27TRnlYO6Ltz+ayHuPdGSTa+E3EpN+bRfIT/I7zg2wDYrP6Fz MRdOfaGrTLsEiWKjpcj49qWfWJNUxL7lFwVKzmbeg9ThndVVNGMnsdQdQp0fyYQ1vyB8 //Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TwLf1yEw; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9-v6si6556676plo.206.2018.06.28.06.08.06; Thu, 28 Jun 2018 06:08:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TwLf1yEw; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965616AbeF1NIF (ORCPT + 1 other); Thu, 28 Jun 2018 09:08:05 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:33913 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964854AbeF1NHy (ORCPT ); Thu, 28 Jun 2018 09:07:54 -0400 Received: by mail-lj1-f193.google.com with SMTP id l12-v6so4471686lja.1 for ; Thu, 28 Jun 2018 06:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n8xdOgR9xdzvzWB90Up/sa7t8scWSSkMLPBwbUPPKZE=; b=TwLf1yEwE8WItY91FenBbkE7tDsAuc5gacWmkzlmFks/DBHZYFgi+Qt436frykLcYi bGR4hdIMDROjvs0fBnfZmtZvMFleA+3hiYhsMT4QaY1T2HIt429H1GNQ9mizXhneaNik S14pzUtYtl+7ej9diHviKQ0uNW7IhgGWiz+sQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n8xdOgR9xdzvzWB90Up/sa7t8scWSSkMLPBwbUPPKZE=; b=taUImzjxjZC8RCaRWUEq5P2iv08L3TbbDZx6+ORc0hdH/pGm0mHHdT67tEz5oKYGIX ZAUG3jup7snNoE5meaF/NbiYeTNtCeteksEfhypmQ0+uli8KN4a3odUdR0bcLpRseZBJ y0tZFW78m0XB3eqjyB5Hmf/7S0dTGH90ZPO65dMJrJorAXIIwVfzHS43IoJgXV0LvTwm +Q+RiP7IyYfivCh8I4iTH8fPZFZ/K8CZuEyc5BMBKeDvljaNz6hMQ9/dhsSwtkme3mJn savBVnApNcevArD1tbVB/yIhYE4bTa7hbemBIUpeJ6NlzhNUhBtS0dzAolOxUYEeT5Y9 uqzA== X-Gm-Message-State: APt69E34bm87Kgxl+6fW8J0646AVOEEMsM8iLIAD81nToh9Km1uVW8ZE j0cWOPz2cI9QK+KcqD6VsYyk7L6X33o= X-Received: by 2002:a2e:658d:: with SMTP id e13-v6mr7024179ljf.57.1530191271731; Thu, 28 Jun 2018 06:07:51 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:50 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 8/9 v2] crypto: atmel-ecc: Detail what is unlocked Date: Thu, 28 Jun 2018 15:07:28 +0200 Message-Id: <20180628130729.17589-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of just providing a broad error message about the chip being unlocked provide details on what is unlocked, one line per thing that can be locked: data and OTP and configuration are locked independently. Loose the overzealous defines. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebased --- drivers/crypto/atmel-ecc.c | 8 ++++++-- drivers/crypto/atmel-ecc.h | 2 -- 2 files changed, 6 insertions(+), 4 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 659cb3cf37a9..0dfea6eadc56 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -690,8 +690,12 @@ static int device_sanity_check(struct i2c_client *client) * Failure to lock these zones may permit modification of any secret * keys and may lead to other security problems. */ - if (cmd->data[LOCK_CONFIG_IDX] || cmd->data[LOCK_VALUE_IDX]) { - dev_err(&client->dev, "Configuration or Data and OTP zones are unlocked!\n"); + if (cmd->data[RSP_DATA_IDX+3] == 0x55) { + dev_err(&client->dev, "configuration zone is unlocked\n"); + ret = -ENOTSUPP; + } + if (cmd->data[RSP_DATA_IDX+2] == 0x55) { + dev_err(&client->dev, "data and OTP zones are unlocked\n"); ret = -ENOTSUPP; } diff --git a/drivers/crypto/atmel-ecc.h b/drivers/crypto/atmel-ecc.h index 4458585ab588..42b724256f93 100644 --- a/drivers/crypto/atmel-ecc.h +++ b/drivers/crypto/atmel-ecc.h @@ -97,8 +97,6 @@ static const struct { #define CONFIG_ZONE_SERIAL_8_I2CEN 0x03 #define CONFIG_ZONE_I2C_OTP 0x04 #define CONFIG_ZONE_FOOTER 0x15 -#define LOCK_VALUE_IDX (RSP_DATA_IDX + 2) -#define LOCK_CONFIG_IDX (RSP_DATA_IDX + 3) /* * Wake High delay to data communication (microseconds). SDA should be stable From patchwork Thu Jun 28 13:07:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 140442 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2166072ljj; Thu, 28 Jun 2018 06:08:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcdRNfruaBSjTAMHYtdnrfVODdvnM10lv/alIIavKhb6n1YWJmDBNH4En7G2Gbwuhcfy1o+ X-Received: by 2002:a65:4a49:: with SMTP id a9-v6mr7078153pgu.267.1530191282743; Thu, 28 Jun 2018 06:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530191282; cv=none; d=google.com; s=arc-20160816; b=lvZDek9i/c5L/EklKsL4QqgdNw49bwRxDQshZKwtWFHExFiYa3qnQITLeMbVPAXpvx cqWL30glaFX8E0crl+haqOIGm/LBzwUEZWgJi1ERPkKNB1GQWkS1IRcFiUH9jO+fxabO B++qxkyfKEAyq9br8szg3NAte6nkVz8j5Vgf5TJXdEFYG+sVHy96PqHrgKx4gRVsuShZ JO1Ps4oqqZBodTRhiq2dC/NsuRswbMh0NOoDDKqZE9Pf8V8ZvpCGT2uMq5nRpFdcDPHj xyOoZ6jiQHTFXLqthvSM2+XqqkNxE/qLEOnmQdn1vzGR1yqDPCII6e6gzcZJ2i2iKHNO yCow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=/znJ1zhTl++d3m411IYML5IV0OCEtg98TAu77s/1Qmk=; b=pdgqZ98TUpnbm7n2Hi1crky+RSnSB5kf5BublA+FJoBb4y/6BxnN3mmffOFb69BiXb P48/MgHzM99XxFWpJRGqlk0eSwnI4M8j7U1hYzYYMErYCyFghgO3t/g5zXNJfTYHUmvO NwKXZ9LUKzRyhHTfGxI+zawvLOa7fdCcMmy/h/13AOJ+u2j7Jbxrcaiw+P4bR+LHuDEt M1Q8/hZ6CcAuiTyPoX2x7x9haTTQyVF8F1vuWbLOaTS2oXfHEiDcwhmd+shgrd2f/SAy IFFiqXzhxx4YL44O33m3wTOg3jeIufnq1m9K/qn38YfyYfS+P+LAcIdlIzuDNPYodwc6 TvaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h3NLwFUg; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9-v6si6556676plo.206.2018.06.28.06.08.02; Thu, 28 Jun 2018 06:08:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h3NLwFUg; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965723AbeF1NH6 (ORCPT + 1 other); Thu, 28 Jun 2018 09:07:58 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:45179 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965616AbeF1NHz (ORCPT ); Thu, 28 Jun 2018 09:07:55 -0400 Received: by mail-lf0-f68.google.com with SMTP id m13-v6so4146110lfb.12 for ; Thu, 28 Jun 2018 06:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/znJ1zhTl++d3m411IYML5IV0OCEtg98TAu77s/1Qmk=; b=h3NLwFUg9b9cnLltKFS3ak6mq60aJI4A5zgK/ak3SLF57+VAtqo+R2KbZWkriWFOEK 59ZKTO26SaEl6sqlO3C57aikynuoyjfcE5KVQAhdThUNBvoYahz/UBXDoj4RBhtxbPw6 9t4aGG/c5A3CKgwpPblsmLSWnoJyKdGvtDrJk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/znJ1zhTl++d3m411IYML5IV0OCEtg98TAu77s/1Qmk=; b=bE3aqjk919hbKSUutEw8dD9pgnWKczHXjzT9NEO+iqBzQLl2AV1Yb5oEmfuvKIPrsI Oto/H/PYfwDtwgmaNd/ruRwnoCQIOhH7DaonDg+CSTSnREaMHAQrToGKwnb25m8Ydr6+ +eZT3zX2aGVulVjQC3c3uWuxFKwbNoJ/3k0uJUQ1c8mTPV6rZuKS4xsND6MbnKonC4vm H9KuNCJynbjM2Wudha01SohkWJ0cRJLos9BUMh1KNSgAv+kM8iNVlGSbGPYEMLJ6SgfP udPJ0oZKVp8BGbJPxLPHIeWDgzcoWdsMai1Op0rMcFiLY2pHQ7Qbu6NFRh3UtFKLnKOL heFg== X-Gm-Message-State: APt69E0tNdzwnRQG6uD+axFiet2Nf4i5ZJU3UQFkYgzDCd3xiv+Y9+wE 4VeypH5v3jM3pTEcR+rGlh6LXByO2oM= X-Received: by 2002:a19:6a0f:: with SMTP id u15-v6mr7321445lfu.81.1530191274170; Thu, 28 Jun 2018 06:07:54 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm1314649lfl.53.2018.06.28.06.07.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 06:07:52 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 9/9 v2] crypto: atmel-ecc: Break out lock check helper Date: Thu, 28 Jun 2018 15:07:29 +0200 Message-Id: <20180628130729.17589-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180628130729.17589-1-linus.walleij@linaro.org> References: <20180628130729.17589-1-linus.walleij@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This breaks out a lock status checker to be used with further refactorings. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebased --- drivers/crypto/atmel-ecc.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 0dfea6eadc56..549ec7190287 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -666,7 +666,9 @@ static int atmel_ecc_get_serial(struct i2c_client *client) return ret; } -static int device_sanity_check(struct i2c_client *client) +static int atmel_ecc_get_lock_status(struct i2c_client *client, + bool *config_is_locked, + bool *otp_data_is_locked) { struct atmel_ecc_cmd *cmd; int ret; @@ -680,21 +682,49 @@ static int device_sanity_check(struct i2c_client *client) ret = atmel_ecc_send_receive(client, cmd); if (ret) { dev_err(&client->dev, - "failed to send ECC init command\n"); + "failed to send config read command\n"); goto free_cmd; } + /* According to datasheet anything else than 0x55 means "locked" */ + if (cmd->data[RSP_DATA_IDX+3] == 0x55) + *config_is_locked = false; + else + *config_is_locked = true; + + if (cmd->data[RSP_DATA_IDX+2] == 0x55) + *otp_data_is_locked = false; + else + *otp_data_is_locked = true; + +free_cmd: + kfree(cmd); + return ret; +} + +static int device_sanity_check(struct i2c_client *client) +{ + struct atmel_ecc_cmd *cmd; + bool config_locked; + bool otp_data_locked; + int ret; + /* * It is vital that the Configuration, Data and OTP zones be locked * prior to release into the field of the system containing the device. * Failure to lock these zones may permit modification of any secret * keys and may lead to other security problems. */ - if (cmd->data[RSP_DATA_IDX+3] == 0x55) { + ret = atmel_ecc_get_lock_status(client, &config_locked, + &otp_data_locked); + if (ret) + return ret; + + if (!config_locked) { dev_err(&client->dev, "configuration zone is unlocked\n"); ret = -ENOTSUPP; } - if (cmd->data[RSP_DATA_IDX+2] == 0x55) { + if (!otp_data_locked) { dev_err(&client->dev, "data and OTP zones are unlocked\n"); ret = -ENOTSUPP; }