1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2018-2019 NXP
4  *
5  * Brief   CAAM Job Rings module header.
6  */
7 #ifndef __CAAM_JR_H__
8 #define __CAAM_JR_H__
9 
10 #include <caam_jr_status.h>
11 #include <types_ext.h>
12 
13 /*
14  * Job context to enqueue/dequeue
15  */
16 struct caam_jobctx {
17 	uint32_t *desc;      /* reference to the descriptor */
18 	uint32_t status;     /* executed job status */
19 	uint32_t id;         /* Job identifier */
20 	bool completion;     /* job completion flag */
21 	void *context;       /* caller job context */
22 	void (*callback)(struct caam_jobctx *ctx); /* job completion callback */
23 };
24 
25 /*
26  * Job Ring module configuration
27  */
28 struct caam_jrcfg {
29 	vaddr_t base;    /* CAAM virtual base address */
30 	paddr_t offset;  /* Job Ring address offset */
31 	int it_num;      /* Job Ring interrupt number */
32 	uint8_t nb_jobs; /* Number of Jobs to managed */
33 };
34 
35 /*
36  * The CAAM physical address is decorrelated from the CPU addressing mode.
37  * CAAM can manage 32 or 64 bits address depending on its version and the
38  * device.
39  */
40 /*
41  * Definition of input and output ring object
42  */
43 #ifdef CFG_CAAM_64BIT
44 struct caam_inring_entry {
45 	uint64_t desc; /* Physical address of the descriptor */
46 };
47 
48 struct caam_outring_entry {
49 	uint64_t desc;	 /* Physical address of the descriptor */
50 	uint32_t status; /* Status of the executed job */
51 } __packed;
52 #else
53 struct caam_inring_entry {
54 	uint32_t desc; /* Physical address of the descriptor */
55 };
56 
57 struct caam_outring_entry {
58 	uint32_t desc;	 /* Physical address of the descriptor */
59 	uint32_t status; /* Status of the executed job */
60 } __packed;
61 #endif /* CFG_CAAM_64BIT */
62 
63 /*
64  * Initialization of the CAAM Job Ring module
65  *
66  * @jrcfg  Job Ring Configuration
67  */
68 enum caam_status caam_jr_init(struct caam_jrcfg *jrcfg);
69 
70 /*
71  * Cancels a job ID. Remove the job from SW Job array
72  *
73  * @job_id      Job ID
74  */
75 void caam_jr_cancel(uint32_t job_id);
76 
77 /*
78  * Checks if one of the given job IDs in bit mask format
79  * is completed. If none is completed, wait until timeout expires.
80  * Endlessly wait if @timeout_ms = UINT_MAX
81  *
82  * @job_ids     Job IDs Mask
83  * @timeout_ms  Timeout in millisecond
84  */
85 enum caam_status caam_jr_dequeue(uint32_t job_ids, unsigned int timeout_ms);
86 
87 /*
88  * Enqueues a job in the Job Ring input queue and either wait until job
89  * completion or if job is asynchrnous, returns immediately (if status
90  * success, the output parameter job_id is filled with the Job Id pushed)
91  *
92  * @jobctx  Reference to the job context
93  * @job_id  [out] If pointer not NULL, job is asynchronous and parameter is
94  *                the Job Id enqueued
95  */
96 enum caam_status caam_jr_enqueue(struct caam_jobctx *jobctx, uint32_t *job_id);
97 
98 /*
99  * Request the CAAM JR to halt.
100  * Stop fetching input queue and wait running job completion.
101  */
102 enum caam_status caam_jr_halt(void);
103 
104 /* Request the CAAM JR to flush all job running. */
105 enum caam_status caam_jr_flush(void);
106 
107 /*
108  * Resume the CAAM JR processing.
109  *
110  * @pm_hints  Hint on current power transition
111  */
112 void caam_jr_resume(uint32_t pm_hints);
113 
114 /* Forces the completion of all CAAM Job to ensure CAAM is not BUSY. */
115 enum caam_status caam_jr_complete(void);
116 #endif /* __CAAM_JR_H__ */
117