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 /* 2310082SFred.Herard@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 241258Smlf * Use is subject to license terms. 251258Smlf */ 261258Smlf 271258Smlf #ifndef _SATA_HBA_H 281258Smlf #define _SATA_HBA_H 291258Smlf 301258Smlf #ifdef __cplusplus 311258Smlf extern "C" { 321258Smlf #endif 331258Smlf 341258Smlf #include <sys/sata/sata_defs.h> 351258Smlf 361258Smlf /* 371258Smlf * SATA Host Bus Adapter (HBA) driver transport definitions 381258Smlf */ 391258Smlf 401258Smlf #include <sys/types.h> 411258Smlf 421258Smlf #ifndef TRUE 431258Smlf #define TRUE 1 441258Smlf #define FALSE 0 451258Smlf #endif 461258Smlf 471258Smlf #define SATA_SUCCESS 0 484014Sls24207 #define SATA_RETRY 1 491258Smlf #define SATA_FAILURE -1 501258Smlf 511258Smlf 521258Smlf /* SATA Framework definitions */ 531258Smlf 541258Smlf #define SATA_MAX_CPORTS 32 /* Max number of controller ports */ 551258Smlf /* Multiplier (PMult) */ 561258Smlf #define SATA_MAX_PMPORTS 16 /* Maximum number of ports on PMult */ 571258Smlf #define SATA_PMULT_HOSTPORT 0xf /* Port Multiplier host port number */ 581258Smlf 591258Smlf 601258Smlf /* 611258Smlf * SATA device address 621258Smlf * Address qualifier flags are used to specify what is addressed (device 631258Smlf * or port) and where (controller or port multiplier data port). 641258Smlf */ 651258Smlf struct sata_address { 661258Smlf uint8_t cport; /* Controller's SATA port number */ 671258Smlf uint8_t pmport; /* Port Multiplier SATA port number */ 681258Smlf uint8_t qual; /* Address Qualifier flags */ 691258Smlf uint8_t pad; /* Reserved */ 701258Smlf }; 711258Smlf 721258Smlf typedef struct sata_address sata_address_t; 731258Smlf 741258Smlf /* 751258Smlf * SATA address Qualifier flags (in qual field of sata_address struct). 761258Smlf * They are mutually exclusive. 771258Smlf */ 781258Smlf 791258Smlf #define SATA_ADDR_NULL 0x00 /* No address */ 801258Smlf #define SATA_ADDR_DCPORT 0x01 /* Device attched to controller port */ 811258Smlf #define SATA_ADDR_DPMPORT 0x02 /* Device attched to PM device port */ 821258Smlf #define SATA_ADDR_CPORT 0x04 /* Controller's device port */ 831258Smlf #define SATA_ADDR_PMPORT 0x08 /* Port Multiplier's device port */ 841258Smlf #define SATA_ADDR_CNTRL 0x10 /* Controller */ 851258Smlf #define SATA_ADDR_PMULT 0x20 /* Port Multiplier */ 86*10663SXiao-Yu.Zhang@Sun.COM #define SATA_ADDR_PMULT_SPEC 0x40 /* Port Multiplier Specific */ 871258Smlf 881258Smlf /* 891258Smlf * SATA port status and control register block. 901258Smlf * The sstatus, serror, scontrol, sactive and snotific 911258Smlf * are the copies of the SATA port status and control registers. 921258Smlf * (Port SStatus, SError, SControl, SActive and SNotification are 931258Smlf * defined by Serial ATA r1.0a sepc and Serial ATA II spec. 941258Smlf */ 951258Smlf 961258Smlf struct sata_port_scr 971258Smlf { 981258Smlf uint32_t sstatus; /* Port SStatus register */ 991258Smlf uint32_t serror; /* Port SError register */ 1001258Smlf uint32_t scontrol; /* Port SControl register */ 1011258Smlf uint32_t sactive; /* Port SActive register */ 1021258Smlf uint32_t snotific; /* Port SNotification register */ 1031258Smlf }; 1041258Smlf 1051258Smlf typedef struct sata_port_scr sata_port_scr_t; 1061258Smlf 1071258Smlf /* 10810318SXiao-Yu.Zhang@Sun.COM * SATA Port Multiplier general status and control register block. 10910318SXiao-Yu.Zhang@Sun.COM * The gscr0, gscr1, gscr2 are the copyies of the register on port multiplier. 11010318SXiao-Yu.Zhang@Sun.COM * GSCR[0], GSCR[1], GSCR[2] are defined in SATA defined by Port Multiplier 11110318SXiao-Yu.Zhang@Sun.COM * 1.0/1.1/1.2 spec. 11210318SXiao-Yu.Zhang@Sun.COM */ 11310318SXiao-Yu.Zhang@Sun.COM struct sata_pmult_gscr { 11410318SXiao-Yu.Zhang@Sun.COM uint32_t gscr0; /* Product Identifier register */ 11510318SXiao-Yu.Zhang@Sun.COM uint32_t gscr1; /* Resrved Information register */ 11610318SXiao-Yu.Zhang@Sun.COM uint32_t gscr2; /* Port Information register */ 11710318SXiao-Yu.Zhang@Sun.COM uint32_t gscr64; /* Feature register */ 118*10663SXiao-Yu.Zhang@Sun.COM uint32_t resv[4]; /* Reseved */ 11910318SXiao-Yu.Zhang@Sun.COM }; 12010318SXiao-Yu.Zhang@Sun.COM 12110318SXiao-Yu.Zhang@Sun.COM typedef struct sata_pmult_gscr sata_pmult_gscr_t; 12210318SXiao-Yu.Zhang@Sun.COM 12310318SXiao-Yu.Zhang@Sun.COM /* 1241258Smlf * SATA Device Structure (rev 1) 1251258Smlf * Used to request/return state of the controller, port, port multiplier 1261258Smlf * or an attached drive: 1271258Smlf * The satadev_addr.cport, satadev_addr.pmport and satadev_addr.qual 1281258Smlf * fields are used to specify SATA address (see sata_address structure 1291258Smlf * description). 1301258Smlf * The satadev_scr structure is used to pass the content of a port 1311258Smlf * status and control registers. 1321258Smlf * The satadev_add_info field is used by SATA HBA driver to return an 1331258Smlf * additional information, which type depends on the function using 1341258Smlf * sata_device as argument. For example: 1351258Smlf * - in case of sata_tran_probe_port() this field should contain 1361258Smlf * a number of available Port Multiplier device ports; 1371258Smlf * - in case of sata_hba_event_notify() this field may contain 1381258Smlf * a value specific for a reported event. 1391258Smlf */ 1401258Smlf #define SATA_DEVICE_REV_1 1 141*10663SXiao-Yu.Zhang@Sun.COM #define SATA_DEVICE_REV SATA_DEVICE_REV_1 1421258Smlf 1431258Smlf struct sata_device 1441258Smlf { 1451258Smlf int satadev_rev; /* structure version */ 1461258Smlf struct sata_address satadev_addr; /* sata port/device address */ 1471258Smlf uint32_t satadev_state; /* Port or device state */ 1481258Smlf uint32_t satadev_type; /* Attached device type */ 1491258Smlf struct sata_port_scr satadev_scr; /* Port status and ctrl regs */ 1501258Smlf uint32_t satadev_add_info; /* additional information, */ 1511258Smlf /* function specific */ 1521258Smlf }; 1531258Smlf 1541258Smlf typedef struct sata_device sata_device_t; 1551258Smlf 1561258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_device)) 1571258Smlf 1581258Smlf 1591258Smlf /* 1601258Smlf * satadev_state field of sata_device structure. 1611258Smlf * Common flags specifying current state of a port or an attached drive. 1626539Spawelw * These states are mutually exclusive, obviously 1631258Smlf */ 1641258Smlf #define SATA_STATE_UNKNOWN 0x000000 1651258Smlf #define SATA_STATE_READY 0x000010 1661258Smlf 1671258Smlf /* 1681258Smlf * Attached drive specific states (satadev_state field of the sata_device 1691258Smlf * structure). 1701258Smlf * SATA_DSTATE_PWR_ACTIVE, SATA_DSTATE_PWR_IDLE and SATA_DSTATE_PWR_STANDBY 1711258Smlf * are mutually exclusive. All other states may be combined with each other 1721258Smlf * and with one of the power states. 1731258Smlf * These flags may be used only if the address qualifier (satadev_addr.qual) is 1741258Smlf * set to SATA_ADDR_DCPORT or SATA_ADDR_DPMPORT value. 1751258Smlf */ 1761258Smlf 1771258Smlf #define SATA_DSTATE_PWR_ACTIVE 0x000100 1781258Smlf #define SATA_DSTATE_PWR_IDLE 0x000200 1791258Smlf #define SATA_DSTATE_PWR_STANDBY 0x000400 1801258Smlf #define SATA_DSTATE_RESET 0x001000 18110318SXiao-Yu.Zhang@Sun.COM #define SATA_DSTATE_PMULT_INIT 0x002000 1821258Smlf #define SATA_DSTATE_FAILED 0x008000 1831258Smlf 1841258Smlf /* Mask for drive power states */ 1851258Smlf #define SATA_DSTATE_PWR (SATA_DSTATE_PWR_ACTIVE | \ 1861258Smlf SATA_DSTATE_PWR_IDLE | \ 1871258Smlf SATA_DSTATE_PWR_STANDBY) 1881258Smlf /* 1891258Smlf * SATA Port specific states (satadev_state field of sata_device structure). 1901258Smlf * SATA_PSTATE_PWRON and SATA_PSTATE_PWROFF are mutually exclusive. 1911258Smlf * All other states may be combined with each other and with one of the power 1921258Smlf * level state. 1931258Smlf * These flags may be used only if the address qualifier (satadev_addr.qual) is 1941258Smlf * set to SATA_ADDR_CPORT or SATA_ADDR_PMPORT value. 1951258Smlf */ 1961258Smlf 1971258Smlf #define SATA_PSTATE_PWRON 0x010000 1981258Smlf #define SATA_PSTATE_PWROFF 0X020000 1991258Smlf #define SATA_PSTATE_SHUTDOWN 0x040000 2001258Smlf #define SATA_PSTATE_FAILED 0x080000 2011258Smlf 2021258Smlf /* Mask for the valid port-specific state flags */ 2031258Smlf #define SATA_PSTATE_VALID (SATA_PSTATE_PWRON | \ 2041258Smlf SATA_PSTATE_PWROFF | \ 2051258Smlf SATA_PSTATE_SHUTDOWN | \ 2061258Smlf SATA_PSTATE_FAILED) 2071258Smlf 2081258Smlf /* Mask for a port power states */ 2091258Smlf #define SATA_PSTATE_PWR (SATA_PSTATE_PWRON | \ 2101258Smlf SATA_PSTATE_PWROFF) 2111258Smlf /* 2121258Smlf * Device type (in satadev_type field of sata_device structure). 2131258Smlf * More device types may be added in the future. 2141258Smlf */ 2151258Smlf 2161258Smlf #define SATA_DTYPE_NONE 0x00 /* No device attached */ 2178010SYing.Tian@Sun.COM #define SATA_DTYPE_ATADISK 0x01 /* ATA disk */ 2188010SYing.Tian@Sun.COM #define SATA_DTYPE_ATAPI 0x40 /* ATAPI device */ 2198010SYing.Tian@Sun.COM #define SATA_DTYPE_ATAPICD \ 2208010SYing.Tian@Sun.COM (SATA_DTYPE_ATAPI|0x02) /* ATAPI CD/DVD device */ 2218010SYing.Tian@Sun.COM #define SATA_DTYPE_ATAPITAPE \ 2228010SYing.Tian@Sun.COM (SATA_DTYPE_ATAPI|0x04) /* ATAPI tape */ 2238010SYing.Tian@Sun.COM #define SATA_DTYPE_ATAPIDISK \ 2248010SYing.Tian@Sun.COM (SATA_DTYPE_ATAPI|0x08) /* ATAPI disk */ 2251258Smlf #define SATA_DTYPE_PMULT 0x10 /* Port Multiplier */ 2261258Smlf #define SATA_DTYPE_UNKNOWN 0x20 /* Device attached, unkown */ 2271258Smlf 2281258Smlf 2291258Smlf /* 2301258Smlf * SATA cmd structure (rev 1) 2311258Smlf * 2321258Smlf * SATA HBA framework always sets all fields except status_reg and error_reg. 2331258Smlf * SATA HBA driver action depends on the addressing type specified by 2341258Smlf * addr_type field: 2351258Smlf * If LBA48 addressing is indicated, SATA HBA driver has to load values from 2361258Smlf * satacmd_sec_count_msb_reg, satacmd_lba_low_msb_reg, 2371258Smlf * satacmd_lba_mid_msb_reg and satacmd_lba_hi_msb_reg 2381258Smlf * to appropriate registers prior to loading other registers. 2391258Smlf * For other addressing modes, SATA HBA driver should skip loading values 2401258Smlf * from satacmd_sec_count_msb_reg, satacmd_lba_low_msb_reg, 2411258Smlf * satacmd_lba_mid_msb_reg and satacmd_lba_hi_msb_reg 2421258Smlf * fields and load only remaining field values to corresponding registers. 2431258Smlf * 2441258Smlf * satacmd_sec_count_msb and satamcd_sec_count_lsb values are loaded into 2451258Smlf * sec_count register, satacmd_sec_count_msb loaded first (if LBA48 2461258Smlf * addressing is used). 2471258Smlf * satacmd_lba_low_msb and satacmd_lba_low_lsb values are loaded into the 2481258Smlf * lba_low register, satacmd_lba_low_msb loaded first (if LBA48 addressing 2491258Smlf * is used). The lba_low register is the newer name for the old 2501258Smlf * sector_number register. 2511258Smlf * satacmd_lba_mid_msb and satacmd_lba_mid_lsb values are loaded into lba_mid 2521258Smlf * register, satacmd_lba_mid_msb loaded first (if LBA48 addressing is used). 2531258Smlf * The lba_mid register is the newer name for the old cylinder_low register. 2541258Smlf * satacmd_lba_high_msb and satacmd_lba_high_lsb values are loaded into 2551258Smlf * the lba_high regster, satacmd_lba_high_msb loaded first (if LBA48 2561258Smlf * addressing is used). The lba_high register is a newer name for the old 2571258Smlf * cylinder_high register. 2581258Smlf * 2591258Smlf * No addressing mode is selected when an ata command does not involve actual 2601258Smlf * reading/writing data from/to the media (for example IDENTIFY DEVICE or 2611258Smlf * SET FEATURE command), or the ATAPI PACKET command is sent. 2621258Smlf * If ATAPI PACKET command is sent and tagged commands are used, 2631258Smlf * SATA HBA driver has to provide and manage a tag value and 2641258Smlf * set it into the sector_count register. 2651258Smlf * 2661258Smlf * Device Control register is not specified in sata_cmd structure - SATA HBA 2671258Smlf * driver shall set it accordingly to current mode of operation (interrupt 2681258Smlf * enable/disable). 2691258Smlf * 2701258Smlf * Buffer structure's b_flags should be used to determine the 2711258Smlf * address type of b_un.b_addr. However, there is no need to allocate DMA 2721258Smlf * resources for the buffer in SATA HBA driver. 2731258Smlf * DMA resources for a buffer structure are allocated by the SATA HBA 2741258Smlf * framework. Scatter/gather list is to be used only for DMA transfers 2751258Smlf * and it should be based on the DMA cookies list. 2761258Smlf * 2771258Smlf * Upon completion of a command, SATA HBA driver has to update 2781258Smlf * satacmd_status_reg and satacmd_error_reg to reflect the contents of 2791258Smlf * the corresponding device status and error registers. 2805014Spawelw * If the command completed successfully, satacmd_flags.sata_copy_xxx flags 2815014Spawelw * specify what register fields should be updated in sata_cmd structure. 2821258Smlf * If the command completed with error, SATA HBA driver has to update 2831258Smlf * satacmd_sec_count_msb, satacmd_sec_count_lsb, satacmd_lba_low_msb, 2841258Smlf * satacmd_lba_low_lsb, satacmd_lba_mid_msb, satacmd_lba_mid_lsb, 2851258Smlf * satacmd_lba_high_msb and satacmd_lba_high_lsb to values read from the 2861258Smlf * corresponding device registers. 2871258Smlf * If an operation could not complete because of the port error, the 2881258Smlf * sata_pkt.satapkt_device.satadev_scr structure has to be updated. 2891258Smlf * 2901258Smlf * If ATAPI PACKET command was sent and command completed with error, 2911258Smlf * rqsense structure has to be filed by SATA HBA driver. The satacmd_arq_cdb 2921258Smlf * points to pre-set request sense cdb that may be used for issuing request 2931258Smlf * sense data from the device. 2941258Smlf * 2955014Spawelw * The sata_max_queue_depth field specifies the maximum allowable queue depth 2965014Spawelw * minus one, i.e. for maximum queue depth of 32, sata_max_queue_depth would 2975014Spawelw * be set to value 0x1f. 2981258Smlf * If FPDMA-type command was sent and command completed with error, the HBA 2991258Smlf * driver may use pre-set command READ LOG EXTENDED command pointed to 3001258Smlf * by satacmd_rle_sata_cmd field to retrieve error data from a device. 3011258Smlf * Only ATA register fields of the sata_cmd are set-up for that purpose. 3021258Smlf * 3031258Smlf * If the READ MULTIPLIER command was specified in cmd_reg (command directed 3041258Smlf * to a port multiplier host port rather then to an attached device), 3051258Smlf * upon the command completion SATA HBA driver has to update_sector count 3061258Smlf * and lba fields of the sata_cmd structure to values returned via 3071258Smlf * command block registers (task file registers). 3081258Smlf */ 3091258Smlf #define SATA_CMD_REV_1 1 3101612Sls24207 #define SATA_CMD_REV_2 2 3114862SUnknown #define SATA_CMD_REV_3 3 3124862SUnknown #define SATA_CMD_REV SATA_CMD_REV_3 3131258Smlf 3141258Smlf #define SATA_ATAPI_MAX_CDB_LEN 16 /* Covers both 12 and 16 byte cdbs */ 3154862SUnknown #define SATA_ATAPI_RQSENSE_LEN 24 /* Allocated Request Sense data */ 3164862SUnknown #define SATA_ATAPI_MIN_RQSENSE_LEN 18 /* Min Fixed size Request Sense data */ 3175014Spawelw #define SATA_ATAPI_RQSENSE_CDB_LEN 6 /* Request Sense CDB length */ 3184862SUnknown 3195014Spawelw #define SATA_MAX_QUEUE_DEPTH 32 /* Default max queue depth */ 3201258Smlf 3211258Smlf struct sata_cmd { 3221258Smlf int satacmd_rev; /* version */ 3231258Smlf struct buf *satacmd_bp; /* ptr to buffer structure */ 3241612Sls24207 struct sata_cmd_flags { 3251612Sls24207 uint32_t sata_data_direction : 3; /* 0-2 */ 3261612Sls24207 uint32_t : 1; /* reserved */ /* 3 */ 3271612Sls24207 uint32_t sata_queue_stag : 1; /* 4 */ 3281612Sls24207 uint32_t sata_queue_otag : 1; /* 5 */ 3291612Sls24207 uint32_t : 2; /* reserved */ /* 6-7 */ 3301612Sls24207 uint32_t sata_queued : 1; /* 8 */ 3311612Sls24207 uint32_t : 3; /* reserved */ /* 9-11 */ 3321612Sls24207 uint32_t sata_ignore_dev_reset : 1; /* 12 */ 3331612Sls24207 uint32_t sata_clear_dev_reset : 1; /* 13 */ 3341612Sls24207 uint32_t : 2; /* reserved */ /* 14-15 */ 3351612Sls24207 uint32_t sata_special_regs : 1; /* 16 */ 3361612Sls24207 uint32_t sata_copy_out_sec_count_msb : 1; /* 17 */ 3371612Sls24207 uint32_t sata_copy_out_lba_low_msb : 1; /* 18 */ 3381612Sls24207 uint32_t sata_copy_out_lba_mid_msb : 1; /* 19 */ 3391612Sls24207 uint32_t sata_copy_out_lba_high_msb : 1; /* 20 */ 3401612Sls24207 uint32_t sata_copy_out_sec_count_lsb : 1; /* 21 */ 3411612Sls24207 uint32_t sata_copy_out_lba_low_lsb : 1; /* 22 */ 3421612Sls24207 uint32_t sata_copy_out_lba_mid_lsb : 1; /* 23 */ 3431612Sls24207 uint32_t sata_copy_out_lba_high_lsb : 1; /* 24 */ 3441612Sls24207 uint32_t sata_copy_out_device_reg : 1; /* 25 */ 3451612Sls24207 uint32_t sata_copy_out_error_reg : 1; /* 26 */ 3464862SUnknown uint32_t sata_max_queue_depth: 5; /* 27-31 */ 3471612Sls24207 } satacmd_flags; 3481258Smlf uint8_t satacmd_addr_type; /* addr type: LBA28, LBA48 */ 3491258Smlf uint8_t satacmd_features_reg_ext; /* features reg extended */ 3501258Smlf uint8_t satacmd_sec_count_msb; /* sector count MSB (LBA48) */ 3511258Smlf uint8_t satacmd_lba_low_msb; /* LBA Low MSB (LBA48) */ 3521258Smlf uint8_t satacmd_lba_mid_msb; /* LBA Mid MSB (LBA48) */ 3531258Smlf uint8_t satacmd_lba_high_msb; /* LBA High MSB (LBA48) */ 3541258Smlf uint8_t satacmd_sec_count_lsb; /* sector count LSB */ 3551258Smlf uint8_t satacmd_lba_low_lsb; /* LBA Low LSB */ 3561258Smlf uint8_t satacmd_lba_mid_lsb; /* LBA Mid LSB */ 3571258Smlf uint8_t satacmd_lba_high_lsb; /* LBA High LSB */ 3581258Smlf uint8_t satacmd_device_reg; /* ATA dev reg & LBA28 MSB */ 3591258Smlf uint8_t satacmd_cmd_reg; /* ata command code */ 3601258Smlf uint8_t satacmd_features_reg; /* ATA features register */ 3611258Smlf uint8_t satacmd_status_reg; /* ATA status register */ 3621258Smlf uint8_t satacmd_error_reg; /* ATA error register */ 3631258Smlf uint8_t satacmd_acdb_len; /* ATAPI cdb length */ 3641258Smlf uint8_t satacmd_acdb[SATA_ATAPI_MAX_CDB_LEN]; /* ATAPI cdb */ 3651258Smlf 3664862SUnknown /* kept for binary compat. */ 3674862SUnknown uint8_t *pad1; /* unused */ 3681258Smlf 3691258Smlf uint8_t satacmd_rqsense[SATA_ATAPI_RQSENSE_LEN]; 3701258Smlf /* 3714862SUnknown * Error retrieval buffer 3724862SUnknown * dma handle pointer 3734862SUnknown * (for buffer DMA syncing) 3744862SUnknown * Valid only in error 3754862SUnknown * retrieval packet! 3761258Smlf */ 3774862SUnknown ddi_dma_handle_t *satacmd_err_ret_buf_handle; 3781258Smlf 3791258Smlf int satacmd_num_dma_cookies; /* number of dma cookies */ 3801258Smlf /* ptr to dma cookie list */ 3811258Smlf ddi_dma_cookie_t *satacmd_dma_cookie_list; 3821258Smlf }; 3831258Smlf 3841258Smlf typedef struct sata_cmd sata_cmd_t; 3851258Smlf 3861258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_cmd)) 3871258Smlf 3881258Smlf 3891258Smlf /* ATA address type (in satacmd_addr_type field */ 3901258Smlf #define ATA_ADDR_LBA 0x1 3911258Smlf #define ATA_ADDR_LBA28 0x2 3921258Smlf #define ATA_ADDR_LBA48 0x4 3931258Smlf 3941258Smlf /* 3951258Smlf * satacmd_flags : contain data transfer direction flags, 3961258Smlf * tagged queuing type flags, queued command flag, and reset state handling 3971258Smlf * flag. 3981258Smlf */ 3991258Smlf 4001258Smlf /* 4011612Sls24207 * Data transfer direction flags (satacmd_flags.sata_data_direction) 4021258Smlf * Direction flags are mutually exclusive. 4031258Smlf */ 4041258Smlf #define SATA_DIR_NODATA_XFER 0x0001 /* No data transfer */ 4051258Smlf #define SATA_DIR_READ 0x0002 /* Reading data from a device */ 4061258Smlf #define SATA_DIR_WRITE 0x0004 /* Writing data to a device */ 4071258Smlf 4081258Smlf /* 4092553Sls24207 * Tagged Queuing type flags 4102553Sls24207 * satacmd_flags.sata_queue_stag 4112553Sls24207 * satacmd_flags.sata_queue_otag 4122553Sls24207 * 4131258Smlf * These flags indicate how the SATA command should be queued. 4141258Smlf * 4152553Sls24207 * sata_queue_stag 4161258Smlf * Simple-queue-tagged command. It may be executed out-of-order in respect 4171258Smlf * to other queued commands. 4182553Sls24207 * sata_queue_otag 4191258Smlf * Ordered-queue-tagged command. It cannot be executed out-of-order in 4201258Smlf * respect to other commands, i.e. it should be executed in the order of 4211258Smlf * being transported to the HBA. 4221258Smlf * 4231258Smlf * Translated head-of-queue-tagged scsi commands and commands that are 4245279Sls24207 * to be put at the head of the queue are treated as sata_queue_otag 4251258Smlf * tagged commands. 4261258Smlf */ 4271258Smlf 4281258Smlf 4291258Smlf /* 4302553Sls24207 * Queuing command set-up flag (satacmd_flags.sata_queued). 4311258Smlf * This flag indicates that sata_cmd was set-up for DMA Queued command 4321258Smlf * (either READ_DMA_QUEUED, READ_DMA_QUEUED_EXT, WRITE_DMA_QUEUED or 4331258Smlf * WRITE_DMA_QUEUED_EXT command) or one of the Native Command Queuing commands 4341258Smlf * (either READ_FPDMA_QUEUED or WRITE_FPDMA_QUEUED). 4351258Smlf * This flag will be used only if sata_tran_hba_flags indicates controller 4361258Smlf * support for queuing and the device for which sata_cmd is prepared supports 4371258Smlf * either legacy queuing (indicated by Device Identify data word 83 bit 2) 4381258Smlf * or NCQ (indicated by word 76 of Device Identify data). 4391258Smlf */ 4401258Smlf 4411258Smlf /* 4422553Sls24207 * Reset state handling 4432553Sls24207 * satacmd_flags.sata_ignore_dev_reset 4442553Sls24207 * satacmd_flags.sata_clear_dev_reset 4452553Sls24207 * 4461258Smlf * SATA HBA device enters reset state if the device was subjected to 4471258Smlf * the Device Reset (may also enter this state if the device was reset 4481258Smlf * as a side effect of port reset). SATA HBA driver sets this state. 4491258Smlf * Device stays in this condition until explicit request from SATA HBA 4502553Sls24207 * framework to clear the state. 4511258Smlf */ 4521258Smlf 4531258Smlf /* 4541258Smlf * SATA Packet structure (rev 1) 4551258Smlf * hba_driver_private is for a private use of the SATA HBA driver; 4561258Smlf * satapkt_framework_private is used only by SATA HBA framework; 4571258Smlf * satapkt_comp is a callback function to be called when packet 4581258Smlf * execution is completed (for any reason) if mode of operation is not 4591258Smlf * synchronous (SATA_OPMODE_SYNCH); 4601258Smlf * satapkt_reason specifies why the packet operation was completed 4611258Smlf * 4621258Smlf * NOTE: after the packet completion callback SATA HBA driver should not 4631258Smlf * attempt to access any sata_pkt fields because sata_pkt is not valid anymore 4641258Smlf * (it could have been destroyed). 4651258Smlf * Since satapkt_hba_driver_private field cannot be retrieved, any hba private 4661258Smlf * data respources allocated per packet and accessed via this pointer should 4671258Smlf * either be freed before the completion callback is done, or the pointer has 4681258Smlf * to be saved by the HBA driver before the completion callback. 4691258Smlf */ 4701258Smlf #define SATA_PKT_REV_1 1 4711258Smlf #define SATA_PKT_REV SATA_PKT_REV_1 4721258Smlf 4731258Smlf struct sata_pkt { 4741258Smlf int satapkt_rev; /* version */ 4751258Smlf struct sata_device satapkt_device; /* Device address/type */ 4761258Smlf 4771258Smlf /* HBA driver private data */ 4781258Smlf void *satapkt_hba_driver_private; 4791258Smlf 4801258Smlf /* SATA framework priv data */ 4811258Smlf void *satapkt_framework_private; 4821258Smlf 4831258Smlf /* Rqsted mode of operation */ 4841258Smlf uint32_t satapkt_op_mode; 4851258Smlf 4861258Smlf struct sata_cmd satapkt_cmd; /* composite sata command */ 4871258Smlf int satapkt_time; /* time allotted to command */ 4881258Smlf void (*satapkt_comp)(struct sata_pkt *); /* callback */ 4891258Smlf int satapkt_reason; /* completion reason */ 4901258Smlf }; 4911258Smlf 4921258Smlf typedef struct sata_pkt sata_pkt_t; 4931258Smlf 4941258Smlf _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_pkt)) 4951258Smlf 4961258Smlf 4971258Smlf /* 4981258Smlf * Operation mode flags (in satapkt_op_mode field of sata_pkt structure). 4991258Smlf * Use to specify what should be a mode of operation for specified command. 5001258Smlf * Default (000b) means use Interrupt and Asynchronous mode to 5011258Smlf * perform an operation. 5021258Smlf * Synchronous operation menas that the packet operation has to be completed 5031258Smlf * before the function called to initiate the operation returns. 5041258Smlf */ 5051258Smlf #define SATA_OPMODE_INTERRUPTS 0 /* Use interrupts (hint) */ 5061258Smlf #define SATA_OPMODE_POLLING 1 /* Use polling instead of interrupts */ 5071258Smlf #define SATA_OPMODE_ASYNCH 0 /* Return immediately after accepting pkt */ 5081258Smlf #define SATA_OPMODE_SYNCH 4 /* Perform synchronous operation */ 5091258Smlf 5101258Smlf /* 5111258Smlf * satapkt_reason values: 5121258Smlf * 5131258Smlf * SATA_PKT_QUEUE_FULL - cmd not sent because of queue full (detected 5141258Smlf * by the controller). If a device reject command for this reason, it 5151258Smlf * should be reported as SATA_PKT_DEV_ERROR 5161258Smlf * 5171258Smlf * SATA_PKT_CMD_NOT_SUPPORTED - command not supported by a controller 5181258Smlf * Controller is unable to send such command to a device. 5191258Smlf * If device rejects a command, it should be reported as 5201258Smlf * SATA_PKT_DEV_ERROR. 5211258Smlf * 5221258Smlf * SATA_PKT_DEV_ERROR - cmd failed because of device reported an error. 5231258Smlf * The content of status_reg (ERROR bit has to be set) and error_reg 5241258Smlf * fields of the sata_cmd structure have to be set and will be used 5251258Smlf * by SATA HBA Framework to determine the error cause. 5261258Smlf * 5271258Smlf * SATA_PKT_PORT_ERROR - cmd failed because of a link or a port error. 5281258Smlf * Link failed / no communication with a device / communication error 5291258Smlf * or other port related error was detected by a controller. 5301258Smlf * sata_pkt.satapkt_device.satadev_scr.sXXXXXXX words have to be set. 5311258Smlf * 5321258Smlf * SATA_PKT_ABORTED - cmd execution was aborted by the request from the 5331258Smlf * framework. Abort mechanism is HBA driver specific. 5341258Smlf * 5351258Smlf * SATA_PKT_TIMEOUT - cmd execution has timed-out. Timeout specified by 5361258Smlf * pkt_time was exceeded. The command was terminated by the SATA HBA 5371258Smlf * driver. 5381258Smlf * 5391258Smlf * SATA_PKT_COMPLETED - this is a value returned when an operation 5401258Smlf * completes without errors. 5411258Smlf * 5421258Smlf * SATA_PKT_BUSY - packet was not accepted for execution because the 5431258Smlf * driver was busy performing some other operation(s). 5441258Smlf * 5451258Smlf * SATA_PKT_RESET - packet execution was aborted because of device 5461258Smlf * reset originated by either the HBA driver or the SATA framework. 5471258Smlf * 5481258Smlf */ 5491258Smlf 5501258Smlf #define SATA_PKT_BUSY -1 /* Not completed, busy */ 5511258Smlf #define SATA_PKT_COMPLETED 0 /* No error */ 5521258Smlf #define SATA_PKT_DEV_ERROR 1 /* Device reported error */ 5531258Smlf #define SATA_PKT_QUEUE_FULL 2 /* Not accepted, queue full */ 5541258Smlf #define SATA_PKT_PORT_ERROR 3 /* Not completed, port error */ 5551258Smlf #define SATA_PKT_CMD_UNSUPPORTED 4 /* Cmd unsupported */ 5561258Smlf #define SATA_PKT_ABORTED 5 /* Aborted by request */ 5571258Smlf #define SATA_PKT_TIMEOUT 6 /* Operation timeut */ 5581258Smlf #define SATA_PKT_RESET 7 /* Aborted by reset request */ 5591258Smlf 5601258Smlf /* 5614862SUnknown * Error retrieval sata packet types 5624862SUnknown */ 5634862SUnknown #define SATA_ERR_RETR_PKT_TYPE_NCQ 1 5644862SUnknown #define SATA_ERR_RETR_PKT_TYPE_ATAPI 2 5654862SUnknown 5664862SUnknown /* 56710318SXiao-Yu.Zhang@Sun.COM * Read/write port multiplier packet types 56810318SXiao-Yu.Zhang@Sun.COM */ 56910318SXiao-Yu.Zhang@Sun.COM #define SATA_RDWR_PMULT_PKT_TYPE_READ 1 57010318SXiao-Yu.Zhang@Sun.COM #define SATA_RDWR_PMULT_PKT_TYPE_WRITE 2 57110318SXiao-Yu.Zhang@Sun.COM 57210318SXiao-Yu.Zhang@Sun.COM /* 5731258Smlf * Hoplug functions vector structure (rev 1) 5741258Smlf */ 5751258Smlf #define SATA_TRAN_HOTPLUG_OPS_REV_1 1 5761258Smlf 5771258Smlf struct sata_tran_hotplug_ops { 5781258Smlf int sata_tran_hotplug_ops_rev; /* version */ 5791258Smlf int (*sata_tran_port_activate)(dev_info_t *, sata_device_t *); 5801258Smlf int (*sata_tran_port_deactivate)(dev_info_t *, sata_device_t *); 5811258Smlf }; 5821258Smlf 5831258Smlf typedef struct sata_tran_hotplug_ops sata_tran_hotplug_ops_t; 5841258Smlf 5851258Smlf 5861258Smlf /* 5871258Smlf * Power management functions vector structure (rev 1) 5881258Smlf * The embedded function returns information about the controller's 5891258Smlf * power level. 5901258Smlf * Additional functions may be added in the future without changes to 5911258Smlf * sata_tran structure. 5921258Smlf */ 5931258Smlf #define SATA_TRAN_PWRMGT_OPS_REV_1 1 5941258Smlf 5951258Smlf struct sata_tran_pwrmgt_ops { 5961258Smlf int sata_tran_pwrmgt_ops_rev; /* version */ 5971258Smlf int (*sata_tran_get_pwr_level)(dev_info_t *, sata_device_t *); 5981258Smlf }; 5991258Smlf 6001258Smlf typedef struct sata_tran_pwrmgt_ops sata_tran_pwrmgt_ops_t; 6011258Smlf 6021258Smlf 6031258Smlf /* 6041258Smlf * SATA port PHY Power Level 6051258Smlf * These states correspond to the interface power management state as defined 6061258Smlf * in Serial ATA spec. 6071258Smlf */ 6081258Smlf #define SATA_TRAN_PORTPWR_LEVEL1 1 /* Interface in active PM state */ 6091258Smlf #define SATA_TRAN_PORTPWR_LEVEL2 2 /* Interface in PARTIAL PM state */ 6101258Smlf #define SATA_TRAN_PORTPWR_LEVEL3 3 /* Interface in SLUMBER PM state */ 6111258Smlf 6121258Smlf /* 6131258Smlf * SATA HBA Tran structure (rev 1) 6141258Smlf * Registered with SATA Framework 6151258Smlf * 6161258Smlf * dma_attr is a pointer to data (buffer) dma attibutes of the controller 6171258Smlf * DMA engine. 6181258Smlf * 6191258Smlf * The qdepth field specifies number of commands that may be accepted by 6201258Smlf * the controller. Value range 1-32. A value greater than 1 indicates that 6211258Smlf * the controller supports queuing. Support for Native Command Queuing 6221258Smlf * indicated by SATA_CTLF_NCQ flag also requires qdepth set to a value 6231258Smlf * greater then 1. 6241258Smlf * 6251258Smlf */ 6261258Smlf #define SATA_TRAN_HBA_REV_1 1 6274862SUnknown #define SATA_TRAN_HBA_REV_2 2 62810318SXiao-Yu.Zhang@Sun.COM #define SATA_TRAN_HBA_REV_3 3 62910318SXiao-Yu.Zhang@Sun.COM #define SATA_TRAN_HBA_REV SATA_TRAN_HBA_REV_3 6301258Smlf 6311258Smlf struct sata_hba_tran { 6321258Smlf int sata_tran_hba_rev; /* version */ 6331258Smlf dev_info_t *sata_tran_hba_dip; /* Controler dev info */ 6341258Smlf ddi_dma_attr_t *sata_tran_hba_dma_attr; /* DMA attributes */ 6351258Smlf int sata_tran_hba_num_cports; /* Num of HBA device ports */ 6361258Smlf uint16_t sata_tran_hba_features_support; /* HBA features */ 6371258Smlf uint16_t sata_tran_hba_qdepth; /* HBA-supported queue depth */ 6381258Smlf 6391258Smlf int (*sata_tran_probe_port)(dev_info_t *, sata_device_t *); 6401258Smlf int (*sata_tran_start)(dev_info_t *, sata_pkt_t *); 6411258Smlf int (*sata_tran_abort)(dev_info_t *, sata_pkt_t *, int); 6421258Smlf int (*sata_tran_reset_dport)(dev_info_t *, 6431258Smlf sata_device_t *); 6441258Smlf int (*sata_tran_selftest)(dev_info_t *, sata_device_t *); 6451258Smlf 6461258Smlf /* Hotplug vector */ 6471258Smlf struct sata_tran_hotplug_ops *sata_tran_hotplug_ops; 6481258Smlf 6491258Smlf /* Power mgt vector */ 6501258Smlf struct sata_tran_pwrmgt_ops *sata_tran_pwrmgt_ops; 6511258Smlf 6521258Smlf int (*sata_tran_ioctl)(dev_info_t *, int, intptr_t); 6531258Smlf }; 6541258Smlf 6551258Smlf typedef struct sata_hba_tran sata_hba_tran_t; 6561258Smlf 6571258Smlf 6581258Smlf /* 6591258Smlf * Controller's features support flags (sata_tran_hba_features_support). 6601258Smlf * Note: SATA_CTLF_NCQ indicates that SATA controller supports NCQ in addition 6611258Smlf * to legacy queuing commands, indicated by SATA_CTLF_QCMD flag. 6621258Smlf */ 6631258Smlf 6641258Smlf #define SATA_CTLF_ATAPI 0x001 /* ATAPI support */ 6651258Smlf #define SATA_CTLF_PORT_MULTIPLIER 0x010 /* Port Multiplier suport */ 6661258Smlf #define SATA_CTLF_HOTPLUG 0x020 /* Hotplug support */ 6671258Smlf #define SATA_CTLF_ASN 0x040 /* Asynchronous Event Support */ 6681258Smlf #define SATA_CTLF_QCMD 0x080 /* Queued commands support */ 6691258Smlf #define SATA_CTLF_NCQ 0x100 /* NCQ support */ 67010318SXiao-Yu.Zhang@Sun.COM #define SATA_CTLF_PMULT_FBS 0x200 /* FIS-based switching support */ 6711258Smlf 6721258Smlf /* 6731258Smlf * sata_tran_start() return values. 6741258Smlf * When pkt is not accepted, the satapkt_reason has to be updated 6751258Smlf * before function returns - it should reflect the same reason for not being 6761258Smlf * executed as the return status of above functions. 6771258Smlf * If pkt was accepted and executed synchronously, 6781258Smlf * satapk_reason should indicate a completion status. 6791258Smlf */ 6801258Smlf #define SATA_TRAN_ACCEPTED 0 /* accepted */ 6811258Smlf #define SATA_TRAN_QUEUE_FULL 1 /* not accepted, queue full */ 6821258Smlf #define SATA_TRAN_PORT_ERROR 2 /* not accepted, port error */ 6831258Smlf #define SATA_TRAN_CMD_UNSUPPORTED 3 /* not accepted, cmd not supported */ 6841258Smlf #define SATA_TRAN_BUSY 4 /* not accepted, busy */ 6851258Smlf 6861258Smlf 6871258Smlf /* 6881258Smlf * sata_tran_abort() abort type flag 6891258Smlf */ 6901258Smlf #define SATA_ABORT_PACKET 0 6911258Smlf #define SATA_ABORT_ALL_PACKETS 1 6921258Smlf 6931258Smlf 6941258Smlf /* 6951258Smlf * Events handled by SATA HBA Framework 6961258Smlf * More then one event may be reported at the same time 6971258Smlf * 6981258Smlf * SATA_EVNT__DEVICE_ATTACHED 6991258Smlf * HBA detected the presence of a device ( electrical connection with 7001258Smlf * a device was detected ). 7011258Smlf * 7021258Smlf * SATA_EVNT_DEVICE_DETACHED 7031258Smlf * HBA detected the detachment of a device (electrical connection with 7041258Smlf * a device was broken) 7051258Smlf * 7061258Smlf * SATA_EVNT_LINK_LOST 7071258Smlf * HBA lost link with an attached device 7081258Smlf * 7091258Smlf * SATA_EVNT_LINK_ESTABLISHED 7101258Smlf * HBA established a link with an attached device 7111258Smlf * 7121258Smlf * SATA_EVNT_PORT_FAILED 7131258Smlf * HBA has determined that the port failed and is unuseable 7141258Smlf * 7151258Smlf * SATA_EVENT_DEVICE_RESET 7161258Smlf * SATA device was reset, causing loss of the device setting 7171258Smlf * 7181258Smlf * SATA_EVNT_PWR_LEVEL_CHANGED 7191258Smlf * A port or entire SATA controller power level has changed 7201258Smlf * 72110318SXiao-Yu.Zhang@Sun.COM * SATA_EVNT_PMULT_LINK_CHANGED 72210318SXiao-Yu.Zhang@Sun.COM * Port multiplier detect change on a link of its device port 72310318SXiao-Yu.Zhang@Sun.COM * 7241258Smlf */ 7251258Smlf #define SATA_EVNT_DEVICE_ATTACHED 0x01 7261258Smlf #define SATA_EVNT_DEVICE_DETACHED 0x02 7271258Smlf #define SATA_EVNT_LINK_LOST 0x04 7281258Smlf #define SATA_EVNT_LINK_ESTABLISHED 0x08 7291258Smlf #define SATA_EVNT_PORT_FAILED 0x10 7301258Smlf #define SATA_EVNT_DEVICE_RESET 0x20 7311258Smlf #define SATA_EVNT_PWR_LEVEL_CHANGED 0x40 73210318SXiao-Yu.Zhang@Sun.COM #define SATA_EVNT_PMULT_LINK_CHANGED 0x80 7331258Smlf 7341258Smlf /* 7351258Smlf * SATA Framework interface entry points 7361258Smlf */ 7371258Smlf int sata_hba_init(struct modlinkage *); 7381258Smlf int sata_hba_attach(dev_info_t *, sata_hba_tran_t *, ddi_attach_cmd_t); 7391258Smlf int sata_hba_detach(dev_info_t *, ddi_detach_cmd_t); 7401258Smlf void sata_hba_fini(struct modlinkage *); 7411258Smlf void sata_hba_event_notify(dev_info_t *, sata_device_t *, int); 7424862SUnknown sata_pkt_t *sata_get_error_retrieval_pkt(dev_info_t *, sata_device_t *, int); 7434862SUnknown void sata_free_error_retrieval_pkt(sata_pkt_t *); 74410318SXiao-Yu.Zhang@Sun.COM sata_pkt_t *sata_get_rdwr_pmult_pkt(dev_info_t *, sata_device_t *, uint8_t, 74510318SXiao-Yu.Zhang@Sun.COM uint32_t, uint32_t); 74610318SXiao-Yu.Zhang@Sun.COM void sata_free_rdwr_pmult_pkt(sata_pkt_t *); 747*10663SXiao-Yu.Zhang@Sun.COM void sata_register_pmult(dev_info_t *, sata_device_t *, sata_pmult_gscr_t *); 7487152Sap25164 void sata_free_dma_resources(sata_pkt_t *); 7491258Smlf 75010082SFred.Herard@Sun.COM /* 75110082SFred.Herard@Sun.COM * SATA trace ring buffer constants 75210082SFred.Herard@Sun.COM */ 75310082SFred.Herard@Sun.COM #define DMSG_RING_SIZE 0x100000 /* 1MB */ 75410082SFred.Herard@Sun.COM #define DMSG_BUF_SIZE 256 75510082SFred.Herard@Sun.COM 75610082SFred.Herard@Sun.COM /* 75710082SFred.Herard@Sun.COM * SATA trace ring buffer content 75810082SFred.Herard@Sun.COM */ 75910082SFred.Herard@Sun.COM typedef struct sata_trace_dmsg { 76010082SFred.Herard@Sun.COM dev_info_t *dip; 76110082SFred.Herard@Sun.COM timespec_t timestamp; 76210082SFred.Herard@Sun.COM char buf[DMSG_BUF_SIZE]; 76310082SFred.Herard@Sun.COM struct sata_trace_dmsg *next; 76410082SFred.Herard@Sun.COM } sata_trace_dmsg_t; 76510082SFred.Herard@Sun.COM 76610082SFred.Herard@Sun.COM /* 76710082SFred.Herard@Sun.COM * SATA trace ring buffer header 76810082SFred.Herard@Sun.COM */ 76910082SFred.Herard@Sun.COM typedef struct sata_trace_rbuf { 77010082SFred.Herard@Sun.COM kmutex_t lock; /* lock to avoid clutter */ 77110082SFred.Herard@Sun.COM int looped; /* completed ring */ 77210082SFred.Herard@Sun.COM int allocfailed; /* dmsg mem alloc failed */ 77310082SFred.Herard@Sun.COM size_t size; /* current size */ 77410082SFred.Herard@Sun.COM size_t maxsize; /* max size */ 77510082SFred.Herard@Sun.COM sata_trace_dmsg_t *dmsgh; /* messages head */ 77610082SFred.Herard@Sun.COM sata_trace_dmsg_t *dmsgp; /* ptr to last message */ 77710082SFred.Herard@Sun.COM } sata_trace_rbuf_t; 77810082SFred.Herard@Sun.COM 77910082SFred.Herard@Sun.COM /* 78010082SFred.Herard@Sun.COM * SATA trace ring buffer interfaces 78110082SFred.Herard@Sun.COM */ 78210082SFred.Herard@Sun.COM void sata_trace_debug(dev_info_t *, const char *fmt, ...); 78310082SFred.Herard@Sun.COM void sata_vtrace_debug(dev_info_t *, const char *fmt, va_list); 7841258Smlf 7851258Smlf #ifdef __cplusplus 7861258Smlf } 7871258Smlf #endif 7881258Smlf 7891258Smlf #endif /* _SATA_HBA_H */ 790