cam_sim.h revision 249224
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 249224 2013-04-07 06:47:44Z mav $ 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 107227637Smav#define CAM_SIM_ON_DONEQ 0x04 108227637Smav#define CAM_SIM_POLLED 0x08 109235333Smav#define CAM_SIM_BATCH 0x10 110168752Sscottl struct callout callout; 11139212Sgibbs struct cam_devq *devq; /* Device Queue to use for this SIM */ 112186185Strasz int refcount; /* References to the SIM. */ 113168752Sscottl 114186396Sscottl /* "Pool" of inactive ccbs managed by xpt_get_ccb and xpt_release_ccb */ 115168752Sscottl SLIST_HEAD(,ccb_hdr) ccb_freeq; 116168752Sscottl /* 117168752Sscottl * Maximum size of ccb pool. Modified as devices are added/removed 118168752Sscottl * or have their * opening counts changed. 119168752Sscottl */ 120168752Sscottl u_int max_ccbs; 121168752Sscottl /* Current count of allocated ccbs */ 122168752Sscottl u_int ccb_count; 123168752Sscottl 12439212Sgibbs}; 12539212Sgibbs 126249224Smav#define CAM_SIM_LOCK(sim) mtx_lock((sim)->mtx) 127249224Smav#define CAM_SIM_UNLOCK(sim) mtx_unlock((sim)->mtx) 128168752Sscottl 12939212Sgibbsstatic __inline u_int32_t 13039212Sgibbscam_sim_path(struct cam_sim *sim) 13139212Sgibbs{ 13239212Sgibbs return (sim->path_id); 13339212Sgibbs} 13439212Sgibbs 13571507Sjhbstatic __inline const char * 13639212Sgibbscam_sim_name(struct cam_sim *sim) 13739212Sgibbs{ 13839212Sgibbs return (sim->sim_name); 13939212Sgibbs} 14039212Sgibbs 14139212Sgibbsstatic __inline void * 14239212Sgibbscam_sim_softc(struct cam_sim *sim) 14339212Sgibbs{ 14439212Sgibbs return (sim->softc); 14539212Sgibbs} 14639212Sgibbs 14739212Sgibbsstatic __inline u_int32_t 14839212Sgibbscam_sim_unit(struct cam_sim *sim) 14939212Sgibbs{ 15039212Sgibbs return (sim->unit_number); 15139212Sgibbs} 15239212Sgibbs 15339212Sgibbsstatic __inline u_int32_t 15439212Sgibbscam_sim_bus(struct cam_sim *sim) 15539212Sgibbs{ 15639212Sgibbs return (sim->bus_id); 15739212Sgibbs} 15839212Sgibbs 15955206Speter#endif /* _KERNEL */ 16039212Sgibbs#endif /* _CAM_CAM_SIM_H */ 161