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 /* 235832Spawelw * Copyright 2008 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 46*6539Spawelw /* Common flags specifying current state of a port or an attached drive. */ 47*6539Spawelw #define SATA_STATE_PROBING 0x000001 48*6539Spawelw #define SATA_STATE_PROBED 0x000002 49*6539Spawelw 501258Smlf /* Statistics counters */ 511258Smlf struct sata_port_stats { 521258Smlf uint64_t link_lost; /* event counter */ 531258Smlf uint64_t link_established; /* event counter */ 541258Smlf uint64_t device_attached; /* event counter */ 551258Smlf uint64_t device_detached; /* event counter */ 561258Smlf uint64_t port_reset; /* event counter */ 571258Smlf uint64_t port_pwr_changed; /* event counter */ 581258Smlf }; 591258Smlf 601258Smlf typedef struct sata_port_stats sata_port_stats_t; 611258Smlf 621258Smlf struct sata_drive_stats { 631258Smlf uint64_t media_error; /* available ??? */ 641258Smlf uint64_t drive_reset; /* event counter */ 651258Smlf } sata_drv_stats_t; 661258Smlf 671258Smlf typedef struct sata_drive_stats sata_drive_stats_t; 681258Smlf 691258Smlf struct sata_ctrl_stats { 701258Smlf uint64_t ctrl_reset; /* event counter */ 711258Smlf uint64_t ctrl_pwr_change; /* event counter */ 721258Smlf }; 731258Smlf 741258Smlf typedef struct sata_ctrl_stats sata_ctrl_stats_t; 751258Smlf 761258Smlf 771258Smlf /* 781258Smlf * SATA HBA instance info structure 791258Smlf */ 801258Smlf struct sata_hba_inst { 811258Smlf dev_info_t *satahba_dip; /* this HBA instance devinfo */ 821258Smlf struct sata_hba_inst *satahba_next; /* ptr to next sata_hba_inst */ 831258Smlf struct sata_hba_inst *satahba_prev; /* ptr to prev sata_hba_inst */ 841258Smlf struct scsi_hba_tran *satahba_scsi_tran; /* scsi_hba_tran */ 851258Smlf struct sata_hba_tran *satahba_tran; /* sata_hba_tran */ 861258Smlf kmutex_t satahba_mutex; /* sata hba cntrl mutex */ 871781Spawelw struct taskq *satahba_taskq; /* cmd completion task queue */ 881258Smlf 891258Smlf /* 901258Smlf * HBA event flags: 911258Smlf * SATA_EVNT_MAIN 921258Smlf * SATA_EVNT_PWR_LEVEL_CHANGED 931258Smlf * SATA_EVNT_SKIP 941258Smlf */ 951258Smlf uint_t satahba_event_flags; 961258Smlf 971258Smlf struct sata_cport_info *satahba_dev_port[SATA_MAX_CPORTS]; 981258Smlf 991258Smlf /* 1001258Smlf * DEVCTL open flag: 1011258Smlf * SATA_DEVCTL_SOPENED 1021258Smlf * SATA_DEVCTL_EXOPENED 1031258Smlf */ 1041258Smlf uint_t satahba_open_flag; /* shared open flag */ 1051258Smlf struct sata_ctrl_stats satahba_stats; /* HBA cntrl statistics */ 1061258Smlf 1071258Smlf uint_t satahba_attached; /* HBA attaching: */ 1081258Smlf /* 0 - not completed */ 1091258Smlf /* 1 - completed */ 1101258Smlf }; 1111258Smlf 1121258Smlf typedef struct sata_hba_inst sata_hba_inst_t; 1131258Smlf 1141258Smlf /* 1151258Smlf * SATA controller's device port info and state. 1161258Smlf * This structure is pointed to by the sata_hba_inst.satahba_dev_port[x] 1171258Smlf * where x is a device port number. 1181258Smlf * cport_state holds port state flags, defined in sata_hba.h file. 1191258Smlf * cport_event_flags holds SATA_EVNT_* flags defined in this file and in 1201258Smlf * sata_hba.h file. 1211258Smlf * cport_dev_type holds SATA_DTYPE_* types defined in sata_hba.h file. 1221258Smlf */ 1231258Smlf struct sata_cport_info { 1241258Smlf sata_address_t cport_addr; /* this port SATA address */ 1251258Smlf kmutex_t cport_mutex; /* port mutex */ 1261258Smlf 1271258Smlf /* 1281258Smlf * Port state flags 1291258Smlf * SATA_STATE_UNKNOWN 1301258Smlf * SATA_STATE_PROBING 1311258Smlf * SATA_STATE_PROBED 1321258Smlf * SATA_STATE_READY 1331258Smlf * SATA_PSTATE_PWRON 1341258Smlf * SATA_PSTATE_PWROFF 1351258Smlf * SATA_PSTATE_SHUTDOWN 1361258Smlf * SATA_PSTATE_FAILED 1371258Smlf */ 1381258Smlf uint32_t cport_state; 1391258Smlf 1401258Smlf /* 1411258Smlf * Port event flags: 1421258Smlf * SATA_EVNT_DEVICE_ATTACHED 1431258Smlf * SATA_EVNT_DEVICE_DETACHED 1441258Smlf * SATA_EVNT_LINK_LOST 1451258Smlf * SATA_EVNT_LINK_ESTABLISHED 1461258Smlf * SATA_EVNT_PORT_FAILED 1471258Smlf * SATA_EVNT_PWR_LEVEL_CHANGED 1481258Smlf */ 1491258Smlf uint32_t cport_event_flags; 1501258Smlf 1511258Smlf struct sata_port_scr cport_scr; /* Port status and ctrl regs */ 1521258Smlf 1531258Smlf /* 1541258Smlf * Attached device type: 1551258Smlf * SATA_DTYPE_NONE 1561258Smlf * SATA_DTYPE_ATADISK 1571258Smlf * SATA_DTYPE_ATAPICD 1581258Smlf * SATA_DTYPE_ATAPINONCD 1591258Smlf * SATA_DTYPE_PMULT 1601258Smlf * SATA_DTYPE_UNKNOWN 1611258Smlf */ 1621258Smlf uint32_t cport_dev_type; 1631258Smlf union { 1641258Smlf struct sata_drive_info *cport_sata_drive; /* Attached drive info */ 1651258Smlf struct sata_pmult_info *cport_sata_pmult; /* Attached Port Mult */ 1661258Smlf } cport_devp; 1671258Smlf /* lbolt value at link lost */ 1681258Smlf clock_t cport_link_lost_time; 1692960Spawelw /* lbolt value @ dev attached */ 1702960Spawelw clock_t cport_dev_attach_time; 1711258Smlf 1721258Smlf struct sata_port_stats cport_stats; /* Port statistics */ 1733935Spawelw 1743935Spawelw boolean_t cport_tgtnode_clean; /* Target node usable */ 1751258Smlf }; 1761258Smlf 1771258Smlf typedef struct sata_cport_info sata_cport_info_t; 1781258Smlf 1791258Smlf /* 1801258Smlf * Attached SATA drive info and state. 1811258Smlf * This structure is pointed to by sata_cport_info's cport_sata_drive field 1821258Smlf * when a drive is attached directly to a controller device port. 1831258Smlf */ 1841258Smlf struct sata_drive_info { 1851258Smlf sata_address_t satadrv_addr; /* this drive SATA address */ 1861258Smlf 1871258Smlf /* 1881258Smlf * Drive state flags 1891258Smlf * SATA_STATE_UNKNOWN 1901258Smlf * SATA_STATE_PROBING 1911258Smlf * SATA_STATE_PROBED 1921258Smlf * SATA_STATE_READY 1931258Smlf * SATA_DSTATE_PWR_ACTIVE 1941258Smlf * SATA_DSTATE_PWR_IDLE 1951258Smlf * SATA_DSTATE_RESET 1961258Smlf * SATA_DSTATE_FAILED 1971258Smlf */ 1981258Smlf uint32_t satadrv_state; 1991258Smlf 2001258Smlf /* 2011258Smlf * drive event flags: 2021258Smlf * SATA_EVNT_DRIVE_RESET 2031258Smlf */ 2041258Smlf uint32_t satadrv_event_flags; 205*6539Spawelw /* 206*6539Spawelw * lbolt value @ start of 207*6539Spawelw * device reset processing 208*6539Spawelw */ 209*6539Spawelw clock_t satadrv_reset_time; 2101258Smlf /* 2111258Smlf * Attached device type: 2121258Smlf * SATA_DTYPE_ATADISK 2131258Smlf * SATA_DTYPE_ATAPICD 2141258Smlf * SATA_DTYPE_ATAPINONCD 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 */ 2301258Smlf }; 2311258Smlf 2321258Smlf typedef struct sata_drive_info sata_drive_info_t; 2331258Smlf 2341258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_drive_info)) 2351258Smlf 2361258Smlf 2371258Smlf /* Port Multiplier & host port info and state */ 2381258Smlf struct sata_pmult_info { 2391258Smlf sata_address_t pmult_addr; /* this PMult SATA Address */ 2401258Smlf kmutex_t pmult_mutex; /* pmult (host port) mutex */ 2411258Smlf 2421258Smlf /* 2431258Smlf * PMult state flags 2441258Smlf * SATA_STATE_UNKNOWN 2451258Smlf * SATA_STATE_PROBING 2461258Smlf * SATA_STATE_PROBED 2471258Smlf * SATA_STATE_READY 2481258Smlf * SATA_PSTATE_FAILED 2491258Smlf */ 2501258Smlf uint32_t pmult_state; 2511258Smlf uint32_t pmult_event_flags; /* Undefined for now */ 2521258Smlf struct sata_port_scr pmult_scr; /* Host port SCR block */ 2531258Smlf uint32_t pmult_num_dev_ports; /* Number of data ports */ 2541258Smlf struct sata_pmport_info *pmult_dev_port[SATA_MAX_PMPORTS - 1]; 2551258Smlf }; 2561258Smlf 2571258Smlf typedef struct sata_pmult_info sata_pmult_info_t; 2581258Smlf 2591258Smlf /* Port Multiplier's device port info & state */ 2601258Smlf struct sata_pmport_info { 2611258Smlf sata_address_t pmport_addr; /* this SATA port address */ 2621258Smlf kmutex_t pmport_mutex; /* pmult device port mutex */ 2631258Smlf 2641258Smlf /* 2651258Smlf * Port state flags 2661258Smlf * SATA_STATE_UNKNOWN 2671258Smlf * SATA_STATE_PROBING 2681258Smlf * SATA_STATE_PROBED 2691258Smlf * SATA_STATE_READY 2701258Smlf * SATA_PSTATE_PWRON 2711258Smlf * SATA_PSTATE_PWROFF 2721258Smlf * SATA_PSTATE_SHUTDOWN 2731258Smlf * SATA_PSTATE_FAILED 2741258Smlf */ 2751258Smlf uint32_t pmport_state; 2761258Smlf 2771258Smlf /* 2781258Smlf * Port event flags: 2791258Smlf * SATA_EVNT_DEVICE_ATTACHED 2801258Smlf * SATA_EVNT_DEVICE_DETACHED 2811258Smlf * SATA_EVNT_LINK_LOST 2821258Smlf * SATA_EVNT_LINK_ESTABLISHED 2831258Smlf * SATA_EVNT_PORT_FAILED 2841258Smlf * SATA_EVNT_PWR_LEVEL_CHANGED 2851258Smlf */ 2861258Smlf uint32_t pmport_event_flags; 2871258Smlf 2881258Smlf struct sata_port_scr pmport_scr; /* PMult device port scr */ 2891258Smlf 2901258Smlf /* 2911258Smlf * Attached device type: 2921258Smlf * SATA_DTYPE_NONE 2931258Smlf * SATA_DTYPE_ATADISK 2941258Smlf * SATA_DTYPE_ATAPICD 2951258Smlf * SATA_DTYPE_ATAPINONCD 2961258Smlf * SATA_DTYPE_UNKNOWN 2971258Smlf */ 2981258Smlf uint32_t pmport_dev_type; 2991258Smlf 3001258Smlf struct sata_drive_info *pmport_sata_drive; /* Attached drive info */ 3011258Smlf 3021258Smlf /* lbolt value at link lost */ 3031258Smlf clock_t pmport_link_lost_time; 3042960Spawelw /* lbolt value @ dev attached */ 3052960Spawelw clock_t pmport_dev_attach_time; 3061258Smlf 3071258Smlf struct sata_port_stats pmport_stats; /* Port statistics */ 3083935Spawelw 3093935Spawelw boolean_t pmport_tgtnode_clean; /* Target node usable */ 3101258Smlf }; 3111258Smlf 3121258Smlf typedef struct sata_pmport_info sata_pmport_info_t; 3131258Smlf 3141258Smlf /* 3151258Smlf * Port SSTATUS register (sata_port_scr sport_sstatus field). 3161258Smlf * Link bits are valid only in port active state. 3171258Smlf */ 3181258Smlf #define SATA_PORT_DEVLINK_UP 0x00000103 /* Link with dev established */ 3191258Smlf #define SATA_PORT_DEVLINK_UP_MASK 0x0000010F /* Mask for link bits */ 3201258Smlf 3211258Smlf /* 3221258Smlf * Port state clear mask (cport_state and pmport_state fields). 3231258Smlf * SATA_PSTATE_SHUTDOWN and power state are preserved. 3241258Smlf */ 3251258Smlf #define SATA_PORT_STATE_CLEAR_MASK (~(SATA_PSTATE_SHUTDOWN)) 3261258Smlf 3271258Smlf /* 3281258Smlf * Valid i.e.supported device types mask (cport_dev_type, satadrv_type, 3291258Smlf * pmult_dev_type fields). 3304862SUnknown * ATA disks and ATAPI CD/DVD now. 3311258Smlf */ 3324862SUnknown #define SATA_VALID_DEV_TYPE (SATA_DTYPE_ATADISK | \ 3334862SUnknown SATA_DTYPE_ATAPICD) 3341258Smlf 3351258Smlf /* 3361258Smlf * Device feature_support (satadrv_features_support) 3371258Smlf */ 3381258Smlf #define SATA_DEV_F_DMA 0x01 3391258Smlf #define SATA_DEV_F_LBA28 0x02 3401258Smlf #define SATA_DEV_F_LBA48 0x04 3411258Smlf #define SATA_DEV_F_NCQ 0x08 3421258Smlf #define SATA_DEV_F_SATA1 0x10 3431258Smlf #define SATA_DEV_F_SATA2 0x20 3441940Sls24207 #define SATA_DEV_F_TCQ 0x40 /* Non NCQ tagged queuing */ 3451258Smlf 3461258Smlf /* 3473821Sls24207 * Device features enabled (satadrv_features_enabled) 3483821Sls24207 */ 3493821Sls24207 #define SATA_DEV_F_E_TAGGED_QING 0x01 /* Tagged queuing enabled */ 3503821Sls24207 #define SATA_DEV_F_E_UNTAGGED_QING 0x02 /* Untagged queuing enabled */ 3513821Sls24207 3523821Sls24207 /* 3531258Smlf * Drive settings flags (satdrv_settings) 3541258Smlf */ 3551258Smlf #define SATA_DEV_READ_AHEAD 0x0001 /* Read Ahead enabled */ 3561258Smlf #define SATA_DEV_WRITE_CACHE 0x0002 /* Write cache ON */ 3574862SUnknown #define SATA_DEV_DMA 0x0004 /* DMA selected */ 3581258Smlf #define SATA_DEV_SERIAL_FEATURES 0x8000 /* Serial ATA feat. enabled */ 3591258Smlf #define SATA_DEV_ASYNCH_NOTIFY 0x2000 /* Asynch-event enabled */ 3604862SUnknown #define SATA_DEV_RMSN 0x0100 /* Rem Media Stat Notfc enbl */ 3611258Smlf 3621258Smlf /* 3631258Smlf * Internal event and flags. 3641258Smlf * These flags are set in the *_event_flags fields of various structures. 3651258Smlf * Events and lock flags defined below are used internally by the 3661258Smlf * SATA framework (they are not reported by SATA HBA drivers). 3671258Smlf */ 3681258Smlf #define SATA_EVNT_MAIN 0x80000000 3691258Smlf #define SATA_EVNT_SKIP 0x40000000 3701258Smlf #define SATA_EVNT_INPROC_DEVICE_RESET 0x08000000 3711258Smlf #define SATA_EVNT_CLEAR_DEVICE_RESET 0x04000000 3723935Spawelw #define SATA_EVNT_TARGET_NODE_CLEANUP 0x00000100 3735832Spawelw #define SATA_EVNT_AUTOONLINE_DEVICE 0x00000200 3741258Smlf 3751258Smlf /* 3761258Smlf * Lock flags - used to serialize configuration operations 3771258Smlf * on ports and devices. 3781258Smlf * SATA_EVNT_LOCK_PORT_BUSY is set by event daemon to prevent 3791258Smlf * simultaneous cfgadm operations. 3801258Smlf * SATA_APCTL_LOCK_PORT_BUSY is set by cfgadm ioctls to prevent 3811258Smlf * simultaneous event processing. 3821258Smlf */ 3831258Smlf #define SATA_EVNT_LOCK_PORT_BUSY 0x00800000 3841258Smlf #define SATA_APCTL_LOCK_PORT_BUSY 0x00400000 3851258Smlf 3861258Smlf /* Mask for port events */ 3871258Smlf #define SATA_EVNT_PORT_EVENTS (SATA_EVNT_DEVICE_ATTACHED | \ 3881258Smlf SATA_EVNT_DEVICE_DETACHED | \ 3891258Smlf SATA_EVNT_LINK_LOST | \ 3901258Smlf SATA_EVNT_LINK_ESTABLISHED | \ 3913935Spawelw SATA_EVNT_PORT_FAILED | \ 3925832Spawelw SATA_EVNT_TARGET_NODE_CLEANUP | \ 3935832Spawelw SATA_EVNT_AUTOONLINE_DEVICE) 3941258Smlf /* Mask for drive events */ 3953935Spawelw #define SATA_EVNT_DRIVE_EVENTS (SATA_EVNT_DEVICE_RESET | \ 3963935Spawelw SATA_EVNT_INPROC_DEVICE_RESET) 3971258Smlf #define SATA_EVNT_CONTROLLER_EVENTS SATA_EVNT_PWR_LEVEL_CHANGED 3981258Smlf 3995832Spawelw /* Delays and timeout duration definitions */ 4001258Smlf #define SATA_EVNT_DAEMON_SLEEP_TIME 50000 /* 50 ms */ 4011258Smlf #define SATA_EVNT_DAEMON_TERM_TIMEOUT 100000 /* 100 ms */ 4021258Smlf #define SATA_EVNT_DAEMON_TERM_WAIT 60000000 /* 60 s */ 4031258Smlf #define SATA_EVNT_LINK_LOST_TIMEOUT 1000000 /* 1 s */ 404*6539Spawelw 405*6539Spawelw #define SATA_DEV_IDENTIFY_TIMEOUT 60000000 /* 60 s, device enumeration */ 406*6539Spawelw #define SATA_DEV_REPROBE_TIMEOUT 30000000 /* 30 s, dev resp after rst */ 407*6539Spawelw #define SATA_DEV_RETRY_DLY 10000 /* 10 ms */ 4081258Smlf 4092960Spawelw /* DEVICE IDENTIFY and device initialization retry delay */ 4102960Spawelw #define SATA_DEV_IDENTIFY_RETRY 1 4112960Spawelw #define SATA_DEV_IDENTIFY_NORETRY 0 4121258Smlf 4131258Smlf /* 4141258Smlf * sata_scsi's hba_open_flag: field indicating open devctl instance. 4151258Smlf * 0 = closed, 1 = shared open, 2 = exclusive open. 4161258Smlf */ 4171258Smlf #define SATA_DEVCTL_CLOSED 0 4181258Smlf #define SATA_DEVCTL_SOPENED 1 4191258Smlf #define SATA_DEVCTL_EXOPENED 2 4201258Smlf 4211258Smlf /* 4221258Smlf * sata_pkt_txlate structure contains info about resources allocated 4231258Smlf * for the packet 4241258Smlf * Address of this structure is stored in scsi_pkt.pkt_ha_private and 4251258Smlf * in sata_pkt.sata_hba_private fields, so all three strucures are 4261258Smlf * cross-linked, with sata_pkt_txlate as a centerpiece. 4271258Smlf */ 4281258Smlf 4291258Smlf typedef struct sata_pkt_txlate { 4301258Smlf struct sata_hba_inst *txlt_sata_hba_inst; 4311258Smlf struct scsi_pkt *txlt_scsi_pkt; 4321258Smlf struct sata_pkt *txlt_sata_pkt; 4331258Smlf ddi_dma_handle_t txlt_buf_dma_handle; 4341258Smlf uint_t txlt_flags; /* data-in / data-out */ 4351258Smlf uint_t txlt_num_dma_win; /* number of DMA windows */ 4361258Smlf uint_t txlt_cur_dma_win; /* current DMA window */ 4371258Smlf 4381258Smlf /* cookies in the current DMA window */ 4391258Smlf uint_t txlt_curwin_num_dma_cookies; 4401258Smlf 4413935Spawelw /* processed dma cookies in current DMA win */ 4421258Smlf uint_t txlt_curwin_processed_dma_cookies; 4431258Smlf size_t txlt_total_residue; 4443935Spawelw ddi_dma_cookie_t txlt_dma_cookie; /* default dma cookie */ 4451258Smlf int txlt_dma_cookie_list_len; /* alloc list len */ 4461258Smlf ddi_dma_cookie_t *txlt_dma_cookie_list; /* dma cookie list */ 4471258Smlf int txlt_num_dma_cookies; /* dma cookies in list */ 4482539Spawelw 4492539Spawelw /* temporary buffer access handle */ 4502539Spawelw ddi_acc_handle_t txlt_tmp_buf_handle; 4512539Spawelw caddr_t txlt_tmp_buf; /* temp buffer address */ 4521258Smlf } sata_pkt_txlate_t; 4531258Smlf 4541258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_pkt_txlate)) 4551258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", scsi_pkt)) 4561258Smlf 4571258Smlf 4581258Smlf /* 4591258Smlf * Additional scsi sense code definitions. 4604862SUnknown * These definition should eventually be moved to scsi header file 4614862SUnknown * usr/src/uts/common/sys/scsi/generic/sense.h 4621258Smlf */ 4634862SUnknown #define SD_SCSI_ASC_NO_ADD_SENSE 0x00 4644862SUnknown #define SD_SCSI_ASC_LU_NOT_READY 0x04 4655832Spawelw #define SD_SCSI_ASC_WRITE_ERR 0x0c 4665832Spawelw #define SD_SCSI_ASC_UNREC_READ_ERR 0x11 4674862SUnknown #define SD_SCSI_ASC_INVALID_COMMAND_CODE 0x20 4684862SUnknown #define SD_SCSI_ASC_LBA_OUT_OF_RANGE 0x21 4694862SUnknown #define SD_SCSI_ASC_INVALID_FIELD_IN_CDB 0x24 4704862SUnknown #define SD_SCSI_ASC_INVALID_FIELD_IN_PARAMS_LIST 0x26 4714862SUnknown #define SD_SCSI_ASC_RESET 0x29 4724862SUnknown #define SD_SCSI_ASC_SAVING_PARAMS_NOT_SUPPORTED 0x39 4731258Smlf 4741258Smlf 4751258Smlf /* SCSI defs missing from scsi headers */ 4761258Smlf /* Missing from sys/scsi/generic/commands.h */ 4771258Smlf #define SCMD_SYNCHRONIZE_CACHE_G1 0x91 4781258Smlf /* 4791258Smlf * Missing from sys/scsi/impl/mode.h, although defined 4801258Smlf * in sys/scsi/targets/sddefs.h as MODEPAGE_ERR_RECOV 4811258Smlf */ 4821258Smlf #define MODEPAGE_RW_ERRRECOV 0x01 /* read/write recovery */ 4831258Smlf 4841258Smlf /* 4851258Smlf * Macros for accessing various structure fields 4861258Smlf */ 4871258Smlf 4881258Smlf #define SATA_TRAN(sata_hba_inst) \ 4891258Smlf sata_hba_inst->satahba_tran 4901258Smlf 4911258Smlf #define SATA_DIP(sata_hba_inst) \ 4921258Smlf sata_hba_inst->satahba_dip 4931258Smlf 4941258Smlf #define SATA_NUM_CPORTS(sata_hba_inst) \ 4951258Smlf sata_hba_inst->satahba_tran->sata_tran_hba_num_cports 4961258Smlf 4971258Smlf #define SATA_QDEPTH(sata_hba_inst) \ 4981258Smlf sata_hba_inst->satahba_tran->sata_tran_hba_qdepth 4991258Smlf 5001258Smlf #define SATA_FEATURES(sata_hba_inst) \ 5011258Smlf sata_hba_inst->satahba_tran->sata_tran_hba_features_support 5021258Smlf 5031258Smlf #define SATA_DMA_ATTR(sata_hba_inst) \ 5041258Smlf sata_hba_inst->satahba_tran->sata_tran_hba_dma_attr 5051258Smlf 5061258Smlf #define SATA_START_FUNC(sata_hba_inst) \ 5071258Smlf sata_hba_inst->satahba_tran->sata_tran_start 5081258Smlf 5091258Smlf #define SATA_ABORT_FUNC(sata_hba_inst) \ 5101258Smlf sata_hba_inst->satahba_tran->sata_tran_abort 5111258Smlf 5121258Smlf #define SATA_RESET_DPORT_FUNC(sata_hba_inst) \ 5131258Smlf sata_hba_inst->satahba_tran->sata_tran_reset_dport 5141258Smlf 5151258Smlf #define SATA_PORT_DEACTIVATE_FUNC(sata_hba_inst) \ 5161258Smlf (sata_hba_inst->satahba_tran->sata_tran_hotplug_ops == NULL ? \ 5171258Smlf NULL : \ 5181258Smlf sata_hba_inst->satahba_tran->sata_tran_hotplug_ops->\ 5191258Smlf sata_tran_port_deactivate) 5201258Smlf 5211258Smlf #define SATA_PORT_ACTIVATE_FUNC(sata_hba_inst) \ 5221258Smlf (sata_hba_inst->satahba_tran->sata_tran_hotplug_ops == NULL ? \ 5231258Smlf NULL : \ 5241258Smlf sata_hba_inst->satahba_tran->sata_tran_hotplug_ops->\ 5251258Smlf sata_tran_port_activate) 5261258Smlf 5271258Smlf #define SATA_PROBE_PORT_FUNC(sata_hba_inst) \ 5281258Smlf sata_hba_inst->satahba_tran->sata_tran_probe_port 5291258Smlf 5301258Smlf #define SATA_SELFTEST_FUNC(sata_hba_inst) \ 5311258Smlf sata_hba_inst->satahba_tran->sata_tran_selftest 5321258Smlf 5331258Smlf #define SATA_CPORT_MUTEX(sata_hba_inst, cport) \ 5341258Smlf sata_hba_inst->satahba_dev_port[cport]->cport_mutex 5351258Smlf 5361258Smlf #define SATA_CPORT_INFO(sata_hba_inst, cport) \ 5371258Smlf sata_hba_inst->satahba_dev_port[cport] 5381258Smlf 5391258Smlf #define SATA_CPORT_STATE(sata_hba_inst, cport) \ 5401258Smlf sata_hba_inst->satahba_dev_port[cport]->cport_state 5411258Smlf 5423935Spawelw #define SATA_CPORT_EVENT_FLAGS(sata_hba_inst, cport) \ 5433935Spawelw sata_hba_inst->satahba_dev_port[cport]->cport_event_flags 5443935Spawelw 5451258Smlf #define SATA_CPORT_SCR(sata_hba_inst, cport) \ 5461258Smlf sata_hba_inst->satahba_dev_port[cport]->cport_scr 5471258Smlf 5481258Smlf #define SATA_CPORT_DEV_TYPE(sata_hba_inst, cport) \ 5491258Smlf sata_hba_inst->satahba_dev_port[cport]->cport_dev_type 5501258Smlf 5511258Smlf #define SATA_CPORT_DRV_INFO(sata_hba_inst, cport) \ 5521258Smlf sata_hba_inst->satahba_dev_port[cport]->cport_devp.cport_sata_drive 5531258Smlf 5541258Smlf #define SATA_CPORTINFO_DRV_TYPE(cportinfo) \ 5551258Smlf cportinfo->cport_dev_type 5561258Smlf 5571258Smlf #define SATA_CPORTINFO_DRV_INFO(cportinfo) \ 5581258Smlf cportinfo->cport_devp.cport_sata_drive 5591258Smlf 5601258Smlf #define SATA_CPORTINFO_PMULT_INFO(cportinfo) \ 5611258Smlf cportinfo->cport_devp.cport_sata_pmult 5621258Smlf 5631258Smlf #define SATA_PMULT_INFO(sata_hba_inst, cport) \ 5641258Smlf sata_hba_inst->satahba_dev_port[cport]->cport_devp.cport_sata_pmult 5651258Smlf 5661258Smlf #define SATA_NUM_PMPORTS(sata_hba_inst, cport) \ 5671258Smlf sata_hba_inst->satahba_dev_port[cport]->\ 5681258Smlf cport_devp.cport_sata_pmult->pmult_num_dev_ports 5691258Smlf 5701258Smlf #define SATA_PMPORT_INFO(sata_hba_inst, cport, pmport) \ 5711258Smlf sata_hba_inst->satahba_dev_port[cport]->\ 5721258Smlf cport_devp.cport_sata_pmult->pmult_dev_port[pmport] 5731258Smlf 5741258Smlf #define SATA_PMPORT_DRV_INFO(sata_hba_inst, cport, pmport) \ 5751258Smlf sata_hba_inst->satahba_dev_port[cport]->\ 5761258Smlf cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->\ 5771258Smlf pmport_sata_drive 5781258Smlf 5791258Smlf #define SATA_PMPORT_STATE(sata_hba_inst, cport, pmport) \ 5801258Smlf sata_hba_inst->satahba_dev_port[cport]->\ 5811258Smlf cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_state 5821258Smlf 5831258Smlf #define SATA_PMPORT_SCR(sata_hba_inst, cport, pmport) \ 5841258Smlf sata_hba_inst->satahba_dev_port[cport]->\ 5851258Smlf cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_scr 5861258Smlf 5871258Smlf #define SATA_PMPORT_DEV_TYPE(sata_hba_inst, cport, pmport) \ 5881258Smlf sata_hba_inst->satahba_dev_port[cport]->\ 5891258Smlf cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_dev_type 5901258Smlf 5915832Spawelw #define SATA_PMPORTINFO_DRV_TYPE(pmportinfo) \ 5925832Spawelw pmportinfo->pmport_dev_type 5935832Spawelw 5945832Spawelw #define SATA_PMPORTINFO_DRV_INFO(pmportinfo) \ 5955832Spawelw pmportinfo->pmport_sata_drive 5965832Spawelw 5971258Smlf #define SATA_TXLT_HBA_INST(spx) \ 5981258Smlf spx->txlt_sata_hba_inst 5991258Smlf 6001258Smlf #define SATA_TXLT_CPORT(spx) \ 6011258Smlf spx->txlt_sata_pkt->satapkt_device.satadev_addr.cport 6021258Smlf 6031258Smlf #define SATA_TXLT_CPORT_MUTEX(spx) \ 6041258Smlf spx->txlt_sata_hba_inst->\ 6051258Smlf satahba_dev_port[spx->txlt_sata_pkt->\ 6061258Smlf satapkt_device.satadev_addr.cport]->cport_mutex 6071258Smlf 6081781Spawelw #define SATA_TXLT_TASKQ(spx) \ 6091781Spawelw spx->txlt_sata_hba_inst->\ 6101781Spawelw satahba_taskq 6111781Spawelw 6121258Smlf /* 6131258Smlf * Minor number construction for devctl and attachment point nodes. 6141258Smlf * All necessary information has to be encoded in NBITSMINOR32 bits. 6151258Smlf * 6161258Smlf * Devctl node minor number: 6171258Smlf * ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | SATA_DEVCTL_NODE) 6181258Smlf * 6191258Smlf * Attachment point node minor number has to include controller 6201258Smlf * instance (7 bits), controller port number (5 bits) and port multiplier 6211258Smlf * device port number (4 bits) and port multiplier device port 6221258Smlf * indicator (1 bit). Additionally, a single bit is used to 6231258Smlf * differentiate between attachment point node and device control node. 6241258Smlf * 6251258Smlf * Attachment point minor number: 6261258Smlf * ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | SATA_AP_NODE | 6271258Smlf * [(port_multiplier_device_port << SATA_PMULT_PORT_SHIFT) | SATA_PMULT_AP] | 6281258Smlf * (controller_port)) 6291258Smlf * 6301258Smlf * 17 bits are used (if 64 instances of controllers are expected) 6311258Smlf * bit 18 is reserved for future use. 6321258Smlf * 6331258Smlf * -------------------------------------------------------- 6341258Smlf * |17|16|15|14|13|12|11|10 |09|08|07|06|05|04|03|02|01|00| 6351258Smlf * -------------------------------------------------------- 6361258Smlf * | R| c| c| c| c| c| c|a/d|pm|pp|pp|pp|pp|cp|cp|cp|cp|cp| 6371258Smlf * -------------------------------------------------------- 6381258Smlf * Where: 6391258Smlf * cp - device port number on the HBA SATA controller 6401258Smlf * pp - device port number on the port multiplier 6411258Smlf * pm - 0 - target attached to controller device port 6421258Smlf * 1 - target attached to port multiplier's device port 6431258Smlf * a/d - 0 - devctl node 6441258Smlf * 1 - attachment point node 6451258Smlf * c - controller number 6461258Smlf * R - reserved bit 6471258Smlf */ 6481258Smlf 6491258Smlf #define SATA_AP_NODE 0x400 /* Attachment Point node */ 6501258Smlf #define SATA_DEVCTL_NODE 0x000 /* DEVCTL node */ 6511258Smlf #define SATA_PMULT_AP 0x200 /* device on PMult port */ 6521258Smlf #define SATA_PMULT_PORT_SHIFT 5 6531258Smlf #define SATA_CNTRL_INSTANCE_SHIFT 11 6541258Smlf #define SATA_CPORT_MASK 0x1f /* 32 device ports */ 6551258Smlf #define SATA_PMULT_PORT_MASK 0xf /* 15 device ports */ 6561258Smlf #define SATA_CNTRL_INSTANCE_MASK 0x03F /* 64 controllers */ 6571258Smlf 6581258Smlf /* Macro for creating devctl node minor number */ 6591258Smlf #define SATA_MAKE_DEVCTL_MINOR(controller_instance) \ 6601258Smlf ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | \ 6611258Smlf SATA_DEVCTL_NODE) 6621258Smlf 6631258Smlf /* Macro for creating an attachment point node minor number */ 6641258Smlf #define SATA_MAKE_AP_MINOR(cntrl_instance, cport, pmport, qual) \ 6651258Smlf (qual & (SATA_ADDR_PMPORT | SATA_ADDR_DPMPORT) ? \ 6661258Smlf (((cntrl_instance) << SATA_CNTRL_INSTANCE_SHIFT) | \ 6671258Smlf SATA_AP_NODE | SATA_PMULT_AP | \ 6681258Smlf (pmport << SATA_PMULT_PORT_SHIFT) | cport) : \ 6691258Smlf (((cntrl_instance) << SATA_CNTRL_INSTANCE_SHIFT) | \ 6701258Smlf SATA_AP_NODE | cport)) 6711258Smlf 6721258Smlf /* Macro retrieving controller number from a minor number */ 6731258Smlf #define SATA_MINOR2INSTANCE(minor) \ 6741258Smlf ((minor >> SATA_CNTRL_INSTANCE_SHIFT) & SATA_CNTRL_INSTANCE_MASK) 6751258Smlf 6761529Spawelw /* 6771529Spawelw * Macro for creating an attachment point number from sata address. 6781529Spawelw * Address qualifier has to be one of: 6791529Spawelw * SATA_ADDR_DCPORT, SATA_ADDR_DPMPORT, SATA_ADDR_CPORT or SATA_ADDR_PMPORT 6801529Spawelw */ 6811529Spawelw #define SATA_MAKE_AP_NUMBER(cport, pmport, qual) \ 6821529Spawelw ((qual & (SATA_ADDR_PMPORT | SATA_ADDR_DPMPORT)) ? \ 6831529Spawelw (SATA_PMULT_AP | (pmport << SATA_PMULT_PORT_SHIFT) | cport) : \ 6841529Spawelw (cport)) 6851258Smlf 6861258Smlf /* 6871258Smlf * SCSI target number format 6881258Smlf * 6891258Smlf * ------------------------------- 6901258Smlf * | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| Bit number 6911258Smlf * ------------------------------- 6921258Smlf * |pm|pp|pp|pp|pp|cp|cp|cp|cp|cp| 6931258Smlf * ------------------------------- 6941258Smlf * Where: 6951258Smlf * cp - device port number on the HBA SATA controller 6961258Smlf * pp - device port number on the port multiplier 6971258Smlf * pm - 0 - target attached to controller device port 6981258Smlf * 1 - target attached to port multiplier's device port 6991258Smlf */ 7001258Smlf 7011258Smlf /* SATA ports to SCSI target number translation */ 7021258Smlf 7031258Smlf #define SATA_TO_SCSI_TARGET(cport, pmport, qual) \ 7041258Smlf (qual == SATA_ADDR_DCPORT ? cport : \ 7051258Smlf (cport | (pmport << SATA_PMULT_PORT_SHIFT) | SATA_PMULT_AP)) 7061258Smlf 7071258Smlf /* SCSI target number to SATA cntrl/pmport/cport translations */ 7081258Smlf #define SCSI_TO_SATA_CPORT(scsi_target) \ 7091258Smlf (scsi_target & SATA_CPORT_MASK) 7101258Smlf 7111258Smlf #define SCSI_TO_SATA_PMPORT(scsi_target) \ 7121258Smlf ((scsi_target >> SATA_PMULT_PORT_SHIFT) & SATA_PMULT_PORT_MASK) 7131258Smlf 7141258Smlf #define SCSI_TO_SATA_ADDR_QUAL(scsi_target) \ 7151258Smlf ((scsi_target & SATA_PMULT_AP) ? SATA_ADDR_DPMPORT : \ 7161258Smlf SATA_ADDR_DCPORT) 7171258Smlf 7181258Smlf 7191258Smlf /* Debug flags */ 7201258Smlf #if DEBUG 7211258Smlf 7221258Smlf #define SATA_DEBUG 7231258Smlf #define SATA_DBG_SCSI_IF 1 7241258Smlf #define SATA_DBG_HBA_IF 2 7251258Smlf #define SATA_DBG_NODES 4 7261258Smlf #define SATA_DBG_IOCTL_IF 8 7271258Smlf #define SATA_DBG_EVENTS 0x10 7281258Smlf #define SATA_DBG_EVENTS_PROC 0x20 7291258Smlf #define SATA_DBG_EVENTS_PROCPST 0x40 7301258Smlf #define SATA_DBG_EVENTS_CNTRL 0x80 7311258Smlf #define SATA_DBG_EVENTS_DAEMON 0x100 7321258Smlf #define SATA_DBG_DMA_SETUP 0x400 7332734Spawelw #define SATA_DBG_DEV_SETTINGS 0x800 7344862SUnknown #define SATA_DBG_ATAPI 0x1000 7354862SUnknown #define SATA_DBG_ATAPI_PACKET 0x8000 7364862SUnknown 7374862SUnknown typedef struct sata_atapi_cmd { 7384862SUnknown uint8_t acdb[SATA_ATAPI_MAX_CDB_LEN]; 7394862SUnknown uint8_t arqs[SATA_ATAPI_RQSENSE_LEN]; 7404862SUnknown uint_t sata_pkt_reason; 7414862SUnknown uint_t scsi_pkt_reason; 7424862SUnknown } sata_atapi_cmd_t; 7431258Smlf 7441258Smlf /* Debug macros */ 7451258Smlf #define SATADBG1(flag, sata, format, arg1) \ 7461258Smlf if (sata_debug_flags & (flag)) { \ 7471258Smlf sata_log(sata, CE_CONT, format, arg1); \ 7481258Smlf } 7491258Smlf 7501258Smlf #define SATADBG2(flag, sata, format, arg1, arg2) \ 7511258Smlf if (sata_debug_flags & (flag)) { \ 7521258Smlf sata_log(sata, CE_CONT, format, arg1, arg2); \ 7531258Smlf } 7541258Smlf 7551258Smlf #define SATADBG3(flag, sata, format, arg1, arg2, arg3) \ 7561258Smlf if (sata_debug_flags & (flag)) { \ 7571258Smlf sata_log(sata, CE_CONT, format, arg1, arg2, arg3); \ 7581258Smlf } 7591258Smlf #else 7601258Smlf 7611258Smlf #define SATADBG1(flag, dip, frmt, arg1) 7621258Smlf #define SATADBG2(flag, dip, frmt, arg1, arg2) 7631258Smlf #define SATADBG3(flag, dip, frmt, arg1, arg2, arg3) 7641258Smlf 7651258Smlf #endif 7661258Smlf 7671258Smlf #ifdef __cplusplus 7681258Smlf } 7691258Smlf #endif 7701258Smlf 7711258Smlf #endif /* _SATA_H */ 772