1d2bd3ab9SScott Long /* 2d2bd3ab9SScott Long * Copyright (c) 2004-2005 HighPoint Technologies, Inc. 31713e81bSScott Long * All rights reserved. 41713e81bSScott Long * 51713e81bSScott Long * Redistribution and use in source and binary forms, with or without 61713e81bSScott Long * modification, are permitted provided that the following conditions 71713e81bSScott Long * are met: 81713e81bSScott Long * 1. Redistributions of source code must retain the above copyright 91713e81bSScott Long * notice, this list of conditions and the following disclaimer. 101713e81bSScott Long * 2. Redistributions in binary form must reproduce the above copyright 111713e81bSScott Long * notice, this list of conditions and the following disclaimer in the 121713e81bSScott Long * documentation and/or other materials provided with the distribution. 131713e81bSScott Long * 141713e81bSScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 151713e81bSScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 161713e81bSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 171713e81bSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 181713e81bSScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 191713e81bSScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 201713e81bSScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 211713e81bSScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 221713e81bSScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 231713e81bSScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 241713e81bSScott Long * SUCH DAMAGE. 251713e81bSScott Long * 261713e81bSScott Long * $FreeBSD$ 271713e81bSScott Long */ 281713e81bSScott Long #ifndef _OSBSD_H_ 291713e81bSScott Long #define _OSBSD_H_ 301713e81bSScott Long 311713e81bSScott Long #include <sys/bus.h> 321713e81bSScott Long #include <sys/resource.h> 331713e81bSScott Long #include <sys/eventhandler.h> 34d2bd3ab9SScott Long #include <sys/devicestat.h> 351713e81bSScott Long 36d2bd3ab9SScott Long #if (__FreeBSD_version < 500043) 37d2bd3ab9SScott Long #include <stddef.h> 38d2bd3ab9SScott Long #include <sys/buf.h> 39d2bd3ab9SScott Long #endif 40d2bd3ab9SScott Long 41d2bd3ab9SScott Long #include <vm/vm.h> 42d2bd3ab9SScott Long #include <vm/pmap.h> 43d2bd3ab9SScott Long #include <vm/vm_extern.h> 44d2bd3ab9SScott Long 45d2bd3ab9SScott Long #if (__FreeBSD_version < 600030) 46d2bd3ab9SScott Long #include <machine/bus_memio.h> 47d2bd3ab9SScott Long #endif 481713e81bSScott Long #include <machine/bus.h> 491713e81bSScott Long #include <machine/resource.h> 501713e81bSScott Long #include <machine/bus.h> 51d2bd3ab9SScott Long 521713e81bSScott Long #include <sys/rman.h> 531713e81bSScott Long 541713e81bSScott Long #include <cam/cam.h> 551713e81bSScott Long #include <cam/cam_ccb.h> 561713e81bSScott Long #include <cam/cam_debug.h> 571713e81bSScott Long #include <cam/cam_sim.h> 581713e81bSScott Long #include <cam/cam_xpt_sim.h> 591713e81bSScott Long #include <cam/cam_periph.h> 60d2bd3ab9SScott Long #include <cam/cam_xpt_periph.h> 61d2bd3ab9SScott Long 621713e81bSScott Long #include <cam/scsi/scsi_all.h> 631713e81bSScott Long #include <cam/scsi/scsi_message.h> 641713e81bSScott Long 65d2bd3ab9SScott Long 66d2bd3ab9SScott Long 671713e81bSScott Long extern intrmask_t lock_driver(void); 681713e81bSScott Long extern void unlock_driver(intrmask_t spl); 691713e81bSScott Long 701713e81bSScott Long typedef struct 711713e81bSScott Long { 721713e81bSScott Long UCHAR status; /* 0 nonbootable; 80h bootable */ 731713e81bSScott Long UCHAR start_head; 741713e81bSScott Long USHORT start_sector; 751713e81bSScott Long UCHAR type; 761713e81bSScott Long UCHAR end_head; 771713e81bSScott Long USHORT end_sector; 781713e81bSScott Long ULONG start_abs_sector; 791713e81bSScott Long ULONG num_of_sector; 801713e81bSScott Long } partition; 811713e81bSScott Long 821713e81bSScott Long typedef struct _INQUIRYDATA { 831713e81bSScott Long UCHAR DeviceType : 5; 841713e81bSScott Long UCHAR DeviceTypeQualifier : 3; 851713e81bSScott Long UCHAR DeviceTypeModifier : 7; 861713e81bSScott Long UCHAR RemovableMedia : 1; 871713e81bSScott Long UCHAR Versions; 881713e81bSScott Long UCHAR ResponseDataFormat; 891713e81bSScott Long UCHAR AdditionalLength; 901713e81bSScott Long UCHAR Reserved[2]; 911713e81bSScott Long UCHAR SoftReset : 1; 921713e81bSScott Long UCHAR CommandQueue : 1; 931713e81bSScott Long UCHAR Reserved2 : 1; 941713e81bSScott Long UCHAR LinkedCommands : 1; 951713e81bSScott Long UCHAR Synchronous : 1; 961713e81bSScott Long UCHAR Wide16Bit : 1; 971713e81bSScott Long UCHAR Wide32Bit : 1; 981713e81bSScott Long UCHAR RelativeAddressing : 1; 991713e81bSScott Long UCHAR VendorId[8]; 1001713e81bSScott Long UCHAR ProductId[16]; 1011713e81bSScott Long UCHAR ProductRevisionLevel[4]; 1021713e81bSScott Long UCHAR VendorSpecific[20]; 1031713e81bSScott Long UCHAR Reserved3[40]; 1041713e81bSScott Long } INQUIRYDATA, *PINQUIRYDATA; 1051713e81bSScott Long 1061713e81bSScott Long typedef struct _READ_CAPACITY_DATA { 1071713e81bSScott Long ULONG LogicalBlockAddress; 1081713e81bSScott Long ULONG BytesPerBlock; 1091713e81bSScott Long } READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA; 1101713e81bSScott Long 1111713e81bSScott Long #define MV_IAL_HT_SACOALT_DEFAULT 1 1121713e81bSScott Long #define MV_IAL_HT_SAITMTH_DEFAULT 1 1131713e81bSScott Long 1141713e81bSScott Long /****************************************/ 1151713e81bSScott Long /* GENERAL Definitions */ 1161713e81bSScott Long /****************************************/ 1171713e81bSScott Long 1181713e81bSScott Long /* Bits for HD_ERROR */ 1191713e81bSScott Long #define NM_ERR 0x02 /* media present */ 1201713e81bSScott Long #define ABRT_ERR 0x04 /* Command aborted */ 1211713e81bSScott Long #define MCR_ERR 0x08 /* media change request */ 1221713e81bSScott Long #define IDNF_ERR 0x10 /* ID field not found */ 1231713e81bSScott Long #define MC_ERR 0x20 /* media changed */ 1241713e81bSScott Long #define UNC_ERR 0x40 /* Uncorrect data */ 1251713e81bSScott Long #define WP_ERR 0x40 /* write protect */ 1261713e81bSScott Long #define ICRC_ERR 0x80 /* new meaning: CRC error during transfer */ 1271713e81bSScott Long 1281713e81bSScott Long #define REQUESTS_ARRAY_SIZE (9 * MV_EDMA_REQUEST_QUEUE_SIZE) /* 9 K bytes */ 1291713e81bSScott Long #define RESPONSES_ARRAY_SIZE (12 * MV_EDMA_RESPONSE_QUEUE_SIZE) /* 3 K bytes */ 1301713e81bSScott Long 1311713e81bSScott Long #define PRD_ENTRIES_PER_CMD (MAX_SG_DESCRIPTORS+1) 1321713e81bSScott Long #define PRD_ENTRIES_SIZE (MV_EDMA_PRD_ENTRY_SIZE*PRD_ENTRIES_PER_CMD) 1331713e81bSScott Long #define PRD_TABLES_FOR_VBUS (MV_SATA_CHANNELS_NUM*MV_EDMA_QUEUE_LENGTH) 1341713e81bSScott Long 135d2bd3ab9SScott Long typedef enum _SataEvent 136d2bd3ab9SScott Long { 1371713e81bSScott Long SATA_EVENT_NO_CHANGE = 0, 1381713e81bSScott Long SATA_EVENT_CHANNEL_CONNECTED, 1391713e81bSScott Long SATA_EVENT_CHANNEL_DISCONNECTED 1401713e81bSScott Long } SATA_EVENT; 1411713e81bSScott Long 1421713e81bSScott Long typedef ULONG_PTR dma_addr_t; 1431713e81bSScott Long 144d2bd3ab9SScott Long typedef struct _MV_CHANNEL 145d2bd3ab9SScott Long { 1461713e81bSScott Long unsigned int maxUltraDmaModeSupported; 1471713e81bSScott Long unsigned int maxDmaModeSupported; 1481713e81bSScott Long unsigned int maxPioModeSupported; 1491713e81bSScott Long MV_BOOLEAN online; 1501713e81bSScott Long } MV_CHANNEL; 1511713e81bSScott Long 152d2bd3ab9SScott Long typedef struct _BUS_DMAMAP 153d2bd3ab9SScott Long { struct _BUS_DMAMAP *next; 154d2bd3ab9SScott Long struct IALAdapter *pAdapter; 155d2bd3ab9SScott Long bus_dmamap_t dma_map; 156d2bd3ab9SScott Long SCAT_GATH psg[MAX_SG_DESCRIPTORS]; 157d2bd3ab9SScott Long } BUS_DMAMAP, *PBUS_DMAMAP; 1581713e81bSScott Long 159d2bd3ab9SScott Long typedef struct IALAdapter 160d2bd3ab9SScott Long { 1611713e81bSScott Long struct cam_path *path; 162d2bd3ab9SScott Long 163d2bd3ab9SScott Long bus_dma_tag_t io_dma_parent; /* I/O buffer DMA tag */ 164d2bd3ab9SScott Long PBUS_DMAMAP pbus_dmamap_list; 165d2bd3ab9SScott Long PBUS_DMAMAP pbus_dmamap; 166d2bd3ab9SScott Long 1671713e81bSScott Long device_t hpt_dev; /* bus device */ 1681713e81bSScott Long struct resource *hpt_irq; /* interrupt */ 1691713e81bSScott Long struct resource *mem_res; 170d2bd3ab9SScott Long void *hpt_intr; /* interrupt handle */ 1711713e81bSScott Long struct IALAdapter *next; 1721713e81bSScott Long 1731713e81bSScott Long MV_SATA_ADAPTER mvSataAdapter; 1741713e81bSScott Long MV_CHANNEL mvChannel[MV_SATA_CHANNELS_NUM]; 1751713e81bSScott Long MV_U8 *requestsArrayBaseAddr; 1761713e81bSScott Long MV_U8 *requestsArrayBaseAlignedAddr; 1771713e81bSScott Long dma_addr_t requestsArrayBaseDmaAddr; 1781713e81bSScott Long dma_addr_t requestsArrayBaseDmaAlignedAddr; 1791713e81bSScott Long MV_U8 *responsesArrayBaseAddr; 1801713e81bSScott Long MV_U8 *responsesArrayBaseAlignedAddr; 1811713e81bSScott Long dma_addr_t responsesArrayBaseDmaAddr; 1821713e81bSScott Long dma_addr_t responsesArrayBaseDmaAlignedAddr; 1831713e81bSScott Long SATA_EVENT sataEvents[MV_SATA_CHANNELS_NUM]; 1841713e81bSScott Long 1851713e81bSScott Long struct callout_handle event_timer_connect; 1861713e81bSScott Long struct callout_handle event_timer_disconnect; 1871713e81bSScott Long 1881713e81bSScott Long struct _VBus VBus; 1891713e81bSScott Long struct _VDevice VDevices[MV_SATA_CHANNELS_NUM]; 1901713e81bSScott Long PCommand pCommandBlocks; 1911713e81bSScott Long PUCHAR prdTableAddr; 192d2bd3ab9SScott Long PUCHAR prdTableAlignedAddr; 1931713e81bSScott Long void* pFreePRDLink; 1941713e81bSScott Long 1951713e81bSScott Long union ccb *pending_Q; 1961713e81bSScott Long 1971713e81bSScott Long MV_U8 outstandingCommands; 1981713e81bSScott Long 1991713e81bSScott Long UCHAR status; 2001713e81bSScott Long UCHAR ver_601; 2011713e81bSScott Long UCHAR beeping; 2021713e81bSScott Long 2031713e81bSScott Long eventhandler_tag eh; 204d2bd3ab9SScott Long } 205d2bd3ab9SScott Long IAL_ADAPTER_T; 2061713e81bSScott Long 2071713e81bSScott Long extern IAL_ADAPTER_T *gIal_Adapter; 2081713e81bSScott Long 2091713e81bSScott Long /*entry.c*/ 2101713e81bSScott Long typedef void (*HPT_DPC)(IAL_ADAPTER_T *,void*,UCHAR); 211d2bd3ab9SScott Long 2121713e81bSScott Long int hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags); 213d2bd3ab9SScott Long void hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags); 2141713e81bSScott Long void Check_Idle_Call(IAL_ADAPTER_T *pAdapter); 2151713e81bSScott Long void fRescanAllDevice(_VBUS_ARG0); 2161713e81bSScott Long int hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk); 2171713e81bSScott Long 218d2bd3ab9SScott Long int Kernel_DeviceIoControl(_VBUS_ARG 219d2bd3ab9SScott Long DWORD dwIoControlCode, /* operation control code */ 220d2bd3ab9SScott Long PVOID lpInBuffer, /* input data buffer */ 221d2bd3ab9SScott Long DWORD nInBufferSize, /* size of input data buffer */ 222d2bd3ab9SScott Long PVOID lpOutBuffer, /* output data buffer */ 223d2bd3ab9SScott Long DWORD nOutBufferSize, /* size of output data buffer */ 224d2bd3ab9SScott Long PDWORD lpBytesReturned /* byte count */ 225d2bd3ab9SScott Long ); 226d2bd3ab9SScott Long 2271713e81bSScott Long 2281713e81bSScott Long #define __str_direct(x) #x 2291713e81bSScott Long #define __str(x) __str_direct(x) 2301713e81bSScott Long #define KMSG_LEADING __str(PROC_DIR_NAME) ": " 231d2bd3ab9SScott Long #define hpt_printk(_x_) do { printf(KMSG_LEADING); printf _x_ ; } while (0) 2321713e81bSScott Long 2331713e81bSScott Long #define DUPLICATE 0 2341713e81bSScott Long #define INITIALIZE 1 2351713e81bSScott Long #define REBUILD_PARITY 2 2361713e81bSScott Long #define VERIFY 3 2371713e81bSScott Long 238d2bd3ab9SScott Long /***********************************************************/ 239d2bd3ab9SScott Long 2401713e81bSScott Long static __inline struct cam_periph * 2411713e81bSScott Long hpt_get_periph(int path_id,int target_id) 2421713e81bSScott Long { 2431713e81bSScott Long struct cam_periph *periph = NULL; 2441713e81bSScott Long struct cam_path *path; 2451713e81bSScott Long int status; 2461713e81bSScott Long 2471713e81bSScott Long status = xpt_create_path(&path, NULL, path_id, target_id, 0); 2481713e81bSScott Long if (status == CAM_REQ_CMP) { 249d2bd3ab9SScott Long periph = cam_periph_find(path, "da"); 2501713e81bSScott Long xpt_free_path(path); 251d2bd3ab9SScott Long 2521713e81bSScott Long } 2531713e81bSScott Long return periph; 2541713e81bSScott Long } 2551713e81bSScott Long 256d2bd3ab9SScott Long #if (__FreeBSD_version < 500000) 257d2bd3ab9SScott Long #define YIELD_THREAD yield(curproc, 0) 258d2bd3ab9SScott Long #endif 259d2bd3ab9SScott Long 260d2bd3ab9SScott Long #ifdef __i386__ 261d2bd3ab9SScott Long #define BITS_PER_LONG 32 262d2bd3ab9SScott Long #define VDEV_TO_ID(pVDev) (DEVICEID)(pVDev) 263d2bd3ab9SScott Long #define ID_TO_VDEV(id) (PVDevice)(id) 264d2bd3ab9SScott Long #else /*Only support x86_64(AMD64 and EM64T)*/ 265d2bd3ab9SScott Long #define BITS_PER_LONG 64 266d2bd3ab9SScott Long #define VDEV_TO_ID(pVDev) (DEVICEID)(ULONG_PTR)(pVDev) 267d2bd3ab9SScott Long #define ID_TO_VDEV(id) (PVDevice)(((ULONG_PTR)gIal_Adapter & 0xffffffff00000000) | (id)) 268d2bd3ab9SScott Long #endif 269d2bd3ab9SScott Long 270d2bd3ab9SScott Long #define INVALID_DEVICEID (-1) 271d2bd3ab9SScott Long #define INVALID_STRIPSIZE (-1) 272d2bd3ab9SScott Long 273d2bd3ab9SScott Long #define shortswap(w) ((WORD)((w)>>8 | ((w) & 0xFF)<<8)) 274d2bd3ab9SScott Long 275d2bd3ab9SScott Long #ifndef MinBlockSizeShift 276d2bd3ab9SScott Long #define MinBlockSizeShift 5 277d2bd3ab9SScott Long #define MaxBlockSizeShift 12 278d2bd3ab9SScott Long #endif 279d2bd3ab9SScott Long 280d2bd3ab9SScott Long #pragma pack(1) 281d2bd3ab9SScott Long typedef struct _HPT_IOCTL_TRANSFER_PARAM 2821713e81bSScott Long { 283d2bd3ab9SScott Long ULONG nInBufferSize; 284d2bd3ab9SScott Long ULONG nOutBufferSize; 285d2bd3ab9SScott Long UCHAR buffer[0]; 286d2bd3ab9SScott Long }HPT_IOCTL_TRANSFER_PARAM, *PHPT_IOCTL_TRANSFER_PARAM; 2871713e81bSScott Long 288d2bd3ab9SScott Long typedef struct _HPT_SET_STATE_PARAM 2891713e81bSScott Long { 290d2bd3ab9SScott Long DEVICEID idArray; 291d2bd3ab9SScott Long DWORD state; 292d2bd3ab9SScott Long } HPT_SET_STATE_PARAM, *PHPT_SET_STATE_PARAM; 2931713e81bSScott Long 294d2bd3ab9SScott Long typedef struct _HPT_SET_ARRAY_INFO 2951713e81bSScott Long { 296d2bd3ab9SScott Long DEVICEID idArray; 297d2bd3ab9SScott Long ALTERABLE_ARRAY_INFO Info; 298d2bd3ab9SScott Long } HPT_SET_ARRAY_INFO, *PHPT_SET_ARRAY_INFO; 2991713e81bSScott Long 300d2bd3ab9SScott Long typedef struct _HPT_SET_DEVICE_INFO 3011713e81bSScott Long { 302d2bd3ab9SScott Long DEVICEID idDisk; 303d2bd3ab9SScott Long ALTERABLE_DEVICE_INFO Info; 304d2bd3ab9SScott Long } HPT_SET_DEVICE_INFO, *PHPT_SET_DEVICE_INFO; 3051713e81bSScott Long 306d2bd3ab9SScott Long typedef struct _HPT_ADD_DISK_TO_ARRAY 3071713e81bSScott Long { 308d2bd3ab9SScott Long DEVICEID idArray; 309d2bd3ab9SScott Long DEVICEID idDisk; 310d2bd3ab9SScott Long } HPT_ADD_DISK_TO_ARRAY, *PHPT_ADD_DISK_TO_ARRAY; 3111713e81bSScott Long 312d2bd3ab9SScott Long int check_VDevice_valid(PVDevice); 313d2bd3ab9SScott Long int hpt_default_ioctl(_VBUS_ARG DWORD, PVOID, DWORD, PVOID, DWORD, PDWORD); 3141713e81bSScott Long 315d2bd3ab9SScott Long #define HPT_NULL_ID 0 3161713e81bSScott Long 317d2bd3ab9SScott Long #pragma pack() 3181713e81bSScott Long 3191713e81bSScott Long #endif 320