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

crypto: qat - add support for compression for 4xxx

Add the logic required to enable the compression service for 4xxx devices.
This allows to load the compression firmware image and report
the appropriate compression capabilities.

The firmware image selection for a given device is based on the
'ServicesEnabled' key stored in the internal configuration, which is
added statically at the probe of the device according to the following
rule, by default:
- odd numbered devices assigned to compression services
- even numbered devices assigned to crypto services

In addition, restore the 'ServicesEnabled' key, if present, when SRIOV
is enabled on the device.

Signed-off-by: Tomasz Kowalik <tomaszx.kowalik@intel.com>
Co-developed-by: Mateuszx Potrola <mateuszx.potrola@intel.com>
Signed-off-by: Mateuszx Potrola <mateuszx.potrola@intel.com>
Co-developed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Marco Chiappero <marco.chiappero@intel.com>
Reviewed-by: Fiona Trahe <fiona.trahe@intel.com>
Reviewed-by: Marco Chiappero <marco.chiappero@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Tomasz Kowalik and committed by
Herbert Xu
0cec19c7 beb1e6d7

+147 -13
+72 -7
drivers/crypto/qat/qat_4xxx/adf_4xxx_hw_data.c
··· 2 2 /* Copyright(c) 2020 - 2021 Intel Corporation */ 3 3 #include <linux/iopoll.h> 4 4 #include <adf_accel_devices.h> 5 + #include <adf_cfg.h> 5 6 #include <adf_common_drv.h> 6 7 #include <adf_gen4_hw_data.h> 7 8 #include <adf_gen4_pfvf.h> ··· 14 13 char *obj_name; 15 14 }; 16 15 17 - static struct adf_fw_config adf_4xxx_fw_config[] = { 16 + static struct adf_fw_config adf_4xxx_fw_cy_config[] = { 18 17 {0xF0, ADF_4XXX_SYM_OBJ}, 19 18 {0xF, ADF_4XXX_ASYM_OBJ}, 19 + {0x100, ADF_4XXX_ADMIN_OBJ}, 20 + }; 21 + 22 + static struct adf_fw_config adf_4xxx_fw_dc_config[] = { 23 + {0xF0, ADF_4XXX_DC_OBJ}, 24 + {0xF, ADF_4XXX_DC_OBJ}, 20 25 {0x100, ADF_4XXX_ADMIN_OBJ}, 21 26 }; 22 27 ··· 38 31 .type = DEV_4XXX, 39 32 .instances = 0, 40 33 }; 34 + 35 + enum dev_services { 36 + SVC_CY = 0, 37 + SVC_DC, 38 + }; 39 + 40 + static const char *const dev_cfg_services[] = { 41 + [SVC_CY] = ADF_CFG_CY, 42 + [SVC_DC] = ADF_CFG_DC, 43 + }; 44 + 45 + static int get_service_enabled(struct adf_accel_dev *accel_dev) 46 + { 47 + char services[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; 48 + u32 ret; 49 + 50 + ret = adf_cfg_get_param_value(accel_dev, ADF_GENERAL_SEC, 51 + ADF_SERVICES_ENABLED, services); 52 + if (ret) { 53 + dev_err(&GET_DEV(accel_dev), 54 + ADF_SERVICES_ENABLED " param not found\n"); 55 + return ret; 56 + } 57 + 58 + ret = match_string(dev_cfg_services, ARRAY_SIZE(dev_cfg_services), 59 + services); 60 + if (ret < 0) 61 + dev_err(&GET_DEV(accel_dev), 62 + "Invalid value of " ADF_SERVICES_ENABLED " param: %s\n", 63 + services); 64 + 65 + return ret; 66 + } 41 67 42 68 static u32 get_accel_mask(struct adf_hw_device_data *self) 43 69 { ··· 189 149 capabilities_dc &= ~ICP_ACCEL_CAPABILITIES_CNV_INTEGRITY64; 190 150 } 191 151 192 - return capabilities_cy; 152 + switch (get_service_enabled(accel_dev)) { 153 + case SVC_CY: 154 + return capabilities_cy; 155 + case SVC_DC: 156 + return capabilities_dc; 157 + } 158 + 159 + return 0; 193 160 } 194 161 195 162 static enum dev_sku_info get_sku(struct adf_hw_device_data *self) ··· 277 230 278 231 static u32 uof_get_num_objs(void) 279 232 { 280 - return ARRAY_SIZE(adf_4xxx_fw_config); 233 + BUILD_BUG_ON_MSG(ARRAY_SIZE(adf_4xxx_fw_cy_config) != 234 + ARRAY_SIZE(adf_4xxx_fw_dc_config), 235 + "Size mismatch between adf_4xxx_fw_*_config arrays"); 236 + 237 + return ARRAY_SIZE(adf_4xxx_fw_cy_config); 281 238 } 282 239 283 - static char *uof_get_name(u32 obj_num) 240 + static char *uof_get_name(struct adf_accel_dev *accel_dev, u32 obj_num) 284 241 { 285 - return adf_4xxx_fw_config[obj_num].obj_name; 242 + switch (get_service_enabled(accel_dev)) { 243 + case SVC_CY: 244 + return adf_4xxx_fw_cy_config[obj_num].obj_name; 245 + case SVC_DC: 246 + return adf_4xxx_fw_dc_config[obj_num].obj_name; 247 + } 248 + 249 + return NULL; 286 250 } 287 251 288 - static u32 uof_get_ae_mask(u32 obj_num) 252 + static u32 uof_get_ae_mask(struct adf_accel_dev *accel_dev, u32 obj_num) 289 253 { 290 - return adf_4xxx_fw_config[obj_num].ae_mask; 254 + switch (get_service_enabled(accel_dev)) { 255 + case SVC_CY: 256 + return adf_4xxx_fw_cy_config[obj_num].ae_mask; 257 + case SVC_DC: 258 + return adf_4xxx_fw_dc_config[obj_num].ae_mask; 259 + } 260 + 261 + return 0; 291 262 } 292 263 293 264 void adf_init_hw_data_4xxx(struct adf_hw_device_data *hw_data)
+1
drivers/crypto/qat/qat_4xxx/adf_4xxx_hw_data.h
··· 77 77 #define ADF_4XXX_FW "qat_4xxx.bin" 78 78 #define ADF_4XXX_MMP "qat_4xxx_mmp.bin" 79 79 #define ADF_4XXX_SYM_OBJ "qat_4xxx_sym.bin" 80 + #define ADF_4XXX_DC_OBJ "qat_4xxx_dc.bin" 80 81 #define ADF_4XXX_ASYM_OBJ "qat_4xxx_asym.bin" 81 82 #define ADF_4XXX_ADMIN_OBJ "qat_4xxx_admin.bin" 82 83
+33
drivers/crypto/qat/qat_4xxx/adf_drv.c
··· 29 29 adf_devmgr_rm_dev(accel_dev, NULL); 30 30 } 31 31 32 + static int adf_cfg_dev_init(struct adf_accel_dev *accel_dev) 33 + { 34 + const char *config; 35 + int ret; 36 + 37 + config = accel_dev->accel_id % 2 ? ADF_CFG_DC : ADF_CFG_CY; 38 + 39 + ret = adf_cfg_section_add(accel_dev, ADF_GENERAL_SEC); 40 + if (ret) 41 + return ret; 42 + 43 + /* Default configuration is crypto only for even devices 44 + * and compression for odd devices 45 + */ 46 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_GENERAL_SEC, 47 + ADF_SERVICES_ENABLED, config, 48 + ADF_STR); 49 + if (ret) 50 + return ret; 51 + 52 + return 0; 53 + } 54 + 32 55 static int adf_crypto_dev_config(struct adf_accel_dev *accel_dev) 33 56 { 34 57 char key[ADF_CFG_MAX_KEY_LEN_IN_BYTES]; ··· 250 227 goto out_err; 251 228 } 252 229 230 + ret = adf_cfg_dev_init(accel_dev); 231 + if (ret) { 232 + dev_err(&pdev->dev, "Failed to initialize configuration.\n"); 233 + goto out_err; 234 + } 235 + 253 236 /* Get accelerator capabilities mask */ 254 237 hw_data->accel_capabilities_mask = hw_data->get_accel_cap(accel_dev); 238 + if (!hw_data->accel_capabilities_mask) { 239 + dev_err(&pdev->dev, "Failed to get capabilities mask.\n"); 240 + goto out_err; 241 + } 255 242 256 243 /* Find and map all the device's BARS */ 257 244 bar_mask = pci_select_bars(pdev, IORESOURCE_MEM) & ADF_4XXX_BAR_MASK;
+2 -2
drivers/crypto/qat/qat_common/adf_accel_devices.h
··· 192 192 int (*ring_pair_reset)(struct adf_accel_dev *accel_dev, u32 bank_nr); 193 193 void (*reset_device)(struct adf_accel_dev *accel_dev); 194 194 void (*set_msix_rttable)(struct adf_accel_dev *accel_dev); 195 - char *(*uof_get_name)(u32 obj_num); 195 + char *(*uof_get_name)(struct adf_accel_dev *accel_dev, u32 obj_num); 196 196 u32 (*uof_get_num_objs)(void); 197 - u32 (*uof_get_ae_mask)(u32 obj_num); 197 + u32 (*uof_get_ae_mask)(struct adf_accel_dev *accel_dev, u32 obj_num); 198 198 struct adf_pfvf_ops pfvf_ops; 199 199 struct adf_hw_csr_ops csr_ops; 200 200 const char *fw_name;
+6 -2
drivers/crypto/qat/qat_common/adf_accel_engine.c
··· 22 22 num_objs = hw_device->uof_get_num_objs(); 23 23 24 24 for (i = 0; i < num_objs; i++) { 25 - obj_name = hw_device->uof_get_name(i); 26 - ae_mask = hw_device->uof_get_ae_mask(i); 25 + obj_name = hw_device->uof_get_name(accel_dev, i); 26 + ae_mask = hw_device->uof_get_ae_mask(accel_dev, i); 27 + if (!obj_name || !ae_mask) { 28 + dev_err(&GET_DEV(accel_dev), "Invalid UOF image\n"); 29 + goto out_err; 30 + } 27 31 28 32 if (qat_uclo_set_cfg_ae_mask(loader, ae_mask)) { 29 33 dev_err(&GET_DEV(accel_dev),
+1
drivers/crypto/qat/qat_common/adf_cfg.c
··· 297 297 up_read(&cfg->lock); 298 298 return ret; 299 299 } 300 + EXPORT_SYMBOL_GPL(adf_cfg_get_param_value);
+3
drivers/crypto/qat/qat_common/adf_cfg_strings.h
··· 22 22 #define ADF_RING_ASYM_BANK_NUM "BankAsymNumber" 23 23 #define ADF_CY "Cy" 24 24 #define ADF_DC "Dc" 25 + #define ADF_CFG_DC "dc" 26 + #define ADF_CFG_CY "sym;asym" 27 + #define ADF_SERVICES_ENABLED "ServicesEnabled" 25 28 #define ADF_ETRMGR_COALESCING_ENABLED "InterruptCoalescingEnabled" 26 29 #define ADF_ETRMGR_COALESCING_ENABLED_FORMAT \ 27 30 ADF_ETRMGR_BANK "%d" ADF_ETRMGR_COALESCING_ENABLED
+29 -2
drivers/crypto/qat/qat_common/adf_sriov.c
··· 126 126 } 127 127 EXPORT_SYMBOL_GPL(adf_disable_sriov); 128 128 129 + static int adf_sriov_prepare_restart(struct adf_accel_dev *accel_dev) 130 + { 131 + char services[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; 132 + int ret; 133 + 134 + ret = adf_cfg_get_param_value(accel_dev, ADF_GENERAL_SEC, 135 + ADF_SERVICES_ENABLED, services); 136 + 137 + adf_dev_stop(accel_dev); 138 + adf_dev_shutdown(accel_dev); 139 + 140 + if (!ret) { 141 + ret = adf_cfg_section_add(accel_dev, ADF_GENERAL_SEC); 142 + if (ret) 143 + return ret; 144 + 145 + ret = adf_cfg_add_key_value_param(accel_dev, ADF_GENERAL_SEC, 146 + ADF_SERVICES_ENABLED, 147 + services, ADF_STR); 148 + if (ret) 149 + return ret; 150 + } 151 + 152 + return 0; 153 + } 154 + 129 155 /** 130 156 * adf_sriov_configure() - Enable SRIOV for the device 131 157 * @pdev: Pointer to PCI device. ··· 191 165 return -EBUSY; 192 166 } 193 167 194 - adf_dev_stop(accel_dev); 195 - adf_dev_shutdown(accel_dev); 168 + ret = adf_sriov_prepare_restart(accel_dev); 169 + if (ret) 170 + return ret; 196 171 } 197 172 198 173 if (adf_cfg_section_add(accel_dev, ADF_KERNEL_SEC))