From patchwork Thu Dec 14 14:02:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 121965 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6849291qgn; Thu, 14 Dec 2017 06:06:35 -0800 (PST) X-Google-Smtp-Source: ACJfBovjdPdO7a6KRSXozFxDbn+DIzyrkDDvAjeZYpxzBEAxSI9UoGak4VLELnfN5B9xDQ8MERoW X-Received: by 10.84.235.72 with SMTP id g8mr1804799plt.238.1513260395839; Thu, 14 Dec 2017 06:06:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513260395; cv=none; d=google.com; s=arc-20160816; b=tZrGMhxbvhYGCEGOM0mDeulrw4cBQsOonlmN5I4xawDW5cmT/6cKrG/GertRzIMOTF 4p0I6+Ei78FFRTtv9u0M46vDOxOtqVvKnJJy8K0Gzt9YR43pWCYyplMhVAshJDoEK8Rn ELQ/U7SbYT4X2kCKZR9mYWFSLZyvjUTyKlQsDGhl6qIORz2g9J4BW+IBPh7iQRpmfuNc +5AW+Fr3eALyhaB3CAiyU66xZ15btivxHKM2N2Ep8MW7CVRc2+LQhFZWCDcpqBAhPVKY aAtKvmMKueUF+zspZO8Ubwg8KdC17Igk/L6HW+Yw6z/MmNhHjQdw6wU1zsLm0KfBRCCD 6Whw== 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:arc-authentication-results; bh=hS2PH6TrJ1rMJZGYVYh36UkTWfGPCwulNbAyYH7LPr0=; b=fbYexIZwWcBa3G7WadyzD15yZXeQy6e5eMZL1xFFhyqnmjSa8MAbUP+Snla2ERDGpp 3J3LGLhyzUCz5FwvuaF/Mk++xCU/KnT8wzVxUY47/PcZe/2J8zaeZao25rvRwPsd1TNw TTncDmeZChtoHVdM4ZDtv5bDzghwF1mFr5e3eaCgtuQlN+Lf35L33ibwRmW+tDkaYSb7 s71lXrvdNyF1vucdPnKkfYpwFsHMj8DS70m2X9kJQF1TiBW+Z2FdaAD+Sg0paAuHuvgn DwFMhbMLSQm6ZYx6FdpS1qqh1aiCakXfIj5cLSLUGqqRr51wqoaK4JurSmrSyBAA2wf+ S8vA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si3194753plh.282.2017.12.14.06.06.35; Thu, 14 Dec 2017 06:06:35 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751098AbdLNOGd (ORCPT + 1 other); Thu, 14 Dec 2017 09:06:33 -0500 Received: from foss.arm.com ([217.140.101.70]:42178 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752710AbdLNODU (ORCPT ); Thu, 14 Dec 2017 09:03:20 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4E7351435; Thu, 14 Dec 2017 06:03:20 -0800 (PST) Received: from sugar.kfn.arm.com (unknown [10.45.48.196]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8987C3F246; Thu, 14 Dec 2017 06:03:18 -0800 (PST) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org Subject: [PATCH 04/10] staging: ccree: staging: ccree: replace sysfs by debugfs interface Date: Thu, 14 Dec 2017 14:02:41 +0000 Message-Id: <1513260170-26346-5-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513260170-26346-1-git-send-email-gilad@benyossef.com> References: <1513260170-26346-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The ccree driver has had a none standard sysfs interface for debugging. Replace it with a proper debugfs interface. Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/Makefile | 3 +- drivers/staging/ccree/cc_debugfs.c | 114 +++++++++++++++++++ drivers/staging/ccree/cc_debugfs.h | 45 ++++++++ drivers/staging/ccree/ssi_aead.c | 1 - drivers/staging/ccree/ssi_cipher.c | 1 - drivers/staging/ccree/ssi_config.h | 2 - drivers/staging/ccree/ssi_driver.c | 27 ++--- drivers/staging/ccree/ssi_driver.h | 2 +- drivers/staging/ccree/ssi_hash.c | 1 - drivers/staging/ccree/ssi_pm.c | 1 - drivers/staging/ccree/ssi_request_mgr.c | 1 - drivers/staging/ccree/ssi_sysfs.c | 192 -------------------------------- drivers/staging/ccree/ssi_sysfs.h | 32 ------ 13 files changed, 176 insertions(+), 246 deletions(-) create mode 100644 drivers/staging/ccree/cc_debugfs.c create mode 100644 drivers/staging/ccree/cc_debugfs.h delete mode 100644 drivers/staging/ccree/ssi_sysfs.c delete mode 100644 drivers/staging/ccree/ssi_sysfs.h -- 2.7.4 diff --git a/drivers/staging/ccree/Makefile b/drivers/staging/ccree/Makefile index ae702f3..ab9f073 100644 --- a/drivers/staging/ccree/Makefile +++ b/drivers/staging/ccree/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_CRYPTO_DEV_CCREE) := ccree.o -ccree-y := ssi_driver.o ssi_sysfs.o ssi_buffer_mgr.o ssi_request_mgr.o ssi_cipher.o ssi_hash.o ssi_aead.o ssi_ivgen.o ssi_sram_mgr.o ssi_pm.o +ccree-y := ssi_driver.o ssi_buffer_mgr.o ssi_request_mgr.o ssi_cipher.o ssi_hash.o ssi_aead.o ssi_ivgen.o ssi_sram_mgr.o ssi_pm.o ccree-$(CONFIG_CRYPTO_FIPS) += ssi_fips.o +ccree-$(CONFIG_DEBUG_FS) += cc_debugfs.o diff --git a/drivers/staging/ccree/cc_debugfs.c b/drivers/staging/ccree/cc_debugfs.c new file mode 100644 index 0000000..7768a7b --- /dev/null +++ b/drivers/staging/ccree/cc_debugfs.c @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2012-2017 ARM Limited or its affiliates. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include "ssi_config.h" +#include "ssi_driver.h" +#include "cc_crypto_ctx.h" + +struct cc_debugfs_ctx { + struct dentry *dir; +}; + +#define CC_DEBUG_REG(_X) { \ + .name = __stringify(_X),\ + .offset = CC_REG(_X) \ + } + +/* + * This is a global var for the dentry of the + * debugfs ccree/ dir. It is not tied down to + * a specific instance of ccree, hence it is + * global. + */ +static struct dentry *cc_debugfs_dir; + +struct debugfs_reg32 debug_regs[] = { + CC_DEBUG_REG(HOST_SIGNATURE), + CC_DEBUG_REG(HOST_IRR), + CC_DEBUG_REG(HOST_POWER_DOWN_EN), + CC_DEBUG_REG(AXIM_MON_ERR), + CC_DEBUG_REG(DSCRPTR_QUEUE_CONTENT), + CC_DEBUG_REG(HOST_IMR), + CC_DEBUG_REG(AXIM_CFG), + CC_DEBUG_REG(AXIM_CACHE_PARAMS), + CC_DEBUG_REG(HOST_VERSION), + CC_DEBUG_REG(GPR_HOST), + CC_DEBUG_REG(AXIM_MON_COMP), +}; + +int cc_debugfs_global_init(void) +{ + cc_debugfs_dir = debugfs_create_dir("ccree", NULL); + + return !cc_debugfs_dir; +} + +void cc_debugfs_global_fini(void) +{ + debugfs_remove(cc_debugfs_dir); +} + +int cc_debugfs_init(struct cc_drvdata *drvdata) +{ + struct device *dev = drvdata_to_dev(drvdata); + struct cc_debugfs_ctx *ctx; + struct debugfs_regset32 *regset; + struct dentry *file; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); + if (!regset) + return -ENOMEM; + + regset->regs = debug_regs; + regset->nregs = ARRAY_SIZE(debug_regs); + regset->base = drvdata->cc_base; + + ctx->dir = debugfs_create_dir(drvdata->plat_dev->name, cc_debugfs_dir); + if (!ctx->dir) + return -ENFILE; + + file = debugfs_create_regset32("regs", 0400, ctx->dir, regset); + if (!file) { + debugfs_remove(ctx->dir); + return -ENFILE; + } + + file = debugfs_create_bool("coherent", 0400, ctx->dir, + &drvdata->coherent); + + if (!file) { + debugfs_remove_recursive(ctx->dir); + return -ENFILE; + } + + drvdata->debugfs = ctx; + + return 0; +} + +void cc_debugfs_fini(struct cc_drvdata *drvdata) +{ + struct cc_debugfs_ctx *ctx = (struct cc_debugfs_ctx *)drvdata->debugfs; + + debugfs_remove_recursive(ctx->dir); +} diff --git a/drivers/staging/ccree/cc_debugfs.h b/drivers/staging/ccree/cc_debugfs.h new file mode 100644 index 0000000..edfe9ba --- /dev/null +++ b/drivers/staging/ccree/cc_debugfs.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2012-2017 ARM Limited or its affiliates. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef __CC_DEBUGFS_H__ +#define __CC_DEBUGFS_H__ + +#ifdef CONFIG_DEBUG_FS +int cc_debugfs_global_init(void); +void cc_debugfs_global_fini(void); + +int cc_debugfs_init(struct cc_drvdata *drvdata); +void cc_debugfs_fini(struct cc_drvdata *drvdata); + +#else + +int cc_debugfs_global_init(void) +{ + return 0; +} + +void cc_debugfs_global_fini(void) {} + +int cc_debugfs_init(struct cc_drvdata *drvdata) +{ + return 0; +} + +void cc_debugfs_fini(struct cc_drvdata *drvdata) {} + +#endif + +#endif /*__CC_SYSFS_H__*/ diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c index 12ceb119..dde6797 100644 --- a/drivers/staging/ccree/ssi_aead.c +++ b/drivers/staging/ccree/ssi_aead.c @@ -34,7 +34,6 @@ #include "ssi_aead.h" #include "ssi_request_mgr.h" #include "ssi_hash.h" -#include "ssi_sysfs.h" #include "ssi_sram_mgr.h" #define template_aead template_u.aead diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c index 791fe75..f940568 100644 --- a/drivers/staging/ccree/ssi_cipher.c +++ b/drivers/staging/ccree/ssi_cipher.c @@ -32,7 +32,6 @@ #include "ssi_buffer_mgr.h" #include "ssi_cipher.h" #include "ssi_request_mgr.h" -#include "ssi_sysfs.h" #define MAX_ABLKCIPHER_SEQ_LEN 6 diff --git a/drivers/staging/ccree/ssi_config.h b/drivers/staging/ccree/ssi_config.h index ee2d310..15725cc 100644 --- a/drivers/staging/ccree/ssi_config.h +++ b/drivers/staging/ccree/ssi_config.h @@ -28,8 +28,6 @@ //#define CC_DUMP_DESCS // #define CC_DUMP_BYTES // #define CC_DEBUG -/* Enable sysfs interface for debugging REE driver */ -#define ENABLE_CC_SYSFS //#define CC_IRQ_DELAY 100000 /* was 32 bit, but for juno's sake it was enlarged to 48 bit */ #define DMA_BIT_MASK_LEN 48 diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c index 5427c7f..14705dc 100644 --- a/drivers/staging/ccree/ssi_driver.c +++ b/drivers/staging/ccree/ssi_driver.c @@ -63,7 +63,7 @@ #include "ssi_driver.h" #include "ssi_request_mgr.h" #include "ssi_buffer_mgr.h" -#include "ssi_sysfs.h" +#include "cc_debugfs.h" #include "ssi_cipher.h" #include "ssi_aead.h" #include "ssi_hash.h" @@ -299,18 +299,16 @@ static int init_cc_resources(struct platform_device *plat_dev) goto post_clk_err; } -#ifdef ENABLE_CC_SYSFS - rc = ssi_sysfs_init(&dev->kobj, new_drvdata); + rc = cc_debugfs_init(new_drvdata); if (rc) { - dev_err(dev, "init_stat_db failed\n"); + dev_err(dev, "Failed registering debugfs interface\n"); goto post_regs_err; } -#endif rc = cc_fips_init(new_drvdata); if (rc) { dev_err(dev, "CC_FIPS_INIT failed 0x%x\n", rc); - goto post_sysfs_err; + goto post_debugfs_err; } rc = cc_sram_mgr_init(new_drvdata); if (rc) { @@ -394,10 +392,8 @@ static int init_cc_resources(struct platform_device *plat_dev) cc_sram_mgr_fini(new_drvdata); post_fips_init_err: cc_fips_fini(new_drvdata); -post_sysfs_err: -#ifdef ENABLE_CC_SYSFS - ssi_sysfs_fini(); -#endif +post_debugfs_err: + cc_debugfs_fini(new_drvdata); post_regs_err: fini_cc_regs(new_drvdata); post_clk_err: @@ -425,9 +421,7 @@ static void cleanup_cc_resources(struct platform_device *plat_dev) cc_req_mgr_fini(drvdata); cc_sram_mgr_fini(drvdata); cc_fips_fini(drvdata); -#ifdef ENABLE_CC_SYSFS - ssi_sysfs_fini(); -#endif + cc_debugfs_fini(drvdata); fini_cc_regs(drvdata); cc_clk_off(drvdata); } @@ -520,6 +514,12 @@ static struct platform_driver cc7x_driver = { static int __init ccree_init(void) { + int ret; + + ret = cc_debugfs_global_init(); + if (ret) + return ret; + return platform_driver_register(&cc7x_driver); } module_init(ccree_init); @@ -527,6 +527,7 @@ module_init(ccree_init); static void __exit ccree_exit(void) { platform_driver_unregister(&cc7x_driver); + cc_debugfs_global_fini(); } module_exit(ccree_exit); diff --git a/drivers/staging/ccree/ssi_driver.h b/drivers/staging/ccree/ssi_driver.h index 35e1b72..4e05386 100644 --- a/drivers/staging/ccree/ssi_driver.h +++ b/drivers/staging/ccree/ssi_driver.h @@ -44,7 +44,6 @@ #include "dx_reg_common.h" #define CC_SUPPORT_SHA CC_DEV_SHA_MAX #include "cc_crypto_ctx.h" -#include "ssi_sysfs.h" #include "hash_defs.h" #include "cc_hw_queue_defs.h" #include "ssi_sram_mgr.h" @@ -127,6 +126,7 @@ struct cc_drvdata { void *fips_handle; void *ivgen_handle; void *sram_mgr_handle; + void *debugfs; struct clk *clk; bool coherent; }; diff --git a/drivers/staging/ccree/ssi_hash.c b/drivers/staging/ccree/ssi_hash.c index 5794ab6..0aea404 100644 --- a/drivers/staging/ccree/ssi_hash.c +++ b/drivers/staging/ccree/ssi_hash.c @@ -27,7 +27,6 @@ #include "ssi_driver.h" #include "ssi_request_mgr.h" #include "ssi_buffer_mgr.h" -#include "ssi_sysfs.h" #include "ssi_hash.h" #include "ssi_sram_mgr.h" diff --git a/drivers/staging/ccree/ssi_pm.c b/drivers/staging/ccree/ssi_pm.c index 0db935d..abc715e 100644 --- a/drivers/staging/ccree/ssi_pm.c +++ b/drivers/staging/ccree/ssi_pm.c @@ -24,7 +24,6 @@ #include "ssi_buffer_mgr.h" #include "ssi_request_mgr.h" #include "ssi_sram_mgr.h" -#include "ssi_sysfs.h" #include "ssi_ivgen.h" #include "ssi_hash.h" #include "ssi_pm.h" diff --git a/drivers/staging/ccree/ssi_request_mgr.c b/drivers/staging/ccree/ssi_request_mgr.c index 480e6d3..07b9404 100644 --- a/drivers/staging/ccree/ssi_request_mgr.c +++ b/drivers/staging/ccree/ssi_request_mgr.c @@ -27,7 +27,6 @@ #include "ssi_driver.h" #include "ssi_buffer_mgr.h" #include "ssi_request_mgr.h" -#include "ssi_sysfs.h" #include "ssi_ivgen.h" #include "ssi_pm.h" diff --git a/drivers/staging/ccree/ssi_sysfs.c b/drivers/staging/ccree/ssi_sysfs.c deleted file mode 100644 index b2e58f5..0000000 --- a/drivers/staging/ccree/ssi_sysfs.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2012-2017 ARM Limited or its affiliates. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#include -#include "ssi_config.h" -#include "ssi_driver.h" -#include "cc_crypto_ctx.h" -#include "ssi_sysfs.h" - -#ifdef ENABLE_CC_SYSFS - -static struct cc_drvdata *sys_get_drvdata(void); - -static ssize_t ssi_sys_regdump_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - struct cc_drvdata *drvdata = sys_get_drvdata(); - u32 register_value; - int offset = 0; - - register_value = cc_ioread(drvdata, CC_REG(HOST_SIGNATURE)); - offset += scnprintf(buf + offset, PAGE_SIZE - offset, - "%s \t(0x%lX)\t 0x%08X\n", "HOST_SIGNATURE ", - CC_HOST_SIGNATURE_REG_OFFSET, register_value); - register_value = cc_ioread(drvdata, CC_REG(HOST_IRR)); - offset += scnprintf(buf + offset, PAGE_SIZE - offset, - "%s \t(0x%lX)\t 0x%08X\n", "HOST_IRR ", - CC_HOST_IRR_REG_OFFSET, register_value); - register_value = cc_ioread(drvdata, CC_REG(HOST_POWER_DOWN_EN)); - offset += scnprintf(buf + offset, PAGE_SIZE - offset, - "%s \t(0x%lX)\t 0x%08X\n", "HOST_POWER_DOWN_EN ", - CC_HOST_POWER_DOWN_EN_REG_OFFSET, register_value); - register_value = cc_ioread(drvdata, CC_REG(AXIM_MON_ERR)); - offset += scnprintf(buf + offset, PAGE_SIZE - offset, - "%s \t(0x%lX)\t 0x%08X\n", "AXIM_MON_ERR ", - CC_AXIM_MON_ERR_REG_OFFSET, register_value); - register_value = cc_ioread(drvdata, CC_REG(DSCRPTR_QUEUE_CONTENT)); - offset += scnprintf(buf + offset, PAGE_SIZE - offset, - "%s \t(0x%lX)\t 0x%08X\n", "DSCRPTR_QUEUE_CONTENT", - CC_DSCRPTR_QUEUE_CONTENT_REG_OFFSET, - register_value); - return offset; -} - -static ssize_t ssi_sys_help_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - static const char * const help_str[] = { - "cat reg_dump ", - "Print several of CC register values", - }; - int i = 0, offset = 0; - - offset += scnprintf(buf + offset, PAGE_SIZE - offset, "Usage:\n"); - for (i = 0; i < ARRAY_SIZE(help_str); i += 2) { - offset += scnprintf(buf + offset, PAGE_SIZE - offset, - "%s\t\t%s\n", help_str[i], - help_str[i + 1]); - } - - return offset; -} - -/******************************************************** - * SYSFS objects * - ********************************************************/ -/* - * Structure used to create a directory - * and its attributes in sysfs. - */ -struct sys_dir { - struct kobject *sys_dir_kobj; - struct attribute_group sys_dir_attr_group; - struct attribute **sys_dir_attr_list; - u32 num_of_attrs; - struct cc_drvdata *drvdata; /* Associated driver context */ -}; - -/* top level directory structures */ -static struct sys_dir sys_top_dir; - -/* TOP LEVEL ATTRIBUTES */ -static struct kobj_attribute ssi_sys_top_level_attrs[] = { - __ATTR(dump_regs, 0444, ssi_sys_regdump_show, NULL), - __ATTR(help, 0444, ssi_sys_help_show, NULL), -#if defined CC_CYCLE_COUNT - __ATTR(stats_host, 0664, ssi_sys_stat_host_db_show, - ssi_sys_stats_host_db_clear), - __ATTR(stats_cc, 0664, ssi_sys_stat_cc_db_show, - ssi_sys_stats_cc_db_clear), -#endif - -}; - -static struct cc_drvdata *sys_get_drvdata(void) -{ - /* TODO: supporting multiple SeP devices would require avoiding - * global "top_dir" and finding associated "top_dir" by traversing - * up the tree to the kobject which matches one of the top_dir's - */ - return sys_top_dir.drvdata; -} - -static int sys_init_dir(struct sys_dir *sys_dir, struct cc_drvdata *drvdata, - struct kobject *parent_dir_kobj, const char *dir_name, - struct kobj_attribute *attrs, u32 num_of_attrs) -{ - int i; - - memset(sys_dir, 0, sizeof(struct sys_dir)); - - sys_dir->drvdata = drvdata; - - /* initialize directory kobject */ - sys_dir->sys_dir_kobj = - kobject_create_and_add(dir_name, parent_dir_kobj); - - if (!(sys_dir->sys_dir_kobj)) - return -ENOMEM; - /* allocate memory for directory's attributes list */ - sys_dir->sys_dir_attr_list = - kcalloc(num_of_attrs + 1, sizeof(struct attribute *), - GFP_KERNEL); - - if (!(sys_dir->sys_dir_attr_list)) { - kobject_put(sys_dir->sys_dir_kobj); - return -ENOMEM; - } - - sys_dir->num_of_attrs = num_of_attrs; - - /* initialize attributes list */ - for (i = 0; i < num_of_attrs; ++i) - sys_dir->sys_dir_attr_list[i] = &attrs[i].attr; - - /* last list entry should be NULL */ - sys_dir->sys_dir_attr_list[num_of_attrs] = NULL; - - sys_dir->sys_dir_attr_group.attrs = sys_dir->sys_dir_attr_list; - - return sysfs_create_group(sys_dir->sys_dir_kobj, - &sys_dir->sys_dir_attr_group); -} - -static void sys_free_dir(struct sys_dir *sys_dir) -{ - if (!sys_dir) - return; - - kfree(sys_dir->sys_dir_attr_list); - - if (sys_dir->sys_dir_kobj) { - sysfs_remove_group(sys_dir->sys_dir_kobj, - &sys_dir->sys_dir_attr_group); - kobject_put(sys_dir->sys_dir_kobj); - } -} - -int ssi_sysfs_init(struct kobject *sys_dev_obj, struct cc_drvdata *drvdata) -{ - int retval; - struct device *dev = drvdata_to_dev(drvdata); - - dev_info(dev, "setup sysfs under %s\n", sys_dev_obj->name); - - /* Initialize top directory */ - retval = sys_init_dir(&sys_top_dir, drvdata, sys_dev_obj, "cc_info", - ssi_sys_top_level_attrs, - ARRAY_SIZE(ssi_sys_top_level_attrs)); - return retval; -} - -void ssi_sysfs_fini(void) -{ - sys_free_dir(&sys_top_dir); -} - -#endif /*ENABLE_CC_SYSFS*/ - diff --git a/drivers/staging/ccree/ssi_sysfs.h b/drivers/staging/ccree/ssi_sysfs.h deleted file mode 100644 index 9833d18..0000000 --- a/drivers/staging/ccree/ssi_sysfs.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2012-2017 ARM Limited or its affiliates. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -/* \file ssi_sysfs.h - * ARM CryptoCell sysfs APIs - */ - -#ifndef __CC_SYSFS_H__ -#define __CC_SYSFS_H__ - -#include - -/* forward declaration */ -struct cc_drvdata; - -int ssi_sysfs_init(struct kobject *sys_dev_obj, struct cc_drvdata *drvdata); -void ssi_sysfs_fini(void); - -#endif /*__CC_SYSFS_H__*/ From patchwork Thu Dec 14 14:02:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 121961 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6844611qgn; Thu, 14 Dec 2017 06:03:40 -0800 (PST) X-Google-Smtp-Source: ACJfBot1WyAfDMWJ+gPH8UwBI75gI32/gz8oKlFEHVGJuwpdxqPFYl7/3/wQd4w+s9GDEf/O/Vg0 X-Received: by 10.84.197.35 with SMTP id m32mr9600452pld.214.1513260220348; Thu, 14 Dec 2017 06:03:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513260220; cv=none; d=google.com; s=arc-20160816; b=IWzczwe++am1yIUOtPplD6IpDcpPRmyb9v6X55rz7mXGUlYnspl2kURvuHlURowvFl Yh61yyiGYWJSpEG8un5sP2kWMRkKO6/1oKGPR3nuOxIi36yvxnbGTvdnWp3whTUq7vkl B1R4RejgXra0h3L5rqqshcWBMVUJaEGSTjpr6b85XDVzbYhnX8BXJ54OhkEc0P8WCAwI ADaR1OEdyccWJlKHNuQBnQ+qXSXlaosOySKRkBMG/hD9m/JETiqAlUE3YXioRwkVucEi xlRAhXLi2nxmhd/MApuFDYltDntfdYJ7wxvVSaoFRG+2JAJW14qfUq5qJZSmqCbIFyqU 2XXQ== 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:arc-authentication-results; bh=gx+u11w21CW5olbM31+i0MUBydqse19haA8S7r/hxPg=; b=O0y5MCpVekf4lQLFlY1bd9rvZvk6eZweU8nMoJRzrAEve+kNwx4hRiuaArS/vg4/rp Z/w1BvNE39r4iKINQPe1z2w2EvSYrzupOcgLLJQuwXGlpolmph5e0YQIIRPqVJ9hkcJU IqquZjo9GVlFIb6yWojfgfGjT3PJpLsvjIb29yhcRB6Ix1btFrYhMTKvpEXWF04p3TDO dprg+3YuRc2cEPnjQADU7ovbGt7HD9jX9cbbB3us5QlxVFAcLfCvj36qFXRMiQwn5eKc cwjo6Ghvqn0IGngowS2iP5JVwj2ZOmX1xyH53TqJ+n/6+bQbUQa3mBxqKplMaw/7ZFqO Dh5g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si2928886pgp.308.2017.12.14.06.03.40; Thu, 14 Dec 2017 06:03:40 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752900AbdLNODh (ORCPT + 1 other); Thu, 14 Dec 2017 09:03:37 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:42210 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752547AbdLNODf (ORCPT ); Thu, 14 Dec 2017 09:03:35 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 95C8C1435; Thu, 14 Dec 2017 06:03:35 -0800 (PST) Received: from sugar.kfn.arm.com (unknown [10.45.48.196]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D3EDE3F246; Thu, 14 Dec 2017 06:03:33 -0800 (PST) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org Subject: [PATCH 07/10] staging: ccree: turn compile time debug log to params Date: Thu, 14 Dec 2017 14:02:44 +0000 Message-Id: <1513260170-26346-8-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513260170-26346-1-git-send-email-gilad@benyossef.com> References: <1513260170-26346-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The ccree driver has some support to dump runtime data to kernel log to assist in debugging. The code used to be enabled by a build time flag. Refactor to enable it via module/kernel parameters. Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_config.h | 2 -- drivers/staging/ccree/ssi_driver.c | 18 ++++++++++++------ drivers/staging/ccree/ssi_driver.h | 16 ++++++++++------ drivers/staging/ccree/ssi_request_mgr.c | 26 +++++++++++++------------- 4 files changed, 35 insertions(+), 27 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_config.h b/drivers/staging/ccree/ssi_config.h index b530974..bc90ad0 100644 --- a/drivers/staging/ccree/ssi_config.h +++ b/drivers/staging/ccree/ssi_config.h @@ -23,8 +23,6 @@ #include -//#define CC_DUMP_DESCS -// #define CC_DUMP_BYTES /* was 32 bit, but for juno's sake it was enlarged to 48 bit */ #define DMA_BIT_MASK_LEN 48 diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c index dbca241..195fb27 100644 --- a/drivers/staging/ccree/ssi_driver.c +++ b/drivers/staging/ccree/ssi_driver.c @@ -72,20 +72,26 @@ #include "ssi_pm.h" #include "ssi_fips.h" -#ifdef CC_DUMP_BYTES -void dump_byte_array(const char *name, const u8 *buf, size_t len) +bool cc_dump_desc; +module_param_named(dump_desc, cc_dump_desc, bool, 0600); +MODULE_PARM_DESC(cc_dump_desc, "Dump descriptors to kernel log as debugging aid"); + +bool cc_dump_bytes; +module_param_named(dump_bytes, cc_dump_bytes, bool, 0600); +MODULE_PARM_DESC(cc_dump_bytes, "Dump buffers to kernel log as debugging aid"); + +void __dump_byte_array(const char *name, const u8 *buf, size_t len) { - char prefix[NAME_LEN]; + char prefix[64]; if (!buf) return; snprintf(prefix, sizeof(prefix), "%s[%lu]: ", name, len); - print_hex_dump(KERN_DEBUG, prefix, DUMP_PREFIX_ADDRESS, 16, 1, len, - false); + print_hex_dump(KERN_DEBUG, prefix, DUMP_PREFIX_ADDRESS, 16, 1, buf, + len, false); } -#endif static irqreturn_t cc_isr(int irq, void *dev_id) { diff --git a/drivers/staging/ccree/ssi_driver.h b/drivers/staging/ccree/ssi_driver.h index 4e05386..12e2a8b 100644 --- a/drivers/staging/ccree/ssi_driver.h +++ b/drivers/staging/ccree/ssi_driver.h @@ -48,6 +48,9 @@ #include "cc_hw_queue_defs.h" #include "ssi_sram_mgr.h" +extern bool cc_dump_desc; +extern bool cc_dump_bytes; + #define DRV_MODULE_VERSION "3.0" #define CC_DEV_NAME_STR "cc715ree" @@ -169,13 +172,14 @@ static inline struct device *drvdata_to_dev(struct cc_drvdata *drvdata) return &drvdata->plat_dev->dev; } -#ifdef CC_DUMP_BYTES -void dump_byte_array(const char *name, const u8 *the_array, - unsigned long size); -#else +void __dump_byte_array(const char *name, const u8 *the_array, + unsigned long size); static inline void dump_byte_array(const char *name, const u8 *the_array, - unsigned long size) {}; -#endif + unsigned long size) +{ + if (cc_dump_bytes) + __dump_byte_array(name, the_array, size); +} int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe); void fini_cc_regs(struct cc_drvdata *drvdata); diff --git a/drivers/staging/ccree/ssi_request_mgr.c b/drivers/staging/ccree/ssi_request_mgr.c index f6374b0..2aa21f8 100644 --- a/drivers/staging/ccree/ssi_request_mgr.c +++ b/drivers/staging/ccree/ssi_request_mgr.c @@ -161,11 +161,12 @@ int cc_req_mgr_init(struct cc_drvdata *drvdata) return rc; } -static void enqueue_seq(void __iomem *cc_base, struct cc_hw_desc seq[], +static void enqueue_seq(struct cc_drvdata *drvdata, struct cc_hw_desc seq[], unsigned int seq_len) { int i, w; - void * __iomem reg = cc_base + CC_REG(DSCRPTR_QUEUE_WORD0); + void * __iomem reg = drvdata->cc_base + CC_REG(DSCRPTR_QUEUE_WORD0); + struct device *dev = drvdata_to_dev(drvdata); /* * We do indeed write all 6 command words to the same @@ -175,11 +176,12 @@ static void enqueue_seq(void __iomem *cc_base, struct cc_hw_desc seq[], for (i = 0; i < seq_len; i++) { for (w = 0; w <= 5; w++) writel_relaxed(seq[i].word[w], reg); -#ifdef CC_DUMP_DESCS - dev_dbg(dev, "desc[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", - i, seq[i].word[0], seq[i].word[1], seq[i].word[2], - seq[i].word[3], seq[i].word[4], seq[i].word[5]); -#endif + + if (cc_dump_desc) + dev_dbg(dev, "desc[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", + i, seq[i].word[0], seq[i].word[1], + seq[i].word[2], seq[i].word[3], + seq[i].word[4], seq[i].word[5]); } } @@ -256,7 +258,6 @@ static int cc_queues_status(struct cc_drvdata *drvdata, int send_request(struct cc_drvdata *drvdata, struct cc_crypto_req *cc_req, struct cc_hw_desc *desc, unsigned int len, bool is_dout) { - void __iomem *cc_base = drvdata->cc_base; struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle; unsigned int used_sw_slots; unsigned int iv_seq_len = 0; @@ -364,9 +365,9 @@ int send_request(struct cc_drvdata *drvdata, struct cc_crypto_req *cc_req, wmb(); /* STAT_PHASE_4: Push sequence */ - enqueue_seq(cc_base, iv_seq, iv_seq_len); - enqueue_seq(cc_base, desc, len); - enqueue_seq(cc_base, &req_mgr_h->compl_desc, (is_dout ? 0 : 1)); + enqueue_seq(drvdata, iv_seq, iv_seq_len); + enqueue_seq(drvdata, desc, len); + enqueue_seq(drvdata, &req_mgr_h->compl_desc, (is_dout ? 0 : 1)); if (req_mgr_h->q_free_slots < total_seq_len) { /* This situation should never occur. Maybe indicating problem @@ -407,7 +408,6 @@ int send_request(struct cc_drvdata *drvdata, struct cc_crypto_req *cc_req, int send_request_init(struct cc_drvdata *drvdata, struct cc_hw_desc *desc, unsigned int len) { - void __iomem *cc_base = drvdata->cc_base; struct cc_req_mgr_handle *req_mgr_h = drvdata->request_mgr_handle; unsigned int total_seq_len = len; /*initial sequence length*/ int rc = 0; @@ -426,7 +426,7 @@ int send_request_init(struct cc_drvdata *drvdata, struct cc_hw_desc *desc, * to make sure there are no outstnading memory writes */ wmb(); - enqueue_seq(cc_base, desc, len); + enqueue_seq(drvdata, desc, len); /* Update the free slots in HW queue */ req_mgr_h->q_free_slots = From patchwork Thu Dec 14 14:02:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 121963 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp6845003qgn; Thu, 14 Dec 2017 06:03:54 -0800 (PST) X-Google-Smtp-Source: ACJfBovI4+TsGQ/dZu80rm9Umqictic+MQgTV2YkqgJx0BpQ+oIAyIySsYWuFDD3lRvg6rJYG4QP X-Received: by 10.159.196.130 with SMTP id c2mr9788954plo.123.1513260234742; Thu, 14 Dec 2017 06:03:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513260234; cv=none; d=google.com; s=arc-20160816; b=t/zO25x7x/RRwsa7Od8NFdiVMx9OveQDMNQOpdT88er1wESYpqYrFv5A0T5FH+ocCO 5Ibm3BTf1AH3+LfwLeF0Zcysja24eU55ZFTf8CkSEss9fFrB6a9dXoaiEDvOJJ7ZuH4T 5ErNh3mqheIpr1N9L3wZ45RyVW9TH3l1llKDar1ZHr5dkE03vAPAwkceOszx/EAZRGwf oQZRe/CjrJIBKCMxLhIbCJ3A5NgKU7cr6Mr2uPsxPKU7Z27yn0odcLnyg2ZncalvDEB+ oaFNvnBI13pxspbeqcRaBBwgplJRZX7ExV4oOS4+wyJusuurBIwIUtB5vvhFqqicwx4L 0KpQ== 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:arc-authentication-results; bh=awR0xId7++2hLaDI/gGN66mVFGh0a/BZyiaysquBtlU=; b=VYOb3TahVlt5Wlcwv9/1M0xqQBdj0zXhYywjV69+rMCRXIcuyu0pNoGeTDRaXodsmf Ku7xi9mCBpbu51CQG9lQq7JyPhumVhryfQ01ZMJts6sX/O5S9NoWDF7iLJMc0F0lUREO TZLPozck2MOAv1MzMK3yBrFhO6aKJRacDf8Y5RWviNyL+Nm5d36cHcjGHQo4LiI5DQFV T7zXropclz+mRKXKXdcGYKihCN8qpFRkWrmPuNELH08rcNpCJAjz3PVfbGR3/C2Vzz1U 3vNTO4qGj9/xiZGyjKylRJdemfP4gf5YjgXlph9Ns5eo+14zeicL3+1xpMw9eZI8w1jt Pb/g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m63si3203934pld.467.2017.12.14.06.03.54; Thu, 14 Dec 2017 06:03:54 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753107AbdLNODx (ORCPT + 1 other); Thu, 14 Dec 2017 09:03:53 -0500 Received: from foss.arm.com ([217.140.101.70]:42248 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753042AbdLNODv (ORCPT ); Thu, 14 Dec 2017 09:03:51 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7DD9B15A2; Thu, 14 Dec 2017 06:03:51 -0800 (PST) Received: from sugar.kfn.arm.com (unknown [10.45.48.196]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 402DB3F246; Thu, 14 Dec 2017 06:03:49 -0800 (PST) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org Subject: [PATCH 10/10] staging: ccree: update TODO Date: Thu, 14 Dec 2017 14:02:47 +0000 Message-Id: <1513260170-26346-11-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513260170-26346-1-git-send-email-gilad@benyossef.com> References: <1513260170-26346-1-git-send-email-gilad@benyossef.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Update TODO with handling on sysfs -> debugfs transition Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/TODO | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/TODO b/drivers/staging/ccree/TODO index f44edcd..6d8702b 100644 --- a/drivers/staging/ccree/TODO +++ b/drivers/staging/ccree/TODO @@ -6,6 +6,5 @@ * * ************************************************************************* -1. Migrate sysfs to debugfs. -2. Handle HW FIFO fullness more cleanly. +1. Handle HW FIFO fullness more cleanly.