]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: qat - reorganize PFVF code
authorMarco Chiappero <marco.chiappero@intel.com>
Wed, 17 Nov 2021 14:30:51 +0000 (14:30 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 26 Nov 2021 05:20:47 +0000 (16:20 +1100)
Reorganize the structure of the PFVF code by moving the content of
adf_pf2vf_msg.c and adf_vf2pf_msg.c.

The logic that handles high level messages has been moved to
adf_pfvf_pf_msg.c and adf_pfvf_vf_msg.c.
The implementation of low level communication primitives and the
protocol is now included in adf_pfvf_pf_proto.c and adf_pfvf_vf_proto.c.

In addition, the file adf_pf2vf_msg.h has been renamed in adf_pfvf_msg.h
since it common to PF and VF and the copyright date for the touched
files has been updated.

Signed-off-by: Marco Chiappero <marco.chiappero@intel.com>
Co-developed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
22 files changed:
drivers/crypto/qat/qat_4xxx/adf_4xxx_hw_data.c
drivers/crypto/qat/qat_c3xxx/adf_c3xxx_hw_data.c
drivers/crypto/qat/qat_c3xxxvf/adf_c3xxxvf_hw_data.c
drivers/crypto/qat/qat_c62x/adf_c62x_hw_data.c
drivers/crypto/qat/qat_c62xvf/adf_c62xvf_hw_data.c
drivers/crypto/qat/qat_common/Makefile
drivers/crypto/qat/qat_common/adf_common_drv.h
drivers/crypto/qat/qat_common/adf_gen2_pfvf.c
drivers/crypto/qat/qat_common/adf_pfvf_msg.h [moved from drivers/crypto/qat/qat_common/adf_pf2vf_msg.h with 96% similarity]
drivers/crypto/qat/qat_common/adf_pfvf_pf_msg.c [new file with mode: 0644]
drivers/crypto/qat/qat_common/adf_pfvf_pf_msg.h [new file with mode: 0644]
drivers/crypto/qat/qat_common/adf_pfvf_pf_proto.c [moved from drivers/crypto/qat/qat_common/adf_pf2vf_msg.c with 53% similarity]
drivers/crypto/qat/qat_common/adf_pfvf_pf_proto.h [new file with mode: 0644]
drivers/crypto/qat/qat_common/adf_pfvf_vf_msg.c [new file with mode: 0644]
drivers/crypto/qat/qat_common/adf_pfvf_vf_msg.h [new file with mode: 0644]
drivers/crypto/qat/qat_common/adf_pfvf_vf_proto.c [new file with mode: 0644]
drivers/crypto/qat/qat_common/adf_pfvf_vf_proto.h [new file with mode: 0644]
drivers/crypto/qat/qat_common/adf_sriov.c
drivers/crypto/qat/qat_common/adf_vf2pf_msg.c [deleted file]
drivers/crypto/qat/qat_common/adf_vf_isr.c
drivers/crypto/qat/qat_dh895xcc/adf_dh895xcc_hw_data.c
drivers/crypto/qat/qat_dh895xccvf/adf_dh895xccvf_hw_data.c

index ec57a2e2d1fcbedc20d7bc8004ff5a3c28b5d3af..2a878d98f81aaf2301e7459a4b56f97b56555b85 100644 (file)
@@ -1,10 +1,10 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2020 Intel Corporation */
+/* Copyright(c) 2020 - 2021 Intel Corporation */
 #include <linux/iopoll.h>
 #include <adf_accel_devices.h>
 #include <adf_common_drv.h>
-#include <adf_pf2vf_msg.h>
 #include <adf_gen4_hw_data.h>
+#include <adf_pfvf_msg.h>
 #include "adf_4xxx_hw_data.h"
 #include "icp_qat_hw.h"
 
index d25f78660b8cb5f798313aa5b2b63d8740c1ee04..94a11e72edae16d1b72e496369bdd0ff7f85b88e 100644 (file)
@@ -1,10 +1,10 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2014 - 2020 Intel Corporation */
+/* Copyright(c) 2014 - 2021 Intel Corporation */
 #include <adf_accel_devices.h>
 #include <adf_common_drv.h>
-#include <adf_pf2vf_msg.h>
 #include <adf_gen2_hw_data.h>
 #include <adf_gen2_pfvf.h>
+#include <adf_pfvf_msg.h>
 #include "adf_c3xxx_hw_data.h"
 #include "icp_qat_hw.h"
 
index c39733320063ab117cc545fdc0c5cbd6f0e92c4d..4c43a0d93fa60f6e1f4a19b2f0df2409667ebff3 100644 (file)
@@ -1,10 +1,11 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2015 - 2020 Intel Corporation */
+/* Copyright(c) 2015 - 2021 Intel Corporation */
 #include <adf_accel_devices.h>
-#include <adf_pf2vf_msg.h>
 #include <adf_common_drv.h>
 #include <adf_gen2_hw_data.h>
 #include <adf_gen2_pfvf.h>
+#include <adf_pfvf_msg.h>
+#include <adf_pfvf_vf_msg.h>
 #include "adf_c3xxxvf_hw_data.h"
 
 static struct adf_hw_device_class c3xxxiov_class = {
index f24a01e1bc1a1272a7e8f40d99c9aba4f3133567..3cb1a88d97aec5d1c3bb0d29f259d7c2159ec162 100644 (file)
@@ -1,10 +1,10 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2014 - 2020 Intel Corporation */
+/* Copyright(c) 2014 - 2021 Intel Corporation */
 #include <adf_accel_devices.h>
 #include <adf_common_drv.h>
-#include <adf_pf2vf_msg.h>
 #include <adf_gen2_hw_data.h>
 #include <adf_gen2_pfvf.h>
+#include <adf_pfvf_msg.h>
 #include "adf_c62x_hw_data.h"
 #include "icp_qat_hw.h"
 
index 03097bbe600a294d128e91406ca70ba62debc3cf..c4b23e2cd57966f211251fbd1bccdeb4c3068462 100644 (file)
@@ -1,10 +1,11 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2015 - 2020 Intel Corporation */
+/* Copyright(c) 2015 - 2021 Intel Corporation */
 #include <adf_accel_devices.h>
-#include <adf_pf2vf_msg.h>
 #include <adf_common_drv.h>
 #include <adf_gen2_hw_data.h>
 #include <adf_gen2_pfvf.h>
+#include <adf_pfvf_msg.h>
+#include <adf_pfvf_vf_msg.h>
 #include "adf_c62xvf_hw_data.h"
 
 static struct adf_hw_device_class c62xiov_class = {
index 676aef6533e0f48a892e764b13776b839dcbe3d3..1376504d16ff74efad96b023b65e5f2455c39536 100644 (file)
@@ -19,6 +19,7 @@ intel_qat-objs := adf_cfg.o \
        qat_hal.o
 
 intel_qat-$(CONFIG_DEBUG_FS) += adf_transport_debug.o
-intel_qat-$(CONFIG_PCI_IOV) += adf_sriov.o adf_pf2vf_msg.o \
-                              adf_vf2pf_msg.o adf_vf_isr.o \
+intel_qat-$(CONFIG_PCI_IOV) += adf_sriov.o adf_vf_isr.o \
+                              adf_pfvf_pf_msg.o adf_pfvf_pf_proto.o \
+                              adf_pfvf_vf_msg.o adf_pfvf_vf_proto.o \
                               adf_gen2_pfvf.o
index c0699e4535027fd82ccf9580ab329421233525ac..2d8b720855054e188e09c9a5b4f8102fd9dbec65 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
-/* Copyright(c) 2014 - 2020 Intel Corporation */
+/* Copyright(c) 2014 - 2021 Intel Corporation */
 #ifndef ADF_DRV_H
 #define ADF_DRV_H
 
@@ -62,8 +62,6 @@ int adf_dev_start(struct adf_accel_dev *accel_dev);
 void adf_dev_stop(struct adf_accel_dev *accel_dev);
 void adf_dev_shutdown(struct adf_accel_dev *accel_dev);
 
-void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev);
-int adf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev);
 void adf_devmgr_update_class_index(struct adf_hw_device_data *hw_data);
 void adf_clean_vf_map(bool);
 
@@ -199,13 +197,9 @@ void adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev,
 bool adf_recv_and_handle_pf2vf_msg(struct adf_accel_dev *accel_dev);
 bool adf_recv_and_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 vf_nr);
 int adf_pf2vf_handle_pf_restarting(struct adf_accel_dev *accel_dev);
-int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev);
 void adf_enable_pf2vf_interrupts(struct adf_accel_dev *accel_dev);
 void adf_disable_pf2vf_interrupts(struct adf_accel_dev *accel_dev);
 void adf_schedule_vf2pf_handler(struct adf_accel_vf_info *vf_info);
-int adf_send_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 msg);
-int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev);
-void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev);
 int adf_init_pf_wq(void);
 void adf_exit_pf_wq(void);
 int adf_init_vf_wq(void);
@@ -214,11 +208,6 @@ void adf_flush_vf_wq(struct adf_accel_dev *accel_dev);
 #else
 #define adf_sriov_configure NULL
 
-static inline int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev)
-{
-       return 0;
-}
-
 static inline void adf_disable_sriov(struct adf_accel_dev *accel_dev)
 {
 }
@@ -231,15 +220,6 @@ static inline void adf_disable_pf2vf_interrupts(struct adf_accel_dev *accel_dev)
 {
 }
 
-static inline int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev)
-{
-       return 0;
-}
-
-static inline void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev)
-{
-}
-
 static inline int adf_init_pf_wq(void)
 {
        return 0;
index f79c3ca28283a195401adc23574572727f28f26e..f3a0a9d651e0d86d70f7ae9c9701d15af9e55996 100644 (file)
@@ -6,7 +6,9 @@
 #include "adf_accel_devices.h"
 #include "adf_common_drv.h"
 #include "adf_gen2_pfvf.h"
-#include "adf_pf2vf_msg.h"
+#include "adf_pfvf_msg.h"
+#include "adf_pfvf_pf_proto.h"
+#include "adf_pfvf_vf_proto.h"
 
  /* VF2PF interrupts */
 #define ADF_GEN2_ERR_REG_VF2PF(vf_src) (((vf_src) & 0x01FFFE00) >> 9)
similarity index 96%
rename from drivers/crypto/qat/qat_common/adf_pf2vf_msg.h
rename to drivers/crypto/qat/qat_common/adf_pfvf_msg.h
index 73eb8f13ad095a20cdd577de77e7d947a1e5aba2..0520466563fd6d6c33cbc8d411ef4a7668236b72 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
-/* Copyright(c) 2015 - 2020 Intel Corporation */
-#ifndef ADF_PF2VF_MSG_H
-#define ADF_PF2VF_MSG_H
+/* Copyright(c) 2015 - 2021 Intel Corporation */
+#ifndef ADF_PFVF_MSG_H
+#define ADF_PFVF_MSG_H
 
 /*
  * PF<->VF Messaging
@@ -91,4 +91,4 @@
 /* VF->PF Compatible Version Request */
 #define ADF_VF2PF_COMPAT_VER_REQ_SHIFT         22
 
-#endif /* ADF_IOV_MSG_H */
+#endif /* ADF_PFVF_MSG_H */
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_pf_msg.c b/drivers/crypto/qat/qat_common/adf_pfvf_pf_msg.c
new file mode 100644 (file)
index 0000000..647b82e
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
+/* Copyright(c) 2015 - 2021 Intel Corporation */
+#include <linux/pci.h>
+#include "adf_accel_devices.h"
+#include "adf_pfvf_msg.h"
+#include "adf_pfvf_pf_msg.h"
+#include "adf_pfvf_pf_proto.h"
+
+void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev)
+{
+       struct adf_accel_vf_info *vf;
+       u32 msg = (ADF_PF2VF_MSGORIGIN_SYSTEM |
+               (ADF_PF2VF_MSGTYPE_RESTARTING << ADF_PF2VF_MSGTYPE_SHIFT));
+       int i, num_vfs = pci_num_vf(accel_to_pci_dev(accel_dev));
+
+       for (i = 0, vf = accel_dev->pf.vf_info; i < num_vfs; i++, vf++) {
+               if (vf->init && adf_send_pf2vf_msg(accel_dev, i, msg))
+                       dev_err(&GET_DEV(accel_dev),
+                               "Failed to send restarting msg to VF%d\n", i);
+       }
+}
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_pf_msg.h b/drivers/crypto/qat/qat_common/adf_pfvf_pf_msg.h
new file mode 100644 (file)
index 0000000..187807b
--- /dev/null
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
+/* Copyright(c) 2021 Intel Corporation */
+#ifndef ADF_PFVF_PF_MSG_H
+#define ADF_PFVF_PF_MSG_H
+
+#include "adf_accel_devices.h"
+
+void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev);
+
+#endif /* ADF_PFVF_PF_MSG_H */
similarity index 53%
rename from drivers/crypto/qat/qat_common/adf_pf2vf_msg.c
rename to drivers/crypto/qat/qat_common/adf_pfvf_pf_proto.c
index c064e8bab50dd09aa1b3cdffe8069104f6fa44fb..ac6a54cf17f6d207b93ac829425a18e4584b8014 100644 (file)
@@ -1,15 +1,11 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2015 - 2020 Intel Corporation */
+/* Copyright(c) 2015 - 2021 Intel Corporation */
+#include <linux/spinlock.h>
+#include <linux/types.h>
 #include "adf_accel_devices.h"
 #include "adf_common_drv.h"
-#include "adf_pf2vf_msg.h"
-
-#define ADF_PFVF_MSG_COLLISION_DETECT_DELAY    10
-#define ADF_PFVF_MSG_ACK_DELAY                 2
-#define ADF_PFVF_MSG_ACK_MAX_RETRY             100
-#define ADF_PFVF_MSG_RESP_TIMEOUT      (ADF_PFVF_MSG_ACK_DELAY * \
-                                        ADF_PFVF_MSG_ACK_MAX_RETRY + \
-                                        ADF_PFVF_MSG_COLLISION_DETECT_DELAY)
+#include "adf_pfvf_msg.h"
+#include "adf_pfvf_pf_proto.h"
 
 /**
  * adf_send_pf2vf_msg() - send PF to VF message
  *
  * Return: 0 on success, error code otherwise.
  */
-static int adf_send_pf2vf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr, u32 msg)
+int adf_send_pf2vf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr, u32 msg)
 {
        return GET_PFVF_OPS(accel_dev)->send_msg(accel_dev, msg, vf_nr);
 }
 
-/**
- * adf_send_vf2pf_msg() - send VF to PF message
- * @accel_dev: Pointer to acceleration device
- * @msg:       Message to send
- *
- * This function allows the VF to send a message to the PF.
- *
- * Return: 0 on success, error code otherwise.
- */
-int adf_send_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 msg)
-{
-       return GET_PFVF_OPS(accel_dev)->send_msg(accel_dev, msg, 0);
-}
-
 /**
  * adf_recv_vf2pf_msg() - receive a VF to PF message
  * @accel_dev: Pointer to acceleration device
@@ -54,42 +36,6 @@ static u32 adf_recv_vf2pf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr)
        return GET_PFVF_OPS(accel_dev)->recv_msg(accel_dev, vf_nr);
 }
 
-/**
- * adf_send_vf2pf_req() - send VF2PF request message
- * @accel_dev: Pointer to acceleration device.
- * @msg:       Request message to send
- *
- * This function sends a message that requires a response from the VF to the PF
- * and waits for a reply.
- *
- * Return: 0 on success, error code otherwise.
- */
-static int adf_send_vf2pf_req(struct adf_accel_dev *accel_dev, u32 msg)
-{
-       unsigned long timeout = msecs_to_jiffies(ADF_PFVF_MSG_RESP_TIMEOUT);
-       int ret;
-
-       reinit_completion(&accel_dev->vf.iov_msg_completion);
-
-       /* Send request from VF to PF */
-       ret = adf_send_vf2pf_msg(accel_dev, msg);
-       if (ret) {
-               dev_err(&GET_DEV(accel_dev),
-                       "Failed to send request msg to PF\n");
-               return ret;
-       }
-
-       /* Wait for response */
-       if (!wait_for_completion_timeout(&accel_dev->vf.iov_msg_completion,
-                                        timeout)) {
-               dev_err(&GET_DEV(accel_dev),
-                       "PFVF request/response message timeout expired\n");
-               return -EIO;
-       }
-
-       return 0;
-}
-
 static int adf_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 vf_nr,
                                u32 msg, u32 *response)
 {
@@ -193,77 +139,6 @@ bool adf_recv_and_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 vf_nr)
        return true;
 }
 
-void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev)
-{
-       struct adf_accel_vf_info *vf;
-       u32 msg = (ADF_PF2VF_MSGORIGIN_SYSTEM |
-               (ADF_PF2VF_MSGTYPE_RESTARTING << ADF_PF2VF_MSGTYPE_SHIFT));
-       int i, num_vfs = pci_num_vf(accel_to_pci_dev(accel_dev));
-
-       for (i = 0, vf = accel_dev->pf.vf_info; i < num_vfs; i++, vf++) {
-               if (vf->init && adf_send_pf2vf_msg(accel_dev, i, msg))
-                       dev_err(&GET_DEV(accel_dev),
-                               "Failed to send restarting msg to VF%d\n", i);
-       }
-}
-
-static int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev)
-{
-       struct adf_hw_device_data *hw_data = accel_dev->hw_device;
-       u32 msg = 0;
-       int ret;
-
-       msg = ADF_VF2PF_MSGORIGIN_SYSTEM;
-       msg |= ADF_VF2PF_MSGTYPE_COMPAT_VER_REQ << ADF_VF2PF_MSGTYPE_SHIFT;
-       msg |= ADF_PFVF_COMPAT_THIS_VERSION << ADF_VF2PF_COMPAT_VER_REQ_SHIFT;
-       BUILD_BUG_ON(ADF_PFVF_COMPAT_THIS_VERSION > 255);
-
-       ret = adf_send_vf2pf_req(accel_dev, msg);
-       if (ret) {
-               dev_err(&GET_DEV(accel_dev),
-                       "Failed to send Compatibility Version Request.\n");
-               return ret;
-       }
-
-       /* Response from PF received, check compatibility */
-       switch (accel_dev->vf.compatible) {
-       case ADF_PF2VF_VF_COMPATIBLE:
-               break;
-       case ADF_PF2VF_VF_COMPAT_UNKNOWN:
-               /* VF is newer than PF and decides whether it is compatible */
-               if (accel_dev->vf.pf_version >= hw_data->min_iov_compat_ver) {
-                       accel_dev->vf.compatible = ADF_PF2VF_VF_COMPATIBLE;
-                       break;
-               }
-               fallthrough;
-       case ADF_PF2VF_VF_INCOMPATIBLE:
-               dev_err(&GET_DEV(accel_dev),
-                       "PF (vers %d) and VF (vers %d) are not compatible\n",
-                       accel_dev->vf.pf_version,
-                       ADF_PFVF_COMPAT_THIS_VERSION);
-               return -EINVAL;
-       default:
-               dev_err(&GET_DEV(accel_dev),
-                       "Invalid response from PF; assume not compatible\n");
-               return -EINVAL;
-       }
-       return ret;
-}
-
-/**
- * adf_enable_vf2pf_comms() - Function enables communication from vf to pf
- *
- * @accel_dev: Pointer to acceleration device virtual function.
- *
- * Return: 0 on success, error code otherwise.
- */
-int adf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev)
-{
-       adf_enable_pf2vf_interrupts(accel_dev);
-       return adf_vf2pf_request_version(accel_dev);
-}
-EXPORT_SYMBOL_GPL(adf_enable_vf2pf_comms);
-
 /**
  * adf_enable_pf2vf_comms() - Function enables communication from pf to vf
  *
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_pf_proto.h b/drivers/crypto/qat/qat_common/adf_pfvf_pf_proto.h
new file mode 100644 (file)
index 0000000..6324540
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
+/* Copyright(c) 2021 Intel Corporation */
+#ifndef ADF_PFVF_PF_PROTO_H
+#define ADF_PFVF_PF_PROTO_H
+
+#include <linux/types.h>
+#include "adf_accel_devices.h"
+
+int adf_send_pf2vf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr, u32 msg);
+
+int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev);
+
+#endif /* ADF_PFVF_PF_PROTO_H */
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_vf_msg.c b/drivers/crypto/qat/qat_common/adf_pfvf_vf_msg.c
new file mode 100644 (file)
index 0000000..7969a64
--- /dev/null
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
+/* Copyright(c) 2015 - 2021 Intel Corporation */
+#include "adf_accel_devices.h"
+#include "adf_common_drv.h"
+#include "adf_pfvf_msg.h"
+#include "adf_pfvf_vf_msg.h"
+#include "adf_pfvf_vf_proto.h"
+
+/**
+ * adf_vf2pf_notify_init() - send init msg to PF
+ * @accel_dev:  Pointer to acceleration VF device.
+ *
+ * Function sends an init message from the VF to a PF
+ *
+ * Return: 0 on success, error code otherwise.
+ */
+int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev)
+{
+       u32 msg = (ADF_VF2PF_MSGORIGIN_SYSTEM |
+               (ADF_VF2PF_MSGTYPE_INIT << ADF_VF2PF_MSGTYPE_SHIFT));
+
+       if (adf_send_vf2pf_msg(accel_dev, msg)) {
+               dev_err(&GET_DEV(accel_dev),
+                       "Failed to send Init event to PF\n");
+               return -EFAULT;
+       }
+       set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(adf_vf2pf_notify_init);
+
+/**
+ * adf_vf2pf_notify_shutdown() - send shutdown msg to PF
+ * @accel_dev:  Pointer to acceleration VF device.
+ *
+ * Function sends a shutdown message from the VF to a PF
+ *
+ * Return: void
+ */
+void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev)
+{
+       u32 msg = (ADF_VF2PF_MSGORIGIN_SYSTEM |
+           (ADF_VF2PF_MSGTYPE_SHUTDOWN << ADF_VF2PF_MSGTYPE_SHIFT));
+
+       if (test_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status))
+               if (adf_send_vf2pf_msg(accel_dev, msg))
+                       dev_err(&GET_DEV(accel_dev),
+                               "Failed to send Shutdown event to PF\n");
+}
+EXPORT_SYMBOL_GPL(adf_vf2pf_notify_shutdown);
+
+int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev)
+{
+       struct adf_hw_device_data *hw_data = accel_dev->hw_device;
+       u32 msg = 0;
+       int ret;
+
+       msg = ADF_VF2PF_MSGORIGIN_SYSTEM;
+       msg |= ADF_VF2PF_MSGTYPE_COMPAT_VER_REQ << ADF_VF2PF_MSGTYPE_SHIFT;
+       msg |= ADF_PFVF_COMPAT_THIS_VERSION << ADF_VF2PF_COMPAT_VER_REQ_SHIFT;
+       BUILD_BUG_ON(ADF_PFVF_COMPAT_THIS_VERSION > 255);
+
+       ret = adf_send_vf2pf_req(accel_dev, msg);
+       if (ret) {
+               dev_err(&GET_DEV(accel_dev),
+                       "Failed to send Compatibility Version Request.\n");
+               return ret;
+       }
+
+       /* Response from PF received, check compatibility */
+       switch (accel_dev->vf.compatible) {
+       case ADF_PF2VF_VF_COMPATIBLE:
+               break;
+       case ADF_PF2VF_VF_COMPAT_UNKNOWN:
+               /* VF is newer than PF and decides whether it is compatible */
+               if (accel_dev->vf.pf_version >= hw_data->min_iov_compat_ver) {
+                       accel_dev->vf.compatible = ADF_PF2VF_VF_COMPATIBLE;
+                       break;
+               }
+               fallthrough;
+       case ADF_PF2VF_VF_INCOMPATIBLE:
+               dev_err(&GET_DEV(accel_dev),
+                       "PF (vers %d) and VF (vers %d) are not compatible\n",
+                       accel_dev->vf.pf_version,
+                       ADF_PFVF_COMPAT_THIS_VERSION);
+               return -EINVAL;
+       default:
+               dev_err(&GET_DEV(accel_dev),
+                       "Invalid response from PF; assume not compatible\n");
+               return -EINVAL;
+       }
+       return ret;
+}
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_vf_msg.h b/drivers/crypto/qat/qat_common/adf_pfvf_vf_msg.h
new file mode 100644 (file)
index 0000000..5091b5b
--- /dev/null
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
+/* Copyright(c) 2021 Intel Corporation */
+#ifndef ADF_PFVF_VF_MSG_H
+#define ADF_PFVF_VF_MSG_H
+
+#if defined(CONFIG_PCI_IOV)
+int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev);
+void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev);
+int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev);
+#else
+static inline int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev)
+{
+       return 0;
+}
+
+static inline void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev)
+{
+}
+#endif
+
+#endif /* ADF_PFVF_VF_MSG_H */
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_vf_proto.c b/drivers/crypto/qat/qat_common/adf_pfvf_vf_proto.c
new file mode 100644 (file)
index 0000000..62817bc
--- /dev/null
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
+/* Copyright(c) 2015 - 2021 Intel Corporation */
+#include <linux/completion.h>
+#include <linux/types.h>
+#include "adf_accel_devices.h"
+#include "adf_common_drv.h"
+#include "adf_pfvf_msg.h"
+#include "adf_pfvf_vf_msg.h"
+#include "adf_pfvf_vf_proto.h"
+
+#define ADF_PFVF_MSG_COLLISION_DETECT_DELAY    10
+#define ADF_PFVF_MSG_ACK_DELAY                 2
+#define ADF_PFVF_MSG_ACK_MAX_RETRY             100
+
+#define ADF_PFVF_MSG_RESP_TIMEOUT      (ADF_PFVF_MSG_ACK_DELAY * \
+                                        ADF_PFVF_MSG_ACK_MAX_RETRY + \
+                                        ADF_PFVF_MSG_COLLISION_DETECT_DELAY)
+
+/**
+ * adf_send_vf2pf_msg() - send VF to PF message
+ * @accel_dev: Pointer to acceleration device
+ * @msg:       Message to send
+ *
+ * This function allows the VF to send a message to the PF.
+ *
+ * Return: 0 on success, error code otherwise.
+ */
+int adf_send_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 msg)
+{
+       return GET_PFVF_OPS(accel_dev)->send_msg(accel_dev, msg, 0);
+}
+
+/**
+ * adf_recv_pf2vf_msg() - receive a PF to VF message
+ * @accel_dev: Pointer to acceleration device
+ *
+ * This function allows the VF to receive a message from the PF.
+ *
+ * Return: a valid message on success, zero otherwise.
+ */
+static u32 adf_recv_pf2vf_msg(struct adf_accel_dev *accel_dev)
+{
+       return GET_PFVF_OPS(accel_dev)->recv_msg(accel_dev, 0);
+}
+
+/**
+ * adf_send_vf2pf_req() - send VF2PF request message
+ * @accel_dev: Pointer to acceleration device.
+ * @msg:       Request message to send
+ *
+ * This function sends a message that requires a response from the VF to the PF
+ * and waits for a reply.
+ *
+ * Return: 0 on success, error code otherwise.
+ */
+int adf_send_vf2pf_req(struct adf_accel_dev *accel_dev, u32 msg)
+{
+       unsigned long timeout = msecs_to_jiffies(ADF_PFVF_MSG_RESP_TIMEOUT);
+       int ret;
+
+       reinit_completion(&accel_dev->vf.iov_msg_completion);
+
+       /* Send request from VF to PF */
+       ret = adf_send_vf2pf_msg(accel_dev, msg);
+       if (ret) {
+               dev_err(&GET_DEV(accel_dev),
+                       "Failed to send request msg to PF\n");
+               return ret;
+       }
+
+       /* Wait for response */
+       if (!wait_for_completion_timeout(&accel_dev->vf.iov_msg_completion,
+                                        timeout)) {
+               dev_err(&GET_DEV(accel_dev),
+                       "PFVF request/response message timeout expired\n");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+static bool adf_handle_pf2vf_msg(struct adf_accel_dev *accel_dev, u32 msg)
+{
+       switch ((msg & ADF_PF2VF_MSGTYPE_MASK) >> ADF_PF2VF_MSGTYPE_SHIFT) {
+       case ADF_PF2VF_MSGTYPE_RESTARTING:
+               dev_dbg(&GET_DEV(accel_dev),
+                       "Restarting msg received from PF 0x%x\n", msg);
+
+               adf_pf2vf_handle_pf_restarting(accel_dev);
+               return false;
+       case ADF_PF2VF_MSGTYPE_VERSION_RESP:
+               dev_dbg(&GET_DEV(accel_dev),
+                       "Version resp received from PF 0x%x\n", msg);
+               accel_dev->vf.pf_version =
+                       (msg & ADF_PF2VF_VERSION_RESP_VERS_MASK) >>
+                       ADF_PF2VF_VERSION_RESP_VERS_SHIFT;
+               accel_dev->vf.compatible =
+                       (msg & ADF_PF2VF_VERSION_RESP_RESULT_MASK) >>
+                       ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
+               complete(&accel_dev->vf.iov_msg_completion);
+               return true;
+       default:
+               dev_err(&GET_DEV(accel_dev),
+                       "Unknown PF2VF message(0x%x)\n", msg);
+       }
+
+       return false;
+}
+
+bool adf_recv_and_handle_pf2vf_msg(struct adf_accel_dev *accel_dev)
+{
+       u32 msg;
+
+       msg = adf_recv_pf2vf_msg(accel_dev);
+       if (msg)
+               return adf_handle_pf2vf_msg(accel_dev, msg);
+
+       return true;
+}
+
+/**
+ * adf_enable_vf2pf_comms() - Function enables communication from vf to pf
+ *
+ * @accel_dev: Pointer to acceleration device virtual function.
+ *
+ * Return: 0 on success, error code otherwise.
+ */
+int adf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev)
+{
+       adf_enable_pf2vf_interrupts(accel_dev);
+       return adf_vf2pf_request_version(accel_dev);
+}
+EXPORT_SYMBOL_GPL(adf_enable_vf2pf_comms);
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_vf_proto.h b/drivers/crypto/qat/qat_common/adf_pfvf_vf_proto.h
new file mode 100644 (file)
index 0000000..a3ab24c
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
+/* Copyright(c) 2021 Intel Corporation */
+#ifndef ADF_PFVF_VF_PROTO_H
+#define ADF_PFVF_VF_PROTO_H
+
+#include <linux/types.h>
+#include "adf_accel_devices.h"
+
+int adf_send_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 msg);
+int adf_send_vf2pf_req(struct adf_accel_dev *accel_dev, u32 msg);
+
+int adf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev);
+
+#endif /* ADF_PFVF_VF_PROTO_H */
index 342063406c1964329f3298e2df10c083b667bbea..429990c5e0f34c5afec813ad300f8b25ed937945 100644 (file)
@@ -1,12 +1,12 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2015 - 2020 Intel Corporation */
+/* Copyright(c) 2015 - 2021 Intel Corporation */
 #include <linux/workqueue.h>
 #include <linux/pci.h>
 #include <linux/device.h>
 #include <linux/iommu.h>
 #include "adf_common_drv.h"
 #include "adf_cfg.h"
-#include "adf_pf2vf_msg.h"
+#include "adf_pfvf_pf_msg.h"
 
 static struct workqueue_struct *pf2vf_resp_wq;
 
diff --git a/drivers/crypto/qat/qat_common/adf_vf2pf_msg.c b/drivers/crypto/qat/qat_common/adf_vf2pf_msg.c
deleted file mode 100644 (file)
index f366098..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2015 - 2020 Intel Corporation */
-#include "adf_accel_devices.h"
-#include "adf_common_drv.h"
-#include "adf_pf2vf_msg.h"
-
-/**
- * adf_vf2pf_notify_init() - send init msg to PF
- * @accel_dev:  Pointer to acceleration VF device.
- *
- * Function sends an init message from the VF to a PF
- *
- * Return: 0 on success, error code otherwise.
- */
-int adf_vf2pf_notify_init(struct adf_accel_dev *accel_dev)
-{
-       u32 msg = (ADF_VF2PF_MSGORIGIN_SYSTEM |
-               (ADF_VF2PF_MSGTYPE_INIT << ADF_VF2PF_MSGTYPE_SHIFT));
-
-       if (adf_send_vf2pf_msg(accel_dev, msg)) {
-               dev_err(&GET_DEV(accel_dev),
-                       "Failed to send Init event to PF\n");
-               return -EFAULT;
-       }
-       set_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(adf_vf2pf_notify_init);
-
-/**
- * adf_vf2pf_notify_shutdown() - send shutdown msg to PF
- * @accel_dev:  Pointer to acceleration VF device.
- *
- * Function sends a shutdown message from the VF to a PF
- *
- * Return: void
- */
-void adf_vf2pf_notify_shutdown(struct adf_accel_dev *accel_dev)
-{
-       u32 msg = (ADF_VF2PF_MSGORIGIN_SYSTEM |
-           (ADF_VF2PF_MSGTYPE_SHUTDOWN << ADF_VF2PF_MSGTYPE_SHIFT));
-
-       if (test_bit(ADF_STATUS_PF_RUNNING, &accel_dev->status))
-               if (adf_send_vf2pf_msg(accel_dev, msg))
-                       dev_err(&GET_DEV(accel_dev),
-                               "Failed to send Shutdown event to PF\n");
-}
-EXPORT_SYMBOL_GPL(adf_vf2pf_notify_shutdown);
-
-/**
- * adf_recv_pf2vf_msg() - receive a PF to VF message
- * @accel_dev: Pointer to acceleration device
- *
- * This function allows the VF to receive a message from the PF.
- *
- * Return: a valid message on success, zero otherwise.
- */
-static u32 adf_recv_pf2vf_msg(struct adf_accel_dev *accel_dev)
-{
-       return GET_PFVF_OPS(accel_dev)->recv_msg(accel_dev, 0);
-}
-
-static bool adf_handle_pf2vf_msg(struct adf_accel_dev *accel_dev, u32 msg)
-{
-       switch ((msg & ADF_PF2VF_MSGTYPE_MASK) >> ADF_PF2VF_MSGTYPE_SHIFT) {
-       case ADF_PF2VF_MSGTYPE_RESTARTING:
-               dev_dbg(&GET_DEV(accel_dev),
-                       "Restarting msg received from PF 0x%x\n", msg);
-
-               adf_pf2vf_handle_pf_restarting(accel_dev);
-               return false;
-       case ADF_PF2VF_MSGTYPE_VERSION_RESP:
-               dev_dbg(&GET_DEV(accel_dev),
-                       "Version resp received from PF 0x%x\n", msg);
-               accel_dev->vf.pf_version =
-                       (msg & ADF_PF2VF_VERSION_RESP_VERS_MASK) >>
-                       ADF_PF2VF_VERSION_RESP_VERS_SHIFT;
-               accel_dev->vf.compatible =
-                       (msg & ADF_PF2VF_VERSION_RESP_RESULT_MASK) >>
-                       ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
-               complete(&accel_dev->vf.iov_msg_completion);
-               return true;
-       default:
-               dev_err(&GET_DEV(accel_dev),
-                       "Unknown PF2VF message(0x%x)\n", msg);
-       }
-
-       return false;
-}
-
-bool adf_recv_and_handle_pf2vf_msg(struct adf_accel_dev *accel_dev)
-{
-       u32 msg;
-
-       msg = adf_recv_pf2vf_msg(accel_dev);
-       if (msg)
-               return adf_handle_pf2vf_msg(accel_dev, msg);
-
-       return true;
-}
index b17040b8a4b9f0f03fa9a129b9199a279ada5e4f..fe094178f065efb981103258e838a34bc2554132 100644 (file)
@@ -15,7 +15,6 @@
 #include "adf_cfg_common.h"
 #include "adf_transport_access_macros.h"
 #include "adf_transport_internal.h"
-#include "adf_pf2vf_msg.h"
 
 #define ADF_VINTSOU_OFFSET     0x204
 #define ADF_VINTMSK_OFFSET     0x208
index aa42373a7118db9de7b991f064702bcfb7ab2ace..37f43b8c29eb71eea2da715ee1e0b2df039211cd 100644 (file)
@@ -1,10 +1,10 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2014 - 2020 Intel Corporation */
+/* Copyright(c) 2014 - 2021 Intel Corporation */
 #include <adf_accel_devices.h>
-#include <adf_pf2vf_msg.h>
 #include <adf_common_drv.h>
 #include <adf_gen2_hw_data.h>
 #include <adf_gen2_pfvf.h>
+#include <adf_pfvf_msg.h>
 #include "adf_dh895xcc_hw_data.h"
 #include "icp_qat_hw.h"
 
index 2e2ef6b5bd2a2f77ccc6d806977666593e7df77b..d3795bab37255eb59aa491806a9d078f18f21ad6 100644 (file)
@@ -1,10 +1,11 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
-/* Copyright(c) 2015 - 2020 Intel Corporation */
+/* Copyright(c) 2015 - 2021 Intel Corporation */
 #include <adf_accel_devices.h>
-#include <adf_pf2vf_msg.h>
 #include <adf_common_drv.h>
 #include <adf_gen2_hw_data.h>
 #include <adf_gen2_pfvf.h>
+#include <adf_pfvf_msg.h>
+#include <adf_pfvf_vf_msg.h>
 #include "adf_dh895xccvf_hw_data.h"
 
 static struct adf_hw_device_class dh895xcciov_class = {