aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/csiostor/csio_defs.h
blob: e50e93e7fe5a1c3c79225d92f660333a22344db6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * This file is part of the Chelsio FCoE driver for Linux.
 *
 * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __CSIO_DEFS_H__
#define __CSIO_DEFS_H__

#include <linux/kernel.h>
#include <linux/stddef.h>
#include <linux/timer.h>
#include <linux/list.h>
#include <linux/bug.h>
#include <linux/pci.h>
#include <linux/jiffies.h>

#define CSIO_INVALID_IDX		0xFFFFFFFF
#define CSIO_INC_STATS(elem, val)	((elem)->stats.val++)
#define CSIO_DEC_STATS(elem, val)	((elem)->stats.val--)
#define CSIO_VALID_WWN(__n)		((*__n >> 4) == 0x5 ? true : false)
#define CSIO_DID_MASK			0xFFFFFF
#define CSIO_WORD_TO_BYTE		4

#ifndef readq
static inline u64 readq(void __iomem *addr)
{
	return readl(addr) + ((u64)readl(addr + 4) << 32);
}

static inline void writeq(u64 val, void __iomem *addr)
{
	writel(val, addr);
	writel(val >> 32, addr + 4);
}
#endif

static inline int
csio_list_deleted(struct list_head *list)
{
	return ((list->next == list) && (list->prev == list));
}

#define csio_list_next(elem)	(((struct list_head *)(elem))->next)
#define csio_list_prev(elem)	(((struct list_head *)(elem))->prev)

/* State machine */
struct csio_lnode;

/* State machine evets */
enum csio_ln_ev {
	CSIO_LNE_NONE = (uint32_t)0,
	CSIO_LNE_LINKUP,
	CSIO_LNE_FAB_INIT_DONE,
	CSIO_LNE_LINK_DOWN,
	CSIO_LNE_DOWN_LINK,
	CSIO_LNE_LOGO,
	CSIO_LNE_CLOSE,
	CSIO_LNE_MAX_EVENT,
};

typedef void (*csio_sm_state_t)(struct csio_lnode *ln, enum csio_ln_ev evt);

struct csio_sm {
	struct list_head	sm_list;
	csio_sm_state_t		sm_state;
};

static inline void
csio_set_state(void *smp, void *state)
{
	((struct csio_sm *)smp)->sm_state = state;
}

static inline void
csio_init_state(struct csio_sm *smp, void *state)
{
	csio_set_state(smp, state);
}

static inline void
csio_post_event(void *smp, uint32_t evt)
{
	((struct csio_sm *)smp)->sm_state(smp, evt);
}

static inline csio_sm_state_t
csio_get_state(void *smp)
{
	return ((struct csio_sm *)smp)->sm_state;
}

static inline bool
csio_match_state(void *smp, void *state)
{
	return (csio_get_state(smp) == (csio_sm_state_t)state);
}

#define	CSIO_ASSERT(cond)		BUG_ON(!(cond))

#ifdef __CSIO_DEBUG__
#define CSIO_DB_ASSERT(__c)		CSIO_ASSERT((__c))
#else
#define CSIO_DB_ASSERT(__c)
#endif

#endif /* ifndef __CSIO_DEFS_H__ */