Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 */
5/*
6 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
7 * Copyright (c) 2014-2015 QLogic Corporation
8 * All rights reserved
9 * www.qlogic.com
10 */
11
12/* BFA common services */
13
14#ifndef __BFA_CS_H__
15#define __BFA_CS_H__
16
17#include "cna.h"
18
19/* BFA state machine interfaces */
20
21/* For converting from state machine function to state encoding. */
22#define BFA_SM_TABLE(n, s, e, t) \
23struct s; \
24enum e; \
25typedef void (*t)(struct s *, enum e); \
26 \
27struct n ## _sm_table_s { \
28 t sm; /* state machine function */ \
29 int state; /* state machine encoding */ \
30 char *name; /* state name for display */ \
31}; \
32 \
33static inline int \
34n ## _sm_to_state(struct n ## _sm_table_s *smt, t sm) \
35{ \
36 int i = 0; \
37 \
38 while (smt[i].sm && smt[i].sm != sm) \
39 i++; \
40 return smt[i].state; \
41}
42
43BFA_SM_TABLE(iocpf, bfa_iocpf, iocpf_event, bfa_fsm_iocpf_t)
44BFA_SM_TABLE(ioc, bfa_ioc, ioc_event, bfa_fsm_ioc_t)
45BFA_SM_TABLE(cmdq, bfa_msgq_cmdq, cmdq_event, bfa_fsm_msgq_cmdq_t)
46BFA_SM_TABLE(rspq, bfa_msgq_rspq, rspq_event, bfa_fsm_msgq_rspq_t)
47
48BFA_SM_TABLE(ioceth, bna_ioceth, bna_ioceth_event, bna_fsm_ioceth_t)
49BFA_SM_TABLE(enet, bna_enet, bna_enet_event, bna_fsm_enet_t)
50BFA_SM_TABLE(ethport, bna_ethport, bna_ethport_event, bna_fsm_ethport_t)
51BFA_SM_TABLE(tx, bna_tx, bna_tx_event, bna_fsm_tx_t)
52BFA_SM_TABLE(rxf, bna_rxf, bna_rxf_event, bna_fsm_rxf_t)
53BFA_SM_TABLE(rx, bna_rx, bna_rx_event, bna_fsm_rx_t)
54
55#undef BFA_SM_TABLE
56
57#define BFA_SM(_sm) (_sm)
58
59/* State machine with entry actions. */
60typedef void (*bfa_fsm_t)(void *fsm, int event);
61
62/* oc - object class eg. bfa_ioc
63 * st - state, eg. reset
64 * otype - object type, eg. struct bfa_ioc
65 * etype - object type, eg. enum ioc_event
66 */
67#define bfa_fsm_state_decl(oc, st, otype, etype) \
68 static void oc ## _sm_ ## st(otype * fsm, etype event); \
69 static void oc ## _sm_ ## st ## _entry(otype * fsm)
70
71#define bfa_fsm_set_state(_fsm, _state) do { \
72 (_fsm)->fsm = (_state); \
73 _state ## _entry(_fsm); \
74} while (0)
75
76#define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))
77#define bfa_fsm_cmp_state(_fsm, _state) ((_fsm)->fsm == (_state))
78/* Generic wait counter. */
79
80typedef void (*bfa_wc_resume_t) (void *cbarg);
81
82struct bfa_wc {
83 bfa_wc_resume_t wc_resume;
84 void *wc_cbarg;
85 int wc_count;
86};
87
88static inline void
89bfa_wc_up(struct bfa_wc *wc)
90{
91 wc->wc_count++;
92}
93
94static inline void
95bfa_wc_down(struct bfa_wc *wc)
96{
97 wc->wc_count--;
98 if (wc->wc_count == 0)
99 wc->wc_resume(wc->wc_cbarg);
100}
101
102/* Initialize a waiting counter. */
103static inline void
104bfa_wc_init(struct bfa_wc *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg)
105{
106 wc->wc_resume = wc_resume;
107 wc->wc_cbarg = wc_cbarg;
108 wc->wc_count = 0;
109 bfa_wc_up(wc);
110}
111
112/* Wait for counter to reach zero */
113static inline void
114bfa_wc_wait(struct bfa_wc *wc)
115{
116 bfa_wc_down(wc);
117}
118
119#endif /* __BFA_CS_H__ */
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 */
5/*
6 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
7 * Copyright (c) 2014-2015 QLogic Corporation
8 * All rights reserved
9 * www.qlogic.com
10 */
11
12/* BFA common services */
13
14#ifndef __BFA_CS_H__
15#define __BFA_CS_H__
16
17#include "cna.h"
18
19/* BFA state machine interfaces */
20
21typedef void (*bfa_sm_t)(void *sm, int event);
22
23/* For converting from state machine function to state encoding. */
24struct 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};
29#define BFA_SM(_sm) ((bfa_sm_t)(_sm))
30
31/* State machine with entry actions. */
32typedef void (*bfa_fsm_t)(void *fsm, int event);
33
34/* oc - object class eg. bfa_ioc
35 * st - state, eg. reset
36 * otype - object type, eg. struct bfa_ioc
37 * etype - object type, eg. enum ioc_event
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/* Generic wait counter. */
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/* Initialize a waiting counter. */
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/* Wait for counter to reach zero */
97static inline void
98bfa_wc_wait(struct bfa_wc *wc)
99{
100 bfa_wc_down(wc);
101}
102
103#endif /* __BFA_CS_H__ */