1331722Seadler/*
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 _GLOBAL_H_
29136849Sscottl#define _GLOBAL_H_
30136849Sscottl
31136849Sscottl#include <dev/hptmv/mvOs.h>
32143039Sscottl#include <dev/hptmv/mvSata.h>
33143039Sscottl#include <dev/hptmv/mvStorageDev.h>
34136849Sscottl
35149871Sscottl#define COMPANY      "HighPoint Technologies, Inc."
36190809Sdelphij#define COPYRIGHT    "(c) 2000-2007. HighPoint Technologies, Inc."
37190809Sdelphij#define DRIVER_NAME		"RocketRAID 18xx SATA Controller driver"
38190809Sdelphij#define CONTROLLER_NAME	"RocketRAID 18xx SATA Controller"
39149871Sscottl#define PROC_DIR_NAME hptmv
40136849Sscottl
41190809Sdelphij#define HPT_INTERFACE_VERSION 0x01010000
42136849Sscottl#define SUPPORT_48BIT_LBA
43136849Sscottl#define SUPPORT_ARRAY
44136849Sscottl#define SUPPORT_RAID5 1
45136849Sscottl#define _RAID5N_
46136849Sscottl#define MAX_QUEUE_COMM 32
47136849Sscottl#define MAX_SG_DESCRIPTORS 17
48149871Sscottl#define MAX_VBUS 2    /*one vbus per adapter in mv linux driver,
49149871Sscottl                        MAX_VBUS is defined for share code and can not be 1*/
50136849Sscottl
51136849Sscottl#define SET_VBUS_FOR_EACH_CONTROLLER
52136849Sscottl#define MAX_MEMBERS 8
53136849Sscottl#define MAX_ARRAY_NAME 16
54136849Sscottl#define MAX_VDEVICE_PER_VBUS 8
55136849Sscottl#define MAX_ARRAY_DEVICE MAX_ARRAY_PER_VBUS
56136849Sscottl#define MAX_CHIP_IN_VBUS 1
57136849Sscottl
58136849Sscottl#define SUPPORT_IOCTL
59136849Sscottl#define SUPPORT_FAIL_LED
60136849Sscottl
61136849Sscottltypedef void * PChipInstance;
62136849Sscottltypedef void * PChannel;
63136849Sscottltypedef struct _VDevice *PVDevice;
64136849Sscottltypedef struct _VBus *PVBus;
65136849Sscottltypedef struct _ArrayDescript *PArrayDescript;
66136849Sscottltypedef struct _ArrayDescriptV2 *PArrayDescriptV2;
67136849Sscottltypedef struct _Command *PCommand;
68136849Sscottl
69136849Sscottltypedef struct _Device {
70136849Sscottl	UCHAR df_on_line;
71136849Sscottl	UCHAR df_atapi;
72136849Sscottl	UCHAR df_removable_drive;
73136849Sscottl	UCHAR busyCount;
74136849Sscottl
75136849Sscottl	UCHAR df_tcq_set: 1;
76149871Sscottl    UCHAR df_tcq: 1;          /* enable TCQ */
77136849Sscottl	UCHAR df_ncq_set: 1;
78149871Sscottl    UCHAR df_ncq: 1;          /* enable NCQ */
79136849Sscottl	UCHAR df_write_cache_set: 1;
80149871Sscottl    UCHAR df_write_cache: 1;  /* enable write cache */
81136849Sscottl	UCHAR df_read_ahead_set: 1;
82149871Sscottl    UCHAR df_read_ahead: 1;   /* enable read ahead */
83149871Sscottl
84136849Sscottl	UCHAR retryCount;
85136849Sscottl	UCHAR resetCount;
86136849Sscottl	UCHAR pad1;
87149871Sscottl
88136849Sscottl	UCHAR df_user_mode_set;
89149871Sscottl    UCHAR bDeModeSetting;    /* Current Data Transfer mode: 0-4 PIO 0-4 */
90149871Sscottl    UCHAR bDeUsable_Mode;       /* actual maximum data transfer mode */
91136849Sscottl	UCHAR bDeUserSelectMode;
92149871Sscottl
93136849Sscottl	PVBus pVBus;
94136849Sscottl	ULONG dDeRealCapacity;
95136849Sscottl	ULONG dDeHiddenLba;
96136849Sscottl	ULONG HeadPosition;
97136849Sscottl	ULONG QueueLength;
98136849Sscottl	MV_SATA_CHANNEL *mv;
99149871Sscottl}
100149871SscottlDevice, *PDevice;
101136849Sscottl
102149871Sscottltypedef struct _SCAT_GATH
103149871Sscottl{
104149871Sscottl    ULONG_PTR     dSgAddress;
105149871Sscottl    USHORT        wSgSize;
106149871Sscottl    USHORT        wSgFlag;
107136849Sscottl} SCAT_GATH, FAR *FPSCAT_GATH;
108136849Sscottl
109136849Sscottl#define OS_VDEV_EXT
110149871Sscottltypedef struct _VDevice_Ext
111149871Sscottl{
112136849Sscottl	UCHAR gui_locked; /* the device is locked by GUI */
113136849Sscottl	UCHAR reserve[3];
114136849Sscottl} VDevice_Ext, *PVDevice_Ext;
115136849Sscottl
116136849Sscottl
117136849Sscottl#define SG_FLAG_SKIP        0x4000
118136849Sscottl#define SG_FLAG_EOT         0x8000
119136849Sscottl
120136849Sscottl#define _VBUS_ARG0 PVBus _vbus_p
121136849Sscottl#define _VBUS_ARG PVBus _vbus_p,
122136849Sscottl#define _VBUS_P _vbus_p,
123136849Sscottl#define _VBUS_P0 _vbus_p
124136849Sscottl#define _VBUS_INST(x) PVBus _vbus_p = x;
125136849Sscottl#define _vbus_(x) (_vbus_p->x)
126136849Sscottl
127136849Sscottl/*************************************************************************
128136849Sscottl * arithmetic functions
129136849Sscottl *************************************************************************/
130136849Sscottl#define LongRShift(x, y) 	(x >> y)
131136849Sscottl#define LongLShift(x, y)   	(x << y)
132136849Sscottl#define LongDiv(x, y)      	(x / (UINT)(y))
133136849Sscottl#define LongRem(x, y)		(x % (UINT)(y))
134136849Sscottl#define LongMul(x, y)      	(x * y)
135136849Sscottl
136136849Sscottl/*************************************************************************
137136849Sscottl * C library
138136849Sscottl *************************************************************************/
139136849Sscottlint HPTLIBAPI os_memcmp(const void *cs, const void *ct, unsigned len);
140136849Sscottlvoid HPTLIBAPI os_memcpy(void *to, const void *from, unsigned len);
141136849Sscottlvoid HPTLIBAPI os_memset(void *s, char c, unsigned len);
142136849Sscottlunsigned HPTLIBAPI os_strlen(const char *s);
143149871Sscottl
144136849Sscottl#ifdef NO_LIBC
145136849Sscottl#define memcmp os_memcmp
146136849Sscottl#define memcpy os_memcpy
147136849Sscottl#define memset os_memset
148136849Sscottl#define strlen os_strlen
149136849Sscottl#endif
150136849Sscottl#define ZeroMemory(a, b)  	memset((char *)a, 0, b)
151136849Sscottl#define MemoryCopy(a,b,c) 	memcpy((char *)(a), (char *)(b), (UINT)(c))
152149871Sscottl#define farMemoryCopy(a,b,c) memcpy((char *)(a), (char *)(b), (UINT)c)
153136849Sscottl#define StrLen            	strlen
154136849Sscottl
155136849Sscottl/*
156136849Sscottl * we don't want whole hptintf.h in shared code...
157136849Sscottl * some constants must match that in hptintf.h!
158136849Sscottl */
159149871Sscottlenum _driver_events_t
160149871Sscottl{
161136849Sscottl	ET_DEVICE=0,
162149871Sscottl    ET_DEVICE_REMOVED,
163149871Sscottl    ET_DEVICE_PLUGGED,
164149871Sscottl    ET_DEVICE_ERROR,
165149871Sscottl    ET_REBUILD_STARTED,
166149871Sscottl    ET_REBUILD_ABORTED,
167149871Sscottl    ET_REBUILD_FINISHED,
168149871Sscottl    ET_SPARE_TOOK_OVER,
169149871Sscottl    ET_REBUILD_FAILED,
170136849Sscottl	ET_VERIFY_STARTED,
171136849Sscottl	ET_VERIFY_ABORTED,
172136849Sscottl	ET_VERIFY_FAILED,
173136849Sscottl	ET_VERIFY_FINISHED,
174136849Sscottl	ET_INITIALIZE_STARTED,
175136849Sscottl	ET_INITIALIZE_ABORTED,
176136849Sscottl	ET_INITIALIZE_FAILED,
177136849Sscottl	ET_INITIALIZE_FINISHED,
178136849Sscottl	ET_VERIFY_DATA_ERROR,
179136849Sscottl};
180136849Sscottl
181149871Sscottl#define StallExec(x) mvMicroSecondsDelay(x)
182136849Sscottlextern void HPTLIBAPI ioctl_ReportEvent(UCHAR event, PVOID param);
183149871Sscottl#define fNotifyGUI(WhatHappen, pVDevice) ioctl_ReportEvent(WhatHappen, pVDevice)
184149871Sscottl#define DECLARE_BUFFER(type, ptr) UCHAR ptr##__buf[512]; type ptr=(type)ptr##__buf
185136849Sscottl
186149871Sscottlint HPTLIBAPI fDeReadWrite(PDevice pDev, ULONG Lba, UCHAR Cmd, void *tmpBuffer);
187149871Sscottlvoid HPTLIBAPI fDeSelectMode(PDevice pDev, UCHAR NewMode);
188190809Sdelphijint HPTLIBAPI fDeSetTCQ(PDevice pDev, int enable, int depth);
189190809Sdelphijint HPTLIBAPI fDeSetNCQ(PDevice pDev, int enable, int depth);
190190809Sdelphijint HPTLIBAPI fDeSetWriteCache(PDevice pDev, int enable);
191190809Sdelphijint HPTLIBAPI fDeSetReadAhead(PDevice pDev, int enable);
192149871Sscottl
193143039Sscottl#include <dev/hptmv/atapi.h>
194143039Sscottl#include <dev/hptmv/command.h>
195143039Sscottl#include <dev/hptmv/array.h>
196143039Sscottl#include <dev/hptmv/raid5n.h>
197143039Sscottl#include <dev/hptmv/vdevice.h>
198136849Sscottl
199149871Sscottl#if defined(__FreeBSD__) && defined(HPTLIBAPI)
200149871Sscottl#undef HPTLIBAPI
201149871Sscottl#define HPTLIBAPI
202149871Sscottl#endif
203136849Sscottl
204136849Sscottl#ifdef SUPPORT_ARRAY
205136849Sscottl#define ArrayTables(i) ((PVDevice)&_vbus_(_ArrayTables)[i*ARRAY_VDEV_SIZE])
206136849Sscottl#endif
207136849Sscottl
208136849Sscottl#endif
209