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$ 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); 64186185Straszvoid cam_sim_hold(struct cam_sim *sim); 65186185Straszvoid cam_sim_release(struct cam_sim *sim); 6639212Sgibbs 6739212Sgibbs/* Optional sim attributes may be set with these. */ 6839212Sgibbsvoid cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id); 6939212Sgibbs 7039212Sgibbs 7139212Sgibbs 7239212Sgibbs/* Convenience routines for accessing sim attributes. */ 7371507Sjhbstatic __inline u_int32_t cam_sim_path(struct cam_sim *sim); 7471507Sjhbstatic __inline const char * cam_sim_name(struct cam_sim *sim); 7571507Sjhbstatic __inline void * cam_sim_softc(struct cam_sim *sim); 7671507Sjhbstatic __inline u_int32_t cam_sim_unit(struct cam_sim *sim); 7771507Sjhbstatic __inline u_int32_t cam_sim_bus(struct cam_sim *sim); 7839212Sgibbs 7939212Sgibbs 8039212Sgibbs 8139212Sgibbs/* Generically useful offsets into the sim private area */ 8239212Sgibbs#define spriv_ptr0 sim_priv.entries[0].ptr 8339212Sgibbs#define spriv_ptr1 sim_priv.entries[1].ptr 8439212Sgibbs#define spriv_field0 sim_priv.entries[0].field 8539212Sgibbs#define spriv_field1 sim_priv.entries[1].field 8639212Sgibbs 8739212Sgibbs/* 8839212Sgibbs * The sim driver should not access anything directly from this 8939212Sgibbs * structure. 9039212Sgibbs */ 9139212Sgibbsstruct cam_sim { 9239212Sgibbs sim_action_func sim_action; 9339212Sgibbs sim_poll_func sim_poll; 9471507Sjhb const char *sim_name; 9539212Sgibbs void *softc; 96168752Sscottl struct mtx *mtx; 97168864Sscottl TAILQ_HEAD(, ccb_hdr) sim_doneq; 98168864Sscottl TAILQ_ENTRY(cam_sim) links; 9939212Sgibbs u_int32_t path_id;/* The Boot device may set this to 0? */ 10039212Sgibbs u_int32_t unit_number; 10139212Sgibbs u_int32_t bus_id; 10246581Sken int max_tagged_dev_openings; 10346581Sken int max_dev_openings; 10439212Sgibbs u_int32_t flags; 105168752Sscottl#define CAM_SIM_REL_TIMEOUT_PENDING 0x01 106168752Sscottl#define CAM_SIM_MPSAFE 0x02 107168752Sscottl struct callout callout; 10839212Sgibbs struct cam_devq *devq; /* Device Queue to use for this SIM */ 109186185Strasz int refcount; /* References to the SIM. */ 11039212Sgibbs}; 11139212Sgibbs 112249224Smav#define CAM_SIM_LOCK(sim) mtx_lock((sim)->mtx) 113249224Smav#define CAM_SIM_UNLOCK(sim) mtx_unlock((sim)->mtx) 114168752Sscottl 11539212Sgibbsstatic __inline u_int32_t 11639212Sgibbscam_sim_path(struct cam_sim *sim) 11739212Sgibbs{ 11839212Sgibbs return (sim->path_id); 11939212Sgibbs} 12039212Sgibbs 12171507Sjhbstatic __inline const char * 12239212Sgibbscam_sim_name(struct cam_sim *sim) 12339212Sgibbs{ 12439212Sgibbs return (sim->sim_name); 12539212Sgibbs} 12639212Sgibbs 12739212Sgibbsstatic __inline void * 12839212Sgibbscam_sim_softc(struct cam_sim *sim) 12939212Sgibbs{ 13039212Sgibbs return (sim->softc); 13139212Sgibbs} 13239212Sgibbs 13339212Sgibbsstatic __inline u_int32_t 13439212Sgibbscam_sim_unit(struct cam_sim *sim) 13539212Sgibbs{ 13639212Sgibbs return (sim->unit_number); 13739212Sgibbs} 13839212Sgibbs 13939212Sgibbsstatic __inline u_int32_t 14039212Sgibbscam_sim_bus(struct cam_sim *sim) 14139212Sgibbs{ 14239212Sgibbs return (sim->bus_id); 14339212Sgibbs} 14439212Sgibbs 14555206Speter#endif /* _KERNEL */ 14639212Sgibbs#endif /* _CAM_CAM_SIM_H */ 147