blob: 3eb7be79da414a3d14eca379f80acfa6ed8c9cf1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Ruchika Guptaac1b2692014-10-15 11:35:30 +05302/*
3 * Copyright 2008-2014 Freescale Semiconductor, Inc.
Gaurav Jaine31dab82022-03-24 11:50:25 +05304 * Copyright 2021 NXP
Ruchika Guptaac1b2692014-10-15 11:35:30 +05305 *
Ruchika Guptaac1b2692014-10-15 11:35:30 +05306 */
7
8#ifndef __JR_H
9#define __JR_H
10
11#include <linux/compiler.h>
Gaurav Jaine31dab82022-03-24 11:50:25 +053012#include "fsl_sec.h"
Ye Li3c3e9a12021-03-25 17:30:36 +080013#include "type.h"
Gaurav Jaine31dab82022-03-24 11:50:25 +053014#include <misc.h>
Ruchika Guptaac1b2692014-10-15 11:35:30 +053015
16#define JR_SIZE 4
Franck LENORMAND71812782021-03-25 17:30:22 +080017/* Timeout currently defined as 10 sec */
18#define CONFIG_USEC_DEQ_TIMEOUT 10000000U
Ruchika Guptaac1b2692014-10-15 11:35:30 +053019
20#define DEFAULT_JR_ID 0
21#define DEFAULT_JR_LIODN 0
22#define DEFAULT_IRQ 0 /* Interrupts not to be configured */
23
24#define MCFGR_SWRST ((uint32_t)(1)<<31) /* Software Reset */
25#define MCFGR_DMA_RST ((uint32_t)(1)<<28) /* DMA Reset */
26#define MCFGR_PS_SHIFT 16
horia.geanta@freescale.com66e26aa2015-07-08 17:24:57 +030027#define MCFGR_AWCACHE_SHIFT 8
28#define MCFGR_AWCACHE_MASK (0xf << MCFGR_AWCACHE_SHIFT)
Saksham Jain0c19cea2016-03-23 16:24:42 +053029#define MCFGR_ARCACHE_SHIFT 12
30#define MCFGR_ARCACHE_MASK (0xf << MCFGR_ARCACHE_SHIFT)
31
Ruchika Guptaac1b2692014-10-15 11:35:30 +053032#define JR_INTMASK 0x00000001
33#define JRCR_RESET 0x01
34#define JRINT_ERR_HALT_INPROGRESS 0x4
35#define JRINT_ERR_HALT_MASK 0xc
36#define JRNSLIODN_SHIFT 16
37#define JRNSLIODN_MASK 0x0fff0000
38#define JRSLIODN_SHIFT 0
39#define JRSLIODN_MASK 0x00000fff
40
Gaurav Jaine31dab82022-03-24 11:50:25 +053041#define JRDID_MS_PRIM_DID BIT(0)
42#define JRDID_MS_PRIM_TZ BIT(4)
43#define JRDID_MS_TZ_OWN BIT(15)
44
45#define JQ_DEQ_ERR (-1)
46#define JQ_DEQ_TO_ERR (-2)
47#define JQ_ENQ_ERR (-3)
Ruchika Guptaac1b2692014-10-15 11:35:30 +053048
Lukas Aueraed8eac2018-01-25 14:11:17 +010049#define RNG4_MAX_HANDLES 2
50
Gaurav Jaine31dab82022-03-24 11:50:25 +053051enum {
52 /* Run caam jobring descriptor(in buf) */
53 CAAM_JR_RUN_DESC,
54};
55
Ruchika Guptaac1b2692014-10-15 11:35:30 +053056struct op_ring {
Ye Li3c3e9a12021-03-25 17:30:36 +080057 caam_dma_addr_t desc;
58 uint32_t status;
Ruchika Guptaac1b2692014-10-15 11:35:30 +053059} __packed;
60
61struct jr_info {
Aneesh Bansal43421822015-10-29 22:58:03 +053062 void (*callback)(uint32_t status, void *arg);
Ye Li3c3e9a12021-03-25 17:30:36 +080063 caam_dma_addr_t desc_phys_addr;
Ruchika Guptaac1b2692014-10-15 11:35:30 +053064 uint32_t desc_len;
65 uint32_t op_done;
66 void *arg;
67};
68
69struct jobring {
70 int jq_id;
71 int irq;
72 int liodn;
73 /* Head is the index where software would enq the descriptor in
74 * the i/p ring
75 */
76 int head;
77 /* Tail index would be used by s/w ehile enqueuing to determine if
78 * there is any space left in the s/w maintained i/p rings
79 */
80 /* Also in case of deq tail will be incremented only in case of
81 * in-order job completion
82 */
83 int tail;
84 /* Read index of the output ring. It may not match with tail in case
85 * of out of order completetion
86 */
87 int read_idx;
88 /* Write index to input ring. Would be always equal to head */
89 int write_idx;
90 /* Size of the rings. */
91 int size;
Ruchika Guptad2180332016-01-22 16:12:55 +053092 /* Op ring size aligned to cache line size */
93 int op_size;
Ruchika Guptaac1b2692014-10-15 11:35:30 +053094 /* The ip and output rings have to be accessed by SEC. So the
95 * pointers will ahve to point to the housekeeping region provided
96 * by SEC
97 */
98 /*Circular Ring of i/p descriptors */
Ye Li3c3e9a12021-03-25 17:30:36 +080099 caam_dma_addr_t *input_ring;
Ruchika Guptaac1b2692014-10-15 11:35:30 +0530100 /* Circular Ring of o/p descriptors */
101 /* Circula Ring containing info regarding descriptors in i/p
102 * and o/p ring
103 */
104 /* This ring can be on the stack */
105 struct jr_info info[JR_SIZE];
106 struct op_ring *output_ring;
Alex Porosanu7703d1e2016-04-29 15:18:00 +0300107 /* Offset in CCSR to the SEC engine to which this JR belongs */
108 uint32_t sec_offset;
109
Ruchika Guptaac1b2692014-10-15 11:35:30 +0530110};
111
112struct result {
113 int done;
114 uint32_t status;
115};
116
Gaurav Jaine31dab82022-03-24 11:50:25 +0530117/*
118 * struct caam_regs - CAAM initialization register interface
119 *
120 * Interface to caam memory map, jobring register, jobring storage.
121 */
122struct caam_regs {
123 ccsr_sec_t *sec; /*caam initialization registers*/
124 struct jr_regs *regs; /*jobring configuration registers*/
125 u8 jrid; /*id to identify a jobring*/
126 /*Private sub-storage for a single JobR*/
127 struct jobring jr[CONFIG_SYS_FSL_MAX_NUM_OF_SEC];
128};
129
Ruchika Guptaac1b2692014-10-15 11:35:30 +0530130void caam_jr_strstatus(u32 status);
131int run_descriptor_jr(uint32_t *desc);
132
133#endif