Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1 | /* |
| 2 | * qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx |
| 3 | * |
| 4 | * based on qla2x00t.c code: |
| 5 | * |
| 6 | * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net> |
| 7 | * Copyright (C) 2004 - 2005 Leonid Stoljar |
| 8 | * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us> |
| 9 | * Copyright (C) 2006 - 2010 ID7 Ltd. |
| 10 | * |
| 11 | * Forward port and refactoring to modern qla2xxx and target/configfs |
| 12 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 13 | * Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org> |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation, version 2 |
| 18 | * of the License. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/types.h> |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 29 | #include <linux/blkdev.h> |
| 30 | #include <linux/interrupt.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/list.h> |
| 34 | #include <linux/workqueue.h> |
| 35 | #include <asm/unaligned.h> |
| 36 | #include <scsi/scsi.h> |
| 37 | #include <scsi/scsi_host.h> |
| 38 | #include <scsi/scsi_tcq.h> |
| 39 | #include <target/target_core_base.h> |
| 40 | #include <target/target_core_fabric.h> |
| 41 | |
| 42 | #include "qla_def.h" |
| 43 | #include "qla_target.h" |
| 44 | |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 45 | static int ql2xtgt_tape_enable; |
| 46 | module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR); |
| 47 | MODULE_PARM_DESC(ql2xtgt_tape_enable, |
| 48 | "Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER."); |
| 49 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 50 | static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED; |
| 51 | module_param(qlini_mode, charp, S_IRUGO); |
| 52 | MODULE_PARM_DESC(qlini_mode, |
| 53 | "Determines when initiator mode will be enabled. Possible values: " |
| 54 | "\"exclusive\" - initiator mode will be enabled on load, " |
| 55 | "disabled on enabling target mode and then on disabling target mode " |
| 56 | "enabled back; " |
| 57 | "\"disabled\" - initiator mode will never be enabled; " |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 58 | "\"dual\" - Initiator Modes will be enabled. Target Mode can be activated " |
| 59 | "when ready " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 60 | "\"enabled\" (default) - initiator mode will always stay enabled."); |
| 61 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 62 | static int ql_dm_tgt_ex_pct = 0; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 63 | module_param(ql_dm_tgt_ex_pct, int, S_IRUGO|S_IWUSR); |
| 64 | MODULE_PARM_DESC(ql_dm_tgt_ex_pct, |
| 65 | "For Dual Mode (qlini_mode=dual), this parameter determines " |
| 66 | "the percentage of exchanges/cmds FW will allocate resources " |
| 67 | "for Target mode."); |
| 68 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 69 | int ql2xuctrlirq = 1; |
| 70 | module_param(ql2xuctrlirq, int, 0644); |
| 71 | MODULE_PARM_DESC(ql2xuctrlirq, |
| 72 | "User to control IRQ placement via smp_affinity." |
| 73 | "Valid with qlini_mode=disabled." |
| 74 | "1(default): enable"); |
| 75 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 76 | int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 77 | |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 78 | static int qla_sam_status = SAM_STAT_BUSY; |
| 79 | static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */ |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 80 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 81 | /* |
| 82 | * From scsi/fc/fc_fcp.h |
| 83 | */ |
| 84 | enum fcp_resp_rsp_codes { |
| 85 | FCP_TMF_CMPL = 0, |
| 86 | FCP_DATA_LEN_INVALID = 1, |
| 87 | FCP_CMND_FIELDS_INVALID = 2, |
| 88 | FCP_DATA_PARAM_MISMATCH = 3, |
| 89 | FCP_TMF_REJECTED = 4, |
| 90 | FCP_TMF_FAILED = 5, |
| 91 | FCP_TMF_INVALID_LUN = 9, |
| 92 | }; |
| 93 | |
| 94 | /* |
| 95 | * fc_pri_ta from scsi/fc/fc_fcp.h |
| 96 | */ |
| 97 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ |
| 98 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ |
| 99 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 100 | #define FCP_PTA_ACA 4 /* auto. contingent allegiance */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 101 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ |
| 102 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ |
| 103 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ |
| 104 | |
| 105 | /* |
| 106 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which |
| 107 | * must be called under HW lock and could unlock/lock it inside. |
| 108 | * It isn't an issue, since in the current implementation on the time when |
| 109 | * those functions are called: |
| 110 | * |
| 111 | * - Either context is IRQ and only IRQ handler can modify HW data, |
| 112 | * including rings related fields, |
| 113 | * |
| 114 | * - Or access to target mode variables from struct qla_tgt doesn't |
| 115 | * cross those functions boundaries, except tgt_stop, which |
| 116 | * additionally protected by irq_cmd_count. |
| 117 | */ |
| 118 | /* Predefs for callbacks handed to qla2xxx LLD */ |
| 119 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 120 | struct atio_from_isp *pkt, uint8_t); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 121 | static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp, |
| 122 | response_t *pkt); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 123 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 124 | int fn, void *iocb, int flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 125 | 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] | 126 | *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 127 | static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 128 | struct atio_from_isp *atio, uint16_t status, int qfull); |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 129 | static void qlt_disable_vha(struct scsi_qla_host *vha); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 130 | static void qlt_clear_tgt_db(struct qla_tgt *tgt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 131 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 132 | struct imm_ntfy_from_isp *ntfy, |
| 133 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 134 | 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] | 135 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 136 | struct imm_ntfy_from_isp *imm, int ha_locked); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 137 | static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha, |
| 138 | fc_port_t *fcport, bool local); |
| 139 | void qlt_unreg_sess(struct fc_port *sess); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 140 | static void qlt_24xx_handle_abts(struct scsi_qla_host *, |
| 141 | struct abts_recv_from_24xx *); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 142 | static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *, |
| 143 | uint16_t); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 144 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t); |
| 145 | static inline uint32_t qlt_make_handle(struct qla_qpair *); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 146 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 147 | /* |
| 148 | * Global Variables |
| 149 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 150 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Quinn Tran | b5d1531 | 2017-08-30 10:16:49 -0700 | [diff] [blame] | 151 | struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 152 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 153 | static struct workqueue_struct *qla_tgt_wq; |
| 154 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 155 | static LIST_HEAD(qla_tgt_glist); |
| 156 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 157 | static const char *prot_op_str(u32 prot_op) |
| 158 | { |
| 159 | switch (prot_op) { |
| 160 | case TARGET_PROT_NORMAL: return "NORMAL"; |
| 161 | case TARGET_PROT_DIN_INSERT: return "DIN_INSERT"; |
| 162 | case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT"; |
| 163 | case TARGET_PROT_DIN_STRIP: return "DIN_STRIP"; |
| 164 | case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP"; |
| 165 | case TARGET_PROT_DIN_PASS: return "DIN_PASS"; |
| 166 | case TARGET_PROT_DOUT_PASS: return "DOUT_PASS"; |
| 167 | default: return "UNKNOWN"; |
| 168 | } |
| 169 | } |
| 170 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 171 | /* This API intentionally takes dest as a parameter, rather than returning |
| 172 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 173 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 174 | { |
| 175 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 176 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 177 | /* memory barrier */ |
| 178 | wmb(); |
| 179 | } |
| 180 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 181 | /* Might release hw lock, then reaquire!! */ |
| 182 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 183 | { |
| 184 | /* Send marker if required */ |
| 185 | if (unlikely(vha->marker_needed != 0)) { |
| 186 | int rc = qla2x00_issue_marker(vha, vha_locked); |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 187 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 188 | if (rc != QLA_SUCCESS) { |
| 189 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 190 | "qla_target(%d): issue_marker() failed\n", |
| 191 | vha->vp_idx); |
| 192 | } |
| 193 | return rc; |
| 194 | } |
| 195 | return QLA_SUCCESS; |
| 196 | } |
| 197 | |
| 198 | static inline |
| 199 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
| 200 | uint8_t *d_id) |
| 201 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 202 | struct scsi_qla_host *host; |
| 203 | uint32_t key = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 204 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 205 | if ((vha->d_id.b.area == d_id[1]) && (vha->d_id.b.domain == d_id[0]) && |
| 206 | (vha->d_id.b.al_pa == d_id[2])) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 207 | return vha; |
| 208 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 209 | key = (uint32_t)d_id[0] << 16; |
| 210 | key |= (uint32_t)d_id[1] << 8; |
| 211 | key |= (uint32_t)d_id[2]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 212 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 213 | host = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 214 | if (!host) |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 215 | ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 216 | "Unable to find host %06x\n", key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 217 | |
| 218 | return host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static inline |
| 222 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 223 | uint16_t vp_idx) |
| 224 | { |
| 225 | struct qla_hw_data *ha = vha->hw; |
| 226 | |
| 227 | if (vha->vp_idx == vp_idx) |
| 228 | return vha; |
| 229 | |
| 230 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 231 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 232 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 233 | |
| 234 | return NULL; |
| 235 | } |
| 236 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 237 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 238 | { |
| 239 | unsigned long flags; |
| 240 | |
| 241 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 242 | |
| 243 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 244 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 245 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 246 | vha->hw->tgt.num_pend_cmds; |
| 247 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 248 | } |
| 249 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 250 | { |
| 251 | unsigned long flags; |
| 252 | |
| 253 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 254 | vha->hw->tgt.num_pend_cmds--; |
| 255 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 256 | } |
| 257 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 258 | |
| 259 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 260 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 261 | { |
| 262 | struct qla_tgt_sess_op *u; |
| 263 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 264 | unsigned long flags; |
| 265 | |
| 266 | if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 267 | ql_dbg(ql_dbg_async, vha, 0x502c, |
| 268 | "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped", |
| 269 | vha->vp_idx); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 270 | goto out_term; |
| 271 | } |
| 272 | |
| 273 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 274 | if (u == NULL) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 275 | goto out_term; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 276 | |
| 277 | u->vha = vha; |
| 278 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 279 | INIT_LIST_HEAD(&u->cmd_list); |
| 280 | |
| 281 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 282 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 283 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 284 | |
| 285 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 286 | |
| 287 | out: |
| 288 | return; |
| 289 | |
| 290 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 291 | 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] | 292 | goto out; |
| 293 | } |
| 294 | |
| 295 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 296 | uint8_t ha_locked) |
| 297 | { |
| 298 | struct qla_tgt_sess_op *u, *t; |
| 299 | scsi_qla_host_t *host; |
| 300 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 301 | unsigned long flags; |
| 302 | uint8_t queued = 0; |
| 303 | |
| 304 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 305 | if (u->aborted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 306 | ql_dbg(ql_dbg_async, vha, 0x502e, |
| 307 | "Freeing unknown %s %p, because of Abort\n", |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 308 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 309 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 310 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 311 | goto abort; |
| 312 | } |
| 313 | |
| 314 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 315 | if (host != NULL) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 316 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 317 | "Requeuing unknown ATIO_TYPE7 %p\n", u); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 318 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 319 | } else if (tgt->tgt_stop) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 320 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 321 | "Freeing unknown %s %p, because tgt is being stopped\n", |
| 322 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 323 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 324 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 325 | } else { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 326 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 327 | "Reschedule u %p, vha %p, host %p\n", u, vha, host); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 328 | if (!queued) { |
| 329 | queued = 1; |
| 330 | schedule_delayed_work(&vha->unknown_atio_work, |
| 331 | 1); |
| 332 | } |
| 333 | continue; |
| 334 | } |
| 335 | |
| 336 | abort: |
| 337 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 338 | list_del(&u->cmd_list); |
| 339 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 340 | kfree(u); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 345 | { |
| 346 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 347 | struct scsi_qla_host, unknown_atio_work); |
| 348 | |
| 349 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 350 | } |
| 351 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 352 | 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] | 353 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 354 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 355 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 356 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 357 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 358 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 359 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 360 | switch (atio->u.raw.entry_type) { |
| 361 | case ATIO_TYPE7: |
| 362 | { |
| 363 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 364 | atio->u.isp24.fcp_hdr.d_id); |
| 365 | if (unlikely(NULL == host)) { |
| 366 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 367 | "qla_target(%d): Received ATIO_TYPE7 " |
| 368 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
| 369 | atio->u.isp24.fcp_hdr.d_id[0], |
| 370 | atio->u.isp24.fcp_hdr.d_id[1], |
| 371 | atio->u.isp24.fcp_hdr.d_id[2]); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 372 | |
| 373 | |
| 374 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 375 | break; |
| 376 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 377 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 378 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 379 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 380 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 381 | break; |
| 382 | } |
| 383 | |
| 384 | case IMMED_NOTIFY_TYPE: |
| 385 | { |
| 386 | struct scsi_qla_host *host = vha; |
| 387 | struct imm_ntfy_from_isp *entry = |
| 388 | (struct imm_ntfy_from_isp *)atio; |
| 389 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 390 | qlt_issue_marker(vha, ha_locked); |
| 391 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 392 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 393 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 394 | host = qlt_find_host_by_vp_idx(vha, |
| 395 | entry->u.isp24.vp_index); |
| 396 | if (unlikely(!host)) { |
| 397 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 398 | "qla_target(%d): Received " |
| 399 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 400 | "with unknown vp_index %d\n", |
| 401 | vha->vp_idx, entry->u.isp24.vp_index); |
| 402 | break; |
| 403 | } |
| 404 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 405 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 406 | break; |
| 407 | } |
| 408 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 409 | case VP_RPT_ID_IOCB_TYPE: |
| 410 | qla24xx_report_id_acquisition(vha, |
| 411 | (struct vp_rpt_id_entry_24xx *)atio); |
| 412 | break; |
| 413 | |
| 414 | case ABTS_RECV_24XX: |
| 415 | { |
| 416 | struct abts_recv_from_24xx *entry = |
| 417 | (struct abts_recv_from_24xx *)atio; |
| 418 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 419 | entry->vp_index); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 420 | unsigned long flags; |
| 421 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 422 | if (unlikely(!host)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 423 | ql_dbg(ql_dbg_tgt, vha, 0xe00a, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 424 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 425 | "received, with unknown vp_index %d\n", |
| 426 | vha->vp_idx, entry->vp_index); |
| 427 | break; |
| 428 | } |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 429 | if (!ha_locked) |
| 430 | spin_lock_irqsave(&host->hw->hardware_lock, flags); |
| 431 | qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio); |
| 432 | if (!ha_locked) |
| 433 | spin_unlock_irqrestore(&host->hw->hardware_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 434 | break; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 438 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 439 | default: |
| 440 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 441 | "qla_target(%d): Received unknown ATIO atio " |
| 442 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 443 | break; |
| 444 | } |
| 445 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 446 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 447 | } |
| 448 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 449 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, |
| 450 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 451 | { |
| 452 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 453 | case CTIO_CRC2: |
| 454 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 455 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 456 | vha->vp_idx, __func__); |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 457 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 458 | case CTIO_TYPE7: |
| 459 | { |
| 460 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 461 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 462 | entry->vp_index); |
| 463 | if (unlikely(!host)) { |
| 464 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 465 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 466 | "received, with unknown vp_index %d\n", |
| 467 | vha->vp_idx, entry->vp_index); |
| 468 | break; |
| 469 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 470 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 471 | break; |
| 472 | } |
| 473 | |
| 474 | case IMMED_NOTIFY_TYPE: |
| 475 | { |
| 476 | struct scsi_qla_host *host = vha; |
| 477 | struct imm_ntfy_from_isp *entry = |
| 478 | (struct imm_ntfy_from_isp *)pkt; |
| 479 | |
| 480 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 481 | if (unlikely(!host)) { |
| 482 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 483 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 484 | "received, with unknown vp_index %d\n", |
| 485 | vha->vp_idx, entry->u.isp24.vp_index); |
| 486 | break; |
| 487 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 488 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 489 | break; |
| 490 | } |
| 491 | |
| 492 | case NOTIFY_ACK_TYPE: |
| 493 | { |
| 494 | struct scsi_qla_host *host = vha; |
| 495 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 496 | |
| 497 | if (0xFF != entry->u.isp24.vp_index) { |
| 498 | host = qlt_find_host_by_vp_idx(vha, |
| 499 | entry->u.isp24.vp_index); |
| 500 | if (unlikely(!host)) { |
| 501 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 502 | "qla_target(%d): Response " |
| 503 | "pkt (NOTIFY_ACK_TYPE) " |
| 504 | "received, with unknown " |
| 505 | "vp_index %d\n", vha->vp_idx, |
| 506 | entry->u.isp24.vp_index); |
| 507 | break; |
| 508 | } |
| 509 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 510 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 511 | break; |
| 512 | } |
| 513 | |
| 514 | case ABTS_RECV_24XX: |
| 515 | { |
| 516 | struct abts_recv_from_24xx *entry = |
| 517 | (struct abts_recv_from_24xx *)pkt; |
| 518 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 519 | entry->vp_index); |
| 520 | if (unlikely(!host)) { |
| 521 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 522 | "qla_target(%d): Response pkt " |
| 523 | "(ABTS_RECV_24XX) received, with unknown " |
| 524 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 525 | break; |
| 526 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 527 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 528 | break; |
| 529 | } |
| 530 | |
| 531 | case ABTS_RESP_24XX: |
| 532 | { |
| 533 | struct abts_resp_to_24xx *entry = |
| 534 | (struct abts_resp_to_24xx *)pkt; |
| 535 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 536 | entry->vp_index); |
| 537 | if (unlikely(!host)) { |
| 538 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 539 | "qla_target(%d): Response pkt " |
| 540 | "(ABTS_RECV_24XX) received, with unknown " |
| 541 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 542 | break; |
| 543 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 544 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 545 | break; |
| 546 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 547 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 548 | qlt_response_pkt(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | |
| 552 | } |
| 553 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 554 | /* |
| 555 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 556 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 557 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 558 | struct imm_ntfy_from_isp *ntfy, int type) |
| 559 | { |
| 560 | struct qla_work_evt *e; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 561 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 562 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 563 | if (!e) |
| 564 | return QLA_FUNCTION_FAILED; |
| 565 | |
| 566 | e->u.nack.fcport = fcport; |
| 567 | e->u.nack.type = type; |
| 568 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 569 | return qla2x00_post_work(vha, e); |
| 570 | } |
| 571 | |
| 572 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 573 | void qla2x00_async_nack_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 574 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 575 | struct srb *sp = (struct srb *)s; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 576 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 577 | unsigned long flags; |
| 578 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 579 | ql_dbg(ql_dbg_disc, vha, 0x20f2, |
| 580 | "Async done-%s res %x %8phC type %d\n", |
| 581 | sp->name, res, sp->fcport->port_name, sp->type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 582 | |
| 583 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 584 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 585 | sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 586 | |
| 587 | switch (sp->type) { |
| 588 | case SRB_NACK_PLOGI: |
| 589 | sp->fcport->login_gen++; |
| 590 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 591 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 592 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 593 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 594 | break; |
| 595 | |
| 596 | case SRB_NACK_PRLI: |
| 597 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 598 | sp->fcport->deleted = 0; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 599 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 600 | |
| 601 | if (!sp->fcport->login_succ && |
| 602 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 603 | sp->fcport->login_succ = 1; |
| 604 | |
| 605 | vha->fcport_count++; |
Quinn Tran | 0aca778 | 2018-09-04 14:19:16 -0700 | [diff] [blame] | 606 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 607 | qla24xx_sched_upd_fcport(sp->fcport); |
Quinn Tran | 0aca778 | 2018-09-04 14:19:16 -0700 | [diff] [blame] | 608 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | 2952849 | 2018-05-01 09:01:45 -0700 | [diff] [blame] | 609 | } else { |
| 610 | sp->fcport->login_retry = 0; |
| 611 | sp->fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 612 | sp->fcport->deleted = 0; |
| 613 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 614 | } |
| 615 | break; |
| 616 | |
| 617 | case SRB_NACK_LOGO: |
| 618 | sp->fcport->login_gen++; |
| 619 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 620 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 621 | break; |
| 622 | } |
| 623 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 624 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 625 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 629 | struct imm_ntfy_from_isp *ntfy, int type) |
| 630 | { |
| 631 | int rval = QLA_FUNCTION_FAILED; |
| 632 | srb_t *sp; |
| 633 | char *c = NULL; |
| 634 | |
| 635 | fcport->flags |= FCF_ASYNC_SENT; |
| 636 | switch (type) { |
| 637 | case SRB_NACK_PLOGI: |
| 638 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 639 | c = "PLOGI"; |
| 640 | break; |
| 641 | case SRB_NACK_PRLI: |
| 642 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 643 | fcport->deleted = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 644 | c = "PRLI"; |
| 645 | break; |
| 646 | case SRB_NACK_LOGO: |
| 647 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 648 | c = "LOGO"; |
| 649 | break; |
| 650 | } |
| 651 | |
| 652 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 653 | if (!sp) |
| 654 | goto done; |
| 655 | |
| 656 | sp->type = type; |
| 657 | sp->name = "nack"; |
| 658 | |
Ben Hutchings | e74e7d9 | 2018-03-20 21:36:14 +0000 | [diff] [blame] | 659 | sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 660 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 661 | |
| 662 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 663 | sp->done = qla2x00_async_nack_sp_done; |
| 664 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 665 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
| 666 | "Async-%s %8phC hndl %x %s\n", |
| 667 | sp->name, fcport->port_name, sp->handle, c); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 668 | |
Bill Kuzeja | f233e8c | 2019-02-14 10:52:29 -0500 | [diff] [blame] | 669 | rval = qla2x00_start_sp(sp); |
| 670 | if (rval != QLA_SUCCESS) |
| 671 | goto done_free_sp; |
| 672 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 673 | return rval; |
| 674 | |
| 675 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 676 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 677 | done: |
| 678 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 679 | return rval; |
| 680 | } |
| 681 | |
| 682 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 683 | { |
| 684 | fc_port_t *t; |
| 685 | unsigned long flags; |
| 686 | |
| 687 | switch (e->u.nack.type) { |
| 688 | case SRB_NACK_PRLI: |
Quinn Tran | 1021f0b | 2019-01-24 23:23:45 -0800 | [diff] [blame] | 689 | t = e->u.nack.fcport; |
| 690 | flush_work(&t->del_work); |
| 691 | flush_work(&t->free_work); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 692 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 693 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 694 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 695 | if (t) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 696 | ql_log(ql_log_info, vha, 0xd034, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 697 | "%s create sess success %p", __func__, t); |
| 698 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 699 | /* create sess has an extra kref */ |
| 700 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
| 701 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 702 | } |
| 703 | break; |
| 704 | } |
| 705 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
Bart Van Assche | 845bbb0 | 2019-04-11 14:53:18 -0700 | [diff] [blame] | 706 | (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] | 707 | } |
| 708 | |
| 709 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 710 | { |
| 711 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 712 | struct qla_hw_data *ha = fcport->vha->hw; |
| 713 | unsigned long flags; |
| 714 | |
| 715 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 716 | |
| 717 | if (fcport->se_sess) { |
| 718 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 719 | ha->tgt.tgt_ops->put_sess(fcport); |
| 720 | } else { |
| 721 | qlt_unreg_sess(fcport); |
| 722 | } |
| 723 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 724 | } |
| 725 | |
| 726 | /* |
| 727 | * Called from qla2x00_reg_remote_port() |
| 728 | */ |
| 729 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 730 | { |
| 731 | struct qla_hw_data *ha = vha->hw; |
| 732 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 733 | struct fc_port *sess = fcport; |
| 734 | unsigned long flags; |
| 735 | |
| 736 | if (!vha->hw->tgt.tgt_ops) |
| 737 | return; |
| 738 | |
| 739 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 740 | if (tgt->tgt_stop) { |
| 741 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 746 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 747 | return; |
| 748 | } |
| 749 | |
| 750 | if (!sess->se_sess) { |
| 751 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 752 | |
| 753 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 754 | sess = qlt_create_sess(vha, fcport, false); |
| 755 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 756 | |
| 757 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 758 | } else { |
| 759 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 760 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 761 | return; |
| 762 | } |
| 763 | |
| 764 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 765 | ql_dbg(ql_dbg_disc, vha, 0x2107, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 766 | "%s: kref_get fail sess %8phC \n", |
| 767 | __func__, sess->port_name); |
| 768 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 769 | return; |
| 770 | } |
| 771 | |
| 772 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 773 | "qla_target(%u): %ssession for port %8phC " |
| 774 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 775 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 776 | |
| 777 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 778 | "Reappeared sess %p\n", sess); |
| 779 | |
| 780 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 781 | fcport->loop_id, |
| 782 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 783 | } |
| 784 | |
| 785 | if (sess && sess->local) { |
| 786 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 787 | "qla_target(%u): local session for " |
| 788 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 789 | fcport->port_name, sess->loop_id); |
| 790 | sess->local = 0; |
| 791 | } |
| 792 | ha->tgt.tgt_ops->put_sess(sess); |
| 793 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 794 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 795 | |
| 796 | /* |
| 797 | * This is a zero-base ref-counting solution, since hardware_lock |
| 798 | * guarantees that ref_count is not modified concurrently. |
| 799 | * Upon successful return content of iocb is undefined |
| 800 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 801 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 802 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 803 | struct imm_ntfy_from_isp *iocb) |
| 804 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 805 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 806 | |
| 807 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 808 | if (pla->id.b24 == id->b24) { |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 809 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d, |
| 810 | "%s %d %8phC Term INOT due to new INOT", |
| 811 | __func__, __LINE__, |
| 812 | pla->iocb.u.isp24.port_name); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 813 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
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 | return pla; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 820 | if (!pla) { |
| 821 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 822 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 823 | vha->vp_idx); |
| 824 | return NULL; |
| 825 | } |
| 826 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 827 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 828 | pla->id = *id; |
| 829 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 830 | |
| 831 | return pla; |
| 832 | } |
| 833 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 834 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 835 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 836 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 837 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 838 | port_id_t port_id; |
| 839 | uint16_t loop_id; |
| 840 | fc_port_t *fcport = pla->fcport; |
| 841 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 842 | BUG_ON(!pla->ref_count); |
| 843 | pla->ref_count--; |
| 844 | |
| 845 | if (pla->ref_count) |
| 846 | return; |
| 847 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 848 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 849 | "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] | 850 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 851 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 852 | iocb->u.isp24.port_id[0], |
| 853 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 854 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 855 | |
| 856 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 857 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 858 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 859 | port_id.b.rsvd_1 = 0; |
| 860 | |
| 861 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 862 | |
| 863 | fcport->loop_id = loop_id; |
| 864 | fcport->d_id = port_id; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 865 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 866 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 867 | else |
| 868 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 869 | |
| 870 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 871 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 872 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 873 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 874 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 875 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 876 | |
| 877 | list_del(&pla->list); |
| 878 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 879 | } |
| 880 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 881 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 882 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 883 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 884 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 885 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 886 | /* Inc ref_count first because link might already be pointing at pla */ |
| 887 | pla->ref_count++; |
| 888 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 889 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 890 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 891 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 892 | sess, link, sess->port_name, |
| 893 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 894 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 895 | pla->ref_count, pla, link); |
| 896 | |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 897 | if (link == QLT_PLOGI_LINK_CONFLICT) { |
| 898 | switch (sess->disc_state) { |
| 899 | case DSC_DELETED: |
| 900 | case DSC_DELETE_PEND: |
| 901 | pla->ref_count--; |
| 902 | return; |
| 903 | default: |
| 904 | break; |
| 905 | } |
| 906 | } |
| 907 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 908 | if (sess->plogi_link[link]) |
| 909 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 910 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 911 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 912 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 913 | |
| 914 | sess->plogi_link[link] = pla; |
| 915 | } |
| 916 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 917 | typedef struct { |
| 918 | /* These fields must be initialized by the caller */ |
| 919 | port_id_t id; |
| 920 | /* |
| 921 | * number of cmds dropped while we were waiting for |
| 922 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 923 | * triggered by a command, otherwise, to 0 |
| 924 | */ |
| 925 | int cmd_count; |
| 926 | |
| 927 | /* These fields are used by callee */ |
| 928 | struct list_head list; |
| 929 | } qlt_port_logo_t; |
| 930 | |
| 931 | static void |
| 932 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 933 | { |
| 934 | qlt_port_logo_t *tmp; |
| 935 | int res; |
| 936 | |
| 937 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 938 | |
| 939 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 940 | if (tmp->id.b24 == logo->id.b24) { |
| 941 | tmp->cmd_count += logo->cmd_count; |
| 942 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 943 | return; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | list_add_tail(&logo->list, &vha->logo_list); |
| 948 | |
| 949 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 950 | |
| 951 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 952 | |
| 953 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 954 | list_del(&logo->list); |
| 955 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 956 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 957 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 958 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 959 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 960 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 961 | } |
| 962 | |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 963 | void qlt_free_session_done(struct work_struct *work) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 964 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 965 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 966 | free_work); |
| 967 | struct qla_tgt *tgt = sess->tgt; |
| 968 | struct scsi_qla_host *vha = sess->vha; |
| 969 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 970 | unsigned long flags; |
| 971 | bool logout_started = false; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 972 | scsi_qla_host_t *base_vha; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 973 | struct qlt_plogi_ack_t *own = |
| 974 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 975 | |
| 976 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 977 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 978 | " 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] | 979 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 980 | 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] | 981 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 982 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 983 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 984 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Quinn Tran | 2137490 | 2019-04-23 14:52:35 -0700 | [diff] [blame] | 985 | qla2x00_mark_device_lost(vha, sess, 0, 0); |
| 986 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 987 | if (sess->send_els_logo) { |
| 988 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 989 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 990 | logo.id = sess->d_id; |
| 991 | logo.cmd_count = 0; |
Quinn Tran | cb97f2c | 2018-08-02 13:16:51 -0700 | [diff] [blame] | 992 | if (!own) |
| 993 | qlt_send_first_logo(vha, &logo); |
Himanshu Madhani | a239034 | 2018-01-22 12:04:20 -0800 | [diff] [blame] | 994 | sess->send_els_logo = 0; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 995 | } |
| 996 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 997 | if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 998 | int rc; |
| 999 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1000 | if (!own || |
| 1001 | (own && |
| 1002 | (own->iocb.u.isp24.status_subcode == ELS_PLOGI))) { |
| 1003 | rc = qla2x00_post_async_logout_work(vha, sess, |
| 1004 | NULL); |
| 1005 | if (rc != QLA_SUCCESS) |
| 1006 | ql_log(ql_log_warn, vha, 0xf085, |
| 1007 | "Schedule logo failed sess %p rc %d\n", |
| 1008 | sess, rc); |
| 1009 | else |
| 1010 | logout_started = true; |
| 1011 | } else if (own && (own->iocb.u.isp24.status_subcode == |
| 1012 | ELS_PRLI) && ha->flags.rida_fmt2) { |
| 1013 | rc = qla2x00_post_async_prlo_work(vha, sess, |
| 1014 | NULL); |
| 1015 | if (rc != QLA_SUCCESS) |
| 1016 | ql_log(ql_log_warn, vha, 0xf085, |
| 1017 | "Schedule PRLO failed sess %p rc %d\n", |
| 1018 | sess, rc); |
| 1019 | else |
| 1020 | logout_started = true; |
| 1021 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1022 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1023 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1024 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1025 | /* |
| 1026 | * Release the target session for FC Nexus from fabric module code. |
| 1027 | */ |
| 1028 | if (sess->se_sess != NULL) |
| 1029 | ha->tgt.tgt_ops->free_session(sess); |
| 1030 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1031 | if (logout_started) { |
| 1032 | bool traced = false; |
| 1033 | |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 1034 | while (!READ_ONCE(sess->logout_completed)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1035 | if (!traced) { |
| 1036 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 1037 | "%s: waiting for sess %p logout\n", |
| 1038 | __func__, sess); |
| 1039 | traced = true; |
| 1040 | } |
| 1041 | msleep(100); |
| 1042 | } |
| 1043 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1044 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1045 | "%s: sess %p logout completed\n", __func__, sess); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | if (sess->logo_ack_needed) { |
| 1049 | sess->logo_ack_needed = 0; |
| 1050 | qla24xx_async_notify_ack(vha, sess, |
| 1051 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1054 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1055 | if (sess->se_sess) { |
| 1056 | sess->se_sess = NULL; |
| 1057 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 1058 | tgt->sess_count--; |
| 1059 | } |
| 1060 | |
| 1061 | sess->disc_state = DSC_DELETED; |
| 1062 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1063 | sess->deleted = QLA_SESS_DELETED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1064 | |
| 1065 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1066 | vha->fcport_count--; |
| 1067 | sess->login_succ = 0; |
| 1068 | } |
| 1069 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 1070 | qla2x00_clear_loop_id(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1071 | |
| 1072 | if (sess->conflict) { |
| 1073 | sess->conflict->login_pause = 0; |
| 1074 | sess->conflict = NULL; |
| 1075 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1076 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1077 | } |
| 1078 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1079 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1080 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1081 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1082 | struct imm_ntfy_from_isp *iocb; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 1083 | |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 1084 | own = sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1085 | |
| 1086 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1087 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1088 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1089 | "se_sess %p / sess %p port %8phC is gone," |
| 1090 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1091 | sess->se_sess, sess, sess->port_name, |
| 1092 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1093 | own ? own->ref_count : -1, |
| 1094 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1095 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1096 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1097 | } else { |
| 1098 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1099 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1100 | sess->se_sess, sess, sess->port_name, |
| 1101 | own ? "releasing own PLOGI" : |
| 1102 | "no own PLOGI pending", |
| 1103 | own ? own->ref_count : -1); |
| 1104 | } |
| 1105 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1106 | if (own) { |
| 1107 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1108 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1109 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1110 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1111 | } |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1112 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1113 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1114 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1115 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1116 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1117 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1118 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1119 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1120 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1121 | |
| 1122 | if (vha->fcport_count == 0) |
| 1123 | wake_up_all(&vha->fcport_waitQ); |
| 1124 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1125 | base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1126 | |
| 1127 | sess->free_pending = 0; |
| 1128 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1129 | if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags)) |
| 1130 | return; |
| 1131 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1132 | if ((!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) { |
| 1133 | switch (vha->host->active_mode) { |
| 1134 | case MODE_INITIATOR: |
| 1135 | case MODE_DUAL: |
| 1136 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1137 | qla2xxx_wake_dpc(vha); |
| 1138 | break; |
| 1139 | case MODE_TARGET: |
| 1140 | default: |
| 1141 | /* no-op */ |
| 1142 | break; |
| 1143 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1144 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1145 | } |
| 1146 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1147 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1148 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1149 | { |
| 1150 | struct scsi_qla_host *vha = sess->vha; |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1151 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1152 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1153 | ql_dbg(ql_dbg_disc, sess->vha, 0x210a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1154 | "%s sess %p for deletion %8phC\n", |
| 1155 | __func__, sess, sess->port_name); |
| 1156 | |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1157 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
| 1158 | if (sess->free_pending) { |
| 1159 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1160 | return; |
| 1161 | } |
| 1162 | sess->free_pending = 1; |
| 1163 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1164 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1165 | if (sess->se_sess) |
| 1166 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1167 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1168 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1169 | sess->disc_state = DSC_DELETE_PEND; |
| 1170 | sess->last_rscn_gen = sess->rscn_gen; |
| 1171 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1172 | |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 1173 | if (sess->nvme_flag & NVME_FLAG_REGISTERED && |
| 1174 | !(sess->nvme_flag & NVME_FLAG_DELETING)) { |
| 1175 | sess->nvme_flag |= NVME_FLAG_DELETING; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1176 | schedule_work(&sess->nvme_del_work); |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 1177 | } else { |
| 1178 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 1179 | schedule_work(&sess->free_work); |
| 1180 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1181 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1182 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1183 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1184 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1185 | { |
| 1186 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1187 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1188 | uint16_t loop_id; |
| 1189 | int res = 0; |
| 1190 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1191 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1192 | |
| 1193 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1194 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1195 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1196 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1197 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1198 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1199 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1200 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1201 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1202 | 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] | 1203 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1207 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1208 | if (!sess) { |
| 1209 | res = -ESRCH; |
| 1210 | return res; |
| 1211 | } |
| 1212 | |
| 1213 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1214 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1215 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1216 | mcmd, loop_id); |
| 1217 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1218 | 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] | 1219 | } |
| 1220 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1221 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1222 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1223 | if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1224 | sess->logout_on_delete = 0; |
| 1225 | sess->logo_ack_needed = 0; |
| 1226 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1227 | sess->scan_state = 0; |
| 1228 | } |
| 1229 | } |
| 1230 | |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1231 | void qlt_schedule_sess_for_deletion(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1232 | { |
| 1233 | struct qla_tgt *tgt = sess->tgt; |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1234 | unsigned long flags; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1235 | u16 sec; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1236 | |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1237 | switch (sess->disc_state) { |
| 1238 | case DSC_DELETE_PEND: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1239 | return; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1240 | case DSC_DELETED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1241 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1242 | wake_up_all(&tgt->waitQ); |
| 1243 | if (sess->vha->fcport_count == 0) |
| 1244 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1245 | |
| 1246 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1247 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1248 | return; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 1249 | break; |
| 1250 | case DSC_UPD_FCPORT: |
| 1251 | /* |
| 1252 | * This port is not done reporting to upper layer. |
| 1253 | * let it finish |
| 1254 | */ |
| 1255 | sess->next_disc_state = DSC_DELETE_PEND; |
| 1256 | sec = jiffies_to_msecs(jiffies - |
| 1257 | sess->jiffies_at_registration)/1000; |
| 1258 | if (sess->sec_since_registration < sec && sec && !(sec % 5)) { |
| 1259 | sess->sec_since_registration = sec; |
| 1260 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 1261 | "%s %8phC : Slow Rport registration(%d Sec)\n", |
| 1262 | __func__, sess->port_name, sec); |
| 1263 | } |
| 1264 | return; |
| 1265 | default: |
| 1266 | break; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1267 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1268 | |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1269 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1270 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1271 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1272 | return; |
| 1273 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1274 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Mikhail Malygin | 49d7bd3 | 2018-06-13 13:05:57 +0000 | [diff] [blame] | 1275 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1276 | |
| 1277 | sess->disc_state = DSC_DELETE_PEND; |
| 1278 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1279 | qla24xx_chk_fcp_state(sess); |
| 1280 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1281 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
Quinn Tran | 5c64005 | 2018-09-26 22:05:14 -0700 | [diff] [blame] | 1282 | "Scheduling sess %p for deletion %8phC\n", |
| 1283 | sess, sess->port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1284 | |
Quinn Tran | a01c77d | 2017-12-04 14:44:58 -0800 | [diff] [blame] | 1285 | INIT_WORK(&sess->del_work, qla24xx_delete_sess_fn); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1286 | WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work)); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1287 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1288 | |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1289 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1290 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1291 | struct fc_port *sess; |
| 1292 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1293 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1294 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1295 | if (sess->se_sess) |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1296 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1297 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1298 | |
| 1299 | /* At this point tgt could be already dead */ |
| 1300 | } |
| 1301 | |
| 1302 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 1303 | uint16_t *loop_id) |
| 1304 | { |
| 1305 | struct qla_hw_data *ha = vha->hw; |
| 1306 | dma_addr_t gid_list_dma; |
| 1307 | struct gid_list_info *gid_list; |
| 1308 | char *id_iter; |
| 1309 | int res, rc, i; |
| 1310 | uint16_t entries; |
| 1311 | |
| 1312 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1313 | &gid_list_dma, GFP_KERNEL); |
| 1314 | if (!gid_list) { |
| 1315 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1316 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1317 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1318 | return -ENOMEM; |
| 1319 | } |
| 1320 | |
| 1321 | /* Get list of logged in devices */ |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1322 | rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1323 | if (rc != QLA_SUCCESS) { |
| 1324 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1325 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1326 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1327 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1328 | goto out_free_id_list; |
| 1329 | } |
| 1330 | |
| 1331 | id_iter = (char *)gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1332 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1333 | for (i = 0; i < entries; i++) { |
| 1334 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 1335 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1336 | if ((gid->al_pa == s_id[2]) && |
| 1337 | (gid->area == s_id[1]) && |
| 1338 | (gid->domain == s_id[0])) { |
| 1339 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1340 | res = 0; |
| 1341 | break; |
| 1342 | } |
| 1343 | id_iter += ha->gid_list_info_size; |
| 1344 | } |
| 1345 | |
| 1346 | out_free_id_list: |
| 1347 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1348 | gid_list, gid_list_dma); |
| 1349 | return res; |
| 1350 | } |
| 1351 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1352 | /* |
| 1353 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1354 | * Caller must put it. |
| 1355 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1356 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1357 | struct scsi_qla_host *vha, |
| 1358 | fc_port_t *fcport, |
| 1359 | bool local) |
| 1360 | { |
| 1361 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1362 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1363 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1364 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1365 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1366 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1367 | |
| 1368 | if (fcport->se_sess) { |
| 1369 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1370 | ql_dbg(ql_dbg_disc, vha, 0x20f6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1371 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1372 | __func__, sess->port_name); |
| 1373 | return NULL; |
| 1374 | } |
| 1375 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1376 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1377 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1378 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1379 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1380 | /* |
| 1381 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1382 | * session eventually ends and release corresponding nport handle. |
| 1383 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1384 | * code will adjust these flags as necessary. |
| 1385 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1386 | sess->logout_on_delete = 1; |
| 1387 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1388 | sess->logout_completed = 0; |
| 1389 | |
| 1390 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1391 | &fcport->port_name[0], sess) < 0) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1392 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1393 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1394 | vha->vp_idx, fcport->port_name); |
| 1395 | return NULL; |
| 1396 | } else { |
| 1397 | kref_init(&fcport->sess_kref); |
| 1398 | /* |
| 1399 | * Take an extra reference to ->sess_kref here to handle |
| 1400 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1401 | */ |
| 1402 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1403 | ql_dbg(ql_dbg_disc, vha, 0x20f7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1404 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1405 | __func__, sess->port_name); |
| 1406 | return NULL; |
| 1407 | } |
| 1408 | |
| 1409 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1410 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1411 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1412 | |
| 1413 | qlt_do_generation_tick(vha, &sess->generation); |
| 1414 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1415 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1416 | |
| 1417 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1418 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1419 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1420 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1421 | |
| 1422 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1423 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1424 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1425 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1426 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1427 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1428 | |
| 1429 | return sess; |
| 1430 | } |
| 1431 | |
| 1432 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1433 | * max_gen - specifies maximum session generation |
| 1434 | * at which this deletion requestion is still valid |
| 1435 | */ |
| 1436 | void |
| 1437 | 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] | 1438 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1439 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1440 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1441 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1442 | |
| 1443 | if (!vha->hw->tgt.tgt_ops) |
| 1444 | return; |
| 1445 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1446 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1447 | return; |
| 1448 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1449 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1450 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1451 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1452 | return; |
| 1453 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1454 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1455 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1456 | return; |
| 1457 | } |
| 1458 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1459 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1460 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1461 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1462 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1463 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1464 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1465 | sess->generation); |
| 1466 | return; |
| 1467 | } |
| 1468 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1469 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1470 | |
| 1471 | sess->local = 1; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1472 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1473 | qlt_schedule_sess_for_deletion(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1477 | { |
| 1478 | struct qla_hw_data *ha = tgt->ha; |
| 1479 | unsigned long flags; |
| 1480 | int res; |
| 1481 | /* |
| 1482 | * We need to protect against race, when tgt is freed before or |
| 1483 | * inside wake_up() |
| 1484 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1485 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1486 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1487 | "tgt %p, sess_count=%d\n", |
| 1488 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1489 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1490 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1491 | |
| 1492 | return res; |
| 1493 | } |
| 1494 | |
| 1495 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1496 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1497 | { |
| 1498 | struct scsi_qla_host *vha = tgt->vha; |
| 1499 | struct qla_hw_data *ha = tgt->ha; |
| 1500 | unsigned long flags; |
| 1501 | |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1502 | mutex_lock(&ha->optrom_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1503 | mutex_lock(&qla_tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1504 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1505 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1506 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1507 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1508 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1509 | mutex_unlock(&ha->optrom_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1510 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1511 | } |
| 1512 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1513 | 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] | 1514 | vha->host_no, vha); |
| 1515 | /* |
| 1516 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1517 | * Lock is needed, because we still can get an incoming packet. |
| 1518 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1519 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1520 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1521 | qlt_clear_tgt_db(tgt); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1522 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1523 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1524 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1525 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1526 | "Waiting for sess works (tgt %p)", tgt); |
| 1527 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1528 | while (!list_empty(&tgt->sess_works_list)) { |
| 1529 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1530 | flush_scheduled_work(); |
| 1531 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1532 | } |
| 1533 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1534 | |
| 1535 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1536 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1537 | |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1538 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1539 | |
| 1540 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1541 | if (!ha->flags.host_shutting_down && |
| 1542 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1543 | qlt_disable_vha(vha); |
| 1544 | |
| 1545 | /* Wait for sessions to clear out (just in case) */ |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1546 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 1547 | mutex_unlock(&ha->optrom_mutex); |
| 1548 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1549 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1550 | } |
| 1551 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1552 | |
| 1553 | /* Called by tcm_qla2xxx configfs code */ |
| 1554 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1555 | { |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1556 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1557 | |
| 1558 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1559 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1560 | "Already in tgt->tgt_stopped state\n"); |
| 1561 | dump_stack(); |
| 1562 | return; |
| 1563 | } |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1564 | if (!tgt->tgt_stop) { |
| 1565 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
| 1566 | "%s: phase1 stop is not completed\n", __func__); |
| 1567 | dump_stack(); |
| 1568 | return; |
| 1569 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1570 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1571 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1572 | tgt->tgt_stop = 0; |
| 1573 | tgt->tgt_stopped = 1; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1574 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1575 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1576 | 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] | 1577 | tgt); |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 1578 | |
| 1579 | switch (vha->qlini_mode) { |
| 1580 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 1581 | vha->flags.online = 1; |
| 1582 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1583 | break; |
| 1584 | default: |
| 1585 | break; |
| 1586 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1587 | } |
| 1588 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1589 | |
| 1590 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1591 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1592 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1593 | scsi_qla_host_t *vha = tgt->vha; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1594 | void *node; |
| 1595 | u64 key = 0; |
| 1596 | u16 i; |
| 1597 | struct qla_qpair_hint *h; |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1598 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1599 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1600 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stop && |
| 1601 | !tgt->tgt_stopped) |
| 1602 | qlt_stop_phase1(tgt); |
| 1603 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1604 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1605 | qlt_stop_phase2(tgt); |
| 1606 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1607 | for (i = 0; i < vha->hw->max_qpairs + 1; i++) { |
| 1608 | unsigned long flags; |
| 1609 | |
| 1610 | h = &tgt->qphints[i]; |
| 1611 | if (h->qpair) { |
| 1612 | spin_lock_irqsave(h->qpair->qp_lock_ptr, flags); |
| 1613 | list_del(&h->hint_elem); |
| 1614 | spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags); |
| 1615 | h->qpair = NULL; |
| 1616 | } |
| 1617 | } |
| 1618 | kfree(tgt->qphints); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1619 | mutex_lock(&qla_tgt_mutex); |
| 1620 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
| 1621 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1622 | |
| 1623 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 1624 | btree_remove64(&tgt->lun_qpair_map, key); |
| 1625 | |
| 1626 | btree_destroy64(&tgt->lun_qpair_map); |
| 1627 | |
Sawan Chandak | 3be63b1e | 2017-12-04 14:45:04 -0800 | [diff] [blame] | 1628 | if (vha->vp_idx) |
| 1629 | if (ha->tgt.tgt_ops && |
| 1630 | ha->tgt.tgt_ops->remove_target && |
| 1631 | vha->vha_tgt.target_lport_ptr) |
| 1632 | ha->tgt.tgt_ops->remove_target(vha); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1633 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1634 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1635 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1636 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1637 | "Release of tgt %p finished\n", tgt); |
| 1638 | |
| 1639 | kfree(tgt); |
| 1640 | } |
| 1641 | |
| 1642 | /* ha->hardware_lock supposed to be held on entry */ |
| 1643 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1644 | const void *param, unsigned int param_size) |
| 1645 | { |
| 1646 | struct qla_tgt_sess_work_param *prm; |
| 1647 | unsigned long flags; |
| 1648 | |
| 1649 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1650 | if (!prm) { |
| 1651 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1652 | "qla_target(%d): Unable to create session " |
| 1653 | "work, command will be refused", 0); |
| 1654 | return -ENOMEM; |
| 1655 | } |
| 1656 | |
| 1657 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1658 | "Scheduling work (type %d, prm %p)" |
| 1659 | " to find session for param %p (size %d, tgt %p)\n", |
| 1660 | type, prm, param, param_size, tgt); |
| 1661 | |
| 1662 | prm->type = type; |
| 1663 | memcpy(&prm->tm_iocb, param, param_size); |
| 1664 | |
| 1665 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1666 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1667 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1668 | |
| 1669 | schedule_work(&tgt->sess_work); |
| 1670 | |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
| 1674 | /* |
| 1675 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1676 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1677 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1678 | struct imm_ntfy_from_isp *ntfy, |
| 1679 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1680 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1681 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1682 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1683 | struct qla_hw_data *ha = vha->hw; |
| 1684 | request_t *pkt; |
| 1685 | struct nack_to_isp *nack; |
| 1686 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 1687 | if (!ha->flags.fw_started) |
| 1688 | return; |
| 1689 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1690 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1691 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1692 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1693 | if (!pkt) { |
| 1694 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1695 | "qla_target(%d): %s failed: unable to allocate " |
| 1696 | "request packet\n", vha->vp_idx, __func__); |
| 1697 | return; |
| 1698 | } |
| 1699 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1700 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1701 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1702 | |
| 1703 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1704 | pkt->entry_count = 1; |
| 1705 | |
| 1706 | nack = (struct nack_to_isp *)pkt; |
| 1707 | nack->ox_id = ntfy->ox_id; |
| 1708 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1709 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1710 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1711 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1712 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1713 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1714 | } |
| 1715 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1716 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1717 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1718 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1719 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1720 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1721 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1722 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1723 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1724 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1725 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1726 | |
| 1727 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1728 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1729 | vha->vp_idx, nack->u.isp24.status); |
| 1730 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1731 | /* Memory Barrier */ |
| 1732 | wmb(); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1733 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1734 | } |
| 1735 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1736 | static int qlt_build_abts_resp_iocb(struct qla_tgt_mgmt_cmd *mcmd) |
| 1737 | { |
| 1738 | struct scsi_qla_host *vha = mcmd->vha; |
| 1739 | struct qla_hw_data *ha = vha->hw; |
| 1740 | struct abts_resp_to_24xx *resp; |
| 1741 | uint32_t f_ctl, h; |
| 1742 | uint8_t *p; |
| 1743 | int rc; |
| 1744 | struct abts_recv_from_24xx *abts = &mcmd->orig_iocb.abts; |
| 1745 | struct qla_qpair *qpair = mcmd->qpair; |
| 1746 | |
| 1747 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1748 | "Sending task mgmt ABTS response (ha=%p, status=%x)\n", |
| 1749 | ha, mcmd->fc_tm_rsp); |
| 1750 | |
| 1751 | rc = qlt_check_reserve_free_req(qpair, 1); |
| 1752 | if (rc) { |
| 1753 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1754 | "qla_target(%d): %s failed: unable to allocate request packet\n", |
| 1755 | vha->vp_idx, __func__); |
| 1756 | return -EAGAIN; |
| 1757 | } |
| 1758 | |
| 1759 | resp = (struct abts_resp_to_24xx *)qpair->req->ring_ptr; |
| 1760 | memset(resp, 0, sizeof(*resp)); |
| 1761 | |
| 1762 | h = qlt_make_handle(qpair); |
| 1763 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 1764 | /* |
| 1765 | * CTIO type 7 from the firmware doesn't provide a way to |
| 1766 | * know the initiator's LOOP ID, hence we can't find |
| 1767 | * the session and, so, the command. |
| 1768 | */ |
| 1769 | return -EAGAIN; |
| 1770 | } else { |
| 1771 | qpair->req->outstanding_cmds[h] = (srb_t *)mcmd; |
| 1772 | } |
| 1773 | |
| 1774 | resp->handle = MAKE_HANDLE(qpair->req->id, h); |
| 1775 | resp->entry_type = ABTS_RESP_24XX; |
| 1776 | resp->entry_count = 1; |
| 1777 | resp->nport_handle = abts->nport_handle; |
| 1778 | resp->vp_index = vha->vp_idx; |
| 1779 | resp->sof_type = abts->sof_type; |
| 1780 | resp->exchange_address = abts->exchange_address; |
| 1781 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
| 1782 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
| 1783 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1784 | F_CTL_SEQ_INITIATIVE); |
| 1785 | p = (uint8_t *)&f_ctl; |
| 1786 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1787 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1788 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1789 | |
| 1790 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1791 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1792 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1793 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1794 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1795 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1796 | |
| 1797 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1798 | if (mcmd->fc_tm_rsp == FCP_TMF_CMPL) { |
| 1799 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1800 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1801 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1802 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1803 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1804 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1805 | } else { |
| 1806 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1807 | resp->payload.ba_rjt.reason_code = |
| 1808 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1809 | /* Other bytes are zero */ |
| 1810 | } |
| 1811 | |
| 1812 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
| 1813 | |
| 1814 | /* Memory Barrier */ |
| 1815 | wmb(); |
| 1816 | if (qpair->reqq_start_iocbs) |
| 1817 | qpair->reqq_start_iocbs(qpair); |
| 1818 | else |
| 1819 | qla2x00_start_iocbs(vha, qpair->req); |
| 1820 | |
| 1821 | return rc; |
| 1822 | } |
| 1823 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1824 | /* |
| 1825 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1826 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1827 | static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1828 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1829 | bool ids_reversed) |
| 1830 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1831 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1832 | struct qla_hw_data *ha = vha->hw; |
| 1833 | struct abts_resp_to_24xx *resp; |
| 1834 | uint32_t f_ctl; |
| 1835 | uint8_t *p; |
| 1836 | |
| 1837 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1838 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1839 | ha, abts, status); |
| 1840 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1841 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, |
| 1842 | NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1843 | if (!resp) { |
| 1844 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1845 | "qla_target(%d): %s failed: unable to allocate " |
| 1846 | "request packet", vha->vp_idx, __func__); |
| 1847 | return; |
| 1848 | } |
| 1849 | |
| 1850 | resp->entry_type = ABTS_RESP_24XX; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1851 | resp->handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1852 | resp->entry_count = 1; |
| 1853 | resp->nport_handle = abts->nport_handle; |
| 1854 | resp->vp_index = vha->vp_idx; |
| 1855 | resp->sof_type = abts->sof_type; |
| 1856 | resp->exchange_address = abts->exchange_address; |
| 1857 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1858 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1859 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1860 | F_CTL_SEQ_INITIATIVE); |
| 1861 | p = (uint8_t *)&f_ctl; |
| 1862 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1863 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1864 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1865 | if (ids_reversed) { |
| 1866 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1867 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1868 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1869 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1870 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1871 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1872 | } else { |
| 1873 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1874 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1875 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1876 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1877 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1878 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1879 | } |
| 1880 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1881 | if (status == FCP_TMF_CMPL) { |
| 1882 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1883 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1884 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1885 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1886 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1887 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1888 | } else { |
| 1889 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1890 | resp->payload.ba_rjt.reason_code = |
| 1891 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1892 | /* Other bytes are zero */ |
| 1893 | } |
| 1894 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1895 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1896 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1897 | /* Memory Barrier */ |
| 1898 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 1899 | if (qpair->reqq_start_iocbs) |
| 1900 | qpair->reqq_start_iocbs(qpair); |
| 1901 | else |
| 1902 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | /* |
| 1906 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1907 | */ |
| 1908 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1909 | 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] | 1910 | { |
| 1911 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1912 | u16 tmp; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1913 | struct abts_recv_from_24xx *entry; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1914 | |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1915 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1916 | if (ctio == NULL) { |
| 1917 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1918 | "qla_target(%d): %s failed: unable to allocate " |
| 1919 | "request packet\n", vha->vp_idx, __func__); |
| 1920 | return; |
| 1921 | } |
| 1922 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1923 | if (mcmd) |
| 1924 | /* abts from remote port */ |
| 1925 | entry = &mcmd->orig_iocb.abts; |
| 1926 | else |
| 1927 | /* abts from this driver. */ |
| 1928 | entry = (struct abts_recv_from_24xx *)pkt; |
| 1929 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1930 | /* |
| 1931 | * We've got on entrance firmware's response on by us generated |
| 1932 | * ABTS response. So, in it ID fields are reversed. |
| 1933 | */ |
| 1934 | |
| 1935 | ctio->entry_type = CTIO_TYPE7; |
| 1936 | ctio->entry_count = 1; |
| 1937 | ctio->nport_handle = entry->nport_handle; |
| 1938 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1939 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1940 | ctio->vp_index = vha->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1941 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1942 | tmp = (CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1943 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1944 | if (mcmd) { |
| 1945 | ctio->initiator_id[0] = entry->fcp_hdr_le.s_id[0]; |
| 1946 | ctio->initiator_id[1] = entry->fcp_hdr_le.s_id[1]; |
| 1947 | ctio->initiator_id[2] = entry->fcp_hdr_le.s_id[2]; |
| 1948 | |
| 1949 | if (mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) |
| 1950 | tmp |= (mcmd->abort_io_attr << 9); |
| 1951 | else if (qpair->retry_term_cnt & 1) |
| 1952 | tmp |= (0x4 << 9); |
| 1953 | } else { |
| 1954 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1955 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1956 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1957 | |
| 1958 | if (qpair->retry_term_cnt & 1) |
| 1959 | tmp |= (0x4 << 9); |
| 1960 | } |
| 1961 | ctio->u.status1.flags = cpu_to_le16(tmp); |
| 1962 | ctio->u.status1.ox_id = entry->fcp_hdr_le.ox_id; |
| 1963 | |
| 1964 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1965 | "Sending retry TERM EXCH CTIO7 flags %04xh oxid %04xh attr valid %x\n", |
| 1966 | le16_to_cpu(ctio->u.status1.flags), |
| 1967 | le16_to_cpu(ctio->u.status1.ox_id), |
| 1968 | (mcmd && mcmd->flags & QLA24XX_MGMT_ABORT_IO_ATTR_VALID) ? 1 : 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1969 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1970 | /* Memory Barrier */ |
| 1971 | wmb(); |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 1972 | if (qpair->reqq_start_iocbs) |
| 1973 | qpair->reqq_start_iocbs(qpair); |
| 1974 | else |
| 1975 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1976 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 1977 | if (mcmd) |
| 1978 | qlt_build_abts_resp_iocb(mcmd); |
| 1979 | else |
| 1980 | qlt_24xx_send_abts_resp(qpair, |
| 1981 | (struct abts_recv_from_24xx *)entry, FCP_TMF_CMPL, true); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1982 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | /* drop cmds for the given lun |
| 1986 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1987 | * XXX does not go through the list of other port (which may have cmds |
| 1988 | * for the same lun) |
| 1989 | */ |
| 1990 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1991 | u64 lun, uint8_t *s_id) |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1992 | { |
| 1993 | struct qla_tgt_sess_op *op; |
| 1994 | struct qla_tgt_cmd *cmd; |
| 1995 | uint32_t key; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1996 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1997 | |
| 1998 | key = sid_to_key(s_id); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1999 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2000 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 2001 | uint32_t op_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 2002 | u64 op_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2003 | |
| 2004 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 2005 | op_lun = scsilun_to_int( |
| 2006 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 2007 | if (op_key == key && op_lun == lun) |
| 2008 | op->aborted = true; |
| 2009 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2010 | |
| 2011 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 2012 | uint32_t op_key; |
| 2013 | u64 op_lun; |
| 2014 | |
| 2015 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 2016 | op_lun = scsilun_to_int( |
| 2017 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 2018 | if (op_key == key && op_lun == lun) |
| 2019 | op->aborted = true; |
| 2020 | } |
| 2021 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2022 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 2023 | uint32_t cmd_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 2024 | u64 cmd_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2025 | |
| 2026 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 2027 | cmd_lun = scsilun_to_int( |
| 2028 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 2029 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 2030 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2031 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 2032 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 2033 | } |
| 2034 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2035 | static struct qla_qpair_hint *qlt_find_qphint(struct scsi_qla_host *vha, |
| 2036 | uint64_t unpacked_lun) |
| 2037 | { |
| 2038 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 2039 | struct qla_qpair_hint *h = NULL; |
| 2040 | |
| 2041 | if (vha->flags.qpairs_available) { |
| 2042 | h = btree_lookup64(&tgt->lun_qpair_map, unpacked_lun); |
| 2043 | if (!h) |
| 2044 | h = &tgt->qphints[0]; |
| 2045 | } else { |
| 2046 | h = &tgt->qphints[0]; |
| 2047 | } |
| 2048 | |
| 2049 | return h; |
| 2050 | } |
| 2051 | |
| 2052 | static void qlt_do_tmr_work(struct work_struct *work) |
| 2053 | { |
| 2054 | struct qla_tgt_mgmt_cmd *mcmd = |
| 2055 | container_of(work, struct qla_tgt_mgmt_cmd, work); |
| 2056 | struct qla_hw_data *ha = mcmd->vha->hw; |
| 2057 | int rc = EIO; |
| 2058 | uint32_t tag; |
| 2059 | unsigned long flags; |
| 2060 | |
| 2061 | switch (mcmd->tmr_func) { |
| 2062 | case QLA_TGT_ABTS: |
| 2063 | tag = mcmd->orig_iocb.abts.exchange_addr_to_abort; |
| 2064 | break; |
| 2065 | default: |
| 2066 | tag = 0; |
| 2067 | break; |
| 2068 | } |
| 2069 | |
| 2070 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, mcmd->unpacked_lun, |
| 2071 | mcmd->tmr_func, tag); |
| 2072 | |
| 2073 | if (rc != 0) { |
| 2074 | spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags); |
| 2075 | switch (mcmd->tmr_func) { |
| 2076 | case QLA_TGT_ABTS: |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2077 | mcmd->fc_tm_rsp = FCP_TMF_REJECTED; |
| 2078 | qlt_build_abts_resp_iocb(mcmd); |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2079 | break; |
| 2080 | case QLA_TGT_LUN_RESET: |
| 2081 | case QLA_TGT_CLEAR_TS: |
| 2082 | case QLA_TGT_ABORT_TS: |
| 2083 | case QLA_TGT_CLEAR_ACA: |
| 2084 | case QLA_TGT_TARGET_RESET: |
| 2085 | qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio, |
| 2086 | qla_sam_status); |
| 2087 | break; |
| 2088 | |
| 2089 | case QLA_TGT_ABORT_ALL: |
| 2090 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 2091 | case QLA_TGT_NEXUS_LOSS: |
| 2092 | qlt_send_notify_ack(mcmd->qpair, |
| 2093 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
| 2094 | break; |
| 2095 | } |
| 2096 | spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags); |
| 2097 | |
| 2098 | ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052, |
| 2099 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 2100 | mcmd->vha->vp_idx, rc); |
| 2101 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2102 | } |
| 2103 | } |
| 2104 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2105 | /* ha->hardware_lock supposed to be held on entry */ |
| 2106 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2107 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2108 | { |
| 2109 | struct qla_hw_data *ha = vha->hw; |
| 2110 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2111 | struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0]; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 2112 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2113 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 2114 | "qla_target(%d): task abort (tag=%d)\n", |
| 2115 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 2116 | |
| 2117 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 2118 | if (mcmd == NULL) { |
| 2119 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 2120 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 2121 | vha->vp_idx, __func__); |
| 2122 | return -ENOMEM; |
| 2123 | } |
| 2124 | memset(mcmd, 0, sizeof(*mcmd)); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2125 | mcmd->cmd_type = TYPE_TGT_TMCMD; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2126 | mcmd->sess = sess; |
| 2127 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2128 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 2129 | mcmd->tmr_func = QLA_TGT_ABTS; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2130 | mcmd->qpair = h->qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2131 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2132 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 2133 | /* |
| 2134 | * LUN is looked up by target-core internally based on the passed |
| 2135 | * abts->exchange_addr_to_abort tag. |
| 2136 | */ |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2137 | mcmd->se_cmd.cpuid = h->cpuid; |
| 2138 | |
| 2139 | if (ha->tgt.tgt_ops->find_cmd_by_tag) { |
| 2140 | struct qla_tgt_cmd *abort_cmd; |
| 2141 | |
| 2142 | abort_cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess, |
| 2143 | abts->exchange_addr_to_abort); |
| 2144 | if (abort_cmd && abort_cmd->qpair) { |
| 2145 | mcmd->qpair = abort_cmd->qpair; |
| 2146 | mcmd->se_cmd.cpuid = abort_cmd->se_cmd.cpuid; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2147 | mcmd->abort_io_attr = abort_cmd->atio.u.isp24.attr; |
| 2148 | mcmd->flags = QLA24XX_MGMT_ABORT_IO_ATTR_VALID; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2149 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2150 | } |
| 2151 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 2152 | INIT_WORK(&mcmd->work, qlt_do_tmr_work); |
| 2153 | queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, &mcmd->work); |
| 2154 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2155 | return 0; |
| 2156 | } |
| 2157 | |
| 2158 | /* |
| 2159 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2160 | */ |
| 2161 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 2162 | struct abts_recv_from_24xx *abts) |
| 2163 | { |
| 2164 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2165 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2166 | uint32_t tag = abts->exchange_addr_to_abort; |
| 2167 | uint8_t s_id[3]; |
| 2168 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2169 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2170 | |
| 2171 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 2172 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 2173 | "qla_target(%d): ABTS: Abort Sequence not " |
| 2174 | "supported\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2175 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2176 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2177 | return; |
| 2178 | } |
| 2179 | |
| 2180 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 2181 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 2182 | "qla_target(%d): ABTS: Unknown Exchange " |
| 2183 | "Address received\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2184 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2185 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2186 | return; |
| 2187 | } |
| 2188 | |
| 2189 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 2190 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 2191 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 2192 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 2193 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 2194 | |
| 2195 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 2196 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 2197 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 2198 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2199 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2200 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 2201 | if (!sess) { |
| 2202 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
Colin Ian King | 03fea73 | 2018-03-19 10:53:41 +0000 | [diff] [blame] | 2203 | "qla_target(%d): task abort for non-existent session\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2204 | vha->vp_idx); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2205 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2206 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [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 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2211 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2212 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2213 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2214 | if (sess->deleted) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2215 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2216 | false); |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 2217 | return; |
| 2218 | } |
| 2219 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2220 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 2221 | if (rc != 0) { |
| 2222 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 2223 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 2224 | vha->vp_idx, rc); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2225 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2226 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2227 | return; |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | /* |
| 2232 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2233 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2234 | static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2235 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 2236 | { |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2237 | struct scsi_qla_host *ha = mcmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2238 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 2239 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2240 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2241 | |
| 2242 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 2243 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 2244 | ha, atio, resp_code); |
| 2245 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2246 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2247 | ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2248 | if (ctio == NULL) { |
| 2249 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 2250 | "qla_target(%d): %s failed: unable to allocate " |
| 2251 | "request packet\n", ha->vp_idx, __func__); |
| 2252 | return; |
| 2253 | } |
| 2254 | |
| 2255 | ctio->entry_type = CTIO_TYPE7; |
| 2256 | ctio->entry_count = 1; |
| 2257 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 2258 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2259 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2260 | ctio->vp_index = ha->vp_idx; |
| 2261 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2262 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2263 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2264 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2265 | temp = (atio->u.isp24.attr << 9)| |
| 2266 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2267 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2268 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2269 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2270 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2271 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2272 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2273 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2274 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2275 | /* Memory Barrier */ |
| 2276 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2277 | if (qpair->reqq_start_iocbs) |
| 2278 | qpair->reqq_start_iocbs(qpair); |
| 2279 | else |
| 2280 | qla2x00_start_iocbs(ha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2284 | { |
| 2285 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2286 | } |
| 2287 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2288 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2289 | /* |
| 2290 | * ha->hardware_lock supposed to be held on entry. Might drop it, then |
| 2291 | * reacquire |
| 2292 | */ |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2293 | 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] | 2294 | uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq) |
| 2295 | { |
| 2296 | struct atio_from_isp *atio = &cmd->atio; |
| 2297 | struct ctio7_to_24xx *ctio; |
| 2298 | uint16_t temp; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2299 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2300 | |
| 2301 | ql_dbg(ql_dbg_tgt_dif, vha, 0x3066, |
| 2302 | "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, " |
| 2303 | "sense_key=%02x, asc=%02x, ascq=%02x", |
| 2304 | vha, atio, scsi_status, sense_key, asc, ascq); |
| 2305 | |
| 2306 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); |
| 2307 | if (!ctio) { |
| 2308 | ql_dbg(ql_dbg_async, vha, 0x3067, |
| 2309 | "qla2x00t(%ld): %s failed: unable to allocate request packet", |
| 2310 | vha->host_no, __func__); |
| 2311 | goto out; |
| 2312 | } |
| 2313 | |
| 2314 | ctio->entry_type = CTIO_TYPE7; |
| 2315 | ctio->entry_count = 1; |
| 2316 | ctio->handle = QLA_TGT_SKIP_HANDLE; |
| 2317 | ctio->nport_handle = cmd->sess->loop_id; |
| 2318 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
| 2319 | ctio->vp_index = vha->vp_idx; |
| 2320 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2321 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2322 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2323 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2324 | temp = (atio->u.isp24.attr << 9) | |
| 2325 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2326 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2327 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2328 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
| 2329 | ctio->u.status1.scsi_status = |
| 2330 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status); |
| 2331 | ctio->u.status1.response_len = cpu_to_le16(18); |
| 2332 | ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
| 2333 | |
| 2334 | if (ctio->u.status1.residual != 0) |
| 2335 | ctio->u.status1.scsi_status |= |
| 2336 | cpu_to_le16(SS_RESIDUAL_UNDER); |
| 2337 | |
| 2338 | /* Response code and sense key */ |
| 2339 | put_unaligned_le32(((0x70 << 24) | (sense_key << 8)), |
| 2340 | (&ctio->u.status1.sense_data)[0]); |
| 2341 | /* Additional sense length */ |
| 2342 | put_unaligned_le32(0x0a, (&ctio->u.status1.sense_data)[1]); |
| 2343 | /* ASC and ASCQ */ |
| 2344 | put_unaligned_le32(((asc << 24) | (ascq << 16)), |
| 2345 | (&ctio->u.status1.sense_data)[3]); |
| 2346 | |
| 2347 | /* Memory Barrier */ |
| 2348 | wmb(); |
| 2349 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2350 | if (qpair->reqq_start_iocbs) |
| 2351 | qpair->reqq_start_iocbs(qpair); |
| 2352 | else |
| 2353 | qla2x00_start_iocbs(vha, qpair->req); |
| 2354 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2355 | out: |
| 2356 | return; |
| 2357 | } |
| 2358 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2359 | /* callback from target fabric module code */ |
| 2360 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2361 | { |
| 2362 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2363 | struct qla_hw_data *ha = vha->hw; |
| 2364 | unsigned long flags; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2365 | struct qla_qpair *qpair = mcmd->qpair; |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2366 | bool free_mcmd = true; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2367 | |
| 2368 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2369 | "TM response mcmd (%p) status %#x state %#x", |
| 2370 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2371 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2372 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2373 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2374 | if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2375 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2376 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2377 | * previous life, just abort the processing. |
| 2378 | */ |
| 2379 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2380 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2381 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2382 | mcmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2383 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2384 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2385 | return; |
| 2386 | } |
| 2387 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2388 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2389 | switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) { |
| 2390 | case ELS_LOGO: |
| 2391 | case ELS_PRLO: |
| 2392 | case ELS_TPRLO: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2393 | ql_dbg(ql_dbg_disc, vha, 0x2106, |
Bart Van Assche | 19ce192 | 2019-04-17 14:44:11 -0700 | [diff] [blame] | 2394 | "TM response logo %8phC status %#x state %#x", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2395 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2396 | mcmd->flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 2397 | qlt_schedule_sess_for_deletion(mcmd->sess); |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2398 | break; |
| 2399 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2400 | qlt_send_notify_ack(vha->hw->base_qpair, |
| 2401 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
Bart Van Assche | 8837aa8 | 2018-11-27 15:04:54 -0800 | [diff] [blame] | 2402 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2403 | } |
| 2404 | } else { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2405 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) { |
| 2406 | qlt_build_abts_resp_iocb(mcmd); |
| 2407 | free_mcmd = false; |
| 2408 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2409 | qlt_24xx_send_task_mgmt_ctio(qpair, mcmd, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2410 | mcmd->fc_tm_rsp); |
| 2411 | } |
| 2412 | /* |
| 2413 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2414 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2415 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2416 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2417 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2418 | * qlt_xmit_tm_rsp() returns here.. |
| 2419 | */ |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 2420 | if (free_mcmd) |
| 2421 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2422 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2423 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2424 | } |
| 2425 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2426 | |
| 2427 | /* No locks */ |
| 2428 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2429 | { |
| 2430 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2431 | |
| 2432 | BUG_ON(cmd->sg_cnt == 0); |
| 2433 | |
| 2434 | prm->sg = (struct scatterlist *)cmd->sg; |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2435 | prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2436 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2437 | if (unlikely(prm->seg_cnt == 0)) |
| 2438 | goto out_err; |
| 2439 | |
| 2440 | prm->cmd->sg_mapped = 1; |
| 2441 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2442 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2443 | /* |
| 2444 | * If greater than four sg entries then we need to allocate |
| 2445 | * the continuation entries |
| 2446 | */ |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2447 | if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2448 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2449 | QLA_TGT_DATASEGS_PER_CMD_24XX, |
| 2450 | QLA_TGT_DATASEGS_PER_CONT_24XX); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2451 | } else { |
| 2452 | /* DIF */ |
| 2453 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2454 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2455 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2456 | prm->tot_dsds = prm->seg_cnt; |
| 2457 | } else |
| 2458 | prm->tot_dsds = prm->seg_cnt; |
| 2459 | |
| 2460 | if (cmd->prot_sg_cnt) { |
| 2461 | prm->prot_sg = cmd->prot_sg; |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2462 | prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2463 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2464 | cmd->dma_data_direction); |
| 2465 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2466 | goto out_err; |
| 2467 | |
| 2468 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2469 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2470 | /* Dif Bundling not support here */ |
| 2471 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2472 | cmd->blk_sz); |
| 2473 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2474 | } else |
| 2475 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2476 | } |
| 2477 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2478 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2479 | return 0; |
| 2480 | |
| 2481 | out_err: |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2482 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2483 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2484 | 0, prm->cmd->sg_cnt); |
| 2485 | return -1; |
| 2486 | } |
| 2487 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2488 | 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] | 2489 | { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2490 | struct qla_hw_data *ha; |
| 2491 | struct qla_qpair *qpair; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 2492 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2493 | if (!cmd->sg_mapped) |
| 2494 | return; |
| 2495 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2496 | qpair = cmd->qpair; |
| 2497 | |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2498 | dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt, |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2499 | cmd->dma_data_direction); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2500 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2501 | |
| 2502 | if (cmd->prot_sg_cnt) |
Christoph Hellwig | e7d0bb7 | 2018-10-11 09:42:07 +0200 | [diff] [blame] | 2503 | 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] | 2504 | cmd->dma_data_direction); |
| 2505 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2506 | if (!cmd->ctx) |
| 2507 | return; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2508 | ha = vha->hw; |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2509 | if (cmd->ctx_dsd_alloced) |
| 2510 | qla2x00_clean_dsd_pool(ha, cmd->ctx); |
| 2511 | |
| 2512 | 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] | 2513 | } |
| 2514 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2515 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2516 | uint32_t req_cnt) |
| 2517 | { |
Quinn Tran | d63b328 | 2017-06-02 09:12:07 -0700 | [diff] [blame] | 2518 | uint32_t cnt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2519 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2520 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2521 | if (req->cnt < (req_cnt + 2)) { |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 2522 | cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr : |
| 2523 | RD_REG_DWORD_RELAXED(req->req_q_out)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2524 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2525 | if (req->ring_index < cnt) |
| 2526 | req->cnt = cnt - req->ring_index; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2527 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2528 | req->cnt = req->length - (req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2529 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2530 | if (unlikely(req->cnt < (req_cnt + 2))) |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2531 | return -EAGAIN; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2532 | } |
| 2533 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2534 | req->cnt -= req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2535 | |
| 2536 | return 0; |
| 2537 | } |
| 2538 | |
| 2539 | /* |
| 2540 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2541 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2542 | static inline void *qlt_get_req_pkt(struct req_que *req) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2543 | { |
| 2544 | /* Adjust ring index. */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2545 | req->ring_index++; |
| 2546 | if (req->ring_index == req->length) { |
| 2547 | req->ring_index = 0; |
| 2548 | req->ring_ptr = req->ring; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2549 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2550 | req->ring_ptr++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2551 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2552 | return (cont_entry_t *)req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2556 | static inline uint32_t qlt_make_handle(struct qla_qpair *qpair) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2557 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2558 | uint32_t h; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2559 | int index; |
| 2560 | uint8_t found = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2561 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2562 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2563 | h = req->current_outstanding_cmd; |
| 2564 | |
| 2565 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 2566 | h++; |
| 2567 | if (h == req->num_outstanding_cmds) |
| 2568 | h = 1; |
| 2569 | |
| 2570 | if (h == QLA_TGT_SKIP_HANDLE) |
| 2571 | continue; |
| 2572 | |
| 2573 | if (!req->outstanding_cmds[h]) { |
| 2574 | found = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2575 | break; |
| 2576 | } |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2577 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2578 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2579 | if (found) { |
| 2580 | req->current_outstanding_cmd = h; |
| 2581 | } else { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2582 | ql_dbg(ql_dbg_io, qpair->vha, 0x305b, |
| 2583 | "qla_target(%d): Ran out of empty cmd slots\n", |
| 2584 | qpair->vha->vp_idx); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2585 | h = QLA_TGT_NULL_HANDLE; |
| 2586 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2587 | |
| 2588 | return h; |
| 2589 | } |
| 2590 | |
| 2591 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2592 | static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair, |
| 2593 | struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2594 | { |
| 2595 | uint32_t h; |
| 2596 | struct ctio7_to_24xx *pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2597 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2598 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2599 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2600 | pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2601 | prm->pkt = pkt; |
| 2602 | memset(pkt, 0, sizeof(*pkt)); |
| 2603 | |
| 2604 | pkt->entry_type = CTIO_TYPE7; |
| 2605 | pkt->entry_count = (uint8_t)prm->req_cnt; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2606 | pkt->vp_index = prm->cmd->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2607 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2608 | h = qlt_make_handle(qpair); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2609 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2610 | /* |
| 2611 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2612 | * know the initiator's LOOP ID, hence we can't find |
| 2613 | * the session and, so, the command. |
| 2614 | */ |
| 2615 | return -EAGAIN; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 2616 | } else |
| 2617 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2618 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2619 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2620 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
| 2621 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2622 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2623 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2624 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2625 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2626 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2627 | temp = atio->u.isp24.attr << 9; |
| 2628 | pkt->u.status0.flags |= cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2629 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2630 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2631 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2632 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2633 | return 0; |
| 2634 | } |
| 2635 | |
| 2636 | /* |
| 2637 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2638 | * that there is sufficient amount of request entries to not drop it. |
| 2639 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2640 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2641 | { |
| 2642 | int cnt; |
| 2643 | uint32_t *dword_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2644 | |
| 2645 | /* Build continuation packets */ |
| 2646 | while (prm->seg_cnt > 0) { |
| 2647 | cont_a64_entry_t *cont_pkt64 = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2648 | (cont_a64_entry_t *)qlt_get_req_pkt( |
| 2649 | prm->cmd->qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2650 | |
| 2651 | /* |
| 2652 | * Make sure that from cont_pkt64 none of |
| 2653 | * 64-bit specific fields used for 32-bit |
| 2654 | * addressing. Cast to (cont_entry_t *) for |
| 2655 | * that. |
| 2656 | */ |
| 2657 | |
| 2658 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2659 | |
| 2660 | cont_pkt64->entry_count = 1; |
| 2661 | cont_pkt64->sys_define = 0; |
| 2662 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2663 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
| 2664 | dword_ptr = (uint32_t *)&cont_pkt64->dseg_0_address; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2665 | |
| 2666 | /* Load continuation entry data segments */ |
| 2667 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2668 | cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2669 | cnt++, prm->seg_cnt--) { |
| 2670 | *dword_ptr++ = |
Christoph Hellwig | 3d5ca1e | 2018-10-18 15:03:37 +0200 | [diff] [blame] | 2671 | cpu_to_le32(lower_32_bits |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2672 | (sg_dma_address(prm->sg))); |
Christoph Hellwig | 3d5ca1e | 2018-10-18 15:03:37 +0200 | [diff] [blame] | 2673 | *dword_ptr++ = cpu_to_le32(upper_32_bits |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2674 | (sg_dma_address(prm->sg))); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2675 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2676 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2677 | prm->sg = sg_next(prm->sg); |
| 2678 | } |
| 2679 | } |
| 2680 | } |
| 2681 | |
| 2682 | /* |
| 2683 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2684 | * that there is sufficient amount of request entries to not drop it. |
| 2685 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2686 | static void qlt_load_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2687 | { |
| 2688 | int cnt; |
| 2689 | uint32_t *dword_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2690 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2691 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2692 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2693 | |
| 2694 | /* Setup packet address segment pointer */ |
| 2695 | dword_ptr = pkt24->u.status0.dseg_0_address; |
| 2696 | |
| 2697 | /* Set total data segment count */ |
| 2698 | if (prm->seg_cnt) |
| 2699 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2700 | |
| 2701 | if (prm->seg_cnt == 0) { |
| 2702 | /* No data transfer */ |
| 2703 | *dword_ptr++ = 0; |
| 2704 | *dword_ptr = 0; |
| 2705 | return; |
| 2706 | } |
| 2707 | |
| 2708 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2709 | |
| 2710 | /* Load command entry data segments */ |
| 2711 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2712 | (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2713 | cnt++, prm->seg_cnt--) { |
| 2714 | *dword_ptr++ = |
Christoph Hellwig | 3d5ca1e | 2018-10-18 15:03:37 +0200 | [diff] [blame] | 2715 | cpu_to_le32(lower_32_bits(sg_dma_address(prm->sg))); |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2716 | |
Christoph Hellwig | 3d5ca1e | 2018-10-18 15:03:37 +0200 | [diff] [blame] | 2717 | *dword_ptr++ = cpu_to_le32(upper_32_bits( |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2718 | sg_dma_address(prm->sg))); |
| 2719 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2720 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2721 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2722 | prm->sg = sg_next(prm->sg); |
| 2723 | } |
| 2724 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2725 | qlt_load_cont_data_segments(prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2729 | { |
| 2730 | return cmd->bufflen > 0; |
| 2731 | } |
| 2732 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2733 | static void qlt_print_dif_err(struct qla_tgt_prm *prm) |
| 2734 | { |
| 2735 | struct qla_tgt_cmd *cmd; |
| 2736 | struct scsi_qla_host *vha; |
| 2737 | |
| 2738 | /* asc 0x10=dif error */ |
| 2739 | if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) { |
| 2740 | cmd = prm->cmd; |
| 2741 | vha = cmd->vha; |
| 2742 | /* ASCQ */ |
| 2743 | switch (prm->sense_buffer[13]) { |
| 2744 | case 1: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2745 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2746 | "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2747 | "se_cmd=%p tag[%x]", |
| 2748 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2749 | cmd->atio.u.isp24.exchange_addr); |
| 2750 | break; |
| 2751 | case 2: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2752 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2753 | "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2754 | "se_cmd=%p tag[%x]", |
| 2755 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2756 | cmd->atio.u.isp24.exchange_addr); |
| 2757 | break; |
| 2758 | case 3: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2759 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2760 | "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2761 | "se_cmd=%p tag[%x]", |
| 2762 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2763 | cmd->atio.u.isp24.exchange_addr); |
| 2764 | break; |
| 2765 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2766 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe010, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2767 | "BE detected Dif ERR: lba[%llx|%lld] len[%x] " |
| 2768 | "se_cmd=%p tag[%x]", |
| 2769 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2770 | cmd->atio.u.isp24.exchange_addr); |
| 2771 | break; |
| 2772 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2773 | ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2777 | /* |
| 2778 | * Called without ha->hardware_lock held |
| 2779 | */ |
| 2780 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2781 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2782 | uint32_t *full_req_cnt) |
| 2783 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2784 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2785 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2786 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2787 | prm->cmd = cmd; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2788 | prm->tgt = cmd->tgt; |
| 2789 | prm->pkt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2790 | prm->rq_result = scsi_status; |
| 2791 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2792 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2793 | prm->sg = NULL; |
| 2794 | prm->seg_cnt = -1; |
| 2795 | prm->req_cnt = 1; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2796 | prm->residual = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2797 | prm->add_status_pkt = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2798 | prm->prot_sg = NULL; |
| 2799 | prm->prot_seg_cnt = 0; |
| 2800 | prm->tot_dsds = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2801 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2802 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2803 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2804 | return -EAGAIN; |
| 2805 | } |
| 2806 | |
| 2807 | *full_req_cnt = prm->req_cnt; |
| 2808 | |
| 2809 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2810 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2811 | ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2812 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2813 | prm->residual, se_cmd->tag, |
| 2814 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2815 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2816 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2817 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2818 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2819 | ql_dbg_qp(ql_dbg_io, qpair, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2820 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2821 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2822 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2823 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2824 | } |
| 2825 | |
| 2826 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2827 | /* |
| 2828 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2829 | * ignored in *xmit_response() below |
| 2830 | */ |
| 2831 | if (qlt_has_data(cmd)) { |
| 2832 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2833 | (IS_FWI2_CAPABLE(cmd->vha->hw) && |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2834 | (prm->rq_result != 0))) { |
| 2835 | prm->add_status_pkt = 1; |
| 2836 | (*full_req_cnt)++; |
| 2837 | } |
| 2838 | } |
| 2839 | } |
| 2840 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2841 | return 0; |
| 2842 | } |
| 2843 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2844 | static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd, |
| 2845 | int sending_sense) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2846 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2847 | if (cmd->qpair->enable_class_2) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2848 | return 0; |
| 2849 | |
| 2850 | if (sending_sense) |
| 2851 | return cmd->conf_compl_supported; |
| 2852 | else |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2853 | return cmd->qpair->enable_explicit_conf && |
| 2854 | cmd->conf_compl_supported; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2855 | } |
| 2856 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2857 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2858 | struct qla_tgt_prm *prm) |
| 2859 | { |
| 2860 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2861 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2862 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2863 | if (qlt_need_explicit_conf(prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2864 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2865 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2866 | CTIO7_FLAGS_CONFORM_REQ); |
| 2867 | } |
| 2868 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2869 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2870 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2871 | int i; |
| 2872 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2873 | if (qlt_need_explicit_conf(prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2874 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2875 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2876 | "Skipping EXPLICIT_CONFORM and " |
| 2877 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2878 | "non GOOD status\n"); |
| 2879 | goto skip_explict_conf; |
| 2880 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2881 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2882 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2883 | CTIO7_FLAGS_CONFORM_REQ); |
| 2884 | } |
| 2885 | skip_explict_conf: |
| 2886 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2887 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2888 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2889 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2890 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2891 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2892 | ctio->u.status1.sense_length = |
| 2893 | cpu_to_le16(prm->sense_buffer_len); |
| 2894 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2895 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2896 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2897 | |
| 2898 | qlt_print_dif_err(prm); |
| 2899 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2900 | } else { |
| 2901 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2902 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2903 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2904 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2905 | ctio->u.status1.sense_length = 0; |
| 2906 | memset(ctio->u.status1.sense_data, 0, |
| 2907 | sizeof(ctio->u.status1.sense_data)); |
| 2908 | } |
| 2909 | |
| 2910 | /* Sense with len > 24, is it possible ??? */ |
| 2911 | } |
| 2912 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2913 | static inline int |
| 2914 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2915 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2916 | switch (se_cmd->prot_op) { |
| 2917 | case TARGET_PROT_DOUT_INSERT: |
| 2918 | case TARGET_PROT_DIN_STRIP: |
| 2919 | if (ql2xenablehba_err_chk >= 1) |
| 2920 | return 1; |
| 2921 | break; |
| 2922 | case TARGET_PROT_DOUT_PASS: |
| 2923 | case TARGET_PROT_DIN_PASS: |
| 2924 | if (ql2xenablehba_err_chk >= 2) |
| 2925 | return 1; |
| 2926 | break; |
| 2927 | case TARGET_PROT_DIN_INSERT: |
| 2928 | case TARGET_PROT_DOUT_STRIP: |
| 2929 | return 1; |
| 2930 | default: |
| 2931 | break; |
| 2932 | } |
| 2933 | return 0; |
| 2934 | } |
| 2935 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2936 | static inline int |
| 2937 | qla_tgt_ref_mask_check(struct se_cmd *se_cmd) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2938 | { |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2939 | switch (se_cmd->prot_op) { |
| 2940 | case TARGET_PROT_DIN_INSERT: |
| 2941 | case TARGET_PROT_DOUT_INSERT: |
| 2942 | case TARGET_PROT_DIN_STRIP: |
| 2943 | case TARGET_PROT_DOUT_STRIP: |
| 2944 | case TARGET_PROT_DIN_PASS: |
| 2945 | case TARGET_PROT_DOUT_PASS: |
| 2946 | return 1; |
| 2947 | default: |
| 2948 | return 0; |
| 2949 | } |
| 2950 | return 0; |
| 2951 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2952 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2953 | /* |
| 2954 | * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command |
| 2955 | */ |
| 2956 | static void |
| 2957 | qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx, |
| 2958 | uint16_t *pfw_prot_opts) |
| 2959 | { |
| 2960 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2961 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2962 | scsi_qla_host_t *vha = cmd->tgt->vha; |
| 2963 | struct qla_hw_data *ha = vha->hw; |
| 2964 | uint32_t t32 = 0; |
| 2965 | |
| 2966 | /* |
| 2967 | * wait till Mode Sense/Select cmd, modepage Ah, subpage 2 |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2968 | * have been immplemented by TCM, before AppTag is avail. |
| 2969 | * Look for modesense_handlers[] |
| 2970 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2971 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2972 | ctx->app_tag_mask[0] = 0x0; |
| 2973 | ctx->app_tag_mask[1] = 0x0; |
| 2974 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2975 | if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2976 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2977 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2978 | *pfw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2979 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2980 | *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2981 | } |
| 2982 | |
| 2983 | t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts); |
| 2984 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2985 | switch (se_cmd->prot_type) { |
| 2986 | case TARGET_DIF_TYPE0_PROT: |
| 2987 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2988 | * No check for ql2xenablehba_err_chk, as it |
| 2989 | * would be an I/O error if hba tag generation |
| 2990 | * is not done. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2991 | */ |
| 2992 | ctx->ref_tag = cpu_to_le32(lba); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2993 | /* enable ALL bytes of the ref tag */ |
| 2994 | ctx->ref_tag_mask[0] = 0xff; |
| 2995 | ctx->ref_tag_mask[1] = 0xff; |
| 2996 | ctx->ref_tag_mask[2] = 0xff; |
| 2997 | ctx->ref_tag_mask[3] = 0xff; |
| 2998 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2999 | case TARGET_DIF_TYPE1_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3000 | /* |
| 3001 | * For TYPE 1 protection: 16 bit GUARD tag, 32 bit |
| 3002 | * REF tag, and 16 bit app tag. |
| 3003 | */ |
| 3004 | ctx->ref_tag = cpu_to_le32(lba); |
| 3005 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 3006 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 3007 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 3008 | break; |
| 3009 | } |
| 3010 | /* enable ALL bytes of the ref tag */ |
| 3011 | ctx->ref_tag_mask[0] = 0xff; |
| 3012 | ctx->ref_tag_mask[1] = 0xff; |
| 3013 | ctx->ref_tag_mask[2] = 0xff; |
| 3014 | ctx->ref_tag_mask[3] = 0xff; |
| 3015 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3016 | case TARGET_DIF_TYPE2_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3017 | /* |
| 3018 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF |
| 3019 | * tag has to match LBA in CDB + N |
| 3020 | */ |
| 3021 | ctx->ref_tag = cpu_to_le32(lba); |
| 3022 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 3023 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 3024 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 3025 | break; |
| 3026 | } |
| 3027 | /* enable ALL bytes of the ref tag */ |
| 3028 | ctx->ref_tag_mask[0] = 0xff; |
| 3029 | ctx->ref_tag_mask[1] = 0xff; |
| 3030 | ctx->ref_tag_mask[2] = 0xff; |
| 3031 | ctx->ref_tag_mask[3] = 0xff; |
| 3032 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3033 | case TARGET_DIF_TYPE3_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3034 | /* For TYPE 3 protection: 16 bit GUARD only */ |
| 3035 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 3036 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 3037 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 3038 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3039 | } |
| 3040 | } |
| 3041 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3042 | static inline int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3043 | 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] | 3044 | { |
| 3045 | uint32_t *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3046 | uint32_t transfer_length = 0; |
| 3047 | uint32_t data_bytes; |
| 3048 | uint32_t dif_bytes; |
| 3049 | uint8_t bundling = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3050 | struct crc_context *crc_ctx_pkt = NULL; |
| 3051 | struct qla_hw_data *ha; |
| 3052 | struct ctio_crc2_to_fw *pkt; |
| 3053 | dma_addr_t crc_ctx_dma; |
| 3054 | uint16_t fw_prot_opts = 0; |
| 3055 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 3056 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 3057 | uint32_t h; |
| 3058 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3059 | struct qla_tc_param tc; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3060 | uint16_t t16; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3061 | scsi_qla_host_t *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3062 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3063 | ha = vha->hw; |
| 3064 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3065 | pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3066 | prm->pkt = pkt; |
| 3067 | memset(pkt, 0, sizeof(*pkt)); |
| 3068 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3069 | ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3070 | "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] | 3071 | cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3072 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 3073 | |
| 3074 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 3075 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 3076 | bundling = 0; |
| 3077 | |
| 3078 | /* Compute dif len and adjust data len to incude protection */ |
| 3079 | data_bytes = cmd->bufflen; |
| 3080 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 3081 | |
| 3082 | switch (se_cmd->prot_op) { |
| 3083 | case TARGET_PROT_DIN_INSERT: |
| 3084 | case TARGET_PROT_DOUT_STRIP: |
| 3085 | transfer_length = data_bytes; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3086 | if (cmd->prot_sg_cnt) |
| 3087 | data_bytes += dif_bytes; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3088 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3089 | case TARGET_PROT_DIN_STRIP: |
| 3090 | case TARGET_PROT_DOUT_INSERT: |
| 3091 | case TARGET_PROT_DIN_PASS: |
| 3092 | case TARGET_PROT_DOUT_PASS: |
| 3093 | transfer_length = data_bytes + dif_bytes; |
| 3094 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3095 | default: |
| 3096 | BUG(); |
| 3097 | break; |
| 3098 | } |
| 3099 | |
| 3100 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 3101 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 3102 | /* HBA error checking enabled */ |
| 3103 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 3104 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 3105 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 3106 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 3107 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 3108 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 3109 | } |
| 3110 | |
| 3111 | switch (se_cmd->prot_op) { |
| 3112 | case TARGET_PROT_DIN_INSERT: |
| 3113 | case TARGET_PROT_DOUT_INSERT: |
| 3114 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 3115 | break; |
| 3116 | case TARGET_PROT_DIN_STRIP: |
| 3117 | case TARGET_PROT_DOUT_STRIP: |
| 3118 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 3119 | break; |
| 3120 | case TARGET_PROT_DIN_PASS: |
| 3121 | case TARGET_PROT_DOUT_PASS: |
| 3122 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 3123 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 3124 | break; |
| 3125 | default:/* Normal Request */ |
| 3126 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 3127 | break; |
| 3128 | } |
| 3129 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3130 | /* ---- PKT ---- */ |
| 3131 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 3132 | pkt->entry_type = CTIO_CRC2; |
| 3133 | pkt->entry_count = 1; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3134 | pkt->vp_index = cmd->vp_idx; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3135 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3136 | h = qlt_make_handle(qpair); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3137 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 3138 | /* |
| 3139 | * CTIO type 7 from the firmware doesn't provide a way to |
| 3140 | * know the initiator's LOOP ID, hence we can't find |
| 3141 | * the session and, so, the command. |
| 3142 | */ |
| 3143 | return -EAGAIN; |
| 3144 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3145 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3146 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3147 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 3148 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3149 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3150 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3151 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3152 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3153 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3154 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3155 | |
| 3156 | /* silence compile warning */ |
| 3157 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3158 | pkt->ox_id = cpu_to_le16(t16); |
| 3159 | |
| 3160 | t16 = (atio->u.isp24.attr << 9); |
| 3161 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3162 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 3163 | |
| 3164 | /* Set transfer direction */ |
| 3165 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3166 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3167 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3168 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3169 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3170 | pkt->dseg_count = prm->tot_dsds; |
| 3171 | /* Fibre channel byte count */ |
| 3172 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 3173 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3174 | /* ----- CRC context -------- */ |
| 3175 | |
| 3176 | /* Allocate CRC context from global pool */ |
| 3177 | crc_ctx_pkt = cmd->ctx = |
Souptick Joarder | 501017f | 2018-02-15 01:40:38 +0530 | [diff] [blame] | 3178 | dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3179 | |
| 3180 | if (!crc_ctx_pkt) |
| 3181 | goto crc_queuing_error; |
| 3182 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3183 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 3184 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 3185 | |
| 3186 | /* Set handle */ |
| 3187 | crc_ctx_pkt->handle = pkt->handle; |
| 3188 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3189 | qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3190 | |
| 3191 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 3192 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 3193 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 3194 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3195 | if (!bundling) { |
| 3196 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 3197 | } else { |
| 3198 | /* |
| 3199 | * Configure Bundling if we need to fetch interlaving |
| 3200 | * protection PCI accesses |
| 3201 | */ |
| 3202 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 3203 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 3204 | crc_ctx_pkt->u.bundling.dseg_count = |
| 3205 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
| 3206 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 3207 | } |
| 3208 | |
| 3209 | /* Finish the common fields of CRC pkt */ |
| 3210 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 3211 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 3212 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3213 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3214 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3215 | memset((uint8_t *)&tc, 0 , sizeof(tc)); |
| 3216 | tc.vha = vha; |
| 3217 | tc.blk_sz = cmd->blk_sz; |
| 3218 | tc.bufflen = cmd->bufflen; |
| 3219 | tc.sg = cmd->sg; |
| 3220 | tc.prot_sg = cmd->prot_sg; |
| 3221 | tc.ctx = crc_ctx_pkt; |
| 3222 | tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3223 | |
| 3224 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3225 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3226 | |
| 3227 | if (!bundling && prm->prot_seg_cnt) { |
| 3228 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3229 | prm->tot_dsds, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3230 | goto crc_queuing_error; |
| 3231 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3232 | (prm->tot_dsds - prm->prot_seg_cnt), &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3233 | goto crc_queuing_error; |
| 3234 | |
| 3235 | if (bundling && prm->prot_seg_cnt) { |
| 3236 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3237 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3238 | |
| 3239 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 3240 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
Giridhar Malavali | 50b8127 | 2018-12-21 09:33:45 -0800 | [diff] [blame] | 3241 | prm->prot_seg_cnt, cmd)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3242 | goto crc_queuing_error; |
| 3243 | } |
| 3244 | return QLA_SUCCESS; |
| 3245 | |
| 3246 | crc_queuing_error: |
| 3247 | /* Cleanup will be performed by the caller */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3248 | qpair->req->outstanding_cmds[h] = NULL; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3249 | |
| 3250 | return QLA_FUNCTION_FAILED; |
| 3251 | } |
| 3252 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3253 | /* |
| 3254 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 3255 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 3256 | */ |
| 3257 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 3258 | uint8_t scsi_status) |
| 3259 | { |
| 3260 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3261 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3262 | struct ctio7_to_24xx *pkt; |
| 3263 | struct qla_tgt_prm prm; |
| 3264 | uint32_t full_req_cnt = 0; |
| 3265 | unsigned long flags = 0; |
| 3266 | int res; |
| 3267 | |
Quinn Tran | 51fd6e6 | 2019-01-24 23:23:43 -0800 | [diff] [blame] | 3268 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
| 3269 | (cmd->sess && cmd->sess->deleted)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3270 | cmd->state = QLA_TGT_STATE_PROCESSED; |
Quinn Tran | 51fd6e6 | 2019-01-24 23:23:43 -0800 | [diff] [blame] | 3271 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3272 | return 0; |
| 3273 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3274 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3275 | ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3276 | "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] | 3277 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 3278 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3279 | &cmd->se_cmd, qpair->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3280 | |
| 3281 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 3282 | &full_req_cnt); |
| 3283 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3284 | return res; |
| 3285 | } |
| 3286 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3287 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3288 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3289 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3290 | qpair->tgt_counters.core_qla_snd_status++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3291 | else |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3292 | qpair->tgt_counters.core_qla_que_buf++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3293 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3294 | if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3295 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3296 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3297 | * previous life, just abort the processing. |
| 3298 | */ |
| 3299 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3300 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3301 | ql_dbg_qp(ql_dbg_async, qpair, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3302 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3303 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3304 | cmd->reset_count, qpair->chip_reset); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3305 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3306 | return 0; |
| 3307 | } |
| 3308 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3309 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3310 | res = qlt_check_reserve_free_req(qpair, full_req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3311 | if (unlikely(res)) |
| 3312 | goto out_unmap_unlock; |
| 3313 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3314 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3315 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3316 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3317 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3318 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3319 | qpair->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3320 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3321 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3322 | |
| 3323 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 3324 | |
| 3325 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 3326 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3327 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3328 | CTIO7_FLAGS_STATUS_MODE_0); |
| 3329 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3330 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3331 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3332 | |
| 3333 | if (prm.add_status_pkt == 0) { |
| 3334 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 3335 | pkt->u.status0.scsi_status = |
| 3336 | cpu_to_le16(prm.rq_result); |
| 3337 | pkt->u.status0.residual = |
| 3338 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3339 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3340 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3341 | if (qlt_need_explicit_conf(cmd, 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3342 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3343 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3344 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 3345 | CTIO7_FLAGS_CONFORM_REQ); |
| 3346 | } |
| 3347 | } |
| 3348 | |
| 3349 | } else { |
| 3350 | /* |
| 3351 | * We have already made sure that there is sufficient |
| 3352 | * amount of request entries to not drop HW lock in |
| 3353 | * req_pkt(). |
| 3354 | */ |
| 3355 | struct ctio7_to_24xx *ctio = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3356 | (struct ctio7_to_24xx *)qlt_get_req_pkt( |
| 3357 | qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3358 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3359 | ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e, |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3360 | "Building additional status packet 0x%p.\n", |
| 3361 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3362 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3363 | /* |
| 3364 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 3365 | * ctio7_to_24xx |
| 3366 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3367 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3368 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3369 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3370 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3371 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3372 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3373 | CTIO7_FLAGS_DATA_IN); |
| 3374 | |
| 3375 | /* Real finish is ctio_m1's finish */ |
| 3376 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3377 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3378 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3379 | |
| 3380 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3381 | * all neccessary fields that's part of CTIO7. |
| 3382 | * There should be no residual of CTIO-CRC2 data. |
| 3383 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3384 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3385 | &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3386 | } |
| 3387 | } else |
| 3388 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3389 | |
| 3390 | |
| 3391 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d594db0 | 2018-09-11 10:18:23 -0700 | [diff] [blame] | 3392 | spin_lock(&cmd->cmd_lock); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3393 | cmd->cmd_sent_to_fw = 1; |
Quinn Tran | d594db0 | 2018-09-11 10:18:23 -0700 | [diff] [blame] | 3394 | spin_unlock(&cmd->cmd_lock); |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3395 | cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3396 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3397 | /* Memory Barrier */ |
| 3398 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3399 | if (qpair->reqq_start_iocbs) |
| 3400 | qpair->reqq_start_iocbs(qpair); |
| 3401 | else |
| 3402 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3403 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3404 | |
| 3405 | return 0; |
| 3406 | |
| 3407 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3408 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3409 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3410 | |
| 3411 | return res; |
| 3412 | } |
| 3413 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3414 | |
| 3415 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3416 | { |
| 3417 | struct ctio7_to_24xx *pkt; |
| 3418 | struct scsi_qla_host *vha = cmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3419 | struct qla_tgt *tgt = cmd->tgt; |
| 3420 | struct qla_tgt_prm prm; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3421 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3422 | int res = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3423 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3424 | |
| 3425 | memset(&prm, 0, sizeof(prm)); |
| 3426 | prm.cmd = cmd; |
| 3427 | prm.tgt = tgt; |
| 3428 | prm.sg = NULL; |
| 3429 | prm.req_cnt = 1; |
| 3430 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3431 | /* Calculate number of entries and segments required */ |
| 3432 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3433 | return -EAGAIN; |
| 3434 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3435 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3436 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3437 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3438 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3439 | * previous life, just abort the processing. |
| 3440 | */ |
| 3441 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
| 3442 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3443 | ql_dbg_qp(ql_dbg_async, qpair, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3444 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3445 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3446 | cmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3447 | return 0; |
| 3448 | } |
| 3449 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3450 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3451 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3452 | res = qlt_check_reserve_free_req(qpair, prm.req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3453 | if (res != 0) |
| 3454 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3455 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3456 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3457 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3458 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3459 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3460 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3461 | qpair->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3462 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3463 | } |
| 3464 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3465 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3466 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3467 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3468 | |
| 3469 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3470 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3471 | |
| 3472 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d594db0 | 2018-09-11 10:18:23 -0700 | [diff] [blame] | 3473 | spin_lock(&cmd->cmd_lock); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3474 | cmd->cmd_sent_to_fw = 1; |
Quinn Tran | d594db0 | 2018-09-11 10:18:23 -0700 | [diff] [blame] | 3475 | spin_unlock(&cmd->cmd_lock); |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 3476 | cmd->ctio_flags = le16_to_cpu(pkt->u.status0.flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3477 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3478 | /* Memory Barrier */ |
| 3479 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3480 | if (qpair->reqq_start_iocbs) |
| 3481 | qpair->reqq_start_iocbs(qpair); |
| 3482 | else |
| 3483 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3484 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3485 | |
| 3486 | return res; |
| 3487 | |
| 3488 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3489 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3490 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3491 | |
| 3492 | return res; |
| 3493 | } |
| 3494 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3495 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3496 | |
| 3497 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3498 | * it is assumed either hardware_lock or qpair lock is held. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3499 | */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3500 | static void |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3501 | 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] | 3502 | struct ctio_crc_from_fw *sts) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3503 | { |
| 3504 | uint8_t *ap = &sts->actual_dif[0]; |
| 3505 | uint8_t *ep = &sts->expected_dif[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3506 | uint64_t lba = cmd->se_cmd.t_task_lba; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3507 | uint8_t scsi_status, sense_key, asc, ascq; |
| 3508 | unsigned long flags; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3509 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3510 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3511 | cmd->trc_flags |= TRC_DIF_ERR; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3512 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3513 | cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3514 | cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3515 | cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3516 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3517 | cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3518 | cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3519 | cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3520 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3521 | ql_dbg(ql_dbg_tgt_dif, vha, 0xf075, |
| 3522 | "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3523 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3524 | scsi_status = sense_key = asc = ascq = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3525 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3526 | /* check appl tag */ |
| 3527 | if (cmd->e_app_tag != cmd->a_app_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3528 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d, |
| 3529 | "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]", |
| 3530 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3531 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3532 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3533 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3534 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3535 | cmd->dif_err_code = DIF_ERR_APP; |
| 3536 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3537 | sense_key = ABORTED_COMMAND; |
| 3538 | asc = 0x10; |
| 3539 | ascq = 0x2; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | /* check ref tag */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3543 | if (cmd->e_ref_tag != cmd->a_ref_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3544 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e, |
| 3545 | "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] ", |
| 3546 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3547 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3548 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3549 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3550 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3551 | cmd->dif_err_code = DIF_ERR_REF; |
| 3552 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3553 | sense_key = ABORTED_COMMAND; |
| 3554 | asc = 0x10; |
| 3555 | ascq = 0x3; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3556 | goto out; |
| 3557 | } |
| 3558 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3559 | /* check guard */ |
| 3560 | if (cmd->e_guard != cmd->a_guard) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3561 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe012, |
| 3562 | "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]", |
| 3563 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3564 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3565 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3566 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
| 3567 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3568 | cmd->dif_err_code = DIF_ERR_GRD; |
| 3569 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3570 | sense_key = ABORTED_COMMAND; |
| 3571 | asc = 0x10; |
| 3572 | ascq = 0x1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3573 | } |
| 3574 | out: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3575 | switch (cmd->state) { |
| 3576 | case QLA_TGT_STATE_NEED_DATA: |
| 3577 | /* handle_data will load DIF error code */ |
| 3578 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3579 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
| 3580 | break; |
| 3581 | default: |
| 3582 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3583 | if (cmd->aborted) { |
| 3584 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3585 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3586 | break; |
| 3587 | } |
| 3588 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3589 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3590 | qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc, |
| 3591 | ascq); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3592 | /* assume scsi status gets out on the wire. |
| 3593 | * Will not wait for completion. |
| 3594 | */ |
| 3595 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3596 | break; |
| 3597 | } |
| 3598 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3599 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3600 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3601 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3602 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3603 | struct imm_ntfy_from_isp *ntfy) |
| 3604 | { |
| 3605 | struct nack_to_isp *nack; |
| 3606 | struct qla_hw_data *ha = vha->hw; |
| 3607 | request_t *pkt; |
| 3608 | int ret = 0; |
| 3609 | |
| 3610 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3611 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3612 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3613 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3614 | if (pkt == NULL) { |
| 3615 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3616 | "qla_target(%d): %s failed: unable to allocate " |
| 3617 | "request packet\n", vha->vp_idx, __func__); |
| 3618 | return -ENOMEM; |
| 3619 | } |
| 3620 | |
| 3621 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3622 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3623 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3624 | |
| 3625 | nack = (struct nack_to_isp *)pkt; |
| 3626 | nack->ox_id = ntfy->ox_id; |
| 3627 | |
| 3628 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3629 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3630 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3631 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3632 | } |
| 3633 | |
| 3634 | /* terminate */ |
| 3635 | nack->u.isp24.flags |= |
| 3636 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3637 | |
| 3638 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3639 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3640 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3641 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3642 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3643 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3644 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3645 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3646 | |
| 3647 | qla2x00_start_iocbs(vha, vha->req); |
| 3648 | return ret; |
| 3649 | } |
| 3650 | |
| 3651 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3652 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3653 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3654 | int rc; |
| 3655 | |
Bart Van Assche | e65449a | 2019-04-17 14:44:26 -0700 | [diff] [blame^] | 3656 | WARN_ON_ONCE(!ha_locked); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3657 | rc = __qlt_send_term_imm_notif(vha, imm); |
Bart Van Assche | e65449a | 2019-04-17 14:44:26 -0700 | [diff] [blame^] | 3658 | pr_debug("rc = %d\n", rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3659 | } |
| 3660 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3661 | /* |
| 3662 | * If hardware_lock held on entry, might drop it, then reaquire |
| 3663 | * This function sends the appropriate CTIO to ISP 2xxx or 24xx |
| 3664 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3665 | static int __qlt_send_term_exchange(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3666 | struct qla_tgt_cmd *cmd, |
| 3667 | struct atio_from_isp *atio) |
| 3668 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3669 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3670 | struct ctio7_to_24xx *ctio24; |
| 3671 | struct qla_hw_data *ha = vha->hw; |
| 3672 | request_t *pkt; |
| 3673 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3674 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3675 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3676 | 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] | 3677 | |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 3678 | if (cmd) |
| 3679 | vha = cmd->vha; |
| 3680 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3681 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3682 | if (pkt == NULL) { |
| 3683 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3684 | "qla_target(%d): %s failed: unable to allocate " |
| 3685 | "request packet\n", vha->vp_idx, __func__); |
| 3686 | return -ENOMEM; |
| 3687 | } |
| 3688 | |
| 3689 | if (cmd != NULL) { |
| 3690 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3691 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3692 | "qla_target(%d): Terminating cmd %p with " |
| 3693 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3694 | cmd->state); |
| 3695 | } else |
| 3696 | ret = 1; |
| 3697 | } |
| 3698 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3699 | qpair->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3700 | pkt->entry_count = 1; |
| 3701 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3702 | |
| 3703 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3704 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3705 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3706 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3707 | ctio24->vp_index = vha->vp_idx; |
| 3708 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3709 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3710 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3711 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3712 | temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 | |
| 3713 | CTIO7_FLAGS_TERMINATE; |
| 3714 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3715 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3716 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3717 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3718 | /* Memory Barrier */ |
| 3719 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3720 | if (qpair->reqq_start_iocbs) |
| 3721 | qpair->reqq_start_iocbs(qpair); |
| 3722 | else |
| 3723 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3724 | return ret; |
| 3725 | } |
| 3726 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3727 | static void qlt_send_term_exchange(struct qla_qpair *qpair, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3728 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3729 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3730 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3731 | struct scsi_qla_host *vha; |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3732 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3733 | int rc; |
| 3734 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3735 | /* why use different vha? NPIV */ |
| 3736 | if (cmd) |
| 3737 | vha = cmd->vha; |
| 3738 | else |
| 3739 | vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3740 | |
| 3741 | if (ha_locked) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3742 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3743 | if (rc == -ENOMEM) |
| 3744 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3745 | goto done; |
| 3746 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3747 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 3748 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3749 | if (rc == -ENOMEM) |
| 3750 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3751 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3752 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3753 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3754 | if (cmd->sg_mapped) |
| 3755 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3756 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3757 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3758 | |
| 3759 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3760 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3761 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3762 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3763 | } |
| 3764 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3765 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3766 | { |
| 3767 | struct list_head free_list; |
| 3768 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3769 | |
| 3770 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3771 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3772 | |
| 3773 | cmd = tcmd = NULL; |
| 3774 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3775 | INIT_LIST_HEAD(&free_list); |
| 3776 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3777 | |
| 3778 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3779 | list_del(&cmd->cmd_list); |
| 3780 | /* This cmd was never sent to TCM. There is no need |
| 3781 | * to schedule free or call free_cmd |
| 3782 | */ |
| 3783 | qlt_free_cmd(cmd); |
| 3784 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3785 | } |
| 3786 | } |
| 3787 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3788 | } |
| 3789 | |
| 3790 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3791 | { |
| 3792 | uint32_t total_leaked; |
| 3793 | |
| 3794 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3795 | |
| 3796 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3797 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3798 | |
| 3799 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3800 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3801 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3802 | |
| 3803 | if (IS_P3P_TYPE(vha->hw)) |
| 3804 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3805 | else |
| 3806 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3807 | qla2xxx_wake_dpc(vha); |
| 3808 | } |
| 3809 | |
| 3810 | } |
| 3811 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3812 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3813 | { |
| 3814 | struct qla_tgt *tgt = cmd->tgt; |
| 3815 | struct scsi_qla_host *vha = tgt->vha; |
| 3816 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3817 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3818 | |
| 3819 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3820 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3821 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3822 | se_cmd->tag); |
| 3823 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3824 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3825 | if (cmd->aborted) { |
| 3826 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3827 | /* |
| 3828 | * It's normal to see 2 calls in this path: |
| 3829 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3830 | * 2) TCM TMR - drain_state_list |
| 3831 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3832 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, |
| 3833 | "multiple abort. %p transport_state %x, t_state %x, " |
| 3834 | "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, |
| 3835 | cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3836 | return EIO; |
| 3837 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3838 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3839 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3840 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3841 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3842 | qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3843 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3844 | } |
| 3845 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3846 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3847 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3848 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3849 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3850 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3851 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3852 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3853 | __func__, &cmd->se_cmd, |
| 3854 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3855 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3856 | BUG_ON(cmd->cmd_in_wq); |
| 3857 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3858 | if (cmd->sg_mapped) |
| 3859 | qlt_unmap_sg(cmd->vha, cmd); |
| 3860 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3861 | if (!cmd->q_full) |
| 3862 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3863 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3864 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3865 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3866 | if (unlikely(cmd->free_sg)) |
| 3867 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3868 | |
| 3869 | if (!sess || !sess->se_sess) { |
| 3870 | WARN_ON(1); |
| 3871 | return; |
| 3872 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3873 | cmd->jiffies_at_free = get_jiffies_64(); |
Matthew Wilcox | 83c2b54 | 2018-06-12 12:05:43 -0700 | [diff] [blame] | 3874 | target_free_tag(sess->se_sess, &cmd->se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3875 | } |
| 3876 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3877 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3878 | /* |
| 3879 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3880 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3881 | static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3882 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3883 | { |
| 3884 | int term = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3885 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3886 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3887 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3888 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3889 | "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " |
| 3890 | "se_cmd=%p tag[%x] op %#x/%s", |
| 3891 | cmd->lba, cmd->lba, |
| 3892 | cmd->num_blks, &cmd->se_cmd, |
| 3893 | cmd->atio.u.isp24.exchange_addr, |
| 3894 | cmd->se_cmd.prot_op, |
| 3895 | prot_op_str(cmd->se_cmd.prot_op)); |
| 3896 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3897 | if (ctio != NULL) { |
| 3898 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 3899 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3900 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3901 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3902 | } else |
| 3903 | term = 1; |
| 3904 | |
| 3905 | if (term) |
himanshu.madhani@cavium.com | 3efc31f | 2018-01-15 20:46:47 -0800 | [diff] [blame] | 3906 | qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3907 | |
| 3908 | return term; |
| 3909 | } |
| 3910 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3911 | |
| 3912 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3913 | static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3914 | struct rsp_que *rsp, uint32_t handle, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3915 | { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3916 | void *cmd = NULL; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3917 | struct req_que *req; |
| 3918 | int qid = GET_QID(handle); |
| 3919 | uint32_t h = handle & ~QLA_TGT_HANDLE_MASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3920 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3921 | if (unlikely(h == QLA_TGT_SKIP_HANDLE)) |
| 3922 | return NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3923 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3924 | if (qid == rsp->req->id) { |
| 3925 | req = rsp->req; |
| 3926 | } else if (vha->hw->req_q_map[qid]) { |
| 3927 | ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a, |
| 3928 | "qla_target(%d): CTIO completion with different QID %d handle %x\n", |
| 3929 | vha->vp_idx, rsp->id, handle); |
| 3930 | req = vha->hw->req_q_map[qid]; |
| 3931 | } else { |
| 3932 | return NULL; |
| 3933 | } |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3934 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3935 | h &= QLA_CMD_HANDLE_MASK; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3936 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3937 | if (h != QLA_TGT_NULL_HANDLE) { |
Dan Carpenter | fb2028a | 2017-07-10 11:47:40 +0300 | [diff] [blame] | 3938 | if (unlikely(h >= req->num_outstanding_cmds)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3939 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3940 | "qla_target(%d): Wrong handle %x received\n", |
| 3941 | vha->vp_idx, handle); |
| 3942 | return NULL; |
| 3943 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3944 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 3945 | cmd = (void *) req->outstanding_cmds[h]; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3946 | if (unlikely(cmd == NULL)) { |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3947 | ql_dbg(ql_dbg_async, vha, 0xe053, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3948 | "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n", |
| 3949 | vha->vp_idx, handle, req->id, rsp->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3950 | return NULL; |
| 3951 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3952 | req->outstanding_cmds[h] = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3953 | } else if (ctio != NULL) { |
| 3954 | /* We can't get loop ID from CTIO7 */ |
| 3955 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3956 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3957 | "support NULL handles\n", vha->vp_idx); |
| 3958 | return NULL; |
| 3959 | } |
| 3960 | |
| 3961 | return cmd; |
| 3962 | } |
| 3963 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3964 | /* hardware_lock should be held by caller. */ |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3965 | void |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3966 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
| 3967 | { |
| 3968 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3969 | |
| 3970 | if (cmd->sg_mapped) |
| 3971 | qlt_unmap_sg(vha, cmd); |
| 3972 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3973 | /* TODO: fix debug message type and ids. */ |
| 3974 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
| 3975 | ql_dbg(ql_dbg_io, vha, 0xff00, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3976 | "HOST-ABORT: state=PROCESSED.\n"); |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3977 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3978 | cmd->write_data_transferred = 0; |
| 3979 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3980 | |
| 3981 | ql_dbg(ql_dbg_io, vha, 0xff01, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3982 | "HOST-ABORT: state=DATA_IN.\n"); |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3983 | |
| 3984 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3985 | return; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3986 | } else { |
| 3987 | ql_dbg(ql_dbg_io, vha, 0xff03, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3988 | "HOST-ABORT: state=BAD(%d).\n", |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3989 | cmd->state); |
| 3990 | dump_stack(); |
| 3991 | } |
| 3992 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3993 | cmd->trc_flags |= TRC_FLUSH; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3994 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3995 | } |
| 3996 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3997 | /* |
| 3998 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3999 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4000 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, |
| 4001 | struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4002 | { |
| 4003 | struct qla_hw_data *ha = vha->hw; |
| 4004 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4005 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4006 | struct qla_qpair *qpair = rsp->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4007 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4008 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 4009 | /* That could happen only in case of an error/reset/abort */ |
| 4010 | if (status != CTIO_SUCCESS) { |
| 4011 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 4012 | "Intermediate CTIO received" |
| 4013 | " (status %x)\n", status); |
| 4014 | } |
| 4015 | return; |
| 4016 | } |
| 4017 | |
Bart Van Assche | 81bcf1c | 2019-04-11 14:53:24 -0700 | [diff] [blame] | 4018 | cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 4019 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4020 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 4021 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4022 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 4023 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4024 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 4025 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4026 | |
| 4027 | if (unlikely(status != CTIO_SUCCESS)) { |
| 4028 | switch (status & 0xFFFF) { |
Quinn Tran | 079a3a3 | 2018-09-04 14:19:11 -0700 | [diff] [blame] | 4029 | case CTIO_INVALID_RX_ID: |
| 4030 | if (printk_ratelimit()) |
| 4031 | dev_info(&vha->hw->pdev->dev, |
| 4032 | "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n", |
| 4033 | vha->vp_idx, cmd->atio.u.isp24.attr, |
| 4034 | ((cmd->ctio_flags >> 9) & 0xf), |
| 4035 | cmd->ctio_flags); |
| 4036 | |
| 4037 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4038 | case CTIO_LIP_RESET: |
| 4039 | case CTIO_TARGET_RESET: |
| 4040 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4041 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4042 | case CTIO_TIMEOUT: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4043 | /* They are OK */ |
| 4044 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 4045 | "qla_target(%d): CTIO with " |
| 4046 | "status %#x received, state %x, se_cmd %p, " |
| 4047 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 4048 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 4049 | status, cmd->state, se_cmd); |
| 4050 | break; |
| 4051 | |
| 4052 | case CTIO_PORT_LOGGED_OUT: |
| 4053 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 4054 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 4055 | int logged_out = |
| 4056 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 4057 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4058 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 4059 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4060 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 4061 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4062 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4063 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 4064 | if (logged_out && cmd->sess) { |
| 4065 | /* |
| 4066 | * Session is already logged out, but we need |
| 4067 | * to notify initiator, who's not aware of this |
| 4068 | */ |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 4069 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4070 | ql_dbg(ql_dbg_disc, vha, 0x20f8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4071 | "%s %d %8phC post del sess\n", |
| 4072 | __func__, __LINE__, cmd->sess->port_name); |
| 4073 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4074 | qlt_schedule_sess_for_deletion(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 4075 | } |
| 4076 | break; |
| 4077 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4078 | case CTIO_DIF_ERROR: { |
| 4079 | struct ctio_crc_from_fw *crc = |
| 4080 | (struct ctio_crc_from_fw *)ctio; |
| 4081 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 4082 | "qla_target(%d): CTIO with DIF_ERROR status %x " |
| 4083 | "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " |
| 4084 | "expect_dif[0x%llx]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4085 | vha->vp_idx, status, cmd->state, se_cmd, |
| 4086 | *((u64 *)&crc->actual_dif[0]), |
| 4087 | *((u64 *)&crc->expected_dif[0])); |
| 4088 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 4089 | qlt_handle_dif_error(qpair, cmd, ctio); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 4090 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4091 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4092 | default: |
| 4093 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 4094 | "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] | 4095 | vha->vp_idx, status, cmd->state, se_cmd); |
| 4096 | break; |
| 4097 | } |
| 4098 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4099 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4100 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4101 | * cmd is already aborted/terminated, we don't |
| 4102 | * need to terminate again. The exchange is already |
| 4103 | * cleaned up/freed at FW level. Just cleanup at driver |
| 4104 | * level. |
| 4105 | */ |
| 4106 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4107 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4108 | cmd->trc_flags |= TRC_CTIO_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4109 | if (qlt_term_ctio_exchange(qpair, ctio, cmd, status)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4110 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4111 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4112 | } |
| 4113 | |
| 4114 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4115 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4116 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4117 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 4118 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4119 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4120 | cmd->write_data_transferred = 1; |
| 4121 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4122 | ha->tgt.tgt_ops->handle_data(cmd); |
| 4123 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4124 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4125 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4126 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4127 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4128 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4129 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4130 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 4131 | "qla_target(%d): A command in state (%d) should " |
| 4132 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 4133 | } |
| 4134 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 4135 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4136 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4137 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 4138 | dump_stack(); |
| 4139 | } |
| 4140 | |
| 4141 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 4142 | } |
| 4143 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4144 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 4145 | uint8_t task_codes) |
| 4146 | { |
| 4147 | int fcp_task_attr; |
| 4148 | |
| 4149 | switch (task_codes) { |
| 4150 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4151 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4152 | break; |
| 4153 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4154 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4155 | break; |
| 4156 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4157 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4158 | break; |
| 4159 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4160 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4161 | break; |
| 4162 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4163 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4164 | break; |
| 4165 | default: |
| 4166 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 4167 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 4168 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4169 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4170 | break; |
| 4171 | } |
| 4172 | |
| 4173 | return fcp_task_attr; |
| 4174 | } |
| 4175 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4176 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4177 | uint8_t *); |
| 4178 | /* |
| 4179 | * Process context for I/O path into tcm_qla2xxx code |
| 4180 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4181 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4182 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4183 | scsi_qla_host_t *vha = cmd->vha; |
| 4184 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4185 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4186 | struct atio_from_isp *atio = &cmd->atio; |
| 4187 | unsigned char *cdb; |
| 4188 | unsigned long flags; |
| 4189 | uint32_t data_length; |
| 4190 | int ret, fcp_task_attr, data_dir, bidi = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4191 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4192 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4193 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4194 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4195 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4196 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4197 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 4198 | "cmd with tag %u is aborted\n", |
| 4199 | cmd->atio.u.isp24.exchange_addr); |
| 4200 | goto out_term; |
| 4201 | } |
| 4202 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4203 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4204 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4205 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4206 | |
| 4207 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 4208 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 4209 | bidi = 1; |
| 4210 | data_dir = DMA_TO_DEVICE; |
| 4211 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 4212 | data_dir = DMA_FROM_DEVICE; |
| 4213 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 4214 | data_dir = DMA_TO_DEVICE; |
| 4215 | else |
| 4216 | data_dir = DMA_NONE; |
| 4217 | |
| 4218 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 4219 | atio->u.isp24.fcp_cmnd.task_attr); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 4220 | data_length = get_datalen_for_atio(atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4221 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4222 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 4223 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4224 | if (ret != 0) |
| 4225 | goto out_term; |
| 4226 | /* |
Bart Van Assche | 67eb4a60 | 2019-04-17 14:44:10 -0700 | [diff] [blame] | 4227 | * Drop extra session reference from qlt_handle_cmd_for_atio(). |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4228 | */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4229 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4230 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4231 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4232 | return; |
| 4233 | |
| 4234 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4235 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4236 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 4237 | * cmd has not sent to target yet, so pass NULL as the second |
| 4238 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4239 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4240 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4241 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4242 | qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4243 | |
| 4244 | qlt_decr_num_pend_cmds(vha); |
Matthew Wilcox | 83c2b54 | 2018-06-12 12:05:43 -0700 | [diff] [blame] | 4245 | target_free_tag(sess->se_sess, &cmd->se_cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4246 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4247 | |
| 4248 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4249 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4250 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4251 | } |
| 4252 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4253 | static void qlt_do_work(struct work_struct *work) |
| 4254 | { |
| 4255 | 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] | 4256 | scsi_qla_host_t *vha = cmd->vha; |
| 4257 | unsigned long flags; |
| 4258 | |
| 4259 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4260 | list_del(&cmd->cmd_list); |
| 4261 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4262 | |
| 4263 | __qlt_do_work(cmd); |
| 4264 | } |
| 4265 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 4266 | void qlt_clr_qp_table(struct scsi_qla_host *vha) |
| 4267 | { |
| 4268 | unsigned long flags; |
| 4269 | struct qla_hw_data *ha = vha->hw; |
| 4270 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4271 | void *node; |
| 4272 | u64 key = 0; |
| 4273 | |
| 4274 | ql_log(ql_log_info, vha, 0x706c, |
| 4275 | "User update Number of Active Qpairs %d\n", |
| 4276 | ha->tgt.num_act_qpairs); |
| 4277 | |
| 4278 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 4279 | |
| 4280 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 4281 | btree_remove64(&tgt->lun_qpair_map, key); |
| 4282 | |
| 4283 | ha->base_qpair->lun_cnt = 0; |
| 4284 | for (key = 0; key < ha->max_qpairs; key++) |
| 4285 | if (ha->queue_pair_map[key]) |
| 4286 | ha->queue_pair_map[key]->lun_cnt = 0; |
| 4287 | |
| 4288 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 4289 | } |
| 4290 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4291 | static void qlt_assign_qpair(struct scsi_qla_host *vha, |
| 4292 | struct qla_tgt_cmd *cmd) |
| 4293 | { |
| 4294 | struct qla_qpair *qpair, *qp; |
| 4295 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4296 | struct qla_qpair_hint *h; |
| 4297 | |
| 4298 | if (vha->flags.qpairs_available) { |
| 4299 | h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun); |
| 4300 | if (unlikely(!h)) { |
| 4301 | /* spread lun to qpair ratio evently */ |
| 4302 | int lcnt = 0, rc; |
| 4303 | struct scsi_qla_host *base_vha = |
| 4304 | pci_get_drvdata(vha->hw->pdev); |
| 4305 | |
| 4306 | qpair = vha->hw->base_qpair; |
| 4307 | if (qpair->lun_cnt == 0) { |
| 4308 | qpair->lun_cnt++; |
| 4309 | h = qla_qpair_to_hint(tgt, qpair); |
| 4310 | BUG_ON(!h); |
| 4311 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4312 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4313 | if (rc) { |
| 4314 | qpair->lun_cnt--; |
| 4315 | ql_log(ql_log_info, vha, 0xd037, |
| 4316 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4317 | cmd->unpacked_lun); |
| 4318 | } |
| 4319 | goto out; |
| 4320 | } else { |
| 4321 | lcnt = qpair->lun_cnt; |
| 4322 | } |
| 4323 | |
| 4324 | h = NULL; |
| 4325 | list_for_each_entry(qp, &base_vha->qp_list, |
| 4326 | qp_list_elem) { |
| 4327 | if (qp->lun_cnt == 0) { |
| 4328 | qp->lun_cnt++; |
| 4329 | h = qla_qpair_to_hint(tgt, qp); |
| 4330 | BUG_ON(!h); |
| 4331 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4332 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4333 | if (rc) { |
| 4334 | qp->lun_cnt--; |
| 4335 | ql_log(ql_log_info, vha, 0xd038, |
| 4336 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4337 | cmd->unpacked_lun); |
| 4338 | } |
| 4339 | qpair = qp; |
| 4340 | goto out; |
| 4341 | } else { |
| 4342 | if (qp->lun_cnt < lcnt) { |
| 4343 | lcnt = qp->lun_cnt; |
| 4344 | qpair = qp; |
| 4345 | continue; |
| 4346 | } |
| 4347 | } |
| 4348 | } |
| 4349 | BUG_ON(!qpair); |
| 4350 | qpair->lun_cnt++; |
| 4351 | h = qla_qpair_to_hint(tgt, qpair); |
| 4352 | BUG_ON(!h); |
| 4353 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4354 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4355 | if (rc) { |
| 4356 | qpair->lun_cnt--; |
| 4357 | ql_log(ql_log_info, vha, 0xd039, |
| 4358 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4359 | cmd->unpacked_lun); |
| 4360 | } |
| 4361 | } |
| 4362 | } else { |
| 4363 | h = &tgt->qphints[0]; |
| 4364 | } |
| 4365 | out: |
| 4366 | cmd->qpair = h->qpair; |
| 4367 | cmd->se_cmd.cpuid = h->cpuid; |
| 4368 | } |
| 4369 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4370 | 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] | 4371 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4372 | struct atio_from_isp *atio) |
| 4373 | { |
| 4374 | struct se_session *se_sess = sess->se_sess; |
| 4375 | struct qla_tgt_cmd *cmd; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4376 | int tag, cpu; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4377 | |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4378 | tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4379 | if (tag < 0) |
| 4380 | return NULL; |
| 4381 | |
| 4382 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4383 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 4384 | cmd->cmd_type = TYPE_TGT_CMD; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4385 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4386 | cmd->state = QLA_TGT_STATE_NEW; |
| 4387 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4388 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4389 | cmd->vha = vha; |
| 4390 | cmd->se_cmd.map_tag = tag; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 4391 | cmd->se_cmd.map_cpu = cpu; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4392 | cmd->sess = sess; |
| 4393 | cmd->loop_id = sess->loop_id; |
| 4394 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4395 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4396 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4397 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4398 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4399 | cmd->unpacked_lun = scsilun_to_int( |
| 4400 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 4401 | qlt_assign_qpair(vha, cmd); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4402 | cmd->reset_count = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 4403 | cmd->vp_idx = vha->vp_idx; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4404 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4405 | return cmd; |
| 4406 | } |
| 4407 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4408 | /* ha->hardware_lock supposed to be held on entry */ |
| 4409 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4410 | struct atio_from_isp *atio) |
| 4411 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4412 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4413 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4414 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4415 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4416 | unsigned long flags; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4417 | port_id_t id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4418 | |
| 4419 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4420 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4421 | "New command while device %p is shutting down\n", tgt); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4422 | return -ENODEV; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4423 | } |
| 4424 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4425 | id.b.al_pa = atio->u.isp24.fcp_hdr.s_id[2]; |
| 4426 | id.b.area = atio->u.isp24.fcp_hdr.s_id[1]; |
| 4427 | id.b.domain = atio->u.isp24.fcp_hdr.s_id[0]; |
| 4428 | if (IS_SW_RESV_ADDR(id)) |
| 4429 | return -EBUSY; |
| 4430 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4431 | 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] | 4432 | if (unlikely(!sess)) |
| 4433 | return -EFAULT; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4434 | |
| 4435 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4436 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4437 | if (sess->deleted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4438 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4439 | "New command while old session %p is being deleted\n", |
| 4440 | sess); |
| 4441 | return -EFAULT; |
| 4442 | } |
| 4443 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4444 | /* |
| 4445 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4446 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4447 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4448 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4449 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4450 | __func__, sess->port_name, |
| 4451 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4452 | return -EFAULT; |
| 4453 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4454 | |
| 4455 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4456 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4457 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4458 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4459 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4460 | ha->tgt.tgt_ops->put_sess(sess); |
| 4461 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4462 | return -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4463 | } |
| 4464 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4465 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4466 | cmd->trc_flags |= TRC_NEW_CMD; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4467 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4468 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4469 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4470 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4471 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4472 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4473 | if (vha->flags.qpairs_available) { |
| 4474 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work); |
| 4475 | } else if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4476 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4477 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4478 | &cmd->work); |
| 4479 | else |
| 4480 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4481 | &cmd->work); |
| 4482 | } else { |
| 4483 | queue_work(qla_tgt_wq, &cmd->work); |
| 4484 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4485 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4486 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4490 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4491 | int fn, void *iocb, int flags) |
| 4492 | { |
| 4493 | struct scsi_qla_host *vha = sess->vha; |
| 4494 | struct qla_hw_data *ha = vha->hw; |
| 4495 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4496 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4497 | struct qla_qpair_hint *h = &vha->vha_tgt.qla_tgt->qphints[0]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4498 | |
| 4499 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4500 | if (!mcmd) { |
| 4501 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4502 | "qla_target(%d): Allocation of management " |
| 4503 | "command failed, some commands and their data could " |
| 4504 | "leak\n", vha->vp_idx); |
| 4505 | return -ENOMEM; |
| 4506 | } |
| 4507 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4508 | mcmd->sess = sess; |
| 4509 | |
| 4510 | if (iocb) { |
| 4511 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4512 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4513 | } |
| 4514 | mcmd->tmr_func = fn; |
| 4515 | mcmd->flags = flags; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4516 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4517 | mcmd->qpair = h->qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 4518 | mcmd->vha = vha; |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4519 | mcmd->se_cmd.cpuid = h->cpuid; |
| 4520 | mcmd->unpacked_lun = lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4521 | |
| 4522 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4523 | case QLA_TGT_LUN_RESET: |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4524 | case QLA_TGT_CLEAR_TS: |
| 4525 | case QLA_TGT_ABORT_TS: |
| 4526 | 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] | 4527 | /* fall through */ |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4528 | case QLA_TGT_CLEAR_ACA: |
| 4529 | h = qlt_find_qphint(vha, mcmd->unpacked_lun); |
| 4530 | mcmd->qpair = h->qpair; |
| 4531 | mcmd->se_cmd.cpuid = h->cpuid; |
| 4532 | break; |
| 4533 | |
| 4534 | case QLA_TGT_TARGET_RESET: |
| 4535 | case QLA_TGT_NEXUS_LOSS_SESS: |
| 4536 | case QLA_TGT_NEXUS_LOSS: |
| 4537 | case QLA_TGT_ABORT_ALL: |
| 4538 | default: |
| 4539 | /* no-op */ |
| 4540 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4541 | } |
| 4542 | |
Quinn Tran | 84905df | 2018-05-01 09:01:53 -0700 | [diff] [blame] | 4543 | INIT_WORK(&mcmd->work, qlt_do_tmr_work); |
| 4544 | queue_work_on(mcmd->se_cmd.cpuid, qla_tgt_wq, |
| 4545 | &mcmd->work); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4546 | |
| 4547 | return 0; |
| 4548 | } |
| 4549 | |
| 4550 | /* ha->hardware_lock supposed to be held on entry */ |
| 4551 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4552 | { |
| 4553 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4554 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4555 | struct fc_port *sess; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4556 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4557 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4558 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4559 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4560 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4561 | |
| 4562 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4563 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4564 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4565 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4566 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4567 | unpacked_lun = |
| 4568 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4569 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 4570 | if (sess == NULL || sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4571 | return -EFAULT; |
| 4572 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4573 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4574 | } |
| 4575 | |
| 4576 | /* ha->hardware_lock supposed to be held on entry */ |
| 4577 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4578 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4579 | { |
| 4580 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4581 | struct qla_hw_data *ha = vha->hw; |
| 4582 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4583 | u64 unpacked_lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4584 | int rc; |
| 4585 | |
| 4586 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4587 | if (mcmd == NULL) { |
| 4588 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4589 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4590 | vha->vp_idx, __func__); |
| 4591 | return -ENOMEM; |
| 4592 | } |
| 4593 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4594 | |
| 4595 | mcmd->sess = sess; |
| 4596 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4597 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4598 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4599 | unpacked_lun = |
| 4600 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4601 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4602 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4603 | mcmd->qpair = ha->base_qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4604 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4605 | 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] | 4606 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4607 | if (rc != 0) { |
| 4608 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4609 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4610 | vha->vp_idx, rc); |
| 4611 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4612 | return -EFAULT; |
| 4613 | } |
| 4614 | |
| 4615 | return 0; |
| 4616 | } |
| 4617 | |
| 4618 | /* ha->hardware_lock supposed to be held on entry */ |
| 4619 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4620 | struct imm_ntfy_from_isp *iocb) |
| 4621 | { |
| 4622 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4623 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4624 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4625 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4626 | |
| 4627 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4628 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4629 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4630 | 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] | 4631 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4632 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4633 | if (sess == NULL) { |
| 4634 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4635 | "qla_target(%d): task abort for unexisting " |
| 4636 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4637 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4638 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4639 | } |
| 4640 | |
| 4641 | return __qlt_abort_task(vha, iocb, sess); |
| 4642 | } |
| 4643 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4644 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4645 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4646 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4647 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4648 | "%s: se_sess %p / sess %p from" |
| 4649 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4650 | " LOGO failed: %#x\n", |
| 4651 | __func__, |
| 4652 | fcport->se_sess, |
| 4653 | fcport, |
| 4654 | fcport->port_name, fcport->loop_id, |
| 4655 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4656 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4657 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4658 | |
| 4659 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4660 | } |
| 4661 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4662 | /* |
| 4663 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4664 | * |
| 4665 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4666 | * deletion. Returns existing session with matching wwn if present. |
| 4667 | * Null otherwise. |
| 4668 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4669 | struct fc_port * |
| 4670 | 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] | 4671 | 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] | 4672 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4673 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4674 | uint64_t other_wwn; |
| 4675 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4676 | *conflict_sess = NULL; |
| 4677 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4678 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4679 | |
| 4680 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4681 | |
| 4682 | if (wwn == other_wwn) { |
| 4683 | WARN_ON(sess); |
| 4684 | sess = other_sess; |
| 4685 | continue; |
| 4686 | } |
| 4687 | |
| 4688 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4689 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4690 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4691 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4692 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4693 | other_sess, other_sess->loop_id, other_wwn); |
| 4694 | |
| 4695 | /* |
| 4696 | * logout_on_delete is set by default, but another |
| 4697 | * session that has the same s_id/loop_id combo |
| 4698 | * might have cleared it when requested this session |
| 4699 | * deletion, so don't touch it |
| 4700 | */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4701 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4702 | } else { |
| 4703 | /* |
| 4704 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4705 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4706 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4707 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01b, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4708 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4709 | other_sess, other_sess->loop_id, other_wwn); |
| 4710 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4711 | other_sess->keep_nport_handle = 1; |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 4712 | if (other_sess->disc_state != DSC_DELETED) |
| 4713 | *conflict_sess = other_sess; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4714 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4715 | } |
| 4716 | continue; |
| 4717 | } |
| 4718 | |
| 4719 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4720 | if ((loop_id == other_sess->loop_id) && |
| 4721 | (loop_id != FC_NO_LOOP_ID)) { |
| 4722 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4723 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4724 | other_sess, other_sess->loop_id, other_wwn); |
| 4725 | |
| 4726 | /* Same loop_id but different s_id |
| 4727 | * Ok to kill and logout */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4728 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4729 | } |
| 4730 | } |
| 4731 | |
| 4732 | return sess; |
| 4733 | } |
| 4734 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4735 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4736 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4737 | { |
| 4738 | struct qla_tgt_sess_op *op; |
| 4739 | struct qla_tgt_cmd *cmd; |
| 4740 | uint32_t key; |
| 4741 | int count = 0; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4742 | unsigned long flags; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4743 | |
| 4744 | key = (((u32)s_id->b.domain << 16) | |
| 4745 | ((u32)s_id->b.area << 8) | |
| 4746 | ((u32)s_id->b.al_pa)); |
| 4747 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4748 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4749 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4750 | 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] | 4751 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4752 | if (op_key == key) { |
| 4753 | op->aborted = true; |
| 4754 | count++; |
| 4755 | } |
| 4756 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4757 | |
| 4758 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4759 | 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] | 4760 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4761 | if (op_key == key) { |
| 4762 | op->aborted = true; |
| 4763 | count++; |
| 4764 | } |
| 4765 | } |
| 4766 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4767 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4768 | 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] | 4769 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4770 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4771 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4772 | count++; |
| 4773 | } |
| 4774 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4775 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4776 | |
| 4777 | return count; |
| 4778 | } |
| 4779 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4780 | static int qlt_handle_login(struct scsi_qla_host *vha, |
| 4781 | struct imm_ntfy_from_isp *iocb) |
| 4782 | { |
| 4783 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
| 4784 | uint64_t wwn; |
| 4785 | port_id_t port_id; |
| 4786 | uint16_t loop_id, wd3_lo; |
| 4787 | int res = 0; |
| 4788 | struct qlt_plogi_ack_t *pla; |
| 4789 | unsigned long flags; |
| 4790 | |
| 4791 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4792 | |
| 4793 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4794 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4795 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4796 | port_id.b.rsvd_1 = 0; |
| 4797 | |
| 4798 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4799 | |
| 4800 | /* Mark all stale commands sitting in qla_tgt_wq for deletion */ |
| 4801 | abort_cmds_for_s_id(vha, &port_id); |
| 4802 | |
| 4803 | if (wwn) { |
| 4804 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 4805 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4806 | port_id, loop_id, &conflict_sess); |
| 4807 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | aa9e6d7 | 2018-08-31 11:24:38 -0700 | [diff] [blame] | 4808 | } else { |
| 4809 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4810 | "%s %d Term INOT due to WWN=0 lid=%d, NportID %06X ", |
| 4811 | __func__, __LINE__, loop_id, port_id.b24); |
| 4812 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4813 | goto out; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4817 | res = 1; |
| 4818 | goto out; |
| 4819 | } |
| 4820 | |
| 4821 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4822 | if (!pla) { |
Quinn Tran | 48acad0 | 2018-08-02 13:16:44 -0700 | [diff] [blame] | 4823 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
| 4824 | "%s %d %8phC Term INOT due to mem alloc fail", |
| 4825 | __func__, __LINE__, |
| 4826 | iocb->u.isp24.port_name); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4827 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4828 | goto out; |
| 4829 | } |
| 4830 | |
| 4831 | if (conflict_sess) { |
| 4832 | conflict_sess->login_gen++; |
| 4833 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
| 4834 | QLT_PLOGI_LINK_CONFLICT); |
| 4835 | } |
| 4836 | |
| 4837 | if (!sess) { |
| 4838 | pla->ref_count++; |
| 4839 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4840 | "%s %d %8phC post new sess\n", |
| 4841 | __func__, __LINE__, iocb->u.isp24.port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4842 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 4843 | qla24xx_post_newsess_work(vha, &port_id, |
| 4844 | iocb->u.isp24.port_name, |
| 4845 | iocb->u.isp24.u.plogi.node_name, |
| 4846 | pla, FC4_TYPE_UNKNOWN); |
| 4847 | else |
| 4848 | qla24xx_post_newsess_work(vha, &port_id, |
| 4849 | iocb->u.isp24.port_name, NULL, |
| 4850 | pla, FC4_TYPE_UNKNOWN); |
| 4851 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4852 | goto out; |
| 4853 | } |
| 4854 | |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 4855 | if (sess->disc_state == DSC_UPD_FCPORT) { |
| 4856 | u16 sec; |
| 4857 | |
| 4858 | /* |
| 4859 | * Remote port registration is still going on from |
| 4860 | * previous login. Allow it to finish before we |
| 4861 | * accept the new login. |
| 4862 | */ |
| 4863 | sess->next_disc_state = DSC_DELETE_PEND; |
| 4864 | sec = jiffies_to_msecs(jiffies - |
| 4865 | sess->jiffies_at_registration) / 1000; |
| 4866 | if (sess->sec_since_registration < sec && sec && |
| 4867 | !(sec % 5)) { |
| 4868 | sess->sec_since_registration = sec; |
| 4869 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4870 | "%s %8phC - Slow Rport registration (%d Sec)\n", |
| 4871 | __func__, sess->port_name, sec); |
| 4872 | } |
| 4873 | |
| 4874 | if (!conflict_sess) |
| 4875 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 4876 | |
| 4877 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4878 | goto out; |
| 4879 | } |
| 4880 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4881 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
| 4882 | sess->d_id = port_id; |
| 4883 | sess->login_gen++; |
| 4884 | |
| 4885 | if (iocb->u.isp24.status_subcode == ELS_PRLI) { |
| 4886 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4887 | sess->local = 0; |
| 4888 | sess->loop_id = loop_id; |
| 4889 | sess->d_id = port_id; |
| 4890 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4891 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4892 | |
| 4893 | if (wd3_lo & BIT_7) |
| 4894 | sess->conf_compl_supported = 1; |
| 4895 | |
| 4896 | if ((wd3_lo & BIT_4) == 0) |
| 4897 | sess->port_type = FCT_INITIATOR; |
| 4898 | else |
| 4899 | sess->port_type = FCT_TARGET; |
| 4900 | |
| 4901 | } else |
| 4902 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4903 | |
| 4904 | |
| 4905 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4906 | "%s %d %8phC DS %d\n", |
| 4907 | __func__, __LINE__, sess->port_name, sess->disc_state); |
| 4908 | |
| 4909 | switch (sess->disc_state) { |
| 4910 | case DSC_DELETED: |
| 4911 | qlt_plogi_ack_unref(vha, pla); |
| 4912 | break; |
| 4913 | |
| 4914 | default: |
| 4915 | /* |
| 4916 | * Under normal circumstances we want to release nport handle |
| 4917 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4918 | * The exception is when LOGO is done while another PLOGI with |
| 4919 | * the same nport handle is waiting as might be the case here. |
| 4920 | * Note: there is always a possibily of a race where session |
| 4921 | * deletion has already started for other reasons (e.g. ACL |
| 4922 | * removal) and now PLOGI arrives: |
| 4923 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4924 | * FW must have assigned this PLOGI a new/same handle and we |
| 4925 | * can proceed ACK'ing it as usual when session deletion |
| 4926 | * completes. |
| 4927 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4928 | * bit reached it, the handle has now been released. We'll |
| 4929 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4930 | * back to initiator. Initiator should eventually retry |
| 4931 | * PLOGI and situation will correct itself. |
| 4932 | */ |
| 4933 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4934 | (sess->d_id.b24 == port_id.b24)); |
| 4935 | |
| 4936 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4937 | "%s %d %8phC post del sess\n", |
| 4938 | __func__, __LINE__, sess->port_name); |
| 4939 | |
| 4940 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4941 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4942 | break; |
| 4943 | } |
| 4944 | out: |
| 4945 | return res; |
| 4946 | } |
| 4947 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4948 | /* |
| 4949 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4950 | */ |
| 4951 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4952 | struct imm_ntfy_from_isp *iocb) |
| 4953 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4954 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4955 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4956 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4957 | uint64_t wwn; |
| 4958 | port_id_t port_id; |
| 4959 | uint16_t loop_id; |
| 4960 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4961 | int res = 0; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4962 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4963 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4964 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4965 | |
| 4966 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4967 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4968 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4969 | port_id.b.rsvd_1 = 0; |
| 4970 | |
| 4971 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4972 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4973 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4974 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4975 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4976 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4977 | iocb->u.isp24.status_subcode, loop_id, |
| 4978 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4979 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4980 | /* res = 1 means ack at the end of thread |
| 4981 | * res = 0 means ack async/later. |
| 4982 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4983 | switch (iocb->u.isp24.status_subcode) { |
| 4984 | case ELS_PLOGI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4985 | res = qlt_handle_login(vha, iocb); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4986 | break; |
| 4987 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4988 | case ELS_PRLI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4989 | if (N2N_TOPO(ha)) { |
| 4990 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4991 | iocb->u.isp24.port_name, 1); |
| 4992 | |
| 4993 | if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) { |
| 4994 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4995 | "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n", |
| 4996 | __func__, __LINE__, |
| 4997 | iocb->u.isp24.port_name); |
| 4998 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4999 | break; |
| 5000 | } |
| 5001 | |
| 5002 | res = qlt_handle_login(vha, iocb); |
| 5003 | break; |
| 5004 | } |
| 5005 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5006 | if (IS_SW_RESV_ADDR(port_id)) { |
| 5007 | res = 1; |
| 5008 | break; |
| 5009 | } |
| 5010 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5011 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 5012 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5013 | if (wwn) { |
| 5014 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5015 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 5016 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5017 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 5018 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 5019 | |
| 5020 | if (conflict_sess) { |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 5021 | switch (conflict_sess->disc_state) { |
| 5022 | case DSC_DELETED: |
| 5023 | case DSC_DELETE_PEND: |
| 5024 | break; |
| 5025 | default: |
| 5026 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 5027 | "PRLI with conflicting sess %p port %8phC\n", |
| 5028 | conflict_sess, conflict_sess->port_name); |
| 5029 | conflict_sess->fw_login_state = |
| 5030 | DSC_LS_PORT_UNAVAIL; |
| 5031 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 5032 | res = 0; |
| 5033 | break; |
| 5034 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 5035 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5036 | |
| 5037 | if (sess != NULL) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5038 | bool delete = false; |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 5039 | int sec; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5040 | |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 5041 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
| 5042 | switch (sess->fw_login_state) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5043 | case DSC_LS_PLOGI_PEND: |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 5044 | case DSC_LS_PLOGI_COMP: |
| 5045 | case DSC_LS_PRLI_COMP: |
| 5046 | break; |
| 5047 | default: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5048 | delete = true; |
| 5049 | break; |
| 5050 | } |
| 5051 | |
| 5052 | switch (sess->disc_state) { |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 5053 | case DSC_UPD_FCPORT: |
| 5054 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 5055 | flags); |
| 5056 | |
| 5057 | sec = jiffies_to_msecs(jiffies - |
| 5058 | sess->jiffies_at_registration)/1000; |
| 5059 | if (sess->sec_since_registration < sec && sec && |
| 5060 | !(sec % 5)) { |
| 5061 | sess->sec_since_registration = sec; |
| 5062 | ql_dbg(ql_dbg_disc, sess->vha, 0xffff, |
| 5063 | "%s %8phC : Slow Rport registration(%d Sec)\n", |
| 5064 | __func__, sess->port_name, sec); |
| 5065 | } |
| 5066 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 5067 | return 0; |
| 5068 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5069 | case DSC_LOGIN_PEND: |
| 5070 | case DSC_GPDB: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5071 | case DSC_LOGIN_COMPLETE: |
| 5072 | case DSC_ADISC: |
| 5073 | delete = false; |
| 5074 | break; |
| 5075 | default: |
| 5076 | break; |
| 5077 | } |
| 5078 | |
| 5079 | if (delete) { |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 5080 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 5081 | flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5082 | /* |
| 5083 | * Impatient initiator sent PRLI before last |
| 5084 | * PLOGI could finish. Will force him to re-try, |
| 5085 | * while last one finishes. |
| 5086 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5087 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5088 | "sess %p PRLI received, before plogi ack.\n", |
| 5089 | sess); |
| 5090 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 5091 | res = 0; |
| 5092 | break; |
| 5093 | } |
| 5094 | |
| 5095 | /* |
| 5096 | * This shouldn't happen under normal circumstances, |
| 5097 | * since we have deleted the old session during PLOGI |
| 5098 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5099 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5100 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 5101 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 5102 | |
| 5103 | sess->local = 0; |
| 5104 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 5105 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5106 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5107 | |
| 5108 | if (wd3_lo & BIT_7) |
| 5109 | sess->conf_compl_supported = 1; |
| 5110 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5111 | if ((wd3_lo & BIT_4) == 0) |
| 5112 | sess->port_type = FCT_INITIATOR; |
| 5113 | else |
| 5114 | sess->port_type = FCT_TARGET; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 5115 | |
| 5116 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5117 | } |
| 5118 | res = 1; /* send notify ack */ |
| 5119 | |
| 5120 | /* Make session global (not used in fabric mode) */ |
| 5121 | if (ha->current_topology != ISP_CFG_F) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5122 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5123 | ql_dbg(ql_dbg_disc, vha, 0x20fa, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5124 | "%s %d %8phC post nack\n", |
| 5125 | __func__, __LINE__, sess->port_name); |
| 5126 | qla24xx_post_nack_work(vha, sess, iocb, |
| 5127 | SRB_NACK_PRLI); |
| 5128 | res = 0; |
| 5129 | } else { |
| 5130 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5131 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5132 | qla2xxx_wake_dpc(vha); |
| 5133 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5134 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5135 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5136 | ql_dbg(ql_dbg_disc, vha, 0x20fb, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5137 | "%s %d %8phC post nack\n", |
| 5138 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5139 | qla24xx_post_nack_work(vha, sess, iocb, |
| 5140 | SRB_NACK_PRLI); |
| 5141 | res = 0; |
| 5142 | } |
| 5143 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5144 | break; |
| 5145 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5146 | case ELS_TPRLO: |
| 5147 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 5148 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 5149 | loop_id = 0xFFFF; |
| 5150 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 5151 | res = 1; |
| 5152 | break; |
| 5153 | } |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 5154 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5155 | case ELS_LOGO: |
| 5156 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5157 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 5158 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 5159 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 5160 | |
| 5161 | if (sess) { |
| 5162 | sess->login_gen++; |
| 5163 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5164 | sess->logo_ack_needed = 1; |
| 5165 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 5166 | } |
| 5167 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5168 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5169 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5170 | ql_dbg(ql_dbg_disc, vha, 0x20fc, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5171 | "%s: logo %llx res %d sess %p ", |
| 5172 | __func__, wwn, res, sess); |
| 5173 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5174 | /* |
| 5175 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 5176 | * for LOGO_ACK & sess delete |
| 5177 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5178 | BUG_ON(!sess); |
| 5179 | res = 0; |
| 5180 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5181 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5182 | if (sess) { |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 5183 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5184 | res = 0; |
| 5185 | } |
| 5186 | /* else logo will be ack */ |
| 5187 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5188 | break; |
| 5189 | case ELS_PDISC: |
| 5190 | case ELS_ADISC: |
| 5191 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5192 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5193 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5194 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5195 | qlt_send_notify_ack(ha->base_qpair, |
| 5196 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5197 | tgt->link_reinit_iocb_pending = 0; |
| 5198 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5199 | |
| 5200 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 5201 | iocb->u.isp24.port_name, 1); |
| 5202 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5203 | ql_dbg(ql_dbg_disc, vha, 0x20fd, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5204 | "sess %p lid %d|%d DS %d LS %d\n", |
| 5205 | sess, sess->loop_id, loop_id, |
| 5206 | sess->disc_state, sess->fw_login_state); |
| 5207 | } |
| 5208 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5209 | res = 1; /* send notify ack */ |
| 5210 | break; |
| 5211 | } |
| 5212 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 5213 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5214 | default: |
| 5215 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 5216 | "qla_target(%d): Unsupported ELS command %x " |
| 5217 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 5218 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 5219 | break; |
| 5220 | } |
| 5221 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 5222 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 5223 | "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n", |
| 5224 | vha->vp_idx, iocb->u.isp24.status_subcode, res); |
| 5225 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5226 | return res; |
| 5227 | } |
| 5228 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5229 | /* |
| 5230 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5231 | */ |
| 5232 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 5233 | struct imm_ntfy_from_isp *iocb) |
| 5234 | { |
| 5235 | struct qla_hw_data *ha = vha->hw; |
| 5236 | uint32_t add_flags = 0; |
| 5237 | int send_notify_ack = 1; |
| 5238 | uint16_t status; |
| 5239 | |
| 5240 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 5241 | switch (status) { |
| 5242 | case IMM_NTFY_LIP_RESET: |
| 5243 | { |
| 5244 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 5245 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 5246 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5247 | iocb->u.isp24.status_subcode); |
| 5248 | |
| 5249 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5250 | send_notify_ack = 0; |
| 5251 | break; |
| 5252 | } |
| 5253 | |
| 5254 | case IMM_NTFY_LIP_LINK_REINIT: |
| 5255 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5256 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5257 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5258 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 5259 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 5260 | "subcode %x)\n", vha->vp_idx, |
| 5261 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5262 | iocb->u.isp24.status_subcode); |
| 5263 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5264 | qlt_send_notify_ack(ha->base_qpair, |
| 5265 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5266 | } |
| 5267 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 5268 | tgt->link_reinit_iocb_pending = 1; |
| 5269 | /* |
| 5270 | * QLogic requires to wait after LINK REINIT for possible |
| 5271 | * PDISC or ADISC ELS commands |
| 5272 | */ |
| 5273 | send_notify_ack = 0; |
| 5274 | break; |
| 5275 | } |
| 5276 | |
| 5277 | case IMM_NTFY_PORT_LOGOUT: |
| 5278 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 5279 | "qla_target(%d): Port logout (loop " |
| 5280 | "%#x, subcode %x)\n", vha->vp_idx, |
| 5281 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5282 | iocb->u.isp24.status_subcode); |
| 5283 | |
| 5284 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 5285 | send_notify_ack = 0; |
| 5286 | /* The sessions will be cleared in the callback, if needed */ |
| 5287 | break; |
| 5288 | |
| 5289 | case IMM_NTFY_GLBL_TPRLO: |
| 5290 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 5291 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 5292 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5293 | send_notify_ack = 0; |
| 5294 | /* The sessions will be cleared in the callback, if needed */ |
| 5295 | break; |
| 5296 | |
| 5297 | case IMM_NTFY_PORT_CONFIG: |
| 5298 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 5299 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 5300 | status); |
| 5301 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5302 | send_notify_ack = 0; |
| 5303 | /* The sessions will be cleared in the callback, if needed */ |
| 5304 | break; |
| 5305 | |
| 5306 | case IMM_NTFY_GLBL_LOGO: |
| 5307 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 5308 | "qla_target(%d): Link failure detected\n", |
| 5309 | vha->vp_idx); |
| 5310 | /* I_T nexus loss */ |
| 5311 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5312 | send_notify_ack = 0; |
| 5313 | break; |
| 5314 | |
| 5315 | case IMM_NTFY_IOCB_OVERFLOW: |
| 5316 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 5317 | "qla_target(%d): Cannot provide requested " |
| 5318 | "capability (IOCB overflowed the immediate notify " |
| 5319 | "resource count)\n", vha->vp_idx); |
| 5320 | break; |
| 5321 | |
| 5322 | case IMM_NTFY_ABORT_TASK: |
| 5323 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 5324 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 5325 | "L %#x)\n", vha->vp_idx, |
| 5326 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 5327 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 5328 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 5329 | if (qlt_abort_task(vha, iocb) == 0) |
| 5330 | send_notify_ack = 0; |
| 5331 | break; |
| 5332 | |
| 5333 | case IMM_NTFY_RESOURCE: |
| 5334 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 5335 | "qla_target(%d): Out of resources, host %ld\n", |
| 5336 | vha->vp_idx, vha->host_no); |
| 5337 | break; |
| 5338 | |
| 5339 | case IMM_NTFY_MSG_RX: |
| 5340 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 5341 | "qla_target(%d): Immediate notify task %x\n", |
| 5342 | vha->vp_idx, iocb->u.isp2x.task_flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5343 | break; |
| 5344 | |
| 5345 | case IMM_NTFY_ELS: |
| 5346 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 5347 | send_notify_ack = 0; |
| 5348 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5349 | default: |
| 5350 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 5351 | "qla_target(%d): Received unknown immediate " |
| 5352 | "notify status %x\n", vha->vp_idx, status); |
| 5353 | break; |
| 5354 | } |
| 5355 | |
| 5356 | if (send_notify_ack) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5357 | qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0, |
| 5358 | 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | /* |
| 5362 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5363 | * This function sends busy to ISP 2xxx or 24xx. |
| 5364 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5365 | static int __qlt_send_busy(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5366 | struct atio_from_isp *atio, uint16_t status) |
| 5367 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5368 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5369 | struct ctio7_to_24xx *ctio24; |
| 5370 | struct qla_hw_data *ha = vha->hw; |
| 5371 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5372 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5373 | unsigned long flags; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5374 | u16 temp; |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame] | 5375 | port_id_t id; |
| 5376 | |
| 5377 | id.b.al_pa = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5378 | id.b.area = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5379 | id.b.domain = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5380 | id.b.rsvd_1 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5381 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5382 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame] | 5383 | sess = qla2x00_find_fcport_by_nportid(vha, &id, 1); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5384 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5385 | if (!sess) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5386 | qlt_send_term_exchange(qpair, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5387 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5388 | } |
| 5389 | /* Sending marker isn't necessary, since we called from ISR */ |
| 5390 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5391 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5392 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5393 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5394 | "qla_target(%d): %s failed: unable to allocate " |
| 5395 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5396 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5397 | } |
| 5398 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5399 | qpair->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5400 | pkt->entry_count = 1; |
| 5401 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5402 | |
| 5403 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5404 | ctio24->entry_type = CTIO_TYPE7; |
| 5405 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5406 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5407 | ctio24->vp_index = vha->vp_idx; |
| 5408 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5409 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5410 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5411 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5412 | temp = (atio->u.isp24.attr << 9) | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5413 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5414 | CTIO7_FLAGS_DONT_RET_CTIO; |
| 5415 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5416 | /* |
| 5417 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5418 | * if the explicit conformation is used. |
| 5419 | */ |
| 5420 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 5421 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Quinn Tran | e25f765 | 2018-05-01 09:01:50 -0700 | [diff] [blame] | 5422 | |
| 5423 | ctio24->u.status1.residual = get_datalen_for_atio(atio); |
| 5424 | |
| 5425 | if (ctio24->u.status1.residual != 0) |
| 5426 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 5427 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5428 | /* Memory Barrier */ |
| 5429 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 5430 | if (qpair->reqq_start_iocbs) |
| 5431 | qpair->reqq_start_iocbs(qpair); |
| 5432 | else |
| 5433 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5434 | return 0; |
| 5435 | } |
| 5436 | |
| 5437 | /* |
| 5438 | * This routine is used to allocate a command for either a QFull condition |
| 5439 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5440 | * out previously. |
| 5441 | */ |
| 5442 | static void |
| 5443 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5444 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5445 | { |
| 5446 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5447 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5448 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5449 | struct se_session *se_sess; |
| 5450 | struct qla_tgt_cmd *cmd; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5451 | int tag, cpu; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5452 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5453 | |
| 5454 | if (unlikely(tgt->tgt_stop)) { |
| 5455 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5456 | "New command while device %p is shutting down\n", tgt); |
| 5457 | return; |
| 5458 | } |
| 5459 | |
| 5460 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5461 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5462 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5463 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5464 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5465 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5466 | |
| 5467 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5468 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5469 | vha->vp_idx, __func__, |
| 5470 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5471 | |
| 5472 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5473 | return; |
| 5474 | } |
| 5475 | |
| 5476 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5477 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5478 | if (!sess) |
| 5479 | return; |
| 5480 | |
| 5481 | se_sess = sess->se_sess; |
| 5482 | |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5483 | tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5484 | if (tag < 0) |
| 5485 | return; |
| 5486 | |
| 5487 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 5488 | if (!cmd) { |
| 5489 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5490 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5491 | vha->vp_idx, __func__); |
| 5492 | |
| 5493 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5494 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5495 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5496 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5497 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5498 | |
| 5499 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5500 | return; |
| 5501 | } |
| 5502 | |
| 5503 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 5504 | |
| 5505 | qlt_incr_num_pend_cmds(vha); |
| 5506 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5507 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5508 | |
| 5509 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5510 | cmd->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5511 | cmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5512 | cmd->q_full = 1; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5513 | cmd->qpair = ha->base_qpair; |
Matthew Wilcox | 10e9cbb | 2018-06-12 12:05:44 -0700 | [diff] [blame] | 5514 | cmd->se_cmd.map_cpu = cpu; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5515 | |
| 5516 | if (qfull) { |
| 5517 | cmd->q_full = 1; |
| 5518 | /* NOTE: borrowing the state field to carry the status */ |
| 5519 | cmd->state = status; |
| 5520 | } else |
| 5521 | cmd->term_exchg = 1; |
| 5522 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5523 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5524 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5525 | |
| 5526 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5527 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5528 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5529 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5530 | vha->hw->tgt.num_qfull_cmds_alloc; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5531 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5535 | qlt_free_qfull_cmds(struct qla_qpair *qpair) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5536 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5537 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5538 | struct qla_hw_data *ha = vha->hw; |
| 5539 | unsigned long flags; |
| 5540 | struct qla_tgt_cmd *cmd, *tcmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5541 | struct list_head free_list, q_full_list; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5542 | int rc = 0; |
| 5543 | |
| 5544 | if (list_empty(&ha->tgt.q_full_list)) |
| 5545 | return 0; |
| 5546 | |
| 5547 | INIT_LIST_HEAD(&free_list); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5548 | INIT_LIST_HEAD(&q_full_list); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5549 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5550 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5551 | if (list_empty(&ha->tgt.q_full_list)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5552 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5553 | return 0; |
| 5554 | } |
| 5555 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5556 | list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list); |
| 5557 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5558 | |
| 5559 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 5560 | list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5561 | if (cmd->q_full) |
| 5562 | /* cmd->state is a borrowed field to hold status */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5563 | rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5564 | else if (cmd->term_exchg) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5565 | rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5566 | |
| 5567 | if (rc == -ENOMEM) |
| 5568 | break; |
| 5569 | |
| 5570 | if (cmd->q_full) |
| 5571 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5572 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5573 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5574 | else if (cmd->term_exchg) |
| 5575 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5576 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5577 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5578 | else |
| 5579 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5580 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5581 | cmd); |
| 5582 | |
| 5583 | list_del(&cmd->cmd_list); |
| 5584 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5585 | |
| 5586 | /* piggy back on hardware_lock for protection */ |
| 5587 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5588 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5589 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5590 | |
| 5591 | cmd = NULL; |
| 5592 | |
| 5593 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5594 | list_del(&cmd->cmd_list); |
| 5595 | /* This cmd was never sent to TCM. There is no need |
| 5596 | * to schedule free or call free_cmd |
| 5597 | */ |
| 5598 | qlt_free_cmd(cmd); |
| 5599 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5600 | |
| 5601 | if (!list_empty(&q_full_list)) { |
| 5602 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 5603 | list_splice(&q_full_list, &vha->hw->tgt.q_full_list); |
| 5604 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5605 | } |
| 5606 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5607 | return rc; |
| 5608 | } |
| 5609 | |
| 5610 | static void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5611 | qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio, |
| 5612 | uint16_t status) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5613 | { |
| 5614 | int rc = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5615 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5616 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5617 | rc = __qlt_send_busy(qpair, atio, status); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5618 | if (rc == -ENOMEM) |
| 5619 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5620 | } |
| 5621 | |
| 5622 | static int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5623 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair, |
| 5624 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5625 | { |
| 5626 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5627 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5628 | |
| 5629 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5630 | return 0; |
| 5631 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5632 | if (!ha_locked) |
| 5633 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5634 | qlt_send_busy(qpair, atio, qla_sam_status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5635 | if (!ha_locked) |
| 5636 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5637 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5638 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | /* ha->hardware_lock supposed to be held on entry */ |
| 5642 | /* called via callback from qla2xxx */ |
| 5643 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5644 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5645 | { |
| 5646 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5647 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5648 | int rc; |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5649 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5650 | |
| 5651 | if (unlikely(tgt == NULL)) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5652 | ql_dbg(ql_dbg_tgt, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5653 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5654 | return; |
| 5655 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5656 | /* |
| 5657 | * In tgt_stop mode we also should allow all requests to pass. |
| 5658 | * Otherwise, some commands can stuck. |
| 5659 | */ |
| 5660 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5661 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5662 | |
| 5663 | switch (atio->u.raw.entry_type) { |
| 5664 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5665 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5666 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5667 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5668 | "qla_target(%d): ATIO_TYPE7 " |
| 5669 | "received with UNKNOWN exchange address, " |
| 5670 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5671 | if (!ha_locked) |
| 5672 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5673 | qlt_send_busy(ha->base_qpair, atio, qla_sam_status); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5674 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5675 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5676 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5677 | break; |
| 5678 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5679 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5680 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5681 | rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair, |
| 5682 | atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5683 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5684 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5685 | return; |
| 5686 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5687 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5688 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5689 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5690 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5691 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5692 | if (!ha_locked) |
| 5693 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5694 | switch (rc) { |
| 5695 | case -ENODEV: |
| 5696 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5697 | "qla_target: Unable to send command to target\n"); |
| 5698 | break; |
| 5699 | case -EBADF: |
| 5700 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5701 | "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] | 5702 | qlt_send_term_exchange(ha->base_qpair, NULL, |
| 5703 | atio, 1, 0); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5704 | break; |
| 5705 | case -EBUSY: |
| 5706 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5707 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5708 | vha->vp_idx); |
| 5709 | qlt_send_busy(ha->base_qpair, atio, |
| 5710 | tc_sam_status); |
| 5711 | break; |
| 5712 | default: |
| 5713 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5714 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5715 | vha->vp_idx); |
| 5716 | qlt_send_busy(ha->base_qpair, atio, |
| 5717 | qla_sam_status); |
| 5718 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5719 | } |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5720 | if (!ha_locked) |
| 5721 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5722 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5723 | } |
| 5724 | break; |
| 5725 | |
| 5726 | case IMMED_NOTIFY_TYPE: |
| 5727 | { |
| 5728 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5729 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5730 | "qla_target(%d): Received ATIO packet %x " |
| 5731 | "with error status %x\n", vha->vp_idx, |
| 5732 | atio->u.raw.entry_type, |
| 5733 | atio->u.isp2x.entry_status); |
| 5734 | break; |
| 5735 | } |
| 5736 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5737 | |
| 5738 | if (!ha_locked) |
| 5739 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5740 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5741 | if (!ha_locked) |
| 5742 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5743 | break; |
| 5744 | } |
| 5745 | |
| 5746 | default: |
| 5747 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5748 | "qla_target(%d): Received unknown ATIO atio " |
| 5749 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5750 | break; |
| 5751 | } |
| 5752 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5753 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5754 | } |
| 5755 | |
Quinn Tran | 0691094 | 2018-09-04 14:19:12 -0700 | [diff] [blame] | 5756 | /* |
| 5757 | * qpair lock is assume to be held |
| 5758 | * rc = 0 : send terminate & abts respond |
| 5759 | * rc != 0: do not send term & abts respond |
| 5760 | */ |
| 5761 | static int qlt_chk_unresolv_exchg(struct scsi_qla_host *vha, |
| 5762 | struct qla_qpair *qpair, struct abts_resp_from_24xx_fw *entry) |
| 5763 | { |
| 5764 | struct qla_hw_data *ha = vha->hw; |
| 5765 | int rc = 0; |
| 5766 | |
| 5767 | /* |
| 5768 | * Detect unresolved exchange. If the same ABTS is unable |
| 5769 | * to terminate an existing command and the same ABTS loops |
| 5770 | * between FW & Driver, then force FW dump. Under 1 jiff, |
| 5771 | * we should see multiple loops. |
| 5772 | */ |
| 5773 | if (qpair->retry_term_exchg_addr == entry->exchange_addr_to_abort && |
| 5774 | qpair->retry_term_jiff == jiffies) { |
| 5775 | /* found existing exchange */ |
| 5776 | qpair->retry_term_cnt++; |
| 5777 | if (qpair->retry_term_cnt >= 5) { |
| 5778 | rc = EIO; |
| 5779 | qpair->retry_term_cnt = 0; |
| 5780 | ql_log(ql_log_warn, vha, 0xffff, |
| 5781 | "Unable to send ABTS Respond. Dumping firmware.\n"); |
| 5782 | ql_dump_buffer(ql_dbg_tgt_mgt + ql_dbg_buffer, |
| 5783 | vha, 0xffff, (uint8_t *)entry, sizeof(*entry)); |
| 5784 | |
| 5785 | if (qpair == ha->base_qpair) |
| 5786 | ha->isp_ops->fw_dump(vha, 1); |
| 5787 | else |
| 5788 | ha->isp_ops->fw_dump(vha, 0); |
| 5789 | |
| 5790 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5791 | qla2xxx_wake_dpc(vha); |
| 5792 | } |
| 5793 | } else if (qpair->retry_term_jiff != jiffies) { |
| 5794 | qpair->retry_term_exchg_addr = entry->exchange_addr_to_abort; |
| 5795 | qpair->retry_term_cnt = 0; |
| 5796 | qpair->retry_term_jiff = jiffies; |
| 5797 | } |
| 5798 | |
| 5799 | return rc; |
| 5800 | } |
| 5801 | |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5802 | |
| 5803 | static void qlt_handle_abts_completion(struct scsi_qla_host *vha, |
| 5804 | struct rsp_que *rsp, response_t *pkt) |
| 5805 | { |
| 5806 | struct abts_resp_from_24xx_fw *entry = |
| 5807 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5808 | u32 h = pkt->handle & ~QLA_TGT_HANDLE_MASK; |
| 5809 | struct qla_tgt_mgmt_cmd *mcmd; |
| 5810 | struct qla_hw_data *ha = vha->hw; |
| 5811 | |
Bart Van Assche | 81bcf1c | 2019-04-11 14:53:24 -0700 | [diff] [blame] | 5812 | mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt); |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5813 | if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) { |
| 5814 | ql_dbg(ql_dbg_async, vha, 0xe064, |
| 5815 | "qla_target(%d): ABTS Comp without mcmd\n", |
| 5816 | vha->vp_idx); |
| 5817 | return; |
| 5818 | } |
| 5819 | |
| 5820 | if (mcmd) |
| 5821 | vha = mcmd->vha; |
| 5822 | vha->vha_tgt.qla_tgt->abts_resp_expected--; |
| 5823 | |
| 5824 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5825 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5826 | entry->compl_status); |
| 5827 | |
| 5828 | if (le16_to_cpu(entry->compl_status) != ABTS_RESP_COMPL_SUCCESS) { |
| 5829 | if ((entry->error_subcode1 == 0x1E) && |
| 5830 | (entry->error_subcode2 == 0)) { |
| 5831 | if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) { |
| 5832 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5833 | return; |
| 5834 | } |
| 5835 | qlt_24xx_retry_term_exchange(vha, rsp->qpair, |
| 5836 | pkt, mcmd); |
| 5837 | } else { |
| 5838 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5839 | "qla_target(%d): ABTS_RESP_24XX failed %x (subcode %x:%x)", |
| 5840 | vha->vp_idx, entry->compl_status, |
| 5841 | entry->error_subcode1, |
| 5842 | entry->error_subcode2); |
| 5843 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5844 | } |
| 5845 | } else { |
| 5846 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 5847 | } |
| 5848 | } |
| 5849 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5850 | /* ha->hardware_lock supposed to be held on entry */ |
| 5851 | /* called via callback from qla2xxx */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5852 | static void qlt_response_pkt(struct scsi_qla_host *vha, |
| 5853 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5854 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5855 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5856 | |
| 5857 | if (unlikely(tgt == NULL)) { |
| 5858 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5859 | "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n", |
| 5860 | vha->vp_idx, pkt->entry_type, vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5861 | return; |
| 5862 | } |
| 5863 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5864 | /* |
| 5865 | * In tgt_stop mode we also should allow all requests to pass. |
| 5866 | * Otherwise, some commands can stuck. |
| 5867 | */ |
| 5868 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5869 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5870 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5871 | case CTIO_TYPE7: |
| 5872 | { |
| 5873 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5874 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5875 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5876 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5877 | entry); |
| 5878 | break; |
| 5879 | } |
| 5880 | |
| 5881 | case ACCEPT_TGT_IO_TYPE: |
| 5882 | { |
| 5883 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5884 | int rc; |
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 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5887 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5888 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5889 | "qla_target(%d): ATIO with error " |
| 5890 | "status %x received\n", vha->vp_idx, |
| 5891 | le16_to_cpu(atio->u.isp2x.status)); |
| 5892 | break; |
| 5893 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5894 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5895 | rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1); |
Quinn Tran | ba68a63 | 2017-06-02 09:12:06 -0700 | [diff] [blame] | 5896 | if (rc != 0) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5897 | return; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5898 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5899 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5900 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5901 | switch (rc) { |
| 5902 | case -ENODEV: |
| 5903 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5904 | "qla_target: Unable to send command to target\n"); |
| 5905 | break; |
| 5906 | case -EBADF: |
| 5907 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5908 | "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); |
| 5909 | qlt_send_term_exchange(rsp->qpair, NULL, |
| 5910 | atio, 1, 0); |
| 5911 | break; |
| 5912 | case -EBUSY: |
| 5913 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5914 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5915 | vha->vp_idx); |
| 5916 | qlt_send_busy(rsp->qpair, atio, |
| 5917 | tc_sam_status); |
| 5918 | break; |
| 5919 | default: |
| 5920 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5921 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5922 | vha->vp_idx); |
| 5923 | qlt_send_busy(rsp->qpair, atio, |
| 5924 | qla_sam_status); |
| 5925 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5926 | } |
| 5927 | } |
| 5928 | } |
| 5929 | break; |
| 5930 | |
| 5931 | case CONTINUE_TGT_IO_TYPE: |
| 5932 | { |
| 5933 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5934 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5935 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5936 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5937 | entry); |
| 5938 | break; |
| 5939 | } |
| 5940 | |
| 5941 | case CTIO_A64_TYPE: |
| 5942 | { |
| 5943 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5944 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5945 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5946 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5947 | entry); |
| 5948 | break; |
| 5949 | } |
| 5950 | |
| 5951 | case IMMED_NOTIFY_TYPE: |
| 5952 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5953 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5954 | break; |
| 5955 | |
| 5956 | case NOTIFY_ACK_TYPE: |
| 5957 | if (tgt->notify_ack_expected > 0) { |
| 5958 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 5959 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5960 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5961 | "NOTIFY_ACK seq %08x status %x\n", |
| 5962 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5963 | le16_to_cpu(entry->u.isp2x.status)); |
| 5964 | tgt->notify_ack_expected--; |
| 5965 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5966 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5967 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5968 | "qla_target(%d): NOTIFY_ACK " |
| 5969 | "failed %x\n", vha->vp_idx, |
| 5970 | le16_to_cpu(entry->u.isp2x.status)); |
| 5971 | } |
| 5972 | } else { |
| 5973 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5974 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5975 | vha->vp_idx); |
| 5976 | } |
| 5977 | break; |
| 5978 | |
| 5979 | case ABTS_RECV_24XX: |
| 5980 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5981 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5982 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5983 | break; |
| 5984 | |
| 5985 | case ABTS_RESP_24XX: |
| 5986 | if (tgt->abts_resp_expected > 0) { |
Quinn Tran | 6b0431d | 2018-09-04 14:19:13 -0700 | [diff] [blame] | 5987 | qlt_handle_abts_completion(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5988 | } else { |
| 5989 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5990 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5991 | "received\n", vha->vp_idx); |
| 5992 | } |
| 5993 | break; |
| 5994 | |
| 5995 | default: |
| 5996 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5997 | "qla_target(%d): Received unknown response pkt " |
| 5998 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5999 | break; |
| 6000 | } |
| 6001 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6002 | } |
| 6003 | |
| 6004 | /* |
| 6005 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 6006 | */ |
| 6007 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 6008 | uint16_t *mailbox) |
| 6009 | { |
| 6010 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6011 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 6012 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6013 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 6014 | if (!tgt || tgt->tgt_stop || tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6015 | return; |
| 6016 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6017 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 6018 | IS_QLA2100(ha)) |
| 6019 | return; |
| 6020 | /* |
| 6021 | * In tgt_stop mode we also should allow all requests to pass. |
| 6022 | * Otherwise, some commands can stuck. |
| 6023 | */ |
| 6024 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6025 | |
| 6026 | switch (code) { |
| 6027 | case MBA_RESET: /* Reset */ |
| 6028 | case MBA_SYSTEM_ERR: /* System Error */ |
| 6029 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 6030 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 6031 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 6032 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 6033 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6034 | break; |
| 6035 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 6036 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6037 | break; |
| 6038 | |
| 6039 | case MBA_LOOP_UP: |
| 6040 | { |
| 6041 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 6042 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 6043 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 6044 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 6045 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6046 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6047 | qlt_send_notify_ack(ha->base_qpair, |
| 6048 | (void *)&tgt->link_reinit_iocb, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6049 | 0, 0, 0, 0, 0, 0); |
| 6050 | tgt->link_reinit_iocb_pending = 0; |
| 6051 | } |
| 6052 | break; |
| 6053 | } |
| 6054 | |
| 6055 | case MBA_LIP_OCCURRED: |
| 6056 | case MBA_LOOP_DOWN: |
| 6057 | case MBA_LIP_RESET: |
| 6058 | case MBA_RSCN_UPDATE: |
| 6059 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 6060 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 6061 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 6062 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 6063 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6064 | break; |
| 6065 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6066 | case MBA_REJECTED_FCP_CMD: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6067 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017, |
| 6068 | "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", |
| 6069 | vha->vp_idx, |
| 6070 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 6071 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6072 | |
| 6073 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 6074 | /* exchange starvation. */ |
| 6075 | vha->hw->exch_starvation++; |
| 6076 | if (vha->hw->exch_starvation > 5) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6077 | ql_log(ql_log_warn, vha, 0xd03a, |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6078 | "Exchange starvation-. Resetting RISC\n"); |
| 6079 | |
| 6080 | vha->hw->exch_starvation = 0; |
| 6081 | if (IS_P3P_TYPE(vha->hw)) |
| 6082 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 6083 | &vha->dpc_flags); |
| 6084 | else |
| 6085 | set_bit(ISP_ABORT_NEEDED, |
| 6086 | &vha->dpc_flags); |
| 6087 | qla2xxx_wake_dpc(vha); |
| 6088 | } |
| 6089 | } |
| 6090 | break; |
| 6091 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6092 | case MBA_PORT_UPDATE: |
| 6093 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 6094 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 6095 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 6096 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 6097 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 6098 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 6099 | |
| 6100 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6101 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6102 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 6103 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6104 | vha->hw->exch_starvation = 0; |
| 6105 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6106 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 6107 | "Async MB 2: Port Logged Out\n"); |
| 6108 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6109 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6110 | break; |
| 6111 | } |
| 6112 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6113 | } |
| 6114 | |
| 6115 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 6116 | uint16_t loop_id) |
| 6117 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6118 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6119 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6120 | unsigned long flags; |
| 6121 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6122 | |
Quinn Tran | 063b36d | 2017-12-04 14:45:10 -0800 | [diff] [blame] | 6123 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6124 | if (!fcport) { |
| 6125 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 6126 | "qla_target(%d): Allocation of tmp FC port failed", |
| 6127 | vha->vp_idx); |
| 6128 | return NULL; |
| 6129 | } |
| 6130 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6131 | fcport->loop_id = loop_id; |
| 6132 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 6133 | rc = qla24xx_gpdb_wait(vha, fcport, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6134 | if (rc != QLA_SUCCESS) { |
| 6135 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 6136 | "qla_target(%d): Failed to retrieve fcport " |
| 6137 | "information -- get_port_database() returned %x " |
| 6138 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 6139 | kfree(fcport); |
| 6140 | return NULL; |
| 6141 | } |
| 6142 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6143 | del = NULL; |
| 6144 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 6145 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 6146 | |
| 6147 | if (tfcp) { |
| 6148 | tfcp->d_id = fcport->d_id; |
| 6149 | tfcp->port_type = fcport->port_type; |
| 6150 | tfcp->supported_classes = fcport->supported_classes; |
| 6151 | tfcp->flags |= fcport->flags; |
Quinn Tran | 76f9a2d | 2017-12-04 14:45:11 -0800 | [diff] [blame] | 6152 | tfcp->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6153 | |
| 6154 | del = fcport; |
| 6155 | fcport = tfcp; |
| 6156 | } else { |
| 6157 | if (vha->hw->current_topology == ISP_CFG_F) |
| 6158 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 6159 | |
| 6160 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 6161 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 6162 | vha->fcport_count++; |
| 6163 | fcport->login_gen++; |
| 6164 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 6165 | fcport->login_succ = 1; |
| 6166 | newfcport = 1; |
| 6167 | } |
| 6168 | |
| 6169 | fcport->deleted = 0; |
| 6170 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 6171 | |
| 6172 | switch (vha->host->active_mode) { |
| 6173 | case MODE_INITIATOR: |
| 6174 | case MODE_DUAL: |
| 6175 | if (newfcport) { |
| 6176 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
Quinn Tran | cd4ed6b | 2018-08-31 11:24:31 -0700 | [diff] [blame] | 6177 | qla24xx_sched_upd_fcport(fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6178 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6179 | ql_dbg(ql_dbg_disc, vha, 0x20ff, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6180 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 6181 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 6182 | qla24xx_post_gpsc_work(vha, fcport); |
| 6183 | } |
| 6184 | } |
| 6185 | break; |
| 6186 | |
| 6187 | case MODE_TARGET: |
| 6188 | default: |
| 6189 | break; |
| 6190 | } |
| 6191 | if (del) |
| 6192 | qla2x00_free_fcport(del); |
| 6193 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6194 | return fcport; |
| 6195 | } |
| 6196 | |
| 6197 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6198 | 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] | 6199 | uint8_t *s_id) |
| 6200 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6201 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6202 | fc_port_t *fcport = NULL; |
| 6203 | int rc, global_resets; |
| 6204 | uint16_t loop_id = 0; |
| 6205 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6206 | if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) { |
| 6207 | /* |
| 6208 | * This is Domain Controller, so it should be |
| 6209 | * OK to drop SCSI commands from it. |
| 6210 | */ |
| 6211 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 6212 | "Unable to find initiator with S_ID %x:%x:%x", |
| 6213 | s_id[0], s_id[1], s_id[2]); |
| 6214 | return NULL; |
| 6215 | } |
| 6216 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6217 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 6218 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6219 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6220 | global_resets = |
| 6221 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6222 | |
| 6223 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 6224 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6225 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 6226 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6227 | ql_log(ql_log_info, vha, 0xf071, |
| 6228 | "qla_target(%d): Unable to find " |
| 6229 | "initiator with S_ID %x:%x:%x", |
| 6230 | vha->vp_idx, s_id[0], s_id[1], |
| 6231 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6232 | |
| 6233 | if (rc == -ENOENT) { |
| 6234 | qlt_port_logo_t logo; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 6235 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6236 | sid_to_portid(s_id, &logo.id); |
| 6237 | logo.cmd_count = 1; |
| 6238 | qlt_send_first_logo(vha, &logo); |
| 6239 | } |
| 6240 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6241 | return NULL; |
| 6242 | } |
| 6243 | |
| 6244 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6245 | if (!fcport) { |
| 6246 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6247 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6248 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6249 | |
| 6250 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6251 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6252 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 6253 | "qla_target(%d): global reset during session discovery " |
| 6254 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 6255 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6256 | atomic_read(&vha->vha_tgt. |
| 6257 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6258 | goto retry; |
| 6259 | } |
| 6260 | |
| 6261 | sess = qlt_create_sess(vha, fcport, true); |
| 6262 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 6263 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 6264 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6265 | return sess; |
| 6266 | } |
| 6267 | |
| 6268 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 6269 | struct qla_tgt_sess_work_param *prm) |
| 6270 | { |
| 6271 | struct scsi_qla_host *vha = tgt->vha; |
| 6272 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6273 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6274 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6275 | uint32_t be_s_id; |
| 6276 | uint8_t s_id[3]; |
| 6277 | int rc; |
| 6278 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6279 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6280 | |
| 6281 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6282 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6283 | |
| 6284 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 6285 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 6286 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 6287 | |
| 6288 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 6289 | (unsigned char *)&be_s_id); |
| 6290 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6291 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6292 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6293 | sess = qlt_make_local_sess(vha, s_id); |
| 6294 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6295 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6296 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6297 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6298 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6299 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6300 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6301 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6302 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6303 | } |
| 6304 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6305 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6306 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6307 | "%s: kref_get fail %8phC \n", |
| 6308 | __func__, sess->port_name); |
| 6309 | sess = NULL; |
| 6310 | goto out_term2; |
| 6311 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6312 | } |
| 6313 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6314 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6315 | ha->tgt.tgt_ops->put_sess(sess); |
| 6316 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 6317 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6318 | if (rc != 0) |
| 6319 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6320 | return; |
| 6321 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6322 | out_term2: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6323 | if (sess) |
| 6324 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6325 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6326 | |
| 6327 | out_term: |
| 6328 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6329 | qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts, |
| 6330 | FCP_TMF_REJECTED, false); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6331 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 6335 | struct qla_tgt_sess_work_param *prm) |
| 6336 | { |
| 6337 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 6338 | struct scsi_qla_host *vha = tgt->vha; |
| 6339 | struct qla_hw_data *ha = vha->hw; |
Colin Ian King | bb6abdd | 2019-02-15 09:52:32 +0000 | [diff] [blame] | 6340 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6341 | unsigned long flags; |
| 6342 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 6343 | int rc; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6344 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 6345 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6346 | void *iocb; |
| 6347 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6348 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6349 | |
| 6350 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6351 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6352 | |
| 6353 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 6354 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 6355 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6356 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6357 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6358 | sess = qlt_make_local_sess(vha, s_id); |
| 6359 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6360 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6361 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6362 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6363 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6364 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6365 | if (sess->deleted) { |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6366 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6367 | } |
| 6368 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6369 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6370 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6371 | "%s: kref_get fail %8phC\n", |
| 6372 | __func__, sess->port_name); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6373 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6374 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6375 | } |
| 6376 | |
| 6377 | iocb = a; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6378 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6379 | unpacked_lun = |
| 6380 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6381 | |
| 6382 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6383 | ha->tgt.tgt_ops->put_sess(sess); |
| 6384 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 6385 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6386 | if (rc != 0) |
| 6387 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6388 | return; |
| 6389 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6390 | out_term2: |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6391 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6392 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6393 | 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] | 6394 | } |
| 6395 | |
| 6396 | static void qlt_sess_work_fn(struct work_struct *work) |
| 6397 | { |
| 6398 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 6399 | struct scsi_qla_host *vha = tgt->vha; |
| 6400 | unsigned long flags; |
| 6401 | |
| 6402 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 6403 | |
| 6404 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6405 | while (!list_empty(&tgt->sess_works_list)) { |
| 6406 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 6407 | tgt->sess_works_list.next, typeof(*prm), |
| 6408 | sess_works_list_entry); |
| 6409 | |
| 6410 | /* |
| 6411 | * This work can be scheduled on several CPUs at time, so we |
| 6412 | * must delete the entry to eliminate double processing |
| 6413 | */ |
| 6414 | list_del(&prm->sess_works_list_entry); |
| 6415 | |
| 6416 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6417 | |
| 6418 | switch (prm->type) { |
| 6419 | case QLA_TGT_SESS_WORK_ABORT: |
| 6420 | qlt_abort_work(tgt, prm); |
| 6421 | break; |
| 6422 | case QLA_TGT_SESS_WORK_TM: |
| 6423 | qlt_tmr_work(tgt, prm); |
| 6424 | break; |
| 6425 | default: |
| 6426 | BUG_ON(1); |
| 6427 | break; |
| 6428 | } |
| 6429 | |
| 6430 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6431 | |
| 6432 | kfree(prm); |
| 6433 | } |
| 6434 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6435 | } |
| 6436 | |
| 6437 | /* Must be called under tgt_host_action_mutex */ |
| 6438 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 6439 | { |
| 6440 | struct qla_tgt *tgt; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6441 | int rc, i; |
| 6442 | struct qla_qpair_hint *h; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6443 | |
| 6444 | if (!QLA_TGT_MODE_ENABLED()) |
| 6445 | return 0; |
| 6446 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 6447 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 6448 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 6449 | "This adapter does not support target mode.\n"); |
| 6450 | return 0; |
| 6451 | } |
| 6452 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6453 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6454 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6455 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6456 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6457 | |
| 6458 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 6459 | if (!tgt) { |
| 6460 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 6461 | "Unable to allocate struct qla_tgt\n"); |
| 6462 | return -ENOMEM; |
| 6463 | } |
| 6464 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6465 | tgt->qphints = kcalloc(ha->max_qpairs + 1, |
| 6466 | sizeof(struct qla_qpair_hint), |
| 6467 | GFP_KERNEL); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6468 | if (!tgt->qphints) { |
| 6469 | kfree(tgt); |
| 6470 | ql_log(ql_log_warn, base_vha, 0x0197, |
| 6471 | "Unable to allocate qpair hints.\n"); |
| 6472 | return -ENOMEM; |
| 6473 | } |
| 6474 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6475 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 6476 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 6477 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6478 | rc = btree_init64(&tgt->lun_qpair_map); |
| 6479 | if (rc) { |
| 6480 | kfree(tgt->qphints); |
| 6481 | kfree(tgt); |
| 6482 | ql_log(ql_log_info, base_vha, 0x0198, |
| 6483 | "Unable to initialize lun_qpair_map btree\n"); |
| 6484 | return -EIO; |
| 6485 | } |
| 6486 | h = &tgt->qphints[0]; |
| 6487 | h->qpair = ha->base_qpair; |
| 6488 | INIT_LIST_HEAD(&h->hint_elem); |
| 6489 | h->cpuid = ha->base_qpair->cpuid; |
| 6490 | list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list); |
| 6491 | |
| 6492 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6493 | unsigned long flags; |
| 6494 | |
| 6495 | struct qla_qpair *qpair = ha->queue_pair_map[i]; |
Bart Van Assche | bd432bb | 2019-04-11 14:53:17 -0700 | [diff] [blame] | 6496 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6497 | h = &tgt->qphints[i + 1]; |
| 6498 | INIT_LIST_HEAD(&h->hint_elem); |
| 6499 | if (qpair) { |
| 6500 | h->qpair = qpair; |
| 6501 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 6502 | list_add_tail(&h->hint_elem, &qpair->hints_list); |
| 6503 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 6504 | h->cpuid = qpair->cpuid; |
| 6505 | } |
| 6506 | } |
| 6507 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6508 | tgt->ha = ha; |
| 6509 | tgt->vha = base_vha; |
| 6510 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6511 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6512 | spin_lock_init(&tgt->sess_work_lock); |
| 6513 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6514 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6515 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6516 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6517 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6518 | |
| 6519 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6520 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6521 | base_vha->vp_idx); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6522 | /* 3 is reserved */ |
| 6523 | 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] | 6524 | |
| 6525 | mutex_lock(&qla_tgt_mutex); |
| 6526 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6527 | mutex_unlock(&qla_tgt_mutex); |
| 6528 | |
Quinn Tran | f1443ee | 2017-03-15 09:48:51 -0700 | [diff] [blame] | 6529 | if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target) |
| 6530 | ha->tgt.tgt_ops->add_target(base_vha); |
| 6531 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6532 | return 0; |
| 6533 | } |
| 6534 | |
| 6535 | /* Must be called under tgt_host_action_mutex */ |
| 6536 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6537 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6538 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6539 | return 0; |
| 6540 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6541 | if (vha->fc_vport) { |
| 6542 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6543 | return 0; |
| 6544 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6545 | |
| 6546 | /* free left over qfull cmds */ |
| 6547 | qlt_init_term_exchange(vha); |
| 6548 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6549 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6550 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6551 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6552 | |
| 6553 | return 0; |
| 6554 | } |
| 6555 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6556 | void qlt_remove_target_resources(struct qla_hw_data *ha) |
| 6557 | { |
| 6558 | struct scsi_qla_host *node; |
| 6559 | u32 key = 0; |
| 6560 | |
| 6561 | btree_for_each_safe32(&ha->tgt.host_map, key, node) |
| 6562 | btree_remove32(&ha->tgt.host_map, key); |
| 6563 | |
| 6564 | btree_destroy32(&ha->tgt.host_map); |
| 6565 | } |
| 6566 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6567 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6568 | unsigned char *b) |
| 6569 | { |
| 6570 | int i; |
| 6571 | |
| 6572 | pr_debug("qla2xxx HW vha->node_name: "); |
| 6573 | for (i = 0; i < WWN_SIZE; i++) |
| 6574 | pr_debug("%02x ", vha->node_name[i]); |
| 6575 | pr_debug("\n"); |
| 6576 | pr_debug("qla2xxx HW vha->port_name: "); |
| 6577 | for (i = 0; i < WWN_SIZE; i++) |
| 6578 | pr_debug("%02x ", vha->port_name[i]); |
| 6579 | pr_debug("\n"); |
| 6580 | |
| 6581 | pr_debug("qla2xxx passed configfs WWPN: "); |
| 6582 | put_unaligned_be64(wwpn, b); |
| 6583 | for (i = 0; i < WWN_SIZE; i++) |
| 6584 | pr_debug("%02x ", b[i]); |
| 6585 | pr_debug("\n"); |
| 6586 | } |
| 6587 | |
| 6588 | /** |
| 6589 | * qla_tgt_lport_register - register lport with external module |
| 6590 | * |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6591 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
Bart Van Assche | 807eb90 | 2018-10-18 15:45:41 -0700 | [diff] [blame] | 6592 | * @phys_wwpn: physical port WWPN |
| 6593 | * @npiv_wwpn: NPIV WWPN |
| 6594 | * @npiv_wwnn: NPIV WWNN |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 6595 | * @callback: lport initialization callback for tcm_qla2xxx code |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6596 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6597 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6598 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6599 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6600 | { |
| 6601 | struct qla_tgt *tgt; |
| 6602 | struct scsi_qla_host *vha; |
| 6603 | struct qla_hw_data *ha; |
| 6604 | struct Scsi_Host *host; |
| 6605 | unsigned long flags; |
| 6606 | int rc; |
| 6607 | u8 b[WWN_SIZE]; |
| 6608 | |
| 6609 | mutex_lock(&qla_tgt_mutex); |
| 6610 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6611 | vha = tgt->vha; |
| 6612 | ha = vha->hw; |
| 6613 | |
| 6614 | host = vha->host; |
| 6615 | if (!host) |
| 6616 | continue; |
| 6617 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6618 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6619 | continue; |
| 6620 | |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6621 | if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED) |
| 6622 | continue; |
| 6623 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6624 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6625 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6626 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6627 | host->host_no); |
| 6628 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6629 | continue; |
| 6630 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6631 | if (tgt->tgt_stop) { |
| 6632 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6633 | host->host_no); |
| 6634 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6635 | continue; |
| 6636 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6637 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6638 | |
| 6639 | if (!scsi_host_get(host)) { |
| 6640 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6641 | "Unable to scsi_host_get() for" |
| 6642 | " qla2xxx scsi_host\n"); |
| 6643 | continue; |
| 6644 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6645 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6646 | |
| 6647 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6648 | scsi_host_put(host); |
| 6649 | continue; |
| 6650 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6651 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6652 | if (rc != 0) |
| 6653 | scsi_host_put(host); |
| 6654 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6655 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6656 | return rc; |
| 6657 | } |
| 6658 | mutex_unlock(&qla_tgt_mutex); |
| 6659 | |
| 6660 | return -ENODEV; |
| 6661 | } |
| 6662 | EXPORT_SYMBOL(qlt_lport_register); |
| 6663 | |
| 6664 | /** |
| 6665 | * qla_tgt_lport_deregister - Degister lport |
| 6666 | * |
| 6667 | * @vha: Registered scsi_qla_host pointer |
| 6668 | */ |
| 6669 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6670 | { |
| 6671 | struct qla_hw_data *ha = vha->hw; |
| 6672 | struct Scsi_Host *sh = vha->host; |
| 6673 | /* |
| 6674 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6675 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6676 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6677 | ha->tgt.tgt_ops = NULL; |
| 6678 | /* |
| 6679 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6680 | */ |
| 6681 | scsi_host_put(sh); |
| 6682 | } |
| 6683 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6684 | |
| 6685 | /* Must be called under HW lock */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6686 | void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6687 | { |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6688 | switch (vha->qlini_mode) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6689 | case QLA2XXX_INI_MODE_DISABLED: |
| 6690 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6691 | vha->host->active_mode = MODE_TARGET; |
| 6692 | break; |
| 6693 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6694 | vha->host->active_mode = MODE_INITIATOR; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6695 | break; |
| 6696 | case QLA2XXX_INI_MODE_DUAL: |
| 6697 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6698 | break; |
| 6699 | default: |
| 6700 | break; |
| 6701 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6702 | } |
| 6703 | |
| 6704 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6705 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6706 | { |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6707 | switch (vha->qlini_mode) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6708 | case QLA2XXX_INI_MODE_DISABLED: |
| 6709 | vha->host->active_mode = MODE_UNKNOWN; |
| 6710 | break; |
| 6711 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6712 | vha->host->active_mode = MODE_INITIATOR; |
| 6713 | break; |
| 6714 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6715 | case QLA2XXX_INI_MODE_DUAL: |
| 6716 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6717 | break; |
| 6718 | default: |
| 6719 | break; |
| 6720 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | /* |
| 6724 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6725 | * |
| 6726 | * host_reset, bring up w/ Target Mode Enabled |
| 6727 | */ |
| 6728 | void |
| 6729 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6730 | { |
| 6731 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6732 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6733 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6734 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6735 | |
| 6736 | if (!tgt) { |
| 6737 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6738 | "Unable to locate qla_tgt pointer from" |
| 6739 | " struct qla_hw_data\n"); |
| 6740 | dump_stack(); |
| 6741 | return; |
| 6742 | } |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6743 | if (vha->qlini_mode == QLA2XXX_INI_MODE_ENABLED) |
| 6744 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6745 | |
| 6746 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6747 | tgt->tgt_stopped = 0; |
| 6748 | qlt_set_mode(vha); |
| 6749 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6750 | |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 6751 | mutex_lock(&ha->optrom_mutex); |
| 6752 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, |
| 6753 | "%s.\n", __func__); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6754 | if (vha->vp_idx) { |
| 6755 | qla24xx_disable_vp(vha); |
| 6756 | qla24xx_enable_vp(vha); |
| 6757 | } else { |
| 6758 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6759 | qla2xxx_wake_dpc(base_vha); |
| 6760 | qla2x00_wait_for_hba_online(base_vha); |
| 6761 | } |
Quinn Tran | b6faaaf | 2018-09-04 14:19:09 -0700 | [diff] [blame] | 6762 | mutex_unlock(&ha->optrom_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6763 | } |
| 6764 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6765 | |
| 6766 | /* |
| 6767 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6768 | * |
| 6769 | * Disable Target Mode and reset the adapter |
| 6770 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6771 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6772 | { |
| 6773 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6774 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6775 | unsigned long flags; |
| 6776 | |
| 6777 | if (!tgt) { |
| 6778 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6779 | "Unable to locate qla_tgt pointer from" |
| 6780 | " struct qla_hw_data\n"); |
| 6781 | dump_stack(); |
| 6782 | return; |
| 6783 | } |
| 6784 | |
| 6785 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6786 | qlt_clear_mode(vha); |
| 6787 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6788 | |
| 6789 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6790 | qla2xxx_wake_dpc(vha); |
| 6791 | qla2x00_wait_for_hba_online(vha); |
| 6792 | } |
| 6793 | |
| 6794 | /* |
| 6795 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6796 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6797 | * members. |
| 6798 | */ |
| 6799 | void |
| 6800 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6801 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6802 | vha->vha_tgt.qla_tgt = NULL; |
| 6803 | |
| 6804 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6805 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6806 | |
| 6807 | qlt_clear_mode(vha); |
| 6808 | |
| 6809 | /* |
| 6810 | * NOTE: Currently the value is kept the same for <24xx and |
| 6811 | * >=24xx ISPs. If it is necessary to change it, |
| 6812 | * the check should be added for specific ISPs, |
| 6813 | * assigning the value appropriately. |
| 6814 | */ |
| 6815 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6816 | |
| 6817 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6818 | } |
| 6819 | |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6820 | u8 |
| 6821 | qlt_rff_id(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6822 | { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6823 | u8 fc4_feature = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6824 | /* |
| 6825 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6826 | */ |
| 6827 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6828 | fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6829 | } else if (qla_ini_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6830 | fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6831 | } else if (qla_dual_mode_enabled(vha)) |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6832 | fc4_feature = BIT_0 | BIT_1; |
| 6833 | |
| 6834 | return fc4_feature; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6835 | } |
| 6836 | |
| 6837 | /* |
| 6838 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6839 | * @ha: HA context |
| 6840 | * |
| 6841 | * Beginning of ATIO ring has initialization control block already built |
| 6842 | * by nvram config routine. |
| 6843 | * |
| 6844 | * Returns 0 on success. |
| 6845 | */ |
| 6846 | void |
| 6847 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6848 | { |
| 6849 | struct qla_hw_data *ha = vha->hw; |
| 6850 | uint16_t cnt; |
| 6851 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6852 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6853 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6854 | return; |
| 6855 | |
| 6856 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6857 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6858 | pkt++; |
| 6859 | } |
| 6860 | |
| 6861 | } |
| 6862 | |
| 6863 | /* |
| 6864 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6865 | * @ha: SCSI driver HA context |
| 6866 | */ |
| 6867 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6868 | 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] | 6869 | { |
| 6870 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6871 | struct atio_from_isp *pkt; |
| 6872 | int cnt, i; |
| 6873 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6874 | if (!ha->flags.fw_started) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6875 | return; |
| 6876 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6877 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6878 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6879 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6880 | cnt = pkt->u.raw.entry_count; |
| 6881 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6882 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6883 | /* |
| 6884 | * This packet is corrupted. The header + payload |
| 6885 | * can not be trusted. There is no point in passing |
| 6886 | * it further up. |
| 6887 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6888 | ql_log(ql_log_warn, vha, 0xd03c, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6889 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6890 | pkt->u.isp24.fcp_hdr.s_id, |
| 6891 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6892 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6893 | |
| 6894 | adjust_corrupted_atio(pkt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6895 | qlt_send_term_exchange(ha->base_qpair, NULL, pkt, |
| 6896 | ha_locked, 0); |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6897 | } else { |
| 6898 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6899 | (struct atio_from_isp *)pkt, ha_locked); |
| 6900 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6901 | |
| 6902 | for (i = 0; i < cnt; i++) { |
| 6903 | ha->tgt.atio_ring_index++; |
| 6904 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6905 | ha->tgt.atio_ring_index = 0; |
| 6906 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6907 | } else |
| 6908 | ha->tgt.atio_ring_ptr++; |
| 6909 | |
| 6910 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6911 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6912 | } |
| 6913 | wmb(); |
| 6914 | } |
| 6915 | |
| 6916 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6917 | 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] | 6918 | } |
| 6919 | |
| 6920 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6921 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6922 | { |
| 6923 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6924 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6925 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6926 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6927 | if (!QLA_TGT_MODE_ENABLED()) |
| 6928 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6929 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6930 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6931 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6932 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6933 | |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6934 | if (ha->flags.msix_enabled) { |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 6935 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) { |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6936 | if (IS_QLA2071(ha)) { |
| 6937 | /* 4 ports Baker: Enable Interrupt Handshake */ |
| 6938 | icb->msix_atio = 0; |
| 6939 | icb->firmware_options_2 |= BIT_26; |
| 6940 | } else { |
| 6941 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6942 | icb->firmware_options_2 &= ~BIT_26; |
| 6943 | } |
| 6944 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6945 | "Registering ICB vector 0x%x for atio que.\n", |
| 6946 | msix->entry); |
| 6947 | } |
| 6948 | } else { |
| 6949 | /* INTx|MSI */ |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 6950 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) { |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6951 | icb->msix_atio = 0; |
| 6952 | icb->firmware_options_2 |= BIT_26; |
| 6953 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6954 | "%s: Use INTx for ATIOQ.\n", __func__); |
| 6955 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6956 | } |
| 6957 | } |
| 6958 | |
| 6959 | void |
| 6960 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6961 | { |
| 6962 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6963 | u32 tmp; |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6964 | |
| 6965 | if (!QLA_TGT_MODE_ENABLED()) |
| 6966 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6967 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6968 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6969 | if (!ha->tgt.saved_set) { |
| 6970 | /* We save only once */ |
| 6971 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6972 | ha->tgt.saved_firmware_options_1 = |
| 6973 | nv->firmware_options_1; |
| 6974 | ha->tgt.saved_firmware_options_2 = |
| 6975 | nv->firmware_options_2; |
| 6976 | ha->tgt.saved_firmware_options_3 = |
| 6977 | nv->firmware_options_3; |
| 6978 | ha->tgt.saved_set = 1; |
| 6979 | } |
| 6980 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6981 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6982 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6983 | else /* dual */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 6984 | nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6985 | |
| 6986 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6987 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6988 | |
| 6989 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6990 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6991 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6992 | |
| 6993 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6994 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6995 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6996 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6997 | if (ql2xtgt_tape_enable) |
| 6998 | /* Enable FC Tape support */ |
| 6999 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7000 | else |
| 7001 | /* Disable FC Tape support */ |
| 7002 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 7003 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7004 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7005 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 7006 | |
| 7007 | /* |
| 7008 | * clear BIT 15 explicitly as we have seen at least |
| 7009 | * a couple of instances where this was set and this |
| 7010 | * was causing the firmware to not be initialized. |
| 7011 | */ |
| 7012 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7013 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7014 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 7015 | |
| 7016 | if (IS_QLA25XX(ha)) { |
| 7017 | /* Change Loop-prefer to Pt-Pt */ |
| 7018 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 7019 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 7020 | tmp = P2P << 4; |
| 7021 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
| 7022 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7023 | } else { |
| 7024 | if (ha->tgt.saved_set) { |
| 7025 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 7026 | nv->firmware_options_1 = |
| 7027 | ha->tgt.saved_firmware_options_1; |
| 7028 | nv->firmware_options_2 = |
| 7029 | ha->tgt.saved_firmware_options_2; |
| 7030 | nv->firmware_options_3 = |
| 7031 | ha->tgt.saved_firmware_options_3; |
| 7032 | } |
| 7033 | return; |
| 7034 | } |
| 7035 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7036 | if (ha->base_qpair->enable_class_2) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7037 | if (vha->flags.init_done) |
| 7038 | fc_host_supported_classes(vha->host) = |
| 7039 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 7040 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7041 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7042 | } else { |
| 7043 | if (vha->flags.init_done) |
| 7044 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 7045 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7046 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7047 | } |
| 7048 | } |
| 7049 | |
| 7050 | void |
| 7051 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 7052 | struct init_cb_24xx *icb) |
| 7053 | { |
| 7054 | struct qla_hw_data *ha = vha->hw; |
| 7055 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 7056 | if (!QLA_TGT_MODE_ENABLED()) |
| 7057 | return; |
| 7058 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7059 | if (ha->tgt.node_name_set) { |
| 7060 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7061 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7062 | } |
| 7063 | } |
| 7064 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7065 | void |
| 7066 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 7067 | { |
| 7068 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 7069 | u32 tmp; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7070 | |
| 7071 | if (!QLA_TGT_MODE_ENABLED()) |
| 7072 | return; |
| 7073 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7074 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7075 | if (!ha->tgt.saved_set) { |
| 7076 | /* We save only once */ |
| 7077 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 7078 | ha->tgt.saved_firmware_options_1 = |
| 7079 | nv->firmware_options_1; |
| 7080 | ha->tgt.saved_firmware_options_2 = |
| 7081 | nv->firmware_options_2; |
| 7082 | ha->tgt.saved_firmware_options_3 = |
| 7083 | nv->firmware_options_3; |
| 7084 | ha->tgt.saved_set = 1; |
| 7085 | } |
| 7086 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 7087 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7088 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 7089 | else /* dual */ |
Quinn Tran | 0645cb8 | 2018-09-11 10:18:18 -0700 | [diff] [blame] | 7090 | nv->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7091 | |
| 7092 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7093 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7094 | |
| 7095 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7096 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7097 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7098 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7099 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7100 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7101 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 7102 | /* |
| 7103 | * clear BIT 15 explicitly as we have seen at |
| 7104 | * least a couple of instances where this was set |
| 7105 | * and this was causing the firmware to not be |
| 7106 | * initialized. |
| 7107 | */ |
| 7108 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 7109 | if (ql2xtgt_tape_enable) |
| 7110 | /* Enable FC tape support */ |
| 7111 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7112 | else |
| 7113 | /* Disable FC tape support */ |
| 7114 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 7115 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7116 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7117 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7118 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7119 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 7120 | |
| 7121 | /* Change Loop-prefer to Pt-Pt */ |
| 7122 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 7123 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 7124 | tmp = P2P << 4; |
| 7125 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7126 | } else { |
| 7127 | if (ha->tgt.saved_set) { |
| 7128 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 7129 | nv->firmware_options_1 = |
| 7130 | ha->tgt.saved_firmware_options_1; |
| 7131 | nv->firmware_options_2 = |
| 7132 | ha->tgt.saved_firmware_options_2; |
| 7133 | nv->firmware_options_3 = |
| 7134 | ha->tgt.saved_firmware_options_3; |
| 7135 | } |
| 7136 | return; |
| 7137 | } |
| 7138 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7139 | if (ha->base_qpair->enable_class_2) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7140 | if (vha->flags.init_done) |
| 7141 | fc_host_supported_classes(vha->host) = |
| 7142 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 7143 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7144 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7145 | } else { |
| 7146 | if (vha->flags.init_done) |
| 7147 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 7148 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7149 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7150 | } |
| 7151 | } |
| 7152 | |
| 7153 | void |
| 7154 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 7155 | struct init_cb_81xx *icb) |
| 7156 | { |
| 7157 | struct qla_hw_data *ha = vha->hw; |
| 7158 | |
| 7159 | if (!QLA_TGT_MODE_ENABLED()) |
| 7160 | return; |
| 7161 | |
| 7162 | if (ha->tgt.node_name_set) { |
| 7163 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7164 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7165 | } |
| 7166 | } |
| 7167 | |
| 7168 | void |
| 7169 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 7170 | { |
| 7171 | if (!QLA_TGT_MODE_ENABLED()) |
| 7172 | return; |
| 7173 | |
| 7174 | ha->msix_count += 1; /* For ATIO Q */ |
| 7175 | } |
| 7176 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7177 | |
| 7178 | void |
| 7179 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 7180 | struct vp_config_entry_24xx *vpmod) |
| 7181 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7182 | /* enable target mode. Bit5 = 1 => disable */ |
| 7183 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7184 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7185 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7186 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 7187 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7188 | vpmod->options_idx1 &= ~BIT_4; |
| 7189 | } |
| 7190 | |
| 7191 | void |
| 7192 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 7193 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7194 | int rc; |
| 7195 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7196 | if (!QLA_TGT_MODE_ENABLED()) |
| 7197 | return; |
| 7198 | |
Joe Carnuccio | ecc89f2 | 2019-03-12 11:08:13 -0700 | [diff] [blame] | 7199 | if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha) || |
| 7200 | IS_QLA28XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7201 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 7202 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 7203 | } else { |
| 7204 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 7205 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 7206 | } |
| 7207 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 7208 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 7209 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7210 | |
| 7211 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 7212 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 7213 | qlt_unknown_atio_work_fn); |
| 7214 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7215 | qlt_clear_mode(base_vha); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7216 | |
| 7217 | rc = btree_init32(&ha->tgt.host_map); |
| 7218 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7219 | ql_log(ql_log_info, base_vha, 0xd03d, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7220 | "Unable to initialize ha->host_map btree\n"); |
| 7221 | |
| 7222 | qlt_update_vp_map(base_vha, SET_VP_IDX); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7223 | } |
| 7224 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7225 | irqreturn_t |
| 7226 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 7227 | { |
| 7228 | struct rsp_que *rsp; |
| 7229 | scsi_qla_host_t *vha; |
| 7230 | struct qla_hw_data *ha; |
| 7231 | unsigned long flags; |
| 7232 | |
| 7233 | rsp = (struct rsp_que *) dev_id; |
| 7234 | ha = rsp->hw; |
| 7235 | vha = pci_get_drvdata(ha->pdev); |
| 7236 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7237 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7238 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7239 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7240 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7241 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7242 | |
| 7243 | return IRQ_HANDLED; |
| 7244 | } |
| 7245 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7246 | static void |
| 7247 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 7248 | { |
| 7249 | struct qla_tgt_sess_op *op = container_of(work, |
| 7250 | struct qla_tgt_sess_op, work); |
| 7251 | scsi_qla_host_t *vha = op->vha; |
| 7252 | struct qla_hw_data *ha = vha->hw; |
| 7253 | unsigned long flags; |
| 7254 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7255 | if (qla2x00_reset_active(vha) || |
| 7256 | (op->chip_reset != ha->base_qpair->chip_reset)) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7257 | return; |
| 7258 | |
| 7259 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 7260 | qlt_24xx_process_atio_queue(vha, 0); |
| 7261 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 7262 | |
| 7263 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7264 | qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7265 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 7266 | |
| 7267 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7268 | } |
| 7269 | |
| 7270 | void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7271 | qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp, |
| 7272 | response_t *pkt) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7273 | { |
| 7274 | struct qla_tgt_sess_op *op; |
| 7275 | |
| 7276 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 7277 | |
| 7278 | if (!op) { |
| 7279 | /* do not reach for ATIO queue here. This is best effort err |
| 7280 | * recovery at this point. |
| 7281 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7282 | qlt_response_pkt_all_vps(vha, rsp, pkt); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7283 | return; |
| 7284 | } |
| 7285 | |
| 7286 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 7287 | op->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7288 | op->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7289 | op->rsp = rsp; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 7290 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 7291 | queue_work(qla_tgt_wq, &op->work); |
| 7292 | return; |
| 7293 | } |
| 7294 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7295 | int |
| 7296 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 7297 | { |
| 7298 | if (!QLA_TGT_MODE_ENABLED()) |
| 7299 | return 0; |
| 7300 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7301 | ha->tgt.tgt_vp_map = kcalloc(MAX_MULTI_ID_FABRIC, |
| 7302 | sizeof(struct qla_tgt_vp_map), |
| 7303 | GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7304 | if (!ha->tgt.tgt_vp_map) |
| 7305 | return -ENOMEM; |
| 7306 | |
| 7307 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 7308 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 7309 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 7310 | if (!ha->tgt.atio_ring) { |
| 7311 | kfree(ha->tgt.tgt_vp_map); |
| 7312 | return -ENOMEM; |
| 7313 | } |
| 7314 | return 0; |
| 7315 | } |
| 7316 | |
| 7317 | void |
| 7318 | qlt_mem_free(struct qla_hw_data *ha) |
| 7319 | { |
| 7320 | if (!QLA_TGT_MODE_ENABLED()) |
| 7321 | return; |
| 7322 | |
| 7323 | if (ha->tgt.atio_ring) { |
| 7324 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 7325 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 7326 | ha->tgt.atio_dma); |
| 7327 | } |
Bart Van Assche | 5365bf9 | 2019-04-17 14:44:22 -0700 | [diff] [blame] | 7328 | ha->tgt.atio_ring = NULL; |
| 7329 | ha->tgt.atio_dma = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7330 | kfree(ha->tgt.tgt_vp_map); |
Bart Van Assche | 5365bf9 | 2019-04-17 14:44:22 -0700 | [diff] [blame] | 7331 | ha->tgt.tgt_vp_map = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | /* vport_slock to be held by the caller */ |
| 7335 | void |
| 7336 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 7337 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7338 | void *slot; |
| 7339 | u32 key; |
| 7340 | int rc; |
| 7341 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7342 | if (!QLA_TGT_MODE_ENABLED()) |
| 7343 | return; |
| 7344 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7345 | key = vha->d_id.b24; |
| 7346 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7347 | switch (cmd) { |
| 7348 | case SET_VP_IDX: |
| 7349 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 7350 | break; |
| 7351 | case SET_AL_PA: |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7352 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7353 | if (!slot) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7354 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7355 | "Save vha in host_map %p %06x\n", vha, key); |
| 7356 | rc = btree_insert32(&vha->hw->tgt.host_map, |
| 7357 | key, vha, GFP_ATOMIC); |
| 7358 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7359 | ql_log(ql_log_info, vha, 0xd03e, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7360 | "Unable to insert s_id into host_map: %06x\n", |
| 7361 | key); |
| 7362 | return; |
| 7363 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7364 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 7365 | "replace existing vha in host_map %p %06x\n", vha, key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7366 | btree_update32(&vha->hw->tgt.host_map, key, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7367 | break; |
| 7368 | case RESET_VP_IDX: |
| 7369 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 7370 | break; |
| 7371 | case RESET_AL_PA: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7372 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7373 | "clear vha in host_map %p %06x\n", vha, key); |
| 7374 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7375 | if (slot) |
| 7376 | btree_remove32(&vha->hw->tgt.host_map, key); |
| 7377 | vha->d_id.b24 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7378 | break; |
| 7379 | } |
| 7380 | } |
| 7381 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7382 | void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id) |
| 7383 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7384 | |
| 7385 | if (!vha->d_id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7386 | vha->d_id = id; |
| 7387 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7388 | } else if (vha->d_id.b24 != id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7389 | qlt_update_vp_map(vha, RESET_AL_PA); |
| 7390 | vha->d_id = id; |
| 7391 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7392 | } |
| 7393 | } |
| 7394 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7395 | static int __init qlt_parse_ini_mode(void) |
| 7396 | { |
| 7397 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 7398 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 7399 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 7400 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 7401 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 7402 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7403 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 7404 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7405 | else |
| 7406 | return false; |
| 7407 | |
| 7408 | return true; |
| 7409 | } |
| 7410 | |
| 7411 | int __init qlt_init(void) |
| 7412 | { |
| 7413 | int ret; |
| 7414 | |
| 7415 | if (!qlt_parse_ini_mode()) { |
| 7416 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 7417 | "qlt_parse_ini_mode() failed\n"); |
| 7418 | return -EINVAL; |
| 7419 | } |
| 7420 | |
| 7421 | if (!QLA_TGT_MODE_ENABLED()) |
| 7422 | return 0; |
| 7423 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7424 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 7425 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 7426 | qla_tgt_mgmt_cmd), 0, NULL); |
| 7427 | if (!qla_tgt_mgmt_cmd_cachep) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7428 | ql_log(ql_log_fatal, NULL, 0xd04b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7429 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 7430 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7431 | } |
| 7432 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7433 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 7434 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 7435 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7436 | |
| 7437 | if (!qla_tgt_plogi_cachep) { |
| 7438 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 7439 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 7440 | ret = -ENOMEM; |
| 7441 | goto out_mgmt_cmd_cachep; |
| 7442 | } |
| 7443 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7444 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 7445 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 7446 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 7447 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 7448 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 7449 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7450 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7451 | } |
| 7452 | |
| 7453 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 7454 | if (!qla_tgt_wq) { |
| 7455 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 7456 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 7457 | ret = -ENOMEM; |
| 7458 | goto out_cmd_mempool; |
| 7459 | } |
| 7460 | /* |
| 7461 | * Return 1 to signal that initiator-mode is being disabled |
| 7462 | */ |
| 7463 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 7464 | |
| 7465 | out_cmd_mempool: |
| 7466 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7467 | out_plogi_cachep: |
| 7468 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7469 | out_mgmt_cmd_cachep: |
| 7470 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7471 | return ret; |
| 7472 | } |
| 7473 | |
| 7474 | void qlt_exit(void) |
| 7475 | { |
| 7476 | if (!QLA_TGT_MODE_ENABLED()) |
| 7477 | return; |
| 7478 | |
| 7479 | destroy_workqueue(qla_tgt_wq); |
| 7480 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7481 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7482 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7483 | } |