xref: /freebsd/sys/dev/hptmv/osbsd.h (revision a4b19cf5c76ac66d02a3ef8a549115ba865d630c)
1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4d2bd3ab9SScott Long  * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
51713e81bSScott Long  * All rights reserved.
61713e81bSScott Long  *
71713e81bSScott Long  * Redistribution and use in source and binary forms, with or without
81713e81bSScott Long  * modification, are permitted provided that the following conditions
91713e81bSScott Long  * are met:
101713e81bSScott Long  * 1. Redistributions of source code must retain the above copyright
111713e81bSScott Long  *    notice, this list of conditions and the following disclaimer.
121713e81bSScott Long  * 2. Redistributions in binary form must reproduce the above copyright
131713e81bSScott Long  *    notice, this list of conditions and the following disclaimer in the
141713e81bSScott Long  *    documentation and/or other materials provided with the distribution.
151713e81bSScott Long  *
161713e81bSScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
171713e81bSScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
181713e81bSScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
191713e81bSScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
201713e81bSScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
211713e81bSScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
221713e81bSScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
231713e81bSScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
241713e81bSScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251713e81bSScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261713e81bSScott Long  * SUCH DAMAGE.
271713e81bSScott Long  */
281713e81bSScott Long #ifndef _OSBSD_H_
291713e81bSScott Long #define _OSBSD_H_
301713e81bSScott Long 
311713e81bSScott Long #include <sys/bus.h>
321713e81bSScott Long #include <sys/resource.h>
331713e81bSScott Long #include <sys/eventhandler.h>
34d2bd3ab9SScott Long #include <sys/devicestat.h>
351713e81bSScott Long 
36d2bd3ab9SScott Long #include <vm/vm.h>
37d2bd3ab9SScott Long #include <vm/pmap.h>
38d2bd3ab9SScott Long #include <vm/vm_extern.h>
39d2bd3ab9SScott Long 
401713e81bSScott Long #include <machine/bus.h>
411713e81bSScott Long #include <machine/resource.h>
421713e81bSScott Long #include <machine/bus.h>
43d2bd3ab9SScott Long 
441713e81bSScott Long #include <sys/rman.h>
451713e81bSScott Long 
461713e81bSScott Long #include <cam/cam.h>
471713e81bSScott Long #include <cam/cam_ccb.h>
481713e81bSScott Long #include <cam/cam_debug.h>
491713e81bSScott Long #include <cam/cam_sim.h>
501713e81bSScott Long #include <cam/cam_xpt_sim.h>
511713e81bSScott Long #include <cam/cam_periph.h>
52d2bd3ab9SScott Long 
531713e81bSScott Long #include <cam/scsi/scsi_all.h>
541713e81bSScott Long #include <cam/scsi/scsi_message.h>
551713e81bSScott Long 
56d2bd3ab9SScott Long 
57d2bd3ab9SScott Long 
581713e81bSScott Long typedef struct
591713e81bSScott Long {
601713e81bSScott Long 	UCHAR		status;     		/* 0 nonbootable; 80h bootable */
611713e81bSScott Long 	UCHAR      	start_head;
621713e81bSScott Long 	USHORT     	start_sector;
631713e81bSScott Long 	UCHAR      	type;
641713e81bSScott Long 	UCHAR      	end_head;
651713e81bSScott Long 	USHORT     	end_sector;
661713e81bSScott Long 	ULONG      	start_abs_sector;
671713e81bSScott Long 	ULONG      	num_of_sector;
681713e81bSScott Long } partition;
691713e81bSScott Long 
701713e81bSScott Long typedef struct _INQUIRYDATA {
711713e81bSScott Long 	UCHAR DeviceType : 5;
721713e81bSScott Long 	UCHAR DeviceTypeQualifier : 3;
731713e81bSScott Long 	UCHAR DeviceTypeModifier : 7;
741713e81bSScott Long 	UCHAR RemovableMedia : 1;
751713e81bSScott Long 	UCHAR Versions;
761713e81bSScott Long 	UCHAR ResponseDataFormat;
771713e81bSScott Long 	UCHAR AdditionalLength;
781713e81bSScott Long 	UCHAR Reserved[2];
791713e81bSScott Long 	UCHAR SoftReset : 1;
801713e81bSScott Long 	UCHAR CommandQueue : 1;
811713e81bSScott Long 	UCHAR Reserved2 : 1;
821713e81bSScott Long 	UCHAR LinkedCommands : 1;
831713e81bSScott Long 	UCHAR Synchronous : 1;
841713e81bSScott Long 	UCHAR Wide16Bit : 1;
851713e81bSScott Long 	UCHAR Wide32Bit : 1;
861713e81bSScott Long 	UCHAR RelativeAddressing : 1;
871713e81bSScott Long 	UCHAR VendorId[8];
881713e81bSScott Long 	UCHAR ProductId[16];
891713e81bSScott Long 	UCHAR ProductRevisionLevel[4];
901713e81bSScott Long 	UCHAR VendorSpecific[20];
911713e81bSScott Long 	UCHAR Reserved3[40];
921713e81bSScott Long } INQUIRYDATA, *PINQUIRYDATA;
931713e81bSScott Long 
941713e81bSScott Long #define MV_IAL_HT_SACOALT_DEFAULT	1
951713e81bSScott Long #define MV_IAL_HT_SAITMTH_DEFAULT	1
961713e81bSScott Long 
971713e81bSScott Long /****************************************/
981713e81bSScott Long /*          GENERAL Definitions         */
991713e81bSScott Long /****************************************/
1001713e81bSScott Long 
1011713e81bSScott Long /* Bits for HD_ERROR */
1021713e81bSScott Long #define NM_ERR			0x02	/* media present */
1031713e81bSScott Long #define ABRT_ERR		0x04	/* Command aborted */
1041713e81bSScott Long #define MCR_ERR         0x08	/* media change request */
1051713e81bSScott Long #define IDNF_ERR        0x10	/* ID field not found */
1061713e81bSScott Long #define MC_ERR          0x20	/* media changed */
1071713e81bSScott Long #define UNC_ERR         0x40	/* Uncorrect data */
1081713e81bSScott Long #define WP_ERR          0x40	/* write protect */
1091713e81bSScott Long #define ICRC_ERR        0x80	/* new meaning:  CRC error during transfer */
1101713e81bSScott Long 
1111713e81bSScott Long #define REQUESTS_ARRAY_SIZE			(9 * MV_EDMA_REQUEST_QUEUE_SIZE) /* 9 K bytes */
1121713e81bSScott Long #define RESPONSES_ARRAY_SIZE		(12 * MV_EDMA_RESPONSE_QUEUE_SIZE) /* 3 K bytes */
1131713e81bSScott Long 
1141713e81bSScott Long #define PRD_ENTRIES_PER_CMD         (MAX_SG_DESCRIPTORS+1)
1151713e81bSScott Long #define PRD_ENTRIES_SIZE            (MV_EDMA_PRD_ENTRY_SIZE*PRD_ENTRIES_PER_CMD)
1161713e81bSScott Long #define PRD_TABLES_FOR_VBUS         (MV_SATA_CHANNELS_NUM*MV_EDMA_QUEUE_LENGTH)
1171713e81bSScott Long 
118d2bd3ab9SScott Long typedef enum _SataEvent
119d2bd3ab9SScott Long {
1201713e81bSScott Long     SATA_EVENT_NO_CHANGE = 0,
1211713e81bSScott Long 	SATA_EVENT_CHANNEL_CONNECTED,
1221713e81bSScott Long 	SATA_EVENT_CHANNEL_DISCONNECTED
1231713e81bSScott Long } SATA_EVENT;
1241713e81bSScott Long 
1251713e81bSScott Long typedef ULONG_PTR dma_addr_t;
1261713e81bSScott Long 
127d2bd3ab9SScott Long typedef struct _MV_CHANNEL
128d2bd3ab9SScott Long {
1291713e81bSScott Long 	unsigned int		maxUltraDmaModeSupported;
1301713e81bSScott Long 	unsigned int		maxDmaModeSupported;
1311713e81bSScott Long 	unsigned int		maxPioModeSupported;
1321713e81bSScott Long 	MV_BOOLEAN		online;
13364470755SXin LI 	MV_BOOLEAN		writeCacheSupported;
13464470755SXin LI 	MV_BOOLEAN		writeCacheEnabled;
13564470755SXin LI 	MV_BOOLEAN		readAheadSupported;
13664470755SXin LI 	MV_BOOLEAN		readAheadEnabled;
13764470755SXin LI 	MV_U8			queueDepth;
13864470755SXin LI 
1391713e81bSScott Long } MV_CHANNEL;
1401713e81bSScott Long 
141d2bd3ab9SScott Long typedef struct _BUS_DMAMAP
142d2bd3ab9SScott Long {	struct _BUS_DMAMAP 	 	*next;
143d2bd3ab9SScott Long 	struct IALAdapter 			*pAdapter;
144d2bd3ab9SScott Long 	bus_dmamap_t 			dma_map;
14549b3fc40SJohn Baldwin 	struct callout		timeout;
146d2bd3ab9SScott Long 	SCAT_GATH				psg[MAX_SG_DESCRIPTORS];
147d2bd3ab9SScott Long } BUS_DMAMAP, *PBUS_DMAMAP;
1481713e81bSScott Long 
149d2bd3ab9SScott Long typedef struct IALAdapter
150d2bd3ab9SScott Long {
1511713e81bSScott Long 	struct cam_path 	*path;
15249b3fc40SJohn Baldwin 	struct mtx		lock;
153d2bd3ab9SScott Long 
154d2bd3ab9SScott Long 	bus_dma_tag_t	  io_dma_parent; /* I/O buffer DMA tag */
155d2bd3ab9SScott Long 	PBUS_DMAMAP	  pbus_dmamap_list;
156d2bd3ab9SScott Long 	PBUS_DMAMAP	  pbus_dmamap;
157d2bd3ab9SScott Long 
1581713e81bSScott Long 	device_t			hpt_dev;				/* bus device */
1591713e81bSScott Long 	struct resource		*hpt_irq;					/* interrupt */
1601713e81bSScott Long 	struct resource		*mem_res;
161d2bd3ab9SScott Long 	void				*hpt_intr;				/* interrupt handle */
1621713e81bSScott Long 	struct IALAdapter   *next;
1631713e81bSScott Long 
1641713e81bSScott Long 	MV_SATA_ADAPTER     mvSataAdapter;
1651713e81bSScott Long 	MV_CHANNEL          mvChannel[MV_SATA_CHANNELS_NUM];
1661713e81bSScott Long 	MV_U8				*requestsArrayBaseAddr;
1671713e81bSScott Long 	MV_U8				*requestsArrayBaseAlignedAddr;
1681713e81bSScott Long 	dma_addr_t			requestsArrayBaseDmaAddr;
1691713e81bSScott Long 	dma_addr_t			requestsArrayBaseDmaAlignedAddr;
1701713e81bSScott Long 	MV_U8				*responsesArrayBaseAddr;
1711713e81bSScott Long 	MV_U8				*responsesArrayBaseAlignedAddr;
1721713e81bSScott Long 	dma_addr_t			responsesArrayBaseDmaAddr;
1731713e81bSScott Long 	dma_addr_t			responsesArrayBaseDmaAlignedAddr;
1741713e81bSScott Long 	SATA_EVENT			sataEvents[MV_SATA_CHANNELS_NUM];
1751713e81bSScott Long 
17649b3fc40SJohn Baldwin    	struct	callout event_timer_connect;
17749b3fc40SJohn Baldwin   	struct	callout event_timer_disconnect;
1781713e81bSScott Long 
1791713e81bSScott Long 	struct _VBus        VBus;
1801713e81bSScott Long 	struct _VDevice     VDevices[MV_SATA_CHANNELS_NUM];
1811713e81bSScott Long 	PCommand			pCommandBlocks;
1821713e81bSScott Long 	PUCHAR				prdTableAddr;
183d2bd3ab9SScott Long 	PUCHAR				prdTableAlignedAddr;
1841713e81bSScott Long 	void*				pFreePRDLink;
1851713e81bSScott Long 
1861713e81bSScott Long 	union ccb           *pending_Q;
1871713e81bSScott Long 
1881713e81bSScott Long 	MV_U8   			outstandingCommands;
1891713e81bSScott Long 
1901713e81bSScott Long 	UCHAR               status;
1911713e81bSScott Long 	UCHAR               ver_601;
1921713e81bSScott Long 	UCHAR               beeping;
193d2bd3ab9SScott Long }
194d2bd3ab9SScott Long IAL_ADAPTER_T;
1951713e81bSScott Long 
1961713e81bSScott Long extern IAL_ADAPTER_T *gIal_Adapter;
1971713e81bSScott Long 
1981713e81bSScott Long /*entry.c*/
1991713e81bSScott Long typedef void (*HPT_DPC)(IAL_ADAPTER_T *,void*,UCHAR);
200d2bd3ab9SScott Long 
2011713e81bSScott Long int hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags);
202d2bd3ab9SScott Long void hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray, UCHAR flags);
2031713e81bSScott Long void Check_Idle_Call(IAL_ADAPTER_T *pAdapter);
2041713e81bSScott Long void fRescanAllDevice(_VBUS_ARG0);
2051713e81bSScott Long int hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk);
2061713e81bSScott Long 
207d2bd3ab9SScott Long int Kernel_DeviceIoControl(_VBUS_ARG
208d2bd3ab9SScott Long 							DWORD dwIoControlCode,       	/* operation control code */
209d2bd3ab9SScott Long 							PVOID lpInBuffer,            	/* input data buffer */
210d2bd3ab9SScott Long 							DWORD nInBufferSize,         	/* size of input data buffer */
211d2bd3ab9SScott Long 							PVOID lpOutBuffer,           	/* output data buffer */
212d2bd3ab9SScott Long 							DWORD nOutBufferSize,        	/* size of output data buffer */
213d2bd3ab9SScott Long 							PDWORD lpBytesReturned      	/* byte count */
214d2bd3ab9SScott Long 						);
215d2bd3ab9SScott Long 
2161713e81bSScott Long 
2171713e81bSScott Long #define __str_direct(x) #x
2181713e81bSScott Long #define __str(x) __str_direct(x)
2191713e81bSScott Long #define KMSG_LEADING __str(PROC_DIR_NAME) ": "
220d2bd3ab9SScott Long #define hpt_printk(_x_) do { printf(KMSG_LEADING); printf _x_ ; } while (0)
2211713e81bSScott Long 
2221713e81bSScott Long #define DUPLICATE      0
2231713e81bSScott Long #define INITIALIZE     1
2241713e81bSScott Long #define REBUILD_PARITY 2
2251713e81bSScott Long #define VERIFY         3
2261713e81bSScott Long 
227d2bd3ab9SScott Long /***********************************************************/
228d2bd3ab9SScott Long 
2291713e81bSScott Long static __inline struct cam_periph *
hpt_get_periph(int path_id,int target_id)2301713e81bSScott Long hpt_get_periph(int path_id,int target_id)
2311713e81bSScott Long {
2321713e81bSScott Long 	struct cam_periph	*periph = NULL;
2331713e81bSScott Long     struct cam_path	*path;
2341713e81bSScott Long     int			status;
2351713e81bSScott Long 
2361713e81bSScott Long     status = xpt_create_path(&path, NULL, path_id, target_id, 0);
2371713e81bSScott Long     if (status == CAM_REQ_CMP) {
238d2bd3ab9SScott Long 		periph = cam_periph_find(path, "da");
2391713e81bSScott Long 		xpt_free_path(path);
240d2bd3ab9SScott Long 
2411713e81bSScott Long     }
2421713e81bSScott Long 	return periph;
2431713e81bSScott Long }
2441713e81bSScott Long 
245d2bd3ab9SScott Long #ifdef __i386__
246d2bd3ab9SScott Long #define BITS_PER_LONG 32
247d2bd3ab9SScott Long #define VDEV_TO_ID(pVDev) (DEVICEID)(pVDev)
248d2bd3ab9SScott Long #define ID_TO_VDEV(id) (PVDevice)(id)
249d2bd3ab9SScott Long #else /*Only support x86_64(AMD64 and EM64T)*/
250d2bd3ab9SScott Long #define BITS_PER_LONG 64
251d2bd3ab9SScott Long #define VDEV_TO_ID(pVDev) (DEVICEID)(ULONG_PTR)(pVDev)
252d2bd3ab9SScott Long #define ID_TO_VDEV(id) (PVDevice)(((ULONG_PTR)gIal_Adapter & 0xffffffff00000000) | (id))
253d2bd3ab9SScott Long #endif
254d2bd3ab9SScott Long 
255d2bd3ab9SScott Long #define INVALID_DEVICEID		(-1)
256d2bd3ab9SScott Long #define INVALID_STRIPSIZE		(-1)
257d2bd3ab9SScott Long 
258d2bd3ab9SScott Long #define shortswap(w) ((WORD)((w)>>8 | ((w) & 0xFF)<<8))
259d2bd3ab9SScott Long 
260d2bd3ab9SScott Long #ifndef MinBlockSizeShift
261d2bd3ab9SScott Long #define MinBlockSizeShift 5
262d2bd3ab9SScott Long #define MaxBlockSizeShift 12
263d2bd3ab9SScott Long #endif
264d2bd3ab9SScott Long 
265d2bd3ab9SScott Long #pragma pack(1)
266d2bd3ab9SScott Long typedef struct _HPT_IOCTL_TRANSFER_PARAM
2671713e81bSScott Long {
268d2bd3ab9SScott Long 	ULONG nInBufferSize;
269d2bd3ab9SScott Long 	ULONG nOutBufferSize;
270d2bd3ab9SScott Long 	UCHAR buffer[0];
271d2bd3ab9SScott Long }HPT_IOCTL_TRANSFER_PARAM, *PHPT_IOCTL_TRANSFER_PARAM;
2721713e81bSScott Long 
273d2bd3ab9SScott Long typedef struct _HPT_SET_STATE_PARAM
2741713e81bSScott Long {
275d2bd3ab9SScott Long 	DEVICEID idArray;
276d2bd3ab9SScott Long 	DWORD state;
277d2bd3ab9SScott Long } HPT_SET_STATE_PARAM, *PHPT_SET_STATE_PARAM;
2781713e81bSScott Long 
279d2bd3ab9SScott Long typedef struct _HPT_SET_ARRAY_INFO
2801713e81bSScott Long {
281d2bd3ab9SScott Long 	DEVICEID idArray;
282d2bd3ab9SScott Long 	ALTERABLE_ARRAY_INFO Info;
283d2bd3ab9SScott Long } HPT_SET_ARRAY_INFO, *PHPT_SET_ARRAY_INFO;
2841713e81bSScott Long 
285d2bd3ab9SScott Long typedef struct _HPT_SET_DEVICE_INFO
2861713e81bSScott Long {
287d2bd3ab9SScott Long 	DEVICEID idDisk;
288d2bd3ab9SScott Long 	ALTERABLE_DEVICE_INFO Info;
289d2bd3ab9SScott Long } HPT_SET_DEVICE_INFO, *PHPT_SET_DEVICE_INFO;
2901713e81bSScott Long 
29164470755SXin LI typedef struct _HPT_SET_DEVICE_INFO_V2
29264470755SXin LI {
29364470755SXin LI 	DEVICEID idDisk;
29464470755SXin LI 	ALTERABLE_DEVICE_INFO_V2 Info;
29564470755SXin LI } HPT_SET_DEVICE_INFO_V2, *PHPT_SET_DEVICE_INFO_V2;
29664470755SXin LI 
297d2bd3ab9SScott Long typedef struct _HPT_ADD_DISK_TO_ARRAY
2981713e81bSScott Long {
299d2bd3ab9SScott Long 	DEVICEID idArray;
300d2bd3ab9SScott Long 	DEVICEID idDisk;
301d2bd3ab9SScott Long } HPT_ADD_DISK_TO_ARRAY, *PHPT_ADD_DISK_TO_ARRAY;
3021713e81bSScott Long 
30364470755SXin LI typedef struct _HPT_DEVICE_IO
30464470755SXin LI {
30564470755SXin LI 	DEVICEID	id;
30664470755SXin LI 	int			cmd;
30764470755SXin LI 	ULONG		lba;
30864470755SXin LI 	DWORD		nSector;
30964470755SXin LI 	UCHAR		buffer[0];
31064470755SXin LI } HPT_DEVICE_IO, *PHPT_DEVICE_IO;
31164470755SXin LI 
312d2bd3ab9SScott Long int check_VDevice_valid(PVDevice);
313d2bd3ab9SScott Long int hpt_default_ioctl(_VBUS_ARG DWORD, PVOID, DWORD, PVOID, DWORD, PDWORD);
3141713e81bSScott Long 
315d2bd3ab9SScott Long #define HPT_NULL_ID 0
3161713e81bSScott Long 
317d2bd3ab9SScott Long #pragma pack()
3181713e81bSScott Long 
3191713e81bSScott Long #endif
320