1898b0535SWarner Losh /*- 28b8a9b1dSJustin T. Gibbs * Data structures and definitions for SCSI Interface Modules (SIMs). 38b8a9b1dSJustin T. Gibbs * 48b8a9b1dSJustin T. Gibbs * Copyright (c) 1997 Justin T. Gibbs. 58b8a9b1dSJustin T. Gibbs * All rights reserved. 68b8a9b1dSJustin T. Gibbs * 78b8a9b1dSJustin T. Gibbs * Redistribution and use in source and binary forms, with or without 88b8a9b1dSJustin T. Gibbs * modification, are permitted provided that the following conditions 98b8a9b1dSJustin T. Gibbs * are met: 108b8a9b1dSJustin T. Gibbs * 1. Redistributions of source code must retain the above copyright 118b8a9b1dSJustin T. Gibbs * notice, this list of conditions, and the following disclaimer, 128b8a9b1dSJustin T. Gibbs * without modification, immediately at the beginning of the file. 138b8a9b1dSJustin T. Gibbs * 2. The name of the author may not be used to endorse or promote products 148b8a9b1dSJustin T. Gibbs * derived from this software without specific prior written permission. 158b8a9b1dSJustin T. Gibbs * 168b8a9b1dSJustin T. Gibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 178b8a9b1dSJustin T. Gibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 188b8a9b1dSJustin T. Gibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 198b8a9b1dSJustin T. Gibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 208b8a9b1dSJustin T. Gibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 218b8a9b1dSJustin T. Gibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 228b8a9b1dSJustin T. Gibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 238b8a9b1dSJustin T. Gibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 248b8a9b1dSJustin T. Gibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 258b8a9b1dSJustin T. Gibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 268b8a9b1dSJustin T. Gibbs * SUCH DAMAGE. 278b8a9b1dSJustin T. Gibbs * 28c3aac50fSPeter Wemm * $FreeBSD$ 298b8a9b1dSJustin T. Gibbs */ 308b8a9b1dSJustin T. Gibbs 318b8a9b1dSJustin T. Gibbs #ifndef _CAM_CAM_SIM_H 328b8a9b1dSJustin T. Gibbs #define _CAM_CAM_SIM_H 1 338b8a9b1dSJustin T. Gibbs 34c4473420SPeter Wemm #ifdef _KERNEL 358b8a9b1dSJustin T. Gibbs 368b8a9b1dSJustin T. Gibbs /* 378b8a9b1dSJustin T. Gibbs * The sim driver creates a sim for each controller. The sim device 388b8a9b1dSJustin T. Gibbs * queue is separately created in order to allow resource sharing between 398b8a9b1dSJustin T. Gibbs * sims. For instance, a driver may create one sim for each channel of 408b8a9b1dSJustin T. Gibbs * a multi-channel controller and use the same queue for each channel. 418b8a9b1dSJustin T. Gibbs * In this way, the queue resources are shared across all the channels 428b8a9b1dSJustin T. Gibbs * of the multi-channel controller. 438b8a9b1dSJustin T. Gibbs */ 448b8a9b1dSJustin T. Gibbs 458b8a9b1dSJustin T. Gibbs struct cam_sim; 468b8a9b1dSJustin T. Gibbs struct cam_devq; 478b8a9b1dSJustin T. Gibbs 488b8a9b1dSJustin T. Gibbs typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb); 498b8a9b1dSJustin T. Gibbs typedef void (*sim_poll_func)(struct cam_sim *sim); 508b8a9b1dSJustin T. Gibbs 518b8a9b1dSJustin T. Gibbs struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions); 528b8a9b1dSJustin T. Gibbs void cam_simq_free(struct cam_devq *devq); 538b8a9b1dSJustin T. Gibbs 548b8a9b1dSJustin T. Gibbs struct cam_sim * cam_sim_alloc(sim_action_func sim_action, 558b8a9b1dSJustin T. Gibbs sim_poll_func sim_poll, 56e2138feeSJohn Baldwin const char *sim_name, 578b8a9b1dSJustin T. Gibbs void *softc, 588b8a9b1dSJustin T. Gibbs u_int32_t unit, 592b83592fSScott Long struct mtx *mtx, 609deea857SKenneth D. Merry int max_dev_transactions, 619deea857SKenneth D. Merry int max_tagged_dev_transactions, 628b8a9b1dSJustin T. Gibbs struct cam_devq *queue); 638b8a9b1dSJustin T. Gibbs void cam_sim_free(struct cam_sim *sim, int free_devq); 648b8a9b1dSJustin T. Gibbs 658b8a9b1dSJustin T. Gibbs /* Optional sim attributes may be set with these. */ 668b8a9b1dSJustin T. Gibbs void cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id); 678b8a9b1dSJustin T. Gibbs 688b8a9b1dSJustin T. Gibbs 698b8a9b1dSJustin T. Gibbs 708b8a9b1dSJustin T. Gibbs /* Convenience routines for accessing sim attributes. */ 718b8a9b1dSJustin T. Gibbs static __inline u_int32_t cam_sim_path(struct cam_sim *sim); 72e2138feeSJohn Baldwin static __inline const char * cam_sim_name(struct cam_sim *sim); 738b8a9b1dSJustin T. Gibbs static __inline void * cam_sim_softc(struct cam_sim *sim); 748b8a9b1dSJustin T. Gibbs static __inline u_int32_t cam_sim_unit(struct cam_sim *sim); 758b8a9b1dSJustin T. Gibbs static __inline u_int32_t cam_sim_bus(struct cam_sim *sim); 768b8a9b1dSJustin T. Gibbs 778b8a9b1dSJustin T. Gibbs 788b8a9b1dSJustin T. Gibbs 798b8a9b1dSJustin T. Gibbs /* Generically useful offsets into the sim private area */ 808b8a9b1dSJustin T. Gibbs #define spriv_ptr0 sim_priv.entries[0].ptr 818b8a9b1dSJustin T. Gibbs #define spriv_ptr1 sim_priv.entries[1].ptr 828b8a9b1dSJustin T. Gibbs #define spriv_field0 sim_priv.entries[0].field 838b8a9b1dSJustin T. Gibbs #define spriv_field1 sim_priv.entries[1].field 848b8a9b1dSJustin T. Gibbs 858b8a9b1dSJustin T. Gibbs /* 868b8a9b1dSJustin T. Gibbs * The sim driver should not access anything directly from this 878b8a9b1dSJustin T. Gibbs * structure. 888b8a9b1dSJustin T. Gibbs */ 898b8a9b1dSJustin T. Gibbs struct cam_sim { 908b8a9b1dSJustin T. Gibbs sim_action_func sim_action; 918b8a9b1dSJustin T. Gibbs sim_poll_func sim_poll; 92e2138feeSJohn Baldwin const char *sim_name; 938b8a9b1dSJustin T. Gibbs void *softc; 942b83592fSScott Long struct mtx *mtx; 959758cc83SScott Long TAILQ_HEAD(, ccb_hdr) sim_doneq; 969758cc83SScott Long TAILQ_ENTRY(cam_sim) links; 978b8a9b1dSJustin T. Gibbs u_int32_t path_id;/* The Boot device may set this to 0? */ 988b8a9b1dSJustin T. Gibbs u_int32_t unit_number; 998b8a9b1dSJustin T. Gibbs u_int32_t bus_id; 1009deea857SKenneth D. Merry int max_tagged_dev_openings; 1019deea857SKenneth D. Merry int max_dev_openings; 1028b8a9b1dSJustin T. Gibbs u_int32_t flags; 1038b8a9b1dSJustin T. Gibbs #define CAM_SIM_REL_TIMEOUT_PENDING 0x01 1042b83592fSScott Long #define CAM_SIM_MPSAFE 0x02 1059758cc83SScott Long #define CAM_SIM_ON_DONEQ 0x04 1062b83592fSScott Long struct callout callout; 1078b8a9b1dSJustin T. Gibbs struct cam_devq *devq; /* Device Queue to use for this SIM */ 1082b83592fSScott Long 1092b83592fSScott Long /* "Pool" of inactive ccbs managed by xpt_alloc_ccb and xpt_free_ccb */ 1102b83592fSScott Long SLIST_HEAD(,ccb_hdr) ccb_freeq; 1112b83592fSScott Long /* 1122b83592fSScott Long * Maximum size of ccb pool. Modified as devices are added/removed 1132b83592fSScott Long * or have their * opening counts changed. 1142b83592fSScott Long */ 1152b83592fSScott Long u_int max_ccbs; 1162b83592fSScott Long /* Current count of allocated ccbs */ 1172b83592fSScott Long u_int ccb_count; 1182b83592fSScott Long 1198b8a9b1dSJustin T. Gibbs }; 1208b8a9b1dSJustin T. Gibbs 1212b83592fSScott Long #define CAM_SIM_LOCK(sim) mtx_lock((sim)->mtx); 1222b83592fSScott Long #define CAM_SIM_UNLOCK(sim) mtx_unlock((sim)->mtx); 1232b83592fSScott Long 1248b8a9b1dSJustin T. Gibbs static __inline u_int32_t 1258b8a9b1dSJustin T. Gibbs cam_sim_path(struct cam_sim *sim) 1268b8a9b1dSJustin T. Gibbs { 1278b8a9b1dSJustin T. Gibbs return (sim->path_id); 1288b8a9b1dSJustin T. Gibbs } 1298b8a9b1dSJustin T. Gibbs 130e2138feeSJohn Baldwin static __inline const char * 1318b8a9b1dSJustin T. Gibbs cam_sim_name(struct cam_sim *sim) 1328b8a9b1dSJustin T. Gibbs { 1338b8a9b1dSJustin T. Gibbs return (sim->sim_name); 1348b8a9b1dSJustin T. Gibbs } 1358b8a9b1dSJustin T. Gibbs 1368b8a9b1dSJustin T. Gibbs static __inline void * 1378b8a9b1dSJustin T. Gibbs cam_sim_softc(struct cam_sim *sim) 1388b8a9b1dSJustin T. Gibbs { 1398b8a9b1dSJustin T. Gibbs return (sim->softc); 1408b8a9b1dSJustin T. Gibbs } 1418b8a9b1dSJustin T. Gibbs 1428b8a9b1dSJustin T. Gibbs static __inline u_int32_t 1438b8a9b1dSJustin T. Gibbs cam_sim_unit(struct cam_sim *sim) 1448b8a9b1dSJustin T. Gibbs { 1458b8a9b1dSJustin T. Gibbs return (sim->unit_number); 1468b8a9b1dSJustin T. Gibbs } 1478b8a9b1dSJustin T. Gibbs 1488b8a9b1dSJustin T. Gibbs static __inline u_int32_t 1498b8a9b1dSJustin T. Gibbs cam_sim_bus(struct cam_sim *sim) 1508b8a9b1dSJustin T. Gibbs { 1518b8a9b1dSJustin T. Gibbs return (sim->bus_id); 1528b8a9b1dSJustin T. Gibbs } 1538b8a9b1dSJustin T. Gibbs 154c4473420SPeter Wemm #endif /* _KERNEL */ 1558b8a9b1dSJustin T. Gibbs #endif /* _CAM_CAM_SIM_H */ 156