2020-11-13 16:46:43 +00:00
|
|
|
// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
|
|
|
|
/* Copyright(c) 2020 Intel Corporation */
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
|
|
|
|
#include <adf_accel_devices.h>
|
|
|
|
#include <adf_cfg.h>
|
|
|
|
#include <adf_common_drv.h>
|
2023-05-26 17:48:59 +01:00
|
|
|
#include <adf_dbgfs.h>
|
2023-12-15 05:01:46 -05:00
|
|
|
#include <adf_gen4_config.h>
|
|
|
|
#include <adf_gen4_hw_data.h>
|
2020-11-13 16:46:43 +00:00
|
|
|
|
|
|
|
#include "adf_4xxx_hw_data.h"
|
|
|
|
|
|
|
|
static const struct pci_device_id adf_pci_tbl[] = {
|
2025-04-03 21:07:28 +01:00
|
|
|
{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_QAT_4XXX) },
|
|
|
|
{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_QAT_401XX) },
|
|
|
|
{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_QAT_402XX) },
|
2020-11-13 16:46:43 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, adf_pci_tbl);
|
|
|
|
|
|
|
|
static void adf_cleanup_accel(struct adf_accel_dev *accel_dev)
|
|
|
|
{
|
|
|
|
if (accel_dev->hw_device) {
|
|
|
|
adf_clean_hw_data_4xxx(accel_dev->hw_device);
|
|
|
|
accel_dev->hw_device = NULL;
|
|
|
|
}
|
2023-05-26 17:48:59 +01:00
|
|
|
adf_dbgfs_exit(accel_dev);
|
2020-11-13 16:46:43 +00:00
|
|
|
adf_cfg_dev_remove(accel_dev);
|
|
|
|
adf_devmgr_rm_dev(accel_dev, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
|
|
|
{
|
|
|
|
struct adf_accel_dev *accel_dev;
|
|
|
|
struct adf_accel_pci *accel_pci_dev;
|
|
|
|
struct adf_hw_device_data *hw_data;
|
|
|
|
unsigned int i, bar_nr;
|
|
|
|
unsigned long bar_mask;
|
|
|
|
struct adf_bar *bar;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (num_possible_nodes() > 1 && dev_to_node(&pdev->dev) < 0) {
|
|
|
|
/*
|
|
|
|
* If the accelerator is connected to a node with no memory
|
|
|
|
* there is no point in using the accelerator since the remote
|
|
|
|
* memory transaction will be very slow.
|
|
|
|
*/
|
|
|
|
dev_err(&pdev->dev, "Invalid NUMA configuration.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
accel_dev = devm_kzalloc(&pdev->dev, sizeof(*accel_dev), GFP_KERNEL);
|
|
|
|
if (!accel_dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&accel_dev->crypto_list);
|
|
|
|
accel_pci_dev = &accel_dev->accel_pci_dev;
|
|
|
|
accel_pci_dev->pci_dev = pdev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add accel device to accel table
|
|
|
|
* This should be called before adf_cleanup_accel is called
|
|
|
|
*/
|
|
|
|
if (adf_devmgr_add_dev(accel_dev, NULL)) {
|
|
|
|
dev_err(&pdev->dev, "Failed to add new accelerator device.\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
accel_dev->owner = THIS_MODULE;
|
|
|
|
/* Allocate and initialise device hardware meta-data structure */
|
|
|
|
hw_data = devm_kzalloc(&pdev->dev, sizeof(*hw_data), GFP_KERNEL);
|
|
|
|
if (!hw_data) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
accel_dev->hw_device = hw_data;
|
2023-03-03 17:56:50 +01:00
|
|
|
adf_init_hw_data_4xxx(accel_dev->hw_device, ent->device);
|
2020-11-13 16:46:43 +00:00
|
|
|
|
|
|
|
pci_read_config_byte(pdev, PCI_REVISION_ID, &accel_pci_dev->revid);
|
2025-03-12 11:39:38 +00:00
|
|
|
pci_read_config_dword(pdev, ADF_GEN4_FUSECTL4_OFFSET, &hw_data->fuses[ADF_FUSECTL4]);
|
2020-11-13 16:46:43 +00:00
|
|
|
|
|
|
|
/* Get Accelerators and Accelerators Engines masks */
|
|
|
|
hw_data->accel_mask = hw_data->get_accel_mask(hw_data);
|
|
|
|
hw_data->ae_mask = hw_data->get_ae_mask(hw_data);
|
|
|
|
accel_pci_dev->sku = hw_data->get_sku(hw_data);
|
|
|
|
/* If the device has no acceleration engines then ignore it */
|
|
|
|
if (!hw_data->accel_mask || !hw_data->ae_mask ||
|
|
|
|
(~hw_data->ae_mask & 0x01)) {
|
|
|
|
dev_err(&pdev->dev, "No acceleration units found.\n");
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create device configuration table */
|
|
|
|
ret = adf_cfg_dev_add(accel_dev);
|
|
|
|
if (ret)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Enable PCI device */
|
|
|
|
ret = pcim_enable_device(pdev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Can't enable PCI device.\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set DMA identifier */
|
2021-08-12 09:18:13 +01:00
|
|
|
ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "No usable DMA configuration.\n");
|
|
|
|
goto out_err;
|
2020-11-13 16:46:43 +00:00
|
|
|
}
|
|
|
|
|
2023-12-15 05:01:46 -05:00
|
|
|
ret = adf_gen4_cfg_dev_init(accel_dev);
|
2021-12-16 09:13:34 +00:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Failed to initialize configuration.\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2020-12-01 14:24:51 +00:00
|
|
|
/* Get accelerator capabilities mask */
|
|
|
|
hw_data->accel_capabilities_mask = hw_data->get_accel_cap(accel_dev);
|
2021-12-16 09:13:34 +00:00
|
|
|
if (!hw_data->accel_capabilities_mask) {
|
|
|
|
dev_err(&pdev->dev, "Failed to get capabilities mask.\n");
|
2022-11-21 19:27:34 +08:00
|
|
|
ret = -EINVAL;
|
2021-12-16 09:13:34 +00:00
|
|
|
goto out_err;
|
|
|
|
}
|
2020-12-01 14:24:51 +00:00
|
|
|
|
2020-11-13 16:46:43 +00:00
|
|
|
/* Find and map all the device's BARS */
|
2023-12-15 05:01:46 -05:00
|
|
|
bar_mask = pci_select_bars(pdev, IORESOURCE_MEM) & ADF_GEN4_BAR_MASK;
|
2020-11-13 16:46:43 +00:00
|
|
|
|
2024-10-30 12:27:36 +01:00
|
|
|
ret = pcim_request_all_regions(pdev, pci_name(pdev));
|
2020-11-13 16:46:43 +00:00
|
|
|
if (ret) {
|
2024-10-30 12:27:36 +01:00
|
|
|
dev_err(&pdev->dev, "Failed to request PCI regions.\n");
|
2020-11-13 16:46:43 +00:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for_each_set_bit(bar_nr, &bar_mask, PCI_STD_NUM_BARS) {
|
|
|
|
bar = &accel_pci_dev->pci_bars[i++];
|
2024-10-30 12:27:36 +01:00
|
|
|
bar->virt_addr = pcim_iomap(pdev, bar_nr, 0);
|
|
|
|
if (!bar->virt_addr) {
|
|
|
|
dev_err(&pdev->dev, "Failed to ioremap PCI region.\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2020-11-13 16:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pci_set_master(pdev);
|
|
|
|
|
|
|
|
if (pci_save_state(pdev)) {
|
|
|
|
dev_err(&pdev->dev, "Failed to save pci state.\n");
|
|
|
|
ret = -ENOMEM;
|
2023-03-07 10:19:42 -06:00
|
|
|
goto out_err;
|
2020-11-13 16:46:43 +00:00
|
|
|
}
|
|
|
|
|
2023-10-20 11:32:52 +01:00
|
|
|
accel_dev->ras_errors.enabled = true;
|
2023-05-26 17:48:59 +01:00
|
|
|
adf_dbgfs_init(accel_dev);
|
|
|
|
|
2023-02-27 15:55:43 -05:00
|
|
|
ret = adf_dev_up(accel_dev, true);
|
2020-11-13 16:46:43 +00:00
|
|
|
if (ret)
|
|
|
|
goto out_err_dev_stop;
|
|
|
|
|
2023-02-27 15:55:41 -05:00
|
|
|
ret = adf_sysfs_init(accel_dev);
|
|
|
|
if (ret)
|
|
|
|
goto out_err_dev_stop;
|
|
|
|
|
2020-11-13 16:46:43 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
out_err_dev_stop:
|
2024-07-17 07:44:56 -04:00
|
|
|
adf_dev_down(accel_dev);
|
2020-11-13 16:46:43 +00:00
|
|
|
out_err:
|
|
|
|
adf_cleanup_accel(accel_dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adf_remove(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct adf_accel_dev *accel_dev = adf_devmgr_pci_to_accel_dev(pdev);
|
|
|
|
|
|
|
|
if (!accel_dev) {
|
|
|
|
pr_err("QAT: Driver removal failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2024-07-17 07:44:56 -04:00
|
|
|
adf_dev_down(accel_dev);
|
2020-11-13 16:46:43 +00:00
|
|
|
adf_cleanup_accel(accel_dev);
|
|
|
|
}
|
|
|
|
|
2025-03-26 15:59:46 +00:00
|
|
|
static void adf_shutdown(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct adf_accel_dev *accel_dev = adf_devmgr_pci_to_accel_dev(pdev);
|
|
|
|
|
|
|
|
adf_dev_down(accel_dev);
|
|
|
|
}
|
|
|
|
|
2020-11-13 16:46:43 +00:00
|
|
|
static struct pci_driver adf_driver = {
|
|
|
|
.id_table = adf_pci_tbl,
|
|
|
|
.name = ADF_4XXX_DEVICE_NAME,
|
|
|
|
.probe = adf_probe,
|
|
|
|
.remove = adf_remove,
|
2025-03-26 15:59:46 +00:00
|
|
|
.shutdown = adf_shutdown,
|
2020-11-13 16:46:43 +00:00
|
|
|
.sriov_configure = adf_sriov_configure,
|
2021-10-04 14:59:33 +02:00
|
|
|
.err_handler = &adf_err_handler,
|
2020-11-13 16:46:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module_pci_driver(adf_driver);
|
|
|
|
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
|
MODULE_AUTHOR("Intel");
|
|
|
|
MODULE_FIRMWARE(ADF_4XXX_FW);
|
2024-04-22 15:13:17 +01:00
|
|
|
MODULE_FIRMWARE(ADF_402XX_FW);
|
2020-11-13 16:46:43 +00:00
|
|
|
MODULE_FIRMWARE(ADF_4XXX_MMP);
|
2024-04-22 15:13:17 +01:00
|
|
|
MODULE_FIRMWARE(ADF_402XX_MMP);
|
2020-11-13 16:46:43 +00:00
|
|
|
MODULE_DESCRIPTION("Intel(R) QuickAssist Technology");
|
|
|
|
MODULE_VERSION(ADF_DRV_VERSION);
|
|
|
|
MODULE_SOFTDEP("pre: crypto-intel_qat");
|
module: Convert symbol namespace to string literal
Clean up the existing export namespace code along the same lines of
commit 33def8498fdd ("treewide: Convert macro and uses of __section(foo)
to __section("foo")") and for the same reason, it is not desired for the
namespace argument to be a macro expansion itself.
Scripted using
git grep -l -e MODULE_IMPORT_NS -e EXPORT_SYMBOL_NS | while read file;
do
awk -i inplace '
/^#define EXPORT_SYMBOL_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/^#define MODULE_IMPORT_NS/ {
gsub(/__stringify\(ns\)/, "ns");
print;
next;
}
/MODULE_IMPORT_NS/ {
$0 = gensub(/MODULE_IMPORT_NS\(([^)]*)\)/, "MODULE_IMPORT_NS(\"\\1\")", "g");
}
/EXPORT_SYMBOL_NS/ {
if ($0 ~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+),/) {
if ($0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/ &&
$0 !~ /(EXPORT_SYMBOL_NS[^(]*)\(\)/ &&
$0 !~ /^my/) {
getline line;
gsub(/[[:space:]]*\\$/, "");
gsub(/[[:space:]]/, "", line);
$0 = $0 " " line;
}
$0 = gensub(/(EXPORT_SYMBOL_NS[^(]*)\(([^,]+), ([^)]+)\)/,
"\\1(\\2, \"\\3\")", "g");
}
}
{ print }' $file;
done
Requested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://mail.google.com/mail/u/2/#inbox/FMfcgzQXKWgMmjdFwwdsfgxzKpVHWPlc
Acked-by: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-12-02 15:59:47 +01:00
|
|
|
MODULE_IMPORT_NS("CRYPTO_QAT");
|