1252867Sdelphij/* $Id: os_bsd.h,v 1.20 2010/05/11 03:12:11 lcn Exp $ */ 2252867Sdelphij/*- 3252867Sdelphij * HighPoint RAID Driver for FreeBSD 4252867Sdelphij * Copyright (C) 2005-2011 HighPoint Technologies, Inc. All Rights Reserved. 5252867Sdelphij * All rights reserved. 6252867Sdelphij * 7252867Sdelphij * Redistribution and use in source and binary forms, with or without 8252867Sdelphij * modification, are permitted provided that the following conditions 9252867Sdelphij * are met: 10252867Sdelphij * 1. Redistributions of source code must retain the above copyright 11252867Sdelphij * notice, this list of conditions and the following disclaimer. 12252867Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 13252867Sdelphij * notice, this list of conditions and the following disclaimer in the 14252867Sdelphij * documentation and/or other materials provided with the distribution. 15252867Sdelphij * 16252867Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17252867Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18252867Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19252867Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20252867Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21252867Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22252867Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23252867Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24252867Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25252867Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26252867Sdelphij * SUCH DAMAGE. 27252867Sdelphij * 28252867Sdelphij * $FreeBSD: releng/11.0/sys/dev/hptnr/os_bsd.h 281387 2015-04-11 00:45:03Z delphij $ 29252867Sdelphij */ 30252867Sdelphij 31252867Sdelphij#include <dev/hptnr/hptnr_config.h> 32252867Sdelphij 33252867Sdelphij#ifndef _OS_BSD_H 34252867Sdelphij#define _OS_BSD_H 35252867Sdelphij 36252867Sdelphij#ifndef DBG 37252867Sdelphij#define DBG 0 38252867Sdelphij#endif 39252867Sdelphij 40252867Sdelphij#include <sys/param.h> 41252867Sdelphij#include <sys/types.h> 42252867Sdelphij#include <sys/cons.h> 43252867Sdelphij#include <sys/time.h> 44252867Sdelphij#include <sys/systm.h> 45252867Sdelphij 46252867Sdelphij#include <sys/stat.h> 47252867Sdelphij#include <sys/malloc.h> 48252867Sdelphij#include <sys/conf.h> 49252867Sdelphij#include <sys/libkern.h> 50252867Sdelphij#include <sys/kernel.h> 51252867Sdelphij 52252867Sdelphij#include <sys/kthread.h> 53252867Sdelphij#include <sys/mutex.h> 54252867Sdelphij#include <sys/module.h> 55252867Sdelphij 56252867Sdelphij#include <sys/eventhandler.h> 57252867Sdelphij#include <sys/bus.h> 58252867Sdelphij#include <sys/taskqueue.h> 59252867Sdelphij#include <sys/ioccom.h> 60252867Sdelphij 61252867Sdelphij#include <machine/resource.h> 62252867Sdelphij#include <machine/pci_cfgreg.h> 63252867Sdelphij#include <machine/bus.h> 64252867Sdelphij#include <machine/stdarg.h> 65252867Sdelphij#include <sys/rman.h> 66252867Sdelphij 67252867Sdelphij#include <vm/vm.h> 68252867Sdelphij#include <vm/pmap.h> 69252867Sdelphij 70252867Sdelphij#include <dev/pci/pcireg.h> 71252867Sdelphij#include <dev/pci/pcivar.h> 72252867Sdelphij 73252867Sdelphij#include <cam/cam.h> 74252867Sdelphij#include <cam/cam_ccb.h> 75252867Sdelphij#include <cam/cam_sim.h> 76252867Sdelphij#include <cam/cam_xpt_sim.h> 77252867Sdelphij#include <cam/cam_debug.h> 78252867Sdelphij#include <cam/cam_xpt_periph.h> 79252867Sdelphij#include <cam/cam_periph.h> 80252867Sdelphij#include <cam/scsi/scsi_all.h> 81252867Sdelphij#include <cam/scsi/scsi_message.h> 82252867Sdelphij 83252867Sdelphij 84252867Sdelphijtypedef struct _INQUIRYDATA { 85252867Sdelphij u_char DeviceType : 5; 86252867Sdelphij u_char DeviceTypeQualifier : 3; 87252867Sdelphij u_char DeviceTypeModifier : 7; 88252867Sdelphij u_char RemovableMedia : 1; 89252867Sdelphij u_char Versions; 90252867Sdelphij u_char ResponseDataFormat; 91252867Sdelphij u_char AdditionalLength; 92252867Sdelphij u_char Reserved[2]; 93252867Sdelphij u_char SoftReset : 1; 94252867Sdelphij u_char CommandQueue : 1; 95252867Sdelphij u_char Reserved2 : 1; 96252867Sdelphij u_char LinkedCommands : 1; 97252867Sdelphij u_char Synchronous : 1; 98252867Sdelphij u_char Wide16Bit : 1; 99252867Sdelphij u_char Wide32Bit : 1; 100252867Sdelphij u_char RelativeAddressing : 1; 101252867Sdelphij u_char VendorId[8]; 102252867Sdelphij u_char ProductId[16]; 103252867Sdelphij u_char ProductRevisionLevel[4]; 104252867Sdelphij u_char VendorSpecific[20]; 105252867Sdelphij u_char Reserved3[40]; 106252867Sdelphij} 107252867Sdelphij__attribute__((packed)) 108252867SdelphijINQUIRYDATA, *PINQUIRYDATA; 109252867Sdelphij 110252867Sdelphij#endif 111252867Sdelphij 112252867Sdelphij/* private headers */ 113252867Sdelphij 114252867Sdelphij#include <dev/hptnr/osm.h> 115252867Sdelphij#include <dev/hptnr/him.h> 116252867Sdelphij#include <dev/hptnr/ldm.h> 117252867Sdelphij 118252867Sdelphij/* driver parameters */ 119252867Sdelphijextern const char driver_name[]; 120252867Sdelphijextern const char driver_name_long[]; 121252867Sdelphijextern const char driver_ver[]; 122252867Sdelphijextern int osm_max_targets; 123252867Sdelphij 124252867Sdelphij/* 125252867Sdelphij * adapter/vbus extensions: 126252867Sdelphij * each physical controller has an adapter_ext, passed to him.create_adapter() 127252867Sdelphij * each vbus has a vbus_ext passed to ldm_create_vbus(). 128252867Sdelphij */ 129252867Sdelphij#define EXT_TYPE_HBA 1 130252867Sdelphij#define EXT_TYPE_VBUS 2 131252867Sdelphij 132252867Sdelphijtypedef struct _hba { 133252867Sdelphij int ext_type; 134252867Sdelphij LDM_ADAPTER ldm_adapter; 135252867Sdelphij device_t pcidev; 136252867Sdelphij PCI_ADDRESS pciaddr; 137252867Sdelphij struct _vbus_ext *vbus_ext; 138252867Sdelphij struct _hba *next; 139252867Sdelphij 140252867Sdelphij struct { 141252867Sdelphij struct resource *res; 142252867Sdelphij int type; 143252867Sdelphij int rid; 144252867Sdelphij void *base; 145252867Sdelphij } 146252867Sdelphij pcibar[6]; 147252867Sdelphij 148252867Sdelphij struct resource *irq_res; 149252867Sdelphij void *irq_handle; 150252867Sdelphij} 151252867SdelphijHBA, *PHBA; 152252867Sdelphij 153252867Sdelphijtypedef struct _os_cmdext { 154252867Sdelphij struct _vbus_ext *vbus_ext; 155252867Sdelphij struct _os_cmdext *next; 156252867Sdelphij union ccb *ccb; 157252867Sdelphij bus_dmamap_t dma_map; 158269613Sjhb struct callout timeout; 159252867Sdelphij SG psg[os_max_sg_descriptors]; 160252867Sdelphij} 161252867SdelphijOS_CMDEXT, *POS_CMDEXT; 162252867Sdelphij 163252867Sdelphijtypedef struct _vbus_ext { 164252867Sdelphij int ext_type; 165252867Sdelphij struct _vbus_ext *next; 166252867Sdelphij PHBA hba_list; 167252867Sdelphij struct freelist *freelist_head; 168252867Sdelphij struct freelist *freelist_dma_head; 169252867Sdelphij 170252867Sdelphij struct cam_sim *sim; /* sim for this vbus */ 171252867Sdelphij struct cam_path *path; /* peripheral, path, tgt, lun with this vbus */ 172252867Sdelphij struct mtx lock; /* general purpose lock */ 173252867Sdelphij bus_dma_tag_t io_dmat; /* I/O buffer DMA tag */ 174252867Sdelphij 175252867Sdelphij POS_CMDEXT cmdext_list; 176252867Sdelphij 177252867Sdelphij OSM_TASK *tasks; 178252867Sdelphij struct task worker; 179252867Sdelphij 180269613Sjhb struct callout timer; 181252867Sdelphij 182252867Sdelphij eventhandler_tag shutdown_eh; 183252867Sdelphij 184252867Sdelphij /* the LDM vbus instance continues */ 185252867Sdelphij unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long)))); 186252867Sdelphij} 187252867SdelphijVBUS_EXT, *PVBUS_EXT; 188252867Sdelphij 189252867Sdelphij#define hpt_lock_vbus(vbus_ext) mtx_lock(&(vbus_ext)->lock) 190252867Sdelphij#define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock) 191269613Sjhb#define hpt_assert_vbus_locked(vbus_ext) mtx_assert(&(vbus_ext)->lock, MA_OWNED) 192252867Sdelphij 193252867Sdelphij 194281387Sdelphij#define HPT_OSM_TIMEOUT (120*hz) /* timeout value for OS commands */ 195252867Sdelphij 196252867Sdelphij#define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM) 197252867Sdelphij 198252867Sdelphij#define HPT_SCAN_BUS _IO('H', 1) 199252867Sdelphij 200252867Sdelphij#define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi,(task)); 201252867Sdelphij 202252867Sdelphijstatic __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo) 203252867Sdelphij{ 204252867Sdelphij return msleep(ident, &vbus_ext->lock, priority, wmesg, timo); 205252867Sdelphij} 206