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 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SATA_H 28 #define _SATA_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* 37 * Generic SATA Host Adapter Implementation 38 */ 39 40 #include <sys/types.h> 41 #include <sys/scsi/scsi.h> 42 #include <sys/scsi/impl/services.h> 43 #include <sys/sata/sata_defs.h> 44 #include <sys/sata/sata_hba.h> 45 46 /* Statistics counters */ 47 struct sata_port_stats { 48 uint64_t link_lost; /* event counter */ 49 uint64_t link_established; /* event counter */ 50 uint64_t device_attached; /* event counter */ 51 uint64_t device_detached; /* event counter */ 52 uint64_t port_reset; /* event counter */ 53 uint64_t port_pwr_changed; /* event counter */ 54 }; 55 56 typedef struct sata_port_stats sata_port_stats_t; 57 58 struct sata_drive_stats { 59 uint64_t media_error; /* available ??? */ 60 uint64_t drive_reset; /* event counter */ 61 } sata_drv_stats_t; 62 63 typedef struct sata_drive_stats sata_drive_stats_t; 64 65 struct sata_ctrl_stats { 66 uint64_t ctrl_reset; /* event counter */ 67 uint64_t ctrl_pwr_change; /* event counter */ 68 }; 69 70 typedef struct sata_ctrl_stats sata_ctrl_stats_t; 71 72 73 /* 74 * SATA HBA instance info structure 75 */ 76 struct sata_hba_inst { 77 dev_info_t *satahba_dip; /* this HBA instance devinfo */ 78 struct sata_hba_inst *satahba_next; /* ptr to next sata_hba_inst */ 79 struct sata_hba_inst *satahba_prev; /* ptr to prev sata_hba_inst */ 80 struct scsi_hba_tran *satahba_scsi_tran; /* scsi_hba_tran */ 81 struct sata_hba_tran *satahba_tran; /* sata_hba_tran */ 82 kmutex_t satahba_mutex; /* sata hba cntrl mutex */ 83 struct taskq *satahba_taskq; /* cmd completion task queue */ 84 85 /* 86 * HBA event flags: 87 * SATA_EVNT_MAIN 88 * SATA_EVNT_PWR_LEVEL_CHANGED 89 * SATA_EVNT_SKIP 90 */ 91 uint_t satahba_event_flags; 92 93 struct sata_cport_info *satahba_dev_port[SATA_MAX_CPORTS]; 94 95 /* 96 * DEVCTL open flag: 97 * SATA_DEVCTL_SOPENED 98 * SATA_DEVCTL_EXOPENED 99 */ 100 uint_t satahba_open_flag; /* shared open flag */ 101 struct sata_ctrl_stats satahba_stats; /* HBA cntrl statistics */ 102 103 uint_t satahba_attached; /* HBA attaching: */ 104 /* 0 - not completed */ 105 /* 1 - completed */ 106 }; 107 108 typedef struct sata_hba_inst sata_hba_inst_t; 109 110 /* 111 * SATA controller's device port info and state. 112 * This structure is pointed to by the sata_hba_inst.satahba_dev_port[x] 113 * where x is a device port number. 114 * cport_state holds port state flags, defined in sata_hba.h file. 115 * cport_event_flags holds SATA_EVNT_* flags defined in this file and in 116 * sata_hba.h file. 117 * cport_dev_type holds SATA_DTYPE_* types defined in sata_hba.h file. 118 */ 119 struct sata_cport_info { 120 sata_address_t cport_addr; /* this port SATA address */ 121 kmutex_t cport_mutex; /* port mutex */ 122 123 /* 124 * Port state flags 125 * SATA_STATE_UNKNOWN 126 * SATA_STATE_PROBING 127 * SATA_STATE_PROBED 128 * SATA_STATE_READY 129 * SATA_PSTATE_PWRON 130 * SATA_PSTATE_PWROFF 131 * SATA_PSTATE_SHUTDOWN 132 * SATA_PSTATE_FAILED 133 */ 134 uint32_t cport_state; 135 136 /* 137 * Port event flags: 138 * SATA_EVNT_DEVICE_ATTACHED 139 * SATA_EVNT_DEVICE_DETACHED 140 * SATA_EVNT_LINK_LOST 141 * SATA_EVNT_LINK_ESTABLISHED 142 * SATA_EVNT_PORT_FAILED 143 * SATA_EVNT_PWR_LEVEL_CHANGED 144 */ 145 uint32_t cport_event_flags; 146 147 struct sata_port_scr cport_scr; /* Port status and ctrl regs */ 148 149 /* 150 * Attached device type: 151 * SATA_DTYPE_NONE 152 * SATA_DTYPE_ATADISK 153 * SATA_DTYPE_ATAPICD 154 * SATA_DTYPE_ATAPINONCD 155 * SATA_DTYPE_PMULT 156 * SATA_DTYPE_UNKNOWN 157 */ 158 uint32_t cport_dev_type; 159 union { 160 struct sata_drive_info *cport_sata_drive; /* Attached drive info */ 161 struct sata_pmult_info *cport_sata_pmult; /* Attached Port Mult */ 162 } cport_devp; 163 /* lbolt value at link lost */ 164 clock_t cport_link_lost_time; 165 166 struct sata_port_stats cport_stats; /* Port statistics */ 167 }; 168 169 typedef struct sata_cport_info sata_cport_info_t; 170 171 /* 172 * Attached SATA drive info and state. 173 * This structure is pointed to by sata_cport_info's cport_sata_drive field 174 * when a drive is attached directly to a controller device port. 175 */ 176 struct sata_drive_info { 177 sata_address_t satadrv_addr; /* this drive SATA address */ 178 179 /* 180 * Drive state flags 181 * SATA_STATE_UNKNOWN 182 * SATA_STATE_PROBING 183 * SATA_STATE_PROBED 184 * SATA_STATE_READY 185 * SATA_DSTATE_PWR_ACTIVE 186 * SATA_DSTATE_PWR_IDLE 187 * SATA_DSTATE_RESET 188 * SATA_DSTATE_FAILED 189 */ 190 uint32_t satadrv_state; 191 192 /* 193 * drive event flags: 194 * SATA_EVNT_DRIVE_RESET 195 */ 196 uint32_t satadrv_event_flags; 197 198 /* 199 * Attached device type: 200 * SATA_DTYPE_ATADISK 201 * SATA_DTYPE_ATAPICD 202 * SATA_DTYPE_ATAPINONCD 203 */ 204 uint32_t satadrv_type; 205 206 uint32_t satadrv_status_reg; /* drive status reg */ 207 uint32_t satadrv_error_reg; /* drive error reg */ 208 uint16_t satadrv_features_support; /* drive features support */ 209 uint16_t satadrv_queue_depth; /* drive queue depth */ 210 uint16_t satadrv_settings; /* drive settings flags */ 211 uint16_t satadrv_pad2; /* struct alignment pad */ 212 uint64_t satadrv_capacity; /* drive capacity */ 213 sata_id_t satadrv_id; /* Device Identify Data */ 214 struct sata_drive_stats satadrv_stats; /* drive statistics */ 215 }; 216 217 typedef struct sata_drive_info sata_drive_info_t; 218 219 _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_drive_info)) 220 221 222 /* Port Multiplier & host port info and state */ 223 struct sata_pmult_info { 224 sata_address_t pmult_addr; /* this PMult SATA Address */ 225 kmutex_t pmult_mutex; /* pmult (host port) mutex */ 226 227 /* 228 * PMult state flags 229 * SATA_STATE_UNKNOWN 230 * SATA_STATE_PROBING 231 * SATA_STATE_PROBED 232 * SATA_STATE_READY 233 * SATA_PSTATE_FAILED 234 */ 235 uint32_t pmult_state; 236 uint32_t pmult_event_flags; /* Undefined for now */ 237 struct sata_port_scr pmult_scr; /* Host port SCR block */ 238 uint32_t pmult_num_dev_ports; /* Number of data ports */ 239 struct sata_pmport_info *pmult_dev_port[SATA_MAX_PMPORTS - 1]; 240 }; 241 242 typedef struct sata_pmult_info sata_pmult_info_t; 243 244 /* Port Multiplier's device port info & state */ 245 struct sata_pmport_info { 246 sata_address_t pmport_addr; /* this SATA port address */ 247 kmutex_t pmport_mutex; /* pmult device port mutex */ 248 249 /* 250 * Port state flags 251 * SATA_STATE_UNKNOWN 252 * SATA_STATE_PROBING 253 * SATA_STATE_PROBED 254 * SATA_STATE_READY 255 * SATA_PSTATE_PWRON 256 * SATA_PSTATE_PWROFF 257 * SATA_PSTATE_SHUTDOWN 258 * SATA_PSTATE_FAILED 259 */ 260 uint32_t pmport_state; 261 262 /* 263 * Port event flags: 264 * SATA_EVNT_DEVICE_ATTACHED 265 * SATA_EVNT_DEVICE_DETACHED 266 * SATA_EVNT_LINK_LOST 267 * SATA_EVNT_LINK_ESTABLISHED 268 * SATA_EVNT_PORT_FAILED 269 * SATA_EVNT_PWR_LEVEL_CHANGED 270 */ 271 uint32_t pmport_event_flags; 272 273 struct sata_port_scr pmport_scr; /* PMult device port scr */ 274 275 /* 276 * Attached device type: 277 * SATA_DTYPE_NONE 278 * SATA_DTYPE_ATADISK 279 * SATA_DTYPE_ATAPICD 280 * SATA_DTYPE_ATAPINONCD 281 * SATA_DTYPE_UNKNOWN 282 */ 283 uint32_t pmport_dev_type; 284 285 struct sata_drive_info *pmport_sata_drive; /* Attached drive info */ 286 287 /* lbolt value at link lost */ 288 clock_t pmport_link_lost_time; 289 290 struct sata_port_stats pmport_stats; /* Port statistics */ 291 }; 292 293 typedef struct sata_pmport_info sata_pmport_info_t; 294 295 /* 296 * Port SSTATUS register (sata_port_scr sport_sstatus field). 297 * Link bits are valid only in port active state. 298 */ 299 #define SATA_PORT_DEVLINK_UP 0x00000103 /* Link with dev established */ 300 #define SATA_PORT_DEVLINK_UP_MASK 0x0000010F /* Mask for link bits */ 301 302 /* 303 * Port state clear mask (cport_state and pmport_state fields). 304 * SATA_PSTATE_SHUTDOWN and power state are preserved. 305 */ 306 #define SATA_PORT_STATE_CLEAR_MASK (~(SATA_PSTATE_SHUTDOWN)) 307 308 /* 309 * Valid i.e.supported device types mask (cport_dev_type, satadrv_type, 310 * pmult_dev_type fields). 311 */ 312 #define SATA_VALID_DEV_TYPE (SATA_DTYPE_ATADISK) /* only disks now */ 313 314 /* 315 * Device feature_support (satadrv_features_support) 316 */ 317 #define SATA_DEV_F_DMA 0x01 318 #define SATA_DEV_F_LBA28 0x02 319 #define SATA_DEV_F_LBA48 0x04 320 #define SATA_DEV_F_NCQ 0x08 321 #define SATA_DEV_F_SATA1 0x10 322 #define SATA_DEV_F_SATA2 0x20 323 324 /* 325 * Drive settings flags (satdrv_settings) 326 */ 327 #define SATA_DEV_READ_AHEAD 0x0001 /* Read Ahead enabled */ 328 #define SATA_DEV_WRITE_CACHE 0x0002 /* Write cache ON */ 329 #define SATA_DEV_SERIAL_FEATURES 0x8000 /* Serial ATA feat. enabled */ 330 #define SATA_DEV_ASYNCH_NOTIFY 0x2000 /* Asynch-event enabled */ 331 332 333 /* 334 * Internal event and flags. 335 * These flags are set in the *_event_flags fields of various structures. 336 * Events and lock flags defined below are used internally by the 337 * SATA framework (they are not reported by SATA HBA drivers). 338 */ 339 #define SATA_EVNT_MAIN 0x80000000 340 #define SATA_EVNT_SKIP 0x40000000 341 #define SATA_EVNT_INPROC_DEVICE_RESET 0x08000000 342 #define SATA_EVNT_CLEAR_DEVICE_RESET 0x04000000 343 344 /* 345 * Lock flags - used to serialize configuration operations 346 * on ports and devices. 347 * SATA_EVNT_LOCK_PORT_BUSY is set by event daemon to prevent 348 * simultaneous cfgadm operations. 349 * SATA_APCTL_LOCK_PORT_BUSY is set by cfgadm ioctls to prevent 350 * simultaneous event processing. 351 */ 352 #define SATA_EVNT_LOCK_PORT_BUSY 0x00800000 353 #define SATA_APCTL_LOCK_PORT_BUSY 0x00400000 354 355 /* Mask for port events */ 356 #define SATA_EVNT_PORT_EVENTS (SATA_EVNT_DEVICE_ATTACHED | \ 357 SATA_EVNT_DEVICE_DETACHED | \ 358 SATA_EVNT_LINK_LOST | \ 359 SATA_EVNT_LINK_ESTABLISHED | \ 360 SATA_EVNT_PORT_FAILED) 361 /* Mask for drive events */ 362 #define SATA_EVNT_DRIVE_EVENTS SATA_EVNT_DEVICE_RESET 363 #define SATA_EVNT_CONTROLLER_EVENTS SATA_EVNT_PWR_LEVEL_CHANGED 364 365 /* Delays and timeounts definitions */ 366 #define SATA_EVNT_DAEMON_SLEEP_TIME 50000 /* 50 ms */ 367 #define SATA_EVNT_DAEMON_TERM_TIMEOUT 100000 /* 100 ms */ 368 #define SATA_EVNT_DAEMON_TERM_WAIT 60000000 /* 60 s */ 369 #define SATA_EVNT_LINK_LOST_TIMEOUT 1000000 /* 1 s */ 370 371 #define SATA_DEVICE_IDENTIFY_RETRY 2 372 373 /* 374 * sata_scsi's hba_open_flag: field indicating open devctl instance. 375 * 0 = closed, 1 = shared open, 2 = exclusive open. 376 */ 377 #define SATA_DEVCTL_CLOSED 0 378 #define SATA_DEVCTL_SOPENED 1 379 #define SATA_DEVCTL_EXOPENED 2 380 381 /* 382 * sata_pkt_txlate structure contains info about resources allocated 383 * for the packet 384 * Address of this structure is stored in scsi_pkt.pkt_ha_private and 385 * in sata_pkt.sata_hba_private fields, so all three strucures are 386 * cross-linked, with sata_pkt_txlate as a centerpiece. 387 */ 388 389 typedef struct sata_pkt_txlate { 390 struct sata_hba_inst *txlt_sata_hba_inst; 391 struct scsi_pkt *txlt_scsi_pkt; 392 struct sata_pkt *txlt_sata_pkt; 393 ddi_dma_handle_t txlt_buf_dma_handle; 394 uint_t txlt_flags; /* data-in / data-out */ 395 uint_t txlt_num_dma_win; /* number of DMA windows */ 396 uint_t txlt_cur_dma_win; /* current DMA window */ 397 398 /* cookies in the current DMA window */ 399 uint_t txlt_curwin_num_dma_cookies; 400 401 /* procesed dma cookies in current DMA win */ 402 uint_t txlt_curwin_processed_dma_cookies; 403 size_t txlt_total_residue; 404 int txlt_dma_cookie_list_len; /* alloc list len */ 405 ddi_dma_cookie_t *txlt_dma_cookie_list; /* dma cookie list */ 406 int txlt_num_dma_cookies; /* dma cookies in list */ 407 } sata_pkt_txlate_t; 408 409 _NOTE(SCHEME_PROTECTS_DATA("unshared data", sata_pkt_txlate)) 410 _NOTE(SCHEME_PROTECTS_DATA("unshared data", scsi_pkt)) 411 412 413 /* 414 * Additional scsi sense code definitions. 415 * These definition should eventually be moved to scsi header files. 416 */ 417 #define SD_SCSI_NO_ADD_SENSE 0x00 418 #define SD_SCSI_LU_NOT_READY 0x04 419 #define SD_SCSI_WRITE_ERROR 0x0c 420 #define SD_SCSI_UNREC_READ_ERROR 0x11 421 #define SD_SCSI_INVALID_COMMAND_CODE 0x20 422 #define SD_SCSI_LBA_OUT_OF_RANGE 0x21 423 #define SD_SCSI_INVALID_FIELD_IN_CDB 0x24 424 #define SD_SCSI_INVALID_FIELD_IN_PARAMETER_LIST 0x26 425 #define SD_SCSI_SAVING_PARAMS_NOT_SUP 0x39 426 427 428 /* SCSI defs missing from scsi headers */ 429 /* Missing from sys/scsi/generic/commands.h */ 430 #define SCMD_SYNCHRONIZE_CACHE_G1 0x91 431 /* 432 * Missing from sys/scsi/impl/mode.h, although defined 433 * in sys/scsi/targets/sddefs.h as MODEPAGE_ERR_RECOV 434 */ 435 #define MODEPAGE_RW_ERRRECOV 0x01 /* read/write recovery */ 436 437 /* 438 * Macros for accessing various structure fields 439 * 440 */ 441 442 #define SATA_TRAN(sata_hba_inst) \ 443 sata_hba_inst->satahba_tran 444 445 #define SATA_DIP(sata_hba_inst) \ 446 sata_hba_inst->satahba_dip 447 448 #define SATA_NUM_CPORTS(sata_hba_inst) \ 449 sata_hba_inst->satahba_tran->sata_tran_hba_num_cports 450 451 #define SATA_QDEPTH(sata_hba_inst) \ 452 sata_hba_inst->satahba_tran->sata_tran_hba_qdepth 453 454 #define SATA_FEATURES(sata_hba_inst) \ 455 sata_hba_inst->satahba_tran->sata_tran_hba_features_support 456 457 #define SATA_DMA_ATTR(sata_hba_inst) \ 458 sata_hba_inst->satahba_tran->sata_tran_hba_dma_attr 459 460 #define SATA_START_FUNC(sata_hba_inst) \ 461 sata_hba_inst->satahba_tran->sata_tran_start 462 463 #define SATA_ABORT_FUNC(sata_hba_inst) \ 464 sata_hba_inst->satahba_tran->sata_tran_abort 465 466 #define SATA_RESET_DPORT_FUNC(sata_hba_inst) \ 467 sata_hba_inst->satahba_tran->sata_tran_reset_dport 468 469 #define SATA_PORT_DEACTIVATE_FUNC(sata_hba_inst) \ 470 (sata_hba_inst->satahba_tran->sata_tran_hotplug_ops == NULL ? \ 471 NULL : \ 472 sata_hba_inst->satahba_tran->sata_tran_hotplug_ops->\ 473 sata_tran_port_deactivate) 474 475 #define SATA_PORT_ACTIVATE_FUNC(sata_hba_inst) \ 476 (sata_hba_inst->satahba_tran->sata_tran_hotplug_ops == NULL ? \ 477 NULL : \ 478 sata_hba_inst->satahba_tran->sata_tran_hotplug_ops->\ 479 sata_tran_port_activate) 480 481 #define SATA_PROBE_PORT_FUNC(sata_hba_inst) \ 482 sata_hba_inst->satahba_tran->sata_tran_probe_port 483 484 #define SATA_SELFTEST_FUNC(sata_hba_inst) \ 485 sata_hba_inst->satahba_tran->sata_tran_selftest 486 487 #define SATA_CPORT_MUTEX(sata_hba_inst, cport) \ 488 sata_hba_inst->satahba_dev_port[cport]->cport_mutex 489 490 #define SATA_CPORT_INFO(sata_hba_inst, cport) \ 491 sata_hba_inst->satahba_dev_port[cport] 492 493 #define SATA_CPORT_STATE(sata_hba_inst, cport) \ 494 sata_hba_inst->satahba_dev_port[cport]->cport_state 495 496 #define SATA_CPORT_SCR(sata_hba_inst, cport) \ 497 sata_hba_inst->satahba_dev_port[cport]->cport_scr 498 499 #define SATA_CPORT_DEV_TYPE(sata_hba_inst, cport) \ 500 sata_hba_inst->satahba_dev_port[cport]->cport_dev_type 501 502 #define SATA_CPORT_DRV_INFO(sata_hba_inst, cport) \ 503 sata_hba_inst->satahba_dev_port[cport]->cport_devp.cport_sata_drive 504 505 #define SATA_CPORTINFO_DRV_TYPE(cportinfo) \ 506 cportinfo->cport_dev_type 507 508 #define SATA_CPORTINFO_DRV_INFO(cportinfo) \ 509 cportinfo->cport_devp.cport_sata_drive 510 511 #define SATA_CPORTINFO_PMULT_INFO(cportinfo) \ 512 cportinfo->cport_devp.cport_sata_pmult 513 514 #define SATA_PMULT_INFO(sata_hba_inst, cport) \ 515 sata_hba_inst->satahba_dev_port[cport]->cport_devp.cport_sata_pmult 516 517 #define SATA_NUM_PMPORTS(sata_hba_inst, cport) \ 518 sata_hba_inst->satahba_dev_port[cport]->\ 519 cport_devp.cport_sata_pmult->pmult_num_dev_ports 520 521 #define SATA_PMPORT_INFO(sata_hba_inst, cport, pmport) \ 522 sata_hba_inst->satahba_dev_port[cport]->\ 523 cport_devp.cport_sata_pmult->pmult_dev_port[pmport] 524 525 #define SATA_PMPORT_DRV_INFO(sata_hba_inst, cport, pmport) \ 526 sata_hba_inst->satahba_dev_port[cport]->\ 527 cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->\ 528 pmport_sata_drive 529 530 #define SATA_PMPORT_STATE(sata_hba_inst, cport, pmport) \ 531 sata_hba_inst->satahba_dev_port[cport]->\ 532 cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_state 533 534 #define SATA_PMPORT_SCR(sata_hba_inst, cport, pmport) \ 535 sata_hba_inst->satahba_dev_port[cport]->\ 536 cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_scr 537 538 #define SATA_PMPORT_DEV_TYPE(sata_hba_inst, cport, pmport) \ 539 sata_hba_inst->satahba_dev_port[cport]->\ 540 cport_devp.cport_sata_pmult->pmult_dev_port[pmport]->pmport_dev_type 541 542 #define SATA_TXLT_HBA_INST(spx) \ 543 spx->txlt_sata_hba_inst 544 545 #define SATA_TXLT_CPORT(spx) \ 546 spx->txlt_sata_pkt->satapkt_device.satadev_addr.cport 547 548 #define SATA_TXLT_CPORT_MUTEX(spx) \ 549 spx->txlt_sata_hba_inst->\ 550 satahba_dev_port[spx->txlt_sata_pkt->\ 551 satapkt_device.satadev_addr.cport]->cport_mutex 552 553 #define SATA_TXLT_TASKQ(spx) \ 554 spx->txlt_sata_hba_inst->\ 555 satahba_taskq 556 557 /* 558 * Minor number construction for devctl and attachment point nodes. 559 * All necessary information has to be encoded in NBITSMINOR32 bits. 560 * 561 * Devctl node minor number: 562 * ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | SATA_DEVCTL_NODE) 563 * 564 * Attachment point node minor number has to include controller 565 * instance (7 bits), controller port number (5 bits) and port multiplier 566 * device port number (4 bits) and port multiplier device port 567 * indicator (1 bit). Additionally, a single bit is used to 568 * differentiate between attachment point node and device control node. 569 * 570 * Attachment point minor number: 571 * ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | SATA_AP_NODE | 572 * [(port_multiplier_device_port << SATA_PMULT_PORT_SHIFT) | SATA_PMULT_AP] | 573 * (controller_port)) 574 * 575 * 17 bits are used (if 64 instances of controllers are expected) 576 * bit 18 is reserved for future use. 577 * 578 * -------------------------------------------------------- 579 * |17|16|15|14|13|12|11|10 |09|08|07|06|05|04|03|02|01|00| 580 * -------------------------------------------------------- 581 * | R| c| c| c| c| c| c|a/d|pm|pp|pp|pp|pp|cp|cp|cp|cp|cp| 582 * -------------------------------------------------------- 583 * Where: 584 * cp - device port number on the HBA SATA controller 585 * pp - device port number on the port multiplier 586 * pm - 0 - target attached to controller device port 587 * 1 - target attached to port multiplier's device port 588 * a/d - 0 - devctl node 589 * 1 - attachment point node 590 * c - controller number 591 * R - reserved bit 592 */ 593 594 #define SATA_AP_NODE 0x400 /* Attachment Point node */ 595 #define SATA_DEVCTL_NODE 0x000 /* DEVCTL node */ 596 #define SATA_PMULT_AP 0x200 /* device on PMult port */ 597 #define SATA_PMULT_PORT_SHIFT 5 598 #define SATA_CNTRL_INSTANCE_SHIFT 11 599 #define SATA_CPORT_MASK 0x1f /* 32 device ports */ 600 #define SATA_PMULT_PORT_MASK 0xf /* 15 device ports */ 601 #define SATA_CNTRL_INSTANCE_MASK 0x03F /* 64 controllers */ 602 603 /* Macro for creating devctl node minor number */ 604 #define SATA_MAKE_DEVCTL_MINOR(controller_instance) \ 605 ((controller_instance << SATA_CNTRL_INSTANCE_SHIFT) | \ 606 SATA_DEVCTL_NODE) 607 608 /* Macro for creating an attachment point node minor number */ 609 #define SATA_MAKE_AP_MINOR(cntrl_instance, cport, pmport, qual) \ 610 (qual & (SATA_ADDR_PMPORT | SATA_ADDR_DPMPORT) ? \ 611 (((cntrl_instance) << SATA_CNTRL_INSTANCE_SHIFT) | \ 612 SATA_AP_NODE | SATA_PMULT_AP | \ 613 (pmport << SATA_PMULT_PORT_SHIFT) | cport) : \ 614 (((cntrl_instance) << SATA_CNTRL_INSTANCE_SHIFT) | \ 615 SATA_AP_NODE | cport)) 616 617 /* Macro retrieving controller number from a minor number */ 618 #define SATA_MINOR2INSTANCE(minor) \ 619 ((minor >> SATA_CNTRL_INSTANCE_SHIFT) & SATA_CNTRL_INSTANCE_MASK) 620 621 /* 622 * Macro for creating an attachment point number from sata address. 623 * Address qualifier has to be one of: 624 * SATA_ADDR_DCPORT, SATA_ADDR_DPMPORT, SATA_ADDR_CPORT or SATA_ADDR_PMPORT 625 */ 626 #define SATA_MAKE_AP_NUMBER(cport, pmport, qual) \ 627 ((qual & (SATA_ADDR_PMPORT | SATA_ADDR_DPMPORT)) ? \ 628 (SATA_PMULT_AP | (pmport << SATA_PMULT_PORT_SHIFT) | cport) : \ 629 (cport)) 630 631 /* 632 * SCSI target number format 633 * 634 * ------------------------------- 635 * | 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| Bit number 636 * ------------------------------- 637 * |pm|pp|pp|pp|pp|cp|cp|cp|cp|cp| 638 * ------------------------------- 639 * Where: 640 * cp - device port number on the HBA SATA controller 641 * pp - device port number on the port multiplier 642 * pm - 0 - target attached to controller device port 643 * 1 - target attached to port multiplier's device port 644 */ 645 646 /* SATA ports to SCSI target number translation */ 647 648 #define SATA_TO_SCSI_TARGET(cport, pmport, qual) \ 649 (qual == SATA_ADDR_DCPORT ? cport : \ 650 (cport | (pmport << SATA_PMULT_PORT_SHIFT) | SATA_PMULT_AP)) 651 652 /* SCSI target number to SATA cntrl/pmport/cport translations */ 653 #define SCSI_TO_SATA_CPORT(scsi_target) \ 654 (scsi_target & SATA_CPORT_MASK) 655 656 #define SCSI_TO_SATA_PMPORT(scsi_target) \ 657 ((scsi_target >> SATA_PMULT_PORT_SHIFT) & SATA_PMULT_PORT_MASK) 658 659 #define SCSI_TO_SATA_ADDR_QUAL(scsi_target) \ 660 ((scsi_target & SATA_PMULT_AP) ? SATA_ADDR_DPMPORT : \ 661 SATA_ADDR_DCPORT) 662 663 664 /* Debug flags */ 665 #if DEBUG 666 667 #define SATA_DEBUG 668 #define SATA_DBG_SCSI_IF 1 669 #define SATA_DBG_HBA_IF 2 670 #define SATA_DBG_NODES 4 671 #define SATA_DBG_IOCTL_IF 8 672 #define SATA_DBG_EVENTS 0x10 673 #define SATA_DBG_EVENTS_PROC 0x20 674 #define SATA_DBG_EVENTS_PROCPST 0x40 675 #define SATA_DBG_EVENTS_CNTRL 0x80 676 #define SATA_DBG_EVENTS_DAEMON 0x100 677 #define SATA_DBG_DMA_SETUP 0x400 678 679 extern int sata_debug_flag; 680 681 /* Debug macros */ 682 #define SATADBG1(flag, sata, format, arg1) \ 683 if (sata_debug_flags & (flag)) { \ 684 sata_log(sata, CE_CONT, format, arg1); \ 685 } 686 687 #define SATADBG2(flag, sata, format, arg1, arg2) \ 688 if (sata_debug_flags & (flag)) { \ 689 sata_log(sata, CE_CONT, format, arg1, arg2); \ 690 } 691 692 #define SATADBG3(flag, sata, format, arg1, arg2, arg3) \ 693 if (sata_debug_flags & (flag)) { \ 694 sata_log(sata, CE_CONT, format, arg1, arg2, arg3); \ 695 } 696 #else 697 698 #define SATADBG1(flag, dip, frmt, arg1) 699 #define SATADBG2(flag, dip, frmt, arg1, arg2) 700 #define SATADBG3(flag, dip, frmt, arg1, arg2, arg3) 701 702 #endif 703 704 #ifdef __cplusplus 705 } 706 #endif 707 708 #endif /* _SATA_H */ 709