The cam_sim structure was being deallocated unconditionally by device
[dragonfly.git] / sys / bus / cam / cam_sim.h
CommitLineData
984263bc
MD
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 * $FreeBSD: src/sys/cam/cam_sim.h,v 1.4 1999/12/29 04:54:27 peter Exp $
3aed1355 29 * $DragonFly: src/sys/bus/cam/cam_sim.h,v 1.4 2004/03/15 01:10:30 dillon Exp $
984263bc
MD
30 */
31
32#ifndef _CAM_CAM_SIM_H
33#define _CAM_CAM_SIM_H 1
34
35#ifdef _KERNEL
36
37/*
38 * The sim driver creates a sim for each controller. The sim device
39 * queue is separately created in order to allow resource sharing between
40 * sims. For instance, a driver may create one sim for each channel of
41 * a multi-channel controller and use the same queue for each channel.
42 * In this way, the queue resources are shared across all the channels
43 * of the multi-channel controller.
44 */
45
46struct cam_sim;
47struct cam_devq;
48
49typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
50typedef void (*sim_poll_func)(struct cam_sim *sim);
51
52struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
3aed1355 53void cam_simq_release(struct cam_devq *devq);
984263bc
MD
54
55struct cam_sim * cam_sim_alloc(sim_action_func sim_action,
56 sim_poll_func sim_poll,
f15db79e 57 const char *sim_name,
984263bc
MD
58 void *softc,
59 u_int32_t unit,
60 int max_dev_transactions,
61 int max_tagged_dev_transactions,
62 struct cam_devq *queue);
3aed1355
MD
63void cam_sim_free(struct cam_sim *sim);
64void cam_sim_release(struct cam_sim *sim, int flags);
65
66#define CAM_SIM_DEVQ 0x0001
67#define CAM_SIM_SOFTC 0x0002
984263bc
MD
68
69/* Optional sim attributes may be set with these. */
70void cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
71
72
73
74/* Convenience routines for accessing sim attributes. */
75static __inline u_int32_t cam_sim_path(struct cam_sim *sim);
f15db79e 76static __inline const char *cam_sim_name(struct cam_sim *sim);
984263bc
MD
77static __inline void * cam_sim_softc(struct cam_sim *sim);
78static __inline u_int32_t cam_sim_unit(struct cam_sim *sim);
79static __inline u_int32_t cam_sim_bus(struct cam_sim *sim);
80
81
82
83/* Generically useful offsets into the sim private area */
84#define spriv_ptr0 sim_priv.entries[0].ptr
85#define spriv_ptr1 sim_priv.entries[1].ptr
86#define spriv_field0 sim_priv.entries[0].field
87#define spriv_field1 sim_priv.entries[1].field
88
89/*
90 * The sim driver should not access anything directly from this
91 * structure.
92 */
93struct cam_sim {
94 sim_action_func sim_action;
95 sim_poll_func sim_poll;
f15db79e 96 const char *sim_name;
3aed1355
MD
97 void *softc; /* might be NULL */
98 u_int32_t path_id; /* bootdev may set this to 0? */
984263bc
MD
99 u_int32_t unit_number;
100 u_int32_t bus_id;
101 int max_tagged_dev_openings;
102 int max_dev_openings;
103 u_int32_t flags;
104#define CAM_SIM_REL_TIMEOUT_PENDING 0x01
105 struct callout_handle c_handle;
106 struct cam_devq *devq; /* Device Queue to use for this SIM */
3aed1355 107 int refcount; /* References to the sim */
984263bc
MD
108};
109
110static __inline u_int32_t
111cam_sim_path(struct cam_sim *sim)
112{
113 return (sim->path_id);
114}
115
f15db79e 116static __inline const char *
984263bc
MD
117cam_sim_name(struct cam_sim *sim)
118{
119 return (sim->sim_name);
120}
121
122static __inline void *
123cam_sim_softc(struct cam_sim *sim)
124{
125 return (sim->softc);
126}
127
128static __inline u_int32_t
129cam_sim_unit(struct cam_sim *sim)
130{
131 return (sim->unit_number);
132}
133
134static __inline u_int32_t
135cam_sim_bus(struct cam_sim *sim)
136{
137 return (sim->bus_id);
138}
139
140#endif /* _KERNEL */
141#endif /* _CAM_CAM_SIM_H */