Skip to content

Commit 84ca4e5

Browse files
Pascal van Leeuwenherbertx
authored andcommitted
crypto: inside-secure - Add support for 256 bit wide internal bus
This patch adds support for large EIP197's with a 256 bit wide internal bus, which affects the format of the result descriptor due to internal alignment requirements. Signed-off-by: Pascal van Leeuwen <pvanleeuwen@verimatrix.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent a9a8962 commit 84ca4e5

3 files changed

Lines changed: 72 additions & 51 deletions

File tree

‎drivers/crypto/inside-secure/safexcel.c‎

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
572572
static 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

863870
inline 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
10191031
acknowledge:
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

12931305
static 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

13211328
static 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);

‎drivers/crypto/inside-secure/safexcel.h‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@
213213
/* EIP197_HIA_xDR_PROC_COUNT */
214214
#define EIP197_xDR_PROC_xD_PKT_OFFSET 24
215215
#define EIP197_xDR_PROC_xD_PKT_MASK GENMASK(6, 0)
216-
#define EIP197_xDR_PROC_xD_COUNT(n) ((n) << 2)
217216
#define EIP197_xDR_PROC_xD_PKT(n) ((n) << 24)
218217
#define EIP197_xDR_PROC_CLR_COUNT BIT(31)
219218

@@ -228,6 +227,8 @@
228227
#define EIP197_HIA_RA_PE_CTRL_EN BIT(30)
229228

230229
/* EIP197_HIA_OPTIONS */
230+
#define EIP197_N_RINGS_OFFSET 0
231+
#define EIP197_N_RINGS_MASK GENMASK(3, 0)
231232
#define EIP197_N_PES_OFFSET 4
232233
#define EIP197_N_PES_MASK GENMASK(4, 0)
233234
#define EIP97_N_PES_MASK GENMASK(2, 0)
@@ -486,16 +487,15 @@ struct safexcel_result_desc {
486487

487488
u32 data_lo;
488489
u32 data_hi;
489-
490-
struct result_data_desc result_data;
491490
} __packed;
492491

493492
/*
494493
* The EIP(1)97 only needs to fetch the descriptor part of
495494
* the result descriptor, not the result token part!
496495
*/
497-
#define EIP197_RD64_FETCH_SIZE ((sizeof(struct safexcel_result_desc) -\
498-
sizeof(struct result_data_desc)) /\
496+
#define EIP197_RD64_FETCH_SIZE (sizeof(struct safexcel_result_desc) /\
497+
sizeof(u32))
498+
#define EIP197_RD64_RESULT_SIZE (sizeof(struct result_data_desc) /\
499499
sizeof(u32))
500500

501501
struct safexcel_token {
@@ -582,6 +582,9 @@ struct safexcel_command_desc {
582582
struct safexcel_control_data_desc control_data;
583583
} __packed;
584584

585+
#define EIP197_CD64_FETCH_SIZE (sizeof(struct safexcel_command_desc) /\
586+
sizeof(u32))
587+
585588
/*
586589
* Internal structures & functions
587590
*/
@@ -625,6 +628,7 @@ struct safexcel_config {
625628

626629
u32 rd_size;
627630
u32 rd_offset;
631+
u32 res_offset;
628632
};
629633

630634
struct safexcel_work_data {
@@ -734,6 +738,8 @@ struct safexcel_hwconfig {
734738
int hwdataw;
735739
int hwcfsize;
736740
int hwrfsize;
741+
int hwnumpes;
742+
int hwnumrings;
737743
};
738744

739745
struct safexcel_crypto_priv {
@@ -805,7 +811,7 @@ struct safexcel_inv_result {
805811

806812
void safexcel_dequeue(struct safexcel_crypto_priv *priv, int ring);
807813
int safexcel_rdesc_check_errors(struct safexcel_crypto_priv *priv,
808-
struct safexcel_result_desc *rdesc);
814+
void *rdp);
809815
void safexcel_complete(struct safexcel_crypto_priv *priv, int ring);
810816
int safexcel_invalidate_cache(struct crypto_async_request *async,
811817
struct safexcel_crypto_priv *priv,

‎drivers/crypto/inside-secure/safexcel_ring.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int safexcel_init_ring_descriptors(struct safexcel_crypto_priv *priv,
1414
struct safexcel_desc_ring *cdr,
1515
struct safexcel_desc_ring *rdr)
1616
{
17-
cdr->offset = sizeof(u32) * priv->config.cd_offset;
17+
cdr->offset = priv->config.cd_offset;
1818
cdr->base = dmam_alloc_coherent(priv->dev,
1919
cdr->offset * EIP197_DEFAULT_RING_SIZE,
2020
&cdr->base_dma, GFP_KERNEL);
@@ -24,7 +24,7 @@ int safexcel_init_ring_descriptors(struct safexcel_crypto_priv *priv,
2424
cdr->base_end = cdr->base + cdr->offset * (EIP197_DEFAULT_RING_SIZE - 1);
2525
cdr->read = cdr->base;
2626

27-
rdr->offset = sizeof(u32) * priv->config.rd_offset;
27+
rdr->offset = priv->config.rd_offset;
2828
rdr->base = dmam_alloc_coherent(priv->dev,
2929
rdr->offset * EIP197_DEFAULT_RING_SIZE,
3030
&rdr->base_dma, GFP_KERNEL);

0 commit comments

Comments
 (0)