vhba.h revision 253749
1/*- 2 * Copyright (c) 2010 by Panasas, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice immediately at the beginning of the file, without modification, 10 * this list of conditions, and the following disclaimer. 11 * 2. The name of the author may not be used to endorse or promote products 12 * derived from this software without specific prior written permission. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26/* $FreeBSD: head/tools/tools/vhba/vhba.h 253749 2013-07-28 18:35:43Z avg $ */ 27/* 28 * Virtual HBA defines 29 */ 30#include <sys/cdefs.h> 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/endian.h> 34#include <sys/lock.h> 35#include <sys/kernel.h> 36#include <sys/queue.h> 37#include <sys/queue.h> 38#include <sys/malloc.h> 39#include <sys/taskqueue.h> 40#include <sys/mutex.h> 41#include <sys/condvar.h> 42 43#include <sys/proc.h> 44 45#include <machine/bus.h> 46#include <machine/stdarg.h> 47 48#include <cam/cam.h> 49#include <cam/cam_debug.h> 50#include <cam/cam_ccb.h> 51#include <cam/cam_sim.h> 52#include <cam/cam_xpt.h> 53#include <cam/cam_xpt_sim.h> 54#include <cam/cam_debug.h> 55#include <cam/scsi/scsi_all.h> 56#include <cam/scsi/scsi_message.h> 57 58 59#include <sys/unistd.h> 60#include <sys/kthread.h> 61#include <sys/conf.h> 62#include <sys/module.h> 63#include <sys/ioccom.h> 64#include <sys/devicestat.h> 65#include <cam/cam_periph.h> 66#include <cam/cam_xpt_periph.h> 67 68#define VHBA_MAXTGT 64 69#define VHBA_MAXCMDS 256 70 71typedef struct { 72 struct mtx lock; 73 struct cam_sim * sim; 74 struct cam_devq * devq; 75 TAILQ_HEAD(, ccb_hdr) actv; 76 TAILQ_HEAD(, ccb_hdr) done; 77 void * private; 78} vhba_softc_t; 79 80/* 81 * Each different instantiation of a fake HBA needs to 82 * provide these as function entry points. It's responsible 83 * for setting up some thread or regular timeout that will 84 * dequeue things from the actv queue and put done items 85 * on the done queue. 86 */ 87void vhba_init(vhba_softc_t *); 88void vhba_fini(vhba_softc_t *); 89void vhba_kick(vhba_softc_t *); 90 91/* 92 * Support functions 93 */ 94void vhba_fill_sense(struct ccb_scsiio *, uint8_t, uint8_t, uint8_t); 95int vhba_rwparm(uint8_t *, uint64_t *, uint32_t *, uint64_t, uint32_t); 96void vhba_default_cmd(struct ccb_scsiio *, lun_id_t, uint8_t *); 97void vhba_set_status(struct ccb_hdr *, cam_status); 98 99/* 100 * Common module loader function 101 */ 102int vhba_modprobe(module_t, int, void *); 103 104/* 105 * retrofits 106 */ 107#ifndef MODE_SENSE 108#define MODE_SENSE 0x1a 109#endif 110#ifndef SMS_FORMAT_DEVICE_PAGE 111#define SMS_FORMAT_DEVICE_PAGE 0x03 112#endif 113#ifndef SMS_GEOMETRY_PAGE 114#define SMS_GEOMETRY_PAGE 0x04 115#endif 116