@@ -393,29 +393,21 @@ static int safexcel_hw_setup_rdesc_rings(struct safexcel_crypto_priv *priv)
393
393
394
394
static int safexcel_hw_init (struct safexcel_crypto_priv * priv )
395
395
{
396
- u32 version , val ;
396
+ u32 val ;
397
397
int i , ret , pe ;
398
398
399
399
dev_dbg (priv -> dev , "HW init: using %d pipe(s) and %d ring(s)\n" ,
400
400
priv -> config .pes , priv -> config .rings );
401
401
402
- /* Determine endianess and configure byte swap */
403
- version = readl (EIP197_HIA_AIC (priv ) + EIP197_HIA_VERSION );
404
- val = readl (EIP197_HIA_AIC (priv ) + EIP197_HIA_MST_CTRL );
405
-
406
- if ((version & 0xffff ) == EIP197_HIA_VERSION_BE )
407
- val |= EIP197_MST_CTRL_BYTE_SWAP ;
408
- else if (((version >> 16 ) & 0xffff ) == EIP197_HIA_VERSION_LE )
409
- val |= (EIP197_MST_CTRL_NO_BYTE_SWAP >> 24 );
410
-
411
402
/*
412
403
* For EIP197's only set maximum number of TX commands to 2^5 = 32
413
404
* Skip for the EIP97 as it does not have this field.
414
405
*/
415
- if (priv -> version != EIP97IES_MRVL )
406
+ if (priv -> flags & SAFEXCEL_HW_EIP197 ) {
407
+ val = readl (EIP197_HIA_AIC (priv ) + EIP197_HIA_MST_CTRL );
416
408
val |= EIP197_MST_CTRL_TX_MAX_CMD (5 );
417
-
418
- writel ( val , EIP197_HIA_AIC ( priv ) + EIP197_HIA_MST_CTRL );
409
+ writel ( val , EIP197_HIA_AIC ( priv ) + EIP197_HIA_MST_CTRL );
410
+ }
419
411
420
412
/* Configure wr/rd cache values */
421
413
writel (EIP197_MST_CTRL_RD_CACHE (RD_CACHE_4BITS ) |
@@ -438,7 +430,7 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
438
430
writel (EIP197_DxE_THR_CTRL_RESET_PE ,
439
431
EIP197_HIA_DFE_THR (priv ) + EIP197_HIA_DFE_THR_CTRL (pe ));
440
432
441
- if (priv -> version != EIP97IES_MRVL )
433
+ if (priv -> flags & SAFEXCEL_HW_EIP197 )
442
434
/* Reset HIA input interface arbiter (EIP197 only) */
443
435
writel (EIP197_HIA_RA_PE_CTRL_RESET ,
444
436
EIP197_HIA_AIC (priv ) + EIP197_HIA_RA_PE_CTRL (pe ));
@@ -464,7 +456,7 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
464
456
EIP197_PE_IN_xBUF_THRES_MAX (7 ),
465
457
EIP197_PE (priv ) + EIP197_PE_IN_TBUF_THRES (pe ));
466
458
467
- if (priv -> version != EIP97IES_MRVL )
459
+ if (priv -> flags & SAFEXCEL_HW_EIP197 )
468
460
/* enable HIA input interface arbiter and rings */
469
461
writel (EIP197_HIA_RA_PE_CTRL_EN |
470
462
GENMASK (priv -> config .rings - 1 , 0 ),
@@ -490,7 +482,7 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
490
482
/* FIXME: instability issues can occur for EIP97 but disabling
491
483
* it impacts performance.
492
484
*/
493
- if (priv -> version != EIP97IES_MRVL )
485
+ if (priv -> flags & SAFEXCEL_HW_EIP197 )
494
486
val |= EIP197_HIA_DSE_CFG_EN_SINGLE_WR ;
495
487
writel (val , EIP197_HIA_DSE (priv ) + EIP197_HIA_DSE_CFG (pe ));
496
488
@@ -577,8 +569,9 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
577
569
/* Clear any HIA interrupt */
578
570
writel (GENMASK (30 , 20 ), EIP197_HIA_AIC_G (priv ) + EIP197_HIA_AIC_G_ACK );
579
571
580
- if (priv -> version != EIP97IES_MRVL ) {
572
+ if (priv -> flags & SAFEXCEL_HW_EIP197 ) {
581
573
eip197_trc_cache_init (priv );
574
+ priv -> flags |= EIP197_TRC_CACHE ;
582
575
583
576
ret = eip197_load_firmwares (priv );
584
577
if (ret )
@@ -1083,12 +1076,12 @@ static void safexcel_configure(struct safexcel_crypto_priv *priv)
1083
1076
val = readl (EIP197_HIA_AIC_G (priv ) + EIP197_HIA_OPTIONS );
1084
1077
1085
1078
/* Read number of PEs from the engine */
1086
- if (priv -> version == EIP97IES_MRVL )
1087
- /* Narrow field width for EIP97 type engine */
1088
- mask = EIP97_N_PES_MASK ;
1089
- else
1079
+ if (priv -> flags & SAFEXCEL_HW_EIP197 )
1090
1080
/* Wider field width for all EIP197 type engines */
1091
1081
mask = EIP197_N_PES_MASK ;
1082
+ else
1083
+ /* Narrow field width for EIP97 type engine */
1084
+ mask = EIP97_N_PES_MASK ;
1092
1085
1093
1086
priv -> config .pes = (val >> EIP197_N_PES_OFFSET ) & mask ;
1094
1087
@@ -1108,18 +1101,7 @@ static void safexcel_init_register_offsets(struct safexcel_crypto_priv *priv)
1108
1101
{
1109
1102
struct safexcel_register_offsets * offsets = & priv -> offsets ;
1110
1103
1111
- if (priv -> version == EIP97IES_MRVL ) {
1112
- offsets -> hia_aic = EIP97_HIA_AIC_BASE ;
1113
- offsets -> hia_aic_g = EIP97_HIA_AIC_G_BASE ;
1114
- offsets -> hia_aic_r = EIP97_HIA_AIC_R_BASE ;
1115
- offsets -> hia_aic_xdr = EIP97_HIA_AIC_xDR_BASE ;
1116
- offsets -> hia_dfe = EIP97_HIA_DFE_BASE ;
1117
- offsets -> hia_dfe_thr = EIP97_HIA_DFE_THR_BASE ;
1118
- offsets -> hia_dse = EIP97_HIA_DSE_BASE ;
1119
- offsets -> hia_dse_thr = EIP97_HIA_DSE_THR_BASE ;
1120
- offsets -> hia_gen_cfg = EIP97_HIA_GEN_CFG_BASE ;
1121
- offsets -> pe = EIP97_PE_BASE ;
1122
- } else {
1104
+ if (priv -> flags & SAFEXCEL_HW_EIP197 ) {
1123
1105
offsets -> hia_aic = EIP197_HIA_AIC_BASE ;
1124
1106
offsets -> hia_aic_g = EIP197_HIA_AIC_G_BASE ;
1125
1107
offsets -> hia_aic_r = EIP197_HIA_AIC_R_BASE ;
@@ -1130,6 +1112,19 @@ static void safexcel_init_register_offsets(struct safexcel_crypto_priv *priv)
1130
1112
offsets -> hia_dse_thr = EIP197_HIA_DSE_THR_BASE ;
1131
1113
offsets -> hia_gen_cfg = EIP197_HIA_GEN_CFG_BASE ;
1132
1114
offsets -> pe = EIP197_PE_BASE ;
1115
+ offsets -> global = EIP197_GLOBAL_BASE ;
1116
+ } else {
1117
+ offsets -> hia_aic = EIP97_HIA_AIC_BASE ;
1118
+ offsets -> hia_aic_g = EIP97_HIA_AIC_G_BASE ;
1119
+ offsets -> hia_aic_r = EIP97_HIA_AIC_R_BASE ;
1120
+ offsets -> hia_aic_xdr = EIP97_HIA_AIC_xDR_BASE ;
1121
+ offsets -> hia_dfe = EIP97_HIA_DFE_BASE ;
1122
+ offsets -> hia_dfe_thr = EIP97_HIA_DFE_THR_BASE ;
1123
+ offsets -> hia_dse = EIP97_HIA_DSE_BASE ;
1124
+ offsets -> hia_dse_thr = EIP97_HIA_DSE_THR_BASE ;
1125
+ offsets -> hia_gen_cfg = EIP97_HIA_GEN_CFG_BASE ;
1126
+ offsets -> pe = EIP97_PE_BASE ;
1127
+ offsets -> global = EIP97_GLOBAL_BASE ;
1133
1128
}
1134
1129
}
1135
1130
@@ -1145,32 +1140,98 @@ static int safexcel_probe_generic(void *pdev,
1145
1140
int is_pci_dev )
1146
1141
{
1147
1142
struct device * dev = priv -> dev ;
1148
- u32 peid ;
1149
- int i , ret ;
1143
+ u32 peid , version , mask , val ;
1144
+ int i , ret , hwctg ;
1150
1145
1151
1146
priv -> context_pool = dmam_pool_create ("safexcel-context" , dev ,
1152
1147
sizeof (struct safexcel_context_record ),
1153
1148
1 , 0 );
1154
1149
if (!priv -> context_pool )
1155
1150
return - ENOMEM ;
1156
1151
1152
+ /*
1153
+ * First try the EIP97 HIA version regs
1154
+ * For the EIP197, this is guaranteed to NOT return any of the test
1155
+ * values
1156
+ */
1157
+ version = readl (priv -> base + EIP97_HIA_AIC_BASE + EIP197_HIA_VERSION );
1158
+
1159
+ mask = 0 ; /* do not swap */
1160
+ if (EIP197_REG_LO16 (version ) == EIP197_HIA_VERSION_LE ) {
1161
+ priv -> hwconfig .hiaver = EIP197_VERSION_MASK (version );
1162
+ } else if (EIP197_REG_HI16 (version ) == EIP197_HIA_VERSION_BE ) {
1163
+ /* read back byte-swapped, so complement byte swap bits */
1164
+ mask = EIP197_MST_CTRL_BYTE_SWAP_BITS ;
1165
+ priv -> hwconfig .hiaver = EIP197_VERSION_SWAP (version );
1166
+ } else {
1167
+ /* So it wasn't an EIP97 ... maybe it's an EIP197? */
1168
+ version = readl (priv -> base + EIP197_HIA_AIC_BASE +
1169
+ EIP197_HIA_VERSION );
1170
+ if (EIP197_REG_LO16 (version ) == EIP197_HIA_VERSION_LE ) {
1171
+ priv -> hwconfig .hiaver = EIP197_VERSION_MASK (version );
1172
+ priv -> flags |= SAFEXCEL_HW_EIP197 ;
1173
+ } else if (EIP197_REG_HI16 (version ) ==
1174
+ EIP197_HIA_VERSION_BE ) {
1175
+ /* read back byte-swapped, so complement swap bits */
1176
+ mask = EIP197_MST_CTRL_BYTE_SWAP_BITS ;
1177
+ priv -> hwconfig .hiaver = EIP197_VERSION_SWAP (version );
1178
+ priv -> flags |= SAFEXCEL_HW_EIP197 ;
1179
+ } else {
1180
+ return - ENODEV ;
1181
+ }
1182
+ }
1183
+
1184
+ /* Now initialize the reg offsets based on the probing info so far */
1157
1185
safexcel_init_register_offsets (priv );
1158
1186
1187
+ /*
1188
+ * If the version was read byte-swapped, we need to flip the device
1189
+ * swapping Keep in mind here, though, that what we write will also be
1190
+ * byte-swapped ...
1191
+ */
1192
+ if (mask ) {
1193
+ val = readl (EIP197_HIA_AIC (priv ) + EIP197_HIA_MST_CTRL );
1194
+ val = val ^ (mask >> 24 ); /* toggle byte swap bits */
1195
+ writel (val , EIP197_HIA_AIC (priv ) + EIP197_HIA_MST_CTRL );
1196
+ }
1197
+
1198
+ /*
1199
+ * We're not done probing yet! We may fall through to here if no HIA
1200
+ * was found at all. So, with the endianness presumably correct now and
1201
+ * the offsets setup, *really* probe for the EIP97/EIP197.
1202
+ */
1203
+ version = readl (EIP197_GLOBAL (priv ) + EIP197_VERSION );
1204
+ if (((priv -> flags & SAFEXCEL_HW_EIP197 ) &&
1205
+ (EIP197_REG_LO16 (version ) != EIP197_VERSION_LE )) ||
1206
+ ((!(priv -> flags & SAFEXCEL_HW_EIP197 ) &&
1207
+ (EIP197_REG_LO16 (version ) != EIP97_VERSION_LE )))) {
1208
+ /*
1209
+ * We did not find the device that matched our initial probing
1210
+ * (or our initial probing failed) Report appropriate error.
1211
+ */
1212
+ return - ENODEV ;
1213
+ }
1214
+
1215
+ priv -> hwconfig .hwver = EIP197_VERSION_MASK (version );
1216
+ hwctg = version >> 28 ;
1217
+ peid = version & 255 ;
1218
+
1219
+ /* Detect EIP96 packet engine and version */
1220
+ version = readl (EIP197_PE (priv ) + EIP197_PE_EIP96_VERSION (0 ));
1221
+ if (EIP197_REG_LO16 (version ) != EIP96_VERSION_LE ) {
1222
+ dev_err (dev , "EIP%d: EIP96 not detected.\n" , peid );
1223
+ return - ENODEV ;
1224
+ }
1225
+ priv -> hwconfig .pever = EIP197_VERSION_MASK (version );
1226
+
1159
1227
/* Get supported algorithms from EIP96 transform engine */
1160
1228
priv -> hwconfig .algo_flags = readl (EIP197_PE (priv ) +
1161
1229
EIP197_PE_EIP96_OPTIONS (0 ));
1162
1230
1163
- if (priv -> version == EIP97IES_MRVL ) {
1164
- peid = 97 ;
1165
- } else {
1166
- priv -> flags |= EIP197_TRC_CACHE ;
1167
- peid = 197 ;
1168
- }
1169
-
1170
- /* Dump some debug information important during development */
1171
- dev_dbg (priv -> dev , "Inside Secure EIP%d packetengine\n" , peid );
1172
- dev_dbg (priv -> dev , "Supported algorithms: %08x\n" ,
1173
- priv -> hwconfig .algo_flags );
1231
+ /* Print single info line describing what we just detected */
1232
+ dev_info (priv -> dev , "EIP%d:%x(%d)-HIA:%x,PE:%x,alg:%08x\n" , peid ,
1233
+ priv -> hwconfig .hwver , hwctg , priv -> hwconfig .hiaver ,
1234
+ priv -> hwconfig .pever , priv -> hwconfig .algo_flags );
1174
1235
1175
1236
safexcel_configure (priv );
1176
1237
@@ -1522,7 +1583,6 @@ static const struct pci_device_id safexcel_pci_ids[] = {
1522
1583
{
1523
1584
PCI_DEVICE_SUB (PCI_VENDOR_ID_XILINX , 0x9038 ,
1524
1585
0x16ae , 0xc522 ),
1525
- /* assume EIP197B for now */
1526
1586
.driver_data = EIP197_DEVBRD ,
1527
1587
},
1528
1588
{},
0 commit comments