Skip to content

Commit 35c0e6c

Browse files
Pascal van Leeuwenherbertx
authored andcommitted
crypto: inside-secure - Base CD fetchcount on actual CD FIFO size
This patch derives the command descriptor fetch count from the actual FIFO size advertised by the hardware. Fetching command descriptors one at a time is a performance bottleneck for small blocks, especially on hardware with multiple pipes. Even moreso if the HW has few rings. Signed-off-by: Pascal van Leeuwen <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 4bdf712 commit 35c0e6c

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

drivers/crypto/inside-secure/safexcel.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,22 @@ static int eip197_load_firmwares(struct safexcel_crypto_priv *priv)
310310
static int safexcel_hw_setup_cdesc_rings(struct safexcel_crypto_priv *priv)
311311
{
312312
u32 hdw, cd_size_rnd, val;
313-
int i;
313+
int i, cd_fetch_cnt;
314314

315-
hdw = readl(EIP197_HIA_AIC_G(priv) + EIP197_HIA_OPTIONS);
316-
hdw &= GENMASK(27, 25);
317-
hdw >>= 25;
318-
319-
cd_size_rnd = (priv->config.cd_size + (BIT(hdw) - 1)) >> hdw;
315+
cd_size_rnd = (priv->config.cd_size +
316+
(BIT(priv->hwconfig.hwdataw) - 1)) >>
317+
priv->hwconfig.hwdataw;
318+
/* determine number of CD's we can fetch into the CD FIFO as 1 block */
319+
if (priv->flags & SAFEXCEL_HW_EIP197) {
320+
/* EIP197: try to fetch enough in 1 go to keep all pipes busy */
321+
cd_fetch_cnt = (1 << priv->hwconfig.hwcfsize) / cd_size_rnd;
322+
cd_fetch_cnt = min_t(uint, cd_fetch_cnt,
323+
(priv->config.pes * EIP197_FETCH_DEPTH));
324+
} else {
325+
/* for the EIP97, just fetch all that fits minus 1 */
326+
cd_fetch_cnt = ((1 << priv->hwconfig.hwcfsize) /
327+
cd_size_rnd) - 1;
328+
}
320329

321330
for (i = 0; i < priv->config.rings; i++) {
322331
/* ring base address */
@@ -328,8 +337,8 @@ static int safexcel_hw_setup_cdesc_rings(struct safexcel_crypto_priv *priv)
328337
writel(EIP197_xDR_DESC_MODE_64BIT | (priv->config.cd_offset << 16) |
329338
priv->config.cd_size,
330339
EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_DESC_SIZE);
331-
writel(((EIP197_FETCH_COUNT * (cd_size_rnd << hdw)) << 16) |
332-
(EIP197_FETCH_COUNT * priv->config.cd_offset),
340+
writel(((cd_fetch_cnt * (cd_size_rnd << hdw)) << 16) |
341+
(cd_fetch_cnt * priv->config.cd_offset),
333342
EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_CFG);
334343

335344
/* Configure DMA tx control */
@@ -1142,7 +1151,7 @@ static int safexcel_probe_generic(void *pdev,
11421151
int is_pci_dev)
11431152
{
11441153
struct device *dev = priv->dev;
1145-
u32 peid, version, mask, val;
1154+
u32 peid, version, mask, val, hiaopt;
11461155
int i, ret, hwctg;
11471156

11481157
priv->context_pool = dmam_pool_create("safexcel-context", dev,
@@ -1226,13 +1235,31 @@ static int safexcel_probe_generic(void *pdev,
12261235
}
12271236
priv->hwconfig.pever = EIP197_VERSION_MASK(version);
12281237

1238+
hiaopt = readl(EIP197_HIA_AIC(priv) + EIP197_HIA_OPTIONS);
1239+
1240+
if (priv->flags & SAFEXCEL_HW_EIP197) {
1241+
/* EIP197 */
1242+
priv->hwconfig.hwdataw = (hiaopt >> EIP197_HWDATAW_OFFSET) &
1243+
EIP197_HWDATAW_MASK;
1244+
priv->hwconfig.hwcfsize = ((hiaopt >> EIP197_CFSIZE_OFFSET) &
1245+
EIP197_CFSIZE_MASK) +
1246+
EIP197_CFSIZE_ADJUST;
1247+
} else {
1248+
/* EIP97 */
1249+
priv->hwconfig.hwdataw = (hiaopt >> EIP197_HWDATAW_OFFSET) &
1250+
EIP97_HWDATAW_MASK;
1251+
priv->hwconfig.hwcfsize = (hiaopt >> EIP97_CFSIZE_OFFSET) &
1252+
EIP97_CFSIZE_MASK;
1253+
}
1254+
12291255
/* Get supported algorithms from EIP96 transform engine */
12301256
priv->hwconfig.algo_flags = readl(EIP197_PE(priv) +
12311257
EIP197_PE_EIP96_OPTIONS(0));
12321258

12331259
/* Print single info line describing what we just detected */
1234-
dev_info(priv->dev, "EIP%d:%x(%d)-HIA:%x,PE:%x,alg:%08x\n", peid,
1260+
dev_info(priv->dev, "EIP%d:%x(%d)-HIA:%x(%d,%d),PE:%x,alg:%08x\n", peid,
12351261
priv->hwconfig.hwver, hwctg, priv->hwconfig.hiaver,
1262+
priv->hwconfig.hwdataw, priv->hwconfig.hwcfsize,
12361263
priv->hwconfig.pever, priv->hwconfig.algo_flags);
12371264

12381265
safexcel_configure(priv);

drivers/crypto/inside-secure/safexcel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define EIP197_MAX_TOKENS 18
3232
#define EIP197_MAX_RINGS 4
3333
#define EIP197_FETCH_COUNT 1
34+
#define EIP197_FETCH_DEPTH 2
3435
#define EIP197_MAX_BATCH_SZ 64
3536

3637
#define EIP197_GFP_FLAGS(base) ((base).flags & CRYPTO_TFM_REQ_MAY_SLEEP ? \
@@ -225,6 +226,14 @@
225226
#define EIP197_N_PES_OFFSET 4
226227
#define EIP197_N_PES_MASK GENMASK(4, 0)
227228
#define EIP97_N_PES_MASK GENMASK(2, 0)
229+
#define EIP197_HWDATAW_OFFSET 25
230+
#define EIP197_HWDATAW_MASK GENMASK(3, 0)
231+
#define EIP97_HWDATAW_MASK GENMASK(2, 0)
232+
#define EIP197_CFSIZE_OFFSET 9
233+
#define EIP197_CFSIZE_ADJUST 4
234+
#define EIP97_CFSIZE_OFFSET 8
235+
#define EIP197_CFSIZE_MASK GENMASK(3, 0)
236+
#define EIP97_CFSIZE_MASK GENMASK(4, 0)
228237

229238
/* EIP197_HIA_AIC_R_ENABLE_CTRL */
230239
#define EIP197_CDR_IRQ(n) BIT((n) * 2)
@@ -680,6 +689,8 @@ struct safexcel_hwconfig {
680689
int hwver;
681690
int hiaver;
682691
int pever;
692+
int hwdataw;
693+
int hwcfsize;
683694
};
684695

685696
struct safexcel_crypto_priv {

0 commit comments

Comments
 (0)