Skip to content

Commit 098e51e

Browse files
Pascal van Leeuwenherbertx
authored andcommitted
crypto: inside-secure - Fix Unable to fit even 1 command desc error w/ EIP97
Due to the additions of support for modes like AES-CCM and AES-GCM, which require large command tokens, the size of the descriptor has grown such that it now does not fit into the descriptor cache of a standard EIP97 anymore. This means that the driver no longer works on the Marvell Armada 3700LP chip (as used on e.g. Espressobin) that it has always supported. Additionally, performance on EIP197's like Marvell A8K may also degrade due to being able to fit less descriptors in the on-chip cache. Putting these tokens into the descriptor was really a hack and not how the design was supposed to be used - resource allocation did not account for it. So what this patch does, is move the command token out of the descriptor. To avoid having to allocate buffers on the fly for these command tokens, they are stuffed in a "shadow ring", which is a circular buffer of fixed size blocks that runs in lock-step with the descriptor ring. i.e. there is one token block per descriptor. The descriptor ring itself is then pre- populated with the pointers to these token blocks so these do not need to be filled in when building the descriptors later. Signed-off-by: Pascal van Leeuwen <pvanleeuwen@rambus.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent a306376 commit 098e51e

5 files changed

Lines changed: 446 additions & 249 deletions

File tree

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ static int safexcel_hw_setup_cdesc_rings(struct safexcel_crypto_priv *priv)
501501
writel(upper_32_bits(priv->ring[i].cdr.base_dma),
502502
EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_RING_BASE_ADDR_HI);
503503

504-
writel(EIP197_xDR_DESC_MODE_64BIT | (priv->config.cd_offset << 14) |
505-
priv->config.cd_size,
504+
writel(EIP197_xDR_DESC_MODE_64BIT | EIP197_CDR_DESC_MODE_ADCP |
505+
(priv->config.cd_offset << 14) | priv->config.cd_size,
506506
EIP197_HIA_CDR(priv, i) + EIP197_HIA_xDR_DESC_SIZE);
507507
writel(((cd_fetch_cnt *
508508
(cd_size_rnd << priv->hwconfig.hwdataw)) << 16) |
@@ -974,16 +974,18 @@ int safexcel_invalidate_cache(struct crypto_async_request *async,
974974
{
975975
struct safexcel_command_desc *cdesc;
976976
struct safexcel_result_desc *rdesc;
977+
struct safexcel_token *dmmy;
977978
int ret = 0;
978979

979980
/* Prepare command descriptor */
980-
cdesc = safexcel_add_cdesc(priv, ring, true, true, 0, 0, 0, ctxr_dma);
981+
cdesc = safexcel_add_cdesc(priv, ring, true, true, 0, 0, 0, ctxr_dma,
982+
&dmmy);
981983
if (IS_ERR(cdesc))
982984
return PTR_ERR(cdesc);
983985

984986
cdesc->control_data.type = EIP197_TYPE_EXTENDED;
985987
cdesc->control_data.options = 0;
986-
cdesc->control_data.refresh = 0;
988+
cdesc->control_data.context_lo &= ~EIP197_CONTEXT_SIZE_MASK;
987989
cdesc->control_data.control0 = CONTEXT_CONTROL_INV_TR;
988990

989991
/* Prepare result descriptor */
@@ -1331,6 +1333,7 @@ static void safexcel_configure(struct safexcel_crypto_priv *priv)
13311333

13321334
priv->config.cd_size = EIP197_CD64_FETCH_SIZE;
13331335
priv->config.cd_offset = (priv->config.cd_size + mask) & ~mask;
1336+
priv->config.cdsh_offset = (EIP197_MAX_TOKENS + mask) & ~mask;
13341337

13351338
/* res token is behind the descr, but ofs must be rounded to buswdth */
13361339
priv->config.res_offset = (EIP197_RD64_FETCH_SIZE + mask) & ~mask;
@@ -1341,6 +1344,7 @@ static void safexcel_configure(struct safexcel_crypto_priv *priv)
13411344

13421345
/* convert dwords to bytes */
13431346
priv->config.cd_offset *= sizeof(u32);
1347+
priv->config.cdsh_offset *= sizeof(u32);
13441348
priv->config.rd_offset *= sizeof(u32);
13451349
priv->config.res_offset *= sizeof(u32);
13461350
}

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040

4141
/* Static configuration */
4242
#define EIP197_DEFAULT_RING_SIZE 400
43-
#define EIP197_MAX_TOKENS 19
43+
#define EIP197_EMB_TOKENS 4 /* Pad CD to 16 dwords */
44+
#define EIP197_MAX_TOKENS 16
4445
#define EIP197_MAX_RINGS 4
4546
#define EIP197_FETCH_DEPTH 2
4647
#define EIP197_MAX_BATCH_SZ 64
@@ -207,6 +208,7 @@
207208

208209
/* EIP197_HIA_xDR_DESC_SIZE */
209210
#define EIP197_xDR_DESC_MODE_64BIT BIT(31)
211+
#define EIP197_CDR_DESC_MODE_ADCP BIT(30)
210212

211213
/* EIP197_HIA_xDR_DMA_CFG */
212214
#define EIP197_HIA_xDR_WR_RES_BUF BIT(22)
@@ -277,9 +279,9 @@
277279
#define EIP197_HIA_DxE_CFG_MIN_CTRL_SIZE(n) ((n) << 16)
278280
#define EIP197_HIA_DxE_CFG_CTRL_CACHE_CTRL(n) (((n) & 0x7) << 20)
279281
#define EIP197_HIA_DxE_CFG_MAX_CTRL_SIZE(n) ((n) << 24)
280-
#define EIP197_HIA_DFE_CFG_DIS_DEBUG (BIT(31) | BIT(29))
282+
#define EIP197_HIA_DFE_CFG_DIS_DEBUG GENMASK(31, 29)
281283
#define EIP197_HIA_DSE_CFG_EN_SINGLE_WR BIT(29)
282-
#define EIP197_HIA_DSE_CFG_DIS_DEBUG BIT(31)
284+
#define EIP197_HIA_DSE_CFG_DIS_DEBUG GENMASK(31, 30)
283285

284286
/* EIP197_HIA_DFE/DSE_THR_CTRL */
285287
#define EIP197_DxE_THR_CTRL_EN BIT(30)
@@ -553,6 +555,8 @@ static inline void eip197_noop_token(struct safexcel_token *token)
553555
{
554556
token->opcode = EIP197_TOKEN_OPCODE_NOOP;
555557
token->packet_length = BIT(2);
558+
token->stat = 0;
559+
token->instructions = 0;
556560
}
557561

558562
/* Instructions */
@@ -574,14 +578,13 @@ struct safexcel_control_data_desc {
574578
u16 application_id;
575579
u16 rsvd;
576580

577-
u8 refresh:2;
578-
u32 context_lo:30;
581+
u32 context_lo;
579582
u32 context_hi;
580583

581584
u32 control0;
582585
u32 control1;
583586

584-
u32 token[EIP197_MAX_TOKENS];
587+
u32 token[EIP197_EMB_TOKENS];
585588
} __packed;
586589

587590
#define EIP197_OPTION_MAGIC_VALUE BIT(0)
@@ -591,21 +594,27 @@ struct safexcel_control_data_desc {
591594
#define EIP197_OPTION_2_TOKEN_IV_CMD GENMASK(11, 10)
592595
#define EIP197_OPTION_4_TOKEN_IV_CMD GENMASK(11, 9)
593596

597+
#define EIP197_TYPE_BCLA 0x0
594598
#define EIP197_TYPE_EXTENDED 0x3
599+
#define EIP197_CONTEXT_SMALL 0x2
600+
#define EIP197_CONTEXT_SIZE_MASK 0x3
595601

596602
/* Basic Command Descriptor format */
597603
struct safexcel_command_desc {
598604
u32 particle_size:17;
599605
u8 rsvd0:5;
600606
u8 last_seg:1;
601607
u8 first_seg:1;
602-
u16 additional_cdata_size:8;
608+
u8 additional_cdata_size:8;
603609

604610
u32 rsvd1;
605611

606612
u32 data_lo;
607613
u32 data_hi;
608614

615+
u32 atok_lo;
616+
u32 atok_hi;
617+
609618
struct safexcel_control_data_desc control_data;
610619
} __packed;
611620

@@ -629,15 +638,20 @@ enum eip197_fw {
629638

630639
struct safexcel_desc_ring {
631640
void *base;
641+
void *shbase;
632642
void *base_end;
643+
void *shbase_end;
633644
dma_addr_t base_dma;
645+
dma_addr_t shbase_dma;
634646

635647
/* write and read pointers */
636648
void *write;
649+
void *shwrite;
637650
void *read;
638651

639652
/* descriptor element offset */
640-
unsigned offset;
653+
unsigned int offset;
654+
unsigned int shoffset;
641655
};
642656

643657
enum safexcel_alg_type {
@@ -652,6 +666,7 @@ struct safexcel_config {
652666

653667
u32 cd_size;
654668
u32 cd_offset;
669+
u32 cdsh_offset;
655670

656671
u32 rd_size;
657672
u32 rd_offset;
@@ -862,7 +877,8 @@ struct safexcel_command_desc *safexcel_add_cdesc(struct safexcel_crypto_priv *pr
862877
bool first, bool last,
863878
dma_addr_t data, u32 len,
864879
u32 full_data_len,
865-
dma_addr_t context);
880+
dma_addr_t context,
881+
struct safexcel_token **atoken);
866882
struct safexcel_result_desc *safexcel_add_rdesc(struct safexcel_crypto_priv *priv,
867883
int ring_id,
868884
bool first, bool last,

0 commit comments

Comments
 (0)