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 | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 144 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 145 | /* |
| 146 | * Global Variables |
| 147 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 148 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Quinn Tran | b5d1531 | 2017-08-30 10:16:49 -0700 | [diff] [blame] | 149 | struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 150 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 151 | static struct workqueue_struct *qla_tgt_wq; |
| 152 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 153 | static LIST_HEAD(qla_tgt_glist); |
| 154 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 155 | static const char *prot_op_str(u32 prot_op) |
| 156 | { |
| 157 | switch (prot_op) { |
| 158 | case TARGET_PROT_NORMAL: return "NORMAL"; |
| 159 | case TARGET_PROT_DIN_INSERT: return "DIN_INSERT"; |
| 160 | case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT"; |
| 161 | case TARGET_PROT_DIN_STRIP: return "DIN_STRIP"; |
| 162 | case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP"; |
| 163 | case TARGET_PROT_DIN_PASS: return "DIN_PASS"; |
| 164 | case TARGET_PROT_DOUT_PASS: return "DOUT_PASS"; |
| 165 | default: return "UNKNOWN"; |
| 166 | } |
| 167 | } |
| 168 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 169 | /* This API intentionally takes dest as a parameter, rather than returning |
| 170 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 171 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 172 | { |
| 173 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 174 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 175 | /* memory barrier */ |
| 176 | wmb(); |
| 177 | } |
| 178 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 179 | /* Might release hw lock, then reaquire!! */ |
| 180 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 181 | { |
| 182 | /* Send marker if required */ |
| 183 | if (unlikely(vha->marker_needed != 0)) { |
| 184 | int rc = qla2x00_issue_marker(vha, vha_locked); |
| 185 | if (rc != QLA_SUCCESS) { |
| 186 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 187 | "qla_target(%d): issue_marker() failed\n", |
| 188 | vha->vp_idx); |
| 189 | } |
| 190 | return rc; |
| 191 | } |
| 192 | return QLA_SUCCESS; |
| 193 | } |
| 194 | |
| 195 | static inline |
| 196 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
| 197 | uint8_t *d_id) |
| 198 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 199 | struct scsi_qla_host *host; |
| 200 | uint32_t key = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 201 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 202 | if ((vha->d_id.b.area == d_id[1]) && (vha->d_id.b.domain == d_id[0]) && |
| 203 | (vha->d_id.b.al_pa == d_id[2])) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 204 | return vha; |
| 205 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 206 | key = (uint32_t)d_id[0] << 16; |
| 207 | key |= (uint32_t)d_id[1] << 8; |
| 208 | key |= (uint32_t)d_id[2]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 209 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 210 | host = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 211 | if (!host) |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 212 | ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 213 | "Unable to find host %06x\n", key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 214 | |
| 215 | return host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static inline |
| 219 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 220 | uint16_t vp_idx) |
| 221 | { |
| 222 | struct qla_hw_data *ha = vha->hw; |
| 223 | |
| 224 | if (vha->vp_idx == vp_idx) |
| 225 | return vha; |
| 226 | |
| 227 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 228 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 229 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 230 | |
| 231 | return NULL; |
| 232 | } |
| 233 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 234 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 235 | { |
| 236 | unsigned long flags; |
| 237 | |
| 238 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 239 | |
| 240 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 241 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 242 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 243 | vha->hw->tgt.num_pend_cmds; |
| 244 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 245 | } |
| 246 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 247 | { |
| 248 | unsigned long flags; |
| 249 | |
| 250 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 251 | vha->hw->tgt.num_pend_cmds--; |
| 252 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 253 | } |
| 254 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 255 | |
| 256 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 257 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 258 | { |
| 259 | struct qla_tgt_sess_op *u; |
| 260 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 261 | unsigned long flags; |
| 262 | |
| 263 | if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 264 | ql_dbg(ql_dbg_async, vha, 0x502c, |
| 265 | "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped", |
| 266 | vha->vp_idx); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 267 | goto out_term; |
| 268 | } |
| 269 | |
| 270 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 271 | if (u == NULL) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 272 | goto out_term; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 273 | |
| 274 | u->vha = vha; |
| 275 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 276 | INIT_LIST_HEAD(&u->cmd_list); |
| 277 | |
| 278 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 279 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 280 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 281 | |
| 282 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 283 | |
| 284 | out: |
| 285 | return; |
| 286 | |
| 287 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 288 | 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] | 289 | goto out; |
| 290 | } |
| 291 | |
| 292 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 293 | uint8_t ha_locked) |
| 294 | { |
| 295 | struct qla_tgt_sess_op *u, *t; |
| 296 | scsi_qla_host_t *host; |
| 297 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 298 | unsigned long flags; |
| 299 | uint8_t queued = 0; |
| 300 | |
| 301 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 302 | if (u->aborted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 303 | ql_dbg(ql_dbg_async, vha, 0x502e, |
| 304 | "Freeing unknown %s %p, because of Abort\n", |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 305 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 306 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 307 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 308 | goto abort; |
| 309 | } |
| 310 | |
| 311 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 312 | if (host != NULL) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 313 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 314 | "Requeuing unknown ATIO_TYPE7 %p\n", u); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 315 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 316 | } else if (tgt->tgt_stop) { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 317 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 318 | "Freeing unknown %s %p, because tgt is being stopped\n", |
| 319 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 320 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 321 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 322 | } else { |
Quinn Tran | 604e2e5 | 2017-12-28 12:33:37 -0800 | [diff] [blame] | 323 | ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d, |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 324 | "Reschedule u %p, vha %p, host %p\n", u, vha, host); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 325 | if (!queued) { |
| 326 | queued = 1; |
| 327 | schedule_delayed_work(&vha->unknown_atio_work, |
| 328 | 1); |
| 329 | } |
| 330 | continue; |
| 331 | } |
| 332 | |
| 333 | abort: |
| 334 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 335 | list_del(&u->cmd_list); |
| 336 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 337 | kfree(u); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 342 | { |
| 343 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 344 | struct scsi_qla_host, unknown_atio_work); |
| 345 | |
| 346 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 347 | } |
| 348 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 349 | 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] | 350 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 351 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 352 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 353 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 354 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 355 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 356 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 357 | switch (atio->u.raw.entry_type) { |
| 358 | case ATIO_TYPE7: |
| 359 | { |
| 360 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 361 | atio->u.isp24.fcp_hdr.d_id); |
| 362 | if (unlikely(NULL == host)) { |
| 363 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 364 | "qla_target(%d): Received ATIO_TYPE7 " |
| 365 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
| 366 | atio->u.isp24.fcp_hdr.d_id[0], |
| 367 | atio->u.isp24.fcp_hdr.d_id[1], |
| 368 | atio->u.isp24.fcp_hdr.d_id[2]); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 369 | |
| 370 | |
| 371 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 372 | break; |
| 373 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 374 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 375 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 376 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 377 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 378 | break; |
| 379 | } |
| 380 | |
| 381 | case IMMED_NOTIFY_TYPE: |
| 382 | { |
| 383 | struct scsi_qla_host *host = vha; |
| 384 | struct imm_ntfy_from_isp *entry = |
| 385 | (struct imm_ntfy_from_isp *)atio; |
| 386 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 387 | qlt_issue_marker(vha, ha_locked); |
| 388 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 389 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 390 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 391 | host = qlt_find_host_by_vp_idx(vha, |
| 392 | entry->u.isp24.vp_index); |
| 393 | if (unlikely(!host)) { |
| 394 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 395 | "qla_target(%d): Received " |
| 396 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 397 | "with unknown vp_index %d\n", |
| 398 | vha->vp_idx, entry->u.isp24.vp_index); |
| 399 | break; |
| 400 | } |
| 401 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 402 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 406 | case VP_RPT_ID_IOCB_TYPE: |
| 407 | qla24xx_report_id_acquisition(vha, |
| 408 | (struct vp_rpt_id_entry_24xx *)atio); |
| 409 | break; |
| 410 | |
| 411 | case ABTS_RECV_24XX: |
| 412 | { |
| 413 | struct abts_recv_from_24xx *entry = |
| 414 | (struct abts_recv_from_24xx *)atio; |
| 415 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 416 | entry->vp_index); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 417 | unsigned long flags; |
| 418 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 419 | if (unlikely(!host)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 420 | ql_dbg(ql_dbg_tgt, vha, 0xe00a, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 421 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 422 | "received, with unknown vp_index %d\n", |
| 423 | vha->vp_idx, entry->vp_index); |
| 424 | break; |
| 425 | } |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 426 | if (!ha_locked) |
| 427 | spin_lock_irqsave(&host->hw->hardware_lock, flags); |
| 428 | qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio); |
| 429 | if (!ha_locked) |
| 430 | spin_unlock_irqrestore(&host->hw->hardware_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 431 | break; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 435 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 436 | default: |
| 437 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 438 | "qla_target(%d): Received unknown ATIO atio " |
| 439 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 440 | break; |
| 441 | } |
| 442 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 443 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 444 | } |
| 445 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 446 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, |
| 447 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 448 | { |
| 449 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 450 | case CTIO_CRC2: |
| 451 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 452 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 453 | vha->vp_idx, __func__); |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 454 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 455 | case CTIO_TYPE7: |
| 456 | { |
| 457 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 458 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 459 | entry->vp_index); |
| 460 | if (unlikely(!host)) { |
| 461 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 462 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 463 | "received, with unknown vp_index %d\n", |
| 464 | vha->vp_idx, entry->vp_index); |
| 465 | break; |
| 466 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 467 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 468 | break; |
| 469 | } |
| 470 | |
| 471 | case IMMED_NOTIFY_TYPE: |
| 472 | { |
| 473 | struct scsi_qla_host *host = vha; |
| 474 | struct imm_ntfy_from_isp *entry = |
| 475 | (struct imm_ntfy_from_isp *)pkt; |
| 476 | |
| 477 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 478 | if (unlikely(!host)) { |
| 479 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 480 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 481 | "received, with unknown vp_index %d\n", |
| 482 | vha->vp_idx, entry->u.isp24.vp_index); |
| 483 | break; |
| 484 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 485 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 486 | break; |
| 487 | } |
| 488 | |
| 489 | case NOTIFY_ACK_TYPE: |
| 490 | { |
| 491 | struct scsi_qla_host *host = vha; |
| 492 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 493 | |
| 494 | if (0xFF != entry->u.isp24.vp_index) { |
| 495 | host = qlt_find_host_by_vp_idx(vha, |
| 496 | entry->u.isp24.vp_index); |
| 497 | if (unlikely(!host)) { |
| 498 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 499 | "qla_target(%d): Response " |
| 500 | "pkt (NOTIFY_ACK_TYPE) " |
| 501 | "received, with unknown " |
| 502 | "vp_index %d\n", vha->vp_idx, |
| 503 | entry->u.isp24.vp_index); |
| 504 | break; |
| 505 | } |
| 506 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 507 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 508 | break; |
| 509 | } |
| 510 | |
| 511 | case ABTS_RECV_24XX: |
| 512 | { |
| 513 | struct abts_recv_from_24xx *entry = |
| 514 | (struct abts_recv_from_24xx *)pkt; |
| 515 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 516 | entry->vp_index); |
| 517 | if (unlikely(!host)) { |
| 518 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 519 | "qla_target(%d): Response pkt " |
| 520 | "(ABTS_RECV_24XX) received, with unknown " |
| 521 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 522 | break; |
| 523 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 524 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 525 | break; |
| 526 | } |
| 527 | |
| 528 | case ABTS_RESP_24XX: |
| 529 | { |
| 530 | struct abts_resp_to_24xx *entry = |
| 531 | (struct abts_resp_to_24xx *)pkt; |
| 532 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 533 | entry->vp_index); |
| 534 | if (unlikely(!host)) { |
| 535 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 536 | "qla_target(%d): Response pkt " |
| 537 | "(ABTS_RECV_24XX) received, with unknown " |
| 538 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 539 | break; |
| 540 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 541 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 542 | break; |
| 543 | } |
| 544 | |
| 545 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 546 | qlt_response_pkt(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 547 | break; |
| 548 | } |
| 549 | |
| 550 | } |
| 551 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 552 | /* |
| 553 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 554 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 555 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 556 | struct imm_ntfy_from_isp *ntfy, int type) |
| 557 | { |
| 558 | struct qla_work_evt *e; |
| 559 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 560 | if (!e) |
| 561 | return QLA_FUNCTION_FAILED; |
| 562 | |
| 563 | e->u.nack.fcport = fcport; |
| 564 | e->u.nack.type = type; |
| 565 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 566 | return qla2x00_post_work(vha, e); |
| 567 | } |
| 568 | |
| 569 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 570 | void qla2x00_async_nack_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 571 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 572 | struct srb *sp = (struct srb *)s; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 573 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 574 | unsigned long flags; |
| 575 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 576 | ql_dbg(ql_dbg_disc, vha, 0x20f2, |
| 577 | "Async done-%s res %x %8phC type %d\n", |
| 578 | sp->name, res, sp->fcport->port_name, sp->type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 579 | |
| 580 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 581 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 582 | sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 583 | |
| 584 | switch (sp->type) { |
| 585 | case SRB_NACK_PLOGI: |
| 586 | sp->fcport->login_gen++; |
| 587 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 588 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 589 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 590 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 591 | break; |
| 592 | |
| 593 | case SRB_NACK_PRLI: |
| 594 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 595 | sp->fcport->deleted = 0; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 596 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 597 | |
| 598 | if (!sp->fcport->login_succ && |
| 599 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 600 | sp->fcport->login_succ = 1; |
| 601 | |
| 602 | vha->fcport_count++; |
| 603 | |
Quinn Tran | 2952849 | 2018-05-01 09:01:45 -0700 | [diff] [blame] | 604 | ql_dbg(ql_dbg_disc, vha, 0x20f3, |
| 605 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 606 | __func__, __LINE__, |
| 607 | sp->fcport->port_name, |
| 608 | vha->fcport_count); |
| 609 | sp->fcport->disc_state = DSC_UPD_FCPORT; |
| 610 | qla24xx_post_upd_fcport_work(vha, sp->fcport); |
| 611 | } else { |
| 612 | sp->fcport->login_retry = 0; |
| 613 | sp->fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 614 | sp->fcport->deleted = 0; |
| 615 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 616 | } |
| 617 | break; |
| 618 | |
| 619 | case SRB_NACK_LOGO: |
| 620 | sp->fcport->login_gen++; |
| 621 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 622 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 623 | break; |
| 624 | } |
| 625 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 626 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 627 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 631 | struct imm_ntfy_from_isp *ntfy, int type) |
| 632 | { |
| 633 | int rval = QLA_FUNCTION_FAILED; |
| 634 | srb_t *sp; |
| 635 | char *c = NULL; |
| 636 | |
| 637 | fcport->flags |= FCF_ASYNC_SENT; |
| 638 | switch (type) { |
| 639 | case SRB_NACK_PLOGI: |
| 640 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 641 | c = "PLOGI"; |
| 642 | break; |
| 643 | case SRB_NACK_PRLI: |
| 644 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 645 | fcport->deleted = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 646 | c = "PRLI"; |
| 647 | break; |
| 648 | case SRB_NACK_LOGO: |
| 649 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 650 | c = "LOGO"; |
| 651 | break; |
| 652 | } |
| 653 | |
| 654 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 655 | if (!sp) |
| 656 | goto done; |
| 657 | |
| 658 | sp->type = type; |
| 659 | sp->name = "nack"; |
| 660 | |
Ben Hutchings | e74e7d9 | 2018-03-20 21:36:14 +0000 | [diff] [blame] | 661 | sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 662 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 663 | |
| 664 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 665 | sp->done = qla2x00_async_nack_sp_done; |
| 666 | |
| 667 | rval = qla2x00_start_sp(sp); |
| 668 | if (rval != QLA_SUCCESS) |
| 669 | goto done_free_sp; |
| 670 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 671 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
| 672 | "Async-%s %8phC hndl %x %s\n", |
| 673 | sp->name, fcport->port_name, sp->handle, c); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 674 | |
| 675 | return rval; |
| 676 | |
| 677 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 678 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 679 | done: |
| 680 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 681 | return rval; |
| 682 | } |
| 683 | |
| 684 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 685 | { |
| 686 | fc_port_t *t; |
| 687 | unsigned long flags; |
| 688 | |
| 689 | switch (e->u.nack.type) { |
| 690 | case SRB_NACK_PRLI: |
| 691 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 692 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 693 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 694 | if (t) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 695 | ql_log(ql_log_info, vha, 0xd034, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 696 | "%s create sess success %p", __func__, t); |
| 697 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 698 | /* create sess has an extra kref */ |
| 699 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
| 700 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 701 | } |
| 702 | break; |
| 703 | } |
| 704 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
| 705 | (struct imm_ntfy_from_isp*)e->u.nack.iocb, e->u.nack.type); |
| 706 | } |
| 707 | |
| 708 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 709 | { |
| 710 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 711 | struct qla_hw_data *ha = fcport->vha->hw; |
| 712 | unsigned long flags; |
| 713 | |
| 714 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 715 | |
| 716 | if (fcport->se_sess) { |
| 717 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 718 | ha->tgt.tgt_ops->put_sess(fcport); |
| 719 | } else { |
| 720 | qlt_unreg_sess(fcport); |
| 721 | } |
| 722 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 723 | } |
| 724 | |
| 725 | /* |
| 726 | * Called from qla2x00_reg_remote_port() |
| 727 | */ |
| 728 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 729 | { |
| 730 | struct qla_hw_data *ha = vha->hw; |
| 731 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 732 | struct fc_port *sess = fcport; |
| 733 | unsigned long flags; |
| 734 | |
| 735 | if (!vha->hw->tgt.tgt_ops) |
| 736 | return; |
| 737 | |
| 738 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 739 | if (tgt->tgt_stop) { |
| 740 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 745 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 746 | return; |
| 747 | } |
| 748 | |
| 749 | if (!sess->se_sess) { |
| 750 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 751 | |
| 752 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 753 | sess = qlt_create_sess(vha, fcport, false); |
| 754 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 755 | |
| 756 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 757 | } else { |
| 758 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 759 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 760 | return; |
| 761 | } |
| 762 | |
| 763 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 764 | ql_dbg(ql_dbg_disc, vha, 0x2107, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 765 | "%s: kref_get fail sess %8phC \n", |
| 766 | __func__, sess->port_name); |
| 767 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 772 | "qla_target(%u): %ssession for port %8phC " |
| 773 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 774 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 775 | |
| 776 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 777 | "Reappeared sess %p\n", sess); |
| 778 | |
| 779 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 780 | fcport->loop_id, |
| 781 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 782 | } |
| 783 | |
| 784 | if (sess && sess->local) { |
| 785 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 786 | "qla_target(%u): local session for " |
| 787 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 788 | fcport->port_name, sess->loop_id); |
| 789 | sess->local = 0; |
| 790 | } |
| 791 | ha->tgt.tgt_ops->put_sess(sess); |
| 792 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 793 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 794 | |
| 795 | /* |
| 796 | * This is a zero-base ref-counting solution, since hardware_lock |
| 797 | * guarantees that ref_count is not modified concurrently. |
| 798 | * Upon successful return content of iocb is undefined |
| 799 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 800 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 801 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 802 | struct imm_ntfy_from_isp *iocb) |
| 803 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 804 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 805 | |
| 806 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 807 | if (pla->id.b24 == id->b24) { |
| 808 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 809 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 810 | return pla; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 815 | if (!pla) { |
| 816 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 817 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 818 | vha->vp_idx); |
| 819 | return NULL; |
| 820 | } |
| 821 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 822 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 823 | pla->id = *id; |
| 824 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 825 | |
| 826 | return pla; |
| 827 | } |
| 828 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 829 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 830 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 831 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 832 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 833 | port_id_t port_id; |
| 834 | uint16_t loop_id; |
| 835 | fc_port_t *fcport = pla->fcport; |
| 836 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 837 | BUG_ON(!pla->ref_count); |
| 838 | pla->ref_count--; |
| 839 | |
| 840 | if (pla->ref_count) |
| 841 | return; |
| 842 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 843 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 844 | "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] | 845 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 846 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 847 | iocb->u.isp24.port_id[0], |
| 848 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 849 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 850 | |
| 851 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 852 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 853 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 854 | port_id.b.rsvd_1 = 0; |
| 855 | |
| 856 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 857 | |
| 858 | fcport->loop_id = loop_id; |
| 859 | fcport->d_id = port_id; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 860 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 861 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 862 | else |
| 863 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 864 | |
| 865 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 866 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 867 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 868 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 869 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 870 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 871 | |
| 872 | list_del(&pla->list); |
| 873 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 874 | } |
| 875 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 876 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 877 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 878 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 879 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 880 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 881 | /* Inc ref_count first because link might already be pointing at pla */ |
| 882 | pla->ref_count++; |
| 883 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 884 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 885 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 886 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 887 | sess, link, sess->port_name, |
| 888 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 889 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 890 | pla->ref_count, pla, link); |
| 891 | |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 892 | if (link == QLT_PLOGI_LINK_CONFLICT) { |
| 893 | switch (sess->disc_state) { |
| 894 | case DSC_DELETED: |
| 895 | case DSC_DELETE_PEND: |
| 896 | pla->ref_count--; |
| 897 | return; |
| 898 | default: |
| 899 | break; |
| 900 | } |
| 901 | } |
| 902 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 903 | if (sess->plogi_link[link]) |
| 904 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 905 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 906 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 907 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 908 | |
| 909 | sess->plogi_link[link] = pla; |
| 910 | } |
| 911 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 912 | typedef struct { |
| 913 | /* These fields must be initialized by the caller */ |
| 914 | port_id_t id; |
| 915 | /* |
| 916 | * number of cmds dropped while we were waiting for |
| 917 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 918 | * triggered by a command, otherwise, to 0 |
| 919 | */ |
| 920 | int cmd_count; |
| 921 | |
| 922 | /* These fields are used by callee */ |
| 923 | struct list_head list; |
| 924 | } qlt_port_logo_t; |
| 925 | |
| 926 | static void |
| 927 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 928 | { |
| 929 | qlt_port_logo_t *tmp; |
| 930 | int res; |
| 931 | |
| 932 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 933 | |
| 934 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 935 | if (tmp->id.b24 == logo->id.b24) { |
| 936 | tmp->cmd_count += logo->cmd_count; |
| 937 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 938 | return; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | list_add_tail(&logo->list, &vha->logo_list); |
| 943 | |
| 944 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 945 | |
| 946 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 947 | |
| 948 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 949 | list_del(&logo->list); |
| 950 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 951 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 952 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 953 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 954 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 955 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 956 | } |
| 957 | |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 958 | void qlt_free_session_done(struct work_struct *work) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 959 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 960 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 961 | free_work); |
| 962 | struct qla_tgt *tgt = sess->tgt; |
| 963 | struct scsi_qla_host *vha = sess->vha; |
| 964 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 965 | unsigned long flags; |
| 966 | bool logout_started = false; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 967 | scsi_qla_host_t *base_vha; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 968 | struct qlt_plogi_ack_t *own = |
| 969 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 970 | |
| 971 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 972 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 973 | " 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] | 974 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 975 | 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] | 976 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 977 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 978 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 979 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 980 | if (sess->send_els_logo) { |
| 981 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 982 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 983 | logo.id = sess->d_id; |
| 984 | logo.cmd_count = 0; |
Himanshu Madhani | a239034 | 2018-01-22 12:04:20 -0800 | [diff] [blame] | 985 | sess->send_els_logo = 0; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 986 | qlt_send_first_logo(vha, &logo); |
| 987 | } |
| 988 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 989 | if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 990 | int rc; |
| 991 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 992 | if (!own || |
| 993 | (own && |
| 994 | (own->iocb.u.isp24.status_subcode == ELS_PLOGI))) { |
| 995 | rc = qla2x00_post_async_logout_work(vha, sess, |
| 996 | NULL); |
| 997 | if (rc != QLA_SUCCESS) |
| 998 | ql_log(ql_log_warn, vha, 0xf085, |
| 999 | "Schedule logo failed sess %p rc %d\n", |
| 1000 | sess, rc); |
| 1001 | else |
| 1002 | logout_started = true; |
| 1003 | } else if (own && (own->iocb.u.isp24.status_subcode == |
| 1004 | ELS_PRLI) && ha->flags.rida_fmt2) { |
| 1005 | rc = qla2x00_post_async_prlo_work(vha, sess, |
| 1006 | NULL); |
| 1007 | if (rc != QLA_SUCCESS) |
| 1008 | ql_log(ql_log_warn, vha, 0xf085, |
| 1009 | "Schedule PRLO failed sess %p rc %d\n", |
| 1010 | sess, rc); |
| 1011 | else |
| 1012 | logout_started = true; |
| 1013 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1014 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1015 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1016 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1017 | /* |
| 1018 | * Release the target session for FC Nexus from fabric module code. |
| 1019 | */ |
| 1020 | if (sess->se_sess != NULL) |
| 1021 | ha->tgt.tgt_ops->free_session(sess); |
| 1022 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1023 | if (logout_started) { |
| 1024 | bool traced = false; |
| 1025 | |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 1026 | while (!READ_ONCE(sess->logout_completed)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1027 | if (!traced) { |
| 1028 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 1029 | "%s: waiting for sess %p logout\n", |
| 1030 | __func__, sess); |
| 1031 | traced = true; |
| 1032 | } |
| 1033 | msleep(100); |
| 1034 | } |
| 1035 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1036 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1037 | "%s: sess %p logout completed\n", __func__, sess); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | if (sess->logo_ack_needed) { |
| 1041 | sess->logo_ack_needed = 0; |
| 1042 | qla24xx_async_notify_ack(vha, sess, |
| 1043 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1044 | } |
| 1045 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1046 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1047 | if (sess->se_sess) { |
| 1048 | sess->se_sess = NULL; |
| 1049 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 1050 | tgt->sess_count--; |
| 1051 | } |
| 1052 | |
| 1053 | sess->disc_state = DSC_DELETED; |
| 1054 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1055 | sess->deleted = QLA_SESS_DELETED; |
| 1056 | sess->login_retry = vha->hw->login_retry_count; |
| 1057 | |
| 1058 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1059 | vha->fcport_count--; |
| 1060 | sess->login_succ = 0; |
| 1061 | } |
| 1062 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 1063 | qla2x00_clear_loop_id(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1064 | |
| 1065 | if (sess->conflict) { |
| 1066 | sess->conflict->login_pause = 0; |
| 1067 | sess->conflict = NULL; |
| 1068 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1069 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1070 | } |
| 1071 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1072 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1073 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1074 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1075 | struct imm_ntfy_from_isp *iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1076 | |
| 1077 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1078 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1079 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1080 | "se_sess %p / sess %p port %8phC is gone," |
| 1081 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1082 | sess->se_sess, sess, sess->port_name, |
| 1083 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1084 | own ? own->ref_count : -1, |
| 1085 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1086 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1087 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1088 | } else { |
| 1089 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1090 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1091 | sess->se_sess, sess, sess->port_name, |
| 1092 | own ? "releasing own PLOGI" : |
| 1093 | "no own PLOGI pending", |
| 1094 | own ? own->ref_count : -1); |
| 1095 | } |
| 1096 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1097 | if (own) { |
| 1098 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1099 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1100 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1101 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1102 | } |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1103 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1104 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1105 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1106 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1107 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1108 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1109 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1110 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1111 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1112 | |
| 1113 | if (vha->fcport_count == 0) |
| 1114 | wake_up_all(&vha->fcport_waitQ); |
| 1115 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1116 | base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1117 | |
| 1118 | sess->free_pending = 0; |
| 1119 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1120 | if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags)) |
| 1121 | return; |
| 1122 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1123 | if ((!tgt || !tgt->tgt_stop) && !LOOP_TRANSITION(vha)) { |
| 1124 | switch (vha->host->active_mode) { |
| 1125 | case MODE_INITIATOR: |
| 1126 | case MODE_DUAL: |
| 1127 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1128 | qla2xxx_wake_dpc(vha); |
| 1129 | break; |
| 1130 | case MODE_TARGET: |
| 1131 | default: |
| 1132 | /* no-op */ |
| 1133 | break; |
| 1134 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1135 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1138 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1139 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1140 | { |
| 1141 | struct scsi_qla_host *vha = sess->vha; |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1142 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1143 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1144 | ql_dbg(ql_dbg_disc, sess->vha, 0x210a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1145 | "%s sess %p for deletion %8phC\n", |
| 1146 | __func__, sess, sess->port_name); |
| 1147 | |
Quinn Tran | 1ae634e | 2017-12-28 12:33:44 -0800 | [diff] [blame] | 1148 | spin_lock_irqsave(&sess->vha->work_lock, flags); |
| 1149 | if (sess->free_pending) { |
| 1150 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1151 | return; |
| 1152 | } |
| 1153 | sess->free_pending = 1; |
| 1154 | spin_unlock_irqrestore(&sess->vha->work_lock, flags); |
| 1155 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1156 | if (sess->se_sess) |
| 1157 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1158 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1159 | qla2x00_mark_device_lost(vha, sess, 1, 1); |
| 1160 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1161 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1162 | sess->disc_state = DSC_DELETE_PEND; |
| 1163 | sess->last_rscn_gen = sess->rscn_gen; |
| 1164 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1165 | |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 1166 | if (sess->nvme_flag & NVME_FLAG_REGISTERED && |
| 1167 | !(sess->nvme_flag & NVME_FLAG_DELETING)) { |
| 1168 | sess->nvme_flag |= NVME_FLAG_DELETING; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1169 | schedule_work(&sess->nvme_del_work); |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame] | 1170 | } else { |
| 1171 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 1172 | schedule_work(&sess->free_work); |
| 1173 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1174 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1175 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1176 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1177 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1178 | { |
| 1179 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1180 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1181 | uint16_t loop_id; |
| 1182 | int res = 0; |
| 1183 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1184 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1185 | |
| 1186 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1187 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1188 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1189 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1190 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1191 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1192 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1193 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1194 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1195 | 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] | 1196 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1200 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1201 | if (!sess) { |
| 1202 | res = -ESRCH; |
| 1203 | return res; |
| 1204 | } |
| 1205 | |
| 1206 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1207 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1208 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1209 | mcmd, loop_id); |
| 1210 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1211 | 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] | 1212 | } |
| 1213 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1214 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1215 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1216 | if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1217 | sess->logout_on_delete = 0; |
| 1218 | sess->logo_ack_needed = 0; |
| 1219 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1220 | sess->scan_state = 0; |
| 1221 | } |
| 1222 | } |
| 1223 | |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1224 | void qlt_schedule_sess_for_deletion(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1225 | { |
| 1226 | struct qla_tgt *tgt = sess->tgt; |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1227 | struct qla_hw_data *ha = sess->vha->hw; |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1228 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1229 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1230 | if (sess->disc_state == DSC_DELETE_PEND) |
| 1231 | return; |
| 1232 | |
| 1233 | if (sess->disc_state == DSC_DELETED) { |
| 1234 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1235 | wake_up_all(&tgt->waitQ); |
| 1236 | if (sess->vha->fcport_count == 0) |
| 1237 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1238 | |
| 1239 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1240 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1241 | return; |
| 1242 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1243 | |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1244 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1245 | if (sess->deleted == QLA_SESS_DELETED) |
| 1246 | sess->logout_on_delete = 0; |
| 1247 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1248 | if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) { |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1249 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1250 | return; |
| 1251 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1252 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1253 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1254 | |
| 1255 | sess->disc_state = DSC_DELETE_PEND; |
| 1256 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1257 | qla24xx_chk_fcp_state(sess); |
| 1258 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1259 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
| 1260 | "Scheduling sess %p for deletion\n", sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1261 | |
Quinn Tran | a01c77d | 2017-12-04 14:44:58 -0800 | [diff] [blame] | 1262 | INIT_WORK(&sess->del_work, qla24xx_delete_sess_fn); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1263 | WARN_ON(!queue_work(sess->vha->hw->wq, &sess->del_work)); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1264 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1265 | |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1266 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1267 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1268 | struct fc_port *sess; |
| 1269 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1270 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1271 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1272 | if (sess->se_sess) |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1273 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1274 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1275 | |
| 1276 | /* At this point tgt could be already dead */ |
| 1277 | } |
| 1278 | |
| 1279 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 1280 | uint16_t *loop_id) |
| 1281 | { |
| 1282 | struct qla_hw_data *ha = vha->hw; |
| 1283 | dma_addr_t gid_list_dma; |
| 1284 | struct gid_list_info *gid_list; |
| 1285 | char *id_iter; |
| 1286 | int res, rc, i; |
| 1287 | uint16_t entries; |
| 1288 | |
| 1289 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1290 | &gid_list_dma, GFP_KERNEL); |
| 1291 | if (!gid_list) { |
| 1292 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1293 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1294 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1295 | return -ENOMEM; |
| 1296 | } |
| 1297 | |
| 1298 | /* Get list of logged in devices */ |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1299 | rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1300 | if (rc != QLA_SUCCESS) { |
| 1301 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1302 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1303 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1304 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1305 | goto out_free_id_list; |
| 1306 | } |
| 1307 | |
| 1308 | id_iter = (char *)gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1309 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1310 | for (i = 0; i < entries; i++) { |
| 1311 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; |
| 1312 | if ((gid->al_pa == s_id[2]) && |
| 1313 | (gid->area == s_id[1]) && |
| 1314 | (gid->domain == s_id[0])) { |
| 1315 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1316 | res = 0; |
| 1317 | break; |
| 1318 | } |
| 1319 | id_iter += ha->gid_list_info_size; |
| 1320 | } |
| 1321 | |
| 1322 | out_free_id_list: |
| 1323 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1324 | gid_list, gid_list_dma); |
| 1325 | return res; |
| 1326 | } |
| 1327 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1328 | /* |
| 1329 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1330 | * Caller must put it. |
| 1331 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1332 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1333 | struct scsi_qla_host *vha, |
| 1334 | fc_port_t *fcport, |
| 1335 | bool local) |
| 1336 | { |
| 1337 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1338 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1339 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1340 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1341 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1342 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1343 | |
| 1344 | if (fcport->se_sess) { |
| 1345 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1346 | ql_dbg(ql_dbg_disc, vha, 0x20f6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1347 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1348 | __func__, sess->port_name); |
| 1349 | return NULL; |
| 1350 | } |
| 1351 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1352 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1353 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1354 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1355 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1356 | /* |
| 1357 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1358 | * session eventually ends and release corresponding nport handle. |
| 1359 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1360 | * code will adjust these flags as necessary. |
| 1361 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1362 | sess->logout_on_delete = 1; |
| 1363 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1364 | sess->logout_completed = 0; |
| 1365 | |
| 1366 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1367 | &fcport->port_name[0], sess) < 0) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1368 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1369 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1370 | vha->vp_idx, fcport->port_name); |
| 1371 | return NULL; |
| 1372 | } else { |
| 1373 | kref_init(&fcport->sess_kref); |
| 1374 | /* |
| 1375 | * Take an extra reference to ->sess_kref here to handle |
| 1376 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1377 | */ |
| 1378 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1379 | ql_dbg(ql_dbg_disc, vha, 0x20f7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1380 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1381 | __func__, sess->port_name); |
| 1382 | return NULL; |
| 1383 | } |
| 1384 | |
| 1385 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1386 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1387 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1388 | |
| 1389 | qlt_do_generation_tick(vha, &sess->generation); |
| 1390 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1391 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1392 | |
| 1393 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1394 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1395 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1396 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1397 | |
| 1398 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1399 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1400 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1401 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1402 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1403 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1404 | |
| 1405 | return sess; |
| 1406 | } |
| 1407 | |
| 1408 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1409 | * max_gen - specifies maximum session generation |
| 1410 | * at which this deletion requestion is still valid |
| 1411 | */ |
| 1412 | void |
| 1413 | 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] | 1414 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1415 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1416 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1417 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1418 | |
| 1419 | if (!vha->hw->tgt.tgt_ops) |
| 1420 | return; |
| 1421 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1422 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1423 | return; |
| 1424 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1425 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1426 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1427 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1428 | return; |
| 1429 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1430 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1431 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1432 | return; |
| 1433 | } |
| 1434 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1435 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1436 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1437 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1438 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1439 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1440 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1441 | sess->generation); |
| 1442 | return; |
| 1443 | } |
| 1444 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1445 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1446 | |
| 1447 | sess->local = 1; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1448 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Hannes Reinecke | 1c6cacf | 2018-02-22 09:49:35 +0100 | [diff] [blame] | 1449 | qlt_schedule_sess_for_deletion(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1453 | { |
| 1454 | struct qla_hw_data *ha = tgt->ha; |
| 1455 | unsigned long flags; |
| 1456 | int res; |
| 1457 | /* |
| 1458 | * We need to protect against race, when tgt is freed before or |
| 1459 | * inside wake_up() |
| 1460 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1461 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1462 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1463 | "tgt %p, sess_count=%d\n", |
| 1464 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1465 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1466 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1467 | |
| 1468 | return res; |
| 1469 | } |
| 1470 | |
| 1471 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1472 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1473 | { |
| 1474 | struct scsi_qla_host *vha = tgt->vha; |
| 1475 | struct qla_hw_data *ha = tgt->ha; |
| 1476 | unsigned long flags; |
| 1477 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1478 | mutex_lock(&qla_tgt_mutex); |
| 1479 | if (!vha->fc_vport) { |
| 1480 | struct Scsi_Host *sh = vha->host; |
| 1481 | struct fc_host_attrs *fc_host = shost_to_fc_host(sh); |
| 1482 | bool npiv_vports; |
| 1483 | |
| 1484 | spin_lock_irqsave(sh->host_lock, flags); |
| 1485 | npiv_vports = (fc_host->npiv_vports_inuse); |
| 1486 | spin_unlock_irqrestore(sh->host_lock, flags); |
| 1487 | |
| 1488 | if (npiv_vports) { |
| 1489 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1490 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, |
| 1491 | "NPIV is in use. Can not stop target\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1492 | return -EPERM; |
| 1493 | } |
| 1494 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1495 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1496 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1497 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1498 | mutex_unlock(&qla_tgt_mutex); |
| 1499 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1500 | } |
| 1501 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1502 | 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] | 1503 | vha->host_no, vha); |
| 1504 | /* |
| 1505 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1506 | * Lock is needed, because we still can get an incoming packet. |
| 1507 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1508 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1509 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1510 | qlt_clear_tgt_db(tgt); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1511 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1512 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1513 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1514 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1515 | "Waiting for sess works (tgt %p)", tgt); |
| 1516 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1517 | while (!list_empty(&tgt->sess_works_list)) { |
| 1518 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1519 | flush_scheduled_work(); |
| 1520 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1521 | } |
| 1522 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1523 | |
| 1524 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1525 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1526 | |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1527 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1528 | |
| 1529 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1530 | if (!ha->flags.host_shutting_down && |
| 1531 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1532 | qlt_disable_vha(vha); |
| 1533 | |
| 1534 | /* Wait for sessions to clear out (just in case) */ |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1535 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1536 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1537 | } |
| 1538 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1539 | |
| 1540 | /* Called by tcm_qla2xxx configfs code */ |
| 1541 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1542 | { |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1543 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1544 | |
| 1545 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1546 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1547 | "Already in tgt->tgt_stopped state\n"); |
| 1548 | dump_stack(); |
| 1549 | return; |
| 1550 | } |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1551 | if (!tgt->tgt_stop) { |
| 1552 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
| 1553 | "%s: phase1 stop is not completed\n", __func__); |
| 1554 | dump_stack(); |
| 1555 | return; |
| 1556 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1557 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1558 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1559 | tgt->tgt_stop = 0; |
| 1560 | tgt->tgt_stopped = 1; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1561 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1562 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1563 | 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] | 1564 | tgt); |
| 1565 | } |
| 1566 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1567 | |
| 1568 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1569 | static void qlt_release(struct qla_tgt *tgt) |
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 | scsi_qla_host_t *vha = tgt->vha; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1572 | void *node; |
| 1573 | u64 key = 0; |
| 1574 | u16 i; |
| 1575 | struct qla_qpair_hint *h; |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1576 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1577 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1578 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stop && |
| 1579 | !tgt->tgt_stopped) |
| 1580 | qlt_stop_phase1(tgt); |
| 1581 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1582 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1583 | qlt_stop_phase2(tgt); |
| 1584 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1585 | for (i = 0; i < vha->hw->max_qpairs + 1; i++) { |
| 1586 | unsigned long flags; |
| 1587 | |
| 1588 | h = &tgt->qphints[i]; |
| 1589 | if (h->qpair) { |
| 1590 | spin_lock_irqsave(h->qpair->qp_lock_ptr, flags); |
| 1591 | list_del(&h->hint_elem); |
| 1592 | spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags); |
| 1593 | h->qpair = NULL; |
| 1594 | } |
| 1595 | } |
| 1596 | kfree(tgt->qphints); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1597 | mutex_lock(&qla_tgt_mutex); |
| 1598 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
| 1599 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1600 | |
| 1601 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 1602 | btree_remove64(&tgt->lun_qpair_map, key); |
| 1603 | |
| 1604 | btree_destroy64(&tgt->lun_qpair_map); |
| 1605 | |
Sawan Chandak | 3be63b1e | 2017-12-04 14:45:04 -0800 | [diff] [blame] | 1606 | if (vha->vp_idx) |
| 1607 | if (ha->tgt.tgt_ops && |
| 1608 | ha->tgt.tgt_ops->remove_target && |
| 1609 | vha->vha_tgt.target_lport_ptr) |
| 1610 | ha->tgt.tgt_ops->remove_target(vha); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1611 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1612 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1613 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1614 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1615 | "Release of tgt %p finished\n", tgt); |
| 1616 | |
| 1617 | kfree(tgt); |
| 1618 | } |
| 1619 | |
| 1620 | /* ha->hardware_lock supposed to be held on entry */ |
| 1621 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1622 | const void *param, unsigned int param_size) |
| 1623 | { |
| 1624 | struct qla_tgt_sess_work_param *prm; |
| 1625 | unsigned long flags; |
| 1626 | |
| 1627 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1628 | if (!prm) { |
| 1629 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1630 | "qla_target(%d): Unable to create session " |
| 1631 | "work, command will be refused", 0); |
| 1632 | return -ENOMEM; |
| 1633 | } |
| 1634 | |
| 1635 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1636 | "Scheduling work (type %d, prm %p)" |
| 1637 | " to find session for param %p (size %d, tgt %p)\n", |
| 1638 | type, prm, param, param_size, tgt); |
| 1639 | |
| 1640 | prm->type = type; |
| 1641 | memcpy(&prm->tm_iocb, param, param_size); |
| 1642 | |
| 1643 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1644 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1645 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1646 | |
| 1647 | schedule_work(&tgt->sess_work); |
| 1648 | |
| 1649 | return 0; |
| 1650 | } |
| 1651 | |
| 1652 | /* |
| 1653 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1654 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1655 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1656 | struct imm_ntfy_from_isp *ntfy, |
| 1657 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1658 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1659 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1660 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1661 | struct qla_hw_data *ha = vha->hw; |
| 1662 | request_t *pkt; |
| 1663 | struct nack_to_isp *nack; |
| 1664 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 1665 | if (!ha->flags.fw_started) |
| 1666 | return; |
| 1667 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1668 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1669 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1670 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1671 | if (!pkt) { |
| 1672 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1673 | "qla_target(%d): %s failed: unable to allocate " |
| 1674 | "request packet\n", vha->vp_idx, __func__); |
| 1675 | return; |
| 1676 | } |
| 1677 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1678 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1679 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1680 | |
| 1681 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1682 | pkt->entry_count = 1; |
| 1683 | |
| 1684 | nack = (struct nack_to_isp *)pkt; |
| 1685 | nack->ox_id = ntfy->ox_id; |
| 1686 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1687 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1688 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1689 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1690 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1691 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1692 | } |
| 1693 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1694 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1695 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1696 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1697 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1698 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1699 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1700 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1701 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1702 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1703 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1704 | |
| 1705 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1706 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1707 | vha->vp_idx, nack->u.isp24.status); |
| 1708 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1709 | /* Memory Barrier */ |
| 1710 | wmb(); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1711 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | /* |
| 1715 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1716 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1717 | static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1718 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1719 | bool ids_reversed) |
| 1720 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1721 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1722 | struct qla_hw_data *ha = vha->hw; |
| 1723 | struct abts_resp_to_24xx *resp; |
| 1724 | uint32_t f_ctl; |
| 1725 | uint8_t *p; |
| 1726 | |
| 1727 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1728 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1729 | ha, abts, status); |
| 1730 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1731 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, |
| 1732 | NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1733 | if (!resp) { |
| 1734 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1735 | "qla_target(%d): %s failed: unable to allocate " |
| 1736 | "request packet", vha->vp_idx, __func__); |
| 1737 | return; |
| 1738 | } |
| 1739 | |
| 1740 | resp->entry_type = ABTS_RESP_24XX; |
| 1741 | resp->entry_count = 1; |
| 1742 | resp->nport_handle = abts->nport_handle; |
| 1743 | resp->vp_index = vha->vp_idx; |
| 1744 | resp->sof_type = abts->sof_type; |
| 1745 | resp->exchange_address = abts->exchange_address; |
| 1746 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1747 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1748 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1749 | F_CTL_SEQ_INITIATIVE); |
| 1750 | p = (uint8_t *)&f_ctl; |
| 1751 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1752 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1753 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1754 | if (ids_reversed) { |
| 1755 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1756 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1757 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1758 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1759 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1760 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1761 | } else { |
| 1762 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1763 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1764 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1765 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1766 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1767 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1768 | } |
| 1769 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1770 | if (status == FCP_TMF_CMPL) { |
| 1771 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1772 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1773 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1774 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1775 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1776 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1777 | } else { |
| 1778 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1779 | resp->payload.ba_rjt.reason_code = |
| 1780 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1781 | /* Other bytes are zero */ |
| 1782 | } |
| 1783 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1784 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1785 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1786 | /* Memory Barrier */ |
| 1787 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 1788 | if (qpair->reqq_start_iocbs) |
| 1789 | qpair->reqq_start_iocbs(qpair); |
| 1790 | else |
| 1791 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | /* |
| 1795 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1796 | */ |
| 1797 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
| 1798 | struct abts_resp_from_24xx_fw *entry) |
| 1799 | { |
| 1800 | struct ctio7_to_24xx *ctio; |
| 1801 | |
| 1802 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1803 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1804 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1805 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready( |
| 1806 | vha->hw->base_qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1807 | if (ctio == NULL) { |
| 1808 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1809 | "qla_target(%d): %s failed: unable to allocate " |
| 1810 | "request packet\n", vha->vp_idx, __func__); |
| 1811 | return; |
| 1812 | } |
| 1813 | |
| 1814 | /* |
| 1815 | * We've got on entrance firmware's response on by us generated |
| 1816 | * ABTS response. So, in it ID fields are reversed. |
| 1817 | */ |
| 1818 | |
| 1819 | ctio->entry_type = CTIO_TYPE7; |
| 1820 | ctio->entry_count = 1; |
| 1821 | ctio->nport_handle = entry->nport_handle; |
| 1822 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1823 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1824 | ctio->vp_index = vha->vp_idx; |
| 1825 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1826 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1827 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1828 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1829 | ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
| 1830 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1831 | ctio->u.status1.ox_id = cpu_to_le16(entry->fcp_hdr_le.ox_id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1832 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1833 | /* Memory Barrier */ |
| 1834 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1835 | qla2x00_start_iocbs(vha, vha->req); |
| 1836 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1837 | qlt_24xx_send_abts_resp(vha->hw->base_qpair, |
| 1838 | (struct abts_recv_from_24xx *)entry, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1839 | FCP_TMF_CMPL, true); |
| 1840 | } |
| 1841 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1842 | static int abort_cmd_for_tag(struct scsi_qla_host *vha, uint32_t tag) |
| 1843 | { |
| 1844 | struct qla_tgt_sess_op *op; |
| 1845 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1846 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1847 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1848 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1849 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1850 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1851 | op->aborted = true; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1852 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1853 | return 1; |
| 1854 | } |
| 1855 | } |
| 1856 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1857 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1858 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1859 | op->aborted = true; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1860 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1861 | return 1; |
| 1862 | } |
| 1863 | } |
| 1864 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1865 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1866 | if (tag == cmd->atio.u.isp24.exchange_addr) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1867 | cmd->aborted = 1; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1868 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1869 | return 1; |
| 1870 | } |
| 1871 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1872 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1873 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1874 | return 0; |
| 1875 | } |
| 1876 | |
| 1877 | /* drop cmds for the given lun |
| 1878 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1879 | * XXX does not go through the list of other port (which may have cmds |
| 1880 | * for the same lun) |
| 1881 | */ |
| 1882 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1883 | u64 lun, uint8_t *s_id) |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1884 | { |
| 1885 | struct qla_tgt_sess_op *op; |
| 1886 | struct qla_tgt_cmd *cmd; |
| 1887 | uint32_t key; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1888 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1889 | |
| 1890 | key = sid_to_key(s_id); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1891 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1892 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1893 | uint32_t op_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1894 | u64 op_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1895 | |
| 1896 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1897 | op_lun = scsilun_to_int( |
| 1898 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1899 | if (op_key == key && op_lun == lun) |
| 1900 | op->aborted = true; |
| 1901 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1902 | |
| 1903 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1904 | uint32_t op_key; |
| 1905 | u64 op_lun; |
| 1906 | |
| 1907 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1908 | op_lun = scsilun_to_int( |
| 1909 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1910 | if (op_key == key && op_lun == lun) |
| 1911 | op->aborted = true; |
| 1912 | } |
| 1913 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1914 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1915 | uint32_t cmd_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1916 | u64 cmd_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1917 | |
| 1918 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1919 | cmd_lun = scsilun_to_int( |
| 1920 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 1921 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1922 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1923 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1924 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1925 | } |
| 1926 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1927 | /* ha->hardware_lock supposed to be held on entry */ |
| 1928 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1929 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1930 | { |
| 1931 | struct qla_hw_data *ha = vha->hw; |
| 1932 | struct qla_tgt_mgmt_cmd *mcmd; |
| 1933 | int rc; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1934 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 1935 | if (abort_cmd_for_tag(vha, abts->exchange_addr_to_abort)) { |
| 1936 | /* send TASK_ABORT response immediately */ |
Linus Torvalds | 48ea2ce | 2017-07-13 14:27:32 -0700 | [diff] [blame] | 1937 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_CMPL, false); |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 1938 | return 0; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1939 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1940 | |
| 1941 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 1942 | "qla_target(%d): task abort (tag=%d)\n", |
| 1943 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 1944 | |
| 1945 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 1946 | if (mcmd == NULL) { |
| 1947 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 1948 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 1949 | vha->vp_idx, __func__); |
| 1950 | return -ENOMEM; |
| 1951 | } |
| 1952 | memset(mcmd, 0, sizeof(*mcmd)); |
| 1953 | |
| 1954 | mcmd->sess = sess; |
| 1955 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1956 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 1957 | mcmd->tmr_func = QLA_TGT_ABTS; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1958 | mcmd->qpair = ha->base_qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 1959 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1960 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 1961 | /* |
| 1962 | * LUN is looked up by target-core internally based on the passed |
| 1963 | * abts->exchange_addr_to_abort tag. |
| 1964 | */ |
| 1965 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, 0, mcmd->tmr_func, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1966 | abts->exchange_addr_to_abort); |
| 1967 | if (rc != 0) { |
| 1968 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, |
| 1969 | "qla_target(%d): tgt_ops->handle_tmr()" |
| 1970 | " failed: %d", vha->vp_idx, rc); |
| 1971 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 1972 | return -EFAULT; |
| 1973 | } |
| 1974 | |
| 1975 | return 0; |
| 1976 | } |
| 1977 | |
| 1978 | /* |
| 1979 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1980 | */ |
| 1981 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 1982 | struct abts_recv_from_24xx *abts) |
| 1983 | { |
| 1984 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1985 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1986 | uint32_t tag = abts->exchange_addr_to_abort; |
| 1987 | uint8_t s_id[3]; |
| 1988 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1989 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1990 | |
| 1991 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 1992 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 1993 | "qla_target(%d): ABTS: Abort Sequence not " |
| 1994 | "supported\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1995 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 1996 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1997 | return; |
| 1998 | } |
| 1999 | |
| 2000 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 2001 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 2002 | "qla_target(%d): ABTS: Unknown Exchange " |
| 2003 | "Address received\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2004 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2005 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2006 | return; |
| 2007 | } |
| 2008 | |
| 2009 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 2010 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 2011 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 2012 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 2013 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 2014 | |
| 2015 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 2016 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 2017 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 2018 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2019 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2020 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 2021 | if (!sess) { |
| 2022 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
Colin Ian King | 03fea73 | 2018-03-19 10:53:41 +0000 | [diff] [blame] | 2023 | "qla_target(%d): task abort for non-existent session\n", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2024 | vha->vp_idx); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2025 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2026 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 2027 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2028 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2029 | return; |
| 2030 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2031 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2032 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2033 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2034 | if (sess->deleted) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2035 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2036 | false); |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 2037 | return; |
| 2038 | } |
| 2039 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2040 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 2041 | if (rc != 0) { |
| 2042 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 2043 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 2044 | vha->vp_idx, rc); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2045 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2046 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2047 | return; |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | /* |
| 2052 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2053 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2054 | static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2055 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 2056 | { |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2057 | struct scsi_qla_host *ha = mcmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2058 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 2059 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2060 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2061 | |
| 2062 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 2063 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 2064 | ha, atio, resp_code); |
| 2065 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2066 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2067 | ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2068 | if (ctio == NULL) { |
| 2069 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 2070 | "qla_target(%d): %s failed: unable to allocate " |
| 2071 | "request packet\n", ha->vp_idx, __func__); |
| 2072 | return; |
| 2073 | } |
| 2074 | |
| 2075 | ctio->entry_type = CTIO_TYPE7; |
| 2076 | ctio->entry_count = 1; |
| 2077 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 2078 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2079 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2080 | ctio->vp_index = ha->vp_idx; |
| 2081 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2082 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2083 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2084 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2085 | temp = (atio->u.isp24.attr << 9)| |
| 2086 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2087 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2088 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2089 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2090 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2091 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2092 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2093 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2094 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2095 | /* Memory Barrier */ |
| 2096 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2097 | if (qpair->reqq_start_iocbs) |
| 2098 | qpair->reqq_start_iocbs(qpair); |
| 2099 | else |
| 2100 | qla2x00_start_iocbs(ha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2104 | { |
| 2105 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2106 | } |
| 2107 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2108 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2109 | /* |
| 2110 | * ha->hardware_lock supposed to be held on entry. Might drop it, then |
| 2111 | * reacquire |
| 2112 | */ |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2113 | 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] | 2114 | uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq) |
| 2115 | { |
| 2116 | struct atio_from_isp *atio = &cmd->atio; |
| 2117 | struct ctio7_to_24xx *ctio; |
| 2118 | uint16_t temp; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2119 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2120 | |
| 2121 | ql_dbg(ql_dbg_tgt_dif, vha, 0x3066, |
| 2122 | "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, " |
| 2123 | "sense_key=%02x, asc=%02x, ascq=%02x", |
| 2124 | vha, atio, scsi_status, sense_key, asc, ascq); |
| 2125 | |
| 2126 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); |
| 2127 | if (!ctio) { |
| 2128 | ql_dbg(ql_dbg_async, vha, 0x3067, |
| 2129 | "qla2x00t(%ld): %s failed: unable to allocate request packet", |
| 2130 | vha->host_no, __func__); |
| 2131 | goto out; |
| 2132 | } |
| 2133 | |
| 2134 | ctio->entry_type = CTIO_TYPE7; |
| 2135 | ctio->entry_count = 1; |
| 2136 | ctio->handle = QLA_TGT_SKIP_HANDLE; |
| 2137 | ctio->nport_handle = cmd->sess->loop_id; |
| 2138 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
| 2139 | ctio->vp_index = vha->vp_idx; |
| 2140 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2141 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2142 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2143 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2144 | temp = (atio->u.isp24.attr << 9) | |
| 2145 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2146 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2147 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2148 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
| 2149 | ctio->u.status1.scsi_status = |
| 2150 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status); |
| 2151 | ctio->u.status1.response_len = cpu_to_le16(18); |
| 2152 | ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
| 2153 | |
| 2154 | if (ctio->u.status1.residual != 0) |
| 2155 | ctio->u.status1.scsi_status |= |
| 2156 | cpu_to_le16(SS_RESIDUAL_UNDER); |
| 2157 | |
| 2158 | /* Response code and sense key */ |
| 2159 | put_unaligned_le32(((0x70 << 24) | (sense_key << 8)), |
| 2160 | (&ctio->u.status1.sense_data)[0]); |
| 2161 | /* Additional sense length */ |
| 2162 | put_unaligned_le32(0x0a, (&ctio->u.status1.sense_data)[1]); |
| 2163 | /* ASC and ASCQ */ |
| 2164 | put_unaligned_le32(((asc << 24) | (ascq << 16)), |
| 2165 | (&ctio->u.status1.sense_data)[3]); |
| 2166 | |
| 2167 | /* Memory Barrier */ |
| 2168 | wmb(); |
| 2169 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2170 | if (qpair->reqq_start_iocbs) |
| 2171 | qpair->reqq_start_iocbs(qpair); |
| 2172 | else |
| 2173 | qla2x00_start_iocbs(vha, qpair->req); |
| 2174 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2175 | out: |
| 2176 | return; |
| 2177 | } |
| 2178 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2179 | /* callback from target fabric module code */ |
| 2180 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2181 | { |
| 2182 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2183 | struct qla_hw_data *ha = vha->hw; |
| 2184 | unsigned long flags; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2185 | struct qla_qpair *qpair = mcmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2186 | |
| 2187 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2188 | "TM response mcmd (%p) status %#x state %#x", |
| 2189 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2190 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2191 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2192 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2193 | if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2194 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2195 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2196 | * previous life, just abort the processing. |
| 2197 | */ |
| 2198 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2199 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2200 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2201 | mcmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2202 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2203 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2204 | return; |
| 2205 | } |
| 2206 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2207 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
| 2208 | if (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2209 | ELS_LOGO || |
| 2210 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2211 | ELS_PRLO || |
| 2212 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2213 | ELS_TPRLO) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2214 | ql_dbg(ql_dbg_disc, vha, 0x2106, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2215 | "TM response logo %phC status %#x state %#x", |
| 2216 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2217 | mcmd->flags); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 2218 | qlt_schedule_sess_for_deletion(mcmd->sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2219 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2220 | qlt_send_notify_ack(vha->hw->base_qpair, |
| 2221 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2222 | } |
| 2223 | } else { |
Swapnil Nagle | d7236ac | 2016-02-04 11:45:17 -0500 | [diff] [blame] | 2224 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2225 | qlt_24xx_send_abts_resp(qpair, &mcmd->orig_iocb.abts, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2226 | mcmd->fc_tm_rsp, false); |
| 2227 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2228 | qlt_24xx_send_task_mgmt_ctio(qpair, mcmd, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2229 | mcmd->fc_tm_rsp); |
| 2230 | } |
| 2231 | /* |
| 2232 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2233 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2234 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2235 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2236 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2237 | * qlt_xmit_tm_rsp() returns here.. |
| 2238 | */ |
| 2239 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2240 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2241 | } |
| 2242 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2243 | |
| 2244 | /* No locks */ |
| 2245 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2246 | { |
| 2247 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2248 | |
| 2249 | BUG_ON(cmd->sg_cnt == 0); |
| 2250 | |
| 2251 | prm->sg = (struct scatterlist *)cmd->sg; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2252 | prm->seg_cnt = pci_map_sg(cmd->qpair->pdev, cmd->sg, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2253 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2254 | if (unlikely(prm->seg_cnt == 0)) |
| 2255 | goto out_err; |
| 2256 | |
| 2257 | prm->cmd->sg_mapped = 1; |
| 2258 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2259 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2260 | /* |
| 2261 | * If greater than four sg entries then we need to allocate |
| 2262 | * the continuation entries |
| 2263 | */ |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2264 | if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2265 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2266 | QLA_TGT_DATASEGS_PER_CMD_24XX, |
| 2267 | QLA_TGT_DATASEGS_PER_CONT_24XX); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2268 | } else { |
| 2269 | /* DIF */ |
| 2270 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2271 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2272 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2273 | prm->tot_dsds = prm->seg_cnt; |
| 2274 | } else |
| 2275 | prm->tot_dsds = prm->seg_cnt; |
| 2276 | |
| 2277 | if (cmd->prot_sg_cnt) { |
| 2278 | prm->prot_sg = cmd->prot_sg; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2279 | prm->prot_seg_cnt = pci_map_sg(cmd->qpair->pdev, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2280 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2281 | cmd->dma_data_direction); |
| 2282 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2283 | goto out_err; |
| 2284 | |
| 2285 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2286 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2287 | /* Dif Bundling not support here */ |
| 2288 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2289 | cmd->blk_sz); |
| 2290 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2291 | } else |
| 2292 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2293 | } |
| 2294 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2295 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2296 | return 0; |
| 2297 | |
| 2298 | out_err: |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2299 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2300 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2301 | 0, prm->cmd->sg_cnt); |
| 2302 | return -1; |
| 2303 | } |
| 2304 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2305 | 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] | 2306 | { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2307 | struct qla_hw_data *ha; |
| 2308 | struct qla_qpair *qpair; |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2309 | if (!cmd->sg_mapped) |
| 2310 | return; |
| 2311 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2312 | qpair = cmd->qpair; |
| 2313 | |
| 2314 | pci_unmap_sg(qpair->pdev, cmd->sg, cmd->sg_cnt, |
| 2315 | cmd->dma_data_direction); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2316 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2317 | |
| 2318 | if (cmd->prot_sg_cnt) |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2319 | pci_unmap_sg(qpair->pdev, cmd->prot_sg, cmd->prot_sg_cnt, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2320 | cmd->dma_data_direction); |
| 2321 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2322 | if (!cmd->ctx) |
| 2323 | return; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2324 | ha = vha->hw; |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2325 | if (cmd->ctx_dsd_alloced) |
| 2326 | qla2x00_clean_dsd_pool(ha, cmd->ctx); |
| 2327 | |
| 2328 | 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] | 2329 | } |
| 2330 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2331 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2332 | uint32_t req_cnt) |
| 2333 | { |
Quinn Tran | d63b328 | 2017-06-02 09:12:07 -0700 | [diff] [blame] | 2334 | uint32_t cnt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2335 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2336 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2337 | if (req->cnt < (req_cnt + 2)) { |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 2338 | cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr : |
| 2339 | RD_REG_DWORD_RELAXED(req->req_q_out)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2340 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2341 | if (req->ring_index < cnt) |
| 2342 | req->cnt = cnt - req->ring_index; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2343 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2344 | req->cnt = req->length - (req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2345 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2346 | if (unlikely(req->cnt < (req_cnt + 2))) |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2347 | return -EAGAIN; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2348 | } |
| 2349 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2350 | req->cnt -= req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2351 | |
| 2352 | return 0; |
| 2353 | } |
| 2354 | |
| 2355 | /* |
| 2356 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2357 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2358 | static inline void *qlt_get_req_pkt(struct req_que *req) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2359 | { |
| 2360 | /* Adjust ring index. */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2361 | req->ring_index++; |
| 2362 | if (req->ring_index == req->length) { |
| 2363 | req->ring_index = 0; |
| 2364 | req->ring_ptr = req->ring; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2365 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2366 | req->ring_ptr++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2367 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2368 | return (cont_entry_t *)req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2372 | static inline uint32_t qlt_make_handle(struct qla_qpair *qpair) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2373 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2374 | uint32_t h; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2375 | int index; |
| 2376 | uint8_t found = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2377 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2378 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2379 | h = req->current_outstanding_cmd; |
| 2380 | |
| 2381 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 2382 | h++; |
| 2383 | if (h == req->num_outstanding_cmds) |
| 2384 | h = 1; |
| 2385 | |
| 2386 | if (h == QLA_TGT_SKIP_HANDLE) |
| 2387 | continue; |
| 2388 | |
| 2389 | if (!req->outstanding_cmds[h]) { |
| 2390 | found = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2391 | break; |
| 2392 | } |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2393 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2394 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2395 | if (found) { |
| 2396 | req->current_outstanding_cmd = h; |
| 2397 | } else { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2398 | ql_dbg(ql_dbg_io, qpair->vha, 0x305b, |
| 2399 | "qla_target(%d): Ran out of empty cmd slots\n", |
| 2400 | qpair->vha->vp_idx); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2401 | h = QLA_TGT_NULL_HANDLE; |
| 2402 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2403 | |
| 2404 | return h; |
| 2405 | } |
| 2406 | |
| 2407 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2408 | static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair, |
| 2409 | struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2410 | { |
| 2411 | uint32_t h; |
| 2412 | struct ctio7_to_24xx *pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2413 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2414 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2415 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2416 | pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2417 | prm->pkt = pkt; |
| 2418 | memset(pkt, 0, sizeof(*pkt)); |
| 2419 | |
| 2420 | pkt->entry_type = CTIO_TYPE7; |
| 2421 | pkt->entry_count = (uint8_t)prm->req_cnt; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2422 | pkt->vp_index = prm->cmd->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2423 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2424 | h = qlt_make_handle(qpair); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2425 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2426 | /* |
| 2427 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2428 | * know the initiator's LOOP ID, hence we can't find |
| 2429 | * the session and, so, the command. |
| 2430 | */ |
| 2431 | return -EAGAIN; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 2432 | } else |
| 2433 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2434 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2435 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2436 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
| 2437 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2438 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2439 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2440 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2441 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2442 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2443 | temp = atio->u.isp24.attr << 9; |
| 2444 | pkt->u.status0.flags |= cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2445 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2446 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2447 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2448 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2449 | return 0; |
| 2450 | } |
| 2451 | |
| 2452 | /* |
| 2453 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2454 | * that there is sufficient amount of request entries to not drop it. |
| 2455 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2456 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2457 | { |
| 2458 | int cnt; |
| 2459 | uint32_t *dword_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2460 | |
| 2461 | /* Build continuation packets */ |
| 2462 | while (prm->seg_cnt > 0) { |
| 2463 | cont_a64_entry_t *cont_pkt64 = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2464 | (cont_a64_entry_t *)qlt_get_req_pkt( |
| 2465 | prm->cmd->qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2466 | |
| 2467 | /* |
| 2468 | * Make sure that from cont_pkt64 none of |
| 2469 | * 64-bit specific fields used for 32-bit |
| 2470 | * addressing. Cast to (cont_entry_t *) for |
| 2471 | * that. |
| 2472 | */ |
| 2473 | |
| 2474 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2475 | |
| 2476 | cont_pkt64->entry_count = 1; |
| 2477 | cont_pkt64->sys_define = 0; |
| 2478 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2479 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
| 2480 | dword_ptr = (uint32_t *)&cont_pkt64->dseg_0_address; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2481 | |
| 2482 | /* Load continuation entry data segments */ |
| 2483 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2484 | cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2485 | cnt++, prm->seg_cnt--) { |
| 2486 | *dword_ptr++ = |
| 2487 | cpu_to_le32(pci_dma_lo32 |
| 2488 | (sg_dma_address(prm->sg))); |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2489 | *dword_ptr++ = cpu_to_le32(pci_dma_hi32 |
| 2490 | (sg_dma_address(prm->sg))); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2491 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2492 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2493 | prm->sg = sg_next(prm->sg); |
| 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | /* |
| 2499 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2500 | * that there is sufficient amount of request entries to not drop it. |
| 2501 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2502 | static void qlt_load_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2503 | { |
| 2504 | int cnt; |
| 2505 | uint32_t *dword_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2506 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2507 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2508 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2509 | |
| 2510 | /* Setup packet address segment pointer */ |
| 2511 | dword_ptr = pkt24->u.status0.dseg_0_address; |
| 2512 | |
| 2513 | /* Set total data segment count */ |
| 2514 | if (prm->seg_cnt) |
| 2515 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2516 | |
| 2517 | if (prm->seg_cnt == 0) { |
| 2518 | /* No data transfer */ |
| 2519 | *dword_ptr++ = 0; |
| 2520 | *dword_ptr = 0; |
| 2521 | return; |
| 2522 | } |
| 2523 | |
| 2524 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2525 | |
| 2526 | /* Load command entry data segments */ |
| 2527 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2528 | (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2529 | cnt++, prm->seg_cnt--) { |
| 2530 | *dword_ptr++ = |
| 2531 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2532 | |
| 2533 | *dword_ptr++ = cpu_to_le32(pci_dma_hi32( |
| 2534 | sg_dma_address(prm->sg))); |
| 2535 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2536 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2537 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2538 | prm->sg = sg_next(prm->sg); |
| 2539 | } |
| 2540 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2541 | qlt_load_cont_data_segments(prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2545 | { |
| 2546 | return cmd->bufflen > 0; |
| 2547 | } |
| 2548 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2549 | static void qlt_print_dif_err(struct qla_tgt_prm *prm) |
| 2550 | { |
| 2551 | struct qla_tgt_cmd *cmd; |
| 2552 | struct scsi_qla_host *vha; |
| 2553 | |
| 2554 | /* asc 0x10=dif error */ |
| 2555 | if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) { |
| 2556 | cmd = prm->cmd; |
| 2557 | vha = cmd->vha; |
| 2558 | /* ASCQ */ |
| 2559 | switch (prm->sense_buffer[13]) { |
| 2560 | case 1: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2561 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2562 | "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2563 | "se_cmd=%p tag[%x]", |
| 2564 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2565 | cmd->atio.u.isp24.exchange_addr); |
| 2566 | break; |
| 2567 | case 2: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2568 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2569 | "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2570 | "se_cmd=%p tag[%x]", |
| 2571 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2572 | cmd->atio.u.isp24.exchange_addr); |
| 2573 | break; |
| 2574 | case 3: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2575 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2576 | "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2577 | "se_cmd=%p tag[%x]", |
| 2578 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2579 | cmd->atio.u.isp24.exchange_addr); |
| 2580 | break; |
| 2581 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2582 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe010, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2583 | "BE detected Dif ERR: lba[%llx|%lld] len[%x] " |
| 2584 | "se_cmd=%p tag[%x]", |
| 2585 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2586 | cmd->atio.u.isp24.exchange_addr); |
| 2587 | break; |
| 2588 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2589 | ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2593 | /* |
| 2594 | * Called without ha->hardware_lock held |
| 2595 | */ |
| 2596 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2597 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2598 | uint32_t *full_req_cnt) |
| 2599 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2600 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2601 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2602 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2603 | prm->cmd = cmd; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2604 | prm->tgt = cmd->tgt; |
| 2605 | prm->pkt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2606 | prm->rq_result = scsi_status; |
| 2607 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2608 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2609 | prm->sg = NULL; |
| 2610 | prm->seg_cnt = -1; |
| 2611 | prm->req_cnt = 1; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2612 | prm->residual = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2613 | prm->add_status_pkt = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2614 | prm->prot_sg = NULL; |
| 2615 | prm->prot_seg_cnt = 0; |
| 2616 | prm->tot_dsds = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2617 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2618 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2619 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2620 | return -EAGAIN; |
| 2621 | } |
| 2622 | |
| 2623 | *full_req_cnt = prm->req_cnt; |
| 2624 | |
| 2625 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2626 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2627 | ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2628 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2629 | prm->residual, se_cmd->tag, |
| 2630 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2631 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2632 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2633 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2634 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2635 | ql_dbg_qp(ql_dbg_io, qpair, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2636 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2637 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2638 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2639 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2640 | } |
| 2641 | |
| 2642 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2643 | /* |
| 2644 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2645 | * ignored in *xmit_response() below |
| 2646 | */ |
| 2647 | if (qlt_has_data(cmd)) { |
| 2648 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2649 | (IS_FWI2_CAPABLE(cmd->vha->hw) && |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2650 | (prm->rq_result != 0))) { |
| 2651 | prm->add_status_pkt = 1; |
| 2652 | (*full_req_cnt)++; |
| 2653 | } |
| 2654 | } |
| 2655 | } |
| 2656 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2657 | return 0; |
| 2658 | } |
| 2659 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2660 | static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd, |
| 2661 | int sending_sense) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2662 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2663 | if (cmd->qpair->enable_class_2) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2664 | return 0; |
| 2665 | |
| 2666 | if (sending_sense) |
| 2667 | return cmd->conf_compl_supported; |
| 2668 | else |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2669 | return cmd->qpair->enable_explicit_conf && |
| 2670 | cmd->conf_compl_supported; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2671 | } |
| 2672 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2673 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2674 | struct qla_tgt_prm *prm) |
| 2675 | { |
| 2676 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2677 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2678 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2679 | if (qlt_need_explicit_conf(prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2680 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2681 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2682 | CTIO7_FLAGS_CONFORM_REQ); |
| 2683 | } |
| 2684 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2685 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2686 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2687 | int i; |
| 2688 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2689 | if (qlt_need_explicit_conf(prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2690 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2691 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2692 | "Skipping EXPLICIT_CONFORM and " |
| 2693 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2694 | "non GOOD status\n"); |
| 2695 | goto skip_explict_conf; |
| 2696 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2697 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2698 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2699 | CTIO7_FLAGS_CONFORM_REQ); |
| 2700 | } |
| 2701 | skip_explict_conf: |
| 2702 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2703 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2704 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2705 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2706 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2707 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2708 | ctio->u.status1.sense_length = |
| 2709 | cpu_to_le16(prm->sense_buffer_len); |
| 2710 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2711 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2712 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2713 | |
| 2714 | qlt_print_dif_err(prm); |
| 2715 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2716 | } else { |
| 2717 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2718 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2719 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2720 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2721 | ctio->u.status1.sense_length = 0; |
| 2722 | memset(ctio->u.status1.sense_data, 0, |
| 2723 | sizeof(ctio->u.status1.sense_data)); |
| 2724 | } |
| 2725 | |
| 2726 | /* Sense with len > 24, is it possible ??? */ |
| 2727 | } |
| 2728 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2729 | static inline int |
| 2730 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2731 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2732 | switch (se_cmd->prot_op) { |
| 2733 | case TARGET_PROT_DOUT_INSERT: |
| 2734 | case TARGET_PROT_DIN_STRIP: |
| 2735 | if (ql2xenablehba_err_chk >= 1) |
| 2736 | return 1; |
| 2737 | break; |
| 2738 | case TARGET_PROT_DOUT_PASS: |
| 2739 | case TARGET_PROT_DIN_PASS: |
| 2740 | if (ql2xenablehba_err_chk >= 2) |
| 2741 | return 1; |
| 2742 | break; |
| 2743 | case TARGET_PROT_DIN_INSERT: |
| 2744 | case TARGET_PROT_DOUT_STRIP: |
| 2745 | return 1; |
| 2746 | default: |
| 2747 | break; |
| 2748 | } |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2752 | static inline int |
| 2753 | qla_tgt_ref_mask_check(struct se_cmd *se_cmd) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2754 | { |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2755 | switch (se_cmd->prot_op) { |
| 2756 | case TARGET_PROT_DIN_INSERT: |
| 2757 | case TARGET_PROT_DOUT_INSERT: |
| 2758 | case TARGET_PROT_DIN_STRIP: |
| 2759 | case TARGET_PROT_DOUT_STRIP: |
| 2760 | case TARGET_PROT_DIN_PASS: |
| 2761 | case TARGET_PROT_DOUT_PASS: |
| 2762 | return 1; |
| 2763 | default: |
| 2764 | return 0; |
| 2765 | } |
| 2766 | return 0; |
| 2767 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2768 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2769 | /* |
| 2770 | * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command |
| 2771 | */ |
| 2772 | static void |
| 2773 | qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx, |
| 2774 | uint16_t *pfw_prot_opts) |
| 2775 | { |
| 2776 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2777 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2778 | scsi_qla_host_t *vha = cmd->tgt->vha; |
| 2779 | struct qla_hw_data *ha = vha->hw; |
| 2780 | uint32_t t32 = 0; |
| 2781 | |
| 2782 | /* |
| 2783 | * wait till Mode Sense/Select cmd, modepage Ah, subpage 2 |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2784 | * have been immplemented by TCM, before AppTag is avail. |
| 2785 | * Look for modesense_handlers[] |
| 2786 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2787 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2788 | ctx->app_tag_mask[0] = 0x0; |
| 2789 | ctx->app_tag_mask[1] = 0x0; |
| 2790 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2791 | if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2792 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2793 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2794 | *pfw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2795 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2796 | *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2797 | } |
| 2798 | |
| 2799 | t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts); |
| 2800 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2801 | switch (se_cmd->prot_type) { |
| 2802 | case TARGET_DIF_TYPE0_PROT: |
| 2803 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2804 | * No check for ql2xenablehba_err_chk, as it |
| 2805 | * would be an I/O error if hba tag generation |
| 2806 | * is not done. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2807 | */ |
| 2808 | ctx->ref_tag = cpu_to_le32(lba); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2809 | /* enable ALL bytes of the ref tag */ |
| 2810 | ctx->ref_tag_mask[0] = 0xff; |
| 2811 | ctx->ref_tag_mask[1] = 0xff; |
| 2812 | ctx->ref_tag_mask[2] = 0xff; |
| 2813 | ctx->ref_tag_mask[3] = 0xff; |
| 2814 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2815 | case TARGET_DIF_TYPE1_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2816 | /* |
| 2817 | * For TYPE 1 protection: 16 bit GUARD tag, 32 bit |
| 2818 | * REF tag, and 16 bit app tag. |
| 2819 | */ |
| 2820 | ctx->ref_tag = cpu_to_le32(lba); |
| 2821 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2822 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2823 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2824 | break; |
| 2825 | } |
| 2826 | /* enable ALL bytes of the ref tag */ |
| 2827 | ctx->ref_tag_mask[0] = 0xff; |
| 2828 | ctx->ref_tag_mask[1] = 0xff; |
| 2829 | ctx->ref_tag_mask[2] = 0xff; |
| 2830 | ctx->ref_tag_mask[3] = 0xff; |
| 2831 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2832 | case TARGET_DIF_TYPE2_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2833 | /* |
| 2834 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF |
| 2835 | * tag has to match LBA in CDB + N |
| 2836 | */ |
| 2837 | ctx->ref_tag = cpu_to_le32(lba); |
| 2838 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2839 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2840 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2841 | break; |
| 2842 | } |
| 2843 | /* enable ALL bytes of the ref tag */ |
| 2844 | ctx->ref_tag_mask[0] = 0xff; |
| 2845 | ctx->ref_tag_mask[1] = 0xff; |
| 2846 | ctx->ref_tag_mask[2] = 0xff; |
| 2847 | ctx->ref_tag_mask[3] = 0xff; |
| 2848 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2849 | case TARGET_DIF_TYPE3_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2850 | /* For TYPE 3 protection: 16 bit GUARD only */ |
| 2851 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2852 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2853 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2854 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2855 | } |
| 2856 | } |
| 2857 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2858 | static inline int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2859 | 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] | 2860 | { |
| 2861 | uint32_t *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2862 | uint32_t transfer_length = 0; |
| 2863 | uint32_t data_bytes; |
| 2864 | uint32_t dif_bytes; |
| 2865 | uint8_t bundling = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2866 | struct crc_context *crc_ctx_pkt = NULL; |
| 2867 | struct qla_hw_data *ha; |
| 2868 | struct ctio_crc2_to_fw *pkt; |
| 2869 | dma_addr_t crc_ctx_dma; |
| 2870 | uint16_t fw_prot_opts = 0; |
| 2871 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2872 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2873 | uint32_t h; |
| 2874 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2875 | struct qla_tc_param tc; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2876 | uint16_t t16; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2877 | scsi_qla_host_t *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2878 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2879 | ha = vha->hw; |
| 2880 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2881 | pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2882 | prm->pkt = pkt; |
| 2883 | memset(pkt, 0, sizeof(*pkt)); |
| 2884 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2885 | ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2886 | "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] | 2887 | cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2888 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 2889 | |
| 2890 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 2891 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 2892 | bundling = 0; |
| 2893 | |
| 2894 | /* Compute dif len and adjust data len to incude protection */ |
| 2895 | data_bytes = cmd->bufflen; |
| 2896 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 2897 | |
| 2898 | switch (se_cmd->prot_op) { |
| 2899 | case TARGET_PROT_DIN_INSERT: |
| 2900 | case TARGET_PROT_DOUT_STRIP: |
| 2901 | transfer_length = data_bytes; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2902 | if (cmd->prot_sg_cnt) |
| 2903 | data_bytes += dif_bytes; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2904 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2905 | case TARGET_PROT_DIN_STRIP: |
| 2906 | case TARGET_PROT_DOUT_INSERT: |
| 2907 | case TARGET_PROT_DIN_PASS: |
| 2908 | case TARGET_PROT_DOUT_PASS: |
| 2909 | transfer_length = data_bytes + dif_bytes; |
| 2910 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2911 | default: |
| 2912 | BUG(); |
| 2913 | break; |
| 2914 | } |
| 2915 | |
| 2916 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2917 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 2918 | /* HBA error checking enabled */ |
| 2919 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2920 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2921 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2922 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2923 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2924 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2925 | } |
| 2926 | |
| 2927 | switch (se_cmd->prot_op) { |
| 2928 | case TARGET_PROT_DIN_INSERT: |
| 2929 | case TARGET_PROT_DOUT_INSERT: |
| 2930 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 2931 | break; |
| 2932 | case TARGET_PROT_DIN_STRIP: |
| 2933 | case TARGET_PROT_DOUT_STRIP: |
| 2934 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 2935 | break; |
| 2936 | case TARGET_PROT_DIN_PASS: |
| 2937 | case TARGET_PROT_DOUT_PASS: |
| 2938 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2939 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 2940 | break; |
| 2941 | default:/* Normal Request */ |
| 2942 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2943 | break; |
| 2944 | } |
| 2945 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2946 | /* ---- PKT ---- */ |
| 2947 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 2948 | pkt->entry_type = CTIO_CRC2; |
| 2949 | pkt->entry_count = 1; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2950 | pkt->vp_index = cmd->vp_idx; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2951 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2952 | h = qlt_make_handle(qpair); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2953 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2954 | /* |
| 2955 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2956 | * know the initiator's LOOP ID, hence we can't find |
| 2957 | * the session and, so, the command. |
| 2958 | */ |
| 2959 | return -EAGAIN; |
| 2960 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2961 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2962 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2963 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2964 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2965 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2966 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2967 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2968 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2969 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2970 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2971 | |
| 2972 | /* silence compile warning */ |
| 2973 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2974 | pkt->ox_id = cpu_to_le16(t16); |
| 2975 | |
| 2976 | t16 = (atio->u.isp24.attr << 9); |
| 2977 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2978 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2979 | |
| 2980 | /* Set transfer direction */ |
| 2981 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2982 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2983 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2984 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2985 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2986 | pkt->dseg_count = prm->tot_dsds; |
| 2987 | /* Fibre channel byte count */ |
| 2988 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 2989 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2990 | /* ----- CRC context -------- */ |
| 2991 | |
| 2992 | /* Allocate CRC context from global pool */ |
| 2993 | crc_ctx_pkt = cmd->ctx = |
Souptick Joarder | 501017f | 2018-02-15 01:40:38 +0530 | [diff] [blame] | 2994 | dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2995 | |
| 2996 | if (!crc_ctx_pkt) |
| 2997 | goto crc_queuing_error; |
| 2998 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2999 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 3000 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 3001 | |
| 3002 | /* Set handle */ |
| 3003 | crc_ctx_pkt->handle = pkt->handle; |
| 3004 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3005 | qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3006 | |
| 3007 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 3008 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 3009 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 3010 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3011 | if (!bundling) { |
| 3012 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 3013 | } else { |
| 3014 | /* |
| 3015 | * Configure Bundling if we need to fetch interlaving |
| 3016 | * protection PCI accesses |
| 3017 | */ |
| 3018 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 3019 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 3020 | crc_ctx_pkt->u.bundling.dseg_count = |
| 3021 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
| 3022 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 3023 | } |
| 3024 | |
| 3025 | /* Finish the common fields of CRC pkt */ |
| 3026 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 3027 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 3028 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3029 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3030 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3031 | memset((uint8_t *)&tc, 0 , sizeof(tc)); |
| 3032 | tc.vha = vha; |
| 3033 | tc.blk_sz = cmd->blk_sz; |
| 3034 | tc.bufflen = cmd->bufflen; |
| 3035 | tc.sg = cmd->sg; |
| 3036 | tc.prot_sg = cmd->prot_sg; |
| 3037 | tc.ctx = crc_ctx_pkt; |
| 3038 | tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3039 | |
| 3040 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3041 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3042 | |
| 3043 | if (!bundling && prm->prot_seg_cnt) { |
| 3044 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3045 | prm->tot_dsds, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3046 | goto crc_queuing_error; |
| 3047 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3048 | (prm->tot_dsds - prm->prot_seg_cnt), &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3049 | goto crc_queuing_error; |
| 3050 | |
| 3051 | if (bundling && prm->prot_seg_cnt) { |
| 3052 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3053 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3054 | |
| 3055 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 3056 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3057 | prm->prot_seg_cnt, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3058 | goto crc_queuing_error; |
| 3059 | } |
| 3060 | return QLA_SUCCESS; |
| 3061 | |
| 3062 | crc_queuing_error: |
| 3063 | /* Cleanup will be performed by the caller */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3064 | qpair->req->outstanding_cmds[h] = NULL; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3065 | |
| 3066 | return QLA_FUNCTION_FAILED; |
| 3067 | } |
| 3068 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3069 | /* |
| 3070 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 3071 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 3072 | */ |
| 3073 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 3074 | uint8_t scsi_status) |
| 3075 | { |
| 3076 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3077 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3078 | struct ctio7_to_24xx *pkt; |
| 3079 | struct qla_tgt_prm prm; |
| 3080 | uint32_t full_req_cnt = 0; |
| 3081 | unsigned long flags = 0; |
| 3082 | int res; |
| 3083 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3084 | if (cmd->sess && cmd->sess->deleted) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3085 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3086 | if (cmd->sess->logout_completed) |
| 3087 | /* no need to terminate. FW already freed exchange. */ |
| 3088 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 3089 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3090 | qlt_send_term_exchange(qpair, cmd, &cmd->atio, 0, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3091 | return 0; |
| 3092 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3093 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3094 | ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3095 | "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] | 3096 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 3097 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3098 | &cmd->se_cmd, qpair->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3099 | |
| 3100 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 3101 | &full_req_cnt); |
| 3102 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3103 | return res; |
| 3104 | } |
| 3105 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3106 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3107 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3108 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3109 | qpair->tgt_counters.core_qla_snd_status++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3110 | else |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3111 | qpair->tgt_counters.core_qla_que_buf++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3112 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3113 | if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3114 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3115 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3116 | * previous life, just abort the processing. |
| 3117 | */ |
| 3118 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3119 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3120 | ql_dbg_qp(ql_dbg_async, qpair, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3121 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3122 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3123 | cmd->reset_count, qpair->chip_reset); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3124 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3125 | return 0; |
| 3126 | } |
| 3127 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3128 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3129 | res = qlt_check_reserve_free_req(qpair, full_req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3130 | if (unlikely(res)) |
| 3131 | goto out_unmap_unlock; |
| 3132 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3133 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3134 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3135 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3136 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3137 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3138 | qpair->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3139 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3140 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3141 | |
| 3142 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 3143 | |
| 3144 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 3145 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3146 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3147 | CTIO7_FLAGS_STATUS_MODE_0); |
| 3148 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3149 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3150 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3151 | |
| 3152 | if (prm.add_status_pkt == 0) { |
| 3153 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 3154 | pkt->u.status0.scsi_status = |
| 3155 | cpu_to_le16(prm.rq_result); |
| 3156 | pkt->u.status0.residual = |
| 3157 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3158 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3159 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3160 | if (qlt_need_explicit_conf(cmd, 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3161 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3162 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3163 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 3164 | CTIO7_FLAGS_CONFORM_REQ); |
| 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | } else { |
| 3169 | /* |
| 3170 | * We have already made sure that there is sufficient |
| 3171 | * amount of request entries to not drop HW lock in |
| 3172 | * req_pkt(). |
| 3173 | */ |
| 3174 | struct ctio7_to_24xx *ctio = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3175 | (struct ctio7_to_24xx *)qlt_get_req_pkt( |
| 3176 | qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3177 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3178 | ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e, |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3179 | "Building additional status packet 0x%p.\n", |
| 3180 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3181 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3182 | /* |
| 3183 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 3184 | * ctio7_to_24xx |
| 3185 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3186 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3187 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3188 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3189 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3190 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3191 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3192 | CTIO7_FLAGS_DATA_IN); |
| 3193 | |
| 3194 | /* Real finish is ctio_m1's finish */ |
| 3195 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3196 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3197 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3198 | |
| 3199 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3200 | * all neccessary fields that's part of CTIO7. |
| 3201 | * There should be no residual of CTIO-CRC2 data. |
| 3202 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3203 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3204 | &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3205 | } |
| 3206 | } else |
| 3207 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3208 | |
| 3209 | |
| 3210 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3211 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3212 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3213 | /* Memory Barrier */ |
| 3214 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3215 | if (qpair->reqq_start_iocbs) |
| 3216 | qpair->reqq_start_iocbs(qpair); |
| 3217 | else |
| 3218 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3219 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3220 | |
| 3221 | return 0; |
| 3222 | |
| 3223 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3224 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3225 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3226 | |
| 3227 | return res; |
| 3228 | } |
| 3229 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3230 | |
| 3231 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3232 | { |
| 3233 | struct ctio7_to_24xx *pkt; |
| 3234 | struct scsi_qla_host *vha = cmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3235 | struct qla_tgt *tgt = cmd->tgt; |
| 3236 | struct qla_tgt_prm prm; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3237 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3238 | int res = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3239 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3240 | |
| 3241 | memset(&prm, 0, sizeof(prm)); |
| 3242 | prm.cmd = cmd; |
| 3243 | prm.tgt = tgt; |
| 3244 | prm.sg = NULL; |
| 3245 | prm.req_cnt = 1; |
| 3246 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3247 | /* Calculate number of entries and segments required */ |
| 3248 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3249 | return -EAGAIN; |
| 3250 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3251 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3252 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3253 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3254 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3255 | * previous life, just abort the processing. |
| 3256 | */ |
| 3257 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
| 3258 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3259 | ql_dbg_qp(ql_dbg_async, qpair, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3260 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3261 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3262 | cmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3263 | return 0; |
| 3264 | } |
| 3265 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3266 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3267 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3268 | res = qlt_check_reserve_free_req(qpair, prm.req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3269 | if (res != 0) |
| 3270 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3271 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3272 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3273 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3274 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3275 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3276 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3277 | qpair->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3278 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3279 | } |
| 3280 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3281 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3282 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3283 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3284 | |
| 3285 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3286 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3287 | |
| 3288 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3289 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3290 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3291 | /* Memory Barrier */ |
| 3292 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3293 | if (qpair->reqq_start_iocbs) |
| 3294 | qpair->reqq_start_iocbs(qpair); |
| 3295 | else |
| 3296 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3297 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3298 | |
| 3299 | return res; |
| 3300 | |
| 3301 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3302 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3303 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3304 | |
| 3305 | return res; |
| 3306 | } |
| 3307 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3308 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3309 | |
| 3310 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3311 | * it is assumed either hardware_lock or qpair lock is held. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3312 | */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3313 | static void |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3314 | 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] | 3315 | struct ctio_crc_from_fw *sts) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3316 | { |
| 3317 | uint8_t *ap = &sts->actual_dif[0]; |
| 3318 | uint8_t *ep = &sts->expected_dif[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3319 | uint64_t lba = cmd->se_cmd.t_task_lba; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3320 | uint8_t scsi_status, sense_key, asc, ascq; |
| 3321 | unsigned long flags; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3322 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3323 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3324 | cmd->trc_flags |= TRC_DIF_ERR; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3325 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3326 | cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3327 | cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3328 | cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3329 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3330 | cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3331 | cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3332 | cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3333 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3334 | ql_dbg(ql_dbg_tgt_dif, vha, 0xf075, |
| 3335 | "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3336 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3337 | scsi_status = sense_key = asc = ascq = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3338 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3339 | /* check appl tag */ |
| 3340 | if (cmd->e_app_tag != cmd->a_app_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3341 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d, |
| 3342 | "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]", |
| 3343 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3344 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3345 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3346 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3347 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3348 | cmd->dif_err_code = DIF_ERR_APP; |
| 3349 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3350 | sense_key = ABORTED_COMMAND; |
| 3351 | asc = 0x10; |
| 3352 | ascq = 0x2; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | /* check ref tag */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3356 | if (cmd->e_ref_tag != cmd->a_ref_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3357 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e, |
| 3358 | "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] ", |
| 3359 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3360 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3361 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3362 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3363 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3364 | cmd->dif_err_code = DIF_ERR_REF; |
| 3365 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3366 | sense_key = ABORTED_COMMAND; |
| 3367 | asc = 0x10; |
| 3368 | ascq = 0x3; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3369 | goto out; |
| 3370 | } |
| 3371 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3372 | /* check guard */ |
| 3373 | if (cmd->e_guard != cmd->a_guard) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3374 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe012, |
| 3375 | "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]", |
| 3376 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3377 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3378 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3379 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
| 3380 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3381 | cmd->dif_err_code = DIF_ERR_GRD; |
| 3382 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3383 | sense_key = ABORTED_COMMAND; |
| 3384 | asc = 0x10; |
| 3385 | ascq = 0x1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3386 | } |
| 3387 | out: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3388 | switch (cmd->state) { |
| 3389 | case QLA_TGT_STATE_NEED_DATA: |
| 3390 | /* handle_data will load DIF error code */ |
| 3391 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3392 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
| 3393 | break; |
| 3394 | default: |
| 3395 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3396 | if (cmd->aborted) { |
| 3397 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3398 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3399 | break; |
| 3400 | } |
| 3401 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3402 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3403 | qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc, |
| 3404 | ascq); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3405 | /* assume scsi status gets out on the wire. |
| 3406 | * Will not wait for completion. |
| 3407 | */ |
| 3408 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3409 | break; |
| 3410 | } |
| 3411 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3412 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3413 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3414 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3415 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3416 | struct imm_ntfy_from_isp *ntfy) |
| 3417 | { |
| 3418 | struct nack_to_isp *nack; |
| 3419 | struct qla_hw_data *ha = vha->hw; |
| 3420 | request_t *pkt; |
| 3421 | int ret = 0; |
| 3422 | |
| 3423 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3424 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3425 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3426 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3427 | if (pkt == NULL) { |
| 3428 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3429 | "qla_target(%d): %s failed: unable to allocate " |
| 3430 | "request packet\n", vha->vp_idx, __func__); |
| 3431 | return -ENOMEM; |
| 3432 | } |
| 3433 | |
| 3434 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3435 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3436 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3437 | |
| 3438 | nack = (struct nack_to_isp *)pkt; |
| 3439 | nack->ox_id = ntfy->ox_id; |
| 3440 | |
| 3441 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3442 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3443 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3444 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3445 | } |
| 3446 | |
| 3447 | /* terminate */ |
| 3448 | nack->u.isp24.flags |= |
| 3449 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3450 | |
| 3451 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3452 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3453 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3454 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3455 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3456 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3457 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3458 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3459 | |
| 3460 | qla2x00_start_iocbs(vha, vha->req); |
| 3461 | return ret; |
| 3462 | } |
| 3463 | |
| 3464 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3465 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3466 | { |
| 3467 | unsigned long flags = 0; |
| 3468 | int rc; |
| 3469 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3470 | if (ha_locked) { |
| 3471 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3472 | |
| 3473 | #if 0 /* Todo */ |
| 3474 | if (rc == -ENOMEM) |
| 3475 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
Bart Van Assche | 91f42b3 | 2016-03-30 15:25:21 -0700 | [diff] [blame] | 3476 | #else |
| 3477 | if (rc) { |
| 3478 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3479 | #endif |
| 3480 | goto done; |
| 3481 | } |
| 3482 | |
| 3483 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3484 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3485 | |
| 3486 | #if 0 /* Todo */ |
| 3487 | if (rc == -ENOMEM) |
| 3488 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
| 3489 | #endif |
| 3490 | |
| 3491 | done: |
| 3492 | if (!ha_locked) |
| 3493 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3494 | } |
| 3495 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3496 | /* |
| 3497 | * If hardware_lock held on entry, might drop it, then reaquire |
| 3498 | * This function sends the appropriate CTIO to ISP 2xxx or 24xx |
| 3499 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3500 | static int __qlt_send_term_exchange(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3501 | struct qla_tgt_cmd *cmd, |
| 3502 | struct atio_from_isp *atio) |
| 3503 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3504 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3505 | struct ctio7_to_24xx *ctio24; |
| 3506 | struct qla_hw_data *ha = vha->hw; |
| 3507 | request_t *pkt; |
| 3508 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3509 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3510 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3511 | 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] | 3512 | |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 3513 | if (cmd) |
| 3514 | vha = cmd->vha; |
| 3515 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3516 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3517 | if (pkt == NULL) { |
| 3518 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3519 | "qla_target(%d): %s failed: unable to allocate " |
| 3520 | "request packet\n", vha->vp_idx, __func__); |
| 3521 | return -ENOMEM; |
| 3522 | } |
| 3523 | |
| 3524 | if (cmd != NULL) { |
| 3525 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3526 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3527 | "qla_target(%d): Terminating cmd %p with " |
| 3528 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3529 | cmd->state); |
| 3530 | } else |
| 3531 | ret = 1; |
| 3532 | } |
| 3533 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3534 | qpair->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3535 | pkt->entry_count = 1; |
| 3536 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3537 | |
| 3538 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3539 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3540 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3541 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3542 | ctio24->vp_index = vha->vp_idx; |
| 3543 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3544 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3545 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3546 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3547 | temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 | |
| 3548 | CTIO7_FLAGS_TERMINATE; |
| 3549 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3550 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3551 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3552 | |
| 3553 | /* Most likely, it isn't needed */ |
| 3554 | ctio24->u.status1.residual = get_unaligned((uint32_t *) |
| 3555 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3556 | atio->u.isp24.fcp_cmnd.add_cdb_len]); |
| 3557 | if (ctio24->u.status1.residual != 0) |
| 3558 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 3559 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3560 | /* Memory Barrier */ |
| 3561 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3562 | if (qpair->reqq_start_iocbs) |
| 3563 | qpair->reqq_start_iocbs(qpair); |
| 3564 | else |
| 3565 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3566 | return ret; |
| 3567 | } |
| 3568 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3569 | static void qlt_send_term_exchange(struct qla_qpair *qpair, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3570 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3571 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3572 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3573 | struct scsi_qla_host *vha; |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3574 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3575 | int rc; |
| 3576 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3577 | /* why use different vha? NPIV */ |
| 3578 | if (cmd) |
| 3579 | vha = cmd->vha; |
| 3580 | else |
| 3581 | vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3582 | |
| 3583 | if (ha_locked) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3584 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3585 | if (rc == -ENOMEM) |
| 3586 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3587 | goto done; |
| 3588 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3589 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 3590 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3591 | if (rc == -ENOMEM) |
| 3592 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3593 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3594 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3595 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3596 | if (cmd->sg_mapped) |
| 3597 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3598 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3599 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3600 | |
| 3601 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3602 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3603 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3604 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3605 | } |
| 3606 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3607 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3608 | { |
| 3609 | struct list_head free_list; |
| 3610 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3611 | |
| 3612 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3613 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3614 | |
| 3615 | cmd = tcmd = NULL; |
| 3616 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3617 | INIT_LIST_HEAD(&free_list); |
| 3618 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3619 | |
| 3620 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3621 | list_del(&cmd->cmd_list); |
| 3622 | /* This cmd was never sent to TCM. There is no need |
| 3623 | * to schedule free or call free_cmd |
| 3624 | */ |
| 3625 | qlt_free_cmd(cmd); |
| 3626 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3627 | } |
| 3628 | } |
| 3629 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3630 | } |
| 3631 | |
| 3632 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3633 | { |
| 3634 | uint32_t total_leaked; |
| 3635 | |
| 3636 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3637 | |
| 3638 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3639 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3640 | |
| 3641 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3642 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3643 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3644 | |
| 3645 | if (IS_P3P_TYPE(vha->hw)) |
| 3646 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3647 | else |
| 3648 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3649 | qla2xxx_wake_dpc(vha); |
| 3650 | } |
| 3651 | |
| 3652 | } |
| 3653 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3654 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3655 | { |
| 3656 | struct qla_tgt *tgt = cmd->tgt; |
| 3657 | struct scsi_qla_host *vha = tgt->vha; |
| 3658 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3659 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3660 | |
| 3661 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3662 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3663 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3664 | se_cmd->tag); |
| 3665 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3666 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3667 | if (cmd->aborted) { |
| 3668 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3669 | /* |
| 3670 | * It's normal to see 2 calls in this path: |
| 3671 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3672 | * 2) TCM TMR - drain_state_list |
| 3673 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3674 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, |
| 3675 | "multiple abort. %p transport_state %x, t_state %x, " |
| 3676 | "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, |
| 3677 | cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3678 | return EIO; |
| 3679 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3680 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3681 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3682 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3683 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3684 | qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3685 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3686 | } |
| 3687 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3688 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3689 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3690 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3691 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3692 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3693 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3694 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3695 | __func__, &cmd->se_cmd, |
| 3696 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3697 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3698 | BUG_ON(cmd->cmd_in_wq); |
| 3699 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3700 | if (cmd->sg_mapped) |
| 3701 | qlt_unmap_sg(cmd->vha, cmd); |
| 3702 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3703 | if (!cmd->q_full) |
| 3704 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3705 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3706 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3707 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3708 | if (unlikely(cmd->free_sg)) |
| 3709 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3710 | |
| 3711 | if (!sess || !sess->se_sess) { |
| 3712 | WARN_ON(1); |
| 3713 | return; |
| 3714 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3715 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3716 | percpu_ida_free(&sess->se_sess->sess_tag_pool, cmd->se_cmd.map_tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3717 | } |
| 3718 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3719 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3720 | /* |
| 3721 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3722 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3723 | static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3724 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3725 | { |
| 3726 | int term = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3727 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3728 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3729 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3730 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3731 | "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " |
| 3732 | "se_cmd=%p tag[%x] op %#x/%s", |
| 3733 | cmd->lba, cmd->lba, |
| 3734 | cmd->num_blks, &cmd->se_cmd, |
| 3735 | cmd->atio.u.isp24.exchange_addr, |
| 3736 | cmd->se_cmd.prot_op, |
| 3737 | prot_op_str(cmd->se_cmd.prot_op)); |
| 3738 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3739 | if (ctio != NULL) { |
| 3740 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
| 3741 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3742 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3743 | } else |
| 3744 | term = 1; |
| 3745 | |
| 3746 | if (term) |
himanshu.madhani@cavium.com | 3efc31f | 2018-01-15 20:46:47 -0800 | [diff] [blame] | 3747 | qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3748 | |
| 3749 | return term; |
| 3750 | } |
| 3751 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3752 | |
| 3753 | /* ha->hardware_lock supposed to be held on entry */ |
| 3754 | static struct qla_tgt_cmd *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3755 | struct rsp_que *rsp, uint32_t handle, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3756 | { |
| 3757 | struct qla_tgt_cmd *cmd = NULL; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3758 | struct req_que *req; |
| 3759 | int qid = GET_QID(handle); |
| 3760 | uint32_t h = handle & ~QLA_TGT_HANDLE_MASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3761 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3762 | if (unlikely(h == QLA_TGT_SKIP_HANDLE)) |
| 3763 | return NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3764 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3765 | if (qid == rsp->req->id) { |
| 3766 | req = rsp->req; |
| 3767 | } else if (vha->hw->req_q_map[qid]) { |
| 3768 | ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a, |
| 3769 | "qla_target(%d): CTIO completion with different QID %d handle %x\n", |
| 3770 | vha->vp_idx, rsp->id, handle); |
| 3771 | req = vha->hw->req_q_map[qid]; |
| 3772 | } else { |
| 3773 | return NULL; |
| 3774 | } |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3775 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3776 | h &= QLA_CMD_HANDLE_MASK; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3777 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3778 | if (h != QLA_TGT_NULL_HANDLE) { |
Dan Carpenter | fb2028a | 2017-07-10 11:47:40 +0300 | [diff] [blame] | 3779 | if (unlikely(h >= req->num_outstanding_cmds)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3780 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3781 | "qla_target(%d): Wrong handle %x received\n", |
| 3782 | vha->vp_idx, handle); |
| 3783 | return NULL; |
| 3784 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3785 | |
| 3786 | cmd = (struct qla_tgt_cmd *)req->outstanding_cmds[h]; |
| 3787 | if (unlikely(cmd == NULL)) { |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3788 | ql_dbg(ql_dbg_async, vha, 0xe053, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3789 | "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n", |
| 3790 | vha->vp_idx, handle, req->id, rsp->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3791 | return NULL; |
| 3792 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3793 | req->outstanding_cmds[h] = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3794 | } else if (ctio != NULL) { |
| 3795 | /* We can't get loop ID from CTIO7 */ |
| 3796 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3797 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3798 | "support NULL handles\n", vha->vp_idx); |
| 3799 | return NULL; |
| 3800 | } |
| 3801 | |
| 3802 | return cmd; |
| 3803 | } |
| 3804 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3805 | /* hardware_lock should be held by caller. */ |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3806 | void |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3807 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
| 3808 | { |
| 3809 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3810 | |
| 3811 | if (cmd->sg_mapped) |
| 3812 | qlt_unmap_sg(vha, cmd); |
| 3813 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3814 | /* TODO: fix debug message type and ids. */ |
| 3815 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
| 3816 | ql_dbg(ql_dbg_io, vha, 0xff00, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3817 | "HOST-ABORT: state=PROCESSED.\n"); |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3818 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3819 | cmd->write_data_transferred = 0; |
| 3820 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3821 | |
| 3822 | ql_dbg(ql_dbg_io, vha, 0xff01, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3823 | "HOST-ABORT: state=DATA_IN.\n"); |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3824 | |
| 3825 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3826 | return; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3827 | } else { |
| 3828 | ql_dbg(ql_dbg_io, vha, 0xff03, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3829 | "HOST-ABORT: state=BAD(%d).\n", |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3830 | cmd->state); |
| 3831 | dump_stack(); |
| 3832 | } |
| 3833 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3834 | cmd->trc_flags |= TRC_FLUSH; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3835 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3836 | } |
| 3837 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3838 | /* |
| 3839 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3840 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3841 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, |
| 3842 | struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3843 | { |
| 3844 | struct qla_hw_data *ha = vha->hw; |
| 3845 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3846 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3847 | struct qla_qpair *qpair = rsp->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3848 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3849 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3850 | /* That could happen only in case of an error/reset/abort */ |
| 3851 | if (status != CTIO_SUCCESS) { |
| 3852 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3853 | "Intermediate CTIO received" |
| 3854 | " (status %x)\n", status); |
| 3855 | } |
| 3856 | return; |
| 3857 | } |
| 3858 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3859 | cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3860 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3861 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3862 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3863 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3864 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3865 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3866 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3867 | |
| 3868 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3869 | switch (status & 0xFFFF) { |
| 3870 | case CTIO_LIP_RESET: |
| 3871 | case CTIO_TARGET_RESET: |
| 3872 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3873 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3874 | case CTIO_TIMEOUT: |
| 3875 | case CTIO_INVALID_RX_ID: |
| 3876 | /* They are OK */ |
| 3877 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3878 | "qla_target(%d): CTIO with " |
| 3879 | "status %#x received, state %x, se_cmd %p, " |
| 3880 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3881 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3882 | status, cmd->state, se_cmd); |
| 3883 | break; |
| 3884 | |
| 3885 | case CTIO_PORT_LOGGED_OUT: |
| 3886 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3887 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3888 | int logged_out = |
| 3889 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3890 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3891 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3892 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3893 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3894 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3895 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3896 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3897 | if (logged_out && cmd->sess) { |
| 3898 | /* |
| 3899 | * Session is already logged out, but we need |
| 3900 | * to notify initiator, who's not aware of this |
| 3901 | */ |
| 3902 | cmd->sess->logout_on_delete = 0; |
| 3903 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3904 | ql_dbg(ql_dbg_disc, vha, 0x20f8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3905 | "%s %d %8phC post del sess\n", |
| 3906 | __func__, __LINE__, cmd->sess->port_name); |
| 3907 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 3908 | qlt_schedule_sess_for_deletion(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3909 | } |
| 3910 | break; |
| 3911 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3912 | case CTIO_DIF_ERROR: { |
| 3913 | struct ctio_crc_from_fw *crc = |
| 3914 | (struct ctio_crc_from_fw *)ctio; |
| 3915 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3916 | "qla_target(%d): CTIO with DIF_ERROR status %x " |
| 3917 | "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " |
| 3918 | "expect_dif[0x%llx]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3919 | vha->vp_idx, status, cmd->state, se_cmd, |
| 3920 | *((u64 *)&crc->actual_dif[0]), |
| 3921 | *((u64 *)&crc->expected_dif[0])); |
| 3922 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3923 | qlt_handle_dif_error(qpair, cmd, ctio); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3924 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3925 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3926 | default: |
| 3927 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3928 | "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] | 3929 | vha->vp_idx, status, cmd->state, se_cmd); |
| 3930 | break; |
| 3931 | } |
| 3932 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3933 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3934 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3935 | * cmd is already aborted/terminated, we don't |
| 3936 | * need to terminate again. The exchange is already |
| 3937 | * cleaned up/freed at FW level. Just cleanup at driver |
| 3938 | * level. |
| 3939 | */ |
| 3940 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3941 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3942 | cmd->trc_flags |= TRC_CTIO_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3943 | if (qlt_term_ctio_exchange(qpair, ctio, cmd, status)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3944 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3945 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3949 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3950 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3951 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3952 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3953 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3954 | cmd->write_data_transferred = 1; |
| 3955 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3956 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3957 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3958 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3959 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3960 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3961 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3962 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3963 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3964 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 3965 | "qla_target(%d): A command in state (%d) should " |
| 3966 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 3967 | } |
| 3968 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3969 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3970 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3971 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 3972 | dump_stack(); |
| 3973 | } |
| 3974 | |
| 3975 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3976 | } |
| 3977 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3978 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 3979 | uint8_t task_codes) |
| 3980 | { |
| 3981 | int fcp_task_attr; |
| 3982 | |
| 3983 | switch (task_codes) { |
| 3984 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3985 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3986 | break; |
| 3987 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3988 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3989 | break; |
| 3990 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3991 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3992 | break; |
| 3993 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3994 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3995 | break; |
| 3996 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3997 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3998 | break; |
| 3999 | default: |
| 4000 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 4001 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 4002 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 4003 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4004 | break; |
| 4005 | } |
| 4006 | |
| 4007 | return fcp_task_attr; |
| 4008 | } |
| 4009 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4010 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4011 | uint8_t *); |
| 4012 | /* |
| 4013 | * Process context for I/O path into tcm_qla2xxx code |
| 4014 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4015 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4016 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4017 | scsi_qla_host_t *vha = cmd->vha; |
| 4018 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4019 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4020 | struct atio_from_isp *atio = &cmd->atio; |
| 4021 | unsigned char *cdb; |
| 4022 | unsigned long flags; |
| 4023 | uint32_t data_length; |
| 4024 | int ret, fcp_task_attr, data_dir, bidi = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4025 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4026 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4027 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4028 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4029 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4030 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4031 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 4032 | "cmd with tag %u is aborted\n", |
| 4033 | cmd->atio.u.isp24.exchange_addr); |
| 4034 | goto out_term; |
| 4035 | } |
| 4036 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4037 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4038 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4039 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4040 | |
| 4041 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 4042 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 4043 | bidi = 1; |
| 4044 | data_dir = DMA_TO_DEVICE; |
| 4045 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 4046 | data_dir = DMA_FROM_DEVICE; |
| 4047 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 4048 | data_dir = DMA_TO_DEVICE; |
| 4049 | else |
| 4050 | data_dir = DMA_NONE; |
| 4051 | |
| 4052 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 4053 | atio->u.isp24.fcp_cmnd.task_attr); |
| 4054 | data_length = be32_to_cpu(get_unaligned((uint32_t *) |
| 4055 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 4056 | atio->u.isp24.fcp_cmnd.add_cdb_len])); |
| 4057 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4058 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 4059 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4060 | if (ret != 0) |
| 4061 | goto out_term; |
| 4062 | /* |
| 4063 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( |
| 4064 | */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4065 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4066 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4067 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4068 | return; |
| 4069 | |
| 4070 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4071 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4072 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 4073 | * cmd has not sent to target yet, so pass NULL as the second |
| 4074 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4075 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4076 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4077 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4078 | qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4079 | |
| 4080 | qlt_decr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4081 | percpu_ida_free(&sess->se_sess->sess_tag_pool, cmd->se_cmd.map_tag); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4082 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4083 | |
| 4084 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4085 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4086 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4087 | } |
| 4088 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4089 | static void qlt_do_work(struct work_struct *work) |
| 4090 | { |
| 4091 | 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] | 4092 | scsi_qla_host_t *vha = cmd->vha; |
| 4093 | unsigned long flags; |
| 4094 | |
| 4095 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4096 | list_del(&cmd->cmd_list); |
| 4097 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4098 | |
| 4099 | __qlt_do_work(cmd); |
| 4100 | } |
| 4101 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 4102 | void qlt_clr_qp_table(struct scsi_qla_host *vha) |
| 4103 | { |
| 4104 | unsigned long flags; |
| 4105 | struct qla_hw_data *ha = vha->hw; |
| 4106 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4107 | void *node; |
| 4108 | u64 key = 0; |
| 4109 | |
| 4110 | ql_log(ql_log_info, vha, 0x706c, |
| 4111 | "User update Number of Active Qpairs %d\n", |
| 4112 | ha->tgt.num_act_qpairs); |
| 4113 | |
| 4114 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 4115 | |
| 4116 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 4117 | btree_remove64(&tgt->lun_qpair_map, key); |
| 4118 | |
| 4119 | ha->base_qpair->lun_cnt = 0; |
| 4120 | for (key = 0; key < ha->max_qpairs; key++) |
| 4121 | if (ha->queue_pair_map[key]) |
| 4122 | ha->queue_pair_map[key]->lun_cnt = 0; |
| 4123 | |
| 4124 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 4125 | } |
| 4126 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4127 | static void qlt_assign_qpair(struct scsi_qla_host *vha, |
| 4128 | struct qla_tgt_cmd *cmd) |
| 4129 | { |
| 4130 | struct qla_qpair *qpair, *qp; |
| 4131 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4132 | struct qla_qpair_hint *h; |
| 4133 | |
| 4134 | if (vha->flags.qpairs_available) { |
| 4135 | h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun); |
| 4136 | if (unlikely(!h)) { |
| 4137 | /* spread lun to qpair ratio evently */ |
| 4138 | int lcnt = 0, rc; |
| 4139 | struct scsi_qla_host *base_vha = |
| 4140 | pci_get_drvdata(vha->hw->pdev); |
| 4141 | |
| 4142 | qpair = vha->hw->base_qpair; |
| 4143 | if (qpair->lun_cnt == 0) { |
| 4144 | qpair->lun_cnt++; |
| 4145 | h = qla_qpair_to_hint(tgt, qpair); |
| 4146 | BUG_ON(!h); |
| 4147 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4148 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4149 | if (rc) { |
| 4150 | qpair->lun_cnt--; |
| 4151 | ql_log(ql_log_info, vha, 0xd037, |
| 4152 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4153 | cmd->unpacked_lun); |
| 4154 | } |
| 4155 | goto out; |
| 4156 | } else { |
| 4157 | lcnt = qpair->lun_cnt; |
| 4158 | } |
| 4159 | |
| 4160 | h = NULL; |
| 4161 | list_for_each_entry(qp, &base_vha->qp_list, |
| 4162 | qp_list_elem) { |
| 4163 | if (qp->lun_cnt == 0) { |
| 4164 | qp->lun_cnt++; |
| 4165 | h = qla_qpair_to_hint(tgt, qp); |
| 4166 | BUG_ON(!h); |
| 4167 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4168 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4169 | if (rc) { |
| 4170 | qp->lun_cnt--; |
| 4171 | ql_log(ql_log_info, vha, 0xd038, |
| 4172 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4173 | cmd->unpacked_lun); |
| 4174 | } |
| 4175 | qpair = qp; |
| 4176 | goto out; |
| 4177 | } else { |
| 4178 | if (qp->lun_cnt < lcnt) { |
| 4179 | lcnt = qp->lun_cnt; |
| 4180 | qpair = qp; |
| 4181 | continue; |
| 4182 | } |
| 4183 | } |
| 4184 | } |
| 4185 | BUG_ON(!qpair); |
| 4186 | qpair->lun_cnt++; |
| 4187 | h = qla_qpair_to_hint(tgt, qpair); |
| 4188 | BUG_ON(!h); |
| 4189 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4190 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4191 | if (rc) { |
| 4192 | qpair->lun_cnt--; |
| 4193 | ql_log(ql_log_info, vha, 0xd039, |
| 4194 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4195 | cmd->unpacked_lun); |
| 4196 | } |
| 4197 | } |
| 4198 | } else { |
| 4199 | h = &tgt->qphints[0]; |
| 4200 | } |
| 4201 | out: |
| 4202 | cmd->qpair = h->qpair; |
| 4203 | cmd->se_cmd.cpuid = h->cpuid; |
| 4204 | } |
| 4205 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4206 | 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] | 4207 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4208 | struct atio_from_isp *atio) |
| 4209 | { |
| 4210 | struct se_session *se_sess = sess->se_sess; |
| 4211 | struct qla_tgt_cmd *cmd; |
| 4212 | int tag; |
| 4213 | |
| 4214 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 4215 | if (tag < 0) |
| 4216 | return NULL; |
| 4217 | |
| 4218 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4219 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 4220 | cmd->cmd_type = TYPE_TGT_CMD; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4221 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4222 | cmd->state = QLA_TGT_STATE_NEW; |
| 4223 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4224 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4225 | cmd->vha = vha; |
| 4226 | cmd->se_cmd.map_tag = tag; |
| 4227 | cmd->sess = sess; |
| 4228 | cmd->loop_id = sess->loop_id; |
| 4229 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4230 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4231 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4232 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4233 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4234 | cmd->unpacked_lun = scsilun_to_int( |
| 4235 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 4236 | qlt_assign_qpair(vha, cmd); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4237 | cmd->reset_count = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 4238 | cmd->vp_idx = vha->vp_idx; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4239 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4240 | return cmd; |
| 4241 | } |
| 4242 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4243 | /* ha->hardware_lock supposed to be held on entry */ |
| 4244 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4245 | struct atio_from_isp *atio) |
| 4246 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4247 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4248 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4249 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4250 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4251 | unsigned long flags; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4252 | port_id_t id; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4253 | |
| 4254 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4255 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4256 | "New command while device %p is shutting down\n", tgt); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4257 | return -ENODEV; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4258 | } |
| 4259 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4260 | id.b.al_pa = atio->u.isp24.fcp_hdr.s_id[2]; |
| 4261 | id.b.area = atio->u.isp24.fcp_hdr.s_id[1]; |
| 4262 | id.b.domain = atio->u.isp24.fcp_hdr.s_id[0]; |
| 4263 | if (IS_SW_RESV_ADDR(id)) |
| 4264 | return -EBUSY; |
| 4265 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4266 | 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] | 4267 | if (unlikely(!sess)) |
| 4268 | return -EFAULT; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4269 | |
| 4270 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4271 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4272 | if (sess->deleted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4273 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4274 | "New command while old session %p is being deleted\n", |
| 4275 | sess); |
| 4276 | return -EFAULT; |
| 4277 | } |
| 4278 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4279 | /* |
| 4280 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4281 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4282 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4283 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4284 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4285 | __func__, sess->port_name, |
| 4286 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4287 | return -EFAULT; |
| 4288 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4289 | |
| 4290 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4291 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4292 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4293 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4294 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4295 | ha->tgt.tgt_ops->put_sess(sess); |
| 4296 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 4297 | return -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4298 | } |
| 4299 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4300 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4301 | cmd->trc_flags |= TRC_NEW_CMD; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4302 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4303 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4304 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4305 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4306 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4307 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4308 | if (vha->flags.qpairs_available) { |
| 4309 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work); |
| 4310 | } else if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4311 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4312 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4313 | &cmd->work); |
| 4314 | else |
| 4315 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4316 | &cmd->work); |
| 4317 | } else { |
| 4318 | queue_work(qla_tgt_wq, &cmd->work); |
| 4319 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4320 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4321 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4325 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4326 | int fn, void *iocb, int flags) |
| 4327 | { |
| 4328 | struct scsi_qla_host *vha = sess->vha; |
| 4329 | struct qla_hw_data *ha = vha->hw; |
| 4330 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4331 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4332 | int res; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4333 | |
| 4334 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4335 | if (!mcmd) { |
| 4336 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4337 | "qla_target(%d): Allocation of management " |
| 4338 | "command failed, some commands and their data could " |
| 4339 | "leak\n", vha->vp_idx); |
| 4340 | return -ENOMEM; |
| 4341 | } |
| 4342 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4343 | mcmd->sess = sess; |
| 4344 | |
| 4345 | if (iocb) { |
| 4346 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4347 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4348 | } |
| 4349 | mcmd->tmr_func = fn; |
| 4350 | mcmd->flags = flags; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4351 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4352 | mcmd->qpair = ha->base_qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 4353 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4354 | |
| 4355 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4356 | case QLA_TGT_LUN_RESET: |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4357 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
| 4358 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4359 | } |
| 4360 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4361 | res = ha->tgt.tgt_ops->handle_tmr(mcmd, lun, mcmd->tmr_func, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4362 | if (res != 0) { |
| 4363 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, |
| 4364 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", |
| 4365 | sess->vha->vp_idx, res); |
| 4366 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4367 | return -EFAULT; |
| 4368 | } |
| 4369 | |
| 4370 | return 0; |
| 4371 | } |
| 4372 | |
| 4373 | /* ha->hardware_lock supposed to be held on entry */ |
| 4374 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4375 | { |
| 4376 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4377 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4378 | struct fc_port *sess; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4379 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4380 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4381 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4382 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4383 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4384 | |
| 4385 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4386 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4387 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4388 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4389 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4390 | unpacked_lun = |
| 4391 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4392 | |
Quinn Tran | fb35265 | 2017-12-28 12:33:32 -0800 | [diff] [blame] | 4393 | if (sess == NULL || sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4394 | return -EFAULT; |
| 4395 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4396 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4397 | } |
| 4398 | |
| 4399 | /* ha->hardware_lock supposed to be held on entry */ |
| 4400 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4401 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4402 | { |
| 4403 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4404 | struct qla_hw_data *ha = vha->hw; |
| 4405 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4406 | u64 unpacked_lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4407 | int rc; |
| 4408 | |
| 4409 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4410 | if (mcmd == NULL) { |
| 4411 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4412 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4413 | vha->vp_idx, __func__); |
| 4414 | return -ENOMEM; |
| 4415 | } |
| 4416 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4417 | |
| 4418 | mcmd->sess = sess; |
| 4419 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4420 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4421 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4422 | unpacked_lun = |
| 4423 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4424 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4425 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4426 | mcmd->qpair = ha->base_qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4427 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4428 | 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] | 4429 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4430 | if (rc != 0) { |
| 4431 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4432 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4433 | vha->vp_idx, rc); |
| 4434 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4435 | return -EFAULT; |
| 4436 | } |
| 4437 | |
| 4438 | return 0; |
| 4439 | } |
| 4440 | |
| 4441 | /* ha->hardware_lock supposed to be held on entry */ |
| 4442 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4443 | struct imm_ntfy_from_isp *iocb) |
| 4444 | { |
| 4445 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4446 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4447 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4448 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4449 | |
| 4450 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4451 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4452 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4453 | 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] | 4454 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4455 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4456 | if (sess == NULL) { |
| 4457 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4458 | "qla_target(%d): task abort for unexisting " |
| 4459 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4460 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4461 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4462 | } |
| 4463 | |
| 4464 | return __qlt_abort_task(vha, iocb, sess); |
| 4465 | } |
| 4466 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4467 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4468 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4469 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4470 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4471 | "%s: se_sess %p / sess %p from" |
| 4472 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4473 | " LOGO failed: %#x\n", |
| 4474 | __func__, |
| 4475 | fcport->se_sess, |
| 4476 | fcport, |
| 4477 | fcport->port_name, fcport->loop_id, |
| 4478 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4479 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4480 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4481 | |
| 4482 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4483 | } |
| 4484 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4485 | /* |
| 4486 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4487 | * |
| 4488 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4489 | * deletion. Returns existing session with matching wwn if present. |
| 4490 | * Null otherwise. |
| 4491 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4492 | struct fc_port * |
| 4493 | 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] | 4494 | 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] | 4495 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4496 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4497 | uint64_t other_wwn; |
| 4498 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4499 | *conflict_sess = NULL; |
| 4500 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4501 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4502 | |
| 4503 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4504 | |
| 4505 | if (wwn == other_wwn) { |
| 4506 | WARN_ON(sess); |
| 4507 | sess = other_sess; |
| 4508 | continue; |
| 4509 | } |
| 4510 | |
| 4511 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4512 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4513 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4514 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4515 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4516 | other_sess, other_sess->loop_id, other_wwn); |
| 4517 | |
| 4518 | /* |
| 4519 | * logout_on_delete is set by default, but another |
| 4520 | * session that has the same s_id/loop_id combo |
| 4521 | * might have cleared it when requested this session |
| 4522 | * deletion, so don't touch it |
| 4523 | */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4524 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4525 | } else { |
| 4526 | /* |
| 4527 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4528 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4529 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4530 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01b, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4531 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4532 | other_sess, other_sess->loop_id, other_wwn); |
| 4533 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4534 | other_sess->keep_nport_handle = 1; |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 4535 | if (other_sess->disc_state != DSC_DELETED) |
| 4536 | *conflict_sess = other_sess; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4537 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4538 | } |
| 4539 | continue; |
| 4540 | } |
| 4541 | |
| 4542 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4543 | if ((loop_id == other_sess->loop_id) && |
| 4544 | (loop_id != FC_NO_LOOP_ID)) { |
| 4545 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4546 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4547 | other_sess, other_sess->loop_id, other_wwn); |
| 4548 | |
| 4549 | /* Same loop_id but different s_id |
| 4550 | * Ok to kill and logout */ |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 4551 | qlt_schedule_sess_for_deletion(other_sess); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | return sess; |
| 4556 | } |
| 4557 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4558 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4559 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4560 | { |
| 4561 | struct qla_tgt_sess_op *op; |
| 4562 | struct qla_tgt_cmd *cmd; |
| 4563 | uint32_t key; |
| 4564 | int count = 0; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4565 | unsigned long flags; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4566 | |
| 4567 | key = (((u32)s_id->b.domain << 16) | |
| 4568 | ((u32)s_id->b.area << 8) | |
| 4569 | ((u32)s_id->b.al_pa)); |
| 4570 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4571 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4572 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4573 | 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] | 4574 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4575 | if (op_key == key) { |
| 4576 | op->aborted = true; |
| 4577 | count++; |
| 4578 | } |
| 4579 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4580 | |
| 4581 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4582 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 4583 | if (op_key == key) { |
| 4584 | op->aborted = true; |
| 4585 | count++; |
| 4586 | } |
| 4587 | } |
| 4588 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4589 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4590 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 4591 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4592 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4593 | count++; |
| 4594 | } |
| 4595 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4596 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4597 | |
| 4598 | return count; |
| 4599 | } |
| 4600 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4601 | static int qlt_handle_login(struct scsi_qla_host *vha, |
| 4602 | struct imm_ntfy_from_isp *iocb) |
| 4603 | { |
| 4604 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
| 4605 | uint64_t wwn; |
| 4606 | port_id_t port_id; |
| 4607 | uint16_t loop_id, wd3_lo; |
| 4608 | int res = 0; |
| 4609 | struct qlt_plogi_ack_t *pla; |
| 4610 | unsigned long flags; |
| 4611 | |
| 4612 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4613 | |
| 4614 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4615 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4616 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4617 | port_id.b.rsvd_1 = 0; |
| 4618 | |
| 4619 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4620 | |
| 4621 | /* Mark all stale commands sitting in qla_tgt_wq for deletion */ |
| 4622 | abort_cmds_for_s_id(vha, &port_id); |
| 4623 | |
| 4624 | if (wwn) { |
| 4625 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 4626 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4627 | port_id, loop_id, &conflict_sess); |
| 4628 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4629 | } |
| 4630 | |
| 4631 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4632 | res = 1; |
| 4633 | goto out; |
| 4634 | } |
| 4635 | |
| 4636 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4637 | if (!pla) { |
| 4638 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4639 | goto out; |
| 4640 | } |
| 4641 | |
| 4642 | if (conflict_sess) { |
| 4643 | conflict_sess->login_gen++; |
| 4644 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
| 4645 | QLT_PLOGI_LINK_CONFLICT); |
| 4646 | } |
| 4647 | |
| 4648 | if (!sess) { |
| 4649 | pla->ref_count++; |
| 4650 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4651 | "%s %d %8phC post new sess\n", |
| 4652 | __func__, __LINE__, iocb->u.isp24.port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4653 | if (iocb->u.isp24.status_subcode == ELS_PLOGI) |
| 4654 | qla24xx_post_newsess_work(vha, &port_id, |
| 4655 | iocb->u.isp24.port_name, |
| 4656 | iocb->u.isp24.u.plogi.node_name, |
| 4657 | pla, FC4_TYPE_UNKNOWN); |
| 4658 | else |
| 4659 | qla24xx_post_newsess_work(vha, &port_id, |
| 4660 | iocb->u.isp24.port_name, NULL, |
| 4661 | pla, FC4_TYPE_UNKNOWN); |
| 4662 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4663 | goto out; |
| 4664 | } |
| 4665 | |
| 4666 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
| 4667 | sess->d_id = port_id; |
| 4668 | sess->login_gen++; |
| 4669 | |
| 4670 | if (iocb->u.isp24.status_subcode == ELS_PRLI) { |
| 4671 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4672 | sess->local = 0; |
| 4673 | sess->loop_id = loop_id; |
| 4674 | sess->d_id = port_id; |
| 4675 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
| 4676 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4677 | |
| 4678 | if (wd3_lo & BIT_7) |
| 4679 | sess->conf_compl_supported = 1; |
| 4680 | |
| 4681 | if ((wd3_lo & BIT_4) == 0) |
| 4682 | sess->port_type = FCT_INITIATOR; |
| 4683 | else |
| 4684 | sess->port_type = FCT_TARGET; |
| 4685 | |
| 4686 | } else |
| 4687 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4688 | |
| 4689 | |
| 4690 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4691 | "%s %d %8phC DS %d\n", |
| 4692 | __func__, __LINE__, sess->port_name, sess->disc_state); |
| 4693 | |
| 4694 | switch (sess->disc_state) { |
| 4695 | case DSC_DELETED: |
| 4696 | qlt_plogi_ack_unref(vha, pla); |
| 4697 | break; |
| 4698 | |
| 4699 | default: |
| 4700 | /* |
| 4701 | * Under normal circumstances we want to release nport handle |
| 4702 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4703 | * The exception is when LOGO is done while another PLOGI with |
| 4704 | * the same nport handle is waiting as might be the case here. |
| 4705 | * Note: there is always a possibily of a race where session |
| 4706 | * deletion has already started for other reasons (e.g. ACL |
| 4707 | * removal) and now PLOGI arrives: |
| 4708 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4709 | * FW must have assigned this PLOGI a new/same handle and we |
| 4710 | * can proceed ACK'ing it as usual when session deletion |
| 4711 | * completes. |
| 4712 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4713 | * bit reached it, the handle has now been released. We'll |
| 4714 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4715 | * back to initiator. Initiator should eventually retry |
| 4716 | * PLOGI and situation will correct itself. |
| 4717 | */ |
| 4718 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4719 | (sess->d_id.b24 == port_id.b24)); |
| 4720 | |
| 4721 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4722 | "%s %d %8phC post del sess\n", |
| 4723 | __func__, __LINE__, sess->port_name); |
| 4724 | |
| 4725 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4726 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4727 | break; |
| 4728 | } |
| 4729 | out: |
| 4730 | return res; |
| 4731 | } |
| 4732 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4733 | /* |
| 4734 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4735 | */ |
| 4736 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4737 | struct imm_ntfy_from_isp *iocb) |
| 4738 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4739 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4740 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4741 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4742 | uint64_t wwn; |
| 4743 | port_id_t port_id; |
| 4744 | uint16_t loop_id; |
| 4745 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4746 | int res = 0; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4747 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4748 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4749 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4750 | |
| 4751 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4752 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4753 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4754 | port_id.b.rsvd_1 = 0; |
| 4755 | |
| 4756 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4757 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4758 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4759 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4760 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4761 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4762 | iocb->u.isp24.status_subcode, loop_id, |
| 4763 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4764 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4765 | /* res = 1 means ack at the end of thread |
| 4766 | * res = 0 means ack async/later. |
| 4767 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4768 | switch (iocb->u.isp24.status_subcode) { |
| 4769 | case ELS_PLOGI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4770 | res = qlt_handle_login(vha, iocb); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4771 | break; |
| 4772 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4773 | case ELS_PRLI: |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4774 | if (N2N_TOPO(ha)) { |
| 4775 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4776 | iocb->u.isp24.port_name, 1); |
| 4777 | |
| 4778 | if (sess && sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]) { |
| 4779 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4780 | "%s %d %8phC Term PRLI due to PLOGI ACK not completed\n", |
| 4781 | __func__, __LINE__, |
| 4782 | iocb->u.isp24.port_name); |
| 4783 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4784 | break; |
| 4785 | } |
| 4786 | |
| 4787 | res = qlt_handle_login(vha, iocb); |
| 4788 | break; |
| 4789 | } |
| 4790 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4791 | if (IS_SW_RESV_ADDR(port_id)) { |
| 4792 | res = 1; |
| 4793 | break; |
| 4794 | } |
| 4795 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4796 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4797 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4798 | if (wwn) { |
| 4799 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4800 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4801 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4802 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4803 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4804 | |
| 4805 | if (conflict_sess) { |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 4806 | switch (conflict_sess->disc_state) { |
| 4807 | case DSC_DELETED: |
| 4808 | case DSC_DELETE_PEND: |
| 4809 | break; |
| 4810 | default: |
| 4811 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4812 | "PRLI with conflicting sess %p port %8phC\n", |
| 4813 | conflict_sess, conflict_sess->port_name); |
| 4814 | conflict_sess->fw_login_state = |
| 4815 | DSC_LS_PORT_UNAVAIL; |
| 4816 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4817 | res = 0; |
| 4818 | break; |
| 4819 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4820 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4821 | |
| 4822 | if (sess != NULL) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4823 | bool delete = false; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4824 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
| 4825 | switch (sess->fw_login_state) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4826 | case DSC_LS_PLOGI_PEND: |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4827 | case DSC_LS_PLOGI_COMP: |
| 4828 | case DSC_LS_PRLI_COMP: |
| 4829 | break; |
| 4830 | default: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4831 | delete = true; |
| 4832 | break; |
| 4833 | } |
| 4834 | |
| 4835 | switch (sess->disc_state) { |
| 4836 | case DSC_LOGIN_PEND: |
| 4837 | case DSC_GPDB: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 4838 | case DSC_UPD_FCPORT: |
| 4839 | case DSC_LOGIN_COMPLETE: |
| 4840 | case DSC_ADISC: |
| 4841 | delete = false; |
| 4842 | break; |
| 4843 | default: |
| 4844 | break; |
| 4845 | } |
| 4846 | |
| 4847 | if (delete) { |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4848 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 4849 | flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4850 | /* |
| 4851 | * Impatient initiator sent PRLI before last |
| 4852 | * PLOGI could finish. Will force him to re-try, |
| 4853 | * while last one finishes. |
| 4854 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4855 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4856 | "sess %p PRLI received, before plogi ack.\n", |
| 4857 | sess); |
| 4858 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4859 | res = 0; |
| 4860 | break; |
| 4861 | } |
| 4862 | |
| 4863 | /* |
| 4864 | * This shouldn't happen under normal circumstances, |
| 4865 | * since we have deleted the old session during PLOGI |
| 4866 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4867 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4868 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 4869 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 4870 | |
| 4871 | sess->local = 0; |
| 4872 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4873 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4874 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4875 | |
| 4876 | if (wd3_lo & BIT_7) |
| 4877 | sess->conf_compl_supported = 1; |
| 4878 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4879 | if ((wd3_lo & BIT_4) == 0) |
| 4880 | sess->port_type = FCT_INITIATOR; |
| 4881 | else |
| 4882 | sess->port_type = FCT_TARGET; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 4883 | |
| 4884 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4885 | } |
| 4886 | res = 1; /* send notify ack */ |
| 4887 | |
| 4888 | /* Make session global (not used in fabric mode) */ |
| 4889 | if (ha->current_topology != ISP_CFG_F) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4890 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4891 | ql_dbg(ql_dbg_disc, vha, 0x20fa, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4892 | "%s %d %8phC post nack\n", |
| 4893 | __func__, __LINE__, sess->port_name); |
| 4894 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4895 | SRB_NACK_PRLI); |
| 4896 | res = 0; |
| 4897 | } else { |
| 4898 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4899 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4900 | qla2xxx_wake_dpc(vha); |
| 4901 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4902 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4903 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4904 | ql_dbg(ql_dbg_disc, vha, 0x20fb, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4905 | "%s %d %8phC post nack\n", |
| 4906 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4907 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4908 | SRB_NACK_PRLI); |
| 4909 | res = 0; |
| 4910 | } |
| 4911 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4912 | break; |
| 4913 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4914 | case ELS_TPRLO: |
| 4915 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 4916 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 4917 | loop_id = 0xFFFF; |
| 4918 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 4919 | res = 1; |
| 4920 | break; |
| 4921 | } |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 4922 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4923 | case ELS_LOGO: |
| 4924 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4925 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4926 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 4927 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4928 | |
| 4929 | if (sess) { |
| 4930 | sess->login_gen++; |
| 4931 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4932 | sess->logo_ack_needed = 1; |
| 4933 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 4934 | } |
| 4935 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4936 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4937 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4938 | ql_dbg(ql_dbg_disc, vha, 0x20fc, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4939 | "%s: logo %llx res %d sess %p ", |
| 4940 | __func__, wwn, res, sess); |
| 4941 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4942 | /* |
| 4943 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 4944 | * for LOGO_ACK & sess delete |
| 4945 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4946 | BUG_ON(!sess); |
| 4947 | res = 0; |
| 4948 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4949 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4950 | if (sess) { |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4951 | qlt_schedule_sess_for_deletion(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4952 | res = 0; |
| 4953 | } |
| 4954 | /* else logo will be ack */ |
| 4955 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4956 | break; |
| 4957 | case ELS_PDISC: |
| 4958 | case ELS_ADISC: |
| 4959 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4960 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4961 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4962 | qlt_send_notify_ack(ha->base_qpair, |
| 4963 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4964 | tgt->link_reinit_iocb_pending = 0; |
| 4965 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4966 | |
| 4967 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4968 | iocb->u.isp24.port_name, 1); |
| 4969 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4970 | ql_dbg(ql_dbg_disc, vha, 0x20fd, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4971 | "sess %p lid %d|%d DS %d LS %d\n", |
| 4972 | sess, sess->loop_id, loop_id, |
| 4973 | sess->disc_state, sess->fw_login_state); |
| 4974 | } |
| 4975 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4976 | res = 1; /* send notify ack */ |
| 4977 | break; |
| 4978 | } |
| 4979 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4980 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4981 | default: |
| 4982 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 4983 | "qla_target(%d): Unsupported ELS command %x " |
| 4984 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 4985 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 4986 | break; |
| 4987 | } |
| 4988 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4989 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4990 | "qla_target(%d): Exit ELS opcode: 0x%02x res %d\n", |
| 4991 | vha->vp_idx, iocb->u.isp24.status_subcode, res); |
| 4992 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4993 | return res; |
| 4994 | } |
| 4995 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4996 | /* |
| 4997 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4998 | */ |
| 4999 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 5000 | struct imm_ntfy_from_isp *iocb) |
| 5001 | { |
| 5002 | struct qla_hw_data *ha = vha->hw; |
| 5003 | uint32_t add_flags = 0; |
| 5004 | int send_notify_ack = 1; |
| 5005 | uint16_t status; |
| 5006 | |
| 5007 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 5008 | switch (status) { |
| 5009 | case IMM_NTFY_LIP_RESET: |
| 5010 | { |
| 5011 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 5012 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 5013 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5014 | iocb->u.isp24.status_subcode); |
| 5015 | |
| 5016 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5017 | send_notify_ack = 0; |
| 5018 | break; |
| 5019 | } |
| 5020 | |
| 5021 | case IMM_NTFY_LIP_LINK_REINIT: |
| 5022 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5023 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5024 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 5025 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 5026 | "subcode %x)\n", vha->vp_idx, |
| 5027 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5028 | iocb->u.isp24.status_subcode); |
| 5029 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5030 | qlt_send_notify_ack(ha->base_qpair, |
| 5031 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5032 | } |
| 5033 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 5034 | tgt->link_reinit_iocb_pending = 1; |
| 5035 | /* |
| 5036 | * QLogic requires to wait after LINK REINIT for possible |
| 5037 | * PDISC or ADISC ELS commands |
| 5038 | */ |
| 5039 | send_notify_ack = 0; |
| 5040 | break; |
| 5041 | } |
| 5042 | |
| 5043 | case IMM_NTFY_PORT_LOGOUT: |
| 5044 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 5045 | "qla_target(%d): Port logout (loop " |
| 5046 | "%#x, subcode %x)\n", vha->vp_idx, |
| 5047 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5048 | iocb->u.isp24.status_subcode); |
| 5049 | |
| 5050 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 5051 | send_notify_ack = 0; |
| 5052 | /* The sessions will be cleared in the callback, if needed */ |
| 5053 | break; |
| 5054 | |
| 5055 | case IMM_NTFY_GLBL_TPRLO: |
| 5056 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 5057 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 5058 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5059 | send_notify_ack = 0; |
| 5060 | /* The sessions will be cleared in the callback, if needed */ |
| 5061 | break; |
| 5062 | |
| 5063 | case IMM_NTFY_PORT_CONFIG: |
| 5064 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 5065 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 5066 | status); |
| 5067 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5068 | send_notify_ack = 0; |
| 5069 | /* The sessions will be cleared in the callback, if needed */ |
| 5070 | break; |
| 5071 | |
| 5072 | case IMM_NTFY_GLBL_LOGO: |
| 5073 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 5074 | "qla_target(%d): Link failure detected\n", |
| 5075 | vha->vp_idx); |
| 5076 | /* I_T nexus loss */ |
| 5077 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5078 | send_notify_ack = 0; |
| 5079 | break; |
| 5080 | |
| 5081 | case IMM_NTFY_IOCB_OVERFLOW: |
| 5082 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 5083 | "qla_target(%d): Cannot provide requested " |
| 5084 | "capability (IOCB overflowed the immediate notify " |
| 5085 | "resource count)\n", vha->vp_idx); |
| 5086 | break; |
| 5087 | |
| 5088 | case IMM_NTFY_ABORT_TASK: |
| 5089 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 5090 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 5091 | "L %#x)\n", vha->vp_idx, |
| 5092 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 5093 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 5094 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 5095 | if (qlt_abort_task(vha, iocb) == 0) |
| 5096 | send_notify_ack = 0; |
| 5097 | break; |
| 5098 | |
| 5099 | case IMM_NTFY_RESOURCE: |
| 5100 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 5101 | "qla_target(%d): Out of resources, host %ld\n", |
| 5102 | vha->vp_idx, vha->host_no); |
| 5103 | break; |
| 5104 | |
| 5105 | case IMM_NTFY_MSG_RX: |
| 5106 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 5107 | "qla_target(%d): Immediate notify task %x\n", |
| 5108 | vha->vp_idx, iocb->u.isp2x.task_flags); |
| 5109 | if (qlt_handle_task_mgmt(vha, iocb) == 0) |
| 5110 | send_notify_ack = 0; |
| 5111 | break; |
| 5112 | |
| 5113 | case IMM_NTFY_ELS: |
| 5114 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 5115 | send_notify_ack = 0; |
| 5116 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5117 | default: |
| 5118 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 5119 | "qla_target(%d): Received unknown immediate " |
| 5120 | "notify status %x\n", vha->vp_idx, status); |
| 5121 | break; |
| 5122 | } |
| 5123 | |
| 5124 | if (send_notify_ack) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5125 | qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0, |
| 5126 | 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | /* |
| 5130 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5131 | * This function sends busy to ISP 2xxx or 24xx. |
| 5132 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5133 | static int __qlt_send_busy(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5134 | struct atio_from_isp *atio, uint16_t status) |
| 5135 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5136 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5137 | struct ctio7_to_24xx *ctio24; |
| 5138 | struct qla_hw_data *ha = vha->hw; |
| 5139 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5140 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5141 | unsigned long flags; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5142 | u16 temp; |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame^] | 5143 | port_id_t id; |
| 5144 | |
| 5145 | id.b.al_pa = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5146 | id.b.area = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5147 | id.b.domain = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5148 | id.b.rsvd_1 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5149 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5150 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 8ea4faf | 2018-05-01 09:01:49 -0700 | [diff] [blame^] | 5151 | sess = qla2x00_find_fcport_by_nportid(vha, &id, 1); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5152 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5153 | if (!sess) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5154 | qlt_send_term_exchange(qpair, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5155 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5156 | } |
| 5157 | /* Sending marker isn't necessary, since we called from ISR */ |
| 5158 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5159 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5160 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5161 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5162 | "qla_target(%d): %s failed: unable to allocate " |
| 5163 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5164 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5165 | } |
| 5166 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5167 | qpair->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5168 | pkt->entry_count = 1; |
| 5169 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5170 | |
| 5171 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5172 | ctio24->entry_type = CTIO_TYPE7; |
| 5173 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5174 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5175 | ctio24->vp_index = vha->vp_idx; |
| 5176 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5177 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5178 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5179 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5180 | temp = (atio->u.isp24.attr << 9) | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5181 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5182 | CTIO7_FLAGS_DONT_RET_CTIO; |
| 5183 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5184 | /* |
| 5185 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5186 | * if the explicit conformation is used. |
| 5187 | */ |
| 5188 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 5189 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5190 | /* Memory Barrier */ |
| 5191 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 5192 | if (qpair->reqq_start_iocbs) |
| 5193 | qpair->reqq_start_iocbs(qpair); |
| 5194 | else |
| 5195 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5196 | return 0; |
| 5197 | } |
| 5198 | |
| 5199 | /* |
| 5200 | * This routine is used to allocate a command for either a QFull condition |
| 5201 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5202 | * out previously. |
| 5203 | */ |
| 5204 | static void |
| 5205 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5206 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5207 | { |
| 5208 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5209 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5210 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5211 | struct se_session *se_sess; |
| 5212 | struct qla_tgt_cmd *cmd; |
| 5213 | int tag; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5214 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5215 | |
| 5216 | if (unlikely(tgt->tgt_stop)) { |
| 5217 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5218 | "New command while device %p is shutting down\n", tgt); |
| 5219 | return; |
| 5220 | } |
| 5221 | |
| 5222 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5223 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5224 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5225 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5226 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5227 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5228 | |
| 5229 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5230 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5231 | vha->vp_idx, __func__, |
| 5232 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5233 | |
| 5234 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5235 | return; |
| 5236 | } |
| 5237 | |
| 5238 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5239 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5240 | if (!sess) |
| 5241 | return; |
| 5242 | |
| 5243 | se_sess = sess->se_sess; |
| 5244 | |
| 5245 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 5246 | if (tag < 0) |
| 5247 | return; |
| 5248 | |
| 5249 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 5250 | if (!cmd) { |
| 5251 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5252 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5253 | vha->vp_idx, __func__); |
| 5254 | |
| 5255 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5256 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5257 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5258 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5259 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5260 | |
| 5261 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5262 | return; |
| 5263 | } |
| 5264 | |
| 5265 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 5266 | |
| 5267 | qlt_incr_num_pend_cmds(vha); |
| 5268 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5269 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5270 | |
| 5271 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5272 | cmd->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5273 | cmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5274 | cmd->q_full = 1; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5275 | cmd->qpair = ha->base_qpair; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5276 | |
| 5277 | if (qfull) { |
| 5278 | cmd->q_full = 1; |
| 5279 | /* NOTE: borrowing the state field to carry the status */ |
| 5280 | cmd->state = status; |
| 5281 | } else |
| 5282 | cmd->term_exchg = 1; |
| 5283 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5284 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5285 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5286 | |
| 5287 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5288 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5289 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5290 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5291 | vha->hw->tgt.num_qfull_cmds_alloc; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5292 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5296 | qlt_free_qfull_cmds(struct qla_qpair *qpair) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5297 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5298 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5299 | struct qla_hw_data *ha = vha->hw; |
| 5300 | unsigned long flags; |
| 5301 | struct qla_tgt_cmd *cmd, *tcmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5302 | struct list_head free_list, q_full_list; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5303 | int rc = 0; |
| 5304 | |
| 5305 | if (list_empty(&ha->tgt.q_full_list)) |
| 5306 | return 0; |
| 5307 | |
| 5308 | INIT_LIST_HEAD(&free_list); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5309 | INIT_LIST_HEAD(&q_full_list); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5310 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5311 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5312 | if (list_empty(&ha->tgt.q_full_list)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5313 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5314 | return 0; |
| 5315 | } |
| 5316 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5317 | list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list); |
| 5318 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5319 | |
| 5320 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 5321 | list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5322 | if (cmd->q_full) |
| 5323 | /* cmd->state is a borrowed field to hold status */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5324 | rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5325 | else if (cmd->term_exchg) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5326 | rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5327 | |
| 5328 | if (rc == -ENOMEM) |
| 5329 | break; |
| 5330 | |
| 5331 | if (cmd->q_full) |
| 5332 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5333 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5334 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5335 | else if (cmd->term_exchg) |
| 5336 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5337 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5338 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5339 | else |
| 5340 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5341 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5342 | cmd); |
| 5343 | |
| 5344 | list_del(&cmd->cmd_list); |
| 5345 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5346 | |
| 5347 | /* piggy back on hardware_lock for protection */ |
| 5348 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5349 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5350 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5351 | |
| 5352 | cmd = NULL; |
| 5353 | |
| 5354 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5355 | list_del(&cmd->cmd_list); |
| 5356 | /* This cmd was never sent to TCM. There is no need |
| 5357 | * to schedule free or call free_cmd |
| 5358 | */ |
| 5359 | qlt_free_cmd(cmd); |
| 5360 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5361 | |
| 5362 | if (!list_empty(&q_full_list)) { |
| 5363 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 5364 | list_splice(&q_full_list, &vha->hw->tgt.q_full_list); |
| 5365 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5366 | } |
| 5367 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5368 | return rc; |
| 5369 | } |
| 5370 | |
| 5371 | static void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5372 | qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio, |
| 5373 | uint16_t status) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5374 | { |
| 5375 | int rc = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5376 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5377 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5378 | rc = __qlt_send_busy(qpair, atio, status); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5379 | if (rc == -ENOMEM) |
| 5380 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5381 | } |
| 5382 | |
| 5383 | static int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5384 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair, |
| 5385 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5386 | { |
| 5387 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5388 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5389 | |
| 5390 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5391 | return 0; |
| 5392 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5393 | if (!ha_locked) |
| 5394 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5395 | qlt_send_busy(qpair, atio, qla_sam_status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5396 | if (!ha_locked) |
| 5397 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5398 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5399 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | /* ha->hardware_lock supposed to be held on entry */ |
| 5403 | /* called via callback from qla2xxx */ |
| 5404 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5405 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5406 | { |
| 5407 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5408 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5409 | int rc; |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5410 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5411 | |
| 5412 | if (unlikely(tgt == NULL)) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5413 | ql_dbg(ql_dbg_tgt, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5414 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5415 | return; |
| 5416 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5417 | /* |
| 5418 | * In tgt_stop mode we also should allow all requests to pass. |
| 5419 | * Otherwise, some commands can stuck. |
| 5420 | */ |
| 5421 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5422 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5423 | |
| 5424 | switch (atio->u.raw.entry_type) { |
| 5425 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5426 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5427 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5428 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5429 | "qla_target(%d): ATIO_TYPE7 " |
| 5430 | "received with UNKNOWN exchange address, " |
| 5431 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5432 | if (!ha_locked) |
| 5433 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5434 | qlt_send_busy(ha->base_qpair, atio, qla_sam_status); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5435 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5436 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5437 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5438 | break; |
| 5439 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5440 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5441 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5442 | rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair, |
| 5443 | atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5444 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5445 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5446 | return; |
| 5447 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5448 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5449 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5450 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5451 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5452 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5453 | if (!ha_locked) |
| 5454 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5455 | switch (rc) { |
| 5456 | case -ENODEV: |
| 5457 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5458 | "qla_target: Unable to send command to target\n"); |
| 5459 | break; |
| 5460 | case -EBADF: |
| 5461 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5462 | "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] | 5463 | qlt_send_term_exchange(ha->base_qpair, NULL, |
| 5464 | atio, 1, 0); |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5465 | break; |
| 5466 | case -EBUSY: |
| 5467 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5468 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5469 | vha->vp_idx); |
| 5470 | qlt_send_busy(ha->base_qpair, atio, |
| 5471 | tc_sam_status); |
| 5472 | break; |
| 5473 | default: |
| 5474 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5475 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5476 | vha->vp_idx); |
| 5477 | qlt_send_busy(ha->base_qpair, atio, |
| 5478 | qla_sam_status); |
| 5479 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5480 | } |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5481 | if (!ha_locked) |
| 5482 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5483 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5484 | } |
| 5485 | break; |
| 5486 | |
| 5487 | case IMMED_NOTIFY_TYPE: |
| 5488 | { |
| 5489 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5490 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5491 | "qla_target(%d): Received ATIO packet %x " |
| 5492 | "with error status %x\n", vha->vp_idx, |
| 5493 | atio->u.raw.entry_type, |
| 5494 | atio->u.isp2x.entry_status); |
| 5495 | break; |
| 5496 | } |
| 5497 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5498 | |
| 5499 | if (!ha_locked) |
| 5500 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5501 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5502 | if (!ha_locked) |
| 5503 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5504 | break; |
| 5505 | } |
| 5506 | |
| 5507 | default: |
| 5508 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5509 | "qla_target(%d): Received unknown ATIO atio " |
| 5510 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5511 | break; |
| 5512 | } |
| 5513 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5514 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | /* ha->hardware_lock supposed to be held on entry */ |
| 5518 | /* called via callback from qla2xxx */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5519 | static void qlt_response_pkt(struct scsi_qla_host *vha, |
| 5520 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5521 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5522 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5523 | |
| 5524 | if (unlikely(tgt == NULL)) { |
| 5525 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5526 | "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n", |
| 5527 | vha->vp_idx, pkt->entry_type, vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5528 | return; |
| 5529 | } |
| 5530 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5531 | /* |
| 5532 | * In tgt_stop mode we also should allow all requests to pass. |
| 5533 | * Otherwise, some commands can stuck. |
| 5534 | */ |
| 5535 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5536 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5537 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5538 | case CTIO_TYPE7: |
| 5539 | { |
| 5540 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5541 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5542 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5543 | entry); |
| 5544 | break; |
| 5545 | } |
| 5546 | |
| 5547 | case ACCEPT_TGT_IO_TYPE: |
| 5548 | { |
| 5549 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5550 | int rc; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5551 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5552 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5553 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5554 | "qla_target(%d): ATIO with error " |
| 5555 | "status %x received\n", vha->vp_idx, |
| 5556 | le16_to_cpu(atio->u.isp2x.status)); |
| 5557 | break; |
| 5558 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5559 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5560 | rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1); |
Quinn Tran | ba68a63 | 2017-06-02 09:12:06 -0700 | [diff] [blame] | 5561 | if (rc != 0) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5562 | return; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5563 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5564 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5565 | if (unlikely(rc != 0)) { |
Quinn Tran | 7cf95f7 | 2017-12-28 12:33:28 -0800 | [diff] [blame] | 5566 | switch (rc) { |
| 5567 | case -ENODEV: |
| 5568 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5569 | "qla_target: Unable to send command to target\n"); |
| 5570 | break; |
| 5571 | case -EBADF: |
| 5572 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5573 | "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); |
| 5574 | qlt_send_term_exchange(rsp->qpair, NULL, |
| 5575 | atio, 1, 0); |
| 5576 | break; |
| 5577 | case -EBUSY: |
| 5578 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5579 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5580 | vha->vp_idx); |
| 5581 | qlt_send_busy(rsp->qpair, atio, |
| 5582 | tc_sam_status); |
| 5583 | break; |
| 5584 | default: |
| 5585 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5586 | "qla_target(%d): Unable to send command to target, sending BUSY status\n", |
| 5587 | vha->vp_idx); |
| 5588 | qlt_send_busy(rsp->qpair, atio, |
| 5589 | qla_sam_status); |
| 5590 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5591 | } |
| 5592 | } |
| 5593 | } |
| 5594 | break; |
| 5595 | |
| 5596 | case CONTINUE_TGT_IO_TYPE: |
| 5597 | { |
| 5598 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5599 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5600 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5601 | entry); |
| 5602 | break; |
| 5603 | } |
| 5604 | |
| 5605 | case CTIO_A64_TYPE: |
| 5606 | { |
| 5607 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5608 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5609 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5610 | entry); |
| 5611 | break; |
| 5612 | } |
| 5613 | |
| 5614 | case IMMED_NOTIFY_TYPE: |
| 5615 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5616 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5617 | break; |
| 5618 | |
| 5619 | case NOTIFY_ACK_TYPE: |
| 5620 | if (tgt->notify_ack_expected > 0) { |
| 5621 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 5622 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5623 | "NOTIFY_ACK seq %08x status %x\n", |
| 5624 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5625 | le16_to_cpu(entry->u.isp2x.status)); |
| 5626 | tgt->notify_ack_expected--; |
| 5627 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5628 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5629 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5630 | "qla_target(%d): NOTIFY_ACK " |
| 5631 | "failed %x\n", vha->vp_idx, |
| 5632 | le16_to_cpu(entry->u.isp2x.status)); |
| 5633 | } |
| 5634 | } else { |
| 5635 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5636 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5637 | vha->vp_idx); |
| 5638 | } |
| 5639 | break; |
| 5640 | |
| 5641 | case ABTS_RECV_24XX: |
| 5642 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5643 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5644 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5645 | break; |
| 5646 | |
| 5647 | case ABTS_RESP_24XX: |
| 5648 | if (tgt->abts_resp_expected > 0) { |
| 5649 | struct abts_resp_from_24xx_fw *entry = |
| 5650 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5651 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5652 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5653 | entry->compl_status); |
| 5654 | tgt->abts_resp_expected--; |
| 5655 | if (le16_to_cpu(entry->compl_status) != |
| 5656 | ABTS_RESP_COMPL_SUCCESS) { |
| 5657 | if ((entry->error_subcode1 == 0x1E) && |
| 5658 | (entry->error_subcode2 == 0)) { |
| 5659 | /* |
| 5660 | * We've got a race here: aborted |
| 5661 | * exchange not terminated, i.e. |
| 5662 | * response for the aborted command was |
| 5663 | * sent between the abort request was |
| 5664 | * received and processed. |
| 5665 | * Unfortunately, the firmware has a |
| 5666 | * silly requirement that all aborted |
| 5667 | * exchanges must be explicitely |
| 5668 | * terminated, otherwise it refuses to |
| 5669 | * send responses for the abort |
| 5670 | * requests. So, we have to |
| 5671 | * (re)terminate the exchange and retry |
| 5672 | * the abort response. |
| 5673 | */ |
| 5674 | qlt_24xx_retry_term_exchange(vha, |
| 5675 | entry); |
| 5676 | } else |
| 5677 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5678 | "qla_target(%d): ABTS_RESP_24XX " |
| 5679 | "failed %x (subcode %x:%x)", |
| 5680 | vha->vp_idx, entry->compl_status, |
| 5681 | entry->error_subcode1, |
| 5682 | entry->error_subcode2); |
| 5683 | } |
| 5684 | } else { |
| 5685 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5686 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5687 | "received\n", vha->vp_idx); |
| 5688 | } |
| 5689 | break; |
| 5690 | |
| 5691 | default: |
| 5692 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5693 | "qla_target(%d): Received unknown response pkt " |
| 5694 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5695 | break; |
| 5696 | } |
| 5697 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | /* |
| 5701 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5702 | */ |
| 5703 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5704 | uint16_t *mailbox) |
| 5705 | { |
| 5706 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5707 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5708 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5709 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 5710 | if (!tgt || tgt->tgt_stop || tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5711 | return; |
| 5712 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5713 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5714 | IS_QLA2100(ha)) |
| 5715 | return; |
| 5716 | /* |
| 5717 | * In tgt_stop mode we also should allow all requests to pass. |
| 5718 | * Otherwise, some commands can stuck. |
| 5719 | */ |
| 5720 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5721 | |
| 5722 | switch (code) { |
| 5723 | case MBA_RESET: /* Reset */ |
| 5724 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5725 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5726 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5727 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5728 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5729 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5730 | break; |
| 5731 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5732 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5733 | break; |
| 5734 | |
| 5735 | case MBA_LOOP_UP: |
| 5736 | { |
| 5737 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5738 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5739 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5740 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5741 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5742 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5743 | qlt_send_notify_ack(ha->base_qpair, |
| 5744 | (void *)&tgt->link_reinit_iocb, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5745 | 0, 0, 0, 0, 0, 0); |
| 5746 | tgt->link_reinit_iocb_pending = 0; |
| 5747 | } |
| 5748 | break; |
| 5749 | } |
| 5750 | |
| 5751 | case MBA_LIP_OCCURRED: |
| 5752 | case MBA_LOOP_DOWN: |
| 5753 | case MBA_LIP_RESET: |
| 5754 | case MBA_RSCN_UPDATE: |
| 5755 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5756 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5757 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5758 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5759 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5760 | break; |
| 5761 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5762 | case MBA_REJECTED_FCP_CMD: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5763 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017, |
| 5764 | "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", |
| 5765 | vha->vp_idx, |
| 5766 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5767 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5768 | |
| 5769 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 5770 | /* exchange starvation. */ |
| 5771 | vha->hw->exch_starvation++; |
| 5772 | if (vha->hw->exch_starvation > 5) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5773 | ql_log(ql_log_warn, vha, 0xd03a, |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5774 | "Exchange starvation-. Resetting RISC\n"); |
| 5775 | |
| 5776 | vha->hw->exch_starvation = 0; |
| 5777 | if (IS_P3P_TYPE(vha->hw)) |
| 5778 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 5779 | &vha->dpc_flags); |
| 5780 | else |
| 5781 | set_bit(ISP_ABORT_NEEDED, |
| 5782 | &vha->dpc_flags); |
| 5783 | qla2xxx_wake_dpc(vha); |
| 5784 | } |
| 5785 | } |
| 5786 | break; |
| 5787 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5788 | case MBA_PORT_UPDATE: |
| 5789 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5790 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5791 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5792 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5793 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5794 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5795 | |
| 5796 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5797 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5798 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 5799 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5800 | vha->hw->exch_starvation = 0; |
| 5801 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5802 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 5803 | "Async MB 2: Port Logged Out\n"); |
| 5804 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5805 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5806 | break; |
| 5807 | } |
| 5808 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 5812 | uint16_t loop_id) |
| 5813 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5814 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5815 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5816 | unsigned long flags; |
| 5817 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5818 | |
Quinn Tran | 063b36d | 2017-12-04 14:45:10 -0800 | [diff] [blame] | 5819 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5820 | if (!fcport) { |
| 5821 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 5822 | "qla_target(%d): Allocation of tmp FC port failed", |
| 5823 | vha->vp_idx); |
| 5824 | return NULL; |
| 5825 | } |
| 5826 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5827 | fcport->loop_id = loop_id; |
| 5828 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 5829 | rc = qla24xx_gpdb_wait(vha, fcport, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5830 | if (rc != QLA_SUCCESS) { |
| 5831 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 5832 | "qla_target(%d): Failed to retrieve fcport " |
| 5833 | "information -- get_port_database() returned %x " |
| 5834 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 5835 | kfree(fcport); |
| 5836 | return NULL; |
| 5837 | } |
| 5838 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5839 | del = NULL; |
| 5840 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5841 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 5842 | |
| 5843 | if (tfcp) { |
| 5844 | tfcp->d_id = fcport->d_id; |
| 5845 | tfcp->port_type = fcport->port_type; |
| 5846 | tfcp->supported_classes = fcport->supported_classes; |
| 5847 | tfcp->flags |= fcport->flags; |
Quinn Tran | 76f9a2d | 2017-12-04 14:45:11 -0800 | [diff] [blame] | 5848 | tfcp->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5849 | |
| 5850 | del = fcport; |
| 5851 | fcport = tfcp; |
| 5852 | } else { |
| 5853 | if (vha->hw->current_topology == ISP_CFG_F) |
| 5854 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 5855 | |
| 5856 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 5857 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 5858 | vha->fcport_count++; |
| 5859 | fcport->login_gen++; |
| 5860 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 5861 | fcport->login_succ = 1; |
| 5862 | newfcport = 1; |
| 5863 | } |
| 5864 | |
| 5865 | fcport->deleted = 0; |
| 5866 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5867 | |
| 5868 | switch (vha->host->active_mode) { |
| 5869 | case MODE_INITIATOR: |
| 5870 | case MODE_DUAL: |
| 5871 | if (newfcport) { |
| 5872 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5873 | ql_dbg(ql_dbg_disc, vha, 0x20fe, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5874 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 5875 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5876 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 5877 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5878 | ql_dbg(ql_dbg_disc, vha, 0x20ff, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5879 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 5880 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5881 | qla24xx_post_gpsc_work(vha, fcport); |
| 5882 | } |
| 5883 | } |
| 5884 | break; |
| 5885 | |
| 5886 | case MODE_TARGET: |
| 5887 | default: |
| 5888 | break; |
| 5889 | } |
| 5890 | if (del) |
| 5891 | qla2x00_free_fcport(del); |
| 5892 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5893 | return fcport; |
| 5894 | } |
| 5895 | |
| 5896 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5897 | 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] | 5898 | uint8_t *s_id) |
| 5899 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5900 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5901 | fc_port_t *fcport = NULL; |
| 5902 | int rc, global_resets; |
| 5903 | uint16_t loop_id = 0; |
| 5904 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5905 | if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) { |
| 5906 | /* |
| 5907 | * This is Domain Controller, so it should be |
| 5908 | * OK to drop SCSI commands from it. |
| 5909 | */ |
| 5910 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 5911 | "Unable to find initiator with S_ID %x:%x:%x", |
| 5912 | s_id[0], s_id[1], s_id[2]); |
| 5913 | return NULL; |
| 5914 | } |
| 5915 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5916 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 5917 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5918 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5919 | global_resets = |
| 5920 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5921 | |
| 5922 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 5923 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5924 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5925 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5926 | ql_log(ql_log_info, vha, 0xf071, |
| 5927 | "qla_target(%d): Unable to find " |
| 5928 | "initiator with S_ID %x:%x:%x", |
| 5929 | vha->vp_idx, s_id[0], s_id[1], |
| 5930 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5931 | |
| 5932 | if (rc == -ENOENT) { |
| 5933 | qlt_port_logo_t logo; |
| 5934 | sid_to_portid(s_id, &logo.id); |
| 5935 | logo.cmd_count = 1; |
| 5936 | qlt_send_first_logo(vha, &logo); |
| 5937 | } |
| 5938 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5939 | return NULL; |
| 5940 | } |
| 5941 | |
| 5942 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5943 | if (!fcport) { |
| 5944 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5945 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5946 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5947 | |
| 5948 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5949 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5950 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 5951 | "qla_target(%d): global reset during session discovery " |
| 5952 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 5953 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5954 | atomic_read(&vha->vha_tgt. |
| 5955 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5956 | goto retry; |
| 5957 | } |
| 5958 | |
| 5959 | sess = qlt_create_sess(vha, fcport, true); |
| 5960 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5961 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5962 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5963 | return sess; |
| 5964 | } |
| 5965 | |
| 5966 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 5967 | struct qla_tgt_sess_work_param *prm) |
| 5968 | { |
| 5969 | struct scsi_qla_host *vha = tgt->vha; |
| 5970 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5971 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5972 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5973 | uint32_t be_s_id; |
| 5974 | uint8_t s_id[3]; |
| 5975 | int rc; |
| 5976 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5977 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5978 | |
| 5979 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5980 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5981 | |
| 5982 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 5983 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 5984 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 5985 | |
| 5986 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5987 | (unsigned char *)&be_s_id); |
| 5988 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5989 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5990 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5991 | sess = qlt_make_local_sess(vha, s_id); |
| 5992 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5993 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5994 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5995 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5996 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5997 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5998 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5999 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6000 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6001 | } |
| 6002 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6003 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6004 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6005 | "%s: kref_get fail %8phC \n", |
| 6006 | __func__, sess->port_name); |
| 6007 | sess = NULL; |
| 6008 | goto out_term2; |
| 6009 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6010 | } |
| 6011 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6012 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6013 | ha->tgt.tgt_ops->put_sess(sess); |
| 6014 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 6015 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6016 | if (rc != 0) |
| 6017 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6018 | return; |
| 6019 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6020 | out_term2: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6021 | if (sess) |
| 6022 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6023 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6024 | |
| 6025 | out_term: |
| 6026 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6027 | qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts, |
| 6028 | FCP_TMF_REJECTED, false); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6029 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 6033 | struct qla_tgt_sess_work_param *prm) |
| 6034 | { |
| 6035 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 6036 | struct scsi_qla_host *vha = tgt->vha; |
| 6037 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6038 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6039 | unsigned long flags; |
| 6040 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 6041 | int rc; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6042 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 6043 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6044 | void *iocb; |
| 6045 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6046 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6047 | |
| 6048 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6049 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6050 | |
| 6051 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 6052 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 6053 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6054 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6055 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6056 | sess = qlt_make_local_sess(vha, s_id); |
| 6057 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6058 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6059 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6060 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6061 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6062 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6063 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6064 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6065 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6066 | } |
| 6067 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6068 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6069 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6070 | "%s: kref_get fail %8phC\n", |
| 6071 | __func__, sess->port_name); |
| 6072 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6073 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6074 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | iocb = a; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6078 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6079 | unpacked_lun = |
| 6080 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6081 | |
| 6082 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6083 | ha->tgt.tgt_ops->put_sess(sess); |
| 6084 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 6085 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6086 | if (rc != 0) |
| 6087 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6088 | return; |
| 6089 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6090 | out_term2: |
| 6091 | if (sess) |
| 6092 | ha->tgt.tgt_ops->put_sess(sess); |
| 6093 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6094 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6095 | 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] | 6096 | } |
| 6097 | |
| 6098 | static void qlt_sess_work_fn(struct work_struct *work) |
| 6099 | { |
| 6100 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 6101 | struct scsi_qla_host *vha = tgt->vha; |
| 6102 | unsigned long flags; |
| 6103 | |
| 6104 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 6105 | |
| 6106 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6107 | while (!list_empty(&tgt->sess_works_list)) { |
| 6108 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 6109 | tgt->sess_works_list.next, typeof(*prm), |
| 6110 | sess_works_list_entry); |
| 6111 | |
| 6112 | /* |
| 6113 | * This work can be scheduled on several CPUs at time, so we |
| 6114 | * must delete the entry to eliminate double processing |
| 6115 | */ |
| 6116 | list_del(&prm->sess_works_list_entry); |
| 6117 | |
| 6118 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6119 | |
| 6120 | switch (prm->type) { |
| 6121 | case QLA_TGT_SESS_WORK_ABORT: |
| 6122 | qlt_abort_work(tgt, prm); |
| 6123 | break; |
| 6124 | case QLA_TGT_SESS_WORK_TM: |
| 6125 | qlt_tmr_work(tgt, prm); |
| 6126 | break; |
| 6127 | default: |
| 6128 | BUG_ON(1); |
| 6129 | break; |
| 6130 | } |
| 6131 | |
| 6132 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6133 | |
| 6134 | kfree(prm); |
| 6135 | } |
| 6136 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6137 | } |
| 6138 | |
| 6139 | /* Must be called under tgt_host_action_mutex */ |
| 6140 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 6141 | { |
| 6142 | struct qla_tgt *tgt; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6143 | int rc, i; |
| 6144 | struct qla_qpair_hint *h; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6145 | |
| 6146 | if (!QLA_TGT_MODE_ENABLED()) |
| 6147 | return 0; |
| 6148 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 6149 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 6150 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 6151 | "This adapter does not support target mode.\n"); |
| 6152 | return 0; |
| 6153 | } |
| 6154 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6155 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6156 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6157 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6158 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6159 | |
| 6160 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 6161 | if (!tgt) { |
| 6162 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 6163 | "Unable to allocate struct qla_tgt\n"); |
| 6164 | return -ENOMEM; |
| 6165 | } |
| 6166 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6167 | tgt->qphints = kzalloc((ha->max_qpairs + 1) * |
| 6168 | sizeof(struct qla_qpair_hint), GFP_KERNEL); |
| 6169 | if (!tgt->qphints) { |
| 6170 | kfree(tgt); |
| 6171 | ql_log(ql_log_warn, base_vha, 0x0197, |
| 6172 | "Unable to allocate qpair hints.\n"); |
| 6173 | return -ENOMEM; |
| 6174 | } |
| 6175 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6176 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 6177 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 6178 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6179 | rc = btree_init64(&tgt->lun_qpair_map); |
| 6180 | if (rc) { |
| 6181 | kfree(tgt->qphints); |
| 6182 | kfree(tgt); |
| 6183 | ql_log(ql_log_info, base_vha, 0x0198, |
| 6184 | "Unable to initialize lun_qpair_map btree\n"); |
| 6185 | return -EIO; |
| 6186 | } |
| 6187 | h = &tgt->qphints[0]; |
| 6188 | h->qpair = ha->base_qpair; |
| 6189 | INIT_LIST_HEAD(&h->hint_elem); |
| 6190 | h->cpuid = ha->base_qpair->cpuid; |
| 6191 | list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list); |
| 6192 | |
| 6193 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6194 | unsigned long flags; |
| 6195 | |
| 6196 | struct qla_qpair *qpair = ha->queue_pair_map[i]; |
| 6197 | h = &tgt->qphints[i + 1]; |
| 6198 | INIT_LIST_HEAD(&h->hint_elem); |
| 6199 | if (qpair) { |
| 6200 | h->qpair = qpair; |
| 6201 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 6202 | list_add_tail(&h->hint_elem, &qpair->hints_list); |
| 6203 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 6204 | h->cpuid = qpair->cpuid; |
| 6205 | } |
| 6206 | } |
| 6207 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6208 | tgt->ha = ha; |
| 6209 | tgt->vha = base_vha; |
| 6210 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6211 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6212 | spin_lock_init(&tgt->sess_work_lock); |
| 6213 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6214 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6215 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6216 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6217 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6218 | |
| 6219 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6220 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6221 | base_vha->vp_idx); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6222 | /* 3 is reserved */ |
| 6223 | 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] | 6224 | |
| 6225 | mutex_lock(&qla_tgt_mutex); |
| 6226 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6227 | mutex_unlock(&qla_tgt_mutex); |
| 6228 | |
Quinn Tran | f1443ee | 2017-03-15 09:48:51 -0700 | [diff] [blame] | 6229 | if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target) |
| 6230 | ha->tgt.tgt_ops->add_target(base_vha); |
| 6231 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6232 | return 0; |
| 6233 | } |
| 6234 | |
| 6235 | /* Must be called under tgt_host_action_mutex */ |
| 6236 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6237 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6238 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6239 | return 0; |
| 6240 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6241 | if (vha->fc_vport) { |
| 6242 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6243 | return 0; |
| 6244 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6245 | |
| 6246 | /* free left over qfull cmds */ |
| 6247 | qlt_init_term_exchange(vha); |
| 6248 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6249 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6250 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6251 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6252 | |
| 6253 | return 0; |
| 6254 | } |
| 6255 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6256 | void qlt_remove_target_resources(struct qla_hw_data *ha) |
| 6257 | { |
| 6258 | struct scsi_qla_host *node; |
| 6259 | u32 key = 0; |
| 6260 | |
| 6261 | btree_for_each_safe32(&ha->tgt.host_map, key, node) |
| 6262 | btree_remove32(&ha->tgt.host_map, key); |
| 6263 | |
| 6264 | btree_destroy32(&ha->tgt.host_map); |
| 6265 | } |
| 6266 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6267 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6268 | unsigned char *b) |
| 6269 | { |
| 6270 | int i; |
| 6271 | |
| 6272 | pr_debug("qla2xxx HW vha->node_name: "); |
| 6273 | for (i = 0; i < WWN_SIZE; i++) |
| 6274 | pr_debug("%02x ", vha->node_name[i]); |
| 6275 | pr_debug("\n"); |
| 6276 | pr_debug("qla2xxx HW vha->port_name: "); |
| 6277 | for (i = 0; i < WWN_SIZE; i++) |
| 6278 | pr_debug("%02x ", vha->port_name[i]); |
| 6279 | pr_debug("\n"); |
| 6280 | |
| 6281 | pr_debug("qla2xxx passed configfs WWPN: "); |
| 6282 | put_unaligned_be64(wwpn, b); |
| 6283 | for (i = 0; i < WWN_SIZE; i++) |
| 6284 | pr_debug("%02x ", b[i]); |
| 6285 | pr_debug("\n"); |
| 6286 | } |
| 6287 | |
| 6288 | /** |
| 6289 | * qla_tgt_lport_register - register lport with external module |
| 6290 | * |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6291 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 6292 | * @phys_wwpn: |
| 6293 | * @npiv_wwpn: |
| 6294 | * @npiv_wwnn: |
| 6295 | * @callback: lport initialization callback for tcm_qla2xxx code |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6296 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6297 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6298 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6299 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6300 | { |
| 6301 | struct qla_tgt *tgt; |
| 6302 | struct scsi_qla_host *vha; |
| 6303 | struct qla_hw_data *ha; |
| 6304 | struct Scsi_Host *host; |
| 6305 | unsigned long flags; |
| 6306 | int rc; |
| 6307 | u8 b[WWN_SIZE]; |
| 6308 | |
| 6309 | mutex_lock(&qla_tgt_mutex); |
| 6310 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6311 | vha = tgt->vha; |
| 6312 | ha = vha->hw; |
| 6313 | |
| 6314 | host = vha->host; |
| 6315 | if (!host) |
| 6316 | continue; |
| 6317 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6318 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6319 | continue; |
| 6320 | |
| 6321 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6322 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6323 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6324 | host->host_no); |
| 6325 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6326 | continue; |
| 6327 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6328 | if (tgt->tgt_stop) { |
| 6329 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6330 | host->host_no); |
| 6331 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6332 | continue; |
| 6333 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6334 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6335 | |
| 6336 | if (!scsi_host_get(host)) { |
| 6337 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6338 | "Unable to scsi_host_get() for" |
| 6339 | " qla2xxx scsi_host\n"); |
| 6340 | continue; |
| 6341 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6342 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6343 | |
| 6344 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6345 | scsi_host_put(host); |
| 6346 | continue; |
| 6347 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6348 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6349 | if (rc != 0) |
| 6350 | scsi_host_put(host); |
| 6351 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6352 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6353 | return rc; |
| 6354 | } |
| 6355 | mutex_unlock(&qla_tgt_mutex); |
| 6356 | |
| 6357 | return -ENODEV; |
| 6358 | } |
| 6359 | EXPORT_SYMBOL(qlt_lport_register); |
| 6360 | |
| 6361 | /** |
| 6362 | * qla_tgt_lport_deregister - Degister lport |
| 6363 | * |
| 6364 | * @vha: Registered scsi_qla_host pointer |
| 6365 | */ |
| 6366 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6367 | { |
| 6368 | struct qla_hw_data *ha = vha->hw; |
| 6369 | struct Scsi_Host *sh = vha->host; |
| 6370 | /* |
| 6371 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6372 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6373 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6374 | ha->tgt.tgt_ops = NULL; |
| 6375 | /* |
| 6376 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6377 | */ |
| 6378 | scsi_host_put(sh); |
| 6379 | } |
| 6380 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6381 | |
| 6382 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6383 | static void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6384 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6385 | switch (ql2x_ini_mode) { |
| 6386 | case QLA2XXX_INI_MODE_DISABLED: |
| 6387 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6388 | vha->host->active_mode = MODE_TARGET; |
| 6389 | break; |
| 6390 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6391 | vha->host->active_mode = MODE_UNKNOWN; |
| 6392 | break; |
| 6393 | case QLA2XXX_INI_MODE_DUAL: |
| 6394 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6395 | break; |
| 6396 | default: |
| 6397 | break; |
| 6398 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6402 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6403 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6404 | switch (ql2x_ini_mode) { |
| 6405 | case QLA2XXX_INI_MODE_DISABLED: |
| 6406 | vha->host->active_mode = MODE_UNKNOWN; |
| 6407 | break; |
| 6408 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6409 | vha->host->active_mode = MODE_INITIATOR; |
| 6410 | break; |
| 6411 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6412 | case QLA2XXX_INI_MODE_DUAL: |
| 6413 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6414 | break; |
| 6415 | default: |
| 6416 | break; |
| 6417 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6418 | } |
| 6419 | |
| 6420 | /* |
| 6421 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6422 | * |
| 6423 | * host_reset, bring up w/ Target Mode Enabled |
| 6424 | */ |
| 6425 | void |
| 6426 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6427 | { |
| 6428 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6429 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6430 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6431 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6432 | |
| 6433 | if (!tgt) { |
| 6434 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6435 | "Unable to locate qla_tgt pointer from" |
| 6436 | " struct qla_hw_data\n"); |
| 6437 | dump_stack(); |
| 6438 | return; |
| 6439 | } |
| 6440 | |
| 6441 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6442 | tgt->tgt_stopped = 0; |
| 6443 | qlt_set_mode(vha); |
| 6444 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6445 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6446 | if (vha->vp_idx) { |
| 6447 | qla24xx_disable_vp(vha); |
| 6448 | qla24xx_enable_vp(vha); |
| 6449 | } else { |
| 6450 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6451 | qla2xxx_wake_dpc(base_vha); |
| 6452 | qla2x00_wait_for_hba_online(base_vha); |
| 6453 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6454 | } |
| 6455 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6456 | |
| 6457 | /* |
| 6458 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6459 | * |
| 6460 | * Disable Target Mode and reset the adapter |
| 6461 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6462 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6463 | { |
| 6464 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6465 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6466 | unsigned long flags; |
| 6467 | |
| 6468 | if (!tgt) { |
| 6469 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6470 | "Unable to locate qla_tgt pointer from" |
| 6471 | " struct qla_hw_data\n"); |
| 6472 | dump_stack(); |
| 6473 | return; |
| 6474 | } |
| 6475 | |
| 6476 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6477 | qlt_clear_mode(vha); |
| 6478 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6479 | |
| 6480 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6481 | qla2xxx_wake_dpc(vha); |
| 6482 | qla2x00_wait_for_hba_online(vha); |
| 6483 | } |
| 6484 | |
| 6485 | /* |
| 6486 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6487 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6488 | * members. |
| 6489 | */ |
| 6490 | void |
| 6491 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6492 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6493 | vha->vha_tgt.qla_tgt = NULL; |
| 6494 | |
| 6495 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6496 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6497 | |
| 6498 | qlt_clear_mode(vha); |
| 6499 | |
| 6500 | /* |
| 6501 | * NOTE: Currently the value is kept the same for <24xx and |
| 6502 | * >=24xx ISPs. If it is necessary to change it, |
| 6503 | * the check should be added for specific ISPs, |
| 6504 | * assigning the value appropriately. |
| 6505 | */ |
| 6506 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6507 | |
| 6508 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6509 | } |
| 6510 | |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6511 | u8 |
| 6512 | qlt_rff_id(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6513 | { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6514 | u8 fc4_feature = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6515 | /* |
| 6516 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6517 | */ |
| 6518 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6519 | fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6520 | } else if (qla_ini_mode_enabled(vha)) { |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6521 | fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6522 | } else if (qla_dual_mode_enabled(vha)) |
Quinn Tran | e374f9f | 2017-12-28 12:33:31 -0800 | [diff] [blame] | 6523 | fc4_feature = BIT_0 | BIT_1; |
| 6524 | |
| 6525 | return fc4_feature; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6526 | } |
| 6527 | |
| 6528 | /* |
| 6529 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6530 | * @ha: HA context |
| 6531 | * |
| 6532 | * Beginning of ATIO ring has initialization control block already built |
| 6533 | * by nvram config routine. |
| 6534 | * |
| 6535 | * Returns 0 on success. |
| 6536 | */ |
| 6537 | void |
| 6538 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6539 | { |
| 6540 | struct qla_hw_data *ha = vha->hw; |
| 6541 | uint16_t cnt; |
| 6542 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6543 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6544 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6545 | return; |
| 6546 | |
| 6547 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6548 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6549 | pkt++; |
| 6550 | } |
| 6551 | |
| 6552 | } |
| 6553 | |
| 6554 | /* |
| 6555 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6556 | * @ha: SCSI driver HA context |
| 6557 | */ |
| 6558 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6559 | 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] | 6560 | { |
| 6561 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6562 | struct atio_from_isp *pkt; |
| 6563 | int cnt, i; |
| 6564 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6565 | if (!ha->flags.fw_started) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6566 | return; |
| 6567 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6568 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6569 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6570 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6571 | cnt = pkt->u.raw.entry_count; |
| 6572 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6573 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6574 | /* |
| 6575 | * This packet is corrupted. The header + payload |
| 6576 | * can not be trusted. There is no point in passing |
| 6577 | * it further up. |
| 6578 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6579 | ql_log(ql_log_warn, vha, 0xd03c, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6580 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6581 | pkt->u.isp24.fcp_hdr.s_id, |
| 6582 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6583 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6584 | |
| 6585 | adjust_corrupted_atio(pkt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6586 | qlt_send_term_exchange(ha->base_qpair, NULL, pkt, |
| 6587 | ha_locked, 0); |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6588 | } else { |
| 6589 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6590 | (struct atio_from_isp *)pkt, ha_locked); |
| 6591 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6592 | |
| 6593 | for (i = 0; i < cnt; i++) { |
| 6594 | ha->tgt.atio_ring_index++; |
| 6595 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6596 | ha->tgt.atio_ring_index = 0; |
| 6597 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6598 | } else |
| 6599 | ha->tgt.atio_ring_ptr++; |
| 6600 | |
| 6601 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6602 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6603 | } |
| 6604 | wmb(); |
| 6605 | } |
| 6606 | |
| 6607 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6608 | 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] | 6609 | } |
| 6610 | |
| 6611 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6612 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6613 | { |
| 6614 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6615 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6616 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6617 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6618 | if (!QLA_TGT_MODE_ENABLED()) |
| 6619 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6620 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6621 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6622 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6623 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6624 | |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6625 | if (ha->flags.msix_enabled) { |
| 6626 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
| 6627 | if (IS_QLA2071(ha)) { |
| 6628 | /* 4 ports Baker: Enable Interrupt Handshake */ |
| 6629 | icb->msix_atio = 0; |
| 6630 | icb->firmware_options_2 |= BIT_26; |
| 6631 | } else { |
| 6632 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6633 | icb->firmware_options_2 &= ~BIT_26; |
| 6634 | } |
| 6635 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6636 | "Registering ICB vector 0x%x for atio que.\n", |
| 6637 | msix->entry); |
| 6638 | } |
| 6639 | } else { |
| 6640 | /* INTx|MSI */ |
| 6641 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
| 6642 | icb->msix_atio = 0; |
| 6643 | icb->firmware_options_2 |= BIT_26; |
| 6644 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6645 | "%s: Use INTx for ATIOQ.\n", __func__); |
| 6646 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6647 | } |
| 6648 | } |
| 6649 | |
| 6650 | void |
| 6651 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6652 | { |
| 6653 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6654 | u32 tmp; |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6655 | |
| 6656 | if (!QLA_TGT_MODE_ENABLED()) |
| 6657 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6658 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6659 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6660 | if (!ha->tgt.saved_set) { |
| 6661 | /* We save only once */ |
| 6662 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6663 | ha->tgt.saved_firmware_options_1 = |
| 6664 | nv->firmware_options_1; |
| 6665 | ha->tgt.saved_firmware_options_2 = |
| 6666 | nv->firmware_options_2; |
| 6667 | ha->tgt.saved_firmware_options_3 = |
| 6668 | nv->firmware_options_3; |
| 6669 | ha->tgt.saved_set = 1; |
| 6670 | } |
| 6671 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6672 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6673 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6674 | else /* dual */ |
| 6675 | nv->exchange_count = cpu_to_le16(ql2xexchoffld); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6676 | |
| 6677 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6678 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6679 | |
| 6680 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6681 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6682 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6683 | |
| 6684 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6685 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6686 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6687 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6688 | if (ql2xtgt_tape_enable) |
| 6689 | /* Enable FC Tape support */ |
| 6690 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6691 | else |
| 6692 | /* Disable FC Tape support */ |
| 6693 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6694 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6695 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6696 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6697 | |
| 6698 | /* |
| 6699 | * clear BIT 15 explicitly as we have seen at least |
| 6700 | * a couple of instances where this was set and this |
| 6701 | * was causing the firmware to not be initialized. |
| 6702 | */ |
| 6703 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6704 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6705 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6706 | |
| 6707 | if (IS_QLA25XX(ha)) { |
| 6708 | /* Change Loop-prefer to Pt-Pt */ |
| 6709 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 6710 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 6711 | tmp = P2P << 4; |
| 6712 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
| 6713 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6714 | } else { |
| 6715 | if (ha->tgt.saved_set) { |
| 6716 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6717 | nv->firmware_options_1 = |
| 6718 | ha->tgt.saved_firmware_options_1; |
| 6719 | nv->firmware_options_2 = |
| 6720 | ha->tgt.saved_firmware_options_2; |
| 6721 | nv->firmware_options_3 = |
| 6722 | ha->tgt.saved_firmware_options_3; |
| 6723 | } |
| 6724 | return; |
| 6725 | } |
| 6726 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6727 | if (ha->base_qpair->enable_class_2) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6728 | if (vha->flags.init_done) |
| 6729 | fc_host_supported_classes(vha->host) = |
| 6730 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6731 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6732 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6733 | } else { |
| 6734 | if (vha->flags.init_done) |
| 6735 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6736 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6737 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6738 | } |
| 6739 | } |
| 6740 | |
| 6741 | void |
| 6742 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6743 | struct init_cb_24xx *icb) |
| 6744 | { |
| 6745 | struct qla_hw_data *ha = vha->hw; |
| 6746 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6747 | if (!QLA_TGT_MODE_ENABLED()) |
| 6748 | return; |
| 6749 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6750 | if (ha->tgt.node_name_set) { |
| 6751 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6752 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6753 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6754 | |
| 6755 | /* disable ZIO at start time. */ |
| 6756 | if (!vha->flags.init_done) { |
| 6757 | uint32_t tmp; |
| 6758 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6759 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6760 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6761 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6762 | } |
| 6763 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6764 | void |
| 6765 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6766 | { |
| 6767 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6768 | u32 tmp; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6769 | |
| 6770 | if (!QLA_TGT_MODE_ENABLED()) |
| 6771 | return; |
| 6772 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6773 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6774 | if (!ha->tgt.saved_set) { |
| 6775 | /* We save only once */ |
| 6776 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6777 | ha->tgt.saved_firmware_options_1 = |
| 6778 | nv->firmware_options_1; |
| 6779 | ha->tgt.saved_firmware_options_2 = |
| 6780 | nv->firmware_options_2; |
| 6781 | ha->tgt.saved_firmware_options_3 = |
| 6782 | nv->firmware_options_3; |
| 6783 | ha->tgt.saved_set = 1; |
| 6784 | } |
| 6785 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6786 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6787 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6788 | else /* dual */ |
| 6789 | nv->exchange_count = cpu_to_le16(ql2xexchoffld); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6790 | |
| 6791 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6792 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6793 | |
| 6794 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6795 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6796 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6797 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6798 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6799 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6800 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6801 | /* |
| 6802 | * clear BIT 15 explicitly as we have seen at |
| 6803 | * least a couple of instances where this was set |
| 6804 | * and this was causing the firmware to not be |
| 6805 | * initialized. |
| 6806 | */ |
| 6807 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6808 | if (ql2xtgt_tape_enable) |
| 6809 | /* Enable FC tape support */ |
| 6810 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6811 | else |
| 6812 | /* Disable FC tape support */ |
| 6813 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6814 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6815 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6816 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6817 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6818 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6819 | |
| 6820 | /* Change Loop-prefer to Pt-Pt */ |
| 6821 | tmp = ~(BIT_4|BIT_5|BIT_6); |
| 6822 | nv->firmware_options_2 &= cpu_to_le32(tmp); |
| 6823 | tmp = P2P << 4; |
| 6824 | nv->firmware_options_2 |= cpu_to_le32(tmp); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6825 | } else { |
| 6826 | if (ha->tgt.saved_set) { |
| 6827 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6828 | nv->firmware_options_1 = |
| 6829 | ha->tgt.saved_firmware_options_1; |
| 6830 | nv->firmware_options_2 = |
| 6831 | ha->tgt.saved_firmware_options_2; |
| 6832 | nv->firmware_options_3 = |
| 6833 | ha->tgt.saved_firmware_options_3; |
| 6834 | } |
| 6835 | return; |
| 6836 | } |
| 6837 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6838 | if (ha->base_qpair->enable_class_2) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6839 | if (vha->flags.init_done) |
| 6840 | fc_host_supported_classes(vha->host) = |
| 6841 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6842 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6843 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6844 | } else { |
| 6845 | if (vha->flags.init_done) |
| 6846 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6847 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6848 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6849 | } |
| 6850 | } |
| 6851 | |
| 6852 | void |
| 6853 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6854 | struct init_cb_81xx *icb) |
| 6855 | { |
| 6856 | struct qla_hw_data *ha = vha->hw; |
| 6857 | |
| 6858 | if (!QLA_TGT_MODE_ENABLED()) |
| 6859 | return; |
| 6860 | |
| 6861 | if (ha->tgt.node_name_set) { |
| 6862 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6863 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6864 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6865 | |
| 6866 | /* disable ZIO at start time. */ |
| 6867 | if (!vha->flags.init_done) { |
| 6868 | uint32_t tmp; |
| 6869 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6870 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6871 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6872 | } |
| 6873 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6874 | } |
| 6875 | |
| 6876 | void |
| 6877 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 6878 | { |
| 6879 | if (!QLA_TGT_MODE_ENABLED()) |
| 6880 | return; |
| 6881 | |
| 6882 | ha->msix_count += 1; /* For ATIO Q */ |
| 6883 | } |
| 6884 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6885 | |
| 6886 | void |
| 6887 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 6888 | struct vp_config_entry_24xx *vpmod) |
| 6889 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6890 | /* enable target mode. Bit5 = 1 => disable */ |
| 6891 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6892 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6893 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6894 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6895 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6896 | vpmod->options_idx1 &= ~BIT_4; |
| 6897 | } |
| 6898 | |
| 6899 | void |
| 6900 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 6901 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6902 | int rc; |
| 6903 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6904 | if (!QLA_TGT_MODE_ENABLED()) |
| 6905 | return; |
| 6906 | |
Himanshu Madhani | c955886 | 2017-10-13 09:34:04 -0700 | [diff] [blame] | 6907 | if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6908 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 6909 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 6910 | } else { |
| 6911 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 6912 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 6913 | } |
| 6914 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6915 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 6916 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6917 | |
| 6918 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 6919 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 6920 | qlt_unknown_atio_work_fn); |
| 6921 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6922 | qlt_clear_mode(base_vha); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6923 | |
| 6924 | rc = btree_init32(&ha->tgt.host_map); |
| 6925 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6926 | ql_log(ql_log_info, base_vha, 0xd03d, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6927 | "Unable to initialize ha->host_map btree\n"); |
| 6928 | |
| 6929 | qlt_update_vp_map(base_vha, SET_VP_IDX); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6930 | } |
| 6931 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6932 | irqreturn_t |
| 6933 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 6934 | { |
| 6935 | struct rsp_que *rsp; |
| 6936 | scsi_qla_host_t *vha; |
| 6937 | struct qla_hw_data *ha; |
| 6938 | unsigned long flags; |
| 6939 | |
| 6940 | rsp = (struct rsp_que *) dev_id; |
| 6941 | ha = rsp->hw; |
| 6942 | vha = pci_get_drvdata(ha->pdev); |
| 6943 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6944 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6945 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6946 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6947 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6948 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6949 | |
| 6950 | return IRQ_HANDLED; |
| 6951 | } |
| 6952 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6953 | static void |
| 6954 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 6955 | { |
| 6956 | struct qla_tgt_sess_op *op = container_of(work, |
| 6957 | struct qla_tgt_sess_op, work); |
| 6958 | scsi_qla_host_t *vha = op->vha; |
| 6959 | struct qla_hw_data *ha = vha->hw; |
| 6960 | unsigned long flags; |
| 6961 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6962 | if (qla2x00_reset_active(vha) || |
| 6963 | (op->chip_reset != ha->base_qpair->chip_reset)) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6964 | return; |
| 6965 | |
| 6966 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 6967 | qlt_24xx_process_atio_queue(vha, 0); |
| 6968 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 6969 | |
| 6970 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6971 | qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6972 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 6973 | |
| 6974 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6975 | } |
| 6976 | |
| 6977 | void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6978 | qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp, |
| 6979 | response_t *pkt) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6980 | { |
| 6981 | struct qla_tgt_sess_op *op; |
| 6982 | |
| 6983 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 6984 | |
| 6985 | if (!op) { |
| 6986 | /* do not reach for ATIO queue here. This is best effort err |
| 6987 | * recovery at this point. |
| 6988 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6989 | qlt_response_pkt_all_vps(vha, rsp, pkt); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6990 | return; |
| 6991 | } |
| 6992 | |
| 6993 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 6994 | op->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6995 | op->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6996 | op->rsp = rsp; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6997 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 6998 | queue_work(qla_tgt_wq, &op->work); |
| 6999 | return; |
| 7000 | } |
| 7001 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7002 | int |
| 7003 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 7004 | { |
| 7005 | if (!QLA_TGT_MODE_ENABLED()) |
| 7006 | return 0; |
| 7007 | |
| 7008 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * |
| 7009 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); |
| 7010 | if (!ha->tgt.tgt_vp_map) |
| 7011 | return -ENOMEM; |
| 7012 | |
| 7013 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 7014 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 7015 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 7016 | if (!ha->tgt.atio_ring) { |
| 7017 | kfree(ha->tgt.tgt_vp_map); |
| 7018 | return -ENOMEM; |
| 7019 | } |
| 7020 | return 0; |
| 7021 | } |
| 7022 | |
| 7023 | void |
| 7024 | qlt_mem_free(struct qla_hw_data *ha) |
| 7025 | { |
| 7026 | if (!QLA_TGT_MODE_ENABLED()) |
| 7027 | return; |
| 7028 | |
| 7029 | if (ha->tgt.atio_ring) { |
| 7030 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 7031 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 7032 | ha->tgt.atio_dma); |
| 7033 | } |
| 7034 | kfree(ha->tgt.tgt_vp_map); |
| 7035 | } |
| 7036 | |
| 7037 | /* vport_slock to be held by the caller */ |
| 7038 | void |
| 7039 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 7040 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7041 | void *slot; |
| 7042 | u32 key; |
| 7043 | int rc; |
| 7044 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7045 | if (!QLA_TGT_MODE_ENABLED()) |
| 7046 | return; |
| 7047 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7048 | key = vha->d_id.b24; |
| 7049 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7050 | switch (cmd) { |
| 7051 | case SET_VP_IDX: |
| 7052 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 7053 | break; |
| 7054 | case SET_AL_PA: |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7055 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7056 | if (!slot) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7057 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7058 | "Save vha in host_map %p %06x\n", vha, key); |
| 7059 | rc = btree_insert32(&vha->hw->tgt.host_map, |
| 7060 | key, vha, GFP_ATOMIC); |
| 7061 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7062 | ql_log(ql_log_info, vha, 0xd03e, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7063 | "Unable to insert s_id into host_map: %06x\n", |
| 7064 | key); |
| 7065 | return; |
| 7066 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7067 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 7068 | "replace existing vha in host_map %p %06x\n", vha, key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7069 | btree_update32(&vha->hw->tgt.host_map, key, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7070 | break; |
| 7071 | case RESET_VP_IDX: |
| 7072 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 7073 | break; |
| 7074 | case RESET_AL_PA: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7075 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7076 | "clear vha in host_map %p %06x\n", vha, key); |
| 7077 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7078 | if (slot) |
| 7079 | btree_remove32(&vha->hw->tgt.host_map, key); |
| 7080 | vha->d_id.b24 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7081 | break; |
| 7082 | } |
| 7083 | } |
| 7084 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7085 | void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id) |
| 7086 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7087 | |
| 7088 | if (!vha->d_id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7089 | vha->d_id = id; |
| 7090 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7091 | } else if (vha->d_id.b24 != id.b24) { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7092 | qlt_update_vp_map(vha, RESET_AL_PA); |
| 7093 | vha->d_id = id; |
| 7094 | qlt_update_vp_map(vha, SET_AL_PA); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7095 | } |
| 7096 | } |
| 7097 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7098 | static int __init qlt_parse_ini_mode(void) |
| 7099 | { |
| 7100 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 7101 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 7102 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 7103 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 7104 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 7105 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7106 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 7107 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7108 | else |
| 7109 | return false; |
| 7110 | |
| 7111 | return true; |
| 7112 | } |
| 7113 | |
| 7114 | int __init qlt_init(void) |
| 7115 | { |
| 7116 | int ret; |
| 7117 | |
| 7118 | if (!qlt_parse_ini_mode()) { |
| 7119 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 7120 | "qlt_parse_ini_mode() failed\n"); |
| 7121 | return -EINVAL; |
| 7122 | } |
| 7123 | |
| 7124 | if (!QLA_TGT_MODE_ENABLED()) |
| 7125 | return 0; |
| 7126 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7127 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 7128 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 7129 | qla_tgt_mgmt_cmd), 0, NULL); |
| 7130 | if (!qla_tgt_mgmt_cmd_cachep) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7131 | ql_log(ql_log_fatal, NULL, 0xd04b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7132 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 7133 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7134 | } |
| 7135 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7136 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 7137 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 7138 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7139 | |
| 7140 | if (!qla_tgt_plogi_cachep) { |
| 7141 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 7142 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 7143 | ret = -ENOMEM; |
| 7144 | goto out_mgmt_cmd_cachep; |
| 7145 | } |
| 7146 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7147 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 7148 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 7149 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 7150 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 7151 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 7152 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7153 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7154 | } |
| 7155 | |
| 7156 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 7157 | if (!qla_tgt_wq) { |
| 7158 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 7159 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 7160 | ret = -ENOMEM; |
| 7161 | goto out_cmd_mempool; |
| 7162 | } |
| 7163 | /* |
| 7164 | * Return 1 to signal that initiator-mode is being disabled |
| 7165 | */ |
| 7166 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 7167 | |
| 7168 | out_cmd_mempool: |
| 7169 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7170 | out_plogi_cachep: |
| 7171 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7172 | out_mgmt_cmd_cachep: |
| 7173 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7174 | return ret; |
| 7175 | } |
| 7176 | |
| 7177 | void qlt_exit(void) |
| 7178 | { |
| 7179 | if (!QLA_TGT_MODE_ENABLED()) |
| 7180 | return; |
| 7181 | |
| 7182 | destroy_workqueue(qla_tgt_wq); |
| 7183 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7184 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7185 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7186 | } |