1 /* 2 * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net> 3 * Copyright (C) 2004 - 2005 Leonid Stoljar 4 * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us> 5 * Copyright (C) 2007 - 2010 ID7 Ltd. 6 * 7 * Forward port and refactoring to modern qla2xxx and target/configfs 8 * 9 * Copyright (C) 2010-2011 Nicholas A. Bellinger <nab@kernel.org> 10 * 11 * Additional file for the target driver support. 12 * 13 * This program is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU General Public License 15 * as published by the Free Software Foundation; either version 2 16 * of the License, or (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 */ 23 /* 24 * This is the global def file that is useful for including from the 25 * target portion. 26 */ 27 28 #ifndef __QLA_TARGET_H 29 #define __QLA_TARGET_H 30 31 #include "qla_def.h" 32 #include "qla_dsd.h" 33 34 /* 35 * Must be changed on any change in any initiator visible interfaces or 36 * data in the target add-on 37 */ 38 #define QLA2XXX_TARGET_MAGIC 269 39 40 /* 41 * Must be changed on any change in any target visible interfaces or 42 * data in the initiator 43 */ 44 #define QLA2XXX_INITIATOR_MAGIC 57222 45 46 #define QLA2XXX_INI_MODE_STR_EXCLUSIVE "exclusive" 47 #define QLA2XXX_INI_MODE_STR_DISABLED "disabled" 48 #define QLA2XXX_INI_MODE_STR_ENABLED "enabled" 49 #define QLA2XXX_INI_MODE_STR_DUAL "dual" 50 51 #define QLA2XXX_INI_MODE_EXCLUSIVE 0 52 #define QLA2XXX_INI_MODE_DISABLED 1 53 #define QLA2XXX_INI_MODE_ENABLED 2 54 #define QLA2XXX_INI_MODE_DUAL 3 55 56 #define QLA2XXX_COMMAND_COUNT_INIT 250 57 #define QLA2XXX_IMMED_NOTIFY_COUNT_INIT 250 58 59 /* 60 * Used to mark which completion handles (for RIO Status's) are for CTIO's 61 * vs. regular (non-target) info. This is checked for in 62 * qla2x00_process_response_queue() to see if a handle coming back in a 63 * multi-complete should come to the tgt driver or be handled there by qla2xxx 64 */ 65 #define CTIO_COMPLETION_HANDLE_MARK BIT_29 66 #if (CTIO_COMPLETION_HANDLE_MARK <= DEFAULT_OUTSTANDING_COMMANDS) 67 #error "CTIO_COMPLETION_HANDLE_MARK not larger than " 68 "DEFAULT_OUTSTANDING_COMMANDS" 69 #endif 70 #define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK) 71 72 /* Used to mark CTIO as intermediate */ 73 #define CTIO_INTERMEDIATE_HANDLE_MARK BIT_30 74 #define QLA_TGT_NULL_HANDLE 0 75 76 #define QLA_TGT_HANDLE_MASK 0xF0000000 77 #define QLA_QPID_HANDLE_MASK 0x00FF0000 /* qpair id mask */ 78 #define QLA_CMD_HANDLE_MASK 0x0000FFFF 79 #define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~QLA_TGT_HANDLE_MASK) 80 81 #define QLA_QPID_HANDLE_SHIFT 16 82 #define GET_QID(_h) ((_h & QLA_QPID_HANDLE_MASK) >> QLA_QPID_HANDLE_SHIFT) 83 84 85 #ifndef OF_SS_MODE_0 86 /* 87 * ISP target entries - Flags bit definitions. 88 */ 89 #define OF_SS_MODE_0 0 90 #define OF_SS_MODE_1 1 91 #define OF_SS_MODE_2 2 92 #define OF_SS_MODE_3 3 93 94 #define OF_EXPL_CONF BIT_5 /* Explicit Confirmation Requested */ 95 #define OF_DATA_IN BIT_6 /* Data in to initiator */ 96 /* (data from target to initiator) */ 97 #define OF_DATA_OUT BIT_7 /* Data out from initiator */ 98 /* (data from initiator to target) */ 99 #define OF_NO_DATA (BIT_7 | BIT_6) 100 #define OF_INC_RC BIT_8 /* Increment command resource count */ 101 #define OF_FAST_POST BIT_9 /* Enable mailbox fast posting. */ 102 #define OF_CONF_REQ BIT_13 /* Confirmation Requested */ 103 #define OF_TERM_EXCH BIT_14 /* Terminate exchange */ 104 #define OF_SSTS BIT_15 /* Send SCSI status */ 105 #endif 106 107 #ifndef QLA_TGT_DATASEGS_PER_CMD32 108 #define QLA_TGT_DATASEGS_PER_CMD32 3 109 #define QLA_TGT_DATASEGS_PER_CONT32 7 110 #define QLA_TGT_MAX_SG32(ql) \ 111 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \ 112 QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0) 113 114 #define QLA_TGT_DATASEGS_PER_CMD64 2 115 #define QLA_TGT_DATASEGS_PER_CONT64 5 116 #define QLA_TGT_MAX_SG64(ql) \ 117 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \ 118 QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0) 119 #endif 120 121 #ifndef QLA_TGT_DATASEGS_PER_CMD_24XX 122 #define QLA_TGT_DATASEGS_PER_CMD_24XX 1 123 #define QLA_TGT_DATASEGS_PER_CONT_24XX 5 124 #define QLA_TGT_MAX_SG_24XX(ql) \ 125 (min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \ 126 QLA_TGT_DATASEGS_PER_CONT_24XX*((ql) - 1)) : 0)) 127 #endif 128 #endif 129 130 #define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha)) \ 131 ? le16_to_cpu((iocb)->u.isp2x.target.extended) \ 132 : (uint16_t)(iocb)->u.isp2x.target.id.standard) 133 134 #ifndef NOTIFY_ACK_TYPE 135 #define NOTIFY_ACK_TYPE 0x0E /* Notify acknowledge entry. */ 136 /* 137 * ISP queue - notify acknowledge entry structure definition. 138 * This is sent to the ISP from the target driver. 139 */ 140 struct nack_to_isp { 141 uint8_t entry_type; /* Entry type. */ 142 uint8_t entry_count; /* Entry count. */ 143 uint8_t sys_define; /* System defined. */ 144 uint8_t entry_status; /* Entry Status. */ 145 union { 146 struct { 147 uint32_t sys_define_2; /* System defined. */ 148 target_id_t target; 149 uint8_t target_id; 150 uint8_t reserved_1; 151 uint16_t flags; 152 uint16_t resp_code; 153 uint16_t status; 154 uint16_t task_flags; 155 uint16_t seq_id; 156 uint16_t srr_rx_id; 157 uint32_t srr_rel_offs; 158 uint16_t srr_ui; 159 uint16_t srr_flags; 160 uint16_t srr_reject_code; 161 uint8_t srr_reject_vendor_uniq; 162 uint8_t srr_reject_code_expl; 163 uint8_t reserved_2[24]; 164 } isp2x; 165 struct { 166 uint32_t handle; 167 uint16_t nport_handle; 168 uint16_t reserved_1; 169 uint16_t flags; 170 uint16_t srr_rx_id; 171 uint16_t status; 172 uint8_t status_subcode; 173 uint8_t fw_handle; 174 uint32_t exchange_address; 175 uint32_t srr_rel_offs; 176 uint16_t srr_ui; 177 uint16_t srr_flags; 178 uint8_t reserved_4[19]; 179 uint8_t vp_index; 180 uint8_t srr_reject_vendor_uniq; 181 uint8_t srr_reject_code_expl; 182 uint8_t srr_reject_code; 183 uint8_t reserved_5[5]; 184 } isp24; 185 } u; 186 uint8_t reserved[2]; 187 uint16_t ox_id; 188 } __packed; 189 #define NOTIFY_ACK_FLAGS_TERMINATE BIT_3 190 #define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0 191 #define NOTIFY_ACK_SRR_FLAGS_REJECT 1 192 193 #define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9 194 195 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0 196 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a 197 198 #define NOTIFY_ACK_SUCCESS 0x01 199 #endif 200 201 #ifndef ACCEPT_TGT_IO_TYPE 202 #define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */ 203 #endif 204 205 #ifndef CONTINUE_TGT_IO_TYPE 206 #define CONTINUE_TGT_IO_TYPE 0x17 207 /* 208 * ISP queue - Continue Target I/O (CTIO) entry for status mode 0 structure. 209 * This structure is sent to the ISP 2xxx from target driver. 210 */ 211 struct ctio_to_2xxx { 212 uint8_t entry_type; /* Entry type. */ 213 uint8_t entry_count; /* Entry count. */ 214 uint8_t sys_define; /* System defined. */ 215 uint8_t entry_status; /* Entry Status. */ 216 uint32_t handle; /* System defined handle */ 217 target_id_t target; 218 uint16_t rx_id; 219 uint16_t flags; 220 uint16_t status; 221 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */ 222 uint16_t dseg_count; /* Data segment count. */ 223 uint32_t relative_offset; 224 uint32_t residual; 225 uint16_t reserved_1[3]; 226 uint16_t scsi_status; 227 uint32_t transfer_length; 228 struct dsd32 dsd[3]; 229 } __packed; 230 #define ATIO_PATH_INVALID 0x07 231 #define ATIO_CANT_PROV_CAP 0x16 232 #define ATIO_CDB_VALID 0x3D 233 234 #define ATIO_EXEC_READ BIT_1 235 #define ATIO_EXEC_WRITE BIT_0 236 #endif 237 238 #ifndef CTIO_A64_TYPE 239 #define CTIO_A64_TYPE 0x1F 240 #define CTIO_SUCCESS 0x01 241 #define CTIO_ABORTED 0x02 242 #define CTIO_INVALID_RX_ID 0x08 243 #define CTIO_TIMEOUT 0x0B 244 #define CTIO_DIF_ERROR 0x0C /* DIF error detected */ 245 #define CTIO_LIP_RESET 0x0E 246 #define CTIO_TARGET_RESET 0x17 247 #define CTIO_PORT_UNAVAILABLE 0x28 248 #define CTIO_PORT_LOGGED_OUT 0x29 249 #define CTIO_PORT_CONF_CHANGED 0x2A 250 #define CTIO_SRR_RECEIVED 0x45 251 #endif 252 253 #ifndef CTIO_RET_TYPE 254 #define CTIO_RET_TYPE 0x17 /* CTIO return entry */ 255 #define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */ 256 257 struct fcp_hdr { 258 uint8_t r_ctl; 259 uint8_t d_id[3]; 260 uint8_t cs_ctl; 261 uint8_t s_id[3]; 262 uint8_t type; 263 uint8_t f_ctl[3]; 264 uint8_t seq_id; 265 uint8_t df_ctl; 266 uint16_t seq_cnt; 267 __be16 ox_id; 268 uint16_t rx_id; 269 uint32_t parameter; 270 } __packed; 271 272 struct fcp_hdr_le { 273 uint8_t d_id[3]; 274 uint8_t r_ctl; 275 uint8_t s_id[3]; 276 uint8_t cs_ctl; 277 uint8_t f_ctl[3]; 278 uint8_t type; 279 uint16_t seq_cnt; 280 uint8_t df_ctl; 281 uint8_t seq_id; 282 uint16_t rx_id; 283 uint16_t ox_id; 284 uint32_t parameter; 285 } __packed; 286 287 #define F_CTL_EXCH_CONTEXT_RESP BIT_23 288 #define F_CTL_SEQ_CONTEXT_RESIP BIT_22 289 #define F_CTL_LAST_SEQ BIT_20 290 #define F_CTL_END_SEQ BIT_19 291 #define F_CTL_SEQ_INITIATIVE BIT_16 292 293 #define R_CTL_BASIC_LINK_SERV 0x80 294 #define R_CTL_B_ACC 0x4 295 #define R_CTL_B_RJT 0x5 296 297 struct atio7_fcp_cmnd { 298 uint64_t lun; 299 uint8_t cmnd_ref; 300 uint8_t task_attr:3; 301 uint8_t reserved:5; 302 uint8_t task_mgmt_flags; 303 #define FCP_CMND_TASK_MGMT_CLEAR_ACA 6 304 #define FCP_CMND_TASK_MGMT_TARGET_RESET 5 305 #define FCP_CMND_TASK_MGMT_LU_RESET 4 306 #define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2 307 #define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1 308 uint8_t wrdata:1; 309 uint8_t rddata:1; 310 uint8_t add_cdb_len:6; 311 uint8_t cdb[16]; 312 /* 313 * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4 314 * only to make sizeof(struct atio7_fcp_cmnd) be as expected by 315 * BUILD_BUG_ON in qlt_init(). 316 */ 317 uint8_t add_cdb[4]; 318 /* uint32_t data_length; */ 319 } __packed; 320 321 /* 322 * ISP queue - Accept Target I/O (ATIO) type entry IOCB structure. 323 * This is sent from the ISP to the target driver. 324 */ 325 struct atio_from_isp { 326 union { 327 struct { 328 uint16_t entry_hdr; 329 uint8_t sys_define; /* System defined. */ 330 uint8_t entry_status; /* Entry Status. */ 331 uint32_t sys_define_2; /* System defined. */ 332 target_id_t target; 333 uint16_t rx_id; 334 uint16_t flags; 335 uint16_t status; 336 uint8_t command_ref; 337 uint8_t task_codes; 338 uint8_t task_flags; 339 uint8_t execution_codes; 340 uint8_t cdb[MAX_CMDSZ]; 341 uint32_t data_length; 342 uint16_t lun; 343 uint8_t initiator_port_name[WWN_SIZE]; /* on qla23xx */ 344 uint16_t reserved_32[6]; 345 uint16_t ox_id; 346 } isp2x; 347 struct { 348 uint16_t entry_hdr; 349 uint8_t fcp_cmnd_len_low; 350 uint8_t fcp_cmnd_len_high:4; 351 uint8_t attr:4; 352 uint32_t exchange_addr; 353 #define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF 354 struct fcp_hdr fcp_hdr; 355 struct atio7_fcp_cmnd fcp_cmnd; 356 } isp24; 357 struct { 358 uint8_t entry_type; /* Entry type. */ 359 uint8_t entry_count; /* Entry count. */ 360 __le16 attr_n_length; 361 #define FCP_CMD_LENGTH_MASK 0x0fff 362 #define FCP_CMD_LENGTH_MIN 0x38 363 uint8_t data[56]; 364 uint32_t signature; 365 #define ATIO_PROCESSED 0xDEADDEAD /* Signature */ 366 } raw; 367 } u; 368 } __packed; 369 370 static inline int fcpcmd_is_corrupted(struct atio *atio) 371 { 372 if (atio->entry_type == ATIO_TYPE7 && 373 ((le16_to_cpu(atio->attr_n_length) & FCP_CMD_LENGTH_MASK) < 374 FCP_CMD_LENGTH_MIN)) 375 return 1; 376 else 377 return 0; 378 } 379 380 /* adjust corrupted atio so we won't trip over the same entry again. */ 381 static inline void adjust_corrupted_atio(struct atio_from_isp *atio) 382 { 383 atio->u.raw.attr_n_length = cpu_to_le16(FCP_CMD_LENGTH_MIN); 384 atio->u.isp24.fcp_cmnd.add_cdb_len = 0; 385 } 386 387 static inline int get_datalen_for_atio(struct atio_from_isp *atio) 388 { 389 int len = atio->u.isp24.fcp_cmnd.add_cdb_len; 390 391 return (be32_to_cpu(get_unaligned((uint32_t *) 392 &atio->u.isp24.fcp_cmnd.add_cdb[len * 4]))); 393 } 394 395 #define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */ 396 397 /* 398 * ISP queue - Continue Target I/O (ATIO) type 7 entry (for 24xx) structure. 399 * This structure is sent to the ISP 24xx from the target driver. 400 */ 401 402 struct ctio7_to_24xx { 403 uint8_t entry_type; /* Entry type. */ 404 uint8_t entry_count; /* Entry count. */ 405 uint8_t sys_define; /* System defined. */ 406 uint8_t entry_status; /* Entry Status. */ 407 uint32_t handle; /* System defined handle */ 408 uint16_t nport_handle; 409 #define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF 410 uint16_t timeout; 411 uint16_t dseg_count; /* Data segment count. */ 412 uint8_t vp_index; 413 uint8_t add_flags; 414 uint8_t initiator_id[3]; 415 uint8_t reserved; 416 uint32_t exchange_addr; 417 union { 418 struct { 419 uint16_t reserved1; 420 __le16 flags; 421 uint32_t residual; 422 __le16 ox_id; 423 uint16_t scsi_status; 424 uint32_t relative_offset; 425 uint32_t reserved2; 426 uint32_t transfer_length; 427 uint32_t reserved3; 428 struct dsd64 dsd; 429 } status0; 430 struct { 431 uint16_t sense_length; 432 __le16 flags; 433 uint32_t residual; 434 __le16 ox_id; 435 uint16_t scsi_status; 436 uint16_t response_len; 437 uint16_t reserved; 438 uint8_t sense_data[24]; 439 } status1; 440 } u; 441 } __packed; 442 443 /* 444 * ISP queue - CTIO type 7 from ISP 24xx to target driver 445 * returned entry structure. 446 */ 447 struct ctio7_from_24xx { 448 uint8_t entry_type; /* Entry type. */ 449 uint8_t entry_count; /* Entry count. */ 450 uint8_t sys_define; /* System defined. */ 451 uint8_t entry_status; /* Entry Status. */ 452 uint32_t handle; /* System defined handle */ 453 uint16_t status; 454 uint16_t timeout; 455 uint16_t dseg_count; /* Data segment count. */ 456 uint8_t vp_index; 457 uint8_t reserved1[5]; 458 uint32_t exchange_address; 459 uint16_t reserved2; 460 uint16_t flags; 461 uint32_t residual; 462 uint16_t ox_id; 463 uint16_t reserved3; 464 uint32_t relative_offset; 465 uint8_t reserved4[24]; 466 } __packed; 467 468 /* CTIO7 flags values */ 469 #define CTIO7_FLAGS_SEND_STATUS BIT_15 470 #define CTIO7_FLAGS_TERMINATE BIT_14 471 #define CTIO7_FLAGS_CONFORM_REQ BIT_13 472 #define CTIO7_FLAGS_DONT_RET_CTIO BIT_8 473 #define CTIO7_FLAGS_STATUS_MODE_0 0 474 #define CTIO7_FLAGS_STATUS_MODE_1 BIT_6 475 #define CTIO7_FLAGS_STATUS_MODE_2 BIT_7 476 #define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5 477 #define CTIO7_FLAGS_CONFIRM_SATISF BIT_4 478 #define CTIO7_FLAGS_DSD_PTR BIT_2 479 #define CTIO7_FLAGS_DATA_IN BIT_1 /* data to initiator */ 480 #define CTIO7_FLAGS_DATA_OUT BIT_0 /* data from initiator */ 481 482 #define ELS_PLOGI 0x3 483 #define ELS_FLOGI 0x4 484 #define ELS_LOGO 0x5 485 #define ELS_PRLI 0x20 486 #define ELS_PRLO 0x21 487 #define ELS_TPRLO 0x24 488 #define ELS_PDISC 0x50 489 #define ELS_ADISC 0x52 490 491 /* 492 *CTIO Type CRC_2 IOCB 493 */ 494 struct ctio_crc2_to_fw { 495 uint8_t entry_type; /* Entry type. */ 496 #define CTIO_CRC2 0x7A 497 uint8_t entry_count; /* Entry count. */ 498 uint8_t sys_define; /* System defined. */ 499 uint8_t entry_status; /* Entry Status. */ 500 501 uint32_t handle; /* System handle. */ 502 uint16_t nport_handle; /* N_PORT handle. */ 503 __le16 timeout; /* Command timeout. */ 504 505 uint16_t dseg_count; /* Data segment count. */ 506 uint8_t vp_index; 507 uint8_t add_flags; /* additional flags */ 508 #define CTIO_CRC2_AF_DIF_DSD_ENA BIT_3 509 510 uint8_t initiator_id[3]; /* initiator ID */ 511 uint8_t reserved1; 512 uint32_t exchange_addr; /* rcv exchange address */ 513 uint16_t reserved2; 514 __le16 flags; /* refer to CTIO7 flags values */ 515 uint32_t residual; 516 __le16 ox_id; 517 uint16_t scsi_status; 518 __le32 relative_offset; 519 uint32_t reserved5; 520 __le32 transfer_length; /* total fc transfer length */ 521 uint32_t reserved6; 522 __le64 crc_context_address __packed; /* Data segment address. */ 523 uint16_t crc_context_len; /* Data segment length. */ 524 uint16_t reserved_1; /* MUST be set to 0. */ 525 }; 526 527 /* CTIO Type CRC_x Status IOCB */ 528 struct ctio_crc_from_fw { 529 uint8_t entry_type; /* Entry type. */ 530 uint8_t entry_count; /* Entry count. */ 531 uint8_t sys_define; /* System defined. */ 532 uint8_t entry_status; /* Entry Status. */ 533 534 uint32_t handle; /* System handle. */ 535 uint16_t status; 536 uint16_t timeout; /* Command timeout. */ 537 uint16_t dseg_count; /* Data segment count. */ 538 uint32_t reserved1; 539 uint16_t state_flags; 540 #define CTIO_CRC_SF_DIF_CHOPPED BIT_4 541 542 uint32_t exchange_address; /* rcv exchange address */ 543 uint16_t reserved2; 544 uint16_t flags; 545 uint32_t resid_xfer_length; 546 uint16_t ox_id; 547 uint8_t reserved3[12]; 548 uint16_t runt_guard; /* reported runt blk guard */ 549 uint8_t actual_dif[8]; 550 uint8_t expected_dif[8]; 551 } __packed; 552 553 /* 554 * ISP queue - ABTS received/response entries structure definition for 24xx. 555 */ 556 #define ABTS_RECV_24XX 0x54 /* ABTS received (for 24xx) */ 557 #define ABTS_RESP_24XX 0x55 /* ABTS responce (for 24xx) */ 558 559 /* 560 * ISP queue - ABTS received IOCB entry structure definition for 24xx. 561 * The ABTS BLS received from the wire is sent to the 562 * target driver by the ISP 24xx. 563 * The IOCB is placed on the response queue. 564 */ 565 struct abts_recv_from_24xx { 566 uint8_t entry_type; /* Entry type. */ 567 uint8_t entry_count; /* Entry count. */ 568 uint8_t sys_define; /* System defined. */ 569 uint8_t entry_status; /* Entry Status. */ 570 uint8_t reserved_1[6]; 571 uint16_t nport_handle; 572 uint8_t reserved_2[2]; 573 uint8_t vp_index; 574 uint8_t reserved_3:4; 575 uint8_t sof_type:4; 576 uint32_t exchange_address; 577 struct fcp_hdr_le fcp_hdr_le; 578 uint8_t reserved_4[16]; 579 uint32_t exchange_addr_to_abort; 580 } __packed; 581 582 #define ABTS_PARAM_ABORT_SEQ BIT_0 583 584 struct ba_acc_le { 585 uint16_t reserved; 586 uint8_t seq_id_last; 587 uint8_t seq_id_valid; 588 #define SEQ_ID_VALID 0x80 589 #define SEQ_ID_INVALID 0x00 590 uint16_t rx_id; 591 uint16_t ox_id; 592 uint16_t high_seq_cnt; 593 uint16_t low_seq_cnt; 594 } __packed; 595 596 struct ba_rjt_le { 597 uint8_t vendor_uniq; 598 uint8_t reason_expl; 599 uint8_t reason_code; 600 #define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1 601 #define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9 602 uint8_t reserved; 603 } __packed; 604 605 /* 606 * ISP queue - ABTS Response IOCB entry structure definition for 24xx. 607 * The ABTS response to the ABTS received is sent by the 608 * target driver to the ISP 24xx. 609 * The IOCB is placed on the request queue. 610 */ 611 struct abts_resp_to_24xx { 612 uint8_t entry_type; /* Entry type. */ 613 uint8_t entry_count; /* Entry count. */ 614 uint8_t sys_define; /* System defined. */ 615 uint8_t entry_status; /* Entry Status. */ 616 uint32_t handle; 617 uint16_t reserved_1; 618 uint16_t nport_handle; 619 uint16_t control_flags; 620 #define ABTS_CONTR_FLG_TERM_EXCHG BIT_0 621 uint8_t vp_index; 622 uint8_t reserved_3:4; 623 uint8_t sof_type:4; 624 uint32_t exchange_address; 625 struct fcp_hdr_le fcp_hdr_le; 626 union { 627 struct ba_acc_le ba_acct; 628 struct ba_rjt_le ba_rjt; 629 } __packed payload; 630 uint32_t reserved_4; 631 uint32_t exchange_addr_to_abort; 632 } __packed; 633 634 /* 635 * ISP queue - ABTS Response IOCB from ISP24xx Firmware entry structure. 636 * The ABTS response with completion status to the ABTS response 637 * (sent by the target driver to the ISP 24xx) is sent by the 638 * ISP24xx firmware to the target driver. 639 * The IOCB is placed on the response queue. 640 */ 641 struct abts_resp_from_24xx_fw { 642 uint8_t entry_type; /* Entry type. */ 643 uint8_t entry_count; /* Entry count. */ 644 uint8_t sys_define; /* System defined. */ 645 uint8_t entry_status; /* Entry Status. */ 646 uint32_t handle; 647 uint16_t compl_status; 648 #define ABTS_RESP_COMPL_SUCCESS 0 649 #define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31 650 uint16_t nport_handle; 651 uint16_t reserved_1; 652 uint8_t reserved_2; 653 uint8_t reserved_3:4; 654 uint8_t sof_type:4; 655 uint32_t exchange_address; 656 struct fcp_hdr_le fcp_hdr_le; 657 uint8_t reserved_4[8]; 658 uint32_t error_subcode1; 659 #define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E 660 uint32_t error_subcode2; 661 uint32_t exchange_addr_to_abort; 662 } __packed; 663 664 /********************************************************************\ 665 * Type Definitions used by initiator & target halves 666 \********************************************************************/ 667 668 struct qla_tgt_mgmt_cmd; 669 struct fc_port; 670 struct qla_tgt_cmd; 671 672 /* 673 * This structure provides a template of function calls that the 674 * target driver (from within qla_target.c) can issue to the 675 * target module (tcm_qla2xxx). 676 */ 677 struct qla_tgt_func_tmpl { 678 struct qla_tgt_cmd *(*find_cmd_by_tag)(struct fc_port *, uint64_t); 679 int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *, 680 unsigned char *, uint32_t, int, int, int); 681 void (*handle_data)(struct qla_tgt_cmd *); 682 int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, u64, uint16_t, 683 uint32_t); 684 void (*free_cmd)(struct qla_tgt_cmd *); 685 void (*free_mcmd)(struct qla_tgt_mgmt_cmd *); 686 void (*free_session)(struct fc_port *); 687 688 int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *, 689 struct fc_port *); 690 void (*update_sess)(struct fc_port *, port_id_t, uint16_t, bool); 691 struct fc_port *(*find_sess_by_loop_id)(struct scsi_qla_host *, 692 const uint16_t); 693 struct fc_port *(*find_sess_by_s_id)(struct scsi_qla_host *, 694 const uint8_t *); 695 void (*clear_nacl_from_fcport_map)(struct fc_port *); 696 void (*put_sess)(struct fc_port *); 697 void (*shutdown_sess)(struct fc_port *); 698 int (*get_dif_tags)(struct qla_tgt_cmd *cmd, uint16_t *pfw_prot_opts); 699 int (*chk_dif_tags)(uint32_t tag); 700 void (*add_target)(struct scsi_qla_host *); 701 void (*remove_target)(struct scsi_qla_host *); 702 }; 703 704 int qla2x00_wait_for_hba_online(struct scsi_qla_host *); 705 706 #include <target/target_core_base.h> 707 708 #define QLA_TGT_TIMEOUT 10 /* in seconds */ 709 710 #define QLA_TGT_MAX_HW_PENDING_TIME 60 /* in seconds */ 711 712 /* Immediate notify status constants */ 713 #define IMM_NTFY_LIP_RESET 0x000E 714 #define IMM_NTFY_LIP_LINK_REINIT 0x000F 715 #define IMM_NTFY_IOCB_OVERFLOW 0x0016 716 #define IMM_NTFY_ABORT_TASK 0x0020 717 #define IMM_NTFY_PORT_LOGOUT 0x0029 718 #define IMM_NTFY_PORT_CONFIG 0x002A 719 #define IMM_NTFY_GLBL_TPRLO 0x002D 720 #define IMM_NTFY_GLBL_LOGO 0x002E 721 #define IMM_NTFY_RESOURCE 0x0034 722 #define IMM_NTFY_MSG_RX 0x0036 723 #define IMM_NTFY_SRR 0x0045 724 #define IMM_NTFY_ELS 0x0046 725 726 /* Immediate notify task flags */ 727 #define IMM_NTFY_TASK_MGMT_SHIFT 8 728 729 #define QLA_TGT_CLEAR_ACA 0x40 730 #define QLA_TGT_TARGET_RESET 0x20 731 #define QLA_TGT_LUN_RESET 0x10 732 #define QLA_TGT_CLEAR_TS 0x04 733 #define QLA_TGT_ABORT_TS 0x02 734 #define QLA_TGT_ABORT_ALL_SESS 0xFFFF 735 #define QLA_TGT_ABORT_ALL 0xFFFE 736 #define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD 737 #define QLA_TGT_NEXUS_LOSS 0xFFFC 738 #define QLA_TGT_ABTS 0xFFFB 739 #define QLA_TGT_2G_ABORT_TASK 0xFFFA 740 741 /* Notify Acknowledge flags */ 742 #define NOTIFY_ACK_RES_COUNT BIT_8 743 #define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5 744 #define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4 745 746 /* Command's states */ 747 #define QLA_TGT_STATE_NEW 0 /* New command + target processing */ 748 #define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */ 749 #define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */ 750 #define QLA_TGT_STATE_PROCESSED 3 /* target done processing */ 751 752 /* ATIO task_codes field */ 753 #define ATIO_SIMPLE_QUEUE 0 754 #define ATIO_HEAD_OF_QUEUE 1 755 #define ATIO_ORDERED_QUEUE 2 756 #define ATIO_ACA_QUEUE 4 757 #define ATIO_UNTAGGED 5 758 759 /* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */ 760 #define FC_TM_SUCCESS 0 761 #define FC_TM_BAD_FCP_DATA 1 762 #define FC_TM_BAD_CMD 2 763 #define FC_TM_FCP_DATA_MISMATCH 3 764 #define FC_TM_REJECT 4 765 #define FC_TM_FAILED 5 766 767 #define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \ 768 (((const uint8_t *)(sense))[0] & 0x70) == 0x70) 769 770 struct qla_port_24xx_data { 771 uint8_t port_name[WWN_SIZE]; 772 uint16_t loop_id; 773 uint16_t reserved; 774 }; 775 776 struct qla_qpair_hint { 777 struct list_head hint_elem; 778 struct qla_qpair *qpair; 779 u16 cpuid; 780 uint8_t cmd_cnt; 781 }; 782 783 struct qla_tgt { 784 struct scsi_qla_host *vha; 785 struct qla_hw_data *ha; 786 struct btree_head64 lun_qpair_map; 787 struct qla_qpair_hint *qphints; 788 /* 789 * To sync between IRQ handlers and qlt_target_release(). Needed, 790 * because req_pkt() can drop/reaquire HW lock inside. Protected by 791 * HW lock. 792 */ 793 int atio_irq_cmd_count; 794 795 int sg_tablesize; 796 797 /* Target's flags, serialized by pha->hardware_lock */ 798 unsigned int link_reinit_iocb_pending:1; 799 800 /* 801 * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex 802 * OR hardware_lock for reading. 803 */ 804 int tgt_stop; /* the target mode driver is being stopped */ 805 int tgt_stopped; /* the target mode driver has been stopped */ 806 807 /* Count of sessions refering qla_tgt. Protected by hardware_lock. */ 808 int sess_count; 809 810 /* Protected by hardware_lock */ 811 struct list_head del_sess_list; 812 813 spinlock_t sess_work_lock; 814 struct list_head sess_works_list; 815 struct work_struct sess_work; 816 817 struct imm_ntfy_from_isp link_reinit_iocb; 818 wait_queue_head_t waitQ; 819 int notify_ack_expected; 820 int abts_resp_expected; 821 int modify_lun_expected; 822 atomic_t tgt_global_resets_count; 823 struct list_head tgt_list_entry; 824 }; 825 826 struct qla_tgt_sess_op { 827 struct scsi_qla_host *vha; 828 uint32_t chip_reset; 829 struct atio_from_isp atio; 830 struct work_struct work; 831 struct list_head cmd_list; 832 bool aborted; 833 struct rsp_que *rsp; 834 }; 835 836 enum trace_flags { 837 TRC_NEW_CMD = BIT_0, 838 TRC_DO_WORK = BIT_1, 839 TRC_DO_WORK_ERR = BIT_2, 840 TRC_XFR_RDY = BIT_3, 841 TRC_XMIT_DATA = BIT_4, 842 TRC_XMIT_STATUS = BIT_5, 843 TRC_SRR_RSP = BIT_6, 844 TRC_SRR_XRDY = BIT_7, 845 TRC_SRR_TERM = BIT_8, 846 TRC_SRR_CTIO = BIT_9, 847 TRC_FLUSH = BIT_10, 848 TRC_CTIO_ERR = BIT_11, 849 TRC_CTIO_DONE = BIT_12, 850 TRC_CTIO_ABORTED = BIT_13, 851 TRC_CTIO_STRANGE = BIT_14, 852 TRC_CMD_DONE = BIT_15, 853 TRC_CMD_CHK_STOP = BIT_16, 854 TRC_CMD_FREE = BIT_17, 855 TRC_DATA_IN = BIT_18, 856 TRC_ABORT = BIT_19, 857 TRC_DIF_ERR = BIT_20, 858 }; 859 860 struct qla_tgt_cmd { 861 /* 862 * Do not move cmd_type field. it needs to line up with srb->cmd_type 863 */ 864 uint8_t cmd_type; 865 uint8_t pad[7]; 866 struct se_cmd se_cmd; 867 struct fc_port *sess; 868 struct qla_qpair *qpair; 869 uint32_t reset_count; 870 int state; 871 struct work_struct work; 872 /* Sense buffer that will be mapped into outgoing status */ 873 unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER]; 874 875 spinlock_t cmd_lock; 876 /* to save extra sess dereferences */ 877 unsigned int conf_compl_supported:1; 878 unsigned int sg_mapped:1; 879 unsigned int free_sg:1; 880 unsigned int write_data_transferred:1; 881 unsigned int q_full:1; 882 unsigned int term_exchg:1; 883 unsigned int cmd_sent_to_fw:1; 884 unsigned int cmd_in_wq:1; 885 886 /* 887 * This variable may be set from outside the LIO and I/O completion 888 * callback functions. Do not declare this member variable as a 889 * bitfield to avoid a read-modify-write operation when this variable 890 * is set. 891 */ 892 unsigned int aborted; 893 894 struct scatterlist *sg; /* cmd data buffer SG vector */ 895 int sg_cnt; /* SG segments count */ 896 int bufflen; /* cmd buffer length */ 897 int offset; 898 u64 unpacked_lun; 899 enum dma_data_direction dma_data_direction; 900 901 uint16_t ctio_flags; 902 uint16_t vp_idx; 903 uint16_t loop_id; /* to save extra sess dereferences */ 904 struct qla_tgt *tgt; /* to save extra sess dereferences */ 905 struct scsi_qla_host *vha; 906 struct list_head cmd_list; 907 908 struct atio_from_isp atio; 909 910 uint8_t ctx_dsd_alloced; 911 912 /* T10-DIF */ 913 #define DIF_ERR_NONE 0 914 #define DIF_ERR_GRD 1 915 #define DIF_ERR_REF 2 916 #define DIF_ERR_APP 3 917 int8_t dif_err_code; 918 struct scatterlist *prot_sg; 919 uint32_t prot_sg_cnt; 920 uint32_t blk_sz, num_blks; 921 uint8_t scsi_status, sense_key, asc, ascq; 922 923 struct crc_context *ctx; 924 uint8_t *cdb; 925 uint64_t lba; 926 uint16_t a_guard, e_guard, a_app_tag, e_app_tag; 927 uint32_t a_ref_tag, e_ref_tag; 928 #define DIF_BUNDL_DMA_VALID 1 929 uint16_t prot_flags; 930 931 uint64_t jiffies_at_alloc; 932 uint64_t jiffies_at_free; 933 934 enum trace_flags trc_flags; 935 }; 936 937 struct qla_tgt_sess_work_param { 938 struct list_head sess_works_list_entry; 939 940 #define QLA_TGT_SESS_WORK_ABORT 1 941 #define QLA_TGT_SESS_WORK_TM 2 942 int type; 943 944 union { 945 struct abts_recv_from_24xx abts; 946 struct imm_ntfy_from_isp tm_iocb; 947 struct atio_from_isp tm_iocb2; 948 }; 949 }; 950 951 struct qla_tgt_mgmt_cmd { 952 uint8_t cmd_type; 953 uint8_t pad[3]; 954 uint16_t tmr_func; 955 uint8_t fc_tm_rsp; 956 uint8_t abort_io_attr; 957 struct fc_port *sess; 958 struct qla_qpair *qpair; 959 struct scsi_qla_host *vha; 960 struct se_cmd se_cmd; 961 struct work_struct free_work; 962 unsigned int flags; 963 #define QLA24XX_MGMT_SEND_NACK BIT_0 964 #define QLA24XX_MGMT_ABORT_IO_ATTR_VALID BIT_1 965 uint32_t reset_count; 966 struct work_struct work; 967 uint64_t unpacked_lun; 968 union { 969 struct atio_from_isp atio; 970 struct imm_ntfy_from_isp imm_ntfy; 971 struct abts_recv_from_24xx abts; 972 } __packed orig_iocb; 973 }; 974 975 struct qla_tgt_prm { 976 struct qla_tgt_cmd *cmd; 977 struct qla_tgt *tgt; 978 void *pkt; 979 struct scatterlist *sg; /* cmd data buffer SG vector */ 980 unsigned char *sense_buffer; 981 int seg_cnt; 982 int req_cnt; 983 uint16_t rq_result; 984 int sense_buffer_len; 985 int residual; 986 int add_status_pkt; 987 /* dif */ 988 struct scatterlist *prot_sg; 989 uint16_t prot_seg_cnt; 990 uint16_t tot_dsds; 991 }; 992 993 /* Check for Switch reserved address */ 994 #define IS_SW_RESV_ADDR(_s_id) \ 995 ((_s_id.b.domain == 0xff) && ((_s_id.b.area & 0xf0) == 0xf0)) 996 997 #define QLA_TGT_XMIT_DATA 1 998 #define QLA_TGT_XMIT_STATUS 2 999 #define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA) 1000 1001 1002 extern struct qla_tgt_data qla_target; 1003 1004 /* 1005 * Function prototypes for qla_target.c logic used by qla2xxx LLD code. 1006 */ 1007 extern int qlt_add_target(struct qla_hw_data *, struct scsi_qla_host *); 1008 extern int qlt_remove_target(struct qla_hw_data *, struct scsi_qla_host *); 1009 extern int qlt_lport_register(void *, u64, u64, u64, 1010 int (*callback)(struct scsi_qla_host *, void *, u64, u64)); 1011 extern void qlt_lport_deregister(struct scsi_qla_host *); 1012 extern void qlt_unreg_sess(struct fc_port *); 1013 extern void qlt_fc_port_added(struct scsi_qla_host *, fc_port_t *); 1014 extern void qlt_fc_port_deleted(struct scsi_qla_host *, fc_port_t *, int); 1015 extern int __init qlt_init(void); 1016 extern void qlt_exit(void); 1017 extern void qlt_update_vp_map(struct scsi_qla_host *, int); 1018 extern void qlt_free_session_done(struct work_struct *); 1019 /* 1020 * This macro is used during early initializations when host->active_mode 1021 * is not set. Right now, ha value is ignored. 1022 */ 1023 #define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED) 1024 1025 extern int ql2x_ini_mode; 1026 1027 static inline bool qla_tgt_mode_enabled(struct scsi_qla_host *ha) 1028 { 1029 return ha->host->active_mode == MODE_TARGET; 1030 } 1031 1032 static inline bool qla_ini_mode_enabled(struct scsi_qla_host *ha) 1033 { 1034 return ha->host->active_mode == MODE_INITIATOR; 1035 } 1036 1037 static inline bool qla_dual_mode_enabled(struct scsi_qla_host *ha) 1038 { 1039 return (ha->host->active_mode == MODE_DUAL); 1040 } 1041 1042 static inline uint32_t sid_to_key(const uint8_t *s_id) 1043 { 1044 uint32_t key; 1045 1046 key = (((unsigned long)s_id[0] << 16) | 1047 ((unsigned long)s_id[1] << 8) | 1048 (unsigned long)s_id[2]); 1049 return key; 1050 } 1051 1052 static inline void sid_to_portid(const uint8_t *s_id, port_id_t *p) 1053 { 1054 memset(p, 0, sizeof(*p)); 1055 p->b.domain = s_id[0]; 1056 p->b.area = s_id[1]; 1057 p->b.al_pa = s_id[2]; 1058 } 1059 1060 /* 1061 * Exported symbols from qla_target.c LLD logic used by qla2xxx code.. 1062 */ 1063 extern void qlt_response_pkt_all_vps(struct scsi_qla_host *, struct rsp_que *, 1064 response_t *); 1065 extern int qlt_rdy_to_xfer(struct qla_tgt_cmd *); 1066 extern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t); 1067 extern int qlt_abort_cmd(struct qla_tgt_cmd *); 1068 extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *); 1069 extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *); 1070 extern void qlt_free_cmd(struct qla_tgt_cmd *cmd); 1071 extern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *); 1072 extern void qlt_enable_vha(struct scsi_qla_host *); 1073 extern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *); 1074 extern u8 qlt_rff_id(struct scsi_qla_host *); 1075 extern void qlt_init_atio_q_entries(struct scsi_qla_host *); 1076 extern void qlt_24xx_process_atio_queue(struct scsi_qla_host *, uint8_t); 1077 extern void qlt_24xx_config_rings(struct scsi_qla_host *); 1078 extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host *, 1079 struct nvram_24xx *); 1080 extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host *, 1081 struct init_cb_24xx *); 1082 extern void qlt_81xx_config_nvram_stage2(struct scsi_qla_host *, 1083 struct init_cb_81xx *); 1084 extern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host *, 1085 struct nvram_81xx *); 1086 extern int qlt_24xx_process_response_error(struct scsi_qla_host *, 1087 struct sts_entry_24xx *); 1088 extern void qlt_modify_vp_config(struct scsi_qla_host *, 1089 struct vp_config_entry_24xx *); 1090 extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *); 1091 extern int qlt_mem_alloc(struct qla_hw_data *); 1092 extern void qlt_mem_free(struct qla_hw_data *); 1093 extern int qlt_stop_phase1(struct qla_tgt *); 1094 extern void qlt_stop_phase2(struct qla_tgt *); 1095 extern irqreturn_t qla83xx_msix_atio_q(int, void *); 1096 extern void qlt_83xx_iospace_config(struct qla_hw_data *); 1097 extern int qlt_free_qfull_cmds(struct qla_qpair *); 1098 extern void qlt_logo_completion_handler(fc_port_t *, int); 1099 extern void qlt_do_generation_tick(struct scsi_qla_host *, int *); 1100 1101 void qlt_send_resp_ctio(struct qla_qpair *, struct qla_tgt_cmd *, uint8_t, 1102 uint8_t, uint8_t, uint8_t); 1103 1104 #endif /* __QLA_TARGET_H */ 1105