2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
19 * bfasm.h State machine defines
25 typedef void (*bfa_sm_t
)(void *sm
, int event
);
27 #define bfa_sm_set_state(_sm, _state) (_sm)->sm = (bfa_sm_t)(_state)
28 #define bfa_sm_send_event(_sm, _event) (_sm)->sm((_sm), (_event))
29 #define bfa_sm_get_state(_sm) ((_sm)->sm)
30 #define bfa_sm_cmp_state(_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state))
33 * For converting from state machine function to state encoding.
35 struct bfa_sm_table_s
{
36 bfa_sm_t sm
; /* state machine function */
37 int state
; /* state machine encoding */
38 char *name
; /* state name for display */
40 #define BFA_SM(_sm) ((bfa_sm_t)(_sm))
42 int bfa_sm_to_state(struct bfa_sm_table_s
*smt
, bfa_sm_t sm
);
45 * State machine with entry actions.
47 typedef void (*bfa_fsm_t
)(void *fsm
, int event
);
50 * oc - object class eg. bfa_ioc
51 * st - state, eg. reset
52 * otype - object type, eg. struct bfa_ioc_s
53 * etype - object type, eg. enum ioc_event
55 #define bfa_fsm_state_decl(oc, st, otype, etype) \
56 static void oc ## _sm_ ## st(otype * fsm, etype event); \
57 static void oc ## _sm_ ## st ## _entry(otype * fsm)
59 #define bfa_fsm_set_state(_fsm, _state) do { \
60 (_fsm)->fsm = (bfa_fsm_t)(_state); \
61 _state ## _entry(_fsm); \
64 #define bfa_fsm_send_event(_fsm, _event) \
65 (_fsm)->fsm((_fsm), (_event))
66 #define bfa_fsm_cmp_state(_fsm, _state) \
67 ((_fsm)->fsm == (bfa_fsm_t)(_state))