18b8a9b1dSJustin T. Gibbs /* 28b8a9b1dSJustin T. Gibbs * Common functions 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 #include <sys/param.h> 328b8a9b1dSJustin T. Gibbs #include <sys/systm.h> 338b8a9b1dSJustin T. Gibbs #include <sys/malloc.h> 348b8a9b1dSJustin T. Gibbs 358b8a9b1dSJustin T. Gibbs #include <cam/cam.h> 368b8a9b1dSJustin T. Gibbs #include <cam/cam_ccb.h> 378b8a9b1dSJustin T. Gibbs #include <cam/cam_sim.h> 388b8a9b1dSJustin T. Gibbs #include <cam/cam_queue.h> 398b8a9b1dSJustin T. Gibbs 408b8a9b1dSJustin T. Gibbs #define CAM_PATH_ANY (u_int32_t)-1 418b8a9b1dSJustin T. Gibbs 428b8a9b1dSJustin T. Gibbs struct cam_devq * 438b8a9b1dSJustin T. Gibbs cam_simq_alloc(u_int32_t max_sim_transactions) 448b8a9b1dSJustin T. Gibbs { 458b8a9b1dSJustin T. Gibbs return (cam_devq_alloc(/*size*/0, max_sim_transactions)); 468b8a9b1dSJustin T. Gibbs } 478b8a9b1dSJustin T. Gibbs 488b8a9b1dSJustin T. Gibbs void 498b8a9b1dSJustin T. Gibbs cam_simq_free(struct cam_devq *devq) 508b8a9b1dSJustin T. Gibbs { 518b8a9b1dSJustin T. Gibbs cam_devq_free(devq); 528b8a9b1dSJustin T. Gibbs } 538b8a9b1dSJustin T. Gibbs 548b8a9b1dSJustin T. Gibbs struct cam_sim * 558b8a9b1dSJustin T. Gibbs cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll, 568b8a9b1dSJustin T. Gibbs char *sim_name, void *softc, u_int32_t unit, 579deea857SKenneth D. Merry int max_dev_transactions, 589deea857SKenneth D. Merry int max_tagged_dev_transactions, struct cam_devq *queue) 598b8a9b1dSJustin T. Gibbs { 608b8a9b1dSJustin T. Gibbs struct cam_sim *sim; 618b8a9b1dSJustin T. Gibbs 628b8a9b1dSJustin T. Gibbs /* 638b8a9b1dSJustin T. Gibbs * If this is the xpt layer creating a sim, then it's OK 648b8a9b1dSJustin T. Gibbs * to wait for an allocation. 658b8a9b1dSJustin T. Gibbs * 668b8a9b1dSJustin T. Gibbs * XXX Should we pass in a flag to indicate that wait is OK? 678b8a9b1dSJustin T. Gibbs */ 688b8a9b1dSJustin T. Gibbs if (strcmp(sim_name, "xpt") == 0) 698b8a9b1dSJustin T. Gibbs sim = (struct cam_sim *)malloc(sizeof(struct cam_sim), 708b8a9b1dSJustin T. Gibbs M_DEVBUF, M_WAITOK); 718b8a9b1dSJustin T. Gibbs else 728b8a9b1dSJustin T. Gibbs sim = (struct cam_sim *)malloc(sizeof(struct cam_sim), 738b8a9b1dSJustin T. Gibbs M_DEVBUF, M_NOWAIT); 748b8a9b1dSJustin T. Gibbs 758b8a9b1dSJustin T. Gibbs if (sim != NULL) { 768b8a9b1dSJustin T. Gibbs sim->sim_action = sim_action; 778b8a9b1dSJustin T. Gibbs sim->sim_poll = sim_poll; 788b8a9b1dSJustin T. Gibbs sim->sim_name = sim_name; 798b8a9b1dSJustin T. Gibbs sim->softc = softc; 808b8a9b1dSJustin T. Gibbs sim->path_id = CAM_PATH_ANY; 818b8a9b1dSJustin T. Gibbs sim->unit_number = unit; 828b8a9b1dSJustin T. Gibbs sim->bus_id = 0; /* set in xpt_bus_register */ 838b8a9b1dSJustin T. Gibbs sim->max_tagged_dev_openings = max_tagged_dev_transactions; 848b8a9b1dSJustin T. Gibbs sim->max_dev_openings = max_dev_transactions; 858b8a9b1dSJustin T. Gibbs sim->flags = 0; 868b8a9b1dSJustin T. Gibbs callout_handle_init(&sim->c_handle); 878b8a9b1dSJustin T. Gibbs sim->devq = queue; 888b8a9b1dSJustin T. Gibbs } 898b8a9b1dSJustin T. Gibbs 908b8a9b1dSJustin T. Gibbs return (sim); 918b8a9b1dSJustin T. Gibbs } 928b8a9b1dSJustin T. Gibbs 938b8a9b1dSJustin T. Gibbs void 948b8a9b1dSJustin T. Gibbs cam_sim_free(struct cam_sim *sim, int free_devq) 958b8a9b1dSJustin T. Gibbs { 968b8a9b1dSJustin T. Gibbs if (free_devq) 978b8a9b1dSJustin T. Gibbs cam_simq_free(sim->devq); 988b8a9b1dSJustin T. Gibbs free(sim, M_DEVBUF); 998b8a9b1dSJustin T. Gibbs } 1008b8a9b1dSJustin T. Gibbs 1018b8a9b1dSJustin T. Gibbs void 1028b8a9b1dSJustin T. Gibbs cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id) 1038b8a9b1dSJustin T. Gibbs { 1048b8a9b1dSJustin T. Gibbs sim->path_id = path_id; 1058b8a9b1dSJustin T. Gibbs } 106