@@ -492,12 +492,12 @@ static int safexcel_hw_setup_cdesc_rings(struct safexcel_crypto_priv *priv)
492492 writel (upper_32_bits (priv -> ring [i ].cdr .base_dma ),
493493 EIP197_HIA_CDR (priv , i ) + EIP197_HIA_xDR_RING_BASE_ADDR_HI );
494494
495- writel (EIP197_xDR_DESC_MODE_64BIT | (priv -> config .cd_offset << 16 ) |
495+ writel (EIP197_xDR_DESC_MODE_64BIT | (priv -> config .cd_offset << 14 ) |
496496 priv -> config .cd_size ,
497497 EIP197_HIA_CDR (priv , i ) + EIP197_HIA_xDR_DESC_SIZE );
498498 writel (((cd_fetch_cnt *
499499 (cd_size_rnd << priv -> hwconfig .hwdataw )) << 16 ) |
500- (cd_fetch_cnt * priv -> config .cd_offset ),
500+ (cd_fetch_cnt * ( priv -> config .cd_offset / sizeof ( u32 )) ),
501501 EIP197_HIA_CDR (priv , i ) + EIP197_HIA_xDR_CFG );
502502
503503 /* Configure DMA tx control */
@@ -540,13 +540,13 @@ static int safexcel_hw_setup_rdesc_rings(struct safexcel_crypto_priv *priv)
540540 writel (upper_32_bits (priv -> ring [i ].rdr .base_dma ),
541541 EIP197_HIA_RDR (priv , i ) + EIP197_HIA_xDR_RING_BASE_ADDR_HI );
542542
543- writel (EIP197_xDR_DESC_MODE_64BIT | (priv -> config .rd_offset << 16 ) |
543+ writel (EIP197_xDR_DESC_MODE_64BIT | (priv -> config .rd_offset << 14 ) |
544544 priv -> config .rd_size ,
545545 EIP197_HIA_RDR (priv , i ) + EIP197_HIA_xDR_DESC_SIZE );
546546
547547 writel (((rd_fetch_cnt *
548548 (rd_size_rnd << priv -> hwconfig .hwdataw )) << 16 ) |
549- (rd_fetch_cnt * priv -> config .rd_offset ),
549+ (rd_fetch_cnt * ( priv -> config .rd_offset / sizeof ( u32 )) ),
550550 EIP197_HIA_RDR (priv , i ) + EIP197_HIA_xDR_CFG );
551551
552552 /* Configure DMA tx control */
@@ -572,7 +572,7 @@ static int safexcel_hw_setup_rdesc_rings(struct safexcel_crypto_priv *priv)
572572static int safexcel_hw_init (struct safexcel_crypto_priv * priv )
573573{
574574 u32 val ;
575- int i , ret , pe ;
575+ int i , ret , pe , opbuflo , opbufhi ;
576576
577577 dev_dbg (priv -> dev , "HW init: using %d pipe(s) and %d ring(s)\n" ,
578578 priv -> config .pes , priv -> config .rings );
@@ -652,9 +652,16 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
652652 ;
653653
654654 /* DMA transfer size to use */
655+ if (priv -> hwconfig .hwnumpes > 4 ) {
656+ opbuflo = 9 ;
657+ opbufhi = 10 ;
658+ } else {
659+ opbuflo = 7 ;
660+ opbufhi = 8 ;
661+ }
655662 val = EIP197_HIA_DSE_CFG_DIS_DEBUG ;
656- val |= EIP197_HIA_DxE_CFG_MIN_DATA_SIZE (7 ) |
657- EIP197_HIA_DxE_CFG_MAX_DATA_SIZE (8 );
663+ val |= EIP197_HIA_DxE_CFG_MIN_DATA_SIZE (opbuflo ) |
664+ EIP197_HIA_DxE_CFG_MAX_DATA_SIZE (opbufhi );
658665 val |= EIP197_HIA_DxE_CFG_DATA_CACHE_CTRL (WR_CACHE_3BITS );
659666 val |= EIP197_HIA_DSE_CFG_ALWAYS_BUFFERABLE ;
660667 /* FIXME: instability issues can occur for EIP97 but disabling
@@ -668,8 +675,8 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
668675 writel (0 , EIP197_HIA_DSE_THR (priv ) + EIP197_HIA_DSE_THR_CTRL (pe ));
669676
670677 /* Configure the procesing engine thresholds */
671- writel (EIP197_PE_OUT_DBUF_THRES_MIN (7 ) |
672- EIP197_PE_OUT_DBUF_THRES_MAX (8 ),
678+ writel (EIP197_PE_OUT_DBUF_THRES_MIN (opbuflo ) |
679+ EIP197_PE_OUT_DBUF_THRES_MAX (opbufhi ),
673680 EIP197_PE (priv ) + EIP197_PE_OUT_DBUF_THRES (pe ));
674681
675682 /* Processing Engine configuration */
@@ -709,7 +716,7 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
709716 writel (0 ,
710717 EIP197_HIA_CDR (priv , i ) + EIP197_HIA_xDR_PROC_PNTR );
711718
712- writel ((EIP197_DEFAULT_RING_SIZE * priv -> config .cd_offset ) << 2 ,
719+ writel ((EIP197_DEFAULT_RING_SIZE * priv -> config .cd_offset ),
713720 EIP197_HIA_CDR (priv , i ) + EIP197_HIA_xDR_RING_SIZE );
714721 }
715722
@@ -732,7 +739,7 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
732739 EIP197_HIA_RDR (priv , i ) + EIP197_HIA_xDR_PROC_PNTR );
733740
734741 /* Ring size */
735- writel ((EIP197_DEFAULT_RING_SIZE * priv -> config .rd_offset ) << 2 ,
742+ writel ((EIP197_DEFAULT_RING_SIZE * priv -> config .rd_offset ),
736743 EIP197_HIA_RDR (priv , i ) + EIP197_HIA_xDR_RING_SIZE );
737744 }
738745
@@ -852,20 +859,24 @@ void safexcel_dequeue(struct safexcel_crypto_priv *priv, int ring)
852859 spin_unlock_bh (& priv -> ring [ring ].lock );
853860
854861 /* let the RDR know we have pending descriptors */
855- writel ((rdesc * priv -> config .rd_offset ) << 2 ,
862+ writel ((rdesc * priv -> config .rd_offset ),
856863 EIP197_HIA_RDR (priv , ring ) + EIP197_HIA_xDR_PREP_COUNT );
857864
858865 /* let the CDR know we have pending descriptors */
859- writel ((cdesc * priv -> config .cd_offset ) << 2 ,
866+ writel ((cdesc * priv -> config .cd_offset ),
860867 EIP197_HIA_CDR (priv , ring ) + EIP197_HIA_xDR_PREP_COUNT );
861868}
862869
863870inline int safexcel_rdesc_check_errors (struct safexcel_crypto_priv * priv ,
864- struct safexcel_result_desc * rdesc )
871+ void * rdp )
865872{
866- if (likely ((!rdesc -> descriptor_overflow ) &&
867- (!rdesc -> buffer_overflow ) &&
868- (!rdesc -> result_data .error_code )))
873+ struct safexcel_result_desc * rdesc = rdp ;
874+ struct result_data_desc * result_data = rdp + priv -> config .res_offset ;
875+
876+ if (likely ((!rdesc -> last_seg ) || /* Rest only valid if last seg! */
877+ ((!rdesc -> descriptor_overflow ) &&
878+ (!rdesc -> buffer_overflow ) &&
879+ (!result_data -> error_code ))))
869880 return 0 ;
870881
871882 if (rdesc -> descriptor_overflow )
@@ -874,21 +885,22 @@ inline int safexcel_rdesc_check_errors(struct safexcel_crypto_priv *priv,
874885 if (rdesc -> buffer_overflow )
875886 dev_err (priv -> dev , "Buffer overflow detected" );
876887
877- if (rdesc -> result_data . error_code & 0x4066 ) {
888+ if (result_data -> error_code & 0x4066 ) {
878889 /* Fatal error (bits 1,2,5,6 & 14) */
879890 dev_err (priv -> dev ,
880891 "result descriptor error (%x)" ,
881- rdesc -> result_data .error_code );
892+ result_data -> error_code );
893+
882894 return - EIO ;
883- } else if (rdesc -> result_data . error_code &
895+ } else if (result_data -> error_code &
884896 (BIT (7 ) | BIT (4 ) | BIT (3 ) | BIT (0 ))) {
885897 /*
886898 * Give priority over authentication fails:
887899 * Blocksize, length & overflow errors,
888900 * something wrong with the input!
889901 */
890902 return - EINVAL ;
891- } else if (rdesc -> result_data . error_code & BIT (9 )) {
903+ } else if (result_data -> error_code & BIT (9 )) {
892904 /* Authentication failed */
893905 return - EBADMSG ;
894906 }
@@ -1019,7 +1031,7 @@ static inline void safexcel_handle_result_descriptor(struct safexcel_crypto_priv
10191031acknowledge :
10201032 if (i )
10211033 writel (EIP197_xDR_PROC_xD_PKT (i ) |
1022- EIP197_xDR_PROC_xD_COUNT (tot_descs * priv -> config .rd_offset ),
1034+ (tot_descs * priv -> config .rd_offset ),
10231035 EIP197_HIA_RDR (priv , ring ) + EIP197_HIA_xDR_PROC_COUNT );
10241036
10251037 /* If the number of requests overflowed the counter, try to proceed more
@@ -1292,30 +1304,25 @@ static void safexcel_unregister_algorithms(struct safexcel_crypto_priv *priv)
12921304
12931305static void safexcel_configure (struct safexcel_crypto_priv * priv )
12941306{
1295- u32 val , mask = 0 ;
1296-
1297- val = readl (EIP197_HIA_AIC_G (priv ) + EIP197_HIA_OPTIONS );
1307+ u32 mask = BIT (priv -> hwconfig .hwdataw ) - 1 ;
12981308
1299- /* Read number of PEs from the engine */
1300- if (priv -> flags & SAFEXCEL_HW_EIP197 )
1301- /* Wider field width for all EIP197 type engines */
1302- mask = EIP197_N_PES_MASK ;
1303- else
1304- /* Narrow field width for EIP97 type engine */
1305- mask = EIP97_N_PES_MASK ;
1306-
1307- priv -> config .pes = (val >> EIP197_N_PES_OFFSET ) & mask ;
1308-
1309- priv -> config .rings = min_t (u32 , val & GENMASK (3 , 0 ), max_rings );
1309+ priv -> config .pes = priv -> hwconfig .hwnumpes ;
1310+ priv -> config .rings = min_t (u32 , priv -> hwconfig .hwnumrings , max_rings );
13101311
1311- val = (val & GENMASK (27 , 25 )) >> 25 ;
1312- mask = BIT (val ) - 1 ;
1313-
1314- priv -> config .cd_size = (sizeof (struct safexcel_command_desc ) / sizeof (u32 ));
1312+ priv -> config .cd_size = EIP197_CD64_FETCH_SIZE ;
13151313 priv -> config .cd_offset = (priv -> config .cd_size + mask ) & ~mask ;
13161314
1317- priv -> config .rd_size = (sizeof (struct safexcel_result_desc ) / sizeof (u32 ));
1315+ /* res token is behind the descr, but ofs must be rounded to buswdth */
1316+ priv -> config .res_offset = (EIP197_RD64_FETCH_SIZE + mask ) & ~mask ;
1317+ /* now the size of the descr is this 1st part plus the result struct */
1318+ priv -> config .rd_size = priv -> config .res_offset +
1319+ EIP197_RD64_RESULT_SIZE ;
13181320 priv -> config .rd_offset = (priv -> config .rd_size + mask ) & ~mask ;
1321+
1322+ /* convert dwords to bytes */
1323+ priv -> config .cd_offset *= sizeof (u32 );
1324+ priv -> config .rd_offset *= sizeof (u32 );
1325+ priv -> config .res_offset *= sizeof (u32 );
13191326}
13201327
13211328static void safexcel_init_register_offsets (struct safexcel_crypto_priv * priv )
@@ -1457,6 +1464,10 @@ static int safexcel_probe_generic(void *pdev,
14571464 priv -> hwconfig .hwrfsize = ((hiaopt >> EIP197_RFSIZE_OFFSET ) &
14581465 EIP197_RFSIZE_MASK ) +
14591466 EIP197_RFSIZE_ADJUST ;
1467+ priv -> hwconfig .hwnumpes = (hiaopt >> EIP197_N_PES_OFFSET ) &
1468+ EIP197_N_PES_MASK ;
1469+ priv -> hwconfig .hwnumrings = (hiaopt >> EIP197_N_RINGS_OFFSET ) &
1470+ EIP197_N_RINGS_MASK ;
14601471 } else {
14611472 /* EIP97 */
14621473 priv -> hwconfig .hwdataw = (hiaopt >> EIP197_HWDATAW_OFFSET ) &
@@ -1465,15 +1476,19 @@ static int safexcel_probe_generic(void *pdev,
14651476 EIP97_CFSIZE_MASK ;
14661477 priv -> hwconfig .hwrfsize = (hiaopt >> EIP97_RFSIZE_OFFSET ) &
14671478 EIP97_RFSIZE_MASK ;
1479+ priv -> hwconfig .hwnumpes = 1 ; /* by definition */
1480+ priv -> hwconfig .hwnumrings = (hiaopt >> EIP197_N_RINGS_OFFSET ) &
1481+ EIP197_N_RINGS_MASK ;
14681482 }
14691483
14701484 /* Get supported algorithms from EIP96 transform engine */
14711485 priv -> hwconfig .algo_flags = readl (EIP197_PE (priv ) +
14721486 EIP197_PE_EIP96_OPTIONS (0 ));
14731487
14741488 /* Print single info line describing what we just detected */
1475- dev_info (priv -> dev , "EIP%d:%x(%d)-HIA:%x(%d,%d,%d),PE:%x,alg:%08x\n" ,
1476- peid , priv -> hwconfig .hwver , hwctg , priv -> hwconfig .hiaver ,
1489+ dev_info (priv -> dev , "EIP%d:%x(%d,%d,%d,%d)-HIA:%x(%d,%d,%d),PE:%x,alg:%08x\n" ,
1490+ peid , priv -> hwconfig .hwver , hwctg , priv -> hwconfig .hwnumpes ,
1491+ priv -> hwconfig .hwnumrings , priv -> hwconfig .hiaver ,
14771492 priv -> hwconfig .hwdataw , priv -> hwconfig .hwcfsize ,
14781493 priv -> hwconfig .hwrfsize , priv -> hwconfig .pever ,
14791494 priv -> hwconfig .algo_flags );
0 commit comments