]>
Commit | Line | Data |
---|---|---|
52fa7bf9 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
8b230ed8 | 2 | /* |
2732ba56 | 3 | * Linux network driver for QLogic BR-series Converged Network Adapter. |
8b230ed8 RM |
4 | */ |
5 | /* | |
2732ba56 RM |
6 | * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. |
7 | * Copyright (c) 2014-2015 QLogic Corporation | |
8b230ed8 | 8 | * All rights reserved |
2732ba56 | 9 | * www.qlogic.com |
8b230ed8 RM |
10 | */ |
11 | ||
1aa8b471 | 12 | /* BFA common services */ |
8b230ed8 | 13 | |
758ccc34 RM |
14 | #ifndef __BFA_CS_H__ |
15 | #define __BFA_CS_H__ | |
8b230ed8 RM |
16 | |
17 | #include "cna.h" | |
18 | ||
1aa8b471 | 19 | /* BFA state machine interfaces */ |
758ccc34 | 20 | |
8b230ed8 RM |
21 | typedef void (*bfa_sm_t)(void *sm, int event); |
22 | ||
1aa8b471 | 23 | /* For converting from state machine function to state encoding. */ |
8b230ed8 RM |
24 | struct bfa_sm_table { |
25 | bfa_sm_t sm; /*!< state machine function */ | |
26 | int state; /*!< state machine encoding */ | |
27 | char *name; /*!< state name for display */ | |
28 | }; | |
758ccc34 | 29 | #define BFA_SM(_sm) ((bfa_sm_t)(_sm)) |
8b230ed8 | 30 | |
1aa8b471 | 31 | /* State machine with entry actions. */ |
8b230ed8 RM |
32 | typedef void (*bfa_fsm_t)(void *fsm, int event); |
33 | ||
1aa8b471 | 34 | /* oc - object class eg. bfa_ioc |
8b230ed8 RM |
35 | * st - state, eg. reset |
36 | * otype - object type, eg. struct bfa_ioc | |
37 | * etype - object type, eg. enum ioc_event | |
38 | */ | |
758ccc34 RM |
39 | #define bfa_fsm_state_decl(oc, st, otype, etype) \ |
40 | static void oc ## _sm_ ## st(otype * fsm, etype event); \ | |
8b230ed8 RM |
41 | static void oc ## _sm_ ## st ## _entry(otype * fsm) |
42 | ||
758ccc34 RM |
43 | #define bfa_fsm_set_state(_fsm, _state) do { \ |
44 | (_fsm)->fsm = (bfa_fsm_t)(_state); \ | |
45 | _state ## _entry(_fsm); \ | |
8b230ed8 RM |
46 | } while (0) |
47 | ||
48 | #define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event))) | |
758ccc34 | 49 | #define bfa_fsm_cmp_state(_fsm, _state) \ |
8b230ed8 RM |
50 | ((_fsm)->fsm == (bfa_fsm_t)(_state)) |
51 | ||
52 | static inline int | |
b7ee31c5 | 53 | bfa_sm_to_state(const struct bfa_sm_table *smt, bfa_sm_t sm) |
8b230ed8 RM |
54 | { |
55 | int i = 0; | |
56 | ||
57 | while (smt[i].sm && smt[i].sm != sm) | |
58 | i++; | |
59 | return smt[i].state; | |
60 | } | |
758ccc34 | 61 | |
1aa8b471 | 62 | /* Generic wait counter. */ |
758ccc34 RM |
63 | |
64 | typedef void (*bfa_wc_resume_t) (void *cbarg); | |
65 | ||
66 | struct bfa_wc { | |
67 | bfa_wc_resume_t wc_resume; | |
68 | void *wc_cbarg; | |
69 | int wc_count; | |
70 | }; | |
71 | ||
72 | static inline void | |
73 | bfa_wc_up(struct bfa_wc *wc) | |
74 | { | |
75 | wc->wc_count++; | |
76 | } | |
77 | ||
78 | static inline void | |
79 | bfa_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 | ||
1aa8b471 | 86 | /* Initialize a waiting counter. */ |
758ccc34 RM |
87 | static inline void |
88 | bfa_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 | ||
1aa8b471 | 96 | /* Wait for counter to reach zero */ |
758ccc34 RM |
97 | static inline void |
98 | bfa_wc_wait(struct bfa_wc *wc) | |
99 | { | |
100 | bfa_wc_down(wc); | |
101 | } | |
102 | ||
103 | #endif /* __BFA_CS_H__ */ |