os_bsd.h revision 174604
1/* 2 * Copyright (c) HighPoint Technologies, 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, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 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 18 * FOR 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/sys/dev/hptrr/os_bsd.h 174604 2007-12-15 00:56:17Z scottl $ 27 */ 28#include <dev/hptrr/hptrr_config.h> 29/* $Id: os_bsd.h,v 1.18 2006/04/11 08:19:02 gmm Exp $ 30 * 31 * HighPoint RAID Driver for FreeBSD 32 * Copyright (C) 2005 HighPoint Technologies, Inc. All Rights Reserved. 33 */ 34 35#ifndef _OS_BSD_H 36#define _OS_BSD_H 37 38#include <sys/param.h> 39#include <sys/types.h> 40#include <sys/cons.h> 41#if (__FreeBSD_version >= 500000) 42#include <sys/time.h> 43#include <sys/systm.h> 44#else 45#include <machine/clock.h> /*to support DELAY function under 4.x BSD versions*/ 46#endif 47 48#include <sys/stat.h> 49#include <sys/malloc.h> 50#include <sys/conf.h> 51#include <sys/libkern.h> 52#include <sys/kernel.h> 53 54#if (__FreeBSD_version >= 500000) 55#include <sys/kthread.h> 56#include <sys/mutex.h> 57#include <sys/module.h> 58#endif 59 60#include <sys/eventhandler.h> 61#include <sys/bus.h> 62#include <sys/taskqueue.h> 63#include <sys/ioccom.h> 64 65#include <machine/resource.h> 66#include <machine/bus.h> 67#include <machine/stdarg.h> 68#include <sys/rman.h> 69 70#include <vm/vm.h> 71#include <vm/pmap.h> 72 73#if (__FreeBSD_version >= 500000) 74#include <dev/pci/pcireg.h> 75#include <dev/pci/pcivar.h> 76#else 77#include <pci/pcivar.h> 78#include <pci/pcireg.h> 79#endif 80 81#if (__FreeBSD_version <= 500043) 82#include <sys/devicestat.h> 83#endif 84 85#include <cam/cam.h> 86#include <cam/cam_ccb.h> 87#include <cam/cam_sim.h> 88#include <cam/cam_xpt_sim.h> 89#include <cam/cam_debug.h> 90#include <cam/cam_xpt_periph.h> 91#include <cam/cam_periph.h> 92#include <cam/scsi/scsi_all.h> 93#include <cam/scsi/scsi_message.h> 94 95#if (__FreeBSD_version < 500043) 96#include <sys/bus_private.h> 97#endif 98 99 100typedef struct _INQUIRYDATA { 101 u_char DeviceType : 5; 102 u_char DeviceTypeQualifier : 3; 103 u_char DeviceTypeModifier : 7; 104 u_char RemovableMedia : 1; 105 u_char Versions; 106 u_char ResponseDataFormat; 107 u_char AdditionalLength; 108 u_char Reserved[2]; 109 u_char SoftReset : 1; 110 u_char CommandQueue : 1; 111 u_char Reserved2 : 1; 112 u_char LinkedCommands : 1; 113 u_char Synchronous : 1; 114 u_char Wide16Bit : 1; 115 u_char Wide32Bit : 1; 116 u_char RelativeAddressing : 1; 117 u_char VendorId[8]; 118 u_char ProductId[16]; 119 u_char ProductRevisionLevel[4]; 120 u_char VendorSpecific[20]; 121 u_char Reserved3[40]; 122} 123__attribute__((packed)) 124INQUIRYDATA, *PINQUIRYDATA; 125 126#endif 127 128/* private headers */ 129 130#include <dev/hptrr/osm.h> 131#include <dev/hptrr/him.h> 132#include <dev/hptrr/ldm.h> 133 134/* driver parameters */ 135extern char driver_name[]; 136extern char driver_name_long[]; 137extern char driver_ver[]; 138extern int osm_max_targets; 139 140/* 141 * adapter/vbus extensions: 142 * each physical controller has an adapter_ext, passed to him.create_adapter() 143 * each vbus has a vbus_ext passed to ldm_create_vbus(). 144 */ 145#define EXT_TYPE_HBA 1 146#define EXT_TYPE_VBUS 2 147 148typedef struct _hba { 149 int ext_type; 150 LDM_ADAPTER ldm_adapter; 151 device_t pcidev; 152 PCI_ADDRESS pciaddr; 153 struct _vbus_ext *vbus_ext; 154 struct _hba *next; 155 156 struct { 157 struct resource *res; 158 int type; 159 int rid; 160 void *base; 161 } 162 pcibar[6]; 163 164 struct resource *irq_res; 165 void *irq_handle; 166} 167HBA, *PHBA; 168 169typedef struct _os_cmdext { 170 struct _vbus_ext *vbus_ext; 171 struct _os_cmdext *next; 172 union ccb *ccb; 173 bus_dmamap_t dma_map; 174 SG psg[os_max_sg_descriptors]; 175} 176OS_CMDEXT, *POS_CMDEXT; 177 178typedef struct _vbus_ext { 179 int ext_type; 180 struct _vbus_ext *next; 181 PHBA hba_list; 182 struct freelist *freelist_head; 183 struct freelist *freelist_dma_head; 184 185 struct cam_sim *sim; /* sim for this vbus */ 186 struct cam_path *path; /* peripheral, path, tgt, lun with this vbus */ 187#if (__FreeBSD_version >= 500000) 188 struct mtx lock; /* general purpose lock */ 189#else 190 int hpt_splx; 191#endif 192 bus_dma_tag_t io_dmat; /* I/O buffer DMA tag */ 193 194 POS_CMDEXT cmdext_list; 195 196 OSM_TASK *tasks; 197 struct task worker; 198 199 struct callout_handle timer; 200 201 eventhandler_tag shutdown_eh; 202 203 /* the LDM vbus instance continues */ 204 unsigned long vbus[0] __attribute__((aligned(sizeof(unsigned long)))); 205} 206VBUS_EXT, *PVBUS_EXT; 207 208#if __FreeBSD_version >= 500000 209#define hpt_lock_vbus(vbus_ext) mtx_lock(&(vbus_ext)->lock) 210#define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock) 211#else 212static __inline void hpt_lock_vbus(PVBUS_EXT vbus_ext) 213{ 214 vbus_ext->hpt_splx = splcam(); 215} 216static __inline void hpt_unlock_vbus(PVBUS_EXT vbus_ext) 217{ 218 splx(vbus_ext->hpt_splx); 219} 220#endif 221 222 223#define HPT_OSM_TIMEOUT (20*hz) /* timeout value for OS commands */ 224 225#define HPT_DO_IOCONTROL _IOW('H', 0, HPT_IOCTL_PARAM) 226 227#define HPT_SCAN_BUS _IO('H', 1) 228 229#if __FreeBSD_version >= 501000 230#define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi_giant,(task)); 231#else 232#define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi,(task)); 233#endif 234 235#if __FreeBSD_version >= 500000 236static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo) 237{ 238 return msleep(ident, &vbus_ext->lock, priority, wmesg, timo); 239} 240#else 241static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo) 242{ 243 int retval = 0; 244 245 asleep(ident, priority, wmesg, timo); 246 hpt_unlock_vbus(vbus_ext); 247 retval = await(priority, timo); 248 hpt_lock_vbus(vbus_ext); 249 250 return retval; 251} 252#endif 253 254#if __FreeBSD_version < 501000 255#define READ_16 0x88 256#define WRITE_16 0x8a 257#define SERVICE_ACTION_IN 0x9e 258#endif 259 260#define HPT_DEV_MAJOR 200 261