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