OSDN Git Service

crypto: qat - leverage bitfield.h utils for PFVF messages
authorMarco Chiappero <marco.chiappero@intel.com>
Thu, 16 Dec 2021 09:13:21 +0000 (09:13 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 24 Dec 2021 03:18:25 +0000 (14:18 +1100)
The PFVF protocol defines messages composed of a number of control
bitfields. Replace all the code setting and retrieving such bits
with the utilities from bitfield.h, to improve code quality and
readability.

Signed-off-by: Marco Chiappero <marco.chiappero@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: Fiona Trahe <fiona.trahe@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/qat/qat_common/adf_pfvf_msg.h
drivers/crypto/qat/qat_common/adf_pfvf_pf_proto.c
drivers/crypto/qat/qat_common/adf_pfvf_vf_msg.c

index 26eb278..daee3d7 100644 (file)
@@ -3,6 +3,8 @@
 #ifndef ADF_PFVF_MSG_H
 #define ADF_PFVF_MSG_H
 
+#include <linux/bits.h>
+
 /*
  * PF<->VF Messaging
  * The PF has an array of 32-bit PF2VF registers, one for each VF.  The
@@ -86,10 +88,8 @@ enum pfvf_compatibility_version {
 };
 
 /* PF->VF Version Response */
-#define ADF_PF2VF_VERSION_RESP_VERS_SHIFT      0
-#define ADF_PF2VF_VERSION_RESP_VERS_MASK       0xFF
-#define ADF_PF2VF_VERSION_RESP_RESULT_SHIFT    8
-#define ADF_PF2VF_VERSION_RESP_RESULT_MASK     0x03
+#define ADF_PF2VF_VERSION_RESP_VERS_MASK       GENMASK(7, 0)
+#define ADF_PF2VF_VERSION_RESP_RESULT_MASK     GENMASK(9, 8)
 
 enum pf2vf_compat_response {
        ADF_PF2VF_VF_COMPATIBLE                 = 0x01,
index bb4d7db..8785b9d 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
 /* Copyright(c) 2015 - 2021 Intel Corporation */
+#include <linux/bitfield.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
 #include "adf_accel_devices.h"
@@ -64,9 +65,9 @@ static int adf_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr,
                        compat = ADF_PF2VF_VF_COMPAT_UNKNOWN;
 
                resp->type = ADF_PF2VF_MSGTYPE_VERSION_RESP;
-               resp->data = ADF_PFVF_COMPAT_THIS_VERSION <<
-                            ADF_PF2VF_VERSION_RESP_VERS_SHIFT;
-               resp->data |= compat << ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
+               resp->data = FIELD_PREP(ADF_PF2VF_VERSION_RESP_VERS_MASK,
+                                       ADF_PFVF_COMPAT_THIS_VERSION) |
+                            FIELD_PREP(ADF_PF2VF_VERSION_RESP_RESULT_MASK, compat);
                }
                break;
        case ADF_VF2PF_MSGTYPE_VERSION_REQ:
@@ -80,10 +81,10 @@ static int adf_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr,
                /* PF always newer than legacy VF */
                compat = ADF_PF2VF_VF_COMPATIBLE;
 
-               resp->type = ADF_PF2VF_MSGTYPE_VERSION_RESP;
                /* Set legacy major and minor version to the latest, 1.1 */
-               resp->data |= 0x11;
-               resp->data |= compat << ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
+               resp->type = ADF_PF2VF_MSGTYPE_VERSION_RESP;
+               resp->data = FIELD_PREP(ADF_PF2VF_VERSION_RESP_VERS_MASK, 0x11) |
+                            FIELD_PREP(ADF_PF2VF_VERSION_RESP_RESULT_MASK, compat);
                }
                break;
        case ADF_VF2PF_MSGTYPE_INIT:
index 5184a77..130d7b9 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only)
 /* Copyright(c) 2015 - 2021 Intel Corporation */
+#include <linux/bitfield.h>
 #include "adf_accel_devices.h"
 #include "adf_common_drv.h"
 #include "adf_pfvf_msg.h"
@@ -67,10 +68,8 @@ int adf_vf2pf_request_version(struct adf_accel_dev *accel_dev)
                return ret;
        }
 
-       pf_version = (resp.data >> ADF_PF2VF_VERSION_RESP_VERS_SHIFT)
-                    & ADF_PF2VF_VERSION_RESP_VERS_MASK;
-       compat = (resp.data >> ADF_PF2VF_VERSION_RESP_RESULT_SHIFT)
-                & ADF_PF2VF_VERSION_RESP_RESULT_MASK;
+       pf_version = FIELD_GET(ADF_PF2VF_VERSION_RESP_VERS_MASK, resp.data);
+       compat = FIELD_GET(ADF_PF2VF_VERSION_RESP_RESULT_MASK, resp.data);
 
        /* Response from PF received, check compatibility */
        switch (compat) {