bna: get rid of duplicate and unused macros
[deliverable/linux.git] / drivers / net / ethernet / brocade / bna / bfa_cs.h
CommitLineData
8b230ed8 1/*
2732ba56 2 * Linux network driver for QLogic BR-series Converged Network Adapter.
8b230ed8
RM
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/*
2732ba56
RM
14 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15 * Copyright (c) 2014-2015 QLogic Corporation
8b230ed8 16 * All rights reserved
2732ba56 17 * www.qlogic.com
8b230ed8
RM
18 */
19
1aa8b471 20/* BFA common services */
8b230ed8 21
758ccc34
RM
22#ifndef __BFA_CS_H__
23#define __BFA_CS_H__
8b230ed8
RM
24
25#include "cna.h"
26
1aa8b471 27/* BFA state machine interfaces */
758ccc34 28
8b230ed8
RM
29typedef void (*bfa_sm_t)(void *sm, int event);
30
1aa8b471 31/* For converting from state machine function to state encoding. */
8b230ed8
RM
32struct bfa_sm_table {
33 bfa_sm_t sm; /*!< state machine function */
34 int state; /*!< state machine encoding */
35 char *name; /*!< state name for display */
36};
758ccc34 37#define BFA_SM(_sm) ((bfa_sm_t)(_sm))
8b230ed8 38
1aa8b471 39/* State machine with entry actions. */
8b230ed8
RM
40typedef void (*bfa_fsm_t)(void *fsm, int event);
41
1aa8b471 42/* oc - object class eg. bfa_ioc
8b230ed8
RM
43 * st - state, eg. reset
44 * otype - object type, eg. struct bfa_ioc
45 * etype - object type, eg. enum ioc_event
46 */
758ccc34
RM
47#define bfa_fsm_state_decl(oc, st, otype, etype) \
48 static void oc ## _sm_ ## st(otype * fsm, etype event); \
8b230ed8
RM
49 static void oc ## _sm_ ## st ## _entry(otype * fsm)
50
758ccc34
RM
51#define bfa_fsm_set_state(_fsm, _state) do { \
52 (_fsm)->fsm = (bfa_fsm_t)(_state); \
53 _state ## _entry(_fsm); \
8b230ed8
RM
54} while (0)
55
56#define bfa_fsm_send_event(_fsm, _event) ((_fsm)->fsm((_fsm), (_event)))
758ccc34 57#define bfa_fsm_cmp_state(_fsm, _state) \
8b230ed8
RM
58 ((_fsm)->fsm == (bfa_fsm_t)(_state))
59
60static inline int
b7ee31c5 61bfa_sm_to_state(const struct bfa_sm_table *smt, bfa_sm_t sm)
8b230ed8
RM
62{
63 int i = 0;
64
65 while (smt[i].sm && smt[i].sm != sm)
66 i++;
67 return smt[i].state;
68}
758ccc34 69
1aa8b471 70/* Generic wait counter. */
758ccc34
RM
71
72typedef void (*bfa_wc_resume_t) (void *cbarg);
73
74struct bfa_wc {
75 bfa_wc_resume_t wc_resume;
76 void *wc_cbarg;
77 int wc_count;
78};
79
80static inline void
81bfa_wc_up(struct bfa_wc *wc)
82{
83 wc->wc_count++;
84}
85
86static inline void
87bfa_wc_down(struct bfa_wc *wc)
88{
89 wc->wc_count--;
90 if (wc->wc_count == 0)
91 wc->wc_resume(wc->wc_cbarg);
92}
93
1aa8b471 94/* Initialize a waiting counter. */
758ccc34
RM
95static inline void
96bfa_wc_init(struct bfa_wc *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg)
97{
98 wc->wc_resume = wc_resume;
99 wc->wc_cbarg = wc_cbarg;
100 wc->wc_count = 0;
101 bfa_wc_up(wc);
102}
103
1aa8b471 104/* Wait for counter to reach zero */
758ccc34
RM
105static inline void
106bfa_wc_wait(struct bfa_wc *wc)
107{
108 bfa_wc_down(wc);
109}
110
111#endif /* __BFA_CS_H__ */
This page took 0.497032 seconds and 5 git commands to generate.