Lines Matching full:sim

46 static MALLOC_DEFINE(M_CAMSIM, "CAM SIM", "CAM SIM buffers");
49 MTX_SYSINIT(cam_sim_free_init, &cam_sim_free_mtx, "CAM SIM free lock", MTX_DEF);
66 * @brief allocate a new sim and fill in the details
68 * A Storage Interface Module (SIM) is the interface between CAM and
69 * hardware. SIM receives CCBs from CAM via @p sim_action callback and
74 * The @p mtx acts as a perimeter lock for the SIM. All calls into the SIM's
76 * a SIM, managing its reference count. When the lock is NULL, the SIM is 100%
81 * outstanding transactions to the SIM. For HBAs that have global limits shared
83 * attached to the SIM.
87 * @param sim_name Name of SIM class
88 * @param softc Software context associated with the SIM
89 * @param unit Unit number of SIM
90 * @param mtx Mutex to lock while interacting with the SIM, or NULL
91 * for a SIM that handle its own locking to enable multi
97 * @param queue The cam_devq to use for this SIM.
105 struct cam_sim *sim; in cam_sim_alloc() local
107 sim = malloc(sizeof(struct cam_sim), M_CAMSIM, M_ZERO | M_NOWAIT); in cam_sim_alloc()
108 if (sim == NULL) in cam_sim_alloc()
111 sim->sim_action = sim_action; in cam_sim_alloc()
112 sim->sim_poll = sim_poll; in cam_sim_alloc()
113 sim->sim_name = sim_name; in cam_sim_alloc()
114 sim->softc = softc; in cam_sim_alloc()
115 sim->path_id = CAM_PATH_ANY; in cam_sim_alloc()
116 sim->unit_number = unit; in cam_sim_alloc()
117 sim->bus_id = 0; /* set in xpt_bus_register */ in cam_sim_alloc()
118 sim->max_tagged_dev_openings = max_tagged_dev_transactions; in cam_sim_alloc()
119 sim->max_dev_openings = max_dev_transactions; in cam_sim_alloc()
120 sim->flags = 0; in cam_sim_alloc()
121 sim->refcount = 1; in cam_sim_alloc()
122 sim->devq = queue; in cam_sim_alloc()
123 sim->mtx = mtx; in cam_sim_alloc()
124 return (sim); in cam_sim_alloc()
128 * @brief frees up the sim
130 * Frees up the CAM @c sim and optionally the devq. If a mutex is associated
131 * with the sim, it must be locked on entry. It will remain locked on
134 * This function will wait for all outstanding reference to the sim to clear
137 * @param sim The sim to free
138 * @param free_devq Free the devq associated with the sim at creation.
141 cam_sim_free(struct cam_sim *sim, int free_devq) in cam_sim_free() argument
146 if (sim->mtx == NULL) { in cam_sim_free()
150 mtx = sim->mtx; in cam_sim_free()
153 KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); in cam_sim_free()
154 sim->refcount--; in cam_sim_free()
155 if (sim->refcount > 0) { in cam_sim_free()
156 error = msleep(sim, mtx, PRIBIO, "simfree", 0); in cam_sim_free()
159 KASSERT(sim->refcount == 0, ("sim->refcount == 0")); in cam_sim_free()
160 if (mtx == &cam_sim_free_mtx) /* sim->mtx == NULL */ in cam_sim_free()
164 cam_simq_free(sim->devq); in cam_sim_free()
165 free(sim, M_CAMSIM); in cam_sim_free()
169 cam_sim_release(struct cam_sim *sim) in cam_sim_release() argument
173 if (sim->mtx == NULL) in cam_sim_release()
175 else if (!mtx_owned(sim->mtx)) in cam_sim_release()
176 mtx = sim->mtx; in cam_sim_release()
181 KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); in cam_sim_release()
182 sim->refcount--; in cam_sim_release()
183 if (sim->refcount == 0) in cam_sim_release()
184 wakeup(sim); in cam_sim_release()
190 cam_sim_hold(struct cam_sim *sim) in cam_sim_hold() argument
194 if (sim->mtx == NULL) in cam_sim_hold()
196 else if (!mtx_owned(sim->mtx)) in cam_sim_hold()
197 mtx = sim->mtx; in cam_sim_hold()
202 KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); in cam_sim_hold()
203 sim->refcount++; in cam_sim_hold()
209 cam_sim_set_path(struct cam_sim *sim, uint32_t path_id) in cam_sim_set_path() argument
211 sim->path_id = path_id; in cam_sim_set_path()