Skip to content

Commit b2d92ac

Browse files
Pascal van Leeuwenherbertx
authored andcommitted
crypto: inside-secure - Base RD fetchcount on actual RD FIFO size
This patch derives the result descriptor fetch count from the actual FIFO size advertised by the hardware. Fetching result 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 35c0e6c commit b2d92ac

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

drivers/crypto/inside-secure/safexcel.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,22 @@ static int safexcel_hw_setup_cdesc_rings(struct safexcel_crypto_priv *priv)
357357
static int safexcel_hw_setup_rdesc_rings(struct safexcel_crypto_priv *priv)
358358
{
359359
u32 hdw, rd_size_rnd, val;
360-
int i;
361-
362-
hdw = readl(EIP197_HIA_AIC_G(priv) + EIP197_HIA_OPTIONS);
363-
hdw &= GENMASK(27, 25);
364-
hdw >>= 25;
360+
int i, rd_fetch_cnt;
365361

366-
rd_size_rnd = (priv->config.rd_size + (BIT(hdw) - 1)) >> hdw;
362+
/* determine number of RD's we can fetch into the FIFO as one block */
363+
rd_size_rnd = (EIP197_RD64_FETCH_SIZE +
364+
BIT(priv->hwconfig.hwdataw) - 1) >>
365+
priv->hwconfig.hwdataw;
366+
if (priv->flags & SAFEXCEL_HW_EIP197) {
367+
/* EIP197: try to fetch enough in 1 go to keep all pipes busy */
368+
rd_fetch_cnt = (1 << priv->hwconfig.hwrfsize) / rd_size_rnd;
369+
rd_fetch_cnt = min_t(uint, rd_fetch_cnt,
370+
(priv->config.pes * EIP197_FETCH_DEPTH));
371+
} else {
372+
/* for the EIP97, just fetch all that fits minus 1 */
373+
rd_fetch_cnt = ((1 << priv->hwconfig.hwrfsize) /
374+
rd_size_rnd) - 1;
375+
}
367376

368377
for (i = 0; i < priv->config.rings; i++) {
369378
/* ring base address */
@@ -376,8 +385,8 @@ static int safexcel_hw_setup_rdesc_rings(struct safexcel_crypto_priv *priv)
376385
priv->config.rd_size,
377386
EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_DESC_SIZE);
378387

379-
writel(((EIP197_FETCH_COUNT * (rd_size_rnd << hdw)) << 16) |
380-
(EIP197_FETCH_COUNT * priv->config.rd_offset),
388+
writel(((rd_fetch_cnt * (rd_size_rnd << hdw)) << 16) |
389+
(rd_fetch_cnt * priv->config.rd_offset),
381390
EIP197_HIA_RDR(priv, i) + EIP197_HIA_xDR_CFG);
382391

383392
/* Configure DMA tx control */
@@ -1244,23 +1253,29 @@ static int safexcel_probe_generic(void *pdev,
12441253
priv->hwconfig.hwcfsize = ((hiaopt >> EIP197_CFSIZE_OFFSET) &
12451254
EIP197_CFSIZE_MASK) +
12461255
EIP197_CFSIZE_ADJUST;
1256+
priv->hwconfig.hwrfsize = ((hiaopt >> EIP197_RFSIZE_OFFSET) &
1257+
EIP197_RFSIZE_MASK) +
1258+
EIP197_RFSIZE_ADJUST;
12471259
} else {
12481260
/* EIP97 */
12491261
priv->hwconfig.hwdataw = (hiaopt >> EIP197_HWDATAW_OFFSET) &
12501262
EIP97_HWDATAW_MASK;
12511263
priv->hwconfig.hwcfsize = (hiaopt >> EIP97_CFSIZE_OFFSET) &
12521264
EIP97_CFSIZE_MASK;
1265+
priv->hwconfig.hwrfsize = (hiaopt >> EIP97_RFSIZE_OFFSET) &
1266+
EIP97_RFSIZE_MASK;
12531267
}
12541268

12551269
/* Get supported algorithms from EIP96 transform engine */
12561270
priv->hwconfig.algo_flags = readl(EIP197_PE(priv) +
12571271
EIP197_PE_EIP96_OPTIONS(0));
12581272

12591273
/* Print single info line describing what we just detected */
1260-
dev_info(priv->dev, "EIP%d:%x(%d)-HIA:%x(%d,%d),PE:%x,alg:%08x\n", peid,
1261-
priv->hwconfig.hwver, hwctg, priv->hwconfig.hiaver,
1274+
dev_info(priv->dev, "EIP%d:%x(%d)-HIA:%x(%d,%d,%d),PE:%x,alg:%08x\n",
1275+
peid, priv->hwconfig.hwver, hwctg, priv->hwconfig.hiaver,
12621276
priv->hwconfig.hwdataw, priv->hwconfig.hwcfsize,
1263-
priv->hwconfig.pever, priv->hwconfig.algo_flags);
1277+
priv->hwconfig.hwrfsize, priv->hwconfig.pever,
1278+
priv->hwconfig.algo_flags);
12641279

12651280
safexcel_configure(priv);
12661281

drivers/crypto/inside-secure/safexcel.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#define EIP197_DEFAULT_RING_SIZE 400
3131
#define EIP197_MAX_TOKENS 18
3232
#define EIP197_MAX_RINGS 4
33-
#define EIP197_FETCH_COUNT 1
3433
#define EIP197_FETCH_DEPTH 2
3534
#define EIP197_MAX_BATCH_SZ 64
3635

@@ -234,6 +233,11 @@
234233
#define EIP97_CFSIZE_OFFSET 8
235234
#define EIP197_CFSIZE_MASK GENMASK(3, 0)
236235
#define EIP97_CFSIZE_MASK GENMASK(4, 0)
236+
#define EIP197_RFSIZE_OFFSET 12
237+
#define EIP197_RFSIZE_ADJUST 4
238+
#define EIP97_RFSIZE_OFFSET 12
239+
#define EIP197_RFSIZE_MASK GENMASK(3, 0)
240+
#define EIP97_RFSIZE_MASK GENMASK(4, 0)
237241

238242
/* EIP197_HIA_AIC_R_ENABLE_CTRL */
239243
#define EIP197_CDR_IRQ(n) BIT((n) * 2)
@@ -462,6 +466,14 @@ struct safexcel_result_desc {
462466
struct result_data_desc result_data;
463467
} __packed;
464468

469+
/*
470+
* The EIP(1)97 only needs to fetch the descriptor part of
471+
* the result descriptor, not the result token part!
472+
*/
473+
#define EIP197_RD64_FETCH_SIZE ((sizeof(struct safexcel_result_desc) -\
474+
sizeof(struct result_data_desc)) /\
475+
sizeof(u32))
476+
465477
struct safexcel_token {
466478
u32 packet_length:17;
467479
u8 stat:2;
@@ -691,6 +703,7 @@ struct safexcel_hwconfig {
691703
int pever;
692704
int hwdataw;
693705
int hwcfsize;
706+
int hwrfsize;
694707
};
695708

696709
struct safexcel_crypto_priv {

0 commit comments

Comments
 (0)