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__); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 453 | case CTIO_TYPE7: |
| 454 | { |
| 455 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 456 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 457 | entry->vp_index); |
| 458 | if (unlikely(!host)) { |
| 459 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 460 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 461 | "received, with unknown vp_index %d\n", |
| 462 | vha->vp_idx, entry->vp_index); |
| 463 | break; |
| 464 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 465 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 466 | break; |
| 467 | } |
| 468 | |
| 469 | case IMMED_NOTIFY_TYPE: |
| 470 | { |
| 471 | struct scsi_qla_host *host = vha; |
| 472 | struct imm_ntfy_from_isp *entry = |
| 473 | (struct imm_ntfy_from_isp *)pkt; |
| 474 | |
| 475 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 476 | if (unlikely(!host)) { |
| 477 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 478 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 479 | "received, with unknown vp_index %d\n", |
| 480 | vha->vp_idx, entry->u.isp24.vp_index); |
| 481 | break; |
| 482 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 483 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 484 | break; |
| 485 | } |
| 486 | |
| 487 | case NOTIFY_ACK_TYPE: |
| 488 | { |
| 489 | struct scsi_qla_host *host = vha; |
| 490 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 491 | |
| 492 | if (0xFF != entry->u.isp24.vp_index) { |
| 493 | host = qlt_find_host_by_vp_idx(vha, |
| 494 | entry->u.isp24.vp_index); |
| 495 | if (unlikely(!host)) { |
| 496 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 497 | "qla_target(%d): Response " |
| 498 | "pkt (NOTIFY_ACK_TYPE) " |
| 499 | "received, with unknown " |
| 500 | "vp_index %d\n", vha->vp_idx, |
| 501 | entry->u.isp24.vp_index); |
| 502 | break; |
| 503 | } |
| 504 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 505 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 506 | break; |
| 507 | } |
| 508 | |
| 509 | case ABTS_RECV_24XX: |
| 510 | { |
| 511 | struct abts_recv_from_24xx *entry = |
| 512 | (struct abts_recv_from_24xx *)pkt; |
| 513 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 514 | entry->vp_index); |
| 515 | if (unlikely(!host)) { |
| 516 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 517 | "qla_target(%d): Response pkt " |
| 518 | "(ABTS_RECV_24XX) received, with unknown " |
| 519 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 520 | break; |
| 521 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 522 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 523 | break; |
| 524 | } |
| 525 | |
| 526 | case ABTS_RESP_24XX: |
| 527 | { |
| 528 | struct abts_resp_to_24xx *entry = |
| 529 | (struct abts_resp_to_24xx *)pkt; |
| 530 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 531 | entry->vp_index); |
| 532 | if (unlikely(!host)) { |
| 533 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 534 | "qla_target(%d): Response pkt " |
| 535 | "(ABTS_RECV_24XX) received, with unknown " |
| 536 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 537 | break; |
| 538 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 539 | qlt_response_pkt(host, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 540 | break; |
| 541 | } |
| 542 | |
| 543 | default: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 544 | qlt_response_pkt(vha, rsp, pkt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 545 | break; |
| 546 | } |
| 547 | |
| 548 | } |
| 549 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 550 | /* |
| 551 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 552 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 553 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 554 | struct imm_ntfy_from_isp *ntfy, int type) |
| 555 | { |
| 556 | struct qla_work_evt *e; |
| 557 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 558 | if (!e) |
| 559 | return QLA_FUNCTION_FAILED; |
| 560 | |
| 561 | e->u.nack.fcport = fcport; |
| 562 | e->u.nack.type = type; |
| 563 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 564 | return qla2x00_post_work(vha, e); |
| 565 | } |
| 566 | |
| 567 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 568 | void qla2x00_async_nack_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 569 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 570 | struct srb *sp = (struct srb *)s; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 571 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 572 | unsigned long flags; |
| 573 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 574 | ql_dbg(ql_dbg_disc, vha, 0x20f2, |
| 575 | "Async done-%s res %x %8phC type %d\n", |
| 576 | sp->name, res, sp->fcport->port_name, sp->type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 577 | |
| 578 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 579 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 580 | sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 581 | |
| 582 | switch (sp->type) { |
| 583 | case SRB_NACK_PLOGI: |
| 584 | sp->fcport->login_gen++; |
| 585 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 586 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 587 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 588 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 589 | break; |
| 590 | |
| 591 | case SRB_NACK_PRLI: |
| 592 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 593 | sp->fcport->deleted = 0; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 594 | sp->fcport->send_els_logo = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 595 | |
| 596 | if (!sp->fcport->login_succ && |
| 597 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 598 | sp->fcport->login_succ = 1; |
| 599 | |
| 600 | vha->fcport_count++; |
| 601 | |
| 602 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 603 | !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 604 | ql_dbg(ql_dbg_disc, vha, 0x20f3, |
| 605 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 606 | __func__, __LINE__, |
| 607 | sp->fcport->port_name, |
| 608 | vha->fcport_count); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 609 | |
| 610 | qla24xx_post_upd_fcport_work(vha, sp->fcport); |
| 611 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 612 | ql_dbg(ql_dbg_disc, vha, 0x20f5, |
| 613 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 614 | __func__, __LINE__, |
| 615 | sp->fcport->port_name, |
| 616 | vha->fcport_count); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 617 | |
| 618 | qla24xx_post_gpsc_work(vha, sp->fcport); |
| 619 | } |
| 620 | } |
| 621 | break; |
| 622 | |
| 623 | case SRB_NACK_LOGO: |
| 624 | sp->fcport->login_gen++; |
| 625 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 626 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 627 | break; |
| 628 | } |
| 629 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 630 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 631 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 635 | struct imm_ntfy_from_isp *ntfy, int type) |
| 636 | { |
| 637 | int rval = QLA_FUNCTION_FAILED; |
| 638 | srb_t *sp; |
| 639 | char *c = NULL; |
| 640 | |
| 641 | fcport->flags |= FCF_ASYNC_SENT; |
| 642 | switch (type) { |
| 643 | case SRB_NACK_PLOGI: |
| 644 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 645 | c = "PLOGI"; |
| 646 | break; |
| 647 | case SRB_NACK_PRLI: |
| 648 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 649 | fcport->deleted = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 650 | c = "PRLI"; |
| 651 | break; |
| 652 | case SRB_NACK_LOGO: |
| 653 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 654 | c = "LOGO"; |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 659 | if (!sp) |
| 660 | goto done; |
| 661 | |
| 662 | sp->type = type; |
| 663 | sp->name = "nack"; |
| 664 | |
| 665 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 666 | |
| 667 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
Quinn Tran | 2e01d0b | 2017-12-04 14:44:56 -0800 | [diff] [blame] | 668 | sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 669 | sp->done = qla2x00_async_nack_sp_done; |
| 670 | |
| 671 | rval = qla2x00_start_sp(sp); |
| 672 | if (rval != QLA_SUCCESS) |
| 673 | goto done_free_sp; |
| 674 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 675 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
| 676 | "Async-%s %8phC hndl %x %s\n", |
| 677 | sp->name, fcport->port_name, sp->handle, c); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 678 | |
| 679 | return rval; |
| 680 | |
| 681 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 682 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 683 | done: |
| 684 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 685 | return rval; |
| 686 | } |
| 687 | |
| 688 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 689 | { |
| 690 | fc_port_t *t; |
| 691 | unsigned long flags; |
| 692 | |
| 693 | switch (e->u.nack.type) { |
| 694 | case SRB_NACK_PRLI: |
| 695 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 696 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 697 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 698 | if (t) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 699 | ql_log(ql_log_info, vha, 0xd034, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 700 | "%s create sess success %p", __func__, t); |
| 701 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 702 | /* create sess has an extra kref */ |
| 703 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
| 704 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 705 | } |
| 706 | break; |
| 707 | } |
| 708 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
| 709 | (struct imm_ntfy_from_isp*)e->u.nack.iocb, e->u.nack.type); |
| 710 | } |
| 711 | |
| 712 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 713 | { |
| 714 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 715 | struct qla_hw_data *ha = fcport->vha->hw; |
| 716 | unsigned long flags; |
| 717 | |
| 718 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 719 | |
| 720 | if (fcport->se_sess) { |
| 721 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 722 | ha->tgt.tgt_ops->put_sess(fcport); |
| 723 | } else { |
| 724 | qlt_unreg_sess(fcport); |
| 725 | } |
| 726 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 727 | } |
| 728 | |
| 729 | /* |
| 730 | * Called from qla2x00_reg_remote_port() |
| 731 | */ |
| 732 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 733 | { |
| 734 | struct qla_hw_data *ha = vha->hw; |
| 735 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 736 | struct fc_port *sess = fcport; |
| 737 | unsigned long flags; |
| 738 | |
| 739 | if (!vha->hw->tgt.tgt_ops) |
| 740 | return; |
| 741 | |
| 742 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 743 | if (tgt->tgt_stop) { |
| 744 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 749 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | if (!sess->se_sess) { |
| 754 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 755 | |
| 756 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 757 | sess = qlt_create_sess(vha, fcport, false); |
| 758 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 759 | |
| 760 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 761 | } else { |
| 762 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 763 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 764 | return; |
| 765 | } |
| 766 | |
| 767 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 768 | ql_dbg(ql_dbg_disc, vha, 0x2107, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 769 | "%s: kref_get fail sess %8phC \n", |
| 770 | __func__, sess->port_name); |
| 771 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 772 | return; |
| 773 | } |
| 774 | |
| 775 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 776 | "qla_target(%u): %ssession for port %8phC " |
| 777 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 778 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 779 | |
| 780 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 781 | "Reappeared sess %p\n", sess); |
| 782 | |
| 783 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 784 | fcport->loop_id, |
| 785 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 786 | } |
| 787 | |
| 788 | if (sess && sess->local) { |
| 789 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 790 | "qla_target(%u): local session for " |
| 791 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 792 | fcport->port_name, sess->loop_id); |
| 793 | sess->local = 0; |
| 794 | } |
| 795 | ha->tgt.tgt_ops->put_sess(sess); |
| 796 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 797 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * This is a zero-base ref-counting solution, since hardware_lock |
| 801 | * guarantees that ref_count is not modified concurrently. |
| 802 | * Upon successful return content of iocb is undefined |
| 803 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 804 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 805 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 806 | struct imm_ntfy_from_isp *iocb) |
| 807 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 808 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 809 | |
| 810 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 811 | if (pla->id.b24 == id->b24) { |
| 812 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 813 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 814 | return pla; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 819 | if (!pla) { |
| 820 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 821 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 822 | vha->vp_idx); |
| 823 | return NULL; |
| 824 | } |
| 825 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 826 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 827 | pla->id = *id; |
| 828 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 829 | |
| 830 | return pla; |
| 831 | } |
| 832 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 833 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 834 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 835 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 836 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 837 | port_id_t port_id; |
| 838 | uint16_t loop_id; |
| 839 | fc_port_t *fcport = pla->fcport; |
| 840 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 841 | BUG_ON(!pla->ref_count); |
| 842 | pla->ref_count--; |
| 843 | |
| 844 | if (pla->ref_count) |
| 845 | return; |
| 846 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 847 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 848 | "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] | 849 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 850 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 851 | iocb->u.isp24.port_id[0], |
| 852 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 853 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 854 | |
| 855 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 856 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 857 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 858 | port_id.b.rsvd_1 = 0; |
| 859 | |
| 860 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 861 | |
| 862 | fcport->loop_id = loop_id; |
| 863 | fcport->d_id = port_id; |
| 864 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 865 | |
| 866 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 867 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 868 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 869 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 870 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 871 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 872 | |
| 873 | list_del(&pla->list); |
| 874 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 875 | } |
| 876 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 877 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 878 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 879 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 880 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 881 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 882 | /* Inc ref_count first because link might already be pointing at pla */ |
| 883 | pla->ref_count++; |
| 884 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 885 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 886 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 887 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 888 | sess, link, sess->port_name, |
| 889 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 890 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 891 | pla->ref_count, pla, link); |
| 892 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 893 | if (sess->plogi_link[link]) |
| 894 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 895 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 896 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 897 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 898 | |
| 899 | sess->plogi_link[link] = pla; |
| 900 | } |
| 901 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 902 | typedef struct { |
| 903 | /* These fields must be initialized by the caller */ |
| 904 | port_id_t id; |
| 905 | /* |
| 906 | * number of cmds dropped while we were waiting for |
| 907 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 908 | * triggered by a command, otherwise, to 0 |
| 909 | */ |
| 910 | int cmd_count; |
| 911 | |
| 912 | /* These fields are used by callee */ |
| 913 | struct list_head list; |
| 914 | } qlt_port_logo_t; |
| 915 | |
| 916 | static void |
| 917 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 918 | { |
| 919 | qlt_port_logo_t *tmp; |
| 920 | int res; |
| 921 | |
| 922 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 923 | |
| 924 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 925 | if (tmp->id.b24 == logo->id.b24) { |
| 926 | tmp->cmd_count += logo->cmd_count; |
| 927 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 928 | return; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | list_add_tail(&logo->list, &vha->logo_list); |
| 933 | |
| 934 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 935 | |
| 936 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 937 | |
| 938 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 939 | list_del(&logo->list); |
| 940 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 941 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 942 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 943 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 944 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 945 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 946 | } |
| 947 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 948 | static void qlt_free_session_done(struct work_struct *work) |
| 949 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 950 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 951 | free_work); |
| 952 | struct qla_tgt *tgt = sess->tgt; |
| 953 | struct scsi_qla_host *vha = sess->vha; |
| 954 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 955 | unsigned long flags; |
| 956 | bool logout_started = false; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 957 | struct event_arg ea; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 958 | scsi_qla_host_t *base_vha; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 959 | |
| 960 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 961 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 962 | " 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] | 963 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 964 | 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] | 965 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 966 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 967 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 968 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 969 | if (sess->send_els_logo) { |
| 970 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 971 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 972 | logo.id = sess->d_id; |
| 973 | logo.cmd_count = 0; |
| 974 | qlt_send_first_logo(vha, &logo); |
| 975 | } |
| 976 | |
| 977 | if (sess->logout_on_delete) { |
| 978 | int rc; |
| 979 | |
| 980 | rc = qla2x00_post_async_logout_work(vha, sess, NULL); |
| 981 | if (rc != QLA_SUCCESS) |
| 982 | ql_log(ql_log_warn, vha, 0xf085, |
| 983 | "Schedule logo failed sess %p rc %d\n", |
| 984 | sess, rc); |
| 985 | else |
| 986 | logout_started = true; |
| 987 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 988 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 989 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 990 | /* |
| 991 | * Release the target session for FC Nexus from fabric module code. |
| 992 | */ |
| 993 | if (sess->se_sess != NULL) |
| 994 | ha->tgt.tgt_ops->free_session(sess); |
| 995 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 996 | if (logout_started) { |
| 997 | bool traced = false; |
| 998 | |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 999 | while (!READ_ONCE(sess->logout_completed)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1000 | if (!traced) { |
| 1001 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 1002 | "%s: waiting for sess %p logout\n", |
| 1003 | __func__, sess); |
| 1004 | traced = true; |
| 1005 | } |
| 1006 | msleep(100); |
| 1007 | } |
| 1008 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1009 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1010 | "%s: sess %p logout completed\n",__func__, sess); |
| 1011 | } |
| 1012 | |
| 1013 | if (sess->logo_ack_needed) { |
| 1014 | sess->logo_ack_needed = 0; |
| 1015 | qla24xx_async_notify_ack(vha, sess, |
| 1016 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1017 | } |
| 1018 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1019 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1020 | if (sess->se_sess) { |
| 1021 | sess->se_sess = NULL; |
| 1022 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 1023 | tgt->sess_count--; |
| 1024 | } |
| 1025 | |
| 1026 | sess->disc_state = DSC_DELETED; |
| 1027 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1028 | sess->deleted = QLA_SESS_DELETED; |
| 1029 | sess->login_retry = vha->hw->login_retry_count; |
| 1030 | |
| 1031 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1032 | vha->fcport_count--; |
| 1033 | sess->login_succ = 0; |
| 1034 | } |
| 1035 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1036 | if (sess->chip_reset != ha->base_qpair->chip_reset) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1037 | qla2x00_clear_loop_id(sess); |
| 1038 | |
| 1039 | if (sess->conflict) { |
| 1040 | sess->conflict->login_pause = 0; |
| 1041 | sess->conflict = NULL; |
| 1042 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1043 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1044 | } |
| 1045 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1046 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1047 | struct qlt_plogi_ack_t *own = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1048 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1049 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1050 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1051 | struct imm_ntfy_from_isp *iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1052 | |
| 1053 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1054 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1055 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1056 | "se_sess %p / sess %p port %8phC is gone," |
| 1057 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1058 | sess->se_sess, sess, sess->port_name, |
| 1059 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1060 | own ? own->ref_count : -1, |
| 1061 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1062 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1063 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1064 | } else { |
| 1065 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1066 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1067 | sess->se_sess, sess, sess->port_name, |
| 1068 | own ? "releasing own PLOGI" : |
| 1069 | "no own PLOGI pending", |
| 1070 | own ? own->ref_count : -1); |
| 1071 | } |
| 1072 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1073 | if (own) { |
| 1074 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1075 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1076 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1077 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1078 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1079 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1080 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1081 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1082 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1083 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1084 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1085 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1086 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1087 | |
| 1088 | if (vha->fcport_count == 0) |
| 1089 | wake_up_all(&vha->fcport_waitQ); |
| 1090 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1091 | base_vha = pci_get_drvdata(ha->pdev); |
| 1092 | if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags)) |
| 1093 | return; |
| 1094 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1095 | if (!tgt || !tgt->tgt_stop) { |
| 1096 | memset(&ea, 0, sizeof(ea)); |
| 1097 | ea.event = FCME_DELETE_DONE; |
| 1098 | ea.fcport = sess; |
| 1099 | qla2x00_fcport_event_handler(vha, &ea); |
| 1100 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1103 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1104 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1105 | { |
| 1106 | struct scsi_qla_host *vha = sess->vha; |
| 1107 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1108 | ql_dbg(ql_dbg_disc, sess->vha, 0x210a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1109 | "%s sess %p for deletion %8phC\n", |
| 1110 | __func__, sess, sess->port_name); |
| 1111 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1112 | if (sess->se_sess) |
| 1113 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1114 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1115 | qla2x00_mark_device_lost(vha, sess, 1, 1); |
| 1116 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1117 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1118 | sess->disc_state = DSC_DELETE_PEND; |
| 1119 | sess->last_rscn_gen = sess->rscn_gen; |
| 1120 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1121 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1122 | if (sess->nvme_flag & NVME_FLAG_REGISTERED) |
| 1123 | schedule_work(&sess->nvme_del_work); |
| 1124 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1125 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 1126 | schedule_work(&sess->free_work); |
| 1127 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1128 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1129 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1130 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1131 | { |
| 1132 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1133 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1134 | uint16_t loop_id; |
| 1135 | int res = 0; |
| 1136 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1137 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1138 | |
| 1139 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1140 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1141 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1142 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1143 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1144 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1145 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1146 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1147 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1148 | 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] | 1149 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1153 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1154 | if (!sess) { |
| 1155 | res = -ESRCH; |
| 1156 | return res; |
| 1157 | } |
| 1158 | |
| 1159 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1160 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1161 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1162 | mcmd, loop_id); |
| 1163 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1164 | 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] | 1165 | } |
| 1166 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1167 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1168 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1169 | if (sess->chip_reset != sess->vha->hw->base_qpair->chip_reset) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1170 | sess->logout_on_delete = 0; |
| 1171 | sess->logo_ack_needed = 0; |
| 1172 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1173 | sess->scan_state = 0; |
| 1174 | } |
| 1175 | } |
| 1176 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1177 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1178 | void qlt_schedule_sess_for_deletion(struct fc_port *sess, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1179 | bool immediate) |
| 1180 | { |
| 1181 | struct qla_tgt *tgt = sess->tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1182 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1183 | if (sess->disc_state == DSC_DELETE_PEND) |
| 1184 | return; |
| 1185 | |
| 1186 | if (sess->disc_state == DSC_DELETED) { |
| 1187 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1188 | wake_up_all(&tgt->waitQ); |
| 1189 | if (sess->vha->fcport_count == 0) |
| 1190 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1191 | |
| 1192 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1193 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1194 | return; |
| 1195 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1196 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1197 | sess->disc_state = DSC_DELETE_PEND; |
| 1198 | |
| 1199 | if (sess->deleted == QLA_SESS_DELETED) |
| 1200 | sess->logout_on_delete = 0; |
| 1201 | |
| 1202 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
| 1203 | qla24xx_chk_fcp_state(sess); |
| 1204 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1205 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
| 1206 | "Scheduling sess %p for deletion\n", sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1207 | |
Quinn Tran | a01c77d | 2017-12-04 14:44:58 -0800 | [diff] [blame] | 1208 | INIT_WORK(&sess->del_work, qla24xx_delete_sess_fn); |
| 1209 | queue_work(sess->vha->hw->wq, &sess->del_work); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1210 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1211 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1212 | void qlt_schedule_sess_for_deletion_lock(struct fc_port *sess) |
| 1213 | { |
| 1214 | unsigned long flags; |
| 1215 | struct qla_hw_data *ha = sess->vha->hw; |
| 1216 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1217 | qlt_schedule_sess_for_deletion(sess, 1); |
| 1218 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1219 | } |
| 1220 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1221 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1222 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1223 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1224 | struct fc_port *sess; |
| 1225 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1226 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1227 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1228 | if (sess->se_sess) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1229 | qlt_schedule_sess_for_deletion(sess, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1230 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1231 | |
| 1232 | /* At this point tgt could be already dead */ |
| 1233 | } |
| 1234 | |
| 1235 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 1236 | uint16_t *loop_id) |
| 1237 | { |
| 1238 | struct qla_hw_data *ha = vha->hw; |
| 1239 | dma_addr_t gid_list_dma; |
| 1240 | struct gid_list_info *gid_list; |
| 1241 | char *id_iter; |
| 1242 | int res, rc, i; |
| 1243 | uint16_t entries; |
| 1244 | |
| 1245 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1246 | &gid_list_dma, GFP_KERNEL); |
| 1247 | if (!gid_list) { |
| 1248 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1249 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1250 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1251 | return -ENOMEM; |
| 1252 | } |
| 1253 | |
| 1254 | /* Get list of logged in devices */ |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1255 | rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1256 | if (rc != QLA_SUCCESS) { |
| 1257 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1258 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1259 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1260 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1261 | goto out_free_id_list; |
| 1262 | } |
| 1263 | |
| 1264 | id_iter = (char *)gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1265 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1266 | for (i = 0; i < entries; i++) { |
| 1267 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; |
| 1268 | if ((gid->al_pa == s_id[2]) && |
| 1269 | (gid->area == s_id[1]) && |
| 1270 | (gid->domain == s_id[0])) { |
| 1271 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1272 | res = 0; |
| 1273 | break; |
| 1274 | } |
| 1275 | id_iter += ha->gid_list_info_size; |
| 1276 | } |
| 1277 | |
| 1278 | out_free_id_list: |
| 1279 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1280 | gid_list, gid_list_dma); |
| 1281 | return res; |
| 1282 | } |
| 1283 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1284 | /* |
| 1285 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1286 | * Caller must put it. |
| 1287 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1288 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1289 | struct scsi_qla_host *vha, |
| 1290 | fc_port_t *fcport, |
| 1291 | bool local) |
| 1292 | { |
| 1293 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1294 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1295 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1296 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1297 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1298 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1299 | |
| 1300 | if (fcport->se_sess) { |
| 1301 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1302 | ql_dbg(ql_dbg_disc, vha, 0x20f6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1303 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1304 | __func__, sess->port_name); |
| 1305 | return NULL; |
| 1306 | } |
| 1307 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1308 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1309 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1310 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1311 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1312 | /* |
| 1313 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1314 | * session eventually ends and release corresponding nport handle. |
| 1315 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1316 | * code will adjust these flags as necessary. |
| 1317 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1318 | sess->logout_on_delete = 1; |
| 1319 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1320 | sess->logout_completed = 0; |
| 1321 | |
| 1322 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1323 | &fcport->port_name[0], sess) < 0) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1324 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1325 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1326 | vha->vp_idx, fcport->port_name); |
| 1327 | return NULL; |
| 1328 | } else { |
| 1329 | kref_init(&fcport->sess_kref); |
| 1330 | /* |
| 1331 | * Take an extra reference to ->sess_kref here to handle |
| 1332 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1333 | */ |
| 1334 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1335 | ql_dbg(ql_dbg_disc, vha, 0x20f7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1336 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1337 | __func__, sess->port_name); |
| 1338 | return NULL; |
| 1339 | } |
| 1340 | |
| 1341 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1342 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1343 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1344 | |
| 1345 | qlt_do_generation_tick(vha, &sess->generation); |
| 1346 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1347 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1348 | |
| 1349 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1350 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1351 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1352 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1353 | |
| 1354 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1355 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1356 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1357 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1358 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1359 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1360 | |
| 1361 | return sess; |
| 1362 | } |
| 1363 | |
| 1364 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1365 | * max_gen - specifies maximum session generation |
| 1366 | * at which this deletion requestion is still valid |
| 1367 | */ |
| 1368 | void |
| 1369 | 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] | 1370 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1371 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1372 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1373 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1374 | |
| 1375 | if (!vha->hw->tgt.tgt_ops) |
| 1376 | return; |
| 1377 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1378 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1379 | return; |
| 1380 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1381 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1382 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1383 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1384 | return; |
| 1385 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1386 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1387 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1388 | return; |
| 1389 | } |
| 1390 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1391 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1392 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1393 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1394 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1395 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1396 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1397 | sess->generation); |
| 1398 | return; |
| 1399 | } |
| 1400 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1401 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1402 | |
| 1403 | sess->local = 1; |
| 1404 | qlt_schedule_sess_for_deletion(sess, false); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1405 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1409 | { |
| 1410 | struct qla_hw_data *ha = tgt->ha; |
| 1411 | unsigned long flags; |
| 1412 | int res; |
| 1413 | /* |
| 1414 | * We need to protect against race, when tgt is freed before or |
| 1415 | * inside wake_up() |
| 1416 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1417 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1418 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1419 | "tgt %p, sess_count=%d\n", |
| 1420 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1421 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1422 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1423 | |
| 1424 | return res; |
| 1425 | } |
| 1426 | |
| 1427 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1428 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1429 | { |
| 1430 | struct scsi_qla_host *vha = tgt->vha; |
| 1431 | struct qla_hw_data *ha = tgt->ha; |
| 1432 | unsigned long flags; |
| 1433 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1434 | mutex_lock(&qla_tgt_mutex); |
| 1435 | if (!vha->fc_vport) { |
| 1436 | struct Scsi_Host *sh = vha->host; |
| 1437 | struct fc_host_attrs *fc_host = shost_to_fc_host(sh); |
| 1438 | bool npiv_vports; |
| 1439 | |
| 1440 | spin_lock_irqsave(sh->host_lock, flags); |
| 1441 | npiv_vports = (fc_host->npiv_vports_inuse); |
| 1442 | spin_unlock_irqrestore(sh->host_lock, flags); |
| 1443 | |
| 1444 | if (npiv_vports) { |
| 1445 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1446 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, |
| 1447 | "NPIV is in use. Can not stop target\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1448 | return -EPERM; |
| 1449 | } |
| 1450 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1451 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1452 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1453 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1454 | mutex_unlock(&qla_tgt_mutex); |
| 1455 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1456 | } |
| 1457 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1458 | 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] | 1459 | vha->host_no, vha); |
| 1460 | /* |
| 1461 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1462 | * Lock is needed, because we still can get an incoming packet. |
| 1463 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1464 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1465 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1466 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1467 | qlt_clear_tgt_db(tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1468 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1469 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1470 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1471 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1472 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1473 | "Waiting for sess works (tgt %p)", tgt); |
| 1474 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1475 | while (!list_empty(&tgt->sess_works_list)) { |
| 1476 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1477 | flush_scheduled_work(); |
| 1478 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1479 | } |
| 1480 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1481 | |
| 1482 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1483 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1484 | |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1485 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1486 | |
| 1487 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1488 | if (!ha->flags.host_shutting_down && |
| 1489 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1490 | qlt_disable_vha(vha); |
| 1491 | |
| 1492 | /* Wait for sessions to clear out (just in case) */ |
Joe Carnuccio | b85e095 | 2017-08-23 15:05:11 -0700 | [diff] [blame] | 1493 | wait_event_timeout(tgt->waitQ, test_tgt_sess_count(tgt), 10*HZ); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1494 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1495 | } |
| 1496 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1497 | |
| 1498 | /* Called by tcm_qla2xxx configfs code */ |
| 1499 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1500 | { |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1501 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1502 | |
| 1503 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1504 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1505 | "Already in tgt->tgt_stopped state\n"); |
| 1506 | dump_stack(); |
| 1507 | return; |
| 1508 | } |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1509 | if (!tgt->tgt_stop) { |
| 1510 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
| 1511 | "%s: phase1 stop is not completed\n", __func__); |
| 1512 | dump_stack(); |
| 1513 | return; |
| 1514 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1515 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1516 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1517 | tgt->tgt_stop = 0; |
| 1518 | tgt->tgt_stopped = 1; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1519 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1520 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1521 | 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] | 1522 | tgt); |
| 1523 | } |
| 1524 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1525 | |
| 1526 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1527 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1528 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1529 | scsi_qla_host_t *vha = tgt->vha; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1530 | void *node; |
| 1531 | u64 key = 0; |
| 1532 | u16 i; |
| 1533 | struct qla_qpair_hint *h; |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1534 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1535 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1536 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stop && |
| 1537 | !tgt->tgt_stopped) |
| 1538 | qlt_stop_phase1(tgt); |
| 1539 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1540 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1541 | qlt_stop_phase2(tgt); |
| 1542 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1543 | for (i = 0; i < vha->hw->max_qpairs + 1; i++) { |
| 1544 | unsigned long flags; |
| 1545 | |
| 1546 | h = &tgt->qphints[i]; |
| 1547 | if (h->qpair) { |
| 1548 | spin_lock_irqsave(h->qpair->qp_lock_ptr, flags); |
| 1549 | list_del(&h->hint_elem); |
| 1550 | spin_unlock_irqrestore(h->qpair->qp_lock_ptr, flags); |
| 1551 | h->qpair = NULL; |
| 1552 | } |
| 1553 | } |
| 1554 | kfree(tgt->qphints); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1555 | mutex_lock(&qla_tgt_mutex); |
| 1556 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
| 1557 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 1558 | |
| 1559 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 1560 | btree_remove64(&tgt->lun_qpair_map, key); |
| 1561 | |
| 1562 | btree_destroy64(&tgt->lun_qpair_map); |
| 1563 | |
Sawan Chandak | 3be63b1e | 2017-12-04 14:45:04 -0800 | [diff] [blame^] | 1564 | if (vha->vp_idx) |
| 1565 | if (ha->tgt.tgt_ops && |
| 1566 | ha->tgt.tgt_ops->remove_target && |
| 1567 | vha->vha_tgt.target_lport_ptr) |
| 1568 | ha->tgt.tgt_ops->remove_target(vha); |
Quinn Tran | bdbe24d | 2017-08-23 15:05:18 -0700 | [diff] [blame] | 1569 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1570 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1571 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1572 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1573 | "Release of tgt %p finished\n", tgt); |
| 1574 | |
| 1575 | kfree(tgt); |
| 1576 | } |
| 1577 | |
| 1578 | /* ha->hardware_lock supposed to be held on entry */ |
| 1579 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1580 | const void *param, unsigned int param_size) |
| 1581 | { |
| 1582 | struct qla_tgt_sess_work_param *prm; |
| 1583 | unsigned long flags; |
| 1584 | |
| 1585 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1586 | if (!prm) { |
| 1587 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1588 | "qla_target(%d): Unable to create session " |
| 1589 | "work, command will be refused", 0); |
| 1590 | return -ENOMEM; |
| 1591 | } |
| 1592 | |
| 1593 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1594 | "Scheduling work (type %d, prm %p)" |
| 1595 | " to find session for param %p (size %d, tgt %p)\n", |
| 1596 | type, prm, param, param_size, tgt); |
| 1597 | |
| 1598 | prm->type = type; |
| 1599 | memcpy(&prm->tm_iocb, param, param_size); |
| 1600 | |
| 1601 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1602 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1603 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1604 | |
| 1605 | schedule_work(&tgt->sess_work); |
| 1606 | |
| 1607 | return 0; |
| 1608 | } |
| 1609 | |
| 1610 | /* |
| 1611 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1612 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1613 | static void qlt_send_notify_ack(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1614 | struct imm_ntfy_from_isp *ntfy, |
| 1615 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1616 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1617 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1618 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1619 | struct qla_hw_data *ha = vha->hw; |
| 1620 | request_t *pkt; |
| 1621 | struct nack_to_isp *nack; |
| 1622 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 1623 | if (!ha->flags.fw_started) |
| 1624 | return; |
| 1625 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1626 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1627 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1628 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1629 | if (!pkt) { |
| 1630 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1631 | "qla_target(%d): %s failed: unable to allocate " |
| 1632 | "request packet\n", vha->vp_idx, __func__); |
| 1633 | return; |
| 1634 | } |
| 1635 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1636 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1637 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1638 | |
| 1639 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1640 | pkt->entry_count = 1; |
| 1641 | |
| 1642 | nack = (struct nack_to_isp *)pkt; |
| 1643 | nack->ox_id = ntfy->ox_id; |
| 1644 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1645 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1646 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1647 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1648 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1649 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1650 | } |
| 1651 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1652 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1653 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1654 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1655 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1656 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1657 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1658 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1659 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1660 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1661 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1662 | |
| 1663 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1664 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1665 | vha->vp_idx, nack->u.isp24.status); |
| 1666 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1667 | /* Memory Barrier */ |
| 1668 | wmb(); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1669 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | /* |
| 1673 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1674 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1675 | static void qlt_24xx_send_abts_resp(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1676 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1677 | bool ids_reversed) |
| 1678 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1679 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1680 | struct qla_hw_data *ha = vha->hw; |
| 1681 | struct abts_resp_to_24xx *resp; |
| 1682 | uint32_t f_ctl; |
| 1683 | uint8_t *p; |
| 1684 | |
| 1685 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1686 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1687 | ha, abts, status); |
| 1688 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1689 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(qpair, |
| 1690 | NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1691 | if (!resp) { |
| 1692 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1693 | "qla_target(%d): %s failed: unable to allocate " |
| 1694 | "request packet", vha->vp_idx, __func__); |
| 1695 | return; |
| 1696 | } |
| 1697 | |
| 1698 | resp->entry_type = ABTS_RESP_24XX; |
| 1699 | resp->entry_count = 1; |
| 1700 | resp->nport_handle = abts->nport_handle; |
| 1701 | resp->vp_index = vha->vp_idx; |
| 1702 | resp->sof_type = abts->sof_type; |
| 1703 | resp->exchange_address = abts->exchange_address; |
| 1704 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1705 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1706 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1707 | F_CTL_SEQ_INITIATIVE); |
| 1708 | p = (uint8_t *)&f_ctl; |
| 1709 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1710 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1711 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1712 | if (ids_reversed) { |
| 1713 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1714 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1715 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1716 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1717 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1718 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1719 | } else { |
| 1720 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1721 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1722 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1723 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1724 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1725 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1726 | } |
| 1727 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1728 | if (status == FCP_TMF_CMPL) { |
| 1729 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1730 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1731 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1732 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1733 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1734 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1735 | } else { |
| 1736 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1737 | resp->payload.ba_rjt.reason_code = |
| 1738 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1739 | /* Other bytes are zero */ |
| 1740 | } |
| 1741 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1742 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1743 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1744 | /* Memory Barrier */ |
| 1745 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 1746 | if (qpair->reqq_start_iocbs) |
| 1747 | qpair->reqq_start_iocbs(qpair); |
| 1748 | else |
| 1749 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | /* |
| 1753 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1754 | */ |
| 1755 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
| 1756 | struct abts_resp_from_24xx_fw *entry) |
| 1757 | { |
| 1758 | struct ctio7_to_24xx *ctio; |
| 1759 | |
| 1760 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1761 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1762 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1763 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready( |
| 1764 | vha->hw->base_qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1765 | if (ctio == NULL) { |
| 1766 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1767 | "qla_target(%d): %s failed: unable to allocate " |
| 1768 | "request packet\n", vha->vp_idx, __func__); |
| 1769 | return; |
| 1770 | } |
| 1771 | |
| 1772 | /* |
| 1773 | * We've got on entrance firmware's response on by us generated |
| 1774 | * ABTS response. So, in it ID fields are reversed. |
| 1775 | */ |
| 1776 | |
| 1777 | ctio->entry_type = CTIO_TYPE7; |
| 1778 | ctio->entry_count = 1; |
| 1779 | ctio->nport_handle = entry->nport_handle; |
| 1780 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1781 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1782 | ctio->vp_index = vha->vp_idx; |
| 1783 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1784 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1785 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1786 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1787 | ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
| 1788 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1789 | 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] | 1790 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1791 | /* Memory Barrier */ |
| 1792 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1793 | qla2x00_start_iocbs(vha, vha->req); |
| 1794 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1795 | qlt_24xx_send_abts_resp(vha->hw->base_qpair, |
| 1796 | (struct abts_recv_from_24xx *)entry, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1797 | FCP_TMF_CMPL, true); |
| 1798 | } |
| 1799 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1800 | static int abort_cmd_for_tag(struct scsi_qla_host *vha, uint32_t tag) |
| 1801 | { |
| 1802 | struct qla_tgt_sess_op *op; |
| 1803 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1804 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1805 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1806 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1807 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1808 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1809 | op->aborted = true; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1810 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1811 | return 1; |
| 1812 | } |
| 1813 | } |
| 1814 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1815 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1816 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1817 | op->aborted = true; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1818 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1819 | return 1; |
| 1820 | } |
| 1821 | } |
| 1822 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1823 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1824 | if (tag == cmd->atio.u.isp24.exchange_addr) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1825 | cmd->aborted = 1; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1826 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1827 | return 1; |
| 1828 | } |
| 1829 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1830 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1831 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1832 | return 0; |
| 1833 | } |
| 1834 | |
| 1835 | /* drop cmds for the given lun |
| 1836 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1837 | * XXX does not go through the list of other port (which may have cmds |
| 1838 | * for the same lun) |
| 1839 | */ |
| 1840 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1841 | u64 lun, uint8_t *s_id) |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1842 | { |
| 1843 | struct qla_tgt_sess_op *op; |
| 1844 | struct qla_tgt_cmd *cmd; |
| 1845 | uint32_t key; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1846 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1847 | |
| 1848 | key = sid_to_key(s_id); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1849 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1850 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1851 | uint32_t op_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1852 | u64 op_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1853 | |
| 1854 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1855 | op_lun = scsilun_to_int( |
| 1856 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1857 | if (op_key == key && op_lun == lun) |
| 1858 | op->aborted = true; |
| 1859 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1860 | |
| 1861 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1862 | uint32_t op_key; |
| 1863 | u64 op_lun; |
| 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 | } |
| 1871 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1872 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1873 | uint32_t cmd_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1874 | u64 cmd_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1875 | |
| 1876 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1877 | cmd_lun = scsilun_to_int( |
| 1878 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 1879 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1880 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1881 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1882 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1883 | } |
| 1884 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1885 | /* ha->hardware_lock supposed to be held on entry */ |
| 1886 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1887 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1888 | { |
| 1889 | struct qla_hw_data *ha = vha->hw; |
| 1890 | struct qla_tgt_mgmt_cmd *mcmd; |
| 1891 | int rc; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1892 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 1893 | if (abort_cmd_for_tag(vha, abts->exchange_addr_to_abort)) { |
| 1894 | /* send TASK_ABORT response immediately */ |
Linus Torvalds | 48ea2ce | 2017-07-13 14:27:32 -0700 | [diff] [blame] | 1895 | 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] | 1896 | return 0; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1897 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1898 | |
| 1899 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 1900 | "qla_target(%d): task abort (tag=%d)\n", |
| 1901 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 1902 | |
| 1903 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 1904 | if (mcmd == NULL) { |
| 1905 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 1906 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 1907 | vha->vp_idx, __func__); |
| 1908 | return -ENOMEM; |
| 1909 | } |
| 1910 | memset(mcmd, 0, sizeof(*mcmd)); |
| 1911 | |
| 1912 | mcmd->sess = sess; |
| 1913 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 1914 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 1915 | mcmd->tmr_func = QLA_TGT_ABTS; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1916 | mcmd->qpair = ha->base_qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 1917 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1918 | |
Nicholas Bellinger | eb5ae23 | 2017-06-03 07:07:21 -0700 | [diff] [blame] | 1919 | /* |
| 1920 | * LUN is looked up by target-core internally based on the passed |
| 1921 | * abts->exchange_addr_to_abort tag. |
| 1922 | */ |
| 1923 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, 0, mcmd->tmr_func, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1924 | abts->exchange_addr_to_abort); |
| 1925 | if (rc != 0) { |
| 1926 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, |
| 1927 | "qla_target(%d): tgt_ops->handle_tmr()" |
| 1928 | " failed: %d", vha->vp_idx, rc); |
| 1929 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 1930 | return -EFAULT; |
| 1931 | } |
| 1932 | |
| 1933 | return 0; |
| 1934 | } |
| 1935 | |
| 1936 | /* |
| 1937 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1938 | */ |
| 1939 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 1940 | struct abts_recv_from_24xx *abts) |
| 1941 | { |
| 1942 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1943 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1944 | uint32_t tag = abts->exchange_addr_to_abort; |
| 1945 | uint8_t s_id[3]; |
| 1946 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1947 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1948 | |
| 1949 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 1950 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 1951 | "qla_target(%d): ABTS: Abort Sequence not " |
| 1952 | "supported\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1953 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 1954 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1955 | return; |
| 1956 | } |
| 1957 | |
| 1958 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 1959 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 1960 | "qla_target(%d): ABTS: Unknown Exchange " |
| 1961 | "Address received\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1962 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 1963 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1964 | return; |
| 1965 | } |
| 1966 | |
| 1967 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 1968 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 1969 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 1970 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 1971 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 1972 | |
| 1973 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 1974 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1975 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 1976 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1977 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1978 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 1979 | if (!sess) { |
| 1980 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
| 1981 | "qla_target(%d): task abort for non-existant session\n", |
| 1982 | vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1983 | rc = qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1984 | QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1985 | |
| 1986 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1987 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1988 | if (rc != 0) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1989 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, |
| 1990 | FCP_TMF_REJECTED, false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1991 | } |
| 1992 | return; |
| 1993 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1994 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1995 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1996 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1997 | if (sess->deleted) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 1998 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 1999 | false); |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 2000 | return; |
| 2001 | } |
| 2002 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2003 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 2004 | if (rc != 0) { |
| 2005 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 2006 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 2007 | vha->vp_idx, rc); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2008 | qlt_24xx_send_abts_resp(ha->base_qpair, abts, FCP_TMF_REJECTED, |
| 2009 | false); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2010 | return; |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | /* |
| 2015 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2016 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2017 | static void qlt_24xx_send_task_mgmt_ctio(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2018 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 2019 | { |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 2020 | struct scsi_qla_host *ha = mcmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2021 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 2022 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2023 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2024 | |
| 2025 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 2026 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 2027 | ha, atio, resp_code); |
| 2028 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2029 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2030 | ctio = (struct ctio7_to_24xx *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2031 | if (ctio == NULL) { |
| 2032 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 2033 | "qla_target(%d): %s failed: unable to allocate " |
| 2034 | "request packet\n", ha->vp_idx, __func__); |
| 2035 | return; |
| 2036 | } |
| 2037 | |
| 2038 | ctio->entry_type = CTIO_TYPE7; |
| 2039 | ctio->entry_count = 1; |
| 2040 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 2041 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2042 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2043 | ctio->vp_index = ha->vp_idx; |
| 2044 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2045 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2046 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2047 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2048 | temp = (atio->u.isp24.attr << 9)| |
| 2049 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2050 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2051 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2052 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2053 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2054 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2055 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2056 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2057 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2058 | /* Memory Barrier */ |
| 2059 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2060 | if (qpair->reqq_start_iocbs) |
| 2061 | qpair->reqq_start_iocbs(qpair); |
| 2062 | else |
| 2063 | qla2x00_start_iocbs(ha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2067 | { |
| 2068 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2069 | } |
| 2070 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2071 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2072 | /* |
| 2073 | * ha->hardware_lock supposed to be held on entry. Might drop it, then |
| 2074 | * reacquire |
| 2075 | */ |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2076 | 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] | 2077 | uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq) |
| 2078 | { |
| 2079 | struct atio_from_isp *atio = &cmd->atio; |
| 2080 | struct ctio7_to_24xx *ctio; |
| 2081 | uint16_t temp; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2082 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2083 | |
| 2084 | ql_dbg(ql_dbg_tgt_dif, vha, 0x3066, |
| 2085 | "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, " |
| 2086 | "sense_key=%02x, asc=%02x, ascq=%02x", |
| 2087 | vha, atio, scsi_status, sense_key, asc, ascq); |
| 2088 | |
| 2089 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); |
| 2090 | if (!ctio) { |
| 2091 | ql_dbg(ql_dbg_async, vha, 0x3067, |
| 2092 | "qla2x00t(%ld): %s failed: unable to allocate request packet", |
| 2093 | vha->host_no, __func__); |
| 2094 | goto out; |
| 2095 | } |
| 2096 | |
| 2097 | ctio->entry_type = CTIO_TYPE7; |
| 2098 | ctio->entry_count = 1; |
| 2099 | ctio->handle = QLA_TGT_SKIP_HANDLE; |
| 2100 | ctio->nport_handle = cmd->sess->loop_id; |
| 2101 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
| 2102 | ctio->vp_index = vha->vp_idx; |
| 2103 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2104 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2105 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2106 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2107 | temp = (atio->u.isp24.attr << 9) | |
| 2108 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2109 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2110 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2111 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
| 2112 | ctio->u.status1.scsi_status = |
| 2113 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status); |
| 2114 | ctio->u.status1.response_len = cpu_to_le16(18); |
| 2115 | ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
| 2116 | |
| 2117 | if (ctio->u.status1.residual != 0) |
| 2118 | ctio->u.status1.scsi_status |= |
| 2119 | cpu_to_le16(SS_RESIDUAL_UNDER); |
| 2120 | |
| 2121 | /* Response code and sense key */ |
| 2122 | put_unaligned_le32(((0x70 << 24) | (sense_key << 8)), |
| 2123 | (&ctio->u.status1.sense_data)[0]); |
| 2124 | /* Additional sense length */ |
| 2125 | put_unaligned_le32(0x0a, (&ctio->u.status1.sense_data)[1]); |
| 2126 | /* ASC and ASCQ */ |
| 2127 | put_unaligned_le32(((asc << 24) | (ascq << 16)), |
| 2128 | (&ctio->u.status1.sense_data)[3]); |
| 2129 | |
| 2130 | /* Memory Barrier */ |
| 2131 | wmb(); |
| 2132 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2133 | if (qpair->reqq_start_iocbs) |
| 2134 | qpair->reqq_start_iocbs(qpair); |
| 2135 | else |
| 2136 | qla2x00_start_iocbs(vha, qpair->req); |
| 2137 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2138 | out: |
| 2139 | return; |
| 2140 | } |
| 2141 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2142 | /* callback from target fabric module code */ |
| 2143 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2144 | { |
| 2145 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2146 | struct qla_hw_data *ha = vha->hw; |
| 2147 | unsigned long flags; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2148 | struct qla_qpair *qpair = mcmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2149 | |
| 2150 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2151 | "TM response mcmd (%p) status %#x state %#x", |
| 2152 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2153 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2154 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2155 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2156 | if (!vha->flags.online || mcmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2157 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2158 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2159 | * previous life, just abort the processing. |
| 2160 | */ |
| 2161 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2162 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2163 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2164 | mcmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2165 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2166 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2167 | return; |
| 2168 | } |
| 2169 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2170 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
| 2171 | if (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2172 | ELS_LOGO || |
| 2173 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2174 | ELS_PRLO || |
| 2175 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2176 | ELS_TPRLO) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2177 | ql_dbg(ql_dbg_disc, vha, 0x2106, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2178 | "TM response logo %phC status %#x state %#x", |
| 2179 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2180 | mcmd->flags); |
| 2181 | qlt_schedule_sess_for_deletion_lock(mcmd->sess); |
| 2182 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2183 | qlt_send_notify_ack(vha->hw->base_qpair, |
| 2184 | &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2185 | } |
| 2186 | } else { |
Swapnil Nagle | d7236ac | 2016-02-04 11:45:17 -0500 | [diff] [blame] | 2187 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2188 | qlt_24xx_send_abts_resp(qpair, &mcmd->orig_iocb.abts, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2189 | mcmd->fc_tm_rsp, false); |
| 2190 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2191 | qlt_24xx_send_task_mgmt_ctio(qpair, mcmd, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2192 | mcmd->fc_tm_rsp); |
| 2193 | } |
| 2194 | /* |
| 2195 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2196 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2197 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2198 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2199 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2200 | * qlt_xmit_tm_rsp() returns here.. |
| 2201 | */ |
| 2202 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2203 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2204 | } |
| 2205 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2206 | |
| 2207 | /* No locks */ |
| 2208 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2209 | { |
| 2210 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2211 | |
| 2212 | BUG_ON(cmd->sg_cnt == 0); |
| 2213 | |
| 2214 | prm->sg = (struct scatterlist *)cmd->sg; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2215 | prm->seg_cnt = pci_map_sg(cmd->qpair->pdev, cmd->sg, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2216 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2217 | if (unlikely(prm->seg_cnt == 0)) |
| 2218 | goto out_err; |
| 2219 | |
| 2220 | prm->cmd->sg_mapped = 1; |
| 2221 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2222 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2223 | /* |
| 2224 | * If greater than four sg entries then we need to allocate |
| 2225 | * the continuation entries |
| 2226 | */ |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2227 | if (prm->seg_cnt > QLA_TGT_DATASEGS_PER_CMD_24XX) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2228 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2229 | QLA_TGT_DATASEGS_PER_CMD_24XX, |
| 2230 | QLA_TGT_DATASEGS_PER_CONT_24XX); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2231 | } else { |
| 2232 | /* DIF */ |
| 2233 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2234 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2235 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2236 | prm->tot_dsds = prm->seg_cnt; |
| 2237 | } else |
| 2238 | prm->tot_dsds = prm->seg_cnt; |
| 2239 | |
| 2240 | if (cmd->prot_sg_cnt) { |
| 2241 | prm->prot_sg = cmd->prot_sg; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2242 | prm->prot_seg_cnt = pci_map_sg(cmd->qpair->pdev, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2243 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2244 | cmd->dma_data_direction); |
| 2245 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2246 | goto out_err; |
| 2247 | |
| 2248 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2249 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2250 | /* Dif Bundling not support here */ |
| 2251 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2252 | cmd->blk_sz); |
| 2253 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2254 | } else |
| 2255 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2256 | } |
| 2257 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2258 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2259 | return 0; |
| 2260 | |
| 2261 | out_err: |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2262 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe04d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2263 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2264 | 0, prm->cmd->sg_cnt); |
| 2265 | return -1; |
| 2266 | } |
| 2267 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2268 | 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] | 2269 | { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2270 | struct qla_hw_data *ha; |
| 2271 | struct qla_qpair *qpair; |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2272 | if (!cmd->sg_mapped) |
| 2273 | return; |
| 2274 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2275 | qpair = cmd->qpair; |
| 2276 | |
| 2277 | pci_unmap_sg(qpair->pdev, cmd->sg, cmd->sg_cnt, |
| 2278 | cmd->dma_data_direction); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2279 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2280 | |
| 2281 | if (cmd->prot_sg_cnt) |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2282 | pci_unmap_sg(qpair->pdev, cmd->prot_sg, cmd->prot_sg_cnt, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2283 | cmd->dma_data_direction); |
| 2284 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2285 | if (!cmd->ctx) |
| 2286 | return; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2287 | ha = vha->hw; |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2288 | if (cmd->ctx_dsd_alloced) |
| 2289 | qla2x00_clean_dsd_pool(ha, cmd->ctx); |
| 2290 | |
| 2291 | 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] | 2292 | } |
| 2293 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2294 | static int qlt_check_reserve_free_req(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2295 | uint32_t req_cnt) |
| 2296 | { |
Quinn Tran | d63b328 | 2017-06-02 09:12:07 -0700 | [diff] [blame] | 2297 | uint32_t cnt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2298 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2299 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2300 | if (req->cnt < (req_cnt + 2)) { |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 2301 | cnt = (uint16_t)(qpair->use_shadow_reg ? *req->out_ptr : |
| 2302 | RD_REG_DWORD_RELAXED(req->req_q_out)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2303 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2304 | if (req->ring_index < cnt) |
| 2305 | req->cnt = cnt - req->ring_index; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2306 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2307 | req->cnt = req->length - (req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2308 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2309 | if (unlikely(req->cnt < (req_cnt + 2))) |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2310 | return -EAGAIN; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2311 | } |
| 2312 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2313 | req->cnt -= req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2314 | |
| 2315 | return 0; |
| 2316 | } |
| 2317 | |
| 2318 | /* |
| 2319 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2320 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2321 | static inline void *qlt_get_req_pkt(struct req_que *req) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2322 | { |
| 2323 | /* Adjust ring index. */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2324 | req->ring_index++; |
| 2325 | if (req->ring_index == req->length) { |
| 2326 | req->ring_index = 0; |
| 2327 | req->ring_ptr = req->ring; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2328 | } else { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2329 | req->ring_ptr++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2330 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2331 | return (cont_entry_t *)req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2335 | static inline uint32_t qlt_make_handle(struct qla_qpair *qpair) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2336 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2337 | uint32_t h; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2338 | int index; |
| 2339 | uint8_t found = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2340 | struct req_que *req = qpair->req; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2341 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2342 | h = req->current_outstanding_cmd; |
| 2343 | |
| 2344 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 2345 | h++; |
| 2346 | if (h == req->num_outstanding_cmds) |
| 2347 | h = 1; |
| 2348 | |
| 2349 | if (h == QLA_TGT_SKIP_HANDLE) |
| 2350 | continue; |
| 2351 | |
| 2352 | if (!req->outstanding_cmds[h]) { |
| 2353 | found = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2354 | break; |
| 2355 | } |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2356 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2357 | |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2358 | if (found) { |
| 2359 | req->current_outstanding_cmd = h; |
| 2360 | } else { |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 2361 | ql_dbg(ql_dbg_io, qpair->vha, 0x305b, |
| 2362 | "qla_target(%d): Ran out of empty cmd slots\n", |
| 2363 | qpair->vha->vp_idx); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 2364 | h = QLA_TGT_NULL_HANDLE; |
| 2365 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2366 | |
| 2367 | return h; |
| 2368 | } |
| 2369 | |
| 2370 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2371 | static int qlt_24xx_build_ctio_pkt(struct qla_qpair *qpair, |
| 2372 | struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2373 | { |
| 2374 | uint32_t h; |
| 2375 | struct ctio7_to_24xx *pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2376 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2377 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2378 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2379 | pkt = (struct ctio7_to_24xx *)qpair->req->ring_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2380 | prm->pkt = pkt; |
| 2381 | memset(pkt, 0, sizeof(*pkt)); |
| 2382 | |
| 2383 | pkt->entry_type = CTIO_TYPE7; |
| 2384 | pkt->entry_count = (uint8_t)prm->req_cnt; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2385 | pkt->vp_index = prm->cmd->vp_idx; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2386 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2387 | h = qlt_make_handle(qpair); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2388 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2389 | /* |
| 2390 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2391 | * know the initiator's LOOP ID, hence we can't find |
| 2392 | * the session and, so, the command. |
| 2393 | */ |
| 2394 | return -EAGAIN; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 2395 | } else |
| 2396 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
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 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2399 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
| 2400 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2401 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2402 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2403 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2404 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2405 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2406 | temp = atio->u.isp24.attr << 9; |
| 2407 | pkt->u.status0.flags |= cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2408 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2409 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2410 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2411 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2412 | return 0; |
| 2413 | } |
| 2414 | |
| 2415 | /* |
| 2416 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2417 | * that there is sufficient amount of request entries to not drop it. |
| 2418 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2419 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2420 | { |
| 2421 | int cnt; |
| 2422 | uint32_t *dword_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2423 | |
| 2424 | /* Build continuation packets */ |
| 2425 | while (prm->seg_cnt > 0) { |
| 2426 | cont_a64_entry_t *cont_pkt64 = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2427 | (cont_a64_entry_t *)qlt_get_req_pkt( |
| 2428 | prm->cmd->qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2429 | |
| 2430 | /* |
| 2431 | * Make sure that from cont_pkt64 none of |
| 2432 | * 64-bit specific fields used for 32-bit |
| 2433 | * addressing. Cast to (cont_entry_t *) for |
| 2434 | * that. |
| 2435 | */ |
| 2436 | |
| 2437 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2438 | |
| 2439 | cont_pkt64->entry_count = 1; |
| 2440 | cont_pkt64->sys_define = 0; |
| 2441 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2442 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
| 2443 | dword_ptr = (uint32_t *)&cont_pkt64->dseg_0_address; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2444 | |
| 2445 | /* Load continuation entry data segments */ |
| 2446 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2447 | cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2448 | cnt++, prm->seg_cnt--) { |
| 2449 | *dword_ptr++ = |
| 2450 | cpu_to_le32(pci_dma_lo32 |
| 2451 | (sg_dma_address(prm->sg))); |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2452 | *dword_ptr++ = cpu_to_le32(pci_dma_hi32 |
| 2453 | (sg_dma_address(prm->sg))); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2454 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2455 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2456 | prm->sg = sg_next(prm->sg); |
| 2457 | } |
| 2458 | } |
| 2459 | } |
| 2460 | |
| 2461 | /* |
| 2462 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2463 | * that there is sufficient amount of request entries to not drop it. |
| 2464 | */ |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2465 | static void qlt_load_data_segments(struct qla_tgt_prm *prm) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2466 | { |
| 2467 | int cnt; |
| 2468 | uint32_t *dword_ptr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2469 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2470 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2471 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2472 | |
| 2473 | /* Setup packet address segment pointer */ |
| 2474 | dword_ptr = pkt24->u.status0.dseg_0_address; |
| 2475 | |
| 2476 | /* Set total data segment count */ |
| 2477 | if (prm->seg_cnt) |
| 2478 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2479 | |
| 2480 | if (prm->seg_cnt == 0) { |
| 2481 | /* No data transfer */ |
| 2482 | *dword_ptr++ = 0; |
| 2483 | *dword_ptr = 0; |
| 2484 | return; |
| 2485 | } |
| 2486 | |
| 2487 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2488 | |
| 2489 | /* Load command entry data segments */ |
| 2490 | for (cnt = 0; |
Quinn Tran | b5399f7 | 2017-06-13 20:47:27 -0700 | [diff] [blame] | 2491 | (cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2492 | cnt++, prm->seg_cnt--) { |
| 2493 | *dword_ptr++ = |
| 2494 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2495 | |
| 2496 | *dword_ptr++ = cpu_to_le32(pci_dma_hi32( |
| 2497 | sg_dma_address(prm->sg))); |
| 2498 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2499 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2500 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2501 | prm->sg = sg_next(prm->sg); |
| 2502 | } |
| 2503 | |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 2504 | qlt_load_cont_data_segments(prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2508 | { |
| 2509 | return cmd->bufflen > 0; |
| 2510 | } |
| 2511 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2512 | static void qlt_print_dif_err(struct qla_tgt_prm *prm) |
| 2513 | { |
| 2514 | struct qla_tgt_cmd *cmd; |
| 2515 | struct scsi_qla_host *vha; |
| 2516 | |
| 2517 | /* asc 0x10=dif error */ |
| 2518 | if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) { |
| 2519 | cmd = prm->cmd; |
| 2520 | vha = cmd->vha; |
| 2521 | /* ASCQ */ |
| 2522 | switch (prm->sense_buffer[13]) { |
| 2523 | case 1: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2524 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2525 | "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2526 | "se_cmd=%p tag[%x]", |
| 2527 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2528 | cmd->atio.u.isp24.exchange_addr); |
| 2529 | break; |
| 2530 | case 2: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2531 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2532 | "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2533 | "se_cmd=%p tag[%x]", |
| 2534 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2535 | cmd->atio.u.isp24.exchange_addr); |
| 2536 | break; |
| 2537 | case 3: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2538 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2539 | "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2540 | "se_cmd=%p tag[%x]", |
| 2541 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2542 | cmd->atio.u.isp24.exchange_addr); |
| 2543 | break; |
| 2544 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2545 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe010, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2546 | "BE detected Dif ERR: lba[%llx|%lld] len[%x] " |
| 2547 | "se_cmd=%p tag[%x]", |
| 2548 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2549 | cmd->atio.u.isp24.exchange_addr); |
| 2550 | break; |
| 2551 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2552 | ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2556 | /* |
| 2557 | * Called without ha->hardware_lock held |
| 2558 | */ |
| 2559 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2560 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2561 | uint32_t *full_req_cnt) |
| 2562 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2563 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2564 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2565 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2566 | prm->cmd = cmd; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2567 | prm->tgt = cmd->tgt; |
| 2568 | prm->pkt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2569 | prm->rq_result = scsi_status; |
| 2570 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2571 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2572 | prm->sg = NULL; |
| 2573 | prm->seg_cnt = -1; |
| 2574 | prm->req_cnt = 1; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2575 | prm->residual = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2576 | prm->add_status_pkt = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2577 | prm->prot_sg = NULL; |
| 2578 | prm->prot_seg_cnt = 0; |
| 2579 | prm->tot_dsds = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2580 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2581 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2582 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2583 | return -EAGAIN; |
| 2584 | } |
| 2585 | |
| 2586 | *full_req_cnt = prm->req_cnt; |
| 2587 | |
| 2588 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2589 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2590 | ql_dbg_qp(ql_dbg_io + ql_dbg_verbose, qpair, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2591 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2592 | prm->residual, se_cmd->tag, |
| 2593 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2594 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2595 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2596 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2597 | prm->residual = se_cmd->residual_count; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2598 | ql_dbg_qp(ql_dbg_io, qpair, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2599 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2600 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2601 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2602 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2603 | } |
| 2604 | |
| 2605 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2606 | /* |
| 2607 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2608 | * ignored in *xmit_response() below |
| 2609 | */ |
| 2610 | if (qlt_has_data(cmd)) { |
| 2611 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2612 | (IS_FWI2_CAPABLE(cmd->vha->hw) && |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2613 | (prm->rq_result != 0))) { |
| 2614 | prm->add_status_pkt = 1; |
| 2615 | (*full_req_cnt)++; |
| 2616 | } |
| 2617 | } |
| 2618 | } |
| 2619 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2620 | return 0; |
| 2621 | } |
| 2622 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2623 | static inline int qlt_need_explicit_conf(struct qla_tgt_cmd *cmd, |
| 2624 | int sending_sense) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2625 | { |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2626 | if (cmd->qpair->enable_class_2) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2627 | return 0; |
| 2628 | |
| 2629 | if (sending_sense) |
| 2630 | return cmd->conf_compl_supported; |
| 2631 | else |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2632 | return cmd->qpair->enable_explicit_conf && |
| 2633 | cmd->conf_compl_supported; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2634 | } |
| 2635 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2636 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2637 | struct qla_tgt_prm *prm) |
| 2638 | { |
| 2639 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2640 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2641 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2642 | if (qlt_need_explicit_conf(prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2643 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2644 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2645 | CTIO7_FLAGS_CONFORM_REQ); |
| 2646 | } |
| 2647 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2648 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2649 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2650 | int i; |
| 2651 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 2652 | if (qlt_need_explicit_conf(prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2653 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2654 | ql_dbg_qp(ql_dbg_tgt, prm->cmd->qpair, 0xe017, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2655 | "Skipping EXPLICIT_CONFORM and " |
| 2656 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2657 | "non GOOD status\n"); |
| 2658 | goto skip_explict_conf; |
| 2659 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2660 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2661 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2662 | CTIO7_FLAGS_CONFORM_REQ); |
| 2663 | } |
| 2664 | skip_explict_conf: |
| 2665 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2666 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2667 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2668 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2669 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2670 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2671 | ctio->u.status1.sense_length = |
| 2672 | cpu_to_le16(prm->sense_buffer_len); |
| 2673 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2674 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2675 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2676 | |
| 2677 | qlt_print_dif_err(prm); |
| 2678 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2679 | } else { |
| 2680 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2681 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2682 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2683 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2684 | ctio->u.status1.sense_length = 0; |
| 2685 | memset(ctio->u.status1.sense_data, 0, |
| 2686 | sizeof(ctio->u.status1.sense_data)); |
| 2687 | } |
| 2688 | |
| 2689 | /* Sense with len > 24, is it possible ??? */ |
| 2690 | } |
| 2691 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2692 | static inline int |
| 2693 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2694 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2695 | switch (se_cmd->prot_op) { |
| 2696 | case TARGET_PROT_DOUT_INSERT: |
| 2697 | case TARGET_PROT_DIN_STRIP: |
| 2698 | if (ql2xenablehba_err_chk >= 1) |
| 2699 | return 1; |
| 2700 | break; |
| 2701 | case TARGET_PROT_DOUT_PASS: |
| 2702 | case TARGET_PROT_DIN_PASS: |
| 2703 | if (ql2xenablehba_err_chk >= 2) |
| 2704 | return 1; |
| 2705 | break; |
| 2706 | case TARGET_PROT_DIN_INSERT: |
| 2707 | case TARGET_PROT_DOUT_STRIP: |
| 2708 | return 1; |
| 2709 | default: |
| 2710 | break; |
| 2711 | } |
| 2712 | return 0; |
| 2713 | } |
| 2714 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2715 | static inline int |
| 2716 | qla_tgt_ref_mask_check(struct se_cmd *se_cmd) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2717 | { |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2718 | switch (se_cmd->prot_op) { |
| 2719 | case TARGET_PROT_DIN_INSERT: |
| 2720 | case TARGET_PROT_DOUT_INSERT: |
| 2721 | case TARGET_PROT_DIN_STRIP: |
| 2722 | case TARGET_PROT_DOUT_STRIP: |
| 2723 | case TARGET_PROT_DIN_PASS: |
| 2724 | case TARGET_PROT_DOUT_PASS: |
| 2725 | return 1; |
| 2726 | default: |
| 2727 | return 0; |
| 2728 | } |
| 2729 | return 0; |
| 2730 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2731 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2732 | /* |
| 2733 | * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command |
| 2734 | */ |
| 2735 | static void |
| 2736 | qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx, |
| 2737 | uint16_t *pfw_prot_opts) |
| 2738 | { |
| 2739 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2740 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2741 | scsi_qla_host_t *vha = cmd->tgt->vha; |
| 2742 | struct qla_hw_data *ha = vha->hw; |
| 2743 | uint32_t t32 = 0; |
| 2744 | |
| 2745 | /* |
| 2746 | * wait till Mode Sense/Select cmd, modepage Ah, subpage 2 |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2747 | * have been immplemented by TCM, before AppTag is avail. |
| 2748 | * Look for modesense_handlers[] |
| 2749 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2750 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2751 | ctx->app_tag_mask[0] = 0x0; |
| 2752 | ctx->app_tag_mask[1] = 0x0; |
| 2753 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2754 | if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2755 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2756 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2757 | *pfw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2758 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2759 | *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2760 | } |
| 2761 | |
| 2762 | t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts); |
| 2763 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2764 | switch (se_cmd->prot_type) { |
| 2765 | case TARGET_DIF_TYPE0_PROT: |
| 2766 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2767 | * No check for ql2xenablehba_err_chk, as it |
| 2768 | * would be an I/O error if hba tag generation |
| 2769 | * is not done. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2770 | */ |
| 2771 | ctx->ref_tag = cpu_to_le32(lba); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2772 | /* enable ALL bytes of the ref tag */ |
| 2773 | ctx->ref_tag_mask[0] = 0xff; |
| 2774 | ctx->ref_tag_mask[1] = 0xff; |
| 2775 | ctx->ref_tag_mask[2] = 0xff; |
| 2776 | ctx->ref_tag_mask[3] = 0xff; |
| 2777 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2778 | case TARGET_DIF_TYPE1_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2779 | /* |
| 2780 | * For TYPE 1 protection: 16 bit GUARD tag, 32 bit |
| 2781 | * REF tag, and 16 bit app tag. |
| 2782 | */ |
| 2783 | ctx->ref_tag = cpu_to_le32(lba); |
| 2784 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2785 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2786 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2787 | break; |
| 2788 | } |
| 2789 | /* enable ALL bytes of the ref tag */ |
| 2790 | ctx->ref_tag_mask[0] = 0xff; |
| 2791 | ctx->ref_tag_mask[1] = 0xff; |
| 2792 | ctx->ref_tag_mask[2] = 0xff; |
| 2793 | ctx->ref_tag_mask[3] = 0xff; |
| 2794 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2795 | case TARGET_DIF_TYPE2_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2796 | /* |
| 2797 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF |
| 2798 | * tag has to match LBA in CDB + N |
| 2799 | */ |
| 2800 | ctx->ref_tag = cpu_to_le32(lba); |
| 2801 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2802 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2803 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2804 | break; |
| 2805 | } |
| 2806 | /* enable ALL bytes of the ref tag */ |
| 2807 | ctx->ref_tag_mask[0] = 0xff; |
| 2808 | ctx->ref_tag_mask[1] = 0xff; |
| 2809 | ctx->ref_tag_mask[2] = 0xff; |
| 2810 | ctx->ref_tag_mask[3] = 0xff; |
| 2811 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2812 | case TARGET_DIF_TYPE3_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2813 | /* For TYPE 3 protection: 16 bit GUARD only */ |
| 2814 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2815 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2816 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2817 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2818 | } |
| 2819 | } |
| 2820 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2821 | static inline int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2822 | 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] | 2823 | { |
| 2824 | uint32_t *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2825 | uint32_t transfer_length = 0; |
| 2826 | uint32_t data_bytes; |
| 2827 | uint32_t dif_bytes; |
| 2828 | uint8_t bundling = 1; |
| 2829 | uint8_t *clr_ptr; |
| 2830 | struct crc_context *crc_ctx_pkt = NULL; |
| 2831 | struct qla_hw_data *ha; |
| 2832 | struct ctio_crc2_to_fw *pkt; |
| 2833 | dma_addr_t crc_ctx_dma; |
| 2834 | uint16_t fw_prot_opts = 0; |
| 2835 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2836 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2837 | uint32_t h; |
| 2838 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2839 | struct qla_tc_param tc; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2840 | uint16_t t16; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2841 | scsi_qla_host_t *vha = cmd->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2842 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2843 | ha = vha->hw; |
| 2844 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2845 | pkt = (struct ctio_crc2_to_fw *)qpair->req->ring_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2846 | prm->pkt = pkt; |
| 2847 | memset(pkt, 0, sizeof(*pkt)); |
| 2848 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2849 | ql_dbg_qp(ql_dbg_tgt, cmd->qpair, 0xe071, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2850 | "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] | 2851 | cmd->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2852 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 2853 | |
| 2854 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 2855 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 2856 | bundling = 0; |
| 2857 | |
| 2858 | /* Compute dif len and adjust data len to incude protection */ |
| 2859 | data_bytes = cmd->bufflen; |
| 2860 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 2861 | |
| 2862 | switch (se_cmd->prot_op) { |
| 2863 | case TARGET_PROT_DIN_INSERT: |
| 2864 | case TARGET_PROT_DOUT_STRIP: |
| 2865 | transfer_length = data_bytes; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2866 | if (cmd->prot_sg_cnt) |
| 2867 | data_bytes += dif_bytes; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2868 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2869 | case TARGET_PROT_DIN_STRIP: |
| 2870 | case TARGET_PROT_DOUT_INSERT: |
| 2871 | case TARGET_PROT_DIN_PASS: |
| 2872 | case TARGET_PROT_DOUT_PASS: |
| 2873 | transfer_length = data_bytes + dif_bytes; |
| 2874 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2875 | default: |
| 2876 | BUG(); |
| 2877 | break; |
| 2878 | } |
| 2879 | |
| 2880 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2881 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 2882 | /* HBA error checking enabled */ |
| 2883 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2884 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2885 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2886 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2887 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2888 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2889 | } |
| 2890 | |
| 2891 | switch (se_cmd->prot_op) { |
| 2892 | case TARGET_PROT_DIN_INSERT: |
| 2893 | case TARGET_PROT_DOUT_INSERT: |
| 2894 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 2895 | break; |
| 2896 | case TARGET_PROT_DIN_STRIP: |
| 2897 | case TARGET_PROT_DOUT_STRIP: |
| 2898 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 2899 | break; |
| 2900 | case TARGET_PROT_DIN_PASS: |
| 2901 | case TARGET_PROT_DOUT_PASS: |
| 2902 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2903 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 2904 | break; |
| 2905 | default:/* Normal Request */ |
| 2906 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2907 | break; |
| 2908 | } |
| 2909 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2910 | /* ---- PKT ---- */ |
| 2911 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 2912 | pkt->entry_type = CTIO_CRC2; |
| 2913 | pkt->entry_count = 1; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 2914 | pkt->vp_index = cmd->vp_idx; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2915 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2916 | h = qlt_make_handle(qpair); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2917 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2918 | /* |
| 2919 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2920 | * know the initiator's LOOP ID, hence we can't find |
| 2921 | * the session and, so, the command. |
| 2922 | */ |
| 2923 | return -EAGAIN; |
| 2924 | } else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 2925 | qpair->req->outstanding_cmds[h] = (srb_t *)prm->cmd; |
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 | pkt->handle = MAKE_HANDLE(qpair->req->id, h); |
| 2928 | pkt->handle |= CTIO_COMPLETION_HANDLE_MARK; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2929 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2930 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2931 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2932 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2933 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2934 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2935 | |
| 2936 | /* silence compile warning */ |
| 2937 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2938 | pkt->ox_id = cpu_to_le16(t16); |
| 2939 | |
| 2940 | t16 = (atio->u.isp24.attr << 9); |
| 2941 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2942 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2943 | |
| 2944 | /* Set transfer direction */ |
| 2945 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2946 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2947 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2948 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2949 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2950 | pkt->dseg_count = prm->tot_dsds; |
| 2951 | /* Fibre channel byte count */ |
| 2952 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 2953 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2954 | /* ----- CRC context -------- */ |
| 2955 | |
| 2956 | /* Allocate CRC context from global pool */ |
| 2957 | crc_ctx_pkt = cmd->ctx = |
| 2958 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
| 2959 | |
| 2960 | if (!crc_ctx_pkt) |
| 2961 | goto crc_queuing_error; |
| 2962 | |
| 2963 | /* Zero out CTX area. */ |
| 2964 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 2965 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 2966 | |
| 2967 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 2968 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 2969 | |
| 2970 | /* Set handle */ |
| 2971 | crc_ctx_pkt->handle = pkt->handle; |
| 2972 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2973 | qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2974 | |
| 2975 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 2976 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 2977 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 2978 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2979 | if (!bundling) { |
| 2980 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 2981 | } else { |
| 2982 | /* |
| 2983 | * Configure Bundling if we need to fetch interlaving |
| 2984 | * protection PCI accesses |
| 2985 | */ |
| 2986 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 2987 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 2988 | crc_ctx_pkt->u.bundling.dseg_count = |
| 2989 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
| 2990 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 2991 | } |
| 2992 | |
| 2993 | /* Finish the common fields of CRC pkt */ |
| 2994 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 2995 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 2996 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2997 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2998 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2999 | memset((uint8_t *)&tc, 0 , sizeof(tc)); |
| 3000 | tc.vha = vha; |
| 3001 | tc.blk_sz = cmd->blk_sz; |
| 3002 | tc.bufflen = cmd->bufflen; |
| 3003 | tc.sg = cmd->sg; |
| 3004 | tc.prot_sg = cmd->prot_sg; |
| 3005 | tc.ctx = crc_ctx_pkt; |
| 3006 | tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3007 | |
| 3008 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3009 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3010 | |
| 3011 | if (!bundling && prm->prot_seg_cnt) { |
| 3012 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3013 | prm->tot_dsds, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3014 | goto crc_queuing_error; |
| 3015 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3016 | (prm->tot_dsds - prm->prot_seg_cnt), &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3017 | goto crc_queuing_error; |
| 3018 | |
| 3019 | if (bundling && prm->prot_seg_cnt) { |
| 3020 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 3021 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3022 | |
| 3023 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 3024 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3025 | prm->prot_seg_cnt, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3026 | goto crc_queuing_error; |
| 3027 | } |
| 3028 | return QLA_SUCCESS; |
| 3029 | |
| 3030 | crc_queuing_error: |
| 3031 | /* Cleanup will be performed by the caller */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3032 | qpair->req->outstanding_cmds[h] = NULL; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3033 | |
| 3034 | return QLA_FUNCTION_FAILED; |
| 3035 | } |
| 3036 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3037 | /* |
| 3038 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 3039 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 3040 | */ |
| 3041 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 3042 | uint8_t scsi_status) |
| 3043 | { |
| 3044 | struct scsi_qla_host *vha = cmd->vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3045 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3046 | struct ctio7_to_24xx *pkt; |
| 3047 | struct qla_tgt_prm prm; |
| 3048 | uint32_t full_req_cnt = 0; |
| 3049 | unsigned long flags = 0; |
| 3050 | int res; |
| 3051 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3052 | if (cmd->sess && cmd->sess->deleted) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3053 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3054 | if (cmd->sess->logout_completed) |
| 3055 | /* no need to terminate. FW already freed exchange. */ |
| 3056 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 3057 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3058 | qlt_send_term_exchange(qpair, cmd, &cmd->atio, 0, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3059 | return 0; |
| 3060 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3061 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3062 | ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3063 | "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] | 3064 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 3065 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3066 | &cmd->se_cmd, qpair->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3067 | |
| 3068 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 3069 | &full_req_cnt); |
| 3070 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3071 | return res; |
| 3072 | } |
| 3073 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3074 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3075 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3076 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3077 | qpair->tgt_counters.core_qla_snd_status++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3078 | else |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3079 | qpair->tgt_counters.core_qla_que_buf++; |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3080 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3081 | if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3082 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3083 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3084 | * previous life, just abort the processing. |
| 3085 | */ |
| 3086 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3087 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3088 | ql_dbg_qp(ql_dbg_async, qpair, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3089 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3090 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3091 | cmd->reset_count, qpair->chip_reset); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3092 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3093 | return 0; |
| 3094 | } |
| 3095 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3096 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3097 | res = qlt_check_reserve_free_req(qpair, full_req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3098 | if (unlikely(res)) |
| 3099 | goto out_unmap_unlock; |
| 3100 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3101 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3102 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3103 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3104 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3105 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3106 | qpair->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3107 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3108 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3109 | |
| 3110 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 3111 | |
| 3112 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 3113 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3114 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3115 | CTIO7_FLAGS_STATUS_MODE_0); |
| 3116 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3117 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3118 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3119 | |
| 3120 | if (prm.add_status_pkt == 0) { |
| 3121 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 3122 | pkt->u.status0.scsi_status = |
| 3123 | cpu_to_le16(prm.rq_result); |
| 3124 | pkt->u.status0.residual = |
| 3125 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3126 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3127 | CTIO7_FLAGS_SEND_STATUS); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3128 | if (qlt_need_explicit_conf(cmd, 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3129 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3130 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3131 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 3132 | CTIO7_FLAGS_CONFORM_REQ); |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | } else { |
| 3137 | /* |
| 3138 | * We have already made sure that there is sufficient |
| 3139 | * amount of request entries to not drop HW lock in |
| 3140 | * req_pkt(). |
| 3141 | */ |
| 3142 | struct ctio7_to_24xx *ctio = |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3143 | (struct ctio7_to_24xx *)qlt_get_req_pkt( |
| 3144 | qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3145 | |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3146 | ql_dbg_qp(ql_dbg_tgt, qpair, 0x305e, |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3147 | "Building additional status packet 0x%p.\n", |
| 3148 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3149 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3150 | /* |
| 3151 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 3152 | * ctio7_to_24xx |
| 3153 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3154 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3155 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3156 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3157 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3158 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3159 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3160 | CTIO7_FLAGS_DATA_IN); |
| 3161 | |
| 3162 | /* Real finish is ctio_m1's finish */ |
| 3163 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3164 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3165 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3166 | |
| 3167 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3168 | * all neccessary fields that's part of CTIO7. |
| 3169 | * There should be no residual of CTIO-CRC2 data. |
| 3170 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3171 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3172 | &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3173 | } |
| 3174 | } else |
| 3175 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3176 | |
| 3177 | |
| 3178 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3179 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3180 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3181 | /* Memory Barrier */ |
| 3182 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3183 | if (qpair->reqq_start_iocbs) |
| 3184 | qpair->reqq_start_iocbs(qpair); |
| 3185 | else |
| 3186 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3187 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3188 | |
| 3189 | return 0; |
| 3190 | |
| 3191 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3192 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3193 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3194 | |
| 3195 | return res; |
| 3196 | } |
| 3197 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3198 | |
| 3199 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3200 | { |
| 3201 | struct ctio7_to_24xx *pkt; |
| 3202 | struct scsi_qla_host *vha = cmd->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3203 | struct qla_tgt *tgt = cmd->tgt; |
| 3204 | struct qla_tgt_prm prm; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3205 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3206 | int res = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3207 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3208 | |
| 3209 | memset(&prm, 0, sizeof(prm)); |
| 3210 | prm.cmd = cmd; |
| 3211 | prm.tgt = tgt; |
| 3212 | prm.sg = NULL; |
| 3213 | prm.req_cnt = 1; |
| 3214 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3215 | /* Calculate number of entries and segments required */ |
| 3216 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3217 | return -EAGAIN; |
| 3218 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3219 | if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3220 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3221 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3222 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3223 | * previous life, just abort the processing. |
| 3224 | */ |
| 3225 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
| 3226 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 3227 | ql_dbg_qp(ql_dbg_async, qpair, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3228 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3229 | vha->flags.online, qla2x00_reset_active(vha), |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 3230 | cmd->reset_count, qpair->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3231 | return 0; |
| 3232 | } |
| 3233 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3234 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3235 | /* Does F/W have an IOCBs for this request */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3236 | res = qlt_check_reserve_free_req(qpair, prm.req_cnt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3237 | if (res != 0) |
| 3238 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3239 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3240 | res = qlt_build_ctio_crc2_pkt(qpair, &prm); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3241 | else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3242 | res = qlt_24xx_build_ctio_pkt(qpair, &prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3243 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3244 | if (unlikely(res != 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3245 | qpair->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3246 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3247 | } |
| 3248 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3249 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3250 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3251 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3252 | |
| 3253 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
Quinn Tran | 32d29b4 | 2017-06-13 20:47:26 -0700 | [diff] [blame] | 3254 | qlt_load_data_segments(&prm); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3255 | |
| 3256 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3257 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3258 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3259 | /* Memory Barrier */ |
| 3260 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3261 | if (qpair->reqq_start_iocbs) |
| 3262 | qpair->reqq_start_iocbs(qpair); |
| 3263 | else |
| 3264 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3265 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3266 | |
| 3267 | return res; |
| 3268 | |
| 3269 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3270 | qlt_unmap_sg(vha, cmd); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3271 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3272 | |
| 3273 | return res; |
| 3274 | } |
| 3275 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3276 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3277 | |
| 3278 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3279 | * it is assumed either hardware_lock or qpair lock is held. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3280 | */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3281 | static void |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3282 | 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] | 3283 | struct ctio_crc_from_fw *sts) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3284 | { |
| 3285 | uint8_t *ap = &sts->actual_dif[0]; |
| 3286 | uint8_t *ep = &sts->expected_dif[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3287 | uint64_t lba = cmd->se_cmd.t_task_lba; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3288 | uint8_t scsi_status, sense_key, asc, ascq; |
| 3289 | unsigned long flags; |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3290 | struct scsi_qla_host *vha = cmd->vha; |
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 | cmd->trc_flags |= TRC_DIF_ERR; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3293 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3294 | cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3295 | cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3296 | cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3297 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3298 | cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3299 | cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3300 | cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3301 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3302 | ql_dbg(ql_dbg_tgt_dif, vha, 0xf075, |
| 3303 | "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state); |
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 | scsi_status = sense_key = asc = ascq = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3306 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3307 | /* check appl tag */ |
| 3308 | if (cmd->e_app_tag != cmd->a_app_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3309 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d, |
| 3310 | "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]", |
| 3311 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3312 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3313 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3314 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
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 | cmd->dif_err_code = DIF_ERR_APP; |
| 3317 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3318 | sense_key = ABORTED_COMMAND; |
| 3319 | asc = 0x10; |
| 3320 | ascq = 0x2; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | /* check ref tag */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3324 | if (cmd->e_ref_tag != cmd->a_ref_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3325 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e, |
| 3326 | "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] ", |
| 3327 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3328 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3329 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3330 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3331 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3332 | cmd->dif_err_code = DIF_ERR_REF; |
| 3333 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3334 | sense_key = ABORTED_COMMAND; |
| 3335 | asc = 0x10; |
| 3336 | ascq = 0x3; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3337 | goto out; |
| 3338 | } |
| 3339 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3340 | /* check guard */ |
| 3341 | if (cmd->e_guard != cmd->a_guard) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3342 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe012, |
| 3343 | "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]", |
| 3344 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3345 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3346 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3347 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
| 3348 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3349 | cmd->dif_err_code = DIF_ERR_GRD; |
| 3350 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3351 | sense_key = ABORTED_COMMAND; |
| 3352 | asc = 0x10; |
| 3353 | ascq = 0x1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3354 | } |
| 3355 | out: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3356 | switch (cmd->state) { |
| 3357 | case QLA_TGT_STATE_NEED_DATA: |
| 3358 | /* handle_data will load DIF error code */ |
| 3359 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3360 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
| 3361 | break; |
| 3362 | default: |
| 3363 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3364 | if (cmd->aborted) { |
| 3365 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3366 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3367 | break; |
| 3368 | } |
| 3369 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3370 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3371 | qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc, |
| 3372 | ascq); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3373 | /* assume scsi status gets out on the wire. |
| 3374 | * Will not wait for completion. |
| 3375 | */ |
| 3376 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3377 | break; |
| 3378 | } |
| 3379 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3380 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3381 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3382 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3383 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3384 | struct imm_ntfy_from_isp *ntfy) |
| 3385 | { |
| 3386 | struct nack_to_isp *nack; |
| 3387 | struct qla_hw_data *ha = vha->hw; |
| 3388 | request_t *pkt; |
| 3389 | int ret = 0; |
| 3390 | |
| 3391 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3392 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3393 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3394 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3395 | if (pkt == NULL) { |
| 3396 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3397 | "qla_target(%d): %s failed: unable to allocate " |
| 3398 | "request packet\n", vha->vp_idx, __func__); |
| 3399 | return -ENOMEM; |
| 3400 | } |
| 3401 | |
| 3402 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3403 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3404 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3405 | |
| 3406 | nack = (struct nack_to_isp *)pkt; |
| 3407 | nack->ox_id = ntfy->ox_id; |
| 3408 | |
| 3409 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3410 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3411 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3412 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3413 | } |
| 3414 | |
| 3415 | /* terminate */ |
| 3416 | nack->u.isp24.flags |= |
| 3417 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3418 | |
| 3419 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3420 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3421 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3422 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3423 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3424 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3425 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3426 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3427 | |
| 3428 | qla2x00_start_iocbs(vha, vha->req); |
| 3429 | return ret; |
| 3430 | } |
| 3431 | |
| 3432 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3433 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3434 | { |
| 3435 | unsigned long flags = 0; |
| 3436 | int rc; |
| 3437 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3438 | if (ha_locked) { |
| 3439 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3440 | |
| 3441 | #if 0 /* Todo */ |
| 3442 | if (rc == -ENOMEM) |
| 3443 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
Bart Van Assche | 91f42b3 | 2016-03-30 15:25:21 -0700 | [diff] [blame] | 3444 | #else |
| 3445 | if (rc) { |
| 3446 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3447 | #endif |
| 3448 | goto done; |
| 3449 | } |
| 3450 | |
| 3451 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3452 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3453 | |
| 3454 | #if 0 /* Todo */ |
| 3455 | if (rc == -ENOMEM) |
| 3456 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
| 3457 | #endif |
| 3458 | |
| 3459 | done: |
| 3460 | if (!ha_locked) |
| 3461 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3462 | } |
| 3463 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3464 | /* |
| 3465 | * If hardware_lock held on entry, might drop it, then reaquire |
| 3466 | * This function sends the appropriate CTIO to ISP 2xxx or 24xx |
| 3467 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3468 | static int __qlt_send_term_exchange(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3469 | struct qla_tgt_cmd *cmd, |
| 3470 | struct atio_from_isp *atio) |
| 3471 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3472 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3473 | struct ctio7_to_24xx *ctio24; |
| 3474 | struct qla_hw_data *ha = vha->hw; |
| 3475 | request_t *pkt; |
| 3476 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3477 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3478 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3479 | 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] | 3480 | |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 3481 | if (cmd) |
| 3482 | vha = cmd->vha; |
| 3483 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3484 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3485 | if (pkt == NULL) { |
| 3486 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3487 | "qla_target(%d): %s failed: unable to allocate " |
| 3488 | "request packet\n", vha->vp_idx, __func__); |
| 3489 | return -ENOMEM; |
| 3490 | } |
| 3491 | |
| 3492 | if (cmd != NULL) { |
| 3493 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3494 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3495 | "qla_target(%d): Terminating cmd %p with " |
| 3496 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3497 | cmd->state); |
| 3498 | } else |
| 3499 | ret = 1; |
| 3500 | } |
| 3501 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 3502 | qpair->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3503 | pkt->entry_count = 1; |
| 3504 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3505 | |
| 3506 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3507 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3508 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3509 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3510 | ctio24->vp_index = vha->vp_idx; |
| 3511 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3512 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3513 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3514 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3515 | temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 | |
| 3516 | CTIO7_FLAGS_TERMINATE; |
| 3517 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3518 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3519 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3520 | |
| 3521 | /* Most likely, it isn't needed */ |
| 3522 | ctio24->u.status1.residual = get_unaligned((uint32_t *) |
| 3523 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3524 | atio->u.isp24.fcp_cmnd.add_cdb_len]); |
| 3525 | if (ctio24->u.status1.residual != 0) |
| 3526 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 3527 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3528 | /* Memory Barrier */ |
| 3529 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3530 | if (qpair->reqq_start_iocbs) |
| 3531 | qpair->reqq_start_iocbs(qpair); |
| 3532 | else |
| 3533 | qla2x00_start_iocbs(vha, qpair->req); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3534 | return ret; |
| 3535 | } |
| 3536 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3537 | static void qlt_send_term_exchange(struct qla_qpair *qpair, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3538 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3539 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3540 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3541 | struct scsi_qla_host *vha; |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3542 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3543 | int rc; |
| 3544 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3545 | /* why use different vha? NPIV */ |
| 3546 | if (cmd) |
| 3547 | vha = cmd->vha; |
| 3548 | else |
| 3549 | vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3550 | |
| 3551 | if (ha_locked) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3552 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3553 | if (rc == -ENOMEM) |
| 3554 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3555 | goto done; |
| 3556 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3557 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 3558 | rc = __qlt_send_term_exchange(qpair, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3559 | if (rc == -ENOMEM) |
| 3560 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3561 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3562 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3563 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3564 | if (cmd->sg_mapped) |
| 3565 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3566 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3567 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3568 | |
| 3569 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3570 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3571 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3572 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3573 | } |
| 3574 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3575 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3576 | { |
| 3577 | struct list_head free_list; |
| 3578 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3579 | |
| 3580 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3581 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3582 | |
| 3583 | cmd = tcmd = NULL; |
| 3584 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3585 | INIT_LIST_HEAD(&free_list); |
| 3586 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3587 | |
| 3588 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3589 | list_del(&cmd->cmd_list); |
| 3590 | /* This cmd was never sent to TCM. There is no need |
| 3591 | * to schedule free or call free_cmd |
| 3592 | */ |
| 3593 | qlt_free_cmd(cmd); |
| 3594 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3595 | } |
| 3596 | } |
| 3597 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3598 | } |
| 3599 | |
| 3600 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3601 | { |
| 3602 | uint32_t total_leaked; |
| 3603 | |
| 3604 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3605 | |
| 3606 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3607 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3608 | |
| 3609 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3610 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3611 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3612 | |
| 3613 | if (IS_P3P_TYPE(vha->hw)) |
| 3614 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3615 | else |
| 3616 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3617 | qla2xxx_wake_dpc(vha); |
| 3618 | } |
| 3619 | |
| 3620 | } |
| 3621 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3622 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3623 | { |
| 3624 | struct qla_tgt *tgt = cmd->tgt; |
| 3625 | struct scsi_qla_host *vha = tgt->vha; |
| 3626 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3627 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3628 | |
| 3629 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3630 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3631 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3632 | se_cmd->tag); |
| 3633 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3634 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3635 | if (cmd->aborted) { |
| 3636 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3637 | /* |
| 3638 | * It's normal to see 2 calls in this path: |
| 3639 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3640 | * 2) TCM TMR - drain_state_list |
| 3641 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3642 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, |
| 3643 | "multiple abort. %p transport_state %x, t_state %x, " |
| 3644 | "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, |
| 3645 | cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3646 | return EIO; |
| 3647 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3648 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3649 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3650 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3651 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3652 | qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3653 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3654 | } |
| 3655 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3656 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3657 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3658 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3659 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3660 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3661 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3662 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3663 | __func__, &cmd->se_cmd, |
| 3664 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3665 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3666 | BUG_ON(cmd->cmd_in_wq); |
| 3667 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3668 | if (cmd->sg_mapped) |
| 3669 | qlt_unmap_sg(cmd->vha, cmd); |
| 3670 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3671 | if (!cmd->q_full) |
| 3672 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3673 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3674 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3675 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3676 | if (unlikely(cmd->free_sg)) |
| 3677 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3678 | |
| 3679 | if (!sess || !sess->se_sess) { |
| 3680 | WARN_ON(1); |
| 3681 | return; |
| 3682 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3683 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3684 | 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] | 3685 | } |
| 3686 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3687 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3688 | /* |
| 3689 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3690 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3691 | static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3692 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3693 | { |
| 3694 | int term = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3695 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3696 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3697 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3698 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3699 | "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " |
| 3700 | "se_cmd=%p tag[%x] op %#x/%s", |
| 3701 | cmd->lba, cmd->lba, |
| 3702 | cmd->num_blks, &cmd->se_cmd, |
| 3703 | cmd->atio.u.isp24.exchange_addr, |
| 3704 | cmd->se_cmd.prot_op, |
| 3705 | prot_op_str(cmd->se_cmd.prot_op)); |
| 3706 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3707 | if (ctio != NULL) { |
| 3708 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
| 3709 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3710 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3711 | } else |
| 3712 | term = 1; |
| 3713 | |
| 3714 | if (term) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3715 | qlt_term_ctio_exchange(qpair, ctio, cmd, status); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3716 | |
| 3717 | return term; |
| 3718 | } |
| 3719 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3720 | |
| 3721 | /* ha->hardware_lock supposed to be held on entry */ |
| 3722 | 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] | 3723 | struct rsp_que *rsp, uint32_t handle, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3724 | { |
| 3725 | struct qla_tgt_cmd *cmd = NULL; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3726 | struct req_que *req; |
| 3727 | int qid = GET_QID(handle); |
| 3728 | uint32_t h = handle & ~QLA_TGT_HANDLE_MASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3729 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3730 | if (unlikely(h == QLA_TGT_SKIP_HANDLE)) |
| 3731 | return NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3732 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3733 | if (qid == rsp->req->id) { |
| 3734 | req = rsp->req; |
| 3735 | } else if (vha->hw->req_q_map[qid]) { |
| 3736 | ql_dbg(ql_dbg_tgt_mgt, vha, 0x1000a, |
| 3737 | "qla_target(%d): CTIO completion with different QID %d handle %x\n", |
| 3738 | vha->vp_idx, rsp->id, handle); |
| 3739 | req = vha->hw->req_q_map[qid]; |
| 3740 | } else { |
| 3741 | return NULL; |
| 3742 | } |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3743 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3744 | h &= QLA_CMD_HANDLE_MASK; |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3745 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3746 | if (h != QLA_TGT_NULL_HANDLE) { |
Dan Carpenter | fb2028a | 2017-07-10 11:47:40 +0300 | [diff] [blame] | 3747 | if (unlikely(h >= req->num_outstanding_cmds)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3748 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3749 | "qla_target(%d): Wrong handle %x received\n", |
| 3750 | vha->vp_idx, handle); |
| 3751 | return NULL; |
| 3752 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3753 | |
| 3754 | cmd = (struct qla_tgt_cmd *)req->outstanding_cmds[h]; |
| 3755 | if (unlikely(cmd == NULL)) { |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3756 | ql_dbg(ql_dbg_async, vha, 0xe053, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3757 | "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n", |
| 3758 | vha->vp_idx, handle, req->id, rsp->id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3759 | return NULL; |
| 3760 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3761 | req->outstanding_cmds[h] = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3762 | } else if (ctio != NULL) { |
| 3763 | /* We can't get loop ID from CTIO7 */ |
| 3764 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3765 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3766 | "support NULL handles\n", vha->vp_idx); |
| 3767 | return NULL; |
| 3768 | } |
| 3769 | |
| 3770 | return cmd; |
| 3771 | } |
| 3772 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3773 | /* hardware_lock should be held by caller. */ |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 3774 | void |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3775 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
| 3776 | { |
| 3777 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3778 | |
| 3779 | if (cmd->sg_mapped) |
| 3780 | qlt_unmap_sg(vha, cmd); |
| 3781 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3782 | /* TODO: fix debug message type and ids. */ |
| 3783 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
| 3784 | ql_dbg(ql_dbg_io, vha, 0xff00, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3785 | "HOST-ABORT: state=PROCESSED.\n"); |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3786 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3787 | cmd->write_data_transferred = 0; |
| 3788 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3789 | |
| 3790 | ql_dbg(ql_dbg_io, vha, 0xff01, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3791 | "HOST-ABORT: state=DATA_IN.\n"); |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3792 | |
| 3793 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3794 | return; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3795 | } else { |
| 3796 | ql_dbg(ql_dbg_io, vha, 0xff03, |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3797 | "HOST-ABORT: state=BAD(%d).\n", |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3798 | cmd->state); |
| 3799 | dump_stack(); |
| 3800 | } |
| 3801 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3802 | cmd->trc_flags |= TRC_FLUSH; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3803 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3804 | } |
| 3805 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3806 | /* |
| 3807 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3808 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3809 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, |
| 3810 | struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3811 | { |
| 3812 | struct qla_hw_data *ha = vha->hw; |
| 3813 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3814 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3815 | struct qla_qpair *qpair = rsp->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3816 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3817 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3818 | /* That could happen only in case of an error/reset/abort */ |
| 3819 | if (status != CTIO_SUCCESS) { |
| 3820 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3821 | "Intermediate CTIO received" |
| 3822 | " (status %x)\n", status); |
| 3823 | } |
| 3824 | return; |
| 3825 | } |
| 3826 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3827 | cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3828 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3829 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3830 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3831 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3832 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3833 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3834 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3835 | |
| 3836 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3837 | switch (status & 0xFFFF) { |
| 3838 | case CTIO_LIP_RESET: |
| 3839 | case CTIO_TARGET_RESET: |
| 3840 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3841 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3842 | case CTIO_TIMEOUT: |
| 3843 | case CTIO_INVALID_RX_ID: |
| 3844 | /* They are OK */ |
| 3845 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3846 | "qla_target(%d): CTIO with " |
| 3847 | "status %#x received, state %x, se_cmd %p, " |
| 3848 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3849 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3850 | status, cmd->state, se_cmd); |
| 3851 | break; |
| 3852 | |
| 3853 | case CTIO_PORT_LOGGED_OUT: |
| 3854 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3855 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3856 | int logged_out = |
| 3857 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3858 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3859 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3860 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3861 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3862 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3863 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3864 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3865 | if (logged_out && cmd->sess) { |
| 3866 | /* |
| 3867 | * Session is already logged out, but we need |
| 3868 | * to notify initiator, who's not aware of this |
| 3869 | */ |
| 3870 | cmd->sess->logout_on_delete = 0; |
| 3871 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3872 | ql_dbg(ql_dbg_disc, vha, 0x20f8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3873 | "%s %d %8phC post del sess\n", |
| 3874 | __func__, __LINE__, cmd->sess->port_name); |
| 3875 | |
| 3876 | qlt_schedule_sess_for_deletion_lock(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3877 | } |
| 3878 | break; |
| 3879 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3880 | case CTIO_DIF_ERROR: { |
| 3881 | struct ctio_crc_from_fw *crc = |
| 3882 | (struct ctio_crc_from_fw *)ctio; |
| 3883 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3884 | "qla_target(%d): CTIO with DIF_ERROR status %x " |
| 3885 | "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " |
| 3886 | "expect_dif[0x%llx]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3887 | vha->vp_idx, status, cmd->state, se_cmd, |
| 3888 | *((u64 *)&crc->actual_dif[0]), |
| 3889 | *((u64 *)&crc->expected_dif[0])); |
| 3890 | |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 3891 | qlt_handle_dif_error(qpair, cmd, ctio); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3892 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3893 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3894 | default: |
| 3895 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3896 | "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] | 3897 | vha->vp_idx, status, cmd->state, se_cmd); |
| 3898 | break; |
| 3899 | } |
| 3900 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3901 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3902 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3903 | * cmd is already aborted/terminated, we don't |
| 3904 | * need to terminate again. The exchange is already |
| 3905 | * cleaned up/freed at FW level. Just cleanup at driver |
| 3906 | * level. |
| 3907 | */ |
| 3908 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3909 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3910 | cmd->trc_flags |= TRC_CTIO_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3911 | if (qlt_term_ctio_exchange(qpair, ctio, cmd, status)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3912 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3913 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3917 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3918 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3919 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3920 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3921 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3922 | cmd->write_data_transferred = 1; |
| 3923 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3924 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3925 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3926 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3927 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3928 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3929 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3930 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3931 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3932 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 3933 | "qla_target(%d): A command in state (%d) should " |
| 3934 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 3935 | } |
| 3936 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3937 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3938 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3939 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 3940 | dump_stack(); |
| 3941 | } |
| 3942 | |
| 3943 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3944 | } |
| 3945 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3946 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 3947 | uint8_t task_codes) |
| 3948 | { |
| 3949 | int fcp_task_attr; |
| 3950 | |
| 3951 | switch (task_codes) { |
| 3952 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3953 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3954 | break; |
| 3955 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3956 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3957 | break; |
| 3958 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3959 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3960 | break; |
| 3961 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3962 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3963 | break; |
| 3964 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3965 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3966 | break; |
| 3967 | default: |
| 3968 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 3969 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 3970 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3971 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3972 | break; |
| 3973 | } |
| 3974 | |
| 3975 | return fcp_task_attr; |
| 3976 | } |
| 3977 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3978 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3979 | uint8_t *); |
| 3980 | /* |
| 3981 | * Process context for I/O path into tcm_qla2xxx code |
| 3982 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3983 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3984 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3985 | scsi_qla_host_t *vha = cmd->vha; |
| 3986 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3987 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3988 | struct atio_from_isp *atio = &cmd->atio; |
| 3989 | unsigned char *cdb; |
| 3990 | unsigned long flags; |
| 3991 | uint32_t data_length; |
| 3992 | int ret, fcp_task_attr, data_dir, bidi = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 3993 | struct qla_qpair *qpair = cmd->qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3994 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3995 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3996 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3997 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3998 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 3999 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 4000 | "cmd with tag %u is aborted\n", |
| 4001 | cmd->atio.u.isp24.exchange_addr); |
| 4002 | goto out_term; |
| 4003 | } |
| 4004 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4005 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4006 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4007 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4008 | |
| 4009 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 4010 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 4011 | bidi = 1; |
| 4012 | data_dir = DMA_TO_DEVICE; |
| 4013 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 4014 | data_dir = DMA_FROM_DEVICE; |
| 4015 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 4016 | data_dir = DMA_TO_DEVICE; |
| 4017 | else |
| 4018 | data_dir = DMA_NONE; |
| 4019 | |
| 4020 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 4021 | atio->u.isp24.fcp_cmnd.task_attr); |
| 4022 | data_length = be32_to_cpu(get_unaligned((uint32_t *) |
| 4023 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 4024 | atio->u.isp24.fcp_cmnd.add_cdb_len])); |
| 4025 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4026 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 4027 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4028 | if (ret != 0) |
| 4029 | goto out_term; |
| 4030 | /* |
| 4031 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( |
| 4032 | */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4033 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4034 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4035 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4036 | return; |
| 4037 | |
| 4038 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4039 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4040 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 4041 | * cmd has not sent to target yet, so pass NULL as the second |
| 4042 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4043 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4044 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4045 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4046 | qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4047 | |
| 4048 | qlt_decr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4049 | 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] | 4050 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4051 | |
| 4052 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4053 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4054 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4055 | } |
| 4056 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4057 | static void qlt_do_work(struct work_struct *work) |
| 4058 | { |
| 4059 | 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] | 4060 | scsi_qla_host_t *vha = cmd->vha; |
| 4061 | unsigned long flags; |
| 4062 | |
| 4063 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4064 | list_del(&cmd->cmd_list); |
| 4065 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4066 | |
| 4067 | __qlt_do_work(cmd); |
| 4068 | } |
| 4069 | |
Quinn Tran | 09620ee | 2017-06-13 20:47:20 -0700 | [diff] [blame] | 4070 | void qlt_clr_qp_table(struct scsi_qla_host *vha) |
| 4071 | { |
| 4072 | unsigned long flags; |
| 4073 | struct qla_hw_data *ha = vha->hw; |
| 4074 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4075 | void *node; |
| 4076 | u64 key = 0; |
| 4077 | |
| 4078 | ql_log(ql_log_info, vha, 0x706c, |
| 4079 | "User update Number of Active Qpairs %d\n", |
| 4080 | ha->tgt.num_act_qpairs); |
| 4081 | |
| 4082 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 4083 | |
| 4084 | btree_for_each_safe64(&tgt->lun_qpair_map, key, node) |
| 4085 | btree_remove64(&tgt->lun_qpair_map, key); |
| 4086 | |
| 4087 | ha->base_qpair->lun_cnt = 0; |
| 4088 | for (key = 0; key < ha->max_qpairs; key++) |
| 4089 | if (ha->queue_pair_map[key]) |
| 4090 | ha->queue_pair_map[key]->lun_cnt = 0; |
| 4091 | |
| 4092 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 4093 | } |
| 4094 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4095 | static void qlt_assign_qpair(struct scsi_qla_host *vha, |
| 4096 | struct qla_tgt_cmd *cmd) |
| 4097 | { |
| 4098 | struct qla_qpair *qpair, *qp; |
| 4099 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 4100 | struct qla_qpair_hint *h; |
| 4101 | |
| 4102 | if (vha->flags.qpairs_available) { |
| 4103 | h = btree_lookup64(&tgt->lun_qpair_map, cmd->unpacked_lun); |
| 4104 | if (unlikely(!h)) { |
| 4105 | /* spread lun to qpair ratio evently */ |
| 4106 | int lcnt = 0, rc; |
| 4107 | struct scsi_qla_host *base_vha = |
| 4108 | pci_get_drvdata(vha->hw->pdev); |
| 4109 | |
| 4110 | qpair = vha->hw->base_qpair; |
| 4111 | if (qpair->lun_cnt == 0) { |
| 4112 | qpair->lun_cnt++; |
| 4113 | h = qla_qpair_to_hint(tgt, qpair); |
| 4114 | BUG_ON(!h); |
| 4115 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4116 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4117 | if (rc) { |
| 4118 | qpair->lun_cnt--; |
| 4119 | ql_log(ql_log_info, vha, 0xd037, |
| 4120 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4121 | cmd->unpacked_lun); |
| 4122 | } |
| 4123 | goto out; |
| 4124 | } else { |
| 4125 | lcnt = qpair->lun_cnt; |
| 4126 | } |
| 4127 | |
| 4128 | h = NULL; |
| 4129 | list_for_each_entry(qp, &base_vha->qp_list, |
| 4130 | qp_list_elem) { |
| 4131 | if (qp->lun_cnt == 0) { |
| 4132 | qp->lun_cnt++; |
| 4133 | h = qla_qpair_to_hint(tgt, qp); |
| 4134 | BUG_ON(!h); |
| 4135 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4136 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4137 | if (rc) { |
| 4138 | qp->lun_cnt--; |
| 4139 | ql_log(ql_log_info, vha, 0xd038, |
| 4140 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4141 | cmd->unpacked_lun); |
| 4142 | } |
| 4143 | qpair = qp; |
| 4144 | goto out; |
| 4145 | } else { |
| 4146 | if (qp->lun_cnt < lcnt) { |
| 4147 | lcnt = qp->lun_cnt; |
| 4148 | qpair = qp; |
| 4149 | continue; |
| 4150 | } |
| 4151 | } |
| 4152 | } |
| 4153 | BUG_ON(!qpair); |
| 4154 | qpair->lun_cnt++; |
| 4155 | h = qla_qpair_to_hint(tgt, qpair); |
| 4156 | BUG_ON(!h); |
| 4157 | rc = btree_insert64(&tgt->lun_qpair_map, |
| 4158 | cmd->unpacked_lun, h, GFP_ATOMIC); |
| 4159 | if (rc) { |
| 4160 | qpair->lun_cnt--; |
| 4161 | ql_log(ql_log_info, vha, 0xd039, |
| 4162 | "Unable to insert lun %llx into lun_qpair_map\n", |
| 4163 | cmd->unpacked_lun); |
| 4164 | } |
| 4165 | } |
| 4166 | } else { |
| 4167 | h = &tgt->qphints[0]; |
| 4168 | } |
| 4169 | out: |
| 4170 | cmd->qpair = h->qpair; |
| 4171 | cmd->se_cmd.cpuid = h->cpuid; |
| 4172 | } |
| 4173 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4174 | 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] | 4175 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4176 | struct atio_from_isp *atio) |
| 4177 | { |
| 4178 | struct se_session *se_sess = sess->se_sess; |
| 4179 | struct qla_tgt_cmd *cmd; |
| 4180 | int tag; |
| 4181 | |
| 4182 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 4183 | if (tag < 0) |
| 4184 | return NULL; |
| 4185 | |
| 4186 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4187 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
Quinn Tran | c5419e2 | 2017-06-13 20:47:16 -0700 | [diff] [blame] | 4188 | cmd->cmd_type = TYPE_TGT_CMD; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4189 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4190 | cmd->state = QLA_TGT_STATE_NEW; |
| 4191 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4192 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4193 | cmd->vha = vha; |
| 4194 | cmd->se_cmd.map_tag = tag; |
| 4195 | cmd->sess = sess; |
| 4196 | cmd->loop_id = sess->loop_id; |
| 4197 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4198 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4199 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4200 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4201 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4202 | cmd->unpacked_lun = scsilun_to_int( |
| 4203 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 4204 | qlt_assign_qpair(vha, cmd); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4205 | cmd->reset_count = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 22d8472 | 2017-06-13 20:47:25 -0700 | [diff] [blame] | 4206 | cmd->vp_idx = vha->vp_idx; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4207 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4208 | return cmd; |
| 4209 | } |
| 4210 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4211 | static void qlt_create_sess_from_atio(struct work_struct *work) |
| 4212 | { |
| 4213 | struct qla_tgt_sess_op *op = container_of(work, |
| 4214 | struct qla_tgt_sess_op, work); |
| 4215 | scsi_qla_host_t *vha = op->vha; |
| 4216 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4217 | struct fc_port *sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4218 | struct qla_tgt_cmd *cmd; |
| 4219 | unsigned long flags; |
| 4220 | uint8_t *s_id = op->atio.u.isp24.fcp_hdr.s_id; |
| 4221 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4222 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4223 | list_del(&op->cmd_list); |
| 4224 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 4225 | |
| 4226 | if (op->aborted) { |
| 4227 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf083, |
| 4228 | "sess_op with tag %u is aborted\n", |
| 4229 | op->atio.u.isp24.exchange_addr); |
| 4230 | goto out_term; |
| 4231 | } |
| 4232 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4233 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf022, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4234 | "qla_target(%d): Unable to find wwn login" |
| 4235 | " (s_id %x:%x:%x), trying to create it manually\n", |
| 4236 | vha->vp_idx, s_id[0], s_id[1], s_id[2]); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4237 | |
| 4238 | if (op->atio.u.raw.entry_count > 1) { |
| 4239 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf023, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4240 | "Dropping multy entry atio %p\n", &op->atio); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4241 | goto out_term; |
| 4242 | } |
| 4243 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4244 | sess = qlt_make_local_sess(vha, s_id); |
| 4245 | /* sess has an extra creation ref. */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4246 | |
| 4247 | if (!sess) |
| 4248 | goto out_term; |
| 4249 | /* |
| 4250 | * Now obtain a pre-allocated session tag using the original op->atio |
| 4251 | * packet header, and dispatch into __qlt_do_work() using the existing |
| 4252 | * process context. |
| 4253 | */ |
| 4254 | cmd = qlt_get_tag(vha, sess, &op->atio); |
| 4255 | if (!cmd) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4256 | struct qla_qpair *qpair = ha->base_qpair; |
| 4257 | |
| 4258 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 4259 | qlt_send_busy(qpair, &op->atio, SAM_STAT_BUSY); |
| 4260 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 4261 | |
| 4262 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4263 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4264 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4265 | kfree(op); |
| 4266 | return; |
| 4267 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4268 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4269 | /* |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 4270 | * __qlt_do_work() will call qlt_put_sess() to release |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4271 | * the extra reference taken above by qlt_make_local_sess() |
| 4272 | */ |
| 4273 | __qlt_do_work(cmd); |
| 4274 | kfree(op); |
| 4275 | return; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4276 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4277 | 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] | 4278 | kfree(op); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4279 | } |
| 4280 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4281 | /* ha->hardware_lock supposed to be held on entry */ |
| 4282 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4283 | struct atio_from_isp *atio) |
| 4284 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4285 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4286 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4287 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4288 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4289 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4290 | |
| 4291 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4292 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4293 | "New command while device %p is shutting down\n", tgt); |
| 4294 | return -EFAULT; |
| 4295 | } |
| 4296 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4297 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
| 4298 | if (unlikely(!sess)) { |
| 4299 | struct qla_tgt_sess_op *op = kzalloc(sizeof(struct qla_tgt_sess_op), |
| 4300 | GFP_ATOMIC); |
| 4301 | if (!op) |
| 4302 | return -ENOMEM; |
| 4303 | |
| 4304 | memcpy(&op->atio, atio, sizeof(*atio)); |
Himanshu Madhani | 78c2106 | 2014-09-25 06:14:44 -0400 | [diff] [blame] | 4305 | op->vha = vha; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4306 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4307 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4308 | list_add_tail(&op->cmd_list, &vha->qla_sess_op_cmd_list); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4309 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4310 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4311 | INIT_WORK(&op->work, qlt_create_sess_from_atio); |
| 4312 | queue_work(qla_tgt_wq, &op->work); |
| 4313 | return 0; |
| 4314 | } |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4315 | |
| 4316 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4317 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4318 | if (sess->deleted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4319 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4320 | "New command while old session %p is being deleted\n", |
| 4321 | sess); |
| 4322 | return -EFAULT; |
| 4323 | } |
| 4324 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4325 | /* |
| 4326 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4327 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4328 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4329 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4330 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4331 | __func__, sess->port_name, |
| 4332 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4333 | return -EFAULT; |
| 4334 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4335 | |
| 4336 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4337 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4338 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4339 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4340 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4341 | ha->tgt.tgt_ops->put_sess(sess); |
| 4342 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4343 | return -ENOMEM; |
| 4344 | } |
| 4345 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4346 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4347 | cmd->trc_flags |= TRC_NEW_CMD; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4348 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4349 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4350 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4351 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4352 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4353 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 4354 | if (vha->flags.qpairs_available) { |
| 4355 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &cmd->work); |
| 4356 | } else if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4357 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4358 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4359 | &cmd->work); |
| 4360 | else |
| 4361 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4362 | &cmd->work); |
| 4363 | } else { |
| 4364 | queue_work(qla_tgt_wq, &cmd->work); |
| 4365 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4366 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4367 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4371 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4372 | int fn, void *iocb, int flags) |
| 4373 | { |
| 4374 | struct scsi_qla_host *vha = sess->vha; |
| 4375 | struct qla_hw_data *ha = vha->hw; |
| 4376 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4377 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4378 | int res; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4379 | |
| 4380 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4381 | if (!mcmd) { |
| 4382 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4383 | "qla_target(%d): Allocation of management " |
| 4384 | "command failed, some commands and their data could " |
| 4385 | "leak\n", vha->vp_idx); |
| 4386 | return -ENOMEM; |
| 4387 | } |
| 4388 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4389 | mcmd->sess = sess; |
| 4390 | |
| 4391 | if (iocb) { |
| 4392 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4393 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4394 | } |
| 4395 | mcmd->tmr_func = fn; |
| 4396 | mcmd->flags = flags; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4397 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4398 | mcmd->qpair = ha->base_qpair; |
Quinn Tran | 72fcd4e | 2017-08-23 15:05:13 -0700 | [diff] [blame] | 4399 | mcmd->vha = vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4400 | |
| 4401 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4402 | case QLA_TGT_LUN_RESET: |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4403 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
| 4404 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4405 | } |
| 4406 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4407 | 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] | 4408 | if (res != 0) { |
| 4409 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, |
| 4410 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", |
| 4411 | sess->vha->vp_idx, res); |
| 4412 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4413 | return -EFAULT; |
| 4414 | } |
| 4415 | |
| 4416 | return 0; |
| 4417 | } |
| 4418 | |
| 4419 | /* ha->hardware_lock supposed to be held on entry */ |
| 4420 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4421 | { |
| 4422 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4423 | struct qla_hw_data *ha = vha->hw; |
| 4424 | struct qla_tgt *tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4425 | struct fc_port *sess; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4426 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4427 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4428 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4429 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4430 | tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4431 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4432 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4433 | |
| 4434 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4435 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4436 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4437 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4438 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4439 | unpacked_lun = |
| 4440 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4441 | |
| 4442 | if (!sess) { |
| 4443 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf024, |
| 4444 | "qla_target(%d): task mgmt fn 0x%x for " |
| 4445 | "non-existant session\n", vha->vp_idx, fn); |
| 4446 | return qlt_sched_sess_work(tgt, QLA_TGT_SESS_WORK_TM, iocb, |
| 4447 | sizeof(struct atio_from_isp)); |
| 4448 | } |
| 4449 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4450 | if (sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4451 | return -EFAULT; |
| 4452 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4453 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4454 | } |
| 4455 | |
| 4456 | /* ha->hardware_lock supposed to be held on entry */ |
| 4457 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4458 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4459 | { |
| 4460 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4461 | struct qla_hw_data *ha = vha->hw; |
| 4462 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4463 | u64 unpacked_lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4464 | int rc; |
| 4465 | |
| 4466 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4467 | if (mcmd == NULL) { |
| 4468 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4469 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4470 | vha->vp_idx, __func__); |
| 4471 | return -ENOMEM; |
| 4472 | } |
| 4473 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4474 | |
| 4475 | mcmd->sess = sess; |
| 4476 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4477 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4478 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4479 | unpacked_lun = |
| 4480 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 4481 | mcmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4482 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4483 | mcmd->qpair = ha->base_qpair; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4484 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4485 | 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] | 4486 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4487 | if (rc != 0) { |
| 4488 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4489 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4490 | vha->vp_idx, rc); |
| 4491 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4492 | return -EFAULT; |
| 4493 | } |
| 4494 | |
| 4495 | return 0; |
| 4496 | } |
| 4497 | |
| 4498 | /* ha->hardware_lock supposed to be held on entry */ |
| 4499 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4500 | struct imm_ntfy_from_isp *iocb) |
| 4501 | { |
| 4502 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4503 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4504 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4505 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4506 | |
| 4507 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4508 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4509 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4510 | 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] | 4511 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4512 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4513 | if (sess == NULL) { |
| 4514 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4515 | "qla_target(%d): task abort for unexisting " |
| 4516 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4517 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4518 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4519 | } |
| 4520 | |
| 4521 | return __qlt_abort_task(vha, iocb, sess); |
| 4522 | } |
| 4523 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4524 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4525 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4526 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4527 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4528 | "%s: se_sess %p / sess %p from" |
| 4529 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4530 | " LOGO failed: %#x\n", |
| 4531 | __func__, |
| 4532 | fcport->se_sess, |
| 4533 | fcport, |
| 4534 | fcport->port_name, fcport->loop_id, |
| 4535 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4536 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4537 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4538 | |
| 4539 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4540 | } |
| 4541 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4542 | /* |
| 4543 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4544 | * |
| 4545 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4546 | * deletion. Returns existing session with matching wwn if present. |
| 4547 | * Null otherwise. |
| 4548 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4549 | struct fc_port * |
| 4550 | 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] | 4551 | 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] | 4552 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4553 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4554 | uint64_t other_wwn; |
| 4555 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4556 | *conflict_sess = NULL; |
| 4557 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4558 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4559 | |
| 4560 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4561 | |
| 4562 | if (wwn == other_wwn) { |
| 4563 | WARN_ON(sess); |
| 4564 | sess = other_sess; |
| 4565 | continue; |
| 4566 | } |
| 4567 | |
| 4568 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4569 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4570 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4571 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4572 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4573 | other_sess, other_sess->loop_id, other_wwn); |
| 4574 | |
| 4575 | /* |
| 4576 | * logout_on_delete is set by default, but another |
| 4577 | * session that has the same s_id/loop_id combo |
| 4578 | * might have cleared it when requested this session |
| 4579 | * deletion, so don't touch it |
| 4580 | */ |
| 4581 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4582 | } else { |
| 4583 | /* |
| 4584 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4585 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4586 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4587 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01b, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4588 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4589 | other_sess, other_sess->loop_id, other_wwn); |
| 4590 | |
| 4591 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4592 | other_sess->keep_nport_handle = 1; |
| 4593 | *conflict_sess = other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4594 | qlt_schedule_sess_for_deletion(other_sess, |
| 4595 | true); |
| 4596 | } |
| 4597 | continue; |
| 4598 | } |
| 4599 | |
| 4600 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4601 | if ((loop_id == other_sess->loop_id) && |
| 4602 | (loop_id != FC_NO_LOOP_ID)) { |
| 4603 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4604 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4605 | other_sess, other_sess->loop_id, other_wwn); |
| 4606 | |
| 4607 | /* Same loop_id but different s_id |
| 4608 | * Ok to kill and logout */ |
| 4609 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4610 | } |
| 4611 | } |
| 4612 | |
| 4613 | return sess; |
| 4614 | } |
| 4615 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4616 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4617 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4618 | { |
| 4619 | struct qla_tgt_sess_op *op; |
| 4620 | struct qla_tgt_cmd *cmd; |
| 4621 | uint32_t key; |
| 4622 | int count = 0; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4623 | unsigned long flags; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4624 | |
| 4625 | key = (((u32)s_id->b.domain << 16) | |
| 4626 | ((u32)s_id->b.area << 8) | |
| 4627 | ((u32)s_id->b.al_pa)); |
| 4628 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4629 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4630 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4631 | 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] | 4632 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4633 | if (op_key == key) { |
| 4634 | op->aborted = true; |
| 4635 | count++; |
| 4636 | } |
| 4637 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4638 | |
| 4639 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4640 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 4641 | if (op_key == key) { |
| 4642 | op->aborted = true; |
| 4643 | count++; |
| 4644 | } |
| 4645 | } |
| 4646 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4647 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4648 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 4649 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4650 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4651 | count++; |
| 4652 | } |
| 4653 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4654 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4655 | |
| 4656 | return count; |
| 4657 | } |
| 4658 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4659 | /* |
| 4660 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4661 | */ |
| 4662 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4663 | struct imm_ntfy_from_isp *iocb) |
| 4664 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4665 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4666 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4667 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4668 | uint64_t wwn; |
| 4669 | port_id_t port_id; |
| 4670 | uint16_t loop_id; |
| 4671 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4672 | int res = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4673 | struct qlt_plogi_ack_t *pla; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4674 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4675 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4676 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4677 | |
| 4678 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4679 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4680 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4681 | port_id.b.rsvd_1 = 0; |
| 4682 | |
| 4683 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4684 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4685 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4686 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4687 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4688 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4689 | iocb->u.isp24.status_subcode, loop_id, |
| 4690 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4691 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4692 | /* res = 1 means ack at the end of thread |
| 4693 | * res = 0 means ack async/later. |
| 4694 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4695 | switch (iocb->u.isp24.status_subcode) { |
| 4696 | case ELS_PLOGI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4697 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4698 | /* Mark all stale commands in qla_tgt_wq for deletion */ |
| 4699 | abort_cmds_for_s_id(vha, &port_id); |
| 4700 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4701 | if (wwn) { |
| 4702 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4703 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4704 | port_id, loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4705 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4706 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4707 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4708 | if (IS_SW_RESV_ADDR(port_id)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4709 | res = 1; |
| 4710 | break; |
| 4711 | } |
| 4712 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4713 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4714 | if (!pla) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4715 | qlt_send_term_imm_notif(vha, iocb, 1); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4716 | break; |
| 4717 | } |
| 4718 | |
| 4719 | res = 0; |
| 4720 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4721 | if (conflict_sess) { |
| 4722 | conflict_sess->login_gen++; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4723 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4724 | QLT_PLOGI_LINK_CONFLICT); |
| 4725 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4726 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4727 | if (!sess) { |
| 4728 | pla->ref_count++; |
| 4729 | qla24xx_post_newsess_work(vha, &port_id, |
| 4730 | iocb->u.isp24.port_name, pla); |
| 4731 | res = 0; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4732 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4733 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4734 | |
| 4735 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4736 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4737 | sess->d_id = port_id; |
| 4738 | sess->login_gen++; |
| 4739 | |
| 4740 | switch (sess->disc_state) { |
| 4741 | case DSC_DELETED: |
| 4742 | qlt_plogi_ack_unref(vha, pla); |
| 4743 | break; |
| 4744 | |
| 4745 | default: |
| 4746 | /* |
| 4747 | * Under normal circumstances we want to release nport handle |
| 4748 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4749 | * The exception is when LOGO is done while another PLOGI with |
| 4750 | * the same nport handle is waiting as might be the case here. |
| 4751 | * Note: there is always a possibily of a race where session |
| 4752 | * deletion has already started for other reasons (e.g. ACL |
| 4753 | * removal) and now PLOGI arrives: |
| 4754 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4755 | * FW must have assigned this PLOGI a new/same handle and we |
| 4756 | * can proceed ACK'ing it as usual when session deletion |
| 4757 | * completes. |
| 4758 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4759 | * bit reached it, the handle has now been released. We'll |
| 4760 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4761 | * back to initiator. Initiator should eventually retry |
| 4762 | * PLOGI and situation will correct itself. |
| 4763 | */ |
| 4764 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4765 | (sess->d_id.b24 == port_id.b24)); |
| 4766 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4767 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4768 | "%s %d %8phC post del sess\n", |
| 4769 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4770 | |
| 4771 | |
| 4772 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4773 | break; |
| 4774 | } |
| 4775 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4776 | break; |
| 4777 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4778 | case ELS_PRLI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4779 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4780 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4781 | if (wwn) { |
| 4782 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4783 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4784 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4785 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4786 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4787 | |
| 4788 | if (conflict_sess) { |
| 4789 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4790 | "PRLI with conflicting sess %p port %8phC\n", |
| 4791 | conflict_sess, conflict_sess->port_name); |
| 4792 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4793 | res = 0; |
| 4794 | break; |
| 4795 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4796 | |
| 4797 | if (sess != NULL) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4798 | if (sess->fw_login_state != DSC_LS_PLOGI_PEND && |
| 4799 | sess->fw_login_state != DSC_LS_PLOGI_COMP) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4800 | /* |
| 4801 | * Impatient initiator sent PRLI before last |
| 4802 | * PLOGI could finish. Will force him to re-try, |
| 4803 | * while last one finishes. |
| 4804 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4805 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4806 | "sess %p PRLI received, before plogi ack.\n", |
| 4807 | sess); |
| 4808 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4809 | res = 0; |
| 4810 | break; |
| 4811 | } |
| 4812 | |
| 4813 | /* |
| 4814 | * This shouldn't happen under normal circumstances, |
| 4815 | * since we have deleted the old session during PLOGI |
| 4816 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4817 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4818 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 4819 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 4820 | |
| 4821 | sess->local = 0; |
| 4822 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4823 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4824 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4825 | |
| 4826 | if (wd3_lo & BIT_7) |
| 4827 | sess->conf_compl_supported = 1; |
| 4828 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4829 | if ((wd3_lo & BIT_4) == 0) |
| 4830 | sess->port_type = FCT_INITIATOR; |
| 4831 | else |
| 4832 | sess->port_type = FCT_TARGET; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4833 | } |
| 4834 | res = 1; /* send notify ack */ |
| 4835 | |
| 4836 | /* Make session global (not used in fabric mode) */ |
| 4837 | if (ha->current_topology != ISP_CFG_F) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4838 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4839 | ql_dbg(ql_dbg_disc, vha, 0x20fa, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4840 | "%s %d %8phC post nack\n", |
| 4841 | __func__, __LINE__, sess->port_name); |
| 4842 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4843 | SRB_NACK_PRLI); |
| 4844 | res = 0; |
| 4845 | } else { |
| 4846 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4847 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4848 | qla2xxx_wake_dpc(vha); |
| 4849 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4850 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4851 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4852 | ql_dbg(ql_dbg_disc, vha, 0x20fb, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4853 | "%s %d %8phC post nack\n", |
| 4854 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4855 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4856 | SRB_NACK_PRLI); |
| 4857 | res = 0; |
| 4858 | } |
| 4859 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4860 | break; |
| 4861 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4862 | case ELS_TPRLO: |
| 4863 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 4864 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 4865 | loop_id = 0xFFFF; |
| 4866 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 4867 | res = 1; |
| 4868 | break; |
| 4869 | } |
| 4870 | /* drop through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4871 | case ELS_LOGO: |
| 4872 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4873 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4874 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 4875 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4876 | |
| 4877 | if (sess) { |
| 4878 | sess->login_gen++; |
| 4879 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4880 | sess->logo_ack_needed = 1; |
| 4881 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 4882 | } |
| 4883 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4884 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4885 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4886 | ql_dbg(ql_dbg_disc, vha, 0x20fc, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4887 | "%s: logo %llx res %d sess %p ", |
| 4888 | __func__, wwn, res, sess); |
| 4889 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4890 | /* |
| 4891 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 4892 | * for LOGO_ACK & sess delete |
| 4893 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4894 | BUG_ON(!sess); |
| 4895 | res = 0; |
| 4896 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4897 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4898 | if (sess) { |
| 4899 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4900 | res = 0; |
| 4901 | } |
| 4902 | /* else logo will be ack */ |
| 4903 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4904 | break; |
| 4905 | case ELS_PDISC: |
| 4906 | case ELS_ADISC: |
| 4907 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4908 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4909 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4910 | qlt_send_notify_ack(ha->base_qpair, |
| 4911 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4912 | tgt->link_reinit_iocb_pending = 0; |
| 4913 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4914 | |
| 4915 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4916 | iocb->u.isp24.port_name, 1); |
| 4917 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4918 | ql_dbg(ql_dbg_disc, vha, 0x20fd, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4919 | "sess %p lid %d|%d DS %d LS %d\n", |
| 4920 | sess, sess->loop_id, loop_id, |
| 4921 | sess->disc_state, sess->fw_login_state); |
| 4922 | } |
| 4923 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4924 | res = 1; /* send notify ack */ |
| 4925 | break; |
| 4926 | } |
| 4927 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4928 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4929 | default: |
| 4930 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 4931 | "qla_target(%d): Unsupported ELS command %x " |
| 4932 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 4933 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 4934 | break; |
| 4935 | } |
| 4936 | |
| 4937 | return res; |
| 4938 | } |
| 4939 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4940 | /* |
| 4941 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4942 | */ |
| 4943 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 4944 | struct imm_ntfy_from_isp *iocb) |
| 4945 | { |
| 4946 | struct qla_hw_data *ha = vha->hw; |
| 4947 | uint32_t add_flags = 0; |
| 4948 | int send_notify_ack = 1; |
| 4949 | uint16_t status; |
| 4950 | |
| 4951 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 4952 | switch (status) { |
| 4953 | case IMM_NTFY_LIP_RESET: |
| 4954 | { |
| 4955 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 4956 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 4957 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4958 | iocb->u.isp24.status_subcode); |
| 4959 | |
| 4960 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 4961 | send_notify_ack = 0; |
| 4962 | break; |
| 4963 | } |
| 4964 | |
| 4965 | case IMM_NTFY_LIP_LINK_REINIT: |
| 4966 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4967 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4968 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 4969 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 4970 | "subcode %x)\n", vha->vp_idx, |
| 4971 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4972 | iocb->u.isp24.status_subcode); |
| 4973 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 4974 | qlt_send_notify_ack(ha->base_qpair, |
| 4975 | &tgt->link_reinit_iocb, 0, 0, 0, 0, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4976 | } |
| 4977 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 4978 | tgt->link_reinit_iocb_pending = 1; |
| 4979 | /* |
| 4980 | * QLogic requires to wait after LINK REINIT for possible |
| 4981 | * PDISC or ADISC ELS commands |
| 4982 | */ |
| 4983 | send_notify_ack = 0; |
| 4984 | break; |
| 4985 | } |
| 4986 | |
| 4987 | case IMM_NTFY_PORT_LOGOUT: |
| 4988 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 4989 | "qla_target(%d): Port logout (loop " |
| 4990 | "%#x, subcode %x)\n", vha->vp_idx, |
| 4991 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4992 | iocb->u.isp24.status_subcode); |
| 4993 | |
| 4994 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 4995 | send_notify_ack = 0; |
| 4996 | /* The sessions will be cleared in the callback, if needed */ |
| 4997 | break; |
| 4998 | |
| 4999 | case IMM_NTFY_GLBL_TPRLO: |
| 5000 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 5001 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 5002 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5003 | send_notify_ack = 0; |
| 5004 | /* The sessions will be cleared in the callback, if needed */ |
| 5005 | break; |
| 5006 | |
| 5007 | case IMM_NTFY_PORT_CONFIG: |
| 5008 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 5009 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 5010 | status); |
| 5011 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 5012 | send_notify_ack = 0; |
| 5013 | /* The sessions will be cleared in the callback, if needed */ |
| 5014 | break; |
| 5015 | |
| 5016 | case IMM_NTFY_GLBL_LOGO: |
| 5017 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 5018 | "qla_target(%d): Link failure detected\n", |
| 5019 | vha->vp_idx); |
| 5020 | /* I_T nexus loss */ |
| 5021 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 5022 | send_notify_ack = 0; |
| 5023 | break; |
| 5024 | |
| 5025 | case IMM_NTFY_IOCB_OVERFLOW: |
| 5026 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 5027 | "qla_target(%d): Cannot provide requested " |
| 5028 | "capability (IOCB overflowed the immediate notify " |
| 5029 | "resource count)\n", vha->vp_idx); |
| 5030 | break; |
| 5031 | |
| 5032 | case IMM_NTFY_ABORT_TASK: |
| 5033 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 5034 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 5035 | "L %#x)\n", vha->vp_idx, |
| 5036 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 5037 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 5038 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 5039 | if (qlt_abort_task(vha, iocb) == 0) |
| 5040 | send_notify_ack = 0; |
| 5041 | break; |
| 5042 | |
| 5043 | case IMM_NTFY_RESOURCE: |
| 5044 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 5045 | "qla_target(%d): Out of resources, host %ld\n", |
| 5046 | vha->vp_idx, vha->host_no); |
| 5047 | break; |
| 5048 | |
| 5049 | case IMM_NTFY_MSG_RX: |
| 5050 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 5051 | "qla_target(%d): Immediate notify task %x\n", |
| 5052 | vha->vp_idx, iocb->u.isp2x.task_flags); |
| 5053 | if (qlt_handle_task_mgmt(vha, iocb) == 0) |
| 5054 | send_notify_ack = 0; |
| 5055 | break; |
| 5056 | |
| 5057 | case IMM_NTFY_ELS: |
| 5058 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 5059 | send_notify_ack = 0; |
| 5060 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5061 | default: |
| 5062 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 5063 | "qla_target(%d): Received unknown immediate " |
| 5064 | "notify status %x\n", vha->vp_idx, status); |
| 5065 | break; |
| 5066 | } |
| 5067 | |
| 5068 | if (send_notify_ack) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5069 | qlt_send_notify_ack(ha->base_qpair, iocb, add_flags, 0, 0, 0, |
| 5070 | 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | /* |
| 5074 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5075 | * This function sends busy to ISP 2xxx or 24xx. |
| 5076 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5077 | static int __qlt_send_busy(struct qla_qpair *qpair, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5078 | struct atio_from_isp *atio, uint16_t status) |
| 5079 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5080 | struct scsi_qla_host *vha = qpair->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5081 | struct ctio7_to_24xx *ctio24; |
| 5082 | struct qla_hw_data *ha = vha->hw; |
| 5083 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5084 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5085 | unsigned long flags; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5086 | u16 temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5087 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5088 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5089 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5090 | atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5091 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5092 | if (!sess) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5093 | qlt_send_term_exchange(qpair, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5094 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5095 | } |
| 5096 | /* Sending marker isn't necessary, since we called from ISR */ |
| 5097 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5098 | pkt = (request_t *)__qla2x00_alloc_iocbs(qpair, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5099 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5100 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5101 | "qla_target(%d): %s failed: unable to allocate " |
| 5102 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5103 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5104 | } |
| 5105 | |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5106 | qpair->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5107 | pkt->entry_count = 1; |
| 5108 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5109 | |
| 5110 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5111 | ctio24->entry_type = CTIO_TYPE7; |
| 5112 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5113 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5114 | ctio24->vp_index = vha->vp_idx; |
| 5115 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5116 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5117 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5118 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5119 | temp = (atio->u.isp24.attr << 9) | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5120 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5121 | CTIO7_FLAGS_DONT_RET_CTIO; |
| 5122 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5123 | /* |
| 5124 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5125 | * if the explicit conformation is used. |
| 5126 | */ |
| 5127 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 5128 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5129 | /* Memory Barrier */ |
| 5130 | wmb(); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 5131 | if (qpair->reqq_start_iocbs) |
| 5132 | qpair->reqq_start_iocbs(qpair); |
| 5133 | else |
| 5134 | qla2x00_start_iocbs(vha, qpair->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5135 | return 0; |
| 5136 | } |
| 5137 | |
| 5138 | /* |
| 5139 | * This routine is used to allocate a command for either a QFull condition |
| 5140 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5141 | * out previously. |
| 5142 | */ |
| 5143 | static void |
| 5144 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5145 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5146 | { |
| 5147 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5148 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5149 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5150 | struct se_session *se_sess; |
| 5151 | struct qla_tgt_cmd *cmd; |
| 5152 | int tag; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5153 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5154 | |
| 5155 | if (unlikely(tgt->tgt_stop)) { |
| 5156 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5157 | "New command while device %p is shutting down\n", tgt); |
| 5158 | return; |
| 5159 | } |
| 5160 | |
| 5161 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5162 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5163 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5164 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5165 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5166 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5167 | |
| 5168 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5169 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5170 | vha->vp_idx, __func__, |
| 5171 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5172 | |
| 5173 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5174 | return; |
| 5175 | } |
| 5176 | |
| 5177 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5178 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5179 | if (!sess) |
| 5180 | return; |
| 5181 | |
| 5182 | se_sess = sess->se_sess; |
| 5183 | |
| 5184 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 5185 | if (tag < 0) |
| 5186 | return; |
| 5187 | |
| 5188 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 5189 | if (!cmd) { |
| 5190 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5191 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5192 | vha->vp_idx, __func__); |
| 5193 | |
| 5194 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5195 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5196 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5197 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5198 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5199 | |
| 5200 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5201 | return; |
| 5202 | } |
| 5203 | |
| 5204 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 5205 | |
| 5206 | qlt_incr_num_pend_cmds(vha); |
| 5207 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5208 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5209 | |
| 5210 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5211 | cmd->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5212 | cmd->reset_count = ha->base_qpair->chip_reset; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5213 | cmd->q_full = 1; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5214 | cmd->qpair = ha->base_qpair; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5215 | |
| 5216 | if (qfull) { |
| 5217 | cmd->q_full = 1; |
| 5218 | /* NOTE: borrowing the state field to carry the status */ |
| 5219 | cmd->state = status; |
| 5220 | } else |
| 5221 | cmd->term_exchg = 1; |
| 5222 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5223 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5224 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5225 | |
| 5226 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5227 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5228 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5229 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5230 | vha->hw->tgt.num_qfull_cmds_alloc; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5231 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5232 | } |
| 5233 | |
| 5234 | int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5235 | qlt_free_qfull_cmds(struct qla_qpair *qpair) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5236 | { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5237 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5238 | struct qla_hw_data *ha = vha->hw; |
| 5239 | unsigned long flags; |
| 5240 | struct qla_tgt_cmd *cmd, *tcmd; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5241 | struct list_head free_list, q_full_list; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5242 | int rc = 0; |
| 5243 | |
| 5244 | if (list_empty(&ha->tgt.q_full_list)) |
| 5245 | return 0; |
| 5246 | |
| 5247 | INIT_LIST_HEAD(&free_list); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5248 | INIT_LIST_HEAD(&q_full_list); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5249 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5250 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5251 | if (list_empty(&ha->tgt.q_full_list)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5252 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5253 | return 0; |
| 5254 | } |
| 5255 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5256 | list_splice_init(&vha->hw->tgt.q_full_list, &q_full_list); |
| 5257 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5258 | |
| 5259 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 5260 | list_for_each_entry_safe(cmd, tcmd, &q_full_list, cmd_list) { |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5261 | if (cmd->q_full) |
| 5262 | /* cmd->state is a borrowed field to hold status */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5263 | rc = __qlt_send_busy(qpair, &cmd->atio, cmd->state); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5264 | else if (cmd->term_exchg) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5265 | rc = __qlt_send_term_exchange(qpair, NULL, &cmd->atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5266 | |
| 5267 | if (rc == -ENOMEM) |
| 5268 | break; |
| 5269 | |
| 5270 | if (cmd->q_full) |
| 5271 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5272 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5273 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5274 | else if (cmd->term_exchg) |
| 5275 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5276 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5277 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5278 | else |
| 5279 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5280 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5281 | cmd); |
| 5282 | |
| 5283 | list_del(&cmd->cmd_list); |
| 5284 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5285 | |
| 5286 | /* piggy back on hardware_lock for protection */ |
| 5287 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5288 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5289 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5290 | |
| 5291 | cmd = NULL; |
| 5292 | |
| 5293 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5294 | list_del(&cmd->cmd_list); |
| 5295 | /* This cmd was never sent to TCM. There is no need |
| 5296 | * to schedule free or call free_cmd |
| 5297 | */ |
| 5298 | qlt_free_cmd(cmd); |
| 5299 | } |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5300 | |
| 5301 | if (!list_empty(&q_full_list)) { |
| 5302 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 5303 | list_splice(&q_full_list, &vha->hw->tgt.q_full_list); |
| 5304 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 5305 | } |
| 5306 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5307 | return rc; |
| 5308 | } |
| 5309 | |
| 5310 | static void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5311 | qlt_send_busy(struct qla_qpair *qpair, struct atio_from_isp *atio, |
| 5312 | uint16_t status) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5313 | { |
| 5314 | int rc = 0; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5315 | struct scsi_qla_host *vha = qpair->vha; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5316 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5317 | rc = __qlt_send_busy(qpair, atio, status); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5318 | if (rc == -ENOMEM) |
| 5319 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5320 | } |
| 5321 | |
| 5322 | static int |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5323 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, struct qla_qpair *qpair, |
| 5324 | struct atio_from_isp *atio, uint8_t ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5325 | { |
| 5326 | struct qla_hw_data *ha = vha->hw; |
| 5327 | uint16_t status; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5328 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5329 | |
| 5330 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5331 | return 0; |
| 5332 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5333 | if (!ha_locked) |
| 5334 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5335 | status = temp_sam_status; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5336 | qlt_send_busy(qpair, atio, status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5337 | if (!ha_locked) |
| 5338 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5339 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5340 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | /* ha->hardware_lock supposed to be held on entry */ |
| 5344 | /* called via callback from qla2xxx */ |
| 5345 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5346 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5347 | { |
| 5348 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5349 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5350 | int rc; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5351 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5352 | |
| 5353 | if (unlikely(tgt == NULL)) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5354 | ql_dbg(ql_dbg_tgt, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5355 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5356 | return; |
| 5357 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5358 | /* |
| 5359 | * In tgt_stop mode we also should allow all requests to pass. |
| 5360 | * Otherwise, some commands can stuck. |
| 5361 | */ |
| 5362 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5363 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5364 | |
| 5365 | switch (atio->u.raw.entry_type) { |
| 5366 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5367 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5368 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5369 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5370 | "qla_target(%d): ATIO_TYPE7 " |
| 5371 | "received with UNKNOWN exchange address, " |
| 5372 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5373 | if (!ha_locked) |
| 5374 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5375 | qlt_send_busy(ha->base_qpair, atio, |
| 5376 | SAM_STAT_TASK_SET_FULL); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5377 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5378 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 5379 | flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5380 | break; |
| 5381 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5382 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5383 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5384 | rc = qlt_chk_qfull_thresh_hold(vha, ha->base_qpair, |
| 5385 | atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5386 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5387 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5388 | return; |
| 5389 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5390 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5391 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5392 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5393 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5394 | if (unlikely(rc != 0)) { |
| 5395 | if (rc == -ESRCH) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5396 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5397 | spin_lock_irqsave(&ha->hardware_lock, |
| 5398 | flags); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5399 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5400 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5401 | qlt_send_busy(ha->base_qpair, atio, |
| 5402 | SAM_STAT_BUSY); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5403 | #else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5404 | qlt_send_term_exchange(ha->base_qpair, NULL, |
| 5405 | atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5406 | #endif |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5407 | if (!ha_locked) |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5408 | spin_unlock_irqrestore( |
| 5409 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5410 | } else { |
| 5411 | if (tgt->tgt_stop) { |
| 5412 | ql_dbg(ql_dbg_tgt, vha, 0xe059, |
| 5413 | "qla_target: Unable to send " |
| 5414 | "command to target for req, " |
| 5415 | "ignoring.\n"); |
| 5416 | } else { |
| 5417 | ql_dbg(ql_dbg_tgt, vha, 0xe05a, |
| 5418 | "qla_target(%d): Unable to send " |
| 5419 | "command to target, sending BUSY " |
| 5420 | "status.\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5421 | if (!ha_locked) |
| 5422 | spin_lock_irqsave( |
| 5423 | &ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5424 | qlt_send_busy(ha->base_qpair, |
| 5425 | atio, SAM_STAT_BUSY); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5426 | if (!ha_locked) |
| 5427 | spin_unlock_irqrestore( |
| 5428 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5429 | } |
| 5430 | } |
| 5431 | } |
| 5432 | break; |
| 5433 | |
| 5434 | case IMMED_NOTIFY_TYPE: |
| 5435 | { |
| 5436 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5437 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5438 | "qla_target(%d): Received ATIO packet %x " |
| 5439 | "with error status %x\n", vha->vp_idx, |
| 5440 | atio->u.raw.entry_type, |
| 5441 | atio->u.isp2x.entry_status); |
| 5442 | break; |
| 5443 | } |
| 5444 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5445 | |
| 5446 | if (!ha_locked) |
| 5447 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5448 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5449 | if (!ha_locked) |
| 5450 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5451 | break; |
| 5452 | } |
| 5453 | |
| 5454 | default: |
| 5455 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5456 | "qla_target(%d): Received unknown ATIO atio " |
| 5457 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5458 | break; |
| 5459 | } |
| 5460 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5461 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | /* ha->hardware_lock supposed to be held on entry */ |
| 5465 | /* called via callback from qla2xxx */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5466 | static void qlt_response_pkt(struct scsi_qla_host *vha, |
| 5467 | struct rsp_que *rsp, response_t *pkt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5468 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5469 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5470 | |
| 5471 | if (unlikely(tgt == NULL)) { |
| 5472 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
Quinn Tran | 60a9ead | 2017-06-13 20:47:28 -0700 | [diff] [blame] | 5473 | "qla_target(%d): Response pkt %x received, but no tgt (ha %p)\n", |
| 5474 | vha->vp_idx, pkt->entry_type, vha->hw); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5475 | return; |
| 5476 | } |
| 5477 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5478 | /* |
| 5479 | * In tgt_stop mode we also should allow all requests to pass. |
| 5480 | * Otherwise, some commands can stuck. |
| 5481 | */ |
| 5482 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5483 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5484 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5485 | case CTIO_TYPE7: |
| 5486 | { |
| 5487 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5488 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5489 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5490 | entry); |
| 5491 | break; |
| 5492 | } |
| 5493 | |
| 5494 | case ACCEPT_TGT_IO_TYPE: |
| 5495 | { |
| 5496 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5497 | int rc; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5498 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5499 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5500 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5501 | "qla_target(%d): ATIO with error " |
| 5502 | "status %x received\n", vha->vp_idx, |
| 5503 | le16_to_cpu(atio->u.isp2x.status)); |
| 5504 | break; |
| 5505 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5506 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5507 | rc = qlt_chk_qfull_thresh_hold(vha, rsp->qpair, atio, 1); |
Quinn Tran | ba68a63 | 2017-06-02 09:12:06 -0700 | [diff] [blame] | 5508 | if (rc != 0) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5509 | return; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5510 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5511 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5512 | if (unlikely(rc != 0)) { |
| 5513 | if (rc == -ESRCH) { |
| 5514 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5515 | qlt_send_busy(rsp->qpair, atio, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5516 | #else |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5517 | qlt_send_term_exchange(rsp->qpair, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5518 | #endif |
| 5519 | } else { |
| 5520 | if (tgt->tgt_stop) { |
| 5521 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5522 | "qla_target: Unable to send " |
| 5523 | "command to target, sending TERM " |
| 5524 | "EXCHANGE for rsp\n"); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5525 | qlt_send_term_exchange(rsp->qpair, NULL, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5526 | atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5527 | } else { |
| 5528 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5529 | "qla_target(%d): Unable to send " |
| 5530 | "command to target, sending BUSY " |
| 5531 | "status\n", vha->vp_idx); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5532 | qlt_send_busy(rsp->qpair, atio, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5533 | } |
| 5534 | } |
| 5535 | } |
| 5536 | } |
| 5537 | break; |
| 5538 | |
| 5539 | case CONTINUE_TGT_IO_TYPE: |
| 5540 | { |
| 5541 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5542 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5543 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5544 | entry); |
| 5545 | break; |
| 5546 | } |
| 5547 | |
| 5548 | case CTIO_A64_TYPE: |
| 5549 | { |
| 5550 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5551 | qlt_do_ctio_completion(vha, rsp, entry->handle, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5552 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5553 | entry); |
| 5554 | break; |
| 5555 | } |
| 5556 | |
| 5557 | case IMMED_NOTIFY_TYPE: |
| 5558 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5559 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5560 | break; |
| 5561 | |
| 5562 | case NOTIFY_ACK_TYPE: |
| 5563 | if (tgt->notify_ack_expected > 0) { |
| 5564 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 5565 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5566 | "NOTIFY_ACK seq %08x status %x\n", |
| 5567 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5568 | le16_to_cpu(entry->u.isp2x.status)); |
| 5569 | tgt->notify_ack_expected--; |
| 5570 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5571 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5572 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5573 | "qla_target(%d): NOTIFY_ACK " |
| 5574 | "failed %x\n", vha->vp_idx, |
| 5575 | le16_to_cpu(entry->u.isp2x.status)); |
| 5576 | } |
| 5577 | } else { |
| 5578 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5579 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5580 | vha->vp_idx); |
| 5581 | } |
| 5582 | break; |
| 5583 | |
| 5584 | case ABTS_RECV_24XX: |
| 5585 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5586 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5587 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5588 | break; |
| 5589 | |
| 5590 | case ABTS_RESP_24XX: |
| 5591 | if (tgt->abts_resp_expected > 0) { |
| 5592 | struct abts_resp_from_24xx_fw *entry = |
| 5593 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5594 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5595 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5596 | entry->compl_status); |
| 5597 | tgt->abts_resp_expected--; |
| 5598 | if (le16_to_cpu(entry->compl_status) != |
| 5599 | ABTS_RESP_COMPL_SUCCESS) { |
| 5600 | if ((entry->error_subcode1 == 0x1E) && |
| 5601 | (entry->error_subcode2 == 0)) { |
| 5602 | /* |
| 5603 | * We've got a race here: aborted |
| 5604 | * exchange not terminated, i.e. |
| 5605 | * response for the aborted command was |
| 5606 | * sent between the abort request was |
| 5607 | * received and processed. |
| 5608 | * Unfortunately, the firmware has a |
| 5609 | * silly requirement that all aborted |
| 5610 | * exchanges must be explicitely |
| 5611 | * terminated, otherwise it refuses to |
| 5612 | * send responses for the abort |
| 5613 | * requests. So, we have to |
| 5614 | * (re)terminate the exchange and retry |
| 5615 | * the abort response. |
| 5616 | */ |
| 5617 | qlt_24xx_retry_term_exchange(vha, |
| 5618 | entry); |
| 5619 | } else |
| 5620 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5621 | "qla_target(%d): ABTS_RESP_24XX " |
| 5622 | "failed %x (subcode %x:%x)", |
| 5623 | vha->vp_idx, entry->compl_status, |
| 5624 | entry->error_subcode1, |
| 5625 | entry->error_subcode2); |
| 5626 | } |
| 5627 | } else { |
| 5628 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5629 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5630 | "received\n", vha->vp_idx); |
| 5631 | } |
| 5632 | break; |
| 5633 | |
| 5634 | default: |
| 5635 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5636 | "qla_target(%d): Received unknown response pkt " |
| 5637 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5638 | break; |
| 5639 | } |
| 5640 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5641 | } |
| 5642 | |
| 5643 | /* |
| 5644 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5645 | */ |
| 5646 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5647 | uint16_t *mailbox) |
| 5648 | { |
| 5649 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5650 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5651 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5652 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 5653 | if (!tgt || tgt->tgt_stop || tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5654 | return; |
| 5655 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5656 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5657 | IS_QLA2100(ha)) |
| 5658 | return; |
| 5659 | /* |
| 5660 | * In tgt_stop mode we also should allow all requests to pass. |
| 5661 | * Otherwise, some commands can stuck. |
| 5662 | */ |
| 5663 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5664 | |
| 5665 | switch (code) { |
| 5666 | case MBA_RESET: /* Reset */ |
| 5667 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5668 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5669 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5670 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5671 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5672 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5673 | break; |
| 5674 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5675 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5676 | break; |
| 5677 | |
| 5678 | case MBA_LOOP_UP: |
| 5679 | { |
| 5680 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5681 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5682 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5683 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5684 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5685 | if (tgt->link_reinit_iocb_pending) { |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5686 | qlt_send_notify_ack(ha->base_qpair, |
| 5687 | (void *)&tgt->link_reinit_iocb, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5688 | 0, 0, 0, 0, 0, 0); |
| 5689 | tgt->link_reinit_iocb_pending = 0; |
| 5690 | } |
| 5691 | break; |
| 5692 | } |
| 5693 | |
| 5694 | case MBA_LIP_OCCURRED: |
| 5695 | case MBA_LOOP_DOWN: |
| 5696 | case MBA_LIP_RESET: |
| 5697 | case MBA_RSCN_UPDATE: |
| 5698 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5699 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5700 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5701 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5702 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5703 | break; |
| 5704 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5705 | case MBA_REJECTED_FCP_CMD: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5706 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017, |
| 5707 | "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", |
| 5708 | vha->vp_idx, |
| 5709 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5710 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5711 | |
| 5712 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 5713 | /* exchange starvation. */ |
| 5714 | vha->hw->exch_starvation++; |
| 5715 | if (vha->hw->exch_starvation > 5) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5716 | ql_log(ql_log_warn, vha, 0xd03a, |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5717 | "Exchange starvation-. Resetting RISC\n"); |
| 5718 | |
| 5719 | vha->hw->exch_starvation = 0; |
| 5720 | if (IS_P3P_TYPE(vha->hw)) |
| 5721 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 5722 | &vha->dpc_flags); |
| 5723 | else |
| 5724 | set_bit(ISP_ABORT_NEEDED, |
| 5725 | &vha->dpc_flags); |
| 5726 | qla2xxx_wake_dpc(vha); |
| 5727 | } |
| 5728 | } |
| 5729 | break; |
| 5730 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5731 | case MBA_PORT_UPDATE: |
| 5732 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5733 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5734 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5735 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5736 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5737 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5738 | |
| 5739 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5740 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5741 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 5742 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5743 | vha->hw->exch_starvation = 0; |
| 5744 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5745 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 5746 | "Async MB 2: Port Logged Out\n"); |
| 5747 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5748 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5749 | break; |
| 5750 | } |
| 5751 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 5755 | uint16_t loop_id) |
| 5756 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5757 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5758 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5759 | unsigned long flags; |
| 5760 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5761 | |
| 5762 | fcport = kzalloc(sizeof(*fcport), GFP_KERNEL); |
| 5763 | if (!fcport) { |
| 5764 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 5765 | "qla_target(%d): Allocation of tmp FC port failed", |
| 5766 | vha->vp_idx); |
| 5767 | return NULL; |
| 5768 | } |
| 5769 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5770 | fcport->loop_id = loop_id; |
| 5771 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 5772 | rc = qla24xx_gpdb_wait(vha, fcport, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5773 | if (rc != QLA_SUCCESS) { |
| 5774 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 5775 | "qla_target(%d): Failed to retrieve fcport " |
| 5776 | "information -- get_port_database() returned %x " |
| 5777 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 5778 | kfree(fcport); |
| 5779 | return NULL; |
| 5780 | } |
| 5781 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5782 | del = NULL; |
| 5783 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5784 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 5785 | |
| 5786 | if (tfcp) { |
| 5787 | tfcp->d_id = fcport->d_id; |
| 5788 | tfcp->port_type = fcport->port_type; |
| 5789 | tfcp->supported_classes = fcport->supported_classes; |
| 5790 | tfcp->flags |= fcport->flags; |
| 5791 | |
| 5792 | del = fcport; |
| 5793 | fcport = tfcp; |
| 5794 | } else { |
| 5795 | if (vha->hw->current_topology == ISP_CFG_F) |
| 5796 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 5797 | |
| 5798 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 5799 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 5800 | vha->fcport_count++; |
| 5801 | fcport->login_gen++; |
| 5802 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 5803 | fcport->login_succ = 1; |
| 5804 | newfcport = 1; |
| 5805 | } |
| 5806 | |
| 5807 | fcport->deleted = 0; |
| 5808 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5809 | |
| 5810 | switch (vha->host->active_mode) { |
| 5811 | case MODE_INITIATOR: |
| 5812 | case MODE_DUAL: |
| 5813 | if (newfcport) { |
| 5814 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5815 | ql_dbg(ql_dbg_disc, vha, 0x20fe, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5816 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 5817 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5818 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 5819 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5820 | ql_dbg(ql_dbg_disc, vha, 0x20ff, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5821 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 5822 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5823 | qla24xx_post_gpsc_work(vha, fcport); |
| 5824 | } |
| 5825 | } |
| 5826 | break; |
| 5827 | |
| 5828 | case MODE_TARGET: |
| 5829 | default: |
| 5830 | break; |
| 5831 | } |
| 5832 | if (del) |
| 5833 | qla2x00_free_fcport(del); |
| 5834 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5835 | return fcport; |
| 5836 | } |
| 5837 | |
| 5838 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5839 | 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] | 5840 | uint8_t *s_id) |
| 5841 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5842 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5843 | fc_port_t *fcport = NULL; |
| 5844 | int rc, global_resets; |
| 5845 | uint16_t loop_id = 0; |
| 5846 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5847 | if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) { |
| 5848 | /* |
| 5849 | * This is Domain Controller, so it should be |
| 5850 | * OK to drop SCSI commands from it. |
| 5851 | */ |
| 5852 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 5853 | "Unable to find initiator with S_ID %x:%x:%x", |
| 5854 | s_id[0], s_id[1], s_id[2]); |
| 5855 | return NULL; |
| 5856 | } |
| 5857 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5858 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 5859 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5860 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5861 | global_resets = |
| 5862 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5863 | |
| 5864 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 5865 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5866 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5867 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5868 | ql_log(ql_log_info, vha, 0xf071, |
| 5869 | "qla_target(%d): Unable to find " |
| 5870 | "initiator with S_ID %x:%x:%x", |
| 5871 | vha->vp_idx, s_id[0], s_id[1], |
| 5872 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5873 | |
| 5874 | if (rc == -ENOENT) { |
| 5875 | qlt_port_logo_t logo; |
| 5876 | sid_to_portid(s_id, &logo.id); |
| 5877 | logo.cmd_count = 1; |
| 5878 | qlt_send_first_logo(vha, &logo); |
| 5879 | } |
| 5880 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5881 | return NULL; |
| 5882 | } |
| 5883 | |
| 5884 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5885 | if (!fcport) { |
| 5886 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5887 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5888 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5889 | |
| 5890 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5891 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5892 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 5893 | "qla_target(%d): global reset during session discovery " |
| 5894 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 5895 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5896 | atomic_read(&vha->vha_tgt. |
| 5897 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5898 | goto retry; |
| 5899 | } |
| 5900 | |
| 5901 | sess = qlt_create_sess(vha, fcport, true); |
| 5902 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5903 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5904 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5905 | return sess; |
| 5906 | } |
| 5907 | |
| 5908 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 5909 | struct qla_tgt_sess_work_param *prm) |
| 5910 | { |
| 5911 | struct scsi_qla_host *vha = tgt->vha; |
| 5912 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5913 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5914 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5915 | uint32_t be_s_id; |
| 5916 | uint8_t s_id[3]; |
| 5917 | int rc; |
| 5918 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5919 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5920 | |
| 5921 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5922 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5923 | |
| 5924 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 5925 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 5926 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 5927 | |
| 5928 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5929 | (unsigned char *)&be_s_id); |
| 5930 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5931 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5932 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5933 | sess = qlt_make_local_sess(vha, s_id); |
| 5934 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5935 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5936 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5937 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5938 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5939 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5940 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5941 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5942 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5943 | } |
| 5944 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5945 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5946 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5947 | "%s: kref_get fail %8phC \n", |
| 5948 | __func__, sess->port_name); |
| 5949 | sess = NULL; |
| 5950 | goto out_term2; |
| 5951 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5952 | } |
| 5953 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5954 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5955 | ha->tgt.tgt_ops->put_sess(sess); |
| 5956 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 5957 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5958 | if (rc != 0) |
| 5959 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5960 | return; |
| 5961 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5962 | out_term2: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5963 | if (sess) |
| 5964 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5965 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5966 | |
| 5967 | out_term: |
| 5968 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 5969 | qlt_24xx_send_abts_resp(ha->base_qpair, &prm->abts, |
| 5970 | FCP_TMF_REJECTED, false); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5971 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5972 | } |
| 5973 | |
| 5974 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 5975 | struct qla_tgt_sess_work_param *prm) |
| 5976 | { |
| 5977 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 5978 | struct scsi_qla_host *vha = tgt->vha; |
| 5979 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5980 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5981 | unsigned long flags; |
| 5982 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 5983 | int rc; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 5984 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 5985 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5986 | void *iocb; |
| 5987 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5988 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5989 | |
| 5990 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5991 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5992 | |
| 5993 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 5994 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 5995 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5996 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5997 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5998 | sess = qlt_make_local_sess(vha, s_id); |
| 5999 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6000 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 6001 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6002 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6003 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6004 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6005 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6006 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6007 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 6008 | } |
| 6009 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6010 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6011 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6012 | "%s: kref_get fail %8phC\n", |
| 6013 | __func__, sess->port_name); |
| 6014 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6015 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6016 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | iocb = a; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6020 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 6021 | unpacked_lun = |
| 6022 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6023 | |
| 6024 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6025 | ha->tgt.tgt_ops->put_sess(sess); |
| 6026 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 6027 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6028 | if (rc != 0) |
| 6029 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6030 | return; |
| 6031 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 6032 | out_term2: |
| 6033 | if (sess) |
| 6034 | ha->tgt.tgt_ops->put_sess(sess); |
| 6035 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6036 | out_term: |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6037 | 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] | 6038 | } |
| 6039 | |
| 6040 | static void qlt_sess_work_fn(struct work_struct *work) |
| 6041 | { |
| 6042 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 6043 | struct scsi_qla_host *vha = tgt->vha; |
| 6044 | unsigned long flags; |
| 6045 | |
| 6046 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 6047 | |
| 6048 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6049 | while (!list_empty(&tgt->sess_works_list)) { |
| 6050 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 6051 | tgt->sess_works_list.next, typeof(*prm), |
| 6052 | sess_works_list_entry); |
| 6053 | |
| 6054 | /* |
| 6055 | * This work can be scheduled on several CPUs at time, so we |
| 6056 | * must delete the entry to eliminate double processing |
| 6057 | */ |
| 6058 | list_del(&prm->sess_works_list_entry); |
| 6059 | |
| 6060 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6061 | |
| 6062 | switch (prm->type) { |
| 6063 | case QLA_TGT_SESS_WORK_ABORT: |
| 6064 | qlt_abort_work(tgt, prm); |
| 6065 | break; |
| 6066 | case QLA_TGT_SESS_WORK_TM: |
| 6067 | qlt_tmr_work(tgt, prm); |
| 6068 | break; |
| 6069 | default: |
| 6070 | BUG_ON(1); |
| 6071 | break; |
| 6072 | } |
| 6073 | |
| 6074 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 6075 | |
| 6076 | kfree(prm); |
| 6077 | } |
| 6078 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 6079 | } |
| 6080 | |
| 6081 | /* Must be called under tgt_host_action_mutex */ |
| 6082 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 6083 | { |
| 6084 | struct qla_tgt *tgt; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6085 | int rc, i; |
| 6086 | struct qla_qpair_hint *h; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6087 | |
| 6088 | if (!QLA_TGT_MODE_ENABLED()) |
| 6089 | return 0; |
| 6090 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 6091 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 6092 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 6093 | "This adapter does not support target mode.\n"); |
| 6094 | return 0; |
| 6095 | } |
| 6096 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6097 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6098 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6099 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6100 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6101 | |
| 6102 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 6103 | if (!tgt) { |
| 6104 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 6105 | "Unable to allocate struct qla_tgt\n"); |
| 6106 | return -ENOMEM; |
| 6107 | } |
| 6108 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6109 | tgt->qphints = kzalloc((ha->max_qpairs + 1) * |
| 6110 | sizeof(struct qla_qpair_hint), GFP_KERNEL); |
| 6111 | if (!tgt->qphints) { |
| 6112 | kfree(tgt); |
| 6113 | ql_log(ql_log_warn, base_vha, 0x0197, |
| 6114 | "Unable to allocate qpair hints.\n"); |
| 6115 | return -ENOMEM; |
| 6116 | } |
| 6117 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6118 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 6119 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 6120 | |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 6121 | rc = btree_init64(&tgt->lun_qpair_map); |
| 6122 | if (rc) { |
| 6123 | kfree(tgt->qphints); |
| 6124 | kfree(tgt); |
| 6125 | ql_log(ql_log_info, base_vha, 0x0198, |
| 6126 | "Unable to initialize lun_qpair_map btree\n"); |
| 6127 | return -EIO; |
| 6128 | } |
| 6129 | h = &tgt->qphints[0]; |
| 6130 | h->qpair = ha->base_qpair; |
| 6131 | INIT_LIST_HEAD(&h->hint_elem); |
| 6132 | h->cpuid = ha->base_qpair->cpuid; |
| 6133 | list_add_tail(&h->hint_elem, &ha->base_qpair->hints_list); |
| 6134 | |
| 6135 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6136 | unsigned long flags; |
| 6137 | |
| 6138 | struct qla_qpair *qpair = ha->queue_pair_map[i]; |
| 6139 | h = &tgt->qphints[i + 1]; |
| 6140 | INIT_LIST_HEAD(&h->hint_elem); |
| 6141 | if (qpair) { |
| 6142 | h->qpair = qpair; |
| 6143 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
| 6144 | list_add_tail(&h->hint_elem, &qpair->hints_list); |
| 6145 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
| 6146 | h->cpuid = qpair->cpuid; |
| 6147 | } |
| 6148 | } |
| 6149 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6150 | tgt->ha = ha; |
| 6151 | tgt->vha = base_vha; |
| 6152 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6153 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6154 | spin_lock_init(&tgt->sess_work_lock); |
| 6155 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6156 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6157 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6158 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6159 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6160 | |
| 6161 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6162 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6163 | base_vha->vp_idx); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6164 | /* 3 is reserved */ |
| 6165 | 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] | 6166 | |
| 6167 | mutex_lock(&qla_tgt_mutex); |
| 6168 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6169 | mutex_unlock(&qla_tgt_mutex); |
| 6170 | |
Quinn Tran | f1443ee | 2017-03-15 09:48:51 -0700 | [diff] [blame] | 6171 | if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target) |
| 6172 | ha->tgt.tgt_ops->add_target(base_vha); |
| 6173 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6174 | return 0; |
| 6175 | } |
| 6176 | |
| 6177 | /* Must be called under tgt_host_action_mutex */ |
| 6178 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6179 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6180 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6181 | return 0; |
| 6182 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6183 | if (vha->fc_vport) { |
| 6184 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6185 | return 0; |
| 6186 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6187 | |
| 6188 | /* free left over qfull cmds */ |
| 6189 | qlt_init_term_exchange(vha); |
| 6190 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6191 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6192 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6193 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6194 | |
| 6195 | return 0; |
| 6196 | } |
| 6197 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6198 | void qlt_remove_target_resources(struct qla_hw_data *ha) |
| 6199 | { |
| 6200 | struct scsi_qla_host *node; |
| 6201 | u32 key = 0; |
| 6202 | |
| 6203 | btree_for_each_safe32(&ha->tgt.host_map, key, node) |
| 6204 | btree_remove32(&ha->tgt.host_map, key); |
| 6205 | |
| 6206 | btree_destroy32(&ha->tgt.host_map); |
| 6207 | } |
| 6208 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6209 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6210 | unsigned char *b) |
| 6211 | { |
| 6212 | int i; |
| 6213 | |
| 6214 | pr_debug("qla2xxx HW vha->node_name: "); |
| 6215 | for (i = 0; i < WWN_SIZE; i++) |
| 6216 | pr_debug("%02x ", vha->node_name[i]); |
| 6217 | pr_debug("\n"); |
| 6218 | pr_debug("qla2xxx HW vha->port_name: "); |
| 6219 | for (i = 0; i < WWN_SIZE; i++) |
| 6220 | pr_debug("%02x ", vha->port_name[i]); |
| 6221 | pr_debug("\n"); |
| 6222 | |
| 6223 | pr_debug("qla2xxx passed configfs WWPN: "); |
| 6224 | put_unaligned_be64(wwpn, b); |
| 6225 | for (i = 0; i < WWN_SIZE; i++) |
| 6226 | pr_debug("%02x ", b[i]); |
| 6227 | pr_debug("\n"); |
| 6228 | } |
| 6229 | |
| 6230 | /** |
| 6231 | * qla_tgt_lport_register - register lport with external module |
| 6232 | * |
| 6233 | * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops |
| 6234 | * @wwpn: Passwd FC target WWPN |
| 6235 | * @callback: lport initialization callback for tcm_qla2xxx code |
| 6236 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
| 6237 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6238 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6239 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6240 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6241 | { |
| 6242 | struct qla_tgt *tgt; |
| 6243 | struct scsi_qla_host *vha; |
| 6244 | struct qla_hw_data *ha; |
| 6245 | struct Scsi_Host *host; |
| 6246 | unsigned long flags; |
| 6247 | int rc; |
| 6248 | u8 b[WWN_SIZE]; |
| 6249 | |
| 6250 | mutex_lock(&qla_tgt_mutex); |
| 6251 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6252 | vha = tgt->vha; |
| 6253 | ha = vha->hw; |
| 6254 | |
| 6255 | host = vha->host; |
| 6256 | if (!host) |
| 6257 | continue; |
| 6258 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6259 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6260 | continue; |
| 6261 | |
| 6262 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6263 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6264 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6265 | host->host_no); |
| 6266 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6267 | continue; |
| 6268 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6269 | if (tgt->tgt_stop) { |
| 6270 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6271 | host->host_no); |
| 6272 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6273 | continue; |
| 6274 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6275 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6276 | |
| 6277 | if (!scsi_host_get(host)) { |
| 6278 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6279 | "Unable to scsi_host_get() for" |
| 6280 | " qla2xxx scsi_host\n"); |
| 6281 | continue; |
| 6282 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6283 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6284 | |
| 6285 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6286 | scsi_host_put(host); |
| 6287 | continue; |
| 6288 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6289 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6290 | if (rc != 0) |
| 6291 | scsi_host_put(host); |
| 6292 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6293 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6294 | return rc; |
| 6295 | } |
| 6296 | mutex_unlock(&qla_tgt_mutex); |
| 6297 | |
| 6298 | return -ENODEV; |
| 6299 | } |
| 6300 | EXPORT_SYMBOL(qlt_lport_register); |
| 6301 | |
| 6302 | /** |
| 6303 | * qla_tgt_lport_deregister - Degister lport |
| 6304 | * |
| 6305 | * @vha: Registered scsi_qla_host pointer |
| 6306 | */ |
| 6307 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6308 | { |
| 6309 | struct qla_hw_data *ha = vha->hw; |
| 6310 | struct Scsi_Host *sh = vha->host; |
| 6311 | /* |
| 6312 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6313 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6314 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6315 | ha->tgt.tgt_ops = NULL; |
| 6316 | /* |
| 6317 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6318 | */ |
| 6319 | scsi_host_put(sh); |
| 6320 | } |
| 6321 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6322 | |
| 6323 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6324 | static void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6325 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6326 | switch (ql2x_ini_mode) { |
| 6327 | case QLA2XXX_INI_MODE_DISABLED: |
| 6328 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6329 | vha->host->active_mode = MODE_TARGET; |
| 6330 | break; |
| 6331 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6332 | vha->host->active_mode = MODE_UNKNOWN; |
| 6333 | break; |
| 6334 | case QLA2XXX_INI_MODE_DUAL: |
| 6335 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6336 | break; |
| 6337 | default: |
| 6338 | break; |
| 6339 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6343 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6344 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6345 | switch (ql2x_ini_mode) { |
| 6346 | case QLA2XXX_INI_MODE_DISABLED: |
| 6347 | vha->host->active_mode = MODE_UNKNOWN; |
| 6348 | break; |
| 6349 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6350 | vha->host->active_mode = MODE_INITIATOR; |
| 6351 | break; |
| 6352 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6353 | case QLA2XXX_INI_MODE_DUAL: |
| 6354 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6355 | break; |
| 6356 | default: |
| 6357 | break; |
| 6358 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | /* |
| 6362 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6363 | * |
| 6364 | * host_reset, bring up w/ Target Mode Enabled |
| 6365 | */ |
| 6366 | void |
| 6367 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6368 | { |
| 6369 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6370 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6371 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6372 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6373 | |
| 6374 | if (!tgt) { |
| 6375 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6376 | "Unable to locate qla_tgt pointer from" |
| 6377 | " struct qla_hw_data\n"); |
| 6378 | dump_stack(); |
| 6379 | return; |
| 6380 | } |
| 6381 | |
| 6382 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6383 | tgt->tgt_stopped = 0; |
| 6384 | qlt_set_mode(vha); |
| 6385 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6386 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6387 | if (vha->vp_idx) { |
| 6388 | qla24xx_disable_vp(vha); |
| 6389 | qla24xx_enable_vp(vha); |
| 6390 | } else { |
| 6391 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6392 | qla2xxx_wake_dpc(base_vha); |
| 6393 | qla2x00_wait_for_hba_online(base_vha); |
| 6394 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6395 | } |
| 6396 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6397 | |
| 6398 | /* |
| 6399 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6400 | * |
| 6401 | * Disable Target Mode and reset the adapter |
| 6402 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6403 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6404 | { |
| 6405 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6406 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6407 | unsigned long flags; |
| 6408 | |
| 6409 | if (!tgt) { |
| 6410 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6411 | "Unable to locate qla_tgt pointer from" |
| 6412 | " struct qla_hw_data\n"); |
| 6413 | dump_stack(); |
| 6414 | return; |
| 6415 | } |
| 6416 | |
| 6417 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6418 | qlt_clear_mode(vha); |
| 6419 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6420 | |
| 6421 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6422 | qla2xxx_wake_dpc(vha); |
| 6423 | qla2x00_wait_for_hba_online(vha); |
| 6424 | } |
| 6425 | |
| 6426 | /* |
| 6427 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6428 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6429 | * members. |
| 6430 | */ |
| 6431 | void |
| 6432 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6433 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6434 | vha->vha_tgt.qla_tgt = NULL; |
| 6435 | |
| 6436 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6437 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6438 | |
| 6439 | qlt_clear_mode(vha); |
| 6440 | |
| 6441 | /* |
| 6442 | * NOTE: Currently the value is kept the same for <24xx and |
| 6443 | * >=24xx ISPs. If it is necessary to change it, |
| 6444 | * the check should be added for specific ISPs, |
| 6445 | * assigning the value appropriately. |
| 6446 | */ |
| 6447 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6448 | |
| 6449 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6450 | } |
| 6451 | |
| 6452 | void |
| 6453 | qlt_rff_id(struct scsi_qla_host *vha, struct ct_sns_req *ct_req) |
| 6454 | { |
| 6455 | /* |
| 6456 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6457 | */ |
| 6458 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6459 | ct_req->req.rff_id.fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6460 | } else if (qla_ini_mode_enabled(vha)) { |
| 6461 | ct_req->req.rff_id.fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6462 | } else if (qla_dual_mode_enabled(vha)) |
| 6463 | ct_req->req.rff_id.fc4_feature = BIT_0 | BIT_1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | /* |
| 6467 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6468 | * @ha: HA context |
| 6469 | * |
| 6470 | * Beginning of ATIO ring has initialization control block already built |
| 6471 | * by nvram config routine. |
| 6472 | * |
| 6473 | * Returns 0 on success. |
| 6474 | */ |
| 6475 | void |
| 6476 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6477 | { |
| 6478 | struct qla_hw_data *ha = vha->hw; |
| 6479 | uint16_t cnt; |
| 6480 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6481 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6482 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6483 | return; |
| 6484 | |
| 6485 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6486 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6487 | pkt++; |
| 6488 | } |
| 6489 | |
| 6490 | } |
| 6491 | |
| 6492 | /* |
| 6493 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6494 | * @ha: SCSI driver HA context |
| 6495 | */ |
| 6496 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6497 | 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] | 6498 | { |
| 6499 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6500 | struct atio_from_isp *pkt; |
| 6501 | int cnt, i; |
| 6502 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6503 | if (!ha->flags.fw_started) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6504 | return; |
| 6505 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6506 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6507 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6508 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6509 | cnt = pkt->u.raw.entry_count; |
| 6510 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6511 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6512 | /* |
| 6513 | * This packet is corrupted. The header + payload |
| 6514 | * can not be trusted. There is no point in passing |
| 6515 | * it further up. |
| 6516 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6517 | ql_log(ql_log_warn, vha, 0xd03c, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6518 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6519 | pkt->u.isp24.fcp_hdr.s_id, |
| 6520 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6521 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6522 | |
| 6523 | adjust_corrupted_atio(pkt); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6524 | qlt_send_term_exchange(ha->base_qpair, NULL, pkt, |
| 6525 | ha_locked, 0); |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6526 | } else { |
| 6527 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6528 | (struct atio_from_isp *)pkt, ha_locked); |
| 6529 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6530 | |
| 6531 | for (i = 0; i < cnt; i++) { |
| 6532 | ha->tgt.atio_ring_index++; |
| 6533 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6534 | ha->tgt.atio_ring_index = 0; |
| 6535 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6536 | } else |
| 6537 | ha->tgt.atio_ring_ptr++; |
| 6538 | |
| 6539 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6540 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6541 | } |
| 6542 | wmb(); |
| 6543 | } |
| 6544 | |
| 6545 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6546 | 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] | 6547 | } |
| 6548 | |
| 6549 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6550 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6551 | { |
| 6552 | struct qla_hw_data *ha = vha->hw; |
Himanshu Madhani | c955886 | 2017-10-13 09:34:04 -0700 | [diff] [blame] | 6553 | struct init_cb_24xx *icb; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6554 | if (!QLA_TGT_MODE_ENABLED()) |
| 6555 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6556 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6557 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6558 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6559 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6560 | |
Himanshu Madhani | c955886 | 2017-10-13 09:34:04 -0700 | [diff] [blame] | 6561 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 6562 | |
| 6563 | if ((ql2xenablemsix != 0) && IS_ATIO_MSIX_CAPABLE(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6564 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6565 | |
| 6566 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6567 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6568 | "Registering ICB vector 0x%x for atio que.\n", |
| 6569 | msix->entry); |
Himanshu Madhani | c955886 | 2017-10-13 09:34:04 -0700 | [diff] [blame] | 6570 | } else if (ql2xenablemsix == 0) { |
| 6571 | icb->firmware_options_2 |= cpu_to_le32(BIT_26); |
| 6572 | ql_dbg(ql_dbg_init, vha, 0xf07f, |
| 6573 | "Registering INTx vector for ATIO.\n"); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6574 | } |
| 6575 | } |
| 6576 | |
| 6577 | void |
| 6578 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6579 | { |
| 6580 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6581 | |
| 6582 | if (!QLA_TGT_MODE_ENABLED()) |
| 6583 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6584 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6585 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6586 | if (!ha->tgt.saved_set) { |
| 6587 | /* We save only once */ |
| 6588 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6589 | ha->tgt.saved_firmware_options_1 = |
| 6590 | nv->firmware_options_1; |
| 6591 | ha->tgt.saved_firmware_options_2 = |
| 6592 | nv->firmware_options_2; |
| 6593 | ha->tgt.saved_firmware_options_3 = |
| 6594 | nv->firmware_options_3; |
| 6595 | ha->tgt.saved_set = 1; |
| 6596 | } |
| 6597 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6598 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6599 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6600 | else /* dual */ |
| 6601 | nv->exchange_count = cpu_to_le16(ql2xexchoffld); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6602 | |
| 6603 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6604 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6605 | |
| 6606 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6607 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6608 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6609 | |
| 6610 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6611 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6612 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6613 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6614 | if (ql2xtgt_tape_enable) |
| 6615 | /* Enable FC Tape support */ |
| 6616 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6617 | else |
| 6618 | /* Disable FC Tape support */ |
| 6619 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6620 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6621 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6622 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6623 | |
| 6624 | /* |
| 6625 | * clear BIT 15 explicitly as we have seen at least |
| 6626 | * a couple of instances where this was set and this |
| 6627 | * was causing the firmware to not be initialized. |
| 6628 | */ |
| 6629 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6630 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6631 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6632 | } else { |
| 6633 | if (ha->tgt.saved_set) { |
| 6634 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6635 | nv->firmware_options_1 = |
| 6636 | ha->tgt.saved_firmware_options_1; |
| 6637 | nv->firmware_options_2 = |
| 6638 | ha->tgt.saved_firmware_options_2; |
| 6639 | nv->firmware_options_3 = |
| 6640 | ha->tgt.saved_firmware_options_3; |
| 6641 | } |
| 6642 | return; |
| 6643 | } |
| 6644 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6645 | if (ha->base_qpair->enable_class_2) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6646 | if (vha->flags.init_done) |
| 6647 | fc_host_supported_classes(vha->host) = |
| 6648 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6649 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6650 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6651 | } else { |
| 6652 | if (vha->flags.init_done) |
| 6653 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6654 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6655 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | void |
| 6660 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6661 | struct init_cb_24xx *icb) |
| 6662 | { |
| 6663 | struct qla_hw_data *ha = vha->hw; |
| 6664 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6665 | if (!QLA_TGT_MODE_ENABLED()) |
| 6666 | return; |
| 6667 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6668 | if (ha->tgt.node_name_set) { |
| 6669 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6670 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6671 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6672 | |
| 6673 | /* disable ZIO at start time. */ |
| 6674 | if (!vha->flags.init_done) { |
| 6675 | uint32_t tmp; |
| 6676 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6677 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6678 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6679 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6680 | } |
| 6681 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6682 | void |
| 6683 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6684 | { |
| 6685 | struct qla_hw_data *ha = vha->hw; |
| 6686 | |
| 6687 | if (!QLA_TGT_MODE_ENABLED()) |
| 6688 | return; |
| 6689 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6690 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6691 | if (!ha->tgt.saved_set) { |
| 6692 | /* We save only once */ |
| 6693 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6694 | ha->tgt.saved_firmware_options_1 = |
| 6695 | nv->firmware_options_1; |
| 6696 | ha->tgt.saved_firmware_options_2 = |
| 6697 | nv->firmware_options_2; |
| 6698 | ha->tgt.saved_firmware_options_3 = |
| 6699 | nv->firmware_options_3; |
| 6700 | ha->tgt.saved_set = 1; |
| 6701 | } |
| 6702 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6703 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6704 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6705 | else /* dual */ |
| 6706 | nv->exchange_count = cpu_to_le16(ql2xexchoffld); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6707 | |
| 6708 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6709 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6710 | |
| 6711 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6712 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6713 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6714 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6715 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6716 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6717 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6718 | /* |
| 6719 | * clear BIT 15 explicitly as we have seen at |
| 6720 | * least a couple of instances where this was set |
| 6721 | * and this was causing the firmware to not be |
| 6722 | * initialized. |
| 6723 | */ |
| 6724 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6725 | if (ql2xtgt_tape_enable) |
| 6726 | /* Enable FC tape support */ |
| 6727 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6728 | else |
| 6729 | /* Disable FC tape support */ |
| 6730 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6731 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6732 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6733 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6734 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6735 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6736 | } else { |
| 6737 | if (ha->tgt.saved_set) { |
| 6738 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6739 | nv->firmware_options_1 = |
| 6740 | ha->tgt.saved_firmware_options_1; |
| 6741 | nv->firmware_options_2 = |
| 6742 | ha->tgt.saved_firmware_options_2; |
| 6743 | nv->firmware_options_3 = |
| 6744 | ha->tgt.saved_firmware_options_3; |
| 6745 | } |
| 6746 | return; |
| 6747 | } |
| 6748 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6749 | if (ha->base_qpair->enable_class_2) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6750 | if (vha->flags.init_done) |
| 6751 | fc_host_supported_classes(vha->host) = |
| 6752 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6753 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6754 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6755 | } else { |
| 6756 | if (vha->flags.init_done) |
| 6757 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6758 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6759 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6760 | } |
| 6761 | } |
| 6762 | |
| 6763 | void |
| 6764 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6765 | struct init_cb_81xx *icb) |
| 6766 | { |
| 6767 | struct qla_hw_data *ha = vha->hw; |
| 6768 | |
| 6769 | if (!QLA_TGT_MODE_ENABLED()) |
| 6770 | return; |
| 6771 | |
| 6772 | if (ha->tgt.node_name_set) { |
| 6773 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6774 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6775 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6776 | |
| 6777 | /* disable ZIO at start time. */ |
| 6778 | if (!vha->flags.init_done) { |
| 6779 | uint32_t tmp; |
| 6780 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6781 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6782 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6783 | } |
| 6784 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | void |
| 6788 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 6789 | { |
| 6790 | if (!QLA_TGT_MODE_ENABLED()) |
| 6791 | return; |
| 6792 | |
| 6793 | ha->msix_count += 1; /* For ATIO Q */ |
| 6794 | } |
| 6795 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6796 | |
| 6797 | void |
| 6798 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 6799 | struct vp_config_entry_24xx *vpmod) |
| 6800 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6801 | /* enable target mode. Bit5 = 1 => disable */ |
| 6802 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6803 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6804 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6805 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6806 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6807 | vpmod->options_idx1 &= ~BIT_4; |
| 6808 | } |
| 6809 | |
| 6810 | void |
| 6811 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 6812 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6813 | int rc; |
| 6814 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6815 | if (!QLA_TGT_MODE_ENABLED()) |
| 6816 | return; |
| 6817 | |
Himanshu Madhani | c955886 | 2017-10-13 09:34:04 -0700 | [diff] [blame] | 6818 | if ((ql2xenablemsix == 0) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6819 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 6820 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 6821 | } else { |
| 6822 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 6823 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 6824 | } |
| 6825 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6826 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 6827 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6828 | |
| 6829 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 6830 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 6831 | qlt_unknown_atio_work_fn); |
| 6832 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6833 | qlt_clear_mode(base_vha); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6834 | |
| 6835 | rc = btree_init32(&ha->tgt.host_map); |
| 6836 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6837 | ql_log(ql_log_info, base_vha, 0xd03d, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6838 | "Unable to initialize ha->host_map btree\n"); |
| 6839 | |
| 6840 | qlt_update_vp_map(base_vha, SET_VP_IDX); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6841 | } |
| 6842 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6843 | irqreturn_t |
| 6844 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 6845 | { |
| 6846 | struct rsp_que *rsp; |
| 6847 | scsi_qla_host_t *vha; |
| 6848 | struct qla_hw_data *ha; |
| 6849 | unsigned long flags; |
| 6850 | |
| 6851 | rsp = (struct rsp_que *) dev_id; |
| 6852 | ha = rsp->hw; |
| 6853 | vha = pci_get_drvdata(ha->pdev); |
| 6854 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6855 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6856 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6857 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6858 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6859 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6860 | |
| 6861 | return IRQ_HANDLED; |
| 6862 | } |
| 6863 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6864 | static void |
| 6865 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 6866 | { |
| 6867 | struct qla_tgt_sess_op *op = container_of(work, |
| 6868 | struct qla_tgt_sess_op, work); |
| 6869 | scsi_qla_host_t *vha = op->vha; |
| 6870 | struct qla_hw_data *ha = vha->hw; |
| 6871 | unsigned long flags; |
| 6872 | |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6873 | if (qla2x00_reset_active(vha) || |
| 6874 | (op->chip_reset != ha->base_qpair->chip_reset)) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6875 | return; |
| 6876 | |
| 6877 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 6878 | qlt_24xx_process_atio_queue(vha, 0); |
| 6879 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 6880 | |
| 6881 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6882 | qlt_response_pkt_all_vps(vha, op->rsp, (response_t *)&op->atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6883 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 6884 | |
| 6885 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6886 | } |
| 6887 | |
| 6888 | void |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6889 | qlt_handle_abts_recv(struct scsi_qla_host *vha, struct rsp_que *rsp, |
| 6890 | response_t *pkt) |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6891 | { |
| 6892 | struct qla_tgt_sess_op *op; |
| 6893 | |
| 6894 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 6895 | |
| 6896 | if (!op) { |
| 6897 | /* do not reach for ATIO queue here. This is best effort err |
| 6898 | * recovery at this point. |
| 6899 | */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6900 | qlt_response_pkt_all_vps(vha, rsp, pkt); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6901 | return; |
| 6902 | } |
| 6903 | |
| 6904 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 6905 | op->vha = vha; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6906 | op->chip_reset = vha->hw->base_qpair->chip_reset; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 6907 | op->rsp = rsp; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6908 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 6909 | queue_work(qla_tgt_wq, &op->work); |
| 6910 | return; |
| 6911 | } |
| 6912 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6913 | int |
| 6914 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 6915 | { |
| 6916 | if (!QLA_TGT_MODE_ENABLED()) |
| 6917 | return 0; |
| 6918 | |
| 6919 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * |
| 6920 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); |
| 6921 | if (!ha->tgt.tgt_vp_map) |
| 6922 | return -ENOMEM; |
| 6923 | |
| 6924 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 6925 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 6926 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 6927 | if (!ha->tgt.atio_ring) { |
| 6928 | kfree(ha->tgt.tgt_vp_map); |
| 6929 | return -ENOMEM; |
| 6930 | } |
| 6931 | return 0; |
| 6932 | } |
| 6933 | |
| 6934 | void |
| 6935 | qlt_mem_free(struct qla_hw_data *ha) |
| 6936 | { |
| 6937 | if (!QLA_TGT_MODE_ENABLED()) |
| 6938 | return; |
| 6939 | |
| 6940 | if (ha->tgt.atio_ring) { |
| 6941 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 6942 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 6943 | ha->tgt.atio_dma); |
| 6944 | } |
| 6945 | kfree(ha->tgt.tgt_vp_map); |
| 6946 | } |
| 6947 | |
| 6948 | /* vport_slock to be held by the caller */ |
| 6949 | void |
| 6950 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 6951 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6952 | void *slot; |
| 6953 | u32 key; |
| 6954 | int rc; |
| 6955 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6956 | if (!QLA_TGT_MODE_ENABLED()) |
| 6957 | return; |
| 6958 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6959 | key = vha->d_id.b24; |
| 6960 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6961 | switch (cmd) { |
| 6962 | case SET_VP_IDX: |
| 6963 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 6964 | break; |
| 6965 | case SET_AL_PA: |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6966 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 6967 | if (!slot) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6968 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6969 | "Save vha in host_map %p %06x\n", vha, key); |
| 6970 | rc = btree_insert32(&vha->hw->tgt.host_map, |
| 6971 | key, vha, GFP_ATOMIC); |
| 6972 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6973 | ql_log(ql_log_info, vha, 0xd03e, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6974 | "Unable to insert s_id into host_map: %06x\n", |
| 6975 | key); |
| 6976 | return; |
| 6977 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6978 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 6979 | "replace existing vha in host_map %p %06x\n", vha, key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6980 | btree_update32(&vha->hw->tgt.host_map, key, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6981 | break; |
| 6982 | case RESET_VP_IDX: |
| 6983 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 6984 | break; |
| 6985 | case RESET_AL_PA: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6986 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6987 | "clear vha in host_map %p %06x\n", vha, key); |
| 6988 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 6989 | if (slot) |
| 6990 | btree_remove32(&vha->hw->tgt.host_map, key); |
| 6991 | vha->d_id.b24 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6992 | break; |
| 6993 | } |
| 6994 | } |
| 6995 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6996 | void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id) |
| 6997 | { |
| 6998 | unsigned long flags; |
| 6999 | struct qla_hw_data *ha = vha->hw; |
| 7000 | |
| 7001 | if (!vha->d_id.b24) { |
| 7002 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7003 | vha->d_id = id; |
| 7004 | qlt_update_vp_map(vha, SET_AL_PA); |
| 7005 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7006 | } else if (vha->d_id.b24 != id.b24) { |
| 7007 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7008 | qlt_update_vp_map(vha, RESET_AL_PA); |
| 7009 | vha->d_id = id; |
| 7010 | qlt_update_vp_map(vha, SET_AL_PA); |
| 7011 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7012 | } |
| 7013 | } |
| 7014 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7015 | static int __init qlt_parse_ini_mode(void) |
| 7016 | { |
| 7017 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 7018 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 7019 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 7020 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 7021 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 7022 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 7023 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 7024 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7025 | else |
| 7026 | return false; |
| 7027 | |
| 7028 | return true; |
| 7029 | } |
| 7030 | |
| 7031 | int __init qlt_init(void) |
| 7032 | { |
| 7033 | int ret; |
| 7034 | |
| 7035 | if (!qlt_parse_ini_mode()) { |
| 7036 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 7037 | "qlt_parse_ini_mode() failed\n"); |
| 7038 | return -EINVAL; |
| 7039 | } |
| 7040 | |
| 7041 | if (!QLA_TGT_MODE_ENABLED()) |
| 7042 | return 0; |
| 7043 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7044 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 7045 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 7046 | qla_tgt_mgmt_cmd), 0, NULL); |
| 7047 | if (!qla_tgt_mgmt_cmd_cachep) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7048 | ql_log(ql_log_fatal, NULL, 0xd04b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7049 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 7050 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7051 | } |
| 7052 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7053 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 7054 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 7055 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7056 | |
| 7057 | if (!qla_tgt_plogi_cachep) { |
| 7058 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 7059 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 7060 | ret = -ENOMEM; |
| 7061 | goto out_mgmt_cmd_cachep; |
| 7062 | } |
| 7063 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7064 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 7065 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 7066 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 7067 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 7068 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 7069 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7070 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7071 | } |
| 7072 | |
| 7073 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 7074 | if (!qla_tgt_wq) { |
| 7075 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 7076 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 7077 | ret = -ENOMEM; |
| 7078 | goto out_cmd_mempool; |
| 7079 | } |
| 7080 | /* |
| 7081 | * Return 1 to signal that initiator-mode is being disabled |
| 7082 | */ |
| 7083 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 7084 | |
| 7085 | out_cmd_mempool: |
| 7086 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7087 | out_plogi_cachep: |
| 7088 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7089 | out_mgmt_cmd_cachep: |
| 7090 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7091 | return ret; |
| 7092 | } |
| 7093 | |
| 7094 | void qlt_exit(void) |
| 7095 | { |
| 7096 | if (!QLA_TGT_MODE_ENABLED()) |
| 7097 | return; |
| 7098 | |
| 7099 | destroy_workqueue(qla_tgt_wq); |
| 7100 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 7101 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7102 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 7103 | } |