cam_sim.h revision 39212
1/*
2 * Data structures and definitions for SCSI Interface Modules (SIMs).
3 *
4 * Copyright (c) 1997 Justin T. Gibbs.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions, and the following disclaimer,
12 *    without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 *    derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 *      $Id$
29 */
30
31#ifndef _CAM_CAM_SIM_H
32#define _CAM_CAM_SIM_H 1
33
34#ifdef KERNEL
35
36/*
37 * The sim driver creates a sim for each controller.  The sim device
38 * queue is separately created in order to allow resource sharing between
39 * sims.  For instance, a driver may create one sim for each channel of
40 * a multi-channel controller and use the same queue for each channel.
41 * In this way, the queue resources are shared across all the channels
42 * of the multi-channel controller.
43 */
44
45struct cam_sim;
46struct cam_devq;
47
48typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
49typedef void (*sim_poll_func)(struct cam_sim *sim);
50
51struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
52void		  cam_simq_free(struct cam_devq *devq);
53
54struct cam_sim *  cam_sim_alloc(sim_action_func sim_action,
55				sim_poll_func sim_poll,
56				char *sim_name,
57				void *softc,
58				u_int32_t unit,
59				u_int32_t max_dev_transactions,
60				u_int32_t max_tagged_dev_transactions,
61				struct cam_devq *queue);
62void		  cam_sim_free(struct cam_sim *sim, int free_devq);
63
64/* Optional sim attributes may be set with these. */
65void	cam_sim_set_basexfer_speed(struct cam_sim *sim,
66				   u_int32_t base_xfer_speed);
67void	cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
68
69
70
71/* Convenience routines for accessing sim attributes. */
72static __inline u_int32_t cam_sim_path(struct cam_sim *sim);
73static __inline char *	  cam_sim_name(struct cam_sim *sim);
74static __inline void *	  cam_sim_softc(struct cam_sim *sim);
75static __inline u_int32_t cam_sim_unit(struct cam_sim *sim);
76static __inline u_int32_t cam_sim_bus(struct cam_sim *sim);
77
78
79
80/* Generically useful offsets into the sim private area */
81#define spriv_ptr0 sim_priv.entries[0].ptr
82#define spriv_ptr1 sim_priv.entries[1].ptr
83#define spriv_field0 sim_priv.entries[0].field
84#define spriv_field1 sim_priv.entries[1].field
85
86/*
87 * The sim driver should not access anything directly from this
88 * structure.
89 */
90struct cam_sim {
91	sim_action_func		sim_action;
92	sim_poll_func		sim_poll;
93	char			*sim_name;
94	void			*softc;
95	u_int32_t		path_id;/* The Boot device may set this to 0? */
96	u_int32_t		unit_number;
97	u_int32_t		bus_id;
98	u_int32_t		base_transfer_speed; /* in kB/s */
99	u_int32_t		max_tagged_dev_openings;
100	u_int32_t		max_dev_openings;
101	u_int32_t		flags;
102#define		CAM_SIM_REL_TIMEOUT_PENDING	0x01
103	struct callout_handle	c_handle;
104	struct cam_devq 	*devq;	/* Device Queue to use for this SIM */
105};
106
107static __inline u_int32_t
108cam_sim_path(struct cam_sim *sim)
109{
110	return (sim->path_id);
111}
112
113static __inline char *
114cam_sim_name(struct cam_sim *sim)
115{
116	return (sim->sim_name);
117}
118
119static __inline void *
120cam_sim_softc(struct cam_sim *sim)
121{
122	return (sim->softc);
123}
124
125static __inline u_int32_t
126cam_sim_unit(struct cam_sim *sim)
127{
128	return (sim->unit_number);
129}
130
131static __inline u_int32_t
132cam_sim_bus(struct cam_sim *sim)
133{
134	return (sim->bus_id);
135}
136
137#endif /* KERNEL */
138#endif /* _CAM_CAM_SIM_H */
139