Thomas Gleixner | 8e8e69d | 2019-05-29 07:17:59 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2 | /* |
| 3 | * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx |
| 4 | * |
| 5 | * based on qla2x00t.c code: |
| 6 | * |
| 7 | * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net> |
| 8 | * Copyright (C) 2004 - 2005 Leonid Stoljar |
| 9 | * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us> |
| 10 | * Copyright (C) 2006 - 2010 ID7 Ltd. |
| 11 | * |
| 12 | * Forward port and refactoring to modern qla2xxx and target/configfs |
| 13 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 14 | * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org> |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/types.h> |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 20 | #include <linux/blkdev.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/workqueue.h> |
| 26 | #include <asm/unaligned.h> |
| 27 | #include <scsi/scsi.h> |
| 28 | #include <scsi/scsi_host.h> |
| 29 | #include <scsi/scsi_tcq.h> |
| 30 | #include <target/target_core_base.h> |
| 31 | #include <target/target_core_fabric.h> |
| 32 | |
| 33 | #include "qla_def.h" |
| 34 | #include "qla_target.h" |
| 35 | |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 36 | static int ql2xtgt_tape_enable; |
| 37 | module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR); |
| 38 | MODULE_PARM_DESC(ql2xtgt_tape_enable, |
| 39 | "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER."); |
| 40 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 41 | static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED; |
| 42 | module_param(qlini_mode, charp, S_IRUGO); |
| 43 | MODULE_PARM_DESC(qlini_mode, |
| 44 | "Determines when initiator mode will be enabled. Possible values: " |
| 45 | "\"exclusive\" - initiator mode will be enabled on load, " |
| 46 | "disabled on enabling target mode and then on disabling target mode " |
| 47 | "enabled back; " |
| 48 | "\"disabled\" - initiator mode will never be enabled; " |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 49 | "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated " |
| 50 | "when ready " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 51 | "\"enabled\" (default) - initiator mode will always stay enabled."); |
| 52 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 53 | static int ql_dm_tgt_ex_pct = 0; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 54 | module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR); |
| 55 | MODULE_PARM_DESC(ql_dm_tgt_ex_pct, |
| 56 | "For Dual Mode (qlini_mode=dual), this parameter determines " |
| 57 | "the percentage of exchanges/cmds FW will allocate resources " |
| 58 | "for Target mode."); |
| 59 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 60 | int ql2xuctrlirq = 1; |
| 61 | module_param(ql2xuctrlirq, int, 0644); |
| 62 | MODULE_PARM_DESC(ql2xuctrlirq, |
| 63 | "User to control IRQ placement via smp_affinity." |
| 64 | "Valid with qlini_mode=disabled." |
| 65 | "1(default): enable"); |
| 66 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 67 | int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 68 | |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 69 | static int qla_sam_status = SAM_STAT_BUSY; |
| 70 | static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */ |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 71 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 72 | /* |
| 73 | * From scsi/fc/fc_fcp.h |
| 74 | */ |
| 75 | enum fcp_resp_rsp_codes { |
| 76 | FCP_TMF_CMPL = 0, |
| 77 | FCP_DATA_LEN_INVALID = 1, |
| 78 | FCP_CMND_FIELDS_INVALID = 2, |
| 79 | FCP_DATA_PARAM_MISMATCH = 3, |
| 80 | FCP_TMF_REJECTED = 4, |
| 81 | FCP_TMF_FAILED = 5, |
| 82 | FCP_TMF_INVALID_LUN = 9, |
| 83 | }; |
| 84 | |
| 85 | /* |
| 86 | * fc_pri_ta from scsi/fc/fc_fcp.h |
| 87 | */ |
| 88 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ |
| 89 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ |
| 90 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 91 | #define FCP_PTA_ACA 4 /* auto. contingent allegiance */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 92 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ |
| 93 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ |
| 94 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ |
| 95 | |
| 96 | /* |
| 97 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which |
| 98 | * must be called under HW lock and could unlock/lock it inside. |
| 99 | * It isn't an issue, since in the current implementation on the time when |
| 100 | * those functions are called: |
| 101 | * |
| 102 | * - Either context is IRQ and only IRQ handler can modify HW data, |
| 103 | * including rings related fields, |
| 104 | * |
| 105 | * - Or access to target mode variables from struct qla_tgt doesn't |
| 106 | * cross those functions boundaries, except tgt_stop, which |
| 107 | * additionally protected by irq_cmd_count. |
| 108 | */ |
| 109 | /* Predefs for callbacks handed to qla2xxx LLD */ |
| 110 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 111 | struct atio_from_isp *pkt, uint8_t); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 112 | static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp, |
| 113 | response_t *pkt); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 114 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 115 | int fn, void *iocb, int flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 116 | static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 117 | *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 118 | static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 119 | struct atio_from_isp *atio, uint16_t status, int qfull); |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 120 | static void qlt_disable_vha(struct scsi_qla_host *vha); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 121 | static void qlt_clear_tgt_db(struct qla_tgt *tgt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 122 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 123 | struct imm_ntfy_from_isp *ntfy, |
| 124 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 125 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 126 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 127 | struct imm_ntfy_from_isp *imm, int ha_locked); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 128 | static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha, |
| 129 | fc_port_t *fcport, bool local); |
| 130 | void qlt_unreg_sess(struct fc_port *sess); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 131 | static void qlt_24xx_handle_abts(struct scsi_qla_host *, |
| 132 | struct abts_recv_from_24xx *); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 133 | static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *, |
| 134 | uint16_t); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 135 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t); |
| 136 | static inline uint32_t qlt_make_handle(struct qla_qpair *); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 137 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 138 | /* |
| 139 | * Global Variables |
| 140 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 141 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Quinn Tran | b5d1531 | 2017-08-30 10:16:49 -0700 | [diff] [blame] | 142 | struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 143 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 144 | static struct workqueue_struct *qla_tgt_wq; |
| 145 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 146 | static LIST_HEAD(qla_tgt_glist); |
| 147 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 148 | static const char *prot_op_str(u32 prot_op) |
| 149 | { |
| 150 | switch (prot_op) { |
| 151 | case TARGET_PROT_NORMAL: return "NORMAL"; |
| 152 | case TARGET_PROT_DIN_INSERT: return "DIN_INSERT"; |
| 153 | case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT"; |
| 154 | case TARGET_PROT_DIN_STRIP: return "DIN_STRIP"; |
| 155 | case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP"; |
| 156 | case TARGET_PROT_DIN_PASS: return "DIN_PASS"; |
| 157 | case TARGET_PROT_DOUT_PASS: return "DOUT_PASS"; |
| 158 | default: return "UNKNOWN"; |
| 159 | } |
| 160 | } |
| 161 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 162 | /* This API intentionally takes dest as a parameter, rather than returning |
| 163 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 164 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 165 | { |
| 166 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 167 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 168 | /* memory barrier */ |
| 169 | wmb(); |
| 170 | } |
| 171 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 172 | /* Might release hw lock, then reaquire!! */ |
| 173 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 174 | { |
| 175 | /* Send marker if required */ |
| 176 | if (unlikely(vha->marker_needed != 0)) { |
| 177 | int rc = qla2x00_issue_marker(vha, vha_locked); |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 178 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 179 | if (rc != QLA_SUCCESS) { |
| 180 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 181 | "qla_target(%d): issue_marker() failed\n", |
| 182 | vha->vp_idx); |
| 183 | } |
| 184 | return rc; |
| 185 | } |
| 186 | return QLA_SUCCESS; |
| 187 | } |
| 188 | |
| 189 | static inline |
| 190 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
| 191 | uint8_t *d_id) |
| 192 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 193 | struct scsi_qla_host *host; |
| 194 | uint32_t key = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 195 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 196 | if ((vha->d_id.b.area == d_id[1]) && (vha->d_id.b.domain == d_id[0]) && |
| 197 | (vha->d_id.b.al_pa == d_id[2])) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 198 | return vha; |
| 199 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 200 | key = (uint32_t)d_id[0] << 16; |
| 201 | key |= (uint32_t)d_id[1] << 8; |
| 202 | key |= (uint32_t)d_id[2]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 203 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 204 | host = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 205 | if (!host) |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 206 | ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 207 | "Unable to find host %06x\n", key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 208 | |
| 209 | return host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static inline |
| 213 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 214 | uint16_t vp_idx) |
| 215 | { |
| 216 | struct qla_hw_data *ha = vha->hw; |
| 217 | |
| 218 | if (vha->vp_idx == vp_idx) |
| 219 | return vha; |
| 220 | |
| 221 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 222 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 223 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 224 | |
| 225 | return NULL; |
| 226 | } |
| 227 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 228 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 229 | { |
| 230 | unsigned long flags; |
| 231 | |
| 232 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 233 | |
| 234 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 235 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 236 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 237 | vha->hw->tgt.num_pend_cmds; |
| 238 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 239 | } |
| 240 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 241 | { |
| 242 | unsigned long flags; |
| 243 | |
| 244 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 245 | vha->hw->tgt.num_pend_cmds--; |
| 246 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 247 | } |
| 248 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 249 | |
| 250 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 251 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 252 | { |
| 253 | struct qla_tgt_sess_op *u; |
| 254 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 255 | unsigned long flags; |
| 256 | |
| 257 | if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 258 | ql_dbg(ql_dbg_async, vha, 0x502c, |
| 259 | "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped", |
| 260 | vha->vp_idx); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 261 | goto out_term; |
| 262 | } |
| 263 | |
| 264 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 265 | if (u == NULL) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 266 | goto out_term; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 267 | |
| 268 | u->vha = vha; |
| 269 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 270 | INIT_LIST_HEAD(&u->cmd_list); |
| 271 | |
| 272 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 273 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 274 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 275 | |
| 276 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 277 | |
| 278 | out: |
| 279 | return; |
| 280 | |
| 281 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 282 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 283 | goto out; |
| 284 | } |
| 285 | |
| 286 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 287 | uint8_t ha_locked) |
| 288 | { |
| 289 | struct qla_tgt_sess_op *u, *t; |
| 290 | scsi_qla_host_t *host; |
| 291 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 292 | unsigned long flags; |
| 293 | uint8_t queued = 0; |
| 294 | |
| 295 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 296 | if (u->aborted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 297 | ql_dbg(ql_dbg_async, vha, 0x502e, |
| 298 | "Freeing unknown %s %p, because of Abort\n", |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 299 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 300 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 301 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 302 | goto abort; |
| 303 | } |
| 304 | |
| 305 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 306 | if (host != NULL) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 307 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 308 | "Requeuing unknown ATIO_TYPE7 %p\n", u); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 309 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 310 | } else if (tgt->tgt_stop) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 311 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 312 | "Freeing unknown %s %p, because tgt is being stopped\n", |
| 313 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 314 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 315 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 316 | } else { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 317 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 318 | "Reschedule u %p, vha %p, host %p\n", u, vha, host); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 319 | if (!queued) { |
| 320 | queued = 1; |
| 321 | schedule_delayed_work(&vha->unknown_atio_work, |
| 322 | 1); |
| 323 | } |
| 324 | continue; |
| 325 | } |
| 326 | |
| 327 | abort: |
| 328 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 329 | list_del(&u->cmd_list); |
| 330 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 331 | kfree(u); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 336 | { |
| 337 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 338 | struct scsi_qla_host, unknown_atio_work); |
| 339 | |
| 340 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 341 | } |
| 342 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 343 | static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 344 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 345 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 346 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 347 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 348 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 349 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 350 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 351 | switch (atio->u.raw.entry_type) { |
| 352 | case ATIO_TYPE7: |
| 353 | { |
| 354 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 355 | atio->u.isp24.fcp_hdr.d_id); |
| 356 | if (unlikely(NULL == host)) { |
| 357 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 358 | "qla_target(%d): Received ATIO_TYPE7 " |
| 359 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
| 360 | atio->u.isp24.fcp_hdr.d_id[0], |
| 361 | atio->u.isp24.fcp_hdr.d_id[1], |
| 362 | atio->u.isp24.fcp_hdr.d_id[2]); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 363 | |
| 364 | |
| 365 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 366 | break; |
| 367 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 368 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 369 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 370 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 371 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 372 | break; |
| 373 | } |
| 374 | |
| 375 | case IMMED_NOTIFY_TYPE: |
| 376 | { |
| 377 | struct scsi_qla_host *host = vha; |
| 378 | struct imm_ntfy_from_isp *entry = |
| 379 | (struct imm_ntfy_from_isp *)atio; |
| 380 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 381 | qlt_issue_marker(vha, ha_locked); |
| 382 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 383 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 384 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 385 | host = qlt_find_host_by_vp_idx(vha, |
| 386 | entry->u.isp24.vp_index); |
| 387 | if (unlikely(!host)) { |
| 388 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 389 | "qla_target(%d): Received " |
| 390 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 391 | "with unknown vp_index %d\n", |
| 392 | vha->vp_idx, entry->u.isp24.vp_index); |
| 393 | break; |
| 394 | } |
| 395 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 396 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 397 | break; |
| 398 | } |
| 399 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 400 | case VP_RPT_ID_IOCB_TYPE: |
| 401 | qla24xx_report_id_acquisition(vha, |
| 402 | (struct vp_rpt_id_entry_24xx *)atio); |
| 403 | break; |
| 404 | |
| 405 | case ABTS_RECV_24XX: |
| 406 | { |
| 407 | struct abts_recv_from_24xx *entry = |
| 408 | (struct abts_recv_from_24xx *)atio; |
| 409 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 410 | entry->vp_index); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 411 | unsigned long flags; |
| 412 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 413 | if (unlikely(!host)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 414 | ql_dbg(ql_dbg_tgt, vha, 0xe00a, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 415 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 416 | "received, with unknown vp_index %d\n", |
| 417 | vha->vp_idx, entry->vp_index); |
| 418 | break; |
| 419 | } |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 420 | if (!ha_locked) |
| 421 | spin_lock_irqsave(&host->hw->hardware_lock, flags); |
| 422 | qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio); |
| 423 | if (!ha_locked) |
| 424 | spin_unlock_irqrestore(&host->hw->hardware_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 425 | break; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 429 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 430 | default: |
| 431 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 432 | "qla_target(%d): Received unknown ATIO atio " |
| 433 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 434 | break; |
| 435 | } |
| 436 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 437 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 438 | } |
| 439 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 440 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, |
| 441 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 442 | { |
| 443 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 444 | case CTIO_CRC2: |
| 445 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 446 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 447 | vha->vp_idx, __func__); |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 448 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 449 | case CTIO_TYPE7: |
| 450 | { |
| 451 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 452 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 453 | entry->vp_index); |
| 454 | if (unlikely(!host)) { |
| 455 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 456 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 457 | "received, with unknown vp_index %d\n", |
| 458 | vha->vp_idx, entry->vp_index); |
| 459 | break; |
| 460 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 461 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 462 | break; |
| 463 | } |
| 464 | |
| 465 | case IMMED_NOTIFY_TYPE: |
| 466 | { |
| 467 | struct scsi_qla_host *host = vha; |
| 468 | struct imm_ntfy_from_isp *entry = |
| 469 | (struct imm_ntfy_from_isp *)pkt; |
| 470 | |
| 471 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 472 | if (unlikely(!host)) { |
| 473 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 474 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 475 | "received, with unknown vp_index %d\n", |
| 476 | vha->vp_idx, entry->u.isp24.vp_index); |
| 477 | break; |
| 478 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 479 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 480 | break; |
| 481 | } |
| 482 | |
| 483 | case NOTIFY_ACK_TYPE: |
| 484 | { |
| 485 | struct scsi_qla_host *host = vha; |
| 486 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 487 | |
| 488 | if (0xFF != entry->u.isp24.vp_index) { |
| 489 | host = qlt_find_host_by_vp_idx(vha, |
| 490 | entry->u.isp24.vp_index); |
| 491 | if (unlikely(!host)) { |
| 492 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 493 | "qla_target(%d): Response " |
| 494 | "pkt (NOTIFY_ACK_TYPE) " |
| 495 | "received, with unknown " |
| 496 | "vp_index %d\n", vha->vp_idx, |
| 497 | entry->u.isp24.vp_index); |
| 498 | break; |
| 499 | } |
| 500 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 501 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 502 | break; |
| 503 | } |
| 504 | |
| 505 | case ABTS_RECV_24XX: |
| 506 | { |
| 507 | struct abts_recv_from_24xx *entry = |
| 508 | (struct abts_recv_from_24xx *)pkt; |
| 509 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 510 | entry->vp_index); |
| 511 | if (unlikely(!host)) { |
| 512 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 513 | "qla_target(%d): Response pkt " |
| 514 | "(ABTS_RECV_24XX) received, with unknown " |
| 515 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 516 | break; |
| 517 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 518 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 519 | break; |
| 520 | } |
| 521 | |
| 522 | case ABTS_RESP_24XX: |
| 523 | { |
| 524 | struct abts_resp_to_24xx *entry = |
| 525 | (struct abts_resp_to_24xx *)pkt; |
| 526 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 527 | entry->vp_index); |
| 528 | if (unlikely(!host)) { |
| 529 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 530 | "qla_target(%d): Response pkt " |
| 531 | "(ABTS_RECV_24XX) received, with unknown " |
| 532 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 533 | break; |
| 534 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 535 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 536 | break; |
| 537 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 538 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 539 | qlt_response_pkt(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 540 | break; |
| 541 | } |
| 542 | |
| 543 | } |
| 544 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 545 | /* |
| 546 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 547 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 548 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 549 | struct imm_ntfy_from_isp *ntfy, int type) |
| 550 | { |
| 551 | struct qla_work_evt *e; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 552 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 553 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 554 | if (!e) |
| 555 | return QLA_FUNCTION_FAILED; |
| 556 | |
| 557 | e->u.nack.fcport = fcport; |
| 558 | e->u.nack.type = type; |
| 559 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 560 | return qla2x00_post_work(vha, e); |
| 561 | } |
| 562 | |
| 563 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 564 | void qla2x00_async_nack_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 565 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 566 | struct srb *sp = (struct srb *)s; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 567 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 568 | unsigned long flags; |
| 569 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 570 | ql_dbg(ql_dbg_disc, vha, 0x20f2, |
| 571 | "Async done-%s res %x %8phC type %d\n", |
| 572 | sp->name, res, sp->fcport->port_name, sp->type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 573 | |
| 574 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 575 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 576 | sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 577 | |
| 578 | switch (sp->type) { |
| 579 | case SRB_NACK_PLOGI: |
| 580 | sp->fcport->login_gen++; |
| 581 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 582 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 583 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 584 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 585 | break; |
| 586 | |
| 587 | case SRB_NACK_PRLI: |
| 588 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 589 | sp->fcport->deleted = 0; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 590 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 591 | |
| 592 | if (!sp->fcport->login_succ && |
| 593 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 594 | sp->fcport->login_succ = 1; |
| 595 | |
| 596 | vha->fcport_count++; |
Quinn Tran | 0aca778 | 2018-09-04 14:19:16 -0700 | [diff] [blame] | 597 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 598 | qla24xx_sched_upd_fcport(sp->fcport); |
Quinn Tran | 0aca778 | 2018-09-04 14:19:16 -0700 | [diff] [blame] | 599 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | 2952849 | 2018-05-01 09:01:45 -0700 | [diff] [blame] | 600 | } else { |
| 601 | sp->fcport->login_retry = 0; |
| 602 | sp->fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 603 | sp->fcport->deleted = 0; |
| 604 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 605 | } |
| 606 | break; |
| 607 | |
| 608 | case SRB_NACK_LOGO: |
| 609 | sp->fcport->login_gen++; |
| 610 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 611 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 612 | break; |
| 613 | } |
| 614 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 615 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 616 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 620 | struct imm_ntfy_from_isp *ntfy, int type) |
| 621 | { |
| 622 | int rval = QLA_FUNCTION_FAILED; |
| 623 | srb_t *sp; |
| 624 | char *c = NULL; |
| 625 | |
| 626 | fcport->flags |= FCF_ASYNC_SENT; |
| 627 | switch (type) { |
| 628 | case SRB_NACK_PLOGI: |
| 629 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 630 | c = "PLOGI"; |
| 631 | break; |
| 632 | case SRB_NACK_PRLI: |
| 633 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 634 | fcport->deleted = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 635 | c = "PRLI"; |
| 636 | break; |
| 637 | case SRB_NACK_LOGO: |
| 638 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 639 | c = "LOGO"; |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 644 | if (!sp) |
| 645 | goto done; |
| 646 | |
| 647 | sp->type = type; |
| 648 | sp->name = "nack"; |
| 649 | |
Ben Hutchings | e74e7d9 | 2018-03-20 21:36:14 +0000 | [diff] [blame] | 650 | sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 651 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 652 | |
| 653 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 654 | sp->done = qla2x00_async_nack_sp_done; |
| 655 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 656 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
| 657 | "Async-%s %8phC hndl %x %s\n", |
| 658 | sp->name, fcport->port_name, sp->handle, c); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 659 | |
Bill Kuzeja | f233e8c | 2019-02-14 10:52:29 -0500 | [diff] [blame] | 660 | rval = qla2x00_start_sp(sp); |
| 661 | if (rval != QLA_SUCCESS) |
| 662 | goto done_free_sp; |
| 663 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 664 | return rval; |
| 665 | |
| 666 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 667 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 668 | done: |
| 669 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 670 | return rval; |
| 671 | } |
| 672 | |
| 673 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 674 | { |
| 675 | fc_port_t *t; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 676 | |
| 677 | switch (e->u.nack.type) { |
| 678 | case SRB_NACK_PRLI: |
Quinn Tran | 1021f0b | 2019-01-24 23:23:45 -0800 | [diff] [blame] | 679 | t = e->u.nack.fcport; |
| 680 | flush_work(&t->del_work); |
| 681 | flush_work(&t->free_work); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 682 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 683 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 684 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 685 | if (t) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 686 | ql_log(ql_log_info, vha, 0xd034, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 687 | "%s create sess success %p", __func__, t); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 688 | /* create sess has an extra kref */ |
| 689 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 690 | } |
| 691 | break; |
| 692 | } |
| 693 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
Bart Van Assche | 845bbb0 | 2019-04-11 14:53:18 -0700 | [diff] [blame] | 694 | (struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 698 | { |
| 699 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 700 | struct qla_hw_data *ha = fcport->vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 701 | |
| 702 | if (fcport->se_sess) { |
| 703 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 704 | ha->tgt.tgt_ops->put_sess(fcport); |
| 705 | } else { |
| 706 | qlt_unreg_sess(fcport); |
| 707 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /* |
| 711 | * Called from qla2x00_reg_remote_port() |
| 712 | */ |
| 713 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 714 | { |
| 715 | struct qla_hw_data *ha = vha->hw; |
| 716 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 717 | struct fc_port *sess = fcport; |
| 718 | unsigned long flags; |
| 719 | |
| 720 | if (!vha->hw->tgt.tgt_ops) |
| 721 | return; |
| 722 | |
| 723 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 724 | if (tgt->tgt_stop) { |
| 725 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 726 | return; |
| 727 | } |
| 728 | |
| 729 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 730 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | if (!sess->se_sess) { |
| 735 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 736 | |
| 737 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 738 | sess = qlt_create_sess(vha, fcport, false); |
| 739 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 740 | |
| 741 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 742 | } else { |
| 743 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 744 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 749 | ql_dbg(ql_dbg_disc, vha, 0x2107, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 750 | "%s: kref_get fail sess %8phC \n", |
| 751 | __func__, sess->port_name); |
| 752 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 753 | return; |
| 754 | } |
| 755 | |
| 756 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 757 | "qla_target(%u): %ssession for port %8phC " |
| 758 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 759 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 760 | |
| 761 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 762 | "Reappeared sess %p\n", sess); |
| 763 | |
| 764 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 765 | fcport->loop_id, |
| 766 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 767 | } |
| 768 | |
| 769 | if (sess && sess->local) { |
| 770 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 771 | "qla_target(%u): local session for " |
| 772 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 773 | fcport->port_name, sess->loop_id); |
| 774 | sess->local = 0; |
| 775 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 776 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 777 | |
| 778 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 779 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 780 | |
| 781 | /* |
| 782 | * This is a zero-base ref-counting solution, since hardware_lock |
| 783 | * guarantees that ref_count is not modified concurrently. |
| 784 | * Upon successful return content of iocb is undefined |
| 785 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 786 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 787 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 788 | struct imm_ntfy_from_isp *iocb) |
| 789 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 790 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 791 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 792 | lockdep_assert_held(&vha->hw->hardware_lock); |
| 793 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 794 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 795 | if (pla->id.b24 == id->b24) { |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 796 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d, |
| 797 | "%s %d %8phC Term INOT due to new INOT", |
| 798 | __func__, __LINE__, |
| 799 | pla->iocb.u.isp24.port_name); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 800 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 801 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 802 | return pla; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 807 | if (!pla) { |
| 808 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 809 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 810 | vha->vp_idx); |
| 811 | return NULL; |
| 812 | } |
| 813 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 814 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 815 | pla->id = *id; |
| 816 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 817 | |
| 818 | return pla; |
| 819 | } |
| 820 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 821 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 822 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 823 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 824 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 825 | port_id_t port_id; |
| 826 | uint16_t loop_id; |
| 827 | fc_port_t *fcport = pla->fcport; |
| 828 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 829 | BUG_ON(!pla->ref_count); |
| 830 | pla->ref_count--; |
| 831 | |
| 832 | if (pla->ref_count) |
| 833 | return; |
| 834 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 835 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 836 | "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x" |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 837 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 838 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 839 | iocb->u.isp24.port_id[0], |
| 840 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 841 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 842 | |
| 843 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 844 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 845 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 846 | port_id.b.rsvd_1 = 0; |
| 847 | |
| 848 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 849 | |
| 850 | fcport->loop_id = loop_id; |
| 851 | fcport->d_id = port_id; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 852 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 853 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 854 | else |
| 855 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 856 | |
| 857 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 858 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 859 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 860 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 861 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 862 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 863 | |
| 864 | list_del(&pla->list); |
| 865 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 866 | } |
| 867 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 868 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 869 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 870 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 871 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 872 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 873 | /* Inc ref_count first because link might already be pointing at pla */ |
| 874 | pla->ref_count++; |
| 875 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 876 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 877 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 878 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 879 | sess, link, sess->port_name, |
| 880 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 881 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 882 | pla->ref_count, pla, link); |
| 883 | |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 884 | if (link == QLT_PLOGI_LINK_CONFLICT) { |
| 885 | switch (sess->disc_state) { |
| 886 | case DSC_DELETED: |
| 887 | case DSC_DELETE_PEND: |
| 888 | pla->ref_count--; |
| 889 | return; |
| 890 | default: |
| 891 | break; |
| 892 | } |
| 893 | } |
| 894 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 895 | if (sess->plogi_link[link]) |
| 896 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 897 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 898 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 899 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 900 | |
| 901 | sess->plogi_link[link] = pla; |
| 902 | } |
| 903 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 904 | typedef struct { |
| 905 | /* These fields must be initialized by the caller */ |
| 906 | port_id_t id; |
| 907 | /* |
| 908 | * number of cmds dropped while we were waiting for |
| 909 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 910 | * triggered by a command, otherwise, to 0 |
| 911 | */ |
| 912 | int cmd_count; |
| 913 | |
| 914 | /* These fields are used by callee */ |
| 915 | struct list_head list; |
| 916 | } qlt_port_logo_t; |
| 917 | |
| 918 | static void |
| 919 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 920 | { |
| 921 | qlt_port_logo_t *tmp; |
| 922 | int res; |
| 923 | |
| 924 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 925 | |
| 926 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 927 | if (tmp->id.b24 == logo->id.b24) { |
| 928 | tmp->cmd_count += logo->cmd_count; |
| 929 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 930 | return; |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | list_add_tail(&logo->list, &vha->logo_list); |
| 935 | |
| 936 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 937 | |
| 938 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 939 | |
| 940 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 941 | list_del(&logo->list); |
| 942 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 943 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 944 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 945 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 946 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 947 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 948 | } |
| 949 | |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 950 | void qlt_free_session_done(struct work_struct *work) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 951 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 952 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 953 | free_work); |
| 954 | struct qla_tgt *tgt = sess->tgt; |
| 955 | struct scsi_qla_host *vha = sess->vha; |
| 956 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 957 | unsigned long flags; |
| 958 | bool logout_started = false; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 959 | scsi_qla_host_t *base_vha; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 960 | struct qlt_plogi_ack_t *own = |
| 961 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 962 | |
| 963 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 964 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 965 | " s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n", |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 966 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 967 | sess->d_id.b.domain, sess->d_id.b.area, sess->d_id.b.al_pa, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 968 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 969 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 970 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 971 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Quinn Tran | 2137490 | 2019-04-23 14:52:35 -0700 | [diff] [blame] | 972 | qla2x00_mark_device_lost(vha, sess, 0, 0); |
| 973 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 974 | if (sess->send_els_logo) { |
| 975 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 976 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 977 | logo.id = sess->d_id; |
| 978 | logo.cmd_count = 0; |
Quinn Tran | cb97f2c | 2018-08-02 13:16:51 -0700 | [diff] [blame] | 979 | if (!own) |
| 980 | qlt_send_first_logo(vha, &logo); |
Himanshu Madhani | a239034 | 2018-01-22 12:04:20 -0800 | [diff] [blame] | 981 | sess->send_els_logo = 0; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 982 | } |
| 983 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 984 | if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 985 | int rc; |
| 986 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 987 | if (!own || |
| 988 | (own && |
| 989 | (own->iocb.u.isp24.status_subcode == ELS_PLOGI))) { |
| 990 | rc = qla2x00_post_async_logout_work(vha, sess, |
| 991 | NULL); |
| 992 | if (rc != QLA_SUCCESS) |
| 993 | ql_log(ql_log_warn, vha, 0xf085, |
| 994 | "Schedule logo failed sess %p rc %d\n", |
| 995 | sess, rc); |
| 996 | else |
| 997 | logout_started = true; |
| 998 | } else if (own && (own->iocb.u.isp24.status_subcode == |
| 999 | ELS_PRLI) && ha->flags.rida_fmt2) { |
| 1000 | rc = qla2x00_post_async_prlo_work(vha, sess, |
| 1001 | NULL); |
| 1002 | if (rc != QLA_SUCCESS) |
| 1003 | ql_log(ql_log_warn, vha, 0xf085, |
| 1004 | "Schedule PRLO failed sess %p rc %d\n", |
| 1005 | sess, rc); |
| 1006 | else |
| 1007 | logout_started = true; |
| 1008 | } |
Quinn Tran | baf23ed | 2019-06-16 08:05:53 -0700 | [diff] [blame] | 1009 | } /* if sess->logout_on_delete */ |
| 1010 | |
| 1011 | if (sess->nvme_flag & NVME_FLAG_REGISTERED && |
| 1012 | !(sess->nvme_flag & NVME_FLAG_DELETING)) { |
| 1013 | sess->nvme_flag |= NVME_FLAG_DELETING; |
| 1014 | qla_nvme_unregister_remote_port(sess); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1015 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1016 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1017 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1018 | /* |
| 1019 | * Release the target session for FC Nexus from fabric module code. |
| 1020 | */ |
| 1021 | if (sess->se_sess != NULL) |
| 1022 | ha->tgt.tgt_ops->free_session(sess); |
| 1023 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1024 | if (logout_started) { |
| 1025 | bool traced = false; |
| 1026 | |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 1027 | while (!READ_ONCE(sess->logout_completed)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1028 | if (!traced) { |
| 1029 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 1030 | "%s: waiting for sess %p logout\n", |
| 1031 | __func__, sess); |
| 1032 | traced = true; |
| 1033 | } |
| 1034 | msleep(100); |
| 1035 | } |
| 1036 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1037 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1038 | "%s: sess %p logout completed\n", __func__, sess); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | if (sess->logo_ack_needed) { |
| 1042 | sess->logo_ack_needed = 0; |
| 1043 | qla24xx_async_notify_ack(vha, sess, |
| 1044 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1047 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1048 | if (sess->se_sess) { |
| 1049 | sess->se_sess = NULL; |
| 1050 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 1051 | tgt->sess_count--; |
| 1052 | } |
| 1053 | |
| 1054 | sess->disc_state = DSC_DELETED; |
| 1055 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1056 | sess->deleted = QLA_SESS_DELETED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1057 | |
| 1058 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1059 | vha->fcport_count--; |
| 1060 | sess->login_succ = 0; |
| 1061 | } |
| 1062 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 1063 | qla2x00_clear_loop_id(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1064 | |
| 1065 | if (sess->conflict) { |
| 1066 | sess->conflict->login_pause = 0; |
| 1067 | sess->conflict = NULL; |
| 1068 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1069 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1070 | } |
| 1071 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1072 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1073 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1074 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1075 | struct imm_ntfy_from_isp *iocb; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 1076 | |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 1077 | own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1078 | |
| 1079 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1080 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1081 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1082 | "se_sess %p / sess %p port %8phC is gone," |
| 1083 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1084 | sess->se_sess, sess, sess->port_name, |
| 1085 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1086 | own ? own->ref_count : -1, |
| 1087 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1088 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1089 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1090 | } else { |
| 1091 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1092 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1093 | sess->se_sess, sess, sess->port_name, |
| 1094 | own ? "releasing own PLOGI" : |
| 1095 | "no own PLOGI pending", |
| 1096 | own ? own->ref_count : -1); |
| 1097 | } |
| 1098 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1099 | if (own) { |
| 1100 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1101 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1102 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1103 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1104 | } |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1105 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1106 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1107 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1108 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1109 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1110 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1111 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1112 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1113 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1114 | |
| 1115 | if (vha->fcport_count == 0) |
| 1116 | wake_up_all(&vha->fcport_waitQ); |
| 1117 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1118 | base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1119 | |
| 1120 | sess->free_pending = 0; |
| 1121 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1122 | if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags)) |
| 1123 | return; |
| 1124 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1125 | if ((!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) { |
| 1126 | switch (vha->host->active_mode) { |
| 1127 | case MODE_INITIATOR: |
| 1128 | case MODE_DUAL: |
| 1129 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1130 | qla2xxx_wake_dpc(vha); |
| 1131 | break; |
| 1132 | case MODE_TARGET: |
| 1133 | default: |
| 1134 | /* no-op */ |
| 1135 | break; |
| 1136 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1137 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1138 | } |
| 1139 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1140 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1141 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1142 | { |
| 1143 | struct scsi_qla_host *vha = sess->vha; |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1144 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1145 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1146 | ql_dbg(ql_dbg_disc, sess->vha, 0x210a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1147 | "%s sess %p for deletion %8phC\n", |
| 1148 | __func__, sess, sess->port_name); |
| 1149 | |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1150 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
| 1151 | if (sess->free_pending) { |
| 1152 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1153 | return; |
| 1154 | } |
| 1155 | sess->free_pending = 1; |
| 1156 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1157 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1158 | if (sess->se_sess) |
| 1159 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1160 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1161 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1162 | sess->disc_state = DSC_DELETE_PEND; |
| 1163 | sess->last_rscn_gen = sess->rscn_gen; |
| 1164 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1165 | |
Quinn Tran | baf23ed | 2019-06-16 08:05:53 -0700 | [diff] [blame] | 1166 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 1167 | schedule_work(&sess->free_work); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1168 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1169 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1170 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1171 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1172 | { |
| 1173 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1174 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1175 | uint16_t loop_id; |
| 1176 | int res = 0; |
| 1177 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1178 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1179 | |
| 1180 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1181 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1182 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1183 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1184 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1185 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1186 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1187 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1188 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1189 | sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1190 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1194 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1195 | if (!sess) { |
| 1196 | res = -ESRCH; |
| 1197 | return res; |
| 1198 | } |
| 1199 | |
| 1200 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1201 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1202 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1203 | mcmd, loop_id); |
| 1204 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1205 | return qlt_issue_task_mgmt(sess, 0, mcmd, iocb, QLA24XX_MGMT_SEND_NACK); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1206 | } |
| 1207 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1208 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1209 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1210 | if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1211 | sess->logout_on_delete = 0; |
| 1212 | sess->logo_ack_needed = 0; |
| 1213 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1214 | } |
| 1215 | } |
| 1216 | |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1217 | void qlt_schedule_sess_for_deletion(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1218 | { |
| 1219 | struct qla_tgt *tgt = sess->tgt; |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1220 | unsigned long flags; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1221 | u16 sec; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1222 | |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1223 | switch (sess->disc_state) { |
| 1224 | case DSC_DELETE_PEND: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1225 | return; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1226 | case DSC_DELETED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1227 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1228 | wake_up_all(&tgt->waitQ); |
| 1229 | if (sess->vha->fcport_count == 0) |
| 1230 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1231 | |
| 1232 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1233 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1234 | return; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1235 | break; |
| 1236 | case DSC_UPD_FCPORT: |
| 1237 | /* |
| 1238 | * This port is not done reporting to upper layer. |
| 1239 | * let it finish |
| 1240 | */ |
| 1241 | sess->next_disc_state = DSC_DELETE_PEND; |
| 1242 | sec = jiffies_to_msecs(jiffies - |
| 1243 | sess->jiffies_at_registration)/1000; |
| 1244 | if (sess->sec_since_registration < sec && sec && !(sec % 5)) { |
| 1245 | sess->sec_since_registration = sec; |
| 1246 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 1247 | "%s %8phC : Slow Rport registration(%d Sec)\n", |
| 1248 | __func__, sess->port_name, sec); |
| 1249 | } |
| 1250 | return; |
| 1251 | default: |
| 1252 | break; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1253 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1254 | |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1255 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1256 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1257 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1258 | return; |
| 1259 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1260 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1261 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1262 | |
| 1263 | sess->disc_state = DSC_DELETE_PEND; |
| 1264 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1265 | qla24xx_chk_fcp_state(sess); |
| 1266 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1267 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
Quinn Tran | 5c64005 | 2018-09-26 22:05:14 -0700 | [diff] [blame] | 1268 | "Scheduling sess %p for deletion %8phC\n", |
| 1269 | sess, sess->port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1270 | |
Quinn Tran | a01c77d | 2017-12-04 14:44:58 -0800 | [diff] [blame] | 1271 | INIT_WORK(&sess->del_work, qla24xx_delete_sess_fn); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1272 | WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work)); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1273 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1274 | |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1275 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1276 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1277 | struct fc_port *sess; |
| 1278 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1279 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1280 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1281 | if (sess->se_sess) |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1282 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1283 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1284 | |
| 1285 | /* At this point tgt could be already dead */ |
| 1286 | } |
| 1287 | |
| 1288 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 1289 | uint16_t *loop_id) |
| 1290 | { |
| 1291 | struct qla_hw_data *ha = vha->hw; |
| 1292 | dma_addr_t gid_list_dma; |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1293 | struct gid_list_info *gid_list, *gid; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1294 | int res, rc, i; |
| 1295 | uint16_t entries; |
| 1296 | |
| 1297 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1298 | &gid_list_dma, GFP_KERNEL); |
| 1299 | if (!gid_list) { |
| 1300 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1301 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1302 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1303 | return -ENOMEM; |
| 1304 | } |
| 1305 | |
| 1306 | /* Get list of logged in devices */ |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1307 | rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1308 | if (rc != QLA_SUCCESS) { |
| 1309 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1310 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1311 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1312 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1313 | goto out_free_id_list; |
| 1314 | } |
| 1315 | |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1316 | gid = gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1317 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1318 | for (i = 0; i < entries; i++) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1319 | if ((gid->al_pa == s_id[2]) && |
| 1320 | (gid->area == s_id[1]) && |
| 1321 | (gid->domain == s_id[0])) { |
| 1322 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1323 | res = 0; |
| 1324 | break; |
| 1325 | } |
Bart Van Assche | 9c17c3b | 2019-08-08 20:01:35 -0700 | [diff] [blame] | 1326 | gid = (void *)gid + ha->gid_list_info_size; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | out_free_id_list: |
| 1330 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1331 | gid_list, gid_list_dma); |
| 1332 | return res; |
| 1333 | } |
| 1334 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1335 | /* |
| 1336 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1337 | * Caller must put it. |
| 1338 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1339 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1340 | struct scsi_qla_host *vha, |
| 1341 | fc_port_t *fcport, |
| 1342 | bool local) |
| 1343 | { |
| 1344 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1345 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1346 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1347 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1348 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1349 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1350 | |
| 1351 | if (fcport->se_sess) { |
| 1352 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1353 | ql_dbg(ql_dbg_disc, vha, 0x20f6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1354 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1355 | __func__, sess->port_name); |
| 1356 | return NULL; |
| 1357 | } |
| 1358 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1359 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1360 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1361 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1362 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1363 | /* |
| 1364 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1365 | * session eventually ends and release corresponding nport handle. |
| 1366 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1367 | * code will adjust these flags as necessary. |
| 1368 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1369 | sess->logout_on_delete = 1; |
| 1370 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1371 | sess->logout_completed = 0; |
| 1372 | |
| 1373 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1374 | &fcport->port_name[0], sess) < 0) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1375 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1376 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1377 | vha->vp_idx, fcport->port_name); |
| 1378 | return NULL; |
| 1379 | } else { |
| 1380 | kref_init(&fcport->sess_kref); |
| 1381 | /* |
| 1382 | * Take an extra reference to ->sess_kref here to handle |
| 1383 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1384 | */ |
| 1385 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1386 | ql_dbg(ql_dbg_disc, vha, 0x20f7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1387 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1388 | __func__, sess->port_name); |
| 1389 | return NULL; |
| 1390 | } |
| 1391 | |
| 1392 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1393 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1394 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1395 | |
| 1396 | qlt_do_generation_tick(vha, &sess->generation); |
| 1397 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1398 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1399 | |
| 1400 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1401 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1402 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1403 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1404 | |
| 1405 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1406 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1407 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1408 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1409 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1410 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1411 | |
| 1412 | return sess; |
| 1413 | } |
| 1414 | |
| 1415 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1416 | * max_gen - specifies maximum session generation |
| 1417 | * at which this deletion requestion is still valid |
| 1418 | */ |
| 1419 | void |
| 1420 | qlt_fc_port_deleted(struct scsi_qla_host *vha, fc_port_t *fcport, int max_gen) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1421 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1422 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1423 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1424 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1425 | |
| 1426 | if (!vha->hw->tgt.tgt_ops) |
| 1427 | return; |
| 1428 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1429 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1430 | return; |
| 1431 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1432 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1433 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1434 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1435 | return; |
| 1436 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1437 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1438 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1439 | return; |
| 1440 | } |
| 1441 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1442 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1443 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1444 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1445 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1446 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1447 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1448 | sess->generation); |
| 1449 | return; |
| 1450 | } |
| 1451 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1452 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1453 | |
| 1454 | sess->local = 1; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1455 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1456 | qlt_schedule_sess_for_deletion(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1460 | { |
| 1461 | struct qla_hw_data *ha = tgt->ha; |
| 1462 | unsigned long flags; |
| 1463 | int res; |
| 1464 | /* |
| 1465 | * We need to protect against race, when tgt is freed before or |
| 1466 | * inside wake_up() |
| 1467 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1468 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1469 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1470 | "tgt %p, sess_count=%d\n", |
| 1471 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1472 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1473 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1474 | |
| 1475 | return res; |
| 1476 | } |
| 1477 | |
| 1478 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1479 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1480 | { |
| 1481 | struct scsi_qla_host *vha = tgt->vha; |
| 1482 | struct qla_hw_data *ha = tgt->ha; |
| 1483 | unsigned long flags; |
| 1484 | |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1485 | mutex_lock(&ha->optrom_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1486 | mutex_lock(&qla_tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1487 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1488 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1489 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1490 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1491 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1492 | mutex_unlock(&ha->optrom_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1493 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1496 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1497 | vha->host_no, vha); |
| 1498 | /* |
| 1499 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1500 | * Lock is needed, because we still can get an incoming packet. |
| 1501 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1502 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1503 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1504 | qlt_clear_tgt_db(tgt); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1505 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1506 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1507 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1508 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1509 | "Waiting for sess works (tgt %p)", tgt); |
| 1510 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1511 | while (!list_empty(&tgt->sess_works_list)) { |
| 1512 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1513 | flush_scheduled_work(); |
| 1514 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1515 | } |
| 1516 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1517 | |
| 1518 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1519 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1520 | |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1521 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1522 | |
| 1523 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1524 | if (!ha->flags.host_shutting_down && |
| 1525 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1526 | qlt_disable_vha(vha); |
| 1527 | |
| 1528 | /* Wait for sessions to clear out (just in case) */ |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1529 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1530 | mutex_unlock(&ha->optrom_mutex); |
| 1531 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1532 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1533 | } |
| 1534 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1535 | |
| 1536 | /* Called by tcm_qla2xxx configfs code */ |
| 1537 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1538 | { |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1539 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1540 | |
| 1541 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1542 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1543 | "Already in tgt->tgt_stopped state\n"); |
| 1544 | dump_stack(); |
| 1545 | return; |
| 1546 | } |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1547 | if (!tgt->tgt_stop) { |
| 1548 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
| 1549 | "%s: phase1 stop is not completed\n", __func__); |
| 1550 | dump_stack(); |
| 1551 | return; |
| 1552 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1553 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1554 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1555 | tgt->tgt_stop = 0; |
| 1556 | tgt->tgt_stopped = 1; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1557 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1558 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1559 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00c, "Stop of tgt %p finished\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1560 | tgt); |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 1561 | |
| 1562 | switch (vha->qlini_mode) { |
| 1563 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 1564 | vha->flags.online = 1; |
| 1565 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1566 | break; |
| 1567 | default: |
| 1568 | break; |
| 1569 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1570 | } |
| 1571 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1572 | |
| 1573 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1574 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1575 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1576 | scsi_qla_host_t *vha = tgt->vha; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1577 | void *node; |
| 1578 | u64 key = 0; |
| 1579 | u16 i; |
| 1580 | struct qla_qpair_hint *h; |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1581 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1582 | |
Bart Van Assche | 8b21900 | 2019-08-08 20:01:38 -0700 | [diff] [blame] | 1583 | if (!tgt->tgt_stop && !tgt->tgt_stopped) |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1584 | qlt_stop_phase1(tgt); |
| 1585 | |
Bart Van Assche | 8b21900 | 2019-08-08 20:01:38 -0700 | [diff] [blame] | 1586 | if (!tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1587 | qlt_stop_phase2(tgt); |
| 1588 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1589 | for (i = 0; i < vha->hw->max_qpairs + 1; i++) { |
| 1590 | unsigned long flags; |
| 1591 | |
| 1592 | h = &tgt->qphints[i]; |
| 1593 | if (h->qpair) { |
| 1594 | spin_lock_irqsave(h->qpair->qp_lock_ptr, flags); |
| 1595 | list_del(&h->hint_elem); |
| 1596 | spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags); |
| 1597 | h->qpair = NULL; |
| 1598 | } |
| 1599 | } |
| 1600 | kfree(tgt->qphints); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1601 | mutex_lock(&qla_tgt_mutex); |
| 1602 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
| 1603 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1604 | |
| 1605 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 1606 | btree_remove64(&tgt->lun_qpair_map, key); |
| 1607 | |
| 1608 | btree_destroy64(&tgt->lun_qpair_map); |
| 1609 | |
Sawan Chandak | 3be63b1e | 2017-12-04 14:45:04 -0800 | [diff] [blame] | 1610 | if (vha->vp_idx) |
| 1611 | if (ha->tgt.tgt_ops && |
| 1612 | ha->tgt.tgt_ops->remove_target && |
| 1613 | vha->vha_tgt.target_lport_ptr) |
| 1614 | ha->tgt.tgt_ops->remove_target(vha); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1615 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1616 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1617 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1618 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1619 | "Release of tgt %p finished\n", tgt); |
| 1620 | |
| 1621 | kfree(tgt); |
| 1622 | } |
| 1623 | |
| 1624 | /* ha->hardware_lock supposed to be held on entry */ |
| 1625 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1626 | const void *param, unsigned int param_size) |
| 1627 | { |
| 1628 | struct qla_tgt_sess_work_param *prm; |
| 1629 | unsigned long flags; |
| 1630 | |
| 1631 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1632 | if (!prm) { |
| 1633 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1634 | "qla_target(%d): Unable to create session " |
| 1635 | "work, command will be refused", 0); |
| 1636 | return -ENOMEM; |
| 1637 | } |
| 1638 | |
| 1639 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1640 | "Scheduling work (type %d, prm %p)" |
| 1641 | " to find session for param %p (size %d, tgt %p)\n", |
| 1642 | type, prm, param, param_size, tgt); |
| 1643 | |
| 1644 | prm->type = type; |
| 1645 | memcpy(&prm->tm_iocb, param, param_size); |
| 1646 | |
| 1647 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1648 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1649 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1650 | |
| 1651 | schedule_work(&tgt->sess_work); |
| 1652 | |
| 1653 | return 0; |
| 1654 | } |
| 1655 | |
| 1656 | /* |
| 1657 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1658 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1659 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1660 | struct imm_ntfy_from_isp *ntfy, |
| 1661 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1662 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1663 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1664 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1665 | struct qla_hw_data *ha = vha->hw; |
| 1666 | request_t *pkt; |
| 1667 | struct nack_to_isp *nack; |
| 1668 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 1669 | if (!ha->flags.fw_started) |
| 1670 | return; |
| 1671 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1672 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1673 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1674 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1675 | if (!pkt) { |
| 1676 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1677 | "qla_target(%d): %s failed: unable to allocate " |
| 1678 | "request packet\n", vha->vp_idx, __func__); |
| 1679 | return; |
| 1680 | } |
| 1681 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1682 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1683 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1684 | |
| 1685 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1686 | pkt->entry_count = 1; |
| 1687 | |
| 1688 | nack = (struct nack_to_isp *)pkt; |
| 1689 | nack->ox_id = ntfy->ox_id; |
| 1690 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1691 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1692 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1693 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1694 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1695 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1696 | } |
| 1697 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1698 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1699 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1700 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1701 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1702 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1703 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1704 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1705 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1706 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1707 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1708 | |
| 1709 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1710 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1711 | vha->vp_idx, nack->u.isp24.status); |
| 1712 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1713 | /* Memory Barrier */ |
| 1714 | wmb(); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1715 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1716 | } |
| 1717 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1718 | static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd) |
| 1719 | { |
| 1720 | struct scsi_qla_host *vha = mcmd->vha; |
| 1721 | struct qla_hw_data *ha = vha->hw; |
| 1722 | struct abts_resp_to_24xx *resp; |
| 1723 | uint32_t f_ctl, h; |
| 1724 | uint8_t *p; |
| 1725 | int rc; |
| 1726 | struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts; |
| 1727 | struct qla_qpair *qpair = mcmd->qpair; |
| 1728 | |
| 1729 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1730 | "Sending task mgmt ABTS response (ha=%p, status=%x)\n", |
| 1731 | ha, mcmd->fc_tm_rsp); |
| 1732 | |
| 1733 | rc = qlt_check_reserve_free_req(qpair, 1); |
| 1734 | if (rc) { |
| 1735 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1736 | "qla_target(%d): %s failed: unable to allocate request packet\n", |
| 1737 | vha->vp_idx, __func__); |
| 1738 | return -EAGAIN; |
| 1739 | } |
| 1740 | |
| 1741 | resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr; |
| 1742 | memset(resp, 0, sizeof(*resp)); |
| 1743 | |
| 1744 | h = qlt_make_handle(qpair); |
| 1745 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 1746 | /* |
| 1747 | * CTIO type 7 from the firmware doesn't provide a way to |
| 1748 | * know the initiator's LOOP ID, hence we can't find |
| 1749 | * the session and, so, the command. |
| 1750 | */ |
| 1751 | return -EAGAIN; |
| 1752 | } else { |
| 1753 | qpair->req->outstanding_cmds[h] = (srb_t *)mcmd; |
| 1754 | } |
| 1755 | |
| 1756 | resp->handle = MAKE_HANDLE(qpair->req->id, h); |
| 1757 | resp->entry_type = ABTS_RESP_24XX; |
| 1758 | resp->entry_count = 1; |
| 1759 | resp->nport_handle = abts->nport_handle; |
| 1760 | resp->vp_index = vha->vp_idx; |
| 1761 | resp->sof_type = abts->sof_type; |
| 1762 | resp->exchange_address = abts->exchange_address; |
| 1763 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
| 1764 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
| 1765 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1766 | F_CTL_SEQ_INITIATIVE); |
| 1767 | p = (uint8_t *)&f_ctl; |
| 1768 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1769 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1770 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1771 | |
| 1772 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1773 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1774 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1775 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1776 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1777 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1778 | |
| 1779 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1780 | if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) { |
| 1781 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1782 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1783 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1784 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1785 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1786 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1787 | } else { |
| 1788 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1789 | resp->payload.ba_rjt.reason_code = |
| 1790 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1791 | /* Other bytes are zero */ |
| 1792 | } |
| 1793 | |
| 1794 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
| 1795 | |
| 1796 | /* Memory Barrier */ |
| 1797 | wmb(); |
| 1798 | if (qpair->reqq_start_iocbs) |
| 1799 | qpair->reqq_start_iocbs(qpair); |
| 1800 | else |
| 1801 | qla2x00_start_iocbs(vha, qpair->req); |
| 1802 | |
| 1803 | return rc; |
| 1804 | } |
| 1805 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1806 | /* |
| 1807 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1808 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1809 | static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1810 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1811 | bool ids_reversed) |
| 1812 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1813 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1814 | struct qla_hw_data *ha = vha->hw; |
| 1815 | struct abts_resp_to_24xx *resp; |
| 1816 | uint32_t f_ctl; |
| 1817 | uint8_t *p; |
| 1818 | |
| 1819 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1820 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1821 | ha, abts, status); |
| 1822 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1823 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, |
| 1824 | NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1825 | if (!resp) { |
| 1826 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1827 | "qla_target(%d): %s failed: unable to allocate " |
| 1828 | "request packet", vha->vp_idx, __func__); |
| 1829 | return; |
| 1830 | } |
| 1831 | |
| 1832 | resp->entry_type = ABTS_RESP_24XX; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1833 | resp->handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1834 | resp->entry_count = 1; |
| 1835 | resp->nport_handle = abts->nport_handle; |
| 1836 | resp->vp_index = vha->vp_idx; |
| 1837 | resp->sof_type = abts->sof_type; |
| 1838 | resp->exchange_address = abts->exchange_address; |
| 1839 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1840 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1841 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1842 | F_CTL_SEQ_INITIATIVE); |
| 1843 | p = (uint8_t *)&f_ctl; |
| 1844 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1845 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1846 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1847 | if (ids_reversed) { |
| 1848 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1849 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1850 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1851 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1852 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1853 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1854 | } else { |
| 1855 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1856 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1857 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1858 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1859 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1860 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1861 | } |
| 1862 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1863 | if (status == FCP_TMF_CMPL) { |
| 1864 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1865 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1866 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1867 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1868 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1869 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1870 | } else { |
| 1871 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1872 | resp->payload.ba_rjt.reason_code = |
| 1873 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1874 | /* Other bytes are zero */ |
| 1875 | } |
| 1876 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1877 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1878 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1879 | /* Memory Barrier */ |
| 1880 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 1881 | if (qpair->reqq_start_iocbs) |
| 1882 | qpair->reqq_start_iocbs(qpair); |
| 1883 | else |
| 1884 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | /* |
| 1888 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1889 | */ |
| 1890 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1891 | struct qla_qpair *qpair, response_t *pkt, struct qla_tgt_mgmt_cmd *mcmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1892 | { |
| 1893 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1894 | u16 tmp; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1895 | struct abts_recv_from_24xx *entry; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1896 | |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1897 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1898 | if (ctio == NULL) { |
| 1899 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1900 | "qla_target(%d): %s failed: unable to allocate " |
| 1901 | "request packet\n", vha->vp_idx, __func__); |
| 1902 | return; |
| 1903 | } |
| 1904 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1905 | if (mcmd) |
| 1906 | /* abts from remote port */ |
| 1907 | entry = &mcmd->orig_iocb.abts; |
| 1908 | else |
| 1909 | /* abts from this driver. */ |
| 1910 | entry = (struct abts_recv_from_24xx *)pkt; |
| 1911 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1912 | /* |
| 1913 | * We've got on entrance firmware's response on by us generated |
| 1914 | * ABTS response. So, in it ID fields are reversed. |
| 1915 | */ |
| 1916 | |
| 1917 | ctio->entry_type = CTIO_TYPE7; |
| 1918 | ctio->entry_count = 1; |
| 1919 | ctio->nport_handle = entry->nport_handle; |
| 1920 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1921 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1922 | ctio->vp_index = vha->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1923 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1924 | tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1925 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1926 | if (mcmd) { |
| 1927 | ctio->initiator_id[0] = entry->fcp_hdr_le.s_id[0]; |
| 1928 | ctio->initiator_id[1] = entry->fcp_hdr_le.s_id[1]; |
| 1929 | ctio->initiator_id[2] = entry->fcp_hdr_le.s_id[2]; |
| 1930 | |
| 1931 | if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) |
| 1932 | tmp |= (mcmd->abort_io_attr << 9); |
| 1933 | else if (qpair->retry_term_cnt & 1) |
| 1934 | tmp |= (0x4 << 9); |
| 1935 | } else { |
| 1936 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1937 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1938 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1939 | |
| 1940 | if (qpair->retry_term_cnt & 1) |
| 1941 | tmp |= (0x4 << 9); |
| 1942 | } |
| 1943 | ctio->u.status1.flags = cpu_to_le16(tmp); |
| 1944 | ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id; |
| 1945 | |
| 1946 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1947 | "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n", |
| 1948 | le16_to_cpu(ctio->u.status1.flags), |
| 1949 | le16_to_cpu(ctio->u.status1.ox_id), |
| 1950 | (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1951 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1952 | /* Memory Barrier */ |
| 1953 | wmb(); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1954 | if (qpair->reqq_start_iocbs) |
| 1955 | qpair->reqq_start_iocbs(qpair); |
| 1956 | else |
| 1957 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1958 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1959 | if (mcmd) |
| 1960 | qlt_build_abts_resp_iocb(mcmd); |
| 1961 | else |
| 1962 | qlt_24xx_send_abts_resp(qpair, |
| 1963 | (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1964 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /* drop cmds for the given lun |
| 1968 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1969 | * XXX does not go through the list of other port (which may have cmds |
| 1970 | * for the same lun) |
| 1971 | */ |
| 1972 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1973 | u64 lun, uint8_t *s_id) |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1974 | { |
| 1975 | struct qla_tgt_sess_op *op; |
| 1976 | struct qla_tgt_cmd *cmd; |
| 1977 | uint32_t key; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1978 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1979 | |
| 1980 | key = sid_to_key(s_id); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1981 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1982 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1983 | uint32_t op_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1984 | u64 op_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1985 | |
| 1986 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1987 | op_lun = scsilun_to_int( |
| 1988 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1989 | if (op_key == key && op_lun == lun) |
| 1990 | op->aborted = true; |
| 1991 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1992 | |
| 1993 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1994 | uint32_t op_key; |
| 1995 | u64 op_lun; |
| 1996 | |
| 1997 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1998 | op_lun = scsilun_to_int( |
| 1999 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 2000 | if (op_key == key && op_lun == lun) |
| 2001 | op->aborted = true; |
| 2002 | } |
| 2003 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2004 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 2005 | uint32_t cmd_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 2006 | u64 cmd_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2007 | |
| 2008 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 2009 | cmd_lun = scsilun_to_int( |
| 2010 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 2011 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 2012 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2013 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 2014 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2015 | } |
| 2016 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2017 | static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha, |
| 2018 | uint64_t unpacked_lun) |
| 2019 | { |
| 2020 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 2021 | struct qla_qpair_hint *h = NULL; |
| 2022 | |
| 2023 | if (vha->flags.qpairs_available) { |
| 2024 | h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun); |
| 2025 | if (!h) |
| 2026 | h = &tgt->qphints[0]; |
| 2027 | } else { |
| 2028 | h = &tgt->qphints[0]; |
| 2029 | } |
| 2030 | |
| 2031 | return h; |
| 2032 | } |
| 2033 | |
| 2034 | static void qlt_do_tmr_work(struct work_struct *work) |
| 2035 | { |
| 2036 | struct qla_tgt_mgmt_cmd *mcmd = |
| 2037 | container_of(work, struct qla_tgt_mgmt_cmd, work); |
| 2038 | struct qla_hw_data *ha = mcmd->vha->hw; |
| 2039 | int rc = EIO; |
| 2040 | uint32_t tag; |
| 2041 | unsigned long flags; |
| 2042 | |
| 2043 | switch (mcmd->tmr_func) { |
| 2044 | case QLA_TGT_ABTS: |
| 2045 | tag = mcmd->orig_iocb.abts.exchange_addr_to_abort; |
| 2046 | break; |
| 2047 | default: |
| 2048 | tag = 0; |
| 2049 | break; |
| 2050 | } |
| 2051 | |
| 2052 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun, |
| 2053 | mcmd->tmr_func, tag); |
| 2054 | |
| 2055 | if (rc != 0) { |
| 2056 | spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags); |
| 2057 | switch (mcmd->tmr_func) { |
| 2058 | case QLA_TGT_ABTS: |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2059 | mcmd->fc_tm_rsp = FCP_TMF_REJECTED; |
| 2060 | qlt_build_abts_resp_iocb(mcmd); |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2061 | break; |
| 2062 | case QLA_TGT_LUN_RESET: |
| 2063 | case QLA_TGT_CLEAR_TS: |
| 2064 | case QLA_TGT_ABORT_TS: |
| 2065 | case QLA_TGT_CLEAR_ACA: |
| 2066 | case QLA_TGT_TARGET_RESET: |
| 2067 | qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio, |
| 2068 | qla_sam_status); |
| 2069 | break; |
| 2070 | |
| 2071 | case QLA_TGT_ABORT_ALL: |
| 2072 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 2073 | case QLA_TGT_NEXUS_LOSS: |
| 2074 | qlt_send_notify_ack(mcmd->qpair, |
| 2075 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
| 2076 | break; |
| 2077 | } |
| 2078 | spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags); |
| 2079 | |
| 2080 | ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052, |
| 2081 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 2082 | mcmd->vha->vp_idx, rc); |
| 2083 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2084 | } |
| 2085 | } |
| 2086 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2087 | /* ha->hardware_lock supposed to be held on entry */ |
| 2088 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2089 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2090 | { |
| 2091 | struct qla_hw_data *ha = vha->hw; |
| 2092 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2093 | struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0]; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 2094 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2095 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 2096 | "qla_target(%d): task abort (tag=%d)\n", |
| 2097 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 2098 | |
| 2099 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 2100 | if (mcmd == NULL) { |
| 2101 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 2102 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 2103 | vha->vp_idx, __func__); |
| 2104 | return -ENOMEM; |
| 2105 | } |
| 2106 | memset(mcmd, 0, sizeof(*mcmd)); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2107 | mcmd->cmd_type = TYPE_TGT_TMCMD; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2108 | mcmd->sess = sess; |
| 2109 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2110 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 2111 | mcmd->tmr_func = QLA_TGT_ABTS; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2112 | mcmd->qpair = h->qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2113 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2114 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 2115 | /* |
| 2116 | * LUN is looked up by target-core internally based on the passed |
| 2117 | * abts->exchange_addr_to_abort tag. |
| 2118 | */ |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2119 | mcmd->se_cmd.cpuid = h->cpuid; |
| 2120 | |
| 2121 | if (ha->tgt.tgt_ops->find_cmd_by_tag) { |
| 2122 | struct qla_tgt_cmd *abort_cmd; |
| 2123 | |
| 2124 | abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess, |
| 2125 | abts->exchange_addr_to_abort); |
| 2126 | if (abort_cmd && abort_cmd->qpair) { |
| 2127 | mcmd->qpair = abort_cmd->qpair; |
| 2128 | mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2129 | mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr; |
| 2130 | mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2131 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2132 | } |
| 2133 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2134 | INIT_WORK(&mcmd->work, qlt_do_tmr_work); |
| 2135 | queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work); |
| 2136 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2137 | return 0; |
| 2138 | } |
| 2139 | |
| 2140 | /* |
| 2141 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2142 | */ |
| 2143 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 2144 | struct abts_recv_from_24xx *abts) |
| 2145 | { |
| 2146 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2147 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2148 | uint32_t tag = abts->exchange_addr_to_abort; |
| 2149 | uint8_t s_id[3]; |
| 2150 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2151 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2152 | |
| 2153 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 2154 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 2155 | "qla_target(%d): ABTS: Abort Sequence not " |
| 2156 | "supported\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2157 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2158 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2159 | return; |
| 2160 | } |
| 2161 | |
| 2162 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 2163 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 2164 | "qla_target(%d): ABTS: Unknown Exchange " |
| 2165 | "Address received\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2166 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2167 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2168 | return; |
| 2169 | } |
| 2170 | |
| 2171 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 2172 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 2173 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 2174 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 2175 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 2176 | |
| 2177 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 2178 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 2179 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 2180 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2181 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2182 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 2183 | if (!sess) { |
| 2184 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
Colin Ian King | 03fea73 | 2018-03-19 10:53:41 +0000 | [diff] [blame] | 2185 | "qla_target(%d): task abort for non-existent session\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2186 | vha->vp_idx); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2187 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2188 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 2189 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2190 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2191 | return; |
| 2192 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2193 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2194 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2195 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2196 | if (sess->deleted) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2197 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2198 | false); |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 2199 | return; |
| 2200 | } |
| 2201 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2202 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 2203 | if (rc != 0) { |
| 2204 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 2205 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 2206 | vha->vp_idx, rc); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2207 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2208 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2209 | return; |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | /* |
| 2214 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2215 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2216 | static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2217 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 2218 | { |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2219 | struct scsi_qla_host *ha = mcmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2220 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 2221 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2222 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2223 | |
| 2224 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 2225 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 2226 | ha, atio, resp_code); |
| 2227 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2228 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2229 | ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2230 | if (ctio == NULL) { |
| 2231 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 2232 | "qla_target(%d): %s failed: unable to allocate " |
| 2233 | "request packet\n", ha->vp_idx, __func__); |
| 2234 | return; |
| 2235 | } |
| 2236 | |
| 2237 | ctio->entry_type = CTIO_TYPE7; |
| 2238 | ctio->entry_count = 1; |
| 2239 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 2240 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2241 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2242 | ctio->vp_index = ha->vp_idx; |
| 2243 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2244 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2245 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2246 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2247 | temp = (atio->u.isp24.attr << 9)| |
| 2248 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2249 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2250 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2251 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2252 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2253 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2254 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2255 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2256 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2257 | /* Memory Barrier */ |
| 2258 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2259 | if (qpair->reqq_start_iocbs) |
| 2260 | qpair->reqq_start_iocbs(qpair); |
| 2261 | else |
| 2262 | qla2x00_start_iocbs(ha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2266 | { |
| 2267 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2268 | } |
| 2269 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2270 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2271 | /* |
| 2272 | * ha->hardware_lock supposed to be held on entry. Might drop it, then |
| 2273 | * reacquire |
| 2274 | */ |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2275 | void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2276 | uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq) |
| 2277 | { |
| 2278 | struct atio_from_isp *atio = &cmd->atio; |
| 2279 | struct ctio7_to_24xx *ctio; |
| 2280 | uint16_t temp; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2281 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2282 | |
| 2283 | ql_dbg(ql_dbg_tgt_dif, vha, 0x3066, |
| 2284 | "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, " |
| 2285 | "sense_key=%02x, asc=%02x, ascq=%02x", |
| 2286 | vha, atio, scsi_status, sense_key, asc, ascq); |
| 2287 | |
| 2288 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); |
| 2289 | if (!ctio) { |
| 2290 | ql_dbg(ql_dbg_async, vha, 0x3067, |
| 2291 | "qla2x00t(%ld): %s failed: unable to allocate request packet", |
| 2292 | vha->host_no, __func__); |
| 2293 | goto out; |
| 2294 | } |
| 2295 | |
| 2296 | ctio->entry_type = CTIO_TYPE7; |
| 2297 | ctio->entry_count = 1; |
| 2298 | ctio->handle = QLA_TGT_SKIP_HANDLE; |
| 2299 | ctio->nport_handle = cmd->sess->loop_id; |
| 2300 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
| 2301 | ctio->vp_index = vha->vp_idx; |
| 2302 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2303 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2304 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2305 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2306 | temp = (atio->u.isp24.attr << 9) | |
| 2307 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2308 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2309 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2310 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
| 2311 | ctio->u.status1.scsi_status = |
| 2312 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status); |
| 2313 | ctio->u.status1.response_len = cpu_to_le16(18); |
| 2314 | ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
| 2315 | |
| 2316 | if (ctio->u.status1.residual != 0) |
| 2317 | ctio->u.status1.scsi_status |= |
| 2318 | cpu_to_le16(SS_RESIDUAL_UNDER); |
| 2319 | |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2320 | /* Fixed format sense data. */ |
| 2321 | ctio->u.status1.sense_data[0] = 0x70; |
| 2322 | ctio->u.status1.sense_data[2] = sense_key; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2323 | /* Additional sense length */ |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2324 | ctio->u.status1.sense_data[7] = 0xa; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2325 | /* ASC and ASCQ */ |
Bart Van Assche | a861b49 | 2019-04-17 14:44:42 -0700 | [diff] [blame] | 2326 | ctio->u.status1.sense_data[12] = asc; |
| 2327 | ctio->u.status1.sense_data[13] = ascq; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2328 | |
| 2329 | /* Memory Barrier */ |
| 2330 | wmb(); |
| 2331 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2332 | if (qpair->reqq_start_iocbs) |
| 2333 | qpair->reqq_start_iocbs(qpair); |
| 2334 | else |
| 2335 | qla2x00_start_iocbs(vha, qpair->req); |
| 2336 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2337 | out: |
| 2338 | return; |
| 2339 | } |
| 2340 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2341 | /* callback from target fabric module code */ |
| 2342 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2343 | { |
| 2344 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2345 | struct qla_hw_data *ha = vha->hw; |
| 2346 | unsigned long flags; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2347 | struct qla_qpair *qpair = mcmd->qpair; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2348 | bool free_mcmd = true; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2349 | |
| 2350 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2351 | "TM response mcmd (%p) status %#x state %#x", |
| 2352 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2353 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2354 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2355 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2356 | if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2357 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2358 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2359 | * previous life, just abort the processing. |
| 2360 | */ |
| 2361 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2362 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2363 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2364 | mcmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2365 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2366 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2367 | return; |
| 2368 | } |
| 2369 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2370 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2371 | switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) { |
| 2372 | case ELS_LOGO: |
| 2373 | case ELS_PRLO: |
| 2374 | case ELS_TPRLO: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2375 | ql_dbg(ql_dbg_disc, vha, 0x2106, |
Bart Van Assche | 19ce192 | 2019-04-17 14:44:11 -0700 | [diff] [blame] | 2376 | "TM response logo %8phC status %#x state %#x", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2377 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2378 | mcmd->flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 2379 | qlt_schedule_sess_for_deletion(mcmd->sess); |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2380 | break; |
| 2381 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2382 | qlt_send_notify_ack(vha->hw->base_qpair, |
| 2383 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2384 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2385 | } |
| 2386 | } else { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2387 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) { |
| 2388 | qlt_build_abts_resp_iocb(mcmd); |
| 2389 | free_mcmd = false; |
| 2390 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2391 | qlt_24xx_send_task_mgmt_ctio(qpair, mcmd, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2392 | mcmd->fc_tm_rsp); |
| 2393 | } |
| 2394 | /* |
| 2395 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2396 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2397 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2398 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2399 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2400 | * qlt_xmit_tm_rsp() returns here.. |
| 2401 | */ |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2402 | if (free_mcmd) |
| 2403 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2404 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2405 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2406 | } |
| 2407 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2408 | |
| 2409 | /* No locks */ |
| 2410 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2411 | { |
| 2412 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2413 | |
| 2414 | BUG_ON(cmd->sg_cnt == 0); |
| 2415 | |
| 2416 | prm->sg = (struct scatterlist *)cmd->sg; |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2417 | prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2418 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2419 | if (unlikely(prm->seg_cnt == 0)) |
| 2420 | goto out_err; |
| 2421 | |
| 2422 | prm->cmd->sg_mapped = 1; |
| 2423 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2424 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2425 | /* |
| 2426 | * If greater than four sg entries then we need to allocate |
| 2427 | * the continuation entries |
| 2428 | */ |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2429 | if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2430 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2431 | QLA_TGT_DATASEGS_PER_CMD_24XX, |
| 2432 | QLA_TGT_DATASEGS_PER_CONT_24XX); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2433 | } else { |
| 2434 | /* DIF */ |
| 2435 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2436 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2437 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2438 | prm->tot_dsds = prm->seg_cnt; |
| 2439 | } else |
| 2440 | prm->tot_dsds = prm->seg_cnt; |
| 2441 | |
| 2442 | if (cmd->prot_sg_cnt) { |
| 2443 | prm->prot_sg = cmd->prot_sg; |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2444 | prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2445 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2446 | cmd->dma_data_direction); |
| 2447 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2448 | goto out_err; |
| 2449 | |
| 2450 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2451 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2452 | /* Dif Bundling not support here */ |
| 2453 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2454 | cmd->blk_sz); |
| 2455 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2456 | } else |
| 2457 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2458 | } |
| 2459 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2460 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2461 | return 0; |
| 2462 | |
| 2463 | out_err: |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2464 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2465 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2466 | 0, prm->cmd->sg_cnt); |
| 2467 | return -1; |
| 2468 | } |
| 2469 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2470 | static void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2471 | { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2472 | struct qla_hw_data *ha; |
| 2473 | struct qla_qpair *qpair; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 2474 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2475 | if (!cmd->sg_mapped) |
| 2476 | return; |
| 2477 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2478 | qpair = cmd->qpair; |
| 2479 | |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2480 | dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt, |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2481 | cmd->dma_data_direction); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2482 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2483 | |
| 2484 | if (cmd->prot_sg_cnt) |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2485 | dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2486 | cmd->dma_data_direction); |
| 2487 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2488 | if (!cmd->ctx) |
| 2489 | return; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2490 | ha = vha->hw; |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2491 | if (cmd->ctx_dsd_alloced) |
| 2492 | qla2x00_clean_dsd_pool(ha, cmd->ctx); |
| 2493 | |
| 2494 | dma_pool_free(ha->dl_dma_pool, cmd->ctx, cmd->ctx->crc_ctx_dma); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2495 | } |
| 2496 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2497 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2498 | uint32_t req_cnt) |
| 2499 | { |
Quinn Tran | d63b328 | 2017-06-02 09:12:07 -0700 | [diff] [blame] | 2500 | uint32_t cnt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2501 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2502 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2503 | if (req->cnt < (req_cnt + 2)) { |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 2504 | cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr : |
| 2505 | RD_REG_DWORD_RELAXED(req->req_q_out)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2506 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2507 | if (req->ring_index < cnt) |
| 2508 | req->cnt = cnt - req->ring_index; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2509 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2510 | req->cnt = req->length - (req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2511 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2512 | if (unlikely(req->cnt < (req_cnt + 2))) |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2513 | return -EAGAIN; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2514 | } |
| 2515 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2516 | req->cnt -= req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2517 | |
| 2518 | return 0; |
| 2519 | } |
| 2520 | |
| 2521 | /* |
| 2522 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2523 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2524 | static inline void *qlt_get_req_pkt(struct req_que *req) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2525 | { |
| 2526 | /* Adjust ring index. */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2527 | req->ring_index++; |
| 2528 | if (req->ring_index == req->length) { |
| 2529 | req->ring_index = 0; |
| 2530 | req->ring_ptr = req->ring; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2531 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2532 | req->ring_ptr++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2533 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2534 | return (cont_entry_t *)req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2538 | static inline uint32_t qlt_make_handle(struct qla_qpair *qpair) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2539 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2540 | uint32_t h; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2541 | int index; |
| 2542 | uint8_t found = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2543 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2544 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2545 | h = req->current_outstanding_cmd; |
| 2546 | |
| 2547 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 2548 | h++; |
| 2549 | if (h == req->num_outstanding_cmds) |
| 2550 | h = 1; |
| 2551 | |
| 2552 | if (h == QLA_TGT_SKIP_HANDLE) |
| 2553 | continue; |
| 2554 | |
| 2555 | if (!req->outstanding_cmds[h]) { |
| 2556 | found = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2557 | break; |
| 2558 | } |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2559 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2560 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2561 | if (found) { |
| 2562 | req->current_outstanding_cmd = h; |
| 2563 | } else { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2564 | ql_dbg(ql_dbg_io, qpair->vha, 0x305b, |
| 2565 | "qla_target(%d): Ran out of empty cmd slots\n", |
| 2566 | qpair->vha->vp_idx); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2567 | h = QLA_TGT_NULL_HANDLE; |
| 2568 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2569 | |
| 2570 | return h; |
| 2571 | } |
| 2572 | |
| 2573 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2574 | static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair, |
| 2575 | struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2576 | { |
| 2577 | uint32_t h; |
| 2578 | struct ctio7_to_24xx *pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2579 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2580 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2581 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2582 | pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2583 | prm->pkt = pkt; |
| 2584 | memset(pkt, 0, sizeof(*pkt)); |
| 2585 | |
| 2586 | pkt->entry_type = CTIO_TYPE7; |
| 2587 | pkt->entry_count = (uint8_t)prm->req_cnt; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2588 | pkt->vp_index = prm->cmd->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2589 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2590 | h = qlt_make_handle(qpair); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2591 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2592 | /* |
| 2593 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2594 | * know the initiator's LOOP ID, hence we can't find |
| 2595 | * the session and, so, the command. |
| 2596 | */ |
| 2597 | return -EAGAIN; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 2598 | } else |
| 2599 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2600 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2601 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2602 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
| 2603 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2604 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2605 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2606 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2607 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2608 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2609 | temp = atio->u.isp24.attr << 9; |
| 2610 | pkt->u.status0.flags |= cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2611 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2612 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2613 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2614 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2615 | return 0; |
| 2616 | } |
| 2617 | |
| 2618 | /* |
| 2619 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2620 | * that there is sufficient amount of request entries to not drop it. |
| 2621 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2622 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2623 | { |
| 2624 | int cnt; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2625 | struct dsd64 *cur_dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2626 | |
| 2627 | /* Build continuation packets */ |
| 2628 | while (prm->seg_cnt > 0) { |
| 2629 | cont_a64_entry_t *cont_pkt64 = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2630 | (cont_a64_entry_t *)qlt_get_req_pkt( |
| 2631 | prm->cmd->qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2632 | |
| 2633 | /* |
| 2634 | * Make sure that from cont_pkt64 none of |
| 2635 | * 64-bit specific fields used for 32-bit |
| 2636 | * addressing. Cast to (cont_entry_t *) for |
| 2637 | * that. |
| 2638 | */ |
| 2639 | |
| 2640 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2641 | |
| 2642 | cont_pkt64->entry_count = 1; |
| 2643 | cont_pkt64->sys_define = 0; |
| 2644 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2645 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2646 | cur_dsd = cont_pkt64->dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2647 | |
| 2648 | /* Load continuation entry data segments */ |
| 2649 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2650 | cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2651 | cnt++, prm->seg_cnt--) { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2652 | append_dsd64(&cur_dsd, prm->sg); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2653 | prm->sg = sg_next(prm->sg); |
| 2654 | } |
| 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | /* |
| 2659 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2660 | * that there is sufficient amount of request entries to not drop it. |
| 2661 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2662 | static void qlt_load_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2663 | { |
| 2664 | int cnt; |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2665 | struct dsd64 *cur_dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2666 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2667 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2668 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2669 | |
| 2670 | /* Setup packet address segment pointer */ |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2671 | cur_dsd = &pkt24->u.status0.dsd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2672 | |
| 2673 | /* Set total data segment count */ |
| 2674 | if (prm->seg_cnt) |
| 2675 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2676 | |
| 2677 | if (prm->seg_cnt == 0) { |
| 2678 | /* No data transfer */ |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2679 | cur_dsd->address = 0; |
| 2680 | cur_dsd->length = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2681 | return; |
| 2682 | } |
| 2683 | |
| 2684 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2685 | |
| 2686 | /* Load command entry data segments */ |
| 2687 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2688 | (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2689 | cnt++, prm->seg_cnt--) { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 2690 | append_dsd64(&cur_dsd, prm->sg); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2691 | prm->sg = sg_next(prm->sg); |
| 2692 | } |
| 2693 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2694 | qlt_load_cont_data_segments(prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2698 | { |
| 2699 | return cmd->bufflen > 0; |
| 2700 | } |
| 2701 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2702 | static void qlt_print_dif_err(struct qla_tgt_prm *prm) |
| 2703 | { |
| 2704 | struct qla_tgt_cmd *cmd; |
| 2705 | struct scsi_qla_host *vha; |
| 2706 | |
| 2707 | /* asc 0x10=dif error */ |
| 2708 | if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) { |
| 2709 | cmd = prm->cmd; |
| 2710 | vha = cmd->vha; |
| 2711 | /* ASCQ */ |
| 2712 | switch (prm->sense_buffer[13]) { |
| 2713 | case 1: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2714 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2715 | "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2716 | "se_cmd=%p tag[%x]", |
| 2717 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2718 | cmd->atio.u.isp24.exchange_addr); |
| 2719 | break; |
| 2720 | case 2: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2721 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2722 | "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2723 | "se_cmd=%p tag[%x]", |
| 2724 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2725 | cmd->atio.u.isp24.exchange_addr); |
| 2726 | break; |
| 2727 | case 3: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2728 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2729 | "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2730 | "se_cmd=%p tag[%x]", |
| 2731 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2732 | cmd->atio.u.isp24.exchange_addr); |
| 2733 | break; |
| 2734 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2735 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe010, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2736 | "BE detected Dif ERR: lba[%llx|%lld] len[%x] " |
| 2737 | "se_cmd=%p tag[%x]", |
| 2738 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2739 | cmd->atio.u.isp24.exchange_addr); |
| 2740 | break; |
| 2741 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2742 | ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2743 | } |
| 2744 | } |
| 2745 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2746 | /* |
| 2747 | * Called without ha->hardware_lock held |
| 2748 | */ |
| 2749 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2750 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2751 | uint32_t *full_req_cnt) |
| 2752 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2753 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2754 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2755 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2756 | prm->cmd = cmd; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2757 | prm->tgt = cmd->tgt; |
| 2758 | prm->pkt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2759 | prm->rq_result = scsi_status; |
| 2760 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2761 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2762 | prm->sg = NULL; |
| 2763 | prm->seg_cnt = -1; |
| 2764 | prm->req_cnt = 1; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2765 | prm->residual = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2766 | prm->add_status_pkt = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2767 | prm->prot_sg = NULL; |
| 2768 | prm->prot_seg_cnt = 0; |
| 2769 | prm->tot_dsds = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2770 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2771 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2772 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2773 | return -EAGAIN; |
| 2774 | } |
| 2775 | |
| 2776 | *full_req_cnt = prm->req_cnt; |
| 2777 | |
| 2778 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2779 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2780 | ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2781 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2782 | prm->residual, se_cmd->tag, |
| 2783 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2784 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2785 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2786 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2787 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2788 | ql_dbg_qp(ql_dbg_io, qpair, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2789 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2790 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2791 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2792 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2793 | } |
| 2794 | |
| 2795 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2796 | /* |
| 2797 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2798 | * ignored in *xmit_response() below |
| 2799 | */ |
| 2800 | if (qlt_has_data(cmd)) { |
| 2801 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2802 | (IS_FWI2_CAPABLE(cmd->vha->hw) && |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2803 | (prm->rq_result != 0))) { |
| 2804 | prm->add_status_pkt = 1; |
| 2805 | (*full_req_cnt)++; |
| 2806 | } |
| 2807 | } |
| 2808 | } |
| 2809 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2810 | return 0; |
| 2811 | } |
| 2812 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2813 | static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd, |
| 2814 | int sending_sense) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2815 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2816 | if (cmd->qpair->enable_class_2) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2817 | return 0; |
| 2818 | |
| 2819 | if (sending_sense) |
| 2820 | return cmd->conf_compl_supported; |
| 2821 | else |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2822 | return cmd->qpair->enable_explicit_conf && |
| 2823 | cmd->conf_compl_supported; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2824 | } |
| 2825 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2826 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2827 | struct qla_tgt_prm *prm) |
| 2828 | { |
| 2829 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2830 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2831 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2832 | if (qlt_need_explicit_conf(prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2833 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2834 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2835 | CTIO7_FLAGS_CONFORM_REQ); |
| 2836 | } |
| 2837 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2838 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2839 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2840 | int i; |
| 2841 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2842 | if (qlt_need_explicit_conf(prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2843 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2844 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2845 | "Skipping EXPLICIT_CONFORM and " |
| 2846 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2847 | "non GOOD status\n"); |
| 2848 | goto skip_explict_conf; |
| 2849 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2850 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2851 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2852 | CTIO7_FLAGS_CONFORM_REQ); |
| 2853 | } |
| 2854 | skip_explict_conf: |
| 2855 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2856 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2857 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2858 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2859 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2860 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2861 | ctio->u.status1.sense_length = |
| 2862 | cpu_to_le16(prm->sense_buffer_len); |
| 2863 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2864 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2865 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2866 | |
| 2867 | qlt_print_dif_err(prm); |
| 2868 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2869 | } else { |
| 2870 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2871 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2872 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2873 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2874 | ctio->u.status1.sense_length = 0; |
| 2875 | memset(ctio->u.status1.sense_data, 0, |
| 2876 | sizeof(ctio->u.status1.sense_data)); |
| 2877 | } |
| 2878 | |
| 2879 | /* Sense with len > 24, is it possible ??? */ |
| 2880 | } |
| 2881 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2882 | static inline int |
| 2883 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2884 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2885 | switch (se_cmd->prot_op) { |
| 2886 | case TARGET_PROT_DOUT_INSERT: |
| 2887 | case TARGET_PROT_DIN_STRIP: |
| 2888 | if (ql2xenablehba_err_chk >= 1) |
| 2889 | return 1; |
| 2890 | break; |
| 2891 | case TARGET_PROT_DOUT_PASS: |
| 2892 | case TARGET_PROT_DIN_PASS: |
| 2893 | if (ql2xenablehba_err_chk >= 2) |
| 2894 | return 1; |
| 2895 | break; |
| 2896 | case TARGET_PROT_DIN_INSERT: |
| 2897 | case TARGET_PROT_DOUT_STRIP: |
| 2898 | return 1; |
| 2899 | default: |
| 2900 | break; |
| 2901 | } |
| 2902 | return 0; |
| 2903 | } |
| 2904 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2905 | static inline int |
| 2906 | qla_tgt_ref_mask_check(struct se_cmd *se_cmd) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2907 | { |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2908 | switch (se_cmd->prot_op) { |
| 2909 | case TARGET_PROT_DIN_INSERT: |
| 2910 | case TARGET_PROT_DOUT_INSERT: |
| 2911 | case TARGET_PROT_DIN_STRIP: |
| 2912 | case TARGET_PROT_DOUT_STRIP: |
| 2913 | case TARGET_PROT_DIN_PASS: |
| 2914 | case TARGET_PROT_DOUT_PASS: |
| 2915 | return 1; |
| 2916 | default: |
| 2917 | return 0; |
| 2918 | } |
| 2919 | return 0; |
| 2920 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2921 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2922 | /* |
| 2923 | * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command |
| 2924 | */ |
| 2925 | static void |
| 2926 | qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx, |
| 2927 | uint16_t *pfw_prot_opts) |
| 2928 | { |
| 2929 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2930 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2931 | scsi_qla_host_t *vha = cmd->tgt->vha; |
| 2932 | struct qla_hw_data *ha = vha->hw; |
| 2933 | uint32_t t32 = 0; |
| 2934 | |
| 2935 | /* |
| 2936 | * wait till Mode Sense/Select cmd, modepage Ah, subpage 2 |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2937 | * have been immplemented by TCM, before AppTag is avail. |
| 2938 | * Look for modesense_handlers[] |
| 2939 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2940 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2941 | ctx->app_tag_mask[0] = 0x0; |
| 2942 | ctx->app_tag_mask[1] = 0x0; |
| 2943 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2944 | if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2945 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2946 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2947 | *pfw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2948 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2949 | *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2950 | } |
| 2951 | |
| 2952 | t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts); |
| 2953 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2954 | switch (se_cmd->prot_type) { |
| 2955 | case TARGET_DIF_TYPE0_PROT: |
| 2956 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2957 | * No check for ql2xenablehba_err_chk, as it |
| 2958 | * would be an I/O error if hba tag generation |
| 2959 | * is not done. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2960 | */ |
| 2961 | ctx->ref_tag = cpu_to_le32(lba); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2962 | /* enable ALL bytes of the ref tag */ |
| 2963 | ctx->ref_tag_mask[0] = 0xff; |
| 2964 | ctx->ref_tag_mask[1] = 0xff; |
| 2965 | ctx->ref_tag_mask[2] = 0xff; |
| 2966 | ctx->ref_tag_mask[3] = 0xff; |
| 2967 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2968 | case TARGET_DIF_TYPE1_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2969 | /* |
| 2970 | * For TYPE 1 protection: 16 bit GUARD tag, 32 bit |
| 2971 | * REF tag, and 16 bit app tag. |
| 2972 | */ |
| 2973 | ctx->ref_tag = cpu_to_le32(lba); |
| 2974 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2975 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2976 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2977 | break; |
| 2978 | } |
| 2979 | /* enable ALL bytes of the ref tag */ |
| 2980 | ctx->ref_tag_mask[0] = 0xff; |
| 2981 | ctx->ref_tag_mask[1] = 0xff; |
| 2982 | ctx->ref_tag_mask[2] = 0xff; |
| 2983 | ctx->ref_tag_mask[3] = 0xff; |
| 2984 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2985 | case TARGET_DIF_TYPE2_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2986 | /* |
| 2987 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF |
| 2988 | * tag has to match LBA in CDB + N |
| 2989 | */ |
| 2990 | ctx->ref_tag = cpu_to_le32(lba); |
| 2991 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2992 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2993 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2994 | break; |
| 2995 | } |
| 2996 | /* enable ALL bytes of the ref tag */ |
| 2997 | ctx->ref_tag_mask[0] = 0xff; |
| 2998 | ctx->ref_tag_mask[1] = 0xff; |
| 2999 | ctx->ref_tag_mask[2] = 0xff; |
| 3000 | ctx->ref_tag_mask[3] = 0xff; |
| 3001 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3002 | case TARGET_DIF_TYPE3_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3003 | /* For TYPE 3 protection: 16 bit GUARD only */ |
| 3004 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 3005 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 3006 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 3007 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3008 | } |
| 3009 | } |
| 3010 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3011 | static inline int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3012 | qlt_build_ctio_crc2_pkt(struct qla_qpair *qpair, struct qla_tgt_prm *prm) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3013 | { |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 3014 | struct dsd64 *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3015 | uint32_t transfer_length = 0; |
| 3016 | uint32_t data_bytes; |
| 3017 | uint32_t dif_bytes; |
| 3018 | uint8_t bundling = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3019 | struct crc_context *crc_ctx_pkt = NULL; |
| 3020 | struct qla_hw_data *ha; |
| 3021 | struct ctio_crc2_to_fw *pkt; |
| 3022 | dma_addr_t crc_ctx_dma; |
| 3023 | uint16_t fw_prot_opts = 0; |
| 3024 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 3025 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 3026 | uint32_t h; |
| 3027 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3028 | struct qla_tc_param tc; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3029 | uint16_t t16; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3030 | scsi_qla_host_t *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3031 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3032 | ha = vha->hw; |
| 3033 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3034 | pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3035 | prm->pkt = pkt; |
| 3036 | memset(pkt, 0, sizeof(*pkt)); |
| 3037 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3038 | ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3039 | "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n", |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3040 | cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3041 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 3042 | |
| 3043 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 3044 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 3045 | bundling = 0; |
| 3046 | |
| 3047 | /* Compute dif len and adjust data len to incude protection */ |
| 3048 | data_bytes = cmd->bufflen; |
| 3049 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 3050 | |
| 3051 | switch (se_cmd->prot_op) { |
| 3052 | case TARGET_PROT_DIN_INSERT: |
| 3053 | case TARGET_PROT_DOUT_STRIP: |
| 3054 | transfer_length = data_bytes; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3055 | if (cmd->prot_sg_cnt) |
| 3056 | data_bytes += dif_bytes; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3057 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3058 | case TARGET_PROT_DIN_STRIP: |
| 3059 | case TARGET_PROT_DOUT_INSERT: |
| 3060 | case TARGET_PROT_DIN_PASS: |
| 3061 | case TARGET_PROT_DOUT_PASS: |
| 3062 | transfer_length = data_bytes + dif_bytes; |
| 3063 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3064 | default: |
| 3065 | BUG(); |
| 3066 | break; |
| 3067 | } |
| 3068 | |
| 3069 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 3070 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 3071 | /* HBA error checking enabled */ |
| 3072 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 3073 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 3074 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 3075 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 3076 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 3077 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 3078 | } |
| 3079 | |
| 3080 | switch (se_cmd->prot_op) { |
| 3081 | case TARGET_PROT_DIN_INSERT: |
| 3082 | case TARGET_PROT_DOUT_INSERT: |
| 3083 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 3084 | break; |
| 3085 | case TARGET_PROT_DIN_STRIP: |
| 3086 | case TARGET_PROT_DOUT_STRIP: |
| 3087 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 3088 | break; |
| 3089 | case TARGET_PROT_DIN_PASS: |
| 3090 | case TARGET_PROT_DOUT_PASS: |
| 3091 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 3092 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 3093 | break; |
| 3094 | default:/* Normal Request */ |
| 3095 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 3096 | break; |
| 3097 | } |
| 3098 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3099 | /* ---- PKT ---- */ |
| 3100 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 3101 | pkt->entry_type = CTIO_CRC2; |
| 3102 | pkt->entry_count = 1; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3103 | pkt->vp_index = cmd->vp_idx; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3104 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3105 | h = qlt_make_handle(qpair); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3106 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 3107 | /* |
| 3108 | * CTIO type 7 from the firmware doesn't provide a way to |
| 3109 | * know the initiator's LOOP ID, hence we can't find |
| 3110 | * the session and, so, the command. |
| 3111 | */ |
| 3112 | return -EAGAIN; |
| 3113 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3114 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3115 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3116 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 3117 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3118 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3119 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3120 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3121 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3122 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3123 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3124 | |
| 3125 | /* silence compile warning */ |
| 3126 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3127 | pkt->ox_id = cpu_to_le16(t16); |
| 3128 | |
| 3129 | t16 = (atio->u.isp24.attr << 9); |
| 3130 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3131 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 3132 | |
| 3133 | /* Set transfer direction */ |
| 3134 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3135 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3136 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3137 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3138 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3139 | pkt->dseg_count = prm->tot_dsds; |
| 3140 | /* Fibre channel byte count */ |
| 3141 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 3142 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3143 | /* ----- CRC context -------- */ |
| 3144 | |
| 3145 | /* Allocate CRC context from global pool */ |
| 3146 | crc_ctx_pkt = cmd->ctx = |
Souptick Joarder | 501017f | 2018-02-15 01:40:38 +0530 | [diff] [blame] | 3147 | dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3148 | |
| 3149 | if (!crc_ctx_pkt) |
| 3150 | goto crc_queuing_error; |
| 3151 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3152 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 3153 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 3154 | |
| 3155 | /* Set handle */ |
| 3156 | crc_ctx_pkt->handle = pkt->handle; |
| 3157 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3158 | qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3159 | |
Bart Van Assche | d4556a4 | 2019-04-17 14:44:39 -0700 | [diff] [blame] | 3160 | put_unaligned_le64(crc_ctx_dma, &pkt->crc_context_address); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3161 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 3162 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3163 | if (!bundling) { |
Bart Van Assche | 9e75b5e | 2019-08-08 20:01:33 -0700 | [diff] [blame] | 3164 | cur_dsd = &crc_ctx_pkt->u.nobundling.data_dsd[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3165 | } else { |
| 3166 | /* |
| 3167 | * Configure Bundling if we need to fetch interlaving |
| 3168 | * protection PCI accesses |
| 3169 | */ |
| 3170 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 3171 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 3172 | crc_ctx_pkt->u.bundling.dseg_count = |
| 3173 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
Bart Van Assche | 9e75b5e | 2019-08-08 20:01:33 -0700 | [diff] [blame] | 3174 | cur_dsd = &crc_ctx_pkt->u.bundling.data_dsd[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | /* Finish the common fields of CRC pkt */ |
| 3178 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 3179 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 3180 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3181 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3182 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3183 | memset((uint8_t *)&tc, 0 , sizeof(tc)); |
| 3184 | tc.vha = vha; |
| 3185 | tc.blk_sz = cmd->blk_sz; |
| 3186 | tc.bufflen = cmd->bufflen; |
| 3187 | tc.sg = cmd->sg; |
| 3188 | tc.prot_sg = cmd->prot_sg; |
| 3189 | tc.ctx = crc_ctx_pkt; |
| 3190 | tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3191 | |
| 3192 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3193 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3194 | |
| 3195 | if (!bundling && prm->prot_seg_cnt) { |
| 3196 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3197 | prm->tot_dsds, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3198 | goto crc_queuing_error; |
| 3199 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3200 | (prm->tot_dsds - prm->prot_seg_cnt), &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3201 | goto crc_queuing_error; |
| 3202 | |
| 3203 | if (bundling && prm->prot_seg_cnt) { |
| 3204 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3205 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3206 | |
Bart Van Assche | 15b7a68 | 2019-04-17 14:44:38 -0700 | [diff] [blame] | 3207 | cur_dsd = &crc_ctx_pkt->u.bundling.dif_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3208 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
Giridhar Malavali | 50b8127 | 2018-12-21 09:33:45 -0800 | [diff] [blame] | 3209 | prm->prot_seg_cnt, cmd)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3210 | goto crc_queuing_error; |
| 3211 | } |
| 3212 | return QLA_SUCCESS; |
| 3213 | |
| 3214 | crc_queuing_error: |
| 3215 | /* Cleanup will be performed by the caller */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3216 | qpair->req->outstanding_cmds[h] = NULL; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3217 | |
| 3218 | return QLA_FUNCTION_FAILED; |
| 3219 | } |
| 3220 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3221 | /* |
| 3222 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 3223 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 3224 | */ |
| 3225 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 3226 | uint8_t scsi_status) |
| 3227 | { |
| 3228 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3229 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3230 | struct ctio7_to_24xx *pkt; |
| 3231 | struct qla_tgt_prm prm; |
| 3232 | uint32_t full_req_cnt = 0; |
| 3233 | unsigned long flags = 0; |
| 3234 | int res; |
| 3235 | |
Quinn Tran | 51fd6e6 | 2019-01-24 23:23:43 -0800 | [diff] [blame] | 3236 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
| 3237 | (cmd->sess && cmd->sess->deleted)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3238 | cmd->state = QLA_TGT_STATE_PROCESSED; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3239 | return 0; |
| 3240 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3241 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3242 | ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3243 | "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3244 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 3245 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3246 | &cmd->se_cmd, qpair->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3247 | |
| 3248 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 3249 | &full_req_cnt); |
| 3250 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3251 | return res; |
| 3252 | } |
| 3253 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3254 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3255 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3256 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3257 | qpair->tgt_counters.core_qla_snd_status++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3258 | else |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3259 | qpair->tgt_counters.core_qla_que_buf++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3260 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3261 | if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3262 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3263 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3264 | * previous life, just abort the processing. |
| 3265 | */ |
| 3266 | cmd->state = QLA_TGT_STATE_PROCESSED; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3267 | ql_dbg_qp(ql_dbg_async, qpair, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3268 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3269 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3270 | cmd->reset_count, qpair->chip_reset); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3271 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3272 | return 0; |
| 3273 | } |
| 3274 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3275 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3276 | res = qlt_check_reserve_free_req(qpair, full_req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3277 | if (unlikely(res)) |
| 3278 | goto out_unmap_unlock; |
| 3279 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3280 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3281 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3282 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3283 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3284 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3285 | qpair->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3286 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3287 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3288 | |
| 3289 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 3290 | |
| 3291 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 3292 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3293 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3294 | CTIO7_FLAGS_STATUS_MODE_0); |
| 3295 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3296 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3297 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3298 | |
| 3299 | if (prm.add_status_pkt == 0) { |
| 3300 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 3301 | pkt->u.status0.scsi_status = |
| 3302 | cpu_to_le16(prm.rq_result); |
| 3303 | pkt->u.status0.residual = |
| 3304 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3305 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3306 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3307 | if (qlt_need_explicit_conf(cmd, 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3308 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3309 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3310 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 3311 | CTIO7_FLAGS_CONFORM_REQ); |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | } else { |
| 3316 | /* |
| 3317 | * We have already made sure that there is sufficient |
| 3318 | * amount of request entries to not drop HW lock in |
| 3319 | * req_pkt(). |
| 3320 | */ |
| 3321 | struct ctio7_to_24xx *ctio = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3322 | (struct ctio7_to_24xx *)qlt_get_req_pkt( |
| 3323 | qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3324 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3325 | ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e, |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3326 | "Building additional status packet 0x%p.\n", |
| 3327 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3328 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3329 | /* |
| 3330 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 3331 | * ctio7_to_24xx |
| 3332 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3333 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3334 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3335 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3336 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3337 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3338 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3339 | CTIO7_FLAGS_DATA_IN); |
| 3340 | |
| 3341 | /* Real finish is ctio_m1's finish */ |
| 3342 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3343 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3344 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3345 | |
| 3346 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3347 | * all neccessary fields that's part of CTIO7. |
| 3348 | * There should be no residual of CTIO-CRC2 data. |
| 3349 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3350 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3351 | &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3352 | } |
| 3353 | } else |
| 3354 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3355 | |
| 3356 | |
| 3357 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3358 | cmd->cmd_sent_to_fw = 1; |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3359 | cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3360 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3361 | /* Memory Barrier */ |
| 3362 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3363 | if (qpair->reqq_start_iocbs) |
| 3364 | qpair->reqq_start_iocbs(qpair); |
| 3365 | else |
| 3366 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3367 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3368 | |
| 3369 | return 0; |
| 3370 | |
| 3371 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3372 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3373 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3374 | |
| 3375 | return res; |
| 3376 | } |
| 3377 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3378 | |
| 3379 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3380 | { |
| 3381 | struct ctio7_to_24xx *pkt; |
| 3382 | struct scsi_qla_host *vha = cmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3383 | struct qla_tgt *tgt = cmd->tgt; |
| 3384 | struct qla_tgt_prm prm; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3385 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3386 | int res = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3387 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3388 | |
| 3389 | memset(&prm, 0, sizeof(prm)); |
| 3390 | prm.cmd = cmd; |
| 3391 | prm.tgt = tgt; |
| 3392 | prm.sg = NULL; |
| 3393 | prm.req_cnt = 1; |
| 3394 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3395 | /* Calculate number of entries and segments required */ |
| 3396 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3397 | return -EAGAIN; |
| 3398 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3399 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3400 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3401 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3402 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3403 | * previous life, just abort the processing. |
| 3404 | */ |
Bart Van Assche | aefed3e | 2019-04-17 14:44:29 -0700 | [diff] [blame] | 3405 | cmd->aborted = 1; |
| 3406 | cmd->write_data_transferred = 0; |
| 3407 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3408 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3409 | ql_dbg_qp(ql_dbg_async, qpair, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3410 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3411 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3412 | cmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3413 | return 0; |
| 3414 | } |
| 3415 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3416 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3417 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3418 | res = qlt_check_reserve_free_req(qpair, prm.req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3419 | if (res != 0) |
| 3420 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3421 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3422 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3423 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3424 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3425 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3426 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3427 | qpair->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3428 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3429 | } |
| 3430 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3431 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3432 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3433 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3434 | |
| 3435 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3436 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3437 | |
| 3438 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3439 | cmd->cmd_sent_to_fw = 1; |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3440 | cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3441 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3442 | /* Memory Barrier */ |
| 3443 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3444 | if (qpair->reqq_start_iocbs) |
| 3445 | qpair->reqq_start_iocbs(qpair); |
| 3446 | else |
| 3447 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3448 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3449 | |
| 3450 | return res; |
| 3451 | |
| 3452 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3453 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3454 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3455 | |
| 3456 | return res; |
| 3457 | } |
| 3458 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3459 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3460 | |
| 3461 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3462 | * it is assumed either hardware_lock or qpair lock is held. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3463 | */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3464 | static void |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3465 | qlt_handle_dif_error(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3466 | struct ctio_crc_from_fw *sts) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3467 | { |
| 3468 | uint8_t *ap = &sts->actual_dif[0]; |
| 3469 | uint8_t *ep = &sts->expected_dif[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3470 | uint64_t lba = cmd->se_cmd.t_task_lba; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3471 | uint8_t scsi_status, sense_key, asc, ascq; |
| 3472 | unsigned long flags; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3473 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3474 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3475 | cmd->trc_flags |= TRC_DIF_ERR; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3476 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3477 | cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3478 | cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3479 | cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3480 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3481 | cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3482 | cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3483 | cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3484 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3485 | ql_dbg(ql_dbg_tgt_dif, vha, 0xf075, |
| 3486 | "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3487 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3488 | scsi_status = sense_key = asc = ascq = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3489 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3490 | /* check appl tag */ |
| 3491 | if (cmd->e_app_tag != cmd->a_app_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3492 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d, |
| 3493 | "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]", |
| 3494 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3495 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3496 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3497 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3498 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3499 | cmd->dif_err_code = DIF_ERR_APP; |
| 3500 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3501 | sense_key = ABORTED_COMMAND; |
| 3502 | asc = 0x10; |
| 3503 | ascq = 0x2; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | /* check ref tag */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3507 | if (cmd->e_ref_tag != cmd->a_ref_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3508 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e, |
| 3509 | "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] ", |
| 3510 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3511 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3512 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3513 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3514 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3515 | cmd->dif_err_code = DIF_ERR_REF; |
| 3516 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3517 | sense_key = ABORTED_COMMAND; |
| 3518 | asc = 0x10; |
| 3519 | ascq = 0x3; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3520 | goto out; |
| 3521 | } |
| 3522 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3523 | /* check guard */ |
| 3524 | if (cmd->e_guard != cmd->a_guard) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3525 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe012, |
| 3526 | "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]", |
| 3527 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3528 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3529 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3530 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
| 3531 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3532 | cmd->dif_err_code = DIF_ERR_GRD; |
| 3533 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3534 | sense_key = ABORTED_COMMAND; |
| 3535 | asc = 0x10; |
| 3536 | ascq = 0x1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3537 | } |
| 3538 | out: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3539 | switch (cmd->state) { |
| 3540 | case QLA_TGT_STATE_NEED_DATA: |
| 3541 | /* handle_data will load DIF error code */ |
| 3542 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3543 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
| 3544 | break; |
| 3545 | default: |
| 3546 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3547 | if (cmd->aborted) { |
| 3548 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3549 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3550 | break; |
| 3551 | } |
| 3552 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3553 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3554 | qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc, |
| 3555 | ascq); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3556 | /* assume scsi status gets out on the wire. |
| 3557 | * Will not wait for completion. |
| 3558 | */ |
| 3559 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3560 | break; |
| 3561 | } |
| 3562 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3563 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3564 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3565 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3566 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3567 | struct imm_ntfy_from_isp *ntfy) |
| 3568 | { |
| 3569 | struct nack_to_isp *nack; |
| 3570 | struct qla_hw_data *ha = vha->hw; |
| 3571 | request_t *pkt; |
| 3572 | int ret = 0; |
| 3573 | |
| 3574 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3575 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3576 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3577 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3578 | if (pkt == NULL) { |
| 3579 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3580 | "qla_target(%d): %s failed: unable to allocate " |
| 3581 | "request packet\n", vha->vp_idx, __func__); |
| 3582 | return -ENOMEM; |
| 3583 | } |
| 3584 | |
| 3585 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3586 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3587 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3588 | |
| 3589 | nack = (struct nack_to_isp *)pkt; |
| 3590 | nack->ox_id = ntfy->ox_id; |
| 3591 | |
| 3592 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3593 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3594 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3595 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3596 | } |
| 3597 | |
| 3598 | /* terminate */ |
| 3599 | nack->u.isp24.flags |= |
| 3600 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3601 | |
| 3602 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3603 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3604 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3605 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3606 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3607 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3608 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3609 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3610 | |
| 3611 | qla2x00_start_iocbs(vha, vha->req); |
| 3612 | return ret; |
| 3613 | } |
| 3614 | |
| 3615 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3616 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3617 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3618 | int rc; |
| 3619 | |
Bart Van Assche | e65449a | 2019-04-17 14:44:26 -0700 | [diff] [blame] | 3620 | WARN_ON_ONCE(!ha_locked); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3621 | rc = __qlt_send_term_imm_notif(vha, imm); |
Bart Van Assche | e65449a | 2019-04-17 14:44:26 -0700 | [diff] [blame] | 3622 | pr_debug("rc = %d\n", rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3623 | } |
| 3624 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3625 | /* |
| 3626 | * If hardware_lock held on entry, might drop it, then reaquire |
| 3627 | * This function sends the appropriate CTIO to ISP 2xxx or 24xx |
| 3628 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3629 | static int __qlt_send_term_exchange(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3630 | struct qla_tgt_cmd *cmd, |
| 3631 | struct atio_from_isp *atio) |
| 3632 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3633 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3634 | struct ctio7_to_24xx *ctio24; |
| 3635 | struct qla_hw_data *ha = vha->hw; |
| 3636 | request_t *pkt; |
| 3637 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3638 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3639 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3640 | ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3641 | |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 3642 | if (cmd) |
| 3643 | vha = cmd->vha; |
| 3644 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3645 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3646 | if (pkt == NULL) { |
| 3647 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3648 | "qla_target(%d): %s failed: unable to allocate " |
| 3649 | "request packet\n", vha->vp_idx, __func__); |
| 3650 | return -ENOMEM; |
| 3651 | } |
| 3652 | |
| 3653 | if (cmd != NULL) { |
| 3654 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3655 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3656 | "qla_target(%d): Terminating cmd %p with " |
| 3657 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3658 | cmd->state); |
| 3659 | } else |
| 3660 | ret = 1; |
| 3661 | } |
| 3662 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3663 | qpair->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3664 | pkt->entry_count = 1; |
| 3665 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3666 | |
| 3667 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3668 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3669 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3670 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3671 | ctio24->vp_index = vha->vp_idx; |
| 3672 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3673 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3674 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3675 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3676 | temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 | |
| 3677 | CTIO7_FLAGS_TERMINATE; |
| 3678 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3679 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3680 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3681 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3682 | /* Memory Barrier */ |
| 3683 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3684 | if (qpair->reqq_start_iocbs) |
| 3685 | qpair->reqq_start_iocbs(qpair); |
| 3686 | else |
| 3687 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3688 | return ret; |
| 3689 | } |
| 3690 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3691 | static void qlt_send_term_exchange(struct qla_qpair *qpair, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3692 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3693 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3694 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3695 | struct scsi_qla_host *vha; |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3696 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3697 | int rc; |
| 3698 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3699 | /* why use different vha? NPIV */ |
| 3700 | if (cmd) |
| 3701 | vha = cmd->vha; |
| 3702 | else |
| 3703 | vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3704 | |
| 3705 | if (ha_locked) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3706 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3707 | if (rc == -ENOMEM) |
| 3708 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3709 | goto done; |
| 3710 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3711 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 3712 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3713 | if (rc == -ENOMEM) |
| 3714 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3715 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3716 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3717 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3718 | if (cmd->sg_mapped) |
| 3719 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3720 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3721 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3722 | |
| 3723 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3724 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3725 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3726 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3727 | } |
| 3728 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3729 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3730 | { |
| 3731 | struct list_head free_list; |
| 3732 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3733 | |
| 3734 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3735 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3736 | |
| 3737 | cmd = tcmd = NULL; |
| 3738 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3739 | INIT_LIST_HEAD(&free_list); |
| 3740 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3741 | |
| 3742 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3743 | list_del(&cmd->cmd_list); |
| 3744 | /* This cmd was never sent to TCM. There is no need |
| 3745 | * to schedule free or call free_cmd |
| 3746 | */ |
| 3747 | qlt_free_cmd(cmd); |
| 3748 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3749 | } |
| 3750 | } |
| 3751 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3752 | } |
| 3753 | |
| 3754 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3755 | { |
| 3756 | uint32_t total_leaked; |
| 3757 | |
| 3758 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3759 | |
| 3760 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3761 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3762 | |
| 3763 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3764 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3765 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3766 | |
| 3767 | if (IS_P3P_TYPE(vha->hw)) |
| 3768 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3769 | else |
| 3770 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3771 | qla2xxx_wake_dpc(vha); |
| 3772 | } |
| 3773 | |
| 3774 | } |
| 3775 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3776 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3777 | { |
| 3778 | struct qla_tgt *tgt = cmd->tgt; |
| 3779 | struct scsi_qla_host *vha = tgt->vha; |
| 3780 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3781 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3782 | |
| 3783 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3784 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3785 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3786 | se_cmd->tag); |
| 3787 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3788 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3789 | if (cmd->aborted) { |
| 3790 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3791 | /* |
| 3792 | * It's normal to see 2 calls in this path: |
| 3793 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3794 | * 2) TCM TMR - drain_state_list |
| 3795 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3796 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, |
| 3797 | "multiple abort. %p transport_state %x, t_state %x, " |
| 3798 | "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, |
| 3799 | cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3800 | return EIO; |
| 3801 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3802 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3803 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3804 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3805 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3806 | qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3807 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3808 | } |
| 3809 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3810 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3811 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3812 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3813 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3814 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3815 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3816 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3817 | __func__, &cmd->se_cmd, |
| 3818 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3819 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3820 | BUG_ON(cmd->cmd_in_wq); |
| 3821 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3822 | if (cmd->sg_mapped) |
| 3823 | qlt_unmap_sg(cmd->vha, cmd); |
| 3824 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3825 | if (!cmd->q_full) |
| 3826 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3827 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3828 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3829 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3830 | if (unlikely(cmd->free_sg)) |
| 3831 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3832 | |
| 3833 | if (!sess || !sess->se_sess) { |
| 3834 | WARN_ON(1); |
| 3835 | return; |
| 3836 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3837 | cmd->jiffies_at_free = get_jiffies_64(); |
Matthew Wilcox | 83c2b54 | 2018-06-12 12:05:43 -0700 | [diff] [blame] | 3838 | target_free_tag(sess->se_sess, &cmd->se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3839 | } |
| 3840 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3841 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3842 | /* |
| 3843 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3844 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3845 | static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3846 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3847 | { |
| 3848 | int term = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3849 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3850 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3851 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3852 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3853 | "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " |
| 3854 | "se_cmd=%p tag[%x] op %#x/%s", |
| 3855 | cmd->lba, cmd->lba, |
| 3856 | cmd->num_blks, &cmd->se_cmd, |
| 3857 | cmd->atio.u.isp24.exchange_addr, |
| 3858 | cmd->se_cmd.prot_op, |
| 3859 | prot_op_str(cmd->se_cmd.prot_op)); |
| 3860 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3861 | if (ctio != NULL) { |
| 3862 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 3863 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3864 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3865 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3866 | } else |
| 3867 | term = 1; |
| 3868 | |
| 3869 | if (term) |
himanshu.madhani@cavium.com | 3efc31f | 2018-01-15 20:46:47 -0800 | [diff] [blame] | 3870 | qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3871 | |
| 3872 | return term; |
| 3873 | } |
| 3874 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3875 | |
| 3876 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3877 | static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3878 | struct rsp_que *rsp, uint32_t handle, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3879 | { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3880 | void *cmd = NULL; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3881 | struct req_que *req; |
| 3882 | int qid = GET_QID(handle); |
| 3883 | uint32_t h = handle & ~QLA_TGT_HANDLE_MASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3884 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3885 | if (unlikely(h == QLA_TGT_SKIP_HANDLE)) |
| 3886 | return NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3887 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3888 | if (qid == rsp->req->id) { |
| 3889 | req = rsp->req; |
| 3890 | } else if (vha->hw->req_q_map[qid]) { |
| 3891 | ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a, |
| 3892 | "qla_target(%d): CTIO completion with different QID %d handle %x\n", |
| 3893 | vha->vp_idx, rsp->id, handle); |
| 3894 | req = vha->hw->req_q_map[qid]; |
| 3895 | } else { |
| 3896 | return NULL; |
| 3897 | } |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3898 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3899 | h &= QLA_CMD_HANDLE_MASK; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3900 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3901 | if (h != QLA_TGT_NULL_HANDLE) { |
Dan Carpenter | fb2028a | 2017-07-10 11:47:40 +0300 | [diff] [blame] | 3902 | if (unlikely(h >= req->num_outstanding_cmds)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3903 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3904 | "qla_target(%d): Wrong handle %x received\n", |
| 3905 | vha->vp_idx, handle); |
| 3906 | return NULL; |
| 3907 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3908 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3909 | cmd = (void *) req->outstanding_cmds[h]; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3910 | if (unlikely(cmd == NULL)) { |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3911 | ql_dbg(ql_dbg_async, vha, 0xe053, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3912 | "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n", |
| 3913 | vha->vp_idx, handle, req->id, rsp->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3914 | return NULL; |
| 3915 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3916 | req->outstanding_cmds[h] = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3917 | } else if (ctio != NULL) { |
| 3918 | /* We can't get loop ID from CTIO7 */ |
| 3919 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3920 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3921 | "support NULL handles\n", vha->vp_idx); |
| 3922 | return NULL; |
| 3923 | } |
| 3924 | |
| 3925 | return cmd; |
| 3926 | } |
| 3927 | |
| 3928 | /* |
| 3929 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3930 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3931 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, |
| 3932 | struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3933 | { |
| 3934 | struct qla_hw_data *ha = vha->hw; |
| 3935 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3936 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3937 | struct qla_qpair *qpair = rsp->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3938 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3939 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3940 | /* That could happen only in case of an error/reset/abort */ |
| 3941 | if (status != CTIO_SUCCESS) { |
| 3942 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3943 | "Intermediate CTIO received" |
| 3944 | " (status %x)\n", status); |
| 3945 | } |
| 3946 | return; |
| 3947 | } |
| 3948 | |
Bart Van Assche | 81bcf1c | 2019-04-11 14:53:24 -0700 | [diff] [blame] | 3949 | cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3950 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3951 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3952 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3953 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3954 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3955 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3956 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3957 | |
| 3958 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3959 | switch (status & 0xFFFF) { |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3960 | case CTIO_INVALID_RX_ID: |
| 3961 | if (printk_ratelimit()) |
| 3962 | dev_info(&vha->hw->pdev->dev, |
| 3963 | "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n", |
| 3964 | vha->vp_idx, cmd->atio.u.isp24.attr, |
| 3965 | ((cmd->ctio_flags >> 9) & 0xf), |
| 3966 | cmd->ctio_flags); |
| 3967 | |
| 3968 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3969 | case CTIO_LIP_RESET: |
| 3970 | case CTIO_TARGET_RESET: |
| 3971 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3972 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3973 | case CTIO_TIMEOUT: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3974 | /* They are OK */ |
| 3975 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3976 | "qla_target(%d): CTIO with " |
| 3977 | "status %#x received, state %x, se_cmd %p, " |
| 3978 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3979 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3980 | status, cmd->state, se_cmd); |
| 3981 | break; |
| 3982 | |
| 3983 | case CTIO_PORT_LOGGED_OUT: |
| 3984 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3985 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3986 | int logged_out = |
| 3987 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3988 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3989 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3990 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3991 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3992 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3993 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3994 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3995 | if (logged_out && cmd->sess) { |
| 3996 | /* |
| 3997 | * Session is already logged out, but we need |
| 3998 | * to notify initiator, who's not aware of this |
| 3999 | */ |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 4000 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4001 | ql_dbg(ql_dbg_disc, vha, 0x20f8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4002 | "%s %d %8phC post del sess\n", |
| 4003 | __func__, __LINE__, cmd->sess->port_name); |
| 4004 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4005 | qlt_schedule_sess_for_deletion(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 4006 | } |
| 4007 | break; |
| 4008 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4009 | case CTIO_DIF_ERROR: { |
| 4010 | struct ctio_crc_from_fw *crc = |
| 4011 | (struct ctio_crc_from_fw *)ctio; |
| 4012 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 4013 | "qla_target(%d): CTIO with DIF_ERROR status %x " |
| 4014 | "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " |
| 4015 | "expect_dif[0x%llx]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4016 | vha->vp_idx, status, cmd->state, se_cmd, |
| 4017 | *((u64 *)&crc->actual_dif[0]), |
| 4018 | *((u64 *)&crc->expected_dif[0])); |
| 4019 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 4020 | qlt_handle_dif_error(qpair, cmd, ctio); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 4021 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4022 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4023 | default: |
| 4024 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4025 | "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4026 | vha->vp_idx, status, cmd->state, se_cmd); |
| 4027 | break; |
| 4028 | } |
| 4029 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4030 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4031 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4032 | * cmd is already aborted/terminated, we don't |
| 4033 | * need to terminate again. The exchange is already |
| 4034 | * cleaned up/freed at FW level. Just cleanup at driver |
| 4035 | * level. |
| 4036 | */ |
| 4037 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4038 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4039 | cmd->trc_flags |= TRC_CTIO_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4040 | if (qlt_term_ctio_exchange(qpair, ctio, cmd, status)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4041 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4042 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4046 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4047 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4048 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 4049 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4050 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4051 | cmd->write_data_transferred = 1; |
| 4052 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4053 | ha->tgt.tgt_ops->handle_data(cmd); |
| 4054 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4055 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4056 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4057 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4058 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4059 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4060 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4061 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 4062 | "qla_target(%d): A command in state (%d) should " |
| 4063 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 4064 | } |
| 4065 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4066 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4067 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4068 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 4069 | dump_stack(); |
| 4070 | } |
| 4071 | |
| 4072 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 4073 | } |
| 4074 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4075 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 4076 | uint8_t task_codes) |
| 4077 | { |
| 4078 | int fcp_task_attr; |
| 4079 | |
| 4080 | switch (task_codes) { |
| 4081 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4082 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4083 | break; |
| 4084 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4085 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4086 | break; |
| 4087 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4088 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4089 | break; |
| 4090 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4091 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4092 | break; |
| 4093 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4094 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4095 | break; |
| 4096 | default: |
| 4097 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 4098 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 4099 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4100 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4101 | break; |
| 4102 | } |
| 4103 | |
| 4104 | return fcp_task_attr; |
| 4105 | } |
| 4106 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4107 | /* |
| 4108 | * Process context for I/O path into tcm_qla2xxx code |
| 4109 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4110 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4111 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4112 | scsi_qla_host_t *vha = cmd->vha; |
| 4113 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4114 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4115 | struct atio_from_isp *atio = &cmd->atio; |
| 4116 | unsigned char *cdb; |
| 4117 | unsigned long flags; |
| 4118 | uint32_t data_length; |
| 4119 | int ret, fcp_task_attr, data_dir, bidi = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4120 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4121 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4122 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4123 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4124 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4125 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4126 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 4127 | "cmd with tag %u is aborted\n", |
| 4128 | cmd->atio.u.isp24.exchange_addr); |
| 4129 | goto out_term; |
| 4130 | } |
| 4131 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4132 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4133 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4134 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4135 | |
| 4136 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 4137 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 4138 | bidi = 1; |
| 4139 | data_dir = DMA_TO_DEVICE; |
| 4140 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 4141 | data_dir = DMA_FROM_DEVICE; |
| 4142 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 4143 | data_dir = DMA_TO_DEVICE; |
| 4144 | else |
| 4145 | data_dir = DMA_NONE; |
| 4146 | |
| 4147 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 4148 | atio->u.isp24.fcp_cmnd.task_attr); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 4149 | data_length = get_datalen_for_atio(atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4150 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4151 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 4152 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4153 | if (ret != 0) |
| 4154 | goto out_term; |
| 4155 | /* |
Bart Van Assche | 67eb4a60 | 2019-04-17 14:44:10 -0700 | [diff] [blame] | 4156 | * Drop extra session reference from qlt_handle_cmd_for_atio(). |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4157 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4158 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4159 | return; |
| 4160 | |
| 4161 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4162 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4163 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 4164 | * cmd has not sent to target yet, so pass NULL as the second |
| 4165 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4166 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4167 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4168 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4169 | qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4170 | |
| 4171 | qlt_decr_num_pend_cmds(vha); |
Matthew Wilcox | 83c2b54 | 2018-06-12 12:05:43 -0700 | [diff] [blame] | 4172 | target_free_tag(sess->se_sess, &cmd->se_cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4173 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4174 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4175 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4176 | } |
| 4177 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4178 | static void qlt_do_work(struct work_struct *work) |
| 4179 | { |
| 4180 | struct qla_tgt_cmd *cmd = container_of(work, struct qla_tgt_cmd, work); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4181 | scsi_qla_host_t *vha = cmd->vha; |
| 4182 | unsigned long flags; |
| 4183 | |
| 4184 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4185 | list_del(&cmd->cmd_list); |
| 4186 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4187 | |
| 4188 | __qlt_do_work(cmd); |
| 4189 | } |
| 4190 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 4191 | void qlt_clr_qp_table(struct scsi_qla_host *vha) |
| 4192 | { |
| 4193 | unsigned long flags; |
| 4194 | struct qla_hw_data *ha = vha->hw; |
| 4195 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4196 | void *node; |
| 4197 | u64 key = 0; |
| 4198 | |
| 4199 | ql_log(ql_log_info, vha, 0x706c, |
| 4200 | "User update Number of Active Qpairs %d\n", |
| 4201 | ha->tgt.num_act_qpairs); |
| 4202 | |
| 4203 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 4204 | |
| 4205 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 4206 | btree_remove64(&tgt->lun_qpair_map, key); |
| 4207 | |
| 4208 | ha->base_qpair->lun_cnt = 0; |
| 4209 | for (key = 0; key < ha->max_qpairs; key++) |
| 4210 | if (ha->queue_pair_map[key]) |
| 4211 | ha->queue_pair_map[key]->lun_cnt = 0; |
| 4212 | |
| 4213 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 4214 | } |
| 4215 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4216 | static void qlt_assign_qpair(struct scsi_qla_host *vha, |
| 4217 | struct qla_tgt_cmd *cmd) |
| 4218 | { |
| 4219 | struct qla_qpair *qpair, *qp; |
| 4220 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4221 | struct qla_qpair_hint *h; |
| 4222 | |
| 4223 | if (vha->flags.qpairs_available) { |
| 4224 | h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun); |
| 4225 | if (unlikely(!h)) { |
| 4226 | /* spread lun to qpair ratio evently */ |
| 4227 | int lcnt = 0, rc; |
| 4228 | struct scsi_qla_host *base_vha = |
| 4229 | pci_get_drvdata(vha->hw->pdev); |
| 4230 | |
| 4231 | qpair = vha->hw->base_qpair; |
| 4232 | if (qpair->lun_cnt == 0) { |
| 4233 | qpair->lun_cnt++; |
| 4234 | h = qla_qpair_to_hint(tgt, qpair); |
| 4235 | BUG_ON(!h); |
| 4236 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4237 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4238 | if (rc) { |
| 4239 | qpair->lun_cnt--; |
| 4240 | ql_log(ql_log_info, vha, 0xd037, |
| 4241 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4242 | cmd->unpacked_lun); |
| 4243 | } |
| 4244 | goto out; |
| 4245 | } else { |
| 4246 | lcnt = qpair->lun_cnt; |
| 4247 | } |
| 4248 | |
| 4249 | h = NULL; |
| 4250 | list_for_each_entry(qp, &base_vha->qp_list, |
| 4251 | qp_list_elem) { |
| 4252 | if (qp->lun_cnt == 0) { |
| 4253 | qp->lun_cnt++; |
| 4254 | h = qla_qpair_to_hint(tgt, qp); |
| 4255 | BUG_ON(!h); |
| 4256 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4257 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4258 | if (rc) { |
| 4259 | qp->lun_cnt--; |
| 4260 | ql_log(ql_log_info, vha, 0xd038, |
| 4261 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4262 | cmd->unpacked_lun); |
| 4263 | } |
| 4264 | qpair = qp; |
| 4265 | goto out; |
| 4266 | } else { |
| 4267 | if (qp->lun_cnt < lcnt) { |
| 4268 | lcnt = qp->lun_cnt; |
| 4269 | qpair = qp; |
| 4270 | continue; |
| 4271 | } |
| 4272 | } |
| 4273 | } |
| 4274 | BUG_ON(!qpair); |
| 4275 | qpair->lun_cnt++; |
| 4276 | h = qla_qpair_to_hint(tgt, qpair); |
| 4277 | BUG_ON(!h); |
| 4278 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4279 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4280 | if (rc) { |
| 4281 | qpair->lun_cnt--; |
| 4282 | ql_log(ql_log_info, vha, 0xd039, |
| 4283 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4284 | cmd->unpacked_lun); |
| 4285 | } |
| 4286 | } |
| 4287 | } else { |
| 4288 | h = &tgt->qphints[0]; |
| 4289 | } |
| 4290 | out: |
| 4291 | cmd->qpair = h->qpair; |
| 4292 | cmd->se_cmd.cpuid = h->cpuid; |
| 4293 | } |
| 4294 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4295 | static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4296 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4297 | struct atio_from_isp *atio) |
| 4298 | { |
| 4299 | struct se_session *se_sess = sess->se_sess; |
| 4300 | struct qla_tgt_cmd *cmd; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4301 | int tag, cpu; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4302 | |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4303 | tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4304 | if (tag < 0) |
| 4305 | return NULL; |
| 4306 | |
| 4307 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4308 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 4309 | cmd->cmd_type = TYPE_TGT_CMD; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4310 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4311 | cmd->state = QLA_TGT_STATE_NEW; |
| 4312 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4313 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4314 | cmd->vha = vha; |
| 4315 | cmd->se_cmd.map_tag = tag; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4316 | cmd->se_cmd.map_cpu = cpu; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4317 | cmd->sess = sess; |
| 4318 | cmd->loop_id = sess->loop_id; |
| 4319 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4320 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4321 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4322 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4323 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4324 | cmd->unpacked_lun = scsilun_to_int( |
| 4325 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 4326 | qlt_assign_qpair(vha, cmd); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4327 | cmd->reset_count = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 4328 | cmd->vp_idx = vha->vp_idx; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4329 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4330 | return cmd; |
| 4331 | } |
| 4332 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4333 | /* ha->hardware_lock supposed to be held on entry */ |
| 4334 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4335 | struct atio_from_isp *atio) |
| 4336 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4337 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4338 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4339 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4340 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4341 | unsigned long flags; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4342 | port_id_t id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4343 | |
| 4344 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4345 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4346 | "New command while device %p is shutting down\n", tgt); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4347 | return -ENODEV; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4348 | } |
| 4349 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4350 | id.b.al_pa = atio->u.isp24.fcp_hdr.s_id[2]; |
| 4351 | id.b.area = atio->u.isp24.fcp_hdr.s_id[1]; |
| 4352 | id.b.domain = atio->u.isp24.fcp_hdr.s_id[0]; |
| 4353 | if (IS_SW_RESV_ADDR(id)) |
| 4354 | return -EBUSY; |
| 4355 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4356 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 4357 | if (unlikely(!sess)) |
| 4358 | return -EFAULT; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4359 | |
| 4360 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4361 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4362 | if (sess->deleted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4363 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4364 | "New command while old session %p is being deleted\n", |
| 4365 | sess); |
| 4366 | return -EFAULT; |
| 4367 | } |
| 4368 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4369 | /* |
| 4370 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4371 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4372 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4373 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4374 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4375 | __func__, sess->port_name, |
| 4376 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4377 | return -EFAULT; |
| 4378 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4379 | |
| 4380 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4381 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4382 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4383 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4384 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4385 | return -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4386 | } |
| 4387 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4388 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4389 | cmd->trc_flags |= TRC_NEW_CMD; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4390 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4391 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4392 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4393 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4394 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4395 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4396 | if (vha->flags.qpairs_available) { |
| 4397 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work); |
| 4398 | } else if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4399 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4400 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4401 | &cmd->work); |
| 4402 | else |
| 4403 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4404 | &cmd->work); |
| 4405 | } else { |
| 4406 | queue_work(qla_tgt_wq, &cmd->work); |
| 4407 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4408 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4409 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4413 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4414 | int fn, void *iocb, int flags) |
| 4415 | { |
| 4416 | struct scsi_qla_host *vha = sess->vha; |
| 4417 | struct qla_hw_data *ha = vha->hw; |
| 4418 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4419 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4420 | struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4421 | |
| 4422 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4423 | if (!mcmd) { |
| 4424 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4425 | "qla_target(%d): Allocation of management " |
| 4426 | "command failed, some commands and their data could " |
| 4427 | "leak\n", vha->vp_idx); |
| 4428 | return -ENOMEM; |
| 4429 | } |
| 4430 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4431 | mcmd->sess = sess; |
| 4432 | |
| 4433 | if (iocb) { |
| 4434 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4435 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4436 | } |
| 4437 | mcmd->tmr_func = fn; |
| 4438 | mcmd->flags = flags; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4439 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4440 | mcmd->qpair = h->qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 4441 | mcmd->vha = vha; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4442 | mcmd->se_cmd.cpuid = h->cpuid; |
| 4443 | mcmd->unpacked_lun = lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4444 | |
| 4445 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4446 | case QLA_TGT_LUN_RESET: |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4447 | case QLA_TGT_CLEAR_TS: |
| 4448 | case QLA_TGT_ABORT_TS: |
| 4449 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
Bart Van Assche | 50435d4 | 2018-10-18 15:45:40 -0700 | [diff] [blame] | 4450 | /* fall through */ |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4451 | case QLA_TGT_CLEAR_ACA: |
| 4452 | h = qlt_find_qphint(vha, mcmd->unpacked_lun); |
| 4453 | mcmd->qpair = h->qpair; |
| 4454 | mcmd->se_cmd.cpuid = h->cpuid; |
| 4455 | break; |
| 4456 | |
| 4457 | case QLA_TGT_TARGET_RESET: |
| 4458 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 4459 | case QLA_TGT_NEXUS_LOSS: |
| 4460 | case QLA_TGT_ABORT_ALL: |
| 4461 | default: |
| 4462 | /* no-op */ |
| 4463 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4464 | } |
| 4465 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4466 | INIT_WORK(&mcmd->work, qlt_do_tmr_work); |
| 4467 | queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, |
| 4468 | &mcmd->work); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4469 | |
| 4470 | return 0; |
| 4471 | } |
| 4472 | |
| 4473 | /* ha->hardware_lock supposed to be held on entry */ |
| 4474 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4475 | { |
| 4476 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4477 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4478 | struct fc_port *sess; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4479 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4480 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4481 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4482 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4483 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4484 | |
| 4485 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4486 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4487 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4488 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4489 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4490 | unpacked_lun = |
| 4491 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4492 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 4493 | if (sess == NULL || sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4494 | return -EFAULT; |
| 4495 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4496 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4497 | } |
| 4498 | |
| 4499 | /* ha->hardware_lock supposed to be held on entry */ |
| 4500 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4501 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4502 | { |
| 4503 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4504 | struct qla_hw_data *ha = vha->hw; |
| 4505 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4506 | u64 unpacked_lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4507 | int rc; |
| 4508 | |
| 4509 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4510 | if (mcmd == NULL) { |
| 4511 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4512 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4513 | vha->vp_idx, __func__); |
| 4514 | return -ENOMEM; |
| 4515 | } |
| 4516 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4517 | |
| 4518 | mcmd->sess = sess; |
| 4519 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4520 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4521 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4522 | unpacked_lun = |
| 4523 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4524 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4525 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4526 | mcmd->qpair = ha->base_qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4527 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4528 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, unpacked_lun, mcmd->tmr_func, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4529 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4530 | if (rc != 0) { |
| 4531 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4532 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4533 | vha->vp_idx, rc); |
| 4534 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4535 | return -EFAULT; |
| 4536 | } |
| 4537 | |
| 4538 | return 0; |
| 4539 | } |
| 4540 | |
| 4541 | /* ha->hardware_lock supposed to be held on entry */ |
| 4542 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4543 | struct imm_ntfy_from_isp *iocb) |
| 4544 | { |
| 4545 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4546 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4547 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4548 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4549 | |
| 4550 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4551 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4552 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4553 | sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4554 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4555 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4556 | if (sess == NULL) { |
| 4557 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4558 | "qla_target(%d): task abort for unexisting " |
| 4559 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4560 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4561 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4562 | } |
| 4563 | |
| 4564 | return __qlt_abort_task(vha, iocb, sess); |
| 4565 | } |
| 4566 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4567 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4568 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4569 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4570 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4571 | "%s: se_sess %p / sess %p from" |
| 4572 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4573 | " LOGO failed: %#x\n", |
| 4574 | __func__, |
| 4575 | fcport->se_sess, |
| 4576 | fcport, |
| 4577 | fcport->port_name, fcport->loop_id, |
| 4578 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4579 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4580 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4581 | |
| 4582 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4583 | } |
| 4584 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4585 | /* |
| 4586 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4587 | * |
| 4588 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4589 | * deletion. Returns existing session with matching wwn if present. |
| 4590 | * Null otherwise. |
| 4591 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4592 | struct fc_port * |
| 4593 | qlt_find_sess_invalidate_other(scsi_qla_host_t *vha, uint64_t wwn, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4594 | port_id_t port_id, uint16_t loop_id, struct fc_port **conflict_sess) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4595 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4596 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4597 | uint64_t other_wwn; |
| 4598 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4599 | *conflict_sess = NULL; |
| 4600 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4601 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4602 | |
| 4603 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4604 | |
| 4605 | if (wwn == other_wwn) { |
| 4606 | WARN_ON(sess); |
| 4607 | sess = other_sess; |
| 4608 | continue; |
| 4609 | } |
| 4610 | |
| 4611 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4612 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4613 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4614 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4615 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4616 | other_sess, other_sess->loop_id, other_wwn); |
| 4617 | |
| 4618 | /* |
| 4619 | * logout_on_delete is set by default, but another |
| 4620 | * session that has the same s_id/loop_id combo |
| 4621 | * might have cleared it when requested this session |
| 4622 | * deletion, so don't touch it |
| 4623 | */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4624 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4625 | } else { |
| 4626 | /* |
| 4627 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4628 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4629 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4630 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01b, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4631 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4632 | other_sess, other_sess->loop_id, other_wwn); |
| 4633 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4634 | other_sess->keep_nport_handle = 1; |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 4635 | if (other_sess->disc_state != DSC_DELETED) |
| 4636 | *conflict_sess = other_sess; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4637 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4638 | } |
| 4639 | continue; |
| 4640 | } |
| 4641 | |
| 4642 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4643 | if ((loop_id == other_sess->loop_id) && |
| 4644 | (loop_id != FC_NO_LOOP_ID)) { |
| 4645 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4646 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4647 | other_sess, other_sess->loop_id, other_wwn); |
| 4648 | |
| 4649 | /* Same loop_id but different s_id |
| 4650 | * Ok to kill and logout */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4651 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4652 | } |
| 4653 | } |
| 4654 | |
| 4655 | return sess; |
| 4656 | } |
| 4657 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4658 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4659 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4660 | { |
| 4661 | struct qla_tgt_sess_op *op; |
| 4662 | struct qla_tgt_cmd *cmd; |
| 4663 | uint32_t key; |
| 4664 | int count = 0; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4665 | unsigned long flags; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4666 | |
| 4667 | key = (((u32)s_id->b.domain << 16) | |
| 4668 | ((u32)s_id->b.area << 8) | |
| 4669 | ((u32)s_id->b.al_pa)); |
| 4670 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4671 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4672 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4673 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4674 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4675 | if (op_key == key) { |
| 4676 | op->aborted = true; |
| 4677 | count++; |
| 4678 | } |
| 4679 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4680 | |
| 4681 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4682 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 4683 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4684 | if (op_key == key) { |
| 4685 | op->aborted = true; |
| 4686 | count++; |
| 4687 | } |
| 4688 | } |
| 4689 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4690 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4691 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 4692 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4693 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4694 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4695 | count++; |
| 4696 | } |
| 4697 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4698 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4699 | |
| 4700 | return count; |
| 4701 | } |
| 4702 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4703 | static int qlt_handle_login(struct scsi_qla_host *vha, |
| 4704 | struct imm_ntfy_from_isp *iocb) |
| 4705 | { |
| 4706 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
| 4707 | uint64_t wwn; |
| 4708 | port_id_t port_id; |
| 4709 | uint16_t loop_id, wd3_lo; |
| 4710 | int res = 0; |
| 4711 | struct qlt_plogi_ack_t *pla; |
| 4712 | unsigned long flags; |
| 4713 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 4714 | lockdep_assert_held(&vha->hw->hardware_lock); |
| 4715 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4716 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4717 | |
| 4718 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4719 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4720 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4721 | port_id.b.rsvd_1 = 0; |
| 4722 | |
| 4723 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4724 | |
| 4725 | /* Mark all stale commands sitting in qla_tgt_wq for deletion */ |
| 4726 | abort_cmds_for_s_id(vha, &port_id); |
| 4727 | |
| 4728 | if (wwn) { |
| 4729 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 4730 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4731 | port_id, loop_id, &conflict_sess); |
| 4732 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | aa9e6d7 | 2018-08-31 11:24:38 -0700 | [diff] [blame] | 4733 | } else { |
| 4734 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4735 | "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ", |
| 4736 | __func__, __LINE__, loop_id, port_id.b24); |
| 4737 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4738 | goto out; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4742 | res = 1; |
| 4743 | goto out; |
| 4744 | } |
| 4745 | |
| 4746 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4747 | if (!pla) { |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 4748 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
| 4749 | "%s %d %8phC Term INOT due to mem alloc fail", |
| 4750 | __func__, __LINE__, |
| 4751 | iocb->u.isp24.port_name); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4752 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4753 | goto out; |
| 4754 | } |
| 4755 | |
| 4756 | if (conflict_sess) { |
| 4757 | conflict_sess->login_gen++; |
| 4758 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
| 4759 | QLT_PLOGI_LINK_CONFLICT); |
| 4760 | } |
| 4761 | |
| 4762 | if (!sess) { |
| 4763 | pla->ref_count++; |
| 4764 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4765 | "%s %d %8phC post new sess\n", |
| 4766 | __func__, __LINE__, iocb->u.isp24.port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4767 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 4768 | qla24xx_post_newsess_work(vha, &port_id, |
| 4769 | iocb->u.isp24.port_name, |
| 4770 | iocb->u.isp24.u.plogi.node_name, |
| 4771 | pla, FC4_TYPE_UNKNOWN); |
| 4772 | else |
| 4773 | qla24xx_post_newsess_work(vha, &port_id, |
| 4774 | iocb->u.isp24.port_name, NULL, |
| 4775 | pla, FC4_TYPE_UNKNOWN); |
| 4776 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4777 | goto out; |
| 4778 | } |
| 4779 | |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4780 | if (sess->disc_state == DSC_UPD_FCPORT) { |
| 4781 | u16 sec; |
| 4782 | |
| 4783 | /* |
| 4784 | * Remote port registration is still going on from |
| 4785 | * previous login. Allow it to finish before we |
| 4786 | * accept the new login. |
| 4787 | */ |
| 4788 | sess->next_disc_state = DSC_DELETE_PEND; |
| 4789 | sec = jiffies_to_msecs(jiffies - |
| 4790 | sess->jiffies_at_registration) / 1000; |
| 4791 | if (sess->sec_since_registration < sec && sec && |
| 4792 | !(sec % 5)) { |
| 4793 | sess->sec_since_registration = sec; |
| 4794 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4795 | "%s %8phC - Slow Rport registration (%d Sec)\n", |
| 4796 | __func__, sess->port_name, sec); |
| 4797 | } |
| 4798 | |
| 4799 | if (!conflict_sess) |
| 4800 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 4801 | |
| 4802 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4803 | goto out; |
| 4804 | } |
| 4805 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4806 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
| 4807 | sess->d_id = port_id; |
| 4808 | sess->login_gen++; |
| 4809 | |
| 4810 | if (iocb->u.isp24.status_subcode == ELS_PRLI) { |
| 4811 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4812 | sess->local = 0; |
| 4813 | sess->loop_id = loop_id; |
| 4814 | sess->d_id = port_id; |
| 4815 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4816 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4817 | |
| 4818 | if (wd3_lo & BIT_7) |
| 4819 | sess->conf_compl_supported = 1; |
| 4820 | |
| 4821 | if ((wd3_lo & BIT_4) == 0) |
| 4822 | sess->port_type = FCT_INITIATOR; |
| 4823 | else |
| 4824 | sess->port_type = FCT_TARGET; |
| 4825 | |
| 4826 | } else |
| 4827 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4828 | |
| 4829 | |
| 4830 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4831 | "%s %d %8phC DS %d\n", |
| 4832 | __func__, __LINE__, sess->port_name, sess->disc_state); |
| 4833 | |
| 4834 | switch (sess->disc_state) { |
| 4835 | case DSC_DELETED: |
| 4836 | qlt_plogi_ack_unref(vha, pla); |
| 4837 | break; |
| 4838 | |
| 4839 | default: |
| 4840 | /* |
| 4841 | * Under normal circumstances we want to release nport handle |
| 4842 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4843 | * The exception is when LOGO is done while another PLOGI with |
| 4844 | * the same nport handle is waiting as might be the case here. |
| 4845 | * Note: there is always a possibily of a race where session |
| 4846 | * deletion has already started for other reasons (e.g. ACL |
| 4847 | * removal) and now PLOGI arrives: |
| 4848 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4849 | * FW must have assigned this PLOGI a new/same handle and we |
| 4850 | * can proceed ACK'ing it as usual when session deletion |
| 4851 | * completes. |
| 4852 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4853 | * bit reached it, the handle has now been released. We'll |
| 4854 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4855 | * back to initiator. Initiator should eventually retry |
| 4856 | * PLOGI and situation will correct itself. |
| 4857 | */ |
| 4858 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4859 | (sess->d_id.b24 == port_id.b24)); |
| 4860 | |
| 4861 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4862 | "%s %d %8phC post del sess\n", |
| 4863 | __func__, __LINE__, sess->port_name); |
| 4864 | |
| 4865 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4866 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4867 | break; |
| 4868 | } |
| 4869 | out: |
| 4870 | return res; |
| 4871 | } |
| 4872 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4873 | /* |
| 4874 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4875 | */ |
| 4876 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4877 | struct imm_ntfy_from_isp *iocb) |
| 4878 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4879 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4880 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4881 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4882 | uint64_t wwn; |
| 4883 | port_id_t port_id; |
| 4884 | uint16_t loop_id; |
| 4885 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4886 | int res = 0; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4887 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4888 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 4889 | lockdep_assert_held(&ha->hardware_lock); |
| 4890 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4891 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4892 | |
| 4893 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4894 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4895 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4896 | port_id.b.rsvd_1 = 0; |
| 4897 | |
| 4898 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4899 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4900 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4901 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4902 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4903 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4904 | iocb->u.isp24.status_subcode, loop_id, |
| 4905 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4906 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4907 | /* res = 1 means ack at the end of thread |
| 4908 | * res = 0 means ack async/later. |
| 4909 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4910 | switch (iocb->u.isp24.status_subcode) { |
| 4911 | case ELS_PLOGI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4912 | res = qlt_handle_login(vha, iocb); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4913 | break; |
| 4914 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4915 | case ELS_PRLI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4916 | if (N2N_TOPO(ha)) { |
| 4917 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4918 | iocb->u.isp24.port_name, 1); |
| 4919 | |
| 4920 | if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) { |
| 4921 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4922 | "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n", |
| 4923 | __func__, __LINE__, |
| 4924 | iocb->u.isp24.port_name); |
| 4925 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4926 | break; |
| 4927 | } |
| 4928 | |
| 4929 | res = qlt_handle_login(vha, iocb); |
| 4930 | break; |
| 4931 | } |
| 4932 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4933 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4934 | res = 1; |
| 4935 | break; |
| 4936 | } |
| 4937 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4938 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4939 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4940 | if (wwn) { |
| 4941 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4942 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4943 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4944 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4945 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4946 | |
| 4947 | if (conflict_sess) { |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 4948 | switch (conflict_sess->disc_state) { |
| 4949 | case DSC_DELETED: |
| 4950 | case DSC_DELETE_PEND: |
| 4951 | break; |
| 4952 | default: |
| 4953 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4954 | "PRLI with conflicting sess %p port %8phC\n", |
| 4955 | conflict_sess, conflict_sess->port_name); |
| 4956 | conflict_sess->fw_login_state = |
| 4957 | DSC_LS_PORT_UNAVAIL; |
| 4958 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4959 | res = 0; |
| 4960 | break; |
| 4961 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4962 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4963 | |
| 4964 | if (sess != NULL) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4965 | bool delete = false; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4966 | int sec; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 4967 | |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4968 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
| 4969 | switch (sess->fw_login_state) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4970 | case DSC_LS_PLOGI_PEND: |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4971 | case DSC_LS_PLOGI_COMP: |
| 4972 | case DSC_LS_PRLI_COMP: |
| 4973 | break; |
| 4974 | default: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4975 | delete = true; |
| 4976 | break; |
| 4977 | } |
| 4978 | |
| 4979 | switch (sess->disc_state) { |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4980 | case DSC_UPD_FCPORT: |
| 4981 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 4982 | flags); |
| 4983 | |
| 4984 | sec = jiffies_to_msecs(jiffies - |
| 4985 | sess->jiffies_at_registration)/1000; |
| 4986 | if (sess->sec_since_registration < sec && sec && |
| 4987 | !(sec % 5)) { |
| 4988 | sess->sec_since_registration = sec; |
| 4989 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 4990 | "%s %8phC : Slow Rport registration(%d Sec)\n", |
| 4991 | __func__, sess->port_name, sec); |
| 4992 | } |
| 4993 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4994 | return 0; |
| 4995 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4996 | case DSC_LOGIN_PEND: |
| 4997 | case DSC_GPDB: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4998 | case DSC_LOGIN_COMPLETE: |
| 4999 | case DSC_ADISC: |
| 5000 | delete = false; |
| 5001 | break; |
| 5002 | default: |
| 5003 | break; |
| 5004 | } |
| 5005 | |
| 5006 | if (delete) { |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 5007 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 5008 | flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5009 | /* |
| 5010 | * Impatient initiator sent PRLI before last |
| 5011 | * PLOGI could finish. Will force him to re-try, |
| 5012 | * while last one finishes. |
| 5013 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5014 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5015 | "sess %p PRLI received, before plogi ack.\n", |
| 5016 | sess); |
| 5017 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 5018 | res = 0; |
| 5019 | break; |
| 5020 | } |
| 5021 | |
| 5022 | /* |
| 5023 | * This shouldn't happen under normal circumstances, |
| 5024 | * since we have deleted the old session during PLOGI |
| 5025 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5026 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5027 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 5028 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 5029 | |
| 5030 | sess->local = 0; |
| 5031 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 5032 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5033 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5034 | |
| 5035 | if (wd3_lo & BIT_7) |
| 5036 | sess->conf_compl_supported = 1; |
| 5037 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5038 | if ((wd3_lo & BIT_4) == 0) |
| 5039 | sess->port_type = FCT_INITIATOR; |
| 5040 | else |
| 5041 | sess->port_type = FCT_TARGET; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 5042 | |
| 5043 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5044 | } |
| 5045 | res = 1; /* send notify ack */ |
| 5046 | |
| 5047 | /* Make session global (not used in fabric mode) */ |
| 5048 | if (ha->current_topology != ISP_CFG_F) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5049 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5050 | ql_dbg(ql_dbg_disc, vha, 0x20fa, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5051 | "%s %d %8phC post nack\n", |
| 5052 | __func__, __LINE__, sess->port_name); |
| 5053 | qla24xx_post_nack_work(vha, sess, iocb, |
| 5054 | SRB_NACK_PRLI); |
| 5055 | res = 0; |
| 5056 | } else { |
| 5057 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5058 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5059 | qla2xxx_wake_dpc(vha); |
| 5060 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5061 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5062 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5063 | ql_dbg(ql_dbg_disc, vha, 0x20fb, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5064 | "%s %d %8phC post nack\n", |
| 5065 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5066 | qla24xx_post_nack_work(vha, sess, iocb, |
| 5067 | SRB_NACK_PRLI); |
| 5068 | res = 0; |
| 5069 | } |
| 5070 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5071 | break; |
| 5072 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5073 | case ELS_TPRLO: |
| 5074 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 5075 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 5076 | loop_id = 0xFFFF; |
| 5077 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 5078 | res = 1; |
| 5079 | break; |
| 5080 | } |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 5081 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5082 | case ELS_LOGO: |
| 5083 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5084 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 5085 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 5086 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 5087 | |
| 5088 | if (sess) { |
| 5089 | sess->login_gen++; |
| 5090 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5091 | sess->logo_ack_needed = 1; |
| 5092 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 5093 | } |
| 5094 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5095 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5096 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5097 | ql_dbg(ql_dbg_disc, vha, 0x20fc, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5098 | "%s: logo %llx res %d sess %p ", |
| 5099 | __func__, wwn, res, sess); |
| 5100 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5101 | /* |
| 5102 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 5103 | * for LOGO_ACK & sess delete |
| 5104 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5105 | BUG_ON(!sess); |
| 5106 | res = 0; |
| 5107 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5108 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5109 | if (sess) { |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 5110 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5111 | res = 0; |
| 5112 | } |
| 5113 | /* else logo will be ack */ |
| 5114 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5115 | break; |
| 5116 | case ELS_PDISC: |
| 5117 | case ELS_ADISC: |
| 5118 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5119 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5120 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5121 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5122 | qlt_send_notify_ack(ha->base_qpair, |
| 5123 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5124 | tgt->link_reinit_iocb_pending = 0; |
| 5125 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5126 | |
| 5127 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 5128 | iocb->u.isp24.port_name, 1); |
| 5129 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5130 | ql_dbg(ql_dbg_disc, vha, 0x20fd, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5131 | "sess %p lid %d|%d DS %d LS %d\n", |
| 5132 | sess, sess->loop_id, loop_id, |
| 5133 | sess->disc_state, sess->fw_login_state); |
| 5134 | } |
| 5135 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5136 | res = 1; /* send notify ack */ |
| 5137 | break; |
| 5138 | } |
| 5139 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5140 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5141 | default: |
| 5142 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 5143 | "qla_target(%d): Unsupported ELS command %x " |
| 5144 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 5145 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 5146 | break; |
| 5147 | } |
| 5148 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 5149 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 5150 | "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n", |
| 5151 | vha->vp_idx, iocb->u.isp24.status_subcode, res); |
| 5152 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5153 | return res; |
| 5154 | } |
| 5155 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5156 | /* |
| 5157 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5158 | */ |
| 5159 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 5160 | struct imm_ntfy_from_isp *iocb) |
| 5161 | { |
| 5162 | struct qla_hw_data *ha = vha->hw; |
| 5163 | uint32_t add_flags = 0; |
| 5164 | int send_notify_ack = 1; |
| 5165 | uint16_t status; |
| 5166 | |
Bart Van Assche | 57bf595 | 2019-08-08 20:01:34 -0700 | [diff] [blame] | 5167 | lockdep_assert_held(&ha->hardware_lock); |
| 5168 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5169 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 5170 | switch (status) { |
| 5171 | case IMM_NTFY_LIP_RESET: |
| 5172 | { |
| 5173 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 5174 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 5175 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5176 | iocb->u.isp24.status_subcode); |
| 5177 | |
| 5178 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5179 | send_notify_ack = 0; |
| 5180 | break; |
| 5181 | } |
| 5182 | |
| 5183 | case IMM_NTFY_LIP_LINK_REINIT: |
| 5184 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5185 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5186 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5187 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 5188 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 5189 | "subcode %x)\n", vha->vp_idx, |
| 5190 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5191 | iocb->u.isp24.status_subcode); |
| 5192 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5193 | qlt_send_notify_ack(ha->base_qpair, |
| 5194 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5195 | } |
| 5196 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 5197 | tgt->link_reinit_iocb_pending = 1; |
| 5198 | /* |
| 5199 | * QLogic requires to wait after LINK REINIT for possible |
| 5200 | * PDISC or ADISC ELS commands |
| 5201 | */ |
| 5202 | send_notify_ack = 0; |
| 5203 | break; |
| 5204 | } |
| 5205 | |
| 5206 | case IMM_NTFY_PORT_LOGOUT: |
| 5207 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 5208 | "qla_target(%d): Port logout (loop " |
| 5209 | "%#x, subcode %x)\n", vha->vp_idx, |
| 5210 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5211 | iocb->u.isp24.status_subcode); |
| 5212 | |
| 5213 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 5214 | send_notify_ack = 0; |
| 5215 | /* The sessions will be cleared in the callback, if needed */ |
| 5216 | break; |
| 5217 | |
| 5218 | case IMM_NTFY_GLBL_TPRLO: |
| 5219 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 5220 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 5221 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5222 | send_notify_ack = 0; |
| 5223 | /* The sessions will be cleared in the callback, if needed */ |
| 5224 | break; |
| 5225 | |
| 5226 | case IMM_NTFY_PORT_CONFIG: |
| 5227 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 5228 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 5229 | status); |
| 5230 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5231 | send_notify_ack = 0; |
| 5232 | /* The sessions will be cleared in the callback, if needed */ |
| 5233 | break; |
| 5234 | |
| 5235 | case IMM_NTFY_GLBL_LOGO: |
| 5236 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 5237 | "qla_target(%d): Link failure detected\n", |
| 5238 | vha->vp_idx); |
| 5239 | /* I_T nexus loss */ |
| 5240 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5241 | send_notify_ack = 0; |
| 5242 | break; |
| 5243 | |
| 5244 | case IMM_NTFY_IOCB_OVERFLOW: |
| 5245 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 5246 | "qla_target(%d): Cannot provide requested " |
| 5247 | "capability (IOCB overflowed the immediate notify " |
| 5248 | "resource count)\n", vha->vp_idx); |
| 5249 | break; |
| 5250 | |
| 5251 | case IMM_NTFY_ABORT_TASK: |
| 5252 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 5253 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 5254 | "L %#x)\n", vha->vp_idx, |
| 5255 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 5256 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 5257 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 5258 | if (qlt_abort_task(vha, iocb) == 0) |
| 5259 | send_notify_ack = 0; |
| 5260 | break; |
| 5261 | |
| 5262 | case IMM_NTFY_RESOURCE: |
| 5263 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 5264 | "qla_target(%d): Out of resources, host %ld\n", |
| 5265 | vha->vp_idx, vha->host_no); |
| 5266 | break; |
| 5267 | |
| 5268 | case IMM_NTFY_MSG_RX: |
| 5269 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 5270 | "qla_target(%d): Immediate notify task %x\n", |
| 5271 | vha->vp_idx, iocb->u.isp2x.task_flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5272 | break; |
| 5273 | |
| 5274 | case IMM_NTFY_ELS: |
| 5275 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 5276 | send_notify_ack = 0; |
| 5277 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5278 | default: |
| 5279 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 5280 | "qla_target(%d): Received unknown immediate " |
| 5281 | "notify status %x\n", vha->vp_idx, status); |
| 5282 | break; |
| 5283 | } |
| 5284 | |
| 5285 | if (send_notify_ack) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5286 | qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0, |
| 5287 | 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | /* |
| 5291 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5292 | * This function sends busy to ISP 2xxx or 24xx. |
| 5293 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5294 | static int __qlt_send_busy(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5295 | struct atio_from_isp *atio, uint16_t status) |
| 5296 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5297 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5298 | struct ctio7_to_24xx *ctio24; |
| 5299 | struct qla_hw_data *ha = vha->hw; |
| 5300 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5301 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5302 | unsigned long flags; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5303 | u16 temp; |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame] | 5304 | port_id_t id; |
| 5305 | |
| 5306 | id.b.al_pa = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5307 | id.b.area = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5308 | id.b.domain = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5309 | id.b.rsvd_1 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5310 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5311 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame] | 5312 | sess = qla2x00_find_fcport_by_nportid(vha, &id, 1); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5313 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5314 | if (!sess) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5315 | qlt_send_term_exchange(qpair, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5316 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5317 | } |
| 5318 | /* Sending marker isn't necessary, since we called from ISR */ |
| 5319 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5320 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5321 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5322 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5323 | "qla_target(%d): %s failed: unable to allocate " |
| 5324 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5325 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5326 | } |
| 5327 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5328 | qpair->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5329 | pkt->entry_count = 1; |
| 5330 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5331 | |
| 5332 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5333 | ctio24->entry_type = CTIO_TYPE7; |
| 5334 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5335 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5336 | ctio24->vp_index = vha->vp_idx; |
| 5337 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5338 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5339 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5340 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5341 | temp = (atio->u.isp24.attr << 9) | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5342 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5343 | CTIO7_FLAGS_DONT_RET_CTIO; |
| 5344 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5345 | /* |
| 5346 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5347 | * if the explicit conformation is used. |
| 5348 | */ |
| 5349 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 5350 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 5351 | |
| 5352 | ctio24->u.status1.residual = get_datalen_for_atio(atio); |
| 5353 | |
| 5354 | if (ctio24->u.status1.residual != 0) |
| 5355 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 5356 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5357 | /* Memory Barrier */ |
| 5358 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 5359 | if (qpair->reqq_start_iocbs) |
| 5360 | qpair->reqq_start_iocbs(qpair); |
| 5361 | else |
| 5362 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5363 | return 0; |
| 5364 | } |
| 5365 | |
| 5366 | /* |
| 5367 | * This routine is used to allocate a command for either a QFull condition |
| 5368 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5369 | * out previously. |
| 5370 | */ |
| 5371 | static void |
| 5372 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5373 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5374 | { |
| 5375 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5376 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5377 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5378 | struct se_session *se_sess; |
| 5379 | struct qla_tgt_cmd *cmd; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5380 | int tag, cpu; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5381 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5382 | |
| 5383 | if (unlikely(tgt->tgt_stop)) { |
| 5384 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5385 | "New command while device %p is shutting down\n", tgt); |
| 5386 | return; |
| 5387 | } |
| 5388 | |
| 5389 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5390 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5391 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5392 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5393 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5394 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5395 | |
| 5396 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5397 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5398 | vha->vp_idx, __func__, |
| 5399 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5400 | |
| 5401 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5402 | return; |
| 5403 | } |
| 5404 | |
| 5405 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5406 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5407 | if (!sess) |
| 5408 | return; |
| 5409 | |
| 5410 | se_sess = sess->se_sess; |
| 5411 | |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5412 | tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu); |
Bart Van Assche | c04466c | 2019-04-17 14:44:27 -0700 | [diff] [blame] | 5413 | if (tag < 0) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5414 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5415 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5416 | vha->vp_idx, __func__); |
| 5417 | |
| 5418 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5419 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5420 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5421 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5422 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5423 | |
| 5424 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5425 | return; |
| 5426 | } |
| 5427 | |
Bart Van Assche | c04466c | 2019-04-17 14:44:27 -0700 | [diff] [blame] | 5428 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5429 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 5430 | |
| 5431 | qlt_incr_num_pend_cmds(vha); |
| 5432 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5433 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5434 | |
| 5435 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5436 | cmd->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5437 | cmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5438 | cmd->q_full = 1; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5439 | cmd->qpair = ha->base_qpair; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5440 | cmd->se_cmd.map_cpu = cpu; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5441 | |
| 5442 | if (qfull) { |
| 5443 | cmd->q_full = 1; |
| 5444 | /* NOTE: borrowing the state field to carry the status */ |
| 5445 | cmd->state = status; |
| 5446 | } else |
| 5447 | cmd->term_exchg = 1; |
| 5448 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5449 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5450 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5451 | |
| 5452 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5453 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5454 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5455 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5456 | vha->hw->tgt.num_qfull_cmds_alloc; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5457 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5461 | qlt_free_qfull_cmds(struct qla_qpair *qpair) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5462 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5463 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5464 | struct qla_hw_data *ha = vha->hw; |
| 5465 | unsigned long flags; |
| 5466 | struct qla_tgt_cmd *cmd, *tcmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5467 | struct list_head free_list, q_full_list; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5468 | int rc = 0; |
| 5469 | |
| 5470 | if (list_empty(&ha->tgt.q_full_list)) |
| 5471 | return 0; |
| 5472 | |
| 5473 | INIT_LIST_HEAD(&free_list); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5474 | INIT_LIST_HEAD(&q_full_list); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5475 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5476 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5477 | if (list_empty(&ha->tgt.q_full_list)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5478 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5479 | return 0; |
| 5480 | } |
| 5481 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5482 | list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list); |
| 5483 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5484 | |
| 5485 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 5486 | list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5487 | if (cmd->q_full) |
| 5488 | /* cmd->state is a borrowed field to hold status */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5489 | rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5490 | else if (cmd->term_exchg) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5491 | rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5492 | |
| 5493 | if (rc == -ENOMEM) |
| 5494 | break; |
| 5495 | |
| 5496 | if (cmd->q_full) |
| 5497 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5498 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5499 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5500 | else if (cmd->term_exchg) |
| 5501 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5502 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5503 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5504 | else |
| 5505 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5506 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5507 | cmd); |
| 5508 | |
| 5509 | list_del(&cmd->cmd_list); |
| 5510 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5511 | |
| 5512 | /* piggy back on hardware_lock for protection */ |
| 5513 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5514 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5515 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5516 | |
| 5517 | cmd = NULL; |
| 5518 | |
| 5519 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5520 | list_del(&cmd->cmd_list); |
| 5521 | /* This cmd was never sent to TCM. There is no need |
| 5522 | * to schedule free or call free_cmd |
| 5523 | */ |
| 5524 | qlt_free_cmd(cmd); |
| 5525 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5526 | |
| 5527 | if (!list_empty(&q_full_list)) { |
| 5528 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 5529 | list_splice(&q_full_list, &vha->hw->tgt.q_full_list); |
| 5530 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5531 | } |
| 5532 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5533 | return rc; |
| 5534 | } |
| 5535 | |
| 5536 | static void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5537 | qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio, |
| 5538 | uint16_t status) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5539 | { |
| 5540 | int rc = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5541 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5542 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5543 | rc = __qlt_send_busy(qpair, atio, status); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5544 | if (rc == -ENOMEM) |
| 5545 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5546 | } |
| 5547 | |
| 5548 | static int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5549 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair, |
| 5550 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5551 | { |
| 5552 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5553 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5554 | |
| 5555 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5556 | return 0; |
| 5557 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5558 | if (!ha_locked) |
| 5559 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5560 | qlt_send_busy(qpair, atio, qla_sam_status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5561 | if (!ha_locked) |
| 5562 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5563 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5564 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | /* ha->hardware_lock supposed to be held on entry */ |
| 5568 | /* called via callback from qla2xxx */ |
| 5569 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5570 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5571 | { |
| 5572 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5573 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5574 | int rc; |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5575 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5576 | |
| 5577 | if (unlikely(tgt == NULL)) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5578 | ql_dbg(ql_dbg_tgt, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5579 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5580 | return; |
| 5581 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5582 | /* |
| 5583 | * In tgt_stop mode we also should allow all requests to pass. |
| 5584 | * Otherwise, some commands can stuck. |
| 5585 | */ |
| 5586 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5587 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5588 | |
| 5589 | switch (atio->u.raw.entry_type) { |
| 5590 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5591 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5592 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5593 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5594 | "qla_target(%d): ATIO_TYPE7 " |
| 5595 | "received with UNKNOWN exchange address, " |
| 5596 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5597 | if (!ha_locked) |
| 5598 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5599 | qlt_send_busy(ha->base_qpair, atio, qla_sam_status); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5600 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5601 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5602 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5603 | break; |
| 5604 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5605 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5606 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5607 | rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair, |
| 5608 | atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5609 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5610 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5611 | return; |
| 5612 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5613 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5614 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5615 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5616 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5617 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5618 | if (!ha_locked) |
| 5619 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5620 | switch (rc) { |
| 5621 | case -ENODEV: |
| 5622 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5623 | "qla_target: Unable to send command to target\n"); |
| 5624 | break; |
| 5625 | case -EBADF: |
| 5626 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5627 | "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5628 | qlt_send_term_exchange(ha->base_qpair, NULL, |
| 5629 | atio, 1, 0); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5630 | break; |
| 5631 | case -EBUSY: |
| 5632 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5633 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5634 | vha->vp_idx); |
| 5635 | qlt_send_busy(ha->base_qpair, atio, |
| 5636 | tc_sam_status); |
| 5637 | break; |
| 5638 | default: |
| 5639 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5640 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5641 | vha->vp_idx); |
| 5642 | qlt_send_busy(ha->base_qpair, atio, |
| 5643 | qla_sam_status); |
| 5644 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5645 | } |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5646 | if (!ha_locked) |
| 5647 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5648 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5649 | } |
| 5650 | break; |
| 5651 | |
| 5652 | case IMMED_NOTIFY_TYPE: |
| 5653 | { |
| 5654 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5655 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5656 | "qla_target(%d): Received ATIO packet %x " |
| 5657 | "with error status %x\n", vha->vp_idx, |
| 5658 | atio->u.raw.entry_type, |
| 5659 | atio->u.isp2x.entry_status); |
| 5660 | break; |
| 5661 | } |
| 5662 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5663 | |
| 5664 | if (!ha_locked) |
| 5665 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5666 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5667 | if (!ha_locked) |
| 5668 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5669 | break; |
| 5670 | } |
| 5671 | |
| 5672 | default: |
| 5673 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5674 | "qla_target(%d): Received unknown ATIO atio " |
| 5675 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5676 | break; |
| 5677 | } |
| 5678 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5679 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5680 | } |
| 5681 | |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 5682 | /* |
| 5683 | * qpair lock is assume to be held |
| 5684 | * rc = 0 : send terminate & abts respond |
| 5685 | * rc != 0: do not send term & abts respond |
| 5686 | */ |
| 5687 | static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha, |
| 5688 | struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry) |
| 5689 | { |
| 5690 | struct qla_hw_data *ha = vha->hw; |
| 5691 | int rc = 0; |
| 5692 | |
| 5693 | /* |
| 5694 | * Detect unresolved exchange. If the same ABTS is unable |
| 5695 | * to terminate an existing command and the same ABTS loops |
| 5696 | * between FW & Driver, then force FW dump. Under 1 jiff, |
| 5697 | * we should see multiple loops. |
| 5698 | */ |
| 5699 | if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort && |
| 5700 | qpair->retry_term_jiff == jiffies) { |
| 5701 | /* found existing exchange */ |
| 5702 | qpair->retry_term_cnt++; |
| 5703 | if (qpair->retry_term_cnt >= 5) { |
| 5704 | rc = EIO; |
| 5705 | qpair->retry_term_cnt = 0; |
| 5706 | ql_log(ql_log_warn, vha, 0xffff, |
| 5707 | "Unable to send ABTS Respond. Dumping firmware.\n"); |
| 5708 | ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer, |
| 5709 | vha, 0xffff, (uint8_t *)entry, sizeof(*entry)); |
| 5710 | |
| 5711 | if (qpair == ha->base_qpair) |
| 5712 | ha->isp_ops->fw_dump(vha, 1); |
| 5713 | else |
| 5714 | ha->isp_ops->fw_dump(vha, 0); |
| 5715 | |
| 5716 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5717 | qla2xxx_wake_dpc(vha); |
| 5718 | } |
| 5719 | } else if (qpair->retry_term_jiff != jiffies) { |
| 5720 | qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort; |
| 5721 | qpair->retry_term_cnt = 0; |
| 5722 | qpair->retry_term_jiff = jiffies; |
| 5723 | } |
| 5724 | |
| 5725 | return rc; |
| 5726 | } |
| 5727 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5728 | |
| 5729 | static void qlt_handle_abts_completion(struct scsi_qla_host *vha, |
| 5730 | struct rsp_que *rsp, response_t *pkt) |
| 5731 | { |
| 5732 | struct abts_resp_from_24xx_fw *entry = |
| 5733 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5734 | u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK; |
| 5735 | struct qla_tgt_mgmt_cmd *mcmd; |
| 5736 | struct qla_hw_data *ha = vha->hw; |
| 5737 | |
Bart Van Assche | 81bcf1c | 2019-04-11 14:53:24 -0700 | [diff] [blame] | 5738 | mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5739 | if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) { |
| 5740 | ql_dbg(ql_dbg_async, vha, 0xe064, |
| 5741 | "qla_target(%d): ABTS Comp without mcmd\n", |
| 5742 | vha->vp_idx); |
| 5743 | return; |
| 5744 | } |
| 5745 | |
| 5746 | if (mcmd) |
| 5747 | vha = mcmd->vha; |
| 5748 | vha->vha_tgt.qla_tgt->abts_resp_expected--; |
| 5749 | |
| 5750 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5751 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5752 | entry->compl_status); |
| 5753 | |
| 5754 | if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) { |
| 5755 | if ((entry->error_subcode1 == 0x1E) && |
| 5756 | (entry->error_subcode2 == 0)) { |
| 5757 | if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) { |
| 5758 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5759 | return; |
| 5760 | } |
| 5761 | qlt_24xx_retry_term_exchange(vha, rsp->qpair, |
| 5762 | pkt, mcmd); |
| 5763 | } else { |
| 5764 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5765 | "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)", |
| 5766 | vha->vp_idx, entry->compl_status, |
| 5767 | entry->error_subcode1, |
| 5768 | entry->error_subcode2); |
| 5769 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5770 | } |
| 5771 | } else { |
| 5772 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5773 | } |
| 5774 | } |
| 5775 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5776 | /* ha->hardware_lock supposed to be held on entry */ |
| 5777 | /* called via callback from qla2xxx */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5778 | static void qlt_response_pkt(struct scsi_qla_host *vha, |
| 5779 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5780 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5781 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5782 | |
| 5783 | if (unlikely(tgt == NULL)) { |
| 5784 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5785 | "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n", |
| 5786 | vha->vp_idx, pkt->entry_type, vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5787 | return; |
| 5788 | } |
| 5789 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5790 | /* |
| 5791 | * In tgt_stop mode we also should allow all requests to pass. |
| 5792 | * Otherwise, some commands can stuck. |
| 5793 | */ |
| 5794 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5795 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5796 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5797 | case CTIO_TYPE7: |
| 5798 | { |
| 5799 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5800 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5801 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5802 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5803 | entry); |
| 5804 | break; |
| 5805 | } |
| 5806 | |
| 5807 | case ACCEPT_TGT_IO_TYPE: |
| 5808 | { |
| 5809 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5810 | int rc; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5811 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5812 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5813 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5814 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5815 | "qla_target(%d): ATIO with error " |
| 5816 | "status %x received\n", vha->vp_idx, |
| 5817 | le16_to_cpu(atio->u.isp2x.status)); |
| 5818 | break; |
| 5819 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5820 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5821 | rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1); |
Quinn Tran | ba68a63 | 2017-06-02 09:12:06 -0700 | [diff] [blame] | 5822 | if (rc != 0) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5823 | return; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5824 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5825 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5826 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5827 | switch (rc) { |
| 5828 | case -ENODEV: |
| 5829 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5830 | "qla_target: Unable to send command to target\n"); |
| 5831 | break; |
| 5832 | case -EBADF: |
| 5833 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5834 | "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); |
| 5835 | qlt_send_term_exchange(rsp->qpair, NULL, |
| 5836 | atio, 1, 0); |
| 5837 | break; |
| 5838 | case -EBUSY: |
| 5839 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5840 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5841 | vha->vp_idx); |
| 5842 | qlt_send_busy(rsp->qpair, atio, |
| 5843 | tc_sam_status); |
| 5844 | break; |
| 5845 | default: |
| 5846 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5847 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5848 | vha->vp_idx); |
| 5849 | qlt_send_busy(rsp->qpair, atio, |
| 5850 | qla_sam_status); |
| 5851 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5852 | } |
| 5853 | } |
| 5854 | } |
| 5855 | break; |
| 5856 | |
| 5857 | case CONTINUE_TGT_IO_TYPE: |
| 5858 | { |
| 5859 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5860 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5861 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5862 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5863 | entry); |
| 5864 | break; |
| 5865 | } |
| 5866 | |
| 5867 | case CTIO_A64_TYPE: |
| 5868 | { |
| 5869 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5870 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5871 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5872 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5873 | entry); |
| 5874 | break; |
| 5875 | } |
| 5876 | |
| 5877 | case IMMED_NOTIFY_TYPE: |
| 5878 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5879 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5880 | break; |
| 5881 | |
| 5882 | case NOTIFY_ACK_TYPE: |
| 5883 | if (tgt->notify_ack_expected > 0) { |
| 5884 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5885 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5886 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5887 | "NOTIFY_ACK seq %08x status %x\n", |
| 5888 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5889 | le16_to_cpu(entry->u.isp2x.status)); |
| 5890 | tgt->notify_ack_expected--; |
| 5891 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5892 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5893 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5894 | "qla_target(%d): NOTIFY_ACK " |
| 5895 | "failed %x\n", vha->vp_idx, |
| 5896 | le16_to_cpu(entry->u.isp2x.status)); |
| 5897 | } |
| 5898 | } else { |
| 5899 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5900 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5901 | vha->vp_idx); |
| 5902 | } |
| 5903 | break; |
| 5904 | |
| 5905 | case ABTS_RECV_24XX: |
| 5906 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5907 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5908 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5909 | break; |
| 5910 | |
| 5911 | case ABTS_RESP_24XX: |
| 5912 | if (tgt->abts_resp_expected > 0) { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5913 | qlt_handle_abts_completion(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5914 | } else { |
| 5915 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5916 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5917 | "received\n", vha->vp_idx); |
| 5918 | } |
| 5919 | break; |
| 5920 | |
| 5921 | default: |
| 5922 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5923 | "qla_target(%d): Received unknown response pkt " |
| 5924 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5925 | break; |
| 5926 | } |
| 5927 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5928 | } |
| 5929 | |
| 5930 | /* |
| 5931 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5932 | */ |
| 5933 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5934 | uint16_t *mailbox) |
| 5935 | { |
| 5936 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5937 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5938 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5939 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 5940 | if (!tgt || tgt->tgt_stop || tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5941 | return; |
| 5942 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5943 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5944 | IS_QLA2100(ha)) |
| 5945 | return; |
| 5946 | /* |
| 5947 | * In tgt_stop mode we also should allow all requests to pass. |
| 5948 | * Otherwise, some commands can stuck. |
| 5949 | */ |
| 5950 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5951 | |
| 5952 | switch (code) { |
| 5953 | case MBA_RESET: /* Reset */ |
| 5954 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5955 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5956 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5957 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5958 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5959 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5960 | break; |
| 5961 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5962 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5963 | break; |
| 5964 | |
| 5965 | case MBA_LOOP_UP: |
| 5966 | { |
| 5967 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5968 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5969 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5970 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5971 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5972 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5973 | qlt_send_notify_ack(ha->base_qpair, |
| 5974 | (void *)&tgt->link_reinit_iocb, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5975 | 0, 0, 0, 0, 0, 0); |
| 5976 | tgt->link_reinit_iocb_pending = 0; |
| 5977 | } |
| 5978 | break; |
| 5979 | } |
| 5980 | |
| 5981 | case MBA_LIP_OCCURRED: |
| 5982 | case MBA_LOOP_DOWN: |
| 5983 | case MBA_LIP_RESET: |
| 5984 | case MBA_RSCN_UPDATE: |
| 5985 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5986 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5987 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5988 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5989 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5990 | break; |
| 5991 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5992 | case MBA_REJECTED_FCP_CMD: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5993 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017, |
| 5994 | "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", |
| 5995 | vha->vp_idx, |
| 5996 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5997 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5998 | |
| 5999 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 6000 | /* exchange starvation. */ |
| 6001 | vha->hw->exch_starvation++; |
| 6002 | if (vha->hw->exch_starvation > 5) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6003 | ql_log(ql_log_warn, vha, 0xd03a, |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6004 | "Exchange starvation-. Resetting RISC\n"); |
| 6005 | |
| 6006 | vha->hw->exch_starvation = 0; |
| 6007 | if (IS_P3P_TYPE(vha->hw)) |
| 6008 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 6009 | &vha->dpc_flags); |
| 6010 | else |
| 6011 | set_bit(ISP_ABORT_NEEDED, |
| 6012 | &vha->dpc_flags); |
| 6013 | qla2xxx_wake_dpc(vha); |
| 6014 | } |
| 6015 | } |
| 6016 | break; |
| 6017 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6018 | case MBA_PORT_UPDATE: |
| 6019 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 6020 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 6021 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 6022 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 6023 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 6024 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 6025 | |
| 6026 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6027 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6028 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 6029 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6030 | vha->hw->exch_starvation = 0; |
| 6031 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6032 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 6033 | "Async MB 2: Port Logged Out\n"); |
| 6034 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6035 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6036 | break; |
| 6037 | } |
| 6038 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6039 | } |
| 6040 | |
| 6041 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 6042 | uint16_t loop_id) |
| 6043 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6044 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6045 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6046 | unsigned long flags; |
| 6047 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6048 | |
Quinn Tran | 063b36d | 2017-12-04 14:45:10 -0800 | [diff] [blame] | 6049 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6050 | if (!fcport) { |
| 6051 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 6052 | "qla_target(%d): Allocation of tmp FC port failed", |
| 6053 | vha->vp_idx); |
| 6054 | return NULL; |
| 6055 | } |
| 6056 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6057 | fcport->loop_id = loop_id; |
| 6058 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 6059 | rc = qla24xx_gpdb_wait(vha, fcport, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6060 | if (rc != QLA_SUCCESS) { |
| 6061 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 6062 | "qla_target(%d): Failed to retrieve fcport " |
| 6063 | "information -- get_port_database() returned %x " |
| 6064 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 6065 | kfree(fcport); |
| 6066 | return NULL; |
| 6067 | } |
| 6068 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6069 | del = NULL; |
| 6070 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 6071 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 6072 | |
| 6073 | if (tfcp) { |
| 6074 | tfcp->d_id = fcport->d_id; |
| 6075 | tfcp->port_type = fcport->port_type; |
| 6076 | tfcp->supported_classes = fcport->supported_classes; |
| 6077 | tfcp->flags |= fcport->flags; |
Quinn Tran | 76f9a2d | 2017-12-04 14:45:11 -0800 | [diff] [blame] | 6078 | tfcp->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6079 | |
| 6080 | del = fcport; |
| 6081 | fcport = tfcp; |
| 6082 | } else { |
| 6083 | if (vha->hw->current_topology == ISP_CFG_F) |
| 6084 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 6085 | |
| 6086 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 6087 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 6088 | vha->fcport_count++; |
| 6089 | fcport->login_gen++; |
| 6090 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 6091 | fcport->login_succ = 1; |
| 6092 | newfcport = 1; |
| 6093 | } |
| 6094 | |
| 6095 | fcport->deleted = 0; |
| 6096 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 6097 | |
| 6098 | switch (vha->host->active_mode) { |
| 6099 | case MODE_INITIATOR: |
| 6100 | case MODE_DUAL: |
| 6101 | if (newfcport) { |
| 6102 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 6103 | qla24xx_sched_upd_fcport(fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6104 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6105 | ql_dbg(ql_dbg_disc, vha, 0x20ff, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6106 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 6107 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 6108 | qla24xx_post_gpsc_work(vha, fcport); |
| 6109 | } |
| 6110 | } |
| 6111 | break; |
| 6112 | |
| 6113 | case MODE_TARGET: |
| 6114 | default: |
| 6115 | break; |
| 6116 | } |
| 6117 | if (del) |
| 6118 | qla2x00_free_fcport(del); |
| 6119 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6120 | return fcport; |
| 6121 | } |
| 6122 | |
| 6123 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6124 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *vha, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6125 | uint8_t *s_id) |
| 6126 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6127 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6128 | fc_port_t *fcport = NULL; |
| 6129 | int rc, global_resets; |
| 6130 | uint16_t loop_id = 0; |
| 6131 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6132 | if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) { |
| 6133 | /* |
| 6134 | * This is Domain Controller, so it should be |
| 6135 | * OK to drop SCSI commands from it. |
| 6136 | */ |
| 6137 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 6138 | "Unable to find initiator with S_ID %x:%x:%x", |
| 6139 | s_id[0], s_id[1], s_id[2]); |
| 6140 | return NULL; |
| 6141 | } |
| 6142 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6143 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 6144 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6145 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6146 | global_resets = |
| 6147 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6148 | |
| 6149 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 6150 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6151 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 6152 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6153 | ql_log(ql_log_info, vha, 0xf071, |
| 6154 | "qla_target(%d): Unable to find " |
| 6155 | "initiator with S_ID %x:%x:%x", |
| 6156 | vha->vp_idx, s_id[0], s_id[1], |
| 6157 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6158 | |
| 6159 | if (rc == -ENOENT) { |
| 6160 | qlt_port_logo_t logo; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 6161 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6162 | sid_to_portid(s_id, &logo.id); |
| 6163 | logo.cmd_count = 1; |
| 6164 | qlt_send_first_logo(vha, &logo); |
| 6165 | } |
| 6166 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6167 | return NULL; |
| 6168 | } |
| 6169 | |
| 6170 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6171 | if (!fcport) { |
| 6172 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6173 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6174 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6175 | |
| 6176 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6177 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6178 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 6179 | "qla_target(%d): global reset during session discovery " |
| 6180 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 6181 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6182 | atomic_read(&vha->vha_tgt. |
| 6183 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6184 | goto retry; |
| 6185 | } |
| 6186 | |
| 6187 | sess = qlt_create_sess(vha, fcport, true); |
| 6188 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6189 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 6190 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6191 | return sess; |
| 6192 | } |
| 6193 | |
| 6194 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 6195 | struct qla_tgt_sess_work_param *prm) |
| 6196 | { |
| 6197 | struct scsi_qla_host *vha = tgt->vha; |
| 6198 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6199 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6200 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6201 | uint8_t s_id[3]; |
| 6202 | int rc; |
| 6203 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6204 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6205 | |
| 6206 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6207 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6208 | |
| 6209 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 6210 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 6211 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 6212 | |
Bart Van Assche | ac452b8 | 2019-08-08 20:01:40 -0700 | [diff] [blame^] | 6213 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6214 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6215 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6216 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6217 | sess = qlt_make_local_sess(vha, s_id); |
| 6218 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6219 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6220 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6221 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6222 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6223 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6224 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6225 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6226 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6227 | } |
| 6228 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6229 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6230 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6231 | "%s: kref_get fail %8phC \n", |
| 6232 | __func__, sess->port_name); |
| 6233 | sess = NULL; |
| 6234 | goto out_term2; |
| 6235 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6236 | } |
| 6237 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6238 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6239 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 6240 | |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6241 | ha->tgt.tgt_ops->put_sess(sess); |
| 6242 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6243 | if (rc != 0) |
| 6244 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6245 | return; |
| 6246 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6247 | out_term2: |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6248 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 6249 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6250 | if (sess) |
| 6251 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6252 | |
| 6253 | out_term: |
| 6254 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6255 | qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts, |
| 6256 | FCP_TMF_REJECTED, false); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6257 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 6261 | struct qla_tgt_sess_work_param *prm) |
| 6262 | { |
| 6263 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 6264 | struct scsi_qla_host *vha = tgt->vha; |
| 6265 | struct qla_hw_data *ha = vha->hw; |
Colin Ian King | bb6abdd | 2019-02-15 09:52:32 +0000 | [diff] [blame] | 6266 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6267 | unsigned long flags; |
| 6268 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 6269 | int rc; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6270 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 6271 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6272 | void *iocb; |
| 6273 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6274 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6275 | |
| 6276 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6277 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6278 | |
| 6279 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 6280 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 6281 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6282 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6283 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6284 | sess = qlt_make_local_sess(vha, s_id); |
| 6285 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6286 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6287 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6288 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6289 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6290 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6291 | if (sess->deleted) { |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6292 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6293 | } |
| 6294 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6295 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6296 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6297 | "%s: kref_get fail %8phC\n", |
| 6298 | __func__, sess->port_name); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6299 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6300 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | iocb = a; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6304 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6305 | unpacked_lun = |
| 6306 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6307 | |
| 6308 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6309 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 6310 | |
Bart Van Assche | 300ec74 | 2019-04-17 14:44:41 -0700 | [diff] [blame] | 6311 | ha->tgt.tgt_ops->put_sess(sess); |
| 6312 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6313 | if (rc != 0) |
| 6314 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6315 | return; |
| 6316 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6317 | out_term2: |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6318 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6319 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6320 | qlt_send_term_exchange(ha->base_qpair, NULL, &prm->tm_iocb2, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6321 | } |
| 6322 | |
| 6323 | static void qlt_sess_work_fn(struct work_struct *work) |
| 6324 | { |
| 6325 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 6326 | struct scsi_qla_host *vha = tgt->vha; |
| 6327 | unsigned long flags; |
| 6328 | |
| 6329 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 6330 | |
| 6331 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6332 | while (!list_empty(&tgt->sess_works_list)) { |
| 6333 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 6334 | tgt->sess_works_list.next, typeof(*prm), |
| 6335 | sess_works_list_entry); |
| 6336 | |
| 6337 | /* |
| 6338 | * This work can be scheduled on several CPUs at time, so we |
| 6339 | * must delete the entry to eliminate double processing |
| 6340 | */ |
| 6341 | list_del(&prm->sess_works_list_entry); |
| 6342 | |
| 6343 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6344 | |
| 6345 | switch (prm->type) { |
| 6346 | case QLA_TGT_SESS_WORK_ABORT: |
| 6347 | qlt_abort_work(tgt, prm); |
| 6348 | break; |
| 6349 | case QLA_TGT_SESS_WORK_TM: |
| 6350 | qlt_tmr_work(tgt, prm); |
| 6351 | break; |
| 6352 | default: |
| 6353 | BUG_ON(1); |
| 6354 | break; |
| 6355 | } |
| 6356 | |
| 6357 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6358 | |
| 6359 | kfree(prm); |
| 6360 | } |
| 6361 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6362 | } |
| 6363 | |
| 6364 | /* Must be called under tgt_host_action_mutex */ |
| 6365 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 6366 | { |
| 6367 | struct qla_tgt *tgt; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6368 | int rc, i; |
| 6369 | struct qla_qpair_hint *h; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6370 | |
| 6371 | if (!QLA_TGT_MODE_ENABLED()) |
| 6372 | return 0; |
| 6373 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 6374 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 6375 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 6376 | "This adapter does not support target mode.\n"); |
| 6377 | return 0; |
| 6378 | } |
| 6379 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6380 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6381 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6382 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6383 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6384 | |
| 6385 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 6386 | if (!tgt) { |
| 6387 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 6388 | "Unable to allocate struct qla_tgt\n"); |
| 6389 | return -ENOMEM; |
| 6390 | } |
| 6391 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6392 | tgt->qphints = kcalloc(ha->max_qpairs + 1, |
| 6393 | sizeof(struct qla_qpair_hint), |
| 6394 | GFP_KERNEL); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6395 | if (!tgt->qphints) { |
| 6396 | kfree(tgt); |
| 6397 | ql_log(ql_log_warn, base_vha, 0x0197, |
| 6398 | "Unable to allocate qpair hints.\n"); |
| 6399 | return -ENOMEM; |
| 6400 | } |
| 6401 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6402 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 6403 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 6404 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6405 | rc = btree_init64(&tgt->lun_qpair_map); |
| 6406 | if (rc) { |
| 6407 | kfree(tgt->qphints); |
| 6408 | kfree(tgt); |
| 6409 | ql_log(ql_log_info, base_vha, 0x0198, |
| 6410 | "Unable to initialize lun_qpair_map btree\n"); |
| 6411 | return -EIO; |
| 6412 | } |
| 6413 | h = &tgt->qphints[0]; |
| 6414 | h->qpair = ha->base_qpair; |
| 6415 | INIT_LIST_HEAD(&h->hint_elem); |
| 6416 | h->cpuid = ha->base_qpair->cpuid; |
| 6417 | list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list); |
| 6418 | |
| 6419 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6420 | unsigned long flags; |
| 6421 | |
| 6422 | struct qla_qpair *qpair = ha->queue_pair_map[i]; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 6423 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6424 | h = &tgt->qphints[i + 1]; |
| 6425 | INIT_LIST_HEAD(&h->hint_elem); |
| 6426 | if (qpair) { |
| 6427 | h->qpair = qpair; |
| 6428 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 6429 | list_add_tail(&h->hint_elem, &qpair->hints_list); |
| 6430 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 6431 | h->cpuid = qpair->cpuid; |
| 6432 | } |
| 6433 | } |
| 6434 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6435 | tgt->ha = ha; |
| 6436 | tgt->vha = base_vha; |
| 6437 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6438 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6439 | spin_lock_init(&tgt->sess_work_lock); |
| 6440 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6441 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6442 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6443 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6444 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6445 | |
| 6446 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6447 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6448 | base_vha->vp_idx); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6449 | /* 3 is reserved */ |
| 6450 | tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6451 | |
| 6452 | mutex_lock(&qla_tgt_mutex); |
| 6453 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6454 | mutex_unlock(&qla_tgt_mutex); |
| 6455 | |
Quinn Tran | f1443ee | 2017-03-15 09:48:51 -0700 | [diff] [blame] | 6456 | if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target) |
| 6457 | ha->tgt.tgt_ops->add_target(base_vha); |
| 6458 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6459 | return 0; |
| 6460 | } |
| 6461 | |
| 6462 | /* Must be called under tgt_host_action_mutex */ |
| 6463 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6464 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6465 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6466 | return 0; |
| 6467 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6468 | if (vha->fc_vport) { |
| 6469 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6470 | return 0; |
| 6471 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6472 | |
| 6473 | /* free left over qfull cmds */ |
| 6474 | qlt_init_term_exchange(vha); |
| 6475 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6476 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6477 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6478 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6479 | |
| 6480 | return 0; |
| 6481 | } |
| 6482 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6483 | void qlt_remove_target_resources(struct qla_hw_data *ha) |
| 6484 | { |
| 6485 | struct scsi_qla_host *node; |
| 6486 | u32 key = 0; |
| 6487 | |
| 6488 | btree_for_each_safe32(&ha->tgt.host_map, key, node) |
| 6489 | btree_remove32(&ha->tgt.host_map, key); |
| 6490 | |
| 6491 | btree_destroy32(&ha->tgt.host_map); |
| 6492 | } |
| 6493 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6494 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6495 | unsigned char *b) |
| 6496 | { |
Bart Van Assche | 0943491 | 2019-08-08 20:01:36 -0700 | [diff] [blame] | 6497 | pr_debug("qla2xxx HW vha->node_name: %8phC\n", vha->node_name); |
| 6498 | pr_debug("qla2xxx HW vha->port_name: %8phC\n", vha->port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6499 | put_unaligned_be64(wwpn, b); |
Bart Van Assche | 0943491 | 2019-08-08 20:01:36 -0700 | [diff] [blame] | 6500 | pr_debug("qla2xxx passed configfs WWPN: %8phC\n", b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6501 | } |
| 6502 | |
| 6503 | /** |
| 6504 | * qla_tgt_lport_register - register lport with external module |
| 6505 | * |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6506 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
Bart Van Assche | 807eb90 | 2018-10-18 15:45:41 -0700 | [diff] [blame] | 6507 | * @phys_wwpn: physical port WWPN |
| 6508 | * @npiv_wwpn: NPIV WWPN |
| 6509 | * @npiv_wwnn: NPIV WWNN |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 6510 | * @callback: lport initialization callback for tcm_qla2xxx code |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6511 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6512 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6513 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6514 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6515 | { |
| 6516 | struct qla_tgt *tgt; |
| 6517 | struct scsi_qla_host *vha; |
| 6518 | struct qla_hw_data *ha; |
| 6519 | struct Scsi_Host *host; |
| 6520 | unsigned long flags; |
| 6521 | int rc; |
| 6522 | u8 b[WWN_SIZE]; |
| 6523 | |
| 6524 | mutex_lock(&qla_tgt_mutex); |
| 6525 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6526 | vha = tgt->vha; |
| 6527 | ha = vha->hw; |
| 6528 | |
| 6529 | host = vha->host; |
| 6530 | if (!host) |
| 6531 | continue; |
| 6532 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6533 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6534 | continue; |
| 6535 | |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6536 | if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED) |
| 6537 | continue; |
| 6538 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6539 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6540 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6541 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6542 | host->host_no); |
| 6543 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6544 | continue; |
| 6545 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6546 | if (tgt->tgt_stop) { |
| 6547 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6548 | host->host_no); |
| 6549 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6550 | continue; |
| 6551 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6552 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6553 | |
| 6554 | if (!scsi_host_get(host)) { |
| 6555 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6556 | "Unable to scsi_host_get() for" |
| 6557 | " qla2xxx scsi_host\n"); |
| 6558 | continue; |
| 6559 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6560 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6561 | |
| 6562 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6563 | scsi_host_put(host); |
| 6564 | continue; |
| 6565 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6566 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6567 | if (rc != 0) |
| 6568 | scsi_host_put(host); |
| 6569 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6570 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6571 | return rc; |
| 6572 | } |
| 6573 | mutex_unlock(&qla_tgt_mutex); |
| 6574 | |
| 6575 | return -ENODEV; |
| 6576 | } |
| 6577 | EXPORT_SYMBOL(qlt_lport_register); |
| 6578 | |
| 6579 | /** |
| 6580 | * qla_tgt_lport_deregister - Degister lport |
| 6581 | * |
| 6582 | * @vha: Registered scsi_qla_host pointer |
| 6583 | */ |
| 6584 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6585 | { |
| 6586 | struct qla_hw_data *ha = vha->hw; |
| 6587 | struct Scsi_Host *sh = vha->host; |
| 6588 | /* |
| 6589 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6590 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6591 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6592 | ha->tgt.tgt_ops = NULL; |
| 6593 | /* |
| 6594 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6595 | */ |
| 6596 | scsi_host_put(sh); |
| 6597 | } |
| 6598 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6599 | |
| 6600 | /* Must be called under HW lock */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6601 | void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6602 | { |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6603 | switch (vha->qlini_mode) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6604 | case QLA2XXX_INI_MODE_DISABLED: |
| 6605 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6606 | vha->host->active_mode = MODE_TARGET; |
| 6607 | break; |
| 6608 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6609 | vha->host->active_mode = MODE_INITIATOR; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6610 | break; |
| 6611 | case QLA2XXX_INI_MODE_DUAL: |
| 6612 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6613 | break; |
| 6614 | default: |
| 6615 | break; |
| 6616 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6617 | } |
| 6618 | |
| 6619 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6620 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6621 | { |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6622 | switch (vha->qlini_mode) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6623 | case QLA2XXX_INI_MODE_DISABLED: |
| 6624 | vha->host->active_mode = MODE_UNKNOWN; |
| 6625 | break; |
| 6626 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6627 | vha->host->active_mode = MODE_INITIATOR; |
| 6628 | break; |
| 6629 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6630 | case QLA2XXX_INI_MODE_DUAL: |
| 6631 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6632 | break; |
| 6633 | default: |
| 6634 | break; |
| 6635 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6636 | } |
| 6637 | |
| 6638 | /* |
| 6639 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6640 | * |
| 6641 | * host_reset, bring up w/ Target Mode Enabled |
| 6642 | */ |
| 6643 | void |
| 6644 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6645 | { |
| 6646 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6647 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6648 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6649 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6650 | |
| 6651 | if (!tgt) { |
| 6652 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6653 | "Unable to locate qla_tgt pointer from" |
| 6654 | " struct qla_hw_data\n"); |
| 6655 | dump_stack(); |
| 6656 | return; |
| 6657 | } |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6658 | if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED) |
| 6659 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6660 | |
Quinn Tran | 178235f | 2019-07-26 09:07:29 -0700 | [diff] [blame] | 6661 | if (ha->tgt.num_act_qpairs > ha->max_qpairs) |
| 6662 | ha->tgt.num_act_qpairs = ha->max_qpairs; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6663 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6664 | tgt->tgt_stopped = 0; |
| 6665 | qlt_set_mode(vha); |
| 6666 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6667 | |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 6668 | mutex_lock(&ha->optrom_mutex); |
| 6669 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, |
| 6670 | "%s.\n", __func__); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6671 | if (vha->vp_idx) { |
| 6672 | qla24xx_disable_vp(vha); |
| 6673 | qla24xx_enable_vp(vha); |
| 6674 | } else { |
| 6675 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6676 | qla2xxx_wake_dpc(base_vha); |
| 6677 | qla2x00_wait_for_hba_online(base_vha); |
| 6678 | } |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 6679 | mutex_unlock(&ha->optrom_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6680 | } |
| 6681 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6682 | |
| 6683 | /* |
| 6684 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6685 | * |
| 6686 | * Disable Target Mode and reset the adapter |
| 6687 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6688 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6689 | { |
| 6690 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6691 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6692 | unsigned long flags; |
| 6693 | |
| 6694 | if (!tgt) { |
| 6695 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6696 | "Unable to locate qla_tgt pointer from" |
| 6697 | " struct qla_hw_data\n"); |
| 6698 | dump_stack(); |
| 6699 | return; |
| 6700 | } |
| 6701 | |
| 6702 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6703 | qlt_clear_mode(vha); |
| 6704 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6705 | |
| 6706 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6707 | qla2xxx_wake_dpc(vha); |
| 6708 | qla2x00_wait_for_hba_online(vha); |
| 6709 | } |
| 6710 | |
| 6711 | /* |
| 6712 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6713 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6714 | * members. |
| 6715 | */ |
| 6716 | void |
| 6717 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6718 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6719 | vha->vha_tgt.qla_tgt = NULL; |
| 6720 | |
| 6721 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6722 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6723 | |
| 6724 | qlt_clear_mode(vha); |
| 6725 | |
| 6726 | /* |
| 6727 | * NOTE: Currently the value is kept the same for <24xx and |
| 6728 | * >=24xx ISPs. If it is necessary to change it, |
| 6729 | * the check should be added for specific ISPs, |
| 6730 | * assigning the value appropriately. |
| 6731 | */ |
| 6732 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6733 | |
| 6734 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6735 | } |
| 6736 | |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6737 | u8 |
| 6738 | qlt_rff_id(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6739 | { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6740 | u8 fc4_feature = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6741 | /* |
| 6742 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6743 | */ |
| 6744 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6745 | fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6746 | } else if (qla_ini_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6747 | fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6748 | } else if (qla_dual_mode_enabled(vha)) |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6749 | fc4_feature = BIT_0 | BIT_1; |
| 6750 | |
| 6751 | return fc4_feature; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6752 | } |
| 6753 | |
| 6754 | /* |
| 6755 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6756 | * @ha: HA context |
| 6757 | * |
| 6758 | * Beginning of ATIO ring has initialization control block already built |
| 6759 | * by nvram config routine. |
| 6760 | * |
| 6761 | * Returns 0 on success. |
| 6762 | */ |
| 6763 | void |
| 6764 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6765 | { |
| 6766 | struct qla_hw_data *ha = vha->hw; |
| 6767 | uint16_t cnt; |
| 6768 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6769 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6770 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6771 | return; |
| 6772 | |
| 6773 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6774 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6775 | pkt++; |
| 6776 | } |
| 6777 | |
| 6778 | } |
| 6779 | |
| 6780 | /* |
| 6781 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6782 | * @ha: SCSI driver HA context |
| 6783 | */ |
| 6784 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6785 | qlt_24xx_process_atio_queue(struct scsi_qla_host *vha, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6786 | { |
| 6787 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6788 | struct atio_from_isp *pkt; |
| 6789 | int cnt, i; |
| 6790 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6791 | if (!ha->flags.fw_started) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6792 | return; |
| 6793 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6794 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6795 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6796 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6797 | cnt = pkt->u.raw.entry_count; |
| 6798 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6799 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6800 | /* |
| 6801 | * This packet is corrupted. The header + payload |
| 6802 | * can not be trusted. There is no point in passing |
| 6803 | * it further up. |
| 6804 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6805 | ql_log(ql_log_warn, vha, 0xd03c, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6806 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6807 | pkt->u.isp24.fcp_hdr.s_id, |
| 6808 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6809 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6810 | |
| 6811 | adjust_corrupted_atio(pkt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6812 | qlt_send_term_exchange(ha->base_qpair, NULL, pkt, |
| 6813 | ha_locked, 0); |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6814 | } else { |
| 6815 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6816 | (struct atio_from_isp *)pkt, ha_locked); |
| 6817 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6818 | |
| 6819 | for (i = 0; i < cnt; i++) { |
| 6820 | ha->tgt.atio_ring_index++; |
| 6821 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6822 | ha->tgt.atio_ring_index = 0; |
| 6823 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6824 | } else |
| 6825 | ha->tgt.atio_ring_ptr++; |
| 6826 | |
| 6827 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6828 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6829 | } |
| 6830 | wmb(); |
| 6831 | } |
| 6832 | |
| 6833 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6834 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6835 | } |
| 6836 | |
| 6837 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6838 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6839 | { |
| 6840 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6841 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6842 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6843 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6844 | if (!QLA_TGT_MODE_ENABLED()) |
| 6845 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6846 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6847 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6848 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6849 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6850 | |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6851 | if (ha->flags.msix_enabled) { |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 6852 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) { |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6853 | if (IS_QLA2071(ha)) { |
| 6854 | /* 4 ports Baker: Enable Interrupt Handshake */ |
| 6855 | icb->msix_atio = 0; |
| 6856 | icb->firmware_options_2 |= BIT_26; |
| 6857 | } else { |
| 6858 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6859 | icb->firmware_options_2 &= ~BIT_26; |
| 6860 | } |
| 6861 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6862 | "Registering ICB vector 0x%x for atio que.\n", |
| 6863 | msix->entry); |
| 6864 | } |
| 6865 | } else { |
| 6866 | /* INTx|MSI */ |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 6867 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) { |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6868 | icb->msix_atio = 0; |
| 6869 | icb->firmware_options_2 |= BIT_26; |
| 6870 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6871 | "%s: Use INTx for ATIOQ.\n", __func__); |
| 6872 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | void |
| 6877 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6878 | { |
| 6879 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6880 | u32 tmp; |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6881 | |
| 6882 | if (!QLA_TGT_MODE_ENABLED()) |
| 6883 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6884 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6885 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6886 | if (!ha->tgt.saved_set) { |
| 6887 | /* We save only once */ |
| 6888 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6889 | ha->tgt.saved_firmware_options_1 = |
| 6890 | nv->firmware_options_1; |
| 6891 | ha->tgt.saved_firmware_options_2 = |
| 6892 | nv->firmware_options_2; |
| 6893 | ha->tgt.saved_firmware_options_3 = |
| 6894 | nv->firmware_options_3; |
| 6895 | ha->tgt.saved_set = 1; |
| 6896 | } |
| 6897 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6898 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6899 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6900 | else /* dual */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6901 | nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6902 | |
| 6903 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6904 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6905 | |
| 6906 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6907 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6908 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6909 | |
| 6910 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6911 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6912 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6913 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6914 | if (ql2xtgt_tape_enable) |
| 6915 | /* Enable FC Tape support */ |
| 6916 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6917 | else |
| 6918 | /* Disable FC Tape support */ |
| 6919 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6920 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6921 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6922 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6923 | |
| 6924 | /* |
| 6925 | * clear BIT 15 explicitly as we have seen at least |
| 6926 | * a couple of instances where this was set and this |
| 6927 | * was causing the firmware to not be initialized. |
| 6928 | */ |
| 6929 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6930 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6931 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6932 | |
| 6933 | if (IS_QLA25XX(ha)) { |
| 6934 | /* Change Loop-prefer to Pt-Pt */ |
| 6935 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 6936 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 6937 | tmp = P2P << 4; |
| 6938 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
| 6939 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6940 | } else { |
| 6941 | if (ha->tgt.saved_set) { |
| 6942 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6943 | nv->firmware_options_1 = |
| 6944 | ha->tgt.saved_firmware_options_1; |
| 6945 | nv->firmware_options_2 = |
| 6946 | ha->tgt.saved_firmware_options_2; |
| 6947 | nv->firmware_options_3 = |
| 6948 | ha->tgt.saved_firmware_options_3; |
| 6949 | } |
| 6950 | return; |
| 6951 | } |
| 6952 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6953 | if (ha->base_qpair->enable_class_2) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6954 | if (vha->flags.init_done) |
| 6955 | fc_host_supported_classes(vha->host) = |
| 6956 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6957 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6958 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6959 | } else { |
| 6960 | if (vha->flags.init_done) |
| 6961 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6962 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6963 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6964 | } |
| 6965 | } |
| 6966 | |
| 6967 | void |
| 6968 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6969 | struct init_cb_24xx *icb) |
| 6970 | { |
| 6971 | struct qla_hw_data *ha = vha->hw; |
| 6972 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6973 | if (!QLA_TGT_MODE_ENABLED()) |
| 6974 | return; |
| 6975 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6976 | if (ha->tgt.node_name_set) { |
| 6977 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6978 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6979 | } |
| 6980 | } |
| 6981 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6982 | void |
| 6983 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6984 | { |
| 6985 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6986 | u32 tmp; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6987 | |
| 6988 | if (!QLA_TGT_MODE_ENABLED()) |
| 6989 | return; |
| 6990 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6991 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6992 | if (!ha->tgt.saved_set) { |
| 6993 | /* We save only once */ |
| 6994 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6995 | ha->tgt.saved_firmware_options_1 = |
| 6996 | nv->firmware_options_1; |
| 6997 | ha->tgt.saved_firmware_options_2 = |
| 6998 | nv->firmware_options_2; |
| 6999 | ha->tgt.saved_firmware_options_3 = |
| 7000 | nv->firmware_options_3; |
| 7001 | ha->tgt.saved_set = 1; |
| 7002 | } |
| 7003 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 7004 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7005 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 7006 | else /* dual */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 7007 | nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7008 | |
| 7009 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7010 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7011 | |
| 7012 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7013 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7014 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7015 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7016 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7017 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7018 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 7019 | /* |
| 7020 | * clear BIT 15 explicitly as we have seen at |
| 7021 | * least a couple of instances where this was set |
| 7022 | * and this was causing the firmware to not be |
| 7023 | * initialized. |
| 7024 | */ |
| 7025 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 7026 | if (ql2xtgt_tape_enable) |
| 7027 | /* Enable FC tape support */ |
| 7028 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7029 | else |
| 7030 | /* Disable FC tape support */ |
| 7031 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 7032 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7033 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7034 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7035 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7036 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 7037 | |
| 7038 | /* Change Loop-prefer to Pt-Pt */ |
| 7039 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 7040 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 7041 | tmp = P2P << 4; |
| 7042 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7043 | } else { |
| 7044 | if (ha->tgt.saved_set) { |
| 7045 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 7046 | nv->firmware_options_1 = |
| 7047 | ha->tgt.saved_firmware_options_1; |
| 7048 | nv->firmware_options_2 = |
| 7049 | ha->tgt.saved_firmware_options_2; |
| 7050 | nv->firmware_options_3 = |
| 7051 | ha->tgt.saved_firmware_options_3; |
| 7052 | } |
| 7053 | return; |
| 7054 | } |
| 7055 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7056 | if (ha->base_qpair->enable_class_2) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7057 | if (vha->flags.init_done) |
| 7058 | fc_host_supported_classes(vha->host) = |
| 7059 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 7060 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7061 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7062 | } else { |
| 7063 | if (vha->flags.init_done) |
| 7064 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 7065 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7066 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7067 | } |
| 7068 | } |
| 7069 | |
| 7070 | void |
| 7071 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 7072 | struct init_cb_81xx *icb) |
| 7073 | { |
| 7074 | struct qla_hw_data *ha = vha->hw; |
| 7075 | |
| 7076 | if (!QLA_TGT_MODE_ENABLED()) |
| 7077 | return; |
| 7078 | |
| 7079 | if (ha->tgt.node_name_set) { |
| 7080 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7081 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | void |
| 7086 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 7087 | { |
| 7088 | if (!QLA_TGT_MODE_ENABLED()) |
| 7089 | return; |
| 7090 | |
| 7091 | ha->msix_count += 1; /* For ATIO Q */ |
| 7092 | } |
| 7093 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7094 | |
| 7095 | void |
| 7096 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 7097 | struct vp_config_entry_24xx *vpmod) |
| 7098 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7099 | /* enable target mode. Bit5 = 1 => disable */ |
| 7100 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7101 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7102 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7103 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7104 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7105 | vpmod->options_idx1 &= ~BIT_4; |
| 7106 | } |
| 7107 | |
| 7108 | void |
| 7109 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 7110 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7111 | int rc; |
| 7112 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7113 | if (!QLA_TGT_MODE_ENABLED()) |
| 7114 | return; |
| 7115 | |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 7116 | if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha) || |
| 7117 | IS_QLA28XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7118 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 7119 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 7120 | } else { |
| 7121 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 7122 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 7123 | } |
| 7124 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 7125 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 7126 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7127 | |
| 7128 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 7129 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 7130 | qlt_unknown_atio_work_fn); |
| 7131 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7132 | qlt_clear_mode(base_vha); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7133 | |
| 7134 | rc = btree_init32(&ha->tgt.host_map); |
| 7135 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7136 | ql_log(ql_log_info, base_vha, 0xd03d, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7137 | "Unable to initialize ha->host_map btree\n"); |
| 7138 | |
| 7139 | qlt_update_vp_map(base_vha, SET_VP_IDX); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7140 | } |
| 7141 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7142 | irqreturn_t |
| 7143 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 7144 | { |
| 7145 | struct rsp_que *rsp; |
| 7146 | scsi_qla_host_t *vha; |
| 7147 | struct qla_hw_data *ha; |
| 7148 | unsigned long flags; |
| 7149 | |
| 7150 | rsp = (struct rsp_que *) dev_id; |
| 7151 | ha = rsp->hw; |
| 7152 | vha = pci_get_drvdata(ha->pdev); |
| 7153 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7154 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7155 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7156 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7157 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7158 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7159 | |
| 7160 | return IRQ_HANDLED; |
| 7161 | } |
| 7162 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7163 | static void |
| 7164 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 7165 | { |
| 7166 | struct qla_tgt_sess_op *op = container_of(work, |
| 7167 | struct qla_tgt_sess_op, work); |
| 7168 | scsi_qla_host_t *vha = op->vha; |
| 7169 | struct qla_hw_data *ha = vha->hw; |
| 7170 | unsigned long flags; |
| 7171 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7172 | if (qla2x00_reset_active(vha) || |
| 7173 | (op->chip_reset != ha->base_qpair->chip_reset)) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7174 | return; |
| 7175 | |
| 7176 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 7177 | qlt_24xx_process_atio_queue(vha, 0); |
| 7178 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 7179 | |
| 7180 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7181 | qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7182 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 7183 | |
| 7184 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7185 | } |
| 7186 | |
| 7187 | void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7188 | qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp, |
| 7189 | response_t *pkt) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7190 | { |
| 7191 | struct qla_tgt_sess_op *op; |
| 7192 | |
| 7193 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 7194 | |
| 7195 | if (!op) { |
| 7196 | /* do not reach for ATIO queue here. This is best effort err |
| 7197 | * recovery at this point. |
| 7198 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7199 | qlt_response_pkt_all_vps(vha, rsp, pkt); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7200 | return; |
| 7201 | } |
| 7202 | |
| 7203 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 7204 | op->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7205 | op->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7206 | op->rsp = rsp; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7207 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 7208 | queue_work(qla_tgt_wq, &op->work); |
| 7209 | return; |
| 7210 | } |
| 7211 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7212 | int |
| 7213 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 7214 | { |
| 7215 | if (!QLA_TGT_MODE_ENABLED()) |
| 7216 | return 0; |
| 7217 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7218 | ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC, |
| 7219 | sizeof(struct qla_tgt_vp_map), |
| 7220 | GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7221 | if (!ha->tgt.tgt_vp_map) |
| 7222 | return -ENOMEM; |
| 7223 | |
| 7224 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 7225 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 7226 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 7227 | if (!ha->tgt.atio_ring) { |
| 7228 | kfree(ha->tgt.tgt_vp_map); |
| 7229 | return -ENOMEM; |
| 7230 | } |
| 7231 | return 0; |
| 7232 | } |
| 7233 | |
| 7234 | void |
| 7235 | qlt_mem_free(struct qla_hw_data *ha) |
| 7236 | { |
| 7237 | if (!QLA_TGT_MODE_ENABLED()) |
| 7238 | return; |
| 7239 | |
| 7240 | if (ha->tgt.atio_ring) { |
| 7241 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 7242 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 7243 | ha->tgt.atio_dma); |
| 7244 | } |
Bart Van Assche | 5365bf9 | 2019-04-17 14:44:22 -0700 | [diff] [blame] | 7245 | ha->tgt.atio_ring = NULL; |
| 7246 | ha->tgt.atio_dma = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7247 | kfree(ha->tgt.tgt_vp_map); |
Bart Van Assche | 5365bf9 | 2019-04-17 14:44:22 -0700 | [diff] [blame] | 7248 | ha->tgt.tgt_vp_map = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7249 | } |
| 7250 | |
| 7251 | /* vport_slock to be held by the caller */ |
| 7252 | void |
| 7253 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 7254 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7255 | void *slot; |
| 7256 | u32 key; |
| 7257 | int rc; |
| 7258 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7259 | if (!QLA_TGT_MODE_ENABLED()) |
| 7260 | return; |
| 7261 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7262 | key = vha->d_id.b24; |
| 7263 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7264 | switch (cmd) { |
| 7265 | case SET_VP_IDX: |
| 7266 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 7267 | break; |
| 7268 | case SET_AL_PA: |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7269 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7270 | if (!slot) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7271 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7272 | "Save vha in host_map %p %06x\n", vha, key); |
| 7273 | rc = btree_insert32(&vha->hw->tgt.host_map, |
| 7274 | key, vha, GFP_ATOMIC); |
| 7275 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7276 | ql_log(ql_log_info, vha, 0xd03e, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7277 | "Unable to insert s_id into host_map: %06x\n", |
| 7278 | key); |
| 7279 | return; |
| 7280 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7281 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 7282 | "replace existing vha in host_map %p %06x\n", vha, key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7283 | btree_update32(&vha->hw->tgt.host_map, key, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7284 | break; |
| 7285 | case RESET_VP_IDX: |
| 7286 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 7287 | break; |
| 7288 | case RESET_AL_PA: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7289 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7290 | "clear vha in host_map %p %06x\n", vha, key); |
| 7291 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7292 | if (slot) |
| 7293 | btree_remove32(&vha->hw->tgt.host_map, key); |
| 7294 | vha->d_id.b24 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7295 | break; |
| 7296 | } |
| 7297 | } |
| 7298 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7299 | void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id) |
| 7300 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7301 | |
| 7302 | if (!vha->d_id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7303 | vha->d_id = id; |
| 7304 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7305 | } else if (vha->d_id.b24 != id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7306 | qlt_update_vp_map(vha, RESET_AL_PA); |
| 7307 | vha->d_id = id; |
| 7308 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7309 | } |
| 7310 | } |
| 7311 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7312 | static int __init qlt_parse_ini_mode(void) |
| 7313 | { |
| 7314 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 7315 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 7316 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 7317 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 7318 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 7319 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7320 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 7321 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7322 | else |
| 7323 | return false; |
| 7324 | |
| 7325 | return true; |
| 7326 | } |
| 7327 | |
| 7328 | int __init qlt_init(void) |
| 7329 | { |
| 7330 | int ret; |
| 7331 | |
Bart Van Assche | bc04459 | 2019-04-17 14:44:37 -0700 | [diff] [blame] | 7332 | BUILD_BUG_ON(sizeof(struct ctio7_to_24xx) != 64); |
| 7333 | BUILD_BUG_ON(sizeof(struct ctio_to_2xxx) != 64); |
| 7334 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7335 | if (!qlt_parse_ini_mode()) { |
| 7336 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 7337 | "qlt_parse_ini_mode() failed\n"); |
| 7338 | return -EINVAL; |
| 7339 | } |
| 7340 | |
| 7341 | if (!QLA_TGT_MODE_ENABLED()) |
| 7342 | return 0; |
| 7343 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7344 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 7345 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 7346 | qla_tgt_mgmt_cmd), 0, NULL); |
| 7347 | if (!qla_tgt_mgmt_cmd_cachep) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7348 | ql_log(ql_log_fatal, NULL, 0xd04b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7349 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 7350 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7351 | } |
| 7352 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7353 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 7354 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 7355 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7356 | |
| 7357 | if (!qla_tgt_plogi_cachep) { |
| 7358 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 7359 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 7360 | ret = -ENOMEM; |
| 7361 | goto out_mgmt_cmd_cachep; |
| 7362 | } |
| 7363 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7364 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 7365 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 7366 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 7367 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 7368 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 7369 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7370 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7371 | } |
| 7372 | |
| 7373 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 7374 | if (!qla_tgt_wq) { |
| 7375 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 7376 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 7377 | ret = -ENOMEM; |
| 7378 | goto out_cmd_mempool; |
| 7379 | } |
| 7380 | /* |
| 7381 | * Return 1 to signal that initiator-mode is being disabled |
| 7382 | */ |
| 7383 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 7384 | |
| 7385 | out_cmd_mempool: |
| 7386 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7387 | out_plogi_cachep: |
| 7388 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7389 | out_mgmt_cmd_cachep: |
| 7390 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7391 | return ret; |
| 7392 | } |
| 7393 | |
| 7394 | void qlt_exit(void) |
| 7395 | { |
| 7396 | if (!QLA_TGT_MODE_ENABLED()) |
| 7397 | return; |
| 7398 | |
| 7399 | destroy_workqueue(qla_tgt_wq); |
| 7400 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7401 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7402 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7403 | } |