1149871Sscottl/* 2149871Sscottl * Copyright (c) 2004-2005 HighPoint Technologies, Inc. 3136849Sscottl * All rights reserved. 4136849Sscottl * 5136849Sscottl * Redistribution and use in source and binary forms, with or without 6136849Sscottl * modification, are permitted provided that the following conditions 7136849Sscottl * are met: 8136849Sscottl * 1. Redistributions of source code must retain the above copyright 9136849Sscottl * notice, this list of conditions and the following disclaimer. 10136849Sscottl * 2. Redistributions in binary form must reproduce the above copyright 11136849Sscottl * notice, this list of conditions and the following disclaimer in the 12136849Sscottl * documentation and/or other materials provided with the distribution. 13136849Sscottl * 14136849Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15136849Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16136849Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17136849Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18136849Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19136849Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20136849Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21136849Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22136849Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23136849Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24136849Sscottl * SUCH DAMAGE. 25136849Sscottl * 26136849Sscottl * $FreeBSD$ 27136849Sscottl */ 28136849Sscottl#ifndef _OSBSD_H_ 29136849Sscottl#define _OSBSD_H_ 30136849Sscottl 31136849Sscottl#include <sys/bus.h> 32136849Sscottl#include <sys/resource.h> 33136849Sscottl#include <sys/eventhandler.h> 34149871Sscottl#include <sys/devicestat.h> 35136849Sscottl 36149871Sscottl#if (__FreeBSD_version < 500043) 37149871Sscottl#include <stddef.h> 38149871Sscottl#include <sys/buf.h> 39149871Sscottl#endif 40149871Sscottl 41149871Sscottl#include <vm/vm.h> 42149871Sscottl#include <vm/pmap.h> 43149871Sscottl#include <vm/vm_extern.h> 44149871Sscottl 45190809Sdelphij#if (__FreeBSD_version < 600000) 46149871Sscottl#include <machine/bus_memio.h> 47149871Sscottl#endif 48136849Sscottl#include <machine/bus.h> 49136849Sscottl#include <machine/resource.h> 50136849Sscottl#include <machine/bus.h> 51149871Sscottl 52136849Sscottl#include <sys/rman.h> 53136849Sscottl 54136849Sscottl#include <cam/cam.h> 55136849Sscottl#include <cam/cam_ccb.h> 56136849Sscottl#include <cam/cam_debug.h> 57136849Sscottl#include <cam/cam_sim.h> 58136849Sscottl#include <cam/cam_xpt_sim.h> 59136849Sscottl#include <cam/cam_periph.h> 60149871Sscottl 61136849Sscottl#include <cam/scsi/scsi_all.h> 62136849Sscottl#include <cam/scsi/scsi_message.h> 63136849Sscottl 64149871Sscottl 65149871Sscottl 66136849Sscottlextern intrmask_t lock_driver(void); 67136849Sscottlextern void unlock_driver(intrmask_t spl); 68136849Sscottl 69136849Sscottltypedef struct 70136849Sscottl{ 71149871Sscottl UCHAR status; /* 0 nonbootable; 80h bootable */ 72136849Sscottl UCHAR start_head; 73136849Sscottl USHORT start_sector; 74136849Sscottl UCHAR type; 75136849Sscottl UCHAR end_head; 76136849Sscottl USHORT end_sector; 77136849Sscottl ULONG start_abs_sector; 78136849Sscottl ULONG num_of_sector; 79136849Sscottl} partition; 80136849Sscottl 81136849Sscottltypedef struct _INQUIRYDATA { 82136849Sscottl UCHAR DeviceType : 5; 83136849Sscottl UCHAR DeviceTypeQualifier : 3; 84136849Sscottl UCHAR DeviceTypeModifier : 7; 85136849Sscottl UCHAR RemovableMedia : 1; 86136849Sscottl UCHAR Versions; 87136849Sscottl UCHAR ResponseDataFormat; 88136849Sscottl UCHAR AdditionalLength; 89136849Sscottl UCHAR Reserved[2]; 90136849Sscottl UCHAR SoftReset : 1; 91136849Sscottl UCHAR CommandQueue : 1; 92136849Sscottl UCHAR Reserved2 : 1; 93136849Sscottl UCHAR LinkedCommands : 1; 94136849Sscottl UCHAR Synchronous : 1; 95136849Sscottl UCHAR Wide16Bit : 1; 96136849Sscottl UCHAR Wide32Bit : 1; 97136849Sscottl UCHAR RelativeAddressing : 1; 98136849Sscottl UCHAR VendorId[8]; 99136849Sscottl UCHAR ProductId[16]; 100136849Sscottl UCHAR ProductRevisionLevel[4]; 101136849Sscottl UCHAR VendorSpecific[20]; 102136849Sscottl UCHAR Reserved3[40]; 103136849Sscottl} INQUIRYDATA, *PINQUIRYDATA; 104136849Sscottl 105136849Sscottl#define MV_IAL_HT_SACOALT_DEFAULT 1 106136849Sscottl#define MV_IAL_HT_SAITMTH_DEFAULT 1 107136849Sscottl 108136849Sscottl/****************************************/ 109136849Sscottl/* GENERAL Definitions */ 110136849Sscottl/****************************************/ 111136849Sscottl 112136849Sscottl/* Bits for HD_ERROR */ 113149871Sscottl#define NM_ERR 0x02 /* media present */ 114149871Sscottl#define ABRT_ERR 0x04 /* Command aborted */ 115136849Sscottl#define MCR_ERR 0x08 /* media change request */ 116136849Sscottl#define IDNF_ERR 0x10 /* ID field not found */ 117136849Sscottl#define MC_ERR 0x20 /* media changed */ 118136849Sscottl#define UNC_ERR 0x40 /* Uncorrect data */ 119136849Sscottl#define WP_ERR 0x40 /* write protect */ 120136849Sscottl#define ICRC_ERR 0x80 /* new meaning: CRC error during transfer */ 121136849Sscottl 122149871Sscottl#define REQUESTS_ARRAY_SIZE (9 * MV_EDMA_REQUEST_QUEUE_SIZE) /* 9 K bytes */ 123149871Sscottl#define RESPONSES_ARRAY_SIZE (12 * MV_EDMA_RESPONSE_QUEUE_SIZE) /* 3 K bytes */ 124136849Sscottl 125149871Sscottl#define PRD_ENTRIES_PER_CMD (MAX_SG_DESCRIPTORS+1) 126149871Sscottl#define PRD_ENTRIES_SIZE (MV_EDMA_PRD_ENTRY_SIZE*PRD_ENTRIES_PER_CMD) 127149871Sscottl#define PRD_TABLES_FOR_VBUS (MV_SATA_CHANNELS_NUM*MV_EDMA_QUEUE_LENGTH) 128136849Sscottl 129149871Sscottltypedef enum _SataEvent 130149871Sscottl{ 131149871Sscottl SATA_EVENT_NO_CHANGE = 0, 132136849Sscottl SATA_EVENT_CHANNEL_CONNECTED, 133136849Sscottl SATA_EVENT_CHANNEL_DISCONNECTED 134136849Sscottl} SATA_EVENT; 135136849Sscottl 136136849Sscottltypedef ULONG_PTR dma_addr_t; 137136849Sscottl 138149871Sscottltypedef struct _MV_CHANNEL 139149871Sscottl{ 140136849Sscottl unsigned int maxUltraDmaModeSupported; 141136849Sscottl unsigned int maxDmaModeSupported; 142136849Sscottl unsigned int maxPioModeSupported; 143190809Sdelphij MV_BOOLEAN online; 144190809Sdelphij MV_BOOLEAN writeCacheSupported; 145190809Sdelphij MV_BOOLEAN writeCacheEnabled; 146190809Sdelphij MV_BOOLEAN readAheadSupported; 147190809Sdelphij MV_BOOLEAN readAheadEnabled; 148190809Sdelphij MV_U8 queueDepth; 149190809Sdelphij 150136849Sscottl} MV_CHANNEL; 151136849Sscottl 152149871Sscottltypedef struct _BUS_DMAMAP 153149871Sscottl{ struct _BUS_DMAMAP *next; 154149871Sscottl struct IALAdapter *pAdapter; 155149871Sscottl bus_dmamap_t dma_map; 156149871Sscottl SCAT_GATH psg[MAX_SG_DESCRIPTORS]; 157149871Sscottl} BUS_DMAMAP, *PBUS_DMAMAP; 158136849Sscottl 159149871Sscottltypedef struct IALAdapter 160149871Sscottl{ 161136849Sscottl struct cam_path *path; 162149871Sscottl 163149871Sscottl bus_dma_tag_t io_dma_parent; /* I/O buffer DMA tag */ 164149871Sscottl PBUS_DMAMAP pbus_dmamap_list; 165149871Sscottl PBUS_DMAMAP pbus_dmamap; 166149871Sscottl 167149871Sscottl device_t hpt_dev; /* bus device */ 168149871Sscottl struct resource *hpt_irq; /* interrupt */ 169136849Sscottl struct resource *mem_res; 170149871Sscottl void *hpt_intr; /* interrupt handle */ 171149871Sscottl struct IALAdapter *next; 172136849Sscottl 173149871Sscottl MV_SATA_ADAPTER mvSataAdapter; 174149871Sscottl MV_CHANNEL mvChannel[MV_SATA_CHANNELS_NUM]; 175149871Sscottl MV_U8 *requestsArrayBaseAddr; 176149871Sscottl MV_U8 *requestsArrayBaseAlignedAddr; 177149871Sscottl dma_addr_t requestsArrayBaseDmaAddr; 178149871Sscottl dma_addr_t requestsArrayBaseDmaAlignedAddr; 179149871Sscottl MV_U8 *responsesArrayBaseAddr; 180149871Sscottl MV_U8 *responsesArrayBaseAlignedAddr; 181149871Sscottl dma_addr_t responsesArrayBaseDmaAddr; 182149871Sscottl dma_addr_t responsesArrayBaseDmaAlignedAddr; 183149871Sscottl SATA_EVENT sataEvents[MV_SATA_CHANNELS_NUM]; 184136849Sscottl 185136849Sscottl struct callout_handle event_timer_connect; 186136849Sscottl struct callout_handle event_timer_disconnect; 187136849Sscottl 188149871Sscottl struct _VBus VBus; 189149871Sscottl struct _VDevice VDevices[MV_SATA_CHANNELS_NUM]; 190149871Sscottl PCommand pCommandBlocks; 191149871Sscottl PUCHAR prdTableAddr; 192149871Sscottl PUCHAR prdTableAlignedAddr; 193149871Sscottl void* pFreePRDLink; 194136849Sscottl 195149871Sscottl union ccb *pending_Q; 196136849Sscottl 197149871Sscottl MV_U8 outstandingCommands; 198136849Sscottl 199149871Sscottl UCHAR status; 200149871Sscottl UCHAR ver_601; 201149871Sscottl UCHAR beeping; 202136849Sscottl 203136849Sscottl eventhandler_tag eh; 204149871Sscottl} 205149871SscottlIAL_ADAPTER_T; 206136849Sscottl 207136849Sscottlextern IAL_ADAPTER_T *gIal_Adapter; 208136849Sscottl 209136849Sscottl/*entry.c*/ 210136849Sscottltypedef void (*HPT_DPC)(IAL_ADAPTER_T *,void*,UCHAR); 211149871Sscottl 212136849Sscottlint hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags); 213149871Sscottlvoid hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags); 214136849Sscottlvoid Check_Idle_Call(IAL_ADAPTER_T *pAdapter); 215136849Sscottlvoid fRescanAllDevice(_VBUS_ARG0); 216136849Sscottlint hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk); 217136849Sscottl 218149871Sscottlint Kernel_DeviceIoControl(_VBUS_ARG 219149871Sscottl DWORD dwIoControlCode, /* operation control code */ 220149871Sscottl PVOID lpInBuffer, /* input data buffer */ 221149871Sscottl DWORD nInBufferSize, /* size of input data buffer */ 222149871Sscottl PVOID lpOutBuffer, /* output data buffer */ 223149871Sscottl DWORD nOutBufferSize, /* size of output data buffer */ 224149871Sscottl PDWORD lpBytesReturned /* byte count */ 225149871Sscottl ); 226136849Sscottl 227149871Sscottl 228136849Sscottl#define __str_direct(x) #x 229136849Sscottl#define __str(x) __str_direct(x) 230136849Sscottl#define KMSG_LEADING __str(PROC_DIR_NAME) ": " 231149871Sscottl#define hpt_printk(_x_) do { printf(KMSG_LEADING); printf _x_ ; } while (0) 232136849Sscottl 233136849Sscottl#define DUPLICATE 0 234136849Sscottl#define INITIALIZE 1 235136849Sscottl#define REBUILD_PARITY 2 236136849Sscottl#define VERIFY 3 237136849Sscottl 238149871Sscottl/***********************************************************/ 239149871Sscottl 240136849Sscottlstatic __inline struct cam_periph * 241136849Sscottlhpt_get_periph(int path_id,int target_id) 242136849Sscottl{ 243149871Sscottl struct cam_periph *periph = NULL; 244149871Sscottl struct cam_path *path; 245149871Sscottl int status; 246136849Sscottl 247149871Sscottl status = xpt_create_path(&path, NULL, path_id, target_id, 0); 248149871Sscottl if (status == CAM_REQ_CMP) { 249149871Sscottl periph = cam_periph_find(path, "da"); 250136849Sscottl xpt_free_path(path); 251149871Sscottl 252149871Sscottl } 253136849Sscottl return periph; 254136849Sscottl} 255136849Sscottl 256149871Sscottl#if (__FreeBSD_version < 500000) 257149871Sscottl#define YIELD_THREAD yield(curproc, 0) 258149871Sscottl#endif 259136849Sscottl 260149871Sscottl#ifdef __i386__ 261149871Sscottl#define BITS_PER_LONG 32 262149871Sscottl#define VDEV_TO_ID(pVDev) (DEVICEID)(pVDev) 263149871Sscottl#define ID_TO_VDEV(id) (PVDevice)(id) 264149871Sscottl#else /*Only support x86_64(AMD64 and EM64T)*/ 265149871Sscottl#define BITS_PER_LONG 64 266149871Sscottl#define VDEV_TO_ID(pVDev) (DEVICEID)(ULONG_PTR)(pVDev) 267149871Sscottl#define ID_TO_VDEV(id) (PVDevice)(((ULONG_PTR)gIal_Adapter & 0xffffffff00000000) | (id)) 268149871Sscottl#endif 269136849Sscottl 270149871Sscottl#define INVALID_DEVICEID (-1) 271149871Sscottl#define INVALID_STRIPSIZE (-1) 272136849Sscottl 273149871Sscottl#define shortswap(w) ((WORD)((w)>>8 | ((w) & 0xFF)<<8)) 274136849Sscottl 275149871Sscottl#ifndef MinBlockSizeShift 276149871Sscottl#define MinBlockSizeShift 5 277149871Sscottl#define MaxBlockSizeShift 12 278149871Sscottl#endif 279136849Sscottl 280149871Sscottl#pragma pack(1) 281149871Sscottltypedef struct _HPT_IOCTL_TRANSFER_PARAM 282136849Sscottl{ 283149871Sscottl ULONG nInBufferSize; 284149871Sscottl ULONG nOutBufferSize; 285149871Sscottl UCHAR buffer[0]; 286149871Sscottl}HPT_IOCTL_TRANSFER_PARAM, *PHPT_IOCTL_TRANSFER_PARAM; 287136849Sscottl 288149871Sscottltypedef struct _HPT_SET_STATE_PARAM 289136849Sscottl{ 290149871Sscottl DEVICEID idArray; 291149871Sscottl DWORD state; 292149871Sscottl} HPT_SET_STATE_PARAM, *PHPT_SET_STATE_PARAM; 293136849Sscottl 294149871Sscottltypedef struct _HPT_SET_ARRAY_INFO 295136849Sscottl{ 296149871Sscottl DEVICEID idArray; 297149871Sscottl ALTERABLE_ARRAY_INFO Info; 298149871Sscottl} HPT_SET_ARRAY_INFO, *PHPT_SET_ARRAY_INFO; 299136849Sscottl 300149871Sscottltypedef struct _HPT_SET_DEVICE_INFO 301136849Sscottl{ 302149871Sscottl DEVICEID idDisk; 303149871Sscottl ALTERABLE_DEVICE_INFO Info; 304149871Sscottl} HPT_SET_DEVICE_INFO, *PHPT_SET_DEVICE_INFO; 305136849Sscottl 306190809Sdelphijtypedef struct _HPT_SET_DEVICE_INFO_V2 307190809Sdelphij{ 308190809Sdelphij DEVICEID idDisk; 309190809Sdelphij ALTERABLE_DEVICE_INFO_V2 Info; 310190809Sdelphij} HPT_SET_DEVICE_INFO_V2, *PHPT_SET_DEVICE_INFO_V2; 311190809Sdelphij 312149871Sscottltypedef struct _HPT_ADD_DISK_TO_ARRAY 313136849Sscottl{ 314149871Sscottl DEVICEID idArray; 315149871Sscottl DEVICEID idDisk; 316149871Sscottl} HPT_ADD_DISK_TO_ARRAY, *PHPT_ADD_DISK_TO_ARRAY; 317136849Sscottl 318190809Sdelphijtypedef struct _HPT_DEVICE_IO 319190809Sdelphij{ 320190809Sdelphij DEVICEID id; 321190809Sdelphij int cmd; 322190809Sdelphij ULONG lba; 323190809Sdelphij DWORD nSector; 324190809Sdelphij UCHAR buffer[0]; 325190809Sdelphij} HPT_DEVICE_IO, *PHPT_DEVICE_IO; 326190809Sdelphij 327149871Sscottlint check_VDevice_valid(PVDevice); 328149871Sscottlint hpt_default_ioctl(_VBUS_ARG DWORD, PVOID, DWORD, PVOID, DWORD, PDWORD); 329149871Sscottl 330149871Sscottl#define HPT_NULL_ID 0 331149871Sscottl 332149871Sscottl#pragma pack() 333149871Sscottl 334136849Sscottl#endif 335