1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright 2021 NXP
4 *
5 * Scatter-gather entry management code for version 2
6 */
7
8 #include <caam_common.h>
9 #include <caam_io.h>
10 #include <caam_utils_sgt.h>
11
sgt_entry_trace(unsigned int idx __maybe_unused,const struct caamsgtbuf * sgt __maybe_unused)12 void sgt_entry_trace(unsigned int idx __maybe_unused,
13 const struct caamsgtbuf *sgt __maybe_unused)
14 {
15 SGT_TRACE("SGT[%d] (%p)", idx, &sgt->sgt[idx]);
16 SGT_TRACE("SGT[%d]->data = %p", idx, sgt->buf[idx].data);
17 SGT_TRACE("SGT[%d]->length = %zu", idx, sgt->buf[idx].length);
18 SGT_TRACE("SGT[%d]->paddr = 0x%" PRIxPA, idx, sgt->buf[idx].paddr);
19 SGT_TRACE("SGT[%d]->w1 = %" PRIx64, idx, sgt->sgt[idx].v2.w1);
20 SGT_TRACE("SGT[%d]->w2 = %" PRIx64, idx, sgt->sgt[idx].v2.w2);
21 }
22
sgt_entry_offset(union caamsgt * sgt,unsigned int offset)23 void sgt_entry_offset(union caamsgt *sgt, unsigned int offset)
24 {
25 uint64_t w2 = 0;
26 uint64_t len = 0;
27 uint64_t off = 0;
28
29 w2 = caam_read_val64(&sgt->v2.w2);
30
31 /*
32 * Compute the new offset reading the one present and adding the
33 * input
34 */
35 off = SGT_V2_ENTRY_OFFSET(w2);
36 off += offset;
37
38 /* Reading length and computing new value by subtracting the offset */
39 len = SGT_V2_ENTRY_AVAIL_LENGTH(w2);
40 len = (offset > len) ? 0 : len - offset;
41
42 /* Clear the offset and length fields */
43 w2 &= ~(BM_SGT_V2_OFFSET | BM_SGT_V2_AVAIL_LENGTH);
44
45 /* Update offset and field */
46 w2 |= BV_SGT_V2_OFFSET(offset) | BV_SGT_V2_AVAIL_LENGTH(len);
47
48 caam_write_val64(&sgt->v2.w2, w2);
49 }
50
caam_sgt_set_entry(union caamsgt * sgt,paddr_t paddr,size_t len,unsigned int offset,bool final_e)51 void caam_sgt_set_entry(union caamsgt *sgt, paddr_t paddr, size_t len,
52 unsigned int offset, bool final_e)
53 {
54 uint64_t w2 = 0;
55
56 /* Write the address to set */
57 caam_write_val64(&sgt->v2.w1, paddr);
58
59 /* Compute the second word */
60 w2 = (final_e ? BM_SGT_V2_F : 0) | BV_SGT_V2_OFFSET(offset) |
61 BM_SGT_V2_IVP | BV_SGT_V2_AVAIL_LENGTH(len);
62
63 caam_write_val64(&sgt->v2.w2, w2);
64 }
65