Message ID | 20231127202704.1263376-15-tom.zanussi@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3441492vqx; Mon, 27 Nov 2023 12:29:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/eAI8wz9DgCmDYVymG8n6ssCSBVH18qrspaOosVPGjiNY98XFC3SwnsKIBhDx8twKWFnl X-Received: by 2002:a05:6a21:6da3:b0:18c:1e48:366b with SMTP id wl35-20020a056a216da300b0018c1e48366bmr11143043pzb.48.1701116963101; Mon, 27 Nov 2023 12:29:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701116963; cv=none; d=google.com; s=arc-20160816; b=b3uMv4Wvl184evFEEndUsU47BzY9UVweOiTH/ZwbfF3aM5JDm5wlfINLUepnHUeD89 bJKz4eMVWFRicCaDs46e1Yq6aBaRV0cF9PRcxim2meDW8/XYo4PMyZLdPVWfk/zR7/UV D1whwIjkVosygSLzBASu12/XWRzcOnYztJWbQftRZwjNqm2+8B05nSfqDtqchocwD+um WCvHNR4/K7KyuNvRl1tAkoPvrcMi/Qqkp86D7n2BS37gKxfgvu8hr3caQVb4t7zamE4B h3L+i2L2MhzG7o9zsekFS8NDuXvHrS41xtIB1XyQGo6c899WIwcHKXUzAJ++7919FIEZ P6dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NaVDFylmzyOJ3a+DibfTBguAtr1XUysdNMkxcfGuzpU=; fh=CKy338m5MbqOKLCytkQoYDn9hkoAEvElo6dffmo/qoM=; b=JLNqFFi9v4GNbYDZ5qlzBwTzlHehpm23zCILDw6JqXRLxGjjZ54txq28FikHG5E8x2 RIFuYljaj9E7sfd41uK15jThUzI6U0mcasjTZC7+As9kHjO4t3KJvhwYUx3DCUFpfxFX PvWxt2cqjpgUNZZhDm626c9NOHV35n1gK95+aJN0fpZKXvrYTs9L8gza3hEKOIldc7tz hfGHniEnLsz9M2GF3GURlLY+g3OSeLmiTzfKiwMNzDr9yMxkOtpfYzot/HgFn/wFMNBl 8K63adQ0vIDM51eZM/KcvORzTyPh4NFeSO0GjqiB40J/akG6c395grQwHuxtA/iw3tyU AeMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mX6t8oq3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x66-20020a626345000000b006c34752a6e8si9967867pfb.81.2023.11.27.12.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 12:29:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mX6t8oq3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D9D7D80EFC7F; Mon, 27 Nov 2023 12:29:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233216AbjK0U2n (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Mon, 27 Nov 2023 15:28:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233484AbjK0U15 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 27 Nov 2023 15:27:57 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D821BE7; Mon, 27 Nov 2023 12:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701116862; x=1732652862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TK9VRQxhG3Ny0okkrMLHhbwPwo5SeI8SZGAn1uUjrJo=; b=mX6t8oq3OGueMOOiRCjSE3aGLh00/tsPzR8fI/vZGNYZaJzJvxvy/xbC t5gS39al3scujzFOj9kuAgt4cbtZBtyRdr9NyTEbo9Oq7jybZ86+h6mFR PR3+M1PNVUZ5KeuPy6iotlVIRkgTm7azqFChcG9/xTKKIj4g0k94SnKnp d/LPQRIOk7d33jYh+Uoq2PBTEB0J4A5LY6c2k7zwwNe9Z1IuiHBvXV7cS rMfGQa+jwdBgdL4x5LzicTPNnaJjQG+xhKQ/HjmPbyLzIF50xEE436e/b 7CgQ+uz4Ycuz6bzEdEUKykIhE6oAhSE+3euIb2E3QndrTN/XkxbD6lD3U Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="457115656" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="457115656" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 12:27:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="16394586" Received: from rpkulapa-mobl.amr.corp.intel.com (HELO tzanussi-mobl1.hsd1.il.comcast.net) ([10.213.183.92]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 12:27:41 -0800 From: Tom Zanussi <tom.zanussi@linux.intel.com> To: herbert@gondor.apana.org.au, davem@davemloft.net, fenghua.yu@intel.com, vkoul@kernel.org Cc: dave.jiang@intel.com, tony.luck@intel.com, wajdi.k.feghali@intel.com, james.guilford@intel.com, kanchana.p.sridhar@intel.com, vinodh.gopal@intel.com, giovanni.cabiddu@intel.com, pavel@ucw.cz, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, dmaengine@vger.kernel.org Subject: [PATCH v10 14/14] dmaengine: idxd: Add support for device/wq defaults Date: Mon, 27 Nov 2023 14:27:04 -0600 Message-Id: <20231127202704.1263376-15-tom.zanussi@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127202704.1263376-1-tom.zanussi@linux.intel.com> References: <20231127202704.1263376-1-tom.zanussi@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 27 Nov 2023 12:29:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783750420419076761 X-GMAIL-MSGID: 1783750420419076761 |
Series |
crypto: Add Intel Analytics Accelerator (IAA) crypto compression driver
|
|
Commit Message
Tom Zanussi
Nov. 27, 2023, 8:27 p.m. UTC
Add a load_device_defaults() function pointer to struct
idxd_driver_data, which if defined, will be called when an idxd device
is probed and will allow the idxd device to be configured with default
values.
The load_device_defaults() function is passed an idxd device to work
with to set specific device attributes.
Also add a load_device_defaults() implementation IAA devices; future
patches would add default functions for other device types such as
DSA.
The way idxd device probing works, if the device configuration is
valid at that point e.g. at least one workqueue and engine is properly
configured then the device will be enabled and ready to go.
The IAA implementation, idxd_load_iaa_device_defaults(), configures a
single workqueue (wq0) for each device with the following default
values:
mode "dedicated"
threshold 0
size 16
priority 10
type IDXD_WQT_KERNEL
group 0
name "iaa_crypto"
driver_name "crypto"
Note that this now adds another configuration step for any users that
want to configure their own devices/workqueus with something different
in that they'll first need to disable (in the case of IAA) wq0 and the
device itself before they can set their own attributes and re-enable,
since they've been already been auto-enabled. Note also that in order
for the new configuration to be applied to the deflate-iaa crypto
algorithm the iaa_crypto module needs to unregister the old version,
which is accomplished by removing the iaa_crypto module, and
re-registering it with the new configuration by reinserting the
iaa_crypto module.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
drivers/dma/idxd/Makefile | 2 +-
drivers/dma/idxd/defaults.c | 53 +++++++++++++++++++++++++++++++++++++
drivers/dma/idxd/idxd.h | 4 +++
drivers/dma/idxd/init.c | 7 +++++
4 files changed, 65 insertions(+), 1 deletion(-)
create mode 100644 drivers/dma/idxd/defaults.c
Comments
On 11/27/23 13:27, Tom Zanussi wrote: > Add a load_device_defaults() function pointer to struct > idxd_driver_data, which if defined, will be called when an idxd device > is probed and will allow the idxd device to be configured with default > values. > > The load_device_defaults() function is passed an idxd device to work > with to set specific device attributes. > > Also add a load_device_defaults() implementation IAA devices; future > patches would add default functions for other device types such as > DSA. > > The way idxd device probing works, if the device configuration is > valid at that point e.g. at least one workqueue and engine is properly > configured then the device will be enabled and ready to go. > > The IAA implementation, idxd_load_iaa_device_defaults(), configures a > single workqueue (wq0) for each device with the following default > values: > > mode "dedicated" > threshold 0 > size 16 > priority 10 > type IDXD_WQT_KERNEL > group 0 > name "iaa_crypto" > driver_name "crypto" > > Note that this now adds another configuration step for any users that > want to configure their own devices/workqueus with something different > in that they'll first need to disable (in the case of IAA) wq0 and the > device itself before they can set their own attributes and re-enable, > since they've been already been auto-enabled. Note also that in order > for the new configuration to be applied to the deflate-iaa crypto > algorithm the iaa_crypto module needs to unregister the old version, > which is accomplished by removing the iaa_crypto module, and > re-registering it with the new configuration by reinserting the > iaa_crypto module. > > Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> > --- > drivers/dma/idxd/Makefile | 2 +- > drivers/dma/idxd/defaults.c | 53 +++++++++++++++++++++++++++++++++++++ > drivers/dma/idxd/idxd.h | 4 +++ > drivers/dma/idxd/init.c | 7 +++++ > 4 files changed, 65 insertions(+), 1 deletion(-) > create mode 100644 drivers/dma/idxd/defaults.c > > diff --git a/drivers/dma/idxd/Makefile b/drivers/dma/idxd/Makefile > index c5e679070e46..2b4a0d406e1e 100644 > --- a/drivers/dma/idxd/Makefile > +++ b/drivers/dma/idxd/Makefile > @@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o > idxd_bus-y := bus.o > > obj-$(CONFIG_INTEL_IDXD) += idxd.o > -idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o > +idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o > > idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.o > > diff --git a/drivers/dma/idxd/defaults.c b/drivers/dma/idxd/defaults.c > new file mode 100644 > index 000000000000..a0c9faad8efe > --- /dev/null > +++ b/drivers/dma/idxd/defaults.c > @@ -0,0 +1,53 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ > +#include <linux/kernel.h> > +#include "idxd.h" > + > +int idxd_load_iaa_device_defaults(struct idxd_device *idxd) > +{ > + struct idxd_engine *engine; > + struct idxd_group *group; > + struct idxd_wq *wq; > + > + if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) > + return 0; > + > + wq = idxd->wqs[0]; > + > + if (wq->state != IDXD_WQ_DISABLED) > + return -EPERM; > + > + /* set mode to "dedicated" */ > + set_bit(WQ_FLAG_DEDICATED, &wq->flags); > + wq->threshold = 0; > + > + /* set size to 16 */ > + wq->size = 16; > + > + /* set priority to 10 */ > + wq->priority = 10; > + > + /* set type to "kernel" */ > + wq->type = IDXD_WQT_KERNEL; > + > + /* set wq group to 0 */ > + group = idxd->groups[0]; > + wq->group = group; > + group->num_wqs++; > + > + /* set name to "iaa_crypto" */ > + memset(wq->name, 0, WQ_NAME_SIZE + 1); > + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1); > + > + /* set driver_name to "crypto" */ > + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); > + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1); > + > + engine = idxd->engines[0]; > + > + /* set engine group to 0 */ > + engine->group = idxd->groups[0]; > + engine->group->num_engines++; > + > + return 0; > +} > diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h > index 62ea21b25906..47de3f93ff1e 100644 > --- a/drivers/dma/idxd/idxd.h > +++ b/drivers/dma/idxd/idxd.h > @@ -277,6 +277,8 @@ struct idxd_dma_dev { > struct dma_device dma; > }; > > +typedef int (*load_device_defaults_fn_t) (struct idxd_device *idxd); > + > struct idxd_driver_data { > const char *name_prefix; > enum idxd_type type; > @@ -286,6 +288,7 @@ struct idxd_driver_data { > int evl_cr_off; > int cr_status_off; > int cr_result_off; > + load_device_defaults_fn_t load_device_defaults; > }; > > struct idxd_evl { > @@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device *idxd); > void idxd_wqs_quiesce(struct idxd_device *idxd); > bool idxd_queue_int_handle_resubmit(struct idxd_desc *desc); > void multi_u64_to_bmap(unsigned long *bmap, u64 *val, int count); > +int idxd_load_iaa_device_defaults(struct idxd_device *idxd); > > /* device interrupt control */ > irqreturn_t idxd_misc_thread(int vec, void *data); > diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c > index 0eb1c827a215..14df1f1347a8 100644 > --- a/drivers/dma/idxd/init.c > +++ b/drivers/dma/idxd/init.c > @@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] = { > .evl_cr_off = offsetof(struct iax_evl_entry, cr), > .cr_status_off = offsetof(struct iax_completion_record, status), > .cr_result_off = offsetof(struct iax_completion_record, error_code), > + .load_device_defaults = idxd_load_iaa_device_defaults, > }, > }; > > @@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) > goto err; > } > > + if (data->load_device_defaults) { > + rc = data->load_device_defaults(idxd); > + if (rc) > + dev_warn(dev, "IDXD loading device defaults failed\n"); > + } > + > rc = idxd_register_devices(idxd); > if (rc) { > dev_err(dev, "IDXD sysfs setup failed\n");
On Mon, 2023-11-27 at 15:14 -0700, Dave Jiang wrote: > > > On 11/27/23 13:27, Tom Zanussi wrote: > > Add a load_device_defaults() function pointer to struct > > idxd_driver_data, which if defined, will be called when an idxd > > device > > is probed and will allow the idxd device to be configured with > > default > > values. > > > > The load_device_defaults() function is passed an idxd device to > > work > > with to set specific device attributes. > > > > Also add a load_device_defaults() implementation IAA devices; > > future > > patches would add default functions for other device types such as > > DSA. > > > > The way idxd device probing works, if the device configuration is > > valid at that point e.g. at least one workqueue and engine is > > properly > > configured then the device will be enabled and ready to go. > > > > The IAA implementation, idxd_load_iaa_device_defaults(), configures > > a > > single workqueue (wq0) for each device with the following default > > values: > > > > mode "dedicated" > > threshold 0 > > size 16 > > priority 10 > > type IDXD_WQT_KERNEL > > group 0 > > name "iaa_crypto" > > driver_name "crypto" > > > > Note that this now adds another configuration step for any users > > that > > want to configure their own devices/workqueus with something > > different > > in that they'll first need to disable (in the case of IAA) wq0 and > > the > > device itself before they can set their own attributes and re- > > enable, > > since they've been already been auto-enabled. Note also that in > > order > > for the new configuration to be applied to the deflate-iaa crypto > > algorithm the iaa_crypto module needs to unregister the old > > version, > > which is accomplished by removing the iaa_crypto module, and > > re-registering it with the new configuration by reinserting the > > iaa_crypto module. > > > > Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> > > Reviewed-by: Dave Jiang <dave.jiang@intel.com> Thanks, Dave! Tom > > > --- > > drivers/dma/idxd/Makefile | 2 +- > > drivers/dma/idxd/defaults.c | 53 > > +++++++++++++++++++++++++++++++++++++ > > drivers/dma/idxd/idxd.h | 4 +++ > > drivers/dma/idxd/init.c | 7 +++++ > > 4 files changed, 65 insertions(+), 1 deletion(-) > > create mode 100644 drivers/dma/idxd/defaults.c > > > > diff --git a/drivers/dma/idxd/Makefile b/drivers/dma/idxd/Makefile > > index c5e679070e46..2b4a0d406e1e 100644 > > --- a/drivers/dma/idxd/Makefile > > +++ b/drivers/dma/idxd/Makefile > > @@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o > > idxd_bus-y := bus.o > > > > obj-$(CONFIG_INTEL_IDXD) += idxd.o > > -idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o > > debugfs.o > > +idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o > > debugfs.o defaults.o > > > > idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.o > > > > diff --git a/drivers/dma/idxd/defaults.c > > b/drivers/dma/idxd/defaults.c > > new file mode 100644 > > index 000000000000..a0c9faad8efe > > --- /dev/null > > +++ b/drivers/dma/idxd/defaults.c > > @@ -0,0 +1,53 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ > > +#include <linux/kernel.h> > > +#include "idxd.h" > > + > > +int idxd_load_iaa_device_defaults(struct idxd_device *idxd) > > +{ > > + struct idxd_engine *engine; > > + struct idxd_group *group; > > + struct idxd_wq *wq; > > + > > + if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) > > + return 0; > > + > > + wq = idxd->wqs[0]; > > + > > + if (wq->state != IDXD_WQ_DISABLED) > > + return -EPERM; > > + > > + /* set mode to "dedicated" */ > > + set_bit(WQ_FLAG_DEDICATED, &wq->flags); > > + wq->threshold = 0; > > + > > + /* set size to 16 */ > > + wq->size = 16; > > + > > + /* set priority to 10 */ > > + wq->priority = 10; > > + > > + /* set type to "kernel" */ > > + wq->type = IDXD_WQT_KERNEL; > > + > > + /* set wq group to 0 */ > > + group = idxd->groups[0]; > > + wq->group = group; > > + group->num_wqs++; > > + > > + /* set name to "iaa_crypto" */ > > + memset(wq->name, 0, WQ_NAME_SIZE + 1); > > + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1); > > + > > + /* set driver_name to "crypto" */ > > + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); > > + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1); > > + > > + engine = idxd->engines[0]; > > + > > + /* set engine group to 0 */ > > + engine->group = idxd->groups[0]; > > + engine->group->num_engines++; > > + > > + return 0; > > +} > > diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h > > index 62ea21b25906..47de3f93ff1e 100644 > > --- a/drivers/dma/idxd/idxd.h > > +++ b/drivers/dma/idxd/idxd.h > > @@ -277,6 +277,8 @@ struct idxd_dma_dev { > > struct dma_device dma; > > }; > > > > +typedef int (*load_device_defaults_fn_t) (struct idxd_device > > *idxd); > > + > > struct idxd_driver_data { > > const char *name_prefix; > > enum idxd_type type; > > @@ -286,6 +288,7 @@ struct idxd_driver_data { > > int evl_cr_off; > > int cr_status_off; > > int cr_result_off; > > + load_device_defaults_fn_t load_device_defaults; > > }; > > > > struct idxd_evl { > > @@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device > > *idxd); > > void idxd_wqs_quiesce(struct idxd_device *idxd); > > bool idxd_queue_int_handle_resubmit(struct idxd_desc *desc); > > void multi_u64_to_bmap(unsigned long *bmap, u64 *val, int count); > > +int idxd_load_iaa_device_defaults(struct idxd_device *idxd); > > > > /* device interrupt control */ > > irqreturn_t idxd_misc_thread(int vec, void *data); > > diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c > > index 0eb1c827a215..14df1f1347a8 100644 > > --- a/drivers/dma/idxd/init.c > > +++ b/drivers/dma/idxd/init.c > > @@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] > > = { > > .evl_cr_off = offsetof(struct iax_evl_entry, cr), > > .cr_status_off = offsetof(struct > > iax_completion_record, status), > > .cr_result_off = offsetof(struct > > iax_completion_record, error_code), > > + .load_device_defaults = > > idxd_load_iaa_device_defaults, > > }, > > }; > > > > @@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev > > *pdev, const struct pci_device_id *id) > > goto err; > > } > > > > + if (data->load_device_defaults) { > > + rc = data->load_device_defaults(idxd); > > + if (rc) > > + dev_warn(dev, "IDXD loading device defaults > > failed\n"); > > + } > > + > > rc = idxd_register_devices(idxd); > > if (rc) { > > dev_err(dev, "IDXD sysfs setup failed\n");
Hi, Tom, On 11/27/23 12:27, Tom Zanussi wrote: > Add a load_device_defaults() function pointer to struct > idxd_driver_data, which if defined, will be called when an idxd device > is probed and will allow the idxd device to be configured with default > values. > > The load_device_defaults() function is passed an idxd device to work > with to set specific device attributes. > > Also add a load_device_defaults() implementation IAA devices; future > patches would add default functions for other device types such as > DSA. > > The way idxd device probing works, if the device configuration is > valid at that point e.g. at least one workqueue and engine is properly > configured then the device will be enabled and ready to go. > > The IAA implementation, idxd_load_iaa_device_defaults(), configures a > single workqueue (wq0) for each device with the following default > values: > > mode "dedicated" > threshold 0 > size 16 Why is it 16? If wqcap supports less than 16, configuring wq size 16 will fail. If wqcap supports more than 16, wq size 16 uses less wq size than capable and less performance. Is it better to set wq size as total wq size reported in wqcap? > priority 10 > type IDXD_WQT_KERNEL > group 0 > name "iaa_crypto" > driver_name "crypto" > > Note that this now adds another configuration step for any users that > want to configure their own devices/workqueus with something different > in that they'll first need to disable (in the case of IAA) wq0 and the > device itself before they can set their own attributes and re-enable, > since they've been already been auto-enabled. Note also that in order > for the new configuration to be applied to the deflate-iaa crypto > algorithm the iaa_crypto module needs to unregister the old version, > which is accomplished by removing the iaa_crypto module, and > re-registering it with the new configuration by reinserting the > iaa_crypto module. > > Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> > --- > drivers/dma/idxd/Makefile | 2 +- > drivers/dma/idxd/defaults.c | 53 +++++++++++++++++++++++++++++++++++++ > drivers/dma/idxd/idxd.h | 4 +++ > drivers/dma/idxd/init.c | 7 +++++ > 4 files changed, 65 insertions(+), 1 deletion(-) > create mode 100644 drivers/dma/idxd/defaults.c > > diff --git a/drivers/dma/idxd/Makefile b/drivers/dma/idxd/Makefile > index c5e679070e46..2b4a0d406e1e 100644 > --- a/drivers/dma/idxd/Makefile > +++ b/drivers/dma/idxd/Makefile > @@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o > idxd_bus-y := bus.o > > obj-$(CONFIG_INTEL_IDXD) += idxd.o > -idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o > +idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o > > idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.o > > diff --git a/drivers/dma/idxd/defaults.c b/drivers/dma/idxd/defaults.c > new file mode 100644 > index 000000000000..a0c9faad8efe > --- /dev/null > +++ b/drivers/dma/idxd/defaults.c > @@ -0,0 +1,53 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ > +#include <linux/kernel.h> > +#include "idxd.h" > + > +int idxd_load_iaa_device_defaults(struct idxd_device *idxd) > +{ > + struct idxd_engine *engine; > + struct idxd_group *group; > + struct idxd_wq *wq; > + > + if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) > + return 0; > + > + wq = idxd->wqs[0]; > + > + if (wq->state != IDXD_WQ_DISABLED) > + return -EPERM; > + > + /* set mode to "dedicated" */ > + set_bit(WQ_FLAG_DEDICATED, &wq->flags); > + wq->threshold = 0; > + > + /* set size to 16 */ > + wq->size = 16; > + > + /* set priority to 10 */ > + wq->priority = 10; > + > + /* set type to "kernel" */ > + wq->type = IDXD_WQT_KERNEL; > + > + /* set wq group to 0 */ > + group = idxd->groups[0]; > + wq->group = group; > + group->num_wqs++; > + > + /* set name to "iaa_crypto" */ > + memset(wq->name, 0, WQ_NAME_SIZE + 1); > + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1); Is strcpy(wq->name, "iaa_crypto") simpler than memset() and strscpy()? > + > + /* set driver_name to "crypto" */ > + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); > + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1); Is strcpy(wq->driver_name, "crypto") simpler? > + > + engine = idxd->engines[0]; > + > + /* set engine group to 0 */ > + engine->group = idxd->groups[0]; > + engine->group->num_engines++; > + > + return 0; > +} > diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h > index 62ea21b25906..47de3f93ff1e 100644 > --- a/drivers/dma/idxd/idxd.h > +++ b/drivers/dma/idxd/idxd.h > @@ -277,6 +277,8 @@ struct idxd_dma_dev { > struct dma_device dma; > }; > > +typedef int (*load_device_defaults_fn_t) (struct idxd_device *idxd); > + > struct idxd_driver_data { > const char *name_prefix; > enum idxd_type type; > @@ -286,6 +288,7 @@ struct idxd_driver_data { > int evl_cr_off; > int cr_status_off; > int cr_result_off; > + load_device_defaults_fn_t load_device_defaults; > }; > > struct idxd_evl { > @@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device *idxd); > void idxd_wqs_quiesce(struct idxd_device *idxd); > bool idxd_queue_int_handle_resubmit(struct idxd_desc *desc); > void multi_u64_to_bmap(unsigned long *bmap, u64 *val, int count); > +int idxd_load_iaa_device_defaults(struct idxd_device *idxd); > > /* device interrupt control */ > irqreturn_t idxd_misc_thread(int vec, void *data); > diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c > index 0eb1c827a215..14df1f1347a8 100644 > --- a/drivers/dma/idxd/init.c > +++ b/drivers/dma/idxd/init.c > @@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] = { > .evl_cr_off = offsetof(struct iax_evl_entry, cr), > .cr_status_off = offsetof(struct iax_completion_record, status), > .cr_result_off = offsetof(struct iax_completion_record, error_code), > + .load_device_defaults = idxd_load_iaa_device_defaults, > }, > }; > > @@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) > goto err; > } > > + if (data->load_device_defaults) { > + rc = data->load_device_defaults(idxd); > + if (rc) > + dev_warn(dev, "IDXD loading device defaults failed\n"); > + } > + > rc = idxd_register_devices(idxd); > if (rc) { > dev_err(dev, "IDXD sysfs setup failed\n"); Thanks. -Fenghua
Hi Fenghua, On Tue, 2023-11-28 at 12:31 -0800, Fenghua Yu wrote: > Hi, Tom, > > On 11/27/23 12:27, Tom Zanussi wrote: > > Add a load_device_defaults() function pointer to struct > > idxd_driver_data, which if defined, will be called when an idxd > > device > > is probed and will allow the idxd device to be configured with > > default > > values. > > > > The load_device_defaults() function is passed an idxd device to > > work > > with to set specific device attributes. > > > > Also add a load_device_defaults() implementation IAA devices; > > future > > patches would add default functions for other device types such as > > DSA. > > > > The way idxd device probing works, if the device configuration is > > valid at that point e.g. at least one workqueue and engine is > > properly > > configured then the device will be enabled and ready to go. > > > > The IAA implementation, idxd_load_iaa_device_defaults(), configures > > a > > single workqueue (wq0) for each device with the following default > > values: > > > > mode "dedicated" > > threshold 0 > > size 16 > > Why is it 16? > > If wqcap supports less than 16, configuring wq size 16 will fail. > If wqcap supports more than 16, wq size 16 uses less wq size than > capable and less performance. > > Is it better to set wq size as total wq size reported in wqcap? Yes, good point. I'll calculate this based on wqcap. > > priority 10 > > type IDXD_WQT_KERNEL > > group 0 > > name "iaa_crypto" > > driver_name "crypto" > > > > Note that this now adds another configuration step for any users > > that > > want to configure their own devices/workqueus with something > > different > > in that they'll first need to disable (in the case of IAA) wq0 and > > the > > device itself before they can set their own attributes and re- > > enable, > > since they've been already been auto-enabled. Note also that in > > order > > for the new configuration to be applied to the deflate-iaa crypto > > algorithm the iaa_crypto module needs to unregister the old > > version, > > which is accomplished by removing the iaa_crypto module, and > > re-registering it with the new configuration by reinserting the > > iaa_crypto module. > > > > Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> > > --- > > drivers/dma/idxd/Makefile | 2 +- > > drivers/dma/idxd/defaults.c | 53 > > +++++++++++++++++++++++++++++++++++++ > > drivers/dma/idxd/idxd.h | 4 +++ > > drivers/dma/idxd/init.c | 7 +++++ > > 4 files changed, 65 insertions(+), 1 deletion(-) > > create mode 100644 drivers/dma/idxd/defaults.c > > > > diff --git a/drivers/dma/idxd/Makefile b/drivers/dma/idxd/Makefile > > index c5e679070e46..2b4a0d406e1e 100644 > > --- a/drivers/dma/idxd/Makefile > > +++ b/drivers/dma/idxd/Makefile > > @@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o > > idxd_bus-y := bus.o > > > > obj-$(CONFIG_INTEL_IDXD) += idxd.o > > -idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o > > debugfs.o > > +idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o > > debugfs.o defaults.o > > > > idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.o > > > > diff --git a/drivers/dma/idxd/defaults.c > > b/drivers/dma/idxd/defaults.c > > new file mode 100644 > > index 000000000000..a0c9faad8efe > > --- /dev/null > > +++ b/drivers/dma/idxd/defaults.c > > @@ -0,0 +1,53 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ > > +#include <linux/kernel.h> > > +#include "idxd.h" > > + > > +int idxd_load_iaa_device_defaults(struct idxd_device *idxd) > > +{ > > + struct idxd_engine *engine; > > + struct idxd_group *group; > > + struct idxd_wq *wq; > > + > > + if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) > > + return 0; > > + > > + wq = idxd->wqs[0]; > > + > > + if (wq->state != IDXD_WQ_DISABLED) > > + return -EPERM; > > + > > + /* set mode to "dedicated" */ > > + set_bit(WQ_FLAG_DEDICATED, &wq->flags); > > + wq->threshold = 0; > > + > > + /* set size to 16 */ > > + wq->size = 16; > > + > > + /* set priority to 10 */ > > + wq->priority = 10; > > + > > + /* set type to "kernel" */ > > + wq->type = IDXD_WQT_KERNEL; > > + > > + /* set wq group to 0 */ > > + group = idxd->groups[0]; > > + wq->group = group; > > + group->num_wqs++; > > + > > + /* set name to "iaa_crypto" */ > > + memset(wq->name, 0, WQ_NAME_SIZE + 1); > > + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1); > > Is strcpy(wq->name, "iaa_crypto") simpler than memset() and > strscpy()? That's what I originally had, but checkpatch complained about it, suggesting strscpy, so I changed it to make checkpatch happy. > > > + > > + /* set driver_name to "crypto" */ > > + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); > > + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1); > > Is strcpy(wq->driver_name, "crypto") simpler? Same here. Thanks, Tom > > > + > > + engine = idxd->engines[0]; > > + > > + /* set engine group to 0 */ > > + engine->group = idxd->groups[0]; > > + engine->group->num_engines++; > > + > > + return 0; > > +} > > diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h > > index 62ea21b25906..47de3f93ff1e 100644 > > --- a/drivers/dma/idxd/idxd.h > > +++ b/drivers/dma/idxd/idxd.h > > @@ -277,6 +277,8 @@ struct idxd_dma_dev { > > struct dma_device dma; > > }; > > > > +typedef int (*load_device_defaults_fn_t) (struct idxd_device > > *idxd); > > + > > struct idxd_driver_data { > > const char *name_prefix; > > enum idxd_type type; > > @@ -286,6 +288,7 @@ struct idxd_driver_data { > > int evl_cr_off; > > int cr_status_off; > > int cr_result_off; > > + load_device_defaults_fn_t load_device_defaults; > > }; > > > > struct idxd_evl { > > @@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device > > *idxd); > > void idxd_wqs_quiesce(struct idxd_device *idxd); > > bool idxd_queue_int_handle_resubmit(struct idxd_desc *desc); > > void multi_u64_to_bmap(unsigned long *bmap, u64 *val, int count); > > +int idxd_load_iaa_device_defaults(struct idxd_device *idxd); > > > > /* device interrupt control */ > > irqreturn_t idxd_misc_thread(int vec, void *data); > > diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c > > index 0eb1c827a215..14df1f1347a8 100644 > > --- a/drivers/dma/idxd/init.c > > +++ b/drivers/dma/idxd/init.c > > @@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] > > = { > > .evl_cr_off = offsetof(struct iax_evl_entry, cr), > > .cr_status_off = offsetof(struct > > iax_completion_record, status), > > .cr_result_off = offsetof(struct > > iax_completion_record, error_code), > > + .load_device_defaults = > > idxd_load_iaa_device_defaults, > > }, > > }; > > > > @@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev > > *pdev, const struct pci_device_id *id) > > goto err; > > } > > > > + if (data->load_device_defaults) { > > + rc = data->load_device_defaults(idxd); > > + if (rc) > > + dev_warn(dev, "IDXD loading device defaults > > failed\n"); > > + } > > + > > rc = idxd_register_devices(idxd); > > if (rc) { > > dev_err(dev, "IDXD sysfs setup failed\n"); > > Thanks. > > -Fenghua
Hi, Tom, > From: Tom Zanussi <tom.zanussi@linux.intel.com> > > > + /* set name to "iaa_crypto" */ > > > + memset(wq->name, 0, WQ_NAME_SIZE + 1); > > > + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1); > > > > Is strcpy(wq->name, "iaa_crypto") simpler than memset() and strscpy()? > > That's what I originally had, but checkpatch complained about it, suggesting > strscpy, so I changed it to make checkpatch happy. Why is size WQ_NAME_SIZE+1 instead of WQ_NAME_SIZE? Will WQ_NAME_SIZE+1 cause mem corruption because wq->name is defined as a string with WQ_NAME_SIZE? > > > > > > + > > > + /* set driver_name to "crypto" */ > > > + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); > > > + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1); > > > > Is strcpy(wq->driver_name, "crypto") simpler? > > Same here. Ditto. Thanks. -Fenghua
Hi Fenghua, On Thu, 2023-11-30 at 00:31 +0000, Yu, Fenghua wrote: > Hi, Tom, > > > From: Tom Zanussi <tom.zanussi@linux.intel.com> > > > > + /* set name to "iaa_crypto" */ > > > > + memset(wq->name, 0, WQ_NAME_SIZE + 1); > > > > + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1); > > > > > > Is strcpy(wq->name, "iaa_crypto") simpler than memset() and > > > strscpy()? > > > > That's what I originally had, but checkpatch complained about it, > > suggesting > > strscpy, so I changed it to make checkpatch happy. > > Why is size WQ_NAME_SIZE+1 instead of WQ_NAME_SIZE? Will > WQ_NAME_SIZE+1 cause mem corruption because wq->name is defined as a > string with WQ_NAME_SIZE? No, wq->name actually is: char name[WQ_NAME_SIZE + 1]; This code is doing the same thing as elsewhere in the idxd driver except instead of sprintf() it uses strscpy(). > > > > > > > > > + > > > > + /* set driver_name to "crypto" */ > > > > + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); > > > > + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + > > > > 1); > > > > > > Is strcpy(wq->driver_name, "crypto") simpler? > > > > Same here. > > Ditto. > Same. Tom > Thanks. > > -Fenghua
diff --git a/drivers/dma/idxd/Makefile b/drivers/dma/idxd/Makefile index c5e679070e46..2b4a0d406e1e 100644 --- a/drivers/dma/idxd/Makefile +++ b/drivers/dma/idxd/Makefile @@ -4,7 +4,7 @@ obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o idxd_bus-y := bus.o obj-$(CONFIG_INTEL_IDXD) += idxd.o -idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o +idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.o diff --git a/drivers/dma/idxd/defaults.c b/drivers/dma/idxd/defaults.c new file mode 100644 index 000000000000..a0c9faad8efe --- /dev/null +++ b/drivers/dma/idxd/defaults.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2023 Intel Corporation. All rights rsvd. */ +#include <linux/kernel.h> +#include "idxd.h" + +int idxd_load_iaa_device_defaults(struct idxd_device *idxd) +{ + struct idxd_engine *engine; + struct idxd_group *group; + struct idxd_wq *wq; + + if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) + return 0; + + wq = idxd->wqs[0]; + + if (wq->state != IDXD_WQ_DISABLED) + return -EPERM; + + /* set mode to "dedicated" */ + set_bit(WQ_FLAG_DEDICATED, &wq->flags); + wq->threshold = 0; + + /* set size to 16 */ + wq->size = 16; + + /* set priority to 10 */ + wq->priority = 10; + + /* set type to "kernel" */ + wq->type = IDXD_WQT_KERNEL; + + /* set wq group to 0 */ + group = idxd->groups[0]; + wq->group = group; + group->num_wqs++; + + /* set name to "iaa_crypto" */ + memset(wq->name, 0, WQ_NAME_SIZE + 1); + strscpy(wq->name, "iaa_crypto", WQ_NAME_SIZE + 1); + + /* set driver_name to "crypto" */ + memset(wq->driver_name, 0, DRIVER_NAME_SIZE + 1); + strscpy(wq->driver_name, "crypto", DRIVER_NAME_SIZE + 1); + + engine = idxd->engines[0]; + + /* set engine group to 0 */ + engine->group = idxd->groups[0]; + engine->group->num_engines++; + + return 0; +} diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h index 62ea21b25906..47de3f93ff1e 100644 --- a/drivers/dma/idxd/idxd.h +++ b/drivers/dma/idxd/idxd.h @@ -277,6 +277,8 @@ struct idxd_dma_dev { struct dma_device dma; }; +typedef int (*load_device_defaults_fn_t) (struct idxd_device *idxd); + struct idxd_driver_data { const char *name_prefix; enum idxd_type type; @@ -286,6 +288,7 @@ struct idxd_driver_data { int evl_cr_off; int cr_status_off; int cr_result_off; + load_device_defaults_fn_t load_device_defaults; }; struct idxd_evl { @@ -730,6 +733,7 @@ void idxd_unregister_devices(struct idxd_device *idxd); void idxd_wqs_quiesce(struct idxd_device *idxd); bool idxd_queue_int_handle_resubmit(struct idxd_desc *desc); void multi_u64_to_bmap(unsigned long *bmap, u64 *val, int count); +int idxd_load_iaa_device_defaults(struct idxd_device *idxd); /* device interrupt control */ irqreturn_t idxd_misc_thread(int vec, void *data); diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 0eb1c827a215..14df1f1347a8 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -59,6 +59,7 @@ static struct idxd_driver_data idxd_driver_data[] = { .evl_cr_off = offsetof(struct iax_evl_entry, cr), .cr_status_off = offsetof(struct iax_completion_record, status), .cr_result_off = offsetof(struct iax_completion_record, error_code), + .load_device_defaults = idxd_load_iaa_device_defaults, }, }; @@ -745,6 +746,12 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto err; } + if (data->load_device_defaults) { + rc = data->load_device_defaults(idxd); + if (rc) + dev_warn(dev, "IDXD loading device defaults failed\n"); + } + rc = idxd_register_devices(idxd); if (rc) { dev_err(dev, "IDXD sysfs setup failed\n");