cam_sim.c (168864) | cam_sim.c (186185) |
---|---|
1/*- 2 * Common functions for SCSI Interface Modules (SIMs). 3 * 4 * Copyright (c) 1997 Justin T. Gibbs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Common functions for SCSI Interface Modules (SIMs). 3 * 4 * Copyright (c) 1997 Justin T. Gibbs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/cam/cam_sim.c 168864 2007-04-19 14:28:43Z scottl $"); | 30__FBSDID("$FreeBSD: head/sys/cam/cam_sim.c 186185 2008-12-16 16:57:33Z trasz $"); |
31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/malloc.h> 35#include <sys/kernel.h> 36#include <sys/lock.h> 37#include <sys/mutex.h> 38 --- 40 unchanged lines hidden (view full) --- 79 sim->sim_name = sim_name; 80 sim->softc = softc; 81 sim->path_id = CAM_PATH_ANY; 82 sim->unit_number = unit; 83 sim->bus_id = 0; /* set in xpt_bus_register */ 84 sim->max_tagged_dev_openings = max_tagged_dev_transactions; 85 sim->max_dev_openings = max_dev_transactions; 86 sim->flags = 0; | 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/malloc.h> 35#include <sys/kernel.h> 36#include <sys/lock.h> 37#include <sys/mutex.h> 38 --- 40 unchanged lines hidden (view full) --- 79 sim->sim_name = sim_name; 80 sim->softc = softc; 81 sim->path_id = CAM_PATH_ANY; 82 sim->unit_number = unit; 83 sim->bus_id = 0; /* set in xpt_bus_register */ 84 sim->max_tagged_dev_openings = max_tagged_dev_transactions; 85 sim->max_dev_openings = max_dev_transactions; 86 sim->flags = 0; |
87 sim->refcount = 1; |
|
87 sim->devq = queue; 88 sim->mtx = mtx; 89 if (mtx == &Giant) { 90 sim->flags |= 0; 91 callout_init(&sim->callout, 0); 92 } else { 93 sim->flags |= CAM_SIM_MPSAFE; 94 callout_init(&sim->callout, 1); 95 } 96 97 SLIST_INIT(&sim->ccb_freeq); 98 TAILQ_INIT(&sim->sim_doneq); 99 100 return (sim); 101} 102 103void 104cam_sim_free(struct cam_sim *sim, int free_devq) 105{ | 88 sim->devq = queue; 89 sim->mtx = mtx; 90 if (mtx == &Giant) { 91 sim->flags |= 0; 92 callout_init(&sim->callout, 0); 93 } else { 94 sim->flags |= CAM_SIM_MPSAFE; 95 callout_init(&sim->callout, 1); 96 } 97 98 SLIST_INIT(&sim->ccb_freeq); 99 TAILQ_INIT(&sim->sim_doneq); 100 101 return (sim); 102} 103 104void 105cam_sim_free(struct cam_sim *sim, int free_devq) 106{ |
107 int error; 108 109 sim->refcount--; 110 if (sim->refcount > 0) { 111 error = msleep(sim, sim->mtx, PRIBIO, "simfree", 0); 112 KASSERT(error == 0, ("invalid error value for msleep(9)")); 113 } 114 115 KASSERT(sim->refcount == 0, ("sim->refcount == 0")); 116 |
|
106 if (free_devq) 107 cam_simq_free(sim->devq); 108 free(sim, M_CAMSIM); 109} 110 111void | 117 if (free_devq) 118 cam_simq_free(sim->devq); 119 free(sim, M_CAMSIM); 120} 121 122void |
123cam_sim_release(struct cam_sim *sim) 124{ 125 KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); 126 127 sim->refcount--; 128 if (sim->refcount <= 1) 129 wakeup(sim); 130} 131 132void 133cam_sim_hold(struct cam_sim *sim) 134{ 135 KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); 136 137 sim->refcount++; 138} 139 140void |
|
112cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id) 113{ 114 sim->path_id = path_id; 115} | 141cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id) 142{ 143 sim->path_id = path_id; 144} |