xref: /freebsd/sys/cam/cam_sim.h (revision 447b3557a9cc5f00a301be8404339f21a9a0faa8)
1898b0535SWarner Losh /*-
28b8a9b1dSJustin T. Gibbs  * Data structures and definitions for SCSI Interface Modules (SIMs).
38b8a9b1dSJustin T. Gibbs  *
4bec9534dSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5bec9534dSPedro F. Giffuni  *
68b8a9b1dSJustin T. Gibbs  * Copyright (c) 1997 Justin T. Gibbs.
78b8a9b1dSJustin T. Gibbs  * All rights reserved.
88b8a9b1dSJustin T. Gibbs  *
98b8a9b1dSJustin T. Gibbs  * Redistribution and use in source and binary forms, with or without
108b8a9b1dSJustin T. Gibbs  * modification, are permitted provided that the following conditions
118b8a9b1dSJustin T. Gibbs  * are met:
128b8a9b1dSJustin T. Gibbs  * 1. Redistributions of source code must retain the above copyright
138b8a9b1dSJustin T. Gibbs  *    notice, this list of conditions, and the following disclaimer,
148b8a9b1dSJustin T. Gibbs  *    without modification, immediately at the beginning of the file.
158b8a9b1dSJustin T. Gibbs  * 2. The name of the author may not be used to endorse or promote products
168b8a9b1dSJustin T. Gibbs  *    derived from this software without specific prior written permission.
178b8a9b1dSJustin T. Gibbs  *
188b8a9b1dSJustin T. Gibbs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
198b8a9b1dSJustin T. Gibbs  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
208b8a9b1dSJustin T. Gibbs  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
218b8a9b1dSJustin T. Gibbs  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
228b8a9b1dSJustin T. Gibbs  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
238b8a9b1dSJustin T. Gibbs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
248b8a9b1dSJustin T. Gibbs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
258b8a9b1dSJustin T. Gibbs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
268b8a9b1dSJustin T. Gibbs  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
278b8a9b1dSJustin T. Gibbs  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
288b8a9b1dSJustin T. Gibbs  * SUCH DAMAGE.
298b8a9b1dSJustin T. Gibbs  *
30c3aac50fSPeter Wemm  * $FreeBSD$
318b8a9b1dSJustin T. Gibbs  */
328b8a9b1dSJustin T. Gibbs 
338b8a9b1dSJustin T. Gibbs #ifndef _CAM_CAM_SIM_H
348b8a9b1dSJustin T. Gibbs #define _CAM_CAM_SIM_H 1
358b8a9b1dSJustin T. Gibbs 
36c4473420SPeter Wemm #ifdef _KERNEL
378b8a9b1dSJustin T. Gibbs 
388b8a9b1dSJustin T. Gibbs /*
398b8a9b1dSJustin T. Gibbs  * The sim driver creates a sim for each controller.  The sim device
408b8a9b1dSJustin T. Gibbs  * queue is separately created in order to allow resource sharing between
418b8a9b1dSJustin T. Gibbs  * sims.  For instance, a driver may create one sim for each channel of
428b8a9b1dSJustin T. Gibbs  * a multi-channel controller and use the same queue for each channel.
438b8a9b1dSJustin T. Gibbs  * In this way, the queue resources are shared across all the channels
448b8a9b1dSJustin T. Gibbs  * of the multi-channel controller.
458b8a9b1dSJustin T. Gibbs  */
468b8a9b1dSJustin T. Gibbs 
478b8a9b1dSJustin T. Gibbs struct cam_sim;
488b8a9b1dSJustin T. Gibbs struct cam_devq;
498b8a9b1dSJustin T. Gibbs 
508b8a9b1dSJustin T. Gibbs typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
518b8a9b1dSJustin T. Gibbs typedef void (*sim_poll_func)(struct cam_sim *sim);
528b8a9b1dSJustin T. Gibbs 
538b8a9b1dSJustin T. Gibbs struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
548b8a9b1dSJustin T. Gibbs void		  cam_simq_free(struct cam_devq *devq);
558b8a9b1dSJustin T. Gibbs 
568b8a9b1dSJustin T. Gibbs struct cam_sim *  cam_sim_alloc(sim_action_func sim_action,
578b8a9b1dSJustin T. Gibbs 				sim_poll_func sim_poll,
58e2138feeSJohn Baldwin 				const char *sim_name,
598b8a9b1dSJustin T. Gibbs 				void *softc,
608b8a9b1dSJustin T. Gibbs 				u_int32_t unit,
612b83592fSScott Long 				struct mtx *mtx,
629deea857SKenneth D. Merry 				int max_dev_transactions,
639deea857SKenneth D. Merry 				int max_tagged_dev_transactions,
648b8a9b1dSJustin T. Gibbs 				struct cam_devq *queue);
656e40542aSBjoern A. Zeeb struct cam_sim *  cam_sim_alloc_dev(sim_action_func sim_action,
666e40542aSBjoern A. Zeeb 				sim_poll_func sim_poll,
676e40542aSBjoern A. Zeeb 				const char *sim_name,
686e40542aSBjoern A. Zeeb 				void *softc,
696e40542aSBjoern A. Zeeb 				device_t dev,
706e40542aSBjoern A. Zeeb 				struct mtx *mtx,
716e40542aSBjoern A. Zeeb 				int max_dev_transactions,
726e40542aSBjoern A. Zeeb 				int max_tagged_dev_transactions,
736e40542aSBjoern A. Zeeb 				struct cam_devq *queue);
748b8a9b1dSJustin T. Gibbs void		  cam_sim_free(struct cam_sim *sim, int free_devq);
75fa6099fdSEdward Tomasz Napierala void		  cam_sim_hold(struct cam_sim *sim);
76fa6099fdSEdward Tomasz Napierala void		  cam_sim_release(struct cam_sim *sim);
778b8a9b1dSJustin T. Gibbs 
788b8a9b1dSJustin T. Gibbs /* Optional sim attributes may be set with these. */
798b8a9b1dSJustin T. Gibbs void	cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
808b8a9b1dSJustin T. Gibbs 
818b8a9b1dSJustin T. Gibbs /* Generically useful offsets into the sim private area */
828b8a9b1dSJustin T. Gibbs #define spriv_ptr0 sim_priv.entries[0].ptr
838b8a9b1dSJustin T. Gibbs #define spriv_ptr1 sim_priv.entries[1].ptr
848b8a9b1dSJustin T. Gibbs #define spriv_field0 sim_priv.entries[0].field
858b8a9b1dSJustin T. Gibbs #define spriv_field1 sim_priv.entries[1].field
868b8a9b1dSJustin T. Gibbs 
878b8a9b1dSJustin T. Gibbs /*
888b8a9b1dSJustin T. Gibbs  * The sim driver should not access anything directly from this
898b8a9b1dSJustin T. Gibbs  * structure.
908b8a9b1dSJustin T. Gibbs  */
918b8a9b1dSJustin T. Gibbs struct cam_sim {
928b8a9b1dSJustin T. Gibbs 	sim_action_func		sim_action;
938b8a9b1dSJustin T. Gibbs 	sim_poll_func		sim_poll;
94e2138feeSJohn Baldwin 	const char		*sim_name;
958b8a9b1dSJustin T. Gibbs 	void			*softc;
962b83592fSScott Long 	struct mtx		*mtx;
979758cc83SScott Long 	TAILQ_HEAD(, ccb_hdr)	sim_doneq;
989758cc83SScott Long 	TAILQ_ENTRY(cam_sim)	links;
998b8a9b1dSJustin T. Gibbs 	u_int32_t		path_id;/* The Boot device may set this to 0? */
1008b8a9b1dSJustin T. Gibbs 	u_int32_t		unit_number;
1018b8a9b1dSJustin T. Gibbs 	u_int32_t		bus_id;
1029deea857SKenneth D. Merry 	int			max_tagged_dev_openings;
1039deea857SKenneth D. Merry 	int			max_dev_openings;
1048b8a9b1dSJustin T. Gibbs 	u_int32_t		flags;
1058b8a9b1dSJustin T. Gibbs #define	CAM_SIM_REL_TIMEOUT_PENDING	0x01
1062b83592fSScott Long 	struct callout		callout;
1078b8a9b1dSJustin T. Gibbs 	struct cam_devq 	*devq;	/* Device Queue to use for this SIM */
108fa6099fdSEdward Tomasz Napierala 	int			refcount; /* References to the SIM. */
1096e40542aSBjoern A. Zeeb 	device_t		sim_dev; /* For attached peripherals. */
1108b8a9b1dSJustin T. Gibbs };
1118b8a9b1dSJustin T. Gibbs 
1124b387081SAlexander Motin #define CAM_SIM_LOCK(sim)	mtx_lock((sim)->mtx)
1134b387081SAlexander Motin #define CAM_SIM_UNLOCK(sim)	mtx_unlock((sim)->mtx)
1142b83592fSScott Long 
1158b8a9b1dSJustin T. Gibbs static __inline u_int32_t
1160b4da9c8SWarner Losh cam_sim_path(const struct cam_sim *sim)
1178b8a9b1dSJustin T. Gibbs {
1188b8a9b1dSJustin T. Gibbs 	return (sim->path_id);
1198b8a9b1dSJustin T. Gibbs }
1208b8a9b1dSJustin T. Gibbs 
121e2138feeSJohn Baldwin static __inline const char *
1220b4da9c8SWarner Losh cam_sim_name(const struct cam_sim *sim)
1238b8a9b1dSJustin T. Gibbs {
1248b8a9b1dSJustin T. Gibbs 	return (sim->sim_name);
1258b8a9b1dSJustin T. Gibbs }
1268b8a9b1dSJustin T. Gibbs 
1278b8a9b1dSJustin T. Gibbs static __inline void *
1280b4da9c8SWarner Losh cam_sim_softc(const struct cam_sim *sim)
1298b8a9b1dSJustin T. Gibbs {
1308b8a9b1dSJustin T. Gibbs 	return (sim->softc);
1318b8a9b1dSJustin T. Gibbs }
1328b8a9b1dSJustin T. Gibbs 
1338b8a9b1dSJustin T. Gibbs static __inline u_int32_t
1340b4da9c8SWarner Losh cam_sim_unit(const struct cam_sim *sim)
1358b8a9b1dSJustin T. Gibbs {
1368b8a9b1dSJustin T. Gibbs 	return (sim->unit_number);
1378b8a9b1dSJustin T. Gibbs }
1388b8a9b1dSJustin T. Gibbs 
1398b8a9b1dSJustin T. Gibbs static __inline u_int32_t
1400b4da9c8SWarner Losh cam_sim_bus(const struct cam_sim *sim)
1418b8a9b1dSJustin T. Gibbs {
1428b8a9b1dSJustin T. Gibbs 	return (sim->bus_id);
1438b8a9b1dSJustin T. Gibbs }
1448b8a9b1dSJustin T. Gibbs 
145*447b3557SJohn Baldwin static __inline bool
146*447b3557SJohn Baldwin cam_sim_pollable(const struct cam_sim *sim)
147*447b3557SJohn Baldwin {
148*447b3557SJohn Baldwin 	return (sim->sim_poll != NULL);
149*447b3557SJohn Baldwin }
150*447b3557SJohn Baldwin 
151c4473420SPeter Wemm #endif /* _KERNEL */
1528b8a9b1dSJustin T. Gibbs #endif /* _CAM_CAM_SIM_H */
153