1228940Sdelphij/*- 2284730Sdelphij * Copyright (c) 2005-2011 HighPoint Technologies, Inc. 3228940Sdelphij * All rights reserved. 4228940Sdelphij * 5228940Sdelphij * Redistribution and use in source and binary forms, with or without 6228940Sdelphij * modification, are permitted provided that the following conditions 7228940Sdelphij * are met: 8228940Sdelphij * 1. Redistributions of source code must retain the above copyright 9228940Sdelphij * notice, this list of conditions and the following disclaimer. 10228940Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 11228940Sdelphij * notice, this list of conditions and the following disclaimer in the 12228940Sdelphij * documentation and/or other materials provided with the distribution. 13228940Sdelphij * 14228940Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15228940Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16228940Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17228940Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18228940Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19228940Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20228940Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21228940Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22228940Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23228940Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24228940Sdelphij * SUCH DAMAGE. 25228940Sdelphij * 26228940Sdelphij * $FreeBSD: releng/11.0/sys/dev/hpt27xx/os_bsd.h 284730 2015-06-23 17:26:16Z delphij $ 27228940Sdelphij */ 28228940Sdelphij 29228940Sdelphij#include <dev/hpt27xx/hpt27xx_config.h> 30228940Sdelphij 31228940Sdelphij#ifndef _OS_BSD_H 32228940Sdelphij#define _OS_BSD_H 33228940Sdelphij 34228940Sdelphij#ifndef DBG 35228940Sdelphij#define DBG 0 36228940Sdelphij#endif 37228940Sdelphij 38228940Sdelphij#include <sys/param.h> 39228940Sdelphij#include <sys/types.h> 40228940Sdelphij#include <sys/cons.h> 41228940Sdelphij#include <sys/time.h> 42228940Sdelphij#include <sys/systm.h> 43228940Sdelphij 44228940Sdelphij#include <sys/stat.h> 45228940Sdelphij#include <sys/malloc.h> 46228940Sdelphij#include <sys/conf.h> 47228940Sdelphij#include <sys/libkern.h> 48228940Sdelphij#include <sys/kernel.h> 49228940Sdelphij 50228940Sdelphij#include <sys/kthread.h> 51228940Sdelphij#include <sys/mutex.h> 52228940Sdelphij#include <sys/module.h> 53228940Sdelphij 54228940Sdelphij#include <sys/eventhandler.h> 55228940Sdelphij#include <sys/bus.h> 56228940Sdelphij#include <sys/taskqueue.h> 57228940Sdelphij#include <sys/ioccom.h> 58228940Sdelphij 59228940Sdelphij#include <machine/resource.h> 60228940Sdelphij#include <machine/pci_cfgreg.h> 61228940Sdelphij#include <machine/bus.h> 62228940Sdelphij#include <machine/stdarg.h> 63228940Sdelphij#include <sys/rman.h> 64228940Sdelphij 65228940Sdelphij#include <vm/vm.h> 66228940Sdelphij#include <vm/pmap.h> 67228940Sdelphij 68228940Sdelphij#include <dev/pci/pcireg.h> 69228940Sdelphij#include <dev/pci/pcivar.h> 70228940Sdelphij 71228940Sdelphij#include <cam/cam.h> 72228940Sdelphij#include <cam/cam_ccb.h> 73228940Sdelphij#include <cam/cam_sim.h> 74228940Sdelphij#include <cam/cam_xpt_sim.h> 75228940Sdelphij#include <cam/cam_debug.h> 76228940Sdelphij#include <cam/cam_xpt_periph.h> 77228940Sdelphij#include <cam/cam_periph.h> 78228940Sdelphij#include <cam/scsi/scsi_all.h> 79228940Sdelphij#include <cam/scsi/scsi_message.h> 80228940Sdelphij 81228940Sdelphij 82228940Sdelphijtypedef struct _INQUIRYDATA { 83228940Sdelphij u_char DeviceType : 5; 84228940Sdelphij u_char DeviceTypeQualifier : 3; 85228940Sdelphij u_char DeviceTypeModifier : 7; 86228940Sdelphij u_char RemovableMedia : 1; 87228940Sdelphij u_char Versions; 88228940Sdelphij u_char ResponseDataFormat; 89228940Sdelphij u_char AdditionalLength; 90228940Sdelphij u_char Reserved[2]; 91228940Sdelphij u_char SoftReset : 1; 92228940Sdelphij u_char CommandQueue : 1; 93228940Sdelphij u_char Reserved2 : 1; 94228940Sdelphij u_char LinkedCommands : 1; 95228940Sdelphij u_char Synchronous : 1; 96228940Sdelphij u_char Wide16Bit : 1; 97228940Sdelphij u_char Wide32Bit : 1; 98228940Sdelphij u_char RelativeAddressing : 1; 99228940Sdelphij u_char VendorId[8]; 100228940Sdelphij u_char ProductId[16]; 101228940Sdelphij u_char ProductRevisionLevel[4]; 102228940Sdelphij u_char VendorSpecific[20]; 103228940Sdelphij u_char Reserved3[40]; 104228940Sdelphij} 105228940Sdelphij__attribute__((packed)) 106228940SdelphijINQUIRYDATA, *PINQUIRYDATA; 107228940Sdelphij 108228940Sdelphij#endif 109228940Sdelphij 110228940Sdelphij/* private headers */ 111228940Sdelphij 112228940Sdelphij#include <dev/hpt27xx/osm.h> 113228940Sdelphij#include <dev/hpt27xx/him.h> 114228940Sdelphij#include <dev/hpt27xx/ldm.h> 115228940Sdelphij 116228940Sdelphij/* driver parameters */ 117245768Sdelphijextern const char driver_name[]; 118245768Sdelphijextern const char driver_name_long[]; 119245768Sdelphijextern const char driver_ver[]; 120228940Sdelphijextern int osm_max_targets; 121228940Sdelphij 122228940Sdelphij/* 123228940Sdelphij * adapter/vbus extensions: 124228940Sdelphij * each physical controller has an adapter_ext, passed to him.create_adapter() 125228940Sdelphij * each vbus has a vbus_ext passed to ldm_create_vbus(). 126228940Sdelphij */ 127228940Sdelphij#define EXT_TYPE_HBA 1 128228940Sdelphij#define EXT_TYPE_VBUS 2 129228940Sdelphij 130228940Sdelphijtypedef struct _hba { 131228940Sdelphij int ext_type; 132228940Sdelphij LDM_ADAPTER ldm_adapter; 133228940Sdelphij device_t pcidev; 134228940Sdelphij PCI_ADDRESS pciaddr; 135228940Sdelphij struct _vbus_ext *vbus_ext; 136228940Sdelphij struct _hba *next; 137228940Sdelphij 138228940Sdelphij struct { 139228940Sdelphij struct resource *res; 140228940Sdelphij int type; 141228940Sdelphij int rid; 142228940Sdelphij void *base; 143228940Sdelphij } 144228940Sdelphij pcibar[6]; 145228940Sdelphij 146228940Sdelphij struct resource *irq_res; 147228940Sdelphij void *irq_handle; 148228940Sdelphij} 149228940SdelphijHBA, *PHBA; 150228940Sdelphij 151228940Sdelphijtypedef struct _os_cmdext { 152228940Sdelphij struct _vbus_ext *vbus_ext; 153228940Sdelphij struct _os_cmdext *next; 154228940Sdelphij union ccb *ccb; 155228940Sdelphij bus_dmamap_t dma_map; 156284730Sdelphij#if (__FreeBSD_version >= 1000510) 157267290Sjhb struct callout timeout; 158284730Sdelphij#endif 159228940Sdelphij SG psg[os_max_sg_descriptors]; 160228940Sdelphij} 161228940SdelphijOS_CMDEXT, *POS_CMDEXT; 162228940Sdelphij 163228940Sdelphijtypedef struct _vbus_ext { 164228940Sdelphij int ext_type; 165228940Sdelphij struct _vbus_ext *next; 166228940Sdelphij PHBA hba_list; 167228940Sdelphij struct freelist *freelist_head; 168228940Sdelphij struct freelist *freelist_dma_head; 169228940Sdelphij 170228940Sdelphij struct cam_sim *sim; /* sim for this vbus */ 171228940Sdelphij struct cam_path *path; /* peripheral, path, tgt, lun with this vbus */ 172228940Sdelphij struct mtx lock; /* general purpose lock */ 173228940Sdelphij bus_dma_tag_t io_dmat; /* I/O buffer DMA tag */ 174228940Sdelphij 175228940Sdelphij POS_CMDEXT cmdext_list; 176228940Sdelphij 177228940Sdelphij OSM_TASK *tasks; 178228940Sdelphij struct task worker; 179284730Sdelphij#if (__FreeBSD_version >= 1000510) 180267290Sjhb struct callout timer; 181284730Sdelphij#else 182284730Sdelphij struct callout_handle timer; 183284730Sdelphij#endif 184228940Sdelphij eventhandler_tag shutdown_eh; 185228940Sdelphij 186228940Sdelphij /* the LDM vbus instance continues */ 187228940Sdelphij unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long)))); 188228940Sdelphij} 189228940SdelphijVBUS_EXT, *PVBUS_EXT; 190228940Sdelphij 191228940Sdelphij#define hpt_lock_vbus(vbus_ext) mtx_lock(&(vbus_ext)->lock) 192228940Sdelphij#define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock) 193267290Sjhb#define hpt_assert_vbus_locked(vbus_ext) mtx_assert(&(vbus_ext)->lock, MA_OWNED) 194228940Sdelphij 195228940Sdelphij 196228940Sdelphij#define HPT_OSM_TIMEOUT (20*hz) /* timeout value for OS commands */ 197228940Sdelphij 198228940Sdelphij#define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM) 199228940Sdelphij 200228940Sdelphij#define HPT_SCAN_BUS _IO('H', 1) 201228940Sdelphij 202284730Sdelphij#if __FreeBSD_version < 1000510 203284730Sdelphij#define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi_giant,(task)); 204284730Sdelphij#else 205228940Sdelphij#define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi,(task)); 206284730Sdelphij#endif 207228940Sdelphij 208228940Sdelphijstatic __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo) 209228940Sdelphij{ 210228940Sdelphij return msleep(ident, &vbus_ext->lock, priority, wmesg, timo); 211228940Sdelphij} 212284730Sdelphij 213