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 <= MAX_OUTSTANDING_COMMANDS)
64 #error "CTIO_COMPLETION_HANDLE_MARK not larger than MAX_OUTSTANDING_COMMANDS"
66 #define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK)
68 /* Used to mark CTIO as intermediate */
69 #define CTIO_INTERMEDIATE_HANDLE_MARK BIT_30
73 * ISP target entries - Flags bit definitions.
75 #define OF_SS_MODE_0 0
76 #define OF_SS_MODE_1 1
77 #define OF_SS_MODE_2 2
78 #define OF_SS_MODE_3 3
80 #define OF_EXPL_CONF BIT_5 /* Explicit Confirmation Requested */
81 #define OF_DATA_IN BIT_6 /* Data in to initiator */
82 /* (data from target to initiator) */
83 #define OF_DATA_OUT BIT_7 /* Data out from initiator */
84 /* (data from initiator to target) */
85 #define OF_NO_DATA (BIT_7 | BIT_6)
86 #define OF_INC_RC BIT_8 /* Increment command resource count */
87 #define OF_FAST_POST BIT_9 /* Enable mailbox fast posting. */
88 #define OF_CONF_REQ BIT_13 /* Confirmation Requested */
89 #define OF_TERM_EXCH BIT_14 /* Terminate exchange */
90 #define OF_SSTS BIT_15 /* Send SCSI status */
93 #ifndef QLA_TGT_DATASEGS_PER_CMD32
94 #define QLA_TGT_DATASEGS_PER_CMD32 3
95 #define QLA_TGT_DATASEGS_PER_CONT32 7
96 #define QLA_TGT_MAX_SG32(ql) \
97 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \
98 QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0)
100 #define QLA_TGT_DATASEGS_PER_CMD64 2
101 #define QLA_TGT_DATASEGS_PER_CONT64 5
102 #define QLA_TGT_MAX_SG64(ql) \
103 (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \
104 QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0)
107 #ifndef QLA_TGT_DATASEGS_PER_CMD_24XX
108 #define QLA_TGT_DATASEGS_PER_CMD_24XX 1
109 #define QLA_TGT_DATASEGS_PER_CONT_24XX 5
110 #define QLA_TGT_MAX_SG_24XX(ql) \
111 (min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \
112 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
;
169 uint8_t reserved_4
[19];
181 #ifndef NOTIFY_ACK_TYPE
182 #define NOTIFY_ACK_TYPE 0x0E /* Notify acknowledge entry. */
184 * ISP queue - notify acknowledge entry structure definition.
185 * This is sent to the ISP from the target driver.
188 uint8_t entry_type
; /* Entry type. */
189 uint8_t entry_count
; /* Entry count. */
190 uint8_t sys_define
; /* System defined. */
191 uint8_t entry_status
; /* Entry Status. */
194 uint32_t sys_define_2
; /* System defined. */
204 uint32_t srr_rel_offs
;
207 uint16_t srr_reject_code
;
208 uint8_t srr_reject_vendor_uniq
;
209 uint8_t srr_reject_code_expl
;
210 uint8_t reserved_2
[24];
214 uint16_t nport_handle
;
219 uint8_t status_subcode
;
221 uint32_t exchange_address
;
222 uint32_t srr_rel_offs
;
225 uint8_t reserved_4
[19];
227 uint8_t srr_reject_vendor_uniq
;
228 uint8_t srr_reject_code_expl
;
229 uint8_t srr_reject_code
;
230 uint8_t reserved_5
[5];
236 #define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0
237 #define NOTIFY_ACK_SRR_FLAGS_REJECT 1
239 #define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9
241 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0
242 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a
244 #define NOTIFY_ACK_SUCCESS 0x01
247 #ifndef ACCEPT_TGT_IO_TYPE
248 #define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */
251 #ifndef CONTINUE_TGT_IO_TYPE
252 #define CONTINUE_TGT_IO_TYPE 0x17
254 * ISP queue - Continue Target I/O (CTIO) entry for status mode 0 structure.
255 * This structure is sent to the ISP 2xxx from target driver.
257 struct ctio_to_2xxx
{
258 uint8_t entry_type
; /* Entry type. */
259 uint8_t entry_count
; /* Entry count. */
260 uint8_t sys_define
; /* System defined. */
261 uint8_t entry_status
; /* Entry Status. */
262 uint32_t handle
; /* System defined handle */
267 uint16_t timeout
; /* 0 = 30 seconds, 0xFFFF = disable */
268 uint16_t dseg_count
; /* Data segment count. */
269 uint32_t relative_offset
;
271 uint16_t reserved_1
[3];
272 uint16_t scsi_status
;
273 uint32_t transfer_length
;
274 uint32_t dseg_0_address
; /* Data segment 0 address. */
275 uint32_t dseg_0_length
; /* Data segment 0 length. */
276 uint32_t dseg_1_address
; /* Data segment 1 address. */
277 uint32_t dseg_1_length
; /* Data segment 1 length. */
278 uint32_t dseg_2_address
; /* Data segment 2 address. */
279 uint32_t dseg_2_length
; /* Data segment 2 length. */
281 #define ATIO_PATH_INVALID 0x07
282 #define ATIO_CANT_PROV_CAP 0x16
283 #define ATIO_CDB_VALID 0x3D
285 #define ATIO_EXEC_READ BIT_1
286 #define ATIO_EXEC_WRITE BIT_0
289 #ifndef CTIO_A64_TYPE
290 #define CTIO_A64_TYPE 0x1F
291 #define CTIO_SUCCESS 0x01
292 #define CTIO_ABORTED 0x02
293 #define CTIO_INVALID_RX_ID 0x08
294 #define CTIO_TIMEOUT 0x0B
295 #define CTIO_LIP_RESET 0x0E
296 #define CTIO_TARGET_RESET 0x17
297 #define CTIO_PORT_UNAVAILABLE 0x28
298 #define CTIO_PORT_LOGGED_OUT 0x29
299 #define CTIO_PORT_CONF_CHANGED 0x2A
300 #define CTIO_SRR_RECEIVED 0x45
303 #ifndef CTIO_RET_TYPE
304 #define CTIO_RET_TYPE 0x17 /* CTIO return entry */
305 #define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */
337 #define F_CTL_EXCH_CONTEXT_RESP BIT_23
338 #define F_CTL_SEQ_CONTEXT_RESIP BIT_22
339 #define F_CTL_LAST_SEQ BIT_20
340 #define F_CTL_END_SEQ BIT_19
341 #define F_CTL_SEQ_INITIATIVE BIT_16
343 #define R_CTL_BASIC_LINK_SERV 0x80
344 #define R_CTL_B_ACC 0x4
345 #define R_CTL_B_RJT 0x5
347 struct atio7_fcp_cmnd
{
352 uint8_t task_mgmt_flags
;
353 #define FCP_CMND_TASK_MGMT_CLEAR_ACA 6
354 #define FCP_CMND_TASK_MGMT_TARGET_RESET 5
355 #define FCP_CMND_TASK_MGMT_LU_RESET 4
356 #define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2
357 #define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1
360 uint8_t add_cdb_len
:6;
363 * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4
364 * only to make sizeof(struct atio7_fcp_cmnd) be as expected by
365 * BUILD_BUG_ON in qlt_init().
368 /* uint32_t data_length; */
372 * ISP queue - Accept Target I/O (ATIO) type entry IOCB structure.
373 * This is sent from the ISP to the target driver.
375 struct atio_from_isp
{
379 uint8_t sys_define
; /* System defined. */
380 uint8_t entry_status
; /* Entry Status. */
381 uint32_t sys_define_2
; /* System defined. */
389 uint8_t execution_codes
;
390 uint8_t cdb
[MAX_CMDSZ
];
391 uint32_t data_length
;
393 uint8_t initiator_port_name
[WWN_SIZE
]; /* on qla23xx */
394 uint16_t reserved_32
[6];
399 uint8_t fcp_cmnd_len_low
;
400 uint8_t fcp_cmnd_len_high
:4;
402 uint32_t exchange_addr
;
403 #define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF
404 struct fcp_hdr fcp_hdr
;
405 struct atio7_fcp_cmnd fcp_cmnd
;
408 uint8_t entry_type
; /* Entry type. */
409 uint8_t entry_count
; /* Entry count. */
412 #define ATIO_PROCESSED 0xDEADDEAD /* Signature */
417 #define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */
420 * ISP queue - Continue Target I/O (ATIO) type 7 entry (for 24xx) structure.
421 * This structure is sent to the ISP 24xx from the target driver.
424 struct ctio7_to_24xx
{
425 uint8_t entry_type
; /* Entry type. */
426 uint8_t entry_count
; /* Entry count. */
427 uint8_t sys_define
; /* System defined. */
428 uint8_t entry_status
; /* Entry Status. */
429 uint32_t handle
; /* System defined handle */
430 uint16_t nport_handle
;
431 #define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF
433 uint16_t dseg_count
; /* Data segment count. */
436 uint8_t initiator_id
[3];
438 uint32_t exchange_addr
;
445 uint16_t scsi_status
;
446 uint32_t relative_offset
;
448 uint32_t transfer_length
;
450 /* Data segment 0 address. */
451 uint32_t dseg_0_address
[2];
452 /* Data segment 0 length. */
453 uint32_t dseg_0_length
;
456 uint16_t sense_length
;
460 uint16_t scsi_status
;
461 uint16_t response_len
;
463 uint8_t sense_data
[24];
469 * ISP queue - CTIO type 7 from ISP 24xx to target driver
470 * returned entry structure.
472 struct ctio7_from_24xx
{
473 uint8_t entry_type
; /* Entry type. */
474 uint8_t entry_count
; /* Entry count. */
475 uint8_t sys_define
; /* System defined. */
476 uint8_t entry_status
; /* Entry Status. */
477 uint32_t handle
; /* System defined handle */
480 uint16_t dseg_count
; /* Data segment count. */
482 uint8_t reserved1
[5];
483 uint32_t exchange_address
;
489 uint32_t relative_offset
;
490 uint8_t reserved4
[24];
493 /* CTIO7 flags values */
494 #define CTIO7_FLAGS_SEND_STATUS BIT_15
495 #define CTIO7_FLAGS_TERMINATE BIT_14
496 #define CTIO7_FLAGS_CONFORM_REQ BIT_13
497 #define CTIO7_FLAGS_DONT_RET_CTIO BIT_8
498 #define CTIO7_FLAGS_STATUS_MODE_0 0
499 #define CTIO7_FLAGS_STATUS_MODE_1 BIT_6
500 #define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5
501 #define CTIO7_FLAGS_CONFIRM_SATISF BIT_4
502 #define CTIO7_FLAGS_DSD_PTR BIT_2
503 #define CTIO7_FLAGS_DATA_IN BIT_1
504 #define CTIO7_FLAGS_DATA_OUT BIT_0
506 #define ELS_PLOGI 0x3
507 #define ELS_FLOGI 0x4
509 #define ELS_PRLI 0x20
510 #define ELS_PRLO 0x21
511 #define ELS_TPRLO 0x24
512 #define ELS_PDISC 0x50
513 #define ELS_ADISC 0x52
516 * ISP queue - ABTS received/response entries structure definition for 24xx.
518 #define ABTS_RECV_24XX 0x54 /* ABTS received (for 24xx) */
519 #define ABTS_RESP_24XX 0x55 /* ABTS responce (for 24xx) */
522 * ISP queue - ABTS received IOCB entry structure definition for 24xx.
523 * The ABTS BLS received from the wire is sent to the
524 * target driver by the ISP 24xx.
525 * The IOCB is placed on the response queue.
527 struct abts_recv_from_24xx
{
528 uint8_t entry_type
; /* Entry type. */
529 uint8_t entry_count
; /* Entry count. */
530 uint8_t sys_define
; /* System defined. */
531 uint8_t entry_status
; /* Entry Status. */
532 uint8_t reserved_1
[6];
533 uint16_t nport_handle
;
534 uint8_t reserved_2
[2];
536 uint8_t reserved_3
:4;
538 uint32_t exchange_address
;
539 struct fcp_hdr_le fcp_hdr_le
;
540 uint8_t reserved_4
[16];
541 uint32_t exchange_addr_to_abort
;
544 #define ABTS_PARAM_ABORT_SEQ BIT_0
549 uint8_t seq_id_valid
;
550 #define SEQ_ID_VALID 0x80
551 #define SEQ_ID_INVALID 0x00
554 uint16_t high_seq_cnt
;
555 uint16_t low_seq_cnt
;
562 #define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1
563 #define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9
568 * ISP queue - ABTS Response IOCB entry structure definition for 24xx.
569 * The ABTS response to the ABTS received is sent by the
570 * target driver to the ISP 24xx.
571 * The IOCB is placed on the request queue.
573 struct abts_resp_to_24xx
{
574 uint8_t entry_type
; /* Entry type. */
575 uint8_t entry_count
; /* Entry count. */
576 uint8_t sys_define
; /* System defined. */
577 uint8_t entry_status
; /* Entry Status. */
580 uint16_t nport_handle
;
581 uint16_t control_flags
;
582 #define ABTS_CONTR_FLG_TERM_EXCHG BIT_0
584 uint8_t reserved_3
:4;
586 uint32_t exchange_address
;
587 struct fcp_hdr_le fcp_hdr_le
;
589 struct ba_acc_le ba_acct
;
590 struct ba_rjt_le ba_rjt
;
593 uint32_t exchange_addr_to_abort
;
597 * ISP queue - ABTS Response IOCB from ISP24xx Firmware entry structure.
598 * The ABTS response with completion status to the ABTS response
599 * (sent by the target driver to the ISP 24xx) is sent by the
600 * ISP24xx firmware to the target driver.
601 * The IOCB is placed on the response queue.
603 struct abts_resp_from_24xx_fw
{
604 uint8_t entry_type
; /* Entry type. */
605 uint8_t entry_count
; /* Entry count. */
606 uint8_t sys_define
; /* System defined. */
607 uint8_t entry_status
; /* Entry Status. */
609 uint16_t compl_status
;
610 #define ABTS_RESP_COMPL_SUCCESS 0
611 #define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31
612 uint16_t nport_handle
;
615 uint8_t reserved_3
:4;
617 uint32_t exchange_address
;
618 struct fcp_hdr_le fcp_hdr_le
;
619 uint8_t reserved_4
[8];
620 uint32_t error_subcode1
;
621 #define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E
622 uint32_t error_subcode2
;
623 uint32_t exchange_addr_to_abort
;
626 /********************************************************************\
627 * Type Definitions used by initiator & target halves
628 \********************************************************************/
630 struct qla_tgt_mgmt_cmd
;
634 * This structure provides a template of function calls that the
635 * target driver (from within qla_target.c) can issue to the
636 * target module (tcm_qla2xxx).
638 struct qla_tgt_func_tmpl
{
640 int (*handle_cmd
)(struct scsi_qla_host
*, struct qla_tgt_cmd
*,
641 unsigned char *, uint32_t, int, int, int);
642 int (*handle_data
)(struct qla_tgt_cmd
*);
643 int (*handle_tmr
)(struct qla_tgt_mgmt_cmd
*, uint32_t, uint8_t,
645 void (*free_cmd
)(struct qla_tgt_cmd
*);
646 void (*free_mcmd
)(struct qla_tgt_mgmt_cmd
*);
647 void (*free_session
)(struct qla_tgt_sess
*);
649 int (*check_initiator_node_acl
)(struct scsi_qla_host
*, unsigned char *,
650 void *, uint8_t *, uint16_t);
651 struct qla_tgt_sess
*(*find_sess_by_loop_id
)(struct scsi_qla_host
*,
653 struct qla_tgt_sess
*(*find_sess_by_s_id
)(struct scsi_qla_host
*,
655 void (*clear_nacl_from_fcport_map
)(struct qla_tgt_sess
*);
656 void (*put_sess
)(struct qla_tgt_sess
*);
657 void (*shutdown_sess
)(struct qla_tgt_sess
*);
660 int qla2x00_wait_for_hba_online(struct scsi_qla_host
*);
662 #include <target/target_core_base.h>
664 #define QLA_TGT_TIMEOUT 10 /* in seconds */
666 #define QLA_TGT_MAX_HW_PENDING_TIME 60 /* in seconds */
668 /* Immediate notify status constants */
669 #define IMM_NTFY_LIP_RESET 0x000E
670 #define IMM_NTFY_LIP_LINK_REINIT 0x000F
671 #define IMM_NTFY_IOCB_OVERFLOW 0x0016
672 #define IMM_NTFY_ABORT_TASK 0x0020
673 #define IMM_NTFY_PORT_LOGOUT 0x0029
674 #define IMM_NTFY_PORT_CONFIG 0x002A
675 #define IMM_NTFY_GLBL_TPRLO 0x002D
676 #define IMM_NTFY_GLBL_LOGO 0x002E
677 #define IMM_NTFY_RESOURCE 0x0034
678 #define IMM_NTFY_MSG_RX 0x0036
679 #define IMM_NTFY_SRR 0x0045
680 #define IMM_NTFY_ELS 0x0046
682 /* Immediate notify task flags */
683 #define IMM_NTFY_TASK_MGMT_SHIFT 8
685 #define QLA_TGT_CLEAR_ACA 0x40
686 #define QLA_TGT_TARGET_RESET 0x20
687 #define QLA_TGT_LUN_RESET 0x10
688 #define QLA_TGT_CLEAR_TS 0x04
689 #define QLA_TGT_ABORT_TS 0x02
690 #define QLA_TGT_ABORT_ALL_SESS 0xFFFF
691 #define QLA_TGT_ABORT_ALL 0xFFFE
692 #define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD
693 #define QLA_TGT_NEXUS_LOSS 0xFFFC
695 /* Notify Acknowledge flags */
696 #define NOTIFY_ACK_RES_COUNT BIT_8
697 #define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5
698 #define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
700 /* Command's states */
701 #define QLA_TGT_STATE_NEW 0 /* New command + target processing */
702 #define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */
703 #define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */
704 #define QLA_TGT_STATE_PROCESSED 3 /* target done processing */
705 #define QLA_TGT_STATE_ABORTED 4 /* Command aborted */
707 /* Special handles */
708 #define QLA_TGT_NULL_HANDLE 0
709 #define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~CTIO_COMPLETION_HANDLE_MARK)
711 /* ATIO task_codes field */
712 #define ATIO_SIMPLE_QUEUE 0
713 #define ATIO_HEAD_OF_QUEUE 1
714 #define ATIO_ORDERED_QUEUE 2
715 #define ATIO_ACA_QUEUE 4
716 #define ATIO_UNTAGGED 5
718 /* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */
719 #define FC_TM_SUCCESS 0
720 #define FC_TM_BAD_FCP_DATA 1
721 #define FC_TM_BAD_CMD 2
722 #define FC_TM_FCP_DATA_MISMATCH 3
723 #define FC_TM_REJECT 4
724 #define FC_TM_FAILED 5
727 * Error code of qlt_pre_xmit_response() meaning that cmd's exchange was
728 * terminated, so no more actions is needed and success should be returned
731 #define QLA_TGT_PRE_XMIT_RESP_CMD_ABORTED 0x1717
733 #if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
734 #define pci_dma_lo32(a) (a & 0xffffffff)
735 #define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff)
737 #define pci_dma_lo32(a) (a & 0xffffffff)
738 #define pci_dma_hi32(a) 0
741 #define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \
742 (((const uint8_t *)(sense))[0] & 0x70) == 0x70)
744 struct qla_port_24xx_data
{
745 uint8_t port_name
[WWN_SIZE
];
751 struct scsi_qla_host
*vha
;
752 struct qla_hw_data
*ha
;
755 * To sync between IRQ handlers and qlt_target_release(). Needed,
756 * because req_pkt() can drop/reaquire HW lock inside. Protected by
761 int datasegs_per_cmd
, datasegs_per_cont
, sg_tablesize
;
763 /* Target's flags, serialized by pha->hardware_lock */
764 unsigned int tgt_enable_64bit_addr
:1; /* 64-bits PCI addr enabled */
765 unsigned int link_reinit_iocb_pending
:1;
768 * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex
769 * OR hardware_lock for reading.
771 int tgt_stop
; /* the target mode driver is being stopped */
772 int tgt_stopped
; /* the target mode driver has been stopped */
774 /* Count of sessions refering qla_tgt. Protected by hardware_lock. */
777 /* Protected by hardware_lock. Addition also protected by tgt_mutex. */
778 struct list_head sess_list
;
780 /* Protected by hardware_lock */
781 struct list_head del_sess_list
;
782 struct delayed_work sess_del_work
;
784 spinlock_t sess_work_lock
;
785 struct list_head sess_works_list
;
786 struct work_struct sess_work
;
788 struct imm_ntfy_from_isp link_reinit_iocb
;
789 wait_queue_head_t waitQ
;
790 int notify_ack_expected
;
791 int abts_resp_expected
;
792 int modify_lun_expected
;
797 struct list_head srr_ctio_list
;
798 struct list_head srr_imm_list
;
799 struct work_struct srr_work
;
801 atomic_t tgt_global_resets_count
;
803 struct list_head tgt_list_entry
;
807 * Equivilant to IT Nexus (Initiator-Target)
809 struct qla_tgt_sess
{
813 unsigned int conf_compl_supported
:1;
814 unsigned int deleted
:1;
815 unsigned int local
:1;
816 unsigned int tearing_down
:1;
818 struct se_session
*se_sess
;
819 struct scsi_qla_host
*vha
;
822 struct list_head sess_list_entry
;
823 unsigned long expires
;
824 struct list_head del_list_entry
;
826 uint8_t port_name
[WWN_SIZE
];
827 struct work_struct free_work
;
831 struct qla_tgt_sess
*sess
;
833 struct se_cmd se_cmd
;
834 struct work_struct free_work
;
835 struct work_struct work
;
836 /* Sense buffer that will be mapped into outgoing status */
837 unsigned char sense_buffer
[TRANSPORT_SENSE_BUFFER
];
839 /* to save extra sess dereferences */
840 unsigned int conf_compl_supported
:1;
841 unsigned int sg_mapped
:1;
842 unsigned int free_sg
:1;
843 unsigned int aborted
:1; /* Needed in case of SRR */
844 unsigned int write_data_transferred
:1;
846 struct scatterlist
*sg
; /* cmd data buffer SG vector */
847 int sg_cnt
; /* SG segments count */
848 int bufflen
; /* cmd buffer length */
851 uint32_t unpacked_lun
;
852 enum dma_data_direction dma_data_direction
;
854 uint16_t loop_id
; /* to save extra sess dereferences */
855 struct qla_tgt
*tgt
; /* to save extra sess dereferences */
856 struct scsi_qla_host
*vha
;
857 struct list_head cmd_list
;
859 struct atio_from_isp atio
;
862 struct qla_tgt_sess_work_param
{
863 struct list_head sess_works_list_entry
;
865 #define QLA_TGT_SESS_WORK_ABORT 1
866 #define QLA_TGT_SESS_WORK_TM 2
870 struct abts_recv_from_24xx abts
;
871 struct imm_ntfy_from_isp tm_iocb
;
872 struct atio_from_isp tm_iocb2
;
876 struct qla_tgt_mgmt_cmd
{
879 struct qla_tgt_sess
*sess
;
880 struct se_cmd se_cmd
;
881 struct work_struct free_work
;
883 #define QLA24XX_MGMT_SEND_NACK 1
885 struct atio_from_isp atio
;
886 struct imm_ntfy_from_isp imm_ntfy
;
887 struct abts_recv_from_24xx abts
;
888 } __packed orig_iocb
;
892 struct qla_tgt_cmd
*cmd
;
895 struct scatterlist
*sg
; /* cmd data buffer SG vector */
899 uint16_t scsi_status
;
900 unsigned char *sense_buffer
;
901 int sense_buffer_len
;
906 struct qla_tgt_srr_imm
{
907 struct list_head srr_list_entry
;
909 struct imm_ntfy_from_isp imm_ntfy
;
912 struct qla_tgt_srr_ctio
{
913 struct list_head srr_list_entry
;
915 struct qla_tgt_cmd
*cmd
;
918 #define QLA_TGT_XMIT_DATA 1
919 #define QLA_TGT_XMIT_STATUS 2
920 #define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA)
923 extern struct qla_tgt_data qla_target
;
925 * Internal function prototypes
927 void qlt_disable_vha(struct scsi_qla_host
*);
930 * Function prototypes for qla_target.c logic used by qla2xxx LLD code.
932 extern int qlt_add_target(struct qla_hw_data
*, struct scsi_qla_host
*);
933 extern int qlt_remove_target(struct qla_hw_data
*, struct scsi_qla_host
*);
934 extern int qlt_lport_register(struct qla_tgt_func_tmpl
*, u64
,
935 int (*callback
)(struct scsi_qla_host
*), void *);
936 extern void qlt_lport_deregister(struct scsi_qla_host
*);
937 extern void qlt_unreg_sess(struct qla_tgt_sess
*);
938 extern void qlt_fc_port_added(struct scsi_qla_host
*, fc_port_t
*);
939 extern void qlt_fc_port_deleted(struct scsi_qla_host
*, fc_port_t
*);
940 extern void qlt_set_mode(struct scsi_qla_host
*ha
);
941 extern void qlt_clear_mode(struct scsi_qla_host
*ha
);
942 extern int __init
qlt_init(void);
943 extern void qlt_exit(void);
944 extern void qlt_update_vp_map(struct scsi_qla_host
*, int);
947 * This macro is used during early initializations when host->active_mode
948 * is not set. Right now, ha value is ignored.
950 #define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED)
952 static inline bool qla_tgt_mode_enabled(struct scsi_qla_host
*ha
)
954 return ha
->host
->active_mode
& MODE_TARGET
;
957 static inline bool qla_ini_mode_enabled(struct scsi_qla_host
*ha
)
959 return ha
->host
->active_mode
& MODE_INITIATOR
;
962 static inline void qla_reverse_ini_mode(struct scsi_qla_host
*ha
)
964 if (ha
->host
->active_mode
& MODE_INITIATOR
)
965 ha
->host
->active_mode
&= ~MODE_INITIATOR
;
967 ha
->host
->active_mode
|= MODE_INITIATOR
;
971 * Exported symbols from qla_target.c LLD logic used by qla2xxx code..
973 extern void qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host
*,
974 struct atio_from_isp
*);
975 extern void qlt_response_pkt_all_vps(struct scsi_qla_host
*, response_t
*);
976 extern int qlt_rdy_to_xfer(struct qla_tgt_cmd
*);
977 extern int qlt_xmit_response(struct qla_tgt_cmd
*, int, uint8_t);
978 extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd
*);
979 extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd
*);
980 extern void qlt_free_cmd(struct qla_tgt_cmd
*cmd
);
981 extern void qlt_ctio_completion(struct scsi_qla_host
*, uint32_t);
982 extern void qlt_async_event(uint16_t, struct scsi_qla_host
*, uint16_t *);
983 extern void qlt_enable_vha(struct scsi_qla_host
*);
984 extern void qlt_vport_create(struct scsi_qla_host
*, struct qla_hw_data
*);
985 extern void qlt_rff_id(struct scsi_qla_host
*, struct ct_sns_req
*);
986 extern void qlt_init_atio_q_entries(struct scsi_qla_host
*);
987 extern void qlt_24xx_process_atio_queue(struct scsi_qla_host
*);
988 extern void qlt_24xx_config_rings(struct scsi_qla_host
*,
989 device_reg_t __iomem
*);
990 extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host
*,
991 struct nvram_24xx
*);
992 extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host
*,
993 struct init_cb_24xx
*);
994 extern int qlt_24xx_process_response_error(struct scsi_qla_host
*,
995 struct sts_entry_24xx
*);
996 extern void qlt_modify_vp_config(struct scsi_qla_host
*,
997 struct vp_config_entry_24xx
*);
998 extern void qlt_probe_one_stage1(struct scsi_qla_host
*, struct qla_hw_data
*);
999 extern int qlt_mem_alloc(struct qla_hw_data
*);
1000 extern void qlt_mem_free(struct qla_hw_data
*);
1001 extern void qlt_stop_phase1(struct qla_tgt
*);
1002 extern void qlt_stop_phase2(struct qla_tgt
*);
1004 #endif /* __QLA_TARGET_H */