summaryrefslogtreecommitdiffstats
path: root/sys/dev/hptmv/osbsd.h
blob: a07f51dbc8d7160cdc2885f6973a34a088566f22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
 * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */
#ifndef _OSBSD_H_
#define _OSBSD_H_

#include <sys/bus.h>
#include <sys/resource.h>
#include <sys/eventhandler.h>
#include <sys/devicestat.h>

#if (__FreeBSD_version < 500043)
#include <stddef.h>
#include <sys/buf.h>
#endif

#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_extern.h>

#if (__FreeBSD_version < 600030)
#include <machine/bus_memio.h>
#endif
#include <machine/bus.h>
#include <machine/resource.h>
#include <machine/bus.h>

#include <sys/rman.h>

#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_debug.h>
#include <cam/cam_sim.h>
#include <cam/cam_xpt_sim.h>
#include <cam/cam_periph.h>
#include <cam/cam_xpt_periph.h>

#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_message.h>



extern intrmask_t lock_driver(void);
extern void unlock_driver(intrmask_t spl);

typedef struct 
{
	UCHAR		status;     		/* 0 nonbootable; 80h bootable */
	UCHAR      	start_head;
	USHORT     	start_sector;
	UCHAR      	type;
	UCHAR      	end_head;
	USHORT     	end_sector;
	ULONG      	start_abs_sector;
	ULONG      	num_of_sector;
} partition;

typedef struct _INQUIRYDATA {
	UCHAR DeviceType : 5;
	UCHAR DeviceTypeQualifier : 3;
	UCHAR DeviceTypeModifier : 7;
	UCHAR RemovableMedia : 1;
	UCHAR Versions;
	UCHAR ResponseDataFormat;
	UCHAR AdditionalLength;
	UCHAR Reserved[2];
	UCHAR SoftReset : 1;
	UCHAR CommandQueue : 1;
	UCHAR Reserved2 : 1;
	UCHAR LinkedCommands : 1;
	UCHAR Synchronous : 1;
	UCHAR Wide16Bit : 1;
	UCHAR Wide32Bit : 1;
	UCHAR RelativeAddressing : 1;
	UCHAR VendorId[8];
	UCHAR ProductId[16];
	UCHAR ProductRevisionLevel[4];
	UCHAR VendorSpecific[20];
	UCHAR Reserved3[40];
} INQUIRYDATA, *PINQUIRYDATA;

typedef struct _READ_CAPACITY_DATA {
	ULONG LogicalBlockAddress;
	ULONG BytesPerBlock;
} READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA;

#define MV_IAL_HT_SACOALT_DEFAULT	1
#define MV_IAL_HT_SAITMTH_DEFAULT	1

/****************************************/
/*          GENERAL Definitions         */
/****************************************/

/* Bits for HD_ERROR */
#define NM_ERR			0x02	/* media present */
#define ABRT_ERR		0x04	/* Command aborted */
#define MCR_ERR         0x08	/* media change request */
#define IDNF_ERR        0x10	/* ID field not found */
#define MC_ERR          0x20	/* media changed */
#define UNC_ERR         0x40	/* Uncorrect data */
#define WP_ERR          0x40	/* write protect */
#define ICRC_ERR        0x80	/* new meaning:  CRC error during transfer */

#define REQUESTS_ARRAY_SIZE			(9 * MV_EDMA_REQUEST_QUEUE_SIZE) /* 9 K bytes */
#define RESPONSES_ARRAY_SIZE		(12 * MV_EDMA_RESPONSE_QUEUE_SIZE) /* 3 K bytes */

#define PRD_ENTRIES_PER_CMD         (MAX_SG_DESCRIPTORS+1)
#define PRD_ENTRIES_SIZE            (MV_EDMA_PRD_ENTRY_SIZE*PRD_ENTRIES_PER_CMD)
#define PRD_TABLES_FOR_VBUS         (MV_SATA_CHANNELS_NUM*MV_EDMA_QUEUE_LENGTH)

typedef enum _SataEvent
{
    SATA_EVENT_NO_CHANGE = 0,
	SATA_EVENT_CHANNEL_CONNECTED,
	SATA_EVENT_CHANNEL_DISCONNECTED
} SATA_EVENT;

typedef ULONG_PTR dma_addr_t;

typedef struct _MV_CHANNEL
{
	unsigned int		maxUltraDmaModeSupported;
	unsigned int		maxDmaModeSupported;
	unsigned int		maxPioModeSupported;
	MV_BOOLEAN			online;
} MV_CHANNEL;

typedef struct _BUS_DMAMAP
{	struct _BUS_DMAMAP 	 	*next;
	struct IALAdapter 			*pAdapter;
	bus_dmamap_t 			dma_map;
	SCAT_GATH				psg[MAX_SG_DESCRIPTORS];
} BUS_DMAMAP, *PBUS_DMAMAP;

typedef struct IALAdapter 
{
	struct cam_path 	*path;

	bus_dma_tag_t	  io_dma_parent; /* I/O buffer DMA tag */
	PBUS_DMAMAP	  pbus_dmamap_list;
	PBUS_DMAMAP	  pbus_dmamap;

	device_t			hpt_dev;				/* bus device */
	struct resource		*hpt_irq;					/* interrupt */
	struct resource		*mem_res;
	void				*hpt_intr;				/* interrupt handle */
	struct IALAdapter   *next;

	MV_SATA_ADAPTER     mvSataAdapter;
	MV_CHANNEL          mvChannel[MV_SATA_CHANNELS_NUM];
	MV_U8				*requestsArrayBaseAddr;
	MV_U8				*requestsArrayBaseAlignedAddr;
	dma_addr_t			requestsArrayBaseDmaAddr;
	dma_addr_t			requestsArrayBaseDmaAlignedAddr;
	MV_U8				*responsesArrayBaseAddr;
	MV_U8				*responsesArrayBaseAlignedAddr;
	dma_addr_t			responsesArrayBaseDmaAddr;
	dma_addr_t			responsesArrayBaseDmaAlignedAddr;
	SATA_EVENT			sataEvents[MV_SATA_CHANNELS_NUM];
	
   	struct	callout_handle event_timer_connect;
  	struct	callout_handle event_timer_disconnect;

	struct _VBus        VBus;
	struct _VDevice     VDevices[MV_SATA_CHANNELS_NUM];
	PCommand			pCommandBlocks;
	PUCHAR				prdTableAddr;
	PUCHAR				prdTableAlignedAddr;
	void*				pFreePRDLink;

	union ccb           *pending_Q;

	MV_U8   			outstandingCommands;

	UCHAR               status;
	UCHAR               ver_601;
	UCHAR               beeping;

	eventhandler_tag	eh;
}
IAL_ADAPTER_T;

extern IAL_ADAPTER_T *gIal_Adapter;

/*entry.c*/
typedef void (*HPT_DPC)(IAL_ADAPTER_T *,void*,UCHAR);

int hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags);
void hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags);
void Check_Idle_Call(IAL_ADAPTER_T *pAdapter);
void fRescanAllDevice(_VBUS_ARG0);
int hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk);

int Kernel_DeviceIoControl(_VBUS_ARG
							DWORD dwIoControlCode,       	/* operation control code */
							PVOID lpInBuffer,            	/* input data buffer */
							DWORD nInBufferSize,         	/* size of input data buffer */
							PVOID lpOutBuffer,           	/* output data buffer */
							DWORD nOutBufferSize,        	/* size of output data buffer */
							PDWORD lpBytesReturned      	/* byte count */
						);


#define __str_direct(x) #x
#define __str(x) __str_direct(x)
#define KMSG_LEADING __str(PROC_DIR_NAME) ": "
#define hpt_printk(_x_) do { printf(KMSG_LEADING); printf _x_ ; } while (0)

#define DUPLICATE      0
#define INITIALIZE     1
#define REBUILD_PARITY 2
#define VERIFY         3

/***********************************************************/

static __inline struct cam_periph *
hpt_get_periph(int path_id,int target_id)
{
	struct cam_periph	*periph = NULL;
    struct cam_path	*path;
    int			status;

    status = xpt_create_path(&path, NULL, path_id, target_id, 0);
    if (status == CAM_REQ_CMP) {
		periph = cam_periph_find(path, "da");
		xpt_free_path(path);
			
    }
	return periph;	
}

#if (__FreeBSD_version < 500000)
#define YIELD_THREAD yield(curproc, 0)
#endif

#ifdef __i386__
#define BITS_PER_LONG 32
#define VDEV_TO_ID(pVDev) (DEVICEID)(pVDev)
#define ID_TO_VDEV(id) (PVDevice)(id)
#else /*Only support x86_64(AMD64 and EM64T)*/
#define BITS_PER_LONG 64
#define VDEV_TO_ID(pVDev) (DEVICEID)(ULONG_PTR)(pVDev)
#define ID_TO_VDEV(id) (PVDevice)(((ULONG_PTR)gIal_Adapter & 0xffffffff00000000) | (id))
#endif

#define INVALID_DEVICEID		(-1)
#define INVALID_STRIPSIZE		(-1)

#define shortswap(w) ((WORD)((w)>>8 | ((w) & 0xFF)<<8))

#ifndef MinBlockSizeShift
#define MinBlockSizeShift 5
#define MaxBlockSizeShift 12
#endif

#pragma pack(1)
typedef struct _HPT_IOCTL_TRANSFER_PARAM
{
	ULONG nInBufferSize;
	ULONG nOutBufferSize;
	UCHAR buffer[0];
}HPT_IOCTL_TRANSFER_PARAM, *PHPT_IOCTL_TRANSFER_PARAM;

typedef struct _HPT_SET_STATE_PARAM
{
	DEVICEID idArray;
	DWORD state;
} HPT_SET_STATE_PARAM, *PHPT_SET_STATE_PARAM;

typedef struct _HPT_SET_ARRAY_INFO
{
	DEVICEID idArray;
	ALTERABLE_ARRAY_INFO Info;
} HPT_SET_ARRAY_INFO, *PHPT_SET_ARRAY_INFO;

typedef struct _HPT_SET_DEVICE_INFO
{
	DEVICEID idDisk;
	ALTERABLE_DEVICE_INFO Info;
} HPT_SET_DEVICE_INFO, *PHPT_SET_DEVICE_INFO;

typedef struct _HPT_ADD_DISK_TO_ARRAY
{
	DEVICEID idArray;
	DEVICEID idDisk;
} HPT_ADD_DISK_TO_ARRAY, *PHPT_ADD_DISK_TO_ARRAY;

int check_VDevice_valid(PVDevice);
int hpt_default_ioctl(_VBUS_ARG DWORD, PVOID, DWORD, PVOID, DWORD, PDWORD);

#define HPT_NULL_ID 0

#pragma pack()

#endif
OpenPOWER on IntegriCloud