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))
117 #define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha)) \
118 ? le16_to_cpu((iocb)->u.isp2x.target.extended) \
119 : (uint16_t)(iocb)->u.isp2x.target.id.standard)
121 #ifndef IMMED_NOTIFY_TYPE
122 #define IMMED_NOTIFY_TYPE 0x0D /* Immediate notify entry. */
124 * ISP queue - immediate notify entry structure definition.
125 * This is sent by the ISP to the Target driver.
126 * This IOCB would have report of events sent by the
127 * initiator, that needs to be handled by the target
128 * driver immediately.
130 struct imm_ntfy_from_isp
{
131 uint8_t entry_type
; /* Entry type. */
132 uint8_t entry_count
; /* Entry count. */
133 uint8_t sys_define
; /* System defined. */
134 uint8_t entry_status
; /* Entry Status. */
137 uint32_t sys_define_2
; /* System defined. */
142 uint16_t status_modifier
;
147 uint32_t srr_rel_offs
;
149 #define SRR_IU_DATA_IN 0x1
150 #define SRR_IU_DATA_OUT 0x5
151 #define SRR_IU_STATUS 0x7
153 uint8_t reserved_2
[28];
157 uint16_t nport_handle
;
160 #define NOTIFY24XX_FLAGS_GLOBAL_TPRLO BIT_1
161 #define NOTIFY24XX_FLAGS_PUREX_IOCB BIT_0
164 uint8_t status_subcode
;
166 uint32_t exchange_address
;
167 uint32_t srr_rel_offs
;
170 uint8_t reserved_4
[19];
182 #ifndef NOTIFY_ACK_TYPE
183 #define NOTIFY_ACK_TYPE 0x0E /* Notify acknowledge entry. */
185 * ISP queue - notify acknowledge entry structure definition.
186 * This is sent to the ISP from the target driver.
189 uint8_t entry_type
; /* Entry type. */
190 uint8_t entry_count
; /* Entry count. */
191 uint8_t sys_define
; /* System defined. */
192 uint8_t entry_status
; /* Entry Status. */
195 uint32_t sys_define_2
; /* System defined. */
205 uint32_t srr_rel_offs
;
208 uint16_t srr_reject_code
;
209 uint8_t srr_reject_vendor_uniq
;
210 uint8_t srr_reject_code_expl
;
211 uint8_t reserved_2
[24];
215 uint16_t nport_handle
;
220 uint8_t status_subcode
;
222 uint32_t exchange_address
;
223 uint32_t srr_rel_offs
;
226 uint8_t reserved_4
[19];
228 uint8_t srr_reject_vendor_uniq
;
229 uint8_t srr_reject_code_expl
;
230 uint8_t srr_reject_code
;
231 uint8_t reserved_5
[5];
237 #define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0
238 #define NOTIFY_ACK_SRR_FLAGS_REJECT 1
240 #define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9
242 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0
243 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a
245 #define NOTIFY_ACK_SUCCESS 0x01
248 #ifndef ACCEPT_TGT_IO_TYPE
249 #define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */
252 #ifndef CONTINUE_TGT_IO_TYPE
253 #define CONTINUE_TGT_IO_TYPE 0x17
255 * ISP queue - Continue Target I/O (CTIO) entry for status mode 0 structure.
256 * This structure is sent to the ISP 2xxx from target driver.
258 struct ctio_to_2xxx
{
259 uint8_t entry_type
; /* Entry type. */
260 uint8_t entry_count
; /* Entry count. */
261 uint8_t sys_define
; /* System defined. */
262 uint8_t entry_status
; /* Entry Status. */
263 uint32_t handle
; /* System defined handle */
268 uint16_t timeout
; /* 0 = 30 seconds, 0xFFFF = disable */
269 uint16_t dseg_count
; /* Data segment count. */
270 uint32_t relative_offset
;
272 uint16_t reserved_1
[3];
273 uint16_t scsi_status
;
274 uint32_t transfer_length
;
275 uint32_t dseg_0_address
; /* Data segment 0 address. */
276 uint32_t dseg_0_length
; /* Data segment 0 length. */
277 uint32_t dseg_1_address
; /* Data segment 1 address. */
278 uint32_t dseg_1_length
; /* Data segment 1 length. */
279 uint32_t dseg_2_address
; /* Data segment 2 address. */
280 uint32_t dseg_2_length
; /* Data segment 2 length. */
282 #define ATIO_PATH_INVALID 0x07
283 #define ATIO_CANT_PROV_CAP 0x16
284 #define ATIO_CDB_VALID 0x3D
286 #define ATIO_EXEC_READ BIT_1
287 #define ATIO_EXEC_WRITE BIT_0
290 #ifndef CTIO_A64_TYPE
291 #define CTIO_A64_TYPE 0x1F
292 #define CTIO_SUCCESS 0x01
293 #define CTIO_ABORTED 0x02
294 #define CTIO_INVALID_RX_ID 0x08
295 #define CTIO_TIMEOUT 0x0B
296 #define CTIO_DIF_ERROR 0x0C /* DIF error detected */
297 #define CTIO_LIP_RESET 0x0E
298 #define CTIO_TARGET_RESET 0x17
299 #define CTIO_PORT_UNAVAILABLE 0x28
300 #define CTIO_PORT_LOGGED_OUT 0x29
301 #define CTIO_PORT_CONF_CHANGED 0x2A
302 #define CTIO_SRR_RECEIVED 0x45
305 #ifndef CTIO_RET_TYPE
306 #define CTIO_RET_TYPE 0x17 /* CTIO return entry */
307 #define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */
339 #define F_CTL_EXCH_CONTEXT_RESP BIT_23
340 #define F_CTL_SEQ_CONTEXT_RESIP BIT_22
341 #define F_CTL_LAST_SEQ BIT_20
342 #define F_CTL_END_SEQ BIT_19
343 #define F_CTL_SEQ_INITIATIVE BIT_16
345 #define R_CTL_BASIC_LINK_SERV 0x80
346 #define R_CTL_B_ACC 0x4
347 #define R_CTL_B_RJT 0x5
349 struct atio7_fcp_cmnd
{
354 uint8_t task_mgmt_flags
;
355 #define FCP_CMND_TASK_MGMT_CLEAR_ACA 6
356 #define FCP_CMND_TASK_MGMT_TARGET_RESET 5
357 #define FCP_CMND_TASK_MGMT_LU_RESET 4
358 #define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2
359 #define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1
362 uint8_t add_cdb_len
:6;
365 * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4
366 * only to make sizeof(struct atio7_fcp_cmnd) be as expected by
367 * BUILD_BUG_ON in qlt_init().
370 /* uint32_t data_length; */
374 * ISP queue - Accept Target I/O (ATIO) type entry IOCB structure.
375 * This is sent from the ISP to the target driver.
377 struct atio_from_isp
{
381 uint8_t sys_define
; /* System defined. */
382 uint8_t entry_status
; /* Entry Status. */
383 uint32_t sys_define_2
; /* System defined. */
391 uint8_t execution_codes
;
392 uint8_t cdb
[MAX_CMDSZ
];
393 uint32_t data_length
;
395 uint8_t initiator_port_name
[WWN_SIZE
]; /* on qla23xx */
396 uint16_t reserved_32
[6];
401 uint8_t fcp_cmnd_len_low
;
402 uint8_t fcp_cmnd_len_high
:4;
404 uint32_t exchange_addr
;
405 #define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF
406 struct fcp_hdr fcp_hdr
;
407 struct atio7_fcp_cmnd fcp_cmnd
;
410 uint8_t entry_type
; /* Entry type. */
411 uint8_t entry_count
; /* Entry count. */
414 #define ATIO_PROCESSED 0xDEADDEAD /* Signature */
419 #define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */
422 * ISP queue - Continue Target I/O (ATIO) type 7 entry (for 24xx) structure.
423 * This structure is sent to the ISP 24xx from the target driver.
426 struct ctio7_to_24xx
{
427 uint8_t entry_type
; /* Entry type. */
428 uint8_t entry_count
; /* Entry count. */
429 uint8_t sys_define
; /* System defined. */
430 uint8_t entry_status
; /* Entry Status. */
431 uint32_t handle
; /* System defined handle */
432 uint16_t nport_handle
;
433 #define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF
435 uint16_t dseg_count
; /* Data segment count. */
438 uint8_t initiator_id
[3];
440 uint32_t exchange_addr
;
447 uint16_t scsi_status
;
448 uint32_t relative_offset
;
450 uint32_t transfer_length
;
452 /* Data segment 0 address. */
453 uint32_t dseg_0_address
[2];
454 /* Data segment 0 length. */
455 uint32_t dseg_0_length
;
458 uint16_t sense_length
;
462 uint16_t scsi_status
;
463 uint16_t response_len
;
465 uint8_t sense_data
[24];
471 * ISP queue - CTIO type 7 from ISP 24xx to target driver
472 * returned entry structure.
474 struct ctio7_from_24xx
{
475 uint8_t entry_type
; /* Entry type. */
476 uint8_t entry_count
; /* Entry count. */
477 uint8_t sys_define
; /* System defined. */
478 uint8_t entry_status
; /* Entry Status. */
479 uint32_t handle
; /* System defined handle */
482 uint16_t dseg_count
; /* Data segment count. */
484 uint8_t reserved1
[5];
485 uint32_t exchange_address
;
491 uint32_t relative_offset
;
492 uint8_t reserved4
[24];
495 /* CTIO7 flags values */
496 #define CTIO7_FLAGS_SEND_STATUS BIT_15
497 #define CTIO7_FLAGS_TERMINATE BIT_14
498 #define CTIO7_FLAGS_CONFORM_REQ BIT_13
499 #define CTIO7_FLAGS_DONT_RET_CTIO BIT_8
500 #define CTIO7_FLAGS_STATUS_MODE_0 0
501 #define CTIO7_FLAGS_STATUS_MODE_1 BIT_6
502 #define CTIO7_FLAGS_STATUS_MODE_2 BIT_7
503 #define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5
504 #define CTIO7_FLAGS_CONFIRM_SATISF BIT_4
505 #define CTIO7_FLAGS_DSD_PTR BIT_2
506 #define CTIO7_FLAGS_DATA_IN BIT_1 /* data to initiator */
507 #define CTIO7_FLAGS_DATA_OUT BIT_0 /* data from initiator */
509 #define ELS_PLOGI 0x3
510 #define ELS_FLOGI 0x4
512 #define ELS_PRLI 0x20
513 #define ELS_PRLO 0x21
514 #define ELS_TPRLO 0x24
515 #define ELS_PDISC 0x50
516 #define ELS_ADISC 0x52
519 *CTIO Type CRC_2 IOCB
521 struct ctio_crc2_to_fw
{
522 uint8_t entry_type
; /* Entry type. */
523 #define CTIO_CRC2 0x7A
524 uint8_t entry_count
; /* Entry count. */
525 uint8_t sys_define
; /* System defined. */
526 uint8_t entry_status
; /* Entry Status. */
528 uint32_t handle
; /* System handle. */
529 uint16_t nport_handle
; /* N_PORT handle. */
530 __le16 timeout
; /* Command timeout. */
532 uint16_t dseg_count
; /* Data segment count. */
534 uint8_t add_flags
; /* additional flags */
535 #define CTIO_CRC2_AF_DIF_DSD_ENA BIT_3
537 uint8_t initiator_id
[3]; /* initiator ID */
539 uint32_t exchange_addr
; /* rcv exchange address */
541 __le16 flags
; /* refer to CTIO7 flags values */
544 uint16_t scsi_status
;
545 __le32 relative_offset
;
547 __le32 transfer_length
; /* total fc transfer length */
549 __le32 crc_context_address
[2];/* Data segment address. */
550 uint16_t crc_context_len
; /* Data segment length. */
551 uint16_t reserved_1
; /* MUST be set to 0. */
554 /* CTIO Type CRC_x Status IOCB */
555 struct ctio_crc_from_fw
{
556 uint8_t entry_type
; /* Entry type. */
557 uint8_t entry_count
; /* Entry count. */
558 uint8_t sys_define
; /* System defined. */
559 uint8_t entry_status
; /* Entry Status. */
561 uint32_t handle
; /* System handle. */
563 uint16_t timeout
; /* Command timeout. */
564 uint16_t dseg_count
; /* Data segment count. */
566 uint16_t state_flags
;
567 #define CTIO_CRC_SF_DIF_CHOPPED BIT_4
569 uint32_t exchange_address
; /* rcv exchange address */
572 uint32_t resid_xfer_length
;
574 uint8_t reserved3
[12];
575 uint16_t runt_guard
; /* reported runt blk guard */
576 uint8_t actual_dif
[8];
577 uint8_t expected_dif
[8];
581 * ISP queue - ABTS received/response entries structure definition for 24xx.
583 #define ABTS_RECV_24XX 0x54 /* ABTS received (for 24xx) */
584 #define ABTS_RESP_24XX 0x55 /* ABTS responce (for 24xx) */
587 * ISP queue - ABTS received IOCB entry structure definition for 24xx.
588 * The ABTS BLS received from the wire is sent to the
589 * target driver by the ISP 24xx.
590 * The IOCB is placed on the response queue.
592 struct abts_recv_from_24xx
{
593 uint8_t entry_type
; /* Entry type. */
594 uint8_t entry_count
; /* Entry count. */
595 uint8_t sys_define
; /* System defined. */
596 uint8_t entry_status
; /* Entry Status. */
597 uint8_t reserved_1
[6];
598 uint16_t nport_handle
;
599 uint8_t reserved_2
[2];
601 uint8_t reserved_3
:4;
603 uint32_t exchange_address
;
604 struct fcp_hdr_le fcp_hdr_le
;
605 uint8_t reserved_4
[16];
606 uint32_t exchange_addr_to_abort
;
609 #define ABTS_PARAM_ABORT_SEQ BIT_0
614 uint8_t seq_id_valid
;
615 #define SEQ_ID_VALID 0x80
616 #define SEQ_ID_INVALID 0x00
619 uint16_t high_seq_cnt
;
620 uint16_t low_seq_cnt
;
627 #define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1
628 #define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9
633 * ISP queue - ABTS Response IOCB entry structure definition for 24xx.
634 * The ABTS response to the ABTS received is sent by the
635 * target driver to the ISP 24xx.
636 * The IOCB is placed on the request queue.
638 struct abts_resp_to_24xx
{
639 uint8_t entry_type
; /* Entry type. */
640 uint8_t entry_count
; /* Entry count. */
641 uint8_t sys_define
; /* System defined. */
642 uint8_t entry_status
; /* Entry Status. */
645 uint16_t nport_handle
;
646 uint16_t control_flags
;
647 #define ABTS_CONTR_FLG_TERM_EXCHG BIT_0
649 uint8_t reserved_3
:4;
651 uint32_t exchange_address
;
652 struct fcp_hdr_le fcp_hdr_le
;
654 struct ba_acc_le ba_acct
;
655 struct ba_rjt_le ba_rjt
;
658 uint32_t exchange_addr_to_abort
;
662 * ISP queue - ABTS Response IOCB from ISP24xx Firmware entry structure.
663 * The ABTS response with completion status to the ABTS response
664 * (sent by the target driver to the ISP 24xx) is sent by the
665 * ISP24xx firmware to the target driver.
666 * The IOCB is placed on the response queue.
668 struct abts_resp_from_24xx_fw
{
669 uint8_t entry_type
; /* Entry type. */
670 uint8_t entry_count
; /* Entry count. */
671 uint8_t sys_define
; /* System defined. */
672 uint8_t entry_status
; /* Entry Status. */
674 uint16_t compl_status
;
675 #define ABTS_RESP_COMPL_SUCCESS 0
676 #define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31
677 uint16_t nport_handle
;
680 uint8_t reserved_3
:4;
682 uint32_t exchange_address
;
683 struct fcp_hdr_le fcp_hdr_le
;
684 uint8_t reserved_4
[8];
685 uint32_t error_subcode1
;
686 #define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E
687 uint32_t error_subcode2
;
688 uint32_t exchange_addr_to_abort
;
691 /********************************************************************\
692 * Type Definitions used by initiator & target halves
693 \********************************************************************/
695 struct qla_tgt_mgmt_cmd
;
699 * This structure provides a template of function calls that the
700 * target driver (from within qla_target.c) can issue to the
701 * target module (tcm_qla2xxx).
703 struct qla_tgt_func_tmpl
{
705 int (*handle_cmd
)(struct scsi_qla_host
*, struct qla_tgt_cmd
*,
706 unsigned char *, uint32_t, int, int, int);
707 void (*handle_data
)(struct qla_tgt_cmd
*);
708 void (*handle_dif_err
)(struct qla_tgt_cmd
*);
709 int (*handle_tmr
)(struct qla_tgt_mgmt_cmd
*, uint32_t, uint8_t,
711 void (*free_cmd
)(struct qla_tgt_cmd
*);
712 void (*free_mcmd
)(struct qla_tgt_mgmt_cmd
*);
713 void (*free_session
)(struct qla_tgt_sess
*);
715 int (*check_initiator_node_acl
)(struct scsi_qla_host
*, unsigned char *,
716 void *, uint8_t *, uint16_t);
717 void (*update_sess
)(struct qla_tgt_sess
*, port_id_t
, uint16_t, bool);
718 struct qla_tgt_sess
*(*find_sess_by_loop_id
)(struct scsi_qla_host
*,
720 struct qla_tgt_sess
*(*find_sess_by_s_id
)(struct scsi_qla_host
*,
722 void (*clear_nacl_from_fcport_map
)(struct qla_tgt_sess
*);
723 void (*put_sess
)(struct qla_tgt_sess
*);
724 void (*shutdown_sess
)(struct qla_tgt_sess
*);
727 int qla2x00_wait_for_hba_online(struct scsi_qla_host
*);
729 #include <target/target_core_base.h>
731 #define QLA_TGT_TIMEOUT 10 /* in seconds */
733 #define QLA_TGT_MAX_HW_PENDING_TIME 60 /* in seconds */
735 /* Immediate notify status constants */
736 #define IMM_NTFY_LIP_RESET 0x000E
737 #define IMM_NTFY_LIP_LINK_REINIT 0x000F
738 #define IMM_NTFY_IOCB_OVERFLOW 0x0016
739 #define IMM_NTFY_ABORT_TASK 0x0020
740 #define IMM_NTFY_PORT_LOGOUT 0x0029
741 #define IMM_NTFY_PORT_CONFIG 0x002A
742 #define IMM_NTFY_GLBL_TPRLO 0x002D
743 #define IMM_NTFY_GLBL_LOGO 0x002E
744 #define IMM_NTFY_RESOURCE 0x0034
745 #define IMM_NTFY_MSG_RX 0x0036
746 #define IMM_NTFY_SRR 0x0045
747 #define IMM_NTFY_ELS 0x0046
749 /* Immediate notify task flags */
750 #define IMM_NTFY_TASK_MGMT_SHIFT 8
752 #define QLA_TGT_CLEAR_ACA 0x40
753 #define QLA_TGT_TARGET_RESET 0x20
754 #define QLA_TGT_LUN_RESET 0x10
755 #define QLA_TGT_CLEAR_TS 0x04
756 #define QLA_TGT_ABORT_TS 0x02
757 #define QLA_TGT_ABORT_ALL_SESS 0xFFFF
758 #define QLA_TGT_ABORT_ALL 0xFFFE
759 #define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD
760 #define QLA_TGT_NEXUS_LOSS 0xFFFC
762 /* Notify Acknowledge flags */
763 #define NOTIFY_ACK_RES_COUNT BIT_8
764 #define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5
765 #define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
767 /* Command's states */
768 #define QLA_TGT_STATE_NEW 0 /* New command + target processing */
769 #define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */
770 #define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */
771 #define QLA_TGT_STATE_PROCESSED 3 /* target done processing */
772 #define QLA_TGT_STATE_ABORTED 4 /* Command aborted */
774 /* Special handles */
775 #define QLA_TGT_NULL_HANDLE 0
776 #define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~CTIO_COMPLETION_HANDLE_MARK)
778 /* ATIO task_codes field */
779 #define ATIO_SIMPLE_QUEUE 0
780 #define ATIO_HEAD_OF_QUEUE 1
781 #define ATIO_ORDERED_QUEUE 2
782 #define ATIO_ACA_QUEUE 4
783 #define ATIO_UNTAGGED 5
785 /* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */
786 #define FC_TM_SUCCESS 0
787 #define FC_TM_BAD_FCP_DATA 1
788 #define FC_TM_BAD_CMD 2
789 #define FC_TM_FCP_DATA_MISMATCH 3
790 #define FC_TM_REJECT 4
791 #define FC_TM_FAILED 5
794 * Error code of qlt_pre_xmit_response() meaning that cmd's exchange was
795 * terminated, so no more actions is needed and success should be returned
798 #define QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED 0x1717
800 #if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
801 #define pci_dma_lo32(a) (a & 0xffffffff)
802 #define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff)
804 #define pci_dma_lo32(a) (a & 0xffffffff)
805 #define pci_dma_hi32(a) 0
808 #define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \
809 (((const uint8_t *)(sense))[0] & 0x70) == 0x70)
811 struct qla_port_24xx_data
{
812 uint8_t port_name
[WWN_SIZE
];
818 struct scsi_qla_host
*vha
;
819 struct qla_hw_data
*ha
;
822 * To sync between IRQ handlers and qlt_target_release(). Needed,
823 * because req_pkt() can drop/reaquire HW lock inside. Protected by
828 int datasegs_per_cmd
, datasegs_per_cont
, sg_tablesize
;
830 /* Target's flags, serialized by pha->hardware_lock */
831 unsigned int tgt_enable_64bit_addr
:1; /* 64-bits PCI addr enabled */
832 unsigned int link_reinit_iocb_pending
:1;
835 * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex
836 * OR hardware_lock for reading.
838 int tgt_stop
; /* the target mode driver is being stopped */
839 int tgt_stopped
; /* the target mode driver has been stopped */
841 /* Count of sessions refering qla_tgt. Protected by hardware_lock. */
844 /* Protected by hardware_lock. Addition also protected by tgt_mutex. */
845 struct list_head sess_list
;
847 /* Protected by hardware_lock */
848 struct list_head del_sess_list
;
849 struct delayed_work sess_del_work
;
851 spinlock_t sess_work_lock
;
852 struct list_head sess_works_list
;
853 struct work_struct sess_work
;
855 struct imm_ntfy_from_isp link_reinit_iocb
;
856 wait_queue_head_t waitQ
;
857 int notify_ack_expected
;
858 int abts_resp_expected
;
859 int modify_lun_expected
;
864 struct list_head srr_ctio_list
;
865 struct list_head srr_imm_list
;
866 struct work_struct srr_work
;
868 atomic_t tgt_global_resets_count
;
870 struct list_head tgt_list_entry
;
873 struct qla_tgt_sess_op
{
874 struct scsi_qla_host
*vha
;
875 struct atio_from_isp atio
;
876 struct work_struct work
;
880 * Equivilant to IT Nexus (Initiator-Target)
882 struct qla_tgt_sess
{
886 unsigned int conf_compl_supported
:1;
887 unsigned int deleted
:1;
888 unsigned int local
:1;
890 struct se_session
*se_sess
;
891 struct scsi_qla_host
*vha
;
894 struct list_head sess_list_entry
;
895 unsigned long expires
;
896 struct list_head del_list_entry
;
898 uint8_t port_name
[WWN_SIZE
];
899 struct work_struct free_work
;
903 struct se_cmd se_cmd
;
904 struct qla_tgt_sess
*sess
;
906 struct work_struct free_work
;
907 struct work_struct work
;
908 /* Sense buffer that will be mapped into outgoing status */
909 unsigned char sense_buffer
[TRANSPORT_SENSE_BUFFER
];
911 /* to save extra sess dereferences */
912 unsigned int conf_compl_supported
:1;
913 unsigned int sg_mapped
:1;
914 unsigned int free_sg
:1;
915 unsigned int aborted
:1; /* Needed in case of SRR */
916 unsigned int write_data_transferred
:1;
917 unsigned int ctx_dsd_alloced
:1;
918 unsigned int q_full
:1;
919 unsigned int term_exchg
:1;
920 unsigned int cmd_sent_to_fw
:1;
921 unsigned int cmd_in_wq
:1;
923 struct scatterlist
*sg
; /* cmd data buffer SG vector */
924 int sg_cnt
; /* SG segments count */
925 int bufflen
; /* cmd buffer length */
927 uint32_t unpacked_lun
;
928 enum dma_data_direction dma_data_direction
;
929 uint32_t reset_count
;
931 uint16_t loop_id
; /* to save extra sess dereferences */
932 struct qla_tgt
*tgt
; /* to save extra sess dereferences */
933 struct scsi_qla_host
*vha
;
934 struct list_head cmd_list
;
936 struct atio_from_isp atio
;
938 struct scatterlist
*prot_sg
;
939 uint32_t prot_sg_cnt
;
941 struct crc_context
*ctx
;
943 uint64_t jiffies_at_alloc
;
944 uint64_t jiffies_at_free
;
945 /* BIT_0 - Atio Arrival / schedule to work
946 * BIT_1 - qlt_do_work
947 * BIT_2 - qlt_do work failed
948 * BIT_3 - xfer rdy/tcm_qla2xxx_write_pending
949 * BIT_4 - read respond/tcm_qla2xx_queue_data_in
950 * BIT_5 - status respond / tcm_qla2xx_queue_status
951 * BIT_6 - tcm request to abort/Term exchange.
952 * pre_xmit_response->qlt_send_term_exchange
953 * BIT_7 - SRR received (qlt_handle_srr->qlt_xmit_response)
954 * BIT_8 - SRR received (qlt_handle_srr->qlt_rdy_to_xfer)
955 * BIT_9 - SRR received (qla_handle_srr->qlt_send_term_exchange)
956 * BIT_10 - Data in - hanlde_data->tcm_qla2xxx_handle_data
957 * BIT_11 - Data actually going to TCM : tcm_qla2xx_handle_data_work
958 * BIT_12 - good completion - qlt_ctio_do_completion -->free_cmd
959 * BIT_13 - Bad completion -
960 * qlt_ctio_do_completion --> qlt_term_ctio_exchange
961 * BIT_14 - Back end data received/sent.
962 * BIT_15 - SRR prepare ctio
963 * BIT_16 - complete free
968 struct qla_tgt_sess_work_param
{
969 struct list_head sess_works_list_entry
;
971 #define QLA_TGT_SESS_WORK_ABORT 1
972 #define QLA_TGT_SESS_WORK_TM 2
976 struct abts_recv_from_24xx abts
;
977 struct imm_ntfy_from_isp tm_iocb
;
978 struct atio_from_isp tm_iocb2
;
982 struct qla_tgt_mgmt_cmd
{
985 struct qla_tgt_sess
*sess
;
986 struct se_cmd se_cmd
;
987 struct work_struct free_work
;
989 uint32_t reset_count
;
990 #define QLA24XX_MGMT_SEND_NACK 1
992 struct atio_from_isp atio
;
993 struct imm_ntfy_from_isp imm_ntfy
;
994 struct abts_recv_from_24xx abts
;
995 } __packed orig_iocb
;
999 struct qla_tgt_cmd
*cmd
;
1000 struct qla_tgt
*tgt
;
1002 struct scatterlist
*sg
; /* cmd data buffer SG vector */
1003 unsigned char *sense_buffer
;
1007 uint16_t scsi_status
;
1008 int sense_buffer_len
;
1012 struct scatterlist
*prot_sg
;
1013 uint16_t prot_seg_cnt
;
1017 struct qla_tgt_srr_imm
{
1018 struct list_head srr_list_entry
;
1020 struct imm_ntfy_from_isp imm_ntfy
;
1023 struct qla_tgt_srr_ctio
{
1024 struct list_head srr_list_entry
;
1026 struct qla_tgt_cmd
*cmd
;
1029 #define QLA_TGT_XMIT_DATA 1
1030 #define QLA_TGT_XMIT_STATUS 2
1031 #define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA)
1034 extern struct qla_tgt_data qla_target
;
1037 * Function prototypes for qla_target.c logic used by qla2xxx LLD code.
1039 extern int qlt_add_target(struct qla_hw_data
*, struct scsi_qla_host
*);
1040 extern int qlt_remove_target(struct qla_hw_data
*, struct scsi_qla_host
*);
1041 extern int qlt_lport_register(void *, u64
, u64
, u64
,
1042 int (*callback
)(struct scsi_qla_host
*, void *, u64
, u64
));
1043 extern void qlt_lport_deregister(struct scsi_qla_host
*);
1044 extern void qlt_unreg_sess(struct qla_tgt_sess
*);
1045 extern void qlt_fc_port_added(struct scsi_qla_host
*, fc_port_t
*);
1046 extern void qlt_fc_port_deleted(struct scsi_qla_host
*, fc_port_t
*);
1047 extern int __init
qlt_init(void);
1048 extern void qlt_exit(void);
1049 extern void qlt_update_vp_map(struct scsi_qla_host
*, int);
1052 * This macro is used during early initializations when host->active_mode
1053 * is not set. Right now, ha value is ignored.
1055 #define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED)
1056 extern int ql2x_ini_mode
;
1058 static inline bool qla_tgt_mode_enabled(struct scsi_qla_host
*ha
)
1060 return ha
->host
->active_mode
& MODE_TARGET
;
1063 static inline bool qla_ini_mode_enabled(struct scsi_qla_host
*ha
)
1065 return ha
->host
->active_mode
& MODE_INITIATOR
;
1068 static inline void qla_reverse_ini_mode(struct scsi_qla_host
*ha
)
1070 if (ha
->host
->active_mode
& MODE_INITIATOR
)
1071 ha
->host
->active_mode
&= ~MODE_INITIATOR
;
1073 ha
->host
->active_mode
|= MODE_INITIATOR
;
1077 * Exported symbols from qla_target.c LLD logic used by qla2xxx code..
1079 extern void qlt_response_pkt_all_vps(struct scsi_qla_host
*, response_t
*);
1080 extern int qlt_rdy_to_xfer(struct qla_tgt_cmd
*);
1081 extern int qlt_xmit_response(struct qla_tgt_cmd
*, int, uint8_t);
1082 extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd
*);
1083 extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd
*);
1084 extern void qlt_free_cmd(struct qla_tgt_cmd
*cmd
);
1085 extern void qlt_async_event(uint16_t, struct scsi_qla_host
*, uint16_t *);
1086 extern void qlt_enable_vha(struct scsi_qla_host
*);
1087 extern void qlt_vport_create(struct scsi_qla_host
*, struct qla_hw_data
*);
1088 extern void qlt_rff_id(struct scsi_qla_host
*, struct ct_sns_req
*);
1089 extern void qlt_init_atio_q_entries(struct scsi_qla_host
*);
1090 extern void qlt_24xx_process_atio_queue(struct scsi_qla_host
*);
1091 extern void qlt_24xx_config_rings(struct scsi_qla_host
*);
1092 extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host
*,
1093 struct nvram_24xx
*);
1094 extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host
*,
1095 struct init_cb_24xx
*);
1096 extern void qlt_81xx_config_nvram_stage2(struct scsi_qla_host
*,
1097 struct init_cb_81xx
*);
1098 extern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host
*,
1099 struct nvram_81xx
*);
1100 extern int qlt_24xx_process_response_error(struct scsi_qla_host
*,
1101 struct sts_entry_24xx
*);
1102 extern void qlt_modify_vp_config(struct scsi_qla_host
*,
1103 struct vp_config_entry_24xx
*);
1104 extern void qlt_probe_one_stage1(struct scsi_qla_host
*, struct qla_hw_data
*);
1105 extern int qlt_mem_alloc(struct qla_hw_data
*);
1106 extern void qlt_mem_free(struct qla_hw_data
*);
1107 extern int qlt_stop_phase1(struct qla_tgt
*);
1108 extern void qlt_stop_phase2(struct qla_tgt
*);
1109 extern irqreturn_t
qla83xx_msix_atio_q(int, void *);
1110 extern void qlt_83xx_iospace_config(struct qla_hw_data
*);
1111 extern int qlt_free_qfull_cmds(struct scsi_qla_host
*);
1113 #endif /* __QLA_TARGET_H */