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 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 69 | int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 70 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 71 | static int temp_sam_status = SAM_STAT_BUSY; |
| 72 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 73 | /* |
| 74 | * From scsi/fc/fc_fcp.h |
| 75 | */ |
| 76 | enum fcp_resp_rsp_codes { |
| 77 | FCP_TMF_CMPL = 0, |
| 78 | FCP_DATA_LEN_INVALID = 1, |
| 79 | FCP_CMND_FIELDS_INVALID = 2, |
| 80 | FCP_DATA_PARAM_MISMATCH = 3, |
| 81 | FCP_TMF_REJECTED = 4, |
| 82 | FCP_TMF_FAILED = 5, |
| 83 | FCP_TMF_INVALID_LUN = 9, |
| 84 | }; |
| 85 | |
| 86 | /* |
| 87 | * fc_pri_ta from scsi/fc/fc_fcp.h |
| 88 | */ |
| 89 | #define FCP_PTA_SIMPLE 0 /* simple task attribute */ |
| 90 | #define FCP_PTA_HEADQ 1 /* head of queue task attribute */ |
| 91 | #define FCP_PTA_ORDERED 2 /* ordered task attribute */ |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 92 | #define FCP_PTA_ACA 4 /* auto. contingent allegiance */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 93 | #define FCP_PTA_MASK 7 /* mask for task attribute field */ |
| 94 | #define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */ |
| 95 | #define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */ |
| 96 | |
| 97 | /* |
| 98 | * This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which |
| 99 | * must be called under HW lock and could unlock/lock it inside. |
| 100 | * It isn't an issue, since in the current implementation on the time when |
| 101 | * those functions are called: |
| 102 | * |
| 103 | * - Either context is IRQ and only IRQ handler can modify HW data, |
| 104 | * including rings related fields, |
| 105 | * |
| 106 | * - Or access to target mode variables from struct qla_tgt doesn't |
| 107 | * cross those functions boundaries, except tgt_stop, which |
| 108 | * additionally protected by irq_cmd_count. |
| 109 | */ |
| 110 | /* Predefs for callbacks handed to qla2xxx LLD */ |
| 111 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 112 | struct atio_from_isp *pkt, uint8_t); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 113 | static void qlt_response_pkt(struct scsi_qla_host *ha, response_t *pkt); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 114 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 115 | int fn, void *iocb, int flags); |
| 116 | static void qlt_send_term_exchange(struct scsi_qla_host *ha, struct qla_tgt_cmd |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 117 | *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 118 | static void qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, |
| 119 | struct qla_tgt_cmd *cmd); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 120 | static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 121 | struct atio_from_isp *atio, uint16_t status, int qfull); |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 122 | static void qlt_disable_vha(struct scsi_qla_host *vha); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 123 | static void qlt_clear_tgt_db(struct qla_tgt *tgt); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 124 | static void qlt_send_notify_ack(struct scsi_qla_host *vha, |
| 125 | struct imm_ntfy_from_isp *ntfy, |
| 126 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 127 | 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] | 128 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 129 | struct imm_ntfy_from_isp *imm, int ha_locked); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 130 | static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha, |
| 131 | fc_port_t *fcport, bool local); |
| 132 | void qlt_unreg_sess(struct fc_port *sess); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 133 | static void qlt_24xx_handle_abts(struct scsi_qla_host *, |
| 134 | struct abts_recv_from_24xx *); |
| 135 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 136 | /* |
| 137 | * Global Variables |
| 138 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 139 | static struct kmem_cache *qla_tgt_mgmt_cmd_cachep; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 140 | static struct kmem_cache *qla_tgt_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 141 | static mempool_t *qla_tgt_mgmt_cmd_mempool; |
| 142 | static struct workqueue_struct *qla_tgt_wq; |
| 143 | static DEFINE_MUTEX(qla_tgt_mutex); |
| 144 | static LIST_HEAD(qla_tgt_glist); |
| 145 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 146 | static const char *prot_op_str(u32 prot_op) |
| 147 | { |
| 148 | switch (prot_op) { |
| 149 | case TARGET_PROT_NORMAL: return "NORMAL"; |
| 150 | case TARGET_PROT_DIN_INSERT: return "DIN_INSERT"; |
| 151 | case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT"; |
| 152 | case TARGET_PROT_DIN_STRIP: return "DIN_STRIP"; |
| 153 | case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP"; |
| 154 | case TARGET_PROT_DIN_PASS: return "DIN_PASS"; |
| 155 | case TARGET_PROT_DOUT_PASS: return "DOUT_PASS"; |
| 156 | default: return "UNKNOWN"; |
| 157 | } |
| 158 | } |
| 159 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 160 | /* This API intentionally takes dest as a parameter, rather than returning |
| 161 | * int value to avoid caller forgetting to issue wmb() after the store */ |
| 162 | void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest) |
| 163 | { |
| 164 | scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev); |
| 165 | *dest = atomic_inc_return(&base_vha->generation_tick); |
| 166 | /* memory barrier */ |
| 167 | wmb(); |
| 168 | } |
| 169 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 170 | /* Might release hw lock, then reaquire!! */ |
| 171 | static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked) |
| 172 | { |
| 173 | /* Send marker if required */ |
| 174 | if (unlikely(vha->marker_needed != 0)) { |
| 175 | int rc = qla2x00_issue_marker(vha, vha_locked); |
| 176 | if (rc != QLA_SUCCESS) { |
| 177 | ql_dbg(ql_dbg_tgt, vha, 0xe03d, |
| 178 | "qla_target(%d): issue_marker() failed\n", |
| 179 | vha->vp_idx); |
| 180 | } |
| 181 | return rc; |
| 182 | } |
| 183 | return QLA_SUCCESS; |
| 184 | } |
| 185 | |
| 186 | static inline |
| 187 | struct scsi_qla_host *qlt_find_host_by_d_id(struct scsi_qla_host *vha, |
| 188 | uint8_t *d_id) |
| 189 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 190 | struct scsi_qla_host *host; |
| 191 | uint32_t key = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 192 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 193 | if ((vha->d_id.b.area == d_id[1]) && (vha->d_id.b.domain == d_id[0]) && |
| 194 | (vha->d_id.b.al_pa == d_id[2])) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 195 | return vha; |
| 196 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 197 | key = (uint32_t)d_id[0] << 16; |
| 198 | key |= (uint32_t)d_id[1] << 8; |
| 199 | key |= (uint32_t)d_id[2]; |
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 | host = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 202 | if (!host) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 203 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf005, |
| 204 | "Unable to find host %06x\n", key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 205 | |
| 206 | return host; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static inline |
| 210 | struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha, |
| 211 | uint16_t vp_idx) |
| 212 | { |
| 213 | struct qla_hw_data *ha = vha->hw; |
| 214 | |
| 215 | if (vha->vp_idx == vp_idx) |
| 216 | return vha; |
| 217 | |
| 218 | BUG_ON(ha->tgt.tgt_vp_map == NULL); |
| 219 | if (likely(test_bit(vp_idx, ha->vp_idx_map))) |
| 220 | return ha->tgt.tgt_vp_map[vp_idx].vha; |
| 221 | |
| 222 | return NULL; |
| 223 | } |
| 224 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 225 | static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha) |
| 226 | { |
| 227 | unsigned long flags; |
| 228 | |
| 229 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 230 | |
| 231 | vha->hw->tgt.num_pend_cmds++; |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 232 | if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds) |
| 233 | vha->qla_stats.stat_max_pend_cmds = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 234 | vha->hw->tgt.num_pend_cmds; |
| 235 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 236 | } |
| 237 | static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha) |
| 238 | { |
| 239 | unsigned long flags; |
| 240 | |
| 241 | spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags); |
| 242 | vha->hw->tgt.num_pend_cmds--; |
| 243 | spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags); |
| 244 | } |
| 245 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 246 | |
| 247 | static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, |
| 248 | struct atio_from_isp *atio, uint8_t ha_locked) |
| 249 | { |
| 250 | struct qla_tgt_sess_op *u; |
| 251 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 252 | unsigned long flags; |
| 253 | |
| 254 | if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 255 | ql_dbg(ql_dbg_async, vha, 0x502c, |
| 256 | "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped", |
| 257 | vha->vp_idx); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 258 | goto out_term; |
| 259 | } |
| 260 | |
| 261 | u = kzalloc(sizeof(*u), GFP_ATOMIC); |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 262 | if (u == NULL) |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 263 | goto out_term; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 264 | |
| 265 | u->vha = vha; |
| 266 | memcpy(&u->atio, atio, sizeof(*atio)); |
| 267 | INIT_LIST_HEAD(&u->cmd_list); |
| 268 | |
| 269 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 270 | list_add_tail(&u->cmd_list, &vha->unknown_atio_list); |
| 271 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 272 | |
| 273 | schedule_delayed_work(&vha->unknown_atio_work, 1); |
| 274 | |
| 275 | out: |
| 276 | return; |
| 277 | |
| 278 | out_term: |
| 279 | qlt_send_term_exchange(vha, NULL, atio, ha_locked, 0); |
| 280 | goto out; |
| 281 | } |
| 282 | |
| 283 | static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha, |
| 284 | uint8_t ha_locked) |
| 285 | { |
| 286 | struct qla_tgt_sess_op *u, *t; |
| 287 | scsi_qla_host_t *host; |
| 288 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 289 | unsigned long flags; |
| 290 | uint8_t queued = 0; |
| 291 | |
| 292 | list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) { |
| 293 | if (u->aborted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 294 | ql_dbg(ql_dbg_async, vha, 0x502e, |
| 295 | "Freeing unknown %s %p, because of Abort\n", |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 296 | "ATIO_TYPE7", u); |
| 297 | qlt_send_term_exchange(vha, NULL, &u->atio, |
| 298 | ha_locked, 0); |
| 299 | goto abort; |
| 300 | } |
| 301 | |
| 302 | host = qlt_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id); |
| 303 | if (host != NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 304 | ql_dbg(ql_dbg_async, vha, 0x502f, |
| 305 | "Requeuing unknown ATIO_TYPE7 %p\n", u); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 306 | qlt_24xx_atio_pkt(host, &u->atio, ha_locked); |
| 307 | } else if (tgt->tgt_stop) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 308 | ql_dbg(ql_dbg_async, vha, 0x503a, |
| 309 | "Freeing unknown %s %p, because tgt is being stopped\n", |
| 310 | "ATIO_TYPE7", u); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 311 | qlt_send_term_exchange(vha, NULL, &u->atio, |
| 312 | ha_locked, 0); |
| 313 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 314 | ql_dbg(ql_dbg_async, vha, 0x503d, |
| 315 | "Reschedule u %p, vha %p, host %p\n", u, vha, host); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 316 | if (!queued) { |
| 317 | queued = 1; |
| 318 | schedule_delayed_work(&vha->unknown_atio_work, |
| 319 | 1); |
| 320 | } |
| 321 | continue; |
| 322 | } |
| 323 | |
| 324 | abort: |
| 325 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 326 | list_del(&u->cmd_list); |
| 327 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 328 | kfree(u); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | void qlt_unknown_atio_work_fn(struct work_struct *work) |
| 333 | { |
| 334 | struct scsi_qla_host *vha = container_of(to_delayed_work(work), |
| 335 | struct scsi_qla_host, unknown_atio_work); |
| 336 | |
| 337 | qlt_try_to_dequeue_unknown_atios(vha, 0); |
| 338 | } |
| 339 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 340 | 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] | 341 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 342 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 343 | ql_dbg(ql_dbg_tgt, vha, 0xe072, |
| 344 | "%s: qla_target(%d): type %x ox_id %04x\n", |
| 345 | __func__, vha->vp_idx, atio->u.raw.entry_type, |
| 346 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 347 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 348 | switch (atio->u.raw.entry_type) { |
| 349 | case ATIO_TYPE7: |
| 350 | { |
| 351 | struct scsi_qla_host *host = qlt_find_host_by_d_id(vha, |
| 352 | atio->u.isp24.fcp_hdr.d_id); |
| 353 | if (unlikely(NULL == host)) { |
| 354 | ql_dbg(ql_dbg_tgt, vha, 0xe03e, |
| 355 | "qla_target(%d): Received ATIO_TYPE7 " |
| 356 | "with unknown d_id %x:%x:%x\n", vha->vp_idx, |
| 357 | atio->u.isp24.fcp_hdr.d_id[0], |
| 358 | atio->u.isp24.fcp_hdr.d_id[1], |
| 359 | atio->u.isp24.fcp_hdr.d_id[2]); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 360 | |
| 361 | |
| 362 | qlt_queue_unknown_atio(vha, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 363 | break; |
| 364 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 365 | if (unlikely(!list_empty(&vha->unknown_atio_list))) |
| 366 | qlt_try_to_dequeue_unknown_atios(vha, ha_locked); |
| 367 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 368 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 369 | break; |
| 370 | } |
| 371 | |
| 372 | case IMMED_NOTIFY_TYPE: |
| 373 | { |
| 374 | struct scsi_qla_host *host = vha; |
| 375 | struct imm_ntfy_from_isp *entry = |
| 376 | (struct imm_ntfy_from_isp *)atio; |
| 377 | |
| 378 | if ((entry->u.isp24.vp_index != 0xFF) && |
| 379 | (entry->u.isp24.nport_handle != 0xFFFF)) { |
| 380 | host = qlt_find_host_by_vp_idx(vha, |
| 381 | entry->u.isp24.vp_index); |
| 382 | if (unlikely(!host)) { |
| 383 | ql_dbg(ql_dbg_tgt, vha, 0xe03f, |
| 384 | "qla_target(%d): Received " |
| 385 | "ATIO (IMMED_NOTIFY_TYPE) " |
| 386 | "with unknown vp_index %d\n", |
| 387 | vha->vp_idx, entry->u.isp24.vp_index); |
| 388 | break; |
| 389 | } |
| 390 | } |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 391 | qlt_24xx_atio_pkt(host, atio, ha_locked); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 392 | break; |
| 393 | } |
| 394 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 395 | case VP_RPT_ID_IOCB_TYPE: |
| 396 | qla24xx_report_id_acquisition(vha, |
| 397 | (struct vp_rpt_id_entry_24xx *)atio); |
| 398 | break; |
| 399 | |
| 400 | case ABTS_RECV_24XX: |
| 401 | { |
| 402 | struct abts_recv_from_24xx *entry = |
| 403 | (struct abts_recv_from_24xx *)atio; |
| 404 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 405 | entry->vp_index); |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 406 | unsigned long flags; |
| 407 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 408 | if (unlikely(!host)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 409 | ql_dbg(ql_dbg_tgt, vha, 0xe00a, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 410 | "qla_target(%d): Response pkt (ABTS_RECV_24XX) " |
| 411 | "received, with unknown vp_index %d\n", |
| 412 | vha->vp_idx, entry->vp_index); |
| 413 | break; |
| 414 | } |
Quinn Tran | 8f6fc8d | 2017-03-15 09:48:46 -0700 | [diff] [blame] | 415 | if (!ha_locked) |
| 416 | spin_lock_irqsave(&host->hw->hardware_lock, flags); |
| 417 | qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio); |
| 418 | if (!ha_locked) |
| 419 | spin_unlock_irqrestore(&host->hw->hardware_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 420 | break; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */ |
| 424 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 425 | default: |
| 426 | ql_dbg(ql_dbg_tgt, vha, 0xe040, |
| 427 | "qla_target(%d): Received unknown ATIO atio " |
| 428 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 429 | break; |
| 430 | } |
| 431 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 432 | return false; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | void qlt_response_pkt_all_vps(struct scsi_qla_host *vha, response_t *pkt) |
| 436 | { |
| 437 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 438 | case CTIO_CRC2: |
| 439 | ql_dbg(ql_dbg_tgt, vha, 0xe073, |
| 440 | "qla_target(%d):%s: CRC2 Response pkt\n", |
| 441 | vha->vp_idx, __func__); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 442 | case CTIO_TYPE7: |
| 443 | { |
| 444 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
| 445 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 446 | entry->vp_index); |
| 447 | if (unlikely(!host)) { |
| 448 | ql_dbg(ql_dbg_tgt, vha, 0xe041, |
| 449 | "qla_target(%d): Response pkt (CTIO_TYPE7) " |
| 450 | "received, with unknown vp_index %d\n", |
| 451 | vha->vp_idx, entry->vp_index); |
| 452 | break; |
| 453 | } |
| 454 | qlt_response_pkt(host, pkt); |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | case IMMED_NOTIFY_TYPE: |
| 459 | { |
| 460 | struct scsi_qla_host *host = vha; |
| 461 | struct imm_ntfy_from_isp *entry = |
| 462 | (struct imm_ntfy_from_isp *)pkt; |
| 463 | |
| 464 | host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index); |
| 465 | if (unlikely(!host)) { |
| 466 | ql_dbg(ql_dbg_tgt, vha, 0xe042, |
| 467 | "qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) " |
| 468 | "received, with unknown vp_index %d\n", |
| 469 | vha->vp_idx, entry->u.isp24.vp_index); |
| 470 | break; |
| 471 | } |
| 472 | qlt_response_pkt(host, pkt); |
| 473 | break; |
| 474 | } |
| 475 | |
| 476 | case NOTIFY_ACK_TYPE: |
| 477 | { |
| 478 | struct scsi_qla_host *host = vha; |
| 479 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 480 | |
| 481 | if (0xFF != entry->u.isp24.vp_index) { |
| 482 | host = qlt_find_host_by_vp_idx(vha, |
| 483 | entry->u.isp24.vp_index); |
| 484 | if (unlikely(!host)) { |
| 485 | ql_dbg(ql_dbg_tgt, vha, 0xe043, |
| 486 | "qla_target(%d): Response " |
| 487 | "pkt (NOTIFY_ACK_TYPE) " |
| 488 | "received, with unknown " |
| 489 | "vp_index %d\n", vha->vp_idx, |
| 490 | entry->u.isp24.vp_index); |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | qlt_response_pkt(host, pkt); |
| 495 | break; |
| 496 | } |
| 497 | |
| 498 | case ABTS_RECV_24XX: |
| 499 | { |
| 500 | struct abts_recv_from_24xx *entry = |
| 501 | (struct abts_recv_from_24xx *)pkt; |
| 502 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 503 | entry->vp_index); |
| 504 | if (unlikely(!host)) { |
| 505 | ql_dbg(ql_dbg_tgt, vha, 0xe044, |
| 506 | "qla_target(%d): Response pkt " |
| 507 | "(ABTS_RECV_24XX) received, with unknown " |
| 508 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 509 | break; |
| 510 | } |
| 511 | qlt_response_pkt(host, pkt); |
| 512 | break; |
| 513 | } |
| 514 | |
| 515 | case ABTS_RESP_24XX: |
| 516 | { |
| 517 | struct abts_resp_to_24xx *entry = |
| 518 | (struct abts_resp_to_24xx *)pkt; |
| 519 | struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha, |
| 520 | entry->vp_index); |
| 521 | if (unlikely(!host)) { |
| 522 | ql_dbg(ql_dbg_tgt, vha, 0xe045, |
| 523 | "qla_target(%d): Response pkt " |
| 524 | "(ABTS_RECV_24XX) received, with unknown " |
| 525 | "vp_index %d\n", vha->vp_idx, entry->vp_index); |
| 526 | break; |
| 527 | } |
| 528 | qlt_response_pkt(host, pkt); |
| 529 | break; |
| 530 | } |
| 531 | |
| 532 | default: |
| 533 | qlt_response_pkt(vha, pkt); |
| 534 | break; |
| 535 | } |
| 536 | |
| 537 | } |
| 538 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 539 | /* |
| 540 | * All qlt_plogi_ack_t operations are protected by hardware_lock |
| 541 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 542 | static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 543 | struct imm_ntfy_from_isp *ntfy, int type) |
| 544 | { |
| 545 | struct qla_work_evt *e; |
| 546 | e = qla2x00_alloc_work(vha, QLA_EVT_NACK); |
| 547 | if (!e) |
| 548 | return QLA_FUNCTION_FAILED; |
| 549 | |
| 550 | e->u.nack.fcport = fcport; |
| 551 | e->u.nack.type = type; |
| 552 | memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp)); |
| 553 | return qla2x00_post_work(vha, e); |
| 554 | } |
| 555 | |
| 556 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 557 | void qla2x00_async_nack_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 558 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 559 | struct srb *sp = (struct srb *)s; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 560 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 561 | unsigned long flags; |
| 562 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 563 | ql_dbg(ql_dbg_disc, vha, 0x20f2, |
| 564 | "Async done-%s res %x %8phC type %d\n", |
| 565 | sp->name, res, sp->fcport->port_name, sp->type); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 566 | |
| 567 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 568 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 569 | sp->fcport->chip_reset = vha->hw->chip_reset; |
| 570 | |
| 571 | switch (sp->type) { |
| 572 | case SRB_NACK_PLOGI: |
| 573 | sp->fcport->login_gen++; |
| 574 | sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP; |
| 575 | sp->fcport->logout_on_delete = 1; |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 576 | sp->fcport->plogi_nack_done_deadline = jiffies + HZ; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 577 | break; |
| 578 | |
| 579 | case SRB_NACK_PRLI: |
| 580 | sp->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 581 | sp->fcport->deleted = 0; |
| 582 | |
| 583 | if (!sp->fcport->login_succ && |
| 584 | !IS_SW_RESV_ADDR(sp->fcport->d_id)) { |
| 585 | sp->fcport->login_succ = 1; |
| 586 | |
| 587 | vha->fcport_count++; |
| 588 | |
| 589 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 590 | !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 591 | ql_dbg(ql_dbg_disc, vha, 0x20f3, |
| 592 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 593 | __func__, __LINE__, |
| 594 | sp->fcport->port_name, |
| 595 | vha->fcport_count); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 596 | |
| 597 | qla24xx_post_upd_fcport_work(vha, sp->fcport); |
| 598 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 599 | ql_dbg(ql_dbg_disc, vha, 0x20f5, |
| 600 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 601 | __func__, __LINE__, |
| 602 | sp->fcport->port_name, |
| 603 | vha->fcport_count); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 604 | |
| 605 | qla24xx_post_gpsc_work(vha, sp->fcport); |
| 606 | } |
| 607 | } |
| 608 | break; |
| 609 | |
| 610 | case SRB_NACK_LOGO: |
| 611 | sp->fcport->login_gen++; |
| 612 | sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 613 | qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE); |
| 614 | break; |
| 615 | } |
| 616 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 617 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 618 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport, |
| 622 | struct imm_ntfy_from_isp *ntfy, int type) |
| 623 | { |
| 624 | int rval = QLA_FUNCTION_FAILED; |
| 625 | srb_t *sp; |
| 626 | char *c = NULL; |
| 627 | |
| 628 | fcport->flags |= FCF_ASYNC_SENT; |
| 629 | switch (type) { |
| 630 | case SRB_NACK_PLOGI: |
| 631 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; |
| 632 | c = "PLOGI"; |
| 633 | break; |
| 634 | case SRB_NACK_PRLI: |
| 635 | fcport->fw_login_state = DSC_LS_PRLI_PEND; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 636 | fcport->deleted = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 637 | c = "PRLI"; |
| 638 | break; |
| 639 | case SRB_NACK_LOGO: |
| 640 | fcport->fw_login_state = DSC_LS_LOGO_PEND; |
| 641 | c = "LOGO"; |
| 642 | break; |
| 643 | } |
| 644 | |
| 645 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
| 646 | if (!sp) |
| 647 | goto done; |
| 648 | |
| 649 | sp->type = type; |
| 650 | sp->name = "nack"; |
| 651 | |
| 652 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 653 | |
| 654 | sp->u.iocb_cmd.u.nack.ntfy = ntfy; |
| 655 | |
| 656 | sp->done = qla2x00_async_nack_sp_done; |
| 657 | |
| 658 | rval = qla2x00_start_sp(sp); |
| 659 | if (rval != QLA_SUCCESS) |
| 660 | goto done_free_sp; |
| 661 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 662 | ql_dbg(ql_dbg_disc, vha, 0x20f4, |
| 663 | "Async-%s %8phC hndl %x %s\n", |
| 664 | sp->name, fcport->port_name, sp->handle, c); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 665 | |
| 666 | return rval; |
| 667 | |
| 668 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 669 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 670 | done: |
| 671 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 672 | return rval; |
| 673 | } |
| 674 | |
| 675 | void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
| 676 | { |
| 677 | fc_port_t *t; |
| 678 | unsigned long flags; |
| 679 | |
| 680 | switch (e->u.nack.type) { |
| 681 | case SRB_NACK_PRLI: |
| 682 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 683 | t = qlt_create_sess(vha, e->u.nack.fcport, 0); |
| 684 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 685 | if (t) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 686 | ql_log(ql_log_info, vha, 0xd034, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 687 | "%s create sess success %p", __func__, t); |
| 688 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 689 | /* create sess has an extra kref */ |
| 690 | vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport); |
| 691 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 692 | } |
| 693 | break; |
| 694 | } |
| 695 | qla24xx_async_notify_ack(vha, e->u.nack.fcport, |
| 696 | (struct imm_ntfy_from_isp*)e->u.nack.iocb, e->u.nack.type); |
| 697 | } |
| 698 | |
| 699 | void qla24xx_delete_sess_fn(struct work_struct *work) |
| 700 | { |
| 701 | fc_port_t *fcport = container_of(work, struct fc_port, del_work); |
| 702 | struct qla_hw_data *ha = fcport->vha->hw; |
| 703 | unsigned long flags; |
| 704 | |
| 705 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 706 | |
| 707 | if (fcport->se_sess) { |
| 708 | ha->tgt.tgt_ops->shutdown_sess(fcport); |
| 709 | ha->tgt.tgt_ops->put_sess(fcport); |
| 710 | } else { |
| 711 | qlt_unreg_sess(fcport); |
| 712 | } |
| 713 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 714 | } |
| 715 | |
| 716 | /* |
| 717 | * Called from qla2x00_reg_remote_port() |
| 718 | */ |
| 719 | void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 720 | { |
| 721 | struct qla_hw_data *ha = vha->hw; |
| 722 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 723 | struct fc_port *sess = fcport; |
| 724 | unsigned long flags; |
| 725 | |
| 726 | if (!vha->hw->tgt.tgt_ops) |
| 727 | return; |
| 728 | |
| 729 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 730 | if (tgt->tgt_stop) { |
| 731 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 736 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 737 | return; |
| 738 | } |
| 739 | |
| 740 | if (!sess->se_sess) { |
| 741 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 742 | |
| 743 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 744 | sess = qlt_create_sess(vha, fcport, false); |
| 745 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 746 | |
| 747 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 748 | } else { |
| 749 | if (fcport->fw_login_state == DSC_LS_PRLI_COMP) { |
| 750 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 755 | ql_dbg(ql_dbg_disc, vha, 0x2107, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 756 | "%s: kref_get fail sess %8phC \n", |
| 757 | __func__, sess->port_name); |
| 758 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c, |
| 763 | "qla_target(%u): %ssession for port %8phC " |
| 764 | "(loop ID %d) reappeared\n", vha->vp_idx, |
| 765 | sess->local ? "local " : "", sess->port_name, sess->loop_id); |
| 766 | |
| 767 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007, |
| 768 | "Reappeared sess %p\n", sess); |
| 769 | |
| 770 | ha->tgt.tgt_ops->update_sess(sess, fcport->d_id, |
| 771 | fcport->loop_id, |
| 772 | (fcport->flags & FCF_CONF_COMP_SUPPORTED)); |
| 773 | } |
| 774 | |
| 775 | if (sess && sess->local) { |
| 776 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d, |
| 777 | "qla_target(%u): local session for " |
| 778 | "port %8phC (loop ID %d) became global\n", vha->vp_idx, |
| 779 | fcport->port_name, sess->loop_id); |
| 780 | sess->local = 0; |
| 781 | } |
| 782 | ha->tgt.tgt_ops->put_sess(sess); |
| 783 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 784 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 785 | |
| 786 | /* |
| 787 | * This is a zero-base ref-counting solution, since hardware_lock |
| 788 | * guarantees that ref_count is not modified concurrently. |
| 789 | * Upon successful return content of iocb is undefined |
| 790 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 791 | static struct qlt_plogi_ack_t * |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 792 | qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id, |
| 793 | struct imm_ntfy_from_isp *iocb) |
| 794 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 795 | struct qlt_plogi_ack_t *pla; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 796 | |
| 797 | list_for_each_entry(pla, &vha->plogi_ack_list, list) { |
| 798 | if (pla->id.b24 == id->b24) { |
| 799 | qlt_send_term_imm_notif(vha, &pla->iocb, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 800 | memcpy(&pla->iocb, iocb, sizeof(pla->iocb)); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 801 | return pla; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC); |
| 806 | if (!pla) { |
| 807 | ql_dbg(ql_dbg_async, vha, 0x5088, |
| 808 | "qla_target(%d): Allocation of plogi_ack failed\n", |
| 809 | vha->vp_idx); |
| 810 | return NULL; |
| 811 | } |
| 812 | |
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 | pla->id = *id; |
| 815 | list_add_tail(&pla->list, &vha->plogi_ack_list); |
| 816 | |
| 817 | return pla; |
| 818 | } |
| 819 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 820 | void qlt_plogi_ack_unref(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 821 | struct qlt_plogi_ack_t *pla) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 822 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 823 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 824 | port_id_t port_id; |
| 825 | uint16_t loop_id; |
| 826 | fc_port_t *fcport = pla->fcport; |
| 827 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 828 | BUG_ON(!pla->ref_count); |
| 829 | pla->ref_count--; |
| 830 | |
| 831 | if (pla->ref_count) |
| 832 | return; |
| 833 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 834 | ql_dbg(ql_dbg_disc, vha, 0x5089, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 835 | "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] | 836 | " exch %#x ox_id %#x\n", iocb->u.isp24.port_name, |
| 837 | iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1], |
| 838 | iocb->u.isp24.port_id[0], |
| 839 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 840 | iocb->u.isp24.exchange_address, iocb->ox_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 841 | |
| 842 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 843 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 844 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 845 | port_id.b.rsvd_1 = 0; |
| 846 | |
| 847 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 848 | |
| 849 | fcport->loop_id = loop_id; |
| 850 | fcport->d_id = port_id; |
| 851 | qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI); |
| 852 | |
| 853 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 854 | if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla) |
| 855 | fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 856 | if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla) |
| 857 | fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
| 858 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 859 | |
| 860 | list_del(&pla->list); |
| 861 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
| 862 | } |
| 863 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 864 | void |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 865 | qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla, |
| 866 | struct fc_port *sess, enum qlt_plogi_link_t link) |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 867 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 868 | struct imm_ntfy_from_isp *iocb = &pla->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 869 | /* Inc ref_count first because link might already be pointing at pla */ |
| 870 | pla->ref_count++; |
| 871 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 872 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097, |
| 873 | "Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC" |
| 874 | " s_id %02x:%02x:%02x, ref=%d pla %p link %d\n", |
| 875 | sess, link, sess->port_name, |
| 876 | iocb->u.isp24.port_name, iocb->u.isp24.port_id[2], |
| 877 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 878 | pla->ref_count, pla, link); |
| 879 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 880 | if (sess->plogi_link[link]) |
| 881 | qlt_plogi_ack_unref(vha, sess->plogi_link[link]); |
| 882 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 883 | if (link == QLT_PLOGI_LINK_SAME_WWN) |
| 884 | pla->fcport = sess; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 885 | |
| 886 | sess->plogi_link[link] = pla; |
| 887 | } |
| 888 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 889 | typedef struct { |
| 890 | /* These fields must be initialized by the caller */ |
| 891 | port_id_t id; |
| 892 | /* |
| 893 | * number of cmds dropped while we were waiting for |
| 894 | * initiator to ack LOGO initialize to 1 if LOGO is |
| 895 | * triggered by a command, otherwise, to 0 |
| 896 | */ |
| 897 | int cmd_count; |
| 898 | |
| 899 | /* These fields are used by callee */ |
| 900 | struct list_head list; |
| 901 | } qlt_port_logo_t; |
| 902 | |
| 903 | static void |
| 904 | qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo) |
| 905 | { |
| 906 | qlt_port_logo_t *tmp; |
| 907 | int res; |
| 908 | |
| 909 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 910 | |
| 911 | list_for_each_entry(tmp, &vha->logo_list, list) { |
| 912 | if (tmp->id.b24 == logo->id.b24) { |
| 913 | tmp->cmd_count += logo->cmd_count; |
| 914 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 915 | return; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | list_add_tail(&logo->list, &vha->logo_list); |
| 920 | |
| 921 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 922 | |
| 923 | res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id); |
| 924 | |
| 925 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 926 | list_del(&logo->list); |
| 927 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 928 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 929 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098, |
| 930 | "Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n", |
| 931 | logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa, |
| 932 | logo->cmd_count, res); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 933 | } |
| 934 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 935 | static void qlt_free_session_done(struct work_struct *work) |
| 936 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 937 | struct fc_port *sess = container_of(work, struct fc_port, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 938 | free_work); |
| 939 | struct qla_tgt *tgt = sess->tgt; |
| 940 | struct scsi_qla_host *vha = sess->vha; |
| 941 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 942 | unsigned long flags; |
| 943 | bool logout_started = false; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 944 | struct event_arg ea; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 945 | scsi_qla_host_t *base_vha; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 946 | |
| 947 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf084, |
| 948 | "%s: se_sess %p / sess %p from port %8phC loop_id %#04x" |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 949 | " 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] | 950 | __func__, sess->se_sess, sess, sess->port_name, sess->loop_id, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 951 | 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] | 952 | sess->logout_on_delete, sess->keep_nport_handle, |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 953 | sess->send_els_logo); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 954 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 955 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 956 | if (!IS_SW_RESV_ADDR(sess->d_id)) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 957 | if (sess->send_els_logo) { |
| 958 | qlt_port_logo_t logo; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 959 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 960 | logo.id = sess->d_id; |
| 961 | logo.cmd_count = 0; |
| 962 | qlt_send_first_logo(vha, &logo); |
| 963 | } |
| 964 | |
| 965 | if (sess->logout_on_delete) { |
| 966 | int rc; |
| 967 | |
| 968 | rc = qla2x00_post_async_logout_work(vha, sess, NULL); |
| 969 | if (rc != QLA_SUCCESS) |
| 970 | ql_log(ql_log_warn, vha, 0xf085, |
| 971 | "Schedule logo failed sess %p rc %d\n", |
| 972 | sess, rc); |
| 973 | else |
| 974 | logout_started = true; |
| 975 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 976 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 977 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 978 | /* |
| 979 | * Release the target session for FC Nexus from fabric module code. |
| 980 | */ |
| 981 | if (sess->se_sess != NULL) |
| 982 | ha->tgt.tgt_ops->free_session(sess); |
| 983 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 984 | if (logout_started) { |
| 985 | bool traced = false; |
| 986 | |
| 987 | while (!ACCESS_ONCE(sess->logout_completed)) { |
| 988 | if (!traced) { |
| 989 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf086, |
| 990 | "%s: waiting for sess %p logout\n", |
| 991 | __func__, sess); |
| 992 | traced = true; |
| 993 | } |
| 994 | msleep(100); |
| 995 | } |
| 996 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 997 | ql_dbg(ql_dbg_disc, vha, 0xf087, |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 998 | "%s: sess %p logout completed\n",__func__, sess); |
| 999 | } |
| 1000 | |
| 1001 | if (sess->logo_ack_needed) { |
| 1002 | sess->logo_ack_needed = 0; |
| 1003 | qla24xx_async_notify_ack(vha, sess, |
| 1004 | (struct imm_ntfy_from_isp *)sess->iocb, SRB_NACK_LOGO); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1007 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1008 | if (sess->se_sess) { |
| 1009 | sess->se_sess = NULL; |
| 1010 | if (tgt && !IS_SW_RESV_ADDR(sess->d_id)) |
| 1011 | tgt->sess_count--; |
| 1012 | } |
| 1013 | |
| 1014 | sess->disc_state = DSC_DELETED; |
| 1015 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1016 | sess->deleted = QLA_SESS_DELETED; |
| 1017 | sess->login_retry = vha->hw->login_retry_count; |
| 1018 | |
| 1019 | if (sess->login_succ && !IS_SW_RESV_ADDR(sess->d_id)) { |
| 1020 | vha->fcport_count--; |
| 1021 | sess->login_succ = 0; |
| 1022 | } |
| 1023 | |
| 1024 | if (sess->chip_reset != sess->vha->hw->chip_reset) |
| 1025 | qla2x00_clear_loop_id(sess); |
| 1026 | |
| 1027 | if (sess->conflict) { |
| 1028 | sess->conflict->login_pause = 0; |
| 1029 | sess->conflict = NULL; |
| 1030 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 1031 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1032 | } |
| 1033 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1034 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1035 | struct qlt_plogi_ack_t *own = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1036 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1037 | struct qlt_plogi_ack_t *con = |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1038 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1039 | struct imm_ntfy_from_isp *iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1040 | |
| 1041 | if (con) { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1042 | iocb = &con->iocb; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1043 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf099, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1044 | "se_sess %p / sess %p port %8phC is gone," |
| 1045 | " %s (ref=%d), releasing PLOGI for %8phC (ref=%d)\n", |
| 1046 | sess->se_sess, sess, sess->port_name, |
| 1047 | own ? "releasing own PLOGI" : "no own PLOGI pending", |
| 1048 | own ? own->ref_count : -1, |
| 1049 | iocb->u.isp24.port_name, con->ref_count); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1050 | qlt_plogi_ack_unref(vha, con); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1051 | sess->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1052 | } else { |
| 1053 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09a, |
| 1054 | "se_sess %p / sess %p port %8phC is gone, %s (ref=%d)\n", |
| 1055 | sess->se_sess, sess, sess->port_name, |
| 1056 | own ? "releasing own PLOGI" : |
| 1057 | "no own PLOGI pending", |
| 1058 | own ? own->ref_count : -1); |
| 1059 | } |
| 1060 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1061 | if (own) { |
| 1062 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1063 | qlt_plogi_ack_unref(vha, own); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1064 | sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL; |
| 1065 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 1066 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1067 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1068 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1069 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf001, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1070 | "Unregistration of sess %p %8phC finished fcp_cnt %d\n", |
| 1071 | sess, sess->port_name, vha->fcport_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1072 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1073 | if (tgt && (tgt->sess_count == 0)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1074 | wake_up_all(&tgt->waitQ); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1075 | |
| 1076 | if (vha->fcport_count == 0) |
| 1077 | wake_up_all(&vha->fcport_waitQ); |
| 1078 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1079 | base_vha = pci_get_drvdata(ha->pdev); |
| 1080 | if (test_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags)) |
| 1081 | return; |
| 1082 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1083 | if (!tgt || !tgt->tgt_stop) { |
| 1084 | memset(&ea, 0, sizeof(ea)); |
| 1085 | ea.event = FCME_DELETE_DONE; |
| 1086 | ea.fcport = sess; |
| 1087 | qla2x00_fcport_event_handler(vha, &ea); |
| 1088 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1089 | } |
| 1090 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1091 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1092 | void qlt_unreg_sess(struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1093 | { |
| 1094 | struct scsi_qla_host *vha = sess->vha; |
| 1095 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1096 | ql_dbg(ql_dbg_disc, sess->vha, 0x210a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1097 | "%s sess %p for deletion %8phC\n", |
| 1098 | __func__, sess, sess->port_name); |
| 1099 | |
Quinn Tran | 36c7845 | 2016-02-04 11:45:18 -0500 | [diff] [blame] | 1100 | if (sess->se_sess) |
| 1101 | vha->hw->tgt.tgt_ops->clear_nacl_from_fcport_map(sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1102 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1103 | qla2x00_mark_device_lost(vha, sess, 1, 1); |
| 1104 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1105 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1106 | sess->disc_state = DSC_DELETE_PEND; |
| 1107 | sess->last_rscn_gen = sess->rscn_gen; |
| 1108 | sess->last_login_gen = sess->login_gen; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1109 | |
| 1110 | INIT_WORK(&sess->free_work, qlt_free_session_done); |
| 1111 | schedule_work(&sess->free_work); |
| 1112 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1113 | EXPORT_SYMBOL(qlt_unreg_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1114 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1115 | static int qlt_reset(struct scsi_qla_host *vha, void *iocb, int mcmd) |
| 1116 | { |
| 1117 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1118 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1119 | uint16_t loop_id; |
| 1120 | int res = 0; |
| 1121 | struct imm_ntfy_from_isp *n = (struct imm_ntfy_from_isp *)iocb; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1122 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1123 | |
| 1124 | loop_id = le16_to_cpu(n->u.isp24.nport_handle); |
| 1125 | if (loop_id == 0xFFFF) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1126 | /* Global event */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1127 | atomic_inc(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1128 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1129 | qlt_clear_tgt_db(vha->vha_tgt.qla_tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1130 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1131 | } else { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1132 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1133 | 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] | 1134 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | ql_dbg(ql_dbg_tgt, vha, 0xe000, |
| 1138 | "Using sess for qla_tgt_reset: %p\n", sess); |
| 1139 | if (!sess) { |
| 1140 | res = -ESRCH; |
| 1141 | return res; |
| 1142 | } |
| 1143 | |
| 1144 | ql_dbg(ql_dbg_tgt, vha, 0xe047, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1145 | "scsi(%ld): resetting (session %p from port %8phC mcmd %x, " |
| 1146 | "loop_id %d)\n", vha->host_no, sess, sess->port_name, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1147 | mcmd, loop_id); |
| 1148 | |
Quinn Tran | bb1181c | 2016-12-23 18:06:05 -0800 | [diff] [blame] | 1149 | 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] | 1150 | } |
| 1151 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1152 | static void qla24xx_chk_fcp_state(struct fc_port *sess) |
| 1153 | { |
| 1154 | if (sess->chip_reset != sess->vha->hw->chip_reset) { |
| 1155 | sess->logout_on_delete = 0; |
| 1156 | sess->logo_ack_needed = 0; |
| 1157 | sess->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1158 | sess->scan_state = 0; |
| 1159 | } |
| 1160 | } |
| 1161 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1162 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1163 | void qlt_schedule_sess_for_deletion(struct fc_port *sess, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1164 | bool immediate) |
| 1165 | { |
| 1166 | struct qla_tgt *tgt = sess->tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1167 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1168 | if (sess->disc_state == DSC_DELETE_PEND) |
| 1169 | return; |
| 1170 | |
| 1171 | if (sess->disc_state == DSC_DELETED) { |
| 1172 | if (tgt && tgt->tgt_stop && (tgt->sess_count == 0)) |
| 1173 | wake_up_all(&tgt->waitQ); |
| 1174 | if (sess->vha->fcport_count == 0) |
| 1175 | wake_up_all(&sess->vha->fcport_waitQ); |
| 1176 | |
| 1177 | if (!sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN] && |
| 1178 | !sess->plogi_link[QLT_PLOGI_LINK_CONFLICT]) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1179 | return; |
| 1180 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1181 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1182 | sess->disc_state = DSC_DELETE_PEND; |
| 1183 | |
| 1184 | if (sess->deleted == QLA_SESS_DELETED) |
| 1185 | sess->logout_on_delete = 0; |
| 1186 | |
| 1187 | sess->deleted = QLA_SESS_DELETION_IN_PROGRESS; |
| 1188 | qla24xx_chk_fcp_state(sess); |
| 1189 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1190 | ql_dbg(ql_dbg_tgt, sess->vha, 0xe001, |
| 1191 | "Scheduling sess %p for deletion\n", sess); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1192 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1193 | schedule_work(&sess->del_work); |
| 1194 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1195 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1196 | void qlt_schedule_sess_for_deletion_lock(struct fc_port *sess) |
| 1197 | { |
| 1198 | unsigned long flags; |
| 1199 | struct qla_hw_data *ha = sess->vha->hw; |
| 1200 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1201 | qlt_schedule_sess_for_deletion(sess, 1); |
| 1202 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1203 | } |
| 1204 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1205 | /* ha->tgt.sess_lock supposed to be held on entry */ |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1206 | static void qlt_clear_tgt_db(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1207 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1208 | struct fc_port *sess; |
| 1209 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1210 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1211 | list_for_each_entry(sess, &vha->vp_fcports, list) { |
| 1212 | if (sess->se_sess) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1213 | qlt_schedule_sess_for_deletion(sess, 1); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1214 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1215 | |
| 1216 | /* At this point tgt could be already dead */ |
| 1217 | } |
| 1218 | |
| 1219 | static int qla24xx_get_loop_id(struct scsi_qla_host *vha, const uint8_t *s_id, |
| 1220 | uint16_t *loop_id) |
| 1221 | { |
| 1222 | struct qla_hw_data *ha = vha->hw; |
| 1223 | dma_addr_t gid_list_dma; |
| 1224 | struct gid_list_info *gid_list; |
| 1225 | char *id_iter; |
| 1226 | int res, rc, i; |
| 1227 | uint16_t entries; |
| 1228 | |
| 1229 | gid_list = dma_alloc_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1230 | &gid_list_dma, GFP_KERNEL); |
| 1231 | if (!gid_list) { |
| 1232 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf044, |
| 1233 | "qla_target(%d): DMA Alloc failed of %u\n", |
| 1234 | vha->vp_idx, qla2x00_gid_list_size(ha)); |
| 1235 | return -ENOMEM; |
| 1236 | } |
| 1237 | |
| 1238 | /* Get list of logged in devices */ |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1239 | rc = qla24xx_gidlist_wait(vha, gid_list, gid_list_dma, &entries); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1240 | if (rc != QLA_SUCCESS) { |
| 1241 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf045, |
| 1242 | "qla_target(%d): get_id_list() failed: %x\n", |
| 1243 | vha->vp_idx, rc); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1244 | res = -EBUSY; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1245 | goto out_free_id_list; |
| 1246 | } |
| 1247 | |
| 1248 | id_iter = (char *)gid_list; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 1249 | res = -ENOENT; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1250 | for (i = 0; i < entries; i++) { |
| 1251 | struct gid_list_info *gid = (struct gid_list_info *)id_iter; |
| 1252 | if ((gid->al_pa == s_id[2]) && |
| 1253 | (gid->area == s_id[1]) && |
| 1254 | (gid->domain == s_id[0])) { |
| 1255 | *loop_id = le16_to_cpu(gid->loop_id); |
| 1256 | res = 0; |
| 1257 | break; |
| 1258 | } |
| 1259 | id_iter += ha->gid_list_info_size; |
| 1260 | } |
| 1261 | |
| 1262 | out_free_id_list: |
| 1263 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
| 1264 | gid_list, gid_list_dma); |
| 1265 | return res; |
| 1266 | } |
| 1267 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1268 | /* |
| 1269 | * Adds an extra ref to allow to drop hw lock after adding sess to the list. |
| 1270 | * Caller must put it. |
| 1271 | */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1272 | static struct fc_port *qlt_create_sess( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1273 | struct scsi_qla_host *vha, |
| 1274 | fc_port_t *fcport, |
| 1275 | bool local) |
| 1276 | { |
| 1277 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1278 | struct fc_port *sess = fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1279 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1280 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1281 | if (vha->vha_tgt.qla_tgt->tgt_stop) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1282 | return NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1283 | |
| 1284 | if (fcport->se_sess) { |
| 1285 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1286 | ql_dbg(ql_dbg_disc, vha, 0x20f6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1287 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1288 | __func__, sess->port_name); |
| 1289 | return NULL; |
| 1290 | } |
| 1291 | return fcport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1292 | } |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1293 | sess->tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1294 | sess->local = local; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1295 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1296 | /* |
| 1297 | * Under normal circumstances we want to logout from firmware when |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1298 | * session eventually ends and release corresponding nport handle. |
| 1299 | * In the exception cases (e.g. when new PLOGI is waiting) corresponding |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1300 | * code will adjust these flags as necessary. |
| 1301 | */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1302 | sess->logout_on_delete = 1; |
| 1303 | sess->keep_nport_handle = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1304 | sess->logout_completed = 0; |
| 1305 | |
| 1306 | if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, |
| 1307 | &fcport->port_name[0], sess) < 0) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1308 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf015, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1309 | "(%d) %8phC check_initiator_node_acl failed\n", |
| 1310 | vha->vp_idx, fcport->port_name); |
| 1311 | return NULL; |
| 1312 | } else { |
| 1313 | kref_init(&fcport->sess_kref); |
| 1314 | /* |
| 1315 | * Take an extra reference to ->sess_kref here to handle |
| 1316 | * fc_port access across ->tgt.sess_lock reaquire. |
| 1317 | */ |
| 1318 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1319 | ql_dbg(ql_dbg_disc, vha, 0x20f7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1320 | "%s: kref_get_unless_zero failed for %8phC\n", |
| 1321 | __func__, sess->port_name); |
| 1322 | return NULL; |
| 1323 | } |
| 1324 | |
| 1325 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 1326 | if (!IS_SW_RESV_ADDR(sess->d_id)) |
| 1327 | vha->vha_tgt.qla_tgt->sess_count++; |
| 1328 | |
| 1329 | qlt_do_generation_tick(vha, &sess->generation); |
| 1330 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1331 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1332 | |
| 1333 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1334 | "Adding sess %p se_sess %p to tgt %p sess_count %d\n", |
| 1335 | sess, sess->se_sess, vha->vha_tgt.qla_tgt, |
| 1336 | vha->vha_tgt.qla_tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1337 | |
| 1338 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04b, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1339 | "qla_target(%d): %ssession for wwn %8phC (loop_id %d, " |
| 1340 | "s_id %x:%x:%x, confirmed completion %ssupported) added\n", |
| 1341 | vha->vp_idx, local ? "local " : "", fcport->port_name, |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 1342 | fcport->loop_id, sess->d_id.b.domain, sess->d_id.b.area, |
| 1343 | sess->d_id.b.al_pa, sess->conf_compl_supported ? "" : "not "); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1344 | |
| 1345 | return sess; |
| 1346 | } |
| 1347 | |
| 1348 | /* |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1349 | * max_gen - specifies maximum session generation |
| 1350 | * at which this deletion requestion is still valid |
| 1351 | */ |
| 1352 | void |
| 1353 | 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] | 1354 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1355 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1356 | struct fc_port *sess = fcport; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1357 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1358 | |
| 1359 | if (!vha->hw->tgt.tgt_ops) |
| 1360 | return; |
| 1361 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 1362 | if (!tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1363 | return; |
| 1364 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1365 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1366 | if (tgt->tgt_stop) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1367 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1368 | return; |
| 1369 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1370 | if (!sess->se_sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1371 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1372 | return; |
| 1373 | } |
| 1374 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1375 | if (max_gen - sess->generation < 0) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1376 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 1377 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf092, |
| 1378 | "Ignoring stale deletion request for se_sess %p / sess %p" |
| 1379 | " for port %8phC, req_gen %d, sess_gen %d\n", |
| 1380 | sess->se_sess, sess, sess->port_name, max_gen, |
| 1381 | sess->generation); |
| 1382 | return; |
| 1383 | } |
| 1384 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1385 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf008, "qla_tgt_fc_port_deleted %p", sess); |
| 1386 | |
| 1387 | sess->local = 1; |
| 1388 | qlt_schedule_sess_for_deletion(sess, false); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1389 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static inline int test_tgt_sess_count(struct qla_tgt *tgt) |
| 1393 | { |
| 1394 | struct qla_hw_data *ha = tgt->ha; |
| 1395 | unsigned long flags; |
| 1396 | int res; |
| 1397 | /* |
| 1398 | * We need to protect against race, when tgt is freed before or |
| 1399 | * inside wake_up() |
| 1400 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1401 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1402 | ql_dbg(ql_dbg_tgt, tgt->vha, 0xe002, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1403 | "tgt %p, sess_count=%d\n", |
| 1404 | tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1405 | res = (tgt->sess_count == 0); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1406 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1407 | |
| 1408 | return res; |
| 1409 | } |
| 1410 | |
| 1411 | /* Called by tcm_qla2xxx configfs code */ |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1412 | int qlt_stop_phase1(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1413 | { |
| 1414 | struct scsi_qla_host *vha = tgt->vha; |
| 1415 | struct qla_hw_data *ha = tgt->ha; |
| 1416 | unsigned long flags; |
| 1417 | |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1418 | mutex_lock(&qla_tgt_mutex); |
| 1419 | if (!vha->fc_vport) { |
| 1420 | struct Scsi_Host *sh = vha->host; |
| 1421 | struct fc_host_attrs *fc_host = shost_to_fc_host(sh); |
| 1422 | bool npiv_vports; |
| 1423 | |
| 1424 | spin_lock_irqsave(sh->host_lock, flags); |
| 1425 | npiv_vports = (fc_host->npiv_vports_inuse); |
| 1426 | spin_unlock_irqrestore(sh->host_lock, flags); |
| 1427 | |
| 1428 | if (npiv_vports) { |
| 1429 | mutex_unlock(&qla_tgt_mutex); |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1430 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021, |
| 1431 | "NPIV is in use. Can not stop target\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1432 | return -EPERM; |
| 1433 | } |
| 1434 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1435 | if (tgt->tgt_stop || tgt->tgt_stopped) { |
| 1436 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, |
| 1437 | "Already in tgt->tgt_stop or tgt_stopped state\n"); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1438 | mutex_unlock(&qla_tgt_mutex); |
| 1439 | return -EPERM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1440 | } |
| 1441 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1442 | 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] | 1443 | vha->host_no, vha); |
| 1444 | /* |
| 1445 | * Mutex needed to sync with qla_tgt_fc_port_[added,deleted]. |
| 1446 | * Lock is needed, because we still can get an incoming packet. |
| 1447 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1448 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1449 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1450 | tgt->tgt_stop = 1; |
Joern Engel | c570104 | 2014-09-16 16:23:14 -0400 | [diff] [blame] | 1451 | qlt_clear_tgt_db(tgt); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1452 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1453 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1454 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1455 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1456 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf009, |
| 1457 | "Waiting for sess works (tgt %p)", tgt); |
| 1458 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1459 | while (!list_empty(&tgt->sess_works_list)) { |
| 1460 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1461 | flush_scheduled_work(); |
| 1462 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1463 | } |
| 1464 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1465 | |
| 1466 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00a, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1467 | "Waiting for tgt %p: sess_count=%d\n", tgt, tgt->sess_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1468 | |
| 1469 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); |
| 1470 | |
| 1471 | /* Big hammer */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1472 | if (!ha->flags.host_shutting_down && |
| 1473 | (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1474 | qlt_disable_vha(vha); |
| 1475 | |
| 1476 | /* Wait for sessions to clear out (just in case) */ |
| 1477 | wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); |
Nicholas Bellinger | 3c231bd | 2014-02-19 17:50:22 -0800 | [diff] [blame] | 1478 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1479 | } |
| 1480 | EXPORT_SYMBOL(qlt_stop_phase1); |
| 1481 | |
| 1482 | /* Called by tcm_qla2xxx configfs code */ |
| 1483 | void qlt_stop_phase2(struct qla_tgt *tgt) |
| 1484 | { |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1485 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1486 | |
| 1487 | if (tgt->tgt_stopped) { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1488 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04f, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1489 | "Already in tgt->tgt_stopped state\n"); |
| 1490 | dump_stack(); |
| 1491 | return; |
| 1492 | } |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1493 | if (!tgt->tgt_stop) { |
| 1494 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00b, |
| 1495 | "%s: phase1 stop is not completed\n", __func__); |
| 1496 | dump_stack(); |
| 1497 | return; |
| 1498 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1499 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1500 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1501 | tgt->tgt_stop = 0; |
| 1502 | tgt->tgt_stopped = 1; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1503 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1504 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1505 | 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] | 1506 | tgt); |
| 1507 | } |
| 1508 | EXPORT_SYMBOL(qlt_stop_phase2); |
| 1509 | |
| 1510 | /* Called from qlt_remove_target() -> qla2x00_remove_one() */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1511 | static void qlt_release(struct qla_tgt *tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1512 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1513 | scsi_qla_host_t *vha = tgt->vha; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1514 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 1515 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stop && |
| 1516 | !tgt->tgt_stopped) |
| 1517 | qlt_stop_phase1(tgt); |
| 1518 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1519 | if ((vha->vha_tgt.qla_tgt != NULL) && !tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1520 | qlt_stop_phase2(tgt); |
| 1521 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1522 | vha->vha_tgt.qla_tgt = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1523 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1524 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00d, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1525 | "Release of tgt %p finished\n", tgt); |
| 1526 | |
| 1527 | kfree(tgt); |
| 1528 | } |
| 1529 | |
| 1530 | /* ha->hardware_lock supposed to be held on entry */ |
| 1531 | static int qlt_sched_sess_work(struct qla_tgt *tgt, int type, |
| 1532 | const void *param, unsigned int param_size) |
| 1533 | { |
| 1534 | struct qla_tgt_sess_work_param *prm; |
| 1535 | unsigned long flags; |
| 1536 | |
| 1537 | prm = kzalloc(sizeof(*prm), GFP_ATOMIC); |
| 1538 | if (!prm) { |
| 1539 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf050, |
| 1540 | "qla_target(%d): Unable to create session " |
| 1541 | "work, command will be refused", 0); |
| 1542 | return -ENOMEM; |
| 1543 | } |
| 1544 | |
| 1545 | ql_dbg(ql_dbg_tgt_mgt, tgt->vha, 0xf00e, |
| 1546 | "Scheduling work (type %d, prm %p)" |
| 1547 | " to find session for param %p (size %d, tgt %p)\n", |
| 1548 | type, prm, param, param_size, tgt); |
| 1549 | |
| 1550 | prm->type = type; |
| 1551 | memcpy(&prm->tm_iocb, param, param_size); |
| 1552 | |
| 1553 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 1554 | list_add_tail(&prm->sess_works_list_entry, &tgt->sess_works_list); |
| 1555 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 1556 | |
| 1557 | schedule_work(&tgt->sess_work); |
| 1558 | |
| 1559 | return 0; |
| 1560 | } |
| 1561 | |
| 1562 | /* |
| 1563 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1564 | */ |
| 1565 | static void qlt_send_notify_ack(struct scsi_qla_host *vha, |
| 1566 | struct imm_ntfy_from_isp *ntfy, |
| 1567 | uint32_t add_flags, uint16_t resp_code, int resp_code_valid, |
| 1568 | uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan) |
| 1569 | { |
| 1570 | struct qla_hw_data *ha = vha->hw; |
| 1571 | request_t *pkt; |
| 1572 | struct nack_to_isp *nack; |
| 1573 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 1574 | if (!ha->flags.fw_started) |
| 1575 | return; |
| 1576 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1577 | ql_dbg(ql_dbg_tgt, vha, 0xe004, "Sending NOTIFY_ACK (ha=%p)\n", ha); |
| 1578 | |
| 1579 | /* Send marker if required */ |
| 1580 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1581 | return; |
| 1582 | |
| 1583 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
| 1584 | if (!pkt) { |
| 1585 | ql_dbg(ql_dbg_tgt, vha, 0xe049, |
| 1586 | "qla_target(%d): %s failed: unable to allocate " |
| 1587 | "request packet\n", vha->vp_idx, __func__); |
| 1588 | return; |
| 1589 | } |
| 1590 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1591 | if (vha->vha_tgt.qla_tgt != NULL) |
| 1592 | vha->vha_tgt.qla_tgt->notify_ack_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1593 | |
| 1594 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 1595 | pkt->entry_count = 1; |
| 1596 | |
| 1597 | nack = (struct nack_to_isp *)pkt; |
| 1598 | nack->ox_id = ntfy->ox_id; |
| 1599 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1600 | nack->u.isp24.handle = QLA_TGT_SKIP_HANDLE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1601 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 1602 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 1603 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1604 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1605 | } |
| 1606 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 1607 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 1608 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1609 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1610 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 1611 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 1612 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 1613 | nack->u.isp24.srr_flags = cpu_to_le16(srr_flags); |
| 1614 | nack->u.isp24.srr_reject_code = srr_reject_code; |
| 1615 | nack->u.isp24.srr_reject_code_expl = srr_explan; |
| 1616 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 1617 | |
| 1618 | ql_dbg(ql_dbg_tgt, vha, 0xe005, |
| 1619 | "qla_target(%d): Sending 24xx Notify Ack %d\n", |
| 1620 | vha->vp_idx, nack->u.isp24.status); |
| 1621 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1622 | /* Memory Barrier */ |
| 1623 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1624 | qla2x00_start_iocbs(vha, vha->req); |
| 1625 | } |
| 1626 | |
| 1627 | /* |
| 1628 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1629 | */ |
| 1630 | static void qlt_24xx_send_abts_resp(struct scsi_qla_host *vha, |
| 1631 | struct abts_recv_from_24xx *abts, uint32_t status, |
| 1632 | bool ids_reversed) |
| 1633 | { |
| 1634 | struct qla_hw_data *ha = vha->hw; |
| 1635 | struct abts_resp_to_24xx *resp; |
| 1636 | uint32_t f_ctl; |
| 1637 | uint8_t *p; |
| 1638 | |
| 1639 | ql_dbg(ql_dbg_tgt, vha, 0xe006, |
| 1640 | "Sending task mgmt ABTS response (ha=%p, atio=%p, status=%x\n", |
| 1641 | ha, abts, status); |
| 1642 | |
| 1643 | /* Send marker if required */ |
| 1644 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1645 | return; |
| 1646 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1647 | resp = (struct abts_resp_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1648 | if (!resp) { |
| 1649 | ql_dbg(ql_dbg_tgt, vha, 0xe04a, |
| 1650 | "qla_target(%d): %s failed: unable to allocate " |
| 1651 | "request packet", vha->vp_idx, __func__); |
| 1652 | return; |
| 1653 | } |
| 1654 | |
| 1655 | resp->entry_type = ABTS_RESP_24XX; |
| 1656 | resp->entry_count = 1; |
| 1657 | resp->nport_handle = abts->nport_handle; |
| 1658 | resp->vp_index = vha->vp_idx; |
| 1659 | resp->sof_type = abts->sof_type; |
| 1660 | resp->exchange_address = abts->exchange_address; |
| 1661 | resp->fcp_hdr_le = abts->fcp_hdr_le; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1662 | f_ctl = cpu_to_le32(F_CTL_EXCH_CONTEXT_RESP | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1663 | F_CTL_LAST_SEQ | F_CTL_END_SEQ | |
| 1664 | F_CTL_SEQ_INITIATIVE); |
| 1665 | p = (uint8_t *)&f_ctl; |
| 1666 | resp->fcp_hdr_le.f_ctl[0] = *p++; |
| 1667 | resp->fcp_hdr_le.f_ctl[1] = *p++; |
| 1668 | resp->fcp_hdr_le.f_ctl[2] = *p; |
| 1669 | if (ids_reversed) { |
| 1670 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1671 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1672 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1673 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1674 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1675 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1676 | } else { |
| 1677 | resp->fcp_hdr_le.d_id[0] = abts->fcp_hdr_le.s_id[0]; |
| 1678 | resp->fcp_hdr_le.d_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1679 | resp->fcp_hdr_le.d_id[2] = abts->fcp_hdr_le.s_id[2]; |
| 1680 | resp->fcp_hdr_le.s_id[0] = abts->fcp_hdr_le.d_id[0]; |
| 1681 | resp->fcp_hdr_le.s_id[1] = abts->fcp_hdr_le.d_id[1]; |
| 1682 | resp->fcp_hdr_le.s_id[2] = abts->fcp_hdr_le.d_id[2]; |
| 1683 | } |
| 1684 | resp->exchange_addr_to_abort = abts->exchange_addr_to_abort; |
| 1685 | if (status == FCP_TMF_CMPL) { |
| 1686 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_ACC; |
| 1687 | resp->payload.ba_acct.seq_id_valid = SEQ_ID_INVALID; |
| 1688 | resp->payload.ba_acct.low_seq_cnt = 0x0000; |
| 1689 | resp->payload.ba_acct.high_seq_cnt = 0xFFFF; |
| 1690 | resp->payload.ba_acct.ox_id = abts->fcp_hdr_le.ox_id; |
| 1691 | resp->payload.ba_acct.rx_id = abts->fcp_hdr_le.rx_id; |
| 1692 | } else { |
| 1693 | resp->fcp_hdr_le.r_ctl = R_CTL_BASIC_LINK_SERV | R_CTL_B_RJT; |
| 1694 | resp->payload.ba_rjt.reason_code = |
| 1695 | BA_RJT_REASON_CODE_UNABLE_TO_PERFORM; |
| 1696 | /* Other bytes are zero */ |
| 1697 | } |
| 1698 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1699 | vha->vha_tgt.qla_tgt->abts_resp_expected++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1700 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1701 | /* Memory Barrier */ |
| 1702 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1703 | qla2x00_start_iocbs(vha, vha->req); |
| 1704 | } |
| 1705 | |
| 1706 | /* |
| 1707 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1708 | */ |
| 1709 | static void qlt_24xx_retry_term_exchange(struct scsi_qla_host *vha, |
| 1710 | struct abts_resp_from_24xx_fw *entry) |
| 1711 | { |
| 1712 | struct ctio7_to_24xx *ctio; |
| 1713 | |
| 1714 | ql_dbg(ql_dbg_tgt, vha, 0xe007, |
| 1715 | "Sending retry TERM EXCH CTIO7 (ha=%p)\n", vha->hw); |
| 1716 | /* Send marker if required */ |
| 1717 | if (qlt_issue_marker(vha, 1) != QLA_SUCCESS) |
| 1718 | return; |
| 1719 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 1720 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1721 | if (ctio == NULL) { |
| 1722 | ql_dbg(ql_dbg_tgt, vha, 0xe04b, |
| 1723 | "qla_target(%d): %s failed: unable to allocate " |
| 1724 | "request packet\n", vha->vp_idx, __func__); |
| 1725 | return; |
| 1726 | } |
| 1727 | |
| 1728 | /* |
| 1729 | * We've got on entrance firmware's response on by us generated |
| 1730 | * ABTS response. So, in it ID fields are reversed. |
| 1731 | */ |
| 1732 | |
| 1733 | ctio->entry_type = CTIO_TYPE7; |
| 1734 | ctio->entry_count = 1; |
| 1735 | ctio->nport_handle = entry->nport_handle; |
| 1736 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1737 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1738 | ctio->vp_index = vha->vp_idx; |
| 1739 | ctio->initiator_id[0] = entry->fcp_hdr_le.d_id[0]; |
| 1740 | ctio->initiator_id[1] = entry->fcp_hdr_le.d_id[1]; |
| 1741 | ctio->initiator_id[2] = entry->fcp_hdr_le.d_id[2]; |
| 1742 | ctio->exchange_addr = entry->exchange_addr_to_abort; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1743 | ctio->u.status1.flags = cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1 | |
| 1744 | CTIO7_FLAGS_TERMINATE); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1745 | 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] | 1746 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 1747 | /* Memory Barrier */ |
| 1748 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1749 | qla2x00_start_iocbs(vha, vha->req); |
| 1750 | |
| 1751 | qlt_24xx_send_abts_resp(vha, (struct abts_recv_from_24xx *)entry, |
| 1752 | FCP_TMF_CMPL, true); |
| 1753 | } |
| 1754 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1755 | static int abort_cmd_for_tag(struct scsi_qla_host *vha, uint32_t tag) |
| 1756 | { |
| 1757 | struct qla_tgt_sess_op *op; |
| 1758 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1759 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1760 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1761 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1762 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1763 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1764 | op->aborted = true; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1765 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1766 | return 1; |
| 1767 | } |
| 1768 | } |
| 1769 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1770 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1771 | if (tag == op->atio.u.isp24.exchange_addr) { |
| 1772 | op->aborted = true; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1773 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1774 | return 1; |
| 1775 | } |
| 1776 | } |
| 1777 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1778 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1779 | if (tag == cmd->atio.u.isp24.exchange_addr) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1780 | cmd->aborted = 1; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1781 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1782 | return 1; |
| 1783 | } |
| 1784 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1785 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1786 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1787 | return 0; |
| 1788 | } |
| 1789 | |
| 1790 | /* drop cmds for the given lun |
| 1791 | * XXX only looks for cmds on the port through which lun reset was recieved |
| 1792 | * XXX does not go through the list of other port (which may have cmds |
| 1793 | * for the same lun) |
| 1794 | */ |
| 1795 | static void abort_cmds_for_lun(struct scsi_qla_host *vha, |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1796 | u64 lun, uint8_t *s_id) |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1797 | { |
| 1798 | struct qla_tgt_sess_op *op; |
| 1799 | struct qla_tgt_cmd *cmd; |
| 1800 | uint32_t key; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1801 | unsigned long flags; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1802 | |
| 1803 | key = sid_to_key(s_id); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1804 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1805 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 1806 | uint32_t op_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1807 | u64 op_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1808 | |
| 1809 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1810 | op_lun = scsilun_to_int( |
| 1811 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1812 | if (op_key == key && op_lun == lun) |
| 1813 | op->aborted = true; |
| 1814 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1815 | |
| 1816 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 1817 | uint32_t op_key; |
| 1818 | u64 op_lun; |
| 1819 | |
| 1820 | op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 1821 | op_lun = scsilun_to_int( |
| 1822 | (struct scsi_lun *)&op->atio.u.isp24.fcp_cmnd.lun); |
| 1823 | if (op_key == key && op_lun == lun) |
| 1824 | op->aborted = true; |
| 1825 | } |
| 1826 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1827 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 1828 | uint32_t cmd_key; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1829 | u64 cmd_lun; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1830 | |
| 1831 | cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 1832 | cmd_lun = scsilun_to_int( |
| 1833 | (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); |
| 1834 | if (cmd_key == key && cmd_lun == lun) |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 1835 | cmd->aborted = 1; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1836 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 1837 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1838 | } |
| 1839 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1840 | /* ha->hardware_lock supposed to be held on entry */ |
| 1841 | static int __qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1842 | struct abts_recv_from_24xx *abts, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1843 | { |
| 1844 | struct qla_hw_data *ha = vha->hw; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1845 | struct se_session *se_sess = sess->se_sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1846 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1847 | struct qla_tgt_cmd *cmd; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1848 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1849 | int rc; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1850 | bool found_lun = false; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1851 | unsigned long flags; |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1852 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1853 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1854 | list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 1855 | if (se_cmd->tag == abts->exchange_addr_to_abort) { |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1856 | found_lun = true; |
| 1857 | break; |
| 1858 | } |
| 1859 | } |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1860 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); |
Steve Hodgson | 06e97b4 | 2012-11-16 08:06:17 -0800 | [diff] [blame] | 1861 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 1862 | /* cmd not in LIO lists, look in qla list */ |
| 1863 | if (!found_lun) { |
| 1864 | if (abort_cmd_for_tag(vha, abts->exchange_addr_to_abort)) { |
| 1865 | /* send TASK_ABORT response immediately */ |
| 1866 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_CMPL, false); |
| 1867 | return 0; |
| 1868 | } else { |
| 1869 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf081, |
| 1870 | "unable to find cmd in driver or LIO for tag 0x%x\n", |
| 1871 | abts->exchange_addr_to_abort); |
| 1872 | return -ENOENT; |
| 1873 | } |
| 1874 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1875 | |
| 1876 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf00f, |
| 1877 | "qla_target(%d): task abort (tag=%d)\n", |
| 1878 | vha->vp_idx, abts->exchange_addr_to_abort); |
| 1879 | |
| 1880 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 1881 | if (mcmd == NULL) { |
| 1882 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf051, |
| 1883 | "qla_target(%d): %s: Allocation of ABORT cmd failed", |
| 1884 | vha->vp_idx, __func__); |
| 1885 | return -ENOMEM; |
| 1886 | } |
| 1887 | memset(mcmd, 0, sizeof(*mcmd)); |
| 1888 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1889 | cmd = container_of(se_cmd, struct qla_tgt_cmd, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1890 | mcmd->sess = sess; |
| 1891 | memcpy(&mcmd->orig_iocb.abts, abts, sizeof(mcmd->orig_iocb.abts)); |
Arun Easi | 80187f8 | 2014-09-25 06:14:53 -0400 | [diff] [blame] | 1892 | mcmd->reset_count = vha->hw->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 1893 | mcmd->tmr_func = QLA_TGT_ABTS; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1894 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 1895 | rc = ha->tgt.tgt_ops->handle_tmr(mcmd, cmd->unpacked_lun, mcmd->tmr_func, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1896 | abts->exchange_addr_to_abort); |
| 1897 | if (rc != 0) { |
| 1898 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf052, |
| 1899 | "qla_target(%d): tgt_ops->handle_tmr()" |
| 1900 | " failed: %d", vha->vp_idx, rc); |
| 1901 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 1902 | return -EFAULT; |
| 1903 | } |
| 1904 | |
| 1905 | return 0; |
| 1906 | } |
| 1907 | |
| 1908 | /* |
| 1909 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1910 | */ |
| 1911 | static void qlt_24xx_handle_abts(struct scsi_qla_host *vha, |
| 1912 | struct abts_recv_from_24xx *abts) |
| 1913 | { |
| 1914 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 1915 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1916 | uint32_t tag = abts->exchange_addr_to_abort; |
| 1917 | uint8_t s_id[3]; |
| 1918 | int rc; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1919 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1920 | |
| 1921 | if (le32_to_cpu(abts->fcp_hdr_le.parameter) & ABTS_PARAM_ABORT_SEQ) { |
| 1922 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf053, |
| 1923 | "qla_target(%d): ABTS: Abort Sequence not " |
| 1924 | "supported\n", vha->vp_idx); |
| 1925 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1926 | return; |
| 1927 | } |
| 1928 | |
| 1929 | if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { |
| 1930 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf010, |
| 1931 | "qla_target(%d): ABTS: Unknown Exchange " |
| 1932 | "Address received\n", vha->vp_idx); |
| 1933 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1934 | return; |
| 1935 | } |
| 1936 | |
| 1937 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf011, |
| 1938 | "qla_target(%d): task abort (s_id=%x:%x:%x, " |
| 1939 | "tag=%d, param=%x)\n", vha->vp_idx, abts->fcp_hdr_le.s_id[2], |
| 1940 | abts->fcp_hdr_le.s_id[1], abts->fcp_hdr_le.s_id[0], tag, |
| 1941 | le32_to_cpu(abts->fcp_hdr_le.parameter)); |
| 1942 | |
| 1943 | s_id[0] = abts->fcp_hdr_le.s_id[2]; |
| 1944 | s_id[1] = abts->fcp_hdr_le.s_id[1]; |
| 1945 | s_id[2] = abts->fcp_hdr_le.s_id[0]; |
| 1946 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1947 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1948 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 1949 | if (!sess) { |
| 1950 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf012, |
| 1951 | "qla_target(%d): task abort for non-existant session\n", |
| 1952 | vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 1953 | rc = qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1954 | QLA_TGT_SESS_WORK_ABORT, abts, sizeof(*abts)); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1955 | |
| 1956 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1957 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1958 | if (rc != 0) { |
| 1959 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, |
| 1960 | false); |
| 1961 | } |
| 1962 | return; |
| 1963 | } |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 1964 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 1965 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1966 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1967 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 1968 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1969 | return; |
| 1970 | } |
| 1971 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1972 | rc = __qlt_24xx_handle_abts(vha, abts, sess); |
| 1973 | if (rc != 0) { |
| 1974 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf054, |
| 1975 | "qla_target(%d): __qlt_24xx_handle_abts() failed: %d\n", |
| 1976 | vha->vp_idx, rc); |
| 1977 | qlt_24xx_send_abts_resp(vha, abts, FCP_TMF_REJECTED, false); |
| 1978 | return; |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | /* |
| 1983 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 1984 | */ |
| 1985 | static void qlt_24xx_send_task_mgmt_ctio(struct scsi_qla_host *ha, |
| 1986 | struct qla_tgt_mgmt_cmd *mcmd, uint32_t resp_code) |
| 1987 | { |
| 1988 | struct atio_from_isp *atio = &mcmd->orig_iocb.atio; |
| 1989 | struct ctio7_to_24xx *ctio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 1990 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1991 | |
| 1992 | ql_dbg(ql_dbg_tgt, ha, 0xe008, |
| 1993 | "Sending task mgmt CTIO7 (ha=%p, atio=%p, resp_code=%x\n", |
| 1994 | ha, atio, resp_code); |
| 1995 | |
| 1996 | /* Send marker if required */ |
| 1997 | if (qlt_issue_marker(ha, 1) != QLA_SUCCESS) |
| 1998 | return; |
| 1999 | |
| 2000 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(ha, NULL); |
| 2001 | if (ctio == NULL) { |
| 2002 | ql_dbg(ql_dbg_tgt, ha, 0xe04c, |
| 2003 | "qla_target(%d): %s failed: unable to allocate " |
| 2004 | "request packet\n", ha->vp_idx, __func__); |
| 2005 | return; |
| 2006 | } |
| 2007 | |
| 2008 | ctio->entry_type = CTIO_TYPE7; |
| 2009 | ctio->entry_count = 1; |
| 2010 | ctio->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 2011 | ctio->nport_handle = mcmd->sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2012 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2013 | ctio->vp_index = ha->vp_idx; |
| 2014 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2015 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2016 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2017 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2018 | temp = (atio->u.isp24.attr << 9)| |
| 2019 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2020 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2021 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2022 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2023 | ctio->u.status1.scsi_status = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2024 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID); |
| 2025 | ctio->u.status1.response_len = cpu_to_le16(8); |
Roland Dreier | e4b11b8 | 2012-09-18 15:10:56 -0700 | [diff] [blame] | 2026 | ctio->u.status1.sense_data[0] = resp_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2027 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 2028 | /* Memory Barrier */ |
| 2029 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2030 | qla2x00_start_iocbs(ha, ha->req); |
| 2031 | } |
| 2032 | |
| 2033 | void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *mcmd) |
| 2034 | { |
| 2035 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 2036 | } |
| 2037 | EXPORT_SYMBOL(qlt_free_mcmd); |
| 2038 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2039 | /* |
| 2040 | * ha->hardware_lock supposed to be held on entry. Might drop it, then |
| 2041 | * reacquire |
| 2042 | */ |
| 2043 | void qlt_send_resp_ctio(scsi_qla_host_t *vha, struct qla_tgt_cmd *cmd, |
| 2044 | uint8_t scsi_status, uint8_t sense_key, uint8_t asc, uint8_t ascq) |
| 2045 | { |
| 2046 | struct atio_from_isp *atio = &cmd->atio; |
| 2047 | struct ctio7_to_24xx *ctio; |
| 2048 | uint16_t temp; |
| 2049 | |
| 2050 | ql_dbg(ql_dbg_tgt_dif, vha, 0x3066, |
| 2051 | "Sending response CTIO7 (vha=%p, atio=%p, scsi_status=%02x, " |
| 2052 | "sense_key=%02x, asc=%02x, ascq=%02x", |
| 2053 | vha, atio, scsi_status, sense_key, asc, ascq); |
| 2054 | |
| 2055 | ctio = (struct ctio7_to_24xx *)qla2x00_alloc_iocbs(vha, NULL); |
| 2056 | if (!ctio) { |
| 2057 | ql_dbg(ql_dbg_async, vha, 0x3067, |
| 2058 | "qla2x00t(%ld): %s failed: unable to allocate request packet", |
| 2059 | vha->host_no, __func__); |
| 2060 | goto out; |
| 2061 | } |
| 2062 | |
| 2063 | ctio->entry_type = CTIO_TYPE7; |
| 2064 | ctio->entry_count = 1; |
| 2065 | ctio->handle = QLA_TGT_SKIP_HANDLE; |
| 2066 | ctio->nport_handle = cmd->sess->loop_id; |
| 2067 | ctio->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
| 2068 | ctio->vp_index = vha->vp_idx; |
| 2069 | ctio->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2070 | ctio->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2071 | ctio->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2072 | ctio->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2073 | temp = (atio->u.isp24.attr << 9) | |
| 2074 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS; |
| 2075 | ctio->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2076 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2077 | ctio->u.status1.ox_id = cpu_to_le16(temp); |
| 2078 | ctio->u.status1.scsi_status = |
| 2079 | cpu_to_le16(SS_RESPONSE_INFO_LEN_VALID | scsi_status); |
| 2080 | ctio->u.status1.response_len = cpu_to_le16(18); |
| 2081 | ctio->u.status1.residual = cpu_to_le32(get_datalen_for_atio(atio)); |
| 2082 | |
| 2083 | if (ctio->u.status1.residual != 0) |
| 2084 | ctio->u.status1.scsi_status |= |
| 2085 | cpu_to_le16(SS_RESIDUAL_UNDER); |
| 2086 | |
| 2087 | /* Response code and sense key */ |
| 2088 | put_unaligned_le32(((0x70 << 24) | (sense_key << 8)), |
| 2089 | (&ctio->u.status1.sense_data)[0]); |
| 2090 | /* Additional sense length */ |
| 2091 | put_unaligned_le32(0x0a, (&ctio->u.status1.sense_data)[1]); |
| 2092 | /* ASC and ASCQ */ |
| 2093 | put_unaligned_le32(((asc << 24) | (ascq << 16)), |
| 2094 | (&ctio->u.status1.sense_data)[3]); |
| 2095 | |
| 2096 | /* Memory Barrier */ |
| 2097 | wmb(); |
| 2098 | |
| 2099 | qla2x00_start_iocbs(vha, vha->req); |
| 2100 | out: |
| 2101 | return; |
| 2102 | } |
| 2103 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2104 | /* callback from target fabric module code */ |
| 2105 | void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *mcmd) |
| 2106 | { |
| 2107 | struct scsi_qla_host *vha = mcmd->sess->vha; |
| 2108 | struct qla_hw_data *ha = vha->hw; |
| 2109 | unsigned long flags; |
| 2110 | |
| 2111 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf013, |
| 2112 | "TM response mcmd (%p) status %#x state %#x", |
| 2113 | mcmd, mcmd->fc_tm_rsp, mcmd->flags); |
| 2114 | |
| 2115 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2116 | |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2117 | if (!vha->flags.online || mcmd->reset_count != ha->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2118 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2119 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2120 | * previous life, just abort the processing. |
| 2121 | */ |
| 2122 | ql_dbg(ql_dbg_async, vha, 0xe100, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 2123 | "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 2124 | vha->flags.online, qla2x00_reset_active(vha), |
| 2125 | mcmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2126 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2127 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2128 | return; |
| 2129 | } |
| 2130 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2131 | if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { |
| 2132 | if (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2133 | ELS_LOGO || |
| 2134 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2135 | ELS_PRLO || |
| 2136 | mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode == |
| 2137 | ELS_TPRLO) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2138 | ql_dbg(ql_dbg_disc, vha, 0x2106, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2139 | "TM response logo %phC status %#x state %#x", |
| 2140 | mcmd->sess->port_name, mcmd->fc_tm_rsp, |
| 2141 | mcmd->flags); |
| 2142 | qlt_schedule_sess_for_deletion_lock(mcmd->sess); |
| 2143 | } else { |
| 2144 | qlt_send_notify_ack(vha, &mcmd->orig_iocb.imm_ntfy, |
| 2145 | 0, 0, 0, 0, 0, 0); |
| 2146 | } |
| 2147 | } else { |
Swapnil Nagle | d7236ac | 2016-02-04 11:45:17 -0500 | [diff] [blame] | 2148 | if (mcmd->orig_iocb.atio.u.raw.entry_type == ABTS_RECV_24XX) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2149 | qlt_24xx_send_abts_resp(vha, &mcmd->orig_iocb.abts, |
| 2150 | mcmd->fc_tm_rsp, false); |
| 2151 | else |
| 2152 | qlt_24xx_send_task_mgmt_ctio(vha, mcmd, |
| 2153 | mcmd->fc_tm_rsp); |
| 2154 | } |
| 2155 | /* |
| 2156 | * Make the callback for ->free_mcmd() to queue_work() and invoke |
| 2157 | * target_put_sess_cmd() to drop cmd_kref to 1. The final |
| 2158 | * target_put_sess_cmd() call will be made from TFO->check_stop_free() |
| 2159 | * -> tcm_qla2xxx_check_stop_free() to release the TMR associated se_cmd |
| 2160 | * descriptor after TFO->queue_tm_rsp() -> tcm_qla2xxx_queue_tm_rsp() -> |
| 2161 | * qlt_xmit_tm_rsp() returns here.. |
| 2162 | */ |
| 2163 | ha->tgt.tgt_ops->free_mcmd(mcmd); |
| 2164 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2165 | } |
| 2166 | EXPORT_SYMBOL(qlt_xmit_tm_rsp); |
| 2167 | |
| 2168 | /* No locks */ |
| 2169 | static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm) |
| 2170 | { |
| 2171 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2172 | |
| 2173 | BUG_ON(cmd->sg_cnt == 0); |
| 2174 | |
| 2175 | prm->sg = (struct scatterlist *)cmd->sg; |
| 2176 | prm->seg_cnt = pci_map_sg(prm->tgt->ha->pdev, cmd->sg, |
| 2177 | cmd->sg_cnt, cmd->dma_data_direction); |
| 2178 | if (unlikely(prm->seg_cnt == 0)) |
| 2179 | goto out_err; |
| 2180 | |
| 2181 | prm->cmd->sg_mapped = 1; |
| 2182 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2183 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) { |
| 2184 | /* |
| 2185 | * If greater than four sg entries then we need to allocate |
| 2186 | * the continuation entries |
| 2187 | */ |
| 2188 | if (prm->seg_cnt > prm->tgt->datasegs_per_cmd) |
| 2189 | prm->req_cnt += DIV_ROUND_UP(prm->seg_cnt - |
| 2190 | prm->tgt->datasegs_per_cmd, |
| 2191 | prm->tgt->datasegs_per_cont); |
| 2192 | } else { |
| 2193 | /* DIF */ |
| 2194 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2195 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2196 | prm->seg_cnt = DIV_ROUND_UP(cmd->bufflen, cmd->blk_sz); |
| 2197 | prm->tot_dsds = prm->seg_cnt; |
| 2198 | } else |
| 2199 | prm->tot_dsds = prm->seg_cnt; |
| 2200 | |
| 2201 | if (cmd->prot_sg_cnt) { |
| 2202 | prm->prot_sg = cmd->prot_sg; |
| 2203 | prm->prot_seg_cnt = pci_map_sg(prm->tgt->ha->pdev, |
| 2204 | cmd->prot_sg, cmd->prot_sg_cnt, |
| 2205 | cmd->dma_data_direction); |
| 2206 | if (unlikely(prm->prot_seg_cnt == 0)) |
| 2207 | goto out_err; |
| 2208 | |
| 2209 | if ((cmd->se_cmd.prot_op == TARGET_PROT_DIN_INSERT) || |
| 2210 | (cmd->se_cmd.prot_op == TARGET_PROT_DOUT_STRIP)) { |
| 2211 | /* Dif Bundling not support here */ |
| 2212 | prm->prot_seg_cnt = DIV_ROUND_UP(cmd->bufflen, |
| 2213 | cmd->blk_sz); |
| 2214 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2215 | } else |
| 2216 | prm->tot_dsds += prm->prot_seg_cnt; |
| 2217 | } |
| 2218 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2219 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2220 | return 0; |
| 2221 | |
| 2222 | out_err: |
| 2223 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe04d, |
| 2224 | "qla_target(%d): PCI mapping failed: sg_cnt=%d", |
| 2225 | 0, prm->cmd->sg_cnt); |
| 2226 | return -1; |
| 2227 | } |
| 2228 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2229 | 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] | 2230 | { |
| 2231 | struct qla_hw_data *ha = vha->hw; |
| 2232 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 2233 | if (!cmd->sg_mapped) |
| 2234 | return; |
| 2235 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2236 | pci_unmap_sg(ha->pdev, cmd->sg, cmd->sg_cnt, cmd->dma_data_direction); |
| 2237 | cmd->sg_mapped = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2238 | |
| 2239 | if (cmd->prot_sg_cnt) |
| 2240 | pci_unmap_sg(ha->pdev, cmd->prot_sg, cmd->prot_sg_cnt, |
| 2241 | cmd->dma_data_direction); |
| 2242 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2243 | if (!cmd->ctx) |
| 2244 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2245 | |
Joe Carnuccio | d5ff0ee | 2017-05-24 18:06:24 -0700 | [diff] [blame] | 2246 | if (cmd->ctx_dsd_alloced) |
| 2247 | qla2x00_clean_dsd_pool(ha, cmd->ctx); |
| 2248 | |
| 2249 | 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] | 2250 | } |
| 2251 | |
| 2252 | static int qlt_check_reserve_free_req(struct scsi_qla_host *vha, |
| 2253 | uint32_t req_cnt) |
| 2254 | { |
Saurav Kashyap | d29fb73 | 2014-09-25 06:14:49 -0400 | [diff] [blame] | 2255 | uint32_t cnt, cnt_in; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2256 | |
| 2257 | if (vha->req->cnt < (req_cnt + 2)) { |
Arun Easi | 75554b6 | 2014-09-25 06:14:45 -0400 | [diff] [blame] | 2258 | cnt = (uint16_t)RD_REG_DWORD(vha->req->req_q_out); |
Saurav Kashyap | d29fb73 | 2014-09-25 06:14:49 -0400 | [diff] [blame] | 2259 | cnt_in = (uint16_t)RD_REG_DWORD(vha->req->req_q_in); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2260 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2261 | if (vha->req->ring_index < cnt) |
| 2262 | vha->req->cnt = cnt - vha->req->ring_index; |
| 2263 | else |
| 2264 | vha->req->cnt = vha->req->length - |
| 2265 | (vha->req->ring_index - cnt); |
Arnd Bergmann | bc7095a | 2016-03-15 22:40:31 +0100 | [diff] [blame] | 2266 | |
| 2267 | if (unlikely(vha->req->cnt < (req_cnt + 2))) { |
| 2268 | ql_dbg(ql_dbg_io, vha, 0x305a, |
| 2269 | "qla_target(%d): There is no room in the request ring: vha->req->ring_index=%d, vha->req->cnt=%d, req_cnt=%d Req-out=%d Req-in=%d Req-Length=%d\n", |
| 2270 | vha->vp_idx, vha->req->ring_index, |
| 2271 | vha->req->cnt, req_cnt, cnt, cnt_in, |
| 2272 | vha->req->length); |
| 2273 | return -EAGAIN; |
| 2274 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2275 | } |
| 2276 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2277 | vha->req->cnt -= req_cnt; |
| 2278 | |
| 2279 | return 0; |
| 2280 | } |
| 2281 | |
| 2282 | /* |
| 2283 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 2284 | */ |
| 2285 | static inline void *qlt_get_req_pkt(struct scsi_qla_host *vha) |
| 2286 | { |
| 2287 | /* Adjust ring index. */ |
| 2288 | vha->req->ring_index++; |
| 2289 | if (vha->req->ring_index == vha->req->length) { |
| 2290 | vha->req->ring_index = 0; |
| 2291 | vha->req->ring_ptr = vha->req->ring; |
| 2292 | } else { |
| 2293 | vha->req->ring_ptr++; |
| 2294 | } |
| 2295 | return (cont_entry_t *)vha->req->ring_ptr; |
| 2296 | } |
| 2297 | |
| 2298 | /* ha->hardware_lock supposed to be held on entry */ |
| 2299 | static inline uint32_t qlt_make_handle(struct scsi_qla_host *vha) |
| 2300 | { |
| 2301 | struct qla_hw_data *ha = vha->hw; |
| 2302 | uint32_t h; |
| 2303 | |
| 2304 | h = ha->tgt.current_handle; |
| 2305 | /* always increment cmd handle */ |
| 2306 | do { |
| 2307 | ++h; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2308 | if (h > DEFAULT_OUTSTANDING_COMMANDS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2309 | h = 1; /* 0 is QLA_TGT_NULL_HANDLE */ |
| 2310 | if (h == ha->tgt.current_handle) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2311 | ql_dbg(ql_dbg_io, vha, 0x305b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2312 | "qla_target(%d): Ran out of " |
| 2313 | "empty cmd slots in ha %p\n", vha->vp_idx, ha); |
| 2314 | h = QLA_TGT_NULL_HANDLE; |
| 2315 | break; |
| 2316 | } |
| 2317 | } while ((h == QLA_TGT_NULL_HANDLE) || |
| 2318 | (h == QLA_TGT_SKIP_HANDLE) || |
| 2319 | (ha->tgt.cmds[h-1] != NULL)); |
| 2320 | |
| 2321 | if (h != QLA_TGT_NULL_HANDLE) |
| 2322 | ha->tgt.current_handle = h; |
| 2323 | |
| 2324 | return h; |
| 2325 | } |
| 2326 | |
| 2327 | /* ha->hardware_lock supposed to be held on entry */ |
| 2328 | static int qlt_24xx_build_ctio_pkt(struct qla_tgt_prm *prm, |
| 2329 | struct scsi_qla_host *vha) |
| 2330 | { |
| 2331 | uint32_t h; |
| 2332 | struct ctio7_to_24xx *pkt; |
| 2333 | struct qla_hw_data *ha = vha->hw; |
| 2334 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2335 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2336 | |
| 2337 | pkt = (struct ctio7_to_24xx *)vha->req->ring_ptr; |
| 2338 | prm->pkt = pkt; |
| 2339 | memset(pkt, 0, sizeof(*pkt)); |
| 2340 | |
| 2341 | pkt->entry_type = CTIO_TYPE7; |
| 2342 | pkt->entry_count = (uint8_t)prm->req_cnt; |
| 2343 | pkt->vp_index = vha->vp_idx; |
| 2344 | |
| 2345 | h = qlt_make_handle(vha); |
| 2346 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2347 | /* |
| 2348 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2349 | * know the initiator's LOOP ID, hence we can't find |
| 2350 | * the session and, so, the command. |
| 2351 | */ |
| 2352 | return -EAGAIN; |
| 2353 | } else |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2354 | ha->tgt.cmds[h - 1] = prm->cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2355 | |
| 2356 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; |
| 2357 | pkt->nport_handle = prm->cmd->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2358 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2359 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2360 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2361 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2362 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 2363 | temp = atio->u.isp24.attr << 9; |
| 2364 | pkt->u.status0.flags |= cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 2365 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2366 | pkt->u.status0.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2367 | pkt->u.status0.relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2368 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2369 | return 0; |
| 2370 | } |
| 2371 | |
| 2372 | /* |
| 2373 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2374 | * that there is sufficient amount of request entries to not drop it. |
| 2375 | */ |
| 2376 | static void qlt_load_cont_data_segments(struct qla_tgt_prm *prm, |
| 2377 | struct scsi_qla_host *vha) |
| 2378 | { |
| 2379 | int cnt; |
| 2380 | uint32_t *dword_ptr; |
| 2381 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; |
| 2382 | |
| 2383 | /* Build continuation packets */ |
| 2384 | while (prm->seg_cnt > 0) { |
| 2385 | cont_a64_entry_t *cont_pkt64 = |
| 2386 | (cont_a64_entry_t *)qlt_get_req_pkt(vha); |
| 2387 | |
| 2388 | /* |
| 2389 | * Make sure that from cont_pkt64 none of |
| 2390 | * 64-bit specific fields used for 32-bit |
| 2391 | * addressing. Cast to (cont_entry_t *) for |
| 2392 | * that. |
| 2393 | */ |
| 2394 | |
| 2395 | memset(cont_pkt64, 0, sizeof(*cont_pkt64)); |
| 2396 | |
| 2397 | cont_pkt64->entry_count = 1; |
| 2398 | cont_pkt64->sys_define = 0; |
| 2399 | |
| 2400 | if (enable_64bit_addressing) { |
| 2401 | cont_pkt64->entry_type = CONTINUE_A64_TYPE; |
| 2402 | dword_ptr = |
| 2403 | (uint32_t *)&cont_pkt64->dseg_0_address; |
| 2404 | } else { |
| 2405 | cont_pkt64->entry_type = CONTINUE_TYPE; |
| 2406 | dword_ptr = |
| 2407 | (uint32_t *)&((cont_entry_t *) |
| 2408 | cont_pkt64)->dseg_0_address; |
| 2409 | } |
| 2410 | |
| 2411 | /* Load continuation entry data segments */ |
| 2412 | for (cnt = 0; |
| 2413 | cnt < prm->tgt->datasegs_per_cont && prm->seg_cnt; |
| 2414 | cnt++, prm->seg_cnt--) { |
| 2415 | *dword_ptr++ = |
| 2416 | cpu_to_le32(pci_dma_lo32 |
| 2417 | (sg_dma_address(prm->sg))); |
| 2418 | if (enable_64bit_addressing) { |
| 2419 | *dword_ptr++ = |
| 2420 | cpu_to_le32(pci_dma_hi32 |
| 2421 | (sg_dma_address |
| 2422 | (prm->sg))); |
| 2423 | } |
| 2424 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2425 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2426 | prm->sg = sg_next(prm->sg); |
| 2427 | } |
| 2428 | } |
| 2429 | } |
| 2430 | |
| 2431 | /* |
| 2432 | * ha->hardware_lock supposed to be held on entry. We have already made sure |
| 2433 | * that there is sufficient amount of request entries to not drop it. |
| 2434 | */ |
| 2435 | static void qlt_load_data_segments(struct qla_tgt_prm *prm, |
| 2436 | struct scsi_qla_host *vha) |
| 2437 | { |
| 2438 | int cnt; |
| 2439 | uint32_t *dword_ptr; |
| 2440 | int enable_64bit_addressing = prm->tgt->tgt_enable_64bit_addr; |
| 2441 | struct ctio7_to_24xx *pkt24 = (struct ctio7_to_24xx *)prm->pkt; |
| 2442 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2443 | pkt24->u.status0.transfer_length = cpu_to_le32(prm->cmd->bufflen); |
| 2444 | |
| 2445 | /* Setup packet address segment pointer */ |
| 2446 | dword_ptr = pkt24->u.status0.dseg_0_address; |
| 2447 | |
| 2448 | /* Set total data segment count */ |
| 2449 | if (prm->seg_cnt) |
| 2450 | pkt24->dseg_count = cpu_to_le16(prm->seg_cnt); |
| 2451 | |
| 2452 | if (prm->seg_cnt == 0) { |
| 2453 | /* No data transfer */ |
| 2454 | *dword_ptr++ = 0; |
| 2455 | *dword_ptr = 0; |
| 2456 | return; |
| 2457 | } |
| 2458 | |
| 2459 | /* If scatter gather */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2460 | |
| 2461 | /* Load command entry data segments */ |
| 2462 | for (cnt = 0; |
| 2463 | (cnt < prm->tgt->datasegs_per_cmd) && prm->seg_cnt; |
| 2464 | cnt++, prm->seg_cnt--) { |
| 2465 | *dword_ptr++ = |
| 2466 | cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg))); |
| 2467 | if (enable_64bit_addressing) { |
| 2468 | *dword_ptr++ = |
| 2469 | cpu_to_le32(pci_dma_hi32( |
| 2470 | sg_dma_address(prm->sg))); |
| 2471 | } |
| 2472 | *dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg)); |
| 2473 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2474 | prm->sg = sg_next(prm->sg); |
| 2475 | } |
| 2476 | |
| 2477 | qlt_load_cont_data_segments(prm, vha); |
| 2478 | } |
| 2479 | |
| 2480 | static inline int qlt_has_data(struct qla_tgt_cmd *cmd) |
| 2481 | { |
| 2482 | return cmd->bufflen > 0; |
| 2483 | } |
| 2484 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2485 | static void qlt_print_dif_err(struct qla_tgt_prm *prm) |
| 2486 | { |
| 2487 | struct qla_tgt_cmd *cmd; |
| 2488 | struct scsi_qla_host *vha; |
| 2489 | |
| 2490 | /* asc 0x10=dif error */ |
| 2491 | if (prm->sense_buffer && (prm->sense_buffer[12] == 0x10)) { |
| 2492 | cmd = prm->cmd; |
| 2493 | vha = cmd->vha; |
| 2494 | /* ASCQ */ |
| 2495 | switch (prm->sense_buffer[13]) { |
| 2496 | case 1: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2497 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00b, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2498 | "BE detected Guard TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2499 | "se_cmd=%p tag[%x]", |
| 2500 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2501 | cmd->atio.u.isp24.exchange_addr); |
| 2502 | break; |
| 2503 | case 2: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2504 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00c, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2505 | "BE detected APP TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2506 | "se_cmd=%p tag[%x]", |
| 2507 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2508 | cmd->atio.u.isp24.exchange_addr); |
| 2509 | break; |
| 2510 | case 3: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2511 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00f, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2512 | "BE detected REF TAG ERR: lba[0x%llx|%lld] len[0x%x] " |
| 2513 | "se_cmd=%p tag[%x]", |
| 2514 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2515 | cmd->atio.u.isp24.exchange_addr); |
| 2516 | break; |
| 2517 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2518 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe010, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2519 | "BE detected Dif ERR: lba[%llx|%lld] len[%x] " |
| 2520 | "se_cmd=%p tag[%x]", |
| 2521 | cmd->lba, cmd->lba, cmd->num_blks, &cmd->se_cmd, |
| 2522 | cmd->atio.u.isp24.exchange_addr); |
| 2523 | break; |
| 2524 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 2525 | ql_dump_buffer(ql_dbg_tgt_dif, vha, 0xe011, cmd->cdb, 16); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2526 | } |
| 2527 | } |
| 2528 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2529 | /* |
| 2530 | * Called without ha->hardware_lock held |
| 2531 | */ |
| 2532 | static int qlt_pre_xmit_response(struct qla_tgt_cmd *cmd, |
| 2533 | struct qla_tgt_prm *prm, int xmit_type, uint8_t scsi_status, |
| 2534 | uint32_t *full_req_cnt) |
| 2535 | { |
| 2536 | struct qla_tgt *tgt = cmd->tgt; |
| 2537 | struct scsi_qla_host *vha = tgt->vha; |
| 2538 | struct qla_hw_data *ha = vha->hw; |
| 2539 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2540 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2541 | prm->cmd = cmd; |
| 2542 | prm->tgt = tgt; |
| 2543 | prm->rq_result = scsi_status; |
| 2544 | prm->sense_buffer = &cmd->sense_buffer[0]; |
| 2545 | prm->sense_buffer_len = TRANSPORT_SENSE_BUFFER; |
| 2546 | prm->sg = NULL; |
| 2547 | prm->seg_cnt = -1; |
| 2548 | prm->req_cnt = 1; |
| 2549 | prm->add_status_pkt = 0; |
| 2550 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2551 | /* Send marker if required */ |
| 2552 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) |
| 2553 | return -EFAULT; |
| 2554 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2555 | if ((xmit_type & QLA_TGT_XMIT_DATA) && qlt_has_data(cmd)) { |
| 2556 | if (qlt_pci_map_calc_cnt(prm) != 0) |
| 2557 | return -EAGAIN; |
| 2558 | } |
| 2559 | |
| 2560 | *full_req_cnt = prm->req_cnt; |
| 2561 | |
| 2562 | if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { |
| 2563 | prm->residual = se_cmd->residual_count; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2564 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x305c, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2565 | "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2566 | prm->residual, se_cmd->tag, |
| 2567 | se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, |
| 2568 | cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2569 | prm->rq_result |= SS_RESIDUAL_UNDER; |
| 2570 | } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { |
| 2571 | prm->residual = se_cmd->residual_count; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 2572 | ql_dbg(ql_dbg_io, vha, 0x305d, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 2573 | "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", |
| 2574 | prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? |
| 2575 | se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2576 | prm->rq_result |= SS_RESIDUAL_OVER; |
| 2577 | } |
| 2578 | |
| 2579 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 2580 | /* |
| 2581 | * If QLA_TGT_XMIT_DATA is not set, add_status_pkt will be |
| 2582 | * ignored in *xmit_response() below |
| 2583 | */ |
| 2584 | if (qlt_has_data(cmd)) { |
| 2585 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer) || |
| 2586 | (IS_FWI2_CAPABLE(ha) && |
| 2587 | (prm->rq_result != 0))) { |
| 2588 | prm->add_status_pkt = 1; |
| 2589 | (*full_req_cnt)++; |
| 2590 | } |
| 2591 | } |
| 2592 | } |
| 2593 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2594 | return 0; |
| 2595 | } |
| 2596 | |
| 2597 | static inline int qlt_need_explicit_conf(struct qla_hw_data *ha, |
| 2598 | struct qla_tgt_cmd *cmd, int sending_sense) |
| 2599 | { |
| 2600 | if (ha->tgt.enable_class_2) |
| 2601 | return 0; |
| 2602 | |
| 2603 | if (sending_sense) |
| 2604 | return cmd->conf_compl_supported; |
| 2605 | else |
| 2606 | return ha->tgt.enable_explicit_conf && |
| 2607 | cmd->conf_compl_supported; |
| 2608 | } |
| 2609 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2610 | static void qlt_24xx_init_ctio_to_isp(struct ctio7_to_24xx *ctio, |
| 2611 | struct qla_tgt_prm *prm) |
| 2612 | { |
| 2613 | prm->sense_buffer_len = min_t(uint32_t, prm->sense_buffer_len, |
| 2614 | (uint32_t)sizeof(ctio->u.status1.sense_data)); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2615 | ctio->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_SEND_STATUS); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2616 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 0)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2617 | ctio->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2618 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2619 | CTIO7_FLAGS_CONFORM_REQ); |
| 2620 | } |
| 2621 | ctio->u.status0.residual = cpu_to_le32(prm->residual); |
| 2622 | ctio->u.status0.scsi_status = cpu_to_le16(prm->rq_result); |
| 2623 | if (QLA_TGT_SENSE_VALID(prm->sense_buffer)) { |
| 2624 | int i; |
| 2625 | |
| 2626 | if (qlt_need_explicit_conf(prm->tgt->ha, prm->cmd, 1)) { |
Quinn Tran | df2e32c | 2017-01-19 22:27:53 -0800 | [diff] [blame] | 2627 | if ((prm->rq_result & SS_SCSI_STATUS_BYTE) != 0) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2628 | ql_dbg(ql_dbg_tgt, prm->cmd->vha, 0xe017, |
| 2629 | "Skipping EXPLICIT_CONFORM and " |
| 2630 | "CTIO7_FLAGS_CONFORM_REQ for FCP READ w/ " |
| 2631 | "non GOOD status\n"); |
| 2632 | goto skip_explict_conf; |
| 2633 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2634 | ctio->u.status1.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2635 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 2636 | CTIO7_FLAGS_CONFORM_REQ); |
| 2637 | } |
| 2638 | skip_explict_conf: |
| 2639 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2640 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2641 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2642 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2643 | ctio->u.status1.scsi_status |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2644 | cpu_to_le16(SS_SENSE_LEN_VALID); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2645 | ctio->u.status1.sense_length = |
| 2646 | cpu_to_le16(prm->sense_buffer_len); |
| 2647 | for (i = 0; i < prm->sense_buffer_len/4; i++) |
| 2648 | ((uint32_t *)ctio->u.status1.sense_data)[i] = |
| 2649 | cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2650 | |
| 2651 | qlt_print_dif_err(prm); |
| 2652 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2653 | } else { |
| 2654 | ctio->u.status1.flags &= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2655 | ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2656 | ctio->u.status1.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2657 | cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2658 | ctio->u.status1.sense_length = 0; |
| 2659 | memset(ctio->u.status1.sense_data, 0, |
| 2660 | sizeof(ctio->u.status1.sense_data)); |
| 2661 | } |
| 2662 | |
| 2663 | /* Sense with len > 24, is it possible ??? */ |
| 2664 | } |
| 2665 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2666 | static inline int |
| 2667 | qlt_hba_err_chk_enabled(struct se_cmd *se_cmd) |
| 2668 | { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2669 | switch (se_cmd->prot_op) { |
| 2670 | case TARGET_PROT_DOUT_INSERT: |
| 2671 | case TARGET_PROT_DIN_STRIP: |
| 2672 | if (ql2xenablehba_err_chk >= 1) |
| 2673 | return 1; |
| 2674 | break; |
| 2675 | case TARGET_PROT_DOUT_PASS: |
| 2676 | case TARGET_PROT_DIN_PASS: |
| 2677 | if (ql2xenablehba_err_chk >= 2) |
| 2678 | return 1; |
| 2679 | break; |
| 2680 | case TARGET_PROT_DIN_INSERT: |
| 2681 | case TARGET_PROT_DOUT_STRIP: |
| 2682 | return 1; |
| 2683 | default: |
| 2684 | break; |
| 2685 | } |
| 2686 | return 0; |
| 2687 | } |
| 2688 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2689 | static inline int |
| 2690 | qla_tgt_ref_mask_check(struct se_cmd *se_cmd) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2691 | { |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2692 | switch (se_cmd->prot_op) { |
| 2693 | case TARGET_PROT_DIN_INSERT: |
| 2694 | case TARGET_PROT_DOUT_INSERT: |
| 2695 | case TARGET_PROT_DIN_STRIP: |
| 2696 | case TARGET_PROT_DOUT_STRIP: |
| 2697 | case TARGET_PROT_DIN_PASS: |
| 2698 | case TARGET_PROT_DOUT_PASS: |
| 2699 | return 1; |
| 2700 | default: |
| 2701 | return 0; |
| 2702 | } |
| 2703 | return 0; |
| 2704 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2705 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2706 | /* |
| 2707 | * qla_tgt_set_dif_tags - Extract Ref and App tags from SCSI command |
| 2708 | */ |
| 2709 | static void |
| 2710 | qla_tgt_set_dif_tags(struct qla_tgt_cmd *cmd, struct crc_context *ctx, |
| 2711 | uint16_t *pfw_prot_opts) |
| 2712 | { |
| 2713 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2714 | uint32_t lba = 0xffffffff & se_cmd->t_task_lba; |
| 2715 | scsi_qla_host_t *vha = cmd->tgt->vha; |
| 2716 | struct qla_hw_data *ha = vha->hw; |
| 2717 | uint32_t t32 = 0; |
| 2718 | |
| 2719 | /* |
| 2720 | * wait till Mode Sense/Select cmd, modepage Ah, subpage 2 |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2721 | * have been immplemented by TCM, before AppTag is avail. |
| 2722 | * Look for modesense_handlers[] |
| 2723 | */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2724 | ctx->app_tag = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2725 | ctx->app_tag_mask[0] = 0x0; |
| 2726 | ctx->app_tag_mask[1] = 0x0; |
| 2727 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2728 | if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2729 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2730 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2731 | *pfw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2732 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2733 | *pfw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2734 | } |
| 2735 | |
| 2736 | t32 = ha->tgt.tgt_ops->get_dif_tags(cmd, pfw_prot_opts); |
| 2737 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2738 | switch (se_cmd->prot_type) { |
| 2739 | case TARGET_DIF_TYPE0_PROT: |
| 2740 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2741 | * No check for ql2xenablehba_err_chk, as it |
| 2742 | * would be an I/O error if hba tag generation |
| 2743 | * is not done. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2744 | */ |
| 2745 | ctx->ref_tag = cpu_to_le32(lba); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2746 | /* enable ALL bytes of the ref tag */ |
| 2747 | ctx->ref_tag_mask[0] = 0xff; |
| 2748 | ctx->ref_tag_mask[1] = 0xff; |
| 2749 | ctx->ref_tag_mask[2] = 0xff; |
| 2750 | ctx->ref_tag_mask[3] = 0xff; |
| 2751 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2752 | case TARGET_DIF_TYPE1_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2753 | /* |
| 2754 | * For TYPE 1 protection: 16 bit GUARD tag, 32 bit |
| 2755 | * REF tag, and 16 bit app tag. |
| 2756 | */ |
| 2757 | ctx->ref_tag = cpu_to_le32(lba); |
| 2758 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2759 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2760 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2761 | break; |
| 2762 | } |
| 2763 | /* enable ALL bytes of the ref tag */ |
| 2764 | ctx->ref_tag_mask[0] = 0xff; |
| 2765 | ctx->ref_tag_mask[1] = 0xff; |
| 2766 | ctx->ref_tag_mask[2] = 0xff; |
| 2767 | ctx->ref_tag_mask[3] = 0xff; |
| 2768 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2769 | case TARGET_DIF_TYPE2_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2770 | /* |
| 2771 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF |
| 2772 | * tag has to match LBA in CDB + N |
| 2773 | */ |
| 2774 | ctx->ref_tag = cpu_to_le32(lba); |
| 2775 | if (!qla_tgt_ref_mask_check(se_cmd) || |
| 2776 | !(ha->tgt.tgt_ops->chk_dif_tags(t32))) { |
| 2777 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2778 | break; |
| 2779 | } |
| 2780 | /* enable ALL bytes of the ref tag */ |
| 2781 | ctx->ref_tag_mask[0] = 0xff; |
| 2782 | ctx->ref_tag_mask[1] = 0xff; |
| 2783 | ctx->ref_tag_mask[2] = 0xff; |
| 2784 | ctx->ref_tag_mask[3] = 0xff; |
| 2785 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2786 | case TARGET_DIF_TYPE3_PROT: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2787 | /* For TYPE 3 protection: 16 bit GUARD only */ |
| 2788 | *pfw_prot_opts |= PO_DIS_REF_TAG_VALD; |
| 2789 | ctx->ref_tag_mask[0] = ctx->ref_tag_mask[1] = |
| 2790 | ctx->ref_tag_mask[2] = ctx->ref_tag_mask[3] = 0x00; |
| 2791 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2792 | } |
| 2793 | } |
| 2794 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2795 | static inline int |
| 2796 | qlt_build_ctio_crc2_pkt(struct qla_tgt_prm *prm, scsi_qla_host_t *vha) |
| 2797 | { |
| 2798 | uint32_t *cur_dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2799 | uint32_t transfer_length = 0; |
| 2800 | uint32_t data_bytes; |
| 2801 | uint32_t dif_bytes; |
| 2802 | uint8_t bundling = 1; |
| 2803 | uint8_t *clr_ptr; |
| 2804 | struct crc_context *crc_ctx_pkt = NULL; |
| 2805 | struct qla_hw_data *ha; |
| 2806 | struct ctio_crc2_to_fw *pkt; |
| 2807 | dma_addr_t crc_ctx_dma; |
| 2808 | uint16_t fw_prot_opts = 0; |
| 2809 | struct qla_tgt_cmd *cmd = prm->cmd; |
| 2810 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2811 | uint32_t h; |
| 2812 | struct atio_from_isp *atio = &prm->cmd->atio; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2813 | struct qla_tc_param tc; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2814 | uint16_t t16; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2815 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2816 | ha = vha->hw; |
| 2817 | |
| 2818 | pkt = (struct ctio_crc2_to_fw *)vha->req->ring_ptr; |
| 2819 | prm->pkt = pkt; |
| 2820 | memset(pkt, 0, sizeof(*pkt)); |
| 2821 | |
| 2822 | ql_dbg(ql_dbg_tgt, vha, 0xe071, |
| 2823 | "qla_target(%d):%s: se_cmd[%p] CRC2 prot_op[0x%x] cmd prot sg:cnt[%p:%x] lba[%llu]\n", |
| 2824 | vha->vp_idx, __func__, se_cmd, se_cmd->prot_op, |
| 2825 | prm->prot_sg, prm->prot_seg_cnt, se_cmd->t_task_lba); |
| 2826 | |
| 2827 | if ((se_cmd->prot_op == TARGET_PROT_DIN_INSERT) || |
| 2828 | (se_cmd->prot_op == TARGET_PROT_DOUT_STRIP)) |
| 2829 | bundling = 0; |
| 2830 | |
| 2831 | /* Compute dif len and adjust data len to incude protection */ |
| 2832 | data_bytes = cmd->bufflen; |
| 2833 | dif_bytes = (data_bytes / cmd->blk_sz) * 8; |
| 2834 | |
| 2835 | switch (se_cmd->prot_op) { |
| 2836 | case TARGET_PROT_DIN_INSERT: |
| 2837 | case TARGET_PROT_DOUT_STRIP: |
| 2838 | transfer_length = data_bytes; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2839 | if (cmd->prot_sg_cnt) |
| 2840 | data_bytes += dif_bytes; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2841 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2842 | case TARGET_PROT_DIN_STRIP: |
| 2843 | case TARGET_PROT_DOUT_INSERT: |
| 2844 | case TARGET_PROT_DIN_PASS: |
| 2845 | case TARGET_PROT_DOUT_PASS: |
| 2846 | transfer_length = data_bytes + dif_bytes; |
| 2847 | break; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2848 | default: |
| 2849 | BUG(); |
| 2850 | break; |
| 2851 | } |
| 2852 | |
| 2853 | if (!qlt_hba_err_chk_enabled(se_cmd)) |
| 2854 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 2855 | /* HBA error checking enabled */ |
| 2856 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 2857 | if ((se_cmd->prot_type == TARGET_DIF_TYPE1_PROT) || |
| 2858 | (se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)) |
| 2859 | fw_prot_opts |= PO_DIS_VALD_APP_ESC; |
| 2860 | else if (se_cmd->prot_type == TARGET_DIF_TYPE3_PROT) |
| 2861 | fw_prot_opts |= PO_DIS_VALD_APP_REF_ESC; |
| 2862 | } |
| 2863 | |
| 2864 | switch (se_cmd->prot_op) { |
| 2865 | case TARGET_PROT_DIN_INSERT: |
| 2866 | case TARGET_PROT_DOUT_INSERT: |
| 2867 | fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 2868 | break; |
| 2869 | case TARGET_PROT_DIN_STRIP: |
| 2870 | case TARGET_PROT_DOUT_STRIP: |
| 2871 | fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 2872 | break; |
| 2873 | case TARGET_PROT_DIN_PASS: |
| 2874 | case TARGET_PROT_DOUT_PASS: |
| 2875 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2876 | /* FUTURE: does tcm require T10CRC<->IPCKSUM conversion? */ |
| 2877 | break; |
| 2878 | default:/* Normal Request */ |
| 2879 | fw_prot_opts |= PO_MODE_DIF_PASS; |
| 2880 | break; |
| 2881 | } |
| 2882 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2883 | /* ---- PKT ---- */ |
| 2884 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 2885 | pkt->entry_type = CTIO_CRC2; |
| 2886 | pkt->entry_count = 1; |
| 2887 | pkt->vp_index = vha->vp_idx; |
| 2888 | |
| 2889 | h = qlt_make_handle(vha); |
| 2890 | if (unlikely(h == QLA_TGT_NULL_HANDLE)) { |
| 2891 | /* |
| 2892 | * CTIO type 7 from the firmware doesn't provide a way to |
| 2893 | * know the initiator's LOOP ID, hence we can't find |
| 2894 | * the session and, so, the command. |
| 2895 | */ |
| 2896 | return -EAGAIN; |
| 2897 | } else |
| 2898 | ha->tgt.cmds[h-1] = prm->cmd; |
| 2899 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2900 | pkt->handle = h | CTIO_COMPLETION_HANDLE_MARK; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2901 | pkt->nport_handle = cpu_to_le16(prm->cmd->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2902 | pkt->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2903 | pkt->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 2904 | pkt->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 2905 | pkt->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 2906 | pkt->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2907 | |
| 2908 | /* silence compile warning */ |
| 2909 | t16 = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 2910 | pkt->ox_id = cpu_to_le16(t16); |
| 2911 | |
| 2912 | t16 = (atio->u.isp24.attr << 9); |
| 2913 | pkt->flags |= cpu_to_le16(t16); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2914 | pkt->relative_offset = cpu_to_le32(prm->cmd->offset); |
| 2915 | |
| 2916 | /* Set transfer direction */ |
| 2917 | if (cmd->dma_data_direction == DMA_TO_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2918 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_IN); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2919 | else if (cmd->dma_data_direction == DMA_FROM_DEVICE) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2920 | pkt->flags = cpu_to_le16(CTIO7_FLAGS_DATA_OUT); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2921 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2922 | pkt->dseg_count = prm->tot_dsds; |
| 2923 | /* Fibre channel byte count */ |
| 2924 | pkt->transfer_length = cpu_to_le32(transfer_length); |
| 2925 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2926 | /* ----- CRC context -------- */ |
| 2927 | |
| 2928 | /* Allocate CRC context from global pool */ |
| 2929 | crc_ctx_pkt = cmd->ctx = |
| 2930 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
| 2931 | |
| 2932 | if (!crc_ctx_pkt) |
| 2933 | goto crc_queuing_error; |
| 2934 | |
| 2935 | /* Zero out CTX area. */ |
| 2936 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 2937 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 2938 | |
| 2939 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 2940 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 2941 | |
| 2942 | /* Set handle */ |
| 2943 | crc_ctx_pkt->handle = pkt->handle; |
| 2944 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2945 | qla_tgt_set_dif_tags(cmd, crc_ctx_pkt, &fw_prot_opts); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2946 | |
| 2947 | pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 2948 | pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 2949 | pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 2950 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2951 | if (!bundling) { |
| 2952 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 2953 | } else { |
| 2954 | /* |
| 2955 | * Configure Bundling if we need to fetch interlaving |
| 2956 | * protection PCI accesses |
| 2957 | */ |
| 2958 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 2959 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 2960 | crc_ctx_pkt->u.bundling.dseg_count = |
| 2961 | cpu_to_le16(prm->tot_dsds - prm->prot_seg_cnt); |
| 2962 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 2963 | } |
| 2964 | |
| 2965 | /* Finish the common fields of CRC pkt */ |
| 2966 | crc_ctx_pkt->blk_size = cpu_to_le16(cmd->blk_sz); |
| 2967 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 2968 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2969 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2970 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2971 | memset((uint8_t *)&tc, 0 , sizeof(tc)); |
| 2972 | tc.vha = vha; |
| 2973 | tc.blk_sz = cmd->blk_sz; |
| 2974 | tc.bufflen = cmd->bufflen; |
| 2975 | tc.sg = cmd->sg; |
| 2976 | tc.prot_sg = cmd->prot_sg; |
| 2977 | tc.ctx = crc_ctx_pkt; |
| 2978 | tc.ctx_dsd_alloced = &cmd->ctx_dsd_alloced; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2979 | |
| 2980 | /* Walks data segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2981 | pkt->flags |= cpu_to_le16(CTIO7_FLAGS_DSD_PTR); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2982 | |
| 2983 | if (!bundling && prm->prot_seg_cnt) { |
| 2984 | if (qla24xx_walk_and_build_sglist_no_difb(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2985 | prm->tot_dsds, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2986 | goto crc_queuing_error; |
| 2987 | } else if (qla24xx_walk_and_build_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2988 | (prm->tot_dsds - prm->prot_seg_cnt), &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2989 | goto crc_queuing_error; |
| 2990 | |
| 2991 | if (bundling && prm->prot_seg_cnt) { |
| 2992 | /* Walks dif segments */ |
Quinn Tran | c7ee3bd | 2014-06-02 07:02:16 -0400 | [diff] [blame] | 2993 | pkt->add_flags |= CTIO_CRC2_AF_DIF_DSD_ENA; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2994 | |
| 2995 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 2996 | if (qla24xx_walk_and_build_prot_sglist(ha, NULL, cur_dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 2997 | prm->prot_seg_cnt, &tc)) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 2998 | goto crc_queuing_error; |
| 2999 | } |
| 3000 | return QLA_SUCCESS; |
| 3001 | |
| 3002 | crc_queuing_error: |
| 3003 | /* Cleanup will be performed by the caller */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3004 | vha->hw->tgt.cmds[h - 1] = NULL; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3005 | |
| 3006 | return QLA_FUNCTION_FAILED; |
| 3007 | } |
| 3008 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3009 | /* |
| 3010 | * Callback to setup response of xmit_type of QLA_TGT_XMIT_DATA and * |
| 3011 | * QLA_TGT_XMIT_STATUS for >= 24xx silicon |
| 3012 | */ |
| 3013 | int qlt_xmit_response(struct qla_tgt_cmd *cmd, int xmit_type, |
| 3014 | uint8_t scsi_status) |
| 3015 | { |
| 3016 | struct scsi_qla_host *vha = cmd->vha; |
| 3017 | struct qla_hw_data *ha = vha->hw; |
| 3018 | struct ctio7_to_24xx *pkt; |
| 3019 | struct qla_tgt_prm prm; |
| 3020 | uint32_t full_req_cnt = 0; |
| 3021 | unsigned long flags = 0; |
| 3022 | int res; |
| 3023 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3024 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3025 | if (cmd->sess && cmd->sess->deleted) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3026 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3027 | if (cmd->sess->logout_completed) |
| 3028 | /* no need to terminate. FW already freed exchange. */ |
| 3029 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 3030 | else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3031 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3032 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3033 | return 0; |
| 3034 | } |
| 3035 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3036 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3037 | memset(&prm, 0, sizeof(prm)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3038 | |
| 3039 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe018, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3040 | "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p]\n", |
| 3041 | (xmit_type & QLA_TGT_XMIT_STATUS) ? |
| 3042 | 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, |
| 3043 | &cmd->se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3044 | |
| 3045 | res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, |
| 3046 | &full_req_cnt); |
| 3047 | if (unlikely(res != 0)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3048 | return res; |
| 3049 | } |
| 3050 | |
| 3051 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3052 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3053 | if (xmit_type == QLA_TGT_XMIT_STATUS) |
| 3054 | vha->tgt_counters.core_qla_snd_status++; |
| 3055 | else |
| 3056 | vha->tgt_counters.core_qla_que_buf++; |
| 3057 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3058 | if (!ha->flags.fw_started || cmd->reset_count != ha->chip_reset) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3059 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3060 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3061 | * previous life, just abort the processing. |
| 3062 | */ |
| 3063 | cmd->state = QLA_TGT_STATE_PROCESSED; |
| 3064 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 3065 | ql_dbg(ql_dbg_async, vha, 0xe101, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3066 | "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3067 | vha->flags.online, qla2x00_reset_active(vha), |
| 3068 | cmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3069 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3070 | return 0; |
| 3071 | } |
| 3072 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3073 | /* Does F/W have an IOCBs for this request */ |
| 3074 | res = qlt_check_reserve_free_req(vha, full_req_cnt); |
| 3075 | if (unlikely(res)) |
| 3076 | goto out_unmap_unlock; |
| 3077 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3078 | if (cmd->se_cmd.prot_op && (xmit_type & QLA_TGT_XMIT_DATA)) |
| 3079 | res = qlt_build_ctio_crc2_pkt(&prm, vha); |
| 3080 | else |
| 3081 | res = qlt_24xx_build_ctio_pkt(&prm, vha); |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3082 | if (unlikely(res != 0)) { |
| 3083 | vha->req->cnt += full_req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3084 | goto out_unmap_unlock; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3085 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3086 | |
| 3087 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
| 3088 | |
| 3089 | if (qlt_has_data(cmd) && (xmit_type & QLA_TGT_XMIT_DATA)) { |
| 3090 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3091 | cpu_to_le16(CTIO7_FLAGS_DATA_IN | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3092 | CTIO7_FLAGS_STATUS_MODE_0); |
| 3093 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3094 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
| 3095 | qlt_load_data_segments(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3096 | |
| 3097 | if (prm.add_status_pkt == 0) { |
| 3098 | if (xmit_type & QLA_TGT_XMIT_STATUS) { |
| 3099 | pkt->u.status0.scsi_status = |
| 3100 | cpu_to_le16(prm.rq_result); |
| 3101 | pkt->u.status0.residual = |
| 3102 | cpu_to_le32(prm.residual); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3103 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3104 | CTIO7_FLAGS_SEND_STATUS); |
| 3105 | if (qlt_need_explicit_conf(ha, cmd, 0)) { |
| 3106 | pkt->u.status0.flags |= |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3107 | cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3108 | CTIO7_FLAGS_EXPLICIT_CONFORM | |
| 3109 | CTIO7_FLAGS_CONFORM_REQ); |
| 3110 | } |
| 3111 | } |
| 3112 | |
| 3113 | } else { |
| 3114 | /* |
| 3115 | * We have already made sure that there is sufficient |
| 3116 | * amount of request entries to not drop HW lock in |
| 3117 | * req_pkt(). |
| 3118 | */ |
| 3119 | struct ctio7_to_24xx *ctio = |
| 3120 | (struct ctio7_to_24xx *)qlt_get_req_pkt(vha); |
| 3121 | |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3122 | ql_dbg(ql_dbg_io, vha, 0x305e, |
| 3123 | "Building additional status packet 0x%p.\n", |
| 3124 | ctio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3125 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3126 | /* |
| 3127 | * T10Dif: ctio_crc2_to_fw overlay ontop of |
| 3128 | * ctio7_to_24xx |
| 3129 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3130 | memcpy(ctio, pkt, sizeof(*ctio)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3131 | /* reset back to CTIO7 */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3132 | ctio->entry_count = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3133 | ctio->entry_type = CTIO_TYPE7; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3134 | ctio->dseg_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3135 | ctio->u.status1.flags &= ~cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3136 | CTIO7_FLAGS_DATA_IN); |
| 3137 | |
| 3138 | /* Real finish is ctio_m1's finish */ |
| 3139 | pkt->handle |= CTIO_INTERMEDIATE_HANDLE_MARK; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3140 | pkt->u.status0.flags |= cpu_to_le16( |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3141 | CTIO7_FLAGS_DONT_RET_CTIO); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3142 | |
| 3143 | /* qlt_24xx_init_ctio_to_isp will correct |
| 3144 | * all neccessary fields that's part of CTIO7. |
| 3145 | * There should be no residual of CTIO-CRC2 data. |
| 3146 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3147 | qlt_24xx_init_ctio_to_isp((struct ctio7_to_24xx *)ctio, |
| 3148 | &prm); |
| 3149 | pr_debug("Status CTIO7: %p\n", ctio); |
| 3150 | } |
| 3151 | } else |
| 3152 | qlt_24xx_init_ctio_to_isp(pkt, &prm); |
| 3153 | |
| 3154 | |
| 3155 | cmd->state = QLA_TGT_STATE_PROCESSED; /* Mid-level is done processing */ |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3156 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3157 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3158 | /* Memory Barrier */ |
| 3159 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3160 | qla2x00_start_iocbs(vha, vha->req); |
| 3161 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3162 | |
| 3163 | return 0; |
| 3164 | |
| 3165 | out_unmap_unlock: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3166 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3167 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3168 | |
| 3169 | return res; |
| 3170 | } |
| 3171 | EXPORT_SYMBOL(qlt_xmit_response); |
| 3172 | |
| 3173 | int qlt_rdy_to_xfer(struct qla_tgt_cmd *cmd) |
| 3174 | { |
| 3175 | struct ctio7_to_24xx *pkt; |
| 3176 | struct scsi_qla_host *vha = cmd->vha; |
| 3177 | struct qla_hw_data *ha = vha->hw; |
| 3178 | struct qla_tgt *tgt = cmd->tgt; |
| 3179 | struct qla_tgt_prm prm; |
| 3180 | unsigned long flags; |
| 3181 | int res = 0; |
| 3182 | |
| 3183 | memset(&prm, 0, sizeof(prm)); |
| 3184 | prm.cmd = cmd; |
| 3185 | prm.tgt = tgt; |
| 3186 | prm.sg = NULL; |
| 3187 | prm.req_cnt = 1; |
| 3188 | |
| 3189 | /* Send marker if required */ |
| 3190 | if (qlt_issue_marker(vha, 0) != QLA_SUCCESS) |
| 3191 | return -EIO; |
| 3192 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3193 | /* Calculate number of entries and segments required */ |
| 3194 | if (qlt_pci_map_calc_cnt(&prm) != 0) |
| 3195 | return -EAGAIN; |
| 3196 | |
| 3197 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3198 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3199 | if (!ha->flags.fw_started || (cmd->reset_count != ha->chip_reset) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3200 | (cmd->sess && cmd->sess->deleted)) { |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3201 | /* |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3202 | * Either the port is not online or this request was from |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3203 | * previous life, just abort the processing. |
| 3204 | */ |
| 3205 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
| 3206 | qlt_abort_cmd_on_host_reset(cmd->vha, cmd); |
| 3207 | ql_dbg(ql_dbg_async, vha, 0xe102, |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3208 | "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", |
| 3209 | vha->flags.online, qla2x00_reset_active(vha), |
| 3210 | cmd->reset_count, ha->chip_reset); |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3211 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3212 | return 0; |
| 3213 | } |
| 3214 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3215 | /* Does F/W have an IOCBs for this request */ |
| 3216 | res = qlt_check_reserve_free_req(vha, prm.req_cnt); |
| 3217 | if (res != 0) |
| 3218 | goto out_unlock_free_unmap; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3219 | if (cmd->se_cmd.prot_op) |
| 3220 | res = qlt_build_ctio_crc2_pkt(&prm, vha); |
| 3221 | else |
| 3222 | res = qlt_24xx_build_ctio_pkt(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3223 | |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3224 | if (unlikely(res != 0)) { |
| 3225 | vha->req->cnt += prm.req_cnt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3226 | goto out_unlock_free_unmap; |
Quinn Tran | 810e30b | 2015-06-10 11:05:20 -0400 | [diff] [blame] | 3227 | } |
| 3228 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3229 | pkt = (struct ctio7_to_24xx *)prm.pkt; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3230 | pkt->u.status0.flags |= cpu_to_le16(CTIO7_FLAGS_DATA_OUT | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3231 | CTIO7_FLAGS_STATUS_MODE_0); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3232 | |
| 3233 | if (cmd->se_cmd.prot_op == TARGET_PROT_NORMAL) |
| 3234 | qlt_load_data_segments(&prm, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3235 | |
| 3236 | cmd->state = QLA_TGT_STATE_NEED_DATA; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3237 | cmd->cmd_sent_to_fw = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3238 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3239 | /* Memory Barrier */ |
| 3240 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3241 | qla2x00_start_iocbs(vha, vha->req); |
| 3242 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3243 | |
| 3244 | return res; |
| 3245 | |
| 3246 | out_unlock_free_unmap: |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3247 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3248 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3249 | |
| 3250 | return res; |
| 3251 | } |
| 3252 | EXPORT_SYMBOL(qlt_rdy_to_xfer); |
| 3253 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3254 | |
| 3255 | /* |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3256 | * it is assumed either hardware_lock or qpair lock is held. |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3257 | */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3258 | static void |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3259 | qlt_handle_dif_error(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3260 | struct ctio_crc_from_fw *sts) |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3261 | { |
| 3262 | uint8_t *ap = &sts->actual_dif[0]; |
| 3263 | uint8_t *ep = &sts->expected_dif[0]; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3264 | uint64_t lba = cmd->se_cmd.t_task_lba; |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3265 | uint8_t scsi_status, sense_key, asc, ascq; |
| 3266 | unsigned long flags; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3267 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3268 | cmd->trc_flags |= TRC_DIF_ERR; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3269 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3270 | cmd->a_guard = be16_to_cpu(*(uint16_t *)(ap + 0)); |
| 3271 | cmd->a_app_tag = be16_to_cpu(*(uint16_t *)(ap + 2)); |
| 3272 | cmd->a_ref_tag = be32_to_cpu(*(uint32_t *)(ap + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3273 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3274 | cmd->e_guard = be16_to_cpu(*(uint16_t *)(ep + 0)); |
| 3275 | cmd->e_app_tag = be16_to_cpu(*(uint16_t *)(ep + 2)); |
| 3276 | cmd->e_ref_tag = be32_to_cpu(*(uint32_t *)(ep + 4)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3277 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3278 | ql_dbg(ql_dbg_tgt_dif, vha, 0xf075, |
| 3279 | "%s: aborted %d state %d\n", __func__, cmd->aborted, cmd->state); |
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 | scsi_status = sense_key = asc = ascq = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3282 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3283 | /* check appl tag */ |
| 3284 | if (cmd->e_app_tag != cmd->a_app_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3285 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00d, |
| 3286 | "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]", |
| 3287 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3288 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3289 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3290 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
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->dif_err_code = DIF_ERR_APP; |
| 3293 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3294 | sense_key = ABORTED_COMMAND; |
| 3295 | asc = 0x10; |
| 3296 | ascq = 0x2; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | /* check ref tag */ |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3300 | if (cmd->e_ref_tag != cmd->a_ref_tag) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3301 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe00e, |
| 3302 | "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] ", |
| 3303 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3304 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3305 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3306 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3307 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3308 | cmd->dif_err_code = DIF_ERR_REF; |
| 3309 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3310 | sense_key = ABORTED_COMMAND; |
| 3311 | asc = 0x10; |
| 3312 | ascq = 0x3; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3313 | goto out; |
| 3314 | } |
| 3315 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3316 | /* check guard */ |
| 3317 | if (cmd->e_guard != cmd->a_guard) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3318 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe012, |
| 3319 | "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]", |
| 3320 | cmd->cdb[0], lba, (lba+cmd->num_blks), cmd->num_blks, |
| 3321 | cmd->a_ref_tag, cmd->e_ref_tag, cmd->a_app_tag, |
| 3322 | cmd->e_app_tag, cmd->a_guard, cmd->e_guard, cmd, |
| 3323 | cmd->atio.u.isp24.fcp_hdr.ox_id); |
| 3324 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3325 | cmd->dif_err_code = DIF_ERR_GRD; |
| 3326 | scsi_status = SAM_STAT_CHECK_CONDITION; |
| 3327 | sense_key = ABORTED_COMMAND; |
| 3328 | asc = 0x10; |
| 3329 | ascq = 0x1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3330 | } |
| 3331 | out: |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3332 | switch (cmd->state) { |
| 3333 | case QLA_TGT_STATE_NEED_DATA: |
| 3334 | /* handle_data will load DIF error code */ |
| 3335 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3336 | vha->hw->tgt.tgt_ops->handle_data(cmd); |
| 3337 | break; |
| 3338 | default: |
| 3339 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3340 | if (cmd->aborted) { |
| 3341 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3342 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3343 | break; |
| 3344 | } |
| 3345 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3346 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3347 | qlt_send_resp_ctio(vha, cmd, scsi_status, sense_key, asc, ascq); |
| 3348 | /* assume scsi status gets out on the wire. |
| 3349 | * Will not wait for completion. |
| 3350 | */ |
| 3351 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3352 | break; |
| 3353 | } |
| 3354 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3355 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3356 | /* If hardware_lock held on entry, might drop it, then reaquire */ |
| 3357 | /* This function sends the appropriate CTIO to ISP 2xxx or 24xx */ |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3358 | static int __qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3359 | struct imm_ntfy_from_isp *ntfy) |
| 3360 | { |
| 3361 | struct nack_to_isp *nack; |
| 3362 | struct qla_hw_data *ha = vha->hw; |
| 3363 | request_t *pkt; |
| 3364 | int ret = 0; |
| 3365 | |
| 3366 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xe01c, |
| 3367 | "Sending TERM ELS CTIO (ha=%p)\n", ha); |
| 3368 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3369 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3370 | if (pkt == NULL) { |
| 3371 | ql_dbg(ql_dbg_tgt, vha, 0xe080, |
| 3372 | "qla_target(%d): %s failed: unable to allocate " |
| 3373 | "request packet\n", vha->vp_idx, __func__); |
| 3374 | return -ENOMEM; |
| 3375 | } |
| 3376 | |
| 3377 | pkt->entry_type = NOTIFY_ACK_TYPE; |
| 3378 | pkt->entry_count = 1; |
Quinn Tran | 4f06073 | 2016-12-23 18:06:13 -0800 | [diff] [blame] | 3379 | pkt->handle = QLA_TGT_SKIP_HANDLE; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3380 | |
| 3381 | nack = (struct nack_to_isp *)pkt; |
| 3382 | nack->ox_id = ntfy->ox_id; |
| 3383 | |
| 3384 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3385 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3386 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3387 | __constant_cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3388 | } |
| 3389 | |
| 3390 | /* terminate */ |
| 3391 | nack->u.isp24.flags |= |
| 3392 | __constant_cpu_to_le16(NOTIFY_ACK_FLAGS_TERMINATE); |
| 3393 | |
| 3394 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3395 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3396 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3397 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3398 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3399 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3400 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3401 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3402 | |
| 3403 | qla2x00_start_iocbs(vha, vha->req); |
| 3404 | return ret; |
| 3405 | } |
| 3406 | |
| 3407 | static void qlt_send_term_imm_notif(struct scsi_qla_host *vha, |
| 3408 | struct imm_ntfy_from_isp *imm, int ha_locked) |
| 3409 | { |
| 3410 | unsigned long flags = 0; |
| 3411 | int rc; |
| 3412 | |
| 3413 | if (qlt_issue_marker(vha, ha_locked) < 0) |
| 3414 | return; |
| 3415 | |
| 3416 | if (ha_locked) { |
| 3417 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3418 | |
| 3419 | #if 0 /* Todo */ |
| 3420 | if (rc == -ENOMEM) |
| 3421 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
Bart Van Assche | 91f42b3 | 2016-03-30 15:25:21 -0700 | [diff] [blame] | 3422 | #else |
| 3423 | if (rc) { |
| 3424 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 3425 | #endif |
| 3426 | goto done; |
| 3427 | } |
| 3428 | |
| 3429 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3430 | rc = __qlt_send_term_imm_notif(vha, imm); |
| 3431 | |
| 3432 | #if 0 /* Todo */ |
| 3433 | if (rc == -ENOMEM) |
| 3434 | qlt_alloc_qfull_cmd(vha, imm, 0, 0); |
| 3435 | #endif |
| 3436 | |
| 3437 | done: |
| 3438 | if (!ha_locked) |
| 3439 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3440 | } |
| 3441 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3442 | /* |
| 3443 | * If hardware_lock held on entry, might drop it, then reaquire |
| 3444 | * This function sends the appropriate CTIO to ISP 2xxx or 24xx |
| 3445 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3446 | static int __qlt_send_term_exchange(struct scsi_qla_host *vha, |
| 3447 | struct qla_tgt_cmd *cmd, |
| 3448 | struct atio_from_isp *atio) |
| 3449 | { |
| 3450 | struct ctio7_to_24xx *ctio24; |
| 3451 | struct qla_hw_data *ha = vha->hw; |
| 3452 | request_t *pkt; |
| 3453 | int ret = 0; |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3454 | uint16_t temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3455 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3456 | 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] | 3457 | |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 3458 | pkt = (request_t *)qla2x00_alloc_iocbs_ready(vha, NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3459 | if (pkt == NULL) { |
| 3460 | ql_dbg(ql_dbg_tgt, vha, 0xe050, |
| 3461 | "qla_target(%d): %s failed: unable to allocate " |
| 3462 | "request packet\n", vha->vp_idx, __func__); |
| 3463 | return -ENOMEM; |
| 3464 | } |
| 3465 | |
| 3466 | if (cmd != NULL) { |
| 3467 | if (cmd->state < QLA_TGT_STATE_PROCESSED) { |
| 3468 | ql_dbg(ql_dbg_tgt, vha, 0xe051, |
| 3469 | "qla_target(%d): Terminating cmd %p with " |
| 3470 | "incorrect state %d\n", vha->vp_idx, cmd, |
| 3471 | cmd->state); |
| 3472 | } else |
| 3473 | ret = 1; |
| 3474 | } |
| 3475 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 3476 | vha->tgt_counters.num_term_xchg_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3477 | pkt->entry_count = 1; |
| 3478 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 3479 | |
| 3480 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 3481 | ctio24->entry_type = CTIO_TYPE7; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3482 | ctio24->nport_handle = CTIO7_NHANDLE_UNRECOGNIZED; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3483 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3484 | ctio24->vp_index = vha->vp_idx; |
| 3485 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 3486 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 3487 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 3488 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3489 | temp = (atio->u.isp24.attr << 9) | CTIO7_FLAGS_STATUS_MODE_1 | |
| 3490 | CTIO7_FLAGS_TERMINATE; |
| 3491 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Quinn Tran | 33a5fce | 2014-06-24 00:22:29 -0400 | [diff] [blame] | 3492 | temp = be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id); |
| 3493 | ctio24->u.status1.ox_id = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3494 | |
| 3495 | /* Most likely, it isn't needed */ |
| 3496 | ctio24->u.status1.residual = get_unaligned((uint32_t *) |
| 3497 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 3498 | atio->u.isp24.fcp_cmnd.add_cdb_len]); |
| 3499 | if (ctio24->u.status1.residual != 0) |
| 3500 | ctio24->u.status1.scsi_status |= SS_RESIDUAL_UNDER; |
| 3501 | |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 3502 | /* Memory Barrier */ |
| 3503 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3504 | qla2x00_start_iocbs(vha, vha->req); |
| 3505 | return ret; |
| 3506 | } |
| 3507 | |
| 3508 | static void qlt_send_term_exchange(struct scsi_qla_host *vha, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3509 | struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, |
| 3510 | int ul_abort) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3511 | { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3512 | unsigned long flags = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3513 | int rc; |
| 3514 | |
| 3515 | if (qlt_issue_marker(vha, ha_locked) < 0) |
| 3516 | return; |
| 3517 | |
| 3518 | if (ha_locked) { |
| 3519 | rc = __qlt_send_term_exchange(vha, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3520 | if (rc == -ENOMEM) |
| 3521 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3522 | goto done; |
| 3523 | } |
| 3524 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 3525 | rc = __qlt_send_term_exchange(vha, cmd, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3526 | if (rc == -ENOMEM) |
| 3527 | qlt_alloc_qfull_cmd(vha, atio, 0, 0); |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3528 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3529 | done: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3530 | if (cmd && !ul_abort && !cmd->aborted) { |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3531 | if (cmd->sg_mapped) |
| 3532 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3533 | vha->hw->tgt.tgt_ops->free_cmd(cmd); |
| 3534 | } |
Himanshu Madhani | 6bc85dd | 2015-06-10 11:05:22 -0400 | [diff] [blame] | 3535 | |
| 3536 | if (!ha_locked) |
| 3537 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 3538 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3539 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3540 | } |
| 3541 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3542 | static void qlt_init_term_exchange(struct scsi_qla_host *vha) |
| 3543 | { |
| 3544 | struct list_head free_list; |
| 3545 | struct qla_tgt_cmd *cmd, *tcmd; |
| 3546 | |
| 3547 | vha->hw->tgt.leak_exchg_thresh_hold = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3548 | (vha->hw->cur_fw_xcb_count/100) * LEAK_EXCHG_THRESH_HOLD_PERCENT; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3549 | |
| 3550 | cmd = tcmd = NULL; |
| 3551 | if (!list_empty(&vha->hw->tgt.q_full_list)) { |
| 3552 | INIT_LIST_HEAD(&free_list); |
| 3553 | list_splice_init(&vha->hw->tgt.q_full_list, &free_list); |
| 3554 | |
| 3555 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 3556 | list_del(&cmd->cmd_list); |
| 3557 | /* This cmd was never sent to TCM. There is no need |
| 3558 | * to schedule free or call free_cmd |
| 3559 | */ |
| 3560 | qlt_free_cmd(cmd); |
| 3561 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 3562 | } |
| 3563 | } |
| 3564 | vha->hw->tgt.num_qfull_cmds_dropped = 0; |
| 3565 | } |
| 3566 | |
| 3567 | static void qlt_chk_exch_leak_thresh_hold(struct scsi_qla_host *vha) |
| 3568 | { |
| 3569 | uint32_t total_leaked; |
| 3570 | |
| 3571 | total_leaked = vha->hw->tgt.num_qfull_cmds_dropped; |
| 3572 | |
| 3573 | if (vha->hw->tgt.leak_exchg_thresh_hold && |
| 3574 | (total_leaked > vha->hw->tgt.leak_exchg_thresh_hold)) { |
| 3575 | |
| 3576 | ql_dbg(ql_dbg_tgt, vha, 0xe079, |
| 3577 | "Chip reset due to exchange starvation: %d/%d.\n", |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3578 | total_leaked, vha->hw->cur_fw_xcb_count); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3579 | |
| 3580 | if (IS_P3P_TYPE(vha->hw)) |
| 3581 | set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags); |
| 3582 | else |
| 3583 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3584 | qla2xxx_wake_dpc(vha); |
| 3585 | } |
| 3586 | |
| 3587 | } |
| 3588 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3589 | int qlt_abort_cmd(struct qla_tgt_cmd *cmd) |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3590 | { |
| 3591 | struct qla_tgt *tgt = cmd->tgt; |
| 3592 | struct scsi_qla_host *vha = tgt->vha; |
| 3593 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3594 | unsigned long flags; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3595 | |
| 3596 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, |
| 3597 | "qla_target(%d): terminating exchange for aborted cmd=%p " |
| 3598 | "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, |
| 3599 | se_cmd->tag); |
| 3600 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3601 | spin_lock_irqsave(&cmd->cmd_lock, flags); |
| 3602 | if (cmd->aborted) { |
| 3603 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
| 3604 | /* |
| 3605 | * It's normal to see 2 calls in this path: |
| 3606 | * 1) XFER Rdy completion + CMD_T_ABORT |
| 3607 | * 2) TCM TMR - drain_state_list |
| 3608 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3609 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, |
| 3610 | "multiple abort. %p transport_state %x, t_state %x, " |
| 3611 | "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, |
| 3612 | cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3613 | return EIO; |
| 3614 | } |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3615 | cmd->aborted = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3616 | cmd->trc_flags |= TRC_ABORT; |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3617 | spin_unlock_irqrestore(&cmd->cmd_lock, flags); |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3618 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3619 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 0, 1); |
| 3620 | return 0; |
Alexei Potashnik | 7359df2 | 2015-07-14 16:00:49 -0400 | [diff] [blame] | 3621 | } |
| 3622 | EXPORT_SYMBOL(qlt_abort_cmd); |
| 3623 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3624 | void qlt_free_cmd(struct qla_tgt_cmd *cmd) |
| 3625 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3626 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3627 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3628 | ql_dbg(ql_dbg_tgt, cmd->vha, 0xe074, |
| 3629 | "%s: se_cmd[%p] ox_id %04x\n", |
| 3630 | __func__, &cmd->se_cmd, |
| 3631 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3632 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3633 | BUG_ON(cmd->cmd_in_wq); |
| 3634 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3635 | if (cmd->sg_mapped) |
| 3636 | qlt_unmap_sg(cmd->vha, cmd); |
| 3637 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 3638 | if (!cmd->q_full) |
| 3639 | qlt_decr_num_pend_cmds(cmd->vha); |
| 3640 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3641 | BUG_ON(cmd->sg_mapped); |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3642 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3643 | if (unlikely(cmd->free_sg)) |
| 3644 | kfree(cmd->sg); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3645 | |
| 3646 | if (!sess || !sess->se_sess) { |
| 3647 | WARN_ON(1); |
| 3648 | return; |
| 3649 | } |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 3650 | cmd->jiffies_at_free = get_jiffies_64(); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3651 | 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] | 3652 | } |
| 3653 | EXPORT_SYMBOL(qlt_free_cmd); |
| 3654 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3655 | /* |
| 3656 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3657 | */ |
| 3658 | static int qlt_term_ctio_exchange(struct scsi_qla_host *vha, void *ctio, |
| 3659 | struct qla_tgt_cmd *cmd, uint32_t status) |
| 3660 | { |
| 3661 | int term = 0; |
| 3662 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3663 | if (cmd->se_cmd.prot_op) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3664 | ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3665 | "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " |
| 3666 | "se_cmd=%p tag[%x] op %#x/%s", |
| 3667 | cmd->lba, cmd->lba, |
| 3668 | cmd->num_blks, &cmd->se_cmd, |
| 3669 | cmd->atio.u.isp24.exchange_addr, |
| 3670 | cmd->se_cmd.prot_op, |
| 3671 | prot_op_str(cmd->se_cmd.prot_op)); |
| 3672 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3673 | if (ctio != NULL) { |
| 3674 | struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; |
| 3675 | term = !(c->flags & |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3676 | cpu_to_le16(OF_TERM_EXCH)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3677 | } else |
| 3678 | term = 1; |
| 3679 | |
| 3680 | if (term) |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 3681 | qlt_send_term_exchange(vha, cmd, &cmd->atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3682 | |
| 3683 | return term; |
| 3684 | } |
| 3685 | |
| 3686 | /* ha->hardware_lock supposed to be held on entry */ |
| 3687 | static inline struct qla_tgt_cmd *qlt_get_cmd(struct scsi_qla_host *vha, |
| 3688 | uint32_t handle) |
| 3689 | { |
| 3690 | struct qla_hw_data *ha = vha->hw; |
| 3691 | |
| 3692 | handle--; |
| 3693 | if (ha->tgt.cmds[handle] != NULL) { |
| 3694 | struct qla_tgt_cmd *cmd = ha->tgt.cmds[handle]; |
| 3695 | ha->tgt.cmds[handle] = NULL; |
| 3696 | return cmd; |
| 3697 | } else |
| 3698 | return NULL; |
| 3699 | } |
| 3700 | |
| 3701 | /* ha->hardware_lock supposed to be held on entry */ |
| 3702 | static struct qla_tgt_cmd *qlt_ctio_to_cmd(struct scsi_qla_host *vha, |
| 3703 | uint32_t handle, void *ctio) |
| 3704 | { |
| 3705 | struct qla_tgt_cmd *cmd = NULL; |
| 3706 | |
| 3707 | /* Clear out internal marks */ |
| 3708 | handle &= ~(CTIO_COMPLETION_HANDLE_MARK | |
| 3709 | CTIO_INTERMEDIATE_HANDLE_MARK); |
| 3710 | |
| 3711 | if (handle != QLA_TGT_NULL_HANDLE) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3712 | if (unlikely(handle == QLA_TGT_SKIP_HANDLE)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3713 | return NULL; |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 3714 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3715 | /* handle-1 is actually used */ |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3716 | if (unlikely(handle > DEFAULT_OUTSTANDING_COMMANDS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3717 | ql_dbg(ql_dbg_tgt, vha, 0xe052, |
| 3718 | "qla_target(%d): Wrong handle %x received\n", |
| 3719 | vha->vp_idx, handle); |
| 3720 | return NULL; |
| 3721 | } |
| 3722 | cmd = qlt_get_cmd(vha, handle); |
| 3723 | if (unlikely(cmd == NULL)) { |
| 3724 | ql_dbg(ql_dbg_tgt, vha, 0xe053, |
| 3725 | "qla_target(%d): Suspicious: unable to " |
| 3726 | "find the command with handle %x\n", vha->vp_idx, |
| 3727 | handle); |
| 3728 | return NULL; |
| 3729 | } |
| 3730 | } else if (ctio != NULL) { |
| 3731 | /* We can't get loop ID from CTIO7 */ |
| 3732 | ql_dbg(ql_dbg_tgt, vha, 0xe054, |
| 3733 | "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " |
| 3734 | "support NULL handles\n", vha->vp_idx); |
| 3735 | return NULL; |
| 3736 | } |
| 3737 | |
| 3738 | return cmd; |
| 3739 | } |
| 3740 | |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3741 | /* hardware_lock should be held by caller. */ |
| 3742 | static void |
| 3743 | qlt_abort_cmd_on_host_reset(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) |
| 3744 | { |
| 3745 | struct qla_hw_data *ha = vha->hw; |
| 3746 | uint32_t handle; |
| 3747 | |
| 3748 | if (cmd->sg_mapped) |
| 3749 | qlt_unmap_sg(vha, cmd); |
| 3750 | |
| 3751 | handle = qlt_make_handle(vha); |
| 3752 | |
| 3753 | /* TODO: fix debug message type and ids. */ |
| 3754 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
| 3755 | ql_dbg(ql_dbg_io, vha, 0xff00, |
| 3756 | "HOST-ABORT: handle=%d, state=PROCESSED.\n", handle); |
| 3757 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
| 3758 | cmd->write_data_transferred = 0; |
| 3759 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3760 | |
| 3761 | ql_dbg(ql_dbg_io, vha, 0xff01, |
| 3762 | "HOST-ABORT: handle=%d, state=DATA_IN.\n", handle); |
| 3763 | |
| 3764 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3765 | return; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3766 | } else { |
| 3767 | ql_dbg(ql_dbg_io, vha, 0xff03, |
| 3768 | "HOST-ABORT: handle=%d, state=BAD(%d).\n", handle, |
| 3769 | cmd->state); |
| 3770 | dump_stack(); |
| 3771 | } |
| 3772 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3773 | cmd->trc_flags |= TRC_FLUSH; |
Arun Easi | c0cb449 | 2014-09-25 06:14:51 -0400 | [diff] [blame] | 3774 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3775 | } |
| 3776 | |
| 3777 | void |
| 3778 | qlt_host_reset_handler(struct qla_hw_data *ha) |
| 3779 | { |
| 3780 | struct qla_tgt_cmd *cmd; |
| 3781 | unsigned long flags; |
| 3782 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
| 3783 | scsi_qla_host_t *vha = NULL; |
| 3784 | struct qla_tgt *tgt = base_vha->vha_tgt.qla_tgt; |
| 3785 | uint32_t i; |
| 3786 | |
| 3787 | if (!base_vha->hw->tgt.tgt_ops) |
| 3788 | return; |
| 3789 | |
| 3790 | if (!tgt || qla_ini_mode_enabled(base_vha)) { |
| 3791 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003, |
| 3792 | "Target mode disabled\n"); |
| 3793 | return; |
| 3794 | } |
| 3795 | |
| 3796 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xff10, |
| 3797 | "HOST-ABORT-HNDLR: base_vha->dpc_flags=%lx.\n", |
| 3798 | base_vha->dpc_flags); |
| 3799 | |
| 3800 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3801 | for (i = 1; i < DEFAULT_OUTSTANDING_COMMANDS + 1; i++) { |
| 3802 | cmd = qlt_get_cmd(base_vha, i); |
| 3803 | if (!cmd) |
| 3804 | continue; |
| 3805 | /* ha->tgt.cmds entry is cleared by qlt_get_cmd. */ |
| 3806 | vha = cmd->vha; |
| 3807 | qlt_abort_cmd_on_host_reset(vha, cmd); |
| 3808 | } |
| 3809 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3810 | } |
| 3811 | |
| 3812 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3813 | /* |
| 3814 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 3815 | */ |
| 3816 | static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle, |
| 3817 | uint32_t status, void *ctio) |
| 3818 | { |
| 3819 | struct qla_hw_data *ha = vha->hw; |
| 3820 | struct se_cmd *se_cmd; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3821 | struct qla_tgt_cmd *cmd; |
| 3822 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3823 | if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { |
| 3824 | /* That could happen only in case of an error/reset/abort */ |
| 3825 | if (status != CTIO_SUCCESS) { |
| 3826 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01d, |
| 3827 | "Intermediate CTIO received" |
| 3828 | " (status %x)\n", status); |
| 3829 | } |
| 3830 | return; |
| 3831 | } |
| 3832 | |
| 3833 | cmd = qlt_ctio_to_cmd(vha, handle, ctio); |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3834 | if (cmd == NULL) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3835 | return; |
Roland Dreier | 092e1dc | 2012-06-11 18:23:15 -0700 | [diff] [blame] | 3836 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3837 | se_cmd = &cmd->se_cmd; |
Quinn Tran | d564a37 | 2014-09-25 06:14:57 -0400 | [diff] [blame] | 3838 | cmd->cmd_sent_to_fw = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3839 | |
Joern Engel | f9b6721 | 2014-09-16 16:23:18 -0400 | [diff] [blame] | 3840 | qlt_unmap_sg(vha, cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3841 | |
| 3842 | if (unlikely(status != CTIO_SUCCESS)) { |
| 3843 | switch (status & 0xFFFF) { |
| 3844 | case CTIO_LIP_RESET: |
| 3845 | case CTIO_TARGET_RESET: |
| 3846 | case CTIO_ABORTED: |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3847 | /* driver request abort via Terminate exchange */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3848 | case CTIO_TIMEOUT: |
| 3849 | case CTIO_INVALID_RX_ID: |
| 3850 | /* They are OK */ |
| 3851 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, |
| 3852 | "qla_target(%d): CTIO with " |
| 3853 | "status %#x received, state %x, se_cmd %p, " |
| 3854 | "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " |
| 3855 | "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, |
| 3856 | status, cmd->state, se_cmd); |
| 3857 | break; |
| 3858 | |
| 3859 | case CTIO_PORT_LOGGED_OUT: |
| 3860 | case CTIO_PORT_UNAVAILABLE: |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3861 | { |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3862 | int logged_out = |
| 3863 | (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; |
| 3864 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3865 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3866 | "qla_target(%d): CTIO with %s status %x " |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3867 | "received (state %x, se_cmd %p)\n", vha->vp_idx, |
Himanshu Madhani | dacb582 | 2016-01-20 15:42:58 -0800 | [diff] [blame] | 3868 | logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3869 | status, cmd->state, se_cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3870 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3871 | if (logged_out && cmd->sess) { |
| 3872 | /* |
| 3873 | * Session is already logged out, but we need |
| 3874 | * to notify initiator, who's not aware of this |
| 3875 | */ |
| 3876 | cmd->sess->logout_on_delete = 0; |
| 3877 | cmd->sess->send_els_logo = 1; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3878 | ql_dbg(ql_dbg_disc, vha, 0x20f8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3879 | "%s %d %8phC post del sess\n", |
| 3880 | __func__, __LINE__, cmd->sess->port_name); |
| 3881 | |
| 3882 | qlt_schedule_sess_for_deletion_lock(cmd->sess); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 3883 | } |
| 3884 | break; |
| 3885 | } |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3886 | case CTIO_DIF_ERROR: { |
| 3887 | struct ctio_crc_from_fw *crc = |
| 3888 | (struct ctio_crc_from_fw *)ctio; |
| 3889 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3890 | "qla_target(%d): CTIO with DIF_ERROR status %x " |
| 3891 | "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " |
| 3892 | "expect_dif[0x%llx]\n", |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3893 | vha->vp_idx, status, cmd->state, se_cmd, |
| 3894 | *((u64 *)&crc->actual_dif[0]), |
| 3895 | *((u64 *)&crc->expected_dif[0])); |
| 3896 | |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 3897 | qlt_handle_dif_error(vha, cmd, ctio); |
| 3898 | return; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3899 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3900 | default: |
| 3901 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 3902 | "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] | 3903 | vha->vp_idx, status, cmd->state, se_cmd); |
| 3904 | break; |
| 3905 | } |
| 3906 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3907 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3908 | /* "cmd->aborted" means |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3909 | * cmd is already aborted/terminated, we don't |
| 3910 | * need to terminate again. The exchange is already |
| 3911 | * cleaned up/freed at FW level. Just cleanup at driver |
| 3912 | * level. |
| 3913 | */ |
| 3914 | if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3915 | (!cmd->aborted)) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3916 | cmd->trc_flags |= TRC_CTIO_ERR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3917 | if (qlt_term_ctio_exchange(vha, ctio, cmd, status)) |
| 3918 | return; |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3919 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | if (cmd->state == QLA_TGT_STATE_PROCESSED) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3923 | cmd->trc_flags |= TRC_CTIO_DONE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3924 | } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3925 | cmd->state = QLA_TGT_STATE_DATA_IN; |
| 3926 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 3927 | if (status == CTIO_SUCCESS) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3928 | cmd->write_data_transferred = 1; |
| 3929 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3930 | ha->tgt.tgt_ops->handle_data(cmd); |
| 3931 | return; |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3932 | } else if (cmd->aborted) { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3933 | cmd->trc_flags |= TRC_CTIO_ABORTED; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3934 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 3935 | "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3936 | } else { |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 3937 | cmd->trc_flags |= TRC_CTIO_STRANGE; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3938 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, |
| 3939 | "qla_target(%d): A command in state (%d) should " |
| 3940 | "not return a CTIO complete\n", vha->vp_idx, cmd->state); |
| 3941 | } |
| 3942 | |
Quinn Tran | 7b89854 | 2014-04-11 16:54:44 -0400 | [diff] [blame] | 3943 | if (unlikely(status != CTIO_SUCCESS) && |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 3944 | !cmd->aborted) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3945 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01f, "Finishing failed CTIO\n"); |
| 3946 | dump_stack(); |
| 3947 | } |
| 3948 | |
| 3949 | ha->tgt.tgt_ops->free_cmd(cmd); |
| 3950 | } |
| 3951 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3952 | static inline int qlt_get_fcp_task_attr(struct scsi_qla_host *vha, |
| 3953 | uint8_t task_codes) |
| 3954 | { |
| 3955 | int fcp_task_attr; |
| 3956 | |
| 3957 | switch (task_codes) { |
| 3958 | case ATIO_SIMPLE_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3959 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3960 | break; |
| 3961 | case ATIO_HEAD_OF_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3962 | fcp_task_attr = TCM_HEAD_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3963 | break; |
| 3964 | case ATIO_ORDERED_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3965 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3966 | break; |
| 3967 | case ATIO_ACA_QUEUE: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3968 | fcp_task_attr = TCM_ACA_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3969 | break; |
| 3970 | case ATIO_UNTAGGED: |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3971 | fcp_task_attr = TCM_SIMPLE_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3972 | break; |
| 3973 | default: |
| 3974 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05d, |
| 3975 | "qla_target: unknown task code %x, use ORDERED instead\n", |
| 3976 | task_codes); |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 3977 | fcp_task_attr = TCM_ORDERED_TAG; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3978 | break; |
| 3979 | } |
| 3980 | |
| 3981 | return fcp_task_attr; |
| 3982 | } |
| 3983 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3984 | static struct fc_port *qlt_make_local_sess(struct scsi_qla_host *, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3985 | uint8_t *); |
| 3986 | /* |
| 3987 | * Process context for I/O path into tcm_qla2xxx code |
| 3988 | */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 3989 | static void __qlt_do_work(struct qla_tgt_cmd *cmd) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3990 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3991 | scsi_qla_host_t *vha = cmd->vha; |
| 3992 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 3993 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 3994 | struct fc_port *sess = cmd->sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3995 | struct atio_from_isp *atio = &cmd->atio; |
| 3996 | unsigned char *cdb; |
| 3997 | unsigned long flags; |
| 3998 | uint32_t data_length; |
| 3999 | int ret, fcp_task_attr, data_dir, bidi = 0; |
| 4000 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4001 | cmd->cmd_in_wq = 0; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4002 | cmd->trc_flags |= TRC_DO_WORK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4003 | if (tgt->tgt_stop) |
| 4004 | goto out_term; |
| 4005 | |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4006 | if (cmd->aborted) { |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4007 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf082, |
| 4008 | "cmd with tag %u is aborted\n", |
| 4009 | cmd->atio.u.isp24.exchange_addr); |
| 4010 | goto out_term; |
| 4011 | } |
| 4012 | |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4013 | spin_lock_init(&cmd->cmd_lock); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4014 | cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; |
Bart Van Assche | 649ee05 | 2015-04-14 13:26:44 +0200 | [diff] [blame] | 4015 | cmd->se_cmd.tag = atio->u.isp24.exchange_addr; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4016 | cmd->unpacked_lun = scsilun_to_int( |
| 4017 | (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); |
| 4018 | |
| 4019 | if (atio->u.isp24.fcp_cmnd.rddata && |
| 4020 | atio->u.isp24.fcp_cmnd.wrdata) { |
| 4021 | bidi = 1; |
| 4022 | data_dir = DMA_TO_DEVICE; |
| 4023 | } else if (atio->u.isp24.fcp_cmnd.rddata) |
| 4024 | data_dir = DMA_FROM_DEVICE; |
| 4025 | else if (atio->u.isp24.fcp_cmnd.wrdata) |
| 4026 | data_dir = DMA_TO_DEVICE; |
| 4027 | else |
| 4028 | data_dir = DMA_NONE; |
| 4029 | |
| 4030 | fcp_task_attr = qlt_get_fcp_task_attr(vha, |
| 4031 | atio->u.isp24.fcp_cmnd.task_attr); |
| 4032 | data_length = be32_to_cpu(get_unaligned((uint32_t *) |
| 4033 | &atio->u.isp24.fcp_cmnd.add_cdb[ |
| 4034 | atio->u.isp24.fcp_cmnd.add_cdb_len])); |
| 4035 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4036 | ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, |
| 4037 | fcp_task_attr, data_dir, bidi); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4038 | if (ret != 0) |
| 4039 | goto out_term; |
| 4040 | /* |
| 4041 | * Drop extra session reference from qla_tgt_handle_cmd_for_atio*( |
| 4042 | */ |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4043 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4044 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4045 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4046 | return; |
| 4047 | |
| 4048 | out_term: |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4049 | ql_dbg(ql_dbg_io, vha, 0x3060, "Terminating work cmd %p", cmd); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4050 | /* |
Roland Dreier | fae9eaf | 2012-06-11 18:23:16 -0700 | [diff] [blame] | 4051 | * cmd has not sent to target yet, so pass NULL as the second |
| 4052 | * argument to qlt_send_term_exchange() and free the memory here. |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4053 | */ |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4054 | cmd->trc_flags |= TRC_DO_WORK_ERR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4055 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4056 | qlt_send_term_exchange(vha, NULL, &cmd->atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4057 | |
| 4058 | qlt_decr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4059 | percpu_ida_free(&sess->se_sess->sess_tag_pool, cmd->se_cmd.map_tag); |
Jörn Engel | 08234e3 | 2013-06-12 16:27:54 -0400 | [diff] [blame] | 4060 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4061 | |
| 4062 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4063 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4064 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4065 | } |
| 4066 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4067 | static void qlt_do_work(struct work_struct *work) |
| 4068 | { |
| 4069 | 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] | 4070 | scsi_qla_host_t *vha = cmd->vha; |
| 4071 | unsigned long flags; |
| 4072 | |
| 4073 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4074 | list_del(&cmd->cmd_list); |
| 4075 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4076 | |
| 4077 | __qlt_do_work(cmd); |
| 4078 | } |
| 4079 | |
| 4080 | 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] | 4081 | struct fc_port *sess, |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4082 | struct atio_from_isp *atio) |
| 4083 | { |
| 4084 | struct se_session *se_sess = sess->se_sess; |
| 4085 | struct qla_tgt_cmd *cmd; |
| 4086 | int tag; |
| 4087 | |
| 4088 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 4089 | if (tag < 0) |
| 4090 | return NULL; |
| 4091 | |
| 4092 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 4093 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 4094 | |
| 4095 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 4096 | cmd->state = QLA_TGT_STATE_NEW; |
| 4097 | cmd->tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4098 | qlt_incr_num_pend_cmds(vha); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4099 | cmd->vha = vha; |
| 4100 | cmd->se_cmd.map_tag = tag; |
| 4101 | cmd->sess = sess; |
| 4102 | cmd->loop_id = sess->loop_id; |
| 4103 | cmd->conf_compl_supported = sess->conf_compl_supported; |
| 4104 | |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4105 | cmd->trc_flags = 0; |
Kanoj Sarcar | 9fce125 | 2015-06-10 11:05:23 -0400 | [diff] [blame] | 4106 | cmd->jiffies_at_alloc = get_jiffies_64(); |
| 4107 | |
| 4108 | cmd->reset_count = vha->hw->chip_reset; |
| 4109 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4110 | return cmd; |
| 4111 | } |
| 4112 | |
| 4113 | static void qlt_send_busy(struct scsi_qla_host *, struct atio_from_isp *, |
| 4114 | uint16_t); |
| 4115 | |
| 4116 | static void qlt_create_sess_from_atio(struct work_struct *work) |
| 4117 | { |
| 4118 | struct qla_tgt_sess_op *op = container_of(work, |
| 4119 | struct qla_tgt_sess_op, work); |
| 4120 | scsi_qla_host_t *vha = op->vha; |
| 4121 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4122 | struct fc_port *sess; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4123 | struct qla_tgt_cmd *cmd; |
| 4124 | unsigned long flags; |
| 4125 | uint8_t *s_id = op->atio.u.isp24.fcp_hdr.s_id; |
| 4126 | |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4127 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
| 4128 | list_del(&op->cmd_list); |
| 4129 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
| 4130 | |
| 4131 | if (op->aborted) { |
| 4132 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf083, |
| 4133 | "sess_op with tag %u is aborted\n", |
| 4134 | op->atio.u.isp24.exchange_addr); |
| 4135 | goto out_term; |
| 4136 | } |
| 4137 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4138 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf022, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4139 | "qla_target(%d): Unable to find wwn login" |
| 4140 | " (s_id %x:%x:%x), trying to create it manually\n", |
| 4141 | vha->vp_idx, s_id[0], s_id[1], s_id[2]); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4142 | |
| 4143 | if (op->atio.u.raw.entry_count > 1) { |
| 4144 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf023, |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4145 | "Dropping multy entry atio %p\n", &op->atio); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4146 | goto out_term; |
| 4147 | } |
| 4148 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4149 | sess = qlt_make_local_sess(vha, s_id); |
| 4150 | /* sess has an extra creation ref. */ |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4151 | |
| 4152 | if (!sess) |
| 4153 | goto out_term; |
| 4154 | /* |
| 4155 | * Now obtain a pre-allocated session tag using the original op->atio |
| 4156 | * packet header, and dispatch into __qlt_do_work() using the existing |
| 4157 | * process context. |
| 4158 | */ |
| 4159 | cmd = qlt_get_tag(vha, sess, &op->atio); |
| 4160 | if (!cmd) { |
| 4161 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4162 | qlt_send_busy(vha, &op->atio, SAM_STAT_BUSY); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4163 | ha->tgt.tgt_ops->put_sess(sess); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4164 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4165 | kfree(op); |
| 4166 | return; |
| 4167 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4168 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4169 | /* |
Christoph Hellwig | e3dc0e3 | 2016-05-02 15:45:23 +0200 | [diff] [blame] | 4170 | * __qlt_do_work() will call qlt_put_sess() to release |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4171 | * the extra reference taken above by qlt_make_local_sess() |
| 4172 | */ |
| 4173 | __qlt_do_work(cmd); |
| 4174 | kfree(op); |
| 4175 | return; |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4176 | out_term: |
| 4177 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4178 | qlt_send_term_exchange(vha, NULL, &op->atio, 1, 0); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4179 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4180 | kfree(op); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4181 | } |
| 4182 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4183 | /* ha->hardware_lock supposed to be held on entry */ |
| 4184 | static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, |
| 4185 | struct atio_from_isp *atio) |
| 4186 | { |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4187 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4188 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4189 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4190 | struct qla_tgt_cmd *cmd; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4191 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4192 | |
| 4193 | if (unlikely(tgt->tgt_stop)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4194 | ql_dbg(ql_dbg_io, vha, 0x3061, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4195 | "New command while device %p is shutting down\n", tgt); |
| 4196 | return -EFAULT; |
| 4197 | } |
| 4198 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4199 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, atio->u.isp24.fcp_hdr.s_id); |
| 4200 | if (unlikely(!sess)) { |
| 4201 | struct qla_tgt_sess_op *op = kzalloc(sizeof(struct qla_tgt_sess_op), |
| 4202 | GFP_ATOMIC); |
| 4203 | if (!op) |
| 4204 | return -ENOMEM; |
| 4205 | |
| 4206 | memcpy(&op->atio, atio, sizeof(*atio)); |
Himanshu Madhani | 78c2106 | 2014-09-25 06:14:44 -0400 | [diff] [blame] | 4207 | op->vha = vha; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4208 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4209 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4210 | list_add_tail(&op->cmd_list, &vha->qla_sess_op_cmd_list); |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4211 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4212 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4213 | INIT_WORK(&op->work, qlt_create_sess_from_atio); |
| 4214 | queue_work(qla_tgt_wq, &op->work); |
| 4215 | return 0; |
| 4216 | } |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4217 | |
| 4218 | /* Another WWN used to have our s_id. Our PLOGI scheduled its |
| 4219 | * session deletion, but it's still in sess_del_work wq */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4220 | if (sess->deleted) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4221 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf002, |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4222 | "New command while old session %p is being deleted\n", |
| 4223 | sess); |
| 4224 | return -EFAULT; |
| 4225 | } |
| 4226 | |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4227 | /* |
| 4228 | * Do kref_get() before returning + dropping qla_hw_data->hardware_lock. |
| 4229 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4230 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4231 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf004, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4232 | "%s: kref_get fail, %8phC oxid %x \n", |
| 4233 | __func__, sess->port_name, |
| 4234 | be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id)); |
| 4235 | return -EFAULT; |
| 4236 | } |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 4237 | |
| 4238 | cmd = qlt_get_tag(vha, sess, atio); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4239 | if (!cmd) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4240 | ql_dbg(ql_dbg_io, vha, 0x3062, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4241 | "qla_target(%d): Allocation of cmd failed\n", vha->vp_idx); |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4242 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4243 | ha->tgt.tgt_ops->put_sess(sess); |
| 4244 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4245 | return -ENOMEM; |
| 4246 | } |
| 4247 | |
Saurav Kashyap | e07f8f6 | 2014-09-25 06:14:58 -0400 | [diff] [blame] | 4248 | cmd->cmd_in_wq = 1; |
Quinn Tran | 1eb42f9 | 2017-01-19 22:27:55 -0800 | [diff] [blame] | 4249 | cmd->trc_flags |= TRC_NEW_CMD; |
Quinn Tran | 5327c7d | 2016-02-10 18:59:14 -0500 | [diff] [blame] | 4250 | cmd->se_cmd.cpuid = ha->msix_count ? |
| 4251 | ha->tgt.rspq_vector_cpuid : WORK_CPU_UNBOUND; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4252 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4253 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4254 | list_add_tail(&cmd->cmd_list, &vha->qla_cmd_list); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4255 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4256 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4257 | INIT_WORK(&cmd->work, qlt_do_work); |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4258 | if (ha->msix_count) { |
Quinn Tran | fb3269b | 2015-12-17 14:57:06 -0500 | [diff] [blame] | 4259 | if (cmd->atio.u.isp24.fcp_cmnd.rddata) |
| 4260 | queue_work_on(smp_processor_id(), qla_tgt_wq, |
| 4261 | &cmd->work); |
| 4262 | else |
| 4263 | queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, |
| 4264 | &cmd->work); |
| 4265 | } else { |
| 4266 | queue_work(qla_tgt_wq, &cmd->work); |
| 4267 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4268 | return 0; |
| 4269 | |
| 4270 | } |
| 4271 | |
| 4272 | /* ha->hardware_lock supposed to be held on entry */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4273 | static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4274 | int fn, void *iocb, int flags) |
| 4275 | { |
| 4276 | struct scsi_qla_host *vha = sess->vha; |
| 4277 | struct qla_hw_data *ha = vha->hw; |
| 4278 | struct qla_tgt_mgmt_cmd *mcmd; |
Swapnil Nagle | 8b2f5ff | 2015-07-14 16:00:43 -0400 | [diff] [blame] | 4279 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4280 | int res; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4281 | |
| 4282 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4283 | if (!mcmd) { |
| 4284 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x10009, |
| 4285 | "qla_target(%d): Allocation of management " |
| 4286 | "command failed, some commands and their data could " |
| 4287 | "leak\n", vha->vp_idx); |
| 4288 | return -ENOMEM; |
| 4289 | } |
| 4290 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4291 | mcmd->sess = sess; |
| 4292 | |
| 4293 | if (iocb) { |
| 4294 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4295 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4296 | } |
| 4297 | mcmd->tmr_func = fn; |
| 4298 | mcmd->flags = flags; |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 4299 | mcmd->reset_count = vha->hw->chip_reset; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4300 | |
| 4301 | switch (fn) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4302 | case QLA_TGT_LUN_RESET: |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4303 | abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id); |
| 4304 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4305 | } |
| 4306 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4307 | 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] | 4308 | if (res != 0) { |
| 4309 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000b, |
| 4310 | "qla_target(%d): tgt.tgt_ops->handle_tmr() failed: %d\n", |
| 4311 | sess->vha->vp_idx, res); |
| 4312 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4313 | return -EFAULT; |
| 4314 | } |
| 4315 | |
| 4316 | return 0; |
| 4317 | } |
| 4318 | |
| 4319 | /* ha->hardware_lock supposed to be held on entry */ |
| 4320 | static int qlt_handle_task_mgmt(struct scsi_qla_host *vha, void *iocb) |
| 4321 | { |
| 4322 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4323 | struct qla_hw_data *ha = vha->hw; |
| 4324 | struct qla_tgt *tgt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4325 | struct fc_port *sess; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4326 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 4327 | int fn; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4328 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4329 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4330 | tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4331 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4332 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4333 | |
| 4334 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4335 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4336 | a->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4337 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4338 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4339 | unpacked_lun = |
| 4340 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4341 | |
| 4342 | if (!sess) { |
| 4343 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf024, |
| 4344 | "qla_target(%d): task mgmt fn 0x%x for " |
| 4345 | "non-existant session\n", vha->vp_idx, fn); |
| 4346 | return qlt_sched_sess_work(tgt, QLA_TGT_SESS_WORK_TM, iocb, |
| 4347 | sizeof(struct atio_from_isp)); |
| 4348 | } |
| 4349 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4350 | if (sess->deleted) |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 4351 | return -EFAULT; |
| 4352 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4353 | return qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
| 4354 | } |
| 4355 | |
| 4356 | /* ha->hardware_lock supposed to be held on entry */ |
| 4357 | static int __qlt_abort_task(struct scsi_qla_host *vha, |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4358 | struct imm_ntfy_from_isp *iocb, struct fc_port *sess) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4359 | { |
| 4360 | struct atio_from_isp *a = (struct atio_from_isp *)iocb; |
| 4361 | struct qla_hw_data *ha = vha->hw; |
| 4362 | struct qla_tgt_mgmt_cmd *mcmd; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4363 | u64 unpacked_lun; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4364 | int rc; |
| 4365 | |
| 4366 | mcmd = mempool_alloc(qla_tgt_mgmt_cmd_mempool, GFP_ATOMIC); |
| 4367 | if (mcmd == NULL) { |
| 4368 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05f, |
| 4369 | "qla_target(%d): %s: Allocation of ABORT cmd failed\n", |
| 4370 | vha->vp_idx, __func__); |
| 4371 | return -ENOMEM; |
| 4372 | } |
| 4373 | memset(mcmd, 0, sizeof(*mcmd)); |
| 4374 | |
| 4375 | mcmd->sess = sess; |
| 4376 | memcpy(&mcmd->orig_iocb.imm_ntfy, iocb, |
| 4377 | sizeof(mcmd->orig_iocb.imm_ntfy)); |
| 4378 | |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 4379 | unpacked_lun = |
| 4380 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Arun Easi | 80187f8 | 2014-09-25 06:14:53 -0400 | [diff] [blame] | 4381 | mcmd->reset_count = vha->hw->chip_reset; |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4382 | mcmd->tmr_func = QLA_TGT_2G_ABORT_TASK; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4383 | |
Quinn Tran | be92fc3 | 2017-01-19 22:27:54 -0800 | [diff] [blame] | 4384 | 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] | 4385 | le16_to_cpu(iocb->u.isp2x.seq_id)); |
| 4386 | if (rc != 0) { |
| 4387 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf060, |
| 4388 | "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", |
| 4389 | vha->vp_idx, rc); |
| 4390 | mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); |
| 4391 | return -EFAULT; |
| 4392 | } |
| 4393 | |
| 4394 | return 0; |
| 4395 | } |
| 4396 | |
| 4397 | /* ha->hardware_lock supposed to be held on entry */ |
| 4398 | static int qlt_abort_task(struct scsi_qla_host *vha, |
| 4399 | struct imm_ntfy_from_isp *iocb) |
| 4400 | { |
| 4401 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4402 | struct fc_port *sess; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4403 | int loop_id; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4404 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4405 | |
| 4406 | loop_id = GET_TARGET_ID(ha, (struct atio_from_isp *)iocb); |
| 4407 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4408 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4409 | 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] | 4410 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4411 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4412 | if (sess == NULL) { |
| 4413 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf025, |
| 4414 | "qla_target(%d): task abort for unexisting " |
| 4415 | "session\n", vha->vp_idx); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4416 | return qlt_sched_sess_work(vha->vha_tgt.qla_tgt, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4417 | QLA_TGT_SESS_WORK_ABORT, iocb, sizeof(*iocb)); |
| 4418 | } |
| 4419 | |
| 4420 | return __qlt_abort_task(vha, iocb, sess); |
| 4421 | } |
| 4422 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4423 | void qlt_logo_completion_handler(fc_port_t *fcport, int rc) |
| 4424 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4425 | if (rc != MBS_COMMAND_COMPLETE) { |
| 4426 | ql_dbg(ql_dbg_tgt_mgt, fcport->vha, 0xf093, |
| 4427 | "%s: se_sess %p / sess %p from" |
| 4428 | " port %8phC loop_id %#04x s_id %02x:%02x:%02x" |
| 4429 | " LOGO failed: %#x\n", |
| 4430 | __func__, |
| 4431 | fcport->se_sess, |
| 4432 | fcport, |
| 4433 | fcport->port_name, fcport->loop_id, |
| 4434 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4435 | fcport->d_id.b.al_pa, rc); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4436 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4437 | |
| 4438 | fcport->logout_completed = 1; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4439 | } |
| 4440 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4441 | /* |
| 4442 | * ha->hardware_lock supposed to be held on entry (to protect tgt->sess_list) |
| 4443 | * |
| 4444 | * Schedules sessions with matching port_id/loop_id but different wwn for |
| 4445 | * deletion. Returns existing session with matching wwn if present. |
| 4446 | * Null otherwise. |
| 4447 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4448 | struct fc_port * |
| 4449 | 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] | 4450 | 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] | 4451 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4452 | struct fc_port *sess = NULL, *other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4453 | uint64_t other_wwn; |
| 4454 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4455 | *conflict_sess = NULL; |
| 4456 | |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4457 | list_for_each_entry(other_sess, &vha->vp_fcports, list) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4458 | |
| 4459 | other_wwn = wwn_to_u64(other_sess->port_name); |
| 4460 | |
| 4461 | if (wwn == other_wwn) { |
| 4462 | WARN_ON(sess); |
| 4463 | sess = other_sess; |
| 4464 | continue; |
| 4465 | } |
| 4466 | |
| 4467 | /* find other sess with nport_id collision */ |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4468 | if (port_id.b24 == other_sess->d_id.b24) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4469 | if (loop_id != other_sess->loop_id) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4470 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000c, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4471 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4472 | other_sess, other_sess->loop_id, other_wwn); |
| 4473 | |
| 4474 | /* |
| 4475 | * logout_on_delete is set by default, but another |
| 4476 | * session that has the same s_id/loop_id combo |
| 4477 | * might have cleared it when requested this session |
| 4478 | * deletion, so don't touch it |
| 4479 | */ |
| 4480 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4481 | } else { |
| 4482 | /* |
| 4483 | * Another wwn used to have our s_id/loop_id |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4484 | * kill the session, but don't free the loop_id |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4485 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4486 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01b, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4487 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4488 | other_sess, other_sess->loop_id, other_wwn); |
| 4489 | |
| 4490 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4491 | other_sess->keep_nport_handle = 1; |
| 4492 | *conflict_sess = other_sess; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4493 | qlt_schedule_sess_for_deletion(other_sess, |
| 4494 | true); |
| 4495 | } |
| 4496 | continue; |
| 4497 | } |
| 4498 | |
| 4499 | /* find other sess with nport handle collision */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4500 | if ((loop_id == other_sess->loop_id) && |
| 4501 | (loop_id != FC_NO_LOOP_ID)) { |
| 4502 | ql_dbg(ql_dbg_tgt_tmr, vha, 0x1000d, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4503 | "Invalidating sess %p loop_id %d wwn %llx.\n", |
| 4504 | other_sess, other_sess->loop_id, other_wwn); |
| 4505 | |
| 4506 | /* Same loop_id but different s_id |
| 4507 | * Ok to kill and logout */ |
| 4508 | qlt_schedule_sess_for_deletion(other_sess, true); |
| 4509 | } |
| 4510 | } |
| 4511 | |
| 4512 | return sess; |
| 4513 | } |
| 4514 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4515 | /* Abort any commands for this s_id waiting on qla_tgt_wq workqueue */ |
| 4516 | static int abort_cmds_for_s_id(struct scsi_qla_host *vha, port_id_t *s_id) |
| 4517 | { |
| 4518 | struct qla_tgt_sess_op *op; |
| 4519 | struct qla_tgt_cmd *cmd; |
| 4520 | uint32_t key; |
| 4521 | int count = 0; |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4522 | unsigned long flags; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4523 | |
| 4524 | key = (((u32)s_id->b.domain << 16) | |
| 4525 | ((u32)s_id->b.area << 8) | |
| 4526 | ((u32)s_id->b.al_pa)); |
| 4527 | |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4528 | spin_lock_irqsave(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4529 | list_for_each_entry(op, &vha->qla_sess_op_cmd_list, cmd_list) { |
| 4530 | 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] | 4531 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4532 | if (op_key == key) { |
| 4533 | op->aborted = true; |
| 4534 | count++; |
| 4535 | } |
| 4536 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4537 | |
| 4538 | list_for_each_entry(op, &vha->unknown_atio_list, cmd_list) { |
| 4539 | uint32_t op_key = sid_to_key(op->atio.u.isp24.fcp_hdr.s_id); |
| 4540 | if (op_key == key) { |
| 4541 | op->aborted = true; |
| 4542 | count++; |
| 4543 | } |
| 4544 | } |
| 4545 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4546 | list_for_each_entry(cmd, &vha->qla_cmd_list, cmd_list) { |
| 4547 | uint32_t cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); |
| 4548 | if (cmd_key == key) { |
Quinn Tran | 193b50b | 2015-12-17 14:57:03 -0500 | [diff] [blame] | 4549 | cmd->aborted = 1; |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4550 | count++; |
| 4551 | } |
| 4552 | } |
Quinn Tran | 8b631d8 | 2017-06-02 09:11:54 -0700 | [diff] [blame] | 4553 | spin_unlock_irqrestore(&vha->cmd_list_lock, flags); |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4554 | |
| 4555 | return count; |
| 4556 | } |
| 4557 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4558 | /* |
| 4559 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4560 | */ |
| 4561 | static int qlt_24xx_handle_els(struct scsi_qla_host *vha, |
| 4562 | struct imm_ntfy_from_isp *iocb) |
| 4563 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4564 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4565 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4566 | struct fc_port *sess = NULL, *conflict_sess = NULL; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4567 | uint64_t wwn; |
| 4568 | port_id_t port_id; |
| 4569 | uint16_t loop_id; |
| 4570 | uint16_t wd3_lo; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4571 | int res = 0; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4572 | struct qlt_plogi_ack_t *pla; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4573 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4574 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4575 | wwn = wwn_to_u64(iocb->u.isp24.port_name); |
| 4576 | |
| 4577 | port_id.b.domain = iocb->u.isp24.port_id[2]; |
| 4578 | port_id.b.area = iocb->u.isp24.port_id[1]; |
| 4579 | port_id.b.al_pa = iocb->u.isp24.port_id[0]; |
| 4580 | port_id.b.rsvd_1 = 0; |
| 4581 | |
| 4582 | loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); |
| 4583 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4584 | ql_dbg(ql_dbg_disc, vha, 0xf026, |
| 4585 | "qla_target(%d): Port ID: %02x:%02x:%02x ELS opcode: 0x%02x lid %d %8phC\n", |
| 4586 | vha->vp_idx, iocb->u.isp24.port_id[2], |
| 4587 | iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0], |
| 4588 | iocb->u.isp24.status_subcode, loop_id, |
| 4589 | iocb->u.isp24.port_name); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4590 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4591 | /* res = 1 means ack at the end of thread |
| 4592 | * res = 0 means ack async/later. |
| 4593 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4594 | switch (iocb->u.isp24.status_subcode) { |
| 4595 | case ELS_PLOGI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4596 | |
Alexei Potashnik | daddf5c | 2015-07-14 16:00:45 -0400 | [diff] [blame] | 4597 | /* Mark all stale commands in qla_tgt_wq for deletion */ |
| 4598 | abort_cmds_for_s_id(vha, &port_id); |
| 4599 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4600 | if (wwn) { |
| 4601 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4602 | sess = qlt_find_sess_invalidate_other(vha, wwn, |
| 4603 | port_id, loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4604 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4605 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4606 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4607 | if (IS_SW_RESV_ADDR(port_id)) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4608 | res = 1; |
| 4609 | break; |
| 4610 | } |
| 4611 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4612 | pla = qlt_plogi_ack_find_add(vha, &port_id, iocb); |
| 4613 | if (!pla) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4614 | qlt_send_term_imm_notif(vha, iocb, 1); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4615 | break; |
| 4616 | } |
| 4617 | |
| 4618 | res = 0; |
| 4619 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4620 | if (conflict_sess) { |
| 4621 | conflict_sess->login_gen++; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4622 | qlt_plogi_ack_link(vha, pla, conflict_sess, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4623 | QLT_PLOGI_LINK_CONFLICT); |
| 4624 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4625 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4626 | if (!sess) { |
| 4627 | pla->ref_count++; |
| 4628 | qla24xx_post_newsess_work(vha, &port_id, |
| 4629 | iocb->u.isp24.port_name, pla); |
| 4630 | res = 0; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4631 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4632 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4633 | |
| 4634 | qlt_plogi_ack_link(vha, pla, sess, QLT_PLOGI_LINK_SAME_WWN); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4635 | sess->fw_login_state = DSC_LS_PLOGI_PEND; |
| 4636 | sess->d_id = port_id; |
| 4637 | sess->login_gen++; |
| 4638 | |
| 4639 | switch (sess->disc_state) { |
| 4640 | case DSC_DELETED: |
| 4641 | qlt_plogi_ack_unref(vha, pla); |
| 4642 | break; |
| 4643 | |
| 4644 | default: |
| 4645 | /* |
| 4646 | * Under normal circumstances we want to release nport handle |
| 4647 | * during LOGO process to avoid nport handle leaks inside FW. |
| 4648 | * The exception is when LOGO is done while another PLOGI with |
| 4649 | * the same nport handle is waiting as might be the case here. |
| 4650 | * Note: there is always a possibily of a race where session |
| 4651 | * deletion has already started for other reasons (e.g. ACL |
| 4652 | * removal) and now PLOGI arrives: |
| 4653 | * 1. if PLOGI arrived in FW after nport handle has been freed, |
| 4654 | * FW must have assigned this PLOGI a new/same handle and we |
| 4655 | * can proceed ACK'ing it as usual when session deletion |
| 4656 | * completes. |
| 4657 | * 2. if PLOGI arrived in FW before LOGO with LCF_FREE_NPORT |
| 4658 | * bit reached it, the handle has now been released. We'll |
| 4659 | * get an error when we ACK this PLOGI. Nothing will be sent |
| 4660 | * back to initiator. Initiator should eventually retry |
| 4661 | * PLOGI and situation will correct itself. |
| 4662 | */ |
| 4663 | sess->keep_nport_handle = ((sess->loop_id == loop_id) && |
| 4664 | (sess->d_id.b24 == port_id.b24)); |
| 4665 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4666 | ql_dbg(ql_dbg_disc, vha, 0x20f9, |
| 4667 | "%s %d %8phC post del sess\n", |
| 4668 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4669 | |
| 4670 | |
| 4671 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4672 | break; |
| 4673 | } |
| 4674 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4675 | break; |
| 4676 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4677 | case ELS_PRLI: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4678 | wd3_lo = le16_to_cpu(iocb->u.isp24.u.prli.wd3_lo); |
| 4679 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4680 | if (wwn) { |
| 4681 | spin_lock_irqsave(&tgt->ha->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4682 | sess = qlt_find_sess_invalidate_other(vha, wwn, port_id, |
| 4683 | loop_id, &conflict_sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4684 | spin_unlock_irqrestore(&tgt->ha->tgt.sess_lock, flags); |
| 4685 | } |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 4686 | |
| 4687 | if (conflict_sess) { |
| 4688 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf09b, |
| 4689 | "PRLI with conflicting sess %p port %8phC\n", |
| 4690 | conflict_sess, conflict_sess->port_name); |
| 4691 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4692 | res = 0; |
| 4693 | break; |
| 4694 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4695 | |
| 4696 | if (sess != NULL) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4697 | if (sess->fw_login_state != DSC_LS_PLOGI_PEND && |
| 4698 | sess->fw_login_state != DSC_LS_PLOGI_COMP) { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4699 | /* |
| 4700 | * Impatient initiator sent PRLI before last |
| 4701 | * PLOGI could finish. Will force him to re-try, |
| 4702 | * while last one finishes. |
| 4703 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4704 | ql_log(ql_log_warn, sess->vha, 0xf095, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4705 | "sess %p PRLI received, before plogi ack.\n", |
| 4706 | sess); |
| 4707 | qlt_send_term_imm_notif(vha, iocb, 1); |
| 4708 | res = 0; |
| 4709 | break; |
| 4710 | } |
| 4711 | |
| 4712 | /* |
| 4713 | * This shouldn't happen under normal circumstances, |
| 4714 | * since we have deleted the old session during PLOGI |
| 4715 | */ |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4716 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf096, |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4717 | "PRLI (loop_id %#04x) for existing sess %p (loop_id %#04x)\n", |
| 4718 | sess->loop_id, sess, iocb->u.isp24.nport_handle); |
| 4719 | |
| 4720 | sess->local = 0; |
| 4721 | sess->loop_id = loop_id; |
Quinn Tran | 37cacc0 | 2017-01-19 22:27:58 -0800 | [diff] [blame] | 4722 | sess->d_id = port_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4723 | sess->fw_login_state = DSC_LS_PRLI_PEND; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4724 | |
| 4725 | if (wd3_lo & BIT_7) |
| 4726 | sess->conf_compl_supported = 1; |
| 4727 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4728 | if ((wd3_lo & BIT_4) == 0) |
| 4729 | sess->port_type = FCT_INITIATOR; |
| 4730 | else |
| 4731 | sess->port_type = FCT_TARGET; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4732 | } |
| 4733 | res = 1; /* send notify ack */ |
| 4734 | |
| 4735 | /* Make session global (not used in fabric mode) */ |
| 4736 | if (ha->current_topology != ISP_CFG_F) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4737 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4738 | ql_dbg(ql_dbg_disc, vha, 0x20fa, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4739 | "%s %d %8phC post nack\n", |
| 4740 | __func__, __LINE__, sess->port_name); |
| 4741 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4742 | SRB_NACK_PRLI); |
| 4743 | res = 0; |
| 4744 | } else { |
| 4745 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4746 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4747 | qla2xxx_wake_dpc(vha); |
| 4748 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4749 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4750 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4751 | ql_dbg(ql_dbg_disc, vha, 0x20fb, |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4752 | "%s %d %8phC post nack\n", |
| 4753 | __func__, __LINE__, sess->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4754 | qla24xx_post_nack_work(vha, sess, iocb, |
| 4755 | SRB_NACK_PRLI); |
| 4756 | res = 0; |
| 4757 | } |
| 4758 | } |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4759 | break; |
| 4760 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4761 | case ELS_TPRLO: |
| 4762 | if (le16_to_cpu(iocb->u.isp24.flags) & |
| 4763 | NOTIFY24XX_FLAGS_GLOBAL_TPRLO) { |
| 4764 | loop_id = 0xFFFF; |
| 4765 | qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS); |
| 4766 | res = 1; |
| 4767 | break; |
| 4768 | } |
| 4769 | /* drop through */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4770 | case ELS_LOGO: |
| 4771 | case ELS_PRLO: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4772 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
| 4773 | sess = qla2x00_find_fcport_by_loopid(vha, loop_id); |
| 4774 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 4775 | |
| 4776 | if (sess) { |
| 4777 | sess->login_gen++; |
| 4778 | sess->fw_login_state = DSC_LS_LOGO_PEND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4779 | sess->logo_ack_needed = 1; |
| 4780 | memcpy(sess->iocb, iocb, IOCB_SIZE); |
| 4781 | } |
| 4782 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4783 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4784 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4785 | ql_dbg(ql_dbg_disc, vha, 0x20fc, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4786 | "%s: logo %llx res %d sess %p ", |
| 4787 | __func__, wwn, res, sess); |
| 4788 | if (res == 0) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4789 | /* |
| 4790 | * cmd went upper layer, look for qlt_xmit_tm_rsp() |
| 4791 | * for LOGO_ACK & sess delete |
| 4792 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4793 | BUG_ON(!sess); |
| 4794 | res = 0; |
| 4795 | } else { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4796 | /* cmd did not go to upper layer. */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4797 | if (sess) { |
| 4798 | qlt_schedule_sess_for_deletion_lock(sess); |
| 4799 | res = 0; |
| 4800 | } |
| 4801 | /* else logo will be ack */ |
| 4802 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4803 | break; |
| 4804 | case ELS_PDISC: |
| 4805 | case ELS_ADISC: |
| 4806 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4807 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4808 | if (tgt->link_reinit_iocb_pending) { |
| 4809 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, |
| 4810 | 0, 0, 0, 0, 0, 0); |
| 4811 | tgt->link_reinit_iocb_pending = 0; |
| 4812 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4813 | |
| 4814 | sess = qla2x00_find_fcport_by_wwpn(vha, |
| 4815 | iocb->u.isp24.port_name, 1); |
| 4816 | if (sess) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4817 | ql_dbg(ql_dbg_disc, vha, 0x20fd, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4818 | "sess %p lid %d|%d DS %d LS %d\n", |
| 4819 | sess, sess->loop_id, loop_id, |
| 4820 | sess->disc_state, sess->fw_login_state); |
| 4821 | } |
| 4822 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4823 | res = 1; /* send notify ack */ |
| 4824 | break; |
| 4825 | } |
| 4826 | |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 4827 | case ELS_FLOGI: /* should never happen */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4828 | default: |
| 4829 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf061, |
| 4830 | "qla_target(%d): Unsupported ELS command %x " |
| 4831 | "received\n", vha->vp_idx, iocb->u.isp24.status_subcode); |
| 4832 | res = qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS); |
| 4833 | break; |
| 4834 | } |
| 4835 | |
| 4836 | return res; |
| 4837 | } |
| 4838 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4839 | /* |
| 4840 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4841 | */ |
| 4842 | static void qlt_handle_imm_notify(struct scsi_qla_host *vha, |
| 4843 | struct imm_ntfy_from_isp *iocb) |
| 4844 | { |
| 4845 | struct qla_hw_data *ha = vha->hw; |
| 4846 | uint32_t add_flags = 0; |
| 4847 | int send_notify_ack = 1; |
| 4848 | uint16_t status; |
| 4849 | |
| 4850 | status = le16_to_cpu(iocb->u.isp2x.status); |
| 4851 | switch (status) { |
| 4852 | case IMM_NTFY_LIP_RESET: |
| 4853 | { |
| 4854 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf032, |
| 4855 | "qla_target(%d): LIP reset (loop %#x), subcode %x\n", |
| 4856 | vha->vp_idx, le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4857 | iocb->u.isp24.status_subcode); |
| 4858 | |
| 4859 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 4860 | send_notify_ack = 0; |
| 4861 | break; |
| 4862 | } |
| 4863 | |
| 4864 | case IMM_NTFY_LIP_LINK_REINIT: |
| 4865 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 4866 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4867 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf033, |
| 4868 | "qla_target(%d): LINK REINIT (loop %#x, " |
| 4869 | "subcode %x)\n", vha->vp_idx, |
| 4870 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4871 | iocb->u.isp24.status_subcode); |
| 4872 | if (tgt->link_reinit_iocb_pending) { |
| 4873 | qlt_send_notify_ack(vha, &tgt->link_reinit_iocb, |
| 4874 | 0, 0, 0, 0, 0, 0); |
| 4875 | } |
| 4876 | memcpy(&tgt->link_reinit_iocb, iocb, sizeof(*iocb)); |
| 4877 | tgt->link_reinit_iocb_pending = 1; |
| 4878 | /* |
| 4879 | * QLogic requires to wait after LINK REINIT for possible |
| 4880 | * PDISC or ADISC ELS commands |
| 4881 | */ |
| 4882 | send_notify_ack = 0; |
| 4883 | break; |
| 4884 | } |
| 4885 | |
| 4886 | case IMM_NTFY_PORT_LOGOUT: |
| 4887 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf034, |
| 4888 | "qla_target(%d): Port logout (loop " |
| 4889 | "%#x, subcode %x)\n", vha->vp_idx, |
| 4890 | le16_to_cpu(iocb->u.isp24.nport_handle), |
| 4891 | iocb->u.isp24.status_subcode); |
| 4892 | |
| 4893 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS_SESS) == 0) |
| 4894 | send_notify_ack = 0; |
| 4895 | /* The sessions will be cleared in the callback, if needed */ |
| 4896 | break; |
| 4897 | |
| 4898 | case IMM_NTFY_GLBL_TPRLO: |
| 4899 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf035, |
| 4900 | "qla_target(%d): Global TPRLO (%x)\n", vha->vp_idx, status); |
| 4901 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 4902 | send_notify_ack = 0; |
| 4903 | /* The sessions will be cleared in the callback, if needed */ |
| 4904 | break; |
| 4905 | |
| 4906 | case IMM_NTFY_PORT_CONFIG: |
| 4907 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf036, |
| 4908 | "qla_target(%d): Port config changed (%x)\n", vha->vp_idx, |
| 4909 | status); |
| 4910 | if (qlt_reset(vha, iocb, QLA_TGT_ABORT_ALL) == 0) |
| 4911 | send_notify_ack = 0; |
| 4912 | /* The sessions will be cleared in the callback, if needed */ |
| 4913 | break; |
| 4914 | |
| 4915 | case IMM_NTFY_GLBL_LOGO: |
| 4916 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06a, |
| 4917 | "qla_target(%d): Link failure detected\n", |
| 4918 | vha->vp_idx); |
| 4919 | /* I_T nexus loss */ |
| 4920 | if (qlt_reset(vha, iocb, QLA_TGT_NEXUS_LOSS) == 0) |
| 4921 | send_notify_ack = 0; |
| 4922 | break; |
| 4923 | |
| 4924 | case IMM_NTFY_IOCB_OVERFLOW: |
| 4925 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06b, |
| 4926 | "qla_target(%d): Cannot provide requested " |
| 4927 | "capability (IOCB overflowed the immediate notify " |
| 4928 | "resource count)\n", vha->vp_idx); |
| 4929 | break; |
| 4930 | |
| 4931 | case IMM_NTFY_ABORT_TASK: |
| 4932 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf037, |
| 4933 | "qla_target(%d): Abort Task (S %08x I %#x -> " |
| 4934 | "L %#x)\n", vha->vp_idx, |
| 4935 | le16_to_cpu(iocb->u.isp2x.seq_id), |
| 4936 | GET_TARGET_ID(ha, (struct atio_from_isp *)iocb), |
| 4937 | le16_to_cpu(iocb->u.isp2x.lun)); |
| 4938 | if (qlt_abort_task(vha, iocb) == 0) |
| 4939 | send_notify_ack = 0; |
| 4940 | break; |
| 4941 | |
| 4942 | case IMM_NTFY_RESOURCE: |
| 4943 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06c, |
| 4944 | "qla_target(%d): Out of resources, host %ld\n", |
| 4945 | vha->vp_idx, vha->host_no); |
| 4946 | break; |
| 4947 | |
| 4948 | case IMM_NTFY_MSG_RX: |
| 4949 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf038, |
| 4950 | "qla_target(%d): Immediate notify task %x\n", |
| 4951 | vha->vp_idx, iocb->u.isp2x.task_flags); |
| 4952 | if (qlt_handle_task_mgmt(vha, iocb) == 0) |
| 4953 | send_notify_ack = 0; |
| 4954 | break; |
| 4955 | |
| 4956 | case IMM_NTFY_ELS: |
| 4957 | if (qlt_24xx_handle_els(vha, iocb) == 0) |
| 4958 | send_notify_ack = 0; |
| 4959 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4960 | default: |
| 4961 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, |
| 4962 | "qla_target(%d): Received unknown immediate " |
| 4963 | "notify status %x\n", vha->vp_idx, status); |
| 4964 | break; |
| 4965 | } |
| 4966 | |
| 4967 | if (send_notify_ack) |
| 4968 | qlt_send_notify_ack(vha, iocb, add_flags, 0, 0, 0, 0, 0); |
| 4969 | } |
| 4970 | |
| 4971 | /* |
| 4972 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 4973 | * This function sends busy to ISP 2xxx or 24xx. |
| 4974 | */ |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4975 | static int __qlt_send_busy(struct scsi_qla_host *vha, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4976 | struct atio_from_isp *atio, uint16_t status) |
| 4977 | { |
| 4978 | struct ctio7_to_24xx *ctio24; |
| 4979 | struct qla_hw_data *ha = vha->hw; |
| 4980 | request_t *pkt; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 4981 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4982 | unsigned long flags; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 4983 | u16 temp; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4984 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4985 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4986 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 4987 | atio->u.isp24.fcp_hdr.s_id); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 4988 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4989 | if (!sess) { |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 4990 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 4991 | return 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4992 | } |
| 4993 | /* Sending marker isn't necessary, since we called from ISR */ |
| 4994 | |
| 4995 | pkt = (request_t *)qla2x00_alloc_iocbs(vha, NULL); |
| 4996 | if (!pkt) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 4997 | ql_dbg(ql_dbg_io, vha, 0x3063, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4998 | "qla_target(%d): %s failed: unable to allocate " |
| 4999 | "request packet", vha->vp_idx, __func__); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5000 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5001 | } |
| 5002 | |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 5003 | vha->tgt_counters.num_q_full_sent++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5004 | pkt->entry_count = 1; |
| 5005 | pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; |
| 5006 | |
| 5007 | ctio24 = (struct ctio7_to_24xx *)pkt; |
| 5008 | ctio24->entry_type = CTIO_TYPE7; |
| 5009 | ctio24->nport_handle = sess->loop_id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5010 | ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5011 | ctio24->vp_index = vha->vp_idx; |
| 5012 | ctio24->initiator_id[0] = atio->u.isp24.fcp_hdr.s_id[2]; |
| 5013 | ctio24->initiator_id[1] = atio->u.isp24.fcp_hdr.s_id[1]; |
| 5014 | ctio24->initiator_id[2] = atio->u.isp24.fcp_hdr.s_id[0]; |
| 5015 | ctio24->exchange_addr = atio->u.isp24.exchange_addr; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5016 | temp = (atio->u.isp24.attr << 9) | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5017 | CTIO7_FLAGS_STATUS_MODE_1 | CTIO7_FLAGS_SEND_STATUS | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 5018 | CTIO7_FLAGS_DONT_RET_CTIO; |
| 5019 | ctio24->u.status1.flags = cpu_to_le16(temp); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5020 | /* |
| 5021 | * CTIO from fw w/o se_cmd doesn't provide enough info to retry it, |
| 5022 | * if the explicit conformation is used. |
| 5023 | */ |
| 5024 | ctio24->u.status1.ox_id = swab16(atio->u.isp24.fcp_hdr.ox_id); |
| 5025 | ctio24->u.status1.scsi_status = cpu_to_le16(status); |
Himanshu Madhani | 63163e0 | 2014-09-25 06:14:59 -0400 | [diff] [blame] | 5026 | /* Memory Barrier */ |
| 5027 | wmb(); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5028 | qla2x00_start_iocbs(vha, vha->req); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5029 | return 0; |
| 5030 | } |
| 5031 | |
| 5032 | /* |
| 5033 | * This routine is used to allocate a command for either a QFull condition |
| 5034 | * (ie reply SAM_STAT_BUSY) or to terminate an exchange that did not go |
| 5035 | * out previously. |
| 5036 | */ |
| 5037 | static void |
| 5038 | qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, |
| 5039 | struct atio_from_isp *atio, uint16_t status, int qfull) |
| 5040 | { |
| 5041 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
| 5042 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5043 | struct fc_port *sess; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5044 | struct se_session *se_sess; |
| 5045 | struct qla_tgt_cmd *cmd; |
| 5046 | int tag; |
| 5047 | |
| 5048 | if (unlikely(tgt->tgt_stop)) { |
| 5049 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 5050 | "New command while device %p is shutting down\n", tgt); |
| 5051 | return; |
| 5052 | } |
| 5053 | |
| 5054 | if ((vha->hw->tgt.num_qfull_cmds_alloc + 1) > MAX_QFULL_CMDS_ALLOC) { |
| 5055 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5056 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5057 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5058 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5059 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5060 | |
| 5061 | ql_dbg(ql_dbg_io, vha, 0x3068, |
| 5062 | "qla_target(%d): %s: QFull CMD dropped[%d]\n", |
| 5063 | vha->vp_idx, __func__, |
| 5064 | vha->hw->tgt.num_qfull_cmds_dropped); |
| 5065 | |
| 5066 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5067 | return; |
| 5068 | } |
| 5069 | |
| 5070 | sess = ha->tgt.tgt_ops->find_sess_by_s_id |
| 5071 | (vha, atio->u.isp24.fcp_hdr.s_id); |
| 5072 | if (!sess) |
| 5073 | return; |
| 5074 | |
| 5075 | se_sess = sess->se_sess; |
| 5076 | |
| 5077 | tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); |
| 5078 | if (tag < 0) |
| 5079 | return; |
| 5080 | |
| 5081 | cmd = &((struct qla_tgt_cmd *)se_sess->sess_cmd_map)[tag]; |
| 5082 | if (!cmd) { |
| 5083 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 5084 | "qla_target(%d): %s: Allocation of cmd failed\n", |
| 5085 | vha->vp_idx, __func__); |
| 5086 | |
| 5087 | vha->hw->tgt.num_qfull_cmds_dropped++; |
| 5088 | if (vha->hw->tgt.num_qfull_cmds_dropped > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5089 | vha->qla_stats.stat_max_qfull_cmds_dropped) |
| 5090 | vha->qla_stats.stat_max_qfull_cmds_dropped = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5091 | vha->hw->tgt.num_qfull_cmds_dropped; |
| 5092 | |
| 5093 | qlt_chk_exch_leak_thresh_hold(vha); |
| 5094 | return; |
| 5095 | } |
| 5096 | |
| 5097 | memset(cmd, 0, sizeof(struct qla_tgt_cmd)); |
| 5098 | |
| 5099 | qlt_incr_num_pend_cmds(vha); |
| 5100 | INIT_LIST_HEAD(&cmd->cmd_list); |
| 5101 | memcpy(&cmd->atio, atio, sizeof(*atio)); |
| 5102 | |
| 5103 | cmd->tgt = vha->vha_tgt.qla_tgt; |
| 5104 | cmd->vha = vha; |
| 5105 | cmd->reset_count = vha->hw->chip_reset; |
| 5106 | cmd->q_full = 1; |
| 5107 | |
| 5108 | if (qfull) { |
| 5109 | cmd->q_full = 1; |
| 5110 | /* NOTE: borrowing the state field to carry the status */ |
| 5111 | cmd->state = status; |
| 5112 | } else |
| 5113 | cmd->term_exchg = 1; |
| 5114 | |
| 5115 | list_add_tail(&cmd->cmd_list, &vha->hw->tgt.q_full_list); |
| 5116 | |
| 5117 | vha->hw->tgt.num_qfull_cmds_alloc++; |
| 5118 | if (vha->hw->tgt.num_qfull_cmds_alloc > |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 5119 | vha->qla_stats.stat_max_qfull_cmds_alloc) |
| 5120 | vha->qla_stats.stat_max_qfull_cmds_alloc = |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5121 | vha->hw->tgt.num_qfull_cmds_alloc; |
| 5122 | } |
| 5123 | |
| 5124 | int |
| 5125 | qlt_free_qfull_cmds(struct scsi_qla_host *vha) |
| 5126 | { |
| 5127 | struct qla_hw_data *ha = vha->hw; |
| 5128 | unsigned long flags; |
| 5129 | struct qla_tgt_cmd *cmd, *tcmd; |
| 5130 | struct list_head free_list; |
| 5131 | int rc = 0; |
| 5132 | |
| 5133 | if (list_empty(&ha->tgt.q_full_list)) |
| 5134 | return 0; |
| 5135 | |
| 5136 | INIT_LIST_HEAD(&free_list); |
| 5137 | |
| 5138 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 5139 | |
| 5140 | if (list_empty(&ha->tgt.q_full_list)) { |
| 5141 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 5142 | return 0; |
| 5143 | } |
| 5144 | |
| 5145 | list_for_each_entry_safe(cmd, tcmd, &ha->tgt.q_full_list, cmd_list) { |
| 5146 | if (cmd->q_full) |
| 5147 | /* cmd->state is a borrowed field to hold status */ |
| 5148 | rc = __qlt_send_busy(vha, &cmd->atio, cmd->state); |
| 5149 | else if (cmd->term_exchg) |
| 5150 | rc = __qlt_send_term_exchange(vha, NULL, &cmd->atio); |
| 5151 | |
| 5152 | if (rc == -ENOMEM) |
| 5153 | break; |
| 5154 | |
| 5155 | if (cmd->q_full) |
| 5156 | ql_dbg(ql_dbg_io, vha, 0x3006, |
| 5157 | "%s: busy sent for ox_id[%04x]\n", __func__, |
| 5158 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5159 | else if (cmd->term_exchg) |
| 5160 | ql_dbg(ql_dbg_io, vha, 0x3007, |
| 5161 | "%s: Term exchg sent for ox_id[%04x]\n", __func__, |
| 5162 | be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id)); |
| 5163 | else |
| 5164 | ql_dbg(ql_dbg_io, vha, 0x3008, |
| 5165 | "%s: Unexpected cmd in QFull list %p\n", __func__, |
| 5166 | cmd); |
| 5167 | |
| 5168 | list_del(&cmd->cmd_list); |
| 5169 | list_add_tail(&cmd->cmd_list, &free_list); |
| 5170 | |
| 5171 | /* piggy back on hardware_lock for protection */ |
| 5172 | vha->hw->tgt.num_qfull_cmds_alloc--; |
| 5173 | } |
| 5174 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
| 5175 | |
| 5176 | cmd = NULL; |
| 5177 | |
| 5178 | list_for_each_entry_safe(cmd, tcmd, &free_list, cmd_list) { |
| 5179 | list_del(&cmd->cmd_list); |
| 5180 | /* This cmd was never sent to TCM. There is no need |
| 5181 | * to schedule free or call free_cmd |
| 5182 | */ |
| 5183 | qlt_free_cmd(cmd); |
| 5184 | } |
| 5185 | return rc; |
| 5186 | } |
| 5187 | |
| 5188 | static void |
| 5189 | qlt_send_busy(struct scsi_qla_host *vha, |
| 5190 | struct atio_from_isp *atio, uint16_t status) |
| 5191 | { |
| 5192 | int rc = 0; |
| 5193 | |
| 5194 | rc = __qlt_send_busy(vha, atio, status); |
| 5195 | if (rc == -ENOMEM) |
| 5196 | qlt_alloc_qfull_cmd(vha, atio, status, 1); |
| 5197 | } |
| 5198 | |
| 5199 | static int |
| 5200 | qlt_chk_qfull_thresh_hold(struct scsi_qla_host *vha, |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5201 | struct atio_from_isp *atio, bool ha_locked) |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5202 | { |
| 5203 | struct qla_hw_data *ha = vha->hw; |
| 5204 | uint16_t status; |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5205 | unsigned long flags; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5206 | |
| 5207 | if (ha->tgt.num_pend_cmds < Q_FULL_THRESH_HOLD(ha)) |
| 5208 | return 0; |
| 5209 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5210 | if (!ha_locked) |
| 5211 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5212 | status = temp_sam_status; |
| 5213 | qlt_send_busy(vha, atio, status); |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5214 | if (!ha_locked) |
| 5215 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5216 | |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5217 | return 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | /* ha->hardware_lock supposed to be held on entry */ |
| 5221 | /* called via callback from qla2xxx */ |
| 5222 | static void qlt_24xx_atio_pkt(struct scsi_qla_host *vha, |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5223 | struct atio_from_isp *atio, uint8_t ha_locked) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5224 | { |
| 5225 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5226 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5227 | int rc; |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5228 | unsigned long flags; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5229 | |
| 5230 | if (unlikely(tgt == NULL)) { |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5231 | ql_dbg(ql_dbg_tgt, vha, 0x3064, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5232 | "ATIO pkt, but no tgt (ha %p)", ha); |
| 5233 | return; |
| 5234 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5235 | /* |
| 5236 | * In tgt_stop mode we also should allow all requests to pass. |
| 5237 | * Otherwise, some commands can stuck. |
| 5238 | */ |
| 5239 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5240 | tgt->atio_irq_cmd_count++; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5241 | |
| 5242 | switch (atio->u.raw.entry_type) { |
| 5243 | case ATIO_TYPE7: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5244 | if (unlikely(atio->u.isp24.exchange_addr == |
| 5245 | ATIO_EXCHANGE_ADDRESS_UNKNOWN)) { |
Arun Easi | 667024a | 2014-09-25 06:14:47 -0400 | [diff] [blame] | 5246 | ql_dbg(ql_dbg_io, vha, 0x3065, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5247 | "qla_target(%d): ATIO_TYPE7 " |
| 5248 | "received with UNKNOWN exchange address, " |
| 5249 | "sending QUEUE_FULL\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5250 | if (!ha_locked) |
| 5251 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5252 | qlt_send_busy(vha, atio, SAM_STAT_TASK_SET_FULL); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5253 | if (!ha_locked) |
| 5254 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5255 | break; |
| 5256 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5257 | |
| 5258 | |
| 5259 | |
| 5260 | if (likely(atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0)) { |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5261 | rc = qlt_chk_qfull_thresh_hold(vha, atio, ha_locked); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5262 | if (rc != 0) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5263 | tgt->atio_irq_cmd_count--; |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5264 | return; |
| 5265 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5266 | rc = qlt_handle_cmd_for_atio(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5267 | } else { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5268 | rc = qlt_handle_task_mgmt(vha, atio); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5269 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5270 | if (unlikely(rc != 0)) { |
| 5271 | if (rc == -ESRCH) { |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5272 | if (!ha_locked) |
| 5273 | spin_lock_irqsave |
| 5274 | (&ha->hardware_lock, flags); |
| 5275 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5276 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
| 5277 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); |
| 5278 | #else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5279 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5280 | #endif |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5281 | |
| 5282 | if (!ha_locked) |
| 5283 | spin_unlock_irqrestore |
| 5284 | (&ha->hardware_lock, flags); |
| 5285 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5286 | } else { |
| 5287 | if (tgt->tgt_stop) { |
| 5288 | ql_dbg(ql_dbg_tgt, vha, 0xe059, |
| 5289 | "qla_target: Unable to send " |
| 5290 | "command to target for req, " |
| 5291 | "ignoring.\n"); |
| 5292 | } else { |
| 5293 | ql_dbg(ql_dbg_tgt, vha, 0xe05a, |
| 5294 | "qla_target(%d): Unable to send " |
| 5295 | "command to target, sending BUSY " |
| 5296 | "status.\n", vha->vp_idx); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5297 | if (!ha_locked) |
| 5298 | spin_lock_irqsave( |
| 5299 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5300 | qlt_send_busy(vha, atio, SAM_STAT_BUSY); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5301 | if (!ha_locked) |
| 5302 | spin_unlock_irqrestore( |
| 5303 | &ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5304 | } |
| 5305 | } |
| 5306 | } |
| 5307 | break; |
| 5308 | |
| 5309 | case IMMED_NOTIFY_TYPE: |
| 5310 | { |
| 5311 | if (unlikely(atio->u.isp2x.entry_status != 0)) { |
| 5312 | ql_dbg(ql_dbg_tgt, vha, 0xe05b, |
| 5313 | "qla_target(%d): Received ATIO packet %x " |
| 5314 | "with error status %x\n", vha->vp_idx, |
| 5315 | atio->u.raw.entry_type, |
| 5316 | atio->u.isp2x.entry_status); |
| 5317 | break; |
| 5318 | } |
| 5319 | ql_dbg(ql_dbg_tgt, vha, 0xe02e, "%s", "IMMED_NOTIFY ATIO"); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5320 | |
| 5321 | if (!ha_locked) |
| 5322 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5323 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)atio); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5324 | if (!ha_locked) |
| 5325 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5326 | break; |
| 5327 | } |
| 5328 | |
| 5329 | default: |
| 5330 | ql_dbg(ql_dbg_tgt, vha, 0xe05c, |
| 5331 | "qla_target(%d): Received unknown ATIO atio " |
| 5332 | "type %x\n", vha->vp_idx, atio->u.raw.entry_type); |
| 5333 | break; |
| 5334 | } |
| 5335 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 5336 | tgt->atio_irq_cmd_count--; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | /* ha->hardware_lock supposed to be held on entry */ |
| 5340 | /* called via callback from qla2xxx */ |
| 5341 | static void qlt_response_pkt(struct scsi_qla_host *vha, response_t *pkt) |
| 5342 | { |
| 5343 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5344 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5345 | |
| 5346 | if (unlikely(tgt == NULL)) { |
| 5347 | ql_dbg(ql_dbg_tgt, vha, 0xe05d, |
| 5348 | "qla_target(%d): Response pkt %x received, but no " |
| 5349 | "tgt (ha %p)\n", vha->vp_idx, pkt->entry_type, ha); |
| 5350 | return; |
| 5351 | } |
| 5352 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5353 | /* |
| 5354 | * In tgt_stop mode we also should allow all requests to pass. |
| 5355 | * Otherwise, some commands can stuck. |
| 5356 | */ |
| 5357 | |
| 5358 | tgt->irq_cmd_count++; |
| 5359 | |
| 5360 | switch (pkt->entry_type) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 5361 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5362 | case CTIO_TYPE7: |
| 5363 | { |
| 5364 | struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5365 | qlt_do_ctio_completion(vha, entry->handle, |
| 5366 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5367 | entry); |
| 5368 | break; |
| 5369 | } |
| 5370 | |
| 5371 | case ACCEPT_TGT_IO_TYPE: |
| 5372 | { |
| 5373 | struct atio_from_isp *atio = (struct atio_from_isp *)pkt; |
| 5374 | int rc; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5375 | if (atio->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5376 | cpu_to_le16(ATIO_CDB_VALID)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5377 | ql_dbg(ql_dbg_tgt, vha, 0xe05e, |
| 5378 | "qla_target(%d): ATIO with error " |
| 5379 | "status %x received\n", vha->vp_idx, |
| 5380 | le16_to_cpu(atio->u.isp2x.status)); |
| 5381 | break; |
| 5382 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5383 | |
Quinn Tran | 8b66680 | 2017-03-15 09:48:45 -0700 | [diff] [blame] | 5384 | rc = qlt_chk_qfull_thresh_hold(vha, atio, true); |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 5385 | if (rc != 0) { |
| 5386 | tgt->irq_cmd_count--; |
| 5387 | return; |
| 5388 | } |
| 5389 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5390 | rc = qlt_handle_cmd_for_atio(vha, atio); |
| 5391 | if (unlikely(rc != 0)) { |
| 5392 | if (rc == -ESRCH) { |
| 5393 | #if 1 /* With TERM EXCHANGE some FC cards refuse to boot */ |
| 5394 | qlt_send_busy(vha, atio, 0); |
| 5395 | #else |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5396 | qlt_send_term_exchange(vha, NULL, atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5397 | #endif |
| 5398 | } else { |
| 5399 | if (tgt->tgt_stop) { |
| 5400 | ql_dbg(ql_dbg_tgt, vha, 0xe05f, |
| 5401 | "qla_target: Unable to send " |
| 5402 | "command to target, sending TERM " |
| 5403 | "EXCHANGE for rsp\n"); |
| 5404 | qlt_send_term_exchange(vha, NULL, |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5405 | atio, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5406 | } else { |
| 5407 | ql_dbg(ql_dbg_tgt, vha, 0xe060, |
| 5408 | "qla_target(%d): Unable to send " |
| 5409 | "command to target, sending BUSY " |
| 5410 | "status\n", vha->vp_idx); |
| 5411 | qlt_send_busy(vha, atio, 0); |
| 5412 | } |
| 5413 | } |
| 5414 | } |
| 5415 | } |
| 5416 | break; |
| 5417 | |
| 5418 | case CONTINUE_TGT_IO_TYPE: |
| 5419 | { |
| 5420 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5421 | qlt_do_ctio_completion(vha, entry->handle, |
| 5422 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5423 | entry); |
| 5424 | break; |
| 5425 | } |
| 5426 | |
| 5427 | case CTIO_A64_TYPE: |
| 5428 | { |
| 5429 | struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5430 | qlt_do_ctio_completion(vha, entry->handle, |
| 5431 | le16_to_cpu(entry->status)|(pkt->entry_status << 16), |
| 5432 | entry); |
| 5433 | break; |
| 5434 | } |
| 5435 | |
| 5436 | case IMMED_NOTIFY_TYPE: |
| 5437 | ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); |
| 5438 | qlt_handle_imm_notify(vha, (struct imm_ntfy_from_isp *)pkt); |
| 5439 | break; |
| 5440 | |
| 5441 | case NOTIFY_ACK_TYPE: |
| 5442 | if (tgt->notify_ack_expected > 0) { |
| 5443 | struct nack_to_isp *entry = (struct nack_to_isp *)pkt; |
| 5444 | ql_dbg(ql_dbg_tgt, vha, 0xe036, |
| 5445 | "NOTIFY_ACK seq %08x status %x\n", |
| 5446 | le16_to_cpu(entry->u.isp2x.seq_id), |
| 5447 | le16_to_cpu(entry->u.isp2x.status)); |
| 5448 | tgt->notify_ack_expected--; |
| 5449 | if (entry->u.isp2x.status != |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5450 | cpu_to_le16(NOTIFY_ACK_SUCCESS)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5451 | ql_dbg(ql_dbg_tgt, vha, 0xe061, |
| 5452 | "qla_target(%d): NOTIFY_ACK " |
| 5453 | "failed %x\n", vha->vp_idx, |
| 5454 | le16_to_cpu(entry->u.isp2x.status)); |
| 5455 | } |
| 5456 | } else { |
| 5457 | ql_dbg(ql_dbg_tgt, vha, 0xe062, |
| 5458 | "qla_target(%d): Unexpected NOTIFY_ACK received\n", |
| 5459 | vha->vp_idx); |
| 5460 | } |
| 5461 | break; |
| 5462 | |
| 5463 | case ABTS_RECV_24XX: |
| 5464 | ql_dbg(ql_dbg_tgt, vha, 0xe037, |
| 5465 | "ABTS_RECV_24XX: instance %d\n", vha->vp_idx); |
| 5466 | qlt_24xx_handle_abts(vha, (struct abts_recv_from_24xx *)pkt); |
| 5467 | break; |
| 5468 | |
| 5469 | case ABTS_RESP_24XX: |
| 5470 | if (tgt->abts_resp_expected > 0) { |
| 5471 | struct abts_resp_from_24xx_fw *entry = |
| 5472 | (struct abts_resp_from_24xx_fw *)pkt; |
| 5473 | ql_dbg(ql_dbg_tgt, vha, 0xe038, |
| 5474 | "ABTS_RESP_24XX: compl_status %x\n", |
| 5475 | entry->compl_status); |
| 5476 | tgt->abts_resp_expected--; |
| 5477 | if (le16_to_cpu(entry->compl_status) != |
| 5478 | ABTS_RESP_COMPL_SUCCESS) { |
| 5479 | if ((entry->error_subcode1 == 0x1E) && |
| 5480 | (entry->error_subcode2 == 0)) { |
| 5481 | /* |
| 5482 | * We've got a race here: aborted |
| 5483 | * exchange not terminated, i.e. |
| 5484 | * response for the aborted command was |
| 5485 | * sent between the abort request was |
| 5486 | * received and processed. |
| 5487 | * Unfortunately, the firmware has a |
| 5488 | * silly requirement that all aborted |
| 5489 | * exchanges must be explicitely |
| 5490 | * terminated, otherwise it refuses to |
| 5491 | * send responses for the abort |
| 5492 | * requests. So, we have to |
| 5493 | * (re)terminate the exchange and retry |
| 5494 | * the abort response. |
| 5495 | */ |
| 5496 | qlt_24xx_retry_term_exchange(vha, |
| 5497 | entry); |
| 5498 | } else |
| 5499 | ql_dbg(ql_dbg_tgt, vha, 0xe063, |
| 5500 | "qla_target(%d): ABTS_RESP_24XX " |
| 5501 | "failed %x (subcode %x:%x)", |
| 5502 | vha->vp_idx, entry->compl_status, |
| 5503 | entry->error_subcode1, |
| 5504 | entry->error_subcode2); |
| 5505 | } |
| 5506 | } else { |
| 5507 | ql_dbg(ql_dbg_tgt, vha, 0xe064, |
| 5508 | "qla_target(%d): Unexpected ABTS_RESP_24XX " |
| 5509 | "received\n", vha->vp_idx); |
| 5510 | } |
| 5511 | break; |
| 5512 | |
| 5513 | default: |
| 5514 | ql_dbg(ql_dbg_tgt, vha, 0xe065, |
| 5515 | "qla_target(%d): Received unknown response pkt " |
| 5516 | "type %x\n", vha->vp_idx, pkt->entry_type); |
| 5517 | break; |
| 5518 | } |
| 5519 | |
| 5520 | tgt->irq_cmd_count--; |
| 5521 | } |
| 5522 | |
| 5523 | /* |
| 5524 | * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire |
| 5525 | */ |
| 5526 | void qlt_async_event(uint16_t code, struct scsi_qla_host *vha, |
| 5527 | uint16_t *mailbox) |
| 5528 | { |
| 5529 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5530 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5531 | int login_code; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5532 | |
Quinn Tran | 3a33dc9 | 2017-06-02 09:12:04 -0700 | [diff] [blame] | 5533 | if (!tgt || tgt->tgt_stop || tgt->tgt_stopped) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5534 | return; |
| 5535 | |
| 5536 | if (unlikely(tgt == NULL)) { |
| 5537 | ql_dbg(ql_dbg_tgt, vha, 0xe03a, |
| 5538 | "ASYNC EVENT %#x, but no tgt (ha %p)\n", code, ha); |
| 5539 | return; |
| 5540 | } |
| 5541 | |
| 5542 | if (((code == MBA_POINT_TO_POINT) || (code == MBA_CHG_IN_CONNECTION)) && |
| 5543 | IS_QLA2100(ha)) |
| 5544 | return; |
| 5545 | /* |
| 5546 | * In tgt_stop mode we also should allow all requests to pass. |
| 5547 | * Otherwise, some commands can stuck. |
| 5548 | */ |
| 5549 | |
| 5550 | tgt->irq_cmd_count++; |
| 5551 | |
| 5552 | switch (code) { |
| 5553 | case MBA_RESET: /* Reset */ |
| 5554 | case MBA_SYSTEM_ERR: /* System Error */ |
| 5555 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ |
| 5556 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ |
| 5557 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03a, |
| 5558 | "qla_target(%d): System error async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5559 | "occurred", vha->vp_idx, code); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5560 | break; |
| 5561 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up. */ |
| 5562 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 5563 | break; |
| 5564 | |
| 5565 | case MBA_LOOP_UP: |
| 5566 | { |
| 5567 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03b, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5568 | "qla_target(%d): Async LOOP_UP occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5569 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, |
| 5570 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5571 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5572 | if (tgt->link_reinit_iocb_pending) { |
| 5573 | qlt_send_notify_ack(vha, (void *)&tgt->link_reinit_iocb, |
| 5574 | 0, 0, 0, 0, 0, 0); |
| 5575 | tgt->link_reinit_iocb_pending = 0; |
| 5576 | } |
| 5577 | break; |
| 5578 | } |
| 5579 | |
| 5580 | case MBA_LIP_OCCURRED: |
| 5581 | case MBA_LOOP_DOWN: |
| 5582 | case MBA_LIP_RESET: |
| 5583 | case MBA_RSCN_UPDATE: |
| 5584 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03c, |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5585 | "qla_target(%d): Async event %#x occurred " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5586 | "(m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5587 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5588 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5589 | break; |
| 5590 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5591 | case MBA_REJECTED_FCP_CMD: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5592 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf017, |
| 5593 | "qla_target(%d): Async event LS_REJECT occurred (m[0]=%x, m[1]=%x, m[2]=%x, m[3]=%x)", |
| 5594 | vha->vp_idx, |
| 5595 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5596 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5597 | |
| 5598 | if (le16_to_cpu(mailbox[3]) == 1) { |
| 5599 | /* exchange starvation. */ |
| 5600 | vha->hw->exch_starvation++; |
| 5601 | if (vha->hw->exch_starvation > 5) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5602 | ql_log(ql_log_warn, vha, 0xd03a, |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5603 | "Exchange starvation-. Resetting RISC\n"); |
| 5604 | |
| 5605 | vha->hw->exch_starvation = 0; |
| 5606 | if (IS_P3P_TYPE(vha->hw)) |
| 5607 | set_bit(FCOE_CTX_RESET_NEEDED, |
| 5608 | &vha->dpc_flags); |
| 5609 | else |
| 5610 | set_bit(ISP_ABORT_NEEDED, |
| 5611 | &vha->dpc_flags); |
| 5612 | qla2xxx_wake_dpc(vha); |
| 5613 | } |
| 5614 | } |
| 5615 | break; |
| 5616 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5617 | case MBA_PORT_UPDATE: |
| 5618 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03d, |
| 5619 | "qla_target(%d): Port update async event %#x " |
Masanari Iida | 6efb3c0a | 2012-10-26 22:10:54 +0900 | [diff] [blame] | 5620 | "occurred: updating the ports database (m[0]=%x, m[1]=%x, " |
Alan Cox | 4f1d0f1 | 2012-07-04 16:35:35 +0100 | [diff] [blame] | 5621 | "m[2]=%x, m[3]=%x)", vha->vp_idx, code, |
| 5622 | le16_to_cpu(mailbox[0]), le16_to_cpu(mailbox[1]), |
| 5623 | le16_to_cpu(mailbox[2]), le16_to_cpu(mailbox[3])); |
| 5624 | |
| 5625 | login_code = le16_to_cpu(mailbox[2]); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5626 | if (login_code == 0x4) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5627 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03e, |
| 5628 | "Async MB 2: Got PLOGI Complete\n"); |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 5629 | vha->hw->exch_starvation = 0; |
| 5630 | } else if (login_code == 0x7) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5631 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf03f, |
| 5632 | "Async MB 2: Port Logged Out\n"); |
| 5633 | break; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5634 | default: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5635 | break; |
| 5636 | } |
| 5637 | |
| 5638 | tgt->irq_cmd_count--; |
| 5639 | } |
| 5640 | |
| 5641 | static fc_port_t *qlt_get_port_database(struct scsi_qla_host *vha, |
| 5642 | uint16_t loop_id) |
| 5643 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5644 | fc_port_t *fcport, *tfcp, *del; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5645 | int rc; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5646 | unsigned long flags; |
| 5647 | u8 newfcport = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5648 | |
| 5649 | fcport = kzalloc(sizeof(*fcport), GFP_KERNEL); |
| 5650 | if (!fcport) { |
| 5651 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06f, |
| 5652 | "qla_target(%d): Allocation of tmp FC port failed", |
| 5653 | vha->vp_idx); |
| 5654 | return NULL; |
| 5655 | } |
| 5656 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5657 | fcport->loop_id = loop_id; |
| 5658 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 5659 | rc = qla24xx_gpdb_wait(vha, fcport, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5660 | if (rc != QLA_SUCCESS) { |
| 5661 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf070, |
| 5662 | "qla_target(%d): Failed to retrieve fcport " |
| 5663 | "information -- get_port_database() returned %x " |
| 5664 | "(loop_id=0x%04x)", vha->vp_idx, rc, loop_id); |
| 5665 | kfree(fcport); |
| 5666 | return NULL; |
| 5667 | } |
| 5668 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5669 | del = NULL; |
| 5670 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5671 | tfcp = qla2x00_find_fcport_by_wwpn(vha, fcport->port_name, 1); |
| 5672 | |
| 5673 | if (tfcp) { |
| 5674 | tfcp->d_id = fcport->d_id; |
| 5675 | tfcp->port_type = fcport->port_type; |
| 5676 | tfcp->supported_classes = fcport->supported_classes; |
| 5677 | tfcp->flags |= fcport->flags; |
| 5678 | |
| 5679 | del = fcport; |
| 5680 | fcport = tfcp; |
| 5681 | } else { |
| 5682 | if (vha->hw->current_topology == ISP_CFG_F) |
| 5683 | fcport->flags |= FCF_FABRIC_DEVICE; |
| 5684 | |
| 5685 | list_add_tail(&fcport->list, &vha->vp_fcports); |
| 5686 | if (!IS_SW_RESV_ADDR(fcport->d_id)) |
| 5687 | vha->fcport_count++; |
| 5688 | fcport->login_gen++; |
| 5689 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 5690 | fcport->login_succ = 1; |
| 5691 | newfcport = 1; |
| 5692 | } |
| 5693 | |
| 5694 | fcport->deleted = 0; |
| 5695 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5696 | |
| 5697 | switch (vha->host->active_mode) { |
| 5698 | case MODE_INITIATOR: |
| 5699 | case MODE_DUAL: |
| 5700 | if (newfcport) { |
| 5701 | if (!IS_IIDMA_CAPABLE(vha->hw) || !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5702 | ql_dbg(ql_dbg_disc, vha, 0x20fe, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5703 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 5704 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5705 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 5706 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5707 | ql_dbg(ql_dbg_disc, vha, 0x20ff, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5708 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 5709 | __func__, __LINE__, fcport->port_name, vha->fcport_count); |
| 5710 | qla24xx_post_gpsc_work(vha, fcport); |
| 5711 | } |
| 5712 | } |
| 5713 | break; |
| 5714 | |
| 5715 | case MODE_TARGET: |
| 5716 | default: |
| 5717 | break; |
| 5718 | } |
| 5719 | if (del) |
| 5720 | qla2x00_free_fcport(del); |
| 5721 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5722 | return fcport; |
| 5723 | } |
| 5724 | |
| 5725 | /* Must be called under tgt_mutex */ |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5726 | 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] | 5727 | uint8_t *s_id) |
| 5728 | { |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5729 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5730 | fc_port_t *fcport = NULL; |
| 5731 | int rc, global_resets; |
| 5732 | uint16_t loop_id = 0; |
| 5733 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5734 | if ((s_id[0] == 0xFF) && (s_id[1] == 0xFC)) { |
| 5735 | /* |
| 5736 | * This is Domain Controller, so it should be |
| 5737 | * OK to drop SCSI commands from it. |
| 5738 | */ |
| 5739 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf042, |
| 5740 | "Unable to find initiator with S_ID %x:%x:%x", |
| 5741 | s_id[0], s_id[1], s_id[2]); |
| 5742 | return NULL; |
| 5743 | } |
| 5744 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5745 | mutex_lock(&vha->vha_tgt.tgt_mutex); |
| 5746 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5747 | retry: |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5748 | global_resets = |
| 5749 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5750 | |
| 5751 | rc = qla24xx_get_loop_id(vha, s_id, &loop_id); |
| 5752 | if (rc != 0) { |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5753 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5754 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5755 | ql_log(ql_log_info, vha, 0xf071, |
| 5756 | "qla_target(%d): Unable to find " |
| 5757 | "initiator with S_ID %x:%x:%x", |
| 5758 | vha->vp_idx, s_id[0], s_id[1], |
| 5759 | s_id[2]); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5760 | |
| 5761 | if (rc == -ENOENT) { |
| 5762 | qlt_port_logo_t logo; |
| 5763 | sid_to_portid(s_id, &logo.id); |
| 5764 | logo.cmd_count = 1; |
| 5765 | qlt_send_first_logo(vha, &logo); |
| 5766 | } |
| 5767 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5768 | return NULL; |
| 5769 | } |
| 5770 | |
| 5771 | fcport = qlt_get_port_database(vha, loop_id); |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5772 | if (!fcport) { |
| 5773 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5774 | return NULL; |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5775 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5776 | |
| 5777 | if (global_resets != |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5778 | atomic_read(&vha->vha_tgt.qla_tgt->tgt_global_resets_count)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5779 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf043, |
| 5780 | "qla_target(%d): global reset during session discovery " |
| 5781 | "(counter was %d, new %d), retrying", vha->vp_idx, |
| 5782 | global_resets, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5783 | atomic_read(&vha->vha_tgt. |
| 5784 | qla_tgt->tgt_global_resets_count)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5785 | goto retry; |
| 5786 | } |
| 5787 | |
| 5788 | sess = qlt_create_sess(vha, fcport, true); |
| 5789 | |
Alexei Potashnik | 71cdc07 | 2015-12-17 14:57:01 -0500 | [diff] [blame] | 5790 | mutex_unlock(&vha->vha_tgt.tgt_mutex); |
| 5791 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5792 | return sess; |
| 5793 | } |
| 5794 | |
| 5795 | static void qlt_abort_work(struct qla_tgt *tgt, |
| 5796 | struct qla_tgt_sess_work_param *prm) |
| 5797 | { |
| 5798 | struct scsi_qla_host *vha = tgt->vha; |
| 5799 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5800 | struct fc_port *sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5801 | unsigned long flags = 0, flags2 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5802 | uint32_t be_s_id; |
| 5803 | uint8_t s_id[3]; |
| 5804 | int rc; |
| 5805 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5806 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5807 | |
| 5808 | if (tgt->tgt_stop) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5809 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5810 | |
| 5811 | s_id[0] = prm->abts.fcp_hdr_le.s_id[2]; |
| 5812 | s_id[1] = prm->abts.fcp_hdr_le.s_id[1]; |
| 5813 | s_id[2] = prm->abts.fcp_hdr_le.s_id[0]; |
| 5814 | |
| 5815 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, |
| 5816 | (unsigned char *)&be_s_id); |
| 5817 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5818 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5819 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5820 | sess = qlt_make_local_sess(vha, s_id); |
| 5821 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5822 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5823 | spin_lock_irqsave(&ha->tgt.sess_lock, flags2); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5824 | if (!sess) |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5825 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5826 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5827 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5828 | sess = NULL; |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5829 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5830 | } |
| 5831 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5832 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5833 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf01c, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5834 | "%s: kref_get fail %8phC \n", |
| 5835 | __func__, sess->port_name); |
| 5836 | sess = NULL; |
| 5837 | goto out_term2; |
| 5838 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5839 | } |
| 5840 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5841 | rc = __qlt_24xx_handle_abts(vha, &prm->abts, sess); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5842 | ha->tgt.tgt_ops->put_sess(sess); |
| 5843 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
| 5844 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5845 | if (rc != 0) |
| 5846 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5847 | return; |
| 5848 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5849 | out_term2: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5850 | if (sess) |
| 5851 | ha->tgt.tgt_ops->put_sess(sess); |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5852 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags2); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5853 | |
| 5854 | out_term: |
| 5855 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5856 | qlt_24xx_send_abts_resp(vha, &prm->abts, FCP_TMF_REJECTED, false); |
| 5857 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5858 | } |
| 5859 | |
| 5860 | static void qlt_tmr_work(struct qla_tgt *tgt, |
| 5861 | struct qla_tgt_sess_work_param *prm) |
| 5862 | { |
| 5863 | struct atio_from_isp *a = &prm->tm_iocb2; |
| 5864 | struct scsi_qla_host *vha = tgt->vha; |
| 5865 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 5866 | struct fc_port *sess = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5867 | unsigned long flags; |
| 5868 | uint8_t *s_id = NULL; /* to hide compiler warnings */ |
| 5869 | int rc; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 5870 | u64 unpacked_lun; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 5871 | int fn; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5872 | void *iocb; |
| 5873 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5874 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5875 | |
| 5876 | if (tgt->tgt_stop) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5877 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5878 | |
| 5879 | s_id = prm->tm_iocb2.u.isp24.fcp_hdr.s_id; |
| 5880 | sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); |
| 5881 | if (!sess) { |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5882 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5883 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5884 | sess = qlt_make_local_sess(vha, s_id); |
| 5885 | /* sess has got an extra creation ref */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5886 | |
Quinn Tran | 7560151 | 2015-12-17 14:57:04 -0500 | [diff] [blame] | 5887 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5888 | if (!sess) |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5889 | goto out_term2; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5890 | } else { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5891 | if (sess->deleted) { |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5892 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5893 | goto out_term2; |
Alexei Potashnik | e52a8b4 | 2015-07-14 16:00:48 -0400 | [diff] [blame] | 5894 | } |
| 5895 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5896 | if (!kref_get_unless_zero(&sess->sess_kref)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5897 | ql_dbg(ql_dbg_tgt_tmr, vha, 0xf020, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5898 | "%s: kref_get fail %8phC\n", |
| 5899 | __func__, sess->port_name); |
| 5900 | sess = NULL; |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5901 | goto out_term2; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5902 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | iocb = a; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5906 | fn = a->u.isp24.fcp_cmnd.task_mgmt_flags; |
Quinn Tran | f775bd1 | 2017-06-02 09:11:59 -0700 | [diff] [blame] | 5907 | unpacked_lun = |
| 5908 | scsilun_to_int((struct scsi_lun *)&a->u.isp24.fcp_cmnd.lun); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5909 | |
| 5910 | rc = qlt_issue_task_mgmt(sess, unpacked_lun, fn, iocb, 0); |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5911 | ha->tgt.tgt_ops->put_sess(sess); |
| 5912 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
| 5913 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5914 | if (rc != 0) |
| 5915 | goto out_term; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5916 | return; |
| 5917 | |
Quinn Tran | f159b3c | 2017-03-15 09:48:47 -0700 | [diff] [blame] | 5918 | out_term2: |
| 5919 | if (sess) |
| 5920 | ha->tgt.tgt_ops->put_sess(sess); |
| 5921 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5922 | out_term: |
Quinn Tran | a07100e | 2015-12-07 19:48:57 -0500 | [diff] [blame] | 5923 | qlt_send_term_exchange(vha, NULL, &prm->tm_iocb2, 1, 0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | static void qlt_sess_work_fn(struct work_struct *work) |
| 5927 | { |
| 5928 | struct qla_tgt *tgt = container_of(work, struct qla_tgt, sess_work); |
| 5929 | struct scsi_qla_host *vha = tgt->vha; |
| 5930 | unsigned long flags; |
| 5931 | |
| 5932 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf000, "Sess work (tgt %p)", tgt); |
| 5933 | |
| 5934 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 5935 | while (!list_empty(&tgt->sess_works_list)) { |
| 5936 | struct qla_tgt_sess_work_param *prm = list_entry( |
| 5937 | tgt->sess_works_list.next, typeof(*prm), |
| 5938 | sess_works_list_entry); |
| 5939 | |
| 5940 | /* |
| 5941 | * This work can be scheduled on several CPUs at time, so we |
| 5942 | * must delete the entry to eliminate double processing |
| 5943 | */ |
| 5944 | list_del(&prm->sess_works_list_entry); |
| 5945 | |
| 5946 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 5947 | |
| 5948 | switch (prm->type) { |
| 5949 | case QLA_TGT_SESS_WORK_ABORT: |
| 5950 | qlt_abort_work(tgt, prm); |
| 5951 | break; |
| 5952 | case QLA_TGT_SESS_WORK_TM: |
| 5953 | qlt_tmr_work(tgt, prm); |
| 5954 | break; |
| 5955 | default: |
| 5956 | BUG_ON(1); |
| 5957 | break; |
| 5958 | } |
| 5959 | |
| 5960 | spin_lock_irqsave(&tgt->sess_work_lock, flags); |
| 5961 | |
| 5962 | kfree(prm); |
| 5963 | } |
| 5964 | spin_unlock_irqrestore(&tgt->sess_work_lock, flags); |
| 5965 | } |
| 5966 | |
| 5967 | /* Must be called under tgt_host_action_mutex */ |
| 5968 | int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha) |
| 5969 | { |
| 5970 | struct qla_tgt *tgt; |
| 5971 | |
| 5972 | if (!QLA_TGT_MODE_ENABLED()) |
| 5973 | return 0; |
| 5974 | |
Arun Easi | 33c36c0 | 2013-01-30 03:34:41 -0500 | [diff] [blame] | 5975 | if (!IS_TGT_MODE_CAPABLE(ha)) { |
| 5976 | ql_log(ql_log_warn, base_vha, 0xe070, |
| 5977 | "This adapter does not support target mode.\n"); |
| 5978 | return 0; |
| 5979 | } |
| 5980 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5981 | ql_dbg(ql_dbg_tgt, base_vha, 0xe03b, |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5982 | "Registering target for host %ld(%p).\n", base_vha->host_no, ha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5983 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 5984 | BUG_ON(base_vha->vha_tgt.qla_tgt != NULL); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5985 | |
| 5986 | tgt = kzalloc(sizeof(struct qla_tgt), GFP_KERNEL); |
| 5987 | if (!tgt) { |
| 5988 | ql_dbg(ql_dbg_tgt, base_vha, 0xe066, |
| 5989 | "Unable to allocate struct qla_tgt\n"); |
| 5990 | return -ENOMEM; |
| 5991 | } |
| 5992 | |
| 5993 | if (!(base_vha->host->hostt->supported_mode & MODE_TARGET)) |
| 5994 | base_vha->host->hostt->supported_mode |= MODE_TARGET; |
| 5995 | |
| 5996 | tgt->ha = ha; |
| 5997 | tgt->vha = base_vha; |
| 5998 | init_waitqueue_head(&tgt->waitQ); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5999 | INIT_LIST_HEAD(&tgt->del_sess_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6000 | spin_lock_init(&tgt->sess_work_lock); |
| 6001 | INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); |
| 6002 | INIT_LIST_HEAD(&tgt->sess_works_list); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6003 | atomic_set(&tgt->tgt_global_resets_count, 0); |
| 6004 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6005 | base_vha->vha_tgt.qla_tgt = tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6006 | |
| 6007 | ql_dbg(ql_dbg_tgt, base_vha, 0xe067, |
| 6008 | "qla_target(%d): using 64 Bit PCI addressing", |
| 6009 | base_vha->vp_idx); |
| 6010 | tgt->tgt_enable_64bit_addr = 1; |
| 6011 | /* 3 is reserved */ |
| 6012 | tgt->sg_tablesize = QLA_TGT_MAX_SG_24XX(base_vha->req->length - 3); |
| 6013 | tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX; |
| 6014 | tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX; |
| 6015 | |
| 6016 | mutex_lock(&qla_tgt_mutex); |
| 6017 | list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); |
| 6018 | mutex_unlock(&qla_tgt_mutex); |
| 6019 | |
Quinn Tran | f1443ee | 2017-03-15 09:48:51 -0700 | [diff] [blame] | 6020 | if (ha->tgt.tgt_ops && ha->tgt.tgt_ops->add_target) |
| 6021 | ha->tgt.tgt_ops->add_target(base_vha); |
| 6022 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6023 | return 0; |
| 6024 | } |
| 6025 | |
| 6026 | /* Must be called under tgt_host_action_mutex */ |
| 6027 | int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha) |
| 6028 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6029 | if (!vha->vha_tgt.qla_tgt) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6030 | return 0; |
| 6031 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6032 | if (vha->fc_vport) { |
| 6033 | qlt_release(vha->vha_tgt.qla_tgt); |
| 6034 | return 0; |
| 6035 | } |
Quinn Tran | 33e7997 | 2014-09-25 06:14:55 -0400 | [diff] [blame] | 6036 | |
| 6037 | /* free left over qfull cmds */ |
| 6038 | qlt_init_term_exchange(vha); |
| 6039 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6040 | mutex_lock(&qla_tgt_mutex); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6041 | list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6042 | mutex_unlock(&qla_tgt_mutex); |
| 6043 | |
| 6044 | ql_dbg(ql_dbg_tgt, vha, 0xe03c, "Unregistering target for host %ld(%p)", |
| 6045 | vha->host_no, ha); |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6046 | qlt_release(vha->vha_tgt.qla_tgt); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6047 | |
| 6048 | return 0; |
| 6049 | } |
| 6050 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6051 | void qlt_remove_target_resources(struct qla_hw_data *ha) |
| 6052 | { |
| 6053 | struct scsi_qla_host *node; |
| 6054 | u32 key = 0; |
| 6055 | |
| 6056 | btree_for_each_safe32(&ha->tgt.host_map, key, node) |
| 6057 | btree_remove32(&ha->tgt.host_map, key); |
| 6058 | |
| 6059 | btree_destroy32(&ha->tgt.host_map); |
| 6060 | } |
| 6061 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6062 | static void qlt_lport_dump(struct scsi_qla_host *vha, u64 wwpn, |
| 6063 | unsigned char *b) |
| 6064 | { |
| 6065 | int i; |
| 6066 | |
| 6067 | pr_debug("qla2xxx HW vha->node_name: "); |
| 6068 | for (i = 0; i < WWN_SIZE; i++) |
| 6069 | pr_debug("%02x ", vha->node_name[i]); |
| 6070 | pr_debug("\n"); |
| 6071 | pr_debug("qla2xxx HW vha->port_name: "); |
| 6072 | for (i = 0; i < WWN_SIZE; i++) |
| 6073 | pr_debug("%02x ", vha->port_name[i]); |
| 6074 | pr_debug("\n"); |
| 6075 | |
| 6076 | pr_debug("qla2xxx passed configfs WWPN: "); |
| 6077 | put_unaligned_be64(wwpn, b); |
| 6078 | for (i = 0; i < WWN_SIZE; i++) |
| 6079 | pr_debug("%02x ", b[i]); |
| 6080 | pr_debug("\n"); |
| 6081 | } |
| 6082 | |
| 6083 | /** |
| 6084 | * qla_tgt_lport_register - register lport with external module |
| 6085 | * |
| 6086 | * @qla_tgt_ops: Pointer for tcm_qla2xxx qla_tgt_ops |
| 6087 | * @wwpn: Passwd FC target WWPN |
| 6088 | * @callback: lport initialization callback for tcm_qla2xxx code |
| 6089 | * @target_lport_ptr: pointer for tcm_qla2xxx specific lport data |
| 6090 | */ |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6091 | int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn, |
| 6092 | u64 npiv_wwpn, u64 npiv_wwnn, |
| 6093 | int (*callback)(struct scsi_qla_host *, void *, u64, u64)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6094 | { |
| 6095 | struct qla_tgt *tgt; |
| 6096 | struct scsi_qla_host *vha; |
| 6097 | struct qla_hw_data *ha; |
| 6098 | struct Scsi_Host *host; |
| 6099 | unsigned long flags; |
| 6100 | int rc; |
| 6101 | u8 b[WWN_SIZE]; |
| 6102 | |
| 6103 | mutex_lock(&qla_tgt_mutex); |
| 6104 | list_for_each_entry(tgt, &qla_tgt_glist, tgt_list_entry) { |
| 6105 | vha = tgt->vha; |
| 6106 | ha = vha->hw; |
| 6107 | |
| 6108 | host = vha->host; |
| 6109 | if (!host) |
| 6110 | continue; |
| 6111 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6112 | if (!(host->hostt->supported_mode & MODE_TARGET)) |
| 6113 | continue; |
| 6114 | |
| 6115 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6116 | if ((!npiv_wwpn || !npiv_wwnn) && host->active_mode & MODE_TARGET) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6117 | pr_debug("MODE_TARGET already active on qla2xxx(%d)\n", |
| 6118 | host->host_no); |
| 6119 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6120 | continue; |
| 6121 | } |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6122 | if (tgt->tgt_stop) { |
| 6123 | pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n", |
| 6124 | host->host_no); |
| 6125 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6126 | continue; |
| 6127 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6128 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6129 | |
| 6130 | if (!scsi_host_get(host)) { |
| 6131 | ql_dbg(ql_dbg_tgt, vha, 0xe068, |
| 6132 | "Unable to scsi_host_get() for" |
| 6133 | " qla2xxx scsi_host\n"); |
| 6134 | continue; |
| 6135 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6136 | qlt_lport_dump(vha, phys_wwpn, b); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6137 | |
| 6138 | if (memcmp(vha->port_name, b, WWN_SIZE)) { |
| 6139 | scsi_host_put(host); |
| 6140 | continue; |
| 6141 | } |
Nicholas Bellinger | 49a47f2 | 2014-01-14 20:38:58 -0800 | [diff] [blame] | 6142 | rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); |
| 6143 | if (rc != 0) |
| 6144 | scsi_host_put(host); |
| 6145 | |
Nicholas Bellinger | ddb9514 | 2014-02-19 17:51:25 -0800 | [diff] [blame] | 6146 | mutex_unlock(&qla_tgt_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6147 | return rc; |
| 6148 | } |
| 6149 | mutex_unlock(&qla_tgt_mutex); |
| 6150 | |
| 6151 | return -ENODEV; |
| 6152 | } |
| 6153 | EXPORT_SYMBOL(qlt_lport_register); |
| 6154 | |
| 6155 | /** |
| 6156 | * qla_tgt_lport_deregister - Degister lport |
| 6157 | * |
| 6158 | * @vha: Registered scsi_qla_host pointer |
| 6159 | */ |
| 6160 | void qlt_lport_deregister(struct scsi_qla_host *vha) |
| 6161 | { |
| 6162 | struct qla_hw_data *ha = vha->hw; |
| 6163 | struct Scsi_Host *sh = vha->host; |
| 6164 | /* |
| 6165 | * Clear the target_lport_ptr qla_target_template pointer in qla_hw_data |
| 6166 | */ |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6167 | vha->vha_tgt.target_lport_ptr = NULL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6168 | ha->tgt.tgt_ops = NULL; |
| 6169 | /* |
| 6170 | * Release the Scsi_Host reference for the underlying qla2xxx host |
| 6171 | */ |
| 6172 | scsi_host_put(sh); |
| 6173 | } |
| 6174 | EXPORT_SYMBOL(qlt_lport_deregister); |
| 6175 | |
| 6176 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6177 | static void qlt_set_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6178 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6179 | switch (ql2x_ini_mode) { |
| 6180 | case QLA2XXX_INI_MODE_DISABLED: |
| 6181 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6182 | vha->host->active_mode = MODE_TARGET; |
| 6183 | break; |
| 6184 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6185 | vha->host->active_mode = MODE_UNKNOWN; |
| 6186 | break; |
| 6187 | case QLA2XXX_INI_MODE_DUAL: |
| 6188 | vha->host->active_mode = MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6189 | break; |
| 6190 | default: |
| 6191 | break; |
| 6192 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | /* Must be called under HW lock */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6196 | static void qlt_clear_mode(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6197 | { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6198 | switch (ql2x_ini_mode) { |
| 6199 | case QLA2XXX_INI_MODE_DISABLED: |
| 6200 | vha->host->active_mode = MODE_UNKNOWN; |
| 6201 | break; |
| 6202 | case QLA2XXX_INI_MODE_EXCLUSIVE: |
| 6203 | vha->host->active_mode = MODE_INITIATOR; |
| 6204 | break; |
| 6205 | case QLA2XXX_INI_MODE_ENABLED: |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6206 | case QLA2XXX_INI_MODE_DUAL: |
| 6207 | vha->host->active_mode = MODE_INITIATOR; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6208 | break; |
| 6209 | default: |
| 6210 | break; |
| 6211 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6212 | } |
| 6213 | |
| 6214 | /* |
| 6215 | * qla_tgt_enable_vha - NO LOCK HELD |
| 6216 | * |
| 6217 | * host_reset, bring up w/ Target Mode Enabled |
| 6218 | */ |
| 6219 | void |
| 6220 | qlt_enable_vha(struct scsi_qla_host *vha) |
| 6221 | { |
| 6222 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6223 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6224 | unsigned long flags; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6225 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6226 | int rspq_ent = QLA83XX_RSPQ_MSIX_ENTRY_NUMBER; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6227 | |
| 6228 | if (!tgt) { |
| 6229 | ql_dbg(ql_dbg_tgt, vha, 0xe069, |
| 6230 | "Unable to locate qla_tgt pointer from" |
| 6231 | " struct qla_hw_data\n"); |
| 6232 | dump_stack(); |
| 6233 | return; |
| 6234 | } |
| 6235 | |
| 6236 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6237 | tgt->tgt_stopped = 0; |
| 6238 | qlt_set_mode(vha); |
| 6239 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6240 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6241 | if (vha->vp_idx) { |
| 6242 | qla24xx_disable_vp(vha); |
| 6243 | qla24xx_enable_vp(vha); |
| 6244 | } else { |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6245 | if (ha->msix_entries) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6246 | ql_dbg(ql_dbg_tgt, vha, 0xe081, |
Quinn Tran | cdb898c | 2015-12-17 14:57:05 -0500 | [diff] [blame] | 6247 | "%s: host%ld : vector %d cpu %d\n", |
| 6248 | __func__, vha->host_no, |
| 6249 | ha->msix_entries[rspq_ent].vector, |
| 6250 | ha->msix_entries[rspq_ent].cpuid); |
| 6251 | |
| 6252 | ha->tgt.rspq_vector_cpuid = |
| 6253 | ha->msix_entries[rspq_ent].cpuid; |
| 6254 | } |
| 6255 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6256 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 6257 | qla2xxx_wake_dpc(base_vha); |
| 6258 | qla2x00_wait_for_hba_online(base_vha); |
| 6259 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6260 | } |
| 6261 | EXPORT_SYMBOL(qlt_enable_vha); |
| 6262 | |
| 6263 | /* |
| 6264 | * qla_tgt_disable_vha - NO LOCK HELD |
| 6265 | * |
| 6266 | * Disable Target Mode and reset the adapter |
| 6267 | */ |
Joern Engel | 55a9066 | 2014-09-16 16:23:15 -0400 | [diff] [blame] | 6268 | static void qlt_disable_vha(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6269 | { |
| 6270 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6271 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6272 | unsigned long flags; |
| 6273 | |
| 6274 | if (!tgt) { |
| 6275 | ql_dbg(ql_dbg_tgt, vha, 0xe06a, |
| 6276 | "Unable to locate qla_tgt pointer from" |
| 6277 | " struct qla_hw_data\n"); |
| 6278 | dump_stack(); |
| 6279 | return; |
| 6280 | } |
| 6281 | |
| 6282 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6283 | qlt_clear_mode(vha); |
| 6284 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6285 | |
| 6286 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 6287 | qla2xxx_wake_dpc(vha); |
| 6288 | qla2x00_wait_for_hba_online(vha); |
| 6289 | } |
| 6290 | |
| 6291 | /* |
| 6292 | * Called from qla_init.c:qla24xx_vport_create() contex to setup |
| 6293 | * the target mode specific struct scsi_qla_host and struct qla_hw_data |
| 6294 | * members. |
| 6295 | */ |
| 6296 | void |
| 6297 | qlt_vport_create(struct scsi_qla_host *vha, struct qla_hw_data *ha) |
| 6298 | { |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6299 | vha->vha_tgt.qla_tgt = NULL; |
| 6300 | |
| 6301 | mutex_init(&vha->vha_tgt.tgt_mutex); |
| 6302 | mutex_init(&vha->vha_tgt.tgt_host_action_mutex); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6303 | |
| 6304 | qlt_clear_mode(vha); |
| 6305 | |
| 6306 | /* |
| 6307 | * NOTE: Currently the value is kept the same for <24xx and |
| 6308 | * >=24xx ISPs. If it is necessary to change it, |
| 6309 | * the check should be added for specific ISPs, |
| 6310 | * assigning the value appropriately. |
| 6311 | */ |
| 6312 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6313 | |
| 6314 | qlt_add_target(ha, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6315 | } |
| 6316 | |
| 6317 | void |
| 6318 | qlt_rff_id(struct scsi_qla_host *vha, struct ct_sns_req *ct_req) |
| 6319 | { |
| 6320 | /* |
| 6321 | * FC-4 Feature bit 0 indicates target functionality to the name server. |
| 6322 | */ |
| 6323 | if (qla_tgt_mode_enabled(vha)) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6324 | ct_req->req.rff_id.fc4_feature = BIT_0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6325 | } else if (qla_ini_mode_enabled(vha)) { |
| 6326 | ct_req->req.rff_id.fc4_feature = BIT_1; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6327 | } else if (qla_dual_mode_enabled(vha)) |
| 6328 | ct_req->req.rff_id.fc4_feature = BIT_0 | BIT_1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | /* |
| 6332 | * qlt_init_atio_q_entries() - Initializes ATIO queue entries. |
| 6333 | * @ha: HA context |
| 6334 | * |
| 6335 | * Beginning of ATIO ring has initialization control block already built |
| 6336 | * by nvram config routine. |
| 6337 | * |
| 6338 | * Returns 0 on success. |
| 6339 | */ |
| 6340 | void |
| 6341 | qlt_init_atio_q_entries(struct scsi_qla_host *vha) |
| 6342 | { |
| 6343 | struct qla_hw_data *ha = vha->hw; |
| 6344 | uint16_t cnt; |
| 6345 | struct atio_from_isp *pkt = (struct atio_from_isp *)ha->tgt.atio_ring; |
| 6346 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6347 | if (qla_ini_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6348 | return; |
| 6349 | |
| 6350 | for (cnt = 0; cnt < ha->tgt.atio_q_length; cnt++) { |
| 6351 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6352 | pkt++; |
| 6353 | } |
| 6354 | |
| 6355 | } |
| 6356 | |
| 6357 | /* |
| 6358 | * qlt_24xx_process_atio_queue() - Process ATIO queue entries. |
| 6359 | * @ha: SCSI driver HA context |
| 6360 | */ |
| 6361 | void |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6362 | 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] | 6363 | { |
| 6364 | struct qla_hw_data *ha = vha->hw; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6365 | struct atio_from_isp *pkt; |
| 6366 | int cnt, i; |
| 6367 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6368 | if (!ha->flags.fw_started) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6369 | return; |
| 6370 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6371 | while ((ha->tgt.atio_ring_ptr->signature != ATIO_PROCESSED) || |
| 6372 | fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6373 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6374 | cnt = pkt->u.raw.entry_count; |
| 6375 | |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6376 | if (unlikely(fcpcmd_is_corrupted(ha->tgt.atio_ring_ptr))) { |
| 6377 | /* |
| 6378 | * This packet is corrupted. The header + payload |
| 6379 | * can not be trusted. There is no point in passing |
| 6380 | * it further up. |
| 6381 | */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6382 | ql_log(ql_log_warn, vha, 0xd03c, |
Quinn Tran | 5f35509 | 2016-12-23 18:06:11 -0800 | [diff] [blame] | 6383 | "corrupted fcp frame SID[%3phN] OXID[%04x] EXCG[%x] %64phN\n", |
| 6384 | pkt->u.isp24.fcp_hdr.s_id, |
| 6385 | be16_to_cpu(pkt->u.isp24.fcp_hdr.ox_id), |
| 6386 | le32_to_cpu(pkt->u.isp24.exchange_addr), pkt); |
| 6387 | |
| 6388 | adjust_corrupted_atio(pkt); |
| 6389 | qlt_send_term_exchange(vha, NULL, pkt, ha_locked, 0); |
| 6390 | } else { |
| 6391 | qlt_24xx_atio_pkt_all_vps(vha, |
| 6392 | (struct atio_from_isp *)pkt, ha_locked); |
| 6393 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6394 | |
| 6395 | for (i = 0; i < cnt; i++) { |
| 6396 | ha->tgt.atio_ring_index++; |
| 6397 | if (ha->tgt.atio_ring_index == ha->tgt.atio_q_length) { |
| 6398 | ha->tgt.atio_ring_index = 0; |
| 6399 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 6400 | } else |
| 6401 | ha->tgt.atio_ring_ptr++; |
| 6402 | |
| 6403 | pkt->u.raw.signature = ATIO_PROCESSED; |
| 6404 | pkt = (struct atio_from_isp *)ha->tgt.atio_ring_ptr; |
| 6405 | } |
| 6406 | wmb(); |
| 6407 | } |
| 6408 | |
| 6409 | /* Adjust ring index */ |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6410 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), ha->tgt.atio_ring_index); |
Quinn Tran | 3761f3e | 2015-06-10 11:05:19 -0400 | [diff] [blame] | 6411 | RD_REG_DWORD_RELAXED(ISP_ATIO_Q_OUT(vha)); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6412 | } |
| 6413 | |
| 6414 | void |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6415 | qlt_24xx_config_rings(struct scsi_qla_host *vha) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6416 | { |
| 6417 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6418 | if (!QLA_TGT_MODE_ENABLED()) |
| 6419 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6420 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6421 | WRT_REG_DWORD(ISP_ATIO_Q_IN(vha), 0); |
| 6422 | WRT_REG_DWORD(ISP_ATIO_Q_OUT(vha), 0); |
| 6423 | RD_REG_DWORD(ISP_ATIO_Q_OUT(vha)); |
| 6424 | |
| 6425 | if (IS_ATIO_MSIX_CAPABLE(ha)) { |
| 6426 | struct qla_msix_entry *msix = &ha->msix_entries[2]; |
| 6427 | struct init_cb_24xx *icb = (struct init_cb_24xx *)ha->init_cb; |
| 6428 | |
| 6429 | icb->msix_atio = cpu_to_le16(msix->entry); |
| 6430 | ql_dbg(ql_dbg_init, vha, 0xf072, |
| 6431 | "Registering ICB vector 0x%x for atio que.\n", |
| 6432 | msix->entry); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6433 | } |
| 6434 | } |
| 6435 | |
| 6436 | void |
| 6437 | qlt_24xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_24xx *nv) |
| 6438 | { |
| 6439 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6440 | |
| 6441 | if (!QLA_TGT_MODE_ENABLED()) |
| 6442 | return; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6443 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6444 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6445 | if (!ha->tgt.saved_set) { |
| 6446 | /* We save only once */ |
| 6447 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6448 | ha->tgt.saved_firmware_options_1 = |
| 6449 | nv->firmware_options_1; |
| 6450 | ha->tgt.saved_firmware_options_2 = |
| 6451 | nv->firmware_options_2; |
| 6452 | ha->tgt.saved_firmware_options_3 = |
| 6453 | nv->firmware_options_3; |
| 6454 | ha->tgt.saved_set = 1; |
| 6455 | } |
| 6456 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6457 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6458 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6459 | else /* dual */ |
| 6460 | nv->exchange_count = cpu_to_le16(ql2xexchoffld); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6461 | |
| 6462 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6463 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6464 | |
| 6465 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6466 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6467 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6468 | |
| 6469 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6470 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6471 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6472 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6473 | if (ql2xtgt_tape_enable) |
| 6474 | /* Enable FC Tape support */ |
| 6475 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6476 | else |
| 6477 | /* Disable FC Tape support */ |
| 6478 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6479 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6480 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6481 | nv->host_p &= cpu_to_le32(~BIT_10); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6482 | |
| 6483 | /* |
| 6484 | * clear BIT 15 explicitly as we have seen at least |
| 6485 | * a couple of instances where this was set and this |
| 6486 | * was causing the firmware to not be initialized. |
| 6487 | */ |
| 6488 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6489 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6490 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6491 | } else { |
| 6492 | if (ha->tgt.saved_set) { |
| 6493 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6494 | nv->firmware_options_1 = |
| 6495 | ha->tgt.saved_firmware_options_1; |
| 6496 | nv->firmware_options_2 = |
| 6497 | ha->tgt.saved_firmware_options_2; |
| 6498 | nv->firmware_options_3 = |
| 6499 | ha->tgt.saved_firmware_options_3; |
| 6500 | } |
| 6501 | return; |
| 6502 | } |
| 6503 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6504 | if (ha->tgt.enable_class_2) { |
| 6505 | if (vha->flags.init_done) |
| 6506 | fc_host_supported_classes(vha->host) = |
| 6507 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6508 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6509 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6510 | } else { |
| 6511 | if (vha->flags.init_done) |
| 6512 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6513 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6514 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | void |
| 6519 | qlt_24xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6520 | struct init_cb_24xx *icb) |
| 6521 | { |
| 6522 | struct qla_hw_data *ha = vha->hw; |
| 6523 | |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6524 | if (!QLA_TGT_MODE_ENABLED()) |
| 6525 | return; |
| 6526 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6527 | if (ha->tgt.node_name_set) { |
| 6528 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6529 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6530 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6531 | |
| 6532 | /* disable ZIO at start time. */ |
| 6533 | if (!vha->flags.init_done) { |
| 6534 | uint32_t tmp; |
| 6535 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6536 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6537 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6538 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6539 | } |
| 6540 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6541 | void |
| 6542 | qlt_81xx_config_nvram_stage1(struct scsi_qla_host *vha, struct nvram_81xx *nv) |
| 6543 | { |
| 6544 | struct qla_hw_data *ha = vha->hw; |
| 6545 | |
| 6546 | if (!QLA_TGT_MODE_ENABLED()) |
| 6547 | return; |
| 6548 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6549 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6550 | if (!ha->tgt.saved_set) { |
| 6551 | /* We save only once */ |
| 6552 | ha->tgt.saved_exchange_count = nv->exchange_count; |
| 6553 | ha->tgt.saved_firmware_options_1 = |
| 6554 | nv->firmware_options_1; |
| 6555 | ha->tgt.saved_firmware_options_2 = |
| 6556 | nv->firmware_options_2; |
| 6557 | ha->tgt.saved_firmware_options_3 = |
| 6558 | nv->firmware_options_3; |
| 6559 | ha->tgt.saved_set = 1; |
| 6560 | } |
| 6561 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6562 | if (qla_tgt_mode_enabled(vha)) |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6563 | nv->exchange_count = cpu_to_le16(0xFFFF); |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 6564 | else /* dual */ |
| 6565 | nv->exchange_count = cpu_to_le16(ql2xexchoffld); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6566 | |
| 6567 | /* Enable target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6568 | nv->firmware_options_1 |= cpu_to_le32(BIT_4); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6569 | |
| 6570 | /* Disable ini mode, if requested */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6571 | if (qla_tgt_mode_enabled(vha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6572 | nv->firmware_options_1 |= cpu_to_le32(BIT_5); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6573 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6574 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6575 | /* Enable initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6576 | nv->firmware_options_1 &= cpu_to_le32(~BIT_9); |
Himanshu Madhani | c0f6462 | 2016-12-23 18:06:08 -0800 | [diff] [blame] | 6577 | /* |
| 6578 | * clear BIT 15 explicitly as we have seen at |
| 6579 | * least a couple of instances where this was set |
| 6580 | * and this was causing the firmware to not be |
| 6581 | * initialized. |
| 6582 | */ |
| 6583 | nv->firmware_options_1 &= cpu_to_le32(~BIT_15); |
Arun Easi | d154f35 | 2014-09-25 06:14:48 -0400 | [diff] [blame] | 6584 | if (ql2xtgt_tape_enable) |
| 6585 | /* Enable FC tape support */ |
| 6586 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6587 | else |
| 6588 | /* Disable FC tape support */ |
| 6589 | nv->firmware_options_2 &= cpu_to_le32(~BIT_12); |
| 6590 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6591 | /* Disable Full Login after LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6592 | nv->host_p &= cpu_to_le32(~BIT_10); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6593 | /* Enable target PRLI control */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6594 | nv->firmware_options_2 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6595 | } else { |
| 6596 | if (ha->tgt.saved_set) { |
| 6597 | nv->exchange_count = ha->tgt.saved_exchange_count; |
| 6598 | nv->firmware_options_1 = |
| 6599 | ha->tgt.saved_firmware_options_1; |
| 6600 | nv->firmware_options_2 = |
| 6601 | ha->tgt.saved_firmware_options_2; |
| 6602 | nv->firmware_options_3 = |
| 6603 | ha->tgt.saved_firmware_options_3; |
| 6604 | } |
| 6605 | return; |
| 6606 | } |
| 6607 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6608 | if (ha->tgt.enable_class_2) { |
| 6609 | if (vha->flags.init_done) |
| 6610 | fc_host_supported_classes(vha->host) = |
| 6611 | FC_COS_CLASS2 | FC_COS_CLASS3; |
| 6612 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6613 | nv->firmware_options_2 |= cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6614 | } else { |
| 6615 | if (vha->flags.init_done) |
| 6616 | fc_host_supported_classes(vha->host) = FC_COS_CLASS3; |
| 6617 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6618 | nv->firmware_options_2 &= ~cpu_to_le32(BIT_8); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | void |
| 6623 | qlt_81xx_config_nvram_stage2(struct scsi_qla_host *vha, |
| 6624 | struct init_cb_81xx *icb) |
| 6625 | { |
| 6626 | struct qla_hw_data *ha = vha->hw; |
| 6627 | |
| 6628 | if (!QLA_TGT_MODE_ENABLED()) |
| 6629 | return; |
| 6630 | |
| 6631 | if (ha->tgt.node_name_set) { |
| 6632 | memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6633 | icb->firmware_options_1 |= cpu_to_le32(BIT_14); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6634 | } |
Quinn Tran | 481ce73 | 2015-12-17 14:57:08 -0500 | [diff] [blame] | 6635 | |
| 6636 | /* disable ZIO at start time. */ |
| 6637 | if (!vha->flags.init_done) { |
| 6638 | uint32_t tmp; |
| 6639 | tmp = le32_to_cpu(icb->firmware_options_2); |
| 6640 | tmp &= ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6641 | icb->firmware_options_2 = cpu_to_le32(tmp); |
| 6642 | } |
| 6643 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6644 | } |
| 6645 | |
| 6646 | void |
| 6647 | qlt_83xx_iospace_config(struct qla_hw_data *ha) |
| 6648 | { |
| 6649 | if (!QLA_TGT_MODE_ENABLED()) |
| 6650 | return; |
| 6651 | |
| 6652 | ha->msix_count += 1; /* For ATIO Q */ |
| 6653 | } |
| 6654 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6655 | int |
| 6656 | qlt_24xx_process_response_error(struct scsi_qla_host *vha, |
| 6657 | struct sts_entry_24xx *pkt) |
| 6658 | { |
| 6659 | switch (pkt->entry_type) { |
| 6660 | case ABTS_RECV_24XX: |
| 6661 | case ABTS_RESP_24XX: |
| 6662 | case CTIO_TYPE7: |
| 6663 | case NOTIFY_ACK_TYPE: |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 6664 | case CTIO_CRC2: |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6665 | return 1; |
| 6666 | default: |
| 6667 | return 0; |
| 6668 | } |
| 6669 | } |
| 6670 | |
| 6671 | void |
| 6672 | qlt_modify_vp_config(struct scsi_qla_host *vha, |
| 6673 | struct vp_config_entry_24xx *vpmod) |
| 6674 | { |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6675 | /* enable target mode. Bit5 = 1 => disable */ |
| 6676 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6677 | vpmod->options_idx1 &= ~BIT_5; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6678 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6679 | /* Disable ini mode, if requested. bit4 = 1 => disable */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6680 | if (qla_tgt_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6681 | vpmod->options_idx1 &= ~BIT_4; |
| 6682 | } |
| 6683 | |
| 6684 | void |
| 6685 | qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha) |
| 6686 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6687 | int rc; |
| 6688 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6689 | if (!QLA_TGT_MODE_ENABLED()) |
| 6690 | return; |
| 6691 | |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 6692 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6693 | ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in; |
| 6694 | ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out; |
| 6695 | } else { |
| 6696 | ISP_ATIO_Q_IN(base_vha) = &ha->iobase->isp24.atio_q_in; |
| 6697 | ISP_ATIO_Q_OUT(base_vha) = &ha->iobase->isp24.atio_q_out; |
| 6698 | } |
| 6699 | |
Saurav Kashyap | 0e8cd71 | 2014-01-14 20:40:38 -0800 | [diff] [blame] | 6700 | mutex_init(&base_vha->vha_tgt.tgt_mutex); |
| 6701 | mutex_init(&base_vha->vha_tgt.tgt_host_action_mutex); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6702 | |
| 6703 | INIT_LIST_HEAD(&base_vha->unknown_atio_list); |
| 6704 | INIT_DELAYED_WORK(&base_vha->unknown_atio_work, |
| 6705 | qlt_unknown_atio_work_fn); |
| 6706 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6707 | qlt_clear_mode(base_vha); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6708 | |
| 6709 | rc = btree_init32(&ha->tgt.host_map); |
| 6710 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6711 | ql_log(ql_log_info, base_vha, 0xd03d, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6712 | "Unable to initialize ha->host_map btree\n"); |
| 6713 | |
| 6714 | qlt_update_vp_map(base_vha, SET_VP_IDX); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6715 | } |
| 6716 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6717 | irqreturn_t |
| 6718 | qla83xx_msix_atio_q(int irq, void *dev_id) |
| 6719 | { |
| 6720 | struct rsp_que *rsp; |
| 6721 | scsi_qla_host_t *vha; |
| 6722 | struct qla_hw_data *ha; |
| 6723 | unsigned long flags; |
| 6724 | |
| 6725 | rsp = (struct rsp_que *) dev_id; |
| 6726 | ha = rsp->hw; |
| 6727 | vha = pci_get_drvdata(ha->pdev); |
| 6728 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6729 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6730 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6731 | qlt_24xx_process_atio_queue(vha, 0); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6732 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6733 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6734 | |
| 6735 | return IRQ_HANDLED; |
| 6736 | } |
| 6737 | |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6738 | static void |
| 6739 | qlt_handle_abts_recv_work(struct work_struct *work) |
| 6740 | { |
| 6741 | struct qla_tgt_sess_op *op = container_of(work, |
| 6742 | struct qla_tgt_sess_op, work); |
| 6743 | scsi_qla_host_t *vha = op->vha; |
| 6744 | struct qla_hw_data *ha = vha->hw; |
| 6745 | unsigned long flags; |
| 6746 | |
| 6747 | if (qla2x00_reset_active(vha) || (op->chip_reset != ha->chip_reset)) |
| 6748 | return; |
| 6749 | |
| 6750 | spin_lock_irqsave(&ha->tgt.atio_lock, flags); |
| 6751 | qlt_24xx_process_atio_queue(vha, 0); |
| 6752 | spin_unlock_irqrestore(&ha->tgt.atio_lock, flags); |
| 6753 | |
| 6754 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6755 | qlt_response_pkt_all_vps(vha, (response_t *)&op->atio); |
| 6756 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Quinn Tran | ae940f2 | 2017-03-15 09:48:44 -0700 | [diff] [blame] | 6757 | |
| 6758 | kfree(op); |
Quinn Tran | 2f424b9 | 2015-12-17 14:57:07 -0500 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | void |
| 6762 | qlt_handle_abts_recv(struct scsi_qla_host *vha, response_t *pkt) |
| 6763 | { |
| 6764 | struct qla_tgt_sess_op *op; |
| 6765 | |
| 6766 | op = kzalloc(sizeof(*op), GFP_ATOMIC); |
| 6767 | |
| 6768 | if (!op) { |
| 6769 | /* do not reach for ATIO queue here. This is best effort err |
| 6770 | * recovery at this point. |
| 6771 | */ |
| 6772 | qlt_response_pkt_all_vps(vha, pkt); |
| 6773 | return; |
| 6774 | } |
| 6775 | |
| 6776 | memcpy(&op->atio, pkt, sizeof(*pkt)); |
| 6777 | op->vha = vha; |
| 6778 | op->chip_reset = vha->hw->chip_reset; |
| 6779 | INIT_WORK(&op->work, qlt_handle_abts_recv_work); |
| 6780 | queue_work(qla_tgt_wq, &op->work); |
| 6781 | return; |
| 6782 | } |
| 6783 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6784 | int |
| 6785 | qlt_mem_alloc(struct qla_hw_data *ha) |
| 6786 | { |
| 6787 | if (!QLA_TGT_MODE_ENABLED()) |
| 6788 | return 0; |
| 6789 | |
| 6790 | ha->tgt.tgt_vp_map = kzalloc(sizeof(struct qla_tgt_vp_map) * |
| 6791 | MAX_MULTI_ID_FABRIC, GFP_KERNEL); |
| 6792 | if (!ha->tgt.tgt_vp_map) |
| 6793 | return -ENOMEM; |
| 6794 | |
| 6795 | ha->tgt.atio_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 6796 | (ha->tgt.atio_q_length + 1) * sizeof(struct atio_from_isp), |
| 6797 | &ha->tgt.atio_dma, GFP_KERNEL); |
| 6798 | if (!ha->tgt.atio_ring) { |
| 6799 | kfree(ha->tgt.tgt_vp_map); |
| 6800 | return -ENOMEM; |
| 6801 | } |
| 6802 | return 0; |
| 6803 | } |
| 6804 | |
| 6805 | void |
| 6806 | qlt_mem_free(struct qla_hw_data *ha) |
| 6807 | { |
| 6808 | if (!QLA_TGT_MODE_ENABLED()) |
| 6809 | return; |
| 6810 | |
| 6811 | if (ha->tgt.atio_ring) { |
| 6812 | dma_free_coherent(&ha->pdev->dev, (ha->tgt.atio_q_length + 1) * |
| 6813 | sizeof(struct atio_from_isp), ha->tgt.atio_ring, |
| 6814 | ha->tgt.atio_dma); |
| 6815 | } |
| 6816 | kfree(ha->tgt.tgt_vp_map); |
| 6817 | } |
| 6818 | |
| 6819 | /* vport_slock to be held by the caller */ |
| 6820 | void |
| 6821 | qlt_update_vp_map(struct scsi_qla_host *vha, int cmd) |
| 6822 | { |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6823 | void *slot; |
| 6824 | u32 key; |
| 6825 | int rc; |
| 6826 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6827 | if (!QLA_TGT_MODE_ENABLED()) |
| 6828 | return; |
| 6829 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6830 | key = vha->d_id.b24; |
| 6831 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6832 | switch (cmd) { |
| 6833 | case SET_VP_IDX: |
| 6834 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = vha; |
| 6835 | break; |
| 6836 | case SET_AL_PA: |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6837 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 6838 | if (!slot) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6839 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf018, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6840 | "Save vha in host_map %p %06x\n", vha, key); |
| 6841 | rc = btree_insert32(&vha->hw->tgt.host_map, |
| 6842 | key, vha, GFP_ATOMIC); |
| 6843 | if (rc) |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6844 | ql_log(ql_log_info, vha, 0xd03e, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6845 | "Unable to insert s_id into host_map: %06x\n", |
| 6846 | key); |
| 6847 | return; |
| 6848 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6849 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf019, |
| 6850 | "replace existing vha in host_map %p %06x\n", vha, key); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6851 | btree_update32(&vha->hw->tgt.host_map, key, vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6852 | break; |
| 6853 | case RESET_VP_IDX: |
| 6854 | vha->hw->tgt.tgt_vp_map[vha->vp_idx].vha = NULL; |
| 6855 | break; |
| 6856 | case RESET_AL_PA: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6857 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01a, |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6858 | "clear vha in host_map %p %06x\n", vha, key); |
| 6859 | slot = btree_lookup32(&vha->hw->tgt.host_map, key); |
| 6860 | if (slot) |
| 6861 | btree_remove32(&vha->hw->tgt.host_map, key); |
| 6862 | vha->d_id.b24 = 0; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6863 | break; |
| 6864 | } |
| 6865 | } |
| 6866 | |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 6867 | void qlt_update_host_map(struct scsi_qla_host *vha, port_id_t id) |
| 6868 | { |
| 6869 | unsigned long flags; |
| 6870 | struct qla_hw_data *ha = vha->hw; |
| 6871 | |
| 6872 | if (!vha->d_id.b24) { |
| 6873 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6874 | vha->d_id = id; |
| 6875 | qlt_update_vp_map(vha, SET_AL_PA); |
| 6876 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6877 | } else if (vha->d_id.b24 != id.b24) { |
| 6878 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6879 | qlt_update_vp_map(vha, RESET_AL_PA); |
| 6880 | vha->d_id = id; |
| 6881 | qlt_update_vp_map(vha, SET_AL_PA); |
| 6882 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6883 | } |
| 6884 | } |
| 6885 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6886 | static int __init qlt_parse_ini_mode(void) |
| 6887 | { |
| 6888 | if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_EXCLUSIVE) == 0) |
| 6889 | ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE; |
| 6890 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DISABLED) == 0) |
| 6891 | ql2x_ini_mode = QLA2XXX_INI_MODE_DISABLED; |
| 6892 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_ENABLED) == 0) |
| 6893 | ql2x_ini_mode = QLA2XXX_INI_MODE_ENABLED; |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 6894 | else if (strcasecmp(qlini_mode, QLA2XXX_INI_MODE_STR_DUAL) == 0) |
| 6895 | ql2x_ini_mode = QLA2XXX_INI_MODE_DUAL; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6896 | else |
| 6897 | return false; |
| 6898 | |
| 6899 | return true; |
| 6900 | } |
| 6901 | |
| 6902 | int __init qlt_init(void) |
| 6903 | { |
| 6904 | int ret; |
| 6905 | |
| 6906 | if (!qlt_parse_ini_mode()) { |
| 6907 | ql_log(ql_log_fatal, NULL, 0xe06b, |
| 6908 | "qlt_parse_ini_mode() failed\n"); |
| 6909 | return -EINVAL; |
| 6910 | } |
| 6911 | |
| 6912 | if (!QLA_TGT_MODE_ENABLED()) |
| 6913 | return 0; |
| 6914 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6915 | qla_tgt_mgmt_cmd_cachep = kmem_cache_create("qla_tgt_mgmt_cmd_cachep", |
| 6916 | sizeof(struct qla_tgt_mgmt_cmd), __alignof__(struct |
| 6917 | qla_tgt_mgmt_cmd), 0, NULL); |
| 6918 | if (!qla_tgt_mgmt_cmd_cachep) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 6919 | ql_log(ql_log_fatal, NULL, 0xd04b, |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6920 | "kmem_cache_create for qla_tgt_mgmt_cmd_cachep failed\n"); |
Nicholas Bellinger | 51a07f8 | 2014-05-23 02:00:56 -0700 | [diff] [blame] | 6921 | return -ENOMEM; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6922 | } |
| 6923 | |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6924 | qla_tgt_plogi_cachep = kmem_cache_create("qla_tgt_plogi_cachep", |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 6925 | sizeof(struct qlt_plogi_ack_t), __alignof__(struct qlt_plogi_ack_t), |
| 6926 | 0, NULL); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6927 | |
| 6928 | if (!qla_tgt_plogi_cachep) { |
| 6929 | ql_log(ql_log_fatal, NULL, 0xe06d, |
| 6930 | "kmem_cache_create for qla_tgt_plogi_cachep failed\n"); |
| 6931 | ret = -ENOMEM; |
| 6932 | goto out_mgmt_cmd_cachep; |
| 6933 | } |
| 6934 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6935 | qla_tgt_mgmt_cmd_mempool = mempool_create(25, mempool_alloc_slab, |
| 6936 | mempool_free_slab, qla_tgt_mgmt_cmd_cachep); |
| 6937 | if (!qla_tgt_mgmt_cmd_mempool) { |
| 6938 | ql_log(ql_log_fatal, NULL, 0xe06e, |
| 6939 | "mempool_create for qla_tgt_mgmt_cmd_mempool failed\n"); |
| 6940 | ret = -ENOMEM; |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6941 | goto out_plogi_cachep; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6942 | } |
| 6943 | |
| 6944 | qla_tgt_wq = alloc_workqueue("qla_tgt_wq", 0, 0); |
| 6945 | if (!qla_tgt_wq) { |
| 6946 | ql_log(ql_log_fatal, NULL, 0xe06f, |
| 6947 | "alloc_workqueue for qla_tgt_wq failed\n"); |
| 6948 | ret = -ENOMEM; |
| 6949 | goto out_cmd_mempool; |
| 6950 | } |
| 6951 | /* |
| 6952 | * Return 1 to signal that initiator-mode is being disabled |
| 6953 | */ |
| 6954 | return (ql2x_ini_mode == QLA2XXX_INI_MODE_DISABLED) ? 1 : 0; |
| 6955 | |
| 6956 | out_cmd_mempool: |
| 6957 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6958 | out_plogi_cachep: |
| 6959 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6960 | out_mgmt_cmd_cachep: |
| 6961 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6962 | return ret; |
| 6963 | } |
| 6964 | |
| 6965 | void qlt_exit(void) |
| 6966 | { |
| 6967 | if (!QLA_TGT_MODE_ENABLED()) |
| 6968 | return; |
| 6969 | |
| 6970 | destroy_workqueue(qla_tgt_wq); |
| 6971 | mempool_destroy(qla_tgt_mgmt_cmd_mempool); |
Alexei Potashnik | b7bd104 | 2015-12-17 14:57:02 -0500 | [diff] [blame] | 6972 | kmem_cache_destroy(qla_tgt_plogi_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6973 | kmem_cache_destroy(qla_tgt_mgmt_cmd_cachep); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6974 | } |