Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / net / ethernet / brocade / bna / bfa_cs.h
blob858c9212945171621838ea54886eb0abda982cc4
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
12 /* BFA common services */
14 #ifndef __BFA_CS_H__
15 #define __BFA_CS_H__
17 #include "cna.h"
19 /* BFA state machine interfaces */
21 /* For converting from state machine function to state encoding. */
22 #define BFA_SM_TABLE(n, s, e, t) \
23 struct s; \
24 enum e; \
25 typedef void (*t)(struct s *, enum e); \
27 struct n ## _sm_table_s { \
28 t sm; /* state machine function */ \
29 int state; /* state machine encoding */ \
30 char *name; /* state name for display */ \
31 }; \
33 static inline int \
34 n ## _sm_to_state(struct n ## _sm_table_s *smt, t sm) \
35 { \
36 int i = 0; \
38 while (smt[i].sm && smt[i].sm != sm) \
39 i++; \
40 return smt[i].state; \
43 BFA_SM_TABLE(iocpf, bfa_iocpf, iocpf_event, bfa_fsm_iocpf_t)
44 BFA_SM_TABLE(ioc, bfa_ioc, ioc_event, bfa_fsm_ioc_t)
45 BFA_SM_TABLE(cmdq, bfa_msgq_cmdq, cmdq_event, bfa_fsm_msgq_cmdq_t)
46 BFA_SM_TABLE(rspq, bfa_msgq_rspq, rspq_event, bfa_fsm_msgq_rspq_t)
48 BFA_SM_TABLE(ioceth, bna_ioceth, bna_ioceth_event, bna_fsm_ioceth_t)
49 BFA_SM_TABLE(enet, bna_enet, bna_enet_event, bna_fsm_enet_t)
50 BFA_SM_TABLE(ethport, bna_ethport, bna_ethport_event, bna_fsm_ethport_t)
51 BFA_SM_TABLE(tx, bna_tx, bna_tx_event, bna_fsm_tx_t)
52 BFA_SM_TABLE(rxf, bna_rxf, bna_rxf_event, bna_fsm_rxf_t)
53 BFA_SM_TABLE(rx, bna_rx, bna_rx_event, bna_fsm_rx_t)
55 #undef BFA_SM_TABLE
57 #define BFA_SM(_sm) (_sm)
59 /* State machine with entry actions. */
60 typedef void (*bfa_fsm_t)(void *fsm, int event);
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
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)
71 #define bfa_fsm_set_state(_fsm, _state) do { \
72 (_fsm)->fsm = (_state); \
73 _state ## _entry(_fsm); \
74 } while (0)
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. */
80 typedef void (*bfa_wc_resume_t) (void *cbarg);
82 struct bfa_wc {
83 bfa_wc_resume_t wc_resume;
84 void *wc_cbarg;
85 int wc_count;
88 static inline void
89 bfa_wc_up(struct bfa_wc *wc)
91 wc->wc_count++;
94 static inline void
95 bfa_wc_down(struct bfa_wc *wc)
97 wc->wc_count--;
98 if (wc->wc_count == 0)
99 wc->wc_resume(wc->wc_cbarg);
102 /* Initialize a waiting counter. */
103 static inline void
104 bfa_wc_init(struct bfa_wc *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg)
106 wc->wc_resume = wc_resume;
107 wc->wc_cbarg = wc_cbarg;
108 wc->wc_count = 0;
109 bfa_wc_up(wc);
112 /* Wait for counter to reach zero */
113 static inline void
114 bfa_wc_wait(struct bfa_wc *wc)
116 bfa_wc_down(wc);
119 #endif /* __BFA_CS_H__ */