diff options
Diffstat (limited to 'drivers/scsi/bfa/include/cs/bfa_sm.h')
-rw-r--r-- | drivers/scsi/bfa/include/cs/bfa_sm.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/drivers/scsi/bfa/include/cs/bfa_sm.h b/drivers/scsi/bfa/include/cs/bfa_sm.h new file mode 100644 index 00000000000..9877066680a --- /dev/null +++ b/drivers/scsi/bfa/include/cs/bfa_sm.h | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2005-2009 Brocade Communications Systems, Inc. | ||
3 | * All rights reserved | ||
4 | * www.brocade.com | ||
5 | * | ||
6 | * Linux driver for Brocade Fibre Channel Host Bus Adapter. | ||
7 | * | ||
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 | ||
11 | * | ||
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. | ||
16 | */ | ||
17 | |||
18 | /** | ||
19 | * bfasm.h State machine defines | ||
20 | */ | ||
21 | |||
22 | #ifndef __BFA_SM_H__ | ||
23 | #define __BFA_SM_H__ | ||
24 | |||
25 | typedef void (*bfa_sm_t)(void *sm, int event); | ||
26 | |||
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)) | ||
31 | |||
32 | /** | ||
33 | * For converting from state machine function to state encoding. | ||
34 | */ | ||
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 */ | ||
39 | }; | ||
40 | #define BFA_SM(_sm) ((bfa_sm_t)(_sm)) | ||
41 | |||
42 | int bfa_sm_to_state(struct bfa_sm_table_s *smt, bfa_sm_t sm); | ||
43 | |||
44 | /** | ||
45 | * State machine with entry actions. | ||
46 | */ | ||
47 | typedef void (*bfa_fsm_t)(void *fsm, int event); | ||
48 | |||
49 | /** | ||
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 | ||
54 | */ | ||
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) | ||
58 | |||
59 | #define bfa_fsm_set_state(_fsm, _state) do { \ | ||
60 | (_fsm)->fsm = (bfa_fsm_t)(_state); \ | ||
61 | _state ## _entry(_fsm); \ | ||
62 | } while (0) | ||
63 | |||
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)) | ||
68 | |||
69 | #endif | ||