Commit | Line | Data |
---|---|---|
8b230ed8 RM |
1 | /* |
2 | * Linux network driver for Brocade Converged Network Adapter. | |
3 | * | |
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 | |
7 | * | |
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. | |
12 | */ | |
13 | /* | |
14 | * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. | |
15 | * All rights reserved | |
16 | * www.brocade.com | |
17 | */ | |
18 | ||
19 | /** | |
20 | * @file bfasm.h State machine defines | |
21 | */ | |
22 | ||
23 | #ifndef __BFA_SM_H__ | |
24 | #define __BFA_SM_H__ | |
25 | ||
26 | #include "cna.h" | |
27 | ||
28 | typedef void (*bfa_sm_t)(void *sm, int event); | |
29 | ||
30 | /** | |
31 | * oc - object class eg. bfa_ioc | |
32 | * st - state, eg. reset | |
33 | * otype - object type, eg. struct bfa_ioc | |
34 | * etype - object type, eg. enum ioc_event | |
35 | */ | |
36 | #define bfa_sm_state_decl(oc, st, otype, etype) \ | |
37 | static void oc ## _sm_ ## st(otype * fsm, etype event) | |
38 | ||
39 | #define bfa_sm_set_state(_sm, _state) ((_sm)->sm = (bfa_sm_t)(_state)) | |
40 | #define bfa_sm_send_event(_sm, _event) ((_sm)->sm((_sm), (_event))) | |
41 | #define bfa_sm_get_state(_sm) ((_sm)->sm) | |
42 | #define bfa_sm_cmp_state(_sm, _state) ((_sm)->sm == (bfa_sm_t)(_state)) | |
43 | ||
44 | /** | |
45 | * For converting from state machine function to state encoding. | |
46 | */ | |
47 | struct bfa_sm_table { | |
48 | bfa_sm_t sm; /*!< state machine function */ | |
49 | int state; /*!< state machine encoding */ | |
50 | char *name; /*!< state name for display */ | |
51 | }; | |
52 | #define BFA_SM(_sm) ((bfa_sm_t)(_sm)) | |
53 | ||
54 | /** | |
55 | * State machine with entry actions. | |
56 | */ | |
57 | typedef void (*bfa_fsm_t)(void *fsm, int event); | |
58 | ||
59 | /** | |
60 | * oc - object class eg. bfa_ioc | |
61 | * st - state, eg. reset | |
62 | * otype - object type, eg. struct bfa_ioc | |
63 | * etype - object type, eg. enum ioc_event | |
64 | */ | |
65 | #define bfa_fsm_state_decl(oc, st, otype, etype) \ | |
66 | static void oc ## _sm_ ## st(otype * fsm, etype event); \ | |
67 | static void oc ## _sm_ ## st ## _entry(otype * fsm) | |
68 | ||
69 | #define bfa_fsm_set_state(_fsm, _state) do { \ | |
70 | (_fsm)->fsm = (bfa_fsm_t)(_state); \ | |
71 | _state ## _entry(_fsm); \ | |
72 | } while (0) | |
73 | ||
74 | #define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event))) | |
75 | #define bfa_fsm_get_state(_fsm) ((_fsm)->fsm) | |
76 | #define bfa_fsm_cmp_state(_fsm, _state) \ | |
77 | ((_fsm)->fsm == (bfa_fsm_t)(_state)) | |
78 | ||
79 | static inline int | |
80 | bfa_sm_to_state(struct bfa_sm_table *smt, bfa_sm_t sm) | |
81 | { | |
82 | int i = 0; | |
83 | ||
84 | while (smt[i].sm && smt[i].sm != sm) | |
85 | i++; | |
86 | return smt[i].state; | |
87 | } | |
88 | #endif |