Skip to content

Commit e0740be

Browse files
Andre-ARMherbertx
authored andcommitted
crypto: sun8i-ce - wrap accesses to descriptor address fields
The Allwinner H616 (and later) SoCs support more than 32 bits worth of physical addresses. To accommodate the larger address space, the CE task descriptor fields holding addresses are now encoded as "word addresses", so take the actual address divided by four. This is true for the fields within the descriptor, but also for the descriptor base address, in the CE_TDA register. Wrap all accesses to those fields in a function, which will do the required division if needed. For now this in unused, so there should be no change in behaviour. Signed-off-by: Andre Przywara <[email protected]> Reviewed-by: Chen-Yu Tsai <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 996f8a9 commit e0740be

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
190190
err = -EFAULT;
191191
goto theend;
192192
}
193-
cet->t_key = cpu_to_le32(rctx->addr_key);
193+
cet->t_key = desc_addr_val_le32(ce, rctx->addr_key);
194194

195195
ivsize = crypto_skcipher_ivsize(tfm);
196196
if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) {
@@ -208,7 +208,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
208208
err = -ENOMEM;
209209
goto theend_iv;
210210
}
211-
cet->t_iv = cpu_to_le32(rctx->addr_iv);
211+
cet->t_iv = desc_addr_val_le32(ce, rctx->addr_iv);
212212
}
213213

214214
if (areq->src == areq->dst) {
@@ -236,7 +236,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
236236

237237
len = areq->cryptlen;
238238
for_each_sg(areq->src, sg, nr_sgs, i) {
239-
cet->t_src[i].addr = cpu_to_le32(sg_dma_address(sg));
239+
cet->t_src[i].addr = desc_addr_val_le32(ce, sg_dma_address(sg));
240240
todo = min(len, sg_dma_len(sg));
241241
cet->t_src[i].len = cpu_to_le32(todo / 4);
242242
dev_dbg(ce->dev, "%s total=%u SG(%d %u off=%d) todo=%u\n", __func__,
@@ -251,7 +251,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req
251251

252252
len = areq->cryptlen;
253253
for_each_sg(areq->dst, sg, nr_sgd, i) {
254-
cet->t_dst[i].addr = cpu_to_le32(sg_dma_address(sg));
254+
cet->t_dst[i].addr = desc_addr_val_le32(ce, sg_dma_address(sg));
255255
todo = min(len, sg_dma_len(sg));
256256
cet->t_dst[i].len = cpu_to_le32(todo / 4);
257257
dev_dbg(ce->dev, "%s total=%u SG(%d %u off=%d) todo=%u\n", __func__,

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name)
172172
writel(v, ce->base + CE_ICR);
173173

174174
reinit_completion(&ce->chanlist[flow].complete);
175-
writel(ce->chanlist[flow].t_phy, ce->base + CE_TDQ);
175+
writel(desc_addr_val(ce, ce->chanlist[flow].t_phy), ce->base + CE_TDQ);
176176

177177
ce->chanlist[flow].status = 0;
178178
/* Be sure all data is written before enabling the task */

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
403403

404404
len = areq->nbytes;
405405
for_each_sg(areq->src, sg, nr_sgs, i) {
406-
cet->t_src[i].addr = cpu_to_le32(sg_dma_address(sg));
406+
cet->t_src[i].addr = desc_addr_val_le32(ce, sg_dma_address(sg));
407407
todo = min(len, sg_dma_len(sg));
408408
cet->t_src[i].len = cpu_to_le32(todo / 4);
409409
len -= todo;
@@ -414,7 +414,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
414414
goto theend;
415415
}
416416
addr_res = dma_map_single(ce->dev, result, digestsize, DMA_FROM_DEVICE);
417-
cet->t_dst[0].addr = cpu_to_le32(addr_res);
417+
cet->t_dst[0].addr = desc_addr_val_le32(ce, addr_res);
418418
cet->t_dst[0].len = cpu_to_le32(digestsize / 4);
419419
if (dma_mapping_error(ce->dev, addr_res)) {
420420
dev_err(ce->dev, "DMA map dest\n");
@@ -445,7 +445,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
445445
}
446446

447447
addr_pad = dma_map_single(ce->dev, buf, j * 4, DMA_TO_DEVICE);
448-
cet->t_src[i].addr = cpu_to_le32(addr_pad);
448+
cet->t_src[i].addr = desc_addr_val_le32(ce, addr_pad);
449449
cet->t_src[i].len = cpu_to_le32(j);
450450
if (dma_mapping_error(ce->dev, addr_pad)) {
451451
dev_err(ce->dev, "DMA error on padding SG\n");

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src,
132132
cet->t_sym_ctl = cpu_to_le32(sym);
133133
cet->t_asym_ctl = 0;
134134

135-
cet->t_key = cpu_to_le32(dma_iv);
136-
cet->t_iv = cpu_to_le32(dma_iv);
135+
cet->t_key = desc_addr_val_le32(ce, dma_iv);
136+
cet->t_iv = desc_addr_val_le32(ce, dma_iv);
137137

138-
cet->t_dst[0].addr = cpu_to_le32(dma_dst);
138+
cet->t_dst[0].addr = desc_addr_val_le32(ce, dma_dst);
139139
cet->t_dst[0].len = cpu_to_le32(todo / 4);
140140
ce->chanlist[flow].timeout = 2000;
141141

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wa
7777
cet->t_sym_ctl = 0;
7878
cet->t_asym_ctl = 0;
7979

80-
cet->t_dst[0].addr = cpu_to_le32(dma_dst);
80+
cet->t_dst[0].addr = desc_addr_val_le32(ce, dma_dst);
8181
cet->t_dst[0].len = cpu_to_le32(todo / 4);
8282
ce->chanlist[flow].timeout = todo;
8383

drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct ce_variant {
149149
bool hash_t_dlen_in_bits;
150150
bool prng_t_dlen_in_bytes;
151151
bool trng_t_dlen_in_bytes;
152+
bool needs_word_addresses;
152153
struct ce_clock ce_clks[CE_MAX_CLOCKS];
153154
int esr;
154155
unsigned char prng;
@@ -241,6 +242,20 @@ struct sun8i_ce_dev {
241242
#endif
242243
};
243244

245+
static inline u32 desc_addr_val(struct sun8i_ce_dev *dev, dma_addr_t addr)
246+
{
247+
if (dev->variant->needs_word_addresses)
248+
return addr / 4;
249+
250+
return addr;
251+
}
252+
253+
static inline __le32 desc_addr_val_le32(struct sun8i_ce_dev *dev,
254+
dma_addr_t addr)
255+
{
256+
return cpu_to_le32(desc_addr_val(dev, addr));
257+
}
258+
244259
/*
245260
* struct sun8i_cipher_req_ctx - context for a skcipher request
246261
* @op_dir: direction (encrypt vs decrypt) for this request

0 commit comments

Comments
 (0)