1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SATA_HBA_H 28 #define _SATA_HBA_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #include <sys/sata/sata_defs.h> 35 36 /* 37 * SATA Host Bus Adapter (HBA) driver transport definitions 38 */ 39 40 #include <sys/types.h> 41 42 #ifndef TRUE 43 #define TRUE 1 44 #define FALSE 0 45 #endif 46 47 #define SATA_SUCCESS 0 48 #define SATA_RETRY 1 49 #define SATA_FAILURE -1 50 51 52 /* SATA Framework definitions */ 53 54 #define SATA_MAX_CPORTS 32 /* Max number of controller ports */ 55 /* Multiplier (PMult) */ 56 #define SATA_MAX_PMPORTS 16 /* Maximum number of ports on PMult */ 57 #define SATA_PMULT_HOSTPORT 0xf /* Port Multiplier host port number */ 58 59 60 /* 61 * SATA device address 62 * Address qualifier flags are used to specify what is addressed (device 63 * or port) and where (controller or port multiplier data port). 64 */ 65 struct sata_address { 66 uint8_t cport; /* Controller's SATA port number */ 67 uint8_t pmport; /* Port Multiplier SATA port number */ 68 uint8_t qual; /* Address Qualifier flags */ 69 uint8_t pad; /* Reserved */ 70 }; 71 72 typedef struct sata_address sata_address_t; 73 74 /* 75 * SATA address Qualifier flags (in qual field of sata_address struct). 76 * They are mutually exclusive. 77 */ 78 79 #define SATA_ADDR_NULL 0x00 /* No address */ 80 #define SATA_ADDR_DCPORT 0x01 /* Device attched to controller port */ 81 #define SATA_ADDR_DPMPORT 0x02 /* Device attched to PM device port */ 82 #define SATA_ADDR_CPORT 0x04 /* Controller's device port */ 83 #define SATA_ADDR_PMPORT 0x08 /* Port Multiplier's device port */ 84 #define SATA_ADDR_CNTRL 0x10 /* Controller */ 85 #define SATA_ADDR_PMULT 0x20 /* Port Multiplier */ 86 87 /* 88 * SATA port status and control register block. 89 * The sstatus, serror, scontrol, sactive and snotific 90 * are the copies of the SATA port status and control registers. 91 * (Port SStatus, SError, SControl, SActive and SNotification are 92 * defined by Serial ATA r1.0a sepc and Serial ATA II spec. 93 */ 94 95 struct sata_port_scr 96 { 97 uint32_t sstatus; /* Port SStatus register */ 98 uint32_t serror; /* Port SError register */ 99 uint32_t scontrol; /* Port SControl register */ 100 uint32_t sactive; /* Port SActive register */ 101 uint32_t snotific; /* Port SNotification register */ 102 }; 103 104 typedef struct sata_port_scr sata_port_scr_t; 105 106 /* 107 * SATA Port Multiplier general status and control register block. 108 * The gscr0, gscr1, gscr2 are the copyies of the register on port multiplier. 109 * GSCR[0], GSCR[1], GSCR[2] are defined in SATA defined by Port Multiplier 110 * 1.0/1.1/1.2 spec. 111 */ 112 struct sata_pmult_gscr { 113 uint32_t gscr0; /* Product Identifier register */ 114 uint32_t gscr1; /* Resrved Information register */ 115 uint32_t gscr2; /* Port Information register */ 116 uint32_t gscr64; /* Feature register */ 117 }; 118 119 typedef struct sata_pmult_gscr sata_pmult_gscr_t; 120 121 /* 122 * SATA Device Structure (rev 1) 123 * Used to request/return state of the controller, port, port multiplier 124 * or an attached drive: 125 * The satadev_addr.cport, satadev_addr.pmport and satadev_addr.qual 126 * fields are used to specify SATA address (see sata_address structure 127 * description). 128 * The satadev_scr structure is used to pass the content of a port 129 * status and control registers. 130 * The satadev_add_info field is used by SATA HBA driver to return an 131 * additional information, which type depends on the function using 132 * sata_device as argument. For example: 133 * - in case of sata_tran_probe_port() this field should contain 134 * a number of available Port Multiplier device ports; 135 * - in case of sata_hba_event_notify() this field may contain 136 * a value specific for a reported event. 137 */ 138 #define SATA_DEVICE_REV_1 1 139 #define SATA_DEVICE_REV_2 2 140 #define SATA_DEVICE_REV SATA_DEVICE_REV_2 141 142 struct sata_device 143 { 144 int satadev_rev; /* structure version */ 145 struct sata_address satadev_addr; /* sata port/device address */ 146 uint32_t satadev_state; /* Port or device state */ 147 uint32_t satadev_type; /* Attached device type */ 148 struct sata_port_scr satadev_scr; /* Port status and ctrl regs */ 149 struct sata_pmult_gscr satadev_gscr; /* Port multiplier specific */ 150 /* global status and control */ 151 /* registers */ 152 uint32_t satadev_add_info; /* additional information, */ 153 /* function specific */ 154 }; 155 156 typedef struct sata_device sata_device_t; 157 158 _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_device)) 159 160 161 /* 162 * satadev_state field of sata_device structure. 163 * Common flags specifying current state of a port or an attached drive. 164 * These states are mutually exclusive, obviously 165 */ 166 #define SATA_STATE_UNKNOWN 0x000000 167 #define SATA_STATE_READY 0x000010 168 169 /* 170 * Attached drive specific states (satadev_state field of the sata_device 171 * structure). 172 * SATA_DSTATE_PWR_ACTIVE, SATA_DSTATE_PWR_IDLE and SATA_DSTATE_PWR_STANDBY 173 * are mutually exclusive. All other states may be combined with each other 174 * and with one of the power states. 175 * These flags may be used only if the address qualifier (satadev_addr.qual) is 176 * set to SATA_ADDR_DCPORT or SATA_ADDR_DPMPORT value. 177 */ 178 179 #define SATA_DSTATE_PWR_ACTIVE 0x000100 180 #define SATA_DSTATE_PWR_IDLE 0x000200 181 #define SATA_DSTATE_PWR_STANDBY 0x000400 182 #define SATA_DSTATE_RESET 0x001000 183 #define SATA_DSTATE_PMULT_INIT 0x002000 184 #define SATA_DSTATE_FAILED 0x008000 185 186 /* Mask for drive power states */ 187 #define SATA_DSTATE_PWR (SATA_DSTATE_PWR_ACTIVE | \ 188 SATA_DSTATE_PWR_IDLE | \ 189 SATA_DSTATE_PWR_STANDBY) 190 /* 191 * SATA Port specific states (satadev_state field of sata_device structure). 192 * SATA_PSTATE_PWRON and SATA_PSTATE_PWROFF are mutually exclusive. 193 * All other states may be combined with each other and with one of the power 194 * level state. 195 * These flags may be used only if the address qualifier (satadev_addr.qual) is 196 * set to SATA_ADDR_CPORT or SATA_ADDR_PMPORT value. 197 */ 198 199 #define SATA_PSTATE_PWRON 0x010000 200 #define SATA_PSTATE_PWROFF 0X020000 201 #define SATA_PSTATE_SHUTDOWN 0x040000 202 #define SATA_PSTATE_FAILED 0x080000 203 204 /* Mask for the valid port-specific state flags */ 205 #define SATA_PSTATE_VALID (SATA_PSTATE_PWRON | \ 206 SATA_PSTATE_PWROFF | \ 207 SATA_PSTATE_SHUTDOWN | \ 208 SATA_PSTATE_FAILED) 209 210 /* Mask for a port power states */ 211 #define SATA_PSTATE_PWR (SATA_PSTATE_PWRON | \ 212 SATA_PSTATE_PWROFF) 213 /* 214 * Device type (in satadev_type field of sata_device structure). 215 * More device types may be added in the future. 216 */ 217 218 #define SATA_DTYPE_NONE 0x00 /* No device attached */ 219 #define SATA_DTYPE_ATADISK 0x01 /* ATA disk */ 220 #define SATA_DTYPE_ATAPI 0x40 /* ATAPI device */ 221 #define SATA_DTYPE_ATAPICD \ 222 (SATA_DTYPE_ATAPI|0x02) /* ATAPI CD/DVD device */ 223 #define SATA_DTYPE_ATAPITAPE \ 224 (SATA_DTYPE_ATAPI|0x04) /* ATAPI tape */ 225 #define SATA_DTYPE_ATAPIDISK \ 226 (SATA_DTYPE_ATAPI|0x08) /* ATAPI disk */ 227 #define SATA_DTYPE_PMULT 0x10 /* Port Multiplier */ 228 #define SATA_DTYPE_UNKNOWN 0x20 /* Device attached, unkown */ 229 230 231 /* 232 * SATA cmd structure (rev 1) 233 * 234 * SATA HBA framework always sets all fields except status_reg and error_reg. 235 * SATA HBA driver action depends on the addressing type specified by 236 * addr_type field: 237 * If LBA48 addressing is indicated, SATA HBA driver has to load values from 238 * satacmd_sec_count_msb_reg, satacmd_lba_low_msb_reg, 239 * satacmd_lba_mid_msb_reg and satacmd_lba_hi_msb_reg 240 * to appropriate registers prior to loading other registers. 241 * For other addressing modes, SATA HBA driver should skip loading values 242 * from satacmd_sec_count_msb_reg, satacmd_lba_low_msb_reg, 243 * satacmd_lba_mid_msb_reg and satacmd_lba_hi_msb_reg 244 * fields and load only remaining field values to corresponding registers. 245 * 246 * satacmd_sec_count_msb and satamcd_sec_count_lsb values are loaded into 247 * sec_count register, satacmd_sec_count_msb loaded first (if LBA48 248 * addressing is used). 249 * satacmd_lba_low_msb and satacmd_lba_low_lsb values are loaded into the 250 * lba_low register, satacmd_lba_low_msb loaded first (if LBA48 addressing 251 * is used). The lba_low register is the newer name for the old 252 * sector_number register. 253 * satacmd_lba_mid_msb and satacmd_lba_mid_lsb values are loaded into lba_mid 254 * register, satacmd_lba_mid_msb loaded first (if LBA48 addressing is used). 255 * The lba_mid register is the newer name for the old cylinder_low register. 256 * satacmd_lba_high_msb and satacmd_lba_high_lsb values are loaded into 257 * the lba_high regster, satacmd_lba_high_msb loaded first (if LBA48 258 * addressing is used). The lba_high register is a newer name for the old 259 * cylinder_high register. 260 * 261 * No addressing mode is selected when an ata command does not involve actual 262 * reading/writing data from/to the media (for example IDENTIFY DEVICE or 263 * SET FEATURE command), or the ATAPI PACKET command is sent. 264 * If ATAPI PACKET command is sent and tagged commands are used, 265 * SATA HBA driver has to provide and manage a tag value and 266 * set it into the sector_count register. 267 * 268 * Device Control register is not specified in sata_cmd structure - SATA HBA 269 * driver shall set it accordingly to current mode of operation (interrupt 270 * enable/disable). 271 * 272 * Buffer structure's b_flags should be used to determine the 273 * address type of b_un.b_addr. However, there is no need to allocate DMA 274 * resources for the buffer in SATA HBA driver. 275 * DMA resources for a buffer structure are allocated by the SATA HBA 276 * framework. Scatter/gather list is to be used only for DMA transfers 277 * and it should be based on the DMA cookies list. 278 * 279 * Upon completion of a command, SATA HBA driver has to update 280 * satacmd_status_reg and satacmd_error_reg to reflect the contents of 281 * the corresponding device status and error registers. 282 * If the command completed successfully, satacmd_flags.sata_copy_xxx flags 283 * specify what register fields should be updated in sata_cmd structure. 284 * If the command completed with error, SATA HBA driver has to update 285 * satacmd_sec_count_msb, satacmd_sec_count_lsb, satacmd_lba_low_msb, 286 * satacmd_lba_low_lsb, satacmd_lba_mid_msb, satacmd_lba_mid_lsb, 287 * satacmd_lba_high_msb and satacmd_lba_high_lsb to values read from the 288 * corresponding device registers. 289 * If an operation could not complete because of the port error, the 290 * sata_pkt.satapkt_device.satadev_scr structure has to be updated. 291 * 292 * If ATAPI PACKET command was sent and command completed with error, 293 * rqsense structure has to be filed by SATA HBA driver. The satacmd_arq_cdb 294 * points to pre-set request sense cdb that may be used for issuing request 295 * sense data from the device. 296 * 297 * The sata_max_queue_depth field specifies the maximum allowable queue depth 298 * minus one, i.e. for maximum queue depth of 32, sata_max_queue_depth would 299 * be set to value 0x1f. 300 * If FPDMA-type command was sent and command completed with error, the HBA 301 * driver may use pre-set command READ LOG EXTENDED command pointed to 302 * by satacmd_rle_sata_cmd field to retrieve error data from a device. 303 * Only ATA register fields of the sata_cmd are set-up for that purpose. 304 * 305 * If the READ MULTIPLIER command was specified in cmd_reg (command directed 306 * to a port multiplier host port rather then to an attached device), 307 * upon the command completion SATA HBA driver has to update_sector count 308 * and lba fields of the sata_cmd structure to values returned via 309 * command block registers (task file registers). 310 */ 311 #define SATA_CMD_REV_1 1 312 #define SATA_CMD_REV_2 2 313 #define SATA_CMD_REV_3 3 314 #define SATA_CMD_REV SATA_CMD_REV_3 315 316 #define SATA_ATAPI_MAX_CDB_LEN 16 /* Covers both 12 and 16 byte cdbs */ 317 #define SATA_ATAPI_RQSENSE_LEN 24 /* Allocated Request Sense data */ 318 #define SATA_ATAPI_MIN_RQSENSE_LEN 18 /* Min Fixed size Request Sense data */ 319 #define SATA_ATAPI_RQSENSE_CDB_LEN 6 /* Request Sense CDB length */ 320 321 #define SATA_MAX_QUEUE_DEPTH 32 /* Default max queue depth */ 322 323 struct sata_cmd { 324 int satacmd_rev; /* version */ 325 struct buf *satacmd_bp; /* ptr to buffer structure */ 326 struct sata_cmd_flags { 327 uint32_t sata_data_direction : 3; /* 0-2 */ 328 uint32_t : 1; /* reserved */ /* 3 */ 329 uint32_t sata_queue_stag : 1; /* 4 */ 330 uint32_t sata_queue_otag : 1; /* 5 */ 331 uint32_t : 2; /* reserved */ /* 6-7 */ 332 uint32_t sata_queued : 1; /* 8 */ 333 uint32_t : 3; /* reserved */ /* 9-11 */ 334 uint32_t sata_ignore_dev_reset : 1; /* 12 */ 335 uint32_t sata_clear_dev_reset : 1; /* 13 */ 336 uint32_t : 2; /* reserved */ /* 14-15 */ 337 uint32_t sata_special_regs : 1; /* 16 */ 338 uint32_t sata_copy_out_sec_count_msb : 1; /* 17 */ 339 uint32_t sata_copy_out_lba_low_msb : 1; /* 18 */ 340 uint32_t sata_copy_out_lba_mid_msb : 1; /* 19 */ 341 uint32_t sata_copy_out_lba_high_msb : 1; /* 20 */ 342 uint32_t sata_copy_out_sec_count_lsb : 1; /* 21 */ 343 uint32_t sata_copy_out_lba_low_lsb : 1; /* 22 */ 344 uint32_t sata_copy_out_lba_mid_lsb : 1; /* 23 */ 345 uint32_t sata_copy_out_lba_high_lsb : 1; /* 24 */ 346 uint32_t sata_copy_out_device_reg : 1; /* 25 */ 347 uint32_t sata_copy_out_error_reg : 1; /* 26 */ 348 uint32_t sata_max_queue_depth: 5; /* 27-31 */ 349 } satacmd_flags; 350 uint8_t satacmd_addr_type; /* addr type: LBA28, LBA48 */ 351 uint8_t satacmd_features_reg_ext; /* features reg extended */ 352 uint8_t satacmd_sec_count_msb; /* sector count MSB (LBA48) */ 353 uint8_t satacmd_lba_low_msb; /* LBA Low MSB (LBA48) */ 354 uint8_t satacmd_lba_mid_msb; /* LBA Mid MSB (LBA48) */ 355 uint8_t satacmd_lba_high_msb; /* LBA High MSB (LBA48) */ 356 uint8_t satacmd_sec_count_lsb; /* sector count LSB */ 357 uint8_t satacmd_lba_low_lsb; /* LBA Low LSB */ 358 uint8_t satacmd_lba_mid_lsb; /* LBA Mid LSB */ 359 uint8_t satacmd_lba_high_lsb; /* LBA High LSB */ 360 uint8_t satacmd_device_reg; /* ATA dev reg & LBA28 MSB */ 361 uint8_t satacmd_cmd_reg; /* ata command code */ 362 uint8_t satacmd_features_reg; /* ATA features register */ 363 uint8_t satacmd_status_reg; /* ATA status register */ 364 uint8_t satacmd_error_reg; /* ATA error register */ 365 uint8_t satacmd_acdb_len; /* ATAPI cdb length */ 366 uint8_t satacmd_acdb[SATA_ATAPI_MAX_CDB_LEN]; /* ATAPI cdb */ 367 368 /* kept for binary compat. */ 369 uint8_t *pad1; /* unused */ 370 371 uint8_t satacmd_rqsense[SATA_ATAPI_RQSENSE_LEN]; 372 /* 373 * Error retrieval buffer 374 * dma handle pointer 375 * (for buffer DMA syncing) 376 * Valid only in error 377 * retrieval packet! 378 */ 379 ddi_dma_handle_t *satacmd_err_ret_buf_handle; 380 381 int satacmd_num_dma_cookies; /* number of dma cookies */ 382 /* ptr to dma cookie list */ 383 ddi_dma_cookie_t *satacmd_dma_cookie_list; 384 }; 385 386 typedef struct sata_cmd sata_cmd_t; 387 388 _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_cmd)) 389 390 391 /* ATA address type (in satacmd_addr_type field */ 392 #define ATA_ADDR_LBA 0x1 393 #define ATA_ADDR_LBA28 0x2 394 #define ATA_ADDR_LBA48 0x4 395 396 /* 397 * satacmd_flags : contain data transfer direction flags, 398 * tagged queuing type flags, queued command flag, and reset state handling 399 * flag. 400 */ 401 402 /* 403 * Data transfer direction flags (satacmd_flags.sata_data_direction) 404 * Direction flags are mutually exclusive. 405 */ 406 #define SATA_DIR_NODATA_XFER 0x0001 /* No data transfer */ 407 #define SATA_DIR_READ 0x0002 /* Reading data from a device */ 408 #define SATA_DIR_WRITE 0x0004 /* Writing data to a device */ 409 410 /* 411 * Tagged Queuing type flags 412 * satacmd_flags.sata_queue_stag 413 * satacmd_flags.sata_queue_otag 414 * 415 * These flags indicate how the SATA command should be queued. 416 * 417 * sata_queue_stag 418 * Simple-queue-tagged command. It may be executed out-of-order in respect 419 * to other queued commands. 420 * sata_queue_otag 421 * Ordered-queue-tagged command. It cannot be executed out-of-order in 422 * respect to other commands, i.e. it should be executed in the order of 423 * being transported to the HBA. 424 * 425 * Translated head-of-queue-tagged scsi commands and commands that are 426 * to be put at the head of the queue are treated as sata_queue_otag 427 * tagged commands. 428 */ 429 430 431 /* 432 * Queuing command set-up flag (satacmd_flags.sata_queued). 433 * This flag indicates that sata_cmd was set-up for DMA Queued command 434 * (either READ_DMA_QUEUED, READ_DMA_QUEUED_EXT, WRITE_DMA_QUEUED or 435 * WRITE_DMA_QUEUED_EXT command) or one of the Native Command Queuing commands 436 * (either READ_FPDMA_QUEUED or WRITE_FPDMA_QUEUED). 437 * This flag will be used only if sata_tran_hba_flags indicates controller 438 * support for queuing and the device for which sata_cmd is prepared supports 439 * either legacy queuing (indicated by Device Identify data word 83 bit 2) 440 * or NCQ (indicated by word 76 of Device Identify data). 441 */ 442 443 /* 444 * Reset state handling 445 * satacmd_flags.sata_ignore_dev_reset 446 * satacmd_flags.sata_clear_dev_reset 447 * 448 * SATA HBA device enters reset state if the device was subjected to 449 * the Device Reset (may also enter this state if the device was reset 450 * as a side effect of port reset). SATA HBA driver sets this state. 451 * Device stays in this condition until explicit request from SATA HBA 452 * framework to clear the state. 453 */ 454 455 /* 456 * SATA Packet structure (rev 1) 457 * hba_driver_private is for a private use of the SATA HBA driver; 458 * satapkt_framework_private is used only by SATA HBA framework; 459 * satapkt_comp is a callback function to be called when packet 460 * execution is completed (for any reason) if mode of operation is not 461 * synchronous (SATA_OPMODE_SYNCH); 462 * satapkt_reason specifies why the packet operation was completed 463 * 464 * NOTE: after the packet completion callback SATA HBA driver should not 465 * attempt to access any sata_pkt fields because sata_pkt is not valid anymore 466 * (it could have been destroyed). 467 * Since satapkt_hba_driver_private field cannot be retrieved, any hba private 468 * data respources allocated per packet and accessed via this pointer should 469 * either be freed before the completion callback is done, or the pointer has 470 * to be saved by the HBA driver before the completion callback. 471 */ 472 #define SATA_PKT_REV_1 1 473 #define SATA_PKT_REV SATA_PKT_REV_1 474 475 struct sata_pkt { 476 int satapkt_rev; /* version */ 477 struct sata_device satapkt_device; /* Device address/type */ 478 479 /* HBA driver private data */ 480 void *satapkt_hba_driver_private; 481 482 /* SATA framework priv data */ 483 void *satapkt_framework_private; 484 485 /* Rqsted mode of operation */ 486 uint32_t satapkt_op_mode; 487 488 struct sata_cmd satapkt_cmd; /* composite sata command */ 489 int satapkt_time; /* time allotted to command */ 490 void (*satapkt_comp)(struct sata_pkt *); /* callback */ 491 int satapkt_reason; /* completion reason */ 492 }; 493 494 typedef struct sata_pkt sata_pkt_t; 495 496 _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_pkt)) 497 498 499 /* 500 * Operation mode flags (in satapkt_op_mode field of sata_pkt structure). 501 * Use to specify what should be a mode of operation for specified command. 502 * Default (000b) means use Interrupt and Asynchronous mode to 503 * perform an operation. 504 * Synchronous operation menas that the packet operation has to be completed 505 * before the function called to initiate the operation returns. 506 */ 507 #define SATA_OPMODE_INTERRUPTS 0 /* Use interrupts (hint) */ 508 #define SATA_OPMODE_POLLING 1 /* Use polling instead of interrupts */ 509 #define SATA_OPMODE_ASYNCH 0 /* Return immediately after accepting pkt */ 510 #define SATA_OPMODE_SYNCH 4 /* Perform synchronous operation */ 511 512 /* 513 * satapkt_reason values: 514 * 515 * SATA_PKT_QUEUE_FULL - cmd not sent because of queue full (detected 516 * by the controller). If a device reject command for this reason, it 517 * should be reported as SATA_PKT_DEV_ERROR 518 * 519 * SATA_PKT_CMD_NOT_SUPPORTED - command not supported by a controller 520 * Controller is unable to send such command to a device. 521 * If device rejects a command, it should be reported as 522 * SATA_PKT_DEV_ERROR. 523 * 524 * SATA_PKT_DEV_ERROR - cmd failed because of device reported an error. 525 * The content of status_reg (ERROR bit has to be set) and error_reg 526 * fields of the sata_cmd structure have to be set and will be used 527 * by SATA HBA Framework to determine the error cause. 528 * 529 * SATA_PKT_PORT_ERROR - cmd failed because of a link or a port error. 530 * Link failed / no communication with a device / communication error 531 * or other port related error was detected by a controller. 532 * sata_pkt.satapkt_device.satadev_scr.sXXXXXXX words have to be set. 533 * 534 * SATA_PKT_ABORTED - cmd execution was aborted by the request from the 535 * framework. Abort mechanism is HBA driver specific. 536 * 537 * SATA_PKT_TIMEOUT - cmd execution has timed-out. Timeout specified by 538 * pkt_time was exceeded. The command was terminated by the SATA HBA 539 * driver. 540 * 541 * SATA_PKT_COMPLETED - this is a value returned when an operation 542 * completes without errors. 543 * 544 * SATA_PKT_BUSY - packet was not accepted for execution because the 545 * driver was busy performing some other operation(s). 546 * 547 * SATA_PKT_RESET - packet execution was aborted because of device 548 * reset originated by either the HBA driver or the SATA framework. 549 * 550 */ 551 552 #define SATA_PKT_BUSY -1 /* Not completed, busy */ 553 #define SATA_PKT_COMPLETED 0 /* No error */ 554 #define SATA_PKT_DEV_ERROR 1 /* Device reported error */ 555 #define SATA_PKT_QUEUE_FULL 2 /* Not accepted, queue full */ 556 #define SATA_PKT_PORT_ERROR 3 /* Not completed, port error */ 557 #define SATA_PKT_CMD_UNSUPPORTED 4 /* Cmd unsupported */ 558 #define SATA_PKT_ABORTED 5 /* Aborted by request */ 559 #define SATA_PKT_TIMEOUT 6 /* Operation timeut */ 560 #define SATA_PKT_RESET 7 /* Aborted by reset request */ 561 562 /* 563 * Error retrieval sata packet types 564 */ 565 #define SATA_ERR_RETR_PKT_TYPE_NCQ 1 566 #define SATA_ERR_RETR_PKT_TYPE_ATAPI 2 567 568 /* 569 * Read/write port multiplier packet types 570 */ 571 #define SATA_RDWR_PMULT_PKT_TYPE_READ 1 572 #define SATA_RDWR_PMULT_PKT_TYPE_WRITE 2 573 574 /* 575 * Hoplug functions vector structure (rev 1) 576 */ 577 #define SATA_TRAN_HOTPLUG_OPS_REV_1 1 578 579 struct sata_tran_hotplug_ops { 580 int sata_tran_hotplug_ops_rev; /* version */ 581 int (*sata_tran_port_activate)(dev_info_t *, sata_device_t *); 582 int (*sata_tran_port_deactivate)(dev_info_t *, sata_device_t *); 583 }; 584 585 typedef struct sata_tran_hotplug_ops sata_tran_hotplug_ops_t; 586 587 588 /* 589 * Power management functions vector structure (rev 1) 590 * The embedded function returns information about the controller's 591 * power level. 592 * Additional functions may be added in the future without changes to 593 * sata_tran structure. 594 */ 595 #define SATA_TRAN_PWRMGT_OPS_REV_1 1 596 597 struct sata_tran_pwrmgt_ops { 598 int sata_tran_pwrmgt_ops_rev; /* version */ 599 int (*sata_tran_get_pwr_level)(dev_info_t *, sata_device_t *); 600 }; 601 602 typedef struct sata_tran_pwrmgt_ops sata_tran_pwrmgt_ops_t; 603 604 605 /* 606 * SATA port PHY Power Level 607 * These states correspond to the interface power management state as defined 608 * in Serial ATA spec. 609 */ 610 #define SATA_TRAN_PORTPWR_LEVEL1 1 /* Interface in active PM state */ 611 #define SATA_TRAN_PORTPWR_LEVEL2 2 /* Interface in PARTIAL PM state */ 612 #define SATA_TRAN_PORTPWR_LEVEL3 3 /* Interface in SLUMBER PM state */ 613 614 /* 615 * SATA HBA Tran structure (rev 1) 616 * Registered with SATA Framework 617 * 618 * dma_attr is a pointer to data (buffer) dma attibutes of the controller 619 * DMA engine. 620 * 621 * The qdepth field specifies number of commands that may be accepted by 622 * the controller. Value range 1-32. A value greater than 1 indicates that 623 * the controller supports queuing. Support for Native Command Queuing 624 * indicated by SATA_CTLF_NCQ flag also requires qdepth set to a value 625 * greater then 1. 626 * 627 */ 628 #define SATA_TRAN_HBA_REV_1 1 629 #define SATA_TRAN_HBA_REV_2 2 630 #define SATA_TRAN_HBA_REV_3 3 631 #define SATA_TRAN_HBA_REV SATA_TRAN_HBA_REV_3 632 633 struct sata_hba_tran { 634 int sata_tran_hba_rev; /* version */ 635 dev_info_t *sata_tran_hba_dip; /* Controler dev info */ 636 ddi_dma_attr_t *sata_tran_hba_dma_attr; /* DMA attributes */ 637 int sata_tran_hba_num_cports; /* Num of HBA device ports */ 638 uint16_t sata_tran_hba_features_support; /* HBA features */ 639 uint16_t sata_tran_hba_qdepth; /* HBA-supported queue depth */ 640 641 int (*sata_tran_probe_port)(dev_info_t *, sata_device_t *); 642 int (*sata_tran_start)(dev_info_t *, sata_pkt_t *); 643 int (*sata_tran_abort)(dev_info_t *, sata_pkt_t *, int); 644 int (*sata_tran_reset_dport)(dev_info_t *, 645 sata_device_t *); 646 int (*sata_tran_selftest)(dev_info_t *, sata_device_t *); 647 648 /* Hotplug vector */ 649 struct sata_tran_hotplug_ops *sata_tran_hotplug_ops; 650 651 /* Power mgt vector */ 652 struct sata_tran_pwrmgt_ops *sata_tran_pwrmgt_ops; 653 654 int (*sata_tran_ioctl)(dev_info_t *, int, intptr_t); 655 }; 656 657 typedef struct sata_hba_tran sata_hba_tran_t; 658 659 660 /* 661 * Controller's features support flags (sata_tran_hba_features_support). 662 * Note: SATA_CTLF_NCQ indicates that SATA controller supports NCQ in addition 663 * to legacy queuing commands, indicated by SATA_CTLF_QCMD flag. 664 */ 665 666 #define SATA_CTLF_ATAPI 0x001 /* ATAPI support */ 667 #define SATA_CTLF_PORT_MULTIPLIER 0x010 /* Port Multiplier suport */ 668 #define SATA_CTLF_HOTPLUG 0x020 /* Hotplug support */ 669 #define SATA_CTLF_ASN 0x040 /* Asynchronous Event Support */ 670 #define SATA_CTLF_QCMD 0x080 /* Queued commands support */ 671 #define SATA_CTLF_NCQ 0x100 /* NCQ support */ 672 #define SATA_CTLF_PMULT_FBS 0x200 /* FIS-based switching support */ 673 674 /* 675 * sata_tran_start() return values. 676 * When pkt is not accepted, the satapkt_reason has to be updated 677 * before function returns - it should reflect the same reason for not being 678 * executed as the return status of above functions. 679 * If pkt was accepted and executed synchronously, 680 * satapk_reason should indicate a completion status. 681 */ 682 #define SATA_TRAN_ACCEPTED 0 /* accepted */ 683 #define SATA_TRAN_QUEUE_FULL 1 /* not accepted, queue full */ 684 #define SATA_TRAN_PORT_ERROR 2 /* not accepted, port error */ 685 #define SATA_TRAN_CMD_UNSUPPORTED 3 /* not accepted, cmd not supported */ 686 #define SATA_TRAN_BUSY 4 /* not accepted, busy */ 687 688 689 /* 690 * sata_tran_abort() abort type flag 691 */ 692 #define SATA_ABORT_PACKET 0 693 #define SATA_ABORT_ALL_PACKETS 1 694 695 696 /* 697 * Events handled by SATA HBA Framework 698 * More then one event may be reported at the same time 699 * 700 * SATA_EVNT__DEVICE_ATTACHED 701 * HBA detected the presence of a device ( electrical connection with 702 * a device was detected ). 703 * 704 * SATA_EVNT_DEVICE_DETACHED 705 * HBA detected the detachment of a device (electrical connection with 706 * a device was broken) 707 * 708 * SATA_EVNT_LINK_LOST 709 * HBA lost link with an attached device 710 * 711 * SATA_EVNT_LINK_ESTABLISHED 712 * HBA established a link with an attached device 713 * 714 * SATA_EVNT_PORT_FAILED 715 * HBA has determined that the port failed and is unuseable 716 * 717 * SATA_EVENT_DEVICE_RESET 718 * SATA device was reset, causing loss of the device setting 719 * 720 * SATA_EVNT_PWR_LEVEL_CHANGED 721 * A port or entire SATA controller power level has changed 722 * 723 * SATA_EVNT_PMULT_LINK_CHANGED 724 * Port multiplier detect change on a link of its device port 725 * 726 */ 727 #define SATA_EVNT_DEVICE_ATTACHED 0x01 728 #define SATA_EVNT_DEVICE_DETACHED 0x02 729 #define SATA_EVNT_LINK_LOST 0x04 730 #define SATA_EVNT_LINK_ESTABLISHED 0x08 731 #define SATA_EVNT_PORT_FAILED 0x10 732 #define SATA_EVNT_DEVICE_RESET 0x20 733 #define SATA_EVNT_PWR_LEVEL_CHANGED 0x40 734 #define SATA_EVNT_PMULT_LINK_CHANGED 0x80 735 736 /* 737 * SATA Framework interface entry points 738 */ 739 int sata_hba_init(struct modlinkage *); 740 int sata_hba_attach(dev_info_t *, sata_hba_tran_t *, ddi_attach_cmd_t); 741 int sata_hba_detach(dev_info_t *, ddi_detach_cmd_t); 742 void sata_hba_fini(struct modlinkage *); 743 void sata_hba_event_notify(dev_info_t *, sata_device_t *, int); 744 sata_pkt_t *sata_get_error_retrieval_pkt(dev_info_t *, sata_device_t *, int); 745 void sata_free_error_retrieval_pkt(sata_pkt_t *); 746 sata_pkt_t *sata_get_rdwr_pmult_pkt(dev_info_t *, sata_device_t *, uint8_t, 747 uint32_t, uint32_t); 748 void sata_free_rdwr_pmult_pkt(sata_pkt_t *); 749 int sata_check_pmult_blacklist(sata_device_t *); 750 void sata_free_dma_resources(sata_pkt_t *); 751 752 /* 753 * SATA trace ring buffer constants 754 */ 755 #define DMSG_RING_SIZE 0x100000 /* 1MB */ 756 #define DMSG_BUF_SIZE 256 757 758 /* 759 * SATA trace ring buffer content 760 */ 761 typedef struct sata_trace_dmsg { 762 dev_info_t *dip; 763 timespec_t timestamp; 764 char buf[DMSG_BUF_SIZE]; 765 struct sata_trace_dmsg *next; 766 } sata_trace_dmsg_t; 767 768 /* 769 * SATA trace ring buffer header 770 */ 771 typedef struct sata_trace_rbuf { 772 kmutex_t lock; /* lock to avoid clutter */ 773 int looped; /* completed ring */ 774 int allocfailed; /* dmsg mem alloc failed */ 775 size_t size; /* current size */ 776 size_t maxsize; /* max size */ 777 sata_trace_dmsg_t *dmsgh; /* messages head */ 778 sata_trace_dmsg_t *dmsgp; /* ptr to last message */ 779 } sata_trace_rbuf_t; 780 781 /* 782 * SATA trace ring buffer interfaces 783 */ 784 void sata_trace_debug(dev_info_t *, const char *fmt, ...); 785 void sata_vtrace_debug(dev_info_t *, const char *fmt, va_list); 786 787 #ifdef __cplusplus 788 } 789 #endif 790 791 #endif /* _SATA_HBA_H */ 792