cam_sim.h revision 71507
139212Sgibbs/*
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 71507 2001-01-24 01:46:18Z jhb $
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,
5946581Sken				int max_dev_transactions,
6046581Sken				int max_tagged_dev_transactions,
6139212Sgibbs				struct cam_devq *queue);
6239212Sgibbsvoid		  cam_sim_free(struct cam_sim *sim, int free_devq);
6339212Sgibbs
6439212Sgibbs/* Optional sim attributes may be set with these. */
6539212Sgibbsvoid	cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
6639212Sgibbs
6739212Sgibbs
6839212Sgibbs
6939212Sgibbs/* Convenience routines for accessing sim attributes. */
7071507Sjhbstatic __inline u_int32_t    cam_sim_path(struct cam_sim *sim);
7171507Sjhbstatic __inline const char * cam_sim_name(struct cam_sim *sim);
7271507Sjhbstatic __inline void *	     cam_sim_softc(struct cam_sim *sim);
7371507Sjhbstatic __inline u_int32_t    cam_sim_unit(struct cam_sim *sim);
7471507Sjhbstatic __inline u_int32_t    cam_sim_bus(struct cam_sim *sim);
7539212Sgibbs
7639212Sgibbs
7739212Sgibbs
7839212Sgibbs/* Generically useful offsets into the sim private area */
7939212Sgibbs#define spriv_ptr0 sim_priv.entries[0].ptr
8039212Sgibbs#define spriv_ptr1 sim_priv.entries[1].ptr
8139212Sgibbs#define spriv_field0 sim_priv.entries[0].field
8239212Sgibbs#define spriv_field1 sim_priv.entries[1].field
8339212Sgibbs
8439212Sgibbs/*
8539212Sgibbs * The sim driver should not access anything directly from this
8639212Sgibbs * structure.
8739212Sgibbs */
8839212Sgibbsstruct cam_sim {
8939212Sgibbs	sim_action_func		sim_action;
9039212Sgibbs	sim_poll_func		sim_poll;
9171507Sjhb	const char		*sim_name;
9239212Sgibbs	void			*softc;
9339212Sgibbs	u_int32_t		path_id;/* The Boot device may set this to 0? */
9439212Sgibbs	u_int32_t		unit_number;
9539212Sgibbs	u_int32_t		bus_id;
9646581Sken	int			max_tagged_dev_openings;
9746581Sken	int			max_dev_openings;
9839212Sgibbs	u_int32_t		flags;
9939212Sgibbs#define		CAM_SIM_REL_TIMEOUT_PENDING	0x01
10039212Sgibbs	struct callout_handle	c_handle;
10139212Sgibbs	struct cam_devq 	*devq;	/* Device Queue to use for this SIM */
10239212Sgibbs};
10339212Sgibbs
10439212Sgibbsstatic __inline u_int32_t
10539212Sgibbscam_sim_path(struct cam_sim *sim)
10639212Sgibbs{
10739212Sgibbs	return (sim->path_id);
10839212Sgibbs}
10939212Sgibbs
11071507Sjhbstatic __inline const char *
11139212Sgibbscam_sim_name(struct cam_sim *sim)
11239212Sgibbs{
11339212Sgibbs	return (sim->sim_name);
11439212Sgibbs}
11539212Sgibbs
11639212Sgibbsstatic __inline void *
11739212Sgibbscam_sim_softc(struct cam_sim *sim)
11839212Sgibbs{
11939212Sgibbs	return (sim->softc);
12039212Sgibbs}
12139212Sgibbs
12239212Sgibbsstatic __inline u_int32_t
12339212Sgibbscam_sim_unit(struct cam_sim *sim)
12439212Sgibbs{
12539212Sgibbs	return (sim->unit_number);
12639212Sgibbs}
12739212Sgibbs
12839212Sgibbsstatic __inline u_int32_t
12939212Sgibbscam_sim_bus(struct cam_sim *sim)
13039212Sgibbs{
13139212Sgibbs	return (sim->bus_id);
13239212Sgibbs}
13339212Sgibbs
13455206Speter#endif /* _KERNEL */
13539212Sgibbs#endif /* _CAM_CAM_SIM_H */
136