cam_sim.h revision 168864
1139743Simp/*-
239212Sgibbs * Data structures and definitions for SCSI Interface Modules (SIMs).
339212Sgibbs *
439212Sgibbs * Copyright (c) 1997 Justin T. Gibbs.
539212Sgibbs * All rights reserved.
639212Sgibbs *
739212Sgibbs * Redistribution and use in source and binary forms, with or without
839212Sgibbs * modification, are permitted provided that the following conditions
939212Sgibbs * are met:
1039212Sgibbs * 1. Redistributions of source code must retain the above copyright
1139212Sgibbs *    notice, this list of conditions, and the following disclaimer,
1239212Sgibbs *    without modification, immediately at the beginning of the file.
1339212Sgibbs * 2. The name of the author may not be used to endorse or promote products
1439212Sgibbs *    derived from this software without specific prior written permission.
1539212Sgibbs *
1639212Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1739212Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1839212Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1939212Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2039212Sgibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2139212Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2239212Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2339212Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2439212Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2539212Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2639212Sgibbs * SUCH DAMAGE.
2739212Sgibbs *
2850477Speter * $FreeBSD: head/sys/cam/cam_sim.h 168864 2007-04-19 14:28:43Z scottl $
2939212Sgibbs */
3039212Sgibbs
3139212Sgibbs#ifndef _CAM_CAM_SIM_H
3239212Sgibbs#define _CAM_CAM_SIM_H 1
3339212Sgibbs
3455206Speter#ifdef _KERNEL
3539212Sgibbs
3639212Sgibbs/*
3739212Sgibbs * The sim driver creates a sim for each controller.  The sim device
3839212Sgibbs * queue is separately created in order to allow resource sharing between
3939212Sgibbs * sims.  For instance, a driver may create one sim for each channel of
4039212Sgibbs * a multi-channel controller and use the same queue for each channel.
4139212Sgibbs * In this way, the queue resources are shared across all the channels
4239212Sgibbs * of the multi-channel controller.
4339212Sgibbs */
4439212Sgibbs
4539212Sgibbsstruct cam_sim;
4639212Sgibbsstruct cam_devq;
4739212Sgibbs
4839212Sgibbstypedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
4939212Sgibbstypedef void (*sim_poll_func)(struct cam_sim *sim);
5039212Sgibbs
5139212Sgibbsstruct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
5239212Sgibbsvoid		  cam_simq_free(struct cam_devq *devq);
5339212Sgibbs
5439212Sgibbsstruct cam_sim *  cam_sim_alloc(sim_action_func sim_action,
5539212Sgibbs				sim_poll_func sim_poll,
5671507Sjhb				const char *sim_name,
5739212Sgibbs				void *softc,
5839212Sgibbs				u_int32_t unit,
59168752Sscottl				struct mtx *mtx,
6046581Sken				int max_dev_transactions,
6146581Sken				int max_tagged_dev_transactions,
6239212Sgibbs				struct cam_devq *queue);
6339212Sgibbsvoid		  cam_sim_free(struct cam_sim *sim, int free_devq);
6439212Sgibbs
6539212Sgibbs/* Optional sim attributes may be set with these. */
6639212Sgibbsvoid	cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
6739212Sgibbs
6839212Sgibbs
6939212Sgibbs
7039212Sgibbs/* Convenience routines for accessing sim attributes. */
7171507Sjhbstatic __inline u_int32_t    cam_sim_path(struct cam_sim *sim);
7271507Sjhbstatic __inline const char * cam_sim_name(struct cam_sim *sim);
7371507Sjhbstatic __inline void *	     cam_sim_softc(struct cam_sim *sim);
7471507Sjhbstatic __inline u_int32_t    cam_sim_unit(struct cam_sim *sim);
7571507Sjhbstatic __inline u_int32_t    cam_sim_bus(struct cam_sim *sim);
7639212Sgibbs
7739212Sgibbs
7839212Sgibbs
7939212Sgibbs/* Generically useful offsets into the sim private area */
8039212Sgibbs#define spriv_ptr0 sim_priv.entries[0].ptr
8139212Sgibbs#define spriv_ptr1 sim_priv.entries[1].ptr
8239212Sgibbs#define spriv_field0 sim_priv.entries[0].field
8339212Sgibbs#define spriv_field1 sim_priv.entries[1].field
8439212Sgibbs
8539212Sgibbs/*
8639212Sgibbs * The sim driver should not access anything directly from this
8739212Sgibbs * structure.
8839212Sgibbs */
8939212Sgibbsstruct cam_sim {
9039212Sgibbs	sim_action_func		sim_action;
9139212Sgibbs	sim_poll_func		sim_poll;
9271507Sjhb	const char		*sim_name;
9339212Sgibbs	void			*softc;
94168752Sscottl	struct mtx		*mtx;
95168864Sscottl	TAILQ_HEAD(, ccb_hdr)	sim_doneq;
96168864Sscottl	TAILQ_ENTRY(cam_sim)	links;
9739212Sgibbs	u_int32_t		path_id;/* The Boot device may set this to 0? */
9839212Sgibbs	u_int32_t		unit_number;
9939212Sgibbs	u_int32_t		bus_id;
10046581Sken	int			max_tagged_dev_openings;
10146581Sken	int			max_dev_openings;
10239212Sgibbs	u_int32_t		flags;
103168752Sscottl#define	CAM_SIM_REL_TIMEOUT_PENDING	0x01
104168752Sscottl#define	CAM_SIM_MPSAFE			0x02
105168864Sscottl#define CAM_SIM_ON_DONEQ		0x04
106168752Sscottl	struct callout		callout;
10739212Sgibbs	struct cam_devq 	*devq;	/* Device Queue to use for this SIM */
108168752Sscottl
109168752Sscottl	/* "Pool" of inactive ccbs managed by xpt_alloc_ccb and xpt_free_ccb */
110168752Sscottl	SLIST_HEAD(,ccb_hdr)	ccb_freeq;
111168752Sscottl	/*
112168752Sscottl	 * Maximum size of ccb pool.  Modified as devices are added/removed
113168752Sscottl	 * or have their * opening counts changed.
114168752Sscottl	 */
115168752Sscottl	u_int			max_ccbs;
116168752Sscottl	/* Current count of allocated ccbs */
117168752Sscottl	u_int			ccb_count;
118168752Sscottl
11939212Sgibbs};
12039212Sgibbs
121168752Sscottl#define CAM_SIM_LOCK(sim)	mtx_lock((sim)->mtx);
122168752Sscottl#define CAM_SIM_UNLOCK(sim)	mtx_unlock((sim)->mtx);
123168752Sscottl
12439212Sgibbsstatic __inline u_int32_t
12539212Sgibbscam_sim_path(struct cam_sim *sim)
12639212Sgibbs{
12739212Sgibbs	return (sim->path_id);
12839212Sgibbs}
12939212Sgibbs
13071507Sjhbstatic __inline const char *
13139212Sgibbscam_sim_name(struct cam_sim *sim)
13239212Sgibbs{
13339212Sgibbs	return (sim->sim_name);
13439212Sgibbs}
13539212Sgibbs
13639212Sgibbsstatic __inline void *
13739212Sgibbscam_sim_softc(struct cam_sim *sim)
13839212Sgibbs{
13939212Sgibbs	return (sim->softc);
14039212Sgibbs}
14139212Sgibbs
14239212Sgibbsstatic __inline u_int32_t
14339212Sgibbscam_sim_unit(struct cam_sim *sim)
14439212Sgibbs{
14539212Sgibbs	return (sim->unit_number);
14639212Sgibbs}
14739212Sgibbs
14839212Sgibbsstatic __inline u_int32_t
14939212Sgibbscam_sim_bus(struct cam_sim *sim)
15039212Sgibbs{
15139212Sgibbs	return (sim->bus_id);
15239212Sgibbs}
15339212Sgibbs
15455206Speter#endif /* _KERNEL */
15539212Sgibbs#endif /* _CAM_CAM_SIM_H */
156