xref: /onnv-gate/usr/src/uts/common/sys/sata/impl/sata.h (revision 3935:0767d871beb3)
11258Smlf /*
21258Smlf  * CDDL HEADER START
31258Smlf  *
41258Smlf  * The contents of this file are subject to the terms of the
51258Smlf  * Common Development and Distribution License (the "License").
61258Smlf  * You may not use this file except in compliance with the License.
71258Smlf  *
81258Smlf  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91258Smlf  * or http://www.opensolaris.org/os/licensing.
101258Smlf  * See the License for the specific language governing permissions
111258Smlf  * and limitations under the License.
121258Smlf  *
131258Smlf  * When distributing Covered Code, include this CDDL HEADER in each
141258Smlf  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151258Smlf  * If applicable, add the following below this CDDL HEADER, with the
161258Smlf  * fields enclosed by brackets "[]" replaced with your own identifying
171258Smlf  * information: Portions Copyright [yyyy] [name of copyright owner]
181258Smlf  *
191258Smlf  * CDDL HEADER END
201258Smlf  */
211258Smlf 
221258Smlf /*
233821Sls24207  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
241258Smlf  * Use is subject to license terms.
251258Smlf  */
261258Smlf 
271258Smlf #ifndef _SATA_H
281258Smlf #define	_SATA_H
291258Smlf 
301258Smlf #pragma ident	"%Z%%M%	%I%	%E% SMI"
311258Smlf 
321258Smlf #ifdef	__cplusplus
331258Smlf extern "C" {
341258Smlf #endif
351258Smlf 
361258Smlf /*
371258Smlf  * Generic SATA Host Adapter Implementation
381258Smlf  */
391258Smlf 
401258Smlf #include <sys/types.h>
411258Smlf #include <sys/scsi/scsi.h>
421258Smlf #include <sys/scsi/impl/services.h>
431258Smlf #include <sys/sata/sata_defs.h>
441258Smlf #include <sys/sata/sata_hba.h>
451258Smlf 
461258Smlf /* Statistics counters */
471258Smlf struct sata_port_stats {
481258Smlf 	uint64_t	link_lost;		/* event counter */
491258Smlf 	uint64_t	link_established;	/* event counter */
501258Smlf 	uint64_t	device_attached;	/* event counter */
511258Smlf 	uint64_t	device_detached;	/* event counter */
521258Smlf 	uint64_t	port_reset;		/* event counter */
531258Smlf 	uint64_t	port_pwr_changed;	/* event counter */
541258Smlf };
551258Smlf 
561258Smlf typedef struct sata_port_stats sata_port_stats_t;
571258Smlf 
581258Smlf struct sata_drive_stats {
591258Smlf 	uint64_t	media_error;		/* available ??? */
601258Smlf 	uint64_t	drive_reset;		/* event counter */
611258Smlf } sata_drv_stats_t;
621258Smlf 
631258Smlf typedef struct sata_drive_stats sata_drive_stats_t;
641258Smlf 
651258Smlf struct sata_ctrl_stats {
661258Smlf 	uint64_t	ctrl_reset;		/* event counter */
671258Smlf 	uint64_t	ctrl_pwr_change;	/* event counter */
681258Smlf };
691258Smlf 
701258Smlf typedef struct sata_ctrl_stats sata_ctrl_stats_t;
711258Smlf 
721258Smlf 
731258Smlf /*
741258Smlf  * SATA HBA instance info structure
751258Smlf  */
761258Smlf struct sata_hba_inst {
771258Smlf 	dev_info_t		*satahba_dip;	/* this HBA instance devinfo */
781258Smlf 	struct sata_hba_inst	*satahba_next;	/* ptr to next sata_hba_inst */
791258Smlf 	struct sata_hba_inst	*satahba_prev;	/* ptr to prev sata_hba_inst */
801258Smlf 	struct scsi_hba_tran	*satahba_scsi_tran; /* scsi_hba_tran */
811258Smlf 	struct sata_hba_tran	*satahba_tran;	/* sata_hba_tran */
821258Smlf 	kmutex_t		satahba_mutex;	/* sata hba cntrl mutex */
831781Spawelw 	struct taskq		*satahba_taskq;	/* cmd completion task queue */
841258Smlf 
851258Smlf 						/*
861258Smlf 						 * HBA event flags:
871258Smlf 						 * SATA_EVNT_MAIN
881258Smlf 						 * SATA_EVNT_PWR_LEVEL_CHANGED
891258Smlf 						 * SATA_EVNT_SKIP
901258Smlf 						 */
911258Smlf 	uint_t			satahba_event_flags;
921258Smlf 
931258Smlf 	struct sata_cport_info	*satahba_dev_port[SATA_MAX_CPORTS];
941258Smlf 
951258Smlf 						/*
961258Smlf 						 * DEVCTL open flag:
971258Smlf 						 * SATA_DEVCTL_SOPENED
981258Smlf 						 * SATA_DEVCTL_EXOPENED
991258Smlf 						 */
1001258Smlf 	uint_t			satahba_open_flag; /* shared open flag */
1011258Smlf 	struct sata_ctrl_stats	satahba_stats;	/* HBA cntrl statistics */
1021258Smlf 
1031258Smlf 	uint_t			satahba_attached; /* HBA attaching: */
1041258Smlf 						/* 0 - not completed */
1051258Smlf 						/* 1 - completed */
1061258Smlf };
1071258Smlf 
1081258Smlf typedef struct sata_hba_inst	sata_hba_inst_t;
1091258Smlf 
1101258Smlf /*
1111258Smlf  * SATA controller's device port info and state.
1121258Smlf  * This structure is pointed to by the sata_hba_inst.satahba_dev_port[x]
1131258Smlf  * where x is a device port number.
1141258Smlf  * cport_state holds port state flags, defined in sata_hba.h file.
1151258Smlf  * cport_event_flags holds SATA_EVNT_* flags defined in this file and in
1161258Smlf  * sata_hba.h file.
1171258Smlf  * cport_dev_type holds SATA_DTYPE_* types defined in sata_hba.h file.
1181258Smlf  */
1191258Smlf struct sata_cport_info {
1201258Smlf 	sata_address_t		cport_addr;	/* this port SATA address */
1211258Smlf 	kmutex_t		cport_mutex;	/* port mutex */
1221258Smlf 
1231258Smlf 						/*
1241258Smlf 						 * Port state flags
1251258Smlf 						 * SATA_STATE_UNKNOWN
1261258Smlf 						 * SATA_STATE_PROBING
1271258Smlf 						 * SATA_STATE_PROBED
1281258Smlf 						 * SATA_STATE_READY
1291258Smlf 						 * SATA_PSTATE_PWRON
1301258Smlf 						 * SATA_PSTATE_PWROFF
1311258Smlf 						 * SATA_PSTATE_SHUTDOWN
1321258Smlf 						 * SATA_PSTATE_FAILED
1331258Smlf 						 */
1341258Smlf 	uint32_t		cport_state;
1351258Smlf 
1361258Smlf 						/*
1371258Smlf 						 * Port event flags:
1381258Smlf 						 * SATA_EVNT_DEVICE_ATTACHED
1391258Smlf 						 * SATA_EVNT_DEVICE_DETACHED
1401258Smlf 						 * SATA_EVNT_LINK_LOST
1411258Smlf 						 * SATA_EVNT_LINK_ESTABLISHED
1421258Smlf 						 * SATA_EVNT_PORT_FAILED
1431258Smlf 						 * SATA_EVNT_PWR_LEVEL_CHANGED
1441258Smlf 						 */
1451258Smlf 	uint32_t		cport_event_flags;
1461258Smlf 
1471258Smlf 	struct sata_port_scr	cport_scr;	/* Port status and ctrl regs */
1481258Smlf 
1491258Smlf 						/*
1501258Smlf 						 * Attached device type:
1511258Smlf 						 * SATA_DTYPE_NONE
1521258Smlf 						 * SATA_DTYPE_ATADISK
1531258Smlf 						 * SATA_DTYPE_ATAPICD
1541258Smlf 						 * SATA_DTYPE_ATAPINONCD
1551258Smlf 						 * SATA_DTYPE_PMULT
1561258Smlf 						 * SATA_DTYPE_UNKNOWN
1571258Smlf 						 */
1581258Smlf 	uint32_t		cport_dev_type;
1591258Smlf 	union {
1601258Smlf 	    struct sata_drive_info *cport_sata_drive; /* Attached drive info */
1611258Smlf 	    struct sata_pmult_info *cport_sata_pmult; /* Attached Port Mult */
1621258Smlf 	} 			cport_devp;
1631258Smlf 						/* lbolt value at link lost */
1641258Smlf 	clock_t			cport_link_lost_time;
1652960Spawelw 						/* lbolt value @ dev attached */
1662960Spawelw 	clock_t			cport_dev_attach_time;
1671258Smlf 
1681258Smlf 	struct sata_port_stats	cport_stats;	/* Port statistics */
169*3935Spawelw 
170*3935Spawelw 	boolean_t		cport_tgtnode_clean; /* Target node usable */
1711258Smlf };
1721258Smlf 
1731258Smlf typedef struct sata_cport_info sata_cport_info_t;
1741258Smlf 
1751258Smlf /*
1761258Smlf  * Attached SATA drive info and state.
1771258Smlf  * This structure is pointed to by sata_cport_info's cport_sata_drive field
1781258Smlf  * when a drive is attached directly to a controller device port.
1791258Smlf  */
1801258Smlf struct sata_drive_info {
1811258Smlf 	sata_address_t	satadrv_addr;		/* this drive SATA address */
1821258Smlf 
1831258Smlf 						/*
1841258Smlf 						 * Drive state flags
1851258Smlf 						 * SATA_STATE_UNKNOWN
1861258Smlf 						 * SATA_STATE_PROBING
1871258Smlf 						 * SATA_STATE_PROBED
1881258Smlf 						 * SATA_STATE_READY
1891258Smlf 						 * SATA_DSTATE_PWR_ACTIVE
1901258Smlf 						 * SATA_DSTATE_PWR_IDLE
1911258Smlf 						 * SATA_DSTATE_RESET
1921258Smlf 						 * SATA_DSTATE_FAILED
1931258Smlf 						 */
1941258Smlf 	uint32_t	satadrv_state;
1951258Smlf 
1961258Smlf 						/*
1971258Smlf 						 * drive event flags:
1981258Smlf 						 * SATA_EVNT_DRIVE_RESET
1991258Smlf 						 */
2001258Smlf 	uint32_t	satadrv_event_flags;
2011258Smlf 
2021258Smlf 						/*
2031258Smlf 						 * Attached device type:
2041258Smlf 						 * SATA_DTYPE_ATADISK
2051258Smlf 						 * SATA_DTYPE_ATAPICD
2061258Smlf 						 * SATA_DTYPE_ATAPINONCD
2071258Smlf 						 */
2081258Smlf 	uint32_t	satadrv_type;
2091258Smlf 
2101258Smlf 	uint32_t	satadrv_status_reg;	/* drive status reg */
2111258Smlf 	uint32_t	satadrv_error_reg;	/* drive error reg */
2121258Smlf 	uint16_t	satadrv_features_support; /* drive features support */
2131258Smlf 	uint16_t	satadrv_queue_depth;    /* drive queue depth */
2141258Smlf 	uint16_t	satadrv_settings;	/* drive settings flags */
2153821Sls24207 	uint16_t	satadrv_features_enabled; /* drive features enabled */
2161258Smlf 	uint64_t	satadrv_capacity;	/* drive capacity */
2171258Smlf 	sata_id_t	satadrv_id;		/* Device Identify Data */
2181258Smlf 	struct sata_drive_stats satadrv_stats;	/* drive statistics */
2191258Smlf };
2201258Smlf 
2211258Smlf typedef struct sata_drive_info sata_drive_info_t;
2221258Smlf 
2231258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_drive_info))
2241258Smlf 
2251258Smlf 
2261258Smlf /* Port Multiplier & host port info and state */
2271258Smlf struct sata_pmult_info {
2281258Smlf 	sata_address_t	pmult_addr;		/* this PMult SATA Address */
2291258Smlf 	kmutex_t	pmult_mutex;		/* pmult (host port) mutex */
2301258Smlf 
2311258Smlf 						/*
2321258Smlf 						 * PMult state flags
2331258Smlf 						 * SATA_STATE_UNKNOWN
2341258Smlf 						 * SATA_STATE_PROBING
2351258Smlf 						 * SATA_STATE_PROBED
2361258Smlf 						 * SATA_STATE_READY
2371258Smlf 						 * SATA_PSTATE_FAILED
2381258Smlf 						 */
2391258Smlf 	uint32_t	pmult_state;
2401258Smlf 	uint32_t	pmult_event_flags;	/* Undefined for now */
2411258Smlf 	struct sata_port_scr pmult_scr;		/* Host port SCR block */
2421258Smlf 	uint32_t	pmult_num_dev_ports; 	/* Number of data ports */
2431258Smlf 	struct sata_pmport_info	*pmult_dev_port[SATA_MAX_PMPORTS - 1];
2441258Smlf };
2451258Smlf 
2461258Smlf typedef	struct sata_pmult_info sata_pmult_info_t;
2471258Smlf 
2481258Smlf /* Port Multiplier's device port info & state */
2491258Smlf struct sata_pmport_info {
2501258Smlf 	sata_address_t	pmport_addr;		/* this SATA port address */
2511258Smlf 	kmutex_t	pmport_mutex;		/* pmult device port mutex */
2521258Smlf 
2531258Smlf 						/*
2541258Smlf 						 * Port state flags
2551258Smlf 						 * SATA_STATE_UNKNOWN
2561258Smlf 						 * SATA_STATE_PROBING
2571258Smlf 						 * SATA_STATE_PROBED
2581258Smlf 						 * SATA_STATE_READY
2591258Smlf 						 * SATA_PSTATE_PWRON
2601258Smlf 						 * SATA_PSTATE_PWROFF
2611258Smlf 						 * SATA_PSTATE_SHUTDOWN
2621258Smlf 						 * SATA_PSTATE_FAILED
2631258Smlf 						 */
2641258Smlf 	uint32_t	pmport_state;
2651258Smlf 
2661258Smlf 						/*
2671258Smlf 						 * Port event flags:
2681258Smlf 						 * SATA_EVNT_DEVICE_ATTACHED
2691258Smlf 						 * SATA_EVNT_DEVICE_DETACHED
2701258Smlf 						 * SATA_EVNT_LINK_LOST
2711258Smlf 						 * SATA_EVNT_LINK_ESTABLISHED
2721258Smlf 						 * SATA_EVNT_PORT_FAILED
2731258Smlf 						 * SATA_EVNT_PWR_LEVEL_CHANGED
2741258Smlf 						 */
2751258Smlf 	uint32_t	pmport_event_flags;
2761258Smlf 
2771258Smlf 	struct sata_port_scr pmport_scr;	/* PMult device port scr */
2781258Smlf 
2791258Smlf 						/*
2801258Smlf 						 * Attached device type:
2811258Smlf 						 * SATA_DTYPE_NONE
2821258Smlf 						 * SATA_DTYPE_ATADISK
2831258Smlf 						 * SATA_DTYPE_ATAPICD
2841258Smlf 						 * SATA_DTYPE_ATAPINONCD
2851258Smlf 						 * SATA_DTYPE_UNKNOWN
2861258Smlf 						 */
2871258Smlf 	uint32_t	pmport_dev_type;
2881258Smlf 
2891258Smlf 	struct sata_drive_info	*pmport_sata_drive; /* Attached drive info */
2901258Smlf 
2911258Smlf 						/* lbolt value at link lost */
2921258Smlf 	clock_t		pmport_link_lost_time;
2932960Spawelw 						/* lbolt value @ dev attached */
2942960Spawelw 	clock_t		pmport_dev_attach_time;
2951258Smlf 
2961258Smlf 	struct sata_port_stats	pmport_stats;	/* Port statistics */
297*3935Spawelw 
298*3935Spawelw 	boolean_t	pmport_tgtnode_clean;	/* Target node usable */
2991258Smlf };
3001258Smlf 
3011258Smlf typedef	struct sata_pmport_info sata_pmport_info_t;
3021258Smlf 
3031258Smlf /*
3041258Smlf  * Port SSTATUS register (sata_port_scr sport_sstatus field).
3051258Smlf  * Link bits are valid only in port active state.
3061258Smlf  */
3071258Smlf #define	SATA_PORT_DEVLINK_UP	0x00000103	/* Link with dev established */
3081258Smlf #define	SATA_PORT_DEVLINK_UP_MASK 0x0000010F	/* Mask for link bits */
3091258Smlf 
3101258Smlf /*
3111258Smlf  * Port state clear mask (cport_state and pmport_state fields).
3121258Smlf  * SATA_PSTATE_SHUTDOWN and power state are preserved.
3131258Smlf  */
3141258Smlf #define	SATA_PORT_STATE_CLEAR_MASK	(~(SATA_PSTATE_SHUTDOWN))
3151258Smlf 
3161258Smlf /*
3171258Smlf  * Valid i.e.supported device types mask (cport_dev_type, satadrv_type,
3181258Smlf  * pmult_dev_type fields).
3191258Smlf  */
3201258Smlf #define	SATA_VALID_DEV_TYPE	(SATA_DTYPE_ATADISK)	/* only disks now */
3211258Smlf 
3221258Smlf /*
3231258Smlf  * Device feature_support (satadrv_features_support)
3241258Smlf  */
3251258Smlf #define	SATA_DEV_F_DMA			0x01
3261258Smlf #define	SATA_DEV_F_LBA28		0x02
3271258Smlf #define	SATA_DEV_F_LBA48		0x04
3281258Smlf #define	SATA_DEV_F_NCQ			0x08
3291258Smlf #define	SATA_DEV_F_SATA1		0x10
3301258Smlf #define	SATA_DEV_F_SATA2		0x20
3311940Sls24207 #define	SATA_DEV_F_TCQ			0x40	/* Non NCQ tagged queuing */
3321258Smlf 
3331258Smlf /*
3343821Sls24207  * Device features enabled (satadrv_features_enabled)
3353821Sls24207  */
3363821Sls24207 #define	SATA_DEV_F_E_TAGGED_QING	0x01	/* Tagged queuing enabled */
3373821Sls24207 #define	SATA_DEV_F_E_UNTAGGED_QING	0x02	/* Untagged queuing enabled */
3383821Sls24207 
3393821Sls24207 /*
3401258Smlf  * Drive settings flags (satdrv_settings)
3411258Smlf  */
3421258Smlf #define	SATA_DEV_READ_AHEAD		0x0001	/* Read Ahead enabled */
3431258Smlf #define	SATA_DEV_WRITE_CACHE		0x0002	/* Write cache ON */
3441258Smlf #define	SATA_DEV_SERIAL_FEATURES 	0x8000	/* Serial ATA feat. enabled */
3451258Smlf #define	SATA_DEV_ASYNCH_NOTIFY		0x2000	/* Asynch-event enabled */
3461258Smlf 
3471258Smlf 
3481258Smlf /*
3491258Smlf  * Internal event and flags.
3501258Smlf  * These flags are set in the *_event_flags fields of various structures.
3511258Smlf  * Events and lock flags defined below are used internally by the
3521258Smlf  * SATA framework (they are not reported by SATA HBA drivers).
3531258Smlf  */
3541258Smlf #define	SATA_EVNT_MAIN			0x80000000
3551258Smlf #define	SATA_EVNT_SKIP			0x40000000
3561258Smlf #define	SATA_EVNT_INPROC_DEVICE_RESET	0x08000000
3571258Smlf #define	SATA_EVNT_CLEAR_DEVICE_RESET	0x04000000
358*3935Spawelw #define	SATA_EVNT_TARGET_NODE_CLEANUP	0x00000100
3591258Smlf 
3601258Smlf /*
3611258Smlf  * Lock flags - used to serialize configuration operations
3621258Smlf  * on ports and devices.
3631258Smlf  * SATA_EVNT_LOCK_PORT_BUSY is set by event daemon to prevent
3641258Smlf  * simultaneous cfgadm operations.
3651258Smlf  * SATA_APCTL_LOCK_PORT_BUSY is set by cfgadm ioctls to prevent
3661258Smlf  * simultaneous event processing.
3671258Smlf  */
3681258Smlf #define	SATA_EVNT_LOCK_PORT_BUSY	0x00800000
3691258Smlf #define	SATA_APCTL_LOCK_PORT_BUSY	0x00400000
3701258Smlf 
3711258Smlf /* Mask for port events */
3721258Smlf #define	SATA_EVNT_PORT_EVENTS		(SATA_EVNT_DEVICE_ATTACHED | \
3731258Smlf 					SATA_EVNT_DEVICE_DETACHED | \
3741258Smlf 					SATA_EVNT_LINK_LOST | \
3751258Smlf 					SATA_EVNT_LINK_ESTABLISHED | \
376*3935Spawelw 					SATA_EVNT_PORT_FAILED | \
377*3935Spawelw 					SATA_EVNT_TARGET_NODE_CLEANUP)
3781258Smlf /* Mask for drive events */
379*3935Spawelw #define	SATA_EVNT_DRIVE_EVENTS		(SATA_EVNT_DEVICE_RESET | \
380*3935Spawelw 					SATA_EVNT_INPROC_DEVICE_RESET)
3811258Smlf #define	SATA_EVNT_CONTROLLER_EVENTS	SATA_EVNT_PWR_LEVEL_CHANGED
3821258Smlf 
3831258Smlf /* Delays and timeounts definitions */
3841258Smlf #define	SATA_EVNT_DAEMON_SLEEP_TIME	50000	/* 50 ms */
3851258Smlf #define	SATA_EVNT_DAEMON_TERM_TIMEOUT	100000	/* 100 ms */
3861258Smlf #define	SATA_EVNT_DAEMON_TERM_WAIT	60000000 /* 60 s */
3871258Smlf #define	SATA_EVNT_LINK_LOST_TIMEOUT	1000000	/* 1 s */
3882960Spawelw #define	SATA_DEV_IDENTIFY_TIMEOUT	60000000 /* 60 s */
3892960Spawelw #define	SATA_DEV_IDENTIFY_RETRY_DELAY	10000	/* 10 ms */
3901258Smlf 
3912960Spawelw /* DEVICE IDENTIFY and device initialization retry delay */
3922960Spawelw #define	SATA_DEV_IDENTIFY_RETRY		1
3932960Spawelw #define	SATA_DEV_IDENTIFY_NORETRY	0
3941258Smlf 
3951258Smlf /*
3961258Smlf  * sata_scsi's hba_open_flag: field indicating open devctl instance.
3971258Smlf  *	0 = closed, 1 = shared open, 2 = exclusive open.
3981258Smlf  */
3991258Smlf #define	SATA_DEVCTL_CLOSED	0
4001258Smlf #define	SATA_DEVCTL_SOPENED	1
4011258Smlf #define	SATA_DEVCTL_EXOPENED	2
4021258Smlf 
4031258Smlf /*
4041258Smlf  * sata_pkt_txlate structure contains info about resources allocated
4051258Smlf  * for the packet
4061258Smlf  * Address of this structure is stored in scsi_pkt.pkt_ha_private and
4071258Smlf  * in sata_pkt.sata_hba_private fields, so all three strucures are
4081258Smlf  * cross-linked, with sata_pkt_txlate as a centerpiece.
4091258Smlf  */
4101258Smlf 
4111258Smlf typedef struct sata_pkt_txlate {
4121258Smlf 	struct sata_hba_inst	*txlt_sata_hba_inst;
4131258Smlf 	struct scsi_pkt		*txlt_scsi_pkt;
4141258Smlf 	struct sata_pkt		*txlt_sata_pkt;
4151258Smlf 	ddi_dma_handle_t	txlt_buf_dma_handle;
4161258Smlf 	uint_t			txlt_flags;	/* data-in / data-out */
4171258Smlf 	uint_t			txlt_num_dma_win; /* number of DMA windows */
4181258Smlf 	uint_t			txlt_cur_dma_win; /* current DMA window */
4191258Smlf 
4201258Smlf 				/* cookies in the current DMA window */
4211258Smlf 	uint_t			txlt_curwin_num_dma_cookies;
4221258Smlf 
423*3935Spawelw 				/* processed dma cookies in current DMA win */
4241258Smlf 	uint_t			txlt_curwin_processed_dma_cookies;
4251258Smlf 	size_t			txlt_total_residue;
426*3935Spawelw 	ddi_dma_cookie_t	txlt_dma_cookie; /* default dma cookie */
4271258Smlf 	int			txlt_dma_cookie_list_len; /* alloc list len */
4281258Smlf 	ddi_dma_cookie_t 	*txlt_dma_cookie_list; /* dma cookie list */
4291258Smlf 	int			txlt_num_dma_cookies; /* dma cookies in list */
4302539Spawelw 
4312539Spawelw 				/* temporary buffer access handle */
4322539Spawelw 	ddi_acc_handle_t	txlt_tmp_buf_handle;
4332539Spawelw 	caddr_t			txlt_tmp_buf;	/* temp buffer address */
4341258Smlf } sata_pkt_txlate_t;
4351258Smlf 
4361258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_pkt_txlate))
4371258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", scsi_pkt))
4381258Smlf 
4391258Smlf 
4401258Smlf /*
4411258Smlf  * Additional scsi sense code definitions.
4421258Smlf  * These definition should eventually be moved to scsi header files.
4431258Smlf  */
4441258Smlf #define	SD_SCSI_NO_ADD_SENSE			0x00
4451258Smlf #define	SD_SCSI_LU_NOT_READY			0x04
4461258Smlf #define	SD_SCSI_WRITE_ERROR			0x0c
4471258Smlf #define	SD_SCSI_UNREC_READ_ERROR		0x11
4481258Smlf #define	SD_SCSI_INVALID_COMMAND_CODE		0x20
4491258Smlf #define	SD_SCSI_LBA_OUT_OF_RANGE		0x21
4501258Smlf #define	SD_SCSI_INVALID_FIELD_IN_CDB		0x24
4511258Smlf #define	SD_SCSI_INVALID_FIELD_IN_PARAMETER_LIST 0x26
4521258Smlf #define	SD_SCSI_SAVING_PARAMS_NOT_SUP		0x39
4531258Smlf 
4541258Smlf 
4551258Smlf /* SCSI defs missing from scsi headers */
4561258Smlf /* Missing from sys/scsi/generic/commands.h */
4571258Smlf #define	SCMD_SYNCHRONIZE_CACHE_G1		0x91
4581258Smlf /*
4591258Smlf  * Missing from sys/scsi/impl/mode.h, although defined
4601258Smlf  * in sys/scsi/targets/sddefs.h as MODEPAGE_ERR_RECOV
4611258Smlf  */
4621258Smlf #define	MODEPAGE_RW_ERRRECOV			0x01 /* read/write recovery */
4631258Smlf 
4641258Smlf /*
4651258Smlf  * Macros for accessing various structure fields
4661258Smlf  */
4671258Smlf 
4681258Smlf #define	SATA_TRAN(sata_hba_inst) \
4691258Smlf 	sata_hba_inst->satahba_tran
4701258Smlf 
4711258Smlf #define	SATA_DIP(sata_hba_inst) \
4721258Smlf 	sata_hba_inst->satahba_dip
4731258Smlf 
4741258Smlf #define	SATA_NUM_CPORTS(sata_hba_inst) \
4751258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hba_num_cports
4761258Smlf 
4771258Smlf #define	SATA_QDEPTH(sata_hba_inst) \
4781258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hba_qdepth
4791258Smlf 
4801258Smlf #define	SATA_FEATURES(sata_hba_inst) \
4811258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hba_features_support
4821258Smlf 
4831258Smlf #define	SATA_DMA_ATTR(sata_hba_inst) \
4841258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hba_dma_attr
4851258Smlf 
4861258Smlf #define	SATA_START_FUNC(sata_hba_inst) \
4871258Smlf 	sata_hba_inst->satahba_tran->sata_tran_start
4881258Smlf 
4891258Smlf #define	SATA_ABORT_FUNC(sata_hba_inst) \
4901258Smlf 	sata_hba_inst->satahba_tran->sata_tran_abort
4911258Smlf 
4921258Smlf #define	SATA_RESET_DPORT_FUNC(sata_hba_inst) \
4931258Smlf 	sata_hba_inst->satahba_tran->sata_tran_reset_dport
4941258Smlf 
4951258Smlf #define	SATA_PORT_DEACTIVATE_FUNC(sata_hba_inst) \
4961258Smlf 	(sata_hba_inst->satahba_tran->sata_tran_hotplug_ops == NULL ? \
4971258Smlf 	NULL : \
4981258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hotplug_ops->\
4991258Smlf 	sata_tran_port_deactivate)
5001258Smlf 
5011258Smlf #define	SATA_PORT_ACTIVATE_FUNC(sata_hba_inst) \
5021258Smlf 	(sata_hba_inst->satahba_tran->sata_tran_hotplug_ops == NULL ? \
5031258Smlf 	NULL : \
5041258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hotplug_ops->\
5051258Smlf 	sata_tran_port_activate)
5061258Smlf 
5071258Smlf #define	SATA_PROBE_PORT_FUNC(sata_hba_inst) \
5081258Smlf 	sata_hba_inst->satahba_tran->sata_tran_probe_port
5091258Smlf 
5101258Smlf #define	SATA_SELFTEST_FUNC(sata_hba_inst) \
5111258Smlf 	sata_hba_inst->satahba_tran->sata_tran_selftest
5121258Smlf 
5131258Smlf #define	SATA_CPORT_MUTEX(sata_hba_inst, cport) \
5141258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_mutex
5151258Smlf 
5161258Smlf #define	SATA_CPORT_INFO(sata_hba_inst, cport) \
5171258Smlf 	sata_hba_inst->satahba_dev_port[cport]
5181258Smlf 
5191258Smlf #define	SATA_CPORT_STATE(sata_hba_inst, cport) \
5201258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_state
5211258Smlf 
522*3935Spawelw #define	SATA_CPORT_EVENT_FLAGS(sata_hba_inst, cport) \
523*3935Spawelw 	sata_hba_inst->satahba_dev_port[cport]->cport_event_flags
524*3935Spawelw 
5251258Smlf #define	SATA_CPORT_SCR(sata_hba_inst, cport) \
5261258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_scr
5271258Smlf 
5281258Smlf #define	SATA_CPORT_DEV_TYPE(sata_hba_inst, cport) \
5291258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_dev_type
5301258Smlf 
5311258Smlf #define	SATA_CPORT_DRV_INFO(sata_hba_inst, cport) \
5321258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_devp.cport_sata_drive
5331258Smlf 
5341258Smlf #define	SATA_CPORTINFO_DRV_TYPE(cportinfo) \
5351258Smlf 	cportinfo->cport_dev_type
5361258Smlf 
5371258Smlf #define	SATA_CPORTINFO_DRV_INFO(cportinfo) \
5381258Smlf 	cportinfo->cport_devp.cport_sata_drive
5391258Smlf 
5401258Smlf #define	SATA_CPORTINFO_PMULT_INFO(cportinfo) \
5411258Smlf 	cportinfo->cport_devp.cport_sata_pmult
5421258Smlf 
5431258Smlf #define	SATA_PMULT_INFO(sata_hba_inst, cport) \
5441258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_devp.cport_sata_pmult
5451258Smlf 
5461258Smlf #define	SATA_NUM_PMPORTS(sata_hba_inst, cport) \
5471258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
5481258Smlf 	cport_devp.cport_sata_pmult->pmult_num_dev_ports
5491258Smlf 
5501258Smlf #define	SATA_PMPORT_INFO(sata_hba_inst, cport, pmport) \
5511258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
5521258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]
5531258Smlf 
5541258Smlf #define	SATA_PMPORT_DRV_INFO(sata_hba_inst, cport, pmport) \
5551258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
5561258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->\
5571258Smlf 	pmport_sata_drive
5581258Smlf 
5591258Smlf #define	SATA_PMPORT_STATE(sata_hba_inst, cport, pmport) \
5601258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
5611258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_state
5621258Smlf 
5631258Smlf #define	SATA_PMPORT_SCR(sata_hba_inst, cport, pmport) \
5641258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
5651258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_scr
5661258Smlf 
5671258Smlf #define	SATA_PMPORT_DEV_TYPE(sata_hba_inst, cport, pmport) \
5681258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
5691258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_dev_type
5701258Smlf 
5711258Smlf #define	SATA_TXLT_HBA_INST(spx) \
5721258Smlf 	spx->txlt_sata_hba_inst
5731258Smlf 
5741258Smlf #define	SATA_TXLT_CPORT(spx) \
5751258Smlf 	spx->txlt_sata_pkt->satapkt_device.satadev_addr.cport
5761258Smlf 
5771258Smlf #define	SATA_TXLT_CPORT_MUTEX(spx) \
5781258Smlf 	spx->txlt_sata_hba_inst->\
5791258Smlf 	satahba_dev_port[spx->txlt_sata_pkt->\
5801258Smlf 	satapkt_device.satadev_addr.cport]->cport_mutex
5811258Smlf 
5821781Spawelw #define	SATA_TXLT_TASKQ(spx) \
5831781Spawelw 	spx->txlt_sata_hba_inst->\
5841781Spawelw 	satahba_taskq
5851781Spawelw 
5861258Smlf /*
5871258Smlf  * Minor number construction for devctl and attachment point nodes.
5881258Smlf  * All necessary information has to be encoded in NBITSMINOR32 bits.
5891258Smlf  *
5901258Smlf  * Devctl node minor number:
5911258Smlf  * ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | SATA_DEVCTL_NODE)
5921258Smlf  *
5931258Smlf  * Attachment point node minor number has to include controller
5941258Smlf  * instance (7 bits), controller port number (5 bits) and port multiplier
5951258Smlf  * device port number (4 bits) and port multiplier device port
5961258Smlf  * indicator (1 bit).  Additionally, a single bit is used to
5971258Smlf  * differentiate between attachment point node and device control node.
5981258Smlf  *
5991258Smlf  * Attachment point minor number:
6001258Smlf  * ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | SATA_AP_NODE |
6011258Smlf  * [(port_multiplier_device_port << SATA_PMULT_PORT_SHIFT) | SATA_PMULT_AP] |
6021258Smlf  * (controller_port))
6031258Smlf  *
6041258Smlf  * 17 bits are used (if 64 instances of controllers are expected)
6051258Smlf  * bit 18 is reserved for future use.
6061258Smlf  *
6071258Smlf  *   --------------------------------------------------------
6081258Smlf  *   |17|16|15|14|13|12|11|10 |09|08|07|06|05|04|03|02|01|00|
6091258Smlf  *   --------------------------------------------------------
6101258Smlf  *   | R| c| c| c| c| c| c|a/d|pm|pp|pp|pp|pp|cp|cp|cp|cp|cp|
6111258Smlf  *   --------------------------------------------------------
6121258Smlf  * Where:
6131258Smlf  * cp  - device port number on the HBA SATA controller
6141258Smlf  * pp  - device port number on the port multiplier
6151258Smlf  * pm  - 0 - target attached to controller device port
6161258Smlf  *       1 - target attached to port multiplier's device port
6171258Smlf  * a/d - 0 - devctl node
6181258Smlf  *       1 - attachment point node
6191258Smlf  * c   - controller number
6201258Smlf  * R   - reserved bit
6211258Smlf  */
6221258Smlf 
6231258Smlf #define	SATA_AP_NODE		0x400		/* Attachment Point node */
6241258Smlf #define	SATA_DEVCTL_NODE	0x000		/* DEVCTL node */
6251258Smlf #define	SATA_PMULT_AP		0x200		/* device on PMult port */
6261258Smlf #define	SATA_PMULT_PORT_SHIFT	5
6271258Smlf #define	SATA_CNTRL_INSTANCE_SHIFT 11
6281258Smlf #define	SATA_CPORT_MASK		0x1f		/* 32 device ports */
6291258Smlf #define	SATA_PMULT_PORT_MASK	0xf		/* 15 device ports */
6301258Smlf #define	SATA_CNTRL_INSTANCE_MASK 0x03F		/* 64 controllers */
6311258Smlf 
6321258Smlf /* Macro for creating devctl node minor number */
6331258Smlf #define	SATA_MAKE_DEVCTL_MINOR(controller_instance) \
6341258Smlf 	((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | \
6351258Smlf 	SATA_DEVCTL_NODE)
6361258Smlf 
6371258Smlf /* Macro for creating an attachment point node minor number */
6381258Smlf #define	SATA_MAKE_AP_MINOR(cntrl_instance, cport, pmport, qual) \
6391258Smlf 	(qual & (SATA_ADDR_PMPORT | SATA_ADDR_DPMPORT) ? \
6401258Smlf 	(((cntrl_instance) << SATA_CNTRL_INSTANCE_SHIFT) | \
6411258Smlf 	SATA_AP_NODE | SATA_PMULT_AP | \
6421258Smlf 	(pmport << SATA_PMULT_PORT_SHIFT) | cport) : \
6431258Smlf 	(((cntrl_instance) << SATA_CNTRL_INSTANCE_SHIFT) | \
6441258Smlf 	SATA_AP_NODE | cport))
6451258Smlf 
6461258Smlf /* Macro retrieving controller number from a minor number */
6471258Smlf #define	SATA_MINOR2INSTANCE(minor) \
6481258Smlf 	((minor >> SATA_CNTRL_INSTANCE_SHIFT) & SATA_CNTRL_INSTANCE_MASK)
6491258Smlf 
6501529Spawelw /*
6511529Spawelw  * Macro for creating an attachment point number from sata address.
6521529Spawelw  * Address qualifier has to be one of:
6531529Spawelw  * SATA_ADDR_DCPORT, SATA_ADDR_DPMPORT, SATA_ADDR_CPORT or SATA_ADDR_PMPORT
6541529Spawelw  */
6551529Spawelw #define	SATA_MAKE_AP_NUMBER(cport, pmport, qual) \
6561529Spawelw 	((qual & (SATA_ADDR_PMPORT | SATA_ADDR_DPMPORT)) ? \
6571529Spawelw 	(SATA_PMULT_AP | (pmport << SATA_PMULT_PORT_SHIFT) | cport) : \
6581529Spawelw 	(cport))
6591258Smlf 
6601258Smlf /*
6611258Smlf  * SCSI target number format
6621258Smlf  *
6631258Smlf  *   -------------------------------
6641258Smlf  *   | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|    Bit number
6651258Smlf  *   -------------------------------
6661258Smlf  *   |pm|pp|pp|pp|pp|cp|cp|cp|cp|cp|
6671258Smlf  *   -------------------------------
6681258Smlf  * Where:
6691258Smlf  * cp  - device port number on the HBA SATA controller
6701258Smlf  * pp  - device port number on the port multiplier
6711258Smlf  * pm  - 0 - target attached to controller device port
6721258Smlf  *       1 - target attached to port multiplier's device port
6731258Smlf  */
6741258Smlf 
6751258Smlf /* SATA ports to SCSI target number translation */
6761258Smlf 
6771258Smlf #define	SATA_TO_SCSI_TARGET(cport, pmport, qual) \
6781258Smlf 	(qual == SATA_ADDR_DCPORT ? cport : \
6791258Smlf 	(cport | (pmport << SATA_PMULT_PORT_SHIFT) | SATA_PMULT_AP))
6801258Smlf 
6811258Smlf /* SCSI target number to SATA cntrl/pmport/cport translations */
6821258Smlf #define	SCSI_TO_SATA_CPORT(scsi_target) \
6831258Smlf 	(scsi_target & SATA_CPORT_MASK)
6841258Smlf 
6851258Smlf #define	SCSI_TO_SATA_PMPORT(scsi_target) \
6861258Smlf 	((scsi_target >> SATA_PMULT_PORT_SHIFT) & SATA_PMULT_PORT_MASK)
6871258Smlf 
6881258Smlf #define	SCSI_TO_SATA_ADDR_QUAL(scsi_target) \
6891258Smlf 	((scsi_target & SATA_PMULT_AP) ? SATA_ADDR_DPMPORT : \
6901258Smlf 	SATA_ADDR_DCPORT)
6911258Smlf 
6921258Smlf 
6931258Smlf /* Debug flags */
6941258Smlf #if	DEBUG
6951258Smlf 
6961258Smlf #define	SATA_DEBUG
6971258Smlf #define	SATA_DBG_SCSI_IF	1
6981258Smlf #define	SATA_DBG_HBA_IF		2
6991258Smlf #define	SATA_DBG_NODES		4
7001258Smlf #define	SATA_DBG_IOCTL_IF	8
7011258Smlf #define	SATA_DBG_EVENTS		0x10
7021258Smlf #define	SATA_DBG_EVENTS_PROC	0x20
7031258Smlf #define	SATA_DBG_EVENTS_PROCPST	0x40
7041258Smlf #define	SATA_DBG_EVENTS_CNTRL	0x80
7051258Smlf #define	SATA_DBG_EVENTS_DAEMON	0x100
7061258Smlf #define	SATA_DBG_DMA_SETUP	0x400
7072734Spawelw #define	SATA_DBG_DEV_SETTINGS	0x800
7081258Smlf 
7091258Smlf /* Debug macros */
7101258Smlf #define	SATADBG1(flag, sata, format, arg1) \
7111258Smlf 	if (sata_debug_flags & (flag)) { \
7121258Smlf 		sata_log(sata, CE_CONT, format, arg1); \
7131258Smlf 	}
7141258Smlf 
7151258Smlf #define	SATADBG2(flag, sata, format, arg1, arg2) \
7161258Smlf 	if (sata_debug_flags & (flag)) { \
7171258Smlf 		sata_log(sata, CE_CONT, format, arg1, arg2); \
7181258Smlf 	}
7191258Smlf 
7201258Smlf #define	SATADBG3(flag, sata, format, arg1, arg2, arg3) \
7211258Smlf 	if (sata_debug_flags & (flag)) { \
7221258Smlf 		sata_log(sata, CE_CONT, format, arg1, arg2, arg3); \
7231258Smlf 	}
7241258Smlf #else
7251258Smlf 
7261258Smlf #define	SATADBG1(flag, dip, frmt, arg1)
7271258Smlf #define	SATADBG2(flag, dip, frmt, arg1, arg2)
7281258Smlf #define	SATADBG3(flag, dip, frmt, arg1, arg2, arg3)
7291258Smlf 
7301258Smlf #endif
7311258Smlf 
7321258Smlf #ifdef	__cplusplus
7331258Smlf }
7341258Smlf #endif
7351258Smlf 
7361258Smlf #endif /* _SATA_H */
737