2 * Data structures and definitions for SCSI Interface Modules (SIMs).
4 * Copyright (c) 1997 Justin T. Gibbs.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
31 #ifndef _CAM_CAM_SIM_H
32 #define _CAM_CAM_SIM_H 1
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.
48 typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
49 typedef void (*sim_poll_func)(struct cam_sim *sim);
51 struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
52 void cam_simq_free(struct cam_devq *devq);
54 struct cam_sim * cam_sim_alloc(sim_action_func sim_action,
55 sim_poll_func sim_poll,
60 int max_dev_transactions,
61 int max_tagged_dev_transactions,
62 struct cam_devq *queue);
63 void cam_sim_free(struct cam_sim *sim, int free_devq);
64 void cam_sim_hold(struct cam_sim *sim);
65 void cam_sim_release(struct cam_sim *sim);
67 /* Optional sim attributes may be set with these. */
68 void cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
72 /* Convenience routines for accessing sim attributes. */
73 static __inline u_int32_t cam_sim_path(struct cam_sim *sim);
74 static __inline const char * cam_sim_name(struct cam_sim *sim);
75 static __inline void * cam_sim_softc(struct cam_sim *sim);
76 static __inline u_int32_t cam_sim_unit(struct cam_sim *sim);
77 static __inline u_int32_t cam_sim_bus(struct cam_sim *sim);
81 /* Generically useful offsets into the sim private area */
82 #define spriv_ptr0 sim_priv.entries[0].ptr
83 #define spriv_ptr1 sim_priv.entries[1].ptr
84 #define spriv_field0 sim_priv.entries[0].field
85 #define spriv_field1 sim_priv.entries[1].field
88 * The sim driver should not access anything directly from this
92 sim_action_func sim_action;
93 sim_poll_func sim_poll;
97 TAILQ_HEAD(, ccb_hdr) sim_doneq;
98 TAILQ_ENTRY(cam_sim) links;
99 u_int32_t path_id;/* The Boot device may set this to 0? */
100 u_int32_t unit_number;
102 int max_tagged_dev_openings;
103 int max_dev_openings;
105 #define CAM_SIM_REL_TIMEOUT_PENDING 0x01
106 #define CAM_SIM_MPSAFE 0x02
107 #define CAM_SIM_ON_DONEQ 0x04
108 #define CAM_SIM_POLLED 0x08
109 #define CAM_SIM_BATCH 0x10
110 struct callout callout;
111 struct cam_devq *devq; /* Device Queue to use for this SIM */
112 int refcount; /* References to the SIM. */
114 /* "Pool" of inactive ccbs managed by xpt_get_ccb and xpt_release_ccb */
115 SLIST_HEAD(,ccb_hdr) ccb_freeq;
117 * Maximum size of ccb pool. Modified as devices are added/removed
118 * or have their * opening counts changed.
121 /* Current count of allocated ccbs */
126 #define CAM_SIM_LOCK(sim) mtx_lock((sim)->mtx)
127 #define CAM_SIM_UNLOCK(sim) mtx_unlock((sim)->mtx)
129 static __inline u_int32_t
130 cam_sim_path(struct cam_sim *sim)
132 return (sim->path_id);
135 static __inline const char *
136 cam_sim_name(struct cam_sim *sim)
138 return (sim->sim_name);
141 static __inline void *
142 cam_sim_softc(struct cam_sim *sim)
147 static __inline u_int32_t
148 cam_sim_unit(struct cam_sim *sim)
150 return (sim->unit_number);
153 static __inline u_int32_t
154 cam_sim_bus(struct cam_sim *sim)
156 return (sim->bus_id);
160 #endif /* _CAM_CAM_SIM_H */