Skip to content

Commit 5fd39c4

Browse files
Pascal van Leeuwenherbertx
authored andcommitted
crypto: inside-secure - Add support for the EIP196
This patch adds support for the EIP196, which is an EIP197 derivative that has no classification hardware and a simplified record cache. The patch has been tested with the eip196b-ie and eip197c-iewxkbc configurations on the Xilinx VCU118 development board as well as on the Macchiatobin board (Marvell A8K - EIP197b-ieswx), including the crypto extra tests. Note that this patchset applies on top of the earlier submitted "Add support for eip197f_iewc" series. Signed-off-by: Pascal van Leeuwen <pvanleeuwen@verimatrix.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 9e5de3e commit 5fd39c4

3 files changed

Lines changed: 86 additions & 14 deletions

File tree

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

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@ static int safexcel_hw_setup_cdesc_rings(struct safexcel_crypto_priv *priv)
484484
cd_fetch_cnt = ((1 << priv->hwconfig.hwcfsize) /
485485
cd_size_rnd) - 1;
486486
}
487+
/*
488+
* Since we're using command desc's way larger than formally specified,
489+
* we need to check whether we can fit even 1 for low-end EIP196's!
490+
*/
491+
if (!cd_fetch_cnt) {
492+
dev_err(priv->dev, "Unable to fit even 1 command desc!\n");
493+
return -ENODEV;
494+
}
487495

488496
for (i = 0; i < priv->config.rings; i++) {
489497
/* ring base address */
@@ -608,8 +616,8 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
608616
writel(EIP197_DxE_THR_CTRL_RESET_PE,
609617
EIP197_HIA_DFE_THR(priv) + EIP197_HIA_DFE_THR_CTRL(pe));
610618

611-
if (priv->flags & SAFEXCEL_HW_EIP197)
612-
/* Reset HIA input interface arbiter (EIP197 only) */
619+
if (priv->flags & EIP197_PE_ARB)
620+
/* Reset HIA input interface arbiter (if present) */
613621
writel(EIP197_HIA_RA_PE_CTRL_RESET,
614622
EIP197_HIA_AIC(priv) + EIP197_HIA_RA_PE_CTRL(pe));
615623

@@ -756,22 +764,28 @@ static int safexcel_hw_init(struct safexcel_crypto_priv *priv)
756764
/* Clear any HIA interrupt */
757765
writel(GENMASK(30, 20), EIP197_HIA_AIC_G(priv) + EIP197_HIA_AIC_G_ACK);
758766

759-
if (priv->flags & SAFEXCEL_HW_EIP197) {
767+
if (priv->flags & EIP197_SIMPLE_TRC) {
768+
writel(EIP197_STRC_CONFIG_INIT |
769+
EIP197_STRC_CONFIG_LARGE_REC(EIP197_CS_TRC_REC_WC) |
770+
EIP197_STRC_CONFIG_SMALL_REC(EIP197_CS_TRC_REC_WC),
771+
priv->base + EIP197_STRC_CONFIG);
772+
writel(EIP197_PE_EIP96_TOKEN_CTRL2_CTX_DONE,
773+
EIP197_PE(priv) + EIP197_PE_EIP96_TOKEN_CTRL2(0));
774+
} else if (priv->flags & SAFEXCEL_HW_EIP197) {
760775
ret = eip197_trc_cache_init(priv);
761776
if (ret)
762777
return ret;
778+
}
763779

764-
priv->flags |= EIP197_TRC_CACHE;
765-
780+
if (priv->flags & EIP197_ICE) {
766781
ret = eip197_load_firmwares(priv);
767782
if (ret)
768783
return ret;
769784
}
770785

771-
safexcel_hw_setup_cdesc_rings(priv);
772-
safexcel_hw_setup_rdesc_rings(priv);
773-
774-
return 0;
786+
return safexcel_hw_setup_cdesc_rings(priv) ?:
787+
safexcel_hw_setup_rdesc_rings(priv) ?:
788+
0;
775789
}
776790

777791
/* Called with ring's lock taken */
@@ -1371,7 +1385,7 @@ static int safexcel_probe_generic(void *pdev,
13711385
int is_pci_dev)
13721386
{
13731387
struct device *dev = priv->dev;
1374-
u32 peid, version, mask, val, hiaopt;
1388+
u32 peid, version, mask, val, hiaopt, hwopt, peopt;
13751389
int i, ret, hwctg;
13761390

13771391
priv->context_pool = dmam_pool_create("safexcel-context", dev,
@@ -1433,20 +1447,31 @@ static int safexcel_probe_generic(void *pdev,
14331447
*/
14341448
version = readl(EIP197_GLOBAL(priv) + EIP197_VERSION);
14351449
if (((priv->flags & SAFEXCEL_HW_EIP197) &&
1436-
(EIP197_REG_LO16(version) != EIP197_VERSION_LE)) ||
1450+
(EIP197_REG_LO16(version) != EIP197_VERSION_LE) &&
1451+
(EIP197_REG_LO16(version) != EIP196_VERSION_LE)) ||
14371452
((!(priv->flags & SAFEXCEL_HW_EIP197) &&
14381453
(EIP197_REG_LO16(version) != EIP97_VERSION_LE)))) {
14391454
/*
14401455
* We did not find the device that matched our initial probing
14411456
* (or our initial probing failed) Report appropriate error.
14421457
*/
1458+
dev_err(priv->dev, "Probing for EIP97/EIP19x failed - no such device (read %08x)\n",
1459+
version);
14431460
return -ENODEV;
14441461
}
14451462

14461463
priv->hwconfig.hwver = EIP197_VERSION_MASK(version);
14471464
hwctg = version >> 28;
14481465
peid = version & 255;
14491466

1467+
/* Detect EIP206 processing pipe */
1468+
version = readl(EIP197_PE(priv) + + EIP197_PE_VERSION(0));
1469+
if (EIP197_REG_LO16(version) != EIP206_VERSION_LE) {
1470+
dev_err(priv->dev, "EIP%d: EIP206 not detected\n", peid);
1471+
return -ENODEV;
1472+
}
1473+
priv->hwconfig.ppver = EIP197_VERSION_MASK(version);
1474+
14501475
/* Detect EIP96 packet engine and version */
14511476
version = readl(EIP197_PE(priv) + EIP197_PE_EIP96_VERSION(0));
14521477
if (EIP197_REG_LO16(version) != EIP96_VERSION_LE) {
@@ -1455,10 +1480,13 @@ static int safexcel_probe_generic(void *pdev,
14551480
}
14561481
priv->hwconfig.pever = EIP197_VERSION_MASK(version);
14571482

1483+
hwopt = readl(EIP197_GLOBAL(priv) + EIP197_OPTIONS);
14581484
hiaopt = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_OPTIONS);
14591485

14601486
if (priv->flags & SAFEXCEL_HW_EIP197) {
14611487
/* EIP197 */
1488+
peopt = readl(EIP197_PE(priv) + EIP197_PE_OPTIONS(0));
1489+
14621490
priv->hwconfig.hwdataw = (hiaopt >> EIP197_HWDATAW_OFFSET) &
14631491
EIP197_HWDATAW_MASK;
14641492
priv->hwconfig.hwcfsize = ((hiaopt >> EIP197_CFSIZE_OFFSET) &
@@ -1471,6 +1499,15 @@ static int safexcel_probe_generic(void *pdev,
14711499
EIP197_N_PES_MASK;
14721500
priv->hwconfig.hwnumrings = (hiaopt >> EIP197_N_RINGS_OFFSET) &
14731501
EIP197_N_RINGS_MASK;
1502+
if (hiaopt & EIP197_HIA_OPT_HAS_PE_ARB)
1503+
priv->flags |= EIP197_PE_ARB;
1504+
if (EIP206_OPT_ICE_TYPE(peopt) == 1)
1505+
priv->flags |= EIP197_ICE;
1506+
/* If not a full TRC, then assume simple TRC */
1507+
if (!(hwopt & EIP197_OPT_HAS_TRC))
1508+
priv->flags |= EIP197_SIMPLE_TRC;
1509+
/* EIP197 always has SOME form of TRC */
1510+
priv->flags |= EIP197_TRC_CACHE;
14741511
} else {
14751512
/* EIP97 */
14761513
priv->hwconfig.hwdataw = (hiaopt >> EIP197_HWDATAW_OFFSET) &
@@ -1492,18 +1529,24 @@ static int safexcel_probe_generic(void *pdev,
14921529
break;
14931530
}
14941531
priv->hwconfig.hwnumraic = i;
1532+
/* Low-end EIP196 may not have any ring AIC's ... */
1533+
if (!priv->hwconfig.hwnumraic) {
1534+
dev_err(priv->dev, "No ring interrupt controller present!\n");
1535+
return -ENODEV;
1536+
}
14951537

14961538
/* Get supported algorithms from EIP96 transform engine */
14971539
priv->hwconfig.algo_flags = readl(EIP197_PE(priv) +
14981540
EIP197_PE_EIP96_OPTIONS(0));
14991541

15001542
/* Print single info line describing what we just detected */
1501-
dev_info(priv->dev, "EIP%d:%x(%d,%d,%d,%d)-HIA:%x(%d,%d,%d),PE:%x,alg:%08x\n",
1543+
dev_info(priv->dev, "EIP%d:%x(%d,%d,%d,%d)-HIA:%x(%d,%d,%d),PE:%x/%x,alg:%08x\n",
15021544
peid, priv->hwconfig.hwver, hwctg, priv->hwconfig.hwnumpes,
15031545
priv->hwconfig.hwnumrings, priv->hwconfig.hwnumraic,
15041546
priv->hwconfig.hiaver, priv->hwconfig.hwdataw,
15051547
priv->hwconfig.hwcfsize, priv->hwconfig.hwrfsize,
1506-
priv->hwconfig.pever, priv->hwconfig.algo_flags);
1548+
priv->hwconfig.ppver, priv->hwconfig.pever,
1549+
priv->hwconfig.algo_flags);
15071550

15081551
safexcel_configure(priv);
15091552

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,27 @@
1717
#define EIP197_HIA_VERSION_BE 0xca35
1818
#define EIP197_HIA_VERSION_LE 0x35ca
1919
#define EIP97_VERSION_LE 0x9e61
20+
#define EIP196_VERSION_LE 0x3bc4
2021
#define EIP197_VERSION_LE 0x3ac5
2122
#define EIP96_VERSION_LE 0x9f60
2223
#define EIP201_VERSION_LE 0x36c9
24+
#define EIP206_VERSION_LE 0x31ce
2325
#define EIP197_REG_LO16(reg) (reg & 0xffff)
2426
#define EIP197_REG_HI16(reg) ((reg >> 16) & 0xffff)
2527
#define EIP197_VERSION_MASK(reg) ((reg >> 16) & 0xfff)
2628
#define EIP197_VERSION_SWAP(reg) (((reg & 0xf0) << 4) | \
2729
((reg >> 4) & 0xf0) | \
2830
((reg >> 12) & 0xf))
2931

32+
/* EIP197 HIA OPTIONS ENCODING */
33+
#define EIP197_HIA_OPT_HAS_PE_ARB BIT(29)
34+
35+
/* EIP206 OPTIONS ENCODING */
36+
#define EIP206_OPT_ICE_TYPE(n) ((n>>8)&3)
37+
38+
/* EIP197 OPTIONS ENCODING */
39+
#define EIP197_OPT_HAS_TRC BIT(31)
40+
3041
/* Static configuration */
3142
#define EIP197_DEFAULT_RING_SIZE 400
3243
#define EIP197_MAX_TOKENS 19
@@ -160,12 +171,16 @@
160171
#define EIP197_PE_EIP96_FUNCTION_EN(n) (0x1004 + (0x2000 * (n)))
161172
#define EIP197_PE_EIP96_CONTEXT_CTRL(n) (0x1008 + (0x2000 * (n)))
162173
#define EIP197_PE_EIP96_CONTEXT_STAT(n) (0x100c + (0x2000 * (n)))
174+
#define EIP197_PE_EIP96_TOKEN_CTRL2(n) (0x102c + (0x2000 * (n)))
163175
#define EIP197_PE_EIP96_FUNCTION2_EN(n) (0x1030 + (0x2000 * (n)))
164176
#define EIP197_PE_EIP96_OPTIONS(n) (0x13f8 + (0x2000 * (n)))
165177
#define EIP197_PE_EIP96_VERSION(n) (0x13fc + (0x2000 * (n)))
166178
#define EIP197_PE_OUT_DBUF_THRES(n) (0x1c00 + (0x2000 * (n)))
167179
#define EIP197_PE_OUT_TBUF_THRES(n) (0x1d00 + (0x2000 * (n)))
180+
#define EIP197_PE_OPTIONS(n) (0x1ff8 + (0x2000 * (n)))
181+
#define EIP197_PE_VERSION(n) (0x1ffc + (0x2000 * (n)))
168182
#define EIP197_MST_CTRL 0xfff4
183+
#define EIP197_OPTIONS 0xfff8
169184
#define EIP197_VERSION 0xfffc
170185

171186
/* EIP197-specific registers, no indirection */
@@ -181,6 +196,7 @@
181196
#define EIP197_TRC_ECCADMINSTAT 0xf0838
182197
#define EIP197_TRC_ECCDATASTAT 0xf083c
183198
#define EIP197_TRC_ECCDATA 0xf0840
199+
#define EIP197_STRC_CONFIG 0xf43f0
184200
#define EIP197_FLUE_CACHEBASE_LO(n) (0xf6000 + (32 * (n)))
185201
#define EIP197_FLUE_CACHEBASE_HI(n) (0xf6004 + (32 * (n)))
186202
#define EIP197_FLUE_CONFIG(n) (0xf6010 + (32 * (n)))
@@ -331,6 +347,14 @@
331347
#define EIP197_ADDRESS_MODE BIT(8)
332348
#define EIP197_CONTROL_MODE BIT(9)
333349

350+
/* EIP197_PE_EIP96_TOKEN_CTRL2 */
351+
#define EIP197_PE_EIP96_TOKEN_CTRL2_CTX_DONE BIT(3)
352+
353+
/* EIP197_STRC_CONFIG */
354+
#define EIP197_STRC_CONFIG_INIT BIT(31)
355+
#define EIP197_STRC_CONFIG_LARGE_REC(s) (s<<8)
356+
#define EIP197_STRC_CONFIG_SMALL_REC(s) (s<<0)
357+
334358
/* EIP197_FLUE_CONFIG */
335359
#define EIP197_FLUE_CONFIG_MAGIC 0xc7000004
336360

@@ -472,7 +496,7 @@ struct result_data_desc {
472496
u16 application_id;
473497
u16 rsvd1;
474498

475-
u32 rsvd2;
499+
u32 rsvd2[5];
476500
} __packed;
477501

478502

@@ -731,12 +755,16 @@ struct safexcel_register_offsets {
731755
enum safexcel_flags {
732756
EIP197_TRC_CACHE = BIT(0),
733757
SAFEXCEL_HW_EIP197 = BIT(1),
758+
EIP197_PE_ARB = BIT(2),
759+
EIP197_ICE = BIT(3),
760+
EIP197_SIMPLE_TRC = BIT(4),
734761
};
735762

736763
struct safexcel_hwconfig {
737764
enum safexcel_eip_algorithms algo_flags;
738765
int hwver;
739766
int hiaver;
767+
int ppver;
740768
int pever;
741769
int hwdataw;
742770
int hwcfsize;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ struct safexcel_result_desc *safexcel_add_rdesc(struct safexcel_crypto_priv *pri
180180

181181
rdesc->first_seg = first;
182182
rdesc->last_seg = last;
183+
rdesc->result_size = EIP197_RD64_RESULT_SIZE;
183184
rdesc->particle_size = len;
184185
rdesc->data_lo = lower_32_bits(data);
185186
rdesc->data_hi = upper_32_bits(data);

0 commit comments

Comments
 (0)