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 | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 78 | static int temp_sam_status = SAM_STAT_BUSY; |
| 79 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 80 | /* |
| 81 | * From scsi/fc/fc_fcp.h |
| 82 | */ |
| 83 | enum fcp_resp_rsp_codes { |
| 84 | FCP_TMF_CMPL = 0, |
| 85 | FCP_DATA_LEN_INVALID = 1, |
| 86 | FCP_CMND_FIELDS_INVALID = 2, |
| 87 | FCP_DATA_PARAM_MISMATCH = 3, |
| 88 | FCP_TMF_REJECTED = 4, |
| 89 | FCP_TMF_FAILED = 5, |
| 90 | FCP_TMF_INVALID_LUN = 9, |
| 91 | }; |
| 92 | |
| 93 | /* |
| 94 | * fc_pri_ta from scsi/fc/fc_fcp.h |
| 95 | */ |
| 96 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ |
| 97 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ |
| 98 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 99 | #define FCP_PTA_ACA 4 /* auto. contingent allegiance */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 100 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ |
| 101 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ |
| 102 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ |
| 103 | |
| 104 | /* |
| 105 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which |
| 106 | * must be called under HW lock and could unlock/lock it inside. |
| 107 | * It isn't an issue, since in the current implementation on the time when |
| 108 | * those functions are called: |
| 109 | * |
| 110 | * - Either context is IRQ and only IRQ handler can modify HW data, |
| 111 | * including rings related fields, |
| 112 | * |
| 113 | * - Or access to target mode variables from struct qla_tgt doesn't |
| 114 | * cross those functions boundaries, except tgt_stop, which |
| 115 | * additionally protected by irq_cmd_count. |
| 116 | */ |
| 117 | /* Predefs for callbacks handed to qla2xxx LLD */ |
| 118 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 119 | struct atio_from_isp *pkt, uint8_t); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 120 | static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp, |
| 121 | response_t *pkt); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 122 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 123 | int fn, void *iocb, int flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 124 | 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] | 125 | *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 126 | static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 127 | struct atio_from_isp *atio, uint16_t status, int qfull); |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 128 | static void qlt_disable_vha(struct scsi_qla_host *vha); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 129 | static void qlt_clear_tgt_db(struct qla_tgt *tgt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 130 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 131 | struct imm_ntfy_from_isp *ntfy, |
| 132 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 133 | 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] | 134 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 135 | struct imm_ntfy_from_isp *imm, int ha_locked); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 136 | static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha, |
| 137 | fc_port_t *fcport, bool local); |
| 138 | void qlt_unreg_sess(struct fc_port *sess); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 139 | static void qlt_24xx_handle_abts(struct scsi_qla_host *, |
| 140 | struct abts_recv_from_24xx *); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 141 | static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *, |
| 142 | uint16_t); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 143 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 144 | /* |
| 145 | * Global Variables |
| 146 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 147 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Quinn Tran | b5d1531 | 2017-08-30 10:16:49 -0700 | [diff] [blame] | 148 | struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 149 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 150 | static struct workqueue_struct *qla_tgt_wq; |
| 151 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 152 | static LIST_HEAD(qla_tgt_glist); |
| 153 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 154 | static const char *prot_op_str(u32 prot_op) |
| 155 | { |
| 156 | switch (prot_op) { |
| 157 | case TARGET_PROT_NORMAL: return "NORMAL"; |
| 158 | case TARGET_PROT_DIN_INSERT: return "DIN_INSERT"; |
| 159 | case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT"; |
| 160 | case TARGET_PROT_DIN_STRIP: return "DIN_STRIP"; |
| 161 | case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP"; |
| 162 | case TARGET_PROT_DIN_PASS: return "DIN_PASS"; |
| 163 | case TARGET_PROT_DOUT_PASS: return "DOUT_PASS"; |
| 164 | default: return "UNKNOWN"; |
| 165 | } |
| 166 | } |
| 167 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 168 | /* This API intentionally takes dest as a parameter, rather than returning |
| 169 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 170 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 171 | { |
| 172 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 173 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 174 | /* memory barrier */ |
| 175 | wmb(); |
| 176 | } |
| 177 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 178 | /* Might release hw lock, then reaquire!! */ |
| 179 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 180 | { |
| 181 | /* Send marker if required */ |
| 182 | if (unlikely(vha->marker_needed != 0)) { |
| 183 | int rc = qla2x00_issue_marker(vha, vha_locked); |
| 184 | if (rc != QLA_SUCCESS) { |
| 185 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 186 | "qla_target(%d): issue_marker() failed\n", |
| 187 | vha->vp_idx); |
| 188 | } |
| 189 | return rc; |
| 190 | } |
| 191 | return QLA_SUCCESS; |
| 192 | } |
| 193 | |
| 194 | static inline |
| 195 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
| 196 | uint8_t *d_id) |
| 197 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 198 | struct scsi_qla_host *host; |
| 199 | uint32_t key = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 200 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 201 | if ((vha->d_id.b.area == d_id[1]) && (vha->d_id.b.domain == d_id[0]) && |
| 202 | (vha->d_id.b.al_pa == d_id[2])) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 203 | return vha; |
| 204 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 205 | key = (uint32_t)d_id[0] << 16; |
| 206 | key |= (uint32_t)d_id[1] << 8; |
| 207 | key |= (uint32_t)d_id[2]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 208 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 209 | host = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 210 | if (!host) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 211 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf005, |
| 212 | "Unable to find host %06x\n", key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 213 | |
| 214 | return host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static inline |
| 218 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 219 | uint16_t vp_idx) |
| 220 | { |
| 221 | struct qla_hw_data *ha = vha->hw; |
| 222 | |
| 223 | if (vha->vp_idx == vp_idx) |
| 224 | return vha; |
| 225 | |
| 226 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 227 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 228 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 229 | |
| 230 | return NULL; |
| 231 | } |
| 232 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 233 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 234 | { |
| 235 | unsigned long flags; |
| 236 | |
| 237 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 238 | |
| 239 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 240 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 241 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 242 | vha->hw->tgt.num_pend_cmds; |
| 243 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 244 | } |
| 245 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 246 | { |
| 247 | unsigned long flags; |
| 248 | |
| 249 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 250 | vha->hw->tgt.num_pend_cmds--; |
| 251 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 252 | } |
| 253 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 254 | |
| 255 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 256 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 257 | { |
| 258 | struct qla_tgt_sess_op *u; |
| 259 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 260 | unsigned long flags; |
| 261 | |
| 262 | if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 263 | ql_dbg(ql_dbg_async, vha, 0x502c, |
| 264 | "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped", |
| 265 | vha->vp_idx); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 266 | goto out_term; |
| 267 | } |
| 268 | |
| 269 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 270 | if (u == NULL) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 271 | goto out_term; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 272 | |
| 273 | u->vha = vha; |
| 274 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 275 | INIT_LIST_HEAD(&u->cmd_list); |
| 276 | |
| 277 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 278 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 279 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 280 | |
| 281 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 282 | |
| 283 | out: |
| 284 | return; |
| 285 | |
| 286 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 287 | 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] | 288 | goto out; |
| 289 | } |
| 290 | |
| 291 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 292 | uint8_t ha_locked) |
| 293 | { |
| 294 | struct qla_tgt_sess_op *u, *t; |
| 295 | scsi_qla_host_t *host; |
| 296 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 297 | unsigned long flags; |
| 298 | uint8_t queued = 0; |
| 299 | |
| 300 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 301 | if (u->aborted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 302 | ql_dbg(ql_dbg_async, vha, 0x502e, |
| 303 | "Freeing unknown %s %p, because of Abort\n", |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 304 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 305 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 306 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 307 | goto abort; |
| 308 | } |
| 309 | |
| 310 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 311 | if (host != NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 312 | ql_dbg(ql_dbg_async, vha, 0x502f, |
| 313 | "Requeuing unknown ATIO_TYPE7 %p\n", u); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 314 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 315 | } else if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 316 | ql_dbg(ql_dbg_async, vha, 0x503a, |
| 317 | "Freeing unknown %s %p, because tgt is being stopped\n", |
| 318 | "ATIO_TYPE7", u); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 319 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, |
| 320 | &u->atio, ha_locked, 0); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 321 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 322 | ql_dbg(ql_dbg_async, vha, 0x503d, |
| 323 | "Reschedule u %p, vha %p, host %p\n", u, vha, host); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 324 | if (!queued) { |
| 325 | queued = 1; |
| 326 | schedule_delayed_work(&vha->unknown_atio_work, |
| 327 | 1); |
| 328 | } |
| 329 | continue; |
| 330 | } |
| 331 | |
| 332 | abort: |
| 333 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 334 | list_del(&u->cmd_list); |
| 335 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 336 | kfree(u); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 341 | { |
| 342 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 343 | struct scsi_qla_host, unknown_atio_work); |
| 344 | |
| 345 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 346 | } |
| 347 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 348 | 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] | 349 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 350 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 351 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 352 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 353 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 354 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 355 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 356 | switch (atio->u.raw.entry_type) { |
| 357 | case ATIO_TYPE7: |
| 358 | { |
| 359 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 360 | atio->u.isp24.fcp_hdr.d_id); |
| 361 | if (unlikely(NULL == host)) { |
| 362 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 363 | "qla_target(%d): Received ATIO_TYPE7 " |
| 364 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
| 365 | atio->u.isp24.fcp_hdr.d_id[0], |
| 366 | atio->u.isp24.fcp_hdr.d_id[1], |
| 367 | atio->u.isp24.fcp_hdr.d_id[2]); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 368 | |
| 369 | |
| 370 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 371 | break; |
| 372 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 373 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 374 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 375 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 376 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 377 | break; |
| 378 | } |
| 379 | |
| 380 | case IMMED_NOTIFY_TYPE: |
| 381 | { |
| 382 | struct scsi_qla_host *host = vha; |
| 383 | struct imm_ntfy_from_isp *entry = |
| 384 | (struct imm_ntfy_from_isp *)atio; |
| 385 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 386 | qlt_issue_marker(vha, ha_locked); |
| 387 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 388 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 389 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 390 | host = qlt_find_host_by_vp_idx(vha, |
| 391 | entry->u.isp24.vp_index); |
| 392 | if (unlikely(!host)) { |
| 393 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 394 | "qla_target(%d): Received " |
| 395 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 396 | "with unknown vp_index %d\n", |
| 397 | vha->vp_idx, entry->u.isp24.vp_index); |
| 398 | break; |
| 399 | } |
| 400 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 401 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 402 | break; |
| 403 | } |
| 404 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 405 | case VP_RPT_ID_IOCB_TYPE: |
| 406 | qla24xx_report_id_acquisition(vha, |
| 407 | (struct vp_rpt_id_entry_24xx *)atio); |
| 408 | break; |
| 409 | |
| 410 | case ABTS_RECV_24XX: |
| 411 | { |
| 412 | struct abts_recv_from_24xx *entry = |
| 413 | (struct abts_recv_from_24xx *)atio; |
| 414 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 415 | entry->vp_index); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 416 | unsigned long flags; |
| 417 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 418 | if (unlikely(!host)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 419 | ql_dbg(ql_dbg_tgt, vha, 0xe00a, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 420 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 421 | "received, with unknown vp_index %d\n", |
| 422 | vha->vp_idx, entry->vp_index); |
| 423 | break; |
| 424 | } |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 425 | if (!ha_locked) |
| 426 | spin_lock_irqsave(&host->hw->hardware_lock, flags); |
| 427 | qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio); |
| 428 | if (!ha_locked) |
| 429 | spin_unlock_irqrestore(&host->hw->hardware_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 430 | break; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 434 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 435 | default: |
| 436 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 437 | "qla_target(%d): Received unknown ATIO atio " |
| 438 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 439 | break; |
| 440 | } |
| 441 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 442 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 443 | } |
| 444 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 445 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, |
| 446 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 447 | { |
| 448 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 449 | case CTIO_CRC2: |
| 450 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 451 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 452 | vha->vp_idx, __func__); |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 453 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 454 | case CTIO_TYPE7: |
| 455 | { |
| 456 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 457 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 458 | entry->vp_index); |
| 459 | if (unlikely(!host)) { |
| 460 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 461 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 462 | "received, with unknown vp_index %d\n", |
| 463 | vha->vp_idx, entry->vp_index); |
| 464 | break; |
| 465 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 466 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | |
| 470 | case IMMED_NOTIFY_TYPE: |
| 471 | { |
| 472 | struct scsi_qla_host *host = vha; |
| 473 | struct imm_ntfy_from_isp *entry = |
| 474 | (struct imm_ntfy_from_isp *)pkt; |
| 475 | |
| 476 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 477 | if (unlikely(!host)) { |
| 478 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 479 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 480 | "received, with unknown vp_index %d\n", |
| 481 | vha->vp_idx, entry->u.isp24.vp_index); |
| 482 | break; |
| 483 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 484 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 485 | break; |
| 486 | } |
| 487 | |
| 488 | case NOTIFY_ACK_TYPE: |
| 489 | { |
| 490 | struct scsi_qla_host *host = vha; |
| 491 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 492 | |
| 493 | if (0xFF != entry->u.isp24.vp_index) { |
| 494 | host = qlt_find_host_by_vp_idx(vha, |
| 495 | entry->u.isp24.vp_index); |
| 496 | if (unlikely(!host)) { |
| 497 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 498 | "qla_target(%d): Response " |
| 499 | "pkt (NOTIFY_ACK_TYPE) " |
| 500 | "received, with unknown " |
| 501 | "vp_index %d\n", vha->vp_idx, |
| 502 | entry->u.isp24.vp_index); |
| 503 | break; |
| 504 | } |
| 505 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 506 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | |
| 510 | case ABTS_RECV_24XX: |
| 511 | { |
| 512 | struct abts_recv_from_24xx *entry = |
| 513 | (struct abts_recv_from_24xx *)pkt; |
| 514 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 515 | entry->vp_index); |
| 516 | if (unlikely(!host)) { |
| 517 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 518 | "qla_target(%d): Response pkt " |
| 519 | "(ABTS_RECV_24XX) received, with unknown " |
| 520 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 521 | break; |
| 522 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 523 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 524 | break; |
| 525 | } |
| 526 | |
| 527 | case ABTS_RESP_24XX: |
| 528 | { |
| 529 | struct abts_resp_to_24xx *entry = |
| 530 | (struct abts_resp_to_24xx *)pkt; |
| 531 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 532 | entry->vp_index); |
| 533 | if (unlikely(!host)) { |
| 534 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 535 | "qla_target(%d): Response pkt " |
| 536 | "(ABTS_RECV_24XX) received, with unknown " |
| 537 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 538 | break; |
| 539 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 540 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 541 | break; |
| 542 | } |
| 543 | |
| 544 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 545 | qlt_response_pkt(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 546 | break; |
| 547 | } |
| 548 | |
| 549 | } |
| 550 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 551 | /* |
| 552 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 553 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 554 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 555 | struct imm_ntfy_from_isp *ntfy, int type) |
| 556 | { |
| 557 | struct qla_work_evt *e; |
| 558 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 559 | if (!e) |
| 560 | return QLA_FUNCTION_FAILED; |
| 561 | |
| 562 | e->u.nack.fcport = fcport; |
| 563 | e->u.nack.type = type; |
| 564 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 565 | return qla2x00_post_work(vha, e); |
| 566 | } |
| 567 | |
| 568 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 569 | void qla2x00_async_nack_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 570 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 571 | struct srb *sp = (struct srb *)s; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 572 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 573 | unsigned long flags; |
| 574 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 575 | ql_dbg(ql_dbg_disc, vha, 0x20f2, |
| 576 | "Async done-%s res %x %8phC type %d\n", |
| 577 | sp->name, res, sp->fcport->port_name, sp->type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 578 | |
| 579 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 580 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 581 | sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 582 | |
| 583 | switch (sp->type) { |
| 584 | case SRB_NACK_PLOGI: |
| 585 | sp->fcport->login_gen++; |
| 586 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 587 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 588 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 589 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 590 | break; |
| 591 | |
| 592 | case SRB_NACK_PRLI: |
| 593 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 594 | sp->fcport->deleted = 0; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 595 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 596 | |
| 597 | if (!sp->fcport->login_succ && |
| 598 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 599 | sp->fcport->login_succ = 1; |
| 600 | |
| 601 | vha->fcport_count++; |
| 602 | |
| 603 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 604 | !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 605 | ql_dbg(ql_dbg_disc, vha, 0x20f3, |
| 606 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 607 | __func__, __LINE__, |
| 608 | sp->fcport->port_name, |
| 609 | vha->fcport_count); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 610 | |
| 611 | qla24xx_post_upd_fcport_work(vha, sp->fcport); |
| 612 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 613 | ql_dbg(ql_dbg_disc, vha, 0x20f5, |
| 614 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 615 | __func__, __LINE__, |
| 616 | sp->fcport->port_name, |
| 617 | vha->fcport_count); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 618 | |
| 619 | qla24xx_post_gpsc_work(vha, sp->fcport); |
| 620 | } |
| 621 | } |
| 622 | break; |
| 623 | |
| 624 | case SRB_NACK_LOGO: |
| 625 | sp->fcport->login_gen++; |
| 626 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 627 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 628 | break; |
| 629 | } |
| 630 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 631 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 632 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 636 | struct imm_ntfy_from_isp *ntfy, int type) |
| 637 | { |
| 638 | int rval = QLA_FUNCTION_FAILED; |
| 639 | srb_t *sp; |
| 640 | char *c = NULL; |
| 641 | |
| 642 | fcport->flags |= FCF_ASYNC_SENT; |
| 643 | switch (type) { |
| 644 | case SRB_NACK_PLOGI: |
| 645 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 646 | c = "PLOGI"; |
| 647 | break; |
| 648 | case SRB_NACK_PRLI: |
| 649 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 650 | fcport->deleted = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 651 | c = "PRLI"; |
| 652 | break; |
| 653 | case SRB_NACK_LOGO: |
| 654 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 655 | c = "LOGO"; |
| 656 | break; |
| 657 | } |
| 658 | |
| 659 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 660 | if (!sp) |
| 661 | goto done; |
| 662 | |
| 663 | sp->type = type; |
| 664 | sp->name = "nack"; |
| 665 | |
| 666 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 667 | |
| 668 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
Quinn Tran | 2e01d0b | 2017-12-04 14:44:56 -0800 | [diff] [blame] | 669 | sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 670 | sp->done = qla2x00_async_nack_sp_done; |
| 671 | |
| 672 | rval = qla2x00_start_sp(sp); |
| 673 | if (rval != QLA_SUCCESS) |
| 674 | goto done_free_sp; |
| 675 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 676 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
| 677 | "Async-%s %8phC hndl %x %s\n", |
| 678 | sp->name, fcport->port_name, sp->handle, c); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 679 | |
| 680 | return rval; |
| 681 | |
| 682 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 683 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 684 | done: |
| 685 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 686 | return rval; |
| 687 | } |
| 688 | |
| 689 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 690 | { |
| 691 | fc_port_t *t; |
| 692 | unsigned long flags; |
| 693 | |
| 694 | switch (e->u.nack.type) { |
| 695 | case SRB_NACK_PRLI: |
| 696 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 697 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 698 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 699 | if (t) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 700 | ql_log(ql_log_info, vha, 0xd034, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 701 | "%s create sess success %p", __func__, t); |
| 702 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 703 | /* create sess has an extra kref */ |
| 704 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
| 705 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 706 | } |
| 707 | break; |
| 708 | } |
| 709 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
| 710 | (struct imm_ntfy_from_isp*)e->u.nack.iocb, e->u.nack.type); |
| 711 | } |
| 712 | |
| 713 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 714 | { |
| 715 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 716 | struct qla_hw_data *ha = fcport->vha->hw; |
| 717 | unsigned long flags; |
| 718 | |
| 719 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 720 | |
| 721 | if (fcport->se_sess) { |
| 722 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 723 | ha->tgt.tgt_ops->put_sess(fcport); |
| 724 | } else { |
| 725 | qlt_unreg_sess(fcport); |
| 726 | } |
| 727 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 728 | } |
| 729 | |
| 730 | /* |
| 731 | * Called from qla2x00_reg_remote_port() |
| 732 | */ |
| 733 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 734 | { |
| 735 | struct qla_hw_data *ha = vha->hw; |
| 736 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 737 | struct fc_port *sess = fcport; |
| 738 | unsigned long flags; |
| 739 | |
| 740 | if (!vha->hw->tgt.tgt_ops) |
| 741 | return; |
| 742 | |
| 743 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 744 | if (tgt->tgt_stop) { |
| 745 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 746 | return; |
| 747 | } |
| 748 | |
| 749 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 750 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | if (!sess->se_sess) { |
| 755 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 756 | |
| 757 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 758 | sess = qlt_create_sess(vha, fcport, false); |
| 759 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 760 | |
| 761 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 762 | } else { |
| 763 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 764 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 765 | return; |
| 766 | } |
| 767 | |
| 768 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 769 | ql_dbg(ql_dbg_disc, vha, 0x2107, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 770 | "%s: kref_get fail sess %8phC \n", |
| 771 | __func__, sess->port_name); |
| 772 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 777 | "qla_target(%u): %ssession for port %8phC " |
| 778 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 779 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 780 | |
| 781 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 782 | "Reappeared sess %p\n", sess); |
| 783 | |
| 784 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 785 | fcport->loop_id, |
| 786 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 787 | } |
| 788 | |
| 789 | if (sess && sess->local) { |
| 790 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 791 | "qla_target(%u): local session for " |
| 792 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 793 | fcport->port_name, sess->loop_id); |
| 794 | sess->local = 0; |
| 795 | } |
| 796 | ha->tgt.tgt_ops->put_sess(sess); |
| 797 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 798 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 799 | |
| 800 | /* |
| 801 | * This is a zero-base ref-counting solution, since hardware_lock |
| 802 | * guarantees that ref_count is not modified concurrently. |
| 803 | * Upon successful return content of iocb is undefined |
| 804 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 805 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 806 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 807 | struct imm_ntfy_from_isp *iocb) |
| 808 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 809 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 810 | |
| 811 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 812 | if (pla->id.b24 == id->b24) { |
| 813 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 814 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 815 | return pla; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 820 | if (!pla) { |
| 821 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 822 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 823 | vha->vp_idx); |
| 824 | return NULL; |
| 825 | } |
| 826 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 827 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 828 | pla->id = *id; |
| 829 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 830 | |
| 831 | return pla; |
| 832 | } |
| 833 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 834 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 835 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 836 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 837 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 838 | port_id_t port_id; |
| 839 | uint16_t loop_id; |
| 840 | fc_port_t *fcport = pla->fcport; |
| 841 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 842 | BUG_ON(!pla->ref_count); |
| 843 | pla->ref_count--; |
| 844 | |
| 845 | if (pla->ref_count) |
| 846 | return; |
| 847 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 848 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 849 | "Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x" |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 850 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 851 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 852 | iocb->u.isp24.port_id[0], |
| 853 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 854 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 855 | |
| 856 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 857 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 858 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 859 | port_id.b.rsvd_1 = 0; |
| 860 | |
| 861 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 862 | |
| 863 | fcport->loop_id = loop_id; |
| 864 | fcport->d_id = port_id; |
| 865 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 866 | |
| 867 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 868 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 869 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 870 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 871 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 872 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 873 | |
| 874 | list_del(&pla->list); |
| 875 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 876 | } |
| 877 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 878 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 879 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 880 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 881 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 882 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 883 | /* Inc ref_count first because link might already be pointing at pla */ |
| 884 | pla->ref_count++; |
| 885 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 886 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 887 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 888 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 889 | sess, link, sess->port_name, |
| 890 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 891 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 892 | pla->ref_count, pla, link); |
| 893 | |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 894 | if (link == QLT_PLOGI_LINK_CONFLICT) { |
| 895 | switch (sess->disc_state) { |
| 896 | case DSC_DELETED: |
| 897 | case DSC_DELETE_PEND: |
| 898 | pla->ref_count--; |
| 899 | return; |
| 900 | default: |
| 901 | break; |
| 902 | } |
| 903 | } |
| 904 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 905 | if (sess->plogi_link[link]) |
| 906 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 907 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 908 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 909 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 910 | |
| 911 | sess->plogi_link[link] = pla; |
| 912 | } |
| 913 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 914 | typedef struct { |
| 915 | /* These fields must be initialized by the caller */ |
| 916 | port_id_t id; |
| 917 | /* |
| 918 | * number of cmds dropped while we were waiting for |
| 919 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 920 | * triggered by a command, otherwise, to 0 |
| 921 | */ |
| 922 | int cmd_count; |
| 923 | |
| 924 | /* These fields are used by callee */ |
| 925 | struct list_head list; |
| 926 | } qlt_port_logo_t; |
| 927 | |
| 928 | static void |
| 929 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 930 | { |
| 931 | qlt_port_logo_t *tmp; |
| 932 | int res; |
| 933 | |
| 934 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 935 | |
| 936 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 937 | if (tmp->id.b24 == logo->id.b24) { |
| 938 | tmp->cmd_count += logo->cmd_count; |
| 939 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 940 | return; |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | list_add_tail(&logo->list, &vha->logo_list); |
| 945 | |
| 946 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 947 | |
| 948 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 949 | |
| 950 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 951 | list_del(&logo->list); |
| 952 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 953 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 954 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 955 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 956 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 957 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 958 | } |
| 959 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 960 | static void qlt_free_session_done(struct work_struct *work) |
| 961 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 962 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 963 | free_work); |
| 964 | struct qla_tgt *tgt = sess->tgt; |
| 965 | struct scsi_qla_host *vha = sess->vha; |
| 966 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 967 | unsigned long flags; |
| 968 | bool logout_started = false; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 969 | struct event_arg ea; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 970 | scsi_qla_host_t *base_vha; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 971 | |
| 972 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 973 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 974 | " 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] | 975 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 976 | 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] | 977 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 978 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 979 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 980 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 981 | if (sess->send_els_logo) { |
| 982 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 983 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 984 | logo.id = sess->d_id; |
| 985 | logo.cmd_count = 0; |
| 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 | |
| 992 | rc = qla2x00_post_async_logout_work(vha, sess, NULL); |
| 993 | if (rc != QLA_SUCCESS) |
| 994 | ql_log(ql_log_warn, vha, 0xf085, |
| 995 | "Schedule logo failed sess %p rc %d\n", |
| 996 | sess, rc); |
| 997 | else |
| 998 | logout_started = true; |
| 999 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1000 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1001 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1002 | /* |
| 1003 | * Release the target session for FC Nexus from fabric module code. |
| 1004 | */ |
| 1005 | if (sess->se_sess != NULL) |
| 1006 | ha->tgt.tgt_ops->free_session(sess); |
| 1007 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1008 | if (logout_started) { |
| 1009 | bool traced = false; |
| 1010 | |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 1011 | while (!READ_ONCE(sess->logout_completed)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1012 | if (!traced) { |
| 1013 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 1014 | "%s: waiting for sess %p logout\n", |
| 1015 | __func__, sess); |
| 1016 | traced = true; |
| 1017 | } |
| 1018 | msleep(100); |
| 1019 | } |
| 1020 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1021 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1022 | "%s: sess %p logout completed\n",__func__, sess); |
| 1023 | } |
| 1024 | |
| 1025 | if (sess->logo_ack_needed) { |
| 1026 | sess->logo_ack_needed = 0; |
| 1027 | qla24xx_async_notify_ack(vha, sess, |
| 1028 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1029 | } |
| 1030 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1031 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1032 | if (sess->se_sess) { |
| 1033 | sess->se_sess = NULL; |
| 1034 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 1035 | tgt->sess_count--; |
| 1036 | } |
| 1037 | |
| 1038 | sess->disc_state = DSC_DELETED; |
| 1039 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1040 | sess->deleted = QLA_SESS_DELETED; |
| 1041 | sess->login_retry = vha->hw->login_retry_count; |
| 1042 | |
| 1043 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1044 | vha->fcport_count--; |
| 1045 | sess->login_succ = 0; |
| 1046 | } |
| 1047 | |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 1048 | qla2x00_clear_loop_id(sess); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1049 | |
| 1050 | if (sess->conflict) { |
| 1051 | sess->conflict->login_pause = 0; |
| 1052 | sess->conflict = NULL; |
| 1053 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1054 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1055 | } |
| 1056 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1057 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1058 | struct qlt_plogi_ack_t *own = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1059 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1060 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1061 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1062 | struct imm_ntfy_from_isp *iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1063 | |
| 1064 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1065 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1066 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1067 | "se_sess %p / sess %p port %8phC is gone," |
| 1068 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1069 | sess->se_sess, sess, sess->port_name, |
| 1070 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1071 | own ? own->ref_count : -1, |
| 1072 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1073 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1074 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1075 | } else { |
| 1076 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1077 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1078 | sess->se_sess, sess, sess->port_name, |
| 1079 | own ? "releasing own PLOGI" : |
| 1080 | "no own PLOGI pending", |
| 1081 | own ? own->ref_count : -1); |
| 1082 | } |
| 1083 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1084 | if (own) { |
| 1085 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1086 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1087 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1088 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1089 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1090 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1091 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1092 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1093 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1094 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1095 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1096 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1097 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1098 | |
| 1099 | if (vha->fcport_count == 0) |
| 1100 | wake_up_all(&vha->fcport_waitQ); |
| 1101 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1102 | base_vha = pci_get_drvdata(ha->pdev); |
| 1103 | if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags)) |
| 1104 | return; |
| 1105 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1106 | if (!tgt || !tgt->tgt_stop) { |
| 1107 | memset(&ea, 0, sizeof(ea)); |
| 1108 | ea.event = FCME_DELETE_DONE; |
| 1109 | ea.fcport = sess; |
| 1110 | qla2x00_fcport_event_handler(vha, &ea); |
| 1111 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1112 | } |
| 1113 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1114 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1115 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1116 | { |
| 1117 | struct scsi_qla_host *vha = sess->vha; |
| 1118 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1119 | ql_dbg(ql_dbg_disc, sess->vha, 0x210a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1120 | "%s sess %p for deletion %8phC\n", |
| 1121 | __func__, sess, sess->port_name); |
| 1122 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1123 | if (sess->se_sess) |
| 1124 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1125 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1126 | qla2x00_mark_device_lost(vha, sess, 1, 1); |
| 1127 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1128 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1129 | sess->disc_state = DSC_DELETE_PEND; |
| 1130 | sess->last_rscn_gen = sess->rscn_gen; |
| 1131 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1132 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1133 | if (sess->nvme_flag & NVME_FLAG_REGISTERED) |
| 1134 | schedule_work(&sess->nvme_del_work); |
| 1135 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1136 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 1137 | schedule_work(&sess->free_work); |
| 1138 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1139 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1140 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1141 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1142 | { |
| 1143 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1144 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1145 | uint16_t loop_id; |
| 1146 | int res = 0; |
| 1147 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1148 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1149 | |
| 1150 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1151 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1152 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1153 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1154 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1155 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1156 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1157 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1158 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1159 | 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] | 1160 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1164 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1165 | if (!sess) { |
| 1166 | res = -ESRCH; |
| 1167 | return res; |
| 1168 | } |
| 1169 | |
| 1170 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1171 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1172 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1173 | mcmd, loop_id); |
| 1174 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1175 | 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] | 1176 | } |
| 1177 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1178 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1179 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1180 | if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1181 | sess->logout_on_delete = 0; |
| 1182 | sess->logo_ack_needed = 0; |
| 1183 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1184 | sess->scan_state = 0; |
| 1185 | } |
| 1186 | } |
| 1187 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1188 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1189 | void qlt_schedule_sess_for_deletion(struct fc_port *sess, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1190 | bool immediate) |
| 1191 | { |
| 1192 | struct qla_tgt *tgt = sess->tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1193 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1194 | if (sess->disc_state == DSC_DELETE_PEND) |
| 1195 | return; |
| 1196 | |
| 1197 | if (sess->disc_state == DSC_DELETED) { |
| 1198 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1199 | wake_up_all(&tgt->waitQ); |
| 1200 | if (sess->vha->fcport_count == 0) |
| 1201 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1202 | |
| 1203 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1204 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1205 | return; |
| 1206 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1207 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1208 | sess->disc_state = DSC_DELETE_PEND; |
| 1209 | |
| 1210 | if (sess->deleted == QLA_SESS_DELETED) |
| 1211 | sess->logout_on_delete = 0; |
| 1212 | |
| 1213 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
| 1214 | qla24xx_chk_fcp_state(sess); |
| 1215 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1216 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
| 1217 | "Scheduling sess %p for deletion\n", sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1218 | |
Quinn Tran | a01c77d | 2017-12-04 14:44:58 -0800 | [diff] [blame] | 1219 | INIT_WORK(&sess->del_work, qla24xx_delete_sess_fn); |
| 1220 | queue_work(sess->vha->hw->wq, &sess->del_work); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1221 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1222 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1223 | void qlt_schedule_sess_for_deletion_lock(struct fc_port *sess) |
| 1224 | { |
| 1225 | unsigned long flags; |
| 1226 | struct qla_hw_data *ha = sess->vha->hw; |
| 1227 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1228 | qlt_schedule_sess_for_deletion(sess, 1); |
| 1229 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1232 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1233 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1234 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1235 | struct fc_port *sess; |
| 1236 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1237 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1238 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1239 | if (sess->se_sess) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1240 | qlt_schedule_sess_for_deletion(sess, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1241 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1242 | |
| 1243 | /* At this point tgt could be already dead */ |
| 1244 | } |
| 1245 | |
| 1246 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 1247 | uint16_t *loop_id) |
| 1248 | { |
| 1249 | struct qla_hw_data *ha = vha->hw; |
| 1250 | dma_addr_t gid_list_dma; |
| 1251 | struct gid_list_info *gid_list; |
| 1252 | char *id_iter; |
| 1253 | int res, rc, i; |
| 1254 | uint16_t entries; |
| 1255 | |
| 1256 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1257 | &gid_list_dma, GFP_KERNEL); |
| 1258 | if (!gid_list) { |
| 1259 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1260 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1261 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1262 | return -ENOMEM; |
| 1263 | } |
| 1264 | |
| 1265 | /* Get list of logged in devices */ |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1266 | rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1267 | if (rc != QLA_SUCCESS) { |
| 1268 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1269 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1270 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1271 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1272 | goto out_free_id_list; |
| 1273 | } |
| 1274 | |
| 1275 | id_iter = (char *)gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1276 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1277 | for (i = 0; i < entries; i++) { |
| 1278 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; |
| 1279 | if ((gid->al_pa == s_id[2]) && |
| 1280 | (gid->area == s_id[1]) && |
| 1281 | (gid->domain == s_id[0])) { |
| 1282 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1283 | res = 0; |
| 1284 | break; |
| 1285 | } |
| 1286 | id_iter += ha->gid_list_info_size; |
| 1287 | } |
| 1288 | |
| 1289 | out_free_id_list: |
| 1290 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1291 | gid_list, gid_list_dma); |
| 1292 | return res; |
| 1293 | } |
| 1294 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1295 | /* |
| 1296 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1297 | * Caller must put it. |
| 1298 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1299 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1300 | struct scsi_qla_host *vha, |
| 1301 | fc_port_t *fcport, |
| 1302 | bool local) |
| 1303 | { |
| 1304 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1305 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1306 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1307 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1308 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1309 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1310 | |
| 1311 | if (fcport->se_sess) { |
| 1312 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1313 | ql_dbg(ql_dbg_disc, vha, 0x20f6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1314 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1315 | __func__, sess->port_name); |
| 1316 | return NULL; |
| 1317 | } |
| 1318 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1319 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1320 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1321 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1322 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1323 | /* |
| 1324 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1325 | * session eventually ends and release corresponding nport handle. |
| 1326 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1327 | * code will adjust these flags as necessary. |
| 1328 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1329 | sess->logout_on_delete = 1; |
| 1330 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1331 | sess->logout_completed = 0; |
| 1332 | |
| 1333 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1334 | &fcport->port_name[0], sess) < 0) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1335 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1336 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1337 | vha->vp_idx, fcport->port_name); |
| 1338 | return NULL; |
| 1339 | } else { |
| 1340 | kref_init(&fcport->sess_kref); |
| 1341 | /* |
| 1342 | * Take an extra reference to ->sess_kref here to handle |
| 1343 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1344 | */ |
| 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, 0x20f7, |
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 | |
| 1352 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1353 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1354 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1355 | |
| 1356 | qlt_do_generation_tick(vha, &sess->generation); |
| 1357 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1358 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1359 | |
| 1360 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1361 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1362 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1363 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1364 | |
| 1365 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1366 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1367 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1368 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1369 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1370 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1371 | |
| 1372 | return sess; |
| 1373 | } |
| 1374 | |
| 1375 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1376 | * max_gen - specifies maximum session generation |
| 1377 | * at which this deletion requestion is still valid |
| 1378 | */ |
| 1379 | void |
| 1380 | 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] | 1381 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1382 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1383 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1384 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1385 | |
| 1386 | if (!vha->hw->tgt.tgt_ops) |
| 1387 | return; |
| 1388 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1389 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1390 | return; |
| 1391 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1392 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1393 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1394 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1395 | return; |
| 1396 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1397 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1398 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1399 | return; |
| 1400 | } |
| 1401 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1402 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1403 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1404 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1405 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1406 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1407 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1408 | sess->generation); |
| 1409 | return; |
| 1410 | } |
| 1411 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1412 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1413 | |
| 1414 | sess->local = 1; |
| 1415 | qlt_schedule_sess_for_deletion(sess, false); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1416 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1420 | { |
| 1421 | struct qla_hw_data *ha = tgt->ha; |
| 1422 | unsigned long flags; |
| 1423 | int res; |
| 1424 | /* |
| 1425 | * We need to protect against race, when tgt is freed before or |
| 1426 | * inside wake_up() |
| 1427 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1428 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1429 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1430 | "tgt %p, sess_count=%d\n", |
| 1431 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1432 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1433 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1434 | |
| 1435 | return res; |
| 1436 | } |
| 1437 | |
| 1438 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1439 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1440 | { |
| 1441 | struct scsi_qla_host *vha = tgt->vha; |
| 1442 | struct qla_hw_data *ha = tgt->ha; |
| 1443 | unsigned long flags; |
| 1444 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1445 | mutex_lock(&qla_tgt_mutex); |
| 1446 | if (!vha->fc_vport) { |
| 1447 | struct Scsi_Host *sh = vha->host; |
| 1448 | struct fc_host_attrs *fc_host = shost_to_fc_host(sh); |
| 1449 | bool npiv_vports; |
| 1450 | |
| 1451 | spin_lock_irqsave(sh->host_lock, flags); |
| 1452 | npiv_vports = (fc_host->npiv_vports_inuse); |
| 1453 | spin_unlock_irqrestore(sh->host_lock, flags); |
| 1454 | |
| 1455 | if (npiv_vports) { |
| 1456 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1457 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, |
| 1458 | "NPIV is in use. Can not stop target\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1459 | return -EPERM; |
| 1460 | } |
| 1461 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1462 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1463 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1464 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1465 | mutex_unlock(&qla_tgt_mutex); |
| 1466 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1467 | } |
| 1468 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1469 | 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] | 1470 | vha->host_no, vha); |
| 1471 | /* |
| 1472 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1473 | * Lock is needed, because we still can get an incoming packet. |
| 1474 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1475 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1476 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1477 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1478 | qlt_clear_tgt_db(tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1479 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1480 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1481 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1482 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1483 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1484 | "Waiting for sess works (tgt %p)", tgt); |
| 1485 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1486 | while (!list_empty(&tgt->sess_works_list)) { |
| 1487 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1488 | flush_scheduled_work(); |
| 1489 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1490 | } |
| 1491 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1492 | |
| 1493 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1494 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1495 | |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1496 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1497 | |
| 1498 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1499 | if (!ha->flags.host_shutting_down && |
| 1500 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1501 | qlt_disable_vha(vha); |
| 1502 | |
| 1503 | /* Wait for sessions to clear out (just in case) */ |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1504 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1505 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1506 | } |
| 1507 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1508 | |
| 1509 | /* Called by tcm_qla2xxx configfs code */ |
| 1510 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1511 | { |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1512 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1513 | |
| 1514 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1515 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1516 | "Already in tgt->tgt_stopped state\n"); |
| 1517 | dump_stack(); |
| 1518 | return; |
| 1519 | } |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1520 | if (!tgt->tgt_stop) { |
| 1521 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
| 1522 | "%s: phase1 stop is not completed\n", __func__); |
| 1523 | dump_stack(); |
| 1524 | return; |
| 1525 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1526 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1527 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1528 | tgt->tgt_stop = 0; |
| 1529 | tgt->tgt_stopped = 1; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1530 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1531 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1532 | 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] | 1533 | tgt); |
| 1534 | } |
| 1535 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1536 | |
| 1537 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1538 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1539 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1540 | scsi_qla_host_t *vha = tgt->vha; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1541 | void *node; |
| 1542 | u64 key = 0; |
| 1543 | u16 i; |
| 1544 | struct qla_qpair_hint *h; |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1545 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1546 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1547 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stop && |
| 1548 | !tgt->tgt_stopped) |
| 1549 | qlt_stop_phase1(tgt); |
| 1550 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1551 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1552 | qlt_stop_phase2(tgt); |
| 1553 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1554 | for (i = 0; i < vha->hw->max_qpairs + 1; i++) { |
| 1555 | unsigned long flags; |
| 1556 | |
| 1557 | h = &tgt->qphints[i]; |
| 1558 | if (h->qpair) { |
| 1559 | spin_lock_irqsave(h->qpair->qp_lock_ptr, flags); |
| 1560 | list_del(&h->hint_elem); |
| 1561 | spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags); |
| 1562 | h->qpair = NULL; |
| 1563 | } |
| 1564 | } |
| 1565 | kfree(tgt->qphints); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1566 | mutex_lock(&qla_tgt_mutex); |
| 1567 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
| 1568 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1569 | |
| 1570 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 1571 | btree_remove64(&tgt->lun_qpair_map, key); |
| 1572 | |
| 1573 | btree_destroy64(&tgt->lun_qpair_map); |
| 1574 | |
Sawan Chandak | 3be63b1e | 2017-12-04 14:45:04 -0800 | [diff] [blame] | 1575 | if (vha->vp_idx) |
| 1576 | if (ha->tgt.tgt_ops && |
| 1577 | ha->tgt.tgt_ops->remove_target && |
| 1578 | vha->vha_tgt.target_lport_ptr) |
| 1579 | ha->tgt.tgt_ops->remove_target(vha); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1580 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1581 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1582 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1583 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1584 | "Release of tgt %p finished\n", tgt); |
| 1585 | |
| 1586 | kfree(tgt); |
| 1587 | } |
| 1588 | |
| 1589 | /* ha->hardware_lock supposed to be held on entry */ |
| 1590 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1591 | const void *param, unsigned int param_size) |
| 1592 | { |
| 1593 | struct qla_tgt_sess_work_param *prm; |
| 1594 | unsigned long flags; |
| 1595 | |
| 1596 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1597 | if (!prm) { |
| 1598 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1599 | "qla_target(%d): Unable to create session " |
| 1600 | "work, command will be refused", 0); |
| 1601 | return -ENOMEM; |
| 1602 | } |
| 1603 | |
| 1604 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1605 | "Scheduling work (type %d, prm %p)" |
| 1606 | " to find session for param %p (size %d, tgt %p)\n", |
| 1607 | type, prm, param, param_size, tgt); |
| 1608 | |
| 1609 | prm->type = type; |
| 1610 | memcpy(&prm->tm_iocb, param, param_size); |
| 1611 | |
| 1612 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1613 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1614 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1615 | |
| 1616 | schedule_work(&tgt->sess_work); |
| 1617 | |
| 1618 | return 0; |
| 1619 | } |
| 1620 | |
| 1621 | /* |
| 1622 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1623 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1624 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1625 | struct imm_ntfy_from_isp *ntfy, |
| 1626 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1627 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1628 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1629 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1630 | struct qla_hw_data *ha = vha->hw; |
| 1631 | request_t *pkt; |
| 1632 | struct nack_to_isp *nack; |
| 1633 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 1634 | if (!ha->flags.fw_started) |
| 1635 | return; |
| 1636 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1637 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1638 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1639 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1640 | if (!pkt) { |
| 1641 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1642 | "qla_target(%d): %s failed: unable to allocate " |
| 1643 | "request packet\n", vha->vp_idx, __func__); |
| 1644 | return; |
| 1645 | } |
| 1646 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1647 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1648 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1649 | |
| 1650 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1651 | pkt->entry_count = 1; |
| 1652 | |
| 1653 | nack = (struct nack_to_isp *)pkt; |
| 1654 | nack->ox_id = ntfy->ox_id; |
| 1655 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1656 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1657 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1658 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1659 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1660 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1661 | } |
| 1662 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1663 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1664 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1665 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1666 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1667 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1668 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1669 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1670 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1671 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1672 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1673 | |
| 1674 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1675 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1676 | vha->vp_idx, nack->u.isp24.status); |
| 1677 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1678 | /* Memory Barrier */ |
| 1679 | wmb(); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1680 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | /* |
| 1684 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1685 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1686 | static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1687 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1688 | bool ids_reversed) |
| 1689 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1690 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1691 | struct qla_hw_data *ha = vha->hw; |
| 1692 | struct abts_resp_to_24xx *resp; |
| 1693 | uint32_t f_ctl; |
| 1694 | uint8_t *p; |
| 1695 | |
| 1696 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1697 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1698 | ha, abts, status); |
| 1699 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1700 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, |
| 1701 | NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1702 | if (!resp) { |
| 1703 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1704 | "qla_target(%d): %s failed: unable to allocate " |
| 1705 | "request packet", vha->vp_idx, __func__); |
| 1706 | return; |
| 1707 | } |
| 1708 | |
| 1709 | resp->entry_type = ABTS_RESP_24XX; |
| 1710 | resp->entry_count = 1; |
| 1711 | resp->nport_handle = abts->nport_handle; |
| 1712 | resp->vp_index = vha->vp_idx; |
| 1713 | resp->sof_type = abts->sof_type; |
| 1714 | resp->exchange_address = abts->exchange_address; |
| 1715 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1716 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1717 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1718 | F_CTL_SEQ_INITIATIVE); |
| 1719 | p = (uint8_t *)&f_ctl; |
| 1720 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1721 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1722 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1723 | if (ids_reversed) { |
| 1724 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1725 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1726 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1727 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1728 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1729 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1730 | } else { |
| 1731 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1732 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1733 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1734 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1735 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1736 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1737 | } |
| 1738 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1739 | if (status == FCP_TMF_CMPL) { |
| 1740 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1741 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1742 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1743 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1744 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1745 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1746 | } else { |
| 1747 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1748 | resp->payload.ba_rjt.reason_code = |
| 1749 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1750 | /* Other bytes are zero */ |
| 1751 | } |
| 1752 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1753 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1754 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1755 | /* Memory Barrier */ |
| 1756 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 1757 | if (qpair->reqq_start_iocbs) |
| 1758 | qpair->reqq_start_iocbs(qpair); |
| 1759 | else |
| 1760 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | /* |
| 1764 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1765 | */ |
| 1766 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
| 1767 | struct abts_resp_from_24xx_fw *entry) |
| 1768 | { |
| 1769 | struct ctio7_to_24xx *ctio; |
| 1770 | |
| 1771 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1772 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1773 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1774 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready( |
| 1775 | vha->hw->base_qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1776 | if (ctio == NULL) { |
| 1777 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1778 | "qla_target(%d): %s failed: unable to allocate " |
| 1779 | "request packet\n", vha->vp_idx, __func__); |
| 1780 | return; |
| 1781 | } |
| 1782 | |
| 1783 | /* |
| 1784 | * We've got on entrance firmware's response on by us generated |
| 1785 | * ABTS response. So, in it ID fields are reversed. |
| 1786 | */ |
| 1787 | |
| 1788 | ctio->entry_type = CTIO_TYPE7; |
| 1789 | ctio->entry_count = 1; |
| 1790 | ctio->nport_handle = entry->nport_handle; |
| 1791 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1792 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1793 | ctio->vp_index = vha->vp_idx; |
| 1794 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1795 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1796 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1797 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1798 | ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
| 1799 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1800 | 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] | 1801 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1802 | /* Memory Barrier */ |
| 1803 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1804 | qla2x00_start_iocbs(vha, vha->req); |
| 1805 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1806 | qlt_24xx_send_abts_resp(vha->hw->base_qpair, |
| 1807 | (struct abts_recv_from_24xx *)entry, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1808 | FCP_TMF_CMPL, true); |
| 1809 | } |
| 1810 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1811 | static int abort_cmd_for_tag(struct scsi_qla_host *vha, uint32_t tag) |
| 1812 | { |
| 1813 | struct qla_tgt_sess_op *op; |
| 1814 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1815 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1816 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1817 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1818 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1819 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1820 | op->aborted = true; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1821 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1822 | return 1; |
| 1823 | } |
| 1824 | } |
| 1825 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1826 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1827 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1828 | op->aborted = true; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1829 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1830 | return 1; |
| 1831 | } |
| 1832 | } |
| 1833 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1834 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1835 | if (tag == cmd->atio.u.isp24.exchange_addr) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1836 | cmd->aborted = 1; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1837 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1838 | return 1; |
| 1839 | } |
| 1840 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1841 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1842 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1843 | return 0; |
| 1844 | } |
| 1845 | |
| 1846 | /* drop cmds for the given lun |
| 1847 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1848 | * XXX does not go through the list of other port (which may have cmds |
| 1849 | * for the same lun) |
| 1850 | */ |
| 1851 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1852 | u64 lun, uint8_t *s_id) |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1853 | { |
| 1854 | struct qla_tgt_sess_op *op; |
| 1855 | struct qla_tgt_cmd *cmd; |
| 1856 | uint32_t key; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1857 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1858 | |
| 1859 | key = sid_to_key(s_id); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1860 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1861 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1862 | uint32_t op_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1863 | u64 op_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1864 | |
| 1865 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1866 | op_lun = scsilun_to_int( |
| 1867 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1868 | if (op_key == key && op_lun == lun) |
| 1869 | op->aborted = true; |
| 1870 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1871 | |
| 1872 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1873 | uint32_t op_key; |
| 1874 | u64 op_lun; |
| 1875 | |
| 1876 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1877 | op_lun = scsilun_to_int( |
| 1878 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1879 | if (op_key == key && op_lun == lun) |
| 1880 | op->aborted = true; |
| 1881 | } |
| 1882 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1883 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1884 | uint32_t cmd_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1885 | u64 cmd_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1886 | |
| 1887 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1888 | cmd_lun = scsilun_to_int( |
| 1889 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 1890 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1891 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1892 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1893 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1894 | } |
| 1895 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1896 | /* ha->hardware_lock supposed to be held on entry */ |
| 1897 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1898 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1899 | { |
| 1900 | struct qla_hw_data *ha = vha->hw; |
| 1901 | struct qla_tgt_mgmt_cmd *mcmd; |
| 1902 | int rc; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1903 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 1904 | if (abort_cmd_for_tag(vha, abts->exchange_addr_to_abort)) { |
| 1905 | /* send TASK_ABORT response immediately */ |
Linus Torvalds | 48ea2ce | 2017-07-13 14:27:32 -0700 | [diff] [blame] | 1906 | 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] | 1907 | return 0; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1908 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1909 | |
| 1910 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 1911 | "qla_target(%d): task abort (tag=%d)\n", |
| 1912 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 1913 | |
| 1914 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 1915 | if (mcmd == NULL) { |
| 1916 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 1917 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 1918 | vha->vp_idx, __func__); |
| 1919 | return -ENOMEM; |
| 1920 | } |
| 1921 | memset(mcmd, 0, sizeof(*mcmd)); |
| 1922 | |
| 1923 | mcmd->sess = sess; |
| 1924 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1925 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 1926 | mcmd->tmr_func = QLA_TGT_ABTS; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1927 | mcmd->qpair = ha->base_qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 1928 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1929 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 1930 | /* |
| 1931 | * LUN is looked up by target-core internally based on the passed |
| 1932 | * abts->exchange_addr_to_abort tag. |
| 1933 | */ |
| 1934 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, 0, mcmd->tmr_func, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1935 | abts->exchange_addr_to_abort); |
| 1936 | if (rc != 0) { |
| 1937 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, |
| 1938 | "qla_target(%d): tgt_ops->handle_tmr()" |
| 1939 | " failed: %d", vha->vp_idx, rc); |
| 1940 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 1941 | return -EFAULT; |
| 1942 | } |
| 1943 | |
| 1944 | return 0; |
| 1945 | } |
| 1946 | |
| 1947 | /* |
| 1948 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1949 | */ |
| 1950 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 1951 | struct abts_recv_from_24xx *abts) |
| 1952 | { |
| 1953 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1954 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1955 | uint32_t tag = abts->exchange_addr_to_abort; |
| 1956 | uint8_t s_id[3]; |
| 1957 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1958 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1959 | |
| 1960 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 1961 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 1962 | "qla_target(%d): ABTS: Abort Sequence not " |
| 1963 | "supported\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1964 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 1965 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1966 | return; |
| 1967 | } |
| 1968 | |
| 1969 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 1970 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 1971 | "qla_target(%d): ABTS: Unknown Exchange " |
| 1972 | "Address received\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1973 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 1974 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1975 | return; |
| 1976 | } |
| 1977 | |
| 1978 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 1979 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 1980 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 1981 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 1982 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 1983 | |
| 1984 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 1985 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1986 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 1987 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1988 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1989 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 1990 | if (!sess) { |
| 1991 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
| 1992 | "qla_target(%d): task abort for non-existant session\n", |
| 1993 | vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1994 | rc = qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1995 | QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1996 | |
| 1997 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1998 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1999 | if (rc != 0) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2000 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, |
| 2001 | FCP_TMF_REJECTED, false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2002 | } |
| 2003 | return; |
| 2004 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 2005 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 2006 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2007 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2008 | if (sess->deleted) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2009 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2010 | false); |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 2011 | return; |
| 2012 | } |
| 2013 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2014 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 2015 | if (rc != 0) { |
| 2016 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 2017 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 2018 | vha->vp_idx, rc); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2019 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2020 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2021 | return; |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | /* |
| 2026 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2027 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2028 | static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2029 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 2030 | { |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2031 | struct scsi_qla_host *ha = mcmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2032 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 2033 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2034 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2035 | |
| 2036 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 2037 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 2038 | ha, atio, resp_code); |
| 2039 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2040 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2041 | ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2042 | if (ctio == NULL) { |
| 2043 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 2044 | "qla_target(%d): %s failed: unable to allocate " |
| 2045 | "request packet\n", ha->vp_idx, __func__); |
| 2046 | return; |
| 2047 | } |
| 2048 | |
| 2049 | ctio->entry_type = CTIO_TYPE7; |
| 2050 | ctio->entry_count = 1; |
| 2051 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 2052 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2053 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2054 | ctio->vp_index = ha->vp_idx; |
| 2055 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2056 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2057 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2058 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2059 | temp = (atio->u.isp24.attr << 9)| |
| 2060 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2061 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2062 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2063 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2064 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2065 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2066 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2067 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2068 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2069 | /* Memory Barrier */ |
| 2070 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2071 | if (qpair->reqq_start_iocbs) |
| 2072 | qpair->reqq_start_iocbs(qpair); |
| 2073 | else |
| 2074 | qla2x00_start_iocbs(ha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2078 | { |
| 2079 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2080 | } |
| 2081 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2082 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2083 | /* |
| 2084 | * ha->hardware_lock supposed to be held on entry. Might drop it, then |
| 2085 | * reacquire |
| 2086 | */ |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2087 | 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] | 2088 | uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq) |
| 2089 | { |
| 2090 | struct atio_from_isp *atio = &cmd->atio; |
| 2091 | struct ctio7_to_24xx *ctio; |
| 2092 | uint16_t temp; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2093 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2094 | |
| 2095 | ql_dbg(ql_dbg_tgt_dif, vha, 0x3066, |
| 2096 | "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, " |
| 2097 | "sense_key=%02x, asc=%02x, ascq=%02x", |
| 2098 | vha, atio, scsi_status, sense_key, asc, ascq); |
| 2099 | |
| 2100 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); |
| 2101 | if (!ctio) { |
| 2102 | ql_dbg(ql_dbg_async, vha, 0x3067, |
| 2103 | "qla2x00t(%ld): %s failed: unable to allocate request packet", |
| 2104 | vha->host_no, __func__); |
| 2105 | goto out; |
| 2106 | } |
| 2107 | |
| 2108 | ctio->entry_type = CTIO_TYPE7; |
| 2109 | ctio->entry_count = 1; |
| 2110 | ctio->handle = QLA_TGT_SKIP_HANDLE; |
| 2111 | ctio->nport_handle = cmd->sess->loop_id; |
| 2112 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
| 2113 | ctio->vp_index = vha->vp_idx; |
| 2114 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2115 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2116 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2117 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2118 | temp = (atio->u.isp24.attr << 9) | |
| 2119 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2120 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2121 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2122 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
| 2123 | ctio->u.status1.scsi_status = |
| 2124 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status); |
| 2125 | ctio->u.status1.response_len = cpu_to_le16(18); |
| 2126 | ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
| 2127 | |
| 2128 | if (ctio->u.status1.residual != 0) |
| 2129 | ctio->u.status1.scsi_status |= |
| 2130 | cpu_to_le16(SS_RESIDUAL_UNDER); |
| 2131 | |
| 2132 | /* Response code and sense key */ |
| 2133 | put_unaligned_le32(((0x70 << 24) | (sense_key << 8)), |
| 2134 | (&ctio->u.status1.sense_data)[0]); |
| 2135 | /* Additional sense length */ |
| 2136 | put_unaligned_le32(0x0a, (&ctio->u.status1.sense_data)[1]); |
| 2137 | /* ASC and ASCQ */ |
| 2138 | put_unaligned_le32(((asc << 24) | (ascq << 16)), |
| 2139 | (&ctio->u.status1.sense_data)[3]); |
| 2140 | |
| 2141 | /* Memory Barrier */ |
| 2142 | wmb(); |
| 2143 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2144 | if (qpair->reqq_start_iocbs) |
| 2145 | qpair->reqq_start_iocbs(qpair); |
| 2146 | else |
| 2147 | qla2x00_start_iocbs(vha, qpair->req); |
| 2148 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2149 | out: |
| 2150 | return; |
| 2151 | } |
| 2152 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2153 | /* callback from target fabric module code */ |
| 2154 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2155 | { |
| 2156 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2157 | struct qla_hw_data *ha = vha->hw; |
| 2158 | unsigned long flags; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2159 | struct qla_qpair *qpair = mcmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2160 | |
| 2161 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2162 | "TM response mcmd (%p) status %#x state %#x", |
| 2163 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2164 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2165 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2166 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2167 | if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2168 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2169 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2170 | * previous life, just abort the processing. |
| 2171 | */ |
| 2172 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2173 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2174 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2175 | mcmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2176 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2177 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2178 | return; |
| 2179 | } |
| 2180 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2181 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
| 2182 | if (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2183 | ELS_LOGO || |
| 2184 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2185 | ELS_PRLO || |
| 2186 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2187 | ELS_TPRLO) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2188 | ql_dbg(ql_dbg_disc, vha, 0x2106, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2189 | "TM response logo %phC status %#x state %#x", |
| 2190 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2191 | mcmd->flags); |
| 2192 | qlt_schedule_sess_for_deletion_lock(mcmd->sess); |
| 2193 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2194 | qlt_send_notify_ack(vha->hw->base_qpair, |
| 2195 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2196 | } |
| 2197 | } else { |
Swapnil Nagle | d7236ac | 2016-02-04 11:45:17 -0500 | [diff] [blame] | 2198 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2199 | qlt_24xx_send_abts_resp(qpair, &mcmd->orig_iocb.abts, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2200 | mcmd->fc_tm_rsp, false); |
| 2201 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2202 | qlt_24xx_send_task_mgmt_ctio(qpair, mcmd, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2203 | mcmd->fc_tm_rsp); |
| 2204 | } |
| 2205 | /* |
| 2206 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2207 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2208 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2209 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2210 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2211 | * qlt_xmit_tm_rsp() returns here.. |
| 2212 | */ |
| 2213 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2214 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2215 | } |
| 2216 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2217 | |
| 2218 | /* No locks */ |
| 2219 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2220 | { |
| 2221 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2222 | |
| 2223 | BUG_ON(cmd->sg_cnt == 0); |
| 2224 | |
| 2225 | prm->sg = (struct scatterlist *)cmd->sg; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2226 | prm->seg_cnt = pci_map_sg(cmd->qpair->pdev, cmd->sg, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2227 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2228 | if (unlikely(prm->seg_cnt == 0)) |
| 2229 | goto out_err; |
| 2230 | |
| 2231 | prm->cmd->sg_mapped = 1; |
| 2232 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2233 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2234 | /* |
| 2235 | * If greater than four sg entries then we need to allocate |
| 2236 | * the continuation entries |
| 2237 | */ |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2238 | if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2239 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2240 | QLA_TGT_DATASEGS_PER_CMD_24XX, |
| 2241 | QLA_TGT_DATASEGS_PER_CONT_24XX); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2242 | } else { |
| 2243 | /* DIF */ |
| 2244 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2245 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2246 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2247 | prm->tot_dsds = prm->seg_cnt; |
| 2248 | } else |
| 2249 | prm->tot_dsds = prm->seg_cnt; |
| 2250 | |
| 2251 | if (cmd->prot_sg_cnt) { |
| 2252 | prm->prot_sg = cmd->prot_sg; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2253 | prm->prot_seg_cnt = pci_map_sg(cmd->qpair->pdev, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2254 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2255 | cmd->dma_data_direction); |
| 2256 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2257 | goto out_err; |
| 2258 | |
| 2259 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2260 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2261 | /* Dif Bundling not support here */ |
| 2262 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2263 | cmd->blk_sz); |
| 2264 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2265 | } else |
| 2266 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2267 | } |
| 2268 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2269 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2270 | return 0; |
| 2271 | |
| 2272 | out_err: |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2273 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2274 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2275 | 0, prm->cmd->sg_cnt); |
| 2276 | return -1; |
| 2277 | } |
| 2278 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2279 | 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] | 2280 | { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2281 | struct qla_hw_data *ha; |
| 2282 | struct qla_qpair *qpair; |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2283 | if (!cmd->sg_mapped) |
| 2284 | return; |
| 2285 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2286 | qpair = cmd->qpair; |
| 2287 | |
| 2288 | pci_unmap_sg(qpair->pdev, cmd->sg, cmd->sg_cnt, |
| 2289 | cmd->dma_data_direction); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2290 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2291 | |
| 2292 | if (cmd->prot_sg_cnt) |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2293 | pci_unmap_sg(qpair->pdev, cmd->prot_sg, cmd->prot_sg_cnt, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2294 | cmd->dma_data_direction); |
| 2295 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2296 | if (!cmd->ctx) |
| 2297 | return; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2298 | ha = vha->hw; |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2299 | if (cmd->ctx_dsd_alloced) |
| 2300 | qla2x00_clean_dsd_pool(ha, cmd->ctx); |
| 2301 | |
| 2302 | 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] | 2303 | } |
| 2304 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2305 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2306 | uint32_t req_cnt) |
| 2307 | { |
Quinn Tran | d63b328 | 2017-06-02 09:12:07 -0700 | [diff] [blame] | 2308 | uint32_t cnt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2309 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2310 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2311 | if (req->cnt < (req_cnt + 2)) { |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 2312 | cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr : |
| 2313 | RD_REG_DWORD_RELAXED(req->req_q_out)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2314 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2315 | if (req->ring_index < cnt) |
| 2316 | req->cnt = cnt - req->ring_index; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2317 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2318 | req->cnt = req->length - (req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2319 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2320 | if (unlikely(req->cnt < (req_cnt + 2))) |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2321 | return -EAGAIN; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2322 | } |
| 2323 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2324 | req->cnt -= req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2325 | |
| 2326 | return 0; |
| 2327 | } |
| 2328 | |
| 2329 | /* |
| 2330 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2331 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2332 | static inline void *qlt_get_req_pkt(struct req_que *req) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2333 | { |
| 2334 | /* Adjust ring index. */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2335 | req->ring_index++; |
| 2336 | if (req->ring_index == req->length) { |
| 2337 | req->ring_index = 0; |
| 2338 | req->ring_ptr = req->ring; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2339 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2340 | req->ring_ptr++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2341 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2342 | return (cont_entry_t *)req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2346 | static inline uint32_t qlt_make_handle(struct qla_qpair *qpair) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2347 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2348 | uint32_t h; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2349 | int index; |
| 2350 | uint8_t found = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2351 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2352 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2353 | h = req->current_outstanding_cmd; |
| 2354 | |
| 2355 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 2356 | h++; |
| 2357 | if (h == req->num_outstanding_cmds) |
| 2358 | h = 1; |
| 2359 | |
| 2360 | if (h == QLA_TGT_SKIP_HANDLE) |
| 2361 | continue; |
| 2362 | |
| 2363 | if (!req->outstanding_cmds[h]) { |
| 2364 | found = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2365 | break; |
| 2366 | } |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2367 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2368 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2369 | if (found) { |
| 2370 | req->current_outstanding_cmd = h; |
| 2371 | } else { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2372 | ql_dbg(ql_dbg_io, qpair->vha, 0x305b, |
| 2373 | "qla_target(%d): Ran out of empty cmd slots\n", |
| 2374 | qpair->vha->vp_idx); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2375 | h = QLA_TGT_NULL_HANDLE; |
| 2376 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2377 | |
| 2378 | return h; |
| 2379 | } |
| 2380 | |
| 2381 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2382 | static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair, |
| 2383 | struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2384 | { |
| 2385 | uint32_t h; |
| 2386 | struct ctio7_to_24xx *pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2387 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2388 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2389 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2390 | pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2391 | prm->pkt = pkt; |
| 2392 | memset(pkt, 0, sizeof(*pkt)); |
| 2393 | |
| 2394 | pkt->entry_type = CTIO_TYPE7; |
| 2395 | pkt->entry_count = (uint8_t)prm->req_cnt; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2396 | pkt->vp_index = prm->cmd->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2397 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2398 | h = qlt_make_handle(qpair); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2399 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2400 | /* |
| 2401 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2402 | * know the initiator's LOOP ID, hence we can't find |
| 2403 | * the session and, so, the command. |
| 2404 | */ |
| 2405 | return -EAGAIN; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 2406 | } else |
| 2407 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2408 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2409 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2410 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
| 2411 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2412 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2413 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2414 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2415 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2416 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2417 | temp = atio->u.isp24.attr << 9; |
| 2418 | pkt->u.status0.flags |= cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2419 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2420 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2421 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2422 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2423 | return 0; |
| 2424 | } |
| 2425 | |
| 2426 | /* |
| 2427 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2428 | * that there is sufficient amount of request entries to not drop it. |
| 2429 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2430 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2431 | { |
| 2432 | int cnt; |
| 2433 | uint32_t *dword_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2434 | |
| 2435 | /* Build continuation packets */ |
| 2436 | while (prm->seg_cnt > 0) { |
| 2437 | cont_a64_entry_t *cont_pkt64 = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2438 | (cont_a64_entry_t *)qlt_get_req_pkt( |
| 2439 | prm->cmd->qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2440 | |
| 2441 | /* |
| 2442 | * Make sure that from cont_pkt64 none of |
| 2443 | * 64-bit specific fields used for 32-bit |
| 2444 | * addressing. Cast to (cont_entry_t *) for |
| 2445 | * that. |
| 2446 | */ |
| 2447 | |
| 2448 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2449 | |
| 2450 | cont_pkt64->entry_count = 1; |
| 2451 | cont_pkt64->sys_define = 0; |
| 2452 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2453 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
| 2454 | dword_ptr = (uint32_t *)&cont_pkt64->dseg_0_address; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2455 | |
| 2456 | /* Load continuation entry data segments */ |
| 2457 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2458 | cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2459 | cnt++, prm->seg_cnt--) { |
| 2460 | *dword_ptr++ = |
| 2461 | cpu_to_le32(pci_dma_lo32 |
| 2462 | (sg_dma_address(prm->sg))); |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2463 | *dword_ptr++ = cpu_to_le32(pci_dma_hi32 |
| 2464 | (sg_dma_address(prm->sg))); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2465 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2466 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2467 | prm->sg = sg_next(prm->sg); |
| 2468 | } |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | /* |
| 2473 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2474 | * that there is sufficient amount of request entries to not drop it. |
| 2475 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2476 | static void qlt_load_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2477 | { |
| 2478 | int cnt; |
| 2479 | uint32_t *dword_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2480 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2481 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2482 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2483 | |
| 2484 | /* Setup packet address segment pointer */ |
| 2485 | dword_ptr = pkt24->u.status0.dseg_0_address; |
| 2486 | |
| 2487 | /* Set total data segment count */ |
| 2488 | if (prm->seg_cnt) |
| 2489 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2490 | |
| 2491 | if (prm->seg_cnt == 0) { |
| 2492 | /* No data transfer */ |
| 2493 | *dword_ptr++ = 0; |
| 2494 | *dword_ptr = 0; |
| 2495 | return; |
| 2496 | } |
| 2497 | |
| 2498 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2499 | |
| 2500 | /* Load command entry data segments */ |
| 2501 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2502 | (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2503 | cnt++, prm->seg_cnt--) { |
| 2504 | *dword_ptr++ = |
| 2505 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2506 | |
| 2507 | *dword_ptr++ = cpu_to_le32(pci_dma_hi32( |
| 2508 | sg_dma_address(prm->sg))); |
| 2509 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2510 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2511 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2512 | prm->sg = sg_next(prm->sg); |
| 2513 | } |
| 2514 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2515 | qlt_load_cont_data_segments(prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2519 | { |
| 2520 | return cmd->bufflen > 0; |
| 2521 | } |
| 2522 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2523 | static void qlt_print_dif_err(struct qla_tgt_prm *prm) |
| 2524 | { |
| 2525 | struct qla_tgt_cmd *cmd; |
| 2526 | struct scsi_qla_host *vha; |
| 2527 | |
| 2528 | /* asc 0x10=dif error */ |
| 2529 | if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) { |
| 2530 | cmd = prm->cmd; |
| 2531 | vha = cmd->vha; |
| 2532 | /* ASCQ */ |
| 2533 | switch (prm->sense_buffer[13]) { |
| 2534 | case 1: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2535 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2536 | "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2537 | "se_cmd=%p tag[%x]", |
| 2538 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2539 | cmd->atio.u.isp24.exchange_addr); |
| 2540 | break; |
| 2541 | case 2: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2542 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2543 | "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2544 | "se_cmd=%p tag[%x]", |
| 2545 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2546 | cmd->atio.u.isp24.exchange_addr); |
| 2547 | break; |
| 2548 | case 3: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2549 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2550 | "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2551 | "se_cmd=%p tag[%x]", |
| 2552 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2553 | cmd->atio.u.isp24.exchange_addr); |
| 2554 | break; |
| 2555 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2556 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe010, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2557 | "BE detected Dif ERR: lba[%llx|%lld] len[%x] " |
| 2558 | "se_cmd=%p tag[%x]", |
| 2559 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2560 | cmd->atio.u.isp24.exchange_addr); |
| 2561 | break; |
| 2562 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2563 | ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2564 | } |
| 2565 | } |
| 2566 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2567 | /* |
| 2568 | * Called without ha->hardware_lock held |
| 2569 | */ |
| 2570 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2571 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2572 | uint32_t *full_req_cnt) |
| 2573 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2574 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2575 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2576 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2577 | prm->cmd = cmd; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2578 | prm->tgt = cmd->tgt; |
| 2579 | prm->pkt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2580 | prm->rq_result = scsi_status; |
| 2581 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2582 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2583 | prm->sg = NULL; |
| 2584 | prm->seg_cnt = -1; |
| 2585 | prm->req_cnt = 1; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2586 | prm->residual = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2587 | prm->add_status_pkt = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2588 | prm->prot_sg = NULL; |
| 2589 | prm->prot_seg_cnt = 0; |
| 2590 | prm->tot_dsds = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2591 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2592 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2593 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2594 | return -EAGAIN; |
| 2595 | } |
| 2596 | |
| 2597 | *full_req_cnt = prm->req_cnt; |
| 2598 | |
| 2599 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2600 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2601 | ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2602 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2603 | prm->residual, se_cmd->tag, |
| 2604 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2605 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2606 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2607 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2608 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2609 | ql_dbg_qp(ql_dbg_io, qpair, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2610 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2611 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2612 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2613 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2614 | } |
| 2615 | |
| 2616 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2617 | /* |
| 2618 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2619 | * ignored in *xmit_response() below |
| 2620 | */ |
| 2621 | if (qlt_has_data(cmd)) { |
| 2622 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2623 | (IS_FWI2_CAPABLE(cmd->vha->hw) && |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2624 | (prm->rq_result != 0))) { |
| 2625 | prm->add_status_pkt = 1; |
| 2626 | (*full_req_cnt)++; |
| 2627 | } |
| 2628 | } |
| 2629 | } |
| 2630 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2631 | return 0; |
| 2632 | } |
| 2633 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2634 | static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd, |
| 2635 | int sending_sense) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2636 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2637 | if (cmd->qpair->enable_class_2) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2638 | return 0; |
| 2639 | |
| 2640 | if (sending_sense) |
| 2641 | return cmd->conf_compl_supported; |
| 2642 | else |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2643 | return cmd->qpair->enable_explicit_conf && |
| 2644 | cmd->conf_compl_supported; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2645 | } |
| 2646 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2647 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2648 | struct qla_tgt_prm *prm) |
| 2649 | { |
| 2650 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2651 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2652 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2653 | if (qlt_need_explicit_conf(prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2654 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2655 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2656 | CTIO7_FLAGS_CONFORM_REQ); |
| 2657 | } |
| 2658 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2659 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2660 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2661 | int i; |
| 2662 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2663 | if (qlt_need_explicit_conf(prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2664 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2665 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2666 | "Skipping EXPLICIT_CONFORM and " |
| 2667 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2668 | "non GOOD status\n"); |
| 2669 | goto skip_explict_conf; |
| 2670 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2671 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2672 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2673 | CTIO7_FLAGS_CONFORM_REQ); |
| 2674 | } |
| 2675 | skip_explict_conf: |
| 2676 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2677 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2678 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2679 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2680 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2681 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2682 | ctio->u.status1.sense_length = |
| 2683 | cpu_to_le16(prm->sense_buffer_len); |
| 2684 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2685 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2686 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2687 | |
| 2688 | qlt_print_dif_err(prm); |
| 2689 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2690 | } else { |
| 2691 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2692 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2693 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2694 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2695 | ctio->u.status1.sense_length = 0; |
| 2696 | memset(ctio->u.status1.sense_data, 0, |
| 2697 | sizeof(ctio->u.status1.sense_data)); |
| 2698 | } |
| 2699 | |
| 2700 | /* Sense with len > 24, is it possible ??? */ |
| 2701 | } |
| 2702 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2703 | static inline int |
| 2704 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2705 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2706 | switch (se_cmd->prot_op) { |
| 2707 | case TARGET_PROT_DOUT_INSERT: |
| 2708 | case TARGET_PROT_DIN_STRIP: |
| 2709 | if (ql2xenablehba_err_chk >= 1) |
| 2710 | return 1; |
| 2711 | break; |
| 2712 | case TARGET_PROT_DOUT_PASS: |
| 2713 | case TARGET_PROT_DIN_PASS: |
| 2714 | if (ql2xenablehba_err_chk >= 2) |
| 2715 | return 1; |
| 2716 | break; |
| 2717 | case TARGET_PROT_DIN_INSERT: |
| 2718 | case TARGET_PROT_DOUT_STRIP: |
| 2719 | return 1; |
| 2720 | default: |
| 2721 | break; |
| 2722 | } |
| 2723 | return 0; |
| 2724 | } |
| 2725 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2726 | static inline int |
| 2727 | qla_tgt_ref_mask_check(struct se_cmd *se_cmd) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2728 | { |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2729 | switch (se_cmd->prot_op) { |
| 2730 | case TARGET_PROT_DIN_INSERT: |
| 2731 | case TARGET_PROT_DOUT_INSERT: |
| 2732 | case TARGET_PROT_DIN_STRIP: |
| 2733 | case TARGET_PROT_DOUT_STRIP: |
| 2734 | case TARGET_PROT_DIN_PASS: |
| 2735 | case TARGET_PROT_DOUT_PASS: |
| 2736 | return 1; |
| 2737 | default: |
| 2738 | return 0; |
| 2739 | } |
| 2740 | return 0; |
| 2741 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2742 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2743 | /* |
| 2744 | * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command |
| 2745 | */ |
| 2746 | static void |
| 2747 | qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx, |
| 2748 | uint16_t *pfw_prot_opts) |
| 2749 | { |
| 2750 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2751 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2752 | scsi_qla_host_t *vha = cmd->tgt->vha; |
| 2753 | struct qla_hw_data *ha = vha->hw; |
| 2754 | uint32_t t32 = 0; |
| 2755 | |
| 2756 | /* |
| 2757 | * wait till Mode Sense/Select cmd, modepage Ah, subpage 2 |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2758 | * have been immplemented by TCM, before AppTag is avail. |
| 2759 | * Look for modesense_handlers[] |
| 2760 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2761 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2762 | ctx->app_tag_mask[0] = 0x0; |
| 2763 | ctx->app_tag_mask[1] = 0x0; |
| 2764 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2765 | if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2766 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2767 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2768 | *pfw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2769 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2770 | *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2771 | } |
| 2772 | |
| 2773 | t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts); |
| 2774 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2775 | switch (se_cmd->prot_type) { |
| 2776 | case TARGET_DIF_TYPE0_PROT: |
| 2777 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2778 | * No check for ql2xenablehba_err_chk, as it |
| 2779 | * would be an I/O error if hba tag generation |
| 2780 | * is not done. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2781 | */ |
| 2782 | ctx->ref_tag = cpu_to_le32(lba); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2783 | /* enable ALL bytes of the ref tag */ |
| 2784 | ctx->ref_tag_mask[0] = 0xff; |
| 2785 | ctx->ref_tag_mask[1] = 0xff; |
| 2786 | ctx->ref_tag_mask[2] = 0xff; |
| 2787 | ctx->ref_tag_mask[3] = 0xff; |
| 2788 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2789 | case TARGET_DIF_TYPE1_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2790 | /* |
| 2791 | * For TYPE 1 protection: 16 bit GUARD tag, 32 bit |
| 2792 | * REF tag, and 16 bit app tag. |
| 2793 | */ |
| 2794 | ctx->ref_tag = cpu_to_le32(lba); |
| 2795 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2796 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2797 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2798 | break; |
| 2799 | } |
| 2800 | /* enable ALL bytes of the ref tag */ |
| 2801 | ctx->ref_tag_mask[0] = 0xff; |
| 2802 | ctx->ref_tag_mask[1] = 0xff; |
| 2803 | ctx->ref_tag_mask[2] = 0xff; |
| 2804 | ctx->ref_tag_mask[3] = 0xff; |
| 2805 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2806 | case TARGET_DIF_TYPE2_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2807 | /* |
| 2808 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF |
| 2809 | * tag has to match LBA in CDB + N |
| 2810 | */ |
| 2811 | ctx->ref_tag = cpu_to_le32(lba); |
| 2812 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2813 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2814 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2815 | break; |
| 2816 | } |
| 2817 | /* enable ALL bytes of the ref tag */ |
| 2818 | ctx->ref_tag_mask[0] = 0xff; |
| 2819 | ctx->ref_tag_mask[1] = 0xff; |
| 2820 | ctx->ref_tag_mask[2] = 0xff; |
| 2821 | ctx->ref_tag_mask[3] = 0xff; |
| 2822 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2823 | case TARGET_DIF_TYPE3_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2824 | /* For TYPE 3 protection: 16 bit GUARD only */ |
| 2825 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2826 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2827 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2828 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2829 | } |
| 2830 | } |
| 2831 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2832 | static inline int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2833 | 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] | 2834 | { |
| 2835 | uint32_t *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2836 | uint32_t transfer_length = 0; |
| 2837 | uint32_t data_bytes; |
| 2838 | uint32_t dif_bytes; |
| 2839 | uint8_t bundling = 1; |
| 2840 | uint8_t *clr_ptr; |
| 2841 | struct crc_context *crc_ctx_pkt = NULL; |
| 2842 | struct qla_hw_data *ha; |
| 2843 | struct ctio_crc2_to_fw *pkt; |
| 2844 | dma_addr_t crc_ctx_dma; |
| 2845 | uint16_t fw_prot_opts = 0; |
| 2846 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2847 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2848 | uint32_t h; |
| 2849 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2850 | struct qla_tc_param tc; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2851 | uint16_t t16; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2852 | scsi_qla_host_t *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2853 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2854 | ha = vha->hw; |
| 2855 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2856 | pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2857 | prm->pkt = pkt; |
| 2858 | memset(pkt, 0, sizeof(*pkt)); |
| 2859 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2860 | ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2861 | "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] | 2862 | cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2863 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 2864 | |
| 2865 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 2866 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 2867 | bundling = 0; |
| 2868 | |
| 2869 | /* Compute dif len and adjust data len to incude protection */ |
| 2870 | data_bytes = cmd->bufflen; |
| 2871 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 2872 | |
| 2873 | switch (se_cmd->prot_op) { |
| 2874 | case TARGET_PROT_DIN_INSERT: |
| 2875 | case TARGET_PROT_DOUT_STRIP: |
| 2876 | transfer_length = data_bytes; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2877 | if (cmd->prot_sg_cnt) |
| 2878 | data_bytes += dif_bytes; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2879 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2880 | case TARGET_PROT_DIN_STRIP: |
| 2881 | case TARGET_PROT_DOUT_INSERT: |
| 2882 | case TARGET_PROT_DIN_PASS: |
| 2883 | case TARGET_PROT_DOUT_PASS: |
| 2884 | transfer_length = data_bytes + dif_bytes; |
| 2885 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2886 | default: |
| 2887 | BUG(); |
| 2888 | break; |
| 2889 | } |
| 2890 | |
| 2891 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2892 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 2893 | /* HBA error checking enabled */ |
| 2894 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2895 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2896 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2897 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2898 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2899 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2900 | } |
| 2901 | |
| 2902 | switch (se_cmd->prot_op) { |
| 2903 | case TARGET_PROT_DIN_INSERT: |
| 2904 | case TARGET_PROT_DOUT_INSERT: |
| 2905 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 2906 | break; |
| 2907 | case TARGET_PROT_DIN_STRIP: |
| 2908 | case TARGET_PROT_DOUT_STRIP: |
| 2909 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 2910 | break; |
| 2911 | case TARGET_PROT_DIN_PASS: |
| 2912 | case TARGET_PROT_DOUT_PASS: |
| 2913 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2914 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 2915 | break; |
| 2916 | default:/* Normal Request */ |
| 2917 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2918 | break; |
| 2919 | } |
| 2920 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2921 | /* ---- PKT ---- */ |
| 2922 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 2923 | pkt->entry_type = CTIO_CRC2; |
| 2924 | pkt->entry_count = 1; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2925 | pkt->vp_index = cmd->vp_idx; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2926 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2927 | h = qlt_make_handle(qpair); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2928 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2929 | /* |
| 2930 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2931 | * know the initiator's LOOP ID, hence we can't find |
| 2932 | * the session and, so, the command. |
| 2933 | */ |
| 2934 | return -EAGAIN; |
| 2935 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2936 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2937 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2938 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2939 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2940 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2941 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2942 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2943 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2944 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2945 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2946 | |
| 2947 | /* silence compile warning */ |
| 2948 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2949 | pkt->ox_id = cpu_to_le16(t16); |
| 2950 | |
| 2951 | t16 = (atio->u.isp24.attr << 9); |
| 2952 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2953 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2954 | |
| 2955 | /* Set transfer direction */ |
| 2956 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2957 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2958 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2959 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2960 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2961 | pkt->dseg_count = prm->tot_dsds; |
| 2962 | /* Fibre channel byte count */ |
| 2963 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 2964 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2965 | /* ----- CRC context -------- */ |
| 2966 | |
| 2967 | /* Allocate CRC context from global pool */ |
| 2968 | crc_ctx_pkt = cmd->ctx = |
| 2969 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
| 2970 | |
| 2971 | if (!crc_ctx_pkt) |
| 2972 | goto crc_queuing_error; |
| 2973 | |
| 2974 | /* Zero out CTX area. */ |
| 2975 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 2976 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 2977 | |
| 2978 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 2979 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 2980 | |
| 2981 | /* Set handle */ |
| 2982 | crc_ctx_pkt->handle = pkt->handle; |
| 2983 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2984 | qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2985 | |
| 2986 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 2987 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 2988 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 2989 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2990 | if (!bundling) { |
| 2991 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 2992 | } else { |
| 2993 | /* |
| 2994 | * Configure Bundling if we need to fetch interlaving |
| 2995 | * protection PCI accesses |
| 2996 | */ |
| 2997 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 2998 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 2999 | crc_ctx_pkt->u.bundling.dseg_count = |
| 3000 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
| 3001 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 3002 | } |
| 3003 | |
| 3004 | /* Finish the common fields of CRC pkt */ |
| 3005 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 3006 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 3007 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3008 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3009 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3010 | memset((uint8_t *)&tc, 0 , sizeof(tc)); |
| 3011 | tc.vha = vha; |
| 3012 | tc.blk_sz = cmd->blk_sz; |
| 3013 | tc.bufflen = cmd->bufflen; |
| 3014 | tc.sg = cmd->sg; |
| 3015 | tc.prot_sg = cmd->prot_sg; |
| 3016 | tc.ctx = crc_ctx_pkt; |
| 3017 | tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3018 | |
| 3019 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3020 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3021 | |
| 3022 | if (!bundling && prm->prot_seg_cnt) { |
| 3023 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3024 | prm->tot_dsds, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3025 | goto crc_queuing_error; |
| 3026 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3027 | (prm->tot_dsds - prm->prot_seg_cnt), &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3028 | goto crc_queuing_error; |
| 3029 | |
| 3030 | if (bundling && prm->prot_seg_cnt) { |
| 3031 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3032 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3033 | |
| 3034 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 3035 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3036 | prm->prot_seg_cnt, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3037 | goto crc_queuing_error; |
| 3038 | } |
| 3039 | return QLA_SUCCESS; |
| 3040 | |
| 3041 | crc_queuing_error: |
| 3042 | /* Cleanup will be performed by the caller */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3043 | qpair->req->outstanding_cmds[h] = NULL; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3044 | |
| 3045 | return QLA_FUNCTION_FAILED; |
| 3046 | } |
| 3047 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3048 | /* |
| 3049 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 3050 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 3051 | */ |
| 3052 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 3053 | uint8_t scsi_status) |
| 3054 | { |
| 3055 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3056 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3057 | struct ctio7_to_24xx *pkt; |
| 3058 | struct qla_tgt_prm prm; |
| 3059 | uint32_t full_req_cnt = 0; |
| 3060 | unsigned long flags = 0; |
| 3061 | int res; |
| 3062 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3063 | if (cmd->sess && cmd->sess->deleted) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3064 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3065 | if (cmd->sess->logout_completed) |
| 3066 | /* no need to terminate. FW already freed exchange. */ |
| 3067 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 3068 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3069 | qlt_send_term_exchange(qpair, cmd, &cmd->atio, 0, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3070 | return 0; |
| 3071 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3072 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3073 | ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3074 | "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] | 3075 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 3076 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3077 | &cmd->se_cmd, qpair->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3078 | |
| 3079 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 3080 | &full_req_cnt); |
| 3081 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3082 | return res; |
| 3083 | } |
| 3084 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3085 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3086 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3087 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3088 | qpair->tgt_counters.core_qla_snd_status++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3089 | else |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3090 | qpair->tgt_counters.core_qla_que_buf++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3091 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3092 | if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3093 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3094 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3095 | * previous life, just abort the processing. |
| 3096 | */ |
| 3097 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3098 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3099 | ql_dbg_qp(ql_dbg_async, qpair, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3100 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3101 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3102 | cmd->reset_count, qpair->chip_reset); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3103 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3104 | return 0; |
| 3105 | } |
| 3106 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3107 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3108 | res = qlt_check_reserve_free_req(qpair, full_req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3109 | if (unlikely(res)) |
| 3110 | goto out_unmap_unlock; |
| 3111 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3112 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3113 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3114 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3115 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3116 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3117 | qpair->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3118 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3119 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3120 | |
| 3121 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 3122 | |
| 3123 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 3124 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3125 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3126 | CTIO7_FLAGS_STATUS_MODE_0); |
| 3127 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3128 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3129 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3130 | |
| 3131 | if (prm.add_status_pkt == 0) { |
| 3132 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 3133 | pkt->u.status0.scsi_status = |
| 3134 | cpu_to_le16(prm.rq_result); |
| 3135 | pkt->u.status0.residual = |
| 3136 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3137 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3138 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3139 | if (qlt_need_explicit_conf(cmd, 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3140 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3141 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3142 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 3143 | CTIO7_FLAGS_CONFORM_REQ); |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | } else { |
| 3148 | /* |
| 3149 | * We have already made sure that there is sufficient |
| 3150 | * amount of request entries to not drop HW lock in |
| 3151 | * req_pkt(). |
| 3152 | */ |
| 3153 | struct ctio7_to_24xx *ctio = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3154 | (struct ctio7_to_24xx *)qlt_get_req_pkt( |
| 3155 | qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3156 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3157 | ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e, |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3158 | "Building additional status packet 0x%p.\n", |
| 3159 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3160 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3161 | /* |
| 3162 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 3163 | * ctio7_to_24xx |
| 3164 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3165 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3166 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3167 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3168 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3169 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3170 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3171 | CTIO7_FLAGS_DATA_IN); |
| 3172 | |
| 3173 | /* Real finish is ctio_m1's finish */ |
| 3174 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3175 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3176 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3177 | |
| 3178 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3179 | * all neccessary fields that's part of CTIO7. |
| 3180 | * There should be no residual of CTIO-CRC2 data. |
| 3181 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3182 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3183 | &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3184 | } |
| 3185 | } else |
| 3186 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3187 | |
| 3188 | |
| 3189 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3190 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3191 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3192 | /* Memory Barrier */ |
| 3193 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3194 | if (qpair->reqq_start_iocbs) |
| 3195 | qpair->reqq_start_iocbs(qpair); |
| 3196 | else |
| 3197 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3198 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3199 | |
| 3200 | return 0; |
| 3201 | |
| 3202 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3203 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3204 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3205 | |
| 3206 | return res; |
| 3207 | } |
| 3208 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3209 | |
| 3210 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3211 | { |
| 3212 | struct ctio7_to_24xx *pkt; |
| 3213 | struct scsi_qla_host *vha = cmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3214 | struct qla_tgt *tgt = cmd->tgt; |
| 3215 | struct qla_tgt_prm prm; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3216 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3217 | int res = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3218 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3219 | |
| 3220 | memset(&prm, 0, sizeof(prm)); |
| 3221 | prm.cmd = cmd; |
| 3222 | prm.tgt = tgt; |
| 3223 | prm.sg = NULL; |
| 3224 | prm.req_cnt = 1; |
| 3225 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3226 | /* Calculate number of entries and segments required */ |
| 3227 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3228 | return -EAGAIN; |
| 3229 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3230 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3231 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3232 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3233 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3234 | * previous life, just abort the processing. |
| 3235 | */ |
| 3236 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
| 3237 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3238 | ql_dbg_qp(ql_dbg_async, qpair, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3239 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3240 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3241 | cmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3242 | return 0; |
| 3243 | } |
| 3244 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3245 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3246 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3247 | res = qlt_check_reserve_free_req(qpair, prm.req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3248 | if (res != 0) |
| 3249 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3250 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3251 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3252 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3253 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3254 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3255 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3256 | qpair->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3257 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3258 | } |
| 3259 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3260 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3261 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3262 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3263 | |
| 3264 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3265 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3266 | |
| 3267 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3268 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3269 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3270 | /* Memory Barrier */ |
| 3271 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3272 | if (qpair->reqq_start_iocbs) |
| 3273 | qpair->reqq_start_iocbs(qpair); |
| 3274 | else |
| 3275 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3276 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3277 | |
| 3278 | return res; |
| 3279 | |
| 3280 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3281 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3282 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3283 | |
| 3284 | return res; |
| 3285 | } |
| 3286 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3287 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3288 | |
| 3289 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3290 | * it is assumed either hardware_lock or qpair lock is held. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3291 | */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3292 | static void |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3293 | 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] | 3294 | struct ctio_crc_from_fw *sts) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3295 | { |
| 3296 | uint8_t *ap = &sts->actual_dif[0]; |
| 3297 | uint8_t *ep = &sts->expected_dif[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3298 | uint64_t lba = cmd->se_cmd.t_task_lba; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3299 | uint8_t scsi_status, sense_key, asc, ascq; |
| 3300 | unsigned long flags; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3301 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3302 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3303 | cmd->trc_flags |= TRC_DIF_ERR; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3304 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3305 | cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3306 | cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3307 | cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3308 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3309 | cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3310 | cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3311 | cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
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 | ql_dbg(ql_dbg_tgt_dif, vha, 0xf075, |
| 3314 | "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3315 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3316 | scsi_status = sense_key = asc = ascq = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3317 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3318 | /* check appl tag */ |
| 3319 | if (cmd->e_app_tag != cmd->a_app_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3320 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d, |
| 3321 | "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]", |
| 3322 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3323 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3324 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3325 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3326 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3327 | cmd->dif_err_code = DIF_ERR_APP; |
| 3328 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3329 | sense_key = ABORTED_COMMAND; |
| 3330 | asc = 0x10; |
| 3331 | ascq = 0x2; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | /* check ref tag */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3335 | if (cmd->e_ref_tag != cmd->a_ref_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3336 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e, |
| 3337 | "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] ", |
| 3338 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3339 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3340 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3341 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3342 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3343 | cmd->dif_err_code = DIF_ERR_REF; |
| 3344 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3345 | sense_key = ABORTED_COMMAND; |
| 3346 | asc = 0x10; |
| 3347 | ascq = 0x3; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3348 | goto out; |
| 3349 | } |
| 3350 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3351 | /* check guard */ |
| 3352 | if (cmd->e_guard != cmd->a_guard) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3353 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe012, |
| 3354 | "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]", |
| 3355 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3356 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3357 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3358 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
| 3359 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3360 | cmd->dif_err_code = DIF_ERR_GRD; |
| 3361 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3362 | sense_key = ABORTED_COMMAND; |
| 3363 | asc = 0x10; |
| 3364 | ascq = 0x1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3365 | } |
| 3366 | out: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3367 | switch (cmd->state) { |
| 3368 | case QLA_TGT_STATE_NEED_DATA: |
| 3369 | /* handle_data will load DIF error code */ |
| 3370 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3371 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
| 3372 | break; |
| 3373 | default: |
| 3374 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3375 | if (cmd->aborted) { |
| 3376 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3377 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3378 | break; |
| 3379 | } |
| 3380 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3381 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3382 | qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc, |
| 3383 | ascq); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3384 | /* assume scsi status gets out on the wire. |
| 3385 | * Will not wait for completion. |
| 3386 | */ |
| 3387 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3388 | break; |
| 3389 | } |
| 3390 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3391 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3392 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3393 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3394 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3395 | struct imm_ntfy_from_isp *ntfy) |
| 3396 | { |
| 3397 | struct nack_to_isp *nack; |
| 3398 | struct qla_hw_data *ha = vha->hw; |
| 3399 | request_t *pkt; |
| 3400 | int ret = 0; |
| 3401 | |
| 3402 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3403 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3404 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3405 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3406 | if (pkt == NULL) { |
| 3407 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3408 | "qla_target(%d): %s failed: unable to allocate " |
| 3409 | "request packet\n", vha->vp_idx, __func__); |
| 3410 | return -ENOMEM; |
| 3411 | } |
| 3412 | |
| 3413 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3414 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3415 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3416 | |
| 3417 | nack = (struct nack_to_isp *)pkt; |
| 3418 | nack->ox_id = ntfy->ox_id; |
| 3419 | |
| 3420 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3421 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3422 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3423 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3424 | } |
| 3425 | |
| 3426 | /* terminate */ |
| 3427 | nack->u.isp24.flags |= |
| 3428 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3429 | |
| 3430 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3431 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3432 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3433 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3434 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3435 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3436 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3437 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3438 | |
| 3439 | qla2x00_start_iocbs(vha, vha->req); |
| 3440 | return ret; |
| 3441 | } |
| 3442 | |
| 3443 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3444 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3445 | { |
| 3446 | unsigned long flags = 0; |
| 3447 | int rc; |
| 3448 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3449 | if (ha_locked) { |
| 3450 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3451 | |
| 3452 | #if 0 /* Todo */ |
| 3453 | if (rc == -ENOMEM) |
| 3454 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
Bart Van Assche | 91f42b3 | 2016-03-30 15:25:21 -0700 | [diff] [blame] | 3455 | #else |
| 3456 | if (rc) { |
| 3457 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3458 | #endif |
| 3459 | goto done; |
| 3460 | } |
| 3461 | |
| 3462 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3463 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3464 | |
| 3465 | #if 0 /* Todo */ |
| 3466 | if (rc == -ENOMEM) |
| 3467 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
| 3468 | #endif |
| 3469 | |
| 3470 | done: |
| 3471 | if (!ha_locked) |
| 3472 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3473 | } |
| 3474 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3475 | /* |
| 3476 | * If hardware_lock held on entry, might drop it, then reaquire |
| 3477 | * This function sends the appropriate CTIO to ISP 2xxx or 24xx |
| 3478 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3479 | static int __qlt_send_term_exchange(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3480 | struct qla_tgt_cmd *cmd, |
| 3481 | struct atio_from_isp *atio) |
| 3482 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3483 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3484 | struct ctio7_to_24xx *ctio24; |
| 3485 | struct qla_hw_data *ha = vha->hw; |
| 3486 | request_t *pkt; |
| 3487 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3488 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3489 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3490 | 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] | 3491 | |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 3492 | if (cmd) |
| 3493 | vha = cmd->vha; |
| 3494 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3495 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3496 | if (pkt == NULL) { |
| 3497 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3498 | "qla_target(%d): %s failed: unable to allocate " |
| 3499 | "request packet\n", vha->vp_idx, __func__); |
| 3500 | return -ENOMEM; |
| 3501 | } |
| 3502 | |
| 3503 | if (cmd != NULL) { |
| 3504 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3505 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3506 | "qla_target(%d): Terminating cmd %p with " |
| 3507 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3508 | cmd->state); |
| 3509 | } else |
| 3510 | ret = 1; |
| 3511 | } |
| 3512 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3513 | qpair->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3514 | pkt->entry_count = 1; |
| 3515 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3516 | |
| 3517 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3518 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3519 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3520 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3521 | ctio24->vp_index = vha->vp_idx; |
| 3522 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3523 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3524 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3525 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3526 | temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 | |
| 3527 | CTIO7_FLAGS_TERMINATE; |
| 3528 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3529 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3530 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3531 | |
| 3532 | /* Most likely, it isn't needed */ |
| 3533 | ctio24->u.status1.residual = get_unaligned((uint32_t *) |
| 3534 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3535 | atio->u.isp24.fcp_cmnd.add_cdb_len]); |
| 3536 | if (ctio24->u.status1.residual != 0) |
| 3537 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 3538 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3539 | /* Memory Barrier */ |
| 3540 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3541 | if (qpair->reqq_start_iocbs) |
| 3542 | qpair->reqq_start_iocbs(qpair); |
| 3543 | else |
| 3544 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3545 | return ret; |
| 3546 | } |
| 3547 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3548 | static void qlt_send_term_exchange(struct qla_qpair *qpair, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3549 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3550 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3551 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3552 | struct scsi_qla_host *vha; |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3553 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3554 | int rc; |
| 3555 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3556 | /* why use different vha? NPIV */ |
| 3557 | if (cmd) |
| 3558 | vha = cmd->vha; |
| 3559 | else |
| 3560 | vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3561 | |
| 3562 | if (ha_locked) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3563 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3564 | if (rc == -ENOMEM) |
| 3565 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3566 | goto done; |
| 3567 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3568 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 3569 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3570 | if (rc == -ENOMEM) |
| 3571 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3572 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3573 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3574 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3575 | if (cmd->sg_mapped) |
| 3576 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3577 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3578 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3579 | |
| 3580 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3581 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3582 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3583 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3584 | } |
| 3585 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3586 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3587 | { |
| 3588 | struct list_head free_list; |
| 3589 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3590 | |
| 3591 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3592 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3593 | |
| 3594 | cmd = tcmd = NULL; |
| 3595 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3596 | INIT_LIST_HEAD(&free_list); |
| 3597 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3598 | |
| 3599 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3600 | list_del(&cmd->cmd_list); |
| 3601 | /* This cmd was never sent to TCM. There is no need |
| 3602 | * to schedule free or call free_cmd |
| 3603 | */ |
| 3604 | qlt_free_cmd(cmd); |
| 3605 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3606 | } |
| 3607 | } |
| 3608 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3609 | } |
| 3610 | |
| 3611 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3612 | { |
| 3613 | uint32_t total_leaked; |
| 3614 | |
| 3615 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3616 | |
| 3617 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3618 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3619 | |
| 3620 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3621 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3622 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3623 | |
| 3624 | if (IS_P3P_TYPE(vha->hw)) |
| 3625 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3626 | else |
| 3627 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3628 | qla2xxx_wake_dpc(vha); |
| 3629 | } |
| 3630 | |
| 3631 | } |
| 3632 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3633 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3634 | { |
| 3635 | struct qla_tgt *tgt = cmd->tgt; |
| 3636 | struct scsi_qla_host *vha = tgt->vha; |
| 3637 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3638 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3639 | |
| 3640 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3641 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3642 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3643 | se_cmd->tag); |
| 3644 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3645 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3646 | if (cmd->aborted) { |
| 3647 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3648 | /* |
| 3649 | * It's normal to see 2 calls in this path: |
| 3650 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3651 | * 2) TCM TMR - drain_state_list |
| 3652 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3653 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, |
| 3654 | "multiple abort. %p transport_state %x, t_state %x, " |
| 3655 | "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, |
| 3656 | cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3657 | return EIO; |
| 3658 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3659 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3660 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3661 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3662 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3663 | qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3664 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3665 | } |
| 3666 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3667 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3668 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3669 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3670 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3671 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3672 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3673 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3674 | __func__, &cmd->se_cmd, |
| 3675 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3676 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3677 | BUG_ON(cmd->cmd_in_wq); |
| 3678 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3679 | if (cmd->sg_mapped) |
| 3680 | qlt_unmap_sg(cmd->vha, cmd); |
| 3681 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3682 | if (!cmd->q_full) |
| 3683 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3684 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3685 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3686 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3687 | if (unlikely(cmd->free_sg)) |
| 3688 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3689 | |
| 3690 | if (!sess || !sess->se_sess) { |
| 3691 | WARN_ON(1); |
| 3692 | return; |
| 3693 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3694 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3695 | 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] | 3696 | } |
| 3697 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3698 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3699 | /* |
| 3700 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3701 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3702 | static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3703 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3704 | { |
| 3705 | int term = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3706 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3707 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3708 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3709 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3710 | "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " |
| 3711 | "se_cmd=%p tag[%x] op %#x/%s", |
| 3712 | cmd->lba, cmd->lba, |
| 3713 | cmd->num_blks, &cmd->se_cmd, |
| 3714 | cmd->atio.u.isp24.exchange_addr, |
| 3715 | cmd->se_cmd.prot_op, |
| 3716 | prot_op_str(cmd->se_cmd.prot_op)); |
| 3717 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3718 | if (ctio != NULL) { |
| 3719 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
| 3720 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3721 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3722 | } else |
| 3723 | term = 1; |
| 3724 | |
| 3725 | if (term) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3726 | qlt_term_ctio_exchange(qpair, ctio, cmd, status); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3727 | |
| 3728 | return term; |
| 3729 | } |
| 3730 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3731 | |
| 3732 | /* ha->hardware_lock supposed to be held on entry */ |
| 3733 | 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] | 3734 | struct rsp_que *rsp, uint32_t handle, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3735 | { |
| 3736 | struct qla_tgt_cmd *cmd = NULL; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3737 | struct req_que *req; |
| 3738 | int qid = GET_QID(handle); |
| 3739 | uint32_t h = handle & ~QLA_TGT_HANDLE_MASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3740 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3741 | if (unlikely(h == QLA_TGT_SKIP_HANDLE)) |
| 3742 | return NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3743 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3744 | if (qid == rsp->req->id) { |
| 3745 | req = rsp->req; |
| 3746 | } else if (vha->hw->req_q_map[qid]) { |
| 3747 | ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a, |
| 3748 | "qla_target(%d): CTIO completion with different QID %d handle %x\n", |
| 3749 | vha->vp_idx, rsp->id, handle); |
| 3750 | req = vha->hw->req_q_map[qid]; |
| 3751 | } else { |
| 3752 | return NULL; |
| 3753 | } |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3754 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3755 | h &= QLA_CMD_HANDLE_MASK; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3756 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3757 | if (h != QLA_TGT_NULL_HANDLE) { |
Dan Carpenter | fb2028a | 2017-07-10 11:47:40 +0300 | [diff] [blame] | 3758 | if (unlikely(h >= req->num_outstanding_cmds)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3759 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3760 | "qla_target(%d): Wrong handle %x received\n", |
| 3761 | vha->vp_idx, handle); |
| 3762 | return NULL; |
| 3763 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3764 | |
| 3765 | cmd = (struct qla_tgt_cmd *)req->outstanding_cmds[h]; |
| 3766 | if (unlikely(cmd == NULL)) { |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3767 | ql_dbg(ql_dbg_async, vha, 0xe053, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3768 | "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n", |
| 3769 | vha->vp_idx, handle, req->id, rsp->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3770 | return NULL; |
| 3771 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3772 | req->outstanding_cmds[h] = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3773 | } else if (ctio != NULL) { |
| 3774 | /* We can't get loop ID from CTIO7 */ |
| 3775 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3776 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3777 | "support NULL handles\n", vha->vp_idx); |
| 3778 | return NULL; |
| 3779 | } |
| 3780 | |
| 3781 | return cmd; |
| 3782 | } |
| 3783 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3784 | /* hardware_lock should be held by caller. */ |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3785 | void |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3786 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
| 3787 | { |
| 3788 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3789 | |
| 3790 | if (cmd->sg_mapped) |
| 3791 | qlt_unmap_sg(vha, cmd); |
| 3792 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3793 | /* TODO: fix debug message type and ids. */ |
| 3794 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
| 3795 | ql_dbg(ql_dbg_io, vha, 0xff00, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3796 | "HOST-ABORT: state=PROCESSED.\n"); |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3797 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3798 | cmd->write_data_transferred = 0; |
| 3799 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3800 | |
| 3801 | ql_dbg(ql_dbg_io, vha, 0xff01, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3802 | "HOST-ABORT: state=DATA_IN.\n"); |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3803 | |
| 3804 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3805 | return; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3806 | } else { |
| 3807 | ql_dbg(ql_dbg_io, vha, 0xff03, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3808 | "HOST-ABORT: state=BAD(%d).\n", |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3809 | cmd->state); |
| 3810 | dump_stack(); |
| 3811 | } |
| 3812 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3813 | cmd->trc_flags |= TRC_FLUSH; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3814 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3815 | } |
| 3816 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3817 | /* |
| 3818 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3819 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3820 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, |
| 3821 | struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3822 | { |
| 3823 | struct qla_hw_data *ha = vha->hw; |
| 3824 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3825 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3826 | struct qla_qpair *qpair = rsp->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3827 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3828 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3829 | /* That could happen only in case of an error/reset/abort */ |
| 3830 | if (status != CTIO_SUCCESS) { |
| 3831 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3832 | "Intermediate CTIO received" |
| 3833 | " (status %x)\n", status); |
| 3834 | } |
| 3835 | return; |
| 3836 | } |
| 3837 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3838 | cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3839 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3840 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3841 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3842 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3843 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3844 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3845 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3846 | |
| 3847 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3848 | switch (status & 0xFFFF) { |
| 3849 | case CTIO_LIP_RESET: |
| 3850 | case CTIO_TARGET_RESET: |
| 3851 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3852 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3853 | case CTIO_TIMEOUT: |
| 3854 | case CTIO_INVALID_RX_ID: |
| 3855 | /* They are OK */ |
| 3856 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3857 | "qla_target(%d): CTIO with " |
| 3858 | "status %#x received, state %x, se_cmd %p, " |
| 3859 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3860 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3861 | status, cmd->state, se_cmd); |
| 3862 | break; |
| 3863 | |
| 3864 | case CTIO_PORT_LOGGED_OUT: |
| 3865 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3866 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3867 | int logged_out = |
| 3868 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3869 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3870 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3871 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3872 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3873 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3874 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3875 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3876 | if (logged_out && cmd->sess) { |
| 3877 | /* |
| 3878 | * Session is already logged out, but we need |
| 3879 | * to notify initiator, who's not aware of this |
| 3880 | */ |
| 3881 | cmd->sess->logout_on_delete = 0; |
| 3882 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3883 | ql_dbg(ql_dbg_disc, vha, 0x20f8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3884 | "%s %d %8phC post del sess\n", |
| 3885 | __func__, __LINE__, cmd->sess->port_name); |
| 3886 | |
| 3887 | qlt_schedule_sess_for_deletion_lock(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3888 | } |
| 3889 | break; |
| 3890 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3891 | case CTIO_DIF_ERROR: { |
| 3892 | struct ctio_crc_from_fw *crc = |
| 3893 | (struct ctio_crc_from_fw *)ctio; |
| 3894 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3895 | "qla_target(%d): CTIO with DIF_ERROR status %x " |
| 3896 | "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " |
| 3897 | "expect_dif[0x%llx]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3898 | vha->vp_idx, status, cmd->state, se_cmd, |
| 3899 | *((u64 *)&crc->actual_dif[0]), |
| 3900 | *((u64 *)&crc->expected_dif[0])); |
| 3901 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3902 | qlt_handle_dif_error(qpair, cmd, ctio); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3903 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3904 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3905 | default: |
| 3906 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3907 | "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] | 3908 | vha->vp_idx, status, cmd->state, se_cmd); |
| 3909 | break; |
| 3910 | } |
| 3911 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3912 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3913 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3914 | * cmd is already aborted/terminated, we don't |
| 3915 | * need to terminate again. The exchange is already |
| 3916 | * cleaned up/freed at FW level. Just cleanup at driver |
| 3917 | * level. |
| 3918 | */ |
| 3919 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3920 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3921 | cmd->trc_flags |= TRC_CTIO_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3922 | if (qlt_term_ctio_exchange(qpair, ctio, cmd, status)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3923 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3924 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3928 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3929 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3930 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3931 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3932 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3933 | cmd->write_data_transferred = 1; |
| 3934 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3935 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3936 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3937 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3938 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3939 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3940 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3941 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3942 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3943 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 3944 | "qla_target(%d): A command in state (%d) should " |
| 3945 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 3946 | } |
| 3947 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3948 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3949 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3950 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 3951 | dump_stack(); |
| 3952 | } |
| 3953 | |
| 3954 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3955 | } |
| 3956 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3957 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 3958 | uint8_t task_codes) |
| 3959 | { |
| 3960 | int fcp_task_attr; |
| 3961 | |
| 3962 | switch (task_codes) { |
| 3963 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3964 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3965 | break; |
| 3966 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3967 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3968 | break; |
| 3969 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3970 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3971 | break; |
| 3972 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3973 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3974 | break; |
| 3975 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3976 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3977 | break; |
| 3978 | default: |
| 3979 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 3980 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 3981 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3982 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3983 | break; |
| 3984 | } |
| 3985 | |
| 3986 | return fcp_task_attr; |
| 3987 | } |
| 3988 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3989 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3990 | uint8_t *); |
| 3991 | /* |
| 3992 | * Process context for I/O path into tcm_qla2xxx code |
| 3993 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3994 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3995 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3996 | scsi_qla_host_t *vha = cmd->vha; |
| 3997 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3998 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3999 | struct atio_from_isp *atio = &cmd->atio; |
| 4000 | unsigned char *cdb; |
| 4001 | unsigned long flags; |
| 4002 | uint32_t data_length; |
| 4003 | int ret, fcp_task_attr, data_dir, bidi = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4004 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4005 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4006 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4007 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4008 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4009 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4010 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 4011 | "cmd with tag %u is aborted\n", |
| 4012 | cmd->atio.u.isp24.exchange_addr); |
| 4013 | goto out_term; |
| 4014 | } |
| 4015 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4016 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4017 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4018 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4019 | |
| 4020 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 4021 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 4022 | bidi = 1; |
| 4023 | data_dir = DMA_TO_DEVICE; |
| 4024 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 4025 | data_dir = DMA_FROM_DEVICE; |
| 4026 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 4027 | data_dir = DMA_TO_DEVICE; |
| 4028 | else |
| 4029 | data_dir = DMA_NONE; |
| 4030 | |
| 4031 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 4032 | atio->u.isp24.fcp_cmnd.task_attr); |
| 4033 | data_length = be32_to_cpu(get_unaligned((uint32_t *) |
| 4034 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 4035 | atio->u.isp24.fcp_cmnd.add_cdb_len])); |
| 4036 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4037 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 4038 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4039 | if (ret != 0) |
| 4040 | goto out_term; |
| 4041 | /* |
| 4042 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( |
| 4043 | */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4044 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4045 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4046 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4047 | return; |
| 4048 | |
| 4049 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4050 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4051 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 4052 | * cmd has not sent to target yet, so pass NULL as the second |
| 4053 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4054 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4055 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4056 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4057 | qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4058 | |
| 4059 | qlt_decr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4060 | 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] | 4061 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4062 | |
| 4063 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4064 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4065 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4066 | } |
| 4067 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4068 | static void qlt_do_work(struct work_struct *work) |
| 4069 | { |
| 4070 | 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] | 4071 | scsi_qla_host_t *vha = cmd->vha; |
| 4072 | unsigned long flags; |
| 4073 | |
| 4074 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4075 | list_del(&cmd->cmd_list); |
| 4076 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4077 | |
| 4078 | __qlt_do_work(cmd); |
| 4079 | } |
| 4080 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 4081 | void qlt_clr_qp_table(struct scsi_qla_host *vha) |
| 4082 | { |
| 4083 | unsigned long flags; |
| 4084 | struct qla_hw_data *ha = vha->hw; |
| 4085 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4086 | void *node; |
| 4087 | u64 key = 0; |
| 4088 | |
| 4089 | ql_log(ql_log_info, vha, 0x706c, |
| 4090 | "User update Number of Active Qpairs %d\n", |
| 4091 | ha->tgt.num_act_qpairs); |
| 4092 | |
| 4093 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 4094 | |
| 4095 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 4096 | btree_remove64(&tgt->lun_qpair_map, key); |
| 4097 | |
| 4098 | ha->base_qpair->lun_cnt = 0; |
| 4099 | for (key = 0; key < ha->max_qpairs; key++) |
| 4100 | if (ha->queue_pair_map[key]) |
| 4101 | ha->queue_pair_map[key]->lun_cnt = 0; |
| 4102 | |
| 4103 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 4104 | } |
| 4105 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4106 | static void qlt_assign_qpair(struct scsi_qla_host *vha, |
| 4107 | struct qla_tgt_cmd *cmd) |
| 4108 | { |
| 4109 | struct qla_qpair *qpair, *qp; |
| 4110 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4111 | struct qla_qpair_hint *h; |
| 4112 | |
| 4113 | if (vha->flags.qpairs_available) { |
| 4114 | h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun); |
| 4115 | if (unlikely(!h)) { |
| 4116 | /* spread lun to qpair ratio evently */ |
| 4117 | int lcnt = 0, rc; |
| 4118 | struct scsi_qla_host *base_vha = |
| 4119 | pci_get_drvdata(vha->hw->pdev); |
| 4120 | |
| 4121 | qpair = vha->hw->base_qpair; |
| 4122 | if (qpair->lun_cnt == 0) { |
| 4123 | qpair->lun_cnt++; |
| 4124 | h = qla_qpair_to_hint(tgt, qpair); |
| 4125 | BUG_ON(!h); |
| 4126 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4127 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4128 | if (rc) { |
| 4129 | qpair->lun_cnt--; |
| 4130 | ql_log(ql_log_info, vha, 0xd037, |
| 4131 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4132 | cmd->unpacked_lun); |
| 4133 | } |
| 4134 | goto out; |
| 4135 | } else { |
| 4136 | lcnt = qpair->lun_cnt; |
| 4137 | } |
| 4138 | |
| 4139 | h = NULL; |
| 4140 | list_for_each_entry(qp, &base_vha->qp_list, |
| 4141 | qp_list_elem) { |
| 4142 | if (qp->lun_cnt == 0) { |
| 4143 | qp->lun_cnt++; |
| 4144 | h = qla_qpair_to_hint(tgt, qp); |
| 4145 | BUG_ON(!h); |
| 4146 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4147 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4148 | if (rc) { |
| 4149 | qp->lun_cnt--; |
| 4150 | ql_log(ql_log_info, vha, 0xd038, |
| 4151 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4152 | cmd->unpacked_lun); |
| 4153 | } |
| 4154 | qpair = qp; |
| 4155 | goto out; |
| 4156 | } else { |
| 4157 | if (qp->lun_cnt < lcnt) { |
| 4158 | lcnt = qp->lun_cnt; |
| 4159 | qpair = qp; |
| 4160 | continue; |
| 4161 | } |
| 4162 | } |
| 4163 | } |
| 4164 | BUG_ON(!qpair); |
| 4165 | qpair->lun_cnt++; |
| 4166 | h = qla_qpair_to_hint(tgt, qpair); |
| 4167 | BUG_ON(!h); |
| 4168 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4169 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4170 | if (rc) { |
| 4171 | qpair->lun_cnt--; |
| 4172 | ql_log(ql_log_info, vha, 0xd039, |
| 4173 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4174 | cmd->unpacked_lun); |
| 4175 | } |
| 4176 | } |
| 4177 | } else { |
| 4178 | h = &tgt->qphints[0]; |
| 4179 | } |
| 4180 | out: |
| 4181 | cmd->qpair = h->qpair; |
| 4182 | cmd->se_cmd.cpuid = h->cpuid; |
| 4183 | } |
| 4184 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4185 | 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] | 4186 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4187 | struct atio_from_isp *atio) |
| 4188 | { |
| 4189 | struct se_session *se_sess = sess->se_sess; |
| 4190 | struct qla_tgt_cmd *cmd; |
| 4191 | int tag; |
| 4192 | |
| 4193 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 4194 | if (tag < 0) |
| 4195 | return NULL; |
| 4196 | |
| 4197 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4198 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 4199 | cmd->cmd_type = TYPE_TGT_CMD; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4200 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4201 | cmd->state = QLA_TGT_STATE_NEW; |
| 4202 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4203 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4204 | cmd->vha = vha; |
| 4205 | cmd->se_cmd.map_tag = tag; |
| 4206 | cmd->sess = sess; |
| 4207 | cmd->loop_id = sess->loop_id; |
| 4208 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4209 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4210 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4211 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4212 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4213 | cmd->unpacked_lun = scsilun_to_int( |
| 4214 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 4215 | qlt_assign_qpair(vha, cmd); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4216 | cmd->reset_count = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 4217 | cmd->vp_idx = vha->vp_idx; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4218 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4219 | return cmd; |
| 4220 | } |
| 4221 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4222 | static void qlt_create_sess_from_atio(struct work_struct *work) |
| 4223 | { |
| 4224 | struct qla_tgt_sess_op *op = container_of(work, |
| 4225 | struct qla_tgt_sess_op, work); |
| 4226 | scsi_qla_host_t *vha = op->vha; |
| 4227 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4228 | struct fc_port *sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4229 | struct qla_tgt_cmd *cmd; |
| 4230 | unsigned long flags; |
| 4231 | uint8_t *s_id = op->atio.u.isp24.fcp_hdr.s_id; |
| 4232 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4233 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4234 | list_del(&op->cmd_list); |
| 4235 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 4236 | |
| 4237 | if (op->aborted) { |
| 4238 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf083, |
| 4239 | "sess_op with tag %u is aborted\n", |
| 4240 | op->atio.u.isp24.exchange_addr); |
| 4241 | goto out_term; |
| 4242 | } |
| 4243 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4244 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf022, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4245 | "qla_target(%d): Unable to find wwn login" |
| 4246 | " (s_id %x:%x:%x), trying to create it manually\n", |
| 4247 | vha->vp_idx, s_id[0], s_id[1], s_id[2]); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4248 | |
| 4249 | if (op->atio.u.raw.entry_count > 1) { |
| 4250 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf023, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4251 | "Dropping multy entry atio %p\n", &op->atio); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4252 | goto out_term; |
| 4253 | } |
| 4254 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4255 | sess = qlt_make_local_sess(vha, s_id); |
| 4256 | /* sess has an extra creation ref. */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4257 | |
| 4258 | if (!sess) |
| 4259 | goto out_term; |
| 4260 | /* |
| 4261 | * Now obtain a pre-allocated session tag using the original op->atio |
| 4262 | * packet header, and dispatch into __qlt_do_work() using the existing |
| 4263 | * process context. |
| 4264 | */ |
| 4265 | cmd = qlt_get_tag(vha, sess, &op->atio); |
| 4266 | if (!cmd) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4267 | struct qla_qpair *qpair = ha->base_qpair; |
| 4268 | |
| 4269 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4270 | qlt_send_busy(qpair, &op->atio, SAM_STAT_BUSY); |
| 4271 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 4272 | |
| 4273 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4274 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4275 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4276 | kfree(op); |
| 4277 | return; |
| 4278 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4279 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4280 | /* |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 4281 | * __qlt_do_work() will call qlt_put_sess() to release |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4282 | * the extra reference taken above by qlt_make_local_sess() |
| 4283 | */ |
| 4284 | __qlt_do_work(cmd); |
| 4285 | kfree(op); |
| 4286 | return; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4287 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4288 | qlt_send_term_exchange(vha->hw->base_qpair, NULL, &op->atio, 0, 0); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4289 | kfree(op); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4292 | /* ha->hardware_lock supposed to be held on entry */ |
| 4293 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4294 | struct atio_from_isp *atio) |
| 4295 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4296 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4297 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4298 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4299 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4300 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4301 | |
| 4302 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4303 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4304 | "New command while device %p is shutting down\n", tgt); |
| 4305 | return -EFAULT; |
| 4306 | } |
| 4307 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4308 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
| 4309 | if (unlikely(!sess)) { |
| 4310 | struct qla_tgt_sess_op *op = kzalloc(sizeof(struct qla_tgt_sess_op), |
| 4311 | GFP_ATOMIC); |
| 4312 | if (!op) |
| 4313 | return -ENOMEM; |
| 4314 | |
| 4315 | memcpy(&op->atio, atio, sizeof(*atio)); |
Himanshu Madhani | 78c2106 | 2014-09-25 06:14:44 -0400 | [diff] [blame] | 4316 | op->vha = vha; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4317 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4318 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4319 | list_add_tail(&op->cmd_list, &vha->qla_sess_op_cmd_list); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4320 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4321 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4322 | INIT_WORK(&op->work, qlt_create_sess_from_atio); |
| 4323 | queue_work(qla_tgt_wq, &op->work); |
| 4324 | return 0; |
| 4325 | } |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4326 | |
| 4327 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4328 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4329 | if (sess->deleted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4330 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4331 | "New command while old session %p is being deleted\n", |
| 4332 | sess); |
| 4333 | return -EFAULT; |
| 4334 | } |
| 4335 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4336 | /* |
| 4337 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4338 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4339 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4340 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4341 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4342 | __func__, sess->port_name, |
| 4343 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4344 | return -EFAULT; |
| 4345 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4346 | |
| 4347 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4348 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4349 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4350 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4351 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4352 | ha->tgt.tgt_ops->put_sess(sess); |
| 4353 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4354 | return -ENOMEM; |
| 4355 | } |
| 4356 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4357 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4358 | cmd->trc_flags |= TRC_NEW_CMD; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4359 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4360 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4361 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4362 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4363 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4364 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4365 | if (vha->flags.qpairs_available) { |
| 4366 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work); |
| 4367 | } else if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4368 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4369 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4370 | &cmd->work); |
| 4371 | else |
| 4372 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4373 | &cmd->work); |
| 4374 | } else { |
| 4375 | queue_work(qla_tgt_wq, &cmd->work); |
| 4376 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4377 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4378 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4379 | } |
| 4380 | |
| 4381 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4382 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4383 | int fn, void *iocb, int flags) |
| 4384 | { |
| 4385 | struct scsi_qla_host *vha = sess->vha; |
| 4386 | struct qla_hw_data *ha = vha->hw; |
| 4387 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4388 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4389 | int res; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4390 | |
| 4391 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4392 | if (!mcmd) { |
| 4393 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4394 | "qla_target(%d): Allocation of management " |
| 4395 | "command failed, some commands and their data could " |
| 4396 | "leak\n", vha->vp_idx); |
| 4397 | return -ENOMEM; |
| 4398 | } |
| 4399 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4400 | mcmd->sess = sess; |
| 4401 | |
| 4402 | if (iocb) { |
| 4403 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4404 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4405 | } |
| 4406 | mcmd->tmr_func = fn; |
| 4407 | mcmd->flags = flags; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4408 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4409 | mcmd->qpair = ha->base_qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 4410 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4411 | |
| 4412 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4413 | case QLA_TGT_LUN_RESET: |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4414 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
| 4415 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4416 | } |
| 4417 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4418 | 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] | 4419 | if (res != 0) { |
| 4420 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, |
| 4421 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", |
| 4422 | sess->vha->vp_idx, res); |
| 4423 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4424 | return -EFAULT; |
| 4425 | } |
| 4426 | |
| 4427 | return 0; |
| 4428 | } |
| 4429 | |
| 4430 | /* ha->hardware_lock supposed to be held on entry */ |
| 4431 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4432 | { |
| 4433 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4434 | struct qla_hw_data *ha = vha->hw; |
| 4435 | struct qla_tgt *tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4436 | struct fc_port *sess; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4437 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4438 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4439 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4440 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4441 | tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4442 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4443 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4444 | |
| 4445 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4446 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4447 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4448 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4449 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4450 | unpacked_lun = |
| 4451 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4452 | |
| 4453 | if (!sess) { |
| 4454 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf024, |
| 4455 | "qla_target(%d): task mgmt fn 0x%x for " |
| 4456 | "non-existant session\n", vha->vp_idx, fn); |
| 4457 | return qlt_sched_sess_work(tgt, QLA_TGT_SESS_WORK_TM, iocb, |
| 4458 | sizeof(struct atio_from_isp)); |
| 4459 | } |
| 4460 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4461 | if (sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4462 | return -EFAULT; |
| 4463 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4464 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4465 | } |
| 4466 | |
| 4467 | /* ha->hardware_lock supposed to be held on entry */ |
| 4468 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4469 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4470 | { |
| 4471 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4472 | struct qla_hw_data *ha = vha->hw; |
| 4473 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4474 | u64 unpacked_lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4475 | int rc; |
| 4476 | |
| 4477 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4478 | if (mcmd == NULL) { |
| 4479 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4480 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4481 | vha->vp_idx, __func__); |
| 4482 | return -ENOMEM; |
| 4483 | } |
| 4484 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4485 | |
| 4486 | mcmd->sess = sess; |
| 4487 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4488 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4489 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4490 | unpacked_lun = |
| 4491 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4492 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4493 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4494 | mcmd->qpair = ha->base_qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4495 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4496 | 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] | 4497 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4498 | if (rc != 0) { |
| 4499 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4500 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4501 | vha->vp_idx, rc); |
| 4502 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4503 | return -EFAULT; |
| 4504 | } |
| 4505 | |
| 4506 | return 0; |
| 4507 | } |
| 4508 | |
| 4509 | /* ha->hardware_lock supposed to be held on entry */ |
| 4510 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4511 | struct imm_ntfy_from_isp *iocb) |
| 4512 | { |
| 4513 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4514 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4515 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4516 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4517 | |
| 4518 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4519 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4520 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4521 | 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] | 4522 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4523 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4524 | if (sess == NULL) { |
| 4525 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4526 | "qla_target(%d): task abort for unexisting " |
| 4527 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4528 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4529 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4530 | } |
| 4531 | |
| 4532 | return __qlt_abort_task(vha, iocb, sess); |
| 4533 | } |
| 4534 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4535 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4536 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4537 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4538 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4539 | "%s: se_sess %p / sess %p from" |
| 4540 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4541 | " LOGO failed: %#x\n", |
| 4542 | __func__, |
| 4543 | fcport->se_sess, |
| 4544 | fcport, |
| 4545 | fcport->port_name, fcport->loop_id, |
| 4546 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4547 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4548 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4549 | |
| 4550 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4551 | } |
| 4552 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4553 | /* |
| 4554 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4555 | * |
| 4556 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4557 | * deletion. Returns existing session with matching wwn if present. |
| 4558 | * Null otherwise. |
| 4559 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4560 | struct fc_port * |
| 4561 | 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] | 4562 | 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] | 4563 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4564 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4565 | uint64_t other_wwn; |
| 4566 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4567 | *conflict_sess = NULL; |
| 4568 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4569 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4570 | |
| 4571 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4572 | |
| 4573 | if (wwn == other_wwn) { |
| 4574 | WARN_ON(sess); |
| 4575 | sess = other_sess; |
| 4576 | continue; |
| 4577 | } |
| 4578 | |
| 4579 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4580 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4581 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4582 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4583 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4584 | other_sess, other_sess->loop_id, other_wwn); |
| 4585 | |
| 4586 | /* |
| 4587 | * logout_on_delete is set by default, but another |
| 4588 | * session that has the same s_id/loop_id combo |
| 4589 | * might have cleared it when requested this session |
| 4590 | * deletion, so don't touch it |
| 4591 | */ |
| 4592 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4593 | } else { |
| 4594 | /* |
| 4595 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4596 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4597 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4598 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01b, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4599 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4600 | other_sess, other_sess->loop_id, other_wwn); |
| 4601 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4602 | other_sess->keep_nport_handle = 1; |
Quinn Tran | ba743f9 | 2017-12-04 14:45:12 -0800 | [diff] [blame] | 4603 | if (other_sess->disc_state != DSC_DELETED) |
| 4604 | *conflict_sess = other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4605 | qlt_schedule_sess_for_deletion(other_sess, |
| 4606 | true); |
| 4607 | } |
| 4608 | continue; |
| 4609 | } |
| 4610 | |
| 4611 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4612 | if ((loop_id == other_sess->loop_id) && |
| 4613 | (loop_id != FC_NO_LOOP_ID)) { |
| 4614 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4615 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4616 | other_sess, other_sess->loop_id, other_wwn); |
| 4617 | |
| 4618 | /* Same loop_id but different s_id |
| 4619 | * Ok to kill and logout */ |
| 4620 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | return sess; |
| 4625 | } |
| 4626 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4627 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4628 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4629 | { |
| 4630 | struct qla_tgt_sess_op *op; |
| 4631 | struct qla_tgt_cmd *cmd; |
| 4632 | uint32_t key; |
| 4633 | int count = 0; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4634 | unsigned long flags; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4635 | |
| 4636 | key = (((u32)s_id->b.domain << 16) | |
| 4637 | ((u32)s_id->b.area << 8) | |
| 4638 | ((u32)s_id->b.al_pa)); |
| 4639 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4640 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4641 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4642 | 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] | 4643 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4644 | if (op_key == key) { |
| 4645 | op->aborted = true; |
| 4646 | count++; |
| 4647 | } |
| 4648 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4649 | |
| 4650 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4651 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 4652 | if (op_key == key) { |
| 4653 | op->aborted = true; |
| 4654 | count++; |
| 4655 | } |
| 4656 | } |
| 4657 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4658 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4659 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 4660 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4661 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4662 | count++; |
| 4663 | } |
| 4664 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4665 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4666 | |
| 4667 | return count; |
| 4668 | } |
| 4669 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4670 | /* |
| 4671 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4672 | */ |
| 4673 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4674 | struct imm_ntfy_from_isp *iocb) |
| 4675 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4676 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4677 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4678 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4679 | uint64_t wwn; |
| 4680 | port_id_t port_id; |
| 4681 | uint16_t loop_id; |
| 4682 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4683 | int res = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4684 | struct qlt_plogi_ack_t *pla; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame^] | 4685 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4686 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4687 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4688 | |
| 4689 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4690 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4691 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4692 | port_id.b.rsvd_1 = 0; |
| 4693 | |
| 4694 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4695 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4696 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4697 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4698 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4699 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4700 | iocb->u.isp24.status_subcode, loop_id, |
| 4701 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4702 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4703 | /* res = 1 means ack at the end of thread |
| 4704 | * res = 0 means ack async/later. |
| 4705 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4706 | switch (iocb->u.isp24.status_subcode) { |
| 4707 | case ELS_PLOGI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4708 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4709 | /* Mark all stale commands in qla_tgt_wq for deletion */ |
| 4710 | abort_cmds_for_s_id(vha, &port_id); |
| 4711 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4712 | if (wwn) { |
| 4713 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4714 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4715 | port_id, loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4716 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4717 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4718 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4719 | if (IS_SW_RESV_ADDR(port_id)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4720 | res = 1; |
| 4721 | break; |
| 4722 | } |
| 4723 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4724 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4725 | if (!pla) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4726 | qlt_send_term_imm_notif(vha, iocb, 1); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4727 | break; |
| 4728 | } |
| 4729 | |
| 4730 | res = 0; |
| 4731 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4732 | if (conflict_sess) { |
| 4733 | conflict_sess->login_gen++; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4734 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4735 | QLT_PLOGI_LINK_CONFLICT); |
| 4736 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4737 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4738 | if (!sess) { |
| 4739 | pla->ref_count++; |
| 4740 | qla24xx_post_newsess_work(vha, &port_id, |
| 4741 | iocb->u.isp24.port_name, pla); |
| 4742 | res = 0; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4743 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4744 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4745 | |
| 4746 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4747 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4748 | sess->d_id = port_id; |
| 4749 | sess->login_gen++; |
| 4750 | |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 4751 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4752 | "%s %d %8phC DS %d\n", |
| 4753 | __func__, __LINE__, sess->port_name, sess->disc_state); |
| 4754 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4755 | switch (sess->disc_state) { |
| 4756 | case DSC_DELETED: |
| 4757 | qlt_plogi_ack_unref(vha, pla); |
| 4758 | break; |
| 4759 | |
| 4760 | default: |
| 4761 | /* |
| 4762 | * Under normal circumstances we want to release nport handle |
| 4763 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4764 | * The exception is when LOGO is done while another PLOGI with |
| 4765 | * the same nport handle is waiting as might be the case here. |
| 4766 | * Note: there is always a possibily of a race where session |
| 4767 | * deletion has already started for other reasons (e.g. ACL |
| 4768 | * removal) and now PLOGI arrives: |
| 4769 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4770 | * FW must have assigned this PLOGI a new/same handle and we |
| 4771 | * can proceed ACK'ing it as usual when session deletion |
| 4772 | * completes. |
| 4773 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4774 | * bit reached it, the handle has now been released. We'll |
| 4775 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4776 | * back to initiator. Initiator should eventually retry |
| 4777 | * PLOGI and situation will correct itself. |
| 4778 | */ |
| 4779 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4780 | (sess->d_id.b24 == port_id.b24)); |
| 4781 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4782 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4783 | "%s %d %8phC post del sess\n", |
| 4784 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4785 | |
| 4786 | |
| 4787 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4788 | break; |
| 4789 | } |
| 4790 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4791 | break; |
| 4792 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4793 | case ELS_PRLI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4794 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4795 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4796 | if (wwn) { |
| 4797 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4798 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4799 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4800 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4801 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4802 | |
| 4803 | if (conflict_sess) { |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 4804 | switch (conflict_sess->disc_state) { |
| 4805 | case DSC_DELETED: |
| 4806 | case DSC_DELETE_PEND: |
| 4807 | break; |
| 4808 | default: |
| 4809 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4810 | "PRLI with conflicting sess %p port %8phC\n", |
| 4811 | conflict_sess, conflict_sess->port_name); |
| 4812 | conflict_sess->fw_login_state = |
| 4813 | DSC_LS_PORT_UNAVAIL; |
| 4814 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4815 | res = 0; |
| 4816 | break; |
| 4817 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4818 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4819 | |
| 4820 | if (sess != NULL) { |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame^] | 4821 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
| 4822 | switch (sess->fw_login_state) { |
| 4823 | case DSC_LS_PLOGI_COMP: |
| 4824 | case DSC_LS_PRLI_COMP: |
| 4825 | break; |
| 4826 | default: |
| 4827 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, |
| 4828 | flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4829 | /* |
| 4830 | * Impatient initiator sent PRLI before last |
| 4831 | * PLOGI could finish. Will force him to re-try, |
| 4832 | * while last one finishes. |
| 4833 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4834 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4835 | "sess %p PRLI received, before plogi ack.\n", |
| 4836 | sess); |
| 4837 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4838 | res = 0; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame^] | 4839 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, |
| 4840 | flags); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4841 | break; |
| 4842 | } |
| 4843 | |
| 4844 | /* |
| 4845 | * This shouldn't happen under normal circumstances, |
| 4846 | * since we have deleted the old session during PLOGI |
| 4847 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4848 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4849 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 4850 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 4851 | |
| 4852 | sess->local = 0; |
| 4853 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4854 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4855 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4856 | |
| 4857 | if (wd3_lo & BIT_7) |
| 4858 | sess->conf_compl_supported = 1; |
| 4859 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4860 | if ((wd3_lo & BIT_4) == 0) |
| 4861 | sess->port_type = FCT_INITIATOR; |
| 4862 | else |
| 4863 | sess->port_type = FCT_TARGET; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame^] | 4864 | |
| 4865 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4866 | } |
| 4867 | res = 1; /* send notify ack */ |
| 4868 | |
| 4869 | /* Make session global (not used in fabric mode) */ |
| 4870 | if (ha->current_topology != ISP_CFG_F) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4871 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4872 | ql_dbg(ql_dbg_disc, vha, 0x20fa, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4873 | "%s %d %8phC post nack\n", |
| 4874 | __func__, __LINE__, sess->port_name); |
| 4875 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4876 | SRB_NACK_PRLI); |
| 4877 | res = 0; |
| 4878 | } else { |
| 4879 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4880 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4881 | qla2xxx_wake_dpc(vha); |
| 4882 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4883 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4884 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4885 | ql_dbg(ql_dbg_disc, vha, 0x20fb, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4886 | "%s %d %8phC post nack\n", |
| 4887 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4888 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4889 | SRB_NACK_PRLI); |
| 4890 | res = 0; |
| 4891 | } |
| 4892 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4893 | break; |
| 4894 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4895 | case ELS_TPRLO: |
| 4896 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 4897 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 4898 | loop_id = 0xFFFF; |
| 4899 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 4900 | res = 1; |
| 4901 | break; |
| 4902 | } |
Bart Van Assche | 8188186 | 2017-12-07 16:02:46 -0800 | [diff] [blame] | 4903 | /* fall through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4904 | case ELS_LOGO: |
| 4905 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4906 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4907 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 4908 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4909 | |
| 4910 | if (sess) { |
| 4911 | sess->login_gen++; |
| 4912 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4913 | sess->logo_ack_needed = 1; |
| 4914 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 4915 | } |
| 4916 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4917 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4918 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4919 | ql_dbg(ql_dbg_disc, vha, 0x20fc, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4920 | "%s: logo %llx res %d sess %p ", |
| 4921 | __func__, wwn, res, sess); |
| 4922 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4923 | /* |
| 4924 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 4925 | * for LOGO_ACK & sess delete |
| 4926 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4927 | BUG_ON(!sess); |
| 4928 | res = 0; |
| 4929 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4930 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4931 | if (sess) { |
| 4932 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4933 | res = 0; |
| 4934 | } |
| 4935 | /* else logo will be ack */ |
| 4936 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4937 | break; |
| 4938 | case ELS_PDISC: |
| 4939 | case ELS_ADISC: |
| 4940 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4941 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4942 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4943 | qlt_send_notify_ack(ha->base_qpair, |
| 4944 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4945 | tgt->link_reinit_iocb_pending = 0; |
| 4946 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4947 | |
| 4948 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4949 | iocb->u.isp24.port_name, 1); |
| 4950 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4951 | ql_dbg(ql_dbg_disc, vha, 0x20fd, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4952 | "sess %p lid %d|%d DS %d LS %d\n", |
| 4953 | sess, sess->loop_id, loop_id, |
| 4954 | sess->disc_state, sess->fw_login_state); |
| 4955 | } |
| 4956 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4957 | res = 1; /* send notify ack */ |
| 4958 | break; |
| 4959 | } |
| 4960 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4961 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4962 | default: |
| 4963 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 4964 | "qla_target(%d): Unsupported ELS command %x " |
| 4965 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 4966 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 4967 | break; |
| 4968 | } |
| 4969 | |
| 4970 | return res; |
| 4971 | } |
| 4972 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4973 | /* |
| 4974 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4975 | */ |
| 4976 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 4977 | struct imm_ntfy_from_isp *iocb) |
| 4978 | { |
| 4979 | struct qla_hw_data *ha = vha->hw; |
| 4980 | uint32_t add_flags = 0; |
| 4981 | int send_notify_ack = 1; |
| 4982 | uint16_t status; |
| 4983 | |
| 4984 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 4985 | switch (status) { |
| 4986 | case IMM_NTFY_LIP_RESET: |
| 4987 | { |
| 4988 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 4989 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 4990 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4991 | iocb->u.isp24.status_subcode); |
| 4992 | |
| 4993 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 4994 | send_notify_ack = 0; |
| 4995 | break; |
| 4996 | } |
| 4997 | |
| 4998 | case IMM_NTFY_LIP_LINK_REINIT: |
| 4999 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5000 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5001 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 5002 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 5003 | "subcode %x)\n", vha->vp_idx, |
| 5004 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5005 | iocb->u.isp24.status_subcode); |
| 5006 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5007 | qlt_send_notify_ack(ha->base_qpair, |
| 5008 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5009 | } |
| 5010 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 5011 | tgt->link_reinit_iocb_pending = 1; |
| 5012 | /* |
| 5013 | * QLogic requires to wait after LINK REINIT for possible |
| 5014 | * PDISC or ADISC ELS commands |
| 5015 | */ |
| 5016 | send_notify_ack = 0; |
| 5017 | break; |
| 5018 | } |
| 5019 | |
| 5020 | case IMM_NTFY_PORT_LOGOUT: |
| 5021 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 5022 | "qla_target(%d): Port logout (loop " |
| 5023 | "%#x, subcode %x)\n", vha->vp_idx, |
| 5024 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 5025 | iocb->u.isp24.status_subcode); |
| 5026 | |
| 5027 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 5028 | send_notify_ack = 0; |
| 5029 | /* The sessions will be cleared in the callback, if needed */ |
| 5030 | break; |
| 5031 | |
| 5032 | case IMM_NTFY_GLBL_TPRLO: |
| 5033 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 5034 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 5035 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5036 | send_notify_ack = 0; |
| 5037 | /* The sessions will be cleared in the callback, if needed */ |
| 5038 | break; |
| 5039 | |
| 5040 | case IMM_NTFY_PORT_CONFIG: |
| 5041 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 5042 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 5043 | status); |
| 5044 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5045 | send_notify_ack = 0; |
| 5046 | /* The sessions will be cleared in the callback, if needed */ |
| 5047 | break; |
| 5048 | |
| 5049 | case IMM_NTFY_GLBL_LOGO: |
| 5050 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 5051 | "qla_target(%d): Link failure detected\n", |
| 5052 | vha->vp_idx); |
| 5053 | /* I_T nexus loss */ |
| 5054 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5055 | send_notify_ack = 0; |
| 5056 | break; |
| 5057 | |
| 5058 | case IMM_NTFY_IOCB_OVERFLOW: |
| 5059 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 5060 | "qla_target(%d): Cannot provide requested " |
| 5061 | "capability (IOCB overflowed the immediate notify " |
| 5062 | "resource count)\n", vha->vp_idx); |
| 5063 | break; |
| 5064 | |
| 5065 | case IMM_NTFY_ABORT_TASK: |
| 5066 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 5067 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 5068 | "L %#x)\n", vha->vp_idx, |
| 5069 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 5070 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 5071 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 5072 | if (qlt_abort_task(vha, iocb) == 0) |
| 5073 | send_notify_ack = 0; |
| 5074 | break; |
| 5075 | |
| 5076 | case IMM_NTFY_RESOURCE: |
| 5077 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 5078 | "qla_target(%d): Out of resources, host %ld\n", |
| 5079 | vha->vp_idx, vha->host_no); |
| 5080 | break; |
| 5081 | |
| 5082 | case IMM_NTFY_MSG_RX: |
| 5083 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 5084 | "qla_target(%d): Immediate notify task %x\n", |
| 5085 | vha->vp_idx, iocb->u.isp2x.task_flags); |
| 5086 | if (qlt_handle_task_mgmt(vha, iocb) == 0) |
| 5087 | send_notify_ack = 0; |
| 5088 | break; |
| 5089 | |
| 5090 | case IMM_NTFY_ELS: |
| 5091 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 5092 | send_notify_ack = 0; |
| 5093 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5094 | default: |
| 5095 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 5096 | "qla_target(%d): Received unknown immediate " |
| 5097 | "notify status %x\n", vha->vp_idx, status); |
| 5098 | break; |
| 5099 | } |
| 5100 | |
| 5101 | if (send_notify_ack) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5102 | qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0, |
| 5103 | 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5104 | } |
| 5105 | |
| 5106 | /* |
| 5107 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5108 | * This function sends busy to ISP 2xxx or 24xx. |
| 5109 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5110 | static int __qlt_send_busy(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5111 | struct atio_from_isp *atio, uint16_t status) |
| 5112 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5113 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5114 | struct ctio7_to_24xx *ctio24; |
| 5115 | struct qla_hw_data *ha = vha->hw; |
| 5116 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5117 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5118 | unsigned long flags; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5119 | u16 temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5120 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5121 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5122 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5123 | atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5124 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5125 | if (!sess) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5126 | qlt_send_term_exchange(qpair, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5127 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5128 | } |
| 5129 | /* Sending marker isn't necessary, since we called from ISR */ |
| 5130 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5131 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5132 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5133 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5134 | "qla_target(%d): %s failed: unable to allocate " |
| 5135 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5136 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5137 | } |
| 5138 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5139 | qpair->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5140 | pkt->entry_count = 1; |
| 5141 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5142 | |
| 5143 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5144 | ctio24->entry_type = CTIO_TYPE7; |
| 5145 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5146 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5147 | ctio24->vp_index = vha->vp_idx; |
| 5148 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5149 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5150 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5151 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5152 | temp = (atio->u.isp24.attr << 9) | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5153 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5154 | CTIO7_FLAGS_DONT_RET_CTIO; |
| 5155 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5156 | /* |
| 5157 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5158 | * if the explicit conformation is used. |
| 5159 | */ |
| 5160 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 5161 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5162 | /* Memory Barrier */ |
| 5163 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 5164 | if (qpair->reqq_start_iocbs) |
| 5165 | qpair->reqq_start_iocbs(qpair); |
| 5166 | else |
| 5167 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5168 | return 0; |
| 5169 | } |
| 5170 | |
| 5171 | /* |
| 5172 | * This routine is used to allocate a command for either a QFull condition |
| 5173 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5174 | * out previously. |
| 5175 | */ |
| 5176 | static void |
| 5177 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5178 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5179 | { |
| 5180 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5181 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5182 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5183 | struct se_session *se_sess; |
| 5184 | struct qla_tgt_cmd *cmd; |
| 5185 | int tag; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5186 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5187 | |
| 5188 | if (unlikely(tgt->tgt_stop)) { |
| 5189 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5190 | "New command while device %p is shutting down\n", tgt); |
| 5191 | return; |
| 5192 | } |
| 5193 | |
| 5194 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5195 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5196 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5197 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5198 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5199 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5200 | |
| 5201 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5202 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5203 | vha->vp_idx, __func__, |
| 5204 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5205 | |
| 5206 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5207 | return; |
| 5208 | } |
| 5209 | |
| 5210 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5211 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5212 | if (!sess) |
| 5213 | return; |
| 5214 | |
| 5215 | se_sess = sess->se_sess; |
| 5216 | |
| 5217 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 5218 | if (tag < 0) |
| 5219 | return; |
| 5220 | |
| 5221 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 5222 | if (!cmd) { |
| 5223 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5224 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5225 | vha->vp_idx, __func__); |
| 5226 | |
| 5227 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5228 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5229 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5230 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5231 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5232 | |
| 5233 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5234 | return; |
| 5235 | } |
| 5236 | |
| 5237 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 5238 | |
| 5239 | qlt_incr_num_pend_cmds(vha); |
| 5240 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5241 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5242 | |
| 5243 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5244 | cmd->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5245 | cmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5246 | cmd->q_full = 1; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5247 | cmd->qpair = ha->base_qpair; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5248 | |
| 5249 | if (qfull) { |
| 5250 | cmd->q_full = 1; |
| 5251 | /* NOTE: borrowing the state field to carry the status */ |
| 5252 | cmd->state = status; |
| 5253 | } else |
| 5254 | cmd->term_exchg = 1; |
| 5255 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5256 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5257 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5258 | |
| 5259 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5260 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5261 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5262 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5263 | vha->hw->tgt.num_qfull_cmds_alloc; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5264 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5265 | } |
| 5266 | |
| 5267 | int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5268 | qlt_free_qfull_cmds(struct qla_qpair *qpair) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5269 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5270 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5271 | struct qla_hw_data *ha = vha->hw; |
| 5272 | unsigned long flags; |
| 5273 | struct qla_tgt_cmd *cmd, *tcmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5274 | struct list_head free_list, q_full_list; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5275 | int rc = 0; |
| 5276 | |
| 5277 | if (list_empty(&ha->tgt.q_full_list)) |
| 5278 | return 0; |
| 5279 | |
| 5280 | INIT_LIST_HEAD(&free_list); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5281 | INIT_LIST_HEAD(&q_full_list); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5282 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5283 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5284 | if (list_empty(&ha->tgt.q_full_list)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5285 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5286 | return 0; |
| 5287 | } |
| 5288 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5289 | list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list); |
| 5290 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5291 | |
| 5292 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 5293 | list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5294 | if (cmd->q_full) |
| 5295 | /* cmd->state is a borrowed field to hold status */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5296 | rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5297 | else if (cmd->term_exchg) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5298 | rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5299 | |
| 5300 | if (rc == -ENOMEM) |
| 5301 | break; |
| 5302 | |
| 5303 | if (cmd->q_full) |
| 5304 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5305 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5306 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5307 | else if (cmd->term_exchg) |
| 5308 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5309 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5310 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5311 | else |
| 5312 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5313 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5314 | cmd); |
| 5315 | |
| 5316 | list_del(&cmd->cmd_list); |
| 5317 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5318 | |
| 5319 | /* piggy back on hardware_lock for protection */ |
| 5320 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5321 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5322 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5323 | |
| 5324 | cmd = NULL; |
| 5325 | |
| 5326 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5327 | list_del(&cmd->cmd_list); |
| 5328 | /* This cmd was never sent to TCM. There is no need |
| 5329 | * to schedule free or call free_cmd |
| 5330 | */ |
| 5331 | qlt_free_cmd(cmd); |
| 5332 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5333 | |
| 5334 | if (!list_empty(&q_full_list)) { |
| 5335 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 5336 | list_splice(&q_full_list, &vha->hw->tgt.q_full_list); |
| 5337 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5338 | } |
| 5339 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5340 | return rc; |
| 5341 | } |
| 5342 | |
| 5343 | static void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5344 | qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio, |
| 5345 | uint16_t status) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5346 | { |
| 5347 | int rc = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5348 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5349 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5350 | rc = __qlt_send_busy(qpair, atio, status); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5351 | if (rc == -ENOMEM) |
| 5352 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5353 | } |
| 5354 | |
| 5355 | static int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5356 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair, |
| 5357 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5358 | { |
| 5359 | struct qla_hw_data *ha = vha->hw; |
| 5360 | uint16_t status; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5361 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5362 | |
| 5363 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5364 | return 0; |
| 5365 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5366 | if (!ha_locked) |
| 5367 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5368 | status = temp_sam_status; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5369 | qlt_send_busy(qpair, atio, status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5370 | if (!ha_locked) |
| 5371 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5372 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5373 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | /* ha->hardware_lock supposed to be held on entry */ |
| 5377 | /* called via callback from qla2xxx */ |
| 5378 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5379 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5380 | { |
| 5381 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5382 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5383 | int rc; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5384 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5385 | |
| 5386 | if (unlikely(tgt == NULL)) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5387 | ql_dbg(ql_dbg_tgt, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5388 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5389 | return; |
| 5390 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5391 | /* |
| 5392 | * In tgt_stop mode we also should allow all requests to pass. |
| 5393 | * Otherwise, some commands can stuck. |
| 5394 | */ |
| 5395 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5396 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5397 | |
| 5398 | switch (atio->u.raw.entry_type) { |
| 5399 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5400 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5401 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5402 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5403 | "qla_target(%d): ATIO_TYPE7 " |
| 5404 | "received with UNKNOWN exchange address, " |
| 5405 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5406 | if (!ha_locked) |
| 5407 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5408 | qlt_send_busy(ha->base_qpair, atio, |
| 5409 | SAM_STAT_TASK_SET_FULL); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5410 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5411 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5412 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5413 | break; |
| 5414 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5415 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5416 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5417 | rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair, |
| 5418 | atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5419 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5420 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5421 | return; |
| 5422 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5423 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5424 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5425 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5426 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5427 | if (unlikely(rc != 0)) { |
| 5428 | if (rc == -ESRCH) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5429 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5430 | spin_lock_irqsave(&ha->hardware_lock, |
| 5431 | flags); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5432 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5433 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5434 | qlt_send_busy(ha->base_qpair, atio, |
| 5435 | SAM_STAT_BUSY); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5436 | #else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5437 | qlt_send_term_exchange(ha->base_qpair, NULL, |
| 5438 | atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5439 | #endif |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5440 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5441 | spin_unlock_irqrestore( |
| 5442 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5443 | } else { |
| 5444 | if (tgt->tgt_stop) { |
| 5445 | ql_dbg(ql_dbg_tgt, vha, 0xe059, |
| 5446 | "qla_target: Unable to send " |
| 5447 | "command to target for req, " |
| 5448 | "ignoring.\n"); |
| 5449 | } else { |
| 5450 | ql_dbg(ql_dbg_tgt, vha, 0xe05a, |
| 5451 | "qla_target(%d): Unable to send " |
| 5452 | "command to target, sending BUSY " |
| 5453 | "status.\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5454 | if (!ha_locked) |
| 5455 | spin_lock_irqsave( |
| 5456 | &ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5457 | qlt_send_busy(ha->base_qpair, |
| 5458 | atio, SAM_STAT_BUSY); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5459 | if (!ha_locked) |
| 5460 | spin_unlock_irqrestore( |
| 5461 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5462 | } |
| 5463 | } |
| 5464 | } |
| 5465 | break; |
| 5466 | |
| 5467 | case IMMED_NOTIFY_TYPE: |
| 5468 | { |
| 5469 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5470 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5471 | "qla_target(%d): Received ATIO packet %x " |
| 5472 | "with error status %x\n", vha->vp_idx, |
| 5473 | atio->u.raw.entry_type, |
| 5474 | atio->u.isp2x.entry_status); |
| 5475 | break; |
| 5476 | } |
| 5477 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5478 | |
| 5479 | if (!ha_locked) |
| 5480 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5481 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5482 | if (!ha_locked) |
| 5483 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5484 | break; |
| 5485 | } |
| 5486 | |
| 5487 | default: |
| 5488 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5489 | "qla_target(%d): Received unknown ATIO atio " |
| 5490 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5491 | break; |
| 5492 | } |
| 5493 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5494 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5495 | } |
| 5496 | |
| 5497 | /* ha->hardware_lock supposed to be held on entry */ |
| 5498 | /* called via callback from qla2xxx */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5499 | static void qlt_response_pkt(struct scsi_qla_host *vha, |
| 5500 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5501 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5502 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5503 | |
| 5504 | if (unlikely(tgt == NULL)) { |
| 5505 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5506 | "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n", |
| 5507 | vha->vp_idx, pkt->entry_type, vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5508 | return; |
| 5509 | } |
| 5510 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5511 | /* |
| 5512 | * In tgt_stop mode we also should allow all requests to pass. |
| 5513 | * Otherwise, some commands can stuck. |
| 5514 | */ |
| 5515 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5516 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5517 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5518 | case CTIO_TYPE7: |
| 5519 | { |
| 5520 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5521 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5522 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5523 | entry); |
| 5524 | break; |
| 5525 | } |
| 5526 | |
| 5527 | case ACCEPT_TGT_IO_TYPE: |
| 5528 | { |
| 5529 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5530 | int rc; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5531 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5532 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5533 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5534 | "qla_target(%d): ATIO with error " |
| 5535 | "status %x received\n", vha->vp_idx, |
| 5536 | le16_to_cpu(atio->u.isp2x.status)); |
| 5537 | break; |
| 5538 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5539 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5540 | rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1); |
Quinn Tran | ba68a63 | 2017-06-02 09:12:06 -0700 | [diff] [blame] | 5541 | if (rc != 0) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5542 | return; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5543 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5544 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5545 | if (unlikely(rc != 0)) { |
| 5546 | if (rc == -ESRCH) { |
| 5547 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5548 | qlt_send_busy(rsp->qpair, atio, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5549 | #else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5550 | qlt_send_term_exchange(rsp->qpair, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5551 | #endif |
| 5552 | } else { |
| 5553 | if (tgt->tgt_stop) { |
| 5554 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5555 | "qla_target: Unable to send " |
| 5556 | "command to target, sending TERM " |
| 5557 | "EXCHANGE for rsp\n"); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5558 | qlt_send_term_exchange(rsp->qpair, NULL, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5559 | atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5560 | } else { |
| 5561 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5562 | "qla_target(%d): Unable to send " |
| 5563 | "command to target, sending BUSY " |
| 5564 | "status\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5565 | qlt_send_busy(rsp->qpair, atio, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5566 | } |
| 5567 | } |
| 5568 | } |
| 5569 | } |
| 5570 | break; |
| 5571 | |
| 5572 | case CONTINUE_TGT_IO_TYPE: |
| 5573 | { |
| 5574 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5575 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5576 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5577 | entry); |
| 5578 | break; |
| 5579 | } |
| 5580 | |
| 5581 | case CTIO_A64_TYPE: |
| 5582 | { |
| 5583 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5584 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5585 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5586 | entry); |
| 5587 | break; |
| 5588 | } |
| 5589 | |
| 5590 | case IMMED_NOTIFY_TYPE: |
| 5591 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5592 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5593 | break; |
| 5594 | |
| 5595 | case NOTIFY_ACK_TYPE: |
| 5596 | if (tgt->notify_ack_expected > 0) { |
| 5597 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 5598 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5599 | "NOTIFY_ACK seq %08x status %x\n", |
| 5600 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5601 | le16_to_cpu(entry->u.isp2x.status)); |
| 5602 | tgt->notify_ack_expected--; |
| 5603 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5604 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5605 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5606 | "qla_target(%d): NOTIFY_ACK " |
| 5607 | "failed %x\n", vha->vp_idx, |
| 5608 | le16_to_cpu(entry->u.isp2x.status)); |
| 5609 | } |
| 5610 | } else { |
| 5611 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5612 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5613 | vha->vp_idx); |
| 5614 | } |
| 5615 | break; |
| 5616 | |
| 5617 | case ABTS_RECV_24XX: |
| 5618 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5619 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5620 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5621 | break; |
| 5622 | |
| 5623 | case ABTS_RESP_24XX: |
| 5624 | if (tgt->abts_resp_expected > 0) { |
| 5625 | struct abts_resp_from_24xx_fw *entry = |
| 5626 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5627 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5628 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5629 | entry->compl_status); |
| 5630 | tgt->abts_resp_expected--; |
| 5631 | if (le16_to_cpu(entry->compl_status) != |
| 5632 | ABTS_RESP_COMPL_SUCCESS) { |
| 5633 | if ((entry->error_subcode1 == 0x1E) && |
| 5634 | (entry->error_subcode2 == 0)) { |
| 5635 | /* |
| 5636 | * We've got a race here: aborted |
| 5637 | * exchange not terminated, i.e. |
| 5638 | * response for the aborted command was |
| 5639 | * sent between the abort request was |
| 5640 | * received and processed. |
| 5641 | * Unfortunately, the firmware has a |
| 5642 | * silly requirement that all aborted |
| 5643 | * exchanges must be explicitely |
| 5644 | * terminated, otherwise it refuses to |
| 5645 | * send responses for the abort |
| 5646 | * requests. So, we have to |
| 5647 | * (re)terminate the exchange and retry |
| 5648 | * the abort response. |
| 5649 | */ |
| 5650 | qlt_24xx_retry_term_exchange(vha, |
| 5651 | entry); |
| 5652 | } else |
| 5653 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5654 | "qla_target(%d): ABTS_RESP_24XX " |
| 5655 | "failed %x (subcode %x:%x)", |
| 5656 | vha->vp_idx, entry->compl_status, |
| 5657 | entry->error_subcode1, |
| 5658 | entry->error_subcode2); |
| 5659 | } |
| 5660 | } else { |
| 5661 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5662 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5663 | "received\n", vha->vp_idx); |
| 5664 | } |
| 5665 | break; |
| 5666 | |
| 5667 | default: |
| 5668 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5669 | "qla_target(%d): Received unknown response pkt " |
| 5670 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5671 | break; |
| 5672 | } |
| 5673 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | /* |
| 5677 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5678 | */ |
| 5679 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5680 | uint16_t *mailbox) |
| 5681 | { |
| 5682 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5683 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5684 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5685 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 5686 | if (!tgt || tgt->tgt_stop || tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5687 | return; |
| 5688 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5689 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5690 | IS_QLA2100(ha)) |
| 5691 | return; |
| 5692 | /* |
| 5693 | * In tgt_stop mode we also should allow all requests to pass. |
| 5694 | * Otherwise, some commands can stuck. |
| 5695 | */ |
| 5696 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5697 | |
| 5698 | switch (code) { |
| 5699 | case MBA_RESET: /* Reset */ |
| 5700 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5701 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5702 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5703 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5704 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5705 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5706 | break; |
| 5707 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5708 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5709 | break; |
| 5710 | |
| 5711 | case MBA_LOOP_UP: |
| 5712 | { |
| 5713 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5714 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5715 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5716 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5717 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5718 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5719 | qlt_send_notify_ack(ha->base_qpair, |
| 5720 | (void *)&tgt->link_reinit_iocb, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5721 | 0, 0, 0, 0, 0, 0); |
| 5722 | tgt->link_reinit_iocb_pending = 0; |
| 5723 | } |
| 5724 | break; |
| 5725 | } |
| 5726 | |
| 5727 | case MBA_LIP_OCCURRED: |
| 5728 | case MBA_LOOP_DOWN: |
| 5729 | case MBA_LIP_RESET: |
| 5730 | case MBA_RSCN_UPDATE: |
| 5731 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5732 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5733 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5734 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5735 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5736 | break; |
| 5737 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5738 | case MBA_REJECTED_FCP_CMD: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5739 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017, |
| 5740 | "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", |
| 5741 | vha->vp_idx, |
| 5742 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5743 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5744 | |
| 5745 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 5746 | /* exchange starvation. */ |
| 5747 | vha->hw->exch_starvation++; |
| 5748 | if (vha->hw->exch_starvation > 5) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5749 | ql_log(ql_log_warn, vha, 0xd03a, |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5750 | "Exchange starvation-. Resetting RISC\n"); |
| 5751 | |
| 5752 | vha->hw->exch_starvation = 0; |
| 5753 | if (IS_P3P_TYPE(vha->hw)) |
| 5754 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 5755 | &vha->dpc_flags); |
| 5756 | else |
| 5757 | set_bit(ISP_ABORT_NEEDED, |
| 5758 | &vha->dpc_flags); |
| 5759 | qla2xxx_wake_dpc(vha); |
| 5760 | } |
| 5761 | } |
| 5762 | break; |
| 5763 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5764 | case MBA_PORT_UPDATE: |
| 5765 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5766 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5767 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5768 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5769 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5770 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5771 | |
| 5772 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5773 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5774 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 5775 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5776 | vha->hw->exch_starvation = 0; |
| 5777 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5778 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 5779 | "Async MB 2: Port Logged Out\n"); |
| 5780 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5781 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5782 | break; |
| 5783 | } |
| 5784 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5785 | } |
| 5786 | |
| 5787 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 5788 | uint16_t loop_id) |
| 5789 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5790 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5791 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5792 | unsigned long flags; |
| 5793 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5794 | |
Quinn Tran | 063b36d | 2017-12-04 14:45:10 -0800 | [diff] [blame] | 5795 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5796 | if (!fcport) { |
| 5797 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 5798 | "qla_target(%d): Allocation of tmp FC port failed", |
| 5799 | vha->vp_idx); |
| 5800 | return NULL; |
| 5801 | } |
| 5802 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5803 | fcport->loop_id = loop_id; |
| 5804 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 5805 | rc = qla24xx_gpdb_wait(vha, fcport, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5806 | if (rc != QLA_SUCCESS) { |
| 5807 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 5808 | "qla_target(%d): Failed to retrieve fcport " |
| 5809 | "information -- get_port_database() returned %x " |
| 5810 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 5811 | kfree(fcport); |
| 5812 | return NULL; |
| 5813 | } |
| 5814 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5815 | del = NULL; |
| 5816 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5817 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 5818 | |
| 5819 | if (tfcp) { |
| 5820 | tfcp->d_id = fcport->d_id; |
| 5821 | tfcp->port_type = fcport->port_type; |
| 5822 | tfcp->supported_classes = fcport->supported_classes; |
| 5823 | tfcp->flags |= fcport->flags; |
Quinn Tran | 76f9a2d | 2017-12-04 14:45:11 -0800 | [diff] [blame] | 5824 | tfcp->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5825 | |
| 5826 | del = fcport; |
| 5827 | fcport = tfcp; |
| 5828 | } else { |
| 5829 | if (vha->hw->current_topology == ISP_CFG_F) |
| 5830 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 5831 | |
| 5832 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 5833 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 5834 | vha->fcport_count++; |
| 5835 | fcport->login_gen++; |
| 5836 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 5837 | fcport->login_succ = 1; |
| 5838 | newfcport = 1; |
| 5839 | } |
| 5840 | |
| 5841 | fcport->deleted = 0; |
| 5842 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5843 | |
| 5844 | switch (vha->host->active_mode) { |
| 5845 | case MODE_INITIATOR: |
| 5846 | case MODE_DUAL: |
| 5847 | if (newfcport) { |
| 5848 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5849 | ql_dbg(ql_dbg_disc, vha, 0x20fe, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5850 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 5851 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5852 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 5853 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5854 | ql_dbg(ql_dbg_disc, vha, 0x20ff, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5855 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 5856 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5857 | qla24xx_post_gpsc_work(vha, fcport); |
| 5858 | } |
| 5859 | } |
| 5860 | break; |
| 5861 | |
| 5862 | case MODE_TARGET: |
| 5863 | default: |
| 5864 | break; |
| 5865 | } |
| 5866 | if (del) |
| 5867 | qla2x00_free_fcport(del); |
| 5868 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5869 | return fcport; |
| 5870 | } |
| 5871 | |
| 5872 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5873 | 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] | 5874 | uint8_t *s_id) |
| 5875 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5876 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5877 | fc_port_t *fcport = NULL; |
| 5878 | int rc, global_resets; |
| 5879 | uint16_t loop_id = 0; |
| 5880 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5881 | if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) { |
| 5882 | /* |
| 5883 | * This is Domain Controller, so it should be |
| 5884 | * OK to drop SCSI commands from it. |
| 5885 | */ |
| 5886 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 5887 | "Unable to find initiator with S_ID %x:%x:%x", |
| 5888 | s_id[0], s_id[1], s_id[2]); |
| 5889 | return NULL; |
| 5890 | } |
| 5891 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5892 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 5893 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5894 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5895 | global_resets = |
| 5896 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5897 | |
| 5898 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 5899 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5900 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5901 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5902 | ql_log(ql_log_info, vha, 0xf071, |
| 5903 | "qla_target(%d): Unable to find " |
| 5904 | "initiator with S_ID %x:%x:%x", |
| 5905 | vha->vp_idx, s_id[0], s_id[1], |
| 5906 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5907 | |
| 5908 | if (rc == -ENOENT) { |
| 5909 | qlt_port_logo_t logo; |
| 5910 | sid_to_portid(s_id, &logo.id); |
| 5911 | logo.cmd_count = 1; |
| 5912 | qlt_send_first_logo(vha, &logo); |
| 5913 | } |
| 5914 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5915 | return NULL; |
| 5916 | } |
| 5917 | |
| 5918 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5919 | if (!fcport) { |
| 5920 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5921 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5922 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5923 | |
| 5924 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5925 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5926 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 5927 | "qla_target(%d): global reset during session discovery " |
| 5928 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 5929 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5930 | atomic_read(&vha->vha_tgt. |
| 5931 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5932 | goto retry; |
| 5933 | } |
| 5934 | |
| 5935 | sess = qlt_create_sess(vha, fcport, true); |
| 5936 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5937 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5938 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5939 | return sess; |
| 5940 | } |
| 5941 | |
| 5942 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 5943 | struct qla_tgt_sess_work_param *prm) |
| 5944 | { |
| 5945 | struct scsi_qla_host *vha = tgt->vha; |
| 5946 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5947 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5948 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5949 | uint32_t be_s_id; |
| 5950 | uint8_t s_id[3]; |
| 5951 | int rc; |
| 5952 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5953 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5954 | |
| 5955 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5956 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5957 | |
| 5958 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 5959 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 5960 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 5961 | |
| 5962 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5963 | (unsigned char *)&be_s_id); |
| 5964 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5965 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5966 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5967 | sess = qlt_make_local_sess(vha, s_id); |
| 5968 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5969 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5970 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5971 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5972 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5973 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5974 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5975 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5976 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5977 | } |
| 5978 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5979 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5980 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5981 | "%s: kref_get fail %8phC \n", |
| 5982 | __func__, sess->port_name); |
| 5983 | sess = NULL; |
| 5984 | goto out_term2; |
| 5985 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5986 | } |
| 5987 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5988 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5989 | ha->tgt.tgt_ops->put_sess(sess); |
| 5990 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 5991 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5992 | if (rc != 0) |
| 5993 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5994 | return; |
| 5995 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5996 | out_term2: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5997 | if (sess) |
| 5998 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5999 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6000 | |
| 6001 | out_term: |
| 6002 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6003 | qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts, |
| 6004 | FCP_TMF_REJECTED, false); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6005 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 6009 | struct qla_tgt_sess_work_param *prm) |
| 6010 | { |
| 6011 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 6012 | struct scsi_qla_host *vha = tgt->vha; |
| 6013 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6014 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6015 | unsigned long flags; |
| 6016 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 6017 | int rc; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6018 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 6019 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6020 | void *iocb; |
| 6021 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6022 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6023 | |
| 6024 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6025 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6026 | |
| 6027 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 6028 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 6029 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6030 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6031 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6032 | sess = qlt_make_local_sess(vha, s_id); |
| 6033 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6034 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6035 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6036 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6037 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6038 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6039 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6040 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6041 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6042 | } |
| 6043 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6044 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6045 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6046 | "%s: kref_get fail %8phC\n", |
| 6047 | __func__, sess->port_name); |
| 6048 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6049 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6050 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | iocb = a; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6054 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6055 | unpacked_lun = |
| 6056 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6057 | |
| 6058 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6059 | ha->tgt.tgt_ops->put_sess(sess); |
| 6060 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 6061 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6062 | if (rc != 0) |
| 6063 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6064 | return; |
| 6065 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6066 | out_term2: |
| 6067 | if (sess) |
| 6068 | ha->tgt.tgt_ops->put_sess(sess); |
| 6069 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6070 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6071 | 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] | 6072 | } |
| 6073 | |
| 6074 | static void qlt_sess_work_fn(struct work_struct *work) |
| 6075 | { |
| 6076 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 6077 | struct scsi_qla_host *vha = tgt->vha; |
| 6078 | unsigned long flags; |
| 6079 | |
| 6080 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 6081 | |
| 6082 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6083 | while (!list_empty(&tgt->sess_works_list)) { |
| 6084 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 6085 | tgt->sess_works_list.next, typeof(*prm), |
| 6086 | sess_works_list_entry); |
| 6087 | |
| 6088 | /* |
| 6089 | * This work can be scheduled on several CPUs at time, so we |
| 6090 | * must delete the entry to eliminate double processing |
| 6091 | */ |
| 6092 | list_del(&prm->sess_works_list_entry); |
| 6093 | |
| 6094 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6095 | |
| 6096 | switch (prm->type) { |
| 6097 | case QLA_TGT_SESS_WORK_ABORT: |
| 6098 | qlt_abort_work(tgt, prm); |
| 6099 | break; |
| 6100 | case QLA_TGT_SESS_WORK_TM: |
| 6101 | qlt_tmr_work(tgt, prm); |
| 6102 | break; |
| 6103 | default: |
| 6104 | BUG_ON(1); |
| 6105 | break; |
| 6106 | } |
| 6107 | |
| 6108 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6109 | |
| 6110 | kfree(prm); |
| 6111 | } |
| 6112 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6113 | } |
| 6114 | |
| 6115 | /* Must be called under tgt_host_action_mutex */ |
| 6116 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 6117 | { |
| 6118 | struct qla_tgt *tgt; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6119 | int rc, i; |
| 6120 | struct qla_qpair_hint *h; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6121 | |
| 6122 | if (!QLA_TGT_MODE_ENABLED()) |
| 6123 | return 0; |
| 6124 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 6125 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 6126 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 6127 | "This adapter does not support target mode.\n"); |
| 6128 | return 0; |
| 6129 | } |
| 6130 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6131 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6132 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6133 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6134 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6135 | |
| 6136 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 6137 | if (!tgt) { |
| 6138 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 6139 | "Unable to allocate struct qla_tgt\n"); |
| 6140 | return -ENOMEM; |
| 6141 | } |
| 6142 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6143 | tgt->qphints = kzalloc((ha->max_qpairs + 1) * |
| 6144 | sizeof(struct qla_qpair_hint), GFP_KERNEL); |
| 6145 | if (!tgt->qphints) { |
| 6146 | kfree(tgt); |
| 6147 | ql_log(ql_log_warn, base_vha, 0x0197, |
| 6148 | "Unable to allocate qpair hints.\n"); |
| 6149 | return -ENOMEM; |
| 6150 | } |
| 6151 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6152 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 6153 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 6154 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6155 | rc = btree_init64(&tgt->lun_qpair_map); |
| 6156 | if (rc) { |
| 6157 | kfree(tgt->qphints); |
| 6158 | kfree(tgt); |
| 6159 | ql_log(ql_log_info, base_vha, 0x0198, |
| 6160 | "Unable to initialize lun_qpair_map btree\n"); |
| 6161 | return -EIO; |
| 6162 | } |
| 6163 | h = &tgt->qphints[0]; |
| 6164 | h->qpair = ha->base_qpair; |
| 6165 | INIT_LIST_HEAD(&h->hint_elem); |
| 6166 | h->cpuid = ha->base_qpair->cpuid; |
| 6167 | list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list); |
| 6168 | |
| 6169 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6170 | unsigned long flags; |
| 6171 | |
| 6172 | struct qla_qpair *qpair = ha->queue_pair_map[i]; |
| 6173 | h = &tgt->qphints[i + 1]; |
| 6174 | INIT_LIST_HEAD(&h->hint_elem); |
| 6175 | if (qpair) { |
| 6176 | h->qpair = qpair; |
| 6177 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 6178 | list_add_tail(&h->hint_elem, &qpair->hints_list); |
| 6179 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 6180 | h->cpuid = qpair->cpuid; |
| 6181 | } |
| 6182 | } |
| 6183 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6184 | tgt->ha = ha; |
| 6185 | tgt->vha = base_vha; |
| 6186 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6187 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6188 | spin_lock_init(&tgt->sess_work_lock); |
| 6189 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6190 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6191 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6192 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6193 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6194 | |
| 6195 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6196 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6197 | base_vha->vp_idx); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6198 | /* 3 is reserved */ |
| 6199 | 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] | 6200 | |
| 6201 | mutex_lock(&qla_tgt_mutex); |
| 6202 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6203 | mutex_unlock(&qla_tgt_mutex); |
| 6204 | |
Quinn Tran | f1443ee | 2017-03-15 09:48:51 -0700 | [diff] [blame] | 6205 | if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target) |
| 6206 | ha->tgt.tgt_ops->add_target(base_vha); |
| 6207 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6208 | return 0; |
| 6209 | } |
| 6210 | |
| 6211 | /* Must be called under tgt_host_action_mutex */ |
| 6212 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6213 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6214 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6215 | return 0; |
| 6216 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6217 | if (vha->fc_vport) { |
| 6218 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6219 | return 0; |
| 6220 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6221 | |
| 6222 | /* free left over qfull cmds */ |
| 6223 | qlt_init_term_exchange(vha); |
| 6224 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6225 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6226 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6227 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6228 | |
| 6229 | return 0; |
| 6230 | } |
| 6231 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6232 | void qlt_remove_target_resources(struct qla_hw_data *ha) |
| 6233 | { |
| 6234 | struct scsi_qla_host *node; |
| 6235 | u32 key = 0; |
| 6236 | |
| 6237 | btree_for_each_safe32(&ha->tgt.host_map, key, node) |
| 6238 | btree_remove32(&ha->tgt.host_map, key); |
| 6239 | |
| 6240 | btree_destroy32(&ha->tgt.host_map); |
| 6241 | } |
| 6242 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6243 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6244 | unsigned char *b) |
| 6245 | { |
| 6246 | int i; |
| 6247 | |
| 6248 | pr_debug("qla2xxx HW vha->node_name: "); |
| 6249 | for (i = 0; i < WWN_SIZE; i++) |
| 6250 | pr_debug("%02x ", vha->node_name[i]); |
| 6251 | pr_debug("\n"); |
| 6252 | pr_debug("qla2xxx HW vha->port_name: "); |
| 6253 | for (i = 0; i < WWN_SIZE; i++) |
| 6254 | pr_debug("%02x ", vha->port_name[i]); |
| 6255 | pr_debug("\n"); |
| 6256 | |
| 6257 | pr_debug("qla2xxx passed configfs WWPN: "); |
| 6258 | put_unaligned_be64(wwpn, b); |
| 6259 | for (i = 0; i < WWN_SIZE; i++) |
| 6260 | pr_debug("%02x ", b[i]); |
| 6261 | pr_debug("\n"); |
| 6262 | } |
| 6263 | |
| 6264 | /** |
| 6265 | * qla_tgt_lport_register - register lport with external module |
| 6266 | * |
| 6267 | * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops |
| 6268 | * @wwpn: Passwd FC target WWPN |
| 6269 | * @callback: lport initialization callback for tcm_qla2xxx code |
| 6270 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
| 6271 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6272 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6273 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6274 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6275 | { |
| 6276 | struct qla_tgt *tgt; |
| 6277 | struct scsi_qla_host *vha; |
| 6278 | struct qla_hw_data *ha; |
| 6279 | struct Scsi_Host *host; |
| 6280 | unsigned long flags; |
| 6281 | int rc; |
| 6282 | u8 b[WWN_SIZE]; |
| 6283 | |
| 6284 | mutex_lock(&qla_tgt_mutex); |
| 6285 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6286 | vha = tgt->vha; |
| 6287 | ha = vha->hw; |
| 6288 | |
| 6289 | host = vha->host; |
| 6290 | if (!host) |
| 6291 | continue; |
| 6292 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6293 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6294 | continue; |
| 6295 | |
| 6296 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6297 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6298 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6299 | host->host_no); |
| 6300 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6301 | continue; |
| 6302 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6303 | if (tgt->tgt_stop) { |
| 6304 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6305 | host->host_no); |
| 6306 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6307 | continue; |
| 6308 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6309 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6310 | |
| 6311 | if (!scsi_host_get(host)) { |
| 6312 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6313 | "Unable to scsi_host_get() for" |
| 6314 | " qla2xxx scsi_host\n"); |
| 6315 | continue; |
| 6316 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6317 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6318 | |
| 6319 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6320 | scsi_host_put(host); |
| 6321 | continue; |
| 6322 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6323 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6324 | if (rc != 0) |
| 6325 | scsi_host_put(host); |
| 6326 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6327 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6328 | return rc; |
| 6329 | } |
| 6330 | mutex_unlock(&qla_tgt_mutex); |
| 6331 | |
| 6332 | return -ENODEV; |
| 6333 | } |
| 6334 | EXPORT_SYMBOL(qlt_lport_register); |
| 6335 | |
| 6336 | /** |
| 6337 | * qla_tgt_lport_deregister - Degister lport |
| 6338 | * |
| 6339 | * @vha: Registered scsi_qla_host pointer |
| 6340 | */ |
| 6341 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6342 | { |
| 6343 | struct qla_hw_data *ha = vha->hw; |
| 6344 | struct Scsi_Host *sh = vha->host; |
| 6345 | /* |
| 6346 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6347 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6348 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6349 | ha->tgt.tgt_ops = NULL; |
| 6350 | /* |
| 6351 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6352 | */ |
| 6353 | scsi_host_put(sh); |
| 6354 | } |
| 6355 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6356 | |
| 6357 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6358 | static void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6359 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6360 | switch (ql2x_ini_mode) { |
| 6361 | case QLA2XXX_INI_MODE_DISABLED: |
| 6362 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6363 | vha->host->active_mode = MODE_TARGET; |
| 6364 | break; |
| 6365 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6366 | vha->host->active_mode = MODE_UNKNOWN; |
| 6367 | break; |
| 6368 | case QLA2XXX_INI_MODE_DUAL: |
| 6369 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6370 | break; |
| 6371 | default: |
| 6372 | break; |
| 6373 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6374 | } |
| 6375 | |
| 6376 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6377 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6378 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6379 | switch (ql2x_ini_mode) { |
| 6380 | case QLA2XXX_INI_MODE_DISABLED: |
| 6381 | vha->host->active_mode = MODE_UNKNOWN; |
| 6382 | break; |
| 6383 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6384 | vha->host->active_mode = MODE_INITIATOR; |
| 6385 | break; |
| 6386 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6387 | case QLA2XXX_INI_MODE_DUAL: |
| 6388 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6389 | break; |
| 6390 | default: |
| 6391 | break; |
| 6392 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | /* |
| 6396 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6397 | * |
| 6398 | * host_reset, bring up w/ Target Mode Enabled |
| 6399 | */ |
| 6400 | void |
| 6401 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6402 | { |
| 6403 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6404 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6405 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6406 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6407 | |
| 6408 | if (!tgt) { |
| 6409 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6410 | "Unable to locate qla_tgt pointer from" |
| 6411 | " struct qla_hw_data\n"); |
| 6412 | dump_stack(); |
| 6413 | return; |
| 6414 | } |
| 6415 | |
| 6416 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6417 | tgt->tgt_stopped = 0; |
| 6418 | qlt_set_mode(vha); |
| 6419 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6420 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6421 | if (vha->vp_idx) { |
| 6422 | qla24xx_disable_vp(vha); |
| 6423 | qla24xx_enable_vp(vha); |
| 6424 | } else { |
| 6425 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6426 | qla2xxx_wake_dpc(base_vha); |
| 6427 | qla2x00_wait_for_hba_online(base_vha); |
| 6428 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6429 | } |
| 6430 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6431 | |
| 6432 | /* |
| 6433 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6434 | * |
| 6435 | * Disable Target Mode and reset the adapter |
| 6436 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6437 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6438 | { |
| 6439 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6440 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6441 | unsigned long flags; |
| 6442 | |
| 6443 | if (!tgt) { |
| 6444 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6445 | "Unable to locate qla_tgt pointer from" |
| 6446 | " struct qla_hw_data\n"); |
| 6447 | dump_stack(); |
| 6448 | return; |
| 6449 | } |
| 6450 | |
| 6451 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6452 | qlt_clear_mode(vha); |
| 6453 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6454 | |
| 6455 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6456 | qla2xxx_wake_dpc(vha); |
| 6457 | qla2x00_wait_for_hba_online(vha); |
| 6458 | } |
| 6459 | |
| 6460 | /* |
| 6461 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6462 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6463 | * members. |
| 6464 | */ |
| 6465 | void |
| 6466 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6467 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6468 | vha->vha_tgt.qla_tgt = NULL; |
| 6469 | |
| 6470 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6471 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6472 | |
| 6473 | qlt_clear_mode(vha); |
| 6474 | |
| 6475 | /* |
| 6476 | * NOTE: Currently the value is kept the same for <24xx and |
| 6477 | * >=24xx ISPs. If it is necessary to change it, |
| 6478 | * the check should be added for specific ISPs, |
| 6479 | * assigning the value appropriately. |
| 6480 | */ |
| 6481 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6482 | |
| 6483 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6484 | } |
| 6485 | |
| 6486 | void |
| 6487 | qlt_rff_id(struct scsi_qla_host *vha, struct ct_sns_req *ct_req) |
| 6488 | { |
| 6489 | /* |
| 6490 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6491 | */ |
| 6492 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6493 | ct_req->req.rff_id.fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6494 | } else if (qla_ini_mode_enabled(vha)) { |
| 6495 | ct_req->req.rff_id.fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6496 | } else if (qla_dual_mode_enabled(vha)) |
| 6497 | ct_req->req.rff_id.fc4_feature = BIT_0 | BIT_1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | /* |
| 6501 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6502 | * @ha: HA context |
| 6503 | * |
| 6504 | * Beginning of ATIO ring has initialization control block already built |
| 6505 | * by nvram config routine. |
| 6506 | * |
| 6507 | * Returns 0 on success. |
| 6508 | */ |
| 6509 | void |
| 6510 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6511 | { |
| 6512 | struct qla_hw_data *ha = vha->hw; |
| 6513 | uint16_t cnt; |
| 6514 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6515 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6516 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6517 | return; |
| 6518 | |
| 6519 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6520 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6521 | pkt++; |
| 6522 | } |
| 6523 | |
| 6524 | } |
| 6525 | |
| 6526 | /* |
| 6527 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6528 | * @ha: SCSI driver HA context |
| 6529 | */ |
| 6530 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6531 | 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] | 6532 | { |
| 6533 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6534 | struct atio_from_isp *pkt; |
| 6535 | int cnt, i; |
| 6536 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6537 | if (!ha->flags.fw_started) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6538 | return; |
| 6539 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6540 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6541 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6542 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6543 | cnt = pkt->u.raw.entry_count; |
| 6544 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6545 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6546 | /* |
| 6547 | * This packet is corrupted. The header + payload |
| 6548 | * can not be trusted. There is no point in passing |
| 6549 | * it further up. |
| 6550 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6551 | ql_log(ql_log_warn, vha, 0xd03c, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6552 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6553 | pkt->u.isp24.fcp_hdr.s_id, |
| 6554 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6555 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6556 | |
| 6557 | adjust_corrupted_atio(pkt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6558 | qlt_send_term_exchange(ha->base_qpair, NULL, pkt, |
| 6559 | ha_locked, 0); |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6560 | } else { |
| 6561 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6562 | (struct atio_from_isp *)pkt, ha_locked); |
| 6563 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6564 | |
| 6565 | for (i = 0; i < cnt; i++) { |
| 6566 | ha->tgt.atio_ring_index++; |
| 6567 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6568 | ha->tgt.atio_ring_index = 0; |
| 6569 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6570 | } else |
| 6571 | ha->tgt.atio_ring_ptr++; |
| 6572 | |
| 6573 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6574 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6575 | } |
| 6576 | wmb(); |
| 6577 | } |
| 6578 | |
| 6579 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6580 | 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] | 6581 | } |
| 6582 | |
| 6583 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6584 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6585 | { |
| 6586 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6587 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6588 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6589 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6590 | if (!QLA_TGT_MODE_ENABLED()) |
| 6591 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6592 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6593 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6594 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6595 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6596 | |
Quinn Tran | d2b292c | 2017-12-28 12:33:17 -0800 | [diff] [blame] | 6597 | if (ha->flags.msix_enabled) { |
| 6598 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
| 6599 | if (IS_QLA2071(ha)) { |
| 6600 | /* 4 ports Baker: Enable Interrupt Handshake */ |
| 6601 | icb->msix_atio = 0; |
| 6602 | icb->firmware_options_2 |= BIT_26; |
| 6603 | } else { |
| 6604 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6605 | icb->firmware_options_2 &= ~BIT_26; |
| 6606 | } |
| 6607 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6608 | "Registering ICB vector 0x%x for atio que.\n", |
| 6609 | msix->entry); |
| 6610 | } |
| 6611 | } else { |
| 6612 | /* INTx|MSI */ |
| 6613 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
| 6614 | icb->msix_atio = 0; |
| 6615 | icb->firmware_options_2 |= BIT_26; |
| 6616 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6617 | "%s: Use INTx for ATIOQ.\n", __func__); |
| 6618 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | void |
| 6623 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6624 | { |
| 6625 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6626 | |
| 6627 | if (!QLA_TGT_MODE_ENABLED()) |
| 6628 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6629 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6630 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6631 | if (!ha->tgt.saved_set) { |
| 6632 | /* We save only once */ |
| 6633 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6634 | ha->tgt.saved_firmware_options_1 = |
| 6635 | nv->firmware_options_1; |
| 6636 | ha->tgt.saved_firmware_options_2 = |
| 6637 | nv->firmware_options_2; |
| 6638 | ha->tgt.saved_firmware_options_3 = |
| 6639 | nv->firmware_options_3; |
| 6640 | ha->tgt.saved_set = 1; |
| 6641 | } |
| 6642 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6643 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6644 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6645 | else /* dual */ |
| 6646 | nv->exchange_count = cpu_to_le16(ql2xexchoffld); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6647 | |
| 6648 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6649 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6650 | |
| 6651 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6652 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6653 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6654 | |
| 6655 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6656 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6657 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6658 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6659 | if (ql2xtgt_tape_enable) |
| 6660 | /* Enable FC Tape support */ |
| 6661 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6662 | else |
| 6663 | /* Disable FC Tape support */ |
| 6664 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6665 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6666 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6667 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6668 | |
| 6669 | /* |
| 6670 | * clear BIT 15 explicitly as we have seen at least |
| 6671 | * a couple of instances where this was set and this |
| 6672 | * was causing the firmware to not be initialized. |
| 6673 | */ |
| 6674 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6675 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6676 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6677 | } else { |
| 6678 | if (ha->tgt.saved_set) { |
| 6679 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6680 | nv->firmware_options_1 = |
| 6681 | ha->tgt.saved_firmware_options_1; |
| 6682 | nv->firmware_options_2 = |
| 6683 | ha->tgt.saved_firmware_options_2; |
| 6684 | nv->firmware_options_3 = |
| 6685 | ha->tgt.saved_firmware_options_3; |
| 6686 | } |
| 6687 | return; |
| 6688 | } |
| 6689 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6690 | if (ha->base_qpair->enable_class_2) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6691 | if (vha->flags.init_done) |
| 6692 | fc_host_supported_classes(vha->host) = |
| 6693 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6694 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6695 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6696 | } else { |
| 6697 | if (vha->flags.init_done) |
| 6698 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6699 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6700 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6701 | } |
| 6702 | } |
| 6703 | |
| 6704 | void |
| 6705 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6706 | struct init_cb_24xx *icb) |
| 6707 | { |
| 6708 | struct qla_hw_data *ha = vha->hw; |
| 6709 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6710 | if (!QLA_TGT_MODE_ENABLED()) |
| 6711 | return; |
| 6712 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6713 | if (ha->tgt.node_name_set) { |
| 6714 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6715 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6716 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6717 | |
| 6718 | /* disable ZIO at start time. */ |
| 6719 | if (!vha->flags.init_done) { |
| 6720 | uint32_t tmp; |
| 6721 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6722 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6723 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6724 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6725 | } |
| 6726 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6727 | void |
| 6728 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6729 | { |
| 6730 | struct qla_hw_data *ha = vha->hw; |
| 6731 | |
| 6732 | if (!QLA_TGT_MODE_ENABLED()) |
| 6733 | return; |
| 6734 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6735 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6736 | if (!ha->tgt.saved_set) { |
| 6737 | /* We save only once */ |
| 6738 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6739 | ha->tgt.saved_firmware_options_1 = |
| 6740 | nv->firmware_options_1; |
| 6741 | ha->tgt.saved_firmware_options_2 = |
| 6742 | nv->firmware_options_2; |
| 6743 | ha->tgt.saved_firmware_options_3 = |
| 6744 | nv->firmware_options_3; |
| 6745 | ha->tgt.saved_set = 1; |
| 6746 | } |
| 6747 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6748 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6749 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6750 | else /* dual */ |
| 6751 | nv->exchange_count = cpu_to_le16(ql2xexchoffld); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6752 | |
| 6753 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6754 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6755 | |
| 6756 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6757 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6758 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6759 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6760 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6761 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6762 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6763 | /* |
| 6764 | * clear BIT 15 explicitly as we have seen at |
| 6765 | * least a couple of instances where this was set |
| 6766 | * and this was causing the firmware to not be |
| 6767 | * initialized. |
| 6768 | */ |
| 6769 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6770 | if (ql2xtgt_tape_enable) |
| 6771 | /* Enable FC tape support */ |
| 6772 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6773 | else |
| 6774 | /* Disable FC tape support */ |
| 6775 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6776 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6777 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6778 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6779 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6780 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6781 | } else { |
| 6782 | if (ha->tgt.saved_set) { |
| 6783 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6784 | nv->firmware_options_1 = |
| 6785 | ha->tgt.saved_firmware_options_1; |
| 6786 | nv->firmware_options_2 = |
| 6787 | ha->tgt.saved_firmware_options_2; |
| 6788 | nv->firmware_options_3 = |
| 6789 | ha->tgt.saved_firmware_options_3; |
| 6790 | } |
| 6791 | return; |
| 6792 | } |
| 6793 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6794 | if (ha->base_qpair->enable_class_2) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6795 | if (vha->flags.init_done) |
| 6796 | fc_host_supported_classes(vha->host) = |
| 6797 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6798 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6799 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6800 | } else { |
| 6801 | if (vha->flags.init_done) |
| 6802 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6803 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6804 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6805 | } |
| 6806 | } |
| 6807 | |
| 6808 | void |
| 6809 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6810 | struct init_cb_81xx *icb) |
| 6811 | { |
| 6812 | struct qla_hw_data *ha = vha->hw; |
| 6813 | |
| 6814 | if (!QLA_TGT_MODE_ENABLED()) |
| 6815 | return; |
| 6816 | |
| 6817 | if (ha->tgt.node_name_set) { |
| 6818 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6819 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6820 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6821 | |
| 6822 | /* disable ZIO at start time. */ |
| 6823 | if (!vha->flags.init_done) { |
| 6824 | uint32_t tmp; |
| 6825 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6826 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6827 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6828 | } |
| 6829 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6830 | } |
| 6831 | |
| 6832 | void |
| 6833 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 6834 | { |
| 6835 | if (!QLA_TGT_MODE_ENABLED()) |
| 6836 | return; |
| 6837 | |
| 6838 | ha->msix_count += 1; /* For ATIO Q */ |
| 6839 | } |
| 6840 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6841 | |
| 6842 | void |
| 6843 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 6844 | struct vp_config_entry_24xx *vpmod) |
| 6845 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6846 | /* enable target mode. Bit5 = 1 => disable */ |
| 6847 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6848 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6849 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6850 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6851 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6852 | vpmod->options_idx1 &= ~BIT_4; |
| 6853 | } |
| 6854 | |
| 6855 | void |
| 6856 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 6857 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6858 | int rc; |
| 6859 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6860 | if (!QLA_TGT_MODE_ENABLED()) |
| 6861 | return; |
| 6862 | |
Himanshu Madhani | c955886 | 2017-10-13 09:34:04 -0700 | [diff] [blame] | 6863 | if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6864 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 6865 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 6866 | } else { |
| 6867 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 6868 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 6869 | } |
| 6870 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6871 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 6872 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6873 | |
| 6874 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 6875 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 6876 | qlt_unknown_atio_work_fn); |
| 6877 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6878 | qlt_clear_mode(base_vha); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6879 | |
| 6880 | rc = btree_init32(&ha->tgt.host_map); |
| 6881 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6882 | ql_log(ql_log_info, base_vha, 0xd03d, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6883 | "Unable to initialize ha->host_map btree\n"); |
| 6884 | |
| 6885 | qlt_update_vp_map(base_vha, SET_VP_IDX); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6886 | } |
| 6887 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6888 | irqreturn_t |
| 6889 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 6890 | { |
| 6891 | struct rsp_que *rsp; |
| 6892 | scsi_qla_host_t *vha; |
| 6893 | struct qla_hw_data *ha; |
| 6894 | unsigned long flags; |
| 6895 | |
| 6896 | rsp = (struct rsp_que *) dev_id; |
| 6897 | ha = rsp->hw; |
| 6898 | vha = pci_get_drvdata(ha->pdev); |
| 6899 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6900 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6901 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6902 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6903 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6904 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6905 | |
| 6906 | return IRQ_HANDLED; |
| 6907 | } |
| 6908 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6909 | static void |
| 6910 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 6911 | { |
| 6912 | struct qla_tgt_sess_op *op = container_of(work, |
| 6913 | struct qla_tgt_sess_op, work); |
| 6914 | scsi_qla_host_t *vha = op->vha; |
| 6915 | struct qla_hw_data *ha = vha->hw; |
| 6916 | unsigned long flags; |
| 6917 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6918 | if (qla2x00_reset_active(vha) || |
| 6919 | (op->chip_reset != ha->base_qpair->chip_reset)) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6920 | return; |
| 6921 | |
| 6922 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 6923 | qlt_24xx_process_atio_queue(vha, 0); |
| 6924 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 6925 | |
| 6926 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6927 | qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6928 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 6929 | |
| 6930 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6931 | } |
| 6932 | |
| 6933 | void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6934 | qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp, |
| 6935 | response_t *pkt) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6936 | { |
| 6937 | struct qla_tgt_sess_op *op; |
| 6938 | |
| 6939 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 6940 | |
| 6941 | if (!op) { |
| 6942 | /* do not reach for ATIO queue here. This is best effort err |
| 6943 | * recovery at this point. |
| 6944 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6945 | qlt_response_pkt_all_vps(vha, rsp, pkt); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6946 | return; |
| 6947 | } |
| 6948 | |
| 6949 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 6950 | op->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6951 | op->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6952 | op->rsp = rsp; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6953 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 6954 | queue_work(qla_tgt_wq, &op->work); |
| 6955 | return; |
| 6956 | } |
| 6957 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6958 | int |
| 6959 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 6960 | { |
| 6961 | if (!QLA_TGT_MODE_ENABLED()) |
| 6962 | return 0; |
| 6963 | |
| 6964 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * |
| 6965 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); |
| 6966 | if (!ha->tgt.tgt_vp_map) |
| 6967 | return -ENOMEM; |
| 6968 | |
| 6969 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 6970 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 6971 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 6972 | if (!ha->tgt.atio_ring) { |
| 6973 | kfree(ha->tgt.tgt_vp_map); |
| 6974 | return -ENOMEM; |
| 6975 | } |
| 6976 | return 0; |
| 6977 | } |
| 6978 | |
| 6979 | void |
| 6980 | qlt_mem_free(struct qla_hw_data *ha) |
| 6981 | { |
| 6982 | if (!QLA_TGT_MODE_ENABLED()) |
| 6983 | return; |
| 6984 | |
| 6985 | if (ha->tgt.atio_ring) { |
| 6986 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 6987 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 6988 | ha->tgt.atio_dma); |
| 6989 | } |
| 6990 | kfree(ha->tgt.tgt_vp_map); |
| 6991 | } |
| 6992 | |
| 6993 | /* vport_slock to be held by the caller */ |
| 6994 | void |
| 6995 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 6996 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6997 | void *slot; |
| 6998 | u32 key; |
| 6999 | int rc; |
| 7000 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7001 | if (!QLA_TGT_MODE_ENABLED()) |
| 7002 | return; |
| 7003 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7004 | key = vha->d_id.b24; |
| 7005 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7006 | switch (cmd) { |
| 7007 | case SET_VP_IDX: |
| 7008 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 7009 | break; |
| 7010 | case SET_AL_PA: |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7011 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7012 | if (!slot) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7013 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7014 | "Save vha in host_map %p %06x\n", vha, key); |
| 7015 | rc = btree_insert32(&vha->hw->tgt.host_map, |
| 7016 | key, vha, GFP_ATOMIC); |
| 7017 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7018 | ql_log(ql_log_info, vha, 0xd03e, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7019 | "Unable to insert s_id into host_map: %06x\n", |
| 7020 | key); |
| 7021 | return; |
| 7022 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7023 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 7024 | "replace existing vha in host_map %p %06x\n", vha, key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7025 | btree_update32(&vha->hw->tgt.host_map, key, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7026 | break; |
| 7027 | case RESET_VP_IDX: |
| 7028 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 7029 | break; |
| 7030 | case RESET_AL_PA: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7031 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7032 | "clear vha in host_map %p %06x\n", vha, key); |
| 7033 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 7034 | if (slot) |
| 7035 | btree_remove32(&vha->hw->tgt.host_map, key); |
| 7036 | vha->d_id.b24 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7037 | break; |
| 7038 | } |
| 7039 | } |
| 7040 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 7041 | void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id) |
| 7042 | { |
| 7043 | unsigned long flags; |
| 7044 | struct qla_hw_data *ha = vha->hw; |
| 7045 | |
| 7046 | if (!vha->d_id.b24) { |
| 7047 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7048 | vha->d_id = id; |
| 7049 | qlt_update_vp_map(vha, SET_AL_PA); |
| 7050 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7051 | } else if (vha->d_id.b24 != id.b24) { |
| 7052 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7053 | qlt_update_vp_map(vha, RESET_AL_PA); |
| 7054 | vha->d_id = id; |
| 7055 | qlt_update_vp_map(vha, SET_AL_PA); |
| 7056 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7057 | } |
| 7058 | } |
| 7059 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7060 | static int __init qlt_parse_ini_mode(void) |
| 7061 | { |
| 7062 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 7063 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 7064 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 7065 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 7066 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 7067 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7068 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 7069 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7070 | else |
| 7071 | return false; |
| 7072 | |
| 7073 | return true; |
| 7074 | } |
| 7075 | |
| 7076 | int __init qlt_init(void) |
| 7077 | { |
| 7078 | int ret; |
| 7079 | |
| 7080 | if (!qlt_parse_ini_mode()) { |
| 7081 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 7082 | "qlt_parse_ini_mode() failed\n"); |
| 7083 | return -EINVAL; |
| 7084 | } |
| 7085 | |
| 7086 | if (!QLA_TGT_MODE_ENABLED()) |
| 7087 | return 0; |
| 7088 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7089 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 7090 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 7091 | qla_tgt_mgmt_cmd), 0, NULL); |
| 7092 | if (!qla_tgt_mgmt_cmd_cachep) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7093 | ql_log(ql_log_fatal, NULL, 0xd04b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7094 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 7095 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7096 | } |
| 7097 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7098 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 7099 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 7100 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7101 | |
| 7102 | if (!qla_tgt_plogi_cachep) { |
| 7103 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 7104 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 7105 | ret = -ENOMEM; |
| 7106 | goto out_mgmt_cmd_cachep; |
| 7107 | } |
| 7108 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7109 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 7110 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 7111 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 7112 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 7113 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 7114 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7115 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7116 | } |
| 7117 | |
| 7118 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 7119 | if (!qla_tgt_wq) { |
| 7120 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 7121 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 7122 | ret = -ENOMEM; |
| 7123 | goto out_cmd_mempool; |
| 7124 | } |
| 7125 | /* |
| 7126 | * Return 1 to signal that initiator-mode is being disabled |
| 7127 | */ |
| 7128 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 7129 | |
| 7130 | out_cmd_mempool: |
| 7131 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7132 | out_plogi_cachep: |
| 7133 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7134 | out_mgmt_cmd_cachep: |
| 7135 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7136 | return ret; |
| 7137 | } |
| 7138 | |
| 7139 | void qlt_exit(void) |
| 7140 | { |
| 7141 | if (!QLA_TGT_MODE_ENABLED()) |
| 7142 | return; |
| 7143 | |
| 7144 | destroy_workqueue(qla_tgt_wq); |
| 7145 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7146 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7147 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7148 | } |