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.
7 * Forward port and refactoring to modern qla2xxx and target/configfs
9 * Copyright (C) 2010-2011 Nicholas A. Bellinger <nab@kernel.org>
11 * Additional file for the target driver support.
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.
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.
24 * This is the global def file that is useful for including from the
28 #ifndef __QLA_TARGET_H
29 #define __QLA_TARGET_H
34 * Must be changed on any change in any initiator visible interfaces or
35 * data in the target add-on
37 #define QLA2XXX_TARGET_MAGIC 269
40 * Must be changed on any change in any target visible interfaces or
41 * data in the initiator
43 #define QLA2XXX_INITIATOR_MAGIC 57222
45 #define QLA2XXX_INI_MODE_STR_EXCLUSIVE "exclusive"
46 #define QLA2XXX_INI_MODE_STR_DISABLED "disabled"
47 #define QLA2XXX_INI_MODE_STR_ENABLED "enabled"
49 #define QLA2XXX_INI_MODE_EXCLUSIVE 0
50 #define QLA2XXX_INI_MODE_DISABLED 1
51 #define QLA2XXX_INI_MODE_ENABLED 2
53 #define QLA2XXX_COMMAND_COUNT_INIT 250
54 #define QLA2XXX_IMMED_NOTIFY_COUNT_INIT 250
57 * Used to mark which completion handles (for RIO Status's) are for CTIO's
58 * vs. regular (non-target) info. This is checked for in
59 * qla2x00_process_response_queue() to see if a handle coming back in a
60 * multi-complete should come to the tgt driver or be handled there by qla2xxx
62 #define CTIO_COMPLETION_HANDLE_MARK BIT_29
63 #if (CTIO_COMPLETION_HANDLE_MARK <= DEFAULT_OUTSTANDING_COMMANDS)
64 #error "CTIO_COMPLETION_HANDLE_MARK not larger than "
65 "DEFAULT_OUTSTANDING_COMMANDS"
67 #define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK)
69 /* Used to mark CTIO as intermediate */
70 #define CTIO_INTERMEDIATE_HANDLE_MARK BIT_30
74 * ISP target entries - Flags bit definitions.
76 #define OF_SS_MODE_0 0
77 #define OF_SS_MODE_1 1
78 #define OF_SS_MODE_2 2
79 #define OF_SS_MODE_3 3
81 #define OF_EXPL_CONF BIT_5 /* Explicit Confirmation Requested */
82 #define OF_DATA_IN BIT_6 /* Data in to initiator */
83 /* (data from target to initiator) */
84 #define OF_DATA_OUT BIT_7 /* Data out from initiator */
85 /* (data from initiator to target) */
86 #define OF_NO_DATA (BIT_7 | BIT_6)
87 #define OF_INC_RC BIT_8 /* Increment command resource count */
88 #define OF_FAST_POST BIT_9 /* Enable mailbox fast posting. */
89 #define OF_CONF_REQ BIT_13 /* Confirmation Requested */
90 #define OF_TERM_EXCH BIT_14 /* Terminate exchange */
91 #define OF_SSTS BIT_15 /* Send SCSI status */
94 #ifndef QLA_TGT_DATASEGS_PER_CMD32
95 #define QLA_TGT_DATASEGS_PER_CMD32 3
96 #define QLA_TGT_DATASEGS_PER_CONT32 7
97 #define QLA_TGT_MAX_SG32(ql) \
98 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \
99 QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0)
101 #define QLA_TGT_DATASEGS_PER_CMD64 2
102 #define QLA_TGT_DATASEGS_PER_CONT64 5
103 #define QLA_TGT_MAX_SG64(ql) \
104 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \
105 QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0)
108 #ifndef QLA_TGT_DATASEGS_PER_CMD_24XX
109 #define QLA_TGT_DATASEGS_PER_CMD_24XX 1
110 #define QLA_TGT_DATASEGS_PER_CONT_24XX 5
111 #define QLA_TGT_MAX_SG_24XX(ql) \
112 (min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \
113 QLA_TGT_DATASEGS_PER_CONT_24XX*((ql) - 1)) : 0))
116 #define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha)) \
117 ? le16_to_cpu((iocb)->u.isp2x.target.extended) \
118 : (uint16_t)(iocb)->u.isp2x.target.id.standard)
120 #ifndef IMMED_NOTIFY_TYPE
121 #define IMMED_NOTIFY_TYPE 0x0D /* Immediate notify entry. */
123 * ISP queue - immediate notify entry structure definition.
124 * This is sent by the ISP to the Target driver.
125 * This IOCB would have report of events sent by the
126 * initiator, that needs to be handled by the target
127 * driver immediately.
129 struct imm_ntfy_from_isp {
130 uint8_t entry_type; /* Entry type. */
131 uint8_t entry_count; /* Entry count. */
132 uint8_t sys_define; /* System defined. */
133 uint8_t entry_status; /* Entry Status. */
136 uint32_t sys_define_2; /* System defined. */
141 uint16_t status_modifier;
146 uint32_t srr_rel_offs;
148 #define SRR_IU_DATA_IN 0x1
149 #define SRR_IU_DATA_OUT 0x5
150 #define SRR_IU_STATUS 0x7
152 uint8_t reserved_2[28];
156 uint16_t nport_handle;
159 #define NOTIFY24XX_FLAGS_GLOBAL_TPRLO BIT_1
160 #define NOTIFY24XX_FLAGS_PUREX_IOCB BIT_0
163 uint8_t status_subcode;
165 uint32_t exchange_address;
166 uint32_t srr_rel_offs;
171 uint8_t node_name[8];
172 } plogi; /* PLOGI/ADISC/PDISC */
174 /* PRLI word 3 bit 0-15 */
181 uint16_t nport_handle;
185 uint8_t port_name[8];
198 #ifndef NOTIFY_ACK_TYPE
199 #define NOTIFY_ACK_TYPE 0x0E /* Notify acknowledge entry. */
201 * ISP queue - notify acknowledge entry structure definition.
202 * This is sent to the ISP from the target driver.
205 uint8_t entry_type; /* Entry type. */
206 uint8_t entry_count; /* Entry count. */
207 uint8_t sys_define; /* System defined. */
208 uint8_t entry_status; /* Entry Status. */
211 uint32_t sys_define_2; /* System defined. */
221 uint32_t srr_rel_offs;
224 uint16_t srr_reject_code;
225 uint8_t srr_reject_vendor_uniq;
226 uint8_t srr_reject_code_expl;
227 uint8_t reserved_2[24];
231 uint16_t nport_handle;
236 uint8_t status_subcode;
238 uint32_t exchange_address;
239 uint32_t srr_rel_offs;
242 uint8_t reserved_4[19];
244 uint8_t srr_reject_vendor_uniq;
245 uint8_t srr_reject_code_expl;
246 uint8_t srr_reject_code;
247 uint8_t reserved_5[5];
253 #define NOTIFY_ACK_FLAGS_TERMINATE BIT_3
254 #define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0
255 #define NOTIFY_ACK_SRR_FLAGS_REJECT 1
257 #define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9
259 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0
260 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a
262 #define NOTIFY_ACK_SUCCESS 0x01
265 #ifndef ACCEPT_TGT_IO_TYPE
266 #define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */
269 #ifndef CONTINUE_TGT_IO_TYPE
270 #define CONTINUE_TGT_IO_TYPE 0x17
272 * ISP queue - Continue Target I/O (CTIO) entry for status mode 0 structure.
273 * This structure is sent to the ISP 2xxx from target driver.
275 struct ctio_to_2xxx {
276 uint8_t entry_type; /* Entry type. */
277 uint8_t entry_count; /* Entry count. */
278 uint8_t sys_define; /* System defined. */
279 uint8_t entry_status; /* Entry Status. */
280 uint32_t handle; /* System defined handle */
285 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */
286 uint16_t dseg_count; /* Data segment count. */
287 uint32_t relative_offset;
289 uint16_t reserved_1[3];
290 uint16_t scsi_status;
291 uint32_t transfer_length;
292 uint32_t dseg_0_address; /* Data segment 0 address. */
293 uint32_t dseg_0_length; /* Data segment 0 length. */
294 uint32_t dseg_1_address; /* Data segment 1 address. */
295 uint32_t dseg_1_length; /* Data segment 1 length. */
296 uint32_t dseg_2_address; /* Data segment 2 address. */
297 uint32_t dseg_2_length; /* Data segment 2 length. */
299 #define ATIO_PATH_INVALID 0x07
300 #define ATIO_CANT_PROV_CAP 0x16
301 #define ATIO_CDB_VALID 0x3D
303 #define ATIO_EXEC_READ BIT_1
304 #define ATIO_EXEC_WRITE BIT_0
307 #ifndef CTIO_A64_TYPE
308 #define CTIO_A64_TYPE 0x1F
309 #define CTIO_SUCCESS 0x01
310 #define CTIO_ABORTED 0x02
311 #define CTIO_INVALID_RX_ID 0x08
312 #define CTIO_TIMEOUT 0x0B
313 #define CTIO_DIF_ERROR 0x0C /* DIF error detected */
314 #define CTIO_LIP_RESET 0x0E
315 #define CTIO_TARGET_RESET 0x17
316 #define CTIO_PORT_UNAVAILABLE 0x28
317 #define CTIO_PORT_LOGGED_OUT 0x29
318 #define CTIO_PORT_CONF_CHANGED 0x2A
319 #define CTIO_SRR_RECEIVED 0x45
322 #ifndef CTIO_RET_TYPE
323 #define CTIO_RET_TYPE 0x17 /* CTIO return entry */
324 #define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */
357 #define F_CTL_EXCH_CONTEXT_RESP BIT_23
358 #define F_CTL_SEQ_CONTEXT_RESIP BIT_22
359 #define F_CTL_LAST_SEQ BIT_20
360 #define F_CTL_END_SEQ BIT_19
361 #define F_CTL_SEQ_INITIATIVE BIT_16
363 #define R_CTL_BASIC_LINK_SERV 0x80
364 #define R_CTL_B_ACC 0x4
365 #define R_CTL_B_RJT 0x5
367 struct atio7_fcp_cmnd {
372 uint8_t task_mgmt_flags;
373 #define FCP_CMND_TASK_MGMT_CLEAR_ACA 6
374 #define FCP_CMND_TASK_MGMT_TARGET_RESET 5
375 #define FCP_CMND_TASK_MGMT_LU_RESET 4
376 #define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2
377 #define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1
380 uint8_t add_cdb_len:6;
383 * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4
384 * only to make sizeof(struct atio7_fcp_cmnd) be as expected by
385 * BUILD_BUG_ON in qlt_init().
388 /* uint32_t data_length; */
392 * ISP queue - Accept Target I/O (ATIO) type entry IOCB structure.
393 * This is sent from the ISP to the target driver.
395 struct atio_from_isp {
399 uint8_t sys_define; /* System defined. */
400 uint8_t entry_status; /* Entry Status. */
401 uint32_t sys_define_2; /* System defined. */
409 uint8_t execution_codes;
410 uint8_t cdb[MAX_CMDSZ];
411 uint32_t data_length;
413 uint8_t initiator_port_name[WWN_SIZE]; /* on qla23xx */
414 uint16_t reserved_32[6];
419 uint8_t fcp_cmnd_len_low;
420 uint8_t fcp_cmnd_len_high:4;
422 uint32_t exchange_addr;
423 #define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF
424 struct fcp_hdr fcp_hdr;
425 struct atio7_fcp_cmnd fcp_cmnd;
428 uint8_t entry_type; /* Entry type. */
429 uint8_t entry_count; /* Entry count. */
430 __le16 attr_n_length;
431 #define FCP_CMD_LENGTH_MASK 0x0fff
432 #define FCP_CMD_LENGTH_MIN 0x38
435 #define ATIO_PROCESSED 0xDEADDEAD /* Signature */
440 static inline int fcpcmd_is_corrupted(struct atio *atio)
442 if (atio->entry_type == ATIO_TYPE7 &&
443 ((le16_to_cpu(atio->attr_n_length) & FCP_CMD_LENGTH_MASK) <
450 /* adjust corrupted atio so we won't trip over the same entry again. */
451 static inline void adjust_corrupted_atio(struct atio_from_isp *atio)
453 atio->u.raw.attr_n_length = cpu_to_le16(FCP_CMD_LENGTH_MIN);
454 atio->u.isp24.fcp_cmnd.add_cdb_len = 0;
457 #define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */
460 * ISP queue - Continue Target I/O (ATIO) type 7 entry (for 24xx) structure.
461 * This structure is sent to the ISP 24xx from the target driver.
464 struct ctio7_to_24xx {
465 uint8_t entry_type; /* Entry type. */
466 uint8_t entry_count; /* Entry count. */
467 uint8_t sys_define; /* System defined. */
468 uint8_t entry_status; /* Entry Status. */
469 uint32_t handle; /* System defined handle */
470 uint16_t nport_handle;
471 #define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF
473 uint16_t dseg_count; /* Data segment count. */
476 uint8_t initiator_id[3];
478 uint32_t exchange_addr;
485 uint16_t scsi_status;
486 uint32_t relative_offset;
488 uint32_t transfer_length;
490 /* Data segment 0 address. */
491 uint32_t dseg_0_address[2];
492 /* Data segment 0 length. */
493 uint32_t dseg_0_length;
496 uint16_t sense_length;
500 uint16_t scsi_status;
501 uint16_t response_len;
503 uint8_t sense_data[24];
509 * ISP queue - CTIO type 7 from ISP 24xx to target driver
510 * returned entry structure.
512 struct ctio7_from_24xx {
513 uint8_t entry_type; /* Entry type. */
514 uint8_t entry_count; /* Entry count. */
515 uint8_t sys_define; /* System defined. */
516 uint8_t entry_status; /* Entry Status. */
517 uint32_t handle; /* System defined handle */
520 uint16_t dseg_count; /* Data segment count. */
522 uint8_t reserved1[5];
523 uint32_t exchange_address;
529 uint32_t relative_offset;
530 uint8_t reserved4[24];
533 /* CTIO7 flags values */
534 #define CTIO7_FLAGS_SEND_STATUS BIT_15
535 #define CTIO7_FLAGS_TERMINATE BIT_14
536 #define CTIO7_FLAGS_CONFORM_REQ BIT_13
537 #define CTIO7_FLAGS_DONT_RET_CTIO BIT_8
538 #define CTIO7_FLAGS_STATUS_MODE_0 0
539 #define CTIO7_FLAGS_STATUS_MODE_1 BIT_6
540 #define CTIO7_FLAGS_STATUS_MODE_2 BIT_7
541 #define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5
542 #define CTIO7_FLAGS_CONFIRM_SATISF BIT_4
543 #define CTIO7_FLAGS_DSD_PTR BIT_2
544 #define CTIO7_FLAGS_DATA_IN BIT_1 /* data to initiator */
545 #define CTIO7_FLAGS_DATA_OUT BIT_0 /* data from initiator */
547 #define ELS_PLOGI 0x3
548 #define ELS_FLOGI 0x4
550 #define ELS_PRLI 0x20
551 #define ELS_PRLO 0x21
552 #define ELS_TPRLO 0x24
553 #define ELS_PDISC 0x50
554 #define ELS_ADISC 0x52
557 *CTIO Type CRC_2 IOCB
559 struct ctio_crc2_to_fw {
560 uint8_t entry_type; /* Entry type. */
561 #define CTIO_CRC2 0x7A
562 uint8_t entry_count; /* Entry count. */
563 uint8_t sys_define; /* System defined. */
564 uint8_t entry_status; /* Entry Status. */
566 uint32_t handle; /* System handle. */
567 uint16_t nport_handle; /* N_PORT handle. */
568 __le16 timeout; /* Command timeout. */
570 uint16_t dseg_count; /* Data segment count. */
572 uint8_t add_flags; /* additional flags */
573 #define CTIO_CRC2_AF_DIF_DSD_ENA BIT_3
575 uint8_t initiator_id[3]; /* initiator ID */
577 uint32_t exchange_addr; /* rcv exchange address */
579 __le16 flags; /* refer to CTIO7 flags values */
582 uint16_t scsi_status;
583 __le32 relative_offset;
585 __le32 transfer_length; /* total fc transfer length */
587 __le32 crc_context_address[2];/* Data segment address. */
588 uint16_t crc_context_len; /* Data segment length. */
589 uint16_t reserved_1; /* MUST be set to 0. */
592 /* CTIO Type CRC_x Status IOCB */
593 struct ctio_crc_from_fw {
594 uint8_t entry_type; /* Entry type. */
595 uint8_t entry_count; /* Entry count. */
596 uint8_t sys_define; /* System defined. */
597 uint8_t entry_status; /* Entry Status. */
599 uint32_t handle; /* System handle. */
601 uint16_t timeout; /* Command timeout. */
602 uint16_t dseg_count; /* Data segment count. */
604 uint16_t state_flags;
605 #define CTIO_CRC_SF_DIF_CHOPPED BIT_4
607 uint32_t exchange_address; /* rcv exchange address */
610 uint32_t resid_xfer_length;
612 uint8_t reserved3[12];
613 uint16_t runt_guard; /* reported runt blk guard */
614 uint8_t actual_dif[8];
615 uint8_t expected_dif[8];
619 * ISP queue - ABTS received/response entries structure definition for 24xx.
621 #define ABTS_RECV_24XX 0x54 /* ABTS received (for 24xx) */
622 #define ABTS_RESP_24XX 0x55 /* ABTS responce (for 24xx) */
625 * ISP queue - ABTS received IOCB entry structure definition for 24xx.
626 * The ABTS BLS received from the wire is sent to the
627 * target driver by the ISP 24xx.
628 * The IOCB is placed on the response queue.
630 struct abts_recv_from_24xx {
631 uint8_t entry_type; /* Entry type. */
632 uint8_t entry_count; /* Entry count. */
633 uint8_t sys_define; /* System defined. */
634 uint8_t entry_status; /* Entry Status. */
635 uint8_t reserved_1[6];
636 uint16_t nport_handle;
637 uint8_t reserved_2[2];
639 uint8_t reserved_3:4;
641 uint32_t exchange_address;
642 struct fcp_hdr_le fcp_hdr_le;
643 uint8_t reserved_4[16];
644 uint32_t exchange_addr_to_abort;
647 #define ABTS_PARAM_ABORT_SEQ BIT_0
652 uint8_t seq_id_valid;
653 #define SEQ_ID_VALID 0x80
654 #define SEQ_ID_INVALID 0x00
657 uint16_t high_seq_cnt;
658 uint16_t low_seq_cnt;
665 #define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1
666 #define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9
671 * ISP queue - ABTS Response IOCB entry structure definition for 24xx.
672 * The ABTS response to the ABTS received is sent by the
673 * target driver to the ISP 24xx.
674 * The IOCB is placed on the request queue.
676 struct abts_resp_to_24xx {
677 uint8_t entry_type; /* Entry type. */
678 uint8_t entry_count; /* Entry count. */
679 uint8_t sys_define; /* System defined. */
680 uint8_t entry_status; /* Entry Status. */
683 uint16_t nport_handle;
684 uint16_t control_flags;
685 #define ABTS_CONTR_FLG_TERM_EXCHG BIT_0
687 uint8_t reserved_3:4;
689 uint32_t exchange_address;
690 struct fcp_hdr_le fcp_hdr_le;
692 struct ba_acc_le ba_acct;
693 struct ba_rjt_le ba_rjt;
696 uint32_t exchange_addr_to_abort;
700 * ISP queue - ABTS Response IOCB from ISP24xx Firmware entry structure.
701 * The ABTS response with completion status to the ABTS response
702 * (sent by the target driver to the ISP 24xx) is sent by the
703 * ISP24xx firmware to the target driver.
704 * The IOCB is placed on the response queue.
706 struct abts_resp_from_24xx_fw {
707 uint8_t entry_type; /* Entry type. */
708 uint8_t entry_count; /* Entry count. */
709 uint8_t sys_define; /* System defined. */
710 uint8_t entry_status; /* Entry Status. */
712 uint16_t compl_status;
713 #define ABTS_RESP_COMPL_SUCCESS 0
714 #define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31
715 uint16_t nport_handle;
718 uint8_t reserved_3:4;
720 uint32_t exchange_address;
721 struct fcp_hdr_le fcp_hdr_le;
722 uint8_t reserved_4[8];
723 uint32_t error_subcode1;
724 #define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E
725 uint32_t error_subcode2;
726 uint32_t exchange_addr_to_abort;
729 /********************************************************************\
730 * Type Definitions used by initiator & target halves
731 \********************************************************************/
733 struct qla_tgt_mgmt_cmd;
737 * This structure provides a template of function calls that the
738 * target driver (from within qla_target.c) can issue to the
739 * target module (tcm_qla2xxx).
741 struct qla_tgt_func_tmpl {
743 int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *,
744 unsigned char *, uint32_t, int, int, int);
745 void (*handle_data)(struct qla_tgt_cmd *);
746 void (*handle_dif_err)(struct qla_tgt_cmd *);
747 int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, uint32_t, uint8_t,
749 void (*free_cmd)(struct qla_tgt_cmd *);
750 void (*free_mcmd)(struct qla_tgt_mgmt_cmd *);
751 void (*free_session)(struct qla_tgt_sess *);
753 int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *,
754 struct qla_tgt_sess *);
755 void (*update_sess)(struct qla_tgt_sess *, port_id_t, uint16_t, bool);
756 struct qla_tgt_sess *(*find_sess_by_loop_id)(struct scsi_qla_host *,
758 struct qla_tgt_sess *(*find_sess_by_s_id)(struct scsi_qla_host *,
760 void (*clear_nacl_from_fcport_map)(struct qla_tgt_sess *);
761 void (*shutdown_sess)(struct qla_tgt_sess *);
764 int qla2x00_wait_for_hba_online(struct scsi_qla_host *);
766 #include <target/target_core_base.h>
768 #define QLA_TGT_TIMEOUT 10 /* in seconds */
770 #define QLA_TGT_MAX_HW_PENDING_TIME 60 /* in seconds */
772 /* Immediate notify status constants */
773 #define IMM_NTFY_LIP_RESET 0x000E
774 #define IMM_NTFY_LIP_LINK_REINIT 0x000F
775 #define IMM_NTFY_IOCB_OVERFLOW 0x0016
776 #define IMM_NTFY_ABORT_TASK 0x0020
777 #define IMM_NTFY_PORT_LOGOUT 0x0029
778 #define IMM_NTFY_PORT_CONFIG 0x002A
779 #define IMM_NTFY_GLBL_TPRLO 0x002D
780 #define IMM_NTFY_GLBL_LOGO 0x002E
781 #define IMM_NTFY_RESOURCE 0x0034
782 #define IMM_NTFY_MSG_RX 0x0036
783 #define IMM_NTFY_SRR 0x0045
784 #define IMM_NTFY_ELS 0x0046
786 /* Immediate notify task flags */
787 #define IMM_NTFY_TASK_MGMT_SHIFT 8
789 #define QLA_TGT_CLEAR_ACA 0x40
790 #define QLA_TGT_TARGET_RESET 0x20
791 #define QLA_TGT_LUN_RESET 0x10
792 #define QLA_TGT_CLEAR_TS 0x04
793 #define QLA_TGT_ABORT_TS 0x02
794 #define QLA_TGT_ABORT_ALL_SESS 0xFFFF
795 #define QLA_TGT_ABORT_ALL 0xFFFE
796 #define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD
797 #define QLA_TGT_NEXUS_LOSS 0xFFFC
799 /* Notify Acknowledge flags */
800 #define NOTIFY_ACK_RES_COUNT BIT_8
801 #define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5
802 #define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
804 /* Command's states */
805 #define QLA_TGT_STATE_NEW 0 /* New command + target processing */
806 #define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */
807 #define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */
808 #define QLA_TGT_STATE_PROCESSED 3 /* target done processing */
811 /* Special handles */
812 #define QLA_TGT_NULL_HANDLE 0
813 #define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~CTIO_COMPLETION_HANDLE_MARK)
815 /* ATIO task_codes field */
816 #define ATIO_SIMPLE_QUEUE 0
817 #define ATIO_HEAD_OF_QUEUE 1
818 #define ATIO_ORDERED_QUEUE 2
819 #define ATIO_ACA_QUEUE 4
820 #define ATIO_UNTAGGED 5
822 /* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */
823 #define FC_TM_SUCCESS 0
824 #define FC_TM_BAD_FCP_DATA 1
825 #define FC_TM_BAD_CMD 2
826 #define FC_TM_FCP_DATA_MISMATCH 3
827 #define FC_TM_REJECT 4
828 #define FC_TM_FAILED 5
830 #if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
831 #define pci_dma_lo32(a) (a & 0xffffffff)
832 #define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff)
834 #define pci_dma_lo32(a) (a & 0xffffffff)
835 #define pci_dma_hi32(a) 0
838 #define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \
839 (((const uint8_t *)(sense))[0] & 0x70) == 0x70)
841 struct qla_port_24xx_data {
842 uint8_t port_name[WWN_SIZE];
848 struct scsi_qla_host *vha;
849 struct qla_hw_data *ha;
852 * To sync between IRQ handlers and qlt_target_release(). Needed,
853 * because req_pkt() can drop/reaquire HW lock inside. Protected by
857 int atio_irq_cmd_count;
859 int datasegs_per_cmd, datasegs_per_cont, sg_tablesize;
861 /* Target's flags, serialized by pha->hardware_lock */
862 unsigned int tgt_enable_64bit_addr:1; /* 64-bits PCI addr enabled */
863 unsigned int link_reinit_iocb_pending:1;
866 * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex
867 * OR hardware_lock for reading.
869 int tgt_stop; /* the target mode driver is being stopped */
870 int tgt_stopped; /* the target mode driver has been stopped */
872 /* Count of sessions refering qla_tgt. Protected by hardware_lock. */
875 /* Protected by hardware_lock. Addition also protected by tgt_mutex. */
876 struct list_head sess_list;
878 /* Protected by hardware_lock */
879 struct list_head del_sess_list;
880 struct delayed_work sess_del_work;
882 spinlock_t sess_work_lock;
883 struct list_head sess_works_list;
884 struct work_struct sess_work;
886 struct imm_ntfy_from_isp link_reinit_iocb;
887 wait_queue_head_t waitQ;
888 int notify_ack_expected;
889 int abts_resp_expected;
890 int modify_lun_expected;
895 struct list_head srr_ctio_list;
896 struct list_head srr_imm_list;
897 struct work_struct srr_work;
899 atomic_t tgt_global_resets_count;
901 struct list_head tgt_list_entry;
904 struct qla_tgt_sess_op {
905 struct scsi_qla_host *vha;
907 struct atio_from_isp atio;
908 struct work_struct work;
909 struct list_head cmd_list;
913 enum qla_sess_deletion {
914 QLA_SESS_DELETION_NONE = 0,
915 QLA_SESS_DELETION_PENDING = 1, /* hopefully we can get rid of
917 QLA_SESS_DELETION_IN_PROGRESS = 2,
921 QLT_PLOGI_LINK_SAME_WWN,
922 QLT_PLOGI_LINK_CONFLICT,
927 struct list_head list;
928 struct imm_ntfy_from_isp iocb;
934 * Equivilant to IT Nexus (Initiator-Target)
936 struct qla_tgt_sess {
940 unsigned int conf_compl_supported:1;
941 unsigned int deleted:2;
942 unsigned int local:1;
943 unsigned int logout_on_delete:1;
944 unsigned int keep_nport_handle:1;
945 unsigned int send_els_logo:1;
947 unsigned char logout_completed;
951 struct se_session *se_sess;
952 struct kref sess_kref;
953 struct scsi_qla_host *vha;
956 struct list_head sess_list_entry;
957 unsigned long expires;
958 struct list_head del_list_entry;
960 uint8_t port_name[WWN_SIZE];
961 struct work_struct free_work;
963 qlt_plogi_ack_t *plogi_link[QLT_PLOGI_LINK_MAX];
968 * BIT_0 - Atio Arrival / schedule to work
969 * BIT_1 - qlt_do_work
970 * BIT_2 - qlt_do work failed
971 * BIT_3 - xfer rdy/tcm_qla2xxx_write_pending
972 * BIT_4 - read respond/tcm_qla2xx_queue_data_in
973 * BIT_5 - status respond / tcm_qla2xx_queue_status
974 * BIT_6 - tcm request to abort/Term exchange.
975 * pre_xmit_response->qlt_send_term_exchange
976 * BIT_7 - SRR received (qlt_handle_srr->qlt_xmit_response)
977 * BIT_8 - SRR received (qlt_handle_srr->qlt_rdy_to_xfer)
978 * BIT_9 - SRR received (qla_handle_srr->qlt_send_term_exchange)
979 * BIT_10 - Data in - hanlde_data->tcm_qla2xxx_handle_data
981 * BIT_12 - good completion - qlt_ctio_do_completion -->free_cmd
982 * BIT_13 - Bad completion -
983 * qlt_ctio_do_completion --> qlt_term_ctio_exchange
984 * BIT_14 - Back end data received/sent.
985 * BIT_15 - SRR prepare ctio
986 * BIT_16 - complete free
987 * BIT_17 - flush - qlt_abort_cmd_on_host_reset
988 * BIT_18 - completion w/abort status
989 * BIT_19 - completion w/unknown status
990 * BIT_20 - tcm_qla2xxx_free_cmd
992 CMD_FLAG_DATA_WORK = BIT_11,
993 CMD_FLAG_DATA_WORK_FREE = BIT_21,
997 struct se_cmd se_cmd;
998 struct qla_tgt_sess *sess;
1000 struct work_struct free_work;
1001 struct work_struct work;
1002 /* Sense buffer that will be mapped into outgoing status */
1003 unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
1005 spinlock_t cmd_lock;
1006 /* to save extra sess dereferences */
1007 unsigned int conf_compl_supported:1;
1008 unsigned int sg_mapped:1;
1009 unsigned int free_sg:1;
1010 unsigned int write_data_transferred:1;
1011 unsigned int ctx_dsd_alloced:1;
1012 unsigned int q_full:1;
1013 unsigned int term_exchg:1;
1014 unsigned int cmd_sent_to_fw:1;
1015 unsigned int cmd_in_wq:1;
1016 unsigned int aborted:1;
1018 struct scatterlist *sg; /* cmd data buffer SG vector */
1019 int sg_cnt; /* SG segments count */
1020 int bufflen; /* cmd buffer length */
1022 uint32_t unpacked_lun;
1023 enum dma_data_direction dma_data_direction;
1024 uint32_t reset_count;
1026 uint16_t loop_id; /* to save extra sess dereferences */
1027 struct qla_tgt *tgt; /* to save extra sess dereferences */
1028 struct scsi_qla_host *vha;
1029 struct list_head cmd_list;
1031 struct atio_from_isp atio;
1033 struct scatterlist *prot_sg;
1034 uint32_t prot_sg_cnt;
1036 struct crc_context *ctx;
1038 uint64_t jiffies_at_alloc;
1039 uint64_t jiffies_at_free;
1041 cmd_flags_t cmd_flags;
1044 struct qla_tgt_sess_work_param {
1045 struct list_head sess_works_list_entry;
1047 #define QLA_TGT_SESS_WORK_ABORT 1
1048 #define QLA_TGT_SESS_WORK_TM 2
1052 struct abts_recv_from_24xx abts;
1053 struct imm_ntfy_from_isp tm_iocb;
1054 struct atio_from_isp tm_iocb2;
1058 struct qla_tgt_mgmt_cmd {
1061 struct qla_tgt_sess *sess;
1062 struct se_cmd se_cmd;
1063 struct work_struct free_work;
1065 uint32_t reset_count;
1066 #define QLA24XX_MGMT_SEND_NACK 1
1068 struct atio_from_isp atio;
1069 struct imm_ntfy_from_isp imm_ntfy;
1070 struct abts_recv_from_24xx abts;
1071 } __packed orig_iocb;
1074 struct qla_tgt_prm {
1075 struct qla_tgt_cmd *cmd;
1076 struct qla_tgt *tgt;
1078 struct scatterlist *sg; /* cmd data buffer SG vector */
1079 unsigned char *sense_buffer;
1083 uint16_t scsi_status;
1084 int sense_buffer_len;
1088 struct scatterlist *prot_sg;
1089 uint16_t prot_seg_cnt;
1093 struct qla_tgt_srr_imm {
1094 struct list_head srr_list_entry;
1096 struct imm_ntfy_from_isp imm_ntfy;
1099 struct qla_tgt_srr_ctio {
1100 struct list_head srr_list_entry;
1102 struct qla_tgt_cmd *cmd;
1105 /* Check for Switch reserved address */
1106 #define IS_SW_RESV_ADDR(_s_id) \
1107 ((_s_id.b.domain == 0xff) && (_s_id.b.area == 0xfc))
1109 #define QLA_TGT_XMIT_DATA 1
1110 #define QLA_TGT_XMIT_STATUS 2
1111 #define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA)
1114 extern struct qla_tgt_data qla_target;
1117 * Function prototypes for qla_target.c logic used by qla2xxx LLD code.
1119 extern int qlt_add_target(struct qla_hw_data *, struct scsi_qla_host *);
1120 extern int qlt_remove_target(struct qla_hw_data *, struct scsi_qla_host *);
1121 extern int qlt_lport_register(void *, u64, u64, u64,
1122 int (*callback)(struct scsi_qla_host *, void *, u64, u64));
1123 extern void qlt_lport_deregister(struct scsi_qla_host *);
1124 void qlt_put_sess(struct qla_tgt_sess *sess);
1125 extern void qlt_fc_port_added(struct scsi_qla_host *, fc_port_t *);
1126 extern void qlt_fc_port_deleted(struct scsi_qla_host *, fc_port_t *, int);
1127 extern int __init qlt_init(void);
1128 extern void qlt_exit(void);
1129 extern void qlt_update_vp_map(struct scsi_qla_host *, int);
1132 * This macro is used during early initializations when host->active_mode
1133 * is not set. Right now, ha value is ignored.
1135 #define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED)
1136 extern int ql2x_ini_mode;
1138 static inline bool qla_tgt_mode_enabled(struct scsi_qla_host *ha)
1140 return ha->host->active_mode & MODE_TARGET;
1143 static inline bool qla_ini_mode_enabled(struct scsi_qla_host *ha)
1145 return ha->host->active_mode & MODE_INITIATOR;
1148 static inline void qla_reverse_ini_mode(struct scsi_qla_host *ha)
1150 if (ha->host->active_mode & MODE_INITIATOR)
1151 ha->host->active_mode &= ~MODE_INITIATOR;
1153 ha->host->active_mode |= MODE_INITIATOR;
1156 static inline uint32_t sid_to_key(const uint8_t *s_id)
1160 key = (((unsigned long)s_id[0] << 16) |
1161 ((unsigned long)s_id[1] << 8) |
1162 (unsigned long)s_id[2]);
1166 static inline void sid_to_portid(const uint8_t *s_id, port_id_t *p)
1168 memset(p, 0, sizeof(*p));
1169 p->b.domain = s_id[0];
1170 p->b.area = s_id[1];
1171 p->b.al_pa = s_id[2];
1175 * Exported symbols from qla_target.c LLD logic used by qla2xxx code..
1177 extern void qlt_response_pkt_all_vps(struct scsi_qla_host *, response_t *);
1178 extern int qlt_rdy_to_xfer(struct qla_tgt_cmd *);
1179 extern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t);
1180 extern int qlt_abort_cmd(struct qla_tgt_cmd *);
1181 extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *);
1182 extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *);
1183 extern void qlt_free_cmd(struct qla_tgt_cmd *cmd);
1184 extern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *);
1185 extern void qlt_enable_vha(struct scsi_qla_host *);
1186 extern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *);
1187 extern void qlt_rff_id(struct scsi_qla_host *, struct ct_sns_req *);
1188 extern void qlt_init_atio_q_entries(struct scsi_qla_host *);
1189 extern void qlt_24xx_process_atio_queue(struct scsi_qla_host *, uint8_t);
1190 extern void qlt_24xx_config_rings(struct scsi_qla_host *);
1191 extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host *,
1192 struct nvram_24xx *);
1193 extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host *,
1194 struct init_cb_24xx *);
1195 extern void qlt_81xx_config_nvram_stage2(struct scsi_qla_host *,
1196 struct init_cb_81xx *);
1197 extern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host *,
1198 struct nvram_81xx *);
1199 extern int qlt_24xx_process_response_error(struct scsi_qla_host *,
1200 struct sts_entry_24xx *);
1201 extern void qlt_modify_vp_config(struct scsi_qla_host *,
1202 struct vp_config_entry_24xx *);
1203 extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
1204 extern int qlt_mem_alloc(struct qla_hw_data *);
1205 extern void qlt_mem_free(struct qla_hw_data *);
1206 extern int qlt_stop_phase1(struct qla_tgt *);
1207 extern void qlt_stop_phase2(struct qla_tgt *);
1208 extern irqreturn_t qla83xx_msix_atio_q(int, void *);
1209 extern void qlt_83xx_iospace_config(struct qla_hw_data *);
1210 extern int qlt_free_qfull_cmds(struct scsi_qla_host *);
1211 extern void qlt_logo_completion_handler(fc_port_t *, int);
1212 extern void qlt_do_generation_tick(struct scsi_qla_host *, int *);
1214 #endif /* __QLA_TARGET_H */