162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
462306a36Sopenharmony_ci *  Copyright (C) 2004 - 2005 Leonid Stoljar
562306a36Sopenharmony_ci *  Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
662306a36Sopenharmony_ci *  Copyright (C) 2007 - 2010 ID7 Ltd.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci *  Forward port and refactoring to modern qla2xxx and target/configfs
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci *  Copyright (C) 2010-2011 Nicholas A. Bellinger <nab@kernel.org>
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci *  Additional file for the target driver support.
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_ci/*
1562306a36Sopenharmony_ci * This is the global def file that is useful for including from the
1662306a36Sopenharmony_ci * target portion.
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#ifndef __QLA_TARGET_H
2062306a36Sopenharmony_ci#define __QLA_TARGET_H
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#include "qla_def.h"
2362306a36Sopenharmony_ci#include "qla_dsd.h"
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/*
2662306a36Sopenharmony_ci * Must be changed on any change in any initiator visible interfaces or
2762306a36Sopenharmony_ci * data in the target add-on
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_ci#define QLA2XXX_TARGET_MAGIC	269
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/*
3262306a36Sopenharmony_ci * Must be changed on any change in any target visible interfaces or
3362306a36Sopenharmony_ci * data in the initiator
3462306a36Sopenharmony_ci */
3562306a36Sopenharmony_ci#define QLA2XXX_INITIATOR_MAGIC   57222
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#define QLA2XXX_INI_MODE_STR_EXCLUSIVE	"exclusive"
3862306a36Sopenharmony_ci#define QLA2XXX_INI_MODE_STR_DISABLED	"disabled"
3962306a36Sopenharmony_ci#define QLA2XXX_INI_MODE_STR_ENABLED	"enabled"
4062306a36Sopenharmony_ci#define QLA2XXX_INI_MODE_STR_DUAL		"dual"
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define QLA2XXX_INI_MODE_EXCLUSIVE	0
4362306a36Sopenharmony_ci#define QLA2XXX_INI_MODE_DISABLED	1
4462306a36Sopenharmony_ci#define QLA2XXX_INI_MODE_ENABLED	2
4562306a36Sopenharmony_ci#define QLA2XXX_INI_MODE_DUAL	3
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define QLA2XXX_COMMAND_COUNT_INIT	250
4862306a36Sopenharmony_ci#define QLA2XXX_IMMED_NOTIFY_COUNT_INIT 250
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/*
5162306a36Sopenharmony_ci * Used to mark which completion handles (for RIO Status's) are for CTIO's
5262306a36Sopenharmony_ci * vs. regular (non-target) info. This is checked for in
5362306a36Sopenharmony_ci * qla2x00_process_response_queue() to see if a handle coming back in a
5462306a36Sopenharmony_ci * multi-complete should come to the tgt driver or be handled there by qla2xxx
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_ci#define CTIO_COMPLETION_HANDLE_MARK	BIT_29
5762306a36Sopenharmony_ci#if (CTIO_COMPLETION_HANDLE_MARK <= DEFAULT_OUTSTANDING_COMMANDS)
5862306a36Sopenharmony_ci#error "CTIO_COMPLETION_HANDLE_MARK not larger than "
5962306a36Sopenharmony_ci	"DEFAULT_OUTSTANDING_COMMANDS"
6062306a36Sopenharmony_ci#endif
6162306a36Sopenharmony_ci#define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* Used to mark CTIO as intermediate */
6462306a36Sopenharmony_ci#define CTIO_INTERMEDIATE_HANDLE_MARK	BIT_30
6562306a36Sopenharmony_ci#define QLA_TGT_NULL_HANDLE	0
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define QLA_TGT_HANDLE_MASK  0xF0000000
6862306a36Sopenharmony_ci#define QLA_QPID_HANDLE_MASK 0x00FF0000 /* qpair id mask */
6962306a36Sopenharmony_ci#define QLA_CMD_HANDLE_MASK  0x0000FFFF
7062306a36Sopenharmony_ci#define QLA_TGT_SKIP_HANDLE	(0xFFFFFFFF & ~QLA_TGT_HANDLE_MASK)
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define QLA_QPID_HANDLE_SHIFT 16
7362306a36Sopenharmony_ci#define GET_QID(_h) ((_h & QLA_QPID_HANDLE_MASK) >> QLA_QPID_HANDLE_SHIFT)
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#ifndef OF_SS_MODE_0
7762306a36Sopenharmony_ci/*
7862306a36Sopenharmony_ci * ISP target entries - Flags bit definitions.
7962306a36Sopenharmony_ci */
8062306a36Sopenharmony_ci#define OF_SS_MODE_0        0
8162306a36Sopenharmony_ci#define OF_SS_MODE_1        1
8262306a36Sopenharmony_ci#define OF_SS_MODE_2        2
8362306a36Sopenharmony_ci#define OF_SS_MODE_3        3
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#define OF_EXPL_CONF        BIT_5       /* Explicit Confirmation Requested */
8662306a36Sopenharmony_ci#define OF_DATA_IN          BIT_6       /* Data in to initiator */
8762306a36Sopenharmony_ci					/*  (data from target to initiator) */
8862306a36Sopenharmony_ci#define OF_DATA_OUT         BIT_7       /* Data out from initiator */
8962306a36Sopenharmony_ci					/*  (data from initiator to target) */
9062306a36Sopenharmony_ci#define OF_NO_DATA          (BIT_7 | BIT_6)
9162306a36Sopenharmony_ci#define OF_INC_RC           BIT_8       /* Increment command resource count */
9262306a36Sopenharmony_ci#define OF_FAST_POST        BIT_9       /* Enable mailbox fast posting. */
9362306a36Sopenharmony_ci#define OF_CONF_REQ         BIT_13      /* Confirmation Requested */
9462306a36Sopenharmony_ci#define OF_TERM_EXCH        BIT_14      /* Terminate exchange */
9562306a36Sopenharmony_ci#define OF_SSTS             BIT_15      /* Send SCSI status */
9662306a36Sopenharmony_ci#endif
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci#ifndef QLA_TGT_DATASEGS_PER_CMD32
9962306a36Sopenharmony_ci#define QLA_TGT_DATASEGS_PER_CMD32	3
10062306a36Sopenharmony_ci#define QLA_TGT_DATASEGS_PER_CONT32	7
10162306a36Sopenharmony_ci#define QLA_TGT_MAX_SG32(ql) \
10262306a36Sopenharmony_ci	(((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \
10362306a36Sopenharmony_ci		QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0)
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#define QLA_TGT_DATASEGS_PER_CMD64	2
10662306a36Sopenharmony_ci#define QLA_TGT_DATASEGS_PER_CONT64	5
10762306a36Sopenharmony_ci#define QLA_TGT_MAX_SG64(ql) \
10862306a36Sopenharmony_ci	(((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \
10962306a36Sopenharmony_ci		QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0)
11062306a36Sopenharmony_ci#endif
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#ifndef QLA_TGT_DATASEGS_PER_CMD_24XX
11362306a36Sopenharmony_ci#define QLA_TGT_DATASEGS_PER_CMD_24XX	1
11462306a36Sopenharmony_ci#define QLA_TGT_DATASEGS_PER_CONT_24XX	5
11562306a36Sopenharmony_ci#define QLA_TGT_MAX_SG_24XX(ql) \
11662306a36Sopenharmony_ci	(min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \
11762306a36Sopenharmony_ci		QLA_TGT_DATASEGS_PER_CONT_24XX*((ql) - 1)) : 0))
11862306a36Sopenharmony_ci#endif
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha))			\
12162306a36Sopenharmony_ci			 ? le16_to_cpu((iocb)->u.isp2x.target.extended)	\
12262306a36Sopenharmony_ci			 : (uint16_t)(iocb)->u.isp2x.target.id.standard)
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#ifndef NOTIFY_ACK_TYPE
12562306a36Sopenharmony_ci#define NOTIFY_ACK_TYPE 0x0E	  /* Notify acknowledge entry. */
12662306a36Sopenharmony_ci/*
12762306a36Sopenharmony_ci * ISP queue -	notify acknowledge entry structure definition.
12862306a36Sopenharmony_ci *		This is sent to the ISP from the target driver.
12962306a36Sopenharmony_ci */
13062306a36Sopenharmony_cistruct nack_to_isp {
13162306a36Sopenharmony_ci	uint8_t	 entry_type;		    /* Entry type. */
13262306a36Sopenharmony_ci	uint8_t	 entry_count;		    /* Entry count. */
13362306a36Sopenharmony_ci	uint8_t	 sys_define;		    /* System defined. */
13462306a36Sopenharmony_ci	uint8_t	 entry_status;		    /* Entry Status. */
13562306a36Sopenharmony_ci	union {
13662306a36Sopenharmony_ci		struct {
13762306a36Sopenharmony_ci			__le32	sys_define_2; /* System defined. */
13862306a36Sopenharmony_ci			target_id_t target;
13962306a36Sopenharmony_ci			uint8_t	 target_id;
14062306a36Sopenharmony_ci			uint8_t	 reserved_1;
14162306a36Sopenharmony_ci			__le16	flags;
14262306a36Sopenharmony_ci			__le16	resp_code;
14362306a36Sopenharmony_ci			__le16	status;
14462306a36Sopenharmony_ci			__le16	task_flags;
14562306a36Sopenharmony_ci			__le16	seq_id;
14662306a36Sopenharmony_ci			__le16	srr_rx_id;
14762306a36Sopenharmony_ci			__le32	srr_rel_offs;
14862306a36Sopenharmony_ci			__le16	srr_ui;
14962306a36Sopenharmony_ci			__le16	srr_flags;
15062306a36Sopenharmony_ci			__le16	srr_reject_code;
15162306a36Sopenharmony_ci			uint8_t  srr_reject_vendor_uniq;
15262306a36Sopenharmony_ci			uint8_t  srr_reject_code_expl;
15362306a36Sopenharmony_ci			uint8_t  reserved_2[24];
15462306a36Sopenharmony_ci		} isp2x;
15562306a36Sopenharmony_ci		struct {
15662306a36Sopenharmony_ci			uint32_t handle;
15762306a36Sopenharmony_ci			__le16	nport_handle;
15862306a36Sopenharmony_ci			uint16_t reserved_1;
15962306a36Sopenharmony_ci			__le16	flags;
16062306a36Sopenharmony_ci			__le16	srr_rx_id;
16162306a36Sopenharmony_ci			__le16	status;
16262306a36Sopenharmony_ci			uint8_t  status_subcode;
16362306a36Sopenharmony_ci			uint8_t  fw_handle;
16462306a36Sopenharmony_ci			__le32	exchange_address;
16562306a36Sopenharmony_ci			__le32	srr_rel_offs;
16662306a36Sopenharmony_ci			__le16	srr_ui;
16762306a36Sopenharmony_ci			__le16	srr_flags;
16862306a36Sopenharmony_ci			uint8_t  reserved_4[19];
16962306a36Sopenharmony_ci			uint8_t  vp_index;
17062306a36Sopenharmony_ci			uint8_t  srr_reject_vendor_uniq;
17162306a36Sopenharmony_ci			uint8_t  srr_reject_code_expl;
17262306a36Sopenharmony_ci			uint8_t  srr_reject_code;
17362306a36Sopenharmony_ci			uint8_t  reserved_5[5];
17462306a36Sopenharmony_ci		} isp24;
17562306a36Sopenharmony_ci	} u;
17662306a36Sopenharmony_ci	uint8_t  reserved[2];
17762306a36Sopenharmony_ci	__le16	ox_id;
17862306a36Sopenharmony_ci} __packed;
17962306a36Sopenharmony_ci#define NOTIFY_ACK_FLAGS_FCSP		BIT_5
18062306a36Sopenharmony_ci#define NOTIFY_ACK_FLAGS_TERMINATE	BIT_3
18162306a36Sopenharmony_ci#define NOTIFY_ACK_SRR_FLAGS_ACCEPT	0
18262306a36Sopenharmony_ci#define NOTIFY_ACK_SRR_FLAGS_REJECT	1
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci#define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM	0x9
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci#define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL		0
18762306a36Sopenharmony_ci#define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA	0x2a
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci#define NOTIFY_ACK_SUCCESS      0x01
19062306a36Sopenharmony_ci#endif
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#ifndef ACCEPT_TGT_IO_TYPE
19362306a36Sopenharmony_ci#define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */
19462306a36Sopenharmony_ci#endif
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#ifndef CONTINUE_TGT_IO_TYPE
19762306a36Sopenharmony_ci#define CONTINUE_TGT_IO_TYPE 0x17
19862306a36Sopenharmony_ci/*
19962306a36Sopenharmony_ci * ISP queue -	Continue Target I/O (CTIO) entry for status mode 0 structure.
20062306a36Sopenharmony_ci *		This structure is sent to the ISP 2xxx from target driver.
20162306a36Sopenharmony_ci */
20262306a36Sopenharmony_cistruct ctio_to_2xxx {
20362306a36Sopenharmony_ci	uint8_t	 entry_type;		/* Entry type. */
20462306a36Sopenharmony_ci	uint8_t	 entry_count;		/* Entry count. */
20562306a36Sopenharmony_ci	uint8_t	 sys_define;		/* System defined. */
20662306a36Sopenharmony_ci	uint8_t	 entry_status;		/* Entry Status. */
20762306a36Sopenharmony_ci	uint32_t handle;		/* System defined handle */
20862306a36Sopenharmony_ci	target_id_t target;
20962306a36Sopenharmony_ci	__le16	rx_id;
21062306a36Sopenharmony_ci	__le16	flags;
21162306a36Sopenharmony_ci	__le16	status;
21262306a36Sopenharmony_ci	__le16	timeout;		/* 0 = 30 seconds, 0xFFFF = disable */
21362306a36Sopenharmony_ci	__le16	dseg_count;		/* Data segment count. */
21462306a36Sopenharmony_ci	__le32	relative_offset;
21562306a36Sopenharmony_ci	__le32	residual;
21662306a36Sopenharmony_ci	__le16	reserved_1[3];
21762306a36Sopenharmony_ci	__le16	scsi_status;
21862306a36Sopenharmony_ci	__le32	transfer_length;
21962306a36Sopenharmony_ci	struct dsd32 dsd[3];
22062306a36Sopenharmony_ci} __packed;
22162306a36Sopenharmony_ci#define ATIO_PATH_INVALID       0x07
22262306a36Sopenharmony_ci#define ATIO_CANT_PROV_CAP      0x16
22362306a36Sopenharmony_ci#define ATIO_CDB_VALID          0x3D
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci#define ATIO_EXEC_READ          BIT_1
22662306a36Sopenharmony_ci#define ATIO_EXEC_WRITE         BIT_0
22762306a36Sopenharmony_ci#endif
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci#ifndef CTIO_A64_TYPE
23062306a36Sopenharmony_ci#define CTIO_A64_TYPE 0x1F
23162306a36Sopenharmony_ci#define CTIO_SUCCESS			0x01
23262306a36Sopenharmony_ci#define CTIO_ABORTED			0x02
23362306a36Sopenharmony_ci#define CTIO_INVALID_RX_ID		0x08
23462306a36Sopenharmony_ci#define CTIO_TIMEOUT			0x0B
23562306a36Sopenharmony_ci#define CTIO_DIF_ERROR			0x0C     /* DIF error detected  */
23662306a36Sopenharmony_ci#define CTIO_LIP_RESET			0x0E
23762306a36Sopenharmony_ci#define CTIO_TARGET_RESET		0x17
23862306a36Sopenharmony_ci#define CTIO_PORT_UNAVAILABLE		0x28
23962306a36Sopenharmony_ci#define CTIO_PORT_LOGGED_OUT		0x29
24062306a36Sopenharmony_ci#define CTIO_PORT_CONF_CHANGED		0x2A
24162306a36Sopenharmony_ci#define CTIO_SRR_RECEIVED		0x45
24262306a36Sopenharmony_ci#define CTIO_FAST_AUTH_ERR		0x63
24362306a36Sopenharmony_ci#define CTIO_FAST_INCOMP_PAD_LEN	0x65
24462306a36Sopenharmony_ci#define CTIO_FAST_INVALID_REQ		0x66
24562306a36Sopenharmony_ci#define CTIO_FAST_SPI_ERR		0x67
24662306a36Sopenharmony_ci#endif
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci#ifndef CTIO_RET_TYPE
24962306a36Sopenharmony_ci#define CTIO_RET_TYPE	0x17		/* CTIO return entry */
25062306a36Sopenharmony_ci#define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */
25162306a36Sopenharmony_ci#endif
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_cistruct fcp_hdr {
25462306a36Sopenharmony_ci	uint8_t  r_ctl;
25562306a36Sopenharmony_ci	be_id_t  d_id;
25662306a36Sopenharmony_ci	uint8_t  cs_ctl;
25762306a36Sopenharmony_ci	be_id_t  s_id;
25862306a36Sopenharmony_ci	uint8_t  type;
25962306a36Sopenharmony_ci	uint8_t  f_ctl[3];
26062306a36Sopenharmony_ci	uint8_t  seq_id;
26162306a36Sopenharmony_ci	uint8_t  df_ctl;
26262306a36Sopenharmony_ci	uint16_t seq_cnt;
26362306a36Sopenharmony_ci	__be16   ox_id;
26462306a36Sopenharmony_ci	uint16_t rx_id;
26562306a36Sopenharmony_ci	__le32	parameter;
26662306a36Sopenharmony_ci};
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_cistruct fcp_hdr_le {
26962306a36Sopenharmony_ci	le_id_t  d_id;
27062306a36Sopenharmony_ci	uint8_t  r_ctl;
27162306a36Sopenharmony_ci	le_id_t  s_id;
27262306a36Sopenharmony_ci	uint8_t  cs_ctl;
27362306a36Sopenharmony_ci	uint8_t  f_ctl[3];
27462306a36Sopenharmony_ci	uint8_t  type;
27562306a36Sopenharmony_ci	__le16	seq_cnt;
27662306a36Sopenharmony_ci	uint8_t  df_ctl;
27762306a36Sopenharmony_ci	uint8_t  seq_id;
27862306a36Sopenharmony_ci	__le16	rx_id;
27962306a36Sopenharmony_ci	__le16	ox_id;
28062306a36Sopenharmony_ci	__le32	parameter;
28162306a36Sopenharmony_ci};
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci#define F_CTL_EXCH_CONTEXT_RESP	BIT_23
28462306a36Sopenharmony_ci#define F_CTL_SEQ_CONTEXT_RESIP	BIT_22
28562306a36Sopenharmony_ci#define F_CTL_LAST_SEQ		BIT_20
28662306a36Sopenharmony_ci#define F_CTL_END_SEQ		BIT_19
28762306a36Sopenharmony_ci#define F_CTL_SEQ_INITIATIVE	BIT_16
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci#define R_CTL_BASIC_LINK_SERV	0x80
29062306a36Sopenharmony_ci#define R_CTL_B_ACC		0x4
29162306a36Sopenharmony_ci#define R_CTL_B_RJT		0x5
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_cistruct atio7_fcp_cmnd {
29462306a36Sopenharmony_ci	uint64_t lun;
29562306a36Sopenharmony_ci	uint8_t  cmnd_ref;
29662306a36Sopenharmony_ci	uint8_t  task_attr:3;
29762306a36Sopenharmony_ci	uint8_t  reserved:5;
29862306a36Sopenharmony_ci	uint8_t  task_mgmt_flags;
29962306a36Sopenharmony_ci#define FCP_CMND_TASK_MGMT_CLEAR_ACA		6
30062306a36Sopenharmony_ci#define FCP_CMND_TASK_MGMT_TARGET_RESET		5
30162306a36Sopenharmony_ci#define FCP_CMND_TASK_MGMT_LU_RESET		4
30262306a36Sopenharmony_ci#define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET	2
30362306a36Sopenharmony_ci#define FCP_CMND_TASK_MGMT_ABORT_TASK_SET	1
30462306a36Sopenharmony_ci	uint8_t  wrdata:1;
30562306a36Sopenharmony_ci	uint8_t  rddata:1;
30662306a36Sopenharmony_ci	uint8_t  add_cdb_len:6;
30762306a36Sopenharmony_ci	uint8_t  cdb[16];
30862306a36Sopenharmony_ci	/*
30962306a36Sopenharmony_ci	 * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4
31062306a36Sopenharmony_ci	 * only to make sizeof(struct atio7_fcp_cmnd) be as expected by
31162306a36Sopenharmony_ci	 * BUILD_BUG_ON in qlt_init().
31262306a36Sopenharmony_ci	 */
31362306a36Sopenharmony_ci	uint8_t  add_cdb[4];
31462306a36Sopenharmony_ci	/* __le32	data_length; */
31562306a36Sopenharmony_ci} __packed;
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci/*
31862306a36Sopenharmony_ci * ISP queue -	Accept Target I/O (ATIO) type entry IOCB structure.
31962306a36Sopenharmony_ci *		This is sent from the ISP to the target driver.
32062306a36Sopenharmony_ci */
32162306a36Sopenharmony_cistruct atio_from_isp {
32262306a36Sopenharmony_ci	union {
32362306a36Sopenharmony_ci		struct {
32462306a36Sopenharmony_ci			__le16	entry_hdr;
32562306a36Sopenharmony_ci			uint8_t  sys_define;   /* System defined. */
32662306a36Sopenharmony_ci			uint8_t  entry_status; /* Entry Status.   */
32762306a36Sopenharmony_ci			__le32	sys_define_2; /* System defined. */
32862306a36Sopenharmony_ci			target_id_t target;
32962306a36Sopenharmony_ci			__le16	rx_id;
33062306a36Sopenharmony_ci			__le16	flags;
33162306a36Sopenharmony_ci			__le16	status;
33262306a36Sopenharmony_ci			uint8_t  command_ref;
33362306a36Sopenharmony_ci			uint8_t  task_codes;
33462306a36Sopenharmony_ci			uint8_t  task_flags;
33562306a36Sopenharmony_ci			uint8_t  execution_codes;
33662306a36Sopenharmony_ci			uint8_t  cdb[MAX_CMDSZ];
33762306a36Sopenharmony_ci			__le32	data_length;
33862306a36Sopenharmony_ci			__le16	lun;
33962306a36Sopenharmony_ci			uint8_t  initiator_port_name[WWN_SIZE]; /* on qla23xx */
34062306a36Sopenharmony_ci			__le16	reserved_32[6];
34162306a36Sopenharmony_ci			__le16	ox_id;
34262306a36Sopenharmony_ci		} isp2x;
34362306a36Sopenharmony_ci		struct {
34462306a36Sopenharmony_ci			__le16	entry_hdr;
34562306a36Sopenharmony_ci			uint8_t  fcp_cmnd_len_low;
34662306a36Sopenharmony_ci			uint8_t  fcp_cmnd_len_high:4;
34762306a36Sopenharmony_ci			uint8_t  attr:4;
34862306a36Sopenharmony_ci			__le32	exchange_addr;
34962306a36Sopenharmony_ci#define ATIO_EXCHANGE_ADDRESS_UNKNOWN	0xFFFFFFFF
35062306a36Sopenharmony_ci			struct fcp_hdr fcp_hdr;
35162306a36Sopenharmony_ci			struct atio7_fcp_cmnd fcp_cmnd;
35262306a36Sopenharmony_ci		} isp24;
35362306a36Sopenharmony_ci		struct {
35462306a36Sopenharmony_ci			uint8_t  entry_type;	/* Entry type. */
35562306a36Sopenharmony_ci			uint8_t  entry_count;	/* Entry count. */
35662306a36Sopenharmony_ci			__le16	 attr_n_length;
35762306a36Sopenharmony_ci#define FCP_CMD_LENGTH_MASK 0x0fff
35862306a36Sopenharmony_ci#define FCP_CMD_LENGTH_MIN  0x38
35962306a36Sopenharmony_ci			uint8_t  data[56];
36062306a36Sopenharmony_ci			__le32	signature;
36162306a36Sopenharmony_ci#define ATIO_PROCESSED 0xDEADDEAD		/* Signature */
36262306a36Sopenharmony_ci		} raw;
36362306a36Sopenharmony_ci	} u;
36462306a36Sopenharmony_ci} __packed;
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_cistatic inline int fcpcmd_is_corrupted(struct atio *atio)
36762306a36Sopenharmony_ci{
36862306a36Sopenharmony_ci	if (atio->entry_type == ATIO_TYPE7 &&
36962306a36Sopenharmony_ci	    ((le16_to_cpu(atio->attr_n_length) & FCP_CMD_LENGTH_MASK) <
37062306a36Sopenharmony_ci	     FCP_CMD_LENGTH_MIN))
37162306a36Sopenharmony_ci		return 1;
37262306a36Sopenharmony_ci	else
37362306a36Sopenharmony_ci		return 0;
37462306a36Sopenharmony_ci}
37562306a36Sopenharmony_ci
37662306a36Sopenharmony_ci/* adjust corrupted atio so we won't trip over the same entry again. */
37762306a36Sopenharmony_cistatic inline void adjust_corrupted_atio(struct atio_from_isp *atio)
37862306a36Sopenharmony_ci{
37962306a36Sopenharmony_ci	atio->u.raw.attr_n_length = cpu_to_le16(FCP_CMD_LENGTH_MIN);
38062306a36Sopenharmony_ci	atio->u.isp24.fcp_cmnd.add_cdb_len = 0;
38162306a36Sopenharmony_ci}
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_cistatic inline int get_datalen_for_atio(struct atio_from_isp *atio)
38462306a36Sopenharmony_ci{
38562306a36Sopenharmony_ci	int len = atio->u.isp24.fcp_cmnd.add_cdb_len;
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_ci	return get_unaligned_be32(&atio->u.isp24.fcp_cmnd.add_cdb[len * 4]);
38862306a36Sopenharmony_ci}
38962306a36Sopenharmony_ci
39062306a36Sopenharmony_ci#define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_ci/*
39362306a36Sopenharmony_ci * ISP queue -	Continue Target I/O (ATIO) type 7 entry (for 24xx) structure.
39462306a36Sopenharmony_ci *		This structure is sent to the ISP 24xx from the target driver.
39562306a36Sopenharmony_ci */
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_cistruct ctio7_to_24xx {
39862306a36Sopenharmony_ci	uint8_t	 entry_type;		    /* Entry type. */
39962306a36Sopenharmony_ci	uint8_t	 entry_count;		    /* Entry count. */
40062306a36Sopenharmony_ci	uint8_t	 sys_define;		    /* System defined. */
40162306a36Sopenharmony_ci	uint8_t	 entry_status;		    /* Entry Status. */
40262306a36Sopenharmony_ci	uint32_t handle;		    /* System defined handle */
40362306a36Sopenharmony_ci	__le16	nport_handle;
40462306a36Sopenharmony_ci#define CTIO7_NHANDLE_UNRECOGNIZED	0xFFFF
40562306a36Sopenharmony_ci	__le16	timeout;
40662306a36Sopenharmony_ci	__le16	dseg_count;		    /* Data segment count. */
40762306a36Sopenharmony_ci	uint8_t  vp_index;
40862306a36Sopenharmony_ci	uint8_t  add_flags;
40962306a36Sopenharmony_ci	le_id_t  initiator_id;
41062306a36Sopenharmony_ci	uint8_t  reserved;
41162306a36Sopenharmony_ci	__le32	exchange_addr;
41262306a36Sopenharmony_ci	union {
41362306a36Sopenharmony_ci		struct {
41462306a36Sopenharmony_ci			__le16	reserved1;
41562306a36Sopenharmony_ci			__le16 flags;
41662306a36Sopenharmony_ci			union {
41762306a36Sopenharmony_ci				__le32	residual;
41862306a36Sopenharmony_ci				struct {
41962306a36Sopenharmony_ci					uint8_t rsvd1;
42062306a36Sopenharmony_ci					uint8_t edif_flags;
42162306a36Sopenharmony_ci#define EF_EN_EDIF	BIT_0
42262306a36Sopenharmony_ci#define EF_NEW_SA	BIT_1
42362306a36Sopenharmony_ci					uint16_t rsvd2;
42462306a36Sopenharmony_ci				};
42562306a36Sopenharmony_ci			};
42662306a36Sopenharmony_ci			__le16 ox_id;
42762306a36Sopenharmony_ci			__le16	scsi_status;
42862306a36Sopenharmony_ci			__le32	relative_offset;
42962306a36Sopenharmony_ci			__le32	reserved2;
43062306a36Sopenharmony_ci			__le32	transfer_length;
43162306a36Sopenharmony_ci			__le32	reserved3;
43262306a36Sopenharmony_ci			struct dsd64 dsd;
43362306a36Sopenharmony_ci		} status0;
43462306a36Sopenharmony_ci		struct {
43562306a36Sopenharmony_ci			__le16	sense_length;
43662306a36Sopenharmony_ci			__le16 flags;
43762306a36Sopenharmony_ci			__le32	residual;
43862306a36Sopenharmony_ci			__le16 ox_id;
43962306a36Sopenharmony_ci			__le16	scsi_status;
44062306a36Sopenharmony_ci			__le16	response_len;
44162306a36Sopenharmony_ci			__le16	reserved;
44262306a36Sopenharmony_ci			uint8_t sense_data[24];
44362306a36Sopenharmony_ci		} status1;
44462306a36Sopenharmony_ci	} u;
44562306a36Sopenharmony_ci} __packed;
44662306a36Sopenharmony_ci
44762306a36Sopenharmony_ci/*
44862306a36Sopenharmony_ci * ISP queue - CTIO type 7 from ISP 24xx to target driver
44962306a36Sopenharmony_ci * returned entry structure.
45062306a36Sopenharmony_ci */
45162306a36Sopenharmony_cistruct ctio7_from_24xx {
45262306a36Sopenharmony_ci	uint8_t	 entry_type;		    /* Entry type. */
45362306a36Sopenharmony_ci	uint8_t	 entry_count;		    /* Entry count. */
45462306a36Sopenharmony_ci	uint8_t	 sys_define;		    /* System defined. */
45562306a36Sopenharmony_ci	uint8_t	 entry_status;		    /* Entry Status. */
45662306a36Sopenharmony_ci	uint32_t handle;		    /* System defined handle */
45762306a36Sopenharmony_ci	__le16	status;
45862306a36Sopenharmony_ci	__le16	timeout;
45962306a36Sopenharmony_ci	__le16	dseg_count;		    /* Data segment count. */
46062306a36Sopenharmony_ci	uint8_t  vp_index;
46162306a36Sopenharmony_ci	uint8_t  reserved1[5];
46262306a36Sopenharmony_ci	__le32	exchange_address;
46362306a36Sopenharmony_ci	__le16	edif_sa_index;
46462306a36Sopenharmony_ci	__le16	flags;
46562306a36Sopenharmony_ci	__le32	residual;
46662306a36Sopenharmony_ci	__le16	ox_id;
46762306a36Sopenharmony_ci	__le16	reserved3;
46862306a36Sopenharmony_ci	__le32	relative_offset;
46962306a36Sopenharmony_ci	uint8_t  reserved4[24];
47062306a36Sopenharmony_ci} __packed;
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_ci/* CTIO7 flags values */
47362306a36Sopenharmony_ci#define CTIO7_FLAGS_SEND_STATUS		BIT_15
47462306a36Sopenharmony_ci#define CTIO7_FLAGS_TERMINATE		BIT_14
47562306a36Sopenharmony_ci#define CTIO7_FLAGS_CONFORM_REQ		BIT_13
47662306a36Sopenharmony_ci#define CTIO7_FLAGS_DONT_RET_CTIO	BIT_8
47762306a36Sopenharmony_ci#define CTIO7_FLAGS_STATUS_MODE_0	0
47862306a36Sopenharmony_ci#define CTIO7_FLAGS_STATUS_MODE_1	BIT_6
47962306a36Sopenharmony_ci#define CTIO7_FLAGS_STATUS_MODE_2	BIT_7
48062306a36Sopenharmony_ci#define CTIO7_FLAGS_EXPLICIT_CONFORM	BIT_5
48162306a36Sopenharmony_ci#define CTIO7_FLAGS_CONFIRM_SATISF	BIT_4
48262306a36Sopenharmony_ci#define CTIO7_FLAGS_DSD_PTR		BIT_2
48362306a36Sopenharmony_ci#define CTIO7_FLAGS_DATA_IN		BIT_1 /* data to initiator */
48462306a36Sopenharmony_ci#define CTIO7_FLAGS_DATA_OUT		BIT_0 /* data from initiator */
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci#define ELS_PLOGI			0x3
48762306a36Sopenharmony_ci#define ELS_FLOGI			0x4
48862306a36Sopenharmony_ci#define ELS_LOGO			0x5
48962306a36Sopenharmony_ci#define ELS_PRLI			0x20
49062306a36Sopenharmony_ci#define ELS_PRLO			0x21
49162306a36Sopenharmony_ci#define ELS_TPRLO			0x24
49262306a36Sopenharmony_ci#define ELS_PDISC			0x50
49362306a36Sopenharmony_ci#define ELS_ADISC			0x52
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_ci/*
49662306a36Sopenharmony_ci *CTIO Type CRC_2 IOCB
49762306a36Sopenharmony_ci */
49862306a36Sopenharmony_cistruct ctio_crc2_to_fw {
49962306a36Sopenharmony_ci	uint8_t entry_type;		/* Entry type. */
50062306a36Sopenharmony_ci#define CTIO_CRC2 0x7A
50162306a36Sopenharmony_ci	uint8_t entry_count;		/* Entry count. */
50262306a36Sopenharmony_ci	uint8_t sys_define;		/* System defined. */
50362306a36Sopenharmony_ci	uint8_t entry_status;		/* Entry Status. */
50462306a36Sopenharmony_ci
50562306a36Sopenharmony_ci	uint32_t handle;		/* System handle. */
50662306a36Sopenharmony_ci	__le16	nport_handle;		/* N_PORT handle. */
50762306a36Sopenharmony_ci	__le16 timeout;		/* Command timeout. */
50862306a36Sopenharmony_ci
50962306a36Sopenharmony_ci	__le16	dseg_count;		/* Data segment count. */
51062306a36Sopenharmony_ci	uint8_t  vp_index;
51162306a36Sopenharmony_ci	uint8_t  add_flags;		/* additional flags */
51262306a36Sopenharmony_ci#define CTIO_CRC2_AF_DIF_DSD_ENA BIT_3
51362306a36Sopenharmony_ci
51462306a36Sopenharmony_ci	le_id_t  initiator_id;		/* initiator ID */
51562306a36Sopenharmony_ci	uint8_t  reserved1;
51662306a36Sopenharmony_ci	__le32	exchange_addr;		/* rcv exchange address */
51762306a36Sopenharmony_ci	__le16	reserved2;
51862306a36Sopenharmony_ci	__le16 flags;			/* refer to CTIO7 flags values */
51962306a36Sopenharmony_ci	__le32	residual;
52062306a36Sopenharmony_ci	__le16 ox_id;
52162306a36Sopenharmony_ci	__le16	scsi_status;
52262306a36Sopenharmony_ci	__le32 relative_offset;
52362306a36Sopenharmony_ci	__le32	reserved5;
52462306a36Sopenharmony_ci	__le32 transfer_length;		/* total fc transfer length */
52562306a36Sopenharmony_ci	__le32	reserved6;
52662306a36Sopenharmony_ci	__le64	 crc_context_address __packed; /* Data segment address. */
52762306a36Sopenharmony_ci	__le16	crc_context_len;	/* Data segment length. */
52862306a36Sopenharmony_ci	__le16	reserved_1;		/* MUST be set to 0. */
52962306a36Sopenharmony_ci};
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci/* CTIO Type CRC_x Status IOCB */
53262306a36Sopenharmony_cistruct ctio_crc_from_fw {
53362306a36Sopenharmony_ci	uint8_t entry_type;		/* Entry type. */
53462306a36Sopenharmony_ci	uint8_t entry_count;		/* Entry count. */
53562306a36Sopenharmony_ci	uint8_t sys_define;		/* System defined. */
53662306a36Sopenharmony_ci	uint8_t entry_status;		/* Entry Status. */
53762306a36Sopenharmony_ci
53862306a36Sopenharmony_ci	uint32_t handle;		/* System handle. */
53962306a36Sopenharmony_ci	__le16	status;
54062306a36Sopenharmony_ci	__le16	timeout;		/* Command timeout. */
54162306a36Sopenharmony_ci	__le16	dseg_count;		/* Data segment count. */
54262306a36Sopenharmony_ci	__le32	reserved1;
54362306a36Sopenharmony_ci	__le16	state_flags;
54462306a36Sopenharmony_ci#define CTIO_CRC_SF_DIF_CHOPPED BIT_4
54562306a36Sopenharmony_ci
54662306a36Sopenharmony_ci	__le32	exchange_address;	/* rcv exchange address */
54762306a36Sopenharmony_ci	__le16	reserved2;
54862306a36Sopenharmony_ci	__le16	flags;
54962306a36Sopenharmony_ci	__le32	resid_xfer_length;
55062306a36Sopenharmony_ci	__le16	ox_id;
55162306a36Sopenharmony_ci	uint8_t  reserved3[12];
55262306a36Sopenharmony_ci	__le16	runt_guard;		/* reported runt blk guard */
55362306a36Sopenharmony_ci	uint8_t  actual_dif[8];
55462306a36Sopenharmony_ci	uint8_t  expected_dif[8];
55562306a36Sopenharmony_ci} __packed;
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ci/*
55862306a36Sopenharmony_ci * ISP queue - ABTS received/response entries structure definition for 24xx.
55962306a36Sopenharmony_ci */
56062306a36Sopenharmony_ci#define ABTS_RECV_24XX		0x54 /* ABTS received (for 24xx) */
56162306a36Sopenharmony_ci#define ABTS_RESP_24XX		0x55 /* ABTS responce (for 24xx) */
56262306a36Sopenharmony_ci
56362306a36Sopenharmony_ci/*
56462306a36Sopenharmony_ci * ISP queue -	ABTS received IOCB entry structure definition for 24xx.
56562306a36Sopenharmony_ci *		The ABTS BLS received from the wire is sent to the
56662306a36Sopenharmony_ci *		target driver by the ISP 24xx.
56762306a36Sopenharmony_ci *		The IOCB is placed on the response queue.
56862306a36Sopenharmony_ci */
56962306a36Sopenharmony_cistruct abts_recv_from_24xx {
57062306a36Sopenharmony_ci	uint8_t	 entry_type;		    /* Entry type. */
57162306a36Sopenharmony_ci	uint8_t	 entry_count;		    /* Entry count. */
57262306a36Sopenharmony_ci	uint8_t	 sys_define;		    /* System defined. */
57362306a36Sopenharmony_ci	uint8_t	 entry_status;		    /* Entry Status. */
57462306a36Sopenharmony_ci	uint8_t  reserved_1[6];
57562306a36Sopenharmony_ci	__le16	nport_handle;
57662306a36Sopenharmony_ci	uint8_t  reserved_2[2];
57762306a36Sopenharmony_ci	uint8_t  vp_index;
57862306a36Sopenharmony_ci	uint8_t  reserved_3:4;
57962306a36Sopenharmony_ci	uint8_t  sof_type:4;
58062306a36Sopenharmony_ci	__le32	exchange_address;
58162306a36Sopenharmony_ci	struct fcp_hdr_le fcp_hdr_le;
58262306a36Sopenharmony_ci	uint8_t  reserved_4[16];
58362306a36Sopenharmony_ci	__le32	exchange_addr_to_abort;
58462306a36Sopenharmony_ci} __packed;
58562306a36Sopenharmony_ci
58662306a36Sopenharmony_ci#define ABTS_PARAM_ABORT_SEQ		BIT_0
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_cistruct ba_acc_le {
58962306a36Sopenharmony_ci	__le16	reserved;
59062306a36Sopenharmony_ci	uint8_t  seq_id_last;
59162306a36Sopenharmony_ci	uint8_t  seq_id_valid;
59262306a36Sopenharmony_ci#define SEQ_ID_VALID	0x80
59362306a36Sopenharmony_ci#define SEQ_ID_INVALID	0x00
59462306a36Sopenharmony_ci	__le16	rx_id;
59562306a36Sopenharmony_ci	__le16	ox_id;
59662306a36Sopenharmony_ci	__le16	high_seq_cnt;
59762306a36Sopenharmony_ci	__le16	low_seq_cnt;
59862306a36Sopenharmony_ci} __packed;
59962306a36Sopenharmony_ci
60062306a36Sopenharmony_cistruct ba_rjt_le {
60162306a36Sopenharmony_ci	uint8_t vendor_uniq;
60262306a36Sopenharmony_ci	uint8_t reason_expl;
60362306a36Sopenharmony_ci	uint8_t reason_code;
60462306a36Sopenharmony_ci#define BA_RJT_REASON_CODE_INVALID_COMMAND	0x1
60562306a36Sopenharmony_ci#define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM	0x9
60662306a36Sopenharmony_ci	uint8_t reserved;
60762306a36Sopenharmony_ci} __packed;
60862306a36Sopenharmony_ci
60962306a36Sopenharmony_ci/*
61062306a36Sopenharmony_ci * ISP queue -	ABTS Response IOCB entry structure definition for 24xx.
61162306a36Sopenharmony_ci *		The ABTS response to the ABTS received is sent by the
61262306a36Sopenharmony_ci *		target driver to the ISP 24xx.
61362306a36Sopenharmony_ci *		The IOCB is placed on the request queue.
61462306a36Sopenharmony_ci */
61562306a36Sopenharmony_cistruct abts_resp_to_24xx {
61662306a36Sopenharmony_ci	uint8_t	 entry_type;		    /* Entry type. */
61762306a36Sopenharmony_ci	uint8_t	 entry_count;		    /* Entry count. */
61862306a36Sopenharmony_ci	uint8_t	 sys_define;		    /* System defined. */
61962306a36Sopenharmony_ci	uint8_t	 entry_status;		    /* Entry Status. */
62062306a36Sopenharmony_ci	uint32_t handle;
62162306a36Sopenharmony_ci	__le16	reserved_1;
62262306a36Sopenharmony_ci	__le16	nport_handle;
62362306a36Sopenharmony_ci	__le16	control_flags;
62462306a36Sopenharmony_ci#define ABTS_CONTR_FLG_TERM_EXCHG	BIT_0
62562306a36Sopenharmony_ci	uint8_t  vp_index;
62662306a36Sopenharmony_ci	uint8_t  reserved_3:4;
62762306a36Sopenharmony_ci	uint8_t  sof_type:4;
62862306a36Sopenharmony_ci	__le32	exchange_address;
62962306a36Sopenharmony_ci	struct fcp_hdr_le fcp_hdr_le;
63062306a36Sopenharmony_ci	union {
63162306a36Sopenharmony_ci		struct ba_acc_le ba_acct;
63262306a36Sopenharmony_ci		struct ba_rjt_le ba_rjt;
63362306a36Sopenharmony_ci	} __packed payload;
63462306a36Sopenharmony_ci	__le32	reserved_4;
63562306a36Sopenharmony_ci	__le32	exchange_addr_to_abort;
63662306a36Sopenharmony_ci} __packed;
63762306a36Sopenharmony_ci
63862306a36Sopenharmony_ci/*
63962306a36Sopenharmony_ci * ISP queue -	ABTS Response IOCB from ISP24xx Firmware entry structure.
64062306a36Sopenharmony_ci *		The ABTS response with completion status to the ABTS response
64162306a36Sopenharmony_ci *		(sent by the target driver to the ISP 24xx) is sent by the
64262306a36Sopenharmony_ci *		ISP24xx firmware to the target driver.
64362306a36Sopenharmony_ci *		The IOCB is placed on the response queue.
64462306a36Sopenharmony_ci */
64562306a36Sopenharmony_cistruct abts_resp_from_24xx_fw {
64662306a36Sopenharmony_ci	uint8_t	 entry_type;		    /* Entry type. */
64762306a36Sopenharmony_ci	uint8_t	 entry_count;		    /* Entry count. */
64862306a36Sopenharmony_ci	uint8_t	 sys_define;		    /* System defined. */
64962306a36Sopenharmony_ci	uint8_t	 entry_status;		    /* Entry Status. */
65062306a36Sopenharmony_ci	uint32_t handle;
65162306a36Sopenharmony_ci	__le16	compl_status;
65262306a36Sopenharmony_ci#define ABTS_RESP_COMPL_SUCCESS		0
65362306a36Sopenharmony_ci#define ABTS_RESP_COMPL_SUBCODE_ERROR	0x31
65462306a36Sopenharmony_ci	__le16	nport_handle;
65562306a36Sopenharmony_ci	__le16	reserved_1;
65662306a36Sopenharmony_ci	uint8_t  reserved_2;
65762306a36Sopenharmony_ci	uint8_t  reserved_3:4;
65862306a36Sopenharmony_ci	uint8_t  sof_type:4;
65962306a36Sopenharmony_ci	__le32	exchange_address;
66062306a36Sopenharmony_ci	struct fcp_hdr_le fcp_hdr_le;
66162306a36Sopenharmony_ci	uint8_t reserved_4[8];
66262306a36Sopenharmony_ci	__le32	error_subcode1;
66362306a36Sopenharmony_ci#define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM	0x1E
66462306a36Sopenharmony_ci	__le32	error_subcode2;
66562306a36Sopenharmony_ci	__le32	exchange_addr_to_abort;
66662306a36Sopenharmony_ci} __packed;
66762306a36Sopenharmony_ci
66862306a36Sopenharmony_ci/********************************************************************\
66962306a36Sopenharmony_ci * Type Definitions used by initiator & target halves
67062306a36Sopenharmony_ci\********************************************************************/
67162306a36Sopenharmony_ci
67262306a36Sopenharmony_cistruct qla_tgt_mgmt_cmd;
67362306a36Sopenharmony_cistruct fc_port;
67462306a36Sopenharmony_cistruct qla_tgt_cmd;
67562306a36Sopenharmony_ci
67662306a36Sopenharmony_ci/*
67762306a36Sopenharmony_ci * This structure provides a template of function calls that the
67862306a36Sopenharmony_ci * target driver (from within qla_target.c) can issue to the
67962306a36Sopenharmony_ci * target module (tcm_qla2xxx).
68062306a36Sopenharmony_ci */
68162306a36Sopenharmony_cistruct qla_tgt_func_tmpl {
68262306a36Sopenharmony_ci	struct qla_tgt_cmd *(*find_cmd_by_tag)(struct fc_port *, uint64_t);
68362306a36Sopenharmony_ci	int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *,
68462306a36Sopenharmony_ci			unsigned char *, uint32_t, int, int, int);
68562306a36Sopenharmony_ci	void (*handle_data)(struct qla_tgt_cmd *);
68662306a36Sopenharmony_ci	int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, u64, uint16_t,
68762306a36Sopenharmony_ci			uint32_t);
68862306a36Sopenharmony_ci	struct qla_tgt_cmd *(*get_cmd)(struct fc_port *);
68962306a36Sopenharmony_ci	void (*rel_cmd)(struct qla_tgt_cmd *);
69062306a36Sopenharmony_ci	void (*free_cmd)(struct qla_tgt_cmd *);
69162306a36Sopenharmony_ci	void (*free_mcmd)(struct qla_tgt_mgmt_cmd *);
69262306a36Sopenharmony_ci	void (*free_session)(struct fc_port *);
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_ci	int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *,
69562306a36Sopenharmony_ci					struct fc_port *);
69662306a36Sopenharmony_ci	void (*update_sess)(struct fc_port *, port_id_t, uint16_t, bool);
69762306a36Sopenharmony_ci	struct fc_port *(*find_sess_by_loop_id)(struct scsi_qla_host *,
69862306a36Sopenharmony_ci						const uint16_t);
69962306a36Sopenharmony_ci	struct fc_port *(*find_sess_by_s_id)(struct scsi_qla_host *,
70062306a36Sopenharmony_ci					     const be_id_t);
70162306a36Sopenharmony_ci	void (*clear_nacl_from_fcport_map)(struct fc_port *);
70262306a36Sopenharmony_ci	void (*put_sess)(struct fc_port *);
70362306a36Sopenharmony_ci	void (*shutdown_sess)(struct fc_port *);
70462306a36Sopenharmony_ci	int (*get_dif_tags)(struct qla_tgt_cmd *cmd, uint16_t *pfw_prot_opts);
70562306a36Sopenharmony_ci	int (*chk_dif_tags)(uint32_t tag);
70662306a36Sopenharmony_ci	void (*add_target)(struct scsi_qla_host *);
70762306a36Sopenharmony_ci	void (*remove_target)(struct scsi_qla_host *);
70862306a36Sopenharmony_ci};
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_ciint qla2x00_wait_for_hba_online(struct scsi_qla_host *);
71162306a36Sopenharmony_ci
71262306a36Sopenharmony_ci#include <target/target_core_base.h>
71362306a36Sopenharmony_ci
71462306a36Sopenharmony_ci#define QLA_TGT_TIMEOUT			10	/* in seconds */
71562306a36Sopenharmony_ci
71662306a36Sopenharmony_ci#define QLA_TGT_MAX_HW_PENDING_TIME	60 /* in seconds */
71762306a36Sopenharmony_ci
71862306a36Sopenharmony_ci/* Immediate notify status constants */
71962306a36Sopenharmony_ci#define IMM_NTFY_LIP_RESET          0x000E
72062306a36Sopenharmony_ci#define IMM_NTFY_LIP_LINK_REINIT    0x000F
72162306a36Sopenharmony_ci#define IMM_NTFY_IOCB_OVERFLOW      0x0016
72262306a36Sopenharmony_ci#define IMM_NTFY_ABORT_TASK         0x0020
72362306a36Sopenharmony_ci#define IMM_NTFY_PORT_LOGOUT        0x0029
72462306a36Sopenharmony_ci#define IMM_NTFY_PORT_CONFIG        0x002A
72562306a36Sopenharmony_ci#define IMM_NTFY_GLBL_TPRLO         0x002D
72662306a36Sopenharmony_ci#define IMM_NTFY_GLBL_LOGO          0x002E
72762306a36Sopenharmony_ci#define IMM_NTFY_RESOURCE           0x0034
72862306a36Sopenharmony_ci#define IMM_NTFY_MSG_RX             0x0036
72962306a36Sopenharmony_ci#define IMM_NTFY_SRR                0x0045
73062306a36Sopenharmony_ci#define IMM_NTFY_ELS                0x0046
73162306a36Sopenharmony_ci
73262306a36Sopenharmony_ci/* Immediate notify task flags */
73362306a36Sopenharmony_ci#define IMM_NTFY_TASK_MGMT_SHIFT    8
73462306a36Sopenharmony_ci
73562306a36Sopenharmony_ci#define QLA_TGT_CLEAR_ACA               0x40
73662306a36Sopenharmony_ci#define QLA_TGT_TARGET_RESET            0x20
73762306a36Sopenharmony_ci#define QLA_TGT_LUN_RESET               0x10
73862306a36Sopenharmony_ci#define QLA_TGT_CLEAR_TS                0x04
73962306a36Sopenharmony_ci#define QLA_TGT_ABORT_TS                0x02
74062306a36Sopenharmony_ci#define QLA_TGT_ABORT_ALL_SESS          0xFFFF
74162306a36Sopenharmony_ci#define QLA_TGT_ABORT_ALL               0xFFFE
74262306a36Sopenharmony_ci#define QLA_TGT_NEXUS_LOSS_SESS         0xFFFD
74362306a36Sopenharmony_ci#define QLA_TGT_NEXUS_LOSS              0xFFFC
74462306a36Sopenharmony_ci#define QLA_TGT_ABTS			0xFFFB
74562306a36Sopenharmony_ci#define QLA_TGT_2G_ABORT_TASK		0xFFFA
74662306a36Sopenharmony_ci
74762306a36Sopenharmony_ci/* Notify Acknowledge flags */
74862306a36Sopenharmony_ci#define NOTIFY_ACK_RES_COUNT        BIT_8
74962306a36Sopenharmony_ci#define NOTIFY_ACK_CLEAR_LIP_RESET  BIT_5
75062306a36Sopenharmony_ci#define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
75162306a36Sopenharmony_ci
75262306a36Sopenharmony_ci/* Command's states */
75362306a36Sopenharmony_ci#define QLA_TGT_STATE_NEW		0 /* New command + target processing */
75462306a36Sopenharmony_ci#define QLA_TGT_STATE_NEED_DATA		1 /* target needs data to continue */
75562306a36Sopenharmony_ci#define QLA_TGT_STATE_DATA_IN		2 /* Data arrived + target processing */
75662306a36Sopenharmony_ci#define QLA_TGT_STATE_PROCESSED		3 /* target done processing */
75762306a36Sopenharmony_ci
75862306a36Sopenharmony_ci/* ATIO task_codes field */
75962306a36Sopenharmony_ci#define ATIO_SIMPLE_QUEUE           0
76062306a36Sopenharmony_ci#define ATIO_HEAD_OF_QUEUE          1
76162306a36Sopenharmony_ci#define ATIO_ORDERED_QUEUE          2
76262306a36Sopenharmony_ci#define ATIO_ACA_QUEUE              4
76362306a36Sopenharmony_ci#define ATIO_UNTAGGED               5
76462306a36Sopenharmony_ci
76562306a36Sopenharmony_ci/* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */
76662306a36Sopenharmony_ci#define	FC_TM_SUCCESS               0
76762306a36Sopenharmony_ci#define	FC_TM_BAD_FCP_DATA          1
76862306a36Sopenharmony_ci#define	FC_TM_BAD_CMD               2
76962306a36Sopenharmony_ci#define	FC_TM_FCP_DATA_MISMATCH     3
77062306a36Sopenharmony_ci#define	FC_TM_REJECT                4
77162306a36Sopenharmony_ci#define FC_TM_FAILED                5
77262306a36Sopenharmony_ci
77362306a36Sopenharmony_ci#define QLA_TGT_SENSE_VALID(sense)  ((sense != NULL) && \
77462306a36Sopenharmony_ci				(((const uint8_t *)(sense))[0] & 0x70) == 0x70)
77562306a36Sopenharmony_ci
77662306a36Sopenharmony_cistruct qla_port_24xx_data {
77762306a36Sopenharmony_ci	uint8_t port_name[WWN_SIZE];
77862306a36Sopenharmony_ci	uint16_t loop_id;
77962306a36Sopenharmony_ci	uint16_t reserved;
78062306a36Sopenharmony_ci};
78162306a36Sopenharmony_ci
78262306a36Sopenharmony_cistruct qla_qpair_hint {
78362306a36Sopenharmony_ci	struct list_head hint_elem;
78462306a36Sopenharmony_ci	struct qla_qpair *qpair;
78562306a36Sopenharmony_ci	u16 cpuid;
78662306a36Sopenharmony_ci	uint8_t cmd_cnt;
78762306a36Sopenharmony_ci};
78862306a36Sopenharmony_ci
78962306a36Sopenharmony_cistruct qla_tgt {
79062306a36Sopenharmony_ci	struct scsi_qla_host *vha;
79162306a36Sopenharmony_ci	struct qla_hw_data *ha;
79262306a36Sopenharmony_ci	struct btree_head64 lun_qpair_map;
79362306a36Sopenharmony_ci	struct qla_qpair_hint *qphints;
79462306a36Sopenharmony_ci	/*
79562306a36Sopenharmony_ci	 * To sync between IRQ handlers and qlt_target_release(). Needed,
79662306a36Sopenharmony_ci	 * because req_pkt() can drop/reaquire HW lock inside. Protected by
79762306a36Sopenharmony_ci	 * HW lock.
79862306a36Sopenharmony_ci	 */
79962306a36Sopenharmony_ci	int atio_irq_cmd_count;
80062306a36Sopenharmony_ci
80162306a36Sopenharmony_ci	int sg_tablesize;
80262306a36Sopenharmony_ci
80362306a36Sopenharmony_ci	/* Target's flags, serialized by pha->hardware_lock */
80462306a36Sopenharmony_ci	unsigned int link_reinit_iocb_pending:1;
80562306a36Sopenharmony_ci
80662306a36Sopenharmony_ci	/*
80762306a36Sopenharmony_ci	 * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex
80862306a36Sopenharmony_ci	 * OR hardware_lock for reading.
80962306a36Sopenharmony_ci	 */
81062306a36Sopenharmony_ci	int tgt_stop; /* the target mode driver is being stopped */
81162306a36Sopenharmony_ci	int tgt_stopped; /* the target mode driver has been stopped */
81262306a36Sopenharmony_ci
81362306a36Sopenharmony_ci	/* Count of sessions refering qla_tgt. Protected by hardware_lock. */
81462306a36Sopenharmony_ci	int sess_count;
81562306a36Sopenharmony_ci
81662306a36Sopenharmony_ci	spinlock_t sess_work_lock;
81762306a36Sopenharmony_ci	struct list_head sess_works_list;
81862306a36Sopenharmony_ci	struct work_struct sess_work;
81962306a36Sopenharmony_ci
82062306a36Sopenharmony_ci	struct imm_ntfy_from_isp link_reinit_iocb;
82162306a36Sopenharmony_ci	wait_queue_head_t waitQ;
82262306a36Sopenharmony_ci	int notify_ack_expected;
82362306a36Sopenharmony_ci	int abts_resp_expected;
82462306a36Sopenharmony_ci	int modify_lun_expected;
82562306a36Sopenharmony_ci	atomic_t tgt_global_resets_count;
82662306a36Sopenharmony_ci	struct list_head tgt_list_entry;
82762306a36Sopenharmony_ci};
82862306a36Sopenharmony_ci
82962306a36Sopenharmony_cistruct qla_tgt_sess_op {
83062306a36Sopenharmony_ci	struct scsi_qla_host *vha;
83162306a36Sopenharmony_ci	uint32_t chip_reset;
83262306a36Sopenharmony_ci	struct atio_from_isp atio;
83362306a36Sopenharmony_ci	struct work_struct work;
83462306a36Sopenharmony_ci	struct list_head cmd_list;
83562306a36Sopenharmony_ci	bool aborted;
83662306a36Sopenharmony_ci	struct rsp_que *rsp;
83762306a36Sopenharmony_ci};
83862306a36Sopenharmony_ci
83962306a36Sopenharmony_cienum trace_flags {
84062306a36Sopenharmony_ci	TRC_NEW_CMD = BIT_0,
84162306a36Sopenharmony_ci	TRC_DO_WORK = BIT_1,
84262306a36Sopenharmony_ci	TRC_DO_WORK_ERR = BIT_2,
84362306a36Sopenharmony_ci	TRC_XFR_RDY = BIT_3,
84462306a36Sopenharmony_ci	TRC_XMIT_DATA = BIT_4,
84562306a36Sopenharmony_ci	TRC_XMIT_STATUS = BIT_5,
84662306a36Sopenharmony_ci	TRC_SRR_RSP =  BIT_6,
84762306a36Sopenharmony_ci	TRC_SRR_XRDY = BIT_7,
84862306a36Sopenharmony_ci	TRC_SRR_TERM = BIT_8,
84962306a36Sopenharmony_ci	TRC_SRR_CTIO = BIT_9,
85062306a36Sopenharmony_ci	TRC_FLUSH = BIT_10,
85162306a36Sopenharmony_ci	TRC_CTIO_ERR = BIT_11,
85262306a36Sopenharmony_ci	TRC_CTIO_DONE = BIT_12,
85362306a36Sopenharmony_ci	TRC_CTIO_ABORTED =  BIT_13,
85462306a36Sopenharmony_ci	TRC_CTIO_STRANGE = BIT_14,
85562306a36Sopenharmony_ci	TRC_CMD_DONE = BIT_15,
85662306a36Sopenharmony_ci	TRC_CMD_CHK_STOP = BIT_16,
85762306a36Sopenharmony_ci	TRC_CMD_FREE = BIT_17,
85862306a36Sopenharmony_ci	TRC_DATA_IN = BIT_18,
85962306a36Sopenharmony_ci	TRC_ABORT = BIT_19,
86062306a36Sopenharmony_ci	TRC_DIF_ERR = BIT_20,
86162306a36Sopenharmony_ci};
86262306a36Sopenharmony_ci
86362306a36Sopenharmony_cistruct qla_tgt_cmd {
86462306a36Sopenharmony_ci	/*
86562306a36Sopenharmony_ci	 * Do not move cmd_type field. it needs to line up with srb->cmd_type
86662306a36Sopenharmony_ci	 */
86762306a36Sopenharmony_ci	uint8_t cmd_type;
86862306a36Sopenharmony_ci	uint8_t pad[7];
86962306a36Sopenharmony_ci	struct se_cmd se_cmd;
87062306a36Sopenharmony_ci	struct list_head sess_cmd_list;
87162306a36Sopenharmony_ci	struct fc_port *sess;
87262306a36Sopenharmony_ci	struct qla_qpair *qpair;
87362306a36Sopenharmony_ci	uint32_t reset_count;
87462306a36Sopenharmony_ci	int state;
87562306a36Sopenharmony_ci	struct work_struct work;
87662306a36Sopenharmony_ci	/* Sense buffer that will be mapped into outgoing status */
87762306a36Sopenharmony_ci	unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
87862306a36Sopenharmony_ci
87962306a36Sopenharmony_ci	spinlock_t cmd_lock;
88062306a36Sopenharmony_ci	/* to save extra sess dereferences */
88162306a36Sopenharmony_ci	unsigned int conf_compl_supported:1;
88262306a36Sopenharmony_ci	unsigned int sg_mapped:1;
88362306a36Sopenharmony_ci	unsigned int write_data_transferred:1;
88462306a36Sopenharmony_ci	unsigned int q_full:1;
88562306a36Sopenharmony_ci	unsigned int term_exchg:1;
88662306a36Sopenharmony_ci	unsigned int cmd_sent_to_fw:1;
88762306a36Sopenharmony_ci	unsigned int cmd_in_wq:1;
88862306a36Sopenharmony_ci	unsigned int edif:1;
88962306a36Sopenharmony_ci
89062306a36Sopenharmony_ci	/*
89162306a36Sopenharmony_ci	 * This variable may be set from outside the LIO and I/O completion
89262306a36Sopenharmony_ci	 * callback functions. Do not declare this member variable as a
89362306a36Sopenharmony_ci	 * bitfield to avoid a read-modify-write operation when this variable
89462306a36Sopenharmony_ci	 * is set.
89562306a36Sopenharmony_ci	 */
89662306a36Sopenharmony_ci	unsigned int aborted;
89762306a36Sopenharmony_ci
89862306a36Sopenharmony_ci	struct scatterlist *sg;	/* cmd data buffer SG vector */
89962306a36Sopenharmony_ci	int sg_cnt;		/* SG segments count */
90062306a36Sopenharmony_ci	int bufflen;		/* cmd buffer length */
90162306a36Sopenharmony_ci	int offset;
90262306a36Sopenharmony_ci	u64 unpacked_lun;
90362306a36Sopenharmony_ci	enum dma_data_direction dma_data_direction;
90462306a36Sopenharmony_ci
90562306a36Sopenharmony_ci	uint16_t ctio_flags;
90662306a36Sopenharmony_ci	uint16_t vp_idx;
90762306a36Sopenharmony_ci	uint16_t loop_id;	/* to save extra sess dereferences */
90862306a36Sopenharmony_ci	struct qla_tgt *tgt;	/* to save extra sess dereferences */
90962306a36Sopenharmony_ci	struct scsi_qla_host *vha;
91062306a36Sopenharmony_ci	struct list_head cmd_list;
91162306a36Sopenharmony_ci
91262306a36Sopenharmony_ci	struct atio_from_isp atio;
91362306a36Sopenharmony_ci
91462306a36Sopenharmony_ci	uint8_t ctx_dsd_alloced;
91562306a36Sopenharmony_ci
91662306a36Sopenharmony_ci	/* T10-DIF */
91762306a36Sopenharmony_ci#define DIF_ERR_NONE 0
91862306a36Sopenharmony_ci#define DIF_ERR_GRD 1
91962306a36Sopenharmony_ci#define DIF_ERR_REF 2
92062306a36Sopenharmony_ci#define DIF_ERR_APP 3
92162306a36Sopenharmony_ci	int8_t dif_err_code;
92262306a36Sopenharmony_ci	struct scatterlist *prot_sg;
92362306a36Sopenharmony_ci	uint32_t prot_sg_cnt;
92462306a36Sopenharmony_ci	uint32_t blk_sz, num_blks;
92562306a36Sopenharmony_ci	uint8_t scsi_status, sense_key, asc, ascq;
92662306a36Sopenharmony_ci
92762306a36Sopenharmony_ci	struct crc_context *ctx;
92862306a36Sopenharmony_ci	const uint8_t	*cdb;
92962306a36Sopenharmony_ci	uint64_t	lba;
93062306a36Sopenharmony_ci	uint16_t	a_guard, e_guard, a_app_tag, e_app_tag;
93162306a36Sopenharmony_ci	uint32_t	a_ref_tag, e_ref_tag;
93262306a36Sopenharmony_ci#define DIF_BUNDL_DMA_VALID 1
93362306a36Sopenharmony_ci	uint16_t prot_flags;
93462306a36Sopenharmony_ci
93562306a36Sopenharmony_ci	uint64_t jiffies_at_alloc;
93662306a36Sopenharmony_ci	uint64_t jiffies_at_free;
93762306a36Sopenharmony_ci
93862306a36Sopenharmony_ci	enum trace_flags trc_flags;
93962306a36Sopenharmony_ci};
94062306a36Sopenharmony_ci
94162306a36Sopenharmony_cistruct qla_tgt_sess_work_param {
94262306a36Sopenharmony_ci	struct list_head sess_works_list_entry;
94362306a36Sopenharmony_ci
94462306a36Sopenharmony_ci#define QLA_TGT_SESS_WORK_ABORT	1
94562306a36Sopenharmony_ci	int type;
94662306a36Sopenharmony_ci
94762306a36Sopenharmony_ci	union {
94862306a36Sopenharmony_ci		struct abts_recv_from_24xx abts;
94962306a36Sopenharmony_ci		struct imm_ntfy_from_isp tm_iocb;
95062306a36Sopenharmony_ci		struct atio_from_isp tm_iocb2;
95162306a36Sopenharmony_ci	};
95262306a36Sopenharmony_ci};
95362306a36Sopenharmony_ci
95462306a36Sopenharmony_cistruct qla_tgt_mgmt_cmd {
95562306a36Sopenharmony_ci	uint8_t cmd_type;
95662306a36Sopenharmony_ci	uint8_t pad[3];
95762306a36Sopenharmony_ci	uint16_t tmr_func;
95862306a36Sopenharmony_ci	uint8_t fc_tm_rsp;
95962306a36Sopenharmony_ci	uint8_t abort_io_attr;
96062306a36Sopenharmony_ci	struct fc_port *sess;
96162306a36Sopenharmony_ci	struct qla_qpair *qpair;
96262306a36Sopenharmony_ci	struct scsi_qla_host *vha;
96362306a36Sopenharmony_ci	struct se_cmd se_cmd;
96462306a36Sopenharmony_ci	struct work_struct free_work;
96562306a36Sopenharmony_ci	unsigned int flags;
96662306a36Sopenharmony_ci#define QLA24XX_MGMT_SEND_NACK	BIT_0
96762306a36Sopenharmony_ci#define QLA24XX_MGMT_ABORT_IO_ATTR_VALID BIT_1
96862306a36Sopenharmony_ci	uint32_t reset_count;
96962306a36Sopenharmony_ci	struct work_struct work;
97062306a36Sopenharmony_ci	uint64_t unpacked_lun;
97162306a36Sopenharmony_ci	union {
97262306a36Sopenharmony_ci		struct atio_from_isp atio;
97362306a36Sopenharmony_ci		struct imm_ntfy_from_isp imm_ntfy;
97462306a36Sopenharmony_ci		struct abts_recv_from_24xx abts;
97562306a36Sopenharmony_ci	} __packed orig_iocb;
97662306a36Sopenharmony_ci};
97762306a36Sopenharmony_ci
97862306a36Sopenharmony_cistruct qla_tgt_prm {
97962306a36Sopenharmony_ci	struct qla_tgt_cmd *cmd;
98062306a36Sopenharmony_ci	struct qla_tgt *tgt;
98162306a36Sopenharmony_ci	void *pkt;
98262306a36Sopenharmony_ci	struct scatterlist *sg;	/* cmd data buffer SG vector */
98362306a36Sopenharmony_ci	unsigned char *sense_buffer;
98462306a36Sopenharmony_ci	int seg_cnt;
98562306a36Sopenharmony_ci	int req_cnt;
98662306a36Sopenharmony_ci	uint16_t rq_result;
98762306a36Sopenharmony_ci	int sense_buffer_len;
98862306a36Sopenharmony_ci	int residual;
98962306a36Sopenharmony_ci	int add_status_pkt;
99062306a36Sopenharmony_ci	/* dif */
99162306a36Sopenharmony_ci	struct scatterlist *prot_sg;
99262306a36Sopenharmony_ci	uint16_t prot_seg_cnt;
99362306a36Sopenharmony_ci	uint16_t tot_dsds;
99462306a36Sopenharmony_ci};
99562306a36Sopenharmony_ci
99662306a36Sopenharmony_ci/* Check for Switch reserved address */
99762306a36Sopenharmony_ci#define IS_SW_RESV_ADDR(_s_id) \
99862306a36Sopenharmony_ci	((_s_id.b.domain == 0xff) && ((_s_id.b.area & 0xf0) == 0xf0))
99962306a36Sopenharmony_ci
100062306a36Sopenharmony_ci#define QLA_TGT_XMIT_DATA		1
100162306a36Sopenharmony_ci#define QLA_TGT_XMIT_STATUS		2
100262306a36Sopenharmony_ci#define QLA_TGT_XMIT_ALL		(QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA)
100362306a36Sopenharmony_ci
100462306a36Sopenharmony_ci
100562306a36Sopenharmony_ciextern struct qla_tgt_data qla_target;
100662306a36Sopenharmony_ci
100762306a36Sopenharmony_ci/*
100862306a36Sopenharmony_ci * Function prototypes for qla_target.c logic used by qla2xxx LLD code.
100962306a36Sopenharmony_ci */
101062306a36Sopenharmony_ciextern int qlt_add_target(struct qla_hw_data *, struct scsi_qla_host *);
101162306a36Sopenharmony_ciextern int qlt_remove_target(struct qla_hw_data *, struct scsi_qla_host *);
101262306a36Sopenharmony_ciextern int qlt_lport_register(void *, u64, u64, u64,
101362306a36Sopenharmony_ci			int (*callback)(struct scsi_qla_host *, void *, u64, u64));
101462306a36Sopenharmony_ciextern void qlt_lport_deregister(struct scsi_qla_host *);
101562306a36Sopenharmony_ciextern void qlt_unreg_sess(struct fc_port *);
101662306a36Sopenharmony_ciextern void qlt_fc_port_added(struct scsi_qla_host *, fc_port_t *);
101762306a36Sopenharmony_ciextern void qlt_fc_port_deleted(struct scsi_qla_host *, fc_port_t *, int);
101862306a36Sopenharmony_ciextern int __init qlt_init(void);
101962306a36Sopenharmony_ciextern void qlt_exit(void);
102062306a36Sopenharmony_ciextern void qlt_free_session_done(struct work_struct *);
102162306a36Sopenharmony_ci/*
102262306a36Sopenharmony_ci * This macro is used during early initializations when host->active_mode
102362306a36Sopenharmony_ci * is not set. Right now, ha value is ignored.
102462306a36Sopenharmony_ci */
102562306a36Sopenharmony_ci#define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED)
102662306a36Sopenharmony_ci
102762306a36Sopenharmony_ciextern int ql2x_ini_mode;
102862306a36Sopenharmony_ci
102962306a36Sopenharmony_cistatic inline bool qla_tgt_mode_enabled(struct scsi_qla_host *ha)
103062306a36Sopenharmony_ci{
103162306a36Sopenharmony_ci	return ha->host->active_mode == MODE_TARGET;
103262306a36Sopenharmony_ci}
103362306a36Sopenharmony_ci
103462306a36Sopenharmony_cistatic inline bool qla_ini_mode_enabled(struct scsi_qla_host *ha)
103562306a36Sopenharmony_ci{
103662306a36Sopenharmony_ci	return ha->host->active_mode == MODE_INITIATOR;
103762306a36Sopenharmony_ci}
103862306a36Sopenharmony_ci
103962306a36Sopenharmony_cistatic inline bool qla_dual_mode_enabled(struct scsi_qla_host *ha)
104062306a36Sopenharmony_ci{
104162306a36Sopenharmony_ci	return (ha->host->active_mode == MODE_DUAL);
104262306a36Sopenharmony_ci}
104362306a36Sopenharmony_ci
104462306a36Sopenharmony_cistatic inline uint32_t sid_to_key(const be_id_t s_id)
104562306a36Sopenharmony_ci{
104662306a36Sopenharmony_ci	return s_id.domain << 16 |
104762306a36Sopenharmony_ci		s_id.area << 8 |
104862306a36Sopenharmony_ci		s_id.al_pa;
104962306a36Sopenharmony_ci}
105062306a36Sopenharmony_ci
105162306a36Sopenharmony_ci/*
105262306a36Sopenharmony_ci * Exported symbols from qla_target.c LLD logic used by qla2xxx code..
105362306a36Sopenharmony_ci */
105462306a36Sopenharmony_ciextern void qlt_response_pkt_all_vps(struct scsi_qla_host *, struct rsp_que *,
105562306a36Sopenharmony_ci	response_t *);
105662306a36Sopenharmony_ciextern int qlt_rdy_to_xfer(struct qla_tgt_cmd *);
105762306a36Sopenharmony_ciextern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t);
105862306a36Sopenharmony_ciextern int qlt_abort_cmd(struct qla_tgt_cmd *);
105962306a36Sopenharmony_ciextern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *);
106062306a36Sopenharmony_ciextern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *);
106162306a36Sopenharmony_ciextern void qlt_free_cmd(struct qla_tgt_cmd *cmd);
106262306a36Sopenharmony_ciextern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *);
106362306a36Sopenharmony_ciextern void qlt_enable_vha(struct scsi_qla_host *);
106462306a36Sopenharmony_ciextern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *);
106562306a36Sopenharmony_ciextern u8 qlt_rff_id(struct scsi_qla_host *);
106662306a36Sopenharmony_ciextern void qlt_init_atio_q_entries(struct scsi_qla_host *);
106762306a36Sopenharmony_ciextern void qlt_24xx_process_atio_queue(struct scsi_qla_host *, uint8_t);
106862306a36Sopenharmony_ciextern void qlt_24xx_config_rings(struct scsi_qla_host *);
106962306a36Sopenharmony_ciextern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host *,
107062306a36Sopenharmony_ci	struct nvram_24xx *);
107162306a36Sopenharmony_ciextern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host *,
107262306a36Sopenharmony_ci	struct init_cb_24xx *);
107362306a36Sopenharmony_ciextern void qlt_81xx_config_nvram_stage2(struct scsi_qla_host *,
107462306a36Sopenharmony_ci	struct init_cb_81xx *);
107562306a36Sopenharmony_ciextern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host *,
107662306a36Sopenharmony_ci	struct nvram_81xx *);
107762306a36Sopenharmony_ciextern void qlt_modify_vp_config(struct scsi_qla_host *,
107862306a36Sopenharmony_ci	struct vp_config_entry_24xx *);
107962306a36Sopenharmony_ciextern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
108062306a36Sopenharmony_ciextern int qlt_mem_alloc(struct qla_hw_data *);
108162306a36Sopenharmony_ciextern void qlt_mem_free(struct qla_hw_data *);
108262306a36Sopenharmony_ciextern int qlt_stop_phase1(struct qla_tgt *);
108362306a36Sopenharmony_ciextern void qlt_stop_phase2(struct qla_tgt *);
108462306a36Sopenharmony_ciextern irqreturn_t qla83xx_msix_atio_q(int, void *);
108562306a36Sopenharmony_ciextern void qlt_83xx_iospace_config(struct qla_hw_data *);
108662306a36Sopenharmony_ciextern int qlt_free_qfull_cmds(struct qla_qpair *);
108762306a36Sopenharmony_ciextern void qlt_logo_completion_handler(fc_port_t *, int);
108862306a36Sopenharmony_ciextern void qlt_do_generation_tick(struct scsi_qla_host *, int *);
108962306a36Sopenharmony_ci
109062306a36Sopenharmony_civoid qlt_send_resp_ctio(struct qla_qpair *, struct qla_tgt_cmd *, uint8_t,
109162306a36Sopenharmony_ci    uint8_t, uint8_t, uint8_t);
109262306a36Sopenharmony_ci
109362306a36Sopenharmony_ci#endif /* __QLA_TARGET_H */
1094