1 /* 2 * megaraid_sas.h: header for mega_sas 3 * 4 * Solaris MegaRAID driver for SAS controllers 5 * Copyright (c) 2004-2008, LSI Logic Corporation. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright notice, 15 * this list of conditions and the following disclaimer in the documentation 16 * and/or other materials provided with the distribution. 17 * 18 * 3. Neither the name of the author nor the names of its contributors may be 19 * used to endorse or promote products derived from this software without 20 * specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 33 * DAMAGE. 34 */ 35 36 /* 37 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 38 * Use is subject to license terms. 39 */ 40 41 #ifndef _MEGARAID_SAS_H_ 42 #define _MEGARAID_SAS_H_ 43 44 #pragma ident "%Z%%M% %I% %E% SMI" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 #include <sys/scsi/scsi.h> 51 #include "list.h" 52 53 #pragma pack(1) 54 55 /* 56 * MegaRAID SAS Driver meta data 57 */ 58 #define MEGASAS_VERSION "LSIv1.23" 59 #define MEGASAS_RELDATE "Mar 31, 2008" 60 61 #define MEGASAS_TRUE 1 62 #define MEGASAS_FALSE 0 63 64 /* 65 * MegaRAID device id conversion definitions. 66 */ 67 #define INST2LSIRDCTL(x) ((x) << INST_MINOR_SHIFT) 68 69 /* 70 * MegaRAID SAS supported controllers 71 */ 72 #define PCI_DEVICE_ID_LSI_1064 0x0411 73 #define PCI_DEVICE_ID_LSI_1078 0x0060 74 #define PCI_DEVICE_ID_LSI_1078DE 0x007C 75 76 #define PCI_DEVICE_ID_DELL_PERC5 0x0015 77 #define PCI_DEVICE_ID_DELL_SAS5 0x0054 78 79 #define PCI_SUBSYSTEM_DELL_PERC5E 0x1F01 80 #define PCI_SUBSYSTEM_DELL_PERC5I 0x1F02 81 #define PCI_SUBSYSTEM_DELL_PERC5I_INTEGRATED 0x1F03 82 #define PCI_SUBSYSTEM_DELL_SAS5I 0x1F05 83 #define PCI_SUBSYSTEM_DELL_SAS5I_INTEGRATED 0x1F06 84 85 #define PCI_SUB_DEVICEID_FSC 0x1081 86 #define PCI_SUB_VENDORID_FSC 0x1734 87 88 #define REGISTER_SET_IO (1) 89 90 #define MEGASAS_MAX_SGE_CNT 0x50 91 92 #define MEGASAS_IOCTL_DRIVER 0x12341234 93 #define MEGASAS_IOCTL_FIRMWARE 0x12345678 94 #define MEGASAS_IOCTL_AEN 0x87654321 95 96 #define MEGASAS_1_SECOND 1000000 97 /* 98 * ===================================== 99 * MegaRAID SAS MFI firmware definitions 100 * ===================================== 101 */ 102 /* 103 * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for 104 * protocol between the software and firmware. Commands are issued using 105 * "message frames" 106 */ 107 108 /* 109 * FW posts its state in upper 4 bits of outbound_msg_0 register 110 */ 111 #define MFI_STATE_MASK 0xF0000000 112 #define MFI_STATE_UNDEFINED 0x00000000 113 #define MFI_STATE_BB_INIT 0x10000000 114 #define MFI_STATE_FW_INIT 0x40000000 115 #define MFI_STATE_WAIT_HANDSHAKE 0x60000000 116 #define MFI_STATE_FW_INIT_2 0x70000000 117 #define MFI_STATE_DEVICE_SCAN 0x80000000 118 #define MFI_STATE_BOOT_MESSAGE_PENDING 0x90000000 119 #define MFI_STATE_FLUSH_CACHE 0xA0000000 120 #define MFI_STATE_READY 0xB0000000 121 #define MFI_STATE_OPERATIONAL 0xC0000000 122 #define MFI_STATE_FAULT 0xF0000000 123 124 #define MEGAMFI_FRAME_SIZE 64 125 126 /* 127 * During FW init, clear pending cmds & reset state using inbound_msg_0 128 * 129 * ABORT : Abort all pending cmds 130 * READY : Move from OPERATIONAL to READY state; discard queue info 131 * MFIMODE : Discard (possible) low MFA posted in 64-bit mode (??) 132 * CLR_HANDSHAKE: FW is waiting for HANDSHAKE from BIOS or Driver 133 */ 134 #define MFI_INIT_ABORT 0x00000001 135 #define MFI_INIT_READY 0x00000002 136 #define MFI_INIT_MFIMODE 0x00000004 137 #define MFI_INIT_CLEAR_HANDSHAKE 0x00000008 138 #define MFI_INIT_HOTPLUG 0x00000010 139 #define MFI_STOP_ADP 0x00000020 140 #define MFI_RESET_FLAGS MFI_INIT_READY|MFI_INIT_MFIMODE|MFI_INIT_ABORT 141 142 /* 143 * MFI frame flags 144 */ 145 #define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000 146 #define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE 0x0001 147 #define MFI_FRAME_SGL32 0x0000 148 #define MFI_FRAME_SGL64 0x0002 149 #define MFI_FRAME_SENSE32 0x0000 150 #define MFI_FRAME_SENSE64 0x0004 151 #define MFI_FRAME_DIR_NONE 0x0000 152 #define MFI_FRAME_DIR_WRITE 0x0008 153 #define MFI_FRAME_DIR_READ 0x0010 154 #define MFI_FRAME_DIR_BOTH 0x0018 155 156 /* 157 * Definition for cmd_status 158 */ 159 #define MFI_CMD_STATUS_POLL_MODE 0xFF 160 161 /* 162 * MFI command opcodes 163 */ 164 #define MFI_CMD_OP_INIT 0x00 165 #define MFI_CMD_OP_LD_READ 0x01 166 #define MFI_CMD_OP_LD_WRITE 0x02 167 #define MFI_CMD_OP_LD_SCSI 0x03 168 #define MFI_CMD_OP_PD_SCSI 0x04 169 #define MFI_CMD_OP_DCMD 0x05 170 #define MFI_CMD_OP_ABORT 0x06 171 #define MFI_CMD_OP_SMP 0x07 172 #define MFI_CMD_OP_STP 0x08 173 174 #define MR_DCMD_CTRL_GET_INFO 0x01010000 175 176 #define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000 177 #define MR_FLUSH_CTRL_CACHE 0x01 178 #define MR_FLUSH_DISK_CACHE 0x02 179 180 #define MR_DCMD_CTRL_SHUTDOWN 0x01050000 181 #define MR_ENABLE_DRIVE_SPINDOWN 0x01 182 183 #define MR_DCMD_CTRL_EVENT_GET_INFO 0x01040100 184 #define MR_DCMD_CTRL_EVENT_GET 0x01040300 185 #define MR_DCMD_CTRL_EVENT_WAIT 0x01040500 186 #define MR_DCMD_LD_GET_PROPERTIES 0x03030000 187 188 /* 189 * Solaris Specific MAX values 190 */ 191 #define MAX_SGL 24 192 /* 193 * MFI command completion codes 194 */ 195 enum MFI_STAT { 196 MFI_STAT_OK = 0x00, 197 MFI_STAT_INVALID_CMD = 0x01, 198 MFI_STAT_INVALID_DCMD = 0x02, 199 MFI_STAT_INVALID_PARAMETER = 0x03, 200 MFI_STAT_INVALID_SEQUENCE_NUMBER = 0x04, 201 MFI_STAT_ABORT_NOT_POSSIBLE = 0x05, 202 MFI_STAT_APP_HOST_CODE_NOT_FOUND = 0x06, 203 MFI_STAT_APP_IN_USE = 0x07, 204 MFI_STAT_APP_NOT_INITIALIZED = 0x08, 205 MFI_STAT_ARRAY_INDEX_INVALID = 0x09, 206 MFI_STAT_ARRAY_ROW_NOT_EMPTY = 0x0a, 207 MFI_STAT_CONFIG_RESOURCE_CONFLICT = 0x0b, 208 MFI_STAT_DEVICE_NOT_FOUND = 0x0c, 209 MFI_STAT_DRIVE_TOO_SMALL = 0x0d, 210 MFI_STAT_FLASH_ALLOC_FAIL = 0x0e, 211 MFI_STAT_FLASH_BUSY = 0x0f, 212 MFI_STAT_FLASH_ERROR = 0x10, 213 MFI_STAT_FLASH_IMAGE_BAD = 0x11, 214 MFI_STAT_FLASH_IMAGE_INCOMPLETE = 0x12, 215 MFI_STAT_FLASH_NOT_OPEN = 0x13, 216 MFI_STAT_FLASH_NOT_STARTED = 0x14, 217 MFI_STAT_FLUSH_FAILED = 0x15, 218 MFI_STAT_HOST_CODE_NOT_FOUNT = 0x16, 219 MFI_STAT_LD_CC_IN_PROGRESS = 0x17, 220 MFI_STAT_LD_INIT_IN_PROGRESS = 0x18, 221 MFI_STAT_LD_LBA_OUT_OF_RANGE = 0x19, 222 MFI_STAT_LD_MAX_CONFIGURED = 0x1a, 223 MFI_STAT_LD_NOT_OPTIMAL = 0x1b, 224 MFI_STAT_LD_RBLD_IN_PROGRESS = 0x1c, 225 MFI_STAT_LD_RECON_IN_PROGRESS = 0x1d, 226 MFI_STAT_LD_WRONG_RAID_LEVEL = 0x1e, 227 MFI_STAT_MAX_SPARES_EXCEEDED = 0x1f, 228 MFI_STAT_MEMORY_NOT_AVAILABLE = 0x20, 229 MFI_STAT_MFC_HW_ERROR = 0x21, 230 MFI_STAT_NO_HW_PRESENT = 0x22, 231 MFI_STAT_NOT_FOUND = 0x23, 232 MFI_STAT_NOT_IN_ENCL = 0x24, 233 MFI_STAT_PD_CLEAR_IN_PROGRESS = 0x25, 234 MFI_STAT_PD_TYPE_WRONG = 0x26, 235 MFI_STAT_PR_DISABLED = 0x27, 236 MFI_STAT_ROW_INDEX_INVALID = 0x28, 237 MFI_STAT_SAS_CONFIG_INVALID_ACTION = 0x29, 238 MFI_STAT_SAS_CONFIG_INVALID_DATA = 0x2a, 239 MFI_STAT_SAS_CONFIG_INVALID_PAGE = 0x2b, 240 MFI_STAT_SAS_CONFIG_INVALID_TYPE = 0x2c, 241 MFI_STAT_SCSI_DONE_WITH_ERROR = 0x2d, 242 MFI_STAT_SCSI_IO_FAILED = 0x2e, 243 MFI_STAT_SCSI_RESERVATION_CONFLICT = 0x2f, 244 MFI_STAT_SHUTDOWN_FAILED = 0x30, 245 MFI_STAT_TIME_NOT_SET = 0x31, 246 MFI_STAT_WRONG_STATE = 0x32, 247 MFI_STAT_INVALID_STATUS = 0xFF 248 }; 249 250 enum MR_EVT_CLASS { 251 MR_EVT_CLASS_DEBUG = -2, 252 MR_EVT_CLASS_PROGRESS = -1, 253 MR_EVT_CLASS_INFO = 0, 254 MR_EVT_CLASS_WARNING = 1, 255 MR_EVT_CLASS_CRITICAL = 2, 256 MR_EVT_CLASS_FATAL = 3, 257 MR_EVT_CLASS_DEAD = 4 258 }; 259 260 enum MR_EVT_LOCALE { 261 MR_EVT_LOCALE_LD = 0x0001, 262 MR_EVT_LOCALE_PD = 0x0002, 263 MR_EVT_LOCALE_ENCL = 0x0004, 264 MR_EVT_LOCALE_BBU = 0x0008, 265 MR_EVT_LOCALE_SAS = 0x0010, 266 MR_EVT_LOCALE_CTRL = 0x0020, 267 MR_EVT_LOCALE_CONFIG = 0x0040, 268 MR_EVT_LOCALE_CLUSTER = 0x0080, 269 MR_EVT_LOCALE_ALL = 0xffff 270 }; 271 272 enum MR_EVT_ARGS { 273 MR_EVT_ARGS_NONE, 274 MR_EVT_ARGS_CDB_SENSE, 275 MR_EVT_ARGS_LD, 276 MR_EVT_ARGS_LD_COUNT, 277 MR_EVT_ARGS_LD_LBA, 278 MR_EVT_ARGS_LD_OWNER, 279 MR_EVT_ARGS_LD_LBA_PD_LBA, 280 MR_EVT_ARGS_LD_PROG, 281 MR_EVT_ARGS_LD_STATE, 282 MR_EVT_ARGS_LD_STRIP, 283 MR_EVT_ARGS_PD, 284 MR_EVT_ARGS_PD_ERR, 285 MR_EVT_ARGS_PD_LBA, 286 MR_EVT_ARGS_PD_LBA_LD, 287 MR_EVT_ARGS_PD_PROG, 288 MR_EVT_ARGS_PD_STATE, 289 MR_EVT_ARGS_PCI, 290 MR_EVT_ARGS_RATE, 291 MR_EVT_ARGS_STR, 292 MR_EVT_ARGS_TIME, 293 MR_EVT_ARGS_ECC 294 }; 295 296 /* 297 * SAS controller properties 298 */ 299 struct megasas_ctrl_prop { 300 uint16_t seq_num; 301 uint16_t pred_fail_poll_interval; 302 uint16_t intr_throttle_count; 303 uint16_t intr_throttle_timeouts; 304 305 uint8_t rebuild_rate; 306 uint8_t patrol_read_rate; 307 uint8_t bgi_rate; 308 uint8_t cc_rate; 309 uint8_t recon_rate; 310 311 uint8_t cache_flush_interval; 312 313 uint8_t spinup_drv_count; 314 uint8_t spinup_delay; 315 316 uint8_t cluster_enable; 317 uint8_t coercion_mode; 318 uint8_t disk_write_cache_disable; 319 uint8_t alarm_enable; 320 321 uint8_t reserved[44]; 322 }; 323 324 /* 325 * SAS controller information 326 */ 327 struct megasas_ctrl_info { 328 /* PCI device information */ 329 struct { 330 uint16_t vendor_id; 331 uint16_t device_id; 332 uint16_t sub_vendor_id; 333 uint16_t sub_device_id; 334 uint8_t reserved[24]; 335 } pci; 336 337 /* Host interface information */ 338 struct { 339 uint8_t PCIX : 1; 340 uint8_t PCIE : 1; 341 uint8_t iSCSI : 1; 342 uint8_t SAS_3G : 1; 343 uint8_t reserved_0 : 4; 344 uint8_t reserved_1[6]; 345 uint8_t port_count; 346 uint64_t port_addr[8]; 347 } host_interface; 348 349 /* Device (backend) interface information */ 350 struct { 351 uint8_t SPI : 1; 352 uint8_t SAS_3G : 1; 353 uint8_t SATA_1_5G : 1; 354 uint8_t SATA_3G : 1; 355 uint8_t reserved_0 : 4; 356 uint8_t reserved_1[6]; 357 uint8_t port_count; 358 uint64_t port_addr[8]; 359 } device_interface; 360 361 /* List of components residing in flash. All str are null terminated */ 362 uint32_t image_check_word; 363 uint32_t image_component_count; 364 365 struct { 366 char name[8]; 367 char version[32]; 368 char build_date[16]; 369 char built_time[16]; 370 } image_component[8]; 371 372 /* 373 * List of flash components that have been flashed on the card, but 374 * are not in use, pending reset of the adapter. This list will be 375 * empty if a flash operation has not occurred. All stings are null 376 * terminated 377 */ 378 uint32_t pending_image_component_count; 379 380 struct { 381 char name[8]; 382 char version[32]; 383 char build_date[16]; 384 char build_time[16]; 385 } pending_image_component[8]; 386 387 uint8_t max_arms; 388 uint8_t max_spans; 389 uint8_t max_arrays; 390 uint8_t max_lds; 391 392 char product_name[80]; 393 char serial_no[32]; 394 395 /* 396 * Other physical/controller/operation information. Indicates the 397 * presence of the hardware 398 */ 399 struct { 400 uint32_t bbu : 1; 401 uint32_t alarm : 1; 402 uint32_t nvram : 1; 403 uint32_t uart : 1; 404 uint32_t reserved : 28; 405 } hw_present; 406 407 uint32_t current_fw_time; 408 409 /* Maximum data transfer sizes */ 410 uint16_t max_concurrent_cmds; 411 uint16_t max_sge_count; 412 uint32_t max_request_size; 413 414 /* Logical and physical device counts */ 415 uint16_t ld_present_count; 416 uint16_t ld_degraded_count; 417 uint16_t ld_offline_count; 418 419 uint16_t pd_present_count; 420 uint16_t pd_disk_present_count; 421 uint16_t pd_disk_pred_failure_count; 422 uint16_t pd_disk_failed_count; 423 424 /* Memory size information */ 425 uint16_t nvram_size; 426 uint16_t memory_size; 427 uint16_t flash_size; 428 429 /* Error counters */ 430 uint16_t mem_correctable_error_count; 431 uint16_t mem_uncorrectable_error_count; 432 433 /* Cluster information */ 434 uint8_t cluster_permitted; 435 uint8_t cluster_active; 436 uint8_t reserved_1[2]; 437 438 /* Controller capabilities structures */ 439 struct { 440 uint32_t raid_level_0 : 1; 441 uint32_t raid_level_1 : 1; 442 uint32_t raid_level_5 : 1; 443 uint32_t raid_level_1E : 1; 444 uint32_t reserved : 28; 445 } raid_levels; 446 447 struct { 448 uint32_t rbld_rate : 1; 449 uint32_t cc_rate : 1; 450 uint32_t bgi_rate : 1; 451 uint32_t recon_rate : 1; 452 uint32_t patrol_rate : 1; 453 uint32_t alarm_control : 1; 454 uint32_t cluster_supported : 1; 455 uint32_t bbu : 1; 456 uint32_t spanning_allowed : 1; 457 uint32_t dedicated_hotspares : 1; 458 uint32_t revertible_hotspares : 1; 459 uint32_t foreign_config_import : 1; 460 uint32_t self_diagnostic : 1; 461 uint32_t reserved : 19; 462 } adapter_operations; 463 464 struct { 465 uint32_t read_policy : 1; 466 uint32_t write_policy : 1; 467 uint32_t io_policy : 1; 468 uint32_t access_policy : 1; 469 uint32_t reserved : 28; 470 } ld_operations; 471 472 struct { 473 uint8_t min; 474 uint8_t max; 475 uint8_t reserved[2]; 476 } stripe_size_operations; 477 478 struct { 479 uint32_t force_online : 1; 480 uint32_t force_offline : 1; 481 uint32_t force_rebuild : 1; 482 uint32_t reserved : 29; 483 } pd_operations; 484 485 struct { 486 uint32_t ctrl_supports_sas : 1; 487 uint32_t ctrl_supports_sata : 1; 488 uint32_t allow_mix_in_encl : 1; 489 uint32_t allow_mix_in_ld : 1; 490 uint32_t allow_sata_in_cluster : 1; 491 uint32_t reserved : 27; 492 } pd_mix_support; 493 494 /* Include the controller properties (changeable items) */ 495 uint8_t reserved_2[12]; 496 struct megasas_ctrl_prop properties; 497 498 uint8_t pad[0x800 - 0x640]; 499 }; 500 501 /* 502 * =============================== 503 * MegaRAID SAS driver definitions 504 * =============================== 505 */ 506 #define MEGADRV_MAX_NUM_CMD 1024 507 508 #define MEGADRV_MAX_PD_CHANNELS 2 509 #define MEGADRV_MAX_LD_CHANNELS 2 510 #define MEGADRV_MAX_CHANNELS (MEGADRV_MAX_PD_CHANNELS + \ 511 MEGADRV_MAX_LD_CHANNELS) 512 #define MEGADRV_MAX_DEV_PER_CHANNEL 128 513 #define MEGADRV_DEFAULT_INIT_ID -1 514 #define MEGADRV_MAX_CMD_PER_LUN 1000 515 #define MEGADRV_MAX_LUN 8 516 #define MEGADRV_MAX_LD 64 517 518 #define MEGADRV_RESET_WAIT_TIME 300 519 #define MEGADRV_RESET_NOTICE_INTERVAL 5 520 521 #define MEGASAS_IOCTL_CMD 0 522 523 /* 524 * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit 525 * SGLs based on the size of dma_addr_t 526 */ 527 #define IS_DMA64 (sizeof (dma_addr_t) == 8) 528 529 /* 530 * All MFI register set macros accept megasas_register_set* 531 */ 532 #define WR_IB_MSG_0(v, instance) ddi_put32((instance)->regmap_handle, \ 533 (uint32_t *)((instance)->regmap + 0x10), (v)) 534 535 #define RD_OB_MSG_0(instance) ddi_get32((instance)->regmap_handle, \ 536 (uint32_t *)((instance)->regmap + 0x18)) 537 538 #define WR_IB_DOORBELL(v, instance) ddi_put32((instance)->regmap_handle, \ 539 (uint32_t *)((instance)->regmap + 0x20), (v)) 540 541 #define RD_IB_DOORBELL(instance) ddi_get32((instance)->regmap_handle, \ 542 (uint32_t *)((instance)->regmap + 0x20)) 543 544 #define WR_OB_INTR_STATUS(v, instance) ddi_put32((instance)->regmap_handle, \ 545 (uint32_t *)((instance)->regmap + 0x30), (v)) 546 547 #define RD_OB_INTR_STATUS(instance) ddi_get32((instance)->regmap_handle, \ 548 (uint32_t *)((instance)->regmap + 0x30)) 549 550 #define WR_OB_INTR_MASK(v, instance) ddi_put32((instance)->regmap_handle, \ 551 (uint32_t *)((instance)->regmap + 0x34), (v)) 552 553 #define RD_OB_INTR_MASK(instance) ddi_get32((instance)->regmap_handle, \ 554 (uint32_t *)((instance)->regmap + 0x34)) 555 556 #define WR_IB_QPORT(v, instance) ddi_put32((instance)->regmap_handle, \ 557 (uint32_t *)((instance)->regmap + 0x40), (v)) 558 559 #define WR_OB_DOORBELL_CLEAR(v, instance) ddi_put32((instance)->regmap_handle, \ 560 (uint32_t *)((instance)->regmap + 0xA0), (v)) 561 562 #define RD_OB_SCRATCH_PAD_0(instance) ddi_get32((instance)->regmap_handle, \ 563 (uint32_t *)((instance)->regmap + 0xB0)) 564 565 /* 566 * When FW is in MFI_STATE_READY or MFI_STATE_OPERATIONAL, the state data 567 * of Outbound Msg Reg 0 indicates max concurrent cmds supported, max SGEs 568 * supported per cmd and if 64-bit MFAs (M64) is enabled or disabled. 569 */ 570 #define MFI_OB_INTR_STATUS_MASK 0x00000002 571 572 /* 573 * This MFI_REPLY_1078_MESSAGE_INTR flag is used also 574 * in enable_intr_pcc also. Hence bit 2, i.e. 0x4 has 575 * been set in this flag along with bit 31. 576 */ 577 #define MFI_REPLY_1078_MESSAGE_INTR 0x80000004 578 579 #define MFI_POLL_TIMEOUT_SECS 60 580 581 #define MFI_ENABLE_INTR(instance) ddi_put32((instance)->regmap_handle, \ 582 (uint32_t *)((instance)->regmap + 0x34), 1) 583 #define MFI_DISABLE_INTR(instance) \ 584 { \ 585 uint32_t disable = 1; \ 586 uint32_t mask = ddi_get32((instance)->regmap_handle, \ 587 (uint32_t *)((instance)->regmap + 0x34)); \ 588 mask &= ~disable; \ 589 ddi_put32((instance)->regmap_handle, \ 590 (uint32_t *)((instance)->regmap + 0x34), mask); \ 591 } 592 593 594 struct megasas_register_set { 595 uint32_t reserved_0[4]; /* 0000h */ 596 597 uint32_t inbound_msg_0; /* 0010h */ 598 uint32_t inbound_msg_1; /* 0014h */ 599 uint32_t outbound_msg_0; /* 0018h */ 600 uint32_t outbound_msg_1; /* 001Ch */ 601 602 uint32_t inbound_doorbell; /* 0020h */ 603 uint32_t inbound_intr_status; /* 0024h */ 604 uint32_t inbound_intr_mask; /* 0028h */ 605 606 uint32_t outbound_doorbell; /* 002Ch */ 607 uint32_t outbound_intr_status; /* 0030h */ 608 uint32_t outbound_intr_mask; /* 0034h */ 609 610 uint32_t reserved_1[2]; /* 0038h */ 611 612 uint32_t inbound_queue_port; /* 0040h */ 613 uint32_t outbound_queue_port; /* 0044h */ 614 615 uint32_t reserved_2[22]; /* 0048h */ 616 617 uint32_t outbound_doorbell_clear; /* 00A0h */ 618 619 uint32_t reserved_3[3]; /* 00A4h */ 620 621 uint32_t outbound_scratch_pad; /* 00B0h */ 622 623 uint32_t reserved_4[3]; /* 00B4h */ 624 625 uint32_t inbound_low_queue_port; /* 00C0h */ 626 627 uint32_t inbound_high_queue_port; /* 00C4h */ 628 629 uint32_t reserved_5; /* 00C8h */ 630 uint32_t index_registers[820]; /* 00CCh */ 631 }; 632 633 struct megasas_sge32 { 634 uint32_t phys_addr; 635 uint32_t length; 636 }; 637 638 struct megasas_sge64 { 639 uint64_t phys_addr; 640 uint32_t length; 641 }; 642 643 union megasas_sgl { 644 struct megasas_sge32 sge32[1]; 645 struct megasas_sge64 sge64[1]; 646 }; 647 648 struct megasas_header { 649 uint8_t cmd; /* 00h */ 650 uint8_t sense_len; /* 01h */ 651 uint8_t cmd_status; /* 02h */ 652 uint8_t scsi_status; /* 03h */ 653 654 uint8_t target_id; /* 04h */ 655 uint8_t lun; /* 05h */ 656 uint8_t cdb_len; /* 06h */ 657 uint8_t sge_count; /* 07h */ 658 659 uint32_t context; /* 08h */ 660 uint32_t pad_0; /* 0Ch */ 661 662 uint16_t flags; /* 10h */ 663 uint16_t timeout; /* 12h */ 664 uint32_t data_xferlen; /* 14h */ 665 }; 666 667 union megasas_sgl_frame { 668 struct megasas_sge32 sge32[8]; 669 struct megasas_sge64 sge64[5]; 670 }; 671 672 struct megasas_init_frame { 673 uint8_t cmd; /* 00h */ 674 uint8_t reserved_0; /* 01h */ 675 uint8_t cmd_status; /* 02h */ 676 677 uint8_t reserved_1; /* 03h */ 678 uint32_t reserved_2; /* 04h */ 679 680 uint32_t context; /* 08h */ 681 uint32_t pad_0; /* 0Ch */ 682 683 uint16_t flags; /* 10h */ 684 uint16_t reserved_3; /* 12h */ 685 uint32_t data_xfer_len; /* 14h */ 686 687 uint32_t queue_info_new_phys_addr_lo; /* 18h */ 688 uint32_t queue_info_new_phys_addr_hi; /* 1Ch */ 689 uint32_t queue_info_old_phys_addr_lo; /* 20h */ 690 uint32_t queue_info_old_phys_addr_hi; /* 24h */ 691 692 uint32_t reserved_4[6]; /* 28h */ 693 }; 694 695 struct megasas_init_queue_info { 696 uint32_t init_flags; /* 00h */ 697 uint32_t reply_queue_entries; /* 04h */ 698 699 uint32_t reply_queue_start_phys_addr_lo; /* 08h */ 700 uint32_t reply_queue_start_phys_addr_hi; /* 0Ch */ 701 uint32_t producer_index_phys_addr_lo; /* 10h */ 702 uint32_t producer_index_phys_addr_hi; /* 14h */ 703 uint32_t consumer_index_phys_addr_lo; /* 18h */ 704 uint32_t consumer_index_phys_addr_hi; /* 1Ch */ 705 }; 706 707 struct megasas_io_frame { 708 uint8_t cmd; /* 00h */ 709 uint8_t sense_len; /* 01h */ 710 uint8_t cmd_status; /* 02h */ 711 uint8_t scsi_status; /* 03h */ 712 713 uint8_t target_id; /* 04h */ 714 uint8_t access_byte; /* 05h */ 715 uint8_t reserved_0; /* 06h */ 716 uint8_t sge_count; /* 07h */ 717 718 uint32_t context; /* 08h */ 719 uint32_t pad_0; /* 0Ch */ 720 721 uint16_t flags; /* 10h */ 722 uint16_t timeout; /* 12h */ 723 uint32_t lba_count; /* 14h */ 724 725 uint32_t sense_buf_phys_addr_lo; /* 18h */ 726 uint32_t sense_buf_phys_addr_hi; /* 1Ch */ 727 728 uint32_t start_lba_lo; /* 20h */ 729 uint32_t start_lba_hi; /* 24h */ 730 731 union megasas_sgl sgl; /* 28h */ 732 }; 733 734 struct megasas_pthru_frame { 735 uint8_t cmd; /* 00h */ 736 uint8_t sense_len; /* 01h */ 737 uint8_t cmd_status; /* 02h */ 738 uint8_t scsi_status; /* 03h */ 739 740 uint8_t target_id; /* 04h */ 741 uint8_t lun; /* 05h */ 742 uint8_t cdb_len; /* 06h */ 743 uint8_t sge_count; /* 07h */ 744 745 uint32_t context; /* 08h */ 746 uint32_t pad_0; /* 0Ch */ 747 748 uint16_t flags; /* 10h */ 749 uint16_t timeout; /* 12h */ 750 uint32_t data_xfer_len; /* 14h */ 751 752 uint32_t sense_buf_phys_addr_lo; /* 18h */ 753 uint32_t sense_buf_phys_addr_hi; /* 1Ch */ 754 755 uint8_t cdb[16]; /* 20h */ 756 union megasas_sgl sgl; /* 30h */ 757 }; 758 759 struct megasas_dcmd_frame { 760 uint8_t cmd; /* 00h */ 761 uint8_t reserved_0; /* 01h */ 762 uint8_t cmd_status; /* 02h */ 763 uint8_t reserved_1[4]; /* 03h */ 764 uint8_t sge_count; /* 07h */ 765 766 uint32_t context; /* 08h */ 767 uint32_t pad_0; /* 0Ch */ 768 769 uint16_t flags; /* 10h */ 770 uint16_t timeout; /* 12h */ 771 772 uint32_t data_xfer_len; /* 14h */ 773 uint32_t opcode; /* 18h */ 774 775 /* uint8_t mbox[12]; */ /* 1Ch */ 776 union { /* 1Ch */ 777 uint8_t b[12]; 778 uint16_t s[6]; 779 uint32_t w[3]; 780 } mbox; 781 782 union megasas_sgl sgl; /* 28h */ 783 }; 784 785 struct megasas_abort_frame { 786 uint8_t cmd; /* 00h */ 787 uint8_t reserved_0; /* 01h */ 788 uint8_t cmd_status; /* 02h */ 789 790 uint8_t reserved_1; /* 03h */ 791 uint32_t reserved_2; /* 04h */ 792 793 uint32_t context; /* 08h */ 794 uint32_t pad_0; /* 0Ch */ 795 796 uint16_t flags; /* 10h */ 797 uint16_t reserved_3; /* 12h */ 798 uint32_t reserved_4; /* 14h */ 799 800 uint32_t abort_context; /* 18h */ 801 uint32_t pad_1; /* 1Ch */ 802 803 uint32_t abort_mfi_phys_addr_lo; /* 20h */ 804 uint32_t abort_mfi_phys_addr_hi; /* 24h */ 805 806 uint32_t reserved_5[6]; /* 28h */ 807 }; 808 809 struct megasas_smp_frame { 810 uint8_t cmd; /* 00h */ 811 uint8_t reserved_1; /* 01h */ 812 uint8_t cmd_status; /* 02h */ 813 uint8_t connection_status; /* 03h */ 814 815 uint8_t reserved_2[3]; /* 04h */ 816 uint8_t sge_count; /* 07h */ 817 818 uint32_t context; /* 08h */ 819 uint32_t pad_0; /* 0Ch */ 820 821 uint16_t flags; /* 10h */ 822 uint16_t timeout; /* 12h */ 823 824 uint32_t data_xfer_len; /* 14h */ 825 826 uint64_t sas_addr; /* 20h */ 827 828 union megasas_sgl sgl[2]; /* 28h */ 829 }; 830 831 struct megasas_stp_frame { 832 uint8_t cmd; /* 00h */ 833 uint8_t reserved_1; /* 01h */ 834 uint8_t cmd_status; /* 02h */ 835 uint8_t connection_status; /* 03h */ 836 837 uint8_t target_id; /* 04h */ 838 uint8_t reserved_2[2]; /* 04h */ 839 uint8_t sge_count; /* 07h */ 840 841 uint32_t context; /* 08h */ 842 uint32_t pad_0; /* 0Ch */ 843 844 uint16_t flags; /* 10h */ 845 uint16_t timeout; /* 12h */ 846 847 uint32_t data_xfer_len; /* 14h */ 848 849 uint16_t fis[10]; /* 28h */ 850 uint32_t stp_flags; /* 3C */ 851 union megasas_sgl sgl; /* 40 */ 852 }; 853 854 union megasas_frame { 855 struct megasas_header hdr; 856 struct megasas_init_frame init; 857 struct megasas_io_frame io; 858 struct megasas_pthru_frame pthru; 859 struct megasas_dcmd_frame dcmd; 860 struct megasas_abort_frame abort; 861 struct megasas_smp_frame smp; 862 struct megasas_stp_frame stp; 863 864 uint8_t raw_bytes[64]; 865 }; 866 867 union megasas_evt_class_locale { 868 struct { 869 uint16_t locale; 870 uint8_t reserved; 871 int8_t class; 872 } members; 873 874 uint32_t word; 875 }; 876 877 struct megasas_evt_log_info { 878 uint32_t newest_seq_num; 879 uint32_t oldest_seq_num; 880 uint32_t clear_seq_num; 881 uint32_t shutdown_seq_num; 882 uint32_t boot_seq_num; 883 }; 884 885 struct megasas_progress { 886 uint16_t progress; 887 uint16_t elapsed_seconds; 888 }; 889 890 struct megasas_evtarg_ld { 891 uint16_t target_id; 892 uint8_t ld_index; 893 uint8_t reserved; 894 }; 895 896 struct megasas_evtarg_pd { 897 uint16_t device_id; 898 uint8_t encl_index; 899 uint8_t slot_number; 900 }; 901 902 struct megasas_evt_detail { 903 uint32_t seq_num; 904 uint32_t time_stamp; 905 uint32_t code; 906 union megasas_evt_class_locale cl; 907 uint8_t arg_type; 908 uint8_t reserved1[15]; 909 910 union { 911 struct { 912 struct megasas_evtarg_pd pd; 913 uint8_t cdb_length; 914 uint8_t sense_length; 915 uint8_t reserved[2]; 916 uint8_t cdb[16]; 917 uint8_t sense[64]; 918 } cdbSense; 919 920 struct megasas_evtarg_ld ld; 921 922 struct { 923 struct megasas_evtarg_ld ld; 924 uint64_t count; 925 } ld_count; 926 927 struct { 928 uint64_t lba; 929 struct megasas_evtarg_ld ld; 930 } ld_lba; 931 932 struct { 933 struct megasas_evtarg_ld ld; 934 uint32_t prevOwner; 935 uint32_t newOwner; 936 } ld_owner; 937 938 struct { 939 uint64_t ld_lba; 940 uint64_t pd_lba; 941 struct megasas_evtarg_ld ld; 942 struct megasas_evtarg_pd pd; 943 } ld_lba_pd_lba; 944 945 struct { 946 struct megasas_evtarg_ld ld; 947 struct megasas_progress prog; 948 } ld_prog; 949 950 struct { 951 struct megasas_evtarg_ld ld; 952 uint32_t prev_state; 953 uint32_t new_state; 954 } ld_state; 955 956 struct { 957 uint64_t strip; 958 struct megasas_evtarg_ld ld; 959 } ld_strip; 960 961 struct megasas_evtarg_pd pd; 962 963 struct { 964 struct megasas_evtarg_pd pd; 965 uint32_t err; 966 } pd_err; 967 968 struct { 969 uint64_t lba; 970 struct megasas_evtarg_pd pd; 971 } pd_lba; 972 973 struct { 974 uint64_t lba; 975 struct megasas_evtarg_pd pd; 976 struct megasas_evtarg_ld ld; 977 } pd_lba_ld; 978 979 struct { 980 struct megasas_evtarg_pd pd; 981 struct megasas_progress prog; 982 } pd_prog; 983 984 struct { 985 struct megasas_evtarg_pd pd; 986 uint32_t prevState; 987 uint32_t newState; 988 } pd_state; 989 990 struct { 991 uint16_t vendorId; 992 uint16_t deviceId; 993 uint16_t subVendorId; 994 uint16_t subDeviceId; 995 } pci; 996 997 uint32_t rate; 998 char str[96]; 999 1000 struct { 1001 uint32_t rtc; 1002 uint32_t elapsedSeconds; 1003 } time; 1004 1005 struct { 1006 uint32_t ecar; 1007 uint32_t elog; 1008 char str[64]; 1009 } ecc; 1010 1011 uint8_t b[96]; 1012 uint16_t s[48]; 1013 uint32_t w[24]; 1014 uint64_t d[12]; 1015 } args; 1016 1017 char description[128]; 1018 1019 }; 1020 1021 /* only 63 are usable by the application */ 1022 #define MAX_LOGICAL_DRIVES 64 1023 /* only 255 physical devices may be used */ 1024 #define MAX_PHYSICAL_DEVICES 256 1025 #define MAX_PD_PER_ENCLOSURE 64 1026 /* maximum disks per array */ 1027 #define MAX_ROW_SIZE 32 1028 /* maximum spans per logical drive */ 1029 #define MAX_SPAN_DEPTH 8 1030 /* maximum number of arrays a hot spare may be dedicated to */ 1031 #define MAX_ARRAYS_DEDICATED 16 1032 /* maximum number of arrays which may exist */ 1033 #define MAX_ARRAYS 128 1034 /* maximum number of foreign configs that may ha managed at once */ 1035 #define MAX_FOREIGN_CONFIGS 8 1036 /* maximum spares (global and dedicated combined) */ 1037 #define MAX_SPARES_FOR_THE_CONTROLLER MAX_PHYSICAL_DEVICES 1038 /* maximum possible Target IDs (i.e. 0 to 63) */ 1039 #define MAX_TARGET_ID 63 1040 /* maximum number of supported enclosures */ 1041 #define MAX_ENCLOSURES 32 1042 /* maximum number of PHYs per controller */ 1043 #define MAX_PHYS_PER_CONTROLLER 16 1044 /* maximum number of LDs per array (due to DDF limitations) */ 1045 #define MAX_LDS_PER_ARRAY 16 1046 1047 /* 1048 * ----------------------------------------------------------------------------- 1049 * ----------------------------------------------------------------------------- 1050 * 1051 * Logical Drive commands 1052 * 1053 * ----------------------------------------------------------------------------- 1054 * ----------------------------------------------------------------------------- 1055 */ 1056 #define MR_DCMD_LD 0x03000000, /* Logical Device (LD) opcodes */ 1057 1058 /* 1059 * Input: dcmd.opcode - MR_DCMD_LD_GET_LIST 1060 * dcmd.mbox - reserved 1061 * dcmd.sge IN - ptr to returned MR_LD_LIST structure 1062 * Desc: Return the logical drive list structure 1063 * Status: No error 1064 */ 1065 1066 /* 1067 * defines the logical drive reference structure 1068 */ 1069 typedef union _MR_LD_REF { /* LD reference structure */ 1070 struct { 1071 uint8_t targetId; /* LD target id (0 to MAX_TARGET_ID) */ 1072 uint8_t reserved; /* reserved to make in line with MR_PD_REF */ 1073 uint16_t seqNum; /* Sequence Number */ 1074 } ld_ref; 1075 uint32_t ref; /* shorthand reference to full 32-bits */ 1076 } MR_LD_REF; /* 4 bytes */ 1077 1078 /* 1079 * defines the logical drive list structure 1080 */ 1081 typedef struct _MR_LD_LIST { 1082 uint32_t ldCount; /* number of LDs */ 1083 uint32_t reserved; /* pad to 8-byte boundary */ 1084 struct { 1085 MR_LD_REF ref; /* LD reference */ 1086 uint8_t state; /* current LD state (MR_LD_STATE) */ 1087 uint8_t reserved[3]; /* pad to 8-byte boundary */ 1088 uint64_t size; /* LD size */ 1089 } ldList[MAX_LOGICAL_DRIVES]; 1090 } MR_LD_LIST; 1091 /* 4 + 4 + (MAX_LOGICAL_DRIVES * 16), for 40LD it is = 648 bytes */ 1092 1093 #define DMA_OBJ_ALLOCATED 1 1094 #define DMA_OBJ_REALLOCATED 2 1095 #define DMA_OBJ_FREED 3 1096 1097 #pragma pack() 1098 1099 /* 1100 * dma_obj_t - Our DMA object 1101 * @param buffer : kernel virtual address 1102 * @param size : size of the data to be allocated 1103 * @param acc_handle : access handle 1104 * @param dma_handle : dma handle 1105 * @param dma_cookie : scatter-gather list 1106 * @param dma_attr : dma attributes for this buffer 1107 * 1108 * Our DMA object. The caller must initialize the size and dma attributes 1109 * (dma_attr) fields before allocating the resources. 1110 */ 1111 typedef struct { 1112 caddr_t buffer; 1113 uint32_t size; 1114 ddi_acc_handle_t acc_handle; 1115 ddi_dma_handle_t dma_handle; 1116 ddi_dma_cookie_t dma_cookie[MEGASAS_MAX_SGE_CNT]; 1117 ddi_dma_attr_t dma_attr; 1118 uint8_t status; 1119 } dma_obj_t; 1120 1121 struct megasas_instance { 1122 uint32_t *producer; 1123 uint32_t *consumer; 1124 1125 uint32_t *reply_queue; 1126 dma_obj_t mfi_internal_dma_obj; 1127 1128 uint8_t init_id; 1129 uint8_t reserved[3]; 1130 1131 uint16_t max_num_sge; 1132 uint16_t max_fw_cmds; 1133 uint32_t max_sectors_per_req; 1134 1135 struct megasas_cmd **cmd_list; 1136 1137 mlist_t cmd_pool_list; 1138 kmutex_t cmd_pool_mtx; 1139 1140 mlist_t cmd_pend_list; 1141 kmutex_t cmd_pend_mtx; 1142 1143 dma_obj_t mfi_evt_detail_obj; 1144 struct megasas_cmd *aen_cmd; 1145 1146 uint32_t aen_seq_num; 1147 uint32_t aen_class_locale_word; 1148 1149 scsi_hba_tran_t *tran; 1150 1151 kcondvar_t int_cmd_cv; 1152 kmutex_t int_cmd_mtx; 1153 1154 kcondvar_t aen_cmd_cv; 1155 kmutex_t aen_cmd_mtx; 1156 1157 kcondvar_t abort_cmd_cv; 1158 kmutex_t abort_cmd_mtx; 1159 1160 dev_info_t *dip; 1161 ddi_acc_handle_t pci_handle; 1162 1163 timeout_id_t timeout_id; 1164 uint32_t unique_id; 1165 uint16_t fw_outstanding; 1166 caddr_t regmap; 1167 ddi_acc_handle_t regmap_handle; 1168 uint8_t isr_level; 1169 ddi_iblock_cookie_t iblock_cookie; 1170 ddi_iblock_cookie_t soft_iblock_cookie; 1171 ddi_softintr_t soft_intr_id; 1172 uint8_t softint_running; 1173 kmutex_t completed_pool_mtx; 1174 mlist_t completed_pool_list; 1175 1176 caddr_t internal_buf; 1177 uint32_t internal_buf_dmac_add; 1178 uint32_t internal_buf_size; 1179 1180 uint16_t vendor_id; 1181 uint16_t device_id; 1182 uint16_t subsysvid; 1183 uint16_t subsysid; 1184 int baseaddress; 1185 char iocnode[16]; 1186 1187 struct megasas_func_ptr *func_ptr; 1188 }; 1189 1190 struct megasas_func_ptr { 1191 int (*read_fw_status_reg)(struct megasas_instance *); 1192 void (*issue_cmd)(struct megasas_cmd *, struct megasas_instance *); 1193 int (*issue_cmd_in_sync_mode)(struct megasas_instance *, 1194 struct megasas_cmd *); 1195 int (*issue_cmd_in_poll_mode)(struct megasas_instance *, 1196 struct megasas_cmd *); 1197 void (*enable_intr)(struct megasas_instance *); 1198 void (*disable_intr)(struct megasas_instance *); 1199 int (*intr_ack)(struct megasas_instance *); 1200 }; 1201 1202 /* 1203 * ### Helper routines ### 1204 */ 1205 1206 /* 1207 * con_log() - console log routine 1208 * @param level : indicates the severity of the message. 1209 * @fparam mt : format string 1210 * 1211 * con_log displays the error messages on the console based on the current 1212 * debug level. Also it attaches the appropriate kernel severity level with 1213 * the message. 1214 * 1215 * 1216 * consolge messages debug levels 1217 */ 1218 #define CL_ANN 0 /* print unconditionally, announcements */ 1219 #define CL_ANN1 1 /* No o/p */ 1220 #define CL_DLEVEL1 2 /* debug level 1, informative */ 1221 #define CL_DLEVEL2 3 /* debug level 2, verbose */ 1222 #define CL_DLEVEL3 4 /* debug level 3, very verbose */ 1223 1224 #ifdef __SUNPRO_C 1225 #define __func__ "" 1226 #endif 1227 1228 #if DEBUG 1229 #define con_log(level, fmt) { if (debug_level_g >= level) cmn_err fmt; } 1230 #else 1231 #define con_log(level, fmt) 1232 #endif /* DEBUG */ 1233 1234 /* byte-ordering macros */ 1235 #ifdef __sparc 1236 #define host_to_le16(s) ((s) & 0xFF) << 8 | ((s) & 0xFF00) >> 8 1237 #else 1238 #define host_to_le16(s) (s) 1239 #endif 1240 1241 #ifdef __sparc 1242 #define host_to_le32(l) (((l) & 0xFF) << 24 | ((l) & 0xFF00) << 8 | \ 1243 ((l) & 0xFF0000) >> 8 | ((l) & 0xFF000000) >> 24) 1244 #else 1245 #define host_to_le32(l) (l) 1246 #endif 1247 1248 #ifdef __sparc 1249 #define host_to_le64(ull) ((host_to_le32(((ull) & 0xFFFFFFFF)) << 32) | \ 1250 (host_to_le32((((ull) & 0xFFFFFFFF00000000) >> 32)))) 1251 #else 1252 #define host_to_le64(ull) (ull) 1253 #endif 1254 1255 /* 1256 * ### SCSA definitions ### 1257 */ 1258 #define PKT2TGT(pkt) ((pkt)->pkt_address.a_target) 1259 #define PKT2LUN(pkt) ((pkt)->pkt_address.a_lun) 1260 #define PKT2TRAN(pkt) ((pkt)->pkt_adress.a_hba_tran) 1261 #define ADDR2TRAN(ap) ((ap)->a_hba_tran) 1262 1263 #define TRAN2MEGA(tran) (struct megasas_instance *)(tran)->tran_hba_private) 1264 #define ADDR2MEGA(ap) (TRAN2MEGA(ADDR2TRAN(ap)) 1265 1266 #define PKT2CMD(pkt) ((struct scsa_cmd *)(pkt)->pkt_ha_private) 1267 #define CMD2PKT(sp) ((sp)->cmd_pkt) 1268 #define PKT2REQ(pkt) (&(PKT2CMD(pkt)->request)) 1269 1270 #define CMD2ADDR(cmd) (&CMD2PKT(cmd)->pkt_address) 1271 #define CMD2TRAN(cmd) (CMD2PKT(cmd)->pkt_address.a_hba_tran) 1272 #define CMD2MEGA(cmd) (TRAN2MEGA(CMD2TRAN(cmd))) 1273 1274 #define CFLAG_DMAVALID 0x0001 /* requires a dma operation */ 1275 #define CFLAG_DMASEND 0x0002 /* Transfer from the device */ 1276 #define CFLAG_CONSISTENT 0x0040 /* consistent data transfer */ 1277 1278 /* 1279 * ### Data structures for ioctl inteface and internal commands ### 1280 */ 1281 1282 /* 1283 * Data direction flags 1284 */ 1285 #define UIOC_RD 0x00001 1286 #define UIOC_WR 0x00002 1287 1288 #define SCP2HOST(scp) (scp)->device->host /* to host */ 1289 #define SCP2HOSTDATA(scp) SCP2HOST(scp)->hostdata /* to soft state */ 1290 #define SCP2CHANNEL(scp) (scp)->device->channel /* to channel */ 1291 #define SCP2TARGET(scp) (scp)->device->id /* to target */ 1292 #define SCP2LUN(scp) (scp)->device->lun /* to LUN */ 1293 1294 #define SCSIHOST2ADAP(host) (((caddr_t *)(host->hostdata))[0]) 1295 #define SCP2ADAPTER(scp) \ 1296 (struct megasas_instance *)SCSIHOST2ADAP(SCP2HOST(scp)) 1297 1298 #define MEGADRV_IS_LOGICAL_SCSA(instance, acmd) \ 1299 (acmd->device_id < MEGADRV_MAX_LD) ? 1 : 0 1300 #define MEGADRV_IS_LOGICAL(ap) \ 1301 (ap->a_target < MEGADRV_MAX_LD) ? 1 : 0 1302 #define MAP_DEVICE_ID(instance, ap) \ 1303 (ap->a_target % MEGADRV_MAX_LD) 1304 /* 1305 * #define MAP_DEVICE_ID(instance,ap) \ 1306 * (ap->a_target) 1307 */ 1308 1309 #define HIGH_LEVEL_INTR 1 1310 #define NORMAL_LEVEL_INTR 0 1311 1312 /* 1313 * scsa_cmd - Per-command mega private data 1314 * @param cmd_dmahandle : dma handle 1315 * @param cmd_dmacookies : current dma cookies 1316 * @param cmd_pkt : scsi_pkt reference 1317 * @param cmd_dmacount : dma count 1318 * @param cmd_cookie : next cookie 1319 * @param cmd_ncookies : cookies per window 1320 * @param cmd_cookiecnt : cookies per sub-win 1321 * @param cmd_nwin : number of dma windows 1322 * @param cmd_curwin : current dma window 1323 * @param cmd_dma_offset : current window offset 1324 * @param cmd_dma_len : current window length 1325 * @param cmd_flags : private flags 1326 * @param cmd_cdblen : length of cdb 1327 * @param cmd_scblen : length of scb 1328 * @param cmd_buf : command buffer 1329 * @param channel : channel for scsi sub-system 1330 * @param target : target for scsi sub-system 1331 * @param lun : LUN for scsi sub-system 1332 * 1333 * - Allocated at same time as scsi_pkt by scsi_hba_pkt_alloc(9E) 1334 * - Pointed to by pkt_ha_private field in scsi_pkt 1335 */ 1336 struct scsa_cmd { 1337 ddi_dma_handle_t cmd_dmahandle; 1338 ddi_dma_cookie_t cmd_dmacookies[MEGASAS_MAX_SGE_CNT]; 1339 struct scsi_pkt *cmd_pkt; 1340 ulong_t cmd_dmacount; 1341 uint_t cmd_cookie; 1342 uint_t cmd_ncookies; 1343 uint_t cmd_cookiecnt; 1344 uint_t cmd_nwin; 1345 uint_t cmd_curwin; 1346 off_t cmd_dma_offset; 1347 ulong_t cmd_dma_len; 1348 ulong_t cmd_flags; 1349 uint_t cmd_cdblen; 1350 uint_t cmd_scblen; 1351 struct buf *cmd_buf; 1352 ushort_t device_id; 1353 uchar_t islogical; 1354 uchar_t lun; 1355 }; 1356 1357 1358 struct megasas_cmd { 1359 union megasas_frame *frame; 1360 uint32_t frame_phys_addr; 1361 uint8_t *sense; 1362 uint32_t sense_phys_addr; 1363 dma_obj_t frame_dma_obj; 1364 uint8_t frame_dma_obj_status; 1365 1366 uint32_t index; 1367 uint8_t sync_cmd; 1368 uint8_t cmd_status; 1369 uint16_t abort_aen; 1370 mlist_t list; 1371 uint32_t frame_count; 1372 struct scsa_cmd *cmd; 1373 struct scsi_pkt *pkt; 1374 }; 1375 1376 #define MAX_MGMT_ADAPTERS 1024 1377 #define IOC_SIGNATURE "MEGA-SAS" 1378 1379 #define IOC_CMD_FIRMWARE 0x0 1380 #define MR_DRIVER_IOCTL_COMMON 0xF0010000 1381 #define MR_DRIVER_IOCTL_DRIVER_VERSION 0xF0010100 1382 #define MR_DRIVER_IOCTL_PCI_INFORMATION 0xF0010200 1383 #define MR_DRIVER_IOCTL_MEGARAID_STATISTICS 0xF0010300 1384 1385 1386 #define MR_MAX_SENSE_LENGTH 32 1387 1388 struct megasas_mgmt_info { 1389 1390 uint16_t count; 1391 struct megasas_instance *instance[MAX_MGMT_ADAPTERS]; 1392 uint16_t map[MAX_MGMT_ADAPTERS]; 1393 int max_index; 1394 }; 1395 1396 #pragma pack(1) 1397 1398 struct megasas_drv_ver { 1399 uint8_t signature[12]; 1400 uint8_t os_name[16]; 1401 uint8_t os_ver[12]; 1402 uint8_t drv_name[20]; 1403 uint8_t drv_ver[32]; 1404 uint8_t drv_rel_date[20]; 1405 }; 1406 1407 #define PCI_TYPE0_ADDRESSES 6 1408 #define PCI_TYPE1_ADDRESSES 2 1409 #define PCI_TYPE2_ADDRESSES 5 1410 1411 struct megasas_pci_common_header { 1412 uint16_t vendorID; /* (ro) */ 1413 uint16_t deviceID; /* (ro) */ 1414 uint16_t command; /* Device control */ 1415 uint16_t status; 1416 uint8_t revisionID; /* (ro) */ 1417 uint8_t progIf; /* (ro) */ 1418 uint8_t subClass; /* (ro) */ 1419 uint8_t baseClass; /* (ro) */ 1420 uint8_t cacheLineSize; /* (ro+) */ 1421 uint8_t latencyTimer; /* (ro+) */ 1422 uint8_t headerType; /* (ro) */ 1423 uint8_t bist; /* Built in self test */ 1424 1425 union { 1426 struct { 1427 uint32_t baseAddresses[PCI_TYPE0_ADDRESSES]; 1428 uint32_t cis; 1429 uint16_t subVendorID; 1430 uint16_t subSystemID; 1431 uint32_t romBaseAddress; 1432 uint8_t capabilitiesPtr; 1433 uint8_t reserved1[3]; 1434 uint32_t reserved2; 1435 uint8_t interruptLine; 1436 uint8_t interruptPin; /* (ro) */ 1437 uint8_t minimumGrant; /* (ro) */ 1438 uint8_t maximumLatency; /* (ro) */ 1439 } type_0; 1440 1441 struct { 1442 uint32_t baseAddresses[PCI_TYPE1_ADDRESSES]; 1443 uint8_t primaryBus; 1444 uint8_t secondaryBus; 1445 uint8_t subordinateBus; 1446 uint8_t secondaryLatency; 1447 uint8_t ioBase; 1448 uint8_t ioLimit; 1449 uint16_t secondaryStatus; 1450 uint16_t memoryBase; 1451 uint16_t memoryLimit; 1452 uint16_t prefetchBase; 1453 uint16_t prefetchLimit; 1454 uint32_t prefetchBaseUpper32; 1455 uint32_t prefetchLimitUpper32; 1456 uint16_t ioBaseUpper16; 1457 uint16_t ioLimitUpper16; 1458 uint8_t capabilitiesPtr; 1459 uint8_t reserved1[3]; 1460 uint32_t romBaseAddress; 1461 uint8_t interruptLine; 1462 uint8_t interruptPin; 1463 uint16_t bridgeControl; 1464 } type_1; 1465 1466 struct { 1467 uint32_t socketRegistersBaseAddress; 1468 uint8_t capabilitiesPtr; 1469 uint8_t reserved; 1470 uint16_t secondaryStatus; 1471 uint8_t primaryBus; 1472 uint8_t secondaryBus; 1473 uint8_t subordinateBus; 1474 uint8_t secondaryLatency; 1475 struct { 1476 uint32_t base; 1477 uint32_t limit; 1478 } range[PCI_TYPE2_ADDRESSES-1]; 1479 uint8_t interruptLine; 1480 uint8_t interruptPin; 1481 uint16_t bridgeControl; 1482 } type_2; 1483 } header; 1484 }; 1485 1486 struct megasas_pci_link_capability { 1487 union { 1488 struct { 1489 uint32_t linkSpeed :4; 1490 uint32_t linkWidth :6; 1491 uint32_t aspmSupport :2; 1492 uint32_t losExitLatency :3; 1493 uint32_t l1ExitLatency :3; 1494 uint32_t rsvdp :6; 1495 uint32_t portNumber :8; 1496 } bits; 1497 1498 uint32_t asUlong; 1499 } cap; 1500 1501 }; 1502 1503 struct megasas_pci_link_status_capability { 1504 union { 1505 struct { 1506 uint16_t linkSpeed :4; 1507 uint16_t negotiatedLinkWidth :6; 1508 uint16_t linkTrainingError :1; 1509 uint16_t linkTraning :1; 1510 uint16_t slotClockConfig :1; 1511 uint16_t rsvdZ :3; 1512 } bits; 1513 1514 uint16_t asUshort; 1515 } stat_cap; 1516 1517 uint16_t reserved; 1518 1519 }; 1520 1521 struct megasas_pci_capabilities { 1522 struct megasas_pci_link_capability linkCapability; 1523 struct megasas_pci_link_status_capability linkStatusCapability; 1524 }; 1525 1526 struct megasas_pci_information 1527 { 1528 uint32_t busNumber; 1529 uint8_t deviceNumber; 1530 uint8_t functionNumber; 1531 uint8_t interruptVector; 1532 uint8_t reserved; 1533 struct megasas_pci_common_header pciHeaderInfo; 1534 struct megasas_pci_capabilities capability; 1535 uint8_t reserved2[32]; 1536 }; 1537 1538 struct megasas_ioctl { 1539 uint16_t version; 1540 uint16_t controller_id; 1541 uint8_t signature[8]; 1542 uint32_t reserved_1; 1543 uint32_t control_code; 1544 uint32_t reserved_2[2]; 1545 uint8_t frame[64]; 1546 union megasas_sgl_frame sgl_frame; 1547 uint8_t sense_buff[MR_MAX_SENSE_LENGTH]; 1548 uint8_t data[1]; 1549 }; 1550 1551 struct megasas_aen { 1552 uint16_t host_no; 1553 uint16_t cmd_status; 1554 uint32_t seq_num; 1555 uint32_t class_locale_word; 1556 }; 1557 1558 #pragma pack() 1559 1560 #ifndef DDI_VENDOR_LSI 1561 #define DDI_VENDOR_LSI "LSI" 1562 #endif /* DDI_VENDOR_LSI */ 1563 1564 static int megasas_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); 1565 static int megasas_attach(dev_info_t *, ddi_attach_cmd_t); 1566 static int megasas_reset(dev_info_t *, ddi_reset_cmd_t); 1567 static int megasas_detach(dev_info_t *, ddi_detach_cmd_t); 1568 static int megasas_open(dev_t *, int, int, cred_t *); 1569 static int megasas_close(dev_t, int, int, cred_t *); 1570 static int megasas_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1571 1572 static int megasas_tran_tgt_init(dev_info_t *, dev_info_t *, 1573 scsi_hba_tran_t *, struct scsi_device *); 1574 #if defined(USELESS) && !defined(lint) 1575 static int megasas_tran_tgt_probe(struct scsi_device *, int); 1576 #endif 1577 static struct scsi_pkt *megasas_tran_init_pkt(struct scsi_address *, register 1578 struct scsi_pkt *, struct buf *, int, int, int, int, 1579 int (*)(), caddr_t); 1580 static int megasas_tran_start(struct scsi_address *, 1581 register struct scsi_pkt *); 1582 static int megasas_tran_abort(struct scsi_address *, struct scsi_pkt *); 1583 static int megasas_tran_reset(struct scsi_address *, int); 1584 static int megasas_tran_bus_reset(dev_info_t *, int); 1585 static int megasas_tran_getcap(struct scsi_address *, char *, int); 1586 static int megasas_tran_setcap(struct scsi_address *, char *, int, int); 1587 static void megasas_tran_destroy_pkt(struct scsi_address *, 1588 struct scsi_pkt *); 1589 static void megasas_tran_dmafree(struct scsi_address *, struct scsi_pkt *); 1590 static void megasas_tran_sync_pkt(struct scsi_address *, struct scsi_pkt *); 1591 static int megasas_tran_quiesce(dev_info_t *dip); 1592 static int megasas_tran_unquiesce(dev_info_t *dip); 1593 static uint_t megasas_isr(caddr_t); 1594 static uint_t megasas_softintr(caddr_t); 1595 1596 static int init_mfi(struct megasas_instance *); 1597 static void mega_free_dma_obj(dma_obj_t); 1598 static int mega_alloc_dma_obj(struct megasas_instance *, dma_obj_t *); 1599 static struct megasas_cmd *get_mfi_pkt(struct megasas_instance *); 1600 static void return_mfi_pkt(struct megasas_instance *, 1601 struct megasas_cmd *); 1602 #ifndef lint 1603 static void push_pend_queue(struct megasas_instance *instance, 1604 struct megasas_cmd *cmd); 1605 static struct megasas_cmd *pull_pend_queue(struct megasas_instance *instance); 1606 #endif 1607 static void free_space_for_mfi(struct megasas_instance *); 1608 static void free_additional_dma_buffer(struct megasas_instance *); 1609 static int alloc_additional_dma_buffer(struct megasas_instance *); 1610 static int read_fw_status_reg_xscale(struct megasas_instance *); 1611 static int read_fw_status_reg_ppc(struct megasas_instance *); 1612 static void issue_cmd_xscale(struct megasas_cmd *, 1613 struct megasas_instance *); 1614 static void issue_cmd_ppc(struct megasas_cmd *, struct megasas_instance *); 1615 static int issue_cmd_in_poll_mode_xscale(struct megasas_instance *, 1616 struct megasas_cmd *); 1617 static int issue_cmd_in_poll_mode_ppc(struct megasas_instance *, 1618 struct megasas_cmd *); 1619 static int issue_cmd_in_sync_mode_xscale(struct megasas_instance *, 1620 struct megasas_cmd *); 1621 static int issue_cmd_in_sync_mode_ppc(struct megasas_instance *, 1622 struct megasas_cmd *); 1623 static void enable_intr_xscale(struct megasas_instance *); 1624 static void enable_intr_ppc(struct megasas_instance *); 1625 static void disable_intr_xscale(struct megasas_instance *); 1626 static void disable_intr_ppc(struct megasas_instance *); 1627 static int intr_ack_xscale(struct megasas_instance *); 1628 static int intr_ack_ppc(struct megasas_instance *); 1629 static int mfi_state_transition_to_ready(struct megasas_instance *); 1630 static void destroy_mfi_frame_pool(struct megasas_instance *); 1631 static int create_mfi_frame_pool(struct megasas_instance *); 1632 static int megasas_dma_alloc(struct megasas_instance *, struct scsi_pkt *, 1633 struct buf *, int, int (*)()); 1634 static int megasas_dma_move(struct megasas_instance *, 1635 struct scsi_pkt *, struct buf *); 1636 static void flush_cache(struct megasas_instance *instance); 1637 static void display_scsi_inquiry(caddr_t); 1638 static int start_mfi_aen(struct megasas_instance *instance); 1639 static int handle_drv_ioctl(struct megasas_instance *instance, 1640 struct megasas_ioctl *ioctl, int mode); 1641 static int handle_mfi_ioctl(struct megasas_instance *instance, 1642 struct megasas_ioctl *ioctl, int mode); 1643 static int handle_mfi_aen(struct megasas_instance *instance, 1644 struct megasas_aen *aen); 1645 static void fill_up_drv_ver(struct megasas_drv_ver *dv); 1646 #ifndef lint 1647 static void megasas_minphys(struct buf *bp); 1648 #endif 1649 static struct megasas_cmd *build_cmd(struct megasas_instance *instance, 1650 struct scsi_address *ap, struct scsi_pkt *pkt, 1651 uchar_t *cmd_done); 1652 static int wait_for_outstanding(struct megasas_instance *instance); 1653 static int register_mfi_aen(struct megasas_instance *instance, 1654 uint32_t seq_num, uint32_t class_locale_word); 1655 static int issue_mfi_pthru(struct megasas_instance *instance, struct 1656 megasas_ioctl *ioctl, struct megasas_cmd *cmd, int mode); 1657 static int issue_mfi_dcmd(struct megasas_instance *instance, struct 1658 megasas_ioctl *ioctl, struct megasas_cmd *cmd, int mode); 1659 static int issue_mfi_smp(struct megasas_instance *instance, struct 1660 megasas_ioctl *ioctl, struct megasas_cmd *cmd, int mode); 1661 static int issue_mfi_stp(struct megasas_instance *instance, struct 1662 megasas_ioctl *ioctl, struct megasas_cmd *cmd, int mode); 1663 static int abort_aen_cmd(struct megasas_instance *instance, 1664 struct megasas_cmd *cmd_to_abort); 1665 #if defined(NOT_YET) && !defined(lint) 1666 static void io_timeout_checker(void *instance); 1667 #endif 1668 1669 #ifdef __cplusplus 1670 } 1671 #endif 1672 1673 #endif /* _MEGARAID_SAS_H_ */ 1674