1898b0535SWarner Losh /*- 28b8a9b1dSJustin T. Gibbs * Data structures and definitions for SCSI Interface Modules (SIMs). 38b8a9b1dSJustin T. Gibbs * 4bec9534dSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5bec9534dSPedro F. Giffuni * 68b8a9b1dSJustin T. Gibbs * Copyright (c) 1997 Justin T. Gibbs. 78b8a9b1dSJustin T. Gibbs * All rights reserved. 88b8a9b1dSJustin T. Gibbs * 98b8a9b1dSJustin T. Gibbs * Redistribution and use in source and binary forms, with or without 108b8a9b1dSJustin T. Gibbs * modification, are permitted provided that the following conditions 118b8a9b1dSJustin T. Gibbs * are met: 128b8a9b1dSJustin T. Gibbs * 1. Redistributions of source code must retain the above copyright 138b8a9b1dSJustin T. Gibbs * notice, this list of conditions, and the following disclaimer, 148b8a9b1dSJustin T. Gibbs * without modification, immediately at the beginning of the file. 158b8a9b1dSJustin T. Gibbs * 2. The name of the author may not be used to endorse or promote products 168b8a9b1dSJustin T. Gibbs * derived from this software without specific prior written permission. 178b8a9b1dSJustin T. Gibbs * 188b8a9b1dSJustin T. Gibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 198b8a9b1dSJustin T. Gibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 208b8a9b1dSJustin T. Gibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 218b8a9b1dSJustin T. Gibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 228b8a9b1dSJustin T. Gibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 238b8a9b1dSJustin T. Gibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 248b8a9b1dSJustin T. Gibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 258b8a9b1dSJustin T. Gibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 268b8a9b1dSJustin T. Gibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 278b8a9b1dSJustin T. Gibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 288b8a9b1dSJustin T. Gibbs * SUCH DAMAGE. 298b8a9b1dSJustin T. Gibbs * 30c3aac50fSPeter Wemm * $FreeBSD$ 318b8a9b1dSJustin T. Gibbs */ 328b8a9b1dSJustin T. Gibbs 338b8a9b1dSJustin T. Gibbs #ifndef _CAM_CAM_SIM_H 348b8a9b1dSJustin T. Gibbs #define _CAM_CAM_SIM_H 1 358b8a9b1dSJustin T. Gibbs 36c4473420SPeter Wemm #ifdef _KERNEL 378b8a9b1dSJustin T. Gibbs 388b8a9b1dSJustin T. Gibbs /* 398b8a9b1dSJustin T. Gibbs * The sim driver creates a sim for each controller. The sim device 408b8a9b1dSJustin T. Gibbs * queue is separately created in order to allow resource sharing between 418b8a9b1dSJustin T. Gibbs * sims. For instance, a driver may create one sim for each channel of 428b8a9b1dSJustin T. Gibbs * a multi-channel controller and use the same queue for each channel. 438b8a9b1dSJustin T. Gibbs * In this way, the queue resources are shared across all the channels 448b8a9b1dSJustin T. Gibbs * of the multi-channel controller. 458b8a9b1dSJustin T. Gibbs */ 468b8a9b1dSJustin T. Gibbs 478b8a9b1dSJustin T. Gibbs struct cam_sim; 488b8a9b1dSJustin T. Gibbs struct cam_devq; 498b8a9b1dSJustin T. Gibbs 508b8a9b1dSJustin T. Gibbs typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb); 518b8a9b1dSJustin T. Gibbs typedef void (*sim_poll_func)(struct cam_sim *sim); 528b8a9b1dSJustin T. Gibbs 538b8a9b1dSJustin T. Gibbs struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions); 548b8a9b1dSJustin T. Gibbs void cam_simq_free(struct cam_devq *devq); 558b8a9b1dSJustin T. Gibbs 568b8a9b1dSJustin T. Gibbs struct cam_sim * cam_sim_alloc(sim_action_func sim_action, 578b8a9b1dSJustin T. Gibbs sim_poll_func sim_poll, 58e2138feeSJohn Baldwin const char *sim_name, 598b8a9b1dSJustin T. Gibbs void *softc, 608b8a9b1dSJustin T. Gibbs u_int32_t unit, 612b83592fSScott Long struct mtx *mtx, 629deea857SKenneth D. Merry int max_dev_transactions, 639deea857SKenneth D. Merry int max_tagged_dev_transactions, 648b8a9b1dSJustin T. Gibbs struct cam_devq *queue); 656e40542aSBjoern A. Zeeb struct cam_sim * cam_sim_alloc_dev(sim_action_func sim_action, 666e40542aSBjoern A. Zeeb sim_poll_func sim_poll, 676e40542aSBjoern A. Zeeb const char *sim_name, 686e40542aSBjoern A. Zeeb void *softc, 696e40542aSBjoern A. Zeeb device_t dev, 706e40542aSBjoern A. Zeeb struct mtx *mtx, 716e40542aSBjoern A. Zeeb int max_dev_transactions, 726e40542aSBjoern A. Zeeb int max_tagged_dev_transactions, 736e40542aSBjoern A. Zeeb struct cam_devq *queue); 748b8a9b1dSJustin T. Gibbs void cam_sim_free(struct cam_sim *sim, int free_devq); 75fa6099fdSEdward Tomasz Napierala void cam_sim_hold(struct cam_sim *sim); 76fa6099fdSEdward Tomasz Napierala void cam_sim_release(struct cam_sim *sim); 778b8a9b1dSJustin T. Gibbs 788b8a9b1dSJustin T. Gibbs /* Optional sim attributes may be set with these. */ 798b8a9b1dSJustin T. Gibbs void cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id); 808b8a9b1dSJustin T. Gibbs 818b8a9b1dSJustin T. Gibbs 828b8a9b1dSJustin T. Gibbs 838b8a9b1dSJustin T. Gibbs /* Convenience routines for accessing sim attributes. */ 84*0b4da9c8SWarner Losh static __inline u_int32_t cam_sim_path(const struct cam_sim *sim); 85*0b4da9c8SWarner Losh static __inline const char * cam_sim_name(const struct cam_sim *sim); 86*0b4da9c8SWarner Losh static __inline void * cam_sim_softc(const struct cam_sim *sim); 87*0b4da9c8SWarner Losh static __inline u_int32_t cam_sim_unit(const struct cam_sim *sim); 88*0b4da9c8SWarner Losh static __inline u_int32_t cam_sim_bus(const struct cam_sim *sim); 898b8a9b1dSJustin T. Gibbs 908b8a9b1dSJustin T. Gibbs 918b8a9b1dSJustin T. Gibbs 928b8a9b1dSJustin T. Gibbs /* Generically useful offsets into the sim private area */ 938b8a9b1dSJustin T. Gibbs #define spriv_ptr0 sim_priv.entries[0].ptr 948b8a9b1dSJustin T. Gibbs #define spriv_ptr1 sim_priv.entries[1].ptr 958b8a9b1dSJustin T. Gibbs #define spriv_field0 sim_priv.entries[0].field 968b8a9b1dSJustin T. Gibbs #define spriv_field1 sim_priv.entries[1].field 978b8a9b1dSJustin T. Gibbs 988b8a9b1dSJustin T. Gibbs /* 998b8a9b1dSJustin T. Gibbs * The sim driver should not access anything directly from this 1008b8a9b1dSJustin T. Gibbs * structure. 1018b8a9b1dSJustin T. Gibbs */ 1028b8a9b1dSJustin T. Gibbs struct cam_sim { 1038b8a9b1dSJustin T. Gibbs sim_action_func sim_action; 1048b8a9b1dSJustin T. Gibbs sim_poll_func sim_poll; 105e2138feeSJohn Baldwin const char *sim_name; 1068b8a9b1dSJustin T. Gibbs void *softc; 1072b83592fSScott Long struct mtx *mtx; 1089758cc83SScott Long TAILQ_HEAD(, ccb_hdr) sim_doneq; 1099758cc83SScott Long TAILQ_ENTRY(cam_sim) links; 1108b8a9b1dSJustin T. Gibbs u_int32_t path_id;/* The Boot device may set this to 0? */ 1118b8a9b1dSJustin T. Gibbs u_int32_t unit_number; 1128b8a9b1dSJustin T. Gibbs u_int32_t bus_id; 1139deea857SKenneth D. Merry int max_tagged_dev_openings; 1149deea857SKenneth D. Merry int max_dev_openings; 1158b8a9b1dSJustin T. Gibbs u_int32_t flags; 1168b8a9b1dSJustin T. Gibbs #define CAM_SIM_REL_TIMEOUT_PENDING 0x01 1172b83592fSScott Long #define CAM_SIM_MPSAFE 0x02 1182b83592fSScott Long struct callout callout; 1198b8a9b1dSJustin T. Gibbs struct cam_devq *devq; /* Device Queue to use for this SIM */ 120fa6099fdSEdward Tomasz Napierala int refcount; /* References to the SIM. */ 1216e40542aSBjoern A. Zeeb device_t sim_dev; /* For attached peripherals. */ 1228b8a9b1dSJustin T. Gibbs }; 1238b8a9b1dSJustin T. Gibbs 1244b387081SAlexander Motin #define CAM_SIM_LOCK(sim) mtx_lock((sim)->mtx) 1254b387081SAlexander Motin #define CAM_SIM_UNLOCK(sim) mtx_unlock((sim)->mtx) 1262b83592fSScott Long 1278b8a9b1dSJustin T. Gibbs static __inline u_int32_t 128*0b4da9c8SWarner Losh cam_sim_path(const struct cam_sim *sim) 1298b8a9b1dSJustin T. Gibbs { 1308b8a9b1dSJustin T. Gibbs return (sim->path_id); 1318b8a9b1dSJustin T. Gibbs } 1328b8a9b1dSJustin T. Gibbs 133e2138feeSJohn Baldwin static __inline const char * 134*0b4da9c8SWarner Losh cam_sim_name(const struct cam_sim *sim) 1358b8a9b1dSJustin T. Gibbs { 1368b8a9b1dSJustin T. Gibbs return (sim->sim_name); 1378b8a9b1dSJustin T. Gibbs } 1388b8a9b1dSJustin T. Gibbs 1398b8a9b1dSJustin T. Gibbs static __inline void * 140*0b4da9c8SWarner Losh cam_sim_softc(const struct cam_sim *sim) 1418b8a9b1dSJustin T. Gibbs { 1428b8a9b1dSJustin T. Gibbs return (sim->softc); 1438b8a9b1dSJustin T. Gibbs } 1448b8a9b1dSJustin T. Gibbs 1458b8a9b1dSJustin T. Gibbs static __inline u_int32_t 146*0b4da9c8SWarner Losh cam_sim_unit(const struct cam_sim *sim) 1478b8a9b1dSJustin T. Gibbs { 1488b8a9b1dSJustin T. Gibbs return (sim->unit_number); 1498b8a9b1dSJustin T. Gibbs } 1508b8a9b1dSJustin T. Gibbs 1518b8a9b1dSJustin T. Gibbs static __inline u_int32_t 152*0b4da9c8SWarner Losh cam_sim_bus(const struct cam_sim *sim) 1538b8a9b1dSJustin T. Gibbs { 1548b8a9b1dSJustin T. Gibbs return (sim->bus_id); 1558b8a9b1dSJustin T. Gibbs } 1568b8a9b1dSJustin T. Gibbs 157c4473420SPeter Wemm #endif /* _KERNEL */ 1588b8a9b1dSJustin T. Gibbs #endif /* _CAM_CAM_SIM_H */ 159