2 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15 * Copyright (c) 2014-2015 QLogic Corporation
20 /* BFA common services */
27 /* BFA state machine interfaces */
29 typedef void (*bfa_sm_t
)(void *sm
, int event
);
31 /* For converting from state machine function to state encoding. */
33 bfa_sm_t sm
; /*!< state machine function */
34 int state
; /*!< state machine encoding */
35 char *name
; /*!< state name for display */
37 #define BFA_SM(_sm) ((bfa_sm_t)(_sm))
39 /* State machine with entry actions. */
40 typedef void (*bfa_fsm_t
)(void *fsm
, int event
);
42 /* oc - object class eg. bfa_ioc
43 * st - state, eg. reset
44 * otype - object type, eg. struct bfa_ioc
45 * etype - object type, eg. enum ioc_event
47 #define bfa_fsm_state_decl(oc, st, otype, etype) \
48 static void oc ## _sm_ ## st(otype * fsm, etype event); \
49 static void oc ## _sm_ ## st ## _entry(otype * fsm)
51 #define bfa_fsm_set_state(_fsm, _state) do { \
52 (_fsm)->fsm = (bfa_fsm_t)(_state); \
53 _state ## _entry(_fsm); \
56 #define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))
57 #define bfa_fsm_cmp_state(_fsm, _state) \
58 ((_fsm)->fsm == (bfa_fsm_t)(_state))
61 bfa_sm_to_state(const struct bfa_sm_table
*smt
, bfa_sm_t sm
)
65 while (smt
[i
].sm
&& smt
[i
].sm
!= sm
)
70 /* Generic wait counter. */
72 typedef void (*bfa_wc_resume_t
) (void *cbarg
);
75 bfa_wc_resume_t wc_resume
;
81 bfa_wc_up(struct bfa_wc
*wc
)
87 bfa_wc_down(struct bfa_wc
*wc
)
90 if (wc
->wc_count
== 0)
91 wc
->wc_resume(wc
->wc_cbarg
);
94 /* Initialize a waiting counter. */
96 bfa_wc_init(struct bfa_wc
*wc
, bfa_wc_resume_t wc_resume
, void *wc_cbarg
)
98 wc
->wc_resume
= wc_resume
;
99 wc
->wc_cbarg
= wc_cbarg
;
104 /* Wait for counter to reach zero */
106 bfa_wc_wait(struct bfa_wc
*wc
)
111 #endif /* __BFA_CS_H__ */