1208926Smjacob/*- 2208926Smjacob * Copyright (c) 2010 by Panasas, Inc. 3208926Smjacob * All rights reserved. 4208926Smjacob * 5208926Smjacob * Redistribution and use in source and binary forms, with or without 6208926Smjacob * modification, are permitted provided that the following conditions 7208926Smjacob * are met: 8208926Smjacob * 1. Redistributions of source code must retain the above copyright 9208926Smjacob * notice immediately at the beginning of the file, without modification, 10208926Smjacob * this list of conditions, and the following disclaimer. 11208926Smjacob * 2. The name of the author may not be used to endorse or promote products 12208926Smjacob * derived from this software without specific prior written permission. 13208926Smjacob * 14208926Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15208926Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16208926Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17208926Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18208926Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19208926Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20208926Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21208926Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22208926Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23208926Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24208926Smjacob * SUCH DAMAGE. 25208926Smjacob */ 26208926Smjacob/* $FreeBSD$ */ 27208926Smjacob/* 28208926Smjacob * Virtual HBA defines 29208926Smjacob */ 30208926Smjacob#include <sys/cdefs.h> 31208926Smjacob#include <sys/param.h> 32208926Smjacob#include <sys/systm.h> 33208926Smjacob#include <sys/endian.h> 34208926Smjacob#include <sys/lock.h> 35208926Smjacob#include <sys/kernel.h> 36208926Smjacob#include <sys/queue.h> 37208926Smjacob#include <sys/queue.h> 38208926Smjacob#include <sys/malloc.h> 39208926Smjacob#include <sys/taskqueue.h> 40208926Smjacob#include <sys/mutex.h> 41208926Smjacob#include <sys/condvar.h> 42208926Smjacob 43208926Smjacob#include <sys/proc.h> 44208926Smjacob 45208926Smjacob#include <machine/bus.h> 46253750Savg#include <machine/cpu.h> 47208926Smjacob#include <machine/stdarg.h> 48208926Smjacob 49208926Smjacob#include <cam/cam.h> 50208926Smjacob#include <cam/cam_debug.h> 51208926Smjacob#include <cam/cam_ccb.h> 52208926Smjacob#include <cam/cam_sim.h> 53208926Smjacob#include <cam/cam_xpt.h> 54208926Smjacob#include <cam/cam_xpt_sim.h> 55208926Smjacob#include <cam/cam_debug.h> 56208926Smjacob#include <cam/scsi/scsi_all.h> 57208926Smjacob#include <cam/scsi/scsi_message.h> 58208926Smjacob 59208926Smjacob 60208926Smjacob#include <sys/unistd.h> 61208926Smjacob#include <sys/kthread.h> 62208926Smjacob#include <sys/conf.h> 63208926Smjacob#include <sys/module.h> 64208926Smjacob#include <sys/ioccom.h> 65208926Smjacob#include <sys/devicestat.h> 66208926Smjacob#include <cam/cam_periph.h> 67208926Smjacob#include <cam/cam_xpt_periph.h> 68208926Smjacob 69208926Smjacob#define VHBA_MAXTGT 64 70208926Smjacob#define VHBA_MAXCMDS 256 71208926Smjacob 72208926Smjacobtypedef struct { 73208926Smjacob struct mtx lock; 74208926Smjacob struct cam_sim * sim; 75208926Smjacob struct cam_devq * devq; 76208926Smjacob TAILQ_HEAD(, ccb_hdr) actv; 77208926Smjacob TAILQ_HEAD(, ccb_hdr) done; 78208926Smjacob void * private; 79208926Smjacob} vhba_softc_t; 80208926Smjacob 81208926Smjacob/* 82208926Smjacob * Each different instantiation of a fake HBA needs to 83208926Smjacob * provide these as function entry points. It's responsible 84208926Smjacob * for setting up some thread or regular timeout that will 85208926Smjacob * dequeue things from the actv queue and put done items 86208926Smjacob * on the done queue. 87208926Smjacob */ 88208926Smjacobvoid vhba_init(vhba_softc_t *); 89208926Smjacobvoid vhba_fini(vhba_softc_t *); 90208926Smjacobvoid vhba_kick(vhba_softc_t *); 91208926Smjacob 92208926Smjacob/* 93208926Smjacob * Support functions 94208926Smjacob */ 95208926Smjacobvoid vhba_fill_sense(struct ccb_scsiio *, uint8_t, uint8_t, uint8_t); 96208926Smjacobint vhba_rwparm(uint8_t *, uint64_t *, uint32_t *, uint64_t, uint32_t); 97208926Smjacobvoid vhba_default_cmd(struct ccb_scsiio *, lun_id_t, uint8_t *); 98208926Smjacobvoid vhba_set_status(struct ccb_hdr *, cam_status); 99208926Smjacob 100208926Smjacob/* 101208926Smjacob * Common module loader function 102208926Smjacob */ 103208926Smjacobint vhba_modprobe(module_t, int, void *); 104208926Smjacob 105208926Smjacob/* 106208926Smjacob * retrofits 107208926Smjacob */ 108208926Smjacob#ifndef MODE_SENSE 109208926Smjacob#define MODE_SENSE 0x1a 110208926Smjacob#endif 111208926Smjacob#ifndef SMS_FORMAT_DEVICE_PAGE 112208926Smjacob#define SMS_FORMAT_DEVICE_PAGE 0x03 113208926Smjacob#endif 114208926Smjacob#ifndef SMS_GEOMETRY_PAGE 115208926Smjacob#define SMS_GEOMETRY_PAGE 0x04 116208926Smjacob#endif 117