Merge branch 'vendor/MPC'
[dragonfly.git] / sys / bus / cam / cam_sim.h
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 $
29  * $DragonFly: src/sys/bus/cam/cam_sim.h,v 1.9 2008/07/18 00:07:21 dillon Exp $
30  */
31
32 #ifndef _CAM_CAM_SIM_H
33 #define _CAM_CAM_SIM_H 1
34
35 #ifdef _KERNEL
36
37 #ifndef _SYS_SPINLOCK_H_
38 #include <sys/spinlock.h>
39 #endif
40
41 /*
42  * The sim driver creates a sim for each controller.  The sim device
43  * queue is separately created in order to allow resource sharing between
44  * sims.  For instance, a driver may create one sim for each channel of
45  * a multi-channel controller and use the same queue for each channel.
46  * In this way, the queue resources are shared across all the channels
47  * of the multi-channel controller.
48  */
49
50 struct cam_sim;
51 struct cam_devq;
52
53 typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
54 typedef void (*sim_poll_func)(struct cam_sim *sim);
55
56 typedef struct lock     sim_lock;
57 extern  sim_lock        sim_mplock;
58
59 void              cam_sim_lock(sim_lock *lock);
60 void              cam_sim_unlock(sim_lock *lock);
61 int               cam_sim_cond_lock(sim_lock *lock);
62 void              cam_sim_cond_unlock(sim_lock *lock, int doun);
63 void              sim_lock_assert_owned(sim_lock *lock);
64 void              sim_lock_assert_unowned(sim_lock *lock);
65 int               sim_lock_sleep(void *ident, int flags, const char *wmesg,
66                                  int timo, sim_lock *lock);
67 struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
68 void              cam_simq_release(struct cam_devq *devq);
69
70 struct cam_sim *  cam_sim_alloc(sim_action_func sim_action,
71                                 sim_poll_func sim_poll,
72                                 const char *sim_name,
73                                 void *softc,
74                                 u_int32_t unit,
75                                 sim_lock *lock,
76                                 int max_dev_transactions,
77                                 int max_tagged_dev_transactions,
78                                 struct cam_devq *queue);
79 void              cam_sim_free(struct cam_sim *sim);
80 void              cam_sim_release(struct cam_sim *sim, int flags);
81 void              cam_sim_set_max_tags(struct cam_sim *sim, int max_tags);
82
83 #define CAM_SIM_SOFTC   0x0002
84
85 /* Optional sim attributes may be set with these. */
86 void    cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
87
88
89
90 /* Convenience routines for accessing sim attributes. */
91 static __inline u_int32_t cam_sim_path(struct cam_sim *sim);
92 static __inline const char *cam_sim_name(struct cam_sim *sim);
93 static __inline void *    cam_sim_softc(struct cam_sim *sim);
94 static __inline u_int32_t cam_sim_unit(struct cam_sim *sim);
95 static __inline u_int32_t cam_sim_bus(struct cam_sim *sim);
96
97
98
99 /* Generically useful offsets into the sim private area */
100 #define spriv_ptr0 sim_priv.entries[0].ptr
101 #define spriv_ptr1 sim_priv.entries[1].ptr
102 #define spriv_field0 sim_priv.entries[0].field
103 #define spriv_field1 sim_priv.entries[1].field
104
105 /*
106  * The sim driver should not access anything directly from this
107  * structure.
108  */
109 struct cam_sim {
110         sim_action_func         sim_action;
111         sim_poll_func           sim_poll;
112         const char              *sim_name;
113         void                    *softc;         /* might be NULL */
114         sim_lock                *lock;
115         struct spinlock         sim_spin;
116         TAILQ_HEAD(, ccb_hdr)   sim_doneq;
117         TAILQ_ENTRY(cam_sim)    links;
118         u_int32_t               path_id;        /* bootdev may set this to 0? */
119         u_int32_t               unit_number;
120         u_int32_t               bus_id;
121         int                     max_tagged_dev_openings;
122         int                     max_dev_openings;
123         u_int32_t               flags;
124 #define CAM_SIM_REL_TIMEOUT_PENDING     0x01
125 #define CAM_SIM_MPSAFE                  0x02
126 #define CAM_SIM_ON_DONEQ                0x04
127 #define CAM_SIM_DEREGISTERED            0x08
128         struct callout          callout;
129         struct cam_devq         *devq;  /* Device Queue to use for this SIM */
130         int                     refcount;       /* References to the sim */
131
132         /* "Pool" of inactive ccbs managed by xpt_alloc_ccb and xpt_free_ccb */
133         SLIST_HEAD(,ccb_hdr)    ccb_freeq;
134         /*
135          * Maximum size of ccb pool.  Modified as devices are added/removed
136          * or have their * opening counts changed.
137          */
138         u_int                   max_ccbs;
139         /* Current count of allocated ccbs */
140         u_int                   ccb_count;
141
142 };
143
144 #define CAM_SIM_LOCK(sim)               cam_sim_lock((sim)->lock)
145 #define CAM_SIM_UNLOCK(sim)             cam_sim_unlock((sim)->lock)
146 #define CAM_SIM_COND_LOCK(sim)          cam_sim_cond_lock((sim)->lock)
147 #define CAM_SIM_COND_UNLOCK(sim, doun)  cam_sim_cond_unlock((sim)->lock, doun)
148
149 static __inline u_int32_t
150 cam_sim_path(struct cam_sim *sim)
151 {
152         return (sim->path_id);
153 }
154
155 static __inline const char *
156 cam_sim_name(struct cam_sim *sim)
157 {
158         return (sim->sim_name);
159 }
160
161 static __inline void *
162 cam_sim_softc(struct cam_sim *sim)
163 {
164         return (sim->softc);
165 }
166
167 static __inline u_int32_t
168 cam_sim_unit(struct cam_sim *sim)
169 {
170         return (sim->unit_number);
171 }
172
173 static __inline u_int32_t
174 cam_sim_bus(struct cam_sim *sim)
175 {
176         return (sim->bus_id);
177 }
178
179 #endif /* _KERNEL */
180 #endif /* _CAM_CAM_SIM_H */