1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2018-2019 NXP
4  *
5  * Brief   CAAM Job Rings Hardware Abstration Layer header.
6  */
7 #ifndef __CAAM_HAL_JR_H__
8 #define __CAAM_HAL_JR_H__
9 
10 /*
11  * Configures the Job Ring Owner and lock it.
12  * If the configuration is already locked, checks the configuration
13  * set and returns an error if value is not corresponding to the
14  * expected value.
15  *
16  * @ctrl_base  Base address of the controller
17  * @jr_offset  Job Ring offset to configure
18  * @owner      Onwer ID to configure
19  */
20 enum caam_status caam_hal_jr_setowner(vaddr_t ctrl_base, paddr_t jr_offset,
21 				      enum caam_jr_owner owner);
22 
23 /*
24  * Resets the Job Ring to ensure that all pending jobs are completed
25  * and no other will be executed
26  *
27  * @baseaddr   Job Ring Base address
28  */
29 enum caam_status caam_hal_jr_reset(vaddr_t baseaddr);
30 
31 /*
32  * Configures the Job Ring HW queues.
33  *
34  * @baseaddr   Job Ring Base Address
35  * @nbjobs     Number of job rings supported
36  * @inrings    physical address of the JR input queue
37  * @outrings   physical address of the JR output queue
38  */
39 void caam_hal_jr_config(vaddr_t baseaddr, uint8_t nbjobs, uint64_t inrings,
40 			uint64_t outrings);
41 
42 /*
43  * Returns the number of slots available in the input job ring
44  *
45  * @baseaddr   Job Ring Base address
46  */
47 uint32_t caam_hal_jr_read_nbslot_available(vaddr_t baseaddr);
48 
49 /*
50  * Indicates to HW that a new job is available
51  *
52  * @baseaddr   Job Ring Base Address
53  */
54 void caam_hal_jr_add_newjob(vaddr_t baseaddr);
55 
56 /*
57  * Returns the number of job completed and present in the output ring slots
58  *
59  * @baseaddr   Job Ring Base Address
60  */
61 uint32_t caam_hal_jr_get_nbjob_done(vaddr_t baseaddr);
62 
63 /*
64  * Removes a job from the job ring output queue
65  *
66  * @baseaddr   Job Ring Base Address
67  */
68 void caam_hal_jr_del_job(vaddr_t baseaddr);
69 
70 /*
71  * Disable and acknwoledge the Job Ring interrupt
72  *
73  * @baseaddr   Job Ring Base Address
74  */
75 void caam_hal_jr_disable_itr(vaddr_t baseaddr);
76 
77 /*
78  * Enable the Job Ring interrupt
79  *
80  * @baseaddr   Job Ring Base Address
81  */
82 void caam_hal_jr_enable_itr(vaddr_t baseaddr);
83 
84 /*
85  * If an interrupt is pending, acknowledges it and returns true.
86  *
87  * @baseaddr   Job Ring Base Address
88  */
89 bool caam_hal_jr_check_ack_itr(vaddr_t baseaddr);
90 
91 /*
92  * Halt the Job Ring processing. Stop fetching input queue and wait
93  * all running jobs normal completion.
94  *
95  * @baseaddr   Job Ring Base Address
96  */
97 enum caam_status caam_hal_jr_halt(vaddr_t baseaddr);
98 
99 /*
100  * Wait all Input queue Job Ring processing.
101  *
102  * @baseaddr   Job Ring Base Address
103  */
104 enum caam_status caam_hal_jr_flush(vaddr_t baseaddr);
105 
106 /*
107  * Resume the Job Ring processing.
108  *
109  * @baseaddr   Job Ring Base Address
110  */
111 void caam_hal_jr_resume(vaddr_t baseaddr);
112 
113 /*
114  * Returns the next entry free in the JR input queue.
115  * The HW increments register by 4. Convert it to a software index number
116  *
117  * @baseaddr   CAAM JR Base Address
118  */
119 uint8_t caam_hal_jr_input_index(vaddr_t baseaddr);
120 
121 /*
122  * Returns the next entry to read from the JR output queue.
123  * The HW increments register by 8. Convert it to a software index number
124  *
125  * @baseaddr   CAAM JR Base Address
126  */
127 uint8_t caam_hal_jr_output_index(vaddr_t baseaddr);
128 
129 /*
130  * Let the JR prepare data that need backup
131  *
132  * @ctrl_base   CAAM JR Base Address
133  * @jr_offset   Job Ring offset to prepare backup for
134  */
135 void caam_hal_jr_prepare_backup(vaddr_t ctrl_base, paddr_t jr_offset);
136 
137 #endif /* __CAAM_HAL_JR_H__ */
138