Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: qat - abstract PFVF send function

Make the PFVF send function device specific.

This is in preparation for the introduction of PFVF support in the
qat_4xxx driver since the send logic differs between QAT GEN2 and
QAT GEN4 devices.

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>

authored by

Marco Chiappero and committed by
Herbert Xu
49c43538 9baf2de7

+102 -91
+1
drivers/crypto/qat/qat_common/adf_accel_devices.h
··· 154 154 u32 (*get_vf2pf_sources)(void __iomem *pmisc_addr); 155 155 void (*enable_vf2pf_interrupts)(void __iomem *pmisc_addr, u32 vf_mask); 156 156 void (*disable_vf2pf_interrupts)(void __iomem *pmisc_addr, u32 vf_mask); 157 + int (*send_msg)(struct adf_accel_dev *accel_dev, u32 msg, u8 vf_nr); 157 158 }; 158 159 159 160 struct adf_hw_device_data {
+97
drivers/crypto/qat/qat_common/adf_gen2_pfvf.c
··· 1 1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) 2 2 /* Copyright(c) 2021 Intel Corporation */ 3 + #include <linux/delay.h> 4 + #include <linux/mutex.h> 3 5 #include <linux/types.h> 4 6 #include "adf_accel_devices.h" 5 7 #include "adf_common_drv.h" 6 8 #include "adf_gen2_pfvf.h" 9 + #include "adf_pf2vf_msg.h" 7 10 8 11 /* VF2PF interrupts */ 9 12 #define ADF_GEN2_ERR_REG_VF2PF(vf_src) (((vf_src) & 0x01FFFE00) >> 9) ··· 14 11 15 12 #define ADF_GEN2_PF_PF2VF_OFFSET(i) (0x3A000 + 0x280 + ((i) * 0x04)) 16 13 #define ADF_GEN2_VF_PF2VF_OFFSET 0x200 14 + 15 + #define ADF_PFVF_MSG_ACK_DELAY 2 16 + #define ADF_PFVF_MSG_ACK_MAX_RETRY 100 17 + 18 + #define ADF_PFVF_MSG_RETRY_DELAY 5 19 + #define ADF_PFVF_MSG_MAX_RETRIES 3 17 20 18 21 static u32 adf_gen2_pf_get_pfvf_offset(u32 i) 19 22 { ··· 70 61 } 71 62 } 72 63 64 + static int adf_gen2_pfvf_send(struct adf_accel_dev *accel_dev, u32 msg, 65 + u8 vf_nr) 66 + { 67 + struct adf_accel_pci *pci_info = &accel_dev->accel_pci_dev; 68 + struct adf_hw_device_data *hw_data = accel_dev->hw_device; 69 + void __iomem *pmisc_bar_addr = 70 + pci_info->pci_bars[hw_data->get_misc_bar_id(hw_data)].virt_addr; 71 + u32 val, pfvf_offset, count = 0; 72 + u32 local_in_use_mask, local_in_use_pattern; 73 + u32 remote_in_use_mask, remote_in_use_pattern; 74 + struct mutex *lock; /* lock preventing concurrent acces of CSR */ 75 + unsigned int retries = ADF_PFVF_MSG_MAX_RETRIES; 76 + u32 int_bit; 77 + int ret; 78 + 79 + if (accel_dev->is_vf) { 80 + pfvf_offset = GET_PFVF_OPS(accel_dev)->get_vf2pf_offset(0); 81 + lock = &accel_dev->vf.vf2pf_lock; 82 + local_in_use_mask = ADF_VF2PF_IN_USE_BY_VF_MASK; 83 + local_in_use_pattern = ADF_VF2PF_IN_USE_BY_VF; 84 + remote_in_use_mask = ADF_PF2VF_IN_USE_BY_PF_MASK; 85 + remote_in_use_pattern = ADF_PF2VF_IN_USE_BY_PF; 86 + int_bit = ADF_VF2PF_INT; 87 + } else { 88 + pfvf_offset = GET_PFVF_OPS(accel_dev)->get_pf2vf_offset(vf_nr); 89 + lock = &accel_dev->pf.vf_info[vf_nr].pf2vf_lock; 90 + local_in_use_mask = ADF_PF2VF_IN_USE_BY_PF_MASK; 91 + local_in_use_pattern = ADF_PF2VF_IN_USE_BY_PF; 92 + remote_in_use_mask = ADF_VF2PF_IN_USE_BY_VF_MASK; 93 + remote_in_use_pattern = ADF_VF2PF_IN_USE_BY_VF; 94 + int_bit = ADF_PF2VF_INT; 95 + } 96 + 97 + msg &= ~local_in_use_mask; 98 + msg |= local_in_use_pattern; 99 + 100 + mutex_lock(lock); 101 + 102 + start: 103 + ret = 0; 104 + 105 + /* Check if the PFVF CSR is in use by remote function */ 106 + val = ADF_CSR_RD(pmisc_bar_addr, pfvf_offset); 107 + if ((val & remote_in_use_mask) == remote_in_use_pattern) { 108 + dev_dbg(&GET_DEV(accel_dev), 109 + "PFVF CSR in use by remote function\n"); 110 + goto retry; 111 + } 112 + 113 + /* Attempt to get ownership of the PFVF CSR */ 114 + ADF_CSR_WR(pmisc_bar_addr, pfvf_offset, msg | int_bit); 115 + 116 + /* Wait for confirmation from remote func it received the message */ 117 + do { 118 + msleep(ADF_PFVF_MSG_ACK_DELAY); 119 + val = ADF_CSR_RD(pmisc_bar_addr, pfvf_offset); 120 + } while ((val & int_bit) && (count++ < ADF_PFVF_MSG_ACK_MAX_RETRY)); 121 + 122 + if (val & int_bit) { 123 + dev_dbg(&GET_DEV(accel_dev), "ACK not received from remote\n"); 124 + val &= ~int_bit; 125 + ret = -EIO; 126 + } 127 + 128 + if (val != msg) { 129 + dev_dbg(&GET_DEV(accel_dev), 130 + "Collision - PFVF CSR overwritten by remote function\n"); 131 + goto retry; 132 + } 133 + 134 + /* Finished with the PFVF CSR; relinquish it and leave msg in CSR */ 135 + ADF_CSR_WR(pmisc_bar_addr, pfvf_offset, val & ~local_in_use_mask); 136 + out: 137 + mutex_unlock(lock); 138 + return ret; 139 + 140 + retry: 141 + if (--retries) { 142 + msleep(ADF_PFVF_MSG_RETRY_DELAY); 143 + goto start; 144 + } else { 145 + ret = -EBUSY; 146 + goto out; 147 + } 148 + } 149 + 73 150 void adf_gen2_init_pf_pfvf_ops(struct adf_pfvf_ops *pfvf_ops) 74 151 { 75 152 pfvf_ops->enable_comms = adf_enable_pf2vf_comms; ··· 164 69 pfvf_ops->get_vf2pf_sources = adf_gen2_get_vf2pf_sources; 165 70 pfvf_ops->enable_vf2pf_interrupts = adf_gen2_enable_vf2pf_interrupts; 166 71 pfvf_ops->disable_vf2pf_interrupts = adf_gen2_disable_vf2pf_interrupts; 72 + pfvf_ops->send_msg = adf_gen2_pfvf_send; 167 73 } 168 74 EXPORT_SYMBOL_GPL(adf_gen2_init_pf_pfvf_ops); 169 75 ··· 173 77 pfvf_ops->enable_comms = adf_enable_vf2pf_comms; 174 78 pfvf_ops->get_pf2vf_offset = adf_gen2_vf_get_pfvf_offset; 175 79 pfvf_ops->get_vf2pf_offset = adf_gen2_vf_get_pfvf_offset; 80 + pfvf_ops->send_msg = adf_gen2_pfvf_send; 176 81 } 177 82 EXPORT_SYMBOL_GPL(adf_gen2_init_vf_pfvf_ops);
+2 -90
drivers/crypto/qat/qat_common/adf_pf2vf_msg.c
··· 1 1 // SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) 2 2 /* Copyright(c) 2015 - 2020 Intel Corporation */ 3 - #include <linux/delay.h> 4 3 #include "adf_accel_devices.h" 5 4 #include "adf_common_drv.h" 6 5 #include "adf_pf2vf_msg.h" ··· 7 8 #define ADF_PFVF_MSG_COLLISION_DETECT_DELAY 10 8 9 #define ADF_PFVF_MSG_ACK_DELAY 2 9 10 #define ADF_PFVF_MSG_ACK_MAX_RETRY 100 10 - #define ADF_PFVF_MSG_RETRY_DELAY 5 11 - #define ADF_PFVF_MSG_MAX_RETRIES 3 12 11 #define ADF_PFVF_MSG_RESP_TIMEOUT (ADF_PFVF_MSG_ACK_DELAY * \ 13 12 ADF_PFVF_MSG_ACK_MAX_RETRY + \ 14 13 ADF_PFVF_MSG_COLLISION_DETECT_DELAY) 15 - 16 - static int adf_iov_putmsg(struct adf_accel_dev *accel_dev, u32 msg, u8 vf_nr) 17 - { 18 - struct adf_accel_pci *pci_info = &accel_dev->accel_pci_dev; 19 - struct adf_hw_device_data *hw_data = accel_dev->hw_device; 20 - void __iomem *pmisc_bar_addr = 21 - pci_info->pci_bars[hw_data->get_misc_bar_id(hw_data)].virt_addr; 22 - u32 val, pf2vf_offset, count = 0; 23 - u32 local_in_use_mask, local_in_use_pattern; 24 - u32 remote_in_use_mask, remote_in_use_pattern; 25 - struct mutex *lock; /* lock preventing concurrent acces of CSR */ 26 - unsigned int retries = ADF_PFVF_MSG_MAX_RETRIES; 27 - u32 int_bit; 28 - int ret; 29 - 30 - if (accel_dev->is_vf) { 31 - pf2vf_offset = hw_data->pfvf_ops.get_vf2pf_offset(0); 32 - lock = &accel_dev->vf.vf2pf_lock; 33 - local_in_use_mask = ADF_VF2PF_IN_USE_BY_VF_MASK; 34 - local_in_use_pattern = ADF_VF2PF_IN_USE_BY_VF; 35 - remote_in_use_mask = ADF_PF2VF_IN_USE_BY_PF_MASK; 36 - remote_in_use_pattern = ADF_PF2VF_IN_USE_BY_PF; 37 - int_bit = ADF_VF2PF_INT; 38 - } else { 39 - pf2vf_offset = hw_data->pfvf_ops.get_pf2vf_offset(vf_nr); 40 - lock = &accel_dev->pf.vf_info[vf_nr].pf2vf_lock; 41 - local_in_use_mask = ADF_PF2VF_IN_USE_BY_PF_MASK; 42 - local_in_use_pattern = ADF_PF2VF_IN_USE_BY_PF; 43 - remote_in_use_mask = ADF_VF2PF_IN_USE_BY_VF_MASK; 44 - remote_in_use_pattern = ADF_VF2PF_IN_USE_BY_VF; 45 - int_bit = ADF_PF2VF_INT; 46 - } 47 - 48 - msg &= ~local_in_use_mask; 49 - msg |= local_in_use_pattern; 50 - 51 - mutex_lock(lock); 52 - 53 - start: 54 - ret = 0; 55 - 56 - /* Check if the PFVF CSR is in use by remote function */ 57 - val = ADF_CSR_RD(pmisc_bar_addr, pf2vf_offset); 58 - if ((val & remote_in_use_mask) == remote_in_use_pattern) { 59 - dev_dbg(&GET_DEV(accel_dev), 60 - "PFVF CSR in use by remote function\n"); 61 - goto retry; 62 - } 63 - 64 - /* Attempt to get ownership of the PFVF CSR */ 65 - ADF_CSR_WR(pmisc_bar_addr, pf2vf_offset, msg | int_bit); 66 - 67 - /* Wait for confirmation from remote func it received the message */ 68 - do { 69 - msleep(ADF_PFVF_MSG_ACK_DELAY); 70 - val = ADF_CSR_RD(pmisc_bar_addr, pf2vf_offset); 71 - } while ((val & int_bit) && (count++ < ADF_PFVF_MSG_ACK_MAX_RETRY)); 72 - 73 - if (val & int_bit) { 74 - dev_dbg(&GET_DEV(accel_dev), "ACK not received from remote\n"); 75 - val &= ~int_bit; 76 - ret = -EIO; 77 - } 78 - 79 - if (val != msg) { 80 - dev_dbg(&GET_DEV(accel_dev), 81 - "Collision - PFVF CSR overwritten by remote function\n"); 82 - goto retry; 83 - } 84 - 85 - /* Finished with the PFVF CSR; relinquish it and leave msg in CSR */ 86 - ADF_CSR_WR(pmisc_bar_addr, pf2vf_offset, val & ~local_in_use_mask); 87 - out: 88 - mutex_unlock(lock); 89 - return ret; 90 - 91 - retry: 92 - if (--retries) { 93 - msleep(ADF_PFVF_MSG_RETRY_DELAY); 94 - goto start; 95 - } else { 96 - ret = -EBUSY; 97 - goto out; 98 - } 99 - } 100 14 101 15 /** 102 16 * adf_send_pf2vf_msg() - send PF to VF message ··· 23 111 */ 24 112 static int adf_send_pf2vf_msg(struct adf_accel_dev *accel_dev, u8 vf_nr, u32 msg) 25 113 { 26 - return adf_iov_putmsg(accel_dev, msg, vf_nr); 114 + return GET_PFVF_OPS(accel_dev)->send_msg(accel_dev, msg, vf_nr); 27 115 } 28 116 29 117 /** ··· 37 125 */ 38 126 int adf_send_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 msg) 39 127 { 40 - return adf_iov_putmsg(accel_dev, msg, 0); 128 + return GET_PFVF_OPS(accel_dev)->send_msg(accel_dev, msg, 0); 41 129 } 42 130 43 131 /**
+2 -1
drivers/crypto/qat/qat_common/adf_pf2vf_msg.h
··· 49 49 * 50 50 * When a PF or VF attempts to send a message in the lower or upper 16 bits, 51 51 * respectively, the other 16 bits are written to first with a defined 52 - * IN_USE_BY pattern as part of a collision control scheme (see adf_iov_putmsg). 52 + * IN_USE_BY pattern as part of a collision control scheme (see function 53 + * adf_gen2_pfvf_send() in adf_pf2vf_msg.c). 53 54 */ 54 55 55 56 #define ADF_PFVF_COMPAT_THIS_VERSION 0x1 /* PF<->VF compat */