1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Linux network driver for QLogic BR-series Converged Network Adapter.
6 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
7 * Copyright (c) 2014-2015 QLogic Corporation
12 /* BFA common services */
19 /* BFA state machine interfaces */
21 typedef void (*bfa_sm_t
)(void *sm
, int event
);
23 /* For converting from state machine function to state encoding. */
25 bfa_sm_t sm
; /*!< state machine function */
26 int state
; /*!< state machine encoding */
27 char *name
; /*!< state name for display */
29 #define BFA_SM(_sm) ((bfa_sm_t)(_sm))
31 /* State machine with entry actions. */
32 typedef void (*bfa_fsm_t
)(void *fsm
, int event
);
34 /* oc - object class eg. bfa_ioc
35 * st - state, eg. reset
36 * otype - object type, eg. struct bfa_ioc
37 * etype - object type, eg. enum ioc_event
39 #define bfa_fsm_state_decl(oc, st, otype, etype) \
40 static void oc ## _sm_ ## st(otype * fsm, etype event); \
41 static void oc ## _sm_ ## st ## _entry(otype * fsm)
43 #define bfa_fsm_set_state(_fsm, _state) do { \
44 (_fsm)->fsm = (bfa_fsm_t)(_state); \
45 _state ## _entry(_fsm); \
48 #define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))
49 #define bfa_fsm_cmp_state(_fsm, _state) \
50 ((_fsm)->fsm == (bfa_fsm_t)(_state))
53 bfa_sm_to_state(const struct bfa_sm_table
*smt
, bfa_sm_t sm
)
57 while (smt
[i
].sm
&& smt
[i
].sm
!= sm
)
62 /* Generic wait counter. */
64 typedef void (*bfa_wc_resume_t
) (void *cbarg
);
67 bfa_wc_resume_t wc_resume
;
73 bfa_wc_up(struct bfa_wc
*wc
)
79 bfa_wc_down(struct bfa_wc
*wc
)
82 if (wc
->wc_count
== 0)
83 wc
->wc_resume(wc
->wc_cbarg
);
86 /* Initialize a waiting counter. */
88 bfa_wc_init(struct bfa_wc
*wc
, bfa_wc_resume_t wc_resume
, void *wc_cbarg
)
90 wc
->wc_resume
= wc_resume
;
91 wc
->wc_cbarg
= wc_cbarg
;
96 /* Wait for counter to reach zero */
98 bfa_wc_wait(struct bfa_wc
*wc
)
103 #endif /* __BFA_CS_H__ */