xref: /freebsd/sys/dev/hptmv/global.h (revision d2bd3ab995038214fa00f73d4a88cd891d0afe34)
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 _GLOBAL_H_
291713e81bSScott Long #define _GLOBAL_H_
301713e81bSScott Long 
311713e81bSScott Long #include <dev/hptmv/mvOs.h>
32f7f3900bSScott Long #include <dev/hptmv/mvSata.h>
33f7f3900bSScott Long #include <dev/hptmv/mvStorageDev.h>
341713e81bSScott Long 
351713e81bSScott Long #define COMPANY      "HighPoint Technologies, Inc."
361713e81bSScott Long #define COPYRIGHT    "(c) 2000-2004. HighPoint Technologies, Inc."
371713e81bSScott Long #define DRIVER_NAME		"RocketRAID 182x SATA Controller driver"
381713e81bSScott Long #define CONTROLLER_NAME	"RocketRAID 182x SATA Controller"
391713e81bSScott Long #define PROC_DIR_NAME hptmv
401713e81bSScott Long 
411713e81bSScott Long #define HPT_INTERFACE_VERSION 0x01000003
421713e81bSScott Long #define SUPPORT_48BIT_LBA
431713e81bSScott Long #define SUPPORT_ARRAY
441713e81bSScott Long #define SUPPORT_RAID5 1
451713e81bSScott Long #define _RAID5N_
461713e81bSScott Long #define MAX_QUEUE_COMM 32
471713e81bSScott Long #define MAX_SG_DESCRIPTORS 17
48d2bd3ab9SScott Long #define MAX_VBUS 2    /*one vbus per adapter in mv linux driver,
49d2bd3ab9SScott Long                         MAX_VBUS is defined for share code and can not be 1*/
501713e81bSScott Long 
511713e81bSScott Long #define SET_VBUS_FOR_EACH_CONTROLLER
521713e81bSScott Long #define MAX_MEMBERS 8
531713e81bSScott Long #define MAX_ARRAY_NAME 16
541713e81bSScott Long #define MAX_VDEVICE_PER_VBUS 8
551713e81bSScott Long #define MAX_ARRAY_DEVICE MAX_ARRAY_PER_VBUS
561713e81bSScott Long #define MAX_CHIP_IN_VBUS 1
571713e81bSScott Long 
581713e81bSScott Long #define SUPPORT_IOCTL
591713e81bSScott Long #define SUPPORT_FAIL_LED
601713e81bSScott Long 
611713e81bSScott Long typedef void * PChipInstance;
621713e81bSScott Long typedef void * PChannel;
631713e81bSScott Long typedef struct _VDevice *PVDevice;
641713e81bSScott Long typedef struct _VBus *PVBus;
651713e81bSScott Long typedef struct _ArrayDescript *PArrayDescript;
661713e81bSScott Long typedef struct _ArrayDescriptV2 *PArrayDescriptV2;
671713e81bSScott Long typedef struct _Command *PCommand;
681713e81bSScott Long 
691713e81bSScott Long typedef struct _Device {
701713e81bSScott Long 	UCHAR df_on_line;
711713e81bSScott Long 	UCHAR df_atapi;
721713e81bSScott Long 	UCHAR df_removable_drive;
731713e81bSScott Long 	UCHAR busyCount;
741713e81bSScott Long 
751713e81bSScott Long 	UCHAR df_tcq_set: 1;
761713e81bSScott Long     UCHAR df_tcq: 1;          /* enable TCQ */
771713e81bSScott Long 	UCHAR df_ncq_set: 1;
781713e81bSScott Long     UCHAR df_ncq: 1;          /* enable NCQ */
791713e81bSScott Long 	UCHAR df_write_cache_set: 1;
801713e81bSScott Long     UCHAR df_write_cache: 1;  /* enable write cache */
811713e81bSScott Long 	UCHAR df_read_ahead_set: 1;
821713e81bSScott Long     UCHAR df_read_ahead: 1;   /* enable read ahead */
831713e81bSScott Long 
841713e81bSScott Long 	UCHAR retryCount;
851713e81bSScott Long 	UCHAR resetCount;
861713e81bSScott Long 	UCHAR pad1;
871713e81bSScott Long 
881713e81bSScott Long 	UCHAR df_user_mode_set;
891713e81bSScott Long     UCHAR bDeModeSetting;    /* Current Data Transfer mode: 0-4 PIO 0-4 */
901713e81bSScott Long     UCHAR bDeUsable_Mode;       /* actual maximum data transfer mode */
911713e81bSScott Long 	UCHAR bDeUserSelectMode;
921713e81bSScott Long 
931713e81bSScott Long 	PVBus pVBus;
941713e81bSScott Long 	ULONG dDeRealCapacity;
951713e81bSScott Long 	ULONG dDeHiddenLba;
961713e81bSScott Long 	ULONG HeadPosition;
971713e81bSScott Long 	ULONG QueueLength;
981713e81bSScott Long 	MV_SATA_CHANNEL *mv;
99d2bd3ab9SScott Long }
100d2bd3ab9SScott Long Device, *PDevice;
1011713e81bSScott Long 
102d2bd3ab9SScott Long typedef struct _SCAT_GATH
103d2bd3ab9SScott Long {
1041713e81bSScott Long     ULONG_PTR     dSgAddress;
1051713e81bSScott Long     USHORT        wSgSize;
1061713e81bSScott Long     USHORT        wSgFlag;
1071713e81bSScott Long } SCAT_GATH, FAR *FPSCAT_GATH;
1081713e81bSScott Long 
1091713e81bSScott Long #define OS_VDEV_EXT
110d2bd3ab9SScott Long typedef struct _VDevice_Ext
111d2bd3ab9SScott Long {
1121713e81bSScott Long 	UCHAR gui_locked; /* the device is locked by GUI */
1131713e81bSScott Long 	UCHAR reserve[3];
1141713e81bSScott Long } VDevice_Ext, *PVDevice_Ext;
1151713e81bSScott Long 
1161713e81bSScott Long 
1171713e81bSScott Long #define SG_FLAG_SKIP        0x4000
1181713e81bSScott Long #define SG_FLAG_EOT         0x8000
1191713e81bSScott Long 
1201713e81bSScott Long #define _VBUS_ARG0 PVBus _vbus_p
1211713e81bSScott Long #define _VBUS_ARG PVBus _vbus_p,
1221713e81bSScott Long #define _VBUS_P _vbus_p,
1231713e81bSScott Long #define _VBUS_P0 _vbus_p
1241713e81bSScott Long #define _VBUS_INST(x) PVBus _vbus_p = x;
1251713e81bSScott Long #define _vbus_(x) (_vbus_p->x)
1261713e81bSScott Long 
1271713e81bSScott Long /*************************************************************************
1281713e81bSScott Long  * arithmetic functions
1291713e81bSScott Long  *************************************************************************/
1301713e81bSScott Long #define LongRShift(x, y) 	(x >> y)
1311713e81bSScott Long #define LongLShift(x, y)   	(x << y)
1321713e81bSScott Long #define LongDiv(x, y)      	(x / (UINT)(y))
1331713e81bSScott Long #define LongRem(x, y)		(x % (UINT)(y))
1341713e81bSScott Long #define LongMul(x, y)      	(x * y)
1351713e81bSScott Long /* Minimum and maximum macros */
1361713e81bSScott Long #if (__FreeBSD_version < 501000)
1371713e81bSScott Long #define MAX(a, b)	(((a) > (b)) ? (a) : (b))
1381713e81bSScott Long #define MIN(a, b)	(((a) < (b)) ? (a) : (b))
1391713e81bSScott Long #endif
1401713e81bSScott Long 
1411713e81bSScott Long /*************************************************************************
1421713e81bSScott Long  * C library
1431713e81bSScott Long  *************************************************************************/
1441713e81bSScott Long int HPTLIBAPI os_memcmp(const void *cs, const void *ct, unsigned len);
1451713e81bSScott Long void HPTLIBAPI os_memcpy(void *to, const void *from, unsigned len);
1461713e81bSScott Long void HPTLIBAPI os_memset(void *s, char c, unsigned len);
1471713e81bSScott Long unsigned HPTLIBAPI os_strlen(const char *s);
148d2bd3ab9SScott Long 
1491713e81bSScott Long #ifdef NO_LIBC
1501713e81bSScott Long #define memcmp os_memcmp
1511713e81bSScott Long #define memcpy os_memcpy
1521713e81bSScott Long #define memset os_memset
1531713e81bSScott Long #define strlen os_strlen
1541713e81bSScott Long #elif (__FreeBSD_version <= 410000)
1551713e81bSScott Long #define	memcpy(d, s, len)     bcopy((s),(d),(len))
1561713e81bSScott Long #define	memset(d, s, len)     bzero((d),(len))
1571713e81bSScott Long #endif
1581713e81bSScott Long #define ZeroMemory(a, b)  	memset((char *)a, 0, b)
1591713e81bSScott Long #define MemoryCopy(a,b,c) 	memcpy((char *)(a), (char *)(b), (UINT)(c))
1601713e81bSScott Long #define farMemoryCopy(a,b,c) memcpy((char *)(a), (char *)(b), (UINT)c)
1611713e81bSScott Long #define StrLen            	strlen
1621713e81bSScott Long 
1631713e81bSScott Long /*
1641713e81bSScott Long  * we don't want whole hptintf.h in shared code...
1651713e81bSScott Long  * some constants must match that in hptintf.h!
1661713e81bSScott Long  */
167d2bd3ab9SScott Long enum _driver_events_t
168d2bd3ab9SScott Long {
1691713e81bSScott Long 	ET_DEVICE=0,
1701713e81bSScott Long     ET_DEVICE_REMOVED,
1711713e81bSScott Long     ET_DEVICE_PLUGGED,
1721713e81bSScott Long     ET_DEVICE_ERROR,
1731713e81bSScott Long     ET_REBUILD_STARTED,
1741713e81bSScott Long     ET_REBUILD_ABORTED,
1751713e81bSScott Long     ET_REBUILD_FINISHED,
1761713e81bSScott Long     ET_SPARE_TOOK_OVER,
1771713e81bSScott Long     ET_REBUILD_FAILED,
1781713e81bSScott Long 	ET_VERIFY_STARTED,
1791713e81bSScott Long 	ET_VERIFY_ABORTED,
1801713e81bSScott Long 	ET_VERIFY_FAILED,
1811713e81bSScott Long 	ET_VERIFY_FINISHED,
1821713e81bSScott Long 	ET_INITIALIZE_STARTED,
1831713e81bSScott Long 	ET_INITIALIZE_ABORTED,
1841713e81bSScott Long 	ET_INITIALIZE_FAILED,
1851713e81bSScott Long 	ET_INITIALIZE_FINISHED,
1861713e81bSScott Long 	ET_VERIFY_DATA_ERROR,
1871713e81bSScott Long };
1881713e81bSScott Long 
1891713e81bSScott Long #define StallExec(x) mvMicroSecondsDelay(x)
190d2bd3ab9SScott Long extern void HPTLIBAPI ioctl_ReportEvent(UCHAR event, PVOID param);
191d2bd3ab9SScott Long #define fNotifyGUI(WhatHappen, pVDevice) ioctl_ReportEvent(WhatHappen, pVDevice)
192d2bd3ab9SScott Long #define DECLARE_BUFFER(type, ptr) UCHAR ptr##__buf[512]; type ptr=(type)ptr##__buf
193d2bd3ab9SScott Long 
194d2bd3ab9SScott Long int HPTLIBAPI fDeReadWrite(PDevice pDev, ULONG Lba, UCHAR Cmd, void *tmpBuffer);
195d2bd3ab9SScott Long void HPTLIBAPI fDeSelectMode(PDevice pDev, UCHAR NewMode);
1961713e81bSScott Long 
197f7f3900bSScott Long #include <dev/hptmv/atapi.h>
198f7f3900bSScott Long #include <dev/hptmv/command.h>
199f7f3900bSScott Long #include <dev/hptmv/array.h>
200f7f3900bSScott Long #include <dev/hptmv/raid5n.h>
201f7f3900bSScott Long #include <dev/hptmv/vdevice.h>
2021713e81bSScott Long 
203d2bd3ab9SScott Long #if defined(__FreeBSD__) && defined(HPTLIBAPI)
204d2bd3ab9SScott Long #undef HPTLIBAPI
205d2bd3ab9SScott Long #define HPTLIBAPI
206d2bd3ab9SScott Long #endif
2071713e81bSScott Long 
2081713e81bSScott Long #ifdef SUPPORT_ARRAY
2091713e81bSScott Long #define ArrayTables(i) ((PVDevice)&_vbus_(_ArrayTables)[i*ARRAY_VDEV_SIZE])
2101713e81bSScott Long #endif
2111713e81bSScott Long 
2121713e81bSScott Long #endif
213