master
  1/*-
  2 * Data structures and definitions for SCSI Interface Modules (SIMs).
  3 *
  4 * SPDX-License-Identifier: BSD-2-Clause
  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
 31#ifndef _CAM_CAM_SIM_H
 32#define _CAM_CAM_SIM_H 1
 33
 34#ifdef _KERNEL
 35
 36/*
 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.
 43 */
 44
 45struct cam_sim;
 46struct cam_devq;
 47
 48typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
 49typedef void (*sim_poll_func)(struct cam_sim *sim);
 50
 51struct cam_devq * cam_simq_alloc(uint32_t max_sim_transactions);
 52void		  cam_simq_free(struct cam_devq *devq);
 53
 54struct cam_sim *  cam_sim_alloc(sim_action_func sim_action,
 55				sim_poll_func sim_poll,
 56				const char *sim_name,
 57				void *softc,
 58				uint32_t unit,
 59				struct mtx *mtx,
 60				int max_dev_transactions,
 61				int max_tagged_dev_transactions,
 62				struct cam_devq *queue);
 63struct cam_sim *  cam_sim_alloc_dev(sim_action_func sim_action,
 64				sim_poll_func sim_poll,
 65				const char *sim_name,
 66				void *softc,
 67				device_t dev,
 68				struct mtx *mtx,
 69				int max_dev_transactions,
 70				int max_tagged_dev_transactions,
 71				struct cam_devq *queue);
 72void		  cam_sim_free(struct cam_sim *sim, int free_devq);
 73void		  cam_sim_hold(struct cam_sim *sim);
 74void		  cam_sim_release(struct cam_sim *sim);
 75
 76/* Optional sim attributes may be set with these. */
 77void	cam_sim_set_path(struct cam_sim *sim, uint32_t path_id);
 78
 79/* Generically useful offsets into the sim private area */
 80#define spriv_ptr0 sim_priv.entries[0].ptr
 81#define spriv_ptr1 sim_priv.entries[1].ptr
 82#define spriv_field0 sim_priv.entries[0].field
 83#define spriv_field1 sim_priv.entries[1].field
 84
 85/*
 86 * The sim driver should not access anything directly from this
 87 * structure.
 88 */
 89struct cam_sim {
 90	sim_action_func		sim_action;
 91	sim_poll_func		sim_poll;
 92	const char		*sim_name;
 93	void			*softc;
 94	struct mtx		*mtx;
 95	TAILQ_ENTRY(cam_sim)	links;
 96	uint32_t		path_id;/* The Boot device may set this to 0? */
 97	uint32_t		unit_number;
 98	uint32_t		bus_id;
 99	int			max_tagged_dev_openings;
100	int			max_dev_openings;
101	uint32_t		flags;
102	struct cam_devq 	*devq;	/* Device Queue to use for this SIM */
103	int			refcount; /* References to the SIM. */
104};
105
106static __inline uint32_t
107cam_sim_path(const struct cam_sim *sim)
108{
109	return (sim->path_id);
110}
111
112static __inline const char *
113cam_sim_name(const struct cam_sim *sim)
114{
115	return (sim->sim_name);
116}
117
118static __inline void *
119cam_sim_softc(const struct cam_sim *sim)
120{
121	return (sim->softc);
122}
123
124static __inline uint32_t
125cam_sim_unit(const struct cam_sim *sim)
126{
127	return (sim->unit_number);
128}
129
130static __inline uint32_t
131cam_sim_bus(const struct cam_sim *sim)
132{
133	return (sim->bus_id);
134}
135
136static __inline bool
137cam_sim_pollable(const struct cam_sim *sim)
138{
139	return (sim->sim_poll != NULL);
140}
141
142#endif /* _KERNEL */
143#endif /* _CAM_CAM_SIM_H */