1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef __BFA_CS_H__
15#define __BFA_CS_H__
16
17#include "cna.h"
18
19
20
21typedef void (*bfa_sm_t)(void *sm, int event);
22
23
24struct bfa_sm_table {
25 bfa_sm_t sm;
26 int state;
27 char *name;
28};
29#define BFA_SM(_sm) ((bfa_sm_t)(_sm))
30
31
32typedef void (*bfa_fsm_t)(void *fsm, int event);
33
34
35
36
37
38
39#define bfa_fsm_state_decl(oc, st, otype, etype) \
40 static void oc ## _sm_ ## st(otype * fsm, etype event); \
41 static void oc ## _sm_ ## st ## _entry(otype * fsm)
42
43#define bfa_fsm_set_state(_fsm, _state) do { \
44 (_fsm)->fsm = (bfa_fsm_t)(_state); \
45 _state ## _entry(_fsm); \
46} while (0)
47
48#define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))
49#define bfa_fsm_cmp_state(_fsm, _state) \
50 ((_fsm)->fsm == (bfa_fsm_t)(_state))
51
52static inline int
53bfa_sm_to_state(const struct bfa_sm_table *smt, bfa_sm_t sm)
54{
55 int i = 0;
56
57 while (smt[i].sm && smt[i].sm != sm)
58 i++;
59 return smt[i].state;
60}
61
62
63
64typedef void (*bfa_wc_resume_t) (void *cbarg);
65
66struct bfa_wc {
67 bfa_wc_resume_t wc_resume;
68 void *wc_cbarg;
69 int wc_count;
70};
71
72static inline void
73bfa_wc_up(struct bfa_wc *wc)
74{
75 wc->wc_count++;
76}
77
78static inline void
79bfa_wc_down(struct bfa_wc *wc)
80{
81 wc->wc_count--;
82 if (wc->wc_count == 0)
83 wc->wc_resume(wc->wc_cbarg);
84}
85
86
87static inline void
88bfa_wc_init(struct bfa_wc *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg)
89{
90 wc->wc_resume = wc_resume;
91 wc->wc_cbarg = wc_cbarg;
92 wc->wc_count = 0;
93 bfa_wc_up(wc);
94}
95
96
97static inline void
98bfa_wc_wait(struct bfa_wc *wc)
99{
100 bfa_wc_down(wc);
101}
102
103#endif
104