xref: /freebsd/sys/dev/qat/qat_api/common/include/sal_service_state.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /**
4  ***************************************************************************
5  * @file sal_service_state.h
6  *
7  * @defgroup SalServiceState
8  *
9  * @ingroup SalCtrl
10  *
11  * Checks state for generic service instance
12  *
13  ***************************************************************************/
14 
15 #ifndef SAL_SERVICE_STATE_H_
16 #define SAL_SERVICE_STATE_H_
17 
18 /**
19 *******************************************************************************
20  * @ingroup SalServiceState
21  *      Check to see if the instance is in the running state
22  *
23  * @description
24  *      This function checks the state of an instance to see if it is in the
25  *      running state
26  *
27  * @param[in]  instance   Instance handle (assumes this is valid, i.e. checked
28  *                        before this function is called)
29  * @retval CPA_TRUE       Instance in the RUNNING state
30  * @retval CPA_FALSE      Instance not in RUNNING state
31  *
32  *****************************************************************************/
33 CpaBoolean Sal_ServiceIsRunning(CpaInstanceHandle instanceHandle);
34 
35 /**
36 *******************************************************************************
37  * @ingroup SalServiceState
38  *      Check to see if the instance is beign restarted
39  *
40  * @description
41  *      This function checks the state of an instance to see if the device it
42  *      uses is being restarted because of hardware error.
43  *
44  * @param[in]  instance   Instance handle (assumes this is valid, i.e. checked
45  *                        before this function is called)
46  * @retval CPA_TRUE       Device the instance is using is restarting.
47  * @retval CPA_FALSE      Device the instance is running.
48  *
49  *****************************************************************************/
50 CpaBoolean Sal_ServiceIsRestarting(CpaInstanceHandle instanceHandle);
51 
52 /**
53  *******************************************************************************
54  * @ingroup SalServiceState
55  *      This macro checks if an instance is running. An error message is logged
56  *      if it is not in a running state.
57  *
58  * @return CPA_STATUS_FAIL Instance not in RUNNING state.
59  * @return void            Instance is in RUNNING state.
60  ******************************************************************************/
61 #define SAL_RUNNING_CHECK(instanceHandle)                                      \
62 	do {                                                                   \
63 		if (unlikely(CPA_TRUE !=                                       \
64 			     Sal_ServiceIsRunning(instanceHandle))) {          \
65 			if (CPA_TRUE ==                                        \
66 			    Sal_ServiceIsRestarting(instanceHandle)) {         \
67 				return CPA_STATUS_RESTARTING;                  \
68 			}                                                      \
69 			QAT_UTILS_LOG("Instance not in a Running state\n");    \
70 			return CPA_STATUS_FAIL;                                \
71 		}                                                              \
72 	} while (0)
73 
74 /**
75  *******************************************************************************
76  * @ingroup SalServiceState
77  *      This macro checks if an instance is in a state to get init event.
78  *
79  * @return CPA_STATUS_FAIL Instance not in good state.
80  * @return void            Instance is in good state.
81  ******************************************************************************/
82 #define SAL_SERVICE_GOOD_FOR_INIT(instanceHandle)                              \
83 	do {                                                                   \
84 		sal_service_t *pService = (sal_service_t *)instanceHandle;     \
85 		if ((SAL_SERVICE_STATE_UNINITIALIZED != pService->state) &&    \
86 		    (SAL_SERVICE_STATE_RESTARTING != pService->state)) {       \
87 			QAT_UTILS_LOG(                                         \
88 			    "Not in the correct state to call init\n");        \
89 			return CPA_STATUS_FAIL;                                \
90 		}                                                              \
91 	} while (0)
92 
93 #endif /*SAL_SERVICE_STATE_H_*/
94