xref: /freebsd/sys/dev/hptmv/osbsd.h (revision 39beb93c)
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$
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 #include <sys/devicestat.h>
35 
36 #if (__FreeBSD_version < 500043)
37 #include <stddef.h>
38 #include <sys/buf.h>
39 #endif
40 
41 #include <vm/vm.h>
42 #include <vm/pmap.h>
43 #include <vm/vm_extern.h>
44 
45 #if (__FreeBSD_version < 600030)
46 #include <machine/bus_memio.h>
47 #endif
48 #include <machine/bus.h>
49 #include <machine/resource.h>
50 #include <machine/bus.h>
51 
52 #include <sys/rman.h>
53 
54 #include <cam/cam.h>
55 #include <cam/cam_ccb.h>
56 #include <cam/cam_debug.h>
57 #include <cam/cam_sim.h>
58 #include <cam/cam_xpt_sim.h>
59 #include <cam/cam_periph.h>
60 
61 #include <cam/scsi/scsi_all.h>
62 #include <cam/scsi/scsi_message.h>
63 
64 
65 
66 extern intrmask_t lock_driver(void);
67 extern void unlock_driver(intrmask_t spl);
68 
69 typedef struct
70 {
71 	UCHAR		status;     		/* 0 nonbootable; 80h bootable */
72 	UCHAR      	start_head;
73 	USHORT     	start_sector;
74 	UCHAR      	type;
75 	UCHAR      	end_head;
76 	USHORT     	end_sector;
77 	ULONG      	start_abs_sector;
78 	ULONG      	num_of_sector;
79 } partition;
80 
81 typedef struct _INQUIRYDATA {
82 	UCHAR DeviceType : 5;
83 	UCHAR DeviceTypeQualifier : 3;
84 	UCHAR DeviceTypeModifier : 7;
85 	UCHAR RemovableMedia : 1;
86 	UCHAR Versions;
87 	UCHAR ResponseDataFormat;
88 	UCHAR AdditionalLength;
89 	UCHAR Reserved[2];
90 	UCHAR SoftReset : 1;
91 	UCHAR CommandQueue : 1;
92 	UCHAR Reserved2 : 1;
93 	UCHAR LinkedCommands : 1;
94 	UCHAR Synchronous : 1;
95 	UCHAR Wide16Bit : 1;
96 	UCHAR Wide32Bit : 1;
97 	UCHAR RelativeAddressing : 1;
98 	UCHAR VendorId[8];
99 	UCHAR ProductId[16];
100 	UCHAR ProductRevisionLevel[4];
101 	UCHAR VendorSpecific[20];
102 	UCHAR Reserved3[40];
103 } INQUIRYDATA, *PINQUIRYDATA;
104 
105 typedef struct _READ_CAPACITY_DATA {
106 	ULONG LogicalBlockAddress;
107 	ULONG BytesPerBlock;
108 } READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA;
109 
110 #define MV_IAL_HT_SACOALT_DEFAULT	1
111 #define MV_IAL_HT_SAITMTH_DEFAULT	1
112 
113 /****************************************/
114 /*          GENERAL Definitions         */
115 /****************************************/
116 
117 /* Bits for HD_ERROR */
118 #define NM_ERR			0x02	/* media present */
119 #define ABRT_ERR		0x04	/* Command aborted */
120 #define MCR_ERR         0x08	/* media change request */
121 #define IDNF_ERR        0x10	/* ID field not found */
122 #define MC_ERR          0x20	/* media changed */
123 #define UNC_ERR         0x40	/* Uncorrect data */
124 #define WP_ERR          0x40	/* write protect */
125 #define ICRC_ERR        0x80	/* new meaning:  CRC error during transfer */
126 
127 #define REQUESTS_ARRAY_SIZE			(9 * MV_EDMA_REQUEST_QUEUE_SIZE) /* 9 K bytes */
128 #define RESPONSES_ARRAY_SIZE		(12 * MV_EDMA_RESPONSE_QUEUE_SIZE) /* 3 K bytes */
129 
130 #define PRD_ENTRIES_PER_CMD         (MAX_SG_DESCRIPTORS+1)
131 #define PRD_ENTRIES_SIZE            (MV_EDMA_PRD_ENTRY_SIZE*PRD_ENTRIES_PER_CMD)
132 #define PRD_TABLES_FOR_VBUS         (MV_SATA_CHANNELS_NUM*MV_EDMA_QUEUE_LENGTH)
133 
134 typedef enum _SataEvent
135 {
136     SATA_EVENT_NO_CHANGE = 0,
137 	SATA_EVENT_CHANNEL_CONNECTED,
138 	SATA_EVENT_CHANNEL_DISCONNECTED
139 } SATA_EVENT;
140 
141 typedef ULONG_PTR dma_addr_t;
142 
143 typedef struct _MV_CHANNEL
144 {
145 	unsigned int		maxUltraDmaModeSupported;
146 	unsigned int		maxDmaModeSupported;
147 	unsigned int		maxPioModeSupported;
148 	MV_BOOLEAN			online;
149 } MV_CHANNEL;
150 
151 typedef struct _BUS_DMAMAP
152 {	struct _BUS_DMAMAP 	 	*next;
153 	struct IALAdapter 			*pAdapter;
154 	bus_dmamap_t 			dma_map;
155 	SCAT_GATH				psg[MAX_SG_DESCRIPTORS];
156 } BUS_DMAMAP, *PBUS_DMAMAP;
157 
158 typedef struct IALAdapter
159 {
160 	struct cam_path 	*path;
161 
162 	bus_dma_tag_t	  io_dma_parent; /* I/O buffer DMA tag */
163 	PBUS_DMAMAP	  pbus_dmamap_list;
164 	PBUS_DMAMAP	  pbus_dmamap;
165 
166 	device_t			hpt_dev;				/* bus device */
167 	struct resource		*hpt_irq;					/* interrupt */
168 	struct resource		*mem_res;
169 	void				*hpt_intr;				/* interrupt handle */
170 	struct IALAdapter   *next;
171 
172 	MV_SATA_ADAPTER     mvSataAdapter;
173 	MV_CHANNEL          mvChannel[MV_SATA_CHANNELS_NUM];
174 	MV_U8				*requestsArrayBaseAddr;
175 	MV_U8				*requestsArrayBaseAlignedAddr;
176 	dma_addr_t			requestsArrayBaseDmaAddr;
177 	dma_addr_t			requestsArrayBaseDmaAlignedAddr;
178 	MV_U8				*responsesArrayBaseAddr;
179 	MV_U8				*responsesArrayBaseAlignedAddr;
180 	dma_addr_t			responsesArrayBaseDmaAddr;
181 	dma_addr_t			responsesArrayBaseDmaAlignedAddr;
182 	SATA_EVENT			sataEvents[MV_SATA_CHANNELS_NUM];
183 
184    	struct	callout_handle event_timer_connect;
185   	struct	callout_handle event_timer_disconnect;
186 
187 	struct _VBus        VBus;
188 	struct _VDevice     VDevices[MV_SATA_CHANNELS_NUM];
189 	PCommand			pCommandBlocks;
190 	PUCHAR				prdTableAddr;
191 	PUCHAR				prdTableAlignedAddr;
192 	void*				pFreePRDLink;
193 
194 	union ccb           *pending_Q;
195 
196 	MV_U8   			outstandingCommands;
197 
198 	UCHAR               status;
199 	UCHAR               ver_601;
200 	UCHAR               beeping;
201 
202 	eventhandler_tag	eh;
203 }
204 IAL_ADAPTER_T;
205 
206 extern IAL_ADAPTER_T *gIal_Adapter;
207 
208 /*entry.c*/
209 typedef void (*HPT_DPC)(IAL_ADAPTER_T *,void*,UCHAR);
210 
211 int hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags);
212 void hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags);
213 void Check_Idle_Call(IAL_ADAPTER_T *pAdapter);
214 void fRescanAllDevice(_VBUS_ARG0);
215 int hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk);
216 
217 int Kernel_DeviceIoControl(_VBUS_ARG
218 							DWORD dwIoControlCode,       	/* operation control code */
219 							PVOID lpInBuffer,            	/* input data buffer */
220 							DWORD nInBufferSize,         	/* size of input data buffer */
221 							PVOID lpOutBuffer,           	/* output data buffer */
222 							DWORD nOutBufferSize,        	/* size of output data buffer */
223 							PDWORD lpBytesReturned      	/* byte count */
224 						);
225 
226 
227 #define __str_direct(x) #x
228 #define __str(x) __str_direct(x)
229 #define KMSG_LEADING __str(PROC_DIR_NAME) ": "
230 #define hpt_printk(_x_) do { printf(KMSG_LEADING); printf _x_ ; } while (0)
231 
232 #define DUPLICATE      0
233 #define INITIALIZE     1
234 #define REBUILD_PARITY 2
235 #define VERIFY         3
236 
237 /***********************************************************/
238 
239 static __inline struct cam_periph *
240 hpt_get_periph(int path_id,int target_id)
241 {
242 	struct cam_periph	*periph = NULL;
243     struct cam_path	*path;
244     int			status;
245 
246     status = xpt_create_path(&path, NULL, path_id, target_id, 0);
247     if (status == CAM_REQ_CMP) {
248 		periph = cam_periph_find(path, "da");
249 		xpt_free_path(path);
250 
251     }
252 	return periph;
253 }
254 
255 #if (__FreeBSD_version < 500000)
256 #define YIELD_THREAD yield(curproc, 0)
257 #endif
258 
259 #ifdef __i386__
260 #define BITS_PER_LONG 32
261 #define VDEV_TO_ID(pVDev) (DEVICEID)(pVDev)
262 #define ID_TO_VDEV(id) (PVDevice)(id)
263 #else /*Only support x86_64(AMD64 and EM64T)*/
264 #define BITS_PER_LONG 64
265 #define VDEV_TO_ID(pVDev) (DEVICEID)(ULONG_PTR)(pVDev)
266 #define ID_TO_VDEV(id) (PVDevice)(((ULONG_PTR)gIal_Adapter & 0xffffffff00000000) | (id))
267 #endif
268 
269 #define INVALID_DEVICEID		(-1)
270 #define INVALID_STRIPSIZE		(-1)
271 
272 #define shortswap(w) ((WORD)((w)>>8 | ((w) & 0xFF)<<8))
273 
274 #ifndef MinBlockSizeShift
275 #define MinBlockSizeShift 5
276 #define MaxBlockSizeShift 12
277 #endif
278 
279 #pragma pack(1)
280 typedef struct _HPT_IOCTL_TRANSFER_PARAM
281 {
282 	ULONG nInBufferSize;
283 	ULONG nOutBufferSize;
284 	UCHAR buffer[0];
285 }HPT_IOCTL_TRANSFER_PARAM, *PHPT_IOCTL_TRANSFER_PARAM;
286 
287 typedef struct _HPT_SET_STATE_PARAM
288 {
289 	DEVICEID idArray;
290 	DWORD state;
291 } HPT_SET_STATE_PARAM, *PHPT_SET_STATE_PARAM;
292 
293 typedef struct _HPT_SET_ARRAY_INFO
294 {
295 	DEVICEID idArray;
296 	ALTERABLE_ARRAY_INFO Info;
297 } HPT_SET_ARRAY_INFO, *PHPT_SET_ARRAY_INFO;
298 
299 typedef struct _HPT_SET_DEVICE_INFO
300 {
301 	DEVICEID idDisk;
302 	ALTERABLE_DEVICE_INFO Info;
303 } HPT_SET_DEVICE_INFO, *PHPT_SET_DEVICE_INFO;
304 
305 typedef struct _HPT_ADD_DISK_TO_ARRAY
306 {
307 	DEVICEID idArray;
308 	DEVICEID idDisk;
309 } HPT_ADD_DISK_TO_ARRAY, *PHPT_ADD_DISK_TO_ARRAY;
310 
311 int check_VDevice_valid(PVDevice);
312 int hpt_default_ioctl(_VBUS_ARG DWORD, PVOID, DWORD, PVOID, DWORD, PDWORD);
313 
314 #define HPT_NULL_ID 0
315 
316 #pragma pack()
317 
318 #endif
319