xref: /freebsd/sys/dev/hptmv/osbsd.h (revision 1713e81b9cdf06d2a9a365a7ded13a54fad84798)
11713e81bSScott Long /*
21713e81bSScott Long  * Copyright (c) 2003-2004 HighPoint Technologies, Inc.
31713e81bSScott Long  * All rights reserved.
41713e81bSScott Long  *
51713e81bSScott Long  * Redistribution and use in source and binary forms, with or without
61713e81bSScott Long  * modification, are permitted provided that the following conditions
71713e81bSScott Long  * are met:
81713e81bSScott Long  * 1. Redistributions of source code must retain the above copyright
91713e81bSScott Long  *    notice, this list of conditions and the following disclaimer.
101713e81bSScott Long  * 2. Redistributions in binary form must reproduce the above copyright
111713e81bSScott Long  *    notice, this list of conditions and the following disclaimer in the
121713e81bSScott Long  *    documentation and/or other materials provided with the distribution.
131713e81bSScott Long  *
141713e81bSScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151713e81bSScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161713e81bSScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171713e81bSScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181713e81bSScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191713e81bSScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201713e81bSScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211713e81bSScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221713e81bSScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231713e81bSScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241713e81bSScott Long  * SUCH DAMAGE.
251713e81bSScott Long  *
261713e81bSScott Long  * $FreeBSD$
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>
341713e81bSScott Long 
351713e81bSScott Long #include <machine/bus_memio.h>
361713e81bSScott Long #include <machine/bus.h>
371713e81bSScott Long #include <machine/resource.h>
381713e81bSScott Long #include <machine/bus.h>
391713e81bSScott Long #include <sys/rman.h>
401713e81bSScott Long 
411713e81bSScott Long #include <cam/cam.h>
421713e81bSScott Long #include <cam/cam_ccb.h>
431713e81bSScott Long #include <cam/cam_debug.h>
441713e81bSScott Long #include <cam/cam_sim.h>
451713e81bSScott Long #include <cam/cam_xpt_sim.h>
461713e81bSScott Long #include <cam/cam_periph.h>
471713e81bSScott Long #include <cam/scsi/scsi_all.h>
481713e81bSScott Long #include <cam/scsi/scsi_message.h>
491713e81bSScott Long 
501713e81bSScott Long extern intrmask_t lock_driver(void);
511713e81bSScott Long extern void unlock_driver(intrmask_t spl);
521713e81bSScott Long 
531713e81bSScott Long typedef struct
541713e81bSScott Long {
551713e81bSScott Long 	UCHAR		status;		/* 0 nonbootable; 80h bootable */
561713e81bSScott Long 	UCHAR      	start_head;
571713e81bSScott Long 	USHORT     	start_sector;
581713e81bSScott Long 	UCHAR      	type;
591713e81bSScott Long 	UCHAR      	end_head;
601713e81bSScott Long 	USHORT     	end_sector;
611713e81bSScott Long 	ULONG      	start_abs_sector;
621713e81bSScott Long 	ULONG      	num_of_sector;
631713e81bSScott Long } partition;
641713e81bSScott Long 
651713e81bSScott Long typedef struct _INQUIRYDATA {
661713e81bSScott Long 	UCHAR DeviceType : 5;
671713e81bSScott Long 	UCHAR DeviceTypeQualifier : 3;
681713e81bSScott Long 	UCHAR DeviceTypeModifier : 7;
691713e81bSScott Long 	UCHAR RemovableMedia : 1;
701713e81bSScott Long 	UCHAR Versions;
711713e81bSScott Long 	UCHAR ResponseDataFormat;
721713e81bSScott Long 	UCHAR AdditionalLength;
731713e81bSScott Long 	UCHAR Reserved[2];
741713e81bSScott Long 	UCHAR SoftReset : 1;
751713e81bSScott Long 	UCHAR CommandQueue : 1;
761713e81bSScott Long 	UCHAR Reserved2 : 1;
771713e81bSScott Long 	UCHAR LinkedCommands : 1;
781713e81bSScott Long 	UCHAR Synchronous : 1;
791713e81bSScott Long 	UCHAR Wide16Bit : 1;
801713e81bSScott Long 	UCHAR Wide32Bit : 1;
811713e81bSScott Long 	UCHAR RelativeAddressing : 1;
821713e81bSScott Long 	UCHAR VendorId[8];
831713e81bSScott Long 	UCHAR ProductId[16];
841713e81bSScott Long 	UCHAR ProductRevisionLevel[4];
851713e81bSScott Long 	UCHAR VendorSpecific[20];
861713e81bSScott Long 	UCHAR Reserved3[40];
871713e81bSScott Long } INQUIRYDATA, *PINQUIRYDATA;
881713e81bSScott Long 
891713e81bSScott Long typedef struct _READ_CAPACITY_DATA {
901713e81bSScott Long 	ULONG LogicalBlockAddress;
911713e81bSScott Long 	ULONG BytesPerBlock;
921713e81bSScott Long } READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA;
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 
1181713e81bSScott Long typedef enum _SataEvent {
1191713e81bSScott Long     SATA_EVENT_NO_CHANGE = 0,
1201713e81bSScott Long 	SATA_EVENT_CHANNEL_CONNECTED,
1211713e81bSScott Long 	SATA_EVENT_CHANNEL_DISCONNECTED
1221713e81bSScott Long } SATA_EVENT;
1231713e81bSScott Long 
1241713e81bSScott Long typedef ULONG_PTR dma_addr_t;
1251713e81bSScott Long 
1261713e81bSScott Long typedef struct _MV_CHANNEL {
1271713e81bSScott Long 	unsigned int		maxUltraDmaModeSupported;
1281713e81bSScott Long 	unsigned int		maxDmaModeSupported;
1291713e81bSScott Long 	unsigned int		maxPioModeSupported;
1301713e81bSScott Long 	MV_BOOLEAN		online;
1311713e81bSScott Long } MV_CHANNEL;
1321713e81bSScott Long 
1331713e81bSScott Long struct _privCommand;
1341713e81bSScott Long 
1351713e81bSScott Long typedef struct IALAdapter {
1361713e81bSScott Long 	struct cam_path 	*path;
1371713e81bSScott Long 	device_t		hpt_dev;		/* bus device */
1381713e81bSScott Long 	struct resource		*hpt_irq;		/* interrupt */
1391713e81bSScott Long 	void			*hpt_intr;		/* interrupt handle */
1401713e81bSScott Long 	struct resource		*mem_res;
1411713e81bSScott Long 	bus_space_handle_t	mem_bsh;
1421713e81bSScott Long 	bus_space_tag_t		mem_btag;
1431713e81bSScott Long 	bus_dma_tag_t		parent_dmat;
1441713e81bSScott Long 	bus_dma_tag_t		req_dmat;
1451713e81bSScott Long 	bus_dmamap_t		req_map;
1461713e81bSScott Long 	bus_dma_tag_t		resp_dmat;
1471713e81bSScott Long 	bus_dmamap_t		resp_map;
1481713e81bSScott Long 	bus_dma_tag_t		prd_dmat;
1491713e81bSScott Long 	bus_dmamap_t		prd_map;
1501713e81bSScott Long 	bus_dma_tag_t		buf_dmat;
1511713e81bSScott Long 
1521713e81bSScott Long 	struct IALAdapter	*next;
1531713e81bSScott Long 
1541713e81bSScott Long 	MV_SATA_ADAPTER		mvSataAdapter;
1551713e81bSScott Long 	MV_CHANNEL		mvChannel[MV_SATA_CHANNELS_NUM];
1561713e81bSScott Long 	MV_U8			*requestsArrayBaseAddr;
1571713e81bSScott Long 	MV_U8			*requestsArrayBaseAlignedAddr;
1581713e81bSScott Long 	dma_addr_t		requestsArrayBaseDmaAddr;
1591713e81bSScott Long 	dma_addr_t		requestsArrayBaseDmaAlignedAddr;
1601713e81bSScott Long 	MV_U8			*responsesArrayBaseAddr;
1611713e81bSScott Long 	MV_U8			*responsesArrayBaseAlignedAddr;
1621713e81bSScott Long 	dma_addr_t		responsesArrayBaseDmaAddr;
1631713e81bSScott Long 	dma_addr_t		responsesArrayBaseDmaAlignedAddr;
1641713e81bSScott Long 	SATA_EVENT		sataEvents[MV_SATA_CHANNELS_NUM];
1651713e81bSScott Long 
1661713e81bSScott Long    	struct	callout_handle event_timer_connect;
1671713e81bSScott Long   	struct	callout_handle event_timer_disconnect;
1681713e81bSScott Long 
1691713e81bSScott Long 	struct _VBus		VBus;
1701713e81bSScott Long 	struct _VDevice		VDevices[MV_SATA_CHANNELS_NUM];
1711713e81bSScott Long 	PCommand		pCommandBlocks;
1721713e81bSScott Long 	struct _privCommand	*pPrivateBlocks;
1731713e81bSScott Long 	TAILQ_HEAD(, _privCommand)	PrivCmdTQH;
1741713e81bSScott Long 	PUCHAR			prdTableAddr;
1751713e81bSScott Long 	ULONG			prdTableDmaAddr;
1761713e81bSScott Long 	void*			pFreePRDLink;
1771713e81bSScott Long 
1781713e81bSScott Long 	union ccb		*pending_Q;
1791713e81bSScott Long 
1801713e81bSScott Long 	MV_U8   		outstandingCommands;
1811713e81bSScott Long 
1821713e81bSScott Long 	UCHAR			status;
1831713e81bSScott Long 	UCHAR			ver_601;
1841713e81bSScott Long 	UCHAR			beeping;
1851713e81bSScott Long 
1861713e81bSScott Long 	eventhandler_tag	eh;
1871713e81bSScott Long } IAL_ADAPTER_T;
1881713e81bSScott Long 
1891713e81bSScott Long typedef struct _privCommand {
1901713e81bSScott Long 	TAILQ_ENTRY(_privCommand)	PrivEntry;
1911713e81bSScott Long 	IAL_ADAPTER_T			*pAdapter;
1921713e81bSScott Long 	union ccb			*ccb;
1931713e81bSScott Long 	bus_dmamap_t			buf_map;
1941713e81bSScott Long } *pPrivCommand;
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);
2001713e81bSScott Long int hpt_queue_dpc(HPT_DPC dpc, IAL_ADAPTER_T *pAdapter, void *arg, UCHAR flags);
2011713e81bSScott Long void hpt_rebuild_data_block(IAL_ADAPTER_T *pAdapter, PVDevice pArray,
2021713e81bSScott Long     UCHAR flags);
2031713e81bSScott Long void Check_Idle_Call(IAL_ADAPTER_T *pAdapter);
2041713e81bSScott Long int Kernel_DeviceIoControl(_VBUS_ARG DWORD dwIoControlCode, PVOID lpInBuffer,
2051713e81bSScott Long     DWORD nInBufferSize, PVOID lpOutBuffer, DWORD nOutBufferSize,
2061713e81bSScott Long     PDWORD lpBytesReturned);
2071713e81bSScott Long void fRescanAllDevice(_VBUS_ARG0);
2081713e81bSScott Long int hpt_add_disk_to_array(_VBUS_ARG DEVICEID idArray, DEVICEID idDisk);
2091713e81bSScott Long 
2101713e81bSScott Long 
2111713e81bSScott Long #define __str_direct(x) #x
2121713e81bSScott Long #define __str(x) __str_direct(x)
2131713e81bSScott Long #define KMSG_LEADING __str(PROC_DIR_NAME) ": "
2141713e81bSScott Long #define hpt_printk(_x_) do {	\
2151713e81bSScott Long 	printf(KMSG_LEADING);	\
2161713e81bSScott Long 	printf _x_ ;		\
2171713e81bSScott Long } while (0)
2181713e81bSScott Long 
2191713e81bSScott Long #define DUPLICATE      0
2201713e81bSScott Long #define INITIALIZE     1
2211713e81bSScott Long #define REBUILD_PARITY 2
2221713e81bSScott Long #define VERIFY         3
2231713e81bSScott Long 
2241713e81bSScott Long extern char DRIVER_VERSION[];
2251713e81bSScott Long /**********************************************************/
2261713e81bSScott Long static __inline struct cam_periph *
2271713e81bSScott Long hpt_get_periph(int path_id,int target_id)
2281713e81bSScott Long {
2291713e81bSScott Long 	struct cam_periph *periph = NULL;
2301713e81bSScott Long 	struct cam_path	*path;
2311713e81bSScott Long 	int status;
2321713e81bSScott Long 
2331713e81bSScott Long 	status = xpt_create_path(&path, NULL, path_id, target_id, 0);
2341713e81bSScott Long 	if (status == CAM_REQ_CMP) {
2351713e81bSScott Long 		periph = cam_periph_find(path, NULL);
2361713e81bSScott Long 		xpt_free_path(path);
2371713e81bSScott Long 		if (periph != NULL) {
2381713e81bSScott Long 			if (strncmp(periph->periph_name, "da", 2))
2391713e81bSScott Long 				periph = NULL;
2401713e81bSScott Long     		}
2411713e81bSScott Long     	}
2421713e81bSScott Long 	return periph;
2431713e81bSScott Long }
2441713e81bSScott Long 
2451713e81bSScott Long static __inline void
2461713e81bSScott Long FreePrivCommand(IAL_ADAPTER_T *pAdapter, pPrivCommand prvCmd)
2471713e81bSScott Long {
2481713e81bSScott Long 	TAILQ_INSERT_TAIL(&pAdapter->PrivCmdTQH, prvCmd, PrivEntry);
2491713e81bSScott Long }
2501713e81bSScott Long 
2511713e81bSScott Long static __inline pPrivCommand
2521713e81bSScott Long AllocPrivCommand(IAL_ADAPTER_T *pAdapter)
2531713e81bSScott Long {
2541713e81bSScott Long 	pPrivCommand prvCmd;
2551713e81bSScott Long 
2561713e81bSScott Long 	prvCmd = TAILQ_FIRST(&pAdapter->PrivCmdTQH);
2571713e81bSScott Long 	if (prvCmd == NULL)
2581713e81bSScott Long 		return NULL;
2591713e81bSScott Long 
2601713e81bSScott Long 	TAILQ_REMOVE(&pAdapter->PrivCmdTQH, prvCmd, PrivEntry);
2611713e81bSScott Long 	return (prvCmd);
2621713e81bSScott Long }
2631713e81bSScott Long 
2641713e81bSScott Long static __inline void
2651713e81bSScott Long mv_reg_write_byte(MV_BUS_ADDR_T base, MV_U32 offset, MV_U8 val)
2661713e81bSScott Long {
2671713e81bSScott Long 	IAL_ADAPTER_T *pAdapter;
2681713e81bSScott Long 
2691713e81bSScott Long 	pAdapter = base;
2701713e81bSScott Long 	bus_space_write_1(pAdapter->mem_btag, pAdapter->mem_bsh, offset, val);
2711713e81bSScott Long }
2721713e81bSScott Long 
2731713e81bSScott Long static __inline void
2741713e81bSScott Long mv_reg_write_word(MV_BUS_ADDR_T base, MV_U32 offset, MV_U16 val)
2751713e81bSScott Long {
2761713e81bSScott Long 	IAL_ADAPTER_T *pAdapter;
2771713e81bSScott Long 
2781713e81bSScott Long 	pAdapter = base;
2791713e81bSScott Long 	bus_space_write_2(pAdapter->mem_btag, pAdapter->mem_bsh, offset, val);
2801713e81bSScott Long }
2811713e81bSScott Long 
2821713e81bSScott Long static __inline void
2831713e81bSScott Long mv_reg_write_dword(MV_BUS_ADDR_T base, MV_U32 offset, MV_U32 val)
2841713e81bSScott Long {
2851713e81bSScott Long 	IAL_ADAPTER_T *pAdapter;
2861713e81bSScott Long 
2871713e81bSScott Long 	pAdapter = base;
2881713e81bSScott Long 	bus_space_write_4(pAdapter->mem_btag, pAdapter->mem_bsh, offset, val);
2891713e81bSScott Long }
2901713e81bSScott Long 
2911713e81bSScott Long static __inline MV_U8
2921713e81bSScott Long mv_reg_read_byte(MV_BUS_ADDR_T base, MV_U32 offset)
2931713e81bSScott Long {
2941713e81bSScott Long 	IAL_ADAPTER_T *pAdapter;
2951713e81bSScott Long 
2961713e81bSScott Long 	pAdapter = base;
2971713e81bSScott Long 	return (bus_space_read_1(pAdapter->mem_btag, pAdapter->mem_bsh,
2981713e81bSScott Long 	    offset));
2991713e81bSScott Long }
3001713e81bSScott Long 
3011713e81bSScott Long static __inline MV_U16
3021713e81bSScott Long mv_reg_read_word(MV_BUS_ADDR_T base, MV_U32 offset)
3031713e81bSScott Long {
3041713e81bSScott Long 	IAL_ADAPTER_T *pAdapter;
3051713e81bSScott Long 
3061713e81bSScott Long 	pAdapter = base;
3071713e81bSScott Long 	return (bus_space_read_2(pAdapter->mem_btag, pAdapter->mem_bsh,
3081713e81bSScott Long 	    offset));
3091713e81bSScott Long }
3101713e81bSScott Long 
3111713e81bSScott Long static __inline MV_U32
3121713e81bSScott Long mv_reg_read_dword(MV_BUS_ADDR_T base, MV_U32 offset)
3131713e81bSScott Long {
3141713e81bSScott Long 	IAL_ADAPTER_T *pAdapter;
3151713e81bSScott Long 
3161713e81bSScott Long 	pAdapter = base;
3171713e81bSScott Long 	return (bus_space_read_4(pAdapter->mem_btag, pAdapter->mem_bsh,
3181713e81bSScott Long 	    offset));
3191713e81bSScott Long }
3201713e81bSScott Long 
3211713e81bSScott Long #endif
322