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 /* For converting from state machine function to state encoding. */
22 #define BFA_SM_TABLE(n, s, e, t) \
25 typedef void (*t)(struct s *, enum e); \
27 struct n ## _sm_table_s { \
28 t sm; /* state machine function */ \
29 int state; /* state machine encoding */ \
30 char *name; /* state name for display */ \
34 n ## _sm_to_state(struct n ## _sm_table_s *smt, t sm) \
38 while (smt[i].sm && smt[i].sm != sm) \
40 return smt[i].state; \
43 BFA_SM_TABLE(iocpf
, bfa_iocpf
, iocpf_event
, bfa_fsm_iocpf_t
)
44 BFA_SM_TABLE(ioc
, bfa_ioc
, ioc_event
, bfa_fsm_ioc_t
)
45 BFA_SM_TABLE(cmdq
, bfa_msgq_cmdq
, cmdq_event
, bfa_fsm_msgq_cmdq_t
)
46 BFA_SM_TABLE(rspq
, bfa_msgq_rspq
, rspq_event
, bfa_fsm_msgq_rspq_t
)
48 BFA_SM_TABLE(ioceth
, bna_ioceth
, bna_ioceth_event
, bna_fsm_ioceth_t
)
49 BFA_SM_TABLE(enet
, bna_enet
, bna_enet_event
, bna_fsm_enet_t
)
50 BFA_SM_TABLE(ethport
, bna_ethport
, bna_ethport_event
, bna_fsm_ethport_t
)
51 BFA_SM_TABLE(tx
, bna_tx
, bna_tx_event
, bna_fsm_tx_t
)
52 BFA_SM_TABLE(rxf
, bna_rxf
, bna_rxf_event
, bna_fsm_rxf_t
)
53 BFA_SM_TABLE(rx
, bna_rx
, bna_rx_event
, bna_fsm_rx_t
)
57 #define BFA_SM(_sm) (_sm)
59 /* State machine with entry actions. */
60 typedef void (*bfa_fsm_t
)(void *fsm
, int event
);
62 /* oc - object class eg. bfa_ioc
63 * st - state, eg. reset
64 * otype - object type, eg. struct bfa_ioc
65 * etype - object type, eg. enum ioc_event
67 #define bfa_fsm_state_decl(oc, st, otype, etype) \
68 static void oc ## _sm_ ## st(otype * fsm, etype event); \
69 static void oc ## _sm_ ## st ## _entry(otype * fsm)
71 #define bfa_fsm_set_state(_fsm, _state) do { \
72 (_fsm)->fsm = (_state); \
73 _state ## _entry(_fsm); \
76 #define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))
77 #define bfa_fsm_cmp_state(_fsm, _state) ((_fsm)->fsm == (_state))
78 /* Generic wait counter. */
80 typedef void (*bfa_wc_resume_t
) (void *cbarg
);
83 bfa_wc_resume_t wc_resume
;
89 bfa_wc_up(struct bfa_wc
*wc
)
95 bfa_wc_down(struct bfa_wc
*wc
)
98 if (wc
->wc_count
== 0)
99 wc
->wc_resume(wc
->wc_cbarg
);
102 /* Initialize a waiting counter. */
104 bfa_wc_init(struct bfa_wc
*wc
, bfa_wc_resume_t wc_resume
, void *wc_cbarg
)
106 wc
->wc_resume
= wc_resume
;
107 wc
->wc_cbarg
= wc_cbarg
;
112 /* Wait for counter to reach zero */
114 bfa_wc_wait(struct bfa_wc
*wc
)
119 #endif /* __BFA_CS_H__ */