1226026Sdelphij/* 2226026Sdelphij * Copyright (c) 2010, LSI Corp. 3226026Sdelphij * All rights reserved. 4226026Sdelphij * Author : Manjunath Ranganathaiah 5226026Sdelphij * Support: freebsdraid@lsi.com 6226026Sdelphij * 7226026Sdelphij * Redistribution and use in source and binary forms, with or without 8226026Sdelphij * modification, are permitted provided that the following conditions 9226026Sdelphij * are met: 10226026Sdelphij * 11226026Sdelphij * 1. Redistributions of source code must retain the above copyright 12226026Sdelphij * notice, this list of conditions and the following disclaimer. 13226026Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 14226026Sdelphij * notice, this list of conditions and the following disclaimer in 15226026Sdelphij * the documentation and/or other materials provided with the 16226026Sdelphij * distribution. 17226026Sdelphij * 3. Neither the name of the <ORGANIZATION> nor the names of its 18226026Sdelphij * contributors may be used to endorse or promote products derived 19226026Sdelphij * from this software without specific prior written permission. 20226026Sdelphij * 21226026Sdelphij * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22226026Sdelphij * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23226026Sdelphij * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24226026Sdelphij * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25226026Sdelphij * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26226026Sdelphij * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27226026Sdelphij * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28226026Sdelphij * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29226026Sdelphij * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30226026Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31226026Sdelphij * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32226026Sdelphij * POSSIBILITY OF SUCH DAMAGE. 33226026Sdelphij * 34226026Sdelphij * $FreeBSD: releng/11.0/sys/dev/tws/tws_hdm.h 272000 2014-09-22 20:38:01Z jhb $ 35226026Sdelphij */ 36226026Sdelphij 37226026Sdelphij 38226026Sdelphij/* bit's defination */ 39226026Sdelphij 40226026Sdelphij#define TWS_BIT0 0x00000001 41226026Sdelphij#define TWS_BIT1 0x00000002 42226026Sdelphij#define TWS_BIT2 0x00000004 43226026Sdelphij#define TWS_BIT3 0x00000008 44226026Sdelphij#define TWS_BIT4 0x00000010 45226026Sdelphij#define TWS_BIT5 0x00000020 46226026Sdelphij#define TWS_BIT6 0x00000040 47226026Sdelphij#define TWS_BIT7 0x00000080 48226026Sdelphij#define TWS_BIT8 0x00000100 49226026Sdelphij#define TWS_BIT9 0x00000200 50226026Sdelphij#define TWS_BIT10 0x00000400 51226026Sdelphij#define TWS_BIT11 0x00000800 52226026Sdelphij#define TWS_BIT12 0x00001000 53226026Sdelphij#define TWS_BIT13 0x00002000 54226026Sdelphij#define TWS_BIT14 0x00004000 55226026Sdelphij#define TWS_BIT15 0x00008000 56226026Sdelphij#define TWS_BIT16 0x00010000 57226026Sdelphij#define TWS_BIT17 0x00020000 58226026Sdelphij#define TWS_BIT18 0x00040000 59226026Sdelphij#define TWS_BIT19 0x00080000 60226026Sdelphij#define TWS_BIT20 0x00100000 61226026Sdelphij#define TWS_BIT21 0x00200000 62226026Sdelphij#define TWS_BIT22 0x00400000 63226026Sdelphij#define TWS_BIT23 0x00800000 64226026Sdelphij#define TWS_BIT24 0x01000000 65226026Sdelphij#define TWS_BIT25 0x02000000 66226026Sdelphij#define TWS_BIT26 0x04000000 67226026Sdelphij#define TWS_BIT27 0x08000000 68226026Sdelphij#define TWS_BIT28 0x10000000 69226026Sdelphij#define TWS_BIT29 0x20000000 70226026Sdelphij#define TWS_BIT30 0x40000000 71226026Sdelphij#define TWS_BIT31 0x80000000 72226026Sdelphij 73226026Sdelphij#define TWS_SENSE_DATA_LENGTH 18 74226026Sdelphij#define TWS_ERROR_SPECIFIC_DESC_LEN 98 75226026Sdelphij 76226026Sdelphij/* response codes */ 77226026Sdelphij#define TWS_SENSE_SCSI_CURRENT_ERROR 0x70 78226026Sdelphij#define TWS_SENSE_SCSI_DEFERRED_ERROR 0x71 79226026Sdelphij 80226026Sdelphij#define TWS_SRC_CTRL_ERROR 3 81226026Sdelphij#define TWS_SRC_CTRL_EVENT 4 82226026Sdelphij#define TWS_SRC_FREEBSD_DRIVER 5 83226026Sdelphij#define TWS_SRC_FREEBSD_OS 8 84226026Sdelphij 85226026Sdelphij 86226026Sdelphijenum tws_sense_severity { 87226026Sdelphij error = 1, 88226026Sdelphij warning , 89226026Sdelphij info, 90226026Sdelphij debug, 91226026Sdelphij}; 92226026Sdelphij 93226026Sdelphij/* 94226026Sdelphij * Some errors of interest (in cmd_hdr->status_block.error) when a command 95226026Sdelphij * is completed by the firmware with an error. 96226026Sdelphij */ 97226026Sdelphij#define TWS_ERROR_LOGICAL_UNIT_NOT_SUPPORTED 0x010a 98226026Sdelphij#define TWS_ERROR_NOT_SUPPORTED 0x010D 99226026Sdelphij#define TWS_ERROR_UNIT_OFFLINE 0x0128 100226026Sdelphij#define TWS_ERROR_MORE_DATA 0x0231 101226026Sdelphij 102226026Sdelphij 103226026Sdelphij/* AEN codes of interest. */ 104226026Sdelphij#define TWS_AEN_QUEUE_EMPTY 0x00 105226026Sdelphij#define TWS_AEN_SOFT_RESET 0x01 106226026Sdelphij#define TWS_AEN_SYNC_TIME_WITH_HOST 0x31 107226026Sdelphij 108226026Sdelphij 109226026Sdelphij/* AEN severity */ 110226026Sdelphij#define TWS_SEVERITY_ERROR 0x1 111226026Sdelphij#define TWS_SEVERITY_WARNING 0x2 112226026Sdelphij#define TWS_SEVERITY_INFO 0x3 113226026Sdelphij#define TWS_SEVERITY_DEBUG 0x4 114226026Sdelphij 115226026Sdelphij#define TWS_64BIT_SG_ADDRESSES 0x00000001 116226026Sdelphij#define TWS_BIT_EXTEND 0x00000002 117226026Sdelphij 118226026Sdelphij#define TWS_BASE_FW_SRL 24 119226026Sdelphij#define TWS_BASE_FW_BRANCH 0 120226026Sdelphij#define TWS_BASE_FW_BUILD 1 121226026Sdelphij#define TWS_CURRENT_FW_SRL 41 122226026Sdelphij 123226026Sdelphij#define TWS_CURRENT_FW_BRANCH 8 124226026Sdelphij#define TWS_CURRENT_FW_BUILD 4 125226026Sdelphij#define TWS_CURRENT_ARCH_ID 0x000A 126226026Sdelphij 127226026Sdelphij 128226026Sdelphij#define TWS_FIFO_EMPTY 0xFFFFFFFFFFFFFFFFull 129226026Sdelphij#define TWS_FIFO_EMPTY32 0xFFFFFFFFull 130226026Sdelphij 131226026Sdelphij 132226026Sdelphij/* Register offsets from base address. */ 133226026Sdelphij#define TWS_CONTROL_REGISTER_OFFSET 0x0 134226026Sdelphij#define TWS_STATUS_REGISTER_OFFSET 0x4 135226026Sdelphij#define TWS_COMMAND_QUEUE_OFFSET 0x8 136226026Sdelphij#define TWS_RESPONSE_QUEUE_OFFSET 0xC 137226026Sdelphij#define TWS_COMMAND_QUEUE_OFFSET_LOW 0x20 138226026Sdelphij#define TWS_COMMAND_QUEUE_OFFSET_HIGH 0x24 139226026Sdelphij#define TWS_LARGE_RESPONSE_QUEUE_OFFSET 0x30 140226026Sdelphij 141226026Sdelphij/* I2O offsets */ 142226026Sdelphij#define TWS_I2O0_STATUS 0x0 143226026Sdelphij 144226026Sdelphij#define TWS_I2O0_HIBDB 0x20 145226026Sdelphij 146226026Sdelphij#define TWS_I2O0_HISTAT 0x30 147226026Sdelphij#define TWS_I2O0_HIMASK 0x34 148226026Sdelphij 149226026Sdelphij#define TWS_I2O0_HIBQP 0x40 150226026Sdelphij#define TWS_I2O0_HOBQP 0x44 151226026Sdelphij 152226026Sdelphij#define TWS_I2O0_CTL 0x74 153226026Sdelphij 154226026Sdelphij#define TWS_I2O0_IOBDB 0x9C 155226026Sdelphij#define TWS_I2O0_HOBDBC 0xA0 156226026Sdelphij 157226026Sdelphij#define TWS_I2O0_SCRPD3 0xBC 158226026Sdelphij 159226026Sdelphij#define TWS_I2O0_HIBQPL 0xC0 /* 64bit inb port low */ 160226026Sdelphij#define TWS_I2O0_HIBQPH 0xC4 /* 64bit inb port high */ 161226026Sdelphij#define TWS_I2O0_HOBQPL 0xC8 /* 64bit out port low */ 162226026Sdelphij#define TWS_I2O0_HOBQPH 0xCC /* 64bit out port high */ 163226026Sdelphij 164226026Sdelphij/* IOP related */ 165226026Sdelphij#define TWS_I2O0_IOPOBQPL 0xD8 /* OBFL */ 166226026Sdelphij#define TWS_I2O0_IOPOBQPH 0xDC /* OBFH */ 167226026Sdelphij#define TWS_I2O0_SRC_ADDRH 0xF8 /* Msg ASA */ 168226026Sdelphij 169226026Sdelphij#define TWS_MSG_ACC_MASK 0x20000000 170226026Sdelphij#define TWS_32BIT_MASK 0xFFFFFFFF 171226026Sdelphij 172226026Sdelphij/* revisit */ 173226026Sdelphij#define TWS_FW_CMD_NOP 0x0 174226026Sdelphij#define TWS_FW_CMD_INIT_CONNECTION 0x01 175226026Sdelphij#define TWS_FW_CMD_EXECUTE_SCSI 0x10 176226026Sdelphij 177241753Sdelphij#define TWS_FW_CMD_ATA_PASSTHROUGH 0x11 // This is really a PASSTHROUGH for both ATA and SCSI commands. 178226026Sdelphij#define TWS_FW_CMD_GET_PARAM 0x12 179226026Sdelphij#define TWS_FW_CMD_SET_PARAM 0x13 180226026Sdelphij 181226026Sdelphij 182226026Sdelphij#define BUILD_SGL_OFF__OPCODE(sgl_off, opcode) \ 183226026Sdelphij ((sgl_off << 5) & 0xE0) | (opcode & 0x1F) /* 3:5 */ 184226026Sdelphij 185226026Sdelphij#define BUILD_RES__OPCODE(res, opcode) \ 186226026Sdelphij ((res << 5) & 0xE0) | (opcode & 0x1F) /* 3:5 */ 187226026Sdelphij 188226026Sdelphij#define GET_OPCODE(sgl_off__opcode) \ 189226026Sdelphij (sgl_off__opcode & 0x1F) /* 3:5 */ 190226026Sdelphij 191226026Sdelphij 192226026Sdelphij 193226026Sdelphij/* end revisit */ 194226026Sdelphij 195226026Sdelphij 196226026Sdelphij/* Table #'s and id's of parameters of interest in firmware's param table. */ 197226026Sdelphij#define TWS_PARAM_VERSION_TABLE 0x0402 198226026Sdelphij#define TWS_PARAM_VERSION_FW 3 /* firmware version [16] */ 199226026Sdelphij#define TWS_PARAM_VERSION_BIOS 4 /* BIOSs version [16] */ 200226026Sdelphij#define TWS_PARAM_CTLR_MODEL 8 /* Controller model [16] */ 201226026Sdelphij 202226026Sdelphij#define TWS_PARAM_CONTROLLER_TABLE 0x0403 203226026Sdelphij#define TWS_PARAM_CONTROLLER_PORT_COUNT 3 /* number of ports [1] */ 204226026Sdelphij 205226026Sdelphij#define TWS_PARAM_TIME_TABLE 0x40A 206226026Sdelphij#define TWS_PARAM_TIME_SCHED_TIME 0x3 207226026Sdelphij 208226026Sdelphij#define TWS_PARAM_PHYS_TABLE 0x0001 209226026Sdelphij#define TWS_PARAM_CONTROLLER_PHYS_COUNT 2 /* number of phys */ 210226026Sdelphij 211226026Sdelphij#define TWS_9K_PARAM_DESCRIPTOR 0x8000 212226026Sdelphij 213226026Sdelphij 214226026Sdelphij/* ----------- request ------------- */ 215226026Sdelphij 216226026Sdelphij 217226026Sdelphij#pragma pack(1) 218226026Sdelphij 219226026Sdelphijstruct tws_cmd_init_connect { 220226026Sdelphij u_int8_t res1__opcode; /* 3:5 */ 221226026Sdelphij u_int8_t size; 222226026Sdelphij u_int8_t request_id; 223226026Sdelphij u_int8_t res2; 224226026Sdelphij u_int8_t status; 225226026Sdelphij u_int8_t flags; 226226026Sdelphij u_int16_t message_credits; 227226026Sdelphij u_int32_t features; 228226026Sdelphij u_int16_t fw_srl; 229226026Sdelphij u_int16_t fw_arch_id; 230226026Sdelphij u_int16_t fw_branch; 231226026Sdelphij u_int16_t fw_build; 232226026Sdelphij u_int32_t result; 233226026Sdelphij}; 234226026Sdelphij 235226026Sdelphij/* Structure for downloading firmware onto the controller. */ 236226026Sdelphijstruct tws_cmd_download_firmware { 237226026Sdelphij u_int8_t sgl_off__opcode;/* 3:5 */ 238226026Sdelphij u_int8_t size; 239226026Sdelphij u_int8_t request_id; 240226026Sdelphij u_int8_t unit; 241226026Sdelphij u_int8_t status; 242226026Sdelphij u_int8_t flags; 243226026Sdelphij u_int16_t param; 244226026Sdelphij u_int8_t sgl[1]; 245226026Sdelphij}; 246226026Sdelphij 247226026Sdelphij/* Structure for hard resetting the controller. */ 248226026Sdelphijstruct tws_cmd_reset_firmware { 249226026Sdelphij u_int8_t res1__opcode; /* 3:5 */ 250226026Sdelphij u_int8_t size; 251226026Sdelphij u_int8_t request_id; 252226026Sdelphij u_int8_t unit; 253226026Sdelphij u_int8_t status; 254226026Sdelphij u_int8_t flags; 255226026Sdelphij u_int8_t res2; 256226026Sdelphij u_int8_t param; 257226026Sdelphij}; 258226026Sdelphij 259226026Sdelphij 260226026Sdelphij/* Structure for sending get/set param commands. */ 261226026Sdelphijstruct tws_cmd_param { 262226026Sdelphij u_int8_t sgl_off__opcode;/* 3:5 */ 263226026Sdelphij u_int8_t size; 264226026Sdelphij u_int8_t request_id; 265226026Sdelphij u_int8_t host_id__unit; /* 4:4 */ 266226026Sdelphij u_int8_t status; 267226026Sdelphij u_int8_t flags; 268226026Sdelphij u_int16_t param_count; 269226026Sdelphij u_int8_t sgl[1]; 270226026Sdelphij}; 271226026Sdelphij 272226026Sdelphij/* Generic command packet. */ 273226026Sdelphijstruct tws_cmd_generic { 274226026Sdelphij u_int8_t sgl_off__opcode;/* 3:5 */ 275226026Sdelphij u_int8_t size; 276226026Sdelphij u_int8_t request_id; 277226026Sdelphij u_int8_t host_id__unit; /* 4:4 */ 278226026Sdelphij u_int8_t status; 279226026Sdelphij u_int8_t flags; 280226026Sdelphij u_int16_t count; /* block cnt, parameter cnt, message credits */ 281226026Sdelphij}; 282226026Sdelphij 283226026Sdelphij 284226026Sdelphij 285226026Sdelphij 286226026Sdelphij/* Command packet header. */ 287226026Sdelphijstruct tws_command_header { 288226026Sdelphij u_int8_t sense_data[TWS_SENSE_DATA_LENGTH]; 289226026Sdelphij struct { /* status block - additional sense data */ 290226026Sdelphij u_int16_t srcnum; 291226026Sdelphij u_int8_t reserved; 292226026Sdelphij u_int8_t status; 293226026Sdelphij u_int16_t error; 294226026Sdelphij u_int8_t res__srcid; /* 4:4 */ 295226026Sdelphij u_int8_t res__severity; /* 5:3 */ 296226026Sdelphij } status_block; 297226026Sdelphij u_int8_t err_specific_desc[TWS_ERROR_SPECIFIC_DESC_LEN]; 298226026Sdelphij struct { /* sense buffer descriptor */ 299226026Sdelphij u_int8_t size_header; 300226026Sdelphij u_int16_t request_id; 301226026Sdelphij u_int8_t size_sense; 302226026Sdelphij } header_desc; 303226026Sdelphij}; 304226026Sdelphij 305226026Sdelphij/* Command - 1024 byte size including header (128+24+896)*/ 306226026Sdelphijunion tws_command_giga { 307226026Sdelphij struct tws_cmd_init_connect init_connect; 308226026Sdelphij struct tws_cmd_download_firmware download_fw; 309226026Sdelphij struct tws_cmd_reset_firmware reset_fw; 310226026Sdelphij struct tws_cmd_param param; 311226026Sdelphij struct tws_cmd_generic generic; 312226026Sdelphij u_int8_t padding[1024 - sizeof(struct tws_command_header)]; 313226026Sdelphij}; 314226026Sdelphij 315226026Sdelphij/* driver command pkt - 1024 byte size including header(128+24+744+128) */ 316226026Sdelphij/* h/w & f/w supported command size excluding header 768 */ 317226026Sdelphijstruct tws_command_apache { 318226026Sdelphij u_int8_t res__opcode; /* 3:5 */ 319226026Sdelphij u_int8_t unit; 320226026Sdelphij u_int16_t lun_l4__req_id; /* 4:12 */ 321226026Sdelphij u_int8_t status; 322226026Sdelphij u_int8_t sgl_offset; /* offset (in bytes) to sg_list, 323226026Sdelphij from the end of sgl_entries */ 324226026Sdelphij u_int16_t lun_h4__sgl_entries; 325226026Sdelphij u_int8_t cdb[16]; 326226026Sdelphij u_int8_t sg_list[744]; /* 768 - 24 */ 327226026Sdelphij u_int8_t padding[128]; /* make it 1024 bytes */ 328226026Sdelphij}; 329226026Sdelphij 330226026Sdelphijstruct tws_command_packet { 331226026Sdelphij struct tws_command_header hdr; 332226026Sdelphij union { 333226026Sdelphij union tws_command_giga pkt_g; 334226026Sdelphij struct tws_command_apache pkt_a; 335226026Sdelphij } cmd; 336226026Sdelphij}; 337226026Sdelphij 338226026Sdelphij/* Structure describing payload for get/set param commands. */ 339226026Sdelphijstruct tws_getset_param { 340226026Sdelphij u_int16_t table_id; 341226026Sdelphij u_int8_t parameter_id; 342226026Sdelphij u_int8_t reserved; 343226026Sdelphij u_int16_t parameter_size_bytes; 344226026Sdelphij u_int16_t parameter_actual_size_bytes; 345226026Sdelphij u_int8_t data[1]; 346226026Sdelphij}; 347226026Sdelphij 348226026Sdelphijstruct tws_outbound_response { 349226026Sdelphij u_int32_t not_mfa :1; /* 1 if the structure is valid else MFA */ 350226026Sdelphij u_int32_t reserved :7; /* reserved bits */ 351226026Sdelphij u_int32_t status :8; /* should be 0 */ 352226026Sdelphij u_int32_t request_id:16; /* request id */ 353226026Sdelphij}; 354226026Sdelphij 355226026Sdelphij 356226026Sdelphij/* Scatter/Gather list entry with 32 bit addresses. */ 357226026Sdelphijstruct tws_sg_desc32 { 358226026Sdelphij u_int32_t address; 359226026Sdelphij u_int32_t length :24; 360226026Sdelphij u_int32_t flag :8; 361226026Sdelphij}; 362226026Sdelphij 363226026Sdelphij/* Scatter/Gather list entry with 64 bit addresses. */ 364226026Sdelphijstruct tws_sg_desc64 { 365226026Sdelphij u_int64_t address; 366226026Sdelphij u_int64_t length :32; 367226026Sdelphij u_int64_t reserved :24; 368226026Sdelphij u_int64_t flag :8; 369226026Sdelphij}; 370226026Sdelphij 371226026Sdelphij/* 372226026Sdelphij * Packet that describes an AEN/error generated by the controller, 373226026Sdelphij * shared with user 374226026Sdelphij */ 375226026Sdelphijstruct tws_event_packet { 376226026Sdelphij u_int32_t sequence_id; 377226026Sdelphij u_int32_t time_stamp_sec; 378226026Sdelphij u_int16_t aen_code; 379226026Sdelphij u_int8_t severity; 380226026Sdelphij u_int8_t retrieved; 381226026Sdelphij u_int8_t repeat_count; 382226026Sdelphij u_int8_t parameter_len; 383226026Sdelphij u_int8_t parameter_data[TWS_ERROR_SPECIFIC_DESC_LEN]; 384226026Sdelphij u_int32_t event_src; 385226026Sdelphij u_int8_t severity_str[20]; 386226026Sdelphij}; 387226026Sdelphij 388226026Sdelphij 389226026Sdelphij 390226026Sdelphij#pragma pack() 391226026Sdelphij 392226026Sdelphijstruct tws_sense { 393226026Sdelphij struct tws_command_header *hdr; 394226026Sdelphij u_int64_t hdr_pkt_phy; 395226026Sdelphij}; 396226026Sdelphij 397226026Sdelphijstruct tws_request { 398226026Sdelphij struct tws_command_packet *cmd_pkt; /* command pkt */ 399226026Sdelphij u_int64_t cmd_pkt_phy; /* cmd pkt physical address */ 400226026Sdelphij void *data; /* ptr to data being passed to fw */ 401226026Sdelphij u_int32_t length; /* length of data being passed to fw */ 402226026Sdelphij 403226026Sdelphij u_int32_t state; /* request state */ 404226026Sdelphij u_int32_t type; /* request type */ 405226026Sdelphij u_int32_t flags; /* request flags */ 406226026Sdelphij 407226026Sdelphij u_int32_t error_code; /* error during request processing */ 408226026Sdelphij 409226026Sdelphij u_int32_t request_id; /* request id for tracking with fw */ 410226026Sdelphij void (*cb)(struct tws_request *); /* callback func */ 411226026Sdelphij bus_dmamap_t dma_map; /* dma map */ 412226026Sdelphij union ccb *ccb_ptr; /* pointer to ccb */ 413272000Sjhb struct callout timeout; /* request timeout timer */ 414226026Sdelphij struct tws_softc *sc; /* pointer back to ctlr softc */ 415226026Sdelphij 416226026Sdelphij struct tws_request *next; /* pointer to next request */ 417226026Sdelphij struct tws_request *prev; /* pointer to prev request */ 418226026Sdelphij}; 419226026Sdelphij 420226026Sdelphij 421