Commit | Line | Data |
---|---|---|
7725ccfd JH |
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); | |
1c8a4c37 KG |
26 | /** |
27 | * oc - object class eg. bfa_ioc | |
28 | * st - state, eg. reset | |
29 | * otype - object type, eg. struct bfa_ioc_s | |
30 | * etype - object type, eg. enum ioc_event | |
31 | */ | |
32 | #define bfa_sm_state_decl(oc, st, otype, etype) \ | |
33 | static void oc ## _sm_ ## st(otype * fsm, etype event) | |
7725ccfd | 34 | |
f8ceafde JH |
35 | #define bfa_sm_set_state(_sm, _state) ((_sm)->sm = (bfa_sm_t)(_state)) |
36 | #define bfa_sm_send_event(_sm, _event) ((_sm)->sm((_sm), (_event))) | |
7725ccfd JH |
37 | #define bfa_sm_get_state(_sm) ((_sm)->sm) |
38 | #define bfa_sm_cmp_state(_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state)) | |
39 | ||
40 | /** | |
41 | * For converting from state machine function to state encoding. | |
42 | */ | |
43 | struct bfa_sm_table_s { | |
44 | bfa_sm_t sm; /* state machine function */ | |
45 | int state; /* state machine encoding */ | |
46 | char *name; /* state name for display */ | |
47 | }; | |
48 | #define BFA_SM(_sm) ((bfa_sm_t)(_sm)) | |
49 | ||
50 | int bfa_sm_to_state(struct bfa_sm_table_s *smt, bfa_sm_t sm); | |
51 | ||
52 | /** | |
53 | * State machine with entry actions. | |
54 | */ | |
55 | typedef void (*bfa_fsm_t)(void *fsm, int event); | |
56 | ||
57 | /** | |
58 | * oc - object class eg. bfa_ioc | |
59 | * st - state, eg. reset | |
60 | * otype - object type, eg. struct bfa_ioc_s | |
61 | * etype - object type, eg. enum ioc_event | |
62 | */ | |
63 | #define bfa_fsm_state_decl(oc, st, otype, etype) \ | |
64 | static void oc ## _sm_ ## st(otype * fsm, etype event); \ | |
65 | static void oc ## _sm_ ## st ## _entry(otype * fsm) | |
66 | ||
67 | #define bfa_fsm_set_state(_fsm, _state) do { \ | |
68 | (_fsm)->fsm = (bfa_fsm_t)(_state); \ | |
69 | _state ## _entry(_fsm); \ | |
70 | } while (0) | |
71 | ||
72 | #define bfa_fsm_send_event(_fsm, _event) \ | |
f8ceafde | 73 | ((_fsm)->fsm((_fsm), (_event))) |
7725ccfd JH |
74 | #define bfa_fsm_cmp_state(_fsm, _state) \ |
75 | ((_fsm)->fsm == (bfa_fsm_t)(_state)) | |
76 | ||
77 | #endif |