1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /*****************************************************************************
4  * @file icp_adf_init.h
5  *
6  * @description
7  *      This file contains the function prototype used to register a subsystem
8  *      into the Acceleration Driver Framework (ADF).
9  *
10  *****************************************************************************/
11 #ifndef ICP_ADF_INIT_H
12 #define ICP_ADF_INIT_H
13 
14 #include "icp_accel_devices.h"
15 #include "adf_kernel_types.h"
16 #include "adf_cfg_common.h"
17 
18 /*
19  * Events that will be sending to subsystem. The order of the enum
20  * declaration matters. It should be defined so that the messages can be
21  * sent in loop.
22  */
23 typedef enum icp_adf_subsystemEvent_s {
24 	ICP_ADF_EVENT_INIT = 0,
25 	ICP_ADF_EVENT_START,
26 	ICP_ADF_EVENT_STOP,
27 	ICP_ADF_EVENT_SHUTDOWN,
28 	ICP_ADF_EVENT_RESTARING,
29 	ICP_ADF_EVENT_RESTARTED,
30 	ICP_ADF_EVENT_ERROR,
31 	ICP_ADF_EVENT_END
32 } icp_adf_subsystemEvent_t;
33 
34 /*
35  * Ring info operation used to enable or disable ring polling by ME
36  */
37 typedef enum icp_adf_ringInfoOperation_e {
38 	ICP_ADF_RING_ENABLE = 0,
39 	ICP_ADF_RING_DISABLE
40 } icp_adf_ringInfoOperation_t;
41 
42 /*
43  * Ring generic serivce info private data
44  */
45 typedef enum icp_adf_ringInfoService_e {
46 	ICP_ADF_RING_SERVICE_0 = 0,
47 	ICP_ADF_RING_SERVICE_1,
48 	ICP_ADF_RING_SERVICE_2,
49 	ICP_ADF_RING_SERVICE_3,
50 	ICP_ADF_RING_SERVICE_4,
51 	ICP_ADF_RING_SERVICE_5,
52 	ICP_ADF_RING_SERVICE_6,
53 	ICP_ADF_RING_SERVICE_7,
54 	ICP_ADF_RING_SERVICE_8,
55 	ICP_ADF_RING_SERVICE_9,
56 	ICP_ADF_RING_SERVICE_10,
57 } icp_adf_ringInfoService_t;
58 
59 /*
60  * Ring info callback. Function is used to send operation and ring info
61  * to enable or disable ring polling by ME
62  */
63 typedef CpaStatus (*ringInfoCb)(icp_accel_dev_t *accel_dev,
64 				Cpa32U ringNumber,
65 				icp_adf_ringInfoOperation_t operation,
66 				icp_adf_ringInfoService_t info);
67 
68 /*
69  * Registration handle structure
70  * Each subservice has to have an instance of it.
71  */
72 typedef struct subservice_registation_handle_s {
73 	CpaStatus (*subserviceEventHandler)(icp_accel_dev_t *accel_dev,
74 					    icp_adf_subsystemEvent_t event,
75 					    void *param);
76 	struct {
77 		Cpa32U subsystemInitBit : 1;
78 		Cpa32U subsystemStartBit : 1;
79 		Cpa32U subsystemFailedBit : 1;
80 	} subsystemStatus[ADF_MAX_DEVICES];
81 	char *subsystem_name;
82 	struct subservice_registation_handle_s *pNext;
83 	struct subservice_registation_handle_s *pPrev;
84 } subservice_registation_handle_t;
85 
86 /*
87  * icp_adf_subsystemRegister
88  *
89  * Description:
90  *  Function used by subsystem to register within ADF
91  *  Should be called during insertion of a subsystem
92  *
93  * Returns:
94  *   CPA_STATUS_SUCCESS   on success
95  *   CPA_STATUS_FAIL      on failure
96  */
97 CpaStatus icp_adf_subsystemRegister(subservice_registation_handle_t *handle);
98 
99 /*
100  * icp_adf_subsystemUnregister
101  *
102  * Description:
103  *  Function used by subsystem to unregister from ADF
104  *  Should be called while subsystem in removed
105  *  If the subsystem is initialised and/or started
106  *  it will be stopped and shutdown by this function
107  *
108  * Returns:
109  *   CPA_STATUS_SUCCESS   on success
110  *   CPA_STATUS_FAIL      on failure
111  */
112 CpaStatus icp_adf_subsystemUnregister(subservice_registation_handle_t *handle);
113 
114 /*
115  * icp_adf_accesLayerRingInfoCbRegister
116  *
117  * Description:
118  *  Function register access layer callback, which sends ring info message
119  *
120  * Returns:
121  *   CPA_STATUS_SUCCESS   on success
122  *   CPA_STATUS_FAIL      on failure
123  */
124 CpaStatus icp_adf_accesLayerRingInfoCbRegister(icp_accel_dev_t *accel_dev,
125 					       ringInfoCb);
126 
127 /*
128  * icp_adf_accesLayerRingInfoCbUnregister
129  *
130  * Description:
131  *  Function unregister access layer callback for ring info message
132  *
133  * Returns:
134  *   CPA_STATUS_SUCCESS   on success
135  *   CPA_STATUS_FAIL      on failure
136  */
137 void icp_adf_accesLayerRingInfoCbUnregister(icp_accel_dev_t *accel_dev);
138 
139 /*
140  * icp_adf_isSubsystemStarted
141  *
142  * Description:
143  * Function returns true if the service is started on a device
144  *
145  * Returns:
146  *   CPA_TRUE   if subsystem is started
147  *   CPA_FALSE  if subsystem is not started
148  */
149 
150 CpaBoolean
151 icp_adf_isSubsystemStarted(subservice_registation_handle_t *subsystem_hdl);
152 
153 /*
154  * icp_adf_isDevStarted
155  *
156  * Description:
157  * Function returns true if the device is started
158  * Returns:
159  *   CPA_TRUE   if dev is started
160  *   CPA_FALSE  if dev is not started
161  */
162 CpaBoolean icp_adf_isDevStarted(icp_accel_dev_t *accel_dev);
163 
164 /*
165  * adf_subsystemRestarting
166  *
167  * Description:
168  * Function sends restarting event to all subsystems.
169  * This function should be used by error handling function only
170  *
171  * Returns:
172  *   CPA_TRUE   on success
173  *   CPA_FALSE  on failure
174  */
175 CpaStatus adf_subsystemRestarting(icp_accel_dev_t *accel_dev);
176 
177 /*
178  * adf_subsystemRestarted
179  *
180  * Description:
181  * Function sends restarted event to all subsystems.
182  * This function should be used by error handling function only
183  *
184  * Returns:
185  *   CPA_TRUE   on success
186  *   CPA_FALSE  on failure
187  */
188 CpaStatus adf_subsystemRestarted(icp_accel_dev_t *accel_dev);
189 
190 /*
191  * adf_subsystemError
192  *
193  * Description:
194  * Function sends error event to all subsystems.
195  * This function should be used by error handling funct. only
196  *
197  * Returns:
198  *   CPA_STATUS_SUCCESS   on success
199  *   CPA_STATUS_FAIL      on failure
200  */
201 CpaStatus adf_subsystemError(icp_accel_dev_t *accel_dev);
202 
203 /*
204  * reset_adf_subsystemTable
205  *
206  * Description:
207  * Function to reset subsystem table head, the pointer
208  * to the head of the list and lock.
209  *
210  * Returns: void
211  */
212 void reset_adf_subsystemTable(void);
213 
214 #endif /* ICP_ADF_INIT_H */
215