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: hisilicon/hpre - save capability registers in probe process

Pre-store the valid value of hpre alg support related capability
register in hpre_qm_init(), which will be called by hpre_probe().
It can reduce the number of capability register queries and avoid
obtaining incorrect values in abnormal scenarios, such as reset
failed and the memory space disabled.

Fixes: f214d59a0603 ("crypto: hisilicon/hpre - support hpre capability")
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Zhiqi Song and committed by
Herbert Xu
cf8b5156 cabe13d0

+64 -18
+64 -18
drivers/crypto/hisilicon/hpre/hpre_main.c
··· 226 226 {HPRE_CORE10_ALG_BITMAP_CAP, 0x3170, 0, GENMASK(31, 0), 0x0, 0x10, 0x10} 227 227 }; 228 228 229 + enum hpre_pre_store_cap_idx { 230 + HPRE_CLUSTER_NUM_CAP_IDX = 0x0, 231 + HPRE_CORE_ENABLE_BITMAP_CAP_IDX, 232 + HPRE_DRV_ALG_BITMAP_CAP_IDX, 233 + HPRE_DEV_ALG_BITMAP_CAP_IDX, 234 + }; 235 + 236 + static const u32 hpre_pre_store_caps[] = { 237 + HPRE_CLUSTER_NUM_CAP, 238 + HPRE_CORE_ENABLE_BITMAP_CAP, 239 + HPRE_DRV_ALG_BITMAP_CAP, 240 + HPRE_DEV_ALG_BITMAP_CAP, 241 + }; 242 + 229 243 static const struct hpre_hw_error hpre_hw_errors[] = { 230 244 { 231 245 .int_msk = BIT(0), ··· 362 348 { 363 349 u32 cap_val; 364 350 365 - cap_val = hisi_qm_get_hw_info(qm, hpre_basic_info, HPRE_DRV_ALG_BITMAP_CAP, qm->cap_ver); 351 + cap_val = qm->cap_tables.dev_cap_table[HPRE_DRV_ALG_BITMAP_CAP_IDX].cap_val; 366 352 if (alg & cap_val) 367 353 return true; 368 354 ··· 438 424 module_param_cb(vfs_num, &vfs_num_ops, &vfs_num, 0444); 439 425 MODULE_PARM_DESC(vfs_num, "Number of VFs to enable(1-63), 0(default)"); 440 426 441 - static inline int hpre_cluster_num(struct hisi_qm *qm) 442 - { 443 - return hisi_qm_get_hw_info(qm, hpre_basic_info, HPRE_CLUSTER_NUM_CAP, qm->cap_ver); 444 - } 445 - 446 - static inline int hpre_cluster_core_mask(struct hisi_qm *qm) 447 - { 448 - return hisi_qm_get_hw_info(qm, hpre_basic_info, HPRE_CORE_ENABLE_BITMAP_CAP, qm->cap_ver); 449 - } 450 - 451 427 struct hisi_qp *hpre_create_qp(u8 type) 452 428 { 453 429 int node = cpu_to_node(smp_processor_id()); ··· 504 500 505 501 static int hpre_set_cluster(struct hisi_qm *qm) 506 502 { 507 - u32 cluster_core_mask = hpre_cluster_core_mask(qm); 508 - u8 clusters_num = hpre_cluster_num(qm); 509 503 struct device *dev = &qm->pdev->dev; 510 504 unsigned long offset; 505 + u32 cluster_core_mask; 506 + u8 clusters_num; 511 507 u32 val = 0; 512 508 int ret, i; 513 509 510 + cluster_core_mask = qm->cap_tables.dev_cap_table[HPRE_CORE_ENABLE_BITMAP_CAP_IDX].cap_val; 511 + clusters_num = qm->cap_tables.dev_cap_table[HPRE_CLUSTER_NUM_CAP_IDX].cap_val; 514 512 for (i = 0; i < clusters_num; i++) { 515 513 offset = i * HPRE_CLSTR_ADDR_INTRVL; 516 514 ··· 707 701 708 702 static void hpre_cnt_regs_clear(struct hisi_qm *qm) 709 703 { 710 - u8 clusters_num = hpre_cluster_num(qm); 711 704 unsigned long offset; 705 + u8 clusters_num; 712 706 int i; 713 707 714 708 /* clear clusterX/cluster_ctrl */ 709 + clusters_num = qm->cap_tables.dev_cap_table[HPRE_CLUSTER_NUM_CAP_IDX].cap_val; 715 710 for (i = 0; i < clusters_num; i++) { 716 711 offset = HPRE_CLSTR_BASE + i * HPRE_CLSTR_ADDR_INTRVL; 717 712 writel(0x0, qm->io_base + offset + HPRE_CLUSTER_INQURY); ··· 999 992 1000 993 static int hpre_cluster_debugfs_init(struct hisi_qm *qm) 1001 994 { 1002 - u8 clusters_num = hpre_cluster_num(qm); 1003 995 struct device *dev = &qm->pdev->dev; 1004 996 char buf[HPRE_DBGFS_VAL_MAX_LEN]; 1005 997 struct debugfs_regset32 *regset; 1006 998 struct dentry *tmp_d; 999 + u8 clusters_num; 1007 1000 int i, ret; 1008 1001 1002 + clusters_num = qm->cap_tables.dev_cap_table[HPRE_CLUSTER_NUM_CAP_IDX].cap_val; 1009 1003 for (i = 0; i < clusters_num; i++) { 1010 1004 ret = snprintf(buf, HPRE_DBGFS_VAL_MAX_LEN, "cluster%d", i); 1011 1005 if (ret >= HPRE_DBGFS_VAL_MAX_LEN) ··· 1111 1103 debugfs_remove_recursive(qm->debug.debug_root); 1112 1104 } 1113 1105 1106 + static int hpre_pre_store_cap_reg(struct hisi_qm *qm) 1107 + { 1108 + struct hisi_qm_cap_record *hpre_cap; 1109 + struct device *dev = &qm->pdev->dev; 1110 + size_t i, size; 1111 + 1112 + size = ARRAY_SIZE(hpre_pre_store_caps); 1113 + hpre_cap = devm_kzalloc(dev, sizeof(*hpre_cap) * size, GFP_KERNEL); 1114 + if (!hpre_cap) 1115 + return -ENOMEM; 1116 + 1117 + for (i = 0; i < size; i++) { 1118 + hpre_cap[i].type = hpre_pre_store_caps[i]; 1119 + hpre_cap[i].cap_val = hisi_qm_get_hw_info(qm, hpre_basic_info, 1120 + hpre_pre_store_caps[i], qm->cap_ver); 1121 + } 1122 + 1123 + if (hpre_cap[HPRE_CLUSTER_NUM_CAP_IDX].cap_val > HPRE_CLUSTERS_NUM_MAX) { 1124 + dev_err(dev, "Device cluster num %u is out of range for driver supports %d!\n", 1125 + hpre_cap[HPRE_CLUSTER_NUM_CAP_IDX].cap_val, HPRE_CLUSTERS_NUM_MAX); 1126 + return -EINVAL; 1127 + } 1128 + 1129 + qm->cap_tables.dev_cap_table = hpre_cap; 1130 + 1131 + return 0; 1132 + } 1133 + 1114 1134 static int hpre_qm_init(struct hisi_qm *qm, struct pci_dev *pdev) 1115 1135 { 1116 1136 u64 alg_msk; ··· 1172 1136 return ret; 1173 1137 } 1174 1138 1175 - alg_msk = hisi_qm_get_hw_info(qm, hpre_basic_info, HPRE_DEV_ALG_BITMAP_CAP, qm->cap_ver); 1139 + /* Fetch and save the value of capability registers */ 1140 + ret = hpre_pre_store_cap_reg(qm); 1141 + if (ret) { 1142 + pci_err(pdev, "Failed to pre-store capability registers!\n"); 1143 + hisi_qm_uninit(qm); 1144 + return ret; 1145 + } 1146 + 1147 + alg_msk = qm->cap_tables.dev_cap_table[HPRE_DEV_ALG_BITMAP_CAP_IDX].cap_val; 1176 1148 ret = hisi_qm_set_algs(qm, alg_msk, hpre_dev_algs, ARRAY_SIZE(hpre_dev_algs)); 1177 1149 if (ret) { 1178 1150 pci_err(pdev, "Failed to set hpre algs!\n"); ··· 1194 1150 { 1195 1151 int cluster_dfx_regs_num = ARRAY_SIZE(hpre_cluster_dfx_regs); 1196 1152 int com_dfx_regs_num = ARRAY_SIZE(hpre_com_dfx_regs); 1197 - u8 clusters_num = hpre_cluster_num(qm); 1198 1153 struct qm_debug *debug = &qm->debug; 1199 1154 void __iomem *io_base; 1155 + u8 clusters_num; 1200 1156 int i, j, idx; 1201 1157 1158 + clusters_num = qm->cap_tables.dev_cap_table[HPRE_CLUSTER_NUM_CAP_IDX].cap_val; 1202 1159 debug->last_words = kcalloc(cluster_dfx_regs_num * clusters_num + 1203 1160 com_dfx_regs_num, sizeof(unsigned int), GFP_KERNEL); 1204 1161 if (!debug->last_words) ··· 1236 1191 { 1237 1192 int cluster_dfx_regs_num = ARRAY_SIZE(hpre_cluster_dfx_regs); 1238 1193 int com_dfx_regs_num = ARRAY_SIZE(hpre_com_dfx_regs); 1239 - u8 clusters_num = hpre_cluster_num(qm); 1240 1194 struct qm_debug *debug = &qm->debug; 1241 1195 struct pci_dev *pdev = qm->pdev; 1242 1196 void __iomem *io_base; 1197 + u8 clusters_num; 1243 1198 int i, j, idx; 1244 1199 u32 val; 1245 1200 ··· 1254 1209 hpre_com_dfx_regs[i].name, debug->last_words[i], val); 1255 1210 } 1256 1211 1212 + clusters_num = qm->cap_tables.dev_cap_table[HPRE_CLUSTER_NUM_CAP_IDX].cap_val; 1257 1213 for (i = 0; i < clusters_num; i++) { 1258 1214 io_base = qm->io_base + hpre_cluster_offsets[i]; 1259 1215 for (j = 0; j < cluster_dfx_regs_num; j++) {