Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  based on qla2x00t.c code:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *  Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *  Copyright (C) 2004 - 2005 Leonid Stoljar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *  Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *  Copyright (C) 2006 - 2010 ID7 Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *  Forward port and refactoring to modern qla2xxx and target/configfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *  Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include "qla_def.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include "qla_target.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) static int ql2xtgt_tape_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) MODULE_PARM_DESC(ql2xtgt_tape_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 		"Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) module_param(qlini_mode, charp, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) MODULE_PARM_DESC(qlini_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	"Determines when initiator mode will be enabled. Possible values: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	"\"exclusive\" - initiator mode will be enabled on load, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	"disabled on enabling target mode and then on disabling target mode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	"enabled back; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	"\"disabled\" - initiator mode will never be enabled; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	"\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	"when ready "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	"\"enabled\" (default) - initiator mode will always stay enabled.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) static int ql_dm_tgt_ex_pct = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) MODULE_PARM_DESC(ql_dm_tgt_ex_pct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	"For Dual Mode (qlini_mode=dual), this parameter determines "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	"the percentage of exchanges/cmds FW will allocate resources "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	"for Target mode.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) int ql2xuctrlirq = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) module_param(ql2xuctrlirq, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) MODULE_PARM_DESC(ql2xuctrlirq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)     "User to control IRQ placement via smp_affinity."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)     "Valid with qlini_mode=disabled."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)     "1(default): enable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static int qla_sam_status = SAM_STAT_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  * From scsi/fc/fc_fcp.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) enum fcp_resp_rsp_codes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	FCP_TMF_CMPL = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	FCP_DATA_LEN_INVALID = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	FCP_CMND_FIELDS_INVALID = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	FCP_DATA_PARAM_MISMATCH = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	FCP_TMF_REJECTED = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	FCP_TMF_FAILED = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	FCP_TMF_INVALID_LUN = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  * fc_pri_ta from scsi/fc/fc_fcp.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define FCP_PTA_SIMPLE      0   /* simple task attribute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #define FCP_PTA_HEADQ       1   /* head of queue task attribute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define FCP_PTA_ORDERED     2   /* ordered task attribute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) #define FCP_PTA_ACA         4   /* auto. contingent allegiance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #define FCP_PTA_MASK        7   /* mask for task attribute field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define FCP_PRI_SHIFT       3   /* priority field starts in bit 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #define FCP_PRI_RESVD_MASK  0x80        /* reserved bits in priority field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  * must be called under HW lock and could unlock/lock it inside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  * It isn't an issue, since in the current implementation on the time when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  * those functions are called:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  *   - Either context is IRQ and only IRQ handler can modify HW data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  *     including rings related fields,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  *   - Or access to target mode variables from struct qla_tgt doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  *     cross those functions boundaries, except tgt_stop, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  *     additionally protected by irq_cmd_count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) /* Predefs for callbacks handed to qla2xxx LLD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	struct atio_from_isp *pkt, uint8_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	response_t *pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	int fn, void *iocb, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	*cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	struct atio_from_isp *atio, uint16_t status, int qfull);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) static void qlt_disable_vha(struct scsi_qla_host *vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static void qlt_clear_tgt_db(struct qla_tgt *tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static void qlt_send_notify_ack(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	struct imm_ntfy_from_isp *ntfy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	struct imm_ntfy_from_isp *imm, int ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	fc_port_t *fcport, bool local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) void qlt_unreg_sess(struct fc_port *sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) static void qlt_24xx_handle_abts(struct scsi_qla_host *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	struct abts_recv_from_24xx *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)     uint16_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static inline uint32_t qlt_make_handle(struct qla_qpair *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  * Global Variables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) static struct kmem_cache *qla_tgt_mgmt_cmd_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) struct kmem_cache *qla_tgt_plogi_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) static mempool_t *qla_tgt_mgmt_cmd_mempool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static struct workqueue_struct *qla_tgt_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) static DEFINE_MUTEX(qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static LIST_HEAD(qla_tgt_glist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) static const char *prot_op_str(u32 prot_op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	switch (prot_op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	case TARGET_PROT_NORMAL:	return "NORMAL";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	case TARGET_PROT_DIN_INSERT:	return "DIN_INSERT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	case TARGET_PROT_DOUT_INSERT:	return "DOUT_INSERT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	case TARGET_PROT_DIN_STRIP:	return "DIN_STRIP";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	case TARGET_PROT_DOUT_STRIP:	return "DOUT_STRIP";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	case TARGET_PROT_DIN_PASS:	return "DIN_PASS";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	case TARGET_PROT_DOUT_PASS:	return "DOUT_PASS";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	default:			return "UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) /* This API intentionally takes dest as a parameter, rather than returning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  * int value to avoid caller forgetting to issue wmb() after the store */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	*dest = atomic_inc_return(&base_vha->generation_tick);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	/* memory barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) /* Might release hw lock, then reaquire!! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	/* Send marker if required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	if (unlikely(vha->marker_needed != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		int rc = qla2x00_issue_marker(vha, vha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		if (rc != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 			ql_dbg(ql_dbg_tgt, vha, 0xe03d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 			    "qla_target(%d): issue_marker() failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 			    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 					    be_id_t d_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	struct scsi_qla_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	uint32_t key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	if (vha->d_id.b.area == d_id.area &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	    vha->d_id.b.domain == d_id.domain &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	    vha->d_id.b.al_pa == d_id.al_pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		return vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	key = be_to_port_id(d_id).b24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	host = btree_lookup32(&vha->hw->tgt.host_map, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		    "Unable to find host %06x\n", key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	return host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	uint16_t vp_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	if (vha->vp_idx == vp_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 		return vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	BUG_ON(ha->tgt.tgt_vp_map == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	if (likely(test_bit(vp_idx, ha->vp_idx_map)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		return ha->tgt.tgt_vp_map[vp_idx].vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	vha->hw->tgt.num_pend_cmds++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		vha->qla_stats.stat_max_pend_cmds =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 			vha->hw->tgt.num_pend_cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	vha->hw->tgt.num_pend_cmds--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	struct atio_from_isp *atio, uint8_t ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	struct qla_tgt_sess_op *u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	if (tgt->tgt_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		ql_dbg(ql_dbg_async, vha, 0x502c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		    "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		goto out_term;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	u = kzalloc(sizeof(*u), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	if (u == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		goto out_term;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	u->vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	memcpy(&u->atio, atio, sizeof(*atio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	INIT_LIST_HEAD(&u->cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	spin_lock_irqsave(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	list_add_tail(&u->cmd_list, &vha->unknown_atio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	schedule_delayed_work(&vha->unknown_atio_work, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) out_term:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	uint8_t ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	struct qla_tgt_sess_op *u, *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	scsi_qla_host_t *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	uint8_t queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		if (u->aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 			ql_dbg(ql_dbg_async, vha, 0x502e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			    "Freeing unknown %s %p, because of Abort\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			    "ATIO_TYPE7", u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			qlt_send_term_exchange(vha->hw->base_qpair, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			    &u->atio, ha_locked, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			goto abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		if (host != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 			    "Requeuing unknown ATIO_TYPE7 %p\n", u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 			qlt_24xx_atio_pkt(host, &u->atio, ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		} else if (tgt->tgt_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			    "Freeing unknown %s %p, because tgt is being stopped\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 			    "ATIO_TYPE7", u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 			qlt_send_term_exchange(vha->hw->base_qpair, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 			    &u->atio, ha_locked, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 			ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			    "Reschedule u %p, vha %p, host %p\n", u, vha, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 			if (!queued) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 				queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 				schedule_delayed_work(&vha->unknown_atio_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 				    1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) abort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		spin_lock_irqsave(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		list_del(&u->cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		kfree(u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) void qlt_unknown_atio_work_fn(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	struct scsi_qla_host *vha = container_of(to_delayed_work(work),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	    struct scsi_qla_host, unknown_atio_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	qlt_try_to_dequeue_unknown_atios(vha, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	struct atio_from_isp *atio, uint8_t ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	ql_dbg(ql_dbg_tgt, vha, 0xe072,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		"%s: qla_target(%d): type %x ox_id %04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		__func__, vha->vp_idx, atio->u.raw.entry_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	switch (atio->u.raw.entry_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	case ATIO_TYPE7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		struct scsi_qla_host *host = qlt_find_host_by_d_id(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		    atio->u.isp24.fcp_hdr.d_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		if (unlikely(NULL == host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			ql_dbg(ql_dbg_tgt, vha, 0xe03e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 			    "qla_target(%d): Received ATIO_TYPE7 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			    "with unknown d_id %x:%x:%x\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 			    atio->u.isp24.fcp_hdr.d_id.domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 			    atio->u.isp24.fcp_hdr.d_id.area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			    atio->u.isp24.fcp_hdr.d_id.al_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			qlt_queue_unknown_atio(vha, atio, ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		if (unlikely(!list_empty(&vha->unknown_atio_list)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			qlt_try_to_dequeue_unknown_atios(vha, ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		qlt_24xx_atio_pkt(host, atio, ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	case IMMED_NOTIFY_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		struct scsi_qla_host *host = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		struct imm_ntfy_from_isp *entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		    (struct imm_ntfy_from_isp *)atio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		qlt_issue_marker(vha, ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		if ((entry->u.isp24.vp_index != 0xFF) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		    (entry->u.isp24.nport_handle != cpu_to_le16(0xFFFF))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			host = qlt_find_host_by_vp_idx(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 			    entry->u.isp24.vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			if (unlikely(!host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 				ql_dbg(ql_dbg_tgt, vha, 0xe03f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 				    "qla_target(%d): Received "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 				    "ATIO (IMMED_NOTIFY_TYPE) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 				    "with unknown vp_index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 				    vha->vp_idx, entry->u.isp24.vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		qlt_24xx_atio_pkt(host, atio, ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	case VP_RPT_ID_IOCB_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		qla24xx_report_id_acquisition(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 			(struct vp_rpt_id_entry_24xx *)atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	case ABTS_RECV_24XX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		struct abts_recv_from_24xx *entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			(struct abts_recv_from_24xx *)atio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			entry->vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		if (unlikely(!host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 			ql_dbg(ql_dbg_tgt, vha, 0xe00a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 			    "qla_target(%d): Response pkt (ABTS_RECV_24XX) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 			    "received, with unknown vp_index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			    vha->vp_idx, entry->vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 			spin_lock_irqsave(&host->hw->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			spin_unlock_irqrestore(&host->hw->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	/* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		ql_dbg(ql_dbg_tgt, vha, 0xe040,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		    "qla_target(%d): Received unknown ATIO atio "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		    "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) void qlt_response_pkt_all_vps(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	struct rsp_que *rsp, response_t *pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	switch (pkt->entry_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	case CTIO_CRC2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		ql_dbg(ql_dbg_tgt, vha, 0xe073,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 			"qla_target(%d):%s: CRC2 Response pkt\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 			vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	case CTIO_TYPE7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		    entry->vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		if (unlikely(!host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 			ql_dbg(ql_dbg_tgt, vha, 0xe041,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 			    "qla_target(%d): Response pkt (CTIO_TYPE7) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			    "received, with unknown vp_index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			    vha->vp_idx, entry->vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		qlt_response_pkt(host, rsp, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	case IMMED_NOTIFY_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		struct scsi_qla_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		struct imm_ntfy_from_isp *entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		    (struct imm_ntfy_from_isp *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		if (unlikely(!host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 			ql_dbg(ql_dbg_tgt, vha, 0xe042,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 			    "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			    "received, with unknown vp_index %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			    vha->vp_idx, entry->u.isp24.vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		qlt_response_pkt(host, rsp, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	case NOTIFY_ACK_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		struct scsi_qla_host *host = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		if (0xFF != entry->u.isp24.vp_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			host = qlt_find_host_by_vp_idx(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			    entry->u.isp24.vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			if (unlikely(!host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 				ql_dbg(ql_dbg_tgt, vha, 0xe043,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 				    "qla_target(%d): Response "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 				    "pkt (NOTIFY_ACK_TYPE) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 				    "received, with unknown "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 				    "vp_index %d\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 				    entry->u.isp24.vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		qlt_response_pkt(host, rsp, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	case ABTS_RECV_24XX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		struct abts_recv_from_24xx *entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		    (struct abts_recv_from_24xx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		    entry->vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		if (unlikely(!host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 			ql_dbg(ql_dbg_tgt, vha, 0xe044,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 			    "qla_target(%d): Response pkt "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			    "(ABTS_RECV_24XX) received, with unknown "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 			    "vp_index %d\n", vha->vp_idx, entry->vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		qlt_response_pkt(host, rsp, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	case ABTS_RESP_24XX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		struct abts_resp_to_24xx *entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		    (struct abts_resp_to_24xx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		    entry->vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		if (unlikely(!host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 			ql_dbg(ql_dbg_tgt, vha, 0xe045,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			    "qla_target(%d): Response pkt "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			    "(ABTS_RECV_24XX) received, with unknown "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			    "vp_index %d\n", vha->vp_idx, entry->vp_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		qlt_response_pkt(host, rsp, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		qlt_response_pkt(vha, rsp, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)  * All qlt_plogi_ack_t operations are protected by hardware_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	struct imm_ntfy_from_isp *ntfy, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	struct qla_work_evt *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	e = qla2x00_alloc_work(vha, QLA_EVT_NACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	if (!e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		return QLA_FUNCTION_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	e->u.nack.fcport = fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	e->u.nack.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	return qla2x00_post_work(vha, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) static void qla2x00_async_nack_sp_done(srb_t *sp, int res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	struct scsi_qla_host *vha = sp->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	ql_dbg(ql_dbg_disc, vha, 0x20f2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	    "Async done-%s res %x %8phC  type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	    sp->name, res, sp->fcport->port_name, sp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	sp->fcport->flags &= ~FCF_ASYNC_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	switch (sp->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	case SRB_NACK_PLOGI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		sp->fcport->login_gen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		sp->fcport->logout_on_delete = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		sp->fcport->plogi_nack_done_deadline = jiffies + HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		sp->fcport->send_els_logo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	case SRB_NACK_PRLI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		sp->fcport->fw_login_state = DSC_LS_PRLI_COMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		sp->fcport->deleted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		sp->fcport->send_els_logo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		if (!sp->fcport->login_succ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		    !IS_SW_RESV_ADDR(sp->fcport->d_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 			sp->fcport->login_succ = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 			vha->fcport_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 			qla24xx_sched_upd_fcport(sp->fcport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 			spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			sp->fcport->login_retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			qla2x00_set_fcport_disc_state(sp->fcport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			    DSC_LOGIN_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 			sp->fcport->deleted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			sp->fcport->logout_on_delete = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	case SRB_NACK_LOGO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		sp->fcport->login_gen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	sp->free(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	struct imm_ntfy_from_isp *ntfy, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	int rval = QLA_FUNCTION_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	srb_t *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	char *c = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	fcport->flags |= FCF_ASYNC_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	case SRB_NACK_PLOGI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		fcport->fw_login_state = DSC_LS_PLOGI_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		c = "PLOGI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	case SRB_NACK_PRLI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		fcport->fw_login_state = DSC_LS_PRLI_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		fcport->deleted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		c = "PRLI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	case SRB_NACK_LOGO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		fcport->fw_login_state = DSC_LS_LOGO_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		c = "LOGO";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	if (!sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	sp->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	sp->name = "nack";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	sp->u.iocb_cmd.u.nack.ntfy = ntfy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	sp->done = qla2x00_async_nack_sp_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	ql_dbg(ql_dbg_disc, vha, 0x20f4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	    "Async-%s %8phC hndl %x %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	    sp->name, fcport->port_name, sp->handle, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	rval = qla2x00_start_sp(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	if (rval != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		goto done_free_sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) done_free_sp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	sp->free(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	fcport->flags &= ~FCF_ASYNC_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	fc_port_t *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	switch (e->u.nack.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	case SRB_NACK_PRLI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		t = e->u.nack.fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		flush_work(&t->del_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		flush_work(&t->free_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		mutex_lock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		t = qlt_create_sess(vha, e->u.nack.fcport, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			ql_log(ql_log_info, vha, 0xd034,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			    "%s create sess success %p", __func__, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 			/* create sess has an extra kref */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 			vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	qla24xx_async_notify_ack(vha, e->u.nack.fcport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	    (struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) void qla24xx_delete_sess_fn(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	fc_port_t *fcport = container_of(work, struct fc_port, del_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	struct qla_hw_data *ha = fcport->vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	if (fcport->se_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		ha->tgt.tgt_ops->shutdown_sess(fcport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		ha->tgt.tgt_ops->put_sess(fcport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		qlt_unreg_sess(fcport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)  * Called from qla2x00_reg_remote_port()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	struct fc_port *sess = fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	if (!vha->hw->tgt.tgt_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	if (tgt->tgt_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	if (fcport->disc_state == DSC_DELETE_PEND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	if (!sess->se_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		mutex_lock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		sess = qlt_create_sess(vha, fcport, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		if (fcport->fw_login_state == DSC_LS_PRLI_COMP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		if (!kref_get_unless_zero(&sess->sess_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			ql_dbg(ql_dbg_disc, vha, 0x2107,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			    "%s: kref_get fail sess %8phC \n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 			    __func__, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 			spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		    "qla_target(%u): %ssession for port %8phC "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		    "(loop ID %d) reappeared\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		    sess->local ? "local " : "", sess->port_name, sess->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		    "Reappeared sess %p\n", sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		ha->tgt.tgt_ops->update_sess(sess, fcport->d_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		    fcport->loop_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		    (fcport->flags & FCF_CONF_COMP_SUPPORTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	if (sess && sess->local) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		    "qla_target(%u): local session for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		    "port %8phC (loop ID %d) became global\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		    fcport->port_name, sess->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		sess->local = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	ha->tgt.tgt_ops->put_sess(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778)  * This is a zero-base ref-counting solution, since hardware_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779)  * guarantees that ref_count is not modified concurrently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780)  * Upon successful return content of iocb is undefined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) static struct qlt_plogi_ack_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		       struct imm_ntfy_from_isp *iocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	struct qlt_plogi_ack_t *pla;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	lockdep_assert_held(&vha->hw->hardware_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	list_for_each_entry(pla, &vha->plogi_ack_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		if (pla->id.b24 == id->b24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 			    "%s %d %8phC Term INOT due to new INOT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 			    __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 			    pla->iocb.u.isp24.port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 			qlt_send_term_imm_notif(vha, &pla->iocb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 			memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 			return pla;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	if (!pla) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		ql_dbg(ql_dbg_async, vha, 0x5088,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		       "qla_target(%d): Allocation of plogi_ack failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		       vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	pla->id = *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	list_add_tail(&pla->list, &vha->plogi_ack_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	return pla;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) void qlt_plogi_ack_unref(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818)     struct qlt_plogi_ack_t *pla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	struct imm_ntfy_from_isp *iocb = &pla->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	port_id_t port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	uint16_t loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	fc_port_t *fcport = pla->fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	BUG_ON(!pla->ref_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	pla->ref_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	if (pla->ref_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	ql_dbg(ql_dbg_disc, vha, 0x5089,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	    "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	    " exch %#x ox_id %#x\n", iocb->u.isp24.port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	    iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	    iocb->u.isp24.port_id[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	    le16_to_cpu(iocb->u.isp24.nport_handle),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	    iocb->u.isp24.exchange_address, iocb->ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	port_id.b.domain = iocb->u.isp24.port_id[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	port_id.b.area   = iocb->u.isp24.port_id[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	port_id.b.al_pa  = iocb->u.isp24.port_id[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	port_id.b.rsvd_1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	fcport->loop_id = loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	fcport->d_id = port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	if (iocb->u.isp24.status_subcode == ELS_PLOGI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	list_for_each_entry(fcport, &vha->vp_fcports, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 			fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	list_del(&pla->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	kmem_cache_free(qla_tgt_plogi_cachep, pla);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866)     struct fc_port *sess, enum qlt_plogi_link_t link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	struct imm_ntfy_from_isp *iocb = &pla->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	/* Inc ref_count first because link might already be pointing at pla */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	pla->ref_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		"Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		" s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		sess, link, sess->port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		iocb->u.isp24.port_name, iocb->u.isp24.port_id[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		pla->ref_count, pla, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	if (link == QLT_PLOGI_LINK_CONFLICT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		switch (sess->disc_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		case DSC_DELETED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		case DSC_DELETE_PEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 			pla->ref_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	if (sess->plogi_link[link])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		qlt_plogi_ack_unref(vha, sess->plogi_link[link]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	if (link == QLT_PLOGI_LINK_SAME_WWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		pla->fcport = sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	sess->plogi_link[link] = pla;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	/* These fields must be initialized by the caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	port_id_t id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	 * number of cmds dropped while we were waiting for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	 * initiator to ack LOGO initialize to 1 if LOGO is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	 * triggered by a command, otherwise, to 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	int cmd_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	/* These fields are used by callee */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) } qlt_port_logo_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	qlt_port_logo_t *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	mutex_lock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	list_for_each_entry(tmp, &vha->logo_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		if (tmp->id.b24 == logo->id.b24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			tmp->cmd_count += logo->cmd_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 			mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	list_add_tail(&logo->list, &vha->logo_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	mutex_lock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	list_del(&logo->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	    "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	    logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	    logo->cmd_count, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) void qlt_free_session_done(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	struct fc_port *sess = container_of(work, struct fc_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	    free_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	struct qla_tgt *tgt = sess->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	struct scsi_qla_host *vha = sess->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	bool logout_started = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	struct qlt_plogi_ack_t *own =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	ql_dbg(ql_dbg_disc, vha, 0xf084,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		"%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		" s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		__func__, sess->se_sess, sess, sess->port_name, sess->loop_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		sess->d_id.b.domain, sess->d_id.b.area, sess->d_id.b.al_pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		sess->logout_on_delete, sess->keep_nport_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		sess->send_els_logo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	if (!IS_SW_RESV_ADDR(sess->d_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		qla2x00_mark_device_lost(vha, sess, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		if (sess->send_els_logo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 			qlt_port_logo_t logo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			logo.id = sess->d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 			logo.cmd_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			if (!own)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 				qlt_send_first_logo(vha, &logo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			sess->send_els_logo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 			int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			if (!own ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 			    (own &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 			     (own->iocb.u.isp24.status_subcode == ELS_PLOGI))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 				rc = qla2x00_post_async_logout_work(vha, sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 				    NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 				if (rc != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 					ql_log(ql_log_warn, vha, 0xf085,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 					    "Schedule logo failed sess %p rc %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 					    sess, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 					logout_started = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 			} else if (own && (own->iocb.u.isp24.status_subcode ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 				ELS_PRLI) && ha->flags.rida_fmt2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 				rc = qla2x00_post_async_prlo_work(vha, sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 				    NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 				if (rc != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 					ql_log(ql_log_warn, vha, 0xf085,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 					    "Schedule PRLO failed sess %p rc %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 					    sess, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 					logout_started = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		} /* if sess->logout_on_delete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		if (sess->nvme_flag & NVME_FLAG_REGISTERED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		    !(sess->nvme_flag & NVME_FLAG_DELETING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 			sess->nvme_flag |= NVME_FLAG_DELETING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 			qla_nvme_unregister_remote_port(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	 * Release the target session for FC Nexus from fabric module code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	if (sess->se_sess != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		ha->tgt.tgt_ops->free_session(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	if (logout_started) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		bool traced = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		u16 cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		while (!READ_ONCE(sess->logout_completed)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 			if (!traced) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 				ql_dbg(ql_dbg_disc, vha, 0xf086,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 					"%s: waiting for sess %p logout\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 					__func__, sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 				traced = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 			msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			if (cnt > 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		ql_dbg(ql_dbg_disc, vha, 0xf087,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		    "%s: sess %p logout completed\n", __func__, sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	if (sess->logo_ack_needed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		sess->logo_ack_needed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		qla24xx_async_notify_ack(vha, sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			(struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	spin_lock_irqsave(&vha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	sess->flags &= ~FCF_ASYNC_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	spin_unlock_irqrestore(&vha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (sess->se_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		sess->se_sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		if (tgt && !IS_SW_RESV_ADDR(sess->d_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 			tgt->sess_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	qla2x00_set_fcport_disc_state(sess, DSC_DELETED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	sess->deleted = QLA_SESS_DELETED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		vha->fcport_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		sess->login_succ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	qla2x00_clear_loop_id(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	if (sess->conflict) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		sess->conflict->login_pause = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		sess->conflict = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		if (!test_bit(UNLOADING, &vha->dpc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 			set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		struct qlt_plogi_ack_t *con =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		    sess->plogi_link[QLT_PLOGI_LINK_CONFLICT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		struct imm_ntfy_from_isp *iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		if (con) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 			iocb = &con->iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 				 "se_sess %p / sess %p port %8phC is gone,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 				 " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 				 sess->se_sess, sess, sess->port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 				 own ? "releasing own PLOGI" : "no own PLOGI pending",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 				 own ? own->ref_count : -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 				 iocb->u.isp24.port_name, con->ref_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 			qlt_plogi_ack_unref(vha, con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 			sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 			    "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 			    sess->se_sess, sess, sess->port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 			    own ? "releasing own PLOGI" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 			    "no own PLOGI pending",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 			    own ? own->ref_count : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		if (own) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			sess->fw_login_state = DSC_LS_PLOGI_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			qlt_plogi_ack_unref(vha, own);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 			sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	sess->explicit_logout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	sess->free_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	qla2x00_dfs_remove_rport(vha, sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	ql_dbg(ql_dbg_disc, vha, 0xf001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	    "Unregistration of sess %p %8phC finished fcp_cnt %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		sess, sess->port_name, vha->fcport_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	if (tgt && (tgt->sess_count == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		wake_up_all(&tgt->waitQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	if (!test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	    !(vha->vp_idx && test_bit(VPORT_DELETE, &vha->dpc_flags)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	    (!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		switch (vha->host->active_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		case MODE_INITIATOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		case MODE_DUAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			qla2xxx_wake_dpc(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		case MODE_TARGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 			/* no-op */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	if (vha->fcport_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		wake_up_all(&vha->fcport_waitQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) /* ha->tgt.sess_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) void qlt_unreg_sess(struct fc_port *sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	struct scsi_qla_host *vha = sess->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	ql_dbg(ql_dbg_disc, sess->vha, 0x210a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	    "%s sess %p for deletion %8phC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	    __func__, sess, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	spin_lock_irqsave(&sess->vha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	if (sess->free_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		spin_unlock_irqrestore(&sess->vha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	sess->free_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	 * Use FCF_ASYNC_SENT flag to block other cmds used in sess
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	 * management from being sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	sess->flags |= FCF_ASYNC_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	spin_unlock_irqrestore(&sess->vha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	if (sess->se_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	sess->last_rscn_gen = sess->rscn_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	sess->last_login_gen = sess->login_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	queue_work(sess->vha->hw->wq, &sess->free_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) EXPORT_SYMBOL(qlt_unreg_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	struct fc_port *sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	uint16_t loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	loop_id = le16_to_cpu(n->u.isp24.nport_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	if (loop_id == 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		/* Global event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		qlt_clear_tgt_db(vha->vha_tgt.qla_tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	ql_dbg(ql_dbg_tgt, vha, 0xe000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	    "Using sess for qla_tgt_reset: %p\n", sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	if (!sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 		res = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	ql_dbg(ql_dbg_tgt, vha, 0xe047,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	    "scsi(%ld): resetting (session %p from port %8phC mcmd %x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	    "loop_id %d)\n", vha->host_no, sess, sess->port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	    mcmd, loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	return qlt_issue_task_mgmt(sess, 0, mcmd, iocb, QLA24XX_MGMT_SEND_NACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) static void qla24xx_chk_fcp_state(struct fc_port *sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		sess->logout_on_delete = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		sess->logo_ack_needed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		sess->fw_login_state = DSC_LS_PORT_UNAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) void qlt_schedule_sess_for_deletion(struct fc_port *sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	struct qla_tgt *tgt = sess->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	u16 sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	switch (sess->disc_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	case DSC_DELETE_PEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	case DSC_DELETED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 			!sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 			if (tgt && tgt->tgt_stop && tgt->sess_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 				wake_up_all(&tgt->waitQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 			if (sess->vha->fcport_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 				wake_up_all(&sess->vha->fcport_waitQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	case DSC_UPD_FCPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		 * This port is not done reporting to upper layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		 * let it finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		sess->next_disc_state = DSC_DELETE_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		sec = jiffies_to_msecs(jiffies -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		    sess->jiffies_at_registration)/1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		if (sess->sec_since_registration < sec && sec && !(sec % 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			sess->sec_since_registration = sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 			ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 			    "%s %8phC : Slow Rport registration(%d Sec)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 			    __func__, sess->port_name, sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	spin_lock_irqsave(&sess->vha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 		spin_unlock_irqrestore(&sess->vha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	sess->deleted = QLA_SESS_DELETION_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	spin_unlock_irqrestore(&sess->vha->work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	sess->prli_pend_timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	qla2x00_set_fcport_disc_state(sess, DSC_DELETE_PEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	qla24xx_chk_fcp_state(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	ql_dbg(ql_dbg_disc, sess->vha, 0xe001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	    "Scheduling sess %p for deletion %8phC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	    sess, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) static void qlt_clear_tgt_db(struct qla_tgt *tgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	struct fc_port *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	scsi_qla_host_t *vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	list_for_each_entry(sess, &vha->vp_fcports, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		if (sess->se_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 			qlt_schedule_sess_for_deletion(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	/* At this point tgt could be already dead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) static int qla24xx_get_loop_id(struct scsi_qla_host *vha, be_id_t s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	uint16_t *loop_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	dma_addr_t gid_list_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	struct gid_list_info *gid_list, *gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	int res, rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	uint16_t entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	    &gid_list_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	if (!gid_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		    "qla_target(%d): DMA Alloc failed of %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		    vha->vp_idx, qla2x00_gid_list_size(ha));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	/* Get list of logged in devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	if (rc != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		    "qla_target(%d): get_id_list() failed: %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		    vha->vp_idx, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		res = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		goto out_free_id_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	gid = gid_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	res = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	for (i = 0; i < entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		if (gid->al_pa == s_id.al_pa &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		    gid->area == s_id.area &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		    gid->domain == s_id.domain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 			*loop_id = le16_to_cpu(gid->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 			res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		gid = (void *)gid + ha->gid_list_info_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) out_free_id_list:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	    gid_list, gid_list_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)  * Adds an extra ref to allow to drop hw lock after adding sess to the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)  * Caller must put it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) static struct fc_port *qlt_create_sess(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	fc_port_t *fcport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	bool local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	struct fc_port *sess = fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	if (vha->vha_tgt.qla_tgt->tgt_stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	if (fcport->se_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		if (!kref_get_unless_zero(&sess->sess_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			ql_dbg(ql_dbg_disc, vha, 0x20f6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			    "%s: kref_get_unless_zero failed for %8phC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			    __func__, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		return fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	sess->tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	sess->local = local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	 * Under normal circumstances we want to logout from firmware when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	 * session eventually ends and release corresponding nport handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	 * In the exception cases (e.g. when new PLOGI is waiting) corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	 * code will adjust these flags as necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	sess->logout_on_delete = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	sess->keep_nport_handle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	sess->logout_completed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	if (ha->tgt.tgt_ops->check_initiator_node_acl(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	    &fcport->port_name[0], sess) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		    "(%d) %8phC check_initiator_node_acl failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		    vha->vp_idx, fcport->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		kref_init(&fcport->sess_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		 * Take an extra reference to ->sess_kref here to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		 * fc_port access across ->tgt.sess_lock reaquire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		if (!kref_get_unless_zero(&sess->sess_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 			ql_dbg(ql_dbg_disc, vha, 0x20f7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 			    "%s: kref_get_unless_zero failed for %8phC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 			    __func__, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		if (!IS_SW_RESV_ADDR(sess->d_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 			vha->vha_tgt.qla_tgt->sess_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		qlt_do_generation_tick(vha, &sess->generation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	    "Adding sess %p se_sess %p  to tgt %p sess_count %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	    sess, sess->se_sess, vha->vha_tgt.qla_tgt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	    vha->vha_tgt.qla_tgt->sess_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	    "qla_target(%d): %ssession for wwn %8phC (loop_id %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	    "s_id %x:%x:%x, confirmed completion %ssupported) added\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	    vha->vp_idx, local ?  "local " : "", fcport->port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	    fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	    sess->d_id.b.al_pa, sess->conf_compl_supported ?  "" : "not ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	return sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)  * max_gen - specifies maximum session generation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)  * at which this deletion requestion is still valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport, int max_gen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	struct fc_port *sess = fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	if (!vha->hw->tgt.tgt_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	if (!tgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	if (tgt->tgt_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	if (!sess->se_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	if (max_gen - sess->generation < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 		    "Ignoring stale deletion request for se_sess %p / sess %p"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		    " for port %8phC, req_gen %d, sess_gen %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		    sess->se_sess, sess, sess->port_name, max_gen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 		    sess->generation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	sess->local = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	qlt_schedule_sess_for_deletion(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) static inline int test_tgt_sess_count(struct qla_tgt *tgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	struct qla_hw_data *ha = tgt->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	 * We need to protect against race, when tgt is freed before or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	 * inside wake_up()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	    "tgt %p, sess_count=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	    tgt, tgt->sess_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	res = (tgt->sess_count == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) /* Called by tcm_qla2xxx configfs code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) int qlt_stop_phase1(struct qla_tgt *tgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	struct scsi_qla_host *vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	struct qla_hw_data *ha = tgt->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	mutex_lock(&ha->optrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	mutex_lock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	if (tgt->tgt_stop || tgt->tgt_stopped) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 		    "Already in tgt->tgt_stop or tgt_stopped state\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		mutex_unlock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 		mutex_unlock(&ha->optrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xe003, "Stopping target for host %ld(%p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	    vha->host_no, vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	 * Mutex needed to sync with qla_tgt_fc_port_[added,deleted].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	 * Lock is needed, because we still can get an incoming packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	mutex_lock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	tgt->tgt_stop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	qlt_clear_tgt_db(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	mutex_unlock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	    "Waiting for sess works (tgt %p)", tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	spin_lock_irqsave(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	while (!list_empty(&tgt->sess_works_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		flush_scheduled_work();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 		spin_lock_irqsave(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	    "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	/* Big hammer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	if (!ha->flags.host_shutting_down &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	    (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 		qlt_disable_vha(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	/* Wait for sessions to clear out (just in case) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	mutex_unlock(&ha->optrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) EXPORT_SYMBOL(qlt_stop_phase1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) /* Called by tcm_qla2xxx configfs code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) void qlt_stop_phase2(struct qla_tgt *tgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	scsi_qla_host_t *vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	if (tgt->tgt_stopped) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		    "Already in tgt->tgt_stopped state\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	if (!tgt->tgt_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		    "%s: phase1 stop is not completed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	mutex_lock(&tgt->ha->optrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	mutex_lock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	tgt->tgt_stop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	tgt->tgt_stopped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	mutex_unlock(&tgt->ha->optrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	    tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	switch (vha->qlini_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	case QLA2XXX_INI_MODE_EXCLUSIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		vha->flags.online = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) EXPORT_SYMBOL(qlt_stop_phase2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) /* Called from qlt_remove_target() -> qla2x00_remove_one() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) static void qlt_release(struct qla_tgt *tgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	scsi_qla_host_t *vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	void *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	u64 key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	u16 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	struct qla_qpair_hint *h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	if (!tgt->tgt_stop && !tgt->tgt_stopped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		qlt_stop_phase1(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 	if (!tgt->tgt_stopped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 		qlt_stop_phase2(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	for (i = 0; i < vha->hw->max_qpairs + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		h = &tgt->qphints[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 		if (h->qpair) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 			spin_lock_irqsave(h->qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 			list_del(&h->hint_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 			spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 			h->qpair = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	kfree(tgt->qphints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	mutex_lock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	mutex_unlock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		btree_remove64(&tgt->lun_qpair_map, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	btree_destroy64(&tgt->lun_qpair_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	if (vha->vp_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 		if (ha->tgt.tgt_ops &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 		    ha->tgt.tgt_ops->remove_target &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		    vha->vha_tgt.target_lport_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 			ha->tgt.tgt_ops->remove_target(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	vha->vha_tgt.qla_tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	    "Release of tgt %p finished\n", tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	kfree(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) static int qlt_sched_sess_work(struct qla_tgt *tgt, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	const void *param, unsigned int param_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	struct qla_tgt_sess_work_param *prm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	prm = kzalloc(sizeof(*prm), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	if (!prm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 		ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 		    "qla_target(%d): Unable to create session "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 		    "work, command will be refused", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	    "Scheduling work (type %d, prm %p)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	    " to find session for param %p (size %d, tgt %p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	    type, prm, param, param_size, tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	prm->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	memcpy(&prm->tm_iocb, param, param_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	spin_lock_irqsave(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	schedule_work(&tgt->sess_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) static void qlt_send_notify_ack(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	struct imm_ntfy_from_isp *ntfy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	struct scsi_qla_host *vha = qpair->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	request_t *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	struct nack_to_isp *nack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	if (!ha->flags.fw_started)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	if (!pkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		ql_dbg(ql_dbg_tgt, vha, 0xe049,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		    "qla_target(%d): %s failed: unable to allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 		    "request packet\n", vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	if (vha->vha_tgt.qla_tgt != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		vha->vha_tgt.qla_tgt->notify_ack_expected++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	pkt->entry_type = NOTIFY_ACK_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	pkt->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	nack = (struct nack_to_isp *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	nack->ox_id = ntfy->ox_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 		nack->u.isp24.flags = ntfy->u.isp24.flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 			cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	nack->u.isp24.status = ntfy->u.isp24.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	nack->u.isp24.srr_flags = cpu_to_le16(srr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	nack->u.isp24.srr_reject_code = srr_reject_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	nack->u.isp24.srr_reject_code_expl = srr_explan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	ql_dbg(ql_dbg_tgt, vha, 0xe005,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	    "qla_target(%d): Sending 24xx Notify Ack %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	    vha->vp_idx, nack->u.isp24.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	struct scsi_qla_host *vha = mcmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	struct abts_resp_to_24xx *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	__le32 f_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	uint32_t h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	uint8_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	struct qla_qpair *qpair = mcmd->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	ql_dbg(ql_dbg_tgt, vha, 0xe006,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	    "Sending task mgmt ABTS response (ha=%p, status=%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	    ha, mcmd->fc_tm_rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	rc = qlt_check_reserve_free_req(qpair, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		ql_dbg(ql_dbg_tgt, vha, 0xe04a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 		    "qla_target(%d): %s failed: unable to allocate request packet\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 		    vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	memset(resp, 0, sizeof(*resp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	h = qlt_make_handle(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		 * CTIO type 7 from the firmware doesn't provide a way to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 		 * know the initiator's LOOP ID, hence we can't find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 		 * the session and, so, the command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 		qpair->req->outstanding_cmds[h] = (srb_t *)mcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	resp->handle = make_handle(qpair->req->id, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	resp->entry_type = ABTS_RESP_24XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	resp->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	resp->nport_handle = abts->nport_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	resp->vp_index = vha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	resp->sof_type = abts->sof_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	resp->exchange_address = abts->exchange_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	resp->fcp_hdr_le = abts->fcp_hdr_le;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	    F_CTL_LAST_SEQ | F_CTL_END_SEQ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	    F_CTL_SEQ_INITIATIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	p = (uint8_t *)&f_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	resp->fcp_hdr_le.f_ctl[0] = *p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	resp->fcp_hdr_le.f_ctl[1] = *p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	resp->fcp_hdr_le.f_ctl[2] = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 		resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 		resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 		resp->payload.ba_acct.low_seq_cnt = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 		resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 		resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 		resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 		resp->payload.ba_rjt.reason_code =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 			BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 		/* Other bytes are zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	vha->vha_tgt.qla_tgt->abts_resp_expected++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	struct abts_recv_from_24xx *abts, uint32_t status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	bool ids_reversed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	struct scsi_qla_host *vha = qpair->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	struct abts_resp_to_24xx *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	__le32 f_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	uint8_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	ql_dbg(ql_dbg_tgt, vha, 0xe006,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	    "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	    ha, abts, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	    NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	if (!resp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 		ql_dbg(ql_dbg_tgt, vha, 0xe04a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 		    "qla_target(%d): %s failed: unable to allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 		    "request packet", vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	resp->entry_type = ABTS_RESP_24XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	resp->handle = QLA_TGT_SKIP_HANDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	resp->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	resp->nport_handle = abts->nport_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 	resp->vp_index = vha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 	resp->sof_type = abts->sof_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	resp->exchange_address = abts->exchange_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	resp->fcp_hdr_le = abts->fcp_hdr_le;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	    F_CTL_LAST_SEQ | F_CTL_END_SEQ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	    F_CTL_SEQ_INITIATIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	p = (uint8_t *)&f_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	resp->fcp_hdr_le.f_ctl[0] = *p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	resp->fcp_hdr_le.f_ctl[1] = *p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	resp->fcp_hdr_le.f_ctl[2] = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	if (ids_reversed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 		resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 		resp->fcp_hdr_le.d_id = abts->fcp_hdr_le.s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 		resp->fcp_hdr_le.s_id = abts->fcp_hdr_le.d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	resp->exchange_addr_to_abort = abts->exchange_addr_to_abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	if (status == FCP_TMF_CMPL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 		resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 		resp->payload.ba_acct.low_seq_cnt = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 		resp->payload.ba_acct.high_seq_cnt = cpu_to_le16(0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 		resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 		resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 		resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 		resp->payload.ba_rjt.reason_code =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 			BA_RJT_REASON_CODE_UNABLE_TO_PERFORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 		/* Other bytes are zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	vha->vha_tgt.qla_tgt->abts_resp_expected++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890)     struct qla_qpair *qpair, response_t *pkt, struct qla_tgt_mgmt_cmd *mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	struct ctio7_to_24xx *ctio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	u16 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	struct abts_recv_from_24xx *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	if (ctio == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 		ql_dbg(ql_dbg_tgt, vha, 0xe04b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 		    "qla_target(%d): %s failed: unable to allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 		    "request packet\n", vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	if (mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		/* abts from remote port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 		entry = &mcmd->orig_iocb.abts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		/* abts from this driver.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 		entry = (struct abts_recv_from_24xx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	 * We've got on entrance firmware's response on by us generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	 * ABTS response. So, in it ID fields are reversed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	ctio->entry_type = CTIO_TYPE7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 	ctio->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	ctio->nport_handle = entry->nport_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	ctio->handle = QLA_TGT_SKIP_HANDLE |	CTIO_COMPLETION_HANDLE_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 	ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 	ctio->vp_index = vha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	ctio->exchange_addr = entry->exchange_addr_to_abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	if (mcmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		ctio->initiator_id = entry->fcp_hdr_le.s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 		if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 			tmp |= (mcmd->abort_io_attr << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		else if (qpair->retry_term_cnt & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 			tmp |= (0x4 << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 		ctio->initiator_id = entry->fcp_hdr_le.d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 		if (qpair->retry_term_cnt & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 			tmp |= (0x4 << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	ctio->u.status1.flags = cpu_to_le16(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	ql_dbg(ql_dbg_tgt, vha, 0xe007,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	    "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	    le16_to_cpu(ctio->u.status1.flags),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	    le16_to_cpu(ctio->u.status1.ox_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	    (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 		qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	if (mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		qlt_build_abts_resp_iocb(mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 		qlt_24xx_send_abts_resp(qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 		    (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) /* drop cmds for the given lun
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)  * XXX only looks for cmds on the port through which lun reset was recieved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964)  * XXX does not go through the list of other port (which may have cmds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)  *     for the same lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) static void abort_cmds_for_lun(struct scsi_qla_host *vha, u64 lun, be_id_t s_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	struct qla_tgt_sess_op *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	struct qla_tgt_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	uint32_t key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	key = sid_to_key(s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 	spin_lock_irqsave(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 	list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 		uint32_t op_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 		u64 op_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 		op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 		op_lun = scsilun_to_int(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 			(struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 		if (op_key == key && op_lun == lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 			op->aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 		uint32_t op_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 		u64 op_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 		op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 		op_lun = scsilun_to_int(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 			(struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 		if (op_key == key && op_lun == lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 			op->aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 	list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 		uint32_t cmd_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 		u64 cmd_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 		cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 		cmd_lun = scsilun_to_int(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 			(struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 		if (cmd_key == key && cmd_lun == lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 			cmd->aborted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012)     uint64_t unpacked_lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	struct qla_qpair_hint *h = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	if (vha->flags.qpairs_available) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 		h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 		if (!h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 			h = &tgt->qphints[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 		h = &tgt->qphints[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	return h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) static void qlt_do_tmr_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 	struct qla_tgt_mgmt_cmd *mcmd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 		container_of(work, struct qla_tgt_mgmt_cmd, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	struct qla_hw_data *ha = mcmd->vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	uint32_t tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	switch (mcmd->tmr_func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	case QLA_TGT_ABTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 		tag = le32_to_cpu(mcmd->orig_iocb.abts.exchange_addr_to_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 		tag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 	    mcmd->tmr_func, tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 	if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 		spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		switch (mcmd->tmr_func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 		case QLA_TGT_ABTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 			mcmd->fc_tm_rsp = FCP_TMF_REJECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 			qlt_build_abts_resp_iocb(mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 		case QLA_TGT_LUN_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		case QLA_TGT_CLEAR_TS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		case QLA_TGT_ABORT_TS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 		case QLA_TGT_CLEAR_ACA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		case QLA_TGT_TARGET_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 			qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 			    qla_sam_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		case QLA_TGT_ABORT_ALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		case QLA_TGT_NEXUS_LOSS_SESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 		case QLA_TGT_NEXUS_LOSS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 			qlt_send_notify_ack(mcmd->qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 			    &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 		spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 		ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 		    "qla_target(%d):  tgt_ops->handle_tmr() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 		    mcmd->vha->vp_idx, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 		mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	struct abts_recv_from_24xx *abts, struct fc_port *sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	struct qla_tgt_mgmt_cmd *mcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	    "qla_target(%d): task abort (tag=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	    vha->vp_idx, abts->exchange_addr_to_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	if (mcmd == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 		    "qla_target(%d): %s: Allocation of ABORT cmd failed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 		    vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 	memset(mcmd, 0, sizeof(*mcmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	mcmd->cmd_type = TYPE_TGT_TMCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	mcmd->sess = sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	mcmd->reset_count = ha->base_qpair->chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 	mcmd->tmr_func = QLA_TGT_ABTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 	mcmd->qpair = h->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	mcmd->vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 	 * LUN is looked up by target-core internally based on the passed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 	 * abts->exchange_addr_to_abort tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 	mcmd->se_cmd.cpuid = h->cpuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 	if (ha->tgt.tgt_ops->find_cmd_by_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 		struct qla_tgt_cmd *abort_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 		abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 				le32_to_cpu(abts->exchange_addr_to_abort));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 		if (abort_cmd && abort_cmd->qpair) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 			mcmd->qpair = abort_cmd->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 			mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 			mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 			mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	INIT_WORK(&mcmd->work, qlt_do_tmr_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 	queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) static void qlt_24xx_handle_abts(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	struct abts_recv_from_24xx *abts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	struct fc_port *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	uint32_t tag = le32_to_cpu(abts->exchange_addr_to_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	be_id_t s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 	if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 		    "qla_target(%d): ABTS: Abort Sequence not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 		    "supported\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		    false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 		    "qla_target(%d): ABTS: Unknown Exchange "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 		    "Address received\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 		    false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 	    "qla_target(%d): task abort (s_id=%x:%x:%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	    "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id.domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	    abts->fcp_hdr_le.s_id.area, abts->fcp_hdr_le.s_id.al_pa, tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	    le32_to_cpu(abts->fcp_hdr_le.parameter));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 	s_id = le_id_to_be(abts->fcp_hdr_le.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 	if (!sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 		    "qla_target(%d): task abort for non-existent session\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 		    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 			    false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 	if (sess->deleted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 		    false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 	rc = __qlt_24xx_handle_abts(vha, abts, sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 	if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 		    "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 		    vha->vp_idx, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 		qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 		    false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	struct scsi_qla_host *ha = mcmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	struct atio_from_isp *atio = &mcmd->orig_iocb.atio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	struct ctio7_to_24xx *ctio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	uint16_t temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	ql_dbg(ql_dbg_tgt, ha, 0xe008,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	    "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	    ha, atio, resp_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 	if (ctio == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 		ql_dbg(ql_dbg_tgt, ha, 0xe04c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 		    "qla_target(%d): %s failed: unable to allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 		    "request packet\n", ha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 	ctio->entry_type = CTIO_TYPE7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 	ctio->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 	ctio->nport_handle = cpu_to_le16(mcmd->sess->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	ctio->vp_index = ha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 	ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 	ctio->exchange_addr = atio->u.isp24.exchange_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	temp = (atio->u.isp24.attr << 9)|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	ctio->u.status1.flags = cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 	ctio->u.status1.ox_id = cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	ctio->u.status1.scsi_status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	    cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 	ctio->u.status1.response_len = cpu_to_le16(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 	ctio->u.status1.sense_data[0] = resp_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 		qla2x00_start_iocbs(ha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 	mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) EXPORT_SYMBOL(qlt_free_mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262)  * ha->hardware_lock supposed to be held on entry. Might drop it, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263)  * reacquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266)     uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 	struct atio_from_isp *atio = &cmd->atio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	struct ctio7_to_24xx *ctio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 	uint16_t temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	struct scsi_qla_host *vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	ql_dbg(ql_dbg_tgt_dif, vha, 0x3066,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 	    "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	    "sense_key=%02x, asc=%02x, ascq=%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 	    vha, atio, scsi_status, sense_key, asc, ascq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 	ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	if (!ctio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 		ql_dbg(ql_dbg_async, vha, 0x3067,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		    "qla2x00t(%ld): %s failed: unable to allocate request packet",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 		    vha->host_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 	ctio->entry_type = CTIO_TYPE7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	ctio->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 	ctio->handle = QLA_TGT_SKIP_HANDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 	ctio->nport_handle = cpu_to_le16(cmd->sess->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 	ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	ctio->vp_index = vha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 	ctio->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 	ctio->exchange_addr = atio->u.isp24.exchange_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 	temp = (atio->u.isp24.attr << 9) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 	    CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 	ctio->u.status1.flags = cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	ctio->u.status1.ox_id = cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	ctio->u.status1.scsi_status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 	    cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 	ctio->u.status1.response_len = cpu_to_le16(18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 	ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 	if (ctio->u.status1.residual != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 		ctio->u.status1.scsi_status |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 		    cpu_to_le16(SS_RESIDUAL_UNDER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 	/* Fixed format sense data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	ctio->u.status1.sense_data[0] = 0x70;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 	ctio->u.status1.sense_data[2] = sense_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 	/* Additional sense length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 	ctio->u.status1.sense_data[7] = 0xa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	/* ASC and ASCQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 	ctio->u.status1.sense_data[12] = asc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 	ctio->u.status1.sense_data[13] = ascq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 		qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) /* callback from target fabric module code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 	struct scsi_qla_host *vha = mcmd->sess->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 	struct qla_qpair *qpair = mcmd->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	bool free_mcmd = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	    "TM response mcmd (%p) status %#x state %#x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 	    mcmd, mcmd->fc_tm_rsp, mcmd->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	spin_lock_irqsave(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 		 * Either the port is not online or this request was from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 		 * previous life, just abort the processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 		ql_dbg(ql_dbg_async, vha, 0xe100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 			"RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 			vha->flags.online, qla2x00_reset_active(vha),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 			mcmd->reset_count, qpair->chip_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 		ha->tgt.tgt_ops->free_mcmd(mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 		switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 		case ELS_LOGO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 		case ELS_PRLO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 		case ELS_TPRLO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 			ql_dbg(ql_dbg_disc, vha, 0x2106,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 			    "TM response logo %8phC status %#x state %#x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 			    mcmd->sess->port_name, mcmd->fc_tm_rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 			    mcmd->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 			qlt_schedule_sess_for_deletion(mcmd->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 			qlt_send_notify_ack(vha->hw->base_qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 			    &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 		if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 			qlt_build_abts_resp_iocb(mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 			free_mcmd = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 			qlt_24xx_send_task_mgmt_ctio(qpair, mcmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 			    mcmd->fc_tm_rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 	 * Make the callback for ->free_mcmd() to queue_work() and invoke
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 	 * target_put_sess_cmd() to drop cmd_kref to 1.  The final
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 	 * target_put_sess_cmd() call will be made from TFO->check_stop_free()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 	 * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	 * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() ->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	 * qlt_xmit_tm_rsp() returns here..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	if (free_mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 		ha->tgt.tgt_ops->free_mcmd(mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) EXPORT_SYMBOL(qlt_xmit_tm_rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) /* No locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 	struct qla_tgt_cmd *cmd = prm->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	BUG_ON(cmd->sg_cnt == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 	prm->sg = (struct scatterlist *)cmd->sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 	prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 	    cmd->sg_cnt, cmd->dma_data_direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 	if (unlikely(prm->seg_cnt == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 	prm->cmd->sg_mapped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 	if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 		 * If greater than four sg entries then we need to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 		 * the continuation entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 		if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 			prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 			QLA_TGT_DATASEGS_PER_CMD_24XX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 			QLA_TGT_DATASEGS_PER_CONT_24XX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 		/* DIF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 		if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 		    (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 			prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 			prm->tot_dsds = prm->seg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 			prm->tot_dsds = prm->seg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 		if (cmd->prot_sg_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 			prm->prot_sg      = cmd->prot_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 			prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 				cmd->prot_sg, cmd->prot_sg_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 				cmd->dma_data_direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 			if (unlikely(prm->prot_seg_cnt == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 				goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 			if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 			    (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 				/* Dif Bundling not support here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 				prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 								cmd->blk_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 				prm->tot_dsds += prm->prot_seg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 				prm->tot_dsds += prm->prot_seg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 	    "qla_target(%d): PCI mapping failed: sg_cnt=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 	    0, prm->cmd->sg_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) static void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 	struct qla_hw_data *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	struct qla_qpair *qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 	if (!cmd->sg_mapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 	qpair = cmd->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 	dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 	    cmd->dma_data_direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 	cmd->sg_mapped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 	if (cmd->prot_sg_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 		dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 			cmd->dma_data_direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 	if (!cmd->ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 	ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 	if (cmd->ctx_dsd_alloced)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		qla2x00_clean_dsd_pool(ha, cmd->ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 	dma_pool_free(ha->dl_dma_pool, cmd->ctx, cmd->ctx->crc_ctx_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) static int qlt_check_reserve_free_req(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 	uint32_t req_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 	uint32_t cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 	struct req_que *req = qpair->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 	if (req->cnt < (req_cnt + 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 		cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 		    rd_reg_dword_relaxed(req->req_q_out));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		if  (req->ring_index < cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 			req->cnt = cnt - req->ring_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 			req->cnt = req->length - (req->ring_index - cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 		if (unlikely(req->cnt < (req_cnt + 2)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 			return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 	req->cnt -= req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) static inline void *qlt_get_req_pkt(struct req_que *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 	/* Adjust ring index. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 	req->ring_index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 	if (req->ring_index == req->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 		req->ring_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 		req->ring_ptr = req->ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 		req->ring_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 	return (cont_entry_t *)req->ring_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) static inline uint32_t qlt_make_handle(struct qla_qpair *qpair)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 	uint32_t h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 	uint8_t found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	struct req_que *req = qpair->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 	h = req->current_outstanding_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 	for (index = 1; index < req->num_outstanding_cmds; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 		h++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 		if (h == req->num_outstanding_cmds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 			h = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 		if (h == QLA_TGT_SKIP_HANDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 		if (!req->outstanding_cmds[h]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 			found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 	if (found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 		req->current_outstanding_cmd = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 		ql_dbg(ql_dbg_io, qpair->vha, 0x305b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 		    "qla_target(%d): Ran out of empty cmd slots\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 		    qpair->vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 		h = QLA_TGT_NULL_HANDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 	return h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 	struct qla_tgt_prm *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 	uint32_t h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 	struct ctio7_to_24xx *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 	struct atio_from_isp *atio = &prm->cmd->atio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 	uint16_t temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 	pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 	prm->pkt = pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 	memset(pkt, 0, sizeof(*pkt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 	pkt->entry_type = CTIO_TYPE7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 	pkt->entry_count = (uint8_t)prm->req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 	pkt->vp_index = prm->cmd->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 	h = qlt_make_handle(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 	if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		 * CTIO type 7 from the firmware doesn't provide a way to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 		 * know the initiator's LOOP ID, hence we can't find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 		 * the session and, so, the command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 		qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 	pkt->handle = make_handle(qpair->req->id, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 	pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 	pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 	pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 	pkt->exchange_addr = atio->u.isp24.exchange_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 	temp = atio->u.isp24.attr << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 	pkt->u.status0.flags |= cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 	pkt->u.status0.ox_id = cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 	pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605)  * ha->hardware_lock supposed to be held on entry. We have already made sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)  * that there is sufficient amount of request entries to not drop it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 	int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 	struct dsd64 *cur_dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 	/* Build continuation packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 	while (prm->seg_cnt > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 		cont_a64_entry_t *cont_pkt64 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 			(cont_a64_entry_t *)qlt_get_req_pkt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 			   prm->cmd->qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 		 * Make sure that from cont_pkt64 none of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 		 * 64-bit specific fields used for 32-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 		 * addressing. Cast to (cont_entry_t *) for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 		 * that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 		memset(cont_pkt64, 0, sizeof(*cont_pkt64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 		cont_pkt64->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 		cont_pkt64->sys_define = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 		cont_pkt64->entry_type = CONTINUE_A64_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 		cur_dsd = cont_pkt64->dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 		/* Load continuation entry data segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 		for (cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 		    cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 		    cnt++, prm->seg_cnt--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 			append_dsd64(&cur_dsd, prm->sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 			prm->sg = sg_next(prm->sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)  * ha->hardware_lock supposed to be held on entry. We have already made sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)  * that there is sufficient amount of request entries to not drop it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) static void qlt_load_data_segments(struct qla_tgt_prm *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 	int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 	struct dsd64 *cur_dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 	struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 	pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 	/* Setup packet address segment pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 	cur_dsd = &pkt24->u.status0.dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	/* Set total data segment count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 	if (prm->seg_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 		pkt24->dseg_count = cpu_to_le16(prm->seg_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 	if (prm->seg_cnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 		/* No data transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 		cur_dsd->address = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 		cur_dsd->length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	/* If scatter gather */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 	/* Load command entry data segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 	for (cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 	    (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 	    cnt++, prm->seg_cnt--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 		append_dsd64(&cur_dsd, prm->sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 		prm->sg = sg_next(prm->sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 	qlt_load_cont_data_segments(prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) static inline int qlt_has_data(struct qla_tgt_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 	return cmd->bufflen > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) static void qlt_print_dif_err(struct qla_tgt_prm *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 	struct qla_tgt_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 	struct scsi_qla_host *vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 	/* asc 0x10=dif error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 	if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 		cmd = prm->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 		vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 		/* ASCQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 		switch (prm->sense_buffer[13]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 			ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 			    "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 			    "se_cmd=%p tag[%x]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 			    cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 			    cmd->atio.u.isp24.exchange_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 			ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 			    "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 			    "se_cmd=%p tag[%x]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 			    cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 			    cmd->atio.u.isp24.exchange_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 			ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 			    "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 			    "se_cmd=%p tag[%x]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 			    cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 			    cmd->atio.u.isp24.exchange_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 			ql_dbg(ql_dbg_tgt_dif, vha, 0xe010,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 			    "BE detected Dif ERR: lba[%llx|%lld] len[%x] "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 			    "se_cmd=%p tag[%x]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 			    cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 			    cmd->atio.u.isp24.exchange_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 		ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733)  * Called without ha->hardware_lock held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 	struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 	uint32_t *full_req_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 	struct se_cmd *se_cmd = &cmd->se_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 	struct qla_qpair *qpair = cmd->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	prm->cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	prm->tgt = cmd->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 	prm->pkt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 	prm->rq_result = scsi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 	prm->sense_buffer = &cmd->sense_buffer[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 	prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	prm->sg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 	prm->seg_cnt = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 	prm->req_cnt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 	prm->residual = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 	prm->add_status_pkt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 	prm->prot_sg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 	prm->prot_seg_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 	prm->tot_dsds = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 	if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 		if  (qlt_pci_map_calc_cnt(prm) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 			return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 	*full_req_cnt = prm->req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 	if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 		prm->residual = se_cmd->residual_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 		ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 		    "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 		       prm->residual, se_cmd->tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 		       se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 		       cmd->bufflen, prm->rq_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 		prm->rq_result |= SS_RESIDUAL_UNDER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 	} else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 		prm->residual = se_cmd->residual_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 		ql_dbg_qp(ql_dbg_io, qpair, 0x305d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 		    "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 		       prm->residual, se_cmd->tag, se_cmd->t_task_cdb ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 		       se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 		prm->rq_result |= SS_RESIDUAL_OVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 	if (xmit_type & QLA_TGT_XMIT_STATUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 		 * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 		 * ignored in *xmit_response() below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 		if (qlt_has_data(cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 			if (QLA_TGT_SENSE_VALID(prm->sense_buffer) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 			    (IS_FWI2_CAPABLE(cmd->vha->hw) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 			    (prm->rq_result != 0))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 				prm->add_status_pkt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 				(*full_req_cnt)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800)     int sending_sense)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 	if (cmd->qpair->enable_class_2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 	if (sending_sense)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 		return cmd->conf_compl_supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 		return cmd->qpair->enable_explicit_conf &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809)                     cmd->conf_compl_supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 	struct qla_tgt_prm *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 	prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 	    (uint32_t)sizeof(ctio->u.status1.sense_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 	ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	if (qlt_need_explicit_conf(prm->cmd, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 		ctio->u.status0.flags |= cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 		    CTIO7_FLAGS_EXPLICIT_CONFORM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 		    CTIO7_FLAGS_CONFORM_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 	ctio->u.status0.residual = cpu_to_le32(prm->residual);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 	ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 	if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 		if (qlt_need_explicit_conf(prm->cmd, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 			if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 				ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 				    "Skipping EXPLICIT_CONFORM and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 				    "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 				    "non GOOD status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 				goto skip_explict_conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 			ctio->u.status1.flags |= cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 			    CTIO7_FLAGS_EXPLICIT_CONFORM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 			    CTIO7_FLAGS_CONFORM_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) skip_explict_conf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 		ctio->u.status1.flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 		    ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 		ctio->u.status1.flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 		    cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 		ctio->u.status1.scsi_status |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 		    cpu_to_le16(SS_SENSE_LEN_VALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 		ctio->u.status1.sense_length =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 		    cpu_to_le16(prm->sense_buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 		for (i = 0; i < prm->sense_buffer_len/4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 			uint32_t v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 			v = get_unaligned_be32(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 					&((uint32_t *)prm->sense_buffer)[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 			put_unaligned_le32(v,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 				&((uint32_t *)ctio->u.status1.sense_data)[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 		qlt_print_dif_err(prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 		ctio->u.status1.flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 		    ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 		ctio->u.status1.flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 		    cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 		ctio->u.status1.sense_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 		memset(ctio->u.status1.sense_data, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 		    sizeof(ctio->u.status1.sense_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 	/* Sense with len > 24, is it possible ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) qlt_hba_err_chk_enabled(struct se_cmd *se_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 	switch (se_cmd->prot_op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 	case TARGET_PROT_DOUT_INSERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 	case TARGET_PROT_DIN_STRIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 		if (ql2xenablehba_err_chk >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 	case TARGET_PROT_DOUT_PASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 	case TARGET_PROT_DIN_PASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 		if (ql2xenablehba_err_chk >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 	case TARGET_PROT_DIN_INSERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 	case TARGET_PROT_DOUT_STRIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) qla_tgt_ref_mask_check(struct se_cmd *se_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 	switch (se_cmd->prot_op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 	case TARGET_PROT_DIN_INSERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 	case TARGET_PROT_DOUT_INSERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 	case TARGET_PROT_DIN_STRIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 	case TARGET_PROT_DOUT_STRIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 	case TARGET_PROT_DIN_PASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 	case TARGET_PROT_DOUT_PASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 	    return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 	    return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913)  * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917)     uint16_t *pfw_prot_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 	struct se_cmd *se_cmd = &cmd->se_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 	uint32_t lba = 0xffffffff & se_cmd->t_task_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 	scsi_qla_host_t *vha = cmd->tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 	uint32_t t32 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 	 * wait till Mode Sense/Select cmd, modepage Ah, subpage 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 	 * have been immplemented by TCM, before AppTag is avail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	 * Look for modesense_handlers[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 	ctx->app_tag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 	ctx->app_tag_mask[0] = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 	ctx->app_tag_mask[1] = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 	if (IS_PI_UNINIT_CAPABLE(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 		if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 		    (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 			*pfw_prot_opts |= PO_DIS_VALD_APP_ESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 		else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 			*pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 	t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 	switch (se_cmd->prot_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 	case TARGET_DIF_TYPE0_PROT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 		 * No check for ql2xenablehba_err_chk, as it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 		 * would be an I/O error if hba tag generation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 		 * is not done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 		ctx->ref_tag = cpu_to_le32(lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 		/* enable ALL bytes of the ref tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 		ctx->ref_tag_mask[0] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 		ctx->ref_tag_mask[1] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 		ctx->ref_tag_mask[2] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 		ctx->ref_tag_mask[3] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 	case TARGET_DIF_TYPE1_PROT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 	    /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 	     * For TYPE 1 protection: 16 bit GUARD tag, 32 bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 	     * REF tag, and 16 bit app tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 	     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 	    ctx->ref_tag = cpu_to_le32(lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 	    if (!qla_tgt_ref_mask_check(se_cmd) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 		!(ha->tgt.tgt_ops->chk_dif_tags(t32))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 		    *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 		    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 	    /* enable ALL bytes of the ref tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 	    ctx->ref_tag_mask[0] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 	    ctx->ref_tag_mask[1] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 	    ctx->ref_tag_mask[2] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 	    ctx->ref_tag_mask[3] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 	case TARGET_DIF_TYPE2_PROT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 	    /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 	     * For TYPE 2 protection: 16 bit GUARD + 32 bit REF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 	     * tag has to match LBA in CDB + N
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 	     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 	    ctx->ref_tag = cpu_to_le32(lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 	    if (!qla_tgt_ref_mask_check(se_cmd) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 		!(ha->tgt.tgt_ops->chk_dif_tags(t32))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 		    *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 		    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 	    /* enable ALL bytes of the ref tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 	    ctx->ref_tag_mask[0] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 	    ctx->ref_tag_mask[1] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 	    ctx->ref_tag_mask[2] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 	    ctx->ref_tag_mask[3] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 	case TARGET_DIF_TYPE3_PROT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 	    /* For TYPE 3 protection: 16 bit GUARD only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 	    *pfw_prot_opts |= PO_DIS_REF_TAG_VALD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 	    ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 		ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) qlt_build_ctio_crc2_pkt(struct qla_qpair *qpair, struct qla_tgt_prm *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 	struct dsd64		*cur_dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 	uint32_t		transfer_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 	uint32_t		data_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 	uint32_t		dif_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 	uint8_t			bundling = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 	struct crc_context	*crc_ctx_pkt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 	struct qla_hw_data	*ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 	struct ctio_crc2_to_fw	*pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 	dma_addr_t		crc_ctx_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 	uint16_t		fw_prot_opts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 	struct qla_tgt_cmd	*cmd = prm->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 	struct se_cmd		*se_cmd = &cmd->se_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 	uint32_t h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 	struct atio_from_isp *atio = &prm->cmd->atio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 	struct qla_tc_param	tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 	uint16_t t16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 	scsi_qla_host_t *vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 	ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 	pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 	prm->pkt = pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 	memset(pkt, 0, sizeof(*pkt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 	ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 		"qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 		cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 		prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 	if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 	    (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 		bundling = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 	/* Compute dif len and adjust data len to incude protection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 	data_bytes = cmd->bufflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 	dif_bytes  = (data_bytes / cmd->blk_sz) * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 	switch (se_cmd->prot_op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 	case TARGET_PROT_DIN_INSERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 	case TARGET_PROT_DOUT_STRIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 		transfer_length = data_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 		if (cmd->prot_sg_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 			data_bytes += dif_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 	case TARGET_PROT_DIN_STRIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 	case TARGET_PROT_DOUT_INSERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 	case TARGET_PROT_DIN_PASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 	case TARGET_PROT_DOUT_PASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 		transfer_length = data_bytes + dif_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 	if (!qlt_hba_err_chk_enabled(se_cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 		fw_prot_opts |= 0x10; /* Disable Guard tag checking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 	/* HBA error checking enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	else if (IS_PI_UNINIT_CAPABLE(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 		if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 		    (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 			fw_prot_opts |= PO_DIS_VALD_APP_ESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 		else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 			fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 	switch (se_cmd->prot_op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 	case TARGET_PROT_DIN_INSERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	case TARGET_PROT_DOUT_INSERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 		fw_prot_opts |= PO_MODE_DIF_INSERT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 	case TARGET_PROT_DIN_STRIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 	case TARGET_PROT_DOUT_STRIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 		fw_prot_opts |= PO_MODE_DIF_REMOVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 	case TARGET_PROT_DIN_PASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 	case TARGET_PROT_DOUT_PASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 		fw_prot_opts |= PO_MODE_DIF_PASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 		/* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 	default:/* Normal Request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 		fw_prot_opts |= PO_MODE_DIF_PASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 	/* ---- PKT ---- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 	/* Update entry type to indicate Command Type CRC_2 IOCB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 	pkt->entry_type  = CTIO_CRC2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 	pkt->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 	pkt->vp_index = cmd->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 	h = qlt_make_handle(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 	if (unlikely(h == QLA_TGT_NULL_HANDLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 		 * CTIO type 7 from the firmware doesn't provide a way to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 		 * know the initiator's LOOP ID, hence we can't find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 		 * the session and, so, the command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 		qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 	pkt->handle  = make_handle(qpair->req->id, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 	pkt->handle |= CTIO_COMPLETION_HANDLE_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 	pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) 	pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 	pkt->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 	pkt->exchange_addr   = atio->u.isp24.exchange_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 	/* silence compile warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 	t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 	pkt->ox_id  = cpu_to_le16(t16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 	t16 = (atio->u.isp24.attr << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 	pkt->flags |= cpu_to_le16(t16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 	pkt->relative_offset = cpu_to_le32(prm->cmd->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 	/* Set transfer direction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 	if (cmd->dma_data_direction == DMA_TO_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 		pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 	else if (cmd->dma_data_direction == DMA_FROM_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 		pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 	pkt->dseg_count = cpu_to_le16(prm->tot_dsds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 	/* Fibre channel byte count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 	pkt->transfer_length = cpu_to_le32(transfer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 	/* ----- CRC context -------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 	/* Allocate CRC context from global pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 	crc_ctx_pkt = cmd->ctx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 	    dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 	if (!crc_ctx_pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 		goto crc_queuing_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 	crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 	INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 	/* Set handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 	crc_ctx_pkt->handle = pkt->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 	qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 	put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 	pkt->crc_context_len = cpu_to_le16(CRC_CONTEXT_LEN_FW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 	if (!bundling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 		cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 		 * Configure Bundling if we need to fetch interlaving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 		 * protection PCI accesses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) 		fw_prot_opts |= PO_ENABLE_DIF_BUNDLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 		crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 		crc_ctx_pkt->u.bundling.dseg_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 			cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 		cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 	/* Finish the common fields of CRC pkt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 	crc_ctx_pkt->blk_size   = cpu_to_le16(cmd->blk_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 	crc_ctx_pkt->prot_opts  = cpu_to_le16(fw_prot_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 	crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 	crc_ctx_pkt->guard_seed = cpu_to_le16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 	memset((uint8_t *)&tc, 0 , sizeof(tc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 	tc.vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 	tc.blk_sz = cmd->blk_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 	tc.bufflen = cmd->bufflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 	tc.sg = cmd->sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 	tc.prot_sg = cmd->prot_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 	tc.ctx = crc_ctx_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 	tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 	/* Walks data segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 	pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 	if (!bundling && prm->prot_seg_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 		if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 			prm->tot_dsds, &tc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 			goto crc_queuing_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 	} else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 		(prm->tot_dsds - prm->prot_seg_cnt), &tc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 		goto crc_queuing_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 	if (bundling && prm->prot_seg_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 		/* Walks dif segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 		pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 		cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 		if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 			prm->prot_seg_cnt, cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 			goto crc_queuing_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 	return QLA_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) crc_queuing_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 	/* Cleanup will be performed by the caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 	qpair->req->outstanding_cmds[h] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 	return QLA_FUNCTION_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210)  * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211)  * QLA_TGT_XMIT_STATUS for >= 24xx silicon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 	uint8_t scsi_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 	struct scsi_qla_host *vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 	struct qla_qpair *qpair = cmd->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 	struct ctio7_to_24xx *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 	struct qla_tgt_prm prm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 	uint32_t full_req_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 	if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 	    (cmd->sess && cmd->sess->deleted)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 		cmd->state = QLA_TGT_STATE_PROCESSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) 	ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 	    "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 	    (xmit_type & QLA_TGT_XMIT_STATUS) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 	    1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 	    &cmd->se_cmd, qpair->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 	res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 	    &full_req_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 	if (unlikely(res != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 	spin_lock_irqsave(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 	if (xmit_type == QLA_TGT_XMIT_STATUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 		qpair->tgt_counters.core_qla_snd_status++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 		qpair->tgt_counters.core_qla_que_buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 	if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 		 * Either the port is not online or this request was from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 		 * previous life, just abort the processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 		cmd->state = QLA_TGT_STATE_PROCESSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 		ql_dbg_qp(ql_dbg_async, qpair, 0xe101,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 			"RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 			vha->flags.online, qla2x00_reset_active(vha),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 			cmd->reset_count, qpair->chip_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 		res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 		goto out_unmap_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 	/* Does F/W have an IOCBs for this request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 	res = qlt_check_reserve_free_req(qpair, full_req_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 	if (unlikely(res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 		goto out_unmap_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 	if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 		res = qlt_build_ctio_crc2_pkt(qpair, &prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 		res = qlt_24xx_build_ctio_pkt(qpair, &prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 	if (unlikely(res != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 		qpair->req->cnt += full_req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 		goto out_unmap_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 	pkt = (struct ctio7_to_24xx *)prm.pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 	if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 		pkt->u.status0.flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 		    cpu_to_le16(CTIO7_FLAGS_DATA_IN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 			CTIO7_FLAGS_STATUS_MODE_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 		if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 			qlt_load_data_segments(&prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 		if (prm.add_status_pkt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 			if (xmit_type & QLA_TGT_XMIT_STATUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 				pkt->u.status0.scsi_status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 				    cpu_to_le16(prm.rq_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 				pkt->u.status0.residual =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 				    cpu_to_le32(prm.residual);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 				pkt->u.status0.flags |= cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 				    CTIO7_FLAGS_SEND_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 				if (qlt_need_explicit_conf(cmd, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 					pkt->u.status0.flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 					    cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) 						CTIO7_FLAGS_EXPLICIT_CONFORM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 						CTIO7_FLAGS_CONFORM_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 			 * We have already made sure that there is sufficient
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 			 * amount of request entries to not drop HW lock in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 			 * req_pkt().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 			struct ctio7_to_24xx *ctio =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 				(struct ctio7_to_24xx *)qlt_get_req_pkt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 				    qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 			ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 			    "Building additional status packet 0x%p.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 			    ctio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 			 * T10Dif: ctio_crc2_to_fw overlay ontop of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 			 * ctio7_to_24xx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 			memcpy(ctio, pkt, sizeof(*ctio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 			/* reset back to CTIO7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) 			ctio->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 			ctio->entry_type = CTIO_TYPE7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) 			ctio->dseg_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 			ctio->u.status1.flags &= ~cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) 			    CTIO7_FLAGS_DATA_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 			/* Real finish is ctio_m1's finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 			pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 			pkt->u.status0.flags |= cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 			    CTIO7_FLAGS_DONT_RET_CTIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 			/* qlt_24xx_init_ctio_to_isp will correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 			 * all neccessary fields that's part of CTIO7.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 			 * There should be no residual of CTIO-CRC2 data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 			qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 			    &prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 		qlt_24xx_init_ctio_to_isp(pkt, &prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 	cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 	cmd->cmd_sent_to_fw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 	cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 		qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) out_unmap_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 	qlt_unmap_sg(vha, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) EXPORT_SYMBOL(qlt_xmit_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 	struct ctio7_to_24xx *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 	struct scsi_qla_host *vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 	struct qla_tgt *tgt = cmd->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 	struct qla_tgt_prm prm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 	int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 	struct qla_qpair *qpair = cmd->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 	memset(&prm, 0, sizeof(prm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 	prm.cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 	prm.tgt = tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 	prm.sg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 	prm.req_cnt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 	if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 	    (cmd->sess && cmd->sess->deleted)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) 		 * Either the port is not online or this request was from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) 		 * previous life, just abort the processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) 		cmd->aborted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 		cmd->write_data_transferred = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 		cmd->state = QLA_TGT_STATE_DATA_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 		vha->hw->tgt.tgt_ops->handle_data(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 		ql_dbg_qp(ql_dbg_async, qpair, 0xe102,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) 			"RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 			vha->flags.online, qla2x00_reset_active(vha),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 			cmd->reset_count, qpair->chip_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 	/* Calculate number of entries and segments required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 	if (qlt_pci_map_calc_cnt(&prm) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 	spin_lock_irqsave(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 	/* Does F/W have an IOCBs for this request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 	res = qlt_check_reserve_free_req(qpair, prm.req_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 	if (res != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 		goto out_unlock_free_unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 	if (cmd->se_cmd.prot_op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 		res = qlt_build_ctio_crc2_pkt(qpair, &prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 		res = qlt_24xx_build_ctio_pkt(qpair, &prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 	if (unlikely(res != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 		qpair->req->cnt += prm.req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 		goto out_unlock_free_unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 	pkt = (struct ctio7_to_24xx *)prm.pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 	pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 	    CTIO7_FLAGS_STATUS_MODE_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 	if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 		qlt_load_data_segments(&prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 	cmd->state = QLA_TGT_STATE_NEED_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 	cmd->cmd_sent_to_fw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 	cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 		qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) out_unlock_free_unmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 	qlt_unmap_sg(vha, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) EXPORT_SYMBOL(qlt_rdy_to_xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450)  * it is assumed either hardware_lock or qpair lock is held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) qlt_handle_dif_error(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) 	struct ctio_crc_from_fw *sts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 	uint8_t		*ap = &sts->actual_dif[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 	uint8_t		*ep = &sts->expected_dif[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 	uint64_t	lba = cmd->se_cmd.t_task_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 	uint8_t scsi_status, sense_key, asc, ascq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 	struct scsi_qla_host *vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 	cmd->trc_flags |= TRC_DIF_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 	cmd->a_guard   = get_unaligned_be16(ap + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 	cmd->a_app_tag = get_unaligned_be16(ap + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 	cmd->a_ref_tag = get_unaligned_be32(ap + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 	cmd->e_guard   = get_unaligned_be16(ep + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 	cmd->e_app_tag = get_unaligned_be16(ep + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 	cmd->e_ref_tag = get_unaligned_be32(ep + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 	ql_dbg(ql_dbg_tgt_dif, vha, 0xf075,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 	    "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 	scsi_status = sense_key = asc = ascq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 	/* check appl tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 	if (cmd->e_app_tag != cmd->a_app_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 		ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 		    "App Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard [%x|%x] cmd=%p ox_id[%04x]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 		    cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 		    cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) 		    cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 		    cmd->atio.u.isp24.fcp_hdr.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) 		cmd->dif_err_code = DIF_ERR_APP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 		scsi_status = SAM_STAT_CHECK_CONDITION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 		sense_key = ABORTED_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) 		asc = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 		ascq = 0x2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 	/* check ref tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 	if (cmd->e_ref_tag != cmd->a_ref_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 		ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 		    "Ref Tag ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard[%x|%x] cmd=%p ox_id[%04x] ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 		    cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 		    cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 		    cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) 		    cmd->atio.u.isp24.fcp_hdr.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 		cmd->dif_err_code = DIF_ERR_REF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 		scsi_status = SAM_STAT_CHECK_CONDITION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 		sense_key = ABORTED_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 		asc = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 		ascq = 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 	/* check guard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 	if (cmd->e_guard != cmd->a_guard) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 		ql_dbg(ql_dbg_tgt_dif, vha, 0xe012,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 		    "Guard ERR: cdb[%x] lba[%llx %llx] blks[%x] [Actual|Expected] Ref[%x|%x], App[%x|%x], Guard [%x|%x] cmd=%p ox_id[%04x]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 		    cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 		    cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 		    cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 		    cmd->atio.u.isp24.fcp_hdr.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) 		cmd->dif_err_code = DIF_ERR_GRD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 		scsi_status = SAM_STAT_CHECK_CONDITION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) 		sense_key = ABORTED_COMMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 		asc = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 		ascq = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) 	switch (cmd->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 	case QLA_TGT_STATE_NEED_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) 		/* handle_data will load DIF error code  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) 		cmd->state = QLA_TGT_STATE_DATA_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 		vha->hw->tgt.tgt_ops->handle_data(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 		spin_lock_irqsave(&cmd->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 		if (cmd->aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 			spin_unlock_irqrestore(&cmd->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 			vha->hw->tgt.tgt_ops->free_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 		spin_unlock_irqrestore(&cmd->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 		qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 		    ascq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 		/* assume scsi status gets out on the wire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 		 * Will not wait for completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 		vha->hw->tgt.tgt_ops->free_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) /* If hardware_lock held on entry, might drop it, then reaquire */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 	struct imm_ntfy_from_isp *ntfy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 	struct nack_to_isp *nack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 	request_t *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 	ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 	    "Sending TERM ELS CTIO (ha=%p)\n", ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 	pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 	if (pkt == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 		ql_dbg(ql_dbg_tgt, vha, 0xe080,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 		    "qla_target(%d): %s failed: unable to allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 		    "request packet\n", vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 	pkt->entry_type = NOTIFY_ACK_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) 	pkt->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 	pkt->handle = QLA_TGT_SKIP_HANDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 	nack = (struct nack_to_isp *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 	nack->ox_id = ntfy->ox_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 	nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 	if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 		nack->u.isp24.flags = ntfy->u.isp24.flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 			cpu_to_le16(NOTIFY24XX_FLAGS_PUREX_IOCB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 	/* terminate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 	nack->u.isp24.flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 		__constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 	nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 	nack->u.isp24.status = ntfy->u.isp24.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 	nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 	nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 	nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 	nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 	nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 	nack->u.isp24.vp_index = ntfy->u.isp24.vp_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 	qla2x00_start_iocbs(vha, vha->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 	struct imm_ntfy_from_isp *imm, int ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 	WARN_ON_ONCE(!ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 	rc = __qlt_send_term_imm_notif(vha, imm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 	pr_debug("rc = %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614)  * If hardware_lock held on entry, might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615)  * This function sends the appropriate CTIO to ISP 2xxx or 24xx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) static int __qlt_send_term_exchange(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 	struct qla_tgt_cmd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 	struct atio_from_isp *atio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 	struct scsi_qla_host *vha = qpair->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 	struct ctio7_to_24xx *ctio24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 	request_t *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 	uint16_t temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 	ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) 	if (cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 		vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 	pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 	if (pkt == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 		ql_dbg(ql_dbg_tgt, vha, 0xe050,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 		    "qla_target(%d): %s failed: unable to allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 		    "request packet\n", vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 	if (cmd != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 		if (cmd->state < QLA_TGT_STATE_PROCESSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 			ql_dbg(ql_dbg_tgt, vha, 0xe051,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 			    "qla_target(%d): Terminating cmd %p with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 			    "incorrect state %d\n", vha->vp_idx, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 			    cmd->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 			ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) 	qpair->tgt_counters.num_term_xchg_sent++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 	pkt->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 	pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) 	ctio24 = (struct ctio7_to_24xx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 	ctio24->entry_type = CTIO_TYPE7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) 	ctio24->nport_handle = cpu_to_le16(CTIO7_NHANDLE_UNRECOGNIZED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) 	ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 	ctio24->vp_index = vha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 	ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 	ctio24->exchange_addr = atio->u.isp24.exchange_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) 	temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) 		CTIO7_FLAGS_TERMINATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) 	ctio24->u.status1.flags = cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) 	temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 	ctio24->u.status1.ox_id = cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 		qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) static void qlt_send_term_exchange(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 	struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 	int ul_abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 	struct scsi_qla_host *vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 	/* why use different vha? NPIV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 	if (cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 		vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 		vha = qpair->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 	if (ha_locked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 		rc = __qlt_send_term_exchange(qpair, cmd, atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 		if (rc == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 			qlt_alloc_qfull_cmd(vha, atio, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 	spin_lock_irqsave(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 	rc = __qlt_send_term_exchange(qpair, cmd, atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 	if (rc == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 		qlt_alloc_qfull_cmd(vha, atio, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 	if (cmd && !ul_abort && !cmd->aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 		if (cmd->sg_mapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 			qlt_unmap_sg(vha, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 		vha->hw->tgt.tgt_ops->free_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 	if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 		spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) static void qlt_init_term_exchange(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 	struct list_head free_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 	struct qla_tgt_cmd *cmd, *tcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 	vha->hw->tgt.leak_exchg_thresh_hold =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 	    (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 	cmd = tcmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 	if (!list_empty(&vha->hw->tgt.q_full_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 		INIT_LIST_HEAD(&free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 		list_splice_init(&vha->hw->tgt.q_full_list, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 		list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 			list_del(&cmd->cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 			/* This cmd was never sent to TCM.  There is no need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 			 * to schedule free or call free_cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 			qlt_free_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 			vha->hw->tgt.num_qfull_cmds_alloc--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 	vha->hw->tgt.num_qfull_cmds_dropped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 	uint32_t total_leaked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 	total_leaked = vha->hw->tgt.num_qfull_cmds_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 	if (vha->hw->tgt.leak_exchg_thresh_hold &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) 	    (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) 		ql_dbg(ql_dbg_tgt, vha, 0xe079,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 		    "Chip reset due to exchange starvation: %d/%d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 		    total_leaked, vha->hw->cur_fw_xcb_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 		if (IS_P3P_TYPE(vha->hw))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 			set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 			set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 		qla2xxx_wake_dpc(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) int qlt_abort_cmd(struct qla_tgt_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 	struct qla_tgt *tgt = cmd->tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 	struct scsi_qla_host *vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 	struct se_cmd *se_cmd = &cmd->se_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 	    "qla_target(%d): terminating exchange for aborted cmd=%p "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 	    "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 	    se_cmd->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) 	spin_lock_irqsave(&cmd->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 	if (cmd->aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) 		spin_unlock_irqrestore(&cmd->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) 		 * It's normal to see 2 calls in this path:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 		 *  1) XFER Rdy completion + CMD_T_ABORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 		 *  2) TCM TMR - drain_state_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 		    "multiple abort. %p transport_state %x, t_state %x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 		    "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 		    cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 	cmd->aborted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 	cmd->trc_flags |= TRC_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 	spin_unlock_irqrestore(&cmd->cmd_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 	qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) EXPORT_SYMBOL(qlt_abort_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) void qlt_free_cmd(struct qla_tgt_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 	struct fc_port *sess = cmd->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 	ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 	    "%s: se_cmd[%p] ox_id %04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 	    __func__, &cmd->se_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 	    be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 	BUG_ON(cmd->cmd_in_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 	if (!cmd->q_full)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 		qlt_decr_num_pend_cmds(cmd->vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 	BUG_ON(cmd->sg_mapped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) 	cmd->jiffies_at_free = get_jiffies_64();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 	if (unlikely(cmd->free_sg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 		kfree(cmd->sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 	if (!sess || !sess->se_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 	cmd->jiffies_at_free = get_jiffies_64();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 	cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) EXPORT_SYMBOL(qlt_free_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 	struct qla_tgt_cmd *cmd, uint32_t status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 	int term = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 	struct scsi_qla_host *vha = qpair->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 	if (cmd->se_cmd.prot_op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 		ql_dbg(ql_dbg_tgt_dif, vha, 0xe013,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 		    "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 		    "se_cmd=%p tag[%x] op %#x/%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 		     cmd->lba, cmd->lba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 		     cmd->num_blks, &cmd->se_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 		     cmd->atio.u.isp24.exchange_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 		     cmd->se_cmd.prot_op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 		     prot_op_str(cmd->se_cmd.prot_op));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 	if (ctio != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 		struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 		term = !(c->flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) 		    cpu_to_le16(OF_TERM_EXCH));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 		term = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 	if (term)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 		qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 	return term;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 	struct rsp_que *rsp, uint32_t handle, void *ctio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 	void *cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 	struct req_que *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 	int qid = GET_QID(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 	uint32_t h = handle & ~QLA_TGT_HANDLE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 	if (unlikely(h == QLA_TGT_SKIP_HANDLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 	if (qid == rsp->req->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 		req = rsp->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 	} else if (vha->hw->req_q_map[qid]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) 		    "qla_target(%d): CTIO completion with different QID %d handle %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 		    vha->vp_idx, rsp->id, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 		req = vha->hw->req_q_map[qid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 	h &= QLA_CMD_HANDLE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 	if (h != QLA_TGT_NULL_HANDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 		if (unlikely(h >= req->num_outstanding_cmds)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 			ql_dbg(ql_dbg_tgt, vha, 0xe052,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 			    "qla_target(%d): Wrong handle %x received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 			    vha->vp_idx, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 		cmd = req->outstanding_cmds[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 		if (unlikely(cmd == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 			ql_dbg(ql_dbg_async, vha, 0xe053,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 			    "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 				vha->vp_idx, handle, req->id, rsp->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 		req->outstanding_cmds[h] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 	} else if (ctio != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) 		/* We can't get loop ID from CTIO7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 		ql_dbg(ql_dbg_tgt, vha, 0xe054,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) 		    "qla_target(%d): Wrong CTIO received: QLA24xx doesn't "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 		    "support NULL handles\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 	return cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) static void qlt_do_ctio_completion(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915)     struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 	struct se_cmd *se_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 	struct qla_tgt_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 	struct qla_qpair *qpair = rsp->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 	if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 		/* That could happen only in case of an error/reset/abort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 		if (status != CTIO_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) 			    "Intermediate CTIO received"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 			    " (status %x)\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 	cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 	if (cmd == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 	se_cmd = &cmd->se_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 	cmd->cmd_sent_to_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 	qlt_unmap_sg(vha, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 	if (unlikely(status != CTIO_SUCCESS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 		switch (status & 0xFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 		case CTIO_INVALID_RX_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) 			if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 				dev_info(&vha->hw->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) 				    "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 				    vha->vp_idx, cmd->atio.u.isp24.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 				    ((cmd->ctio_flags >> 9) & 0xf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 				    cmd->ctio_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 		case CTIO_LIP_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) 		case CTIO_TARGET_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 		case CTIO_ABORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 			/* driver request abort via Terminate exchange */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 		case CTIO_TIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 			/* They are OK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 			    "qla_target(%d): CTIO with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 			    "status %#x received, state %x, se_cmd %p, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 			    "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 			    "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 			    status, cmd->state, se_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 		case CTIO_PORT_LOGGED_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) 		case CTIO_PORT_UNAVAILABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 			int logged_out =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 				(status & 0xFFFF) == CTIO_PORT_LOGGED_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 			    "qla_target(%d): CTIO with %s status %x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) 			    "received (state %x, se_cmd %p)\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 			    logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) 			    status, cmd->state, se_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 			if (logged_out && cmd->sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 				 * Session is already logged out, but we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 				 * to notify initiator, who's not aware of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 				cmd->sess->send_els_logo = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) 				ql_dbg(ql_dbg_disc, vha, 0x20f8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 				    "%s %d %8phC post del sess\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) 				    __func__, __LINE__, cmd->sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) 				qlt_schedule_sess_for_deletion(cmd->sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) 		case CTIO_DIF_ERROR: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) 			struct ctio_crc_from_fw *crc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 				(struct ctio_crc_from_fw *)ctio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 			    "qla_target(%d): CTIO with DIF_ERROR status %x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) 			    "received (state %x, ulp_cmd %p) actual_dif[0x%llx] "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 			    "expect_dif[0x%llx]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 			    vha->vp_idx, status, cmd->state, se_cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 			    *((u64 *)&crc->actual_dif[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 			    *((u64 *)&crc->expected_dif[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) 			qlt_handle_dif_error(qpair, cmd, ctio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 			    "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 			    vha->vp_idx, status, cmd->state, se_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) 		/* "cmd->aborted" means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) 		 * cmd is already aborted/terminated, we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) 		 * need to terminate again.  The exchange is already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 		 * cleaned up/freed at FW level.  Just cleanup at driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) 		 * level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 		if ((cmd->state != QLA_TGT_STATE_NEED_DATA) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 		    (!cmd->aborted)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 			cmd->trc_flags |= TRC_CTIO_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) 			if (qlt_term_ctio_exchange(qpair, ctio, cmd, status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) 	if (cmd->state == QLA_TGT_STATE_PROCESSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) 		cmd->trc_flags |= TRC_CTIO_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) 	} else if (cmd->state == QLA_TGT_STATE_NEED_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 		cmd->state = QLA_TGT_STATE_DATA_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) 		if (status == CTIO_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) 			cmd->write_data_transferred = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) 		ha->tgt.tgt_ops->handle_data(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) 	} else if (cmd->aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) 		cmd->trc_flags |= TRC_CTIO_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) 		  "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) 		cmd->trc_flags |= TRC_CTIO_STRANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) 		    "qla_target(%d): A command in state (%d) should "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) 		    "not return a CTIO complete\n", vha->vp_idx, cmd->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 	if (unlikely(status != CTIO_SUCCESS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 		!cmd->aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 	ha->tgt.tgt_ops->free_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 	uint8_t task_codes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) 	int fcp_task_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) 	switch (task_codes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 	case ATIO_SIMPLE_QUEUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) 		fcp_task_attr = TCM_SIMPLE_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 	case ATIO_HEAD_OF_QUEUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 		fcp_task_attr = TCM_HEAD_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 	case ATIO_ORDERED_QUEUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 		fcp_task_attr = TCM_ORDERED_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) 	case ATIO_ACA_QUEUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) 		fcp_task_attr = TCM_ACA_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 	case ATIO_UNTAGGED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) 		fcp_task_attr = TCM_SIMPLE_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 		    "qla_target: unknown task code %x, use ORDERED instead\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) 		    task_codes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) 		fcp_task_attr = TCM_ORDERED_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) 	return fcp_task_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091)  * Process context for I/O path into tcm_qla2xxx code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) static void __qlt_do_work(struct qla_tgt_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) 	scsi_qla_host_t *vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) 	struct fc_port *sess = cmd->sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) 	struct atio_from_isp *atio = &cmd->atio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 	unsigned char *cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) 	uint32_t data_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) 	int ret, fcp_task_attr, data_dir, bidi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 	struct qla_qpair *qpair = cmd->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 	cmd->cmd_in_wq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 	cmd->trc_flags |= TRC_DO_WORK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 	if (cmd->aborted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 		    "cmd with tag %u is aborted\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) 		    cmd->atio.u.isp24.exchange_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) 		goto out_term;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 	spin_lock_init(&cmd->cmd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 	cdb = &atio->u.isp24.fcp_cmnd.cdb[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) 	cmd->se_cmd.tag = le32_to_cpu(atio->u.isp24.exchange_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) 	if (atio->u.isp24.fcp_cmnd.rddata &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) 	    atio->u.isp24.fcp_cmnd.wrdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) 		bidi = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) 		data_dir = DMA_TO_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 	} else if (atio->u.isp24.fcp_cmnd.rddata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 		data_dir = DMA_FROM_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 	else if (atio->u.isp24.fcp_cmnd.wrdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 		data_dir = DMA_TO_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) 		data_dir = DMA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) 	fcp_task_attr = qlt_get_fcp_task_attr(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 	    atio->u.isp24.fcp_cmnd.task_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) 	data_length = get_datalen_for_atio(atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 	ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 				          fcp_task_attr, data_dir, bidi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 		goto out_term;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 	 * Drop extra session reference from qlt_handle_cmd_for_atio().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 	ha->tgt.tgt_ops->put_sess(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) out_term:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 	ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 	 * cmd has not sent to target yet, so pass NULL as the second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) 	 * argument to qlt_send_term_exchange() and free the memory here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 	cmd->trc_flags |= TRC_DO_WORK_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) 	spin_lock_irqsave(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) 	qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 	qlt_decr_num_pend_cmds(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) 	cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) 	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 	ha->tgt.tgt_ops->put_sess(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) static void qlt_do_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 	struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 	scsi_qla_host_t *vha = cmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) 	spin_lock_irqsave(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 	list_del(&cmd->cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 	spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) 	__qlt_do_work(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) void qlt_clr_qp_table(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 	void *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 	u64 key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) 	ql_log(ql_log_info, vha, 0x706c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 	    "User update Number of Active Qpairs %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 	    ha->tgt.num_act_qpairs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 	spin_lock_irqsave(&ha->tgt.atio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) 	btree_for_each_safe64(&tgt->lun_qpair_map, key, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 		btree_remove64(&tgt->lun_qpair_map, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 	ha->base_qpair->lun_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 	for (key = 0; key < ha->max_qpairs; key++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 		if (ha->queue_pair_map[key])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 			ha->queue_pair_map[key]->lun_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 	spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) static void qlt_assign_qpair(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 	struct qla_tgt_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 	struct qla_qpair *qpair, *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) 	struct qla_qpair_hint *h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) 	if (vha->flags.qpairs_available) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 		h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 		if (unlikely(!h)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 			/* spread lun to qpair ratio evently */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) 			int lcnt = 0, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 			struct scsi_qla_host *base_vha =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 				pci_get_drvdata(vha->hw->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 			qpair = vha->hw->base_qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) 			if (qpair->lun_cnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 				qpair->lun_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) 				h = qla_qpair_to_hint(tgt, qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 				BUG_ON(!h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 				rc = btree_insert64(&tgt->lun_qpair_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 					cmd->unpacked_lun, h, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) 				if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 					qpair->lun_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) 					ql_log(ql_log_info, vha, 0xd037,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) 					    "Unable to insert lun %llx into lun_qpair_map\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) 					    cmd->unpacked_lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) 				lcnt = qpair->lun_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 			h = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 			list_for_each_entry(qp, &base_vha->qp_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 			    qp_list_elem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 				if (qp->lun_cnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 					qp->lun_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 					h = qla_qpair_to_hint(tgt, qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 					BUG_ON(!h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) 					rc = btree_insert64(&tgt->lun_qpair_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) 					    cmd->unpacked_lun, h, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 					if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) 						qp->lun_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) 						ql_log(ql_log_info, vha, 0xd038,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 							"Unable to insert lun %llx into lun_qpair_map\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 							cmd->unpacked_lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 					qpair = qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 					goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) 					if (qp->lun_cnt < lcnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 						lcnt = qp->lun_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 						qpair = qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 						continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 			BUG_ON(!qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) 			qpair->lun_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 			h = qla_qpair_to_hint(tgt, qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) 			BUG_ON(!h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 			rc = btree_insert64(&tgt->lun_qpair_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) 				cmd->unpacked_lun, h, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) 				qpair->lun_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) 				ql_log(ql_log_info, vha, 0xd039,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 				   "Unable to insert lun %llx into lun_qpair_map\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 				   cmd->unpacked_lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) 		h = &tgt->qphints[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 	cmd->qpair = h->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) 	cmd->se_cmd.cpuid = h->cpuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 				       struct fc_port *sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) 				       struct atio_from_isp *atio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 	struct qla_tgt_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 	cmd = vha->hw->tgt.tgt_ops->get_cmd(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 	if (!cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 	cmd->cmd_type = TYPE_TGT_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 	memcpy(&cmd->atio, atio, sizeof(*atio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 	cmd->state = QLA_TGT_STATE_NEW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 	cmd->tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 	qlt_incr_num_pend_cmds(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 	cmd->vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 	cmd->sess = sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 	cmd->loop_id = sess->loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 	cmd->conf_compl_supported = sess->conf_compl_supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 	cmd->trc_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 	cmd->jiffies_at_alloc = get_jiffies_64();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 	cmd->unpacked_lun = scsilun_to_int(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 	    (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 	qlt_assign_qpair(vha, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 	cmd->reset_count = vha->hw->base_qpair->chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 	cmd->vp_idx = vha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 	return cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) 	struct atio_from_isp *atio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) 	struct fc_port *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) 	struct qla_tgt_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 	port_id_t id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 	if (unlikely(tgt->tgt_stop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) 		ql_dbg(ql_dbg_io, vha, 0x3061,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) 		    "New command while device %p is shutting down\n", tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 	id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 	if (IS_SW_RESV_ADDR(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) 	sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 	if (unlikely(!sess))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 	/* Another WWN used to have our s_id. Our PLOGI scheduled its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 	 * session deletion, but it's still in sess_del_work wq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 	if (sess->deleted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 		    "New command while old session %p is being deleted\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 		    sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 	 * Do kref_get() before returning + dropping qla_hw_data->hardware_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) 	if (!kref_get_unless_zero(&sess->sess_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) 		    "%s: kref_get fail, %8phC oxid %x \n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) 		    __func__, sess->port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) 		     be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) 	cmd = qlt_get_tag(vha, sess, atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 	if (!cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) 		ql_dbg(ql_dbg_io, vha, 0x3062,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 		    "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 		ha->tgt.tgt_ops->put_sess(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 	cmd->cmd_in_wq = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) 	cmd->trc_flags |= TRC_NEW_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) 	spin_lock_irqsave(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 	list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) 	spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 	INIT_WORK(&cmd->work, qlt_do_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) 	if (vha->flags.qpairs_available) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 		queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 	} else if (ha->msix_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 		if (cmd->atio.u.isp24.fcp_cmnd.rddata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 			queue_work_on(smp_processor_id(), qla_tgt_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 			    &cmd->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 			queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 			    &cmd->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 		queue_work(qla_tgt_wq, &cmd->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 	int fn, void *iocb, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) 	struct scsi_qla_host *vha = sess->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 	struct qla_tgt_mgmt_cmd *mcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 	struct atio_from_isp *a = (struct atio_from_isp *)iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 	struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) 	mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) 	if (!mcmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) 		ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 		    "qla_target(%d): Allocation of management "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) 		    "command failed, some commands and their data could "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 		    "leak\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) 	memset(mcmd, 0, sizeof(*mcmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) 	mcmd->sess = sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) 	if (iocb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) 		memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 		    sizeof(mcmd->orig_iocb.imm_ntfy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 	mcmd->tmr_func = fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) 	mcmd->flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 	mcmd->reset_count = ha->base_qpair->chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 	mcmd->qpair = h->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) 	mcmd->vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 	mcmd->se_cmd.cpuid = h->cpuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 	mcmd->unpacked_lun = lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 	switch (fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) 	case QLA_TGT_LUN_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) 	case QLA_TGT_CLEAR_TS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 	case QLA_TGT_ABORT_TS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) 		abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 	case QLA_TGT_CLEAR_ACA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) 		h = qlt_find_qphint(vha, mcmd->unpacked_lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) 		mcmd->qpair = h->qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 		mcmd->se_cmd.cpuid = h->cpuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 	case QLA_TGT_TARGET_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 	case QLA_TGT_NEXUS_LOSS_SESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 	case QLA_TGT_NEXUS_LOSS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 	case QLA_TGT_ABORT_ALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) 		/* no-op */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 	INIT_WORK(&mcmd->work, qlt_do_tmr_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 	queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) 	    &mcmd->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) 	struct atio_from_isp *a = (struct atio_from_isp *)iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) 	struct fc_port *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) 	u64 unpacked_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) 	int fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 	fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) 	sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) 	    a->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 	unpacked_lun =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 	    scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 	if (sess == NULL || sess->deleted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 	return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) static int __qlt_abort_task(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) 	struct imm_ntfy_from_isp *iocb, struct fc_port *sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) 	struct atio_from_isp *a = (struct atio_from_isp *)iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) 	struct qla_tgt_mgmt_cmd *mcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 	u64 unpacked_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) 	mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) 	if (mcmd == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) 		    "qla_target(%d): %s: Allocation of ABORT cmd failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) 		    vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) 	memset(mcmd, 0, sizeof(*mcmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) 	mcmd->sess = sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 	memcpy(&mcmd->orig_iocb.imm_ntfy, iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) 	    sizeof(mcmd->orig_iocb.imm_ntfy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) 	unpacked_lun =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) 	    scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) 	mcmd->reset_count = ha->base_qpair->chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) 	mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) 	mcmd->qpair = ha->base_qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 	rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, mcmd->tmr_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 	    le16_to_cpu(iocb->u.isp2x.seq_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 	if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 		    "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 		    vha->vp_idx, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 		mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) static int qlt_abort_task(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 	struct imm_ntfy_from_isp *iocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) 	struct fc_port *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) 	int loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) 	loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) 	sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) 	if (sess == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) 		    "qla_target(%d): task abort for unexisting "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) 		    "session\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) 		return qlt_sched_sess_work(vha->vha_tgt.qla_tgt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) 		    QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) 	return __qlt_abort_task(vha, iocb, sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) void qlt_logo_completion_handler(fc_port_t *fcport, int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) 	if (rc != MBS_COMMAND_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) 		ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) 			"%s: se_sess %p / sess %p from"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) 			" port %8phC loop_id %#04x s_id %02x:%02x:%02x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) 			" LOGO failed: %#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) 			__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) 			fcport->se_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) 			fcport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) 			fcport->port_name, fcport->loop_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) 			fcport->d_id.b.domain, fcport->d_id.b.area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) 			fcport->d_id.b.al_pa, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) 	fcport->logout_completed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) * Schedules sessions with matching port_id/loop_id but different wwn for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) * deletion. Returns existing session with matching wwn if present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) * Null otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) struct fc_port *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) qlt_find_sess_invalidate_other(scsi_qla_host_t *vha, uint64_t wwn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569)     port_id_t port_id, uint16_t loop_id, struct fc_port **conflict_sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) 	struct fc_port *sess = NULL, *other_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) 	uint64_t other_wwn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) 	*conflict_sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) 	list_for_each_entry(other_sess, &vha->vp_fcports, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) 		other_wwn = wwn_to_u64(other_sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) 		if (wwn == other_wwn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) 			WARN_ON(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) 			sess = other_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) 		/* find other sess with nport_id collision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) 		if (port_id.b24 == other_sess->d_id.b24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) 			if (loop_id != other_sess->loop_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) 				ql_dbg(ql_dbg_disc, vha, 0x1000c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) 				    "Invalidating sess %p loop_id %d wwn %llx.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) 				    other_sess, other_sess->loop_id, other_wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) 				 * logout_on_delete is set by default, but another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) 				 * session that has the same s_id/loop_id combo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) 				 * might have cleared it when requested this session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) 				 * deletion, so don't touch it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) 				qlt_schedule_sess_for_deletion(other_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) 				 * Another wwn used to have our s_id/loop_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) 				 * kill the session, but don't free the loop_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) 				ql_dbg(ql_dbg_disc, vha, 0xf01b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) 				    "Invalidating sess %p loop_id %d wwn %llx.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) 				    other_sess, other_sess->loop_id, other_wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) 				other_sess->keep_nport_handle = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) 				if (other_sess->disc_state != DSC_DELETED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) 					*conflict_sess = other_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) 				qlt_schedule_sess_for_deletion(other_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) 		/* find other sess with nport handle collision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) 		if ((loop_id == other_sess->loop_id) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) 			(loop_id != FC_NO_LOOP_ID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) 			ql_dbg(ql_dbg_disc, vha, 0x1000d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) 			       "Invalidating sess %p loop_id %d wwn %llx.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) 			       other_sess, other_sess->loop_id, other_wwn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) 			/* Same loop_id but different s_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) 			 * Ok to kill and logout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) 			qlt_schedule_sess_for_deletion(other_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) 	return sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) 	struct qla_tgt_sess_op *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) 	struct qla_tgt_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) 	uint32_t key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) 	key = (((u32)s_id->b.domain << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) 	       ((u32)s_id->b.area   <<  8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) 	       ((u32)s_id->b.al_pa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) 	spin_lock_irqsave(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) 	list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) 		uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) 		if (op_key == key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) 			op->aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) 	list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) 		uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) 		if (op_key == key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) 			op->aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) 	list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) 		uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) 		if (cmd_key == key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) 			cmd->aborted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) 	spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) static int qlt_handle_login(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679)     struct imm_ntfy_from_isp *iocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) 	struct fc_port *sess = NULL, *conflict_sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) 	uint64_t wwn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) 	port_id_t port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) 	uint16_t loop_id, wd3_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) 	int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) 	struct qlt_plogi_ack_t *pla;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) 	lockdep_assert_held(&vha->hw->hardware_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) 	wwn = wwn_to_u64(iocb->u.isp24.port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) 	port_id.b.domain = iocb->u.isp24.port_id[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) 	port_id.b.area   = iocb->u.isp24.port_id[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) 	port_id.b.al_pa  = iocb->u.isp24.port_id[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) 	port_id.b.rsvd_1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) 	loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) 	/* Mark all stale commands sitting in qla_tgt_wq for deletion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) 	abort_cmds_for_s_id(vha, &port_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) 	if (wwn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) 		spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) 		sess = qlt_find_sess_invalidate_other(vha, wwn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) 		    port_id, loop_id, &conflict_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) 		spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) 		ql_dbg(ql_dbg_disc, vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) 		    "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) 		    __func__, __LINE__, loop_id, port_id.b24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) 		qlt_send_term_imm_notif(vha, iocb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) 	if (IS_SW_RESV_ADDR(port_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) 		res = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) 	pla = qlt_plogi_ack_find_add(vha, &port_id, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) 	if (!pla) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) 		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) 		    "%s %d %8phC Term INOT due to mem alloc fail",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) 		    __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) 		    iocb->u.isp24.port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) 		qlt_send_term_imm_notif(vha, iocb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) 	if (conflict_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) 		conflict_sess->login_gen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) 		qlt_plogi_ack_link(vha, pla, conflict_sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) 		    QLT_PLOGI_LINK_CONFLICT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) 	if (!sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) 		pla->ref_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) 		ql_dbg(ql_dbg_disc, vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) 		    "%s %d %8phC post new sess\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) 		    __func__, __LINE__, iocb->u.isp24.port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) 		if (iocb->u.isp24.status_subcode == ELS_PLOGI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) 			qla24xx_post_newsess_work(vha, &port_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) 			    iocb->u.isp24.port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) 			    iocb->u.isp24.u.plogi.node_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) 			    pla, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) 			qla24xx_post_newsess_work(vha, &port_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) 			    iocb->u.isp24.port_name, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) 			    pla, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) 	if (sess->disc_state == DSC_UPD_FCPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) 		u16 sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) 		 * Remote port registration is still going on from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) 		 * previous login. Allow it to finish before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) 		 * accept the new login.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) 		sess->next_disc_state = DSC_DELETE_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) 		sec = jiffies_to_msecs(jiffies -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) 		    sess->jiffies_at_registration) / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) 		if (sess->sec_since_registration < sec && sec &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) 		    !(sec % 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) 			sess->sec_since_registration = sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) 			ql_dbg(ql_dbg_disc, vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) 			    "%s %8phC - Slow Rport registration (%d Sec)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) 			    __func__, sess->port_name, sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) 		if (!conflict_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) 			list_del(&pla->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) 			kmem_cache_free(qla_tgt_plogi_cachep, pla);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) 		qlt_send_term_imm_notif(vha, iocb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) 	qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) 	sess->d_id = port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) 	sess->login_gen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) 	if (iocb->u.isp24.status_subcode == ELS_PRLI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) 		sess->fw_login_state = DSC_LS_PRLI_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) 		sess->local = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) 		sess->loop_id = loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) 		sess->d_id = port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) 		sess->fw_login_state = DSC_LS_PRLI_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) 		wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) 		if (wd3_lo & BIT_7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) 			sess->conf_compl_supported = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) 		if ((wd3_lo & BIT_4) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) 			sess->port_type = FCT_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) 			sess->port_type = FCT_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) 		sess->fw_login_state = DSC_LS_PLOGI_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) 	ql_dbg(ql_dbg_disc, vha, 0x20f9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) 	    "%s %d %8phC  DS %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) 	    __func__, __LINE__, sess->port_name, sess->disc_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) 	switch (sess->disc_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) 	case DSC_DELETED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) 	case DSC_LOGIN_PEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) 		qlt_plogi_ack_unref(vha, pla);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) 		 * Under normal circumstances we want to release nport handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) 		 * during LOGO process to avoid nport handle leaks inside FW.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) 		 * The exception is when LOGO is done while another PLOGI with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) 		 * the same nport handle is waiting as might be the case here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) 		 * Note: there is always a possibily of a race where session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) 		 * deletion has already started for other reasons (e.g. ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) 		 * removal) and now PLOGI arrives:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) 		 * 1. if PLOGI arrived in FW after nport handle has been freed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) 		 *    FW must have assigned this PLOGI a new/same handle and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) 		 *    can proceed ACK'ing it as usual when session deletion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) 		 *    completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) 		 * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) 		 *    bit reached it, the handle has now been released. We'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) 		 *    get an error when we ACK this PLOGI. Nothing will be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) 		 *    back to initiator. Initiator should eventually retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) 		 *    PLOGI and situation will correct itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) 		sess->keep_nport_handle = ((sess->loop_id == loop_id) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) 		    (sess->d_id.b24 == port_id.b24));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) 		ql_dbg(ql_dbg_disc, vha, 0x20f9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) 		    "%s %d %8phC post del sess\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) 		    __func__, __LINE__, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) 		qlt_schedule_sess_for_deletion(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) static int qlt_24xx_handle_els(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) 	struct imm_ntfy_from_isp *iocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) 	struct fc_port *sess = NULL, *conflict_sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) 	uint64_t wwn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) 	port_id_t port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) 	uint16_t loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) 	uint16_t wd3_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) 	int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) 	lockdep_assert_held(&ha->hardware_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) 	wwn = wwn_to_u64(iocb->u.isp24.port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) 	port_id.b.domain = iocb->u.isp24.port_id[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) 	port_id.b.area   = iocb->u.isp24.port_id[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) 	port_id.b.al_pa  = iocb->u.isp24.port_id[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) 	port_id.b.rsvd_1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) 	loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) 	ql_dbg(ql_dbg_disc, vha, 0xf026,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) 	    "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) 	    vha->vp_idx, iocb->u.isp24.port_id[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) 		iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) 		   iocb->u.isp24.status_subcode, loop_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) 		iocb->u.isp24.port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) 	/* res = 1 means ack at the end of thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) 	 * res = 0 means ack async/later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) 	switch (iocb->u.isp24.status_subcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) 	case ELS_PLOGI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) 		res = qlt_handle_login(vha, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) 	case ELS_PRLI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) 		if (N2N_TOPO(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) 			sess = qla2x00_find_fcport_by_wwpn(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) 			    iocb->u.isp24.port_name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) 			if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) 				ql_dbg(ql_dbg_disc, vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) 				    "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) 				    __func__, __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) 				    iocb->u.isp24.port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) 				qlt_send_term_imm_notif(vha, iocb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) 			res = qlt_handle_login(vha, iocb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) 		if (IS_SW_RESV_ADDR(port_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) 			res = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) 		wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) 		if (wwn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) 			spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) 			sess = qlt_find_sess_invalidate_other(vha, wwn, port_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) 				loop_id, &conflict_sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) 			spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) 		if (conflict_sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) 			switch (conflict_sess->disc_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) 			case DSC_DELETED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) 			case DSC_DELETE_PEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) 				ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) 				    "PRLI with conflicting sess %p port %8phC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) 				    conflict_sess, conflict_sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) 				conflict_sess->fw_login_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) 				    DSC_LS_PORT_UNAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) 				qlt_send_term_imm_notif(vha, iocb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) 				res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) 		if (sess != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) 			bool delete = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) 			int sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) 			spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) 			switch (sess->fw_login_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) 			case DSC_LS_PLOGI_PEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) 			case DSC_LS_PLOGI_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) 			case DSC_LS_PRLI_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) 				delete = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) 			switch (sess->disc_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) 			case DSC_UPD_FCPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) 				spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) 				    flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) 				sec = jiffies_to_msecs(jiffies -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) 				    sess->jiffies_at_registration)/1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) 				if (sess->sec_since_registration < sec && sec &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) 				    !(sec % 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) 					sess->sec_since_registration = sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) 					ql_dbg(ql_dbg_disc, sess->vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) 					    "%s %8phC : Slow Rport registration(%d Sec)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) 					    __func__, sess->port_name, sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) 				qlt_send_term_imm_notif(vha, iocb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) 			case DSC_LOGIN_PEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) 			case DSC_GPDB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) 			case DSC_LOGIN_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) 			case DSC_ADISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) 				delete = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) 			if (delete) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) 				spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) 				    flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) 				 * Impatient initiator sent PRLI before last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) 				 * PLOGI could finish. Will force him to re-try,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) 				 * while last one finishes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) 				ql_log(ql_log_warn, sess->vha, 0xf095,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) 				    "sess %p PRLI received, before plogi ack.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) 				    sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) 				qlt_send_term_imm_notif(vha, iocb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) 				res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) 			 * This shouldn't happen under normal circumstances,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) 			 * since we have deleted the old session during PLOGI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) 			    "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) 			    sess->loop_id, sess, iocb->u.isp24.nport_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) 			sess->local = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) 			sess->loop_id = loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) 			sess->d_id = port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) 			sess->fw_login_state = DSC_LS_PRLI_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) 			if (wd3_lo & BIT_7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) 				sess->conf_compl_supported = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) 			if ((wd3_lo & BIT_4) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) 				sess->port_type = FCT_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) 				sess->port_type = FCT_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) 			spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) 		res = 1; /* send notify ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) 		/* Make session global (not used in fabric mode) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) 		if (ha->current_topology != ISP_CFG_F) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) 			if (sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) 				ql_dbg(ql_dbg_disc, vha, 0x20fa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) 				    "%s %d %8phC post nack\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) 				    __func__, __LINE__, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) 				qla24xx_post_nack_work(vha, sess, iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) 					SRB_NACK_PRLI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) 				res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) 				set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) 				set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) 				qla2xxx_wake_dpc(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) 			if (sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) 				ql_dbg(ql_dbg_disc, vha, 0x20fb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) 				    "%s %d %8phC post nack\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) 				    __func__, __LINE__, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) 				qla24xx_post_nack_work(vha, sess, iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) 					SRB_NACK_PRLI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) 				res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) 	case ELS_TPRLO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) 		if (le16_to_cpu(iocb->u.isp24.flags) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) 			NOTIFY24XX_FLAGS_GLOBAL_TPRLO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) 			loop_id = 0xFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) 			qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) 			res = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) 	case ELS_LOGO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) 	case ELS_PRLO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) 		spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) 		sess = qla2x00_find_fcport_by_loopid(vha, loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) 		if (sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) 			sess->login_gen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) 			sess->fw_login_state = DSC_LS_LOGO_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) 			sess->logo_ack_needed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) 			memcpy(sess->iocb, iocb, IOCB_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) 		res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) 		ql_dbg(ql_dbg_disc, vha, 0x20fc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) 		    "%s: logo %llx res %d sess %p ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) 		    __func__, wwn, res, sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) 		if (res == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) 			 * cmd went upper layer, look for qlt_xmit_tm_rsp()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) 			 * for LOGO_ACK & sess delete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) 			BUG_ON(!sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) 			res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) 			/* cmd did not go to upper layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) 			if (sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) 				qlt_schedule_sess_for_deletion(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) 				res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) 			/* else logo will be ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) 	case ELS_PDISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) 	case ELS_ADISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) 		struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) 		if (tgt->link_reinit_iocb_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) 			qlt_send_notify_ack(ha->base_qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) 			    &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) 			tgt->link_reinit_iocb_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) 		sess = qla2x00_find_fcport_by_wwpn(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) 		    iocb->u.isp24.port_name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) 		if (sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) 			ql_dbg(ql_dbg_disc, vha, 0x20fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) 				"sess %p lid %d|%d DS %d LS %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) 				sess, sess->loop_id, loop_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) 				sess->disc_state, sess->fw_login_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) 		res = 1; /* send notify ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) 	case ELS_FLOGI:	/* should never happen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) 		    "qla_target(%d): Unsupported ELS command %x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) 		    "received\n", vha->vp_idx, iocb->u.isp24.status_subcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) 		res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) 	ql_dbg(ql_dbg_disc, vha, 0xf026,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) 	    "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) 	    vha->vp_idx, iocb->u.isp24.status_subcode, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) static void qlt_handle_imm_notify(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) 	struct imm_ntfy_from_isp *iocb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) 	uint32_t add_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) 	int send_notify_ack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) 	uint16_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) 	lockdep_assert_held(&ha->hardware_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) 	status = le16_to_cpu(iocb->u.isp2x.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) 	case IMM_NTFY_LIP_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) 		    "qla_target(%d): LIP reset (loop %#x), subcode %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) 		    vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) 		    iocb->u.isp24.status_subcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) 		if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) 			send_notify_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) 	case IMM_NTFY_LIP_LINK_REINIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) 		struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) 		    "qla_target(%d): LINK REINIT (loop %#x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) 		    "subcode %x)\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) 		    le16_to_cpu(iocb->u.isp24.nport_handle),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) 		    iocb->u.isp24.status_subcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) 		if (tgt->link_reinit_iocb_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) 			qlt_send_notify_ack(ha->base_qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) 			    &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) 		memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) 		tgt->link_reinit_iocb_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) 		 * QLogic requires to wait after LINK REINIT for possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) 		 * PDISC or ADISC ELS commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) 		send_notify_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) 	case IMM_NTFY_PORT_LOGOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) 		    "qla_target(%d): Port logout (loop "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) 		    "%#x, subcode %x)\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) 		    le16_to_cpu(iocb->u.isp24.nport_handle),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) 		    iocb->u.isp24.status_subcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) 		if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) 			send_notify_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) 		/* The sessions will be cleared in the callback, if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) 	case IMM_NTFY_GLBL_TPRLO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) 		    "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) 		if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) 			send_notify_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) 		/* The sessions will be cleared in the callback, if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) 	case IMM_NTFY_PORT_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) 		    "qla_target(%d): Port config changed (%x)\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) 		    status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) 		if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) 			send_notify_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) 		/* The sessions will be cleared in the callback, if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) 	case IMM_NTFY_GLBL_LOGO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) 		    "qla_target(%d): Link failure detected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) 		    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) 		/* I_T nexus loss */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) 		if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) 			send_notify_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) 	case IMM_NTFY_IOCB_OVERFLOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) 		    "qla_target(%d): Cannot provide requested "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) 		    "capability (IOCB overflowed the immediate notify "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) 		    "resource count)\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) 	case IMM_NTFY_ABORT_TASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) 		    "qla_target(%d): Abort Task (S %08x I %#x -> "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) 		    "L %#x)\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) 		    le16_to_cpu(iocb->u.isp2x.seq_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) 		    GET_TARGET_ID(ha, (struct atio_from_isp *)iocb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) 		    le16_to_cpu(iocb->u.isp2x.lun));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) 		if (qlt_abort_task(vha, iocb) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) 			send_notify_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) 	case IMM_NTFY_RESOURCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) 		    "qla_target(%d): Out of resources, host %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) 		    vha->vp_idx, vha->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) 	case IMM_NTFY_MSG_RX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) 		    "qla_target(%d): Immediate notify task %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) 		    vha->vp_idx, iocb->u.isp2x.task_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) 	case IMM_NTFY_ELS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) 		if (qlt_24xx_handle_els(vha, iocb) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) 			send_notify_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) 		    "qla_target(%d): Received unknown immediate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) 		    "notify status %x\n", vha->vp_idx, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) 	if (send_notify_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) 		qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) 		    0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270)  * This function sends busy to ISP 2xxx or 24xx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) static int __qlt_send_busy(struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) 	struct atio_from_isp *atio, uint16_t status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) 	struct scsi_qla_host *vha = qpair->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) 	struct ctio7_to_24xx *ctio24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) 	request_t *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) 	struct fc_port *sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) 	u16 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) 	port_id_t id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) 	id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) 	sess = qla2x00_find_fcport_by_nportid(vha, &id, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) 	if (!sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) 		qlt_send_term_exchange(qpair, NULL, atio, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) 	/* Sending marker isn't necessary, since we called from ISR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) 	pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) 	if (!pkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) 		ql_dbg(ql_dbg_io, vha, 0x3063,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) 		    "qla_target(%d): %s failed: unable to allocate "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) 		    "request packet", vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) 	qpair->tgt_counters.num_q_full_sent++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) 	pkt->entry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) 	pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) 	ctio24 = (struct ctio7_to_24xx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) 	ctio24->entry_type = CTIO_TYPE7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) 	ctio24->nport_handle = cpu_to_le16(sess->loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) 	ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) 	ctio24->vp_index = vha->vp_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) 	ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) 	ctio24->exchange_addr = atio->u.isp24.exchange_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) 	temp = (atio->u.isp24.attr << 9) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) 		CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) 		CTIO7_FLAGS_DONT_RET_CTIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) 	ctio24->u.status1.flags = cpu_to_le16(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) 	 * CTIO from fw w/o se_cmd doesn't provide enough info to retry it,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) 	 * if the explicit conformation is used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) 	ctio24->u.status1.ox_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) 		cpu_to_le16(be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) 	ctio24->u.status1.scsi_status = cpu_to_le16(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) 	ctio24->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) 	if (ctio24->u.status1.residual != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) 		ctio24->u.status1.scsi_status |= cpu_to_le16(SS_RESIDUAL_UNDER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) 	/* Memory Barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) 	if (qpair->reqq_start_iocbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) 		qpair->reqq_start_iocbs(qpair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) 		qla2x00_start_iocbs(vha, qpair->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341)  * This routine is used to allocate a command for either a QFull condition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342)  * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343)  * out previously.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) 	struct atio_from_isp *atio, uint16_t status, int qfull)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) 	struct fc_port *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) 	struct qla_tgt_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) 	if (unlikely(tgt->tgt_stop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) 		ql_dbg(ql_dbg_io, vha, 0x300a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) 			"New command while device %p is shutting down\n", tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) 	if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) 		vha->hw->tgt.num_qfull_cmds_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) 		if (vha->hw->tgt.num_qfull_cmds_dropped >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) 			vha->qla_stats.stat_max_qfull_cmds_dropped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) 			vha->qla_stats.stat_max_qfull_cmds_dropped =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) 				vha->hw->tgt.num_qfull_cmds_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) 		ql_dbg(ql_dbg_io, vha, 0x3068,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) 			"qla_target(%d): %s: QFull CMD dropped[%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370) 			vha->vp_idx, __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) 			vha->hw->tgt.num_qfull_cmds_dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) 		qlt_chk_exch_leak_thresh_hold(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) 	sess = ha->tgt.tgt_ops->find_sess_by_s_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) 		(vha, atio->u.isp24.fcp_hdr.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) 	if (!sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) 	cmd = ha->tgt.tgt_ops->get_cmd(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) 	if (!cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) 		ql_dbg(ql_dbg_io, vha, 0x3009,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) 			"qla_target(%d): %s: Allocation of cmd failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) 			vha->vp_idx, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) 		vha->hw->tgt.num_qfull_cmds_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) 		if (vha->hw->tgt.num_qfull_cmds_dropped >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) 			vha->qla_stats.stat_max_qfull_cmds_dropped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) 			vha->qla_stats.stat_max_qfull_cmds_dropped =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) 				vha->hw->tgt.num_qfull_cmds_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) 		qlt_chk_exch_leak_thresh_hold(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) 	qlt_incr_num_pend_cmds(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) 	INIT_LIST_HEAD(&cmd->cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) 	memcpy(&cmd->atio, atio, sizeof(*atio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) 	cmd->tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) 	cmd->vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) 	cmd->reset_count = ha->base_qpair->chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) 	cmd->q_full = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) 	cmd->qpair = ha->base_qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) 	if (qfull) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) 		cmd->q_full = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) 		/* NOTE: borrowing the state field to carry the status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) 		cmd->state = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) 		cmd->term_exchg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) 	spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) 	list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) 	vha->hw->tgt.num_qfull_cmds_alloc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) 	if (vha->hw->tgt.num_qfull_cmds_alloc >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) 		vha->qla_stats.stat_max_qfull_cmds_alloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) 		vha->qla_stats.stat_max_qfull_cmds_alloc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) 			vha->hw->tgt.num_qfull_cmds_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) 	spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) qlt_free_qfull_cmds(struct qla_qpair *qpair)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) 	struct scsi_qla_host *vha = qpair->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) 	struct qla_tgt_cmd *cmd, *tcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) 	struct list_head free_list, q_full_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) 	if (list_empty(&ha->tgt.q_full_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) 	INIT_LIST_HEAD(&free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) 	INIT_LIST_HEAD(&q_full_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) 	spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) 	if (list_empty(&ha->tgt.q_full_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) 		spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) 	list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) 	spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) 	spin_lock_irqsave(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) 	list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) 		if (cmd->q_full)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) 			/* cmd->state is a borrowed field to hold status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) 			rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) 		else if (cmd->term_exchg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) 			rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) 		if (rc == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) 		if (cmd->q_full)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) 			ql_dbg(ql_dbg_io, vha, 0x3006,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) 			    "%s: busy sent for ox_id[%04x]\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) 			    be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) 		else if (cmd->term_exchg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) 			ql_dbg(ql_dbg_io, vha, 0x3007,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) 			    "%s: Term exchg sent for ox_id[%04x]\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) 			    be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) 			ql_dbg(ql_dbg_io, vha, 0x3008,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) 			    "%s: Unexpected cmd in QFull list %p\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) 			    cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) 		list_del(&cmd->cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) 		list_add_tail(&cmd->cmd_list, &free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) 		/* piggy back on hardware_lock for protection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) 		vha->hw->tgt.num_qfull_cmds_alloc--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) 	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) 	cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) 	list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) 		list_del(&cmd->cmd_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) 		/* This cmd was never sent to TCM.  There is no need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) 		 * to schedule free or call free_cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) 		qlt_free_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) 	if (!list_empty(&q_full_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) 		spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) 		list_splice(&q_full_list, &vha->hw->tgt.q_full_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) 		spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504)     uint16_t status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) 	struct scsi_qla_host *vha = qpair->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) 	rc = __qlt_send_busy(qpair, atio, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) 	if (rc == -ENOMEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) 		qlt_alloc_qfull_cmd(vha, atio, status, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) 	struct atio_from_isp *atio, uint8_t ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) 	if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) 	if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) 		spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) 	qlt_send_busy(qpair, atio, qla_sam_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) 	if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) /* called via callback from qla2xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) 	struct atio_from_isp *atio, uint8_t ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) 	unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) 	if (unlikely(tgt == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) 		ql_dbg(ql_dbg_tgt, vha, 0x3064,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) 		    "ATIO pkt, but no tgt (ha %p)", ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) 	 * In tgt_stop mode we also should allow all requests to pass.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) 	 * Otherwise, some commands can stuck.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) 	tgt->atio_irq_cmd_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) 	switch (atio->u.raw.entry_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) 	case ATIO_TYPE7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) 		if (unlikely(atio->u.isp24.exchange_addr ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) 			     cpu_to_le32(ATIO_EXCHANGE_ADDRESS_UNKNOWN))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) 			ql_dbg(ql_dbg_io, vha, 0x3065,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) 			    "qla_target(%d): ATIO_TYPE7 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) 			    "received with UNKNOWN exchange address, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) 			    "sending QUEUE_FULL\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) 			if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) 				spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) 			qlt_send_busy(ha->base_qpair, atio, qla_sam_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) 			if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) 				spin_unlock_irqrestore(&ha->hardware_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568) 				    flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572) 		if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) 			rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574) 			    atio, ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) 			if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) 				tgt->atio_irq_cmd_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) 			rc = qlt_handle_cmd_for_atio(vha, atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) 			rc = qlt_handle_task_mgmt(vha, atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) 		if (unlikely(rc != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) 			if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) 				spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) 			switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) 			case -ENODEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) 				ql_dbg(ql_dbg_tgt, vha, 0xe05f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) 				    "qla_target: Unable to send command to target\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) 			case -EBADF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) 				ql_dbg(ql_dbg_tgt, vha, 0xe05f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593) 				    "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) 				qlt_send_term_exchange(ha->base_qpair, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) 				    atio, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) 			case -EBUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) 				ql_dbg(ql_dbg_tgt, vha, 0xe060,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) 				    "qla_target(%d): Unable to send command to target, sending BUSY status\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) 				    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) 				qlt_send_busy(ha->base_qpair, atio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) 				    tc_sam_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) 				ql_dbg(ql_dbg_tgt, vha, 0xe060,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) 				    "qla_target(%d): Unable to send command to target, sending BUSY status\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) 				    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) 				qlt_send_busy(ha->base_qpair, atio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) 				    qla_sam_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) 			if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) 				spin_unlock_irqrestore(&ha->hardware_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) 				    flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) 	case IMMED_NOTIFY_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) 		if (unlikely(atio->u.isp2x.entry_status != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) 			ql_dbg(ql_dbg_tgt, vha, 0xe05b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) 			    "qla_target(%d): Received ATIO packet %x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) 			    "with error status %x\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) 			    atio->u.raw.entry_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) 			    atio->u.isp2x.entry_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) 		ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) 		if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) 			spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) 		qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) 		if (!ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) 			spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) 		ql_dbg(ql_dbg_tgt, vha, 0xe05c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) 		    "qla_target(%d): Received unknown ATIO atio "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) 		    "type %x\n", vha->vp_idx, atio->u.raw.entry_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) 	tgt->atio_irq_cmd_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649)  * qpair lock is assume to be held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650)  * rc = 0 : send terminate & abts respond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651)  * rc != 0: do not send term & abts respond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654)     struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) 	 * Detect unresolved exchange. If the same ABTS is unable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) 	 * to terminate an existing command and the same ABTS loops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) 	 * between FW & Driver, then force FW dump. Under 1 jiff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) 	 * we should see multiple loops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) 	if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) 	    qpair->retry_term_jiff == jiffies) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) 		/* found existing exchange */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) 		qpair->retry_term_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) 		if (qpair->retry_term_cnt >= 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) 			qpair->retry_term_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) 			ql_log(ql_log_warn, vha, 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) 			    "Unable to send ABTS Respond. Dumping firmware.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) 			ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) 			    vha, 0xffff, (uint8_t *)entry, sizeof(*entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) 			if (qpair == ha->base_qpair)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) 				ha->isp_ops->fw_dump(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) 				qla2xxx_dump_fw(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) 			set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) 			qla2xxx_wake_dpc(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) 	} else if (qpair->retry_term_jiff != jiffies) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) 		qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) 		qpair->retry_term_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) 		qpair->retry_term_jiff = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) static void qlt_handle_abts_completion(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) 	struct rsp_que *rsp, response_t *pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) 	struct abts_resp_from_24xx_fw *entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) 		(struct abts_resp_from_24xx_fw *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) 	u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) 	struct qla_tgt_mgmt_cmd *mcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) 	mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) 	if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) 		ql_dbg(ql_dbg_async, vha, 0xe064,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) 		    "qla_target(%d): ABTS Comp without mcmd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) 		    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) 	if (mcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) 		vha  = mcmd->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) 	vha->vha_tgt.qla_tgt->abts_resp_expected--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) 	ql_dbg(ql_dbg_tgt, vha, 0xe038,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) 	    "ABTS_RESP_24XX: compl_status %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) 	    entry->compl_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) 	if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) 		if (le32_to_cpu(entry->error_subcode1) == 0x1E &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) 		    le32_to_cpu(entry->error_subcode2) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) 			if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) 				ha->tgt.tgt_ops->free_mcmd(mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) 			qlt_24xx_retry_term_exchange(vha, rsp->qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) 			    pkt, mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) 			ql_dbg(ql_dbg_tgt, vha, 0xe063,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) 			    "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) 			    vha->vp_idx, entry->compl_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) 			    entry->error_subcode1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) 			    entry->error_subcode2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) 			ha->tgt.tgt_ops->free_mcmd(mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) 	} else if (mcmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) 		ha->tgt.tgt_ops->free_mcmd(mcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) /* ha->hardware_lock supposed to be held on entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) /* called via callback from qla2xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744) static void qlt_response_pkt(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) 	struct rsp_que *rsp, response_t *pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) 	if (unlikely(tgt == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) 		ql_dbg(ql_dbg_tgt, vha, 0xe05d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) 		    "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) 		    vha->vp_idx, pkt->entry_type, vha->hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) 	 * In tgt_stop mode we also should allow all requests to pass.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758) 	 * Otherwise, some commands can stuck.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) 	switch (pkt->entry_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) 	case CTIO_CRC2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) 	case CTIO_TYPE7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765) 		struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) 		qlt_do_ctio_completion(vha, rsp, entry->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) 		    le16_to_cpu(entry->status)|(pkt->entry_status << 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) 		    entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) 	case ACCEPT_TGT_IO_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) 		struct atio_from_isp *atio = (struct atio_from_isp *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) 		int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) 		if (atio->u.isp2x.status !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) 		    cpu_to_le16(ATIO_CDB_VALID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) 			ql_dbg(ql_dbg_tgt, vha, 0xe05e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781) 			    "qla_target(%d): ATIO with error "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) 			    "status %x received\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) 			    le16_to_cpu(atio->u.isp2x.status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) 		rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788) 		if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) 		rc = qlt_handle_cmd_for_atio(vha, atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) 		if (unlikely(rc != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) 			switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) 			case -ENODEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) 				ql_dbg(ql_dbg_tgt, vha, 0xe05f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796) 				    "qla_target: Unable to send command to target\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) 			case -EBADF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) 				ql_dbg(ql_dbg_tgt, vha, 0xe05f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800) 				    "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) 				qlt_send_term_exchange(rsp->qpair, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) 				    atio, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) 			case -EBUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) 				ql_dbg(ql_dbg_tgt, vha, 0xe060,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) 				    "qla_target(%d): Unable to send command to target, sending BUSY status\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) 				    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) 				qlt_send_busy(rsp->qpair, atio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) 				    tc_sam_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) 				ql_dbg(ql_dbg_tgt, vha, 0xe060,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) 				    "qla_target(%d): Unable to send command to target, sending BUSY status\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) 				    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) 				qlt_send_busy(rsp->qpair, atio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) 				    qla_sam_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) 	break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) 	case CONTINUE_TGT_IO_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) 		struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) 		qlt_do_ctio_completion(vha, rsp, entry->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828) 		    le16_to_cpu(entry->status)|(pkt->entry_status << 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) 		    entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) 	case CTIO_A64_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) 		struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) 		qlt_do_ctio_completion(vha, rsp, entry->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) 		    le16_to_cpu(entry->status)|(pkt->entry_status << 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) 		    entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) 	case IMMED_NOTIFY_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) 		ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) 		qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848) 	case NOTIFY_ACK_TYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) 		if (tgt->notify_ack_expected > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) 			struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) 			ql_dbg(ql_dbg_tgt, vha, 0xe036,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) 			    "NOTIFY_ACK seq %08x status %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854) 			    le16_to_cpu(entry->u.isp2x.seq_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) 			    le16_to_cpu(entry->u.isp2x.status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856) 			tgt->notify_ack_expected--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) 			if (entry->u.isp2x.status !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) 			    cpu_to_le16(NOTIFY_ACK_SUCCESS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859) 				ql_dbg(ql_dbg_tgt, vha, 0xe061,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) 				    "qla_target(%d): NOTIFY_ACK "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) 				    "failed %x\n", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) 				    le16_to_cpu(entry->u.isp2x.status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) 			ql_dbg(ql_dbg_tgt, vha, 0xe062,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) 			    "qla_target(%d): Unexpected NOTIFY_ACK received\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) 			    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) 	case ABTS_RECV_24XX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) 		ql_dbg(ql_dbg_tgt, vha, 0xe037,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) 		    "ABTS_RECV_24XX: instance %d\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) 		qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) 	case ABTS_RESP_24XX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) 		if (tgt->abts_resp_expected > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879) 			qlt_handle_abts_completion(vha, rsp, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) 			ql_dbg(ql_dbg_tgt, vha, 0xe064,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) 			    "qla_target(%d): Unexpected ABTS_RESP_24XX "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) 			    "received\n", vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) 		ql_dbg(ql_dbg_tgt, vha, 0xe065,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) 		    "qla_target(%d): Received unknown response pkt "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) 		    "type %x\n", vha->vp_idx, pkt->entry_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897)  * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) void qlt_async_event(uint16_t code, struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) 	uint16_t *mailbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904) 	int login_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) 	if (!tgt || tgt->tgt_stop || tgt->tgt_stopped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) 	if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910) 	    IS_QLA2100(ha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) 	 * In tgt_stop mode we also should allow all requests to pass.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) 	 * Otherwise, some commands can stuck.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) 	switch (code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) 	case MBA_RESET:			/* Reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) 	case MBA_SYSTEM_ERR:		/* System Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) 	case MBA_REQ_TRANSFER_ERR:	/* Request Transfer Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) 	case MBA_RSP_TRANSFER_ERR:	/* Response Transfer Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) 		    "qla_target(%d): System error async event %#x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) 		    "occurred", vha->vp_idx, code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) 	case MBA_WAKEUP_THRES:		/* Request Queue Wake-up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) 		set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931) 	case MBA_LOOP_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) 		    "qla_target(%d): Async LOOP_UP occurred "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) 		    "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) 		    mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) 		if (tgt->link_reinit_iocb_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) 			qlt_send_notify_ack(ha->base_qpair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) 			    &tgt->link_reinit_iocb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) 			    0, 0, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) 			tgt->link_reinit_iocb_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) 	case MBA_LIP_OCCURRED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) 	case MBA_LOOP_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) 	case MBA_LIP_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) 	case MBA_RSCN_UPDATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) 		    "qla_target(%d): Async event %#x occurred "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) 		    "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) 		    mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) 	case MBA_REJECTED_FCP_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) 		    "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) 		    vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) 		    mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962) 		if (mailbox[3] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) 			/* exchange starvation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) 			vha->hw->exch_starvation++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) 			if (vha->hw->exch_starvation > 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) 				ql_log(ql_log_warn, vha, 0xd03a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) 				    "Exchange starvation-. Resetting RISC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) 				vha->hw->exch_starvation = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) 				if (IS_P3P_TYPE(vha->hw))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971) 					set_bit(FCOE_CTX_RESET_NEEDED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) 					    &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) 					set_bit(ISP_ABORT_NEEDED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) 					    &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) 				qla2xxx_wake_dpc(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) 	case MBA_PORT_UPDATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983) 		    "qla_target(%d): Port update async event %#x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) 		    "occurred: updating the ports database (m[0]=%x, m[1]=%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) 		    "m[2]=%x, m[3]=%x)", vha->vp_idx, code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) 		    mailbox[0], mailbox[1], mailbox[2], mailbox[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) 		login_code = mailbox[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) 		if (login_code == 0x4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) 			    "Async MB 2: Got PLOGI Complete\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) 			vha->hw->exch_starvation = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) 		} else if (login_code == 0x7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) 			    "Async MB 2: Port Logged Out\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) 	uint16_t loop_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) 	fc_port_t *fcport, *tfcp, *del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) 	u8 newfcport = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) 	fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) 	if (!fcport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) 		    "qla_target(%d): Allocation of tmp FC port failed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) 		    vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) 	fcport->loop_id = loop_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) 	rc = qla24xx_gpdb_wait(vha, fcport, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022) 	if (rc != QLA_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024) 		    "qla_target(%d): Failed to retrieve fcport "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025) 		    "information -- get_port_database() returned %x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) 		    "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027) 		kfree(fcport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) 	del = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) 	spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) 	tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) 	if (tfcp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) 		tfcp->d_id = fcport->d_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) 		tfcp->port_type = fcport->port_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) 		tfcp->supported_classes = fcport->supported_classes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) 		tfcp->flags |= fcport->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) 		tfcp->scan_state = QLA_FCPORT_FOUND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) 		del = fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) 		fcport = tfcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) 		if (vha->hw->current_topology == ISP_CFG_F)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) 			fcport->flags |= FCF_FABRIC_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) 		list_add_tail(&fcport->list, &vha->vp_fcports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) 		if (!IS_SW_RESV_ADDR(fcport->d_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) 		   vha->fcport_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) 		fcport->login_gen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052) 		qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) 		fcport->login_succ = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) 		newfcport = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) 	fcport->deleted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) 	spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) 	switch (vha->host->active_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) 	case MODE_INITIATOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) 	case MODE_DUAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) 		if (newfcport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) 			if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) 				qla24xx_sched_upd_fcport(fcport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) 				ql_dbg(ql_dbg_disc, vha, 0x20ff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) 				   "%s %d %8phC post gpsc fcp_cnt %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) 				   __func__, __LINE__, fcport->port_name, vha->fcport_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) 				qla24xx_post_gpsc_work(vha, fcport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) 	case MODE_TARGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) 	if (del)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) 		qla2x00_free_fcport(del);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) 	return fcport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) /* Must be called under tgt_mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) 					   be_id_t s_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089) 	struct fc_port *sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090) 	fc_port_t *fcport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091) 	int rc, global_resets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) 	uint16_t loop_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) 	if (s_id.domain == 0xFF && s_id.area == 0xFC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) 		 * This is Domain Controller, so it should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) 		 * OK to drop SCSI commands from it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) 		    "Unable to find initiator with S_ID %x:%x:%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) 		    s_id.domain, s_id.area, s_id.al_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105) 	mutex_lock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) 	global_resets =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) 	    atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) 	rc = qla24xx_get_loop_id(vha, s_id, &loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) 	if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) 		mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) 		ql_log(ql_log_info, vha, 0xf071,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) 		    "qla_target(%d): Unable to find "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) 		    "initiator with S_ID %x:%x:%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) 		    vha->vp_idx, s_id.domain, s_id.area, s_id.al_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) 		if (rc == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) 			qlt_port_logo_t logo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) 			logo.id = be_to_port_id(s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) 			logo.cmd_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) 			qlt_send_first_logo(vha, &logo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) 	fcport = qlt_get_port_database(vha, loop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) 	if (!fcport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) 		mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) 	if (global_resets !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) 	    atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) 		    "qla_target(%d): global reset during session discovery "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) 		    "(counter was %d, new %d), retrying", vha->vp_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) 		    global_resets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) 		    atomic_read(&vha->vha_tgt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) 			qla_tgt->tgt_global_resets_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148) 	sess = qlt_create_sess(vha, fcport, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) 	mutex_unlock(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152) 	return sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) static void qlt_abort_work(struct qla_tgt *tgt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) 	struct qla_tgt_sess_work_param *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) 	struct scsi_qla_host *vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) 	struct fc_port *sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) 	unsigned long flags = 0, flags2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) 	be_id_t s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) 	if (tgt->tgt_stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168) 		goto out_term2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) 	s_id = le_id_to_be(prm->abts.fcp_hdr_le.s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) 	sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173) 	if (!sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) 		sess = qlt_make_local_sess(vha, s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) 		/* sess has got an extra creation ref */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) 		spin_lock_irqsave(&ha->tgt.sess_lock, flags2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) 		if (!sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) 			goto out_term2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) 		if (sess->deleted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) 			sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) 			goto out_term2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) 		if (!kref_get_unless_zero(&sess->sess_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) 			ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) 			    "%s: kref_get fail %8phC \n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) 			     __func__, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) 			sess = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) 			goto out_term2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) 	rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) 	ha->tgt.tgt_ops->put_sess(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) 	if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) 		goto out_term;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) out_term2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) out_term:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) 	qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) 	    FCP_TMF_REJECTED, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) static void qlt_tmr_work(struct qla_tgt *tgt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) 	struct qla_tgt_sess_work_param *prm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) 	struct atio_from_isp *a = &prm->tm_iocb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) 	struct scsi_qla_host *vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) 	struct fc_port *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224) 	be_id_t s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) 	u64 unpacked_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) 	int fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) 	void *iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230) 	spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) 	if (tgt->tgt_stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233) 		goto out_term2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) 	s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236) 	sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) 	if (!sess) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) 		spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) 		sess = qlt_make_local_sess(vha, s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) 		/* sess has got an extra creation ref */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) 		spin_lock_irqsave(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) 		if (!sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) 			goto out_term2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247) 		if (sess->deleted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) 			goto out_term2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) 		if (!kref_get_unless_zero(&sess->sess_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) 			ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253) 			    "%s: kref_get fail %8phC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) 			     __func__, sess->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) 			goto out_term2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) 	iocb = a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) 	fn = a->u.isp24.fcp_cmnd.task_mgmt_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261) 	unpacked_lun =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) 	    scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264) 	rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267) 	ha->tgt.tgt_ops->put_sess(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) 	if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) 		goto out_term;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273) out_term2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274) 	spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) out_term:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276) 	qlt_send_term_exchange(ha->base_qpair, NULL, &prm->tm_iocb2, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) static void qlt_sess_work_fn(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281) 	struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) 	struct scsi_qla_host *vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) 	spin_lock_irqsave(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) 	while (!list_empty(&tgt->sess_works_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) 		struct qla_tgt_sess_work_param *prm = list_entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) 		    tgt->sess_works_list.next, typeof(*prm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291) 		    sess_works_list_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) 		 * This work can be scheduled on several CPUs at time, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) 		 * must delete the entry to eliminate double processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) 		list_del(&prm->sess_works_list_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) 		spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) 		switch (prm->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302) 		case QLA_TGT_SESS_WORK_ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303) 			qlt_abort_work(tgt, prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) 		case QLA_TGT_SESS_WORK_TM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306) 			qlt_tmr_work(tgt, prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) 			BUG_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) 		spin_lock_irqsave(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) 		kfree(prm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) 	spin_unlock_irqrestore(&tgt->sess_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) /* Must be called under tgt_host_action_mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) 	struct qla_tgt *tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) 	int rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) 	struct qla_qpair_hint *h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330) 	if (!IS_TGT_MODE_CAPABLE(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) 		ql_log(ql_log_warn, base_vha, 0xe070,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) 		    "This adapter does not support target mode.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) 	ql_dbg(ql_dbg_tgt, base_vha, 0xe03b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) 	    "Registering target for host %ld(%p).\n", base_vha->host_no, ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) 	BUG_ON(base_vha->vha_tgt.qla_tgt != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) 	tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) 	if (!tgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) 		ql_dbg(ql_dbg_tgt, base_vha, 0xe066,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) 		    "Unable to allocate struct qla_tgt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) 	tgt->qphints = kcalloc(ha->max_qpairs + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349) 			       sizeof(struct qla_qpair_hint),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) 			       GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) 	if (!tgt->qphints) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352) 		kfree(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) 		ql_log(ql_log_warn, base_vha, 0x0197,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354) 		    "Unable to allocate qpair hints.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) 	if (!(base_vha->host->hostt->supported_mode & MODE_TARGET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) 		base_vha->host->hostt->supported_mode |= MODE_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) 	rc = btree_init64(&tgt->lun_qpair_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) 		kfree(tgt->qphints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364) 		kfree(tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) 		ql_log(ql_log_info, base_vha, 0x0198,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) 			"Unable to initialize lun_qpair_map btree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) 	h = &tgt->qphints[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) 	h->qpair = ha->base_qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) 	INIT_LIST_HEAD(&h->hint_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) 	h->cpuid = ha->base_qpair->cpuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) 	list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375) 	for (i = 0; i < ha->max_qpairs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) 		struct qla_qpair *qpair = ha->queue_pair_map[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) 		h = &tgt->qphints[i + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) 		INIT_LIST_HEAD(&h->hint_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382) 		if (qpair) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383) 			h->qpair = qpair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) 			spin_lock_irqsave(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) 			list_add_tail(&h->hint_elem, &qpair->hints_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386) 			spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) 			h->cpuid = qpair->cpuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) 	tgt->ha = ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392) 	tgt->vha = base_vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) 	init_waitqueue_head(&tgt->waitQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) 	INIT_LIST_HEAD(&tgt->del_sess_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) 	spin_lock_init(&tgt->sess_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) 	INIT_WORK(&tgt->sess_work, qlt_sess_work_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397) 	INIT_LIST_HEAD(&tgt->sess_works_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398) 	atomic_set(&tgt->tgt_global_resets_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400) 	base_vha->vha_tgt.qla_tgt = tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) 	ql_dbg(ql_dbg_tgt, base_vha, 0xe067,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) 		"qla_target(%d): using 64 Bit PCI addressing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) 		base_vha->vp_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) 	/* 3 is reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) 	tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) 	mutex_lock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409) 	list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410) 	mutex_unlock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412) 	if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413) 		ha->tgt.tgt_ops->add_target(base_vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) /* Must be called under tgt_host_action_mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) 	if (!vha->vha_tgt.qla_tgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) 	if (vha->fc_vport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) 		qlt_release(vha->vha_tgt.qla_tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) 	/* free left over qfull cmds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430) 	qlt_init_term_exchange(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432) 	ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) 	    vha->host_no, ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434) 	qlt_release(vha->vha_tgt.qla_tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439) void qlt_remove_target_resources(struct qla_hw_data *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441) 	struct scsi_qla_host *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442) 	u32 key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) 	btree_for_each_safe32(&ha->tgt.host_map, key, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) 		btree_remove32(&ha->tgt.host_map, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) 	btree_destroy32(&ha->tgt.host_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450) static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) 	unsigned char *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) 	pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) 	pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455) 	put_unaligned_be64(wwpn, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) 	pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460)  * qla_tgt_lport_register - register lport with external module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462)  * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463)  * @phys_wwpn: physical port WWPN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464)  * @npiv_wwpn: NPIV WWPN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465)  * @npiv_wwnn: NPIV WWNN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466)  * @callback:  lport initialization callback for tcm_qla2xxx code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468) int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469) 		       u64 npiv_wwpn, u64 npiv_wwnn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470) 		       int (*callback)(struct scsi_qla_host *, void *, u64, u64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) 	struct qla_tgt *tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) 	struct scsi_qla_host *vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) 	struct qla_hw_data *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) 	struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) 	u8 b[WWN_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480) 	mutex_lock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) 	list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) 		vha = tgt->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483) 		ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485) 		host = vha->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) 		if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489) 		if (!(host->hostt->supported_mode & MODE_TARGET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) 		if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495) 		spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496) 		if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497) 			pr_debug("MODE_TARGET already active on qla2xxx(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498) 			    host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499) 			spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502) 		if (tgt->tgt_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503) 			pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504) 				 host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) 			spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510) 		if (!scsi_host_get(host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) 			ql_dbg(ql_dbg_tgt, vha, 0xe068,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) 			    "Unable to scsi_host_get() for"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) 			    " qla2xxx scsi_host\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) 		qlt_lport_dump(vha, phys_wwpn, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518) 		if (memcmp(vha->port_name, b, WWN_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) 			scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) 		rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) 		if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) 			scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526) 		mutex_unlock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) 	mutex_unlock(&qla_tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) EXPORT_SYMBOL(qlt_lport_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536)  * qla_tgt_lport_deregister - Degister lport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538)  * @vha:  Registered scsi_qla_host pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) void qlt_lport_deregister(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) 	struct Scsi_Host *sh = vha->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545) 	 * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) 	vha->vha_tgt.target_lport_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) 	ha->tgt.tgt_ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550) 	 * Release the Scsi_Host reference for the underlying qla2xxx host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) 	scsi_host_put(sh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554) EXPORT_SYMBOL(qlt_lport_deregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) /* Must be called under HW lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) void qlt_set_mode(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) 	switch (vha->qlini_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560) 	case QLA2XXX_INI_MODE_DISABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561) 	case QLA2XXX_INI_MODE_EXCLUSIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) 		vha->host->active_mode = MODE_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) 	case QLA2XXX_INI_MODE_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) 		vha->host->active_mode = MODE_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) 	case QLA2XXX_INI_MODE_DUAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568) 		vha->host->active_mode = MODE_DUAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575) /* Must be called under HW lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6576) static void qlt_clear_mode(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6578) 	switch (vha->qlini_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6579) 	case QLA2XXX_INI_MODE_DISABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6580) 		vha->host->active_mode = MODE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6581) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6582) 	case QLA2XXX_INI_MODE_EXCLUSIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6583) 		vha->host->active_mode = MODE_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6584) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6585) 	case QLA2XXX_INI_MODE_ENABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6586) 	case QLA2XXX_INI_MODE_DUAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6587) 		vha->host->active_mode = MODE_INITIATOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6588) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6589) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6590) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6595)  * qla_tgt_enable_vha - NO LOCK HELD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6596)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6597)  * host_reset, bring up w/ Target Mode Enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6598)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6599) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6600) qlt_enable_vha(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6602) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6603) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6604) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6605) 	scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6607) 	if (!tgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6608) 		ql_dbg(ql_dbg_tgt, vha, 0xe069,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6609) 		    "Unable to locate qla_tgt pointer from"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6610) 		    " struct qla_hw_data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6611) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6612) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6613) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6614) 	if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6615) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6617) 	if (ha->tgt.num_act_qpairs > ha->max_qpairs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6618) 		ha->tgt.num_act_qpairs = ha->max_qpairs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6619) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6620) 	tgt->tgt_stopped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6621) 	qlt_set_mode(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6622) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6624) 	mutex_lock(&ha->optrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6625) 	ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6626) 	    "%s.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6627) 	if (vha->vp_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6628) 		qla24xx_disable_vp(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6629) 		qla24xx_enable_vp(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6630) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6631) 		set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6632) 		qla2xxx_wake_dpc(base_vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6633) 		WARN_ON_ONCE(qla2x00_wait_for_hba_online(base_vha) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6634) 			     QLA_SUCCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6636) 	mutex_unlock(&ha->optrom_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6638) EXPORT_SYMBOL(qlt_enable_vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6640) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6641)  * qla_tgt_disable_vha - NO LOCK HELD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6642)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6643)  * Disable Target Mode and reset the adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6644)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6645) static void qlt_disable_vha(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6647) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6648) 	struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6649) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6651) 	if (!tgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6652) 		ql_dbg(ql_dbg_tgt, vha, 0xe06a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6653) 		    "Unable to locate qla_tgt pointer from"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6654) 		    " struct qla_hw_data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6655) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6656) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6657) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6659) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6660) 	qlt_clear_mode(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6661) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6663) 	set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6664) 	qla2xxx_wake_dpc(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6666) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6667) 	 * We are expecting the offline state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6668) 	 * QLA_FUNCTION_FAILED means that adapter is offline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6669) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6670) 	if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6671) 		ql_dbg(ql_dbg_tgt, vha, 0xe081,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6672) 		       "adapter is offline\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6675) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6676)  * Called from qla_init.c:qla24xx_vport_create() contex to setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6677)  * the target mode specific struct scsi_qla_host and struct qla_hw_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6678)  * members.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6679)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6680) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6681) qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6683) 	vha->vha_tgt.qla_tgt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6685) 	mutex_init(&vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6686) 	mutex_init(&vha->vha_tgt.tgt_host_action_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6688) 	qlt_clear_mode(vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6690) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6691) 	 * NOTE: Currently the value is kept the same for <24xx and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6692) 	 * >=24xx ISPs. If it is necessary to change it,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6693) 	 * the check should be added for specific ISPs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6694) 	 * assigning the value appropriately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6695) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6696) 	ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6698) 	qlt_add_target(ha, vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6701) u8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6702) qlt_rff_id(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6704) 	u8 fc4_feature = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6705) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6706) 	 * FC-4 Feature bit 0 indicates target functionality to the name server.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6707) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6708) 	if (qla_tgt_mode_enabled(vha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6709) 		fc4_feature = BIT_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6710) 	} else if (qla_ini_mode_enabled(vha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6711) 		fc4_feature = BIT_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6712) 	} else if (qla_dual_mode_enabled(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6713) 		fc4_feature = BIT_0 | BIT_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6715) 	return fc4_feature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6718) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6719)  * qlt_init_atio_q_entries() - Initializes ATIO queue entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6720)  * @ha: HA context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6721)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6722)  * Beginning of ATIO ring has initialization control block already built
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6723)  * by nvram config routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6724)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6725)  * Returns 0 on success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6726)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6727) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6728) qlt_init_atio_q_entries(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6730) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6731) 	uint16_t cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6732) 	struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6734) 	if (qla_ini_mode_enabled(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6735) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6737) 	for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6738) 		pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6739) 		pkt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6740) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6744) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6745)  * qlt_24xx_process_atio_queue() - Process ATIO queue entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6746)  * @ha: SCSI driver HA context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6747)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6748) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6749) qlt_24xx_process_atio_queue(struct scsi_qla_host *vha, uint8_t ha_locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6751) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6752) 	struct atio_from_isp *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6753) 	int cnt, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6755) 	if (!ha->flags.fw_started)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6756) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6758) 	while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6759) 	    fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6760) 		pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6761) 		cnt = pkt->u.raw.entry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6763) 		if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6764) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6765) 			 * This packet is corrupted. The header + payload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6766) 			 * can not be trusted. There is no point in passing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6767) 			 * it further up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6768) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6769) 			ql_log(ql_log_warn, vha, 0xd03c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6770) 			    "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6771) 			    &pkt->u.isp24.fcp_hdr.s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6772) 			    be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6773) 			    pkt->u.isp24.exchange_addr, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6775) 			adjust_corrupted_atio(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6776) 			qlt_send_term_exchange(ha->base_qpair, NULL, pkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6777) 			    ha_locked, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6778) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6779) 			qlt_24xx_atio_pkt_all_vps(vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6780) 			    (struct atio_from_isp *)pkt, ha_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6781) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6783) 		for (i = 0; i < cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6784) 			ha->tgt.atio_ring_index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6785) 			if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6786) 				ha->tgt.atio_ring_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6787) 				ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6788) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6789) 				ha->tgt.atio_ring_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6791) 			pkt->u.raw.signature = cpu_to_le32(ATIO_PROCESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6792) 			pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6793) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6794) 		wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6795) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6797) 	/* Adjust ring index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6798) 	wrt_reg_dword(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6801) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6802) qlt_24xx_config_rings(struct scsi_qla_host *vha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6804) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6805) 	struct qla_msix_entry *msix = &ha->msix_entries[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6806) 	struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6808) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6809) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6811) 	wrt_reg_dword(ISP_ATIO_Q_IN(vha), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6812) 	wrt_reg_dword(ISP_ATIO_Q_OUT(vha), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6813) 	rd_reg_dword(ISP_ATIO_Q_OUT(vha));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6815) 	if (ha->flags.msix_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6816) 		if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6817) 			if (IS_QLA2071(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6818) 				/* 4 ports Baker: Enable Interrupt Handshake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6819) 				icb->msix_atio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6820) 				icb->firmware_options_2 |= cpu_to_le32(BIT_26);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6821) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6822) 				icb->msix_atio = cpu_to_le16(msix->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6823) 				icb->firmware_options_2 &= cpu_to_le32(~BIT_26);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6824) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6825) 			ql_dbg(ql_dbg_init, vha, 0xf072,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6826) 			    "Registering ICB vector 0x%x for atio que.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6827) 			    msix->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6828) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6829) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6830) 		/* INTx|MSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6831) 		if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6832) 			icb->msix_atio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6833) 			icb->firmware_options_2 |= cpu_to_le32(BIT_26);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6834) 			ql_dbg(ql_dbg_init, vha, 0xf072,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6835) 			    "%s: Use INTx for ATIOQ.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6836) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6840) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6841) qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6843) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6844) 	u32 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6846) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6847) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6849) 	if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6850) 		if (!ha->tgt.saved_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6851) 			/* We save only once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6852) 			ha->tgt.saved_exchange_count = nv->exchange_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6853) 			ha->tgt.saved_firmware_options_1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6854) 			    nv->firmware_options_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6855) 			ha->tgt.saved_firmware_options_2 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6856) 			    nv->firmware_options_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6857) 			ha->tgt.saved_firmware_options_3 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6858) 			    nv->firmware_options_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6859) 			ha->tgt.saved_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6860) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6862) 		if (qla_tgt_mode_enabled(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6863) 			nv->exchange_count = cpu_to_le16(0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6864) 		else			/* dual */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6865) 			nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6867) 		/* Enable target mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6868) 		nv->firmware_options_1 |= cpu_to_le32(BIT_4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6870) 		/* Disable ini mode, if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6871) 		if (qla_tgt_mode_enabled(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6872) 			nv->firmware_options_1 |= cpu_to_le32(BIT_5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6874) 		/* Disable Full Login after LIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6875) 		nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6876) 		/* Enable initial LIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6877) 		nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6878) 		if (ql2xtgt_tape_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6879) 			/* Enable FC Tape support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6880) 			nv->firmware_options_2 |= cpu_to_le32(BIT_12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6881) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6882) 			/* Disable FC Tape support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6883) 			nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6885) 		/* Disable Full Login after LIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6886) 		nv->host_p &= cpu_to_le32(~BIT_10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6888) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6889) 		 * clear BIT 15 explicitly as we have seen at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6890) 		 * a couple of instances where this was set and this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6891) 		 * was causing the firmware to not be initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6892) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6893) 		nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6894) 		/* Enable target PRLI control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6895) 		nv->firmware_options_2 |= cpu_to_le32(BIT_14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6897) 		if (IS_QLA25XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6898) 			/* Change Loop-prefer to Pt-Pt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6899) 			tmp = ~(BIT_4|BIT_5|BIT_6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6900) 			nv->firmware_options_2 &= cpu_to_le32(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6901) 			tmp = P2P << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6902) 			nv->firmware_options_2 |= cpu_to_le32(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6903) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6904) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6905) 		if (ha->tgt.saved_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6906) 			nv->exchange_count = ha->tgt.saved_exchange_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6907) 			nv->firmware_options_1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6908) 			    ha->tgt.saved_firmware_options_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6909) 			nv->firmware_options_2 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6910) 			    ha->tgt.saved_firmware_options_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6911) 			nv->firmware_options_3 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6912) 			    ha->tgt.saved_firmware_options_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6913) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6914) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6915) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6917) 	if (ha->base_qpair->enable_class_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6918) 		if (vha->flags.init_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6919) 			fc_host_supported_classes(vha->host) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6920) 				FC_COS_CLASS2 | FC_COS_CLASS3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6922) 		nv->firmware_options_2 |= cpu_to_le32(BIT_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6923) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6924) 		if (vha->flags.init_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6925) 			fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6927) 		nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6928) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6931) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6932) qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6933) 	struct init_cb_24xx *icb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6935) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6937) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6938) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6940) 	if (ha->tgt.node_name_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6941) 		memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6942) 		icb->firmware_options_1 |= cpu_to_le32(BIT_14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6943) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6946) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6947) qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6949) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6950) 	u32 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6952) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6953) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6955) 	if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6956) 		if (!ha->tgt.saved_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6957) 			/* We save only once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6958) 			ha->tgt.saved_exchange_count = nv->exchange_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6959) 			ha->tgt.saved_firmware_options_1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6960) 			    nv->firmware_options_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6961) 			ha->tgt.saved_firmware_options_2 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6962) 			    nv->firmware_options_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6963) 			ha->tgt.saved_firmware_options_3 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6964) 			    nv->firmware_options_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6965) 			ha->tgt.saved_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6966) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6968) 		if (qla_tgt_mode_enabled(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6969) 			nv->exchange_count = cpu_to_le16(0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6970) 		else			/* dual */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6971) 			nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6973) 		/* Enable target mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6974) 		nv->firmware_options_1 |= cpu_to_le32(BIT_4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6976) 		/* Disable ini mode, if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6977) 		if (qla_tgt_mode_enabled(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6978) 			nv->firmware_options_1 |= cpu_to_le32(BIT_5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6979) 		/* Disable Full Login after LIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6980) 		nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6981) 		/* Enable initial LIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6982) 		nv->firmware_options_1 &= cpu_to_le32(~BIT_9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6983) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6984) 		 * clear BIT 15 explicitly as we have seen at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6985) 		 * least a couple of instances where this was set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6986) 		 * and this was causing the firmware to not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6987) 		 * initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6988) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6989) 		nv->firmware_options_1 &= cpu_to_le32(~BIT_15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6990) 		if (ql2xtgt_tape_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6991) 			/* Enable FC tape support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6992) 			nv->firmware_options_2 |= cpu_to_le32(BIT_12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6993) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6994) 			/* Disable FC tape support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6995) 			nv->firmware_options_2 &= cpu_to_le32(~BIT_12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6997) 		/* Disable Full Login after LIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6998) 		nv->host_p &= cpu_to_le32(~BIT_10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6999) 		/* Enable target PRLI control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7000) 		nv->firmware_options_2 |= cpu_to_le32(BIT_14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7002) 		/* Change Loop-prefer to Pt-Pt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7003) 		tmp = ~(BIT_4|BIT_5|BIT_6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7004) 		nv->firmware_options_2 &= cpu_to_le32(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7005) 		tmp = P2P << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7006) 		nv->firmware_options_2 |= cpu_to_le32(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7007) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7008) 		if (ha->tgt.saved_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7009) 			nv->exchange_count = ha->tgt.saved_exchange_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7010) 			nv->firmware_options_1 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7011) 			    ha->tgt.saved_firmware_options_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7012) 			nv->firmware_options_2 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7013) 			    ha->tgt.saved_firmware_options_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7014) 			nv->firmware_options_3 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7015) 			    ha->tgt.saved_firmware_options_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7016) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7017) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7018) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7020) 	if (ha->base_qpair->enable_class_2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7021) 		if (vha->flags.init_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7022) 			fc_host_supported_classes(vha->host) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7023) 				FC_COS_CLASS2 | FC_COS_CLASS3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7025) 		nv->firmware_options_2 |= cpu_to_le32(BIT_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7026) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7027) 		if (vha->flags.init_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7028) 			fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7030) 		nv->firmware_options_2 &= ~cpu_to_le32(BIT_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7031) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7034) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7035) qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7036) 	struct init_cb_81xx *icb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7037) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7038) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7040) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7041) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7043) 	if (ha->tgt.node_name_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7044) 		memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7045) 		icb->firmware_options_1 |= cpu_to_le32(BIT_14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7046) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7049) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7050) qlt_83xx_iospace_config(struct qla_hw_data *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7051) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7052) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7053) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7055) 	ha->msix_count += 1; /* For ATIO Q */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7059) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7060) qlt_modify_vp_config(struct scsi_qla_host *vha,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7061) 	struct vp_config_entry_24xx *vpmod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7063) 	/* enable target mode.  Bit5 = 1 => disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7064) 	if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7065) 		vpmod->options_idx1 &= ~BIT_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7067) 	/* Disable ini mode, if requested.  bit4 = 1 => disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7068) 	if (qla_tgt_mode_enabled(vha))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7069) 		vpmod->options_idx1 &= ~BIT_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7072) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7073) qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7075) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7077) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7078) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7080) 	if  (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7081) 		ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7082) 		ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7083) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7084) 		ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7085) 		ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7086) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7088) 	mutex_init(&base_vha->vha_tgt.tgt_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7089) 	mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7091) 	INIT_LIST_HEAD(&base_vha->unknown_atio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7092) 	INIT_DELAYED_WORK(&base_vha->unknown_atio_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7093) 	    qlt_unknown_atio_work_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7095) 	qlt_clear_mode(base_vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7097) 	rc = btree_init32(&ha->tgt.host_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7098) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7099) 		ql_log(ql_log_info, base_vha, 0xd03d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7100) 		    "Unable to initialize ha->host_map btree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7102) 	qlt_update_vp_map(base_vha, SET_VP_IDX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7105) irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7106) qla83xx_msix_atio_q(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7108) 	struct rsp_que *rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7109) 	scsi_qla_host_t	*vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7110) 	struct qla_hw_data *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7111) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7113) 	rsp = (struct rsp_que *) dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7114) 	ha = rsp->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7115) 	vha = pci_get_drvdata(ha->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7117) 	spin_lock_irqsave(&ha->tgt.atio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7119) 	qlt_24xx_process_atio_queue(vha, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7121) 	spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7123) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7126) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7127) qlt_handle_abts_recv_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7129) 	struct qla_tgt_sess_op *op = container_of(work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7130) 		struct qla_tgt_sess_op, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7131) 	scsi_qla_host_t *vha = op->vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7132) 	struct qla_hw_data *ha = vha->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7133) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7135) 	if (qla2x00_reset_active(vha) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7136) 	    (op->chip_reset != ha->base_qpair->chip_reset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7137) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7139) 	spin_lock_irqsave(&ha->tgt.atio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7140) 	qlt_24xx_process_atio_queue(vha, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7141) 	spin_unlock_irqrestore(&ha->tgt.atio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7143) 	spin_lock_irqsave(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7144) 	qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7145) 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7147) 	kfree(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7150) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7151) qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7152)     response_t *pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7154) 	struct qla_tgt_sess_op *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7156) 	op = kzalloc(sizeof(*op), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7158) 	if (!op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7159) 		/* do not reach for ATIO queue here.  This is best effort err
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7160) 		 * recovery at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7161) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7162) 		qlt_response_pkt_all_vps(vha, rsp, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7163) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7166) 	memcpy(&op->atio, pkt, sizeof(*pkt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7167) 	op->vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7168) 	op->chip_reset = vha->hw->base_qpair->chip_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7169) 	op->rsp = rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7170) 	INIT_WORK(&op->work, qlt_handle_abts_recv_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7171) 	queue_work(qla_tgt_wq, &op->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7172) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7175) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7176) qlt_mem_alloc(struct qla_hw_data *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7178) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7179) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7181) 	ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7182) 				     sizeof(struct qla_tgt_vp_map),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7183) 				     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7184) 	if (!ha->tgt.tgt_vp_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7185) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7187) 	ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7188) 	    (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7189) 	    &ha->tgt.atio_dma, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7190) 	if (!ha->tgt.atio_ring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7191) 		kfree(ha->tgt.tgt_vp_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7192) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7194) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7197) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7198) qlt_mem_free(struct qla_hw_data *ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7200) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7201) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7203) 	if (ha->tgt.atio_ring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7204) 		dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7205) 		    sizeof(struct atio_from_isp), ha->tgt.atio_ring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7206) 		    ha->tgt.atio_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7208) 	ha->tgt.atio_ring = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7209) 	ha->tgt.atio_dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7210) 	kfree(ha->tgt.tgt_vp_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7211) 	ha->tgt.tgt_vp_map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7214) /* vport_slock to be held by the caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7215) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7216) qlt_update_vp_map(struct scsi_qla_host *vha, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7218) 	void *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7219) 	u32 key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7220) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7222) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7223) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7225) 	key = vha->d_id.b24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7227) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7228) 	case SET_VP_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7229) 		vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7230) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7231) 	case SET_AL_PA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7232) 		slot = btree_lookup32(&vha->hw->tgt.host_map, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7233) 		if (!slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7234) 			ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7235) 			    "Save vha in host_map %p %06x\n", vha, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7236) 			rc = btree_insert32(&vha->hw->tgt.host_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7237) 				key, vha, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7238) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7239) 				ql_log(ql_log_info, vha, 0xd03e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7240) 				    "Unable to insert s_id into host_map: %06x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7241) 				    key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7242) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7243) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7244) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7245) 		    "replace existing vha in host_map %p %06x\n", vha, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7246) 		btree_update32(&vha->hw->tgt.host_map, key, vha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7247) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7248) 	case RESET_VP_IDX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7249) 		vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7250) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7251) 	case RESET_AL_PA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7252) 		ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7253) 		   "clear vha in host_map %p %06x\n", vha, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7254) 		slot = btree_lookup32(&vha->hw->tgt.host_map, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7255) 		if (slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7256) 			btree_remove32(&vha->hw->tgt.host_map, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7257) 		vha->d_id.b24 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7258) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7262) void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7265) 	if (!vha->d_id.b24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7266) 		vha->d_id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7267) 		qlt_update_vp_map(vha, SET_AL_PA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7268) 	} else if (vha->d_id.b24 != id.b24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7269) 		qlt_update_vp_map(vha, RESET_AL_PA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7270) 		vha->d_id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7271) 		qlt_update_vp_map(vha, SET_AL_PA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7272) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7275) static int __init qlt_parse_ini_mode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7277) 	if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7278) 		ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7279) 	else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7280) 		ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7281) 	else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7282) 		ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7283) 	else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7284) 		ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7285) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7286) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7288) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7291) int __init qlt_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7293) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7295) 	BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7296) 	BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7298) 	if (!qlt_parse_ini_mode()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7299) 		ql_log(ql_log_fatal, NULL, 0xe06b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7300) 		    "qlt_parse_ini_mode() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7301) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7304) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7305) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7307) 	qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7308) 	    sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7309) 	    qla_tgt_mgmt_cmd), 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7310) 	if (!qla_tgt_mgmt_cmd_cachep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7311) 		ql_log(ql_log_fatal, NULL, 0xd04b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7312) 		    "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7313) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7316) 	qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7317) 	    sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7318) 	    0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7320) 	if (!qla_tgt_plogi_cachep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7321) 		ql_log(ql_log_fatal, NULL, 0xe06d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7322) 		    "kmem_cache_create for qla_tgt_plogi_cachep failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7323) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7324) 		goto out_mgmt_cmd_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7327) 	qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7328) 	    mempool_free_slab, qla_tgt_mgmt_cmd_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7329) 	if (!qla_tgt_mgmt_cmd_mempool) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7330) 		ql_log(ql_log_fatal, NULL, 0xe06e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7331) 		    "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7332) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7333) 		goto out_plogi_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7336) 	qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7337) 	if (!qla_tgt_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7338) 		ql_log(ql_log_fatal, NULL, 0xe06f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7339) 		    "alloc_workqueue for qla_tgt_wq failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7340) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7341) 		goto out_cmd_mempool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7343) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7344) 	 * Return 1 to signal that initiator-mode is being disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7345) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7346) 	return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7348) out_cmd_mempool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7349) 	mempool_destroy(qla_tgt_mgmt_cmd_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7350) out_plogi_cachep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7351) 	kmem_cache_destroy(qla_tgt_plogi_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7352) out_mgmt_cmd_cachep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7353) 	kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7354) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7357) void qlt_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7359) 	if (!QLA_TGT_MODE_ENABLED())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7360) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7362) 	destroy_workqueue(qla_tgt_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7363) 	mempool_destroy(qla_tgt_mgmt_cmd_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7364) 	kmem_cache_destroy(qla_tgt_plogi_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7365) 	kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7366) }