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>
24 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_pf2vf_msg.c [deleted file]
drivers/crypto/qat/qat_common/adf_pf2vf_msg.h [deleted file]
drivers/crypto/qat/qat_common/adf_pfvf_msg.h [new file with mode: 0644]
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 [new file with mode: 0644]
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)
diff --git a/drivers/crypto/qat/qat_common/adf_pf2vf_msg.c b/drivers/crypto/qat/qat_common/adf_pf2vf_msg.c
deleted file mode 100644 (file)
index c064e8b..0000000
+++ /dev/null
@@ -1,283 +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"
-
-#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_pf2vf_msg() - send PF to VF message
- * @accel_dev: Pointer to acceleration device
- * @vf_nr:     VF number to which the message will be sent
- * @msg:       Message to send
- *
- * This function allows the PF to send a message to a specific VF.
- *
- * Return: 0 on success, error code otherwise.
- */
-static 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
- * @vf_nr:     Number of the VF from where the message will be received
- *
- * This function allows the PF to receive a message from a specific VF.
- *
- * Return: a valid message on success, zero otherwise.
- */
-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)
-{
-       struct adf_accel_vf_info *vf_info = &accel_dev->pf.vf_info[vf_nr];
-       struct adf_hw_device_data *hw_data = accel_dev->hw_device;
-       u32 resp = 0;
-
-       switch ((msg & ADF_VF2PF_MSGTYPE_MASK) >> ADF_VF2PF_MSGTYPE_SHIFT) {
-       case ADF_VF2PF_MSGTYPE_COMPAT_VER_REQ:
-               {
-               u8 vf_compat_ver = msg >> ADF_VF2PF_COMPAT_VER_REQ_SHIFT;
-
-               resp = (ADF_PF2VF_MSGORIGIN_SYSTEM |
-                        (ADF_PF2VF_MSGTYPE_VERSION_RESP <<
-                         ADF_PF2VF_MSGTYPE_SHIFT) |
-                        (ADF_PFVF_COMPAT_THIS_VERSION <<
-                         ADF_PF2VF_VERSION_RESP_VERS_SHIFT));
-
-               dev_dbg(&GET_DEV(accel_dev),
-                       "Compatibility Version Request from VF%d vers=%u\n",
-                       vf_nr + 1, vf_compat_ver);
-
-               if (vf_compat_ver < hw_data->min_iov_compat_ver) {
-                       dev_err(&GET_DEV(accel_dev),
-                               "VF (vers %d) incompatible with PF (vers %d)\n",
-                               vf_compat_ver, ADF_PFVF_COMPAT_THIS_VERSION);
-                       resp |= ADF_PF2VF_VF_INCOMPATIBLE <<
-                               ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
-               } else if (vf_compat_ver > ADF_PFVF_COMPAT_THIS_VERSION) {
-                       dev_err(&GET_DEV(accel_dev),
-                               "VF (vers %d) compat with PF (vers %d) unkn.\n",
-                               vf_compat_ver, ADF_PFVF_COMPAT_THIS_VERSION);
-                       resp |= ADF_PF2VF_VF_COMPAT_UNKNOWN <<
-                               ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
-               } else {
-                       dev_dbg(&GET_DEV(accel_dev),
-                               "VF (vers %d) compatible with PF (vers %d)\n",
-                               vf_compat_ver, ADF_PFVF_COMPAT_THIS_VERSION);
-                       resp |= ADF_PF2VF_VF_COMPATIBLE <<
-                               ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
-               }
-               }
-               break;
-       case ADF_VF2PF_MSGTYPE_VERSION_REQ:
-               dev_dbg(&GET_DEV(accel_dev),
-                       "Legacy VersionRequest received from VF%d 0x%x\n",
-                       vf_nr + 1, msg);
-               resp = (ADF_PF2VF_MSGORIGIN_SYSTEM |
-                        (ADF_PF2VF_MSGTYPE_VERSION_RESP <<
-                         ADF_PF2VF_MSGTYPE_SHIFT) |
-                        (ADF_PFVF_COMPAT_THIS_VERSION <<
-                         ADF_PF2VF_VERSION_RESP_VERS_SHIFT));
-               resp |= ADF_PF2VF_VF_COMPATIBLE <<
-                       ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
-               /* Set legacy major and minor version num */
-               resp |= 1 << ADF_PF2VF_MAJORVERSION_SHIFT |
-                       1 << ADF_PF2VF_MINORVERSION_SHIFT;
-               break;
-       case ADF_VF2PF_MSGTYPE_INIT:
-               {
-               dev_dbg(&GET_DEV(accel_dev),
-                       "Init message received from VF%d 0x%x\n",
-                       vf_nr + 1, msg);
-               vf_info->init = true;
-               }
-               break;
-       case ADF_VF2PF_MSGTYPE_SHUTDOWN:
-               {
-               dev_dbg(&GET_DEV(accel_dev),
-                       "Shutdown message received from VF%d 0x%x\n",
-                       vf_nr + 1, msg);
-               vf_info->init = false;
-               }
-               break;
-       default:
-               dev_dbg(&GET_DEV(accel_dev), "Unknown message from VF%d (0x%x)\n",
-                       vf_nr + 1, msg);
-               return -ENOMSG;
-       }
-
-       *response = resp;
-
-       return 0;
-}
-
-bool adf_recv_and_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 vf_nr)
-{
-       u32 resp = 0;
-       u32 msg;
-
-       msg = adf_recv_vf2pf_msg(accel_dev, vf_nr);
-       if (!msg)
-               return true;
-
-       if (adf_handle_vf2pf_msg(accel_dev, vf_nr, msg, &resp))
-               return false;
-
-       if (resp && adf_send_pf2vf_msg(accel_dev, vf_nr, resp))
-               dev_err(&GET_DEV(accel_dev), "Failed to send response to VF\n");
-
-       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
- *
- * @accel_dev: Pointer to acceleration device virtual function.
- *
- * This function carries out the necessary steps to setup and start the PFVF
- * communication channel, if any.
- *
- * Return: 0 on success, error code otherwise.
- */
-int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev)
-{
-       spin_lock_init(&accel_dev->pf.vf2pf_ints_lock);
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(adf_enable_pf2vf_comms);
diff --git a/drivers/crypto/qat/qat_common/adf_pf2vf_msg.h b/drivers/crypto/qat/qat_common/adf_pf2vf_msg.h
deleted file mode 100644 (file)
index 73eb8f1..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/* 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
-
-/*
- * PF<->VF Messaging
- * The PF has an array of 32-bit PF2VF registers, one for each VF.  The
- * PF can access all these registers; each VF can access only the one
- * register associated with that particular VF.
- *
- * The register functionally is split into two parts:
- * The bottom half is for PF->VF messages. In particular when the first
- * bit of this register (bit 0) gets set an interrupt will be triggered
- * in the respective VF.
- * The top half is for VF->PF messages. In particular when the first bit
- * of this half of register (bit 16) gets set an interrupt will be triggered
- * in the PF.
- *
- * The remaining bits within this register are available to encode messages.
- * and implement a collision control mechanism to prevent concurrent use of
- * the PF2VF register by both the PF and VF.
- *
- *  31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
- *  _______________________________________________
- * |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
- * +-----------------------------------------------+
- *  \___________________________/ \_________/ ^   ^
- *                ^                    ^      |   |
- *                |                    |      |   VF2PF Int
- *                |                    |      Message Origin
- *                |                    Message Type
- *                Message-specific Data/Reserved
- *
- *  15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
- *  _______________________________________________
- * |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
- * +-----------------------------------------------+
- *  \___________________________/ \_________/ ^   ^
- *                ^                    ^      |   |
- *                |                    |      |   PF2VF Int
- *                |                    |      Message Origin
- *                |                    Message Type
- *                Message-specific Data/Reserved
- *
- * Message Origin (Should always be 1)
- * A legacy out-of-tree QAT driver allowed for a set of messages not supported
- * by this driver; these had a Msg Origin of 0 and are ignored by this driver.
- *
- * When a PF or VF attempts to send a message in the lower or upper 16 bits,
- * respectively, the other 16 bits are written to first with a defined
- * IN_USE_BY pattern as part of a collision control scheme (see function
- * adf_gen2_pfvf_send() in adf_pf2vf_msg.c).
- */
-
-#define ADF_PFVF_COMPAT_THIS_VERSION           0x1     /* PF<->VF compat */
-
-/* PF->VF messages */
-#define ADF_PF2VF_INT                          BIT(0)
-#define ADF_PF2VF_MSGORIGIN_SYSTEM             BIT(1)
-#define ADF_PF2VF_MSGTYPE_MASK                 0x0000003C
-#define ADF_PF2VF_MSGTYPE_SHIFT                        2
-#define ADF_PF2VF_MSGTYPE_RESTARTING           0x01
-#define ADF_PF2VF_MSGTYPE_VERSION_RESP         0x02
-#define ADF_PF2VF_IN_USE_BY_PF                 0x6AC20000
-#define ADF_PF2VF_IN_USE_BY_PF_MASK            0xFFFE0000
-
-/* PF->VF Version Response */
-#define ADF_PF2VF_VERSION_RESP_VERS_MASK       0x00003FC0
-#define ADF_PF2VF_VERSION_RESP_VERS_SHIFT      6
-#define ADF_PF2VF_VERSION_RESP_RESULT_MASK     0x0000C000
-#define ADF_PF2VF_VERSION_RESP_RESULT_SHIFT    14
-#define ADF_PF2VF_MINORVERSION_SHIFT           6
-#define ADF_PF2VF_MAJORVERSION_SHIFT           10
-#define ADF_PF2VF_VF_COMPATIBLE                        1
-#define ADF_PF2VF_VF_INCOMPATIBLE              2
-#define ADF_PF2VF_VF_COMPAT_UNKNOWN            3
-
-/* VF->PF messages */
-#define ADF_VF2PF_IN_USE_BY_VF                 0x00006AC2
-#define ADF_VF2PF_IN_USE_BY_VF_MASK            0x0000FFFE
-#define ADF_VF2PF_INT                          BIT(16)
-#define ADF_VF2PF_MSGORIGIN_SYSTEM             BIT(17)
-#define ADF_VF2PF_MSGTYPE_MASK                 0x003C0000
-#define ADF_VF2PF_MSGTYPE_SHIFT                        18
-#define ADF_VF2PF_MSGTYPE_INIT                 0x3
-#define ADF_VF2PF_MSGTYPE_SHUTDOWN             0x4
-#define ADF_VF2PF_MSGTYPE_VERSION_REQ          0x5
-#define ADF_VF2PF_MSGTYPE_COMPAT_VER_REQ       0x6
-
-/* VF->PF Compatible Version Request */
-#define ADF_VF2PF_COMPAT_VER_REQ_SHIFT         22
-
-#endif /* ADF_IOV_MSG_H */
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_msg.h b/drivers/crypto/qat/qat_common/adf_pfvf_msg.h
new file mode 100644 (file)
index 0000000..0520466
--- /dev/null
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
+/* Copyright(c) 2015 - 2021 Intel Corporation */
+#ifndef ADF_PFVF_MSG_H
+#define ADF_PFVF_MSG_H
+
+/*
+ * PF<->VF Messaging
+ * The PF has an array of 32-bit PF2VF registers, one for each VF.  The
+ * PF can access all these registers; each VF can access only the one
+ * register associated with that particular VF.
+ *
+ * The register functionally is split into two parts:
+ * The bottom half is for PF->VF messages. In particular when the first
+ * bit of this register (bit 0) gets set an interrupt will be triggered
+ * in the respective VF.
+ * The top half is for VF->PF messages. In particular when the first bit
+ * of this half of register (bit 16) gets set an interrupt will be triggered
+ * in the PF.
+ *
+ * The remaining bits within this register are available to encode messages.
+ * and implement a collision control mechanism to prevent concurrent use of
+ * the PF2VF register by both the PF and VF.
+ *
+ *  31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
+ *  _______________________________________________
+ * |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
+ * +-----------------------------------------------+
+ *  \___________________________/ \_________/ ^   ^
+ *                ^                    ^      |   |
+ *                |                    |      |   VF2PF Int
+ *                |                    |      Message Origin
+ *                |                    Message Type
+ *                Message-specific Data/Reserved
+ *
+ *  15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
+ *  _______________________________________________
+ * |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
+ * +-----------------------------------------------+
+ *  \___________________________/ \_________/ ^   ^
+ *                ^                    ^      |   |
+ *                |                    |      |   PF2VF Int
+ *                |                    |      Message Origin
+ *                |                    Message Type
+ *                Message-specific Data/Reserved
+ *
+ * Message Origin (Should always be 1)
+ * A legacy out-of-tree QAT driver allowed for a set of messages not supported
+ * by this driver; these had a Msg Origin of 0 and are ignored by this driver.
+ *
+ * When a PF or VF attempts to send a message in the lower or upper 16 bits,
+ * respectively, the other 16 bits are written to first with a defined
+ * IN_USE_BY pattern as part of a collision control scheme (see function
+ * adf_gen2_pfvf_send() in adf_pf2vf_msg.c).
+ */
+
+#define ADF_PFVF_COMPAT_THIS_VERSION           0x1     /* PF<->VF compat */
+
+/* PF->VF messages */
+#define ADF_PF2VF_INT                          BIT(0)
+#define ADF_PF2VF_MSGORIGIN_SYSTEM             BIT(1)
+#define ADF_PF2VF_MSGTYPE_MASK                 0x0000003C
+#define ADF_PF2VF_MSGTYPE_SHIFT                        2
+#define ADF_PF2VF_MSGTYPE_RESTARTING           0x01
+#define ADF_PF2VF_MSGTYPE_VERSION_RESP         0x02
+#define ADF_PF2VF_IN_USE_BY_PF                 0x6AC20000
+#define ADF_PF2VF_IN_USE_BY_PF_MASK            0xFFFE0000
+
+/* PF->VF Version Response */
+#define ADF_PF2VF_VERSION_RESP_VERS_MASK       0x00003FC0
+#define ADF_PF2VF_VERSION_RESP_VERS_SHIFT      6
+#define ADF_PF2VF_VERSION_RESP_RESULT_MASK     0x0000C000
+#define ADF_PF2VF_VERSION_RESP_RESULT_SHIFT    14
+#define ADF_PF2VF_MINORVERSION_SHIFT           6
+#define ADF_PF2VF_MAJORVERSION_SHIFT           10
+#define ADF_PF2VF_VF_COMPATIBLE                        1
+#define ADF_PF2VF_VF_INCOMPATIBLE              2
+#define ADF_PF2VF_VF_COMPAT_UNKNOWN            3
+
+/* VF->PF messages */
+#define ADF_VF2PF_IN_USE_BY_VF                 0x00006AC2
+#define ADF_VF2PF_IN_USE_BY_VF_MASK            0x0000FFFE
+#define ADF_VF2PF_INT                          BIT(16)
+#define ADF_VF2PF_MSGORIGIN_SYSTEM             BIT(17)
+#define ADF_VF2PF_MSGTYPE_MASK                 0x003C0000
+#define ADF_VF2PF_MSGTYPE_SHIFT                        18
+#define ADF_VF2PF_MSGTYPE_INIT                 0x3
+#define ADF_VF2PF_MSGTYPE_SHUTDOWN             0x4
+#define ADF_VF2PF_MSGTYPE_VERSION_REQ          0x5
+#define ADF_VF2PF_MSGTYPE_COMPAT_VER_REQ       0x6
+
+/* VF->PF Compatible Version Request */
+#define ADF_VF2PF_COMPAT_VER_REQ_SHIFT         22
+
+#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 */
diff --git a/drivers/crypto/qat/qat_common/adf_pfvf_pf_proto.c b/drivers/crypto/qat/qat_common/adf_pfvf_pf_proto.c
new file mode 100644 (file)
index 0000000..ac6a54c
--- /dev/null
@@ -0,0 +1,158 @@
+// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
+/* 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_pfvf_msg.h"
+#include "adf_pfvf_pf_proto.h"
+
+/**
+ * adf_send_pf2vf_msg() - send PF to VF message
+ * @accel_dev: Pointer to acceleration device
+ * @vf_nr:     VF number to which the message will be sent
+ * @msg:       Message to send
+ *
+ * This function allows the PF to send a message to a specific VF.
+ *
+ * Return: 0 on success, error code otherwise.
+ */
+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_recv_vf2pf_msg() - receive a VF to PF message
+ * @accel_dev: Pointer to acceleration device
+ * @vf_nr:     Number of the VF from where the message will be received
+ *
+ * This function allows the PF to receive a message from a specific VF.
+ *
+ * Return: a valid message on success, zero otherwise.
+ */
+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);
+}
+
+static int adf_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 vf_nr,
+                               u32 msg, u32 *response)
+{
+       struct adf_accel_vf_info *vf_info = &accel_dev->pf.vf_info[vf_nr];
+       struct adf_hw_device_data *hw_data = accel_dev->hw_device;
+       u32 resp = 0;
+
+       switch ((msg & ADF_VF2PF_MSGTYPE_MASK) >> ADF_VF2PF_MSGTYPE_SHIFT) {
+       case ADF_VF2PF_MSGTYPE_COMPAT_VER_REQ:
+               {
+               u8 vf_compat_ver = msg >> ADF_VF2PF_COMPAT_VER_REQ_SHIFT;
+
+               resp = (ADF_PF2VF_MSGORIGIN_SYSTEM |
+                        (ADF_PF2VF_MSGTYPE_VERSION_RESP <<
+                         ADF_PF2VF_MSGTYPE_SHIFT) |
+                        (ADF_PFVF_COMPAT_THIS_VERSION <<
+                         ADF_PF2VF_VERSION_RESP_VERS_SHIFT));
+
+               dev_dbg(&GET_DEV(accel_dev),
+                       "Compatibility Version Request from VF%d vers=%u\n",
+                       vf_nr + 1, vf_compat_ver);
+
+               if (vf_compat_ver < hw_data->min_iov_compat_ver) {
+                       dev_err(&GET_DEV(accel_dev),
+                               "VF (vers %d) incompatible with PF (vers %d)\n",
+                               vf_compat_ver, ADF_PFVF_COMPAT_THIS_VERSION);
+                       resp |= ADF_PF2VF_VF_INCOMPATIBLE <<
+                               ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
+               } else if (vf_compat_ver > ADF_PFVF_COMPAT_THIS_VERSION) {
+                       dev_err(&GET_DEV(accel_dev),
+                               "VF (vers %d) compat with PF (vers %d) unkn.\n",
+                               vf_compat_ver, ADF_PFVF_COMPAT_THIS_VERSION);
+                       resp |= ADF_PF2VF_VF_COMPAT_UNKNOWN <<
+                               ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
+               } else {
+                       dev_dbg(&GET_DEV(accel_dev),
+                               "VF (vers %d) compatible with PF (vers %d)\n",
+                               vf_compat_ver, ADF_PFVF_COMPAT_THIS_VERSION);
+                       resp |= ADF_PF2VF_VF_COMPATIBLE <<
+                               ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
+               }
+               }
+               break;
+       case ADF_VF2PF_MSGTYPE_VERSION_REQ:
+               dev_dbg(&GET_DEV(accel_dev),
+                       "Legacy VersionRequest received from VF%d 0x%x\n",
+                       vf_nr + 1, msg);
+               resp = (ADF_PF2VF_MSGORIGIN_SYSTEM |
+                        (ADF_PF2VF_MSGTYPE_VERSION_RESP <<
+                         ADF_PF2VF_MSGTYPE_SHIFT) |
+                        (ADF_PFVF_COMPAT_THIS_VERSION <<
+                         ADF_PF2VF_VERSION_RESP_VERS_SHIFT));
+               resp |= ADF_PF2VF_VF_COMPATIBLE <<
+                       ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
+               /* Set legacy major and minor version num */
+               resp |= 1 << ADF_PF2VF_MAJORVERSION_SHIFT |
+                       1 << ADF_PF2VF_MINORVERSION_SHIFT;
+               break;
+       case ADF_VF2PF_MSGTYPE_INIT:
+               {
+               dev_dbg(&GET_DEV(accel_dev),
+                       "Init message received from VF%d 0x%x\n",
+                       vf_nr + 1, msg);
+               vf_info->init = true;
+               }
+               break;
+       case ADF_VF2PF_MSGTYPE_SHUTDOWN:
+               {
+               dev_dbg(&GET_DEV(accel_dev),
+                       "Shutdown message received from VF%d 0x%x\n",
+                       vf_nr + 1, msg);
+               vf_info->init = false;
+               }
+               break;
+       default:
+               dev_dbg(&GET_DEV(accel_dev), "Unknown message from VF%d (0x%x)\n",
+                       vf_nr + 1, msg);
+               return -ENOMSG;
+       }
+
+       *response = resp;
+
+       return 0;
+}
+
+bool adf_recv_and_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 vf_nr)
+{
+       u32 resp = 0;
+       u32 msg;
+
+       msg = adf_recv_vf2pf_msg(accel_dev, vf_nr);
+       if (!msg)
+               return true;
+
+       if (adf_handle_vf2pf_msg(accel_dev, vf_nr, msg, &resp))
+               return false;
+
+       if (resp && adf_send_pf2vf_msg(accel_dev, vf_nr, resp))
+               dev_err(&GET_DEV(accel_dev), "Failed to send response to VF\n");
+
+       return true;
+}
+
+/**
+ * adf_enable_pf2vf_comms() - Function enables communication from pf to vf
+ *
+ * @accel_dev: Pointer to acceleration device virtual function.
+ *
+ * This function carries out the necessary steps to setup and start the PFVF
+ * communication channel, if any.
+ *
+ * Return: 0 on success, error code otherwise.
+ */
+int adf_enable_pf2vf_comms(struct adf_accel_dev *accel_dev)
+{
+       spin_lock_init(&accel_dev->pf.vf2pf_ints_lock);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(adf_enable_pf2vf_comms);
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 = {