xref: /freebsd/sys/dev/hptmv/global.h (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 #ifndef _GLOBAL_H_
31 #define _GLOBAL_H_
32 
33 #include <dev/hptmv/mvOs.h>
34 #include <dev/hptmv/mvSata.h>
35 #include <dev/hptmv/mvStorageDev.h>
36 
37 #define COMPANY      "HighPoint Technologies, Inc."
38 #define COPYRIGHT    "(c) 2000-2007. HighPoint Technologies, Inc."
39 #define DRIVER_NAME		"RocketRAID 18xx SATA Controller driver"
40 #define CONTROLLER_NAME	"RocketRAID 18xx SATA Controller"
41 #define PROC_DIR_NAME hptmv
42 
43 #define HPT_INTERFACE_VERSION 0x01010000
44 #define SUPPORT_48BIT_LBA
45 #define SUPPORT_ARRAY
46 #define SUPPORT_RAID5 1
47 #define _RAID5N_
48 #define MAX_QUEUE_COMM 32
49 #define MAX_SG_DESCRIPTORS 17
50 #define MAX_VBUS 2    /*one vbus per adapter in mv linux driver,
51                         MAX_VBUS is defined for share code and can not be 1*/
52 
53 #define SET_VBUS_FOR_EACH_CONTROLLER
54 #define MAX_MEMBERS 8
55 #define MAX_ARRAY_NAME 16
56 #define MAX_VDEVICE_PER_VBUS 8
57 #define MAX_ARRAY_DEVICE MAX_ARRAY_PER_VBUS
58 #define MAX_CHIP_IN_VBUS 1
59 
60 #define SUPPORT_IOCTL
61 #define SUPPORT_FAIL_LED
62 
63 typedef void * PChipInstance;
64 typedef void * PChannel;
65 typedef struct _VDevice *PVDevice;
66 typedef struct _VBus *PVBus;
67 typedef struct _ArrayDescript *PArrayDescript;
68 typedef struct _ArrayDescriptV2 *PArrayDescriptV2;
69 typedef struct _Command *PCommand;
70 
71 typedef struct _Device {
72 	UCHAR df_on_line;
73 	UCHAR df_atapi;
74 	UCHAR df_removable_drive;
75 	UCHAR busyCount;
76 
77 	UCHAR df_tcq_set: 1;
78     UCHAR df_tcq: 1;          /* enable TCQ */
79 	UCHAR df_ncq_set: 1;
80     UCHAR df_ncq: 1;          /* enable NCQ */
81 	UCHAR df_write_cache_set: 1;
82     UCHAR df_write_cache: 1;  /* enable write cache */
83 	UCHAR df_read_ahead_set: 1;
84     UCHAR df_read_ahead: 1;   /* enable read ahead */
85 
86 	UCHAR retryCount;
87 	UCHAR resetCount;
88 	UCHAR pad1;
89 
90 	UCHAR df_user_mode_set;
91     UCHAR bDeModeSetting;    /* Current Data Transfer mode: 0-4 PIO 0-4 */
92     UCHAR bDeUsable_Mode;       /* actual maximum data transfer mode */
93 	UCHAR bDeUserSelectMode;
94 
95 	PVBus pVBus;
96 	ULONG dDeRealCapacity;
97 	ULONG dDeHiddenLba;
98 	ULONG HeadPosition;
99 	ULONG QueueLength;
100 	MV_SATA_CHANNEL *mv;
101 }
102 Device, *PDevice;
103 
104 typedef struct _SCAT_GATH
105 {
106     ULONG_PTR     dSgAddress;
107     USHORT        wSgSize;
108     USHORT        wSgFlag;
109 } SCAT_GATH, FAR *FPSCAT_GATH;
110 
111 #define OS_VDEV_EXT
112 typedef struct _VDevice_Ext
113 {
114 	UCHAR gui_locked; /* the device is locked by GUI */
115 	UCHAR reserve[3];
116 } VDevice_Ext, *PVDevice_Ext;
117 
118 
119 #define SG_FLAG_SKIP        0x4000
120 #define SG_FLAG_EOT         0x8000
121 
122 #define _VBUS_ARG0 PVBus _vbus_p
123 #define _VBUS_ARG PVBus _vbus_p,
124 #define _VBUS_P _vbus_p,
125 #define _VBUS_P0 _vbus_p
126 #define _VBUS_INST(x) PVBus _vbus_p = x;
127 #define _vbus_(x) (_vbus_p->x)
128 
129 /*************************************************************************
130  * arithmetic functions
131  *************************************************************************/
132 #define LongRShift(x, y) 	(x >> y)
133 #define LongLShift(x, y)   	(x << y)
134 #define LongDiv(x, y)      	(x / (UINT)(y))
135 #define LongRem(x, y)		(x % (UINT)(y))
136 #define LongMul(x, y)      	(x * y)
137 
138 /*************************************************************************
139  * C library
140  *************************************************************************/
141 int HPTLIBAPI os_memcmp(const void *cs, const void *ct, unsigned len);
142 void HPTLIBAPI os_memcpy(void *to, const void *from, unsigned len);
143 void HPTLIBAPI os_memset(void *s, char c, unsigned len);
144 unsigned HPTLIBAPI os_strlen(const char *s);
145 
146 #ifdef NO_LIBC
147 #define memcmp os_memcmp
148 #define memcpy os_memcpy
149 #define memset os_memset
150 #define strlen os_strlen
151 #endif
152 #define ZeroMemory(a, b)  	memset((char *)a, 0, b)
153 #define MemoryCopy(a,b,c) 	memcpy((char *)(a), (char *)(b), (UINT)(c))
154 #define farMemoryCopy(a,b,c) memcpy((char *)(a), (char *)(b), (UINT)c)
155 #define StrLen            	strlen
156 
157 /*
158  * we don't want whole hptintf.h in shared code...
159  * some constants must match that in hptintf.h!
160  */
161 enum _driver_events_t
162 {
163 	ET_DEVICE=0,
164     ET_DEVICE_REMOVED,
165     ET_DEVICE_PLUGGED,
166     ET_DEVICE_ERROR,
167     ET_REBUILD_STARTED,
168     ET_REBUILD_ABORTED,
169     ET_REBUILD_FINISHED,
170     ET_SPARE_TOOK_OVER,
171     ET_REBUILD_FAILED,
172 	ET_VERIFY_STARTED,
173 	ET_VERIFY_ABORTED,
174 	ET_VERIFY_FAILED,
175 	ET_VERIFY_FINISHED,
176 	ET_INITIALIZE_STARTED,
177 	ET_INITIALIZE_ABORTED,
178 	ET_INITIALIZE_FAILED,
179 	ET_INITIALIZE_FINISHED,
180 	ET_VERIFY_DATA_ERROR,
181 };
182 
183 #define StallExec(x) mvMicroSecondsDelay(x)
184 extern void HPTLIBAPI ioctl_ReportEvent(UCHAR event, PVOID param);
185 #define fNotifyGUI(WhatHappen, pVDevice) ioctl_ReportEvent(WhatHappen, pVDevice)
186 #define DECLARE_BUFFER(type, ptr) UCHAR ptr##__buf[512]; type ptr=(type)ptr##__buf
187 
188 int HPTLIBAPI fDeReadWrite(PDevice pDev, ULONG Lba, UCHAR Cmd, void *tmpBuffer);
189 void HPTLIBAPI fDeSelectMode(PDevice pDev, UCHAR NewMode);
190 int HPTLIBAPI fDeSetTCQ(PDevice pDev, int enable, int depth);
191 int HPTLIBAPI fDeSetNCQ(PDevice pDev, int enable, int depth);
192 int HPTLIBAPI fDeSetWriteCache(PDevice pDev, int enable);
193 int HPTLIBAPI fDeSetReadAhead(PDevice pDev, int enable);
194 
195 #include <dev/hptmv/atapi.h>
196 #include <dev/hptmv/command.h>
197 #include <dev/hptmv/array.h>
198 #include <dev/hptmv/raid5n.h>
199 #include <dev/hptmv/vdevice.h>
200 
201 #if defined(__FreeBSD__) && defined(HPTLIBAPI)
202 #undef HPTLIBAPI
203 #define HPTLIBAPI
204 #endif
205 
206 #ifdef SUPPORT_ARRAY
207 #define ArrayTables(i) ((PVDevice)&_vbus_(_ArrayTables)[i*ARRAY_VDEV_SIZE])
208 #endif
209 
210 #endif
211