From patchwork Tue Jun 5 13:49:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137734 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp985347lji; Tue, 5 Jun 2018 06:50:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLBG6FVD7u1j9FijsfOJ6MuGuGEPyHOTbdq1J5p26yJadhy9p03lM/B+2XDuCKBSuoNWkmt X-Received: by 2002:a62:e097:: with SMTP id d23-v6mr25660555pfm.81.1528206600962; Tue, 05 Jun 2018 06:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206600; cv=none; d=google.com; s=arc-20160816; b=HromZOotc4ZsylIX7oGGmkEyFuqxS+dyHjfhFsIkrQaNNYNX8LEwSJ/XNJbIQjpOBq MQ+xCEv8+3LDI+FXLnZbsAglI3TbOH5OaZFzQErfTm3DykDGSr+LpmLyJj8CDD253Y4L TbajPZ9t4SznABxPZ3/ZJUOCDqcErSMhK628yPCcierGMdYaVKv2raO8nHShRKNyNU/2 dBrc5Bvpkz3TZTnstaU2mCWT4RUCXFz3CB1bBSq2BSLxnVS++cWhVLx87FsJJnwgnFWa OnjCPFdUBoD2nCPayecZRCaStFpH50nUuPw7F23MGTMdm2i3+Q3Jn/JSZvA3mqmIAmw0 Wu0Q== 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=qUsskWNEl03dTW5sY9d6TE6ocjPdHQsThAov8w4VKAw=; b=aTkfWBzzV2HDqNnsjaWJfIlBPcFjq3AmHlRGjV35FBdtTH+OJ8b9iZZ3f124RT+6Pv dBT1LDBS+VELHgaQwua65MYBX1dicA0wIVADZIFU4iYcMQAMV02cf4dLwOlPTWG3JYVU FrtvWgzO/FLeUhZ4/Jif5k07OB0ze3OGRaBs4yJHMT8A+oLirsfmVlMO0cqMYnW4fEPW 5tKsk2ngrT0NQypMUc6sbgCAQC793RxR6qXv3UfzVBcBvo9EagmfD43KsF2xbDGBwXR4 CfWWlHevHU9x+rs21Iy7u3e/jmIEo73osOiMZ3m3mHOiiL64Ud/0a8feCrbYdrjx0DES xN3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EQw5Mi3b; 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 a3-v6si47110509plc.574.2018.06.05.06.50.00; Tue, 05 Jun 2018 06:50:00 -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=EQw5Mi3b; 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 S1751854AbeFENuA (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:00 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:39790 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeFENt7 (ORCPT ); Tue, 5 Jun 2018 09:49:59 -0400 Received: by mail-lf0-f67.google.com with SMTP id t134-v6so3699002lff.6 for ; Tue, 05 Jun 2018 06:49:58 -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=qUsskWNEl03dTW5sY9d6TE6ocjPdHQsThAov8w4VKAw=; b=EQw5Mi3brrnH3tHAqiz+A28NDNs0UbSPzdIX6fIl36ylbT3mNWzcnkrBnZGd4vLOty sz7SnmQOm5gmdLtxp3GJ9aIrXsFo9DZivDYJfRRhQ+ldf025LGPFVVR9vvJpqkv4kvoS EYAj4rD6CIAdNsm4hzFedUtIGzZpbz3NveN88= 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=qUsskWNEl03dTW5sY9d6TE6ocjPdHQsThAov8w4VKAw=; b=i/m/Lec9Ud6l/rVOxcIvEZStVWwZvtoSjWbgnDVhPbqJBJpq02mlRak0FE5QiYkcwM yIMGfyE9mNFo7aL4bw/+axxlXnjWAtTBFKRwNGEIemZTrDNPJBoxxZt5zbTqRiuU7f4E y8DsLtZG2g9jNh8Yj6jBxRLl+GJnCvTbH2Zcsn05qTCyaRVv41chrmNav5aUZ88oC2me hNjGsNAnwFCW+tbNjzrzlbyHJ0QaGetttyilDMvokggR1bceSbVy3weJpiLM5BCIv8GW zCyrxhjWar+i9ZetOpgISE25orko2Z1aWbO3vslGLCYhiS6kjCnhaNmGBnZG9DGB8cNr LiVA== X-Gm-Message-State: APt69E2W5WYT0e3Tpe5BpQQhv2cS/Jx0VdtBlnVPtWkbKoUfO0LQhwHW VQao4XsJ81bxPqXuh6d+l4IddMTWOu0= X-Received: by 2002:a19:dd0b:: with SMTP id u11-v6mr1799452lfg.100.1528206597712; Tue, 05 Jun 2018 06:49:57 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.49.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:49:56 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 1/9] crypto: atmel-ecc: Make available for other platforms Date: Tue, 5 Jun 2018 15:49:42 +0200 Message-Id: <20180605134950.6605-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. Signed-off-by: Linus Walleij --- drivers/crypto/Kconfig | 1 - 1 file changed, 1 deletion(-) -- 2.17.0 Reviewed-by: Tudor Ambarus diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index d1ea1a07cecb..9e33f2de8dae 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -522,7 +522,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 Tue Jun 5 13:49:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137735 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp985925lji; Tue, 5 Jun 2018 06:50:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKSGe0S7wkbvAxn4x3sokw9vOA4ZOxPPlpTw2s8RIa19yfECmKjqC3zRiYWBKJO4O+M/P7D X-Received: by 2002:a65:6250:: with SMTP id q16-v6mr21330537pgv.113.1528206630226; Tue, 05 Jun 2018 06:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206630; cv=none; d=google.com; s=arc-20160816; b=AZxtsXpKnoLQYJGBIdoByJ6NATG2kXOFlTZ3TIQ3q9Ce56hSNEQG9MoL2hg7tT8tWz za8dZdqAv15VqA5eVd8RIooTFPusAObuLt8Bhy6sg4eRpiCOYWHMBLK8NAxAEUe+dpN0 jQ+JAPTpP2F9CTylHevvQp3qLeW4fP92b9R47tgp3OccmVj57oQlFlI2MezTG4NLu142 zPk+BbO93vrNlMFBUwOyP139CgvQl/mmhnEVSEHu7Kcx1tLqVjzodhYMVCh9YgJdDbxe UAzzLUk4hsOPRPif0B5198Zb14KLuVmg6RthDI+tv9O3ZfVyIp3mw3ZZZdMrJHpe3OXg HoFA== 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=4IBVmNkBN5dxSi2IItg5ld3vNZ4nRlduJskzBlx/EFc=; b=JMsvu+AdMx0i2wTTlKrI8jTYwHym8SN18FA7I0udr3KqZe9LUC+mS/MQxB0OZLRxsH VqhdnLTojhBnsXS5COIDDIsUUAR2sDH+4M3FkWQ/OJLyFA77T/YAdip+3JFycpeBEPhV UBlrFE5vdc/w+nD0K6+xCsrYglqdls7FPLYNBnEOz0mrVpfKf5LSI9QzRS/e6VGdkgck Y8wtKVpwWSd+BFm1Be3yZgrKLTRKBBewS47vWlQ/4ID8+xSAlurTeZCTL2jg9ow63Nnp mNajhH07I5WF8ew6GMfSSr+5WQoj24iJCpdycxh6quzUCXW67uYZTnb7foivEUW9XrFI axgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hVBggSAM; 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 j78-v6si24186154pfe.187.2018.06.05.06.50.27; Tue, 05 Jun 2018 06:50:30 -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=hVBggSAM; 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 S1751940AbeFENuZ (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:25 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:37954 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeFENuX (ORCPT ); Tue, 5 Jun 2018 09:50:23 -0400 Received: by mail-lf0-f67.google.com with SMTP id i83-v6so3710091lfh.5 for ; Tue, 05 Jun 2018 06:50:23 -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=4IBVmNkBN5dxSi2IItg5ld3vNZ4nRlduJskzBlx/EFc=; b=hVBggSAM6HvYGK7AoB7lTCd4EqQ/lzEZC47sNHhzKU7eSSzuiOYvtceaBq+HDEzNy/ WZ1M9UHQ1+EpZwEmgLJfDDuDAztFk1+yzIJXg4sgez/+zkF2BH95jdcjXZ+Xwl9/bbK7 UC7OUv7e7bY1jBiusV1zj8vpIhN/C7jZDzC6k= 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=4IBVmNkBN5dxSi2IItg5ld3vNZ4nRlduJskzBlx/EFc=; b=pd+Jj6kGBPsWJkvtNSbU/q9USgLt1zG6O5wuLVCQNXVoTYpxF55F22G/od0CAPp0Qt d7GG3AJDiVH85Xgorg9jNP3O8O0zaFKj+ieQAyV/GPJ/93aNP6idRYJ1WGXQn3BhAtAD u5ciU0Q3pIL/mGXXdsw/XqZGvLHWxh+VO3TSwKQavR21d6L81w5GaXKpmsgvPcJANraW z/++KC9hx6+xoG43HwM4uWNLJUWTg+nkhupSsGRLdKuFGaXhz1cean9Fg4rqRwhHA9ZU D4EhW3aDCYMqU8t60ryHNXRkz3ugzl1c5wLXk1eEsdiRTk57w3kXwWPgcuBaKKhyz4J/ uFbg== X-Gm-Message-State: APt69E3c6M3cAES7Z74qxDmWYxEH8WjL3Ylz9PsrkqZX+hQQeZDYWuKZ GnFvhXFq3z2MLzZA1K5oaErcuRFX9Ms= X-Received: by 2002:a19:ca0b:: with SMTP id a11-v6mr1674250lfg.69.1528206621778; Tue, 05 Jun 2018 06:50:21 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:20 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 2/9] crypto: atmel-ecc: Silently ignore missing clock frequency Date: Tue, 5 Jun 2018 15:49:43 +0200 Message-Id: <20180605134950.6605-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 silently if no clock frequency can be found, assuming all is safe. Signed-off-by: Linus Walleij --- drivers/crypto/atmel-ecc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index e66f18a0ddd0..145ab3a39a56 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -657,14 +657,13 @@ static int atmel_ecc_probe(struct i2c_client *client, return -ENODEV; } + /* + * Silently assume all is fine if there is no + * "clock-frequency" property. + */ 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 && (bus_clk_rate > 1000000L)) { dev_err(dev, "%d exceeds maximum supported clock frequency (1MHz)\n", bus_clk_rate); return -EINVAL; From patchwork Tue Jun 5 13:49:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137736 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp985931lji; Tue, 5 Jun 2018 06:50:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJG0WGdb8CTxR6BiBNLckDJ+qSGDOwlpZlZzyJLqUFTcbpBlJl1/KjMn9VJkny1HsTxaXqF X-Received: by 2002:a17:902:8a82:: with SMTP id p2-v6mr26472982plo.244.1528206630495; Tue, 05 Jun 2018 06:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206630; cv=none; d=google.com; s=arc-20160816; b=E1FoRuvajIK7QJuCvgOCD7z0dcjVGE56VcuHS//TeP7Q7+upiP2UDeuNoTlS6GUk8d /TN5a32ELvW2lx290e4OGbByK40wzIaStp9xhiPTog/nzA4YuMu0lHvIWOWaP0+Kvvea qE6ipoSw8/6U+/AoVpOU2rIyzLxBg9hCeEZYv8BL1kZDoXUR3t5HPIyJIr89Zl4gz/fz mfDEVD9plWHYpc0sCaMUQACY1C3Bg4WolWTCe2Ya9lXSriVezPgoy3X5zZwDj0EqkwG6 tq6D89Uq3HqfJ8yHCGUIrj4bKcpYaGqeMpCrg5U6Sn7EpoM5WOnvHWto7nQew/uPCzre Z7SA== 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=9F6DqNre3XjVSlouDy8KycNnYII/fFaM7FsoPndHocA=; b=esvsd+gZbRoXvYMHYxefwDVVKCCHXphfmFN/ruXcdPiROAk4D18SL6xpKv81wBLgmb AB83hoNYqETK79YNrpMtVGszSuqvvUgMncFqpiisB/1sJoiYItAyARkIm4csmxnBnkhg BGrIlnx833aGOCsafXw3NJTq+eX9X4sM5dHVlWFqJZne+nhTPRIWjZelxYs43J1IQKkc QzpMkvHRH3JzWiHWi7CeutV1iCjr4mrhGRUNW58evg1/cJFcUnpKIeXuxMT+QgxWEo8s bjz7vYordeD5MJTUu4a5PeNik19U+CrSJVCwbBV4EokA5S74xXzX86e1rwiZV73k4Tsc 0EEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FwF3A1d5; 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 j78-v6si24186154pfe.187.2018.06.05.06.50.30; Tue, 05 Jun 2018 06:50:30 -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=FwF3A1d5; 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 S1751941AbeFENu2 (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:28 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:41545 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeFENu1 (ORCPT ); Tue, 5 Jun 2018 09:50:27 -0400 Received: by mail-lf0-f65.google.com with SMTP id d24-v6so3694948lfa.8 for ; Tue, 05 Jun 2018 06:50:26 -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=9F6DqNre3XjVSlouDy8KycNnYII/fFaM7FsoPndHocA=; b=FwF3A1d5LF+7Ecn5N4e0H4p7WtQk7XdkIKYIM/f6vYh0HggUCMNVjtNF71ltvRiuXf WanF8u8gv9XMYIUMxEhB7bnCJGJ4b3VUgEFO3zo+JHhVyWgrRPaECSPNw8C8tNywnRzM RWx1rzTgCrqmfiCybxvDbOXR38e3IFajgJgBg= 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=9F6DqNre3XjVSlouDy8KycNnYII/fFaM7FsoPndHocA=; b=bm4Xp2VToRxW6RHYqDkKABstQf4QofWrk1GGAtFeOr658TrjNedt5s83QGcMcO7BDB RyXaNEfEAlf0IaKCOJnI8/xfswlfuxEgh/rMrkQtGVUmD5TE5KuZrNplhCBdeEuOwnWw 0oP+rhzBFQM4qbrXH9VoYSufyB6bVc50gwyqZ+wINDRnRUUNOU8DiISWNc+rtiBDRIML FEsk2EwJ7LZsaYv3hl1SYX/xuYQ8bqy7vnj/AM+zoqv8lw/eBiE5/q2XTLw2pA4cxE0t dlp3yI25bKH0MVO2Jtb18io7hMYYsqvaRktVpnxFnFk++/kRMdHMAai2x8coESCSGplA XB5A== X-Gm-Message-State: APt69E1hpbBqvNRIx7EedR+8VEd/ZOTKoGfucNjEzW/P3ForLYW3c0OC mEM3jdbIm/GJeXFqeJd6r1TztFgdBrI= X-Received: by 2002:a2e:82ce:: with SMTP id n14-v6mr6061711ljh.34.1528206625598; Tue, 05 Jun 2018 06:50:25 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:24 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 3/9] crypto: atmel-ecc: More helpful error messages Date: Tue, 5 Jun 2018 15:49:44 +0200 Message-Id: <20180605134950.6605-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 --- drivers/crypto/atmel-ecc.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 145ab3a39a56..214b0572bf8b 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -310,29 +310,41 @@ 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); + ret = atmel_ecc_status(&client->dev, cmd->data); + if (ret < 0) + dev_err(&client->dev, "ECC status parse failed\n"); + + return ret; err: mutex_unlock(&i2c_priv->lock); return ret; @@ -624,8 +636,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 Tue Jun 5 13:49:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137737 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp985989lji; Tue, 5 Jun 2018 06:50:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI0PvHYo2+XbmllVHAG9Kpim8GC7pnMroYebUcWewS8qSpZVHU0CyZDby5ZEsA9ug70lh/3 X-Received: by 2002:a17:902:14b:: with SMTP id 69-v6mr26975407plb.184.1528206634091; Tue, 05 Jun 2018 06:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206634; cv=none; d=google.com; s=arc-20160816; b=BAY+n9BF6k12T8oL5SK7RHAe1ZKCXAmdyOwYkN5WhkZasOoaJEfd16meDsWQaQJz5a alI4c+eiMfxZAWOBLd68tQlLY+ao2GN+yiQSihpzEYjTltggZsoZSLwNV4TYmW+gX6mM xlhRGks75GJYu9kCOJkK7F0MXQbYmXglxfLlUWbX0iQAVv1L9AgRsnWYljrFrup8Op4F K5giPn4ijf5FjHKy08iadegBQ048Dct3EBiio4raPzsnNkYCKOyTPK6raKJdWdikAHHW gwjweaiCLQYzkCr/L0NtPa1c6NmYsCMKTEcM+SmugU7Wy0WDmiLTxq4yfBevu+zw3bxe T13g== 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=CySNetqZe5E0/m66thWs0yXNuIrAKFFK6a4sW9fsogQ=; b=ozJXsUhqq5n+UFn6wZNcP6NPTBG0E5vzKCPBeZ/1D+hYvOvK6KLHCnuQpwvX4Ysi7o ge6Jz2N09V1i5nKGDK5OwBDZR3vj4YzVzssn+XcSH3kDW6bvi2lcjQNtg/SECfg1Z/eZ rSJEy8WbvYTSQkSAbdf7pfDViHmiOOiQjvmRW8RwDLUH2qjqrjGXbkn8Oxhao09KS8to 46tHTSlq4zdV9OfnC9jvI/4xEgliDlO3bnQbmO3/H+kVtfLRwJRI5eagHGywbnFyqHhk WX/V3Wto7Syibc2v4z8tTkDYsnBCxzpylgNOwc4BWzTKXsznEMPgRw5XNkDRuPFBxVru g89A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BvpEA5t1; 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 j78-v6si24186154pfe.187.2018.06.05.06.50.33; Tue, 05 Jun 2018 06:50:34 -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=BvpEA5t1; 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 S1751844AbeFENub (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:31 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:46145 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeFENua (ORCPT ); Tue, 5 Jun 2018 09:50:30 -0400 Received: by mail-lf0-f67.google.com with SMTP id j13-v6so3684179lfb.13 for ; Tue, 05 Jun 2018 06:50:29 -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=CySNetqZe5E0/m66thWs0yXNuIrAKFFK6a4sW9fsogQ=; b=BvpEA5t1j1Gf7Ac3KrKFtdHNGSMl2u1N7UoZ0f4Pn/gkoAXaG6qE6Tw0VsEhBcr67F L/waVuzG/7yGdnj7aI7Ack08Wnt48P6P2gFJK5zroXMXEBsfWe30mQjxHhRcoqkhOgUa FXtCzD/UL0Mp53HwTCK2qXL8im+ar5GGwviiU= 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=CySNetqZe5E0/m66thWs0yXNuIrAKFFK6a4sW9fsogQ=; b=Fm0ELQl36dmf0ie+qmfLE6xvGwXX2b96zt0Ej5PqL+JgLKAHUgKmW3zx99EoWsYbwV l5xsiqadCbTwjWh1LE/oLnVn39+fWfTlw4W7Fy9PoEMZzhatnDgzj0Dwj/XwYlnjfoqY zRl51jTXJTJgdr6xjPdaRr70/2i2d0c1L5GeWosd92o8dXDSlZxob7CiZneysIco5sUZ KuOesS20g7Q5q8QjFulWfGgla1+ClP1OtehCDgWqw40g8iNKNU3nkfNg7GSwDB/cK5tM qb19qPx2ulJ0TjC8MLaxnbZm4Y0gBr8C8M/nGZPTuoDrQO2QrFSFVArDw5v89WnYIKAS +wtg== X-Gm-Message-State: APt69E1rGRP2wQXgUVB6JccyWOkyMO95U/t2u4uimzGn0EcuT39DZ/8A oBG3w+1B+ukfK1e10OYbCC+0LxcR8zo= X-Received: by 2002:a2e:4dcc:: with SMTP id c73-v6mr14368252ljd.135.1528206628571; Tue, 05 Jun 2018 06:50:28 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:27 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 4/9] crypto: atmel-ecc: Provide config zone defines Date: Tue, 5 Jun 2018 15:49:45 +0200 Message-Id: <20180605134950.6605-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 --- drivers/crypto/atmel-ecc.c | 2 +- drivers/crypto/atmel-ecc.h | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 214b0572bf8b..f1f422385a91 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..6d586a3e443d 100644 --- a/drivers/crypto/atmel-ecc.h +++ b/drivers/crypto/atmel-ecc.h @@ -89,8 +89,29 @@ 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_SLOT_0_1 0x05 +#define CONFIG_ZONE_SLOT_2_3 0x06 +#define CONFIG_ZONE_SLOT_4_5 0x07 +#define CONFIG_ZONE_SLOT_6_7 0x08 +#define CONFIG_ZONE_SLOT_8_9 0x09 +#define CONFIG_ZONE_SLOT_10_11 0x0a +#define CONFIG_ZONE_SLOT_12_13 0x0b +#define CONFIG_ZONE_SLOT_14_15 0x0c +#define CONFIG_ZONE_FLAG_0_1 0x0d +#define CONFIG_ZONE_FLAG_2_3 0x0e +#define CONFIG_ZONE_FLAG_4_5 0x0f +#define CONFIG_ZONE_FLAG_6_7 0x10 +#define CONFIG_ZONE_LKU_0_1 0x11 +#define CONFIG_ZONE_LKU_2_3 0x12 +#define CONFIG_ZONE_LKU_4_5 0x13 +#define CONFIG_ZONE_LKU_6_7 0x14 +#define CONFIG_ZONE_FOOTER 0x15 #define LOCK_VALUE_IDX (RSP_DATA_IDX + 2) #define LOCK_CONFIG_IDX (RSP_DATA_IDX + 3) From patchwork Tue Jun 5 13:49:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137738 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp986011lji; Tue, 5 Jun 2018 06:50:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIk4apgyYyHBfV2IZOzd8vNVHNs5aXHUELXrF68ilx8Xc3yD83kx69sxxWaseYqOwBIxnZ5 X-Received: by 2002:a63:6dc5:: with SMTP id i188-v6mr16037112pgc.391.1528206635280; Tue, 05 Jun 2018 06:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206635; cv=none; d=google.com; s=arc-20160816; b=qsfQjqmxhpZEmRvw1YpKheuCO/E5JRNyXu40WEfw29jmrhO3HMyq+5VfCBi928lUHp QrCmrKfuSMcGpWz0vCpYvSEhvtjsSMVpVUe7eAk5E9t6p3s6728zcnN/iSE6IMJ3F8vi tAWdG/KacbFQ+v2Rfrr7lF1eLCb1TshIIEFe2f/1mpyPD9H/qWoYDTe4N2JlIthZlhzo +c/99WRc20xTv9ceDWJ8yk+gA5tlQ2D0y4bYpWh5r6D0uz0ss94ZPWzHVTjlPtLZj3C8 fI9rahf/Sgyn3P9dKWdXmP9taBbqwcUvRjGmZ8ke7628J1CdFYMQDaXilPvmyn3bSMkv KJRA== 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=Rh3sCnI3vLegjKnR3N/27pCwp0NKmzxY+Xf21CxeW5I=; b=Fp/UuQmergk7munvQ6WL2zC9VjEtv76TbIzQecmtLxxKiaShkPm5rY5jEHgADCK8PS Del+eWu93kT6Cg9/0MNayZ52PIY/et0nQRU2in/vTcHS6ZI7r90Ephiii2QuHkfOGOEL ETi18kUwi0DjJ6aT0k6eKaOg6JwIkERXcuP6UwpUBTsw4FYHXYFh1bvEcZKVYSmAkFLP e2pczqb7GPPzRDIQeFZn6vVBr5OSxE0jLWLowEvHAdH+z/zX2u18HSZNKGzWkLVvVVgY 775rAvjRdPN3lIturbkfkz9JZT9NospwjXs0GmHmnxVzsr3jLBjEU92O5SHDqo7VLH9c zYsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HyTFZSlk; 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 j78-v6si24186154pfe.187.2018.06.05.06.50.35; Tue, 05 Jun 2018 06:50:35 -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=HyTFZSlk; 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 S1751942AbeFENue (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:34 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:44944 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeFENuc (ORCPT ); Tue, 5 Jun 2018 09:50:32 -0400 Received: by mail-lf0-f66.google.com with SMTP id 36-v6so3678248lfr.11 for ; Tue, 05 Jun 2018 06:50:32 -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=Rh3sCnI3vLegjKnR3N/27pCwp0NKmzxY+Xf21CxeW5I=; b=HyTFZSlk+sFDyh2U5pdQcTW4qs+oJrD1DBsTpbQZ9zc5BnFUHZuD8WgDuxN+o80++2 tMmVoNnLC8UC9WURRfptlhGuwdKiLYCqT+QbgukLSEYSG68sZirHyS3FmpTARxPC87I+ Y1zvnG52PRaGGTjCW7V1lKsRvh/Edhf5B5YBg= 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=Rh3sCnI3vLegjKnR3N/27pCwp0NKmzxY+Xf21CxeW5I=; b=q6xoqUEnp4cfVKXO6nkQtn+zVdDhmG+PHI2lE5GPiS9T/rf1Raupf8sEIIyDRekVe/ Hwje8HmPeB8Ecs/5UfoWHtMrt8tdpNzmwuTI30LymVgkasTovUbDC4zc4v/v9h6tvHkH ZP0GK3llFlYXYwcUERKkgpJO6negP3k5RiBg1MuNrMd9x2Pr9FooQJ0z848vw/9+uRgs KrNdG+l6J0/3ohaX1eQq7TEgUeSylkPN7DV3oYJi1Mhh1V3fsoGuBM9EHoQtPOGjMFCl dxUYyE4UV0B2UiNtkgqOiVeXD4JkwBdsHOVic1tNxSIuiDwGz5mDGoXPXvqlgt+3nCYl 7Vlw== X-Gm-Message-State: APt69E3R9a6BLjA2wGGv4ARkSxtg/AeLQbUJ6WC2RaouvcVPrOm7IZQ3 ayIz0kGfV0b4I97a0BJwN1qNgrT8460= X-Received: by 2002:a19:5d54:: with SMTP id p20-v6mr1789606lfj.21.1528206631352; Tue, 05 Jun 2018 06:50:31 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:30 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 5/9] crypto: atmel-ecc: Create a config word reader Date: Tue, 5 Jun 2018 15:49:46 +0200 Message-Id: <20180605134950.6605-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 --- 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 f1f422385a91..d89b69d228ac 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); @@ -633,7 +630,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 Tue Jun 5 13:49:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137739 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp986079lji; Tue, 5 Jun 2018 06:50:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJMGQDQuwT+um5JN8D757KmdPw4hVnhk7owx7G99n/ct5ivWwb88RWBHCKdW2nz+o7/sb0p X-Received: by 2002:a62:1656:: with SMTP id 83-v6mr25635493pfw.61.1528206637859; Tue, 05 Jun 2018 06:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206637; cv=none; d=google.com; s=arc-20160816; b=pr7tHwDqyit61j7C0NIxhi05229//VJd+I8ajpuFj85yaFmSPSWiTIlUsep+x8Z1nG Nasmq9rzeNHwt4g5iwCgtb3JPvv/DniU3JnmpHBK4L2n4g4UWKDeQkU1Gx8GclQLx77M astdj9KkDY9SUfk96oWSiwYRjk1Ix13bQRu/QS6hEOtDmy9tDqWXZTG2B4pOhHEeCqG3 BzFB4KpcH3IdjepfaxdiCQYGi7bKrxVe0g6mz4oGRB94nwtrOBWZVNrZQZh4j/WCPiI7 KPit53zvk2+yfAMFnVHa35xwpVAhRZcsdsrLEcrA9rGYrqffwSXR73WXUTc0R8uUr8D0 E7Og== 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=D6YbNO6YBqKM4Fb7yN5okUZ/2TOZtySAcL4Qfb/3wks=; b=BQM9Nbgym2NaZV6qQeT5ZAoPPqahqfX7ftQzNIw5zpvNWOgOsuHUmIv9b+me9r+Nju cblEvXy4roKbJN4lTrqd8RvpVMpsev+dLTZiRs3sod55f7uczWDMup0HSLjq02hSxPlP zdxpfWtWdCY+A4EKKtiIm2pE46CBXDPqta8CJ+3h3+BQkdhiZSQ3JptKWqO70zUfk+lJ KpFMblHDExAsZVNFnx9Jimin5sn9XJZHrYGwVysoFQ19IlFDJn2LLnlKNSAXAYwINE2t WMnLXhKSQYIlS67N0wbolNahTxXpQPq2CaKy5Yz+QAs4A2GlWJg+zZ+Js5kGuUtPdAQv 27hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e+2A41rH; 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 j78-v6si24186154pfe.187.2018.06.05.06.50.37; Tue, 05 Jun 2018 06:50: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=e+2A41rH; 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 S1751945AbeFENug (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:36 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:37986 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751948AbeFENuf (ORCPT ); Tue, 5 Jun 2018 09:50:35 -0400 Received: by mail-lf0-f65.google.com with SMTP id i83-v6so3711230lfh.5 for ; Tue, 05 Jun 2018 06:50: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:in-reply-to:references; bh=D6YbNO6YBqKM4Fb7yN5okUZ/2TOZtySAcL4Qfb/3wks=; b=e+2A41rHl0l2ZLdhF3/MquRYXDCirfZknYN289DvPUvDjgEW+joQX9XPJDyzzEDlIM jvuI2DWy3G3wFbtiUxLzzwwltO9lOVjPyjt6mXJ6UoFMFS9T3TtMHSmeHFimP103hf6y 1k154i1ob8l424EaeMA6gwmmk9uh/LMsn/WyE= 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=D6YbNO6YBqKM4Fb7yN5okUZ/2TOZtySAcL4Qfb/3wks=; b=Ziw2Y3eXn+p7NL6gy9bJoQU7weu3/drV+EEK9T4kUeO0065G5wAKnfH2790xkvk4oJ FN+m3sZc7W4aT9rVrpZl3GcbInUpqTyc7uC1r13a7+DBfM39yUFHfvRmMlz/o0AqX13R Hgk+2jtau9mVvrIIAOZeBYrnDf1iZCCUEdUF6SQkVMuKY3c/9SFznJ5VCT6qnF/RbAFu pFkix8RdHOlmRTgp9my+Xo8VaNnoFrAotLK57VjO+FYcIoTUDjQ5jU06QKhK4WZaU+9g ZDJIcq3Rbopk3XNt2uL05rpxSnBg1A9ZfZESaHmfd8G54f3RctF+prIfVVZyG8oKWuy6 Woxg== X-Gm-Message-State: APt69E1gtFYPypE4n/m57kUJ7mOA/c8jxZs6nAxcJGLdiPbz4iU7xJjC sPnQ/YlD2BIvkn4x8FakCr1290TKQFM= X-Received: by 2002:a2e:9c08:: with SMTP id s8-v6mr600489lji.97.1528206634080; Tue, 05 Jun 2018 06:50:34 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:32 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 6/9] crypto: atmel-ecc: Marshal the command while sending Date: Tue, 5 Jun 2018 15:49:47 +0200 Message-Id: <20180605134950.6605-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 --- drivers/crypto/atmel-ecc.c | 71 ++++++++++++++++++-------------------- drivers/crypto/atmel-ecc.h | 13 +++---- 2 files changed, 40 insertions(+), 44 deletions(-) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index d89b69d228ac..603e29bdcb97 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,8 +284,31 @@ static int atmel_ecc_send_receive(struct i2c_client *client, goto err; } + /* 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, (u8 *)cmd, cmd->count + WORD_ADDR_SIZE); + 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 6d586a3e443d..2a378bccc213 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 @@ -136,14 +137,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 Tue Jun 5 13:49:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137740 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp986110lji; Tue, 5 Jun 2018 06:50:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKW7MAVebR+SYSC5xbiHJoyiFuxsrlO5ZBwM+R1JdENCIS1ttZ2hc8txyWrEXz4Kr6pjDuY X-Received: by 2002:a62:8b9b:: with SMTP id e27-v6mr25902785pfl.82.1528206639969; Tue, 05 Jun 2018 06:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206639; cv=none; d=google.com; s=arc-20160816; b=ojbXYsINCeVVL+2RgBWKEhYqDxm5eU8PtH5D+cWaJ7F2GiIcrv5KTU95B395Rz/Ju7 TIFlF3dReOTpK5i4V1Z1+UjkQ5E1o396sUXGXMJrwZvL+JYv+ddCS6+RblXZg6Ebu9QA ERABnG6k50fWbY0Zyi1DGmN3TXXyQbAc2UDoaEhRJREuu7FwLNgwHiIttZ7kmUwjLU2w 8t1mnto8u1petljb3pAmrKoE+5rIFqiaV3AV+QsVXnjJoKBKKurI1MIcfUTVcOuMWUnx bFketKFH76BPy/KAhTbPECAhCHF3fAD9Cp/ZMKVkMudBL17ZwQ7HOsuqeWGEnqP4JGwq xHXQ== 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=OxiVk9lTluBzygsYhGigdmpo7mqiFb3R0THq7IvYYH0=; b=Pv3rOWToh2IS0fYl/90HpsV0i53gCyiTmG7xOGRUkLhECN8ofOYEaKA2KQ8/BOSs2G mI4zDYTgmRg34fF3usli1Xb0d7ZCRCXrWxK3eJvYluWn8KyZPdpXIZVGM8PbW+Nn5Up6 pzsF+cSHbis1hujFVJlEEy5+ccgHPIuNeA7m1KXhEfWTpCXgdKUIqkYqfP0urrkWXqaP gzc61RgXAMOoizYRq3BZb/a/AkEkEZyPIOl2mxnqtnIWI2wVc0R//eAXI8cXHAXJb5Z2 I5wZ8qbCD+JfZPyojspQtX2WOqywc/Q6WJvmi19ZawkKAexg5Wo8ZUCgfkm64STMogTD SB+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TGi1Cq0i; 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 j78-v6si24186154pfe.187.2018.06.05.06.50.39; Tue, 05 Jun 2018 06:50: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=TGi1Cq0i; 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 S1751954AbeFENui (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:38 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:35507 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeFENui (ORCPT ); Tue, 5 Jun 2018 09:50:38 -0400 Received: by mail-lf0-f65.google.com with SMTP id y72-v6so3718105lfd.2 for ; Tue, 05 Jun 2018 06:50: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=OxiVk9lTluBzygsYhGigdmpo7mqiFb3R0THq7IvYYH0=; b=TGi1Cq0iWcej5ngjCDA6JmHEjVhVwVccvusrY3IsSysAlNayj7HyaQXiobdFyz+OKk jSli1XM7EWd79+zULp+vgA0lxM4141BAqlbwAnH390j2x4ws9i/n+VW5zNfRXS5dBoxe fQkqIYnv9kqqeky5OJVHlna/31Px6YGNCK+8U= 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=OxiVk9lTluBzygsYhGigdmpo7mqiFb3R0THq7IvYYH0=; b=GrBfaYAw2mEVhCDpfCX1t5dS7ddN8dxmhAv25EZag+4cq9KaFQ3bVGKXhy0TP1y4DF mYHyP/EouIofMMXzWTP5qy0g72G1r7PCTHyTJ+K+uC13lpn/byWSBaEyxbdOXt99ez78 yXztipK5ljRGPn8efSFwJJgR/fxGLCGptwgM3M9+aPbk1Qs9AoNUvXTR11fbZr2E5TMT cxSCI7BP16QnYZ663O3BBaFJwJBwVA17OjHkAwnn3Is5AIuRfIDCY5gr90ZZU34xXlJd nj0Gec8thUqEZvZaxwKjDb/qANElfRAkcfXM02rRgb8IHafIdSSl5e6gZp7t+T2On8cb h5cA== X-Gm-Message-State: ALKqPwduiLJpwvK4y6Pc7RvBmsoiqZidN7T9peRkNnIzkLpF9o3ceOuQ 72xMpV7x2ECiEL/Ocp11brweKqa6eoY= X-Received: by 2002:a2e:594d:: with SMTP id n74-v6mr19050374ljb.128.1528206636648; Tue, 05 Jun 2018 06:50:36 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:35 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 7/9] crypto: atmel-ecc: Print out serial number Date: Tue, 5 Jun 2018 15:49:48 +0200 Message-Id: <20180605134950.6605-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 --- drivers/crypto/atmel-ecc.c | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) -- 2.17.0 diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index 603e29bdcb97..fd8149313104 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -616,6 +617,57 @@ 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; + u8 serial[9]; + int ret; + int i; + + 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"); + return ret; + } + for (i = 0; i < 4; i++) + serial[0+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"); + return ret; + } + 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) { + dev_err(&client->dev, + "failed to read serial byte 8\n"); + return ret; + } + 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]); + return 0; +} + static int device_sanity_check(struct i2c_client *client) { struct atmel_ecc_cmd *cmd; @@ -700,6 +752,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 Tue Jun 5 13:49:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137741 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp986193lji; Tue, 5 Jun 2018 06:50:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKOlD4OCUL+enPwbe0A3IbxfdE8R9CCLMhsKZPpzasjS0qyTaw3dWJcEGox7c+L3tStxgzE X-Received: by 2002:a62:9945:: with SMTP id d66-v6mr15620722pfe.192.1528206643499; Tue, 05 Jun 2018 06:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206643; cv=none; d=google.com; s=arc-20160816; b=SjJ0mxqBVPJSuKU41HRspt/lgt7PbGpEqu0a4dvFhHyumklewBtaHAsPKS8E705faD Q+JPV62hoLYPD+5rct3vkgeHrJA8ChfLQrX6W9BVME8VE8cWb0AF9L5uVi5sMf6irD+a 7qevyKualZkIOdB3ZvglQqx/TVtcQozqQD1zbPoOvwjNcaA5FC3QG3K2G6U1MiVHbmu0 4axEtTrt4ZxQFsjujCVDt4GfjmOS4o7C45GiBT/uysXOrmZi9skNHx5xA0IJf6f1NJFG hiFIUOjv3nD9Q7KIaLyAUw53fL6OfFX0Ua61ZTonydLng+HPANau0Hdr0WT1oNc3TXX1 vyJw== 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=GzEI/+65HMa0rNp6Pw7CGfVjulmnkWrDhv37jqOeDAE=; b=IUvLTJ1R9dP4tW5C96+l2NvTjme2euE1yBDk5ZPbaVVLfcfME4xCWfDZdTBWGaWOud 3yTNUicxE1p9RyuW/seZh/sO0yLnEapzeYl9CoAoBdmxR4D5QCqgkzB3bwJtsC9Pt2EM CKKdNhGqAeLPFRh464REege5RFdzXRFq30ARqxLUB38feik580cHVCcnmDexepo+ziCi yx53brbRJhx6LekTL6lwXBNAXp8OXNPw/xRzEWobrIdX2z8oZJnktF0BiyhqZXxyzwOu izCbs0j0b0UfLo+y8ydbn6jwOZ+jsXkuBBiaWf5VKaK/DFNrBbRibGATkq5e00B2TR4f GcCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AsK4Lrmf; 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 j78-v6si24186154pfe.187.2018.06.05.06.50.43; Tue, 05 Jun 2018 06:50:43 -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=AsK4Lrmf; 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 S1751949AbeFENum (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:42 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:44975 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeFENul (ORCPT ); Tue, 5 Jun 2018 09:50:41 -0400 Received: by mail-lf0-f67.google.com with SMTP id 36-v6so3679054lfr.11 for ; Tue, 05 Jun 2018 06:50:41 -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=GzEI/+65HMa0rNp6Pw7CGfVjulmnkWrDhv37jqOeDAE=; b=AsK4LrmfCdy34EY13RKEZhfVr3GeD6SpzfcX0QxGB3NpSA5nHoet0jq/QnzjsCfKFQ An7bJRmcZb6fjd/Kgce+TjSgqzND/57WwfbITSZG09M0wFC1u+N9EazW1q4tFhoDfVYp g8P6ZXIrZhKJ98gUR3Vr4ICszUgDGKFnRHy1E= 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=GzEI/+65HMa0rNp6Pw7CGfVjulmnkWrDhv37jqOeDAE=; b=MGP/XFFHQDTxPFdTzCSbcDV2tb9JMJ5KnA55wFX6/Gm/c/u9EYSR8K8PL/FDsxKJzS DdEfbCN6G/p5fLA+gBi4e/+sQB9ot0kIAHN6+yTOCs+bOAkoktfumm02owORGXZmZmZ6 9HGZYWsKDJCiescIi51omuFkuCQOaDyVyZs+mbUu4jh5z1gHSx8Na3cWV1uZFMcpltFA 5lJDUSc+GSYgs3DoVLloo23VjFED2Qwbzvh3XU5agtSVmxgY8e/UteHWcRY7p/s4UkEV 1pJnX0TxgLKe/pcCvNBVbU5nJmbJqPc7jOEufWkOwrQWoXgFBRQgGA0g5EVvLJp5Lgng Lfag== X-Gm-Message-State: APt69E2YuqWhQmgUaJYacQchm5jw8iVjGN1D7jAvIDxKWuoJChvrRmDJ RACTX53DTwQ3Kpc9h03YsIBf9qvO9o8= X-Received: by 2002:a19:1099:: with SMTP id 25-v6mr1681732lfq.112.1528206640358; Tue, 05 Jun 2018 06:50:40 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:39 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 8/9] crypto: atmel-ecc: Detail what is unlocked Date: Tue, 5 Jun 2018 15:49:49 +0200 Message-Id: <20180605134950.6605-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 --- 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 fd8149313104..2b6c8bb7bd1c 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -692,8 +692,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 2a378bccc213..988e46507619 100644 --- a/drivers/crypto/atmel-ecc.h +++ b/drivers/crypto/atmel-ecc.h @@ -113,8 +113,6 @@ static const struct { #define CONFIG_ZONE_LKU_4_5 0x13 #define CONFIG_ZONE_LKU_6_7 0x14 #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 Tue Jun 5 13:49:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 137742 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp986247lji; Tue, 5 Jun 2018 06:50:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKatFz64dh/S36+oNNiaq9lC0Pw+CxROUGhZljStoLzn1VISTDAe5poF7dJ3R0uylHMDNFC X-Received: by 2002:a17:902:b784:: with SMTP id e4-v6mr16301703pls.264.1528206646303; Tue, 05 Jun 2018 06:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528206646; cv=none; d=google.com; s=arc-20160816; b=Bkqu1lq+3bFzUXyXqvPZnWjVq6RBN0ibXkwVClMeU7AL44nKlgeNpBCNg1I5fX0WFU 3gH/uLsyaT9Wy7CEh1zSqV7lZNkoJnBndcKzzycll07rVUvCB+Wf37pycSCr1NUjyNH2 eCCc3oD28+XbfWRKeMGBZQVWtif60Z977Uh39w3sZ9bWZojNx2xls5RT7/CCUVVVPZ8/ DlBI/XAsSBWRVf/V7+xEz7lDyBECJgAJ/QnHfc+y78ZDkiR74MT+md7anIZdgPWcygmv djd9mR+qgUcbsMU5NL2i9nKMyrLPgNh3AM8HpwNziX7rKJshyvpDdRxh6vedCa/xCGr4 8JCw== 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=Q2W74LtUy6bEDliP9nAz4pPZgsJ1pQcETLnCm5qkJA4=; b=cw4/0rZ5Mc6uTplEVwqySQ32UAgyCgXgJkwEdl3p10cq110K0ThxbfuzAK6svydqIN 0mtnhwABBv+8yyygAhRyrXkryY/bv1cuEIFOgekkRb3UN/uSkN21Dtl1Yp3x0UYJ8NS2 ifztVvfIw/UnnimV+MUpfliPVbFP9RqiHeSPH/Lf+pXwskj+5vXHkn7MhdraoI8AQYPG 0qQ1l4ZMy9ZUIkZxt70aLLkbL/VE4pKCQycHEP+5xdJpeXHLaJNbz1dqiF+gR4pxR/Ug u/f8ATdcH+er8aViXAei3vvsW0yk+KieH2793X42jN9WxdrmLqd2LsEwzu9PVIAO2sLj ANHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R2boDiWv; 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 j78-v6si24186154pfe.187.2018.06.05.06.50.46; Tue, 05 Jun 2018 06:50: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=R2boDiWv; 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 S1751750AbeFENup (ORCPT + 1 other); Tue, 5 Jun 2018 09:50:45 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:33386 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751948AbeFENuo (ORCPT ); Tue, 5 Jun 2018 09:50:44 -0400 Received: by mail-lf0-f68.google.com with SMTP id y20-v6so3743624lfy.0 for ; Tue, 05 Jun 2018 06:50: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=Q2W74LtUy6bEDliP9nAz4pPZgsJ1pQcETLnCm5qkJA4=; b=R2boDiWvUyB5VDzSQkPt8c1ndBIibwB41U5sT6SFJ3FMkFmJs3O+Id2nuB3cloAWSt yUauFSXENpTZDfzHukZkpXRjwi2Lsp+KeqzJxKq4k1l4IeRh1sv5cmA/s1Trfyl44jSU +c7v/P+bL72soB6UdHmE/rqQUD2Uk3N2/dZok= 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=Q2W74LtUy6bEDliP9nAz4pPZgsJ1pQcETLnCm5qkJA4=; b=rbGpjf3UTrxZCCyJ6otFI7Q4nlzppNlFyFsu3CYqN8G4ROQIaDypAli2t77/RRtJ9b 2mvNgMQfSW2RxMhJj1xJSW1umw1epqi2Ds9jU69qHS1zQHqrukuqR2FigwuwKgImwuWu l2QhVWOLOIz8W6tOeyYVf6VUSo1sRqwPIwnusszOuPh17W52PRjqoUp5CzLgp8GuJ9b4 cBnEruutPcdKfTf/AVF+BmaIFMTNIWoGgKphgtWTNbJCB26UkqJhdE5buuIQ2cDuVHAf CjBJJCAd9zNMl8Wu/42mzt6zckfXIBEC3O+Nuj198i1IcXlipWVU3YA413NG341SJjfX VKvg== X-Gm-Message-State: APt69E0I8absggwqw2CNz6NIzZ2PhFXkOSMfuQo+4/7Y8Xe6+J7Hz4xn w3PFMDfyuGfxQQRUz10xkD+SeOkd4kY= X-Received: by 2002:a19:b54d:: with SMTP id e74-v6mr1551313lff.118.1528206643184; Tue, 05 Jun 2018 06:50:43 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x72-v6sm5201092lfi.52.2018.06.05.06.50.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:50:41 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , Tudor Ambarus Cc: Linus Walleij Subject: [PATCH 9/9] crypto: atmel-ecc: Break out lock check helper Date: Tue, 5 Jun 2018 15:49:50 +0200 Message-Id: <20180605134950.6605-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180605134950.6605-1-linus.walleij@linaro.org> References: <20180605134950.6605-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 --- 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 2b6c8bb7bd1c..d15cc77ab739 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -668,7 +668,9 @@ static int atmel_ecc_get_serial(struct i2c_client *client) return 0; } -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; @@ -682,21 +684,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; }