xref: /onnv-gate/usr/src/uts/common/sys/sata/impl/sata.h (revision 10318:811db323512d)
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 /*
2310006SYing.Tian@Sun.COM  * Copyright 2009 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 #ifdef	__cplusplus
311258Smlf extern "C" {
321258Smlf #endif
331258Smlf 
341258Smlf /*
351258Smlf  * Generic SATA Host Adapter Implementation
361258Smlf  */
371258Smlf 
381258Smlf #include <sys/types.h>
391258Smlf #include <sys/scsi/scsi.h>
401258Smlf #include <sys/scsi/impl/services.h>
411258Smlf #include <sys/sata/sata_defs.h>
421258Smlf #include <sys/sata/sata_hba.h>
431258Smlf 
446539Spawelw /* Common flags specifying current state of a port or an attached drive. */
456539Spawelw #define	SATA_STATE_PROBING		0x000001
466539Spawelw #define	SATA_STATE_PROBED		0x000002
476539Spawelw 
481258Smlf /* Statistics counters */
491258Smlf struct sata_port_stats {
501258Smlf 	uint64_t	link_lost;		/* event counter */
511258Smlf 	uint64_t	link_established;	/* event counter */
521258Smlf 	uint64_t	device_attached;	/* event counter */
531258Smlf 	uint64_t	device_detached;	/* event counter */
541258Smlf 	uint64_t	port_reset;		/* event counter */
551258Smlf 	uint64_t	port_pwr_changed;	/* event counter */
561258Smlf };
571258Smlf 
581258Smlf typedef struct sata_port_stats sata_port_stats_t;
591258Smlf 
601258Smlf struct sata_drive_stats {
611258Smlf 	uint64_t	media_error;		/* available ??? */
621258Smlf 	uint64_t	drive_reset;		/* event counter */
631258Smlf } sata_drv_stats_t;
641258Smlf 
651258Smlf typedef struct sata_drive_stats sata_drive_stats_t;
661258Smlf 
671258Smlf struct sata_ctrl_stats {
681258Smlf 	uint64_t	ctrl_reset;		/* event counter */
691258Smlf 	uint64_t	ctrl_pwr_change;	/* event counter */
701258Smlf };
711258Smlf 
721258Smlf typedef struct sata_ctrl_stats sata_ctrl_stats_t;
731258Smlf 
741258Smlf 
751258Smlf /*
761258Smlf  * SATA HBA instance info structure
771258Smlf  */
781258Smlf struct sata_hba_inst {
791258Smlf 	dev_info_t		*satahba_dip;	/* this HBA instance devinfo */
801258Smlf 	struct sata_hba_inst	*satahba_next;	/* ptr to next sata_hba_inst */
811258Smlf 	struct sata_hba_inst	*satahba_prev;	/* ptr to prev sata_hba_inst */
821258Smlf 	struct scsi_hba_tran	*satahba_scsi_tran; /* scsi_hba_tran */
831258Smlf 	struct sata_hba_tran	*satahba_tran;	/* sata_hba_tran */
841258Smlf 	kmutex_t		satahba_mutex;	/* sata hba cntrl mutex */
851781Spawelw 	struct taskq		*satahba_taskq;	/* cmd completion task queue */
861258Smlf 
871258Smlf 						/*
881258Smlf 						 * HBA event flags:
891258Smlf 						 * SATA_EVNT_MAIN
901258Smlf 						 * SATA_EVNT_PWR_LEVEL_CHANGED
911258Smlf 						 * SATA_EVNT_SKIP
921258Smlf 						 */
931258Smlf 	uint_t			satahba_event_flags;
941258Smlf 
951258Smlf 	struct sata_cport_info	*satahba_dev_port[SATA_MAX_CPORTS];
961258Smlf 
971258Smlf 						/*
981258Smlf 						 * DEVCTL open flag:
991258Smlf 						 * SATA_DEVCTL_SOPENED
1001258Smlf 						 * SATA_DEVCTL_EXOPENED
1011258Smlf 						 */
1021258Smlf 	uint_t			satahba_open_flag; /* shared open flag */
1031258Smlf 	struct sata_ctrl_stats	satahba_stats;	/* HBA cntrl statistics */
1041258Smlf 
1051258Smlf 	uint_t			satahba_attached; /* HBA attaching: */
1061258Smlf 						/* 0 - not completed */
1071258Smlf 						/* 1 - completed */
1081258Smlf };
1091258Smlf 
1101258Smlf typedef struct sata_hba_inst	sata_hba_inst_t;
1111258Smlf 
1121258Smlf /*
1131258Smlf  * SATA controller's device port info and state.
1141258Smlf  * This structure is pointed to by the sata_hba_inst.satahba_dev_port[x]
1151258Smlf  * where x is a device port number.
1161258Smlf  * cport_state holds port state flags, defined in sata_hba.h file.
1171258Smlf  * cport_event_flags holds SATA_EVNT_* flags defined in this file and in
1181258Smlf  * sata_hba.h file.
1191258Smlf  * cport_dev_type holds SATA_DTYPE_* types defined in sata_hba.h file.
1201258Smlf  */
1211258Smlf struct sata_cport_info {
1221258Smlf 	sata_address_t		cport_addr;	/* this port SATA address */
1231258Smlf 	kmutex_t		cport_mutex;	/* port mutex */
1241258Smlf 
1251258Smlf 						/*
1261258Smlf 						 * Port state flags
1271258Smlf 						 * SATA_STATE_UNKNOWN
1281258Smlf 						 * SATA_STATE_PROBING
1291258Smlf 						 * SATA_STATE_PROBED
1301258Smlf 						 * SATA_STATE_READY
1311258Smlf 						 * SATA_PSTATE_PWRON
1321258Smlf 						 * SATA_PSTATE_PWROFF
1331258Smlf 						 * SATA_PSTATE_SHUTDOWN
1341258Smlf 						 * SATA_PSTATE_FAILED
1351258Smlf 						 */
1361258Smlf 	uint32_t		cport_state;
1371258Smlf 
1381258Smlf 						/*
1391258Smlf 						 * Port event flags:
1401258Smlf 						 * SATA_EVNT_DEVICE_ATTACHED
1411258Smlf 						 * SATA_EVNT_DEVICE_DETACHED
1421258Smlf 						 * SATA_EVNT_LINK_LOST
1431258Smlf 						 * SATA_EVNT_LINK_ESTABLISHED
1441258Smlf 						 * SATA_EVNT_PORT_FAILED
1451258Smlf 						 * SATA_EVNT_PWR_LEVEL_CHANGED
1461258Smlf 						 */
1471258Smlf 	uint32_t		cport_event_flags;
1481258Smlf 
1491258Smlf 	struct sata_port_scr	cport_scr;	/* Port status and ctrl regs */
1501258Smlf 
1511258Smlf 						/*
1521258Smlf 						 * Attached device type:
1531258Smlf 						 * SATA_DTYPE_NONE
1541258Smlf 						 * SATA_DTYPE_ATADISK
1551258Smlf 						 * SATA_DTYPE_ATAPICD
1568010SYing.Tian@Sun.COM 						 * SATA_DTYPE_ATAPITAPE
1578317SYing.Tian@Sun.COM 						 * SATA_DTYPE_ATAPIDISK
1581258Smlf 						 * SATA_DTYPE_PMULT
1591258Smlf 						 * SATA_DTYPE_UNKNOWN
1601258Smlf 						 */
1611258Smlf 	uint32_t		cport_dev_type;
1621258Smlf 	union {
1631258Smlf 	    struct sata_drive_info *cport_sata_drive; /* Attached drive info */
1641258Smlf 	    struct sata_pmult_info *cport_sata_pmult; /* Attached Port Mult */
1651258Smlf 	} 			cport_devp;
1661258Smlf 						/* lbolt value at link lost */
1671258Smlf 	clock_t			cport_link_lost_time;
1682960Spawelw 						/* lbolt value @ dev attached */
1692960Spawelw 	clock_t			cport_dev_attach_time;
1701258Smlf 
1711258Smlf 	struct sata_port_stats	cport_stats;	/* Port statistics */
1723935Spawelw 
1733935Spawelw 	boolean_t		cport_tgtnode_clean; /* Target node usable */
1741258Smlf };
1751258Smlf 
1761258Smlf typedef struct sata_cport_info sata_cport_info_t;
1771258Smlf 
1781258Smlf /*
1791258Smlf  * Attached SATA drive info and state.
1801258Smlf  * This structure is pointed to by sata_cport_info's cport_sata_drive field
1811258Smlf  * when a drive is attached directly to a controller device port.
1821258Smlf  */
1831258Smlf struct sata_drive_info {
1841258Smlf 	sata_address_t	satadrv_addr;		/* this drive SATA address */
1851258Smlf 
1861258Smlf 						/*
1871258Smlf 						 * Drive state flags
1881258Smlf 						 * SATA_STATE_UNKNOWN
1891258Smlf 						 * SATA_STATE_PROBING
1901258Smlf 						 * SATA_STATE_PROBED
1911258Smlf 						 * SATA_STATE_READY
1921258Smlf 						 * SATA_DSTATE_PWR_ACTIVE
1931258Smlf 						 * SATA_DSTATE_PWR_IDLE
1941258Smlf 						 * SATA_DSTATE_RESET
1951258Smlf 						 * SATA_DSTATE_FAILED
1961258Smlf 						 */
1971258Smlf 	uint32_t	satadrv_state;
1981258Smlf 
1991258Smlf 						/*
2001258Smlf 						 * drive event flags:
2011258Smlf 						 * SATA_EVNT_DRIVE_RESET
2021258Smlf 						 */
2031258Smlf 	uint32_t	satadrv_event_flags;
2046539Spawelw 						/*
2056539Spawelw 						 * lbolt value @ start of
2066539Spawelw 						 * device reset processing
2076539Spawelw 						 */
2086539Spawelw 	clock_t		satadrv_reset_time;
2091258Smlf 						/*
2101258Smlf 						 * Attached device type:
2111258Smlf 						 * SATA_DTYPE_ATADISK
2121258Smlf 						 * SATA_DTYPE_ATAPICD
2138010SYing.Tian@Sun.COM 						 * SATA_DTYPE_ATAPITAPE
2148317SYing.Tian@Sun.COM 						 * SATA_DTYPE_ATAPIDISK
2151258Smlf 						 */
2161258Smlf 	uint32_t	satadrv_type;
2171258Smlf 
2181258Smlf 	uint32_t	satadrv_status_reg;	/* drive status reg */
2191258Smlf 	uint32_t	satadrv_error_reg;	/* drive error reg */
2201258Smlf 	uint16_t	satadrv_features_support; /* drive features support */
2211258Smlf 	uint16_t	satadrv_queue_depth;    /* drive queue depth */
2224862SUnknown 	uint16_t	satadrv_atapi_cdb_len;	/* atapi supported cdb length */
2234862SUnknown 	uint16_t	satadrv_atapi_trans_ver; /* atapi transport version */
2241258Smlf 	uint16_t	satadrv_settings;	/* drive settings flags */
2253821Sls24207 	uint16_t	satadrv_features_enabled; /* drive features enabled */
2261258Smlf 	uint64_t	satadrv_capacity;	/* drive capacity */
2274862SUnknown 	uint64_t	satadrv_max_queue_depth; /* maximum queue depth */
2281258Smlf 	sata_id_t	satadrv_id;		/* Device Identify Data */
2291258Smlf 	struct sata_drive_stats satadrv_stats;	/* drive statistics */
23010131SJane.Chu@Sun.COM 
23110131SJane.Chu@Sun.COM 	/*
23210131SJane.Chu@Sun.COM 	 * saved standby timer
23310131SJane.Chu@Sun.COM 	 * [0] - [3] = high - low
23410131SJane.Chu@Sun.COM 	 */
23510131SJane.Chu@Sun.COM 	uint8_t		satadrv_standby_timer[4];
23610131SJane.Chu@Sun.COM 	uint8_t		satadrv_power_level; /* saved power level */
2371258Smlf };
2381258Smlf 
2391258Smlf typedef struct sata_drive_info sata_drive_info_t;
2401258Smlf 
2411258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_drive_info))
2421258Smlf 
2431258Smlf 
2441258Smlf /* Port Multiplier & host port info and state */
2451258Smlf struct sata_pmult_info {
2461258Smlf 	sata_address_t	pmult_addr;		/* this PMult SATA Address */
2471258Smlf 						/*
2481258Smlf 						 * PMult state flags
2491258Smlf 						 * SATA_STATE_UNKNOWN
2501258Smlf 						 * SATA_STATE_PROBING
2511258Smlf 						 * SATA_STATE_PROBED
2521258Smlf 						 * SATA_STATE_READY
2531258Smlf 						 * SATA_PSTATE_FAILED
2541258Smlf 						 */
2551258Smlf 	uint32_t	pmult_state;
2561258Smlf 	uint32_t	pmult_event_flags;	/* Undefined for now */
257*10318SXiao-Yu.Zhang@Sun.COM 	struct sata_pmult_gscr pmult_gscr;	/* PMult GSCR block */
2581258Smlf 	uint32_t	pmult_num_dev_ports; 	/* Number of data ports */
2591258Smlf 	struct sata_pmport_info	*pmult_dev_port[SATA_MAX_PMPORTS - 1];
2601258Smlf };
2611258Smlf 
2621258Smlf typedef	struct sata_pmult_info sata_pmult_info_t;
2631258Smlf 
264*10318SXiao-Yu.Zhang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_pmult_info))
265*10318SXiao-Yu.Zhang@Sun.COM _NOTE(MUTEX_PROTECTS_DATA(sata_cport_info::cport_mutex, \
266*10318SXiao-Yu.Zhang@Sun.COM     sata_pmult_info::pmult_dev_port))
267*10318SXiao-Yu.Zhang@Sun.COM 
2681258Smlf /* Port Multiplier's device port info & state */
2691258Smlf struct sata_pmport_info {
2701258Smlf 	sata_address_t	pmport_addr;		/* this SATA port address */
2711258Smlf 	kmutex_t	pmport_mutex;		/* pmult device port mutex */
2721258Smlf 
2731258Smlf 						/*
2741258Smlf 						 * Port state flags
2751258Smlf 						 * SATA_STATE_UNKNOWN
2761258Smlf 						 * SATA_STATE_PROBING
2771258Smlf 						 * SATA_STATE_PROBED
2781258Smlf 						 * SATA_STATE_READY
2791258Smlf 						 * SATA_PSTATE_PWRON
2801258Smlf 						 * SATA_PSTATE_PWROFF
2811258Smlf 						 * SATA_PSTATE_SHUTDOWN
2821258Smlf 						 * SATA_PSTATE_FAILED
2831258Smlf 						 */
2841258Smlf 	uint32_t	pmport_state;
2851258Smlf 
2861258Smlf 						/*
2871258Smlf 						 * Port event flags:
2881258Smlf 						 * SATA_EVNT_DEVICE_ATTACHED
2891258Smlf 						 * SATA_EVNT_DEVICE_DETACHED
2901258Smlf 						 * SATA_EVNT_LINK_LOST
2911258Smlf 						 * SATA_EVNT_LINK_ESTABLISHED
2921258Smlf 						 * SATA_EVNT_PORT_FAILED
2931258Smlf 						 * SATA_EVNT_PWR_LEVEL_CHANGED
2941258Smlf 						 */
2951258Smlf 	uint32_t	pmport_event_flags;
2961258Smlf 
2971258Smlf 	struct sata_port_scr pmport_scr;	/* PMult device port scr */
2981258Smlf 
2991258Smlf 						/*
3001258Smlf 						 * Attached device type:
3011258Smlf 						 * SATA_DTYPE_NONE
3021258Smlf 						 * SATA_DTYPE_ATADISK
3031258Smlf 						 * SATA_DTYPE_ATAPICD
3048010SYing.Tian@Sun.COM 						 * SATA_DTYPE_ATAPITAPE
3058317SYing.Tian@Sun.COM 						 * SATA_DTYPE_ATAPIDISK
3061258Smlf 						 * SATA_DTYPE_UNKNOWN
3071258Smlf 						 */
3081258Smlf 	uint32_t	pmport_dev_type;
3091258Smlf 
3101258Smlf 	struct sata_drive_info	*pmport_sata_drive; /* Attached drive info */
3111258Smlf 
3121258Smlf 						/* lbolt value at link lost */
3131258Smlf 	clock_t		pmport_link_lost_time;
3142960Spawelw 						/* lbolt value @ dev attached */
3152960Spawelw 	clock_t		pmport_dev_attach_time;
3161258Smlf 
3171258Smlf 	struct sata_port_stats	pmport_stats;	/* Port statistics */
3183935Spawelw 
3193935Spawelw 	boolean_t	pmport_tgtnode_clean;	/* Target node usable */
3201258Smlf };
3211258Smlf 
3221258Smlf typedef	struct sata_pmport_info sata_pmport_info_t;
3231258Smlf 
3241258Smlf /*
32510131SJane.Chu@Sun.COM  * sata drive's power level
32610131SJane.Chu@Sun.COM  * default value is active
32710131SJane.Chu@Sun.COM  */
32810131SJane.Chu@Sun.COM #define	SATA_POWER_ACTIVE	0x00
32910131SJane.Chu@Sun.COM #define	SATA_POWER_IDLE		0x01
33010131SJane.Chu@Sun.COM #define	SATA_POWER_STANDBY	0x02
33110131SJane.Chu@Sun.COM #define	SATA_POWER_STOPPED	0x03
33210131SJane.Chu@Sun.COM 
33310131SJane.Chu@Sun.COM /*
33410131SJane.Chu@Sun.COM  * pm-capable value definition according to PSARC 2009/310
33510131SJane.Chu@Sun.COM  */
33610131SJane.Chu@Sun.COM #define	SATA_CAP_POWER_CONDITON	PM_CAPABLE_SPC4
33710131SJane.Chu@Sun.COM #define	SATA_CAP_SMART_PAGE	PM_CAPABLE_SMART_LOG
33810131SJane.Chu@Sun.COM #define	SATA_CAP_LOG_SENSE	PM_CAPABLE_LOG_SUPPORTED
33910131SJane.Chu@Sun.COM 
34010131SJane.Chu@Sun.COM /*
3411258Smlf  * Port SSTATUS register (sata_port_scr sport_sstatus field).
3421258Smlf  * Link bits are valid only in port active state.
3431258Smlf  */
3441258Smlf #define	SATA_PORT_DEVLINK_UP	0x00000103	/* Link with dev established */
3451258Smlf #define	SATA_PORT_DEVLINK_UP_MASK 0x0000010F	/* Mask for link bits */
3461258Smlf 
3471258Smlf /*
3481258Smlf  * Port state clear mask (cport_state and pmport_state fields).
3491258Smlf  * SATA_PSTATE_SHUTDOWN and power state are preserved.
3501258Smlf  */
3511258Smlf #define	SATA_PORT_STATE_CLEAR_MASK	(~(SATA_PSTATE_SHUTDOWN))
3521258Smlf 
3531258Smlf /*
3541258Smlf  * Valid i.e.supported device types mask (cport_dev_type, satadrv_type,
3551258Smlf  * pmult_dev_type fields).
3564862SUnknown  * ATA disks and ATAPI CD/DVD now.
3571258Smlf  */
3584862SUnknown #define	SATA_VALID_DEV_TYPE	(SATA_DTYPE_ATADISK | \
3598010SYing.Tian@Sun.COM 				SATA_DTYPE_ATAPICD | \
3608317SYing.Tian@Sun.COM 				SATA_DTYPE_ATAPITAPE | \
3618317SYing.Tian@Sun.COM 				SATA_DTYPE_ATAPIDISK)
3621258Smlf 
3631258Smlf /*
3641258Smlf  * Device feature_support (satadrv_features_support)
3651258Smlf  */
3661258Smlf #define	SATA_DEV_F_DMA			0x01
3671258Smlf #define	SATA_DEV_F_LBA28		0x02
3681258Smlf #define	SATA_DEV_F_LBA48		0x04
3691258Smlf #define	SATA_DEV_F_NCQ			0x08
3701258Smlf #define	SATA_DEV_F_SATA1		0x10
3711258Smlf #define	SATA_DEV_F_SATA2		0x20
3721940Sls24207 #define	SATA_DEV_F_TCQ			0x40	/* Non NCQ tagged queuing */
3731258Smlf 
3741258Smlf /*
3753821Sls24207  * Device features enabled (satadrv_features_enabled)
3763821Sls24207  */
3773821Sls24207 #define	SATA_DEV_F_E_TAGGED_QING	0x01	/* Tagged queuing enabled */
3783821Sls24207 #define	SATA_DEV_F_E_UNTAGGED_QING	0x02	/* Untagged queuing enabled */
3793821Sls24207 
3803821Sls24207 /*
3811258Smlf  * Drive settings flags (satdrv_settings)
3821258Smlf  */
3831258Smlf #define	SATA_DEV_READ_AHEAD		0x0001	/* Read Ahead enabled */
3841258Smlf #define	SATA_DEV_WRITE_CACHE		0x0002	/* Write cache ON */
3854862SUnknown #define	SATA_DEV_DMA			0x0004	/* DMA selected */
3861258Smlf #define	SATA_DEV_SERIAL_FEATURES 	0x8000	/* Serial ATA feat. enabled */
3871258Smlf #define	SATA_DEV_ASYNCH_NOTIFY		0x2000	/* Asynch-event enabled */
3884862SUnknown #define	SATA_DEV_RMSN			0x0100	/* Rem Media Stat Notfc enbl */
3891258Smlf 
3901258Smlf /*
3911258Smlf  * Internal event and flags.
3921258Smlf  * These flags are set in the *_event_flags fields of various structures.
3931258Smlf  * Events and lock flags defined below are used internally by the
3941258Smlf  * SATA framework (they are not reported by SATA HBA drivers).
3951258Smlf  */
3961258Smlf #define	SATA_EVNT_MAIN			0x80000000
3971258Smlf #define	SATA_EVNT_SKIP			0x40000000
3981258Smlf #define	SATA_EVNT_INPROC_DEVICE_RESET	0x08000000
3991258Smlf #define	SATA_EVNT_CLEAR_DEVICE_RESET	0x04000000
4003935Spawelw #define	SATA_EVNT_TARGET_NODE_CLEANUP	0x00000100
4015832Spawelw #define	SATA_EVNT_AUTOONLINE_DEVICE	0x00000200
4021258Smlf 
4031258Smlf /*
4041258Smlf  * Lock flags - used to serialize configuration operations
4051258Smlf  * on ports and devices.
4061258Smlf  * SATA_EVNT_LOCK_PORT_BUSY is set by event daemon to prevent
4071258Smlf  * simultaneous cfgadm operations.
4081258Smlf  * SATA_APCTL_LOCK_PORT_BUSY is set by cfgadm ioctls to prevent
4091258Smlf  * simultaneous event processing.
4101258Smlf  */
4111258Smlf #define	SATA_EVNT_LOCK_PORT_BUSY	0x00800000
4121258Smlf #define	SATA_APCTL_LOCK_PORT_BUSY	0x00400000
4131258Smlf 
4141258Smlf /* Mask for port events */
4151258Smlf #define	SATA_EVNT_PORT_EVENTS		(SATA_EVNT_DEVICE_ATTACHED | \
4161258Smlf 					SATA_EVNT_DEVICE_DETACHED | \
4171258Smlf 					SATA_EVNT_LINK_LOST | \
4181258Smlf 					SATA_EVNT_LINK_ESTABLISHED | \
419*10318SXiao-Yu.Zhang@Sun.COM 					SATA_EVNT_PMULT_LINK_CHANGED | \
4203935Spawelw 					SATA_EVNT_PORT_FAILED | \
4215832Spawelw 					SATA_EVNT_TARGET_NODE_CLEANUP | \
4225832Spawelw 					SATA_EVNT_AUTOONLINE_DEVICE)
4231258Smlf /* Mask for drive events */
4243935Spawelw #define	SATA_EVNT_DRIVE_EVENTS		(SATA_EVNT_DEVICE_RESET | \
4253935Spawelw 					SATA_EVNT_INPROC_DEVICE_RESET)
4261258Smlf #define	SATA_EVNT_CONTROLLER_EVENTS	SATA_EVNT_PWR_LEVEL_CHANGED
4271258Smlf 
4285832Spawelw /* Delays and timeout duration definitions */
4291258Smlf #define	SATA_EVNT_DAEMON_SLEEP_TIME	50000	/* 50 ms */
4301258Smlf #define	SATA_EVNT_DAEMON_TERM_TIMEOUT	100000	/* 100 ms */
4311258Smlf #define	SATA_EVNT_DAEMON_TERM_WAIT	60000000 /* 60 s */
4321258Smlf #define	SATA_EVNT_LINK_LOST_TIMEOUT	1000000	/* 1 s */
4336539Spawelw 
4346539Spawelw #define	SATA_DEV_IDENTIFY_TIMEOUT	60000000 /* 60 s, device enumeration */
4356539Spawelw #define	SATA_DEV_REPROBE_TIMEOUT	30000000  /* 30 s, dev resp after rst */
4366539Spawelw #define	SATA_DEV_RETRY_DLY		10000	/* 10 ms */
4371258Smlf 
4382960Spawelw /* DEVICE IDENTIFY and device initialization retry delay */
4392960Spawelw #define	SATA_DEV_IDENTIFY_RETRY		1
4402960Spawelw #define	SATA_DEV_IDENTIFY_NORETRY	0
4411258Smlf 
4421258Smlf /*
4431258Smlf  * sata_scsi's hba_open_flag: field indicating open devctl instance.
4441258Smlf  *	0 = closed, 1 = shared open, 2 = exclusive open.
4451258Smlf  */
4461258Smlf #define	SATA_DEVCTL_CLOSED	0
4471258Smlf #define	SATA_DEVCTL_SOPENED	1
4481258Smlf #define	SATA_DEVCTL_EXOPENED	2
4491258Smlf 
4501258Smlf /*
4511258Smlf  * sata_pkt_txlate structure contains info about resources allocated
4521258Smlf  * for the packet
4531258Smlf  * Address of this structure is stored in scsi_pkt.pkt_ha_private and
4541258Smlf  * in sata_pkt.sata_hba_private fields, so all three strucures are
4551258Smlf  * cross-linked, with sata_pkt_txlate as a centerpiece.
4561258Smlf  */
4571258Smlf 
4581258Smlf typedef struct sata_pkt_txlate {
4591258Smlf 	struct sata_hba_inst	*txlt_sata_hba_inst;
4601258Smlf 	struct scsi_pkt		*txlt_scsi_pkt;
4611258Smlf 	struct sata_pkt		*txlt_sata_pkt;
4621258Smlf 	ddi_dma_handle_t	txlt_buf_dma_handle;
4631258Smlf 	uint_t			txlt_flags;	/* data-in / data-out */
4641258Smlf 	uint_t			txlt_num_dma_win; /* number of DMA windows */
4651258Smlf 	uint_t			txlt_cur_dma_win; /* current DMA window */
4661258Smlf 
4671258Smlf 				/* cookies in the current DMA window */
4681258Smlf 	uint_t			txlt_curwin_num_dma_cookies;
4691258Smlf 
4703935Spawelw 				/* processed dma cookies in current DMA win */
4711258Smlf 	uint_t			txlt_curwin_processed_dma_cookies;
4721258Smlf 	size_t			txlt_total_residue;
4733935Spawelw 	ddi_dma_cookie_t	txlt_dma_cookie; /* default dma cookie */
4741258Smlf 	int			txlt_dma_cookie_list_len; /* alloc list len */
4751258Smlf 	ddi_dma_cookie_t 	*txlt_dma_cookie_list; /* dma cookie list */
4761258Smlf 	int			txlt_num_dma_cookies; /* dma cookies in list */
4772539Spawelw 
4782539Spawelw 				/* temporary buffer access handle */
4792539Spawelw 	ddi_acc_handle_t	txlt_tmp_buf_handle;
4802539Spawelw 	caddr_t			txlt_tmp_buf;	/* temp buffer address */
4811258Smlf } sata_pkt_txlate_t;
4821258Smlf 
4831258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_pkt_txlate))
4841258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", scsi_pkt))
4851258Smlf 
4861258Smlf 
4871258Smlf /*
4881258Smlf  * Additional scsi sense code definitions.
4894862SUnknown  * These definition should eventually be moved to scsi header file
4904862SUnknown  * usr/src/uts/common/sys/scsi/generic/sense.h
4911258Smlf  */
4924862SUnknown #define	SD_SCSI_ASC_NO_ADD_SENSE			0x00
4934862SUnknown #define	SD_SCSI_ASC_LU_NOT_READY			0x04
4945832Spawelw #define	SD_SCSI_ASC_WRITE_ERR				0x0c
4955832Spawelw #define	SD_SCSI_ASC_UNREC_READ_ERR			0x11
4964862SUnknown #define	SD_SCSI_ASC_INVALID_COMMAND_CODE		0x20
4974862SUnknown #define	SD_SCSI_ASC_LBA_OUT_OF_RANGE			0x21
4984862SUnknown #define	SD_SCSI_ASC_INVALID_FIELD_IN_CDB		0x24
49910131SJane.Chu@Sun.COM #define	SD_SCSI_ASC_INVALID_FIELD_IN_PARAMS_LIST	0x26
5004862SUnknown #define	SD_SCSI_ASC_RESET				0x29
5014862SUnknown #define	SD_SCSI_ASC_SAVING_PARAMS_NOT_SUPPORTED		0x39
50210131SJane.Chu@Sun.COM #define	SD_SCSI_ASC_CMD_SEQUENCE_ERR			0x2c
50310131SJane.Chu@Sun.COM #define	SD_SCSI_ASC_LOW_POWER_CONDITION_ON		0x5e
50410131SJane.Chu@Sun.COM #define	SD_SCSI_ASC_LU_NOT_RESPONSE			0x05
5051258Smlf 
5061258Smlf 
5071258Smlf /* SCSI defs missing from scsi headers */
5081258Smlf /* Missing from sys/scsi/generic/commands.h */
5091258Smlf #define	SCMD_SYNCHRONIZE_CACHE_G1		0x91
5101258Smlf /*
5111258Smlf  * Missing from sys/scsi/impl/mode.h, although defined
5121258Smlf  * in sys/scsi/targets/sddefs.h as MODEPAGE_ERR_RECOV
5131258Smlf  */
5141258Smlf #define	MODEPAGE_RW_ERRRECOV			0x01 /* read/write recovery */
5151258Smlf 
5161258Smlf /*
51710131SJane.Chu@Sun.COM  * medium access command
51810131SJane.Chu@Sun.COM  */
51910131SJane.Chu@Sun.COM #define	SATA_IS_MEDIUM_ACCESS_CMD(cmd) \
52010131SJane.Chu@Sun.COM 	(((cmd) == SCMD_READ) || ((cmd) == SCMD_WRITE) || \
52110131SJane.Chu@Sun.COM 	((cmd) == SCMD_READ_G1) || ((cmd) == SCMD_WRITE_G1) || \
52210131SJane.Chu@Sun.COM 	((cmd) == SCMD_READ_G4) || ((cmd) == SCMD_WRITE_G4) || \
52310131SJane.Chu@Sun.COM 	((cmd) == SCMD_READ_G5) || ((cmd) == SCMD_WRITE_G5) || \
52410131SJane.Chu@Sun.COM 	((cmd) == SCMD_VERIFY) || ((cmd) == SCMD_VERIFY_G4) || \
52510131SJane.Chu@Sun.COM 	((cmd) == SCMD_VERIFY_G5) || ((cmd) == 0x7f) /* VERIFY(32) */|| \
52610131SJane.Chu@Sun.COM 	((cmd) == SCMD_SYNCHRONIZE_CACHE) || ((cmd) == SCMD_SPACE_G4) || \
52710131SJane.Chu@Sun.COM 	((cmd) == SCMD_READ_POSITION) || \
52810131SJane.Chu@Sun.COM 	((cmd) == 0x90) /* PRE-FETCH(16) */ || \
52910131SJane.Chu@Sun.COM 	((cmd) == SCMD_READ_DEFECT_LIST) || \
53010131SJane.Chu@Sun.COM 	((cmd) == 0xb7) /* READ DEFECT DATA */ || \
53110131SJane.Chu@Sun.COM 	((cmd) == SCMD_READ_LONG) || ((cmd) == SCMD_SVC_ACTION_IN_G4) || \
53210131SJane.Chu@Sun.COM 	((cmd) == SCMD_WRITE_LONG) || ((cmd) == SCMD_SVC_ACTION_OUT_G4) || \
53310131SJane.Chu@Sun.COM 	((cmd) == 0x41) || ((cmd) == 0x93) || /* WRITE SAME */ \
53410131SJane.Chu@Sun.COM 	((cmd) == 0x52) || ((cmd) == 0x50) || /* XDREAD & XDWRITE */ \
53510131SJane.Chu@Sun.COM 	((cmd) == 0x53) || ((cmd) == 0x51) || /* XDWRITEREAD & XPWRITE */ \
53610131SJane.Chu@Sun.COM 	((cmd) == 0x7f))
53710131SJane.Chu@Sun.COM 
53810131SJane.Chu@Sun.COM /*
5391258Smlf  * Macros for accessing various structure fields
5401258Smlf  */
5411258Smlf 
5421258Smlf #define	SATA_TRAN(sata_hba_inst) \
5431258Smlf 	sata_hba_inst->satahba_tran
5441258Smlf 
5451258Smlf #define	SATA_DIP(sata_hba_inst) \
5461258Smlf 	sata_hba_inst->satahba_dip
5471258Smlf 
5481258Smlf #define	SATA_NUM_CPORTS(sata_hba_inst) \
5491258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hba_num_cports
5501258Smlf 
5511258Smlf #define	SATA_QDEPTH(sata_hba_inst) \
5521258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hba_qdepth
5531258Smlf 
5541258Smlf #define	SATA_FEATURES(sata_hba_inst) \
5551258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hba_features_support
5561258Smlf 
5571258Smlf #define	SATA_DMA_ATTR(sata_hba_inst) \
5581258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hba_dma_attr
5591258Smlf 
5601258Smlf #define	SATA_START_FUNC(sata_hba_inst) \
5611258Smlf 	sata_hba_inst->satahba_tran->sata_tran_start
5621258Smlf 
5631258Smlf #define	SATA_ABORT_FUNC(sata_hba_inst) \
5641258Smlf 	sata_hba_inst->satahba_tran->sata_tran_abort
5651258Smlf 
5661258Smlf #define	SATA_RESET_DPORT_FUNC(sata_hba_inst) \
5671258Smlf 	sata_hba_inst->satahba_tran->sata_tran_reset_dport
5681258Smlf 
5691258Smlf #define	SATA_PORT_DEACTIVATE_FUNC(sata_hba_inst) \
5701258Smlf 	(sata_hba_inst->satahba_tran->sata_tran_hotplug_ops == NULL ? \
5711258Smlf 	NULL : \
5721258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hotplug_ops->\
5731258Smlf 	sata_tran_port_deactivate)
5741258Smlf 
5751258Smlf #define	SATA_PORT_ACTIVATE_FUNC(sata_hba_inst) \
5761258Smlf 	(sata_hba_inst->satahba_tran->sata_tran_hotplug_ops == NULL ? \
5771258Smlf 	NULL : \
5781258Smlf 	sata_hba_inst->satahba_tran->sata_tran_hotplug_ops->\
5791258Smlf 	sata_tran_port_activate)
5801258Smlf 
5811258Smlf #define	SATA_PROBE_PORT_FUNC(sata_hba_inst) \
5821258Smlf 	sata_hba_inst->satahba_tran->sata_tran_probe_port
5831258Smlf 
5841258Smlf #define	SATA_SELFTEST_FUNC(sata_hba_inst) \
5851258Smlf 	sata_hba_inst->satahba_tran->sata_tran_selftest
5861258Smlf 
5871258Smlf #define	SATA_CPORT_MUTEX(sata_hba_inst, cport) \
5881258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_mutex
5891258Smlf 
5901258Smlf #define	SATA_CPORT_INFO(sata_hba_inst, cport) \
5911258Smlf 	sata_hba_inst->satahba_dev_port[cport]
5921258Smlf 
5931258Smlf #define	SATA_CPORT_STATE(sata_hba_inst, cport) \
5941258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_state
5951258Smlf 
5963935Spawelw #define	SATA_CPORT_EVENT_FLAGS(sata_hba_inst, cport) \
5973935Spawelw 	sata_hba_inst->satahba_dev_port[cport]->cport_event_flags
5983935Spawelw 
5991258Smlf #define	SATA_CPORT_SCR(sata_hba_inst, cport) \
6001258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_scr
6011258Smlf 
6021258Smlf #define	SATA_CPORT_DEV_TYPE(sata_hba_inst, cport) \
6031258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_dev_type
6041258Smlf 
6051258Smlf #define	SATA_CPORT_DRV_INFO(sata_hba_inst, cport) \
6061258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_devp.cport_sata_drive
6071258Smlf 
6081258Smlf #define	SATA_CPORTINFO_DRV_TYPE(cportinfo) \
6091258Smlf 	cportinfo->cport_dev_type
6101258Smlf 
6111258Smlf #define	SATA_CPORTINFO_DRV_INFO(cportinfo) \
6121258Smlf 	cportinfo->cport_devp.cport_sata_drive
6131258Smlf 
6141258Smlf #define	SATA_CPORTINFO_PMULT_INFO(cportinfo) \
6151258Smlf 	cportinfo->cport_devp.cport_sata_pmult
6161258Smlf 
6171258Smlf #define	SATA_PMULT_INFO(sata_hba_inst, cport) \
6181258Smlf 	sata_hba_inst->satahba_dev_port[cport]->cport_devp.cport_sata_pmult
6191258Smlf 
6201258Smlf #define	SATA_NUM_PMPORTS(sata_hba_inst, cport) \
6211258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
6221258Smlf 	cport_devp.cport_sata_pmult->pmult_num_dev_ports
6231258Smlf 
624*10318SXiao-Yu.Zhang@Sun.COM #define	SATA_PMPORT_MUTEX(sata_hba_inst, cport, pmport) \
625*10318SXiao-Yu.Zhang@Sun.COM 	sata_hba_inst->satahba_dev_port[cport]->\
626*10318SXiao-Yu.Zhang@Sun.COM 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_mutex
627*10318SXiao-Yu.Zhang@Sun.COM 
6281258Smlf #define	SATA_PMPORT_INFO(sata_hba_inst, cport, pmport) \
6291258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
6301258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]
6311258Smlf 
6321258Smlf #define	SATA_PMPORT_DRV_INFO(sata_hba_inst, cport, pmport) \
6331258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
6341258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->\
6351258Smlf 	pmport_sata_drive
6361258Smlf 
6371258Smlf #define	SATA_PMPORT_STATE(sata_hba_inst, cport, pmport) \
6381258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
6391258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_state
6401258Smlf 
6411258Smlf #define	SATA_PMPORT_SCR(sata_hba_inst, cport, pmport) \
6421258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
6431258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_scr
6441258Smlf 
6451258Smlf #define	SATA_PMPORT_DEV_TYPE(sata_hba_inst, cport, pmport) \
6461258Smlf 	sata_hba_inst->satahba_dev_port[cport]->\
6471258Smlf 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_dev_type
6481258Smlf 
649*10318SXiao-Yu.Zhang@Sun.COM #define	SATA_PMPORT_EVENT_FLAGS(sata_hba_inst, cport, pmport) \
650*10318SXiao-Yu.Zhang@Sun.COM 	sata_hba_inst->satahba_dev_port[cport]->\
651*10318SXiao-Yu.Zhang@Sun.COM 	cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->\
652*10318SXiao-Yu.Zhang@Sun.COM 	pmport_event_flags
653*10318SXiao-Yu.Zhang@Sun.COM 
6545832Spawelw #define	SATA_PMPORTINFO_DRV_TYPE(pmportinfo) \
6555832Spawelw 	pmportinfo->pmport_dev_type
6565832Spawelw 
6575832Spawelw #define	SATA_PMPORTINFO_DRV_INFO(pmportinfo) \
6585832Spawelw 	pmportinfo->pmport_sata_drive
6595832Spawelw 
6601258Smlf #define	SATA_TXLT_HBA_INST(spx) \
6611258Smlf 	spx->txlt_sata_hba_inst
6621258Smlf 
6631258Smlf #define	SATA_TXLT_CPORT(spx) \
6641258Smlf 	spx->txlt_sata_pkt->satapkt_device.satadev_addr.cport
6651258Smlf 
666*10318SXiao-Yu.Zhang@Sun.COM #define	SATA_TXLT_PMPORT(spx) \
667*10318SXiao-Yu.Zhang@Sun.COM 	spx->txlt_sata_pkt->satapkt_device.satadev_addr.pmport
668*10318SXiao-Yu.Zhang@Sun.COM 
669*10318SXiao-Yu.Zhang@Sun.COM #define	SATA_TXLT_QUAL(spx) \
670*10318SXiao-Yu.Zhang@Sun.COM 	spx->txlt_sata_pkt->satapkt_device.satadev_addr.qual
671*10318SXiao-Yu.Zhang@Sun.COM 
6721258Smlf #define	SATA_TXLT_CPORT_MUTEX(spx) \
6731258Smlf 	spx->txlt_sata_hba_inst->\
6741258Smlf 	satahba_dev_port[spx->txlt_sata_pkt->\
6751258Smlf 	satapkt_device.satadev_addr.cport]->cport_mutex
6761258Smlf 
6771781Spawelw #define	SATA_TXLT_TASKQ(spx) \
6781781Spawelw 	spx->txlt_sata_hba_inst->\
6791781Spawelw 	satahba_taskq
6801781Spawelw 
6811258Smlf /*
6821258Smlf  * Minor number construction for devctl and attachment point nodes.
6831258Smlf  * All necessary information has to be encoded in NBITSMINOR32 bits.
6841258Smlf  *
6851258Smlf  * Devctl node minor number:
6861258Smlf  * ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | SATA_DEVCTL_NODE)
6871258Smlf  *
6881258Smlf  * Attachment point node minor number has to include controller
6891258Smlf  * instance (7 bits), controller port number (5 bits) and port multiplier
6901258Smlf  * device port number (4 bits) and port multiplier device port
6911258Smlf  * indicator (1 bit).  Additionally, a single bit is used to
6921258Smlf  * differentiate between attachment point node and device control node.
6931258Smlf  *
6941258Smlf  * Attachment point minor number:
6951258Smlf  * ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | SATA_AP_NODE |
6961258Smlf  * [(port_multiplier_device_port << SATA_PMULT_PORT_SHIFT) | SATA_PMULT_AP] |
6971258Smlf  * (controller_port))
6981258Smlf  *
6991258Smlf  * 17 bits are used (if 64 instances of controllers are expected)
7001258Smlf  * bit 18 is reserved for future use.
7011258Smlf  *
7021258Smlf  *   --------------------------------------------------------
7031258Smlf  *   |17|16|15|14|13|12|11|10 |09|08|07|06|05|04|03|02|01|00|
7041258Smlf  *   --------------------------------------------------------
7051258Smlf  *   | R| c| c| c| c| c| c|a/d|pm|pp|pp|pp|pp|cp|cp|cp|cp|cp|
7061258Smlf  *   --------------------------------------------------------
7071258Smlf  * Where:
7081258Smlf  * cp  - device port number on the HBA SATA controller
7091258Smlf  * pp  - device port number on the port multiplier
7101258Smlf  * pm  - 0 - target attached to controller device port
7111258Smlf  *       1 - target attached to port multiplier's device port
7121258Smlf  * a/d - 0 - devctl node
7131258Smlf  *       1 - attachment point node
7141258Smlf  * c   - controller number
7151258Smlf  * R   - reserved bit
7161258Smlf  */
7171258Smlf 
7181258Smlf #define	SATA_AP_NODE		0x400		/* Attachment Point node */
7191258Smlf #define	SATA_DEVCTL_NODE	0x000		/* DEVCTL node */
7201258Smlf #define	SATA_PMULT_AP		0x200		/* device on PMult port */
7211258Smlf #define	SATA_PMULT_PORT_SHIFT	5
7221258Smlf #define	SATA_CNTRL_INSTANCE_SHIFT 11
7231258Smlf #define	SATA_CPORT_MASK		0x1f		/* 32 device ports */
7241258Smlf #define	SATA_PMULT_PORT_MASK	0xf		/* 15 device ports */
7251258Smlf #define	SATA_CNTRL_INSTANCE_MASK 0x03F		/* 64 controllers */
7261258Smlf 
7271258Smlf /* Macro for creating devctl node minor number */
7281258Smlf #define	SATA_MAKE_DEVCTL_MINOR(controller_instance) \
7291258Smlf 	((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | \
7301258Smlf 	SATA_DEVCTL_NODE)
7311258Smlf 
7321258Smlf /* Macro for creating an attachment point node minor number */
7331258Smlf #define	SATA_MAKE_AP_MINOR(cntrl_instance, cport, pmport, qual) \
7341258Smlf 	(qual & (SATA_ADDR_PMPORT | SATA_ADDR_DPMPORT) ? \
7351258Smlf 	(((cntrl_instance) << SATA_CNTRL_INSTANCE_SHIFT) | \
7361258Smlf 	SATA_AP_NODE | SATA_PMULT_AP | \
7371258Smlf 	(pmport << SATA_PMULT_PORT_SHIFT) | cport) : \
7381258Smlf 	(((cntrl_instance) << SATA_CNTRL_INSTANCE_SHIFT) | \
7391258Smlf 	SATA_AP_NODE | cport))
7401258Smlf 
7411258Smlf /* Macro retrieving controller number from a minor number */
7421258Smlf #define	SATA_MINOR2INSTANCE(minor) \
7431258Smlf 	((minor >> SATA_CNTRL_INSTANCE_SHIFT) & SATA_CNTRL_INSTANCE_MASK)
7441258Smlf 
7451529Spawelw /*
7461529Spawelw  * Macro for creating an attachment point number from sata address.
7471529Spawelw  * Address qualifier has to be one of:
7481529Spawelw  * SATA_ADDR_DCPORT, SATA_ADDR_DPMPORT, SATA_ADDR_CPORT or SATA_ADDR_PMPORT
7491529Spawelw  */
7501529Spawelw #define	SATA_MAKE_AP_NUMBER(cport, pmport, qual) \
7511529Spawelw 	((qual & (SATA_ADDR_PMPORT | SATA_ADDR_DPMPORT)) ? \
7521529Spawelw 	(SATA_PMULT_AP | (pmport << SATA_PMULT_PORT_SHIFT) | cport) : \
7531529Spawelw 	(cport))
7541258Smlf 
7551258Smlf /*
7561258Smlf  * SCSI target number format
7571258Smlf  *
7581258Smlf  *   -------------------------------
7591258Smlf  *   | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|    Bit number
7601258Smlf  *   -------------------------------
7611258Smlf  *   |pm|pp|pp|pp|pp|cp|cp|cp|cp|cp|
7621258Smlf  *   -------------------------------
7631258Smlf  * Where:
7641258Smlf  * cp  - device port number on the HBA SATA controller
7651258Smlf  * pp  - device port number on the port multiplier
7661258Smlf  * pm  - 0 - target attached to controller device port
7671258Smlf  *       1 - target attached to port multiplier's device port
7681258Smlf  */
7691258Smlf 
7701258Smlf /* SATA ports to SCSI target number translation */
7711258Smlf 
7721258Smlf #define	SATA_TO_SCSI_TARGET(cport, pmport, qual) \
7731258Smlf 	(qual == SATA_ADDR_DCPORT ? cport : \
7741258Smlf 	(cport | (pmport << SATA_PMULT_PORT_SHIFT) | SATA_PMULT_AP))
7751258Smlf 
7761258Smlf /* SCSI target number to SATA cntrl/pmport/cport translations */
7771258Smlf #define	SCSI_TO_SATA_CPORT(scsi_target) \
7781258Smlf 	(scsi_target & SATA_CPORT_MASK)
7791258Smlf 
7801258Smlf #define	SCSI_TO_SATA_PMPORT(scsi_target) \
7811258Smlf 	((scsi_target >> SATA_PMULT_PORT_SHIFT) & SATA_PMULT_PORT_MASK)
7821258Smlf 
7831258Smlf #define	SCSI_TO_SATA_ADDR_QUAL(scsi_target) \
7841258Smlf 	((scsi_target & SATA_PMULT_AP) ? SATA_ADDR_DPMPORT : \
7851258Smlf 	SATA_ADDR_DCPORT)
7861258Smlf 
7871258Smlf 
7881258Smlf /* Debug flags */
7891258Smlf #if	DEBUG
7901258Smlf 
7911258Smlf #define	SATA_DEBUG
7921258Smlf #define	SATA_DBG_SCSI_IF	1
7931258Smlf #define	SATA_DBG_HBA_IF		2
7941258Smlf #define	SATA_DBG_NODES		4
7951258Smlf #define	SATA_DBG_IOCTL_IF	8
7961258Smlf #define	SATA_DBG_EVENTS		0x10
7971258Smlf #define	SATA_DBG_EVENTS_PROC	0x20
7981258Smlf #define	SATA_DBG_EVENTS_PROCPST	0x40
7991258Smlf #define	SATA_DBG_EVENTS_CNTRL	0x80
8001258Smlf #define	SATA_DBG_EVENTS_DAEMON	0x100
8011258Smlf #define	SATA_DBG_DMA_SETUP	0x400
8022734Spawelw #define	SATA_DBG_DEV_SETTINGS	0x800
8034862SUnknown #define	SATA_DBG_ATAPI		0x1000
8044862SUnknown #define	SATA_DBG_ATAPI_PACKET	0x8000
8057510SPawel.Wojcik@Sun.COM #define	SATA_DBG_INTR_CTX	0x10000
806*10318SXiao-Yu.Zhang@Sun.COM #define	SATA_DBG_PMULT		0x20000
8074862SUnknown 
8084862SUnknown typedef struct sata_atapi_cmd {
8094862SUnknown 	uint8_t acdb[SATA_ATAPI_MAX_CDB_LEN];
8104862SUnknown 	uint8_t arqs[SATA_ATAPI_RQSENSE_LEN];
8114862SUnknown 	uint_t sata_pkt_reason;
8124862SUnknown 	uint_t scsi_pkt_reason;
8134862SUnknown } sata_atapi_cmd_t;
8141258Smlf 
8151258Smlf /* Debug macros */
8161258Smlf #define	SATADBG1(flag, sata, format, arg1) \
8171258Smlf 	if (sata_debug_flags & (flag)) { \
8181258Smlf 		sata_log(sata, CE_CONT, format, arg1); \
8191258Smlf 	}
8201258Smlf 
8211258Smlf #define	SATADBG2(flag, sata, format, arg1, arg2) \
8221258Smlf 	if (sata_debug_flags & (flag)) { \
8231258Smlf 		sata_log(sata, CE_CONT, format, arg1, arg2); \
8241258Smlf 	}
8251258Smlf 
8261258Smlf #define	SATADBG3(flag, sata, format, arg1, arg2, arg3) \
8271258Smlf 	if (sata_debug_flags & (flag)) { \
8281258Smlf 		sata_log(sata, CE_CONT, format, arg1, arg2, arg3); \
8291258Smlf 	}
8301258Smlf #else
8311258Smlf 
8321258Smlf #define	SATADBG1(flag, dip, frmt, arg1)
8331258Smlf #define	SATADBG2(flag, dip, frmt, arg1, arg2)
8341258Smlf #define	SATADBG3(flag, dip, frmt, arg1, arg2, arg3)
8351258Smlf 
8361258Smlf #endif
8371258Smlf 
838*10318SXiao-Yu.Zhang@Sun.COM /* sata_rev_tag 1.44 */
8397510SPawel.Wojcik@Sun.COM 
8401258Smlf #ifdef	__cplusplus
8411258Smlf }
8421258Smlf #endif
8431258Smlf 
8441258Smlf #endif /* _SATA_H */
845