xref: /dragonfly/sys/dev/raid/hptmv/osbsd.h (revision bb8c85ff)
1 /*
2  * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/dev/hptmv/osbsd.h,v 1.7 2009/04/07 16:38:25 delphij Exp $
27  */
28 #ifndef _OSBSD_H_
29 #define _OSBSD_H_
30 
31 #include <sys/bus.h>
32 #include <sys/resource.h>
33 #include <sys/eventhandler.h>
34 
35 #include <vm/vm.h>
36 #include <vm/pmap.h>
37 #include <vm/vm_extern.h>
38 
39 #include <sys/rman.h>
40 
41 #include <bus/cam/cam.h>
42 #include <bus/cam/cam_ccb.h>
43 #include <bus/cam/cam_debug.h>
44 #include <bus/cam/cam_sim.h>
45 #include <bus/cam/cam_xpt_sim.h>
46 #include <bus/cam/cam_periph.h>
47 
48 #include <bus/cam/scsi/scsi_all.h>
49 #include <bus/cam/scsi/scsi_message.h>
50 
51 
52 
53 extern void lock_driver(void);
54 extern void unlock_driver(void);
55 
56 typedef struct
57 {
58 	UCHAR		status;     		/* 0 nonbootable; 80h bootable */
59 	UCHAR      	start_head;
60 	USHORT     	start_sector;
61 	UCHAR      	type;
62 	UCHAR      	end_head;
63 	USHORT     	end_sector;
64 	ULONG      	start_abs_sector;
65 	ULONG      	num_of_sector;
66 } partition;
67 
68 typedef struct _INQUIRYDATA {
69 	UCHAR DeviceType : 5;
70 	UCHAR DeviceTypeQualifier : 3;
71 	UCHAR DeviceTypeModifier : 7;
72 	UCHAR RemovableMedia : 1;
73 	UCHAR Versions;
74 	UCHAR ResponseDataFormat;
75 	UCHAR AdditionalLength;
76 	UCHAR Reserved[2];
77 	UCHAR SoftReset : 1;
78 	UCHAR CommandQueue : 1;
79 	UCHAR Reserved2 : 1;
80 	UCHAR LinkedCommands : 1;
81 	UCHAR Synchronous : 1;
82 	UCHAR Wide16Bit : 1;
83 	UCHAR Wide32Bit : 1;
84 	UCHAR RelativeAddressing : 1;
85 	UCHAR VendorId[8];
86 	UCHAR ProductId[16];
87 	UCHAR ProductRevisionLevel[4];
88 	UCHAR VendorSpecific[20];
89 	UCHAR Reserved3[40];
90 } INQUIRYDATA, *PINQUIRYDATA;
91 
92 #define MV_IAL_HT_SACOALT_DEFAULT	1
93 #define MV_IAL_HT_SAITMTH_DEFAULT	1
94 
95 /****************************************/
96 /*          GENERAL Definitions         */
97 /****************************************/
98 
99 /* Bits for HD_ERROR */
100 #define NM_ERR			0x02	/* media present */
101 #define ABRT_ERR		0x04	/* Command aborted */
102 #define MCR_ERR         0x08	/* media change request */
103 #define IDNF_ERR        0x10	/* ID field not found */
104 #define MC_ERR          0x20	/* media changed */
105 #define UNC_ERR         0x40	/* Uncorrect data */
106 #define WP_ERR          0x40	/* write protect */
107 #define ICRC_ERR        0x80	/* new meaning:  CRC error during transfer */
108 
109 #define REQUESTS_ARRAY_SIZE			(9 * MV_EDMA_REQUEST_QUEUE_SIZE) /* 9 K bytes */
110 #define RESPONSES_ARRAY_SIZE		(12 * MV_EDMA_RESPONSE_QUEUE_SIZE) /* 3 K bytes */
111 
112 #define PRD_ENTRIES_PER_CMD         (MAX_SG_DESCRIPTORS+1)
113 #define PRD_ENTRIES_SIZE            (MV_EDMA_PRD_ENTRY_SIZE*PRD_ENTRIES_PER_CMD)
114 #define PRD_TABLES_FOR_VBUS         (MV_SATA_CHANNELS_NUM*MV_EDMA_QUEUE_LENGTH)
115 
116 typedef enum _SataEvent
117 {
118     SATA_EVENT_NO_CHANGE = 0,
119 	SATA_EVENT_CHANNEL_CONNECTED,
120 	SATA_EVENT_CHANNEL_DISCONNECTED
121 } SATA_EVENT;
122 
123 typedef ULONG_PTR dma_addr_t;
124 
125 typedef struct _MV_CHANNEL
126 {
127 	unsigned int		maxUltraDmaModeSupported;
128 	unsigned int		maxDmaModeSupported;
129 	unsigned int		maxPioModeSupported;
130 	MV_BOOLEAN		online;
131 	MV_BOOLEAN		writeCacheSupported;
132 	MV_BOOLEAN		writeCacheEnabled;
133 	MV_BOOLEAN		readAheadSupported;
134 	MV_BOOLEAN		readAheadEnabled;
135 	MV_U8			queueDepth;
136 
137 } MV_CHANNEL;
138 
139 typedef struct _BUS_DMAMAP
140 {	struct _BUS_DMAMAP 	 	*next;
141 	struct IALAdapter 			*pAdapter;
142 	bus_dmamap_t 			dma_map;
143 	SCAT_GATH				psg[MAX_SG_DESCRIPTORS];
144 } BUS_DMAMAP, *PBUS_DMAMAP;
145 
146 typedef struct IALAdapter
147 {
148 	struct cam_path 	*path;
149 
150 	bus_dma_tag_t	  io_dma_parent; /* I/O buffer DMA tag */
151 	PBUS_DMAMAP	  pbus_dmamap_list;
152 	PBUS_DMAMAP	  pbus_dmamap;
153 
154 	device_t			hpt_dev;				/* bus device */
155 	struct resource		*hpt_irq;					/* interrupt */
156 	struct resource		*mem_res;
157 	void				*hpt_intr;				/* interrupt handle */
158 	struct IALAdapter   *next;
159 
160 	MV_SATA_ADAPTER     mvSataAdapter;
161 	MV_CHANNEL          mvChannel[MV_SATA_CHANNELS_NUM];
162 	MV_U8				*requestsArrayBaseAddr;
163 	MV_U8				*requestsArrayBaseAlignedAddr;
164 	dma_addr_t			requestsArrayBaseDmaAddr;
165 	dma_addr_t			requestsArrayBaseDmaAlignedAddr;
166 	MV_U8				*responsesArrayBaseAddr;
167 	MV_U8				*responsesArrayBaseAlignedAddr;
168 	dma_addr_t			responsesArrayBaseDmaAddr;
169 	dma_addr_t			responsesArrayBaseDmaAlignedAddr;
170 	SATA_EVENT			sataEvents[MV_SATA_CHANNELS_NUM];
171 
172 	struct	callout event_timer_connect;
173 	struct	callout event_timer_disconnect;
174 
175 	struct _VBus        VBus;
176 	struct _VDevice     VDevices[MV_SATA_CHANNELS_NUM];
177 	PCommand			pCommandBlocks;
178 	PUCHAR				prdTableAddr;
179 	PUCHAR				prdTableAlignedAddr;
180 	void*				pFreePRDLink;
181 
182 	union ccb           *pending_Q;
183 
184 	MV_U8   			outstandingCommands;
185 
186 	UCHAR               status;
187 	UCHAR               ver_601;
188 	UCHAR               beeping;
189 
190 	eventhandler_tag	eh;
191 }
192 IAL_ADAPTER_T;
193 
194 extern IAL_ADAPTER_T *gIal_Adapter;
195 
196 /*entry.c*/
197 typedef void (*HPT_DPC)(IAL_ADAPTER_T *,void*,UCHAR);
198 
199 int hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags);
200 void hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags);
201 void Check_Idle_Call(IAL_ADAPTER_T *pAdapter);
202 void fRescanAllDevice(_VBUS_ARG0);
203 int hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk);
204 
205 int Kernel_DeviceIoControl(_VBUS_ARG
206 							DWORD dwIoControlCode,       	/* operation control code */
207 							PVOID lpInBuffer,            	/* input data buffer */
208 							DWORD nInBufferSize,         	/* size of input data buffer */
209 							PVOID lpOutBuffer,           	/* output data buffer */
210 							DWORD nOutBufferSize,        	/* size of output data buffer */
211 							PDWORD lpBytesReturned      	/* byte count */
212 						);
213 
214 
215 #define __str_direct(x) #x
216 #define __str(x) __str_direct(x)
217 #define KMSG_LEADING __str(PROC_DIR_NAME) ": "
218 #define hpt_printk(_x_) do { kprintf(KMSG_LEADING); kprintf _x_ ; } while (0)
219 
220 #define DUPLICATE      0
221 #define INITIALIZE     1
222 #define REBUILD_PARITY 2
223 #define VERIFY         3
224 
225 /***********************************************************/
226 
227 static __inline struct cam_periph *
228 hpt_get_periph(int path_id,int target_id)
229 {
230 	struct cam_periph	*periph = NULL;
231     struct cam_path	*path;
232     int			status;
233 
234     status = xpt_create_path(&path, NULL, path_id, target_id, 0);
235     if (status == CAM_REQ_CMP) {
236 		periph = cam_periph_find(path, "da");
237 		xpt_free_path(path);
238 
239     }
240 	return periph;
241 }
242 
243 #ifdef __x86_64__
244 #define BITS_PER_LONG 64
245 #define VDEV_TO_ID(pVDev) (DEVICEID)(ULONG_PTR)(pVDev)
246 #define ID_TO_VDEV(id) (PVDevice)(((ULONG_PTR)gIal_Adapter & 0xffffffff00000000) | (id))
247 #endif
248 
249 #define INVALID_DEVICEID		(-1)
250 #define INVALID_STRIPSIZE		(-1)
251 
252 #define shortswap(w) ((WORD)((w)>>8 | ((w) & 0xFF)<<8))
253 
254 #ifndef MinBlockSizeShift
255 #define MinBlockSizeShift 5
256 #define MaxBlockSizeShift 12
257 #endif
258 
259 #pragma pack(1)
260 typedef struct _HPT_IOCTL_TRANSFER_PARAM
261 {
262 	ULONG nInBufferSize;
263 	ULONG nOutBufferSize;
264 	UCHAR buffer[0];
265 }HPT_IOCTL_TRANSFER_PARAM, *PHPT_IOCTL_TRANSFER_PARAM;
266 
267 typedef struct _HPT_SET_STATE_PARAM
268 {
269 	DEVICEID idArray;
270 	DWORD state;
271 } HPT_SET_STATE_PARAM, *PHPT_SET_STATE_PARAM;
272 
273 typedef struct _HPT_SET_ARRAY_INFO
274 {
275 	DEVICEID idArray;
276 	ALTERABLE_ARRAY_INFO Info;
277 } HPT_SET_ARRAY_INFO, *PHPT_SET_ARRAY_INFO;
278 
279 typedef struct _HPT_SET_DEVICE_INFO
280 {
281 	DEVICEID idDisk;
282 	ALTERABLE_DEVICE_INFO Info;
283 } HPT_SET_DEVICE_INFO, *PHPT_SET_DEVICE_INFO;
284 
285 typedef struct _HPT_SET_DEVICE_INFO_V2
286 {
287 	DEVICEID idDisk;
288 	ALTERABLE_DEVICE_INFO_V2 Info;
289 } HPT_SET_DEVICE_INFO_V2, *PHPT_SET_DEVICE_INFO_V2;
290 
291 typedef struct _HPT_ADD_DISK_TO_ARRAY
292 {
293 	DEVICEID idArray;
294 	DEVICEID idDisk;
295 } HPT_ADD_DISK_TO_ARRAY, *PHPT_ADD_DISK_TO_ARRAY;
296 
297 typedef struct _HPT_DEVICE_IO
298 {
299 	DEVICEID	id;
300 	int			cmd;
301 	ULONG		lba;
302 	DWORD		nSector;
303 	UCHAR		buffer[0];
304 } HPT_DEVICE_IO, *PHPT_DEVICE_IO;
305 
306 int check_VDevice_valid(PVDevice);
307 int hpt_default_ioctl(_VBUS_ARG DWORD, PVOID, DWORD, PVOID, DWORD, PDWORD);
308 
309 #define HPT_NULL_ID 0
310 
311 #pragma pack()
312 
313 #endif
314