summaryrefslogtreecommitdiffstats
path: root/freebsd/sys/cam/cam_sim.h
blob: 7309e97c6957312ad8eda78dc53199e704aa2f97 (plain) (blame)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*-
 * Data structures and definitions for SCSI Interface Modules (SIMs).
 *
 * Copyright (c) 1997 Justin T. Gibbs.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification, immediately at the beginning of the file.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _CAM_CAM_SIM_H
#define _CAM_CAM_SIM_H 1

#ifdef _KERNEL
#ifdef __rtems__
#include <rtems/bsd/sys/param.h>
#include <sys/proc.h>
#include <sys/condvar.h>
#endif /* __rtems__ */

/*
 * The sim driver creates a sim for each controller.  The sim device
 * queue is separately created in order to allow resource sharing between
 * sims.  For instance, a driver may create one sim for each channel of
 * a multi-channel controller and use the same queue for each channel.
 * In this way, the queue resources are shared across all the channels
 * of the multi-channel controller.
 */

struct cam_sim;
struct cam_devq;

typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
typedef void (*sim_poll_func)(struct cam_sim *sim);

struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
void		  cam_simq_free(struct cam_devq *devq);

struct cam_sim *  cam_sim_alloc(sim_action_func sim_action,
				sim_poll_func sim_poll,
				const char *sim_name,
				void *softc,
				u_int32_t unit,
				struct mtx *mtx,
				int max_dev_transactions,
				int max_tagged_dev_transactions,
				struct cam_devq *queue);
void		  cam_sim_free(struct cam_sim *sim, int free_devq);
void		  cam_sim_hold(struct cam_sim *sim);
void		  cam_sim_release(struct cam_sim *sim);

/* Optional sim attributes may be set with these. */
void	cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);



/* Convenience routines for accessing sim attributes. */
static __inline u_int32_t    cam_sim_path(struct cam_sim *sim);
static __inline const char * cam_sim_name(struct cam_sim *sim);
static __inline void *	     cam_sim_softc(struct cam_sim *sim);
static __inline u_int32_t    cam_sim_unit(struct cam_sim *sim);
#ifndef __rtems__
static __inline u_int32_t    cam_sim_bus(struct cam_sim *sim);
#endif /* __rtems__ */



/* Generically useful offsets into the sim private area */
#define spriv_ptr0 sim_priv.entries[0].ptr
#define spriv_ptr1 sim_priv.entries[1].ptr
#define spriv_field0 sim_priv.entries[0].field
#define spriv_field1 sim_priv.entries[1].field

#ifdef __rtems__
/**
 * @brief SIM states.
 *
 * @dot
 *   digraph bsd_sim_state {
 *     BSD_SIM_INIT -> BSD_SIM_INIT_BUSY;
 *     BSD_SIM_INIT -> BSD_SIM_IDLE;
 *     BSD_SIM_INIT_BUSY -> BSD_SIM_INIT_READY;
 *     BSD_SIM_BUSY -> BSD_SIM_IDLE;
 *     BSD_SIM_INIT_READY -> BSD_SIM_INIT;
 *     BSD_SIM_IDLE -> BSD_SIM_BUSY;
 *     BSD_SIM_IDLE -> BSD_SIM_DELETED;
 *   }
 * @enddot
 */
enum bsd_sim_state {
  BSD_SIM_INIT = 0,
  BSD_SIM_INIT_BUSY,
  BSD_SIM_INIT_READY,
  BSD_SIM_IDLE,
  BSD_SIM_BUSY,
  BSD_SIM_DELETED
};
#endif /* __rtems__ */

/*
 * The sim driver should not access anything directly from this
 * structure.
 */
struct cam_sim {
	sim_action_func		sim_action;
	sim_poll_func		sim_poll;
	const char		*sim_name;
	void			*softc;
	struct mtx		*mtx;
#ifndef __rtems__
	TAILQ_HEAD(, ccb_hdr)	sim_doneq;
	TAILQ_ENTRY(cam_sim)	links;
	u_int32_t		path_id;/* The Boot device may set this to 0? */
#else /* __rtems__ */
	char			*disk;
	enum bsd_sim_state	state;
	struct cv		state_changed;
	union ccb		ccb;
#endif /* __rtems__ */
	u_int32_t		unit_number;
#ifndef __rtems__
	u_int32_t		bus_id;
	int			max_tagged_dev_openings;
	int			max_dev_openings;
	u_int32_t		flags;
#define	CAM_SIM_REL_TIMEOUT_PENDING	0x01
#define	CAM_SIM_MPSAFE			0x02
	struct callout		callout;
	struct cam_devq 	*devq;	/* Device Queue to use for this SIM */
	int			refcount; /* References to the SIM. */
#endif /* __rtems__ */
};

#define CAM_SIM_LOCK(sim)	mtx_lock((sim)->mtx)
#define CAM_SIM_UNLOCK(sim)	mtx_unlock((sim)->mtx)

static __inline u_int32_t
cam_sim_path(struct cam_sim *sim)
{
#ifndef __rtems__
	return (sim->path_id);
#else /* __rtems__ */
	return (0);
#endif /* __rtems__ */
}

static __inline const char *
cam_sim_name(struct cam_sim *sim)
{
	return (sim->sim_name);
}

static __inline void *
cam_sim_softc(struct cam_sim *sim)
{
	return (sim->softc);
}

static __inline u_int32_t
cam_sim_unit(struct cam_sim *sim)
{
	return (sim->unit_number);
}

#ifndef __rtems__
static __inline u_int32_t
cam_sim_bus(struct cam_sim *sim)
{
	return (sim->bus_id);
}
#endif /* __rtems__ */

#endif /* _KERNEL */
#endif /* _CAM_CAM_SIM_H */